r5408: - added testing for the behaviour of the special 0x1c name
authorAndrew Tridgell <tridge@samba.org>
Tue, 15 Feb 2005 11:14:04 +0000 (11:14 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:10:43 +0000 (13:10 -0500)
- added WINS server support for the 0x1c name

source/nbt_server/defense.c
source/nbt_server/nbt_server.h
source/nbt_server/winsserver.c
source/nbt_server/winswack.c
source/torture/nbt/wins.c
source/torture/nbt/winsbench.c

index c59877e4b74d66c207dbfee4c7b2e206d4e6e347..8d71b31c65bf12baa2e729046907678002f0db11 100644 (file)
@@ -56,7 +56,8 @@ void nbtd_request_defense(struct nbt_name_socket *nbtsock,
        name = &packet->questions[0].name;
 
        iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE);
-       if (iname != NULL && !(iname->nb_flags & NBT_NM_GROUP)) {
+       if (iname != NULL && 
+           !IS_GROUP_NAME(name, iname->nb_flags)) {
                DEBUG(2,("Defending name %s on %s against %s\n",
                         nbt_name_string(packet, name), 
                         iface->bcast_address, src_address));
index a698ebf1a027c02bb658eb0033a594f2de22a528..6a7b14a5463b1c1b2fe5d31b94373d249837f8db 100644 (file)
@@ -79,3 +79,7 @@ struct nbtd_server {
                return; \
        } \
 } while (0)
+
+/* this copes with the nasty hack that is the type 0x1c name */
+#define IS_GROUP_NAME(name, nb_flags) \
+       ((name)->type != NBT_NAME_LOGON && (nb_flags & NBT_NM_GROUP))
index 45b147d86d1eb8e687b8a43c79cdac982d5f5371..c1eed0b1fa2cb596114e1fd1fd45078e0ac049d8 100644 (file)
@@ -56,7 +56,7 @@ static uint8_t wins_register_new(struct nbt_name_socket *nbtsock,
        rec.state         = WINS_REC_ACTIVE;
        rec.expire_time   = time(NULL) + ttl;
        rec.registered_by = src_address;
-       if (nb_flags & NBT_NM_GROUP) {
+       if (IS_GROUP_NAME(name, nb_flags)) {
                rec.addresses     = str_list_make(packet, "255.255.255.255", NULL);
        } else {
                rec.addresses     = str_list_make(packet, address, NULL);
@@ -145,7 +145,7 @@ static void nbtd_winsserver_register(struct nbt_name_socket *nbtsock,
 
        /* if the registration is for a group, then just update the expiry time 
           and we are done */
-       if (nb_flags & NBT_NM_GROUP) {
+       if (IS_GROUP_NAME(name, nb_flags)) {
                wins_update_ttl(nbtsock, packet, rec, src_address, src_port);
                goto done;
        }
@@ -207,7 +207,7 @@ static void nbtd_winsserver_release(struct nbt_name_socket *nbtsock,
        rec = winsdb_load(winssrv, name, packet);
        if (rec == NULL || 
            rec->state != WINS_REC_ACTIVE || 
-           (rec->nb_flags & NBT_NM_GROUP)) {
+           IS_GROUP_NAME(name, rec->nb_flags)) {
                goto done;
        }
 
index a15f0a7d06ff8d98120eb1f8a0e69068339f1d31..190b1cdec7ddca4f7a9e0bd1dd281c2ef86d09ae 100644 (file)
@@ -173,11 +173,6 @@ void wins_register_wack(struct nbt_name_socket *nbtsock,
        state->src_address     = talloc_strdup(state, src_address);
        if (state->src_address == NULL) goto failed;
 
-       /* send a WACK to the client, specifying the maximum time it could
-          take to check with the owner, plus some slack */
-       ttl = 5 + 4 * str_list_length(rec->addresses);
-       nbtd_wack_reply(nbtsock, packet, src_address, src_port, ttl);
-
        /* setup a name query to the first address */
        state->query.in.name        = *rec->name;
        state->query.in.dest_addr   = state->owner_addresses[0];
@@ -186,6 +181,17 @@ void wins_register_wack(struct nbt_name_socket *nbtsock,
        state->query.in.timeout     = 1;
        state->query.in.retries     = 2;
 
+       /* the LOGON type is a nasty hack */
+       if (rec->name->type == NBT_NAME_LOGON) {
+               wins_wack_allow(state);
+               return;
+       }
+
+       /* send a WACK to the client, specifying the maximum time it could
+          take to check with the owner, plus some slack */
+       ttl = 5 + 4 * str_list_length(rec->addresses);
+       nbtd_wack_reply(nbtsock, packet, src_address, src_port, ttl);
+
        req = nbt_name_query_send(nbtsock, &state->query);
        if (req == NULL) goto failed;
 
index 9258f3b517944b30b4bf18213c2ca6b233a87152..3f8b361a932686ba9e95480b6a772011a65d9a93 100644 (file)
@@ -111,7 +111,9 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
        CHECK_STRING(io.out.wins_server, address);
        CHECK_VALUE(io.out.rcode, 0);
 
-       if (name->type != NBT_NAME_MASTER && nb_flags & NBT_NM_GROUP) {
+       if (name->type != NBT_NAME_MASTER && 
+           name->type != NBT_NAME_LOGON && 
+           (nb_flags & NBT_NM_GROUP)) {
                printf("Try to register as non-group\n");
                io.in.nb_flags &= ~NBT_NM_GROUP;
                status = nbt_name_register_wins(nbtsock, mem_ctx, &io);
@@ -152,7 +154,8 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
        
        CHECK_NAME(query.out.name, *name);
        CHECK_VALUE(query.out.num_addrs, 1);
-       if (nb_flags & NBT_NM_GROUP) {
+       if (name->type != NBT_NAME_LOGON &&
+           (nb_flags & NBT_NM_GROUP)) {
                CHECK_STRING(query.out.reply_addrs[0], "255.255.255.255");
        } else {
                CHECK_STRING(query.out.reply_addrs[0], myaddress);
@@ -258,7 +261,8 @@ 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 (nb_flags & NBT_NM_GROUP) {
+       if (name->type != NBT_NAME_LOGON &&
+           (nb_flags & NBT_NM_GROUP)) {
                if (!NT_STATUS_IS_OK(status)) {
                        printf("ERROR: Name query failed after group release - %s\n",
                               nt_errstr(status));
@@ -300,6 +304,9 @@ static BOOL nbt_test_wins(TALLOC_CTX *mem_ctx, const char *address)
 
        ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
 
+       name.type = NBT_NAME_LOGON;
+       ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H | NBT_NM_GROUP);
+
        name.scope = "example";
        name.type = 0x72;
        ret &= nbt_test_wins_name(mem_ctx, address, &name, NBT_NODE_H);
index 4c0934a0edeec5f1e331067a9ca71fe928a09903..f6a6283dd245cc89bdc2b350b6f906d0518d0770 100644 (file)
@@ -120,7 +120,7 @@ static void release_handler(struct nbt_name_request *req)
 }
 
 /*
-  generate a registration
+  generate a name release
 */
 static void generate_release(struct nbt_name_socket *nbtsock, struct wins_state *state, int idx)
 {