configure: Move assemblage of samba version strings to m4 include file.
[kai/samba.git] / source3 / services / services_db.c
index 07f7aa6002386fcb53dbe46790530fa77fcdf066..ae83e726977292bfdc871e74e50568a00e75d163 100644 (file)
@@ -112,7 +112,9 @@ static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx )
        if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
                return NULL;
 
-       if ( !(sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, acl, &sd_size)) )
+       if ( !(sd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
+                                 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
+                                 acl, &sd_size)) )
                return NULL;
 
        return sd;
@@ -125,22 +127,22 @@ static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx )
 
 static char *get_common_service_dispname( const char *servicename )
 {
-       static fstring dispname;
        int i;
 
        for ( i=0; common_unix_svcs[i].servicename; i++ ) {
                if (strequal(servicename, common_unix_svcs[i].servicename)) {
-                       fstr_sprintf( dispname, "%s (%s)",
+                       char *dispname;
+                       if (asprintf(&dispname,
+                               "%s (%s)",
                                common_unix_svcs[i].dispname,
-                               common_unix_svcs[i].servicename );
-
+                               common_unix_svcs[i].servicename) < 0) {
+                               return NULL;
+                       }
                        return dispname;
                }
        }
 
-       fstrcpy( dispname, servicename );
-
-       return dispname;
+       return SMB_STRDUP(servicename );
 }
 
 /********************************************************************
@@ -197,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", dyn_LIBDIR,
+       filepath = talloc_asprintf(info, "%s/%s/%s", get_dyn_LIBDIR(),
                                SVCCTL_SCRIPT_DIR, servicename);
        if (!filepath) {
                TALLOC_FREE(info);
@@ -275,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",
-                                       dyn_LIBDIR, SVCCTL_SCRIPT_DIR,
+                                       get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR,
                                        builtin_svcs[i].daemon) > 0) {
                                init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
                                SAFE_FREE(pstr);
@@ -292,9 +294,10 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
 
        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",dyn_LIBDIR,
+               if (asprintf(&pstr, "%s/%s/%s",get_dyn_LIBDIR(),
                                        SVCCTL_SCRIPT_DIR, name) > 0) {
                        init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
                        SAFE_FREE(pstr);
@@ -303,7 +306,9 @@ static void fill_service_values( const char *name, REGVAL_CTR *values )
                }
 
                /* lookup common unix display names */
-               init_unistr2( &dname, get_common_service_dispname( name ), UNI_STR_TERMINATE );
+               dispname = get_common_service_dispname(name);
+               init_unistr2( &dname, dispname ? dispname : "", UNI_STR_TERMINATE );
+               SAFE_FREE(dispname);
 
                /* get info from init file itself */
                if ( read_init_file( name, &init_info ) ) {
@@ -464,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 );
@@ -515,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,("add_new_svc_name: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               return NULL;
+               DEBUG(0,("svcctl_get_secdesc: talloc() failed!\n"));
+               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 */
@@ -541,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;
 }
 
@@ -577,7 +586,7 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
        SAFE_FREE(path);
 
        if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
-               DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
+               DEBUG(0,("svcctl_set_secdesc: talloc() failed!\n"));
                TALLOC_FREE( key );
                return False;
        }
@@ -602,9 +611,9 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
 /********************************************************************
 ********************************************************************/
 
-char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
+const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
 {
-       static fstring display_name;
+       char *display_name = NULL;
        REGISTRY_KEY *key = NULL;
        REGVAL_CTR *values;
        REGISTRY_VALUE *val;
@@ -637,7 +646,7 @@ char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
        if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) )
                goto fail;
 
-       rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 );
+       rpcstr_pull_talloc(ctx, &display_name, regval_data_p(val), regval_size(val), 0 );
 
        TALLOC_FREE( key );
 
@@ -646,16 +655,15 @@ char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
 fail:
        /* default to returning the service name */
        TALLOC_FREE( key );
-       fstrcpy( display_name, name );
-       return display_name;
+       return talloc_strdup(ctx, name);
 }
 
 /********************************************************************
 ********************************************************************/
 
-char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
+const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
 {
-       static fstring description;
+       char *description = NULL;
        REGISTRY_KEY *key = NULL;
        REGVAL_CTR *values;
        REGISTRY_VALUE *val;
@@ -670,7 +678,7 @@ char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
        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", 
+               DEBUG(0,("svcctl_lookup_description: key lookup failed! [%s] (%s)\n", 
                        path, dos_errstr(wresult)));
                SAFE_FREE(path);
                return NULL;
@@ -678,19 +686,19 @@ char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
        SAFE_FREE(path);
 
        if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
-               DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
+               DEBUG(0,("svcctl_lookup_description: talloc() failed!\n"));
                TALLOC_FREE( key );
                return NULL;
        }
 
        fetch_reg_values( key, values );
 
-       if ( !(val = regval_ctr_getvalue( values, "Description" )) )
-               fstrcpy( description, "Unix Service");
-       else
-               rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 );
-
-       TALLOC_FREE( key );
+       if ( !(val = regval_ctr_getvalue( values, "Description" )) ) {
+               TALLOC_FREE( key );
+               return "Unix Service";
+       }
+       rpcstr_pull_talloc(ctx, &description, regval_data_p(val), regval_size(val), 0 );
+       TALLOC_FREE(key);
 
        return description;
 }