libsmbconf: move utility functions from main module to new smbconf_util.c
authorMichael Adam <obnox@samba.org>
Mon, 7 Apr 2008 13:01:44 +0000 (15:01 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 9 Apr 2008 23:28:55 +0000 (01:28 +0200)
Michael
(This used to be commit e0f6a9d50c9b72ec33d4323d1a6c5bdf44d011e7)

source3/Makefile.in
source3/lib/smbconf/smbconf.c
source3/lib/smbconf/smbconf_util.c [new file with mode: 0644]

index 52418019782533288b83e0a98467ee2e9669eff4..89490be510b8a17dd0ca3e928ae5e441cc7ef4bc 100644 (file)
@@ -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 \
index 4315dd990efdd7ff65eea80153b1013899ec6cab..62c5be829497b1ad33e70482954eb9bf1ece5ac0 100644 (file)
  *
  **********************************************************************/
 
-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 (file)
index 0000000..137e3a8
--- /dev/null
@@ -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;
+}