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/cli_wbint.h"
23 #include "idmap_cache.h"
26 struct wb_gid2sid_state
{
27 struct tevent_context
*ev
;
32 static void wb_gid2sid_done(struct tevent_req
*subreq
);
34 struct tevent_req
*wb_gid2sid_send(TALLOC_CTX
*mem_ctx
,
35 struct tevent_context
*ev
,
38 struct tevent_req
*req
, *subreq
;
39 struct wb_gid2sid_state
*state
;
40 struct winbindd_domain
*domain
;
41 struct winbindd_child
*child
;
44 req
= tevent_req_create(mem_ctx
, &state
, struct wb_gid2sid_state
);
49 if (winbindd_use_idmap_cache()
50 && idmap_cache_find_gid2sid(gid
, &state
->sid
, &expired
)) {
52 DEBUG(10, ("idmap_cache_find_gid2sid found %d%s\n",
53 (int)gid
, expired
? " (expired)": ""));
55 if (!expired
|| idmap_is_offline()) {
56 if (is_null_sid(&state
->sid
)) {
57 tevent_req_nterror(req
,
58 NT_STATUS_NONE_MAPPED
);
62 return tevent_req_post(req
, ev
);
66 state
->dom_name
= NULL
;
68 for (domain
= domain_list(); domain
!= NULL
; domain
= domain
->next
) {
69 if (domain
->have_idmap_config
70 && (gid
>= domain
->id_range_low
)
71 && (gid
<= domain
->id_range_high
)) {
72 state
->dom_name
= domain
->name
;
77 child
= idmap_child();
79 subreq
= dcerpc_wbint_Gid2Sid_send(
80 state
, ev
, child
->binding_handle
, state
->dom_name
,
82 if (tevent_req_nomem(subreq
, req
)) {
83 return tevent_req_post(req
, ev
);
85 tevent_req_set_callback(subreq
, wb_gid2sid_done
, req
);
89 static void wb_gid2sid_done(struct tevent_req
*subreq
)
91 struct tevent_req
*req
= tevent_req_callback_data(
92 subreq
, struct tevent_req
);
93 struct wb_gid2sid_state
*state
= tevent_req_data(
94 req
, struct wb_gid2sid_state
);
95 NTSTATUS status
, result
;
97 status
= dcerpc_wbint_Gid2Sid_recv(subreq
, state
, &result
);
99 if (!NT_STATUS_IS_OK(status
)) {
100 tevent_req_nterror(req
, status
);
103 if (!NT_STATUS_IS_OK(result
)) {
104 tevent_req_nterror(req
, result
);
107 tevent_req_done(req
);
110 NTSTATUS
wb_gid2sid_recv(struct tevent_req
*req
, struct dom_sid
*sid
)
112 struct wb_gid2sid_state
*state
= tevent_req_data(
113 req
, struct wb_gid2sid_state
);
116 if (tevent_req_is_nterror(req
, &status
)) {
119 sid_copy(sid
, &state
->sid
);