From 087e37d1fb04e1db27a5e85d371ba836755fe3fe Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 15 Jan 2004 14:03:43 +0000 Subject: [PATCH] Implement first cut of multiple consoles git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1012 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/console/authenticate.c | 7 +++-- bacula/src/console/console.c | 14 ++++++++-- bacula/src/console/console_conf.c | 2 +- bacula/src/console/console_conf.h | 44 +++++++++++++++---------------- bacula/src/dird/authenticate.c | 28 +++++++++++++------- 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/bacula/src/console/authenticate.c b/bacula/src/console/authenticate.c index ef679da182..b6f0726a4c 100644 --- a/bacula/src/console/authenticate.c +++ b/bacula/src/console/authenticate.c @@ -47,15 +47,18 @@ static char OKhello[] = "1000 OK:"; /* * Authenticate Director */ -int authenticate_director(JCR *jcr, DIRRES *director) +int authenticate_director(JCR *jcr, DIRRES *director, char *name) { BSOCK *dir = jcr->dir_bsock; int ssl_need = BNET_SSL_NONE; + char bashed_name[MAX_NAME_LENGTH]; /* * Send my name to the Director then do authentication */ - bnet_fsend(dir, hello, "UserAgent"); + bstrncpy(bashed_name, name, sizeof(bashed_name)); + bash_spaces(bashed_name); + bnet_fsend(dir, hello, bashed_name); if (!cram_md5_get_auth(dir, director->password, ssl_need) || !cram_md5_auth(dir, director->password, ssl_need)) { diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 51f49961d0..b59e601eba 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -51,7 +51,7 @@ extern int rl_catch_signals; #endif /* Imported functions */ -int authenticate_director(JCR *jcr, DIRRES *director); +int authenticate_director(JCR *jcr, DIRRES *director, char *name); @@ -398,7 +398,17 @@ try_again: return 1; } jcr.dir_bsock = UA_sock; - if (!authenticate_director(&jcr, dir)) { + + LockRes(); + CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL); + UnlockRes(); + char *con_name; + if (cons) { + con_name = cons->hdr.name; + } else { + con_name = "*UserAgent*"; + } + if (!authenticate_director(&jcr, dir, con_name)) { fprintf(stderr, "ERR=%s", UA_sock->msg); terminate_console(0); return 1; diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index f69975c2d2..ef7eb49399 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -235,7 +235,7 @@ void save_resource(int type, struct res_items *items, int pass) /* The following code is only executed during pass 1 */ switch (type) { case R_CONSOLE: - size = sizeof(CONSRES); + size = sizeof(CONRES); break; case R_DIRECTOR: size = sizeof(DIRRES); diff --git a/bacula/src/console/console_conf.h b/bacula/src/console/console_conf.h index 7326b55bfe..e01c21bf78 100644 --- a/bacula/src/console/console_conf.h +++ b/bacula/src/console/console_conf.h @@ -9,41 +9,41 @@ /* * Resource codes -- they must be sequential for indexing */ -#define R_FIRST 1001 +#define R_FIRST 1001 -#define R_CONSOLE 1001 -#define R_DIRECTOR 1002 +#define R_CONSOLE 1001 +#define R_DIRECTOR 1002 -#define R_LAST R_DIRECTOR +#define R_LAST R_DIRECTOR /* * Some resource attributes */ -#define R_NAME 1020 -#define R_ADDRESS 1021 -#define R_PASSWORD 1022 -#define R_TYPE 1023 -#define R_BACKUP 1024 +#define R_NAME 1020 +#define R_ADDRESS 1021 +#define R_PASSWORD 1022 +#define R_TYPE 1023 +#define R_BACKUP 1024 /* Definition of the contents of each Resource */ /* Console "globals" */ -struct s_res_cons { - RES hdr; - char *rc_file; /* startup file */ - char *hist_file; /* command history file */ - int require_ssl; /* Require SSL on all connections */ +struct s_res_con { + RES hdr; + char *rc_file; /* startup file */ + char *hist_file; /* command history file */ + int require_ssl; /* Require SSL on all connections */ }; -typedef struct s_res_cons CONSRES; +typedef struct s_res_con CONRES; /* Director */ struct s_res_dir { - RES hdr; - int DIRport; /* UA server port */ - char *address; /* UA server address */ - char *password; /* UA server password */ - int enable_ssl; /* Use SSL */ + RES hdr; + int DIRport; /* UA server port */ + char *address; /* UA server address */ + char *password; /* UA server password */ + int enable_ssl; /* Use SSL */ }; typedef struct s_res_dir DIRRES; @@ -52,8 +52,8 @@ typedef struct s_res_dir DIRRES; * resource structure definitions. */ union u_res { - struct s_res_dir res_dir; - struct s_res_cons res_cons; + struct s_res_dir res_dir; + struct s_res_con res_cons; RES hdr; }; diff --git a/bacula/src/dird/authenticate.c b/bacula/src/dird/authenticate.c index 9ec6d81bf1..9dacdb6d87 100644 --- a/bacula/src/dird/authenticate.c +++ b/bacula/src/dird/authenticate.c @@ -128,11 +128,11 @@ int authenticate_file_daemon(JCR *jcr) */ int authenticate_user_agent(BSOCK *ua) { - char name[MAXSTRING]; + char name[MAX_NAME_LENGTH]; int ssl_need = BNET_SSL_NONE; - int ok; + bool ok; - if (ua->msglen < 16 || ua->msglen >= MAXSTRING-1) { + if (ua->msglen < 16 || ua->msglen >= MAX_NAME_LENGTH + 15) { Emsg2(M_ERROR, 0, _("UA Hello from %s is invalid. Len=%d\n"), ua->who, ua->msglen); return 0; @@ -144,14 +144,24 @@ int authenticate_user_agent(BSOCK *ua) ua->msg); return 0; } - - ok = cram_md5_auth(ua, director->password, ssl_need) && - cram_md5_get_auth(ua, director->password, ssl_need); - + name[MAXSTRING-1] = 0; /* terminate name */ + if (strcmp(name, "*UserAgent*") == 0) { /* default console */ + ok = cram_md5_auth(ua, director->password, ssl_need) && + cram_md5_get_auth(ua, director->password, ssl_need); + } else { + unbash_spaces(name); + CONRES *cons = (CONRES *)GetResWithName(R_CONSOLE, name); + if (cons) { + ok = cram_md5_auth(ua, cons->password, ssl_need) && + cram_md5_get_auth(ua, cons->password, ssl_need); + } else { + ok = false; + } + } if (!ok) { bnet_fsend(ua, "%s", _(Dir_sorry)); - Emsg1(M_WARNING, 0, _("Unable to authenticate User Agent at %s.\n"), - ua->who); + Emsg2(M_ERROR, 0, _("Unable to authenticate User Agent \"%s\" at %s.\n"), + name, ua->who); sleep(5); return 0; } -- 2.39.5