]> git.sur5r.net Git - bacula/bacula/commitdiff
Patch to add MySQL ssl access
authorAna Emilia M. Arruda <emiliaarruda@gmail.com>
Wed, 23 Dec 2015 10:59:51 +0000 (11:59 +0100)
committerKern Sibbald <kern@sibbald.com>
Wed, 23 Dec 2015 10:59:51 +0000 (11:59 +0100)
22 files changed:
bacula/autoconf/configure.in
bacula/configure
bacula/src/cats/bdb.h
bacula/src/cats/bvfs.c
bacula/src/cats/cats.c
bacula/src/cats/cats_null.c
bacula/src/cats/grant_mysql_privileges.in
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 08439810687e403341b8171bc2f47764b03f3cc9..39a94cf07e0905ca963d3c1ff5354fc7ce20b73f 100644 (file)
@@ -1452,6 +1452,20 @@ AC_ARG_WITH(db_port,
 )
 AC_SUBST(db_port)
 
+dnl
+dnl Pickup MySQL SSL options for database user connection 
+dnl
+db_ssl_options=
+AC_ARG_WITH(db_ssl_options,
+   AC_HELP_STRING([--with-db-ssl-options=DBSSLOPTIONS], [specify SSL options for database user connection @<:@default=null@:>@]),
+   [
+       if test "x$withval" != "x" ; then
+         db_ssl_options=$withval
+       fi
+   ]
+)
+AC_SUBST(db_ssl_options)
+
 #
 # Handle users and groups for each daemon
 #
@@ -3490,6 +3504,7 @@ Configuration on `date`:
    Database port:           ${db_port}
    Database name:           ${db_name}
    Database user:           ${db_user}
+   Database SSL options:     ${db_ssl_options}
 
    Job Output Email:        ${job_email}
    Traceback Email:         ${dump_email}
index e476645341fe42d6504b6bbabc39fe66a7e3facd..445dfd59f612121d2f5c54cf115adb2ddcbe0ef3 100755 (executable)
@@ -685,6 +685,7 @@ db_port
 db_password
 db_user
 db_name
+db_ssl_options
 mon_sd_password
 mon_fd_password
 mon_dir_password
@@ -986,6 +987,7 @@ with_db_name
 with_db_user
 with_db_password
 with_db_port
+with_db_ssl_options
 with_dir_user
 with_dir_group
 with_sd_user
@@ -23654,6 +23656,19 @@ if test "${with_db_port+set}" = set; then :
        fi
 
 
+fi
++db_ssl_options=
+
+
+
+# Check whether --with-db_ssl_options was given.
+if test "${with_db_ssl_options+set}" = set; then :
+  withval=$with_db_ssl_options;
+       if test "x$withval" != "x" ; then
+         db_ssl_options=$withval
+       fi
+
+
 fi
 
 
@@ -33730,6 +33745,7 @@ Configuration on `date`:
    Database port:           ${db_port}
    Database name:           ${db_name}
    Database user:           ${db_user}
+   Database SSL options:     ${db_ssl_options}
 
    Job Output Email:        ${job_email}
    Traceback Email:         ${dump_email}
index cc53b4a780f1f445db40d471f5824e62c71ddf03..717f0dab9068ff576046c09e7da79ebdadc103a5 100644 (file)
@@ -42,6 +42,11 @@ 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_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 */
+   char *m_db_ssl_capath;             /* path name to a directory that contains trusted SSL CA certificates in PEM format */
+   char *m_db_ssl_cipher;             /* a list of permissible ciphers to use for SSL encryption */
    bool m_disabled_batch_insert;      /* explicitly disabled batch insert mode ? */
    bool m_dedicated;                  /* is this connection dedicated? */
    bool m_use_fatal_jmsg;             /* use Jmsg(M_FATAL) after bad queries? */
index 403f063c8de332ecc490ed24733c613fed172795..09dee9803a8fd1bc4d037a4dac8cb16d875146b9 100644 (file)
@@ -1367,7 +1367,7 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
          result[i++] = str_to_int64(row[1]); /* JobId */
          result[i++] = str_to_int64(row[2]); /* FilenameId */
          result[i++] = str_to_int64(row[3]); /* PathId */
