]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix backward compatibility problem for plugin objects
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Wed, 23 Jun 2021 20:58:22 +0000 (22:58 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:02 +0000 (09:03 +0100)
bacula/src/cats/cats.c
bacula/src/cats/sql_create.c
bacula/src/dird/catreq.c

index aa0fe9d060decb4781972c7b63b01a474f9ff62c..46319d0b754087e77239daa3e1d90b26b3a0f192 100644 (file)
@@ -166,6 +166,7 @@ bool OBJECT_DBR::parse_plugin_object_string(char **obj_str)
 {
    bool ret = false;
    int fnl, pnl;
+   uint64_t val = 0;
 
    char *tmp = get_next_tag(obj_str);
    if (!tmp) {
@@ -224,38 +225,37 @@ bool OBJECT_DBR::parse_plugin_object_string(char **obj_str)
    unbash_spaces(ObjectUUID);
 
    tmp = get_next_tag(obj_str);
-   if (tmp) {
-      uint64_t val = str_to_uint64(tmp);
-      ObjectSize = (val > 9223372036854775808ULL /*2^63 */) ? 0 : val;
-
-   } else if (*obj_str) {
-      /* Object size is the last tag here, we are not expecting to have status in the stream */
-      uint64_t val = str_to_uint64(*obj_str);
-      ObjectSize = (val > 9223372036854775808ULL /*2^63 */) ? 0 : val;
-      ret = true;
+   if (!tmp) {
       goto bail_out;
+   }
+   val = str_to_uint64(tmp);
+   ObjectSize = (val > 9223372036854775808ULL /*2^63 */) ? 0 : val;
 
-   } else {
+   /* We should have status and count in the end of the stream */
+   tmp = get_next_tag(obj_str);
+   if (!tmp) {
+      /* We want to work with plugins that does not send the status and count since it's not required,
+       * so we're good to proceed here - simply return success */
+      ret = true;
       goto bail_out;
    }
+   ObjectStatus = (int)*tmp;
 
-   /* We should have status string in the end */
-   if (*obj_str) {
-      tmp = get_next_tag(obj_str);
-      if (!tmp) {
-         goto bail_out;
-      }
-      ObjectStatus = (int)*tmp;
-      if (*obj_str) {
-         ObjectCount = str_to_uint64(*obj_str);
-      }
-   } else {
+   tmp = get_next_tag(obj_str);
+   if (!tmp) {
       goto bail_out;
    }
+   ObjectCount = str_to_uint64(*obj_str);
 
    ret = true;
 
 bail_out:
+   /* Print whatever was parsed */
+   Dmsg11(dbglvl, "Parsed PluginObject: Path: %s Fname: %s PluginName: %s Category: %s "
+                  "Type: %s Name: %s Source: %s  UUID: %s Size: %lld Status: %d Count: %lld\n",
+                  Path, Filename, PluginName, ObjectCategory, ObjectType, ObjectName, ObjectSource,
+                  ObjectUUID, ObjectSize, (char)ObjectStatus, ObjectCount);
+
    if (!ret) {
       /* Reset parsed fields */
       reset();
index 2a97ad1e80fe949dd51e09fababda90db1ef68f3..6fdea955db9a904f0d9383c5d5562cb6baf2cae4 100644 (file)
@@ -1214,7 +1214,7 @@ bool BDB::bdb_create_object_record(JCR *jcr, OBJECT_DBR *obj)
          "VALUES (%lu, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %llu, '%c', %lu)",
          obj->JobId, esc_path, esc_filename, esc_plugin_name, esc_obj_category,
          esc_obj_type, esc_obj_name, esc_obj_source, esc_obj_uuid,
-         obj->ObjectSize, (char)obj->ObjectStatus, obj->ObjectCount);
+         obj->ObjectSize, obj->ObjectStatus ? (char)obj->ObjectStatus : 'U', obj->ObjectCount);
 
    obj->ObjectId = sql_insert_autokey_record(cmd, NT_("Object"));
    if (obj->ObjectId == 0) {
index 289b465dbbaa1a0c5d43b32a82a26541eb3f6bd0..ff0f50cc82b618db9f7e241146073232ab2aef34 100644 (file)
@@ -642,7 +642,8 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen)
    } else if (Stream == STREAM_PLUGIN_OBJECT) {
       OBJECT_DBR obj_r;
       if (!obj_r.parse_plugin_object_string(&p)) {
-         Jmsg0(jcr, M_FATAL, 0, _("Failed to parse plugin object!\n"));
+         /* Report warning, backup can proceed without plugin object creation */
+         Jmsg0(jcr, M_WARNING, 0, _("Failed to parse plugin object!\n"));
          return;
       }