[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha7-1034-g786447d
Andrew Bartlett
abartlet at samba.org
Tue Apr 14 04:05:16 GMT 2009
The branch, master has been updated
via 786447dea021f97a44582009bf33e28d972dacb4 (commit)
via 97af7f1ed14bcd00b7606ba6e0379589064cd233 (commit)
via 3b3e21bd9ba701a97e752205263a7903619541c7 (commit)
via 4786a493f70070dce6de4cbe488c9de1bdbb75ad (commit)
from 41e4f12c482082d6e622d1fdc830e38853cdbd8b (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 786447dea021f97a44582009bf33e28d972dacb4
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 18 17:36:35 2009 +1100
s3:charcnv remove now unused malloc() based conversion functions
commit 97af7f1ed14bcd00b7606ba6e0379589064cd233
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Apr 14 12:43:34 2009 +1000
Add some harmless use of talloc_tos() in ntlm_auth
commit 3b3e21bd9ba701a97e752205263a7903619541c7
Author: Andrew Bartlett <abartlet at samba.org>
Date: Thu Mar 19 12:20:11 2009 +1100
Convert Samba3 to use the common lib/util/charset API
This removes calls to push_*_allocate() and pull_*_allocate(), as well
as convert_string_allocate, as they are not in the common API
To allow transition to a common charcnv in future, provide Samba4-like
strupper functions in source3/lib/charcnv.c
(the actual implementation remains distinct, but the API is now shared)
Andrew Bartlett
commit 4786a493f70070dce6de4cbe488c9de1bdbb75ad
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Mar 17 14:04:43 2009 +1100
Solve some of the conflict between Samba3 and Samba4 push_string
This renames push_string in Samba3 into push_string_base and
push_string_check for the two different use cases.
This should allow push_string to be imported from Samba4, using it's
calling conventions.
-----------------------------------------------------------------------
Summary of changes:
source3/include/proto.h | 26 +--
source3/include/safe_string.h | 22 +--
source3/lib/charcnv.c | 335 +++++++++------------------------
source3/lib/smbldap.c | 9 +-
source3/lib/substitute.c | 8 +-
source3/lib/util_reg.c | 2 +-
source3/lib/util_str.c | 92 +++++-----
source3/libads/ldap.c | 16 +-
source3/libsmb/clifile.c | 8 +-
source3/libsmb/climessage.c | 4 +-
source3/libsmb/clistr.c | 24 ++-
source3/libsmb/clitrans.c | 10 +-
source3/libsmb/ntlmssp_parse.c | 14 +-
source3/libsmb/smbencrypt.c | 20 +-
source3/nmbd/nmbd_sendannounce.c | 10 +-
source3/passdb/pdb_ldap.c | 22 +-
source3/passdb/secrets.c | 8 +-
source3/smbd/mangle_hash.c | 20 +-
source3/smbd/srvstr.c | 4 +-
source3/smbd/statcache.c | 2 +-
source3/utils/net_conf.c | 6 +-
source3/utils/net_usershare.c | 12 +-
source3/utils/ntlm_auth.c | 4 +-
source3/utils/ntlm_auth_diagnostics.c | 26 ++--
source3/web/cgi.c | 4 +-
source3/web/statuspage.c | 4 +-
source3/web/swat.c | 20 +-
27 files changed, 278 insertions(+), 454 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source3/include/proto.h b/source3/include/proto.h
index cc44242..b8ba8c0 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -348,30 +348,23 @@ void init_iconv(void);
size_t convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
void *dest, size_t destlen, bool allow_bad_conv);
-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 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);
+char *strupper_talloc(TALLOC_CTX *ctx, const char *s);
size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen);
-char *strdup_lower(const char *s);
char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s);
+char *strlower_talloc(TALLOC_CTX *ctx, const char *s);
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);
-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);
-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);
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,
@@ -382,19 +375,19 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx,
size_t pull_ucs2_fstring(char *dest, const void *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,
- size_t dest_len, int flags);
+size_t push_string_check_fn(const char *function, unsigned int line,
+ void *dest, const char *src,
+ size_t dest_len, int flags);
+size_t push_string_base(const char *function, unsigned int line,
+ const char *base, uint16 flags2,
+ void *dest, const char *src,
+ size_t dest_len, int flags);
size_t pull_string_fn(const char *function,
unsigned int line,
const void *base_ptr,
@@ -1835,7 +1828,6 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path,
int scope, const char *expr, const char **attrs,
bool (*fn)(ADS_STRUCT *, char *, void **, void *),
void *data_area);
-void ads_memfree(ADS_STRUCT *ads, void *mem);
char *ads_parent_dn(const char *dn);
ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx);
ADS_STATUS ads_mod_str(TALLOC_CTX *ctx, ADS_MODLIST *mods,
diff --git a/source3/include/safe_string.h b/source3/include/safe_string.h
index a723096..43e4341 100644
--- a/source3/include/safe_string.h
+++ b/source3/include/safe_string.h
@@ -130,13 +130,9 @@ size_t __unsafe_string_function_usage_here_char__(void);
safe_strcat_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
dest,src,maxlength)
-#define push_string(base_ptr, dest, src, dest_len, flags) \
- push_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
- base_ptr, 0, dest, src, dest_len, flags)
-
-#define pull_string(base_ptr, smb_flags2, dest, src, dest_len, src_len, flags) \
- pull_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
- base_ptr, smb_flags2, dest, src, dest_len, src_len, flags)
+#define push_string_check(dest, src, dest_len, flags) \
+ push_string_check_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
+ dest, src, dest_len, flags)
#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
pull_string_talloc_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
@@ -182,15 +178,10 @@ size_t __unsafe_string_function_usage_here_char__(void);
? __unsafe_string_function_usage_here__() \
: safe_strcat_fn(fn_name, fn_line, (d), (s), (max_len)))
-#define push_string_fn2(fn_name, fn_line, base_ptr, flags2, dest, src, dest_len, flags) \
- (CHECK_STRING_SIZE(dest, dest_len) \
- ? __unsafe_string_function_usage_here_size_t__() \
- : push_string_fn(fn_name, fn_line, base_ptr, flags2, dest, src, dest_len, flags))
-
-#define pull_string_fn2(fn_name, fn_line, base_ptr, smb_flags2, dest, src, dest_len, src_len, flags) \
+#define push_string_check_fn2(fn_name, fn_line, dest, src, dest_len, flags) \
(CHECK_STRING_SIZE(dest, dest_len) \
? __unsafe_string_function_usage_here_size_t__() \
- : pull_string_fn(fn_name, fn_line, base_ptr, smb_flags2, dest, src, dest_len, src_len, flags))
+ : push_string_check_fn(fn_name, fn_line, dest, src, dest_len, flags))
#define pull_string_talloc_fn2(fn_name, fn_line, ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
pull_string_talloc_fn(fn_name, fn_line, ctx, base_ptr, smb_flags2, dest, src, src_len, flags)
@@ -214,8 +205,7 @@ size_t __unsafe_string_function_usage_here_char__(void);
#define safe_strcpy_fn2 safe_strcpy_fn
#define safe_strcat_fn2 safe_strcat_fn
-#define push_string_fn2 push_string_fn
-#define pull_string_fn2 pull_string_fn
+#define push_string_check_fn2 push_string_check_fn
#define pull_string_talloc_fn2 pull_string_talloc_fn
#define clistr_push_fn2 clistr_push_fn
#define clistr_pull_fn2 clistr_pull_fn
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 03b32c1..567ee7b 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -518,14 +518,12 @@ size_t convert_string(charset_t from, charset_t to,
}
/**
- * Convert between character sets, allocating a new buffer for the result.
+ * Convert between character sets, allocating a new buffer using talloc for the result.
*
- * @param ctx TALLOC_CTX to use to allocate with. If NULL use malloc.
- * (this is a bad interface and needs fixing. JRA).
* @param srclen length of source buffer.
* @param dest always set at least to NULL
- * @param converted_size set to the size of the allocated buffer on return
- * true
+ * @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.
*
* @return true if new buffer was correctly allocated, and string was
@@ -535,11 +533,11 @@ size_t convert_string(charset_t from, charset_t to,
*
* I hate the goto's in this function. It's embarressing.....
* There has to be a cleaner way to do this. JRA.
- **/
+ */
+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)
-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 i_len, o_len, destlen = (srclen * 3) / 2;
size_t retval;
@@ -576,7 +574,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
if (!conv_silent)
- DEBUG(0,("convert_string_allocate: Conversion not supported.\n"));
+ DEBUG(0,("convert_string_talloc: Conversion not supported.\n"));
errno = EOPNOTSUPP;
return false;
}
@@ -587,7 +585,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
if ((destlen*2)+2 < destlen) {
/* wrapped ! abort. */
if (!conv_silent)
- DEBUG(0, ("convert_string_allocate: destlen wrapped !\n"));
+ DEBUG(0, ("convert_string_talloc: destlen wrapped !\n"));
if (!ctx)
SAFE_FREE(outbuf);
errno = EOPNOTSUPP;
@@ -597,14 +595,10 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
}
/* +2 is for ucs2 null termination. */
- if (ctx) {
- ob = (char *)TALLOC_REALLOC(ctx, ob, destlen + 2);
- } else {
- ob = (char *)SMB_REALLOC(ob, destlen + 2);
- }
+ ob = (char *)TALLOC_REALLOC(ctx, ob, destlen + 2);
if (!ob) {
- DEBUG(0, ("convert_string_allocate: realloc failed!\n"));
+ DEBUG(0, ("convert_string_talloc: realloc failed!\n"));
errno = ENOMEM;
return false;
}
@@ -623,7 +617,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
case EINVAL:
reason="Incomplete multibyte sequence";
if (!conv_silent)
- DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf));
+ DEBUG(3,("convert_string_talloc: Conversion error: %s(%s)\n",reason,inbuf));
if (allow_bad_conv)
goto use_as_is;
break;
@@ -632,7 +626,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
case EILSEQ:
reason="Illegal multibyte sequence";
if (!conv_silent)
- DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf));
+ DEBUG(3,("convert_string_talloc: Conversion error: %s(%s)\n",reason,inbuf));
if (allow_bad_conv)
goto use_as_is;
break;
@@ -640,11 +634,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
if (!conv_silent)
DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf));
/* smb_panic(reason); */
- if (ctx) {
- TALLOC_FREE(ob);
- } else {
- SAFE_FREE(ob);
- }
+ TALLOC_FREE(ob);
return false;
}
@@ -657,15 +647,11 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
*/
if (o_len > 1024) {
/* We're shrinking here so we know the +2 is safe from wrap. */
- if (ctx) {
- ob = (char *)TALLOC_REALLOC(ctx,ob,destlen + 2);
- } else {
- ob = (char *)SMB_REALLOC(ob,destlen + 2);
- }
+ ob = (char *)TALLOC_REALLOC(ctx,ob,destlen + 2);
}
if (destlen && !ob) {
- DEBUG(0, ("convert_string_allocate: out of memory!\n"));
+ DEBUG(0, ("convert_string_talloc: out of memory!\n"));
errno = ENOMEM;
return false;
}
@@ -763,35 +749,12 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
}
}
-/**
- * Convert between character sets, allocating a new buffer using talloc for the result.
- *
- * @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.
- *
- * @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;
-
- *dest = NULL;
- 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)
{
size_t size;
smb_ucs2_t *buffer;
- if (!push_ucs2_allocate(&buffer, src, &size)) {
+ if (!push_ucs2_talloc(NULL, &buffer, src, &size)) {
return (size_t)-1;
}
@@ -801,71 +764,11 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
}
size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True);
- free(buffer);
+ TALLOC_FREE(buffer);
return size;
}
/**
- strdup() a unix string to upper case.
-**/
-
-char *strdup_upper(const char *s)
-{
- char *out_buffer = SMB_STRDUP(s);
- const unsigned char *p = (const unsigned char *)s;
- unsigned char *q = (unsigned char *)out_buffer;
-
- if (!q) {
- return NULL;
- }
-
- /* this is quite a common operation, so we want it to be
- fast. We optimise for the ascii case, knowing that all our
- supported multi-byte character sets are ascii-compatible
- (ie. they match for the first 128 chars) */
-
- while (*p) {
- if (*p & 0x80)
- break;
- *q++ = toupper_ascii_fast(*p);
- p++;
- }
-
- if (*p) {
- /* MB case. */
- 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,
- &converted_size, True))
- {
- return NULL;
- }
-
- strupper_w(buffer);
-
- if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, buffer,
- converted_size,
- (void **)(void *)&out_buffer,
- &converted_size2, True))
- {
- TALLOC_FREE(buffer);
- return NULL;
- }
-
- /* Don't need the intermediate buffer
- * anymore.
- */
- TALLOC_FREE(buffer);
- }
-
- return out_buffer;
-}
-
-/**
talloc_strdup() a unix string to upper case.
**/
@@ -925,51 +828,31 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
return out_buffer;
}
+char *strupper_talloc(TALLOC_CTX *ctx, const char *s) {
+ return talloc_strdup_upper(ctx, s);
+}
+
+
size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
{
size_t size;
smb_ucs2_t *buffer = NULL;
- if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen,
- (void **)(void *)&buffer, &size,
- True))
+ if (!convert_string_talloc(NULL, CH_UNIX, CH_UTF16LE, src, srclen,
+ (void **)(void *)&buffer, &size,
+ True))
{
smb_panic("failed to create UCS2 buffer");
}
if (!strlower_w(buffer) && (dest == src)) {
- SAFE_FREE(buffer);
+ TALLOC_FREE(buffer);
return srclen;
}
size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True);
- SAFE_FREE(buffer);
+ TALLOC_FREE(buffer);
return size;
}
-/**
- strdup() a unix string to lower case.
-**/
-
-char *strdup_lower(const char *s)
-{
- size_t converted_size;
- smb_ucs2_t *buffer = NULL;
- char *out_buffer;
-
- if (!push_ucs2_allocate(&buffer, s, &converted_size)) {
- return NULL;
- }
-
- strlower_w(buffer);
-
- 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)
{
@@ -993,6 +876,9 @@ char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s)
return out_buffer;
}
+char *strlower_talloc(TALLOC_CTX *ctx, const char *s) {
+ return talloc_strdup_lower(ctx, s);
+}
size_t ucs2_align(const void *base_ptr, const void *p, int flags)
{
@@ -1066,7 +952,7 @@ size_t push_ascii_nstring(void *dest, const char *src)
smb_ucs2_t *buffer;
conv_silent = True;
- if (!push_ucs2_allocate(&buffer, src, &buffer_len)) {
+ if (!push_ucs2_talloc(NULL, &buffer, src, &buffer_len)) {
smb_panic("failed to create UCS2 buffer");
}
@@ -1088,8 +974,8 @@ size_t push_ascii_nstring(void *dest, const char *src)
}
((char *)dest)[dest_len] = '\0';
- SAFE_FREE(buffer);
conv_silent = False;
+ TALLOC_FREE(buffer);
return dest_len;
}
@@ -1097,13 +983,13 @@ size_t push_ascii_nstring(void *dest, const char *src)
Push and malloc an ascii string. src and dest null terminated.
********************************************************************/
-bool push_ascii_allocate(char **dest, const char *src, size_t *converted_size)
+bool push_ascii_talloc(TALLOC_CTX *mem_ctx, char **dest, const char *src, size_t *converted_size)
{
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len,
- (void **)dest, converted_size, True);
+ return convert_string_talloc(mem_ctx, CH_UNIX, CH_DOS, src, src_len,
+ (void **)dest, converted_size, True);
}
/**
@@ -1179,21 +1065,14 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len,
**/
static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
- char **ppdest,
- const void *src,
- size_t src_len,
- int flags)
+ char **ppdest,
+ const void *src,
+ size_t src_len,
+ int flags)
{
char *dest = NULL;
size_t dest_len;
-#ifdef DEVELOPER
- /* Ensure we never use the braindead "malloc" varient. */
- if (ctx == NULL) {
- smb_panic("NULL talloc CTX in pull_ascii_base_talloc\n");
- }
-#endif
-
*ppdest = NULL;
if (!src_len) {
@@ -1229,7 +1108,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
/* src_len != -1 here. */
- if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest,
+ if (!convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, &dest,
&dest_len, True)) {
dest_len = 0;
}
@@ -1371,27 +1250,6 @@ bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
/**
--
Samba Shared Repository
More information about the samba-cvs
mailing list