[SCM] Samba Shared Repository - branch v3-2-test updated -
initial-v3-2-unstable-947-g9b3b9aa
Michael Adam
obnox at samba.org
Sat Dec 29 11:57:53 GMT 2007
The branch, v3-2-test has been updated
via 9b3b9aa7e1044719a5112b9e5446e6fbdd7cecf9 (commit)
via 7b51535f2f76b5c3c18620ffd9ac64505357e6db (commit)
via 306c7e4d9cecac4c2c0ea1172bd585c3c17d4541 (commit)
via 198232bd525cfac933b4885e6b330ebf4ac2c8ae (commit)
from c9c7607c402c0a9df9796c767b689d207d67d8e4 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit 9b3b9aa7e1044719a5112b9e5446e6fbdd7cecf9
Author: Michael Adam <obnox at samba.org>
Date: Sat Dec 29 12:55:42 2007 +0100
Rename libnet_smbconf_getshares() to libnet_smbconf_get_share_names().
Michael
commit 7b51535f2f76b5c3c18620ffd9ac64505357e6db
Author: Michael Adam <obnox at samba.org>
Date: Sat Dec 29 12:53:19 2007 +0100
Add a comment header for libnet_smbconf_getshares().
Michael
commit 306c7e4d9cecac4c2c0ea1172bd585c3c17d4541
Author: Michael Adam <obnox at samba.org>
Date: Sat Dec 29 12:52:09 2007 +0100
Move functionality of net_conf_listshares() to libnet_conf.c
into new function libnet_smbconf_getshares().
Michael
commit 198232bd525cfac933b4885e6b330ebf4ac2c8ae
Author: Michael Adam <obnox at samba.org>
Date: Sat Dec 29 03:38:13 2007 +0100
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
-----------------------------------------------------------------------
Summary of changes:
source/libnet/libnet_conf.c | 145 +++++++++++++++++++++++++++++++++++++++++++
source/utils/net_conf.c | 39 ++++++------
2 files changed, 165 insertions(+), 19 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/libnet/libnet_conf.c b/source/libnet/libnet_conf.c
index a8a8e01..99fde86 100644
--- a/source/libnet/libnet_conf.c
+++ b/source/libnet/libnet_conf.c
@@ -266,6 +266,71 @@ char *libnet_smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
return result;
}
+/**
+ * Get the values of a key as a list of value names
+ * and a list of value strings (ordered)
+ */
+static WERROR libnet_smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
+ struct registry_key *key,
+ uint32_t *num_values,
+ char ***value_names,
+ char ***value_strings)
+{
+ TALLOC_CTX *tmp_ctx;
+ WERROR werr = WERR_OK;
+ uint32_t count;
+ struct registry_value *valvalue = NULL;
+ char *valname = NULL;
+ char **tmp_valnames = NULL;
+ char **tmp_valstrings = NULL;
+
+ if ((num_values == NULL) || (value_names == NULL) ||
+ (value_strings == NULL))
+ {
+ werr = WERR_INVALID_PARAM;
+ goto done;
+ }
+
+ tmp_ctx = talloc_new(mem_ctx);
+ if (tmp_ctx == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+
+ for (count = 0;
+ W_ERROR_IS_OK(werr = reg_enumvalue(tmp_ctx, key, count, &valname,
+ &valvalue));
+ count++)
+ {
+ tmp_valnames = TALLOC_REALLOC_ARRAY(tmp_ctx, tmp_valnames,
+ char *, count + 1);
+ tmp_valstrings = TALLOC_REALLOC_ARRAY(tmp_ctx, tmp_valstrings,
+ char *, count + 1);
+ if ((tmp_valstrings == NULL) || (tmp_valnames == NULL)) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+ tmp_valnames[count] = talloc_strdup(tmp_valnames, valname);
+ tmp_valstrings[count] =
+ libnet_smbconf_format_registry_value(tmp_valstrings,
+ valvalue);
+ }
+ if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
+ goto done;
+ }
+
+ werr = WERR_OK;
+
+ *num_values = count - 1;
+ if (count > 0) {
+ *value_names = talloc_move(mem_ctx, &tmp_valnames);
+ *value_strings = talloc_move(mem_ctx, &tmp_valstrings);
+ }
+
+done:
+ TALLOC_FREE(tmp_ctx);
+ return werr;
+}
/**********************************************************************
*
@@ -320,6 +385,86 @@ done:
}
/**
+ * get the list of share names defined in the configuration.
+ */
+WERROR libnet_smbconf_get_share_names(TALLOC_CTX *mem_ctx, uint32_t *num_shares,
+ char ***share_names)
+{
+ uint32_t count;
+ TALLOC_CTX *tmp_ctx;
+ WERROR werr = WERR_OK;
+ struct registry_key *key = NULL;
+ char *subkey_name = NULL;
+ char **tmp_share_names = NULL;
+
+ if ((num_shares == NULL) || (share_names == NULL)) {
+ werr = WERR_INVALID_PARAM;
+ goto done;
+ }
+
+ tmp_ctx = talloc_new(mem_ctx);
+ if (tmp_ctx == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+
+ werr = libnet_smbconf_reg_open_basepath(tmp_ctx,
+ SEC_RIGHTS_ENUM_SUBKEYS,
+ &key);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
+ for (count = 0;
+ W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count,
+ &subkey_name, NULL));
+ count++)
+ {
+ tmp_share_names = TALLOC_REALLOC_ARRAY(tmp_ctx, tmp_share_names,
+ char *, count + 1);
+ tmp_share_names[count] = talloc_strdup(tmp_ctx, subkey_name);
+ }
+ if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
+ goto done;
+ }
+
+ werr = WERR_OK;
+
+ *num_shares = count - 1;
+ if (count > 0) {
+ *share_names = talloc_move(mem_ctx, &tmp_share_names);
+ }
+
+done:
+ TALLOC_FREE(tmp_ctx);
+ return werr;
+}
+
+/**
+ * get a definition of a share (service) from configuration.
+ */
+WERROR libnet_smbconf_getshare(TALLOC_CTX *mem_ctx, const char *servicename,
+ uint32_t *num_params, char ***param_names,
+ char ***param_values)
+{
+ WERROR werr = WERR_OK;
+ struct registry_key *key = NULL;
+
+ werr = libnet_smbconf_reg_open_path(mem_ctx, servicename, REG_KEY_READ,
+ &key);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
+ werr = libnet_smbconf_reg_get_values(mem_ctx, key, num_params,
+ param_names, param_values);
+
+done:
+ TALLOC_FREE(key);
+ return werr;
+}
+
+/**
* delete a service from configuration
*/
WERROR libnet_smbconf_delshare(const char *servicename)
diff --git a/source/utils/net_conf.c b/source/utils/net_conf.c
index 8140941..42af824 100644
--- a/source/utils/net_conf.c
+++ b/source/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_get_share_names(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;
@@ -525,7 +515,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 +529,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;
--
Samba Shared Repository
More information about the samba-cvs
mailing list