From 36ede8ae549837452bbd577e43cda8d84ee22c4b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 7 Apr 2008 15:01:44 +0200 Subject: libsmbconf: move utility functions from main module to new smbconf_util.c Michael (This used to be commit e0f6a9d50c9b72ec33d4323d1a6c5bdf44d011e7) --- source3/lib/smbconf/smbconf.c | 88 ------------------------------- source3/lib/smbconf/smbconf_util.c | 103 +++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 88 deletions(-) create mode 100644 source3/lib/smbconf/smbconf_util.c (limited to 'source3/lib/smbconf') 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)) { @@ -41,89 +36,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 . + */ + +#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; +} -- cgit