svn commit: samba r5325 - in branches/SAMBA_4_0/source: libcli/nbt torture/nbt

tridge at samba.org tridge at samba.org
Fri Feb 11 06:58:07 GMT 2005


Author: tridge
Date: 2005-02-11 06:58:07 +0000 (Fri, 11 Feb 2005)
New Revision: 5325

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

Log:
- expanded the NBT-WINS test to include scopes

- fixed the bugs that the new test found

Modified:
   branches/SAMBA_4_0/source/libcli/nbt/nbtname.c
   branches/SAMBA_4_0/source/torture/nbt/wins.c


Changeset:
Modified: branches/SAMBA_4_0/source/libcli/nbt/nbtname.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/nbt/nbtname.c	2005-02-11 02:14:49 UTC (rev 5324)
+++ branches/SAMBA_4_0/source/libcli/nbt/nbtname.c	2005-02-11 06:58:07 UTC (rev 5325)
@@ -202,12 +202,13 @@
 	/* combine the remaining components into the scope */
 	scope = components[1];
 	for (i=2;i<num_components;i++) {
-		talloc_asprintf_append(scope, ".%s", components[i]);
+		scope = talloc_asprintf_append(scope, ".%s", components[i]);
+		NT_STATUS_HAVE_NO_MEMORY(scope);
 	}
 
 	if (scope) {
 		ret = convert_string_talloc(ndr, CH_DOS, CH_UNIX, scope, 
-					    strlen(r->scope)+1, &p);
+					    strlen(scope)+1, &p);
 		if (ret <= 0) {
 			return NT_STATUS_BAD_NETWORK_NAME;
 		}
@@ -265,10 +266,12 @@
 	       num_components < MAX_COMPONENTS) {
 		*p = 0;
 		components[num_components] = dscope;
-		NT_STATUS_HAVE_NO_MEMORY(components[num_components]);
 		dscope = p+1;
 		num_components++;
 	}
+	if (dscope && num_components < MAX_COMPONENTS) {
+		components[num_components++] = dscope;
+	}
 	if (num_components == MAX_COMPONENTS) {
 		return NT_STATUS_BAD_NETWORK_NAME;
 	}

Modified: branches/SAMBA_4_0/source/torture/nbt/wins.c
===================================================================
--- branches/SAMBA_4_0/source/torture/nbt/wins.c	2005-02-11 02:14:49 UTC (rev 5324)
+++ branches/SAMBA_4_0/source/torture/nbt/wins.c	2005-02-11 06:58:07 UTC (rev 5325)
@@ -33,18 +33,24 @@
 	}} while (0)
 
 #define CHECK_STRING(v, correct) do { \
-	if (StrCaseCmp(v, correct) != 0) { \
+	if ((v) != (correct) && \
+	    ((v)==NULL || (correct)==NULL || StrCaseCmp(v, correct) != 0)) { \
 		printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
 		       __location__, #v, v, correct); \
 		ret = False; \
 	}} while (0)
 
+#define CHECK_NAME(_name, correct) do { \
+	CHECK_STRING((_name).name, (correct).name); \
+	CHECK_VALUE((_name).type, (correct).type); \
+	CHECK_STRING((_name).scope, (correct).scope); \
+} while (0)
 
 /*
   test operations against a WINS server
 */
-static BOOL nbt_test_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, 
-			      const char *address)
+static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
+			       struct nbt_name *name)
 {
 	struct nbt_name_register_wins io;
 	struct nbt_name_query query;
@@ -54,18 +60,18 @@
 	struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL);
 	BOOL ret = True;
 	const char *myaddress = talloc_strdup(mem_ctx, iface_n_ip(0));
-	const char *tname = talloc_asprintf(mem_ctx, "_TORTURE-%5u", 
-					  (unsigned)(random() % (100000)));
 
 	/* we do the listen here to ensure the WINS server receives the packets from
 	   the right IP */
 	socket_listen(nbtsock->sock, myaddress, 0, 0, 0);
 
-	printf("Testing name registration to WINS with name '%s' at %s\n", tname, myaddress);
+	printf("Testing name registration to WINS with name %s<%02x> at %s\n", 
+	       name->name, name->type, myaddress);
+	if (name->scope) {
+		printf("scope is %s\n", name->scope);
+	}
 
