/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: conf.c,v 1.51 2001-09-12 13:45:54 thib Exp $ */
+ /* $Id: conf.c,v 1.52 2001-12-23 22:04:51 thib Exp $ */
#include "fcron.h"
}
if ( strncmp(file_name,"new.", 4) == 0 ) {
- if ( file_stat.st_uid == 0 )
- /* file is owned by root : no test needed : set runas to 0 */
- runas = 0;
+ 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
* the owner of the file */
}
}
else {
- if ( file_stat.st_uid == 0 )
+ if ( file_stat.st_uid == ROOTUID )
/* file is owned by root : either this file has already been parsed
* at least once by fcron, either it is the root's fcrontab */
- runas = 0;
+ runas = ROOTUID;
else {
error("Non-new file %s owned by someone else than root",file_name);
goto err;
error("Cannot read user's name : file ignored");
goto err;
}
- if ( runas != 0 ) {
+ 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) */
}
/* set runas field if necessary (to improve security) */
- if (runas > 0) {
+ 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);
/* chown the file to root:root : this file should only be read and
* modified by fcron (not fcrontab) */
- if (fchown(fileno(f), 0, 0) != 0)
+ if (fchown(fileno(f), ROOTUID, ROOTGID) != 0)
error_e("Could not fchown \"%s\"", file->cf_user);
/* save file : */
/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: config.h.in,v 1.37 2001-09-12 13:50:09 thib Exp $ */
+ /* $Id: config.h.in,v 1.38 2001-12-23 22:05:03 thib Exp $ */
/* *********************************************************** */
/* Define if we should use sete[ug]id() funcs */
#undef USE_SETE_ID
-/* username to run under */
-#undef USERNAME
+/* root uid and gid */
+#undef ROOTUID
+#undef ROOTGID
-/* groupname to run under */
+/* user and group name to run under */
+#undef USERNAME
#undef GROUPNAME
/* Define to empty if the keyword does not work. */
AC_MSG_ERROR(Need rootname.)
;;
yes)
- if cat /etc/passwd | grep "^root:" > /dev/null; then
+ if LINE=`cat /etc/passwd | grep "^root:"`; then
rootname=root
- AC_MSG_RESULT($rootname)
+ rootuid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootname uid: $rootuid)
else
AC_MSG_ERROR([
Cannot determine root's username: try option --with-rootname=USERNAME])
fi
;;
*)
- if cat /etc/passwd | grep "^$withval:" > /dev/null ; then
+ if LINE=`cat /etc/passwd | grep "^$withval:"`; then
rootname=$withval
- AC_MSG_RESULT($rootname)
+ rootuid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootname uid: $rootuid)
else
AC_MSG_ERROR([
Invalid root's username : not in /etc/passwd])
fi
;;
esac ],
- if cat /etc/passwd | grep "^root:" > /dev/null ; then
+ if LINE=`cat /etc/passwd | grep "^root:"`; then
rootname=root
- AC_MSG_RESULT($rootname)
+ rootuid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootname uid: $rootuid)
else
AC_MSG_ERROR([
Cannot determine root's username: try option --with-rootname=USERNAME])
AC_MSG_ERROR(Need rootgroup.)
;;
yes)
- if cat /etc/group | grep "^root:" > /dev/null ; then
+ if LINE=`cat /etc/group | grep "^root:"`; then
rootgroup=root
- AC_MSG_RESULT($rootgroup)
- elif cat /etc/group | grep "^wheel:" > /dev/null ; then
+ rootgid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootgroup gid: $rootgid)
+ elif LINE=`cat /etc/group | grep "^wheel:"`; then
rootgroup=wheel
- AC_MSG_RESULT($rootgroup)
+ rootgid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootgroup gid: $rootgid)
else
AC_MSG_ERROR([
Cannot determine root's groupname: try option --with-rootgroup=GROUPNAME])
fi
;;
*)
- if cat /etc/group | grep "^$withval:" > /dev/null ; then
+ if LINE=`cat /etc/group | grep "^$withval:"`; then
rootgroup=$withval
- AC_MSG_RESULT($rootgroup)
+ rootgid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootgroup gid: $rootgid)
else
AC_MSG_ERROR([
Invalid root's groupname : not in /etc/group])
fi
;;
esac ],
- if cat /etc/group | grep "^root:" > /dev/null ; then
+ if LINE=`cat /etc/group | grep "^root:"`; then
rootgroup=root
- AC_MSG_RESULT($rootgroup)
- elif cat /etc/group | grep "^wheel:" > /dev/null ; then
+ rootgid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootgroup gid: $rootgid)
+ elif LINE=`cat /etc/group | grep "^wheel:"`; then
rootgroup=wheel
- AC_MSG_RESULT($rootgroup)
+ rootgid=`echo $LINE | awk 'BEGIN {FS= ":" } {print $3}'`
+ AC_MSG_RESULT($rootgroup gid: $rootgid)
else
AC_MSG_ERROR([
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"
/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcron.c,v 1.56 2001-09-12 13:44:50 thib Exp $ */
+ /* $Id: fcron.c,v 1.57 2001-12-23 22:04:37 thib Exp $ */
#include "fcron.h"
#include "conf.h"
#include "job.h"
-char rcs_info[] = "$Id: fcron.c,v 1.56 2001-09-12 13:44:50 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.57 2001-12-23 22:04:37 thib Exp $";
void main_loop(void);
void check_signal(void);
{
fprintf(stderr,
"fcron " VERSION_QUOTED " - periodic command scheduler\n"
- "Copyright 2000-2001 Thibault Godouet <fcron@free.fr>\n"
+ "Copyright 2000-2002 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"
);
{
uid_t daemon_uid;
- if ( (daemon_uid = getuid()) != 0 )
+ if ( (daemon_uid = getuid()) != ROOTUID )
die("Fcron must be executed as root");
}
/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcronsighup.c,v 1.2 2001-07-09 11:49:11 thib Exp $ */
+ /* $Id: fcronsighup.c,v 1.3 2001-12-23 22:03:08 thib Exp $ */
#include "global.h"
#include "subs.h"
#include "allow.h"
-char rcs_info[] = "$Id: fcronsighup.c,v 1.2 2001-07-09 11:49:11 thib Exp $";
+char rcs_info[] = "$Id: fcronsighup.c,v 1.3 2001-12-23 22:03:08 thib Exp $";
void usage(void);
void sig_daemon(void);
{
fprintf(stderr,
"fcronsighup "VERSION_QUOTED" - make fcron update its fcrontabs\n"
- "Copyright 2000-2001 Thibault Godouet <fcron@free.fr>\n"
+ "Copyright 2000-2002 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"
* some bad users to block daemon by sending it SIGHUP all the time */
{
/* we don't need to make root wait */
- if (uid != 0) {
+ if (uid != ROOTUID) {
time_t t = 0;
int sl = 0;
FILE *fp = NULL;
/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcrontab.c,v 1.52 2001-11-04 18:58:17 thib Exp $ */
+ /* $Id: fcrontab.c,v 1.53 2001-12-23 22:04:10 thib Exp $ */
/*
* The goal of this program is simple : giving a user interface to fcron
#include "allow.h"
#include "fileconf.h"
-char rcs_info[] = "$Id: fcrontab.c,v 1.52 2001-11-04 18:58:17 thib Exp $";
+char rcs_info[] = "$Id: fcrontab.c,v 1.53 2001-12-23 22:04:10 thib Exp $";
void info(void);
void usage(void);
{
fprintf(stderr,
"fcrontab " VERSION_QUOTED " - user interface to daemon fcron\n"
- "Copyright 2000-2001 Thibault Godouet <fcron@free.fr>\n"
+ "Copyright 2000-2002 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"
);
* except for root. Root requires filesystem uid root for security
* reasons */
#ifdef USE_SETE_ID
- if (asuid != 0 && seteuid(fcrontab_uid) != 0)
+ if (asuid != ROOTUID && seteuid(fcrontab_uid) != 0)
error_e("seteuid(fcrontab_uid[%d])", fcrontab_uid);
#endif
if ((to = fopen(dest, "w")) == NULL) {
return ERR;
}
#ifdef USE_SETE_ID
- if (asuid != 0 && seteuid(uid) != 0)
+ if (asuid != ROOTUID && seteuid(uid) != 0)
die_e("seteuid(uid[%d])", uid);
#endif
- if (asuid == 0 ) {
+ if (asuid == ROOTUID ) {
if ( fchmod(fileno(to), S_IWUSR | S_IRUSR) != 0 )
error_e("Could not fchmod %s to 600", dest);
- if ( fchown(fileno(to), 0, fcrontab_gid) != 0 )
+ if ( fchown(fileno(to), ROOTUID, fcrontab_gid) != 0 )
error_e("Could not fchown %s to root", dest);
}
switch ( pid = fork() ) {
case 0:
/* child */
- if ( uid != 0 ) {
+ if ( uid != ROOTUID ) {
if (setgid(asgid) < 0) {
error_e("setgid(asgid)");
goto exiterr;
close(fd);
goto exiterr;
}
- if ( fchown(fd, 0, 0) != 0 || fchmod(fd, S_IRUSR|S_IWUSR) != 0 ) {
+ if ( fchown(fd, ROOTUID, ROOGID) != 0 || fchmod(fd, S_IRUSR|S_IWUSR) != 0 ) {
fprintf(stderr, "Can't chown or chmod %s.\n", tmp_str);
close(fd);
goto exiterr;
usage(); break;
case 'u':
- if (getuid() != 0) {
+ if (getuid() != ROOTUID) {
fprintf(stderr, "must be privileged to use -u\n");
xexit(EXIT_ERR);
}
else
usage();
- if (getuid() != 0) {
+ if (getuid() != ROOTUID) {
fprintf(stderr, "must be privileged to use -u\n");
xexit(EXIT_ERR);
}
if ( list_opt + rm_opt + edit_opt + reinstall_opt == 0 )
file_opt = optind;
else {
- if (getuid() != 0) {
+ if (getuid() != ROOTUID) {
fprintf(stderr, "must be privileged to use [user|-u user]\n");
xexit(EXIT_ERR);
}
#else /* USE_SETE_ID */
- if (setuid(0) != 0 )
- die_e("Could not change uid to 0");
- if (setgid(0) != 0)
- die_e("Could not change gid to 0");
+ 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);
/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fileconf.c,v 1.54 2001-12-23 12:20:46 thib Exp $ */
+ /* $Id: fileconf.c,v 1.55 2001-12-23 22:04:44 thib Exp $ */
#include "fcrontab.h"
return NULL;
if ( negative == 1 ) {
- if (getuid() != 0) {
+ if (getuid() != ROOTUID) {
fprintf(stderr, "must be privileged to use a negative argument "
"with nice: set to 0\n");
need_correction = 1;
}
else if(strcmp(opt_name, "runas") == 0) {
- if (getuid() != 0) {
+ if (getuid() != ROOTUID) {
fprintf(stderr, "must be privileged to use option runas: "
"skipping option\n");
need_correction = 1;
ptr = ptr + indx; /* move ptr to the next word */
Skip_blanks(ptr);
- if (getuid() != 0) {
+ if (getuid() != ROOTUID) {
fprintf(stderr, "must be privileged to run as another user : "
"ignoring\n");
} else {
/*
* FCRON - periodic command scheduler
*
- * Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
+ * Copyright 2000-2002 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: subs.c,v 1.15 2001-08-17 19:50:08 thib Exp $ */
+ /* $Id: subs.c,v 1.16 2001-12-23 22:05:20 thib Exp $ */
#include "global.h"
#include "subs.h"
}
/* check if the file is secure : owned and writable only by root */
- if ( fstat(fileno(f), &st) != 0 || st.st_uid != 0
+ if ( fstat(fileno(f), &st) != 0 || st.st_uid != ROOTUID
|| st.st_mode & S_IWGRP || st.st_mode & S_IWOTH ) {
error("Conf file (%s) must be owned by root and (no more than) 644 : "
"ignored", fcronconf);