2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_PAM_AUTH_CRAP
4 Copyright (C) Volker Lendecke 2010
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/>.
22 #include "rpc_client/util_netlogon.h"
23 #include "libcli/security/dom_sid.h"
25 struct winbindd_pam_auth_crap_state {
26 struct winbindd_response *response;
27 struct netr_SamInfo3 *info3;
31 static void winbindd_pam_auth_crap_done(struct tevent_req *subreq);
33 struct tevent_req *winbindd_pam_auth_crap_send(
35 struct tevent_context *ev,
36 struct winbindd_cli_state *cli,
37 struct winbindd_request *request)
39 struct tevent_req *req, *subreq;
40 struct winbindd_pam_auth_crap_state *state;
41 struct winbindd_domain *domain;
42 const char *auth_domain = NULL;
44 req = tevent_req_create(mem_ctx, &state,
45 struct winbindd_pam_auth_crap_state);
50 state->flags = request->flags;
52 if (state->flags & WBFLAG_PAM_AUTH_PAC) {
55 status = winbindd_pam_auth_pac_send(cli, &state->info3);
56 if (NT_STATUS_IS_OK(status)) {
57 /* Defer filling out response to recv */
60 tevent_req_nterror(req, status);
63 return tevent_req_post(req, ev);
66 /* Ensure null termination */
67 request->data.auth_crap.user[
68 sizeof(request->data.auth_crap.user)-1] = '\0';
69 request->data.auth_crap.domain[
70 sizeof(request->data.auth_crap.domain)-1] = '\0';
71 request->data.auth_crap.workstation[
72 sizeof(request->data.auth_crap.workstation)-1] = '\0';
74 DEBUG(3, ("[%5lu]: pam auth crap domain: [%s] user: %s\n",
75 (unsigned long)cli->pid,
76 request->data.auth_crap.domain,
77 request->data.auth_crap.user));
79 if (!check_request_flags(request->flags)) {
80 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER_MIX);
81 return tevent_req_post(req, ev);
84 auth_domain = request->data.auth_crap.domain;
85 if (auth_domain[0] == '\0') {
86 auth_domain = lp_workgroup();
89 domain = find_auth_domain(request->flags, auth_domain);
91 tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
92 return tevent_req_post(req, ev);
95 if (request->data.auth_crap.workstation[0] == '\0') {
96 fstrcpy(request->data.auth_crap.workstation, lp_netbios_name());
99 subreq = wb_domain_request_send(state, server_event_context(), domain,
101 if (tevent_req_nomem(subreq, req)) {
102 return tevent_req_post(req, ev);
104 tevent_req_set_callback(subreq, winbindd_pam_auth_crap_done, req);
108 static void winbindd_pam_auth_crap_done(struct tevent_req *subreq)
110 struct tevent_req *req = tevent_req_callback_data(
111 subreq, struct tevent_req);
112 struct winbindd_pam_auth_crap_state *state = tevent_req_data(
113 req, struct winbindd_pam_auth_crap_state);
116 res = wb_domain_request_recv(subreq, state, &state->response, &err);
119 tevent_req_nterror(req, map_nt_error_from_unix(err));
122 tevent_req_done(req);
125 NTSTATUS winbindd_pam_auth_crap_recv(struct tevent_req *req,
126 struct winbindd_response *response)
128 struct winbindd_pam_auth_crap_state *state = tevent_req_data(
129 req, struct winbindd_pam_auth_crap_state);
132 if (tevent_req_is_nterror(req, &status)) {
133 set_auth_errors(response, status);
137 if (state->flags & WBFLAG_PAM_AUTH_PAC) {
138 uint16_t validation_level;
139 union netr_Validation *validation = NULL;
141 status = map_info3_to_validation(talloc_tos(),
145 if (!NT_STATUS_IS_OK(status)) {
149 status = append_auth_data(response,
155 TALLOC_FREE(validation);
160 if (NT_STATUS_IS_OK(NT_STATUS(state->response->data.auth.nt_status)) &&
161 (state->flags & WBFLAG_PAM_INFO3_TEXT))
165 ok = add_trusted_domain_from_auth(
166 state->response->data.auth.validation_level,
167 &state->response->data.auth.info3,
168 &state->response->data.auth.info6);
170 DBG_ERR("add_trusted_domain_from_auth failed\n");
171 set_auth_errors(response, NT_STATUS_LOGON_FAILURE);
172 return NT_STATUS_LOGON_FAILURE;
176 *response = *state->response;
177 response->result = WINBINDD_PENDING;
178 state->response = talloc_move(response, &state->response);
179 return NT_STATUS(response->data.auth.nt_status);