diff -Naur dcron.orig/crond.8 dcron/crond.8 --- dcron.orig/crond.8 1999-02-10 07:22:37.000000000 +0100 +++ dcron/crond.8 2006-04-26 22:42:35.000000000 +0200 @@ -26,6 +26,9 @@ .TP 0.5i .B "-c directory " specify directory containing crontab files. +.TP 0.5i +.B "-s directory " +specify directory containing system-wide crontab files. .SH DESCRIPTION .B crond is responsible for scanning the crontab files and running diff -Naur dcron.orig/database.c dcron/database.c --- dcron.orig/database.c 2006-04-22 17:47:19.000000000 +0200 +++ dcron/database.c 2006-04-26 22:43:52.000000000 +0200 @@ -6,6 +6,7 @@ * May be distributed under the GNU General Public License */ +#include #include "defs.h" Prototype void CheckUpdates(void); @@ -14,7 +15,7 @@ Prototype void RunJobs(void); Prototype int CheckJobs(void); -void SynchronizeFile(const char *fileName); +void SynchronizeFile(const char *userName, const char *fileName); void DeleteFile(const char *userName); char *ParseField(char *userName, char *ary, int modvalue, int off, const char **names, char *ptr); void FixDayDow(CronLine *line); @@ -74,11 +75,13 @@ { FILE *fi; char buf[256]; + char *ptr; if ((fi = fopen(CRONUPDATE, "r")) != NULL) { remove(CRONUPDATE); while (fgets(buf, sizeof(buf), fi) != NULL) { - SynchronizeFile(strtok(buf, " \t\r\n")); + ptr = strtok(buf, " \t\r\n"); + SynchronizeFile(ptr, ptr); } fclose(fi); } @@ -128,9 +131,32 @@ if (strchr(den->d_name, '.') != NULL) continue; if (getpwnam(den->d_name)) - SynchronizeFile(den->d_name); + SynchronizeFile(den->d_name, den->d_name); else logn(7, "ignoring %s\n", den->d_name); + if (strcmp(den->d_name, "root") == 0) + { + DIR *dir; + struct dirent *den; + char fullfileName[PATH_MAX]; + + if ((dir = opendir(SCDir))) + { + while ((den = readdir(dir))) + { + if (strchr(den->d_name, '.') != NULL) + continue; + snprintf(fullfileName, PATH_MAX, "%s/%s", SCDir, den->d_name); + SynchronizeFile("root", fullfileName); + } + closedir(dir); + } + else + { + log9("Unable to open %s!\n", SCDir); + exit(20); + } + } } closedir(dir); } else { @@ -141,7 +167,7 @@ } void -SynchronizeFile(const char *fileName) +SynchronizeFile(const char *userName, const char *fileName) { int maxEntries = MAXLINES; int maxLines; @@ -163,7 +189,7 @@ CronFile *file = calloc(1, sizeof(CronFile)); CronLine **pline; - file->cf_User = strdup(fileName); + file->cf_User = strdup(userName); pline = &file->cf_LineBase; while (fgets(buf, sizeof(buf), fi) != NULL && --maxLines) { @@ -185,7 +211,7 @@ bzero(&line, sizeof(line)); if (DebugOpt) - log9("User %s Entry %s\n", fileName, buf); + log9("User %s Entry %s\n", userName, buf); /* * parse date ranges @@ -232,7 +258,7 @@ FileBase = file; if (maxLines == 0 || maxEntries == 0) - log9("Maximum number of lines reached for user %s\n", fileName); + log9("Maximum number of lines reached for user %s\n", userName); } fclose(fi); } diff -Naur dcron.orig/defs.h dcron/defs.h --- dcron.orig/defs.h 2006-04-22 17:59:38.000000000 +0200 +++ dcron/defs.h 2006-04-26 22:42:35.000000000 +0200 @@ -30,6 +30,9 @@ #ifndef CRONTABS #define CRONTABS "/var/spool/cron/crontabs" #endif +#ifndef SCRONTABS +#define SCRONTABS "/etc/cron.d" +#endif #ifndef TMPDIR #define TMPDIR "/tmp" #endif diff -Naur dcron.orig/main.c dcron/main.c --- dcron.orig/main.c 2006-04-22 17:52:57.000000000 +0200 +++ dcron/main.c 2006-04-26 22:42:35.000000000 +0200 @@ -16,13 +16,17 @@ Prototype short LogLevel; Prototype short ForegroundOpt; Prototype const char *CDir; +Prototype const char *SCDir; Prototype uid_t DaemonUid; +Prototype int InSyncFileRoot; short DebugOpt; short LogLevel = 8; short ForegroundOpt; const char *CDir = CRONTABS; +const char *SCDir = SCRONTABS; uid_t DaemonUid; +int InSyncFileRoot; int main(int ac, char **av) @@ -58,6 +62,9 @@ case 'c': CDir = (*ptr) ? ptr : av[++i]; continue; + case 's': + SCDir = (*ptr) ? ptr : av[++i]; + continue; default: break; } @@ -73,7 +80,7 @@ if (i > ac) puts("expected argument for option"); printf("dcron " VERSION "\n"); - printf("dcron -d[#] -l[#] -f -b -c dir\n"); + printf("dcron -d[#] -l[#] -f -b -c dir -s dir\n"); exit(1); }