From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/lib/util/data_blob.c | 209 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 source4/lib/util/data_blob.c (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c new file mode 100644 index 0000000000..c6471fbf54 --- /dev/null +++ b/source4/lib/util/data_blob.c @@ -0,0 +1,209 @@ +/* + Unix SMB/CIFS implementation. + Easy management of byte-length data + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/******************************************************************* + construct a data blob, must be freed with data_blob_free() + you can pass NULL for p and get a blank data blob +*******************************************************************/ +DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) +{ + DATA_BLOB ret; + + if (p == NULL && length == 0) { + ZERO_STRUCT(ret); + return ret; + } + + if (p) { + ret.data = talloc_memdup(NULL, p, length); + } else { + ret.data = talloc_size(NULL, length); + } + if (ret.data == NULL) { + ret.length = 0; + return ret; + } + talloc_set_name_const(ret.data, name); + ret.length = length; + return ret; +} + +/******************************************************************* + construct a data blob, using supplied TALLOC_CTX +*******************************************************************/ +DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) +{ + DATA_BLOB ret = data_blob_named(p, length, name); + + if (ret.data) { + talloc_steal(mem_ctx, ret.data); + } + return ret; +} + + +/******************************************************************* + reference a data blob, to the supplied TALLOC_CTX. + Returns a NULL DATA_BLOB on failure +*******************************************************************/ +DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +{ + DATA_BLOB ret = *blob; + + ret.data = talloc_reference(mem_ctx, blob->data); + + if (!ret.data) { + return data_blob(NULL, 0); + } + return ret; +} + +/******************************************************************* + construct a zero data blob, using supplied TALLOC_CTX. + use this sparingly as it initialises data - better to initialise + yourself if you want specific data in the blob +*******************************************************************/ +DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) +{ + DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); + data_blob_clear(&blob); + return blob; +} + +/******************************************************************* +free a data blob +*******************************************************************/ +void data_blob_free(DATA_BLOB *d) +{ + if (d) { + talloc_free(d->data); + d->data = NULL; + d->length = 0; + } +} + +/******************************************************************* +clear a DATA_BLOB's contents +*******************************************************************/ +void data_blob_clear(DATA_BLOB *d) +{ + if (d->data) { + memset(d->data, 0, d->length); + } +} + +/******************************************************************* +free a data blob and clear its contents +*******************************************************************/ +void data_blob_clear_free(DATA_BLOB *d) +{ + data_blob_clear(d); + data_blob_free(d); +} + + +/******************************************************************* +check if two data blobs are equal +*******************************************************************/ +BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) +{ + if (d1->length != d2->length) { + return False; + } + if (d1->data == d2->data) { + return True; + } + if (d1->data == NULL || d2->data == NULL) { + return False; + } + if (memcmp(d1->data, d2->data, d1->length) == 0) { + return True; + } + return False; +} + +/******************************************************************* +print the data_blob as hex string +*******************************************************************/ +char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +{ + int i; + char *hex_string; + + hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1); + if (!hex_string) { + return NULL; + } + + for (i = 0; i < blob->length; i++) + slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]); + + return hex_string; +} + +/* + useful for constructing data blobs in test suites, while + avoiding const warnings +*/ +DATA_BLOB data_blob_string_const(const char *str) +{ + DATA_BLOB blob; + blob.data = discard_const(str); + blob.length = strlen(str); + return blob; +} + +DATA_BLOB data_blob_const(const void *p, size_t length) +{ + DATA_BLOB blob; + blob.data = discard_const(p); + blob.length = length; + return blob; +} + + +/* + realloc a data_blob +*/ +NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) +{ + blob->data = talloc_realloc_size(mem_ctx, blob->data, length); + NT_STATUS_HAVE_NO_MEMORY(blob->data); + blob->length = length; + return NT_STATUS_OK; +} + +/* + append some data to a data blob +*/ +NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, + const void *p, size_t length) +{ + blob->data = talloc_realloc_size(mem_ctx, blob->data, + blob->length + length); + NT_STATUS_HAVE_NO_MEMORY(blob->data); + memcpy(blob->data + blob->length, p, length); + blob->length += length; + return NT_STATUS_OK; +} + -- cgit From aa04388943fe5d7d8c873a6ee8a4cc9af2491532 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 28 Feb 2006 13:12:39 +0000 Subject: r13752: Add doxyfile and fix formatting of comments. Current output is available at http://samba.org/~jelmer/util-api/ (This used to be commit 90812203df151a5e62394306827c72adfe13c63c) --- source4/lib/util/data_blob.c | 53 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index c6471fbf54..dfcfaa41ea 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -21,10 +21,15 @@ #include "includes.h" -/******************************************************************* +/** + * @file + * @brief Manipulation of arbitrary data blobs + **/ + +/** construct a data blob, must be freed with data_blob_free() you can pass NULL for p and get a blank data blob -*******************************************************************/ +**/ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) { DATA_BLOB ret; @@ -48,9 +53,9 @@ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) return ret; } -/******************************************************************* +/** construct a data blob, using supplied TALLOC_CTX -*******************************************************************/ +**/ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) { DATA_BLOB ret = data_blob_named(p, length, name); @@ -62,10 +67,10 @@ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t leng } -/******************************************************************* +/** reference a data blob, to the supplied TALLOC_CTX. Returns a NULL DATA_BLOB on failure -*******************************************************************/ +**/ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { DATA_BLOB ret = *blob; @@ -78,11 +83,11 @@ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) return ret; } -/******************************************************************* +/** construct a zero data blob, using supplied TALLOC_CTX. use this sparingly as it initialises data - better to initialise yourself if you want specific data in the blob -*******************************************************************/ +**/ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) { DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); @@ -90,9 +95,9 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) return blob; } -/******************************************************************* +/** free a data blob -*******************************************************************/ +**/ void data_blob_free(DATA_BLOB *d) { if (d) { @@ -102,9 +107,9 @@ void data_blob_free(DATA_BLOB *d) } } -/******************************************************************* +/** clear a DATA_BLOB's contents -*******************************************************************/ +**/ void data_blob_clear(DATA_BLOB *d) { if (d->data) { @@ -112,9 +117,9 @@ void data_blob_clear(DATA_BLOB *d) } } -/******************************************************************* +/** free a data blob and clear its contents -*******************************************************************/ +**/ void data_blob_clear_free(DATA_BLOB *d) { data_blob_clear(d); @@ -122,9 +127,9 @@ void data_blob_clear_free(DATA_BLOB *d) } -/******************************************************************* +/** check if two data blobs are equal -*******************************************************************/ +**/ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) { if (d1->length != d2->length) { @@ -142,9 +147,9 @@ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) return False; } -/******************************************************************* +/** print the data_blob as hex string -*******************************************************************/ +**/ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { int i; @@ -161,10 +166,10 @@ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) return hex_string; } -/* +/** useful for constructing data blobs in test suites, while avoiding const warnings -*/ +**/ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; @@ -182,9 +187,9 @@ DATA_BLOB data_blob_const(const void *p, size_t length) } -/* +/** realloc a data_blob -*/ +**/ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, length); @@ -193,9 +198,9 @@ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) return NT_STATUS_OK; } -/* +/** append some data to a data blob -*/ +**/ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { -- cgit From af30a32b6924b0f2b701186e435defbca2ebd1aa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 17:15:19 +0000 Subject: r13840: Mark some functions as public. (This used to be commit 9a188eb1f48a50d92a67a4fc2b3899b90074059a) --- source4/lib/util/data_blob.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index dfcfaa41ea..c1513a1d78 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -30,7 +30,7 @@ construct a data blob, must be freed with data_blob_free() you can pass NULL for p and get a blank data blob **/ -DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) +_PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) { DATA_BLOB ret; @@ -56,7 +56,7 @@ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) /** construct a data blob, using supplied TALLOC_CTX **/ -DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) +_PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) { DATA_BLOB ret = data_blob_named(p, length, name); @@ -71,7 +71,7 @@ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t leng reference a data blob, to the supplied TALLOC_CTX. Returns a NULL DATA_BLOB on failure **/ -DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +_PUBLIC_ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { DATA_BLOB ret = *blob; @@ -88,7 +88,7 @@ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) use this sparingly as it initialises data - better to initialise yourself if you want specific data in the blob **/ -DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) +_PUBLIC_ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) { DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); data_blob_clear(&blob); @@ -98,7 +98,7 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) /** free a data blob **/ -void data_blob_free(DATA_BLOB *d) +_PUBLIC_ void data_blob_free(DATA_BLOB *d) { if (d) { talloc_free(d->data); @@ -110,7 +110,7 @@ void data_blob_free(DATA_BLOB *d) /** clear a DATA_BLOB's contents **/ -void data_blob_clear(DATA_BLOB *d) +_PUBLIC_ void data_blob_clear(DATA_BLOB *d) { if (d->data) { memset(d->data, 0, d->length); @@ -120,7 +120,7 @@ void data_blob_clear(DATA_BLOB *d) /** free a data blob and clear its contents **/ -void data_blob_clear_free(DATA_BLOB *d) +_PUBLIC_ void data_blob_clear_free(DATA_BLOB *d) { data_blob_clear(d); data_blob_free(d); @@ -130,7 +130,7 @@ void data_blob_clear_free(DATA_BLOB *d) /** check if two data blobs are equal **/ -BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) +_PUBLIC_ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) { if (d1->length != d2->length) { return False; @@ -150,7 +150,7 @@ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) /** print the data_blob as hex string **/ -char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { int i; char *hex_string; @@ -170,7 +170,7 @@ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) useful for constructing data blobs in test suites, while avoiding const warnings **/ -DATA_BLOB data_blob_string_const(const char *str) +_PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; blob.data = discard_const(str); @@ -178,7 +178,7 @@ DATA_BLOB data_blob_string_const(const char *str) return blob; } -DATA_BLOB data_blob_const(const void *p, size_t length) +_PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) { DATA_BLOB blob; blob.data = discard_const(p); @@ -190,7 +190,7 @@ DATA_BLOB data_blob_const(const void *p, size_t length) /** realloc a data_blob **/ -NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) +_PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, length); NT_STATUS_HAVE_NO_MEMORY(blob->data); @@ -201,7 +201,7 @@ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) /** append some data to a data blob **/ -NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, +_PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, -- cgit From c287cc247d90c996894cab18e870c992e7f84f85 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 6 Mar 2006 00:24:51 +0000 Subject: r13851: More doc improvements. (This used to be commit 936d26ae64b93ef8f8b2fbc632b1c2fd60840405) --- source4/lib/util/data_blob.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index c1513a1d78..ac6589aa50 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -178,6 +178,10 @@ _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) return blob; } +/** + * Create a new data blob from const data + */ + _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) { DATA_BLOB blob; -- cgit From dc2715b49c477adb4ba95149a3bfdf79457fa6c0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 21 Jul 2006 00:56:48 +0000 Subject: r17167: indent (This used to be commit 4dcdc5a3ad6847be6c6199854121ae4ccadaa673) --- source4/lib/util/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index ac6589aa50..118d78ca60 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -206,7 +206,7 @@ _PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t append some data to a data blob **/ _PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, - const void *p, size_t length) + const void *p, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, blob->length + length); -- cgit From c047a88f41ffed47e2eb422f8efb594aae80d61e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Jul 2006 00:53:03 +0000 Subject: r17221: Add some integer wrap parinoia to data_blob_append(). Andrew Bartlett (This used to be commit 7c5a25a423da3db982396ac507df985fa934be73) --- source4/lib/util/data_blob.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 118d78ca60..3253d52ee7 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -202,17 +202,30 @@ _PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t return NT_STATUS_OK; } + /** append some data to a data blob **/ _PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { - blob->data = talloc_realloc_size(mem_ctx, blob->data, - blob->length + length); - NT_STATUS_HAVE_NO_MEMORY(blob->data); - memcpy(blob->data + blob->length, p, length); - blob->length += length; + NTSTATUS status; + size_t old_len = blob->length; + size_t new_len = old_len + length; + if (new_len < length || new_len < old_len) { + return NT_STATUS_NO_MEMORY; + } + + if ((const uint8_t *)p + length < (const uint8_t *)p) { + return NT_STATUS_NO_MEMORY; + } + + status = data_blob_realloc(mem_ctx, blob, new_len); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + memcpy(blob->data + old_len, p, length); return NT_STATUS_OK; } -- cgit From bc4af8dd5ef900f0ab46f4ddaf91e33772a3e029 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 13 Jan 2007 15:01:39 +0000 Subject: r20730: this can be const metze (This used to be commit 181db920476a9ebddeee1ebea17be0baf85ea59e) --- source4/lib/util/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 3253d52ee7..7230aa9d99 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -150,7 +150,7 @@ _PUBLIC_ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) /** print the data_blob as hex string **/ -_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) { int i; char *hex_string; -- cgit From c186fb94637f2cd502327c38d95c6d7a2b2dbd11 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 13 Jan 2007 15:39:49 +0000 Subject: r20734: always terminate the string... so that an empty data_blob gets '\0' as "" string metze (This used to be commit 4f5daa830a3c02a05ba1bc7f32eedbe1d52640a1) --- source4/lib/util/data_blob.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 7230aa9d99..e04bd65331 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -163,6 +163,7 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) for (i = 0; i < blob->length; i++) slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]); + hex_string[(blob->length*2)] = '\0'; return hex_string; } -- cgit From d291b8bf933e7595ac2967602d90918c286e3429 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 20 Jun 2007 04:15:39 +0000 Subject: r23551: Change data_blob_equal to data_blob_cmp, suitable for sorting with qsort(). Andrew Bartlett (This used to be commit 96ef5259c63ad6245c94c40d6059d736b1534183) --- source4/lib/util/data_blob.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index e04bd65331..ca04b70eb2 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -130,21 +130,23 @@ _PUBLIC_ void data_blob_clear_free(DATA_BLOB *d) /** check if two data blobs are equal **/ -_PUBLIC_ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) +_PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2) { - if (d1->length != d2->length) { - return False; + int ret; + if (d1->data == NULL && d2->data != NULL) { + return -1; } - if (d1->data == d2->data) { - return True; + if (d1->data != NULL && d2->data == NULL) { + return 1; } - if (d1->data == NULL || d2->data == NULL) { - return False; + if (d1->data == d2->data) { + return d1->length - d2->length; } - if (memcmp(d1->data, d2->data, d1->length) == 0) { - return True; + ret = memcmp(d1->data, d2->data, MIN(d1->length, d2->length)); + if (ret == 0) { + return d1->length - d2->length; } - return False; + return ret; } /** -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/util/data_blob.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index ca04b70eb2..df8e793835 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 0b91f3916430d0271eab867675d44c5439de40c2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 29 Aug 2007 13:07:03 +0000 Subject: r24780: More work allowing libutil to be used by external users. (This used to be commit 31993cf67b816a184a4a4e92ef8ca2532c797190) --- source4/lib/util/data_blob.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index df8e793835..117043f95c 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -196,38 +196,37 @@ _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) /** realloc a data_blob **/ -_PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) +_PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, length); - NT_STATUS_HAVE_NO_MEMORY(blob->data); + if (blob->data == NULL) + return false; blob->length = length; - return NT_STATUS_OK; + return true; } /** append some data to a data blob **/ -_PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, +_PUBLIC_ bool data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { - NTSTATUS status; size_t old_len = blob->length; size_t new_len = old_len + length; if (new_len < length || new_len < old_len) { - return NT_STATUS_NO_MEMORY; + return false; } if ((const uint8_t *)p + length < (const uint8_t *)p) { - return NT_STATUS_NO_MEMORY; + return false; } - status = data_blob_realloc(mem_ctx, blob, new_len); - if (!NT_STATUS_IS_OK(status)) { - return status; + if (!data_blob_realloc(mem_ctx, blob, new_len)) { + return false; } memcpy(blob->data + old_len, p, length); - return NT_STATUS_OK; + return true; } -- cgit From dccf3f99e45137b6cd18c1de1c79808ad67130d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 13:27:14 +0000 Subject: r25027: Fix more warnings. (This used to be commit 5085c53fcfade614e83d21fc2c1a5bc43bb2a729) --- source4/lib/util/data_blob.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 117043f95c..b258e47bba 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -39,9 +39,9 @@ _PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *nam } if (p) { - ret.data = talloc_memdup(NULL, p, length); + ret.data = (uint8_t *)talloc_memdup(NULL, p, length); } else { - ret.data = talloc_size(NULL, length); + ret.data = talloc_array(NULL, uint8_t, length); } if (ret.data == NULL) { ret.length = 0; @@ -175,7 +175,7 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; - blob.data = discard_const(str); + blob.data = discard_const_p(uint8_t, str); blob.length = strlen(str); return blob; } @@ -187,7 +187,7 @@ _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) { DATA_BLOB blob; - blob.data = discard_const(p); + blob.data = discard_const_p(uint8_t, p); blob.length = length; return blob; } @@ -198,7 +198,7 @@ _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) **/ _PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { - blob->data = talloc_realloc_size(mem_ctx, blob->data, length); + blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, length); if (blob->data == NULL) return false; blob->length = length; -- cgit From 4ad97a1d0593b3401a352407009a99ead23f21f2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 21 Aug 2008 19:24:58 +1000 Subject: Don't walk past the end of ldb values. This is a partial fix towards bugs due to us walking past the end of what we think are strings in ldb. There is much more work to do in this area. Andrew Bartlett (This used to be commit 5805a9a8f35fd90fa4f718f73534817fa3bbdfd2) --- source4/lib/util/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/data_blob.c') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index b258e47bba..57b34b7ae7 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -176,7 +176,7 @@ _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; blob.data = discard_const_p(uint8_t, str); - blob.length = strlen(str); + blob.length = str ? strlen(str) : 0; return blob; } -- cgit