2 Unix SMB/CIFS implementation.
3 process model: standard (1 process per client connection)
4 Copyright (C) Andrew Tridgell 1992-2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
6 Copyright (C) Stefan (metze) Metzmacher 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 called when the process model is selected
28 static void standard_model_startup(void)
30 signal(SIGCHLD, SIG_IGN);
35 called when a listening socket becomes readable
37 static void standard_accept_connection(struct event_context *ev, struct fd_event *srv_fde, time_t t, uint16_t flags)
41 socklen_t in_addrlen = sizeof(addr);
44 struct timed_event idle;
45 struct server_socket *server_socket = srv_fde->private;
46 struct server_connection *conn;
49 /* accept an incoming connection. */
50 accepted_fd = accept(srv_fde->fd,&addr,&in_addrlen);
51 if (accepted_fd == -1) {
52 DEBUG(0,("standard_accept_connection: accept: %s\n",
60 /* parent or error code ... */
63 /* go back to the event loop */
69 /* close all the listening sockets */
70 event_remove_fd_all_handler(ev, standard_accept_connection);
72 /* tdb needs special fork handling */
73 if (tdb_reopen_all() == -1) {
74 DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
77 mem_ctx = talloc_init("server_service_connection");
79 DEBUG(0,("talloc_init(server_service_connection) failed\n"));
83 conn = talloc_p(mem_ctx, struct server_connection);
85 DEBUG(0,("talloc_p(mem_ctx, struct server_service_connection) failed\n"));
86 talloc_destroy(mem_ctx);
91 conn->mem_ctx = mem_ctx;
95 fde.flags = EVENT_FD_READ;
96 fde.handler = server_io_handler;
99 idle.next_event = t + 300;
100 idle.handler = server_idle_handler;
103 conn->event.ctx = ev;
104 conn->event.fde = &fde;
105 conn->event.idle = &idle;
106 conn->event.idle_time = 300;
108 conn->server_socket = server_socket;
109 conn->service = server_socket->service;
111 /* TODO: we need a generic socket subsystem */
112 conn->socket = talloc_p(conn->mem_ctx, struct socket_context);
114 DEBUG(0,("talloc_p(conn->mem_ctx, struct socket_context) failed\n"));
115 talloc_destroy(mem_ctx);
118 conn->socket->private_data = NULL;
119 conn->socket->ops = NULL;
120 conn->socket->client_addr = NULL;
121 conn->socket->pkt_count = 0;
122 conn->socket->fde = conn->event.fde;
124 /* create a smb server context and add it to out event
126 server_socket->service->ops->accept_connection(conn);
128 /* accpect_connection() of the service may changed idle.next_event */
129 conn->event.fde = event_add_fd(ev,&fde);
130 conn->event.idle = event_add_timed(ev,&idle);
132 conn->socket->fde = conn->event.fde;
134 DLIST_ADD(server_socket->connection_list,conn);
136 /* return to the event loop */
140 /* called when a SMB connection goes down */
141 static void standard_terminate_connection(struct server_connection *conn, const char *reason)
143 DEBUG(0,("single_terminate_connection: reason[%s]\n",reason));
144 conn->service->ops->close_connection(conn,reason);
145 /* terminate this process */
149 static int standard_get_id(struct smbsrv_request *req)
151 return (int)req->smb_conn->pid;
154 static void standard_exit_server(struct server_context *srv_ctx, const char *reason)
156 DEBUG(1,("standard_exit_server: reason[%s]\n",reason));
160 initialise the standard process model, registering ourselves with the process model subsystem
162 NTSTATUS process_model_standard_init(void)
165 struct model_ops ops;
169 /* fill in our name */
170 ops.name = "standard";
172 /* fill in all the operations */
173 ops.model_startup = standard_model_startup;
174 ops.accept_connection = standard_accept_connection;
175 ops.terminate_connection = standard_terminate_connection;
176 ops.exit_server = standard_exit_server;
177 ops.get_id = standard_get_id;
179 /* register ourselves with the PROCESS_MODEL subsystem. */
180 ret = register_backend("process_model", &ops);
181 if (!NT_STATUS_IS_OK(ret)) {
182 DEBUG(0,("Failed to register process_model 'standard'!\n"));