-/*
- *
- * Bacula Director daemon -- this is the main program
- *
- * Kern Sibbald, March MM
- *
- * Version $Id$
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ 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.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ *
+ * Bacula Director daemon -- this is the main program
+ *
+ * Kern Sibbald, March MM
+ *
+ * Version $Id$
+ */
#include "bacula.h"
#include "dird.h"
/* Forward referenced subroutines */
void terminate_dird(int sig);
-static int check_resources();
+static bool check_resources();
+static bool check_catalog();
static void dir_sql_query(JCR *jcr, const char *cmd);
/* Exported subroutines */
*
*/
#if defined(HAVE_WIN32)
+/* For Win32 main() is in src/win32 code ... */
#define main BaculaMain
#endif
Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
}
+ drop(uid, gid); /* reduce privileges if requested */
+
+ if (!check_catalog()) {
+ Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
+ }
+
if (test_config) {
terminate_dird(0);
}
create_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
read_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
- drop(uid, gid); /* reduce priveleges if requested */
#if !defined(HAVE_WIN32)
signal(SIGHUP, reload_config);
* **** FIXME **** this routine could be a lot more
* intelligent and comprehensive.
*/
-static int check_resources()
+static bool check_resources()
{
bool OK = true;
JOB *job;
}
} /* End loop over Job res */
+
+ /* Loop over Consoles */
+ CONRES *cons;
+ foreach_res(cons, R_CONSOLE) {
+ /* tls_require implies tls_enable */
+ if (cons->tls_require) {
+ if (have_tls) {
+ cons->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ OK = false;
+ continue;
+ }
+ }
+
+ if (!cons->tls_certfile && cons->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Console \"%s\" in %s.\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+
+ if (!cons->tls_keyfile && cons->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Console \"%s\" in %s.\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+
+ if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable && cons->tls_verify_peer) {
+ Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\" or \"TLS CA"
+ " Certificate Dir\" are defined for Console \"%s\" in %s."
+ " At least one CA certificate store is required"
+ " when using \"TLS Verify Peer\".\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+ /* If everything is well, attempt to initialize our per-resource TLS context */
+ if (OK && (cons->tls_enable || cons->tls_require)) {
+ /* Initialize TLS context:
+ * Args: CA certfile, CA certdir, Certfile, Keyfile,
+ * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
+ cons->tls_ctx = new_tls_context(cons->tls_ca_certfile,
+ cons->tls_ca_certdir, cons->tls_certfile,
+ cons->tls_keyfile, NULL, NULL, cons->tls_dhfile, cons->tls_verify_peer);
+
+ if (!cons->tls_ctx) {
+ Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+ }
+
+ }
+
+ /* Loop over Clients */
+ CLIENT *client;
+ foreach_res(client, R_CLIENT) {
+ /* tls_require implies tls_enable */
+ if (client->tls_require) {
+ if (have_tls) {
+ client->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ OK = false;
+ continue;
+ }
+ }
+
+ if ((!client->tls_ca_certfile && !client->tls_ca_certdir) && client->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
+ " or \"TLS CA Certificate Dir\" are defined for File daemon \"%s\" in %s.\n"),
+ client->name(), configfile);
+ OK = false;
+ }
+
+ /* If everything is well, attempt to initialize our per-resource TLS context */
+ if (OK && (client->tls_enable || client->tls_require)) {
+ /* Initialize TLS context:
+ * Args: CA certfile, CA certdir, Certfile, Keyfile,
+ * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
+ client->tls_ctx = new_tls_context(client->tls_ca_certfile,
+ client->tls_ca_certdir, client->tls_certfile,
+ client->tls_keyfile, NULL, NULL, NULL,
+ true);
+
+ if (!client->tls_ctx) {
+ Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
+ client->name(), configfile);
+ OK = false;
+ }
+ }
+ }
+
+ UnlockRes();
+ if (OK) {
+ close_msg(NULL); /* close temp message handler */
+ init_msg(NULL, director->messages); /* open daemon message handler */
+ }
+ return OK;
+}
+
+static bool check_catalog()
+{
+ bool OK = true;
+
/* Loop over databases */
CAT *catalog;
foreach_res(catalog, R_CATALOG) {
catalog->db_port, catalog->db_socket,
catalog->mult_db_connections);
if (!db || !db_open_database(NULL, db)) {
+ Pmsg2(000, _("Could not open Catalog \"%s\", database \"%s\".\n"),
+ catalog->name(), catalog->db_name);
Jmsg(NULL, M_FATAL, 0, _("Could not open Catalog \"%s\", database \"%s\".\n"),
catalog->name(), catalog->db_name);
if (db) {
Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
+ Pmsg1(000, "%s", db_strerror(db));
}
OK = false;
continue;
create_pool(NULL, db, pool, POOL_OP_UPDATE); /* update request */
}
+ /* Loop over all pools for updating RecyclePool */
+ foreach_res(pool, R_POOL) {
+ update_pool_recyclepool(NULL, db, pool);
+ }
+
STORE *store;
foreach_res(store, R_STORAGE) {
STORAGE_DBR sr;
}
db_close_database(NULL, db);
}
-
- /* Loop over Consoles */
- CONRES *cons;
- foreach_res(cons, R_CONSOLE) {
- /* tls_require implies tls_enable */
- if (cons->tls_require) {
- if (have_tls) {
- cons->tls_enable = true;
- } else {
- Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
- OK = false;
- continue;
- }
- }
-
- if (!cons->tls_certfile && cons->tls_enable) {
- Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Console \"%s\" in %s.\n"),
- cons->name(), configfile);
- OK = false;
- }
-
- if (!cons->tls_keyfile && cons->tls_enable) {
- Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Console \"%s\" in %s.\n"),
- cons->name(), configfile);
- OK = false;
- }
-
- if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable && cons->tls_verify_peer) {
- Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\" or \"TLS CA"
- " Certificate Dir\" are defined for Console \"%s\" in %s."
- " At least one CA certificate store is required"
- " when using \"TLS Verify Peer\".\n"),
- cons->name(), configfile);
- OK = false;
- }
- /* If everything is well, attempt to initialize our per-resource TLS context */
- if (OK && (cons->tls_enable || cons->tls_require)) {
- /* Initialize TLS context:
- * Args: CA certfile, CA certdir, Certfile, Keyfile,
- * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
- cons->tls_ctx = new_tls_context(cons->tls_ca_certfile,
- cons->tls_ca_certdir, cons->tls_certfile,
- cons->tls_keyfile, NULL, NULL, cons->tls_dhfile, cons->tls_verify_peer);
-
- if (!cons->tls_ctx) {
- Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
- cons->name(), configfile);
- OK = false;
- }
- }
-
- }
-
- /* Loop over Clients */
- CLIENT *client;
- foreach_res(client, R_CLIENT) {
- /* tls_require implies tls_enable */
- if (client->tls_require) {
- if (have_tls) {
- client->tls_enable = true;
- } else {
- Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
- OK = false;
- continue;
- }
- }
-
- if ((!client->tls_ca_certfile && !client->tls_ca_certdir) && client->tls_enable) {
- Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
- " or \"TLS CA Certificate Dir\" are defined for File daemon \"%s\" in %s.\n"),
- client->name(), configfile);
- OK = false;
- }
-
- /* If everything is well, attempt to initialize our per-resource TLS context */
- if (OK && (client->tls_enable || client->tls_require)) {
- /* Initialize TLS context:
- * Args: CA certfile, CA certdir, Certfile, Keyfile,
- * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
- client->tls_ctx = new_tls_context(client->tls_ca_certfile,
- client->tls_ca_certdir, client->tls_certfile,
- client->tls_keyfile, NULL, NULL, NULL,
- true);
-
- if (!client->tls_ctx) {
- Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
- client->name(), configfile);
- OK = false;
- }
- }
- }
-
- UnlockRes();
- if (OK) {
- close_msg(NULL); /* close temp message handler */
- init_msg(NULL, director->messages); /* open daemon message handler */
- }
+ /* Set type in global for debugging */
+ set_db_type(db_get_type());
return OK;
}