-      }
+      } 
 
       i=0;
       while (num > 0) {
@@ -1440,5 +1440,5 @@ void Bvfs::insert_missing_delta(char *output_table, int64_t *res)
       Dmsg1(dbglevel_sql, "Can't exec q=%s\n", db->cmd);
    }
 }
-
 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL */
index 4d189d01ce16a1ea2fa31b7607247e6f279c8da3..ccdedd48bcb9a63302010f62ef648da47f16fe5a 100644 (file)
@@ -1,17 +1,17 @@
 /* 
    Bacula(R) - The Network Backup Solution
-
    Copyright (C) 2000-2015 Kern Sibbald
    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
-
    The original 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.
-
    This notice must be preserved when any source code is 
    conveyed and/or propagated.
 
@@ -71,7 +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, true, 
+             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); 
 } 
  
index df00f8eaf1f44b7618b7459a4291096a54a5a8b2..7b83ea7b162ec633ec80b28bada31c77e6d2db2b 100644 (file)
  
 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, bool mult_db_connections,
-         bool disable_batch_insert)
+         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,
+         bool mult_db_connections, bool disable_batch_insert)
 { 
    Jmsg(jcr, M_FATAL, 0, _("Please replace this null libbaccats library with a proper one.\n"));
    return NULL; 
index f1fcca5a4ac68ec8e82460adc65b714b31a950fb..ab85680ade1b2af6d40db16a739cbacfe08651b3 100644 (file)
@@ -12,11 +12,15 @@ db_password=@db_password@
 if [ "$db_password" != "" ]; then
    pass="identified by '$db_password'"
 fi
-
+db_ssl_options=@db_ssl_options@
+if [ "$db_ssl_options" != "" ]; then
+   ssl_options="require $db_ssl_options"
+fi
 if $bindir/mysql $* -u root -f <<END-OF-DATA
 use mysql
-grant all privileges on ${db_name}.* to ${db_user}@localhost ${pass};
-grant all privileges on ${db_name}.* to ${db_user}@"%" ${pass};
+grant all privileges on ${db_name}.* to ${db_user}@localhost ${pass} ${ssl_options};
+grant all privileges on ${db_name}.* to ${db_user}@"%" ${pass} ${ssl_options};
 select * from user;
 flush privileges;
 END-OF-DATA
index 2cc45c4cbd820fb26e16538d39d3510bf16d8e9e..ac7561800638fa49b3b6fc8e2229f91067922cff 100644 (file)
@@ -93,6 +93,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_capath, const char *db_ssl_cipher,
                        bool mult_db_connections, bool disable_batch_insert) 
 { 
    BDB_MYSQL *mdb = NULL; 
@@ -130,9 +132,24 @@ BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, cons
    if (db_address) { 
       mdb->m_db_address = bstrdup(db_address); 
    } 
-   if (db_socket) { 
+   if (db_socket) {
       mdb->m_db_socket = bstrdup(db_socket); 
    } 
+   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);
+   }
+   if (db_ssl_capath) {
+      mdb->m_db_ssl_capath = bstrdup(db_ssl_capath);
+   }
+   if (db_ssl_cipher) {
+      mdb->m_db_ssl_cipher = bstrdup(db_ssl_cipher);
+   }
    mdb->m_db_port = db_port; 
  
    if (disable_batch_insert) { 
@@ -200,6 +217,20 @@ bool BDB_MYSQL::bdb_open_database(JCR *jcr)
    mysql_init(&mdb->m_instance); 
  
    Dmsg0(50, "mysql_init done\n"); 
+
+   /*
+   * Sets the appropriate certificate options for
+   * establishing secure connection using SSL to the database.
+   */
+   if (mdb->m_db_ssl_key) {
+      mysql_ssl_set(&(mdb->m_instance),
+                   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);
+   }
+
    /* 
     * If connection fails, try at 5 sec intervals for 30 seconds. 
     */ 
