Author: tridge
Date: 2005-02-11 07:54:20 +0000 (Fri, 11 Feb 2005)
New Revision: 5328

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

Log:
 - allow case sensitive nbt name lookups

 - added --case-sensitive option to nmblookup

 - added case sensitivity tests to the NBT-WINS test

Modified:
   branches/SAMBA_4_0/source/libcli/nbt/nbtname.c
   branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c
   branches/SAMBA_4_0/source/torture/nbt/wins.c
   branches/SAMBA_4_0/source/utils/nmblookup.c


Changeset:
Modified: branches/SAMBA_4_0/source/libcli/nbt/nbtname.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/nbt/nbtname.c      2005-02-11 07:47:28 UTC 
(rev 5327)
+++ branches/SAMBA_4_0/source/libcli/nbt/nbtname.c      2005-02-11 07:54:20 UTC 
(rev 5328)
@@ -114,7 +114,7 @@
   compress a name component
  */
 static uint8_t *compress_name(TALLOC_CTX *mem_ctx, 
-                             uint8_t *name, enum nbt_name_type type)
+                             const uint8_t *name, enum nbt_name_type type)
 {
        uint8_t *cname;
        int i;
@@ -211,7 +211,7 @@
 {
        uint_t num_components;
        uint8_t *components[MAX_COMPONENTS];
-       char *dname, *dscope=NULL, *p;
+       char *dscope=NULL, *p;
        uint8_t *cname;
        int i;
 
@@ -219,14 +219,12 @@
                return NT_STATUS_OK;
        }
 
-       dname = strupper_talloc(ndr, r->name);
-       NT_STATUS_HAVE_NO_MEMORY(dname);
        if (r->scope) {
-               dscope = strupper_talloc(ndr, r->scope);
+               dscope = talloc_strdup(ndr, r->scope);
                NT_STATUS_HAVE_NO_MEMORY(dscope);
        }
 
-       cname = compress_name(ndr, dname, r->type);
+       cname = compress_name(ndr, r->name, r->type);
        NT_STATUS_HAVE_NO_MEMORY(cname);
 
        /* form the base components */

Modified: branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c  2005-02-11 07:47:28 UTC 
(rev 5327)
+++ branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c  2005-02-11 07:54:20 UTC 
(rev 5328)
@@ -101,6 +101,13 @@
        status = nbt_name_dup(state, name, &state->name);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
+       state->name.name = strupper_talloc(state, state->name.name);
+       if (state->name.name == NULL) goto failed;
+       if (state->name.scope) {
+               state->name.scope = strupper_talloc(state, state->name.scope);
+               if (state->name.scope == NULL) goto failed;
+       }
+
        state->nbtsock = nbt_name_socket_init(state, event_ctx);
        if (state->nbtsock == NULL) goto failed;
 

Modified: branches/SAMBA_4_0/source/torture/nbt/wins.c
===================================================================
--- branches/SAMBA_4_0/source/torture/nbt/wins.c        2005-02-11 07:47:28 UTC 
(rev 5327)
+++ branches/SAMBA_4_0/source/torture/nbt/wins.c        2005-02-11 07:54:20 UTC 
(rev 5328)
@@ -114,6 +114,42 @@
        CHECK_VALUE(query.out.num_addrs, 1);
        CHECK_STRING(query.out.reply_addrs[0], myaddress);
 
+
+       query.in.name.name = strupper_talloc(mem_ctx, name->name);
+       if (query.in.name.name &&
+           strcmp(query.in.name.name, name->name) != 0) {
+               printf("check case sensitivity\n");
+               status = nbt_name_query(nbtsock, mem_ctx, &query);
+               if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+                       printf("No response from %s for name query\n", address);
+                       return False;
+               }
+               if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+                       printf("Bad response from %s for name query - %s\n",
+                              address, nt_errstr(status));
+                       return False;
+               }
+       }
+
+       query.in.name = *name;
+       if (name->scope) {
+               query.in.name.scope = strupper_talloc(mem_ctx, name->scope);
+       }
+       if (query.in.name.scope &&
+           strcmp(query.in.name.scope, name->scope) != 0) {
+               printf("check case sensitivity on scope\n");
+               status = nbt_name_query(nbtsock, mem_ctx, &query);
+               if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+                       printf("No response from %s for name query\n", address);
+                       return False;
+               }
+               if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+                       printf("Bad response from %s for name query - %s\n",
+                              address, nt_errstr(status));
+                       return False;
+               }
+       }
+
        printf("refresh the name\n");
        refresh.in.name = *name;
        refresh.in.wins_servers = str_list_make(mem_ctx, address, NULL);
@@ -176,6 +212,7 @@
 
 
        printf("query the name to make sure its gone\n");
+       query.in.name = *name;
        status = nbt_name_query(nbtsock, mem_ctx, &query);
        if (NT_STATUS_IS_OK(status)) {
                printf("ERROR: Name query success after release\n");
@@ -222,6 +259,9 @@
        name.name = talloc_asprintf(mem_ctx, ".");
        ret &= nbt_test_wins_name(mem_ctx, address, &name);
 
+       name.name = talloc_asprintf(mem_ctx, "%5u-\377\200\300FOO", r);
+       ret &= nbt_test_wins_name(mem_ctx, address, &name);
+
        return ret;
 }
 

Modified: branches/SAMBA_4_0/source/utils/nmblookup.c
===================================================================
--- branches/SAMBA_4_0/source/utils/nmblookup.c 2005-02-11 07:47:28 UTC (rev 
5327)
+++ branches/SAMBA_4_0/source/utils/nmblookup.c 2005-02-11 07:54:20 UTC (rev 
5328)
@@ -38,6 +38,7 @@
        BOOL node_status;
        BOOL root_port;
        BOOL lookup_by_ip;
+       BOOL case_sensitive;
 } options;
 
 /*
@@ -178,6 +179,10 @@
        char *node_name, *p;
        struct nbt_name_socket *nbtsock;
        NTSTATUS status;
+
+       if (!options.case_sensitive) {
+               name = strupper_talloc(tmp_ctx, name);
+       }
        
        if (options.find_master) {
                node_type = NBT_NAME_MASTER;
@@ -259,6 +264,9 @@
                { "lookup-by-ip", 'A', POPT_ARG_VAL, &options.lookup_by_ip, 
                  True, "Do a node status on <name> as an IP Address" },
 
+               { "case-sensitive", 0, POPT_ARG_VAL, &options.case_sensitive, 
+                 True, "Don't uppercase the name before sending" },
+
                POPT_COMMON_SAMBA
                { 0, 0, 0, 0 }
        };

Reply via email to