From 4d404f23c9dff8bafd408b2d9566e179afef74bc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 18 May 2017 13:59:20 +0200 Subject: [PATCH] g_lock: Reformat to allow userdata The next patches will make g_locks carry data. This prepares the on-disk format. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/lib/g_lock.c | 129 ++++++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 31 deletions(-) diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 542abe4f24f..ef950d60249 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -63,7 +63,8 @@ static void g_lock_rec_get(struct g_lock_rec *rec, static ssize_t g_lock_put(uint8_t *buf, size_t buflen, const struct g_lock_rec *locks, - size_t num_locks) + size_t num_locks, + const uint8_t *data, size_t datalen) { size_t i, len, ofs; @@ -73,46 +74,106 @@ static ssize_t g_lock_put(uint8_t *buf, size_t buflen, len = num_locks * G_LOCK_REC_LENGTH; + len += sizeof(uint32_t); + if (len < sizeof(uint32_t)) { + return -1; + } + + len += datalen; + if (len < datalen) { + return -1; + } + if (len > buflen) { return len; } ofs = 0; + SIVAL(buf, ofs, num_locks); + ofs += sizeof(uint32_t); for (i=0; i recval.dsize/G_LOCK_REC_LENGTH) { + /* Invalid record */ + return 0; } - for (i=0; imsg); struct db_record *rec = NULL; struct g_lock_rec *locks = NULL; - unsigned i, num_locks; + size_t i, num_locks; NTSTATUS status; TDB_DATA value; @@ -446,8 +509,11 @@ NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name) value = dbwrap_record_get_value(rec); - if (!g_lock_get(talloc_tos(), value, &num_locks, &locks)) { - DEBUG(10, ("g_lock_get for %s failed\n", name)); + status = g_lock_get_talloc(talloc_tos(), value, &locks, &num_locks, + NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + DBG_DEBUG("g_lock_get for %s failed: %s\n", name, + nt_errstr(status)); status = NT_STATUS_FILE_INVALID; goto done; } @@ -457,7 +523,7 @@ NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name) } } if (i == num_locks) { - DBG_DEBUG("Lock not found, num_locks=%u\n", num_locks); + DBG_DEBUG("Lock not found, num_locks=%zu\n", num_locks); status = NT_STATUS_NOT_FOUND; goto done; } @@ -525,9 +591,8 @@ NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name, void *private_data) { TDB_DATA data; - unsigned i, num_locks; + size_t i, num_locks; struct g_lock_rec *locks = NULL; - bool ret; NTSTATUS status; status = dbwrap_fetch_bystring(ctx->db, talloc_tos(), name, &data); @@ -539,12 +604,14 @@ NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name, return NT_STATUS_OK; } - ret = g_lock_get(talloc_tos(), data, &num_locks, &locks); + status = g_lock_get_talloc(talloc_tos(), data, &locks, &num_locks, + NULL, NULL); TALLOC_FREE(data.dptr); - if (!ret) { - DEBUG(10, ("g_lock_get for %s failed\n", name)); + if (!NT_STATUS_IS_OK(status)) { + DBG_DEBUG("g_lock_get for %s failed: %s\n", name, + nt_errstr(status)); return NT_STATUS_INTERNAL_ERROR; } -- 2.47.2