s3:services_db: extract core of svcctl_set_secdesc to _internal version
[amitay/samba.git] / source3 / services / services_db.c
index 7a4b90c7cf523e38d8027f1382143dafcebc5050..dcfb018b41eaecd04f88679962ebce160de27aaa 100644 (file)
  */
 
 #include "includes.h"
+#include "services/services.h"
+#include "registry.h"
+#include "registry/reg_util_legacy.h"
+#include "registry/reg_dispatcher.h"
+#include "registry/reg_objects.h"
+#include "registry/reg_api_util.h"
 
 struct rcinit_file_information {
        char *description;
@@ -82,16 +88,18 @@ struct service_display_info common_unix_svcs[] = {
   { NULL, NULL, NULL, NULL }
 };
 
+static WERROR svcctl_set_secdesc_internal(struct registry_key *key,
+                                         struct security_descriptor *sec_desc);
 
 /********************************************************************
 ********************************************************************/
 
-static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx )
+static struct security_descriptor* construct_service_sd( TALLOC_CTX *ctx )
 {
-       SEC_ACE ace[4];
+       struct security_ace ace[4];
        size_t i = 0;
-       SEC_DESC *sd = NULL;
-       SEC_ACL *theacl = NULL;
+       struct security_descriptor *sd = NULL;
+       struct security_acl *theacl = NULL;
        size_t sd_size;
 
        /* basic access for Everyone */
@@ -109,13 +117,17 @@ static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx )
 
        /* create the security descriptor */
 
-       if ( !(theacl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
+       theacl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace);
+       if (theacl == NULL) {
                return NULL;
+       }
 
-       if ( !(sd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
-                                 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
-                                 theacl, &sd_size)) )
+       sd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
+                          SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
+                          theacl, &sd_size);
+       if (sd == NULL) {
                return NULL;
+       }
 
        return sd;
 }
@@ -194,8 +206,10 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat
        XFILE *f = NULL;
        char *p = NULL;
 
-       if ( !(info = TALLOC_ZERO_P( NULL, struct rcinit_file_information ) ) )
+       info = TALLOC_ZERO_P( NULL, struct rcinit_file_information );
+       if (info == NULL) {
                return False;
+       }
 
        /* attempt the file open */
 
@@ -205,7 +219,8 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat
                TALLOC_FREE(info);
                return false;
        }
