2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
process model manager - main loop
Copyright ( C ) Andrew Tridgell 1992 - 2003
Copyright ( C ) James J Myers 2003 < myersjj @ samba . org >
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
2003-08-13 05:53:07 +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/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2006-03-26 05:23:40 +04:00
# include "smbd/process_model.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2011-12-03 10:03:35 +04:00
# include "lib/util/samba_modules.h"
2003-08-13 05:53:07 +04:00
2010-10-30 04:24:15 +04:00
/* the list of currently registered process models */
static struct process_model {
2010-11-03 12:57:38 +03:00
const struct model_ops * ops ;
2010-10-30 04:24:15 +04:00
bool initialised ;
} * models = NULL ;
static int num_models ;
/*
return the operations structure for a named backend of the specified type
*/
static struct process_model * process_model_byname ( const char * name )
{
int i ;
for ( i = 0 ; i < num_models ; i + + ) {
if ( strcmp ( models [ i ] . ops - > name , name ) = = 0 ) {
return & models [ i ] ;
}
}
return NULL ;
}
2008-09-22 20:15:24 +04:00
2004-06-24 03:44:50 +04:00
/*
setup the events for the chosen process model
*/
2010-10-30 04:24:15 +04:00
_PUBLIC_ const struct model_ops * process_model_startup ( const char * model )
2004-06-24 03:44:50 +04:00
{
2010-10-30 04:24:15 +04:00
struct process_model * m ;
2004-06-24 03:44:50 +04:00
2010-10-30 04:24:15 +04:00
m = process_model_byname ( model ) ;
if ( m = = NULL ) {
2017-09-11 02:39:39 +03:00
DBG_ERR ( " Unknown process model '%s' \n " , model ) ;
2004-06-24 03:44:50 +04:00
exit ( - 1 ) ;
}
2010-10-30 04:24:15 +04:00
if ( ! m - > initialised ) {
m - > initialised = true ;
m - > ops - > model_init ( ) ;
}
2004-06-24 03:44:50 +04:00
2010-10-30 04:24:15 +04:00
return m - > ops ;
2004-06-24 03:44:50 +04:00
}
2003-08-13 05:53:07 +04:00
/*
register a process model .
The ' name ' can be later used by other backends to find the operations
structure for this backend .
*/
2010-11-03 12:57:38 +03:00
_PUBLIC_ NTSTATUS register_process_model ( const struct model_ops * ops )
2003-08-13 05:53:07 +04:00
{
2004-02-02 16:43:03 +03:00
if ( process_model_byname ( ops - > name ) ! = NULL ) {
2003-08-13 05:53:07 +04:00
/* its already registered! */
2017-09-11 02:39:39 +03:00
DBG_ERR ( " PROCESS_MODEL '%s' already registered \n " , ops - > name ) ;
2004-02-02 16:43:03 +03:00
return NT_STATUS_OBJECT_NAME_COLLISION ;
2003-08-13 05:53:07 +04:00
}
2010-11-03 12:57:38 +03:00
models = talloc_realloc ( NULL , models , struct process_model , num_models + 1 ) ;
2003-08-13 05:53:07 +04:00
if ( ! models ) {
smb_panic ( " out of memory in register_process_model " ) ;
}
2010-11-03 12:57:38 +03:00
models [ num_models ] . ops = ops ;
2010-11-02 12:55:18 +03:00
models [ num_models ] . initialised = false ;
2003-08-13 05:53:07 +04:00
num_models + + ;
2017-09-11 02:39:39 +03:00
DBG_NOTICE ( " PROCESS_MODEL '%s' registered \n " , ops - > name ) ;
2004-02-02 16:43:03 +03:00
return NT_STATUS_OK ;
2003-08-13 05:53:07 +04:00
}
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS process_model_init ( struct loadparm_context * lp_ctx )
2005-12-26 19:46:55 +03:00
{
2017-04-20 22:24:43 +03:00
# define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
2010-11-01 06:58:32 +03:00
STATIC_process_model_MODULES_PROTO ;
2011-12-03 10:03:35 +04:00
init_module_fn static_init [ ] = { STATIC_process_model_MODULES } ;
init_module_fn * shared_init ;
2010-10-30 16:42:27 +04:00
static bool initialised ;
2005-12-26 19:46:55 +03:00
2010-11-01 06:58:32 +03:00
if ( initialised ) {
return NT_STATUS_OK ;
2010-10-30 16:42:27 +04:00
}
2010-11-01 06:58:32 +03:00
initialised = true ;
2011-12-03 10:03:35 +04:00
shared_init = load_samba_modules ( NULL , " process_model " ) ;
2005-12-26 19:46:55 +03:00
2017-04-20 22:24:43 +03:00
run_init_functions ( NULL , static_init ) ;
run_init_functions ( NULL , shared_init ) ;
2010-11-01 06:58:32 +03:00
talloc_free ( shared_init ) ;
2005-12-26 19:46:55 +03:00
return NT_STATUS_OK ;
}
2004-02-02 16:43:03 +03:00
/*
return the PROCESS_MODEL module version , and the size of some critical types
This can be used by process model modules to either detect compilation errors , or provide
multiple implementations for different smbd compilation options in one module
*/
const struct process_model_critical_sizes * process_model_version ( void )
{
static const struct process_model_critical_sizes critical_sizes = {
PROCESS_MODEL_VERSION ,
2005-02-03 05:35:52 +03:00
sizeof ( struct model_ops )
2004-02-02 16:43:03 +03:00
} ;
return & critical_sizes ;
}