X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fparse_conf.c;h=1e432a640efe04f3d3e880b109b7ee73cc5f9648;hb=6872bd694d98711846adaae124f19dfc88d8f2e0;hp=d5a0ceafdaf23a1176312376a7600da13ca2f07f;hpb=bcaf435f5b1811182b4092d7316ef305766c890f;p=bacula%2Fbacula diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index d5a0ceafda..1e432a640e 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -33,23 +33,42 @@ * Version $Id$ */ /* - Copyright (C) 2000-2006 Kern Sibbald + Bacula® - The Network Backup Solution - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as amended with additional clauses defined in the - file LICENSE in the main source directory. + Copyright (C) 2000-2006 Free Software Foundation Europe e.V. - 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 - the file LICENSE for additional details. + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed in the file LICENSE. - */ + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ #include "bacula.h" +#if defined(HAVE_WIN32) +#include "shlobj.h" +#else +#define MAX_PATH 1024 +#endif + /* Each daemon has a slightly different set of * resources, so it will define the following * global values. @@ -60,7 +79,7 @@ extern RES_TABLE resources[]; extern RES **res_head; #if defined(_MSC_VER) -// work around visual studio name manling preventing external linkage since res_all +// work around visual studio name mangling preventing external linkage since res_all // is declared as a different type when instantiated. extern "C" CURES res_all; #else @@ -73,7 +92,8 @@ extern brwlock_t res_lock; /* resource lock */ /* Forward referenced subroutines */ static void scan_types(LEX *lc, MSGS *msg, int dest, char *where, char *cmd); - +static const char *get_default_configdir(); +static bool find_config_file(const char *config_file, char *full_path); /* Common Resource definitions */ @@ -88,6 +108,7 @@ RES_ITEM msgs_items[] = { {"syslog", store_msgs, ITEM(res_msgs), MD_SYSLOG, 0, 0}, {"mail", store_msgs, ITEM(res_msgs), MD_MAIL, 0, 0}, {"mailonerror", store_msgs, ITEM(res_msgs), MD_MAIL_ON_ERROR, 0, 0}, + {"mailonsuccess", store_msgs, ITEM(res_msgs), MD_MAIL_ON_SUCCESS, 0, 0}, {"file", store_msgs, ITEM(res_msgs), MD_FILE, 0, 0}, {"append", store_msgs, ITEM(res_msgs), MD_APPEND, 0, 0}, {"stdout", store_msgs, ITEM(res_msgs), MD_STDOUT, 0, 0}, @@ -193,7 +214,7 @@ void init_resource(int type, RES_ITEM *items, int pass) if (items[i].handler == store_bit) { *(int *)(items[i].value) |= items[i].code; } else if (items[i].handler == store_bool) { - *(bool *)(items[i].value) = items[i].default_value; + *(bool *)(items[i].value) = items[i].default_value != 0; } else if (items[i].handler == store_pint || items[i].handler == store_int) { *(int *)(items[i].value) = items[i].default_value; @@ -237,6 +258,7 @@ void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass) case MD_DIRECTOR: /* send to Director */ case MD_MAIL: /* mail */ case MD_MAIL_ON_ERROR: /* mail if Job errors */ + case MD_MAIL_ON_SUCCESS: /* mail if Job succeeds */ if (item->code == MD_OPERATOR) { cmd = res_all.res_msgs.operator_cmd; } else { @@ -768,6 +790,12 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) RES_ITEM *items = NULL; int level = 0; + char *full_path = (char *)alloca(MAX_PATH); + + if (find_config_file(cf, full_path)) { + cf = full_path; + } + /* Make two passes. The first builds the name symbol table, * and the second picks up the items. */ @@ -800,6 +828,9 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) if (token == T_EOL) { break; } + if (token == T_UNICODE_MARK) { + break; + } if (token != T_IDENTIFIER) { scan_err1(lc, _("Expected a Resource name identifier, got: %s"), lc->str); return 0; @@ -814,7 +845,7 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) } if (state == p_none) { scan_err1(lc, _("expected resource name, got: %s"), lc->str); - return 0; + return 0; } break; case p_resource: @@ -895,6 +926,64 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) return 1; } +const char *get_default_configdir() +{ +#if defined(HAVE_WIN32) + HRESULT hr; + static char szConfigDir[MAX_PATH + 1] = { 0 }; + + if (!p_SHGetFolderPath) { + bstrncpy(szConfigDir, DEFAULT_CONFIGDIR, sizeof(szConfigDir)); + return szConfigDir; + } + + if (szConfigDir[0] == '\0') { + hr = p_SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szConfigDir); + + if (SUCCEEDED(hr)) { + bstrncat(szConfigDir, "\\Bacula", sizeof(szConfigDir)); + } else { + bstrncpy(szConfigDir, DEFAULT_CONFIGDIR, sizeof(szConfigDir)); + } + } + return szConfigDir; +#else + return SYSCONFDIR; +#endif +} + +bool +find_config_file(const char *config_file, char *full_path) +{ + if (first_path_separator(config_file) != NULL) { + return false; + } + + struct stat st; + + if (stat(config_file, &st) == 0) { + return false; + } + + const char *config_dir = get_default_configdir(); + size_t dir_length = strlen(config_dir); + size_t file_length = strlen(config_file); + + if ((dir_length + 1 + file_length + 1) > MAX_PATH) { + return false; + } + + memcpy(full_path, config_dir, dir_length + 1); + + if (!IsPathSeparator(full_path[dir_length - 1])) { + full_path[dir_length++] = '/'; + } + + memcpy(&full_path[dir_length], config_file, file_length + 1); + + return true; +} + /********************************************************************* * * Free configuration resources