]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
rpc_server: Make get_domain_userlist() independent of errno
authorVolker Lendecke <vl@samba.org>
Sat, 12 Jun 2021 18:46:20 +0000 (20:46 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 15 Jun 2021 18:11:35 +0000 (18:11 +0000)
In the "num_users==0" case (previously just return NULL) we depended
on errno==0 implicitly. When list_sessions() above in this routine had
to open smbXsrv_session_global, it could however happen that errno was
set. If then there were no users, get_domain_userlist() returned NULL
with errno set, which the callers interpreted then as a real error.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/rpc_server/wkssvc/srv_wkssvc_nt.c

index 84318cf35bec8bdc12e6516e95b124db6b91e363..6b787ad8b321103ff37a79c18ded14fc5805e72a 100644 (file)
@@ -160,7 +160,7 @@ static int dom_user_cmp(const struct dom_usr *usr1, const struct dom_usr *usr2)
  in this list.
  ********************************************************************/
 
-static struct dom_usr *get_domain_userlist(TALLOC_CTX *mem_ctx)
+static int get_domain_userlist(TALLOC_CTX *mem_ctx, struct dom_usr **pusers)
 {
        struct sessionid *session_list = NULL;
        char *machine_name, *p, *nm;
@@ -175,14 +175,14 @@ static struct dom_usr *get_domain_userlist(TALLOC_CTX *mem_ctx)
 
        num_sessions = list_sessions(mem_ctx, &session_list);
        if (num_sessions == 0) {
-               errno = 0;
-               return NULL;
+               *pusers = NULL;
+               return 0;
        }
 
        users = talloc_array(mem_ctx, struct dom_usr, num_sessions);
        if (users == NULL) {
                TALLOC_FREE(session_list);
-               return NULL;
+               return ENOMEM;
        }
 
        for (i=num_users=0; i<num_sessions; i++) {
@@ -232,17 +232,24 @@ static struct dom_usr *get_domain_userlist(TALLOC_CTX *mem_ctx)
        }
        TALLOC_FREE(session_list);
 
+       if (num_users == 0) {
+               TALLOC_FREE(users);
+               *pusers = NULL;
+               return 0;
+       }
+
        tmp = talloc_realloc(mem_ctx, users, struct dom_usr, num_users);
        if (tmp == NULL) {
-               return NULL;
+               TALLOC_FREE(users);
+               return ENOMEM;
        }
        users = tmp;
 
        /* Sort the user list by time, oldest first */
        TYPESAFE_QSORT(users, num_users, dom_user_cmp);
 
-       errno = 0;
-       return users;
+       *pusers = users;
+       return 0;
 }
 
 /*******************************************************************
@@ -505,10 +512,11 @@ static struct wkssvc_NetWkstaEnumUsersCtr1 *create_enum_users1(
        }
        num_users = talloc_array_length(users);
 
-       dom_users = get_domain_userlist(talloc_tos());
-       if (dom_users == NULL && errno != 0) {
+       ret = get_domain_userlist(talloc_tos(), &dom_users);
+       if (ret != 0) {
                TALLOC_FREE(ctr1);
                TALLOC_FREE(users);
+               errno = ret;
                return NULL;
        }
        num_dom_users = talloc_array_length(dom_users);
@@ -519,6 +527,7 @@ static struct wkssvc_NetWkstaEnumUsersCtr1 *create_enum_users1(
                TALLOC_FREE(ctr1);
                TALLOC_FREE(users);
                TALLOC_FREE(dom_users);
+               errno = ENOMEM;
                return NULL;
        }