2 * Unix SMB/CIFS implementation.
3 * Group Policy Object Support
4 * Copyright (C) Guenther Deschner 2007-2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "../libgpo/gpo.h"
22 #include "libgpo/gpo_proto.h"
24 #include "registry/reg_api.h"
25 #include "registry/reg_backend_db.h"
26 #include "registry/reg_api_util.h"
27 #include "registry/reg_init_basic.h"
28 #include "../libcli/security/security.h"
29 #include "libcli/security/dom_sid.h"
30 #include "../libcli/registry/util_reg.h"
33 /****************************************************************
34 ****************************************************************/
36 struct security_token
*registry_create_system_token(TALLOC_CTX
*mem_ctx
)
38 const struct security_token
*system_token
= get_system_token();
40 struct security_token
*dup_token
41 = security_token_duplicate(mem_ctx
, system_token
);
43 if (dup_token
== NULL
) {
44 DBG_WARNING("security_token_duplicate() failed\n");
51 /****************************************************************
52 ****************************************************************/
54 WERROR
gp_init_reg_ctx(TALLOC_CTX
*mem_ctx
,
55 const char *initial_path
,
56 uint32_t desired_access
,
57 const struct security_token
*token
,
58 struct gp_registry_context
**reg_ctx
)
60 struct gp_registry_context
*tmp_ctx
;
64 return WERR_INVALID_PARAMETER
;
67 werr
= registry_init_basic();
68 if (!W_ERROR_IS_OK(werr
)) {
72 tmp_ctx
= talloc_zero(mem_ctx
, struct gp_registry_context
);
73 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
76 tmp_ctx
->token
= token
;
78 tmp_ctx
->token
= registry_create_system_token(mem_ctx
);
80 if (!tmp_ctx
->token
) {
82 return WERR_NOT_ENOUGH_MEMORY
;
86 if (!W_ERROR_IS_OK(werr
)) {
91 tmp_ctx
->path
= talloc_strdup(mem_ctx
, initial_path
);
94 return WERR_NOT_ENOUGH_MEMORY
;
97 werr
= reg_open_path(mem_ctx
, tmp_ctx
->path
, desired_access
,
98 tmp_ctx
->token
, &tmp_ctx
->curr_key
);
99 if (!W_ERROR_IS_OK(werr
)) {
100 TALLOC_FREE(tmp_ctx
);
110 /****************************************************************
111 ****************************************************************/
113 void gp_free_reg_ctx(struct gp_registry_context
*reg_ctx
)
115 TALLOC_FREE(reg_ctx
);
118 /****************************************************************
119 ****************************************************************/
121 WERROR
gp_store_reg_subkey(TALLOC_CTX
*mem_ctx
,
122 const char *subkeyname
,
123 struct registry_key
*curr_key
,
124 struct registry_key
**new_key
)
126 enum winreg_CreateAction action
= REG_ACTION_NONE
;
129 werr
= reg_createkey(mem_ctx
, curr_key
, subkeyname
,
130 REG_KEY_WRITE
, new_key
, &action
);
131 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
138 /****************************************************************
139 ****************************************************************/
141 WERROR
gp_read_reg_subkey(TALLOC_CTX
*mem_ctx
,
142 struct gp_registry_context
*reg_ctx
,
143 const char *subkeyname
,
144 struct registry_key
**key
)
146 const char *tmp
= NULL
;
148 if (!reg_ctx
|| !subkeyname
|| !key
) {
149 return WERR_INVALID_PARAMETER
;
152 tmp
= talloc_asprintf(mem_ctx
, "%s\\%s", reg_ctx
->path
, subkeyname
);
153 W_ERROR_HAVE_NO_MEMORY(tmp
);
155 return reg_open_path(mem_ctx
, tmp
, REG_KEY_READ
,
156 reg_ctx
->token
, key
);
159 /****************************************************************
160 ****************************************************************/
162 WERROR
gp_store_reg_val_sz(TALLOC_CTX
*mem_ctx
,
163 struct registry_key
*key
,
164 const char *val_name
,
167 struct registry_value reg_val
;
169 reg_val
.type
= REG_SZ
;
170 if (!push_reg_sz(mem_ctx
, ®_val
.data
, val
)) {
171 return WERR_NOT_ENOUGH_MEMORY
;
174 return reg_setvalue(key
, val_name
, ®_val
);
177 /****************************************************************
178 ****************************************************************/
180 static WERROR
gp_store_reg_val_dword(TALLOC_CTX
*mem_ctx
,
181 struct registry_key
*key
,
182 const char *val_name
,
185 struct registry_value reg_val
;
187 reg_val
.type
= REG_DWORD
;
188 reg_val
.data
= data_blob_talloc(mem_ctx
, NULL
, 4);
189 SIVAL(reg_val
.data
.data
, 0, val
);
191 return reg_setvalue(key
, val_name
, ®_val
);
194 /****************************************************************
195 ****************************************************************/
197 WERROR
gp_read_reg_val_sz(TALLOC_CTX
*mem_ctx
,
198 struct registry_key
*key
,
199 const char *val_name
,
203 struct registry_value
*reg_val
= NULL
;
205 werr
= reg_queryvalue(mem_ctx
, key
, val_name
, ®_val
);
206 W_ERROR_NOT_OK_RETURN(werr
);
208 if (reg_val
->type
!= REG_SZ
) {
209 return WERR_INVALID_DATATYPE
;
212 if (!pull_reg_sz(mem_ctx
, ®_val
->data
, val
)) {
213 return WERR_NOT_ENOUGH_MEMORY
;
219 /****************************************************************
220 ****************************************************************/
222 static WERROR
gp_read_reg_val_dword(TALLOC_CTX
*mem_ctx
,
223 struct registry_key
*key
,
224 const char *val_name
,
228 struct registry_value
*reg_val
= NULL
;
230 werr
= reg_queryvalue(mem_ctx
, key
, val_name
, ®_val
);
231 W_ERROR_NOT_OK_RETURN(werr
);
233 if (reg_val
->type
!= REG_DWORD
) {
234 return WERR_INVALID_DATATYPE
;
237 if (reg_val
->data
.length
< 4) {
238 return WERR_INSUFFICIENT_BUFFER
;
240 *val
= IVAL(reg_val
->data
.data
, 0);
245 /****************************************************************
246 ****************************************************************/
248 static WERROR
gp_store_reg_gpovals(TALLOC_CTX
*mem_ctx
,
249 struct registry_key
*key
,
250 struct GROUP_POLICY_OBJECT
*gpo
)
255 return WERR_INVALID_PARAMETER
;
258 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "Version",
260 W_ERROR_NOT_OK_RETURN(werr
);
262 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "WQLFilterPass",
264 W_ERROR_NOT_OK_RETURN(werr
);
266 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "AccessDenied",
268 W_ERROR_NOT_OK_RETURN(werr
);
270 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "GPO-Disabled",
271 (gpo
->options
& GPO_FLAG_DISABLE
));
272 W_ERROR_NOT_OK_RETURN(werr
);
274 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "Options",
276 W_ERROR_NOT_OK_RETURN(werr
);
278 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "GPOID",
280 W_ERROR_NOT_OK_RETURN(werr
);
282 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "SOM",
283 gpo
->link
? gpo
->link
: "");
284 W_ERROR_NOT_OK_RETURN(werr
);
286 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "DisplayName",
288 W_ERROR_NOT_OK_RETURN(werr
);
290 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "WQL-Id",
292 W_ERROR_NOT_OK_RETURN(werr
);
297 /****************************************************************
298 ****************************************************************/
300 static const char *gp_reg_groupmembership_path(TALLOC_CTX
*mem_ctx
,
301 const struct dom_sid
*sid
,
304 struct dom_sid_buf sidbuf
;
306 if (flags
& GPO_LIST_FLAG_MACHINE
) {
307 return "GroupMembership";
310 return talloc_asprintf(
313 dom_sid_str_buf(sid
, &sidbuf
),
317 /****************************************************************
318 ****************************************************************/
320 static WERROR
gp_reg_del_groupmembership(TALLOC_CTX
*mem_ctx
,
321 struct registry_key
*key
,
322 const struct security_token
*token
,
325 const char *path
= NULL
;
327 path
= gp_reg_groupmembership_path(mem_ctx
, &token
->sids
[PRIMARY_USER_SID_INDEX
],
329 W_ERROR_HAVE_NO_MEMORY(path
);
331 return reg_deletekey_recursive(key
, path
);
335 /****************************************************************
336 ****************************************************************/
338 static WERROR
gp_reg_store_groupmembership(TALLOC_CTX
*mem_ctx
,
339 struct gp_registry_context
*reg_ctx
,
340 const struct security_token
*token
,
343 struct registry_key
*key
= NULL
;
346 const char *valname
= NULL
;
347 const char *path
= NULL
;
350 path
= gp_reg_groupmembership_path(mem_ctx
, &token
->sids
[PRIMARY_USER_SID_INDEX
],
352 W_ERROR_HAVE_NO_MEMORY(path
);
354 gp_reg_del_groupmembership(mem_ctx
, reg_ctx
->curr_key
, token
, flags
);
356 werr
= gp_store_reg_subkey(mem_ctx
, path
,
357 reg_ctx
->curr_key
, &key
);
358 W_ERROR_NOT_OK_RETURN(werr
);
360 for (i
=0; i
<token
->num_sids
; i
++) {
361 struct dom_sid_buf buf
;
363 valname
= talloc_asprintf(mem_ctx
, "Group%d", count
++);
364 W_ERROR_HAVE_NO_MEMORY(valname
);
366 werr
= gp_store_reg_val_sz(
370 dom_sid_str_buf(&token
->sids
[i
], &buf
));
371 W_ERROR_NOT_OK_RETURN(werr
);
374 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "Count", count
);
375 W_ERROR_NOT_OK_RETURN(werr
);
380 /****************************************************************
381 ****************************************************************/
384 static WERROR
gp_reg_read_groupmembership(TALLOC_CTX
*mem_ctx
,
385 struct gp_registry_context
*reg_ctx
,
386 const struct dom_sid
*object_sid
,
387 struct security_token
**token
,
390 struct registry_key
*key
= NULL
;
393 const char *valname
= NULL
;
394 const char *val
= NULL
;
395 const char *path
= NULL
;
397 int num_token_sids
= 0;
398 struct security_token
*tmp_token
= NULL
;
400 tmp_token
= talloc_zero(mem_ctx
, struct security_token
);
401 W_ERROR_HAVE_NO_MEMORY(tmp_token
);
403 path
= gp_reg_groupmembership_path(mem_ctx
, object_sid
, flags
);
404 W_ERROR_HAVE_NO_MEMORY(path
);
406 werr
= gp_read_reg_subkey(mem_ctx
, reg_ctx
, path
, &key
);
407 W_ERROR_NOT_OK_RETURN(werr
);
409 werr
= gp_read_reg_val_dword(mem_ctx
, key
, "Count", &count
);
410 W_ERROR_NOT_OK_RETURN(werr
);
412 for (i
=0; i
<count
; i
++) {
414 valname
= talloc_asprintf(mem_ctx
, "Group%d", i
);
415 W_ERROR_HAVE_NO_MEMORY(valname
);
417 werr
= gp_read_reg_val_sz(mem_ctx
, key
, valname
, &val
);
418 W_ERROR_NOT_OK_RETURN(werr
);
420 if (!string_to_sid(&tmp_token
->sids
[num_token_sids
++],
422 return WERR_INSUFFICIENT_BUFFER
;
426 tmp_token
->num_sids
= num_token_sids
;
433 /****************************************************************
434 ****************************************************************/
436 static const char *gp_req_state_path(TALLOC_CTX
*mem_ctx
,
437 const struct dom_sid
*sid
,
440 struct dom_sid_buf sidbuf
;
442 if (flags
& GPO_LIST_FLAG_MACHINE
) {
443 return GPO_REG_STATE_MACHINE
;
446 return talloc_asprintf(
450 dom_sid_str_buf(sid
, &sidbuf
));
453 /****************************************************************
454 ****************************************************************/
456 static WERROR
gp_del_reg_state(TALLOC_CTX
*mem_ctx
,
457 struct registry_key
*key
,
460 return reg_deletesubkeys_recursive(key
, path
);
463 /****************************************************************
464 ****************************************************************/
466 WERROR
gp_reg_state_store(TALLOC_CTX
*mem_ctx
,
469 const struct security_token
*token
,
470 struct GROUP_POLICY_OBJECT
*gpo_list
)
472 struct gp_registry_context
*reg_ctx
= NULL
;
473 WERROR werr
= WERR_GEN_FAILURE
;
474 const char *subkeyname
= NULL
;
475 struct GROUP_POLICY_OBJECT
*gpo
;
477 struct registry_key
*key
;
479 werr
= gp_init_reg_ctx(mem_ctx
, KEY_GROUP_POLICY
, REG_KEY_WRITE
,
481 W_ERROR_NOT_OK_RETURN(werr
);
483 werr
= gp_secure_key(mem_ctx
, flags
, reg_ctx
->curr_key
,
484 &token
->sids
[PRIMARY_USER_SID_INDEX
]);
485 if (!W_ERROR_IS_OK(werr
)) {
486 DEBUG(0,("failed to secure key: %s\n", win_errstr(werr
)));
490 werr
= gp_reg_store_groupmembership(mem_ctx
, reg_ctx
, token
, flags
);
491 if (!W_ERROR_IS_OK(werr
)) {
492 DEBUG(0,("failed to store group membership: %s\n", win_errstr(werr
)));
496 subkeyname
= gp_req_state_path(mem_ctx
, &token
->sids
[PRIMARY_USER_SID_INDEX
], flags
);
498 werr
= WERR_NOT_ENOUGH_MEMORY
;
502 werr
= gp_del_reg_state(mem_ctx
, reg_ctx
->curr_key
, subkeyname
);
503 if (!W_ERROR_IS_OK(werr
)) {
504 DEBUG(0,("failed to delete old state: %s\n", win_errstr(werr
)));
508 werr
= gp_store_reg_subkey(mem_ctx
, subkeyname
,
509 reg_ctx
->curr_key
, ®_ctx
->curr_key
);
510 if (!W_ERROR_IS_OK(werr
)) {
514 werr
= gp_store_reg_val_sz(mem_ctx
, reg_ctx
->curr_key
,
515 "Distinguished-Name", dn
);
516 if (!W_ERROR_IS_OK(werr
)) {
520 /* store link list */
522 werr
= gp_store_reg_subkey(mem_ctx
, "GPLink-List",
523 reg_ctx
->curr_key
, &key
);
524 if (!W_ERROR_IS_OK(werr
)) {
530 werr
= gp_store_reg_subkey(mem_ctx
, "GPO-List",
531 reg_ctx
->curr_key
, ®_ctx
->curr_key
);
532 if (!W_ERROR_IS_OK(werr
)) {
536 for (gpo
= gpo_list
; gpo
; gpo
= gpo
->next
) {
538 subkeyname
= talloc_asprintf(mem_ctx
, "%d", count
++);
540 werr
= WERR_NOT_ENOUGH_MEMORY
;
544 werr
= gp_store_reg_subkey(mem_ctx
, subkeyname
,
545 reg_ctx
->curr_key
, &key
);
546 if (!W_ERROR_IS_OK(werr
)) {
550 werr
= gp_store_reg_gpovals(mem_ctx
, key
, gpo
);
551 if (!W_ERROR_IS_OK(werr
)) {
552 DEBUG(0,("gp_reg_state_store: "
553 "gp_store_reg_gpovals failed for %s: %s\n",
554 gpo
->display_name
, win_errstr(werr
)));
559 gp_free_reg_ctx(reg_ctx
);
563 /****************************************************************
564 ****************************************************************/
566 static WERROR
gp_read_reg_gpovals(TALLOC_CTX
*mem_ctx
,
567 struct registry_key
*key
,
568 struct GROUP_POLICY_OBJECT
*gpo
)
573 return WERR_INVALID_PARAMETER
;
576 werr
= gp_read_reg_val_dword(mem_ctx
, key
, "Version",
578 W_ERROR_NOT_OK_RETURN(werr
);
580 werr
= gp_read_reg_val_dword(mem_ctx
, key
, "Options",
582 W_ERROR_NOT_OK_RETURN(werr
);
584 werr
= gp_read_reg_val_sz(mem_ctx
, key
, "GPOID",
586 W_ERROR_NOT_OK_RETURN(werr
);
588 werr
= gp_read_reg_val_sz(mem_ctx
, key
, "SOM",
590 W_ERROR_NOT_OK_RETURN(werr
);
592 werr
= gp_read_reg_val_sz(mem_ctx
, key
, "DisplayName",
594 W_ERROR_NOT_OK_RETURN(werr
);
599 /****************************************************************
600 ****************************************************************/
602 static WERROR
gp_read_reg_gpo(TALLOC_CTX
*mem_ctx
,
603 struct registry_key
*key
,
604 struct GROUP_POLICY_OBJECT
**gpo_ret
)
606 struct GROUP_POLICY_OBJECT
*gpo
= NULL
;
609 if (!gpo_ret
|| !key
) {
610 return WERR_INVALID_PARAMETER
;
613 gpo
= talloc_zero(mem_ctx
, struct GROUP_POLICY_OBJECT
);
614 W_ERROR_HAVE_NO_MEMORY(gpo
);
616 werr
= gp_read_reg_gpovals(mem_ctx
, key
, gpo
);
617 W_ERROR_NOT_OK_RETURN(werr
);
624 /****************************************************************
625 ****************************************************************/
627 WERROR
gp_reg_state_read(TALLOC_CTX
*mem_ctx
,
629 const struct dom_sid
*sid
,
630 struct GROUP_POLICY_OBJECT
**gpo_list
)
632 struct gp_registry_context
*reg_ctx
= NULL
;
633 WERROR werr
= WERR_GEN_FAILURE
;
634 const char *subkeyname
= NULL
;
635 struct GROUP_POLICY_OBJECT
*gpo
= NULL
;
637 struct registry_key
*key
= NULL
;
638 const char *path
= NULL
;
639 const char *gp_state_path
= NULL
;
642 return WERR_INVALID_PARAMETER
;
645 ZERO_STRUCTP(gpo_list
);
647 gp_state_path
= gp_req_state_path(mem_ctx
, sid
, flags
);
648 if (!gp_state_path
) {
649 werr
= WERR_NOT_ENOUGH_MEMORY
;
653 path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
658 werr
= WERR_NOT_ENOUGH_MEMORY
;
662 werr
= gp_init_reg_ctx(mem_ctx
, path
, REG_KEY_READ
, NULL
, ®_ctx
);
663 if (!W_ERROR_IS_OK(werr
)) {
669 subkeyname
= talloc_asprintf(mem_ctx
, "%d", count
++);
671 werr
= WERR_NOT_ENOUGH_MEMORY
;
675 werr
= gp_read_reg_subkey(mem_ctx
, reg_ctx
, subkeyname
, &key
);
676 if (W_ERROR_EQUAL(werr
, WERR_FILE_NOT_FOUND
)) {
680 if (!W_ERROR_IS_OK(werr
)) {
681 DEBUG(0,("gp_reg_state_read: "
682 "gp_read_reg_subkey gave: %s\n",
687 werr
= gp_read_reg_gpo(mem_ctx
, key
, &gpo
);
688 if (!W_ERROR_IS_OK(werr
)) {
692 DLIST_ADD(*gpo_list
, gpo
);
696 gp_free_reg_ctx(reg_ctx
);
700 /****************************************************************
701 ****************************************************************/
703 static WERROR
gp_reg_generate_sd(TALLOC_CTX
*mem_ctx
,
704 const struct dom_sid
*sid
,
705 struct security_descriptor
**sd
,
708 struct security_ace ace
[6] = {};
711 struct security_acl
*theacl
= NULL
;
713 uint8_t inherit_flags
;
716 init_sec_ace(&ace
[0],
718 SEC_ACE_TYPE_ACCESS_ALLOWED
,
722 init_sec_ace(&ace
[1],
723 &global_sid_Builtin_Administrators
,
724 SEC_ACE_TYPE_ACCESS_ALLOWED
,
728 init_sec_ace(&ace
[2],
729 sid
? sid
: &global_sid_Authenticated_Users
,
730 SEC_ACE_TYPE_ACCESS_ALLOWED
,
733 inherit_flags
= SEC_ACE_FLAG_OBJECT_INHERIT
|
734 SEC_ACE_FLAG_CONTAINER_INHERIT
|
735 SEC_ACE_FLAG_INHERIT_ONLY
;
738 init_sec_ace(&ace
[3],
740 SEC_ACE_TYPE_ACCESS_ALLOWED
,
741 mask
, inherit_flags
);
744 init_sec_ace(&ace
[4],
745 &global_sid_Builtin_Administrators
,
746 SEC_ACE_TYPE_ACCESS_ALLOWED
,
747 mask
, inherit_flags
);
750 init_sec_ace(&ace
[5],
751 sid
? sid
: &global_sid_Authenticated_Users
,
752 SEC_ACE_TYPE_ACCESS_ALLOWED
,
753 mask
, inherit_flags
);
755 theacl
= make_sec_acl(mem_ctx
, NT4_ACL_REVISION
, 6, ace
);
756 W_ERROR_HAVE_NO_MEMORY(theacl
);
758 *sd
= make_sec_desc(mem_ctx
, SD_REVISION
,
759 SEC_DESC_SELF_RELATIVE
|
760 SEC_DESC_DACL_AUTO_INHERITED
| /* really ? */
761 SEC_DESC_DACL_AUTO_INHERIT_REQ
, /* really ? */
764 W_ERROR_HAVE_NO_MEMORY(*sd
);
769 /****************************************************************
770 ****************************************************************/
772 WERROR
gp_secure_key(TALLOC_CTX
*mem_ctx
,
774 struct registry_key
*key
,
775 const struct dom_sid
*sid
)
777 struct security_descriptor
*sd
= NULL
;
779 const struct dom_sid
*sd_sid
= NULL
;
782 if (!(flags
& GPO_LIST_FLAG_MACHINE
)) {
786 werr
= gp_reg_generate_sd(mem_ctx
, sd_sid
, &sd
, &sd_size
);
787 W_ERROR_NOT_OK_RETURN(werr
);
789 return reg_setkeysecurity(key
, sd
);
792 /****************************************************************
793 ****************************************************************/
795 void dump_reg_val(int lvl
, const char *direction
,
796 const char *key
, const char *subkey
,
797 struct registry_value
*val
)
800 const char *type_str
= NULL
;
803 DEBUG(lvl
,("no val!\n"));
807 type_str
= str_regtype(val
->type
);
809 DEBUG(lvl
,("\tdump_reg_val:\t%s '%s'\n\t\t\t'%s' %s: ",
810 direction
, key
, subkey
, type_str
));
815 if (val
->data
.length
< 4) {
818 v
= IVAL(val
->data
.data
, 0);
819 DEBUG(lvl
,("%d (0x%08x)\n",
825 if (val
->data
.length
< 8) {
828 v
= BVAL(val
->data
.data
, 0);
829 DEBUG(lvl
,("%d (0x%016llx)\n",
831 (unsigned long long)v
));
836 if (!pull_reg_sz(talloc_tos(), &val
->data
, &s
)) {
839 DEBUG(lvl
,("%s (length: %d)\n",
840 s
, (int)strlen_m(s
)));
845 if (!pull_reg_multi_sz(talloc_tos(), &val
->data
, &a
)) {
848 for (i
=0; a
[i
] != NULL
; i
++) {
851 DEBUG(lvl
,("(num_strings: %d)\n", i
));
852 for (i
=0; a
[i
] != NULL
; i
++) {
853 DEBUGADD(lvl
,("\t%s\n", a
[i
]));
861 dump_data(lvl
, val
->data
.data
,
865 DEBUG(lvl
,("unsupported type: %d\n", val
->type
));
870 /****************************************************************
871 ****************************************************************/
873 void dump_reg_entry(uint32_t flags
,
875 struct gp_registry_entry
*entry
)
877 if (!(flags
& GPO_INFO_FLAG_VERBOSE
))
886 /****************************************************************
887 ****************************************************************/
889 void dump_reg_entries(uint32_t flags
,
891 struct gp_registry_entry
*entries
,
896 if (!(flags
& GPO_INFO_FLAG_VERBOSE
))
899 for (i
=0; i
< num_entries
; i
++) {
900 dump_reg_entry(flags
, dir
, &entries
[i
]);
904 /****************************************************************
905 ****************************************************************/
907 bool add_gp_registry_entry_to_array(TALLOC_CTX
*mem_ctx
,
908 struct gp_registry_entry
*entry
,
909 struct gp_registry_entry
**entries
,
912 *entries
= talloc_realloc(mem_ctx
, *entries
,
913 struct gp_registry_entry
,
916 if (*entries
== NULL
) {
921 (*entries
)[*num
].action
= entry
->action
;
922 (*entries
)[*num
].key
= entry
->key
;
923 (*entries
)[*num
].value
= entry
->value
;
924 (*entries
)[*num
].data
= entry
->data
;
930 /****************************************************************
931 ****************************************************************/
933 static const char *gp_reg_action_str(enum gp_reg_action action
)
936 case GP_REG_ACTION_NONE
:
937 return "GP_REG_ACTION_NONE";
938 case GP_REG_ACTION_ADD_VALUE
:
939 return "GP_REG_ACTION_ADD_VALUE";
940 case GP_REG_ACTION_ADD_KEY
:
941 return "GP_REG_ACTION_ADD_KEY";
942 case GP_REG_ACTION_DEL_VALUES
:
943 return "GP_REG_ACTION_DEL_VALUES";
944 case GP_REG_ACTION_DEL_VALUE
:
945 return "GP_REG_ACTION_DEL_VALUE";
946 case GP_REG_ACTION_DEL_ALL_VALUES
:
947 return "GP_REG_ACTION_DEL_ALL_VALUES";
948 case GP_REG_ACTION_DEL_KEYS
:
949 return "GP_REG_ACTION_DEL_KEYS";
950 case GP_REG_ACTION_SEC_KEY_SET
:
951 return "GP_REG_ACTION_SEC_KEY_SET";
952 case GP_REG_ACTION_SEC_KEY_RESET
:
953 return "GP_REG_ACTION_SEC_KEY_RESET";
959 /****************************************************************
960 ****************************************************************/
962 WERROR
reg_apply_registry_entry(TALLOC_CTX
*mem_ctx
,
963 struct registry_key
*root_key
,
964 struct gp_registry_context
*reg_ctx
,
965 struct gp_registry_entry
*entry
,
966 const struct security_token
*token
,
970 struct registry_key
*key
= NULL
;
972 if (flags
& GPO_INFO_FLAG_VERBOSE
) {
973 printf("about to store key: [%s]\n", entry
->key
);
974 printf(" value: [%s]\n", entry
->value
);
975 printf(" data: [%s]\n", str_regtype(entry
->data
->type
));
976 printf(" action: [%s]\n", gp_reg_action_str(entry
->action
));
979 werr
= gp_store_reg_subkey(mem_ctx
, entry
->key
,
981 /* reg_ctx->curr_key, &key); */
982 if (!W_ERROR_IS_OK(werr
)) {
983 DEBUG(0,("gp_store_reg_subkey failed: %s\n", win_errstr(werr
)));
987 switch (entry
->action
) {
988 case GP_REG_ACTION_NONE
:
989 case GP_REG_ACTION_ADD_KEY
:
992 case GP_REG_ACTION_SEC_KEY_SET
:
993 werr
= gp_secure_key(mem_ctx
, flags
,
995 &token
->sids
[PRIMARY_USER_SID_INDEX
]);
996 if (!W_ERROR_IS_OK(werr
)) {
997 DEBUG(0,("reg_apply_registry_entry: "
998 "gp_secure_key failed: %s\n",
1003 case GP_REG_ACTION_ADD_VALUE
:
1004 werr
= reg_setvalue(key
, entry
->value
, entry
->data
);
1005 if (!W_ERROR_IS_OK(werr
)) {
1006 DEBUG(0,("reg_apply_registry_entry: "
1007 "reg_setvalue failed: %s\n",
1009 dump_reg_entry(flags
, "STORE", entry
);
1013 case GP_REG_ACTION_DEL_VALUE
:
1014 werr
= reg_deletevalue(key
, entry
->value
);
1015 if (!W_ERROR_IS_OK(werr
)) {
1016 DEBUG(0,("reg_apply_registry_entry: "
1017 "reg_deletevalue failed: %s\n",
1019 dump_reg_entry(flags
, "STORE", entry
);
1023 case GP_REG_ACTION_DEL_ALL_VALUES
:
1024 werr
= reg_deleteallvalues(key
);
1025 if (!W_ERROR_IS_OK(werr
)) {
1026 DEBUG(0,("reg_apply_registry_entry: "
1027 "reg_deleteallvalues failed: %s\n",
1029 dump_reg_entry(flags
, "STORE", entry
);
1033 case GP_REG_ACTION_DEL_VALUES
:
1034 case GP_REG_ACTION_DEL_KEYS
:
1035 case GP_REG_ACTION_SEC_KEY_RESET
:
1036 DEBUG(0,("reg_apply_registry_entry: "
1037 "not yet supported: %s (%d)\n",
1038 gp_reg_action_str(entry
->action
),
1040 return WERR_NOT_SUPPORTED
;
1042 DEBUG(0,("invalid action: %d\n", entry
->action
));
1043 return WERR_INVALID_PARAMETER
;