r3466: split out request.h, signing.h, and smb_server.h
[samba.git] / source4 / smbd / process_single.c
1 /* 
2    Unix SMB/CIFS implementation.
3    process model: process (1 process handles all client connections)
4    Copyright (C) Andrew Tridgell 2003
5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
6    Copyright (C) Stefan (metze) Metzmacher 2004
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "dlinklist.h"
25 #include "smb_server/smb_server.h"
26 #include "process_model.h"
27
28
29 /*
30   called when the process model is selected
31 */
32 static void single_start_server(void)
33 {
34         smbd_process_init();
35 }
36
37 /*
38   called when a listening socket becomes readable
39 */
40 static void single_accept_connection(struct event_context *ev, struct fd_event *srv_fde, time_t t, uint16_t flags)
41 {
42         NTSTATUS status;
43         struct socket_context *sock;
44         struct server_socket *server_socket = srv_fde->private;
45         struct server_connection *conn;
46
47         /* accept an incoming connection. */
48         status = socket_accept(server_socket->socket, &sock);
49         if (!NT_STATUS_IS_OK(status)) {
50                 DEBUG(0,("accept_connection_single: accept: %s\n",
51                          nt_errstr(status)));
52                 return;
53         }
54
55         conn = server_setup_connection(ev, server_socket, sock, t, socket_get_fd(sock));
56         if (!conn) {
57                 DEBUG(0,("server_setup_connection(ev, server_socket, sock, t) failed\n"));
58                 return;
59         }
60
61         talloc_steal(conn, sock);
62
63         DLIST_ADD(server_socket->connection_list,conn);
64
65         /* return to event handling */
66         return;
67 }
68
69
70
71 /* called when a SMB connection goes down */
72 static void single_terminate_connection(struct server_connection *conn, const char *reason) 
73 {
74         DEBUG(2,("single_terminate_connection: reason[%s]\n",reason));
75
76         if (conn) {
77                 talloc_free(conn);
78         }
79 }
80
81 static int single_get_id(struct smbsrv_request *req)
82 {
83         return (int)req->smb_conn->pid;
84 }
85
86 static void single_exit_server(struct server_context *srv_ctx, const char *reason)
87 {
88         DEBUG(1,("single_exit_server: reason[%s]\n",reason));
89 }
90
91 /*
92   initialise the single process model, registering ourselves with the process model subsystem
93  */
94 NTSTATUS process_model_single_init(void)
95 {
96         NTSTATUS ret;
97         struct model_ops ops;
98
99         ZERO_STRUCT(ops);
100
101         /* fill in our name */
102         ops.name = "single";
103
104         /* fill in all the operations */
105         ops.model_startup               = single_start_server;
106         ops.accept_connection           = single_accept_connection;
107         ops.terminate_connection        = single_terminate_connection;
108         ops.exit_server                 = single_exit_server;
109         ops.get_id                      = single_get_id;
110
111         /* register ourselves with the PROCESS_MODEL subsystem. */
112         ret = register_backend("process_model", &ops);
113         if (!NT_STATUS_IS_OK(ret)) {
114                 DEBUG(0,("Failed to register process_model 'single'!\n"));
115                 return ret;
116         }
117
118         return ret;
119 }