From bf6fb1017039af22e4a5c6d661c52bcf543b9ae4 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 24 Jan 2009 17:56:41 +0000 Subject: [PATCH] Modify search for .conf file so that if one is given on the command line, it will be used, otherwise it will use the SYSCONF directory. It will no longer look in the current directory unless explicitly requested on the command line. This fixes bug #1189. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8400 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird.c | 2 +- bacula/src/dird/dird_conf.c | 2 +- bacula/src/lib/parse_conf.c | 34 ++++++++++++++++++++-------------- bacula/technotes-2.5 | 5 +++++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index b8b065f621..48fe7487f0 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-2009 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 6595c7d2e8..077ff4c707 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-2009 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index f85798d8fc..8bf7b18a8f 100644 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-2009 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -846,16 +846,17 @@ bool CONFIG::parse_config() if (first && (errstat=rwl_init(&res_lock)) != 0) { berrno be; - Emsg1(M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"), + Jmsg1(NULL, M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"), be.bstrerror(errstat)); } first = false; char *full_path = (char *)alloca(MAX_PATH + 1); - if (find_config_file(cf, full_path, MAX_PATH +1)) { - cf = full_path; + if (!find_config_file(cf, full_path, MAX_PATH +1)) { + Jmsg0(NULL, M_ABORT, 0, _("Config filename too long.\n")); } + cf = full_path; /* Make two passes. The first builds the name symbol table, * and the second picks up the items. @@ -1022,24 +1023,29 @@ const char *get_default_configdir() #endif } +/* + * Returns false on error + * true on OK, with full_path set to where config file should be + */ static bool find_config_file(const char *config_file, char *full_path, int max_path) { - if (first_path_separator(config_file) != NULL) { - return false; - } + int file_length = strlen(config_file) + 1; - struct stat st; - - if (stat(config_file, &st) == 0) { - return false; + /* If a full path specified, use it */ + if (first_path_separator(config_file) != NULL) { + if (file_length > max_path) { + return false; + } + bstrncpy(full_path, config_file, file_length); + return true; } + /* config_file is default file name, now find default dir */ const char *config_dir = get_default_configdir(); int dir_length = strlen(config_dir); - int file_length = strlen(config_file); - if ((dir_length + 1 + file_length + 1) > max_path) { + if ((dir_length + 1 + file_length) > max_path) { return false; } @@ -1049,7 +1055,7 @@ find_config_file(const char *config_file, char *full_path, int max_path) full_path[dir_length++] = '/'; } - memcpy(&full_path[dir_length], config_file, file_length + 1); + memcpy(&full_path[dir_length], config_file, file_length); return true; } diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index e525fe41da..3ecd8e50fd 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -11,6 +11,11 @@ mixed priorities General: 24Jan09 +kes Modify search for .conf file so that if one is given on + the command line, it will be used, otherwise it will use + the SYSCONF directory. It will no longer look in the current + directory unless explicitly requested on the command line. + This fixes bug #1189. kes Fail a job that references a plugin if no Plugin Directory is defined. 22Jan09 -- 2.39.5