]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
net_tdb: Slightly restructure net_tdb_locking()
authorVolker Lendecke <vl@samba.org>
Wed, 4 Nov 2020 14:09:40 +0000 (15:09 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 10 Nov 2020 19:49:35 +0000 (19:49 +0000)
Remove the net_tdb_locking_fetch() subroutine. All of net_tdb_locking() is
still very simple, and net_tdb_locking_fetch() did the fetch as such plus
parsing the hex key. With this restructuring it was possible to avoid a direct
reference to lck->data->id.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/utils/net_tdb.c

index efca041d8e33c1610498c05dd519874e8ee9bcde..9914f0a59b167de5a280acb84d349d6da07cf171 100644 (file)
@@ -43,53 +43,39 @@ static int net_tdb_locking_dump(TALLOC_CTX *mem_ctx,
        return 0;
 }
 
-static int net_tdb_locking_fetch(TALLOC_CTX *mem_ctx, const char *hexkey,
-                                struct share_mode_lock **lock)
+static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
 {
-       DATA_BLOB blob;
-       struct file_id id;
+       TALLOC_CTX *mem_ctx = talloc_stackframe();
+       struct share_mode_lock *lock;
+       DATA_BLOB blob = { .data = NULL };
+       struct file_id id = { .inode = 0 };
+       int ret = -1;
        bool ok;
 
-       blob = strhex_to_data_blob(mem_ctx, hexkey);
-       if (blob.length != sizeof(struct file_id)) {
-               d_printf("Invalid length %zu of key, expected %zu\n",
-                        blob.length,
-                        sizeof(struct file_id));
-               return -1;
+       if (argc < 1) {
+               d_printf("Usage: net tdb locking <key> [ dump ]\n");
+               goto out;
        }
 
-       id = *(struct file_id *)blob.data;
-
        ok = locking_init_readonly();
        if (!ok) {
                d_printf("locking_init_readonly failed\n");
-               return -1;
-       }
-
-       *lock = fetch_share_mode_unlocked(mem_ctx, id);
-
-       if (*lock == NULL) {
-               d_printf("Record with key %s not found.\n", hexkey);
-               return -1;
+               goto out;
        }
 
-       return 0;
-}
-
-static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
-{
-       TALLOC_CTX *mem_ctx = talloc_stackframe();
-       struct share_mode_lock *lock;
-       int ret;
-
-       if (argc < 1) {
-               d_printf("Usage: net tdb locking <key> [ dump ]\n");
-               ret = -1;
+       blob = strhex_to_data_blob(mem_ctx, argv[0]);
+       if (blob.length != sizeof(struct file_id)) {
+               d_printf("Invalid length %zu of key, expected %zu\n",
+                        blob.length,
+                        sizeof(struct file_id));
                goto out;
        }
 
-       ret = net_tdb_locking_fetch(mem_ctx, argv[0], &lock);
-       if (ret != 0) {
+       memcpy(&id, blob.data, blob.length);
+
+       lock = fetch_share_mode_unlocked(mem_ctx, id);
+       if (lock == NULL) {
+               d_printf("Record with key %s not found.\n", argv[1]);
                goto out;
        }
 
@@ -99,12 +85,12 @@ static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
                NTSTATUS status;
                size_t num_share_modes = 0;
 
-               status = share_mode_count_entries(
-                       lock->data->id, &num_share_modes);
+               status = share_mode_count_entries(id, &num_share_modes);
                if (!NT_STATUS_IS_OK(status)) {
                        d_fprintf(stderr,
                                  "Could not count share entries: %s\n",
                                  nt_errstr(status));
+                       goto out;
                }
 
                d_printf("Share path:            %s\n", lock->data->servicepath);
@@ -112,6 +98,7 @@ static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
                d_printf("Number of share modes: %zu\n", num_share_modes);
        }
 
+       ret = 0;
 out:
        TALLOC_FREE(mem_ctx);
        return ret;