]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
Use access to ensure readability of config gile
authorEric Leblond <eric@regit.org>
Sat, 9 Feb 2013 19:49:56 +0000 (20:49 +0100)
committerEric Leblond <eric@regit.org>
Mon, 18 Feb 2013 08:30:49 +0000 (09:30 +0100)
This patch adds a call to access to check the readability of the
configuration file.

src/conffile.c
src/ulogd.c

index dd0ed8f73abff9297ea40edf191355344a313324..616d7a946e164e5e71930c9c9ae8b04a11f144f5 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
 #include <ulogd/ulogd.h>
 #include <ulogd/common.h>
 #include <ulogd/conffile.h>
+#include <unistd.h>
 
 
 /* points to config entry with error */
@@ -89,10 +91,17 @@ static char *get_word(char *line, char *not, char *buf)
 /* register config file with us */
 int config_register_file(const char *file)
 {
-       /* FIXME: stat of file */
        if (fname)
                return 1;
 
+       if (access(file, R_OK) != 0) {
+               ulogd_log(ULOGD_ERROR,
+                        "unable to read configfile \"%s\": %s\n",
+                        file,
+                        strerror(errno));
+               return 1;
+       }
+
        pr_debug("%s: registered config file '%s'\n", __func__, file);
 
        fname = (char *) malloc(strlen(file)+1);
index c7617d9a15847f30f0d8ac6e6f923850067900cc..f8c8ed0fcf046ee5f6547b70f8a2ba1f545bc4d1 100644 (file)
@@ -1216,7 +1216,7 @@ int main(int argc, char* argv[])
 
        /* parse config file */
        if (parse_conffile("global", &ulogd_kset)) {
-               ulogd_log(ULOGD_FATAL, "parse_conffile\n");
+               ulogd_log(ULOGD_FATAL, "unable to parse config file\n");
                warn_and_exit(daemonize);
        }