tdb: fix non-WAF build, commit 1.2.6 ABI file.
[Samba.git] / source3 / winbindd / wb_gid2sid.c
blobd4416f1a76db46e583c99eefe64b82df9b8fc288
1 /*
2 Unix SMB/CIFS implementation.
3 async gid2sid
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/>.
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "librpc/gen_ndr/cli_wbint.h"
23 #include "idmap_cache.h"
24 #include "idmap.h"
26 struct wb_gid2sid_state {
27 struct tevent_context *ev;
28 char *dom_name;
29 struct dom_sid sid;
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,
36 gid_t gid)
38 struct tevent_req *req, *subreq;
39 struct wb_gid2sid_state *state;
40 struct winbindd_domain *domain;
41 struct winbindd_child *child;
42 bool expired;
44 req = tevent_req_create(mem_ctx, &state, struct wb_gid2sid_state);
45 if (req == NULL) {
46 return NULL;
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);
59 } else {
60 tevent_req_done(req);
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;
73 break;
77 child = idmap_child();
79 subreq = dcerpc_wbint_Gid2Sid_send(
80 state, ev, child->binding_handle, state->dom_name,
81 gid, &state->sid);
82 if (tevent_req_nomem(subreq, req)) {
83 return tevent_req_post(req, ev);
85 tevent_req_set_callback(subreq, wb_gid2sid_done, req);
86 return 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);
98 TALLOC_FREE(subreq);
99 if (!NT_STATUS_IS_OK(status)) {
100 tevent_req_nterror(req, status);
101 return;
103 if (!NT_STATUS_IS_OK(result)) {
104 tevent_req_nterror(req, result);
105 return;
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);
114 NTSTATUS status;
116 if (tevent_req_is_nterror(req, &status)) {
117 return status;
119 sid_copy(sid, &state->sid);
120 return NT_STATUS_OK;