2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2009
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "librpc/gen_ndr/ndr_winbind_c.h"
23 #include "lib/util/strv.h"
25 struct wb_query_user_list_state
{
26 struct tevent_context
*ev
;
27 struct winbindd_domain
*domain
;
28 struct wbint_RidArray rids
;
29 const char *domain_name
;
30 struct wbint_Principals names
;
34 static void wb_query_user_list_gotrids(struct tevent_req
*subreq
);
35 static void wb_query_user_list_done(struct tevent_req
*subreq
);
37 struct tevent_req
*wb_query_user_list_send(TALLOC_CTX
*mem_ctx
,
38 struct tevent_context
*ev
,
39 struct winbindd_domain
*domain
)
41 struct tevent_req
*req
, *subreq
;
42 struct wb_query_user_list_state
*state
;
44 req
= tevent_req_create(mem_ctx
, &state
,
45 struct wb_query_user_list_state
);
50 state
->domain
= domain
;
52 subreq
= dcerpc_wbint_QueryUserRidList_send(
53 state
, ev
, dom_child_handle(domain
), &state
->rids
);
54 if (tevent_req_nomem(subreq
, req
)) {
55 return tevent_req_post(req
, ev
);
57 tevent_req_set_callback(subreq
, wb_query_user_list_gotrids
, req
);
61 static void wb_query_user_list_gotrids(struct tevent_req
*subreq
)
63 struct tevent_req
*req
= tevent_req_callback_data(
64 subreq
, struct tevent_req
);
65 struct wb_query_user_list_state
*state
= tevent_req_data(
66 req
, struct wb_query_user_list_state
);
67 NTSTATUS status
, result
;
69 status
= dcerpc_wbint_QueryUserRidList_recv(subreq
, state
, &result
);
71 if (any_nt_status_not_ok(status
, result
, &status
)) {
72 tevent_req_nterror(req
, status
);
76 DEBUG(10, ("dcerpc_wbint_QueryUserList returned %d users\n",
77 state
->rids
.num_rids
));
79 subreq
= dcerpc_wbint_LookupRids_send(
80 state
, state
->ev
, dom_child_handle(state
->domain
),
81 &state
->domain
->sid
, &state
->rids
,
82 &state
->domain_name
, &state
->names
);
83 if (tevent_req_nomem(subreq
, req
)) {
86 tevent_req_set_callback(subreq
, wb_query_user_list_done
, req
);
89 static void wb_query_user_list_done(struct tevent_req
*subreq
)
91 struct tevent_req
*req
= tevent_req_callback_data(
92 subreq
, struct tevent_req
);
93 struct wb_query_user_list_state
*state
= tevent_req_data(
94 req
, struct wb_query_user_list_state
);
95 NTSTATUS status
, result
;
98 status
= dcerpc_wbint_LookupRids_recv(subreq
, state
, &result
);
100 if (any_nt_status_not_ok(status
, result
, &status
)) {
101 tevent_req_nterror(req
, status
);
105 for (i
=0; i
<state
->names
.num_principals
; i
++) {
106 struct wbint_Principal
*p
= &state
->names
.principals
[i
];
110 name
= fill_domain_username_talloc(state
, state
->domain_name
, p
->name
, true);
112 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
115 ret
= strv_add(state
, &state
->users
, name
);
117 tevent_req_nterror(req
, map_nt_error_from_unix(ret
));
122 tevent_req_done(req
);
125 NTSTATUS
wb_query_user_list_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
128 struct wb_query_user_list_state
*state
= tevent_req_data(
129 req
, struct wb_query_user_list_state
);
132 if (tevent_req_is_nterror(req
, &status
)) {
136 *users
= talloc_move(mem_ctx
, &state
->users
);