2004-07-14 01:04:56 +04:00
/*
Unix SMB / CIFS implementation .
SERVER SERVICE code
2005-01-30 03:54:57 +03:00
Copyright ( C ) Andrew Tridgell 2003 - 2005
2004-07-14 01:04:56 +04:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2004
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
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2004-07-14 01:04:56 +04:00
( 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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-07-14 01:04:56 +04:00
*/
# include "includes.h"
2008-10-11 23:31:42 +04:00
# include "../lib/util/dlinklist.h"
2006-03-07 14:07:23 +03:00
# include "smbd/process_model.h"
2004-07-14 01:04:56 +04:00
/*
2005-01-30 03:54:57 +03:00
a linked list of registered servers
*/
static struct registered_server {
struct registered_server * next , * prev ;
const char * service_name ;
2008-02-04 13:58:29 +03:00
void ( * task_init ) ( struct task_server * ) ;
2005-01-30 03:54:57 +03:00
} * registered_servers ;
2004-07-15 12:59:07 +04:00
2004-07-14 01:04:56 +04:00
/*
2005-01-30 03:54:57 +03:00
register a server service .
2004-07-14 01:04:56 +04:00
*/
2005-01-30 03:54:57 +03:00
NTSTATUS register_server_service ( const char * name ,
2008-02-04 13:58:29 +03:00
void ( * task_init ) ( struct task_server * ) )
2005-01-14 04:32:56 +03:00
{
2005-01-30 03:54:57 +03:00
struct registered_server * srv ;
srv = talloc ( talloc_autofree_context ( ) , struct registered_server ) ;
NT_STATUS_HAVE_NO_MEMORY ( srv ) ;
srv - > service_name = name ;
2008-02-04 13:58:29 +03:00
srv - > task_init = task_init ;
2005-01-30 03:54:57 +03:00
DLIST_ADD_END ( registered_servers , srv , struct registered_server * ) ;
return NT_STATUS_OK ;
2004-07-14 01:04:56 +04:00
}
2005-01-14 04:32:56 +03:00
2004-07-14 01:04:56 +04:00
/*
2005-01-30 03:54:57 +03:00
initialise a server service
2004-07-14 01:04:56 +04:00
*/
2005-01-30 03:54:57 +03:00
static NTSTATUS server_service_init ( const char * name ,
2008-12-29 22:24:57 +03:00
struct tevent_context * event_context ,
2007-12-03 02:28:07 +03:00
struct loadparm_context * lp_ctx ,
2005-01-30 03:54:57 +03:00
const struct model_ops * model_ops )
2004-07-14 01:04:56 +04:00
{
2005-01-30 03:54:57 +03:00
struct registered_server * srv ;
for ( srv = registered_servers ; srv ; srv = srv - > next ) {
if ( strcasecmp ( name , srv - > service_name ) = = 0 ) {
2008-02-04 13:58:29 +03:00
return task_server_startup ( event_context , lp_ctx , srv - > service_name ,
model_ops , srv - > task_init ) ;
2005-01-30 03:54:57 +03:00
}
2005-01-14 05:01:19 +03:00
}
2005-01-30 03:54:57 +03:00
return NT_STATUS_INVALID_SYSTEM_SERVICE ;
2004-07-14 01:04:56 +04:00
}
2004-10-29 11:29:26 +04:00
/*
2005-01-30 03:54:57 +03:00
startup all of our server services
2004-10-29 11:29:26 +04:00
*/
2008-12-29 22:24:57 +03:00
NTSTATUS server_service_startup ( struct tevent_context * event_ctx ,
2007-12-03 02:28:07 +03:00
struct loadparm_context * lp_ctx ,
2005-01-30 03:54:57 +03:00
const char * model , const char * * server_services )
2004-10-29 11:29:26 +04:00
{
2005-01-30 03:54:57 +03:00
int i ;
const struct model_ops * model_ops ;
2004-10-29 12:38:59 +04:00
2005-01-30 03:54:57 +03:00
if ( ! server_services ) {
DEBUG ( 0 , ( " server_service_startup: no endpoint servers configured \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2004-10-29 12:38:59 +04:00
2010-10-30 04:24:15 +04:00
model_ops = process_model_startup ( model ) ;
2005-01-30 03:54:57 +03:00
if ( ! model_ops ) {
DEBUG ( 0 , ( " process_model_startup('%s') failed \n " , model ) ) ;
return NT_STATUS_INTERNAL_ERROR ;
2004-10-29 12:38:59 +04:00
}
2005-01-30 03:54:57 +03:00
for ( i = 0 ; server_services [ i ] ; i + + ) {
NTSTATUS status ;
2007-12-03 02:28:07 +03:00
status = server_service_init ( server_services [ i ] , event_ctx , lp_ctx , model_ops ) ;
2005-06-07 11:22:25 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " Failed to start service '%s' - %s \n " ,
server_services [ i ] , nt_errstr ( status ) ) ) ;
}
2005-01-30 03:54:57 +03:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
2004-10-29 11:29:26 +04:00
}
2004-10-29 12:38:59 +04:00
2005-01-30 03:54:57 +03:00
return NT_STATUS_OK ;
2004-10-29 11:29:26 +04:00
}