@@ -227,7 +258,7 @@ bool BDB_MYSQL::bdb_open_database(JCR *jcr)
    Dmsg0(50, "mysql_real_connect done\n"); 
    Dmsg3(50, "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); 
+
    if (mdb->m_db_handle == NULL) { 
       Mmsg2(&mdb->errmsg, _("Unable to connect to MySQL server.\n" 
 "Database=%s User=%s\n" 
@@ -244,6 +275,19 @@ bool BDB_MYSQL::bdb_open_database(JCR *jcr)
       goto get_out; 
    } 
  
+   /* get the current cipher used for SSL connection */
+   if (mdb->m_db_ssl_key) {
+      const char *cipher;
+      if (mdb->m_db_ssl_cipher) {
+         free(mdb->m_db_ssl_cipher);
+      }
+      cipher = (const char *)mysql_get_ssl_cipher(&(mdb->m_instance));
+      if (cipher) {
+         mdb->m_db_ssl_cipher = bstrdup(cipher);
+      }
+      Dmsg1(50, "db_ssl_ciper=%s\n", (mdb->m_db_ssl_cipher == NULL) ? "(NULL)" : mdb->m_db_ssl_cipher);
+   }
+
    mdb->m_connected = true; 
    if (!bdb_check_version(jcr)) { 
       goto get_out; 
@@ -311,7 +355,22 @@ void BDB_MYSQL::bdb_close_database(JCR *jcr)
       } 
       if (mdb->m_db_socket) { 
          free(mdb->m_db_socket); 
-      } 
+      }
+      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);
+      }
+      if (mdb->m_db_ssl_capath) {
+         free(mdb->m_db_ssl_capath);
+      }
+      if (mdb->m_db_ssl_cipher) {
+         free(mdb->m_db_ssl_cipher);
+      }
       delete mdb; 
       if (db_list->size() == 0) { 
          delete db_list; 
index 76ac3ddaabf7bd8988fb21e222fe3c37458d05d9..70d8e6bcb37da822dfee9ee64e0ed734c72fde20 100644 (file)
@@ -99,11 +99,11 @@ BDB_POSTGRESQL::~BDB_POSTGRESQL()
  * Initialize database data structure. In principal this should
  * never have errors, or it is really fatal.
  */
-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, bool mult_db_connections,
-                       bool disable_batch_insert)
+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,
+                       bool mult_db_connections, bool disable_batch_insert) 
 {
    BDB_POSTGRESQL *mdb = NULL;
 
index cc6510c4478a76e3074c41e12fa65e8000601cfb..5a6a726c95814055ac78520ec2178f980eba7ebb 100644 (file)
 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, bool mult_db_connections, bool disable_batch_insert);
+        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,
+        bool mult_db_connections, bool disable_batch_insert);
 
 /* Database prototypes and defines */
 
index c47899c448ee4ff8d6f600b633b812aab9596a27..89f810ed0cb36dca52c7c9c410ba3aba42c4f9a7 100644 (file)
@@ -100,11 +100,11 @@ BDB_SQLITE::~BDB_SQLITE()
  * Initialize database data structure. In principal this should 
  * never have errors, or it is really fatal. 
  */ 
