Convert Samba3 to use the common lib/util/charset code (partial)
authorAndrew Bartlett <abartlet@samba.org>
Wed, 18 Mar 2009 04:12:36 +0000 (15:12 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 18 Mar 2009 05:55:01 +0000 (16:55 +1100)
This parital commit has it's focus on converting Samba3 code to use
the common functions where possible, and exposes some of the
previously static common functions for use by what remains in
libsmb/charcnv.c

libsmb/charcnv.c contains the Samba-3 only wrapper functions still in use.

Andrew Bartlett

19 files changed:
lib/util/charset/charcnv.c
lib/util/charset/charset.h
lib/util/charset/util_unistr.c
libcli/auth/smbencrypt.c
source3/Makefile.in
source3/include/proto.h
source3/lib/charcnv.c
source3/lib/substitute.c
source3/lib/util_reg.c
source3/lib/util_str.c
source3/libsmb/clifile.c
source3/libsmb/climessage.c
source3/param/loadparm.c
source3/smbd/notify.c
source3/smbd/statcache.c
source3/utils/net_conf.c
source3/utils/net_usershare.c
source3/utils/ntlm_auth_diagnostics.c
source3/web/cgi.c

index 94d47a9f7f098b9f9f7bee3d60d1581d78d69f77..a77520a2cb9b567e37691b2f3f4eae085e411286 100644 (file)
@@ -23,6 +23,9 @@
 #include "includes.h"
 #include "system/iconv.h"
 
+/* We are quite valid to use strcasecmp here, work around the Samba3 'NEVER' macro */
+#undef strcasecmp
+
 /**
  * @file
  *
index 37c5acafafa105614ad0120939c5fc8c46aa0fd1..472a6645ea2454d213b1b364f85ef245d07f51bf 100644 (file)
@@ -105,7 +105,6 @@ char *strchr_m(const char *s, char c);
 size_t strlen_m_term(const char *s);
 size_t strlen_m_term_null(const char *s);
 size_t strlen_m(const char *s);
-char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength);
 void string_replace_m(char *s, char oldc, char newc);
 bool strcsequal_m(const char *s1,const char *s2);
 bool strequal_m(const char *s1, const char *s2);
@@ -124,15 +123,60 @@ bool strhaslower(const char *string);
 char *strrchr_m(const char *s, char c);
 char *strchr_m(const char *s, char c);
 
+ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags);
+/**
+ * Copy a string from a dos codepage source to a unix char* destination.
+ *
+ * The resulting string in "dest" is always null terminated.
+ *
+ * @param flags can have:
+ * <dl>
+ * <dt>STR_TERMINATE</dt>
+ * <dd>STR_TERMINATE means the string in @p src
+ * is null terminated, and src_len is ignored.</dd>
+ * </dl>
+ *
+ * @param src_len is the length of the source area in bytes.
+ * @returns the number of bytes occupied by the string in @p src.
+ **/
+ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
 bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
+/**
+ * Copy a string from a char* src to a unicode destination.
+ *
+ * @returns the number of bytes occupied by the string in the destination.
+ *
+ * @param flags can have:
+ *
+ * <dl>
+ * <dt>STR_TERMINATE <dd>means include the null termination.
+ * <dt>STR_UPPER     <dd>means uppercase in the destination.
+ * <dt>STR_NOALIGN   <dd>means don't do alignment.
+ * </dl>
+ *
+ * @param dest_len is the maximum length allowed in the
+ * destination. If dest_len is -1 then no maxiumum is used.
+ **/
+ssize_t push_ucs2(const char *base, void *dest, const char *src, size_t dest_len, int flags);
 bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, size_t *converted_size);
 bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
 bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
+/**
+ Copy a string from a ucs2 source to a unix char* destination.
+ Flags can have:
+  STR_TERMINATE means the string in src is null terminated.
+  STR_NOALIGN   means don't try to align.
+ if STR_TERMINATE is set then src_len is ignored if it is -1.
+ src_len is the length of the source area in bytes
+ Return the number of bytes occupied by the string in src.
+ The resulting string in "dest" is always null terminated.
+**/
+
+size_t pull_ucs2(const char *base, char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
 bool pull_ucs2_talloc(TALLOC_CTX *ctx, 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);
 ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags);
 ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
-
 bool convert_string_talloc(TALLOC_CTX *ctx, 
                                       charset_t from, charset_t to, 
                                       void const *src, size_t srclen, 
@@ -149,6 +193,10 @@ ssize_t iconv_talloc(TALLOC_CTX *mem_ctx,
                                       void *dest);
 
 extern struct smb_iconv_convenience *global_iconv_convenience;
+/**
+ * Destroy global_iconv_convenience allocated implictly by calling get_iconv_convenience() inside the charset routuines.  
+ **/
+void gfree_charcnv(void);
 
 codepoint_t next_codepoint(const char *str, size_t *size);
 
index ea2bfeab9f1556c30fd483dfdf99bd2d29856d9a..19f45bc1f7d9a8dbbae39c53b9b440e97ca4df4c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "system/locale.h"
+#undef strcasecmp
 
 struct smb_iconv_convenience *global_iconv_convenience = NULL;
 
@@ -30,6 +31,15 @@ static inline struct smb_iconv_convenience *get_iconv_convenience(void)
        return global_iconv_convenience;
 }
 
+/**
+ * Destroy global objects allocated implictly by calling get_iconv_convenience()
+ **/
+void gfree_charcnv(void)
+{
+       talloc_free(global_iconv_convenience);
+       global_iconv_convenience = NULL;
+}
+
 /**
  Case insensitive string compararison
 **/
@@ -201,52 +211,6 @@ _PUBLIC_ void string_replace_m(char *s, char oldc, char newc)
        }
 }
 
-/**
- Paranoid strcpy into a buffer of given length (includes terminating
- zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
- and replaces with '_'. Deliberately does *NOT* check for multibyte
- characters. Don't change it !
-**/
-
-_PUBLIC_ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
-{
-       size_t len, i;
-
-       if (maxlength == 0) {
-               /* can't fit any bytes at all! */
-               return NULL;
-       }
-
-       if (!dest) {
-               DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
-               return NULL;
-       }
-
-       if (!src) {
-               *dest = 0;
-               return dest;
-       }  
-
-       len = strlen(src);
-       if (len >= maxlength)
-               len = maxlength - 1;
-
-       if (!other_safe_chars)
-               other_safe_chars = "";
-
-       for(i = 0; i < len; i++) {
-               int val = (src[i] & 0xff);
-               if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val))
-                       dest[i] = src[i];
-               else
-                       dest[i] = '_';
-       }
-
-       dest[i] = '\0';
-
-       return dest;
-}
-
 /**
  Count the number of UCS2 characters in a string. Normally this will
  be the same as the number of bytes in a string for single byte strings,
@@ -636,7 +600,7 @@ _PUBLIC_ size_t count_chars_m(const char *s, char c)
  * @param dest_len the maximum length in bytes allowed in the
  * destination.  If @p dest_len is -1 then no maximum is used.
  **/
-static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
+ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
 {
        size_t src_len;
        ssize_t ret;
@@ -691,7 +655,7 @@ _PUBLIC_ bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, s
  * @param src_len is the length of the source area in bytes.
  * @returns the number of bytes occupied by the string in @p src.
  **/
-static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
+ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
 {
        size_t ret;
 
@@ -730,7 +694,7 @@ static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t s
  * @param dest_len is the maximum length allowed in the
  * destination. If dest_len is -1 then no maxiumum is used.
  **/
-static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags)
+ssize_t push_ucs2(const char *base, void *dest, const char *src, size_t dest_len, int flags)
 {
        size_t len=0;
        size_t src_len = strlen(src);
@@ -741,7 +705,7 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags
                if (tmpbuf == NULL) {
                        return -1;
                }
-               ret = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER);
+               ret = push_ucs2(base, dest, tmpbuf, dest_len, flags & ~STR_UPPER);
                talloc_free(tmpbuf);
                return ret;
        }
@@ -749,7 +713,7 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags
        if (flags & STR_TERMINATE)
                src_len++;
 
