summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-03-01 22:24:34 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-03-01 22:24:34 +0100
commit7ab8f373c84c328b197f923287163e83371e7ccb (patch)
tree8a009647735ccc1cf181d98b01c1084f45e0d711
parent94069bd2747a8397308c0b0b384f7bb4edd8f68b (diff)
downloadsamba-7ab8f373c84c328b197f923287163e83371e7ccb.tar.gz
samba-7ab8f373c84c328b197f923287163e83371e7ccb.tar.bz2
samba-7ab8f373c84c328b197f923287163e83371e7ccb.zip
Use common header file for character set handling in Samba 3 and Samba 4.
-rw-r--r--lib/util/charset/charset.h111
-rw-r--r--lib/util/charset/iconv.c1
-rw-r--r--lib/util/charset/util_unistr.c48
-rw-r--r--source3/Makefile.in4
-rw-r--r--source3/include/charset.h128
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/include/smb.h2
-rw-r--r--source3/lib/charcnv.c2
-rw-r--r--source3/lib/iconv.c4
-rw-r--r--source4/auth/ntlmssp/ntlmssp_parse.c36
-rw-r--r--source4/kdc/kpasswdd.c5
-rw-r--r--source4/libcli/auth/smbencrypt.c32
-rw-r--r--source4/torture/rpc/samba3rpc.c2
-rw-r--r--source4/torture/rpc/samlogon.c6
-rw-r--r--source4/torture/rpc/wkssvc.c2
15 files changed, 172 insertions, 212 deletions
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h
index 1f24f8985f..655bae7bcd 100644
--- a/lib/util/charset/charset.h
+++ b/lib/util/charset/charset.h
@@ -28,9 +28,16 @@
#include <talloc.h>
/* this defines the charset types used in samba */
-typedef enum {CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE, CH_UTF16MUNGED} charset_t;
+typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX, CH_DISPLAY, CH_DOS, CH_UTF8, CH_UTF16BE, CH_UTF16MUNGED} charset_t;
-#define NUM_CHARSETS 6
+#define NUM_CHARSETS 7
+
+/*
+ * SMB UCS2 (16-bit unicode) internal type.
+ * smb_ucs2_t is *always* in little endian format.
+ */
+
+typedef uint16_t smb_ucs2_t;
/*
* for each charset we have a function that pulls from that charset to
@@ -51,6 +58,17 @@ typedef uint32_t codepoint_t;
#define INVALID_CODEPOINT ((codepoint_t)-1)
+/*
+ * This is auxiliary struct used by source/script/gen-8-bit-gap.sh script
+ * during generation of an encoding table for charset module
+ * */
+
+struct charset_gap_table {
+ uint16_t start;
+ uint16_t end;
+ int32_t idx;
+};
+
/* generic iconv conversion structure */
typedef struct smb_iconv_s {
@@ -106,12 +124,12 @@ 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);
+bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
+bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, size_t *converted_size);
+bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
+bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
+bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, size_t *converted_size);
+bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags);
ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
@@ -171,4 +189,81 @@ smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode,
void load_case_tables(void);
bool charset_register_backend(const void *_funcs);
+/*
+ * Define stub for charset module which implements 8-bit encoding with gaps.
+ * Encoding tables for such module should be produced from glibc's CHARMAPs
+ * using script source/script/gen-8bit-gap.sh
+ * CHARSETNAME is CAPITALIZED charset name
+ *
+ * */
+#define SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME) \
+static size_t CHARSETNAME ## _push(void *cd, const char **inbuf, size_t *inbytesleft, \
+ char **outbuf, size_t *outbytesleft) \
+{ \
+ while (*inbytesleft >= 2 && *outbytesleft >= 1) { \
+ int i; \
+ int done = 0; \
+ \
+ uint16 ch = SVAL(*inbuf,0); \
+ \
+ for (i=0; from_idx[i].start != 0xffff; i++) { \
+ if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) { \
+ ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; \
+ (*inbytesleft) -= 2; \
+ (*outbytesleft) -= 1; \
+ (*inbuf) += 2; \
+ (*outbuf) += 1; \
+ done = 1; \
+ break; \
+ } \
+ } \
+ if (!done) { \
+ errno = EINVAL; \
+ return -1; \
+ } \
+ \
+ } \
+ \
+ if (*inbytesleft == 1) { \
+ errno = EINVAL; \
+ return -1; \
+ } \
+ \
+ if (*inbytesleft > 1) { \
+ errno = E2BIG; \
+ return -1; \
+ } \
+ \
+ return 0; \
+} \
+ \
+static size_t CHARSETNAME ## _pull(void *cd, const char **inbuf, size_t *inbytesleft, \
+ char **outbuf, size_t *outbytesleft) \
+{ \
+ while (*inbytesleft >= 1 && *outbytesleft >= 2) { \
+ *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]]; \
+ (*inbytesleft) -= 1; \
+ (*outbytesleft) -= 2; \
+ (*inbuf) += 1; \
+ (*outbuf) += 2; \
+ } \
+ \
+ if (*inbytesleft > 0) { \
+ errno = E2BIG; \
+ return -1; \
+ } \
+ \
+ return 0; \
+} \
+ \
+struct charset_functions CHARSETNAME ## _functions = \
+ {#CHARSETNAME, CHARSETNAME ## _pull, CHARSETNAME ## _push}; \
+ \
+NTSTATUS charset_ ## CHARSETNAME ## _init(void); \
+NTSTATUS charset_ ## CHARSETNAME ## _init(void) \
+{ \
+ return smb_register_charset(& CHARSETNAME ## _functions); \
+} \
+
+
#endif /* __CHARSET_H__ */
diff --git a/lib/util/charset/iconv.c b/lib/util/charset/iconv.c
index b6842a49aa..98284ce9bd 100644
--- a/lib/util/charset/iconv.c
+++ b/lib/util/charset/iconv.c
@@ -22,6 +22,7 @@
#include "../lib/util/dlinklist.h"
#include "system/iconv.h"
#include "system/filesys.h"
+#undef strcasecmp
/**
diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c
index 13178ea5cc..ec88e784d0 100644
--- a/lib/util/charset/util_unistr.c
+++ b/lib/util/charset/util_unistr.c
@@ -668,13 +668,11 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag
* @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)
+_PUBLIC_ bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
{
- size_t src_len = strlen(src)+1, ret;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, &ret, false))
- return -1;
- return (ssize_t)ret;
+ return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, converted_size, false);
}
@@ -781,13 +779,11 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags
* @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)
+_PUBLIC_ bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, size_t *converted_size)
{
- size_t src_len = strlen(src)+1, ret;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest, &ret, false))
- return -1;
- return ret;
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, (void **)dest, converted_size, false);
}
@@ -799,13 +795,11 @@ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src)
* @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)
+_PUBLIC_ bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
{
- size_t src_len = strlen(src)+1, ret;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, &ret, false))
- return -1;
- return ret;
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, converted_size, false);
}
/**
@@ -856,13 +850,11 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src
* @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)
+_PUBLIC_ bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
{
- size_t src_len = strlen(src)+1, ret;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, &ret, false))
- return -1;
- return ret;
+ return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, converted_size, false);
}
/**
@@ -873,13 +865,11 @@ _PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src
* @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)
+_PUBLIC_ bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, size_t *converted_size)
{
- size_t src_len = utf16_len(src), ret;
+ size_t src_len = utf16_len(src);
*dest = NULL;
- if (!convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, &ret, false))
- return -1;
- return ret;
+ return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, converted_size, false);
}
/**
@@ -890,13 +880,11 @@ _PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src)
* @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)
+_PUBLIC_ bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
{
- size_t src_len = strlen(src)+1, ret;
+ size_t src_len = strlen(src)+1;
*dest = NULL;
- if (!convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, &ret, false))
- return -1;
- return ret;
+ return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, converted_size, false);
}
/**
diff --git a/source3/Makefile.in b/source3/Makefile.in
index d957d70edb..8723b4f63f 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -366,8 +366,8 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
lib/substitute.o lib/dbwrap_util.o \
lib/ms_fnmatch.o lib/select.o lib/errmap_unix.o \
lib/tallocmsg.o lib/dmallocmsg.o libsmb/smb_signing.o \
- lib/iconv.o lib/pam_errors.o intl/lang_tdb.o lib/conn_tdb.o \
- lib/adt_tree.o lib/gencache.o \
+ ../lib/util/charset/iconv.o lib/pam_errors.o intl/lang_tdb.o \
+ lib/conn_tdb.o lib/adt_tree.o lib/gencache.o \
lib/module.o lib/events.o @LIBTEVENT_OBJ0@ \
lib/ldap_escape.o @CHARSET_STATIC@ \
lib/secdesc.o lib/util_seaccess.o lib/secace.o lib/secacl.o \
diff --git a/source3/include/charset.h b/source3/include/charset.h
deleted file mode 100644
index 1c2a5fb5f0..0000000000
--- a/source3/include/charset.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- charset defines
- Copyright (C) Andrew Tridgell 2001
- Copyright (C) Jelmer Vernooij 2002
-
- 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/>.
-*/
-
-struct smb_iconv_convenience;
-
-/* this defines the charset types used in samba */
-typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t;
-
-#define NUM_CHARSETS 6
-
-/*
- * for each charset we have a function that pushes from that charset to a ucs2
- * buffer, and a function that pulls from ucs2 buffer to that charset.
- * */
-
-struct charset_functions {
- const char *name;
- size_t (*pull)(void *, const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft);
- size_t (*push)(void *, const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft);
- struct charset_functions *prev, *next;
-};
-
-/*
- * This is auxiliary struct used by source/script/gen-8-bit-gap.sh script
- * during generation of an encoding table for charset module
- * */
-
-struct charset_gap_table {
- uint16 start;
- uint16 end;
- int32 idx;
-};
-
-/*
- * Define stub for charset module which implements 8-bit encoding with gaps.
- * Encoding tables for such module should be produced from glibc's CHARMAPs
- * using script source/script/gen-8bit-gap.sh
- * CHARSETNAME is CAPITALIZED charset name
- *
- * */
-#define SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME) \
-static size_t CHARSETNAME ## _push(void *cd, const char **inbuf, size_t *inbytesleft, \
- char **outbuf, size_t *outbytesleft) \
-{ \
- while (*inbytesleft >= 2 && *outbytesleft >= 1) { \
- int i; \
- int done = 0; \
- \
- uint16 ch = SVAL(*inbuf,0); \
- \
- for (i=0; from_idx[i].start != 0xffff; i++) { \
- if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) { \
- ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; \
- (*inbytesleft) -= 2; \
- (*outbytesleft) -= 1; \
- (*inbuf) += 2; \
- (*outbuf) += 1; \
- done = 1; \
- break; \
- } \
- } \
- if (!done) { \
- errno = EINVAL; \
- return -1; \
- } \
- \
- } \
- \
- if (*inbytesleft == 1) { \
- errno = EINVAL; \
- return -1; \
- } \
- \
- if (*inbytesleft > 1) { \
- errno = E2BIG; \
- return -1; \
- } \
- \
- return 0; \
-} \
- \
-static size_t CHARSETNAME ## _pull(void *cd, const char **inbuf, size_t *inbytesleft, \
- char **outbuf, size_t *outbytesleft) \
-{ \
- while (*inbytesleft >= 1 && *outbytesleft >= 2) { \
- *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]]; \
- (*inbytesleft) -= 1; \
- (*outbytesleft) -= 2; \
- (*inbuf) += 1; \
- (*outbuf) += 2; \
- } \
- \
- if (*inbytesleft > 0) { \
- errno = E2BIG; \
- return -1; \
- } \
- \
- return 0; \
-} \
- \
-struct charset_functions CHARSETNAME ## _functions = \
- {#CHARSETNAME, CHARSETNAME ## _pull, CHARSETNAME ## _push}; \
- \
-NTSTATUS charset_ ## CHARSETNAME ## _init(void); \
-NTSTATUS charset_ ## CHARSETNAME ## _init(void) \
-{ \
- return smb_register_charset(& CHARSETNAME ## _functions); \
-} \
-
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 626e67f653..0e6446be84 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -336,6 +336,7 @@ int bitmap_find(struct bitmap *bm, unsigned ofs);
/* The following definitions come from lib/charcnv.c */
+NTSTATUS smb_register_charset(struct charset_functions *funcs);
char lp_failed_convert_char(void);
void lazy_initialize_conv(void);
void gfree_charcnv(void);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 189e370496..59c3c32346 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -149,8 +149,6 @@ typedef union unid_t {
* smb_ucs2_t is *always* in little endian format.
*/
-typedef uint16 smb_ucs2_t;
-
#ifdef WORDS_BIGENDIAN
#define UCS2_SHIFT 8
#else
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index c3b345142f..81cb9a5094 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -763,7 +763,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
* converted.
*/
bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
- void const *src, size_t srclen, void *dst,
+ void const *src, size_t srclen, void **dst,
size_t *converted_size, bool allow_bad_conv)
{
void **dest = (void **)dst;
diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c
index 3ceb637b8e..fa213a37c0 100644
--- a/source3/lib/iconv.c
+++ b/source3/lib/iconv.c
@@ -207,12 +207,12 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
from = charsets;
to = charsets;
- ret = SMB_MALLOC_P(struct _smb_iconv_t);
+ ret = SMB_MALLOC_P(smb_iconv_t);
if (!ret) {
errno = ENOMEM;
return (smb_iconv_t)-1;
}
- memset(ret, 0, sizeof(struct _smb_iconv_t));
+ memset(ret, 0, sizeof(smb_iconv_t));
ret->from_name = SMB_STRDUP(fromcode);
ret->to_name = SMB_STRDUP(tocode);
diff --git a/source4/auth/ntlmssp/ntlmssp_parse.c b/source4/auth/ntlmssp/ntlmssp_parse.c
index d606b8d563..969845d6c5 100644
--- a/source4/auth/ntlmssp/ntlmssp_parse.c
+++ b/source4/auth/ntlmssp/ntlmssp_parse.c
@@ -44,14 +44,15 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
DATA_BLOB *blob,
const char *format, ...)
{
- int i;
- ssize_t n;
+ int i, j;
+ bool ret;
va_list ap;
char *s;
uint8_t *b;
int head_size=0, data_size=0;
int head_ofs, data_ofs;
int *intargs;
+ size_t n;
DATA_BLOB *pointers;
@@ -65,8 +66,9 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
case 'U':
s = va_arg(ap, char *);
head_size += 8;
- n = push_ucs2_talloc(pointers, (void **)&pointers[i].data, s);
- if (n == -1) {
+ ret = push_ucs2_talloc(pointers, (smb_ucs2_t **)&pointers[i].data,
+ s, &n);
+ if (!ret) {
return false;
}
pointers[i].length = n;
@@ -76,8 +78,9 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
case 'A':
s = va_arg(ap, char *);
head_size += 8;
- n = push_ascii_talloc(pointers, (char **)&pointers[i].data, s);
- if (n == -1) {
+ ret = push_ascii_talloc(pointers, (char **)&pointers[i].data, s,
+ &n);
+ if (!ret) {
return false;
}
pointers[i].length = n;
@@ -85,11 +88,12 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
data_size += pointers[i].length;
break;
case 'a':
- n = va_arg(ap, int);
- intargs[i] = n;
+ j = va_arg(ap, int);
+ intargs[i] = j;
s = va_arg(ap, char *);
- n = push_ucs2_talloc(pointers, (void **)&pointers[i].data, s);
- if (n == -1) {
+ ret = push_ucs2_talloc(pointers, (smb_ucs2_t **)&pointers[i].data,
+ s, &n);
+ if (!ret) {
return false;
}
pointers[i].length = n;
@@ -110,8 +114,8 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
head_size += pointers[i].length;
break;
case 'd':
- n = va_arg(ap, int);
- intargs[i] = n;
+ j = va_arg(ap, int);
+ intargs[i] = j;
head_size += 4;
break;
case 'C':
@@ -145,8 +149,8 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
data_ofs += n;
break;
case 'a':
- n = intargs[i];
- SSVAL(blob->data, data_ofs, n); data_ofs += 2;
+ j = intargs[i];
+ SSVAL(blob->data, data_ofs, j); data_ofs += 2;
n = pointers[i].length;
SSVAL(blob->data, data_ofs, n); data_ofs += 2;
@@ -156,8 +160,8 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx,
data_ofs += n;
break;
case 'd':
- n = intargs[i];
- SIVAL(blob->data, head_ofs, n);
+ j = intargs[i];
+ SIVAL(blob->data, head_ofs, j);
head_ofs += 4;
break;
case 'b':
diff --git a/source4/kdc/kpasswdd.c b/source4/kdc/kpasswdd.c
index 67404af2ab..8f2cb68129 100644
--- a/source4/kdc/kpasswdd.c
+++ b/source4/kdc/kpasswdd.c
@@ -61,12 +61,11 @@ static bool kpasswdd_make_error_reply(struct kdc_server *kdc,
DATA_BLOB *error_blob)
{
char *error_string_utf8;
- ssize_t len;
+ size_t len;
DEBUG(result_code ? 3 : 10, ("kpasswdd: %s\n", error_string));
- len = push_utf8_talloc(mem_ctx, &error_string_utf8, error_string);
- if (len == -1) {
+ if (!push_utf8_talloc(mem_ctx, &error_string_utf8, error_string, &len)) {
return false;
}
diff --git a/source4/libcli/auth/smbencrypt.c b/source4/libcli/auth/smbencrypt.c
index bbb363e0dd..c6118c6568 100644
--- a/source4/libcli/auth/smbencrypt.c
+++ b/source4/libcli/auth/smbencrypt.c
@@ -63,11 +63,12 @@ bool SMBencrypt(const char *passwd, const uint8_t *c8, uint8_t p24[24])
bool E_md4hash(const char *passwd, uint8_t p16[16])
{
- int len;
- void *wpwd;
+ size_t len;
+ smb_ucs2_t *wpwd;
+ bool ret;
- len = push_ucs2_talloc(NULL, &wpwd, passwd);
- if (len < 2) {
+ ret = push_ucs2_talloc(NULL, &wpwd, passwd, &len);
+ if (!ret || len < 2) {
/* We don't want to return fixed data, as most callers
* don't check */
mdfour(p16, (const uint8_t *)passwd, strlen(passwd));
@@ -75,7 +76,7 @@ bool E_md4hash(const char *passwd, uint8_t p16[16])
}
len -= 2;
- mdfour(p16, wpwd, len);
+ mdfour(p16, (const uint8_t *)wpwd, len);
talloc_free(wpwd);
return true;
@@ -116,10 +117,11 @@ bool ntv2_owf_gen(const uint8_t owf[16],
bool upper_case_domain, /* Transform the domain into UPPER case */
uint8_t kr_buf[16])
{
- void *user;
- void *domain;
+ smb_ucs2_t *user;
+ smb_ucs2_t *domain;
size_t user_byte_len;
size_t domain_byte_len;
+ bool ret;
HMACMD5Context ctx;
TALLOC_CTX *mem_ctx = talloc_init("ntv2_owf_gen for %s\\%s", domain_in, user_in);
@@ -150,15 +152,15 @@ bool ntv2_owf_gen(const uint8_t owf[16],
}
}
- user_byte_len = push_ucs2_talloc(mem_ctx, &user, user_in);
- if (user_byte_len == (ssize_t)-1) {
+ ret = push_ucs2_talloc(mem_ctx, &user, user_in, &user_byte_len );
+ if (!ret) {
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, &domain, domain_in);
- if (domain_byte_len == (ssize_t)-1) {
+ ret = push_ucs2_talloc(mem_ctx, &domain, domain_in, &domain_byte_len);
+ if (!ret) {
DEBUG(0, ("push_ucs2_talloc() for domain returned -1 (probably talloc() failure)\n"));
talloc_free(mem_ctx);
return false;
@@ -172,14 +174,14 @@ bool ntv2_owf_gen(const uint8_t owf[16],
domain_byte_len = domain_byte_len - 2;
hmac_md5_init_limK_to_64(owf, 16, &ctx);
- hmac_md5_update(user, user_byte_len, &ctx);
- hmac_md5_update(domain, domain_byte_len, &ctx);
+ hmac_md5_update((const void *)user, user_byte_len, &ctx);
+ hmac_md5_update((const void *)domain, domain_byte_len, &ctx);
hmac_md5_final(kr_buf, &ctx);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("ntv2_owf_gen: user, domain, owfkey, kr\n"));
- dump_data(100, user, user_byte_len);
- dump_data(100, domain, domain_byte_len);
+ dump_data(100, (const void *)user, user_byte_len);
+ dump_data(100, (const void *)domain, domain_byte_len);
dump_data(100, owf, 16);
dump_data(100, kr_buf, 16);
#endif
diff --git a/source4/torture/rpc/samba3rpc.c b/source4/torture/rpc/samba3rpc.c
index c9e65cf493..7cacba7418 100644
--- a/source4/torture/rpc/samba3rpc.c
+++ b/source4/torture/rpc/samba3rpc.c
@@ -2537,7 +2537,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, name, servername) < 0) {
+ if (!pull_ascii_talloc(mem_ctx, name, servername, NULL)) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/torture/rpc/samlogon.c b/source4/torture/rpc/samlogon.c
index 0f0b8dc84d..ce9bf5ea6e 100644
--- a/source4/torture/rpc/samlogon.c
+++ b/source4/torture/rpc/samlogon.c
@@ -1150,7 +1150,7 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea
DATA_BLOB lm_response = data_blob(NULL, 0);
char *password;
char *dospw;
- void *unicodepw;
+ smb_ucs2_t *unicodepw;
uint8_t user_session_key[16];
uint8_t lm_key[16];
@@ -1161,8 +1161,8 @@ 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,
- &unicodepw, samlogon_state->password)) == -1) {
+ if (!push_ucs2_talloc(samlogon_state->mem_ctx,
+ &unicodepw, samlogon_state->password, NULL)) {
DEBUG(0, ("push_ucs2_allocate failed!\n"));
exit(1);
}
diff --git a/source4/torture/rpc/wkssvc.c b/source4/torture/rpc/wkssvc.c
index 0f49562d8b..3c34229dff 100644
--- a/source4/torture/rpc/wkssvc.c
+++ b/source4/torture/rpc/wkssvc.c
@@ -966,7 +966,7 @@ static bool test_NetrMessageBufferSend(struct torture_context *tctx,
size_t size;
uint8_t *msg;
- size = push_ucs2_talloc(tctx, (void **)&msg, message);
+ push_ucs2_talloc(tctx, (void **)&msg, message, &size);
r.in.server_name = dcerpc_server_name(p);
r.in.message_name = dcerpc_server_name(p);