]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add sharemode information about open files to json output
authorJule Anger <janger@samba.org>
Mon, 1 Aug 2022 10:01:41 +0000 (12:01 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +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 ce6ee178b4a6e07d97fdf7e8b2e73eceb3243779..b2c005056711dad33a5f557f3a2f2767b06542bc 100644 (file)
@@ -167,6 +167,13 @@ static const struct mask2txt oplock_mask[] = {
        {0, NULL}
 };
 
+static const struct mask2txt sharemode_mask[] = {
+       {FILE_SHARE_READ, "READ"},
+       {FILE_SHARE_WRITE, "WRITE"},
+       {FILE_SHARE_DELETE, "DELETE"},
+       {0, NULL}
+};
+
 static const struct mask2txt lease_mask[] = {
        {SMB2_LEASE_READ, "READ"},
        {SMB2_LEASE_WRITE, "WRITE"},
@@ -614,6 +621,62 @@ failure:
        return -1;
 }
 
+static int add_sharemode_to_json(struct json_object *parent_json,
+                                int sharemode)
+{
+       struct json_object sharemode_json;
+       char *hex = NULL;
+       char *text = NULL;
+       int result;
+
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return -1;
+       }
+
+       sharemode_json = json_new_object();
+       if (json_is_invalid(&sharemode_json)) {
+               goto failure;
+       }
+
+       hex = talloc_asprintf(tmp_ctx, "0x%08x", sharemode);
+       if (hex == NULL) {
+               goto failure;
+       }
+       result = json_add_string(&sharemode_json, "hex", hex);
+       if (result < 0) {
+               goto failure;
+       }
+       result = map_mask_to_json(&sharemode_json, sharemode, sharemode_mask);
+       if (result < 0) {
+               goto failure;
+       }
+
+       text = talloc_asprintf(tmp_ctx, "%s%s%s",
+                              (sharemode & FILE_SHARE_READ)?"R":"",
+                              (sharemode & FILE_SHARE_WRITE)?"W":"",
+                              (sharemode & FILE_SHARE_DELETE)?"D":"");
+       if (text == NULL) {
+               goto failure;
+       }
+       result = json_add_string(&sharemode_json, "text", text);
+       if (result < 0) {
+               goto failure;
+       }
+
+       result = json_add_object(parent_json, "sharemode", &sharemode_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       TALLOC_FREE(tmp_ctx);
+       return 0;
+failure:
+       json_free(&sharemode_json);
+       TALLOC_FREE(tmp_ctx);
+       return -1;
+}
+
 static int add_open_to_json(struct json_object *parent_json,
                            const struct share_mode_entry *e,
                            bool resolve_uids,
@@ -664,6 +727,10 @@ static int add_open_to_json(struct json_object *parent_json,
        if (result < 0) {
                goto failure;
        }
+       result = add_sharemode_to_json(&sub_json, e->share_access);
+       if (result < 0) {
+               goto failure;
+       }
        result = add_access_mode_to_json(&sub_json, e->access_mask);
        if (result < 0) {
                goto failure;