-       if (ucs2_align(NULL, dest, flags)) {
+       if (ucs2_align(base, dest, flags)) {
                *(char *)dest = 0;
                dest = (void *)((char *)dest + 1);
                if (dest_len) dest_len--;
@@ -813,11 +777,11 @@ _PUBLIC_ bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, si
  The resulting string in "dest" is always null terminated.
 **/
 
-static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
+size_t pull_ucs2(const char *base, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
 {
        size_t ret;
 
-       if (ucs2_align(NULL, src, flags)) {
+       if (ucs2_align(base, src, flags)) {
                src = (const void *)((const char *)src + 1);
                if (src_len > 0)
                        src_len--;
@@ -906,14 +870,13 @@ _PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int f
        if (flags & STR_ASCII) {
                return push_ascii(dest, src, dest_len, flags);
        } else if (flags & STR_UNICODE) {
-               return push_ucs2(dest, src, dest_len, flags);
+               return push_ucs2(NULL, dest, src, dest_len, flags);
        } else {
                smb_panic("push_string requires either STR_ASCII or STR_UNICODE flag to be set");
                return -1;
        }
 }
 
-
 /**
  Copy a string from a unicode or ascii source (depending on
  the packet flags) to a char* destination.
@@ -933,7 +896,7 @@ _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_
        if (flags & STR_ASCII) {
                return pull_ascii(dest, src, dest_len, src_len, flags);
        } else if (flags & STR_UNICODE) {
-               return pull_ucs2(dest, src, dest_len, src_len, flags);
+               return pull_ucs2(NULL, dest, src, dest_len, src_len, flags);
        } else {
                smb_panic("pull_string requires either STR_ASCII or STR_UNICODE flag to be set");
                return -1;
index f5a73feadcd7ccc4a630c88209adf4d8c593a841..bce52aadce9e5979d275c1b2c8a11c87fd06d153 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "includes.h"
 #include "system/time.h"
-#include "auth/ntlmssp/ntlmssp.h"
 #include "auth/ntlmssp/msrpc_parse.h"
 #include "../lib/crypto/crypto.h"
 #include "libcli/auth/libcli_auth.h"
index b7b83c68e642608bc544523e547876075379e080..90f81049f834e8d57de01afb1ccd3ba2c6663e12 100644 (file)
@@ -352,7 +352,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/util_transfer_file.o ../lib/async_req/async_req.o \
          ../lib/async_req/async_sock.o ../lib/async_req/async_req_ntstatus.o \
          $(TDB_LIB_OBJ) \
-         $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \
+         $(VERSION_OBJ) lib/charcnv.o ../lib/util/charset/charcnv.o lib/debug.o lib/fault.o \
          lib/interface.o lib/pidfile.o \
          lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \
          lib/username.o \
@@ -360,7 +360,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \
          lib/wins_srv.o \
          lib/util_str.o lib/clobber.o lib/util_sid.o lib/util_uuid.o \
-         lib/util_unistr.o ../lib/util/charset/util_unistr.c lib/util_file.o \
+         ../lib/util/charset/util_unistr.o lib/util_file.o \
          lib/util.o lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
          lib/substitute.o lib/dbwrap_util.o \
          lib/ms_fnmatch.o lib/select.o lib/errmap_unix.o \
index 75facf926ebf3a18c7977da3bfc779f728c86448..edcbbae820b37b08735a5562a59e5ceb656fd9ee 100644 (file)
@@ -344,7 +344,7 @@ 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,
+bool convert_string_allocate(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);
@@ -354,21 +354,17 @@ 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);
 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,
                        char **ppdest,
@@ -390,6 +386,10 @@ bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
 size_t push_string_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,
+                       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,
index ccd49d72633553198b759d4a8129f4cdd20334a8..6037dcc94253988060262aaa17a37f4d42a00ccd 100644 (file)
 */
 #include "includes.h"
 
-/* We can parameterize this if someone complains.... JRA. */
-
-char lp_failed_convert_char(void)
-{
-       return '_';
-}
-
-/**
- * @file
- *
- * @brief Character-set conversion routines built on our iconv.
- *
- * @note Samba's internal character set (at least in the 3.0 series)
- * is always the same as the one for the Unix filesystem.  It is
- * <b>not</b> necessarily UTF-8 and may be different on machines that
- * need i18n filenames to be compatible with Unix software.  It does
- * have to be a superset of ASCII.  All multibyte sequences must start
- * with a byte with the high bit set.
- *
- * @sa lib/iconv.c
- */
-
-
-static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
-static bool conv_silent; /* Should we do a debug if the conversion fails ? */
-static bool initialized;
-
-/**
- * Return the name of a charset to give to iconv().
- **/
-static const char *charset_name(charset_t ch)
-{
-       const char *ret = NULL;
-
-       if (ch == CH_UTF16LE) ret = "UTF-16LE";
-       else if (ch == CH_UTF16BE) ret = "UTF-16BE";
-       else if (ch == CH_UNIX) ret = lp_unix_charset();
-       else if (ch == CH_DOS) ret = lp_dos_charset();
-       else if (ch == CH_DISPLAY) ret = lp_display_charset();
-       else if (ch == CH_UTF8) ret = "UTF8";
-
-#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
-       if (ret && !strcmp(ret, "LOCALE")) {
-               const char *ln = NULL;
-
-#ifdef HAVE_SETLOCALE
-               setlocale(LC_ALL, "");
-#endif
-               ln = nl_langinfo(CODESET);
-               if (ln) {
-                       /* Check whether the charset name is supported
-                          by iconv */
-                       smb_iconv_t handle = smb_iconv_open(ln,"UCS-2LE");
-                       if (handle == (smb_iconv_t) -1) {
-                               DEBUG(5,("Locale charset '%s' unsupported, using ASCII instead\n", ln));
-                               ln = NULL;
-                       } else {
-                               DEBUG(5,("Substituting charset '%s' for LOCALE\n", ln));
-                               smb_iconv_close(handle);
-                       }
-               }
-               ret = ln;
-       }
-#endif
-
-       if (!ret || !*ret) ret = "ASCII";
-       return ret;
-}
-
-void lazy_initialize_conv(void)
-{
-       if (!initialized) {
-               load_case_tables();
-               init_iconv();
-               initialized = true;
-       }
-}
-
-/**
- * Destroy global objects allocated by init_iconv()
- **/
-void gfree_charcnv(void)
-{
-       int c1, c2;
-
-       for (c1=0;c1<NUM_CHARSETS;c1++) {
-               for (c2=0;c2<NUM_CHARSETS;c2++) {
-                       if ( conv_handles[c1][c2] ) {
-                               smb_iconv_close( conv_handles[c1][c2] );
-                               conv_handles[c1][c2] = 0;
-                       }
-               }
-       }
-       initialized = false;
-}
-
-/**
- * Initialize iconv conversion descriptors.
- *
- * This is called the first time it is needed, and also called again
- * every time the configuration is reloaded, because the charset or
- * codepage might have changed.
- **/
-void init_iconv(void)
-{
-       int c1, c2;
-       bool did_reload = False;
-
-       /* so that charset_name() works we need to get the UNIX<->UCS2 going
-          first */
-       if (!conv_handles[CH_UNIX][CH_UTF16LE])
-               conv_handles[CH_UNIX][CH_UTF16LE] = smb_iconv_open(charset_name(CH_UTF16LE), "ASCII");
-
-       if (!conv_handles[CH_UTF16LE][CH_UNIX])
-               conv_handles[CH_UTF16LE][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UTF16LE));
-
-       for (c1=0;c1<NUM_CHARSETS;c1++) {
-               for (c2=0;c2<NUM_CHARSETS;c2++) {
-                       const char *n1 = charset_name((charset_t)c1);
-                       const char *n2 = charset_name((charset_t)c2);
-                       if (conv_handles[c1][c2] &&
-                           strcmp(n1, conv_handles[c1][c2]->from_name) == 0 &&
-                           strcmp(n2, conv_handles[c1][c2]->to_name) == 0)
-                               continue;
-
-                       did_reload = True;
-
-                       if (conv_handles[c1][c2])
-                               smb_iconv_close(conv_handles[c1][c2]);
-
-                       conv_handles[c1][c2] = smb_iconv_open(n2,n1);
-                       if (conv_handles[c1][c2] == (smb_iconv_t)-1) {
-                               DEBUG(0,("init_iconv: Conversion from %s to %s not supported\n",
-                                        charset_name((charset_t)c1), charset_name((charset_t)c2)));
-                               if (c1 != CH_UTF16LE && c1 != CH_UTF16BE) {
-                                       n1 = "ASCII";
-                               }
-                               if (c2 != CH_UTF16LE && c2 != CH_UTF16BE) {
-                                       n2 = "ASCII";
-                               }
-                               DEBUG(0,("init_iconv: Attempting to replace with conversion from %s to %s\n",
-                                       n1, n2 ));
-                               conv_handles[c1][c2] = smb_iconv_open(n2,n1);
-                               if (!conv_handles[c1][c2]) {
-                                       DEBUG(0,("init_iconv: Conversion from %s to %s failed", n1, n2));
-                                       smb_panic("init_iconv: conv_handle initialization failed");
-                               }
-                       }
-               }
-       }
-
-       if (did_reload) {
-               /* XXX: Does this really get called every time the dos
-                * codepage changes? */
-               /* XXX: Is the did_reload test too strict? */
-               conv_silent = True;
-               init_valid_table();
-               conv_silent = False;
-       }
-}
-
-/**
- * Convert string from one encoding to another, making error checking etc
- * Slow path version - uses (slow) iconv.
- *
- * @param src pointer to source string (multibyte or singlebyte)
- * @param srclen length of the source string in bytes
- * @param dest pointer to destination string (multibyte or singlebyte)
- * @param destlen maximal length allowed for string
- * @param allow_bad_conv determines if a "best effort" conversion is acceptable (never returns errors)
- * @returns the number of bytes occupied in the destination
- *
- * Ensure the srclen contains the terminating zero.
- *
- **/
-
-static size_t convert_string_internal(charset_t from, charset_t to,
-                     void const *src, size_t srclen, 
-                     void *dest, size_t destlen, bool allow_bad_conv)
-{
-       size_t i_len, o_len;
-       size_t retval;
-       const char* inbuf = (const char*)src;
-       char* outbuf = (char*)dest;
-       smb_iconv_t descriptor;
-
-       lazy_initialize_conv();
-
-       descriptor = conv_handles[from][to];
-
-       if (srclen == (size_t)-1) {
-               if (from == CH_UTF16LE || from == CH_UTF16BE) {
-                       srclen = (strlen_w((const smb_ucs2_t *)src)+1) * 2;
-               } else {
-                       srclen = strlen((const char *)src)+1;
-               }
-       }
-
-
-       if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
-               if (!conv_silent)
-                       DEBUG(0,("convert_string_internal: Conversion not supported.\n"));
-               return (size_t)-1;
-       }
-
-       i_len=srclen;
-       o_len=destlen;
-
- again:
-
-       retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
-       if(retval==(size_t)-1) {
-               const char *reason="unknown error";
-               switch(errno) {
-                       case EINVAL:
-                               reason="Incomplete multibyte sequence";
-                               if (!conv_silent)
-                                       DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
-                               if (allow_bad_conv)
-                                       goto use_as_is;
-                               break;
-                       case E2BIG:
-                               reason="No more room"; 
-                               if (!conv_silent) {
-                                       if (from == CH_UNIX) {
-                                               DEBUG(3,("E2BIG: convert_string(%s,%s): srclen=%u destlen=%u - '%s'\n",
-                                                       charset_name(from), charset_name(to),
-                                                       (unsigned int)srclen, (unsigned int)destlen, (const char *)src));
-                                       } else {
-                                               DEBUG(3,("E2BIG: convert_string(%s,%s): srclen=%u destlen=%u\n",
-                                                       charset_name(from), charset_name(to),
-                                                       (unsigned int)srclen, (unsigned int)destlen));
-                                       }
-                               }
-                               break;
-                       case EILSEQ:
-                               reason="Illegal multibyte sequence";
-                               if (!conv_silent)
-                                       DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
-                               if (allow_bad_conv)
-                                       goto use_as_is;
-                               break;
-                       default:
-                               if (!conv_silent)
-                                       DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
-                               break;
-               }
-               /* smb_panic(reason); */
-       }
-       return destlen-o_len;
-
- use_as_is:
-
-       /* 
-        * Conversion not supported. This is actually an error, but there are so
-        * many misconfigured iconv systems and smb.conf's out there we can't just
-        * fail. Do a very bad conversion instead.... JRA.
-        */
-
-       {
-               if (o_len == 0 || i_len == 0)
-                       return destlen - o_len;
-
-               if (((from == CH_UTF16LE)||(from == CH_UTF16BE)) &&
-                               ((to != CH_UTF16LE)||(to != CH_UTF16BE))) {
-                       /* Can't convert from utf16 any endian to multibyte.
-                          Replace with the default fail char.
-                       */
-                       if (i_len < 2)
-                               return destlen - o_len;
-                       if (i_len >= 2) {
-                               *outbuf = lp_failed_convert_char();
-
-                               outbuf++;
-                               o_len--;
-
-                               inbuf += 2;
-                               i_len -= 2;
-                       }
-
-                       if (o_len == 0 || i_len == 0)
-                               return destlen - o_len;
-
-                       /* Keep trying with the next char... */
-                       goto again;
-
-               } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
-                       /* Can't convert to UTF16LE - just widen by adding the
-                          default fail char then zero.
-                       */
-                       if (o_len < 2)
-                               return destlen - o_len;
-
-                       outbuf[0] = lp_failed_convert_char();
-                       outbuf[1] = '\0';
-
-                       inbuf++;
-                       i_len--;
-
-                       outbuf += 2;
-                       o_len -= 2;
-
-                       if (o_len == 0 || i_len == 0)
-                               return destlen - o_len;
-
-                       /* Keep trying with the next char... */
-                       goto again;
-
-               } else if (from != CH_UTF16LE && from != CH_UTF16BE &&
-                               to != CH_UTF16LE && to != CH_UTF16BE) {
-                       /* Failed multibyte to multibyte. Just copy the default fail char and
-                               try again. */
-                       outbuf[0] = lp_failed_convert_char();
-
-                       inbuf++;
-                       i_len--;
-
-                       outbuf++;
-                       o_len--;
-
-                       if (o_len == 0 || i_len == 0)
-                               return destlen - o_len;
-
-                       /* Keep trying with the next char... */
-                       goto again;
-
-               } else {
-                       /* Keep compiler happy.... */
-                       return destlen - o_len;
-               }
-       }
-}
-
-/**
- * Convert string from one encoding to another, making error checking etc
- * Fast path version - handles ASCII first.
- *
- * @param src pointer to source string (multibyte or singlebyte)
- * @param srclen length of the source string in bytes, or -1 for nul terminated.
- * @param dest pointer to destination string (multibyte or singlebyte)
- * @param destlen maximal length allowed for string - *NEVER* -1.
- * @param allow_bad_conv determines if a "best effort" conversion is acceptable (never returns errors)
- * @returns the number of bytes occupied in the destination
- *
- * Ensure the srclen contains the terminating zero.
- *
- * This function has been hand-tuned to provide a fast path.
- * Don't change unless you really know what you are doing. JRA.
- **/
-
-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)
-{
-       /*
-        * NB. We deliberately don't do a strlen here if srclen == -1.
-        * This is very expensive over millions of calls and is taken
-        * care of in the slow path in convert_string_internal. JRA.
-        */
-
-#ifdef DEVELOPER
-       SMB_ASSERT(destlen != (size_t)-1);
-#endif
-
-       if (srclen == 0)
-               return 0;
-
-       if (from != CH_UTF16LE && from != CH_UTF16BE && to != CH_UTF16LE && to != CH_UTF16BE) {
-               const unsigned char *p = (const unsigned char *)src;
-               unsigned char *q = (unsigned char *)dest;
-               size_t slen = srclen;
-               size_t dlen = destlen;
-               unsigned char lastp = '\0';
-               size_t retval = 0;
-
-               /* If all characters are ascii, fast path here. */
-               while (slen && dlen) {
-                       if ((lastp = *p) <= 0x7f) {
-                               *q++ = *p++;
-                               if (slen != (size_t)-1) {
-                                       slen--;
-                               }
-                               dlen--;
-                               retval++;
-                               if (!lastp)
-                                       break;
-                       } else {
-#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
-                               goto general_case;
-#else
-                               return retval + convert_string_internal(from, to, p, slen, q, dlen, allow_bad_conv);
-#endif
-                       }
-               }
-               if (!dlen) {
-                       /* Even if we fast path we should note if we ran out of room. */
-                       if (((slen != (size_t)-1) && slen) ||
-                                       ((slen == (size_t)-1) && lastp)) {
-                               errno = E2BIG;
-                       }
-               }
-               return retval;
-       } else if (from == CH_UTF16LE && to != CH_UTF16LE) {
-               const unsigned char *p = (const unsigned char *)src;
-               unsigned char *q = (unsigned char *)dest;
-               size_t retval = 0;
-               size_t slen = srclen;
-               size_t dlen = destlen;
-               unsigned char lastp = '\0';
-
-               /* If all characters are ascii, fast path here. */
-               while (((slen == (size_t)-1) || (slen >= 2)) && dlen) {
-                       if (((lastp = *p) <= 0x7f) && (p[1] == 0)) {
-                               *q++ = *p;
-                               if (slen != (size_t)-1) {
-                                       slen -= 2;
-                               }
-                               p += 2;
-                               dlen--;
-                               retval++;
-                               if (!lastp)
-                                       break;
-                       } else {
-#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
-                               goto general_case;
-#else
-                               return retval + convert_string_internal(from, to, p, slen, q, dlen, allow_bad_conv);
-#endif
-                       }
-               }
-               if (!dlen) {
-                       /* Even if we fast path we should note if we ran out of room. */
-                       if (((slen != (size_t)-1) && slen) ||
-                                       ((slen == (size_t)-1) && lastp)) {
-                               errno = E2BIG;
-                       }
-               }
-               return retval;
-       } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
-               const unsigned char *p = (const unsigned char *)src;
-               unsigned char *q = (unsigned char *)dest;
-               size_t retval = 0;
-               size_t slen = srclen;
-               size_t dlen = destlen;
-               unsigned char lastp = '\0';
-
-               /* If all characters are ascii, fast path here. */
-               while (slen && (dlen >= 2)) {
-                       if ((lastp = *p) <= 0x7F) {
-                               *q++ = *p++;
-                               *q++ = '\0';
-                               if (slen != (size_t)-1) {
-                                       slen--;
-                               }
-                               dlen -= 2;
-                               retval += 2;
-                               if (!lastp)
-                                       break;
-                       } else {
-#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
-                               goto general_case;
-#else
-                               return retval + convert_string_internal(from, to, p, slen, q, dlen, allow_bad_conv);
-#endif
-                       }
-               }
-               if (!dlen) {
-                       /* Even if we fast path we should note if we ran out of room. */
-                       if (((slen != (size_t)-1) && slen) ||
-                                       ((slen == (size_t)-1) && lastp)) {
-                               errno = E2BIG;
-                       }
-               }
-               return retval;
-       }
-
-#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
-  general_case:
-#endif
-       return convert_string_internal(from, to, src, srclen, dest, destlen, allow_bad_conv);
-}
-
 /**
  * Convert between character sets, allocating a new buffer for the result.
  *
@@ -524,7 +42,7 @@ size_t convert_string(charset_t from, charset_t to,
  * There has to be a cleaner way to do this. JRA.
  **/
 
-bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
+bool convert_string_allocate(charset_t from, charset_t to,
                             void const *src, size_t srclen, void *dst,
                             size_t *converted_size, bool allow_bad_conv)
 {
@@ -734,307 +252,20 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
                        inbuf++;
                        i_len--;
 
-                       outbuf++;
-                       o_len--;
-
-                       if (o_len == 0 || i_len == 0)
-                               goto out;
-
-                       /* Keep trying with the next char... */
-                       goto again;
-
-               } else {
-                       /* Keep compiler happy.... */
-                       goto out;
-               }
-       }
-}
-
-/**
- * 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)) {
-               return (size_t)-1;
-       }
-
-       if (!strupper_w(buffer) && (dest == src)) {
-               free(buffer);
-               return srclen;
-       }
-
-       size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True);
-       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.
-**/
-
-char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
-{
-       char *out_buffer = talloc_strdup(ctx,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 *ubuf = NULL;
-
-               /* We're not using the ascii buffer above. */
-               TALLOC_FREE(out_buffer);
-
-               if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, s,
-                                          strlen(s)+1, (void *)&ubuf,
-                                          &converted_size, True))
-               {
-                       return NULL;
-               }
-
-               strupper_w(ubuf);
-
-               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);
-       }
-
-       return out_buffer;
-}
-
-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))
-       {
-               smb_panic("failed to create UCS2 buffer");
-       }
-       if (!strlower_w(buffer) && (dest == src)) {
-               SAFE_FREE(buffer);
-               return srclen;
-       }
-       size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True);
-       SAFE_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)
-{
-       size_t converted_size;
-       smb_ucs2_t *buffer = NULL;
-       char *out_buffer;
-
-       if (!push_ucs2_talloc(ctx, &buffer, s, &converted_size)) {
-               return NULL;
-       }
-
-       strlower_w(buffer);
-
-       if (!pull_ucs2_talloc(ctx, &out_buffer, buffer, &converted_size)) {
-               TALLOC_FREE(buffer);
-               return NULL;
-       }
-
-       TALLOC_FREE(buffer);
-
-       return out_buffer;
-}
-
-
-size_t ucs2_align(const void *base_ptr, const void *p, int flags)
-{
-       if (flags & (STR_NOALIGN|STR_ASCII))
-               return 0;
-       return PTR_DIFF(p, base_ptr) & 1;
-}
-
-
-/**
- * Copy a string from a char* unix src to a dos codepage string destination.
- *
- * @return the number of bytes occupied by the string in the destination.
- *
- * @param flags can include
- * <dl>
- * <dt>STR_TERMINATE</dt> <dd>means include the null termination</dd>
- * <dt>STR_UPPER</dt> <dd>means uppercase in the destination</dd>
- * </dl>
- *
- * @param dest_len the maximum length in bytes allowed in the
- * destination.
- **/
-size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
-{
-       size_t src_len = strlen(src);
-       char *tmpbuf = NULL;
-       size_t ret;
-
-       /* No longer allow a length of -1. */
-       if (dest_len == (size_t)-1) {
-               smb_panic("push_ascii - dest_len == -1");
-       }
+                       outbuf++;
+                       o_len--;
 
-       if (flags & STR_UPPER) {
-               tmpbuf = SMB_STRDUP(src);
-               if (!tmpbuf) {
-                       smb_panic("malloc fail");
-               }
-               strupper_m(tmpbuf);
-               src = tmpbuf;
-       }
+                       if (o_len == 0 || i_len == 0)
+                               goto out;
 
-       if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) {
-               src_len++;
-       }
+                       /* Keep trying with the next char... */
+                       goto again;
 
