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 "idmap_cache.h"
25 #include "../libcli/security/security.h"
27 struct wb_gid2sid_state
{
28 struct tevent_context
*ev
;
33 static void wb_gid2sid_done(struct tevent_req
*subreq
);
35 struct tevent_req
*wb_gid2sid_send(TALLOC_CTX
*mem_ctx
,
36 struct tevent_context
*ev
,
39 struct tevent_req
*req
, *subreq
;
40 struct wb_gid2sid_state
*state
;
41 struct winbindd_domain
*domain
;
42 struct winbindd_child
*child
;
45 req
= tevent_req_create(mem_ctx
, &state
, struct wb_gid2sid_state
);
50 if (winbindd_use_idmap_cache()
51 && idmap_cache_find_gid2sid(gid
, &state
->sid
, &expired
)) {
53 DEBUG(10, ("idmap_cache_find_gid2sid found %d%s\n",
54 (int)gid
, expired
? " (expired)": ""));
56 if (!expired
|| idmap_is_offline()) {
57 if (is_null_sid(&state
->sid
)) {
58 tevent_req_nterror(req
,
59 NT_STATUS_NONE_MAPPED
);
63 return tevent_req_post(req
, ev
);
67 state
->dom_name
= NULL
;
69 for (domain
= domain_list(); domain
!= NULL
; domain
= domain
->next
) {
70 if (domain
->have_idmap_config
71 && (gid
>= domain
->id_range_low
)
72 && (gid
<= domain
->id_range_high
)) {
73 state
->dom_name
= domain
->name
;
78 child
= idmap_child();
80 subreq
= dcerpc_wbint_Gid2Sid_send(
81 state
, ev
, child
->binding_handle
, state
->dom_name
,
83 if (tevent_req_nomem(subreq
, req
)) {
84 return tevent_req_post(req
, ev
);
86 tevent_req_set_callback(subreq
, wb_gid2sid_done
, req
);
90 static void wb_gid2sid_done(struct tevent_req
*subreq
)
92 struct tevent_req
*req
= tevent_req_callback_data(
93 subreq
, struct tevent_req
);
94 struct wb_gid2sid_state
*state
= tevent_req_data(
95 req
, struct wb_gid2sid_state
);
96 NTSTATUS status
, result
;
98 status
= dcerpc_wbint_Gid2Sid_recv(subreq
, state
, &result
);
100 if (any_nt_status_not_ok(status
, result
, &status
)) {
101 tevent_req_nterror(req
, status
);
104 tevent_req_done(req
);
107 NTSTATUS
wb_gid2sid_recv(struct tevent_req
*req
, struct dom_sid
*sid
)
109 struct wb_gid2sid_state
*state
= tevent_req_data(
110 req
, struct wb_gid2sid_state
);
113 if (tevent_req_is_nterror(req
, &status
)) {
116 sid_copy(sid
, &state
->sid
);