]> granicus.if.org Git - fcron/commitdiff
added a system fcrontab
authorthib <thib>
Fri, 30 Aug 2002 20:04:28 +0000 (20:04 +0000)
committerthib <thib>
Fri, 30 Aug 2002 20:04:28 +0000 (20:04 +0000)
conf.c
config.h.in
configure.in
dyncom.h
fcrondyn.c
fcrontab.h
fileconf.c
fileconf.h
socket.c

diff --git a/conf.c b/conf.c
index 4b90459d1369dcba4c65f76d81911675f4aab60a..93a0c9b421dc95a2107c4a7f27efb0418990f739 100644 (file)
--- 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 */
index bcd206758f64ddf00a5b891dd3ed7e334b5342f9..e9446c38f1456f568d108c94e17d350536540e64 100644 (file)
@@ -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
 #undef USERNAME
 #undef GROUPNAME
 
+/* special user for the system fcrontab */
+#undef SYSFCRONTAB
+
 /* Define to empty if the keyword does not work.  */
 #undef const
 
index aeaa79fc02cb1e9ec2155c6ae14d4c41b48add2e..296f41ec9c9c4931e430d373fff7f258e6a378a4 100644 (file)
@@ -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
 
index 717f42bc3f09b45525cd5b875ee6cff6d8d0b262..fadd83a0431a2a3254ba49e183560e7e9bdfe2c4 100644 (file)
--- 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 */
 
 #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
index 6f7ef3d718f60b5491e886d7205501749f3af168..70be3a61ef085903876978f57fbac114901334a4 100644 (file)
@@ -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:
index b7e6efd0f3949c21fc4b9680c0ff4db8b783cccb..aef145b10838684599cf3d6581e5180df8095103 100644 (file)
@@ -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;
index 2655a211c8358af9bb40f8eca581e704906fa0fe..61ab9ad24b1d8da5f4e7788b4b87a606eff4d75d 100644 (file)
@@ -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)
index 81b14dd05386cc0d2953955b4d22dbef63472c3b..e6bc1b8f93c85f1ec587730b1c1e20691cb98dde 100644 (file)
  *  `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);
 
index 646c8c92a4cd41cf87ab41bdf4527f96cc32dd9f..daca35a00971aba40b46ebaa3dd73a3d136e7228 100644 (file)
--- 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 */