diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2002-08-04 04:32:27 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2002-08-04 04:32:27 +0000 |
commit | 526b145c231b854129898675d00045c8747351bd (patch) | |
tree | 5b311dc7662dad9203a32b0350c10313f8605401 | |
parent | 10bc1114cecec4a11075928b3902878f8e6268b9 (diff) | |
download | src-526b145c231b854129898675d00045c8747351bd.tar.gz src-526b145c231b854129898675d00045c8747351bd.zip |
Never allow a user to use crontab if opening /var/cron/{allow,deny} fails
for any reason other than ENOENT (think resource limits). Close allow and
deny files before allowed() returns to stop the user's EDITOR being able to
read them.
Obtained from: OpenBSD (partially)
Notes
Notes:
svn path=/head/; revision=101293
-rw-r--r-- | usr.sbin/cron/lib/misc.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/usr.sbin/cron/lib/misc.c b/usr.sbin/cron/lib/misc.c index 195ff9cb2da1..89f15e409ee2 100644 --- a/usr.sbin/cron/lib/misc.c +++ b/usr.sbin/cron/lib/misc.c @@ -410,31 +410,38 @@ int allowed(username) char *username; { - static int init = FALSE; - static FILE *allow, *deny; + FILE *allow, *deny; + int isallowed; + + isallowed = FALSE; - if (!init) { - init = TRUE; #if defined(ALLOW_FILE) && defined(DENY_FILE) - allow = fopen(ALLOW_FILE, "r"); - deny = fopen(DENY_FILE, "r"); - Debug(DMISC, ("allow/deny enabled, %d/%d\n", !!allow, !!deny)) + if ((allow = fopen(ALLOW_FILE, "r")) == NULL && errno != ENOENT) + goto out; + if ((deny = fopen(DENY_FILE, "r")) == NULL && errno != ENOENT) + goto out; + Debug(DMISC, ("allow/deny enabled, %d/%d\n", !!allow, !!deny)) #else - allow = NULL; - deny = NULL; + allow = NULL; + deny = NULL; #endif - } if (allow) - return (in_file(username, allow)); - if (deny) - return (!in_file(username, deny)); - + isallowed = in_file(username, allow); + else if (deny) + isallowed = !in_file(username, deny); + else { #if defined(ALLOW_ONLY_ROOT) - return (strcmp(username, ROOT_USER) == 0); + isallowed = (strcmp(username, ROOT_USER) == 0); #else - return TRUE; + isallowed = TRUE; #endif + } +out: if (allow) + fclose(allow); + if (deny) + fclose(deny); + return (isallowed); } |