mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
libsmbconf: add smbconf_create_set_share
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, base_service_def); Pair-Programmed-With: Michael Adam <obnox@samba.org> Signed-off-by: David Disseldorp <ddiss@samba.org> Signed-off-by: Michael Adam <obnox@samba.org>
This commit is contained in:
parent
57634fd87d
commit
caf83bcb76
@ -230,6 +230,83 @@ 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,
|
||||
struct smbconf_service *service)
|
||||
{
|
||||
sbcErr err, err2;
|
||||
int i;
|
||||
uint32_t num_includes = 0;
|
||||
char **includes = NULL;
|
||||
TALLOC_CTX *tmp_ctx = NULL;
|
||||
|
||||
if ((service->name != NULL) && smbconf_share_exists(ctx, service->name))
|
||||
{
|
||||
return SBC_ERR_FILE_EXISTS;
|
||||
}
|
||||
|
||||
err = smbconf_transaction_start(ctx);
|
||||
if (!SBC_ERROR_IS_OK(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
tmp_ctx = talloc_stackframe();
|
||||
|
||||
err = smbconf_create_share(ctx, service->name);
|
||||
if (!SBC_ERROR_IS_OK(err)) {
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
for (i = 0; i < service->num_params; i++) {
|
||||
if (strequal(service->param_names[i], "include")) {
|
||||
includes = talloc_realloc(tmp_ctx, includes, char *,
|
||||
num_includes+1);
|
||||
if (includes == NULL) {
|
||||
err = SBC_ERR_NOMEM;
|
||||
goto cancel;
|
||||
}
|
||||
includes[num_includes] = talloc_strdup(includes,
|
||||
service->param_values[i]);
|
||||
if (includes[num_includes] == NULL) {
|
||||
err = SBC_ERR_NOMEM;
|
||||
goto cancel;
|
||||
}
|
||||
num_includes++;
|
||||
} else {
|
||||
err = smbconf_set_parameter(ctx,
|
||||
service->name,
|
||||
service->param_names[i],
|
||||
service->param_values[i]);
|
||||
if (!SBC_ERROR_IS_OK(err)) {
|
||||
goto cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = smbconf_set_includes(ctx, service->name, num_includes,
|
||||
(const char **)includes);
|
||||
if (!SBC_ERROR_IS_OK(err)) {
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
err = smbconf_transaction_commit(ctx);
|
||||
|
||||
goto done;
|
||||
|
||||
cancel:
|
||||
err2 = smbconf_transaction_cancel(ctx);
|
||||
if (!SBC_ERROR_IS_OK(err2)) {
|
||||
DEBUG(5, (__location__ ": Error cancelling transaction: %s\n",
|
||||
sbcErrorString(err2)));
|
||||
}
|
||||
|
||||
done:
|
||||
talloc_free(tmp_ctx);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a definition of a share (service) from configuration.
|
||||
*/
|
||||
|
@ -204,6 +204,19 @@ 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] 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,
|
||||
struct smbconf_service *service);
|
||||
|
||||
/**
|
||||
* @brief Get a definition of a share (service) from configuration.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user