[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-1010-g602059a

Volker Lendecke vlendec at samba.org
Sun Apr 12 12:53:08 GMT 2009


The branch, master has been updated
       via  602059a6ab8c4939dd453566415321b2b85706f4 (commit)
       via  b742b4547e9a5adb4c235995751bae5649be3031 (commit)
       via  dcda3ab8ca5447b04da7a95cc82965265687a8a5 (commit)
       via  c344ad30435feb235b2423a6f066ab5eba30d2fb (commit)
       via  a36472dd384e54374cc151cd4159f3786b4ec02b (commit)
      from  e9569ae9250ac571c63fbb450709778a247e9ca3 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 602059a6ab8c4939dd453566415321b2b85706f4
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Apr 12 12:52:42 2009 +0200

    Fix a bug in smbclient not sending the correct called name
    
    Jeremy, I think the ability to say
    
    smbclient //foo/bar -I <ip-address> -p 139
    
    making the called name to "foo" got lost with 3d2d0203. Was this removed
    deliberately? If so, please revert this patch. If not, please merge
    appropriately.
    
    Thanks,
    
    Volker

commit b742b4547e9a5adb4c235995751bae5649be3031
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Apr 12 14:31:53 2009 +0200

    Add "netbios retarget"
    
    This is fun -- XP still does this :-)
    
    netbios retarget : foo = 192.168.234.10:1139
    
    and if you connect to port 139 name foo, XP will happily do SMB over 1139

commit dcda3ab8ca5447b04da7a95cc82965265687a8a5
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Apr 12 14:25:02 2009 +0200

    Reactivate get_socket_port

commit c344ad30435feb235b2423a6f066ab5eba30d2fb
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Apr 12 14:05:58 2009 +0200

    write_data already guarantees everything was written

commit a36472dd384e54374cc151cd4159f3786b4ec02b
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Apr 12 11:59:18 2009 +0200

    Extract and print the server name type the client connects to

-----------------------------------------------------------------------

Summary of changes:
 source3/include/proto.h |    1 +
 source3/lib/util_sock.c |    5 +--
 source3/libsmb/clidfs.c |    6 ++-
 source3/smbd/process.c  |   15 +++----
 source3/smbd/reply.c    |  107 +++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 113 insertions(+), 21 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 678f087..cc44242 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1358,6 +1358,7 @@ char *print_canonical_sockaddr(TALLOC_CTX *ctx,
 			const struct sockaddr_storage *pss);
 void set_sockaddr_port(struct sockaddr *psa, uint16_t port);
 const char *client_name(int fd);
+int get_socket_port(int fd);
 const char *client_addr(int fd, char *addr, size_t addrlen);
 const char *client_socket_addr(int fd, char *addr, size_t addr_len);
 int client_socket_port(int fd);
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 5f9d476..cbd7b98 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -208,13 +208,11 @@ static const char *get_socket_addr(int fd, char *addr_buf, size_t addr_len)
 	return print_sockaddr_len(addr_buf, addr_len, (struct sockaddr *)&sa, length);
 }
 
-#if 0
-/* Not currently used. JRA. */
 /****************************************************************************
  Return the port number we've bound to on a socket.
 ****************************************************************************/
 
-static int get_socket_port(int fd)
+int get_socket_port(int fd)
 {
 	struct sockaddr_storage sa;
 	socklen_t length = sizeof(sa);
@@ -239,7 +237,6 @@ static int get_socket_port(int fd)
 	}
 	return -1;
 }
