/*
* Unix SMB/CIFS implementation.
* libnet smbconf registry Support
- * Copyright (C) Michael Adam 2007
+ * Copyright (C) Michael Adam 2007-2008
* Copyright (C) Guenther Deschner 2007
*
* This program is free software; you can redistribute it and/or modify
uint32_t count,
const char *string)
{
- WERROR werr = WERR_OK;
char **new_array = NULL;
if ((array == NULL) || (string == NULL)) {
return WERR_OK;
}
-/*
- * Open a subkey of KEY_SMBCONF (i.e a service)
+/**
+ * Open a registry key specified by "path"
*/
-static WERROR libnet_smbconf_reg_open_path(TALLOC_CTX *ctx,
- const char *subkeyname,
+static WERROR libnet_smbconf_reg_open_path(TALLOC_CTX *mem_ctx,
+ const char *path,
uint32 desired_access,
struct registry_key **key)
{
WERROR werr = WERR_OK;
- char *path = NULL;
NT_USER_TOKEN *token;
+ TALLOC_CTX *tmp_ctx = NULL;
- if (!(token = registry_create_admin_token(ctx))) {
- DEBUG(1, ("Error creating admin token\n"));
+ if (path == NULL) {
+ DEBUG(1, ("Error: NULL path string given\n"));
+ werr = WERR_INVALID_PARAM;
goto done;
}
- if (subkeyname == NULL) {
- path = talloc_strdup(ctx, KEY_SMBCONF);
- } else {
- path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, subkeyname);
+ tmp_ctx = talloc_new(mem_ctx);
+ if (tmp_ctx == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+
+ token = registry_create_admin_token(tmp_ctx);
+ if (token == NULL) {
+ DEBUG(1, ("Error creating admin token\n"));
+ /* what is the appropriate error code here? */
+ werr = WERR_CAN_NOT_COMPLETE;
+ goto done;
}
- werr = reg_open_path(ctx, path, desired_access,
- token, key);
+ werr = reg_open_path(mem_ctx, path, desired_access, token, key);
if (!W_ERROR_IS_OK(werr)) {
DEBUG(1, ("Error opening registry path '%s': %s\n",
}
done:
- TALLOC_FREE(path);
+ TALLOC_FREE(tmp_ctx);
return werr;
}
-/*
- * open the base key KEY_SMBCONF
+/**
+ * Open a subkey of KEY_SMBCONF (i.e a service)
*/
-static WERROR libnet_smbconf_reg_open_basepath(TALLOC_CTX *ctx,
- uint32 desired_access,
- struct registry_key **key)
+static WERROR libnet_smbconf_reg_open_service_key(TALLOC_CTX *ctx,
+ const char *servicename,
+ uint32 desired_access,
+ struct registry_key **key)
{
- return libnet_smbconf_reg_open_path(ctx, NULL, desired_access, key);
+ WERROR werr = WERR_OK;
+ char *path = NULL;
+
+ if (servicename == NULL) {
+ DEBUG(3, ("Error: NULL servicename given.\n"));
+ werr = WERR_INVALID_PARAM;
+ goto done;
+ }
+
+ path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, servicename);
+
+ werr = libnet_smbconf_reg_open_path(ctx, path, desired_access, key);
+
+done:
+ TALLOC_FREE(path);
+ return werr;
}
/*
- * check if a subkey of KEY_SMBCONF of a given name exists
+ * open the base key KEY_SMBCONF
*/
-bool libnet_smbconf_key_exists(const char *subkeyname)
+static WERROR libnet_smbconf_reg_open_basekey(TALLOC_CTX *ctx,
+ uint32 desired_access,
+ struct registry_key **key)
{
- bool ret = false;
- WERROR werr = WERR_OK;
- TALLOC_CTX *mem_ctx = talloc_stackframe();
- struct registry_key *key = NULL;
-
- werr = libnet_smbconf_reg_open_path(mem_ctx, subkeyname, REG_KEY_READ,
- &key);
- if (W_ERROR_IS_OK(werr)) {
- ret = true;
- }
-
- TALLOC_FREE(mem_ctx);
- return ret;
+ return libnet_smbconf_reg_open_path(ctx, KEY_SMBCONF, desired_access,
+ key);
}
static bool libnet_smbconf_value_exists(struct registry_key *key,
/*
* create a subkey of KEY_SMBCONF
*/
-WERROR libnet_smbconf_reg_createkey_internal(TALLOC_CTX *ctx,
- const char * subkeyname,
- struct registry_key **newkey)
+static WERROR libnet_smbconf_reg_create_service_key(TALLOC_CTX *ctx,
+ const char * subkeyname,
+ struct registry_key **newkey)
{
WERROR werr = WERR_OK;
struct registry_key *create_parent = NULL;
goto done;
}
- werr = libnet_smbconf_reg_open_basepath(create_ctx, REG_KEY_WRITE,
- &create_parent);
+ werr = libnet_smbconf_reg_open_basekey(create_ctx, REG_KEY_WRITE,
+ &create_parent);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
/*
* add a value to a key.
*/
-WERROR libnet_smbconf_reg_setvalue_internal(struct registry_key *key,
+static WERROR libnet_smbconf_reg_setvalue_internal(struct registry_key *key,
const char *valname,
const char *valstr)
{
{
char *path, *p;
WERROR werr = WERR_OK;
- NT_USER_TOKEN *token;
struct registry_key *parent_key = NULL;
struct registry_key *new_key = NULL;
TALLOC_CTX* mem_ctx = talloc_stackframe();
enum winreg_CreateAction action;
- if (!(token = registry_create_admin_token(mem_ctx))) {
- /* what is the appropriate error code here? */
- werr = WERR_CAN_NOT_COMPLETE;
- goto done;
- }
-
path = talloc_strdup(mem_ctx, KEY_SMBCONF);
if (path == NULL) {
werr = WERR_NOMEM;
}
p = strrchr(path, '\\');
*p = '\0';
- werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token, &parent_key);
+ werr = libnet_smbconf_reg_open_path(mem_ctx, path, REG_KEY_WRITE,
+ &parent_key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
/* make sure "global" is always listed first */
- if (libnet_smbconf_key_exists(GLOBAL_NAME)) {
+ if (libnet_smbconf_share_exists(GLOBAL_NAME)) {
werr = libnet_smbconf_add_string_to_array(tmp_ctx,
&tmp_share_names,
0, GLOBAL_NAME);
added_count++;
}
- werr = libnet_smbconf_reg_open_basepath(tmp_ctx,
- SEC_RIGHTS_ENUM_SUBKEYS,
- &key);
+ werr = libnet_smbconf_reg_open_basekey(tmp_ctx,
+ SEC_RIGHTS_ENUM_SUBKEYS,
+ &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
return werr;
}
+/**
+ * check if a share/service of a given name exists
+ */
+bool libnet_smbconf_share_exists(const char *servicename)
+{
+ bool ret = false;
+ WERROR werr = WERR_OK;
+ TALLOC_CTX *mem_ctx = talloc_stackframe();
+ struct registry_key *key = NULL;
+
+ werr = libnet_smbconf_reg_open_service_key(mem_ctx, servicename,
+ REG_KEY_READ, &key);
+ if (W_ERROR_IS_OK(werr)) {
+ ret = true;
+ }
+
+ TALLOC_FREE(mem_ctx);
+ return ret;
+}
+
+/**
+ * Add a service if it does not already exist.
+ */
+WERROR libnet_smbconf_create_share(const char *servicename)
+{
+ WERROR werr;
+ TALLOC_CTX *mem_ctx = talloc_stackframe();
+ struct registry_key *key = NULL;
+
+ if (libnet_smbconf_share_exists(servicename)) {
+ werr = WERR_ALREADY_EXISTS;
+ goto done;
+ }
+
+ werr = libnet_smbconf_reg_create_service_key(mem_ctx, servicename, &key);
+
+done:
+ TALLOC_FREE(mem_ctx);
+ return werr;
+}
+
/**
* get a definition of a share (service) from configuration.
*/
WERROR werr = WERR_OK;
struct registry_key *key = NULL;
- werr = libnet_smbconf_reg_open_path(mem_ctx, servicename, REG_KEY_READ,
- &key);
+ werr = libnet_smbconf_reg_open_service_key(mem_ctx, servicename,
+ REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
struct registry_key *key = NULL;
TALLOC_CTX *ctx = talloc_stackframe();
- werr = libnet_smbconf_reg_open_basepath(ctx, REG_KEY_WRITE, &key);
+ werr = libnet_smbconf_reg_open_basekey(ctx, REG_KEY_WRITE, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
struct registry_key *key = NULL;
TALLOC_CTX *mem_ctx = talloc_stackframe();
- if (!libnet_smbconf_key_exists(service)) {
- werr = libnet_smbconf_reg_createkey_internal(mem_ctx, service,
- &key);
- } else {
- werr = libnet_smbconf_reg_open_path(mem_ctx, service,
- REG_KEY_WRITE, &key);
+ if (!libnet_smbconf_share_exists(service)) {
+ werr = WERR_NO_SUCH_SERVICE;
+ goto done;
}
+
+ werr = libnet_smbconf_reg_open_service_key(mem_ctx, service,
+ REG_KEY_WRITE, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
goto done;
}
- if (!libnet_smbconf_key_exists(service)) {
+ if (!libnet_smbconf_share_exists(service)) {
werr = WERR_NO_SUCH_SERVICE;
goto done;
}
- werr = libnet_smbconf_reg_open_path(mem_ctx, service, REG_KEY_READ,
- &key);
+ werr = libnet_smbconf_reg_open_service_key(mem_ctx, service,
+ REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
WERROR werr = WERR_OK;
TALLOC_CTX *mem_ctx = talloc_stackframe();
- if (!libnet_smbconf_key_exists(service)) {
+ if (!libnet_smbconf_share_exists(service)) {
return WERR_NO_SUCH_SERVICE;
}
- werr = libnet_smbconf_reg_open_path(mem_ctx, service, REG_KEY_ALL, &key);
+ werr = libnet_smbconf_reg_open_service_key(mem_ctx, service,
+ REG_KEY_ALL, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}