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"
2020-11-20 17:27:17 +03:00
# include "samba/process_model.h"
2021-08-27 14:06:00 +03:00
# include "lib/util/samba_modules.h"
2004-07-14 01:04:56 +04:00
2020-08-07 23:27:39 +03:00
# undef strcasecmp
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 ;
2018-08-23 00:35:52 +03:00
const struct service_details * service_details ;
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
*/
2017-05-09 23:46:45 +03:00
NTSTATUS register_server_service ( TALLOC_CTX * ctx ,
const char * name ,
2018-08-23 00:29:56 +03:00
const struct service_details * details )
2005-01-14 04:32:56 +03:00
{
2005-01-30 03:54:57 +03:00
struct registered_server * srv ;
2017-05-09 23:46:45 +03:00
srv = talloc ( ctx , struct registered_server ) ;
2005-01-30 03:54:57 +03:00
NT_STATUS_HAVE_NO_MEMORY ( srv ) ;
srv - > service_name = name ;
2017-09-14 22:09:23 +03:00
srv - > service_details =
talloc_memdup ( ctx , details , sizeof ( struct service_details ) ) ;
NT_STATUS_HAVE_NO_MEMORY ( srv - > service_details ) ;
2016-02-05 13:32:18 +03:00
DLIST_ADD_END ( registered_servers , srv ) ;
2005-01-30 03:54:57 +03:00
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 ,
2017-08-21 22:58:14 +03:00
const struct model_ops * model_ops ,
int from_parent_fd )
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 ) {
2017-08-21 22:58:14 +03:00
return task_server_startup ( event_context , lp_ctx ,
srv - > service_name ,
2017-09-14 22:09:23 +03:00
model_ops ,
srv - > service_details ,
2017-08-21 22:58:14 +03:00
from_parent_fd ) ;
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
*/
2017-08-21 22:58:14 +03:00
NTSTATUS server_service_startup ( struct tevent_context * event_ctx ,
2007-12-03 02:28:07 +03:00
struct loadparm_context * lp_ctx ,
2017-08-21 22:58:14 +03:00
const char * model , const char * * server_services ,
int from_parent_fd )
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 ) {
2017-09-11 02:39:39 +03:00
DBG_ERR ( " server_service_startup: "
" no endpoint servers configured \n " ) ;
2005-01-30 03:54:57 +03:00
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 ) {
2017-09-11 02:39:39 +03:00
DBG_ERR ( " process_model_startup('%s') failed \n " , model ) ;
2005-01-30 03:54:57 +03:00
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 ;
2017-08-21 22:58:14 +03:00
status = server_service_init ( server_services [ i ] , event_ctx ,
lp_ctx , model_ops , from_parent_fd ) ;
2005-06-07 11:22:25 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2017-09-11 02:39:39 +03:00
DBG_ERR ( " Failed to start service '%s' - %s \n " ,
server_services [ i ] , nt_errstr ( status ) ) ;
2005-06-07 11:22:25 +04:00
}
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
}
2021-08-27 14:06:00 +03:00
_PUBLIC_ NTSTATUS samba_service_init ( void )
{
# define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
STATIC_service_MODULES_PROTO ;
init_module_fn static_init [ ] = { STATIC_service_MODULES } ;
init_module_fn * shared_init = NULL ;
static bool initialised ;
if ( initialised ) {
return NT_STATUS_OK ;
}
initialised = true ;
shared_init = load_samba_modules ( NULL , " service " ) ;
run_init_functions ( NULL , static_init ) ;
run_init_functions ( NULL , shared_init ) ;
TALLOC_FREE ( shared_init ) ;
return NT_STATUS_OK ;
}