svn commit: samba r4927 - in branches/SAMBA_4_0/source: libcli/nbt smb_server

tridge at samba.org tridge at samba.org
Sat Jan 22 05:36:33 GMT 2005


Author: tridge
Date: 2005-01-22 05:36:32 +0000 (Sat, 22 Jan 2005)
New Revision: 4927

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=4927

Log:
parse the NBT session request in the smb server. This gets rid of that
annoying "not parsing session request" message on each SMB connection

Modified:
   branches/SAMBA_4_0/source/libcli/nbt/nbtname.c
   branches/SAMBA_4_0/source/smb_server/reply.c
   branches/SAMBA_4_0/source/smb_server/smb_server.h


Changeset:
Modified: branches/SAMBA_4_0/source/libcli/nbt/nbtname.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/nbt/nbtname.c	2005-01-22 04:09:21 UTC (rev 4926)
+++ branches/SAMBA_4_0/source/libcli/nbt/nbtname.c	2005-01-22 05:36:32 UTC (rev 4927)
@@ -63,7 +63,7 @@
 			/* its a reserved length field */
 			return NT_STATUS_BAD_NETWORK_NAME;
 		}
-		if (*offset + len + 2 >= ndr->data_size) {
+		if (*offset + len + 2 > ndr->data_size) {
 			return NT_STATUS_BAD_NETWORK_NAME;
 		}
 		*component = (uint8_t*)talloc_strndup(ndr, &ndr->data[1 + *offset], len);
@@ -309,7 +309,18 @@
 				    (ndr_push_flags_fn_t)ndr_push_nbt_name);
 }
 
+
 /*
+  pull a nbt name from a blob
+*/
+NTSTATUS nbt_name_from_blob(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, struct nbt_name *name)
+{
+	return ndr_pull_struct_blob(blob, mem_ctx, name, 
+				    (ndr_pull_flags_fn_t)ndr_pull_nbt_name);
+}
+
+
+/*
   choose a name to use when calling a server in a NBT session request.
   we use heuristics to see if the name we have been given is a IP
   address, or a too-long name. If it is then use *SMBSERVER, or a

Modified: branches/SAMBA_4_0/source/smb_server/reply.c
===================================================================
--- branches/SAMBA_4_0/source/smb_server/reply.c	2005-01-22 04:09:21 UTC (rev 4926)
+++ branches/SAMBA_4_0/source/smb_server/reply.c	2005-01-22 05:36:32 UTC (rev 4927)
@@ -25,6 +25,7 @@
 
 #include "includes.h"
 #include "smb_server/smb_server.h"
+#include "libcli/nbt/libnbt.h"
 
 
 /* useful way of catching wct errors with file and line number */
@@ -2370,7 +2371,42 @@
 }
 
 
+/*
+  parse the called/calling names from session request
+*/
+static NTSTATUS parse_session_request(struct smbsrv_request *req)
+{
+	DATA_BLOB blob;
+	NTSTATUS status;
+	
+	blob.data = req->in.buffer + 4;
+	blob.length = ascii_len_n(blob.data, req->in.size - PTR_DIFF(blob.data, req->in.buffer));
+	if (blob.length == 0) return NT_STATUS_BAD_NETWORK_NAME;
 
+	req->smb_conn->negotiate.called_name  = talloc(req->smb_conn, struct nbt_name);
+	req->smb_conn->negotiate.calling_name = talloc(req->smb_conn, struct nbt_name);
+	if (req->smb_conn->negotiate.called_name == NULL ||
+	    req->smb_conn->negotiate.calling_name == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	status = nbt_name_from_blob(req, &blob, req->smb_conn->negotiate.called_name);
+	NT_STATUS_NOT_OK_RETURN(status);
+
+	blob.data += blob.length;
+	blob.length = ascii_len_n(blob.data, req->in.size - PTR_DIFF(blob.data, req->in.buffer));
+	if (blob.length == 0) return NT_STATUS_BAD_NETWORK_NAME;
+
+	status = nbt_name_from_blob(req, &blob, req->smb_conn->negotiate.calling_name);
+	NT_STATUS_NOT_OK_RETURN(status);
+
+	req->smb_conn->negotiate.done_nbt_session = True;
+
+	return NT_STATUS_OK;
+}	
+
+
+
 /****************************************************************************
  Reply to a special message - a SMB packet with non zero NBT message type
 ****************************************************************************/
@@ -2378,7 +2414,7 @@
 {
 	uint8_t msg_type;
 	uint8_t *buf = talloc_zero_array(req, uint8_t, 4);
-	
+
 	msg_type = CVAL(req->in.buffer,0);
 
 	SIVAL(buf, 0, 0);
@@ -2392,13 +2428,11 @@
 		
 		SCVAL(buf,0,0x82);
 		SCVAL(buf,3,0);
-		
-		DEBUG(0,("REWRITE: not parsing netbios names in NBT session request!\n"));
-		/* TODO: store the name for the session setup 'remote
-		   machine' code, as well as smbstatus */
 
-		req->smb_conn->negotiate.done_nbt_session = True;
-		
+		/* we don't check the status - samba always accepts session
+		   requests for any name */
+		parse_session_request(req);
+
 		req->out.buffer = buf;
 		req->out.size = 4;
 		req_send_reply_nosign(req);

Modified: branches/SAMBA_4_0/source/smb_server/smb_server.h
===================================================================
--- branches/SAMBA_4_0/source/smb_server/smb_server.h	2005-01-22 04:09:21 UTC (rev 4926)
+++ branches/SAMBA_4_0/source/smb_server/smb_server.h	2005-01-22 05:36:32 UTC (rev 4927)
@@ -197,6 +197,10 @@
 	
 		/* the timezone we sent to the client */
 		int zone_offset;
+
+		/* NBT names only set when done_nbt_session is true */
+		struct nbt_name *called_name;
+		struct nbt_name *calling_name;
 	} negotiate;
 
 	/* the context associated with open tree connects on a smb socket */



More information about the samba-cvs mailing list