]> git.sur5r.net Git - bacula/bacula/commitdiff
Add SSL connections to database (PostgreSQL) open code
authorAna Emilia Machado de Arruda <emiliaarruda@gmail.com>
Fri, 29 Jan 2016 18:38:56 +0000 (19:38 +0100)
committerKern Sibbald <kern@sibbald.com>
Mon, 22 May 2017 13:01:42 +0000 (15:01 +0200)
18 files changed:
bacula/src/cats/bdb.h
bacula/src/cats/cats.c
bacula/src/cats/cats_null.c
bacula/src/cats/mysql.c
bacula/src/cats/postgresql.c
bacula/src/cats/protos.h
bacula/src/cats/sqlite.c
bacula/src/dird/dird.c
bacula/src/dird/dird_conf.c
bacula/src/dird/dird_conf.h
bacula/src/dird/job.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_output.c
bacula/src/stored/bscan.c
bacula/src/tools/bbatch.c
bacula/src/tools/bvfs_test.c
bacula/src/tools/cats_test.c
bacula/src/tools/dbcheck.c

index d3b4535415358cfc01f4b1f8b9568f4a47d1a70f..1a48467e1a252312931bfe6ea13f5228e19fcf1f 100644 (file)
@@ -61,6 +61,7 @@ public:
    char *m_db_driverdir;              /* database driver dir */
    int m_ref_count;                   /* reference count */
    int m_db_port;                     /* port for host name address */
+   char *m_db_ssl_mode;               /* security mode of the connection to the server */
    char *m_db_ssl_key;                /* path name to the key file */
    char *m_db_ssl_cert;               /* path name to the certificate file */
    char *m_db_ssl_ca;                 /* path name to the certificate authority file */
index 3cfbaedad937e69c6758ace0447f5dfeb8f6f1c9..d7469fe4cdb397c9236f35da20c53eba984a050e 100644 (file)
@@ -71,10 +71,10 @@ BDB *BDB::bdb_clone_database_connection(JCR *jcr, bool mult_db_connections)
    return db_init_database(jcr, mdb->m_db_driver, mdb->m_db_name, 
              mdb->m_db_user, mdb->m_db_password, mdb->m_db_address, 
              mdb->m_db_port, mdb->m_db_socket,
-             mdb->m_db_ssl_key, mdb->m_db_ssl_cert,
-             mdb->m_db_ssl_ca, mdb->m_db_ssl_capath,
-             mdb->m_db_ssl_cipher, true,
-             mdb->m_disabled_batch_insert); 
+             mdb->m_db_ssl_mode, mdb->m_db_ssl_key,
+             mdb->m_db_ssl_cert, mdb->m_db_ssl_ca,
+             mdb->m_db_ssl_capath, mdb->m_db_ssl_cipher,
+             true, mdb->m_disabled_batch_insert);
 } 
  
 const char *BDB::bdb_get_engine_name(void) 
index f5c360ac947ebf66b4204d4a2280d31109fd7428..ac68388dfc9fb7fb8818dfbc5d650f824f986612 100644 (file)
@@ -26,7 +26,8 @@
  
 BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name,
          const char *db_user, const char *db_password, const char *db_address,
-         int db_port, const char *db_socket, const char *db_ssl_key,
+         int db_port, const char *db_socket,
+         const char *db_ssl_mode, const char *db_ssl_key,
          const char *db_ssl_cert, const char *db_ssl_ca,
          const char *db_ssl_capath, const char *db_ssl_cipher,
          bool mult_db_connections, bool disable_batch_insert)
index cdb75e1f9866f5e72cef3c4ac42f051407609e29..3aa9a668d634dbd05445e73f807eb00a0fb05acb 100644 (file)
@@ -91,7 +91,8 @@ BDB_MYSQL::~BDB_MYSQL()
  */ 
 BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
                        const char *db_password, const char *db_address, int db_port, const char *db_socket, 
