2017-05-08 15:30:03 +02:00
|
|
|
/* Copyright 1988,1990,1993,1994 by Paul Vixie
|
|
|
|
* All rights reserved
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* vix 26jan87 [log is in RCS file]
|
|
|
|
*/
|
|
|
|
|
2019-08-06 18:08:05 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "funcs.h"
|
|
|
|
#include "globals.h"
|
2017-05-08 15:30:03 +02:00
|
|
|
|
|
|
|
static const char *FileName;
|
|
|
|
|
|
|
|
static void
|
|
|
|
log_error (const char *msg)
|
|
|
|
{
|
|
|
|
log_it ("CRON", getpid (), msg, FileName, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_user (user * u) {
|
|
|
|
entry *e, *ne;
|
|
|
|
|
2019-08-06 18:08:05 +02:00
|
|
|
if (!u) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-08 15:30:03 +02:00
|
|
|
free(u->name);
|
|
|
|
free(u->tabname);
|
|
|
|
for (e = u->crontab; e != NULL; e = ne) {
|
|
|
|
ne = e->next;
|
|
|
|
free_entry(e);
|
|
|
|
}
|
2019-08-06 18:08:05 +02:00
|
|
|
#ifdef WITH_SELINUX
|
2017-05-08 15:30:03 +02:00
|
|
|
free_security_context(&(u->scontext));
|
2019-08-06 18:08:05 +02:00
|
|
|
#endif
|
2017-05-08 15:30:03 +02:00
|
|
|
free(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
user *
|
|
|
|
load_user (int crontab_fd, struct passwd *pw, const char *uname,
|
|
|
|
const char *fname, const char *tabname) {
|
|
|
|
char envstr[MAX_ENVSTR];
|
|
|
|
FILE *file;
|
|
|
|
user *u;
|
|
|
|
entry *e;
|
2019-08-06 18:08:05 +02:00
|
|
|
int status = TRUE, save_errno = 0;
|
2017-05-08 15:30:03 +02:00
|
|
|
char **envp = NULL, **tenvp;
|
2019-08-06 18:08:05 +02:00
|
|
|
int envs = 0, entries = 0;
|
2017-05-08 15:30:03 +02:00
|
|
|
|
|
|
|
if (!(file = fdopen(crontab_fd, "r"))) {
|
2019-08-06 18:08:05 +02:00
|
|
|
save_errno = errno;
|
2017-05-08 15:30:03 +02:00
|
|
|
log_it(uname, getpid (), "FAILED", "fdopen on crontab_fd in load_user",
|
|
|
|
save_errno);
|
|
|
|
close(crontab_fd);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:08:05 +02:00
|
|
|
Debug(DPARS, ("load_user()\n"));
|
2017-05-08 15:30:03 +02:00
|
|
|
/* file is open. build user entry, then read the crontab file.
|
|
|
|
*/
|
2019-08-06 18:08:05 +02:00
|
|
|
if ((u = (user *) malloc (sizeof (user))) == NULL) {
|
|
|
|
save_errno = errno;
|
2017-05-08 15:30:03 +02:00
|
|
|
goto done;
|
2019-08-06 18:08:05 +02:00
|
|
|
}
|
2017-05-08 15:30:03 +02:00
|
|
|
memset(u, 0, sizeof(*u));
|
|
|
|
|
|
|
|
if (((u->name = strdup(fname)) == NULL)
|
|
|
|
|| ((u->tabname = strdup(tabname)) == NULL)) {
|
|
|
|
save_errno = errno;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:08:05 +02:00
|
|
|
u->system = pw == NULL;
|
2017-05-08 15:30:03 +02:00
|
|
|
|
|
|
|
/* init environment. this will be copied/augmented for each entry.
|
|
|
|
*/
|
|
|
|
if ((envp = env_init()) == NULL) {
|
|
|
|
save_errno = errno;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:08:05 +02:00
|
|
|
if (env_set_from_environ(&envp) == FALSE) {
|
|
|
|
save_errno = errno;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_SELINUX
|
2017-05-08 15:30:03 +02:00
|
|
|
if (get_security_context(pw == NULL ? NULL : uname,
|
|
|
|
crontab_fd, &u->scontext, tabname) != 0) {
|
|
|
|
goto done;
|
|
|
|
}
|
2019-08-06 18:08:05 +02:00
|
|
|
#endif
|
2017-05-08 15:30:03 +02:00
|
|
|
/* load the crontab
|
|
|
|
*/
|
2019-08-06 18:08:05 +02:00
|
|
|
while (status >= OK) {
|
|
|
|
if (!skip_comments(file) && !u->system) {
|
|
|
|
log_error("too many garbage characters");
|
|
|
|
status = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
status = load_env (envstr, file);
|
2017-05-08 15:30:03 +02:00
|
|
|
switch (status) {
|
|
|
|
case FALSE:
|
2019-08-06 18:08:05 +02:00
|
|
|
++entries;
|
|
|
|
if (!u->system && entries > MAX_USER_ENTRIES) {
|
|
|
|
log_error("too many entries");
|
|
|
|
status = TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
2017-05-08 15:30:03 +02:00
|
|
|
FileName = tabname;
|
|
|
|
e = load_entry(file, log_error, pw, envp);
|
2019-08-06 18:08:05 +02:00
|
|
|
if (e) {
|
2017-05-08 15:30:03 +02:00
|
|
|
e->next = u->crontab;
|
|
|
|
u->crontab = e;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRUE:
|
2019-08-06 18:08:05 +02:00
|
|
|
++envs;
|
|
|
|
if (!u->system && envs > MAX_USER_ENVS) {
|
|
|
|
log_error("too many environment variables");
|
|
|
|
goto done;
|
|
|
|
}
|
2017-05-08 15:30:03 +02:00
|
|
|
if ((tenvp = env_set (envp, envstr)) == NULL) {
|
|
|
|
save_errno = errno;
|
|
|
|
goto done;
|
|
|
|
}
|
2019-08-06 18:08:05 +02:00
|
|
|
envp = tenvp;
|
|
|
|
break;
|
2017-05-08 15:30:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2019-08-06 18:08:05 +02:00
|
|
|
if (status == TRUE) {
|
|
|
|
log_it(uname, getpid(), "FAILED", "loading cron table",
|
|
|
|
save_errno);
|
|
|
|
free_user(u);
|
|
|
|
u = NULL;
|
|
|
|
}
|
2017-05-08 15:30:03 +02:00
|
|
|
if (envp)
|
|
|
|
env_free(envp);
|
|
|
|
fclose(file);
|
2019-08-06 18:08:05 +02:00
|
|
|
Debug(DPARS, ("...load_user() done\n"));
|
2017-05-08 15:30:03 +02:00
|
|
|
errno = save_errno;
|
|
|
|
return (u);
|
|
|
|
}
|