[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-2311-gf1dd6cd

Volker Lendecke vlendec at samba.org
Sun Jun 14 09:27:07 GMT 2009


The branch, master has been updated
       via  f1dd6cd64dad232801749d7a55b5a66788f98171 (commit)
       via  07fac35b3b1083e2fa596a62c8be18992c15d3ef (commit)
       via  c4a97b2b414477043ce373a07722da305a03a52a (commit)
       via  eaaaea01e061927d16eca1c7472de108bf0edce3 (commit)
       via  e4fb2b9408a3a022f8e02442e1f2d0b6de04ba20 (commit)
       via  d61f3626b79e0523beadff355453145aa7b0195c (commit)
       via  225b14cf24ec1349fd79a20ec3464ea64a368a39 (commit)
       via  14889b1acbefd527623fba74e2d877d51e0fc796 (commit)
       via  d362313fea447c2bbf3c989ed45537f95653d7dc (commit)
       via  340b55a84201526f1fe84fde2318802126715e15 (commit)
       via  e3bed4848fca81fcdaaa5b44a16893653b62a50f (commit)
       via  ed3bc614cccec6167c64ac58d78344b6426cd019 (commit)
       via  0834574fdd6b469797b3b6a4edd45f321b9b9971 (commit)
       via  9b06c27cdb5f896cfd92eb103132cee258b87ca1 (commit)
       via  c049d098d1e56a56378bc105d1df89c34cc06ddb (commit)
       via  baa6084378e530b013ac002b91b56cc1e79c5e38 (commit)
      from  478503694a860018740a93296e66d5cb0caa53c9 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f1dd6cd64dad232801749d7a55b5a66788f98171
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 25 22:40:09 2009 +0200

    winbind: replace process_loop() by tevent_loop_once()

commit 07fac35b3b1083e2fa596a62c8be18992c15d3ef
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 25 22:34:48 2009 +0200

    Make rescan_trusted_domains a timed event

commit c4a97b2b414477043ce373a07722da305a03a52a
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 25 20:31:59 2009 +0200

    Do not store the listening fde

commit eaaaea01e061927d16eca1c7472de108bf0edce3
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 25 20:28:38 2009 +0200

    Avoid scanning the client list when a client exits

commit e4fb2b9408a3a022f8e02442e1f2d0b6de04ba20
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 25 20:17:23 2009 +0200

    Do not use "finished" in winbind child

commit d61f3626b79e0523beadff355453145aa7b0195c
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 16 14:21:39 2009 +0200

    Remove unused init_child_connection()

commit 225b14cf24ec1349fd79a20ec3464ea64a368a39
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 16 14:20:30 2009 +0200

    Convert winbindd_domain_info to wb_domain_request_send

commit 14889b1acbefd527623fba74e2d877d51e0fc796
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 16 13:43:03 2009 +0200

    Add winbindd_dual_ping to all children

commit d362313fea447c2bbf3c989ed45537f95653d7dc
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 16 13:25:52 2009 +0200

    Convert async_domain_request to wb_domain_request_send

commit 340b55a84201526f1fe84fde2318802126715e15
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 16 12:00:34 2009 +0200

    Add async wb_ping

commit e3bed4848fca81fcdaaa5b44a16893653b62a50f
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 16 12:00:07 2009 +0200

    Add an async wb request loop

commit ed3bc614cccec6167c64ac58d78344b6426cd019
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 13 12:13:07 2009 +0200

    Add wb_domain_request_send/recv

commit 0834574fdd6b469797b3b6a4edd45f321b9b9971
Author: Volker Lendecke <vl at samba.org>
Date:   Sun May 10 19:17:37 2009 +0200

    Remove some unused code

commit 9b06c27cdb5f896cfd92eb103132cee258b87ca1
Author: Volker Lendecke <vl at samba.org>
Date:   Sun May 10 10:49:53 2009 +0200

    Convert the winbind parent->child communication to wb_reqtrans

commit c049d098d1e56a56378bc105d1df89c34cc06ddb
Author: Volker Lendecke <vl at samba.org>
Date:   Sat May 9 20:04:27 2009 +0200

    Convert the main winbind client communication to wb_reqtrans.c

commit baa6084378e530b013ac002b91b56cc1e79c5e38
Author: Volker Lendecke <vl at samba.org>
Date:   Thu May 7 22:46:27 2009 +0200

    Make winbindd_cli_state->request a pointer instead of a struct member
    
    In itself, this is pretty pointless. But in the next steps I'll convert the
    winbind internal communication to wb_reqtrans which allocates the request
    properly. This minimizes the later diff.
    
    Volker

-----------------------------------------------------------------------

Summary of changes:
 source3/Makefile.in                       |    2 +
 source3/winbindd/wb_ping.c                |   53 +++
 source3/winbindd/winbindd.c               |  506 +++++++-----------------
 source3/winbindd/winbindd.h               |   24 +-
 source3/winbindd/winbindd_async.c         |   42 +-
 source3/winbindd/winbindd_cache.c         |  109 -----
 source3/winbindd/winbindd_ccache_access.c |   40 +-
 source3/winbindd/winbindd_domain.c        |    4 +
 source3/winbindd/winbindd_dual.c          |  615 +++++++++++++++++------------
 source3/winbindd/winbindd_group.c         |   60 ++--
 source3/winbindd/winbindd_idmap.c         |   48 ++-
 source3/winbindd/winbindd_locator.c       |   40 +-
 source3/winbindd/winbindd_misc.c          |  172 +++++----
 source3/winbindd/winbindd_ndr.c           |    1 -
 source3/winbindd/winbindd_pam.c           |  324 ++++++++--------
 source3/winbindd/winbindd_proto.h         |   39 ++-
 source3/winbindd/winbindd_sid.c           |  118 +++---
 source3/winbindd/winbindd_user.c          |   30 +-
 source3/winbindd/winbindd_util.c          |  180 +--------
 source3/winbindd/winbindd_wins.c          |   20 +-
 20 files changed, 1080 insertions(+), 1347 deletions(-)
 create mode 100644 source3/winbindd/wb_ping.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 24117d3..c657786 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1131,7 +1131,9 @@ WINBINDD_OBJ1 = \
 		winbindd/winbindd_idmap.o \
 		winbindd/winbindd_locator.o \
 		winbindd/winbindd_ndr.o \
+		winbindd/wb_ping.o \
 		auth/token_util.o \
+		../nsswitch/libwbclient/wb_reqtrans.o \
 		smbd/connection.o
 
 WINBINDD_OBJ = \
diff --git a/source3/winbindd/wb_ping.c b/source3/winbindd/wb_ping.c
new file mode 100644
index 0000000..56ecc66
--- /dev/null
+++ b/source3/winbindd/wb_ping.c
@@ -0,0 +1,53 @@
+/*
+   Unix SMB/CIFS implementation.
+   async implementation of WINBINDD_PING
+   Copyright (C) Volker Lendecke 2009
+
+   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 wb_ping_state {
+	uint8_t dummy;
+};
+
+struct tevent_req *wb_ping_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
+				struct winbindd_request *request)
+{
+	struct tevent_req *req;
+	struct wb_ping_state *state;
+
+	req = tevent_req_create(mem_ctx, &state, struct wb_ping_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	tevent_req_done(req);
+	tevent_req_post(req, ev);
+	return req;
+}
+
+NTSTATUS wb_ping_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+		      struct winbindd_response **presp)
+{
+	struct winbindd_response *resp;
+
+	resp = talloc_zero(mem_ctx, struct winbindd_response);
+	if (resp == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	*presp = resp;
+	return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 2b25616..716e0ed 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -24,10 +24,13 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "../../nsswitch/libwbclient/wbc_async.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
 
+static void remove_client(struct winbindd_cli_state *state);
+
 static bool opt_nocache = False;
 static bool interactive = False;
 
@@ -504,9 +507,29 @@ static struct winbindd_dispatch_table {
 	{ WINBINDD_NUM_CMDS, NULL, "NONE" }
 };
 
+struct winbindd_async_dispatch_table {
+	enum winbindd_cmd cmd;
+	const char *cmd_name;
+	struct tevent_req *(*send_req)(TALLOC_CTX *mem_ctx,
+				       struct tevent_context *ev,
+				       struct winbindd_request *request);
+	NTSTATUS (*recv_req)(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+			     struct winbindd_response **presp);
+};
+
+static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
+	{ WINBINDD_PING, "PING",
+	  wb_ping_send, wb_ping_recv },
+
+	{ 0, NULL, NULL, NULL }
+};
+
+static void wb_request_done(struct tevent_req *req);
+
 static void process_request(struct winbindd_cli_state *state)
 {
 	struct winbindd_dispatch_table *table = dispatch_table;
+	struct winbindd_async_dispatch_table *atable;
 
 	ZERO_STRUCT(state->response);
 
@@ -518,132 +541,68 @@ static void process_request(struct winbindd_cli_state *state)
 		return;
 
 	/* Remember who asked us. */
-	state->pid = state->request.pid;
+	state->pid = state->request->pid;
 
 	/* Process command */
 
-	for (table = dispatch_table; table->fn; table++) {
-		if (state->request.cmd == table->cmd) {
-			DEBUG(10,("process_request: request fn %s\n",
-				  table->winbindd_cmd_name ));
-			table->fn(state);
+	for (atable = async_nonpriv_table; atable->send_req; atable += 1) {
+		if (state->request->cmd == atable->cmd) {
 			break;
 		}
 	}
 
-	if (!table->fn) {
-		DEBUG(10,("process_request: unknown request fn number %d\n",
-			  (int)state->request.cmd ));
-		request_error(state);
-	}
-}
+	if (atable->send_req != NULL) {
+		struct tevent_req *req;
 
-/*
- * A list of file descriptors being monitored by select in the main processing
- * loop. winbindd_fd_event->handler is called whenever the socket is readable/writable.
- */
-
-static struct winbindd_fd_event *fd_events = NULL;
-
-void add_fd_event(struct winbindd_fd_event *ev)
-{
-	struct winbindd_fd_event *match;
+		DEBUG(10, ("process_request: Handling async request %s\n",
+			   atable->cmd_name));
 
-	/* only add unique winbindd_fd_event structs */
-
-	for (match=fd_events; match; match=match->next ) {
-#ifdef DEVELOPER
-		SMB_ASSERT( match != ev );
-#else
-		if ( match == ev )
-			return;
-#endif
-	}
-
-	DLIST_ADD(fd_events, ev);
-}
-
-void remove_fd_event(struct winbindd_fd_event *ev)
-{
-	DLIST_REMOVE(fd_events, ev);
-}
-
-/*
- * Handler for winbindd_fd_events to complete a read/write request, set up by
- * setup_async_read/setup_async_write.
- */
-
-static void rw_callback(struct winbindd_fd_event *event, int flags)
-{
-	size_t todo;
-	ssize_t done = 0;
-
-	todo = event->length - event->done;
-
-	if (event->flags & EVENT_FD_WRITE) {
-		SMB_ASSERT(flags == EVENT_FD_WRITE);
-		done = sys_write(event->fd,
-				 &((char *)event->data)[event->done],
-				 todo);
-
-		if (done <= 0) {
-			event->flags = 0;
-			event->finished(event->private_data, False);
+		req = atable->send_req(state->mem_ctx, winbind_event_context(),
+				       state->request);
+		if (req == NULL) {
+			DEBUG(0, ("process_request: atable->send failed for "
+				  "%s\n", atable->cmd_name));
+			request_error(state);
 			return;
 		}
+		tevent_req_set_callback(req, wb_request_done, state);
+		state->recv_fn = atable->recv_req;
+		return;
 	}
 
-	if (event->flags & EVENT_FD_READ) {
-		SMB_ASSERT(flags == EVENT_FD_READ);
-		done = sys_read(event->fd, &((char *)event->data)[event->done],
-				todo);
-
-		if (done <= 0) {
-			event->flags = 0;
-			event->finished(event->private_data, False);
-			return;
+	for (table = dispatch_table; table->fn; table++) {
+		if (state->request->cmd == table->cmd) {
+			DEBUG(10,("process_request: request fn %s\n",
+				  table->winbindd_cmd_name ));
+			table->fn(state);
+			break;
 		}
 	}
 
-	event->done += done;
-
-	if (event->done == event->length) {
-		event->flags = 0;
-		event->finished(event->private_data, True);
+	if (!table->fn) {
+		DEBUG(10,("process_request: unknown request fn number %d\n",
+			  (int)state->request->cmd ));
+		request_error(state);
 	}
 }
 
-/*
- * Request an async read/write on a winbindd_fd_event structure. (*finished) is called
- * when the request is completed or an error had occurred.
- */
-
-void setup_async_read(struct winbindd_fd_event *event, void *data, size_t length,
-		      void (*finished)(void *private_data, bool success),
-		      void *private_data)
+static void wb_request_done(struct tevent_req *req)
 {
-	SMB_ASSERT(event->flags == 0);
-	event->data = data;
-	event->length = length;
-	event->done = 0;
-	event->handler = rw_callback;
-	event->finished = finished;
-	event->private_data = private_data;
-	event->flags = EVENT_FD_READ;
-}
-
-void setup_async_write(struct winbindd_fd_event *event, void *data, size_t length,
-		       void (*finished)(void *private_data, bool success),
-		       void *private_data)
-{
-	SMB_ASSERT(event->flags == 0);
-	event->data = data;
-	event->length = length;
-	event->done = 0;
-	event->handler = rw_callback;
-	event->finished = finished;
-	event->private_data = private_data;
-	event->flags = EVENT_FD_WRITE;
+	struct winbindd_cli_state *state = tevent_req_callback_data(
+		req, struct winbindd_cli_state);
+	NTSTATUS status;
+	struct winbindd_response *response;
+
+	status = state->recv_fn(req, state->mem_ctx, &response);
+	TALLOC_FREE(req);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(10, ("returning %s\n", nt_errstr(status)));
+		request_error(state);
+	}
+	state->response = *response;
+	state->response.result = WINBINDD_PENDING;
+	state->response.length = sizeof(struct winbindd_response);
+	request_ok(state);
 }
 
 /*
@@ -656,58 +615,52 @@ void setup_async_write(struct winbindd_fd_event *event, void *data, size_t lengt
  * to call request_finished which schedules sending the response.
  */
 
-static void request_len_recv(void *private_data, bool success);
-static void request_recv(void *private_data, bool success);
-static void request_main_recv(void *private_data, bool success);
 static void request_finished(struct winbindd_cli_state *state);
-static void response_main_sent(void *private_data, bool success);
-static void response_extra_sent(void *private_data, bool success);
 
-static void response_extra_sent(void *private_data, bool success)
+static void winbind_client_request_read(struct tevent_req *req);
+static void winbind_client_response_written(struct tevent_req *req);
+
+static void request_finished(struct winbindd_cli_state *state)
 {
-	struct winbindd_cli_state *state =
-		talloc_get_type_abort(private_data, struct winbindd_cli_state);
+	struct tevent_req *req;
 
-	TALLOC_FREE(state->mem_ctx);
+	TALLOC_FREE(state->request);
 
-	if (!success) {
-		state->finished = True;
+	req = wb_resp_write_send(state, winbind_event_context(),
+				 state->out_queue, state->sock,
+				 &state->response);
+	if (req == NULL) {
+		remove_client(state);
 		return;
 	}
-
-	setup_async_read(&state->fd_event, &state->request, sizeof(uint32),
-			 request_len_recv, state);
+	tevent_req_set_callback(req, winbind_client_response_written, state);
 }
 
-static void response_main_sent(void *private_data, bool success)
+static void winbind_client_response_written(struct tevent_req *req)
 {
-	struct winbindd_cli_state *state =
-		talloc_get_type_abort(private_data, struct winbindd_cli_state);
-
-	if (!success) {
-		state->finished = True;
+	struct winbindd_cli_state *state = tevent_req_callback_data(
+		req, struct winbindd_cli_state);
+	ssize_t ret;
+	int err;
+
+	ret = wb_resp_write_recv(req, &err);
+	TALLOC_FREE(req);
+	if (ret == -1) {
+		DEBUG(2, ("Could not write response to client: %s\n",
+			  strerror(err)));
+		remove_client(state);
 		return;
 	}
 
-	if (state->response.length == sizeof(state->response)) {
-		TALLOC_FREE(state->mem_ctx);
+	TALLOC_FREE(state->mem_ctx);
 
-		setup_async_read(&state->fd_event, &state->request,
-				 sizeof(uint32), request_len_recv, state);
+	req = wb_req_read_send(state, winbind_event_context(), state->sock,
+			       WINBINDD_MAX_EXTRA_DATA);
+	if (req == NULL) {
+		remove_client(state);
 		return;
 	}
-
-	setup_async_write(&state->fd_event, state->response.extra_data.data,
-			  state->response.length - sizeof(state->response),
-			  response_extra_sent, state);
-}
-
-static void request_finished(struct winbindd_cli_state *state)
-{
-	/* Make sure request.extra_data is freed when finish processing a request */
-	SAFE_FREE(state->request.extra_data.data);
-	setup_async_write(&state->fd_event, &state->response,
-			  sizeof(state->response), response_main_sent, state);
+	tevent_req_set_callback(req, winbind_client_request_read, state);
 }
 
 void request_error(struct winbindd_cli_state *state)
@@ -724,90 +677,13 @@ void request_ok(struct winbindd_cli_state *state)
 	request_finished(state);
 }
 
-static void request_len_recv(void *private_data, bool success)
-{
-	struct winbindd_cli_state *state =
-		talloc_get_type_abort(private_data, struct winbindd_cli_state);
-
-	if (!success) {
-		state->finished = True;
-		return;
-	}
-
-	if (*(uint32 *)(void *)(&state->request) != sizeof(state->request)) {
-		DEBUG(0,("request_len_recv: Invalid request size received: %d (expected %u)\n",
-			 *(uint32_t *)(void *)(&state->request),
-			 (uint32_t)sizeof(state->request)));
-		state->finished = True;
-		return;
-	}
-
-	setup_async_read(&state->fd_event,
-			 (uint32 *)(void *)(&state->request)+1,
-			 sizeof(state->request) - sizeof(uint32),
-			 request_main_recv, state);
-}
-
-static void request_main_recv(void *private_data, bool success)
-{
-	struct winbindd_cli_state *state =
-		talloc_get_type_abort(private_data, struct winbindd_cli_state);
-
-	if (!success) {
-		state->finished = True;
-		return;
-	}
-
-	if (state->request.extra_len == 0) {
-		state->request.extra_data.data = NULL;
-		request_recv(state, True);
-		return;
-	}
-
-	if ((!state->privileged) &&
-	    (state->request.extra_len > WINBINDD_MAX_EXTRA_DATA)) {
-		DEBUG(3, ("Got request with %d bytes extra data on "
-			  "unprivileged socket\n", (int)state->request.extra_len));
-		state->request.extra_data.data = NULL;
-		state->finished = True;
-		return;
-	}
-
-	state->request.extra_data.data =
-		SMB_MALLOC_ARRAY(char, state->request.extra_len + 1);
-
-	if (state->request.extra_data.data == NULL) {
-		DEBUG(0, ("malloc failed\n"));
-		state->finished = True;
-		return;
-	}
-
-	/* Ensure null termination */
-	state->request.extra_data.data[state->request.extra_len] = '\0';
-
-	setup_async_read(&state->fd_event, state->request.extra_data.data,
-			 state->request.extra_len, request_recv, state);
-}
-
-static void request_recv(void *private_data, bool success)
-{
-	struct winbindd_cli_state *state =
-		talloc_get_type_abort(private_data, struct winbindd_cli_state);
-
-	if (!success) {
-		state->finished = True;
-		return;
-	}
-
-	process_request(state);
-}
-
 /* Process a new connection by adding it to the client connection list */
 
 static void new_connection(int listen_sock, bool privileged)
 {
 	struct sockaddr_un sunaddr;
 	struct winbindd_cli_state *state;
+	struct tevent_req *req;
 	socklen_t len;
 	int sock;
 
@@ -834,22 +710,48 @@ static void new_connection(int listen_sock, bool privileged)
 
 	state->sock = sock;
 
+	state->out_queue = tevent_queue_create(state, "winbind client reply");
+	if (state->out_queue == NULL) {
+		close(sock);
+		TALLOC_FREE(state);
+		return;
+	}
+
 	state->last_access = time(NULL);	
 
 	state->privileged = privileged;
 
-	state->fd_event.fd = state->sock;
-	state->fd_event.flags = 0;
-	add_fd_event(&state->fd_event);
-
-	setup_async_read(&state->fd_event, &state->request, sizeof(uint32),
-			 request_len_recv, state);
+	req = wb_req_read_send(state, winbind_event_context(), state->sock,
+			       WINBINDD_MAX_EXTRA_DATA);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list