Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/cron/cron/user.c
/* Copyright 1988,1990,1993,1994 by Paul Vixie | /* Copyright 1988,1990,1993,1994 by Paul Vixie | ||||
* All rights reserved | * All rights reserved | ||||
*/ | |||||
/* | |||||
* Copyright (c) 1997 by Internet Software Consortium | |||||
* | * | ||||
* Distribute freely, except: don't remove my name from the source or | * Permission to use, copy, modify, and distribute this software for any | ||||
* documentation (don't take credit for my work), mark your changes (don't | * purpose with or without fee is hereby granted, provided that the above | ||||
* get me blamed for your possible bugs), don't alter or remove this | * copyright notice and this permission notice appear in all copies. | ||||
* 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||||
* I'll try to keep a version up to date. I can be reached as follows: | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||||
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||||
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | |||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |||||
* SOFTWARE. | |||||
*/ | */ | ||||
#if !defined(lint) && !defined(LINT) | #if !defined(lint) && !defined(LINT) | ||||
static const char rcsid[] = | static const char rcsid[] = "$Id: user.c,v 1.2 1998/08/14 00:32:41 vixie Exp $"; | ||||
"$FreeBSD$"; | |||||
#endif | #endif | ||||
/* vix 26jan87 [log is in RCS file] | /* vix 26jan87 [log is in RCS file] | ||||
*/ | */ | ||||
#include "cron.h" | #include "cron.h" | ||||
static char *User_name; | static char *User_name; | ||||
void | void | ||||
free_user(user *u) | free_user(user *u) | ||||
{ | { | ||||
entry *e, *ne; | entry *e, *ne; | ||||
free(u->name); | free(u->name); | ||||
for (e = u->crontab; e != NULL; e = ne) { | for (e = u->crontab; e != NULL; e = ne) { | ||||
ne = e->next; | ne = e->next; | ||||
free_entry(e); | free_entry(e); | ||||
} | } | ||||
free(u); | free(u); | ||||
} | } | ||||
static void | static void | ||||
log_error(char *msg) | log_error(const char *msg) | ||||
{ | { | ||||
log_it(User_name, getpid(), "PARSE", msg); | log_it(User_name, getpid(), "PARSE", msg); | ||||
} | } | ||||
/* NULL pw implies syscrontab */ | /* NULL pw implies syscrontab */ | ||||
user * | user * | ||||
load_user(int crontab_fd, struct passwd *pw, char *name) | load_user(int crontab_fd, struct passwd *pw, const char *name) | ||||
{ | { | ||||
char envstr[MAX_ENVSTR]; | char envstr[MAX_ENVSTR]; | ||||
FILE *file; | FILE *file; | ||||
user *u; | user *u; | ||||
entry *e; | entry *e; | ||||
int status; | int status; | ||||
char **envp, **tenvp; | char **envp, **tenvp; | ||||
if (!(file = fdopen(crontab_fd, "r"))) { | if (!(file = fdopen(crontab_fd, "r"))) { | ||||
warn("fdopen on crontab_fd in load_user"); | warn("fdopen on crontab_fd in load_user"); | ||||
return NULL; | return (NULL); | ||||
} | } | ||||
Debug(DPARS, ("load_user()\n")) | Debug(DPARS, ("load_user()\n")) | ||||
/* file is open. build user entry, then read the crontab file. | /* file is open. build user entry, then read the crontab file. | ||||
*/ | */ | ||||
if ((u = (user *) malloc(sizeof(user))) == NULL) { | if ((u = (user *) malloc(sizeof(user))) == NULL) { | ||||
errno = ENOMEM; | errno = ENOMEM; | ||||
return NULL; | return (NULL); | ||||
} | } | ||||
if ((u->name = strdup(name)) == NULL) { | if ((u->name = strdup(name)) == NULL) { | ||||
free(u); | free(u); | ||||
errno = ENOMEM; | errno = ENOMEM; | ||||
return NULL; | return (NULL); | ||||
} | } | ||||
u->crontab = NULL; | u->crontab = NULL; | ||||
/* | /* | ||||
* init environment. this will be copied/augmented for each entry. | * init environment. this will be copied/augmented for each entry. | ||||
*/ | */ | ||||
if ((envp = env_init()) == NULL) { | if ((envp = env_init()) == NULL) { | ||||
free(u->name); | free(u->name); | ||||
free(u); | free(u); | ||||
return NULL; | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* load the crontab | * load the crontab | ||||
*/ | */ | ||||
while ((status = load_env(envstr, file)) >= OK) { | while ((status = load_env(envstr, file)) >= OK) { | ||||
switch (status) { | switch (status) { | ||||
case ERR: | case ERR: | ||||
Show All 19 Lines | case TRUE: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
done: | done: | ||||
env_free(envp); | env_free(envp); | ||||
fclose(file); | fclose(file); | ||||
Debug(DPARS, ("...load_user() done\n")) | Debug(DPARS, ("...load_user() done\n")) | ||||
return u; | return (u); | ||||
} | } |