summaryrefslogtreecommitdiffstats
path: root/source/libsmb/nmblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/libsmb/nmblib.c')
-rw-r--r--source/libsmb/nmblib.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/source/libsmb/nmblib.c b/source/libsmb/nmblib.c
index ba0d8cee5de..95d124c0208 100644
--- a/source/libsmb/nmblib.c
+++ b/source/libsmb/nmblib.c
@@ -1,5 +1,6 @@
/*
- Unix SMB/CIFS implementation.
+ Unix SMB/Netbios implementation.
+ Version 1.9.
NBT netbios library routines
Copyright (C) Andrew Tridgell 1994-1998
@@ -298,7 +299,7 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
pstrcpy(&buf[offset+1],name->scope);
p = &buf[offset+1];
- while ((p = strchr_m(p,'.'))) {
+ while ((p = strchr(p,'.'))) {
buf[offset] = PTR_DIFF(p,&buf[offset+1]);
offset += (buf[offset] + 1);
p = &buf[offset+1];
@@ -784,8 +785,10 @@ static int build_dgram(char *buf,struct packet_struct *p)
/* put in the header */
ubuf[0] = dgram->header.msg_type;
ubuf[1] = (((int)dgram->header.flags.node_type)<<2);
- if (dgram->header.flags.more) ubuf[1] |= 1;
- if (dgram->header.flags.first) ubuf[1] |= 2;
+ if (dgram->header.flags.more)
+ ubuf[1] |= 1;
+ if (dgram->header.flags.first)
+ ubuf[1] |= 2;
RSSVAL(ubuf,2,dgram->header.dgm_id);
putip(ubuf+4,(char *)&dgram->header.source_ip);
RSSVAL(ubuf,8,dgram->header.source_port);
@@ -795,7 +798,7 @@ static int build_dgram(char *buf,struct packet_struct *p)
if (dgram->header.msg_type == 0x10 ||
dgram->header.msg_type == 0x11 ||
- dgram->header.msg_type == 0x12) {
+ dgram->header.msg_type == 0x12) {
offset += put_nmb_name((char *)ubuf,offset,&dgram->source_name);
offset += put_nmb_name((char *)ubuf,offset,&dgram->dest_name);
}
@@ -820,7 +823,9 @@ void make_nmb_name( struct nmb_name *n, const char *name, int type)
{
extern pstring global_scope;
memset( (char *)n, '\0', sizeof(struct nmb_name) );
- push_ascii(n->name, name, 16, STR_TERMINATE|STR_UPPER);
+ StrnCpy( n->name, name, 15 );
+ unix_to_dos(n->name);
+ strupper( n->name );
n->name_type = (unsigned int)type & 0xFF;
StrnCpy( n->scope, global_scope, 63 );
strupper( n->scope );
@@ -1045,7 +1050,7 @@ BOOL match_mailslot_name(struct packet_struct *p, char *mailslot_name)
/****************************************************************************
return the number of bits that match between two 4 character buffers
***************************************************************************/
-int matching_quad_bits(uchar *p1, uchar *p2)
+static int matching_bits(uchar *p1, uchar *p2)
{
int i, j, ret = 0;
for (i=0; i<4; i++) {
@@ -1071,7 +1076,7 @@ compare two query reply records
***************************************************************************/
static int name_query_comp(uchar *p1, uchar *p2)
{
- return matching_quad_bits(p2+2, sort_ip) - matching_quad_bits(p1+2, sort_ip);
+ return matching_bits(p2+2, sort_ip) - matching_bits(p1+2, sort_ip);
}
/****************************************************************************
@@ -1114,7 +1119,11 @@ char *dns_to_netbios_name(char *dns_name)
netbios name up to and including the '.' this even applies, by
mistake, to workgroup (domain) names, which is _really_ daft.
*/
- for (i = 15; i >= 0; i--)
+ /*
+ * We need to go up, not down, to avoid netbios names like
+ * fred.xyz being produced from fred.xyz.someco.com.
+ */
+ for (i = 0; i < 15; i++)
{
if (netbios_name[i] == '.')
{