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 D_INFO("WB command user_list start.\nQuery users in domain %s.\n",
53 state
->domain
= domain
;
55 subreq
= dcerpc_wbint_QueryUserRidList_send(
56 state
, ev
, dom_child_handle(domain
), &state
->rids
);
57 if (tevent_req_nomem(subreq
, req
)) {
58 return tevent_req_post(req
, ev
);
60 tevent_req_set_callback(subreq
, wb_query_user_list_gotrids
, req
);
64 static void wb_query_user_list_gotrids(struct tevent_req
*subreq
)
66 struct tevent_req
*req
= tevent_req_callback_data(
67 subreq
, struct tevent_req
);
68 struct wb_query_user_list_state
*state
= tevent_req_data(
69 req
, struct wb_query_user_list_state
);
70 NTSTATUS status
, result
;
72 status
= dcerpc_wbint_QueryUserRidList_recv(subreq
, state
, &result
);
74 if (any_nt_status_not_ok(status
, result
, &status
)) {
75 tevent_req_nterror(req
, status
);
79 D_DEBUG("dcerpc_wbint_QueryUserRidList returned %"PRIu32
" users\n",
80 state
->rids
.num_rids
);
82 subreq
= dcerpc_wbint_LookupRids_send(
83 state
, state
->ev
, dom_child_handle(state
->domain
),
84 &state
->domain
->sid
, &state
->rids
,
85 &state
->domain_name
, &state
->names
);
86 if (tevent_req_nomem(subreq
, req
)) {
89 tevent_req_set_callback(subreq
, wb_query_user_list_done
, req
);
92 static void wb_query_user_list_done(struct tevent_req
*subreq
)
94 struct tevent_req
*req
= tevent_req_callback_data(
95 subreq
, struct tevent_req
);
96 struct wb_query_user_list_state
*state
= tevent_req_data(
97 req
, struct wb_query_user_list_state
);
98 NTSTATUS status
, result
;
101 status
= dcerpc_wbint_LookupRids_recv(subreq
, state
, &result
);
103 if (any_nt_status_not_ok(status
, result
, &status
)) {
104 tevent_req_nterror(req
, status
);
107 D_DEBUG("Processing %"PRIu32
" principal(s).\n",
108 state
->names
.num_principals
);
109 for (i
=0; i
<state
->names
.num_principals
; i
++) {
110 struct wbint_Principal
*p
= &state
->names
.principals
[i
];
114 name
= fill_domain_username_talloc(state
, state
->domain_name
, p
->name
, true);
116 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
119 ret
= strv_add(state
, &state
->users
, name
);
121 tevent_req_nterror(req
, map_nt_error_from_unix(ret
));
124 D_DEBUG("%"PRIu32
": Adding user %s\n", i
, name
);
127 tevent_req_done(req
);
130 NTSTATUS
wb_query_user_list_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
133 struct wb_query_user_list_state
*state
= tevent_req_data(
134 req
, struct wb_query_user_list_state
);
137 D_INFO("WB command user_list end.\n");
138 if (tevent_req_is_nterror(req
, &status
)) {
139 D_WARNING("Failed with: %s\n", nt_errstr(status
));
143 *users
= talloc_move(mem_ctx
, &state
->users
);