lib: Give util_paths.c its own header
[nivanova/samba-autobuild/.git] / libgpo / gpext / gpext.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Group Policy Support
4  *  Copyright (C) Guenther Deschner 2007-2008
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include "includes.h"
21 #include "../libgpo/gpo.h"
22 #include "../libgpo/gpext/gpext.h"
23 #include "librpc/gen_ndr/ndr_misc.h"
24 #include "lib/util/dlinklist.h"
25 #include "../libcli/registry/util_reg.h"
26 #include "libgpo/gpo_proto.h"
27 #include "registry.h"
28 #include "registry/reg_api.h"
29 #include "lib/util/util_paths.h"
30
31 static struct gp_extension *extensions = NULL;
32
33 /****************************************************************
34 ****************************************************************/
35
36 struct gp_extension *gpext_get_gp_extension_list(void)
37 {
38         return extensions;
39 }
40
41 /****************************************************************
42 ****************************************************************/
43
44 /* see http://support.microsoft.com/kb/216358/en-us/ for more info */
45
46 struct gp_extension_reg_table gpext_reg_vals[] = {
47         { "DllName", REG_EXPAND_SZ },
48         { "ProcessGroupPolicy", REG_SZ },
49         { "NoMachinePolicy", REG_DWORD },
50         { "NoUserPolicy", REG_DWORD },
51         { "NoSlowLink", REG_DWORD },
52         { "NoBackgroundPolicy", REG_DWORD },
53         { "NoGPOListChanges", REG_DWORD },
54         { "PerUserLocalSettings", REG_DWORD },
55         { "RequiresSuccessfulRegistry", REG_DWORD },
56         { "EnableAsynchronousProcessing", REG_DWORD },
57         { "ExtensionDebugLevel", REG_DWORD },
58         /* new */
59         { "GenerateGroupPolicy", REG_SZ }, /* not supported on w2k */
60         { "NotifyLinkTransition", REG_DWORD },
61         { "ProcessGroupPolicyEx", REG_SZ }, /* not supported on w2k */
62         { "ExtensionEventSource", REG_MULTI_SZ }, /* not supported on w2k */
63         { "GenerateGroupPolicy", REG_SZ },
64         { "MaxNoGPOListChangesInterval", REG_DWORD },
65         { NULL, REG_NONE }
66 };
67
68 /****************************************************************
69 ****************************************************************/
70
71 static struct gp_extension *get_extension_by_name(struct gp_extension *be,
72                                                   const char *name)
73 {
74         struct gp_extension *b;
75
76         for (b = be; b; b = b->next) {
77                 if (strequal(b->name, name)) {
78                         return b;
79                 }
80         }
81
82         return NULL;
83 }
84
85 /****************************************************************
86 ****************************************************************/
87
88 static struct gp_extension_methods *get_methods_by_name(struct gp_extension *be,
89                                                         const char *name)
90 {
91         struct gp_extension *b;
92
93         for (b = be; b; b = b->next) {
94                 if (strequal(b->name, name)) {
95                         return b->methods;
96                 }
97         }
98
99         return NULL;
100 }
101
102 /****************************************************************
103 ****************************************************************/
104
105 NTSTATUS gpext_unregister_gp_extension(const char *name)
106 {
107         struct gp_extension *ext;
108
109         ext = get_extension_by_name(extensions, name);
110         if (!ext) {
111                 return NT_STATUS_OK;
112         }
113
114         DLIST_REMOVE(extensions, ext);
115         talloc_free(ext);
116
117         DEBUG(2,("Successfully removed GP extension '%s'\n", name));
118
119         return NT_STATUS_OK;
120 }
121
122 /****************************************************************
123 ****************************************************************/
124
125 NTSTATUS gpext_register_gp_extension(TALLOC_CTX *gpext_ctx,
126                                      int version,
127                                      const char *name,
128                                      const char *guid,
129                                      struct gp_extension_methods *methods)
130 {
131         struct gp_extension_methods *test;
132         struct gp_extension *entry;
133         NTSTATUS status;
134
135         if (!gpext_ctx) {
136                 return NT_STATUS_INTERNAL_DB_ERROR;
137         }
138
139         if ((version != SMB_GPEXT_INTERFACE_VERSION)) {
140                 DEBUG(0,("Failed to register gp extension.\n"
141                          "The module was compiled against "
142                          "SMB_GPEXT_INTERFACE_VERSION %d,\n"
143                          "current SMB_GPEXT_INTERFACE_VERSION is %d.\n"
144                          "Please recompile against the current "
145                          "version of samba!\n",
146                          version, SMB_GPEXT_INTERFACE_VERSION));
147                 return NT_STATUS_OBJECT_TYPE_MISMATCH;
148         }
149
150         if (!guid || !name || !name[0] || !methods) {
151                 DEBUG(0,("Called with NULL pointer or empty name!\n"));
152                 return NT_STATUS_INVALID_PARAMETER;
153         }
154
155         test = get_methods_by_name(extensions, name);
156         if (test) {
157                 DEBUG(0,("GP extension module %s already registered!\n",
158                         name));
159                 return NT_STATUS_OBJECT_NAME_COLLISION;
160         }
161
162         entry = talloc_zero(gpext_ctx, struct gp_extension);
163         NT_STATUS_HAVE_NO_MEMORY(entry);
164
165         entry->name = talloc_strdup(gpext_ctx, name);
166         NT_STATUS_HAVE_NO_MEMORY(entry->name);
167
168         entry->guid = talloc_zero(gpext_ctx, struct GUID);
169         NT_STATUS_HAVE_NO_MEMORY(entry->guid);
170         status = GUID_from_string(guid, entry->guid);
171         NT_STATUS_NOT_OK_RETURN(status);
172
173         entry->methods = methods;
174         DLIST_ADD(extensions, entry);
175
176         DEBUG(2,("Successfully added GP extension '%s' %s\n",
177                 name, GUID_string2(gpext_ctx, entry->guid)));
178
179         return NT_STATUS_OK;
180 }
181
182 /****************************************************************
183 ****************************************************************/
184
185 static NTSTATUS gp_extension_init_module(TALLOC_CTX *mem_ctx,
186                                          const char *name,
187                                          struct gp_extension **gpext)
188 {
189         NTSTATUS status;
190         struct gp_extension *ext = NULL;
191
192         ext = talloc_zero(mem_ctx, struct gp_extension);
193         NT_STATUS_HAVE_NO_MEMORY(gpext);
194
195         ext->methods = get_methods_by_name(extensions, name);
196         if (!ext->methods) {
197
198                 status = smb_probe_module(SAMBA_SUBSYSTEM_GPEXT,
199                                           name);
200                 if (!NT_STATUS_IS_OK(status)) {
201                         return status;
202                 }
203
204                 ext->methods = get_methods_by_name(extensions, name);
205                 if (!ext->methods) {
206                         return NT_STATUS_DLL_INIT_FAILED;
207                 }
208         }
209
210         *gpext = ext;
211
212         return NT_STATUS_OK;
213 }
214
215 /****************************************************************
216 ****************************************************************/
217
218 static bool add_gp_extension_reg_entry_to_array(TALLOC_CTX *mem_ctx,
219                                                 struct gp_extension_reg_entry *entry,
220                                                 struct gp_extension_reg_entry **entries,
221                                                 size_t *num)
222 {
223         *entries = talloc_realloc(mem_ctx, *entries,
224                                         struct gp_extension_reg_entry,
225                                         (*num)+1);
226         if (*entries == NULL) {
227                 *num = 0;
228                 return false;
229         }
230
231         (*entries)[*num].value = entry->value;
232         (*entries)[*num].data = entry->data;
233
234         *num += 1;
235         return true;
236 }
237
238 /****************************************************************
239 ****************************************************************/
240
241 static bool add_gp_extension_reg_info_entry_to_array(TALLOC_CTX *mem_ctx,
242                                                      struct gp_extension_reg_info_entry *entry,
243                                                      struct gp_extension_reg_info_entry **entries,
244                                                      size_t *num)
245 {
246         *entries = talloc_realloc(mem_ctx, *entries,
247                                         struct gp_extension_reg_info_entry,
248                                         (*num)+1);
249         if (*entries == NULL) {
250                 *num = 0;
251                 return false;
252         }
253
254         (*entries)[*num].guid = entry->guid;
255         (*entries)[*num].num_entries = entry->num_entries;
256         (*entries)[*num].entries = entry->entries;
257
258         *num += 1;
259         return true;
260 }
261
262 /****************************************************************
263 ****************************************************************/
264
265 static NTSTATUS gp_ext_info_add_reg(TALLOC_CTX *mem_ctx,
266                                     struct gp_extension_reg_info_entry *entry,
267                                     const char *value,
268                                     enum winreg_Type type,
269                                     const char *data_s)
270 {
271         struct gp_extension_reg_entry *reg_entry = NULL;
272         struct registry_value *data = NULL;
273
274         reg_entry = talloc_zero(mem_ctx, struct gp_extension_reg_entry);
275         NT_STATUS_HAVE_NO_MEMORY(reg_entry);
276
277         data = talloc_zero(mem_ctx, struct registry_value);
278         NT_STATUS_HAVE_NO_MEMORY(data);
279
280         data->type = type;
281
282         switch (type) {
283                 case REG_SZ:
284                 case REG_EXPAND_SZ:
285                         if (!push_reg_sz(mem_ctx, &data->data, data_s)) {
286                                 return NT_STATUS_NO_MEMORY;
287                         }
288                         break;
289                 case REG_DWORD: {
290                         uint32_t v = atoi(data_s);
291                         data->data = data_blob_talloc(mem_ctx, NULL, 4);
292                         SIVAL(data->data.data, 0, v);
293                         break;
294                 }
295                 default:
296                         return NT_STATUS_NOT_SUPPORTED;
297         }
298
299         reg_entry->value = value;
300         reg_entry->data = data;
301
302         if (!add_gp_extension_reg_entry_to_array(mem_ctx, reg_entry,
303                                                  &entry->entries,
304                                                  &entry->num_entries)) {
305                 return NT_STATUS_NO_MEMORY;
306         }
307
308         return NT_STATUS_OK;
309 }
310
311 /****************************************************************
312 ****************************************************************/
313
314 static NTSTATUS gp_ext_info_add_reg_table(TALLOC_CTX *mem_ctx,
315                                           const char *module,
316                                           struct gp_extension_reg_info_entry *entry,
317                                           struct gp_extension_reg_table *table)
318 {
319         NTSTATUS status;
320         const char *module_name = NULL;
321         int i;
322
323         module_name = talloc_asprintf(mem_ctx, "%s.%s", module, shlib_ext());
324         NT_STATUS_HAVE_NO_MEMORY(module_name);
325
326         status = gp_ext_info_add_reg(mem_ctx, entry,
327                                      "DllName", REG_EXPAND_SZ, module_name);
328         NT_STATUS_NOT_OK_RETURN(status);
329
330         for (i=0; table[i].val; i++) {
331                 status = gp_ext_info_add_reg(mem_ctx, entry,
332                                              table[i].val,
333                                              table[i].type,
334                                              table[i].data);
335                 NT_STATUS_NOT_OK_RETURN(status);
336         }
337
338         return status;
339 }
340
341 /****************************************************************
342 ****************************************************************/
343
344 NTSTATUS gpext_info_add_entry(TALLOC_CTX *mem_ctx,
345                               const char *module,
346                               const char *ext_guid,
347                               struct gp_extension_reg_table *table,
348                               struct gp_extension_reg_info *info)
349 {
350         NTSTATUS status;
351         struct gp_extension_reg_info_entry *entry = NULL;
352
353         entry = talloc_zero(mem_ctx, struct gp_extension_reg_info_entry);
354         NT_STATUS_HAVE_NO_MEMORY(entry);
355
356         status = GUID_from_string(ext_guid, &entry->guid);
357         NT_STATUS_NOT_OK_RETURN(status);
358
359         status = gp_ext_info_add_reg_table(mem_ctx, module, entry, table);
360         NT_STATUS_NOT_OK_RETURN(status);
361
362         if (!add_gp_extension_reg_info_entry_to_array(mem_ctx, entry,
363                                                       &info->entries,
364                                                       &info->num_entries)) {
365                 return NT_STATUS_NO_MEMORY;
366         }
367
368         return NT_STATUS_OK;
369 }
370
371 /****************************************************************
372 ****************************************************************/
373
374 static bool gp_extension_reg_info_verify_entry(struct gp_extension_reg_entry *entry)
375 {
376         int i;
377
378         for (i=0; gpext_reg_vals[i].val; i++) {
379
380                 if ((strequal(entry->value, gpext_reg_vals[i].val)) &&
381                     (entry->data->type == gpext_reg_vals[i].type)) {
382                         return true;
383                 }
384         }
385
386         return false;
387 }
388
389 /****************************************************************
390 ****************************************************************/
391
392 static bool gp_extension_reg_info_verify(struct gp_extension_reg_info_entry *entry)
393 {
394         int i;
395
396         for (i=0; i < entry->num_entries; i++) {
397                 if (!gp_extension_reg_info_verify_entry(&entry->entries[i])) {
398                         return false;
399                 }
400         }
401
402         return true;
403 }
404
405 /****************************************************************
406 ****************************************************************/
407
408 static WERROR gp_extension_store_reg_vals(TALLOC_CTX *mem_ctx,
409                                           struct registry_key *key,
410                                           struct gp_extension_reg_info_entry *entry)
411 {
412         WERROR werr = WERR_OK;
413         size_t i;
414
415         for (i=0; i < entry->num_entries; i++) {
416
417                 werr = reg_setvalue(key,
418                                     entry->entries[i].value,
419                                     entry->entries[i].data);
420                 W_ERROR_NOT_OK_RETURN(werr);
421         }
422
423         return werr;
424 }
425
426 /****************************************************************
427 ****************************************************************/
428
429 static WERROR gp_extension_store_reg_entry(TALLOC_CTX *mem_ctx,
430                                            struct gp_registry_context *reg_ctx,
431                                            struct gp_extension_reg_info_entry *entry)
432 {
433         WERROR werr;
434         struct registry_key *key = NULL;
435         const char *subkeyname = NULL;
436
437         if (!gp_extension_reg_info_verify(entry)) {
438                 return WERR_INVALID_PARAMETER;
439         }
440
441         subkeyname = GUID_string2(mem_ctx, &entry->guid);
442         W_ERROR_HAVE_NO_MEMORY(subkeyname);
443
444         if (!strupper_m(discard_const_p(char, subkeyname))) {
445                 return WERR_INVALID_PARAMETER;
446         }
447
448         werr = gp_store_reg_subkey(mem_ctx,
449                                    subkeyname,
450                                    reg_ctx->curr_key,
451                                    &key);
452         W_ERROR_NOT_OK_RETURN(werr);
453
454         werr = gp_extension_store_reg_vals(mem_ctx,
455                                            key,
456                                            entry);
457         W_ERROR_NOT_OK_RETURN(werr);
458
459         return werr;
460 }
461
462 /****************************************************************
463 ****************************************************************/
464
465 static WERROR gp_extension_store_reg(TALLOC_CTX *mem_ctx,
466                                      struct gp_registry_context *reg_ctx,
467                                      struct gp_extension_reg_info *info)
468 {
469         WERROR werr = WERR_OK;
470         int i;
471
472         if (!info) {
473                 return WERR_OK;
474         }
475
476         for (i=0; i < info->num_entries; i++) {
477                 werr = gp_extension_store_reg_entry(mem_ctx,
478                                                     reg_ctx,
479                                                     &info->entries[i]);
480                 W_ERROR_NOT_OK_RETURN(werr);
481         }
482
483         return werr;
484 }
485
486 /****************************************************************
487 ****************************************************************/
488
489 static NTSTATUS gp_glob_ext_list(TALLOC_CTX *mem_ctx,
490                                  const char ***ext_list,
491                                  size_t *ext_list_len)
492 {
493         DIR *dir = NULL;
494         struct dirent *dirent = NULL;
495
496         dir = opendir(modules_path(talloc_tos(), 
497                                        SAMBA_SUBSYSTEM_GPEXT));
498         if (!dir) {
499                 return map_nt_error_from_unix_common(errno);
500         }
501
502         while ((dirent = readdir(dir))) {
503
504                 fstring name; /* forgive me... */
505                 char *p;
506
507                 if ((strequal(dirent->d_name, ".")) ||
508                     (strequal(dirent->d_name, ".."))) {
509                         continue;
510                 }
511
512                 p = strrchr(dirent->d_name, '.');
513                 if (!p) {
514                         closedir(dir);
515                         return NT_STATUS_NO_MEMORY;
516                 }
517
518                 if (!strcsequal(p+1, shlib_ext())) {
519                         DEBUG(10,("gp_glob_ext_list: not a *.so file: %s\n",
520                                 dirent->d_name));
521                         continue;
522                 }
523
524                 fstrcpy(name, dirent->d_name);
525                 name[PTR_DIFF(p, dirent->d_name)] = 0;
526
527                 if (!add_string_to_array(mem_ctx, name, ext_list,
528                                          ext_list_len)) {
529                         closedir(dir);
530                         return NT_STATUS_NO_MEMORY;
531                 }
532         }
533
534         closedir(dir);
535
536         return NT_STATUS_OK;
537 }
538
539 /****************************************************************
540 ****************************************************************/
541
542 NTSTATUS gpext_shutdown_gp_extensions(void)
543 {
544         struct gp_extension *ext = NULL;
545
546         for (ext = extensions; ext; ext = ext->next) {
547                 if (ext->methods && ext->methods->shutdown) {
548                         ext->methods->shutdown();
549                 }
550         }
551
552         return NT_STATUS_OK;
553 }
554
555 /****************************************************************
556 ****************************************************************/
557
558 NTSTATUS gpext_init_gp_extensions(TALLOC_CTX *mem_ctx)
559 {
560         NTSTATUS status;
561         WERROR werr;
562         int i = 0;
563         const char **ext_array = NULL;
564         size_t ext_array_len = 0;
565         struct gp_extension *gpext = NULL;
566         struct gp_registry_context *reg_ctx = NULL;
567
568         if (gpext_get_gp_extension_list()) {
569                 return NT_STATUS_OK;
570         }
571
572         status = gp_glob_ext_list(mem_ctx, &ext_array, &ext_array_len);
573         NT_STATUS_NOT_OK_RETURN(status);
574
575         for (i=0; i<ext_array_len; i++) {
576
577                 struct gp_extension_reg_info *info = NULL;
578
579                 status = gp_extension_init_module(mem_ctx, ext_array[i],
580                                                   &gpext);
581                 if (!NT_STATUS_IS_OK(status)) {
582                         goto out;
583                 }
584
585                 if (gpext->methods->get_reg_config) {
586
587                         status = gpext->methods->initialize(mem_ctx);
588                         if (!NT_STATUS_IS_OK(status)) {
589                                 gpext->methods->shutdown();
590                                 goto out;
591                         }
592
593                         status = gpext->methods->get_reg_config(mem_ctx,
594                                                                 &info);
595                         if (!NT_STATUS_IS_OK(status)) {
596                                 gpext->methods->shutdown();
597                                 goto out;
598                         }
599
600                         if (!reg_ctx) {
601                                 struct security_token *token;
602
603                                 token = registry_create_system_token(mem_ctx);
604                                 NT_STATUS_HAVE_NO_MEMORY(token);
605
606                                 werr = gp_init_reg_ctx(mem_ctx,
607                                                        KEY_WINLOGON_GPEXT_PATH,
608                                                        REG_KEY_WRITE,
609                                                        token,
610                                                        &reg_ctx);
611                                 if (!W_ERROR_IS_OK(werr)) {
612                                         status = werror_to_ntstatus(werr);
613                                         gpext->methods->shutdown();
614                                         goto out;
615                                 }
616                         }
617
618                         werr = gp_extension_store_reg(mem_ctx, reg_ctx, info);
619                         if (!W_ERROR_IS_OK(werr)) {
620                                 DEBUG(1,("gp_extension_store_reg failed: %s\n",
621                                         win_errstr(werr)));
622                                 TALLOC_FREE(info);
623                                 gpext->methods->shutdown();
624                                 status = werror_to_ntstatus(werr);
625                                 goto out;
626                         }
627                         TALLOC_FREE(info);
628                 }
629
630         }
631
632  out:
633         TALLOC_FREE(reg_ctx);
634
635         return status;
636 }
637
638 /****************************************************************
639 ****************************************************************/
640
641 NTSTATUS gpext_free_gp_extensions(void)
642 {
643         struct gp_extension *ext, *ext_next = NULL;
644
645         for (ext = extensions; ext; ext = ext_next) {
646                 ext_next = ext->next;
647                 DLIST_REMOVE(extensions, ext);
648                 TALLOC_FREE(ext);
649         }
650
651         extensions = NULL;
652
653         return NT_STATUS_OK;
654 }
655
656 /****************************************************************
657 ****************************************************************/
658
659 void gpext_debug_header(int lvl,
660                         const char *name,
661                         uint32_t flags,
662                         const struct GROUP_POLICY_OBJECT *gpo,
663                         const char *extension_guid,
664                         const char *snapin_guid)
665 {
666         char *flags_str = NULL;
667
668         DEBUG(lvl,("%s\n", name));
669         DEBUGADD(lvl,("\tgpo:           %s (%s)\n", gpo->name,
670                 gpo->display_name));
671         DEBUGADD(lvl,("\tcse extension: %s (%s)\n", extension_guid,
672                 cse_gpo_guid_string_to_name(extension_guid)));
673         DEBUGADD(lvl,("\tgplink:        %s\n", gpo->link));
674         DEBUGADD(lvl,("\tsnapin:        %s (%s)\n", snapin_guid,
675                 cse_snapin_gpo_guid_string_to_name(snapin_guid)));
676
677         flags_str = gpo_flag_str(NULL, flags);
678         DEBUGADD(lvl,("\tflags:         0x%08x %s\n", flags, flags_str));
679         TALLOC_FREE(flags_str);
680 }
681
682 /****************************************************************
683 ****************************************************************/
684
685 static NTSTATUS gpext_check_gpo_for_gpext_presence(TALLOC_CTX *mem_ctx,
686                                                    uint32_t flags,
687                                                    const struct GROUP_POLICY_OBJECT *gpo,
688                                                    const struct GUID *guid,
689                                                    bool *gpext_guid_present)
690 {
691         struct GP_EXT *gp_ext = NULL;
692         int i;
693         bool ok;
694
695         *gpext_guid_present = false;
696
697
698         if (gpo->link_type == GP_LINK_LOCAL) {
699                 return NT_STATUS_OK;
700         }
701
702         ok = gpo_get_gp_ext_from_gpo(mem_ctx, flags, gpo, &gp_ext);
703         if (!ok) {
704                 return NT_STATUS_INVALID_PARAMETER;
705         }
706
707         if (gp_ext == NULL) {
708                 return NT_STATUS_OK;
709         }
710
711         for (i = 0; i < gp_ext->num_exts; i++) {
712                 struct GUID guid2;
713                 NTSTATUS status;
714
715                 status = GUID_from_string(gp_ext->extensions_guid[i], &guid2);
716                 if (!NT_STATUS_IS_OK(status)) {
717                         return status;
718                 }
719                 if (GUID_equal(guid, &guid2)) {
720                         *gpext_guid_present = true;
721                         return NT_STATUS_OK;
722                 }
723         }
724
725         return NT_STATUS_OK;
726 }
727
728 /****************************************************************
729 ****************************************************************/
730
731 NTSTATUS gpext_process_extension(TALLOC_CTX *mem_ctx,
732                                  uint32_t flags,
733                                  const struct security_token *token,
734                                  struct registry_key *root_key,
735                                  const struct GROUP_POLICY_OBJECT *deleted_gpo_list,
736                                  const struct GROUP_POLICY_OBJECT *changed_gpo_list,
737                                  const char *extension_guid_filter)
738 {
739         NTSTATUS status;
740         struct gp_extension *ext = NULL;
741         const struct GROUP_POLICY_OBJECT *gpo;
742         struct GUID extension_guid_filter_guid;
743
744         status = gpext_init_gp_extensions(mem_ctx);
745         if (!NT_STATUS_IS_OK(status)) {
746                 DEBUG(1,("gpext_init_gp_extensions failed: %s\n",
747                         nt_errstr(status)));
748                 return status;
749         }
750
751         if (extension_guid_filter) {
752                 status = GUID_from_string(extension_guid_filter,
753                                           &extension_guid_filter_guid);
754                 if (!NT_STATUS_IS_OK(status)) {
755                         return status;
756                 }
757         }
758
759         for (ext = extensions; ext; ext = ext->next) {
760
761                 struct GROUP_POLICY_OBJECT *deleted_gpo_list_filtered = NULL;
762                 struct GROUP_POLICY_OBJECT *changed_gpo_list_filtered = NULL;
763
764                 if (extension_guid_filter) {
765                         if (!GUID_equal(&extension_guid_filter_guid, ext->guid)) {
766                                 continue;
767                         }
768                 }
769
770                 for (gpo = deleted_gpo_list; gpo; gpo = gpo->next) {
771
772                         bool is_present = false;
773
774                         status = gpext_check_gpo_for_gpext_presence(mem_ctx,
775                                                                     flags,
776                                                                     gpo,
777                                                                     ext->guid,
778                                                                     &is_present);
779                         if (!NT_STATUS_IS_OK(status)) {
780                                 return status;
781                         }
782
783                         if (is_present) {
784                                 struct GROUP_POLICY_OBJECT *new_gpo;
785
786                                 status = gpo_copy(mem_ctx, gpo, &new_gpo);
787                                 if (!NT_STATUS_IS_OK(status)) {
788                                         return status;
789                                 }
790
791                                 DLIST_ADD(deleted_gpo_list_filtered, new_gpo);
792                         }
793                 }
794
795                 for (gpo = changed_gpo_list; gpo; gpo = gpo->next) {
796
797                         bool is_present = false;
798
799                         status = gpext_check_gpo_for_gpext_presence(mem_ctx,
800                                                                     flags,
801                                                                     gpo,
802                                                                     ext->guid,
803                                                                     &is_present);
804                         if (!NT_STATUS_IS_OK(status)) {
805                                 return status;
806                         }
807
808                         if (is_present) {
809                                 struct GROUP_POLICY_OBJECT *new_gpo;
810
811                                 status = gpo_copy(mem_ctx, gpo, &new_gpo);
812                                 if (!NT_STATUS_IS_OK(status)) {
813                                         return status;
814                                 }
815
816                                 DLIST_ADD(changed_gpo_list_filtered, new_gpo);
817                         }
818                 }
819
820                 status = ext->methods->initialize(mem_ctx);
821                 NT_STATUS_NOT_OK_RETURN(status);
822
823                 status = ext->methods->process_group_policy(mem_ctx,
824                                                             flags,
825                                                             root_key,
826                                                             token,
827                                                             deleted_gpo_list_filtered,
828                                                             changed_gpo_list_filtered);
829                 if (!NT_STATUS_IS_OK(status)) {
830                         ext->methods->shutdown();
831                 }
832         }
833
834         return status;
835 }