-       if (!(f = x_fopen( filepath, O_RDONLY, 0 ))) {
+       f = x_fopen( filepath, O_RDONLY, 0 );
+       if (f == NULL) {
                DEBUG(0,("read_init_file: failed to open [%s]\n", filepath));
                TALLOC_FREE(info);
                return false;
@@ -220,14 +235,16 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat
 
                /* Look for a line like '^#.*Description:' */
 
-               if ( (p = strstr( str, "Description:" )) != NULL ) {
+               p = strstr( str, "Description:" );
+               if (p != NULL) {
                        char *desc;
 
                        p += strlen( "Description:" ) + 1;
                        if ( !p )
                                break;
 
-                       if ( (desc = cleanup_string(p)) != NULL )
+                       desc = cleanup_string(p);
+                       if (desc != NULL)
                                info->description = talloc_strdup( info, desc );
                }
        }
@@ -248,9 +265,9 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat
  Display name, Description, etc...
 ********************************************************************/
 
-static void fill_service_values( const char *name, REGVAL_CTR *values )
+static void fill_service_values(const char *name, struct regval_ctr *values)
 {
-       UNISTR2 data, dname, ipath, description;
+       char *dname, *ipath, *description;
        uint32 dword;
        int i;
 
@@ -258,34 +275,27 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
           I'm just storing them here for cosmetic purposes */
 
        dword = SVCCTL_AUTO_START;
-       regval_ctr_addvalue( values, "Start", REG_DWORD, (char*)&dword, sizeof(uint32));
+       regval_ctr_addvalue( values, "Start", REG_DWORD, (uint8 *)&dword, sizeof(uint32));
 
        dword = SERVICE_TYPE_WIN32_OWN_PROCESS;
-       regval_ctr_addvalue( values, "Type", REG_DWORD, (char*)&dword, sizeof(uint32));
+       regval_ctr_addvalue( values, "Type", REG_DWORD, (uint8 *)&dword, sizeof(uint32));
 
        dword = SVCCTL_SVC_ERROR_NORMAL;
-       regval_ctr_addvalue( values, "ErrorControl", REG_DWORD, (char*)&dword, sizeof(uint32));
+       regval_ctr_addvalue( values, "ErrorControl", REG_DWORD, (uint8 *)&dword, sizeof(uint32));
 
        /* everything runs as LocalSystem */
 
-       init_unistr2( &data, "LocalSystem", UNI_STR_TERMINATE );
-       regval_ctr_addvalue( values, "ObjectName", REG_SZ, (char*)data.buffer, data.uni_str_len*2);
+       regval_ctr_addvalue_sz(values, "ObjectName", "LocalSystem");
 
        /* special considerations for internal services and the DisplayName value */
 
        for ( i=0; builtin_svcs[i].servicename; i++ ) {
                if ( strequal( name, builtin_svcs[i].servicename ) ) {
-                       char *pstr = NULL;
-                       if (asprintf(&pstr, "%s/%s/%s",
+                       ipath = talloc_asprintf(talloc_tos(), "%s/%s/%s",
                                        get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR,
-                                       builtin_svcs[i].daemon) > 0) {
-                               init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
-                               SAFE_FREE(pstr);
-                       } else {
-                               init_unistr2( &ipath, "", UNI_STR_TERMINATE );
-                       }
-                       init_unistr2( &description, builtin_svcs[i].description, UNI_STR_TERMINATE );
-                       init_unistr2( &dname, builtin_svcs[i].dispname, UNI_STR_TERMINATE );
+                                       builtin_svcs[i].daemon);
+                       description = talloc_strdup(talloc_tos(), builtin_svcs[i].description);
+                       dname = talloc_strdup(talloc_tos(), builtin_svcs[i].dispname);
                        break;
                }
        }
@@ -293,38 +303,37 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
        /* default to an external service if we haven't found a match */
 
        if ( builtin_svcs[i].servicename == NULL ) {
-               char *pstr = NULL;
                char *dispname = NULL;
                struct rcinit_file_information *init_info = NULL;
 
-               if (asprintf(&pstr, "%s/%s/%s",get_dyn_MODULESDIR(),
-                                       SVCCTL_SCRIPT_DIR, name) > 0) {
-                       init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
-                       SAFE_FREE(pstr);
-               } else {
-                       init_unistr2( &ipath, "", UNI_STR_TERMINATE );
-               }
+               ipath = talloc_asprintf(talloc_tos(), "%s/%s/%s",
+                                       get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR,
+                                       name);
 
                /* lookup common unix display names */
                dispname = get_common_service_dispname(name);
-               init_unistr2( &dname, dispname ? dispname : "", UNI_STR_TERMINATE );
+               dname = talloc_strdup(talloc_tos(), dispname ? dispname : "");
                SAFE_FREE(dispname);
 
                /* get info from init file itself */
                if ( read_init_file( name, &init_info ) ) {
-                       init_unistr2( &description, init_info->description, UNI_STR_TERMINATE );
+                       description = talloc_strdup(talloc_tos(), init_info->description);
                        TALLOC_FREE( init_info );
                }
                else {
-                       init_unistr2( &description, "External Unix Service", UNI_STR_TERMINATE );
+                       description = talloc_strdup(talloc_tos(), "External Unix Service");
                }
        }
 
        /* add the new values */
 
-       regval_ctr_addvalue( values, "DisplayName", REG_SZ, (char*)dname.buffer, dname.uni_str_len*2);
-       regval_ctr_addvalue( values, "ImagePath", REG_SZ, (char*)ipath.buffer, ipath.uni_str_len*2);
-       regval_ctr_addvalue( values, "Description", REG_SZ, (char*)description.buffer, description.uni_str_len*2);
+       regval_ctr_addvalue_sz(values, "DisplayName", dname);
+       regval_ctr_addvalue_sz(values, "ImagePath", ipath);
+       regval_ctr_addvalue_sz(values, "Description", description);
+
+       TALLOC_FREE(dname);
+       TALLOC_FREE(ipath);
+       TALLOC_FREE(description);
 
        return;
 }
@@ -332,15 +341,16 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
 /********************************************************************
 ********************************************************************/
 
-static void add_new_svc_name( REGISTRY_KEY *key_parent, struct regsubkey_ctr *subkeys,
-                              const char *name )
+static void add_new_svc_name(struct registry_key_handle *key_parent,
+                            struct regsubkey_ctr *subkeys,
+                            const char *name )
 {
-       REGISTRY_KEY *key_service = NULL, *key_secdesc = NULL;
+       struct registry_key_handle *key_service = NULL, *key_secdesc = NULL;
        WERROR wresult;
        char *path = NULL;
-       REGVAL_CTR *values = NULL;
+       struct regval_ctr *values = NULL;
        struct regsubkey_ctr *svc_subkeys = NULL;
-       SEC_DESC *sd = NULL;
+       struct security_descriptor *sd = NULL;
        DATA_BLOB sd_blob;
        NTSTATUS status;
 
@@ -379,7 +389,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, struct regsubkey_ctr *su
 
        /* now for the service values */
 
-       if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) {
+       wresult = regval_ctr_init(key_service, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
                TALLOC_FREE( key_service );
                return;
@@ -408,7 +419,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, struct regsubkey_ctr *su
        }
        SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) {
+       wresult = regval_ctr_init(key_secdesc, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
                TALLOC_FREE( key_secdesc );
                return;
@@ -430,7 +442,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, struct regsubkey_ctr *su
        }
 
        regval_ctr_addvalue(values, "Security", REG_BINARY,
-                           (const char *)sd_blob.data, sd_blob.length);
+                           sd_blob.data, sd_blob.length);
        store_reg_values( key_secdesc, values );
 
        TALLOC_FREE( key_secdesc );
@@ -446,7 +458,7 @@ void svcctl_init_keys( void )
        const char **service_list = lp_svcctl_list();
        int i;
        struct regsubkey_ctr *subkeys = NULL;
-       REGISTRY_KEY *key = NULL;
+       struct registry_key_handle *key = NULL;
        WERROR wresult;
 
        /* bad mojo here if the lookup failed.  Should not happen */
@@ -502,47 +514,40 @@ void svcctl_init_keys( void )
  in case of any failure.
 ********************************************************************/
 
-SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
+struct security_descriptor *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, struct security_token *token )
 {
-       REGISTRY_KEY *key = NULL;
-       REGVAL_CTR *values = NULL;
-       REGISTRY_VALUE *val = NULL;
-       SEC_DESC *ret_sd = NULL;
+       struct registry_key *key = NULL;
+       struct registry_value *value;
+       struct security_descriptor *ret_sd = NULL;
        char *path= NULL;
        WERROR wresult;
        NTSTATUS status;
+       TALLOC_CTX *mem_ctx = talloc_stackframe();
 
-       /* now add the security descriptor */
-
-       if (asprintf(&path, "%s\\%s\\%s", KEY_SERVICES, name, "Security") < 0) {
-               return NULL;
+       path = talloc_asprintf(mem_ctx, "%s\\%s\\%s", KEY_SERVICES, name,
+                              "Security");
+       if (path == NULL) {
+               goto done;
        }
-       wresult = regkey_open_internal( NULL, &key, path, token,
-                                       REG_KEY_ALL );
+
+       wresult = reg_open_path(mem_ctx, path, REG_KEY_ALL, token, &key);
        if ( !W_ERROR_IS_OK(wresult) ) {
                DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n",
                        path, win_errstr(wresult)));
                goto done;
        }
 
-       if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
-               DEBUG(0,("svcctl_get_secdesc: talloc() failed!\n"));
-               goto done;
-       }
-
-       if (fetch_reg_values( key, values ) == -1) {
-               DEBUG(0, ("Error getting registry values\n"));
-               goto done;
-       }
-
-       if ( !(val = regval_ctr_getvalue( values, "Security" )) ) {
+       wresult = reg_queryvalue(mem_ctx, key, "Security", &value);
+       if (W_ERROR_EQUAL(wresult, WERR_BADFILE)) {
                goto fallback_to_default_sd;
+       } else if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_get_secdesc: error getting value 'Security': "
+                         "%s\n", win_errstr(wresult)));
+               goto done;
        }
 
