From bfcc5f0a5e7662213f23a8d5c0c1c7135d123206 Mon Sep 17 00:00:00 2001 From: thib Date: Fri, 30 Aug 2002 20:04:28 +0000 Subject: [PATCH] added a system fcrontab --- conf.c | 17 +++++++++++++---- config.h.in | 8 +++++--- configure.in | 24 ++++++++++++++++++++++++ dyncom.h | 6 +++++- fcrondyn.c | 32 +++++++++++++++++++++++++------- fcrontab.h | 3 ++- fileconf.c | 14 +++++++------- fileconf.h | 4 ++-- socket.c | 45 ++++++++++++++++++++++++++++----------------- 9 files changed, 111 insertions(+), 42 deletions(-) diff --git a/conf.c b/conf.c index 4b90459..93a0c9b 100644 --- a/conf.c +++ b/conf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: conf.c,v 1.56 2002-08-25 17:24:14 thib Exp $ */ + /* $Id: conf.c,v 1.57 2002-08-30 20:05:51 thib Exp $ */ #include "fcron.h" @@ -142,7 +142,11 @@ synchronize_dir(const char *dir_name) /* then add normal files, if any, to database */ for (list_cur = file_list; list_cur; list_cur = list_cur->next ) { - if ( getpwnam(list_cur->str) ) { + if ( getpwnam(list_cur->str) +#ifdef SYSFCRONTAB + || strcmp(list_cur->str, SYSFCRONTAB) == 0 +#endif + ) { explain("adding file %s", list_cur->str); synchronize_file(list_cur->str); } @@ -152,7 +156,12 @@ synchronize_dir(const char *dir_name) /* finally add new files */ for (list_cur = new_list; list_cur; list_cur = list_cur->next ) { - if ( getpwnam(list_cur->str + 4) ) { /* len("new.") = 4 */ + /* len("new.") = 4 : */ + if ( getpwnam(list_cur->str + 4) +#ifdef SYSFCRONTAB + || strcmp(list_cur->str + 4, SYSFCRONTAB) == 0 +#endif + ) { explain("adding new file %s", list_cur->str + 4); synchronize_file(list_cur->str); } @@ -470,7 +479,7 @@ read_file(const char *file_name, CF *cf) debug("User %s Entry", file_name); bzero(buf, sizeof(buf)); - /* get version of fcrontab file: it permit to daemon not to load + /* get version of fcrontab file: it permits to daemon not to load * a file which he won't understand the syntax, for exemple * a file using a depreciated format generated by an old fcrontab, * if the syntax has changed */ diff --git a/config.h.in b/config.h.in index bcd2067..e9446c3 100644 --- a/config.h.in +++ b/config.h.in @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: config.h.in,v 1.45 2002-08-29 17:34:14 thib Exp $ */ + /* $Id: config.h.in,v 1.46 2002-08-30 20:06:01 thib Exp $ */ /* *********************************************************** */ @@ -38,8 +38,7 @@ #define FCRON_DENY "fcron.deny" #define FCRON_CONF "fcron.conf" -#define SENDMAIL_ARGS "-Ffcron", "-odi" /* args of mail command */ - +#define SENDMAIL_ARGS "-Ffcron", "-odi" /* args of mail command */ /* *** time *** */ #define FIRST_SLEEP 20 /* fcron sleep at least this time after startup @@ -189,6 +188,9 @@ #undef USERNAME #undef GROUPNAME +/* special user for the system fcrontab */ +#undef SYSFCRONTAB + /* Define to empty if the keyword does not work. */ #undef const diff --git a/configure.in b/configure.in index aeaa79f..296f41e 100644 --- a/configure.in +++ b/configure.in @@ -870,6 +870,30 @@ if test \( $seteuid -eq 1 \) -a \( $setegid -eq 1 \) ; then fi +sysfcrontab="systab" +use_sysfcrontab=1 +AC_MSG_CHECKING(use a system fcrontab) +AC_ARG_WITH(sysfcrontab, +[ --with-sysfcrontab=NAME Use (or not) a system fcrontab (default: yes)], +[ case "$withval" in + no) + use_sysfcrontab=0 + AC_MSG_RESULT(no) + ;; + yes) + AC_MSG_RESULT(yes) + ;; + *) + sysfcrontab="$withval" + AC_MSG_RESULT($sysfcrontab) + esac ], + AC_MSG_RESULT(yes) +) +if test "$use_sysfcrontab" -eq 1 ; then + AC_DEFINE_UNQUOTED(SYSFCRONTAB, "$sysfcrontab") +fi + + dnl --------------------------------------------------------------------- dnl DocBook diff --git a/dyncom.h b/dyncom.h index 717f42b..fadd83a 100644 --- a/dyncom.h +++ b/dyncom.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: dyncom.h,v 1.3 2002-08-25 17:25:35 thib Exp $ */ + /* $Id: dyncom.h,v 1.4 2002-08-30 20:05:58 thib Exp $ */ /* This file describe the communication protocol between fcron and fcrondyn */ @@ -57,6 +57,10 @@ #define CUR_USER (-2) #define ARG_REQUIRED (-3) +#ifdef SYSFCRONTAB +#define SYSFCRONTAB_UID (-100) +#endif + /* commands : if you change something here, please update fcrondyn.c's cmd_list * and fcron's socket.c . */ #define NUM_CMD 9 diff --git a/fcrondyn.c b/fcrondyn.c index 6f7ef3d..70be3a6 100644 --- a/fcrondyn.c +++ b/fcrondyn.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcrondyn.c,v 1.5 2002-08-25 17:10:11 thib Exp $ */ + /* $Id: fcrondyn.c,v 1.6 2002-08-30 20:04:28 thib Exp $ */ /* fcrondyn : interact dynamically with running fcron process : * - list jobs, with their status, next time of execution, etc @@ -35,7 +35,7 @@ #include "allow.h" #include "read_string.h" -char rcs_info[] = "$Id: fcrondyn.c,v 1.5 2002-08-25 17:10:11 thib Exp $"; +char rcs_info[] = "$Id: fcrondyn.c,v 1.6 2002-08-30 20:04:28 thib Exp $"; void info(void); void usage(void); @@ -169,6 +169,9 @@ parse_cmd(char *cmd_str, long int **cmd, int *cmd_len) int i = 0, j = 0, rank = -1; long int int_buf = 0; struct passwd *pass = NULL; +#ifdef SYSFCRONTAB + long int sysfcrontab_uid = SYSFCRONTAB_UID; +#endif bzero(buf, sizeof(buf)); *cmd_len = 0; @@ -241,15 +244,30 @@ parse_cmd(char *cmd_str, long int **cmd, int *cmd_len) case USER: int_buf = (long int) *(cmd_str + word_size); *(cmd_str + word_size) = '\0'; - if ( (pass = getpwnam(cmd_str) ) == NULL ) { - fprintf(stderr, "Error : '%s' is not a valid user name.\n", cmd_str); - return INVALID_ARG; +#ifdef SYSFCRONTAB + if ( strcmp(cmd_str, SYSFCRONTAB) == 0 ) { + Write_cmd(sysfcrontab_uid); } + else { +#endif + if ( ( pass = getpwnam(cmd_str) ) == NULL ) { + fprintf(stderr,"Error : '%s' isn't a valid username.\n",cmd_str); + return INVALID_ARG; + } + Write_cmd(pass->pw_uid); +#ifdef SYSFCRONTAB + } +#endif *(cmd_str + word_size) = (char) int_buf; cmd_str += word_size; - Write_cmd(pass->pw_uid); if ( debug_opt ) - fprintf(stderr, " uid = %d\n", pass->pw_uid); + fprintf(stderr, " uid = %d\n", +#ifdef SYSFCRONTAB + (pass) ? pass->pw_uid : SYSFCRONTAB_UID +#else + pass->pw_uid +#endif + ); break; case JOBID: diff --git a/fcrontab.h b/fcrontab.h index b7e6efd..aef145b 100644 --- a/fcrontab.h +++ b/fcrontab.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcrontab.h,v 1.15 2002-03-02 17:26:05 thib Exp $ */ + /* $Id: fcrontab.h,v 1.16 2002-08-30 20:05:27 thib Exp $ */ #ifndef __FCRONTAB_H__ #define __FCRONTAB_H__ @@ -34,6 +34,7 @@ extern pid_t daemon_pid; extern char dosyslog; extern struct CF *file_base; extern char *user; +extern char *runas; extern uid_t uid; extern uid_t asuid; extern uid_t fcrontab_uid; diff --git a/fileconf.c b/fileconf.c index 2655a21..61ab9ad 100644 --- a/fileconf.c +++ b/fileconf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fileconf.c,v 1.60 2002-08-25 17:12:05 thib Exp $ */ + /* $Id: fileconf.c,v 1.61 2002-08-30 20:05:39 thib Exp $ */ #include "fcrontab.h" @@ -147,7 +147,7 @@ get_line(char *str, size_t size, FILE *file) } int -read_file(char *filename, char *user) +read_file(char *filename) /* read file "name" and append CF list */ { CF *cf = NULL; @@ -179,14 +179,14 @@ read_file(char *filename, char *user) Alloc(cf, CF); cf->cf_user = strdup2(user); default_line.cl_file = cf; - default_line.cl_runas = strdup2(user); - default_line.cl_mailto = strdup2(user); + default_line.cl_runas = strdup2(runas); + default_line.cl_mailto = strdup2(runas); set_default_opt(default_line.cl_option); if ( debug_opt ) fprintf(stderr, "FILE %s\n", file_name); - if (strcmp(user, "root") == 0) + if (strcmp(runas, "root") == 0) max_entries = 65535; /* max_lines acts here as a security counter to avoid endless loop. */ @@ -544,8 +544,8 @@ read_opt(char *ptr, CL *cl) Handle_err; if ( i == 1 ) { bzero(cl, sizeof(CL)); - Set(cl->cl_runas, user); - Set(cl->cl_mailto, user); + Set(cl->cl_runas, runas); + Set(cl->cl_mailto, runas); set_default_opt(cl->cl_option); } if (debug_opt) diff --git a/fileconf.h b/fileconf.h index 81b14dd..e6bc1b8 100644 --- a/fileconf.h +++ b/fileconf.h @@ -21,13 +21,13 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fileconf.h,v 1.3 2001-12-23 22:04:48 thib Exp $ */ + /* $Id: fileconf.h,v 1.4 2002-08-30 20:05:42 thib Exp $ */ #ifndef __FILECONF_H__ #define __FILECONF_H__ /* functions prototypes */ -extern int read_file(char *filename, char *user); +extern int read_file(char *filename); extern void delete_file(const char *user_name); extern int save_file(char *path); diff --git a/socket.c b/socket.c index 646c8c9..daca35a 100644 --- a/socket.c +++ b/socket.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: socket.c,v 1.6 2002-08-25 17:27:14 thib Exp $ */ + /* $Id: socket.c,v 1.7 2002-08-30 20:06:04 thib Exp $ */ /* This file contains all fcron's code (server) to handle communication with fcrondyn */ @@ -233,7 +233,7 @@ print_fields(int fd, unsigned char *details) fields[TERM_LEN-1] = '\0'; - if ( send(fd, fields, len, 0) < 0 ) + if ( send(fd, fields, (len < sizeof(fields)) ? len : sizeof(fields), 0) < 0 ) error_e("error in send()"); } @@ -261,6 +261,7 @@ print_line(int fd, struct CL *line, unsigned char *details, pid_t pid, int inde if ( bit_test(details, FIELD_OPTIONS) ) { char opt[9]; int i = 0; + opt[0] = '\0'; if ( is_lavg(line->cl_option) ) i += snprintf(opt+i, sizeof(opt)-i, "L%.*s", (is_lavg_sev(line->cl_option)) ? 0:1, "O"); @@ -274,7 +275,9 @@ print_line(int fd, struct CL *line, unsigned char *details, pid_t pid, int inde } if ( bit_test(details, FIELD_LAVG) ) { len += snprintf(buf+len, sizeof(buf)-len, " %.1lf,%.1lf,%.1lf", - ((double)((line->cl_lavg)[0]))/10, ((double)((line->cl_lavg)[1]))/10, ((double)((line->cl_lavg)[2]))/10); + ((double)((line->cl_lavg)[0]))/10, + ((double)((line->cl_lavg)[1]))/10, + ((double)((line->cl_lavg)[2]))/10); if ( until > 0 ) { ftime = localtime( &until ); len += snprintf(buf+len, sizeof(buf)-len, " %02d/%02d/%d %02d:%02d %s", @@ -293,7 +296,7 @@ print_line(int fd, struct CL *line, unsigned char *details, pid_t pid, int inde } len += snprintf(buf+len, sizeof(buf)-len, " %s\n", line->cl_shell); - if ( send(fd, buf, len + 1, 0) < 0 ) + if ( send(fd, buf, (len < sizeof(buf)) ? len : sizeof(buf), 0) < 0 ) error_e("error in send()"); } @@ -376,20 +379,28 @@ cmd_ls(struct fcrondyn_cl *client, long int *cmd, int fd, int is_root) if (! all) { struct passwd *pass; - if ( (pass = getpwuid( (uid_t) cmd[1] )) == NULL ) { - warn_e("Unable to find passwd entry for %ld", cmd[1]); - send(fd, err_invalid_user_str, sizeof(err_invalid_user_str), 0); - send(fd, END_STR, sizeof(END_STR), 0); - return; - } - if ( ! is_root && strcmp(pass->pw_name, client->fcl_user) != 0 ) { - warn_e("%s is not allowed to see %s's jobs. %ld", client->fcl_user, - pass->pw_name); - send(fd, err_others_nallowed_str, sizeof(err_others_nallowed_str), 0); - send(fd, END_STR, sizeof(END_STR), 0); - return; +#ifdef SYSFCRONTAB + if ( cmd[1] == SYSFCRONTAB_UID ) + user = SYSFCRONTAB; + else { +#endif + if ( (pass = getpwuid( (uid_t) cmd[1] )) == NULL ) { + warn_e("Unable to find passwd entry for %ld", cmd[1]); + send(fd, err_invalid_user_str, sizeof(err_invalid_user_str), 0); + send(fd, END_STR, sizeof(END_STR), 0); + return; + } + if ( ! is_root && strcmp(pass->pw_name, client->fcl_user) != 0 ) { + warn_e("%s is not allowed to see %s's jobs. %ld", client->fcl_user, + pass->pw_name); + send(fd, err_others_nallowed_str, sizeof(err_others_nallowed_str),0); + send(fd, END_STR, sizeof(END_STR), 0); + return; + } + user = pass->pw_name; +#ifdef SYSFCRONTAB } - user = pass->pw_name; +#endif } /* list all jobs one by one and find the corresponding ones */ -- 2.40.0