| 1 | /* | 
|---|
| 2 | Unix SMB/CIFS implementation. | 
|---|
| 3 |  | 
|---|
| 4 | SERVER SERVICE code | 
|---|
| 5 |  | 
|---|
| 6 | Copyright (C) Andrew Tridgell 2003-2005 | 
|---|
| 7 | Copyright (C) Stefan (metze) Metzmacher      2004 | 
|---|
| 8 |  | 
|---|
| 9 | This program is free software; you can redistribute it and/or modify | 
|---|
| 10 | it under the terms of the GNU General Public License as published by | 
|---|
| 11 | the Free Software Foundation; either version 3 of the License, or | 
|---|
| 12 | (at your option) any later version. | 
|---|
| 13 |  | 
|---|
| 14 | This program is distributed in the hope that it will be useful, | 
|---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 17 | GNU General Public License for more details. | 
|---|
| 18 |  | 
|---|
| 19 | You should have received a copy of the GNU General Public License | 
|---|
| 20 | along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | #include "includes.h" | 
|---|
| 24 | #include "../lib/util/dlinklist.h" | 
|---|
| 25 | #include "smbd/process_model.h" | 
|---|
| 26 |  | 
|---|
| 27 | /* | 
|---|
| 28 | a linked list of registered servers | 
|---|
| 29 | */ | 
|---|
| 30 | static struct registered_server { | 
|---|
| 31 | struct registered_server *next, *prev; | 
|---|
| 32 | const char *service_name; | 
|---|
| 33 | void (*task_init)(struct task_server *); | 
|---|
| 34 | } *registered_servers; | 
|---|
| 35 |  | 
|---|
| 36 | /* | 
|---|
| 37 | register a server service. | 
|---|
| 38 | */ | 
|---|
| 39 | NTSTATUS register_server_service(const char *name, | 
|---|
| 40 | void (*task_init)(struct task_server *)) | 
|---|
| 41 | { | 
|---|
| 42 | struct registered_server *srv; | 
|---|
| 43 | srv = talloc(talloc_autofree_context(), struct registered_server); | 
|---|
| 44 | NT_STATUS_HAVE_NO_MEMORY(srv); | 
|---|
| 45 | srv->service_name = name; | 
|---|
| 46 | srv->task_init = task_init; | 
|---|
| 47 | DLIST_ADD_END(registered_servers, srv, struct registered_server *); | 
|---|
| 48 | return NT_STATUS_OK; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | /* | 
|---|
| 53 | initialise a server service | 
|---|
| 54 | */ | 
|---|
| 55 | static NTSTATUS server_service_init(const char *name, | 
|---|
| 56 | struct tevent_context *event_context, | 
|---|
| 57 | struct loadparm_context *lp_ctx, | 
|---|
| 58 | const struct model_ops *model_ops) | 
|---|
| 59 | { | 
|---|
| 60 | struct registered_server *srv; | 
|---|
| 61 | for (srv=registered_servers; srv; srv=srv->next) { | 
|---|
| 62 | if (strcasecmp(name, srv->service_name) == 0) { | 
|---|
| 63 | return task_server_startup(event_context, lp_ctx, srv->service_name, | 
|---|
| 64 | model_ops, srv->task_init); | 
|---|
| 65 | } | 
|---|
| 66 | } | 
|---|
| 67 | return NT_STATUS_INVALID_SYSTEM_SERVICE; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | /* | 
|---|
| 72 | startup all of our server services | 
|---|
| 73 | */ | 
|---|
| 74 | NTSTATUS server_service_startup(struct tevent_context *event_ctx, | 
|---|
| 75 | struct loadparm_context *lp_ctx, | 
|---|
| 76 | const char *model, const char **server_services) | 
|---|
| 77 | { | 
|---|
| 78 | int i; | 
|---|
| 79 | const struct model_ops *model_ops; | 
|---|
| 80 |  | 
|---|
| 81 | if (!server_services) { | 
|---|
| 82 | DEBUG(0,("server_service_startup: no endpoint servers configured\n")); | 
|---|
| 83 | return NT_STATUS_INVALID_PARAMETER; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | model_ops = process_model_startup(event_ctx, model); | 
|---|
| 87 | if (!model_ops) { | 
|---|
| 88 | DEBUG(0,("process_model_startup('%s') failed\n", model)); | 
|---|
| 89 | return NT_STATUS_INTERNAL_ERROR; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | for (i=0;server_services[i];i++) { | 
|---|
| 93 | NTSTATUS status; | 
|---|
| 94 |  | 
|---|
| 95 | status = server_service_init(server_services[i], event_ctx, lp_ctx, model_ops); | 
|---|
| 96 | if (!NT_STATUS_IS_OK(status)) { | 
|---|
| 97 | DEBUG(0,("Failed to start service '%s' - %s\n", | 
|---|
| 98 | server_services[i], nt_errstr(status))); | 
|---|
| 99 | } | 
|---|
| 100 | NT_STATUS_NOT_OK_RETURN(status); | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | return NT_STATUS_OK; | 
|---|
| 104 | } | 
|---|