Index: source/libsmb/nmblib.c =================================================================== RCS file: /cvsroot/samba/source/libsmb/nmblib.c,v retrieving revision 1.68.2.12 diff -u -p -r1.68.2.12 nmblib.c --- source/libsmb/nmblib.c 27 Aug 2003 01:25:00 -0000 1.68.2.12 +++ source/libsmb/nmblib.c 17 Feb 2004 09:09:11 -0000 @@ -256,6 +256,17 @@ static int parse_nmb_name(char *inbuf,in return(ret); } +/**************************************************************************** +put a netbios name, padding(s) and a name type +****************************************************************************/ +static void put_name(char *dest, const char *name, int pad, unsigned int name_type) +{ + size_t len = strlen(name); + + memcpy(dest, name, (len <= 15) ? len : 15); + memset(dest + len, pad, 15 - len); + dest[15] = name_type; +} /******************************************************************* put a compressed nmb name into a buffer. return the length of the @@ -268,16 +279,14 @@ static int parse_nmb_name(char *inbuf,in 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) { /* special case for wildcard name */ - memset(buf1,'\0',20); - buf1[0] = '*'; - buf1[15] = name->name_type; + put_name(buf1, "*", '\0', name->name_type); } else { - slprintf(buf1, sizeof(buf1) - 1,"%-15.15s%c",name->name,name->name_type); + put_name(buf1, name->name, ' ', name->name_type); } buf[offset] = 0x20; @@ -1184,15 +1193,14 @@ int name_mangle( char *In, char *Out, ch int i; int c; int len; - char buf[20]; + nstring buf; char *p = Out; /* Safely copy the input string, In, into buf[]. */ - (void)memset( buf, 0, 20 ); if (strcmp(In,"*") == 0) - buf[0] = '*'; + put_name(buf, "*", '\0', 0x00); else - (void)slprintf( buf, sizeof(buf) - 1, "%-15.15s%c", In, name_type ); + put_name(buf, In, ' ', name_type); /* Place the length of the first field into the output buffer. */ p[0] = 32;