-       /* stream the service security descriptor */
-
-       status = unmarshall_sec_desc(ctx, regval_data_p(val),
-                                    regval_size(val), &ret_sd);
+       status = unmarshall_sec_desc(ctx, value->data.data,
+                                    value->data.length, &ret_sd);
 
        if (NT_STATUS_IS_OK(status)) {
                goto done;
@@ -554,8 +559,7 @@ fallback_to_default_sd:
        ret_sd = construct_service_sd(ctx);
 
 done:
-       SAFE_FREE(path);
-       TALLOC_FREE(key);
+       talloc_free(mem_ctx);
        return ret_sd;
 }
 
@@ -563,184 +567,147 @@ done:
  Wrapper to make storing a Service sd easier
 ********************************************************************/
 
-bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, NT_USER_TOKEN *token )
+static WERROR svcctl_set_secdesc_internal(struct registry_key *key,
+                                         struct security_descriptor *sec_desc)
 {
-       REGISTRY_KEY *key = NULL;
+       struct registry_key *key_security = NULL;
        WERROR wresult;
-       char *path = NULL;
-       REGVAL_CTR *values = NULL;
-       DATA_BLOB blob;
+       struct registry_value value;
        NTSTATUS status;
-       bool ret = False;
-
-       /* now add the security descriptor */
+       enum winreg_CreateAction action = REG_ACTION_NONE;
+       TALLOC_CTX *mem_ctx = talloc_stackframe();
 
-       if (asprintf(&path, "%s\\%s\\%s", KEY_SERVICES, name, "Security") < 0) {
-               return false;
+       wresult = reg_createkey(mem_ctx, key, "Security", REG_KEY_ALL, &key_security, &action);
+       if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_set_secdesc: reg_createkey failed: "
+                         "[%s\\Security] (%s)\n", key->key->name,
+                         win_errstr(wresult)));
+               goto done;
        }