-       ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True);
-       if (ret == (size_t)-1 &&
-                       (flags & (STR_TERMINATE | STR_TERMINATE_ASCII))
-                       && dest_len > 0) {
-               ((char *)dest)[0] = '\0';
+               } else {
+                       /* Keep compiler happy.... */
+                       goto out;
+               }
        }
-       SAFE_FREE(tmpbuf);
-       return ret;
 }
 
 size_t push_ascii_fstring(void *dest, const char *src)
@@ -1080,72 +311,6 @@ size_t push_ascii_nstring(void *dest, const char *src)
        return dest_len;
 }
 
-/********************************************************************
- Push and malloc an ascii string. src and dest null terminated.
-********************************************************************/
-
-bool push_ascii_allocate(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);
-}
-
-/**
- * Copy a string from a dos codepage source to a unix char* destination.
- *
- * The resulting string in "dest" is always null terminated.
- *
- * @param flags can have:
- * <dl>
- * <dt>STR_TERMINATE</dt>
- * <dd>STR_TERMINATE means the string in @p src
- * is null terminated, and src_len is ignored.</dd>
- * </dl>
- *
- * @param src_len is the length of the source area in bytes.
- * @returns the number of bytes occupied by the string in @p src.
- **/
-size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
-{
-       size_t ret;
-
-       if (dest_len == (size_t)-1) {
-               /* No longer allow dest_len of -1. */
-               smb_panic("pull_ascii - invalid dest_len of -1");
-       }
-
-       if (flags & STR_TERMINATE) {
-               if (src_len == (size_t)-1) {
-                       src_len = strlen((const char *)src) + 1;
-               } else {
-                       size_t len = strnlen((const char *)src, src_len);
-                       if (len < src_len)
-                               len++;
-                       src_len = len;
-               }
-       }
-
-       ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, True);
-       if (ret == (size_t)-1) {
-               ret = 0;
-               dest_len = 0;
-       }
-
-       if (dest_len && ret) {
-               /* Did we already process the terminating zero ? */
-               if (dest[MIN(ret-1, dest_len-1)] != 0) {
-                       dest[MIN(ret, dest_len-1)] = 0;
-               }
-       } else  {
-               dest[0] = 0;
-       }
-
-       return src_len;
-}
-
 /**
  * Copy a string from a dos codepage source to a unix char* destination.
  Talloc version.
@@ -1166,10 +331,10 @@ 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;
@@ -1216,8 +381,8 @@ 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,
-                                    &dest_len, True)) {
+       if (!convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, &dest,
+                                  &dest_len, True)) {
                dest_len = 0;
        }
 
@@ -1260,102 +425,6 @@ size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src)
        return pull_ascii(dest, src, dest_len, sizeof(nstring)-1, STR_TERMINATE);
 }
 
-/**
- * Copy a string from a char* src to a unicode destination.
- *
- * @returns the number of bytes occupied by the string in the destination.
- *
- * @param flags can have:
- *
- * <dl>
- * <dt>STR_TERMINATE <dd>means include the null termination.
- * <dt>STR_UPPER     <dd>means uppercase in the destination.
- * <dt>STR_NOALIGN   <dd>means don't do alignment.
- * </dl>
- *
- * @param dest_len is the maximum length allowed in the
- * destination.
- **/
-
-size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
-{
-       size_t len=0;
-       size_t src_len;
-       size_t ret;
-
-       if (dest_len == (size_t)-1) {
-               /* No longer allow dest_len of -1. */
-               smb_panic("push_ucs2 - invalid dest_len of -1");
-       }
-
-       if (flags & STR_TERMINATE)
-               src_len = (size_t)-1;
-       else
-               src_len = strlen(src);
-
-       if (ucs2_align(base_ptr, dest, flags)) {
-               *(char *)dest = 0;
-               dest = (void *)((char *)dest + 1);
-               if (dest_len)
-                       dest_len--;
-               len++;
-       }
-
-       /* ucs2 is always a multiple of 2 bytes */
-       dest_len &= ~1;
-
-       ret =  convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len, True);
-       if (ret == (size_t)-1) {
-               if ((flags & STR_TERMINATE) &&
-                               dest &&
-                               dest_len) {
-                       *(char *)dest = 0;
-               }
-               return len;
-       }
-
-       len += ret;
-
-       if (flags & STR_UPPER) {
-               smb_ucs2_t *dest_ucs2 = (smb_ucs2_t *)dest;
-               size_t i;
-
-               /* We check for i < (ret / 2) below as the dest string isn't null
-                  terminated if STR_TERMINATE isn't set. */
-
-               for (i = 0; i < (ret / 2) && i < (dest_len / 2) && dest_ucs2[i]; i++) {
-                       smb_ucs2_t v = toupper_w(dest_ucs2[i]);
-                       if (v != dest_ucs2[i]) {
-                               dest_ucs2[i] = v;
-                       }
-               }
-       }
-
-       return len;
-}
-
-
-/**
- * Copy a string from a unix char* src to a UCS2 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.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-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, converted_size, True);
-}
-
 
 /**
  * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer
@@ -1374,7 +443,7 @@ bool push_ucs2_allocate(smb_ucs2_t **dest, const char *src,
        size_t src_len = strlen(src)+1;
 
        *dest = NULL;
-       return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len,
+       return convert_string_allocate(CH_UNIX, CH_UTF16LE, src, src_len,
                                       (void **)dest, converted_size, True);
 }
 
@@ -1423,27 +492,6 @@ size_t push_utf8_fstring(void *dest, const char *src)
        return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE);
 }
 
-/**
- * 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.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-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, converted_size, True);
-}
-
 /**
  * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer
  *
@@ -1460,79 +508,10 @@ bool push_utf8_allocate(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_UTF8, src, src_len,
+       return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len,
                                       (void **)dest, converted_size, True);
 }
 
-/**
- Copy a string from a ucs2 source to a unix char* destination.
- Flags can have:
-  STR_TERMINATE means the string in src is null terminated.
-  STR_NOALIGN   means don't try to align.
- if STR_TERMINATE is set then src_len is ignored if it is -1.
- src_len is the length of the source area in bytes
- Return the number of bytes occupied by the string in src.
- The resulting string in "dest" is always null terminated.
-**/
-
-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 ret;
-
-       if (dest_len == (size_t)-1) {
-               /* No longer allow dest_len of -1. */
-               smb_panic("pull_ucs2 - invalid dest_len of -1");
-       }
-
-       if (!src_len) {
-               if (dest && dest_len > 0) {
-                       dest[0] = '\0';
-               }
-               return 0;
-       }
-
-       if (ucs2_align(base_ptr, src, flags)) {
-               src = (const void *)((const char *)src + 1);
-               if (src_len != (size_t)-1)
-                       src_len--;
-       }
-
-       if (flags & STR_TERMINATE) {
-               /* src_len -1 is the default for null terminated strings. */
-               if (src_len != (size_t)-1) {
-                       size_t len = strnlen_w((const smb_ucs2_t *)src,
-                                               src_len/2);
-                       if (len < src_len/2)
-                               len++;
-                       src_len = len*2;
-               }
-       }
-
-       /* ucs2 is always a multiple of 2 bytes */
-       if (src_len != (size_t)-1)
-               src_len &= ~1;
-
-       ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, True);
-       if (ret == (size_t)-1) {
-               ret = 0;
-               dest_len = 0;
-       }
-
-       if (src_len == (size_t)-1)
-               src_len = ret*2;
-
-       if (dest_len && ret) {
-               /* Did we already process the terminating zero ? */
-               if (dest[MIN(ret-1, dest_len-1)] != 0) {
-                       dest[MIN(ret, dest_len-1)] = 0;
-               }
-       } else {
-               dest[0] = 0;
-       }
-
-       return src_len;
-}
-
 /**
  Copy a string from a ucs2 source to a unix char* destination.
  Talloc version with a base pointer.
@@ -1647,27 +626,6 @@ size_t pull_ucs2_fstring(char *dest, const void *src)
        return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE);
 }
 
-/**
- * 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.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-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, converted_size, True);
-}
-
 /**
  * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer
  *
@@ -1684,31 +642,10 @@ bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src,
        size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
 
        *dest = NULL;
-       return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len,
+       return convert_string_allocate(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.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-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, converted_size, True);
-}
-
 /**
  * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer
  *
@@ -1725,7 +662,7 @@ bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size)
        size_t src_len = strlen(src)+1;
 
        *dest = NULL;
-       return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len,
+       return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len,
                                       (void **)dest, converted_size, True);
 }
  
@@ -1804,7 +741,7 @@ size_t push_string_fn(const char *function, unsigned int line,
 **/
 
 size_t push_string_base(const char *function, unsigned int line,
-                       uint16 flags2, char *base,
+                       char *base, uint16 flags2, 
                        void *dest, const char *src,
                        size_t dest_len, int flags)
 {
@@ -1930,85 +867,3 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
        return 0;
 }
 
