]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add Plugin field in SQL Client table
authorEric Bollengier <eric@baculasystems.com>
Thu, 12 Aug 2021 09:47:15 +0000 (11:47 +0200)
committerEric Bollengier <eric@baculasystems.com>
Fri, 30 Jun 2023 16:20:05 +0000 (18:20 +0200)
13 files changed:
bacula/src/cats/cats.h
bacula/src/cats/make_mysql_tables.in
bacula/src/cats/make_postgresql_tables.in
bacula/src/cats/sql_list.c
bacula/src/cats/sql_update.c
bacula/src/dird/fd_cmds.c
bacula/src/dird/ua_status.c
bacula/src/filed/job.c
bacula/src/filed/status.c
bacula/src/lib/output.c
bacula/src/lib/plugins.c
bacula/src/lib/plugins.h
bacula/src/stored/status.c

index fdf283ba2a8eef6b28abaa87b9ac803680b154a2..9d9392f98c82e4e2df4026a6f260f2f9657c1d0a 100644 (file)
@@ -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 */
index 253381bf79f11d30263507b7a150e3478ec94c55..dcecfff924e20fdf33455e564c273d528d659d6a 100644 (file)
@@ -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,
index 0000d349a32af3ffa1b33e23da45ad23d15b15c7..ade6969d116d184a92fafc12cafc7147e415282f 100644 (file)
@@ -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,
index ce111abebcc477bf1b59c6d790834c12a13eb576..d8f4ad16c309f3bd595c5f3f36353c3871a9e4f7 100644 (file)
@@ -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 {
index efb919cd27ee0fb8670661048d8506c88340fe6a..af93c74596f6a2151fcd75424bf4b12da6ab185c 100644 (file)
@@ -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();
index a42b1723214835ee63bc178d08cf2190106ca1b7..7e57b759be52d6fe2d50a28fdc1c4a9994ac8da8 100644 (file)
@@ -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));
index 5c115f36e2c856fc6a7c5e91b6d1be08e80ab683..40a75867ca0a08cd9c2ed9993cfa2f50d61f4737 100644 (file)
@@ -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 {
index f6b2c2773cfa100ec122380b3f75c353b92a187a..5d05c734bd0b4807e60dc74ca498b54617051be2 100644 (file)
@@ -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
 }
 
index 941ae5c256dbe1111d7becd856137b3bacccde01..38b32b6dda8e97d8c8458d372ac742a0ba5b7b63 100644 (file)
@@ -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, "(");
index c34a3b0776c354c11fca4c5cbee9834d46d44c03..10a75f3710ceb328a83170ea51d18bf84ad84395 100644 (file)
@@ -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);
index f590611584e4509f6dffa6b2ec02001ae724288d..9bf35cab37968272140cc0435a4344016c5b3ffe 100644 (file)
@@ -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;
index 07865c6fc09e9d3e9521604b1e97c37a1f6bf260..c5637012991f8823689b1b0debf4d51a2f2cfb64 100644 (file)
@@ -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;
index 5316cd822a5b3a7225d67ecb1f2e7c3bf9e4f683..4c8ac820e4083ef2771d090d44c8f58b4646ebbd 100644 (file)
@@ -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, ")");