-                       const char *db_ssl_key, const char *db_ssl_cert, const char *db_ssl_ca,
+                       const char *db_ssl_mode, const char *db_ssl_key, 
+                       const char *db_ssl_cert, const char *db_ssl_ca,
                        const char *db_ssl_capath, const char *db_ssl_cipher,
                        bool mult_db_connections, bool disable_batch_insert) 
 { 
@@ -133,6 +134,11 @@ BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, cons
    if (db_socket) {
       mdb->m_db_socket = bstrdup(db_socket); 
    } 
+   if (db_ssl_mode) {
+      mdb->m_db_ssl_mode = bstrdup(db_ssl_mode);
+   } else {
+      mdb->m_db_ssl_mode = bstrdup("preferred");
+   }
    if (db_ssl_key) {
       mdb->m_db_ssl_key = bstrdup(db_ssl_key);
    }
@@ -354,6 +360,9 @@ void BDB_MYSQL::bdb_close_database(JCR *jcr)
       if (mdb->m_db_socket) { 
          free(mdb->m_db_socket); 
       }
+      if (mdb->m_db_ssl_mode) {
+         free(mdb->m_db_ssl_mode);
+      }
       if (mdb->m_db_ssl_key) {
          free(mdb->m_db_ssl_key);
       }
index dabc4b827bf8c446635956b5f95615f75124c4f4..3f7ec6119722145f07f4b8dbca8864e6fdcc35b3 100644 (file)
@@ -100,8 +100,8 @@ BDB_POSTGRESQL::~BDB_POSTGRESQL()
  */
 BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
                        const char *db_password, const char *db_address, int db_port, const char *db_socket, 
-                       const char *db_ssl_key, const char *db_ssl_cert, const char *db_ssl_ca,
-                       const char *db_ssl_capath, const char *db_ssl_cipher,
+                       const char *db_ssl_mode, const char *db_ssl_key, const char *db_ssl_cert,
+                       const char *db_ssl_ca, const char *db_ssl_capath, const char *db_ssl_cipher,
                        bool mult_db_connections, bool disable_batch_insert) 
 {
    BDB_POSTGRESQL *mdb = NULL;
@@ -139,7 +139,21 @@ BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, cons
    }
    if (db_socket) {
       mdb->m_db_socket = bstrdup(db_socket);
-   } 
+   }
+   if (db_ssl_mode) {
+      mdb->m_db_ssl_mode = bstrdup(db_ssl_mode);
+   } else {
+      mdb->m_db_ssl_mode = bstrdup("prefer");
+   }
+   if (db_ssl_key) {
+      mdb->m_db_ssl_key = bstrdup(db_ssl_key);
+   }
+   if (db_ssl_cert) {
+      mdb->m_db_ssl_cert = bstrdup(db_ssl_cert);
+   }
+   if (db_ssl_ca) {
+      mdb->m_db_ssl_ca = bstrdup(db_ssl_ca);
+   }
    mdb->m_db_port = db_port;
 
    if (disable_batch_insert) { 
@@ -242,17 +256,29 @@ bool BDB_POSTGRESQL::bdb_open_database(JCR *jcr)
       port = NULL;
    }
 
