2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
2005-01-30 03:54:57 +03:00
2003-08-13 05:53:07 +04:00
process model : process ( 1 process handles all client connections )
2005-01-30 03:54:57 +03:00
2003-08-13 05:53:07 +04:00
Copyright ( C ) Andrew Tridgell 2003
Copyright ( C ) James J Myers 2003 < myersjj @ samba . org >
2004-07-14 01:04:56 +04:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2004
2003-08-13 05:53:07 +04:00
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2006-03-26 05:23:40 +04:00
# include "smbd/process_model.h"
2003-08-13 05:53:07 +04:00
2005-12-15 23:25:37 +03:00
/* For sepecifiying event context to GSSAPI below */
2006-01-10 11:41:49 +03:00
# include "system/kerberos.h"
2005-12-15 23:25:37 +03:00
# include "heimdal/lib/gssapi/gssapi_locl.h"
2004-07-14 01:04:56 +04:00
2003-08-13 05:53:07 +04:00
/*
called when the process model is selected
*/
2005-01-30 03:54:57 +03:00
static void single_model_init ( struct event_context * ev )
2005-01-14 04:32:56 +03:00
{
2005-12-15 23:25:37 +03:00
/* Hack to ensure that GSSAPI uses the right event context */
gssapi_krb5_init_ev ( ev ) ;
2003-08-13 05:53:07 +04:00
}
/*
2005-01-30 03:54:57 +03:00
called when a listening socket becomes readable .
2003-08-13 05:53:07 +04:00
*/
2005-01-30 03:54:57 +03:00
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 )
2003-08-13 05:53:07 +04:00
{
2004-09-20 16:31:07 +04:00
NTSTATUS status ;
2005-01-30 03:54:57 +03:00
struct socket_context * sock2 ;
2004-07-14 01:04:56 +04:00
2003-08-13 05:53:07 +04:00
/* accept an incoming connection. */
2005-01-30 03:54:57 +03:00
status = socket_accept ( sock , & sock2 ) ;
2004-09-20 16:31:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-01-30 03:54:57 +03:00
DEBUG ( 0 , ( " accept_connection_single: accept: %s \n " , nt_errstr ( status ) ) ) ;
2005-10-12 15:04:01 +04:00
/* this looks strange, but is correct. We need to
throttle things until the system clears enough
resources to handle this new socket . If we don ' t
then we will spin filling the log and causing more
problems . We don ' t panic as this is probably a
temporary resource constraint */
sleep ( 1 ) ;
2003-12-13 13:58:48 +03:00
return ;
}
2004-07-14 01:04:56 +04:00
2005-01-30 03:54:57 +03:00
talloc_steal ( private , sock ) ;
2004-09-26 07:05:04 +04:00
2005-04-30 13:54:58 +04:00
new_conn ( ev , sock2 , socket_get_fd ( sock2 ) , private ) ;
2003-08-13 05:53:07 +04:00
}
2005-01-30 05:55:30 +03:00
/*
called to startup a new task
*/
static void single_new_task ( struct event_context * ev ,
void ( * new_task ) ( struct event_context * , uint32_t , void * ) ,
void * private )
{
static uint32_t taskid = 0x10000000 ;
new_task ( ev , taskid + + , private ) ;
}
2004-07-14 01:04:56 +04:00
2005-01-30 05:55:30 +03:00
/* called when a task goes down */
static void single_terminate ( struct event_context * ev , const char * reason )
2003-12-14 02:25:15 +03:00
{
2005-02-16 04:48:11 +03:00
DEBUG ( 2 , ( " single_terminate: reason[%s] \n " , reason ) ) ;
2004-02-02 16:43:03 +03:00
}
2006-03-09 20:48:41 +03:00
/* called to set a title of a task or connection */
static void single_set_title ( struct event_context * ev , const char * title )
{
}
2005-01-14 04:32:56 +03:00
static const struct model_ops single_ops = {
. name = " single " ,
. model_init = single_model_init ,
2005-01-30 05:55:30 +03:00
. new_task = single_new_task ,
2005-01-14 04:32:56 +03:00
. accept_connection = single_accept_connection ,
2005-01-30 05:55:30 +03:00
. terminate = single_terminate ,
2006-03-09 20:48:41 +03:00
. set_title = single_set_title ,
2005-01-14 04:32:56 +03:00
} ;
2003-08-13 05:53:07 +04:00
/*
2005-01-30 03:54:57 +03:00
initialise the single process model , registering ourselves with the
process model subsystem
2003-08-13 05:53:07 +04:00
*/
2004-02-02 16:43:03 +03:00
NTSTATUS process_model_single_init ( void )
2003-08-13 05:53:07 +04:00
{
2005-01-30 03:54:57 +03:00
return register_process_model ( & single_ops ) ;
2003-08-13 05:53:07 +04:00
}