]> granicus.if.org Git - fcron/commitdiff
Moved fcron.conf code from sub.{c,h} to fcronconf.{c,h}
authorThibault Godouet <thib@wind.(none)>
Sat, 16 Jan 2010 10:33:33 +0000 (10:33 +0000)
committerThibault Godouet <thib@wind.(none)>
Sat, 16 Jan 2010 10:33:33 +0000 (10:33 +0000)
13 files changed:
Makefile.in
doc/en/todo.sgml
fcron.c
fcron.h
fcronconf.c [new file with mode: 0644]
fcronconf.h [new file with mode: 0644]
fcrondyn.h
fcronsighup.c
fcrontab.h
job.c
socket.c
subs.c
subs.h

index fea8fc61066ba89f3fb9589ee8644266f32bb413..7f062ef11f320975c4293af96499ec7fcaafdb38 100644 (file)
@@ -73,11 +73,11 @@ CFLAGS += $(OPTIM) $(OPTION) $(DEFS) $(CPPFLAGS)
 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 :
index 443ba0eb614a9e4382802bc77b61c64347218d25..216a93e53e985228f089f39c16a5035242374da3 100644 (file)
@@ -24,14 +24,11 @@ A copy of the license is included in gfdl.sgml.
       <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>
diff --git a/fcron.c b/fcron.c
index df8148e65a1c2823c038078afa5ed5b4c59e6551..f3d195e642a0419f8375e39a020a781651ff2a64 100644 (file)
--- a/fcron.c
+++ b/fcron.c
@@ -29,6 +29,7 @@
 #include "conf.h"
 #include "job.h"
 #include "temp_file.h"
+#include "fcronconf.h"
 #ifdef FCRONDYN
 #include "socket.h"
 #endif
diff --git a/fcron.h b/fcron.h
index 04a8c6696c3cee521ec6d7b2784e1d2127d682e6..b3e491e4b496193d45ed26ae2efea039f3dc231b 100644 (file)
--- a/fcron.h
+++ b/fcron.h
@@ -29,6 +29,7 @@
 #include "global.h"
 #include "exe_list.h"
 #include "lavg_list.h"
+#include "fcronconf.h"
 
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
diff --git a/fcronconf.c b/fcronconf.c
new file mode 100644 (file)
index 0000000..f043f64
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * 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);
+
+}
+
+
diff --git a/fcronconf.h b/fcronconf.h
new file mode 100644 (file)
index 0000000..ede75af
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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__ */
index 51c4bf71ae176d9862f9157b542873d60fb6cce9..be2bd1d629bac81b89fdfc73066aedccf47894cf 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "global.h"
 #include "dyncom.h"
+#include "fcronconf.h"
 
 /* global variables */
 extern char dosyslog;
index 016627ea3e511e2420d5f1cbe9c57c69cdcabc39..f198999b9599cde481d160c56d2664292671c3d7 100644 (file)
@@ -26,6 +26,7 @@
 #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 $";
 
index c5b0bc926401a5d26774a558ecf6079b37d48334..9e752f132807d6ec1e4e1f86d8a61013233103aa 100644 (file)
@@ -27,6 +27,7 @@
 #define __FCRONTAB_H__
 
 #include "global.h"
+#include "fcronconf.h"
 
 /* global variables */
 extern pid_t daemon_pid;
diff --git a/job.c b/job.c
index 9e784133664c59f46deb599836ea6eeb3ede7695..488d53c289fa5e2e7d7d0be6f6b3902c12492e2a 100644 (file)
--- a/job.c
+++ b/job.c
@@ -26,6 +26,7 @@
 #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);
index 3df074284fb18616642e35eae1145cdde408432a..efb8a6f19fd8968f272dd68395f117e4f8b83816 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -30,6 +30,7 @@
 #include "socket.h"
 #include "getloadavg.h"
 #include "database.h"
+#include "fcronconf.h"
 
 
 void remove_connection(struct fcrondyn_cl **client, struct fcrondyn_cl *prev_client);
diff --git a/subs.c b/subs.c
index f7a0eb83004e4e02c1f2bcf59f5563dfafea1f38..fdb19cf9a5f935b19ded079f3227998a8b1afd4a 100644 (file)
--- a/subs.c
+++ b/subs.c
 #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 */
@@ -194,148 +176,6 @@ get_word(char **str)
     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=").
diff --git a/subs.h b/subs.h
index 6a7c420df235c1d513913ea6f34fefa3313c9994..b41405ac3db41cd6c79307a85f96222c2954e3af 100644 (file)
--- a/subs.h
+++ b/subs.h
 #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);
@@ -51,9 +37,6 @@ extern void *alloc_safe(size_t len, const char * desc);
 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);