NetBSD/usr.sbin/cron/user.c

110 lines
2.3 KiB
C
Raw Normal View History

/* $NetBSD: user.c,v 1.3 1998/01/31 14:40:45 christos Exp $ */
1997-03-13 09:19:07 +03:00
1994-01-12 21:35:59 +03:00
/* Copyright 1988,1990,1993,1994 by Paul Vixie
1994-01-05 23:40:12 +03:00
* 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
*/
#include <sys/cdefs.h>
1994-01-05 23:40:12 +03:00
#if !defined(lint) && !defined(LINT)
#if 0
static char rcsid[] = "Id: user.c,v 2.8 1994/01/15 20:43:43 vixie Exp";
#else
__RCSID("$NetBSD: user.c,v 1.3 1998/01/31 14:40:45 christos Exp $");
#endif
1994-01-05 23:40:12 +03:00
#endif
/* vix 26jan87 [log is in RCS file]
*/
#include "cron.h"
void
free_user(u)
user *u;
{
entry *e, *ne;
1994-01-11 22:10:45 +03:00
free(u->name);
1994-01-05 23:40:12 +03:00
for (e = u->crontab; e != NULL; e = ne) {
ne = e->next;
free_entry(e);
}
1994-01-11 22:10:45 +03:00
free(u);
1994-01-05 23:40:12 +03:00
}
user *
1994-01-11 22:10:45 +03:00
load_user(crontab_fd, pw, name)
int crontab_fd;
struct passwd *pw; /* NULL implies syscrontab */
char *name;
1994-01-05 23:40:12 +03:00
{
char envstr[MAX_ENVSTR];
FILE *file;
user *u;
entry *e;
int status;
1994-01-11 22:10:45 +03:00
char **envp;
1994-01-05 23:40:12 +03:00
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));
1994-01-11 22:10:45 +03:00
u->name = strdup(name);
1994-01-05 23:40:12 +03:00
u->crontab = NULL;
1994-01-11 22:10:45 +03:00
/*
* init environment. this will be copied/augmented for each entry.
1994-01-05 23:40:12 +03:00
*/
1994-01-11 22:10:45 +03:00
envp = env_init();
1994-01-05 23:40:12 +03:00
1994-01-11 22:10:45 +03:00
/*
* load the crontab
1994-01-05 23:40:12 +03:00
*/
while ((status = load_env(envstr, file)) >= OK) {
1994-01-11 22:10:45 +03:00
switch (status) {
case ERR:
free_user(u);
u = NULL;
goto done;
case FALSE:
e = load_entry(file, NULL, pw, envp);
if (e) {
1994-01-05 23:40:12 +03:00
e->next = u->crontab;
u->crontab = e;
}
1994-01-11 22:10:45 +03:00
break;
case TRUE:
envp = env_set(envp, envstr);
break;
1994-01-05 23:40:12 +03:00
}
}
1994-01-11 22:10:45 +03:00
done:
env_free(envp);
1994-01-05 23:40:12 +03:00
fclose(file);
Debug(DPARS, ("...load_user() done\n"))
return u;
}