vfs_shadow_copy2: check crossmountpoints against snapdirseverywhere
[obnox/samba/samba-obnox.git] / source3 / winbindd / wb_uid2sid.c
1 /*
2    Unix SMB/CIFS implementation.
3    async uid2sid
4    Copyright (C) Volker Lendecke 2009
5
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.
10
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.
15
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/>.
18 */
19
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "librpc/gen_ndr/ndr_winbind_c.h"
23 #include "idmap_cache.h"
24 #include "idmap.h"
25 #include "../libcli/security/security.h"
26
27 struct wb_uid2sid_state {
28         struct tevent_context *ev;
29         struct dom_sid sid;
30 };
31
32 static void wb_uid2sid_done(struct tevent_req *subreq);
33
34 struct tevent_req *wb_uid2sid_send(TALLOC_CTX *mem_ctx,
35                                    struct tevent_context *ev,
36                                    uid_t uid)
37 {
38         struct tevent_req *req, *subreq;
39         struct wb_uid2sid_state *state;
40         struct winbindd_child *child;
41         bool expired;
42
43         req = tevent_req_create(mem_ctx, &state, struct wb_uid2sid_state);
44         if (req == NULL) {
45                 return NULL;
46         }
47
48         if (winbindd_use_idmap_cache()
49             && idmap_cache_find_uid2sid(uid, &state->sid, &expired)) {
50
51                 DEBUG(10, ("idmap_cache_find_uid2sid found %d%s\n",
52                            (int)uid, expired ? " (expired)": ""));
53
54                 if (!expired || idmap_is_offline()) {
55                         if (is_null_sid(&state->sid)) {
56                                 tevent_req_nterror(req,
57                                                    NT_STATUS_NONE_MAPPED);
58                         } else {
59                                 tevent_req_done(req);
60                         }
61                         return tevent_req_post(req, ev);
62                 }
63         }
64
65         child = idmap_child();
66
67         subreq = dcerpc_wbint_Uid2Sid_send(
68                 state, ev, child->binding_handle,
69                 uid, &state->sid);
70         if (tevent_req_nomem(subreq, req)) {
71                 return tevent_req_post(req, ev);
72         }
73         tevent_req_set_callback(subreq, wb_uid2sid_done, req);
74         return req;
75 }
76
77 static void wb_uid2sid_done(struct tevent_req *subreq)
78 {
79         struct tevent_req *req = tevent_req_callback_data(
80                 subreq, struct tevent_req);
81         struct wb_uid2sid_state *state = tevent_req_data(
82                 req, struct wb_uid2sid_state);
83         NTSTATUS status, result;
84
85         status = dcerpc_wbint_Uid2Sid_recv(subreq, state, &result);
86         TALLOC_FREE(subreq);
87         if (any_nt_status_not_ok(status, result, &status)) {
88                 tevent_req_nterror(req, status);
89                 return;
90         }
91         tevent_req_done(req);
92 }
93
94 NTSTATUS wb_uid2sid_recv(struct tevent_req *req, struct dom_sid *sid)
95 {
96         struct wb_uid2sid_state *state = tevent_req_data(
97                 req, struct wb_uid2sid_state);
98         NTSTATUS status;
99
100         if (tevent_req_is_nterror(req, &status)) {
101                 return status;
102         }
103         sid_copy(sid, &state->sid);
104         return NT_STATUS_OK;
105 }