diff options
51 files changed, 1177 insertions, 1160 deletions
diff --git a/source4/scripting/python/pytalloc.c b/lib/talloc/pytalloc.c index ca476e9604..f4b7d10e97 100644 --- a/source4/scripting/python/pytalloc.c +++ b/lib/talloc/pytalloc.c @@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "includes.h" -#include "scripting/python/pytalloc.h" +#include <talloc.h> +#include "../lib/talloc/pytalloc.h" void py_talloc_dealloc(PyObject* self) { diff --git a/source4/scripting/python/pytalloc.h b/lib/talloc/pytalloc.h index aad5840a67..aad5840a67 100644 --- a/source4/scripting/python/pytalloc.h +++ b/lib/talloc/pytalloc.h diff --git a/source4/lib/charset/charcnv.c b/lib/util/charset/charcnv.c index 3e384304cf..91a16a1cda 100644 --- a/source4/lib/charset/charcnv.c +++ b/lib/util/charset/charcnv.c @@ -22,7 +22,6 @@ */ #include "includes.h" #include "system/iconv.h" -#include "param/param.h" /** * @file @@ -66,7 +65,7 @@ static const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch) /** re-initialize iconv conversion descriptors **/ -static int close_iconv(struct smb_iconv_convenience *data) +static int close_iconv_convenience(struct smb_iconv_convenience *data) { unsigned c1, c2; for (c1=0;c1<NUM_CHARSETS;c1++) { @@ -95,7 +94,7 @@ _PUBLIC_ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *me return NULL; } - talloc_set_destructor(ret, close_iconv); + talloc_set_destructor(ret, close_iconv_convenience); ret->dos_charset = talloc_strdup(ret, dos_charset); ret->unix_charset = talloc_strdup(ret, unix_charset); @@ -313,329 +312,6 @@ _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, return convert_string_talloc_descriptor(ctx, descriptor, src, srclen, dest); } -/** - * 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. If @p dest_len is -1 then no maximum is used. - **/ -static ssize_t push_ascii(struct smb_iconv_convenience *ic, - void *dest, const char *src, size_t dest_len, int flags) -{ - size_t src_len; - ssize_t ret; - - if (flags & STR_UPPER) { - char *tmpbuf = strupper_talloc(NULL, src); - if (tmpbuf == NULL) { - return -1; - } - ret = push_ascii(ic, dest, tmpbuf, dest_len, flags & ~STR_UPPER); - talloc_free(tmpbuf); - return ret; - } - - src_len = strlen(src); - - if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) - src_len++; - - return convert_string(ic, CH_UNIX, CH_DOS, src, src_len, dest, dest_len); -} - -/** - * Copy a string from a unix char* src to an ASCII destination, - * allocating a buffer using talloc(). - * - * @param dest always set at least to NULL - * - * @returns The number of bytes occupied by the string in the destination - * or -1 in case of error. - **/ -_PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) -{ - size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, ic, CH_UNIX, CH_DOS, src, src_len, (void **)dest); -} - - -/** - * 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. - **/ -static ssize_t pull_ascii(struct smb_iconv_convenience *ic, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) -{ - size_t ret; - - if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { - 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(ic, CH_DOS, CH_UNIX, src, src_len, dest, dest_len); - - if (dest_len) - dest[MIN(ret, dest_len-1)] = 0; - - return src_len; -} - -/** - * 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. - **/ -static ssize_t push_ucs2(struct smb_iconv_convenience *ic, - void *dest, const char *src, size_t dest_len, int flags) -{ - size_t len=0; - size_t src_len = strlen(src); - size_t ret; - - if (flags & STR_UPPER) { - char *tmpbuf = strupper_talloc(NULL, src); - if (tmpbuf == NULL) { - return -1; - } - ret = push_ucs2(ic, dest, tmpbuf, dest_len, flags & ~STR_UPPER); - talloc_free(tmpbuf); - return ret; - } - - if (flags & STR_TERMINATE) - src_len++; - - if (ucs2_align(NULL, 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(ic, CH_UNIX, CH_UTF16, src, src_len, dest, dest_len); - if (ret == (size_t)-1) { - return 0; - } - - len += ret; - - 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 - * - * @returns The number of bytes occupied by the string in the destination - * or -1 in case of error. - **/ -_PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, void **dest, const char *src) -{ - size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, ic, CH_UNIX, CH_UTF16, src, src_len, dest); -} - - -/** - * 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 - * - * @returns The number of bytes occupied by the string in the destination - **/ - -_PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) -{ - size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, ic, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); -} - -/** - 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. -**/ - -static size_t pull_ucs2(struct smb_iconv_convenience *ic, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) -{ - size_t ret; - - if (ucs2_align(NULL, src, flags)) { - src = (const void *)((const char *)src + 1); - if (src_len > 0) - src_len--; - } - - if (flags & STR_TERMINATE) { - if (src_len == (size_t)-1) { - src_len = utf16_len(src); - } else { - src_len = utf16_len_n(src, src_len); - } - } - - /* ucs2 is always a multiple of 2 bytes */ - if (src_len != (size_t)-1) - src_len &= ~1; - - ret = convert_string(ic, CH_UTF16, CH_UNIX, src, src_len, dest, dest_len); - if (dest_len) - dest[MIN(ret, dest_len-1)] = 0; - - return src_len; -} - -/** - * Copy a string from a ASCII src to a unix char * destination, allocating a buffer using talloc - * - * @param dest always set at least to NULL - * - * @returns The number of bytes occupied by the string in the destination - **/ - -_PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) -{ - size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, ic, CH_DOS, CH_UNIX, src, src_len, (void **)dest); -} - -/** - * 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 - * - * @returns The number of bytes occupied by the string in the destination - **/ - -_PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const void *src) -{ - size_t src_len = utf16_len(src); - *dest = NULL; - return convert_string_talloc(ctx, ic, CH_UTF16, CH_UNIX, src, src_len, (void **)dest); -} - -/** - * 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 - * - * @returns The number of bytes occupied by the string in the destination - **/ - -_PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) -{ - size_t src_len = strlen(src)+1; - *dest = NULL; - return convert_string_talloc(ctx, ic, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); -} - -/** - Copy a string from a char* src to a unicode or ascii - dos codepage destination choosing unicode or ascii based on the - flags in the SMB buffer starting at base_ptr. - Return the number of bytes occupied by the string in the destination. - flags can have: - STR_TERMINATE means include the null termination. - STR_UPPER means uppercase in the destination. - STR_ASCII use ascii even with unicode packet. - STR_NOALIGN means don't do alignment. - dest_len is the maximum length allowed in the destination. If dest_len - is -1 then no maxiumum is used. -**/ - -_PUBLIC_ ssize_t push_string(struct smb_iconv_convenience *ic, - void *dest, const char *src, size_t dest_len, int flags) -{ - if (flags & STR_ASCII) { - return push_ascii(ic, dest, src, dest_len, flags); - } else if (flags & STR_UNICODE) { - return push_ucs2(ic, 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. - Flags can have: - STR_TERMINATE means the string in src is null terminated. - STR_UNICODE means to force as unicode. - STR_ASCII use ascii even with unicode packet. - STR_NOALIGN means don't do alignment. - if STR_TERMINATE is set then src_len is ignored is 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. -**/ - -_PUBLIC_ ssize_t pull_string(struct smb_iconv_convenience *ic, - char *dest, const void *src, size_t dest_len, size_t src_len, int flags) -{ - if (flags & STR_ASCII) { - return pull_ascii(ic, dest, src, dest_len, src_len, flags); - } else if (flags & STR_UNICODE) { - return pull_ucs2(ic, 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; - } -} - - /* return the unicode codepoint for the next multi-byte CH_UNIX character in the string diff --git a/source4/lib/charset/charset.h b/lib/util/charset/charset.h index 041eaeace7..cba8aaf5f3 100644 --- a/source4/lib/charset/charset.h +++ b/lib/util/charset/charset.h @@ -76,7 +76,6 @@ typedef struct smb_iconv_s { struct loadparm_context; struct smb_iconv_convenience; -extern struct smb_iconv_convenience *global_smb_iconv_convenience; /* replace some string functions with multi-byte versions */ @@ -87,13 +86,13 @@ char *strchr_m(const char *s, char c); size_t strlen_m_term(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_w(char *s, char oldc, char newc); -bool strcsequal_w(const char *s1,const char *s2); -bool strequal_w(const char *s1, const char *s2); +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); int strncasecmp_m(const char *s1, const char *s2, size_t n); bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize); int strcasecmp_m(const char *s1, const char *s2); -size_t count_chars_w(const char *s, char c); +size_t count_chars_m(const char *s, char c); void strupper_m(char *s); void strlower_m(char *s); char *strupper_talloc(TALLOC_CTX *ctx, const char *src); @@ -105,17 +104,30 @@ 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_talloc(TALLOC_CTX *ctx, char **dest, const char *src); +ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src); +ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src); +ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src); +ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src); +ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src); +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); + /* codepoints */ codepoint_t next_codepoint(struct smb_iconv_convenience *ic, const char *str, size_t *size); ssize_t push_codepoint(struct smb_iconv_convenience *ic, char *str, codepoint_t c); -codepoint_t toupper_w(codepoint_t val); -codepoint_t tolower_w(codepoint_t val); +codepoint_t toupper_m(codepoint_t val); +codepoint_t tolower_m(codepoint_t val); int codepoint_cmpi(codepoint_t c1, codepoint_t c2); -ssize_t push_string(struct smb_iconv_convenience *ic, void *dest, const char *src, size_t dest_len, int flags); -ssize_t pull_string(struct smb_iconv_convenience *ic, - char *dest, const void *src, size_t dest_len, size_t src_len, int flags); + +/* Iconv convenience functions */ +struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, + const char *dos_charset, + const char *unix_charset, + bool native_iconv); + ssize_t convert_string(struct smb_iconv_convenience *ic, charset_t from, charset_t to, void const *src, size_t srclen, @@ -126,13 +138,6 @@ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest); -ssize_t push_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); -ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, void **dest, const char *src); -ssize_t push_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); -ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); -ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const void *src); -ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); - /* iconv */ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode); int smb_iconv_close(smb_iconv_t cd); @@ -142,12 +147,6 @@ size_t smb_iconv(smb_iconv_t cd, smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, const char *fromcode, bool native_iconv); -/* iconv convenience */ -struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, - const char *dos_charset, - const char *unix_charset, - bool native_iconv); - void load_case_tables(void); bool charset_register_backend(const void *_funcs); diff --git a/lib/util/charset/codepoints.c b/lib/util/charset/codepoints.c new file mode 100644 index 0000000000..a940c1baf0 --- /dev/null +++ b/lib/util/charset/codepoints.c @@ -0,0 +1,118 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-2001 + Copyright (C) Simo Sorce 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "system/locale.h" +#include "dynconfig/dynconfig.h" + +/** + * @file + * @brief Unicode string manipulation + */ + +/* these 2 tables define the unicode case handling. They are loaded + at startup either via mmap() or read() from the lib directory */ +static void *upcase_table; +static void *lowcase_table; + + +/******************************************************************* +load the case handling tables +********************************************************************/ +void load_case_tables(void) +{ + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("load_case_tables"); + if (!mem_ctx) { + smb_panic("No memory for case_tables"); + } + upcase_table = map_file(talloc_asprintf(mem_ctx, "%s/upcase.dat", dyn_DATADIR), 0x20000); + lowcase_table = map_file(talloc_asprintf(mem_ctx, "%s/lowcase.dat", dyn_DATADIR), 0x20000); + talloc_free(mem_ctx); + if (upcase_table == NULL) { + /* try also under codepages for testing purposes */ + upcase_table = map_file("codepages/upcase.dat", 0x20000); + if (upcase_table == NULL) { + upcase_table = (void *)-1; + } + } + if (lowcase_table == NULL) { + /* try also under codepages for testing purposes */ + lowcase_table = map_file("codepages/lowcase.dat", 0x20000); + if (lowcase_table == NULL) { + lowcase_table = (void *)-1; + } + } +} + +/** + Convert a codepoint_t to upper case. +**/ +_PUBLIC_ codepoint_t toupper_m(codepoint_t val) +{ + if (val < 128) { + return toupper(val); + } + if (upcase_table == NULL) { + load_case_tables(); + } + if (upcase_table == (void *)-1) { + return val; + } + if (val & 0xFFFF0000) { + return val; + } + return SVAL(upcase_table, val*2); +} + +/** + Convert a codepoint_t to lower case. +**/ +_PUBLIC_ codepoint_t tolower_m(codepoint_t val) +{ + if (val < 128) { + return tolower(val); + } + if (lowcase_table == NULL) { + load_case_tables(); + } + if (lowcase_table == (void *)-1) { + return val; + } + if (val & 0xFFFF0000) { + return val; + } + return SVAL(lowcase_table, val*2); +} + +/** + compare two codepoints case insensitively +*/ +_PUBLIC_ int codepoint_cmpi(codepoint_t c1, codepoint_t c2) +{ + if (c1 == c2 || + toupper_m(c1) == toupper_m(c2)) { + return 0; + } + return c1 - c2; +} + + diff --git a/source4/lib/charset/config.m4 b/lib/util/charset/config.m4 index 453de9fe26..453de9fe26 100644 --- a/source4/lib/charset/config.m4 +++ b/lib/util/charset/config.m4 diff --git a/source4/lib/charset/config.mk b/lib/util/charset/config.mk index 12c2f5f321..952c13a84d 100644 --- a/source4/lib/charset/config.mk +++ b/lib/util/charset/config.mk @@ -6,8 +6,6 @@ PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET ################################################ -CHARSET_OBJ_FILES = $(addprefix $(libcharsetsrcdir)/, iconv.o charcnv.o util_unistr.o) +CHARSET_OBJ_FILES = $(addprefix $(libcharsetsrcdir)/, iconv.o charcnv.o util_unistr.o codepoints.o) PUBLIC_HEADERS += $(libcharsetsrcdir)/charset.h - -$(eval $(call proto_header_template,$(libcharsetsrcdir)/charset_proto.h,$(CHARSET_OBJ_FILES:.o=.c))) diff --git a/source4/lib/charset/iconv.c b/lib/util/charset/iconv.c index 150383e7f9..150383e7f9 100644 --- a/source4/lib/charset/iconv.c +++ b/lib/util/charset/iconv.c diff --git a/source4/lib/charset/tests/charset.c b/lib/util/charset/tests/charset.c index 5e42ca2932..06acda80ab 100644 --- a/source4/lib/charset/tests/charset.c +++ b/lib/util/charset/tests/charset.c @@ -21,19 +21,19 @@ #include "includes.h" #include "torture/torture.h" -static bool test_toupper_w(struct torture_context *tctx) +static bool test_toupper_m(struct torture_context *tctx) { - torture_assert_int_equal(tctx, toupper_w('c'), 'C', "c"); - torture_assert_int_equal(tctx, toupper_w('Z'), 'Z', "z"); - torture_assert_int_equal(tctx, toupper_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); + torture_assert_int_equal(tctx, toupper_m('c'), 'C', "c"); + torture_assert_int_equal(tctx, toupper_m('Z'), 'Z', "z"); + torture_assert_int_equal(tctx, toupper_m(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); return true; } -static bool test_tolower_w(struct torture_context *tctx) +static bool test_tolower_m(struct torture_context *tctx) { - torture_assert_int_equal(tctx, tolower_w('C'), 'c', "c"); - torture_assert_int_equal(tctx, tolower_w('z'), 'z', "z"); - torture_assert_int_equal(tctx, tolower_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); + torture_assert_int_equal(tctx, tolower_m('C'), 'c', "c"); + torture_assert_int_equal(tctx, tolower_m('z'), 'z', "z"); + torture_assert_int_equal(tctx, tolower_m(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); return true; } @@ -58,43 +58,43 @@ static bool test_strcasecmp_m(struct torture_context *tctx) } -static bool test_strequal_w(struct torture_context *tctx) +static bool test_strequal_m(struct torture_context *tctx) { - torture_assert(tctx, !strequal_w("foo", "bar"), "different strings"); - torture_assert(tctx, strequal_w("foo", "foo"), "same case strings"); - torture_assert(tctx, strequal_w("foo", "Foo"), "different case strings"); - torture_assert(tctx, !strequal_w(NULL, "Foo"), "one NULL"); - torture_assert(tctx, !strequal_w("foo", NULL), "other NULL"); - torture_assert(tctx, strequal_w(NULL, NULL), "both NULL"); + torture_assert(tctx, !strequal_m("foo", "bar"), "different strings"); + torture_assert(tctx, strequal_m("foo", "foo"), "same case strings"); + torture_assert(tctx, strequal_m("foo", "Foo"), "different case strings"); + torture_assert(tctx, !strequal_m(NULL, "Foo"), "one NULL"); + torture_assert(tctx, !strequal_m("foo", NULL), "other NULL"); + torture_assert(tctx, strequal_m(NULL, NULL), "both NULL"); return true; } -static bool test_strcsequal_w(struct torture_context *tctx) +static bool test_strcsequal_m(struct torture_context *tctx) { - torture_assert(tctx, !strcsequal_w("foo", "bar"), "different strings"); - torture_assert(tctx, strcsequal_w("foo", "foo"), "same case strings"); - torture_assert(tctx, !strcsequal_w("foo", "Foo"), "different case strings"); - torture_assert(tctx, !strcsequal_w(NULL, "Foo"), "one NULL"); - torture_assert(tctx, !strcsequal_w("foo", NULL), "other NULL"); - torture_assert(tctx, strcsequal_w(NULL, NULL), "both NULL"); + torture_assert(tctx, !strcsequal_m("foo", "bar"), "different strings"); + torture_assert(tctx, strcsequal_m("foo", "foo"), "same case strings"); + torture_assert(tctx, !strcsequal_m("foo", "Foo"), "different case strings"); + torture_assert(tctx, !strcsequal_m(NULL, "Foo"), "one NULL"); + torture_assert(tctx, !strcsequal_m("foo", NULL), "other NULL"); + torture_assert(tctx, strcsequal_m(NULL, NULL), "both NULL"); return true; } -static bool test_string_replace_w(struct torture_context *tctx) +static bool test_string_replace_m(struct torture_context *tctx) { char data[6] = "bla"; - string_replace_w(data, 'b', 'c'); + string_replace_m(data, 'b', 'c'); torture_assert_str_equal(tctx, data, "cla", "first char replaced"); memcpy(data, "bab", 4); - string_replace_w(data, 'b', 'c'); + string_replace_m(data, 'b', 'c'); torture_assert_str_equal(tctx, data, "cac", "other chars replaced"); memcpy(data, "bba", 4); - string_replace_w(data, 'b', 'c'); + string_replace_m(data, 'b', 'c'); torture_assert_str_equal(tctx, data, "cca", "other chars replaced"); memcpy(data, "blala", 6); - string_replace_w(data, 'o', 'c'); + string_replace_m(data, 'o', 'c'); torture_assert_str_equal(tctx, data, "blala", "no chars replaced"); - string_replace_w(NULL, 'b', 'c'); + string_replace_m(NULL, 'b', 'c'); return true; } @@ -235,12 +235,12 @@ static bool test_strhasupper(struct torture_context *tctx) return true; } -static bool test_count_chars_w(struct torture_context *tctx) +static bool test_count_chars_m(struct torture_context *tctx) { - torture_assert_int_equal(tctx, count_chars_w("foo", 'o'), 2, "simple"); - torture_assert_int_equal(tctx, count_chars_w("", 'o'), 0, "empty"); - torture_assert_int_equal(tctx, count_chars_w("bla", 'o'), 0, "none"); - torture_assert_int_equal(tctx, count_chars_w("bla", '\0'), 0, "null"); + torture_assert_int_equal(tctx, count_chars_m("foo", 'o'), 2, "simple"); + torture_assert_int_equal(tctx, count_chars_m("", 'o'), 0, "empty"); + torture_assert_int_equal(tctx, count_chars_m("bla", 'o'), 0, "none"); + torture_assert_int_equal(tctx, count_chars_m("bla", '\0'), 0, "null"); return true; } @@ -248,13 +248,13 @@ struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "CHARSET"); - torture_suite_add_simple_test(suite, "toupper_w", test_toupper_w); - torture_suite_add_simple_test(suite, "tolower_w", test_tolower_w); + torture_suite_add_simple_test(suite, "toupper_m", test_toupper_m); + torture_suite_add_simple_test(suite, "tolower_m", test_tolower_m); torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi); torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m); - torture_suite_add_simple_test(suite, "strequal_w", test_strequal_w); - torture_suite_add_simple_test(suite, "strcsequal_w", test_strcsequal_w); - torture_suite_add_simple_test(suite, "string_replace_w", test_string_replace_w); + torture_suite_add_simple_test(suite, "strequal_m", test_strequal_m); + torture_suite_add_simple_test(suite, "strcsequal_m", test_strcsequal_m); + torture_suite_add_simple_test(suite, "string_replace_m", test_string_replace_m); torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m); torture_suite_add_simple_test(suite, "next_token", test_next_token); torture_suite_add_simple_test(suite, "next_token_null", test_next_token_null); @@ -266,7 +266,7 @@ struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "strlen_m_term", test_strlen_m_term); torture_suite_add_simple_test(suite, "strhaslower", test_strhaslower); torture_suite_add_simple_test(suite, "strhasupper", test_strhasupper); - torture_suite_add_simple_test(suite, "count_chars_w", test_count_chars_w); + torture_suite_add_simple_test(suite, "count_chars_m", test_count_chars_m); return suite; } diff --git a/source4/lib/charset/tests/iconv.c b/lib/util/charset/tests/iconv.c index aeb42c2fa1..aeb42c2fa1 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/lib/util/charset/tests/iconv.c diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c new file mode 100644 index 0000000000..85f9755557 --- /dev/null +++ b/lib/util/charset/util_unistr.c @@ -0,0 +1,927 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-2001 + Copyright (C) Simo Sorce 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "system/locale.h" +#include "param/param.h" + +static inline struct smb_iconv_convenience *get_iconv_convenience(void) +{ + static struct smb_iconv_convenience *ic = NULL; + if (ic == NULL) + ic = lp_iconv_convenience(global_loadparm); + return ic; +} + +/** + Case insensitive string compararison +**/ +_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + struct smb_iconv_convenience *iconv_convenience = get_iconv_convenience(); + + /* handle null ptr comparisons to simplify the use in qsort */ + if (s1 == s2) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; + + while (*s1 && *s2) { + c1 = next_codepoint(iconv_convenience, s1, &size1); + c2 = next_codepoint(iconv_convenience, s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return strcasecmp(s1, s2); + } + + if (toupper_m(c1) != toupper_m(c2)) { + return c1 - c2; + } + } + + return *s1 - *s2; +} + +/** + * Get the next token from a string, return False if none found. + * Handles double-quotes. + * + * Based on a routine by GJC@VILLAGE.COM. + * Extensively modified by Andrew.Tridgell@anu.edu.au + **/ +_PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) +{ + const char *s; + bool quoted; + size_t len=1; + + if (!ptr) + return false; + + s = *ptr; + + /* default to simple separators */ + if (!sep) + sep = " \t\n\r"; + + /* find the first non sep char */ + while (*s && strchr_m(sep,*s)) + s++; + + /* nothing left? */ + if (!*s) + return false; + + /* copy over the token */ + for (quoted = false; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { + if (*s == '\"') { + quoted = !quoted; + } else { + len++; + *buff++ = *s; + } + } + + *ptr = (*s) ? s+1 : s; + *buff = 0; + + return true; +} + +/** + Case insensitive string compararison, length limited +**/ +_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + struct smb_iconv_convenience *iconv_convenience = get_iconv_convenience(); + + /* handle null ptr comparisons to simplify the use in qsort */ + if (s1 == s2) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; + + while (*s1 && *s2 && n) { + n--; + + c1 = next_codepoint(iconv_convenience, s1, &size1); + c2 = next_codepoint(iconv_convenience, s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return strcasecmp(s1, s2); + } + + if (toupper_m(c1) != toupper_m(c2)) { + return c1 - c2; + } + } + + if (n == 0) { + return 0; + } + + return *s1 - *s2; +} + +/** + * Compare 2 strings. + * + * @note The comparison is case-insensitive. + **/ +_PUBLIC_ bool strequal_m(const char *s1, const char *s2) +{ + return strcasecmp_m(s1,s2) == 0; +} + +/** + Compare 2 strings (case sensitive). +**/ +_PUBLIC_ bool strcsequal_m(const char *s1,const char *s2) +{ + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; + + return strcmp(s1,s2) == 0; +} + + +/** + String replace. + NOTE: oldc and newc must be 7 bit characters +**/ +_PUBLIC_ void string_replace_m(char *s, char oldc, char newc) +{ + while (s && *s) { + size_t size; + codepoint_t c = next_codepoint(get_iconv_convenience(), s, &size); + if (c == oldc) { + *s = newc; + } + s += size; + } +} + +/** + 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, + but will be different for multibyte. +**/ +_PUBLIC_ 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(get_iconv_convenience(), s, &c_size); + if (c < 0x10000) { + count += 1; + } else { + count += 2; + } + s += c_size; + } + + return count; +} + +/** + Work out the number of multibyte chars in a string, including the NULL + terminator. +**/ +_PUBLIC_ size_t strlen_m_term(const char *s) +{ + if (!s) { + return 0; + } + + return strlen_m(s) + 1; +} + +/** + Strchr and strrchr_m are a bit complex on general multi-byte strings. +**/ +_PUBLIC_ char *strchr_m(const char *s, char c) +{ + if (s == NULL) { + return NULL; + } + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strchr(s, c); + } + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(get_iconv_convenience(), s, &size); + if (c2 == c) { + return discard_const_p(char, s); + } + s += size; + } + + return NULL; +} + +/** + * Multibyte-character version of strrchr + */ +_PUBLIC_ char *strrchr_m(const char *s, char c) +{ + char *ret = NULL; + + if (s == NULL) { + return NULL; + } + + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strrchr(s, c); + } + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(get_iconv_convenience(), s, &size); + if (c2 == c) { + ret = discard_const_p(char, s); + } + s += size; + } + + return ret; +} + +/** + return True if any (multi-byte) character is lower case +*/ +_PUBLIC_ bool strhaslower(const char *string) +{ + while (*string) { + size_t c_size; + codepoint_t s; + codepoint_t t; + + s = next_codepoint(get_iconv_convenience(), string, &c_size); + string += c_size; + + t = toupper_m(s); + + if (s != t) { + return true; /* that means it has lower case chars */ + } + } + + return false; +} + +/** + return True if any (multi-byte) character is upper case +*/ +_PUBLIC_ bool strhasupper(const char *string) +{ + while (*string) { + size_t c_size; + codepoint_t s; + codepoint_t t; + + s = next_codepoint(get_iconv_convenience(), string, &c_size); + string += c_size; + + t = tolower_m(s); + + if (s != t) { + return true; /* that means it has upper case chars */ + } + } + + return false; +} + +/** + Convert a string to lower case, allocated with talloc +**/ +_PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) +{ + size_t size=0; + char *dest; + struct smb_iconv_convenience *iconv_convenience = get_iconv_convenience(); + + /* this takes advantage of the fact that upper/lower can't + change the length of a character by more than 1 byte */ + dest = talloc_array(ctx, char, 2*(strlen(src))+1); + if (dest == NULL) { + return NULL; + } + + while (*src) { + size_t c_size; + codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); + src += c_size; + + c = tolower_m(c); + + c_size = push_codepoint(iconv_convenience, dest+size, c); + if (c_size == -1) { + talloc_free(dest); + return NULL; + } + size += c_size; + } + + dest[size] = 0; + + /* trim it so talloc_append_string() works */ + dest = talloc_realloc(ctx, dest, char, size+1); + + talloc_set_name_const(dest, dest); + + return dest; +} + +/** + Convert a string to UPPER case, allocated with talloc + source length limited to n bytes +**/ +_PUBLIC_ char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n) +{ + size_t size=0; + char *dest; + struct smb_iconv_convenience *iconv_convenience = get_iconv_convenience(); + + if (!src) { + return NULL; + } + + /* this takes advantage of the fact that upper/lower can't + change the length of a character by more than 1 byte */ + dest = talloc_array(ctx, char, 2*(n+1)); + if (dest == NULL) { + return NULL; + } + + while (*src && n--) { + size_t c_size; + codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); + src += c_size; + + c = toupper_m(c); + + c_size = push_codepoint(iconv_convenience, dest+size, c); + if (c_size == -1) { + talloc_free(dest); + return NULL; + } + size += c_size; + } + + dest[size] = 0; + + /* trim it so talloc_append_string() works */ + dest = talloc_realloc(ctx, dest, char, size+1); + + talloc_set_name_const(dest, dest); + + return dest; +} + +/** + Convert a string to UPPER case, allocated with talloc +**/ +_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) +{ + return strupper_talloc_n(ctx, src, src?strlen(src):0); +} + +/** + talloc_strdup() a unix string to upper case. +**/ +_PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src) +{ + return strupper_talloc(ctx, src); +} + +/** + Convert a string to lower case. +**/ +_PUBLIC_ void strlower_m(char *s) +{ + char *d; + struct smb_iconv_convenience *iconv_convenience; + + /* 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 && !(((uint8_t)*s) & 0x80)) { + *s = tolower((uint8_t)*s); + s++; + } + + if (!*s) + return; + + iconv_convenience = get_iconv_convenience(); + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint(iconv_convenience, s, &c_size); + c_size2 = push_codepoint(iconv_convenience, d, tolower_m(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", + c, tolower_m(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strlower_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + +/** + Convert a string to UPPER case. +**/ +_PUBLIC_ void strupper_m(char *s) +{ + char *d; + struct smb_iconv_convenience *iconv_convenience; + + /* 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 && !(((uint8_t)*s) & 0x80)) { + *s = toupper((uint8_t)*s); + s++; + } + + if (!*s) + return; + + iconv_convenience = get_iconv_convenience(); + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint(iconv_convenience, s, &c_size); + c_size2 = push_codepoint(iconv_convenience, d, toupper_m(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", + c, toupper_m(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strupper_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + + +/** + Find the number of 'c' chars in a string +**/ +_PUBLIC_ size_t count_chars_m(const char *s, char c) +{ + size_t count = 0; + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(get_iconv_convenience(), s, &size); + if (c2 == c) count++; + s += size; + } + + return count; +} + + +/** + * 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. 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) +{ + size_t src_len; + ssize_t ret; + struct smb_iconv_convenience *ic = get_iconv_convenience(); + + if (flags & STR_UPPER) { + char *tmpbuf = strupper_talloc(NULL, src); + if (tmpbuf == NULL) { + return -1; + } + ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER); + talloc_free(tmpbuf); + return ret; + } + + src_len = strlen(src); + + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) + src_len++; + + return convert_string(ic, CH_UNIX, CH_DOS, src, src_len, dest, dest_len); +} + +/** + * Copy a string from a unix char* src to an ASCII destination, + * allocating a buffer using talloc(). + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + * or -1 in case of error. + **/ +_PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, ic, CH_UNIX, CH_DOS, src, src_len, (void **)dest); +} + + +/** + * 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. + **/ +static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t ret; + + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { + 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(ic, CH_DOS, CH_UNIX, src, src_len, dest, dest_len); + + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; + + return src_len; +} + +/** + * 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. + **/ +static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t len=0; + size_t src_len = strlen(src); + size_t ret; + + if (flags & STR_UPPER) { + char *tmpbuf = strupper_talloc(NULL, src); + if (tmpbuf == NULL) { + return -1; + } + ret = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER); + talloc_free(tmpbuf); + return ret; + } + + if (flags & STR_TERMINATE) + src_len++; + + if (ucs2_align(NULL, 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(ic, CH_UNIX, CH_UTF16, src, src_len, dest, dest_len); + if (ret == (size_t)-1) { + return 0; + } + + len += ret; + + 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 + * + * @returns The number of bytes occupied by the string in the destination + * or -1 in case of error. + **/ +_PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, ic, CH_UNIX, CH_UTF16, src, src_len, dest); +} + + +/** + * 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 + * + * @returns The number of bytes occupied by the string in the destination + **/ + +_PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, ic, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); +} + +/** + 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. +**/ + +static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t ret; + + if (ucs2_align(NULL, src, flags)) { + src = (const void *)((const char *)src + 1); + if (src_len > 0) + src_len--; + } + + if (flags & STR_TERMINATE) { + if (src_len == (size_t)-1) { + src_len = utf16_len(src); + } else { + src_len = utf16_len_n(src, src_len); + } + } + + /* ucs2 is always a multiple of 2 bytes */ + if (src_len != (size_t)-1) + src_len &= ~1; + + ret = convert_string(ic, CH_UTF16, CH_UNIX, src, src_len, dest, dest_len); + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; + + return src_len; +} + +/** + * Copy a string from a ASCII src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + **/ + +_PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, ic, CH_DOS, CH_UNIX, src, src_len, (void **)dest); +} + +/** + * 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 + * + * @returns The number of bytes occupied by the string in the destination + **/ + +_PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t src_len = utf16_len(src); + *dest = NULL; + return convert_string_talloc(ctx, ic, CH_UTF16, CH_UNIX, src, src_len, (void **)dest); +} + +/** + * 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 + * + * @returns The number of bytes occupied by the string in the destination + **/ + +_PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + struct smb_iconv_convenience *ic = get_iconv_convenience(); + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, ic, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); +} + +/** + Copy a string from a char* src to a unicode or ascii + dos codepage destination choosing unicode or ascii based on the + flags in the SMB buffer starting at base_ptr. + Return the number of bytes occupied by the string in the destination. + flags can have: + STR_TERMINATE means include the null termination. + STR_UPPER means uppercase in the destination. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + dest_len is the maximum length allowed in the destination. If dest_len + is -1 then no maxiumum is used. +**/ + +_PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags) +{ + 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); + } 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. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_UNICODE means to force as unicode. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + if STR_TERMINATE is set then src_len is ignored is 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. +**/ + +_PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +{ + 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); + } else { + smb_panic("pull_string requires either STR_ASCII or STR_UNICODE flag to be set"); + return -1; + } +} + + diff --git a/lib/util/util.h b/lib/util/util.h index c2407ae9c9..1cf60bae39 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -22,7 +22,7 @@ #define _SAMBA_UTIL_H_ #if _SAMBA_BUILD_ == 4 -#include "lib/charset/charset.h" +#include "../lib/util/charset/charset.h" #endif #include "../lib/util/attr.h" diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 05455da084..127f6734e3 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -29,7 +29,7 @@ #include <sys/time.h> #if _SAMBA_BUILD_ == 4 #include "../lib/util/util.h" /* for discard_const */ -#include "lib/charset/charset.h" +#include "../lib/util/charset/charset.h" #endif /* diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index fc64c35fca..58e6910d3d 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -1142,7 +1142,7 @@ sub Parse($$$$$) #include \"includes.h\" #include <Python.h> #include \"librpc/rpc/dcerpc.h\" -#include \"scripting/python/pytalloc.h\" +#include \"lib/talloc/pytalloc.h\" #include \"librpc/rpc/pyrpc.h\" #include \"lib/events/events.h\" #include \"$hdr\" diff --git a/source3/samba4.m4 b/source3/samba4.m4 index 15fffb9e73..c68057fd35 100644 --- a/source3/samba4.m4 +++ b/source3/samba4.m4 @@ -33,7 +33,7 @@ m4_include(../lib/util/xattr.m4) m4_include(../lib/util/capability.m4) m4_include(../lib/util/time.m4) m4_include(../lib/popt/samba.m4) -m4_include(lib/charset/config.m4) +m4_include(../lib/util/charset/config.m4) m4_include(lib/socket/config.m4) m4_include(nsswitch/nsstest.m4) m4_include(../pidl/config.m4) diff --git a/source3/samba4.mk b/source3/samba4.mk index 5d1f0d1052..e08cbfcfec 100644 --- a/source3/samba4.mk +++ b/source3/samba4.mk @@ -73,7 +73,7 @@ authsrcdir := $(samba4srcdir)/auth nsswitchsrcdir := $(samba4srcdir)/nsswitch libsrcdir := $(samba4srcdir)/lib libsocketsrcdir := $(samba4srcdir)/lib/socket -libcharsetsrcdir := $(samba4srcdir)/lib/charset +libcharsetsrcdir := $(samba4srcdir)/../lib/util/charset ldb_sambasrcdir := $(samba4srcdir)/lib/ldb-samba libtlssrcdir := $(samba4srcdir)/lib/tls libregistrysrcdir := $(samba4srcdir)/lib/registry diff --git a/source4/Makefile b/source4/Makefile index 26cab668c8..be41d02a38 100644 --- a/source4/Makefile +++ b/source4/Makefile @@ -59,7 +59,7 @@ authsrcdir := auth nsswitchsrcdir := nsswitch libsrcdir := lib libsocketsrcdir := lib/socket -libcharsetsrcdir := lib/charset +libcharsetsrcdir := ../lib/util/charset ldb_sambasrcdir := lib/ldb-samba tdbsrcdir := ../lib/tdb ldbsrcdir := lib/ldb diff --git a/source4/auth/ntlm/auth_util.c b/source4/auth/ntlm/auth_util.c index 64ceb437ad..2f8ef10e05 100644 --- a/source4/auth/ntlm/auth_util.c +++ b/source4/auth/ntlm/auth_util.c @@ -145,7 +145,7 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex chall_blob = data_blob_talloc(mem_ctx, challenge, 8); if (lp_client_ntlmv2_auth(auth_context->lp_ctx)) { - DATA_BLOB names_blob = NTLMv2_generate_names_blob(mem_ctx, lp_iconv_convenience(auth_context->lp_ctx), lp_netbios_name(auth_context->lp_ctx), lp_workgroup(auth_context->lp_ctx)); + DATA_BLOB names_blob = NTLMv2_generate_names_blob(mem_ctx, lp_netbios_name(auth_context->lp_ctx), lp_workgroup(auth_context->lp_ctx)); DATA_BLOB lmv2_response, ntlmv2_response, lmv2_session_key, ntlmv2_session_key; if (!SMBNTLMv2encrypt_hash(user_info_temp, diff --git a/source4/auth/ntlmssp/ntlmssp_client.c b/source4/auth/ntlmssp/ntlmssp_client.c index eb990dee9c..0ef40200fe 100644 --- a/source4/auth/ntlmssp/ntlmssp_client.c +++ b/source4/auth/ntlmssp/ntlmssp_client.c @@ -73,7 +73,6 @@ NTSTATUS ntlmssp_client_initial(struct gensec_security *gensec_security, /* generate the ntlmssp negotiate packet */ msrpc_gen(out_mem_ctx, - lp_iconv_convenience(gensec_security->lp_ctx), out, "CddAA", "NTLMSSP", NTLMSSP_NEGOTIATE, @@ -258,7 +257,6 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, /* this generates the actual auth packet */ if (!msrpc_gen(mem_ctx, - lp_iconv_convenience(gensec_security->lp_ctx), out, auth_gen_string, "NTLMSSP", NTLMSSP_AUTH, diff --git a/source4/auth/ntlmssp/ntlmssp_parse.c b/source4/auth/ntlmssp/ntlmssp_parse.c index 9256872036..cd270590f1 100644 --- a/source4/auth/ntlmssp/ntlmssp_parse.c +++ b/source4/auth/ntlmssp/ntlmssp_parse.c @@ -42,7 +42,6 @@ C = constant ascii string */ bool msrpc_gen(TALLOC_CTX *mem_ctx, - struct smb_iconv_convenience *iconv_convenience, DATA_BLOB *blob, const char *format, ...) { @@ -67,7 +66,7 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx, case 'U': s = va_arg(ap, char *); head_size += 8; - n = push_ucs2_talloc(pointers, iconv_convenience, (void **)&pointers[i].data, s); + n = push_ucs2_talloc(pointers, (void **)&pointers[i].data, s); if (n == -1) { return false; } @@ -78,7 +77,7 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx, case 'A': s = va_arg(ap, char *); head_size += 8; - n = push_ascii_talloc(pointers, iconv_convenience, (char **)&pointers[i].data, s); + n = push_ascii_talloc(pointers, (char **)&pointers[i].data, s); if (n == -1) { return false; } @@ -90,7 +89,7 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx, n = va_arg(ap, int); intargs[i] = n; s = va_arg(ap, char *); - n = push_ucs2_talloc(pointers, iconv_convenience, (void **)&pointers[i].data, s); + n = push_ucs2_talloc(pointers, (void **)&pointers[i].data, s); if (n == -1) { return false; } @@ -248,7 +247,7 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, } if (0 < len1) { - pull_string(iconv_convenience, p, blob->data + ptr, p_len, + pull_string(p, blob->data + ptr, p_len, len1, STR_UNICODE|STR_NOALIGN); (*ps) = talloc_strdup(mem_ctx, p); if (!(*ps)) { @@ -283,7 +282,7 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, } if (0 < len1) { - pull_string(iconv_convenience, p, blob->data + ptr, p_len, + pull_string(p, blob->data + ptr, p_len, len1, STR_ASCII|STR_NOALIGN); (*ps) = talloc_strdup(mem_ctx, p); if (!(*ps)) { @@ -348,7 +347,7 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, goto cleanup; } - head_ofs += pull_string(iconv_convenience, p, + head_ofs += pull_string(p, blob->data+head_ofs, p_len, blob->length - head_ofs, STR_ASCII|STR_TERMINATE); diff --git a/source4/auth/ntlmssp/ntlmssp_server.c b/source4/auth/ntlmssp/ntlmssp_server.c index ad1ee8e871..38973f623d 100644 --- a/source4/auth/ntlmssp/ntlmssp_server.c +++ b/source4/auth/ntlmssp/ntlmssp_server.c @@ -205,7 +205,6 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, } msrpc_gen(out_mem_ctx, - lp_iconv_convenience(gensec_security->lp_ctx), &struct_blob, "aaaaa", NTLMSSP_NAME_TYPE_DOMAIN, target_name, NTLMSSP_NAME_TYPE_SERVER, gensec_ntlmssp_state->server_name, @@ -226,7 +225,6 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, } msrpc_gen(out_mem_ctx, - lp_iconv_convenience(gensec_security->lp_ctx), out, gen_string, "NTLMSSP", NTLMSSP_CHALLENGE, diff --git a/source4/auth/ntlmssp/ntlmssp_sign.c b/source4/auth/ntlmssp/ntlmssp_sign.c index 49ed48df98..47d7a2104a 100644 --- a/source4/auth/ntlmssp/ntlmssp_sign.c +++ b/source4/auth/ntlmssp/ntlmssp_sign.c @@ -119,7 +119,6 @@ static NTSTATUS ntlmssp_make_packet_signature(struct gensec_ntlmssp_state *gense uint32_t crc; crc = crc32_calc_buffer(data, length); if (!msrpc_gen(sig_mem_ctx, - lp_iconv_convenience(gensec_ntlmssp_state->gensec_security->lp_ctx), sig, "dddd", NTLMSSP_SIGN_VERSION, 0, crc, gensec_ntlmssp_state->crypt.ntlm.seq_num)) { return NT_STATUS_NO_MEMORY; } @@ -248,7 +247,6 @@ NTSTATUS gensec_ntlmssp_seal_packet(struct gensec_security *gensec_security, uint32_t crc; crc = crc32_calc_buffer(data, length); if (!msrpc_gen(sig_mem_ctx, - lp_iconv_convenience(gensec_security->lp_ctx), sig, "dddd", NTLMSSP_SIGN_VERSION, 0, crc, gensec_ntlmssp_state->crypt.ntlm.seq_num)) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/configure.ac b/source4/configure.ac index 9d387fcb4c..cf85b13225 100644 --- a/source4/configure.ac +++ b/source4/configure.ac @@ -22,7 +22,7 @@ m4_include(../lib/util/xattr.m4) m4_include(../lib/util/capability.m4) m4_include(../lib/util/time.m4) m4_include(../lib/popt/samba.m4) -m4_include(lib/charset/config.m4) +m4_include(../lib/util/charset/config.m4) m4_include(lib/socket/config.m4) m4_include(../lib/zlib/zlib.m4) AC_ZLIB([ diff --git a/source4/dsdb/schema/schema_syntax.c b/source4/dsdb/schema/schema_syntax.c index 97cd0020a9..b0018c8161 100644 --- a/source4/dsdb/schema/schema_syntax.c +++ b/source4/dsdb/schema/schema_syntax.c @@ -25,7 +25,7 @@ #include "librpc/gen_ndr/ndr_drsuapi.h" #include "lib/ldb/include/ldb.h" #include "system/time.h" -#include "lib/charset/charset.h" +#include "../lib/util/charset/charset.h" #include "librpc/ndr/libndr.h" #include "param/param.h" diff --git a/source4/kdc/kpasswdd.c b/source4/kdc/kpasswdd.c index 1336b0157e..63b5f2a2e4 100644 --- a/source4/kdc/kpasswdd.c +++ b/source4/kdc/kpasswdd.c @@ -65,7 +65,7 @@ static bool kpasswdd_make_error_reply(struct kdc_server *kdc, DEBUG(result_code ? 3 : 10, ("kpasswdd: %s\n", error_string)); - len = push_utf8_talloc(mem_ctx, lp_iconv_convenience(kdc->task->lp_ctx), &error_string_utf8, error_string); + len = push_utf8_talloc(mem_ctx, &error_string_utf8, error_string); if (len == -1) { return false; } diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c deleted file mode 100644 index e4f4bb551a..0000000000 --- a/source4/lib/charset/util_unistr.c +++ /dev/null @@ -1,684 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-2001 - Copyright (C) Simo Sorce 2001 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "system/locale.h" -#include "dynconfig/dynconfig.h" -#include "param/param.h" - -/** - * @file - * @brief Unicode string manipulation - */ - -/* these 2 tables define the unicode case handling. They are loaded - at startup either via mmap() or read() from the lib directory */ -static void *upcase_table; -static void *lowcase_table; - - -/******************************************************************* -load the case handling tables -********************************************************************/ -void load_case_tables(void) -{ - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init("load_case_tables"); - if (!mem_ctx) { - smb_panic("No memory for case_tables"); - } - upcase_table = map_file(talloc_asprintf(mem_ctx, "%s/upcase.dat", dyn_DATADIR), 0x20000); - lowcase_table = map_file(talloc_asprintf(mem_ctx, "%s/lowcase.dat", dyn_DATADIR), 0x20000); - talloc_free(mem_ctx); - if (upcase_table == NULL) { - /* try also under codepages for testing purposes */ - upcase_table = map_file("codepages/upcase.dat", 0x20000); - if (upcase_table == NULL) { - upcase_table = (void *)-1; - } - } - if (lowcase_table == NULL) { - /* try also under codepages for testing purposes */ - lowcase_table = map_file("codepages/lowcase.dat", 0x20000); - if (lowcase_table == NULL) { - lowcase_table = (void *)-1; - } - } -} - -/** - Convert a codepoint_t to upper case. -**/ -_PUBLIC_ codepoint_t toupper_w(codepoint_t val) -{ - if (val < 128) { - return toupper(val); - } - if (upcase_table == NULL) { - load_case_tables(); - } - if (upcase_table == (void *)-1) { - return val; - } - if (val & 0xFFFF0000) { - return val; - } - return SVAL(upcase_table, val*2); -} - -/** - Convert a codepoint_t to lower case. -**/ -_PUBLIC_ codepoint_t tolower_w(codepoint_t val) -{ - if (val < 128) { - return tolower(val); - } - if (lowcase_table == NULL) { - load_case_tables(); - } - if (lowcase_table == (void *)-1) { - return val; - } - if (val & 0xFFFF0000) { - return val; - } - return SVAL(lowcase_table, val*2); -} - -/** - compare two codepoints case insensitively -*/ -_PUBLIC_ int codepoint_cmpi(codepoint_t c1, codepoint_t c2) -{ - if (c1 == c2 || - toupper_w(c1) == toupper_w(c2)) { - return 0; - } - return c1 - c2; -} - -/** - Case insensitive string compararison -**/ -_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) -{ - codepoint_t c1=0, c2=0; - size_t size1, size2; - struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); - - /* handle null ptr comparisons to simplify the use in qsort */ - if (s1 == s2) return 0; - if (s1 == NULL) return -1; - if (s2 == NULL) return 1; - - while (*s1 && *s2) { - c1 = next_codepoint(iconv_convenience, s1, &size1); - c2 = next_codepoint(iconv_convenience, s2, &size2); - - s1 += size1; - s2 += size2; - - if (c1 == c2) { - continue; - } - - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* what else can we do?? */ - return strcasecmp(s1, s2); - } - - if (toupper_w(c1) != toupper_w(c2)) { - return c1 - c2; - } - } - - return *s1 - *s2; -} - -/** - * Get the next token from a string, return False if none found. - * Handles double-quotes. - * - * Based on a routine by GJC@VILLAGE.COM. - * Extensively modified by Andrew.Tridgell@anu.edu.au - **/ -_PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) -{ - const char *s; - bool quoted; - size_t len=1; - - if (!ptr) - return false; - - s = *ptr; - - /* default to simple separators */ - if (!sep) - sep = " \t\n\r"; - - /* find the first non sep char */ - while (*s && strchr_m(sep,*s)) - s++; - - /* nothing left? */ - if (!*s) - return false; - - /* copy over the token */ - for (quoted = false; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { - if (*s == '\"') { - quoted = !quoted; - } else { - len++; - *buff++ = *s; - } - } - - *ptr = (*s) ? s+1 : s; - *buff = 0; - - return true; -} - -/** - Case insensitive string compararison, length limited -**/ -_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) -{ - codepoint_t c1=0, c2=0; - size_t size1, size2; - struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); - - /* handle null ptr comparisons to simplify the use in qsort */ - if (s1 == s2) return 0; - if (s1 == NULL) return -1; - if (s2 == NULL) return 1; - - while (*s1 && *s2 && n) { - n--; - - c1 = next_codepoint(iconv_convenience, s1, &size1); - c2 = next_codepoint(iconv_convenience, s2, &size2); - - s1 += size1; - s2 += size2; - - if (c1 == c2) { - continue; - } - - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* what else can we do?? */ - return strcasecmp(s1, s2); - } - - if (toupper_w(c1) != toupper_w(c2)) { - return c1 - c2; - } - } - - if (n == 0) { - return 0; - } - - return *s1 - *s2; -} - -/** - * Compare 2 strings. - * - * @note The comparison is case-insensitive. - **/ -_PUBLIC_ bool strequal_w(const char *s1, const char *s2) -{ - return strcasecmp_m(s1,s2) == 0; -} - -/** - Compare 2 strings (case sensitive). -**/ -_PUBLIC_ bool strcsequal_w(const char *s1,const char *s2) -{ - if (s1 == s2) - return true; - if (!s1 || !s2) - return false; - - return strcmp(s1,s2) == 0; -} - - -/** - String replace. - NOTE: oldc and newc must be 7 bit characters -**/ -_PUBLIC_ void string_replace_w(char *s, char oldc, char newc) -{ - while (s && *s) { - size_t size; - codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); - if (c == oldc) { - *s = newc; - } - s += size; - } -} - -/** - 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, - but will be different for multibyte. -**/ -_PUBLIC_ 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(lp_iconv_convenience(global_loadparm), s, &c_size); - if (c < 0x10000) { - count += 1; - } else { - count += 2; - } - s += c_size; - } - - return count; -} - -/** - Work out the number of multibyte chars in a string, including the NULL - terminator. -**/ -_PUBLIC_ size_t strlen_m_term(const char *s) -{ - if (!s) { - return 0; - } - - return strlen_m(s) + 1; -} - -/** - Strchr and strrchr_m are a bit complex on general multi-byte strings. -**/ -_PUBLIC_ char *strchr_m(const char *s, char c) -{ - if (s == NULL) { - return NULL; - } - /* characters below 0x3F are guaranteed to not appear in - non-initial position in multi-byte charsets */ - if ((c & 0xC0) == 0) { - return strchr(s, c); - } - - while (*s) { - size_t size; - codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); - if (c2 == c) { - return discard_const_p(char, s); - } - s += size; - } - - return NULL; -} - -/** - * Multibyte-character version of strrchr - */ -_PUBLIC_ char *strrchr_m(const char *s, char c) -{ - char *ret = NULL; - - if (s == NULL) { - return NULL; - } - - /* characters below 0x3F are guaranteed to not appear in - non-initial position in multi-byte charsets */ - if ((c & 0xC0) == 0) { - return strrchr(s, c); - } - - while (*s) { - size_t size; - codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); - if (c2 == c) { - ret = discard_const_p(char, s); - } - s += size; - } - - return ret; -} - -/** - return True if any (multi-byte) character is lower case -*/ -_PUBLIC_ bool strhaslower(const char *string) -{ - while (*string) { - size_t c_size; - codepoint_t s; - codepoint_t t; - - s = next_codepoint(lp_iconv_convenience(global_loadparm), string, &c_size); - string += c_size; - - t = toupper_w(s); - - if (s != t) { - return true; /* that means it has lower case chars */ - } - } - - return false; -} - -/** - return True if any (multi-byte) character is upper case -*/ -_PUBLIC_ bool strhasupper(const char *string) -{ - while (*string) { - size_t c_size; - codepoint_t s; - codepoint_t t; - - s = next_codepoint(lp_iconv_convenience(global_loadparm), string, &c_size); - string += c_size; - - t = tolower_w(s); - - if (s != t) { - return true; /* that means it has upper case chars */ - } - } - - return false; -} - -/** - Convert a string to lower case, allocated with talloc -**/ -_PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) -{ - size_t size=0; - char *dest; - struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); - - /* this takes advantage of the fact that upper/lower can't - change the length of a character by more than 1 byte */ - dest = talloc_array(ctx, char, 2*(strlen(src))+1); - if (dest == NULL) { - return NULL; - } - - while (*src) { - size_t c_size; - codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); - src += c_size; - - c = tolower_w(c); - - c_size = push_codepoint(iconv_convenience, dest+size, c); - if (c_size == -1) { - talloc_free(dest); - return NULL; - } - size += c_size; - } - - dest[size] = 0; - - /* trim it so talloc_append_string() works */ - dest = talloc_realloc(ctx, dest, char, size+1); - - talloc_set_name_const(dest, dest); - - return dest; -} - -/** - Convert a string to UPPER case, allocated with talloc - source length limited to n bytes -**/ -_PUBLIC_ char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n) -{ - size_t size=0; - char *dest; - struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); - - if (!src) { - return NULL; - } - - /* this takes advantage of the fact that upper/lower can't - change the length of a character by more than 1 byte */ - dest = talloc_array(ctx, char, 2*(n+1)); - if (dest == NULL) { - return NULL; - } - - while (*src && n--) { - size_t c_size; - codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); - src += c_size; - - c = toupper_w(c); - - c_size = push_codepoint(iconv_convenience, dest+size, c); - if (c_size == -1) { - talloc_free(dest); - return NULL; - } - size += c_size; - } - - dest[size] = 0; - - /* trim it so talloc_append_string() works */ - dest = talloc_realloc(ctx, dest, char, size+1); - - talloc_set_name_const(dest, dest); - - return dest; -} - -/** - Convert a string to UPPER case, allocated with talloc -**/ -_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) -{ - return strupper_talloc_n(ctx, src, src?strlen(src):0); -} - -/** - talloc_strdup() a unix string to upper case. -**/ -_PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src) -{ - return strupper_talloc(ctx, src); -} - -/** - Convert a string to lower case. -**/ -_PUBLIC_ void strlower_m(char *s) -{ - char *d; - struct smb_iconv_convenience *iconv_convenience; - - /* 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 && !(((uint8_t)*s) & 0x80)) { - *s = tolower((uint8_t)*s); - s++; - } - - if (!*s) - return; - - iconv_convenience = lp_iconv_convenience(global_loadparm); - - d = s; - - while (*s) { - size_t c_size, c_size2; - codepoint_t c = next_codepoint(iconv_convenience, s, &c_size); - c_size2 = push_codepoint(iconv_convenience, d, tolower_w(c)); - if (c_size2 > c_size) { - DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", - c, tolower_w(c), (int)c_size, (int)c_size2)); - smb_panic("codepoint expansion in strlower_m\n"); - } - s += c_size; - d += c_size2; - } - *d = 0; -} - -/** - Convert a string to UPPER case. -**/ -_PUBLIC_ void strupper_m(char *s) -{ - char *d; - struct smb_iconv_convenience *iconv_convenience; - - /* 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 && !(((uint8_t)*s) & 0x80)) { - *s = toupper((uint8_t)*s); - s++; - } - - if (!*s) - return; - - iconv_convenience = lp_iconv_convenience(global_loadparm); - - d = s; - - while (*s) { - size_t c_size, c_size2; - codepoint_t c = next_codepoint(iconv_convenience, s, &c_size); - c_size2 = push_codepoint(iconv_convenience, d, toupper_w(c)); - if (c_size2 > c_size) { - DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", - c, toupper_w(c), (int)c_size, (int)c_size2)); - smb_panic("codepoint expansion in strupper_m\n"); - } - s += c_size; - d += c_size2; - } - *d = 0; -} - - -/** - Find the number of 'c' chars in a string -**/ -_PUBLIC_ size_t count_chars_w(const char *s, char c) -{ - size_t count = 0; - - while (*s) { - size_t size; - codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); - if (c2 == c) count++; - s += size; - } - - return count; -} - - diff --git a/source4/lib/tdr/tdr.h b/source4/lib/tdr/tdr.h index 301cd3002e..c983cd35c1 100644 --- a/source4/lib/tdr/tdr.h +++ b/source4/lib/tdr/tdr.h @@ -21,7 +21,7 @@ #define __TDR_H__ #include <talloc.h> -#include "charset/charset.h" +#include "../lib/util/charset/charset.h" #define TDR_BIG_ENDIAN 0x01 #define TDR_ALIGN2 0x02 diff --git a/source4/libcli/auth/smbencrypt.c b/source4/libcli/auth/smbencrypt.c index a78c444da7..2803aaff5e 100644 --- a/source4/libcli/auth/smbencrypt.c +++ b/source4/libcli/auth/smbencrypt.c @@ -67,7 +67,7 @@ bool E_md4hash(const char *passwd, uint8_t p16[16]) int len; void *wpwd; - len = push_ucs2_talloc(NULL, lp_iconv_convenience(global_loadparm), &wpwd, passwd); + len = push_ucs2_talloc(NULL, &wpwd, passwd); if (len < 2) { /* We don't want to return fixed data, as most callers * don't check */ @@ -97,7 +97,7 @@ bool E_deshash(const char *passwd, uint8_t p16[16]) ZERO_STRUCT(dospwd); /* Password must be converted to DOS charset - null terminated, uppercase. */ - push_string(lp_iconv_convenience(global_loadparm), dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); + push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); /* Only the first 14 chars are considered, password need not be null terminated. */ E_P16((const uint8_t *)dospwd, p16); @@ -124,7 +124,6 @@ bool ntv2_owf_gen(const uint8_t owf[16], HMACMD5Context ctx; TALLOC_CTX *mem_ctx = talloc_init("ntv2_owf_gen for %s\\%s", domain_in, user_in); - struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); if (!mem_ctx) { return false; @@ -152,14 +151,14 @@ bool ntv2_owf_gen(const uint8_t owf[16], } } - user_byte_len = push_ucs2_talloc(mem_ctx, iconv_convenience, &user, user_in); + user_byte_len = push_ucs2_talloc(mem_ctx, &user, user_in); if (user_byte_len == (ssize_t)-1) { DEBUG(0, ("push_uss2_talloc() for user returned -1 (probably talloc() failure)\n")); talloc_free(mem_ctx); return false; } - domain_byte_len = push_ucs2_talloc(mem_ctx, iconv_convenience, &domain, domain_in); + domain_byte_len = push_ucs2_talloc(mem_ctx, &domain, domain_in); if (domain_byte_len == (ssize_t)-1) { DEBUG(0, ("push_ucs2_talloc() for domain returned -1 (probably talloc() failure)\n")); talloc_free(mem_ctx); @@ -295,13 +294,12 @@ void SMBsesskeygen_lm_sess_key(const uint8_t lm_hash[16], } DATA_BLOB NTLMv2_generate_names_blob(TALLOC_CTX *mem_ctx, - struct smb_iconv_convenience *iconv_convenience, const char *hostname, const char *domain) { DATA_BLOB names_blob = data_blob_talloc(mem_ctx, NULL, 0); - msrpc_gen(mem_ctx, iconv_convenience, &names_blob, + msrpc_gen(mem_ctx, &names_blob, "aaa", NTLMSSP_NAME_TYPE_DOMAIN, domain, NTLMSSP_NAME_TYPE_SERVER, hostname, @@ -324,7 +322,7 @@ static DATA_BLOB NTLMv2_generate_client_data(TALLOC_CTX *mem_ctx, const DATA_BLO /* See http://www.ubiqx.org/cifs/SMB.html#SMB.8.5 */ - msrpc_gen(mem_ctx, NULL, &response, "ddbbdb", + msrpc_gen(mem_ctx, &response, "ddbbdb", 0x00000101, /* Header */ 0, /* 'Reserved' */ long_date, 8, /* Timestamp */ @@ -472,7 +470,7 @@ bool encode_pw_buffer(uint8_t buffer[516], const char *password, int string_flag /* the incoming buffer can be any alignment. */ string_flags |= STR_NOALIGN; - new_pw_len = push_string(lp_iconv_convenience(global_loadparm), new_pw, + new_pw_len = push_string(new_pw, password, sizeof(new_pw), string_flags); @@ -525,7 +523,7 @@ bool decode_pw_buffer(uint8_t in_buffer[516], char *new_pwrd, } /* decode into the return buffer. Buffer length supplied */ - converted_pw_len = pull_string(lp_iconv_convenience(global_loadparm), new_pwrd, &in_buffer[512 - byte_len], new_pwrd_size, + converted_pw_len = pull_string(new_pwrd, &in_buffer[512 - byte_len], new_pwrd_size, byte_len, string_flags); if (converted_pw_len == -1) { diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 4b5d2dc397..ccfb28b84d 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -196,10 +196,9 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.fallback_to_anonymous = false; /* This workgroup gets sent out by the SPNEGO session setup. - * I don't know of any servers that look at it, so we might - * hardcode it to "" some day, when the war on global_loadparm - * is complete -- abartlet 2008-04-28 */ - io.in.workgroup = lp_workgroup(global_loadparm); + * I don't know of any servers that look at it, so we + * hardcode it to "". */ + io.in.workgroup = ""; io.in.options = *options; io.in.session_options = *session_options; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 353b66c622..caef28d7fc 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -430,7 +430,7 @@ size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uin smbcli_req_grow_allocation(req, len + req->out.data_size); - len = push_string(lp_iconv_convenience(global_loadparm), req->out.data + req->out.data_size, str, len, flags); + len = push_string(req->out.data + req->out.data_size, str, len, flags); smbcli_req_grow_data(req, len + req->out.data_size); @@ -977,7 +977,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, return 0; } - len = push_string(lp_iconv_convenience(global_loadparm), blob->data + blob->length, str, max_len, flags); + len = push_string(blob->data + blob->length, str, max_len, flags); blob->length += len; diff --git a/source4/libcli/smb_composite/sesssetup.c b/source4/libcli/smb_composite/sesssetup.c index 645f5362ac..76c1f952e7 100644 --- a/source4/libcli/smb_composite/sesssetup.c +++ b/source4/libcli/smb_composite/sesssetup.c @@ -260,7 +260,7 @@ static NTSTATUS session_setup_nt1(struct composite_context *c, { NTSTATUS nt_status = NT_STATUS_INTERNAL_ERROR; struct sesssetup_state *state = talloc_get_type(c->private_data, struct sesssetup_state); - DATA_BLOB names_blob = NTLMv2_generate_names_blob(state, lp_iconv_convenience(global_loadparm), session->transport->socket->hostname, lp_workgroup(global_loadparm)); + DATA_BLOB names_blob = NTLMv2_generate_names_blob(state, session->transport->socket->hostname, lp_workgroup(global_loadparm)); DATA_BLOB session_key = data_blob(NULL, 0); int flags = CLI_CRED_NTLM_AUTH; @@ -334,7 +334,7 @@ static NTSTATUS session_setup_old(struct composite_context *c, NTSTATUS nt_status; struct sesssetup_state *state = talloc_get_type(c->private_data, struct sesssetup_state); const char *password = cli_credentials_get_password(io->in.credentials); - DATA_BLOB names_blob = NTLMv2_generate_names_blob(state, lp_iconv_convenience(global_loadparm), session->transport->socket->hostname, lp_workgroup(global_loadparm)); + DATA_BLOB names_blob = NTLMv2_generate_names_blob(state, session->transport->socket->hostname, lp_workgroup(global_loadparm)); DATA_BLOB session_key; int flags = 0; if (session->options.lanman_auth) { diff --git a/source4/libnet/libnet_user.h b/source4/libnet/libnet_user.h index 7095160004..4aad654b3b 100644 --- a/source4/libnet/libnet_user.h +++ b/source4/libnet/libnet_user.h @@ -67,7 +67,7 @@ struct libnet_ModifyUser { #define SET_FIELD_LSA_STRING(new, current, mod, field, flag) \ if (new.field != NULL && \ - !strequal_w(current->field.string, new.field)) { \ + !strequal_m(current->field.string, new.field)) { \ \ mod->field = talloc_strdup(mem_ctx, new.field); \ if (mod->field == NULL) return NT_STATUS_NO_MEMORY; \ diff --git a/source4/main.mk b/source4/main.mk index 8ce86b91ca..278c38454d 100644 --- a/source4/main.mk +++ b/source4/main.mk @@ -9,7 +9,7 @@ mkinclude auth/config.mk mkinclude nsswitch/config.mk mkinclude lib/samba3/config.mk mkinclude lib/socket/config.mk -mkinclude lib/charset/config.mk +mkinclude ../lib/util/charset/config.mk mkinclude lib/ldb-samba/config.mk mkinclude lib/tls/config.mk mkinclude lib/registry/config.mk diff --git a/source4/nsswitch/wbinfo.c b/source4/nsswitch/wbinfo.c index a36a66b80f..60c95a3bd0 100644 --- a/source4/nsswitch/wbinfo.c +++ b/source4/nsswitch/wbinfo.c @@ -836,7 +836,7 @@ static bool wbinfo_auth_crap(struct loadparm_context *lp_ctx, char *username) server_chal = data_blob(request.data.auth_crap.chal, 8); /* Pretend this is a login to 'us', for blob purposes */ - names_blob = NTLMv2_generate_names_blob(mem_ctx, lp_iconv_convenience(lp_ctx), lp_netbios_name(lp_ctx), lp_workgroup(lp_ctx)); + names_blob = NTLMv2_generate_names_blob(mem_ctx, lp_netbios_name(lp_ctx), lp_workgroup(lp_ctx)); if (!SMBNTLMv2encrypt(mem_ctx, name_user, name_domain, pass, &server_chal, &names_blob, diff --git a/source4/ntvfs/posix/pvfs_util.c b/source4/ntvfs/posix/pvfs_util.c index b52c3e387b..720ddaaa7b 100644 --- a/source4/ntvfs/posix/pvfs_util.c +++ b/source4/ntvfs/posix/pvfs_util.c @@ -183,7 +183,7 @@ uint32_t pvfs_name_hash(const char *key, size_t length) while (*key && length--) { size_t c_size; codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), key, &c_size); - c = toupper_w(c); + c = toupper_m(c); value *= fnv1_prime; value ^= (uint32_t)c; key += c_size; diff --git a/source4/ntvfs/print/vfs_print.c b/source4/ntvfs/print/vfs_print.c index aa9b11a973..540e51a43b 100644 --- a/source4/ntvfs/print/vfs_print.c +++ b/source4/ntvfs/print/vfs_print.c @@ -83,8 +83,8 @@ static NTSTATUS print_ioctl(struct ntvfs_module_context *ntvfs, p = (char *)io->ioctl.out.blob.data; SSVAL(p,0, 1 /* REWRITE: fsp->rap_print_jobid */); - push_string(lp_iconv_convenience(ntvfs->ctx->lp_ctx), p+2, lp_netbios_name(ntvfs->ctx->lp_ctx), 15, STR_TERMINATE|STR_ASCII); - push_string(lp_iconv_convenience(ntvfs->ctx->lp_ctx), p+18, ntvfs->ctx->config->name, 13, STR_TERMINATE|STR_ASCII); + push_string(p+2, lp_netbios_name(ntvfs->ctx->lp_ctx), 15, STR_TERMINATE|STR_ASCII); + push_string(p+18, ntvfs->ctx->config->name, 13, STR_TERMINATE|STR_ASCII); return NT_STATUS_OK; } diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk index c88728a9fd..5a44fd5ae6 100644 --- a/source4/scripting/python/config.mk +++ b/source4/scripting/python/config.mk @@ -8,7 +8,7 @@ LIBPYTHON_OBJ_FILES = $(addprefix $(pyscriptsrcdir)/, modules.o) [SUBSYSTEM::PYTALLOC] PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON LIBTALLOC -PYTALLOC_OBJ_FILES = $(addprefix $(pyscriptsrcdir)/, pytalloc.o) +PYTALLOC_OBJ_FILES = ../lib/talloc/pytalloc.o [PYTHON::python_uuid] PRIVATE_DEPENDENCIES = LIBNDR diff --git a/source4/smb_server/blob.c b/source4/smb_server/blob.c index bd250361a4..baa9b3e4d8 100644 --- a/source4/smb_server/blob.c +++ b/source4/smb_server/blob.c @@ -140,10 +140,10 @@ size_t smbsrv_blob_push_string(TALLOC_CTX *mem_ctx, alignment = 1; if (dest_len > 0) { SCVAL(blob->data + offset, 0, 0); - ret = push_string(lp_iconv_convenience(global_loadparm), blob->data + offset + 1, str, dest_len-1, flags); + ret = push_string(blob->data + offset + 1, str, dest_len-1, flags); } } else { - ret = push_string(lp_iconv_convenience(global_loadparm), blob->data + offset, str, dest_len, flags); + ret = push_string(blob->data + offset, str, dest_len, flags); } /* sometimes the string needs to be terminated, but the length diff --git a/source4/smb_server/smb/nttrans.c b/source4/smb_server/smb/nttrans.c index 4a06ea4b91..3480711ed2 100644 --- a/source4/smb_server/smb/nttrans.c +++ b/source4/smb_server/smb/nttrans.c @@ -398,7 +398,7 @@ static NTSTATUS nttrans_notify_change_send(struct nttrans_op *op) ssize_t len; SIVAL(p, 4, info->nttrans.out.changes[i].action); - len = push_string(lp_iconv_convenience(global_loadparm), p + 12, info->nttrans.out.changes[i].name.s, + len = push_string(p + 12, info->nttrans.out.changes[i].name.s, op->trans->out.params.length - (p+12 - op->trans->out.params.data), STR_UNICODE); SIVAL(p, 8, len); diff --git a/source4/smb_server/smb/request.c b/source4/smb_server/smb/request.c index 241c262857..52eb69fe68 100644 --- a/source4/smb_server/smb/request.c +++ b/source4/smb_server/smb/request.c @@ -428,7 +428,7 @@ size_t req_push_str(struct smbsrv_request *req, uint8_t *dest, const char *str, dest = req->out.buffer + PTR_DIFF(dest, buf0); } - len = push_string(lp_iconv_convenience(req->smb_conn->lp_ctx), dest, str, len, flags); + len = push_string(dest, str, len, flags); grow_size = len + PTR_DIFF(dest, req->out.data); diff --git a/source4/smb_server/smb2/fileio.c b/source4/smb_server/smb2/fileio.c index 4f4402ba33..221fafadfd 100644 --- a/source4/smb_server/smb2/fileio.c +++ b/source4/smb_server/smb2/fileio.c @@ -458,7 +458,7 @@ static void smb2srv_notify_send(struct ntvfs_request *ntvfs) ssize_t len; SIVAL(p, 4, io->smb2.out.changes[i].action); - len = push_string(lp_iconv_convenience(ntvfs->ctx->lp_ctx), p + 12, io->smb2.out.changes[i].name.s, + len = push_string(p + 12, io->smb2.out.changes[i].name.s, blob.length - (p+12 - blob.data), STR_UNICODE); SIVAL(p, 8, len); diff --git a/source4/static_deps.mk b/source4/static_deps.mk index 2768ea8ab5..e366abf681 100644 --- a/source4/static_deps.mk +++ b/source4/static_deps.mk @@ -2,15 +2,13 @@ # perhaps by some perl scripts run from config.status ? # $(gen_ndrsrcdir)/misc.h: idl -$(ndrsrcdir)/libndr.h: $(ndrsrcdir)/libndr_proto.h $(gen_ndrsrcdir)/misc.h +$(ndrsrcdir)/libndr.h: $(gen_ndrsrcdir)/misc.h $(dcerpcsrcdir)/dcerpc.h: $(dcerpcsrcdir)/dcerpc_proto.h $(authsrcdir)/credentials/credentials.h: $(authsrcdir)/credentials/credentials_proto.h $(libclisrcdir)/nbt/libnbt.h: $(libclisrcdir)/nbt/nbt_proto.h -$(libcharsetsrcdir)/charset.h: $(libcharsetsrcdir)/charset_proto.h include/includes.h: \ include/config.h \ - $(libcharsetsrcdir)/charset.h \ $(gen_ndrsrcdir)/misc.h proto:: diff --git a/source4/torture/basic/scanner.c b/source4/torture/basic/scanner.c index 5212f1edee..7f88662baa 100644 --- a/source4/torture/basic/scanner.c +++ b/source4/torture/basic/scanner.c @@ -163,7 +163,7 @@ static bool trans2_op_exists(struct smbcli_state *cli, int op) /**************************************************************************** check for existance of a trans2 call ****************************************************************************/ -static bool scan_trans2(struct smb_iconv_convenience *iconv_convenience, +static bool scan_trans2( struct smbcli_state *cli, int op, int level, int fnum, int dnum, int qfnum, const char *fname) { @@ -233,7 +233,7 @@ static bool scan_trans2(struct smb_iconv_convenience *iconv_convenience, SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(iconv_convenience, + param_len += push_string( ¶m[6], fname, PARAM_SIZE-7, STR_TERMINATE|STR_UNICODE); @@ -249,7 +249,7 @@ static bool scan_trans2(struct smb_iconv_convenience *iconv_convenience, SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(iconv_convenience, + param_len += push_string( ¶m[6], "\\newfile.dat", PARAM_SIZE-7, STR_TERMINATE|STR_UNICODE); @@ -266,7 +266,7 @@ static bool scan_trans2(struct smb_iconv_convenience *iconv_convenience, smbcli_mkdir(cli->tree, "\\testdir"); param_len = 2; SSVAL(param, 0, level); - param_len += push_string(iconv_convenience, + param_len += push_string( ¶m[2], "\\testdir", PARAM_SIZE-3, STR_TERMINATE|STR_UNICODE); @@ -321,15 +321,15 @@ bool torture_trans2_scan(struct torture_context *torture, } for (level = 0; level <= 50; level++) { - scan_trans2(lp_iconv_convenience(torture->lp_ctx), cli, op, level, fnum, dnum, qfnum, fname); + scan_trans2(cli, op, level, fnum, dnum, qfnum, fname); } for (level = 0x100; level <= 0x130; level++) { - scan_trans2(lp_iconv_convenience(torture->lp_ctx), cli, op, level, fnum, dnum, qfnum, fname); + scan_trans2(cli, op, level, fnum, dnum, qfnum, fname); } for (level = 1000; level < 1050; level++) { - scan_trans2(lp_iconv_convenience(torture->lp_ctx), cli, op, level, fnum, dnum, qfnum, fname); + scan_trans2(cli, op, level, fnum, dnum, qfnum, fname); } } @@ -494,7 +494,7 @@ static bool scan_nttrans(struct smb_iconv_convenience *iconv_convenience, SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(iconv_convenience, + param_len += push_string( ¶m[6], fname, PARAM_SIZE, STR_TERMINATE | STR_UNICODE); @@ -510,7 +510,7 @@ static bool scan_nttrans(struct smb_iconv_convenience *iconv_convenience, SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(iconv_convenience, + param_len += push_string( ¶m[6], "\\newfile.dat", PARAM_SIZE, STR_TERMINATE | STR_UNICODE); @@ -527,8 +527,7 @@ static bool scan_nttrans(struct smb_iconv_convenience *iconv_convenience, smbcli_mkdir(cli->tree, "\\testdir"); param_len = 2; SSVAL(param, 0, level); - param_len += push_string(iconv_convenience, - ¶m[2], "\\testdir", PARAM_SIZE, + param_len += push_string(¶m[2], "\\testdir", PARAM_SIZE, STR_TERMINATE | STR_UNICODE); status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk index 9ea212dfa5..def391ba4e 100644 --- a/source4/torture/local/config.mk +++ b/source4/torture/local/config.mk @@ -19,7 +19,7 @@ PRIVATE_DEPENDENCIES = \ ################################# TORTURE_LOCAL_OBJ_FILES = \ - $(torturesrcdir)/../lib/charset/tests/iconv.o \ + $(torturesrcdir)/../../lib/util/charset/tests/iconv.o \ $(torturesrcdir)/../../lib/talloc/testsuite.o \ $(torturesrcdir)/../../lib/replace/test/getifaddrs.o \ $(torturesrcdir)/../../lib/replace/test/os2_delete.o \ @@ -39,7 +39,7 @@ TORTURE_LOCAL_OBJ_FILES = \ $(torturesrcdir)/../../lib/util/tests/file.o \ $(torturesrcdir)/../../lib/util/tests/genrand.o \ $(torturesrcdir)/../../lib/compression/testsuite.o \ - $(torturesrcdir)/../lib/charset/tests/charset.o \ + $(torturesrcdir)/../../lib/util/charset/tests/charset.o \ $(torturesrcdir)/../libcli/security/tests/sddl.o \ $(torturesrcdir)/../lib/tdr/testsuite.o \ $(torturesrcdir)/../lib/events/testsuite.o \ diff --git a/source4/torture/rap/rap.c b/source4/torture/rap/rap.c index e93bd52b9a..be231107dd 100644 --- a/source4/torture/rap/rap.c +++ b/source4/torture/rap/rap.c @@ -184,7 +184,7 @@ static NTSTATUS rap_pull_string(TALLOC_CTX *mem_ctx, struct ndr_pull *ndr, return NT_STATUS_INVALID_PARAMETER; *dest = talloc_zero_array(mem_ctx, char, len+1); - pull_string(ndr->iconv_convenience, *dest, p, len+1, len, STR_ASCII); + pull_string(*dest, p, len+1, len, STR_ASCII); return NT_STATUS_OK; } diff --git a/source4/torture/rpc/netlogon.c b/source4/torture/rpc/netlogon.c index f4ae5b35eb..c2e12ec01d 100644 --- a/source4/torture/rpc/netlogon.c +++ b/source4/torture/rpc/netlogon.c @@ -592,7 +592,7 @@ bool test_netlogon_ops(struct dcerpc_pipe *p, struct torture_context *tctx, chal = data_blob_const(ninfo.challenge, sizeof(ninfo.challenge)); - names_blob = NTLMv2_generate_names_blob(tctx, lp_iconv_convenience(tctx->lp_ctx), cli_credentials_get_workstation(credentials), + names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials), cli_credentials_get_domain(credentials)); status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx, diff --git a/source4/torture/rpc/samba3rpc.c b/source4/torture/rpc/samba3rpc.c index 260c1cc149..25ff7d0ea9 100644 --- a/source4/torture/rpc/samba3rpc.c +++ b/source4/torture/rpc/samba3rpc.c @@ -1041,7 +1041,7 @@ static bool schan(struct smbcli_state *cli, generate_random_buffer(chal.data, chal.length); names_blob = NTLMv2_generate_names_blob( - mem_ctx, lp_iconv_convenience(lp_ctx), + mem_ctx, cli_credentials_get_workstation(user_creds), cli_credentials_get_domain(user_creds)); status = cli_credentials_get_ntlm_response( @@ -2420,8 +2420,7 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree, memcpy(servername, r.out.info.info0.name, 16); servername[16] = '\0'; - if (pull_ascii_talloc(mem_ctx, iconv_convenience, - name, servername) < 0) { + if (pull_ascii_talloc(mem_ctx, name, servername) < 0) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/torture/rpc/samlogon.c b/source4/torture/rpc/samlogon.c index b7028e6609..01368cccad 100644 --- a/source4/torture/rpc/samlogon.c +++ b/source4/torture/rpc/samlogon.c @@ -595,7 +595,7 @@ static bool test_lmv2_ntlmv2_broken(struct samlogon_state *samlogon_state, DATA_BLOB lmv2_response = data_blob(NULL, 0); DATA_BLOB lmv2_session_key = data_blob(NULL, 0); DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0); - DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, TEST_MACHINE_NAME, samlogon_state->workgroup); + DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, TEST_MACHINE_NAME, samlogon_state->workgroup); uint8_t lm_session_key[8]; uint8_t user_session_key[16]; @@ -743,7 +743,7 @@ static bool test_lmv2_ntlm_broken(struct samlogon_state *samlogon_state, DATA_BLOB lmv2_response = data_blob(NULL, 0); DATA_BLOB lmv2_session_key = data_blob(NULL, 0); DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0); - DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, samlogon_state->netbios_name, samlogon_state->workgroup); + DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->netbios_name, samlogon_state->workgroup); DATA_BLOB ntlm_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24); DATA_BLOB ntlm_session_key = data_blob_talloc(samlogon_state->mem_ctx, NULL, 16); @@ -1162,7 +1162,6 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea ZERO_STRUCT(user_session_key); if ((push_ucs2_talloc(samlogon_state->mem_ctx, - samlogon_state->iconv_convenience, &unicodepw, samlogon_state->password)) == -1) { DEBUG(0, ("push_ucs2_allocate failed!\n")); exit(1); diff --git a/source4/torture/rpc/schannel.c b/source4/torture/rpc/schannel.c index fae0093e4d..15d40a2e17 100644 --- a/source4/torture/rpc/schannel.c +++ b/source4/torture/rpc/schannel.c @@ -68,7 +68,7 @@ bool test_netlogon_ex_ops(struct dcerpc_pipe *p, struct torture_context *tctx, chal = data_blob_const(ninfo.challenge, sizeof(ninfo.challenge)); - names_blob = NTLMv2_generate_names_blob(tctx, lp_iconv_convenience(tctx->lp_ctx), cli_credentials_get_workstation(credentials), + names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials), cli_credentials_get_domain(credentials)); status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx, @@ -573,7 +573,7 @@ static bool torture_schannel_bench_start(struct torture_schannel_bench_conn *con chal = data_blob_const(conn->ninfo.challenge, sizeof(conn->ninfo.challenge)); - names_blob = NTLMv2_generate_names_blob(conn->tmp, lp_iconv_convenience(s->tctx->lp_ctx), + names_blob = NTLMv2_generate_names_blob(conn->tmp, cli_credentials_get_workstation(conn->wks_creds), cli_credentials_get_domain(conn->wks_creds)); diff --git a/source4/torture/rpc/wkssvc.c b/source4/torture/rpc/wkssvc.c index 015f20f6e2..0f49562d8b 100644 --- a/source4/torture/rpc/wkssvc.c +++ b/source4/torture/rpc/wkssvc.c @@ -966,8 +966,7 @@ static bool test_NetrMessageBufferSend(struct torture_context *tctx, size_t size; uint8_t *msg; - size = push_ucs2_talloc(tctx, lp_iconv_convenience(tctx->lp_ctx), - (void **)&msg, message); + size = push_ucs2_talloc(tctx, (void **)&msg, message); r.in.server_name = dcerpc_server_name(p); r.in.message_name = dcerpc_server_name(p); diff --git a/source4/winbind/wb_pam_auth.c b/source4/winbind/wb_pam_auth.c index ee54bcd58f..5913f8d1bf 100644 --- a/source4/winbind/wb_pam_auth.c +++ b/source4/winbind/wb_pam_auth.c @@ -245,7 +245,6 @@ struct composite_context *wb_cmd_pam_auth_send(TALLOC_CTX *mem_ctx, names_blob = NTLMv2_generate_names_blob( mem_ctx, - lp_iconv_convenience(service->task->lp_ctx), cli_credentials_get_workstation(credentials), cli_credentials_get_domain(credentials)); |