diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-05-09 22:14:17 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-05-09 22:14:17 +0000 |
commit | baced3dc507fff203a8eb2abaa99d87b802c68ab (patch) | |
tree | 4573db7155c1226bcd314504b009e95c1d2d0f07 /usr.sbin/cron | |
parent | 321f9cba7df95fec45615a4f5f6f9b995a0edb05 (diff) |
allowed() is only called once so there is no need to use static
variables and leave the allow/deny files open. Previously, the
allow/deny fd's were leaked during the crontab edit.
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r-- | usr.sbin/cron/misc.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index e94a68e3285..6c6ce7d50c4 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.14 2002/05/09 21:53:17 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.15 2002/05/09 22:14:16 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved */ @@ -21,7 +21,7 @@ */ #if !defined(lint) && !defined(LINT) -static char rcsid[] = "$OpenBSD: misc.c,v 1.14 2002/05/09 21:53:17 millert Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.15 2002/05/09 22:14:16 millert Exp $"; #endif /* vix 26jan87 [RCS has the rest of the log] @@ -472,40 +472,43 @@ int allowed(username) char *username; { - static int init = FALSE; - static FILE *allow, *deny; - static int allow_error, deny_error; + FILE *allow = NULL; + FILE *deny = NULL; + int isallowed; - if (!init) { - init = TRUE; #if defined(ALLOW_FILE) && defined(DENY_FILE) - allow = fopen(ALLOW_FILE, "r"); - allow_error = !allow && errno != ENOENT; - deny = fopen(DENY_FILE, "r"); - deny_error = !deny && errno != ENOENT; - Debug(DMISC, ("allow/deny enabled, %d/%d\n", !!allow, !!deny)) + isallowed = FALSE; + allow = fopen(ALLOW_FILE, "r"); + if (allow == NULL && errno != ENOENT) + goto out; + deny = fopen(DENY_FILE, "r"); + if (deny == NULL && errno != ENOENT) + goto out; + Debug(DMISC, ("allow/deny enabled, %d/%d\n", !!allow, !!deny)) + + if (allow) { + isallowed = in_file(username, allow, FALSE); + goto out; + } + if (deny) { + isallowed = !in_file(username, deny, TRUE); + goto out; + } +#endif + +#if defined(ALLOW_ONLY_ROOT) + isallowed = strcmp(username, ROOT_USER) == 0; #else - allow = NULL; - allow_error = 0; - deny = NULL; - deny_error = 0; + isallowed = TRUE; #endif - } - if (allow_error) - return (FALSE); +out: if (allow) - return (in_file(username, allow, FALSE)); - if (deny_error) - return (FALSE); + fclose(allow); if (deny) - return (!in_file(username, deny, TRUE)); + fclose(deny); -#if defined(ALLOW_ONLY_ROOT) - return (strcmp(username, ROOT_USER) == 0); -#else - return (TRUE); -#endif + return (isallowed); } |