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/registry/util_reg.h"
32 /****************************************************************
33 ****************************************************************/
35 struct security_token
*registry_create_system_token(TALLOC_CTX
*mem_ctx
)
37 struct security_token
*token
= NULL
;
39 token
= TALLOC_ZERO_P(mem_ctx
, struct security_token
);
41 DEBUG(1,("talloc failed\n"));
45 token
->privilege_mask
= SE_ALL_PRIVS
;
47 if (!NT_STATUS_IS_OK(add_sid_to_array(token
, &global_sid_System
,
48 &token
->sids
, &token
->num_sids
))) {
49 DEBUG(1,("Error adding nt-authority system sid to token\n"));
56 /****************************************************************
57 ****************************************************************/
59 WERROR
gp_init_reg_ctx(TALLOC_CTX
*mem_ctx
,
60 const char *initial_path
,
61 uint32_t desired_access
,
62 const struct security_token
*token
,
63 struct gp_registry_context
**reg_ctx
)
65 struct gp_registry_context
*tmp_ctx
;
69 return WERR_INVALID_PARAM
;
72 werr
= registry_init_basic();
73 if (!W_ERROR_IS_OK(werr
)) {
77 tmp_ctx
= TALLOC_ZERO_P(mem_ctx
, struct gp_registry_context
);
78 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
81 tmp_ctx
->token
= token
;
83 tmp_ctx
->token
= registry_create_system_token(mem_ctx
);
85 if (!tmp_ctx
->token
) {
91 if (!W_ERROR_IS_OK(werr
)) {
96 tmp_ctx
->path
= talloc_strdup(mem_ctx
, initial_path
);
102 werr
= reg_open_path(mem_ctx
, tmp_ctx
->path
, desired_access
,
103 tmp_ctx
->token
, &tmp_ctx
->curr_key
);
104 if (!W_ERROR_IS_OK(werr
)) {
105 TALLOC_FREE(tmp_ctx
);
115 /****************************************************************
116 ****************************************************************/
118 void gp_free_reg_ctx(struct gp_registry_context
*reg_ctx
)
120 TALLOC_FREE(reg_ctx
);
123 /****************************************************************
124 ****************************************************************/
126 WERROR
gp_store_reg_subkey(TALLOC_CTX
*mem_ctx
,
127 const char *subkeyname
,
128 struct registry_key
*curr_key
,
129 struct registry_key
**new_key
)
131 enum winreg_CreateAction action
= REG_ACTION_NONE
;
134 werr
= reg_createkey(mem_ctx
, curr_key
, subkeyname
,
135 REG_KEY_WRITE
, new_key
, &action
);
136 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
143 /****************************************************************
144 ****************************************************************/
146 WERROR
gp_read_reg_subkey(TALLOC_CTX
*mem_ctx
,
147 struct gp_registry_context
*reg_ctx
,
148 const char *subkeyname
,
149 struct registry_key
**key
)
151 const char *tmp
= NULL
;
153 if (!reg_ctx
|| !subkeyname
|| !key
) {
154 return WERR_INVALID_PARAM
;
157 tmp
= talloc_asprintf(mem_ctx
, "%s\\%s", reg_ctx
->path
, subkeyname
);
158 W_ERROR_HAVE_NO_MEMORY(tmp
);
160 return reg_open_path(mem_ctx
, tmp
, REG_KEY_READ
,
161 reg_ctx
->token
, key
);
164 /****************************************************************
165 ****************************************************************/
167 WERROR
gp_store_reg_val_sz(TALLOC_CTX
*mem_ctx
,
168 struct registry_key
*key
,
169 const char *val_name
,
172 struct registry_value reg_val
;
174 reg_val
.type
= REG_SZ
;
175 if (!push_reg_sz(mem_ctx
, ®_val
.data
, val
)) {
179 return reg_setvalue(key
, val_name
, ®_val
);
182 /****************************************************************
183 ****************************************************************/
185 static WERROR
gp_store_reg_val_dword(TALLOC_CTX
*mem_ctx
,
186 struct registry_key
*key
,
187 const char *val_name
,
190 struct registry_value reg_val
;
192 reg_val
.type
= REG_DWORD
;
193 reg_val
.data
= data_blob_talloc(mem_ctx
, NULL
, 4);
194 SIVAL(reg_val
.data
.data
, 0, val
);
196 return reg_setvalue(key
, val_name
, ®_val
);
199 /****************************************************************
200 ****************************************************************/
202 WERROR
gp_read_reg_val_sz(TALLOC_CTX
*mem_ctx
,
203 struct registry_key
*key
,
204 const char *val_name
,
208 struct registry_value
*reg_val
= NULL
;
210 werr
= reg_queryvalue(mem_ctx
, key
, val_name
, ®_val
);
211 W_ERROR_NOT_OK_RETURN(werr
);
213 if (reg_val
->type
!= REG_SZ
) {
214 return WERR_INVALID_DATATYPE
;
217 if (!pull_reg_sz(mem_ctx
, ®_val
->data
, val
)) {
224 /****************************************************************
225 ****************************************************************/
227 static WERROR
gp_read_reg_val_dword(TALLOC_CTX
*mem_ctx
,
228 struct registry_key
*key
,
229 const char *val_name
,
233 struct registry_value
*reg_val
= NULL
;
235 werr
= reg_queryvalue(mem_ctx
, key
, val_name
, ®_val
);
236 W_ERROR_NOT_OK_RETURN(werr
);
238 if (reg_val
->type
!= REG_DWORD
) {
239 return WERR_INVALID_DATATYPE
;
242 if (reg_val
->data
.length
< 4) {
243 return WERR_INSUFFICIENT_BUFFER
;
245 *val
= IVAL(reg_val
->data
.data
, 0);
250 /****************************************************************
251 ****************************************************************/
253 static WERROR
gp_store_reg_gpovals(TALLOC_CTX
*mem_ctx
,
254 struct registry_key
*key
,
255 struct GROUP_POLICY_OBJECT
*gpo
)
260 return WERR_INVALID_PARAM
;
263 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "Version",
265 W_ERROR_NOT_OK_RETURN(werr
);
267 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "WQLFilterPass",
269 W_ERROR_NOT_OK_RETURN(werr
);
271 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "AccessDenied",
273 W_ERROR_NOT_OK_RETURN(werr
);
275 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "GPO-Disabled",
276 (gpo
->options
& GPO_FLAG_DISABLE
));
277 W_ERROR_NOT_OK_RETURN(werr
);
279 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "Options",
281 W_ERROR_NOT_OK_RETURN(werr
);
283 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "GPOID",
285 W_ERROR_NOT_OK_RETURN(werr
);
287 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "SOM",
289 W_ERROR_NOT_OK_RETURN(werr
);
291 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "DisplayName",
293 W_ERROR_NOT_OK_RETURN(werr
);
295 werr
= gp_store_reg_val_sz(mem_ctx
, key
, "WQL-Id",
297 W_ERROR_NOT_OK_RETURN(werr
);
302 /****************************************************************
303 ****************************************************************/
305 static const char *gp_reg_groupmembership_path(TALLOC_CTX
*mem_ctx
,
306 const struct dom_sid
*sid
,
309 if (flags
& GPO_LIST_FLAG_MACHINE
) {
310 return "GroupMembership";
313 return talloc_asprintf(mem_ctx
, "%s\\%s", sid_string_tos(sid
),
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
[0],
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
;
348 const char *val
= NULL
;
351 path
= gp_reg_groupmembership_path(mem_ctx
, &token
->sids
[0],
353 W_ERROR_HAVE_NO_MEMORY(path
);
355 gp_reg_del_groupmembership(mem_ctx
, reg_ctx
->curr_key
, token
, flags
);
357 werr
= gp_store_reg_subkey(mem_ctx
, path
,
358 reg_ctx
->curr_key
, &key
);
359 W_ERROR_NOT_OK_RETURN(werr
);
361 for (i
=0; i
<token
->num_sids
; i
++) {
363 valname
= talloc_asprintf(mem_ctx
, "Group%d", count
++);
364 W_ERROR_HAVE_NO_MEMORY(valname
);
366 val
= sid_string_talloc(mem_ctx
, &token
->sids
[i
]);
367 W_ERROR_HAVE_NO_MEMORY(val
);
368 werr
= gp_store_reg_val_sz(mem_ctx
, key
, valname
, val
);
369 W_ERROR_NOT_OK_RETURN(werr
);
372 werr
= gp_store_reg_val_dword(mem_ctx
, key
, "Count", count
);
373 W_ERROR_NOT_OK_RETURN(werr
);
378 /****************************************************************
379 ****************************************************************/
382 static WERROR
gp_reg_read_groupmembership(TALLOC_CTX
*mem_ctx
,
383 struct gp_registry_context
*reg_ctx
,
384 const struct dom_sid
*object_sid
,
385 struct security_token
**token
,
388 struct registry_key
*key
= NULL
;
391 const char *valname
= NULL
;
392 const char *val
= NULL
;
393 const char *path
= NULL
;
395 int num_token_sids
= 0;
396 struct security_token
*tmp_token
= NULL
;
398 tmp_token
= TALLOC_ZERO_P(mem_ctx
, struct security_token
);
399 W_ERROR_HAVE_NO_MEMORY(tmp_token
);
401 path
= gp_reg_groupmembership_path(mem_ctx
, object_sid
, flags
);
402 W_ERROR_HAVE_NO_MEMORY(path
);
404 werr
= gp_read_reg_subkey(mem_ctx
, reg_ctx
, path
, &key
);
405 W_ERROR_NOT_OK_RETURN(werr
);
407 werr
= gp_read_reg_val_dword(mem_ctx
, key
, "Count", &count
);
408 W_ERROR_NOT_OK_RETURN(werr
);
410 for (i
=0; i
<count
; i
++) {
412 valname
= talloc_asprintf(mem_ctx
, "Group%d", i
);
413 W_ERROR_HAVE_NO_MEMORY(valname
);
415 werr
= gp_read_reg_val_sz(mem_ctx
, key
, valname
, &val
);
416 W_ERROR_NOT_OK_RETURN(werr
);
418 if (!string_to_sid(&tmp_token
->sids
[num_token_sids
++],
420 return WERR_INSUFFICIENT_BUFFER
;
424 tmp_token
->num_sids
= num_token_sids
;
431 /****************************************************************
432 ****************************************************************/
434 static const char *gp_req_state_path(TALLOC_CTX
*mem_ctx
,
435 const struct dom_sid
*sid
,
438 if (flags
& GPO_LIST_FLAG_MACHINE
) {
439 return GPO_REG_STATE_MACHINE
;
442 return talloc_asprintf(mem_ctx
, "%s\\%s", "State", sid_string_tos(sid
));
445 /****************************************************************
446 ****************************************************************/
448 static WERROR
gp_del_reg_state(TALLOC_CTX
*mem_ctx
,
449 struct registry_key
*key
,
452 return reg_deletesubkeys_recursive(key
, path
);
455 /****************************************************************
456 ****************************************************************/
458 WERROR
gp_reg_state_store(TALLOC_CTX
*mem_ctx
,
461 const struct security_token
*token
,
462 struct GROUP_POLICY_OBJECT
*gpo_list
)
464 struct gp_registry_context
*reg_ctx
= NULL
;
465 WERROR werr
= WERR_GENERAL_FAILURE
;
466 const char *subkeyname
= NULL
;
467 struct GROUP_POLICY_OBJECT
*gpo
;
469 struct registry_key
*key
;
471 werr
= gp_init_reg_ctx(mem_ctx
, KEY_GROUP_POLICY
, REG_KEY_WRITE
,
473 W_ERROR_NOT_OK_RETURN(werr
);
475 werr
= gp_secure_key(mem_ctx
, flags
, reg_ctx
->curr_key
,
477 if (!W_ERROR_IS_OK(werr
)) {
478 DEBUG(0,("failed to secure key: %s\n", win_errstr(werr
)));
482 werr
= gp_reg_store_groupmembership(mem_ctx
, reg_ctx
, token
, flags
);
483 if (!W_ERROR_IS_OK(werr
)) {
484 DEBUG(0,("failed to store group membership: %s\n", win_errstr(werr
)));
488 subkeyname
= gp_req_state_path(mem_ctx
, &token
->sids
[0], flags
);
494 werr
= gp_del_reg_state(mem_ctx
, reg_ctx
->curr_key
, subkeyname
);
495 if (!W_ERROR_IS_OK(werr
)) {
496 DEBUG(0,("failed to delete old state: %s\n", win_errstr(werr
)));
500 werr
= gp_store_reg_subkey(mem_ctx
, subkeyname
,
501 reg_ctx
->curr_key
, ®_ctx
->curr_key
);
502 if (!W_ERROR_IS_OK(werr
)) {
506 werr
= gp_store_reg_val_sz(mem_ctx
, reg_ctx
->curr_key
,
507 "Distinguished-Name", dn
);
508 if (!W_ERROR_IS_OK(werr
)) {
512 /* store link list */
514 werr
= gp_store_reg_subkey(mem_ctx
, "GPLink-List",
515 reg_ctx
->curr_key
, &key
);
516 if (!W_ERROR_IS_OK(werr
)) {
522 werr
= gp_store_reg_subkey(mem_ctx
, "GPO-List",
523 reg_ctx
->curr_key
, ®_ctx
->curr_key
);
524 if (!W_ERROR_IS_OK(werr
)) {
528 for (gpo
= gpo_list
; gpo
; gpo
= gpo
->next
) {
530 subkeyname
= talloc_asprintf(mem_ctx
, "%d", count
++);
536 werr
= gp_store_reg_subkey(mem_ctx
, subkeyname
,
537 reg_ctx
->curr_key
, &key
);
538 if (!W_ERROR_IS_OK(werr
)) {
542 werr
= gp_store_reg_gpovals(mem_ctx
, key
, gpo
);
543 if (!W_ERROR_IS_OK(werr
)) {
544 DEBUG(0,("gp_reg_state_store: "
545 "gpo_store_reg_gpovals failed for %s: %s\n",
546 gpo
->display_name
, win_errstr(werr
)));
551 gp_free_reg_ctx(reg_ctx
);
555 /****************************************************************
556 ****************************************************************/
558 static WERROR
gp_read_reg_gpovals(TALLOC_CTX
*mem_ctx
,
559 struct registry_key
*key
,
560 struct GROUP_POLICY_OBJECT
*gpo
)
565 return WERR_INVALID_PARAM
;
568 werr
= gp_read_reg_val_dword(mem_ctx
, key
, "Version",
570 W_ERROR_NOT_OK_RETURN(werr
);
572 werr
= gp_read_reg_val_dword(mem_ctx
, key
, "Options",
574 W_ERROR_NOT_OK_RETURN(werr
);
576 werr
= gp_read_reg_val_sz(mem_ctx
, key
, "GPOID",
578 W_ERROR_NOT_OK_RETURN(werr
);
580 werr
= gp_read_reg_val_sz(mem_ctx
, key
, "SOM",
582 W_ERROR_NOT_OK_RETURN(werr
);
584 werr
= gp_read_reg_val_sz(mem_ctx
, key
, "DisplayName",
586 W_ERROR_NOT_OK_RETURN(werr
);
591 /****************************************************************
592 ****************************************************************/
594 static WERROR
gp_read_reg_gpo(TALLOC_CTX
*mem_ctx
,
595 struct registry_key
*key
,
596 struct GROUP_POLICY_OBJECT
**gpo_ret
)
598 struct GROUP_POLICY_OBJECT
*gpo
= NULL
;
601 if (!gpo_ret
|| !key
) {
602 return WERR_INVALID_PARAM
;
605 gpo
= TALLOC_ZERO_P(mem_ctx
, struct GROUP_POLICY_OBJECT
);
606 W_ERROR_HAVE_NO_MEMORY(gpo
);
608 werr
= gp_read_reg_gpovals(mem_ctx
, key
, gpo
);
609 W_ERROR_NOT_OK_RETURN(werr
);
616 /****************************************************************
617 ****************************************************************/
619 WERROR
gp_reg_state_read(TALLOC_CTX
*mem_ctx
,
621 const struct dom_sid
*sid
,
622 struct GROUP_POLICY_OBJECT
**gpo_list
)
624 struct gp_registry_context
*reg_ctx
= NULL
;
625 WERROR werr
= WERR_GENERAL_FAILURE
;
626 const char *subkeyname
= NULL
;
627 struct GROUP_POLICY_OBJECT
*gpo
= NULL
;
629 struct registry_key
*key
= NULL
;
630 const char *path
= NULL
;
631 const char *gp_state_path
= NULL
;
634 return WERR_INVALID_PARAM
;
637 ZERO_STRUCTP(gpo_list
);
639 gp_state_path
= gp_req_state_path(mem_ctx
, sid
, flags
);
640 if (!gp_state_path
) {
645 path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
654 werr
= gp_init_reg_ctx(mem_ctx
, path
, REG_KEY_READ
, NULL
, ®_ctx
);
655 if (!W_ERROR_IS_OK(werr
)) {
661 subkeyname
= talloc_asprintf(mem_ctx
, "%d", count
++);
667 werr
= gp_read_reg_subkey(mem_ctx
, reg_ctx
, subkeyname
, &key
);
668 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)) {
672 if (!W_ERROR_IS_OK(werr
)) {
673 DEBUG(0,("gp_reg_state_read: "
674 "gp_read_reg_subkey gave: %s\n",
679 werr
= gp_read_reg_gpo(mem_ctx
, key
, &gpo
);
680 if (!W_ERROR_IS_OK(werr
)) {
684 DLIST_ADD(*gpo_list
, gpo
);
688 gp_free_reg_ctx(reg_ctx
);
692 /****************************************************************
693 ****************************************************************/
695 static WERROR
gp_reg_generate_sd(TALLOC_CTX
*mem_ctx
,
696 const struct dom_sid
*sid
,
697 struct security_descriptor
**sd
,
700 struct security_ace ace
[6];
703 struct security_acl
*theacl
= NULL
;
705 uint8_t inherit_flags
;
708 init_sec_ace(&ace
[0],
710 SEC_ACE_TYPE_ACCESS_ALLOWED
,
714 init_sec_ace(&ace
[1],
715 &global_sid_Builtin_Administrators
,
716 SEC_ACE_TYPE_ACCESS_ALLOWED
,
720 init_sec_ace(&ace
[2],
721 sid
? sid
: &global_sid_Authenticated_Users
,
722 SEC_ACE_TYPE_ACCESS_ALLOWED
,
725 inherit_flags
= SEC_ACE_FLAG_OBJECT_INHERIT
|
726 SEC_ACE_FLAG_CONTAINER_INHERIT
|
727 SEC_ACE_FLAG_INHERIT_ONLY
;
730 init_sec_ace(&ace
[3],
732 SEC_ACE_TYPE_ACCESS_ALLOWED
,
733 mask
, inherit_flags
);
736 init_sec_ace(&ace
[4],
737 &global_sid_Builtin_Administrators
,
738 SEC_ACE_TYPE_ACCESS_ALLOWED
,
739 mask
, inherit_flags
);
742 init_sec_ace(&ace
[5],
743 sid
? sid
: &global_sid_Authenticated_Users
,
744 SEC_ACE_TYPE_ACCESS_ALLOWED
,
745 mask
, inherit_flags
);
747 theacl
= make_sec_acl(mem_ctx
, NT4_ACL_REVISION
, 6, ace
);
748 W_ERROR_HAVE_NO_MEMORY(theacl
);
750 *sd
= make_sec_desc(mem_ctx
, SD_REVISION
,
751 SEC_DESC_SELF_RELATIVE
|
752 SEC_DESC_DACL_AUTO_INHERITED
| /* really ? */
753 SEC_DESC_DACL_AUTO_INHERIT_REQ
, /* really ? */
756 W_ERROR_HAVE_NO_MEMORY(*sd
);
761 /****************************************************************
762 ****************************************************************/
764 WERROR
gp_secure_key(TALLOC_CTX
*mem_ctx
,
766 struct registry_key
*key
,
767 const struct dom_sid
*sid
)
769 struct security_descriptor
*sd
= NULL
;
771 const struct dom_sid
*sd_sid
= NULL
;
774 if (!(flags
& GPO_LIST_FLAG_MACHINE
)) {
778 werr
= gp_reg_generate_sd(mem_ctx
, sd_sid
, &sd
, &sd_size
);
779 W_ERROR_NOT_OK_RETURN(werr
);
781 return reg_setkeysecurity(key
, sd
);
784 /****************************************************************
785 ****************************************************************/
787 void dump_reg_val(int lvl
, const char *direction
,
788 const char *key
, const char *subkey
,
789 struct registry_value
*val
)
792 const char *type_str
= NULL
;
795 DEBUG(lvl
,("no val!\n"));
799 type_str
= str_regtype(val
->type
);
801 DEBUG(lvl
,("\tdump_reg_val:\t%s '%s'\n\t\t\t'%s' %s: ",
802 direction
, key
, subkey
, type_str
));
807 if (val
->data
.length
< 4) {
810 v
= IVAL(val
->data
.data
, 0);
811 DEBUG(lvl
,("%d (0x%08x)\n",
817 if (val
->data
.length
< 8) {
820 v
= BVAL(val
->data
.data
, 0);
821 DEBUG(lvl
,("%d (0x%016llx)\n",
823 (unsigned long long)v
));
828 if (!pull_reg_sz(talloc_tos(), &val
->data
, &s
)) {
831 DEBUG(lvl
,("%s (length: %d)\n",
832 s
, (int)strlen_m(s
)));
837 if (!pull_reg_multi_sz(talloc_tos(), &val
->data
, &a
)) {
840 for (i
=0; a
[i
] != NULL
; i
++) {
843 DEBUG(lvl
,("(num_strings: %d)\n", i
));
844 for (i
=0; a
[i
] != NULL
; i
++) {
845 DEBUGADD(lvl
,("\t%s\n", a
[i
]));
853 dump_data(lvl
, val
->data
.data
,
857 DEBUG(lvl
,("unsupported type: %d\n", val
->type
));
862 /****************************************************************
863 ****************************************************************/
865 void dump_reg_entry(uint32_t flags
,
867 struct gp_registry_entry
*entry
)
869 if (!(flags
& GPO_INFO_FLAG_VERBOSE
))
878 /****************************************************************
879 ****************************************************************/
881 void dump_reg_entries(uint32_t flags
,
883 struct gp_registry_entry
*entries
,
888 if (!(flags
& GPO_INFO_FLAG_VERBOSE
))
891 for (i
=0; i
< num_entries
; i
++) {
892 dump_reg_entry(flags
, dir
, &entries
[i
]);
896 /****************************************************************
897 ****************************************************************/
899 bool add_gp_registry_entry_to_array(TALLOC_CTX
*mem_ctx
,
900 struct gp_registry_entry
*entry
,
901 struct gp_registry_entry
**entries
,
904 *entries
= TALLOC_REALLOC_ARRAY(mem_ctx
, *entries
,
905 struct gp_registry_entry
,
908 if (*entries
== NULL
) {
913 (*entries
)[*num
].action
= entry
->action
;
914 (*entries
)[*num
].key
= entry
->key
;
915 (*entries
)[*num
].value
= entry
->value
;
916 (*entries
)[*num
].data
= entry
->data
;
922 /****************************************************************
923 ****************************************************************/
925 static const char *gp_reg_action_str(enum gp_reg_action action
)
928 case GP_REG_ACTION_NONE
:
929 return "GP_REG_ACTION_NONE";
930 case GP_REG_ACTION_ADD_VALUE
:
931 return "GP_REG_ACTION_ADD_VALUE";
932 case GP_REG_ACTION_ADD_KEY
:
933 return "GP_REG_ACTION_ADD_KEY";
934 case GP_REG_ACTION_DEL_VALUES
:
935 return "GP_REG_ACTION_DEL_VALUES";
936 case GP_REG_ACTION_DEL_VALUE
:
937 return "GP_REG_ACTION_DEL_VALUE";
938 case GP_REG_ACTION_DEL_ALL_VALUES
:
939 return "GP_REG_ACTION_DEL_ALL_VALUES";
940 case GP_REG_ACTION_DEL_KEYS
:
941 return "GP_REG_ACTION_DEL_KEYS";
942 case GP_REG_ACTION_SEC_KEY_SET
:
943 return "GP_REG_ACTION_SEC_KEY_SET";
944 case GP_REG_ACTION_SEC_KEY_RESET
:
945 return "GP_REG_ACTION_SEC_KEY_RESET";
951 /****************************************************************
952 ****************************************************************/
954 WERROR
reg_apply_registry_entry(TALLOC_CTX
*mem_ctx
,
955 struct registry_key
*root_key
,
956 struct gp_registry_context
*reg_ctx
,
957 struct gp_registry_entry
*entry
,
958 const struct security_token
*token
,
962 struct registry_key
*key
= NULL
;
964 if (flags
& GPO_INFO_FLAG_VERBOSE
) {
965 printf("about to store key: [%s]\n", entry
->key
);
966 printf(" value: [%s]\n", entry
->value
);
967 printf(" data: [%s]\n", str_regtype(entry
->data
->type
));
968 printf(" action: [%s]\n", gp_reg_action_str(entry
->action
));
971 werr
= gp_store_reg_subkey(mem_ctx
, entry
->key
,
973 /* reg_ctx->curr_key, &key); */
974 if (!W_ERROR_IS_OK(werr
)) {
975 DEBUG(0,("gp_store_reg_subkey failed: %s\n", win_errstr(werr
)));
979 switch (entry
->action
) {
980 case GP_REG_ACTION_NONE
:
981 case GP_REG_ACTION_ADD_KEY
:
984 case GP_REG_ACTION_SEC_KEY_SET
:
985 werr
= gp_secure_key(mem_ctx
, flags
,
988 if (!W_ERROR_IS_OK(werr
)) {
989 DEBUG(0,("reg_apply_registry_entry: "
990 "gp_secure_key failed: %s\n",
995 case GP_REG_ACTION_ADD_VALUE
:
996 werr
= reg_setvalue(key
, entry
->value
, entry
->data
);
997 if (!W_ERROR_IS_OK(werr
)) {
998 DEBUG(0,("reg_apply_registry_entry: "
999 "reg_setvalue failed: %s\n",
1001 dump_reg_entry(flags
, "STORE", entry
);
1005 case GP_REG_ACTION_DEL_VALUE
:
1006 werr
= reg_deletevalue(key
, entry
->value
);
1007 if (!W_ERROR_IS_OK(werr
)) {
1008 DEBUG(0,("reg_apply_registry_entry: "
1009 "reg_deletevalue failed: %s\n",
1011 dump_reg_entry(flags
, "STORE", entry
);
1015 case GP_REG_ACTION_DEL_ALL_VALUES
:
1016 werr
= reg_deleteallvalues(key
);
1017 if (!W_ERROR_IS_OK(werr
)) {
1018 DEBUG(0,("reg_apply_registry_entry: "
1019 "reg_deleteallvalues failed: %s\n",
1021 dump_reg_entry(flags
, "STORE", entry
);
1025 case GP_REG_ACTION_DEL_VALUES
:
1026 case GP_REG_ACTION_DEL_KEYS
:
1027 case GP_REG_ACTION_SEC_KEY_RESET
:
1028 DEBUG(0,("reg_apply_registry_entry: "
1029 "not yet supported: %s (%d)\n",
1030 gp_reg_action_str(entry
->action
),
1032 return WERR_NOT_SUPPORTED
;
1034 DEBUG(0,("invalid action: %d\n", entry
->action
));
1035 return WERR_INVALID_PARAM
;