summaryrefslogtreecommitdiff
path: root/source3/lib/charcnv.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-03-13 00:28:53 +0000
committerJeremy Allison <jra@samba.org>2004-03-13 00:28:53 +0000
commitfd2d4f87d440f24df0adc4cc29f22051536b0dee (patch)
tree1013336177f8163a9a62571658bac3737f64c0a3 /source3/lib/charcnv.c
parent220d663b744107e03a278b564f4e00712a6fcffe (diff)
downloadsamba-fd2d4f87d440f24df0adc4cc29f22051536b0dee.tar.gz
First part of patch from moriyama@miraclelinux.com (MORIYAMA Masayuki) to
fix up netbios names with mb strings. Includes reformat of libsmb/nmblib.c so it's readable. Jeremy. (This used to be commit 966e49a48c352563cdd7f75fe2768f2d6612ec7e)
Diffstat (limited to 'source3/lib/charcnv.c')
-rw-r--r--source3/lib/charcnv.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index cab81fccc58..38bb239a12c 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -823,9 +823,37 @@ size_t push_ascii_pstring(void *dest, const char *src)
return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE);
}
+/********************************************************************
+ Push an nstring - ensure null terminated. Written by
+ moriyama@miraclelinux.com (MORIYAMA Masayuki).
+********************************************************************/
+
size_t push_ascii_nstring(void *dest, const char *src)
{
- return push_ascii(dest, src, sizeof(nstring), STR_TERMINATE);
+ size_t i, buffer_len, dest_len;
+ smb_ucs2_t *buffer;
+
+ buffer_len = push_ucs2_allocate(&buffer, src);
+ if (buffer_len == (size_t)-1) {
+ smb_panic("failed to create UCS2 buffer");
+ }
+
+ dest_len = 0;
+ for (i = 0; i < buffer_len; i++) {
+ unsigned char mb[10];
+ /* Convert one smb_ucs2_t character at a time. */
+ size_t mb_len = convert_string(CH_UCS2, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False);
+ if ((mb_len != (size_t)-1) && (dest_len + mb_len <= MAX_NETBIOSNAME_LEN - 1)) {
+ memcpy((char *)dest + dest_len, mb, mb_len);
+ dest_len += mb_len;
+ } else {
+ break;
+ }
+ }
+ ((char *)dest)[dest_len] = '\0';
+
+ SAFE_FREE(buffer);
+ return dest_len;
}
/**