lib: Make g_lock_unlock use TDB_DATA
authorVolker Lendecke <vl@samba.org>
Sun, 3 Dec 2017 19:47:02 +0000 (20:47 +0100)
committerRalph Boehme <slow@samba.org>
Thu, 8 Feb 2018 09:01:50 +0000 (10:01 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
libcli/auth/netlogon_creds_cli.c
source3/include/g_lock.h
source3/lib/dbwrap/dbwrap_ctdb.c
source3/lib/g_lock.c
source3/libsmb/trusts_util.c
source3/smbd/server.c
source3/torture/test_g_lock.c

index f51ad3dda26f718539055f201bf1556e3a552f91..fdd1195b1835c492e427ed4a19fecd2f2f272ce1 100644 (file)
@@ -93,7 +93,7 @@ static int netlogon_creds_cli_locked_state_destructor(
 
        if (state->is_glocked) {
                g_lock_unlock(context->db.g_ctx,
 
        if (state->is_glocked) {
                g_lock_unlock(context->db.g_ctx,
-                             context->db.key_name);
+                             string_term_tdb_data(context->db.key_name));
        }
 
        return 0;
        }
 
        return 0;
@@ -1014,7 +1014,8 @@ static int netlogon_creds_cli_lck_destructor(
        struct netlogon_creds_cli_context *ctx = lck->context;
        NTSTATUS status;
 
        struct netlogon_creds_cli_context *ctx = lck->context;
        NTSTATUS status;
 
-       status = g_lock_unlock(ctx->db.g_ctx, ctx->db.key_name);
+       status = g_lock_unlock(ctx->db.g_ctx,
+                              string_term_tdb_data(ctx->db.key_name));
        if (!NT_STATUS_IS_OK(status)) {
                DBG_WARNING("g_lock_unlock failed: %s\n", nt_errstr(status));
                smb_panic("g_lock_unlock failed");
        if (!NT_STATUS_IS_OK(status)) {
                DBG_WARNING("g_lock_unlock failed: %s\n", nt_errstr(status));
                smb_panic("g_lock_unlock failed");
index 867e10420e296176289f558514dfc7428c4e5594..a1d845f307439ce427f06e3fc7292a9af7bccbcb 100644 (file)
@@ -46,7 +46,7 @@ struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
 NTSTATUS g_lock_lock_recv(struct tevent_req *req);
 NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
                     enum g_lock_type lock_type, struct timeval timeout);
 NTSTATUS g_lock_lock_recv(struct tevent_req *req);
 NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
                     enum g_lock_type lock_type, struct timeval timeout);
-NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name);
+NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key);
 
 NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, const char *name,
                           const uint8_t *buf, size_t buflen);
 
 NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, const char *name,
                           const uint8_t *buf, size_t buflen);
index ce66c2ad9e4a6917b536ad9d2ac9ef63f4ae7c62..2885f4e7fda34feab012e0084b1b5941b89a69eb 100644 (file)
@@ -328,7 +328,8 @@ static int db_ctdb_transaction_destructor(struct db_ctdb_transaction_handle *h)
 {
        NTSTATUS status;
 
 {
        NTSTATUS status;
 
-       status = g_lock_unlock(h->ctx->lock_ctx, h->lock_name);
+       status = g_lock_unlock(h->ctx->lock_ctx,
+                              string_term_tdb_data(h->lock_name));
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("g_lock_unlock failed for %s: %s\n", h->lock_name,
                          nt_errstr(status)));
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("g_lock_unlock failed for %s: %s\n", h->lock_name,
                          nt_errstr(status)));
index f1227492045d4280b80c8db0403ea8ed624f6ed8..653ec34bb7f95c4ade1592773606c8bf1c1e0524 100644 (file)
@@ -483,7 +483,7 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
 }
 
 struct g_lock_unlock_state {
 }
 
 struct g_lock_unlock_state {
-       const char *name;
+       TDB_DATA key;
        struct server_id self;
        NTSTATUS status;
 };
        struct server_id self;
        NTSTATUS status;
 };
@@ -501,7 +501,10 @@ static void g_lock_unlock_fn(struct db_record *rec,
 
        ok = g_lock_parse(value.dptr, value.dsize, &lck);
        if (!ok) {
 
        ok = g_lock_parse(value.dptr, value.dsize, &lck);
        if (!ok) {
-               DBG_DEBUG("g_lock_get for %s failed\n", state->name);
+               DBG_DEBUG("g_lock_get for %s failed\n",
+                         hex_encode_talloc(talloc_tos(),
+                                           state->key.dptr,
+                                           state->key.dsize));
                state->status = NT_STATUS_FILE_INVALID;
                return;
        }
                state->status = NT_STATUS_FILE_INVALID;
                return;
        }
@@ -527,15 +530,14 @@ static void g_lock_unlock_fn(struct db_record *rec,
        state->status = g_lock_store(rec, &lck, NULL);
 }
 
        state->status = g_lock_store(rec, &lck, NULL);
 }
 
-NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name)
+NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key)
 {
        struct g_lock_unlock_state state = {
 {
        struct g_lock_unlock_state state = {
-               .self = messaging_server_id(ctx->msg), .name = name
+               .self = messaging_server_id(ctx->msg), .key = key
        };
        NTSTATUS status;
 
        };
        NTSTATUS status;
 
-       status = dbwrap_do_locked(ctx->db, string_term_tdb_data(name),
-                                 g_lock_unlock_fn, &state);
+       status = dbwrap_do_locked(ctx->db, key, g_lock_unlock_fn, &state);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_WARNING("dbwrap_do_locked failed: %s\n",
                            nt_errstr(status));
        if (!NT_STATUS_IS_OK(status)) {
                DBG_WARNING("dbwrap_do_locked failed: %s\n",
                            nt_errstr(status));
@@ -788,7 +790,7 @@ NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
                goto done;
        }
        fn(private_data);
                goto done;
        }
        fn(private_data);
-       g_lock_unlock(g_ctx, name);
+       g_lock_unlock(g_ctx, string_term_tdb_data(name));
 
 done:
        TALLOC_FREE(g_ctx);
 
 done:
        TALLOC_FREE(g_ctx);
index 05ea07fb08066dab443650cb984e054d2ae714d6..fd1b3372b36d285797e081abfa1adc7067cc2070 100644 (file)
@@ -45,7 +45,8 @@ struct trust_pw_change_state {
 
 static int trust_pw_change_state_destructor(struct trust_pw_change_state *state)
 {
 
 static int trust_pw_change_state_destructor(struct trust_pw_change_state *state)
 {
-       g_lock_unlock(state->g_ctx, state->g_lock_key);
+       g_lock_unlock(state->g_ctx,
+                     string_term_tdb_data(state->g_lock_key));
        return 0;
 }
 
        return 0;
 }
 
index cb6bc73de74cbbfcecd2ad61bfb98fb9d0513004..1d0e317b5c8180d0c7a16cafabdebb967ec0265f 100644 (file)
@@ -1495,7 +1495,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
        if (!NT_STATUS_IS_OK(status) &&
            !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
                DBG_ERR("Could not read samba_version_string\n");
        if (!NT_STATUS_IS_OK(status) &&
            !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
                DBG_ERR("Could not read samba_version_string\n");
-               g_lock_unlock(ctx, name);
+               g_lock_unlock(ctx, string_term_tdb_data(name));
                TALLOC_FREE(ctx);
                return status;
        }
                TALLOC_FREE(ctx);
                return status;
        }
index 2dcba1e68e23ebfa87de08d0664d293a43a72b38..1d3be9cbad07b63154deb4dae1a88add198dbd17 100644 (file)
@@ -84,14 +84,14 @@ bool run_g_lock1(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       status = g_lock_unlock(ctx, lockname);
+       status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
        if (!NT_STATUS_IS_OK(status)) {
                fprintf(stderr, "g_lock_unlock failed: %s\n",
                        nt_errstr(status));
                goto fail;
        }
 
        if (!NT_STATUS_IS_OK(status)) {
                fprintf(stderr, "g_lock_unlock failed: %s\n",
                        nt_errstr(status));
                goto fail;
        }
 
-       status = g_lock_unlock(ctx, lockname);
+       status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
        if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
                fprintf(stderr, "g_lock_unlock returned: %s\n",
                        nt_errstr(status));
        if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
                fprintf(stderr, "g_lock_unlock returned: %s\n",
                        nt_errstr(status));
@@ -170,7 +170,7 @@ bool run_g_lock2(int dummy)
                goto fail;
        }
 
                goto fail;
        }
 
-       status = g_lock_unlock(ctx, lockname);
+       status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
        if (!NT_STATUS_IS_OK(status)) {
                fprintf(stderr, "g_lock_unlock failed: %s\n",
                        nt_errstr(status));
        if (!NT_STATUS_IS_OK(status)) {
                fprintf(stderr, "g_lock_unlock failed: %s\n",
                        nt_errstr(status));
@@ -688,7 +688,7 @@ bool run_g_lock5(int dummy)
                                nt_errstr(status));
                        return false;
                }
                                nt_errstr(status));
                        return false;
                }
-               status = g_lock_unlock(ctx, lockname);
+               status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
                if (!NT_STATUS_IS_OK(status)) {
                        fprintf(stderr, "g_lock_unlock failed %s\n",
                                nt_errstr(status));
                if (!NT_STATUS_IS_OK(status)) {
                        fprintf(stderr, "g_lock_unlock failed %s\n",
                                nt_errstr(status));
@@ -922,7 +922,7 @@ bool run_g_lock_ping_pong(int dummy)
 
                name[10] = '0' + ((i) % torture_nprocs);
 
 
                name[10] = '0' + ((i) % torture_nprocs);
 
-               status = g_lock_unlock(ctx, name);
+               status = g_lock_unlock(ctx, string_term_tdb_data(name));
                if (!NT_STATUS_IS_OK(status)) {
                        fprintf(stderr, "g_lock_unlock failed: %s\n",
                                nt_errstr(status));
                if (!NT_STATUS_IS_OK(status)) {
                        fprintf(stderr, "g_lock_unlock failed: %s\n",
                                nt_errstr(status));