summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2003-07-27 02:28:25 +0000
committerAndrew Bartlett <abartlet@samba.org>2003-07-27 02:28:25 +0000
commit455bb6de903ca3950d965b29190c09f116d91889 (patch)
tree997319ee22f82f2d2e1c06c365b71c8f385c48ad
parent422c2467a0d23c91feb5008ac2244b4054c27b43 (diff)
downloadsamba-455bb6de903ca3950d965b29190c09f116d91889.tar.gz
samba-455bb6de903ca3950d965b29190c09f116d91889.tar.bz2
samba-455bb6de903ca3950d965b29190c09f116d91889.zip
Some small fixes to our charset conversion code:
- Treat the NMB names in the 'session request' packet as 'ASCII'. This means that we do not get invalid multibyte from the wire, even if we truncate in the conversion. (Otherwise we panic when we try to strupper_m it). - Remove acnv_uxu2(), as it was duplicated by push_ucs2_allocate() - Remove acnv_dosu2(), as it is not used. - In push_ucs2(), with the STR_UPPER flag, do the case conversion *after* the UCS2 conversion, when it we know that the length can't change. Also faster, as we don't need to do another 2 UCS2 conversions. Andrew Bartlett (This used to be commit 912035af1178424583d0bf887a391a0cac2acd87)
-rw-r--r--source3/lib/charcnv.c120
-rw-r--r--source3/libsmb/nmblib.c12
-rw-r--r--source3/smbd/mangle_hash.c7
3 files changed, 82 insertions, 57 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 5e1951b6e5..8896f0b886 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -319,8 +319,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
size_t size;
smb_ucs2_t *buffer;
- size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen,
- (void **) &buffer);
+ size = push_ucs2_allocate(&buffer, src);
if (size == -1) {
smb_panic("failed to create UCS2 buffer");
}
@@ -334,6 +333,35 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
return size;
}
+/**
+ strdup() a unix string to upper case.
+**/
+
+char *strdup_upper(const char *s)
+{
+ size_t size;
+ smb_ucs2_t *buffer;
+ char *out_buffer;
+
+ size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s)+1,
+ (void **) &buffer);
+ if (size == -1) {
+ return NULL;
+ }
+
+ strupper_w(buffer);
+
+ size = convert_string_allocate(CH_UCS2, CH_UNIX, buffer, size,
+ (void **) &out_buffer);
+ SAFE_FREE(buffer);
+
+ if (size == -1) {
+ return NULL;
+ }
+
+ return out_buffer;
+}
+
size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
{
size_t size;
@@ -353,6 +381,34 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
return size;
}
+/**
+ strdup() a unix string to lower case.
+**/
+
+char *strdup_lower(const char *s)
+{
+ size_t size;
+ smb_ucs2_t *buffer;
+ char *out_buffer;
+
+ size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s),
+ (void **) &buffer);
+ if (size == -1) {
+ return NULL;
+ }
+
+ strlower_w(buffer);
+
+ size = convert_string_allocate(CH_UCS2, CH_UNIX, buffer, size,
+ (void **) &out_buffer);
+ SAFE_FREE(buffer);
+
+ if (size == -1) {
+ return NULL;
+ }
+
+ return out_buffer;
+}
static size_t ucs2_align(const void *base_ptr, const void *p, int flags)
{
@@ -480,18 +536,11 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
{
size_t len=0;
size_t src_len = strlen(src);
- pstring tmpbuf;
/* treat a pstring as "unlimited" length */
if (dest_len == (size_t)-1)
dest_len = sizeof(pstring);
- if (flags & STR_UPPER) {
- pstrcpy(tmpbuf, src);
- strupper_m(tmpbuf);
- src = tmpbuf;
- }
-
if (flags & STR_TERMINATE)
src_len++;
@@ -506,6 +555,18 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
dest_len &= ~1;
len += convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len);
+
+ if (flags & STR_UPPER) {
+ smb_ucs2_t *dest_ucs2 = dest;
+ size_t i;
+ for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) {
+ smb_ucs2_t v = toupper_w(dest_ucs2[i]);
+ if (v != dest_ucs2[i]) {
+ dest_ucs2[i] = v;
+ }
+ }
+ }
+
return len;
}
@@ -809,44 +870,3 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
return 0;
}
-/**
- Convert from unix to ucs2 charset and return the
- allocated and converted string or NULL if an error occurred.
- You must provide a zero terminated string.
- The returning string will be zero terminated.
-**/
-
-smb_ucs2_t *acnv_uxu2(const char *src)
-{
- size_t slen;
- size_t dlen;
- void *dest;
-
- slen = strlen(src) + 1;
- dlen = convert_string_allocate(CH_UNIX, CH_UCS2, src, slen, &dest);
- if (dlen == (size_t)-1)
- return NULL;
- else
- return dest;
-}
-
-/**
- Convert from dos to ucs2 charset and return the
- allocated and converted string or NULL if an error occurred.
- You must provide a zero terminated string.
- The returning string will be zero terminated.
-**/
-
-smb_ucs2_t *acnv_dosu2(const char *src)
-{
- size_t slen;
- size_t dlen;
- void *dest;
-
- slen = strlen(src) + 1;
- dlen = convert_string_allocate(CH_DOS, CH_UCS2, src, slen, &dest);
- if (dlen == (size_t)-1)
- return NULL;
- else
- return dest;
-}
diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index 157a2bb43c..7e97dbf43a 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -1129,12 +1129,14 @@ char *dns_to_netbios_name(char *dns_name)
/****************************************************************************
-interpret the weird netbios "name". Return the name type
+interpret the weird netbios "name" into a unix fstring. Return the name type
****************************************************************************/
-static int name_interpret(char *in,char *out)
+static int name_interpret(char *in, fstring name)
{
int ret;
int len = (*in++) / 2;
+ fstring out_string;
+ char *out = out_string;
*out=0;
@@ -1165,6 +1167,8 @@ static int name_interpret(char *in,char *out)
in += len;
}
#endif
+ pull_ascii(name, out, sizeof(fstring), sizeof(out), STR_TERMINATE);
+
return(ret);
}
@@ -1245,9 +1249,9 @@ static char *name_ptr(char *buf,int ofs)
}
/****************************************************************************
-extract a netbios name from a buf
+extract a netbios name from a buf (into a unix string)
****************************************************************************/
-int name_extract(char *buf,int ofs,char *name)
+int name_extract(char *buf,int ofs, fstring name)
{
char *p = name_ptr(buf,ofs);
int d = PTR_DIFF(p,buf+ofs);
diff --git a/source3/smbd/mangle_hash.c b/source3/smbd/mangle_hash.c
index ac8e425fd3..ac2d7681e8 100644
--- a/source3/smbd/mangle_hash.c
+++ b/source3/smbd/mangle_hash.c
@@ -313,6 +313,7 @@ static BOOL is_8_3(const char *fname, BOOL check_case, BOOL allow_wildcards)
const char *f;
smb_ucs2_t *ucs2name;
NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
+ size_t size;
if (!fname || !*fname)
return False;
@@ -324,9 +325,9 @@ static BOOL is_8_3(const char *fname, BOOL check_case, BOOL allow_wildcards)
if (strlen(f) > 12)
return False;
- ucs2name = acnv_uxu2(f);
- if (!ucs2name) {
- DEBUG(0,("is_8_3: internal error acnv_uxu2() failed!\n"));
+ size = push_ucs2_allocate(&ucs2name, f);
+ if (size == (size_t)-1) {
+ DEBUG(0,("is_8_3: internal error push_ucs2_allocate() failed!\n"));
goto done;
}