LCOV - code coverage report
Current view: top level - source3/lib/smbconf - smbconf_init.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 21 30 70.0 %
Date: 2021-09-23 10:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  libsmbconf - Samba configuration library, init dispatcher
       4             :  *  Copyright (C) Michael Adam 2008
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "includes.h"
      21             : #include "lib/smbconf/smbconf_private.h"
      22             : #include "lib/smbconf/smbconf_txt.h"
      23             : #include "lib/smbconf/smbconf_reg.h"
      24             : #include "lib/smbconf/smbconf_init.h"
      25             : 
      26             : /**
      27             :  * smbconf initialization dispatcher
      28             :  *
      29             :  * this takes a configuration source in the form of
      30             :  * backend:path and calles the appropriate backend
      31             :  * init function with the path argument
      32             :  *
      33             :  * known backends:
      34             :  * -  "registry" or "reg"
      35             :  * -  "txt" or "file"
      36             :  */
      37         793 : sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
      38             :                     const char *source)
      39             : {
      40             :         sbcErr err;
      41         793 :         char *backend = NULL;
      42         793 :         char *path = NULL;
      43             :         char *sep;
      44         793 :         TALLOC_CTX *tmp_ctx = talloc_stackframe();
      45             : 
      46         793 :         if (conf_ctx == NULL) {
      47           0 :                 err = SBC_ERR_INVALID_PARAM;
      48           0 :                 goto done;
      49             :         }
      50             : 
      51         793 :         if ((source == NULL) || (*source == '\0')) {
      52           0 :                 err = SBC_ERR_INVALID_PARAM;
      53           0 :                 goto done;
      54             :         }
      55             : 
      56         793 :         backend = talloc_strdup(tmp_ctx, source);
      57         793 :         if (backend == NULL) {
      58           0 :                 err = SBC_ERR_NOMEM;
      59           0 :                 goto done;
      60             :         }
      61             : 
      62         793 :         sep = strchr(backend, ':');
      63         793 :         if (sep != NULL) {
      64         769 :                 *sep = '\0';
      65         769 :                 path = sep + 1;
      66         769 :                 if (strlen(path) == 0) {
      67         747 :                         path = NULL;
      68             :                 }
      69             :         }
      70             : 
      71         793 :         if (strequal(backend, "registry") || strequal(backend, "reg")) {
      72         771 :                 err = smbconf_init_reg(mem_ctx, conf_ctx, path);
      73          22 :         } else if (strequal(backend, "file") || strequal(backend, "txt")) {
      74          22 :                 err = smbconf_init_txt(mem_ctx, conf_ctx, path);
      75           0 :         } else if (sep == NULL) {
      76             :                 /*
      77             :                  * If no separator was given in the source, and the string is
      78             :                  * not a known backend, assume file backend and use the source
      79             :                  * string as a path argument.
      80             :                  */
      81           0 :                 err = smbconf_init_txt(mem_ctx, conf_ctx, backend);
      82             :         } else {
      83             :                 /*
      84             :                  * Separator was specified but this is not a known backend.
      85             :                  * As a last resort, try to interpret the original source
      86             :                  * string as a file name that contains a ":" sign.
      87             :                  * This may occur with an include directive like this:
      88             :                  * 'include = /path/to/file.%T'
      89             :                  */
      90           0 :                 err = smbconf_init_txt(mem_ctx, conf_ctx, source);
      91             :         }
      92             : 
      93         793 : done:
      94         793 :         talloc_free(tmp_ctx);
      95         793 :         return err;
      96             : }

Generated by: LCOV version 1.13