-#endif
 
 const char *client_name(int fd)
 {
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index 430807e..98b96cf 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -94,6 +94,7 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
 {
 	struct cli_state *c = NULL;
 	struct nmb_name called, calling;
+	const char *called_str;
 	const char *server_n;
 	struct sockaddr_storage ss;
 	char *servicename;
@@ -111,6 +112,7 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
 	sharename = servicename;
 	if (*sharename == '\\') {
 		sharename += 2;
+		called_str = sharename;
 		if (server == NULL) {
 			server = sharename;
 		}
@@ -120,6 +122,8 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
 		}
 		*sharename = 0;
 		sharename++;
+	} else {
+		called_str = server;
 	}
 
 	server_n = server;
@@ -127,7 +131,7 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
 	zero_sockaddr(&ss);
 
 	make_nmb_name(&calling, global_myname(), 0x0);
-	make_nmb_name(&called , server, name_type);
+	make_nmb_name(&called , called_str, name_type);
 
  again:
 	zero_sockaddr(&ss);
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 65778ab..7605ad7 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -59,15 +59,12 @@ bool srv_send_smb(int fd, char *buffer,
 
 	len = smb_len(buf_out) + 4;
 
-	while (nwritten < len) {
-		ret = write_data(fd,buf_out+nwritten,len - nwritten);
-		if (ret <= 0) {
-			DEBUG(0,("Error writing %d bytes to client. %d. (%s)\n",
-				(int)len,(int)ret, strerror(errno) ));
-			srv_free_enc_buffer(buf_out);
-			goto out;
-		}
-		nwritten += ret;
+	ret = write_data(fd,buf_out+nwritten,len - nwritten);
+	if (ret <= 0) {
+		DEBUG(0,("Error writing %d bytes to client. %d. (%s)\n",
+			 (int)len,(int)ret, strerror(errno) ));
+		srv_free_enc_buffer(buf_out);
+		goto out;
 	}
 
 	SMB_PERFCOUNT_SET_MSGLEN_OUT(pcd, len);
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 3f9d5c5..e1364f2 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -407,6 +407,95 @@ bool fsp_belongs_conn(connection_struct *conn, struct smb_request *req,
 	return False;
 }
 
+static bool netbios_session_retarget(const char *name, int name_type)
+{
+	char *trim_name;
+	char *trim_name_type;
+	const char *retarget_parm;
+	char *retarget;
+	char *p;
+	int retarget_type = 0x20;
+	int retarget_port = 139;
+	struct sockaddr_storage retarget_addr;
+	struct sockaddr_in *in_addr;
+	bool ret = false;
+	uint8_t outbuf[10];
+
+	if (get_socket_port(smbd_server_fd()) != 139) {
+		return false;
+	}
+
+	trim_name = talloc_strdup(talloc_tos(), name);
+	if (trim_name == NULL) {
+		goto fail;
+	}
+	trim_char(trim_name, ' ', ' ');
+
+	trim_name_type = talloc_asprintf(trim_name, "%s#%2.2x", trim_name,
+					 name_type);
+	if (trim_name_type == NULL) {
+		goto fail;
+	}
+
+	retarget_parm = lp_parm_const_string(-1, "netbios retarget",
+					     trim_name_type, NULL);
+	if (retarget_parm == NULL) {
+		retarget_parm = lp_parm_const_string(-1, "netbios retarget",
+						     trim_name, NULL);
+	}
+	if (retarget_parm == NULL) {
+		goto fail;
+	}
+
+	retarget = talloc_strdup(trim_name, retarget_parm);
+	if (retarget == NULL) {
+		goto fail;
+	}
+
+	DEBUG(10, ("retargeting %s to %s\n", trim_name_type, retarget));
+
+	p = strchr(retarget, ':');
+	if (p != NULL) {
+		*p++ = '\0';
+		retarget_port = atoi(p);
+	}
+
+	p = strchr_m(retarget, '#');
+	if (p != NULL) {
+		*p++ = '\0';
+		sscanf(p, "%x", &retarget_type);
+	}
+
+	ret = resolve_name(retarget, &retarget_addr, retarget_type);
+	if (!ret) {
+		DEBUG(10, ("could not resolve %s\n", retarget));
+		goto fail;
+	}
+
+	if (retarget_addr.ss_family != AF_INET) {
+		DEBUG(10, ("Retarget target not an IPv4 addr\n"));
+		goto fail;
+	}
+
+	in_addr = (struct sockaddr_in *)&retarget_addr;
+
+	_smb_setlen(outbuf, 6);
+	SCVAL(outbuf, 0, 0x84);
+	*(uint32_t *)(outbuf+4) = in_addr->sin_addr.s_addr;
+	*(uint16_t *)(outbuf+8) = htons(retarget_port);
+
+	if (!srv_send_smb(smbd_server_fd(), (char *)outbuf, false, 0, false,
+			  NULL)) {
+		exit_server_cleanly("netbios_session_regarget: srv_send_smb "
+				    "failed.");
+	}
+
+	ret = true;
+ fail:
+	TALLOC_FREE(trim_name);
+	return ret;
+}
+
 /****************************************************************************
  Reply to a (netbios-level) special message.
 ****************************************************************************/
@@ -416,7 +505,7 @@ void reply_special(char *inbuf)
 	int msg_type = CVAL(inbuf,0);
 	int msg_flags = CVAL(inbuf,1);
 	fstring name1,name2;
-	char name_type = 0;
+	char name_type1, name_type2;
 
 	/*
 	 * We only really use 4 bytes of the outbuf, but for the smb_setlen
@@ -445,19 +534,23 @@ void reply_special(char *inbuf)
 			DEBUG(0,("Invalid name length in session request\n"));
 			return;
 		}
-		name_extract(inbuf,4,name1);
-		name_type = name_extract(inbuf,4 + name_len(inbuf + 4),name2);
-		DEBUG(2,("netbios connect: name1=%s name2=%s\n",
-			 name1,name2));      
+		name_type1 = name_extract(inbuf,4,name1);
+		name_type2 = name_extract(inbuf,4 + name_len(inbuf + 4),name2);
+		DEBUG(2,("netbios connect: name1=%s0x%x name2=%s0x%x\n",
+			 name1, name_type1, name2, name_type2));
+
+		if (netbios_session_retarget(name1, name_type1)) {
+			exit_server_cleanly("retargeted client");
+		}
 
 		set_local_machine_name(name1, True);
 		set_remote_machine_name(name2, True);
 
 		DEBUG(2,("netbios connect: local=%s remote=%s, name type = %x\n",
 			 get_local_machine_name(), get_remote_machine_name(),
-			 name_type));
+			 name_type2));
 
-		if (name_type == 'R') {
+		if (name_type2 == 'R') {
 			/* We are being asked for a pathworks session --- 
 			   no thanks! */
 			SCVAL(outbuf, 0,0x83);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list