From: Eric Bollengier Date: Thu, 12 Aug 2021 09:47:15 +0000 (+0200) Subject: Add Plugin field in SQL Client table X-Git-Tag: Beta-15.0.0~918 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f6ee1083e3948a2c868999036a28e211e9d9fab;p=thirdparty%2Fbacula.git Add Plugin field in SQL Client table --- diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index fdf283ba2..9d9392f98 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -470,6 +470,12 @@ public: bool set_label_date; }; +#define MAX_UNAME_LENGTH 256 +#define MAX_ESCAPE_UNAME_LENGTH MAX_UNAME_LENGTH*2+1 + +#define MAX_PLUGIN_LENGTH 1024 +#define MAX_ESCAPE_PLUGIN_LENGTH MAX_PLUGIN_LENGTH*2+1 + /* Client record -- same as the database */ struct CLIENT_DBR { DBId_t ClientId; /* Unique Client id */ @@ -477,7 +483,8 @@ struct CLIENT_DBR { utime_t FileRetention; utime_t JobRetention; char Name[MAX_NAME_LENGTH]; /* Client name */ - char Uname[256]; /* Uname for client */ + char Uname[MAX_UNAME_LENGTH]; /* Uname for client */ + char Plugin[MAX_PLUGIN_LENGTH]; /* Plugin list for this client */ }; /* Counter record as in database */ diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index 253381bf7..dcecfff92 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -418,6 +418,7 @@ CREATE TABLE Client ( ClientId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, Name TINYBLOB NOT NULL, Uname TINYBLOB NOT NULL, /* full uname -a of client */ + Plugin TINYBLOB DEFAULT '', AutoPrune TINYINT DEFAULT 0, FileRetention BIGINT UNSIGNED DEFAULT 0, JobRetention BIGINT UNSIGNED DEFAULT 0, diff --git a/bacula/src/cats/make_postgresql_tables.in b/bacula/src/cats/make_postgresql_tables.in index 0000d349a..ade6969d1 100644 --- a/bacula/src/cats/make_postgresql_tables.in +++ b/bacula/src/cats/make_postgresql_tables.in @@ -381,6 +381,7 @@ CREATE TABLE client clientid serial not null, name text not null, uname text not null, + plugin text default '', autoprune smallint default 0, fileretention bigint default 0, jobretention bigint default 0, diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index ce111abeb..d8f4ad16c 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -110,7 +110,7 @@ void BDB::bdb_list_client_records(JCR *jcr, DB_LIST_HANDLER *sendit, void *ctx, { bdb_lock(); if (type == VERT_LIST || type == JSON_LIST) { - Mmsg(cmd, "SELECT ClientId,Name,Uname,AutoPrune,FileRetention," + Mmsg(cmd, "SELECT ClientId,Name,Uname,Plugin,AutoPrune,FileRetention," "JobRetention " "FROM Client %s ORDER BY ClientId", get_acls(DB_ACL_BIT(DB_ACL_RBCLIENT), true)); } else { diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index efb919cd2..af93c7459 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -204,7 +204,8 @@ int BDB::bdb_update_client_record(JCR *jcr, CLIENT_DBR *cr) int stat; char ed1[50], ed2[50]; char esc_name[MAX_ESCAPE_NAME_LENGTH]; - char esc_uname[MAX_ESCAPE_NAME_LENGTH]; + char esc_uname[MAX_ESCAPE_UNAME_LENGTH]; + char esc_plugin[MAX_ESCAPE_PLUGIN_LENGTH]; CLIENT_DBR tcr; bdb_lock(); @@ -216,13 +217,15 @@ int BDB::bdb_update_client_record(JCR *jcr, CLIENT_DBR *cr) bdb_escape_string(jcr, esc_name, cr->Name, strlen(cr->Name)); bdb_escape_string(jcr, esc_uname, cr->Uname, strlen(cr->Uname)); + bdb_escape_string(jcr, esc_plugin, cr->Plugin, strlen(cr->Plugin)); + Mmsg(cmd, "UPDATE Client SET AutoPrune=%d,FileRetention=%s,JobRetention=%s," -"Uname='%s' WHERE Name='%s'", +"Uname='%s',Plugin='%s' WHERE Name='%s'", cr->AutoPrune, edit_uint64(cr->FileRetention, ed1), edit_uint64(cr->JobRetention, ed2), - esc_uname, esc_name); + esc_uname, esc_plugin, esc_name); stat = UpdateDB(jcr, cmd, false); bdb_unlock(); diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index a42b17232..7e57b759b 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -194,7 +194,15 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, cr.AutoPrune = jcr->client->AutoPrune; cr.FileRetention = jcr->client->FileRetention; cr.JobRetention = jcr->client->JobRetention; + + /* information about plugins can be found after the Uname */ + char *pos = strchr(fd->msg+strlen(OKjob)+1, ';'); + if (pos) { + *pos = 0; + bstrncpy(cr.Plugin, pos+1, sizeof(cr.Plugin)); + } bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname)); + if (!db_update_client_record(jcr, jcr->db, &cr)) { Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"), db_strerror(jcr->db)); diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 5c115f36e..40a75867c 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -515,7 +515,7 @@ void list_dir_status_header(UAContext *ua) POOL_MEM msg(PM_FNAME); pm_strcpy(msg, " Plugin: "); foreach_alist(plugin, b_plugin_list) { - len = pm_strcat(msg, plugin->file); + len = pm_strcat(msg, plugin->name); if (len > 80) { pm_strcat(msg, "\n "); } else { diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index f6b2c2773..5d05c734b 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -198,7 +198,7 @@ static char OKrestore[] = "2000 OK restore\n"; static char OKsession[] = "2000 OK session\n"; static char OKstore[] = "2000 OK storage\n"; static char OKstoreend[] = "2000 OK storage end\n"; -static char OKjob[] = "2000 OK Job %s (%s) %s,%s,%s"; +static char OKjob[] = "2000 OK Job %s (%s) %s,%s,%s;%s"; static char OKsetdebug[] = "2000 OK setdebug=%ld trace=%d hangup=%d" " blowup=%d options=%s tags=%s\n"; static char BADjob[] = "2901 Bad Job\n"; @@ -1097,10 +1097,30 @@ static int job_cmd(JCR *jcr) Mmsg(jcr->errmsg, "JobId=%d Job=%s", jcr->JobId, jcr->Job); new_plugins(jcr); /* instantiate plugins for this jcr */ generate_plugin_event(jcr, bEventJobStart, (void *)jcr->errmsg); + + POOL_MEM msg; + if (b_plugin_list) { + bool first=true; + Plugin *plugin; + foreach_alist(plugin, b_plugin_list) { + if (!first) { + pm_strcat(msg, ","); + } + first = false; + pm_strcat(msg, plugin->name); + if (plugin->pinfo) { + pInfo *info = (pInfo *)plugin->pinfo; + pm_strcat(msg, "("); + pm_strcat(msg, NPRT(info->plugin_version)); + pm_strcat(msg, ")"); + } + } + } + #ifdef HAVE_WIN32 - return dir->fsend(OKjob, VERSION, LSMDATE, win_os, DISTNAME, DISTVER); + return dir->fsend(OKjob, VERSION, LSMDATE, win_os, DISTNAME, DISTVER, msg.c_str()); #else - return dir->fsend(OKjob, VERSION, LSMDATE, HOST_OS, DISTNAME, DISTVER); + return dir->fsend(OKjob, VERSION, LSMDATE, HOST_OS, DISTNAME, DISTVER, msg.c_str()); #endif } diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 941ae5c25..38b32b6dd 100644 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -245,8 +245,7 @@ static void list_status_header(STATUS_PKT *sp) int len, maxlen=80; pm_strcpy(msg, " Plugin: "); foreach_alist(plugin, b_plugin_list) { - len = pm_strcat(msg, plugin->file); - /* Print plugin version when debug activated */ + len = pm_strcat(msg, plugin->name); if (plugin->pinfo) { pInfo *info = (pInfo *)plugin->pinfo; pm_strcat(msg, "("); diff --git a/bacula/src/lib/output.c b/bacula/src/lib/output.c index c34a3b077..10a75f371 100644 --- a/bacula/src/lib/output.c +++ b/bacula/src/lib/output.c @@ -266,7 +266,7 @@ char *OutputWriter::get_output(va_list ap, POOLMEM **out, OutputType first) if (i++ > 0) { pm_strcat(tmp, ","); } - pm_strcat(tmp, plug->file); + pm_strcat(tmp, plug->name); } } pm_strcat(tmp, separator_str); diff --git a/bacula/src/lib/plugins.c b/bacula/src/lib/plugins.c index f59061158..9bf35cab3 100644 --- a/bacula/src/lib/plugins.c +++ b/bacula/src/lib/plugins.c @@ -146,6 +146,8 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, plugin = new_plugin(); plugin->file = bstrdup(dname.c_str()); + dname.c_str()[len-type_len] = 0; + plugin->name = bstrdup(dname.c_str()); plugin->file_len = strstr(plugin->file, type) - plugin->file; plugin->pHandle = dlopen(fname.c_str(), RTLD_NOW); if (!plugin->pHandle) { @@ -221,6 +223,9 @@ void unload_plugins() if (plugin->file) { free(plugin->file); } + if (plugin->name) { + free(plugin->name); + } free(plugin); } delete b_plugin_list; diff --git a/bacula/src/lib/plugins.h b/bacula/src/lib/plugins.h index 07865c6fc..c56370129 100644 --- a/bacula/src/lib/plugins.h +++ b/bacula/src/lib/plugins.h @@ -71,6 +71,7 @@ typedef bRC (*t_unloadPlugin)(void); class Plugin { public: char *file; + char *name; int32_t file_len; t_unloadPlugin unloadPlugin; void *pinfo; diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index 5316cd822..4c8ac820e 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -1225,9 +1225,8 @@ static void list_plugins(STATUS_PKT *sp) Plugin *plugin; pm_strcpy(msg, " Plugin: "); foreach_alist(plugin, b_plugin_list) { - len = pm_strcat(msg, plugin->file); - /* Print plugin version when debug activated */ - if (debug_level > 0 && plugin->pinfo) { + len = pm_strcat(msg, plugin->name); + if (plugin->pinfo) { pm_strcat(msg, "("); pm_strcat(msg, NPRT(sdplug_info(plugin)->plugin_version)); len = pm_strcat(msg, ")");