svn commit: samba r1897 - in branches/SAMBA_4_0/source: client libcli libcli/raw torture

tridge at samba.org tridge at samba.org
Wed Aug 18 20:13:09 GMT 2004


Author: tridge
Date: 2004-08-18 20:13:08 +0000 (Wed, 18 Aug 2004)
New Revision: 1897

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=1897&nolog=1

Log:
added a choose_called_name() function that allows us to more sanely
handle connections using the IP as the server name, while not trying
for NBT name resolution on names like "192" and "192.168.1.2".

also removed the ip address argument to smbcli_socket_connect() as it
isn't used and doesn't really make sense.



Modified:
   branches/SAMBA_4_0/source/client/client.c
   branches/SAMBA_4_0/source/client/smbmount.c
   branches/SAMBA_4_0/source/libcli/cliconnect.c
   branches/SAMBA_4_0/source/libcli/nmblib.c
   branches/SAMBA_4_0/source/libcli/raw/clitree.c
   branches/SAMBA_4_0/source/torture/torture.c


Changeset:
Modified: branches/SAMBA_4_0/source/client/client.c
===================================================================
--- branches/SAMBA_4_0/source/client/client.c	2004-08-18 20:07:44 UTC (rev 1896)
+++ branches/SAMBA_4_0/source/client/client.c	2004-08-18 20:13:08 UTC (rev 1897)
@@ -58,8 +58,6 @@
 
 static BOOL translation = False;
 
-static BOOL have_ip;
-
 /* clitar bits insert */
 extern int blocksize;
 extern BOOL tar_inc;
@@ -74,7 +72,7 @@
 static BOOL recurse = False;
 BOOL lowercase = False;
 
-static struct in_addr dest_ip;
+static const char *dest_ip;
 
 #define SEPARATORS " \t\n\r"
 
@@ -2745,7 +2743,6 @@
 	struct smbcli_state *c;
 	struct nmb_name called, calling;
 	const char *server_n;
-	struct in_addr ip;
 	fstring servicename;
 	char *sharename;
 	NTSTATUS status;
@@ -2763,19 +2760,14 @@
 
 	asprintf(&sharename, "\\\\%s\\%s", server, sharename);
 
-	server_n = server;
+	server_n = dest_ip?dest_ip:server;
 	
-	zero_ip(&ip);
-
 	make_nmb_name(&calling, lp_netbios_name(), 0x0);
-	make_nmb_name(&called , server, name_type);
+	choose_called_name(&called, server, name_type);
 
  again:
-	zero_ip(&ip);
-	if (have_ip) ip = dest_ip;
-
 	/* have to open a new connection */
