summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c267
-rw-r--r--source3/lib/memcache.c39
-rw-r--r--source3/lib/messages_local.c32
-rw-r--r--source3/lib/ms_fnmatch.c5
-rw-r--r--source3/lib/recvfile.c10
-rw-r--r--source3/lib/replace/libreplace.m41
-rw-r--r--source3/lib/replace/libreplace_network.m441
-rw-r--r--source3/lib/smbldap.c27
-rw-r--r--source3/lib/tdb/common/traverse.c22
-rw-r--r--source3/lib/util.c2
-rw-r--r--source3/lib/util_reg_api.c36
-rw-r--r--source3/lib/util_str.c52
-rw-r--r--source3/lib/util_unistr.c20
13 files changed, 340 insertions, 214 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 81b7238763..b1a5393461 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -515,7 +515,7 @@ size_t convert_string(charset_t from, charset_t to,
* true
* @note -1 is not accepted for srclen.
*
- * @return True if new buffer was correctly allocated, and string was
+ * @return true if new buffer was correctly allocated, and string was
* converted.
*
* Ensure the srclen contains the terminating zero.
@@ -749,24 +749,22 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
*
* @param srclen length of source buffer.
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
* @note -1 is not accepted for srclen.
*
- * @returns Size in bytes of the converted string; or -1 in case of error.
- **/
-size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
- void const *src, size_t srclen, void *dst,
- bool allow_bad_conv)
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
+ */
+bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
+ void const *src, size_t srclen, void *dst,
+ size_t *converted_size, bool allow_bad_conv)
{
void **dest = (void **)dst;
- size_t dest_len;
*dest = NULL;
- if (!convert_string_allocate(ctx, from, to, src, srclen, dest,
- &dest_len, allow_bad_conv))
- return (size_t)-1;
- if (*dest == NULL)
- return (size_t)-1;
- return dest_len;
+ return convert_string_allocate(ctx, from, to, src, srclen, dest,
+ converted_size, allow_bad_conv);
}
size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
@@ -774,10 +772,10 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
size_t size;
smb_ucs2_t *buffer;
- size = push_ucs2_allocate(&buffer, src);
- if (size == (size_t)-1) {
+ if (!push_ucs2_allocate(&buffer, src, &size)) {
return (size_t)-1;
}
+
if (!strupper_w(buffer) && (dest == src)) {
free(buffer);
return srclen;
@@ -816,20 +814,25 @@ char *strdup_upper(const char *s)
if (*p) {
/* MB case. */
- size_t size, size2;
+ size_t converted_size, converted_size2;
smb_ucs2_t *buffer = NULL;
SAFE_FREE(out_buffer);
if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, s,
- strlen(s) + 1, (void **)(void *)&buffer, &size,
- True)) {
+ strlen(s) + 1,
+ (void **)(void *)&buffer,
+ &converted_size, True))
+ {
return NULL;
}
strupper_w(buffer);
if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, buffer,
- size, (void **)(void *)&out_buffer, &size2, True)) {
+ converted_size,
+ (void **)(void *)&out_buffer,
+ &converted_size2, True))
+ {
TALLOC_FREE(buffer);
return NULL;
}
@@ -871,36 +874,33 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
if (*p) {
/* MB case. */
- size_t size;
+ size_t converted_size, converted_size2;
smb_ucs2_t *ubuf = NULL;
/* We're not using the ascii buffer above. */
TALLOC_FREE(out_buffer);
- size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE,
- s, strlen(s)+1,
- (void *)&ubuf,
- True);
- if (size == (size_t)-1) {
+ if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, s,
+ strlen(s)+1, (void *)&ubuf,
+ &converted_size, True))
+ {
return NULL;
}
strupper_w(ubuf);
- size = convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX,
- ubuf, size,
- (void *)&out_buffer,
- True);
+ if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, ubuf,
+ converted_size, (void *)&out_buffer,
+ &converted_size2, True))
+ {
+ TALLOC_FREE(ubuf);
+ return NULL;
+ }
/* Don't need the intermediate buffer
* anymore.
*/
-
TALLOC_FREE(ubuf);
-
- if (size == (size_t)-1) {
- return NULL;
- }
}
return out_buffer;
@@ -912,7 +912,9 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
smb_ucs2_t *buffer = NULL;
if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen,
- (void **)(void *)&buffer, &size, True)) {
+ (void **)(void *)&buffer, &size,
+ True))
+ {
smb_panic("failed to create UCS2 buffer");
}
if (!strlower_w(buffer) && (dest == src)) {
@@ -930,49 +932,45 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
char *strdup_lower(const char *s)
{
- size_t size;
+ size_t converted_size;
smb_ucs2_t *buffer = NULL;
char *out_buffer;
- size = push_ucs2_allocate(&buffer, s);
- if (size == -1 || !buffer) {
+ if (!push_ucs2_allocate(&buffer, s, &converted_size)) {
return NULL;
}
strlower_w(buffer);
- size = pull_ucs2_allocate(&out_buffer, buffer);
- SAFE_FREE(buffer);
-
- if (size == (size_t)-1) {
+ if (!pull_ucs2_allocate(&out_buffer, buffer, &converted_size)) {
+ SAFE_FREE(buffer);
return NULL;
}
+ SAFE_FREE(buffer);
+
return out_buffer;
}
char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s)
{
- size_t size;
+ size_t converted_size;
smb_ucs2_t *buffer = NULL;
char *out_buffer;
- size = push_ucs2_talloc(ctx, &buffer, s);
- if (size == -1 || !buffer) {
- TALLOC_FREE(buffer);
+ if (!push_ucs2_talloc(ctx, &buffer, s, &converted_size)) {
return NULL;
}
strlower_w(buffer);
- size = pull_ucs2_talloc(ctx, &out_buffer, buffer);
- TALLOC_FREE(buffer);
-
- if (size == (size_t)-1) {
- TALLOC_FREE(out_buffer);
+ if (!pull_ucs2_talloc(ctx, &out_buffer, buffer, &converted_size)) {
+ TALLOC_FREE(buffer);
return NULL;
}
+ TALLOC_FREE(buffer);
+
return out_buffer;
}
@@ -1049,8 +1047,7 @@ size_t push_ascii_nstring(void *dest, const char *src)
smb_ucs2_t *buffer;
conv_silent = True;
- buffer_len = push_ucs2_allocate(&buffer, src);
- if (buffer_len == (size_t)-1) {
+ if (!push_ucs2_allocate(&buffer, src, &buffer_len)) {
smb_panic("failed to create UCS2 buffer");
}
@@ -1081,16 +1078,13 @@ size_t push_ascii_nstring(void *dest, const char *src)
Push and malloc an ascii string. src and dest null terminated.
********************************************************************/
-size_t push_ascii_allocate(char **dest, const char *src)
+bool push_ascii_allocate(char **dest, const char *src, size_t *converted_size)
{
- size_t dest_len, src_len = strlen(src)+1;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len,
- (void **)dest, &dest_len, True))
- return (size_t)-1;
- else
- return dest_len;
+ return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
@@ -1172,7 +1166,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
int flags)
{
char *dest = NULL;
- size_t dest_len = 0;
+ size_t converted_size;
#ifdef DEVELOPER
/* Ensure we never use the braindead "malloc" varient. */
@@ -1203,13 +1197,15 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
}
if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest,
- &dest_len, True))
- dest_len = 0;
+ &converted_size, True))
+ {
+ converted_size = 0;
+ }
- if (dest_len && dest) {
+ if (converted_size && dest) {
/* Did we already process the terminating zero ? */
- if (dest[dest_len-1] != 0) {
- dest[dest_len-1] = 0;
+ if (dest[converted_size - 1] != 0) {
+ dest[converted_size - 1] = 0;
}
} else if (dest) {
dest[0] = 0;
@@ -1311,16 +1307,20 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
* allocating a buffer using talloc().
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
- * or -1 in case of error.
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
+bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
+ size_t *converted_size)
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True);
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len,
+ (void **)dest, converted_size, True);
}
@@ -1328,21 +1328,21 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
* Copy a string from a unix char* src to a UCS2 destination, allocating a buffer
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
- * or -1 in case of error.
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
+bool push_ucs2_allocate(smb_ucs2_t **dest, const char *src,
+ size_t *converted_size)
{
- size_t dest_len, src_len = strlen(src)+1;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len,
- (void **)dest, &dest_len, True))
- return (size_t)-1;
- else
- return dest_len;
+ return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
@@ -1394,36 +1394,41 @@ size_t push_utf8_fstring(void *dest, const char *src)
* Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
+bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+ size_t *converted_size)
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest, True);
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len,
+ (void**)dest, converted_size, True);
}
/**
* Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t push_utf8_allocate(char **dest, const char *src)
+bool push_utf8_allocate(char **dest, const char *src, size_t *converted_size)
{
- size_t dest_len, src_len = strlen(src)+1;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len,
- (void **)dest, &dest_len, True))
- return (size_t)-1;
- else
- return dest_len;
+ return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
@@ -1564,14 +1569,8 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx,
src_len &= ~1;
}
- dest_len = convert_string_talloc(ctx,
- CH_UTF16LE,
- CH_UNIX,
- src,
- src_len,
- (void *)&dest,
- True);
- if (dest_len == (size_t)-1) {
+ if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len,
+ (void *)&dest, &dest_len, True)) {
dest_len = 0;
}
@@ -1614,83 +1613,103 @@ size_t pull_ucs2_fstring(char *dest, const void *src)
* Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src)
+bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
+ size_t *converted_size)
{
size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
+
*dest = NULL;
- return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True);
+ return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
* Copy a string from a UCS2 src to a unix char * destination, allocating a buffer
*
* @param dest always set at least to NULL
- *
- * @returns The number of bytes occupied by the string in the destination
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src)
+bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src,
+ size_t *converted_size)
{
- size_t dest_len, src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
+ size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
+
*dest = NULL;
- if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len,
- (void **)dest, &dest_len, True))
- return (size_t)-1;
- else
- return dest_len;
+ return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
* Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
+bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+ size_t *converted_size)
{
size_t src_len = strlen(src)+1;
+
*dest = NULL;
- return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True);
+ return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
* Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t pull_utf8_allocate(char **dest, const char *src)
+bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size)
{
- size_t dest_len, src_len = strlen(src)+1;
+ size_t src_len = strlen(src)+1;
+
*dest = NULL;
- if (!convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len,
- (void **)dest, &dest_len, True))
- return (size_t)-1;
- else
- return dest_len;
+ return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
* Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc
*
* @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
*
- * @returns The number of bytes occupied by the string in the destination
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
**/
-size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
+bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+ size_t *converted_size)
{
size_t src_len = strlen(src)+1;
+
*dest = NULL;
- return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, True);
+ return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
diff --git a/source3/lib/memcache.c b/source3/lib/memcache.c
index 6dee61af50..e1426bc811 100644
--- a/source3/lib/memcache.c
+++ b/source3/lib/memcache.c
@@ -120,11 +120,11 @@ static int memcache_compare(struct memcache_element *e, enum memcache_number n,
{
DATA_BLOB this_key, this_value;
- if ((int)e->n < (int)n) return -1;
- if ((int)e->n > (int)n) return 1;
+ if ((int)e->n < (int)n) return 1;
+ if ((int)e->n > (int)n) return -1;
- if (e->keylength < key.length) return -1;
- if (e->keylength > key.length) return 1;
+ if (e->keylength < key.length) return 1;
+ if (e->keylength > key.length) return -1;
memcache_element_parse(e, &this_key, &this_value);
return memcmp(this_key.data, key.data, key.length);
@@ -357,10 +357,18 @@ void memcache_flush(struct memcache *cache, enum memcache_number n)
return;
}
+ /*
+ * First, find *any* element of number n
+ */
+
while (true) {
struct memcache_element *elem = memcache_node2elem(node);
struct rb_node *next;
+ if ((int)elem->n == (int)n) {
+ break;
+ }
+
if ((int)elem->n < (int)n) {
next = node->rb_right;
}
@@ -373,15 +381,36 @@ void memcache_flush(struct memcache *cache, enum memcache_number n)
node = next;
}
- node = rb_next(node);
if (node == NULL) {
return;
}
+ /*
+ * Then, find the leftmost element with number n
+ */
+
+ while (true) {
+ struct rb_node *prev = rb_prev(node);
+ struct memcache_element *elem;
+
+ if (prev == NULL) {
+ break;
+ }
+ elem = memcache_node2elem(prev);
+ if ((int)elem->n != (int)n) {
+ break;
+ }
+ node = prev;
+ }
+
while (node != NULL) {
struct memcache_element *e = memcache_node2elem(node);
struct rb_node *next = rb_next(node);
+ if (e->n != n) {
+ break;
+ }
+
memcache_delete_element(cache, e);
node = next;
}
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c
index 0cd482647a..f436afc2ff 100644
--- a/source3/lib/messages_local.c
+++ b/source3/lib/messages_local.c
@@ -65,8 +65,8 @@ static void sig_usr1(void)
static int messaging_tdb_destructor(struct messaging_backend *tdb_ctx)
{
- TDB_CONTEXT *tdb = (TDB_CONTEXT *)tdb_ctx->private_data;
- tdb_close(tdb);
+ struct tdb_wrap *tdb = (struct tdb_wrap *)tdb_ctx->private_data;
+ TALLOC_FREE(tdb);
return 0;
}
@@ -79,16 +79,16 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
struct messaging_backend **presult)
{
struct messaging_backend *result;
- TDB_CONTEXT *tdb;
+ struct tdb_wrap *tdb;
if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) {
DEBUG(0, ("talloc failed\n"));
return NT_STATUS_NO_MEMORY;
}
- tdb = tdb_open_log(lock_path("messages.tdb"),
- 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
- O_RDWR|O_CREAT,0600);
+ tdb = tdb_wrap_open(result, lock_path("messages.tdb"),
+ 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
+ O_RDWR|O_CREAT,0600);
if (!tdb) {
NTSTATUS status = map_nt_error_from_unix(errno);
@@ -101,7 +101,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
sec_init();
/* Activate the per-hashchain freelist */
- tdb_set_max_dead(tdb, 5);
+ tdb_set_max_dead(tdb->tdb, 5);
CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1);
@@ -293,7 +293,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
struct messaging_rec *rec;
NTSTATUS status;
TDB_DATA key;
- TDB_CONTEXT *tdb = (TDB_CONTEXT *)backend->private_data;
+ struct tdb_wrap *tdb = (struct tdb_wrap *)backend->private_data;
TALLOC_CTX *frame = talloc_stackframe();
/* NULL pointer means implicit length zero. */
@@ -310,12 +310,12 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
key = message_key_pid(frame, pid);
- if (tdb_chainlock(tdb, key) == -1) {
+ if (tdb_chainlock(tdb->tdb, key) == -1) {
TALLOC_FREE(frame);
return NT_STATUS_LOCK_NOT_GRANTED;
}
- status = messaging_tdb_fetch(tdb, key, talloc_tos(), &msg_array);
+ status = messaging_tdb_fetch(tdb->tdb, key, talloc_tos(), &msg_array);
if (!NT_STATUS_IS_OK(status)) {
goto done;
@@ -345,7 +345,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
msg_array->messages = rec;
msg_array->num_messages += 1;
- status = messaging_tdb_store(tdb, key, msg_array);
+ status = messaging_tdb_store(tdb->tdb, key, msg_array);
if (!NT_STATUS_IS_OK(status)) {
goto done;
@@ -356,11 +356,11 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
DEBUG(2, ("pid %s doesn't exist - deleting messages record\n",
procid_str_static(&pid)));
- tdb_delete(tdb, message_key_pid(talloc_tos(), pid));
+ tdb_delete(tdb->tdb, message_key_pid(talloc_tos(), pid));
}
done:
- tdb_chainunlock(tdb, key);
+ tdb_chainunlock(tdb->tdb, key);
TALLOC_FREE(frame);
return status;
}
@@ -409,7 +409,8 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb,
void message_dispatch(struct messaging_context *msg_ctx)
{
struct messaging_array *msg_array = NULL;
- TDB_CONTEXT *tdb = (TDB_CONTEXT *)(msg_ctx->local->private_data);
+ struct tdb_wrap *tdb = (struct tdb_wrap *)
+ (msg_ctx->local->private_data);
uint32 i;
if (!received_signal)
@@ -420,7 +421,8 @@ void message_dispatch(struct messaging_context *msg_ctx)
received_signal = 0;
- if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb, NULL, &msg_array))) {
+ if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb->tdb, NULL,
+ &msg_array))) {
return;
}
diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c
index 8b69f1c2d2..ca534467fa 100644
--- a/source3/lib/ms_fnmatch.c
+++ b/source3/lib/ms_fnmatch.c
@@ -154,6 +154,7 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
struct max_n *max_n = NULL;
struct max_n *max_n_free = NULL;
struct max_n one_max_n;
+ size_t converted_size;
if (ISDOTDOT(string)) {
string = ".";
@@ -169,11 +170,11 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
}
}
- if (push_ucs2_allocate(&p, pattern) == (size_t)-1) {
+ if (!push_ucs2_allocate(&p, pattern, &converted_size)) {
return -1;
}
- if (push_ucs2_allocate(&s, string) == (size_t)-1) {
+ if (!push_ucs2_allocate(&s, string, &converted_size)) {
SAFE_FREE(p);
return -1;
}
diff --git a/source3/lib/recvfile.c b/source3/lib/recvfile.c
index 6e20933350..513742ce8f 100644
--- a/source3/lib/recvfile.c
+++ b/source3/lib/recvfile.c
@@ -58,6 +58,11 @@ static ssize_t default_sys_recvfile(int fromfd,
size_t total_written = 0;
char *buffer = NULL;
+ DEBUG(10,("default_sys_recvfile: from = %d, to = %d, "
+ "offset=%.0f, count = %lu\n",
+ fromfd, tofd, (double)offset,
+ (unsigned long)count));
+
if (count == 0) {
return 0;
}
@@ -143,6 +148,11 @@ ssize_t sys_recvfile(int fromfd,
static bool try_splice_call = true;
size_t total_written = 0;
+ DEBUG(10,("sys_recvfile: from = %d, to = %d, "
+ "offset=%.0f, count = %lu\n",
+ fromfd, tofd, (double)offset,
+ (unsigned long)count));
+
if (count == 0) {
return 0;
}
diff --git a/source3/lib/replace/libreplace.m4 b/source3/lib/replace/libreplace.m4
index 2b33d97989..6a85ff5a82 100644
--- a/source3/lib/replace/libreplace.m4
+++ b/source3/lib/replace/libreplace.m4
@@ -96,7 +96,6 @@ fi
AC_CHECK_HEADERS(sys/syslog.h syslog.h)
AC_CHECK_HEADERS(sys/time.h time.h)
AC_CHECK_HEADERS(stdarg.h vararg.h)
-AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
AC_CHECK_HEADERS(sys/mount.h mntent.h)
AC_CHECK_HEADERS(stropts.h)
diff --git a/source3/lib/replace/libreplace_network.m4 b/source3/lib/replace/libreplace_network.m4
index 5ab71f160a..f2d177b165 100644
--- a/source3/lib/replace/libreplace_network.m4
+++ b/source3/lib/replace/libreplace_network.m4
@@ -8,6 +8,7 @@ LIBREPLACE_NETWORK_LIBS=""
AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
+AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
dnl we need to check that net/if.h really can be used, to cope with hpux
dnl where including it always fails
@@ -62,6 +63,46 @@ AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
fi
fi
+AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
+ AC_TRY_COMPILE(
+ [
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+ ],[
+struct sockaddr_in sock; sock.sin_len = sizeof(sock);
+ ],[
+ libreplace_cv_HAVE_SOCK_SIN_LEN=yes
+ ],[
+ libreplace_cv_HAVE_SOCK_SIN_LEN=no
+ ])
+])
+if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
+ AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
+fi
+
+############################################
+# check for unix domain sockets
+AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
+ AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+ ],[
+struct sockaddr_un sunaddr;
+sunaddr.sun_family = AF_UNIX;
+ ],[
+ libreplace_cv_HAVE_UNIXSOCKET=yes
+ ],[
+ libreplace_cv_HAVE_UNIXSOCKET=no
+ ])
+])
+if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
+ AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
+fi
+
dnl The following test is roughl taken from the cvs sources.
dnl
dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 65a039b119..9fb16f8927 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -298,6 +298,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
{
char **values;
char *result;
+ size_t converted_size;
if (attribute == NULL) {
return NULL;
@@ -317,7 +318,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
return NULL;
}
- if (pull_utf8_talloc(mem_ctx, &result, values[0]) == (size_t)-1) {
+ if (!pull_utf8_talloc(mem_ctx, &result, values[0], &converted_size)) {
DEBUG(10, ("pull_utf8_talloc failed\n"));
ldap_value_free(values);
return NULL;
@@ -430,6 +431,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
if (value != NULL) {
char *utf8_value = NULL;
+ size_t converted_size;
j = 0;
if (mods[i]->mod_values != NULL) {
@@ -442,7 +444,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
/* notreached. */
}
- if (push_utf8_allocate(&utf8_value, value) == (size_t)-1) {
+ if (!push_utf8_allocate(&utf8_value, value, &converted_size)) {
smb_panic("smbldap_set_mod: String conversion failure!");
/* notreached. */
}
@@ -1176,6 +1178,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state,
char *utf8_filter;
time_t endtime = time(NULL)+lp_ldap_timeout();
struct timeval timeout;
+ size_t converted_size;
SMB_ASSERT(ldap_state);
@@ -1206,7 +1209,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state,
ZERO_STRUCT(ldap_state->last_rebind);
}
- if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) {
+ if (!push_utf8_allocate(&utf8_filter, filter, &converted_size)) {
return LDAP_NO_MEMORY;
}
@@ -1372,12 +1375,13 @@ int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *at
int attempts = 0;
char *utf8_dn;
time_t endtime = time(NULL)+lp_ldap_timeout();
+ size_t converted_size;
SMB_ASSERT(ldap_state);
DEBUG(5,("smbldap_modify: dn => [%s]\n", dn ));
- if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) {
+ if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) {
return LDAP_NO_MEMORY;
}
@@ -1415,12 +1419,13 @@ int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs
int attempts = 0;
char *utf8_dn;
time_t endtime = time(NULL)+lp_ldap_timeout();
+ size_t converted_size;
SMB_ASSERT(ldap_state);
DEBUG(5,("smbldap_add: dn => [%s]\n", dn ));
- if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) {
+ if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) {
return LDAP_NO_MEMORY;
}
@@ -1458,12 +1463,13 @@ int smbldap_delete(struct smbldap_state *ldap_state, const char *dn)
int attempts = 0;
char *utf8_dn;
time_t endtime = time(NULL)+lp_ldap_timeout();
+ size_t converted_size;
SMB_ASSERT(ldap_state);
DEBUG(5,("smbldap_delete: dn => [%s]\n", dn ));
- if (push_utf8_allocate(&utf8_dn, dn) == (size_t)-1) {
+ if (!push_utf8_allocate(&utf8_dn, dn, &converted_size)) {
return LDAP_NO_MEMORY;
}
@@ -1630,14 +1636,16 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx,
char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry)
{
char *utf8_dn, *unix_dn;
+ size_t converted_size;
utf8_dn = ldap_get_dn(ld, entry);
if (!utf8_dn) {
DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n"));
return NULL;
}
- if (pull_utf8_allocate(&unix_dn, utf8_dn) == (size_t)-1) {
- DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 [%s]\n", utf8_dn));
+ if (!pull_utf8_allocate(&unix_dn, utf8_dn, &converted_size)) {
+ DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 "
+ "[%s]\n", utf8_dn));
return NULL;
}
ldap_memfree(utf8_dn);
@@ -1648,13 +1656,14 @@ char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry)
LDAPMessage *entry)
{
char *utf8_dn, *unix_dn;
+ size_t converted_size;
utf8_dn = ldap_get_dn(ld, entry);
if (!utf8_dn) {
DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n"));
return NULL;
}
- if (pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn) == (size_t)-1) {
+ if (!pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn, &converted_size)) {
DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 "
"[%s]\n", utf8_dn));
return NULL;
diff --git a/source3/lib/tdb/common/traverse.c b/source3/lib/tdb/common/traverse.c
index 07b0c23858..69c81e6e98 100644
--- a/source3/lib/tdb/common/traverse.c
+++ b/source3/lib/tdb/common/traverse.c
@@ -204,18 +204,23 @@ int tdb_traverse_read(struct tdb_context *tdb,
{
struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK };
int ret;
+ bool in_transaction = (tdb->transaction != NULL);
/* we need to get a read lock on the transaction lock here to
cope with the lock ordering semantics of solaris10 */
- if (tdb_transaction_lock(tdb, F_RDLCK)) {
- return -1;
+ if (!in_transaction) {
+ if (tdb_transaction_lock(tdb, F_RDLCK)) {
+ return -1;
+ }
}
tdb->traverse_read++;
ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
tdb->traverse_read--;
- tdb_transaction_unlock(tdb);
+ if (!in_transaction) {
+ tdb_transaction_unlock(tdb);
+ }
return ret;
}
@@ -232,20 +237,25 @@ int tdb_traverse(struct tdb_context *tdb,
{
struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK };
int ret;
+ bool in_transaction = (tdb->transaction != NULL);
if (tdb->read_only || tdb->traverse_read) {
return tdb_traverse_read(tdb, fn, private_data);
}
- if (tdb_transaction_lock(tdb, F_WRLCK)) {
- return -1;
+ if (!in_transaction) {
+ if (tdb_transaction_lock(tdb, F_WRLCK)) {
+ return -1;
+ }
}
tdb->traverse_write++;
ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
tdb->traverse_write--;
- tdb_transaction_unlock(tdb);
+ if (!in_transaction) {
+ tdb_transaction_unlock(tdb);
+ }
return ret;
}
diff --git a/source3/lib/util.c b/source3/lib/util.c
index a6b436cc6a..68524a21ce 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3074,7 +3074,7 @@ struct server_id interpret_pid(const char *pid_string)
result.pid = pid;
}
else if (sscanf(pid_string, "%u", &pid) == 1) {
- result.vnn = NONCLUSTER_VNN;
+ result.vnn = get_my_vnn();
result.pid = pid;
}
else {
diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c
index 60031d97d3..8f28e9c282 100644
--- a/source3/lib/util_reg_api.c
+++ b/source3/lib/util_reg_api.c
@@ -91,16 +91,15 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx,
goto error;
}
- value->v.sz.len = convert_string_talloc(
- value, CH_UTF16LE, CH_UNIX, tmp, length+2,
- &value->v.sz.str, False);
-
- SAFE_FREE(tmp);
-
- if (value->v.sz.len == (size_t)-1) {
+ if (!convert_string_talloc(value, CH_UTF16LE, CH_UNIX, tmp,
+ length+2, &value->v.sz.str,
+ &value->v.sz.len, False)) {
+ SAFE_FREE(tmp);
err = WERR_INVALID_PARAM;
goto error;
}
+
+ SAFE_FREE(tmp);
break;
}
case REG_MULTI_SZ:
@@ -143,11 +142,13 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx,
}
case REG_SZ:
case REG_EXPAND_SZ: {
- presult->length = convert_string_talloc(
- mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str,
- MIN(value->v.sz.len, strlen(value->v.sz.str)+1),
- (void *)&(presult->data), False);
- if (presult->length == (size_t)-1) {
+ if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16LE,
+ value->v.sz.str,
+ MIN(value->v.sz.len,
+ strlen(value->v.sz.str)+1),
+ (void *)&(presult->data),
+ &presult->length, False))
+ {
return WERR_NOMEM;
}
break;
@@ -176,12 +177,13 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx,
/* convert the single strings */
for (count = 0; count < value->v.multi_sz.num_strings; count++)
{
- string_lengths[count] = convert_string_talloc(
- strings, CH_UNIX, CH_UTF16LE,
- value->v.multi_sz.strings[count],
+ if (!convert_string_talloc(strings, CH_UNIX,
+ CH_UTF16LE, value->v.multi_sz.strings[count],
strlen(value->v.multi_sz.strings[count])+1,
- (void *)&strings[count], false);
- if (string_lengths[count] == (size_t)-1) {
+ (void *)&strings[count],
+ &string_lengths[count], false))
+ {
+
TALLOC_FREE(tmp_ctx);
return WERR_NOMEM;
}
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 6310e2464d..5a08f7bc2c 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -208,16 +208,14 @@ int StrCaseCmp(const char *s, const char *t)
return +1;
}
- size = push_ucs2_allocate(&buffer_s, ps);
- if (size == (size_t)-1) {
+ if (!push_ucs2_allocate(&buffer_s, ps, &size)) {
return strcmp(ps, pt);
/* Not quite the right answer, but finding the right one
under this failure case is expensive, and it's pretty
close */
}
- size = push_ucs2_allocate(&buffer_t, pt);
- if (size == (size_t)-1) {
+ if (!push_ucs2_allocate(&buffer_t, pt, &size)) {
SAFE_FREE(buffer_s);
return strcmp(ps, pt);
/* Not quite the right answer, but finding the right one
@@ -271,16 +269,14 @@ int StrnCaseCmp(const char *s, const char *t, size_t len)
return 0;
}
- size = push_ucs2_allocate(&buffer_s, ps);
- if (size == (size_t)-1) {
+ if (!push_ucs2_allocate(&buffer_s, ps, &size)) {
return strncmp(ps, pt, len-n);
/* Not quite the right answer, but finding the right one
under this failure case is expensive,
and it's pretty close */
}
- size = push_ucs2_allocate(&buffer_t, pt);
- if (size == (size_t)-1) {
+ if (!push_ucs2_allocate(&buffer_t, pt, &size)) {
SAFE_FREE(buffer_s);
return strncmp(ps, pt, len-n);
/* Not quite the right answer, but finding the right one
@@ -480,9 +476,9 @@ char *skip_string(const char *base, size_t len, char *buf)
size_t str_charnum(const char *s)
{
- size_t ret;
+ size_t ret, converted_size;
smb_ucs2_t *tmpbuf2 = NULL;
- if (push_ucs2_allocate(&tmpbuf2, s) == (size_t)-1) {
+ if (!push_ucs2_allocate(&tmpbuf2, s, &converted_size)) {
return 0;
}
ret = strlen_w(tmpbuf2);
@@ -498,9 +494,9 @@ size_t str_charnum(const char *s)
size_t str_ascii_charnum(const char *s)
{
- size_t ret;
+ size_t ret, converted_size;
char *tmpbuf2 = NULL;
- if (push_ascii_allocate(&tmpbuf2, s) == (size_t)-1) {
+ if (!push_ascii_allocate(&tmpbuf2, s, &converted_size)) {
return 0;
}
ret = strlen(tmpbuf2);
@@ -610,8 +606,9 @@ bool strhasupper(const char *s)
{
smb_ucs2_t *tmp, *p;
bool ret;
+ size_t converted_size;
- if (push_ucs2_allocate(&tmp, s) == -1) {
+ if (!push_ucs2_allocate(&tmp, s, &converted_size)) {
return false;
}
@@ -634,8 +631,9 @@ bool strhaslower(const char *s)
{
smb_ucs2_t *tmp, *p;
bool ret;
+ size_t converted_size;
- if (push_ucs2_allocate(&tmp, s) == -1) {
+ if (!push_ucs2_allocate(&tmp, s, &converted_size)) {
return false;
}
@@ -659,8 +657,9 @@ size_t count_chars(const char *s,char c)
smb_ucs2_t *ptr;
int count;
smb_ucs2_t *alloc_tmpbuf = NULL;
+ size_t converted_size;
- if (push_ucs2_allocate(&alloc_tmpbuf, s) == (size_t)-1) {
+ if (!push_ucs2_allocate(&alloc_tmpbuf, s, &converted_size)) {
return 0;
}
@@ -1410,6 +1409,7 @@ char *strchr_m(const char *src, char c)
smb_ucs2_t *p;
const char *s;
char *ret;
+ size_t converted_size;
/* characters below 0x3F are guaranteed to not appear in
non-initial position in multi-byte charsets */
@@ -1435,7 +1435,7 @@ char *strchr_m(const char *src, char c)
s = src;
#endif
- if (push_ucs2_allocate(&ws, s)==(size_t)-1) {
+ if (!push_ucs2_allocate(&ws, s, &converted_size)) {
/* Wrong answer, but what can we do... */
return strchr(src, c);
}
@@ -1445,7 +1445,7 @@ char *strchr_m(const char *src, char c)
return NULL;
}
*p = 0;
- if (pull_ucs2_allocate(&s2, ws)==(size_t)-1) {
+ if (!pull_ucs2_allocate(&s2, ws, &converted_size)) {
SAFE_FREE(ws);
/* Wrong answer, but what can we do... */
return strchr(src, c);
@@ -1504,8 +1504,9 @@ char *strrchr_m(const char *s, char c)
char *s2 = NULL;
smb_ucs2_t *p;
char *ret;
+ size_t converted_size;
- if (push_ucs2_allocate(&ws,s)==(size_t)-1) {
+ if (!push_ucs2_allocate(&ws, s, &converted_size)) {
/* Wrong answer, but what can we do. */
return strrchr(s, c);
}
@@ -1515,7 +1516,7 @@ char *strrchr_m(const char *s, char c)
return NULL;
}
*p = 0;
- if (pull_ucs2_allocate(&s2,ws)==(size_t)-1) {
+ if (!pull_ucs2_allocate(&s2, ws, &converted_size)) {
SAFE_FREE(ws);
/* Wrong answer, but what can we do. */
return strrchr(s, c);
@@ -1538,8 +1539,9 @@ char *strnrchr_m(const char *s, char c, unsigned int n)
char *s2 = NULL;
smb_ucs2_t *p;
char *ret;
+ size_t converted_size;
- if (push_ucs2_allocate(&ws,s)==(size_t)-1) {
+ if (!push_ucs2_allocate(&ws, s, &converted_size)) {
/* Too hard to try and get right. */
return NULL;
}
@@ -1549,7 +1551,7 @@ char *strnrchr_m(const char *s, char c, unsigned int n)
return NULL;
}
*p = 0;
- if (pull_ucs2_allocate(&s2,ws)==(size_t)-1) {
+ if (!pull_ucs2_allocate(&s2, ws, &converted_size)) {
SAFE_FREE(ws);
/* Too hard to try and get right. */
return NULL;
@@ -1572,7 +1574,7 @@ char *strstr_m(const char *src, const char *findstr)
char *s2;
char *retp;
- size_t findstr_len = 0;
+ size_t converted_size, findstr_len = 0;
/* for correctness */
if (!findstr[0]) {
@@ -1608,12 +1610,12 @@ char *strstr_m(const char *src, const char *findstr)
s = src;
#endif
- if (push_ucs2_allocate(&src_w, src) == (size_t)-1) {
+ if (!push_ucs2_allocate(&src_w, src, &converted_size)) {
DEBUG(0,("strstr_m: src malloc fail\n"));
return NULL;
}
- if (push_ucs2_allocate(&find_w, findstr) == (size_t)-1) {
+ if (!push_ucs2_allocate(&find_w, findstr, &converted_size)) {
SAFE_FREE(src_w);
DEBUG(0,("strstr_m: find malloc fail\n"));
return NULL;
@@ -1628,7 +1630,7 @@ char *strstr_m(const char *src, const char *findstr)
}
*p = 0;
- if (pull_ucs2_allocate(&s2, src_w) == (size_t)-1) {
+ if (!pull_ucs2_allocate(&s2, src_w, &converted_size)) {
SAFE_FREE(src_w);
SAFE_FREE(find_w);
DEBUG(0,("strstr_m: dest malloc fail\n"));
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 84ee673a67..76235ad041 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -312,14 +312,12 @@ int rpcstr_pull_unistr2_fstring(char *dest, UNISTR2 *src)
char *rpcstr_pull_unistr2_talloc(TALLOC_CTX *ctx, const UNISTR2 *src)
{
char *dest = NULL;
- size_t dest_len = convert_string_talloc(ctx,
- CH_UTF16LE,
- CH_UNIX,
- src->buffer,
- src->uni_str_len * 2,
- (void *)&dest,
- true);
- if (dest_len == (size_t)-1) {
+ size_t dest_len;
+
+ if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src->buffer,
+ src->uni_str_len * 2, (void *)&dest,
+ &dest_len, true))
+ {
return NULL;
}
@@ -364,7 +362,11 @@ int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags)
int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
{
- return push_ucs2_talloc(ctx, dest, src);
+ size_t size;
+ if (push_ucs2_talloc(ctx, dest, src, &size))
+ return size;
+ else
+ return -1;
}
/*******************************************************************