1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

use jeremy's versions of the UNICODE routines.

(This used to be commit c5109ff782be8774db47a92b48ca6335ec8d6065)
This commit is contained in:
Luke Leighton 1999-02-10 22:30:47 +00:00
parent 7a65924133
commit 8b6b6b57b5
5 changed files with 59 additions and 47 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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
{

View File

@ -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

View File

@ -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();