#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;
/* 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;
}
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 */
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;
/* 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 );
}
}
/* 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;
}
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;
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;
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;
}
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;
}
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;
/********************************************************************
********************************************************************/
-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;
}
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;
/********************************************************************
********************************************************************/
-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;
}
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;