LCOV - code coverage report
Current view: top level - source4/samba - service.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 39 46 84.8 %
Date: 2024-04-21 15:09:00 Functions: 4 4 100.0 %

          Line data    Source code
       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 "samba/process_model.h"
      26             : #include "lib/util/samba_modules.h"
      27             : 
      28             : #undef strcasecmp
      29             : 
      30             : /*
      31             :   a linked list of registered servers
      32             : */
      33             : static struct registered_server {
      34             :         struct registered_server *next, *prev;
      35             :         const char *service_name;
      36             :         const struct service_details *service_details;
      37             : } *registered_servers;
      38             : 
      39             : /*
      40             :   register a server service. 
      41             : */
      42        1056 : NTSTATUS register_server_service(TALLOC_CTX *ctx,
      43             :                                 const char *name,
      44             :                                 const struct service_details *details)
      45             : {
      46          48 :         struct registered_server *srv;
      47        1056 :         srv = talloc(ctx, struct registered_server);
      48        1056 :         NT_STATUS_HAVE_NO_MEMORY(srv);
      49        1056 :         srv->service_name = name;
      50        1104 :         srv->service_details =
      51        1056 :                 talloc_memdup(ctx, details, sizeof(struct service_details));
      52        1056 :         NT_STATUS_HAVE_NO_MEMORY(srv->service_details);
      53        1056 :         DLIST_ADD_END(registered_servers, srv);
      54        1056 :         return NT_STATUS_OK;
      55             : }
      56             : 
      57             : 
      58             : /*
      59             :   initialise a server service
      60             : */
      61         910 : static NTSTATUS server_service_init(const char *name,
      62             :                                     struct tevent_context *event_context,
      63             :                                     struct loadparm_context *lp_ctx,
      64             :                                     const struct model_ops *model_ops,
      65             :                                     int from_parent_fd)
      66             : {
      67          28 :         struct registered_server *srv;
      68        7686 :         for (srv=registered_servers; srv; srv=srv->next) {
      69        7686 :                 if (strcasecmp(name, srv->service_name) == 0) {
      70         910 :                         return task_server_startup(event_context, lp_ctx,
      71             :                                                    srv->service_name,
      72             :                                                    model_ops,
      73             :                                                    srv->service_details,
      74             :                                                    from_parent_fd);
      75             :                 }
      76             :         }
      77           0 :         return NT_STATUS_INVALID_SYSTEM_SERVICE;
      78             : }
      79             : 
      80             : 
      81             : /*
      82             :   startup all of our server services
      83             : */
      84          65 : NTSTATUS server_service_startup(struct tevent_context *event_ctx,
      85             :                                 struct loadparm_context *lp_ctx,
      86             :                                 const char *model, const char **server_services,
      87             :                                 int from_parent_fd)
      88             : {
      89           2 :         int i;
      90           2 :         const struct model_ops *model_ops;
      91             : 
      92          65 :         if (!server_services) {
      93           0 :                 DBG_ERR("server_service_startup: "
      94             :                         "no endpoint servers configured\n");
      95           0 :                 return NT_STATUS_INVALID_PARAMETER;
      96             :         }
      97             : 
      98          65 :         model_ops = process_model_startup(model);
      99          65 :         if (!model_ops) {
     100           0 :                 DBG_ERR("process_model_startup('%s') failed\n", model);
     101           0 :                 return NT_STATUS_INTERNAL_ERROR;
     102             :         }
     103             : 
     104         975 :         for (i=0;server_services[i];i++) {
     105          28 :                 NTSTATUS status;
     106             : 
     107         910 :                 status = server_service_init(server_services[i], event_ctx,
     108             :                                              lp_ctx, model_ops, from_parent_fd);
     109         910 :                 if (!NT_STATUS_IS_OK(status)) {
     110           0 :                         DBG_ERR("Failed to start service '%s' - %s\n",
     111             :                                  server_services[i], nt_errstr(status));
     112             :                 }
     113         910 :                 NT_STATUS_NOT_OK_RETURN(status);
     114             :         }
     115             : 
     116          65 :         return NT_STATUS_OK;
     117             : }
     118             : 
     119          66 : _PUBLIC_ NTSTATUS samba_service_init(void)
     120             : {
     121             : #define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
     122           3 :         STATIC_service_MODULES_PROTO;
     123          66 :         init_module_fn static_init[] = { STATIC_service_MODULES };
     124          66 :         init_module_fn *shared_init = NULL;
     125           3 :         static bool initialised;
     126             : 
     127          66 :         if (initialised) {
     128           0 :                 return NT_STATUS_OK;
     129             :         }
     130          66 :         initialised = true;
     131             : 
     132          66 :         shared_init = load_samba_modules(NULL, "service");
     133             : 
     134          66 :         run_init_functions(NULL, static_init);
     135          66 :         run_init_functions(NULL, shared_init);
     136             : 
     137          66 :         TALLOC_FREE(shared_init);
     138             : 
     139          66 :         return NT_STATUS_OK;
     140             : }

Generated by: LCOV version 1.14