diff options
author | Michael Adam <obnox@samba.org> | 2008-04-07 15:01:44 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2008-04-10 01:28:55 +0200 |
commit | 36ede8ae549837452bbd577e43cda8d84ee22c4b (patch) | |
tree | cd87e051eabcd41a27d05a69eae86121caad527a /source3 | |
parent | 1fcbcbb486e7c599b11872f003ae213610ea09e4 (diff) | |
download | samba-36ede8ae549837452bbd577e43cda8d84ee22c4b.tar.gz samba-36ede8ae549837452bbd577e43cda8d84ee22c4b.tar.bz2 samba-36ede8ae549837452bbd577e43cda8d84ee22c4b.zip |
libsmbconf: move utility functions from main module to new smbconf_util.c
Michael
(This used to be commit e0f6a9d50c9b72ec33d4323d1a6c5bdf44d011e7)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 3 | ||||
-rw-r--r-- | source3/lib/smbconf/smbconf.c | 88 | ||||
-rw-r--r-- | source3/lib/smbconf/smbconf_util.c | 103 |
3 files changed, 105 insertions, 89 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 5241801978..89490be510 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -830,7 +830,8 @@ LIBNETAPI_OBJ = $(LIBNETAPI_OBJ1) $(LIBNET_OBJ) \ $(SECRETS_OBJ) $(PASSDB_OBJ) @LIBWBCLIENT_STATIC@ $(SMBLDAP_OBJ) $(GROUPDB_OBJ) $(LDB_OBJ) \ $(DCUTIL_OBJ) $(LIBADS_OBJ) $(PRIVILEGES_BASIC_OBJ) -LIBSMBCONF_OBJ = lib/smbconf/smbconf.o lib/smbconf/smbconf_reg.o \ +LIBSMBCONF_OBJ = lib/smbconf/smbconf.o lib/smbconf/smbconf_util.o \ + lib/smbconf/smbconf_reg.o \ lib/smbconf/smbconf_txt_simple.o LIBNET_OBJ = libnet/libnet_join.o \ diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 4315dd990e..62c5be8294 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -27,11 +27,6 @@ * **********************************************************************/ -static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) -{ - return ctx->ops->shutdown(ctx); -} - static WERROR smbconf_global_check(struct smbconf_ctx *ctx) { if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { @@ -43,89 +38,6 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx) /********************************************************************** * - * helper functions exported to the backend modules - * (might go into a smbconf_util.c) - * - **********************************************************************/ - -/** - * add a string to a talloced array of strings. - */ -WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, - char ***array, - uint32_t count, - const char *string) -{ - char **new_array = NULL; - - if ((array == NULL) || (string == NULL)) { - return WERR_INVALID_PARAM; - } - - new_array = TALLOC_REALLOC_ARRAY(mem_ctx, *array, char *, count + 1); - if (new_array == NULL) { - return WERR_NOMEM; - } - - new_array[count] = talloc_strdup(new_array, string); - if (new_array[count] == NULL) { - TALLOC_FREE(new_array); - return WERR_NOMEM; - } - - *array = new_array; - - return WERR_OK; -} - -/** - * Initialize the configuration. - * - * This should be the first function in a sequence of calls to smbconf - * functions: - * - * Upon success, this creates and returns the conf context - * that should be passed around in subsequent calls to the other - * smbconf functions. - * - * After the work with the configuration is completed, smbconf_shutdown() - * should be called. - */ -WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, - const char *path, struct smbconf_ops *ops) -{ - WERROR werr = WERR_OK; - struct smbconf_ctx *ctx; - - if (conf_ctx == NULL) { - return WERR_INVALID_PARAM; - } - - ctx = TALLOC_ZERO_P(mem_ctx, struct smbconf_ctx); - if (ctx == NULL) { - return WERR_NOMEM; - } - - ctx->ops = ops; - - werr = ctx->ops->init(ctx, path); - if (!W_ERROR_IS_OK(werr)) { - goto fail; - } - - talloc_set_destructor(ctx, smbconf_destroy_ctx); - - *conf_ctx = ctx; - return werr; - -fail: - TALLOC_FREE(ctx); - return werr; -} - - -/********************************************************************** - * * The actual libsmbconf API functions that are exported. * **********************************************************************/ diff --git a/source3/lib/smbconf/smbconf_util.c b/source3/lib/smbconf/smbconf_util.c new file mode 100644 index 0000000000..137e3a825c --- /dev/null +++ b/source3/lib/smbconf/smbconf_util.c @@ -0,0 +1,103 @@ +/* + * Unix SMB/CIFS implementation. + * libsmbconf - Samba configuration library, utility functions + * Copyright (C) Michael Adam 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" +#include "smbconf_private.h" + + +static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) +{ + return ctx->ops->shutdown(ctx); +} + +/** + * Initialize the configuration. + * + * This should be the first function in a sequence of calls to smbconf + * functions: + * + * Upon success, this creates and returns the conf context + * that should be passed around in subsequent calls to the other + * smbconf functions. + * + * After the work with the configuration is completed, smbconf_shutdown() + * should be called. + */ +WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, + const char *path, struct smbconf_ops *ops) +{ + WERROR werr = WERR_OK; + struct smbconf_ctx *ctx; + + if (conf_ctx == NULL) { + return WERR_INVALID_PARAM; + } + + ctx = TALLOC_ZERO_P(mem_ctx, struct smbconf_ctx); + if (ctx == NULL) { + return WERR_NOMEM; + } + + ctx->ops = ops; + + werr = ctx->ops->init(ctx, path); + if (!W_ERROR_IS_OK(werr)) { + goto fail; + } + + talloc_set_destructor(ctx, smbconf_destroy_ctx); + + *conf_ctx = ctx; + return werr; + +fail: + TALLOC_FREE(ctx); + return werr; +} + + +/** + * add a string to a talloced array of strings. + */ +WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, + char ***array, + uint32_t count, + const char *string) +{ + char **new_array = NULL; + + if ((array == NULL) || (string == NULL)) { + return WERR_INVALID_PARAM; + } + + new_array = TALLOC_REALLOC_ARRAY(mem_ctx, *array, char *, count + 1); + if (new_array == NULL) { + return WERR_NOMEM; + } + + new_array[count] = talloc_strdup(new_array, string); + if (new_array[count] == NULL) { + TALLOC_FREE(new_array); + return WERR_NOMEM; + } + + *array = new_array; + + return WERR_OK; +} |