s3: Convert WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP to the new async API
authorVolker Lendecke <vl@samba.org>
Tue, 20 Apr 2010 09:11:19 +0000 (11:11 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 23 Apr 2010 21:41:04 +0000 (23:41 +0200)
source3/Makefile.in
source3/winbindd/winbindd.c
source3/winbindd/winbindd_pam.c
source3/winbindd/winbindd_pam_chng_pswd_auth_crap.c [new file with mode: 0644]
source3/winbindd/winbindd_proto.h

index 78c81c40d72b1b0f74851b924be294ab5b72c035..5551ee4510176ae605c8fea3e025c3b7d856c2ae 100644 (file)
@@ -1242,6 +1242,7 @@ WINBINDD_OBJ1 = \
                winbindd/winbindd_pam_auth.o \
                winbindd/winbindd_pam_auth_crap.o \
                winbindd/winbindd_pam_chauthtok.o \
+               winbindd/winbindd_pam_chng_pswd_auth_crap.o \
                winbindd/winbindd_pam_logoff.o \
                auth/token_util.o \
                auth/check_samsec.o \
index 3bd2ad7c09ddc29369d270492a4dd548178070f9..4d00269970ece66ab6fb854914a4fb8e7e485515 100644 (file)
@@ -442,10 +442,6 @@ static struct winbindd_dispatch_table {
        const char *winbindd_cmd_name;
 } dispatch_table[] = {
 
-       /* PAM auth functions */
-
-       { WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, winbindd_pam_chng_pswd_auth_crap, "CHNG_PSWD_AUTH_CRAP" },
-
        /* Enumeration functions */
 
        { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains,
@@ -554,6 +550,9 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
          winbindd_pam_logoff_send, winbindd_pam_logoff_recv },
        { WINBINDD_PAM_CHAUTHTOK, "PAM_CHAUTHTOK",
          winbindd_pam_chauthtok_send, winbindd_pam_chauthtok_recv },
+       { WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, "PAM_CHNG_PSWD_AUTH_CRAP",
+         winbindd_pam_chng_pswd_auth_crap_send,
+         winbindd_pam_chng_pswd_auth_crap_recv },
 
        { 0, NULL, NULL, NULL }
 };
index 3f350e3fb2c09906e1c38d2e53c4e4e05da24f9a..ae7a3639245fd278c161d573188e368a64e8b855 100644 (file)
@@ -2127,48 +2127,6 @@ process_result:
 
 /* Change user password with auth crap*/
 
-void winbindd_pam_chng_pswd_auth_crap(struct winbindd_cli_state *state)
-{
-       struct winbindd_domain *domain = NULL;
-       const char *domain_name = NULL;
-
-       /* Ensure null termination */
-       state->request->data.chng_pswd_auth_crap.user[
-               sizeof(state->request->data.chng_pswd_auth_crap.user)-1]=0;
-       state->request->data.chng_pswd_auth_crap.domain[
-               sizeof(state->request->data.chng_pswd_auth_crap.domain)-1]=0;
-
-       DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
-                 (unsigned long)state->pid,
-                 state->request->data.chng_pswd_auth_crap.domain,
-                 state->request->data.chng_pswd_auth_crap.user));
-
-       if (*state->request->data.chng_pswd_auth_crap.domain != '\0') {
-               domain_name = state->request->data.chng_pswd_auth_crap.domain;
-       } else if (lp_winbind_use_default_domain()) {
-               domain_name = lp_workgroup();
-       }
-
-       if (domain_name != NULL)
-               domain = find_domain_from_name(domain_name);
-
-       if (domain != NULL) {
-               DEBUG(7, ("[%5lu]: pam auth crap changing pswd in domain: "
-                         "%s\n", (unsigned long)state->pid,domain->name));
-               sendto_domain(state, domain);
-               return;
-       }
-
-       set_auth_errors(state->response, NT_STATUS_NO_SUCH_USER);
-       DEBUG(5, ("CRAP change password  for %s\\%s returned %s (PAM: %d)\n",
-                 state->request->data.chng_pswd_auth_crap.domain,
-                 state->request->data.chng_pswd_auth_crap.user,
-                 state->response->data.auth.nt_status_string,
-                 state->response->data.auth.pam_error));
-       request_error(state);
-       return;
-}
-
 enum winbindd_result winbindd_dual_pam_chng_pswd_auth_crap(struct winbindd_domain *domainSt, struct winbindd_cli_state *state)
 {
        NTSTATUS result;
diff --git a/source3/winbindd/winbindd_pam_chng_pswd_auth_crap.c b/source3/winbindd/winbindd_pam_chng_pswd_auth_crap.c
new file mode 100644 (file)
index 0000000..9133a91
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+   Unix SMB/CIFS implementation.
+   async implementation of WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP
+   Copyright (C) Volker Lendecke 2010
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+
+struct winbindd_pam_chng_pswd_auth_crap_state {
+       struct winbindd_request *request;
+       struct winbindd_response *response;
+};
+
+static void winbindd_pam_chng_pswd_auth_crap_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_pam_chng_pswd_auth_crap_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct winbindd_cli_state *cli,
+       struct winbindd_request *request)
+{
+       struct tevent_req *req, *subreq;
+       struct winbindd_pam_chng_pswd_auth_crap_state *state;
+       struct winbindd_domain *domain;
+       const char *domain_name;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct winbindd_pam_chng_pswd_auth_crap_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->request = request;
+
+       /* Ensure null termination */
+       request->data.chng_pswd_auth_crap.user[
+               sizeof(request->data.chng_pswd_auth_crap.user)-1]='\0';
+       request->data.chng_pswd_auth_crap.domain[
+               sizeof(request->data.chng_pswd_auth_crap.domain)-1]=0;
+
+       DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
+                 (unsigned long)cli->pid,
+                 request->data.chng_pswd_auth_crap.domain,
+                 request->data.chng_pswd_auth_crap.user));
+
+       domain_name = NULL;
+       if (*state->request->data.chng_pswd_auth_crap.domain != '\0') {
+               domain_name = state->request->data.chng_pswd_auth_crap.domain;
+       } else if (lp_winbind_use_default_domain()) {
+               domain_name = lp_workgroup();
+       }
+
+       domain = NULL;
+       if (domain_name != NULL) {
+               domain = find_domain_from_name(domain_name);
+       }
+
+       if (domain == NULL) {
+               tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = wb_domain_request_send(state, winbind_event_context(),
+                                       domain, request);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, winbindd_pam_chng_pswd_auth_crap_done,
+                               req);
+       return req;
+}
+
+static void winbindd_pam_chng_pswd_auth_crap_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct winbindd_pam_chng_pswd_auth_crap_state *state = tevent_req_data(
+               req, struct winbindd_pam_chng_pswd_auth_crap_state);
+       int res, err;
+
+       res = wb_domain_request_recv(subreq, state, &state->response, &err);
+       TALLOC_FREE(subreq);
+       if (res == -1) {
+               tevent_req_nterror(req, map_nt_error_from_unix(err));
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS winbindd_pam_chng_pswd_auth_crap_recv(
+       struct tevent_req *req,
+       struct winbindd_response *response)
+{
+       struct winbindd_pam_chng_pswd_auth_crap_state *state = tevent_req_data(
+               req, struct winbindd_pam_chng_pswd_auth_crap_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               set_auth_errors(response, status);
+               return status;
+       }
+       *response = *state->response;
+       response->result = WINBINDD_PENDING;
+       state->response = talloc_move(response, &state->response);
+
+       return NT_STATUS(response->data.auth.nt_status);
+}
index 221c51ed85bcaf2ef27f2395a372cf597e588990..2bf33cbc1ef092838cde6c02d693764df715d0cb 100644 (file)
@@ -391,7 +391,6 @@ enum winbindd_result winbindd_dual_pam_chauthtok(struct winbindd_domain *contact
                                                 struct winbindd_cli_state *state);
 enum winbindd_result winbindd_dual_pam_logoff(struct winbindd_domain *domain,
                                              struct winbindd_cli_state *state) ;
-void winbindd_pam_chng_pswd_auth_crap(struct winbindd_cli_state *state);
 enum winbindd_result winbindd_dual_pam_chng_pswd_auth_crap(struct winbindd_domain *domainSt, struct winbindd_cli_state *state);
 
 /* The following definitions come from winbindd/winbindd_util.c  */
@@ -879,4 +878,13 @@ struct tevent_req *winbindd_pam_logoff_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_pam_logoff_recv(struct tevent_req *req,
                                  struct winbindd_response *response);
 
+struct tevent_req *winbindd_pam_chng_pswd_auth_crap_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct winbindd_cli_state *cli,
+       struct winbindd_request *request);
+NTSTATUS winbindd_pam_chng_pswd_auth_crap_recv(
+       struct tevent_req *req,
+       struct winbindd_response *response);
+
 #endif /*  _WINBINDD_PROTO_H_  */