+ if (job_items[i].flags & ITEM_REQUIRED) {
+ if (!bit_is_set(i, job->hdr.item_present)) {
+ Jmsg(NULL, M_FATAL, 0, _("\"%s\" directive in Job \"%s\" resource is required, but not found.\n"),
+ job_items[i].name, job->hdr.name);
+ OK = false;
+ }
+ }
+ /* If this triggers, take a look at lib/parse_conf.h */
+ if (i >= MAX_RES_ITEMS) {
+ Emsg0(M_ERROR_TERM, 0, _("Too many items in Job resource\n"));
+ }
+ }
+ } /* End loop over Job res */
+
+ /* Loop over databases */
+ CAT *catalog;
+ foreach_res(catalog, R_CATALOG) {
+ B_DB *db;
+ /*
+ * Make sure we can open catalog, otherwise print a warning
+ * message because the server is probably not running.
+ */
+ db = db_init_database(NULL, catalog->db_name, catalog->db_user,
+ catalog->db_password, catalog->db_address,
+ catalog->db_port, catalog->db_socket,
+ catalog->mult_db_connections);
+ if (!db || !db_open_database(NULL, db)) {
+ Jmsg(NULL, M_FATAL, 0, _("Could not open Catalog \"%s\", database \"%s\".\n"),
+ catalog->hdr.name, catalog->db_name);
+ if (db) {
+ Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
+ }
+ OK = false;
+ continue;
+ }
+
+ /* Loop over all pools, defining/updating them in each database */
+ POOL *pool;
+ foreach_res(pool, R_POOL) {
+ create_pool(NULL, db, pool, POOL_OP_UPDATE); /* update request */
+ }
+
+ STORE *store;
+ foreach_res(store, R_STORAGE) {
+ STORAGE_DBR sr;
+ MEDIATYPE_DBR mr;
+ if (store->media_type) {
+ bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
+ mr.ReadOnly = 0;
+ db_create_mediatype_record(NULL, db, &mr);
+ } else {
+ mr.MediaTypeId = 0;
+ }
+ bstrncpy(sr.Name, store->name(), sizeof(sr.Name));
+ sr.AutoChanger = store->autochanger;
+ db_create_storage_record(NULL, db, &sr);
+ store->StorageId = sr.StorageId; /* set storage Id */
+ if (!sr.created) { /* if not created, update it */
+ db_update_storage_record(NULL, db, &sr);
+ }
+
+ /* tls_require implies tls_enable */
+ if (store->tls_require) {
+ if (have_tls) {
+ store->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ OK = false;
+ }
+ }
+
+ if ((!store->tls_ca_certfile && !store->tls_ca_certdir) && store->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
+ " or \"TLS CA Certificate Dir\" are defined for Storage \"%s\" in %s.\n"),
+ store->hdr.name, configfile);
+ OK = false;
+ }
+
+ /* If everything is well, attempt to initialize our per-resource TLS context */
+ if (OK && (store->tls_enable || store->tls_require)) {
+ /* Initialize TLS context:
+ * Args: CA certfile, CA certdir, Certfile, Keyfile,
+ * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
+ store->tls_ctx = new_tls_context(store->tls_ca_certfile,
+ store->tls_ca_certdir, store->tls_certfile,
+ store->tls_keyfile, NULL, NULL, NULL, true);
+
+ if (!store->tls_ctx) {
+ Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for Storage \"%s\" in %s.\n"),
+ store->hdr.name, configfile);
+ OK = false;
+ }
+ }
+ }
+
+ /* Loop over all counters, defining them in each database */
+ /* Set default value in all counters */
+ COUNTER *counter;
+ foreach_res(counter, R_COUNTER) {
+ /* Write to catalog? */
+ if (!counter->created && counter->Catalog == catalog) {
+ COUNTER_DBR cr;
+ bstrncpy(cr.Counter, counter->hdr.name, sizeof(cr.Counter));
+ cr.MinValue = counter->MinValue;
+ cr.MaxValue = counter->MaxValue;
+ cr.CurrentValue = counter->MinValue;
+ if (counter->WrapCounter) {
+ bstrncpy(cr.WrapCounter, counter->WrapCounter->hdr.name, sizeof(cr.WrapCounter));
+ } else {
+ cr.WrapCounter[0] = 0; /* empty string */
+ }
+ if (db_create_counter_record(NULL, db, &cr)) {
+ counter->CurrentValue = cr.CurrentValue;
+ counter->created = true;
+ Dmsg2(100, "Create counter %s val=%d\n", counter->hdr.name, counter->CurrentValue);
+ }
+ }
+ if (!counter->created) {
+ counter->CurrentValue = counter->MinValue; /* default value */
+ }