2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_PAM_CHAUTHTOK
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/>.
23 struct winbindd_pam_chauthtok_state
{
24 struct winbindd_response
*response
;
27 static void winbindd_pam_chauthtok_done(struct tevent_req
*subreq
);
29 struct tevent_req
*winbindd_pam_chauthtok_send(
31 struct tevent_context
*ev
,
32 struct winbindd_cli_state
*cli
,
33 struct winbindd_request
*request
)
35 struct tevent_req
*req
, *subreq
;
36 struct winbindd_pam_chauthtok_state
*state
;
37 struct winbindd_domain
*contact_domain
;
42 req
= tevent_req_create(mem_ctx
, &state
,
43 struct winbindd_pam_chauthtok_state
);
48 /* Ensure null termination */
49 request
->data
.chauthtok
.user
[
50 sizeof(request
->data
.chauthtok
.user
)-1]='\0';
52 DEBUG(3, ("[%5lu]: pam chauthtok %s\n", (unsigned long)cli
->pid
,
53 request
->data
.chauthtok
.user
));
55 status
= normalize_name_unmap(state
, request
->data
.chauthtok
.user
,
58 if (NT_STATUS_IS_OK(status
) ||
59 NT_STATUS_EQUAL(status
, NT_STATUS_FILE_RENAMED
)) {
60 fstrcpy(request
->data
.chauthtok
.user
, mapped_user
);
63 if (!canonicalize_username(request
->data
.chauthtok
.user
, domain
,
65 DEBUG(10, ("winbindd_pam_chauthtok: canonicalize_username %s "
66 "failed with\n", request
->data
.chauthtok
.user
));
67 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_USER
);
68 return tevent_req_post(req
, ev
);
71 contact_domain
= find_domain_from_name(domain
);
72 if (contact_domain
== NULL
) {
73 DEBUG(3, ("Cannot change password for [%s] -> [%s]\\[%s] "
74 "as %s is not a trusted domain\n",
75 request
->data
.chauthtok
.user
, domain
, user
, domain
));
76 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_USER
);
77 return tevent_req_post(req
, ev
);
80 subreq
= wb_domain_request_send(state
, winbind_event_context(),
81 contact_domain
, request
);
82 if (tevent_req_nomem(subreq
, req
)) {
83 return tevent_req_post(req
, ev
);
85 tevent_req_set_callback(subreq
, winbindd_pam_chauthtok_done
, req
);
89 static void winbindd_pam_chauthtok_done(struct tevent_req
*subreq
)
91 struct tevent_req
*req
= tevent_req_callback_data(
92 subreq
, struct tevent_req
);
93 struct winbindd_pam_chauthtok_state
*state
= tevent_req_data(
94 req
, struct winbindd_pam_chauthtok_state
);
97 res
= wb_domain_request_recv(subreq
, state
, &state
->response
, &err
);
100 tevent_req_nterror(req
, map_nt_error_from_unix(err
));
103 tevent_req_done(req
);
106 NTSTATUS
winbindd_pam_chauthtok_recv(struct tevent_req
*req
,
107 struct winbindd_response
*response
)
109 struct winbindd_pam_chauthtok_state
*state
= tevent_req_data(
110 req
, struct winbindd_pam_chauthtok_state
);
113 if (tevent_req_is_nterror(req
, &status
)) {
114 set_auth_errors(response
, status
);
117 *response
= *state
->response
;
118 response
->result
= WINBINDD_PENDING
;
119 state
->response
= talloc_move(response
, &state
->response
);
120 return NT_STATUS(response
->data
.auth
.nt_status
);