-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, bool mult_db_connections, 
-                       bool disable_batch_insert) 
+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,
+                       bool mult_db_connections, bool disable_batch_insert) 
 {  
    BDB_SQLITE *mdb = NULL; 
  
index 9972341f041a2aa2ef595e453ea3fb9146d617c9..f74097f8407647e6633eeb00b3aa04639e0b6b4c 100644 (file)
@@ -960,6 +960,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_capath, catalog->db_ssl_cipher,
               catalog->mult_db_connections,
               catalog->disable_batch_insert);
       if (!db || !db_open_database(NULL, db)) {
index 23cd6cbe4313bfb661f911a9e91981d3c15cbacf..53fb9a1c7140c22adcd0d06ca9f51902b04fc79b 100644 (file)
@@ -252,6 +252,11 @@ static RES_ITEM cat_items[] = {
    {"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},
+   {"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},
+   {"dbsslcapath", store_str,   ITEM(res_cat.db_ssl_capath),  0, 0, 0},
+   {"dbsslcipher", store_str,   ITEM(res_cat.db_ssl_cipher),  0, 0, 0},
    /* Turned off for the moment */
    {"MultipleConnections", store_bit, ITEM(res_cat.mult_db_connections), 0, 0, 0},
    {"DisableBatchInsert", store_bool, ITEM(res_cat.disable_batch_insert), 0, ITEM_DEFAULT, false},
@@ -1311,6 +1316,21 @@ 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_key) {
+         free(res->res_cat.db_ssl_key);
+      }
+      if (res->res_cat.db_ssl_cert) {
+         free(res->res_cat.db_ssl_cert);
+      }
+      if (res->res_cat.db_ssl_ca) {
+         free(res->res_cat.db_ssl_ca);
+      }
+      if (res->res_cat.db_ssl_capath) {
+         free(res->res_cat.db_ssl_capath);
+      }
+      if (res->res_cat.db_ssl_cipher) {
+         free(res->res_cat.db_ssl_cipher);
+      }
       break;
    case R_FILESET:
       if ((num=res->res_fs.num_includes)) {
index 90700e58b75051313f54ac3994d0fdf292d57bff..b1101bd04cfd91b63b8fa2918497485885b79756 100644 (file)
@@ -228,6 +228,11 @@ public:
    char *db_user;
    char *db_name;
    char *db_driver;                   /* Select appropriate driver */
+   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 */
+   char *db_ssl_capath;               /* the path name to a directory that contains trusted SSL CA certificates in PEM format */
+   char *db_ssl_cipher;               /* a list of permissible ciphers to use for SSL encryption */
    uint32_t mult_db_connections;      /* set for multiple db connections */
    bool disable_batch_insert;         /* set to disable batch inserts */
 
index d45f55ceca5be0f0e1a26607306e980a2b8dd180..2290a2bf1aa7f3a7ba39abea61cc56326986b328 100644 (file)
@@ -118,7 +118,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->mult_db_connections,
+                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->mult_db_connections,
                 jcr->catalog->disable_batch_insert);
    if (!jcr->db || !db_open_database(jcr, jcr->db)) {
       Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
@@ -266,7 +269,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->mult_db_connections,
+                              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->mult_db_connections,
                               jcr->catalog->disable_batch_insert);
    if (!jcr->db || !db_open_database(jcr, jcr->db)) {
       Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
index 0774d316ca645e42f7fbcd3c0efa7dfb5072ab36..33b93afcb4a1ddaca063998a6e9f2da62384bca7 100644 (file)
@@ -2211,6 +2211,9 @@ 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); 
    if (!ua->db || !db_open_database(ua->jcr, ua->db)) {
       ua->error_msg(_("Could not open catalog database \"%s\".\n"),
index b0fcfc388e727fb0c2f6edfcb6ad249e717c5fd0..45fab76525fd339e9c3a83a8094ae9348ba95dd5 100644 (file)
@@ -815,6 +815,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_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 3702b88d2dac8fccef1a14fe56e66adeb82fdcd8..4757fb0d641d4668c6276705a9958493be14b17c 100644 (file)
@@ -76,6 +76,11 @@ 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 int db_port = 0;
 static const char *wd = NULL;
 static bool update_db = false;
@@ -117,6 +122,9 @@ PROG_COPYRIGHT
 "       -u <user>         specify database user name (default bacula)\n"
 "       -P <password>     specify database password (default none)\n"
 "       -h <host>         specify database host (default NULL)\n"
+"       -k <sslkey>       path name to the key file (default NULL)\n"
+"       -e <sslcert>      path name to the certificate file (default NULL)\n"
+"       -a <sslca>        path name to the CA certificate file (default NULL)\n"
 "       -t <port>         specify database port (default 0)\n"
 "       -p                proceed inspite of I/O errors\n"
 "       -r                list records\n"
@@ -147,7 +155,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:k:e:a:p:mn:pP:rsSt:u:vV:w:?")) != -1) {
       switch (ch) {
       case 'S' :
          showProgress = true;
@@ -182,6 +190,18 @@ int main (int argc, char *argv[])
          db_host = 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;
@@ -284,7 +304,10 @@ int main (int argc, char *argv[])
    }
 
    db = db_init_database(NULL, db_driver, db_name, db_user, db_password,
-                            db_host, db_port, NULL, false, false);
+                         db_host, db_port, NULL, 
+                         db_ssl_key, db_ssl_cert, db_ssl_ca,
+                         db_ssl_capath, db_ssl_cipher,
+                         false, false);
    if (!db || !db_open_database(NULL, db)) {
       Pmsg2(000, _("Could not open Catalog \"%s\", database \"%s\".\n"),
            db_driver, db_name);
index 9542648e4d4f5105f2161b691b34dcc53b86df22..1d4ac8da1dde7611fc3f04a5d406f6186126241a 100644 (file)
@@ -58,6 +58,11 @@ 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 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -78,6 +83,9 @@ PROG_COPYRIGHT
 "       -u <user>         specify database user name (default bacula)\n"
 "       -P <password      specify database password (default none)\n"
 "       -h <host>         specify database host (default NULL)\n"
+"       -k <sslkey>       path name to the key file (default NULL)\n"
+"       -e <sslcert>      path name to the certificate file (default NULL)\n"
+"       -a <sslca>        path name to the CA certificate file (default NULL)\n"
 "       -w <working>      specify working directory\n"
 "       -r <jobids>       call restore code with given jobids\n"
 "       -v                verbose\n"
@@ -114,7 +122,7 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "bBh:c:d:n:P:Su:vf:w:r:?")) != -1) {
+   while ((ch = getopt(argc, argv, "bBh:k:e:a:c:d:n:P:Su:vf:w:r:?")) != -1) {
       switch (ch) {
       case 'r':
          restore_list=bstrdup(optarg);
@@ -140,6 +148,18 @@ int main (int argc, char *argv[])
          db_host = optarg;
          break;
 
+      case 'k':
+         db_ssl_key = optarg;
+         break;
+
+      case 'e':
+         db_ssl_cert = optarg;
+         break;
+
+      case 'a':
+         db_ssl_ca = optarg;
+         break;
+
       case 'n':
          db_name = optarg;
          break;
@@ -186,7 +206,9 @@ 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, false, disable_batch)) == NULL) {
+                                 db_host, 0, NULL, db_ssl_key, db_ssl_cert,
+                                 db_ssl_ca, db_ssl_capath, db_ssl_cipher,
+                                 false, disable_batch)) == NULL) {
          Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
       }
       if (!db_open_database(NULL, db)) {
@@ -235,7 +257,9 @@ 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, false, false)) == NULL) {
+                                 db_host, 0, NULL, 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"));
       }
       if (!db_open_database(NULL, db)) {
index b2a7ed04eee9567f6643c3b19c497f2a50633942..3ac32537b761b2d31805077de39d072f380374dc 100644 (file)
@@ -39,6 +39,11 @@ 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_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 void usage()
 {
@@ -51,6 +56,9 @@ PROG_COPYRIGHT
 "       -u <user>         specify database user name (default bacula)\n"
 "       -P <password      specify database password (default none)\n"
 "       -h <host>         specify database host (default NULL)\n"
+"       -k <sslkey>       path name to the key file (default NULL)\n"
+"       -e <sslcert>      path name to the certificate file (default NULL)\n"
+"       -a <sslca>        path name to the CA certificate file (default NULL)\n"
 "       -w <working>      specify working directory\n"
 "       -j <jobids>       specify jobids\n"
 "       -p <path>         specify path\n"
@@ -119,7 +127,7 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
+   while ((ch = getopt(argc, argv, "h: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') {
@@ -143,6 +151,18 @@ int main (int argc, char *argv[])
          db_host = optarg;
          break;
 
+      case 'k':
+         db_ssl_key= optarg;
+         break;
+
+      case 'e':
+         db_ssl_cert= optarg;
+         break;
+
+      case 'a':
+         db_ssl_ca= optarg;
+         break;
+
       case 'n':
          db_name = optarg;
          break;
@@ -202,7 +222,10 @@ int main (int argc, char *argv[])
    bstrncpy(bjcr->Job, "bvfs_test", sizeof(bjcr->Job));
    
    if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
-                              db_host, 0, NULL, false, false)) == NULL) {
+                              db_host, 0, NULL,
+                              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"));
    }
    Dmsg1(0, "db_type=%s\n", db_get_engine_name(db));
index f204aa0cf092348892e6fc07cd7a4b0817c3c6d5..c51f21fbe9d9a80b8a77408ea5f20fab329fbac7 100644 (file)
@@ -340,6 +340,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,
                    0 /* mult_db_connections */, false);
       ok(db != NULL, "Test bad connection");
       if (!db) {
@@ -354,6 +356,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,
                 false /* mult_db_connections */, false);
 
    ok(db != NULL, "Test db connection");
index 5d50e2e8cdf256ef1f387ef5b415a4a39d6ca707..73ea9920d15da7d1754c5922ff9ca8d2152ff13b 100644 (file)
@@ -100,7 +100,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>]\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"
 "       -b              batch mode\n"
 "       -C              catalog name in the director conf file\n"
 "       -c              Director conf filename\n"
