From 670418c1165f0a149bfdd4bcdc5bde575df43ef2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 17 Mar 2008 17:29:44 +0100 Subject: Move libnet_conf to a library lib/smbconf/ of its own, fixing the api. The libnet_conf code to access the registry based configuration has become more of a library used in several places in samba (e.g. loadparm) than an abstraction of "net conf". So I move it to a location lib/smbconf/. In the same breath, the api is fixed (not generated by make proto anymore). Michael (This used to be commit 5315ef41f403b96715dd68b512e9e74662e2910a) --- source3/lib/smbconf/smbconf.c | 973 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 973 insertions(+) create mode 100644 source3/lib/smbconf/smbconf.c (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c new file mode 100644 index 0000000000..688097bc5e --- /dev/null +++ b/source3/lib/smbconf/smbconf.c @@ -0,0 +1,973 @@ +/* + * Unix SMB/CIFS implementation. + * libnet smbconf registry Support + * Copyright (C) Michael Adam 2007-2008 + * Copyright (C) Guenther Deschner 2007 + * + * 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 . + */ + +#include "includes.h" +#include "libnet/libnet.h" + +/********************************************************************** + * + * Helper functions (mostly registry related) + * TODO: These should be eventually static. + + **********************************************************************/ + +/** + * add a string to a talloced array of strings. + */ +static WERROR libnet_conf_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; +} + +static WERROR libnet_conf_reg_initialize(struct libnet_conf_ctx *ctx) +{ + WERROR werr = WERR_OK; + + if (!registry_init_smbconf()) { + werr = WERR_REG_IO_FAILURE; + goto done; + } + + werr = ntstatus_to_werror(registry_create_admin_token(ctx, + &(ctx->token))); + if (!W_ERROR_IS_OK(werr)) { + DEBUG(1, ("Error creating admin token\n")); + goto done; + } + +done: + return werr; +} + +/** + * Open a registry key specified by "path" + */ +static WERROR libnet_conf_reg_open_path(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + const char *path, + uint32 desired_access, + struct registry_key **key) +{ + WERROR werr = WERR_OK; + + if (ctx == NULL) { + DEBUG(1, ("Error: configuration is not open!\n")); + werr = WERR_INVALID_PARAM; + goto done; + } + + if (ctx->token == NULL) { + DEBUG(1, ("Error: token missing from libnet_conf_ctx. " + "was libnet_conf_open() called?\n")); + werr = WERR_INVALID_PARAM; + goto done; + } + + if (path == NULL) { + DEBUG(1, ("Error: NULL path string given\n")); + werr = WERR_INVALID_PARAM; + goto done; + } + + werr = reg_open_path(mem_ctx, path, desired_access, ctx->token, key); + + if (!W_ERROR_IS_OK(werr)) { + DEBUG(1, ("Error opening registry path '%s': %s\n", + path, dos_errstr(werr))); + } + +done: + return werr; +} + +/** + * Open a subkey of KEY_SMBCONF (i.e a service) + */ +static WERROR libnet_conf_reg_open_service_key(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + const char *servicename, + uint32 desired_access, + struct registry_key **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(mem_ctx, "%s\\%s", KEY_SMBCONF, servicename); + if (path == NULL) { + werr = WERR_NOMEM; + goto done; + } + + werr = libnet_conf_reg_open_path(mem_ctx, ctx, path, desired_access, + key); + +done: + TALLOC_FREE(path); + return werr; +} + +/** + * open the base key KEY_SMBCONF + */ +static WERROR libnet_conf_reg_open_base_key(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + uint32 desired_access, + struct registry_key **key) +{ + return libnet_conf_reg_open_path(mem_ctx, ctx, KEY_SMBCONF, + desired_access, key); +} + +/** + * check if a value exists in a given registry key + */ +static bool libnet_conf_value_exists(struct registry_key *key, + const char *param) +{ + bool ret = false; + WERROR werr = WERR_OK; + TALLOC_CTX *ctx = talloc_stackframe(); + struct registry_value *value = NULL; + + werr = reg_queryvalue(ctx, key, param, &value); + if (W_ERROR_IS_OK(werr)) { + ret = true; + } + + TALLOC_FREE(ctx); + return ret; +} + +/** + * create a subkey of KEY_SMBCONF + */ +static WERROR libnet_conf_reg_create_service_key(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + const char * subkeyname, + struct registry_key **newkey) +{ + WERROR werr = WERR_OK; + struct registry_key *create_parent = NULL; + TALLOC_CTX *create_ctx; + enum winreg_CreateAction action = REG_ACTION_NONE; + + /* 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; + } + + werr = libnet_conf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE, + &create_parent); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_createkey(mem_ctx, create_parent, subkeyname, + 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; + } + if (!W_ERROR_IS_OK(werr)) { + DEBUG(5, ("Error creating key %s: %s\n", + subkeyname, dos_errstr(werr))); + } + +done: + TALLOC_FREE(create_ctx); + return werr; +} + +/** + * add a value to a key. + */ +static WERROR libnet_conf_reg_set_value(struct registry_key *key, + const char *valname, + const char *valstr) +{ + struct registry_value val; + WERROR werr = WERR_OK; + char *subkeyname; + const char *canon_valname; + const char *canon_valstr; + + if (!lp_canonicalize_parameter_with_value(valname, valstr, + &canon_valname, + &canon_valstr)) + { + if (canon_valname == NULL) { + DEBUG(5, ("invalid parameter '%s' given\n", + valname)); + } else { + DEBUG(5, ("invalid value '%s' given for " + "parameter '%s'\n", valstr, valname)); + } + werr = WERR_INVALID_PARAM; + goto done; + } + + ZERO_STRUCT(val); + + val.type = REG_SZ; + val.v.sz.str = CONST_DISCARD(char *, canon_valstr); + val.v.sz.len = strlen(canon_valstr) + 1; + + if (registry_smbconf_valname_forbidden(canon_valname)) { + DEBUG(5, ("Parameter '%s' not allowed in registry.\n", + canon_valname)); + werr = WERR_INVALID_PARAM; + goto done; + } + + subkeyname = strrchr_m(key->key->name, '\\'); + if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) { + DEBUG(5, ("Invalid registry key '%s' given as " + "smbconf section.\n", key->key->name)); + werr = WERR_INVALID_PARAM; + goto done; + } + subkeyname++; + if (!strequal(subkeyname, GLOBAL_NAME) && + lp_parameter_is_global(valname)) + { + DEBUG(5, ("Global paramter '%s' not allowed in " + "service definition ('%s').\n", canon_valname, + subkeyname)); + werr = WERR_INVALID_PARAM; + goto done; + } + + werr = reg_setvalue(key, canon_valname, &val); + 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))); + } + +done: + return werr; +} + +/** + * format a registry_value into a string. + * + * This is intended to be used for smbconf registry values, + * which are ar stored as REG_SZ values, so the incomplete + * handling should be ok. + */ +static char *libnet_conf_format_registry_value(TALLOC_CTX *mem_ctx, + struct registry_value *value) +{ + char *result = NULL; + + /* alternatively, create a new talloc context? */ + if (mem_ctx == NULL) { + return result; + } + + switch (value->type) { + case REG_DWORD: + result = talloc_asprintf(mem_ctx, "%d", value->v.dword); + break; + case REG_SZ: + case REG_EXPAND_SZ: + result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str); + break; + case REG_MULTI_SZ: { + uint32 j; + for (j = 0; j < value->v.multi_sz.num_strings; j++) { + result = talloc_asprintf(mem_ctx, "%s \"%s\" ", + result, + value->v.multi_sz.strings[j]); + if (result == NULL) { + break; + } + } + break; + } + case REG_BINARY: + result = talloc_asprintf(mem_ctx, "binary (%d bytes)", + (int)value->v.binary.length); + break; + default: + result = talloc_asprintf(mem_ctx, ""); + break; + } + return result; +} + +/** + * Get the values of a key as a list of value names + * and a list of value strings (ordered) + */ +static WERROR libnet_conf_reg_get_values(TALLOC_CTX *mem_ctx, + struct registry_key *key, + uint32_t *num_values, + char ***value_names, + char ***value_strings) +{ + TALLOC_CTX *tmp_ctx = NULL; + WERROR werr = WERR_OK; + uint32_t count; + struct registry_value *valvalue = NULL; + char *valname = NULL; + char **tmp_valnames = NULL; + char **tmp_valstrings = NULL; + + if ((num_values == NULL) || (value_names == NULL) || + (value_strings == NULL)) + { + werr = WERR_INVALID_PARAM; + goto done; + } + + tmp_ctx = talloc_stackframe(); + if (tmp_ctx == NULL) { + werr = WERR_NOMEM; + goto done; + } + + for (count = 0; + W_ERROR_IS_OK(werr = reg_enumvalue(tmp_ctx, key, count, &valname, + &valvalue)); + count++) + { + char *valstring; + + werr = libnet_conf_add_string_to_array(tmp_ctx, + &tmp_valnames, + count, valname); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + valstring = libnet_conf_format_registry_value(tmp_ctx, + valvalue); + werr = libnet_conf_add_string_to_array(tmp_ctx, + &tmp_valstrings, + count, + valstring); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + goto done; + } + + werr = WERR_OK; + + *num_values = count; + if (count > 0) { + *value_names = talloc_move(mem_ctx, &tmp_valnames); + *value_strings = talloc_move(mem_ctx, &tmp_valstrings); + } else { + *value_names = NULL; + *value_strings = NULL; + } + +done: + TALLOC_FREE(tmp_ctx); + return werr; +} + +static int libnet_conf_destroy_ctx(struct libnet_conf_ctx *ctx) +{ + return regdb_close(); +} + +/********************************************************************** + * + * The actual net conf api functions, that are exported. + * + **********************************************************************/ + +/** + * Open the configuration. + * + * This should be the first function in a sequence of calls to libnet_conf + * functions: + * + * Upon success, this creates and returns the conf context + * that should be passed around in subsequent calls to the other + * libnet_conf functions. + * + * After the work with the configuration is completed, libnet_conf_close() + * should be called. + */ +WERROR libnet_conf_open(TALLOC_CTX *mem_ctx, struct libnet_conf_ctx **conf_ctx) +{ + WERROR werr = WERR_OK; + struct libnet_conf_ctx *ctx; + + if (conf_ctx == NULL) { + return WERR_INVALID_PARAM; + } + + ctx = TALLOC_ZERO_P(mem_ctx, struct libnet_conf_ctx); + if (ctx == NULL) { + return WERR_NOMEM; + } + + werr = libnet_conf_reg_initialize(ctx); + if (!W_ERROR_IS_OK(werr)) { + goto fail; + } + + talloc_set_destructor(ctx, libnet_conf_destroy_ctx); + + *conf_ctx = ctx; + return werr; + +fail: + TALLOC_FREE(ctx); + return werr; +} + +/** + * Close the configuration. + */ +void libnet_conf_close(struct libnet_conf_ctx *ctx) +{ + /* this also closes the registry (by destructor): */ + TALLOC_FREE(ctx); +} + +/** + * Get the change sequence number of the given service/parameter. + * + * NOTE: Currently, for registry configuration, this is independent + * of the service and parameter, it returns the registry-sequence + * number. + */ +uint64_t libnet_conf_get_seqnum(struct libnet_conf_ctx *ctx, + const char *service, const char *param) +{ + return (uint64_t)regdb_get_seqnum(); +} + +/** + * Drop the whole configuration (restarting empty). + */ +WERROR libnet_conf_drop(struct libnet_conf_ctx *ctx) +{ + char *path, *p; + WERROR werr = WERR_OK; + struct registry_key *parent_key = NULL; + struct registry_key *new_key = NULL; + TALLOC_CTX* mem_ctx = talloc_stackframe(); + enum winreg_CreateAction action; + + path = talloc_strdup(mem_ctx, KEY_SMBCONF); + if (path == NULL) { + werr = WERR_NOMEM; + goto done; + } + p = strrchr(path, '\\'); + *p = '\0'; + werr = libnet_conf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE, + &parent_key); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE, + &new_key, &action); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * Get the whole configuration as lists of strings with counts: + * + * num_shares : number of shares + * share_names : list of length num_shares of share names + * num_params : list of length num_shares of parameter counts for each share + * param_names : list of lists of parameter names for each share + * param_values : list of lists of parameter values for each share + */ +WERROR libnet_conf_get_config(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, uint32_t *num_shares, + char ***share_names, uint32_t **num_params, + char ****param_names, char ****param_values) +{ + WERROR werr = WERR_OK; + TALLOC_CTX *tmp_ctx = NULL; + uint32_t tmp_num_shares; + char **tmp_share_names; + uint32_t *tmp_num_params; + char ***tmp_param_names; + char ***tmp_param_values; + uint32_t count; + + if ((num_shares == NULL) || (share_names == NULL) || + (num_params == NULL) || (param_names == NULL) || + (param_values == NULL)) + { + werr = WERR_INVALID_PARAM; + goto done; + } + + tmp_ctx = talloc_stackframe(); + if (tmp_ctx == NULL) { + werr = WERR_NOMEM; + goto done; + } + + werr = libnet_conf_get_share_names(tmp_ctx, ctx, &tmp_num_shares, + &tmp_share_names); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + tmp_num_params = TALLOC_ARRAY(tmp_ctx, uint32_t, tmp_num_shares); + tmp_param_names = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares); + tmp_param_values = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares); + + if ((tmp_num_params == NULL) || (tmp_param_names == NULL) || + (tmp_param_values == NULL)) + { + werr = WERR_NOMEM; + goto done; + } + + for (count = 0; count < tmp_num_shares; count++) { + werr = libnet_conf_get_share(mem_ctx, ctx, + tmp_share_names[count], + &tmp_num_params[count], + &tmp_param_names[count], + &tmp_param_values[count]); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + + werr = WERR_OK; + + *num_shares = tmp_num_shares; + if (tmp_num_shares > 0) { + *share_names = talloc_move(mem_ctx, &tmp_share_names); + *num_params = talloc_move(mem_ctx, &tmp_num_params); + *param_names = talloc_move(mem_ctx, &tmp_param_names); + *param_values = talloc_move(mem_ctx, &tmp_param_values); + } else { + *share_names = NULL; + *num_params = NULL; + *param_names = NULL; + *param_values = NULL; + } + +done: + TALLOC_FREE(tmp_ctx); + return werr; +} + +/** + * get the list of share names defined in the configuration. + */ +WERROR libnet_conf_get_share_names(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + uint32_t *num_shares, + char ***share_names) +{ + uint32_t count; + uint32_t added_count = 0; + TALLOC_CTX *tmp_ctx = NULL; + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + char *subkey_name = NULL; + char **tmp_share_names = NULL; + + if ((num_shares == NULL) || (share_names == NULL)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + tmp_ctx = talloc_stackframe(); + if (tmp_ctx == NULL) { + werr = WERR_NOMEM; + goto done; + } + + /* make sure "global" is always listed first */ + if (libnet_conf_share_exists(ctx, GLOBAL_NAME)) { + werr = libnet_conf_add_string_to_array(tmp_ctx, + &tmp_share_names, + 0, GLOBAL_NAME); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + added_count++; + } + + werr = libnet_conf_reg_open_base_key(tmp_ctx, ctx, + SEC_RIGHTS_ENUM_SUBKEYS, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + for (count = 0; + W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count, + &subkey_name, NULL)); + count++) + { + if (strequal(subkey_name, GLOBAL_NAME)) { + continue; + } + + werr = libnet_conf_add_string_to_array(tmp_ctx, + &tmp_share_names, + added_count, + subkey_name); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + added_count++; + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + goto done; + } + werr = WERR_OK; + + *num_shares = added_count; + if (added_count > 0) { + *share_names = talloc_move(mem_ctx, &tmp_share_names); + } else { + *share_names = NULL; + } + +done: + TALLOC_FREE(tmp_ctx); + return werr; +} + +/** + * check if a share/service of a given name exists + */ +bool libnet_conf_share_exists(struct libnet_conf_ctx *ctx, + const char *servicename) +{ + bool ret = false; + WERROR werr = WERR_OK; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct registry_key *key = NULL; + + werr = libnet_conf_reg_open_service_key(mem_ctx, 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_conf_create_share(struct libnet_conf_ctx *ctx, + const char *servicename) +{ + WERROR werr; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct registry_key *key = NULL; + + if (libnet_conf_share_exists(ctx, servicename)) { + werr = WERR_ALREADY_EXISTS; + goto done; + } + + werr = libnet_conf_reg_create_service_key(mem_ctx, ctx, servicename, + &key); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * get a definition of a share (service) from configuration. + */ +WERROR libnet_conf_get_share(TALLOC_CTX *mem_ctx, struct libnet_conf_ctx *ctx, + const char *servicename, uint32_t *num_params, + char ***param_names, char ***param_values) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + + werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, servicename, + REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnet_conf_reg_get_values(mem_ctx, key, num_params, + param_names, param_values); + +done: + TALLOC_FREE(key); + return werr; +} + +/** + * delete a service from configuration + */ +WERROR libnet_conf_delete_share(struct libnet_conf_ctx *ctx, + const char *servicename) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + werr = libnet_conf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_deletekey_recursive(key, key, servicename); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * set a configuration parameter to the value provided. + */ +WERROR libnet_conf_set_parameter(struct libnet_conf_ctx *ctx, + const char *service, + const char *param, + const char *valstr) +{ + WERROR werr; + struct registry_key *key = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + if (!libnet_conf_share_exists(ctx, service)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } + + werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_WRITE, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnet_conf_reg_set_value(key, param, valstr); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * Set a global parameter + * (i.e. a parameter in the [global] service). + * + * This also creates [global] when it does not exist. + */ +WERROR libnet_conf_set_global_parameter(struct libnet_conf_ctx *ctx, + const char *param, const char *val) +{ + WERROR werr; + + if (!libnet_conf_share_exists(ctx, GLOBAL_NAME)) { + werr = libnet_conf_create_share(ctx, GLOBAL_NAME); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + werr = libnet_conf_set_parameter(ctx, GLOBAL_NAME, param, val); + +done: + return werr; +} + +/** + * get the value of a configuration parameter as a string + */ +WERROR libnet_conf_get_parameter(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + const char *service, + const char *param, + char **valstr) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + struct registry_value *value = NULL; + + if (valstr == NULL) { + werr = WERR_INVALID_PARAM; + goto done; + } + + if (!libnet_conf_share_exists(ctx, service)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } + + werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (!libnet_conf_value_exists(key, param)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + werr = reg_queryvalue(mem_ctx, key, param, &value); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + *valstr = libnet_conf_format_registry_value(mem_ctx, value); + + if (*valstr == NULL) { + werr = WERR_NOMEM; + } + +done: + TALLOC_FREE(key); + TALLOC_FREE(value); + return werr; +} + +/** + * Get the value of a global parameter. + * + * Create [global] if it does not exist. + */ +WERROR libnet_conf_get_global_parameter(TALLOC_CTX *mem_ctx, + struct libnet_conf_ctx *ctx, + const char *param, + char **valstr) +{ + WERROR werr; + + if (!libnet_conf_share_exists(ctx, GLOBAL_NAME)) { + werr = libnet_conf_create_share(ctx, GLOBAL_NAME); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + werr = libnet_conf_get_parameter(mem_ctx, ctx, GLOBAL_NAME, param, + valstr); + +done: + return werr; +} + +/** + * delete a parameter from configuration + */ +WERROR libnet_conf_delete_parameter(struct libnet_conf_ctx *ctx, + const char *service, const char *param) +{ + struct registry_key *key = NULL; + WERROR werr = WERR_OK; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + if (!libnet_conf_share_exists(ctx, service)) { + return WERR_NO_SUCH_SERVICE; + } + + werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_ALL, + &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (!libnet_conf_value_exists(key, param)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + werr = reg_deletevalue(key, param); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * Delete a global parameter. + * + * Create [global] if it does not exist. + */ +WERROR libnet_conf_delete_global_parameter(struct libnet_conf_ctx *ctx, + const char *param) +{ + WERROR werr; + + if (!libnet_conf_share_exists(ctx, GLOBAL_NAME)) { + werr = libnet_conf_create_share(ctx, GLOBAL_NAME); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + werr = libnet_conf_delete_parameter(ctx, GLOBAL_NAME, param); + +done: + return werr; +} -- cgit From 6274929b1e1ddf89f4c5e93414121eaf06b6ab14 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 17 Mar 2008 18:01:33 +0100 Subject: libsmbconf: rename all occurrences of libnet_conf_ to smbconf_ . Michael (This used to be commit 097af0309d7c3e9342058ba5266667293b23c80d) --- source3/lib/smbconf/smbconf.c | 295 ++++++++++++++++++++---------------------- 1 file changed, 142 insertions(+), 153 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 688097bc5e..4ccba09ef7 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "libnet/libnet.h" /********************************************************************** * @@ -31,10 +30,10 @@ /** * add a string to a talloced array of strings. */ -static WERROR libnet_conf_add_string_to_array(TALLOC_CTX *mem_ctx, - char ***array, - uint32_t count, - const char *string) +static WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, + char ***array, + uint32_t count, + const char *string) { char **new_array = NULL; @@ -58,7 +57,7 @@ static WERROR libnet_conf_add_string_to_array(TALLOC_CTX *mem_ctx, return WERR_OK; } -static WERROR libnet_conf_reg_initialize(struct libnet_conf_ctx *ctx) +static WERROR smbconf_reg_initialize(struct smbconf_ctx *ctx) { WERROR werr = WERR_OK; @@ -81,11 +80,11 @@ done: /** * Open a registry key specified by "path" */ -static WERROR libnet_conf_reg_open_path(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - const char *path, - uint32 desired_access, - struct registry_key **key) +static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + const char *path, + uint32 desired_access, + struct registry_key **key) { WERROR werr = WERR_OK; @@ -96,8 +95,8 @@ static WERROR libnet_conf_reg_open_path(TALLOC_CTX *mem_ctx, } if (ctx->token == NULL) { - DEBUG(1, ("Error: token missing from libnet_conf_ctx. " - "was libnet_conf_open() called?\n")); + DEBUG(1, ("Error: token missing from smbconf_ctx. " + "was smbconf_open() called?\n")); werr = WERR_INVALID_PARAM; goto done; } @@ -122,11 +121,11 @@ done: /** * Open a subkey of KEY_SMBCONF (i.e a service) */ -static WERROR libnet_conf_reg_open_service_key(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - const char *servicename, - uint32 desired_access, - struct registry_key **key) +static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + const char *servicename, + uint32 desired_access, + struct registry_key **key) { WERROR werr = WERR_OK; char *path = NULL; @@ -143,8 +142,7 @@ static WERROR libnet_conf_reg_open_service_key(TALLOC_CTX *mem_ctx, goto done; } - werr = libnet_conf_reg_open_path(mem_ctx, ctx, path, desired_access, - key); + werr = smbconf_reg_open_path(mem_ctx, ctx, path, desired_access, key); done: TALLOC_FREE(path); @@ -154,20 +152,19 @@ done: /** * open the base key KEY_SMBCONF */ -static WERROR libnet_conf_reg_open_base_key(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - uint32 desired_access, - struct registry_key **key) +static WERROR smbconf_reg_open_base_key(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + uint32 desired_access, + struct registry_key **key) { - return libnet_conf_reg_open_path(mem_ctx, ctx, KEY_SMBCONF, - desired_access, key); + return smbconf_reg_open_path(mem_ctx, ctx, KEY_SMBCONF, desired_access, + key); } /** * check if a value exists in a given registry key */ -static bool libnet_conf_value_exists(struct registry_key *key, - const char *param) +static bool smbconf_value_exists(struct registry_key *key, const char *param) { bool ret = false; WERROR werr = WERR_OK; @@ -186,10 +183,10 @@ static bool libnet_conf_value_exists(struct registry_key *key, /** * create a subkey of KEY_SMBCONF */ -static WERROR libnet_conf_reg_create_service_key(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - const char * subkeyname, - struct registry_key **newkey) +static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + const char * subkeyname, + struct registry_key **newkey) { WERROR werr = WERR_OK; struct registry_key *create_parent = NULL; @@ -204,8 +201,8 @@ static WERROR libnet_conf_reg_create_service_key(TALLOC_CTX *mem_ctx, goto done; } - werr = libnet_conf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE, - &create_parent); + werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE, + &create_parent); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -229,9 +226,9 @@ done: /** * add a value to a key. */ -static WERROR libnet_conf_reg_set_value(struct registry_key *key, - const char *valname, - const char *valstr) +static WERROR smbconf_reg_set_value(struct registry_key *key, + const char *valname, + const char *valstr) { struct registry_value val; WERROR werr = WERR_OK; @@ -303,8 +300,8 @@ done: * which are ar stored as REG_SZ values, so the incomplete * handling should be ok. */ -static char *libnet_conf_format_registry_value(TALLOC_CTX *mem_ctx, - struct registry_value *value) +static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx, + struct registry_value *value) { char *result = NULL; @@ -348,11 +345,11 @@ static char *libnet_conf_format_registry_value(TALLOC_CTX *mem_ctx, * Get the values of a key as a list of value names * and a list of value strings (ordered) */ -static WERROR libnet_conf_reg_get_values(TALLOC_CTX *mem_ctx, - struct registry_key *key, - uint32_t *num_values, - char ***value_names, - char ***value_strings) +static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx, + struct registry_key *key, + uint32_t *num_values, + char ***value_names, + char ***value_strings) { TALLOC_CTX *tmp_ctx = NULL; WERROR werr = WERR_OK; @@ -382,19 +379,16 @@ static WERROR libnet_conf_reg_get_values(TALLOC_CTX *mem_ctx, { char *valstring; - werr = libnet_conf_add_string_to_array(tmp_ctx, - &tmp_valnames, - count, valname); + werr = smbconf_add_string_to_array(tmp_ctx, + &tmp_valnames, + count, valname); if (!W_ERROR_IS_OK(werr)) { goto done; } - valstring = libnet_conf_format_registry_value(tmp_ctx, - valvalue); - werr = libnet_conf_add_string_to_array(tmp_ctx, - &tmp_valstrings, - count, - valstring); + valstring = smbconf_format_registry_value(tmp_ctx, valvalue); + werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings, + count, valstring); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -419,7 +413,7 @@ done: return werr; } -static int libnet_conf_destroy_ctx(struct libnet_conf_ctx *ctx) +static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) { return regdb_close(); } @@ -433,36 +427,36 @@ static int libnet_conf_destroy_ctx(struct libnet_conf_ctx *ctx) /** * Open the configuration. * - * This should be the first function in a sequence of calls to libnet_conf + * 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 - * libnet_conf functions. + * smbconf functions. * - * After the work with the configuration is completed, libnet_conf_close() + * After the work with the configuration is completed, smbconf_close() * should be called. */ -WERROR libnet_conf_open(TALLOC_CTX *mem_ctx, struct libnet_conf_ctx **conf_ctx) +WERROR smbconf_open(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) { WERROR werr = WERR_OK; - struct libnet_conf_ctx *ctx; + struct smbconf_ctx *ctx; if (conf_ctx == NULL) { return WERR_INVALID_PARAM; } - ctx = TALLOC_ZERO_P(mem_ctx, struct libnet_conf_ctx); + ctx = TALLOC_ZERO_P(mem_ctx, struct smbconf_ctx); if (ctx == NULL) { return WERR_NOMEM; } - werr = libnet_conf_reg_initialize(ctx); + werr = smbconf_reg_initialize(ctx); if (!W_ERROR_IS_OK(werr)) { goto fail; } - talloc_set_destructor(ctx, libnet_conf_destroy_ctx); + talloc_set_destructor(ctx, smbconf_destroy_ctx); *conf_ctx = ctx; return werr; @@ -475,7 +469,7 @@ fail: /** * Close the configuration. */ -void libnet_conf_close(struct libnet_conf_ctx *ctx) +void smbconf_close(struct smbconf_ctx *ctx) { /* this also closes the registry (by destructor): */ TALLOC_FREE(ctx); @@ -488,8 +482,8 @@ void libnet_conf_close(struct libnet_conf_ctx *ctx) * of the service and parameter, it returns the registry-sequence * number. */ -uint64_t libnet_conf_get_seqnum(struct libnet_conf_ctx *ctx, - const char *service, const char *param) +uint64_t smbconf_get_seqnum(struct smbconf_ctx *ctx, + const char *service, const char *param) { return (uint64_t)regdb_get_seqnum(); } @@ -497,7 +491,7 @@ uint64_t libnet_conf_get_seqnum(struct libnet_conf_ctx *ctx, /** * Drop the whole configuration (restarting empty). */ -WERROR libnet_conf_drop(struct libnet_conf_ctx *ctx) +WERROR smbconf_drop(struct smbconf_ctx *ctx) { char *path, *p; WERROR werr = WERR_OK; @@ -513,8 +507,8 @@ WERROR libnet_conf_drop(struct libnet_conf_ctx *ctx) } p = strrchr(path, '\\'); *p = '\0'; - werr = libnet_conf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE, - &parent_key); + werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE, + &parent_key); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -543,8 +537,8 @@ done: * param_names : list of lists of parameter names for each share * param_values : list of lists of parameter values for each share */ -WERROR libnet_conf_get_config(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, uint32_t *num_shares, +WERROR smbconf_get_config(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, uint32_t *num_shares, char ***share_names, uint32_t **num_params, char ****param_names, char ****param_values) { @@ -571,8 +565,8 @@ WERROR libnet_conf_get_config(TALLOC_CTX *mem_ctx, goto done; } - werr = libnet_conf_get_share_names(tmp_ctx, ctx, &tmp_num_shares, - &tmp_share_names); + werr = smbconf_get_share_names(tmp_ctx, ctx, &tmp_num_shares, + &tmp_share_names); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -589,11 +583,11 @@ WERROR libnet_conf_get_config(TALLOC_CTX *mem_ctx, } for (count = 0; count < tmp_num_shares; count++) { - werr = libnet_conf_get_share(mem_ctx, ctx, - tmp_share_names[count], - &tmp_num_params[count], - &tmp_param_names[count], - &tmp_param_values[count]); + werr = smbconf_get_share(mem_ctx, ctx, + tmp_share_names[count], + &tmp_num_params[count], + &tmp_param_names[count], + &tmp_param_values[count]); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -622,10 +616,10 @@ done: /** * get the list of share names defined in the configuration. */ -WERROR libnet_conf_get_share_names(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - uint32_t *num_shares, - char ***share_names) +WERROR smbconf_get_share_names(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + uint32_t *num_shares, + char ***share_names) { uint32_t count; uint32_t added_count = 0; @@ -647,18 +641,17 @@ WERROR libnet_conf_get_share_names(TALLOC_CTX *mem_ctx, } /* make sure "global" is always listed first */ - if (libnet_conf_share_exists(ctx, GLOBAL_NAME)) { - werr = libnet_conf_add_string_to_array(tmp_ctx, - &tmp_share_names, - 0, GLOBAL_NAME); + if (smbconf_share_exists(ctx, GLOBAL_NAME)) { + werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names, + 0, GLOBAL_NAME); if (!W_ERROR_IS_OK(werr)) { goto done; } added_count++; } - werr = libnet_conf_reg_open_base_key(tmp_ctx, ctx, - SEC_RIGHTS_ENUM_SUBKEYS, &key); + werr = smbconf_reg_open_base_key(tmp_ctx, ctx, + SEC_RIGHTS_ENUM_SUBKEYS, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -672,10 +665,10 @@ WERROR libnet_conf_get_share_names(TALLOC_CTX *mem_ctx, continue; } - werr = libnet_conf_add_string_to_array(tmp_ctx, - &tmp_share_names, - added_count, - subkey_name); + werr = smbconf_add_string_to_array(tmp_ctx, + &tmp_share_names, + added_count, + subkey_name); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -701,16 +694,16 @@ done: /** * check if a share/service of a given name exists */ -bool libnet_conf_share_exists(struct libnet_conf_ctx *ctx, - const char *servicename) +bool smbconf_share_exists(struct smbconf_ctx *ctx, + const char *servicename) { bool ret = false; WERROR werr = WERR_OK; TALLOC_CTX *mem_ctx = talloc_stackframe(); struct registry_key *key = NULL; - werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, servicename, - REG_KEY_READ, &key); + werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename, + REG_KEY_READ, &key); if (W_ERROR_IS_OK(werr)) { ret = true; } @@ -722,20 +715,19 @@ bool libnet_conf_share_exists(struct libnet_conf_ctx *ctx, /** * Add a service if it does not already exist. */ -WERROR libnet_conf_create_share(struct libnet_conf_ctx *ctx, - const char *servicename) +WERROR smbconf_create_share(struct smbconf_ctx *ctx, + const char *servicename) { WERROR werr; TALLOC_CTX *mem_ctx = talloc_stackframe(); struct registry_key *key = NULL; - if (libnet_conf_share_exists(ctx, servicename)) { + if (smbconf_share_exists(ctx, servicename)) { werr = WERR_ALREADY_EXISTS; goto done; } - werr = libnet_conf_reg_create_service_key(mem_ctx, ctx, servicename, - &key); + werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key); done: TALLOC_FREE(mem_ctx); @@ -745,21 +737,21 @@ done: /** * get a definition of a share (service) from configuration. */ -WERROR libnet_conf_get_share(TALLOC_CTX *mem_ctx, struct libnet_conf_ctx *ctx, - const char *servicename, uint32_t *num_params, - char ***param_names, char ***param_values) +WERROR smbconf_get_share(TALLOC_CTX *mem_ctx, struct smbconf_ctx *ctx, + const char *servicename, uint32_t *num_params, + char ***param_names, char ***param_values) { WERROR werr = WERR_OK; struct registry_key *key = NULL; - werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, servicename, - REG_KEY_READ, &key); + werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename, + REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnet_conf_reg_get_values(mem_ctx, key, num_params, - param_names, param_values); + werr = smbconf_reg_get_values(mem_ctx, key, num_params, + param_names, param_values); done: TALLOC_FREE(key); @@ -769,14 +761,13 @@ done: /** * delete a service from configuration */ -WERROR libnet_conf_delete_share(struct libnet_conf_ctx *ctx, - const char *servicename) +WERROR smbconf_delete_share(struct smbconf_ctx *ctx, const char *servicename) { WERROR werr = WERR_OK; struct registry_key *key = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); - werr = libnet_conf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key); + werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -791,27 +782,27 @@ done: /** * set a configuration parameter to the value provided. */ -WERROR libnet_conf_set_parameter(struct libnet_conf_ctx *ctx, - const char *service, - const char *param, - const char *valstr) +WERROR smbconf_set_parameter(struct smbconf_ctx *ctx, + const char *service, + const char *param, + const char *valstr) { WERROR werr; struct registry_key *key = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (!libnet_conf_share_exists(ctx, service)) { + if (!smbconf_share_exists(ctx, service)) { werr = WERR_NO_SUCH_SERVICE; goto done; } - werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_WRITE, &key); + werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_WRITE, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnet_conf_reg_set_value(key, param, valstr); + werr = smbconf_reg_set_value(key, param, valstr); done: TALLOC_FREE(mem_ctx); @@ -824,18 +815,18 @@ done: * * This also creates [global] when it does not exist. */ -WERROR libnet_conf_set_global_parameter(struct libnet_conf_ctx *ctx, - const char *param, const char *val) +WERROR smbconf_set_global_parameter(struct smbconf_ctx *ctx, + const char *param, const char *val) { WERROR werr; - if (!libnet_conf_share_exists(ctx, GLOBAL_NAME)) { - werr = libnet_conf_create_share(ctx, GLOBAL_NAME); + if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { + werr = smbconf_create_share(ctx, GLOBAL_NAME); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = libnet_conf_set_parameter(ctx, GLOBAL_NAME, param, val); + werr = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val); done: return werr; @@ -844,11 +835,11 @@ done: /** * get the value of a configuration parameter as a string */ -WERROR libnet_conf_get_parameter(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - const char *service, - const char *param, - char **valstr) +WERROR smbconf_get_parameter(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + const char *service, + const char *param, + char **valstr) { WERROR werr = WERR_OK; struct registry_key *key = NULL; @@ -859,18 +850,18 @@ WERROR libnet_conf_get_parameter(TALLOC_CTX *mem_ctx, goto done; } - if (!libnet_conf_share_exists(ctx, service)) { + if (!smbconf_share_exists(ctx, service)) { werr = WERR_NO_SUCH_SERVICE; goto done; } - werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_READ, &key); + werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } - if (!libnet_conf_value_exists(key, param)) { + if (!smbconf_value_exists(key, param)) { werr = WERR_INVALID_PARAM; goto done; } @@ -880,7 +871,7 @@ WERROR libnet_conf_get_parameter(TALLOC_CTX *mem_ctx, goto done; } - *valstr = libnet_conf_format_registry_value(mem_ctx, value); + *valstr = smbconf_format_registry_value(mem_ctx, value); if (*valstr == NULL) { werr = WERR_NOMEM; @@ -897,21 +888,20 @@ done: * * Create [global] if it does not exist. */ -WERROR libnet_conf_get_global_parameter(TALLOC_CTX *mem_ctx, - struct libnet_conf_ctx *ctx, - const char *param, - char **valstr) +WERROR smbconf_get_global_parameter(TALLOC_CTX *mem_ctx, + struct smbconf_ctx *ctx, + const char *param, + char **valstr) { WERROR werr; - if (!libnet_conf_share_exists(ctx, GLOBAL_NAME)) { - werr = libnet_conf_create_share(ctx, GLOBAL_NAME); + if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { + werr = smbconf_create_share(ctx, GLOBAL_NAME); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = libnet_conf_get_parameter(mem_ctx, ctx, GLOBAL_NAME, param, - valstr); + werr = smbconf_get_parameter(mem_ctx, ctx, GLOBAL_NAME, param, valstr); done: return werr; @@ -920,25 +910,24 @@ done: /** * delete a parameter from configuration */ -WERROR libnet_conf_delete_parameter(struct libnet_conf_ctx *ctx, - const char *service, const char *param) +WERROR smbconf_delete_parameter(struct smbconf_ctx *ctx, + const char *service, const char *param) { struct registry_key *key = NULL; WERROR werr = WERR_OK; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (!libnet_conf_share_exists(ctx, service)) { + if (!smbconf_share_exists(ctx, service)) { return WERR_NO_SUCH_SERVICE; } - werr = libnet_conf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_ALL, - &key); + werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_ALL, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } - if (!libnet_conf_value_exists(key, param)) { + if (!smbconf_value_exists(key, param)) { werr = WERR_INVALID_PARAM; goto done; } @@ -955,18 +944,18 @@ done: * * Create [global] if it does not exist. */ -WERROR libnet_conf_delete_global_parameter(struct libnet_conf_ctx *ctx, - const char *param) +WERROR smbconf_delete_global_parameter(struct smbconf_ctx *ctx, + const char *param) { WERROR werr; - if (!libnet_conf_share_exists(ctx, GLOBAL_NAME)) { - werr = libnet_conf_create_share(ctx, GLOBAL_NAME); + if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { + werr = smbconf_create_share(ctx, GLOBAL_NAME); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = libnet_conf_delete_parameter(ctx, GLOBAL_NAME, param); + werr = smbconf_delete_parameter(ctx, GLOBAL_NAME, param); done: return werr; -- cgit From 77dd53ad5c2568a2f06d4ecd524c971ae967b17b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 18 Mar 2008 00:51:15 +0100 Subject: libsmbconf: fix a comment Michael (This used to be commit e6b60f6cad32ce8bb78abb070889dde3eca2d268) --- source3/lib/smbconf/smbconf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 4ccba09ef7..dc45a16c48 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -23,8 +23,7 @@ /********************************************************************** * * Helper functions (mostly registry related) - * TODO: These should be eventually static. - + * **********************************************************************/ /** -- cgit From 7621b4c3d80f411aac6e40ea5cce787cec108af5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 18 Mar 2008 23:29:11 +0100 Subject: libsmbconf: change smbconf_get_seqnum() to smbconf_changed(). The former seqnum is hidden inside a struct smbconf_csn. And the get_seqnum is united with a changed function that stores the seqnum inside the given csn. Michael (This used to be commit 5b6b90900a1a3eab24cb5612d78f9678a363cf73) --- source3/lib/smbconf/smbconf.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index dc45a16c48..454056167e 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -417,6 +417,20 @@ static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) return regdb_close(); } +/** + * Get the change sequence number of the given service/parameter. + * service and parameter strings may be NULL. + */ +static void smbconf_reg_get_csn(struct smbconf_ctx *ctx, + struct smbconf_csn *csn, + const char *service, const char *param) +{ + if (csn == NULL) { + return; + } + csn->csn = (uint64_t)regdb_get_seqnum(); +} + /********************************************************************** * * The actual net conf api functions, that are exported. @@ -475,16 +489,24 @@ void smbconf_close(struct smbconf_ctx *ctx) } /** - * Get the change sequence number of the given service/parameter. - * - * NOTE: Currently, for registry configuration, this is independent - * of the service and parameter, it returns the registry-sequence - * number. + * Detect changes in the configuration. + * The given csn struct is filled with the current csn. + * smbconf_changed() can also be used for initial retrieval + * of the csn. */ -uint64_t smbconf_get_seqnum(struct smbconf_ctx *ctx, - const char *service, const char *param) +bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn, + const char *service, const char *param) { - return (uint64_t)regdb_get_seqnum(); + struct smbconf_csn old_csn; + + if (csn == NULL) { + return false; + } + + old_csn = *csn; + + smbconf_reg_get_csn(ctx, csn, service, param); + return (csn->csn != old_csn.csn); } /** -- cgit From fc730cac358e9077da6440a36da35c12d1486032 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 19 Mar 2008 10:15:16 +0100 Subject: libsmbconf: fix indentation. Michael (This used to be commit 7460697ea42764f5f658a4f7f70872a56aeb160d) --- source3/lib/smbconf/smbconf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 454056167e..549fdc5285 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -559,9 +559,9 @@ done: * param_values : list of lists of parameter values for each share */ WERROR smbconf_get_config(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, uint32_t *num_shares, - char ***share_names, uint32_t **num_params, - char ****param_names, char ****param_values) + struct smbconf_ctx *ctx, uint32_t *num_shares, + char ***share_names, uint32_t **num_params, + char ****param_names, char ****param_values) { WERROR werr = WERR_OK; TALLOC_CTX *tmp_ctx = NULL; -- cgit From 153ed797e61db7feef32af0d256818e66460d064 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 19 Mar 2008 10:47:23 +0100 Subject: libsmbconf: change the API to always take the smbconf_ctx parameter first. ..for consistency. Exception: the open/init function, where the smbconf_ctx is created from the given talloc context. Michael (This used to be commit 304dba6cb2184437f3edad065a530d03fb704036) --- source3/lib/smbconf/smbconf.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 549fdc5285..804b1b8c28 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -558,8 +558,9 @@ done: * param_names : list of lists of parameter names for each share * param_values : list of lists of parameter values for each share */ -WERROR smbconf_get_config(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, uint32_t *num_shares, +WERROR smbconf_get_config(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, + uint32_t *num_shares, char ***share_names, uint32_t **num_params, char ****param_names, char ****param_values) { @@ -586,7 +587,7 @@ WERROR smbconf_get_config(TALLOC_CTX *mem_ctx, goto done; } - werr = smbconf_get_share_names(tmp_ctx, ctx, &tmp_num_shares, + werr = smbconf_get_share_names(ctx, tmp_ctx, &tmp_num_shares, &tmp_share_names); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -604,7 +605,7 @@ WERROR smbconf_get_config(TALLOC_CTX *mem_ctx, } for (count = 0; count < tmp_num_shares; count++) { - werr = smbconf_get_share(mem_ctx, ctx, + werr = smbconf_get_share(ctx, mem_ctx, tmp_share_names[count], &tmp_num_params[count], &tmp_param_names[count], @@ -637,8 +638,8 @@ done: /** * get the list of share names defined in the configuration. */ -WERROR smbconf_get_share_names(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, +WERROR smbconf_get_share_names(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, uint32_t *num_shares, char ***share_names) { @@ -758,7 +759,8 @@ done: /** * get a definition of a share (service) from configuration. */ -WERROR smbconf_get_share(TALLOC_CTX *mem_ctx, struct smbconf_ctx *ctx, +WERROR smbconf_get_share(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, const char *servicename, uint32_t *num_params, char ***param_names, char ***param_values) { @@ -856,8 +858,8 @@ done: /** * get the value of a configuration parameter as a string */ -WERROR smbconf_get_parameter(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, +WERROR smbconf_get_parameter(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, const char *service, const char *param, char **valstr) @@ -909,8 +911,8 @@ done: * * Create [global] if it does not exist. */ -WERROR smbconf_get_global_parameter(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, +WERROR smbconf_get_global_parameter(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, const char *param, char **valstr) { @@ -922,7 +924,7 @@ WERROR smbconf_get_global_parameter(TALLOC_CTX *mem_ctx, goto done; } } - werr = smbconf_get_parameter(mem_ctx, ctx, GLOBAL_NAME, param, valstr); + werr = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param, valstr); done: return werr; -- cgit From 7b53c84fe1c8ec0cb5e1d7a977eca6197a4c36c6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 19 Mar 2008 12:37:17 +0100 Subject: libsmbconf: put the smbconf context struct into a private header. Michael (This used to be commit a99ee5e536eee1563c90e5d7f251bfe9f5d1ffbb) --- source3/lib/smbconf/smbconf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 804b1b8c28..a5059c9eb5 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "smbconf_private.h" /********************************************************************** * -- cgit From 1e8d72aec9411c99cd88ba48c169d7c7f4187db6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 10:43:17 +0100 Subject: libsmbconf: refactor autocreation of [global] into a helper function. Michael (This used to be commit aeaf66c064de58c6f19d5a9d226843dedb552011) --- source3/lib/smbconf/smbconf.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index a5059c9eb5..dd044eef81 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -432,6 +432,14 @@ static void smbconf_reg_get_csn(struct smbconf_ctx *ctx, csn->csn = (uint64_t)regdb_get_seqnum(); } +static WERROR smbconf_global_check(struct smbconf_ctx *ctx) +{ + if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { + return smbconf_create_share(ctx, GLOBAL_NAME); + } + return WERR_OK; +} + /********************************************************************** * * The actual net conf api functions, that are exported. @@ -844,15 +852,11 @@ WERROR smbconf_set_global_parameter(struct smbconf_ctx *ctx, { WERROR werr; - if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { - werr = smbconf_create_share(ctx, GLOBAL_NAME); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } + werr = smbconf_global_check(ctx); + if (W_ERROR_IS_OK(werr)) { + werr = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val); } - werr = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val); -done: return werr; } @@ -919,15 +923,12 @@ WERROR smbconf_get_global_parameter(struct smbconf_ctx *ctx, { WERROR werr; - if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { - werr = smbconf_create_share(ctx, GLOBAL_NAME); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } + werr = smbconf_global_check(ctx); + if (W_ERROR_IS_OK(werr)) { + werr = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param, + valstr); } - werr = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param, valstr); -done: return werr; } @@ -973,14 +974,10 @@ WERROR smbconf_delete_global_parameter(struct smbconf_ctx *ctx, { WERROR werr; - if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { - werr = smbconf_create_share(ctx, GLOBAL_NAME); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } + werr = smbconf_global_check(ctx); + if (W_ERROR_IS_OK(werr)) { + werr = smbconf_delete_parameter(ctx, GLOBAL_NAME, param); } - werr = smbconf_delete_parameter(ctx, GLOBAL_NAME, param); -done: return werr; } -- cgit From 73f8c1c68ca4009da6a27c563c002c2c352135a3 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 11:49:26 +0100 Subject: libsmbconf: refactor out registry implementation of smbconf operations. This leaves most of the api functions mere wrappers except for some common initial checks. Michael (This used to be commit 9448a7a298e9ed035aa6b86df18f2d41081731cc) --- source3/lib/smbconf/smbconf.c | 555 +++++++++++++++++++++++++----------------- 1 file changed, 326 insertions(+), 229 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index dd044eef81..b47ce198e7 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -418,6 +418,21 @@ static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) return regdb_close(); } +static WERROR smbconf_global_check(struct smbconf_ctx *ctx) +{ + if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { + return smbconf_create_share(ctx, GLOBAL_NAME); + } + return WERR_OK; +} + + +/********************************************************************** + * + * smbconf operations: registry implementations + * + **********************************************************************/ + /** * Get the change sequence number of the given service/parameter. * service and parameter strings may be NULL. @@ -432,14 +447,306 @@ static void smbconf_reg_get_csn(struct smbconf_ctx *ctx, csn->csn = (uint64_t)regdb_get_seqnum(); } -static WERROR smbconf_global_check(struct smbconf_ctx *ctx) +/** + * Drop the whole configuration (restarting empty) - registry version + */ +static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx) { - if (!smbconf_share_exists(ctx, GLOBAL_NAME)) { - return smbconf_create_share(ctx, GLOBAL_NAME); + char *path, *p; + WERROR werr = WERR_OK; + struct registry_key *parent_key = NULL; + struct registry_key *new_key = NULL; + TALLOC_CTX* mem_ctx = talloc_stackframe(); + enum winreg_CreateAction action; + + path = talloc_strdup(mem_ctx, KEY_SMBCONF); + if (path == NULL) { + werr = WERR_NOMEM; + goto done; } - return WERR_OK; + p = strrchr(path, '\\'); + *p = '\0'; + werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE, + &parent_key); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE, + &new_key, &action); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * get the list of share names defined in the configuration. + * registry version. + */ +static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, + uint32_t *num_shares, + char ***share_names) +{ + uint32_t count; + uint32_t added_count = 0; + TALLOC_CTX *tmp_ctx = NULL; + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + char *subkey_name = NULL; + char **tmp_share_names = NULL; + + if ((num_shares == NULL) || (share_names == NULL)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + tmp_ctx = talloc_stackframe(); + if (tmp_ctx == NULL) { + werr = WERR_NOMEM; + 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, + 0, GLOBAL_NAME); + 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; + } + + for (count = 0; + W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count, + &subkey_name, NULL)); + count++) + { + if (strequal(subkey_name, GLOBAL_NAME)) { + continue; + } + + werr = smbconf_add_string_to_array(tmp_ctx, + &tmp_share_names, + added_count, + subkey_name); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + added_count++; + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + goto done; + } + werr = WERR_OK; + + *num_shares = added_count; + if (added_count > 0) { + *share_names = talloc_move(mem_ctx, &tmp_share_names); + } else { + *share_names = NULL; + } + +done: + TALLOC_FREE(tmp_ctx); + return werr; } +/** + * check if a share/service of a given name exists - registry version + */ +static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx, + const char *servicename) +{ + bool ret = false; + WERROR werr = WERR_OK; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct registry_key *key = NULL; + + werr = smbconf_reg_open_service_key(mem_ctx, 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 - registry version + */ +static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx, + const char *servicename) +{ + WERROR werr; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct registry_key *key = NULL; + + werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key); + + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * get a definition of a share (service) from configuration. + */ +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) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + + werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename, + REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = smbconf_reg_get_values(mem_ctx, key, num_params, + param_names, param_values); + +done: + TALLOC_FREE(key); + return werr; +} + +/** + * delete a service from configuration + */ +static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx, + const char *servicename) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_deletekey_recursive(key, key, servicename); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * set a configuration parameter to the value provided. + */ +static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx, + const char *service, + const char *param, + const char *valstr) +{ + WERROR werr; + struct registry_key *key = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_WRITE, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = smbconf_reg_set_value(key, param, valstr); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + +/** + * get the value of a configuration parameter as a string + */ +static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, + const char *service, + const char *param, + char **valstr) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + struct registry_value *value = NULL; + + werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (!smbconf_value_exists(key, param)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + werr = reg_queryvalue(mem_ctx, key, param, &value); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + *valstr = smbconf_format_registry_value(mem_ctx, value); + + if (*valstr == NULL) { + werr = WERR_NOMEM; + } + +done: + TALLOC_FREE(key); + TALLOC_FREE(value); + return werr; +} + +/** + * delete a parameter from configuration + */ +static WERROR smbconf_reg_delete_parameter(struct smbconf_ctx *ctx, + const char *service, + const char *param) +{ + struct registry_key *key = NULL; + WERROR werr = WERR_OK; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, + REG_KEY_ALL, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (!smbconf_value_exists(key, param)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + werr = reg_deletevalue(key, param); + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + + /********************************************************************** * * The actual net conf api functions, that are exported. @@ -523,39 +830,7 @@ bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn, */ WERROR smbconf_drop(struct smbconf_ctx *ctx) { - char *path, *p; - WERROR werr = WERR_OK; - struct registry_key *parent_key = NULL; - struct registry_key *new_key = NULL; - TALLOC_CTX* mem_ctx = talloc_stackframe(); - enum winreg_CreateAction action; - - path = talloc_strdup(mem_ctx, KEY_SMBCONF); - if (path == NULL) { - werr = WERR_NOMEM; - goto done; - } - p = strrchr(path, '\\'); - *p = '\0'; - werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE, - &parent_key); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE, - &new_key, &action); - -done: - TALLOC_FREE(mem_ctx); - return werr; + return smbconf_reg_drop(ctx); } /** @@ -652,74 +927,8 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx, uint32_t *num_shares, char ***share_names) { - uint32_t count; - uint32_t added_count = 0; - TALLOC_CTX *tmp_ctx = NULL; - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - char *subkey_name = NULL; - char **tmp_share_names = NULL; - - if ((num_shares == NULL) || (share_names == NULL)) { - werr = WERR_INVALID_PARAM; - goto done; - } - - tmp_ctx = talloc_stackframe(); - if (tmp_ctx == NULL) { - werr = WERR_NOMEM; - 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, - 0, GLOBAL_NAME); - 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; - } - - for (count = 0; - W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count, - &subkey_name, NULL)); - count++) - { - if (strequal(subkey_name, GLOBAL_NAME)) { - continue; - } - - werr = smbconf_add_string_to_array(tmp_ctx, - &tmp_share_names, - added_count, - subkey_name); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - added_count++; - } - if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - goto done; - } - werr = WERR_OK; - - *num_shares = added_count; - if (added_count > 0) { - *share_names = talloc_move(mem_ctx, &tmp_share_names); - } else { - *share_names = NULL; - } - -done: - TALLOC_FREE(tmp_ctx); - return werr; + return smbconf_reg_get_share_names(ctx, mem_ctx, num_shares, + share_names); } /** @@ -728,19 +937,7 @@ done: bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename) { - bool ret = false; - WERROR werr = WERR_OK; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - struct registry_key *key = NULL; - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename, - REG_KEY_READ, &key); - if (W_ERROR_IS_OK(werr)) { - ret = true; - } - - TALLOC_FREE(mem_ctx); - return ret; + return smbconf_reg_share_exists(ctx, servicename); } /** @@ -749,20 +946,11 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, WERROR smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename) { - WERROR werr; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - struct registry_key *key = NULL; - if (smbconf_share_exists(ctx, servicename)) { - werr = WERR_ALREADY_EXISTS; - goto done; + return WERR_ALREADY_EXISTS; } - werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key); - -done: - TALLOC_FREE(mem_ctx); - return werr; + return smbconf_reg_create_share(ctx, servicename); } /** @@ -773,21 +961,8 @@ WERROR smbconf_get_share(struct smbconf_ctx *ctx, const char *servicename, uint32_t *num_params, char ***param_names, char ***param_values) { - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename, - REG_KEY_READ, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = smbconf_reg_get_values(mem_ctx, key, num_params, - param_names, param_values); - -done: - TALLOC_FREE(key); - return werr; + return smbconf_reg_get_share(ctx, mem_ctx, servicename, num_params, + param_names, param_values); } /** @@ -795,20 +970,7 @@ done: */ WERROR smbconf_delete_share(struct smbconf_ctx *ctx, const char *servicename) { - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - - werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_deletekey_recursive(key, key, servicename); - -done: - TALLOC_FREE(mem_ctx); - return werr; + return smbconf_reg_delete_share(ctx, servicename); } /** @@ -819,26 +981,11 @@ WERROR smbconf_set_parameter(struct smbconf_ctx *ctx, const char *param, const char *valstr) { - WERROR werr; - struct registry_key *key = NULL; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (!smbconf_share_exists(ctx, service)) { - werr = WERR_NO_SUCH_SERVICE; - goto done; - } - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_WRITE, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; + return WERR_NO_SUCH_SERVICE; } - werr = smbconf_reg_set_value(key, param, valstr); - -done: - TALLOC_FREE(mem_ctx); - return werr; + return smbconf_reg_set_parameter(ctx, service, param, valstr); } /** @@ -869,46 +1016,15 @@ WERROR smbconf_get_parameter(struct smbconf_ctx *ctx, const char *param, char **valstr) { - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - struct registry_value *value = NULL; - if (valstr == NULL) { - werr = WERR_INVALID_PARAM; - goto done; + return WERR_INVALID_PARAM; } if (!smbconf_share_exists(ctx, service)) { - werr = WERR_NO_SUCH_SERVICE; - goto done; - } - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_READ, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - if (!smbconf_value_exists(key, param)) { - werr = WERR_INVALID_PARAM; - goto done; - } - - werr = reg_queryvalue(mem_ctx, key, param, &value); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - *valstr = smbconf_format_registry_value(mem_ctx, value); - - if (*valstr == NULL) { - werr = WERR_NOMEM; + return WERR_NO_SUCH_SERVICE; } -done: - TALLOC_FREE(key); - TALLOC_FREE(value); - return werr; + return smbconf_reg_get_parameter(ctx, mem_ctx, service, param, valstr); } /** @@ -938,30 +1054,11 @@ WERROR smbconf_get_global_parameter(struct smbconf_ctx *ctx, WERROR smbconf_delete_parameter(struct smbconf_ctx *ctx, const char *service, const char *param) { - struct registry_key *key = NULL; - WERROR werr = WERR_OK; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (!smbconf_share_exists(ctx, service)) { return WERR_NO_SUCH_SERVICE; } - werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_ALL, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - if (!smbconf_value_exists(key, param)) { - werr = WERR_INVALID_PARAM; - goto done; - } - - werr = reg_deletevalue(key, param); - -done: - TALLOC_FREE(mem_ctx); - return werr; + return smbconf_reg_delete_parameter(ctx, service, param); } /** -- cgit From 4c7214aae2354b737ceadc255ebff7643036cc17 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 11:50:06 +0100 Subject: libsmbconf: fix a comment (This used to be commit 103a37ac8e85e9a7b8c2f4eb33e6f1cdbe01d31c) --- source3/lib/smbconf/smbconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index b47ce198e7..a6b986bc4d 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -749,7 +749,7 @@ done: /********************************************************************** * - * The actual net conf api functions, that are exported. + * The actual libsmbconf API functions that are exported. * **********************************************************************/ -- cgit From fbd2c552eaf88604bf91899355c024fc5a4d95b6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 11:52:13 +0100 Subject: libsmbconf: add check for NULL servicename to smbconf_share_exists(). Michael (This used to be commit 5dac66c82af8c87df723092a9309304846684418) --- source3/lib/smbconf/smbconf.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index a6b986bc4d..d1351843f0 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -937,6 +937,9 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx, bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename) { + if (servicename == NULL) { + return false; + } return smbconf_reg_share_exists(ctx, servicename); } -- cgit From 94ef9248001ed0e0690e5463eff66e41f30f6c10 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 11:53:40 +0100 Subject: libsmbconf: add existence check for service to smbconf_get_share(). Michael (This used to be commit 26208d3e96a1e257628366709a1d71ac36f0788b) --- source3/lib/smbconf/smbconf.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index d1351843f0..7edefa40d4 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -964,6 +964,10 @@ WERROR smbconf_get_share(struct smbconf_ctx *ctx, const char *servicename, uint32_t *num_params, char ***param_names, char ***param_values) { + if (!smbconf_share_exists(ctx, servicename)) { + return WERR_NO_SUCH_SERVICE; + } + return smbconf_reg_get_share(ctx, mem_ctx, servicename, num_params, param_names, param_values); } -- cgit From d19e308a146e10f1673a7e6fc36e5303b9d02ac7 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 11:54:30 +0100 Subject: libsmbconf: add existence check for service to smbconf_delete_share(). Michael (This used to be commit d44c2ef0b7d7bddb4115b596872748132ebd6ddc) --- source3/lib/smbconf/smbconf.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 7edefa40d4..bd3d551d69 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -977,6 +977,10 @@ WERROR smbconf_get_share(struct smbconf_ctx *ctx, */ WERROR smbconf_delete_share(struct smbconf_ctx *ctx, const char *servicename) { + if (!smbconf_share_exists(ctx, servicename)) { + return WERR_NO_SUCH_SERVICE; + } + return smbconf_reg_delete_share(ctx, servicename); } -- cgit From f12b10566df44df3c86b59c0cff80b52534558b3 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 12:25:44 +0100 Subject: libsmbconf: move smbconf_reg_initialize() down to the smbconf operations. Michael (This used to be commit f2d605006cd1187f70a044c3356d436e91093d5f) --- source3/lib/smbconf/smbconf.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index bd3d551d69..ba20316b57 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -57,26 +57,6 @@ static WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, return WERR_OK; } -static WERROR smbconf_reg_initialize(struct smbconf_ctx *ctx) -{ - WERROR werr = WERR_OK; - - if (!registry_init_smbconf()) { - werr = WERR_REG_IO_FAILURE; - goto done; - } - - werr = ntstatus_to_werror(registry_create_admin_token(ctx, - &(ctx->token))); - if (!W_ERROR_IS_OK(werr)) { - DEBUG(1, ("Error creating admin token\n")); - goto done; - } - -done: - return werr; -} - /** * Open a registry key specified by "path" */ @@ -433,6 +413,26 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx) * **********************************************************************/ +static WERROR smbconf_reg_initialize(struct smbconf_ctx *ctx) +{ + WERROR werr = WERR_OK; + + if (!registry_init_smbconf()) { + werr = WERR_REG_IO_FAILURE; + goto done; + } + + werr = ntstatus_to_werror(registry_create_admin_token(ctx, + &(ctx->token))); + if (!W_ERROR_IS_OK(werr)) { + DEBUG(1, ("Error creating admin token\n")); + goto done; + } + +done: + return werr; +} + /** * Get the change sequence number of the given service/parameter. * service and parameter strings may be NULL. -- cgit From 2135f7dd61ea46b539fefc9af3d0212a9281edcd Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 12:28:41 +0100 Subject: libsmbconf: introduce a smbconf_ops layer to allow interchangeable backends. Michael (This used to be commit a857f643d1558c0fdab4b647695d75223b730b96) --- source3/lib/smbconf/smbconf.c | 47 ++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index ba20316b57..a9e895a168 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -413,7 +413,10 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx) * **********************************************************************/ -static WERROR smbconf_reg_initialize(struct smbconf_ctx *ctx) +/** + * initialize the registry smbconf backend + */ +static WERROR smbconf_reg_init(struct smbconf_ctx *ctx) { WERROR werr = WERR_OK; @@ -746,6 +749,20 @@ done: return werr; } +struct smbconf_ops smbconf_ops_reg = { + .init = smbconf_reg_init, + .get_csn = smbconf_reg_get_csn, + .drop = smbconf_reg_drop, + .get_share_names = smbconf_reg_get_share_names, + .share_exists = smbconf_reg_share_exists, + .create_share = smbconf_reg_create_share, + .get_share = smbconf_reg_get_share, + .delete_share = smbconf_reg_delete_share, + .set_parameter = smbconf_reg_set_parameter, + .get_parameter = smbconf_reg_get_parameter, + .delete_parameter = smbconf_reg_delete_parameter +}; + /********************************************************************** * @@ -780,7 +797,9 @@ WERROR smbconf_open(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) return WERR_NOMEM; } - werr = smbconf_reg_initialize(ctx); + ctx->ops = &smbconf_ops_reg; + + werr = ctx->ops->init(ctx); if (!W_ERROR_IS_OK(werr)) { goto fail; } @@ -821,7 +840,7 @@ bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn, old_csn = *csn; - smbconf_reg_get_csn(ctx, csn, service, param); + ctx->ops->get_csn(ctx, csn, service, param); return (csn->csn != old_csn.csn); } @@ -830,7 +849,7 @@ bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn, */ WERROR smbconf_drop(struct smbconf_ctx *ctx) { - return smbconf_reg_drop(ctx); + return ctx->ops->drop(ctx); } /** @@ -927,8 +946,8 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx, uint32_t *num_shares, char ***share_names) { - return smbconf_reg_get_share_names(ctx, mem_ctx, num_shares, - share_names); + return ctx->ops->get_share_names(ctx, mem_ctx, num_shares, + share_names); } /** @@ -940,7 +959,7 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, if (servicename == NULL) { return false; } - return smbconf_reg_share_exists(ctx, servicename); + return ctx->ops->share_exists(ctx, servicename); } /** @@ -953,7 +972,7 @@ WERROR smbconf_create_share(struct smbconf_ctx *ctx, return WERR_ALREADY_EXISTS; } - return smbconf_reg_create_share(ctx, servicename); + return ctx->ops->create_share(ctx, servicename); } /** @@ -968,8 +987,8 @@ WERROR smbconf_get_share(struct smbconf_ctx *ctx, return WERR_NO_SUCH_SERVICE; } - return smbconf_reg_get_share(ctx, mem_ctx, servicename, num_params, - param_names, param_values); + return ctx->ops->get_share(ctx, mem_ctx, servicename, num_params, + param_names, param_values); } /** @@ -981,7 +1000,7 @@ WERROR smbconf_delete_share(struct smbconf_ctx *ctx, const char *servicename) return WERR_NO_SUCH_SERVICE; } - return smbconf_reg_delete_share(ctx, servicename); + return ctx->ops->delete_share(ctx, servicename); } /** @@ -996,7 +1015,7 @@ WERROR smbconf_set_parameter(struct smbconf_ctx *ctx, return WERR_NO_SUCH_SERVICE; } - return smbconf_reg_set_parameter(ctx, service, param, valstr); + return ctx->ops->set_parameter(ctx, service, param, valstr); } /** @@ -1035,7 +1054,7 @@ WERROR smbconf_get_parameter(struct smbconf_ctx *ctx, return WERR_NO_SUCH_SERVICE; } - return smbconf_reg_get_parameter(ctx, mem_ctx, service, param, valstr); + return ctx->ops->get_parameter(ctx, mem_ctx, service, param, valstr); } /** @@ -1069,7 +1088,7 @@ WERROR smbconf_delete_parameter(struct smbconf_ctx *ctx, return WERR_NO_SUCH_SERVICE; } - return smbconf_reg_delete_parameter(ctx, service, param); + return ctx->ops->delete_parameter(ctx, service, param); } /** -- cgit From ac7c582ec0a357c5b0e53bf38dd09a34eaab64eb Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 18:40:09 +0100 Subject: libsmbconf: add open and close operations to the smbconf_ops. Note: currently, reg_init_smbconf opens the registry, but does not close it. This has to be changed. so that it is closed. And then libsmbconf will need these open/close functions Michael (This used to be commit 77dbdf82efa60c8a7c00e489c198775b2f66e56c) --- source3/lib/smbconf/smbconf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index a9e895a168..4a5cbbd489 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -395,7 +395,7 @@ done: static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) { - return regdb_close(); + return ctx->ops->close_conf(ctx); } static WERROR smbconf_global_check(struct smbconf_ctx *ctx) @@ -436,6 +436,16 @@ done: return werr; } +static WERROR smbconf_reg_open(struct smbconf_ctx *ctx) +{ + return regdb_open(); +} + +static int smbconf_reg_close(struct smbconf_ctx *ctx) +{ + return regdb_close(); +} + /** * Get the change sequence number of the given service/parameter. * service and parameter strings may be NULL. @@ -751,6 +761,8 @@ done: struct smbconf_ops smbconf_ops_reg = { .init = smbconf_reg_init, + .open_conf = smbconf_reg_open, + .close_conf = smbconf_reg_close, .get_csn = smbconf_reg_get_csn, .drop = smbconf_reg_drop, .get_share_names = smbconf_reg_get_share_names, -- cgit From adf5bf554cd6bfdc5c6e7b1ed54f7f9329b15c50 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 23:41:39 +0100 Subject: libsmbconf: rename smbconf_open() to smbconf_init(). That's more appropriate. Michael (This used to be commit d7bd9bb8aa2003ec0a9860df26857f67255febe2) --- source3/lib/smbconf/smbconf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 4a5cbbd489..47254be68d 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -76,7 +76,7 @@ static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx, if (ctx->token == NULL) { DEBUG(1, ("Error: token missing from smbconf_ctx. " - "was smbconf_open() called?\n")); + "was smbconf_init() called?\n")); werr = WERR_INVALID_PARAM; goto done; } @@ -795,7 +795,7 @@ struct smbconf_ops smbconf_ops_reg = { * After the work with the configuration is completed, smbconf_close() * should be called. */ -WERROR smbconf_open(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) +WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) { WERROR werr = WERR_OK; struct smbconf_ctx *ctx; -- cgit From 23b1d721b8262f69cb7e28348c8e5cdf3483d4ea Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 01:04:57 +0100 Subject: libsmbconf: rename smbconf_close() to smbconf_shutdown(). Michael (This used to be commit 797b26ad3fad27e085827efb61f6b4d8b37e93f0) --- source3/lib/smbconf/smbconf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 47254be68d..660cb6f79f 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -792,7 +792,7 @@ struct smbconf_ops smbconf_ops_reg = { * that should be passed around in subsequent calls to the other * smbconf functions. * - * After the work with the configuration is completed, smbconf_close() + * 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) @@ -829,7 +829,7 @@ fail: /** * Close the configuration. */ -void smbconf_close(struct smbconf_ctx *ctx) +void smbconf_shutdown(struct smbconf_ctx *ctx) { /* this also closes the registry (by destructor): */ TALLOC_FREE(ctx); -- cgit From 095048f2dfb7621709f079f171d31bd6c4e610f9 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 01:15:20 +0100 Subject: libsmbconf: fix comments Michael (This used to be commit 24f32d9bd9aa837d777ea4187bebf3146a67ce59) --- source3/lib/smbconf/smbconf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 660cb6f79f..89fe558510 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -783,7 +783,7 @@ struct smbconf_ops smbconf_ops_reg = { **********************************************************************/ /** - * Open the configuration. + * Initialize the configuration. * * This should be the first function in a sequence of calls to smbconf * functions: @@ -831,7 +831,6 @@ fail: */ void smbconf_shutdown(struct smbconf_ctx *ctx) { - /* this also closes the registry (by destructor): */ TALLOC_FREE(ctx); } -- cgit From 6c20e83294f1b288142a2621a393d7c501532d69 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 02:01:55 +0100 Subject: libsmbconf: add shutdown handler to smbconf_ops. Michael (This used to be commit acbd1f40e0cb4cb5b2ba826c4825edda7ee4937b) --- source3/lib/smbconf/smbconf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 89fe558510..82683caa69 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -395,7 +395,7 @@ done: static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) { - return ctx->ops->close_conf(ctx); + return ctx->ops->shutdown(ctx); } static WERROR smbconf_global_check(struct smbconf_ctx *ctx) @@ -436,6 +436,11 @@ done: return werr; } +static int smbconf_reg_shutdown(struct smbconf_ctx *ctx) +{ + return regdb_close(); +} + static WERROR smbconf_reg_open(struct smbconf_ctx *ctx) { return regdb_open(); @@ -761,6 +766,7 @@ done: struct smbconf_ops smbconf_ops_reg = { .init = smbconf_reg_init, + .shutdown = smbconf_reg_shutdown, .open_conf = smbconf_reg_open, .close_conf = smbconf_reg_close, .get_csn = smbconf_reg_get_csn, -- cgit From fececde1815bf0469bb56e07cf23f54011c9b4ae Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 02:20:16 +0100 Subject: libsmbconf: add backend specific init function. Hide generic init function taking smbconf_ops argument from public api. Michael (This used to be commit b3f6920ccb9a27fde26e889a7f1f3afaf56b784f) --- source3/lib/smbconf/smbconf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 82683caa69..ceed349a09 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -781,6 +781,11 @@ struct smbconf_ops smbconf_ops_reg = { .delete_parameter = smbconf_reg_delete_parameter }; +WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) +{ + return smbconf_init(mem_ctx, conf_ctx, &smbconf_ops_reg); +} + /********************************************************************** * @@ -801,7 +806,8 @@ struct smbconf_ops smbconf_ops_reg = { * 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) +WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, + struct smbconf_ops *ops) { WERROR werr = WERR_OK; struct smbconf_ctx *ctx; @@ -815,7 +821,7 @@ WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) return WERR_NOMEM; } - ctx->ops = &smbconf_ops_reg; + ctx->ops = ops; werr = ctx->ops->init(ctx); if (!W_ERROR_IS_OK(werr)) { -- cgit From 890d1d8f78e27493c95103b828e3536e4565b344 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 16:26:50 +0100 Subject: libsmbconf: move registry implementation to a module of its own. Michael (This used to be commit 431b10bfe0dba0a49e50bebfb3f8ad1a00955837) --- source3/lib/smbconf/smbconf.c | 726 +----------------------------------------- 1 file changed, 5 insertions(+), 721 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index ceed349a09..88f2141139 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -23,17 +23,17 @@ /********************************************************************** * - * Helper functions (mostly registry related) + * Helper functions * **********************************************************************/ /** * add a string to a talloced array of strings. */ -static WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, - char ***array, - uint32_t count, - const char *string) + WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, + char ***array, + uint32_t count, + const char *string) { char **new_array = NULL; @@ -57,342 +57,6 @@ static WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, return WERR_OK; } -/** - * Open a registry key specified by "path" - */ -static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, - const char *path, - uint32 desired_access, - struct registry_key **key) -{ - WERROR werr = WERR_OK; - - if (ctx == NULL) { - DEBUG(1, ("Error: configuration is not open!\n")); - werr = WERR_INVALID_PARAM; - goto done; - } - - if (ctx->token == NULL) { - DEBUG(1, ("Error: token missing from smbconf_ctx. " - "was smbconf_init() called?\n")); - werr = WERR_INVALID_PARAM; - goto done; - } - - if (path == NULL) { - DEBUG(1, ("Error: NULL path string given\n")); - werr = WERR_INVALID_PARAM; - goto done; - } - - werr = reg_open_path(mem_ctx, path, desired_access, ctx->token, key); - - if (!W_ERROR_IS_OK(werr)) { - DEBUG(1, ("Error opening registry path '%s': %s\n", - path, dos_errstr(werr))); - } - -done: - return werr; -} - -/** - * Open a subkey of KEY_SMBCONF (i.e a service) - */ -static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, - const char *servicename, - uint32 desired_access, - struct registry_key **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(mem_ctx, "%s\\%s", KEY_SMBCONF, 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); - return werr; -} - -/** - * open the base key KEY_SMBCONF - */ -static WERROR smbconf_reg_open_base_key(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, - uint32 desired_access, - struct registry_key **key) -{ - return smbconf_reg_open_path(mem_ctx, ctx, KEY_SMBCONF, desired_access, - key); -} - -/** - * check if a value exists in a given registry key - */ -static bool smbconf_value_exists(struct registry_key *key, const char *param) -{ - bool ret = false; - WERROR werr = WERR_OK; - TALLOC_CTX *ctx = talloc_stackframe(); - struct registry_value *value = NULL; - - werr = reg_queryvalue(ctx, key, param, &value); - if (W_ERROR_IS_OK(werr)) { - ret = true; - } - - TALLOC_FREE(ctx); - return ret; -} - -/** - * create a subkey of KEY_SMBCONF - */ -static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx, - struct smbconf_ctx *ctx, - const char * subkeyname, - struct registry_key **newkey) -{ - WERROR werr = WERR_OK; - struct registry_key *create_parent = NULL; - TALLOC_CTX *create_ctx; - enum winreg_CreateAction action = REG_ACTION_NONE; - - /* 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; - } - - werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE, - &create_parent); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_createkey(mem_ctx, create_parent, subkeyname, - 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; - } - if (!W_ERROR_IS_OK(werr)) { - DEBUG(5, ("Error creating key %s: %s\n", - subkeyname, dos_errstr(werr))); - } - -done: - TALLOC_FREE(create_ctx); - return werr; -} - -/** - * add a value to a key. - */ -static WERROR smbconf_reg_set_value(struct registry_key *key, - const char *valname, - const char *valstr) -{ - struct registry_value val; - WERROR werr = WERR_OK; - char *subkeyname; - const char *canon_valname; - const char *canon_valstr; - - if (!lp_canonicalize_parameter_with_value(valname, valstr, - &canon_valname, - &canon_valstr)) - { - if (canon_valname == NULL) { - DEBUG(5, ("invalid parameter '%s' given\n", - valname)); - } else { - DEBUG(5, ("invalid value '%s' given for " - "parameter '%s'\n", valstr, valname)); - } - werr = WERR_INVALID_PARAM; - goto done; - } - - ZERO_STRUCT(val); - - val.type = REG_SZ; - val.v.sz.str = CONST_DISCARD(char *, canon_valstr); - val.v.sz.len = strlen(canon_valstr) + 1; - - if (registry_smbconf_valname_forbidden(canon_valname)) { - DEBUG(5, ("Parameter '%s' not allowed in registry.\n", - canon_valname)); - werr = WERR_INVALID_PARAM; - goto done; - } - - subkeyname = strrchr_m(key->key->name, '\\'); - if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) { - DEBUG(5, ("Invalid registry key '%s' given as " - "smbconf section.\n", key->key->name)); - werr = WERR_INVALID_PARAM; - goto done; - } - subkeyname++; - if (!strequal(subkeyname, GLOBAL_NAME) && - lp_parameter_is_global(valname)) - { - DEBUG(5, ("Global paramter '%s' not allowed in " - "service definition ('%s').\n", canon_valname, - subkeyname)); - werr = WERR_INVALID_PARAM; - goto done; - } - - werr = reg_setvalue(key, canon_valname, &val); - 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))); - } - -done: - return werr; -} - -/** - * format a registry_value into a string. - * - * This is intended to be used for smbconf registry values, - * which are ar stored as REG_SZ values, so the incomplete - * handling should be ok. - */ -static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx, - struct registry_value *value) -{ - char *result = NULL; - - /* alternatively, create a new talloc context? */ - if (mem_ctx == NULL) { - return result; - } - - switch (value->type) { - case REG_DWORD: - result = talloc_asprintf(mem_ctx, "%d", value->v.dword); - break; - case REG_SZ: - case REG_EXPAND_SZ: - result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str); - break; - case REG_MULTI_SZ: { - uint32 j; - for (j = 0; j < value->v.multi_sz.num_strings; j++) { - result = talloc_asprintf(mem_ctx, "%s \"%s\" ", - result, - value->v.multi_sz.strings[j]); - if (result == NULL) { - break; - } - } - break; - } - case REG_BINARY: - result = talloc_asprintf(mem_ctx, "binary (%d bytes)", - (int)value->v.binary.length); - break; - default: - result = talloc_asprintf(mem_ctx, ""); - break; - } - return result; -} - -/** - * Get the values of a key as a list of value names - * and a list of value strings (ordered) - */ -static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx, - struct registry_key *key, - uint32_t *num_values, - char ***value_names, - char ***value_strings) -{ - TALLOC_CTX *tmp_ctx = NULL; - WERROR werr = WERR_OK; - uint32_t count; - struct registry_value *valvalue = NULL; - char *valname = NULL; - char **tmp_valnames = NULL; - char **tmp_valstrings = NULL; - - if ((num_values == NULL) || (value_names == NULL) || - (value_strings == NULL)) - { - werr = WERR_INVALID_PARAM; - goto done; - } - - tmp_ctx = talloc_stackframe(); - if (tmp_ctx == NULL) { - werr = WERR_NOMEM; - goto done; - } - - for (count = 0; - W_ERROR_IS_OK(werr = reg_enumvalue(tmp_ctx, key, count, &valname, - &valvalue)); - count++) - { - char *valstring; - - werr = smbconf_add_string_to_array(tmp_ctx, - &tmp_valnames, - count, valname); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - valstring = smbconf_format_registry_value(tmp_ctx, valvalue); - werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings, - count, valstring); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - } - if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - goto done; - } - - werr = WERR_OK; - - *num_values = count; - if (count > 0) { - *value_names = talloc_move(mem_ctx, &tmp_valnames); - *value_strings = talloc_move(mem_ctx, &tmp_valstrings); - } else { - *value_names = NULL; - *value_strings = NULL; - } - -done: - TALLOC_FREE(tmp_ctx); - return werr; -} - static int smbconf_destroy_ctx(struct smbconf_ctx *ctx) { return ctx->ops->shutdown(ctx); @@ -407,386 +71,6 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx) } -/********************************************************************** - * - * smbconf operations: registry implementations - * - **********************************************************************/ - -/** - * initialize the registry smbconf backend - */ -static WERROR smbconf_reg_init(struct smbconf_ctx *ctx) -{ - WERROR werr = WERR_OK; - - if (!registry_init_smbconf()) { - werr = WERR_REG_IO_FAILURE; - goto done; - } - - werr = ntstatus_to_werror(registry_create_admin_token(ctx, - &(ctx->token))); - if (!W_ERROR_IS_OK(werr)) { - DEBUG(1, ("Error creating admin token\n")); - goto done; - } - -done: - return werr; -} - -static int smbconf_reg_shutdown(struct smbconf_ctx *ctx) -{ - return regdb_close(); -} - -static WERROR smbconf_reg_open(struct smbconf_ctx *ctx) -{ - return regdb_open(); -} - -static int smbconf_reg_close(struct smbconf_ctx *ctx) -{ - return regdb_close(); -} - -/** - * Get the change sequence number of the given service/parameter. - * service and parameter strings may be NULL. - */ -static void smbconf_reg_get_csn(struct smbconf_ctx *ctx, - struct smbconf_csn *csn, - const char *service, const char *param) -{ - if (csn == NULL) { - return; - } - csn->csn = (uint64_t)regdb_get_seqnum(); -} - -/** - * Drop the whole configuration (restarting empty) - registry version - */ -static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx) -{ - char *path, *p; - WERROR werr = WERR_OK; - struct registry_key *parent_key = NULL; - struct registry_key *new_key = NULL; - TALLOC_CTX* mem_ctx = talloc_stackframe(); - enum winreg_CreateAction action; - - path = talloc_strdup(mem_ctx, KEY_SMBCONF); - if (path == NULL) { - werr = WERR_NOMEM; - goto done; - } - p = strrchr(path, '\\'); - *p = '\0'; - werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE, - &parent_key); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE, - &new_key, &action); - -done: - TALLOC_FREE(mem_ctx); - return werr; -} - -/** - * get the list of share names defined in the configuration. - * registry version. - */ -static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx, - TALLOC_CTX *mem_ctx, - uint32_t *num_shares, - char ***share_names) -{ - uint32_t count; - uint32_t added_count = 0; - TALLOC_CTX *tmp_ctx = NULL; - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - char *subkey_name = NULL; - char **tmp_share_names = NULL; - - if ((num_shares == NULL) || (share_names == NULL)) { - werr = WERR_INVALID_PARAM; - goto done; - } - - tmp_ctx = talloc_stackframe(); - if (tmp_ctx == NULL) { - werr = WERR_NOMEM; - 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, - 0, GLOBAL_NAME); - 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; - } - - for (count = 0; - W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count, - &subkey_name, NULL)); - count++) - { - if (strequal(subkey_name, GLOBAL_NAME)) { - continue; - } - - werr = smbconf_add_string_to_array(tmp_ctx, - &tmp_share_names, - added_count, - subkey_name); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - added_count++; - } - if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - goto done; - } - werr = WERR_OK; - - *num_shares = added_count; - if (added_count > 0) { - *share_names = talloc_move(mem_ctx, &tmp_share_names); - } else { - *share_names = NULL; - } - -done: - TALLOC_FREE(tmp_ctx); - return werr; -} - -/** - * check if a share/service of a given name exists - registry version - */ -static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx, - const char *servicename) -{ - bool ret = false; - WERROR werr = WERR_OK; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - struct registry_key *key = NULL; - - werr = smbconf_reg_open_service_key(mem_ctx, 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 - registry version - */ -static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx, - const char *servicename) -{ - WERROR werr; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - struct registry_key *key = NULL; - - werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key); - - TALLOC_FREE(mem_ctx); - return werr; -} - -/** - * get a definition of a share (service) from configuration. - */ -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) -{ - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename, - REG_KEY_READ, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = smbconf_reg_get_values(mem_ctx, key, num_params, - param_names, param_values); - -done: - TALLOC_FREE(key); - return werr; -} - -/** - * delete a service from configuration - */ -static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx, - const char *servicename) -{ - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - - werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_deletekey_recursive(key, key, servicename); - -done: - TALLOC_FREE(mem_ctx); - return werr; -} - -/** - * set a configuration parameter to the value provided. - */ -static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx, - const char *service, - const char *param, - const char *valstr) -{ - WERROR werr; - struct registry_key *key = NULL; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_WRITE, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = smbconf_reg_set_value(key, param, valstr); - -done: - TALLOC_FREE(mem_ctx); - return werr; -} - -/** - * get the value of a configuration parameter as a string - */ -static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx, - TALLOC_CTX *mem_ctx, - const char *service, - const char *param, - char **valstr) -{ - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - struct registry_value *value = NULL; - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_READ, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - if (!smbconf_value_exists(key, param)) { - werr = WERR_INVALID_PARAM; - goto done; - } - - werr = reg_queryvalue(mem_ctx, key, param, &value); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - *valstr = smbconf_format_registry_value(mem_ctx, value); - - if (*valstr == NULL) { - werr = WERR_NOMEM; - } - -done: - TALLOC_FREE(key); - TALLOC_FREE(value); - return werr; -} - -/** - * delete a parameter from configuration - */ -static WERROR smbconf_reg_delete_parameter(struct smbconf_ctx *ctx, - const char *service, - const char *param) -{ - struct registry_key *key = NULL; - WERROR werr = WERR_OK; - TALLOC_CTX *mem_ctx = talloc_stackframe(); - - werr = smbconf_reg_open_service_key(mem_ctx, ctx, service, - REG_KEY_ALL, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - if (!smbconf_value_exists(key, param)) { - werr = WERR_INVALID_PARAM; - goto done; - } - - werr = reg_deletevalue(key, param); - -done: - TALLOC_FREE(mem_ctx); - return werr; -} - -struct smbconf_ops smbconf_ops_reg = { - .init = smbconf_reg_init, - .shutdown = smbconf_reg_shutdown, - .open_conf = smbconf_reg_open, - .close_conf = smbconf_reg_close, - .get_csn = smbconf_reg_get_csn, - .drop = smbconf_reg_drop, - .get_share_names = smbconf_reg_get_share_names, - .share_exists = smbconf_reg_share_exists, - .create_share = smbconf_reg_create_share, - .get_share = smbconf_reg_get_share, - .delete_share = smbconf_reg_delete_share, - .set_parameter = smbconf_reg_set_parameter, - .get_parameter = smbconf_reg_get_parameter, - .delete_parameter = smbconf_reg_delete_parameter -}; - -WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx) -{ - return smbconf_init(mem_ctx, conf_ctx, &smbconf_ops_reg); -} - - /********************************************************************** * * The actual libsmbconf API functions that are exported. -- cgit From 5e1eca34f36e1d886e568142d18813cedf3e1699 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 16:40:20 +0100 Subject: libsmbconf: group together functions in smbconf.c more appropriately Michael (This used to be commit e8ed8ad077f69ae7237f49b150625d20eb509586) --- source3/lib/smbconf/smbconf.c | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 88f2141139..0eee5a6c4a 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -23,7 +23,28 @@ /********************************************************************** * - * Helper functions + * internal helper functions + * + **********************************************************************/ + +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)) { + return smbconf_create_share(ctx, GLOBAL_NAME); + } + return WERR_OK; +} + + +/********************************************************************** + * + * helper functions exported to the backend modules + * (might go into a smbconf_util.c) * **********************************************************************/ @@ -57,26 +78,6 @@ return WERR_OK; } -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)) { - return smbconf_create_share(ctx, GLOBAL_NAME); - } - return WERR_OK; -} - - -/********************************************************************** - * - * The actual libsmbconf API functions that are exported. - * - **********************************************************************/ - /** * Initialize the configuration. * @@ -122,6 +123,13 @@ fail: return werr; } + +/********************************************************************** + * + * The actual libsmbconf API functions that are exported. + * + **********************************************************************/ + /** * Close the configuration. */ -- cgit From 6f7cfeddd61f728e2452a7b89f5ee2ff36ca394f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 17:55:31 +0100 Subject: libsmbconf: add a "path" variable to the conf context. This is passed to the module init routines. In case of the registry, this is the path of the basekey in registry, that is to be used, defaulting to KEY_SMBCONF (HKLM\software\samba\smbconf), when NULL is given. This is the only case currently used. In order to support other keys, registry initialization for smbconf has to be changed to support different keys. Michael (This used to be commit 96434d9dc7a66773e313cc128af57493dee245a1) --- source3/lib/smbconf/smbconf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 0eee5a6c4a..756b9ec3ca 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -92,7 +92,7 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx) * should be called. */ WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, - struct smbconf_ops *ops) + const char *path, struct smbconf_ops *ops) { WERROR werr = WERR_OK; struct smbconf_ctx *ctx; @@ -108,7 +108,7 @@ WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, ctx->ops = ops; - werr = ctx->ops->init(ctx); + werr = ctx->ops->init(ctx, path); if (!W_ERROR_IS_OK(werr)) { goto fail; } -- cgit From a8d7febc7a04d63387667d76d683c5d6943197dd Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Mar 2008 10:55:26 +0100 Subject: smbconf: reformat - fix intentation. This time this won't make me stumble, since there is no magic in indented function headers here - no automatic prototype generation... :-) Michael (This used to be commit 6d72fc4373adff01cf6e0e18f78082d1eab90064) --- source3/lib/smbconf/smbconf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 756b9ec3ca..4315dd990e 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -51,10 +51,10 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx) /** * 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) +WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, + char ***array, + uint32_t count, + const char *string) { char **new_array = NULL; -- cgit From 36ede8ae549837452bbd577e43cda8d84ee22c4b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 7 Apr 2008 15:01:44 +0200 Subject: libsmbconf: move utility functions from main module to new smbconf_util.c Michael (This used to be commit e0f6a9d50c9b72ec33d4323d1a6c5bdf44d011e7) --- source3/lib/smbconf/smbconf.c | 88 ------------------------------------------- 1 file changed, 88 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 4315dd990e..62c5be8294 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -27,11 +27,6 @@ * **********************************************************************/ -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. -- cgit From 3c40c2d7d32ae7db064a7f44da9e736efc7936bb Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 7 Apr 2008 15:12:44 +0200 Subject: libsmbconf: fix a comment Michael (This used to be commit bc1a5bdbd3b7da1f85c952579096b3c8dc407572) --- source3/lib/smbconf/smbconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 62c5be8294..453e228c2c 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -1,6 +1,6 @@ /* * Unix SMB/CIFS implementation. - * libnet smbconf registry Support + * libsmbconf - Samba configuration library * Copyright (C) Michael Adam 2007-2008 * Copyright (C) Guenther Deschner 2007 * -- cgit From 8e9766289972ecf3f4bcaa1a9ed118bba5fea208 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 8 Apr 2008 01:56:32 +0200 Subject: libsmbconf: add get_includes() and set_includes() to the API. Includes have to get a special treatment, at least for registry. Includes are not like other smbconf parameters: they are some kind of metainformation. "include" has two effects when stated twice so it can not be stored boldly into registry, since there can only be one value named "include" in registry per key. I will provide special handling for includes for the registry backend. This patch provides the necessary methods in the smbconf API. Michael (This used to be commit e86eb375d9f83f73aeea0a16c8b43e2ef21a6e20) --- source3/lib/smbconf/smbconf.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 453e228c2c..1ce761ebd4 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -335,3 +335,25 @@ WERROR smbconf_delete_global_parameter(struct smbconf_ctx *ctx, return werr; } + +WERROR smbconf_get_includes(struct smbconf_ctx *ctx, + const char *service, + uint32_t *num_includes, char ***includes) +{ + if (!smbconf_share_exists(ctx, service)) { + return WERR_NO_SUCH_SERVICE; + } + + return ctx->ops->get_includes(ctx, service, num_includes, includes); +} + +WERROR smbconf_set_includes(struct smbconf_ctx *ctx, + const char *service, + uint32_t num_includes, const char **includes) +{ + if (!smbconf_share_exists(ctx, service)) { + return WERR_NO_SUCH_SERVICE; + } + + return ctx->ops->set_includes(ctx, service, num_includes, includes); +} -- cgit From f5aac0a8d01885d06594c4bbe0ff815bb9339a0c Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 8 Apr 2008 10:16:03 +0200 Subject: libsmbconf: add talloc context to the get_includes methods. Michael (This used to be commit ed535b6b30b5c9412803f6373eadc704de6de2f9) --- source3/lib/smbconf/smbconf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 1ce761ebd4..d5a334b928 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -337,6 +337,7 @@ WERROR smbconf_delete_global_parameter(struct smbconf_ctx *ctx, } WERROR smbconf_get_includes(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, const char *service, uint32_t *num_includes, char ***includes) { @@ -344,7 +345,8 @@ WERROR smbconf_get_includes(struct smbconf_ctx *ctx, return WERR_NO_SUCH_SERVICE; } - return ctx->ops->get_includes(ctx, service, num_includes, includes); + return ctx->ops->get_includes(ctx, mem_ctx, service, num_includes, + includes); } WERROR smbconf_set_includes(struct smbconf_ctx *ctx, -- cgit From d399778accf0bef382b657a834f9d2a80d05fe77 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 8 Apr 2008 14:24:42 +0200 Subject: libsmbconf: add "_global_" wrappers for get/set_includes. These use the usual global_check like the other global wrappers. Michael (This used to be commit ce1b2f550860cb3a566db09f7c7eac39c195a5b7) --- source3/lib/smbconf/smbconf.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index d5a334b928..7c24c55781 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -349,6 +349,21 @@ WERROR smbconf_get_includes(struct smbconf_ctx *ctx, includes); } +WERROR smbconf_get_global_includes(struct smbconf_ctx *ctx, + TALLOC_CTX *mem_ctx, + uint32_t *num_includes, char ***includes) +{ + WERROR werr; + + werr = smbconf_global_check(ctx); + if (W_ERROR_IS_OK(werr)) { + werr = smbconf_get_includes(ctx, mem_ctx, GLOBAL_NAME, + num_includes, includes); + } + + return werr; +} + WERROR smbconf_set_includes(struct smbconf_ctx *ctx, const char *service, uint32_t num_includes, const char **includes) @@ -359,3 +374,18 @@ WERROR smbconf_set_includes(struct smbconf_ctx *ctx, return ctx->ops->set_includes(ctx, service, num_includes, includes); } + +WERROR smbconf_set_global_includes(struct smbconf_ctx *ctx, + uint32_t num_includes, + const char **includes) +{ + WERROR werr; + + werr = smbconf_global_check(ctx); + if (W_ERROR_IS_OK(werr)) { + werr = smbconf_set_includes(ctx, GLOBAL_NAME, + num_includes, includes); + } + + return werr; +} -- cgit From 87ca44723181900799985d7c3c1d02863fb8da71 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 22:21:15 +0200 Subject: libsmbconf: add delete_includes mehtod to the api (and backend implementations) Michael (This used to be commit daef50e54d58a6684b6a890ebf523ca6245f0290) --- source3/lib/smbconf/smbconf.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 7c24c55781..541b163bfb 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -389,3 +389,25 @@ WERROR smbconf_set_global_includes(struct smbconf_ctx *ctx, return werr; } + + +WERROR smbconf_delete_includes(struct smbconf_ctx *ctx, const char *service) +{ + if (!smbconf_share_exists(ctx, service)) { + return WERR_NO_SUCH_SERVICE; + } + + return ctx->ops->delete_includes(ctx, service); +} + +WERROR smbconf_delete_global_includes(struct smbconf_ctx *ctx) +{ + WERROR werr; + + werr = smbconf_global_check(ctx); + if (W_ERROR_IS_OK(werr)) { + werr = smbconf_delete_includes(ctx, GLOBAL_NAME); + } + + return werr; +} -- cgit From e700800720aec4b9a85a5c3cbc95cd78a03defaa Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 14:36:39 +0200 Subject: libsmbconf: allow NULL sharename in smbconf_share_exists(). Michael (This used to be commit cb23052b2055d77924b2a593ec14f0c1de9a3b51) --- source3/lib/smbconf/smbconf.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 541b163bfb..0359e000d3 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -183,9 +183,6 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx, bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename) { - if (servicename == NULL) { - return false; - } return ctx->ops->share_exists(ctx, servicename); } -- cgit From be504b9d32e970428175a0cba8fdcceb4369721f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:37:39 +0200 Subject: libsmbconf: don't complain with WERR_ALREADY_EXISTS for NULL share in smbconf_create_share(). These are values stored inside the base key for registry. This is not getting deleted. Michael (This used to be commit aa167de8252bb615bd21fb3fd9468383b8357d32) --- source3/lib/smbconf/smbconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 0359e000d3..9565540df4 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -192,7 +192,7 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, WERROR smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename) { - if (smbconf_share_exists(ctx, servicename)) { + if ((servicename != NULL) && smbconf_share_exists(ctx, servicename)) { return WERR_ALREADY_EXISTS; } -- cgit From fb9232c0a98d9ce600e379dd03ee6fa3cd73cba5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 22 Apr 2008 16:31:16 +0200 Subject: libsmbconf: rewrite API to use smbconf_service struct instead of lists of strings and counters directly... Michael (This used to be commit 17415e2dc457ce41793a7e28e71f72c538c19c61) --- source3/lib/smbconf/smbconf.c | 44 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 9565540df4..00b9ba3e07 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -91,22 +91,16 @@ WERROR smbconf_drop(struct smbconf_ctx *ctx) WERROR smbconf_get_config(struct smbconf_ctx *ctx, TALLOC_CTX *mem_ctx, uint32_t *num_shares, - char ***share_names, uint32_t **num_params, - char ****param_names, char ****param_values) + struct smbconf_service ***services) { WERROR werr = WERR_OK; TALLOC_CTX *tmp_ctx = NULL; uint32_t tmp_num_shares; char **tmp_share_names; - uint32_t *tmp_num_params; - char ***tmp_param_names; - char ***tmp_param_values; + struct smbconf_service **tmp_services; uint32_t count; - if ((num_shares == NULL) || (share_names == NULL) || - (num_params == NULL) || (param_names == NULL) || - (param_values == NULL)) - { + if ((num_shares == NULL) || (services == NULL)) { werr = WERR_INVALID_PARAM; goto done; } @@ -123,23 +117,18 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx, goto done; } - tmp_num_params = TALLOC_ARRAY(tmp_ctx, uint32_t, tmp_num_shares); - tmp_param_names = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares); - tmp_param_values = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares); + tmp_services = TALLOC_ARRAY(tmp_ctx, struct smbconf_service *, + tmp_num_shares); - if ((tmp_num_params == NULL) || (tmp_param_names == NULL) || - (tmp_param_values == NULL)) - { + if (tmp_services == NULL) { werr = WERR_NOMEM; goto done; } for (count = 0; count < tmp_num_shares; count++) { - werr = smbconf_get_share(ctx, mem_ctx, + werr = smbconf_get_share(ctx, tmp_services, tmp_share_names[count], - &tmp_num_params[count], - &tmp_param_names[count], - &tmp_param_values[count]); + &tmp_services[count]); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -149,15 +138,9 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx, *num_shares = tmp_num_shares; if (tmp_num_shares > 0) { - *share_names = talloc_move(mem_ctx, &tmp_share_names); - *num_params = talloc_move(mem_ctx, &tmp_num_params); - *param_names = talloc_move(mem_ctx, &tmp_param_names); - *param_values = talloc_move(mem_ctx, &tmp_param_values); + *services = talloc_move(mem_ctx, &tmp_services); } else { - *share_names = NULL; - *num_params = NULL; - *param_names = NULL; - *param_values = NULL; + *services = NULL; } done: @@ -204,15 +187,14 @@ WERROR smbconf_create_share(struct smbconf_ctx *ctx, */ WERROR smbconf_get_share(struct smbconf_ctx *ctx, TALLOC_CTX *mem_ctx, - const char *servicename, uint32_t *num_params, - char ***param_names, char ***param_values) + const char *servicename, + struct smbconf_service **service) { if (!smbconf_share_exists(ctx, servicename)) { return WERR_NO_SUCH_SERVICE; } - return ctx->ops->get_share(ctx, mem_ctx, servicename, num_params, - param_names, param_values); + return ctx->ops->get_share(ctx, mem_ctx, servicename, service); } /** -- cgit From 8cf78fd594ab20a03315a4a04941d37a682d22cf Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 23 Apr 2008 01:47:33 +0200 Subject: libsmbconf: remove unnecessary talloc success checks from smbconf.c talloc_stackframe() panics on NOMEM. Michael (This used to be commit be4f8447ccd044563f6b12793ea64d9f38741861) --- source3/lib/smbconf/smbconf.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/lib/smbconf/smbconf.c') diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 00b9ba3e07..1a9b4e07f9 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -106,10 +106,6 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx, } tmp_ctx = talloc_stackframe(); - if (tmp_ctx == NULL) { - werr = WERR_NOMEM; - goto done; - } werr = smbconf_get_share_names(ctx, tmp_ctx, &tmp_num_shares, &tmp_share_names); -- cgit