2 Unix SMB/CIFS implementation.
3 Character set conversion Extensions
4 Copyright (C) Igor Vergeichik <iverg@mail.ru> 2001
5 Copyright (C) Andrew Tridgell 2001
6 Copyright (C) Simo Sorce 2001
7 Copyright (C) Martin Pool 2003
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * @brief Character-set conversion routines built on our iconv.
31 * @note Samba's internal character set (at least in the 3.0 series)
32 * is always the same as the one for the Unix filesystem. It is
33 * <b>not</b> necessarily UTF-8 and may be different on machines that
34 * need i18n filenames to be compatible with Unix software. It does
35 * have to be a superset of ASCII. All multibyte sequences must start
36 * with a byte with the high bit set.
42 static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
43 static BOOL conv_silent; /* Should we do a debug if the conversion fails ? */
46 * Return the name of a charset to give to iconv().
48 static const char *charset_name(charset_t ch)
50 const char *ret = NULL;
52 if (ch == CH_UCS2) ret = "UCS-2LE";
53 else if (ch == CH_UNIX) ret = lp_unix_charset();
54 else if (ch == CH_DOS) ret = lp_dos_charset();
55 else if (ch == CH_DISPLAY) ret = lp_display_charset();
56 else if (ch == CH_UTF8) ret = "UTF8";
58 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
59 if (ret && strcasecmp(ret, "LOCALE") == 0) {
60 const char *ln = NULL;
63 setlocale(LC_ALL, "");
65 ln = nl_langinfo(CODESET);
67 /* Check whether the charset name is supported
69 smb_iconv_t handle = smb_iconv_open(ln,"UCS-2LE");
70 if (handle == (smb_iconv_t) -1) {
71 DEBUG(5,("Locale charset '%s' unsupported, using ASCII instead\n", ln));
74 DEBUG(5,("Substituting charset '%s' for LOCALE\n", ln));
75 smb_iconv_close(handle);
82 if (!ret || !*ret) ret = "ASCII";
86 void lazy_initialize_conv(void)
88 static int initialized = False;
98 * Initialize iconv conversion descriptors.
100 * This is called the first time it is needed, and also called again
101 * every time the configuration is reloaded, because the charset or
102 * codepage might have changed.
104 void init_iconv(void)
107 BOOL did_reload = False;
109 /* so that charset_name() works we need to get the UNIX<->UCS2 going
111 if (!conv_handles[CH_UNIX][CH_UCS2])
112 conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open("UCS-2LE", "ASCII");
114 if (!conv_handles[CH_UCS2][CH_UNIX])
115 conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE");
117 for (c1=0;c1<NUM_CHARSETS;c1++) {
118 for (c2=0;c2<NUM_CHARSETS;c2++) {
119 const char *n1 = charset_name((charset_t)c1);
120 const char *n2 = charset_name((charset_t)c2);
121 if (conv_handles[c1][c2] &&
122 strcmp(n1, conv_handles[c1][c2]->from_name) == 0 &&
123 strcmp(n2, conv_handles[c1][c2]->to_name) == 0)
128 if (conv_handles[c1][c2])
129 smb_iconv_close(conv_handles[c1][c2]);
131 conv_handles[c1][c2] = smb_iconv_open(n2,n1);
132 if (conv_handles[c1][c2] == (smb_iconv_t)-1) {
133 DEBUG(0,("Conversion from %s to %s not supported\n",
134 charset_name((charset_t)c1), charset_name((charset_t)c2)));
135 conv_handles[c1][c2] = NULL;
141 /* XXX: Does this really get called every time the dos
142 * codepage changes? */
143 /* XXX: Is the did_reload test too strict? */
145 init_doschar_table();
152 * Convert string from one encoding to another, making error checking etc
153 * Slow path version - uses (slow) iconv.
155 * @param src pointer to source string (multibyte or singlebyte)
156 * @param srclen length of the source string in bytes
157 * @param dest pointer to destination string (multibyte or singlebyte)
158 * @param destlen maximal length allowed for string
159 * @returns the number of bytes occupied in the destination
161 * Ensure the srclen contains the terminating zero.
165 static size_t convert_string_internal(charset_t from, charset_t to,
166 void const *src, size_t srclen,
167 void *dest, size_t destlen)
171 const char* inbuf = (const char*)src;
172 char* outbuf = (char*)dest;
173 smb_iconv_t descriptor;
175 lazy_initialize_conv();
177 descriptor = conv_handles[from][to];
179 if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
181 DEBUG(0,("convert_string_internal: Conversion not supported.\n"));
187 retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
188 if(retval==(size_t)-1) {
189 const char *reason="unknown error";
192 reason="Incomplete multibyte sequence";
194 DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
197 reason="No more room";
199 DEBUG(3, ("convert_string_internal: Required %lu, available %lu\n",
200 (unsigned long)srclen, (unsigned long)destlen));
201 /* we are not sure we need srclen bytes,
202 may be more, may be less.
203 We only know we need more than destlen
207 reason="Illegal multibyte sequence";
209 DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
213 DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
216 /* smb_panic(reason); */
218 return destlen-o_len;
222 /* conversion not supported, use as is */
224 size_t len = MIN(srclen,destlen);
226 memcpy(dest,src,len);
232 * Convert string from one encoding to another, making error checking etc
233 * Fast path version - handles ASCII first.
235 * @param src pointer to source string (multibyte or singlebyte)
236 * @param srclen length of the source string in bytes
237 * @param dest pointer to destination string (multibyte or singlebyte)
238 * @param destlen maximal length allowed for string
239 * @returns the number of bytes occupied in the destination
241 * Ensure the srclen contains the terminating zero.
245 size_t convert_string(charset_t from, charset_t to,
246 void const *src, size_t srclen,
247 void *dest, size_t destlen)
249 if (srclen == (size_t)-1) {
251 srclen = strlen_w(src)+2;
253 srclen = strlen(src)+1;
258 if (from != CH_UCS2 && to != CH_UCS2) {
259 const unsigned char *p = (const unsigned char *)src;
260 unsigned char *q = (unsigned char *)dest;
264 /* If all characters are ascii, fast path here. */
265 while (srclen && destlen) {
266 if ((lastp = *p) <= 0x7f) {
274 return retval + convert_string_internal(from, to, p, srclen, q, destlen);
278 } else if (from == CH_UCS2 && to != CH_UCS2) {
279 const unsigned char *p = (const unsigned char *)src;
280 unsigned char *q = (unsigned char *)dest;
284 /* If all characters are ascii, fast path here. */
285 while ((srclen >= 2) && destlen) {
286 if ((lastp = *p) <= 0x7f && p[1] == 0) {
295 return retval + convert_string_internal(from, to, p, srclen, q, destlen);
299 } else if (from != CH_UCS2 && to == CH_UCS2) {
300 const unsigned char *p = (const unsigned char *)src;
301 unsigned char *q = (unsigned char *)dest;
305 /* If all characters are ascii, fast path here. */
306 while (srclen && (destlen >= 2)) {
307 if ((lastp = *p) <= 0x7F) {
316 return retval + convert_string_internal(from, to, p, srclen, q, destlen);
321 return convert_string_internal(from, to, src, srclen, dest, destlen);
325 * Convert between character sets, allocating a new buffer for the result.
327 * @param ctx TALLOC_CTX to use to allocate with. If NULL use malloc.
328 * @param srclen length of source buffer.
329 * @param dest always set at least to NULL
330 * @note -1 is not accepted for srclen.
332 * @returns Size in bytes of the converted string; or -1 in case of error.
334 * Ensure the srclen contains the terminating zero.
337 size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
338 void const *src, size_t srclen, void **dest)
340 size_t i_len, o_len, destlen = MAX(srclen, 512);
342 const char *inbuf = (const char *)src;
343 char *outbuf = NULL, *ob = NULL;
344 smb_iconv_t descriptor;
348 if (src == NULL || srclen == (size_t)-1)
353 lazy_initialize_conv();
355 descriptor = conv_handles[from][to];
357 if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
359 DEBUG(0,("convert_string_allocate: Conversion not supported.\n"));
364 if ((destlen*2) < destlen) {
365 /* wrapped ! abort. */
367 DEBUG(0, ("convert_string_allocate: destlen wrapped !\n"));
372 destlen = destlen * 2;
376 ob = (char *)talloc_realloc(ctx, ob, destlen);
378 ob = (char *)Realloc(ob, destlen);
381 DEBUG(0, ("convert_string_allocate: realloc failed!\n"));
390 retval = smb_iconv(descriptor,
393 if(retval == (size_t)-1) {
394 const char *reason="unknown error";
397 reason="Incomplete multibyte sequence";
399 DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf));
404 reason="Illegal multibyte sequence";
406 DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf));
410 DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf));
411 /* smb_panic(reason); */
415 destlen = destlen - o_len;
417 *dest = (char *)talloc_realloc(ctx,ob,destlen);
419 *dest = (char *)Realloc(ob,destlen);
420 if (destlen && !*dest) {
421 DEBUG(0, ("convert_string_allocate: out of memory!\n"));
431 /* conversion not supported, use as is */
433 if (srclen && (destlen != srclen)) {
436 ob = (char *)talloc_realloc(ctx, ob, destlen);
438 ob = (char *)Realloc(ob, destlen);
440 DEBUG(0, ("convert_string_allocate: realloc failed!\n"));
447 memcpy(ob,(const char *)src,srclen);
455 * Convert between character sets, allocating a new buffer using talloc for the result.
457 * @param srclen length of source buffer.
458 * @param dest always set at least to NULL
459 * @note -1 is not accepted for srclen.
461 * @returns Size in bytes of the converted string; or -1 in case of error.
463 static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
464 void const *src, size_t srclen, void **dest)
469 dest_len=convert_string_allocate(ctx, from, to, src, srclen, dest);
470 if (dest_len == (size_t)-1)
477 size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
482 size = push_ucs2_allocate(&buffer, src);
484 smb_panic("failed to create UCS2 buffer");
486 if (!strupper_w(buffer) && (dest == src)) {
491 size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen);
497 strdup() a unix string to upper case.
501 char *strdup_upper(const char *s)
507 size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer));
514 size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer));
519 return strdup(out_buffer);
522 size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
527 size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen,
530 smb_panic("failed to create UCS2 buffer");
532 if (!strlower_w(buffer) && (dest == src)) {
536 size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen);
542 strdup() a unix string to lower case.
545 char *strdup_lower(const char *s)
551 size = push_ucs2_allocate(&buffer, s);
558 size = pull_ucs2_allocate(&out_buffer, buffer);
568 static size_t ucs2_align(const void *base_ptr, const void *p, int flags)
570 if (flags & (STR_NOALIGN|STR_ASCII))
572 return PTR_DIFF(p, base_ptr) & 1;
577 * Copy a string from a char* unix src to a dos codepage string destination.
579 * @return the number of bytes occupied by the string in the destination.
581 * @param flags can include
583 * <dt>STR_TERMINATE</dt> <dd>means include the null termination</dd>
584 * <dt>STR_UPPER</dt> <dd>means uppercase in the destination</dd>
587 * @param dest_len the maximum length in bytes allowed in the
588 * destination. If @p dest_len is -1 then no maximum is used.
590 size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
592 size_t src_len = strlen(src);
595 /* treat a pstring as "unlimited" length */
596 if (dest_len == (size_t)-1)
597 dest_len = sizeof(pstring);
599 if (flags & STR_UPPER) {
600 pstrcpy(tmpbuf, src);
605 if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII))
608 return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len);
611 size_t push_ascii_fstring(void *dest, const char *src)
613 return push_ascii(dest, src, sizeof(fstring), STR_TERMINATE);
616 size_t push_ascii_pstring(void *dest, const char *src)
618 return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE);
621 size_t push_ascii_nstring(void *dest, const char *src)
623 return push_ascii(dest, src, sizeof(nstring), STR_TERMINATE);
627 * Copy a string from a dos codepage source to a unix char* destination.
629 * The resulting string in "dest" is always null terminated.
631 * @param flags can have:
633 * <dt>STR_TERMINATE</dt>
634 * <dd>STR_TERMINATE means the string in @p src
635 * is null terminated, and src_len is ignored.</dd>
638 * @param src_len is the length of the source area in bytes.
639 * @returns the number of bytes occupied by the string in @p src.
641 size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
645 if (dest_len == (size_t)-1)
646 dest_len = sizeof(pstring);
648 if (flags & STR_TERMINATE) {
649 if (src_len == (size_t)-1) {
650 src_len = strlen(src) + 1;
652 size_t len = strnlen(src, src_len);
659 ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len);
662 dest[MIN(ret, dest_len-1)] = 0;
669 size_t pull_ascii_pstring(char *dest, const void *src)
671 return pull_ascii(dest, src, sizeof(pstring), -1, STR_TERMINATE);
674 size_t pull_ascii_fstring(char *dest, const void *src)
676 return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE);
679 size_t pull_ascii_nstring(char *dest, const void *src)
681 return pull_ascii(dest, src, sizeof(nstring), sizeof(nstring), STR_TERMINATE);
685 * Copy a string from a char* src to a unicode destination.
687 * @returns the number of bytes occupied by the string in the destination.
689 * @param flags can have:
692 * <dt>STR_TERMINATE <dd>means include the null termination.
693 * <dt>STR_UPPER <dd>means uppercase in the destination.
694 * <dt>STR_NOALIGN <dd>means don't do alignment.
697 * @param dest_len is the maximum length allowed in the
698 * destination. If dest_len is -1 then no maxiumum is used.
700 size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
703 size_t src_len = strlen(src);
705 /* treat a pstring as "unlimited" length */
706 if (dest_len == (size_t)-1)
707 dest_len = sizeof(pstring);
709 if (flags & STR_TERMINATE)
712 if (ucs2_align(base_ptr, dest, flags)) {
714 dest = (void *)((char *)dest + 1);
715 if (dest_len) dest_len--;
719 /* ucs2 is always a multiple of 2 bytes */
722 len += convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len);
724 if (flags & STR_UPPER) {
725 smb_ucs2_t *dest_ucs2 = dest;
727 for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) {
728 smb_ucs2_t v = toupper_w(dest_ucs2[i]);
729 if (v != dest_ucs2[i]) {
740 * Copy a string from a unix char* src to a UCS2 destination,
741 * allocating a buffer using talloc().
743 * @param dest always set at least to NULL
745 * @returns The number of bytes occupied by the string in the destination
746 * or -1 in case of error.
748 size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
750 size_t src_len = strlen(src)+1;
753 return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest);
758 * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer
760 * @param dest always set at least to NULL
762 * @returns The number of bytes occupied by the string in the destination
763 * or -1 in case of error.
766 size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
768 size_t src_len = strlen(src)+1;
771 return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest);
775 Copy a string from a char* src to a UTF-8 destination.
776 Return the number of bytes occupied by the string in the destination
778 STR_TERMINATE means include the null termination
779 STR_UPPER means uppercase in the destination
780 dest_len is the maximum length allowed in the destination. If dest_len
781 is -1 then no maxiumum is used.
784 static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags)
786 size_t src_len = strlen(src);
789 /* treat a pstring as "unlimited" length */
790 if (dest_len == (size_t)-1)
791 dest_len = sizeof(pstring);
793 if (flags & STR_UPPER) {
794 pstrcpy(tmpbuf, src);
799 if (flags & STR_TERMINATE)
802 return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len);
805 size_t push_utf8_fstring(void *dest, const char *src)
807 return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE);
811 * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc
813 * @param dest always set at least to NULL
815 * @returns The number of bytes occupied by the string in the destination
818 size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
820 size_t src_len = strlen(src)+1;
823 return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest);
827 * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer
829 * @param dest always set at least to NULL
831 * @returns The number of bytes occupied by the string in the destination
834 size_t push_utf8_allocate(char **dest, const char *src)
836 size_t src_len = strlen(src)+1;
839 return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest);
843 Copy a string from a ucs2 source to a unix char* destination.
845 STR_TERMINATE means the string in src is null terminated.
846 STR_NOALIGN means don't try to align.
847 if STR_TERMINATE is set then src_len is ignored if it is -1.
848 src_len is the length of the source area in bytes
849 Return the number of bytes occupied by the string in src.
850 The resulting string in "dest" is always null terminated.
853 size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
857 if (dest_len == (size_t)-1)
858 dest_len = sizeof(pstring);
860 if (ucs2_align(base_ptr, src, flags)) {
861 src = (const void *)((const char *)src + 1);
866 if (flags & STR_TERMINATE) {
867 if (src_len == (size_t)-1) {
868 src_len = strlen_w(src)*2 + 2;
870 size_t len = strnlen_w(src, src_len/2);
877 /* ucs2 is always a multiple of 2 bytes */
878 if (src_len != (size_t)-1)
881 ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len);
883 dest[MIN(ret, dest_len-1)] = 0;
890 size_t pull_ucs2_pstring(char *dest, const void *src)
892 return pull_ucs2(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE);
895 size_t pull_ucs2_fstring(char *dest, const void *src)
897 return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE);
901 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc
903 * @param dest always set at least to NULL
905 * @returns The number of bytes occupied by the string in the destination
908 size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src)
910 size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
912 return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest);
916 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer
918 * @param dest always set at least to NULL
920 * @returns The number of bytes occupied by the string in the destination
923 size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src)
925 size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
927 return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest);
931 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc
933 * @param dest always set at least to NULL
935 * @returns The number of bytes occupied by the string in the destination
938 size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
940 size_t src_len = strlen(src)+1;
942 return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest);
946 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer
948 * @param dest always set at least to NULL
950 * @returns The number of bytes occupied by the string in the destination
953 size_t pull_utf8_allocate(void **dest, const char *src)
955 size_t src_len = strlen(src)+1;
957 return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, dest);
961 Copy a string from a char* src to a unicode or ascii
962 dos codepage destination choosing unicode or ascii based on the
963 flags in the SMB buffer starting at base_ptr.
964 Return the number of bytes occupied by the string in the destination.
966 STR_TERMINATE means include the null termination.
967 STR_UPPER means uppercase in the destination.
968 STR_ASCII use ascii even with unicode packet.
969 STR_NOALIGN means don't do alignment.
970 dest_len is the maximum length allowed in the destination. If dest_len
971 is -1 then no maxiumum is used.
974 size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
977 /* We really need to zero fill here, not clobber
978 * region, as we want to ensure that valgrind thinks
979 * all of the outgoing buffer has been written to
980 * so a send() or write() won't trap an error.
984 if (dest_len != (size_t)-1)
985 clobber_region(function, line, dest, dest_len);
987 if (dest_len != (size_t)-1)
988 memset(dest, '\0', dest_len);
992 if (!(flags & STR_ASCII) && \
993 ((flags & STR_UNICODE || \
994 (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {
995 return push_ucs2(base_ptr, dest, src, dest_len, flags);
997 return push_ascii(dest, src, dest_len, flags);
1002 Copy a string from a unicode or ascii source (depending on
1003 the packet flags) to a char* destination.
1005 STR_TERMINATE means the string in src is null terminated.
1006 STR_UNICODE means to force as unicode.
1007 STR_ASCII use ascii even with unicode packet.
1008 STR_NOALIGN means don't do alignment.
1009 if STR_TERMINATE is set then src_len is ignored is it is -1
1010 src_len is the length of the source area in bytes.
1011 Return the number of bytes occupied by the string in src.
1012 The resulting string in "dest" is always null terminated.
1015 size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
1018 if (dest_len != (size_t)-1)
1019 clobber_region(function, line, dest, dest_len);
1022 if (!(flags & STR_ASCII) && \
1023 ((flags & STR_UNICODE || \
1024 (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {
1025 return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags);
1027 return pull_ascii(dest, src, dest_len, src_len, flags);
1030 size_t align_string(const void *base_ptr, const char *p, int flags)
1032 if (!(flags & STR_ASCII) && \
1033 ((flags & STR_UNICODE || \
1034 (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {
1035 return ucs2_align(base_ptr, p, flags);