+   /* Tells libpq that the SSL library has already been initialized */
+   PQinitSSL(0);
+
    /* If connection fails, try at 5 sec intervals for 30 seconds. */
    for (int retry=0; retry < 6; retry++) {
       /* connect to the database */
-      mdb->m_db_handle = PQsetdbLogin(
-           mdb->m_db_address,         /* default = localhost */
-           port,                      /* default port */
-           NULL,                      /* pg options */
-           NULL,                      /* tty, ignored */
-           mdb->m_db_name,            /* database name */
-           mdb->m_db_user,            /* login name */
-           mdb->m_db_password);       /* password */
+      const char *keywords[10] = {"host", "port",
+                                  "dbname", "user",
+                                  "password", "sslmode",
+                                  "sslkey", "sslcert",
+                                  "sslrootcert", NULL };
+      const char *values[10] = {mdb->m_db_address, /* default localhost */
+                                port, /* default port */
+                                mdb->m_db_name,
+                                mdb->m_db_user,
+                                mdb->m_db_password,
+                                mdb->m_db_ssl_mode,
+                                mdb->m_db_ssl_key,
+                                mdb->m_db_ssl_cert,
+                                mdb->m_db_ssl_ca,
+                                NULL };
+      mdb->m_db_handle = PQconnectdbParams(keywords,
+                                           values, 0);
 
       /* If no connect, try once more in case it is a timing problem */
       if (PQstatus(mdb->m_db_handle) == CONNECTION_OK) {
@@ -265,6 +291,18 @@ bool BDB_POSTGRESQL::bdb_open_database(JCR *jcr)
    Dmsg3(dbglvl_info, "db_user=%s db_name=%s db_password=%s\n", mdb->m_db_user, mdb->m_db_name,
         mdb->m_db_password==NULL?"(NULL)":mdb->m_db_password);
 
+#ifdef HAVE_OPENSSL
+   #define USE_OPENSSL 1
+   SSL *ssl;
+   if (PQgetssl(mdb->m_db_handle) != NULL) {
+      Dmsg0(dbglvl_info, "SSL in use\n");
+      ssl = (SSL *)PQgetssl(mdb->m_db_handle);
+      Dmsg2(dbglvl_info, "Version:%s Cipher:%s\n", SSL_get_version(ssl), SSL_get_cipher(ssl)); 
+   } else {
+      Dmsg0(dbglvl_info, "SSL not in use\n");
+   }
+#endif
+
    if (PQstatus(mdb->m_db_handle) != CONNECTION_OK) {
       Mmsg2(&mdb->errmsg, _("Unable to connect to PostgreSQL server. Database=%s User=%s\n"
          "Possible causes: SQL server not running; password incorrect; max_connections exceeded.\n"),
@@ -342,7 +380,19 @@ void BDB_POSTGRESQL::bdb_close_database(JCR *jcr)
       } 
       if (mdb->m_db_socket) {
          free(mdb->m_db_socket);
-      } 
+      }
+      if (mdb->m_db_ssl_mode) {
+         free(mdb->m_db_ssl_mode);
+      }
+      if (mdb->m_db_ssl_key) {
+         free(mdb->m_db_ssl_key);
+      }
+      if (mdb->m_db_ssl_cert) {
+         free(mdb->m_db_ssl_cert);
+      }
+      if (mdb->m_db_ssl_ca) {
+         free(mdb->m_db_ssl_ca);
+      }
       delete mdb;
       if (db_list->size() == 0) {
          delete db_list;
index e281435ef63bdbcae38fecd8ce6787f37f6bb361..dacccb93d8abd481f765d6cafd1ad94154d66aff 100644 (file)
@@ -45,7 +45,8 @@
 BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name,
         const char *db_user, const char *db_password,
         const char *db_address, int db_port,
-        const char *db_socket, const char *db_ssl_key,
+        const char *db_socket,
+        const char *db_ssl_mode, const char *db_ssl_key,
         const char *db_ssl_cert, const char *db_ssl_ca,
         const char *db_ssl_capath, const char *db_ssl_cipher,
         bool mult_db_connections, bool disable_batch_insert);
index 9ee817102167d8f8683cf5c25ddbd623593b58bc..0832cc536974320fa29e4a12aee8177bbc332a31 100644 (file)
@@ -101,7 +101,8 @@ BDB_SQLITE::~BDB_SQLITE()
  */ 
 BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
                        const char *db_password, const char *db_address, int db_port, const char *db_socket, 
-                       const char *db_ssl_key, const char *db_ssl_cert, const char *db_ssl_ca,
+                       const char *db_ssl_mode, const char *db_ssl_key, 
+                       const char *db_ssl_cert, const char *db_ssl_ca,
                        const char *db_ssl_capath, const char *db_ssl_cipher,
                        bool mult_db_connections, bool disable_batch_insert) 
 {  
index 1f85ac7247dd168d04d66687af997a5322a6d2f8..9bde2ebb8422cca99103e09310b147151ed5b33a 100644 (file)
@@ -1142,7 +1142,8 @@ static bool check_catalog(cat_op mode)
               catalog->db_user,
               catalog->db_password, catalog->db_address,
               catalog->db_port, catalog->db_socket,
-              catalog->db_ssl_key, catalog->db_ssl_cert, catalog->db_ssl_ca,
+              catalog->db_ssl_mode, catalog->db_ssl_key,
+              catalog->db_ssl_cert, catalog->db_ssl_ca,
               catalog->db_ssl_capath, catalog->db_ssl_cipher,
               catalog->mult_db_connections,
               catalog->disable_batch_insert);
index 317e289823486d1a30cc54d793eceb077e8ca1ff..f0c7d324ce89850d246a5ce6fba1fb4180ac6744 100644 (file)
@@ -496,6 +496,8 @@ static RES_ITEM cat_items[] = {
    {"User",     store_str,      ITEM(res_cat.db_user),     0, 0, 0},
    {"DbName",   store_str,      ITEM(res_cat.db_name),     0, ITEM_REQUIRED, 0},
    {"dbdriver", store_str,      ITEM(res_cat.db_driver),   0, 0, 0},
+   {"DbSocket", store_str,      ITEM(res_cat.db_socket),   0, 0, 0},
+   {"dbsslmode", store_str,     ITEM(res_cat.db_ssl_mode),  0, 0, 0},
    {"dbsslkey", store_str,      ITEM(res_cat.db_ssl_key),  0, 0, 0},
    {"dbsslcert", store_str,     ITEM(res_cat.db_ssl_cert),  0, 0, 0},
    {"dbsslca", store_str,       ITEM(res_cat.db_ssl_ca),  0, 0, 0},
@@ -1600,6 +1602,9 @@ void free_resource(RES *rres, int type)
       if (res->res_cat.db_password) {
          free(res->res_cat.db_password);
       }
+      if (res->res_cat.db_ssl_mode) {
+         free(res->res_cat.db_ssl_mode);
+      }
       if (res->res_cat.db_ssl_key) {
          free(res->res_cat.db_ssl_key);
       }
index af078878661189b6b198be155f402f5a5aa19fe6..dce2e9abfb347e12896d1982dd2b486caf69fe98 100644 (file)
@@ -231,6 +231,7 @@ public:
    char *db_user;
    char *db_name;
    char *db_driver;                   /* Select appropriate driver */
+   char *db_ssl_mode;                 /* specifies the security state of the connection to the server */
    char *db_ssl_key;                  /* the path name to the key file */
    char *db_ssl_cert;                 /* the path name to the certificate file */
    char *db_ssl_ca;                   /* the path name to the certificate authority file */
index 3ac5feb64533679e8bc5b51c9cee7e8ef2196a9f..a48806c4d3ba04128b9de6f7b579597c29d42ccd 100644 (file)
@@ -116,9 +116,10 @@ bool setup_job(JCR *jcr)
    jcr->db = db_init_database(jcr, jcr->catalog->db_driver, jcr->catalog->db_name,
                 jcr->catalog->db_user, jcr->catalog->db_password,
                 jcr->catalog->db_address, jcr->catalog->db_port,
-                jcr->catalog->db_socket, jcr->catalog->db_ssl_key,
-                jcr->catalog->db_ssl_cert, jcr->catalog->db_ssl_ca,
-                jcr->catalog->db_ssl_capath, jcr->catalog->db_ssl_cipher,
+                jcr->catalog->db_socket, jcr->catalog->db_ssl_mode,
+                jcr->catalog->db_ssl_key, jcr->catalog->db_ssl_cert,
+                jcr->catalog->db_ssl_ca, jcr->catalog->db_ssl_capath, 
+                jcr->catalog->db_ssl_cipher,
                 jcr->catalog->mult_db_connections,
                 jcr->catalog->disable_batch_insert);
    if (!jcr->db || !db_open_database(jcr, jcr->db)) {
@@ -267,9 +268,10 @@ static bool setup_resume_job(JCR *jcr, JOB_DBR *jr)
    jcr->db = db_init_database(jcr, jcr->catalog->db_driver, jcr->catalog->db_name,
                               jcr->catalog->db_user, jcr->catalog->db_password,
                               jcr->catalog->db_address, jcr->catalog->db_port,
-                              jcr->catalog->db_socket, jcr->catalog->db_ssl_key,
-                              jcr->catalog->db_ssl_cert, jcr->catalog->db_ssl_ca,
-                              jcr->catalog->db_ssl_capath, jcr->catalog->db_ssl_cipher,
+                              jcr->catalog->db_socket, jcr->catalog->db_ssl_mode,
+                              jcr->catalog->db_ssl_key, jcr->catalog->db_ssl_cert,
+                              jcr->catalog->db_ssl_ca, jcr->catalog->db_ssl_capath, 
+                              jcr->catalog->db_ssl_cipher,
                               jcr->catalog->mult_db_connections,
                               jcr->catalog->disable_batch_insert);
    if (!jcr->db || !db_open_database(jcr, jcr->db)) {
index 0e1277c16b819099681062a14c8cab95f3cca819..9f2a8324214d84ab12fca78f9bec961f72f87f2c 100644 (file)
@@ -2544,10 +2544,10 @@ bool open_db(UAContext *ua)
                              ua->catalog->db_user,
                              ua->catalog->db_password, ua->catalog->db_address,
                              ua->catalog->db_port, ua->catalog->db_socket,
-                             ua->catalog->db_ssl_key, ua->catalog->db_ssl_cert,
-                             ua->catalog->db_ssl_ca, ua->catalog->db_ssl_capath,
-                             ua->catalog->db_ssl_cipher,
-                             mult_db_conn, ua->catalog->disable_batch_insert);
+                             ua->catalog->db_ssl_mode, ua->catalog->db_ssl_key,
+                             ua->catalog->db_ssl_cert, ua->catalog->db_ssl_ca,
+                             ua->catalog->db_ssl_capath, ua->catalog->db_ssl_cipher,
+                             mult_db_conn, ua->catalog->disable_batch_insert); 
    if (!ua->db || !db_open_database(ua->jcr, ua->db)) {
       ua->error_msg(_("Could not open catalog database \"%s\".\n"),
                  ua->catalog->db_name);
index c8e156a39547aa07bb78896ddef9cd75835e443b..3e940a69c20e445f0d827c0fa34a949e7e685af4 100644 (file)
@@ -940,7 +940,8 @@ bool complete_jcr_for_job(JCR *jcr, JOB *job, POOL *pool)
                 jcr->catalog->db_user,
                 jcr->catalog->db_password, jcr->catalog->db_address,
                 jcr->catalog->db_port, jcr->catalog->db_socket,
-                jcr->catalog->db_ssl_key, jcr->catalog->db_ssl_cert, jcr->catalog->db_ssl_ca,
+                jcr->catalog->db_ssl_mode, jcr->catalog->db_ssl_key,
+                jcr->catalog->db_ssl_cert, jcr->catalog->db_ssl_ca,
                 jcr->catalog->db_ssl_capath, jcr->catalog->db_ssl_cipher,
                 jcr->catalog->mult_db_connections,
                 jcr->catalog->disable_batch_insert);
index f06d5f51ae793f871c9e400ae44c991b557bba85..eb53b63be0884397cef4fe02c37dc538788ac7f6 100644 (file)
@@ -74,6 +74,7 @@ static const char *db_name = "bacula";
 static const char *db_user = "bacula";
 static const char *db_password = "";
 static const char *db_host = NULL;
+static const char *db_ssl_mode = NULL;
 static const char *db_ssl_key = NULL;
 static const char *db_ssl_cert = NULL;
 static const char *db_ssl_ca = NULL;
@@ -148,7 +149,7 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "b:c:d:D:h:p:mn:pP:rsSt:u:vV:w:?")) != -1) {
+   while ((ch = getopt(argc, argv, "b:c:d:D:h:o:k:e:a:p:mn:pP:rsSt:u:vV:w:?")) != -1) {
       switch (ch) {
       case 'S' :
          showProgress = true;
@@ -183,6 +184,22 @@ int main (int argc, char *argv[])
          db_host = optarg;
          break;
 
+      case 'o':
+         db_ssl_mode = optarg;
+         break;
+
+      case 'k':
+         db_ssl_key = optarg;
+         break;
+
+      case 'e':
+         db_ssl_cert = optarg;
+         break;
+
+      case 'a':
+         db_ssl_ca = optarg;
+         break;
+
       case 't':
          db_port = atoi(optarg);
          break;
@@ -285,8 +302,9 @@ int main (int argc, char *argv[])
    }
 
    db = db_init_database(NULL, db_driver, db_name, db_user, db_password,
-                         db_host, db_port, NULL, 
-                         db_ssl_key, db_ssl_cert, db_ssl_ca,
+                         db_host, db_port, NULL,
+                         db_ssl_mode, db_ssl_key,
+                         db_ssl_cert, db_ssl_ca,
                          db_ssl_capath, db_ssl_cipher,
                          false, false);
    if (!db || !db_open_database(NULL, db)) {
index 7b0453fca18c1a5b93ac3105c47a0481ec5e5091..c86685f3a36fcf4a7e4959ba99c2184383b29cc9 100644 (file)
@@ -57,11 +57,12 @@ static const char *db_name = "bacula";
 static const char *db_user = "bacula";
 static const char *db_password = "";
 static const char *db_host = NULL;
-static const char *db_ssl_key= NULL;
-static const char *db_ssl_cert= NULL;
-static const char *db_ssl_ca= NULL;
-static const char *db_ssl_capath= NULL;
-static const char *db_ssl_cipher= NULL;
+static const char *db_ssl_mode = NULL;
+static const char *db_ssl_key = NULL;
+static const char *db_ssl_cert = NULL;
+static const char *db_ssl_ca = NULL;
+static const char *db_ssl_capath = NULL;
+static const char *db_ssl_cipher = NULL;
 
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -121,7 +122,7 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "bBh:k:e:a:c:d:n:P:Su:vf:w:r:?")) != -1) {
+   while ((ch = getopt(argc, argv, "bBh:o:k:e:a:c:d:n:P:Su:vf:w:r:?")) != -1) {
       switch (ch) {
       case 'r':
          restore_list=bstrdup(optarg);
@@ -147,6 +148,10 @@ int main (int argc, char *argv[])
          db_host = optarg;
          break;
 
+      case 'o':
+         db_ssl_mode = optarg;
+         break;
+
       case 'k':
          db_ssl_key = optarg;
          break;
@@ -205,8 +210,10 @@ int main (int argc, char *argv[])
       /* To use the -r option, the catalog should already contains records */
       
       if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password, 
-                                 db_host, 0, NULL, db_ssl_key, db_ssl_cert,
-                                 db_ssl_ca, db_ssl_capath, db_ssl_cipher,
+                                 db_host, 0, NULL,
+                                 db_ssl_mode, db_ssl_key,
+                                 db_ssl_cert, db_ssl_ca,
+                                 db_ssl_capath, db_ssl_cipher,
                                  false, !use_batch_insert)) == NULL) {
          Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
       }
