From e360fa32e0512ef4c2df418ef8a1ee65d1488074 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 23 Jan 2008 19:56:10 +0000 Subject: [PATCH] kes Move initialization of read/write res lock earlier in the code. This fixes the crash with a null conf file. This fixes bug #1030. kes Redefine CURES in lib/parse_conf to be URES and move it all into lib/parse_conf.c -- this responds to bug #1042, but does not fix it. The fix is not to compile with FORTIFY_SOURCE. kes Backport to 2.2.8 fix de-referencing a NULL pointer in the scanner from the trunk SVN. I don't think this was reported as a bug. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6302 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/fd-plugins.h | 140 ++++++++++++++++++++++++++++++++++ bacula/src/filed/filed_conf.c | 2 +- bacula/src/lib/parse_conf.c | 35 +++++---- bacula/src/lib/parse_conf.h | 12 +-- bacula/technotes-2.3 | 9 +++ 5 files changed, 173 insertions(+), 25 deletions(-) create mode 100644 bacula/src/filed/fd-plugins.h diff --git a/bacula/src/filed/fd-plugins.h b/bacula/src/filed/fd-plugins.h new file mode 100644 index 0000000000..80aea4ab78 --- /dev/null +++ b/bacula/src/filed/fd-plugins.h @@ -0,0 +1,140 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2008 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. + 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, which is + 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. +*/ +/* + * Interface definition for Bacula Plugins + * + * Kern Sibbald, October 2007 + * + */ + +#ifndef __PLUGIN_FD_H +#define __PLUGIN_FD_H + +#include +#ifndef __CONFIG_H +#define __CONFIG_H +#include "config.h" +#endif +#include "bc_types.h" +#include "lib/plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/**************************************************************************** + * * + * Bacula definitions * + * * + ****************************************************************************/ + +/* Bacula Variable Ids */ +typedef enum { + bVarJobId = 1, + bVarFDName = 2, + bVarLevel = 3, + bVarType = 4, + bVarClient = 5, + bVarJobName = 6, + bVarJobStatus = 7, + bVarSinceTime = 8 +} bVariable; + +typedef enum { + bEventJobStart = 1, + bEventJobEnd = 2, +} bEventType; + +typedef struct s_bEvent { + uint32_t eventType; +} bEvent; + +typedef struct s_baculaInfo { + uint32_t size; + uint32_t interface; +} bInfo; + +/* Bacula interface version and function pointers */ +typedef struct s_baculaFuncs { + uint32_t size; + uint32_t interface; + bpError (*registerBaculaEvents)(bpContext *ctx, ...); + bpError (*getBaculaValue)(bpContext *ctx, bVariable var, void *value); + bpError (*setBaculaValue)(bpContext *ctx, bVariable var, void *value); + bpError (*JobMessage)(bpContext *ctx, const char *file, int line, + int type, time_t mtime, const char *msg); + bpError (*DebugMessage)(bpContext *ctx, const char *file, int line, + int level, const char *msg); +} bFuncs; + + +/**************************************************************************** + * * + * Plugin definitions * + * * + ****************************************************************************/ + +typedef enum { + pVarName = 1, + pVarDescription = 2 +} pVariable; + + +#define PLUGIN_MAGIC "*PluginData*" +#define PLUGIN_INTERFACE 1 + +typedef struct s_pluginInfo { + uint32_t size; + uint32_t interface; + char *plugin_magic; + char *plugin_license; + char *plugin_author; + char *plugin_date; + char *plugin_version; + char *plugin_description; +} pInfo; + +typedef struct s_pluginFuncs { + uint32_t size; + uint32_t interface; + bpError (*newPlugin)(bpContext *ctx); + bpError (*freePlugin)(bpContext *ctx); + bpError (*getPluginValue)(bpContext *ctx, pVariable var, void *value); + bpError (*setPluginValue)(bpContext *ctx, pVariable var, void *value); + bpError (*handlePluginEvent)(bpContext *ctx, bEvent *event); +} pFuncs; + +#define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) +#define plug_info(plugin) ((pInfo *)(plugin->pinfo)) + +#ifdef __cplusplus +} +#endif + +#endif /* __PLUGIN_FD_H */ diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index ac4f92726e..9721c3a48d 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 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 ac7536b173..c581c422c3 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-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 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. @@ -78,12 +78,20 @@ extern int r_last; extern RES_TABLE resources[]; extern RES **res_head; +/* + * Define the Union of all the common resource structure definitions. + */ +union URES { + MSGS res_msgs; + RES hdr; +}; + #if defined(_MSC_VER) // 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; +extern "C" URES res_all; #else -extern CURES res_all; +extern URES res_all; #endif extern int res_all_size; @@ -188,19 +196,10 @@ const char *res_to_str(int rcode) * Initialize the static structure to zeros, then * apply all the default values. */ -void init_resource(int type, RES_ITEM *items, int pass) +static void init_resource(int type, RES_ITEM *items, int pass) { int i; int rindex = type - r_first; - static bool first = true; - int errstat; - - if (first && (errstat=rwl_init(&res_lock)) != 0) { - berrno be; - Emsg1(M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"), - be.bstrerror(errstat)); - } - first = false; memset(&res_all, 0, res_all_size); res_all.hdr.rcode = type; @@ -293,6 +292,7 @@ void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass) free_pool_memory(dest); Dmsg0(900, "done with dest codes\n"); break; + case MD_FILE: /* file */ case MD_APPEND: /* append */ dest = get_pool_memory(PM_MESSAGE); @@ -790,6 +790,15 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) enum parse_state state = p_none; RES_ITEM *items = NULL; int level = 0; + static bool first = true; + int errstat; + + if (first && (errstat=rwl_init(&res_lock)) != 0) { + berrno be; + Emsg1(M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"), + be.bstrerror(errstat)); + } + first = false; char *full_path = (char *)alloca(MAX_PATH + 1); diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 470ac52818..3e630b55fc 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 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. @@ -116,16 +116,6 @@ public: inline char *MSGS::name() const { return hdr.name; } - -/* Define the Union of all the above common - * resource structure definitions. - */ -union CURES { - MSGS res_msgs; - RES hdr; -}; - - /* Configuration routines */ int parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM); void free_config_resources(void); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 22e87e8e21..8f68eccbc8 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,15 @@ Technical notes on version 2.3 General: +23Jan08 +kes Move initialization of read/write res lock earlier in the code. + This fixes the crash with a null conf file. This fixes bug + #1030. +kes Redefine CURES in lib/parse_conf to be URES and move it all + into lib/parse_conf.c -- this responds to bug #1042, but does + not fix it. The fix is not to compile with FORTIFY_SOURCE. +kes Backport to 2.2.8 fix de-referencing a NULL pointer in the scanner from + the trunk SVN. I don't think this was reported as a bug. 17Jan08 ebl Fix a bug during tape initialization with MTSETDRVBUFFER. 12Jan08 -- 2.39.5