s3:libsmb: Fix querying all names registered within broadcast area
authorSamuel Cabrero <scabrero@samba.org>
Tue, 14 Jan 2020 16:12:33 +0000 (17:12 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 15 Jan 2020 21:25:34 +0000 (21:25 +0000)
Wait for additional replies until timeout when '*' is given to nmblookup
as name.

Introduced by 8da8c36b53cc115f0d446b666fc24fc9423d808e.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=8927

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/namequery.c

index 5d4fca70b200bebb9b15b4240c3e7366520b85bd..e27b60b0398e90d2b5db28c31dc7b0594fbbaea3 100644 (file)
@@ -1221,6 +1221,7 @@ struct name_query_state {
        struct sockaddr_storage my_addr;
        struct sockaddr_storage addr;
        bool bcast;
+       bool bcast_star_query;
 
 
        uint8_t buf[1024];
@@ -1288,6 +1289,16 @@ struct tevent_req *name_query_send(TALLOC_CTX *mem_ctx,
        nmb->header.nscount = 0;
        nmb->header.arcount = 0;
 
+       if (bcast && (strcmp(name, "*")==0)) {
+               /*
+                * We're doing a broadcast query for all
+                * names in the area. Remember this so
+                * we will wait for all names within
+                * the timeout period.
+                */
+               state->bcast_star_query = true;
+       }
+
        make_nmb_name(&nmb->question.question_name,name,name_type);
 
        nmb->question.question_type = 0x20;
@@ -1445,9 +1456,12 @@ static bool name_query_validator(struct packet_struct *p, void *private_data)
        if (state->bcast) {
                /*
                 * We have to collect all entries coming in from broadcast
-                * queries. If we got a unique name, we're done.
+                * queries. If we got a unique name and we are not querying
+                * all names registered within broadcast area (query
+                * for the name '*', so state->bcast_star_query is set),
+                * we're done.
                 */
-               return got_unique_netbios_name;
+               return (got_unique_netbios_name && !state->bcast_star_query);
        }
        /*
         * WINS responses are accepted when they are received