@@ -256,8 +263,10 @@ int main (int argc, char *argv[])
       pm_strcpy(bjcr->fileset_md5, "Dummy.fileset.md5");
       
       if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password, 
-                                 db_host, 0, NULL, db_ssl_key, db_ssl_cert,
-                                 db_ssl_ca, db_ssl_capath, db_ssl_cipher,
+                                 db_host, 0, NULL,
+                                 db_ssl_mode, db_ssl_key,
+                                 db_ssl_cert, db_ssl_ca,
+                                 db_ssl_capath, db_ssl_cipher,
                                  false, false)) == NULL) {
          Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
       }
index 6037faa1043a3196b7316e64d2f4a821ffa8e284..77c2edb40535cd6d7f1c2e1f794e8e8e6692dfc1 100644 (file)
@@ -38,6 +38,7 @@ static const char *db_name = "regress";
 static const char *db_user = "regress";
 static const char *db_password = "";
 static const char *db_host = NULL;
+static const char *db_ssl_mode = NULL;
 static const char *db_ssl_key = NULL;
 static const char *db_ssl_cert = NULL;
 static const char *db_ssl_ca = NULL;
@@ -126,7 +127,7 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "h:k:e:a:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
+   while ((ch = getopt(argc, argv, "h:o:k:e:a:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
       switch (ch) {
       case 'd':                    /* debug level */
          if (*optarg == 't') {
@@ -150,6 +151,10 @@ int main (int argc, char *argv[])
          db_host = optarg;
          break;
 
+      case 'o':
+         db_ssl_mode = optarg;
+         break;
+
       case 'k':
          db_ssl_key= optarg;
          break;
@@ -222,7 +227,8 @@ int main (int argc, char *argv[])
    
    if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password, 
                               db_host, 0, NULL,
-                              db_ssl_key, db_ssl_cert, db_ssl_ca,
+                              db_ssl_mode, db_ssl_key,
+                              db_ssl_cert, db_ssl_ca,
                               db_ssl_capath, db_ssl_cipher,
                               false, false)) == NULL) {
       Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
index f06bba943e4805680ed0b2d2b8a8e36296c7b054..558715491b523e18810d2312d8b27fbcea4fd364 100644 (file)
@@ -339,8 +339,8 @@ int main (int argc, char *argv[])
                    NULL /* dbi driver */,
                    db_name, db_user, db_password, db_address, db_port + 100,
                    NULL /* db_socket */,
-                   db_ssl_key, db_ssl_cert, db_ssl_ca,
-                   db_ssl_capath, db_ssl_cipher,
+                   db_ssl_mode, db_ssl_key, db_ssl_cert,
+                   db_ssl_ca, db_ssl_capath, db_ssl_cipher,
                    0 /* mult_db_connections */, false);
       ok(db != NULL, "Test bad connection");
       if (!db) {
@@ -355,8 +355,8 @@ int main (int argc, char *argv[])
                 NULL /* dbi driver */,
                 db_name, db_user, db_password, db_address, db_port,
                 NULL /* db_socket */,
-                db_ssl_key, db_ssl_cert, db_ssl_ca,
-                db_ssl_capath, db_ssl_cipher,
+                db_ssl_mode, db_ssl_key, db_ssl_cert,
+                db_ssl_ca, db_ssl_capath, db_ssl_cipher,
                 false /* mult_db_connections */, false);
 
    ok(db != NULL, "Test db connection");
index 5c67fd91c154e8014df6b439da819c4f1948064c..28f785a134065bd2a130975e43fddb67b9e48ba4 100644 (file)
@@ -95,7 +95,7 @@ static void usage()
    fprintf(stderr,
 PROG_COPYRIGHT
 "\n%sVersion: %s (%s)\n\n"
-"Usage: dbcheck [-c config ] [-B] [-C catalog name] [-d debug_level] <working-directory> <bacula-database> <user> <password> [<dbhost>] [<dbport>] [<dbport>] [<dbsslkey>] [<dbsslcert>] [<dbsslca>]\n"
+"Usage: dbcheck [-c config ] [-B] [-C catalog name] [-d debug_level] <working-directory> <bacula-database> <user> <password> [<dbhost>] [<dbport>] [<dbport>] [<dbsslmode>] [<dbsslkey>] [<dbsslcert>] [<dbsslca>]\n"
 "       -b              batch mode\n"
 "       -C              catalog name in the director conf file\n"
 "       -c              Director conf filename\n"
@@ -115,7 +115,7 @@ int main (int argc, char *argv[])
 {
    int ch;
    const char *user, *password, *db_name, *dbhost;
-   const char *dbsslkey = NULL, *dbsslcert = NULL, *dbsslca = NULL;
+   const char *dbsslmode = NULL, *dbsslkey = NULL, *dbsslcert = NULL, *dbsslca = NULL;
    const char *dbsslcapath = NULL, *dbsslcipher = NULL;
    int dbport = 0;
    bool print_catalog=false;
@@ -218,7 +218,9 @@ int main (int argc, char *argv[])
             db = db_init_database(NULL, catalog->db_driver, catalog->db_name, catalog->db_user,
                     catalog->db_password, catalog->db_address,
                     catalog->db_port, catalog->db_socket,
-                    catalog->db_ssl_key, catalog->db_ssl_cert, catalog->db_ssl_ca,
+                    catalog->db_ssl_mode,
+                    catalog->db_ssl_key, catalog->db_ssl_cert, 
+                    catalog->db_ssl_ca,
                     catalog->db_ssl_capath, catalog->db_ssl_cipher,
                     catalog->mult_db_connections,
                     catalog->disable_batch_insert);
@@ -239,6 +241,7 @@ int main (int argc, char *argv[])
             dbhost = NULL;
          }
          dbport = catalog->db_port;
+         dbsslmode = catalog->db_ssl_mode;
          dbsslkey = catalog->db_ssl_key;
          dbsslcert = catalog->db_ssl_cert;
          dbsslca = catalog->db_ssl_ca;
@@ -246,7 +249,7 @@ int main (int argc, char *argv[])
          dbsslcipher = catalog->db_ssl_cipher;
       }
    } else {
-      if (argc > 9) {
+      if (argc > 10) {
          Pmsg0(0, _("Wrong number of arguments.\n"));
          usage();
       }
@@ -283,11 +286,14 @@ int main (int argc, char *argv[])
                         exit(1);
                      }
                      if (argc >= 7) {
-                        dbsslkey = argv[6];
-                        dbsslcert = argv[7];
-                        if (argc == 9) {
-                           dbsslca = argv[8];
-                        } /* if (argc == 9) */
+                        dbsslmode = argv[6];
+                        if (argc >= 8) {
+                           dbsslkey = argv[7];
+                           dbsslcert = argv[8];
+                           if (argc == 10) {
+                              dbsslca = argv[9];
+                           } /* if (argc == 10) */
+                        } /* if (argc >= 8) */
                      } /* if (argc >= 7) */
                   } /* if (argc >= 6) */
                } /* if (argc >= 5) */
