docs: Add very basic samba manpage.
[Samba/vl.git] / source3 / winbindd / wb_getpwsid.c
blobef54ee5f48e9a0ef28c9e09eb85b2469369edd7c
1 /*
2 Unix SMB/CIFS implementation.
3 async getpwsid
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 "../libcli/security/security.h"
25 struct wb_getpwsid_state {
26 struct tevent_context *ev;
27 struct dom_sid sid;
28 struct wbint_userinfo *userinfo;
29 struct winbindd_pw *pw;
32 static void wb_getpwsid_queryuser_done(struct tevent_req *subreq);
33 static void wb_getpwsid_lookupsid_done(struct tevent_req *subreq);
34 static void wb_getpwsid_done(struct tevent_req *subreq);
36 struct tevent_req *wb_getpwsid_send(TALLOC_CTX *mem_ctx,
37 struct tevent_context *ev,
38 const struct dom_sid *user_sid,
39 struct winbindd_pw *pw)
41 struct tevent_req *req, *subreq;
42 struct wb_getpwsid_state *state;
44 req = tevent_req_create(mem_ctx, &state, struct wb_getpwsid_state);
45 if (req == NULL) {
46 return NULL;
48 sid_copy(&state->sid, user_sid);
49 state->ev = ev;
50 state->pw = pw;
52 subreq = wb_queryuser_send(state, ev, &state->sid);
53 if (tevent_req_nomem(subreq, req)) {
54 return tevent_req_post(req, ev);
56 tevent_req_set_callback(subreq, wb_getpwsid_queryuser_done, req);
57 return req;
60 static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
62 struct tevent_req *req = tevent_req_callback_data(
63 subreq, struct tevent_req);
64 struct wb_getpwsid_state *state = tevent_req_data(
65 req, struct wb_getpwsid_state);
66 NTSTATUS status;
68 status = wb_queryuser_recv(subreq, state, &state->userinfo);
69 TALLOC_FREE(subreq);
70 if (tevent_req_nterror(req, status)) {
71 return;
74 if ((state->userinfo->acct_name != NULL)
75 && (state->userinfo->acct_name[0] != '\0')) {
77 * QueryUser got us a name, let's got directly to the
78 * fill_pwent step
80 subreq = wb_fill_pwent_send(state, state->ev, state->userinfo,
81 state->pw);
82 if (tevent_req_nomem(subreq, req)) {
83 return;
85 tevent_req_set_callback(subreq, wb_getpwsid_done, req);
86 return;
90 * QueryUser didn't get us a name, do it via LSA.
92 subreq = wb_lookupsid_send(state, state->ev,
93 &state->userinfo->user_sid);
94 if (tevent_req_nomem(subreq, req)) {
95 return;
97 tevent_req_set_callback(subreq, wb_getpwsid_lookupsid_done, req);
100 static void wb_getpwsid_lookupsid_done(struct tevent_req *subreq)
102 struct tevent_req *req = tevent_req_callback_data(
103 subreq, struct tevent_req);
104 struct wb_getpwsid_state *state = tevent_req_data(
105 req, struct wb_getpwsid_state);
106 NTSTATUS status;
107 enum lsa_SidType type;
108 const char *domain;
110 status = wb_lookupsid_recv(subreq, state->userinfo, &type, &domain,
111 &state->userinfo->acct_name);
112 TALLOC_FREE(subreq);
113 if (tevent_req_nterror(req, status)) {
114 return;
116 subreq = wb_fill_pwent_send(state, state->ev, state->userinfo,
117 state->pw);
118 if (tevent_req_nomem(subreq, req)) {
119 return;
121 tevent_req_set_callback(subreq, wb_getpwsid_done, req);
124 static void wb_getpwsid_done(struct tevent_req *subreq)
126 struct tevent_req *req = tevent_req_callback_data(
127 subreq, struct tevent_req);
128 NTSTATUS status;
130 status = wb_fill_pwent_recv(subreq);
131 if (tevent_req_nterror(req, status)) {
132 return;
134 tevent_req_done(req);
137 NTSTATUS wb_getpwsid_recv(struct tevent_req *req)
139 return tevent_req_simple_recv_ntstatus(req);