* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fileconf.c,v 1.64 2002-10-05 14:26:05 thib Exp $ */
+ /* $Id: fileconf.c,v 1.65 2002-10-06 16:56:22 thib Exp $ */
#include "fcrontab.h"
char *get_nice(char *ptr, int *nice);
char *get_bool(char *ptr, int *i);
char *read_field(char *ptr, bitstr_t *ary, int max, const char **names);
-void read_freq(char *ptr, CF *cf);
-void read_arys(char *ptr, CF *cf);
-void read_period(char *ptr, CF *cf);
-void read_env(char *ptr, CF *cf);
-char *read_opt(char *ptr, CL *cl);
-char *check_username(char *ptr, CF *cf, CL *cl);
+void read_freq(char *ptr, cf_t *cf);
+void read_arys(char *ptr, cf_t *cf);
+void read_period(char *ptr, cf_t *cf);
+void read_env(char *ptr, cf_t *cf);
+char *read_opt(char *ptr, cl_t *cl);
+char *check_username(char *ptr, cf_t *cf, cl_t *cl);
char need_correction;
-CL default_line; /* default options for a line */
+cl_t default_line; /* default options for a line */
char *file_name;
int line;
int
read_file(char *filename)
- /* read file "name" and append CF list */
+ /* read file "name" and append cf_t list */
{
- CF *cf = NULL;
+ cf_t *cf = NULL;
FILE *file = NULL;
char buf[LINE_LEN];
int max_lines;
int ret;
bzero(buf, sizeof(buf));
- bzero(&default_line, sizeof(CL));
+ bzero(&default_line, sizeof(cl_t));
need_correction = 0;
line = 1;
file_name = filename;
return ERR;
}
- Alloc(cf, CF);
+ Alloc(cf, cf_t);
cf->cf_user = strdup2(user);
default_line.cl_file = cf;
default_line.cl_runas = strdup2(runas);
}
void
-read_env(char *ptr, CF *cf)
+read_env(char *ptr, cf_t *cf)
/* append env variable list.
* (remove blanks) */
{
char *
-read_opt(char *ptr, CL *cl)
+read_opt(char *ptr, cl_t *cl)
/* read one or several options and fill in the field "option" */
{
char opt_name[20];
if ( in_brackets && (ptr = get_bool(ptr, &i)) == NULL )
Handle_err;
if ( i == 1 ) {
- bzero(cl, sizeof(CL));
+ bzero(cl, sizeof(cl_t));
Set(cl->cl_runas, runas);
Set(cl->cl_mailto, runas);
set_default_opt(cl->cl_option);
char *
-check_username(char *ptr, CF *cf, CL *cl)
+check_username(char *ptr, cf_t *cf, cl_t *cl)
/* check ptr to see if the first word is a username, returns new ptr */
{
short int indx = 0;
void
-read_freq(char *ptr, CF *cf)
+read_freq(char *ptr, cf_t *cf)
/* read a freq entry, and append a line to cf */
{
- CL *cl = NULL;
+ cl_t *cl = NULL;
- Alloc(cl, CL);
- memcpy(cl, &default_line, sizeof(CL));
+ Alloc(cl, cl_t);
+ memcpy(cl, &default_line, sizeof(cl_t));
cl->cl_runas = strdup2(default_line.cl_runas);
cl->cl_mailto = strdup2(default_line.cl_mailto);
cl->cl_first = -1; /* 0 is a valid value, so we have to use -1 to detect unset */
}
void
-read_arys(char *ptr, CF *cf)
+read_arys(char *ptr, cf_t *cf)
/* read a run freq number plus a normal fcron line */
{
- CL *cl = NULL;
+ cl_t *cl = NULL;
unsigned int i = 0;
- Alloc(cl, CL);
- memcpy(cl, &default_line, sizeof(CL));
+ Alloc(cl, cl_t);
+ memcpy(cl, &default_line, sizeof(cl_t));
cl->cl_runas = strdup2(default_line.cl_runas);
cl->cl_mailto = strdup2(default_line.cl_mailto);
}
void
-read_period(char *ptr, CF *cf)
+read_period(char *ptr, cf_t *cf)
/* read a line to run periodically (i.e. once a day, once a week, etc) */
{
- CL *cl = NULL;
+ cl_t *cl = NULL;
short int remain = 8;
- Alloc(cl, CL);
- memcpy(cl, &default_line, sizeof(CL));
+ Alloc(cl, cl_t);
+ memcpy(cl, &default_line, sizeof(cl_t));
cl->cl_runas = strdup2(default_line.cl_runas);
cl->cl_mailto = strdup2(default_line.cl_mailto);
/* free a file if user_name is not null
* otherwise free all files */
{
- CF *file = NULL;
- CF *prev_file = NULL;
- CL *line = NULL;
- CL *cur_line = NULL;
+ cf_t *file = NULL;
+ cf_t *prev_file = NULL;
+ cl_t *line = NULL;
+ cl_t *cur_line = NULL;
env_t *env = NULL;
env_t *cur_env = NULL;
/* Store the informations relatives to the executions
* of tasks at a defined frequency of system's running time */
{
- CF *file = NULL;
- CL *line = NULL;
+ cf_t *file = NULL;
+ cl_t *line = NULL;
int fd;
env_t *env = NULL;
for (file = file_base; file; file = file->cf_next) {
/* open file */
- fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC);
+ fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, S_IRUSR | S_IWUSR);
if ( fd == -1 ) {
error_e("Could not open %s : file has not be installed.", path);
return ERR;
}
+ /* save_file() is run under user's right.
+ * If fcrontab is run by root for a normal user, we must change the file's
+ * ownership to this user, in order to make fcron check the runas fields.
+ * (a malicious user could put a runas(root) and wait for the fcrontab to be
+ * installed by root) */
+ if ( fchown(fd, asuid, fcrontab_gid) != 0 ) {
+ error_e("Could not fchown %s : file has not been installed.", path);
+ close(fd);
+ remove(path);
+ return ERR;
+ }
+
/* save file : */
/* put program's version : it permit to daemon not to load