nbt: fix WinXP S3 domain join: alignment of nbt_netlogon_response_from_pdc
[Samba.git] / source3 / winbindd / wb_getpwsid.c
blob3c942f0857c676d7a3df7a22cf167566b91bb6cb
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 winbindd_domain *user_domain;
27 struct tevent_context *ev;
28 struct dom_sid sid;
29 struct wbint_userinfo *userinfo;
30 struct winbindd_pw *pw;
33 static void wb_getpwsid_queryuser_done(struct tevent_req *subreq);
34 static void wb_getpwsid_lookupsid_done(struct tevent_req *subreq);
35 static void wb_getpwsid_done(struct tevent_req *subreq);
37 struct tevent_req *wb_getpwsid_send(TALLOC_CTX *mem_ctx,
38 struct tevent_context *ev,
39 const struct dom_sid *user_sid,
40 struct winbindd_pw *pw)
42 struct tevent_req *req, *subreq;
43 struct wb_getpwsid_state *state;
45 req = tevent_req_create(mem_ctx, &state, struct wb_getpwsid_state);
46 if (req == NULL) {
47 return NULL;
49 sid_copy(&state->sid, user_sid);
50 state->ev = ev;
51 state->pw = pw;
53 state->user_domain = find_domain_from_sid_noinit(user_sid);
54 if (state->user_domain == NULL) {
55 tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
56 return tevent_req_post(req, ev);
59 subreq = wb_queryuser_send(state, ev, &state->sid);
60 if (tevent_req_nomem(subreq, req)) {
61 return tevent_req_post(req, ev);
63 tevent_req_set_callback(subreq, wb_getpwsid_queryuser_done, req);
64 return req;
67 static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
69 struct tevent_req *req = tevent_req_callback_data(
70 subreq, struct tevent_req);
71 struct wb_getpwsid_state *state = tevent_req_data(
72 req, struct wb_getpwsid_state);
73 NTSTATUS status;
75 status = wb_queryuser_recv(subreq, state, &state->userinfo);
76 TALLOC_FREE(subreq);
77 if (tevent_req_nterror(req, status)) {
78 return;
81 if ((state->userinfo->acct_name != NULL)
82 && (state->userinfo->acct_name[0] != '\0')) {
84 * QueryUser got us a name, let's got directly to the
85 * fill_pwent step
87 subreq = wb_fill_pwent_send(state, state->ev, state->userinfo,
88 state->pw);
89 if (tevent_req_nomem(subreq, req)) {
90 return;
92 tevent_req_set_callback(subreq, wb_getpwsid_done, req);
93 return;
97 * QueryUser didn't get us a name, do it via LSA.
99 subreq = wb_lookupsid_send(state, state->ev,
100 &state->userinfo->user_sid);
101 if (tevent_req_nomem(subreq, req)) {
102 return;
104 tevent_req_set_callback(subreq, wb_getpwsid_lookupsid_done, req);
107 static void wb_getpwsid_lookupsid_done(struct tevent_req *subreq)
109 struct tevent_req *req = tevent_req_callback_data(
110 subreq, struct tevent_req);
111 struct wb_getpwsid_state *state = tevent_req_data(
112 req, struct wb_getpwsid_state);
113 NTSTATUS status;
114 enum lsa_SidType type;
115 const char *domain;
117 status = wb_lookupsid_recv(subreq, state->userinfo, &type, &domain,
118 &state->userinfo->acct_name);
119 TALLOC_FREE(subreq);
120 if (tevent_req_nterror(req, status)) {
121 return;
123 subreq = wb_fill_pwent_send(state, state->ev, state->userinfo,
124 state->pw);
125 if (tevent_req_nomem(subreq, req)) {
126 return;
128 tevent_req_set_callback(subreq, wb_getpwsid_done, req);
131 static void wb_getpwsid_done(struct tevent_req *subreq)
133 struct tevent_req *req = tevent_req_callback_data(
134 subreq, struct tevent_req);
135 NTSTATUS status;
137 status = wb_fill_pwent_recv(subreq);
138 if (tevent_req_nterror(req, status)) {
139 return;
141 tevent_req_done(req);
144 NTSTATUS wb_getpwsid_recv(struct tevent_req *req)
146 NTSTATUS status;
148 if (tevent_req_is_nterror(req, &status)) {
149 return status;
151 return NT_STATUS_OK;