From b71a4d4e0ac2d37afb73b72db5eb3278369d372a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 20 Aug 2003 16:28:38 +0000 Subject: [PATCH] Fix segfault in mysql.c with no password git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@671 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 5 +++ bacula/src/cats/mysql.c | 8 +++- bacula/src/dird/dird.c | 91 ++++++++++++++++++++------------------- bacula/src/dird/job.c | 8 +++- bacula/src/dird/ua_cmds.c | 9 ++-- bacula/src/lib/util.c | 2 +- 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index f527d2a149..8741962f97 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -27,6 +27,11 @@ Testing to do: (painful) - Figure out how to use ssh or stunnel to protect Bacula communications. For 1.32: +- Enhance autochanger interface to include a "scan" feature + scan 1; scan 1-5; scan 1,2,4 ... to update the catalog + when the magazine is changed. +- Make things like list where a file is saved case independent for + Windows. - Edit the Client/Storage name into authentication failure messages. - Implement job in VerifyToCatalog - Implement migrate diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 7f8891acf1..98ec7d88e7 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -61,6 +61,10 @@ db_init_database(JCR *jcr, char *db_name, char *db_user, char *db_password, { B_DB *mdb; + if (!db_user) { + Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n")); + return NULL; + } P(mutex); /* lock DB queue */ /* Look to see if DB already open */ for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) { @@ -76,7 +80,9 @@ db_init_database(JCR *jcr, char *db_name, char *db_user, char *db_password, memset(mdb, 0, sizeof(B_DB)); mdb->db_name = bstrdup(db_name); mdb->db_user = bstrdup(db_user); - mdb->db_password = bstrdup(db_password); + if (db_password) { + mdb->db_password = bstrdup(db_password); + } if (db_address) { mdb->db_address = bstrdup(db_address); } diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index f6f0213c71..665f7fb86a 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -102,56 +102,56 @@ int main (int argc, char *argv[]) while ((ch = getopt(argc, argv, "c:d:fg:r:stu:v?")) != -1) { switch (ch) { case 'c': /* specify config file */ - if (configfile != NULL) { - free(configfile); - } - configfile = bstrdup(optarg); - break; + if (configfile != NULL) { + free(configfile); + } + configfile = bstrdup(optarg); + break; - case 'd': /* set debug level */ - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - Dmsg1(0, "Debug level = %d\n", debug_level); - break; + case 'd': /* set debug level */ + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + Dmsg1(0, "Debug level = %d\n", debug_level); + break; - case 'f': /* run in foreground */ - background = FALSE; - break; + case 'f': /* run in foreground */ + background = FALSE; + break; - case 'g': /* set group id */ - gid = optarg; - break; + case 'g': /* set group id */ + gid = optarg; + break; - case 'r': /* run job */ - if (runjob != NULL) { - free(runjob); - } - if (optarg) { - runjob = bstrdup(optarg); - } - break; + case 'r': /* run job */ + if (runjob != NULL) { + free(runjob); + } + if (optarg) { + runjob = bstrdup(optarg); + } + break; - case 's': /* turn off signals */ - no_signals = TRUE; - break; + case 's': /* turn off signals */ + no_signals = TRUE; + break; - case 't': /* test config */ - test_config = TRUE; - break; + case 't': /* test config */ + test_config = TRUE; + break; - case 'u': /* set uid */ - uid = optarg; - break; + case 'u': /* set uid */ + uid = optarg; + break; - case 'v': /* verbose */ - verbose++; - break; + case 'v': /* verbose */ + verbose++; + break; - case '?': - default: - usage(); + case '?': + default: + usage(); } } @@ -367,9 +367,12 @@ Without that I don't know who I am :-(\n"), configfile); db = db_init_database(NULL, catalog->db_name, catalog->db_user, catalog->db_password, catalog->db_address, catalog->db_port, catalog->db_socket); - if (!db_open_database(NULL, db)) { - Jmsg(NULL, M_FATAL, 0, _("Could not open %s database \"%s\".\n"), - catalog_db, catalog->db_name); + if (!db || !db_open_database(NULL, db)) { + Jmsg(NULL, M_FATAL, 0, _("Could not open database \"%s\".\n"), + catalog->db_name); + if (db) { + Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db)); + } OK = FALSE; } else { /* If a pool is defined for this job, create the pool DB diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 047b6e1117..3987beee4d 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -122,8 +122,12 @@ void run_job(JCR *jcr) jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user, jcr->catalog->db_password, jcr->catalog->db_address, jcr->catalog->db_port, jcr->catalog->db_socket); - if (!db_open_database(jcr, jcr->db)) { - Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); + if (!jcr->db || !db_open_database(jcr, jcr->db)) { + Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"), + jcr->catalog->db_name); + if (jcr->db) { + Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); + } set_jcr_job_status(jcr, JS_ErrorTerminated); free_jcr(jcr); return; diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 30788df097..3d10c87c29 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1657,9 +1657,12 @@ int open_db(UAContext *ua) ua->db = db_init_database(ua->jcr, ua->catalog->db_name, ua->catalog->db_user, ua->catalog->db_password, ua->catalog->db_address, ua->catalog->db_port, ua->catalog->db_socket); - if (!db_open_database(ua->jcr, ua->db)) { - bsendmsg(ua, _("Could not open DB %s: ERR=%s"), - ua->catalog->db_name, db_strerror(ua->db)); + if (!ua->db || !db_open_database(ua->jcr, ua->db)) { + bsendmsg(ua, _("Could not open database \"%s\".\n"), + ua->catalog->db_name); + if (ua->db) { + bsendmsg(ua, "%s", db_strerror(ua->db)); + } close_db(ua); return 0; } diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 59bb7ad69c..9c1ce536c3 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -112,7 +112,7 @@ char *encode_time(time_t time, char *buf) /* * Concatenate a string (str) onto a pool memory buffer pm */ -in pm_strcat(POOLMEM **pm, char *str) +int pm_strcat(POOLMEM **pm, char *str) { int pmlen = strlen(*pm); int len = strlen(str) + 1; -- 2.39.5