*/
#include "includes.h"
-#include "smbconf_private.h"
+#include "lib/smbconf/smbconf_private.h"
#define INCLUDES_VALNAME "includes"
"lock dir",
"config backend",
"include",
+ "includes", /* this has a special meaning internally */
NULL
};
const char **forbidden = NULL;
static bool smbconf_reg_valname_valid(const char *valname)
{
- return (lp_parameter_is_valid(valname) &&
- !smbconf_reg_valname_forbidden(valname));
+ return (!smbconf_reg_valname_forbidden(valname) &&
+ lp_parameter_is_valid(valname));
}
/**
key);
if (!W_ERROR_IS_OK(werr)) {
- DEBUG(1, ("Error opening registry path '%s': %s\n",
- path, dos_errstr(werr)));
+ DEBUG(5, ("Error opening registry path '%s': %s\n",
+ path, win_errstr(werr)));
}
done:
char *path = NULL;
if (servicename == NULL) {
- DEBUG(3, ("Error: NULL servicename given.\n"));
- werr = WERR_INVALID_PARAM;
- goto done;
+ path = talloc_strdup(mem_ctx, ctx->path);
+ } else {
+ path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path,
+ servicename);
}
-
- path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, servicename);
if (path == NULL) {
werr = WERR_NOMEM;
goto done;
werr = smbconf_reg_open_path(mem_ctx, ctx, path, desired_access, key);
done:
- TALLOC_FREE(path);
+ talloc_free(path);
return werr;
}
ret = true;
}
- TALLOC_FREE(ctx);
+ talloc_free(ctx);
return ret;
}
/* create a new talloc ctx for creation. it will hold
* the intermediate parent key (SMBCONF) for creation
* and will be destroyed when leaving this function... */
- if (!(create_ctx = talloc_stackframe())) {
- werr = WERR_NOMEM;
- goto done;
- }
+ create_ctx = talloc_stackframe();
werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE,
&create_parent);
REG_KEY_WRITE, newkey, &action);
if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
- werr = WERR_ALREADY_EXISTS;
+ werr = WERR_FILE_EXISTS;
}
if (!W_ERROR_IS_OK(werr)) {
DEBUG(5, ("Error creating key %s: %s\n",
- subkeyname, dos_errstr(werr)));
+ subkeyname, win_errstr(werr)));
}
done:
- TALLOC_FREE(create_ctx);
+ talloc_free(create_ctx);
return werr;
}
if (!W_ERROR_IS_OK(werr)) {
DEBUG(5, ("Error adding value '%s' to "
"key '%s': %s\n",
- canon_valname, key->key->name, dos_errstr(werr)));
+ canon_valname, key->key->name, win_errstr(werr)));
}
done:
werr = reg_setvalue(key, valname, value);
if (!W_ERROR_IS_OK(werr)) {
DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
- valname, key->key->name, dos_errstr(werr)));
+ valname, key->key->name, win_errstr(werr)));
}
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
return werr;
}
}
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
return werr;
}
}
tmp_ctx = talloc_stackframe();
- if (tmp_ctx == NULL) {
- werr = WERR_NOMEM;
- goto done;
- }
for (count = 0;
werr = reg_enumvalue(tmp_ctx, key, count, &valname, &valvalue),
}
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
+ return werr;
+}
+
+static bool smbconf_reg_key_has_values(struct registry_key *key)
+{
+ WERROR werr;
+ uint32_t num_subkeys;
+ uint32_t max_subkeylen;
+ uint32_t max_subkeysize;
+ uint32_t num_values;
+ uint32_t max_valnamelen;
+ uint32_t max_valbufsize;
+ uint32_t secdescsize;
+ NTTIME last_changed_time;
+
+ werr = reg_queryinfokey(key, &num_subkeys, &max_subkeylen,
+ &max_subkeysize, &num_values, &max_valnamelen,
+ &max_valbufsize, &secdescsize,
+ &last_changed_time);
+ if (!W_ERROR_IS_OK(werr)) {
+ return false;
+ }
+
+ return (num_values != 0);
+}
+
+/**
+ * delete all values from a key
+ */
+static WERROR smbconf_reg_delete_values(struct registry_key *key)
+{
+ WERROR werr;
+ char *valname;
+ struct registry_value *valvalue;
+ uint32_t count;
+ TALLOC_CTX *mem_ctx = talloc_stackframe();
+
+ for (count = 0;
+ werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue),
+ W_ERROR_IS_OK(werr);
+ count++)
+ {
+ werr = reg_deletevalue(key, valname);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+ }
+ if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
+ DEBUG(1, ("smbconf_reg_delete_values: "
+ "Error enumerating values of %s: %s\n",
+ key->key->name,
+ win_errstr(werr)));
+ goto done;
+ }
+
+ werr = WERR_OK;
+
+done:
+ talloc_free(mem_ctx);
return werr;
}
}
rpd(ctx)->open = false;
- if (!registry_init_smbconf()) {
- werr = WERR_REG_IO_FAILURE;
+ werr = registry_init_smbconf(path);
+ if (!W_ERROR_IS_OK(werr)) {
goto done;
}
return ctx->ops->close_conf(ctx);
}
+static bool smbconf_reg_requires_messaging(struct smbconf_ctx *ctx)
+{
+#ifdef CLUSTER_SUPPORT
+ if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) {
+ return true;
+ }
+#endif
+ return false;
+}
+
+static bool smbconf_reg_is_writeable(struct smbconf_ctx *ctx)
+{
+ /*
+ * The backend has write support.
+ *
+ * TODO: add access checks whether the concrete
+ * config source is really writeable by the calling user.
+ */
+ return true;
+}
+
static WERROR smbconf_reg_open(struct smbconf_ctx *ctx)
{
WERROR werr;
&new_key, &action);
done:
- TALLOC_FREE(mem_ctx);
+ talloc_free(mem_ctx);
return werr;
}
}
tmp_ctx = talloc_stackframe();
- if (tmp_ctx == NULL) {
- werr = WERR_NOMEM;
+
+ /* if there are values in the base key, return NULL as share name */
+ werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
+ SEC_RIGHTS_ENUM_SUBKEYS, &key);
+ if (!W_ERROR_IS_OK(werr)) {
goto done;
}
- /* make sure "global" is always listed first */
- if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
+ if (smbconf_reg_key_has_values(key)) {
werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
- 0, GLOBAL_NAME);
+ 0, NULL);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
added_count++;
}
- werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
- SEC_RIGHTS_ENUM_SUBKEYS, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
+ /* make sure "global" is always listed first */
+ if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
+ werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
+ added_count, GLOBAL_NAME);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+ added_count++;
}
for (count = 0;
}
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
return werr;
}
ret = true;
}
- TALLOC_FREE(mem_ctx);
+ talloc_free(mem_ctx);
return ret;
}
TALLOC_CTX *mem_ctx = talloc_stackframe();
struct registry_key *key = NULL;
- werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key);
+ if (servicename == NULL) {
+ werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE,
+ &key);
+ } else {
+ werr = smbconf_reg_create_service_key(mem_ctx, ctx,
+ servicename, &key);
+ }
- TALLOC_FREE(mem_ctx);
+ talloc_free(mem_ctx);
return werr;
}
static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
const char *servicename,
- uint32_t *num_params,
- char ***param_names, char ***param_values)
+ struct smbconf_service **service)
{
WERROR werr = WERR_OK;
struct registry_key *key = NULL;
+ struct smbconf_service *tmp_service = NULL;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
- werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
+ werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
+ if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
+ werr = WERR_NO_SUCH_SERVICE;
+ }
+ goto done;
+ }
+
+ tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
+ if (tmp_service == NULL) {
+ werr = WERR_NOMEM;
goto done;
}
- werr = smbconf_reg_get_values(mem_ctx, key, num_params,
- param_names, param_values);
+ if (servicename != NULL) {
+ tmp_service->name = talloc_strdup(tmp_service, servicename);
+ if (tmp_service->name == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+ }
+
+ werr = smbconf_reg_get_values(tmp_service, key,
+ &(tmp_service->num_params),
+ &(tmp_service->param_names),
+ &(tmp_service->param_values));
+
+ if (W_ERROR_IS_OK(werr)) {
+ *service = talloc_move(mem_ctx, &tmp_service);
+ }
done:
- TALLOC_FREE(key);
+ talloc_free(tmp_ctx);
return werr;
}
goto done;
}
- werr = reg_deletekey_recursive(key, key, servicename);
+ if (servicename != NULL) {
+ werr = reg_deletekey_recursive(key, key, servicename);
+ } else {
+ werr = smbconf_reg_delete_values(key);
+ }
done:
- TALLOC_FREE(mem_ctx);
+ talloc_free(mem_ctx);
return werr;
}
werr = smbconf_reg_set_value(key, param, valstr);
done:
- TALLOC_FREE(mem_ctx);
+ talloc_free(mem_ctx);
return werr;
}
}
done:
- TALLOC_FREE(key);
- TALLOC_FREE(value);
+ talloc_free(key);
+ talloc_free(value);
return werr;
}
werr = reg_deletevalue(key, param);
done:
- TALLOC_FREE(mem_ctx);
+ talloc_free(mem_ctx);
return werr;
}
includes);
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
return werr;
}
}
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
return werr;
}
done:
- TALLOC_FREE(tmp_ctx);
+ talloc_free(tmp_ctx);
return werr;
}
struct smbconf_ops smbconf_ops_reg = {
.init = smbconf_reg_init,
.shutdown = smbconf_reg_shutdown,
+ .requires_messaging = smbconf_reg_requires_messaging,
+ .is_writeable = smbconf_reg_is_writeable,
.open_conf = smbconf_reg_open,
.close_conf = smbconf_reg_close,
.get_csn = smbconf_reg_get_csn,
WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
const char *path)
{
- return smbconf_init(mem_ctx, conf_ctx, path, &smbconf_ops_reg);
+ return smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_reg);
}