s3:winbind: fix bug #7894 - sporadic winbind panic in rpc query_user_list
[samba.git] / source3 / winbindd / winbindd_rpc.c
index e7a1f86d212e292a92b0b6c481ddd30fb96a9b95..b65b126cf03c0c7ecc5b1021d8ce34385a7806b3 100644 (file)
@@ -84,6 +84,13 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
                                                      &total_size,
                                                      &returned_size,
                                                      &disp_info);
+
+               if (!NT_STATUS_IS_OK(result)) {
+                       if (!NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
+                               return result;
+                       }
+               }
+
                num_dom_users = disp_info.info1.count;
                start_idx += disp_info.info1.count;
                loop_count++;
@@ -194,7 +201,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
                talloc_destroy(mem_ctx2);
        } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
 
-       return NT_STATUS_OK;
+       return status;
 }
 
 /* List all domain groups */
@@ -264,7 +271,7 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
 
        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
 
-       return NT_STATUS_OK;
+       return result;
 }
 
 /* convert a single name to a sid in a domain */
@@ -782,16 +789,16 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
         if (!NT_STATUS_IS_OK(result))
                return result;
 
-       *num_names = rids->count;
-       rid_mem = rids->rids;
-
-       if (!*num_names) {
+       if (!rids || !rids->count) {
                names = NULL;
                name_types = NULL;
                sid_mem = NULL;
                return NT_STATUS_OK;
        }
 
+       *num_names = rids->count;
+       rid_mem = rids->rids;
+
         /* Step #2: Convert list of rids into list of usernames.  Do this
            in bunches of ~1000 to avoid crashing NT4.  It looks like there
            is a buffer overflow or something like that lurking around
@@ -1281,12 +1288,8 @@ NTSTATUS winbindd_lookup_names(TALLOC_CTX *mem_ctx,
         * This call can take a long time
         * allow the server to time out.
         * 35 seconds should do it.
-        * NB
-        * only do this when the undelying transport is named pipe.
         */
-       if (cli->transport->transport == NCACN_NP) {
-               orig_timeout = rpccli_set_timeout(cli, 35000);
-       }
+       orig_timeout = rpccli_set_timeout(cli, 35000);
 
        status = lookup_names_fn(cli,
                                 mem_ctx,
@@ -1299,9 +1302,7 @@ NTSTATUS winbindd_lookup_names(TALLOC_CTX *mem_ctx,
                                 types);
 
        /* And restore our original timeout. */
-       if (cli->transport->transport == NCACN_NP) {
-               rpccli_set_timeout(cli, orig_timeout);
-       }
+       rpccli_set_timeout(cli, orig_timeout);
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;