samba-tool group removemembers: adapt functionality to addmembers command
[Samba.git] / source4 / smbd / service.c
blob7c8d2cfe3a4d53d475ea4e357fe43e23bf5efe2e
1 /*
2 Unix SMB/CIFS implementation.
4 SERVER SERVICE code
6 Copyright (C) Andrew Tridgell 2003-2005
7 Copyright (C) Stefan (metze) Metzmacher 2004
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.
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.
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/>.
23 #include "includes.h"
24 #include "../lib/util/dlinklist.h"
25 #include "smbd/process_model.h"
28 a linked list of registered servers
30 static struct registered_server {
31 struct registered_server *next, *prev;
32 const char *service_name;
33 const struct service_details *service_details;
34 } *registered_servers;
37 register a server service.
39 NTSTATUS register_server_service(TALLOC_CTX *ctx,
40 const char *name,
41 const struct service_details *details)
43 struct registered_server *srv;
44 srv = talloc(ctx, struct registered_server);
45 NT_STATUS_HAVE_NO_MEMORY(srv);
46 srv->service_name = name;
47 srv->service_details =
48 talloc_memdup(ctx, details, sizeof(struct service_details));
49 NT_STATUS_HAVE_NO_MEMORY(srv->service_details);
50 DLIST_ADD_END(registered_servers, srv);
51 return NT_STATUS_OK;
56 initialise a server service
58 static NTSTATUS server_service_init(const char *name,
59 struct tevent_context *event_context,
60 struct loadparm_context *lp_ctx,
61 const struct model_ops *model_ops,
62 int from_parent_fd)
64 struct registered_server *srv;
65 for (srv=registered_servers; srv; srv=srv->next) {
66 if (strcasecmp(name, srv->service_name) == 0) {
67 return task_server_startup(event_context, lp_ctx,
68 srv->service_name,
69 model_ops,
70 srv->service_details,
71 from_parent_fd);
74 return NT_STATUS_INVALID_SYSTEM_SERVICE;
79 startup all of our server services
81 NTSTATUS server_service_startup(struct tevent_context *event_ctx,
82 struct loadparm_context *lp_ctx,
83 const char *model, const char **server_services,
84 int from_parent_fd)
86 int i;
87 const struct model_ops *model_ops;
89 if (!server_services) {
90 DBG_ERR("server_service_startup: "
91 "no endpoint servers configured\n");
92 return NT_STATUS_INVALID_PARAMETER;
95 model_ops = process_model_startup(model);
96 if (!model_ops) {
97 DBG_ERR("process_model_startup('%s') failed\n", model);
98 return NT_STATUS_INTERNAL_ERROR;
101 for (i=0;server_services[i];i++) {
102 NTSTATUS status;
104 status = server_service_init(server_services[i], event_ctx,
105 lp_ctx, model_ops, from_parent_fd);
106 if (!NT_STATUS_IS_OK(status)) {
107 DBG_ERR("Failed to start service '%s' - %s\n",
108 server_services[i], nt_errstr(status));
110 NT_STATUS_NOT_OK_RETURN(status);
113 return NT_STATUS_OK;