diff -ruN dcron-orig/Makefile dcron-fwb/Makefile --- dcron-orig/Makefile 2006-05-16 18:24:50.000000000 +0200 +++ dcron-fwb/Makefile 2009-12-21 14:40:24.000000000 +0100 @@ -3,7 +3,7 @@ DESTDIR ?= /usr/local CC = gcc -CFLAGS = -O2 -Wall -Wstrict-prototypes +CFLAGS = -O2 -Wall -Wstrict-prototypes -D_GNU_SOURCE LIB = SRCS = main.c subs.c database.c job.c OBJS = main.o subs.o database.o job.o Binary files dcron-orig/crond and dcron-fwb/crond differ Binary files dcron-orig/crontab and dcron-fwb/crontab differ Binary files dcron-orig/crontab.o and dcron-fwb/crontab.o differ diff -ruN dcron-orig/database.c dcron-fwb/database.c --- dcron-orig/database.c 2006-05-16 18:20:01.000000000 +0200 +++ dcron-fwb/database.c 2009-12-22 16:32:56.000000000 +0100 @@ -15,7 +15,7 @@ Prototype void RunJobs(void); Prototype int CheckJobs(void); -void SynchronizeFile(const char *dpath, const char *fname, const char *uname); +void SynchronizeFile(const char *dpath, const char *fname, const char *uname, int recognize_username_field); void DeleteFile(CronFile **pfile); char *ParseField(char *userName, char *ary, int modvalue, int off, const char **names, char *ptr); void FixDayDow(CronLine *line); @@ -92,9 +92,9 @@ while (fgets(buf, sizeof(buf), fi) != NULL) { ptr = strtok(buf, " \t\r\n"); if (user_override) - SynchronizeFile(dpath, ptr, user_override); + SynchronizeFile(dpath, ptr, user_override, 1); else if (getpwnam(ptr)) - SynchronizeFile(dpath, ptr, ptr); + SynchronizeFile(dpath, ptr, ptr, 0); else logn(7, "ignoring %s/%s (non-existant user)\n", dpath, ptr); } @@ -144,9 +144,9 @@ if (strcmp(den->d_name, CRONUPDATE) == 0) continue; if (user_override) { - SynchronizeFile(dpath, den->d_name, user_override); + SynchronizeFile(dpath, den->d_name, user_override, 1); } else if (getpwnam(den->d_name)) { - SynchronizeFile(dpath, den->d_name, den->d_name); + SynchronizeFile(dpath, den->d_name, den->d_name, 0); } else { logn(7, "ignoring %s/%s (non-existant user)\n", dpath, den->d_name); @@ -160,8 +160,35 @@ } } +/** + * Return index to a field in a string with white space(s) as separator. + * + * It searches a string for a field specified by number + * 'index' and returns the string index position. + * If the end of the string is reached without finding + * field number 'index' then -1 is returned. + * + * @param s The string to be searched through. + * @param index The number of the field index to search for. + * @return The pointer the field in the string or 0 on error. + */ +static const char *field_index(const char *t, int index) { + if (index < 1) return t; + for (;;) { + if ((*t == '\n') || (!*t)) return 0; + if ((*t == ' ') || (*t == '\t')) { + --index; ++t; + while ((*t == ' ') || (*t == '\t')) t++; + if ((*t == '\n') || (!*t)) return 0; + if (!index) return t; + } else { + ++t; + } + } +} + void -SynchronizeFile(const char *dpath, const char *fileName, const char *userName) +SynchronizeFile(const char *dpath, const char *fileName, const char *userName, int recognize_username_field) { CronFile **pfile; CronFile *file; @@ -210,6 +237,7 @@ while (fgets(buf, sizeof(buf), fi) != NULL && --maxLines) { CronLine line; char *ptr = buf; + char *pcmd = buf; int len; while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') @@ -227,13 +255,34 @@ bzero(&line, sizeof(line)); + /* username field must be parsed before other fields */ + if (recognize_username_field) { + const char *tmpusername; + const char *tmpcommand; + tmpusername = field_index(ptr, 5); + tmpcommand = field_index(ptr, 6); + if (!tmpusername || !tmpcommand) { + recognize_username_field = 0; + if (DebugOpt) log9("can't recognize username field\n"); + } else { + pcmd = (char *) tmpcommand; + do { + --tmpcommand; + } while ((*tmpcommand == ' ') || (*tmpcommand == '\t')); + ++tmpcommand; + file->cf_UserName = strndup(tmpusername, tmpcommand - tmpusername); + } + } + if (DebugOpt) - log9("User %s Entry %s\n", userName, buf); + log9("User %s Entry %s\n", file->cf_UserName, buf); /* * parse date ranges */ + if (*ptr == '-') ++ptr; /* ignore '-' as first char of line */ + ptr = ParseField(file->cf_UserName, line.cl_Mins, 60, 0, NULL, ptr); ptr = ParseField(file->cf_UserName, line.cl_Hrs, 24, 0, @@ -252,6 +301,10 @@ if (ptr == NULL) continue; + if (recognize_username_field) { + ptr = pcmd; + } + /* * fix days and dow - if one is not * and the other * is *, the other is set to 0, and vise-versa Binary files dcron-orig/database.o and dcron-fwb/database.o differ diff -ruN dcron-orig/defs.h dcron-fwb/defs.h --- dcron-orig/defs.h 2006-05-16 18:24:45.000000000 +0200 +++ dcron-fwb/defs.h 2009-12-22 12:44:04.000000000 +0100 @@ -11,6 +11,9 @@ #include #include #include +#ifdef WANT_SYSLOG +#include +#endif #include #include #include @@ -37,7 +40,7 @@ #define TMPDIR "/tmp" #endif #ifndef OPEN_MAX -#define OPEN_MAX 256 +#define OPEN_MAX 2048 #endif #ifndef SENDMAIL @@ -55,11 +58,14 @@ #define CRONUPDATE "cron.update" #endif #ifndef MAXLINES -#define MAXLINES 256 /* max lines in non-root crontabs */ +#define MAXLINES 2048 /* max lines in non-root crontabs */ #endif #ifndef PATH_VI #define PATH_VI "/usr/bin/vi" /* location of vi */ #endif +#ifndef PATH_SHELL +#define PATH_SHELL "/bin/bash" +#endif #define VERSION "V3.2" diff -ruN dcron-orig/job.c dcron-fwb/job.c --- dcron-orig/job.c 2006-04-29 18:49:48.000000000 +0200 +++ dcron-fwb/job.c 2009-12-22 12:45:37.000000000 +0100 @@ -83,15 +83,15 @@ mailFile ); } - execl("/bin/sh", "/bin/sh", "-c", line->cl_Shell, NULL, NULL); + execl(PATH_SHELL, PATH_SHELL, "-c", line->cl_Shell, NULL, NULL); /* * note: 8 is a descriptor, not a log level */ - logfd(8, "unable to exec, user %s cmd /bin/sh -c %s\n", + logfd(8, "unable to exec, user %s cmd "PATH_SHELL" -c %s\n", file->cf_UserName, line->cl_Shell ); - fdprintf(1, "Exec failed: /bin/sh -c %s\n", line->cl_Shell); + fdprintf(1, "Exec failed: "PATH_SHELL" -c %s\n", line->cl_Shell); exit(0); } else if (line->cl_Pid < 0) { /* Binary files dcron-orig/job.o and dcron-fwb/job.o differ diff -ruN dcron-orig/main.c dcron-fwb/main.c --- dcron-orig/main.c 2006-04-29 18:47:26.000000000 +0200 +++ dcron-fwb/main.c 2009-12-22 16:29:08.000000000 +0100 @@ -39,6 +39,8 @@ DaemonUid = getuid(); + ForegroundOpt = 1; + for (i = 1; i < ac; ++i) { char *ptr = av[i]; Binary files dcron-orig/main.o and dcron-fwb/main.o differ diff -ruN dcron-orig/subs.c dcron-fwb/subs.c --- dcron-orig/subs.c 2006-04-27 19:29:56.000000000 +0200 +++ dcron-fwb/subs.c 2009-12-22 13:09:01.000000000 +0100 @@ -63,11 +63,11 @@ { char buf[2048]; short n; - static short useDate = 1; + static short useDate = 0; if (level >= LogLevel) { write(fd, buf, n = slog(buf, ctl, sizeof(buf), va, useDate)); - useDate = (n && buf[n-1] == '\n'); + /* useDate = (n && buf[n-1] == '\n'); */ } } @@ -79,7 +79,7 @@ buf[0] = 0; if (useDate) - strftime(buf, 128, "%d-%b-%y %H:%M ", tp); + strftime(buf, 128, "%d-%b-%Y %H:%M ", tp); vsnprintf(buf + strlen(buf), nmax, ctl, va); return(strlen(buf)); } @@ -99,7 +99,7 @@ } setenv("USER", pas->pw_name, 1); setenv("HOME", pas->pw_dir, 1); - setenv("SHELL", "/bin/sh", 1); + setenv("SHELL", PATH_SHELL, 1); /* * Change running state to the user in question Binary files dcron-orig/subs.o and dcron-fwb/subs.o differ