]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/stored_conf.c
Backport from BEE
[bacula/bacula] / bacula / src / stored / stored_conf.c
index d40e212e0c59f8dfc44786152f6c6e118497fdfd..dce408b9b630396656e805f6a929d66791d02e98 100644 (file)
@@ -1,52 +1,34 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 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 and included
-   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.
+   Copyright (C) 2000-2014 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.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   Bacula® is a registered trademark of Kern Sibbald.
 */
 /*
  * Configuration file parser for Bacula Storage daemon
  *
  *     Kern Sibbald, March MM
- *
- *   Version $Id$
  */
 
 #include "bacula.h"
 #include "stored.h"
 
 /* First and last resource ids */
-int r_first = R_FIRST;
-int r_last  = R_LAST;
+int32_t r_first = R_FIRST;
+int32_t r_last  = R_LAST;
 static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 
-/* Forward referenced subroutines */
-static void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass);
-
-
 /* We build the current resource here statically,
  * then move it to dynamic memory */
 #if defined(_MSC_VER)
@@ -56,7 +38,7 @@ extern "C" { // work around visual compiler mangling variables
 #else
 URES res_all;
 #endif
-int res_all_size = sizeof(res_all);
+int32_t res_all_size = sizeof(res_all);
 
 /* Definition of records permitted within each
  * resource with the routine to process the record
@@ -74,12 +56,14 @@ static RES_ITEM store_items[] = {
    {"workingdirectory",      store_dir,  ITEM(res_store.working_directory), 0, ITEM_REQUIRED, 0},
    {"piddirectory",          store_dir,  ITEM(res_store.pid_directory), 0, ITEM_REQUIRED, 0},
    {"subsysdirectory",       store_dir,  ITEM(res_store.subsys_directory), 0, 0, 0},
+   {"plugindirectory",       store_dir,  ITEM(res_store.plugin_directory), 0, 0, 0},
    {"scriptsdirectory",      store_dir,  ITEM(res_store.scripts_directory), 0, 0, 0},
-   {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 10},
+   {"maximumconcurrentjobs", store_pint32, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 20},
    {"heartbeatinterval",     store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0},
-   {"tlsenable",             store_bit,     ITEM(res_store.tls_enable), 1, 0, 0},
-   {"tlsrequire",            store_bit,     ITEM(res_store.tls_require), 1, 0, 0},
-   {"tlsverifypeer",         store_bit,     ITEM(res_store.tls_verify_peer), 1, ITEM_DEFAULT, 1},
+   {"tlsauthenticate",       store_bool,    ITEM(res_store.tls_authenticate), 0, 0, 0},
+   {"tlsenable",             store_bool,    ITEM(res_store.tls_enable), 0, 0, 0},
+   {"tlsrequire",            store_bool,    ITEM(res_store.tls_require), 0, 0, 0},
+   {"tlsverifypeer",         store_bool,    ITEM(res_store.tls_verify_peer), 1, ITEM_DEFAULT, 1},
    {"tlscacertificatefile",  store_dir,       ITEM(res_store.tls_ca_certfile), 0, 0, 0},
    {"tlscacertificatedir",   store_dir,       ITEM(res_store.tls_ca_certdir), 0, 0, 0},
    {"tlscertificate",        store_dir,       ITEM(res_store.tls_certfile), 0, 0, 0},
@@ -87,6 +71,7 @@ static RES_ITEM store_items[] = {
    {"tlsdhfile",             store_dir,       ITEM(res_store.tls_dhfile), 0, 0, 0},
    {"tlsallowedcn",          store_alist_str, ITEM(res_store.tls_allowed_cns), 0, 0, 0},
    {"clientconnectwait",     store_time,  ITEM(res_store.client_wait), 0, ITEM_DEFAULT, 30 * 60},
+   {"verid",                 store_str,       ITEM(res_store.verid), 0, 0, 0},
    {NULL, NULL, {0}, 0, 0, 0}
 };
 
@@ -96,10 +81,11 @@ static RES_ITEM dir_items[] = {
    {"name",        store_name,     ITEM(res_dir.hdr.name),   0, ITEM_REQUIRED, 0},
    {"description", store_str,      ITEM(res_dir.hdr.desc),   0, 0, 0},
    {"password",    store_password, ITEM(res_dir.password),   0, ITEM_REQUIRED, 0},
-   {"monitor",     store_bit,    ITEM(res_dir.monitor),   1, ITEM_DEFAULT, 0},
-   {"tlsenable",            store_bit,     ITEM(res_dir.tls_enable), 1, 0, 0},
-   {"tlsrequire",           store_bit,     ITEM(res_dir.tls_require), 1, 0, 0},
-   {"tlsverifypeer",        store_bit,     ITEM(res_dir.tls_verify_peer), 1, ITEM_DEFAULT, 1},
+   {"monitor",     store_bool,     ITEM(res_dir.monitor),    0, 0, 0},
+   {"tlsauthenticate",      store_bool,    ITEM(res_dir.tls_authenticate), 0, 0, 0},
+   {"tlsenable",            store_bool,    ITEM(res_dir.tls_enable), 0, 0, 0},
+   {"tlsrequire",           store_bool,    ITEM(res_dir.tls_require), 0, 0, 0},
+   {"tlsverifypeer",        store_bool,    ITEM(res_dir.tls_verify_peer), 1, ITEM_DEFAULT, 1},
    {"tlscacertificatefile", store_dir,       ITEM(res_dir.tls_ca_certfile), 0, 0, 0},
    {"tlscacertificatedir",  store_dir,       ITEM(res_dir.tls_ca_certdir), 0, 0, 0},
    {"tlscertificate",       store_dir,       ITEM(res_dir.tls_certfile), 0, 0, 0},
@@ -111,11 +97,11 @@ static RES_ITEM dir_items[] = {
 
 /* Device definition */
 static RES_ITEM dev_items[] = {
-   {"name",                  store_name,   ITEM(res_dev.hdr.name),        0, ITEM_REQUIRED, 0},
-   {"description",           store_str,    ITEM(res_dir.hdr.desc),        0, 0, 0},
-   {"mediatype",             store_strname,ITEM(res_dev.media_type),      0, ITEM_REQUIRED, 0},
-   {"devicetype",            store_devtype,ITEM(res_dev.dev_type), 0, 0, 0},
-   {"archivedevice",         store_strname,ITEM(res_dev.device_name),     0, ITEM_REQUIRED, 0},
+   {"name",                  store_name,   ITEM(res_dev.hdr.name),    0, ITEM_REQUIRED, 0},
+   {"description",           store_str,    ITEM(res_dir.hdr.desc),    0, 0, 0},
+   {"mediatype",             store_strname,ITEM(res_dev.media_type),  0, ITEM_REQUIRED, 0},
+   {"devicetype",            store_devtype,ITEM(res_dev.dev_type),    0, 0, 0},
+   {"archivedevice",         store_strname,ITEM(res_dev.device_name), 0, ITEM_REQUIRED, 0},
    {"hardwareendoffile",     store_bit,  ITEM(res_dev.cap_bits), CAP_EOF,  ITEM_DEFAULT, 1},
    {"hardwareendofmedium",   store_bit,  ITEM(res_dev.cap_bits), CAP_EOM,  ITEM_DEFAULT, 1},
    {"backwardspacerecord",   store_bit,  ITEM(res_dev.cap_bits), CAP_BSR,  ITEM_DEFAULT, 1},
@@ -137,26 +123,28 @@ static RES_ITEM dev_items[] = {
    {"checklabels",           store_bit,  ITEM(res_dev.cap_bits), CAP_CHECKLABELS, ITEM_DEFAULT, 0},
    {"requiresmount",         store_bit,  ITEM(res_dev.cap_bits), CAP_REQMOUNT, ITEM_DEFAULT, 0},
    {"offlineonunmount",      store_bit,  ITEM(res_dev.cap_bits), CAP_OFFLINEUNMOUNT, ITEM_DEFAULT, 0},
-   {"autoselect",            store_bit,  ITEM(res_dev.autoselect), 1, ITEM_DEFAULT, 1},
+   {"blockchecksum",         store_bit,  ITEM(res_dev.cap_bits), CAP_BLOCKCHECKSUM, ITEM_DEFAULT, 1},
+   {"autoselect",            store_bool, ITEM(res_dev.autoselect), 1, ITEM_DEFAULT, 1},
+   {"readonly",              store_bool, ITEM(res_dev.read_only), 1, ITEM_DEFAULT, 0},
    {"changerdevice",         store_strname,ITEM(res_dev.changer_name), 0, 0, 0},
    {"changercommand",        store_strname,ITEM(res_dev.changer_command), 0, 0, 0},
    {"alertcommand",          store_strname,ITEM(res_dev.alert_command), 0, 0, 0},
    {"maximumchangerwait",    store_time,   ITEM(res_dev.max_changer_wait), 0, ITEM_DEFAULT, 5 * 60},
    {"maximumopenwait",       store_time,   ITEM(res_dev.max_open_wait), 0, ITEM_DEFAULT, 5 * 60},
-   {"maximumopenvolumes",    store_pint,   ITEM(res_dev.max_open_vols), 0, ITEM_DEFAULT, 1},
-   {"maximumnetworkbuffersize", store_pint, ITEM(res_dev.max_network_buffer_size), 0, 0, 0},
-   {"volumepollinterval",    store_time,   ITEM(res_dev.vol_poll_interval), 0, 0, 0},
+   {"maximumnetworkbuffersize", store_pint32, ITEM(res_dev.max_network_buffer_size), 0, 0, 0},
+   {"volumepollinterval",    store_time,   ITEM(res_dev.vol_poll_interval), 0, ITEM_DEFAULT, 5 * 60},
    {"maximumrewindwait",     store_time,   ITEM(res_dev.max_rewind_wait), 0, ITEM_DEFAULT, 5 * 60},
-   {"minimumblocksize",      store_pint,   ITEM(res_dev.min_block_size), 0, 0, 0},
-   {"maximumblocksize",      store_pint,   ITEM(res_dev.max_block_size), 0, 0, 0},
-   {"maximumvolumesize",     store_size,   ITEM(res_dev.max_volume_size), 0, 0, 0},
-   {"maximumfilesize",       store_size,   ITEM(res_dev.max_file_size), 0, ITEM_DEFAULT, 1000000000},
-   {"volumecapacity",        store_size,   ITEM(res_dev.volume_capacity), 0, 0, 0},
+   {"minimumblocksize",      store_pint32,   ITEM(res_dev.min_block_size), 0, 0, 0},
+   {"maximumblocksize",      store_maxblocksize, ITEM(res_dev.max_block_size), 0, 0, 0},
+   {"maximumvolumesize",     store_size64,   ITEM(res_dev.max_volume_size), 0, 0, 0},
+   {"maximumfilesize",       store_size64,   ITEM(res_dev.max_file_size), 0, ITEM_DEFAULT, 1000000000},
+   {"volumecapacity",        store_size64,   ITEM(res_dev.volume_capacity), 0, 0, 0},
+   {"maximumconcurrentjobs", store_pint32, ITEM(res_dev.max_concurrent_jobs), 0, 0, 0},
    {"spooldirectory",        store_dir,    ITEM(res_dev.spool_directory), 0, 0, 0},
-   {"maximumspoolsize",      store_size,   ITEM(res_dev.max_spool_size), 0, 0, 0},
-   {"maximumjobspoolsize",   store_size,   ITEM(res_dev.max_job_spool_size), 0, 0, 0},
-   {"driveindex",            store_pint,   ITEM(res_dev.drive_index), 0, 0, 0},
-   {"maximumpartsize",       store_size,   ITEM(res_dev.max_part_size), 0, ITEM_DEFAULT, 0},
+   {"maximumspoolsize",      store_size64,   ITEM(res_dev.max_spool_size), 0, 0, 0},
+   {"maximumjobspoolsize",   store_size64,   ITEM(res_dev.max_job_spool_size), 0, 0, 0},
+   {"driveindex",            store_pint32,   ITEM(res_dev.drive_index), 0, 0, 0},
+   {"maximumpartsize",       store_size64,   ITEM(res_dev.max_part_size), 0, ITEM_DEFAULT, 0},
    {"mountpoint",            store_strname,ITEM(res_dev.mount_point), 0, 0, 0},
    {"mountcommand",          store_strname,ITEM(res_dev.mount_command), 0, 0, 0},
    {"unmountcommand",        store_strname,ITEM(res_dev.unmount_command), 0, 0, 0},
@@ -201,7 +189,7 @@ RES_TABLE resources[] = {
  */
 struct s_kw {
    const char *name;
-   int token;
+   int32_t token;
 };
 
 static s_kw dev_types[] = {
@@ -209,6 +197,8 @@ static s_kw dev_types[] = {
    {"tape",          B_TAPE_DEV},
    {"dvd",           B_DVD_DEV},
    {"fifo",          B_FIFO_DEV},
+   {"vtl",           B_VTL_DEV},
+   {"vtape",         B_VTAPE_DEV},
    {NULL,            0}
 };
 
@@ -217,15 +207,15 @@ static s_kw dev_types[] = {
  * Store Device Type (File, FIFO, Tape, DVD)
  *
  */
-static void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass)
+void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass)
 {
-   int token, i;
+   int i;
 
-   token = lex_get_token(lc, T_NAME);
+   lex_get_token(lc, T_NAME);
    /* Store the label pass 2 so that type is defined */
    for (i=0; dev_types[i].name; i++) {
       if (strcasecmp(lc->str, dev_types[i].name) == 0) {
-         *(int *)(item->value) = dev_types[i].token;
+         *(uint32_t *)(item->value) = dev_types[i].token;
          i = 0;
          break;
       }
@@ -237,6 +227,19 @@ static void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass)
    set_bit(index, res_all.hdr.item_present);
 }
 
+/*
+ * Store Maximum Block Size, and check it is not greater than MAX_BLOCK_LENGTH
+ *
+ */
+void store_maxblocksize(LEX *lc, RES_ITEM *item, int index, int pass)
+{
+   store_size32(lc, item, index, pass);
+   if (*(uint32_t *)(item->value) > MAX_BLOCK_LENGTH) {
+      scan_err2(lc, _("Maximum Block Size configured value %u is greater than allowed maximum: %u"),
+         *(uint32_t *)(item->value), MAX_BLOCK_LENGTH );
+   }
+}
+
 
 /* Dump contents of resource */
 void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
@@ -405,7 +408,7 @@ void free_resource(RES *sres, int type)
       if (res->res_dir.address) {
          free(res->res_dir.address);
       }
-      if (res->res_dir.tls_ctx) { 
+      if (res->res_dir.tls_ctx) {
          free_tls_context(res->res_dir.tls_ctx);
       }
       if (res->res_dir.tls_ca_certfile) {
@@ -437,7 +440,8 @@ void free_resource(RES *sres, int type)
       if (res->res_changer.device) {
          delete res->res_changer.device;
       }
-      break; 
+      rwl_destroy(&res->res_changer.changer_lock);
+      break;
    case R_STORAGE:
       if (res->res_store.sdaddrs) {
          free_addresses(res->res_store.sdaddrs);
@@ -454,10 +458,13 @@ void free_resource(RES *sres, int type)
       if (res->res_store.subsys_directory) {
          free(res->res_store.subsys_directory);
       }
+      if (res->res_store.plugin_directory) {
+         free(res->res_store.plugin_directory);
+      }
       if (res->res_store.scripts_directory) {
          free(res->res_store.scripts_directory);
       }
-      if (res->res_store.tls_ctx) { 
+      if (res->res_store.tls_ctx) {
          free_tls_context(res->res_store.tls_ctx);
       }
       if (res->res_store.tls_ca_certfile) {
@@ -478,6 +485,9 @@ void free_resource(RES *sres, int type)
       if (res->res_store.tls_allowed_cns) {
          delete res->res_store.tls_allowed_cns;
       }
+      if (res->res_store.verid) {
+         free(res->res_store.verid);
+      }
       break;
    case R_DEVICE:
       if (res->res_dev.media_type) {
@@ -539,7 +549,7 @@ void free_resource(RES *sres, int type)
 
 /* Save the new resource by chaining it into the head list for
  * the resource. If this is pass 2, we update any resource
- * or alist pointers.  
+ * or alist pointers.
  */
 void save_resource(int type, RES_ITEM *items, int pass)
 {
@@ -600,15 +610,17 @@ void save_resource(int type, RES_ITEM *items, int pass)
          /* we must explicitly copy the device alist pointer */
          res->res_changer.device   = res_all.res_changer.device;
          /*
-          * Now update each device in this resource to point back 
+          * Now update each device in this resource to point back
           *  to the changer resource.
           */
          foreach_alist(dev, res->res_changer.device) {
             dev->changer_res = (AUTOCHANGER *)&res->res_changer;
          }
-         if ((errstat = pthread_mutex_init(&res->res_changer.changer_mutex, NULL)) != 0) {
+         if ((errstat = rwl_init(&res->res_changer.changer_lock,
+                                 PRIO_SD_ACH_ACCESS)) != 0)
+         {
             berrno be;
-            Jmsg1(NULL, M_ERROR_TERM, 0, _("Unable to init mutex: ERR=%s\n"), 
+            Jmsg1(NULL, M_ERROR_TERM, 0, _("Unable to init lock: ERR=%s\n"),
                   be.bstrerror(errstat));
          }
          break;
@@ -676,3 +688,10 @@ void save_resource(int type, RES_ITEM *items, int pass)
       }
    }
 }
+
+bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code)
+{
+   config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size,
+      r_first, r_last, resources, res_head);
+   return config->parse_config();
+}