summaryrefslogtreecommitdiff
path: root/source3/services
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2010-09-20 08:06:30 +0200
committerMichael Adam <obnox@samba.org>2010-09-21 06:53:31 +0200
commite28bc8d763978762480367d031a4a62ebd411f8a (patch)
tree0abaeae67d9d4f29b66bf32ebe245db951e0cc7e /source3/services
parent53dcbc2dd2705c5273163c757e2587e3596c6971 (diff)
downloadsamba-e28bc8d763978762480367d031a4a62ebd411f8a.tar.gz
samba-e28bc8d763978762480367d031a4a62ebd411f8a.tar.bz2
samba-e28bc8d763978762480367d031a4a62ebd411f8a.zip
s3:services_db: factor out common code of lookup_dispname and lookup_description
into a new function svcctl_get_string_value()
Diffstat (limited to 'source3/services')
-rw-r--r--source3/services/services_db.c83
1 files changed, 31 insertions, 52 deletions
diff --git a/source3/services/services_db.c b/source3/services/services_db.c
index e05db94492..c296075c1f 100644
--- a/source3/services/services_db.c
+++ b/source3/services/services_db.c
@@ -617,102 +617,81 @@ done:
return ret;
}
-/********************************************************************
-********************************************************************/
-
-const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, struct security_token *token )
+static const char *svcctl_get_string_value(TALLOC_CTX *ctx, const char *key_name,
+ const char *value_name,
+ struct security_token *token)
{
- const char *display_name = NULL;
+ const char *result = NULL;
struct registry_key *key = NULL;
struct registry_value *value = NULL;
char *path = NULL;
WERROR wresult;
TALLOC_CTX *mem_ctx = talloc_stackframe();
- path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, name);
+ path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, key_name);
if (path == NULL) {
goto done;
}
wresult = reg_open_path(mem_ctx, path, REG_KEY_READ, token, &key);
if (!W_ERROR_IS_OK(wresult)) {
- DEBUG(0, ("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n",
- path, win_errstr(wresult)));
- goto fail;
+ DEBUG(0, ("svcctl_get_string_value: key lookup failed! "
+ "[%s] (%s)\n", path, win_errstr(wresult)));
+ goto done;
}
- wresult = reg_queryvalue(mem_ctx, key, "DisplayName", &value);
+ wresult = reg_queryvalue(mem_ctx, key, value_name, &value);
if (!W_ERROR_IS_OK(wresult)) {
- DEBUG(0, ("svcctl_lookup_dispname: error getting value "
- "'DisplayName': %s\n", win_errstr(wresult)));
- goto fail;
+ DEBUG(0, ("svcctl_get_string_value: error getting value "
+ "'%s': %s\n", value_name, win_errstr(wresult)));
+ goto done;
}
if (value->type != REG_SZ) {
- goto fail;
+ goto done;
}
- pull_reg_sz(ctx, &value->data, &display_name);
+ pull_reg_sz(ctx, &value->data, &result);
goto done;
-fail:
- /* default to returning the service name */
- display_name = talloc_strdup(ctx, name);
-
done:
talloc_free(mem_ctx);
- return display_name;
+ return result;
}
/********************************************************************
********************************************************************/
-const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, struct security_token *token )
+const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, struct security_token *token )
{
- const char *description = NULL;
- struct registry_key *key = NULL;
- struct registry_value *value = NULL;
- char *path = NULL;
- WERROR wresult;
- TALLOC_CTX *mem_ctx = talloc_stackframe();
+ const char *display_name = NULL;
- path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, name);
- if (path == NULL) {
- goto done;
- }
+ display_name = svcctl_get_string_value(ctx, name, "DisplayName", token);
- wresult = reg_open_path(mem_ctx, path, REG_KEY_READ, token, &key);
- if (!W_ERROR_IS_OK(wresult)) {
- DEBUG(0, ("svcctl_lookup_description: key lookup failed! "
- "[%s] (%s)\n", path, win_errstr(wresult)));
- goto done;
+ if (display_name == NULL) {
+ display_name = talloc_strdup(ctx, name);
}
- wresult = reg_queryvalue(mem_ctx, key, "Description", &value);
- if (!W_ERROR_IS_OK(wresult)) {
- DEBUG(0, ("svcctl_lookup_dispname: error getting value "
- "'Description': %s\n", win_errstr(wresult)));
- goto fail;
- }
+ return display_name;
+}
- if (value->type != REG_SZ) {
- goto fail;
- }
+/********************************************************************
+********************************************************************/
- pull_reg_sz(ctx, &value->data, &description);
+const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, struct security_token *token )
+{
+ const char *description = NULL;
- goto done;
+ description = svcctl_get_string_value(ctx, name, "Description", token);
-fail:
- description = talloc_strdup(ctx, "Unix Service");
+ if (description == NULL) {
+ description = talloc_strdup(ctx, "Unix Service");
+ }
-done:
- talloc_free(mem_ctx);
return description;
}
-
/********************************************************************
********************************************************************/