s4-repl: Use NULL for pointer test when checking for ldb_msg_new() failure
[Samba.git] / source3 / winbindd / winbindd_pam_auth_crap.c
blob2fb5111510c78bd8c82913fe084662ee7afa9dc6
1 /*
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/>.
20 #include "includes.h"
21 #include "winbindd.h"
23 struct winbindd_pam_auth_crap_state {
24 struct winbindd_response *response;
27 static void winbindd_pam_auth_crap_done(struct tevent_req *subreq);
29 struct tevent_req *winbindd_pam_auth_crap_send(
30 TALLOC_CTX *mem_ctx,
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_auth_crap_state *state;
37 struct winbindd_domain *domain;
39 req = tevent_req_create(mem_ctx, &state,
40 struct winbindd_pam_auth_crap_state);
41 if (req == NULL) {
42 return NULL;
45 /* Ensure null termination */
46 request->data.auth_crap.user[
47 sizeof(request->data.auth_crap.user)-1] = '\0';
48 request->data.auth_crap.domain[
49 sizeof(request->data.auth_crap.domain)-1] = '\0';
50 request->data.auth_crap.workstation[
51 sizeof(request->data.auth_crap.workstation)-1] = '\0';
53 DEBUG(3, ("[%5lu]: pam auth crap domain: [%s] user: %s\n",
54 (unsigned long)cli->pid,
55 request->data.auth_crap.domain,
56 request->data.auth_crap.user));
58 if (!check_request_flags(request->flags)) {
59 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER_MIX);
60 return tevent_req_post(req, ev);
63 if ((request->data.auth_crap.domain[0] == '\0')
64 && lp_winbind_use_default_domain()) {
65 fstrcpy(request->data.auth_crap.domain,
66 lp_workgroup());
69 domain = find_auth_domain(
70 request->flags, request->data.auth_crap.domain);
71 if (domain == NULL) {
72 tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
73 return tevent_req_post(req, ev);
76 if (request->data.auth_crap.workstation[0] == '\0') {
77 fstrcpy(request->data.auth_crap.workstation, lp_netbios_name());
80 subreq = wb_domain_request_send(state, winbind_event_context(), domain,
81 request);
82 if (tevent_req_nomem(subreq, req)) {
83 return tevent_req_post(req, ev);
85 tevent_req_set_callback(subreq, winbindd_pam_auth_crap_done, req);
86 return req;
89 static void winbindd_pam_auth_crap_done(struct tevent_req *subreq)
91 struct tevent_req *req = tevent_req_callback_data(
92 subreq, struct tevent_req);
93 struct winbindd_pam_auth_crap_state *state = tevent_req_data(
94 req, struct winbindd_pam_auth_crap_state);
95 int res, err;
97 res = wb_domain_request_recv(subreq, state, &state->response, &err);
98 TALLOC_FREE(subreq);
99 if (res == -1) {
100 tevent_req_nterror(req, map_nt_error_from_unix(err));
101 return;
103 tevent_req_done(req);
106 NTSTATUS winbindd_pam_auth_crap_recv(struct tevent_req *req,
107 struct winbindd_response *response)
109 struct winbindd_pam_auth_crap_state *state = tevent_req_data(
110 req, struct winbindd_pam_auth_crap_state);
111 NTSTATUS status;
113 if (tevent_req_is_nterror(req, &status)) {
114 set_auth_errors(response, status);
115 return 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);