diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-03-01 19:55:46 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-03-01 19:55:46 +0100 |
commit | 94069bd2747a8397308c0b0b384f7bb4edd8f68b (patch) | |
tree | ace3c4fa9d0cb134d4e904354bd33b395c1e1289 | |
parent | bbe2d30f66ebd8537203870b1225179f03d42744 (diff) | |
download | samba-94069bd2747a8397308c0b0b384f7bb4edd8f68b.tar.gz samba-94069bd2747a8397308c0b0b384f7bb4edd8f68b.tar.bz2 samba-94069bd2747a8397308c0b0b384f7bb4edd8f68b.zip |
s4: Use same function signature for convert_* as s3.
26 files changed, 202 insertions, 195 deletions
diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c index 18be2bcac2..258730ec82 100644 --- a/lib/util/charset/charcnv.c +++ b/lib/util/charset/charcnv.c @@ -186,7 +186,7 @@ convert: destlen = 2 + (destlen*3); ob = talloc_realloc(ctx, outbuf, char, destlen); if (!ob) { - DEBUG(0, ("convert_string_talloc: realloc failed!\n")); + DEBUG(0, ("iconv_talloc: realloc failed!\n")); talloc_free(outbuf); return (size_t)-1; } else { @@ -237,10 +237,11 @@ convert: * @param destlen maximal length allowed for string * @returns the number of bytes occupied in the destination **/ -_PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, +_PUBLIC_ bool convert_string_convenience(struct smb_iconv_convenience *ic, charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen, bool allow_badcharcnv) + void *dest, size_t destlen, size_t *converted_size, + bool allow_badcharcnv) { size_t i_len, o_len; size_t retval; @@ -249,7 +250,8 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, smb_iconv_t descriptor; if (allow_badcharcnv) { - return -1; + /* Not implemented yet */ + return false; } if (srclen == (size_t)-1) @@ -261,7 +263,8 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, /* conversion not supported, use as is */ size_t len = MIN(srclen,destlen); memcpy(dest,src,len); - return len; + *converted_size = len; + return true; } i_len=srclen; @@ -272,7 +275,7 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; - return -1; + return false; case E2BIG: reason="No more room"; if (from == CH_UNIX) { @@ -285,14 +288,16 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, charset_name(ic, from), charset_name(ic, to), (int)srclen, (int)destlen)); } - return -1; + return false; case EILSEQ: reason="Illegal multibyte sequence"; - return -1; + return false; } /* smb_panic(reason); */ } - return destlen-o_len; + if (converted_size != NULL) + *converted_size = destlen-o_len; + return true; } /** @@ -305,21 +310,23 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, * @returns Size in bytes of the converted string; or -1 in case of error. **/ -_PUBLIC_ ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, +_PUBLIC_ bool convert_string_talloc_convenience(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, charset_t from, charset_t to, void const *src, size_t srclen, - void **dest, bool allow_badcharcnv) + void **dest, size_t *converted_size, + bool allow_badcharcnv) { smb_iconv_t descriptor; + ssize_t ret; if (allow_badcharcnv) - return (size_t)-1; + return false; /* Not implemented yet */ *dest = NULL; if (src == NULL || srclen == (size_t)-1 || srclen == 0) - return (size_t)-1; + return false; descriptor = get_conv_handle(ic, from, to); @@ -328,10 +335,15 @@ _PUBLIC_ ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n", charset_name(ic, from), charset_name(ic, to))); - return -1; + return false; } - return iconv_talloc(ctx, descriptor, src, srclen, dest); + ret = iconv_talloc(ctx, descriptor, src, srclen, dest); + if (ret == -1) + return false; + if (converted_size != NULL) + *converted_size = ret; + return true; } /* diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index 3acdde30ad..1f24f8985f 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -115,10 +115,11 @@ 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); -ssize_t convert_string_talloc(TALLOC_CTX *ctx, +bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, - void **dest, bool allow_badcharcnv); + void **dest, size_t *converted_size, + bool allow_badcharcnv); size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, @@ -148,15 +149,16 @@ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, const char *unix_charset, bool native_iconv); -ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, +bool convert_string_convenience(struct smb_iconv_convenience *ic, charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen, bool allow_badcharcnv); -ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, + void *dest, size_t destlen, size_t *converted_size, + bool allow_badcharcnv); +bool convert_string_talloc_convenience(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, charset_t from, charset_t to, void const *src, size_t srclen, - void **dest, bool allow_badcharcnv); + void **dest, size_t *converted_size, bool allow_badcharcnv); /* iconv */ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode); int smb_iconv_close(smb_iconv_t cd); diff --git a/lib/util/charset/tests/iconv.c b/lib/util/charset/tests/iconv.c index fbe7b103ab..091876f63b 100644 --- a/lib/util/charset/tests/iconv.c +++ b/lib/util/charset/tests/iconv.c @@ -404,12 +404,12 @@ static bool test_string2key(struct torture_context *tctx) uint16_t *buf; char *dest = NULL; TALLOC_CTX *mem_ctx = talloc_new(tctx); - ssize_t ret; size_t len = (random()%1000)+1; const uint16_t in1[10] = { 'a', 0xd805, 'b', 0xdcf0, 'c', 0, 'd', 'e', 'f', 'g' }; uint8_t le1[20]; uint8_t *munged1; uint8_t *out1; + size_t ret; int i; const char *correct = "a\357\277\275b\357\277\275c\001defg"; @@ -418,8 +418,7 @@ static bool test_string2key(struct torture_context *tctx) torture_comment(tctx, "converting random buffer\n"); - ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)buf, len*2, (void**)&dest, false); - if (ret == -1) { + if (!convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)buf, len*2, (void**)&dest, &ret, false)) { torture_fail(tctx, "Failed to convert random buffer\n"); } @@ -429,8 +428,7 @@ static bool test_string2key(struct torture_context *tctx) torture_comment(tctx, "converting fixed buffer to UTF16\n"); - ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF16, (void *)le1, 20, (void**)&munged1, false); - if (ret == -1) { + if (!convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF16, (void *)le1, 20, (void**)&munged1, &ret, false)) { torture_fail(tctx, "Failed to convert fixed buffer to UTF16_MUNGED\n"); } @@ -438,8 +436,7 @@ static bool test_string2key(struct torture_context *tctx) torture_comment(tctx, "converting fixed buffer to UTF8\n"); - ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)le1, 20, (void**)&out1, false); - if (ret == -1) { + if (!convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)le1, 20, (void**)&out1, &ret, false)) { torture_fail(tctx, "Failed to convert fixed buffer to UTF8\n"); } diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index 96c987393f..13178ea5cc 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -670,9 +670,11 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag **/ _PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t src_len = strlen(src)+1, ret; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, false); + if (!convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, &ret, false)) + return -1; + return (ssize_t)ret; } @@ -781,9 +783,11 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags **/ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t src_len = strlen(src)+1, ret; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest, false); + if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest, &ret, false)) + return -1; + return ret; } @@ -797,9 +801,11 @@ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) _PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t src_len = strlen(src)+1, ret; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, false); + if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, &ret, false)) + return -1; + return ret; } /** @@ -852,9 +858,11 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src _PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t src_len = strlen(src)+1, ret; *dest = NULL; - return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, false); + if (!convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, &ret, false)) + return -1; + return ret; } /** @@ -867,9 +875,11 @@ _PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src _PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) { - size_t src_len = utf16_len(src); + size_t src_len = utf16_len(src), ret; *dest = NULL; - return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, false); + if (!convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, &ret, false)) + return -1; + return ret; } /** @@ -882,9 +892,11 @@ _PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) _PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t src_len = strlen(src)+1, ret; *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, false); + if (!convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, &ret, false)) + return -1; + return ret; } /** @@ -952,11 +964,16 @@ _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_ **/ _PUBLIC_ size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen, bool allow_badcharcnv) + void *dest, size_t destlen, + bool allow_badcharcnv) { - return convert_string_convenience(get_iconv_convenience(), from, to, + size_t ret; + if (!convert_string_convenience(get_iconv_convenience(), from, to, src, srclen, - dest, destlen, allow_badcharcnv); + dest, destlen, &ret, + allow_badcharcnv)) + return -1; + return ret; } /** @@ -964,18 +981,21 @@ _PUBLIC_ size_t convert_string(charset_t from, charset_t to, * * @param srclen length of source buffer. * @param dest always set at least to NULL + * @param converted_size Size in bytes of the converted string * @note -1 is not accepted for srclen. * - * @returns Size in bytes of the converted string; or -1 in case of error. + * @returns boolean indication whether the conversion succeeded **/ -_PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, +_PUBLIC_ bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, - void **dest, bool allow_badcharcnv) + void **dest, size_t *converted_size, + bool allow_badcharcnv) { return convert_string_talloc_convenience(ctx, get_iconv_convenience(), from, to, src, srclen, dest, + converted_size, allow_badcharcnv); } diff --git a/source3/include/proto.h b/source3/include/proto.h index eeb6f1928d..626e67f653 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -347,7 +347,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, size_t *converted_size, bool allow_bad_conv); 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); size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen); char *strdup_upper(const char *s); diff --git a/source4/auth/ntlm/ntlm_check.c b/source4/auth/ntlm/ntlm_check.c index 5298432e61..0805b1b043 100644 --- a/source4/auth/ntlm/ntlm_check.c +++ b/source4/auth/ntlm/ntlm_check.c @@ -323,7 +323,7 @@ NTSTATUS ntlm_password_check(TALLOC_CTX *mem_ctx, if (lm_response->length && (convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, lm_response->data, lm_response->length, - (void **)&unix_pw, false) != -1)) { + (void **)&unix_pw, NULL, false))) { if (E_deshash(unix_pw, client_lm.hash)) { lm_ok = true; } else { diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index 82f5b6ed1d..19eb3433a9 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -1693,7 +1693,7 @@ NTSTATUS samdb_set_password(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, if (convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(ldb_get_opaque(ctx, "loadparm")), CH_UTF16, CH_UNIX, new_password->data, new_password->length, - (void **)&new_pass, false) != -1) { + (void **)&new_pass, NULL, false)) { /* possibly check password complexity */ diff --git a/source4/dsdb/samdb/ldb_modules/password_hash.c b/source4/dsdb/samdb/ldb_modules/password_hash.c index f427e697b4..56d4c4fe36 100644 --- a/source4/dsdb/samdb/ldb_modules/password_hash.c +++ b/source4/dsdb/samdb/ldb_modules/password_hash.c @@ -1307,7 +1307,7 @@ static int setup_password_fields(struct setup_password_fields_io *io) struct ldb_context *ldb; bool ok; int ret; - ssize_t converted_pw_len; + size_t converted_pw_len; ldb = ldb_module_get_ctx(io->ac->module); @@ -1337,10 +1337,9 @@ static int setup_password_fields(struct setup_password_fields_io *io) ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - converted_pw_len = convert_string_talloc_convenience(io->ac, lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), + if (!convert_string_talloc_convenience(io->ac, lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), CH_UTF8, CH_UTF16, io->n.cleartext_utf8->data, io->n.cleartext_utf8->length, - (void **)&cleartext_utf16_str, false); - if (converted_pw_len == -1) { + (void **)&cleartext_utf16_str, &converted_pw_len, false)) { ldb_asprintf_errstring(ldb, "setup_password_fields: " "failed to generate UTF16 password from cleartext UTF8 password"); @@ -1355,10 +1354,9 @@ static int setup_password_fields(struct setup_password_fields_io *io) ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - converted_pw_len = convert_string_talloc_convenience(io->ac, lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), + if (!convert_string_talloc_convenience(io->ac, lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), CH_UTF16MUNGED, CH_UTF8, io->n.cleartext_utf16->data, io->n.cleartext_utf16->length, - (void **)&cleartext_utf8_str, false); - if (converted_pw_len == -1) { + (void **)&cleartext_utf8_str, &converted_pw_len, false)) { /* We can't bail out entirely, as these unconvertable passwords are frustratingly valid */ io->n.cleartext_utf8 = NULL; talloc_free(cleartext_utf8_blob); @@ -1381,10 +1379,9 @@ static int setup_password_fields(struct setup_password_fields_io *io) if (io->n.cleartext_utf8) { struct samr_Password *lm_hash; char *cleartext_unix; - converted_pw_len = convert_string_talloc_convenience(io->ac, lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), + if (convert_string_talloc_convenience(io->ac, lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), CH_UTF8, CH_UNIX, io->n.cleartext_utf8->data, io->n.cleartext_utf8->length, - (void **)&cleartext_unix, false); - if (converted_pw_len != -1) { + (void **)&cleartext_unix, &converted_pw_len, false)) { lm_hash = talloc(io->ac, struct samr_Password); if (!lm_hash) { ldb_oom(ldb); diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c index 0e8ac5e105..fbd8946bb5 100644 --- a/source4/dsdb/schema/schema_init.c +++ b/source4/dsdb/schema/schema_init.c @@ -1186,12 +1186,11 @@ static struct drsuapi_DsReplicaAttribute *dsdb_find_object_attr_name(struct dsdb return WERR_INVALID_PARAM; \ } \ if (_a && _a->value_ctr.num_values >= 1) { \ - ssize_t _ret; \ - _ret = convert_string_talloc_convenience(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \ + size_t _ret; \ + if (!convert_string_talloc_convenience(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \ _a->value_ctr.values[0].blob->data, \ _a->value_ctr.values[0].blob->length, \ - (void **)discard_const(&(p)->elem), false); \ - if (_ret == -1) { \ + (void **)discard_const(&(p)->elem), &_ret, false)) { \ DEBUG(0,("%s: invalid data!\n", attr)); \ dump_data(0, \ _a->value_ctr.values[0].blob->data, \ diff --git a/source4/dsdb/schema/schema_syntax.c b/source4/dsdb/schema/schema_syntax.c index 965b85a13a..27c9a6c4a4 100644 --- a/source4/dsdb/schema/schema_syntax.c +++ b/source4/dsdb/schema/schema_syntax.c @@ -779,7 +779,6 @@ static WERROR dsdb_syntax_UNICODE_drsuapi_to_ldb(struct ldb_context *ldb, W_ERROR_HAVE_NO_MEMORY(out->values); for (i=0; i < out->num_values; i++) { - ssize_t ret; char *str; if (in->value_ctr.values[i].blob == NULL) { @@ -790,13 +789,12 @@ static WERROR dsdb_syntax_UNICODE_drsuapi_to_ldb(struct ldb_context *ldb, return WERR_FOOBAR; } - ret = convert_string_talloc_convenience(out->values, + if (!convert_string_talloc_convenience(out->values, schema->iconv_convenience, CH_UTF16, CH_UNIX, in->value_ctr.values[i].blob->data, in->value_ctr.values[i].blob->length, - (void **)&str, false); - if (ret == -1) { + (void **)&str, NULL, false)) { return WERR_FOOBAR; } @@ -835,11 +833,10 @@ static WERROR dsdb_syntax_UNICODE_ldb_to_drsuapi(struct ldb_context *ldb, out->value_ctr.values[i].blob = &blobs[i]; - ret = convert_string_talloc_convenience(blobs, schema->iconv_convenience, CH_UNIX, CH_UTF16, + if (!convert_string_talloc_convenience(blobs, schema->iconv_convenience, CH_UNIX, CH_UTF16, in->values[i].data, in->values[i].length, - (void **)&blobs[i].data, false); - if (ret == -1) { + (void **)&blobs[i].data, NULL, false)) { return WERR_FOOBAR; } blobs[i].length = ret; @@ -1145,7 +1142,6 @@ static WERROR dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb(struct ldb_context for (i=0; i < out->num_values; i++) { uint32_t len; - ssize_t ret; char *str; if (in->value_ctr.values[i].blob == NULL) { @@ -1162,11 +1158,10 @@ static WERROR dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb(struct ldb_context return WERR_FOOBAR; } - ret = convert_string_talloc_convenience(out->values, schema->iconv_convenience, CH_UTF16, CH_UNIX, + if (!convert_string_talloc_convenience(out->values, schema->iconv_convenience, CH_UTF16, CH_UNIX, in->value_ctr.values[i].blob->data+4, in->value_ctr.values[i].blob->length-4, - (void **)&str, false); - if (ret == -1) { + (void **)&str, NULL, false)) { return WERR_FOOBAR; } @@ -1202,15 +1197,14 @@ static WERROR dsdb_syntax_PRESENTATION_ADDRESS_ldb_to_drsuapi(struct ldb_context for (i=0; i < in->num_values; i++) { uint8_t *data; - ssize_t ret; + size_t ret; out->value_ctr.values[i].blob = &blobs[i]; - ret = convert_string_talloc_convenience(blobs, schema->iconv_convenience, CH_UNIX, CH_UTF16, + if (!convert_string_talloc_convenience(blobs, schema->iconv_convenience, CH_UNIX, CH_UTF16, in->values[i].data, in->values[i].length, - (void **)&data, false); - if (ret == -1) { + (void **)&data, &ret, false)) { return WERR_FOOBAR; } diff --git a/source4/kdc/kpasswdd.c b/source4/kdc/kpasswdd.c index 85e248dceb..67404af2ab 100644 --- a/source4/kdc/kpasswdd.c +++ b/source4/kdc/kpasswdd.c @@ -219,7 +219,7 @@ static bool kpasswd_process_request(struct kdc_server *kdc, DATA_BLOB *reply) { struct auth_session_info *session_info; - ssize_t pw_len; + size_t pw_len; if (!NT_STATUS_IS_OK(gensec_session_info(gensec_security, &session_info))) { @@ -233,13 +233,11 @@ static bool kpasswd_process_request(struct kdc_server *kdc, case KRB5_KPASSWD_VERS_CHANGEPW: { DATA_BLOB password; - pw_len = convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(kdc->task->lp_ctx), + if (!convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(kdc->task->lp_ctx), CH_UTF8, CH_UTF16, (const char *)input->data, input->length, - (void **)&password.data, false); - - if (pw_len == -1) { + (void **)&password.data, &pw_len, false)) { return false; } password.length = pw_len; @@ -281,12 +279,11 @@ static bool kpasswd_process_request(struct kdc_server *kdc, reply); } - pw_len = convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(kdc->task->lp_ctx), + if (!convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(kdc->task->lp_ctx), CH_UTF8, CH_UTF16, (const char *)chpw.newpasswd.data, chpw.newpasswd.length, - (void **)&password.data, false); - if (pw_len == -1) { + (void **)&password.data, &pw_len, false)) { free_ChangePasswdDataMS(&chpw); return false; } diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 41fbd22335..c558805e04 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -60,9 +60,9 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, case REG_SZ: case REG_EXPAND_SZ: if (val != NULL) - data->length = convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16, + convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16, val->data, val->length, - (void **)&data->data, false); + (void **)&data->data, &data->length, false); else { data->data = NULL; data->length = 0; @@ -105,10 +105,10 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, case REG_SZ: case REG_EXPAND_SZ: if (data.data[0] != '\0') { - val.length = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, + convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, (void *)data.data, data.length, - (void **)&val.data, false); + (void **)&val.data, &val.length, false); ldb_msg_add_value(msg, "data", &val, NULL); } else { ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 3a3c3e7747..3de7602e53 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -53,8 +53,8 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) static bool test_reg_val_data_string_sz(struct torture_context *ctx) { DATA_BLOB db; - db.length = convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16, - "bla", 3, (void **)&db.data, false); + convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16, + "bla", 3, (void **)&db.data, &db.length, false); torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db), "sz failed"); @@ -88,10 +88,10 @@ static bool test_reg_val_data_string_empty(struct torture_context *ctx) static bool test_reg_val_description(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16, + convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16, "stationary traveller", strlen("stationary traveller"), - (void **)&data.data, false); + (void **)&data.data, &data.length, false); torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), "camel", REG_SZ, data), "reg_val_description failed"); @@ -102,10 +102,10 @@ static bool test_reg_val_description(struct torture_context *ctx) static bool test_reg_val_description_nullname(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16, + convert_string_talloc_convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16, "west berlin", strlen("west berlin"), - (void **)&data.data, false); + (void **)&data.data, &data.length, false); torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin", reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), NULL, REG_SZ, data), "description with null name failed"); diff --git a/source4/lib/registry/util.c b/source4/lib/registry/util.c index 742c3dca2f..a1897eff2e 100644 --- a/source4/lib/registry/util.c +++ b/source4/lib/registry/util.c @@ -65,7 +65,7 @@ _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, case REG_SZ: convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UTF16, CH_UNIX, data.data, data.length, - (void **)&ret, false); + (void **)&ret, NULL, false); return ret; case REG_BINARY: ret = data_blob_hex_string(mem_ctx, &data); @@ -123,9 +123,9 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, { case REG_SZ: case REG_EXPAND_SZ: - data->length = convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UNIX, CH_UTF16, + convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UNIX, CH_UTF16, data_str, strlen(data_str), - (void **)&data->data, false); + (void **)&data->data, &data->length, false); break; case REG_DWORD: { diff --git a/source4/lib/tdr/tdr.c b/source4/lib/tdr/tdr.c index 93f1329ea9..8b62ea0c2b 100644 --- a/source4/lib/tdr/tdr.c +++ b/source4/lib/tdr/tdr.c @@ -130,7 +130,7 @@ NTSTATUS tdr_print_uint32(struct tdr_print *tdr, const char *name, uint32_t *v) NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v, uint32_t length, uint32_t el_size, charset_t chset) { - int ret; + size_t ret; if (length == -1) { switch (chset) { @@ -153,9 +153,7 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v, TDR_PULL_NEED_BYTES(tdr, el_size*length); - ret = convert_string_talloc_convenience(ctx, tdr->iconv_convenience, chset, CH_UNIX, tdr->data.data+tdr->offset, el_size*length, discard_const_p(void *, v), false); - - if (ret == -1) { + if (!convert_string_talloc_convenience(ctx, tdr->iconv_convenience, chset, CH_UNIX, tdr->data.data+tdr->offset, el_size*length, discard_const_p(void *, v), &ret, false)) { return NT_STATUS_INVALID_PARAMETER; } @@ -166,7 +164,7 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v, NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length, uint32_t el_size, charset_t chset) { - ssize_t ret, required; + size_t ret, required; if (length == -1) { length = strlen(*v) + 1; /* Extra element for null character */ @@ -175,9 +173,7 @@ NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length, required = el_size * length; TDR_PUSH_NEED_BYTES(tdr, required); - ret = convert_string_convenience(tdr->iconv_convenience, CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required, false); - - if (ret == -1) { + if (!convert_string_convenience(tdr->iconv_convenience, CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required, &ret, false)) { return NT_STATUS_INVALID_PARAMETER; } diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index b8f4e5116c..09ecb40002 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -49,7 +49,7 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, while (blob.length - ofs >= 24) { uint_t n = io->num_streams; uint32_t nlen, len; - ssize_t size; + bool ret; void *vstr; io->streams = talloc_realloc(mem_ctx, io->streams, struct stream_struct, n+1); @@ -62,10 +62,10 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, if (nlen > blob.length - (ofs + 24)) { return NT_STATUS_INFO_LENGTH_MISMATCH; } - size = convert_string_talloc(io->streams, + ret = convert_string_talloc(io->streams, CH_UTF16, CH_UNIX, - blob.data+ofs+24, nlen, &vstr, false); - if (size == -1) { + blob.data+ofs+24, nlen, &vstr, NULL, false); + if (!ret) { return NT_STATUS_ILLEGAL_CHARACTER; } io->streams[n].stream_name.s = (const char *)vstr; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 5b461b47fd..0f04190a8b 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -558,7 +558,8 @@ static size_t smbcli_req_pull_ucs2(struct request_bufinfo *bufinfo, TALLOC_CTX * char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; - ssize_t ret; + bool ret; + size_t ret_size; if (!(flags & STR_NOALIGN) && ucs2_align(bufinfo->align_base, src, flags)) { src++; @@ -585,8 +586,8 @@ static size_t smbcli_req_pull_ucs2(struct request_bufinfo *bufinfo, TALLOC_CTX * return 0; } - ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest, false); - if (ret == -1) { + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest, &ret_size, false); + if (!ret) { *dest = NULL; return 0; } @@ -611,7 +612,8 @@ size_t smbcli_req_pull_ascii(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ct char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; - ssize_t ret; + bool ret; + size_t ret_size; src_len = bufinfo->data_size - PTR_DIFF(src, bufinfo->data); if (src_len < 0) { @@ -627,14 +629,14 @@ size_t smbcli_req_pull_ascii(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ct src_len2++; } - ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)dest, false); + ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)dest, &ret_size, false); - if (ret == -1) { + if (!ret) { *dest = NULL; return 0; } - return ret; + return ret_size; } /** @@ -752,7 +754,8 @@ size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; - ssize_t ret; + size_t ret_size; + bool ret; char *dest2; if (src < blob->data || @@ -780,8 +783,8 @@ size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, src_len2 = utf16_len_n(src, src_len); - ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2, false); - if (ret == -1) { + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2, &ret_size, false); + if (!ret) { *dest = NULL; return 0; } @@ -808,7 +811,8 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; - ssize_t ret; + size_t ret_size; + bool ret; char *dest2; src_len = blob->length - PTR_DIFF(src, blob->data); @@ -826,15 +830,15 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2, false); + ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2, &ret_size, false); - if (ret == -1) { + if (!ret) { *dest = NULL; return 0; } *dest = dest2; - return ret; + return ret_size; } /** diff --git a/source4/libcli/smb2/request.c b/source4/libcli/smb2/request.c index 19a2862d68..649a1db8d5 100644 --- a/source4/libcli/smb2/request.c +++ b/source4/libcli/smb2/request.c @@ -656,8 +656,8 @@ NTSTATUS smb2_pull_o16s16_string(struct smb2_request_buffer *buf, TALLOC_CTX *me { DATA_BLOB blob; NTSTATUS status; - ssize_t size; void *vstr; + bool ret; status = smb2_pull_o16s16_blob(buf, mem_ctx, ptr, &blob); NT_STATUS_NOT_OK_RETURN(status); @@ -675,11 +675,11 @@ NTSTATUS smb2_pull_o16s16_string(struct smb2_request_buffer *buf, TALLOC_CTX *me return NT_STATUS_OK; } - size = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, - blob.data, blob.length, &vstr, false); + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, + blob.data, blob.length, &vstr, NULL, false); data_blob_free(&blob); (*str) = (char *)vstr; - if (size == -1) { + if (!ret) { return NT_STATUS_ILLEGAL_CHARACTER; } return NT_STATUS_OK; @@ -694,7 +694,7 @@ NTSTATUS smb2_push_o16s16_string(struct smb2_request_buffer *buf, { DATA_BLOB blob; NTSTATUS status; - ssize_t size; + bool ret; if (str == NULL) { return smb2_push_o16s16_blob(buf, ofs, data_blob(NULL, 0)); @@ -706,12 +706,12 @@ NTSTATUS smb2_push_o16s16_string(struct smb2_request_buffer *buf, return smb2_push_o16s16_blob(buf, ofs, blob); } - size = convert_string_talloc(buf->buffer, CH_UNIX, CH_UTF16, - str, strlen(str), (void **)&blob.data, false); - if (size == -1) { + ret = convert_string_talloc(buf->buffer, CH_UNIX, CH_UTF16, + str, strlen(str), (void **)&blob.data, &blob.length, + false); + if (!ret) { return NT_STATUS_ILLEGAL_CHARACTER; } - blob.length = size; status = smb2_push_o16s16_blob(buf, ofs, blob); data_blob_free(&blob); diff --git a/source4/libnet/libnet_samdump.c b/source4/libnet/libnet_samdump.c index 04a73c53ff..10a14655f3 100644 --- a/source4/libnet/libnet_samdump.c +++ b/source4/libnet/libnet_samdump.c @@ -185,9 +185,9 @@ NTSTATUS libnet_SamDump(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, if (strcasecmp_m(s->name, secret_name) != 0) { continue; } - if (convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF16, CH_UNIX, + if (!convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF16, CH_UNIX, s->secret.data, s->secret.length, - (void **)&secret_string, false) == -1) { + (void **)&secret_string, NULL, false)) { r->out.error_string = talloc_asprintf(mem_ctx, "Could not convert secret for domain %s to a string", t->name); diff --git a/source4/librpc/ndr/ndr_string.c b/source4/librpc/ndr/ndr_string.c index 1ef1b0c13c..d6d996846e 100644 --- a/source4/librpc/ndr/ndr_string.c +++ b/source4/librpc/ndr/ndr_string.c @@ -30,7 +30,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, char *as=NULL; uint32_t len1, ofs, len2; uint16_t len3; - int ret; + size_t ret; charset_t chset = CH_UTF16; unsigned byte_mul = 2; unsigned flags = ndr->flags; @@ -81,12 +81,11 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len2 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len2 + c_len_term)*byte_mul, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -118,13 +117,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len1 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len1 + c_len_term)*byte_mul, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -157,13 +155,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len1 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len1 + c_len_term)*byte_mul, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -192,13 +189,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len3 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len3 + c_len_term)*byte_mul, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -225,13 +221,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len3 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len3, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -246,12 +241,11 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, } else { len1 = utf16_len_n(ndr->data+ndr->offset, ndr->data_size - ndr->offset); } - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len1, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -271,13 +265,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, if (len1 == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); } else { - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len1, - (void **)&as, false); - if (ret == -1) { + (void **)&as, &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -301,7 +294,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, */ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, int ndr_flags, const char *s) { - ssize_t s_len, c_len, d_len; + size_t s_len, c_len, d_len; int chset = CH_UTF16; unsigned flags = ndr->flags; unsigned byte_mul = 2; @@ -334,8 +327,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, int ndr_flags, if (!(flags & LIBNDR_FLAG_STR_NOTERM)) { s_len++; } - d_len = convert_string_talloc_convenience(ndr, ndr->iconv_convenience, CH_UNIX, chset, s, s_len, (void **)&dest, false); - if (d_len == -1) { + if (!convert_string_talloc_convenience(ndr, ndr->iconv_convenience, CH_UNIX, chset, s, s_len, (void **)&dest, &d_len, false)) { return ndr_push_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -656,7 +648,7 @@ _PUBLIC_ enum ndr_err_code ndr_check_string_terminator(struct ndr_pull *ndr, uin _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, const char **var, uint32_t length, uint8_t byte_mul, charset_t chset) { - int ret; + size_t ret; if (length == 0) { *var = talloc_strdup(ndr->current_mem_ctx, ""); return NDR_ERR_SUCCESS; @@ -668,13 +660,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, NDR_PULL_NEED_BYTES(ndr, length*byte_mul); - ret = convert_string_talloc_convenience(ndr->current_mem_ctx, + if (!convert_string_talloc_convenience(ndr->current_mem_ctx, ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, length*byte_mul, - discard_const_p(void *, var), false); - if (ret == -1) { + discard_const_p(void *, var), &ret, false)) { return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } @@ -685,7 +676,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, const char *var, uint32_t length, uint8_t byte_mul, charset_t chset) { - ssize_t ret, required; + size_t ret, required; if (NDR_BE(ndr) && chset == CH_UTF16) { chset = CH_UTF16BE; @@ -694,10 +685,9 @@ _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, required = byte_mul * length; NDR_PUSH_NEED_BYTES(ndr, required); - ret = convert_string_convenience(ndr->iconv_convenience, CH_UNIX, chset, + if (!convert_string_convenience(ndr->iconv_convenience, CH_UNIX, chset, var, strlen(var), - ndr->data+ndr->offset, required, false); - if (ret == -1) { + ndr->data+ndr->offset, required, &ret, false)) { return ndr_push_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); } diff --git a/source4/rpc_server/samr/samr_password.c b/source4/rpc_server/samr/samr_password.c index 33a70fd478..f334eeb8f3 100644 --- a/source4/rpc_server/samr/samr_password.c +++ b/source4/rpc_server/samr/samr_password.c @@ -196,7 +196,7 @@ NTSTATUS dcesrv_samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call, DATA_BLOB lm_pwd_blob; uint8_t new_lm_hash[16]; struct samr_Password lm_verifier; - ssize_t unicode_pw_len; + size_t unicode_pw_len; if (pwbuf == NULL) { return NT_STATUS_INVALID_PARAMETER; @@ -251,22 +251,21 @@ NTSTATUS dcesrv_samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call, return NT_STATUS_WRONG_PASSWORD; } - if (convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx), + if (!convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx), CH_DOS, CH_UNIX, (const char *)new_password.data, new_password.length, - (void **)&new_pass, false) == -1) { + (void **)&new_pass, NULL, false)) { DEBUG(3,("samr: failed to convert incoming password buffer to unix charset\n")); ldb_transaction_cancel(sam_ctx); return NT_STATUS_WRONG_PASSWORD; } - unicode_pw_len = convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx), + if (!convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx), CH_DOS, CH_UTF16, (const char *)new_password.data, new_password.length, - (void **)&new_unicode_password.data, false); - if (unicode_pw_len == -1) { + (void **)&new_unicode_password.data, &unicode_pw_len, false)) { DEBUG(3,("samr: failed to convert incoming password buffer to UTF16 charset\n")); ldb_transaction_cancel(sam_ctx); return NT_STATUS_WRONG_PASSWORD; @@ -429,11 +428,11 @@ NTSTATUS dcesrv_samr_ChangePasswordUser3(struct dcesrv_call_state *dce_call, * this) */ if (lm_pwd && r->in.lm_verifier != NULL) { char *new_pass; - if (convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx), + if (!convert_string_talloc_convenience(mem_ctx, lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx), CH_UTF16, CH_UNIX, (const char *)new_password.data, new_password.length, - (void **)&new_pass, false) != -1) { + (void **)&new_pass, NULL, false)) { E_deshash(new_pass, new_lm_hash); E_old_pw_hash(new_nt_hash, lm_pwd->hash, lm_verifier.hash); if (memcmp(lm_verifier.hash, r->in.lm_verifier->hash, 16) != 0) { diff --git a/source4/smb_server/smb/request.c b/source4/smb_server/smb/request.c index 377c5bf3cc..6846f80594 100644 --- a/source4/smb_server/smb/request.c +++ b/source4/smb_server/smb/request.c @@ -482,7 +482,7 @@ size_t req_append_var_block(struct smbsrv_request *req, static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; - ssize_t ret; + bool ret; char *dest2; if (!(flags & STR_NOALIGN) && ucs2_align(bufinfo->align_base, src, flags)) { @@ -513,9 +513,9 @@ static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest, return src_len2 + alignment; } - ret = convert_string_talloc(bufinfo->mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2, false); + ret = convert_string_talloc(bufinfo->mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2, NULL, false); - if (ret == -1) { + if (!ret) { *dest = NULL; return 0; } @@ -540,7 +540,7 @@ static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest, static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; - ssize_t ret; + bool ret; char *dest2; if (flags & STR_NO_RANGE_CHECK) { @@ -562,9 +562,9 @@ static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest, src_len2++; } - ret = convert_string_talloc(bufinfo->mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2, false); + ret = convert_string_talloc(bufinfo->mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2, NULL, false); - if (ret == -1) { + if (!ret) { *dest = NULL; return 0; } diff --git a/source4/torture/basic/charset.c b/source4/torture/basic/charset.c index 33ab2c9768..5ac299dbbe 100644 --- a/source4/torture/basic/charset.c +++ b/source4/torture/basic/charset.c @@ -42,7 +42,7 @@ static NTSTATUS unicode_open(struct torture_context *tctx, { union smb_open io; char *fname, *fname2=NULL, *ucs_name; - int i; + size_t i; NTSTATUS status; ucs_name = talloc_size(mem_ctx, (1+u_name_len)*2); @@ -56,8 +56,7 @@ static NTSTATUS unicode_open(struct torture_context *tctx, } SSVAL(ucs_name, i*2, 0); - i = convert_string_talloc_convenience(ucs_name, lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname, false); - if (i == -1) { + if (!convert_string_talloc_convenience(ucs_name, lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname, &i, false)) { torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n"); talloc_free(ucs_name); return NT_STATUS_NO_MEMORY; diff --git a/source4/torture/basic/utable.c b/source4/torture/basic/utable.c index ef0e4d44ed..ca6c2fd576 100644 --- a/source4/torture/basic/utable.c +++ b/source4/torture/basic/utable.c @@ -32,7 +32,8 @@ bool torture_utable(struct torture_context *tctx, const char *alt_name; int fnum; uint8_t c2[4]; - int c, len, fd; + int c, fd; + size_t len; int chars_allowed=0, alt_allowed=0; uint8_t valid[0x10000]; @@ -49,9 +50,9 @@ bool torture_utable(struct torture_context *tctx, SSVAL(c2, 0, c); strncpy(fname, "\\utable\\x", sizeof(fname)-1); p = fname+strlen(fname); - len = convert_string_convenience(lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, + convert_string_convenience(lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, c2, 2, - p, sizeof(fname)-strlen(fname), false); + p, sizeof(fname)-strlen(fname), &len, false); p[len] = 0; strncat(fname,"_a_long_extension",sizeof(fname)-1); @@ -102,15 +103,15 @@ static char *form_name(struct smb_iconv_convenience *iconv_convenience, int c) static char fname[256]; uint8_t c2[4]; char *p; - int len; + size_t len; strncpy(fname, "\\utable\\", sizeof(fname)-1); p = fname+strlen(fname); SSVAL(c2, 0, c); - len = convert_string_convenience(iconv_convenience, CH_UTF16, CH_UNIX, + convert_string_convenience(iconv_convenience, CH_UTF16, CH_UNIX, c2, 2, - p, sizeof(fname)-strlen(fname), false); + p, sizeof(fname)-strlen(fname), &len, false); p[len] = 0; return fname; } diff --git a/source4/torture/rpc/samlogon.c b/source4/torture/rpc/samlogon.c index 7e1744ffab..0f0b8dc84d 100644 --- a/source4/torture/rpc/samlogon.c +++ b/source4/torture/rpc/samlogon.c @@ -1171,11 +1171,11 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea password = strupper_talloc(samlogon_state->mem_ctx, samlogon_state->password); - if ((convert_string_talloc_convenience(samlogon_state->mem_ctx, + if (!convert_string_talloc_convenience(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, CH_UNIX, CH_DOS, password, strlen(password)+1, - (void**)&dospw, false)) == -1) { + (void**)&dospw, NULL, false)) { DEBUG(0, ("convert_string_talloc failed!\n")); exit(1); } diff --git a/source4/torture/rpc/spoolss_win.c b/source4/torture/rpc/spoolss_win.c index b09c62479c..08fadafe2c 100644 --- a/source4/torture/rpc/spoolss_win.c +++ b/source4/torture/rpc/spoolss_win.c @@ -383,7 +383,7 @@ static bool test_EnumPrinterKey(struct torture_context *tctx, convert_string_talloc_convenience(ctx, lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, epk.out.key_buffer, *epk.out.needed, - (void**)&ctx->printer_keys, false); + (void**)&ctx->printer_keys, NULL, false); return true; } |