s3:services_db: create the "Security" subkey if it does not exist in svcctl_set_secdesc()
authorMichael Adam <obnox@samba.org>
Tue, 21 Sep 2010 01:00:29 +0000 (03:00 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 21 Sep 2010 04:53:32 +0000 (06:53 +0200)
Windows behaves like this. - Tests will follow.

source3/services/services_db.c

index 2807e7e05c7a60ed2f4a86bf028a87427c136620..19fb1b56235c1d7c25afdf3a1fc73dacf28868ee 100644 (file)
@@ -569,27 +569,35 @@ bool svcctl_set_secdesc(const char *name, struct security_descriptor *sec_desc,
                        struct security_token *token)
 {
        struct registry_key *key = NULL;
+       struct registry_key *key_security = NULL;
        WERROR wresult;
        char *path = NULL;
        struct registry_value value;
        NTSTATUS status;
        bool ret = false;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
+       enum winreg_CreateAction action = REG_ACTION_NONE;
 
-       path = talloc_asprintf(mem_ctx, "%s\\%s\\%s", KEY_SERVICES, name,
-                              "Security");
+       path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, name);
        if (path == NULL) {
                goto done;
        }
 
        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;
        }
 
+       wresult = reg_createkey(mem_ctx, key, "Security", REG_KEY_ALL, &key_security, &action);
+       if (!W_ERROR_IS_OK(wresult)) {
+               DEBUG(0, ("svcctl_set_secdesc: reg_createkey failed: "
+                         "[%s\\Security] (%s)\n", key->key->name,
+                         win_errstr(wresult)));
+               goto done;
+       }
+
        status = marshall_sec_desc(mem_ctx, sec_desc, &value.data.data,
                                   &value.data.length);
        if (!NT_STATUS_IS_OK(status)) {
@@ -599,7 +607,7 @@ bool svcctl_set_secdesc(const char *name, struct security_descriptor *sec_desc,
 
        value.type = REG_BINARY;
 
-       wresult = reg_setvalue(key, "Security", &value);
+       wresult = reg_setvalue(key_security, "Security", &value);
        if (!W_ERROR_IS_OK(wresult)) {
                DEBUG(0, ("svcctl_set_secdesc: reg_setvalue failed: %s\n",
                          win_errstr(wresult)));