LCOV - code coverage report
Current view: top level - source4/param - share.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 42 54 77.8 %
Date: 2021-09-23 10:06:22 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    
       4             :    Modular shares configuration system
       5             :    
       6             :    Copyright (C) Simo Sorce     2006
       7             :    
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "param/share.h"
      24             : #include "param/param.h"
      25             : #include "lib/util/samba_modules.h"
      26             : 
      27       12357 : char *share_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval)
      28             : {
      29       12357 :         return scfg->ctx->ops->string_option(mem_ctx, scfg, opt_name, defval);
      30             : }
      31             : 
      32       13398 : int share_int_option(struct share_config *scfg, const char *opt_name, int defval)
      33             : {
      34       13398 :         return scfg->ctx->ops->int_option(scfg, opt_name, defval);
      35             : }
      36             : 
      37       19906 : bool share_bool_option(struct share_config *scfg, const char *opt_name, bool defval)
      38             : {
      39       19906 :         return scfg->ctx->ops->bool_option(scfg, opt_name, defval);
      40             : }
      41             : 
      42        8108 : const char **share_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
      43             : {
      44        8108 :         return scfg->ctx->ops->string_list_option(mem_ctx, scfg, opt_name);
      45             : }
      46             : 
      47          99 : NTSTATUS share_list_all(TALLOC_CTX *mem_ctx, struct share_context *sctx, int *count, const char ***names)
      48             : {
      49          99 :         return sctx->ops->list_all(mem_ctx, sctx, count, names);
      50             : }
      51             : 
      52        3630 : NTSTATUS share_get_config(TALLOC_CTX *mem_ctx, struct share_context *sctx, const char *name, struct share_config **scfg)
      53             : {
      54        3630 :         return sctx->ops->get_config(mem_ctx, sctx, name, scfg);
      55             : }
      56             : 
      57           4 : NTSTATUS share_create(struct share_context *sctx, const char *name, struct share_info *info, int count)
      58             : {
      59           4 :         if (sctx->ops->create) {
      60           0 :                 return sctx->ops->create(sctx, name, info, count);
      61             :         }
      62           4 :         return NT_STATUS_NOT_IMPLEMENTED;
      63             : }
      64             : 
      65           0 : NTSTATUS share_set(struct share_context *sctx, const char *name, struct share_info *info, int count)
      66             : {
      67           0 :         if (sctx->ops->set) {
      68           0 :                 return sctx->ops->set(sctx, name, info, count);
      69             :         }
      70           0 :         return NT_STATUS_NOT_IMPLEMENTED;
      71             : }
      72             : 
      73           1 : NTSTATUS share_remove(struct share_context *sctx, const char *name)
      74             : {
      75           1 :         if (sctx->ops->remove) {
      76           0 :                 return sctx->ops->remove(sctx, name);
      77             :         }
      78           1 :         return NT_STATUS_NOT_IMPLEMENTED;
      79             : }
      80             : 
      81             : /* List of currently available share backends */
      82             : static struct share_ops **backends = NULL;
      83             : 
      84        5534 : static const struct share_ops *share_backend_by_name(const char *name)
      85             : {
      86             :         int i;
      87             : 
      88        5534 :         for (i = 0; backends && backends[i]; i++) {
      89        3115 :                 if (strcmp(backends[i]->name, name) == 0) {
      90        3114 :                         return backends[i];
      91             :                 }
      92             :         }
      93             : 
      94        2293 :         return NULL;
      95             : }
      96             : 
      97             : /*
      98             :   Register the share backend
      99             : */
     100        2419 : NTSTATUS share_register(const struct share_ops *ops)
     101             : {
     102             :         int i;
     103             : 
     104        2419 :         if (share_backend_by_name(ops->name) != NULL) {
     105           0 :                 DEBUG(0,("SHARE backend [%s] already registered\n", ops->name));
     106           0 :                 return NT_STATUS_OBJECT_NAME_COLLISION;
     107             :         }
     108             : 
     109        2293 :         i = 0;
     110        4235 :         while (backends && backends[i]) {
     111           0 :                 i++;
     112             :         }
     113             : 
     114        2419 :         backends = realloc_p(backends, struct share_ops *, i + 2);
     115        2419 :         if (!backends) {
     116           0 :                 smb_panic("out of memory in share_register");
     117             :         }
     118             : 
     119        2419 :         backends[i] = (struct share_ops *)smb_xmemdup(ops, sizeof(*ops));
     120        2419 :         backends[i]->name = smb_xstrdup(ops->name);
     121             : 
     122        2419 :         backends[i + 1] = NULL;
     123             : 
     124        2419 :         DEBUG(3, ("SHARE backend [%s] registered.\n", ops->name));
     125             : 
     126        2419 :         return NT_STATUS_OK;
     127             : }
     128             : 
     129        3115 : NTSTATUS share_get_context(TALLOC_CTX *mem_ctx,
     130             :                            struct loadparm_context *lp_ctx,
     131             :                            struct share_context **ctx)
     132             : {
     133             :         const struct share_ops *ops;
     134             : 
     135        3115 :         ops = share_backend_by_name("classic");
     136        3115 :         if (!ops) {
     137           0 :                 DEBUG(0, ("share_init_connection: share backend [classic] not found!\n"));
     138           0 :                 return NT_STATUS_INTERNAL_ERROR;
     139             :         }
     140             : 
     141        3115 :         return ops->init(mem_ctx, ops, lp_ctx, ctx);
     142             : }
     143             : 
     144             : /*
     145             :   initialise the SHARE subsystem
     146             : */
     147        2419 : NTSTATUS share_init(void)
     148             : {
     149             : #define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
     150             :         STATIC_share_MODULES_PROTO;
     151        2419 :         init_module_fn static_init[] = { STATIC_share_MODULES };
     152             : 
     153        2419 :         run_init_functions(NULL, static_init);
     154             : 
     155        2419 :         return NT_STATUS_OK;
     156             : }

Generated by: LCOV version 1.13