summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-02-10 22:30:47 +0000
committerLuke Leighton <lkcl@samba.org>1999-02-10 22:30:47 +0000
commit8b6b6b57b54aeafb915cf99e5610941ee1d464b8 (patch)
treeb015714e324e3ff11558942a540e2cd587b32fb1
parent7a65924133431a45cf3b80f06b741f17d4f729c1 (diff)
downloadsamba-8b6b6b57b54aeafb915cf99e5610941ee1d464b8.tar.gz
samba-8b6b6b57b54aeafb915cf99e5610941ee1d464b8.tar.bz2
samba-8b6b6b57b54aeafb915cf99e5610941ee1d464b8.zip
use jeremy's versions of the UNICODE routines.
(This used to be commit c5109ff782be8774db47a92b48ca6335ec8d6065)
-rw-r--r--source3/include/proto.h6
-rw-r--r--source3/lib/util_unistr.c88
-rw-r--r--source3/rpc_server/srv_pipe.c6
-rw-r--r--source3/smbd/chgpasswd.c2
-rw-r--r--source3/utils/torture.c4
5 files changed, 59 insertions, 47 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 2ed35ee0af..f649b40332 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -566,13 +566,13 @@ void split_at_last_component(char *path, char *front, char sep, char *back);
int PutUniCode(char *dst,char *src);
char *skip_unicode_string(char *buf,int n);
-char *unistrn2(char *buf, int len);
-char *unistr2(uint16 *buf);
+char *unistrn2(uint16 *src, int len);
+char *unistr2(uint16 *src);
char *unistr2_to_str(UNISTR2 *str);
uint32 buffer2_to_uint32(BUFFER2 *str);
char *buffer2_to_str(BUFFER2 *str);
char *buffer2_to_multistr(BUFFER2 *str);
-int struni2(char *p, const char *buf);
+int struni2(char *dst, const char *src);
char *unistr(char *buf);
int unistrcpy(char *dst, char *src);
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 50bb73f4fb..5e73fe6ada 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -21,25 +21,31 @@
#include "includes.h"
+#ifndef MAXUNI
+#define MAXUNI 1024
+#endif
+
/*******************************************************************
-write a string in unicoode format
+write a string in (little-endian) unicoode format
********************************************************************/
+
int PutUniCode(char *dst,char *src)
{
int ret = 0;
while (*src) {
- dst[ret++] = src[0];
- dst[ret++] = 0;
+ SSVAL(dst,ret,(*src) & 0xFF);
+ ret += 2;
src++;
}
- dst[ret++]=0;
- dst[ret++]=0;
+ SSVAL(dst,ret,0);
+ ret += 2;
return(ret);
}
/*******************************************************************
skip past some unicode strings in a buffer
********************************************************************/
+
char *skip_unicode_string(char *buf,int n)
{
while (n--)
@@ -52,11 +58,11 @@ char *skip_unicode_string(char *buf,int n)
}
/*******************************************************************
-Return a ascii version of a unicode string
+Return a ascii version of a little-endian unicode string.
Hack alert: uses fixed buffer(s) and only handles ascii strings
********************************************************************/
-#define MAXUNI 1024
-char *unistrn2(char *buf, int len)
+
+char *unistrn2(uint16 *src, int len)
{
static char lbufs[8][MAXUNI];
static int nexti;
@@ -65,9 +71,9 @@ char *unistrn2(char *buf, int len)
nexti = (nexti+1)%8;
- for (p = lbuf; *buf && p-lbuf < MAXUNI-2 && len > 0; len--, p++, buf+=2)
+ for (p = lbuf; *src && p-lbuf < MAXUNI-2 && len > 0; len--, src++)
{
- SSVAL(p, 0, *buf);
+ *p++ = (*src & 0xff);
}
*p = 0;
@@ -76,21 +82,22 @@ char *unistrn2(char *buf, int len)
static char lbufs[8][MAXUNI];
static int nexti;
+
/*******************************************************************
-Return a ascii version of a unicode string
+Return a ascii version of a little-endian unicode string.
Hack alert: uses fixed buffer(s) and only handles ascii strings
********************************************************************/
-#define MAXUNI 1024
-char *unistr2(uint16 *buf)
+
+char *unistr2(uint16 *src)
{
char *lbuf = lbufs[nexti];
char *p;
nexti = (nexti+1)%8;
- for (p = lbuf; *buf && p-lbuf < MAXUNI-2; p++, buf++)
+ for (p = lbuf; *src && p-lbuf < MAXUNI-2; p++, src++)
{
- *p = *buf;
+ *p = (*src & 0xff);
}
*p = 0;
@@ -98,20 +105,21 @@ char *unistr2(uint16 *buf)
}
/*******************************************************************
-Return a ascii version of a unicode string
+Return a ascii version of a little-endian unicode string
********************************************************************/
+
char *unistr2_to_str(UNISTR2 *str)
{
char *lbuf = lbufs[nexti];
char *p;
- uint16 *buf = str->buffer;
+ uint16 *src = str->buffer;
int max_size = MIN(sizeof(str->buffer)-2, str->uni_str_len);
nexti = (nexti+1)%8;
- for (p = lbuf; *buf && p-lbuf < max_size; p++, buf++)
+ for (p = lbuf; *src && p-lbuf < max_size; p++, src++)
{
- *p = *buf;
+ *p = (*src & 0xff);
}
*p = 0;
@@ -121,6 +129,7 @@ char *unistr2_to_str(UNISTR2 *str)
/*******************************************************************
Return a number stored in a buffer
********************************************************************/
+
uint32 buffer2_to_uint32(BUFFER2 *str)
{
if (str->buf_len == 4)
@@ -136,18 +145,19 @@ uint32 buffer2_to_uint32(BUFFER2 *str)
/*******************************************************************
Return a ascii version of a NOTunicode string
********************************************************************/
+
char *buffer2_to_str(BUFFER2 *str)
{
char *lbuf = lbufs[nexti];
char *p;
- uint16 *buf = str->buffer;
+ uint16 *src = str->buffer;
int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2);
nexti = (nexti+1)%8;
- for (p = lbuf; *buf && p-lbuf < max_size; p++, buf++)
+ for (p = lbuf; *src && p-lbuf < max_size; p++, src++)
{
- *p = *buf;
+ *p = (*src & 0xff);
}
*p = 0;
@@ -157,24 +167,25 @@ char *buffer2_to_str(BUFFER2 *str)
/*******************************************************************
Return a ascii version of a NOTunicode string
********************************************************************/
+
char *buffer2_to_multistr(BUFFER2 *str)
{
char *lbuf = lbufs[nexti];
char *p;
- uint16 *buf = str->buffer;
+ uint16 *src = str->buffer;
int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2);
nexti = (nexti+1)%8;
- for (p = lbuf; p-lbuf < max_size; p++, buf++)
+ for (p = lbuf; p-lbuf < max_size; p++, src++)
{
- if (*buf == 0)
+ if (*src == 0)
{
*p = ' ';
}
else
{
- *p = *buf;
+ *p = (*src & 0xff);
}
}
@@ -185,34 +196,35 @@ char *buffer2_to_multistr(BUFFER2 *str)
/*******************************************************************
create a null-terminated unicode string from a null-terminated ascii string.
return number of unicode chars copied, excluding the null character.
-
only handles ascii strings
+Unicode strings created are in little-endian format.
********************************************************************/
-#define MAXUNI 1024
-int struni2(char *p, const char *buf)
+
+int struni2(char *dst, const char *src)
{
- int len = 0;
+ size_t len = 0;
- if (p == NULL) return 0;
+ if (dst == NULL)
+ return 0;
- if (buf != NULL)
+ if (src != NULL)
{
- for (; *buf && len < MAXUNI-2; len++, p += 2, buf++)
+ for (; *src && len < MAXUNI-2; len++, dst +=2, src++)
{
- SSVAL(p, 0, *buf);
+ SSVAL(dst,0,(*src) & 0xFF);
}
}
- *p = 0;
+ SSVAL(dst,0,0);
return len;
}
/*******************************************************************
-Return a ascii version of a unicode string
+Return a ascii version of a little-endian unicode string.
Hack alert: uses fixed buffer(s) and only handles ascii strings
********************************************************************/
-#define MAXUNI 1024
+
char *unistr(char *buf)
{
char *lbuf = lbufs[nexti];
@@ -232,6 +244,7 @@ char *unistr(char *buf)
/*******************************************************************
strcpy for unicode strings. returns length (in num of wide chars)
********************************************************************/
+
int unistrcpy(char *dst, char *src)
{
int num_wchars = 0;
@@ -247,4 +260,3 @@ int unistrcpy(char *dst, char *src)
return num_wchars;
}
-
diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c
index 5908fe06b5..f8d882cd0c 100644
--- a/source3/rpc_server/srv_pipe.c
+++ b/source3/rpc_server/srv_pipe.c
@@ -225,9 +225,9 @@ static BOOL api_pipe_ntlmssp_verify(pipes_struct *p)
if (IS_BITS_SET_ALL(p->ntlmssp_chal.neg_flags, NTLMSSP_NEGOTIATE_UNICODE))
{
- fstrcpy(p->user_name, unistrn2(p->ntlmssp_resp.user , p->ntlmssp_resp.hdr_usr .str_str_len/2));
- fstrcpy(p->domain , unistrn2(p->ntlmssp_resp.domain, p->ntlmssp_resp.hdr_domain.str_str_len/2));
- fstrcpy(p->wks , unistrn2(p->ntlmssp_resp.wks , p->ntlmssp_resp.hdr_wks .str_str_len/2));
+ fstrcpy(p->user_name, unistrn2((uint16*)p->ntlmssp_resp.user , p->ntlmssp_resp.hdr_usr .str_str_len/2));
+ fstrcpy(p->domain , unistrn2((uint16*)p->ntlmssp_resp.domain, p->ntlmssp_resp.hdr_domain.str_str_len/2));
+ fstrcpy(p->wks , unistrn2((uint16*)p->ntlmssp_resp.wks , p->ntlmssp_resp.hdr_wks .str_str_len/2));
}
else
{
diff --git a/source3/smbd/chgpasswd.c b/source3/smbd/chgpasswd.c
index a2e75ecc43..9791d3a38e 100644
--- a/source3/smbd/chgpasswd.c
+++ b/source3/smbd/chgpasswd.c
@@ -693,7 +693,7 @@ BOOL check_oem_password(char *user,
int uni_pw_len = new_pw_len;
char *pw;
new_pw_len /= 2;
- pw = unistrn2(&lmdata[512-uni_pw_len], new_pw_len);
+ pw = unistrn2((uint16*)(&lmdata[512-uni_pw_len]), new_pw_len);
memcpy(new_passwd, pw, new_pw_len+1);
}
else
diff --git a/source3/utils/torture.c b/source3/utils/torture.c
index fb09f515cf..be77c48cfe 100644
--- a/source3/utils/torture.c
+++ b/source3/utils/torture.c
@@ -1167,9 +1167,9 @@ static void create_procs(int nprocs, int numops, void (*fn)(int ))
printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n",
host, share, username, myname, nprocs, numops);
- create_procs(nprocs, numops, run_connection);
-/*
create_procs(nprocs, numops, run_randomipc);
+/*
+ create_procs(nprocs, numops, run_connection);
run_fdpasstest();
run_locktest1();