diff options
author | Volker Lendecke <vl@samba.org> | 2021-06-12 20:46:20 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2021-06-15 18:11:35 +0000 |
commit | 35a43de18d541968a5a0de721b4ec429e61ad23b (patch) | |
tree | 8886aa741b778f5b5c955636db1ee85fee3f4f4d /source3/rpc_server | |
parent | 76c1b77e79c273db4c768a899fa8383e9630dc59 (diff) | |
download | samba-35a43de18d541968a5a0de721b4ec429e61ad23b.tar.gz |
rpc_server: Make get_domain_userlist() independent of errno
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>
Diffstat (limited to 'source3/rpc_server')
-rw-r--r-- | source3/rpc_server/wkssvc/srv_wkssvc_nt.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/source3/rpc_server/wkssvc/srv_wkssvc_nt.c b/source3/rpc_server/wkssvc/srv_wkssvc_nt.c index 84318cf35be..6b787ad8b32 100644 --- a/source3/rpc_server/wkssvc/srv_wkssvc_nt.c +++ b/source3/rpc_server/wkssvc/srv_wkssvc_nt.c @@ -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; } |