]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird.c
Turn off debug
[bacula/bacula] / bacula / src / dird / dird.c
index 5081f08561cab7a5d01e4ec0bba4955d694f098a..9cdab0fb86320ba800712c806228b2cf89f74837 100644 (file)
@@ -1,15 +1,7 @@
-/*
- *
- *   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 */
@@ -68,6 +69,7 @@ DIRRES *director;                     /* Director resource */
 int FDConnectTimeout;
 int SDConnectTimeout;
 char *configfile = NULL;
+void *start_heap;
 
 /* Globals Imported */
 extern int r_first, r_last;           /* first and last resources */
@@ -113,6 +115,7 @@ PROG_COPYRIGHT
  *
  */
 #if defined(HAVE_WIN32)
+/* For Win32 main() is in src/win32 code ... */
 #define main BaculaMain
 #endif
 
@@ -125,6 +128,7 @@ int main (int argc, char *argv[])
    char *uid = NULL;
    char *gid = NULL;
 
+   start_heap = sbrk(0);
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
@@ -224,6 +228,12 @@ int main (int argc, char *argv[])
       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);
    }
@@ -246,7 +256,6 @@ int main (int argc, char *argv[])
    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);
@@ -269,6 +278,8 @@ int main (int argc, char *argv[])
 
    init_job_server(director->MaxConcurrentJobs);
 
+//   init_device_resources();
+
    Dmsg0(200, "wait for next job\n");
    /* Main loop -- call scheduler to get next job to run */
    while ( (jcr = wait_for_next_job(runjob)) ) {
@@ -509,7 +520,7 @@ bail_out:
  *  **** FIXME **** this routine could be a lot more
  *   intelligent and comprehensive.
  */
-static int check_resources()
+static bool check_resources()
 {
    bool OK = true;
    JOB *job;
@@ -716,7 +727,7 @@ static int check_resources()
       for (i=0; job_items[i].name; i++) {
          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"),
+                  Jmsg(NULL, M_ERROR_TERM, 0, _("\"%s\" directive in Job \"%s\" resource is required, but not found.\n"),
                     job_items[i].name, job->name());
                   OK = false;
                 }
@@ -733,6 +744,110 @@ static int check_resources()
       }
    } /* 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) {
@@ -746,10 +861,14 @@ static int check_resources()
                          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));
+            db_close_database(NULL, db);
          }
          OK = false;
          continue;
@@ -761,6 +880,11 @@ static int check_resources()
          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;
@@ -842,102 +966,7 @@ static int check_resources()
       }
       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;
 }