From: thib Date: Sun, 25 Jun 2000 20:03:22 +0000 (+0000) Subject: bug fixes : used to crash after a syntax error in a global variable declaration X-Git-Tag: ver1564~568 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97ee6a9dea438e36c12583acb08ecb61d27f0601;p=fcron bug fixes : used to crash after a syntax error in a global variable declaration debug informations are better check for intervalls in a line begining with &1 --- diff --git a/fileconf.c b/fileconf.c index 5c6e95d..e300ba8 100644 --- a/fileconf.c +++ b/fileconf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fileconf.c,v 1.9 2000-06-22 12:33:55 thib Exp $ */ + /* $Id: fileconf.c,v 1.10 2000-06-25 20:03:22 thib Exp $ */ #include "fcrontab.h" @@ -217,7 +217,7 @@ read_file(char *filename, char *user) break; case '!': ptr = read_opt(ptr, &default_line); - if ( *ptr != '\0' ) { + if ( ptr != NULL && *ptr != '\0' ) { fprintf(stderr, "%s:%d: Syntax error: string '%s' ignored\n", file_name, line, ptr); need_correction = 1; @@ -351,10 +351,10 @@ get_runas(char *ptr, uid_t *uid) bzero(name, sizeof(name)); - while ( isalnum(*ptr) && i < sizeof(name)) + while ( *ptr != ')' && i < sizeof(name)) name[i++] = *ptr++; - if ((pas = getpwnam(user)) == NULL) { + if ((pas = getpwnam(name)) == NULL) { fprintf(stderr, "%s is not in passwd file", name); return NULL; } @@ -578,7 +578,7 @@ read_opt(char *ptr, CL *cl) } else if(strcmp(opt_name, "runas") == 0) { - uid_t uid; + uid_t uid = 0; if (getuid() != 0) { fprintf(stderr, "must be privileged to use option runas: " "skipping option\n"); @@ -588,9 +588,10 @@ read_opt(char *ptr, CL *cl) } if( ! in_brackets || (ptr = get_runas(ptr, &uid)) == NULL ) Handle_err; - cl->cl_nice = i; + cl->cl_runas = uid; + set_runas(cl->cl_option); if (debug_opt) - fprintf(stderr, " Opt : '%s' %d\n", opt_name, i); + fprintf(stderr, " Opt : '%s' %d\n", opt_name, uid); } else { @@ -674,16 +675,11 @@ read_freq(char *ptr, CF *cf) /* read a freq entry, and append a line to cf */ { CL *cl = NULL; - struct passwd *pas; Alloc(cl, CL); memcpy(cl, &default_line, sizeof(CL)); set_freq(cl->cl_option); cl->cl_runfreq = 0; - if ((pas = getpwnam(user)) == NULL) - die("failed to get uid for %s", user); - cl->cl_runas = pas->pw_uid; - /* skip the @ */ ptr++; @@ -817,6 +813,39 @@ read_arys(char *ptr, CF *cf) return; } + /* check for non matching if option runfreq is set to 1 */ + if ( cl->cl_runfreq == 1 ) { + const size_t s_mins=bitstr_size(60), s_hrs=bitstr_size(24); + const size_t s_days=bitstr_size(32), s_mons=bitstr_size(12); + const size_t s_dow=bitstr_size(8); + int j = 0; + + bit_ffc(cl->cl_mins, s_mins, &j); + if ( j != -1 ) goto ok; + bit_ffc(cl->cl_hrs, s_hrs, &j); + if ( j != -1 ) goto ok; + bit_ffc(cl->cl_days, s_days, &j); + if ( j != -1 ) { + if ( is_dayand(cl->cl_option) ) + goto ok; + else { + bit_ffc(cl->cl_dow, s_dow, &j); + if ( j != -1 ) goto ok; + } + } + bit_ffc(cl->cl_mons, s_mons, &j); + if ( j != -1 ) goto ok; + bit_ffc(cl->cl_dow, s_dow, &j); + if ( j != -1 && is_dayand(cl->cl_option) ) goto ok; + + fprintf(stderr, "%s:%d: runfreq=1 with no intervals: skipping line.\n", + file_name, line); + free(cl); + need_correction = 1; + return; + } + ok: + cl->cl_next = cf->cf_line_base; cf->cf_line_base = cl; @@ -1064,6 +1093,7 @@ save_file(char *path) CL *line = NULL; FILE *f = NULL; env_t *env = NULL; + struct passwd *pas = NULL; if (debug_opt) fprintf(stderr, "Saving ...\n"); @@ -1072,7 +1102,7 @@ save_file(char *path) /* open file */ if ( (f = fopen(path, "w")) == NULL ) - perror("save"); + die_e("File has not be saved"); /* save file : */ @@ -1082,6 +1112,9 @@ save_file(char *path) * if the syntax has changed */ fprintf(f, "fcrontab-" FILEVERSION "\n"); + /* put the user's name : it is used to check his uid has not changed */ + fprintf(f, "%s%c", user, '\0'); + /* put the time & date of saving : this is use for calcutating * the system down time. As it is a new file, we set it to 0 */ fprintf(f, "%d", 0); @@ -1105,6 +1138,11 @@ save_file(char *path) if ( fwrite(line, sizeof(CL), 1, f) != 1 ) perror("save"); fprintf(f, "%s%c", line->cl_shell, '\0'); + if ( is_runas(line->cl_option) ) { + if ( (pas = getpwuid(line->cl_runas)) == NULL ) + die_e("could not getpwuid() %d", line->cl_runas); + fprintf(f, "%s%c", pas->pw_name, '\0'); + } } fclose(f);