[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-2537-geb28153

Volker Lendecke vlendec at samba.org
Tue May 20 21:13:53 GMT 2008


The branch, v3-3-test has been updated
       via  eb281532b1721ded39c39bb00c26202080dcd735 (commit)
       via  dbb4d8107a61051d8bcf6c4c69ee976efc50b961 (commit)
       via  6b189dabc562d86dcaa685419d0cb6ea276f100d (commit)
      from  80e700e3bd73f2ffa38046bdcba7f532e25198ef (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit eb281532b1721ded39c39bb00c26202080dcd735
Author: Volker Lendecke <vl at samba.org>
Date:   Tue May 20 23:08:42 2008 +0200

    Fix type error in debug message

commit dbb4d8107a61051d8bcf6c4c69ee976efc50b961
Author: Volker Lendecke <vl at samba.org>
Date:   Tue May 20 23:06:38 2008 +0200

    Fix some signed/unsigned warnings

commit 6b189dabc562d86dcaa685419d0cb6ea276f100d
Author: Tim Prouty <tim.prouty at isilon.com>
Date:   Tue Apr 29 14:36:24 2008 -0700

    Cleanup size_t return values in callers of convert_string_allocate
    
    This patch is the second iteration of an inside-out conversion to cleanup
    functions in charcnv.c returning size_t == -1 to indicate failure.

-----------------------------------------------------------------------

Summary of changes:
 source/include/proto.h               |   33 +++--
 source/lib/charcnv.c                 |  267 ++++++++++++++++++----------------
 source/lib/ms_fnmatch.c              |    5 +-
 source/lib/smbldap.c                 |   27 +++-
 source/lib/util_reg_api.c            |   36 +++--
 source/lib/util_str.c                |   52 ++++---
 source/lib/util_unistr.c             |   20 ++-
 source/libads/ldap.c                 |   63 ++++++---
 source/libads/ldap_printer.c         |   19 ++-
 source/libgpo/gpext/registry.c       |   23 ++-
 source/libgpo/gpo_ini.c              |   12 +-
 source/librpc/ndr/ndr_string.c       |  157 ++++++++++----------
 source/libsmb/clikrb5.c              |    9 +-
 source/libsmb/clirap.c               |   14 +-
 source/libsmb/smbencrypt.c           |   12 +-
 source/modules/vfs_catia.c           |    5 +-
 source/passdb/pdb_ldap.c             |   78 +++++++---
 source/passdb/secrets.c              |    9 +-
 source/printing/nt_printing.c        |    5 +-
 source/rpcclient/cmd_wkssvc.c        |    7 +-
 source/smbd/lanman.c                 |    9 +-
 source/smbd/mangle_hash.c            |   11 +-
 source/smbd/message.c                |   13 +-
 source/smbd/negprot.c                |    5 +-
 source/smbd/sesssetup.c              |    2 +-
 source/smbd/trans2.c                 |   24 ++-
 source/torture/t_push_ucs2.c         |    5 +-
 source/utils/ntlm_auth_diagnostics.c |    5 +-
 source/web/statuspage.c              |    3 +-
 source/web/swat.c                    |   14 +-
 30 files changed, 541 insertions(+), 403 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/include/proto.h b/source/include/proto.h
index bf6328d..a0354a3 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -366,9 +366,9 @@ size_t convert_string(charset_t from, charset_t to,
 bool convert_string_allocate(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);
-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);
+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);
 size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen);
 char *strdup_upper(const char *s);
 char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s);
@@ -379,16 +379,17 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags);
 size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags);
 size_t push_ascii_fstring(void *dest, const char *src);
 size_t push_ascii_nstring(void *dest, const char *src);
-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 pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
 size_t pull_ascii_fstring(char *dest, const void *src);
 size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src);
 size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags);
-size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src);
-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 push_utf8_fstring(void *dest, const char *src);
-size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
-size_t push_utf8_allocate(char **dest, const char *src);
+bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+		      size_t *converted_size);
+bool push_utf8_allocate(char **dest, const char *src, size_t *converted_size);
 size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
 size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx,
 			const void *base_ptr,
@@ -397,11 +398,17 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx,
 			size_t src_len,
 			int flags);
 size_t pull_ucs2_fstring(char *dest, const void *src);
-size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src);
-size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src);
-size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
-size_t pull_utf8_allocate(char **dest, const char *src);
-size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
+bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
+		      size_t *converted_size);
+bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src,
+			size_t *converted_size);
+bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+		      size_t *converted_size);
+bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size);
+bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
+		      size_t *converted_size);
+bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+		       size_t *converted_size);
 size_t push_string_fn(const char *function, unsigned int line,
 		      const void *base_ptr, uint16 flags2,
 		      void *dest, const char *src,
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c
index 81b7238..b1a5393 100644
--- a/source/lib/charcnv.c
+++ b/source/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)


-- 
Samba Shared Repository


More information about the samba-cvs mailing list