2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_PAM_AUTH
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 "libcli/security/dom_sid.h"
24 struct winbindd_pam_auth_state {
25 struct winbindd_request *request;
26 struct winbindd_response *response;
29 static void winbindd_pam_auth_done(struct tevent_req *subreq);
31 struct tevent_req *winbindd_pam_auth_send(TALLOC_CTX *mem_ctx,
32 struct tevent_context *ev,
33 struct winbindd_cli_state *cli,
34 struct winbindd_request *request)
36 struct tevent_req *req, *subreq;
37 struct winbindd_pam_auth_state *state;
38 struct winbindd_domain *domain;
39 fstring name_domain, name_user;
43 req = tevent_req_create(mem_ctx, &state,
44 struct winbindd_pam_auth_state);
48 state->request = request;
50 /* Ensure null termination */
51 request->data.auth.user[sizeof(request->data.auth.user)-1] = '\0';
52 request->data.auth.pass[sizeof(request->data.auth.pass)-1] = '\0';
54 DEBUG(3, ("[%5lu]: pam auth %s\n", (unsigned long)cli->pid,
55 request->data.auth.user));
57 if (!check_request_flags(request->flags)) {
58 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER_MIX);
59 return tevent_req_post(req, ev);
62 /* Parse domain and username */
64 status = normalize_name_unmap(state, request->data.auth.user, &mapped);
66 /* If the name normalization changed something, copy it over the given
69 if (NT_STATUS_IS_OK(status)
70 || NT_STATUS_EQUAL(status, NT_STATUS_FILE_RENAMED)) {
71 fstrcpy(request->data.auth.user, mapped);
74 if (!canonicalize_username(request->data.auth.user, name_domain, name_user)) {
75 tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
76 return tevent_req_post(req, ev);
79 domain = find_auth_domain(request->flags, name_domain);
81 tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
82 return tevent_req_post(req, ev);
85 subreq = wb_domain_request_send(state, server_event_context(), domain,
87 if (tevent_req_nomem(subreq, req)) {
88 return tevent_req_post(req, ev);
90 tevent_req_set_callback(subreq, winbindd_pam_auth_done, req);
94 static void winbindd_pam_auth_done(struct tevent_req *subreq)
96 struct tevent_req *req = tevent_req_callback_data(
97 subreq, struct tevent_req);
98 struct winbindd_pam_auth_state *state = tevent_req_data(
99 req, struct winbindd_pam_auth_state);
102 res = wb_domain_request_recv(subreq, state, &state->response, &err);
105 tevent_req_nterror(req, map_nt_error_from_unix(err));
108 tevent_req_done(req);
111 NTSTATUS winbindd_pam_auth_recv(struct tevent_req *req,
112 struct winbindd_response *response)
114 struct winbindd_pam_auth_state *state = tevent_req_data(
115 req, struct winbindd_pam_auth_state);
118 if (tevent_req_is_nterror(req, &status)) {
119 set_auth_errors(response, status);
122 *response = *state->response;
123 response->result = WINBINDD_PENDING;
124 state->response = talloc_move(response, &state->response);
126 status = NT_STATUS(response->data.auth.nt_status);
127 if (!NT_STATUS_IS_OK(status)) {
131 if (state->request->flags & WBFLAG_PAM_INFO3_TEXT) {
134 ok = add_trusted_domain_from_auth(
135 state->response->data.auth.validation_level,
136 &state->response->data.auth.info3,
137 &state->response->data.auth.info6);
139 DBG_ERR("add_trusted_domain_from_auth failed\n");
140 set_auth_errors(response, NT_STATUS_LOGON_FAILURE);
141 return NT_STATUS_LOGON_FAILURE;
145 if (state->request->flags & WBFLAG_PAM_CACHED_LOGIN) {
147 /* Store in-memory creds for single-signon using ntlm_auth. */
149 status = winbindd_add_memory_creds(
150 state->request->data.auth.user,
151 get_uid_from_request(state->request),
152 state->request->data.auth.pass);
153 DEBUG(10, ("winbindd_add_memory_creds returned: %s\n",