]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add opens to files in json output
authorJule Anger <janger@samba.org>
Wed, 30 Mar 2022 13:36:13 +0000 (15:36 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +0000 (12:56 +0000)
At the moment, there is only information about the open files.
Adds a list of its opens for each file. An open is represented as
a dictionary. Contains only the basic information (pid, uid and
time) about the open.

Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status.c
source3/utils/status_json.c
source3/utils/status_json.h
source3/utils/status_json_dummy.c

index 7b1a5057f8fbb7693dd2f63f8c72f85e1251e1b2..da9510a38d42203291d09c20e7533a7dbf8f4549 100644 (file)
@@ -315,7 +315,10 @@ static int print_share_mode(struct file_id fid,
                } else {
                        print_share_mode_json(state,
                                              d,
+                                             e,
                                              fid,
+                                             pid,
+                                             user_str,
                                              filename);
                }
        }
index 441f51fa1e45728d2ed447170a6c99dbddab84c4..e0da77192cf05f0b471c9c5a9043d67e5a44d328 100644 (file)
@@ -360,6 +360,70 @@ failure:
        return -1;
 }
 
+static int add_open_to_json(struct json_object *parent_json,
+                           const struct share_mode_entry *e,
+                           bool resolve_uids,
+                           const char *pid,
+                           const char *uid_str)
+{
+       struct json_object sub_json;
+       struct json_object opens_json;
+       int result = 0;
+       char *key = NULL;
+       char *share_file_id = NULL;
+
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return -1;
+       }
+
+       opens_json = json_get_object(parent_json, "opens");
+       if (json_is_invalid(&opens_json)) {
+               goto failure;
+       }
+       sub_json = json_new_object();
+       if (json_is_invalid(&sub_json)) {
+               goto failure;
+       }
+
+       result = json_add_string(&sub_json, "pid", pid);
+       if (result < 0) {
+               goto failure;
+       }
+       if (resolve_uids) {
+               result = json_add_string(&sub_json, "username", uid_str);
+               if (result < 0) {
+                       goto failure;
+               }
+       }
+       result = json_add_int(&sub_json, "uid", e->uid);
+       if (result < 0) {
+               goto failure;
+       }
+       share_file_id = talloc_asprintf(tmp_ctx, "%lu", e->share_file_id);
+       result = json_add_string(&sub_json, "share_file_id", share_file_id);
+       if (result < 0) {
+               goto failure;
+       }
+
+       key = talloc_asprintf(tmp_ctx, "%s/%lu", pid, e->share_file_id);
+       result = json_add_object(&opens_json, key, &sub_json);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_update_object(parent_json, "opens", &opens_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       TALLOC_FREE(tmp_ctx);
+       return 0;
+failure:
+       json_free(&opens_json);
+       json_free(&sub_json);
+       TALLOC_FREE(tmp_ctx);
+       return -1;
+}
 
 static int add_fileid_to_json(struct json_object *parent_json,
                              struct file_id fid)
@@ -398,7 +462,10 @@ failure:
 
 int print_share_mode_json(struct traverse_state *state,
                          const struct share_mode_data *d,
+                         const struct share_mode_entry *e,
                          struct file_id fid,
+                         const char *pid,
+                         const char *uid_str,
                          const char *filename)
 {
        struct json_object locks_json;
@@ -443,6 +510,15 @@ int print_share_mode_json(struct traverse_state *state,
                goto failure;
        }
 
+       result = add_open_to_json(&file_json,
+                                 e,
+                                 state->resolve_uids,
+                                 pid,
+                                 uid_str);
+       if (result < 0) {
+               goto failure;
+       }
+
        result = json_update_object(&locks_json, key, &file_json);
        if (result < 0) {
                goto failure;
index bd9c2611d26d44f0aca6720852a28aef1c4be933..5b803080878e088084977982ee305dac1a53ad30 100644 (file)
@@ -46,7 +46,10 @@ int traverse_sessionid_json(struct traverse_state *state,
 
 int print_share_mode_json(struct traverse_state *state,
                          const struct share_mode_data *d,
+                         const struct share_mode_entry *e,
                          struct file_id fid,
+                         const char *pid,
+                         const char *uid_str,
                          const char *filename);
 
 #endif
index c53c329c837df48519e3bcaec59c39bbe816eb5c..668a5a63fbdf8ccf7468c498e921e379068da49e 100644 (file)
@@ -60,7 +60,10 @@ int traverse_sessionid_json(struct traverse_state *state,
 
 int print_share_mode_json(struct traverse_state *state,
                          const struct share_mode_data *d,
+                         const struct share_mode_entry *e,
                          struct file_id fid,
+                         const char *pid,
+                         const char *uid_str,
                          const char *filename)
 {
        return 0;