summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-03-13 02:16:21 +0000
committerJeremy Allison <jra@samba.org>2004-03-13 02:16:21 +0000
commit6b9dbbcd249360fb9acd61d6900baccf621c9cce (patch)
tree612e870056d4060da62d02ed05f38f1d99cd620d /source3/libsmb
parentfd2d4f87d440f24df0adc4cc29f22051536b0dee (diff)
downloadsamba-6b9dbbcd249360fb9acd61d6900baccf621c9cce.tar.gz
samba-6b9dbbcd249360fb9acd61d6900baccf621c9cce.tar.bz2
samba-6b9dbbcd249360fb9acd61d6900baccf621c9cce.zip
Modified fix for bugid #784. Based on a patch from moriyama@miraclelinux.com (MORIYAMA Masayuki).
Don't use nstrings to hold workgroup and netbios names. The problem with them is that MB netbios and workgroup names in unix charset (particularly utf8) may be up to 3x bigger than the name when represented in dos charset (ie. cp932). So go back to using fstrings for these but translate into nstrings (ie. 16 byte length values) for transport on the wire. Jeremy. (This used to be commit b4ea493599ab414f7828b83f40a5a8b43479ff64)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/libsmbclient.c2
-rw-r--r--source3/libsmb/namequery.c4
-rw-r--r--source3/libsmb/nmblib.c28
3 files changed, 20 insertions, 14 deletions
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index 37e794478d..35e8a9786b 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -1787,7 +1787,7 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
if (!is_ipaddress(server) && /* Not an IP addr so check next */
(resolve_name(server, &rem_ip, 0x1d) || /* Found LMB */
resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */
- pstring buserver;
+ fstring buserver;
dir->dir_type = SMBC_SERVER;
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index b6d1f8bda2..b9bc4e1166 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -163,7 +163,7 @@ struct node_status *node_status_query(int fd,struct nmb_name *name,
a servers name given its IP. Return the matched name in *name.
**************************************************************************/
-BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr to_ip, char *name)
+BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr to_ip, fstring name)
{
struct node_status *status = NULL;
struct nmb_name nname;
@@ -202,7 +202,7 @@ BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr t
if (i == count)
goto done;
- pull_ascii_nstring(name, status[i].name);
+ pull_ascii_nstring(name, sizeof(fstring), status[i].name);
/* Store the result in the cache. */
/* but don't store an entry for 0x1c names here. Here we have
diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index cbe495cd95..bc2cca0e0e 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -285,7 +285,7 @@ static void put_name(char *dest, const char *name, int pad, unsigned int name_ty
static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
{
int ret,m;
- fstring buf1;
+ nstring buf1;
char *p;
if (strcmp(name->name,"*") == 0) {
@@ -1230,17 +1230,24 @@ static int name_interpret(char *in, fstring name)
int name_mangle( char *In, char *Out, char name_type )
{
int i;
- int c;
int len;
- char buf[20];
+ nstring buf;
char *p = Out;
/* Safely copy the input string, In, into buf[]. */
- memset( buf, 0, 20 );
- if (strcmp(In,"*") == 0) {
- buf[0] = '*';
- } else {
- slprintf( buf, sizeof(buf) - 1, "%-15.15s%c", In, name_type );
+ if (strcmp(In,"*") == 0)
+ put_name(buf, "*", '\0', 0x00);
+ else {
+ /* We use an fstring here as mb dos names can expend x3 when
+ going to utf8. */
+ fstring buf_unix;
+ nstring buf_dos;
+
+ pull_ascii_fstring(buf_unix, In);
+ strupper_m(buf_unix);
+
+ push_ascii_nstring(buf_dos, buf_unix);
+ put_name(buf, buf_dos, ' ', name_type);
}
/* Place the length of the first field into the output buffer. */
@@ -1249,9 +1256,8 @@ int name_mangle( char *In, char *Out, char name_type )
/* Now convert the name to the rfc1001/1002 format. */
for( i = 0; i < MAX_NETBIOSNAME_LEN; i++ ) {
- c = toupper( buf[i] );
- p[i*2] = ( (c >> 4) & 0x000F ) + 'A';
- p[(i*2)+1] = (c & 0x000F) + 'A';
+ p[i*2] = ( (buf[i] >> 4) & 0x000F ) + 'A';
+ p[(i*2)+1] = (buf[i] & 0x000F) + 'A';
}
p += 32;
p[0] = '\0';