svcctl: use MODULESDIR instead of LIBDIR for the svcctl script directory.
[kai/samba.git] / source3 / services / services_db.c
index d4e144d5ff8ca5d8ce1b36320cb8dfd2da34fee1..49761c32334106796b70cdc15bdc9eedd982d004 100644 (file)
@@ -199,7 +199,7 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat
 
        /* attempt the file open */
 
-       filepath = talloc_asprintf(info, "%s/%s/%s", get_dyn_LIBDIR(),
+       filepath = talloc_asprintf(info, "%s/%s/%s", get_dyn_MODULESDIR(),
                                SVCCTL_SCRIPT_DIR, servicename);
        if (!filepath) {
                TALLOC_FREE(info);
@@ -277,7 +277,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
                if ( strequal( name, builtin_svcs[i].servicename ) ) {
                        char *pstr = NULL;
                        if (asprintf(&pstr, "%s/%s/%s",
-                                       get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR,
+                                       get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR,
                                        builtin_svcs[i].daemon) > 0) {
                                init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
                                SAFE_FREE(pstr);
@@ -297,7 +297,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
                char *dispname = NULL;
                struct rcinit_file_information *init_info = NULL;
 
-               if (asprintf(&pstr, "%s/%s/%s",get_dyn_LIBDIR(),
+               if (asprintf(&pstr, "%s/%s/%s",get_dyn_MODULESDIR(),
                                        SVCCTL_SCRIPT_DIR, name) > 0) {
                        init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
                        SAFE_FREE(pstr);
@@ -469,7 +469,7 @@ void svcctl_init_keys( void )
 
        fetch_reg_keys( key, subkeys );
 
-       /* the builting services exist */
+       /* the builtin services exist */
 
        for ( i=0; builtin_svcs[i].servicename; i++ )
                add_new_svc_name( key, subkeys, builtin_svcs[i].servicename );
@@ -520,25 +520,21 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
        if ( !W_ERROR_IS_OK(wresult) ) {
                DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n",
                        path, dos_errstr(wresult)));
-               SAFE_FREE(path);
-               return NULL;
+               goto done;
        }
-       SAFE_FREE(path);
 
        if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
                DEBUG(0,("svcctl_get_secdesc: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               return NULL;
+               goto done;
        }
 
-       fetch_reg_values( key, values );
-
-       TALLOC_FREE(key);
+       if (fetch_reg_values( key, values ) == -1) {
+               DEBUG(0, ("Error getting registry values\n"));
+               goto done;
+       }
 
        if ( !(val = regval_ctr_getvalue( values, "Security" )) ) {
-               DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", 
-                       name));
-               return construct_service_sd( ctx );
+               goto fallback_to_default_sd;
        }
 
        /* stream the service security descriptor */
@@ -546,10 +542,18 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
        status = unmarshall_sec_desc(ctx, regval_data_p(val),
                                     regval_size(val), &ret_sd);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               return construct_service_sd( ctx );
+       if (NT_STATUS_IS_OK(status)) {
+               goto done;
        }
 
+fallback_to_default_sd:
+       DEBUG(6, ("svcctl_get_secdesc: constructing default secdesc for "
+                 "service [%s]\n", name));
+       ret_sd = construct_service_sd(ctx);
+
+done:
+       SAFE_FREE(path);
+       TALLOC_FREE(key);
        return ret_sd;
 }
 
@@ -588,7 +592,12 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
        }
 
        /* stream the printer security descriptor */
-       prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL);
+
+       if (!prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL)) {
+               DEBUG(0,("svcctl_set_secdesc: prs_init() failed!\n"));
+               TALLOC_FREE( key );
+               return False;
+       }
 
        if ( sec_io_desc("sec_desc", &sec_desc, &ps, 0 ) ) {
                uint32 offset = prs_offset( &ps );