diff options
author | David Disseldorp <ddiss@suse.de> | 2011-11-13 20:01:43 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2012-01-13 09:37:37 -0800 |
commit | ee292bf5f342652b382a1926779f215f7f8bd806 (patch) | |
tree | a8cd9e98c3fbdde4abf655be4a5d3bd7379e317d /librpc/ndr | |
parent | 6501b8bc6f6f7cd83f67c9766abc8231caf7fe54 (diff) | |
download | samba-ee292bf5f342652b382a1926779f215f7f8bd806.tar.gz samba-ee292bf5f342652b382a1926779f215f7f8bd806.tar.bz2 samba-ee292bf5f342652b382a1926779f215f7f8bd806.zip |
ndr: add ndr_pull_charset_to_null()
The same as ndr_pull_charset(), however only perform character
conversion on bytes prior to and including the null terminator.
Signed-off-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'librpc/ndr')
-rw-r--r-- | librpc/ndr/libndr.h | 1 | ||||
-rw-r--r-- | librpc/ndr/ndr_string.c | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 9c26befdf7..162c109781 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -598,6 +598,7 @@ size_t ndr_size_string_array(const char **a, uint32_t count, int flags); uint32_t ndr_string_length(const void *_var, uint32_t element_size); enum ndr_err_code ndr_check_string_terminator(struct ndr_pull *ndr, uint32_t count, uint32_t element_size); 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); +enum ndr_err_code ndr_pull_charset_to_null(struct ndr_pull *ndr, int ndr_flags, const char **var, uint32_t length, uint8_t byte_mul, charset_t chset); 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); /* GUIDs */ diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c index 840776fa3a..94a18c3224 100644 --- a/librpc/ndr/ndr_string.c +++ b/librpc/ndr/ndr_string.c @@ -603,6 +603,37 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, return NDR_ERR_SUCCESS; } +_PUBLIC_ enum ndr_err_code ndr_pull_charset_to_null(struct ndr_pull *ndr, int ndr_flags, const char **var, uint32_t length, uint8_t byte_mul, charset_t chset) +{ + size_t converted_size; + uint32_t str_len; + + if (length == 0) { + *var = talloc_strdup(ndr->current_mem_ctx, ""); + return NDR_ERR_SUCCESS; + } + + if (NDR_BE(ndr) && chset == CH_UTF16) { + chset = CH_UTF16BE; + } + + NDR_PULL_NEED_BYTES(ndr, length*byte_mul); + + str_len = ndr_string_length(ndr->data+ndr->offset, byte_mul); + str_len = MIN(str_len, length); /* overrun protection */ + if (!convert_string_talloc(ndr->current_mem_ctx, chset, CH_UNIX, + ndr->data+ndr->offset, str_len*byte_mul, + discard_const_p(void *, var), + &converted_size)) + { + return ndr_pull_error(ndr, NDR_ERR_CHARCNV, + "Bad character conversion"); + } + NDR_CHECK(ndr_pull_advance(ndr, length*byte_mul)); + + return NDR_ERR_SUCCESS; +} + _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 required; |