s3: Lift the server_messaging_context from notify_job_status
[Samba/gbeck.git] / source3 / winbindd / wb_uid2sid.c
blob18ef3b214a100bc3e8871134eab045ed1a00798c
1 /*
2 Unix SMB/CIFS implementation.
3 async uid2sid
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"
24 struct wb_uid2sid_state {
25 struct tevent_context *ev;
26 char *dom_name;
27 struct dom_sid sid;
30 static void wb_uid2sid_done(struct tevent_req *subreq);
32 struct tevent_req *wb_uid2sid_send(TALLOC_CTX *mem_ctx,
33 struct tevent_context *ev,
34 uid_t uid)
36 struct tevent_req *req, *subreq;
37 struct wb_uid2sid_state *state;
38 struct winbindd_domain *domain;
39 struct winbindd_child *child;
40 bool expired;
42 req = tevent_req_create(mem_ctx, &state, struct wb_uid2sid_state);
43 if (req == NULL) {
44 return NULL;
47 if (winbindd_use_idmap_cache()
48 && idmap_cache_find_uid2sid(uid, &state->sid, &expired)) {
50 DEBUG(10, ("idmap_cache_find_uid2sid found %d%s\n",
51 (int)uid, expired ? " (expired)": ""));
53 if (!expired || idmap_is_offline()) {
54 if (is_null_sid(&state->sid)) {
55 tevent_req_nterror(req,
56 NT_STATUS_NONE_MAPPED);
57 } else {
58 tevent_req_done(req);
60 return tevent_req_post(req, ev);
64 state->dom_name = NULL;
66 for (domain = domain_list(); domain != NULL; domain = domain->next) {
67 if (domain->have_idmap_config
68 && (uid >= domain->id_range_low)
69 && (uid <= domain->id_range_high)) {
70 state->dom_name = domain->name;
71 break;
75 child = idmap_child();
77 subreq = rpccli_wbint_Uid2Sid_send(
78 state, ev, child->rpccli, state->dom_name,
79 uid, &state->sid);
80 if (tevent_req_nomem(subreq, req)) {
81 return tevent_req_post(req, ev);
83 tevent_req_set_callback(subreq, wb_uid2sid_done, req);
84 return req;
87 static void wb_uid2sid_done(struct tevent_req *subreq)
89 struct tevent_req *req = tevent_req_callback_data(
90 subreq, struct tevent_req);
91 struct wb_uid2sid_state *state = tevent_req_data(
92 req, struct wb_uid2sid_state);
93 NTSTATUS status, result;
95 status = rpccli_wbint_Uid2Sid_recv(subreq, state, &result);
96 TALLOC_FREE(subreq);
97 if (!NT_STATUS_IS_OK(status)) {
98 tevent_req_nterror(req, status);
99 return;
101 if (!NT_STATUS_IS_OK(result)) {
102 tevent_req_nterror(req, result);
103 return;
105 tevent_req_done(req);
108 NTSTATUS wb_uid2sid_recv(struct tevent_req *req, struct dom_sid *sid)
110 struct wb_uid2sid_state *state = tevent_req_data(
111 req, struct wb_uid2sid_state);
112 NTSTATUS status;
114 if (tevent_req_is_nterror(req, &status)) {
115 return status;
117 sid_copy(sid, &state->sid);
118 return NT_STATUS_OK;