diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-03-01 06:33:40 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-03-01 06:33:40 +0100 |
commit | 9ffb6d2d9e78ed192b8215194b6328d03d1ddad3 (patch) | |
tree | fc76fb3e1d8d9e381559244440c6738574f6c21d /lib | |
parent | 79fc0ddaf44af1e31d7e6f2c6f576fd3c05e087d (diff) | |
download | samba-9ffb6d2d9e78ed192b8215194b6328d03d1ddad3.tar.gz samba-9ffb6d2d9e78ed192b8215194b6328d03d1ddad3.tar.bz2 samba-9ffb6d2d9e78ed192b8215194b6328d03d1ddad3.zip |
Add allow_badcharcnv argument to all conversion function, for
consistency with Samba 3.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/charset/charcnv.c | 11 | ||||
-rw-r--r-- | lib/util/charset/charset.h | 8 | ||||
-rw-r--r-- | lib/util/charset/tests/iconv.c | 6 | ||||
-rw-r--r-- | lib/util/charset/util_unistr.c | 29 |
4 files changed, 31 insertions, 23 deletions
diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c index 1f3b1ac846..18be2bcac2 100644 --- a/lib/util/charset/charcnv.c +++ b/lib/util/charset/charcnv.c @@ -240,7 +240,7 @@ convert: _PUBLIC_ ssize_t 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) + void *dest, size_t destlen, bool allow_badcharcnv) { size_t i_len, o_len; size_t retval; @@ -248,6 +248,10 @@ _PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, char* outbuf = (char*)dest; smb_iconv_t descriptor; + if (allow_badcharcnv) { + return -1; + } + if (srclen == (size_t)-1) srclen = strlen(inbuf)+1; @@ -305,10 +309,13 @@ _PUBLIC_ ssize_t 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) + void **dest, bool allow_badcharcnv) { smb_iconv_t descriptor; + if (allow_badcharcnv) + return (size_t)-1; + *dest = NULL; if (src == NULL || srclen == (size_t)-1 || srclen == 0) diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index f027beb8db..82484b7805 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -117,11 +117,11 @@ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, - void **dest); + void **dest, bool allow_badcharcnv); ssize_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen); + void *dest, size_t destlen, bool allow_badcharcnv); ssize_t iconv_talloc(TALLOC_CTX *mem_ctx, smb_iconv_t cd, @@ -150,12 +150,12 @@ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, ssize_t 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); + void *dest, size_t destlen, bool allow_badcharcnv); ssize_t 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); + void **dest, 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 1facea6136..fbe7b103ab 100644 --- a/lib/util/charset/tests/iconv.c +++ b/lib/util/charset/tests/iconv.c @@ -418,7 +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); + ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)buf, len*2, (void**)&dest, false); if (ret == -1) { torture_fail(tctx, "Failed to convert random buffer\n"); } @@ -429,7 +429,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); + ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF16, (void *)le1, 20, (void**)&munged1, false); if (ret == -1) { torture_fail(tctx, "Failed to convert fixed buffer to UTF16_MUNGED\n"); } @@ -438,7 +438,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); + ret = convert_string_talloc(mem_ctx, CH_UTF16MUNGED, CH_UTF8, (void *)le1, 20, (void**)&out1, false); if (ret == -1) { 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 41b9c94cbb..e6c6c3f466 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -656,7 +656,7 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) src_len++; - return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len); + return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, false); } /** @@ -672,7 +672,7 @@ _PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, false); } @@ -706,7 +706,7 @@ static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t s } } - ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); + ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, false); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -759,7 +759,7 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags /* ucs2 is always a multiple of 2 bytes */ dest_len &= ~1; - ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len); + ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len, false); if (ret == (size_t)-1) { return 0; } @@ -783,7 +783,7 @@ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest, false); } @@ -799,7 +799,7 @@ _PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, false); } /** @@ -835,7 +835,7 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src if (src_len != (size_t)-1) src_len &= ~1; - ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len); + ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len, false); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -854,7 +854,7 @@ _PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, false); } /** @@ -869,7 +869,7 @@ _PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) { size_t src_len = utf16_len(src); *dest = NULL; - return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, false); } /** @@ -884,7 +884,7 @@ _PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, false); } /** @@ -952,11 +952,11 @@ _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_ **/ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen) + void *dest, size_t destlen, bool allow_badcharcnv) { return convert_string_convenience(get_iconv_convenience(), from, to, src, srclen, - dest, destlen); + dest, destlen, allow_badcharcnv); } /** @@ -972,10 +972,11 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, - void **dest) + void **dest, bool allow_badcharcnv) { return convert_string_talloc_convenience(ctx, get_iconv_convenience(), - from, to, src, srclen, dest); + from, to, src, srclen, dest, + allow_badcharcnv); } |