ifeq ($(FCRONDYN), 1)
LIBOBJS := socket.o $(LIBOBJS)
endif
-OBJSD := fcron.o subs.o save.o temp_file.o log.o database.o job.o conf.o u_list.o exe_list.o lavg_list.o env_list.o $(LIBOBJS)
-OBJSTAB := fcrontab.o subs.o save.o temp_file.o log.o fileconf.o allow.o read_string.o u_list.o env_list.o
-OBJSDYN := fcrondyn.o subs.o log.o allow.o read_string.o
+OBJSD := fcron.o subs.o save.o temp_file.o log.o database.o job.o conf.o u_list.o exe_list.o lavg_list.o env_list.o fcronconf.o $(LIBOBJS)
+OBJSTAB := fcrontab.o subs.o save.o temp_file.o log.o fileconf.o allow.o read_string.o u_list.o env_list.o fcronconf.o
+OBJSDYN := fcrondyn.o subs.o log.o allow.o read_string.o fcronconf.o
OBJCONV := convert-fcrontab.o subs.o save.o log.o u_list.o env_list.o
-OBJSIG := fcronsighup.o subs.o log.o allow.o
+OBJSIG := fcronsighup.o subs.o log.o allow.o fcronconf.o
HEADERSALL := config.h $(SRCDIR)/global.h $(SRCDIR)/log.h $(SRCDIR)/subs.h $(SRCDIR)/save.h $(SRCDIR)/option.h $(SRCDIR)/dyncom.h
# this is a regular expression :
<sect2>
<title>High priority</title>
<itemizedlist>
- <listitem>
- <para>move fcron.conf stuff from subs.{c} to a new fcronconf.{c|h}</para>
- </listitem>
<listitem>
<para>change copyright to ...,2008,2009,2010</para>
</listitem>
<listitem>
- <para>check fcron for memory leaks using library</para>
+ <para>could be worth checking fcron for memory leaks using specialized library (just in case...)</para>
</listitem>
<listitem>
<para>Test (and use ?) docbook2x-man -- xlstproc ? cf http://antoine.ginies.free.fr/docbook/ch09.html</para>
#include "conf.h"
#include "job.h"
#include "temp_file.h"
+#include "fcronconf.h"
#ifdef FCRONDYN
#include "socket.h"
#endif
#include "global.h"
#include "exe_list.h"
#include "lavg_list.h"
+#include "fcronconf.h"
#ifdef HAVE_CRYPT_H
#include <crypt.h>
--- /dev/null
+/*
+ * FCRON - periodic command scheduler
+ *
+ * Copyright 2000-2009 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * The GNU General Public License can also be found in the file
+ * `LICENSE' that comes with the fcron source distribution.
+ */
+
+ /* $Id: subs.c,v 1.29 2008-05-11 11:08:23 thib Exp $ */
+
+#include "global.h"
+#include "fcronconf.h"
+#include "subs.h"
+
+void init_conf(void);
+
+extern char debug_opt;
+extern uid_t rootuid;
+extern gid_t rootgid;
+
+/* fcron.conf parameters */
+char *fcronconf = NULL;
+char *fcrontabs = NULL;
+char *pidfile = NULL;
+char *fifofile = NULL;
+char *fcronallow = NULL;
+char *fcrondeny = NULL;
+char *shell = NULL;
+char *sendmail = NULL;
+char *editor = NULL;
+
+void
+init_conf(void)
+/* initialises config with compiled in constants */
+{
+ /* set fcronconf if cmd line option -c has not been used */
+ if (fcronconf == NULL)
+ fcronconf = strdup2(ETC "/" FCRON_CONF);
+ fcrontabs = strdup2(FCRONTABS);
+ pidfile = strdup2(PIDFILE);
+ fifofile = strdup2(FIFOFILE);
+ fcronallow = strdup2(ETC "/" FCRON_ALLOW);
+ fcrondeny = strdup2(ETC "/" FCRON_DENY);
+ /* // */
+ /* shell = strdup2(FCRON_SHELL); */
+ shell = strdup2("");
+
+#ifdef SENDMAIL
+ sendmail = strdup2(SENDMAIL);
+#endif
+ editor = strdup2(FCRON_EDITOR);
+}
+
+void
+free_conf(void)
+/* free() the memory allocated in init_conf() */
+{
+ free_safe(fcronconf);
+ free_safe(fcrontabs);
+ free_safe(pidfile);
+ free_safe(fifofile);
+ free_safe(fcronallow);
+ free_safe(fcrondeny);
+ free_safe(shell);
+ free_safe(sendmail);
+ free_safe(editor);
+}
+
+void
+read_conf(void)
+/* reads in a config file and updates the necessary global variables */
+{
+ FILE *f = NULL;
+ struct stat st;
+ char buf[LINE_LEN];
+ char *ptr1 = NULL, *ptr2 = NULL;
+ short namesize = 0;
+ char err_on_enoent = 0;
+ struct group *gr = NULL;
+ gid_t fcrongid = -1;
+
+ if (fcronconf != NULL)
+ /* fcronconf has been set by -c option : file must exist */
+ err_on_enoent = 1;
+
+ init_conf();
+
+ if ( (f = fopen(fcronconf, "r")) == NULL ) {
+ if ( errno == ENOENT ) {
+ if ( err_on_enoent )
+ die_e("Could not read %s", fcronconf);
+ else
+ /* file does not exist, it is not an error */
+ return;
+ }
+ else {
+ error_e("Could not read %s : config file ignored", fcronconf);
+ return;
+ }
+ }
+
+ /* get fcrongid */
+ gr = getgrnam(GROUPNAME);
+ if ( gr == NULL ) {
+ die_e("Unable to find %s in /etc/group", GROUPNAME);
+ }
+ fcrongid = gr->gr_gid;
+
+ /* check if the file is secure : owner:root, group:fcron,
+ * writable only by owner */
+ if ( fstat(fileno(f), &st) != 0
+ || st.st_uid != rootuid || st.st_gid != fcrongid
+ || st.st_mode & S_IWGRP || st.st_mode & S_IWOTH ) {
+ error("Conf file (%s) must be owned by root:" GROUPNAME
+ " and (no more than) 644 : ignored", fcronconf, GROUPNAME);
+ fclose(f);
+ return;
+ }
+
+ while ( (ptr1 = fgets(buf, sizeof(buf), f)) != NULL ) {
+
+ Skip_blanks(ptr1); /* at the beginning of the line */
+
+ /* ignore comments and blank lines */
+ if ( *ptr1 == '#' || *ptr1 == '\n' || *ptr1 == '\0')
+ continue;
+
+ remove_blanks(ptr1); /* at the end of the line */
+
+ /* get the name of the var */
+ if ( ( namesize = get_word(&ptr1) ) == 0 )
+ /* name is zero-length */
+ error("Zero-length var name at line %s : line ignored", buf);
+
+ ptr2 = ptr1 + namesize;
+
+ /* skip the blanks and the "=" and go to the value */
+ while ( isspace( (int) *ptr2 ) ) ptr2++;
+ if ( *ptr2 == '=' ) ptr2++;
+ while ( isspace( (int) *ptr2 ) ) ptr2++;
+
+ /* find which var the line refers to and update it */
+ if ( strncmp(ptr1, "fcrontabs", namesize) == 0 ) { Set(fcrontabs, ptr2); }
+ else if ( strncmp(ptr1, "pidfile", namesize) == 0 ) { Set(pidfile, ptr2); }
+ else if ( strncmp(ptr1, "fifofile", namesize) == 0 ) { Set(fifofile , ptr2); }
+ else if ( strncmp(ptr1, "fcronallow", namesize) == 0 ) { Set(fcronallow , ptr2); }
+ else if ( strncmp(ptr1, "fcrondeny", namesize) == 0 ) { Set(fcrondeny , ptr2); }
+ else if ( strncmp(ptr1, "shell", namesize) == 0 ) { Set(shell , ptr2); }
+ else if ( strncmp(ptr1, "sendmail", namesize) == 0 ) { Set(sendmail , ptr2); }
+ else if ( strncmp(ptr1, "editor", namesize) == 0 ) { Set(editor , ptr2); }
+ else
+ error("Unknown var name at line %s : line ignored", buf);
+
+ }
+
+ if (debug_opt) {
+ debug(" fcronconf=%s", fcronconf);
+/* debug(" fcronallow=%s", fcronallow); */
+/* debug(" fcrondeny=%s", fcrondeny); */
+/* debug(" fcrontabs=%s", fcrontabs); */
+/* debug(" pidfile=%s", pidfile); */
+/* debug(" fifofile=%s", fifofile); */
+/* debug(" editor=%s", editor); */
+/* debug(" shell=%s", shell); */
+/* debug(" sendmail=%s", sendmail); */
+ }
+
+ fclose(f);
+
+}
+
+
--- /dev/null
+/*
+ * FCRON - periodic command scheduler
+ *
+ * Copyright 2000-2009 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * The GNU General Public License can also be found in the file
+ * `LICENSE' that comes with the fcron source distribution.
+ */
+
+ /* $Id: subs.h,v 1.11 2007-04-14 18:04:23 thib Exp $ */
+
+#ifndef __FCRONCONF_H__
+#define __FCRONCONF_H__
+
+
+/* global variables */
+
+/* fcron.conf parameters */
+extern char *fcronconf;
+extern char *fcronallow;
+extern char *fcrondeny;
+extern char *fcrontabs;
+extern char *pidfile;
+extern char *fifofile;
+extern char *editor;
+extern char *shell;
+extern char *sendmail;
+/* end of global variables */
+
+/* functions prototypes */
+extern void read_conf(void);
+extern void free_conf(void);
+
+#endif /* __FCRONCONF_H__ */
#include "global.h"
#include "dyncom.h"
+#include "fcronconf.h"
/* global variables */
extern char dosyslog;
#include "fcronsighup.h"
#include "global.h"
#include "allow.h"
+#include "fcronconf.h"
char rcs_info[] = "$Id: fcronsighup.c,v 1.14 2008-05-11 10:46:54 thib Exp $";
#define __FCRONTAB_H__
#include "global.h"
+#include "fcronconf.h"
/* global variables */
extern pid_t daemon_pid;
#include "fcron.h"
#include "job.h"
+#include "temp_file.h"
void sig_dfl(void);
void end_job(cl_t *line, int status, FILE *mailf, short mailpos, char **sendmailenv);
#include "socket.h"
#include "getloadavg.h"
#include "database.h"
+#include "fcronconf.h"
void remove_connection(struct fcrondyn_cl **client, struct fcrondyn_cl *prev_client);
#include "global.h"
#include "subs.h"
-void init_conf(void);
-
-extern char debug_opt;
-extern uid_t rootuid;
-extern gid_t rootgid;
-
-/* fcron.conf parameters */
-char *fcronconf = NULL;
-char *fcrontabs = NULL;
-char *pidfile = NULL;
-char *fifofile = NULL;
-char *fcronallow = NULL;
-char *fcrondeny = NULL;
-char *shell = NULL;
-char *sendmail = NULL;
-char *editor = NULL;
-
-
uid_t
get_user_uid_safe(char *username)
/* get the uid of user username, and die on error */
return (ptr - *str);
}
-void
-init_conf(void)
-/* initialises config with compiled in constants */
-{
- /* set fcronconf if cmd line option -c has not been used */
- if (fcronconf == NULL)
- fcronconf = strdup2(ETC "/" FCRON_CONF);
- fcrontabs = strdup2(FCRONTABS);
- pidfile = strdup2(PIDFILE);
- fifofile = strdup2(FIFOFILE);
- fcronallow = strdup2(ETC "/" FCRON_ALLOW);
- fcrondeny = strdup2(ETC "/" FCRON_DENY);
- /* // */
- /* shell = strdup2(FCRON_SHELL); */
- shell = strdup2("");
-
-#ifdef SENDMAIL
- sendmail = strdup2(SENDMAIL);
-#endif
- editor = strdup2(FCRON_EDITOR);
-}
-
-void
-free_conf(void)
-/* free() the memory allocated in init_conf() */
-{
- free_safe(fcronconf);
- free_safe(fcrontabs);
- free_safe(pidfile);
- free_safe(fifofile);
- free_safe(fcronallow);
- free_safe(fcrondeny);
- free_safe(shell);
- free_safe(sendmail);
- free_safe(editor);
-}
-
-
-
-void
-read_conf(void)
-/* reads in a config file and updates the necessary global variables */
-{
- FILE *f = NULL;
- struct stat st;
- char buf[LINE_LEN];
- char *ptr1 = NULL, *ptr2 = NULL;
- short namesize = 0;
- char err_on_enoent = 0;
- struct group *gr = NULL;
- gid_t fcrongid = -1;
-
- if (fcronconf != NULL)
- /* fcronconf has been set by -c option : file must exist */
- err_on_enoent = 1;
-
- init_conf();
-
- if ( (f = fopen(fcronconf, "r")) == NULL ) {
- if ( errno == ENOENT ) {
- if ( err_on_enoent )
- die_e("Could not read %s", fcronconf);
- else
- /* file does not exist, it is not an error */
- return;
- }
- else {
- error_e("Could not read %s : config file ignored", fcronconf);
- return;
- }
- }
-
- /* get fcrongid */
- gr = getgrnam(GROUPNAME);
- if ( gr == NULL ) {
- die_e("Unable to find %s in /etc/group", GROUPNAME);
- }
- fcrongid = gr->gr_gid;
-
- /* check if the file is secure : owner:root, group:fcron,
- * writable only by owner */
- if ( fstat(fileno(f), &st) != 0
- || st.st_uid != rootuid || st.st_gid != fcrongid
- || st.st_mode & S_IWGRP || st.st_mode & S_IWOTH ) {
- error("Conf file (%s) must be owned by root:" GROUPNAME
- " and (no more than) 644 : ignored", fcronconf, GROUPNAME);
- fclose(f);
- return;
- }
-
- while ( (ptr1 = fgets(buf, sizeof(buf), f)) != NULL ) {
-
- Skip_blanks(ptr1); /* at the beginning of the line */
-
- /* ignore comments and blank lines */
- if ( *ptr1 == '#' || *ptr1 == '\n' || *ptr1 == '\0')
- continue;
-
- remove_blanks(ptr1); /* at the end of the line */
-
- /* get the name of the var */
- if ( ( namesize = get_word(&ptr1) ) == 0 )
- /* name is zero-length */
- error("Zero-length var name at line %s : line ignored", buf);
-
- ptr2 = ptr1 + namesize;
-
- /* skip the blanks and the "=" and go to the value */
- while ( isspace( (int) *ptr2 ) ) ptr2++;
- if ( *ptr2 == '=' ) ptr2++;
- while ( isspace( (int) *ptr2 ) ) ptr2++;
-
- /* find which var the line refers to and update it */
- if ( strncmp(ptr1, "fcrontabs", namesize) == 0 ) { Set(fcrontabs, ptr2); }
- else if ( strncmp(ptr1, "pidfile", namesize) == 0 ) { Set(pidfile, ptr2); }
- else if ( strncmp(ptr1, "fifofile", namesize) == 0 ) { Set(fifofile , ptr2); }
- else if ( strncmp(ptr1, "fcronallow", namesize) == 0 ) { Set(fcronallow , ptr2); }
- else if ( strncmp(ptr1, "fcrondeny", namesize) == 0 ) { Set(fcrondeny , ptr2); }
- else if ( strncmp(ptr1, "shell", namesize) == 0 ) { Set(shell , ptr2); }
- else if ( strncmp(ptr1, "sendmail", namesize) == 0 ) { Set(sendmail , ptr2); }
- else if ( strncmp(ptr1, "editor", namesize) == 0 ) { Set(editor , ptr2); }
- else
- error("Unknown var name at line %s : line ignored", buf);
-
- }
-
- if (debug_opt) {
- debug(" fcronconf=%s", fcronconf);
-/* debug(" fcronallow=%s", fcronallow); */
-/* debug(" fcrondeny=%s", fcrondeny); */
-/* debug(" fcrontabs=%s", fcrontabs); */
-/* debug(" pidfile=%s", pidfile); */
-/* debug(" fifofile=%s", fifofile); */
-/* debug(" editor=%s", editor); */
-/* debug(" shell=%s", shell); */
-/* debug(" sendmail=%s", sendmail); */
- }
-
- fclose(f);
-
-}
-
void
my_unsetenv(const char *name)
/* call unsetenv() if available, otherwise call putenv("var=").
#define __SUBS_H__
-/* global variables */
-
-/* fcron.conf parameters */
-extern char *fcronconf;
-extern char *fcronallow;
-extern char *fcrondeny;
-extern char *fcrontabs;
-extern char *pidfile;
-extern char *fifofile;
-extern char *editor;
-extern char *shell;
-extern char *sendmail;
-/* end of global variables */
-
/* functions prototypes */
extern uid_t get_user_uid_safe(char *username);
extern gid_t get_group_gid_safe(char *groupname);
extern void *realloc_safe(void *ptr, size_t len, const char * desc);
extern void free_safe(void *ptr);
extern int get_word(char **str);
-extern int temp_file(char **name);
-extern void read_conf(void);
-extern void free_conf(void);
extern void my_unsetenv(const char *name);
extern void my_setenv_overwrite(const char *name, const char *value);