* `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"
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;
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;
}
}
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");
}
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 {
/* 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++;
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;
CL *line = NULL;
FILE *f = NULL;
env_t *env = NULL;
+ struct passwd *pas = NULL;
if (debug_opt)
fprintf(stderr, "Saving ...\n");
/* open file */
if ( (f = fopen(path, "w")) == NULL )
- perror("save");
+ die_e("File has not be saved");
/* save file : */
* 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);
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);