From a40df6f92d42676a9184fb2c20a11d5662ca5b3a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 9 Apr 2007 10:38:55 +0000 Subject: r22135: Check in most of Michael Adam's net conf utility. A good share of this patch is moving functions around to fix some linker dependencies for the registry. Michael, I've renamed your auth_utils2.c to token_utils.c. Thanks! Volker (This used to be commit 9de16f25c1c3e0b203da47391772ef2e2fe291ac) --- source3/utils/net_conf.c | 1118 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1118 insertions(+) create mode 100644 source3/utils/net_conf.c (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c new file mode 100644 index 0000000000..7d8849a99a --- /dev/null +++ b/source3/utils/net_conf.c @@ -0,0 +1,1118 @@ +/* + * Samba Unix/Linux SMB client library + * Distributed SMB/CIFS Server Management Utility + * Local configuration interface + * Copyright (C) Michael Adam 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 2 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * This currently only an interface to the configuration + * stored inside the samba registry. In the future there + * might be support for other configuration backends as well. + */ + +/* + * TODO: + * + * - check uid 0 for write operations + * - check for valid parameter names and types (loadparm...) ??? + * - check for correctness of shares (service_ok) ? + * - refactor to use _internal functions for pieces of code + * + */ + +#include "includes.h" +#include "utils/net.h" + +extern REGISTRY_OPS smbconf_reg_ops; + +/* + * usage functions + */ + +static int net_conf_list_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf list\n"); + return -1; +} + +static int net_conf_import_usage(int argc, const char**argv) +{ + d_printf("USAGE: net conf import [--test|-T] []\n" + "\t[--test|-T] testmode - do not act, just print " + "what would be done\n" + "\t only import service , " + "ignore the rest\n"); + return -1; +} + +static int net_conf_listshares_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf listshares\n"); + return -1; +} + +static int net_conf_showshare_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf showshare \n"); + return -1; +} + +static int net_conf_addshare_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf addshare " + "[writeable={y|N} [guest_ok={y|N} []]\n" + "\t the new share name.\n" + "\t the path on the filesystem to export.\n" + "\twriteable={y|N} set \"writeable to \"yes\" or " + "\"no\" (default) on this share.\n" + "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or " + "\"no\" (default) on this share.\n" + "\t optional comment for the new share.\n"); + return -1; +} + +static int net_conf_delshare_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf delshare \n"); + return -1; +} + +static int net_conf_setparm_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf setparm
\n" + "\t(Supported types are 'dword' and 'sz' by now.)\n"); + return -1; +} + +static int net_conf_getparm_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf getparm
\n"); + return -1; +} + +static int net_conf_delparm_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf delparm
\n"); + return -1; +} + + +/* + * Helper functions + */ + +static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) +{ + char *result = NULL; + + /* what if mem_ctx = NULL? */ + + 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\" ", + value->v.multi_sz.strings[j]); + } + 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; +} + +/* + * add a value to a key. + */ +static WERROR reg_setvalue_internal(struct registry_key *key, + const char *valname, + const char *valtype, + const char *valstr) +{ + struct registry_value val; + WERROR werr = WERR_OK; + + ZERO_STRUCT(val); + + if (strequal(valtype, "dword")) { + val.type = REG_DWORD; + val.v.dword = strtoul(valstr, NULL, 10); + } + else if (strequal(valtype, "sz")) { + val.type = REG_SZ; + val.v.sz.str = CONST_DISCARD(char *, valstr); + val.v.sz.len = strlen(valstr) + 1; + } + else { + d_fprintf(stderr, "Sorry, only value types DWORD and SZ implementd currently for setting values.\n"); + goto done; + } + + werr = reg_setvalue(key, valname, &val); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, + "Error adding value '%s' to " + "key '%s': %s\n", + valname, key->key->name, dos_errstr(werr)); + } + +done: + return werr; +} + +/* + * Open a subkey of KEY_SMBCONF (i.e a service) + * - variant without error output (q = quiet)- + */ +static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname, + uint32 desired_access, + struct registry_key **key) +{ + WERROR werr = WERR_OK; + char *path = NULL; + + if (subkeyname == NULL) { + path = talloc_strdup(ctx, KEY_SMBCONF); + } + else { + path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, subkeyname); + } + + werr = reg_open_path(ctx, path, desired_access, + get_root_nt_token(), key); + + TALLOC_FREE(path); + return werr; +} + +/* + * Open a subkey of KEY_SMBCONF (i.e a service) + * - variant with error output - + */ +static WERROR smbconf_open_path(TALLOC_CTX *ctx, const char *subkeyname, + uint32 desired_access, + struct registry_key **key) +{ + WERROR werr = WERR_OK; + + werr = smbconf_open_path_q(ctx, subkeyname, desired_access, key); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error opening registry path '%s\\%s': %s\n", + KEY_SMBCONF, + (subkeyname == NULL) ? "" : subkeyname, + dos_errstr(werr)); + } + + return werr; +} + +/* + * open the base key KEY_SMBCONF + */ +static WERROR smbconf_open_basepath(TALLOC_CTX *ctx, uint32 desired_access, + struct registry_key **key) +{ + return smbconf_open_path(ctx, NULL, desired_access, key); +} + +/* + * delete a subkey of KEY_SMBCONF + */ +static WERROR reg_delkey_internal(TALLOC_CTX *ctx, const char *keyname) +{ + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + + werr = smbconf_open_basepath(ctx, REG_KEY_WRITE, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_deletekey(key, keyname); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error deleting registry key %s\\%s: %s\n", + KEY_SMBCONF, keyname, dos_errstr(werr)); + } + +done: + TALLOC_FREE(key); + return werr; +} + +/* + * create a subkey of KEY_SMBCONF + */ +static WERROR reg_createkey_internal(TALLOC_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_new(ctx))) { + werr = WERR_NOMEM; + goto done; + } + + werr = smbconf_open_basepath(create_ctx, REG_KEY_WRITE, &create_parent); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_createkey(ctx, create_parent, subkeyname, + REG_KEY_WRITE, newkey, &action); + if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) { + d_fprintf(stderr, "Key '%s' already exists.\n", subkeyname); + werr = WERR_ALREADY_EXISTS; + } + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error creating key %s: %s\n", + subkeyname, dos_errstr(werr)); + } + +done: + TALLOC_FREE(create_ctx); + return werr; +} + +/* + * check if a subkey of KEY_SMBCONF of a given name exists + */ +static BOOL smbconf_key_exists(TALLOC_CTX *ctx, const char *subkeyname) +{ + BOOL ret = False; + WERROR werr = WERR_OK; + TALLOC_CTX *mem_ctx; + struct registry_key *key; + + if (!(mem_ctx = talloc_new(ctx))) { + d_fprintf(stderr, "ERROR: Out of memory...!\n"); + goto done; + } + + werr = smbconf_open_path_q(mem_ctx, subkeyname, REG_KEY_READ, &key); + if (W_ERROR_IS_OK(werr)) { + ret = True; + } + +done: + TALLOC_FREE(mem_ctx); + return ret; +} + +static BOOL smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key, + const char *param) +{ + BOOL ret = False; + WERROR werr = WERR_OK; + struct registry_value *value = NULL; + + werr = reg_queryvalue(ctx, key, param, &value); + if (W_ERROR_IS_OK(werr)) { + ret = True; + } + + TALLOC_FREE(value); + return ret; +} + +static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) +{ + WERROR werr = WERR_OK; + uint32 idx = 0; + struct registry_value *valvalue = NULL; + char *valname = NULL; + + for (idx = 0; + W_ERROR_IS_OK(werr = reg_enumvalue(ctx, key, idx, &valname, + &valvalue)); + idx++) + { + d_printf("\t%s = %s\n", valname, format_value(ctx, valvalue)); + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + d_fprintf(stderr, "Error enumerating values: %s\n", + dos_errstr(werr)); + goto done; + } + werr = WERR_OK; + +done: + return werr; +} + +static int import_process_service(TALLOC_CTX *ctx, + struct share_params *share) +{ + int ret = -1; + struct parm_struct *parm; + int pnum = 0; + const char *servicename; + struct registry_key *key; + WERROR werr; + const char *valtype = NULL; + char *valstr = NULL; + + servicename = (share->service == GLOBAL_SECTION_SNUM)? + GLOBAL_NAME : lp_servicename(share->service); + + if (opt_testmode) { + d_printf("[%s]\n", servicename); + } + else { + if (smbconf_key_exists(ctx, servicename)) { + werr = reg_delkey_internal(ctx, servicename); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + werr = reg_createkey_internal(ctx, servicename, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + + while ((parm = lp_next_parameter(share->service, &pnum, 0))) + { + void *ptr = parm->ptr; + int i = 0; + + if ((share->service < 0 && parm->p_class == P_LOCAL) + && !(parm->flags & FLAG_GLOBAL)) + continue; + + if (parm->p_class == P_LOCAL && share->service >= 0) { + ptr = lp_local_ptr(share->service, ptr); + } + + valtype = "sz"; + + switch (parm->type) { + case P_CHAR: + valstr = talloc_asprintf(ctx, "%c", *(char *)ptr); + break; + case P_STRING: + case P_USTRING: + valstr = talloc_asprintf(ctx, "%s", *(char **)ptr); + break; + case P_GSTRING: + case P_UGSTRING: + valstr = talloc_asprintf(ctx, "%s", (char *)ptr); + break; + case P_BOOL: + valstr = talloc_asprintf(ctx, "%s", + BOOLSTR(*(BOOL *)ptr)); + break; + case P_BOOLREV: + valstr = talloc_asprintf(ctx, "%s", + BOOLSTR(!*(BOOL *)ptr)); + break; + case P_ENUM: + for (i = 0; parm->enum_list[i].name; i++) { + if (*(int *)ptr == + parm->enum_list[i].value) + { + valstr = talloc_asprintf(ctx, "%s", + parm->enum_list[i].name); + break; + } + } + break; + case P_OCTAL: + talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); + break; + case P_LIST: + valstr = talloc_strdup(ctx, ""); + if ((char ***)ptr && *(char ***)ptr) { + char **list = *(char ***)ptr; + for (; *list; list++) { + /* surround strings with whitespace + * in double quotes */ + if (strchr_m(*list, ' ')) + { + valstr = talloc_asprintf_append( + valstr, "\"%s\"%s", + *list, + ((*(list+1))?", ":"")); + } + else { + valstr = talloc_asprintf_append( + valstr, "%s%s", *list, + ((*(list+1))?", ":"")); + } + } + } + break; + case P_INTEGER: + valtype = "dword"; + talloc_asprintf(ctx, "%d", *(int *)ptr); + break; + case P_SEP: + break; + default: + valstr = talloc_asprintf(ctx, "\n"); + break; + } + + if (parm->type != P_SEP) { + if (opt_testmode) { + d_printf("\t%s = %s\n", parm->label, valstr); + } + else { + werr = reg_setvalue_internal(key, parm->label, + valtype, valstr); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + } + } + + if (opt_testmode) { + d_printf("\n"); + } + + ret = 0; +done: + return ret; +} + + +/* + * the conf functions + */ + +int net_conf_list(int argc, const char **argv) +{ + WERROR werr = WERR_OK; + int ret = -1; + TALLOC_CTX *ctx; + struct registry_key *base_key = NULL; + struct registry_key *sub_key = NULL; + uint32 idx_key = 0; + char *subkey_name = NULL; + + ctx = talloc_init("list"); + + if (argc != 0) { + net_conf_list_usage(argc, argv); + goto done; + } + + werr = smbconf_open_basepath(ctx, REG_KEY_READ, &base_key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (smbconf_key_exists(ctx, GLOBAL_NAME)) { + werr = reg_openkey(ctx, base_key, GLOBAL_NAME, + REG_KEY_READ, &sub_key); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error opening subkey '%s' : %s\n", + subkey_name, dos_errstr(werr)); + goto done; + } + d_printf("[%s]\n", GLOBAL_NAME); + if (!W_ERROR_IS_OK(list_values(ctx, sub_key))) { + goto done; + } + d_printf("\n"); + } + + for (idx_key = 0; + W_ERROR_IS_OK(werr = reg_enumkey(ctx, base_key, idx_key, + &subkey_name, NULL)); + idx_key++) + { + if (strequal(subkey_name, GLOBAL_NAME)) { + continue; + } + d_printf("[%s]\n", subkey_name); + + werr = reg_openkey(ctx, base_key, subkey_name, + REG_KEY_READ, &sub_key); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, + "Error opening subkey '%s': %s\n", + subkey_name, dos_errstr(werr)); + goto done; + } + if (!W_ERROR_IS_OK(list_values(ctx, sub_key))) { + goto done; + } + d_printf("\n"); + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + d_fprintf(stderr, "Error enumerating subkeys: %s\n", + dos_errstr(werr)); + goto done; + } + + ret = 0; + +done: + TALLOC_FREE(ctx); + return ret; +} + +int net_conf_import(int argc, const char **argv) +{ + int ret = -1; + const char *filename = NULL; + const char *servicename = NULL; + BOOL service_found = False; + TALLOC_CTX *ctx; + struct share_iterator *shares; + struct share_params *share; + struct share_params global_share = { GLOBAL_SECTION_SNUM }; + + ctx = talloc_init("net_conf_import"); + + switch (argc) { + case 0: + default: + net_conf_import_usage(argc, argv); + goto done; + case 2: + servicename = argv[1]; + case 1: + filename = argv[0]; + break; + } + + DEBUG(3,("net_conf_import: reading configuration from file %s.\n", + filename)); + + /* TODO: check for existence and readability */ + + if (!lp_load(filename, + False, /* global_only */ + True, /* save_defaults */ + False, /* add_ipc */ + True)) /* initialize_globals */ + { + d_fprintf(stderr, "Error parsing configuration file.\n"); + goto done; + } + + if (opt_testmode) { + d_printf("\nTEST MODE - would import the following configuration:\n\n"); + } + + if ((servicename == NULL) || strequal(servicename, GLOBAL_NAME)) { + service_found = True; + if (import_process_service(ctx, &global_share) != 0) { + goto done; + } + } + + if (service_found && (servicename != NULL)) { + ret = 0; + goto done; + } + + if (!(shares = share_list_all(ctx))) { + d_fprintf(stderr, "Could not list shares...\n"); + goto done; + } + while ((share = next_share(shares)) != NULL) { + if ((servicename == NULL) + || strequal(servicename, lp_servicename(share->service))) + { + service_found = True; + if (import_process_service(ctx, share)!= 0) { + goto done; + } + } + } + + if ((servicename != NULL) && !service_found) { + d_printf("Share %s not found in file %s\n", + servicename, filename); + goto done; + + } + + ret = 0; + +done: + TALLOC_FREE(ctx); + return ret; +} + +int net_conf_listshares(int argc, const char **argv) +{ + WERROR werr = WERR_OK; + int ret = -1; + struct registry_key *key; + uint32 idx = 0; + char *subkey_name = NULL; + TALLOC_CTX *ctx; + + ctx = talloc_init("listshares"); + + if (argc != 0) { + net_conf_listshares_usage(argc, argv); + goto done; + } + + werr = smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + for (idx = 0; + W_ERROR_IS_OK(werr = reg_enumkey(ctx, key, idx, + &subkey_name, NULL)); + idx++) + { + d_printf("%s\n", subkey_name); + } + if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + d_fprintf(stderr, "Error enumerating subkeys: %s\n", + dos_errstr(werr)); + goto done; + } + + ret = 0; + +done: + TALLOC_FREE(ctx); + return ret; +} + +int net_conf_showshare(int argc, const char **argv) +{ + int ret = -1; + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + TALLOC_CTX *ctx; + + ctx = talloc_init("showshare"); + + if (argc != 1) { + net_conf_showshare_usage(argc, argv); + goto done; + } + + werr = smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + d_printf("[%s]\n", argv[0]); + + if (!W_ERROR_IS_OK(list_values(ctx, key))) { + goto done; + } + + ret = 0; + +done: + TALLOC_FREE(ctx); + return ret; +} + +int net_conf_addshare(int argc, const char **argv) +{ + int ret = -1; + WERROR werr = WERR_OK; + struct registry_key *newkey = NULL; + char *sharename = NULL; + const char *path = NULL; + const char *comment = NULL; + const char *guest_ok = "no"; + const char *writeable = "no"; + SMB_STRUCT_STAT sbuf; + + switch (argc) { + case 0: + case 1: + default: + net_conf_addshare_usage(argc, argv); + goto done; + case 5: + comment = argv[4]; + case 4: + if (!strnequal(argv[3], "guest_ok=", 9)) { + net_conf_addshare_usage(argc, argv); + goto done; + } + switch (argv[3][9]) { + case 'y': + case 'Y': + guest_ok = "yes"; + break; + case 'n': + case 'N': + guest_ok = "no"; + break; + default: + net_conf_addshare_usage(argc, argv); + goto done; + } + case 3: + if (!strnequal(argv[2], "writeable=", 10)) { + net_conf_addshare_usage(argc, argv); + goto done; + } + switch (argv[2][10]) { + case 'y': + case 'Y': + writeable = "yes"; + break; + case 'n': + case 'N': + writeable = "no"; + break; + default: + net_conf_addshare_usage(argc, argv); + goto done; + } + + case 2: + path = argv[1]; + sharename = strdup_lower(argv[0]); + break; + } + + /* + * validate arguments + */ + + /* validate share name */ + + if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS, + strlen(sharename))) + { + d_fprintf(stderr, "ERROR: share name %s contains " + "invalid characters (any of %s)\n", + sharename, INVALID_SHARENAME_CHARS); + goto done; + } + + if (getpwnam(sharename)) { + d_fprintf(stderr, "ERROR: share name %s is already a valid " + "system user name.\n", sharename); + goto done; + } + + if (strequal(sharename, GLOBAL_NAME)) { + d_fprintf(stderr, + "ERROR: 'global' is not a valid share name.\n"); + goto done; + } + + /* validate path */ + + if (path[0] != '/') { + d_fprintf(stderr, + "Error: path '%s' is not an absolute path.\n", + path); + goto done; + } + + if (sys_stat(path, &sbuf) != 0) { + d_fprintf(stderr, + "ERROR: cannot stat path '%s' to ensure " + "this is a directory.\n" + "Error was '%s'.\n", + path, strerror(errno)); + goto done; + } + + if (!S_ISDIR(sbuf.st_mode)) { + d_fprintf(stderr, + "ERROR: path '%s' is not a directory.\n", + path); + goto done; + } + + /* + * create the share + */ + + werr = reg_createkey_internal(NULL, argv[0], &newkey); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + /* add config params as values */ + + werr = reg_setvalue_internal(newkey, "path", "sz", path); + if (!W_ERROR_IS_OK(werr)) + goto done; + + if (comment != NULL) { + werr = reg_setvalue_internal(newkey, "comment", "sz", comment); + if (!W_ERROR_IS_OK(werr)) + goto done; + } + + werr = reg_setvalue_internal(newkey, "guest ok", "sz", guest_ok); + if (!W_ERROR_IS_OK(werr)) + goto done; + + werr = reg_setvalue_internal(newkey, "writeable", "sz", writeable); + if (!W_ERROR_IS_OK(werr)) + goto done; + + ret = 0; + +done: + TALLOC_FREE(newkey); + SAFE_FREE(sharename); + return ret; +} + +int net_conf_delshare(int argc, const char **argv) +{ + int ret = -1; + const char *sharename = NULL; + + if (argc != 1) { + net_conf_delshare_usage(argc, argv); + goto done; + } + sharename = argv[0]; + + if (W_ERROR_IS_OK(reg_delkey_internal(NULL, sharename))) { + ret = 0; + } +done: + return ret; +} + +static int net_conf_setparm(int argc, const char **argv) +{ + int ret = -1; + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + char *service = NULL; + char *param = NULL; + char *type = NULL; + const char *value_str = NULL; + TALLOC_CTX *ctx; + + ctx = talloc_init("setparm"); + + if (argc != 4) { + net_conf_setparm_usage(argc, argv); + goto done; + } + service = strdup_lower(argv[0]); + param = strdup_lower(argv[1]); + type = strdup_lower(argv[2]); + value_str = argv[3]; + + if (!smbconf_key_exists(ctx, service)) { + werr = reg_createkey_internal(ctx, service, &key); + } + else { + werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); + } + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_setvalue_internal(key, param, type, value_str); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error setting value '%s': %s\n", + param, dos_errstr(werr)); + goto done; + } + + + ret = 0; + +done: + SAFE_FREE(service); + TALLOC_FREE(ctx); + return ret; +} + +static int net_conf_getparm(int argc, const char **argv) +{ + int ret = -1; + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + char *service = NULL; + char *param = NULL; + struct registry_value *value = NULL; + TALLOC_CTX *ctx; + + ctx = talloc_init("getparm"); + + if (argc != 2) { + net_conf_getparm_usage(argc, argv); + goto done; + } + service = strdup_lower(argv[0]); + param = strdup_lower(argv[1]); + + if (!smbconf_key_exists(ctx, service)) { + d_fprintf(stderr, + "ERROR: given service '%s' does not exist.\n", + service); + goto done; + } + + werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_queryvalue(ctx, key, param, &value); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error querying value '%s': %s.\n", + param, dos_errstr(werr)); + goto done; + } + + d_printf("%s\n", format_value(ctx, value)); + + ret = 0; +done: + SAFE_FREE(service); + SAFE_FREE(param); + TALLOC_FREE(ctx); + return ret; +} + +static int net_conf_delparm(int argc, const char **argv) +{ + int ret = -1; + WERROR werr = WERR_OK; + struct registry_key *key = NULL; + char *service = NULL; + char *param = NULL; + TALLOC_CTX *ctx; + + ctx = talloc_init("delparm"); + + if (argc != 2) { + net_conf_delparm_usage(argc, argv); + goto done; + } + service = strdup_lower(argv[0]); + param = strdup_lower(argv[1]); + + if (!smbconf_key_exists(ctx, service)) { + d_fprintf(stderr, + "Error: given service '%s' does not exist.\n", + service); + goto done; + } + + werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (!smbconf_value_exists(ctx, key, param)) { + d_fprintf(stderr, + "Error: given parameter '%s' is not set.\n", + param); + goto done; + } + werr = reg_deletevalue(key, param); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error deleting value '%s': %s.\n", + param, dos_errstr(werr)); + goto done; + } + + ret = 0; + +done: + return ret; +} + +/* + * Entry-point for all the CONF functions. + */ + +int net_conf(int argc, const char **argv) +{ + int ret = -1; + int saved_errno = 0; + struct functable2 func[] = { + {"list", net_conf_list, + "Dump the complete configuration in smb.conf like format."}, + {"import", net_conf_import, + "Import configuration from file in smb.conf format."}, + {"listshares", net_conf_listshares, + "List the registry shares."}, + {"showshare", net_conf_showshare, + "Show the definition of a registry share."}, + {"addshare", net_conf_addshare, + "Create a new registry share."}, + {"delshare", net_conf_delshare, + "Delete a registry share."}, + {"setparm", net_conf_setparm, + "Store a parameter."}, + {"getparm", net_conf_getparm, + "Retrieve the value of a parameter."}, + {"delparm", net_conf_delparm, + "Delete a parameter."}, + {NULL, NULL, NULL} + }; + + REGISTRY_HOOK smbconf_reg_hook = {KEY_SMBCONF, &smbconf_reg_ops}; + + if (!regdb_init()) { + saved_errno = errno; + d_fprintf(stderr, "Can't open the registry"); + if (saved_errno) { + d_fprintf(stderr, ": %s\n", strerror(saved_errno)); + } + else { + d_fprintf(stderr, "!\n"); + } + goto done; + } + reghook_cache_init(); + reghook_cache_add(&smbconf_reg_hook); + + ret = net_run_function2(argc, argv, "net conf", func); + + regdb_close(); + +done: + return ret; +} + +/* END */ -- cgit From 6090601c8b6abde1642906351d1dd9bb41e576b6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 14 Jun 2007 11:29:35 +0000 Subject: r23485: This checkin consists mostly of refactorings in preparation of the activation of global registry options in loadparm.c, mainly to extract functionality from net_conf.c to be made availabel elsewhere and to minimize linker dependencies. In detail: * move functions registry_push/pull_value from lib/util_reg.c to new file lib/util_reg_api.c * create a fake user token consisting of builtin administrators sid and se_disk_operators privilege by hand instead of using get_root_nt_token() to minimize linker deps for bin/net. + new function registry_create_admin_token() in new lib/util_reg_smbconf.c + move dup_nt_token from auth/token_util.c to new file lib/util_nttoken.c + adapt net_conf.c and Makefile.in accordingly. * split lib/profiles.c into two parts: new file lib/profiles_basic.c takes all the low level mask manipulation and format conversion functions (se_priv, privset, luid). the privs array is completely hidden from profiles.c by adding some access-functions. some mask-functions are not static anymore. Generally, SID- and LUID-related stuff that has more dependencies is kept in lib/profiles.c * Move initialization of regdb from net_conf.c into a function registry_init_regdb() in lib/util_reg_smbconf.c. Michael (This used to be commit efd3e2bfb756ac5c4df7984791c67e7ae20a582e) --- source3/utils/net_conf.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 7d8849a99a..605ad3fdd2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -38,8 +38,6 @@ #include "includes.h" #include "utils/net.h" -extern REGISTRY_OPS smbconf_reg_ops; - /* * usage functions */ @@ -138,7 +136,7 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) } break; } - case REG_BINARY: + case REG_BINARY: result = talloc_asprintf(mem_ctx, "binary (%d bytes)", (int)value->v.binary.length); break; @@ -198,6 +196,12 @@ static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname, { WERROR werr = WERR_OK; char *path = NULL; + NT_USER_TOKEN *token; + + if (!(token = registry_create_admin_token(ctx))) { + DEBUG(1, ("Error creating admin token\n")); + goto done; + } if (subkeyname == NULL) { path = talloc_strdup(ctx, KEY_SMBCONF); @@ -207,8 +211,9 @@ static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname, } werr = reg_open_path(ctx, path, desired_access, - get_root_nt_token(), key); + token, key); +done: TALLOC_FREE(path); return werr; } @@ -1068,7 +1073,6 @@ done: int net_conf(int argc, const char **argv) { int ret = -1; - int saved_errno = 0; struct functable2 func[] = { {"list", net_conf_list, "Dump the complete configuration in smb.conf like format."}, @@ -1091,21 +1095,10 @@ int net_conf(int argc, const char **argv) {NULL, NULL, NULL} }; - REGISTRY_HOOK smbconf_reg_hook = {KEY_SMBCONF, &smbconf_reg_ops}; - - if (!regdb_init()) { - saved_errno = errno; - d_fprintf(stderr, "Can't open the registry"); - if (saved_errno) { - d_fprintf(stderr, ": %s\n", strerror(saved_errno)); - } - else { - d_fprintf(stderr, "!\n"); - } + if (!registry_init_regdb()) { + d_fprintf(stderr, "Error initializing the registry!\n"); goto done; } - reghook_cache_init(); - reghook_cache_add(&smbconf_reg_hook); ret = net_run_function2(argc, argv, "net conf", func); -- cgit From ac1a7e2f9600b192c18e836bb6286b74156fffcc Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 19 Jun 2007 11:11:01 +0000 Subject: r23543: Adjust comments. (This used to be commit ec22c30581f0809b6a008982abceb97b4f9cd12e) --- source3/utils/net_conf.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 605ad3fdd2..15b67b3856 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -20,19 +20,9 @@ */ /* - * This currently only an interface to the configuration - * stored inside the samba registry. In the future there - * might be support for other configuration backends as well. - */ - -/* - * TODO: - * - * - check uid 0 for write operations - * - check for valid parameter names and types (loadparm...) ??? - * - check for correctness of shares (service_ok) ? - * - refactor to use _internal functions for pieces of code - * + * This is an interface to the configuration stored inside the + * samba registry. In the future there might be support for other + * configuration backends as well. */ #include "includes.h" -- cgit From 3b9e5d0b4f6fb010fe227dcf303fa612189dee8e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 19 Jun 2007 21:40:27 +0000 Subject: r23549: Make "net conf setparm" always use registry data type "sz". This simplifies the usage of this command from "net conf setparm
" to "net conf setparm
". Micheal (This used to be commit 41a8f8ec5f5361f536d047c4ca5d90203b16ff06) --- source3/utils/net_conf.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 15b67b3856..23a6c9fa8f 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -82,8 +82,7 @@ static int net_conf_delshare_usage(int argc, const char **argv) static int net_conf_setparm_usage(int argc, const char **argv) { - d_printf("USAGE: net conf setparm
\n" - "\t(Supported types are 'dword' and 'sz' by now.)\n"); + d_printf("USAGE: net conf setparm
\n"); return -1; } @@ -918,20 +917,18 @@ static int net_conf_setparm(int argc, const char **argv) struct registry_key *key = NULL; char *service = NULL; char *param = NULL; - char *type = NULL; const char *value_str = NULL; TALLOC_CTX *ctx; ctx = talloc_init("setparm"); - if (argc != 4) { + if (argc != 3) { net_conf_setparm_usage(argc, argv); goto done; } service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - type = strdup_lower(argv[2]); - value_str = argv[3]; + value_str = argv[2]; if (!smbconf_key_exists(ctx, service)) { werr = reg_createkey_internal(ctx, service, &key); @@ -943,7 +940,7 @@ static int net_conf_setparm(int argc, const char **argv) goto done; } - werr = reg_setvalue_internal(key, param, type, value_str); + werr = reg_setvalue_internal(key, param, "sz", value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", param, dos_errstr(werr)); -- cgit From cc4f37f92820a5092d17e7b2e2b349644a0820d5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 22 Jun 2007 11:43:50 +0000 Subject: r23585: Add a "drop" function to "net conf" that clears the whole configuration stored in registry. Michael (This used to be commit 6d8973762ef2773ec64ed790f900253120e00d38) --- source3/utils/net_conf.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 23a6c9fa8f..8a906a6c27 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -54,6 +54,12 @@ static int net_conf_listshares_usage(int argc, const char **argv) return -1; } +static int net_conf_drop_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf drop\n"); + return -1; +} + static int net_conf_showshare_usage(int argc, const char **argv) { d_printf("USAGE: net conf showshare \n"); @@ -368,6 +374,56 @@ done: return werr; } +static WERROR drop_smbconf_internal(TALLOC_CTX *ctx) +{ + char *path, *p; + WERROR werr = WERR_OK; + NT_USER_TOKEN *token; + struct registry_key *parent_key = NULL; + struct registry_key *new_key = NULL; + TALLOC_CTX* tmp_ctx = NULL; + enum winreg_CreateAction action; + + tmp_ctx = talloc_new(ctx); + if (tmp_ctx == NULL) { + werr = WERR_NOMEM; + goto done; + } + + if (!(token = registry_create_admin_token(tmp_ctx))) { + /* what is the appropriate error code here? */ + werr = WERR_CAN_NOT_COMPLETE; + goto done; + } + + path = talloc_strdup(tmp_ctx, KEY_SMBCONF); + if (path == NULL) { + d_fprintf(stderr, "ERROR: out of memory!\n"); + werr = WERR_NOMEM; + goto done; + } + p = strrchr(path, '\\'); + *p = '\0'; + werr = reg_open_path(tmp_ctx, path, REG_KEY_WRITE, token, &parent_key); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_deletekey_recursive(tmp_ctx, parent_key, p+1); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE, + &new_key, &action); + +done: + TALLOC_FREE(tmp_ctx); + return werr; +} + static int import_process_service(TALLOC_CTX *ctx, struct share_params *share) { @@ -708,6 +764,29 @@ done: return ret; } +int net_conf_drop(int argc, const char **argv) +{ + int ret = -1; + WERROR werr; + + if (argc != 0) { + net_conf_drop_usage(argc, argv); + goto done; + } + + werr = drop_smbconf_internal(NULL); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error deleting configuration: %s\n", + dos_errstr(werr)); + goto done; + } + + ret = 0; + +done: + return ret; +} + int net_conf_showshare(int argc, const char **argv) { int ret = -1; @@ -1067,6 +1146,8 @@ int net_conf(int argc, const char **argv) "Import configuration from file in smb.conf format."}, {"listshares", net_conf_listshares, "List the registry shares."}, + {"drop", net_conf_drop, + "Delete the complete configuration from registry."}, {"showshare", net_conf_showshare, "Show the definition of a registry share."}, {"addshare", net_conf_addshare, -- cgit From 3163aff376be5dbda5ce38dbc07765a25854434b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 29 Jun 2007 10:22:18 +0000 Subject: r23652: Use the recursive delete function instead of the original one when deleting a share. Just to be sure... Michael (This used to be commit 91770e153d7dd87d5e4f0516c297812091ba5b5a) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8a906a6c27..b9b693d8d5 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -256,7 +256,7 @@ static WERROR reg_delkey_internal(TALLOC_CTX *ctx, const char *keyname) goto done; } - werr = reg_deletekey(key, keyname); + werr = reg_deletekey_recursive(key, key, keyname); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting registry key %s\\%s: %s\n", KEY_SMBCONF, keyname, dos_errstr(werr)); -- cgit From 96c4bf4a1c70e080107e954ea09dbe0a9709ae4f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 29 Jun 2007 12:15:41 +0000 Subject: r23655: Fix a comment and adjust some code formatting. Michael (This used to be commit b294bc707c2a7ef3ff5efcac1d5ea6f3d80f5a70) --- source3/utils/net_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index b9b693d8d5..021ac0005d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -145,7 +145,7 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) /* * add a value to a key. */ -static WERROR reg_setvalue_internal(struct registry_key *key, +static WERROR reg_setvalue_internal(struct registry_key *key, const char *valname, const char *valtype, const char *valstr) @@ -165,7 +165,8 @@ static WERROR reg_setvalue_internal(struct registry_key *key, val.v.sz.len = strlen(valstr) + 1; } else { - d_fprintf(stderr, "Sorry, only value types DWORD and SZ implementd currently for setting values.\n"); + d_fprintf(stderr, "Only value types DWORD and SZ are" + "currently implemented for setting values.\n"); goto done; } -- cgit From 20733036644c11a6b4fa7466f9a5b3aa1cae3916 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 29 Jun 2007 12:30:41 +0000 Subject: r23656: Add initial checking of the validity of a paramter given to "net conf setparm". Add a utility function lp_parameter_valid() for this to loadparm.c. Michael (This used to be commit 639051e58d4da9fb1116c19f0790250640b6ac7a) --- source3/utils/net_conf.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 021ac0005d..5af2d6ccc5 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -167,6 +167,20 @@ static WERROR reg_setvalue_internal(struct registry_key *key, else { d_fprintf(stderr, "Only value types DWORD and SZ are" "currently implemented for setting values.\n"); + werr = WERR_INVALID_PARAM; + goto done; + } + + if (!lp_parameter_valid(valname)) { + d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname); + werr = WERR_INVALID_PARAM; + goto done; + } + + if (registry_smbconf_valname_forbidden(valname)) { + d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n", + valname); + werr = WERR_INVALID_PARAM; goto done; } -- cgit From e388130aa63b9bbe1b27999aad6052585fc2e16b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 29 Jun 2007 13:07:54 +0000 Subject: r23657: Prevent setting of a global option in a share definition in "net conf setparm". Michael (This used to be commit bf92d567984f00ebb998fb2485d0aac87d30b924) --- source3/utils/net_conf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 5af2d6ccc5..1c61a25ee9 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -178,12 +178,21 @@ static WERROR reg_setvalue_internal(struct registry_key *key, } if (registry_smbconf_valname_forbidden(valname)) { - d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n", + d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n", valname); werr = WERR_INVALID_PARAM; goto done; } + if (!strequal(key->key->name, GLOBAL_NAME) && + lp_parameter_is_global(valname)) + { + d_fprintf(stderr, "Global paramter '%s' not allowed in " + "service definition.\n", valname); + werr = WERR_INVALID_PARAM; + goto done; + } + werr = reg_setvalue(key, valname, &val); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, -- cgit From f26abd78b17a4fc1ee3e05dd8fd89d7ae61aabad Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 30 Jun 2007 21:35:39 +0000 Subject: r23666: Rename lp_parameter_valid -> lp_parameter_is_valid. Michael (This used to be commit 7f85cff49dfe1ae90e37162d35f1a48baaa9fe79) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 1c61a25ee9..9888d1f548 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -171,7 +171,7 @@ static WERROR reg_setvalue_internal(struct registry_key *key, goto done; } - if (!lp_parameter_valid(valname)) { + if (!lp_parameter_is_valid(valname)) { d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname); werr = WERR_INVALID_PARAM; goto done; -- cgit From ea78cb941acac7c76318464baba618fe79b2e196 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 20:40:59 +0000 Subject: r23744: Remove TODO-comment. lp_load returns False if opening of the config file fails. That's enough of checking for existence and readbility to my taste. Michael (This used to be commit 204f4f1a94a6693ab5d92df0de48e6cb446c7a7f) --- source3/utils/net_conf.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9888d1f548..c65b57817b 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -690,8 +690,6 @@ int net_conf_import(int argc, const char **argv) DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - /* TODO: check for existence and readability */ - if (!lp_load(filename, False, /* global_only */ True, /* save_defaults */ -- cgit From f7b8a3782a7c28147f4e54c35b02a39d6b2bd879 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 21:33:48 +0000 Subject: r23745: Fix: Check whether top subkeyname instead of whole registry key name is equal to GLOBAL_NAME. Michael (This used to be commit fdcdcacf0a9513829ad474605879ef55ce8b389e) --- source3/utils/net_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c65b57817b..6f23a00177 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -184,11 +184,12 @@ static WERROR reg_setvalue_internal(struct registry_key *key, goto done; } - if (!strequal(key->key->name, GLOBAL_NAME) && + if (!strequal(strrchr_m(key->key->name, '\\')+1, GLOBAL_NAME) && lp_parameter_is_global(valname)) { d_fprintf(stderr, "Global paramter '%s' not allowed in " - "service definition.\n", valname); + "service definition ('%s').\n", valname, + strrchr_m(key->key->name, '\\')+1); werr = WERR_INVALID_PARAM; goto done; } -- cgit From feff1fcfd8844859b339bc14c2fe4650b3784fe4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 21:41:59 +0000 Subject: r23746: Fix missing assignments to target string of asprintf in import function. Michael (This used to be commit 6b1bf7c1f49f737ca3cbee96b184e3b21fdc4931) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 6f23a00177..febc8dc9e1 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -527,7 +527,7 @@ static int import_process_service(TALLOC_CTX *ctx, } break; case P_OCTAL: - talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); + valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); break; case P_LIST: valstr = talloc_strdup(ctx, ""); @@ -553,7 +553,7 @@ static int import_process_service(TALLOC_CTX *ctx, break; case P_INTEGER: valtype = "dword"; - talloc_asprintf(ctx, "%d", *(int *)ptr); + valstr = talloc_asprintf(ctx, "%d", *(int *)ptr); break; case P_SEP: break; -- cgit From c2c96bccda2b5dd9c3991ee54426f27b88812d3c Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 22:18:54 +0000 Subject: r23747: Move formatting of a parameter's value into a value string to a function of its own. (for storing it in registry), Eliminate the valtype variable : store everything as "sz". Eliminate some trailing white spaces on the way. Michael (This used to be commit 76f4f224aa65b1414222818996e215ec80d117a4) --- source3/utils/net_conf.c | 162 ++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 80 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index febc8dc9e1..d05a36f44d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -449,7 +449,84 @@ done: return werr; } -static int import_process_service(TALLOC_CTX *ctx, +static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, + struct share_params *share) +{ + char *valstr = NULL; + int i = 0; + void *ptr = parm->ptr; + + if (parm->p_class == P_LOCAL && share->service >= 0) { + ptr = lp_local_ptr(share->service, ptr); + } + + switch (parm->type) { + case P_CHAR: + valstr = talloc_asprintf(ctx, "%c", *(char *)ptr); + break; + case P_STRING: + case P_USTRING: + valstr = talloc_asprintf(ctx, "%s", *(char **)ptr); + break; + case P_GSTRING: + case P_UGSTRING: + valstr = talloc_asprintf(ctx, "%s", (char *)ptr); + break; + case P_BOOL: + valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(BOOL *)ptr)); + break; + case P_BOOLREV: + valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(BOOL *)ptr)); + break; + case P_ENUM: + for (i = 0; parm->enum_list[i].name; i++) { + if (*(int *)ptr == parm->enum_list[i].value) + { + valstr = talloc_asprintf(ctx, "%s", + parm->enum_list[i].name); + break; + } + } + break; + case P_OCTAL: + valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); + break; + case P_LIST: + valstr = talloc_strdup(ctx, ""); + if ((char ***)ptr && *(char ***)ptr) { + char **list = *(char ***)ptr; + for (; *list; list++) { + /* surround strings with whitespace + * in double quotes */ + if (strchr_m(*list, ' ')) + { + valstr = talloc_asprintf_append( + valstr, "\"%s\"%s", + *list, + ((*(list+1))?", ":"")); + } + else { + valstr = talloc_asprintf_append( + valstr, "%s%s", *list, + ((*(list+1))?", ":"")); + } + } + } + break; + case P_INTEGER: + valstr = talloc_asprintf(ctx, "%d", *(int *)ptr); + break; + case P_SEP: + break; + default: + valstr = talloc_asprintf(ctx, "\n"); + break; + } + + return valstr; +} + +static int import_process_service(TALLOC_CTX *ctx, struct share_params *share) { int ret = -1; @@ -458,7 +535,6 @@ static int import_process_service(TALLOC_CTX *ctx, const char *servicename; struct registry_key *key; WERROR werr; - const char *valtype = NULL; char *valstr = NULL; servicename = (share->service == GLOBAL_SECTION_SNUM)? @@ -482,93 +558,19 @@ static int import_process_service(TALLOC_CTX *ctx, while ((parm = lp_next_parameter(share->service, &pnum, 0))) { - void *ptr = parm->ptr; - int i = 0; - - if ((share->service < 0 && parm->p_class == P_LOCAL) + if ((share->service < 0 && parm->p_class == P_LOCAL) && !(parm->flags & FLAG_GLOBAL)) continue; - if (parm->p_class == P_LOCAL && share->service >= 0) { - ptr = lp_local_ptr(share->service, ptr); - } - - valtype = "sz"; - - switch (parm->type) { - case P_CHAR: - valstr = talloc_asprintf(ctx, "%c", *(char *)ptr); - break; - case P_STRING: - case P_USTRING: - valstr = talloc_asprintf(ctx, "%s", *(char **)ptr); - break; - case P_GSTRING: - case P_UGSTRING: - valstr = talloc_asprintf(ctx, "%s", (char *)ptr); - break; - case P_BOOL: - valstr = talloc_asprintf(ctx, "%s", - BOOLSTR(*(BOOL *)ptr)); - break; - case P_BOOLREV: - valstr = talloc_asprintf(ctx, "%s", - BOOLSTR(!*(BOOL *)ptr)); - break; - case P_ENUM: - for (i = 0; parm->enum_list[i].name; i++) { - if (*(int *)ptr == - parm->enum_list[i].value) - { - valstr = talloc_asprintf(ctx, "%s", - parm->enum_list[i].name); - break; - } - } - break; - case P_OCTAL: - valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); - break; - case P_LIST: - valstr = talloc_strdup(ctx, ""); - if ((char ***)ptr && *(char ***)ptr) { - char **list = *(char ***)ptr; - for (; *list; list++) { - /* surround strings with whitespace - * in double quotes */ - if (strchr_m(*list, ' ')) - { - valstr = talloc_asprintf_append( - valstr, "\"%s\"%s", - *list, - ((*(list+1))?", ":"")); - } - else { - valstr = talloc_asprintf_append( - valstr, "%s%s", *list, - ((*(list+1))?", ":"")); - } - } - } - break; - case P_INTEGER: - valtype = "dword"; - valstr = talloc_asprintf(ctx, "%d", *(int *)ptr); - break; - case P_SEP: - break; - default: - valstr = talloc_asprintf(ctx, "\n"); - break; - } + valstr = parm_valstr(ctx, parm, share); if (parm->type != P_SEP) { if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); } else { - werr = reg_setvalue_internal(key, parm->label, - valtype, valstr); + werr = reg_setvalue_internal(key, parm->label, + "sz", valstr); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From cba898808e4caf7f7f622dcd9124e115babf5f5a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 22:29:34 +0000 Subject: r23748: Clean use of talloc in import_process_service: create a temporary talloc ctx for the function. Michael (This used to be commit 39df7faaa9472d565653b36203860eee8a259f2c) --- source3/utils/net_conf.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index d05a36f44d..f06a5f660d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -536,6 +536,13 @@ static int import_process_service(TALLOC_CTX *ctx, struct registry_key *key; WERROR werr; char *valstr = NULL; + TALLOC_CTX *tmp_ctx = NULL; + + tmp_ctx = talloc_new(ctx); + if (tmp_ctx == NULL) { + werr = WERR_NOMEM; + goto done; + } servicename = (share->service == GLOBAL_SECTION_SNUM)? GLOBAL_NAME : lp_servicename(share->service); @@ -544,13 +551,13 @@ static int import_process_service(TALLOC_CTX *ctx, d_printf("[%s]\n", servicename); } else { - if (smbconf_key_exists(ctx, servicename)) { - werr = reg_delkey_internal(ctx, servicename); + if (smbconf_key_exists(tmp_ctx, servicename)) { + werr = reg_delkey_internal(tmp_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = reg_createkey_internal(ctx, servicename, &key); + werr = reg_createkey_internal(tmp_ctx, servicename, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -562,7 +569,7 @@ static int import_process_service(TALLOC_CTX *ctx, && !(parm->flags & FLAG_GLOBAL)) continue; - valstr = parm_valstr(ctx, parm, share); + valstr = parm_valstr(tmp_ctx, parm, share); if (parm->type != P_SEP) { if (opt_testmode) { @@ -583,7 +590,9 @@ static int import_process_service(TALLOC_CTX *ctx, } ret = 0; + done: + TALLOC_FREE(tmp_ctx); return ret; } -- cgit From 1bea19c1273bdf934663afc0ba63c3873a2fa303 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 22:33:45 +0000 Subject: r23749: Simplify prototype of reg_setvalue_internal: eliminate "type" parameter since we store only REG_SZ. Michael (This used to be commit 65ce4633171eabd6fc94677cb7d884d6125d0745) --- source3/utils/net_conf.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f06a5f660d..9d4f4601e4 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -147,7 +147,6 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) */ static WERROR reg_setvalue_internal(struct registry_key *key, const char *valname, - const char *valtype, const char *valstr) { struct registry_value val; @@ -155,21 +154,9 @@ static WERROR reg_setvalue_internal(struct registry_key *key, ZERO_STRUCT(val); - if (strequal(valtype, "dword")) { - val.type = REG_DWORD; - val.v.dword = strtoul(valstr, NULL, 10); - } - else if (strequal(valtype, "sz")) { - val.type = REG_SZ; - val.v.sz.str = CONST_DISCARD(char *, valstr); - val.v.sz.len = strlen(valstr) + 1; - } - else { - d_fprintf(stderr, "Only value types DWORD and SZ are" - "currently implemented for setting values.\n"); - werr = WERR_INVALID_PARAM; - goto done; - } + val.type = REG_SZ; + val.v.sz.str = CONST_DISCARD(char *, valstr); + val.v.sz.len = strlen(valstr) + 1; if (!lp_parameter_is_valid(valname)) { d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname); @@ -577,7 +564,7 @@ static int import_process_service(TALLOC_CTX *ctx, } else { werr = reg_setvalue_internal(key, parm->label, - "sz", valstr); + valstr); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -979,21 +966,21 @@ int net_conf_addshare(int argc, const char **argv) /* add config params as values */ - werr = reg_setvalue_internal(newkey, "path", "sz", path); + werr = reg_setvalue_internal(newkey, "path", path); if (!W_ERROR_IS_OK(werr)) goto done; if (comment != NULL) { - werr = reg_setvalue_internal(newkey, "comment", "sz", comment); + werr = reg_setvalue_internal(newkey, "comment", comment); if (!W_ERROR_IS_OK(werr)) goto done; } - werr = reg_setvalue_internal(newkey, "guest ok", "sz", guest_ok); + werr = reg_setvalue_internal(newkey, "guest ok", guest_ok); if (!W_ERROR_IS_OK(werr)) goto done; - werr = reg_setvalue_internal(newkey, "writeable", "sz", writeable); + werr = reg_setvalue_internal(newkey, "writeable", writeable); if (!W_ERROR_IS_OK(werr)) goto done; @@ -1053,7 +1040,7 @@ static int net_conf_setparm(int argc, const char **argv) goto done; } - werr = reg_setvalue_internal(key, param, "sz", value_str); + werr = reg_setvalue_internal(key, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", param, dos_errstr(werr)); -- cgit From a5946cb46af25ef43d0d554a81f114b85a882190 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 7 Jul 2007 23:57:25 +0000 Subject: r23750: Change the behaviour of net conf import when there is a global section in the current registry and there is no global section in the input file (or only global options with default values): In that case the existing global section is now not touched. Before, it would have been deleted and recreated empty. The new behaviour is how other shares are treated too. Note that since the input file is parsed by lp_load, there is currently no way to distinguish between a section with only default parameters and a non-existing section in net conf import. Michael PS: A couple of trailing white-spaces have been eliminated and a line was broken to be not longer than 80 chars, too. (This used to be commit ec21a0cf9f01986d333b50b883f2105e32cf7fc9) --- source3/utils/net_conf.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9d4f4601e4..4990541384 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -583,6 +583,19 @@ done: return ret; } +/* return True iff there are nondefault globals */ +static BOOL globals_exist(void) +{ + int i = 0; + struct parm_struct *parm; + + while ((parm = lp_next_parameter(GLOBAL_SECTION_SNUM, &i, 0)) != NULL) { + if (parm->type != P_SEP) { + return True; + } + } + return False; +} /* * the conf functions @@ -689,7 +702,7 @@ int net_conf_import(int argc, const char **argv) DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - if (!lp_load(filename, + if (!lp_load(filename, False, /* global_only */ True, /* save_defaults */ False, /* add_ipc */ @@ -700,10 +713,13 @@ int net_conf_import(int argc, const char **argv) } if (opt_testmode) { - d_printf("\nTEST MODE - would import the following configuration:\n\n"); + d_printf("\nTEST MODE - " + "would import the following configuration:\n\n"); } - if ((servicename == NULL) || strequal(servicename, GLOBAL_NAME)) { + if (((servicename == NULL) && globals_exist()) || + strequal(servicename, GLOBAL_NAME)) + { service_found = True; if (import_process_service(ctx, &global_share) != 0) { goto done; @@ -720,8 +736,8 @@ int net_conf_import(int argc, const char **argv) goto done; } while ((share = next_share(shares)) != NULL) { - if ((servicename == NULL) - || strequal(servicename, lp_servicename(share->service))) + if ((servicename == NULL) + || strequal(servicename, lp_servicename(share->service))) { service_found = True; if (import_process_service(ctx, share)!= 0) { @@ -729,16 +745,16 @@ int net_conf_import(int argc, const char **argv) } } } - + if ((servicename != NULL) && !service_found) { - d_printf("Share %s not found in file %s\n", + d_printf("Share %s not found in file %s\n", servicename, filename); goto done; } ret = 0; - + done: TALLOC_FREE(ctx); return ret; -- cgit From d4f1b08c935cc5c2c7509c50334d3b3f6cc3b371 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 9 Jul 2007 09:35:03 +0000 Subject: r23760: Untangle use of strrchr_m and strequal and add some checks for the validity of the given registry key name. Michael (This used to be commit 4b4ba7724ee77a93e32cd7f3c5884d965fe9bcaa) --- source3/utils/net_conf.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 4990541384..61bcb60aaf 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -151,6 +151,7 @@ static WERROR reg_setvalue_internal(struct registry_key *key, { struct registry_value val; WERROR werr = WERR_OK; + char *subkeyname; ZERO_STRUCT(val); @@ -171,12 +172,20 @@ static WERROR reg_setvalue_internal(struct registry_key *key, goto done; } - if (!strequal(strrchr_m(key->key->name, '\\')+1, GLOBAL_NAME) && + subkeyname = strrchr_m(key->key->name, '\\'); + if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) { + d_fprintf(stderr, "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)) { d_fprintf(stderr, "Global paramter '%s' not allowed in " "service definition ('%s').\n", valname, - strrchr_m(key->key->name, '\\')+1); + subkeyname); werr = WERR_INVALID_PARAM; goto done; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 61bcb60aaf..72314afffd 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -6,7 +6,7 @@ * * 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 2 of the License, or + * 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, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/utils/net_conf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 72314afffd..bcb116a0c8 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -15,8 +15,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ /* -- cgit From 53f5c4adfbf12fbf6f25eab3260d22a2d7c3efbe Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 16 Aug 2007 15:32:00 +0000 Subject: r24496: Add initial synonym handling to "net conf": When storing parameters in the smbconf portion of the registry, up to now, synonyms could be misused to store a parameter twice. Now this is prevented by canonicalizing the paramter name first. Also, the value for a boolean parameter checked for validity before storing the bool in registry. (The canonicalization should finally go into the registry smbconf code to also prevent e.g. "regedit" or "net rpc registry" from storing synonyms. - This is in the making.) Michael (This used to be commit 95447dde860f54d835b3fe90d95fe60231788d1b) --- source3/utils/net_conf.c | 56 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index bcb116a0c8..f7385586fb 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -151,12 +151,10 @@ static WERROR reg_setvalue_internal(struct registry_key *key, struct registry_value val; WERROR werr = WERR_OK; char *subkeyname; - - ZERO_STRUCT(val); - - val.type = REG_SZ; - val.v.sz.str = CONST_DISCARD(char *, valstr); - val.v.sz.len = strlen(valstr) + 1; + const char *canon_valname; + const char *canon_valstr; + BOOL canon_inverse; + struct parm_struct *parm; if (!lp_parameter_is_valid(valname)) { d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname); @@ -164,9 +162,45 @@ static WERROR reg_setvalue_internal(struct registry_key *key, goto done; } - if (registry_smbconf_valname_forbidden(valname)) { + if (!lp_canonicalize_parameter(valname, &canon_valname, &canon_inverse)) + { + d_fprintf(stderr, "ERROR: could not canonicalize parameter " + "'%s' after successful validation: this should not " + "happen!\n", valname); + werr = WERR_INVALID_PARAM; + goto done; + } + if (canon_inverse) { + if (!lp_invert_boolean(valstr, &canon_valstr)) { + d_fprintf(stderr, "invalid value '%s' given for " + "parameter '%s'\n", valstr, canon_valname); + werr = WERR_INVALID_PARAM; + goto done; + } + } else { + parm = lp_get_parameter(canon_valname); + if (parm->type == P_BOOL) { + if (!lp_canonicalize_boolean(valstr, &canon_valstr)) { + d_fprintf(stderr, "invalied value '%s' given " + "for parameter '%s'\n", valstr, + canon_valname); + werr = WERR_INVALID_PARAM; + goto done; + } + } else { + canon_valstr = valstr; + } + } + + 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)) { d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n", - valname); + canon_valname); werr = WERR_INVALID_PARAM; goto done; } @@ -183,18 +217,18 @@ static WERROR reg_setvalue_internal(struct registry_key *key, lp_parameter_is_global(valname)) { d_fprintf(stderr, "Global paramter '%s' not allowed in " - "service definition ('%s').\n", valname, + "service definition ('%s').\n", canon_valname, subkeyname); werr = WERR_INVALID_PARAM; goto done; } - werr = reg_setvalue(key, valname, &val); + werr = reg_setvalue(key, canon_valname, &val); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error adding value '%s' to " "key '%s': %s\n", - valname, key->key->name, dos_errstr(werr)); + canon_valname, key->key->name, dos_errstr(werr)); } done: -- cgit From 8b0b1408a08324aa08b77a8395781a3867b6f3b5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 17 Aug 2007 11:06:37 +0000 Subject: r24513: Reformatting: eliminate trailing spaces, overly long lines and adjust some formattings to standard. Michael (This used to be commit 00432bcd69bb1c30774af277af1dc7271380d75b) --- source3/utils/net_conf.c | 133 +++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 69 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f7385586fb..2f0b3d6b04 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -1,6 +1,6 @@ -/* - * Samba Unix/Linux SMB client library - * Distributed SMB/CIFS Server Management Utility +/* + * Samba Unix/Linux SMB client library + * Distributed SMB/CIFS Server Management Utility * Local configuration interface * Copyright (C) Michael Adam 2007 * @@ -8,26 +8,26 @@ * 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 . + * along with this program; if not, see . */ /* - * This is an interface to the configuration stored inside the - * samba registry. In the future there might be support for other + * This is an interface to the configuration stored inside the + * samba registry. In the future there might be support for other * configuration backends as well. */ #include "includes.h" #include "utils/net.h" -/* +/* * usage functions */ @@ -39,7 +39,8 @@ static int net_conf_list_usage(int argc, const char **argv) static int net_conf_import_usage(int argc, const char**argv) { - d_printf("USAGE: net conf import [--test|-T] []\n" + d_printf("USAGE: net conf import [--test|-T] " + "[]\n" "\t[--test|-T] testmode - do not act, just print " "what would be done\n" "\t only import service , " @@ -125,7 +126,7 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) case REG_MULTI_SZ: { uint32 j; for (j = 0; j < value->v.multi_sz.num_strings; j++) { - result = talloc_asprintf(mem_ctx, "\"%s\" ", + result = talloc_asprintf(mem_ctx, "\"%s\" ", value->v.multi_sz.strings[j]); } break; @@ -142,7 +143,7 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) } /* - * add a value to a key. + * add a value to a key. */ static WERROR reg_setvalue_internal(struct registry_key *key, const char *valname, @@ -235,12 +236,12 @@ done: return werr; } -/* +/* * Open a subkey of KEY_SMBCONF (i.e a service) * - variant without error output (q = quiet)- */ static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname, - uint32 desired_access, + uint32 desired_access, struct registry_key **key) { WERROR werr = WERR_OK; @@ -254,8 +255,7 @@ static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname, if (subkeyname == NULL) { path = talloc_strdup(ctx, KEY_SMBCONF); - } - else { + } else { path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, subkeyname); } @@ -267,12 +267,12 @@ done: return werr; } -/* +/* * Open a subkey of KEY_SMBCONF (i.e a service) * - variant with error output - */ static WERROR smbconf_open_path(TALLOC_CTX *ctx, const char *subkeyname, - uint32 desired_access, + uint32 desired_access, struct registry_key **key) { WERROR werr = WERR_OK; @@ -280,8 +280,8 @@ static WERROR smbconf_open_path(TALLOC_CTX *ctx, const char *subkeyname, werr = smbconf_open_path_q(ctx, subkeyname, desired_access, key); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error opening registry path '%s\\%s': %s\n", - KEY_SMBCONF, - (subkeyname == NULL) ? "" : subkeyname, + KEY_SMBCONF, + (subkeyname == NULL) ? "" : subkeyname, dos_errstr(werr)); } @@ -346,7 +346,7 @@ static WERROR reg_createkey_internal(TALLOC_CTX *ctx, goto done; } - werr = reg_createkey(ctx, create_parent, subkeyname, + werr = reg_createkey(ctx, create_parent, subkeyname, REG_KEY_WRITE, newkey, &action); if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) { d_fprintf(stderr, "Key '%s' already exists.\n", subkeyname); @@ -394,7 +394,7 @@ static BOOL smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key, WERROR werr = WERR_OK; struct registry_value *value = NULL; - werr = reg_queryvalue(ctx, key, param, &value); + werr = reg_queryvalue(ctx, key, param, &value); if (W_ERROR_IS_OK(werr)) { ret = True; } @@ -425,7 +425,7 @@ static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) werr = WERR_OK; done: - return werr; + return werr; } static WERROR drop_smbconf_internal(TALLOC_CTX *ctx) @@ -446,7 +446,7 @@ static WERROR drop_smbconf_internal(TALLOC_CTX *ctx) if (!(token = registry_create_admin_token(tmp_ctx))) { /* what is the appropriate error code here? */ - werr = WERR_CAN_NOT_COMPLETE; + werr = WERR_CAN_NOT_COMPLETE; goto done; } @@ -469,8 +469,8 @@ static WERROR drop_smbconf_internal(TALLOC_CTX *ctx) if (!W_ERROR_IS_OK(werr)) { goto done; } - - werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE, + + werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE, &new_key, &action); done: @@ -533,8 +533,7 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, valstr, "\"%s\"%s", *list, ((*(list+1))?", ":"")); - } - else { + } else { valstr = talloc_asprintf_append( valstr, "%s%s", *list, ((*(list+1))?", ":"")); @@ -578,8 +577,7 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); - } - else { + } else { if (smbconf_key_exists(tmp_ctx, servicename)) { werr = reg_delkey_internal(tmp_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { @@ -603,8 +601,7 @@ static int import_process_service(TALLOC_CTX *ctx, if (parm->type != P_SEP) { if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); - } - else { + } else { werr = reg_setvalue_internal(key, parm->label, valstr); if (!W_ERROR_IS_OK(werr)) { @@ -640,7 +637,7 @@ static BOOL globals_exist(void) } /* - * the conf functions + * the conf functions */ int net_conf_list(int argc, const char **argv) @@ -666,7 +663,7 @@ int net_conf_list(int argc, const char **argv) } if (smbconf_key_exists(ctx, GLOBAL_NAME)) { - werr = reg_openkey(ctx, base_key, GLOBAL_NAME, + werr = reg_openkey(ctx, base_key, GLOBAL_NAME, REG_KEY_READ, &sub_key); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error opening subkey '%s' : %s\n", @@ -683,17 +680,17 @@ int net_conf_list(int argc, const char **argv) for (idx_key = 0; W_ERROR_IS_OK(werr = reg_enumkey(ctx, base_key, idx_key, &subkey_name, NULL)); - idx_key++) + idx_key++) { if (strequal(subkey_name, GLOBAL_NAME)) { continue; } d_printf("[%s]\n", subkey_name); - werr = reg_openkey(ctx, base_key, subkey_name, + werr = reg_openkey(ctx, base_key, subkey_name, REG_KEY_READ, &sub_key); if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, + d_fprintf(stderr, "Error opening subkey '%s': %s\n", subkey_name, dos_errstr(werr)); goto done; @@ -704,7 +701,7 @@ int net_conf_list(int argc, const char **argv) d_printf("\n"); } if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - d_fprintf(stderr, "Error enumerating subkeys: %s\n", + d_fprintf(stderr, "Error enumerating subkeys: %s\n", dos_errstr(werr)); goto done; } @@ -826,12 +823,12 @@ int net_conf_listshares(int argc, const char **argv) for (idx = 0; W_ERROR_IS_OK(werr = reg_enumkey(ctx, key, idx, &subkey_name, NULL)); - idx++) + idx++) { d_printf("%s\n", subkey_name); } if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - d_fprintf(stderr, "Error enumerating subkeys: %s\n", + d_fprintf(stderr, "Error enumerating subkeys: %s\n", dos_errstr(werr)); goto done; } @@ -913,7 +910,7 @@ int net_conf_addshare(int argc, const char **argv) switch (argc) { case 0: case 1: - default: + default: net_conf_addshare_usage(argc, argv); goto done; case 5: @@ -932,7 +929,7 @@ int net_conf_addshare(int argc, const char **argv) case 'N': guest_ok = "no"; break; - default: + default: net_conf_addshare_usage(argc, argv); goto done; } @@ -961,14 +958,14 @@ int net_conf_addshare(int argc, const char **argv) break; } - /* - * validate arguments + /* + * validate arguments */ /* validate share name */ - if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS, - strlen(sharename))) + if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS, + strlen(sharename))) { d_fprintf(stderr, "ERROR: share name %s contains " "invalid characters (any of %s)\n", @@ -983,7 +980,7 @@ int net_conf_addshare(int argc, const char **argv) } if (strequal(sharename, GLOBAL_NAME)) { - d_fprintf(stderr, + d_fprintf(stderr, "ERROR: 'global' is not a valid share name.\n"); goto done; } @@ -991,7 +988,7 @@ int net_conf_addshare(int argc, const char **argv) /* validate path */ if (path[0] != '/') { - d_fprintf(stderr, + d_fprintf(stderr, "Error: path '%s' is not an absolute path.\n", path); goto done; @@ -1001,7 +998,7 @@ int net_conf_addshare(int argc, const char **argv) d_fprintf(stderr, "ERROR: cannot stat path '%s' to ensure " "this is a directory.\n" - "Error was '%s'.\n", + "Error was '%s'.\n", path, strerror(errno)); goto done; } @@ -1013,8 +1010,8 @@ int net_conf_addshare(int argc, const char **argv) goto done; } - /* - * create the share + /* + * create the share */ werr = reg_createkey_internal(NULL, argv[0], &newkey); @@ -1037,7 +1034,7 @@ int net_conf_addshare(int argc, const char **argv) werr = reg_setvalue_internal(newkey, "guest ok", guest_ok); if (!W_ERROR_IS_OK(werr)) goto done; - + werr = reg_setvalue_internal(newkey, "writeable", writeable); if (!W_ERROR_IS_OK(werr)) goto done; @@ -1060,7 +1057,7 @@ int net_conf_delshare(int argc, const char **argv) goto done; } sharename = argv[0]; - + if (W_ERROR_IS_OK(reg_delkey_internal(NULL, sharename))) { ret = 0; } @@ -1090,8 +1087,7 @@ static int net_conf_setparm(int argc, const char **argv) if (!smbconf_key_exists(ctx, service)) { werr = reg_createkey_internal(ctx, service, &key); - } - else { + } else { werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); } if (!W_ERROR_IS_OK(werr)) { @@ -1134,7 +1130,7 @@ static int net_conf_getparm(int argc, const char **argv) param = strdup_lower(argv[1]); if (!smbconf_key_exists(ctx, service)) { - d_fprintf(stderr, + d_fprintf(stderr, "ERROR: given service '%s' does not exist.\n", service); goto done; @@ -1151,9 +1147,9 @@ static int net_conf_getparm(int argc, const char **argv) param, dos_errstr(werr)); goto done; } - + d_printf("%s\n", format_value(ctx, value)); - + ret = 0; done: SAFE_FREE(service); @@ -1181,7 +1177,7 @@ static int net_conf_delparm(int argc, const char **argv) param = strdup_lower(argv[1]); if (!smbconf_key_exists(ctx, service)) { - d_fprintf(stderr, + d_fprintf(stderr, "Error: given service '%s' does not exist.\n", service); goto done; @@ -1193,7 +1189,7 @@ static int net_conf_delparm(int argc, const char **argv) } if (!smbconf_value_exists(ctx, key, param)) { - d_fprintf(stderr, + d_fprintf(stderr, "Error: given parameter '%s' is not set.\n", param); goto done; @@ -1219,25 +1215,25 @@ int net_conf(int argc, const char **argv) { int ret = -1; struct functable2 func[] = { - {"list", net_conf_list, + {"list", net_conf_list, "Dump the complete configuration in smb.conf like format."}, {"import", net_conf_import, "Import configuration from file in smb.conf format."}, - {"listshares", net_conf_listshares, + {"listshares", net_conf_listshares, "List the registry shares."}, {"drop", net_conf_drop, "Delete the complete configuration from registry."}, - {"showshare", net_conf_showshare, + {"showshare", net_conf_showshare, "Show the definition of a registry share."}, - {"addshare", net_conf_addshare, + {"addshare", net_conf_addshare, "Create a new registry share."}, - {"delshare", net_conf_delshare, + {"delshare", net_conf_delshare, "Delete a registry share."}, - {"setparm", net_conf_setparm, + {"setparm", net_conf_setparm, "Store a parameter."}, - {"getparm", net_conf_getparm, + {"getparm", net_conf_getparm, "Retrieve the value of a parameter."}, - {"delparm", net_conf_delparm, + {"delparm", net_conf_delparm, "Delete a parameter."}, {NULL, NULL, NULL} }; @@ -1255,4 +1251,3 @@ done: return ret; } -/* END */ -- cgit From c56874d1129c6e5759acc5b125b5e8edd44a997c Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 17 Aug 2007 16:03:18 +0000 Subject: r24527: Add a function lp_canonicalize_parameter_with_value that turns a parameter and value into the canonical paramter with the value inverted if it was in invers boolean synonym. Make net conf use this function when storing parameters. Michael (This used to be commit 3b762ab18392fd06427957b0263262e3b8e34b9d) --- source3/utils/net_conf.c | 43 ++++++++++--------------------------------- 1 file changed, 10 insertions(+), 33 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 2f0b3d6b04..c18b733a89 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -154,43 +154,20 @@ static WERROR reg_setvalue_internal(struct registry_key *key, char *subkeyname; const char *canon_valname; const char *canon_valstr; - BOOL canon_inverse; - struct parm_struct *parm; - - if (!lp_parameter_is_valid(valname)) { - d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname); - werr = WERR_INVALID_PARAM; - goto done; - } - if (!lp_canonicalize_parameter(valname, &canon_valname, &canon_inverse)) + if (!lp_canonicalize_parameter_with_value(valname, valstr, + &canon_valname, + &canon_valstr)) { - d_fprintf(stderr, "ERROR: could not canonicalize parameter " - "'%s' after successful validation: this should not " - "happen!\n", valname); - werr = WERR_INVALID_PARAM; - goto done; - } - if (canon_inverse) { - if (!lp_invert_boolean(valstr, &canon_valstr)) { - d_fprintf(stderr, "invalid value '%s' given for " - "parameter '%s'\n", valstr, canon_valname); - werr = WERR_INVALID_PARAM; - goto done; - } - } else { - parm = lp_get_parameter(canon_valname); - if (parm->type == P_BOOL) { - if (!lp_canonicalize_boolean(valstr, &canon_valstr)) { - d_fprintf(stderr, "invalied value '%s' given " - "for parameter '%s'\n", valstr, - canon_valname); - werr = WERR_INVALID_PARAM; - goto done; - } + if (canon_valname == NULL) { + d_fprintf(stderr, "invalid parameter '%s' given\n", + valname); } else { - canon_valstr = valstr; + d_fprintf(stderr, "invalid value '%s' given for " + "parameter '%s'\n", valstr, valname); } + werr = WERR_INVALID_PARAM; + goto done; } ZERO_STRUCT(val); -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/utils/net_conf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c18b733a89..6a601d8871 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -342,9 +342,9 @@ done: /* * check if a subkey of KEY_SMBCONF of a given name exists */ -static BOOL smbconf_key_exists(TALLOC_CTX *ctx, const char *subkeyname) +static bool smbconf_key_exists(TALLOC_CTX *ctx, const char *subkeyname) { - BOOL ret = False; + bool ret = False; WERROR werr = WERR_OK; TALLOC_CTX *mem_ctx; struct registry_key *key; @@ -364,10 +364,10 @@ done: return ret; } -static BOOL smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key, +static bool smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key, const char *param) { - BOOL ret = False; + bool ret = False; WERROR werr = WERR_OK; struct registry_value *value = NULL; @@ -479,10 +479,10 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, valstr = talloc_asprintf(ctx, "%s", (char *)ptr); break; case P_BOOL: - valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(BOOL *)ptr)); + valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(bool *)ptr)); break; case P_BOOLREV: - valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(BOOL *)ptr)); + valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(bool *)ptr)); break; case P_ENUM: for (i = 0; parm->enum_list[i].name; i++) { @@ -600,7 +600,7 @@ done: } /* return True iff there are nondefault globals */ -static BOOL globals_exist(void) +static bool globals_exist(void) { int i = 0; struct parm_struct *parm; @@ -695,7 +695,7 @@ int net_conf_import(int argc, const char **argv) int ret = -1; const char *filename = NULL; const char *servicename = NULL; - BOOL service_found = False; + bool service_found = False; TALLOC_CTX *ctx; struct share_iterator *shares; struct share_params *share; -- cgit From 78c6ee0090f4122bc25baaacb5546517ad4b7bc6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Nov 2007 17:27:54 +0100 Subject: Remove some globals (This used to be commit 31d0a846db08d845e6cdfd85def4ac1c34031e02) --- source3/utils/net_conf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 6a601d8871..4ff4bd9a29 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -494,9 +494,11 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, } } break; - case P_OCTAL: - valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); + case P_OCTAL: { + char *o = octal_string(*(int *)ptr); + valstr = talloc_move(ctx, &o); break; + } case P_LIST: valstr = talloc_strdup(ctx, ""); if ((char ***)ptr && *(char ***)ptr) { -- cgit From ade51769d5f7291f912893e5f959b651223a68c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 12:43:10 -0800 Subject: We don't need P_GSTRING or P_UGSTRING anymore. Jeremy. (This used to be commit 78dc75600099b5b3b5a8ecffec747a227ff51d70) --- source3/utils/net_conf.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 4ff4bd9a29..16b372ca72 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -474,10 +474,6 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, case P_USTRING: valstr = talloc_asprintf(ctx, "%s", *(char **)ptr); break; - case P_GSTRING: - case P_UGSTRING: - valstr = talloc_asprintf(ctx, "%s", (char *)ptr); - break; case P_BOOL: valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(bool *)ptr)); break; -- cgit From 1b5c1ae7424ba2fad857adf3701a5809ba3b27fe Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 11 Dec 2007 21:21:17 +0100 Subject: Very quick conversion of net_conf functions into the libnet_conf layer. Certainly needs cleanup later. Guenther (This used to be commit 2b41ac926de76804a50681bd246b3a20e112853b) --- source3/utils/net_conf.c | 158 +++++------------------------------------------ 1 file changed, 16 insertions(+), 142 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 16b372ca72..c853a79249 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -26,6 +26,7 @@ #include "includes.h" #include "utils/net.h" +#include "libnet/libnet_proto.h" /* * usage functions @@ -213,67 +214,6 @@ done: return werr; } -/* - * Open a subkey of KEY_SMBCONF (i.e a service) - * - variant without error output (q = quiet)- - */ -static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname, - uint32 desired_access, - struct registry_key **key) -{ - WERROR werr = WERR_OK; - char *path = NULL; - NT_USER_TOKEN *token; - - if (!(token = registry_create_admin_token(ctx))) { - DEBUG(1, ("Error creating admin token\n")); - goto done; - } - - if (subkeyname == NULL) { - path = talloc_strdup(ctx, KEY_SMBCONF); - } else { - path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, subkeyname); - } - - werr = reg_open_path(ctx, path, desired_access, - token, key); - -done: - TALLOC_FREE(path); - return werr; -} - -/* - * Open a subkey of KEY_SMBCONF (i.e a service) - * - variant with error output - - */ -static WERROR smbconf_open_path(TALLOC_CTX *ctx, const char *subkeyname, - uint32 desired_access, - struct registry_key **key) -{ - WERROR werr = WERR_OK; - - werr = smbconf_open_path_q(ctx, subkeyname, desired_access, key); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error opening registry path '%s\\%s': %s\n", - KEY_SMBCONF, - (subkeyname == NULL) ? "" : subkeyname, - dos_errstr(werr)); - } - - return werr; -} - -/* - * open the base key KEY_SMBCONF - */ -static WERROR smbconf_open_basepath(TALLOC_CTX *ctx, uint32 desired_access, - struct registry_key **key) -{ - return smbconf_open_path(ctx, NULL, desired_access, key); -} - /* * delete a subkey of KEY_SMBCONF */ @@ -282,7 +222,7 @@ static WERROR reg_delkey_internal(TALLOC_CTX *ctx, const char *keyname) WERROR werr = WERR_OK; struct registry_key *key = NULL; - werr = smbconf_open_basepath(ctx, REG_KEY_WRITE, &key); + werr = libnet_smbconf_open_basepath(ctx, REG_KEY_WRITE, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -298,72 +238,6 @@ done: return werr; } -/* - * create a subkey of KEY_SMBCONF - */ -static WERROR reg_createkey_internal(TALLOC_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_new(ctx))) { - werr = WERR_NOMEM; - goto done; - } - - werr = smbconf_open_basepath(create_ctx, REG_KEY_WRITE, &create_parent); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_createkey(ctx, create_parent, subkeyname, - REG_KEY_WRITE, newkey, &action); - if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) { - d_fprintf(stderr, "Key '%s' already exists.\n", subkeyname); - werr = WERR_ALREADY_EXISTS; - } - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error creating key %s: %s\n", - subkeyname, dos_errstr(werr)); - } - -done: - TALLOC_FREE(create_ctx); - return werr; -} - -/* - * check if a subkey of KEY_SMBCONF of a given name exists - */ -static bool smbconf_key_exists(TALLOC_CTX *ctx, const char *subkeyname) -{ - bool ret = False; - WERROR werr = WERR_OK; - TALLOC_CTX *mem_ctx; - struct registry_key *key; - - if (!(mem_ctx = talloc_new(ctx))) { - d_fprintf(stderr, "ERROR: Out of memory...!\n"); - goto done; - } - - werr = smbconf_open_path_q(mem_ctx, subkeyname, REG_KEY_READ, &key); - if (W_ERROR_IS_OK(werr)) { - ret = True; - } - -done: - TALLOC_FREE(mem_ctx); - return ret; -} - static bool smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key, const char *param) { @@ -553,13 +427,13 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (smbconf_key_exists(tmp_ctx, servicename)) { + if (libnet_smbconf_key_exists(tmp_ctx, servicename)) { werr = reg_delkey_internal(tmp_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = reg_createkey_internal(tmp_ctx, servicename, &key); + werr = libnet_reg_createkey_internal(tmp_ctx, servicename, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -632,12 +506,12 @@ int net_conf_list(int argc, const char **argv) goto done; } - werr = smbconf_open_basepath(ctx, REG_KEY_READ, &base_key); + werr = libnet_smbconf_open_basepath(ctx, REG_KEY_READ, &base_key); if (!W_ERROR_IS_OK(werr)) { goto done; } - if (smbconf_key_exists(ctx, GLOBAL_NAME)) { + if (libnet_smbconf_key_exists(ctx, GLOBAL_NAME)) { werr = reg_openkey(ctx, base_key, GLOBAL_NAME, REG_KEY_READ, &sub_key); if (!W_ERROR_IS_OK(werr)) { @@ -790,7 +664,7 @@ int net_conf_listshares(int argc, const char **argv) goto done; } - werr = smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key); + werr = libnet_smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -852,7 +726,7 @@ int net_conf_showshare(int argc, const char **argv) goto done; } - werr = smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key); + werr = libnet_smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -989,7 +863,7 @@ int net_conf_addshare(int argc, const char **argv) * create the share */ - werr = reg_createkey_internal(NULL, argv[0], &newkey); + werr = libnet_reg_createkey_internal(NULL, argv[0], &newkey); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -1060,10 +934,10 @@ static int net_conf_setparm(int argc, const char **argv) param = strdup_lower(argv[1]); value_str = argv[2]; - if (!smbconf_key_exists(ctx, service)) { - werr = reg_createkey_internal(ctx, service, &key); + if (!libnet_smbconf_key_exists(ctx, service)) { + werr = libnet_reg_createkey_internal(ctx, service, &key); } else { - werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); + werr = libnet_smbconf_open_path(ctx, service, REG_KEY_WRITE, &key); } if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1104,14 +978,14 @@ static int net_conf_getparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - if (!smbconf_key_exists(ctx, service)) { + if (!libnet_smbconf_key_exists(ctx, service)) { d_fprintf(stderr, "ERROR: given service '%s' does not exist.\n", service); goto done; } - werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); + werr = libnet_smbconf_open_path(ctx, service, REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -1151,14 +1025,14 @@ static int net_conf_delparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - if (!smbconf_key_exists(ctx, service)) { + if (!libnet_smbconf_key_exists(ctx, service)) { d_fprintf(stderr, "Error: given service '%s' does not exist.\n", service); goto done; } - werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key); + werr = libnet_smbconf_open_path(ctx, service, REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 41410c86cc698f997dd82a143fd92277060384b0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 14 Dec 2007 12:22:20 +0100 Subject: Some libnet and netapi build fixes. Guenther (This used to be commit 1d47247283f7bc75291007be3fde72b1d3d95b99) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c853a79249..808ba8d885 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -26,7 +26,7 @@ #include "includes.h" #include "utils/net.h" -#include "libnet/libnet_proto.h" +#include "libnet/libnet.h" /* * usage functions -- cgit From ec3e8587ecdef8e4a52d4c37ac379d9e414b861b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 23 Dec 2007 02:44:29 +0100 Subject: Move smbconf_value_exists() to libnet/net_conf.c renaming it to libnet_smbconf_value_exists(). Michael (This used to be commit ba71c6844588f0342589163f514385911e7331e7) --- source3/utils/net_conf.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 808ba8d885..c4707e4248 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -238,22 +238,6 @@ done: return werr; } -static bool smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key, - const char *param) -{ - bool ret = False; - WERROR werr = WERR_OK; - struct registry_value *value = NULL; - - werr = reg_queryvalue(ctx, key, param, &value); - if (W_ERROR_IS_OK(werr)) { - ret = True; - } - - TALLOC_FREE(value); - return ret; -} - static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) { WERROR werr = WERR_OK; @@ -1037,7 +1021,7 @@ static int net_conf_delparm(int argc, const char **argv) goto done; } - if (!smbconf_value_exists(ctx, key, param)) { + if (!libnet_smbconf_value_exists(ctx, key, param)) { d_fprintf(stderr, "Error: given parameter '%s' is not set.\n", param); -- cgit From b04708866f146ada8a7cc353347244df54821fbf Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 23 Dec 2007 02:55:25 +0100 Subject: Move logic of net_smbconf_delparm() to libnet/libnet_conf.c Logic in new function libnet_smbconf_delparm(). Michael (This used to be commit 0cff79e3552e91ba0b6bc054802d28afcf4e8da4) --- source3/utils/net_conf.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c4707e4248..8d0b4b9bbe 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -995,7 +995,6 @@ static int net_conf_delparm(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; - struct registry_key *key = NULL; char *service = NULL; char *param = NULL; TALLOC_CTX *ctx; @@ -1009,26 +1008,19 @@ static int net_conf_delparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - if (!libnet_smbconf_key_exists(ctx, service)) { + werr = libnet_smbconf_delparm(ctx, service, param); + + if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, "Error: given service '%s' does not exist.\n", service); goto done; - } - - werr = libnet_smbconf_open_path(ctx, service, REG_KEY_READ, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - if (!libnet_smbconf_value_exists(ctx, key, param)) { + } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) { d_fprintf(stderr, "Error: given parameter '%s' is not set.\n", param); goto done; - } - werr = reg_deletevalue(key, param); - if (!W_ERROR_IS_OK(werr)) { + } else if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting value '%s': %s.\n", param, dos_errstr(werr)); goto done; -- cgit From 31d436e54c2ec56ae59527feb9a31d13eca44f6d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 23 Dec 2007 03:34:36 +0100 Subject: Move reg_setvalue_internal() to libnet_conf.c renaming it to libnet_smbconf_setvalue_internal() Michael (This used to be commit 7cb51a1d6d95704225d9ab22e88cc76fa910d38c) --- source3/utils/net_conf.c | 88 ++++++------------------------------------------ 1 file changed, 10 insertions(+), 78 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8d0b4b9bbe..2648aa2e81 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -143,77 +143,6 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) return result; } -/* - * add a value to a key. - */ -static WERROR reg_setvalue_internal(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) { - d_fprintf(stderr, "invalid parameter '%s' given\n", - valname); - } else { - d_fprintf(stderr, "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)) { - d_fprintf(stderr, "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')) { - d_fprintf(stderr, "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)) - { - d_fprintf(stderr, "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)) { - d_fprintf(stderr, - "Error adding value '%s' to " - "key '%s': %s\n", - canon_valname, key->key->name, dos_errstr(werr)); - } - -done: - return werr; -} - /* * delete a subkey of KEY_SMBCONF */ @@ -435,8 +364,8 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); } else { - werr = reg_setvalue_internal(key, parm->label, - valstr); + werr = libnet_smbconf_reg_setvalue_internal(key, + parm->label, valstr); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -854,21 +783,24 @@ int net_conf_addshare(int argc, const char **argv) /* add config params as values */ - werr = reg_setvalue_internal(newkey, "path", path); + werr = libnet_smbconf_reg_setvalue_internal(newkey, "path", path); if (!W_ERROR_IS_OK(werr)) goto done; if (comment != NULL) { - werr = reg_setvalue_internal(newkey, "comment", comment); + werr = libnet_smbconf_reg_setvalue_internal(newkey, "comment", + comment); if (!W_ERROR_IS_OK(werr)) goto done; } - werr = reg_setvalue_internal(newkey, "guest ok", guest_ok); + werr = libnet_smbconf_reg_setvalue_internal(newkey, "guest ok", + guest_ok); if (!W_ERROR_IS_OK(werr)) goto done; - werr = reg_setvalue_internal(newkey, "writeable", writeable); + werr = libnet_smbconf_reg_setvalue_internal(newkey, "writeable", + writeable); if (!W_ERROR_IS_OK(werr)) goto done; @@ -927,7 +859,7 @@ static int net_conf_setparm(int argc, const char **argv) goto done; } - werr = reg_setvalue_internal(key, param, value_str); + werr = libnet_smbconf_reg_setvalue_internal(key, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", param, dos_errstr(werr)); -- cgit From 62f08d3dd9b1f1d53a8e9ecf352fbbfb4c12c484 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 23 Dec 2007 03:41:55 +0100 Subject: Move net_conf_setparm() to libnet_conf.c renaming it to libnet_smbconf_setparm() Michael (This used to be commit 60f49b22b5aa125ff6cb358a258a1be99c378d7a) --- source3/utils/net_conf.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 2648aa2e81..1ab1378910 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -834,7 +834,6 @@ static int net_conf_setparm(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; - struct registry_key *key = NULL; char *service = NULL; char *param = NULL; const char *value_str = NULL; @@ -850,23 +849,14 @@ static int net_conf_setparm(int argc, const char **argv) param = strdup_lower(argv[1]); value_str = argv[2]; - if (!libnet_smbconf_key_exists(ctx, service)) { - werr = libnet_reg_createkey_internal(ctx, service, &key); - } else { - werr = libnet_smbconf_open_path(ctx, service, REG_KEY_WRITE, &key); - } - if (!W_ERROR_IS_OK(werr)) { - goto done; - } + werr = libnet_smbconf_setparm(ctx, service, param, value_str); - werr = libnet_smbconf_reg_setvalue_internal(key, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", param, dos_errstr(werr)); goto done; } - ret = 0; done: -- cgit From d1c2280cd44e40a4398115c7d862ac0c296c98bc Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 23 Dec 2007 04:10:15 +0100 Subject: Rename libnet_reg_createkey_internal() to libnet_smbconf_reg_createkey_internal(). Michael (This used to be commit 0e7f215f54c68b2d40f65f90ed11c41e1a7ef5ed) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 1ab1378910..673d373177 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -346,7 +346,7 @@ static int import_process_service(TALLOC_CTX *ctx, goto done; } } - werr = libnet_reg_createkey_internal(tmp_ctx, servicename, &key); + werr = libnet_smbconf_reg_createkey_internal(tmp_ctx, servicename, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -776,7 +776,7 @@ int net_conf_addshare(int argc, const char **argv) * create the share */ - werr = libnet_reg_createkey_internal(NULL, argv[0], &newkey); + werr = libnet_smbconf_reg_createkey_internal(NULL, argv[0], &newkey); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 8f163d5c5ae48a3ff1974e936b9316781eceff8a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 23 Dec 2007 15:07:20 +0100 Subject: Move logic of net_conf_getparm() to libnet_conf.c. Michael (This used to be commit d3a20c4d5a8109334cd3ed665ba60cfcc4425059) --- source3/utils/net_conf.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 673d373177..f3f2321643 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -869,7 +869,6 @@ static int net_conf_getparm(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; - struct registry_key *key = NULL; char *service = NULL; char *param = NULL; struct registry_value *value = NULL; @@ -884,21 +883,20 @@ static int net_conf_getparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - if (!libnet_smbconf_key_exists(ctx, service)) { + werr = libnet_smbconf_getparm(ctx, service, param, &value); + + if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, - "ERROR: given service '%s' does not exist.\n", + "Error: given service '%s' does not exist.\n", service); goto done; - } - - werr = libnet_smbconf_open_path(ctx, service, REG_KEY_READ, &key); - if (!W_ERROR_IS_OK(werr)) { + } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) { + d_fprintf(stderr, + "Error: given parameter '%s' is not set.\n", + param); goto done; - } - - werr = reg_queryvalue(ctx, key, param, &value); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error querying value '%s': %s.\n", + } else if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error getting value '%s': %s.\n", param, dos_errstr(werr)); goto done; } -- cgit From c74579f49149171e731ae9b5a8e77c579d120cbb Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 24 Dec 2007 00:53:22 +0100 Subject: Make libnet_smbconf_key_exists() use talloc_stackframe(). And not pass a talloc context. Michael (This used to be commit 7e8451f2f03b246801783aaf4b3d54465292f8f7) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f3f2321643..d09079c6f2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -340,7 +340,7 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (libnet_smbconf_key_exists(tmp_ctx, servicename)) { + if (libnet_smbconf_key_exists(servicename)) { werr = reg_delkey_internal(tmp_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -424,7 +424,7 @@ int net_conf_list(int argc, const char **argv) goto done; } - if (libnet_smbconf_key_exists(ctx, GLOBAL_NAME)) { + if (libnet_smbconf_key_exists(GLOBAL_NAME)) { werr = reg_openkey(ctx, base_key, GLOBAL_NAME, REG_KEY_READ, &sub_key); if (!W_ERROR_IS_OK(werr)) { -- cgit From c9f65929b733353baec531c4735749a754f051c5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 02:21:30 +0100 Subject: Move reg_delkey_internal() to libnet/libnet_conf.c Michael (This used to be commit c1b863fd0520ce64a1bad5e2fa3f69afcc2c78d5) --- source3/utils/net_conf.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index d09079c6f2..f45042b2f8 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -143,30 +143,6 @@ static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) return result; } -/* - * delete a subkey of KEY_SMBCONF - */ -static WERROR reg_delkey_internal(TALLOC_CTX *ctx, const char *keyname) -{ - WERROR werr = WERR_OK; - struct registry_key *key = NULL; - - werr = libnet_smbconf_open_basepath(ctx, REG_KEY_WRITE, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_deletekey_recursive(key, key, keyname); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error deleting registry key %s\\%s: %s\n", - KEY_SMBCONF, keyname, dos_errstr(werr)); - } - -done: - TALLOC_FREE(key); - return werr; -} - static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) { WERROR werr = WERR_OK; -- cgit From 9c20b9a731d581ae8bbf4f9ef66c3b7ded7e4122 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 02:24:39 +0100 Subject: Rename reg_delkey_internal() to libnet_smbconf_delshare(). Michael (This used to be commit 7d501f0d78ec57509d0bc5ef0dc16fcd24ee27e7) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f45042b2f8..e1b4fe1dfa 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -317,7 +317,7 @@ static int import_process_service(TALLOC_CTX *ctx, d_printf("[%s]\n", servicename); } else { if (libnet_smbconf_key_exists(servicename)) { - werr = reg_delkey_internal(tmp_ctx, servicename); + werr = libnet_smbconf_delshare(tmp_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -799,7 +799,7 @@ int net_conf_delshare(int argc, const char **argv) } sharename = argv[0]; - if (W_ERROR_IS_OK(reg_delkey_internal(NULL, sharename))) { + if (W_ERROR_IS_OK(libnet_smbconf_delshare(NULL, sharename))) { ret = 0; } done: -- cgit From 86486fcc9826663f7bf03fe4ceb354818415d089 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 02:31:41 +0100 Subject: Simplify libnet_smbconf_delshare(). Remove talloc context parameter. Remove d_printf error message. Michael (This used to be commit 870d35c04889603843bae989fb9c01396b4c6ed1) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index e1b4fe1dfa..38c14d779f 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -317,7 +317,7 @@ static int import_process_service(TALLOC_CTX *ctx, d_printf("[%s]\n", servicename); } else { if (libnet_smbconf_key_exists(servicename)) { - werr = libnet_smbconf_delshare(tmp_ctx, servicename); + werr = libnet_smbconf_delshare(servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -799,7 +799,7 @@ int net_conf_delshare(int argc, const char **argv) } sharename = argv[0]; - if (W_ERROR_IS_OK(libnet_smbconf_delshare(NULL, sharename))) { + if (W_ERROR_IS_OK(libnet_smbconf_delshare(sharename))) { ret = 0; } done: -- cgit From 734ddacc915aa6008b7189b4c8124bc8ee6b6890 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 02:42:33 +0100 Subject: Add error reporting to net_conf_delshare(). Michael (This used to be commit 8d02a2de61eb6b62fef1fbe57194c9d286423ba0) --- source3/utils/net_conf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 38c14d779f..54875c49a3 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -792,6 +792,7 @@ int net_conf_delshare(int argc, const char **argv) { int ret = -1; const char *sharename = NULL; + WERROR werr = WERR_OK; if (argc != 1) { net_conf_delshare_usage(argc, argv); @@ -799,9 +800,14 @@ int net_conf_delshare(int argc, const char **argv) } sharename = argv[0]; - if (W_ERROR_IS_OK(libnet_smbconf_delshare(sharename))) { - ret = 0; + werr = libnet_smbconf_delshare(sharename); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error deleting share %s: %s\n", + sharename, dos_errstr(werr)); + goto done; } + + ret = 0; done: return ret; } -- cgit From 9626fffe14ebedba7ce53441bb4f9e2288a8410d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 02:48:45 +0100 Subject: Use the proper boolean constants in net_conf.c Michael (This used to be commit 1fe4ea63b197cb7ebc054909d888d74b5ad6523c) --- source3/utils/net_conf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 54875c49a3..a10f983025 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -360,7 +360,7 @@ done: return ret; } -/* return True iff there are nondefault globals */ +/* return true iff there are nondefault globals */ static bool globals_exist(void) { int i = 0; @@ -368,10 +368,10 @@ static bool globals_exist(void) while ((parm = lp_next_parameter(GLOBAL_SECTION_SNUM, &i, 0)) != NULL) { if (parm->type != P_SEP) { - return True; + return true; } } - return False; + return false; } /* @@ -456,7 +456,7 @@ int net_conf_import(int argc, const char **argv) int ret = -1; const char *filename = NULL; const char *servicename = NULL; - bool service_found = False; + bool service_found = false; TALLOC_CTX *ctx; struct share_iterator *shares; struct share_params *share; @@ -480,10 +480,10 @@ int net_conf_import(int argc, const char **argv) filename)); if (!lp_load(filename, - False, /* global_only */ - True, /* save_defaults */ - False, /* add_ipc */ - True)) /* initialize_globals */ + false, /* global_only */ + true, /* save_defaults */ + false, /* add_ipc */ + true)) /* initialize_globals */ { d_fprintf(stderr, "Error parsing configuration file.\n"); goto done; @@ -497,7 +497,7 @@ int net_conf_import(int argc, const char **argv) if (((servicename == NULL) && globals_exist()) || strequal(servicename, GLOBAL_NAME)) { - service_found = True; + service_found = true; if (import_process_service(ctx, &global_share) != 0) { goto done; } @@ -516,7 +516,7 @@ int net_conf_import(int argc, const char **argv) if ((servicename == NULL) || strequal(servicename, lp_servicename(share->service))) { - service_found = True; + service_found = true; if (import_process_service(ctx, share)!= 0) { goto done; } -- cgit From 8e53343a74ab6c8947523ca9bd9a8c1583a8691e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 02:55:07 +0100 Subject: Move drop_smbconf_internal() to libnet_conf.c Michael (This used to be commit 4c2a3396bb687703f6b74655fda2014d1f75200b) --- source3/utils/net_conf.c | 50 ------------------------------------------------ 1 file changed, 50 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index a10f983025..e46ff758ef 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -168,56 +168,6 @@ done: return werr; } -static WERROR drop_smbconf_internal(TALLOC_CTX *ctx) -{ - char *path, *p; - WERROR werr = WERR_OK; - NT_USER_TOKEN *token; - struct registry_key *parent_key = NULL; - struct registry_key *new_key = NULL; - TALLOC_CTX* tmp_ctx = NULL; - enum winreg_CreateAction action; - - tmp_ctx = talloc_new(ctx); - if (tmp_ctx == NULL) { - werr = WERR_NOMEM; - goto done; - } - - if (!(token = registry_create_admin_token(tmp_ctx))) { - /* what is the appropriate error code here? */ - werr = WERR_CAN_NOT_COMPLETE; - goto done; - } - - path = talloc_strdup(tmp_ctx, KEY_SMBCONF); - if (path == NULL) { - d_fprintf(stderr, "ERROR: out of memory!\n"); - werr = WERR_NOMEM; - goto done; - } - p = strrchr(path, '\\'); - *p = '\0'; - werr = reg_open_path(tmp_ctx, path, REG_KEY_WRITE, token, &parent_key); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_deletekey_recursive(tmp_ctx, parent_key, p+1); - - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE, - &new_key, &action); - -done: - TALLOC_FREE(tmp_ctx); - return werr; -} - static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, struct share_params *share) { -- cgit From 2764f5a0a6404b1ade9b996783e0a131b7b2d231 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 03:01:59 +0100 Subject: Rename drop_smbconf_internal() to libnet_smbconf_drop(). Michael (This used to be commit 5873e6a1f8242e07b1699366a536350a7199c28c) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index e46ff758ef..6d59643bee 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -538,7 +538,7 @@ int net_conf_drop(int argc, const char **argv) goto done; } - werr = drop_smbconf_internal(NULL); + werr = libnet_smbconf_drop(NULL); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting configuration: %s\n", dos_errstr(werr)); -- cgit From e5a87c2543dea12488250eb8e15dcfe02b34dfe1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 03:05:06 +0100 Subject: Remove talloc context parameter from libnet_smbconf_drop(). Make use of talloc_stackframe. Michael (This used to be commit aaceab1153f6c2a2adde83681913c771a16ca81f) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 6d59643bee..9a6f5400e1 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -538,7 +538,7 @@ int net_conf_drop(int argc, const char **argv) goto done; } - werr = libnet_smbconf_drop(NULL); + werr = libnet_smbconf_drop(); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting configuration: %s\n", dos_errstr(werr)); -- cgit From f3b0469b4a623c3ef17e2453bf40eb52778b5c42 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 03:29:05 +0100 Subject: Remove talloc context parameter from libnet_smbconf_setparm(). Make use of talloc stackframe internally. This removes talloc contxt from net_conf_setparm. Michael (This used to be commit efaffefc438f8375a083b194ac7a09e563000d3c) --- source3/utils/net_conf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9a6f5400e1..eb6398f5b9 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -769,9 +769,6 @@ static int net_conf_setparm(int argc, const char **argv) char *service = NULL; char *param = NULL; const char *value_str = NULL; - TALLOC_CTX *ctx; - - ctx = talloc_init("setparm"); if (argc != 3) { net_conf_setparm_usage(argc, argv); @@ -781,7 +778,7 @@ static int net_conf_setparm(int argc, const char **argv) param = strdup_lower(argv[1]); value_str = argv[2]; - werr = libnet_smbconf_setparm(ctx, service, param, value_str); + werr = libnet_smbconf_setparm(service, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", @@ -793,7 +790,6 @@ static int net_conf_setparm(int argc, const char **argv) done: SAFE_FREE(service); - TALLOC_FREE(ctx); return ret; } -- cgit From 726f32b6728a7d2b56ccb2f04827d0e5150ea848 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 03:29:41 +0100 Subject: Add a missing free. Michael (This used to be commit bf6031287f75a0e17092f60f9885e7e55cd0f93c) --- source3/utils/net_conf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index eb6398f5b9..5d8b6d605b 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -790,6 +790,7 @@ static int net_conf_setparm(int argc, const char **argv) done: SAFE_FREE(service); + SAFE_FREE(param); return ret; } -- cgit From 44631bfd4d418cbf1ca4309057e6161cdce50bd4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 03:34:04 +0100 Subject: Remove talloc context parameter from libnet_smbconf_delparm(). Make use of talloc stackframe internally. This removes talloc contxt from net_conf_delparm. Michael (This used to be commit 16f137393881edc78c9322f038ba38e53e3ee07d) --- source3/utils/net_conf.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 5d8b6d605b..5dc1eb06f4 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -846,9 +846,6 @@ static int net_conf_delparm(int argc, const char **argv) WERROR werr = WERR_OK; char *service = NULL; char *param = NULL; - TALLOC_CTX *ctx; - - ctx = talloc_init("delparm"); if (argc != 2) { net_conf_delparm_usage(argc, argv); @@ -857,7 +854,7 @@ static int net_conf_delparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_smbconf_delparm(ctx, service, param); + werr = libnet_smbconf_delparm(service, param); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, -- cgit From c2ab4bd70599cd7ff2043fef9904da178e6e4d19 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Dec 2007 03:35:00 +0100 Subject: Add two missing free-s. Michael (This used to be commit 4efac39c363d565c2c7211da73d5e1cf2ac3d0b2) --- source3/utils/net_conf.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 5dc1eb06f4..df85d7eb4b 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -875,6 +875,8 @@ static int net_conf_delparm(int argc, const char **argv) ret = 0; done: + SAFE_FREE(service); + SAFE_FREE(param); return ret; } -- cgit From 18ea20e19b59d3151ca59f0576211f855931f839 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Dec 2007 00:58:11 +0100 Subject: Rename libnet_smbconf_open_path() to libnet_smbconf_reg_open_path(). Michael (This used to be commit 4b0e636965bd37e7c0deecb7b5eff0cc4487408b) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index df85d7eb4b..348e91a15f 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -565,7 +565,7 @@ int net_conf_showshare(int argc, const char **argv) goto done; } - werr = libnet_smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key); + werr = libnet_smbconf_reg_open_path(ctx, argv[0], REG_KEY_READ, &key); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From afca308742795a34e58f7a049c9a8d86cdff80c1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Dec 2007 01:01:14 +0100 Subject: Rename libnet_smbconf_open_basepath() to libnet_smbconf_reg_open_basepath(). Michael (This used to be commit 4c0e7270c42788e7f77c402032ae74cf0f8a7106) --- source3/utils/net_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 348e91a15f..8b89f2fa6f 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -345,7 +345,7 @@ int net_conf_list(int argc, const char **argv) goto done; } - werr = libnet_smbconf_open_basepath(ctx, REG_KEY_READ, &base_key); + werr = libnet_smbconf_reg_open_basepath(ctx, REG_KEY_READ, &base_key); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -503,7 +503,8 @@ int net_conf_listshares(int argc, const char **argv) goto done; } - werr = libnet_smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key); + werr = libnet_smbconf_reg_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, + &key); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From dfa8d9356cea0dd6a1b013a72c3d68c026deb511 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 00:05:23 +0100 Subject: Move format_value() to libnet_conf.c. Michael (This used to be commit 3422a5048ad4b7f789ec233356885d78dbdacf9a) --- source3/utils/net_conf.c | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8b89f2fa6f..98cc1ee198 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -110,39 +110,6 @@ static int net_conf_delparm_usage(int argc, const char **argv) * Helper functions */ -static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value) -{ - char *result = NULL; - - /* what if mem_ctx = NULL? */ - - 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\" ", - value->v.multi_sz.strings[j]); - } - 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; -} - static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) { WERROR werr = WERR_OK; -- cgit From 4b75bc63bb82f2322acdb013f1cfa9eb36419856 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 01:17:39 +0100 Subject: Rename format_value() to libnet_smbconf_format_registry_value(). Michael (This used to be commit 95d5dd9bb0546181cd499e6deabff562166412e3) --- source3/utils/net_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 98cc1ee198..fb6cb58840 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -122,7 +122,8 @@ static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) &valvalue)); idx++) { - d_printf("\t%s = %s\n", valname, format_value(ctx, valvalue)); + d_printf("\t%s = %s\n", valname, + libnet_smbconf_format_registry_value(ctx, valvalue)); } if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { d_fprintf(stderr, "Error enumerating values: %s\n", @@ -798,7 +799,7 @@ static int net_conf_getparm(int argc, const char **argv) goto done; } - d_printf("%s\n", format_value(ctx, value)); + d_printf("%s\n", libnet_smbconf_format_registry_value(ctx, value)); ret = 0; done: -- cgit From eb356fbafc4b6e0d94b1ba75c6c466262e3221e5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 02:12:33 +0100 Subject: Hide the registry backend from libnet_smbconf_getparm(). Return a formatted string of the value instead. Michael (This used to be commit 7d0ec5bae155cda6620db04dcb7bd43db59241aa) --- source3/utils/net_conf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index fb6cb58840..e607d099dc 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -769,7 +769,7 @@ static int net_conf_getparm(int argc, const char **argv) WERROR werr = WERR_OK; char *service = NULL; char *param = NULL; - struct registry_value *value = NULL; + char *valstr = NULL; TALLOC_CTX *ctx; ctx = talloc_init("getparm"); @@ -781,7 +781,7 @@ static int net_conf_getparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_smbconf_getparm(ctx, service, param, &value); + werr = libnet_smbconf_getparm(ctx, service, param, &valstr); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, @@ -799,7 +799,7 @@ static int net_conf_getparm(int argc, const char **argv) goto done; } - d_printf("%s\n", libnet_smbconf_format_registry_value(ctx, value)); + d_printf("%s\n", valstr); ret = 0; done: -- cgit From 8093a75d6f44644b70023272f186575c2372c54b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 02:27:20 +0100 Subject: Make the main net_conf functions static in net_conf.c Michael (This used to be commit dd6e09a65e67a9a16b35b078ebfb41da09926029) --- source3/utils/net_conf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index e607d099dc..8140941da2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -296,7 +296,7 @@ static bool globals_exist(void) * the conf functions */ -int net_conf_list(int argc, const char **argv) +static int net_conf_list(int argc, const char **argv) { WERROR werr = WERR_OK; int ret = -1; @@ -369,7 +369,7 @@ done: return ret; } -int net_conf_import(int argc, const char **argv) +static int net_conf_import(int argc, const char **argv) { int ret = -1; const char *filename = NULL; @@ -455,7 +455,7 @@ done: return ret; } -int net_conf_listshares(int argc, const char **argv) +static int net_conf_listshares(int argc, const char **argv) { WERROR werr = WERR_OK; int ret = -1; @@ -497,7 +497,7 @@ done: return ret; } -int net_conf_drop(int argc, const char **argv) +static int net_conf_drop(int argc, const char **argv) { int ret = -1; WERROR werr; @@ -520,7 +520,7 @@ done: return ret; } -int net_conf_showshare(int argc, const char **argv) +static int net_conf_showshare(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -552,7 +552,7 @@ done: return ret; } -int net_conf_addshare(int argc, const char **argv) +static int net_conf_addshare(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -707,7 +707,7 @@ done: return ret; } -int net_conf_delshare(int argc, const char **argv) +static int net_conf_delshare(int argc, const char **argv) { int ret = -1; const char *sharename = NULL; -- cgit From f8c39cbb7b3e4df3c07735575bc5f31717b22f66 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 03:38:13 +0100 Subject: Move functionality of net_conf_showshare() to libnet_conf.c The functionality is moved to a new function libnet_smbconf_getshare(). This returns the parameters of the given share as two lists: the list of parameter names and the list of matching (formatted) parameter values. The retrieval and formatting is done in a new internal helper function libnet_smbconf_reg_get_values() that is to become the replacement for list_values() from net_conf.c once functionality of net_conf_list() has been moved to libnet_conf, too. Michael (This used to be commit 198232bd525cfac933b4885e6b330ebf4ac2c8ae) --- source3/utils/net_conf.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8140941da2..9a7c8c9097 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -525,7 +525,12 @@ static int net_conf_showshare(int argc, const char **argv) int ret = -1; WERROR werr = WERR_OK; struct registry_key *key = NULL; + char *sharename = NULL; TALLOC_CTX *ctx; + uint32_t num_params; + uint32_t count; + char **param_names; + char **param_values; ctx = talloc_init("showshare"); @@ -534,15 +539,21 @@ static int net_conf_showshare(int argc, const char **argv) goto done; } - werr = libnet_smbconf_reg_open_path(ctx, argv[0], REG_KEY_READ, &key); + sharename = argv[0]; + + werr = libnet_smbconf_getshare(ctx, sharename, &num_params, + ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { + d_printf("error getting share parameters: %s\n", + dos_errstr(werr)); goto done; } - d_printf("[%s]\n", argv[0]); + d_printf("[%s]\n", sharename); - if (!W_ERROR_IS_OK(list_values(ctx, key))) { - goto done; + for (count = 0; count <= num_params; count++) { + d_printf("\t%s = %s\n", param_names[count], + param_values[count]); } ret = 0; -- cgit From 2a642a6e2b42c2b111870f95fe6dd38e875766f1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 12:52:09 +0100 Subject: Move functionality of net_conf_listshares() to libnet_conf.c into new function libnet_smbconf_getshares(). Michael (This used to be commit 306c7e4d9cecac4c2c0ea1172bd585c3c17d4541) --- source3/utils/net_conf.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9a7c8c9097..5c0d6c6376 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -459,9 +459,8 @@ static int net_conf_listshares(int argc, const char **argv) { WERROR werr = WERR_OK; int ret = -1; - struct registry_key *key; - uint32 idx = 0; - char *subkey_name = NULL; + uint32_t count, num_shares = 0; + char **share_names = NULL; TALLOC_CTX *ctx; ctx = talloc_init("listshares"); @@ -471,23 +470,14 @@ static int net_conf_listshares(int argc, const char **argv) goto done; } - werr = libnet_smbconf_reg_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, - &key); + werr = libnet_smbconf_getshares(ctx, &num_shares, &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; } - for (idx = 0; - W_ERROR_IS_OK(werr = reg_enumkey(ctx, key, idx, - &subkey_name, NULL)); - idx++) + for (count = 0; count <= num_shares; count++) { - d_printf("%s\n", subkey_name); - } - if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - d_fprintf(stderr, "Error enumerating subkeys: %s\n", - dos_errstr(werr)); - goto done; + d_printf("%s\n", share_names[count]); } ret = 0; -- cgit From 1c03f6b6081a54f6b6e684d9a76be039fd468444 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 12:55:42 +0100 Subject: Rename libnet_smbconf_getshares() to libnet_smbconf_get_share_names(). Michael (This used to be commit 9b3b9aa7e1044719a5112b9e5446e6fbdd7cecf9) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 5c0d6c6376..42af824508 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -470,7 +470,7 @@ static int net_conf_listshares(int argc, const char **argv) goto done; } - werr = libnet_smbconf_getshares(ctx, &num_shares, &share_names); + werr = libnet_smbconf_get_share_names(ctx, &num_shares, &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 0b7aafff116fc297a0c2fb31a440a62652fe6fc9 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 13:02:22 +0100 Subject: Fix a const warning. Michael (This used to be commit e276e48177f890531ee8b4024c90352f284d4608) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 42af824508..651948c07c 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -515,7 +515,7 @@ static int net_conf_showshare(int argc, const char **argv) int ret = -1; WERROR werr = WERR_OK; struct registry_key *key = NULL; - char *sharename = NULL; + const char *sharename = NULL; TALLOC_CTX *ctx; uint32_t num_params; uint32_t count; -- cgit From e8cb7cecf2dde62f271a37376cefa5179eb7b7bc Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 14:38:42 +0100 Subject: Make sure libnet_smbconf_get_share_names() always lists "global" first. And don't return count-1 but count. Michael (This used to be commit b7cb9b78231512dc4a88c307048d7fb5334fa319) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 651948c07c..8791d7cbdd 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -475,7 +475,7 @@ static int net_conf_listshares(int argc, const char **argv) goto done; } - for (count = 0; count <= num_shares; count++) + for (count = 0; count < num_shares; count++) { d_printf("%s\n", share_names[count]); } -- cgit From a6d6fbb73d56d3b96ccf55c1d028c5af00d83386 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 17:02:27 +0100 Subject: Dont return count - 1 but count from libnet_smbconf_reg_get_values(). Michael (This used to be commit ded60dec7d75db7df485a159fb6bf628d8e24805) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8791d7cbdd..8957408bd6 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -541,7 +541,7 @@ static int net_conf_showshare(int argc, const char **argv) d_printf("[%s]\n", sharename); - for (count = 0; count <= num_params; count++) { + for (count = 0; count < num_params; count++) { d_printf("\t%s = %s\n", param_names[count], param_values[count]); } -- cgit From 9c1449594458ad6f019f48072bba2b1c831b628b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 22:09:51 +0100 Subject: Use libnet_smbconf_get_config() in net_conf_list(). This leaves only output logic in net_conf_list(). Michael (This used to be commit 95d9981d59fe69ee1ed98f21475bd1ba72930c1b) --- source3/utils/net_conf.c | 64 ++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 45 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8957408bd6..ed9ed389e4 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -301,10 +301,12 @@ static int net_conf_list(int argc, const char **argv) WERROR werr = WERR_OK; int ret = -1; TALLOC_CTX *ctx; - struct registry_key *base_key = NULL; - struct registry_key *sub_key = NULL; - uint32 idx_key = 0; - char *subkey_name = NULL; + uint32_t num_shares; + char **share_names; + uint32_t *num_params; + char ***param_names; + char ***param_values; + uint32_t share_count, param_count; ctx = talloc_init("list"); @@ -313,54 +315,26 @@ static int net_conf_list(int argc, const char **argv) goto done; } - werr = libnet_smbconf_reg_open_basepath(ctx, REG_KEY_READ, &base_key); + werr = libnet_smbconf_get_config(ctx, &num_shares, &share_names, + &num_params, ¶m_names, + ¶m_values); if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error getting config: %s\n", + dos_errstr(werr)); goto done; } - if (libnet_smbconf_key_exists(GLOBAL_NAME)) { - werr = reg_openkey(ctx, base_key, GLOBAL_NAME, - REG_KEY_READ, &sub_key); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error opening subkey '%s' : %s\n", - subkey_name, dos_errstr(werr)); - goto done; - } - d_printf("[%s]\n", GLOBAL_NAME); - if (!W_ERROR_IS_OK(list_values(ctx, sub_key))) { - goto done; - } - d_printf("\n"); - } - - for (idx_key = 0; - W_ERROR_IS_OK(werr = reg_enumkey(ctx, base_key, idx_key, - &subkey_name, NULL)); - idx_key++) - { - if (strequal(subkey_name, GLOBAL_NAME)) { - continue; - } - d_printf("[%s]\n", subkey_name); - - werr = reg_openkey(ctx, base_key, subkey_name, - REG_KEY_READ, &sub_key); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, - "Error opening subkey '%s': %s\n", - subkey_name, dos_errstr(werr)); - goto done; - } - if (!W_ERROR_IS_OK(list_values(ctx, sub_key))) { - goto done; + for (share_count = 0; share_count < num_shares; share_count++) { + d_printf("[%s]\n", share_names[share_count]); + for (param_count = 0; param_count < num_params[share_count]; + param_count++) + { + d_printf("\t%s = %s\n", + param_names[share_count][param_count], + param_values[share_count][param_count]); } d_printf("\n"); } - if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - d_fprintf(stderr, "Error enumerating subkeys: %s\n", - dos_errstr(werr)); - goto done; - } ret = 0; -- cgit From 59128c783761c6f823971e7aa9513834a7be4b7d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Dec 2007 22:11:09 +0100 Subject: Remove list_values() from net_conf.c - it is not needed any more. Also make libnet.c:libnet_smbconf_format_registry_value() static. (There are nor more external callers.) Michael (This used to be commit ac7baa17e89d2363b5b3db85de9c842b596dea25) --- source3/utils/net_conf.c | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index ed9ed389e4..29bbc83ec3 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -110,32 +110,6 @@ static int net_conf_delparm_usage(int argc, const char **argv) * Helper functions */ -static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key) -{ - WERROR werr = WERR_OK; - uint32 idx = 0; - struct registry_value *valvalue = NULL; - char *valname = NULL; - - for (idx = 0; - W_ERROR_IS_OK(werr = reg_enumvalue(ctx, key, idx, &valname, - &valvalue)); - idx++) - { - d_printf("\t%s = %s\n", valname, - libnet_smbconf_format_registry_value(ctx, valvalue)); - } - if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { - d_fprintf(stderr, "Error enumerating values: %s\n", - dos_errstr(werr)); - goto done; - } - werr = WERR_OK; - -done: - return werr; -} - static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, struct share_params *share) { -- cgit From 80957726b694ea59da306c1be2e08b213936dc93 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 30 Dec 2007 22:27:45 +0100 Subject: Remove all d_fprintf-s from libnet_conf.c Replacing them buy DEBUG statements and filling in d_fprintfs in callers in net_conf.c. Michael (This used to be commit 1f0122d8d4ec0f67eaedd5df7383c1b45f37290f) --- source3/utils/net_conf.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 29bbc83ec3..9503a3c521 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -216,6 +216,8 @@ static int import_process_service(TALLOC_CTX *ctx, } werr = libnet_smbconf_reg_createkey_internal(tmp_ctx, servicename, &key); if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error creating share %s: %s\n", + servicename, dos_errstr(werr)); goto done; } } @@ -235,6 +237,10 @@ static int import_process_service(TALLOC_CTX *ctx, werr = libnet_smbconf_reg_setvalue_internal(key, parm->label, valstr); if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, + "Error setting parameter '%s'" + ": %s\n", parm->label, + dos_errstr(werr)); goto done; } } @@ -622,31 +628,45 @@ static int net_conf_addshare(int argc, const char **argv) werr = libnet_smbconf_reg_createkey_internal(NULL, argv[0], &newkey); if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error creating share %s: %s\n", + argv[0], dos_errstr(werr)); goto done; } /* add config params as values */ werr = libnet_smbconf_reg_setvalue_internal(newkey, "path", path); - if (!W_ERROR_IS_OK(werr)) + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error setting parameter %s: %s\n", + "path", dos_errstr(werr)); goto done; + } if (comment != NULL) { werr = libnet_smbconf_reg_setvalue_internal(newkey, "comment", comment); - if (!W_ERROR_IS_OK(werr)) + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error setting parameter %s: %s\n", + "comment", dos_errstr(werr)); goto done; + } } werr = libnet_smbconf_reg_setvalue_internal(newkey, "guest ok", guest_ok); - if (!W_ERROR_IS_OK(werr)) + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error setting parameter %s: %s\n", + "'guest ok'", dos_errstr(werr)); goto done; + } werr = libnet_smbconf_reg_setvalue_internal(newkey, "writeable", writeable); - if (!W_ERROR_IS_OK(werr)) + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error setting parameter %s: %s\n", + "writeable", dos_errstr(werr)); goto done; + } ret = 0; -- cgit From a74de0c7eb575e5b983773a1b8daa724c7074e7e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 30 Dec 2007 22:30:21 +0100 Subject: Remove an unused variable. Michael (This used to be commit 332be113a775adce8108a8003682019ae7f5bc21) --- source3/utils/net_conf.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9503a3c521..98e6b60034 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -468,7 +468,6 @@ static int net_conf_showshare(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; - struct registry_key *key = NULL; const char *sharename = NULL; TALLOC_CTX *ctx; uint32_t num_params; -- cgit From e8a680cdf391255fcbdacd1dcebc0f5a947408f1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 31 Dec 2007 01:14:44 +0100 Subject: Rename libnet_smbconf_key_exists() to libnet_smbconf_share_exists() and move it to the api section of libnet_conf.c Michael (This used to be commit 9b5d8f4d95ebfd47831906019e11227aecc83aa1) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 98e6b60034..24257fe7cf 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -208,7 +208,7 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (libnet_smbconf_key_exists(servicename)) { + if (libnet_smbconf_share_exists(servicename)) { werr = libnet_smbconf_delshare(servicename); if (!W_ERROR_IS_OK(werr)) { goto done; -- cgit From 01f8fd55a7f9cb9cc90e3d2b53397412a7bad714 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 31 Dec 2007 01:56:18 +0100 Subject: Rewrite net_conf_addshare() to only use libnet_conf API functions. Also exit on error if the share already exists. net_conf_addshare() is considered a high level utility function. It should not be an libnet_conf API function in itself since it is kind of arbitrary. Michael (This used to be commit af5218f1505321236be52df10ebfe8f42b99573d) --- source3/utils/net_conf.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 24257fe7cf..9e4d4300d5 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -506,11 +506,16 @@ done: return ret; } +/** + * Add a share, with a couple of standard parameters, partly optional. + * + * This is a high level utility function of the net conf utility, + * not a direct frontend to the libnet_conf API. + */ static int net_conf_addshare(int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; - struct registry_key *newkey = NULL; char *sharename = NULL; const char *path = NULL; const char *comment = NULL; @@ -562,7 +567,6 @@ static int net_conf_addshare(int argc, const char **argv) net_conf_addshare_usage(argc, argv); goto done; } - case 2: path = argv[1]; sharename = strdup_lower(argv[0]); @@ -596,6 +600,12 @@ static int net_conf_addshare(int argc, const char **argv) goto done; } + if (libnet_smbconf_share_exists(sharename)) { + d_fprintf(stderr, "ERROR: share %s already exists.\n", + sharename); + goto done; + } + /* validate path */ if (path[0] != '/') { @@ -622,19 +632,10 @@ static int net_conf_addshare(int argc, const char **argv) } /* - * create the share + * create the share by adding the parameters */ - werr = libnet_smbconf_reg_createkey_internal(NULL, argv[0], &newkey); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error creating share %s: %s\n", - argv[0], dos_errstr(werr)); - goto done; - } - - /* add config params as values */ - - werr = libnet_smbconf_reg_setvalue_internal(newkey, "path", path); + werr = libnet_smbconf_setparm(sharename, "path", path); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "path", dos_errstr(werr)); @@ -642,8 +643,7 @@ static int net_conf_addshare(int argc, const char **argv) } if (comment != NULL) { - werr = libnet_smbconf_reg_setvalue_internal(newkey, "comment", - comment); + werr = libnet_smbconf_setparm(sharename, "comment", comment); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "comment", dos_errstr(werr)); @@ -651,16 +651,14 @@ static int net_conf_addshare(int argc, const char **argv) } } - werr = libnet_smbconf_reg_setvalue_internal(newkey, "guest ok", - guest_ok); + werr = libnet_smbconf_setparm(sharename, "guest ok", guest_ok); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "'guest ok'", dos_errstr(werr)); goto done; } - werr = libnet_smbconf_reg_setvalue_internal(newkey, "writeable", - writeable); + werr = libnet_smbconf_setparm(sharename, "writeable", writeable); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "writeable", dos_errstr(werr)); @@ -670,7 +668,6 @@ static int net_conf_addshare(int argc, const char **argv) ret = 0; done: - TALLOC_FREE(newkey); SAFE_FREE(sharename); return ret; } -- cgit From 8d9fb62a4593525a84104665d0a5318e16993d9e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 31 Dec 2007 03:02:39 +0100 Subject: Change net_conf_import() to only use libnet_conf API functions. More precisely, only import_process_service() is changed. This removes all references to registry code from net_conf.c. net_conf_import() is currently -- like net_conf_addshare() -- also considered a high-level add-on, not an API function. Michael (This used to be commit b4dca117c09ddb9c8e7eea25c6cde3fbef8c692b) --- source3/utils/net_conf.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9e4d4300d5..1882567d8b 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -191,7 +191,6 @@ static int import_process_service(TALLOC_CTX *ctx, struct parm_struct *parm; int pnum = 0; const char *servicename; - struct registry_key *key; WERROR werr; char *valstr = NULL; TALLOC_CTX *tmp_ctx = NULL; @@ -214,12 +213,6 @@ static int import_process_service(TALLOC_CTX *ctx, goto done; } } - werr = libnet_smbconf_reg_createkey_internal(tmp_ctx, servicename, &key); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error creating share %s: %s\n", - servicename, dos_errstr(werr)); - goto done; - } } while ((parm = lp_next_parameter(share->service, &pnum, 0))) @@ -234,8 +227,9 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); } else { - werr = libnet_smbconf_reg_setvalue_internal(key, - parm->label, valstr); + werr = libnet_smbconf_setparm(servicename, + parm->label, + valstr); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter '%s'" -- cgit From 4c7ef1c03e81f45270fddc4bd59f837d52bc34d8 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 31 Dec 2007 03:55:22 +0100 Subject: Make grouping in if statement more explicit. Michael (This used to be commit a1bb47695a7fb21af239aa9d02537d3de2fea325) --- source3/utils/net_conf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 1882567d8b..07eb3b890f 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -217,9 +217,11 @@ static int import_process_service(TALLOC_CTX *ctx, while ((parm = lp_next_parameter(share->service, &pnum, 0))) { - if ((share->service < 0 && parm->p_class == P_LOCAL) + if ((share->service < 0) && (parm->p_class == P_LOCAL) && !(parm->flags & FLAG_GLOBAL)) + { continue; + } valstr = parm_valstr(tmp_ctx, parm, share); -- cgit From fd597c7e6d1b5d89c75dd24f2b62916ec81a67ae Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 11:30:14 +0100 Subject: Add libnet_conf API function libnet_smbconf_create_share(). And make libnet_smbconf_setparm() return error if the share does not already exist. Adapt net_conf_addshare to this new situation. Michael (This used to be commit de349bd26db3341815f6d8f6c18a5ca1fd664dca) --- source3/utils/net_conf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 07eb3b890f..feee16f564 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -628,7 +628,18 @@ static int net_conf_addshare(int argc, const char **argv) } /* - * create the share by adding the parameters + * create the share + */ + + werr = libnet_smbconf_create_share(sharename); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error creating share %s: %s\n", + sharename, dos_errstr(werr)); + goto done; + } + + /* + * fill the share with parameters */ werr = libnet_smbconf_setparm(sharename, "path", path); -- cgit From 78acbddbd51a8201100a958447265ad9d7f46229 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 12:08:49 +0100 Subject: Happy new year again. Michael (This used to be commit e568f42e2146fa6510a86746581409450887ff16) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index feee16f564..6c61c24a52 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -2,7 +2,7 @@ * Samba Unix/Linux SMB client library * Distributed SMB/CIFS Server Management Utility * Local configuration interface - * Copyright (C) Michael Adam 2007 + * Copyright (C) Michael Adam 2007-2008 * * 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 -- cgit From 05ff62cf78447dc8caacf4a9d0b4b746f8d8e481 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 13:48:56 +0100 Subject: Rename libnet_smbconf_drop() to libnet_conf_drop(). Michael (This used to be commit 42ae33a96228e916d7d530d844be6937a80d4fea) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 6c61c24a52..2f94f3b722 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -447,7 +447,7 @@ static int net_conf_drop(int argc, const char **argv) goto done; } - werr = libnet_smbconf_drop(); + werr = libnet_conf_drop(); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting configuration: %s\n", dos_errstr(werr)); -- cgit From 90837d048b18ae72199b6f7ed7e1d17b0cc71102 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 13:50:55 +0100 Subject: Rename libnet_smbconf_get_config() to libnet_conf_get_config(). Michael (This used to be commit e8f7c07699b5b93acd81b24bca908769f0b5e8d8) --- source3/utils/net_conf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 2f94f3b722..7730187e7d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -291,9 +291,9 @@ static int net_conf_list(int argc, const char **argv) goto done; } - werr = libnet_smbconf_get_config(ctx, &num_shares, &share_names, - &num_params, ¶m_names, - ¶m_values); + werr = libnet_conf_get_config(ctx, &num_shares, &share_names, + &num_params, ¶m_names, + ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error getting config: %s\n", dos_errstr(werr)); -- cgit From daf1a460c821f247c43c22f1e26785d3acdb3ac3 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 13:53:04 +0100 Subject: Rename libnet_smbconf_get_share_names() to libnet_conf_get_share_names(). Michael (This used to be commit 2e4beee66b3672c3259b312aca3d482598731119) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 7730187e7d..930d7b3508 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -420,7 +420,7 @@ static int net_conf_listshares(int argc, const char **argv) goto done; } - werr = libnet_smbconf_get_share_names(ctx, &num_shares, &share_names); + werr = libnet_conf_get_share_names(ctx, &num_shares, &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 630de5f555b7fb897e1bb700b2a0a3d8d611e9bd Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 13:54:31 +0100 Subject: Rename libnet_smbconf_share_exists() to libnet_conf_share_exists(). Michael (This used to be commit 3258758e5c8dfc2c681e1285cb34aaacae697a55) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 930d7b3508..be1447f182 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -207,7 +207,7 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (libnet_smbconf_share_exists(servicename)) { + if (libnet_conf_share_exists(servicename)) { werr = libnet_smbconf_delshare(servicename); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -596,7 +596,7 @@ static int net_conf_addshare(int argc, const char **argv) goto done; } - if (libnet_smbconf_share_exists(sharename)) { + if (libnet_conf_share_exists(sharename)) { d_fprintf(stderr, "ERROR: share %s already exists.\n", sharename); goto done; -- cgit From 3f3a29ed509916751e8ead326dba3e2221cab199 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 13:55:43 +0100 Subject: Rename libnet_smbconf_create_share() to libnet_conf_create_share(). Michael (This used to be commit 6bc4ee210855dbfbee9e86b59e90b08ecb3a9df9) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index be1447f182..c080da2d91 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -631,7 +631,7 @@ static int net_conf_addshare(int argc, const char **argv) * create the share */ - werr = libnet_smbconf_create_share(sharename); + werr = libnet_conf_create_share(sharename); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error creating share %s: %s\n", sharename, dos_errstr(werr)); -- cgit From e1aa474a32a8b6faa952ad4e9e2e91b8727ad56e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 13:59:14 +0100 Subject: Rename libnet_smbconf_getshare() to libnet_conf_get_share(). Michael (This used to be commit 1575612f1936312125e7778a9a4227e444ea36cf) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c080da2d91..7859e0e615 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -480,8 +480,8 @@ static int net_conf_showshare(int argc, const char **argv) sharename = argv[0]; - werr = libnet_smbconf_getshare(ctx, sharename, &num_params, - ¶m_names, ¶m_values); + werr = libnet_conf_get_share(ctx, sharename, &num_params, + ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_printf("error getting share parameters: %s\n", dos_errstr(werr)); -- cgit From e89411effda51f9012d1830d18adcb968637baac Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 14:01:50 +0100 Subject: Rename libnet_smbconf_delshare() to libnet_conf_delete_share(). Michael (This used to be commit 2075baf551ca7fc6bcee6b93f63fd7fbf75f9a50) --- source3/utils/net_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 7859e0e615..340cb37541 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -208,7 +208,7 @@ static int import_process_service(TALLOC_CTX *ctx, d_printf("[%s]\n", servicename); } else { if (libnet_conf_share_exists(servicename)) { - werr = libnet_smbconf_delshare(servicename); + werr = libnet_conf_delete_share(servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -691,7 +691,7 @@ static int net_conf_delshare(int argc, const char **argv) } sharename = argv[0]; - werr = libnet_smbconf_delshare(sharename); + werr = libnet_conf_delete_share(sharename); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting share %s: %s\n", sharename, dos_errstr(werr)); -- cgit From b9f904b59d867c290675ec1013218ba7333253c5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 14:06:09 +0100 Subject: Rename libnet_smbconf_setparm() to libnet_conf_set_parameter(). Michael (This used to be commit e00cb415d30b3e72ccfb7e5c366c95ec0f9c6247) --- source3/utils/net_conf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 340cb37541..c8de6a555b 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -229,9 +229,9 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); } else { - werr = libnet_smbconf_setparm(servicename, - parm->label, - valstr); + werr = libnet_conf_set_parameter(servicename, + parm->label, + valstr); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter '%s'" @@ -642,7 +642,7 @@ static int net_conf_addshare(int argc, const char **argv) * fill the share with parameters */ - werr = libnet_smbconf_setparm(sharename, "path", path); + werr = libnet_conf_set_parameter(sharename, "path", path); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "path", dos_errstr(werr)); @@ -650,7 +650,7 @@ static int net_conf_addshare(int argc, const char **argv) } if (comment != NULL) { - werr = libnet_smbconf_setparm(sharename, "comment", comment); + werr = libnet_conf_set_parameter(sharename, "comment", comment); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "comment", dos_errstr(werr)); @@ -658,14 +658,14 @@ static int net_conf_addshare(int argc, const char **argv) } } - werr = libnet_smbconf_setparm(sharename, "guest ok", guest_ok); + werr = libnet_conf_set_parameter(sharename, "guest ok", guest_ok); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "'guest ok'", dos_errstr(werr)); goto done; } - werr = libnet_smbconf_setparm(sharename, "writeable", writeable); + werr = libnet_conf_set_parameter(sharename, "writeable", writeable); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "writeable", dos_errstr(werr)); @@ -719,7 +719,7 @@ static int net_conf_setparm(int argc, const char **argv) param = strdup_lower(argv[1]); value_str = argv[2]; - werr = libnet_smbconf_setparm(service, param, value_str); + werr = libnet_conf_set_parameter(service, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", -- cgit From 55771b356d632ffe7d1d773670a71366e3d7302a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 14:08:45 +0100 Subject: Rename libnet_smbconf_getparm() to libnet_conf_get_parameter(). Michael (This used to be commit d08556dbc7071933feaeec538f01ac8f6a637b1d) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c8de6a555b..c62c555ebe 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -753,7 +753,7 @@ static int net_conf_getparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_smbconf_getparm(ctx, service, param, &valstr); + werr = libnet_conf_get_parameter(ctx, service, param, &valstr); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, -- cgit From 2476254ccdf629d7889b9cff458a6e1097fc71ba Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 14:11:20 +0100 Subject: Rename libnet_smbconf_delparm() to libnet_conf_delete_parameter(). Michael (This used to be commit 073eeca51e46da6a687175aadbfdbb9e029532d6) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c62c555ebe..2d4b3f4054 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -795,7 +795,7 @@ static int net_conf_delparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_smbconf_delparm(service, param); + werr = libnet_conf_delete_parameter(service, param); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, -- cgit From 5470f8f638505b8dccc11ca0038632aa472608d8 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 15:33:09 +0100 Subject: Make libnet_conf handle opening/initialization of the registry. Open state is currently tracked by a global variable to avoid double initialization. Later, this can possibly be replaced by a conf-context created by an initialization function and passed around to the other api functions. Michael (This used to be commit 77713e776405800ac54c692a77cd4efd153042cb) --- source3/utils/net_conf.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 2d4b3f4054..a758391630 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -852,11 +852,6 @@ int net_conf(int argc, const char **argv) {NULL, NULL, NULL} }; - if (!registry_init_regdb()) { - d_fprintf(stderr, "Error initializing the registry!\n"); - goto done; - } - ret = net_run_function2(argc, argv, "net conf", func); regdb_close(); -- cgit From 77219ddd220649986fc4f1532271a832d25528bc Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 17:33:24 +0100 Subject: Fix build warning. Guenther (This used to be commit a43125d9e9052fab8eb561976f45d1db4622482e) --- source3/utils/net_conf.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index a758391630..63d5477c9d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -856,7 +856,6 @@ int net_conf(int argc, const char **argv) regdb_close(); -done: return ret; } -- cgit From 2a8722d4c3177077f5d6cc648f4ef42e38e0ab4d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Jan 2008 19:49:57 +0100 Subject: Fix the behaviour of "net conf setparm" to create the share if necessary. This moves functionality taken away from libnet_conf_set_parameter() to the higher level user frontend function. (Somehow I thought I had done this already ... :-) Michael (This used to be commit fc0fca980f08a0af65d82784ef5a50a7b1ac0927) --- source3/utils/net_conf.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 63d5477c9d..2df2410160 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -719,6 +719,15 @@ static int net_conf_setparm(int argc, const char **argv) param = strdup_lower(argv[1]); value_str = argv[2]; + if (!libnet_conf_share_exists(service)) { + werr = libnet_conf_create_share(service); + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, "Error creating share '%s': %s\n", + service, dos_errstr(werr)); + goto done; + } + } + werr = libnet_conf_set_parameter(service, param, value_str); if (!W_ERROR_IS_OK(werr)) { -- cgit From b1472c0956c6d016973c2a76e4dfce5ecc3b9c05 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Jan 2008 19:52:22 +0100 Subject: Remove the final regdb_close() from net_conf.c This is to hide the registry from net_conf. Right now, it does not harm if "net conf" does not close the registry file explicitly just before exiting. I am working out a proper way of handling open/close operations transparently in the libnet_conf library. Michael (This used to be commit 790ef789444945fbae5637f0b469665859171dcd) --- source3/utils/net_conf.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 2df2410160..d212b451bc 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -863,8 +863,6 @@ int net_conf(int argc, const char **argv) ret = net_run_function2(argc, argv, "net conf", func); - regdb_close(); - return ret; } -- cgit From 34fb7839658af03da0a5f3939777ceb6576dfb42 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Jan 2008 21:03:24 +0100 Subject: Update the introductory comment to net_conf.c to mention linbet_conf. Michael (This used to be commit e166b886375b450534c894676ab1f64571dd46b8) --- source3/utils/net_conf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index d212b451bc..f1bf330950 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -19,9 +19,13 @@ */ /* - * This is an interface to the configuration stored inside the - * samba registry. In the future there might be support for other - * configuration backends as well. + * This is an interface to the Samba's configuration as made available + * by the libnet_conf interface (source/libnet/libnet_conf.c). + * + * This currently supports local interaction with the configuration + * stored in the registry. But other backends and remote access via + * rpc (to registry stored configuration) might get implemented in + * the future. */ #include "includes.h" -- cgit From dee8e32d8d66fb07817f28780978cd2b928233ad Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Jan 2008 21:05:51 +0100 Subject: Remove the word "registry" from the help output of the "net conf" command. Michael (This used to be commit 8d9e3e08f3cc6a1f54661d1e54a3902ad50be191) --- source3/utils/net_conf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f1bf330950..1cf98aa3a2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -24,8 +24,7 @@ * * This currently supports local interaction with the configuration * stored in the registry. But other backends and remote access via - * rpc (to registry stored configuration) might get implemented in - * the future. + * rpc might get implemented in the future. */ #include "includes.h" @@ -847,15 +846,15 @@ int net_conf(int argc, const char **argv) {"import", net_conf_import, "Import configuration from file in smb.conf format."}, {"listshares", net_conf_listshares, - "List the registry shares."}, + "List the share names."}, {"drop", net_conf_drop, - "Delete the complete configuration from registry."}, + "Delete the complete configuration."}, {"showshare", net_conf_showshare, - "Show the definition of a registry share."}, + "Show the definition of a share."}, {"addshare", net_conf_addshare, - "Create a new registry share."}, + "Create a new share."}, {"delshare", net_conf_delshare, - "Delete a registry share."}, + "Delete a share."}, {"setparm", net_conf_setparm, "Store a parameter."}, {"getparm", net_conf_getparm, -- cgit From dbdaa5eeec62e2a643a8be36db0a30c20092b064 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Jan 2008 21:09:55 +0100 Subject: Fix a comment. Michael (This used to be commit fc9c3f39b5af55026f1e5e964857c203cf6c9316) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 1cf98aa3a2..52dcda03db 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -19,7 +19,7 @@ */ /* - * This is an interface to the Samba's configuration as made available + * This is an interface to Samba's configuration as made available * by the libnet_conf interface (source/libnet/libnet_conf.c). * * This currently supports local interaction with the configuration -- cgit From 517ad5318d3d196713b96f69eff8e2f5d38d922a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 4 Jan 2008 21:16:48 +0100 Subject: Fix spacing - spaces mixed with tabs. Michael (This used to be commit a4ef828102417f04af1e9823c89404e77e4fd5c1) --- source3/utils/net_conf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 52dcda03db..38cdeacc11 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -46,9 +46,9 @@ static int net_conf_import_usage(int argc, const char**argv) d_printf("USAGE: net conf import [--test|-T] " "[]\n" "\t[--test|-T] testmode - do not act, just print " - "what would be done\n" + "what would be done\n" "\t only import service , " - "ignore the rest\n"); + "ignore the rest\n"); return -1; } @@ -139,14 +139,14 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(bool *)ptr)); break; case P_ENUM: - for (i = 0; parm->enum_list[i].name; i++) { - if (*(int *)ptr == parm->enum_list[i].value) + for (i = 0; parm->enum_list[i].name; i++) { + if (*(int *)ptr == parm->enum_list[i].value) { valstr = talloc_asprintf(ctx, "%s", - parm->enum_list[i].name); - break; - } - } + parm->enum_list[i].name); + break; + } + } break; case P_OCTAL: { char *o = octal_string(*(int *)ptr); -- cgit From 1ee6d3e1ee56554d83437a8c79cb169a26732154 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Jan 2008 01:40:05 +0100 Subject: Introduce a libnet_conf context created by libnet_conf_open(). The libnet_conf_ctx stores the information necessary to interoperate with the configuration. It is created by calling libnet_conf_open() and destroyed by calling libnet_conf_close(). The context is passed to all the libnet_conf functions. It currently stores the token to access the registry. Later, it could store more data, e.g. the server to connect to, credentials, and so on. For support of other backends than registry or support of remote configuration, only the open function will have to be changed. In net_conf, the calls to the actual net_conf functions is wrapped into a function that calls libnet_conf_open()/_close(). Thus an individual variant of net_conf_runfunction2() and functable2 is used to cope with functions being called by the wrapper with the additional libnet_conf_ctx argument. Michael (This used to be commit c2a9346faa26e79af5948197a1b322e545f0ed09) --- source3/utils/net_conf.c | 141 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 106 insertions(+), 35 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 38cdeacc11..f212ed7b19 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -188,6 +188,7 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, } static int import_process_service(TALLOC_CTX *ctx, + struct libnet_conf_ctx *conf_ctx, struct share_params *share) { int ret = -1; @@ -210,8 +211,8 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (libnet_conf_share_exists(servicename)) { - werr = libnet_conf_delete_share(servicename); + if (libnet_conf_share_exists(conf_ctx, servicename)) { + werr = libnet_conf_delete_share(conf_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -232,7 +233,8 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); } else { - werr = libnet_conf_set_parameter(servicename, + werr = libnet_conf_set_parameter(conf_ctx, + servicename, parm->label, valstr); if (!W_ERROR_IS_OK(werr)) { @@ -275,7 +277,8 @@ static bool globals_exist(void) * the conf functions */ -static int net_conf_list(int argc, const char **argv) +static int net_conf_list(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { WERROR werr = WERR_OK; int ret = -1; @@ -294,9 +297,8 @@ static int net_conf_list(int argc, const char **argv) goto done; } - werr = libnet_conf_get_config(ctx, &num_shares, &share_names, - &num_params, ¶m_names, - ¶m_values); + werr = libnet_conf_get_config(ctx, conf_ctx, &num_shares, &share_names, + &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error getting config: %s\n", dos_errstr(werr)); @@ -322,7 +324,8 @@ done: return ret; } -static int net_conf_import(int argc, const char **argv) +static int net_conf_import(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; const char *filename = NULL; @@ -369,7 +372,7 @@ static int net_conf_import(int argc, const char **argv) strequal(servicename, GLOBAL_NAME)) { service_found = true; - if (import_process_service(ctx, &global_share) != 0) { + if (import_process_service(ctx, conf_ctx, &global_share) != 0) { goto done; } } @@ -388,7 +391,7 @@ static int net_conf_import(int argc, const char **argv) || strequal(servicename, lp_servicename(share->service))) { service_found = true; - if (import_process_service(ctx, share)!= 0) { + if (import_process_service(ctx, conf_ctx, share)!= 0) { goto done; } } @@ -408,7 +411,8 @@ done: return ret; } -static int net_conf_listshares(int argc, const char **argv) +static int net_conf_listshares(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { WERROR werr = WERR_OK; int ret = -1; @@ -423,7 +427,8 @@ static int net_conf_listshares(int argc, const char **argv) goto done; } - werr = libnet_conf_get_share_names(ctx, &num_shares, &share_names); + werr = libnet_conf_get_share_names(ctx, conf_ctx, &num_shares, + &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -440,7 +445,8 @@ done: return ret; } -static int net_conf_drop(int argc, const char **argv) +static int net_conf_drop(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; WERROR werr; @@ -450,7 +456,7 @@ static int net_conf_drop(int argc, const char **argv) goto done; } - werr = libnet_conf_drop(); + werr = libnet_conf_drop(conf_ctx); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting configuration: %s\n", dos_errstr(werr)); @@ -463,7 +469,8 @@ done: return ret; } -static int net_conf_showshare(int argc, const char **argv) +static int net_conf_showshare(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -483,7 +490,7 @@ static int net_conf_showshare(int argc, const char **argv) sharename = argv[0]; - werr = libnet_conf_get_share(ctx, sharename, &num_params, + werr = libnet_conf_get_share(ctx, conf_ctx, sharename, &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_printf("error getting share parameters: %s\n", @@ -511,7 +518,8 @@ done: * This is a high level utility function of the net conf utility, * not a direct frontend to the libnet_conf API. */ -static int net_conf_addshare(int argc, const char **argv) +static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -599,7 +607,7 @@ static int net_conf_addshare(int argc, const char **argv) goto done; } - if (libnet_conf_share_exists(sharename)) { + if (libnet_conf_share_exists(conf_ctx, sharename)) { d_fprintf(stderr, "ERROR: share %s already exists.\n", sharename); goto done; @@ -634,7 +642,7 @@ static int net_conf_addshare(int argc, const char **argv) * create the share */ - werr = libnet_conf_create_share(sharename); + werr = libnet_conf_create_share(conf_ctx, sharename); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error creating share %s: %s\n", sharename, dos_errstr(werr)); @@ -645,7 +653,7 @@ static int net_conf_addshare(int argc, const char **argv) * fill the share with parameters */ - werr = libnet_conf_set_parameter(sharename, "path", path); + werr = libnet_conf_set_parameter(conf_ctx, sharename, "path", path); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "path", dos_errstr(werr)); @@ -653,7 +661,8 @@ static int net_conf_addshare(int argc, const char **argv) } if (comment != NULL) { - werr = libnet_conf_set_parameter(sharename, "comment", comment); + werr = libnet_conf_set_parameter(conf_ctx, sharename, "comment", + comment); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "comment", dos_errstr(werr)); @@ -661,14 +670,16 @@ static int net_conf_addshare(int argc, const char **argv) } } - werr = libnet_conf_set_parameter(sharename, "guest ok", guest_ok); + werr = libnet_conf_set_parameter(conf_ctx, sharename, "guest ok", + guest_ok); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "'guest ok'", dos_errstr(werr)); goto done; } - werr = libnet_conf_set_parameter(sharename, "writeable", writeable); + werr = libnet_conf_set_parameter(conf_ctx, sharename, "writeable", + writeable); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "writeable", dos_errstr(werr)); @@ -682,7 +693,8 @@ done: return ret; } -static int net_conf_delshare(int argc, const char **argv) +static int net_conf_delshare(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; const char *sharename = NULL; @@ -694,7 +706,7 @@ static int net_conf_delshare(int argc, const char **argv) } sharename = argv[0]; - werr = libnet_conf_delete_share(sharename); + werr = libnet_conf_delete_share(conf_ctx, sharename); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting share %s: %s\n", sharename, dos_errstr(werr)); @@ -706,7 +718,8 @@ done: return ret; } -static int net_conf_setparm(int argc, const char **argv) +static int net_conf_setparm(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -722,8 +735,8 @@ static int net_conf_setparm(int argc, const char **argv) param = strdup_lower(argv[1]); value_str = argv[2]; - if (!libnet_conf_share_exists(service)) { - werr = libnet_conf_create_share(service); + if (!libnet_conf_share_exists(conf_ctx, service)) { + werr = libnet_conf_create_share(conf_ctx, service); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error creating share '%s': %s\n", service, dos_errstr(werr)); @@ -731,7 +744,7 @@ static int net_conf_setparm(int argc, const char **argv) } } - werr = libnet_conf_set_parameter(service, param, value_str); + werr = libnet_conf_set_parameter(conf_ctx, service, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", @@ -747,7 +760,8 @@ done: return ret; } -static int net_conf_getparm(int argc, const char **argv) +static int net_conf_getparm(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -765,7 +779,7 @@ static int net_conf_getparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_conf_get_parameter(ctx, service, param, &valstr); + werr = libnet_conf_get_parameter(ctx, conf_ctx, service, param, &valstr); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, @@ -793,7 +807,8 @@ done: return ret; } -static int net_conf_delparm(int argc, const char **argv) +static int net_conf_delparm(struct libnet_conf_ctx *conf_ctx, + int argc, const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -807,7 +822,7 @@ static int net_conf_delparm(int argc, const char **argv) service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_conf_delete_parameter(service, param); + werr = libnet_conf_delete_parameter(conf_ctx, service, param); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, @@ -833,6 +848,62 @@ done: return ret; } +static int net_conf_wrap_function(int (*fn)(struct libnet_conf_ctx *, + int, const char **), + int argc, const char **argv) +{ + WERROR werr; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct libnet_conf_ctx *conf_ctx; + int ret = -1; + + werr = libnet_conf_open(mem_ctx, &conf_ctx); + + if (!W_ERROR_IS_OK(werr)) { + return -1; + } + + ret = fn(conf_ctx, argc, argv); + + libnet_conf_close(conf_ctx); + + return ret; +} + +/* + * We need a functable struct of our own, because the + * functions are called through a wrapper that handles + * the opening and closing of the configuration, and so on. + */ +struct conf_functable { + const char *funcname; + int (*fn)(struct libnet_conf_ctx *ctx, int argc, const char **argv); + const char *helptext; +}; + +static int net_conf_run_function(int argc, const char **argv, + const char *whoami, + struct conf_functable *table) +{ + int i; + + if (argc != 0) { + for (i=0; table[i].funcname; i++) { + if (StrCaseCmp(argv[0], table[i].funcname) == 0) + return net_conf_wrap_function(table[i].fn, + argc-1, + argv+1); + } + } + + for (i=0; table[i].funcname; i++) { + d_printf("%s %-15s %s\n", whoami, table[i].funcname, + table[i].helptext); + } + + return -1; +} + /* * Entry-point for all the CONF functions. */ @@ -840,7 +911,7 @@ done: int net_conf(int argc, const char **argv) { int ret = -1; - struct functable2 func[] = { + struct conf_functable func_table[] = { {"list", net_conf_list, "Dump the complete configuration in smb.conf like format."}, {"import", net_conf_import, @@ -864,7 +935,7 @@ int net_conf(int argc, const char **argv) {NULL, NULL, NULL} }; - ret = net_run_function2(argc, argv, "net conf", func); + ret = net_conf_run_function(argc, argv, "net conf", func_table); return ret; } -- cgit From a6bf13ce971a87c1291082a4bc90fdca6d2b8c2b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Jan 2008 23:30:08 +0100 Subject: Add explicit creation of shares to net conf import function. It has been removed from libnet_conf_set_parameter(). Michael (This used to be commit b5c533b06cba9a8ffd28a1fb3bc56ab248340775) --- source3/utils/net_conf.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f212ed7b19..9a4f3ff69a 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -217,6 +217,10 @@ static int import_process_service(TALLOC_CTX *ctx, goto done; } } + werr = libnet_conf_create_share(conf_ctx, servicename); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } } while ((parm = lp_next_parameter(share->service, &pnum, 0))) -- cgit From 801eeaec09f9a53759185a834f42e3d266ec4bce Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Jan 2008 23:45:57 +0100 Subject: Add and modify comments in net_conf.c Michael (This used to be commit b3afc8391d40745328172ba012f0ffc166d75aa9) --- source3/utils/net_conf.c | 50 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 9a4f3ff69a..26ed41b2a0 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -31,9 +31,11 @@ #include "utils/net.h" #include "libnet/libnet.h" -/* +/********************************************************************** + * * usage functions - */ + * + **********************************************************************/ static int net_conf_list_usage(int argc, const char **argv) { @@ -109,10 +111,16 @@ static int net_conf_delparm_usage(int argc, const char **argv) } -/* +/********************************************************************** + * * Helper functions - */ + * + **********************************************************************/ +/** + * This formats an in-memory smbconf parameter to a string. + * The result string is allocated with talloc. + */ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, struct share_params *share) { @@ -187,6 +195,10 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, return valstr; } +/** + * This functions imports a configuration that has previously + * been loaded with lp_load() to registry. + */ static int import_process_service(TALLOC_CTX *ctx, struct libnet_conf_ctx *conf_ctx, struct share_params *share) @@ -263,7 +275,10 @@ done: return ret; } -/* return true iff there are nondefault globals */ +/** + * Return true iff there are nondefault globals in the + * currently loaded configuration. + */ static bool globals_exist(void) { int i = 0; @@ -277,9 +292,12 @@ static bool globals_exist(void) return false; } -/* - * the conf functions - */ + +/********************************************************************** + * + * the main conf functions + * + **********************************************************************/ static int net_conf_list(struct libnet_conf_ctx *conf_ctx, int argc, const char **argv) @@ -852,6 +870,18 @@ done: return ret; } + +/********************************************************************** + * + * Wrapper and net_conf_run_function mechanism. + * + **********************************************************************/ + +/** + * Wrapper function to call the main conf functions. + * The wrapper calls handles opening and closing of the + * configuration. + */ static int net_conf_wrap_function(int (*fn)(struct libnet_conf_ctx *, int, const char **), int argc, const char **argv) @@ -885,6 +915,10 @@ struct conf_functable { const char *helptext; }; +/** + * This imitates net_run_function2 but calls the main functions + * through the wrapper net_conf_wrap_function(). + */ static int net_conf_run_function(int argc, const char **argv, const char *whoami, struct conf_functable *table) -- 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/utils/net_conf.c | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 48 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 26ed41b2a0..21a3b2f7d2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -20,7 +20,7 @@ /* * This is an interface to Samba's configuration as made available - * by the libnet_conf interface (source/libnet/libnet_conf.c). + * by the libsmbconf interface (source/lib/smbconf/smbconf.c). * * This currently supports local interaction with the configuration * stored in the registry. But other backends and remote access via @@ -29,7 +29,6 @@ #include "includes.h" #include "utils/net.h" -#include "libnet/libnet.h" /********************************************************************** * @@ -200,7 +199,7 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, * been loaded with lp_load() to registry. */ static int import_process_service(TALLOC_CTX *ctx, - struct libnet_conf_ctx *conf_ctx, + struct smbconf_ctx *conf_ctx, struct share_params *share) { int ret = -1; @@ -223,13 +222,13 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (libnet_conf_share_exists(conf_ctx, servicename)) { - werr = libnet_conf_delete_share(conf_ctx, servicename); + if (smbconf_share_exists(conf_ctx, servicename)) { + werr = smbconf_delete_share(conf_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = libnet_conf_create_share(conf_ctx, servicename); + werr = smbconf_create_share(conf_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -249,10 +248,10 @@ static int import_process_service(TALLOC_CTX *ctx, if (opt_testmode) { d_printf("\t%s = %s\n", parm->label, valstr); } else { - werr = libnet_conf_set_parameter(conf_ctx, - servicename, - parm->label, - valstr); + werr = smbconf_set_parameter(conf_ctx, + servicename, + parm->label, + valstr); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter '%s'" @@ -299,7 +298,7 @@ static bool globals_exist(void) * **********************************************************************/ -static int net_conf_list(struct libnet_conf_ctx *conf_ctx, +static int net_conf_list(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr = WERR_OK; @@ -319,8 +318,8 @@ static int net_conf_list(struct libnet_conf_ctx *conf_ctx, goto done; } - werr = libnet_conf_get_config(ctx, conf_ctx, &num_shares, &share_names, - &num_params, ¶m_names, ¶m_values); + werr = smbconf_get_config(ctx, conf_ctx, &num_shares, &share_names, + &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error getting config: %s\n", dos_errstr(werr)); @@ -346,7 +345,7 @@ done: return ret; } -static int net_conf_import(struct libnet_conf_ctx *conf_ctx, +static int net_conf_import(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -433,7 +432,7 @@ done: return ret; } -static int net_conf_listshares(struct libnet_conf_ctx *conf_ctx, +static int net_conf_listshares(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr = WERR_OK; @@ -449,8 +448,8 @@ static int net_conf_listshares(struct libnet_conf_ctx *conf_ctx, goto done; } - werr = libnet_conf_get_share_names(ctx, conf_ctx, &num_shares, - &share_names); + werr = smbconf_get_share_names(ctx, conf_ctx, &num_shares, + &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -467,7 +466,7 @@ done: return ret; } -static int net_conf_drop(struct libnet_conf_ctx *conf_ctx, +static int net_conf_drop(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -478,7 +477,7 @@ static int net_conf_drop(struct libnet_conf_ctx *conf_ctx, goto done; } - werr = libnet_conf_drop(conf_ctx); + werr = smbconf_drop(conf_ctx); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting configuration: %s\n", dos_errstr(werr)); @@ -491,7 +490,7 @@ done: return ret; } -static int net_conf_showshare(struct libnet_conf_ctx *conf_ctx, +static int net_conf_showshare(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -512,8 +511,8 @@ static int net_conf_showshare(struct libnet_conf_ctx *conf_ctx, sharename = argv[0]; - werr = libnet_conf_get_share(ctx, conf_ctx, sharename, &num_params, - ¶m_names, ¶m_values); + werr = smbconf_get_share(ctx, conf_ctx, sharename, &num_params, + ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_printf("error getting share parameters: %s\n", dos_errstr(werr)); @@ -538,9 +537,9 @@ done: * Add a share, with a couple of standard parameters, partly optional. * * This is a high level utility function of the net conf utility, - * not a direct frontend to the libnet_conf API. + * not a direct frontend to the smbconf API. */ -static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, +static int net_conf_addshare(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -629,7 +628,7 @@ static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, goto done; } - if (libnet_conf_share_exists(conf_ctx, sharename)) { + if (smbconf_share_exists(conf_ctx, sharename)) { d_fprintf(stderr, "ERROR: share %s already exists.\n", sharename); goto done; @@ -664,7 +663,7 @@ static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, * create the share */ - werr = libnet_conf_create_share(conf_ctx, sharename); + werr = smbconf_create_share(conf_ctx, sharename); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error creating share %s: %s\n", sharename, dos_errstr(werr)); @@ -675,7 +674,7 @@ static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, * fill the share with parameters */ - werr = libnet_conf_set_parameter(conf_ctx, sharename, "path", path); + werr = smbconf_set_parameter(conf_ctx, sharename, "path", path); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "path", dos_errstr(werr)); @@ -683,8 +682,8 @@ static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, } if (comment != NULL) { - werr = libnet_conf_set_parameter(conf_ctx, sharename, "comment", - comment); + werr = smbconf_set_parameter(conf_ctx, sharename, "comment", + comment); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "comment", dos_errstr(werr)); @@ -692,16 +691,15 @@ static int net_conf_addshare(struct libnet_conf_ctx *conf_ctx, } } - werr = libnet_conf_set_parameter(conf_ctx, sharename, "guest ok", - guest_ok); + werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "'guest ok'", dos_errstr(werr)); goto done; } - werr = libnet_conf_set_parameter(conf_ctx, sharename, "writeable", - writeable); + werr = smbconf_set_parameter(conf_ctx, sharename, "writeable", + writeable); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "writeable", dos_errstr(werr)); @@ -715,7 +713,7 @@ done: return ret; } -static int net_conf_delshare(struct libnet_conf_ctx *conf_ctx, +static int net_conf_delshare(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -728,7 +726,7 @@ static int net_conf_delshare(struct libnet_conf_ctx *conf_ctx, } sharename = argv[0]; - werr = libnet_conf_delete_share(conf_ctx, sharename); + werr = smbconf_delete_share(conf_ctx, sharename); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error deleting share %s: %s\n", sharename, dos_errstr(werr)); @@ -740,7 +738,7 @@ done: return ret; } -static int net_conf_setparm(struct libnet_conf_ctx *conf_ctx, +static int net_conf_setparm(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -757,8 +755,8 @@ static int net_conf_setparm(struct libnet_conf_ctx *conf_ctx, param = strdup_lower(argv[1]); value_str = argv[2]; - if (!libnet_conf_share_exists(conf_ctx, service)) { - werr = libnet_conf_create_share(conf_ctx, service); + if (!smbconf_share_exists(conf_ctx, service)) { + werr = smbconf_create_share(conf_ctx, service); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error creating share '%s': %s\n", service, dos_errstr(werr)); @@ -766,7 +764,7 @@ static int net_conf_setparm(struct libnet_conf_ctx *conf_ctx, } } - werr = libnet_conf_set_parameter(conf_ctx, service, param, value_str); + werr = smbconf_set_parameter(conf_ctx, service, param, value_str); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting value '%s': %s\n", @@ -782,7 +780,7 @@ done: return ret; } -static int net_conf_getparm(struct libnet_conf_ctx *conf_ctx, +static int net_conf_getparm(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -801,7 +799,7 @@ static int net_conf_getparm(struct libnet_conf_ctx *conf_ctx, service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_conf_get_parameter(ctx, conf_ctx, service, param, &valstr); + werr = smbconf_get_parameter(ctx, conf_ctx, service, param, &valstr); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, @@ -829,7 +827,7 @@ done: return ret; } -static int net_conf_delparm(struct libnet_conf_ctx *conf_ctx, +static int net_conf_delparm(struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -844,7 +842,7 @@ static int net_conf_delparm(struct libnet_conf_ctx *conf_ctx, service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = libnet_conf_delete_parameter(conf_ctx, service, param); + werr = smbconf_delete_parameter(conf_ctx, service, param); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, @@ -882,16 +880,16 @@ done: * The wrapper calls handles opening and closing of the * configuration. */ -static int net_conf_wrap_function(int (*fn)(struct libnet_conf_ctx *, +static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, int, const char **), int argc, const char **argv) { WERROR werr; TALLOC_CTX *mem_ctx = talloc_stackframe(); - struct libnet_conf_ctx *conf_ctx; + struct smbconf_ctx *conf_ctx; int ret = -1; - werr = libnet_conf_open(mem_ctx, &conf_ctx); + werr = smbconf_open(mem_ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { return -1; @@ -899,7 +897,7 @@ static int net_conf_wrap_function(int (*fn)(struct libnet_conf_ctx *, ret = fn(conf_ctx, argc, argv); - libnet_conf_close(conf_ctx); + smbconf_close(conf_ctx); return ret; } @@ -911,7 +909,7 @@ static int net_conf_wrap_function(int (*fn)(struct libnet_conf_ctx *, */ struct conf_functable { const char *funcname; - int (*fn)(struct libnet_conf_ctx *ctx, int argc, const char **argv); + int (*fn)(struct smbconf_ctx *ctx, int argc, const char **argv); const char *helptext; }; -- 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/utils/net_conf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 21a3b2f7d2..d4437cd122 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -318,7 +318,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, goto done; } - werr = smbconf_get_config(ctx, conf_ctx, &num_shares, &share_names, + werr = smbconf_get_config(conf_ctx, ctx, &num_shares, &share_names, &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error getting config: %s\n", @@ -448,7 +448,7 @@ static int net_conf_listshares(struct smbconf_ctx *conf_ctx, goto done; } - werr = smbconf_get_share_names(ctx, conf_ctx, &num_shares, + werr = smbconf_get_share_names(conf_ctx, ctx, &num_shares, &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -511,7 +511,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, sharename = argv[0]; - werr = smbconf_get_share(ctx, conf_ctx, sharename, &num_params, + werr = smbconf_get_share(conf_ctx, ctx, sharename, &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_printf("error getting share parameters: %s\n", @@ -799,7 +799,7 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = smbconf_get_parameter(ctx, conf_ctx, service, param, &valstr); + werr = smbconf_get_parameter(conf_ctx, ctx, service, param, &valstr); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, -- 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/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index d4437cd122..3af3bd0839 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -889,7 +889,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, struct smbconf_ctx *conf_ctx; int ret = -1; - werr = smbconf_open(mem_ctx, &conf_ctx); + werr = smbconf_init(mem_ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { return -1; -- 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/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 3af3bd0839..118196976d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -897,7 +897,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, ret = fn(conf_ctx, argc, argv); - smbconf_close(conf_ctx); + smbconf_shutdown(conf_ctx); return ret; } -- 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/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 118196976d..cde3ab0a92 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -889,7 +889,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, struct smbconf_ctx *conf_ctx; int ret = -1; - werr = smbconf_init(mem_ctx, &conf_ctx); + werr = smbconf_init_reg(mem_ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { return -1; -- 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/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index cde3ab0a92..d108fe14d2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -889,7 +889,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, struct smbconf_ctx *conf_ctx; int ret = -1; - werr = smbconf_init_reg(mem_ctx, &conf_ctx); + werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL); if (!W_ERROR_IS_OK(werr)) { return -1; -- cgit From ca2f9297c2f5ddac7f165298b1db401c140933b4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Mar 2008 14:33:22 +0100 Subject: net_conf: fix import function by using the new text backend of smbconf. Originally, lp_load() was used to import files to registry. This had several bugs. Most notably, options explicitly set to default values were silently dropped, and all parametric options were ignored. This new implementation reads config from the text backend and stuffs everything verbatim in to the registry backend. Michael (This used to be commit e41c6650f805eaf8bb009e34468dd2d311e52858) --- source3/utils/net_conf.c | 254 +++++++++++------------------------------------ 1 file changed, 59 insertions(+), 195 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index d108fe14d2..1baadc4807 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -117,178 +117,43 @@ static int net_conf_delparm_usage(int argc, const char **argv) **********************************************************************/ /** - * This formats an in-memory smbconf parameter to a string. - * The result string is allocated with talloc. + * This functions process a service previously loaded with libsmbconf. */ -static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, - struct share_params *share) +static WERROR import_process_service(struct smbconf_ctx *conf_ctx, + const char *servicename, + const uint32_t num_params, + const char **param_names, + const char **param_values) { - char *valstr = NULL; - int i = 0; - void *ptr = parm->ptr; - - if (parm->p_class == P_LOCAL && share->service >= 0) { - ptr = lp_local_ptr(share->service, ptr); - } - - switch (parm->type) { - case P_CHAR: - valstr = talloc_asprintf(ctx, "%c", *(char *)ptr); - break; - case P_STRING: - case P_USTRING: - valstr = talloc_asprintf(ctx, "%s", *(char **)ptr); - break; - case P_BOOL: - valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(bool *)ptr)); - break; - case P_BOOLREV: - valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(bool *)ptr)); - break; - case P_ENUM: - for (i = 0; parm->enum_list[i].name; i++) { - if (*(int *)ptr == parm->enum_list[i].value) - { - valstr = talloc_asprintf(ctx, "%s", - parm->enum_list[i].name); - break; - } - } - break; - case P_OCTAL: { - char *o = octal_string(*(int *)ptr); - valstr = talloc_move(ctx, &o); - break; - } - case P_LIST: - valstr = talloc_strdup(ctx, ""); - if ((char ***)ptr && *(char ***)ptr) { - char **list = *(char ***)ptr; - for (; *list; list++) { - /* surround strings with whitespace - * in double quotes */ - if (strchr_m(*list, ' ')) - { - valstr = talloc_asprintf_append( - valstr, "\"%s\"%s", - *list, - ((*(list+1))?", ":"")); - } else { - valstr = talloc_asprintf_append( - valstr, "%s%s", *list, - ((*(list+1))?", ":"")); - } - } - } - break; - case P_INTEGER: - valstr = talloc_asprintf(ctx, "%d", *(int *)ptr); - break; - case P_SEP: - break; - default: - valstr = talloc_asprintf(ctx, "\n"); - break; - } - - return valstr; -} - -/** - * This functions imports a configuration that has previously - * been loaded with lp_load() to registry. - */ -static int import_process_service(TALLOC_CTX *ctx, - struct smbconf_ctx *conf_ctx, - struct share_params *share) -{ - int ret = -1; - struct parm_struct *parm; - int pnum = 0; - const char *servicename; - WERROR werr; - char *valstr = NULL; - TALLOC_CTX *tmp_ctx = NULL; - - tmp_ctx = talloc_new(ctx); - if (tmp_ctx == NULL) { - werr = WERR_NOMEM; - goto done; - } - - servicename = (share->service == GLOBAL_SECTION_SNUM)? - GLOBAL_NAME : lp_servicename(share->service); + uint32_t idx; + WERROR werr = WERR_OK; if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - if (smbconf_share_exists(conf_ctx, servicename)) { - werr = smbconf_delete_share(conf_ctx, servicename); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - } - werr = smbconf_create_share(conf_ctx, servicename); + werr = smbconf_delete_share(conf_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } } - while ((parm = lp_next_parameter(share->service, &pnum, 0))) - { - if ((share->service < 0) && (parm->p_class == P_LOCAL) - && !(parm->flags & FLAG_GLOBAL)) - { - continue; - } - - valstr = parm_valstr(tmp_ctx, parm, share); - - if (parm->type != P_SEP) { - if (opt_testmode) { - d_printf("\t%s = %s\n", parm->label, valstr); - } else { - werr = smbconf_set_parameter(conf_ctx, - servicename, - parm->label, - valstr); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, - "Error setting parameter '%s'" - ": %s\n", parm->label, - dos_errstr(werr)); - goto done; - } + for (idx = 0; idx < num_params; idx ++) { + if (opt_testmode) { + d_printf("\t%s = %s\n", param_names[idx], + param_values[idx]); + } else { + werr = smbconf_set_parameter(conf_ctx, + servicename, + param_names[idx], + param_values[idx]); + if (!W_ERROR_IS_OK(werr)) { + goto done; } } } - if (opt_testmode) { - d_printf("\n"); - } - - ret = 0; - done: - TALLOC_FREE(tmp_ctx); - return ret; -} - -/** - * Return true iff there are nondefault globals in the - * currently loaded configuration. - */ -static bool globals_exist(void) -{ - int i = 0; - struct parm_struct *parm; - - while ((parm = lp_next_parameter(GLOBAL_SECTION_SNUM, &i, 0)) != NULL) { - if (parm->type != P_SEP) { - return true; - } - } - return false; + return werr; } @@ -351,11 +216,9 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, int ret = -1; const char *filename = NULL; const char *servicename = NULL; - bool service_found = false; TALLOC_CTX *ctx; - struct share_iterator *shares; - struct share_params *share; - struct share_params global_share = { GLOBAL_SECTION_SNUM }; + struct smbconf_ctx *txt_ctx; + WERROR werr; ctx = talloc_init("net_conf_import"); @@ -374,13 +237,8 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - if (!lp_load(filename, - false, /* global_only */ - true, /* save_defaults */ - false, /* add_ipc */ - true)) /* initialize_globals */ - { - d_fprintf(stderr, "Error parsing configuration file.\n"); + werr = smbconf_init_txt_simple(ctx, &txt_ctx, filename); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -389,42 +247,48 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, "would import the following configuration:\n\n"); } - if (((servicename == NULL) && globals_exist()) || - strequal(servicename, GLOBAL_NAME)) - { - service_found = true; - if (import_process_service(ctx, conf_ctx, &global_share) != 0) { + if (servicename != NULL) { + char **param_names, **param_values; + uint32_t num_params; + + werr = smbconf_get_share(txt_ctx, ctx, + servicename, + &num_params, + ¶m_names, + ¶m_values); + if (!W_ERROR_IS_OK(werr)) { goto done; } - } - - if (service_found && (servicename != NULL)) { - ret = 0; - goto done; - } + werr = import_process_service(conf_ctx, + servicename, + num_params, + param_names, + param_values); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } else { + char **share_names, ***param_names, ***param_values; + uint32_t num_shares, *num_params, sidx; - if (!(shares = share_list_all(ctx))) { - d_fprintf(stderr, "Could not list shares...\n"); - goto done; - } - while ((share = next_share(shares)) != NULL) { - if ((servicename == NULL) - || strequal(servicename, lp_servicename(share->service))) - { - service_found = true; - if (import_process_service(ctx, conf_ctx, share)!= 0) { + werr = smbconf_get_config(txt_ctx, ctx, + &num_shares, &share_names, + &num_params, ¶m_names, ¶m_values); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + for (sidx = 0; sidx < num_shares; sidx++) { + werr = import_process_service(conf_ctx, + share_names[sidx], + num_params[sidx], + param_names[sidx], + param_values[sidx]); + if (!W_ERROR_IS_OK(werr)) { goto done; } } } - if ((servicename != NULL) && !service_found) { - d_printf("Share %s not found in file %s\n", - servicename, filename); - goto done; - - } - ret = 0; done: -- cgit From c2acc30bcbed9081f21dc0e73bc96b5c9edd3516 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Mar 2008 14:34:21 +0100 Subject: net_conf: use talloc_stackframe() instead of talloc_init(). Michael (This used to be commit ab4fd03705c61114742d8438dece69b9c37c3b38) --- source3/utils/net_conf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 1baadc4807..8a7cc260a3 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -176,7 +176,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, char ***param_values; uint32_t share_count, param_count; - ctx = talloc_init("list"); + ctx = talloc_stackframe(); if (argc != 0) { net_conf_list_usage(argc, argv); @@ -220,7 +220,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, struct smbconf_ctx *txt_ctx; WERROR werr; - ctx = talloc_init("net_conf_import"); + ctx = talloc_stackframe(); switch (argc) { case 0: @@ -305,7 +305,7 @@ static int net_conf_listshares(struct smbconf_ctx *conf_ctx, char **share_names = NULL; TALLOC_CTX *ctx; - ctx = talloc_init("listshares"); + ctx = talloc_stackframe(); if (argc != 0) { net_conf_listshares_usage(argc, argv); @@ -366,7 +366,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, char **param_names; char **param_values; - ctx = talloc_init("showshare"); + ctx = talloc_stackframe(); if (argc != 1) { net_conf_showshare_usage(argc, argv); @@ -654,7 +654,7 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, char *valstr = NULL; TALLOC_CTX *ctx; - ctx = talloc_init("getparm"); + ctx = talloc_stackframe(); if (argc != 2) { net_conf_getparm_usage(argc, argv); -- cgit From 0234cc8bdd25b9727a658485c87e7c1e57ba3224 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Mar 2008 14:39:02 +0100 Subject: net_conf: rename "ctx" to "mem_ctx" for clarity. There are also smbconf contexts arount... Michael (This used to be commit 5171df66eb54c9819b3b40045755f5e9b2cf36c2) --- source3/utils/net_conf.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 8a7cc260a3..c21631dd5e 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -168,7 +168,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, { WERROR werr = WERR_OK; int ret = -1; - TALLOC_CTX *ctx; + TALLOC_CTX *mem_ctx; uint32_t num_shares; char **share_names; uint32_t *num_params; @@ -176,14 +176,14 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, char ***param_values; uint32_t share_count, param_count; - ctx = talloc_stackframe(); + mem_ctx = talloc_stackframe(); if (argc != 0) { net_conf_list_usage(argc, argv); goto done; } - werr = smbconf_get_config(conf_ctx, ctx, &num_shares, &share_names, + werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &share_names, &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error getting config: %s\n", @@ -206,7 +206,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, ret = 0; done: - TALLOC_FREE(ctx); + TALLOC_FREE(mem_ctx); return ret; } @@ -216,11 +216,11 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, int ret = -1; const char *filename = NULL; const char *servicename = NULL; - TALLOC_CTX *ctx; + TALLOC_CTX *mem_ctx; struct smbconf_ctx *txt_ctx; WERROR werr; - ctx = talloc_stackframe(); + mem_ctx = talloc_stackframe(); switch (argc) { case 0: @@ -237,7 +237,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - werr = smbconf_init_txt_simple(ctx, &txt_ctx, filename); + werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -251,7 +251,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, char **param_names, **param_values; uint32_t num_params; - werr = smbconf_get_share(txt_ctx, ctx, + werr = smbconf_get_share(txt_ctx, mem_ctx, servicename, &num_params, ¶m_names, @@ -271,7 +271,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, char **share_names, ***param_names, ***param_values; uint32_t num_shares, *num_params, sidx; - werr = smbconf_get_config(txt_ctx, ctx, + werr = smbconf_get_config(txt_ctx, mem_ctx, &num_shares, &share_names, &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { @@ -292,7 +292,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, ret = 0; done: - TALLOC_FREE(ctx); + TALLOC_FREE(mem_ctx); return ret; } @@ -303,16 +303,16 @@ static int net_conf_listshares(struct smbconf_ctx *conf_ctx, int ret = -1; uint32_t count, num_shares = 0; char **share_names = NULL; - TALLOC_CTX *ctx; + TALLOC_CTX *mem_ctx; - ctx = talloc_stackframe(); + mem_ctx = talloc_stackframe(); if (argc != 0) { net_conf_listshares_usage(argc, argv); goto done; } - werr = smbconf_get_share_names(conf_ctx, ctx, &num_shares, + werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares, &share_names); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -326,7 +326,7 @@ static int net_conf_listshares(struct smbconf_ctx *conf_ctx, ret = 0; done: - TALLOC_FREE(ctx); + TALLOC_FREE(mem_ctx); return ret; } @@ -360,13 +360,13 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, int ret = -1; WERROR werr = WERR_OK; const char *sharename = NULL; - TALLOC_CTX *ctx; + TALLOC_CTX *mem_ctx; uint32_t num_params; uint32_t count; char **param_names; char **param_values; - ctx = talloc_stackframe(); + mem_ctx = talloc_stackframe(); if (argc != 1) { net_conf_showshare_usage(argc, argv); @@ -375,7 +375,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, sharename = argv[0]; - werr = smbconf_get_share(conf_ctx, ctx, sharename, &num_params, + werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &num_params, ¶m_names, ¶m_values); if (!W_ERROR_IS_OK(werr)) { d_printf("error getting share parameters: %s\n", @@ -393,7 +393,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, ret = 0; done: - TALLOC_FREE(ctx); + TALLOC_FREE(mem_ctx); return ret; } @@ -652,9 +652,9 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, char *service = NULL; char *param = NULL; char *valstr = NULL; - TALLOC_CTX *ctx; + TALLOC_CTX *mem_ctx; - ctx = talloc_stackframe(); + mem_ctx = talloc_stackframe(); if (argc != 2) { net_conf_getparm_usage(argc, argv); @@ -663,7 +663,7 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, service = strdup_lower(argv[0]); param = strdup_lower(argv[1]); - werr = smbconf_get_parameter(conf_ctx, ctx, service, param, &valstr); + werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr); if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) { d_fprintf(stderr, @@ -687,7 +687,7 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, done: SAFE_FREE(service); SAFE_FREE(param); - TALLOC_FREE(ctx); + TALLOC_FREE(mem_ctx); return ret; } -- cgit From 3253cffced724bc825da913e669b0331cbe7ac65 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Mar 2008 14:45:34 +0100 Subject: net_conf: add casts to avoid compiler warnings. Michael (This used to be commit 1c6b9a0ac34c4a7b4e000300db8dffdbb09fe7da) --- source3/utils/net_conf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c21631dd5e..70827abfe1 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -262,8 +262,8 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, werr = import_process_service(conf_ctx, servicename, num_params, - param_names, - param_values); + (const char **)param_names, + (const char **)param_values); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -279,10 +279,10 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, } for (sidx = 0; sidx < num_shares; sidx++) { werr = import_process_service(conf_ctx, - share_names[sidx], - num_params[sidx], - param_names[sidx], - param_values[sidx]); + share_names[sidx], + num_params[sidx], + (const char **)param_names[sidx], + (const char **)param_values[sidx]); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 0bdcc557ee4d52d266b7ec6dee5d2381c0601ce1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 26 Mar 2008 14:46:43 +0100 Subject: net_conf: reformat - re-indent one function call. Michael (This used to be commit 9ef9d4c4e77523d7f3cc5fdac199559896e585bd) --- source3/utils/net_conf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 70827abfe1..630d01d0a0 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -272,8 +272,11 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, uint32_t num_shares, *num_params, sidx; werr = smbconf_get_config(txt_ctx, mem_ctx, - &num_shares, &share_names, - &num_params, ¶m_names, ¶m_values); + &num_shares, + &share_names, + &num_params, + ¶m_names, + ¶m_values); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 65b4a93c4ac381a669777c7d06611255e5e48263 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 27 Mar 2008 00:32:00 +0100 Subject: net_conf: fix non-testmode import function. Michael (This used to be commit cd17cc745a35db8ee158f59a5fff1f0f26cf9c6e) --- source3/utils/net_conf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 630d01d0a0..1e4ab9b3f2 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -131,7 +131,13 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); } else { - werr = smbconf_delete_share(conf_ctx, servicename); + if (smbconf_share_exists(conf_ctx, servicename)) { + werr = smbconf_delete_share(conf_ctx, servicename); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + werr = smbconf_create_share(conf_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -280,6 +286,10 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, if (!W_ERROR_IS_OK(werr)) { goto done; } + werr = smbconf_drop(conf_ctx); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } for (sidx = 0; sidx < num_shares; sidx++) { werr = import_process_service(conf_ctx, share_names[sidx], -- cgit From 3d38f143df70d9e55d7112bf3b70b6c029d9397d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 7 Apr 2008 22:33:01 +0200 Subject: libsmbconf: add a "verbatim" parameter to smbconf_init_txt_simple(). Michael (This used to be commit b9e72b402de412c23702715ead96c20e9b3248cc) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 1e4ab9b3f2..e2d88c019d 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -243,7 +243,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename); + werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename, true); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From a98c08c151b04b5e4a75abdb201d6a554137de39 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 01:20:36 +0200 Subject: net conf: fix import to correctly add includes (at the end) Michael (This used to be commit 3e81db83707e30ad46a565c9a118e7293b6cdf50) --- source3/utils/net_conf.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index e2d88c019d..c01a326c64 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -127,6 +127,9 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, { uint32_t idx; WERROR werr = WERR_OK; + uint32_t num_includes = 0; + char **includes = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); if (opt_testmode) { d_printf("[%s]\n", servicename); @@ -148,17 +151,42 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, d_printf("\t%s = %s\n", param_names[idx], param_values[idx]); } else { - werr = smbconf_set_parameter(conf_ctx, - servicename, - param_names[idx], - param_values[idx]); - if (!W_ERROR_IS_OK(werr)) { - goto done; + if (strequal(param_names[idx], "include")) { + includes = TALLOC_REALLOC_ARRAY(mem_ctx, + includes, + char *, + num_includes+1); + if (includes == NULL) { + werr = WERR_NOMEM; + goto done; + } + includes[num_includes] = + talloc_strdup(includes, + param_values[idx]); + if (includes[num_includes] == NULL) { + werr = WERR_NOMEM; + goto done; + } + num_includes++; + } else { + werr = smbconf_set_parameter(conf_ctx, + servicename, + param_names[idx], + param_values[idx]); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } } } } + if (!opt_testmode) { + werr = smbconf_set_includes(conf_ctx, servicename, num_includes, + (const char **)includes); + } + done: + TALLOC_FREE(mem_ctx); return werr; } -- cgit From 2a94369946a896e12d6527a299f39c265d8dbaa2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 01:27:30 +0200 Subject: net conf: don't drop config in testmode Michael (This used to be commit 74e87b977514df79e49613a0b1c5157469b3cb93) --- source3/utils/net_conf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index c01a326c64..f74ba98f54 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -314,9 +314,11 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = smbconf_drop(conf_ctx); - if (!W_ERROR_IS_OK(werr)) { - goto done; + if (!opt_testmode) { + werr = smbconf_drop(conf_ctx); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } } for (sidx = 0; sidx < num_shares; sidx++) { werr = import_process_service(conf_ctx, -- cgit From 52a16b4945e68dc4a0d0c762e0019b554469ae75 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 14:59:05 +0200 Subject: net conf: reduce indentation by grouping testmode code together. Michael (This used to be commit 97f9cb857532328999589062ceb0b229bcaf93a3) --- source3/utils/net_conf.c | 76 +++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f74ba98f54..575bfb89ca 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -133,57 +133,55 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, if (opt_testmode) { d_printf("[%s]\n", servicename); - } else { - if (smbconf_share_exists(conf_ctx, servicename)) { - werr = smbconf_delete_share(conf_ctx, servicename); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } + for (idx = 0; idx < num_params; idx ++) { + d_printf("\t%s = %s\n", param_names[idx], + param_values[idx]); } - werr = smbconf_create_share(conf_ctx, servicename); + d_printf("\n"); + goto done; + } + + if (smbconf_share_exists(conf_ctx, servicename)) { + werr = smbconf_delete_share(conf_ctx, servicename); if (!W_ERROR_IS_OK(werr)) { goto done; } } + werr = smbconf_create_share(conf_ctx, servicename); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } for (idx = 0; idx < num_params; idx ++) { - if (opt_testmode) { - d_printf("\t%s = %s\n", param_names[idx], - param_values[idx]); + if (strequal(param_names[idx], "include")) { + includes = TALLOC_REALLOC_ARRAY(mem_ctx, + includes, + char *, + num_includes+1); + if (includes == NULL) { + werr = WERR_NOMEM; + goto done; + } + includes[num_includes] = talloc_strdup(includes, + param_values[idx]); + if (includes[num_includes] == NULL) { + werr = WERR_NOMEM; + goto done; + } + num_includes++; } else { - if (strequal(param_names[idx], "include")) { - includes = TALLOC_REALLOC_ARRAY(mem_ctx, - includes, - char *, - num_includes+1); - if (includes == NULL) { - werr = WERR_NOMEM; - goto done; - } - includes[num_includes] = - talloc_strdup(includes, - param_values[idx]); - if (includes[num_includes] == NULL) { - werr = WERR_NOMEM; - goto done; - } - num_includes++; - } else { - werr = smbconf_set_parameter(conf_ctx, - servicename, - param_names[idx], - param_values[idx]); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } + werr = smbconf_set_parameter(conf_ctx, + servicename, + param_names[idx], + param_values[idx]); + if (!W_ERROR_IS_OK(werr)) { + goto done; } } } - if (!opt_testmode) { - werr = smbconf_set_includes(conf_ctx, servicename, num_includes, - (const char **)includes); - } + werr = smbconf_set_includes(conf_ctx, servicename, num_includes, + (const char **)includes); done: TALLOC_FREE(mem_ctx); -- cgit From 9765828d973c647205e933eda9992d8695687461 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 15:17:28 +0200 Subject: net conf: add diagnostic message for failure to load text file. Michael (This used to be commit 8f2c3efa679d44acc900fb90f03319e830a7dcf4) --- source3/utils/net_conf.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 575bfb89ca..6f99df2c90 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -271,6 +271,8 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename, true); if (!W_ERROR_IS_OK(werr)) { + d_printf("error loading file '%s': %s\n", filename, + dos_errstr(werr)); goto done; } -- cgit From 68fb75857bdac02fcc7178f546d8c800329f89c6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 15:37:33 +0200 Subject: net conf: implement "net conf getincludes". Michael (This used to be commit 30bc48623cf4f9ee17ff9c3e7a9fd98840a01d92) --- source3/utils/net_conf.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 6f99df2c90..b4565085a5 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -109,6 +109,11 @@ static int net_conf_delparm_usage(int argc, const char **argv) return -1; } +static int net_conf_getincludes_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf getincludes
\n"); + return -1; +} /********************************************************************** * @@ -775,6 +780,46 @@ done: return ret; } +static int net_conf_getincludes(struct smbconf_ctx *conf_ctx, + int argc, const char **argv) +{ + WERROR werr; + uint32_t num_includes; + uint32_t count; + char *service; + char **includes = NULL; + int ret = -1; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + if (argc != 1) { + net_conf_getincludes_usage(argc, argv); + goto done; + } + + service = talloc_strdup_lower(mem_ctx, argv[0]); + if (service == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + + werr = smbconf_get_includes(conf_ctx, mem_ctx, service, + &num_includes, &includes); + if (!W_ERROR_IS_OK(werr)) { + d_printf("error getting includes: %s\n", dos_errstr(werr)); + goto done; + } + + for (count = 0; count < num_includes; count++) { + d_printf("include = %s\n", includes[count]); + } + + ret = 0; + +done: + TALLOC_FREE(mem_ctx); + return ret; +} + /********************************************************************** * @@ -875,6 +920,8 @@ int net_conf(int argc, const char **argv) "Retrieve the value of a parameter."}, {"delparm", net_conf_delparm, "Delete a parameter."}, + {"getincludes", net_conf_getincludes, + "Show the includes of a share definition."}, {NULL, NULL, NULL} }; -- cgit From f3cfc1446e923104f7aba13c519af8f706749eaf Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 18:46:38 +0200 Subject: net conf: implement a "net conf setincludes" command. given zero or more filenames as command line parameters Michael (This used to be commit ab51e4d44c3dcd00697c8ffb2ce628c4072c7a53) --- source3/utils/net_conf.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index b4565085a5..e6957d0f3e 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -115,6 +115,13 @@ static int net_conf_getincludes_usage(int argc, const char **argv) return -1; } +static int net_conf_setincludes_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf setincludes
[]*\n"); + return -1; +} + + /********************************************************************** * * Helper functions @@ -820,6 +827,47 @@ done: return ret; } +static int net_conf_setincludes(struct smbconf_ctx *conf_ctx, + int argc, const char **argv) +{ + WERROR werr; + char *service; + uint32_t num_includes; + const char **includes; + int ret = -1; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + if (argc < 1) { + net_conf_setincludes_usage(argc, argv); + goto done; + } + + service = talloc_strdup_lower(mem_ctx, argv[0]); + if (service == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + + num_includes = argc - 1; + if (num_includes == 0) { + includes = NULL; + } else { + includes = argv + 1; + } + + werr = smbconf_set_includes(conf_ctx, service, num_includes, includes); + if (!W_ERROR_IS_OK(werr)) { + d_printf("error setting includes: %s\n", dos_errstr(werr)); + goto done; + } + + ret = 0; + +done: + TALLOC_FREE(mem_ctx); + return ret; +} + /********************************************************************** * @@ -922,6 +970,8 @@ int net_conf(int argc, const char **argv) "Delete a parameter."}, {"getincludes", net_conf_getincludes, "Show the includes of a share definition."}, + {"setincludes", net_conf_setincludes, + "Set includes for a share."}, {NULL, NULL, NULL} }; -- cgit From 6f7fcdcda5aa4227c63cd2bd129cb0f2ca5c0009 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 23:24:52 +0200 Subject: net conf: implement "net conf delincludes". usage: "net conf delincludes " This is equivalent to "net conf setincludes " (without further arguments). Michael (This used to be commit a1d09f34ec39b614d738c6f795fe8eafaf634105) --- source3/utils/net_conf.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index e6957d0f3e..e83a2be524 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -121,6 +121,12 @@ static int net_conf_setincludes_usage(int argc, const char **argv) return -1; } +static int net_conf_delincludes_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf delincludes
\n"); + return -1; +} + /********************************************************************** * @@ -868,6 +874,38 @@ done: return ret; } +static int net_conf_delincludes(struct smbconf_ctx *conf_ctx, + int argc, const char **argv) +{ + WERROR werr; + char *service; + int ret = -1; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + if (argc != 1) { + net_conf_delincludes_usage(argc, argv); + goto done; + } + + service = talloc_strdup_lower(mem_ctx, argv[0]); + if (service == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + + werr = smbconf_delete_includes(conf_ctx, service); + if (!W_ERROR_IS_OK(werr)) { + d_printf("error deleting includes: %s\n", dos_errstr(werr)); + goto done; + } + + ret = 0; + +done: + TALLOC_FREE(mem_ctx); + return ret; +} + /********************************************************************** * @@ -972,6 +1010,8 @@ int net_conf(int argc, const char **argv) "Show the includes of a share definition."}, {"setincludes", net_conf_setincludes, "Set includes for a share."}, + {"delincludes", net_conf_delincludes, + "Delete includes from a share definition."}, {NULL, NULL, NULL} }; -- cgit From bfc4aba3988da46addddd1b6f62462aa2b1a3d0d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 23:48:45 +0200 Subject: net conf: use talloc and talloc_strdup_lower throughout all net conf functions. Michael (This used to be commit 977cc9898970a0c07c30264e91754740c640e235) --- source3/utils/net_conf.c | 76 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 17 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index e83a2be524..7221f3bd68 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -278,7 +278,11 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, net_conf_import_usage(argc, argv); goto done; case 2: - servicename = argv[1]; + servicename = talloc_strdup_lower(mem_ctx, argv[1]); + if (servicename == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } case 1: filename = argv[0]; break; @@ -434,7 +438,11 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, goto done; } - sharename = argv[0]; + sharename = talloc_strdup_lower(mem_ctx, argv[0]); + if (sharename == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &num_params, ¶m_names, ¶m_values); @@ -475,6 +483,7 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, const char *guest_ok = "no"; const char *writeable = "no"; SMB_STRUCT_STAT sbuf; + TALLOC_CTX *mem_ctx = talloc_stackframe(); switch (argc) { case 0: @@ -522,7 +531,12 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, } case 2: path = argv[1]; - sharename = strdup_lower(argv[0]); + sharename = talloc_strdup_lower(mem_ctx, argv[0]); + if (sharename == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + break; } @@ -634,7 +648,7 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, ret = 0; done: - SAFE_FREE(sharename); + TALLOC_FREE(mem_ctx); return ret; } @@ -644,12 +658,17 @@ static int net_conf_delshare(struct smbconf_ctx *conf_ctx, int ret = -1; const char *sharename = NULL; WERROR werr = WERR_OK; + TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { net_conf_delshare_usage(argc, argv); goto done; } - sharename = argv[0]; + sharename = talloc_strdup_lower(mem_ctx, argv[0]); + if (sharename == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } werr = smbconf_delete_share(conf_ctx, sharename); if (!W_ERROR_IS_OK(werr)) { @@ -660,6 +679,7 @@ static int net_conf_delshare(struct smbconf_ctx *conf_ctx, ret = 0; done: + TALLOC_FREE(mem_ctx); return ret; } @@ -671,13 +691,22 @@ static int net_conf_setparm(struct smbconf_ctx *conf_ctx, char *service = NULL; char *param = NULL; const char *value_str = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 3) { net_conf_setparm_usage(argc, argv); goto done; } - service = strdup_lower(argv[0]); - param = strdup_lower(argv[1]); + service = talloc_strdup_lower(mem_ctx, argv[0]); + if (service == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + param = talloc_strdup_lower(mem_ctx, argv[1]); + if (param == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } value_str = argv[2]; if (!smbconf_share_exists(conf_ctx, service)) { @@ -700,8 +729,7 @@ static int net_conf_setparm(struct smbconf_ctx *conf_ctx, ret = 0; done: - SAFE_FREE(service); - SAFE_FREE(param); + TALLOC_FREE(mem_ctx); return ret; } @@ -721,8 +749,16 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, net_conf_getparm_usage(argc, argv); goto done; } - service = strdup_lower(argv[0]); - param = strdup_lower(argv[1]); + service = talloc_strdup_lower(mem_ctx, argv[0]); + if (service == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + param = talloc_strdup_lower(mem_ctx, argv[1]); + if (param == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr); @@ -746,8 +782,6 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, ret = 0; done: - SAFE_FREE(service); - SAFE_FREE(param); TALLOC_FREE(mem_ctx); return ret; } @@ -759,13 +793,22 @@ static int net_conf_delparm(struct smbconf_ctx *conf_ctx, WERROR werr = WERR_OK; char *service = NULL; char *param = NULL; + TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 2) { net_conf_delparm_usage(argc, argv); goto done; } - service = strdup_lower(argv[0]); - param = strdup_lower(argv[1]); + service = talloc_strdup_lower(mem_ctx, argv[0]); + if (service == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + param = talloc_strdup_lower(mem_ctx, argv[1]); + if (param == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } werr = smbconf_delete_parameter(conf_ctx, service, param); @@ -788,8 +831,7 @@ static int net_conf_delparm(struct smbconf_ctx *conf_ctx, ret = 0; done: - SAFE_FREE(service); - SAFE_FREE(param); + TALLOC_FREE(mem_ctx); return ret; } -- cgit From 35d6068f2504cc76728c3187c3e16171112dabca Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Apr 2008 16:32:05 +0200 Subject: libsmbconf: remove the bool verbatim parameter from txt backend init function. Always be verbatim for now. Backend config options may be added later via some private data pointer. Michael (This used to be commit e8bafcfbf4a7ab1dc1ce4f2acd24b0eb74933256) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 7221f3bd68..245a91fa3e 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -291,7 +291,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename, true); + werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename); if (!W_ERROR_IS_OK(werr)) { d_printf("error loading file '%s': %s\n", filename, dos_errstr(werr)); -- cgit From d2d82394a488471e54bd4931f892dc1640f9d80e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Apr 2008 17:16:54 +0200 Subject: net conf: use the new smbconf_init() dispatcher instead of explicit backend init. Michael (This used to be commit 281c9287a34533045b62302bb33ced3d216421ac) --- source3/utils/net_conf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 245a91fa3e..88cc15e0eb 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -266,6 +266,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, int ret = -1; const char *filename = NULL; const char *servicename = NULL; + char *conf_source = NULL; TALLOC_CTX *mem_ctx; struct smbconf_ctx *txt_ctx; WERROR werr; @@ -291,7 +292,13 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, DEBUG(3,("net_conf_import: reading configuration from file %s.\n", filename)); - werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename); + conf_source = talloc_asprintf(mem_ctx, "file:%s", filename); + if (conf_source == NULL) { + d_printf("error: out of memory!\n"); + goto done; + } + + werr = smbconf_init(mem_ctx, &txt_ctx, conf_source); if (!W_ERROR_IS_OK(werr)) { d_printf("error loading file '%s': %s\n", filename, dos_errstr(werr)); @@ -969,7 +976,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, struct smbconf_ctx *conf_ctx; int ret = -1; - werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL); + werr = smbconf_init(mem_ctx, &conf_ctx, "registry:"); if (!W_ERROR_IS_OK(werr)) { return -1; -- cgit From 7624bab9631b004815decfeced58ee72ebe125cb Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 14:38:36 +0200 Subject: net conf: fix output of out-of-share parameters in test mode import Michael (This used to be commit 5424e07e7d3e842488cba7ae389124f01221c5ba) --- source3/utils/net_conf.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 88cc15e0eb..7d1658ba94 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -150,10 +150,18 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (opt_testmode) { - d_printf("[%s]\n", servicename); - for (idx = 0; idx < num_params; idx ++) { - d_printf("\t%s = %s\n", param_names[idx], - param_values[idx]); + if (servicename != NULL) { + d_printf("[%s]\n", servicename); + for (idx = 0; idx < num_params; idx++) { + d_printf("\t%s = %s\n", param_names[idx], + param_values[idx]); + } + } + else { + for (idx = 0; idx < num_params; idx++) { + d_printf("%s = %s\n", param_names[idx], + param_values[idx]); + } } d_printf("\n"); goto done; -- cgit From 770b1923dc7735c2681c9976201569896feb74d9 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:36:11 +0200 Subject: net conf: simplify logic in test output of net conf import. Michael (This used to be commit 367c8b133b2f3e73155f20f689602909eef9827b) --- source3/utils/net_conf.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 7d1658ba94..293485aab1 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -150,18 +150,14 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (opt_testmode) { + const char *indent = ""; if (servicename != NULL) { d_printf("[%s]\n", servicename); - for (idx = 0; idx < num_params; idx++) { - d_printf("\t%s = %s\n", param_names[idx], - param_values[idx]); - } + indent = "\t"; } - else { - for (idx = 0; idx < num_params; idx++) { - d_printf("%s = %s\n", param_names[idx], - param_values[idx]); - } + for (idx = 0; idx < num_params; idx++) { + d_printf("%s%s = %s\n", indent, param_names[idx], + param_values[idx]); } d_printf("\n"); goto done; -- cgit From ed85ea4248688005d1769894f0b2f2e86d822fde Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:36:44 +0200 Subject: net conf: adapt output of NULL share params in net conf list. don't list NULL share name and don't indent these parameters Michael (This used to be commit 0212b38913945ce3c8b14734804d81f1cd315621) --- source3/utils/net_conf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 293485aab1..4fffcf8a8c 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -246,11 +246,16 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, } for (share_count = 0; share_count < num_shares; share_count++) { - d_printf("[%s]\n", share_names[share_count]); + const char *indent = ""; + if (share_names[share_count] != NULL) { + d_printf("[%s]\n", share_names[share_count]); + indent = "\t"; + } for (param_count = 0; param_count < num_params[share_count]; param_count++) { - d_printf("\t%s = %s\n", + d_printf("%s%s = %s\n", + indent, param_names[share_count][param_count], param_values[share_count][param_count]); } -- 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/utils/net_conf.c | 96 +++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 59 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 4fffcf8a8c..08a06eabd4 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -138,10 +138,7 @@ static int net_conf_delincludes_usage(int argc, const char **argv) * This functions process a service previously loaded with libsmbconf. */ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, - const char *servicename, - const uint32_t num_params, - const char **param_names, - const char **param_values) + struct smbconf_service *service) { uint32_t idx; WERROR werr = WERR_OK; @@ -151,31 +148,32 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, if (opt_testmode) { const char *indent = ""; - if (servicename != NULL) { - d_printf("[%s]\n", servicename); + if (service->name != NULL) { + d_printf("[%s]\n", service->name); indent = "\t"; } - for (idx = 0; idx < num_params; idx++) { - d_printf("%s%s = %s\n", indent, param_names[idx], - param_values[idx]); + for (idx = 0; idx < service->num_params; idx++) { + d_printf("%s%s = %s\n", indent, + service->param_names[idx], + service->param_values[idx]); } d_printf("\n"); goto done; } - if (smbconf_share_exists(conf_ctx, servicename)) { - werr = smbconf_delete_share(conf_ctx, servicename); + if (smbconf_share_exists(conf_ctx, service->name)) { + werr = smbconf_delete_share(conf_ctx, service->name); if (!W_ERROR_IS_OK(werr)) { goto done; } } - werr = smbconf_create_share(conf_ctx, servicename); + werr = smbconf_create_share(conf_ctx, service->name); if (!W_ERROR_IS_OK(werr)) { goto done; } - for (idx = 0; idx < num_params; idx ++) { - if (strequal(param_names[idx], "include")) { + for (idx = 0; idx < service->num_params; idx ++) { + if (strequal(service->param_names[idx], "include")) { includes = TALLOC_REALLOC_ARRAY(mem_ctx, includes, char *, @@ -185,7 +183,7 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, goto done; } includes[num_includes] = talloc_strdup(includes, - param_values[idx]); + service->param_values[idx]); if (includes[num_includes] == NULL) { werr = WERR_NOMEM; goto done; @@ -193,16 +191,16 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, num_includes++; } else { werr = smbconf_set_parameter(conf_ctx, - servicename, - param_names[idx], - param_values[idx]); + service->name, + service->param_names[idx], + service->param_values[idx]); if (!W_ERROR_IS_OK(werr)) { goto done; } } } - werr = smbconf_set_includes(conf_ctx, servicename, num_includes, + werr = smbconf_set_includes(conf_ctx, service->name, num_includes, (const char **)includes); done: @@ -224,11 +222,8 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, int ret = -1; TALLOC_CTX *mem_ctx; uint32_t num_shares; - char **share_names; - uint32_t *num_params; - char ***param_names; - char ***param_values; uint32_t share_count, param_count; + struct smbconf_service **shares = NULL; mem_ctx = talloc_stackframe(); @@ -237,8 +232,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, goto done; } - werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &share_names, - &num_params, ¶m_names, ¶m_values); + werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error getting config: %s\n", dos_errstr(werr)); @@ -247,17 +241,18 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, for (share_count = 0; share_count < num_shares; share_count++) { const char *indent = ""; - if (share_names[share_count] != NULL) { - d_printf("[%s]\n", share_names[share_count]); + if (shares[share_count]->name != NULL) { + d_printf("[%s]\n", shares[share_count]->name); indent = "\t"; } - for (param_count = 0; param_count < num_params[share_count]; + for (param_count = 0; + param_count < shares[share_count]->num_params; param_count++) { d_printf("%s%s = %s\n", indent, - param_names[share_count][param_count], - param_values[share_count][param_count]); + shares[share_count]->param_names[param_count], + shares[share_count]->param_values[param_count]); } d_printf("\n"); } @@ -320,35 +315,25 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, } if (servicename != NULL) { - char **param_names, **param_values; - uint32_t num_params; + struct smbconf_service *service = NULL; werr = smbconf_get_share(txt_ctx, mem_ctx, servicename, - &num_params, - ¶m_names, - ¶m_values); + &service); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = import_process_service(conf_ctx, - servicename, - num_params, - (const char **)param_names, - (const char **)param_values); + werr = import_process_service(conf_ctx, service); if (!W_ERROR_IS_OK(werr)) { goto done; } } else { - char **share_names, ***param_names, ***param_values; - uint32_t num_shares, *num_params, sidx; + struct smbconf_service **services = NULL; + uint32_t num_shares, sidx; werr = smbconf_get_config(txt_ctx, mem_ctx, &num_shares, - &share_names, - &num_params, - ¶m_names, - ¶m_values); + &services); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -359,11 +344,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, } } for (sidx = 0; sidx < num_shares; sidx++) { - werr = import_process_service(conf_ctx, - share_names[sidx], - num_params[sidx], - (const char **)param_names[sidx], - (const char **)param_values[sidx]); + werr = import_process_service(conf_ctx, services[sidx]); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -442,10 +423,8 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, WERROR werr = WERR_OK; const char *sharename = NULL; TALLOC_CTX *mem_ctx; - uint32_t num_params; uint32_t count; - char **param_names; - char **param_values; + struct smbconf_service *service = NULL; mem_ctx = talloc_stackframe(); @@ -460,8 +439,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, goto done; } - werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &num_params, - ¶m_names, ¶m_values); + werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service); if (!W_ERROR_IS_OK(werr)) { d_printf("error getting share parameters: %s\n", dos_errstr(werr)); @@ -470,9 +448,9 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, d_printf("[%s]\n", sharename); - for (count = 0; count < num_params; count++) { - d_printf("\t%s = %s\n", param_names[count], - param_values[count]); + for (count = 0; count < service->num_params; count++) { + d_printf("\t%s = %s\n", service->param_names[count], + service->param_values[count]); } ret = 0; -- cgit From f5769109447d8da0f09b102d444a816ad97a00dc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 9 May 2008 23:22:12 +0200 Subject: net: Remove globals (This used to be commit 1e9319cf88b65a2a8d4f5099a1fe5297e405ed2e) --- source3/utils/net_conf.c | 147 +++++++++++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 61 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 08a06eabd4..a922e13583 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -36,13 +36,15 @@ * **********************************************************************/ -static int net_conf_list_usage(int argc, const char **argv) +static int net_conf_list_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf list\n"); return -1; } -static int net_conf_import_usage(int argc, const char**argv) +static int net_conf_import_usage(struct net_context *c, int argc, + const char**argv) { d_printf("USAGE: net conf import [--test|-T] " "[]\n" @@ -53,25 +55,29 @@ static int net_conf_import_usage(int argc, const char**argv) return -1; } -static int net_conf_listshares_usage(int argc, const char **argv) +static int net_conf_listshares_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf listshares\n"); return -1; } -static int net_conf_drop_usage(int argc, const char **argv) +static int net_conf_drop_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf drop\n"); return -1; } -static int net_conf_showshare_usage(int argc, const char **argv) +static int net_conf_showshare_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf showshare \n"); return -1; } -static int net_conf_addshare_usage(int argc, const char **argv) +static int net_conf_addshare_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf addshare " "[writeable={y|N} [guest_ok={y|N} []]\n" @@ -85,43 +91,50 @@ static int net_conf_addshare_usage(int argc, const char **argv) return -1; } -static int net_conf_delshare_usage(int argc, const char **argv) +static int net_conf_delshare_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf delshare \n"); return -1; } -static int net_conf_setparm_usage(int argc, const char **argv) +static int net_conf_setparm_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf setparm
\n"); return -1; } -static int net_conf_getparm_usage(int argc, const char **argv) +static int net_conf_getparm_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf getparm
\n"); return -1; } -static int net_conf_delparm_usage(int argc, const char **argv) +static int net_conf_delparm_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf delparm
\n"); return -1; } -static int net_conf_getincludes_usage(int argc, const char **argv) +static int net_conf_getincludes_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf getincludes
\n"); return -1; } -static int net_conf_setincludes_usage(int argc, const char **argv) +static int net_conf_setincludes_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf setincludes
[]*\n"); return -1; } -static int net_conf_delincludes_usage(int argc, const char **argv) +static int net_conf_delincludes_usage(struct net_context *c, int argc, + const char **argv) { d_printf("USAGE: net conf delincludes
\n"); return -1; @@ -137,7 +150,8 @@ static int net_conf_delincludes_usage(int argc, const char **argv) /** * This functions process a service previously loaded with libsmbconf. */ -static WERROR import_process_service(struct smbconf_ctx *conf_ctx, +static WERROR import_process_service(struct net_context *c, + struct smbconf_ctx *conf_ctx, struct smbconf_service *service) { uint32_t idx; @@ -146,7 +160,7 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, char **includes = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (opt_testmode) { + if (c->opt_testmode) { const char *indent = ""; if (service->name != NULL) { d_printf("[%s]\n", service->name); @@ -215,7 +229,7 @@ done: * **********************************************************************/ -static int net_conf_list(struct smbconf_ctx *conf_ctx, +static int net_conf_list(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr = WERR_OK; @@ -228,7 +242,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 0) { - net_conf_list_usage(argc, argv); + net_conf_list_usage(c, argc, argv); goto done; } @@ -264,7 +278,7 @@ done: return ret; } -static int net_conf_import(struct smbconf_ctx *conf_ctx, +static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -280,7 +294,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, switch (argc) { case 0: default: - net_conf_import_usage(argc, argv); + net_conf_import_usage(c, argc, argv); goto done; case 2: servicename = talloc_strdup_lower(mem_ctx, argv[1]); @@ -309,7 +323,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, goto done; } - if (opt_testmode) { + if (c->opt_testmode) { d_printf("\nTEST MODE - " "would import the following configuration:\n\n"); } @@ -323,7 +337,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = import_process_service(conf_ctx, service); + werr = import_process_service(c, conf_ctx, service); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -337,14 +351,15 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx, if (!W_ERROR_IS_OK(werr)) { goto done; } - if (!opt_testmode) { + if (!c->opt_testmode) { werr = smbconf_drop(conf_ctx); if (!W_ERROR_IS_OK(werr)) { goto done; } } for (sidx = 0; sidx < num_shares; sidx++) { - werr = import_process_service(conf_ctx, services[sidx]); + werr = import_process_service(c, conf_ctx, + services[sidx]); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -358,8 +373,9 @@ done: return ret; } -static int net_conf_listshares(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_listshares(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { WERROR werr = WERR_OK; int ret = -1; @@ -370,7 +386,7 @@ static int net_conf_listshares(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 0) { - net_conf_listshares_usage(argc, argv); + net_conf_listshares_usage(c, argc, argv); goto done; } @@ -392,14 +408,14 @@ done: return ret; } -static int net_conf_drop(struct smbconf_ctx *conf_ctx, +static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; WERROR werr; if (argc != 0) { - net_conf_drop_usage(argc, argv); + net_conf_drop_usage(c, argc, argv); goto done; } @@ -416,8 +432,9 @@ done: return ret; } -static int net_conf_showshare(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_showshare(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -429,7 +446,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_showshare_usage(argc, argv); + net_conf_showshare_usage(c, argc, argv); goto done; } @@ -466,8 +483,9 @@ done: * This is a high level utility function of the net conf utility, * not a direct frontend to the smbconf API. */ -static int net_conf_addshare(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_addshare(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { int ret = -1; WERROR werr = WERR_OK; @@ -483,13 +501,13 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, case 0: case 1: default: - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; case 5: comment = argv[4]; case 4: if (!strnequal(argv[3], "guest_ok=", 9)) { - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } switch (argv[3][9]) { @@ -502,12 +520,12 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, guest_ok = "no"; break; default: - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } case 3: if (!strnequal(argv[2], "writeable=", 10)) { - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } switch (argv[2][10]) { @@ -520,7 +538,7 @@ static int net_conf_addshare(struct smbconf_ctx *conf_ctx, writeable = "no"; break; default: - net_conf_addshare_usage(argc, argv); + net_conf_addshare_usage(c, argc, argv); goto done; } case 2: @@ -646,8 +664,9 @@ done: return ret; } -static int net_conf_delshare(struct smbconf_ctx *conf_ctx, - int argc, const char **argv) +static int net_conf_delshare(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, + const char **argv) { int ret = -1; const char *sharename = NULL; @@ -655,7 +674,7 @@ static int net_conf_delshare(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_delshare_usage(argc, argv); + net_conf_delshare_usage(c, argc, argv); goto done; } sharename = talloc_strdup_lower(mem_ctx, argv[0]); @@ -677,7 +696,7 @@ done: return ret; } -static int net_conf_setparm(struct smbconf_ctx *conf_ctx, +static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -688,7 +707,7 @@ static int net_conf_setparm(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 3) { - net_conf_setparm_usage(argc, argv); + net_conf_setparm_usage(c, argc, argv); goto done; } service = talloc_strdup_lower(mem_ctx, argv[0]); @@ -727,7 +746,7 @@ done: return ret; } -static int net_conf_getparm(struct smbconf_ctx *conf_ctx, +static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -740,7 +759,7 @@ static int net_conf_getparm(struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); if (argc != 2) { - net_conf_getparm_usage(argc, argv); + net_conf_getparm_usage(c, argc, argv); goto done; } service = talloc_strdup_lower(mem_ctx, argv[0]); @@ -780,7 +799,7 @@ done: return ret; } -static int net_conf_delparm(struct smbconf_ctx *conf_ctx, +static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx, int argc, const char **argv) { int ret = -1; @@ -790,7 +809,7 @@ static int net_conf_delparm(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 2) { - net_conf_delparm_usage(argc, argv); + net_conf_delparm_usage(c, argc, argv); goto done; } service = talloc_strdup_lower(mem_ctx, argv[0]); @@ -829,7 +848,8 @@ done: return ret; } -static int net_conf_getincludes(struct smbconf_ctx *conf_ctx, +static int net_conf_getincludes(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr; @@ -841,7 +861,7 @@ static int net_conf_getincludes(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_getincludes_usage(argc, argv); + net_conf_getincludes_usage(c, argc, argv); goto done; } @@ -869,7 +889,8 @@ done: return ret; } -static int net_conf_setincludes(struct smbconf_ctx *conf_ctx, +static int net_conf_setincludes(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr; @@ -880,7 +901,7 @@ static int net_conf_setincludes(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc < 1) { - net_conf_setincludes_usage(argc, argv); + net_conf_setincludes_usage(c, argc, argv); goto done; } @@ -910,7 +931,8 @@ done: return ret; } -static int net_conf_delincludes(struct smbconf_ctx *conf_ctx, +static int net_conf_delincludes(struct net_context *c, + struct smbconf_ctx *conf_ctx, int argc, const char **argv) { WERROR werr; @@ -919,7 +941,7 @@ static int net_conf_delincludes(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (argc != 1) { - net_conf_delincludes_usage(argc, argv); + net_conf_delincludes_usage(c, argc, argv); goto done; } @@ -954,7 +976,9 @@ done: * The wrapper calls handles opening and closing of the * configuration. */ -static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, +static int net_conf_wrap_function(struct net_context *c, + int (*fn)(struct net_context *, + struct smbconf_ctx *, int, const char **), int argc, const char **argv) { @@ -969,7 +993,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, return -1; } - ret = fn(conf_ctx, argc, argv); + ret = fn(c, conf_ctx, argc, argv); smbconf_shutdown(conf_ctx); @@ -983,7 +1007,8 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *, */ struct conf_functable { const char *funcname; - int (*fn)(struct smbconf_ctx *ctx, int argc, const char **argv); + int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc, + const char **argv); const char *helptext; }; @@ -991,8 +1016,8 @@ struct conf_functable { * This imitates net_run_function2 but calls the main functions * through the wrapper net_conf_wrap_function(). */ -static int net_conf_run_function(int argc, const char **argv, - const char *whoami, +static int net_conf_run_function(struct net_context *c, int argc, + const char **argv, const char *whoami, struct conf_functable *table) { int i; @@ -1000,7 +1025,7 @@ static int net_conf_run_function(int argc, const char **argv, if (argc != 0) { for (i=0; table[i].funcname; i++) { if (StrCaseCmp(argv[0], table[i].funcname) == 0) - return net_conf_wrap_function(table[i].fn, + return net_conf_wrap_function(c, table[i].fn, argc-1, argv+1); } @@ -1018,7 +1043,7 @@ static int net_conf_run_function(int argc, const char **argv, * Entry-point for all the CONF functions. */ -int net_conf(int argc, const char **argv) +int net_conf(struct net_context *c, int argc, const char **argv) { int ret = -1; struct conf_functable func_table[] = { @@ -1051,7 +1076,7 @@ int net_conf(int argc, const char **argv) {NULL, NULL, NULL} }; - ret = net_conf_run_function(argc, argv, "net conf", func_table); + ret = net_conf_run_function(c, argc, argv, "net conf", func_table); return ret; } -- cgit From 1be1be3334a91ac8cc5842893786a66f1c3bbfa3 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sat, 7 Jun 2008 01:02:13 +0200 Subject: net: Make "net conf" use a functable similar to functable3 (This used to be commit b8382bc3af318226a1160c6c39627e7a32e050ab) --- source3/utils/net_conf.c | 182 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 139 insertions(+), 43 deletions(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index a922e13583..f63f04e09a 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -241,7 +241,7 @@ static int net_conf_list(struct net_context *c, struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); - if (argc != 0) { + if (argc != 0 || c->display_usage) { net_conf_list_usage(c, argc, argv); goto done; } @@ -289,6 +289,9 @@ static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx, struct smbconf_ctx *txt_ctx; WERROR werr; + if (c->display_usage) + return net_conf_import_usage(c, argc, argv); + mem_ctx = talloc_stackframe(); switch (argc) { @@ -385,7 +388,7 @@ static int net_conf_listshares(struct net_context *c, mem_ctx = talloc_stackframe(); - if (argc != 0) { + if (argc != 0 || c->display_usage) { net_conf_listshares_usage(c, argc, argv); goto done; } @@ -414,7 +417,7 @@ static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx, int ret = -1; WERROR werr; - if (argc != 0) { + if (argc != 0 || c->display_usage) { net_conf_drop_usage(c, argc, argv); goto done; } @@ -445,7 +448,7 @@ static int net_conf_showshare(struct net_context *c, mem_ctx = talloc_stackframe(); - if (argc != 1) { + if (argc != 1 || c->display_usage) { net_conf_showshare_usage(c, argc, argv); goto done; } @@ -497,6 +500,12 @@ static int net_conf_addshare(struct net_context *c, SMB_STRUCT_STAT sbuf; TALLOC_CTX *mem_ctx = talloc_stackframe(); + if (c->display_usage) { + net_conf_addshare_usage(c, argc, argv); + ret = 0; + goto done; + } + switch (argc) { case 0: case 1: @@ -673,7 +682,7 @@ static int net_conf_delshare(struct net_context *c, WERROR werr = WERR_OK; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (argc != 1) { + if (argc != 1 || c->display_usage) { net_conf_delshare_usage(c, argc, argv); goto done; } @@ -706,7 +715,7 @@ static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx, const char *value_str = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (argc != 3) { + if (argc != 3 || c->display_usage) { net_conf_setparm_usage(c, argc, argv); goto done; } @@ -758,7 +767,7 @@ static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx, mem_ctx = talloc_stackframe(); - if (argc != 2) { + if (argc != 2 || c->display_usage) { net_conf_getparm_usage(c, argc, argv); goto done; } @@ -808,7 +817,7 @@ static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx, char *param = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (argc != 2) { + if (argc != 2 || c->display_usage) { net_conf_delparm_usage(c, argc, argv); goto done; } @@ -860,7 +869,7 @@ static int net_conf_getincludes(struct net_context *c, int ret = -1; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (argc != 1) { + if (argc != 1 || c->display_usage) { net_conf_getincludes_usage(c, argc, argv); goto done; } @@ -900,7 +909,7 @@ static int net_conf_setincludes(struct net_context *c, int ret = -1; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (argc < 1) { + if (argc < 1 || c->display_usage) { net_conf_setincludes_usage(c, argc, argv); goto done; } @@ -940,7 +949,7 @@ static int net_conf_delincludes(struct net_context *c, int ret = -1; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (argc != 1) { + if (argc != 1 || c->display_usage) { net_conf_delincludes_usage(c, argc, argv); goto done; } @@ -1009,11 +1018,13 @@ struct conf_functable { const char *funcname; int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc, const char **argv); - const char *helptext; + int valid_transports; + const char *description; + const char *usage; }; /** - * This imitates net_run_function2 but calls the main functions + * This imitates net_run_function3 but calls the main functions * through the wrapper net_conf_wrap_function(). */ static int net_conf_run_function(struct net_context *c, int argc, @@ -1031,12 +1042,16 @@ static int net_conf_run_function(struct net_context *c, int argc, } } + d_printf("Usage:\n"); for (i=0; table[i].funcname; i++) { - d_printf("%s %-15s %s\n", whoami, table[i].funcname, - table[i].helptext); + if (c->display_usage == false) + d_printf("%s %-15s %s\n", whoami, table[i].funcname, + table[i].description); + else + d_printf("%s\n", table[i].usage); } - return -1; + return c->display_usage?0:-1; } /* @@ -1047,33 +1062,114 @@ int net_conf(struct net_context *c, int argc, const char **argv) { int ret = -1; struct conf_functable func_table[] = { - {"list", net_conf_list, - "Dump the complete configuration in smb.conf like format."}, - {"import", net_conf_import, - "Import configuration from file in smb.conf format."}, - {"listshares", net_conf_listshares, - "List the share names."}, - {"drop", net_conf_drop, - "Delete the complete configuration."}, - {"showshare", net_conf_showshare, - "Show the definition of a share."}, - {"addshare", net_conf_addshare, - "Create a new share."}, - {"delshare", net_conf_delshare, - "Delete a share."}, - {"setparm", net_conf_setparm, - "Store a parameter."}, - {"getparm", net_conf_getparm, - "Retrieve the value of a parameter."}, - {"delparm", net_conf_delparm, - "Delete a parameter."}, - {"getincludes", net_conf_getincludes, - "Show the includes of a share definition."}, - {"setincludes", net_conf_setincludes, - "Set includes for a share."}, - {"delincludes", net_conf_delincludes, - "Delete includes from a share definition."}, - {NULL, NULL, NULL} + { + "list", + net_conf_list, + NET_TRANSPORT_LOCAL, + "Dump the complete configuration in smb.conf like " + "format.", + "net conf list\n" + " Dump the complete configuration in smb.conf like " + "format." + + }, + { + "import", + net_conf_import, + NET_TRANSPORT_LOCAL, + "Import configuration from file in smb.conf format.", + "net conf import\n" + " Import configuration from file in smb.conf format." + }, + { + "listshares", + net_conf_listshares, + NET_TRANSPORT_LOCAL, + "List the share names.", + "net conf listshares\n" + " List the share names." + }, + { + "drop", + net_conf_drop, + NET_TRANSPORT_LOCAL, + "Delete the complete configuration.", + "net conf drop\n" + " Delete the complete configuration." + }, + { + "showshare", + net_conf_showshare, + NET_TRANSPORT_LOCAL, + "Show the definition of a share.", + "net conf showshare\n" + " Show the definition of a share." + }, + { + "addshare", + net_conf_addshare, + NET_TRANSPORT_LOCAL, + "Create a new share.", + "net conf addshare\n" + " Create a new share." + }, + { + "delshare", + net_conf_delshare, + NET_TRANSPORT_LOCAL, + "Delete a share.", + "net conf delshare\n" + " Delete a share." + }, + { + "setparm", + net_conf_setparm, + NET_TRANSPORT_LOCAL, + "Store a parameter.", + "net conf setparm\n" + " Store a parameter." + }, + { + "getparm", + net_conf_getparm, + NET_TRANSPORT_LOCAL, + "Retrieve the value of a parameter.", + "net conf getparm\n" + " Retrieve the value of a parameter." + }, + { + "delparm", + net_conf_delparm, + NET_TRANSPORT_LOCAL, + "Delete a parameter.", + "net conf delparm\n" + " Delete a parameter." + }, + { + "getincludes", + net_conf_getincludes, + NET_TRANSPORT_LOCAL, + "Show the includes of a share definition.", + "net conf getincludes\n" + " Show the includes of a share definition." + }, + { + "setincludes", + net_conf_setincludes, + NET_TRANSPORT_LOCAL, + "Set includes for a share.", + "net conf setincludes\n" + " Set includes for a share." + }, + { + "delincludes", + net_conf_delincludes, + NET_TRANSPORT_LOCAL, + "Delete includes from a share definition.", + "net conf setincludes\n" + " Delete includes from a share definition." + }, + {NULL, NULL, 0, NULL, NULL} }; ret = net_conf_run_function(c, argc, argv, "net conf", func_table); -- cgit From 255bdb26025a5025bc60637dd924f6ec71c49ee5 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sat, 7 Jun 2008 02:25:08 +0200 Subject: net: Rename functable3 to functable, get rid of old functables (This used to be commit bb7c5fc4ec77db4073d3beccf12af12910b6bd07) --- source3/utils/net_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_conf.c') diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index f63f04e09a..ab1b0f3df7 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -1024,7 +1024,7 @@ struct conf_functable { }; /** - * This imitates net_run_function3 but calls the main functions + * This imitates net_run_function but calls the main functions * through the wrapper net_conf_wrap_function(). */ static int net_conf_run_function(struct net_context *c, int argc, -- cgit