@@ -298,7 +304,9 @@ int main (int argc, char *argv[])
 
    /* Open database */
    db = db_init_database(NULL, NULL, db_name, user, password, dbhost,
-           dbport, NULL, dbsslkey, dbsslcert, dbsslca, dbsslcapath, dbsslcipher, false, false);
+          dbport, NULL, dbsslmode, dbsslkey, dbsslcert, dbsslca,
+           dbsslcapath, dbsslcipher, false, false);
+
    if (!db || !db_open_database(NULL, db)) {
       Emsg1(M_FATAL, 0, "%s", db_strerror(db));
           return 1;
@@ -335,6 +343,29 @@ int main (int argc, char *argv[])
    return 0;
 }
 
+static void print_catalog_details(CAT *catalog, const char *working_dir)
+{
+   POOLMEM *catalog_details = get_pool_memory(PM_MESSAGE);
+
+   /*
+    * Instantiate a BDB class and see what db_type gets assigned to it.
+    */
+   db = db_init_database(NULL, catalog->db_driver, catalog->db_name, catalog->db_user,
+                         catalog->db_password, catalog->db_address,
+                         catalog->db_port, catalog->db_socket,
+                         catalog->db_ssl_mode, catalog->db_ssl_key, 
+                         catalog->db_ssl_cert, catalog->db_ssl_ca,
+                         catalog->db_ssl_capath, catalog->db_ssl_cipher,
+                         catalog->mult_db_connections,
+                         catalog->disable_batch_insert);
+   if (db) {
+      printf("%sdb_type=%s\nworking_dir=%s\n", catalog->display(catalog_details),
+             db_get_engine_name(db), working_directory);
+      db_close_database(NULL, db);
+   }
+   free_pool_memory(catalog_details);
+}
+
 static void do_interactive_mode()
 {
    const char *cmd;