]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add server_id to connections
authorJule Anger <janger@samba.org>
Mon, 2 May 2022 08:55:52 +0000 (10:55 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:28 +0000 (12:56 +0000)
Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status_json.c

index c460ce78c6a2730305ecba6ea045b341aea54ad9..fdbe8bb4573a0a43caa1eb735657569c5347e32d 100644 (file)
@@ -23,6 +23,7 @@
 #include "status_json.h"
 #include "../libcli/security/security.h"
 #include "status.h"
+#include "lib/util/server_id.h"
 
 #include <jansson.h>
 #include "audit_logging.h" /* various JSON helpers */
@@ -50,6 +51,61 @@ int add_general_information_to_json(struct traverse_state *state)
        return 0;
 }
 
+static int add_server_id_to_json(struct json_object *parent_json,
+                                const struct server_id server_id)
+{
+       struct json_object sub_json;
+       char *pid_str = NULL;
+       char *task_id_str = NULL;
+       char *vnn_str = NULL;
+       char *unique_id_str = NULL;
+       int result;
+
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return -1;
+       }
+
+       sub_json = json_new_object();
+       if (json_is_invalid(&sub_json)) {
+               goto failure;
+       }
+
+       pid_str = talloc_asprintf(tmp_ctx, "%lu", server_id.pid);
+       result = json_add_string(&sub_json, "pid", pid_str);
+       if (result < 0) {
+               goto failure;
+       }
+       task_id_str = talloc_asprintf(tmp_ctx, "%u", server_id.task_id);
+       result = json_add_string(&sub_json, "task_id", task_id_str);
+       if (result < 0) {
+               goto failure;
+       }
+       vnn_str = talloc_asprintf(tmp_ctx, "%u", server_id.vnn);
+       result = json_add_string(&sub_json, "vnn", vnn_str);
+       if (result < 0) {
+               goto failure;
+       }
+       unique_id_str = talloc_asprintf(tmp_ctx, "%lu", server_id.unique_id);
+       result = json_add_string(&sub_json, "unique_id", unique_id_str);
+       if (result < 0) {
+               goto failure;
+       }
+
+       result = json_add_object(parent_json, "server_id", &sub_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       json_free(&sub_json);
+       TALLOC_FREE(tmp_ctx);
+       return 0;
+failure:
+       json_free(&sub_json);
+       TALLOC_FREE(tmp_ctx);
+       return -1;
+}
+
 int add_section_to_json(struct traverse_state *state,
                        const char *key)
 {
@@ -95,6 +151,10 @@ int traverse_connections_json(struct traverse_state *state,
        if (result < 0) {
                goto failure;
        }
+       result = add_server_id_to_json(&sub_json, crec->pid);
+       if (result < 0) {
+               goto failure;
+       }
        tcon_id_str = talloc_asprintf(tmp_ctx, "%u", crec->cnum);
        if (tcon_id_str == NULL) {
                goto failure;