-	if (!(c=smbcli_state_init()) || !smbcli_socket_connect(c, server_n, &ip)) {
+	if (!(c=smbcli_state_init()) || !smbcli_socket_connect(c, server_n)) {
 		d_printf("Connection to %s failed\n", server_n);
 		return NULL;
 	}
@@ -2905,23 +2897,16 @@
 ****************************************************************************/
 static int do_message_op(void)
 {
-	struct in_addr ip;
 	struct nmb_name called, calling;
-	fstring server_name;
-	char name_type_hex[10];
+	const char *server_name;
 
 	make_nmb_name(&calling, lp_netbios_name(), 0x0);
-	make_nmb_name(&called , desthost, name_type);
+	choose_called_name(&called, desthost, name_type);
 
-	fstrcpy(server_name, desthost);
-	snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
-	fstrcat(server_name, name_type_hex);
+	server_name = dest_ip ? dest_ip : desthost;
 
-	zero_ip(&ip);
-	if (have_ip) ip = dest_ip;
-
-	if (!(cli=smbcli_state_init()) || !smbcli_socket_connect(cli, server_name, &ip)) {
-		d_printf("Connection to %s failed\n", desthost);
+	if (!(cli=smbcli_state_init()) || !smbcli_socket_connect(cli, server_name)) {
+		d_printf("Connection to %s failed\n", server_name);
 		return 1;
 	}
 
@@ -3035,12 +3020,7 @@
  			message = True;
  			break;
 		case 'I':
-			{
-				dest_ip = *interpret_addr2(mem_ctx, poptGetOptArg(pc));
-				if (is_zero_ip(dest_ip))
-					exit(1);
-				have_ip = True;
-			}
+			dest_ip = poptGetOptArg(pc);
 			break;
 		case 'E':
 			setup_logging("client", DEBUG_STDERR);

Modified: branches/SAMBA_4_0/source/client/smbmount.c
===================================================================
--- branches/SAMBA_4_0/source/client/smbmount.c	2004-08-18 20:07:44 UTC (rev 1896)
+++ branches/SAMBA_4_0/source/client/smbmount.c	2004-08-18 20:13:08 UTC (rev 1897)
@@ -139,7 +139,7 @@
 	server_n = server;
 
 	make_nmb_name(&calling, my_netbios_name, 0x0);
-	make_nmb_name(&called , server, 0x20);
+	choose_called_name(&called, server, 0x20);
 
  again:
         zero_ip(&ip);

Modified: branches/SAMBA_4_0/source/libcli/cliconnect.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/cliconnect.c	2004-08-18 20:07:44 UTC (rev 1896)
+++ branches/SAMBA_4_0/source/libcli/cliconnect.c	2004-08-18 20:13:08 UTC (rev 1897)
@@ -23,7 +23,7 @@
 /*
   wrapper around smbcli_sock_connect()
 */
-BOOL smbcli_socket_connect(struct smbcli_state *cli, const char *server, struct in_addr *ip)
+BOOL smbcli_socket_connect(struct smbcli_state *cli, const char *server)
 {
 	struct smbcli_socket *sock;
 
@@ -163,7 +163,7 @@
 	}
 
 	status = smbcli_tree_full_connection(&tree, myname, host, 0, sharename, devtype,
-					  username, domain, password);
+					     username, domain, password);
 	if (!NT_STATUS_IS_OK(status)) {
 		goto done;
 	}

Modified: branches/SAMBA_4_0/source/libcli/nmblib.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/nmblib.c	2004-08-18 20:07:44 UTC (rev 1896)
+++ branches/SAMBA_4_0/source/libcli/nmblib.c	2004-08-18 20:13:08 UTC (rev 1897)
@@ -1285,3 +1285,32 @@
 
 	return(len);
 } /* name_len */
+
+
+/*
+  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
+  truncated name
+*/
+void choose_called_name(struct nmb_name *n, const char *name, int type)
+{
+	if (is_ipaddress(name)) {
+		make_nmb_name(n, "*SMBSERVER", type);
+		return;
+	}
+	if (strlen(name) > 16) {
+		const char *p = strchr(name, '.');
+		char name2[17];
+		if (p - name > 16) {
+			make_nmb_name(n, "*SMBSERVER", type);
+			return;
+		}
+		strlcpy(name2, name, 1+(p-name));
+		make_nmb_name(n, name2, type);
+		return;
+	}
+
+	/* looks OK */
+	make_nmb_name(n, name, type);
+}

Modified: branches/SAMBA_4_0/source/libcli/raw/clitree.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/raw/clitree.c	2004-08-18 20:07:44 UTC (rev 1896)
+++ branches/SAMBA_4_0/source/libcli/raw/clitree.c	2004-08-18 20:13:08 UTC (rev 1897)
@@ -173,11 +173,11 @@
   parameters
 */
 NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, 
-				  const char *my_name, 
-				  const char *dest_host, int port,
-				  const char *service, const char *service_type,
-				  const char *user, const char *domain, 
-				  const char *password)
+				     const char *my_name, 
+				     const char *dest_host, int port,
+				     const char *service, const char *service_type,
+				     const char *user, const char *domain, 
+				     const char *password)
 {
 	struct smbcli_socket *sock;
 	struct smbcli_transport *transport;
@@ -212,7 +212,7 @@
 
 	/* send a NBT session request, if applicable */
 	make_nmb_name(&calling, my_name, 0x0);
-	make_nmb_name(&called,  dest_host, 0x20);
+	choose_called_name(&called,  dest_host, 0x20);
 
 	if (!smbcli_transport_connect(transport, &calling, &called)) {
 		smbcli_transport_close(transport);

Modified: branches/SAMBA_4_0/source/torture/torture.c
===================================================================
--- branches/SAMBA_4_0/source/torture/torture.c	2004-08-18 20:07:44 UTC (rev 1896)
+++ branches/SAMBA_4_0/source/torture/torture.c	2004-08-18 20:13:08 UTC (rev 1897)
@@ -37,22 +37,19 @@
 static struct smbcli_state *open_nbt_connection(void)
 {
 	struct nmb_name called, calling;
-	struct in_addr ip;
 	struct smbcli_state *cli;
 	const char *host = lp_parm_string(-1, "torture", "host");
 
 	make_nmb_name(&calling, lp_netbios_name(), 0x0);
-	make_nmb_name(&called , host, 0x20);
+	choose_called_name(&called, host, 0x20);
 
-	zero_ip(&ip);
-
 	cli = smbcli_state_init();
 	if (!cli) {
 		printf("Failed initialize smbcli_struct to connect with %s\n", host);
 		return NULL;
 	}
 
-	if (!smbcli_socket_connect(cli, host, &ip)) {
+	if (!smbcli_socket_connect(cli, host)) {
 		printf("Failed to connect with %s\n", host);
 		return cli;
 	}
@@ -64,7 +61,7 @@
 		 * Well, that failed, try *SMBSERVER ... 
 		 * However, we must reconnect as well ...
 		 */
-		if (!smbcli_socket_connect(cli, host, &ip)) {
+		if (!smbcli_socket_connect(cli, host)) {
 			printf("Failed to connect with %s\n", host);
 			return False;
 		}



More information about the samba-cvs mailing list