r5261: translate nbt rcode errors to NTSTATUS codes
authorAndrew Tridgell <tridge@samba.org>
Mon, 7 Feb 2005 12:10:38 +0000 (12:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:35 +0000 (13:09 -0500)
(This used to be commit 554d1b70e73faeb1f5ecf88f31c5810d86d76200)

source4/libcli/nbt/libnbt.h
source4/libcli/nbt/namequery.c
source4/libcli/nbt/nbtsocket.c
source4/utils/nmblookup.c

index 7ccd6a51a4f46556d7de2a2cfcff09572ef1e4b6..c126f592808e0e1460ebfdcb9523ad6dfb426c7c 100644 (file)
@@ -132,6 +132,7 @@ struct nbt_name_query {
                struct nbt_name name;
                int16_t num_addrs;
                const char **reply_addrs;
+               uint8_t rcode;
        } out;
 };
 
@@ -147,6 +148,7 @@ struct nbt_name_status {
                const char *reply_from;
                struct nbt_name name;
                struct nbt_rdata_status status;
+               uint8_t rcode;
        } out;
 };
 
index ddef2a7d070d5a9739efe4e986204752cb99af25..32fcad2052fe41098c07728310e61f4d57285a11 100644 (file)
@@ -91,6 +91,7 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
                return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
 
+       io->out.rcode = packet->operation & NBT_RCODE;
        io->out.name = packet->answers[0].name;
        io->out.num_addrs = packet->answers[0].rdata.netbios.length / 6;
        io->out.reply_addrs = talloc_array(mem_ctx, const char *, io->out.num_addrs);
@@ -184,6 +185,7 @@ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
                return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
 
+       io->out.rcode = packet->operation & NBT_RCODE;
        io->out.name = packet->answers[0].name;
        talloc_steal(mem_ctx, io->out.name.name);
        talloc_steal(mem_ctx, io->out.name.scope);
index f6566e8a6ec3fe2cc4449ed407ef2dee539d257b..38b356338cdeca1351b082e5521b6d5495b91105 100644 (file)
@@ -484,3 +484,29 @@ NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
        return NT_STATUS_OK;
 }
 
+
+/*
+  turn a NBT rcode into a NTSTATUS
+*/
+NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode)
+{
+       int i;
+       struct {
+               enum nbt_rcode rcode;
+               NTSTATUS status;
+       } map[] = {
+               { NBT_RCODE_FMT, NT_STATUS_INVALID_PARAMETER },
+               { NBT_RCODE_SVR, NT_STATUS_SERVER_DISABLED },
+               { NBT_RCODE_NAM, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NBT_RCODE_IMP, NT_STATUS_NOT_SUPPORTED },
+               { NBT_RCODE_RFS, NT_STATUS_ACCESS_DENIED },
+               { NBT_RCODE_ACT, NT_STATUS_ADDRESS_ALREADY_EXISTS },
+               { NBT_RCODE_ACT, NT_STATUS_CONFLICTING_ADDRESSES }
+       };
+       for (i=0;i<ARRAY_SIZE(map);i++) {
+               if (map[i].rcode == rcode) {
+                       return map[i].status;
+               }
+       }
+       return NT_STATUS_UNSUCCESSFUL;
+}
index f41ab4cc6e3789764d51d50d6419f6563558cc39..36550b893331e82e1aa42d34963ef7d7d8d58fdd 100644 (file)
@@ -155,6 +155,10 @@ static NTSTATUS do_node_query(struct nbt_name_socket *nbtsock,
 
        status = nbt_name_query(nbtsock, nbtsock, &io);
        NT_STATUS_NOT_OK_RETURN(status);
+
+       if (io.out.rcode != 0) {
+               return nbt_rcode_to_ntstatus(io.out.rcode);
+       }
                
        for (i=0;i<io.out.num_addrs;i++) {
                printf("%s %s<%02x>\n",