* 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
*/
/*
- * 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 Samba's configuration as made available
+ * 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
+ * rpc might get implemented in the future.
*/
#include "includes.h"
#include "utils/net.h"
-#include "libnet/libnet.h"
-/*
+/**********************************************************************
+ *
* usage functions
- */
+ *
+ **********************************************************************/
static int net_conf_list_usage(int argc, const char **argv)
{
d_printf("USAGE: net conf import [--test|-T] <filename> "
"[<servicename>]\n"
"\t[--test|-T] testmode - do not act, just print "
- "what would be done\n"
+ "what would be done\n"
"\t<servicename> only import service <servicename>, "
- "ignore the rest\n");
+ "ignore the rest\n");
return -1;
}
return -1;
}
-
-/*
- * Helper functions
- */
-
-static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key)
+static int net_conf_getincludes_usage(int argc, const char **argv)
{
- 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;
+ d_printf("USAGE: net conf getincludes <section>\n");
+ return -1;
}
-static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm,
- struct share_params *share)
+static int net_conf_setincludes_usage(int argc, const char **argv)
{
- 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, "<type unimplemented>\n");
- break;
- }
-
- return valstr;
+ d_printf("USAGE: net conf setincludes <section> [<filename>]*\n");
+ return -1;
}
-static int import_process_service(TALLOC_CTX *ctx,
- struct share_params *share)
+static int net_conf_delincludes_usage(int argc, const char **argv)
{
- int ret = -1;
- struct parm_struct *parm;
- int pnum = 0;
- const char *servicename;
- struct registry_key *key;
- WERROR werr;
- char *valstr = NULL;
- TALLOC_CTX *tmp_ctx = NULL;
+ d_printf("USAGE: net conf delincludes <section>\n");
+ return -1;
+}
- 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);
+/**********************************************************************
+ *
+ * Helper functions
+ *
+ **********************************************************************/
+
+/**
+ * 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)
+{
+ 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);
- } else {
- if (libnet_smbconf_key_exists(servicename)) {
- werr = libnet_smbconf_delshare(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 = libnet_smbconf_reg_createkey_internal(tmp_ctx, servicename, &key);
+ 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;
+ }
- 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 = libnet_smbconf_reg_setvalue_internal(key,
- parm->label, valstr);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
+ for (idx = 0; idx < num_params; 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 {
+ 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;
+ werr = smbconf_set_includes(conf_ctx, servicename, num_includes,
+ (const char **)includes);
done:
- TALLOC_FREE(tmp_ctx);
- return ret;
+ TALLOC_FREE(mem_ctx);
+ return werr;
}
-/* 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
- */
+/**********************************************************************
+ *
+ * the main conf functions
+ *
+ **********************************************************************/
-static int net_conf_list(int argc, const char **argv)
+static int net_conf_list(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
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;
char ***param_values;
uint32_t share_count, param_count;
- ctx = talloc_init("list");
+ mem_ctx = talloc_stackframe();
if (argc != 0) {
net_conf_list_usage(argc, argv);
goto done;
}
- werr = libnet_smbconf_get_config(ctx, &num_shares, &share_names,
- &num_params, ¶m_names,
- ¶m_values);
+ 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",
dos_errstr(werr));
ret = 0;
done:
- TALLOC_FREE(ctx);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_import(int argc, const char **argv)
+static int net_conf_import(struct smbconf_ctx *conf_ctx,
+ 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 };
+ char *conf_source = NULL;
+ TALLOC_CTX *mem_ctx;
+ struct smbconf_ctx *txt_ctx;
+ WERROR werr;
- ctx = talloc_init("net_conf_import");
+ mem_ctx = talloc_stackframe();
switch (argc) {
case 0:
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;
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");
+ 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));
goto done;
}
"would import the following configuration:\n\n");
}
- if (((servicename == NULL) && globals_exist()) ||
- strequal(servicename, GLOBAL_NAME))
- {
- service_found = true;
- if (import_process_service(ctx, &global_share) != 0) {
+ if (servicename != NULL) {
+ char **param_names, **param_values;
+ uint32_t num_params;
+
+ werr = smbconf_get_share(txt_ctx, mem_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;
- }
-
- 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) {
+ werr = import_process_service(conf_ctx,
+ servicename,
+ num_params,
+ (const char **)param_names,
+ (const char **)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;
+
+ werr = smbconf_get_config(txt_ctx, mem_ctx,
+ &num_shares,
+ &share_names,
+ &num_params,
+ ¶m_names,
+ ¶m_values);
+ 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,
+ share_names[sidx],
+ num_params[sidx],
+ (const char **)param_names[sidx],
+ (const char **)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:
- TALLOC_FREE(ctx);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_listshares(int argc, const char **argv)
+static int net_conf_listshares(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
WERROR werr = WERR_OK;
int ret = -1;
uint32_t count, num_shares = 0;
char **share_names = NULL;
- TALLOC_CTX *ctx;
+ TALLOC_CTX *mem_ctx;
- ctx = talloc_init("listshares");
+ mem_ctx = talloc_stackframe();
if (argc != 0) {
net_conf_listshares_usage(argc, argv);
goto done;
}
- werr = libnet_smbconf_get_share_names(ctx, &num_shares, &share_names);
+ werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
+ &share_names);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
ret = 0;
done:
- TALLOC_FREE(ctx);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_drop(int argc, const char **argv)
+static int net_conf_drop(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
int ret = -1;
WERROR werr;
goto done;
}
- werr = libnet_smbconf_drop();
+ werr = smbconf_drop(conf_ctx);
if (!W_ERROR_IS_OK(werr)) {
d_fprintf(stderr, "Error deleting configuration: %s\n",
dos_errstr(werr));
return ret;
}
-static int net_conf_showshare(int argc, const char **argv)
+static int net_conf_showshare(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
int ret = -1;
WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
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_init("showshare");
+ mem_ctx = talloc_stackframe();
if (argc != 1) {
net_conf_showshare_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 = libnet_smbconf_getshare(ctx, sharename, &num_params,
- ¶m_names, ¶m_values);
+ 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",
dos_errstr(werr));
ret = 0;
done:
- TALLOC_FREE(ctx);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_addshare(int argc, const char **argv)
+/**
+ * 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 smbconf API.
+ */
+static int net_conf_addshare(struct smbconf_ctx *conf_ctx,
+ 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;
+ TALLOC_CTX *mem_ctx = talloc_stackframe();
switch (argc) {
case 0:
net_conf_addshare_usage(argc, argv);
goto done;
}
-
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;
}
goto done;
}
+ if (smbconf_share_exists(conf_ctx, sharename)) {
+ d_fprintf(stderr, "ERROR: share %s already exists.\n",
+ sharename);
+ goto done;
+ }
+
/* validate path */
if (path[0] != '/') {
* create the share
*/
- werr = libnet_smbconf_reg_createkey_internal(NULL, argv[0], &newkey);
+ 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));
goto done;
}
- /* add config params as values */
+ /*
+ * fill the share with parameters
+ */
- werr = libnet_smbconf_reg_setvalue_internal(newkey, "path", path);
- if (!W_ERROR_IS_OK(werr))
+ 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));
goto done;
+ }
if (comment != NULL) {
- werr = libnet_smbconf_reg_setvalue_internal(newkey, "comment",
- comment);
- if (!W_ERROR_IS_OK(werr))
+ 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));
goto done;
+ }
}
- werr = libnet_smbconf_reg_setvalue_internal(newkey, "guest ok",
- guest_ok);
- if (!W_ERROR_IS_OK(werr))
+ 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_smbconf_reg_setvalue_internal(newkey, "writeable",
- writeable);
- if (!W_ERROR_IS_OK(werr))
+ 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));
goto done;
+ }
ret = 0;
done:
- TALLOC_FREE(newkey);
- SAFE_FREE(sharename);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_delshare(int argc, const char **argv)
+static int net_conf_delshare(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
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 = libnet_smbconf_delshare(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));
ret = 0;
done:
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_setparm(int argc, const char **argv)
+static int net_conf_setparm(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
int ret = -1;
WERROR werr = WERR_OK;
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];
- werr = libnet_smbconf_setparm(service, param, value_str);
+ 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));
+ goto done;
+ }
+ }
+
+ 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",
ret = 0;
done:
- SAFE_FREE(service);
- SAFE_FREE(param);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_getparm(int argc, const char **argv)
+static int net_conf_getparm(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
int ret = -1;
WERROR werr = WERR_OK;
char *service = NULL;
char *param = NULL;
char *valstr = NULL;
- TALLOC_CTX *ctx;
+ TALLOC_CTX *mem_ctx;
- ctx = talloc_init("getparm");
+ mem_ctx = talloc_stackframe();
if (argc != 2) {
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 = libnet_smbconf_getparm(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,
ret = 0;
done:
- SAFE_FREE(service);
- SAFE_FREE(param);
- TALLOC_FREE(ctx);
+ TALLOC_FREE(mem_ctx);
return ret;
}
-static int net_conf_delparm(int argc, const char **argv)
+static int net_conf_delparm(struct smbconf_ctx *conf_ctx,
+ int argc, const char **argv)
{
int ret = -1;
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 = libnet_smbconf_delparm(service, param);
+ werr = smbconf_delete_parameter(conf_ctx, service, param);
if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
d_fprintf(stderr,
ret = 0;
done:
- SAFE_FREE(service);
- SAFE_FREE(param);
+ TALLOC_FREE(mem_ctx);
+ 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;
+}
+
+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;
+}
+
+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;
+}
+
+
+/**********************************************************************
+ *
+ * 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 smbconf_ctx *,
+ int, const char **),
+ int argc, const char **argv)
+{
+ WERROR werr;
+ TALLOC_CTX *mem_ctx = talloc_stackframe();
+ struct smbconf_ctx *conf_ctx;
+ int ret = -1;
+
+ werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
+
+ if (!W_ERROR_IS_OK(werr)) {
+ return -1;
+ }
+
+ ret = fn(conf_ctx, argc, argv);
+
+ smbconf_shutdown(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 smbconf_ctx *ctx, int argc, const char **argv);
+ 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)
+{
+ 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.
*/
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,
"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,
"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}
};
- if (!registry_init_regdb()) {
- d_fprintf(stderr, "Error initializing the registry!\n");
- goto done;
- }
+ ret = net_conf_run_function(argc, argv, "net conf", func_table);
- ret = net_run_function2(argc, argv, "net conf", func);
-
- regdb_close();
-
-done:
return ret;
}