Signed-off-by: Sami Kerola <kerolasa(a)iki.fi>
---
src/.indent.pro | 10 ++++
src/cron.c | 166 +++++++++++++++++++++++++++++--------------------------
src/crontab.c | 77 +++++++++++++-------------
src/database.c | 105 +++++++++++++++++------------------
src/do_command.c | 100 +++++++++++++++++----------------
src/entry.c | 62 ++++++++++-----------
src/env.c | 8 +--
src/job.c | 2 +-
src/misc.c | 47 ++++++++--------
src/popen.c | 4 +-
src/pw_dup.c | 49 ++++++++--------
src/security.c | 102 ++++++++++++++++++----------------
src/user.c | 68 +++++++++++------------
13 files changed, 405 insertions(+), 395 deletions(-)
diff --git a/src/.indent.pro b/src/.indent.pro
index 36235da..a2ce7c4 100644
--- a/src/.indent.pro
+++ b/src/.indent.pro
@@ -1,3 +1,13 @@
+-T FILE
+-T bitstr_t
+-T cron_db
+-T entry
+-T off_t
+-T orphan
+-T security_context_t
+-T size_t
+-T time_t
+-T user
--blank-before-sizeof
--brace-indent0
--braces-on-func-def-line
diff --git a/src/cron.c b/src/cron.c
index c06fd3f..35dc865 100644
--- a/src/cron.c
+++ b/src/cron.c
@@ -84,14 +84,14 @@ static int DisableInotify;
*/
# if defined WITH_SYSCRONTAB
-# define NUM_WATCHES 3
+# define NUM_WATCHES 3
int wd[NUM_WATCHES];
-const char *watchpaths[NUM_WATCHES] = {SPOOL_DIR, SYS_CROND_DIR, SYSCRONTAB};
+const char *watchpaths[NUM_WATCHES] = { SPOOL_DIR, SYS_CROND_DIR, SYSCRONTAB };
# else
-# define NUM_WATCHES 2
+# define NUM_WATCHES 2
int wd[NUM_WATCHES];
-const char *watchpaths[NUM_WATCHES] = {SPOOL_DIR, SYS_CROND_DIR};
+const char *watchpaths[NUM_WATCHES] = { SPOOL_DIR, SYS_CROND_DIR };
# endif
static void reset_watches(void) {
@@ -126,8 +126,9 @@ void set_cron_watched(int fd) {
int w;
w = inotify_add_watch(fd, watchpaths[i],
- IN_CREATE | IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO |
- IN_MOVED_FROM | IN_MOVE_SELF | IN_DELETE | IN_DELETE_SELF);
+ IN_CREATE | IN_CLOSE_WRITE | IN_ATTRIB |
+ IN_MODIFY | IN_MOVED_TO | IN_MOVED_FROM |
+ IN_MOVE_SELF | IN_DELETE | IN_DELETE_SELF);
if (w < 0 && errno != ENOENT) {
if (wd[i] != -1) {
log_it("CRON", pid, "This directory or file can't be
watched",
@@ -150,7 +151,7 @@ void set_cron_watched(int fd) {
}
#endif
-static void handle_signals(cron_db * database) {
+static void handle_signals(cron_db *database) {
if (got_sighup) {
got_sighup = 0;
#if defined WITH_INOTIFY
@@ -182,8 +183,7 @@ static void usage(void) {
[-P] change PATH \n \
[-c] enable clustering support \n \
[-s] log into syslog instead of sending mails \n \
- [-x [",
- ProgramName);
+ [-x [", ProgramName);
for (dflags = DebugFlagNames; *dflags; dflags++)
fprintf(stderr, "%s%s", *dflags, dflags[1] ? "," : "]");
fprintf(stderr, "] print debug information\n");
@@ -198,7 +198,7 @@ int main(int argc, char *argv[]) {
pid_t pid = getpid();
long oldGMToff;
- if ((ProgramName=strrchr(argv[0], '/')) == NULL) {
+ if ((ProgramName = strrchr(argv[0], '/')) == NULL) {
ProgramName = argv[0];
}
else {
@@ -240,24 +240,21 @@ int main(int argc, char *argv[]) {
if (ChangePath) {
if (putenv("PATH=" _PATH_DEFPATH) < 0) {
- log_it("CRON", pid, "DEATH", "can't putenv PATH",
- errno);
+ log_it("CRON", pid, "DEATH", "can't putenv PATH",
errno);
exit(1);
}
}
- /* Get the default locale character set for the mail
- * "Content-Type: ...; charset=" header
- */
+ /* Get the default locale character set for the mail
+ * "Content-Type: ...; charset=" header */
setlocale(LC_ALL, ""); /* set locale to system defaults or to
- * that specified by any LC_* env vars */
+ * that specified by any LC_* env vars */
if ((cs = nl_langinfo(CODESET)) != 0L)
strncpy(cron_default_mail_charset, cs, MAX_ENVSTR);
else
strcpy(cron_default_mail_charset, "US-ASCII");
- /* if there are no debug flags turned on, fork as a daemon should.
- */
+ /* if there are no debug flags turned on, fork as a daemon should. */
if (DebugFlags) {
#if DEBUGGING
(void) fprintf(stderr, "[%ld] cron started\n", (long) getpid());
@@ -290,7 +287,8 @@ int main(int argc, char *argv[]) {
if (!SyslogOutput && (access("/usr/sbin/sendmail", X_OK) != 0 ||
MailCmd[0] != '\0')) {
SyslogOutput = 1;
- log_it("CRON", pid, "INFO", "Syslog will be used instead of
sendmail.", 0);
+ log_it("CRON", pid, "INFO", "Syslog will be used instead of
sendmail.",
+ 0);
}
pid = getpid();
@@ -304,8 +302,8 @@ int main(int argc, char *argv[]) {
fd = -1;
#if defined WITH_INOTIFY
if (DisableInotify || EnableClustering) {
- log_it("CRON", getpid(), "No inotify - daemon runs with -i or -c
option",
- "", 0);
+ log_it("CRON", getpid(),
+ "No inotify - daemon runs with -i or -c option", "", 0);
}
else {
reset_watches();
@@ -340,7 +338,8 @@ int main(int argc, char *argv[]) {
do {
cron_sleep(timeRunning + 1, &database);
set_time(FALSE);
- } while (!got_sigintterm && clockTime == timeRunning);
+ }
+ while (!got_sigintterm && clockTime == timeRunning);
if (got_sigintterm)
break;
timeRunning = clockTime;
@@ -394,10 +393,13 @@ int main(int argc, char *argv[]) {
sleep(10);
virtualTime++;
if (virtualTime >= timeRunning)
- /* always run also the other timezone jobs in the last step */
+ /* always run also the other
+ * timezone jobs in the last
+ * step */
oldGMToff = GMToff;
find_jobs(virtualTime, &database, TRUE, TRUE, oldGMToff);
- } while (virtualTime < timeRunning);
+ }
+ while (virtualTime < timeRunning);
break;
case medium:
@@ -422,12 +424,15 @@ int main(int argc, char *argv[]) {
if (job_runqueue())
sleep(10);
virtualTime++;
- if (virtualTime >= timeRunning)
- /* always run also the other timezone jobs in the last step */
+ if (virtualTime >= timeRunning)
+ /* always run also the other
+ * timezone jobs in the last
+ * step */
oldGMToff = GMToff;
find_jobs(virtualTime, &database, FALSE, TRUE, oldGMToff);
set_time(FALSE);
- } while (virtualTime < timeRunning && clockTime == timeRunning);
+ }
+ while (virtualTime < timeRunning && clockTime == timeRunning);
break;
case negative:
@@ -474,7 +479,7 @@ int main(int argc, char *argv[]) {
return 0;
}
-static void run_reboot_jobs(cron_db * db) {
+static void run_reboot_jobs(cron_db *db) {
user *u;
entry *e;
int reboot;
@@ -502,7 +507,8 @@ static void run_reboot_jobs(cron_db * db) {
(void) job_runqueue();
}
-static void find_jobs(int vtime, cron_db * db, int doWild, int doNonWild, long vGMToff)
{
+static void
+find_jobs(int vtime, cron_db *db, int doWild, int doNonWild, long vGMToff) {
char *orig_tz, *job_tz;
time_t virtualSecond = vtime * SECONDS_PER_MINUTE;
time_t virtualGMTSecond = virtualSecond - vGMToff;
@@ -535,7 +541,7 @@ static void find_jobs(int vtime, cron_db * db, int doWild, int
doNonWild, long v
dom = tm->tm_mday -FIRST_DOM; \
month = tm->tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH; \
dow = tm->tm_wday -FIRST_DOW; \
- } while (0)
+} while (0)
orig_tz = getenv("TZ");
maketime(NULL, orig_tz);
@@ -543,18 +549,18 @@ static void find_jobs(int vtime, cron_db * db, int doWild, int
doNonWild, long v
Debug(DSCH, ("[%ld] tick(%d,%d,%d,%d,%d) %s %s\n",
(long) getpid(), minute, hour, dom, month, dow,
doWild ? " " : "No wildcard", doNonWild ? " " :
"Wildcard only"));
- /* the dom/dow situation is odd. '* * 1,15 * Sun' will run on the
- * first and fifteenth AND every Sunday; '* * * * Sun' will run *only*
- * on Sundays; '* * 1,15 * *' will run *only* the 1st and 15th. this
- * is why we keep 'e->dow_star' and 'e->dom_star'. yes, it's
bizarre.
- * like many bizarre things, it's the standard.
- */
- for (u = db->head; u != NULL; u = u->next) {
+ /* the dom/dow situation is odd. '* * 1,15 * Sun' will run on the
+ * first and fifteenth AND every Sunday; '* * * * Sun' will run *only*
+ * on Sundays; '* * 1,15 * *' will run *only* the 1st and 15th. this
+ * is why we keep 'e->dow_star' and 'e->dom_star'. yes, it's
bizarre.
+ * like many bizarre things, it's the standard.
+ */
+ for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
Debug(DSCH | DEXT, ("user [%s:%ld:%ld:...] cmd=\"%s\"\n",
e->pwd->pw_name, (long) e->pwd->pw_uid,
(long) e->pwd->pw_gid, e->cmd));
- uname = e->pwd->pw_name;
+ uname = e->pwd->pw_name;
/* check if user exists in time of job is being run f.e. ldap */
if (getpwnam(uname) != NULL) {
job_tz = env_get("CRON_TZ", e->envp);
@@ -565,19 +571,20 @@ static void find_jobs(int vtime, cron_db * db, int doWild, int
doNonWild, long v
bit_test(e->month, month) &&
(((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
? (bit_test(e->dow, dow) && bit_test(e->dom, dom))
- : (bit_test(e->dow, dow) || bit_test(e->dom, dom))
- )
- ) {
+ : (bit_test(e->dow, dow) || bit_test(e->dom, dom)))) {
if (job_tz != NULL && vGMToff != GMToff)
- /* do not try to run the jobs from different timezones
- * during the DST switch of the default timezone.
+ /* do not try to run the jobs
+ * from different timezones
+ * during the DST switch of the
+ * default timezone.
*/
continue;
if ((doNonWild &&
!(e->flags & (MIN_STAR | HR_STAR))) ||
(doWild && (e->flags & (MIN_STAR | HR_STAR))))
- job_add(e, u); /*will add job, if it isn't in queue already for NOW. */
+ /*will add job, if it isn't in queue already for NOW. */
+ job_add(e, u);
}
}
}
@@ -612,7 +619,7 @@ static void set_time(int initialize) {
/*
* Try to just hit the next minute.
*/
-static void cron_sleep(int target, cron_db * db) {
+static void cron_sleep(int target, cron_db *db) {
time_t t1, t2;
int seconds_to_wait;
@@ -664,17 +671,18 @@ static void sigchld_reaper(void) {
if (errno == EINTR)
continue;
Debug(DPROC, ("[%ld] sigchld...no children\n", (long) getpid()));
- break;
+ break;
case 0:
Debug(DPROC, ("[%ld] sigchld...no dead kids\n", (long) getpid()));
- break;
+ break;
default:
Debug(DPROC,
("[%ld] sigchld...pid #%ld died, stat=%d\n",
(long) getpid(), (long) pid, WEXITSTATUS(waiter)));
- break;
+ break;
}
- } while (pid > 0);
+ }
+ while (pid > 0);
}
static void parse_args(int argc, char *argv[]) {
@@ -682,37 +690,37 @@ static void parse_args(int argc, char *argv[]) {
while (-1 != (argch = getopt(argc, argv, "hnpsiPx:m:c"))) {
switch (argch) {
- case 'x':
- if (!set_debug_flags(optarg))
- usage();
- break;
- case 'n':
- NoFork = 1;
- break;
- case 'p':
- PermitAnyCrontab = 1;
- break;
- case 's':
- SyslogOutput = 1;
- break;
- case 'i':
- DisableInotify = 1;
- break;
- case 'P':
- ChangePath = 0;
- break;
- case 'm':
- strncpy(MailCmd, optarg, MAX_COMMAND);
- if (strncmp(MailCmd, "off", 4))
- SyslogOutput = 1;
- break;
- case 'c':
- EnableClustering = 1;
- break;
- case 'h':
- default:
+ case 'x':
+ if (!set_debug_flags(optarg))
usage();
- break;
+ break;
+ case 'n':
+ NoFork = 1;
+ break;
+ case 'p':
+ PermitAnyCrontab = 1;
+ break;
+ case 's':
+ SyslogOutput = 1;
+ break;
+ case 'i':
+ DisableInotify = 1;
+ break;
+ case 'P':
+ ChangePath = 0;
+ break;
+ case 'm':
+ strncpy(MailCmd, optarg, MAX_COMMAND);
+ if (strncmp(MailCmd, "off", 4))
+ SyslogOutput = 1;
+ break;
+ case 'c':
+ EnableClustering = 1;
+ break;
+ case 'h':
+ default:
+ usage();
+ break;
}
}
}
diff --git a/src/crontab.c b/src/crontab.c
index 29c1967..8d0a325 100644
--- a/src/crontab.c
+++ b/src/crontab.c
@@ -66,10 +66,13 @@
#define NHEADER_LINES 0
-enum opt_t {opt_unknown, opt_list, opt_delete, opt_edit, opt_replace, opt_hostset,
opt_hostget};
+enum opt_t { opt_unknown, opt_list, opt_delete, opt_edit, opt_replace,
+ opt_hostset, opt_hostget
+};
#if DEBUGGING
-static const char *Options[] = {"???", "list", "delete",
"edit", "replace", "hostset", "hostget"};
+static const char *Options[] =
+ { "???", "list", "delete", "edit",
"replace", "hostset", "hostget" };
# ifdef WITH_SELINUX
static const char *getoptargs = "u:lerisncx:";
@@ -129,7 +132,7 @@ int main(int argc, char *argv[]) {
int exitstatus;
const char *n = "-"; /*set the n string to - so we have a valid string to use
*/
- if ((ProgramName=strrchr(argv[0], '/')) == NULL) {
+ if ((ProgramName = strrchr(argv[0], '/')) == NULL) {
ProgramName = argv[0];
}
else {
@@ -146,7 +149,8 @@ int main(int argc, char *argv[]) {
setlinebuf(stderr);
#endif
/*should we desire to make changes to behavior later. */
- if (argv[1] == NULL) { /* change behavior to allow crontab to take stdin with no
'-' */
+ if (argv[1] == NULL) {
+ /* change behavior to allow crontab to take stdin with no '-' */
argv[1] = n;
}
parse_args(argc, argv); /* sets many globals, opens a file */
@@ -242,8 +246,7 @@ static void parse_args(int argc, char *argv[]) {
}
#endif
if (Option == opt_hostset || Option == opt_hostget) {
- fprintf(stderr,
- "cannot use -u with -n or -c\n");
+ fprintf(stderr, "cannot use -u with -n or -c\n");
exit(ERROR_EXIT);
}
@@ -276,7 +279,7 @@ static void parse_args(int argc, char *argv[]) {
break;
#ifdef WITH_SELINUX
case 's':
- if (getprevcon((security_context_t *) & (selinux_context))) {
+ if (getprevcon((security_context_t *) &(selinux_context))) {
fprintf(stderr, "Cannot obtain SELinux process context\n");
exit(ERROR_EXIT);
}
@@ -284,15 +287,13 @@ static void parse_args(int argc, char *argv[]) {
#endif
case 'n':
if (MY_UID(pw) != ROOT_UID) {
- fprintf(stderr,
- "must be privileged to set host with -n\n");
+ fprintf(stderr, "must be privileged to set host with -n\n");
exit(ERROR_EXIT);
}
if (Option != opt_unknown)
usage("only one operation permitted");
if (strcmp(User, RealUser) != 0) {
- fprintf(stderr,
- "cannot use -u with -n or -c\n");
+ fprintf(stderr, "cannot use -u with -n or -c\n");
exit(ERROR_EXIT);
}
Option = opt_hostset;
@@ -301,8 +302,7 @@ static void parse_args(int argc, char *argv[]) {
if (Option != opt_unknown)
usage("only one operation permitted");
if (strcmp(User, RealUser) != 0) {
- fprintf(stderr,
- "cannot use -u with -n or -c\n");
+ fprintf(stderr, "cannot use -u with -n or -c\n");
exit(ERROR_EXIT);
}
Option = opt_hostget;
@@ -314,7 +314,7 @@ static void parse_args(int argc, char *argv[]) {
endpwent();
- if (Option == opt_hostset && argv[optind] != NULL) {
+ if (Option == opt_hostset && argv[optind] != NULL) {
HostSpecified = 1;
if (strlen(argv[optind]) >= sizeof Host)
usage("hostname too long");
@@ -388,8 +388,7 @@ static void list_cmd(void) {
/* file is open. copy to stdout, close.
*/
- Set_LineNum(1)
- while (EOF != (ch = get_char(f)))
+ Set_LineNum(1) while (EOF != (ch = get_char(f)))
putchar(ch);
fclose(f);
}
@@ -400,8 +399,7 @@ static void delete_cmd(void) {
printf("crontab: really delete %s's crontab? ", User);
fflush(stdout);
if ((fgets(n, MAX_FNAME - 1, stdin) == 0L)
- || ((n[0] != 'Y') && (n[0] != 'y'))
- )
+ || ((n[0] != 'Y') && (n[0] != 'y')))
exit(0);
}
@@ -434,8 +432,7 @@ static char *tmp_path() {
return tmpdir ? tmpdir : "/tmp";
}
-static char *host_specific_filename(const char *filename, int prefix)
-{
+static char *host_specific_filename(const char *filename, int prefix) {
/*
* For cluster-wide use, where there is otherwise risk of the same
* name being generated on more than one host at once, prefix with
@@ -452,7 +449,8 @@ static char *host_specific_filename(const char *filename, int prefix)
if (prefix) {
if (!glue_strings(safename, sizeof safename, hostname, filename, '.'))
return NULL;
- } else {
+ }
+ else {
if (!glue_strings(safename, sizeof safename, filename, hostname, '.'))
return NULL;
}
@@ -516,7 +514,7 @@ static void edit_cmd(void) {
}
Set_LineNum(1)
- /*
+ /*
* NHEADER_LINES processing removed for clarity
* (NHEADER_LINES == 0 in all Red Hat crontabs)
*/
@@ -553,10 +551,10 @@ static void edit_cmd(void) {
perror(Filename);
exit(ERROR_EXIT);
}
- if (swap_uids() == -1) {
- perror("swapping uids");
- exit(ERROR_EXIT);
- }
+ if (swap_uids() == -1) {
+ perror("swapping uids");
+ exit(ERROR_EXIT);
+ }
/* Set it to 1970 */
utimebuf.actime = 0;
utimebuf.modtime = 0;
@@ -647,7 +645,7 @@ static void edit_cmd(void) {
(void) signal(SIGINT, SIG_DFL);
(void) signal(SIGQUIT, SIG_DFL);
- /* lstat doesn't make any harm, because
+ /* lstat doesn't make any harm, because
* the file is stat'ed only when crontab is touched
*/
if (lstat(Filename, &statbuf) < 0) {
@@ -735,7 +733,8 @@ static int replace_cmd(void) {
safename = host_specific_filename("tmp.XXXXXXXXXX", 1);
- if (!safename || !glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR,
+ if (!safename
+ || !glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR,
safename, '/')) {
TempFilename[0] = '\0';
fprintf(stderr, "path too long\n");
@@ -771,8 +770,7 @@ static int replace_cmd(void) {
/* copy the crontab to the tmp
*/
rewind(NewCrontab);
- Set_LineNum(1)
- while (EOF != (ch = get_char(NewCrontab)))
+ Set_LineNum(1) while (EOF != (ch = get_char(NewCrontab)))
putc(ch, tmp);
if (ftruncate(fileno(tmp), ftell(tmp)) == -1) {
fprintf(stderr, "%s: error while writing new crontab to %s\n",
@@ -798,8 +796,7 @@ static int replace_cmd(void) {
* in the file proper -- kludged it by stopping after first error.
* vix 31mar87
*/
- Set_LineNum(1 - NHEADER_LINES)
- CheckErrorCount = 0;
+ Set_LineNum(1 - NHEADER_LINES) CheckErrorCount = 0;
eof = FALSE;
envp = env_init();
@@ -838,7 +835,8 @@ static int replace_cmd(void) {
goto done;
}
- file_owner = (getgid() == geteuid() && getgid() == getegid()) ? ROOT_UID :
pw->pw_uid;
+ file_owner = (getgid() == geteuid() &&
+ getgid() == getegid())? ROOT_UID : pw->pw_uid;
#ifdef HAVE_FCHOWN
if (fchown(fileno(tmp), file_owner, -1) < OK) {
@@ -896,13 +894,14 @@ static int hostset_cmd(void) {
int fd;
int error = 0;
char *safename;
-
+
if (!HostSpecified)
gethostname(Host, sizeof Host);
-
+
safename = host_specific_filename("tmp.XXXXXXXXXX", 1);
- if (!safename || !glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR,
- safename, '/')) {
+ if (!safename
+ || !glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR,
+ safename, '/')) {
TempFilename[0] = '\0';
fprintf(stderr, "path too long\n");
return (-2);
@@ -921,7 +920,7 @@ static int hostset_cmd(void) {
(void) signal(SIGINT, die);
(void) signal(SIGQUIT, die);
- (void) fchmod(fd, 0600); /* not all mkstemp() implementations do this */
+ (void) fchmod(fd, 0600); /* not all mkstemp() implementations do this */
if (fprintf(tmp, "%s\n", Host) < 0 || fclose(tmp) == EOF) {
fprintf(stderr, "%s: error while writing to %s\n",
@@ -973,7 +972,7 @@ static int hostget_cmd(void) {
fprintf(stderr, "File %s not found\n", n);
else
perror(n);
- return (-2);
+ return (-2);
}
if (get_string(Host, sizeof Host, f, "\n") == EOF) {
diff --git a/src/database.c b/src/database.c
index 5811f08..acf37f0 100644
--- a/src/database.c
+++ b/src/database.c
@@ -68,13 +68,12 @@ static void max_mtime(const char *dir_name, struct stat *max_st);
static int
check_open(const char *tabname, const char *uname,
- struct passwd *pw, time_t * mtime) {
+ struct passwd *pw, time_t *mtime) {
struct stat statbuf;
int crontab_fd;
pid_t pid = getpid();
- if ((crontab_fd =
- open(tabname, O_RDONLY | O_NONBLOCK, 0)) == -1) {
+ if ((crontab_fd = open(tabname, O_RDONLY | O_NONBLOCK, 0)) == -1) {
log_it(uname, pid, "CAN'T OPEN", tabname, errno);
return (-1);
}
@@ -113,16 +112,14 @@ check_open(const char *tabname, const char *uname,
static orphan *orphans;
-static void
-free_orphan(orphan *o) {
+static void free_orphan(orphan *o) {
free(o->tabname);
free(o->fname);
free(o->uname);
free(o);
}
-void
-check_orphans(cron_db *db) {
+void check_orphans(cron_db *db) {
orphan *prev_orphan = NULL;
orphan *o = orphans;
@@ -132,12 +129,12 @@ check_orphans(cron_db *db) {
if (prev_orphan == NULL) {
orphans = next;
- } else {
+ }
+ else {
prev_orphan->next = next;
}
- process_crontab(o->uname, o->fname, o->tabname,
- db, NULL);
+ process_crontab(o->uname, o->fname, o->tabname, db, NULL);
/* process_crontab could have added a new orphan */
if (prev_orphan == NULL && orphans != next) {
@@ -145,7 +142,8 @@ check_orphans(cron_db *db) {
}
free_orphan(o);
o = next;
- } else {
+ }
+ else {
prev_orphan = o;
o = o->next;
}
@@ -156,33 +154,33 @@ static void
add_orphan(const char *uname, const char *fname, const char *tabname) {
orphan *o;
- o = calloc(1, sizeof(*o));
+ o = calloc(1, sizeof (*o));
if (o == NULL)
return;
if (uname)
- if ((o->uname=strdup(uname)) == NULL)
+ if ((o->uname = strdup(uname)) == NULL)
goto cleanup;
if (fname)
- if ((o->fname=strdup(fname)) == NULL)
+ if ((o->fname = strdup(fname)) == NULL)
goto cleanup;
if (tabname)
- if ((o->tabname=strdup(tabname)) == NULL)
+ if ((o->tabname = strdup(tabname)) == NULL)
goto cleanup;
o->next = orphans;
orphans = o;
return;
-cleanup:
+ cleanup:
free_orphan(o);
}
static void
process_crontab(const char *uname, const char *fname, const char *tabname,
- cron_db * new_db, cron_db * old_db) {
+ cron_db *new_db, cron_db *old_db) {
struct passwd *pw = NULL;
int crontab_fd = -1;
user *u = NULL;
@@ -209,7 +207,8 @@ process_crontab(const char *uname, const char *fname, const char
*tabname,
Debug(DLOAD, ("\t%s:", fname));
if (old_db != NULL)
- u = find_user(old_db, fname, crond_crontab ? tabname : NULL); /* find user in old_db
*/
+ /* find user in old_db */
+ u = find_user(old_db, fname, crond_crontab ? tabname : NULL);
if (u != NULL) {
/* if crontab has not changed since we last read it
@@ -217,7 +216,7 @@ process_crontab(const char *uname, const char *fname, const char
*tabname,
*/
if (u->mtime == mtime) {
Debug(DLOAD, (" [no change, using old data]"));
- unlink_user(old_db, u);
+ unlink_user(old_db, u);
link_user(new_db, u);
goto next_crontab;
}
@@ -230,13 +229,13 @@ process_crontab(const char *uname, const char *fname, const char
*tabname,
* we finish with the crontab...
*/
Debug(DLOAD, (" [delete old data]"));
- unlink_user(old_db, u);
+ unlink_user(old_db, u);
free_user(u);
log_it(fname, getpid(), "RELOAD", tabname, 0);
}
u = load_user(crontab_fd, pw, uname, fname, tabname); /* read the file */
- crontab_fd = -1; /* load_user takes care of closing the file */
+ crontab_fd = -1; /* load_user takes care of closing the file */
if (u != NULL) {
u->mtime = mtime;
link_user(new_db, u);
@@ -245,14 +244,12 @@ process_crontab(const char *uname, const char *fname, const char
*tabname,
next_crontab:
if (crontab_fd != -1) {
Debug(DLOAD, (" [done]\n"));
- close(crontab_fd);
+ close(crontab_fd);
}
}
-static int
-cluster_host_is_local(void)
-{
- char filename[MAXNAMLEN+1];
+static int cluster_host_is_local(void) {
+ char filename[MAXNAMLEN + 1];
int is_local;
FILE *f;
char hostname[MAXHOSTNAMELEN], myhostname[MAXHOSTNAMELEN];
@@ -277,14 +274,16 @@ cluster_host_is_local(void)
if ((f = fopen(filename, "r"))) {
if (EOF != get_string(hostname, MAXHOSTNAMELEN, f, "\n") &&
- gethostname(myhostname, MAXHOSTNAMELEN) == 0) {
+ gethostname(myhostname, MAXHOSTNAMELEN) == 0) {
is_local = (strcmp(myhostname, hostname) == 0);
- } else {
+ }
+ else {
Debug(DLOAD, ("cluster: hostname comparison error\n"));
}
fclose(f);
- } else {
+ }
+ else {
Debug(DLOAD, ("cluster: file %s not found\n", filename));
}
}
@@ -293,7 +292,7 @@ cluster_host_is_local(void)
}
#if defined WITH_INOTIFY
-void check_inotify_database(cron_db * old_db) {
+void check_inotify_database(cron_db *old_db) {
cron_db new_db;
DIR_T *dp;
DIR *dir;
@@ -339,9 +338,9 @@ void check_inotify_database(cron_db * old_db) {
set_cron_watched(old_db->ifd);
/* TODO: parse the events and read only affected files */
-#if defined WITH_SYSCRONTAB
+# if defined WITH_SYSCRONTAB
process_crontab("root", NULL, SYSCRONTAB, &new_db, old_db);
-#endif
+# endif
if (!(dir = opendir(SYS_CROND_DIR))) {
log_it("CRON", pid, "OPENDIR FAILED", SYS_CROND_DIR, errno);
@@ -397,14 +396,14 @@ void check_inotify_database(cron_db * old_db) {
}
#endif
-static void overwrite_database(cron_db * old_db, cron_db * new_db) {
+static void overwrite_database(cron_db *old_db, cron_db *new_db) {
user *u, *nu;
/* whatever's left in the old database is now junk.
*/
Debug(DLOAD, ("unlinking old database:\n"));
- for (u = old_db->head; u != NULL; u = nu) {
+ for (u = old_db->head; u != NULL; u = nu) {
Debug(DLOAD, ("\t%s\n", u->name));
- nu = u->next;
+ nu = u->next;
unlink_user(old_db, u);
free_user(u);
}
@@ -414,7 +413,7 @@ static void overwrite_database(cron_db * old_db, cron_db * new_db) {
*old_db = *new_db;
}
-int load_database(cron_db * old_db) {
+int load_database(cron_db *old_db) {
struct stat statbuf, syscron_stat, crond_stat;
cron_db new_db;
DIR_T *dp;
@@ -424,11 +423,11 @@ int load_database(cron_db * old_db) {
Debug(DLOAD, ("[%ld] load_database()\n", (long) pid));
- /* before we start loading any data, do a stat on SPOOL_DIR
- * so that if anything changes as of this moment (i.e., before we've
- * cached any of the database), we'll see the changes next time.
- */
- if (stat(SPOOL_DIR, &statbuf) < OK) {
+ /* before we start loading any data, do a stat on SPOOL_DIR
+ * so that if anything changes as of this moment (i.e., before we've
+ * cached any of the database), we'll see the changes next time.
+ */
+ if (stat(SPOOL_DIR, &statbuf) < OK) {
log_it("CRON", pid, "STAT FAILED", SPOOL_DIR, errno);
statbuf.st_mtime = 0;
}
@@ -463,11 +462,10 @@ int load_database(cron_db * old_db) {
* time this function is called.
*/
if (old_db->mtime == TMAX(crond_stat.st_mtime,
- TMAX(statbuf.st_mtime, syscron_stat.st_mtime))
- ) {
+ TMAX(statbuf.st_mtime, syscron_stat.st_mtime))) {
Debug(DLOAD, ("[%ld] spool dir mtime unch, no load needed.\n",
(long) pid));
- return 0;
+ return 0;
}
/* something's different. make a new database, moving unchanged
@@ -542,10 +540,10 @@ int load_database(cron_db * old_db) {
overwrite_database(old_db, &new_db);
Debug(DLOAD, ("load_database is done\n"));
- return 1;
+ return 1;
}
-void link_user(cron_db * db, user * u) {
+void link_user(cron_db *db, user *u) {
if (db->head == NULL)
db->head = u;
if (db->tail)
@@ -555,7 +553,7 @@ void link_user(cron_db * db, user * u) {
db->tail = u;
}
-void unlink_user(cron_db * db, user * u) {
+void unlink_user(cron_db *db, user *u) {
if (u->prev == NULL)
db->head = u->next;
else
@@ -567,15 +565,12 @@ void unlink_user(cron_db * db, user * u) {
u->next->prev = u->prev;
}
-user *find_user(cron_db * db, const char *name, const char *tabname) {
+user *find_user(cron_db *db, const char *name, const char *tabname) {
user *u;
for (u = db->head; u != NULL; u = u->next)
if ((strcmp(u->name, name) == 0)
- && ((tabname == NULL)
- || (strcmp(tabname, u->tabname) == 0)
- )
- )
+ && ((tabname == NULL) || (strcmp(tabname, u->tabname) == 0)))
break;
return (u);
}
@@ -585,7 +580,7 @@ static int not_a_crontab(DIR_T * dp) {
/* avoid file names beginning with ".". this is good
* because we would otherwise waste two guaranteed calls
- * to getpwnam() for . and .., and there shouldn't be
+ * to getpwnam() for . and .., and there shouldn't be
* hidden files in here anyway
*/
if (dp->d_name[0] == '.')
@@ -597,7 +592,7 @@ static int not_a_crontab(DIR_T * dp) {
/* ignore CRON_HOSTNAME file (in case doesn't start with ".") */
if (0 == strcmp(dp->d_name, CRON_HOSTNAME))
- return(1);
+ return (1);
len = strlen(dp->d_name);
@@ -630,7 +625,7 @@ static void max_mtime(const char *dir_name, struct stat *max_st) {
while (NULL != (dp = readdir(dir))) {
char tabname[MAXNAMLEN + 1];
- if ( not_a_crontab ( dp ) && strcmp(dp->d_name, CRON_HOSTNAME) != 0)
+ if (not_a_crontab(dp) && strcmp(dp->d_name, CRON_HOSTNAME) != 0)
continue;
if (!glue_strings(tabname, sizeof tabname, dir_name, dp->d_name, '/'))
diff --git a/src/do_command.c b/src/do_command.c
index 1fa4c02..4b576a8 100644
--- a/src/do_command.c
+++ b/src/do_command.c
@@ -43,7 +43,7 @@
static int child_process(entry *, char **);
static int safe_p(const char *, const char *);
-void do_command(entry * e, user * u) {
+void do_command(entry *e, user *u) {
pid_t pid = getpid();
int ev;
char **jobenv = 0L;
@@ -52,21 +52,22 @@ void do_command(entry * e, user * u) {
(long) pid, e->cmd, u->name,
(long) e->pwd->pw_uid, (long) e->pwd->pw_gid));
- /* fork to become asynchronous -- parent process is done immediately,
- * and continues to run the normal cron code, which means return to
- * tick(). the child and grandchild don't leave this function, alive.
- *
- * vfork() is unsuitable, since we have much to do, and the parent
- * needs to be able to run off and fork other processes.
- */
- switch (fork()) {
+ /* fork to become asynchronous -- parent process is done immediately,
+ * and continues to run the normal cron code, which means return to
+ * tick(). the child and grandchild don't leave this function, alive.
+ *
+ * vfork() is unsuitable, since we have much to do, and the parent
+ * needs to be able to run off and fork other processes.
+ */
+ switch (fork()) {
case -1:
log_it("CRON", pid, "CAN'T FORK", "do_command",
errno);
break;
case 0:
/* child process */
acquire_daemonlock(1);
- /* Set up the Red Hat security context for both mail/minder and job processes:
+ /* Set up the Red Hat security context for both mail/minder and
+ * job processes:
*/
if (cron_set_job_security_context(e, u, &jobenv) != 0) {
_exit(ERROR_EXIT);
@@ -84,7 +85,7 @@ void do_command(entry * e, user * u) {
Debug(DPROC, ("[%ld] main process returning to work\n", (long) pid));
}
-static int child_process(entry * e, char **jobenv) {
+static int child_process(entry *e, char **jobenv) {
int stdin_pipe[2], stdout_pipe[2];
char *input_data, *usernm, *mailto = NULL, *mailfrom = NULL;
int children = 0;
@@ -92,8 +93,8 @@ static int child_process(entry * e, char **jobenv) {
struct sigaction sa;
/* Ignore SIGPIPE as we will be writing to pipes and do not want to terminate
- prematurely */
- memset(&sa, 0, sizeof(sa));
+ * prematurely */
+ memset(&sa, 0, sizeof (sa));
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
@@ -108,10 +109,11 @@ static int child_process(entry * e, char **jobenv) {
Debug(DPROC, ("[%ld] child_process('%s')\n", (long) getpid(),
e->cmd));
#ifdef CAPITALIZE_FOR_PS
- /* mark ourselves as different to PS command watchers by upshifting
- * our program name. This has no effect on some kernels.
- */
- /*local */ {
+ /* mark ourselves as different to PS command watchers by upshifting
+ * our program name. This has no effect on some kernels.
+ */
+ /*local */
+ {
char *pch;
for (pch = ProgramName; *pch; pch++)
@@ -148,7 +150,8 @@ static int child_process(entry * e, char **jobenv) {
* from it. Subsequent %'s will be transformed into newlines,
* but that happens later.
*/
- /*local */ {
+ /*local */
+ {
int escaped = FALSE;
int ch;
char *p;
@@ -182,8 +185,7 @@ static int child_process(entry * e, char **jobenv) {
case -1:
log_it("CRON", pid, "CAN'T FORK", "child_process",
errno);
return ERROR_EXIT;
- /*NOTREACHED*/
- case 0:
+ /*NOTREACHED*/ case 0:
Debug(DPROC, ("[%ld] grandchild process fork()'ed\n", (long) getpid()));
/* write a log message. we've waited this long to do it
@@ -357,7 +359,8 @@ static int child_process(entry * e, char **jobenv) {
Debug(DPROC, ("[%ld] child reading output from grandchild\n",
(long) getpid()));
- /*local */ {
+ /*local */
+ {
FILE *in = fdopen(stdout_pipe[READ_PIPE], "r");
int ch = getc(in);
@@ -378,10 +381,10 @@ static int child_process(entry * e, char **jobenv) {
("[%ld] got data (%x:%c) from grandchild\n",
(long) getpid(), ch, ch));
- /* get name of recipient. this is MAILTO if set to a
- * valid local username; USER otherwise.
- */
- if (mailto) {
+ /* get name of recipient. this is MAILTO if set to a
+ * valid local username; USER otherwise.
+ */
+ if (mailto) {
/* MAILTO was present in the environment
*/
if (!*mailto) {
@@ -399,7 +402,8 @@ static int child_process(entry * e, char **jobenv) {
/* get sender address. this is MAILFROM if set (and safe),
* the user account name otherwise.
*/
- if (!SyslogOutput && (!mailfrom || !*mailfrom || !safe_p(usernm, mailfrom)))
{
+ if (!SyslogOutput && (!mailfrom || !*mailfrom ||
+ !safe_p(usernm, mailfrom))) {
mailfrom = e->pwd->pw_name;
}
@@ -420,8 +424,8 @@ static int child_process(entry * e, char **jobenv) {
gethostname(hostname, MAXHOSTNAMELEN);
if (MailCmd[0] == '\0') {
- if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG, mailfrom)
- >= sizeof mailcmd) {
+ if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG,
+ mailfrom) >= sizeof mailcmd) {
fprintf(stderr, "mailcmd too long\n");
(void) _exit(ERROR_EXIT);
}
@@ -446,16 +450,15 @@ static int child_process(entry * e, char **jobenv) {
fprintf(mail, "Content-Type: text/plain; charset=%s\n",
cron_default_mail_charset);
}
- else { /* user specified Content-Type header.
- * disallow new-lines for security reasons
- * (else users could specify arbitrary mail headers!)
- */
+ else { /* user specified Content-Type header.
+ * disallow new-lines for security reasons
+ * (else users could specify arbitrary mail headers!)
+ */
char *nl = content_type;
size_t ctlen = strlen(content_type);
while ((*nl != '\0')
&& ((nl = strchr(nl, '\n')) != 0L)
- && (nl < (content_type + ctlen))
- )
+ && (nl < (content_type + ctlen)))
*nl = ' ';
fprintf(mail, "Content-Type: %s\n", content_type);
}
@@ -464,8 +467,7 @@ static int child_process(entry * e, char **jobenv) {
size_t ctlen = strlen(content_transfer_encoding);
while ((*nl != '\0')
&& ((nl = strchr(nl, '\n')) != 0L)
- && (nl < (content_transfer_encoding + ctlen))
- )
+ && (nl < (content_transfer_encoding + ctlen)))
*nl = ' ';
fprintf(mail, "Content-Transfer-Encoding: %s\n",
content_transfer_encoding);
@@ -498,9 +500,9 @@ static int child_process(entry * e, char **jobenv) {
#if defined(SYSLOG)
if (SyslogOutput) {
logbuf[bufidx++] = ch;
- if ((ch == '\n') || (bufidx == sizeof(logbuf)-1)) {
+ if ((ch == '\n') || (bufidx == sizeof (logbuf) - 1)) {
if (ch == '\n')
- logbuf[bufidx-1] = '\0';
+ logbuf[bufidx - 1] = '\0';
else
logbuf[bufidx] = '\0';
log_it(usernm, getpid(), "CMDOUT", logbuf, 0);
@@ -515,13 +517,13 @@ static int child_process(entry * e, char **jobenv) {
if (mail) {
Debug(DPROC, ("[%ld] closing pipe to mail\n", (long) getpid()));
- /* Note: the pclose will probably see
- * the termination of the grandchild
- * in addition to the mail process, since
- * it (the grandchild) is likely to exit
- * after closing its stdout.
- */
- status = cron_pclose(mail);
+ /* Note: the pclose will probably see
+ * the termination of the grandchild
+ * in addition to the mail process, since
+ * it (the grandchild) is likely to exit
+ * after closing its stdout.
+ */
+ status = cron_pclose(mail);
}
#if defined(SYSLOG)
if (SyslogOutput) {
@@ -560,18 +562,18 @@ static int child_process(entry * e, char **jobenv) {
Debug(DPROC, ("[%ld] waiting for grandchild #%d to finish\n",
(long) getpid(), children));
- while ((child = wait(&waiter)) < OK && errno == EINTR) ;
+ while ((child = wait(&waiter)) < OK && errno == EINTR) ;
if (child < OK) {
Debug(DPROC,
("[%ld] no more grandchildren--mail written?\n",
(long) getpid()));
- break;
+ break;
}
Debug(DPROC, ("[%ld] grandchild #%ld finished, status=%04x",
(long) getpid(), (long) child, WEXITSTATUS(waiter)));
- if (WIFSIGNALED(waiter) && WCOREDUMP(waiter))
+ if (WIFSIGNALED(waiter) && WCOREDUMP(waiter))
Debug(DPROC, (", dumped core"));
- Debug(DPROC, ("\n"));
+ Debug(DPROC, ("\n"));
}
return OK_EXIT;
}
diff --git a/src/entry.c b/src/entry.c
index 0b482b9..a54b255 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -66,7 +66,7 @@ get_range(bitstr_t *, int, int, const char *[], int, FILE *),
get_number(int *, int, const char *[], int, FILE *, const char *),
set_element(bitstr_t *, int, int, int);
-void free_entry(entry * e) {
+void free_entry(entry *e) {
free(e->cmd);
free(e->pwd);
env_free(e->envp);
@@ -76,7 +76,7 @@ void free_entry(entry * e) {
/* return NULL if eof or syntax error occurs;
* otherwise return a pointer to a new entry.
*/
-entry *load_entry(FILE * file, void (*error_func) (), struct passwd *pw,
+entry *load_entry(FILE *file, void (*error_func) (), struct passwd *pw,
char **envp) {
/* this function reads one crontab entry -- the next -- from a file.
* it skips any leading blank lines, ignores comments, and returns
@@ -100,7 +100,7 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd
*pw,
Debug(DPARS, ("load_entry()...about to eat comments\n"));
- skip_comments(file);
+ skip_comments(file);
ch = get_char(file);
if (ch == EOF)
@@ -113,17 +113,18 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd
*pw,
e = (entry *) calloc(sizeof (entry), sizeof (char));
- /* check for '-' as a first character, this option will disable
- * writing a syslog message about command getting executed
- */
+ /* check for '-' as a first character, this option will disable
+ * writing a syslog message about command getting executed
+ */
if (ch == '-') {
- /* if we are editing system crontab or user uid is 0 (root)
- * we are allowed to disable logging
- */
+ /* if we are editing system crontab or user uid is 0 (root)
+ * we are allowed to disable logging
+ */
if (pw == NULL || pw->pw_uid == 0)
e->flags |= DONT_LOG;
else {
- log_it("CRON", getpid(), "ERROR", "Only privileged user can
disable logging", 0);
+ log_it("CRON", getpid(), "ERROR",
+ "Only privileged user can disable logging", 0);
ecode = e_option;
goto eof;
}
@@ -274,10 +275,10 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd
*pw,
char *username = cmd; /* temp buffer */
Debug(DPARS, ("load_entry()...about to parse username\n"));
- ch = get_string(username, MAX_COMMAND, file, " \t\n");
+ ch = get_string(username, MAX_COMMAND, file, " \t\n");
Debug(DPARS, ("load_entry()...got %s\n", username));
- if (ch == EOF || ch == '\n' || ch == '*') {
+ if (ch == EOF || ch == '\n' || ch == '*') {
ecode = e_cmd;
goto eof;
}
@@ -385,9 +386,9 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd
*pw,
Debug(DPARS, ("load_entry()...returning successfully\n"));
- /* success, fini, return pointer to the entry we just created...
- */
- return (e);
+ /* success, fini, return pointer to the entry we just created...
+ */
+ return (e);
eof:
if (e->envp)
@@ -405,8 +406,8 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd
*pw,
}
static int
-get_list(bitstr_t * bits, int low, int high, const char *names[],
- int ch, FILE * file) {
+get_list(bitstr_t *bits, int low, int high, const char *names[],
+ int ch, FILE *file) {
int done;
/* we know that we point to a non-blank character here;
@@ -417,11 +418,11 @@ get_list(bitstr_t * bits, int low, int high, const char *names[],
Debug(DPARS | DEXT, ("get_list()...entered\n"));
- /* list = range {"," range}
- */
- /* clear the bit string, since the default is 'off'.
- */
- bit_nclear(bits, 0, (high - low));
+ /* list = range {"," range}
+ */
+ /* clear the bit string, since the default is 'off'.
+ */
+ bit_nclear(bits, 0, (high - low));
/* process all ranges
*/
@@ -439,16 +440,15 @@ get_list(bitstr_t * bits, int low, int high, const char *names[],
*/
Skip_Nonblanks(ch, file)
Skip_Blanks(ch, file)
-
Debug(DPARS | DEXT, ("get_list()...exiting w/ %02x\n", ch));
- return (ch);
+ return (ch);
}
static int
-get_range(bitstr_t * bits, int low, int high, const char *names[],
- int ch, FILE * file) {
+get_range(bitstr_t *bits, int low, int high, const char *names[],
+ int ch, FILE *file) {
/* range = number | number "-" number [ "/" number ]
*/
@@ -456,7 +456,7 @@ get_range(bitstr_t * bits, int low, int high, const char *names[],
Debug(DPARS | DEXT, ("get_range()...entering, exit won't show\n"));
- if (ch == '*') {
+ if (ch == '*') {
/* '*' means "first-last" but can still be modified by /step
*/
num1 = low;
@@ -533,7 +533,7 @@ get_range(bitstr_t * bits, int low, int high, const char *names[],
}
static int
-get_number(int *numptr, int low, const char *names[], int ch, FILE * file,
+get_number(int *numptr, int low, const char *names[], int ch, FILE *file,
const char *terms) {
char temp[MAX_TEMPSTR], *pc;
int len, i;
@@ -570,7 +570,7 @@ get_number(int *numptr, int low, const char *names[], int ch, FILE *
file,
for (i = 0; names[i] != NULL; i++) {
Debug(DPARS | DEXT,
("get_num, compare(%s,%s)\n", names[i], temp));
- if (!strcasecmp(names[i], temp)) {
+ if (!strcasecmp(names[i], temp)) {
*numptr = i + low;
return (ch);
}
@@ -583,10 +583,10 @@ get_number(int *numptr, int low, const char *names[], int ch, FILE *
file,
return (EOF);
}
-static int set_element(bitstr_t * bits, int low, int high, int number) {
+static int set_element(bitstr_t *bits, int low, int high, int number) {
Debug(DPARS | DEXT, ("set_element(?,%d,%d,%d)\n", low, high, number));
- if (number < low || number > high)
+ if (number < low || number > high)
return (EOF);
bit_set(bits, (number - low));
diff --git a/src/env.c b/src/env.c
index 772e9a0..5a175ee 100644
--- a/src/env.c
+++ b/src/env.c
@@ -128,7 +128,7 @@ enum env_state {
* FALSE = not an env setting (file was repositioned)
* TRUE = was an env setting
*/
-int load_env(char *envstr, FILE * f) {
+int load_env(char *envstr, FILE *f) {
long filepos;
int fileline;
enum env_state state;
@@ -143,7 +143,7 @@ int load_env(char *envstr, FILE * f) {
Debug(DPARS, ("load_env, read <%s>\n", envstr));
- memset(name, 0, sizeof name);
+ memset(name, 0, sizeof name);
memset(val, 0, sizeof val);
str = name;
state = NAMEI;
@@ -213,7 +213,7 @@ int load_env(char *envstr, FILE * f) {
}
if (state != FINI && !(state == VALUE && !quotechar)) {
Debug(DPARS, ("load_env, not an env var, state = %d\n", state));
- fseek(f, filepos, 0);
+ fseek(f, filepos, 0);
Set_LineNum(fileline);
return (FALSE);
}
@@ -233,7 +233,7 @@ int load_env(char *envstr, FILE * f) {
if (!glue_strings(envstr, MAX_ENVSTR, name, val, '='))
return (FALSE);
Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val,
envstr));
- return (TRUE);
+ return (TRUE);
}
char *env_get(const char *name, char **envp) {
diff --git a/src/job.c b/src/job.c
index 8ad14db..5c2a02a 100644
--- a/src/job.c
+++ b/src/job.c
@@ -34,7 +34,7 @@ typedef struct _job {
static job *jhead = NULL, *jtail = NULL;
-void job_add(entry * e, user * u) {
+void job_add(entry *e, user *u) {
job *j;
/* if already on queue, keep going */
diff --git a/src/misc.c b/src/misc.c
index 70c7daf..3e121ca 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -155,7 +155,8 @@ int strdtb(char *s) {
*/
do {
x--;
- } while (x >= s && isspace((unsigned char) *x));
+ }
+ while (x >= s && isspace((unsigned char) *x));
/* one character beyond where we stopped above is where the null
* goes.
@@ -363,21 +364,20 @@ void acquire_daemonlock(int closeflag) {
/* get_char(file) : like getc() but increment LineNumber on newlines
*/
-int get_char(FILE * file) {
+int get_char(FILE *file) {
int ch;
ch = getc(file);
if (ch == '\n')
- Set_LineNum(LineNumber + 1)
- return (ch);
+ Set_LineNum(LineNumber + 1) return (ch);
}
/* unget_char(ch, file) : like ungetc but do LineNumber processing
*/
-void unget_char(int ch, FILE * file) {
+void unget_char(int ch, FILE *file) {
ungetc(ch, file);
if (ch == '\n')
- Set_LineNum(LineNumber - 1)
+ Set_LineNum(LineNumber - 1);
}
/* get_string(str, max, file, termstr) : like fgets() but
@@ -386,7 +386,7 @@ void unget_char(int ch, FILE * file) {
* (3) uses get_char() so LineNumber will be accurate
* (4) returns EOF or terminating character, whichever
*/
-int get_string(char *string, int size, FILE * file, const char *terms) {
+int get_string(char *string, int size, FILE *file, const char *terms) {
int ch;
while (EOF != (ch = get_char(file)) && !strchr(terms, ch)) {
@@ -404,7 +404,7 @@ int get_string(char *string, int size, FILE * file, const char *terms)
{
/* skip_comments(file) : read past comment (if any)
*/
-void skip_comments(FILE * file) {
+void skip_comments(FILE *file) {
int ch;
while (EOF != (ch = get_char(file))) {
@@ -441,7 +441,7 @@ void skip_comments(FILE * file) {
* return TRUE if one of the lines in file matches string exactly,
* FALSE if no lines match, and error on error.
*/
-static int in_file(const char *string, FILE * file, int error) {
+static int in_file(const char *string, FILE *file, int error) {
char line[MAX_TEMPSTR];
char *endp;
@@ -467,8 +467,7 @@ static int in_file(const char *string, FILE * file, int error) {
* or (deny_file exists and user is NOT listed).
* root is always allowed.
*/
-int allowed(const char *username, const char *allow_file,
- const char *deny_file) {
+int allowed(const char *username, const char *allow_file, const char *deny_file) {
FILE *fp;
int isallowed;
char buf[128];
@@ -524,9 +523,7 @@ void log_it(const char *username, PID_T xpid, const char *event,
*/
msg = malloc(msg_size = (strlen(username)
+ strlen(event)
- + strlen(detail)
- + MAX_TEMPSTR)
- );
+ + strlen(detail) + MAX_TEMPSTR));
if (msg == NULL) { /* damn, out of mem and we did not test that before... */
fprintf(stderr, "%s: Run OUT OF MEMORY while %s\n",
ProgramName, __FUNCTION__);
@@ -549,8 +546,9 @@ void log_it(const char *username, PID_T xpid, const char *event,
*/
snprintf(msg, msg_size,
"%s (%02d/%02d-%02d:%02d:%02d-%d) %s (%s)%s%s\n", username,
- t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, pid,
- event, detail, err != 0 ? ": " : "", err != 0 ? strerror(err) :
"");
+ t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,
+ pid, event, detail, err != 0 ? ": " : "",
+ err != 0 ? strerror(err) : "");
/* we have to run strlen() because sprintf() returns (char*) on old BSD
*/
@@ -579,9 +577,9 @@ void log_it(const char *username, PID_T xpid, const char *event,
err != 0 ? ": " : "", err != 0 ? strerror(err) : "");
-#endif /*SYSLOG*/
+#endif /*SYSLOG*/
#if DEBUGGING
- if (DebugFlags) {
+ if (DebugFlags) {
fprintf(stderr, "log_it: (%s %ld) %s (%s)%s%s\n",
username, (long) pid, event, detail,
err != 0 ? ": " : "", err != 0 ? strerror(err) : "");
@@ -597,7 +595,7 @@ void log_close(void) {
#if defined(SYSLOG)
closelog();
syslog_open = FALSE;
-#endif /*SYSLOG*/
+#endif /*SYSLOG*/
}
/* char *first_word(char *s, char *t)
@@ -686,8 +684,7 @@ char *arpadate(time_t *clock) {
struct tm tm = *localtime(&t);
long gmtoff = get_gmtoff(&t, &tm);
int hours = gmtoff / SECONDS_PER_HOUR;
- int minutes =
- (gmtoff - (hours * SECONDS_PER_HOUR)) / SECONDS_PER_MINUTE;
+ int minutes = (gmtoff - (hours * SECONDS_PER_HOUR)) / SECONDS_PER_MINUTE;
static char ret[64]; /* zone name might be >3 chars */
(void) sprintf(ret, "%s, %2d %s %2d %02d:%02d:%02d %.2d%.2d (%s)",
@@ -701,8 +698,8 @@ char *arpadate(time_t *clock) {
#endif /*MAIL_DATE */
#ifdef HAVE_SAVED_UIDS
- static uid_t save_euid;
- static gid_t save_egid;
+static uid_t save_euid;
+static gid_t save_egid;
int swap_uids(void) {
save_egid = getegid();
@@ -718,7 +715,7 @@ int swap_uids_back(void) {
int swap_uids(void) {
return ((setregid(getegid(), getgid())
- || setreuid(geteuid(), getuid())) ? -1 : 0);
+ || setreuid(geteuid(), getuid()))? -1 : 0);
}
int swap_uids_back(void) {
@@ -745,7 +742,7 @@ size_t strlens(const char *last, ...) {
* If the local pointer is non-NULL it *must* point to a local copy.
*/
#ifndef HAVE_STRUCT_TM_TM_GMTOFF
-long get_gmtoff(time_t * clock, struct tm *local) {
+long get_gmtoff(time_t *clock, struct tm *local) {
struct tm gmt;
long offset;
diff --git a/src/popen.c b/src/popen.c
index aa36ff7..65fa2cb 100644
--- a/src/popen.c
+++ b/src/popen.c
@@ -117,7 +117,7 @@ FILE *cron_popen(char *program, const char *type, struct passwd *pw)
{
}
/* reset SIGPIPE to default for the child */
- memset(&sa, 0, sizeof(sa));
+ memset(&sa, 0, sizeof (sa));
sa.sa_handler = SIG_DFL;
sigaction(SIGPIPE, &sa, NULL);
@@ -152,7 +152,7 @@ FILE *cron_popen(char *program, const char *type, struct passwd *pw)
{
return (iop);
}
-int cron_pclose(FILE * iop) {
+int cron_pclose(FILE *iop) {
int fdes;
sigset_t oset, nset;
WAIT_T stat_loc;
diff --git a/src/pw_dup.c b/src/pw_dup.c
index ea787cd..94efe7b 100644
--- a/src/pw_dup.c
+++ b/src/pw_dup.c
@@ -36,22 +36,21 @@
#if !defined(OpenBSD) || OpenBSD < 200105
-#include <pwd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+# include <pwd.h>
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
-#include "funcs.h"
-#include "globals.h"
+# include "funcs.h"
+# include "globals.h"
-struct passwd *
-pw_dup(const struct passwd *pw) {
- char *cp;
- size_t nsize=0, psize=0, gsize=0, dsize=0, ssize=0, total;
- struct passwd *newpw;
+struct passwd *pw_dup(const struct passwd *pw) {
+ char *cp;
+ size_t nsize = 0, psize = 0, gsize = 0, dsize = 0, ssize = 0, total;
+ struct passwd *newpw;
/* Allocate in one big chunk for easy freeing */
- total = sizeof(struct passwd);
+ total = sizeof (struct passwd);
if (pw->pw_name) {
nsize = strlen(pw->pw_name) + 1;
total += nsize;
@@ -60,12 +59,12 @@ pw_dup(const struct passwd *pw) {
psize = strlen(pw->pw_passwd) + 1;
total += psize;
}
-#ifdef LOGIN_CAP
+# ifdef LOGIN_CAP
if (pw->pw_class) {
csize = strlen(pw->pw_class) + 1;
total += csize;
}
-#endif /* LOGIN_CAP */
+# endif/* LOGIN_CAP */
if (pw->pw_gecos) {
gsize = strlen(pw->pw_gecos) + 1;
total += gsize;
@@ -80,43 +79,43 @@ pw_dup(const struct passwd *pw) {
}
if ((cp = malloc(total)) == NULL)
return (NULL);
- newpw = (struct passwd *)cp;
+ newpw = (struct passwd *) cp;
/*
* Copy in passwd contents and make strings relative to space
* at the end of the buffer.
*/
- (void)memcpy(newpw, pw, sizeof(struct passwd));
- cp += sizeof(struct passwd);
+ (void) memcpy(newpw, pw, sizeof (struct passwd));
+ cp += sizeof (struct passwd);
if (pw->pw_name) {
- (void)memcpy(cp, pw->pw_name, nsize);
+ (void) memcpy(cp, pw->pw_name, nsize);
newpw->pw_name = cp;
cp += nsize;
}
if (pw->pw_passwd) {
- (void)memcpy(cp, pw->pw_passwd, psize);
+ (void) memcpy(cp, pw->pw_passwd, psize);
newpw->pw_passwd = cp;
cp += psize;
}
-#ifdef LOGIN_CAP
+# ifdef LOGIN_CAP
if (pw->pw_class) {
- (void)memcpy(cp, pw->pw_class, csize);
+ (void) memcpy(cp, pw->pw_class, csize);
newpw->pw_class = cp;
cp += csize;
}
-#endif /* LOGIN_CAP */
+# endif/* LOGIN_CAP */
if (pw->pw_gecos) {
- (void)memcpy(cp, pw->pw_gecos, gsize);
+ (void) memcpy(cp, pw->pw_gecos, gsize);
newpw->pw_gecos = cp;
cp += gsize;
}
if (pw->pw_dir) {
- (void)memcpy(cp, pw->pw_dir, dsize);
+ (void) memcpy(cp, pw->pw_dir, dsize);
newpw->pw_dir = cp;
cp += dsize;
}
if (pw->pw_shell) {
- (void)memcpy(cp, pw->pw_shell, ssize);
+ (void) memcpy(cp, pw->pw_shell, ssize);
newpw->pw_shell = cp;
cp += ssize;
}
diff --git a/src/security.c b/src/security.c
index 98fd388..a0853c3 100644
--- a/src/security.c
+++ b/src/security.c
@@ -1,4 +1,4 @@
-/* security.c
+/* security.c
*
* Implement Red Hat crond security context transitions
*
@@ -52,23 +52,22 @@ static int pam_session_opened = 0; //global for open session
static int
cron_conv(int num_msg, const struct pam_message **msgm,
- struct pam_response **response, void *appdata_ptr)
-{
- int i;
-
- for (i = 0; i < num_msg; i++) {
- switch (msgm[i]->msg_style) {
- case PAM_ERROR_MSG:
- case PAM_TEXT_INFO:
- if (msgm[i]->msg != NULL) {
- log_it("CRON", getpid(),
"pam_message", msgm[i]->msg, 0);
- }
- break;
- default:
- break;
- }
- }
- return (0);
+ struct pam_response **response, void *appdata_ptr) {
+ int i;
+
+ for (i = 0; i < num_msg; i++) {
+ switch (msgm[i]->msg_style) {
+ case PAM_ERROR_MSG:
+ case PAM_TEXT_INFO:
+ if (msgm[i]->msg != NULL) {
+ log_it("CRON", getpid(), "pam_message", msgm[i]->msg, 0);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ return (0);
}
static const struct pam_conv conv = {
@@ -90,8 +89,8 @@ return(retcode); }
static char **build_env(char **cronenv);
#ifdef WITH_SELINUX
-static int cron_change_selinux_range(user * u, security_context_t ucontext);
-static int cron_get_job_range(user * u, security_context_t * ucontextp,
+static int cron_change_selinux_range(user *u, security_context_t ucontext);
+static int cron_get_job_range(user *u, security_context_t *ucontextp,
char **jobenv);
#endif
@@ -101,14 +100,14 @@ void cron_restore_default_security_context() {
#endif
}
-int cron_set_job_security_context(entry * e, user * u, char ***jobenv) {
+int cron_set_job_security_context(entry *e, user *u, char ***jobenv) {
time_t minutely_time = 0;
#ifdef WITH_PAM
int ret;
#endif
if ((e->flags & MIN_STAR) == MIN_STAR) {
- /* "minute-ly" job: Every minute for given hour/dow/month/dom.
+ /* "minute-ly" job: Every minute for given hour/dow/month/dom.
* Ensure that these jobs never run in the same minute:
*/
minutely_time = time(0);
@@ -162,7 +161,7 @@ int cron_set_job_security_context(entry * e, user * u, char ***jobenv)
{
time_t job_run_time = time(0L);
if ((minutely_time > 0) && ((job_run_time / 60) != (minutely_time / 60))) {
- /* if a per-minute job is delayed into the next minute
+ /* if a per-minute job is delayed into the next minute
* (eg. by network authentication method timeouts), skip it.
*/
struct tm tmS, tmN;
@@ -261,7 +260,8 @@ int cron_change_user_permanently(struct passwd *pw, char *homedir) {
#ifdef WITH_SELINUX
-static int cron_authorize_context(security_context_t scontext,
+static int
+cron_authorize_context(security_context_t scontext,
security_context_t file_context) {
struct av_decision avd;
int retval;
@@ -270,12 +270,14 @@ static int cron_authorize_context(security_context_t scontext,
tclass = string_to_security_class("file");
if (!tclass) {
- log_it("CRON", getpid(), "ERROR", "Failed to translate
security class file", errno);
+ log_it("CRON", getpid(), "ERROR",
+ "Failed to translate security class file", errno);
return 0;
}
bit = string_to_av_perm(tclass, "entrypoint");
if (!bit) {
- log_it("CRON", getpid(), "ERROR", "Failed to translate av perm
entrypoint", errno);
+ log_it("CRON", getpid(), "ERROR",
+ "Failed to translate av perm entrypoint", errno);
return 0;
}
/*
@@ -285,8 +287,7 @@ static int cron_authorize_context(security_context_t scontext,
* the user cron job. It performs an entrypoint
* permission check for this purpose.
*/
- retval = security_compute_av(scontext, file_context,
- tclass, bit, &avd);
+ retval = security_compute_av(scontext, file_context, tclass, bit, &avd);
if (retval || ((bit & avd.allowed) != bit))
return 0;
return 1;
@@ -294,8 +295,8 @@ static int cron_authorize_context(security_context_t scontext,
#endif
#ifdef WITH_SELINUX
-static int cron_authorize_range(security_context_t scontext,
- security_context_t ucontext) {
+static int
+cron_authorize_range(security_context_t scontext, security_context_t ucontext) {
struct av_decision avd;
int retval;
security_class_t tclass;
@@ -303,12 +304,14 @@ static int cron_authorize_range(security_context_t scontext,
tclass = string_to_security_class("context");
if (!tclass) {
- log_it("CRON", getpid(), "ERROR", "Failed to translate
security class context", errno);
+ log_it("CRON", getpid(), "ERROR",
+ "Failed to translate security class context", errno);
return 0;
}
bit = string_to_av_perm(tclass, "contains");
if (!bit) {
- log_it("CRON", getpid(), "ERROR", "Failed to translate av perm
contains", errno);
+ log_it("CRON", getpid(), "ERROR",
+ "Failed to translate av perm contains", errno);
return 0;
}
@@ -317,8 +320,7 @@ static int cron_authorize_range(security_context_t scontext,
* so crond must ensure that any user specified range
* falls within the seusers-specified range for that Linux user.
*/
- retval = security_compute_av(scontext, ucontext,
- tclass, bit, &avd);
+ retval = security_compute_av(scontext, ucontext, tclass, bit, &avd);
if (retval || ((bit & avd.allowed) != bit))
return 0;
@@ -330,7 +332,7 @@ static int cron_authorize_range(security_context_t scontext,
/* always uses u->scontext as the default process context, then changes the
level, and retuns it in ucontextp (or NULL otherwise) */
static int
-cron_get_job_range(user * u, security_context_t * ucontextp, char **jobenv) {
+cron_get_job_range(user *u, security_context_t *ucontextp, char **jobenv) {
char *range;
if (is_selinux_enabled() <= 0)
@@ -383,7 +385,7 @@ cron_get_job_range(user * u, security_context_t * ucontextp, char
**jobenv) {
#endif
#ifdef WITH_SELINUX
-static int cron_change_selinux_range(user * u, security_context_t ucontext) {
+static int cron_change_selinux_range(user *u, security_context_t ucontext) {
char *msg = NULL;
if (is_selinux_enabled() <= 0)
@@ -466,10 +468,10 @@ static int cron_change_selinux_range(user * u, security_context_t
ucontext) {
#ifdef WITH_SELINUX
int
get_security_context(const char *name, int crontab_fd,
- security_context_t * rcontext, const char *tabname) {
+ security_context_t *rcontext, const char *tabname) {
security_context_t scontext = NULL;
security_context_t file_context = NULL;
- security_context_t rawcontext=NULL;
+ security_context_t rawcontext = NULL;
int retval = 0;
char *seuser = NULL;
char *level = NULL;
@@ -523,12 +525,14 @@ get_security_context(const char *name, int crontab_fd,
}
if (!cron_authorize_context(scontext, file_context)) {
- char *msg=NULL;
+ char *msg = NULL;
if (asprintf(&msg,
- "Unauthorized SELinux context=%s file_context=%s", (char *) scontext,
file_context) >= 0) {
+ "Unauthorized SELinux context=%s file_context=%s",
+ (char *) scontext, file_context) >= 0) {
log_it(name, getpid(), msg, tabname, 0);
free(msg);
- } else {
+ }
+ else {
log_it(name, getpid(), "Unauthorized SELinux context", tabname, 0);
}
freecon(scontext);
@@ -538,8 +542,7 @@ get_security_context(const char *name, int crontab_fd,
}
else {
log_it(name, getpid(),
- "SELinux in permissive mode, continuing",
- tabname, 0);
+ "SELinux in permissive mode, continuing", tabname, 0);
return 0;
}
}
@@ -551,7 +554,7 @@ get_security_context(const char *name, int crontab_fd,
#endif
#ifdef WITH_SELINUX
-void free_security_context(security_context_t * scontext) {
+void free_security_context(security_context_t *scontext) {
if (*scontext != NULL) {
freecon(*scontext);
*scontext = 0L;
@@ -572,22 +575,23 @@ int crontab_security_access(void) {
passwd_class = string_to_security_class("passwd");
if (passwd_class == 0) {
- fprintf(stderr, "Security class \"passwd\" is not defined in the
SELinux policy.\n");
+ fprintf(stderr,
+ "Security class \"passwd\" is not defined in the SELinux
policy.\n");
retval = -1;
}
if (retval == 0) {
crontab_bit = string_to_av_perm(passwd_class, "crontab");
if (crontab_bit == 0) {
- fprintf(stderr, "Security av permission \"crontab\" is not defined in
the SELinux policy.\n");
+ fprintf(stderr,
+ "Security av permission \"crontab\" is not defined in the SELinux
policy.\n");
retval = -1;
}
}
if (retval == 0)
retval = security_compute_av_raw(user_context,
- user_context, passwd_class,
- crontab_bit, &avd);
+ user_context, passwd_class, crontab_bit, &avd);
if ((retval == 0) && ((crontab_bit & avd.allowed) == crontab_bit)) {
selinux_check_passwd_access = 0;
@@ -605,7 +609,7 @@ int crontab_security_access(void) {
#endif
/* Build up the job environment from the PAM environment plus the
-* crontab environment
+* crontab environment
*/
static char **build_env(char **cronenv) {
#ifdef WITH_PAM
diff --git a/src/user.c b/src/user.c
index 1fae04e..b8508d9 100644
--- a/src/user.c
+++ b/src/user.c
@@ -34,19 +34,16 @@
static const char *FileName;
-static void
-log_error (const char *msg)
-{
- log_it ("CRON", getpid (), msg, FileName, 0);
+static void log_error(const char *msg) {
+ log_it("CRON", getpid(), msg, FileName, 0);
}
-void
-free_user (user * u) {
+void free_user(user *u) {
entry *e, *ne;
free(u->name);
free(u->tabname);
- for (e = u->crontab; e != NULL; e = ne) {
+ for (e = u->crontab; e != NULL; e = ne) {
ne = e->next;
free_entry(e);
}
@@ -56,9 +53,8 @@ free_user (user * u) {
free(u);
}
-user *
-load_user (int crontab_fd, struct passwd *pw, const char *uname,
- const char *fname, const char *tabname) {
+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;
@@ -66,9 +62,9 @@ load_user (int crontab_fd, struct passwd *pw, const char *uname,
int status, save_errno = errno;
char **envp = NULL, **tenvp;
- if (!(file = fdopen(crontab_fd, "r"))) {
+ if (!(file = fdopen(crontab_fd, "r"))) {
save_errno = errno;
- log_it(uname, getpid (), "FAILED", "fdopen on crontab_fd in
load_user",
+ log_it(uname, getpid(), "FAILED", "fdopen on crontab_fd in
load_user",
save_errno);
close(crontab_fd);
return (NULL);
@@ -77,9 +73,9 @@ load_user (int crontab_fd, struct passwd *pw, const char *uname,
Debug(DPARS, ("load_user()\n"));
/* 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)
goto done;
- memset(u, 0, sizeof(*u));
+ memset(u, 0, sizeof (*u));
if (((u->name = strdup(fname)) == NULL)
|| ((u->tabname = strdup(tabname)) == NULL)) {
@@ -91,7 +87,7 @@ load_user (int crontab_fd, struct passwd *pw, const char *uname,
/* init environment. this will be copied/augmented for each entry.
- */
+ */
if ((envp = env_init()) == NULL) {
save_errno = errno;
free_user(u);
@@ -101,42 +97,42 @@ load_user (int crontab_fd, struct passwd *pw, const char *uname,
#ifdef WITH_SELINUX
if (get_security_context(pw == NULL ? NULL : uname,
- crontab_fd, &u->scontext, tabname) != 0) {
- free_user (u);
+ crontab_fd, &u->scontext, tabname) != 0) {
+ free_user(u);
u = NULL;
goto done;
}
#endif
/* load the crontab
- */
- while ((status = load_env (envstr, file)) >= OK) {
+ */
+ while ((status = load_env(envstr, file)) >= OK) {
switch (status) {
- case ERR:
+ case ERR:
+ save_errno = errno;
+ free_user(u);
+ u = NULL;
+ goto done;
+ case FALSE:
+ FileName = tabname;
+ e = load_entry(file, log_error, pw, envp);
+ if (e) {
+ e->next = u->crontab;
+ u->crontab = e;
+ }
+ break;
+ case TRUE:
+ if ((tenvp = env_set(envp, envstr)) == NULL) {
save_errno = errno;
free_user(u);
u = NULL;
goto done;
- case FALSE:
- FileName = tabname;
- e = load_entry(file, log_error, pw, envp);
- if (e) {
- e->next = u->crontab;
- u->crontab = e;
- }
- break;
- case TRUE:
- if ((tenvp = env_set (envp, envstr)) == NULL) {
- save_errno = errno;
- free_user(u);
- u = NULL;
- goto done;
- }
+ }
envp = tenvp;
break;
}
}
-done:
+ done:
if (envp)
env_free(envp);
fclose(file);
--
1.8.0