diff options
| author | Chris Gerhard <Chris.Gerhard@sun.com> | 2008-12-23 15:44:14 +0000 |
|---|---|---|
| committer | Chris Gerhard <Chris.Gerhard@sun.com> | 2008-12-23 15:44:14 +0000 |
| commit | 5b08e637db3c0e4201b09b542c766da0f66129e8 (patch) | |
| tree | c1cfc272be27e1403ecdfdd35023261f8157919c /usr/src/cmd/cron/crontab.c | |
| parent | a51287096c163d49f314be2853367563999e083c (diff) | |
| download | illumos-joyent-5b08e637db3c0e4201b09b542c766da0f66129e8.tar.gz | |
PSARC/2007/503 crontab entry environment variables
6518038 cron & crontab should support multiple timezones
Diffstat (limited to 'usr/src/cmd/cron/crontab.c')
| -rw-r--r-- | usr/src/cmd/cron/crontab.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/usr/src/cmd/cron/crontab.c b/usr/src/cmd/cron/crontab.c index 6878460300..266ad44da3 100644 --- a/usr/src/cmd/cron/crontab.c +++ b/usr/src/cmd/cron/crontab.c @@ -26,8 +26,6 @@ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #include <sys/stat.h> #include <sys/types.h> @@ -47,6 +45,8 @@ #include <libintl.h> #include <spawn.h> #include <security/pam_appl.h> +#include <limits.h> +#include <libzoneinfo.h> #include "cron.h" #include "getresponse.h" @@ -91,6 +91,9 @@ " Edit again, to ensure crontab information is intact (%s/%s)?\n"\ " ('%s' will discard edits.)" #define NAMETOOLONG "login name too long" +#define BAD_TZ "Timezone unrecognized in: %s" +#define BAD_SHELL "Invalid shell specified: %s" +#define BAD_HOME "Unable to access directory: %s\t%s\n" extern int per_errno; extern char **environ; @@ -435,6 +438,7 @@ FILE *fp; FILE *tfp; char pid[6], *tnam_end; int t; + char buf[LINE_MAX]; sprintf(pid, "%-5d", getpid()); tnam = xmalloc(strlen(CRONDIR)+strlen(TMPFILE)+7); @@ -462,6 +466,56 @@ FILE *fp; /* fix for 1039689 - treat blank line like a comment */ if (line[cursor] == '#' || line[cursor] == '\n') goto cont; + + if (strncmp(&line[cursor], ENV_TZ, strlen(ENV_TZ)) == 0) { + char *x; + + strncpy(buf, &line[cursor + strlen(ENV_TZ)], + sizeof (buf)); + if ((x = strchr(buf, '\n')) != NULL) + *x = NULL; + + if (isvalid_tz(buf, NULL, _VTZ_ALL)) { + goto cont; + } else { + err = 1; + fprintf(stderr, BAD_TZ, &line[cursor]); + continue; + } + } else if (strncmp(&line[cursor], ENV_SHELL, + strlen(ENV_SHELL)) == 0) { + char *x; + + strncpy(buf, &line[cursor + strlen(ENV_SHELL)], + sizeof (buf)); + if ((x = strchr(buf, '\n')) != NULL) + *x = NULL; + + if (isvalid_shell(buf)) { + goto cont; + } else { + err = 1; + fprintf(stderr, BAD_SHELL, &line[cursor]); + continue; + } + } else if (strncmp(&line[cursor], ENV_HOME, + strlen(ENV_HOME)) == 0) { + char *x; + + strncpy(buf, &line[cursor + strlen(ENV_HOME)], + sizeof (buf)); + if ((x = strchr(buf, '\n')) != NULL) + *x = NULL; + if (chdir(buf) == 0) { + goto cont; + } else { + err = 1; + fprintf(stderr, BAD_HOME, &line[cursor], + strerror(errno)); + continue; + } + } + if (next_field(0, 59)) continue; if (next_field(0, 23)) continue; if (next_field(1, 31)) continue; |
