libsmbconf: add smbconf_create_set_share
authorDavid Disseldorp <ddiss@samba.org>
Fri, 20 Apr 2012 16:34:17 +0000 (18:34 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Mon, 15 Apr 2013 16:15:19 +0000 (18:15 +0200)
This call creates a new share definition, using the parameters provided
with a smbconf_service structure.
Such an interface allows for simple cloning of services with:
smbconf_get_share(conf_ctx, mem_ctx, base_sharename, &base_service_def);
base_service_def->name = clone_sharename;
smbconf_create_set_share(conf_ctx, clone_sharename, base_service_def);

lib/smbconf/smbconf.c
lib/smbconf/smbconf.h
lib/smbconf/smbconf_private.h
lib/smbconf/smbconf_txt.c
source3/lib/smbconf/smbconf_reg.c

index e0441ed9857f1d09bf4ca69a95b416d8ce5535a2..37048a469e63de9ed31263d50042bcf7955795e2 100644 (file)
@@ -230,6 +230,20 @@ sbcErr smbconf_create_share(struct smbconf_ctx *ctx,
        return ctx->ops->create_share(ctx, servicename);
 }
 
+/**
+ * create and set the definition for a new share (service).
+ */
+sbcErr smbconf_create_set_share(struct smbconf_ctx *ctx,
+                               const char *servicename,
+                               struct smbconf_service *service)
+{
+       if ((servicename != NULL) && smbconf_share_exists(ctx, servicename)) {
+               return SBC_ERR_FILE_EXISTS;
+       }
+
+       return ctx->ops->create_set_share(ctx, servicename, service);
+}
+
 /**
  * get a definition of a share (service) from configuration.
  */
index 7f62b06af45bd809a2cf7a7cbba48645fa569382..4fc2ae3d218c24f2917b87300f794c582fb8cf0b 100644 (file)
@@ -204,6 +204,22 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename);
  */
 sbcErr smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename);
 
+/**
+ * @brief create and set the definition for a new service.
+ *
+ * @param[in] ctx       The smbconf context to use.
+ *
+ * @param[in] servicename The name of the service to add.
+ *
+ * @param[in] service   The definition for the added service.
+ *
+ * @return              SBC_ERR_OK on success, a corresponding sbcErr if an
+ *                      error occured.
+ */
+sbcErr smbconf_create_set_share(struct smbconf_ctx *ctx,
+                               const char *servicename,
+                               struct smbconf_service *service);
+
 /**
  * @brief Get a definition of a share (service) from configuration.
  *
index e768c30b91eb6cc7e685ad72156ae0fa0457732d..0205ce9a2f3c475754fbd4922911064105fd5c39 100644 (file)
@@ -42,6 +42,9 @@ struct smbconf_ops {
                                  char ***share_names);
        bool (*share_exists)(struct smbconf_ctx *ctx, const char *service);
        sbcErr (*create_share)(struct smbconf_ctx *ctx, const char *service);
+       sbcErr (*create_set_share)(struct smbconf_ctx *ctx,
+                                  const char *servicename,
+                                  struct smbconf_service *service);
        sbcErr (*get_share)(struct smbconf_ctx *ctx,
                            TALLOC_CTX *mem_ctx,
                            const char *servicename,
index 5c4bd27b9df06d3f719ad2871241e6ec64dd6adb..4432346a4b820c410d480db7c10ac98881889fe0 100644 (file)
@@ -391,6 +391,16 @@ static sbcErr smbconf_txt_create_share(struct smbconf_ctx *ctx,
        return SBC_ERR_NOT_SUPPORTED;
 }
 
+/**
+ * create and set the definition for a new share (service).
+ */
+static sbcErr smbconf_txt_create_set_share(struct smbconf_ctx *ctx,
+                                          const char *servicename,
+                                          struct smbconf_service *service)
+{
+       return SBC_ERR_NOT_SUPPORTED;
+}
+
 /**
  * get a definition of a share (service) from configuration.
  */
@@ -635,6 +645,7 @@ static struct smbconf_ops smbconf_ops_txt = {
        .get_share_names        = smbconf_txt_get_share_names,
        .share_exists           = smbconf_txt_share_exists,
        .create_share           = smbconf_txt_create_share,
+       .create_set_share       = smbconf_txt_create_set_share,
        .get_share              = smbconf_txt_get_share,
        .delete_share           = smbconf_txt_delete_share,
        .set_parameter          = smbconf_txt_set_parameter,
index ec6b93fd09dc2c50545479813eed14fbaa5415dd..1853f0ee315681d44367b55660b315e5fe0ca516 100644 (file)
@@ -894,6 +894,37 @@ static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx,
        return err;
 }
 
+/**
+ * create and set the definition for a new share (service).
+ */
+static sbcErr smbconf_reg_create_set_share(struct smbconf_ctx *ctx,
+                                          const char *servicename,
+                                          struct smbconf_service *service)
+{
+       sbcErr err;
+       struct registry_key *key = NULL;
+       int i;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+
+       err = smbconf_reg_create_service_key(tmp_ctx, ctx,
+                                            servicename, &key);
+       if (!SBC_ERROR_IS_OK(err)) {
+               goto done;
+       }
+
+       for (i = 0; i < service->num_params; i++) {
+               err = smbconf_reg_set_value(key, service->param_names[i],
+                                           service->param_values[i]);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       goto done;
+               }
+       }
+
+done:
+       talloc_free(tmp_ctx);
+       return err;
+}
+
 /**
  * get a definition of a share (service) from configuration.
  */
@@ -1215,6 +1246,7 @@ struct smbconf_ops smbconf_ops_reg = {
        .get_share_names        = smbconf_reg_get_share_names,
        .share_exists           = smbconf_reg_share_exists,
        .create_share           = smbconf_reg_create_share,
+       .create_set_share       = smbconf_reg_create_set_share,
        .get_share              = smbconf_reg_get_share,
        .delete_share           = smbconf_reg_delete_share,
        .set_parameter          = smbconf_reg_set_parameter,