diff options
author | Michael Adam <obnox@samba.org> | 2010-02-26 09:31:03 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2010-03-03 09:16:36 +0100 |
commit | 93d438d9709e8e6462721f010c9a484a92a6649a (patch) | |
tree | 1e63611871e97183272ce66e055cd4f5a14d43c6 /source3 | |
parent | 9cea4d5969d3061689e7399e0a97f7f83ed31976 (diff) | |
download | samba-93d438d9709e8e6462721f010c9a484a92a6649a.tar.gz samba-93d438d9709e8e6462721f010c9a484a92a6649a.tar.bz2 samba-93d438d9709e8e6462721f010c9a484a92a6649a.zip |
s3:net: refactor getting of secdesc out of net_registry_getsd()
New net_registry_getsd_internal does the work(),
net_registry_getsd() just prints the result.
This in preparation to add support for other output formats
than the currently used display_sec_desc().
Michael
Diffstat (limited to 'source3')
-rw-r--r-- | source3/utils/net_registry.c | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c index c118b73310..2a13ebd6bd 100644 --- a/source3/utils/net_registry.c +++ b/source3/utils/net_registry.c @@ -420,13 +420,13 @@ done: return ret; } -static int net_registry_getsd(struct net_context *c, int argc, - const char **argv) +static WERROR net_registry_getsd_internal(struct net_context *c, + TALLOC_CTX *mem_ctx, + const char *keyname, + struct security_descriptor **sd) { WERROR werr; - int ret = -1; struct registry_key *key = NULL; - struct security_descriptor *secdesc = NULL; TALLOC_CTX *ctx = talloc_stackframe(); uint32_t access_mask = REG_KEY_READ | SEC_FLAG_MAXIMUM_ALLOWED | @@ -438,33 +438,61 @@ static int net_registry_getsd(struct net_context *c, int argc, */ access_mask = REG_KEY_READ; - if (argc != 1 || c->display_usage) { - d_printf("%s\n%s", - _("Usage:"), - _("net registry getsd <path>\n")); - d_printf("%s\n%s", - _("Example:"), - _("net registry getsd 'HKLM\\Software\\Samba'\n")); + if (sd == NULL) { + d_fprintf(stderr, _("internal error: invalid argument\n")); + werr = WERR_INVALID_PARAM; goto done; } - if (strlen(argv[0]) == 0) { + + if (strlen(keyname) == 0) { d_fprintf(stderr, "error: zero length key name given\n"); + werr = WERR_INVALID_PARAM; goto done; } - werr = open_key(ctx, argv[0], access_mask, &key); + werr = open_key(ctx, keyname, access_mask, &key); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr)); goto done; } - werr = reg_getkeysecurity(ctx, key, &secdesc); + werr = reg_getkeysecurity(mem_ctx, key, sd); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, _("reg_getkeysecurity failed: %s\n"), win_errstr(werr)); goto done; } + werr = WERR_OK; + +done: + TALLOC_FREE(ctx); + return werr; +} + +static int net_registry_getsd(struct net_context *c, int argc, + const char **argv) +{ + WERROR werr; + int ret = -1; + struct security_descriptor *secdesc = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); + + if (argc != 1 || c->display_usage) { + d_printf("%s\n%s", + _("Usage:"), + _("net registry getsd <path>\n")); + d_printf("%s\n%s", + _("Example:"), + _("net registry getsd 'HKLM\\Software\\Samba'\n")); + goto done; + } + + werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + display_sec_desc(secdesc); ret = 0; |