-       wresult = regkey_open_internal( NULL, &key, path, token,
-                                       REG_KEY_ALL );
-       if ( !W_ERROR_IS_OK(wresult) ) {
-               DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n",
-                       path, win_errstr(wresult)));
-               SAFE_FREE(path);
-               return False;
+
+       status = marshall_sec_desc(mem_ctx, sec_desc, &value.data.data,
+                                  &value.data.length);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("svcctl_set_secdesc: marshall_sec_desc() failed: %s\n",
+                         nt_errstr(status)));
+               wresult = ntstatus_to_werror(status);
+               goto done;
        }
-       SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
-               DEBUG(0,("svcctl_set_secdesc: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               return False;
+       value.type = REG_BINARY;
+
+       wresult = reg_setvalue(key_security, "Security", &value);
+       if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_set_secdesc: reg_setvalue failed: %s\n",
+                         win_errstr(wresult)));
        }
 
-       /* stream the printer security descriptor */
+done:
+       talloc_free(mem_ctx);
+       return wresult;
+}
 
-       status = marshall_sec_desc(ctx, sec_desc, &blob.data, &blob.length);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0,("svcctl_set_secdesc: ndr_push_struct_blob() failed!\n"));
-               TALLOC_FREE( key );
-               return False;
+bool svcctl_set_secdesc(const char *name, struct security_descriptor *sec_desc,
+                       struct security_token *token)
+{
+       struct registry_key *key = NULL;
+       WERROR wresult;
+       char *path = NULL;
+       bool ret = false;
+       TALLOC_CTX *mem_ctx = talloc_stackframe();
+
+       path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, name);
+       if (path == NULL) {
+               goto done;
        }
 
-       regval_ctr_addvalue( values, "Security", REG_BINARY, (const char *)blob.data, blob.length);
-       ret = store_reg_values( key, values );
+       wresult = reg_open_path(mem_ctx, path, REG_KEY_ALL, token, &key);
+       if ( !W_ERROR_IS_OK(wresult) ) {
+               DEBUG(0, ("svcctl_set_secdesc: key lookup failed! [%s] (%s)\n",
+                         path, win_errstr(wresult)));
+               goto done;
+       }
 
-       /* cleanup */
+       wresult = svcctl_set_secdesc_internal(key, sec_desc);
 
-       TALLOC_FREE( key);
+       ret = W_ERROR_IS_OK(wresult);
 
+done:
+       talloc_free(mem_ctx);
        return ret;
 }
 
