s3:services_db: fix a debug message
[amitay/samba.git] / source3 / services / services_db.c
index 35c88524e485da319174dcd370d844206dfe4a06..50e54b6524008e32fa8ca7a8f5597e86f3ff463a 100644 (file)
@@ -24,6 +24,9 @@
 #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;
@@ -112,13 +115,17 @@ static struct security_descriptor* 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;
 }
@@ -197,8 +204,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 */
 
@@ -208,7 +217,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;
@@ -223,14 +233,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 );
                }
        }
@@ -375,7 +387,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;
@@ -404,7 +417,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;
@@ -498,7 +512,7 @@ void svcctl_init_keys( void )
  in case of any failure.
 ********************************************************************/
 
-struct security_descriptor *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;
@@ -521,7 +535,8 @@ struct security_descriptor *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *nam
                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;
        }
@@ -559,60 +574,61 @@ done:
  Wrapper to make storing a Service sd easier
 ********************************************************************/
 
-bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, struct security_descriptor *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;
+       struct registry_key *key = NULL;
        WERROR wresult;
        char *path = NULL;
-       struct regval_ctr *values = NULL;
-       DATA_BLOB blob;
+       struct registry_value value;
        NTSTATUS status;
-       bool ret = False;
+       bool ret = false;
+       TALLOC_CTX *mem_ctx = talloc_stackframe();
 
        /* now add the security descriptor */
 
-       if (asprintf(&path, "%s\\%s\\%s", KEY_SERVICES, name, "Security") < 0) {
-               return false;
-       }
-       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;
+       path = talloc_asprintf(mem_ctx, "%s\\%s\\%s", KEY_SERVICES, name,
+                              "Security");
+       if (path == NULL) {
+               goto done;
        }
-       SAFE_FREE(path);
 
-       if ( !(values = TALLOC_ZERO_P( key, struct regval_ctr )) ) {
-               DEBUG(0,("svcctl_set_secdesc: talloc() failed!\n"));
-               TALLOC_FREE( key );
-               return False;
+       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;
        }
 
        /* stream the printer security descriptor */
 
-       status = marshall_sec_desc(ctx, sec_desc, &blob.data, &blob.length);
+       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: ndr_push_struct_blob() failed!\n"));
-               TALLOC_FREE( key );
-               return False;
+               goto done;
        }
 
-       regval_ctr_addvalue( values, "Security", REG_BINARY, blob.data, blob.length);
-       ret = store_reg_values( key, values );
+       value.type = REG_BINARY;
 
-       /* cleanup */
+       wresult = reg_setvalue(key, "Security", &value);
+       if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_set_secdesc: reg_setvalue failed: %s\n",
+                         win_errstr(wresult)));
+               goto done;
+       }
 
-       TALLOC_FREE( key);
+       ret = true;
 
+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_lookup_dispname(TALLOC_CTX *ctx, const char *name, struct security_token *token )
 {
        const char *display_name = NULL;
        struct registry_key_handle *key = NULL;
@@ -637,7 +653,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;
@@ -664,7 +681,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;
@@ -689,7 +706,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;
@@ -714,7 +732,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;
@@ -736,7 +754,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;