LCOV - code coverage report
Current view: top level - source4/samba - process_model.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 35 44 79.5 %
Date: 2024-04-21 15:09:00 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    process model manager - main loop
       4             :    Copyright (C) Andrew Tridgell 1992-2003
       5             :    Copyright (C) James J Myers 2003 <myersjj@samba.org>
       6             :    
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             :    
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "samba/process_model.h"
      23             : #include "param/param.h"
      24             : #include "lib/util/samba_modules.h"
      25             : 
      26             : /* the list of currently registered process models */
      27             : static struct process_model {
      28             :         const struct model_ops *ops;
      29             :         bool initialised;
      30             : } *models = NULL;
      31             : static int num_models;
      32             : 
      33             : 
      34             : /*
      35             :   return the operations structure for a named backend of the specified type
      36             : */
      37         343 : static struct process_model *process_model_byname(const char *name)
      38             : {
      39          13 :         int i;
      40             : 
      41         635 :         for (i=0;i<num_models;i++) {
      42         431 :                 if (strcmp(models[i].ops->name, name) == 0) {
      43         139 :                         return &models[i];
      44             :                 }
      45             :         }
      46             : 
      47         195 :         return NULL;
      48             : }
      49             : 
      50             : 
      51             : /*
      52             :   setup the events for the chosen process model
      53             : */
      54         139 : _PUBLIC_ const struct model_ops *process_model_startup(const char *model)
      55             : {
      56           4 :         struct process_model *m;
      57             : 
      58         139 :         m = process_model_byname(model);
      59         139 :         if (m == NULL) {
      60           0 :                 DBG_ERR("Unknown process model '%s'\n", model);
      61           0 :                 exit(-1);
      62             :         }
      63             : 
      64         139 :         if (!m->initialised) {
      65         128 :                 m->initialised = true;
      66         128 :                 m->ops->model_init();
      67             :         }
      68             : 
      69         139 :         return m->ops;
      70             : }
      71             : 
      72             : /*
      73             :   register a process model. 
      74             : 
      75             :   The 'name' can be later used by other backends to find the operations
      76             :   structure for this backend.  
      77             : */
      78         204 : _PUBLIC_ NTSTATUS register_process_model(const struct model_ops *ops)
      79             : {
      80         204 :         if (process_model_byname(ops->name) != NULL) {
      81             :                 /* its already registered! */
      82           0 :                 DBG_ERR("PROCESS_MODEL '%s' already registered\n", ops->name);
      83           0 :                 return NT_STATUS_OBJECT_NAME_COLLISION;
      84             :         }
      85             : 
      86         204 :         models = talloc_realloc(NULL, models, struct process_model, num_models+1);
      87         204 :         if (!models) {
      88           0 :                 smb_panic("out of memory in register_process_model");
      89             :         }
      90             : 
      91         204 :         models[num_models].ops = ops;
      92         204 :         models[num_models].initialised = false;
      93             : 
      94         204 :         num_models++;
      95             : 
      96         204 :         DBG_NOTICE("PROCESS_MODEL '%s' registered\n", ops->name);
      97             : 
      98         204 :         return NT_STATUS_OK;
      99             : }
     100             : 
     101          68 : _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
     102             : {
     103             : #define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
     104           3 :         STATIC_process_model_MODULES_PROTO;
     105          68 :         init_module_fn static_init[] = { STATIC_process_model_MODULES };
     106           3 :         init_module_fn *shared_init;
     107           3 :         static bool initialised;
     108             : 
     109          68 :         if (initialised) {
     110           0 :                 return NT_STATUS_OK;
     111             :         }
     112          68 :         initialised = true;
     113             : 
     114          68 :         shared_init = load_samba_modules(NULL, "process_model");
     115             :         
     116          68 :         run_init_functions(NULL, static_init);
     117          68 :         run_init_functions(NULL, shared_init);
     118             : 
     119          68 :         talloc_free(shared_init);
     120             : 
     121          68 :         return NT_STATUS_OK;
     122             : }
     123             : 
     124             : /*
     125             :   return the PROCESS_MODEL module version, and the size of some critical types
     126             :   This can be used by process model modules to either detect compilation errors, or provide
     127             :   multiple implementations for different smbd compilation options in one module
     128             : */
     129           0 : const struct process_model_critical_sizes *process_model_version(void)
     130             : {
     131           0 :         static const struct process_model_critical_sizes critical_sizes = {
     132             :                 PROCESS_MODEL_VERSION,
     133             :                 sizeof(struct model_ops)
     134             :         };
     135             : 
     136           0 :         return &critical_sizes;
     137             : }

Generated by: LCOV version 1.14