diff options
Diffstat (limited to 'usr.sbin/cron/user.c')
| -rw-r--r-- | usr.sbin/cron/user.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/usr.sbin/cron/user.c b/usr.sbin/cron/user.c new file mode 100644 index 000000000000..39c7a967a998 --- /dev/null +++ b/usr.sbin/cron/user.c @@ -0,0 +1,103 @@ +/* Copyright 1988,1990,1993,1994 by Paul Vixie + * All rights reserved + * + * Distribute freely, except: don't remove my name from the source or + * documentation (don't take credit for my work), mark your changes (don't + * get me blamed for your possible bugs), don't alter or remove this + * notice. May be sold if buildable source is provided to buyer. No + * warrantee of any kind, express or implied, is included with this + * software; use at your own risk, responsibility for damages (if any) to + * anyone resulting from the use of this software rests entirely with the + * user. + * + * Send bug reports, bug fixes, enhancements, requests, flames, etc., and + * I'll try to keep a version up to date. I can be reached as follows: + * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul + * From Id: user.c,v 2.8 1994/01/15 20:43:43 vixie Exp + */ + +#if !defined(lint) && !defined(LINT) +static char rcsid[] = "$Header: /home/cvs/386BSD/src/usr.sbin/cron/user.c,v 1.1 1994/01/22 20:39:10 guido Exp $"; +#endif + +/* vix 26jan87 [log is in RCS file] + */ + + +#include "cron.h" + + +void +free_user(u) + user *u; +{ + entry *e, *ne; + + free(u->name); + for (e = u->crontab; e != NULL; e = ne) { + ne = e->next; + free_entry(e); + } + free(u); +} + + +user * +load_user(crontab_fd, pw, name) + int crontab_fd; + struct passwd *pw; /* NULL implies syscrontab */ + char *name; +{ + char envstr[MAX_ENVSTR]; + FILE *file; + user *u; + entry *e; + int status; + char **envp; + + if (!(file = fdopen(crontab_fd, "r"))) { + perror("fdopen on crontab_fd in load_user"); + return NULL; + } + + Debug(DPARS, ("load_user()\n")) + + /* file is open. build user entry, then read the crontab file. + */ + u = (user *) malloc(sizeof(user)); + u->name = strdup(name); + u->crontab = NULL; + + /* + * init environment. this will be copied/augmented for each entry. + */ + envp = env_init(); + + /* + * load the crontab + */ + while ((status = load_env(envstr, file)) >= OK) { + switch (status) { + case ERR: + free_user(u); + u = NULL; + goto done; + case FALSE: + e = load_entry(file, NULL, pw, envp); + if (e) { + e->next = u->crontab; + u->crontab = e; + } + break; + case TRUE: + envp = env_set(envp, envstr); + break; + } + } + + done: + env_free(envp); + fclose(file); + Debug(DPARS, ("...load_user() done\n")) + return u; +} |
