From f8421ce733169a52450bb73b037b22d00000e15a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 21 May 2007 16:29:11 +0000 Subject: [PATCH] More cleanup and converting to BSOCK class git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4867 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/authenticate.c | 67 +++++++++---------- bacula/src/dird/ua_cmds.c | 22 +++--- bacula/src/lib/bsock.c | 28 ++++---- bacula/src/lib/bsock.h | 1 + bacula/src/qt-console/bat_conf.cpp | 1 - bacula/src/qt-console/bat_conf.h | 19 ++++-- .../src/qt-console/console/authenticate.cpp | 34 +++++----- bacula/src/qt-console/console/console.cpp | 11 +-- bacula/src/tray-monitor/authenticate.c | 46 ++++++------- 9 files changed, 121 insertions(+), 108 deletions(-) diff --git a/bacula/src/dird/authenticate.c b/bacula/src/dird/authenticate.c index 23b5d5f4f5..28455cfe13 100644 --- a/bacula/src/dird/authenticate.c +++ b/bacula/src/dird/authenticate.c @@ -1,19 +1,7 @@ -/* - * - * Bacula Director -- authorize.c -- handles authorization of - * Storage and File daemons. - * - * Kern Sibbald, May MMI - * - * This routine runs as a thread and must be thread reentrant. - * - * Version $Id$ - * - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2006 Free Software Foundation Europe e.V. + Copyright (C) 2001-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. @@ -37,6 +25,18 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula Director -- authorize.c -- handles authorization of + * Storage and File daemons. + * + * Kern Sibbald, May MMI + * + * This routine runs as a thread and must be thread reentrant. + * + * Version $Id$ + * + */ #include "bacula.h" #include "dird.h" @@ -75,7 +75,7 @@ bool authenticate_storage_daemon(JCR *jcr, STORE *store) bash_spaces(dirname); /* Timeout Hello after 1 min */ btimer_t *tid = start_bsock_timer(sd, AUTH_TIMEOUT); - if (!bnet_fsend(sd, hello, dirname)) { + if (!sd->fsend(hello, dirname)) { stop_bsock_timer(tid); Dmsg1(50, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd)); Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd)); @@ -105,7 +105,7 @@ bool authenticate_storage_daemon(JCR *jcr, STORE *store) stop_bsock_timer(tid); Dmsg0(50, _("Director and Storage daemon passwords or names not the same.\n")); Jmsg2(jcr, M_FATAL, 0, - _("Director unable to authenticate with Storage daemon on \"%s:%d\". Possible causes:\n" + _("Director unable to authenticate with Storage daemon at \"%s:%d\". Possible causes:\n" "Passwords or names not the same or\n" "Maximum Concurrent Jobs exceeded on the SD or\n" "SD networking messed up (restart daemon).\n" @@ -133,24 +133,24 @@ bool authenticate_storage_daemon(JCR *jcr, STORE *store) /* Engage TLS! Full Speed Ahead! */ if (!bnet_tls_client(store->tls_ctx, sd, NULL)) { stop_bsock_timer(tid); - Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed with SD on \"%s:%d\"\n"), + Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed with SD at \"%s:%d\"\n"), sd->host(), sd->port()); return 0; } } Dmsg1(116, ">stored: %s", sd->msg); - if (bnet_recv(sd) <= 0) { + if (sd->recv() <= 0) { stop_bsock_timer(tid); Jmsg3(jcr, M_FATAL, 0, _("bdirdwho(), sd->host(), bnet_strerror(sd)); + sd->who(), sd->host(), sd->bstrerror()); return 0; } Dmsg1(110, "msg); stop_bsock_timer(tid); if (strncmp(sd->msg, OKhello, sizeof(OKhello)) != 0) { Dmsg0(50, _("Storage daemon rejected Hello command\n")); - Jmsg2(jcr, M_FATAL, 0, _("Storage daemon on \"%s:%d\" rejected Hello command\n"), + Jmsg2(jcr, M_FATAL, 0, _("Storage daemon at \"%s:%d\" rejected Hello command\n"), sd->host(), sd->port()); return 0; } @@ -175,12 +175,12 @@ int authenticate_file_daemon(JCR *jcr) */ bstrncpy(dirname, director->hdr.name, sizeof(dirname)); bash_spaces(dirname); - /* Timeout Hello after 10 mins */ + /* Timeout Hello after 1 min */ btimer_t *tid = start_bsock_timer(fd, AUTH_TIMEOUT); - if (!bnet_fsend(fd, hello, dirname)) { + if (!fd->fsend(hello, dirname)) { stop_bsock_timer(tid); - Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon on \"%s:%d\". ERR=%s\n"), - fd->host(), fd->port(), bnet_strerror(fd)); + Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon at \"%s:%d\". ERR=%s\n"), + fd->host(), fd->port(), fd->bstrerror()); return 0; } Dmsg1(50, "Sent: %s", fd->msg); @@ -207,7 +207,7 @@ int authenticate_file_daemon(JCR *jcr) stop_bsock_timer(tid); Dmsg0(50, _("Director and File daemon passwords or names not the same.\n")); Jmsg(jcr, M_FATAL, 0, - _("Unable to authenticate with File daemon on \"%s:%d\". Possible causes:\n" + _("Unable to authenticate with File daemon at \"%s:%d\". Possible causes:\n" "Passwords or names not the same or\n" "Maximum Concurrent Jobs exceeded on the FD or\n" "FD networking messed up (restart daemon).\n" @@ -227,7 +227,7 @@ int authenticate_file_daemon(JCR *jcr) /* Verify that we are willing to meet the remote host's requirements */ if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) { stop_bsock_timer(tid); - Jmsg(jcr, M_FATAL, 0, _("Authorization problem: FD on \"%s:%d\" requires TLS.\n"), + Jmsg(jcr, M_FATAL, 0, _("Authorization problem: FD at \"%s:%d\" requires TLS.\n"), fd->host(), fd->port()); return 0; } @@ -238,26 +238,26 @@ int authenticate_file_daemon(JCR *jcr) if (!bnet_tls_client(client->tls_ctx, fd, client->tls_allowed_cns)) { stop_bsock_timer(tid); - Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed with FD on \"%s:%d\".\n"), + Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed with FD at \"%s:%d\".\n"), fd->host(), fd->port()); return 0; } } Dmsg1(116, ">filed: %s", fd->msg); - if (bnet_recv(fd) <= 0) { + if (fd->recv() <= 0) { stop_bsock_timer(tid); Dmsg1(50, _("Bad response from File daemon to Hello command: ERR=%s\n"), bnet_strerror(fd)); - Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon on \"%s:%d\" to Hello command: ERR=%s\n"), - fd->host(), fd->port(), bnet_strerror(fd)); + Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon at \"%s:%d\" to Hello command: ERR=%s\n"), + fd->host(), fd->port(), fd->bstrerror()); return 0; } Dmsg1(110, "msg); stop_bsock_timer(tid); if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)) != 0) { Dmsg0(50, _("File daemon rejected Hello command\n")); - Jmsg(jcr, M_FATAL, 0, _("File daemon on \"%s:%d\" rejected Hello command\n"), + Jmsg(jcr, M_FATAL, 0, _("File daemon at \"%s:%d\" rejected Hello command\n"), fd->host(), fd->port()); return 0; } @@ -279,9 +279,6 @@ int authenticate_user_agent(UAContext *uac) TLS_CONTEXT *tls_ctx = NULL; alist *verify_list = NULL; - -// Emsg4(M_INFO, 0, _("UA Hello from %s:%s:%d is invalid. Len=%d\n"), ua->who(), -// ua->host(), ua->port(), ua->msglen); if (ua->msglen < 16 || ua->msglen >= MAX_NAME_LENGTH + 15) { Emsg4(M_ERROR, 0, _("UA Hello from %s:%s:%d is invalid. Len=%d\n"), ua->who(), ua->host(), ua->port(), ua->msglen); @@ -378,12 +375,12 @@ int authenticate_user_agent(UAContext *uac) /* Authorization Completed */ auth_done: if (!auth_success) { - bnet_fsend(ua, "%s", _(Dir_sorry)); + ua->fsend("%s", _(Dir_sorry)); Emsg4(M_ERROR, 0, _("Unable to authenticate console \"%s\" at %s:%s:%d.\n"), name, ua->who(), ua->host(), ua->port()); sleep(5); return 0; } - bnet_fsend(ua, _("1000 OK: %s Version: %s (%s)\n"), my_name, VERSION, BDATE); + ua->fsend(_("1000 OK: %s Version: %s (%s)\n"), my_name, VERSION, BDATE); return 1; } diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 666bc6ef61..fa983bb370 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -700,7 +700,7 @@ static int setip_cmd(UAContext *ua, const char *cmd) return 1; } LockRes(); - client = (CLIENT *)GetResWithName(R_CLIENT, ua->cons->name()); + client = GetClientResWithName(ua->cons->name()); if (!client) { ua->error_msg(_("Client \"%s\" not found.\n"), ua->cons->name()); @@ -733,7 +733,7 @@ static void do_en_disable_cmd(UAContext *ua, bool setting) } } else { LockRes(); - job = (JOB *)GetResWithName(R_JOB, ua->argv[i]); + job = GetJobResWithName(ua->argv[i]); UnlockRes(); } if (!job) { @@ -949,7 +949,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd) strcasecmp(ua->argk[i], "fd") == 0) { client = NULL; if (ua->argv[i]) { - client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); + client = GetClientResWithName(ua->argv[i]); if (client) { do_client_setdebug(ua, client, level, trace_flag); return 1; @@ -967,7 +967,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd) strcasecmp(ua->argk[i], NT_("sd")) == 0) { store = NULL; if (ua->argv[i]) { - store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]); + store = GetStoreResWithName(ua->argv[i]); if (store) { do_storage_setdebug(ua, store, level, trace_flag); return 1; @@ -1071,13 +1071,13 @@ static int estimate_cmd(UAContext *ua, const char *cmd) if (strcasecmp(ua->argk[i], NT_("client")) == 0 || strcasecmp(ua->argk[i], NT_("fd")) == 0) { if (ua->argv[i]) { - client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); + client = GetClientResWithName(ua->argv[i]); continue; } } if (strcasecmp(ua->argk[i], NT_("job")) == 0) { if (ua->argv[i]) { - job = (JOB *)GetResWithName(R_JOB, ua->argv[i]); + job = GetJobResWithName(ua->argv[i]); if (job && !acl_access_ok(ua, Job_ACL, job->name())) { ua->error_msg(_("No authorization for Job \"%s\"\n"), job->name()); return 1; @@ -1087,7 +1087,7 @@ static int estimate_cmd(UAContext *ua, const char *cmd) } if (strcasecmp(ua->argk[i], NT_("fileset")) == 0) { if (ua->argv[i]) { - fileset = (FILESET *)GetResWithName(R_FILESET, ua->argv[i]); + fileset = GetFileSetResWithName(ua->argv[i]); if (fileset && !acl_access_ok(ua, FileSet_ACL, fileset->name())) { ua->error_msg(_("No authorization for FileSet \"%s\"\n"), fileset->name()); return 1; @@ -1112,7 +1112,7 @@ static int estimate_cmd(UAContext *ua, const char *cmd) } } if (!job) { - job = (JOB *)GetResWithName(R_JOB, ua->argk[1]); + job = GetJobResWithName(ua->argk[1]); if (!job) { ua->error_msg(_("No job specified.\n")); return 1; @@ -1724,7 +1724,7 @@ bool open_client_db(UAContext *ua) ua->error_msg(_("No authorization for Catalog \"%s\"\n"), ua->argv[i]); return false; } - catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]); + catalog = GetCatalogResWithName(ua->argv[i]); if (catalog) { if (ua->catalog && ua->catalog != catalog) { close_db(ua); @@ -1741,7 +1741,7 @@ bool open_client_db(UAContext *ua) ua->error_msg(_("No authorization for Client \"%s\"\n"), ua->argv[i]); return false; } - client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); + client = GetClientResWithName(ua->argv[i]); if (client) { catalog = client->catalog; if (ua->catalog && ua->catalog != catalog) { @@ -1763,7 +1763,7 @@ bool open_client_db(UAContext *ua) ua->error_msg(_("No authorization for Job \"%s\"\n"), ua->argv[i]); return false; } - job = (JOB *)GetResWithName(R_JOB, ua->argv[i]); + job = GetJobResWithName(ua->argv[i]); if (job) { catalog = job->client->catalog; if (ua->catalog && ua->catalog != catalog) { diff --git a/bacula/src/lib/bsock.c b/bacula/src/lib/bsock.c index 6ed339a996..87ea2e5aca 100644 --- a/bacula/src/lib/bsock.c +++ b/bacula/src/lib/bsock.c @@ -490,7 +490,7 @@ bool BSOCK::despool(void update_attr_spool_size(ssize_t size), ssize_t tsize) if (nbytes != (size_t) msglen) { berrno be; Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, msglen); - Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), + Qmsg1(get_jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), be.bstrerror()); update_attr_spool_size(tsize - last); return false; @@ -506,7 +506,7 @@ bool BSOCK::despool(void update_attr_spool_size(ssize_t size), ssize_t tsize) update_attr_spool_size(tsize - last); if (ferror(m_spool_fd)) { berrno be; - Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), + Qmsg1(get_jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), be.bstrerror()); return false; } @@ -567,23 +567,23 @@ bool BSOCK::set_buffer_size(uint32_t size, int rw) } start_size = dbuf_size; if ((msg = realloc_pool_memory(msg, dbuf_size + 100)) == NULL) { - Qmsg0(jcr(), M_FATAL, 0, _("Could not malloc BSOCK data buffer\n")); + Qmsg0(get_jcr(), M_FATAL, 0, _("Could not malloc BSOCK data buffer\n")); return false; } if (rw & BNET_SETBUF_READ) { while ((dbuf_size > TAPE_BSIZE) && (setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) { berrno be; - Qmsg1(jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.bstrerror()); + Qmsg1(get_jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.bstrerror()); dbuf_size -= TAPE_BSIZE; } Dmsg1(200, "set network buffer size=%d\n", dbuf_size); if (dbuf_size != start_size) { - Qmsg1(jcr(), M_WARNING, 0, + Qmsg1(get_jcr(), M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size); } if (dbuf_size % TAPE_BSIZE != 0) { - Qmsg1(jcr(), M_ABORT, 0, + Qmsg1(get_jcr(), M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"), dbuf_size); } @@ -598,16 +598,16 @@ bool BSOCK::set_buffer_size(uint32_t size, int rw) while ((dbuf_size > TAPE_BSIZE) && (setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) { berrno be; - Qmsg1(jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.bstrerror()); + Qmsg1(get_jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.bstrerror()); dbuf_size -= TAPE_BSIZE; } Dmsg1(900, "set network buffer size=%d\n", dbuf_size); if (dbuf_size != start_size) { - Qmsg1(jcr(), M_WARNING, 0, + Qmsg1(get_jcr(), M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size); } if (dbuf_size % TAPE_BSIZE != 0) { - Qmsg1(jcr(), M_ABORT, 0, + Qmsg1(get_jcr(), M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"), dbuf_size); } @@ -629,13 +629,13 @@ int BSOCK::set_nonblocking() /* Get current flags */ if ((oflags = fcntl(m_fd, F_GETFL, 0)) < 0) { berrno be; - Jmsg1(jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.bstrerror()); + Jmsg1(get_jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.bstrerror()); } /* Set O_NONBLOCK flag */ if ((fcntl(m_fd, F_SETFL, oflags|O_NONBLOCK)) < 0) { berrno be; - Jmsg1(jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror()); + Jmsg1(get_jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror()); } m_blocking = 0; @@ -663,13 +663,13 @@ int BSOCK::set_blocking() /* Get current flags */ if ((oflags = fcntl(m_fd, F_GETFL, 0)) < 0) { berrno be; - Jmsg1(jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.bstrerror()); + Jmsg1(get_jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.bstrerror()); } /* Set O_NONBLOCK flag */ if ((fcntl(m_fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) { berrno be; - Jmsg1(jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror()); + Jmsg1(get_jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror()); } m_blocking = 1; @@ -694,7 +694,7 @@ void BSOCK::restore_blocking (int flags) #ifndef HAVE_WIN32 if ((fcntl(m_fd, F_SETFL, flags)) < 0) { berrno be; - Jmsg1(jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror()); + Jmsg1(get_jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror()); } m_blocking = (flags & O_NONBLOCK) ? true : false; diff --git a/bacula/src/lib/bsock.h b/bacula/src/lib/bsock.h index 974db66070..2bf6a7f38e 100644 --- a/bacula/src/lib/bsock.h +++ b/bacula/src/lib/bsock.h @@ -108,6 +108,7 @@ public: char *host() { return m_host; }; int port() { return m_port; }; JCR *jcr() { return m_jcr; }; + JCR *get_jcr() { return m_jcr; }; bool is_terminated() { return m_terminated; }; bool is_timed_out() { return m_timed_out; }; void set_terminated() { m_terminated = true; }; diff --git a/bacula/src/qt-console/bat_conf.cpp b/bacula/src/qt-console/bat_conf.cpp index 29f2489068..c098847f8f 100644 --- a/bacula/src/qt-console/bat_conf.cpp +++ b/bacula/src/qt-console/bat_conf.cpp @@ -110,7 +110,6 @@ static RES_ITEM con_font_items[] = { {"name", store_name, ITEM(con_font.hdr.name), 0, ITEM_REQUIRED, 0}, {"description", store_str, ITEM(con_font.hdr.desc), 0, 0, 0}, {"font", store_str, ITEM(con_font.fontface), 0, 0, 0}, - {"requiressl", store_bit, ITEM(con_font.require_ssl), 1, ITEM_DEFAULT, 0}, {NULL, NULL, {0}, 0, 0, 0} }; diff --git a/bacula/src/qt-console/bat_conf.h b/bacula/src/qt-console/bat_conf.h index 34020550e6..e0e96d7d31 100644 --- a/bacula/src/qt-console/bat_conf.h +++ b/bacula/src/qt-console/bat_conf.h @@ -61,7 +61,8 @@ enum { /* Definition of the contents of each Resource */ -struct DIRRES { +class DIRRES { +public: RES hdr; int DIRport; /* UA server port */ char *address; /* UA server address */ @@ -82,13 +83,14 @@ struct DIRRES { inline char *DIRRES::name() const { return hdr.name; } + struct CONFONTRES { RES hdr; char *fontface; /* Console Font specification */ - int require_ssl; /* Require SSL on all connections */ }; -struct CONRES { +class CONRES { +public: RES hdr; char *password; /* UA server password */ int tls_enable; /* Enable TLS on all connections */ @@ -97,11 +99,16 @@ struct CONRES { char *tls_ca_certdir; /* TLS CA Certificate Directory */ char *tls_certfile; /* TLS Client Certificate File */ char *tls_keyfile; /* TLS Client Key File */ - utime_t heartbeat_interval; /* Dir heartbeat interval */ + utime_t heartbeat_interval; /* Cons heartbeat interval */ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ + + /* Methods */ + char *name() const; }; +inline char *CONRES::name() const { return hdr.name; } + /* Define the Union of all the above * resource structure definitions. @@ -115,4 +122,8 @@ union u_res { typedef union u_res URES; +#define GetConsoleResWithName(x) ((CONRES *)GetResWithName(R_CONSOLE, (x))) +#define GetDirResWithName(x) ((DIRRES *)GetResWithName(R_DIRECTOR, (x))) + + #endif /* _BAT_CONF_H_ */ diff --git a/bacula/src/qt-console/console/authenticate.cpp b/bacula/src/qt-console/console/authenticate.cpp index 7ef47a1431..566718865f 100644 --- a/bacula/src/qt-console/console/authenticate.cpp +++ b/bacula/src/qt-console/console/authenticate.cpp @@ -101,22 +101,25 @@ bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons) if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) || /* Now challenge dir */ !cram_md5_challenge(dir, password, tls_local_need, compatible)) { - printf(_("%s: Director authorization problem.\n"), my_name); - display_text(_("Director authorization problem.\n")); + display_textf(_("Director authorization problem at \"%s:%d\"\n"), + dir->host(), dir->port()); goto bail_out; } /* Verify that the remote host is willing to meet our TLS requirements */ if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) { - display_text(_("Authorization problem:" - " Remote server did not advertise required TLS support.\n")); + display_textf(_("Authorization problem:" + " Remote server at \"%s:%d\" did not advertise required TLS support.\n"), + dir->host(), dir->port()); goto bail_out; } /* Verify that we are willing to meet the remote host's requirements */ if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) { - display_text(_("Authorization problem:" - " Remote server requires TLS.\n")); + display_textf(_("Authorization problem with Director at \"%s:%d\":" + " Remote server requires TLS.\n"), + dir->host(), dir->port()); + goto bail_out; } @@ -125,7 +128,8 @@ bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons) if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) { /* Engage TLS! Full Speed Ahead! */ if (!bnet_tls_client(tls_ctx, dir, NULL)) { - display_text(_("TLS negotiation failed\n")); + display_textf(_("TLS negotiation failed with Director at \"%s:%d\"\n"), + dir->host(), dir->port()); goto bail_out; } } @@ -134,18 +138,17 @@ bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons) Dmsg1(6, ">dird: %s", dir->msg); if (dir->recv() <= 0) { stop_bsock_timer(tid); - display_textf(_("Bad response to Hello command: ERR=%s\n"), - dir->bstrerror()); - printf(_("%s: Bad response to Hello command: ERR=%s\n"), - my_name, dir->bstrerror()); - display_text(_("The Director is probably not running.\n")); + display_textf(_("Bad response to Hello command: ERR=%s\n" + "The Director at \"%s:%d\" is probably not running.\n"), + dir->bstrerror(), dir->host(), dir->port()); return false; } stop_bsock_timer(tid); Dmsg1(10, "msg); if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) { - display_text(_("Director rejected Hello command\n")); + display_textf(_("Director at \"%s:%d\" rejected Hello command\n"), + dir->host(), dir->port()); return false; } else { display_text(dir->msg); @@ -154,9 +157,10 @@ bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons) bail_out: stop_bsock_timer(tid); - display_text(_("Director authorization problem.\n" + display_textf(_("Authorization problem with Director at \"%s:%d\"\n" "Most likely the passwords do not agree.\n" "If you are using TLS, there may have been a certificate validation error during the TLS handshake.\n" - "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n")); + "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"), + dir->host(), dir->port()); return false; } diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 168ef97823..c7ab58d7ce 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -119,14 +119,15 @@ void Console::connect() LockRes(); /* If cons==NULL, default console will be used */ - CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL); + CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, NULL); UnlockRes(); char buf[1024]; /* Initialize Console TLS context */ if (cons && (cons->tls_enable || cons->tls_require)) { /* Generate passphrase prompt */ - bsnprintf(buf, sizeof(buf), "Passphrase for Console \"%s\" TLS private key: ", cons->hdr.name); + bsnprintf(buf, sizeof(buf), "Passphrase for Console \"%s\" TLS private key: ", + cons->name()); /* Initialize TLS context: * Args: CA certfile, CA certdir, Certfile, Keyfile, @@ -138,7 +139,7 @@ void Console::connect() if (!cons->tls_ctx) { display_textf(_("Failed to initialize TLS context for Console \"%s\".\n"), - m_dir->hdr.name); + m_dir->name()); return; } } @@ -147,7 +148,7 @@ void Console::connect() if (m_dir->tls_enable || m_dir->tls_require) { /* Generate passphrase prompt */ bsnprintf(buf, sizeof(buf), "Passphrase for Director \"%s\" TLS private key: ", - m_dir->hdr.name); + m_dir->name()); /* Initialize TLS context: * Args: CA certfile, CA certdir, Certfile, Keyfile, @@ -158,7 +159,7 @@ void Console::connect() if (!m_dir->tls_ctx) { display_textf(_("Failed to initialize TLS context for Director \"%s\".\n"), - m_dir->hdr.name); + m_dir->name()); mainWin->set_status("Connection failed"); return; } diff --git a/bacula/src/tray-monitor/authenticate.c b/bacula/src/tray-monitor/authenticate.c index f4a936bc5f..11afefe162 100644 --- a/bacula/src/tray-monitor/authenticate.c +++ b/bacula/src/tray-monitor/authenticate.c @@ -1,19 +1,7 @@ -/* - * - * Bacula authentication. Provides authentication with - * File and Storage daemons. - * - * Nicolas Boichat, August MMIV - * - * This routine runs as a thread and must be thread reentrant. - * - * Basic tasks done here: - * - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2006 Free Software Foundation Europe e.V. + Copyright (C) 2004-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. @@ -37,6 +25,18 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula authentication. Provides authentication with + * File and Storage daemons. + * + * Nicolas Boichat, August MMIV + * + * This routine runs as a thread and must be thread reentrant. + * + * Basic tasks done here: + * + */ #include "bacula.h" #include "tray-monitor.h" @@ -80,7 +80,7 @@ int authenticate_director(JCR *jcr, MONITOR *mon, DIRRES *director) /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(dir, 60 * 5); - bnet_fsend(dir, DIRhello, bashed_name); + dir->fsend(DIRhello, bashed_name); if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) || !cram_md5_challenge(dir, password, tls_local_need, compatible)) { @@ -92,10 +92,10 @@ int authenticate_director(JCR *jcr, MONITOR *mon, DIRRES *director) } Dmsg1(6, ">dird: %s", dir->msg); - if (bnet_recv(dir) <= 0) { + if (dir->recv() <= 0) { stop_bsock_timer(tid); Jmsg1(jcr, M_FATAL, 0, _("Bad response to Hello command: ERR=%s\n"), - bnet_strerror(dir)); + dir->bstrerror()); return 0; } Dmsg1(10, "msg); @@ -104,7 +104,7 @@ int authenticate_director(JCR *jcr, MONITOR *mon, DIRRES *director) Jmsg0(jcr, M_FATAL, 0, _("Director rejected Hello command\n")); return 0; } else { - Jmsg0(jcr, M_FATAL, 0, dir->msg); + Jmsg0(jcr, M_INFO, 0, dir->msg); } return 1; } @@ -127,7 +127,7 @@ int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store) bash_spaces(dirname); /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(sd, 60 * 5); - if (!bnet_fsend(sd, SDFDhello, dirname)) { + if (!sd->fsend(SDFDhello, dirname)) { stop_bsock_timer(tid); Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd)); return 0; @@ -140,10 +140,10 @@ int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store) return 0; } Dmsg1(116, ">stored: %s", sd->msg); - if (bnet_recv(sd) <= 0) { + if (sd->recv() <= 0) { stop_bsock_timer(tid); Jmsg1(jcr, M_FATAL, 0, _("bdirdbstrerror()); return 0; } Dmsg1(110, "msg); @@ -173,7 +173,7 @@ int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client) bash_spaces(dirname); /* Timeout Hello after 5 mins */ btimer_t *tid = start_bsock_timer(fd, 60 * 5); - if (!bnet_fsend(fd, SDFDhello, dirname)) { + if (!fd->fsend(SDFDhello, dirname)) { stop_bsock_timer(tid); Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd)); return 0; @@ -186,10 +186,10 @@ int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client) return 0; } Dmsg1(116, ">filed: %s", fd->msg); - if (bnet_recv(fd) <= 0) { + if (fd->recv() <= 0) { stop_bsock_timer(tid); Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"), - bnet_strerror(fd)); + fd->bstrerror()); return 0; } Dmsg1(110, "msg); -- 2.39.5