-/*
-  Return the unicode codepoint for the next multi-byte CH_UNIX character
-  in the string. The unicode codepoint (codepoint_t) is an unsinged 32 bit value.
-
-  Also return the number of bytes consumed (which tells the caller
-  how many bytes to skip to get to the next CH_UNIX character).
-
-  Return INVALID_CODEPOINT if the next character cannot be converted.
-*/
-
-codepoint_t next_codepoint(const char *str, size_t *size)
-{
-       /* It cannot occupy more than 4 bytes in UTF16 format */
-       uint8_t buf[4];
-       smb_iconv_t descriptor;
-       size_t ilen_orig;
-       size_t ilen;
-       size_t olen;
-       char *outbuf;
-
-       if ((str[0] & 0x80) == 0) {
-               *size = 1;
-               return (codepoint_t)str[0];
-       }
-
-       /* We assume that no multi-byte character can take
-          more than 5 bytes. This is OK as we only
-          support codepoints up to 1M */
-
-       ilen_orig = strnlen(str, 5);
-       ilen = ilen_orig;
-
-        lazy_initialize_conv();
-
-        descriptor = conv_handles[CH_UNIX][CH_UTF16LE];
-       if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
-               *size = 1;
-               return INVALID_CODEPOINT;
-       }
-
-       /* This looks a little strange, but it is needed to cope
-          with codepoints above 64k which are encoded as per RFC2781. */
-       olen = 2;
-       outbuf = (char *)buf;
-       smb_iconv(descriptor, &str, &ilen, &outbuf, &olen);
-       if (olen == 2) {
-               /* We failed to convert to a 2 byte character.
-                  See if we can convert to a 4 UTF16-LE byte char encoding.
-               */
-               olen = 4;
-               outbuf = (char *)buf;
-               smb_iconv(descriptor,  &str, &ilen, &outbuf, &olen);
-               if (olen == 4) {
-                       /* We didn't convert any bytes */
-                       *size = 1;
-                       return INVALID_CODEPOINT;
-               }
-               olen = 4 - olen;
-       } else {
-               olen = 2 - olen;
-       }
-
-       *size = ilen_orig - ilen;
-
-       if (olen == 2) {
-               /* 2 byte, UTF16-LE encoded value. */
-               return (codepoint_t)SVAL(buf, 0);
-       }
-       if (olen == 4) {
-               /* Decode a 4 byte UTF16-LE character manually.
-                  See RFC2871 for the encoding machanism.
-               */
-               codepoint_t w1 = SVAL(buf,0) & ~0xD800;
-               codepoint_t w2 = SVAL(buf,2) & ~0xDC00;
-
-               return (codepoint_t)0x10000 +
-                               (w1 << 10) + w2;
-       }
-
-       /* no other length is valid */
-       return INVALID_CODEPOINT;
-}
index 0cb326961d767478086984e8ab9ad246fcb966fb..c9dc1d2eb47e89434eaeaf2bfaad88ff05c3ce04 100644 (file)
@@ -576,7 +576,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
 
                switch (*(p+1)) {
                case 'U' : 
-                       r = strdup_lower(smb_name);
+                       r = strlower_talloc(tmp_ctx, smb_name);
                        if (r == NULL) {
                                goto error;
                        }
@@ -584,7 +584,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
                        break;
                case 'G' : {
                        struct passwd *pass;
-                       r = SMB_STRDUP(smb_name);
+                       r = talloc_strdup(tmp_ctx, smb_name);
                        if (r == NULL) {
                                goto error;
                        }
@@ -598,7 +598,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
                        break;
                }
                case 'D' :
-                       r = strdup_upper(domain_name);
+                       r = strupper_talloc(tmp_ctx, domain_name);
                        if (r == NULL) {
                                goto error;
                        }
@@ -678,7 +678,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
                }
 
                p++;
