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
;
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_child
*child
;
43 req
= tevent_req_create(mem_ctx
, &state
, struct wb_gid2sid_state
);
48 if (winbindd_use_idmap_cache()
49 && idmap_cache_find_gid2sid(gid
, &state
->sid
, &expired
)) {
51 DEBUG(10, ("idmap_cache_find_gid2sid found %d%s\n",
52 (int)gid
, expired
? " (expired)": ""));
54 if (!expired
|| idmap_is_offline()) {
55 if (is_null_sid(&state
->sid
)) {
56 tevent_req_nterror(req
,
57 NT_STATUS_NONE_MAPPED
);
61 return tevent_req_post(req
, ev
);
65 child
= idmap_child();
67 subreq
= dcerpc_wbint_Gid2Sid_send(
68 state
, ev
, child
->binding_handle
,
70 if (tevent_req_nomem(subreq
, req
)) {
71 return tevent_req_post(req
, ev
);
73 tevent_req_set_callback(subreq
, wb_gid2sid_done
, req
);
77 static void wb_gid2sid_done(struct tevent_req
*subreq
)
79 struct tevent_req
*req
= tevent_req_callback_data(
80 subreq
, struct tevent_req
);
81 struct wb_gid2sid_state
*state
= tevent_req_data(
82 req
, struct wb_gid2sid_state
);
83 NTSTATUS status
, result
;
85 status
= dcerpc_wbint_Gid2Sid_recv(subreq
, state
, &result
);
87 if (any_nt_status_not_ok(status
, result
, &status
)) {
88 tevent_req_nterror(req
, status
);
94 NTSTATUS
wb_gid2sid_recv(struct tevent_req
*req
, struct dom_sid
*sid
)
96 struct wb_gid2sid_state
*state
= tevent_req_data(
97 req
, struct wb_gid2sid_state
);
100 if (tevent_req_is_nterror(req
, &status
)) {
103 sid_copy(sid
, &state
->sid
);