r5328: - allow case sensitive nbt name lookups
authorAndrew Tridgell <tridge@samba.org>
Fri, 11 Feb 2005 07:54:20 +0000 (07:54 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:42 +0000 (13:09 -0500)
 - added --case-sensitive option to nmblookup

 - added case sensitivity tests to the NBT-WINS test
(This used to be commit 80a95d5688e055b36727e5c043cb36322d719763)

source4/libcli/nbt/nbtname.c
source4/libcli/resolve/nbtlist.c
source4/torture/nbt/wins.c
source4/utils/nmblookup.c

index 1904b33a9bde5c52199b18f799e5a3565e4711ab..0d2840e0b5b36d802ae66cabfc04624fe1db13c5 100644 (file)
@@ -114,7 +114,7 @@ static NTSTATUS decompress_name(char *name, enum nbt_name_type *type)
   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 @@ NTSTATUS ndr_push_nbt_name(struct ndr_push *ndr, int ndr_flags, struct nbt_name
 {
        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 @@ NTSTATUS ndr_push_nbt_name(struct ndr_push *ndr, int ndr_flags, struct nbt_name
                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 */
index 5a9e31e09da8a475e9f440180a29c03cd6b36140..89e9a63748d80a9db0933b0151521c1d28a2febf 100644 (file)
@@ -101,6 +101,13 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name,
        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;
 
index fdd5a1094dd96620733ee438117323612cf97d52..27b50dd2042188ae544dcd549629223c5da712b2 100644 (file)
@@ -114,6 +114,42 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
        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 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
 
 
        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 @@ static BOOL nbt_test_wins(TALLOC_CTX *mem_ctx, const char *address)
        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;
 }
 
index 5e8b59edc87e2d78c3684b64f11244fc672bd865..857d03fe19eed612d789a903f839dedc11b6747b 100644 (file)
@@ -38,6 +38,7 @@ static struct {
        BOOL node_status;
        BOOL root_port;
        BOOL lookup_by_ip;
+       BOOL case_sensitive;
 } options;
 
 /*
@@ -178,6 +179,10 @@ static void process_one(const char *name)
        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 @@ int main(int argc,char *argv[])
                { "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 }
        };