s3:services_db: untanlge assignments from check in read_init_file().
[amitay/samba.git] / source3 / services / services_db.c
index b610c922a9df2d7ed044997d2b835befef1bcfca..c819862b550c24be8f2dc4aa035990882179693e 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"
 
 struct rcinit_file_information {
        char *description;
@@ -86,12 +91,12 @@ struct service_display_info common_unix_svcs[] = {
 /********************************************************************
 ********************************************************************/
 
-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 +114,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 +203,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 +216,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 +232,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 );
                }
        }
@@ -258,13 +272,13 @@ static void fill_service_values(const char *name, struct 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 */
 
@@ -333,7 +347,7 @@ static void add_new_svc_name(struct registry_key_handle *key_parent,
        char *path = 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;
 
@@ -372,7 +386,8 @@ static void add_new_svc_name(struct registry_key_handle *key_parent,
 
        /* now for the service values */
 
-       if ( !(values = TALLOC_ZERO_P( key_service, struct 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;
@@ -401,7 +416,8 @@ static void add_new_svc_name(struct registry_key_handle *key_parent,
        }
        SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key_secdesc, struct 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;
@@ -423,7 +439,7 @@ static void add_new_svc_name(struct registry_key_handle *key_parent,
        }
 
        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 );
@@ -495,12 +511,12 @@ 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 )
 {
        struct registry_key_handle *key = NULL;
        struct regval_ctr *values = NULL;
        struct regval_blob *val = NULL;
-       SEC_DESC *ret_sd = NULL;
+       struct security_descriptor *ret_sd = NULL;
        char *path= NULL;
        WERROR wresult;
        NTSTATUS status;
@@ -518,7 +534,8 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
                goto done;
        }
 
-       if ( !(values = TALLOC_ZERO_P( key, struct regval_ctr )) ) {
+       wresult = regval_ctr_init(key, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("svcctl_get_secdesc: talloc() failed!\n"));
                goto done;
        }
@@ -556,7 +573,7 @@ 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 )
+bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, struct security_descriptor *sec_desc, struct security_token *token )
 {
        struct registry_key_handle *key = NULL;
        WERROR wresult;
@@ -581,7 +598,8 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
        }
        SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key, struct regval_ctr )) ) {
+       wresult = regval_ctr_init(key, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("svcctl_set_secdesc: talloc() failed!\n"));
                TALLOC_FREE( key );
                return False;
@@ -596,7 +614,7 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
                return False;
        }
 
-       regval_ctr_addvalue( values, "Security", REG_BINARY, (const char *)blob.data, blob.length);
+       regval_ctr_addvalue( values, "Security", REG_BINARY, blob.data, blob.length);
        ret = store_reg_values( key, values );
 
        /* cleanup */
@@ -609,7 +627,7 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
 /********************************************************************
 ********************************************************************/
 
-const char *svcctl_lookup_dispname(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 )
 {
        const char *display_name = NULL;
        struct registry_key_handle *key = NULL;
@@ -634,7 +652,8 @@ const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, NT_USER_TO
        }
        SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key, struct regval_ctr )) ) {
+       wresult = regval_ctr_init(key, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
                TALLOC_FREE( key );
                goto fail;
@@ -661,7 +680,7 @@ fail:
 /********************************************************************
 ********************************************************************/
 
-const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
+const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, struct security_token *token )
 {
        const char *description = NULL;
        struct registry_key_handle *key = NULL;
@@ -686,7 +705,8 @@ const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, NT_USER
        }
        SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key, struct regval_ctr )) ) {
+       wresult = regval_ctr_init(key, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("svcctl_lookup_description: talloc() failed!\n"));
                TALLOC_FREE( key );
                return NULL;
@@ -711,7 +731,7 @@ const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, NT_USER
 /********************************************************************
 ********************************************************************/
 
-struct regval_ctr *svcctl_fetch_regvalues(const char *name, NT_USER_TOKEN *token)
+struct regval_ctr *svcctl_fetch_regvalues(const char *name, struct security_token *token)
 {
        struct registry_key_handle *key = NULL;
        struct regval_ctr *values = NULL;
@@ -733,7 +753,8 @@ struct regval_ctr *svcctl_fetch_regvalues(const char *name, NT_USER_TOKEN *token
        }
        SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( NULL, struct regval_ctr )) ) {
+       wresult = regval_ctr_init(NULL, &values);
+       if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n"));
                TALLOC_FREE( key );
                return NULL;