root/source3/lib/smbconf/smbconf_init.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. smbconf_init

   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 
  25 /**
  26  * smbconf initialization dispatcher
  27  *
  28  * this takes a configuration source in the form of
  29  * backend:path and calles the appropriate backend
  30  * init function with the path argument
  31  *
  32  * known backends:
  33  * -  "registry" or "reg"
  34  * -  "txt" or "file"
  35  */
  36 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  37                     const char *source)
  38 {
  39         WERROR werr;
  40         char *backend = NULL;
  41         char *path = NULL;
  42         char *sep;
  43         TALLOC_CTX *tmp_ctx = talloc_stackframe();
  44 
  45         if (conf_ctx == NULL) {
  46                 werr = WERR_INVALID_PARAM;
  47                 goto done;
  48         }
  49 
  50         if ((source == NULL) || (*source == '\0')) {
  51                 werr = WERR_INVALID_PARAM;
  52                 goto done;
  53         }
  54 
  55         backend = talloc_strdup(tmp_ctx, source);
  56         if (backend == NULL) {
  57                 werr = WERR_NOMEM;
  58                 goto done;
  59         }
  60 
  61         sep = strchr(backend, ':');
  62         if (sep != NULL) {
  63                 *sep = '\0';
  64                 path = sep + 1;
  65                 if (strlen(path) == 0) {
  66                         path = NULL;
  67                 }
  68         }
  69 
  70         if (strequal(backend, "registry") || strequal(backend, "reg")) {
  71                 werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
  72         } else if (strequal(backend, "file") || strequal(backend, "txt")) {
  73                 werr = smbconf_init_txt(mem_ctx, conf_ctx, path);
  74         } else if (sep == NULL) {
  75                 /*
  76                  * If no separator was given in the source, and the string is
  77                  * not a known backend, assume file backend and use the source
  78                  * string as a path argument.
  79                  */
  80                 werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);
  81         } else {
  82                 /*
  83                  * Separator was specified but this is not a known backend.
  84                  * As a last resort, try to interpret the original source
  85                  * string as a file name that contains a ":" sign.
  86                  * This may occur with an include directive like this:
  87                  * 'include = /path/to/file.%T'
  88                  */
  89                 werr = smbconf_init_txt(mem_ctx, conf_ctx, source);
  90         }
  91 
  92 done:
  93         talloc_free(tmp_ctx);
  94         return werr;
  95 }

/* [<][>][^][v][top][bottom][index][help] */