smbd: Convert smb_set_file_size to cp_smb_filename
[Samba/gebeck_regimport.git] / source3 / winbindd / wb_gid2sid.c
blob942e5f7669e38ea58f9bb7536b8691532229ce0d
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/ndr_wbint_c.h"
23 #include "idmap_cache.h"
24 #include "idmap.h"
25 #include "../libcli/security/security.h"
27 struct wb_gid2sid_state {
28 struct tevent_context *ev;
29 char *dom_name;
30 struct dom_sid sid;
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,
37 gid_t gid)
39 struct tevent_req *req, *subreq;
40 struct wb_gid2sid_state *state;
41 struct winbindd_domain *domain;
42 struct winbindd_child *child;
43 bool expired;
45 req = tevent_req_create(mem_ctx, &state, struct wb_gid2sid_state);
46 if (req == NULL) {
47 return NULL;
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);
60 } else {
61 tevent_req_done(req);
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;
74 break;
78 child = idmap_child();
80 subreq = dcerpc_wbint_Gid2Sid_send(
81 state, ev, child->binding_handle, state->dom_name,
82 gid, &state->sid);
83 if (tevent_req_nomem(subreq, req)) {
84 return tevent_req_post(req, ev);
86 tevent_req_set_callback(subreq, wb_gid2sid_done, req);
87 return 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);
99 TALLOC_FREE(subreq);
100 if (any_nt_status_not_ok(status, result, &status)) {
101 tevent_req_nterror(req, status);
102 return;
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);
111 NTSTATUS status;
113 if (tevent_req_is_nterror(req, &status)) {
114 return status;
116 sid_copy(sid, &state->sid);
117 return NT_STATUS_OK;