@@ -120,6 +120,8 @@ 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 *dbsslcapath = NULL, *dbsslcipher = NULL;
    int dbport = 0;
    bool print_catalog=false;
    char *configfile = NULL;
@@ -230,9 +232,14 @@ int main (int argc, char *argv[])
             dbhost = NULL;
          }
          dbport = catalog->db_port;
+         dbsslkey = catalog->db_ssl_key;
+         dbsslcert = catalog->db_ssl_cert;
+         dbsslca = catalog->db_ssl_ca;
+         dbsslcapath = catalog->db_ssl_capath;
+         dbsslcipher = catalog->db_ssl_cipher;
       }
    } else {
-      if (argc > 6) {
+      if (argc > 9) {
          Pmsg0(0, _("Wrong number of arguments.\n"));
          usage();
       }
@@ -251,42 +258,43 @@ int main (int argc, char *argv[])
       password = "";
       dbhost = NULL;
 
-      if (argc == 2) {
+      if (argc >= 2) {
          db_name = argv[1];
          user = db_name;
-      } else if (argc == 3) {
-         db_name = argv[1];
-         user = argv[2];
-      } else if (argc == 4) {
-         db_name = argv[1];
-         user = argv[2];
-         password = argv[3];
-      } else if (argc == 5) {
-         db_name = argv[1];
-         user = argv[2];
-         password = argv[3];
-         dbhost = argv[4];
-      } else if (argc == 6) {
-         db_name = argv[1];
-         user = argv[2];
-         password = argv[3];
-         dbhost = argv[4];
-         errno = 0;
-         dbport = strtol(argv[5], &endptr, 10);
-         if (*endptr != '\0') {
-            Pmsg0(0, _("Database port must be a numeric value.\n"));
-            exit(1);
-         } else if (errno == ERANGE) {
-            Pmsg0(0, _("Database port must be a int value.\n"));
-            exit(1);
-         }
-      }
+         if (argc >= 3) {
+            user = argv[2];
+            if (argc >= 4) {
+               password = argv[3];
+               if (argc >= 5) {
+                  dbhost = argv[4];
+                  if (argc >= 6) {
+                     errno = 0;
+                     dbport = strtol(argv[5], &endptr, 10);
+                     if (*endptr != '\0') {
+                        Pmsg0(0, _("Database port must be a numeric value.\n"));
+                        exit(1);
+                     } else if (errno == ERANGE) {
+                        Pmsg0(0, _("Database port must be a int value.\n"));
+                        exit(1);
+                     }
+                     if (argc >= 7) {
+                        dbsslkey = argv[6];
+                        dbsslcert = argv[7];
+                        if (argc == 9) {
+                           dbsslca = argv[8];
+                        } /* if (argc == 9) */
+                     } /* if (argc >= 7) */
+                  } /* if (argc >= 6) */
+               } /* if (argc >= 5) */
+            } /* if (argc >= 4) */
+         } /* if (argc >= 3) */
+      } /* if (argc >= 2) */
    }
 
    /*
     * Open database
     */
-   db = db_init_database(NULL, NULL, db_name, user, password, dbhost, dbport, NULL, false, false);
+   db = db_init_database(NULL, NULL, db_name, user, password, dbhost, dbport, NULL, dbsslkey, dbsslcert, dbsslca, dbsslcapath, dbsslcipher, false, false);
    if (!db || !db_open_database(NULL, db)) {
       Emsg1(M_FATAL, 0, "%s", db_strerror(db));
           return 1;
@@ -337,6 +345,8 @@ static void print_catalog_details(CAT *catalog, const char *working_dir)
    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_capath, catalog->db_ssl_cipher,
                          catalog->mult_db_connections,
                          catalog->disable_batch_insert);
    if (db) {