No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / cron / user.c
blob7c3e0037ab1dd3abad7e42e3aad75f5cb6f8687e
1 /* $NetBSD: user.c,v 1.3 1998/01/31 14:40:45 christos Exp $ */
3 /* Copyright 1988,1990,1993,1994 by Paul Vixie
4 * All rights reserved
6 * Distribute freely, except: don't remove my name from the source or
7 * documentation (don't take credit for my work), mark your changes (don't
8 * get me blamed for your possible bugs), don't alter or remove this
9 * notice. May be sold if buildable source is provided to buyer. No
10 * warrantee of any kind, express or implied, is included with this
11 * software; use at your own risk, responsibility for damages (if any) to
12 * anyone resulting from the use of this software rests entirely with the
13 * user.
15 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
16 * I'll try to keep a version up to date. I can be reached as follows:
17 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
20 #include <sys/cdefs.h>
21 #if !defined(lint) && !defined(LINT)
22 #if 0
23 static char rcsid[] = "Id: user.c,v 2.8 1994/01/15 20:43:43 vixie Exp";
24 #else
25 __RCSID("$NetBSD: user.c,v 1.3 1998/01/31 14:40:45 christos Exp $");
26 #endif
27 #endif
29 /* vix 26jan87 [log is in RCS file]
33 #include "cron.h"
36 void
37 free_user(user *u)
39 entry *e, *ne;
41 free(u->name);
42 for (e = u->crontab; e != NULL; e = ne) {
43 ne = e->next;
44 free_entry(e);
46 free(u);
50 user *
51 load_user(int crontab_fd, struct passwd *pw, /* NULL implies syscrontab */
52 const char *name)
54 char envstr[MAX_ENVSTR];
55 FILE *file;
56 user *u;
57 entry *e;
58 int status;
59 char **envp;
61 if (!(file = fdopen(crontab_fd, "r"))) {
62 perror("fdopen on crontab_fd in load_user");
63 return NULL;
66 Debug(DPARS, ("load_user()\n"))
68 /* file is open. build user entry, then read the crontab file.
70 u = (user *) malloc(sizeof(user));
71 u->name = strdup(name);
72 u->crontab = NULL;
74 /*
75 * init environment. this will be copied/augmented for each entry.
77 envp = env_init();
80 * load the crontab
82 while ((status = load_env(envstr, file)) >= OK) {
83 switch (status) {
84 case ERR:
85 free_user(u);
86 u = NULL;
87 goto done;
88 case FALSE:
89 e = load_entry(file, NULL, pw, envp);
90 if (e) {
91 e->next = u->crontab;
92 u->crontab = e;
94 break;
95 case TRUE:
96 envp = env_set(envp, envstr);
97 break;
101 done:
102 env_free(envp);
103 fclose(file);
104 Debug(DPARS, ("...load_user() done\n"))
105 return u;