From 55d4d36993293fee914a009f1d8f05810e347f2b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Jan 2005 00:54:57 +0000 Subject: r5102: This is a major simplification of the logic for controlling top level servers in smbd. The old code still contained a fairly bit of legacy from the time when smbd was only handling SMB connection. The new code gets rid of all of the smb_server specific code in smbd/, and creates a much simpler infrastructures for new server code. Major changes include: - simplified the process model code a lot. - got rid of the top level server and service structures completely. The top level context is now the event_context. This got rid of service.h and server.h completely (they were the most confusing parts of the old code) - added service_stream.[ch] for the helper functions that are specific to stream type services (services that handle streams, and use a logically separate process per connection) - got rid of the builtin idle_handler code in the service logic, as none of the servers were using it, and it can easily be handled by a server in future by adding its own timed_event to the event context. - fixed some major memory leaks in the rpc server code. - added registration of servers, rather than hard coding our list of possible servers. This allows for servers as modules in the future. - temporarily disabled the winbind code until I add the helper functions for that type of server - added error checking on service startup. If a configured server fails to startup then smbd doesn't startup. - cleaned up the command line handling in smbd, removing unused options (This used to be commit cf6a46c3cbde7b1eb1b86bd3882b953a2de3a42e) --- source4/smbd/process_single.c | 100 ++++++++---------------------------------- 1 file changed, 19 insertions(+), 81 deletions(-) (limited to 'source4/smbd/process_single.c') diff --git a/source4/smbd/process_single.c b/source4/smbd/process_single.c index 6a00ad237f..d6217d8712 100644 --- a/source4/smbd/process_single.c +++ b/source4/smbd/process_single.c @@ -1,6 +1,8 @@ /* Unix SMB/CIFS implementation. + process model: process (1 process handles all client connections) + Copyright (C) Andrew Tridgell 2003 Copyright (C) James J Myers 2003 Copyright (C) Stefan (metze) Metzmacher 2004 @@ -24,121 +26,57 @@ #include "events.h" #include "dlinklist.h" #include "smb_server/smb_server.h" -#include "process_model.h" /* called when the process model is selected */ -static void single_model_init(struct server_context *server) -{ -} - -static void single_model_exit(struct server_context *server, const char *reason) +static void single_model_init(struct event_context *ev) { - DEBUG(1,("single_exit_server: reason[%s]\n",reason)); - talloc_free(server); - exit(0); } /* - called when a listening socket becomes readable + called when a listening socket becomes readable. */ -static void single_accept_connection(struct event_context *ev, struct fd_event *srv_fde, - struct timeval t, uint16_t flags) +static void single_accept_connection(struct event_context *ev, + struct socket_context *sock, + void (*new_conn)(struct event_context *, struct socket_context *, + uint32_t , void *), + void *private) { NTSTATUS status; - struct socket_context *sock; - struct server_stream_socket *stream_socket = srv_fde->private; - struct server_connection *conn; + struct socket_context *sock2; /* accept an incoming connection. */ - status = socket_accept(stream_socket->socket, &sock); + status = socket_accept(sock, &sock2); if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("accept_connection_single: accept: %s\n", - nt_errstr(status))); - return; - } - - conn = server_setup_connection(ev, stream_socket, sock, t, socket_get_fd(sock)); - if (!conn) { - DEBUG(10,("server_setup_connection failed\n")); + DEBUG(0,("accept_connection_single: accept: %s\n", nt_errstr(status))); return; } - talloc_steal(conn, sock); + talloc_steal(private, sock); - /* return to event handling */ - return; + new_conn(ev, sock2, socket_get_fd(sock), private); } - -/* called when a SMB connection goes down */ -static void single_terminate_connection(struct server_connection *conn, const char *reason) +/* called when a connection goes down */ +static void single_terminate_connection(struct event_context *ev, const char *reason) { - DEBUG(2,("single_terminate_connection: reason[%s]\n",reason)); - - if (conn) { - talloc_free(conn); - } -} - -/* - called to create a new event context for a new task -*/ -static void single_create_task(struct server_task *task) -{ - task->task.id = (uint32_t)task; - task->event.ctx = task->service->server->event.ctx; - - /* setup to receive internal messages on this connection */ - task->messaging.ctx = messaging_init(task, task->task.id, task->event.ctx); - if (!task->messaging.ctx) { - server_terminate_task(task, "messaging_init() failed"); - return; - } - - task->task.ops->task_init(task); - return; -} - -/* - called to exit from a server_task -*/ -static void single_terminate_task(struct server_task *task, const char *reason) -{ - DEBUG(1,("single_exit_server: reason[%s]\n",reason)); - talloc_free(task); - return; } static const struct model_ops single_ops = { .name = "single", - .model_init = single_model_init, - .model_exit = single_model_exit, - .accept_connection = single_accept_connection, .terminate_connection = single_terminate_connection, - - .create_task = single_create_task, - .terminate_task = single_terminate_task }; /* - initialise the single process model, registering ourselves with the process model subsystem + initialise the single process model, registering ourselves with the + process model subsystem */ NTSTATUS process_model_single_init(void) { - NTSTATUS ret; - - /* register ourselves with the PROCESS_MODEL subsystem. */ - ret = register_process_model(&single_ops); - if (!NT_STATUS_IS_OK(ret)) { - DEBUG(0,("Failed to register process_model 'single'!\n")); - return ret; - } - - return ret; + return register_process_model(&single_ops); } -- cgit