libsmbconf: fix comment typo.
[obnox/samba-ctdb.git] / source / lib / smbconf / smbconf_init.c
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 "smbconf_private.h"
22
23 /**
24  * smbconf initialization dispatcher
25  *
26  * this takes a configuration source in the form of
27  * backend:path and calles the appropriate backend
28  * init function with the path argument
29  *
30  * known backends:
31  * -  "registry" or "reg"
32  * -  "txt" or "file"
33  */
34 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
35                     const char *source)
36 {
37         WERROR werr;
38         char *backend = NULL;
39         char *path = NULL;
40         char *sep;
41         TALLOC_CTX *tmp_ctx = talloc_stackframe();
42
43         if (conf_ctx == NULL) {
44                 werr = WERR_INVALID_PARAM;
45                 goto done;
46         }
47
48         if ((source == NULL) || (*source == '\0')) {
49                 werr = WERR_INVALID_PARAM;
50                 goto done;
51         }
52
53         backend = talloc_strdup(tmp_ctx, source);
54         if (backend == NULL) {
55                 werr = WERR_NOMEM;
56                 goto done;
57         }
58
59         sep = strchr(backend, ':');
60         if (sep != NULL) {
61                 *sep = '\0';
62                 path = sep + 1;
63                 if (strlen(path) == 0) {
64                         path = NULL;
65                 }
66         }
67
68         if (strequal(backend, "registry") || strequal(backend, "reg")) {
69                 werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
70         } else if (strequal(backend, "file") || strequal(backend, "txt")) {
71                 werr = smbconf_init_txt(mem_ctx, conf_ctx, path);
72         } else if (sep == NULL) {
73                 /*
74                  * If no separator was given in the source, and the string is
75                  * not a known backend, assume file backend and use the source
76                  * string as a path argument.
77                  */
78                 werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);
79         } else {
80                 /*
81                  * Separator was specified but this is not a known backend.
82                  * Can't handle this.
83                  */
84                 DEBUG(1, ("smbconf_init: ERROR - unknown backend '%s' given\n",
85                           backend));
86                 werr = WERR_INVALID_PARAM;
87         }
88
89 done:
90         TALLOC_FREE(tmp_ctx);
91         return werr;
92 }