]> granicus.if.org Git - fcron/commitdiff
user ROOTNAME/ROOTGROUP instead of ROOTUID/ROOTGID
authorthib <thib>
Sat, 20 May 2006 16:22:37 +0000 (16:22 +0000)
committerthib <thib>
Sat, 20 May 2006 16:22:37 +0000 (16:22 +0000)
14 files changed:
conf.c
config.h.in
configure.in
convert-fcrontab.c
convert-fcrontab.h
fcron.c
fcron.h
fcrondyn.c
fcrondyn.h
fcronsighup.c
fcronsighup.h
fcrontab.c
fcrontab.h
fileconf.c

diff --git a/conf.c b/conf.c
index 7afee317347cf750de90602d760836ee1f4a40cf..12dd4d8fb39a375baaf25fb6dfa3505618c7775a 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.70 2006-01-11 00:53:20 thib Exp $ */
+ /* $Id: conf.c,v 1.71 2006-05-20 16:27:32 thib Exp $ */
 
 #include "fcron.h"
 
@@ -467,9 +467,9 @@ read_file(const char *file_name, cf_t *cf)
 #endif
 
     if ( strncmp(file_name,"new.", 4) == 0 ) {
-       if ( file_stat.st_uid == ROOTUID ) {
-           /* file is owned by root : no test needed : set runas to ROOTUID */
-           runas = ROOTUID;
+       if ( file_stat.st_uid == rootuid ) {
+           /* file is owned by root : no test needed : set runas to rootuid */
+           runas = rootuid;
        }
        else {
            /* this is a standard user's new fcrontab : set the runas field to
@@ -486,10 +486,10 @@ read_file(const char *file_name, cf_t *cf)
     else {
        if(!cf->cf_user)
            cf->cf_user = strdup2(file_name);
-       if ( file_stat.st_uid == ROOTUID ) {
+       if ( file_stat.st_uid == rootuid ) {
            /* file is owned by root : either this file has already been parsed
             * at least once by fcron, or it is root's fcrontab */
-           runas = ROOTUID;
+           runas = rootuid;
        }
        else {
            error("Non-new file %s owned by someone else than root",file_name);
@@ -553,7 +553,7 @@ read_file(const char *file_name, cf_t *cf)
        error("Cannot read user's name : file ignored");
        goto err;
     }
-    if ( runas != ROOTUID ) {
+    if ( runas != rootuid ) {
        /* we use file owner's name for more security (see above) */
        /* free the value obtained by read_strn() (we need to read it anyway
         * to set the file ptr to the next thing to read) */
@@ -759,7 +759,7 @@ add_line_to_file(cl_t *cl, cf_t *cf, uid_t runas, char *runas_str, time_t t_save
     }
 
     /* set runas field if necessary (to improve security) */
-    if (runas != ROOTUID) {
+    if (runas != rootuid) {
        if (strcmp(cl->cl_runas, runas_str) != 0)
            warn("warning: runas(%s) is not owner (%s): overridden.",
                 cl->cl_runas, runas_str);
@@ -1054,7 +1054,7 @@ save_file(cf_t *arg_file)
        /* save the file safely : save it to a temporary name, then rename() it */
        /* chown the file to root:root : this file should only be read and
         * modified by fcron (not fcrontab) */
-       save_file_safe(file, file->cf_user, "fcron", ROOTUID, ROOTGID, now);
+       save_file_safe(file, file->cf_user, "fcron", rootuid, rootgid, now);
 
        if (arg_file != NULL)
            /* we have to save only a single file */
index 19668786535257f82d4a3cd9710620607fc9f377..57103af858839f74d91520bc43a2d0d50b9dfacc 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: config.h.in,v 1.56 2006-01-11 00:53:50 thib Exp $ */
+ /* $Id: config.h.in,v 1.57 2006-05-20 16:27:43 thib Exp $ */
 
 
 /* *********************************************************** */
 #undef USE_SETE_ID
 
 /* root uid, gid, name and group */
-#undef ROOTUID
-#undef ROOTGID
 #undef ROOTNAME
 #undef ROOTGROUP
 
index 1009c2ddc7f88a3fe44fbf75b4f7937ecab843d3..c6c1389bd90568cf0e05c22ee21a5c22ee70fcd5 100644 (file)
@@ -13,7 +13,7 @@ AC_PREFIX_DEFAULT($prefix)
 AC_CONFIG_HEADER(config.h)
 AC_PREREQ(2.57)
 
-vers="3.0.1"
+vers="3.0.2"
 vers_quoted="\"$vers\""
 AC_DEFINE_UNQUOTED(VERSION, $vers)
 AC_DEFINE_UNQUOTED(VERSION_QUOTED, $vers_quoted)
@@ -674,15 +674,9 @@ Cannot determine root's groupname: try option --with-rootgroup=GROUPNAME])
 ROOTNAME="$rootname"
 AC_SUBST(ROOTNAME)
 AC_DEFINE_UNQUOTED(ROOTNAME, "$rootname")
-ROOTUID=$rootuid
-AC_SUBST(ROOTUID)
-AC_DEFINE_UNQUOTED(ROOTUID, $rootuid)
 ROOTGROUP="$rootgroup"
 AC_SUBST(ROOTGROUP)
 AC_DEFINE_UNQUOTED(ROOTGROUP, "$rootgroup")
-ROOTGID=$rootgid
-AC_SUBST(ROOTGID)
-AC_DEFINE_UNQUOTED(ROOTGID, $rootgid)
 
 username="$rootname"
 groupname="$rootgroup"
index 1a5ae404682ca905f6691b4fd23aba754b3f478b..22b14b37d88174d0682e68d68ac6ac9f1007d2af 100644 (file)
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: convert-fcrontab.c,v 1.20 2006-01-11 00:54:22 thib Exp $ */
+ /* $Id: convert-fcrontab.c,v 1.21 2006-05-20 16:27:46 thib Exp $ */
 
 #include "convert-fcrontab.h"
 #include "global.h"
 
-char rcs_info[] = "$Id: convert-fcrontab.c,v 1.20 2006-01-11 00:54:22 thib Exp $";
+char rcs_info[] = "$Id: convert-fcrontab.c,v 1.21 2006-05-20 16:27:46 thib Exp $";
 
 void info(void);
 void usage(void);
@@ -41,6 +41,8 @@ char  *cdir = FCRONTABS;      /* the dir where are stored users' fcrontabs */
 char *prog_name = NULL;
 char foreground = 1;
 pid_t daemon_pid = 0;
+uid_t rootuid = 0;
+gid_t rootgid = 0;
 char debug_opt = 0;
 char dosyslog = 1;
 
@@ -54,6 +56,11 @@ info(void)
            "Copyright " COPYRIGHT_QUOTED " Thibault Godouet <fcron@free.fr>\n"
            "This program is free software distributed WITHOUT ANY WARRANTY.\n"
             "See the GNU General Public License for more details.\n"
+           "\n"
+           "WARNING: this program is not supposed to be installed on the "
+           "system. It is only used at installation time to convert the "
+           "the binary fcrontabs in the old format (fcron < 1.1.0, which "
+           "was published in 2001) to the present one."
        );
 
     exit(EXIT_OK);
@@ -70,6 +77,11 @@ usage()
            "convert-fcrontab -V\n"
            "convert-fcrontab user\n"
            "  Update the fcrontab of \"user\" to fit the new binary format.\n"
+           "\n"
+           "WARNING: this program is not supposed to be installed on the "
+           "system. It is only used at installation time to convert the "
+           "the binary fcrontabs in the old format (fcron < 1.1.0, which "
+           "was published in 2001) to the present one."
        );
     
     exit(EXIT_ERR);
@@ -236,6 +248,9 @@ main(int argc, char *argv[])
     extern int optind, opterr, optopt;
     char *user_to_update = NULL;
 
+    rootuid = get_user_uid_safe(ROOTNAME);
+    rootgid = get_group_gid_safe(ROOTGROUP);
+
     if ( strrchr(argv[0], '/') == NULL) prog_name = argv[0];
     else prog_name = strrchr(argv[0], '/') + 1;
 
index 043896cc5ff342c66a91d18ef9bce098e4d9366d..4df34be285c5b646b59e66e225175bc31d6692cc 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: convert-fcrontab.h,v 1.3 2006-01-11 00:54:25 thib Exp $ */
+ /* $Id: convert-fcrontab.h,v 1.4 2006-05-20 16:27:51 thib Exp $ */
 
 #ifndef __CONVERT_FCRONTAB_H__
 #define __CONVERT_FCRONTAB_H__
@@ -29,4 +29,9 @@
 /* We create a .h (even if empty !)  because we have a generic rule
    in Makefile to create .o files which needs the corresponding .h to exist. */
 
+#include "global.h"
+
+extern uid_t rootuid;
+extern gid_t rootgid;
+
 #endif /* __CONVERT_FCRONTAB_H__ */
diff --git a/fcron.c b/fcron.c
index 5b751fe263b57a33ad049da7875c92ba65c04e8f..436653928048af164e6a28ae32f1ab2234bd6a45 100644 (file)
--- a/fcron.c
+++ b/fcron.c
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.c,v 1.77 2006-02-05 20:59:08 thib Exp $ */
+ /* $Id: fcron.c,v 1.78 2006-05-20 16:27:10 thib Exp $ */
 
 #include "fcron.h"
 
@@ -33,7 +33,7 @@
 #include "socket.h"
 #endif
 
-char rcs_info[] = "$Id: fcron.c,v 1.77 2006-02-05 20:59:08 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.78 2006-05-20 16:27:10 thib Exp $";
 
 void main_loop(void);
 void check_signal(void);
@@ -79,6 +79,12 @@ mode_t saved_umask;           /* default root umask */
 char *prog_name = NULL;
 char *orig_tz_envvar = NULL;
 
+/* uid/gid of user/group root 
+ * (we don't use the static UID or GID as we ask for user and group names
+ * in the configure script) */
+uid_t rootuid = 0;
+gid_t rootgid = 0;
+
 /* have we got a signal ? */
 char sig_conf = 0;            /* is 1 when we got a SIGHUP, 2 for a SIGUSR1 */ 
 char sig_chld = 0;            /* is 1 when we got a SIGCHLD */  
@@ -391,9 +397,9 @@ create_spooldir(char *dir)
     /* create a new spool dir for fcron : set correctly its mode and owner */
 {
     int dir_fd = -1;
-    struct passwd *pass = NULL;
-    struct group *grp = NULL;
     struct stat st;
+    uid_t useruid = get_user_uid_safe(USERNAME);
+    gid_t usergid = get_group_gid_safe(GROUPNAME);
 
     if ( mkdir(dir, 0) != 0 && errno != EEXIST )
        die_e("Cannot create dir %s", dir);
@@ -411,13 +417,7 @@ create_spooldir(char *dir)
        die("%s exists and is not a directory", dir);
     }
 
-    if ( (pass = getpwnam(USERNAME)) == NULL )
-       die_e("Cannot getpwnam(%s)", USERNAME);
-
-    if ( (grp = getgrnam(GROUPNAME)) == NULL )
-       die_e("Cannot getgrnam(%s)", GROUPNAME);
-
-    if ( fchown(dir_fd, pass->pw_uid, grp->gr_gid) != 0 ) {
+    if ( fchown(dir_fd, useruid, usergid) != 0 ) {
        close(dir_fd);
        die_e("Cannot fchown dir %s to %s:%s", dir, USERNAME, GROUPNAME);
     }
@@ -488,6 +488,9 @@ int
 main(int argc, char **argv)
 {
 
+    rootuid = get_user_uid_safe(ROOTNAME);
+    rootgid = get_group_gid_safe(ROOTGROUP);
+
     /* we set it to 022 in order to get a pidfile readable by fcrontab
      * (will be set to 066 later) */
     saved_umask = umask(022);
@@ -499,7 +502,7 @@ main(int argc, char **argv)
 
     {
        uid_t daemon_uid;                 
-       if ( (daemon_uid = getuid()) != ROOTUID )
+       if ( (daemon_uid = getuid()) != rootuid )
            die("Fcron must be executed as root");
     }
 
diff --git a/fcron.h b/fcron.h
index 883d240b32a6be164d71ade9e264f4a9b093f198..23326a5f0c628f586010e0522d95031fd3b30165 100644 (file)
--- a/fcron.h
+++ b/fcron.h
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.h,v 1.33 2006-01-11 00:53:01 thib Exp $ */
+ /* $Id: fcron.h,v 1.34 2006-05-20 16:27:20 thib Exp $ */
 
 #ifndef __FCRON_H__
 #define __FCRON_H__
@@ -69,6 +69,8 @@ extern pid_t daemon_pid;
 extern char *orig_tz_envvar;
 extern mode_t saved_umask;
 extern char *prog_name;
+extern uid_t rootuid;
+extern gid_t rootgid;
 extern char sig_hup;
 extern struct cf_t *file_base;
 extern struct job_t *queue_base;
index a44e7896e5e9948098a76d09bbbff0013142e8bc..c45bd157e2c3f7921c1f2115f8161a9a7b9293e0 100644 (file)
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcrondyn.c,v 1.14 2006-01-11 00:48:33 thib Exp $ */
+ /* $Id: fcrondyn.c,v 1.15 2006-05-20 16:26:17 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.14 2006-01-11 00:48:33 thib Exp $";
+char rcs_info[] = "$Id: fcrondyn.c,v 1.15 2006-05-20 16:26:17 thib Exp $";
 
 void info(void);
 void usage(void);
@@ -67,6 +67,12 @@ char foreground = 1;
 char dosyslog = 1;
 pid_t daemon_pid = 0;
 
+/* uid/gid of user/group root 
+ * (we don't use the static UID or GID as we ask for user and group names
+ * in the configure script) */
+uid_t rootuid = 0;
+gid_t rootgid = 0;
+
 /* misc */
 char *user_str;
 uid_t user_uid;
@@ -223,7 +229,7 @@ parse_cmd(char *cmd_str, long int **cmd, int *cmd_len)
            }
 
            /* use default value : currently, works only with CUR_USER */
-           if ( user_uid == ROOTUID ) {
+           if ( user_uid == rootuid ) {
                /* default for root = all */
                int_buf = ALL;
                Write_cmd( int_buf );
@@ -291,7 +297,7 @@ parse_cmd(char *cmd_str, long int **cmd, int *cmd_len)
            case NICE_VALUE:
                /* after strtol(), cmd_str will be updated (first non-number char) */
                if ( (int_buf = strtol(cmd_str, &cmd_str, 10)) > 20 
-                    || (int_buf < 0 && getuid() != ROOTUID) || int_buf < -20
+                    || (int_buf < 0 && getuid() != rootuid) || int_buf < -20
                     || (! isspace( (int) *cmd_str) && *cmd_str != '\0') ) {
                    fprintf(stderr, "Error : invalid nice value.\n");
                    return INVALID_ARG;
@@ -621,6 +627,9 @@ main(int argc, char **argv)
     int fd = (-1);
     struct passwd *pass = NULL;
 
+    rootuid = get_user_uid_safe(ROOTNAME);
+    rootgid = get_group_gid_safe(ROOTGROUP);
+
     if ( strrchr(argv[0], '/') == NULL) prog_name = argv[0];
     else prog_name = strrchr(argv[0], '/') + 1;
 
index 97eb0f9de40c55295459d2d4e39dcee4f95313c8..2966c081566ab6acf8d8e4ea44947f4dac9ae8c2 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcrondyn.h,v 1.5 2006-01-11 00:49:26 thib Exp $ */
+ /* $Id: fcrondyn.h,v 1.6 2006-05-20 16:26:34 thib Exp $ */
 
 #ifndef __FCRONDYN_H__
 #define __FCRONDYN_H__
@@ -33,7 +33,8 @@
 extern char debug_opt;
 extern char dosyslog;
 extern pid_t daemon_pid;
-
+extern uid_t rootuid;
+extern gid_t rootgid;
 
 /* types def */
 #define MAX_NUM_OPT 4
index 7eea5a298c06b36b959212cb6f481c2f928d6b87..a63b7449ac688150ea9499d762b850ebf98436f0 100644 (file)
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcronsighup.c,v 1.9 2006-01-11 00:40:16 thib Exp $ */
+ /* $Id: fcronsighup.c,v 1.10 2006-05-20 16:22:37 thib Exp $ */
 
 #include "fcronsighup.h"
 #include "global.h"
 #include "allow.h"
 
-char rcs_info[] = "$Id: fcronsighup.c,v 1.9 2006-01-11 00:40:16 thib Exp $";
+char rcs_info[] = "$Id: fcronsighup.c,v 1.10 2006-05-20 16:22:37 thib Exp $";
 
 void usage(void);
 void sig_daemon(void);
@@ -35,7 +35,8 @@ pid_t read_pid(void);
 
 uid_t uid = 0;
 uid_t fcrontab_uid = 0;
-
+uid_t rootuid = 0;
+gid_t rootgid = 0;
 
 #ifdef DEBUG
 char debug_opt = 1;       /* set to 1 if we are in debug mode */
@@ -97,7 +98,7 @@ sig_daemon(void)
      * some bad users to block daemon by sending it SIGHUP all the time */
 {
     /* we don't need to make root wait */
-    if (uid != ROOTUID) {
+    if (uid != rootuid) {
        time_t t = 0;
        int sl = 0;
        FILE *fp = NULL;
@@ -186,8 +187,8 @@ sig_daemon(void)
     foreground = 1;
 
 #ifdef USE_SETE_ID
-    if (seteuid(ROOTUID) != 0)
-       error_e("seteuid(ROOTUID)");
+    if (seteuid(rootuid) != 0)
+       error_e("seteuid(rootuid)");
 #endif /* USE_SETE_ID */
 
     if ( kill(daemon_pid, SIGHUP) != 0)
@@ -205,14 +206,15 @@ sig_daemon(void)
 int
 main(int argc, char **argv)
 {
-    struct passwd *pass;
+    struct passwd *pass = NULL;
+
+    rootuid = get_user_uid_safe(ROOTNAME);
+    rootgid = get_group_gid_safe(ROOTGROUP);
 
     if (strrchr(argv[0],'/')==NULL) prog_name = argv[0];
     else prog_name = strrchr(argv[0],'/')+1;
 
-    if ( ! (pass = getpwnam(USERNAME)) )
-       die("user \"%s\" is not in passwd file. Aborting.", USERNAME);
-    fcrontab_uid = pass->pw_uid;
+    fcrontab_uid = get_user_uid_safe(USERNAME);
 
 #ifdef USE_SETE_ID
     /* get user's permissions */
index bf4a7afd3e5476595f601812dee577ed90c8c736..2ae814b52970515fb38d3d0f7869c814e297ecc7 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcronsighup.h,v 1.3 2006-01-11 00:40:46 thib Exp $ */
+ /* $Id: fcronsighup.h,v 1.4 2006-05-20 16:23:28 thib Exp $ */
 
 #ifndef __FCRONSIGHUP_H__
 #define __FCRONSIGHUP_H__
@@ -29,4 +29,9 @@
 /* We create a .h (even if empty !)  because we have a generic rule
    in Makefile to create .o files which needs the corresponding .h to exist. */
 
+#include "global.h"
+
+extern uid_t rootuid;
+extern gid_t rootgid;
+
 #endif /* __FCRONSIGHUP_H__ */
index 4579305ccbaea4b813ccf722aeefbafd3df6a5ea..1aa5605e6ed9eb0d73b82e5b3a69cf016a805d26 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcrontab.c,v 1.68 2006-01-11 00:49:33 thib Exp $ */
+ /* $Id: fcrontab.c,v 1.69 2006-05-20 16:26:37 thib Exp $ */
 
 /* 
  * The goal of this program is simple : giving a user interface to fcron
@@ -46,7 +46,7 @@
 #include "temp_file.h"
 #include "read_string.h"
 
-char rcs_info[] = "$Id: fcrontab.c,v 1.68 2006-01-11 00:49:33 thib Exp $";
+char rcs_info[] = "$Id: fcrontab.c,v 1.69 2006-05-20 16:26:37 thib Exp $";
 
 void info(void);
 void usage(void);
@@ -69,6 +69,9 @@ char debug_opt = 1;       /* set to 1 if we are in debug mode */
 char debug_opt = 0;       /* set to 1 if we are in debug mode */
 #endif
 
+/* uid/gid of users/groups 
+ * (we don't use the static UID or GID as we ask for user and group names
+ * in the configure script) */
 char *user = NULL;
 char *runas = NULL;
 uid_t uid = 0;
@@ -76,6 +79,8 @@ uid_t asuid = 0;
 gid_t asgid = 0;
 uid_t fcrontab_uid = 0;
 gid_t fcrontab_gid = 0;
+uid_t rootuid = 0;
+gid_t rootgid = 0;
 
 char need_sig = 0;           /* do we need to signal fcron daemon */
 
@@ -201,9 +206,9 @@ copy_src(char *orig, char *dest)
      * except for root. Root requires filesystem uid root for security
      * reasons */
 #ifdef USE_SETE_ID
-    if (asuid == ROOTUID) {
-       if (seteuid(ROOTUID) != 0)
-           die_e("seteuid(ROOTUID) : old source file kept");
+    if (asuid == rootuid) {
+       if (seteuid(rootuid) != 0)
+           die_e("seteuid(rootuid) : old source file kept");
     } 
     else {
        if (seteuid(fcrontab_uid) != 0)
@@ -226,15 +231,15 @@ copy_src(char *orig, char *dest)
     }
 
 #ifdef USE_SETE_ID
-    if (asuid != ROOTUID && seteuid(uid) != 0)
+    if (asuid != rootuid && seteuid(uid) != 0)
        die_e("seteuid(uid[%d]) : old source file kept", uid);
 #endif
-    if (asuid == ROOTUID ) {
+    if (asuid == rootuid ) {
        if ( fchmod(to_fd, S_IWUSR | S_IRUSR) != 0 ) {
            error_e("Could not fchmod %s to 600", tmp_filename_str);
            goto exiterr;
        }
-       if ( fchown(to_fd, ROOTUID, fcrontab_gid) != 0 ) {
+       if ( fchown(to_fd, rootuid, fcrontab_gid) != 0 ) {
            error_e("Could not fchown %s to root", tmp_filename_str);
            goto exiterr;
        }
@@ -311,7 +316,7 @@ remove_fcrontab(char rm_orig)
        if ( errno != EEXIST )
            error_e("Can't create file %s", buf);
     }
-    else if ( asuid == ROOTUID && fchown(fd, ROOTUID, fcrontab_gid) != 0 )
+    else if ( asuid == rootuid && fchown(fd, rootuid, fcrontab_gid) != 0 )
        error_e("Could not fchown %s to root", buf);
     close(fd);
     
@@ -488,7 +493,7 @@ edit_file(char *buf)
        switch ( pid = fork() ) {
        case 0:
            /* child */
-           if ( uid != ROOTUID ) {
+           if ( uid != rootuid ) {
                if (setgid(asgid) < 0) {
                    error_e("setgid(asgid)");
                    goto exiterr;
@@ -546,7 +551,7 @@ edit_file(char *buf)
                close(fd);
                goto exiterr;
            }
-           if ( fchown(fd, ROOTUID, ROOTGID) != 0 || fchmod(fd, S_IRUSR|S_IWUSR) != 0 ){
+           if ( fchown(fd, rootuid, rootgid) != 0 || fchmod(fd, S_IRUSR|S_IWUSR) != 0 ){
                fprintf(stderr, "Can't chown or chmod %s.\n", tmp_str);
                close(fd);
                goto exiterr;
@@ -814,7 +819,7 @@ parseopt(int argc, char *argv[])
            usage(); break;
 
        case 'u':
-           if (uid != ROOTUID) {
+           if (uid != rootuid) {
                fprintf(stderr, "must be privileged to use -u\n");
                xexit(EXIT_ERR);
            }
@@ -903,7 +908,7 @@ parseopt(int argc, char *argv[])
        else
            usage();
 
-       if (uid != ROOTUID) {
+       if (uid != rootuid) {
            fprintf(stderr, "must be privileged to use -u\n");
            xexit(EXIT_ERR);
        }
@@ -913,7 +918,7 @@ parseopt(int argc, char *argv[])
        if ( list_opt + rm_opt + edit_opt + reinstall_opt == 0 )
            file_opt = optind;
        else {
-           if (uid != ROOTUID) {
+           if (uid != rootuid) {
                fprintf(stderr, "must be privileged to use [user|-u user]\n");
                xexit(EXIT_ERR);
            }
@@ -937,8 +942,8 @@ parseopt(int argc, char *argv[])
 #ifdef SYSFCRONTAB
        if ( strcmp(user, SYSFCRONTAB) == 0 ) {
            is_sysfcrontab = 1;
-           asuid = ROOTUID;
-           asgid = ROOTGID;
+           asuid = rootuid;
+           asgid = rootgid;
        }
        else
 #endif /* def SYSFCRONTAB */ 
@@ -979,6 +984,9 @@ main(int argc, char **argv)
 #endif
     struct passwd *pass;
 
+    rootuid = get_user_uid_safe(ROOTNAME);
+    rootgid = get_group_gid_safe(ROOTGROUP);
+
     memset(buf, 0, sizeof(buf));
     memset(file, 0, sizeof(file));
 
@@ -1054,10 +1062,10 @@ main(int argc, char **argv)
 
 #else /* USE_SETE_ID */
 
-    if (setuid(ROOTUID) != 0 ) 
-       die_e("Could not change uid to ROOTUID"); 
-    if (setgid(ROOTGID) != 0)
-       die_e("Could not change gid to ROOTGID");
+    if (setuid(rootuid) != 0 ) 
+       die_e("Could not change uid to rootuid"); 
+    if (setgid(rootgid) != 0)
+       die_e("Could not change gid to rootgid");
     /* change directory */
     if (chdir(fcrontabs) != 0) {
        error_e("Could not chdir to %s", fcrontabs);
@@ -1067,7 +1075,7 @@ main(int argc, char **argv)
     
     /* this program is seteuid : we set default permission mode
      * to 640 for a normal user, 600 for root, for security reasons */
-    if ( asuid == ROOTUID )
+    if ( asuid == rootuid )
        umask(066);  /* octal : '0' + number in octal notation */
     else
        umask(026);
index bd315fe0b63fa6c8efc7df39ff83f4d838133440..914bf15cc8e21c39505d32c4b61559e8538e5de4 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcrontab.h,v 1.19 2006-01-11 00:51:17 thib Exp $ */
+ /* $Id: fcrontab.h,v 1.20 2006-05-20 16:26:58 thib Exp $ */
 
 #ifndef __FCRONTAB_H__
 #define __FCRONTAB_H__
@@ -39,5 +39,7 @@ extern uid_t uid;
 extern uid_t asuid;
 extern uid_t fcrontab_uid;
 extern gid_t fcrontab_gid;
+extern uid_t rootuid;
+extern gid_t rootgid;
 
 #endif /* __FCRONTAB_H__ */
index 4a4cc8647a9a0f57dae68f85dc8ac95100244bf8..bc4cd6fcaf72bbe208a42f0e6178770e7f194870 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fileconf.c,v 1.76 2006-01-11 00:53:05 thib Exp $ */
+ /* $Id: fileconf.c,v 1.77 2006-05-20 16:27:23 thib Exp $ */
 
 #include "fcrontab.h"
 
@@ -186,7 +186,7 @@ read_file(char *filename)
     if ( debug_opt )
        fprintf(stderr, "FILE %s\n", file_name);
 
-    if (strcmp(runas, "root") == 0)
+    if (strcmp(runas, ROOTNAME) == 0)
        max_entries = 65535;
 
     /* max_lines acts here as a security counter to avoid endless loop. */
@@ -376,7 +376,7 @@ get_nice(char *ptr, int *nice)
        return NULL;
 
     if ( negative == 1 ) {
-       if (getuid() != ROOTUID) {
+       if (getuid() != rootuid) {
            fprintf(stderr, "must be privileged to use a negative argument "
                    "with nice: set to 0\n");
            need_correction = 1;
@@ -842,7 +842,7 @@ read_opt(char *ptr, cl_t *cl)
        }
 
        else if(strcmp(opt_name, "runas") == 0) {
-           if (getuid() != ROOTUID) {
+           if (getuid() != rootuid) {
                fprintf(stderr, "must be privileged to use option runas: "
                        "skipping option\n");
                need_correction = 1;
@@ -1085,7 +1085,7 @@ check_username(char *ptr, cf_t *cf, cl_t *cl)
         ptr = ptr + indx;      /* move ptr to the next word */
        Skip_blanks(ptr);
 
-       if (getuid() != ROOTUID) {
+       if (getuid() != rootuid) {
            fprintf(stderr, "must be privileged to run as another user : "
                    "ignoring\n");
        } else {