mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
lib/dbwrap: allow dbwrap_merge_dbufs() to update an existing buffer
This will be useful in future... BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
6f2ce1fd34
commit
3c26ee84ce
@ -680,22 +680,28 @@ static ssize_t tdb_data_buf(const TDB_DATA *dbufs, int num_dbufs,
|
||||
}
|
||||
|
||||
|
||||
TDB_DATA dbwrap_merge_dbufs(TALLOC_CTX *mem_ctx,
|
||||
NTSTATUS dbwrap_merge_dbufs(TDB_DATA *buf, TALLOC_CTX *mem_ctx,
|
||||
const TDB_DATA *dbufs, int num_dbufs)
|
||||
{
|
||||
ssize_t len = tdb_data_buf(dbufs, num_dbufs, NULL, 0);
|
||||
uint8_t *buf;
|
||||
|
||||
if (len == -1) {
|
||||
return (TDB_DATA) {0};
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
buf = talloc_array(mem_ctx, uint8_t, len);
|
||||
if (buf == NULL) {
|
||||
return (TDB_DATA) {0};
|
||||
if (buf->dsize != len) {
|
||||
uint8_t *tmp;
|
||||
|
||||
tmp = talloc_realloc(mem_ctx, buf->dptr, uint8_t, len);
|
||||
if (tmp == NULL && len != 0) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
buf->dptr = tmp;
|
||||
buf->dsize = len;
|
||||
}
|
||||
|
||||
tdb_data_buf(dbufs, num_dbufs, buf, len);
|
||||
tdb_data_buf(dbufs, num_dbufs, buf->dptr, buf->dsize);
|
||||
|
||||
return (TDB_DATA) { .dptr = buf, .dsize = len };
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ NTSTATUS dbwrap_parse_marshall_buf(const uint8_t *buf, size_t buflen,
|
||||
NTSTATUS dbwrap_unmarshall(struct db_context *db, const uint8_t *buf,
|
||||
size_t buflen);
|
||||
|
||||
TDB_DATA dbwrap_merge_dbufs(TALLOC_CTX *mem_ctx,
|
||||
NTSTATUS dbwrap_merge_dbufs(TDB_DATA *buf, TALLOC_CTX *mem_ctx,
|
||||
const TDB_DATA *dbufs, int num_dbufs);
|
||||
|
||||
|
||||
|
@ -149,9 +149,12 @@ static NTSTATUS db_rbt_storev(struct db_record *rec,
|
||||
if (num_dbufs == 1) {
|
||||
data = dbufs[0];
|
||||
} else {
|
||||
data = dbwrap_merge_dbufs(rec, dbufs, num_dbufs);
|
||||
if (data.dptr == NULL) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
NTSTATUS status;
|
||||
|
||||
data = (TDB_DATA) {0};
|
||||
status = dbwrap_merge_dbufs(&data, rec, dbufs, num_dbufs);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
to_free = data.dptr;
|
||||
}
|
||||
|
@ -674,11 +674,11 @@ static NTSTATUS db_ctdb_storev_transaction(
|
||||
struct db_ctdb_transaction_handle *h = talloc_get_type_abort(
|
||||
rec->private_data, struct db_ctdb_transaction_handle);
|
||||
NTSTATUS status;
|
||||
TDB_DATA data;
|
||||
TDB_DATA data = {0};
|
||||
|
||||
data = dbwrap_merge_dbufs(rec, dbufs, num_dbufs);
|
||||
if (data.dptr == NULL) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
status = dbwrap_merge_dbufs(&data, rec, dbufs, num_dbufs);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = db_ctdb_transaction_store(h, rec->key, data);
|
||||
|
Loading…
Reference in New Issue
Block a user