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