-               SAFE_FREE(r);
+               TALLOC_FREE(r);
 
                if (a_string == NULL) {
                        goto done;
index 6570bb072d4ffd4629ad69a9ded7d034579f1ed5..96717e33d331cfd1308b4f7e917394fe2bb4706a 100644 (file)
@@ -93,7 +93,7 @@ WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
                size_t dstlen, thislen;
 
                thislen = strnlen_w(p, len) + 1;
-               if (!convert_string_allocate(*values, CH_UTF16LE, CH_UNIX,
+               if (!convert_string_talloc(*values, CH_UTF16LE, CH_UNIX,
                        p, thislen*2, (void *)&val, &dstlen, true)) {
                        TALLOC_FREE(*values);
                        return WERR_NOMEM;
index b9ccb83e556134a2a54a717b7f3811d943c7870d..ffa998bca282fb0540b586a02717d518d5bd4458 100644 (file)
@@ -384,11 +384,11 @@ size_t str_ascii_charnum(const char *s)
 {
        size_t ret, converted_size;
        char *tmpbuf2 = NULL;
-       if (!push_ascii_allocate(&tmpbuf2, s, &converted_size)) {
+       if (!push_ascii_talloc(NULL, &tmpbuf2, s, &converted_size)) {
                return 0;
        }
        ret = strlen(tmpbuf2);
-       SAFE_FREE(tmpbuf2);
+       TALLOC_FREE(tmpbuf2);
        return ret;
 }
 
@@ -1139,137 +1139,6 @@ char *string_truncate(char *s, unsigned int length)
        return s;
 }
 
-/**
- Strchr and strrchr_m are very hard to do on general multi-byte strings.
- We convert via ucs2 for now.
-**/
-
-char *strchr_m(const char *src, char c)
-{
-       smb_ucs2_t *ws = NULL;
-       char *s2 = NULL;
-       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 */
-       if ((c & 0xC0) == 0) {
-               return strchr(src, c);
-       }
-
-       /* 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) */
-
-       for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
-               if (*s == c)
-                       return (char *)s;
-       }
-
-       if (!*s)
-               return NULL;
-
-#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
-       /* With compose characters we must restart from the beginning. JRA. */
-       s = src;
-#endif
-
-       if (!push_ucs2_allocate(&ws, s, &converted_size)) {
-               /* Wrong answer, but what can we do... */
-               return strchr(src, c);
-       }
-       p = strchr_w(ws, UCS2_CHAR(c));
-       if (!p) {
-               SAFE_FREE(ws);
-               return NULL;
-       }
-       *p = 0;
-       if (!pull_ucs2_allocate(&s2, ws, &converted_size)) {
-               SAFE_FREE(ws);
-               /* Wrong answer, but what can we do... */
-               return strchr(src, c);
-       }
-       ret = (char *)(s+strlen(s2));
-       SAFE_FREE(ws);
-       SAFE_FREE(s2);
-       return ret;
-}
-
-char *strrchr_m(const char *s, char c)
-{
-       /* characters below 0x3F are guaranteed to not appear in
-          non-initial position in multi-byte charsets */
-       if ((c & 0xC0) == 0) {
-               return strrchr(s, c);
-       }
-
-       /* 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). Also, in Samba
-          we only search for ascii characters in 'c' and that
-          in all mb character sets with a compound character
-          containing c, if 'c' is not a match at position
-          p, then p[-1] > 0x7f. JRA. */
-
-       {
-               size_t len = strlen(s);
-               const char *cp = s;
-               bool got_mb = false;
-
-               if (len == 0)
-                       return NULL;
-               cp += (len - 1);
-               do {
-                       if (c == *cp) {
-                               /* Could be a match. Part of a multibyte ? */
-                               if ((cp > s) &&
-                                       (((unsigned char)cp[-1]) & 0x80)) {
-                                       /* Yep - go slow :-( */
-                                       got_mb = true;
-                                       break;
-                               }
-                               /* No - we have a match ! */
-                               return (char *)cp;
-                       }
-               } while (cp-- != s);
-               if (!got_mb)
-                       return NULL;
-       }
-
-       /* String contained a non-ascii char. Slow path. */
-       {
-               smb_ucs2_t *ws = NULL;
-               char *s2 = NULL;
-               smb_ucs2_t *p;
-               char *ret;
-               size_t converted_size;
-
-               if (!push_ucs2_allocate(&ws, s, &converted_size)) {
-                       /* Wrong answer, but what can we do. */
-                       return strrchr(s, c);
-               }
-               p = strrchr_w(ws, UCS2_CHAR(c));
-               if (!p) {
-                       SAFE_FREE(ws);
-                       return NULL;
-               }
-               *p = 0;
-               if (!pull_ucs2_allocate(&s2, ws, &converted_size)) {
-                       SAFE_FREE(ws);
-                       /* Wrong answer, but what can we do. */
-                       return strrchr(s, c);
-               }
-               ret = (char *)(s+strlen(s2));
-               SAFE_FREE(ws);
-               SAFE_FREE(s2);
-               return ret;
-       }
-}
-
 /***********************************************************************
  Return the equivalent of doing strrchr 'n' times - always going
  backwards.
@@ -1385,144 +1254,6 @@ char *strstr_m(const char *src, const char *findstr)
        return retp;
 }
 
-/**
- Convert a string to lower case.
-**/
-
-void strlower_m(char *s)
-{
-       size_t len;
-       int errno_save;
-
-       /* 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 (*s && !(((unsigned char)s[0]) & 0x80)) {
-               *s = tolower_ascii((unsigned char)*s);
-               s++;
-       }
-
-       if (!*s)
-               return;
-
-       /* I assume that lowercased string takes the same number of bytes
-        * as source string even in UTF-8 encoding. (VIV) */
-       len = strlen(s) + 1;
-       errno_save = errno;
-       errno = 0;
-       unix_strlower(s,len,s,len);
-       /* Catch mb conversion errors that may not terminate. */
-       if (errno)
-               s[len-1] = '\0';
-       errno = errno_save;
-}
-
-/**
- Convert a string to upper case.
-**/
-
-void strupper_m(char *s)
-{
-       size_t len;
-       int errno_save;
-
-       /* 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 (*s && !(((unsigned char)s[0]) & 0x80)) {
-               *s = toupper_ascii_fast((unsigned char)*s);
-               s++;
-       }
-
-       if (!*s)
-               return;
-
-       /* I assume that lowercased string takes the same number of bytes
-        * as source string even in multibyte encoding. (VIV) */
-       len = strlen(s) + 1;
-       errno_save = errno;
-       errno = 0;
-       unix_strupper(s,len,s,len);
-       /* Catch mb conversion errors that may not terminate. */
-       if (errno)
-               s[len-1] = '\0';
-       errno = errno_save;
-}
-
-/**
- Count the number of UCS2 characters in a string. Normally this will
- be the same as the number of bytes in a string for single byte strings,
- but will be different for multibyte.
-**/
-
-size_t strlen_m(const char *s)
-{
-       size_t count = 0;
-
-       if (!s) {
-               return 0;
-       }
-
-       while (*s && !(((uint8_t)*s) & 0x80)) {
-               s++;
-               count++;
-       }
-
-       if (!*s) {
-               return count;
-       }
-
-       while (*s) {
-               size_t c_size;
-               codepoint_t c = next_codepoint(s, &c_size);
-               if (c < 0x10000) {
-                       /* Unicode char fits into 16 bits. */
-                       count += 1;
-               } else {
-                       /* Double-width unicode char - 32 bits. */
-                       count += 2;
-               }
-               s += c_size;
-       }
-
-       return count;
-}
-
-/**
- Count the number of UCS2 characters in a string including the null
- terminator.
-**/
-
-size_t strlen_m_term(const char *s)
-{
-       if (!s) {
-               return 0;
-       }
-       return strlen_m(s) + 1;
-}
-
-/*
- * Weird helper routine for the winreg pipe: If nothing is around, return 0,
- * if a string is there, include the terminator.
- */
-
-size_t strlen_m_term_null(const char *s)
-{
-       size_t len;
-       if (!s) {
-               return 0;
-       }
-       len = strlen_m(s);
-       if (len == 0) {
-               return 0;
-       }
-
-       return len+1;
-}
 /**
  Return a RFC2254 binary string representation of a buffer.
  Used in LDAP filters.
index 0703f04c5ff900e6b853d99e7421f55d7c8460e3..aeac8bc0c18d31533ed0419efaf85636f4556ded 100644 (file)
@@ -938,10 +938,10 @@ uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2,
                buflen += 1;
        }
 
-       if (!convert_string_allocate(talloc_tos(), CH_UNIX,
-                                    ucs2 ? CH_UTF16LE : CH_DOS,
-                                    str, str_len, &converted,
-                                    &converted_size, true)) {
+       if (!convert_string_talloc(talloc_tos(), CH_UNIX,
+                                  ucs2 ? CH_UTF16LE : CH_DOS,
+                                  str, str_len, &converted,
+                                  &converted_size, true)) {
                return NULL;
        }
 
index 808190e79c7c5f1850049222e8f1fc17322e863c..3fbb9e37acad229a30347fab7237434663ee1723 100644 (file)
@@ -85,7 +85,7 @@ int cli_message_text_build(struct cli_state *cli, const char *msg, int len, int
        p = smb_buf(cli->outbuf);
        *p++ = 1;
 
-       if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, msg, len,
+       if (!convert_string_allocate(CH_UNIX, CH_DOS, msg, len,
                (void **)(void *)&msgdos, &lendos, True) || !msgdos) {
                DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
                SSVAL(p, 0, len); p += 2;
index f49a1bc4c948311dc507a378628ad48353974496..37798d06a40d2db6c2440aec686e9706136026e1 100644 (file)
@@ -7015,7 +7015,6 @@ static bool handle_charset(int snum, const char *pszParmValue, char **ptr)
 {
        if (strcmp(*ptr, pszParmValue) != 0) {
                string_set(ptr, pszParmValue);
-               init_iconv();
        }
        return True;
 }
@@ -9047,8 +9046,6 @@ bool lp_load_ex(const char *pszFname,
                lp_do_parameter(GLOBAL_SECTION_SNUM, "wins server", "127.0.0.1");
        }
 
-       init_iconv();
-
        bAllowIncludeRegistry = true;
 
        return (bRetval);
index 8ceeaf5f5588ae4e5d5c091a3379ce944c00bc88..06040c6a35b0ae6298685b6ee84cbde7f8812c27 100644 (file)
@@ -81,7 +81,7 @@ static bool notify_marshall_changes(int num_changes,
 
                c = &changes[i];
 
-               if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE,
+               if (!convert_string_allocate(CH_UNIX, CH_UTF16LE,
                        c->name, strlen(c->name)+1, &uni_name.buffer,
                        &namelen, True) || (uni_name.buffer == NULL)) {
                        goto fail;
index 72fed008a2a5ba0dda09e7137a808b6a2d3e68e6..2f7d16790d0caee200f4ebe06b7228f0d9ee8677 100644 (file)
@@ -205,7 +205,7 @@ bool stat_cache_lookup(connection_struct *conn,
        } else {
                chk_name = talloc_strdup_upper(ctx,name);
                if (!chk_name) {
-                       DEBUG(0, ("stat_cache_lookup: strdup_upper failed!\n"));
+                       DEBUG(0, ("stat_cache_lookup: talloc_strdup_upper failed!\n"));
                        return False;
                }
 
index 38a2553e53a1280e51aeec563f95937e42c9886b..5e82f76ade49560f6e16b5ca48fc98e5dbb309a2 100644 (file)
@@ -300,7 +300,7 @@ static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
                        net_conf_import_usage(c, argc, argv);
                        goto done;
                case 2:
-                       servicename = talloc_strdup_lower(mem_ctx, argv[1]);
+                       servicename = strlower_talloc(mem_ctx, argv[1]);
                        if (servicename == NULL) {
                                d_printf("error: out of memory!\n");
                                goto done;
@@ -501,7 +501,7 @@ static int net_conf_showshare(struct net_context *c,
                goto done;
        }
 
-       sharename = talloc_strdup_lower(mem_ctx, argv[0]);
+       sharename = strlower_talloc(mem_ctx, argv[0]);
        if (sharename == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -600,7 +600,7 @@ static int net_conf_addshare(struct net_context *c,
                        }
                case 2:
                        path = argv[1];
-                       sharename = talloc_strdup_lower(mem_ctx, argv[0]);
+                       sharename = strlower_talloc(mem_ctx, argv[0]);
                        if (sharename == NULL) {
                                d_printf("error: out of memory!\n");
                                goto done;
@@ -728,7 +728,7 @@ static int net_conf_delshare(struct net_context *c,
                net_conf_delshare_usage(c, argc, argv);
                goto done;
        }
-       sharename = talloc_strdup_lower(mem_ctx, argv[0]);
+       sharename = strlower_talloc(mem_ctx, argv[0]);
        if (sharename == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -761,12 +761,12 @@ static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
                net_conf_setparm_usage(c, argc, argv);
                goto done;
        }
-       service = talloc_strdup_lower(mem_ctx, argv[0]);
+       service = strlower_talloc(mem_ctx, argv[0]);
        if (service == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
        }
-       param = talloc_strdup_lower(mem_ctx, argv[1]);
+       param = strlower_talloc(mem_ctx, argv[1]);
        if (param == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -813,12 +813,12 @@ static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
                net_conf_getparm_usage(c, argc, argv);
                goto done;
        }
-       service = talloc_strdup_lower(mem_ctx, argv[0]);
+       service = strlower_talloc(mem_ctx, argv[0]);
        if (service == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
        }
-       param = talloc_strdup_lower(mem_ctx, argv[1]);
+       param = strlower_talloc(mem_ctx, argv[1]);
        if (param == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -863,12 +863,12 @@ static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
                net_conf_delparm_usage(c, argc, argv);
                goto done;
        }
-       service = talloc_strdup_lower(mem_ctx, argv[0]);
+       service = strlower_talloc(mem_ctx, argv[0]);
        if (service == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
        }
-       param = talloc_strdup_lower(mem_ctx, argv[1]);
+       param = strlower_talloc(mem_ctx, argv[1]);
        if (param == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -916,7 +916,7 @@ static int net_conf_getincludes(struct net_context *c,
                goto done;
        }
 
-       service = talloc_strdup_lower(mem_ctx, argv[0]);
+       service = strlower_talloc(mem_ctx, argv[0]);
        if (service == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -956,7 +956,7 @@ static int net_conf_setincludes(struct net_context *c,
                goto done;
        }
 
-       service = talloc_strdup_lower(mem_ctx, argv[0]);
+       service = strlower_talloc(mem_ctx, argv[0]);
        if (service == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
@@ -996,7 +996,7 @@ static int net_conf_delincludes(struct net_context *c,
                goto done;
        }
 
-       service = talloc_strdup_lower(mem_ctx, argv[0]);
+       service = strlower_talloc(mem_ctx, argv[0]);
        if (service == NULL) {
                d_printf("error: out of memory!\n");
                goto done;
index ce8e82182e83e76934240d8634a1c22e1f28c068..7d3cb287a84c756bfcfb9652eabe7291c80bd889 100644 (file)
@@ -154,8 +154,8 @@ static int net_usershare_delete(struct net_context *c, int argc, const char **ar
                return net_usershare_delete_usage(c, argc, argv);
        }
 
-       if ((sharename = strdup_lower(argv[0])) == NULL) {
-               d_fprintf(stderr, "strdup failed\n");
+       if ((sharename = strlower_talloc(talloc_tos(), argv[0])) == NULL) {
+               d_fprintf(stderr, "strlower_talloc failed\n");
                return -1;
        }
 
@@ -624,22 +624,22 @@ static int net_usershare_add(struct net_context *c, int argc, const char **argv)
                default:
                        return net_usershare_add_usage(c, argc, argv);
                case 2:
-                       sharename = strdup_lower(argv[0]);
+                       sharename = strlower_talloc(ctx, argv[0]);
                        us_path = argv[1];
                        break;
                case 3:
-                       sharename = strdup_lower(argv[0]);
+                       sharename = strlower_talloc(ctx, argv[0]);
                        us_path = argv[1];
                        us_comment = argv[2];
                        break;
                case 4:
-                       sharename = strdup_lower(argv[0]);
+                       sharename = strlower_talloc(ctx, argv[0]);
                        us_path = argv[1];
                        us_comment = argv[2];
                        arg_acl = argv[3];
                        break;
                case 5:
-                       sharename = strdup_lower(argv[0]);
+                       sharename = strlower_talloc(ctx, argv[0]);
                        us_path = argv[1];
                        us_comment = argv[2];
                        arg_acl = argv[3];
index ff4d69f0a5dbacee6634f236eeee29b4a6be9526..07de42afa86514bcdac3104005eeb89672c6a547 100644 (file)
@@ -459,7 +459,7 @@ static bool test_plaintext(enum ntlm_break break_which)
        flags |= WBFLAG_PAM_LMKEY;
        flags |= WBFLAG_PAM_USER_SESSION_KEY;
 
-       if (!push_ucs2_allocate(&nt_response_ucs2, opt_password,
+       if (!push_ucs2_talloc(NULL, &nt_response_ucs2, opt_password,
                                &converted_size))
        {
                DEBUG(0, ("push_ucs2_allocate failed!\n"));
@@ -469,21 +469,21 @@ static bool test_plaintext(enum ntlm_break break_which)
        nt_response.data = (unsigned char *)nt_response_ucs2;
        nt_response.length = strlen_w(nt_response_ucs2)*sizeof(smb_ucs2_t);
 
-       if ((password = strdup_upper(opt_password)) == NULL) {
-               DEBUG(0, ("strdup_upper failed!\n"));
+       if ((password = strupper_talloc(NULL, opt_password)) == NULL) {
+               DEBUG(0, ("strupper_talloc() failed!\n"));
                exit(1);
        }
 
-       if (!convert_string_allocate(NULL, CH_UNIX,
-                                    CH_DOS, password,
-                                    strlen(password)+1, 
-                                    &lm_response.data,
-                                    &lm_response.length, True)) {
-               DEBUG(0, ("convert_string_allocate failed!\n"));
+       if (!convert_string_talloc(NULL, CH_UNIX,
+                                  CH_DOS, password,
+                                  strlen(password)+1, 
+                                  &lm_response.data,
+                                  &lm_response.length, True)) {
+               DEBUG(0, ("convert_string_talloc failed!\n"));
                exit(1);
        }
 
-       SAFE_FREE(password);
+       TALLOC_FREE(password);
 
        switch (break_which) {
        case BREAK_NONE:
@@ -514,8 +514,8 @@ static bool test_plaintext(enum ntlm_break break_which)
                                              user_session_key,
                                              &error_string, NULL);
        
-       SAFE_FREE(nt_response.data);
-       SAFE_FREE(lm_response.data);
+       TALLOC_FREE(nt_response.data);
+       TALLOC_FREE(lm_response.data);
        data_blob_free(&chall);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
index 40f9ee69668b8f36d2232e5216b73dcee7480817..261d4366bf95d968046c615525f529ec1af06135 100644 (file)
@@ -205,14 +205,14 @@ void cgi_load_variables(void)
                char *dest = NULL;
                size_t dest_len;
 
-               convert_string_allocate(frame, CH_UTF8, CH_UNIX,
+               convert_string_talloc(frame, CH_UTF8, CH_UNIX,
                               variables[i].name, strlen(variables[i].name),
                               &dest, &dest_len, True);
                SAFE_FREE(variables[i].name);
                variables[i].name = SMB_STRDUP(dest ? dest : "");
 
                dest = NULL;
-               convert_string_allocate(frame, CH_UTF8, CH_UNIX,
+               convert_string_talloc(frame, CH_UTF8, CH_UNIX,
                               variables[i].value, strlen(variables[i].value),
                               &dest, &dest_len, True);
                SAFE_FREE(variables[i].value);