-/********************************************************************
-********************************************************************/
-
-const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
+const char *svcctl_get_string_value(TALLOC_CTX *ctx, const char *key_name,
+                                   const char *value_name,
+                                   struct security_token *token)
 {
-       char *display_name = NULL;
-       REGISTRY_KEY *key = NULL;
-       REGVAL_CTR *values = NULL;
-       REGISTRY_VALUE *val = 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();
 
-       /* now add the security descriptor */
-
-       if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) {
-               return NULL;
-       }
-       wresult = regkey_open_internal( NULL, &key, path, token,
-                                       REG_KEY_READ );
-       if ( !W_ERROR_IS_OK(wresult) ) {
-               DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", 
-                       path, win_errstr(wresult)));
-               SAFE_FREE(path);
-               goto fail;
+       path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, key_name);
+       if (path == NULL) {
+               goto done;
        }
-       SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
-               DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               goto fail;
+       wresult = reg_open_path(mem_ctx, path, REG_KEY_READ, token, &key);
+       if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_get_string_value: key lookup failed! "
+                         "[%s] (%s)\n", path, win_errstr(wresult)));
+               goto done;
        }
 
-       fetch_reg_values( key, values );
-
-       if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) )
-               goto fail;
+       wresult = reg_queryvalue(mem_ctx, key, value_name, &value);
+       if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_get_string_value: error getting value "
+                         "'%s': %s\n", value_name, win_errstr(wresult)));
+               goto done;
+       }
 
-       rpcstr_pull_talloc(ctx, &display_name, regval_data_p(val), regval_size(val), 0 );
+       if (value->type != REG_SZ) {
+               goto done;
+       }
 
-       TALLOC_FREE( key );
+       pull_reg_sz(ctx, &value->data, &result);
 
-       return display_name;
+       goto done;
 
-fail:
-       /* default to returning the service name */
-       TALLOC_FREE( key );
-       return talloc_strdup(ctx, name);
+done:
+       talloc_free(mem_ctx);
+       return result;
 }
 
 /********************************************************************
 ********************************************************************/
 
-const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
+const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, struct security_token *token )
 {
-       char *description = NULL;
-       REGISTRY_KEY *key = NULL;
-       REGVAL_CTR *values = NULL;
-       REGISTRY_VALUE *val = NULL;
-       char *path = NULL;
-       WERROR wresult;
-
-       /* now add the security descriptor */
-
-       if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) {
-               return NULL;
-       }
-       wresult = regkey_open_internal( NULL, &key, path, token,
-                                       REG_KEY_READ );
-       if ( !W_ERROR_IS_OK(wresult) ) {
-               DEBUG(0,("svcctl_lookup_description: key lookup failed! [%s] (%s)\n", 
-                       path, win_errstr(wresult)));
-               SAFE_FREE(path);
-               return NULL;
-       }
-       SAFE_FREE(path);
-
-       if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
-               DEBUG(0,("svcctl_lookup_description: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               return NULL;
-       }
+       const char *display_name = NULL;
 
-       fetch_reg_values( key, values );
+       display_name = svcctl_get_string_value(ctx, name, "DisplayName", token);
 
-       if ( !(val = regval_ctr_getvalue( values, "Description" )) ) {
-               TALLOC_FREE( key );
-               return "Unix Service";
+       if (display_name == NULL) {
+               display_name = talloc_strdup(ctx, name);
        }
-       rpcstr_pull_talloc(ctx, &description, regval_data_p(val), regval_size(val), 0 );
-       TALLOC_FREE(key);
 
-       return description;
+       return display_name;
 }
 
-
 /********************************************************************
 ********************************************************************/
 
-REGVAL_CTR *svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token )
+const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, struct security_token *token )
 {
-       REGISTRY_KEY *key = NULL;
-       REGVAL_CTR *values = NULL;
-       char *path = NULL;
-       WERROR wresult;
+       const char *description = NULL;
 
-       /* now add the security descriptor */
+       description = svcctl_get_string_value(ctx, name, "Description", token);
 
-       if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) {
-               return NULL;
-       }
-       wresult = regkey_open_internal( NULL, &key, path, token,
-                                       REG_KEY_READ );
-       if ( !W_ERROR_IS_OK(wresult) ) {
-               DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n",
-                       path, win_errstr(wresult)));
-               SAFE_FREE(path);
-               return NULL;
+       if (description == NULL) {
+               description = talloc_strdup(ctx, "Unix Service");
        }
-       SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
-               DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               return NULL;
-       }
-       fetch_reg_values( key, values );
-
-       TALLOC_FREE( key );
-       return values;
+       return description;
 }