-	io.in.name.name = tname;
-	io.in.name.type = NBT_NAME_CLIENT;
-	io.in.name.scope = NULL;
+	io.in.name = *name;
 	io.in.wins_servers = str_list_make(mem_ctx, address, NULL);
 	io.in.addresses = str_list_make(mem_ctx, myaddress, NULL);
 	io.in.nb_flags = NBT_NODE_H;
@@ -86,7 +92,7 @@
 	CHECK_VALUE(io.out.rcode, 0);
 
 	printf("query the name to make sure its there\n");
-	query.in.name = io.in.name;
+	query.in.name = *name;
 	query.in.dest_addr = address;
 	query.in.broadcast = False;
 	query.in.wins_lookup = True;
@@ -104,15 +110,12 @@
 		return False;
 	}
 	
-	CHECK_STRING(query.out.name.name, tname);
-	CHECK_VALUE(query.out.name.type, NBT_NAME_CLIENT);
+	CHECK_NAME(query.out.name, *name);
 	CHECK_VALUE(query.out.num_addrs, 1);
 	CHECK_STRING(query.out.reply_addrs[0], myaddress);
 
 	printf("refresh the name\n");
-	refresh.in.name.name = tname;
-	refresh.in.name.type = NBT_NAME_CLIENT;
-	refresh.in.name.scope = NULL;
+	refresh.in.name = *name;
 	refresh.in.wins_servers = str_list_make(mem_ctx, address, NULL);
 	refresh.in.addresses = str_list_make(mem_ctx, myaddress, NULL);
 	refresh.in.nb_flags = NBT_NODE_H;
@@ -133,7 +136,7 @@
 	CHECK_VALUE(io.out.rcode, 0);
 
 	printf("release the name\n");
-	release.in.name = io.in.name;
+	release.in.name = *name;
 	release.in.dest_addr = address;
 	release.in.address = myaddress;
 	release.in.nb_flags = NBT_NODE_H;
@@ -152,10 +155,10 @@
 		return False;
 	}
 	
-	CHECK_STRING(release.out.name.name, tname);
-	CHECK_VALUE(release.out.name.type, NBT_NAME_CLIENT);
+	CHECK_NAME(release.out.name, *name);
 	CHECK_VALUE(release.out.rcode, 0);
 
+
 	printf("release again\n");
 	status = nbt_name_release(nbtsock, mem_ctx, &release);
 	if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
@@ -168,8 +171,7 @@
 		return False;
 	}
 	
-	CHECK_STRING(release.out.name.name, tname);
-	CHECK_VALUE(release.out.name.type, NBT_NAME_CLIENT);
+	CHECK_NAME(release.out.name, *name);
 	CHECK_VALUE(release.out.rcode, 0);
 
 
@@ -188,7 +190,42 @@
 }
 
 
+
 /*
+  test operations against a WINS server
+*/
+static BOOL nbt_test_wins(TALLOC_CTX *mem_ctx, const char *address)
+{
+	struct nbt_name name;
+	BOOL ret = True;
+	uint32_t r = (unsigned)(random() % (100000));
+
+	name.name = talloc_asprintf(mem_ctx, "_TORTURE-%5u", r);
+				    
+	name.type = NBT_NAME_CLIENT;
+	name.scope = NULL;
+	ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
+	name.scope = "example";
+	name.type = 0x71;
+	ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
+	name.scope = "foo.example.com";
+	ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
+	name.name = talloc_asprintf(mem_ctx, "_T\01-%5u.foo", r);
+	ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
+	name.name = "";
+	ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
+	name.name = talloc_asprintf(mem_ctx, ".");
+	ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
+	return ret;
+}
+
+/*
   test WINS operations
 */
 BOOL torture_nbt_wins(void)
@@ -212,7 +249,7 @@
 		return False;
 	}
 
-	ret &= nbt_test_wins(mem_ctx, &name, address);
+	ret &= nbt_test_wins(mem_ctx, address);
 
 	talloc_free(mem_ctx);
 



More information about the samba-cvs mailing list