s3-sessionid: use sessionid_init_readonly() from cmdline tools.
[Samba.git] / source4 / smbd / process_model.c
blobaf12a7b8cb1f8f8486c00f740cc9e04488bc8ee6
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>
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.
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.
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/>.
21 #include "includes.h"
22 #include "smbd/process_model.h"
23 #include "param/param.h"
25 /* the list of currently registered process models */
26 static struct process_model {
27 const struct model_ops *ops;
28 bool initialised;
29 } *models = NULL;
30 static int num_models;
34 return the operations structure for a named backend of the specified type
36 static struct process_model *process_model_byname(const char *name)
38 int i;
40 for (i=0;i<num_models;i++) {
41 if (strcmp(models[i].ops->name, name) == 0) {
42 return &models[i];
46 return NULL;
51 setup the events for the chosen process model
53 _PUBLIC_ const struct model_ops *process_model_startup(const char *model)
55 struct process_model *m;
57 m = process_model_byname(model);
58 if (m == NULL) {
59 DEBUG(0,("Unknown process model '%s'\n", model));
60 exit(-1);
63 if (!m->initialised) {
64 m->initialised = true;
65 m->ops->model_init();
68 return m->ops;
72 register a process model.
74 The 'name' can be later used by other backends to find the operations
75 structure for this backend.
77 _PUBLIC_ NTSTATUS register_process_model(const struct model_ops *ops)
79 if (process_model_byname(ops->name) != NULL) {
80 /* its already registered! */
81 DEBUG(0,("PROCESS_MODEL '%s' already registered\n",
82 ops->name));
83 return NT_STATUS_OBJECT_NAME_COLLISION;
86 models = talloc_realloc(NULL, models, struct process_model, num_models+1);
87 if (!models) {
88 smb_panic("out of memory in register_process_model");
91 models[num_models].ops = ops;
92 models[num_models].initialised = false;
94 num_models++;
96 DEBUG(3,("PROCESS_MODEL '%s' registered\n", ops->name));
98 return NT_STATUS_OK;
101 _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
103 #define _MODULE_PROTO(init) extern NTSTATUS init(void);
104 STATIC_process_model_MODULES_PROTO;
105 init_module_fn static_init[] = { STATIC_process_model_MODULES };
106 init_module_fn *shared_init;
107 static bool initialised;
109 if (initialised) {
110 return NT_STATUS_OK;
112 initialised = true;
114 shared_init = load_samba_modules(NULL, lp_ctx, "process_model");
116 run_init_functions(static_init);
117 run_init_functions(shared_init);
119 talloc_free(shared_init);
121 return NT_STATUS_OK;
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
129 const struct process_model_critical_sizes *process_model_version(void)
131 static const struct process_model_critical_sizes critical_sizes = {
132 PROCESS_MODEL_VERSION,
133 sizeof(struct model_ops)
136 return &critical_sizes;