Fix a bunch of compiler warnings about wrong format types.
[Samba/gbeck.git] / libgpo / gpo_util.c
blob7a23b5cbd37c6ea33024df4ee581779ca0de416e
1 /*
2 * Unix SMB/CIFS implementation.
3 * Group Policy Object Support
4 * Copyright (C) Guenther Deschner 2005-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/>.
19 #define TALLOC_DEPRECATED 1
20 #include "includes.h"
21 #include "librpc/gen_ndr/ndr_misc.h"
22 #if _SAMBA_BUILD_ == 4
23 #include "system/filesys.h"
24 #include "auth/auth.h"
25 #include "../libgpo/gpo.h"
26 #include "../lib/talloc/talloc.h"
27 #include "source4/libgpo/ads_convenience.h"
28 #endif
29 #undef strdup
31 #if 0
32 #define DEFAULT_DOMAIN_POLICY "Default Domain Policy"
33 #define DEFAULT_DOMAIN_CONTROLLERS_POLICY "Default Domain Controllers Policy"
34 #endif
36 /* should we store a parsed guid ? */
37 struct gp_table {
38 const char *name;
39 const char *guid_string;
42 #if 0 /* unused */
43 static struct gp_table gpo_default_policy[] = {
44 { DEFAULT_DOMAIN_POLICY,
45 "31B2F340-016D-11D2-945F-00C04FB984F9" },
46 { DEFAULT_DOMAIN_CONTROLLERS_POLICY,
47 "6AC1786C-016F-11D2-945F-00C04fB984F9" },
48 { NULL, NULL }
50 #endif
52 /* the following is seen in gPCMachineExtensionNames / gPCUserExtensionNames */
54 static struct gp_table gpo_cse_extensions[] = {
55 /* used to be "Administrative Templates Extension" */
56 /* "Registry Settings"
57 (http://support.microsoft.com/kb/216357/EN-US/) */
58 { "Registry Settings",
59 GP_EXT_GUID_REGISTRY },
60 { "Microsoft Disc Quota",
61 "3610EDA5-77EF-11D2-8DC5-00C04FA31A66" },
62 { "EFS recovery",
63 "B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A" },
64 { "Folder Redirection",
65 "25537BA6-77A8-11D2-9B6C-0000F8080861" },
66 { "IP Security",
67 "E437BC1C-AA7D-11D2-A382-00C04F991E27" },
68 { "Internet Explorer Branding",
69 "A2E30F80-D7DE-11d2-BBDE-00C04F86AE3B" },
70 { "QoS Packet Scheduler",
71 "426031c0-0b47-4852-b0ca-ac3d37bfcb39" },
72 { "Scripts",
73 GP_EXT_GUID_SCRIPTS },
74 { "Security",
75 GP_EXT_GUID_SECURITY },
76 { "Software Installation",
77 "C6DC5466-785A-11D2-84D0-00C04FB169F7" },
78 { "Wireless Group Policy",
79 "0ACDD40C-75AC-BAA0-BF6DE7E7FE63" },
80 { "Application Management",
81 "C6DC5466-785A-11D2-84D0-00C04FB169F7" },
82 { "unknown",
83 "3060E8D0-7020-11D2-842D-00C04FA372D4" },
84 { NULL, NULL }
87 /* guess work */
88 static struct gp_table gpo_cse_snapin_extensions[] = {
89 { "Administrative Templates",
90 "0F6B957D-509E-11D1-A7CC-0000F87571E3" },
91 { "Certificates",
92 "53D6AB1D-2488-11D1-A28C-00C04FB94F17" },
93 { "EFS recovery policy processing",
94 "B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A" },
95 { "Folder Redirection policy processing",
96 "25537BA6-77A8-11D2-9B6C-0000F8080861" },
97 { "Folder Redirection",
98 "88E729D6-BDC1-11D1-BD2A-00C04FB9603F" },
99 { "Registry policy processing",
100 "35378EAC-683F-11D2-A89A-00C04FBBCFA2" },
101 { "Remote Installation Services",
102 "3060E8CE-7020-11D2-842D-00C04FA372D4" },
103 { "Security Settings",
104 "803E14A0-B4FB-11D0-A0D0-00A0C90F574B" },
105 { "Security policy processing",
106 "827D319E-6EAC-11D2-A4EA-00C04F79F83A" },
107 { "unknown",
108 "3060E8D0-7020-11D2-842D-00C04FA372D4" },
109 { "unknown2",
110 "53D6AB1B-2488-11D1-A28C-00C04FB94F17" },
111 { NULL, NULL }
114 /****************************************************************
115 ****************************************************************/
117 static const char *name_to_guid_string(const char *name,
118 struct gp_table *table)
120 int i;
122 for (i = 0; table[i].name; i++) {
123 if (strequal(name, table[i].name)) {
124 return table[i].guid_string;
128 return NULL;
131 /****************************************************************
132 ****************************************************************/
134 static const char *guid_string_to_name(const char *guid_string,
135 struct gp_table *table)
137 int i;
139 for (i = 0; table[i].guid_string; i++) {
140 if (strequal(guid_string, table[i].guid_string)) {
141 return table[i].name;
145 return NULL;
148 /****************************************************************
149 ****************************************************************/
151 static const char *snapin_guid_string_to_name(const char *guid_string,
152 struct gp_table *table)
154 int i;
155 for (i = 0; table[i].guid_string; i++) {
156 if (strequal(guid_string, table[i].guid_string)) {
157 return table[i].name;
160 return NULL;
163 #if 0 /* unused */
164 static const char *default_gpo_name_to_guid_string(const char *name)
166 return name_to_guid_string(name, gpo_default_policy);
169 static const char *default_gpo_guid_string_to_name(const char *guid)
171 return guid_string_to_name(guid, gpo_default_policy);
173 #endif
175 /****************************************************************
176 ****************************************************************/
178 const char *cse_gpo_guid_string_to_name(const char *guid)
180 return guid_string_to_name(guid, gpo_cse_extensions);
183 /****************************************************************
184 ****************************************************************/
186 const char *cse_gpo_name_to_guid_string(const char *name)
188 return name_to_guid_string(name, gpo_cse_extensions);
191 /****************************************************************
192 ****************************************************************/
194 const char *cse_snapin_gpo_guid_string_to_name(const char *guid)
196 return snapin_guid_string_to_name(guid, gpo_cse_snapin_extensions);
199 /****************************************************************
200 ****************************************************************/
202 void dump_gp_ext(struct GP_EXT *gp_ext, int debuglevel)
204 int lvl = debuglevel;
205 int i;
207 if (gp_ext == NULL) {
208 return;
211 DEBUG(lvl,("\t---------------------\n\n"));
212 DEBUGADD(lvl,("\tname:\t\t\t%s\n", gp_ext->gp_extension));
214 for (i=0; i< gp_ext->num_exts; i++) {
216 DEBUGADD(lvl,("\textension:\t\t\t%s\n",
217 gp_ext->extensions_guid[i]));
218 DEBUGADD(lvl,("\textension (name):\t\t\t%s\n",
219 gp_ext->extensions[i]));
221 DEBUGADD(lvl,("\tsnapin:\t\t\t%s\n",
222 gp_ext->snapins_guid[i]));
223 DEBUGADD(lvl,("\tsnapin (name):\t\t\t%s\n",
224 gp_ext->snapins[i]));
228 #ifdef HAVE_LDAP
230 /****************************************************************
231 ****************************************************************/
233 void dump_gpo(ADS_STRUCT *ads,
234 TALLOC_CTX *mem_ctx,
235 struct GROUP_POLICY_OBJECT *gpo,
236 int debuglevel)
238 int lvl = debuglevel;
240 if (gpo == NULL) {
241 return;
244 DEBUG(lvl,("---------------------\n\n"));
246 DEBUGADD(lvl,("name:\t\t\t%s\n", gpo->name));
247 DEBUGADD(lvl,("displayname:\t\t%s\n", gpo->display_name));
248 DEBUGADD(lvl,("version:\t\t%d (0x%08x)\n", gpo->version, gpo->version));
249 DEBUGADD(lvl,("version_user:\t\t%d (0x%04x)\n",
250 GPO_VERSION_USER(gpo->version),
251 GPO_VERSION_USER(gpo->version)));
252 DEBUGADD(lvl,("version_machine:\t%d (0x%04x)\n",
253 GPO_VERSION_MACHINE(gpo->version),
254 GPO_VERSION_MACHINE(gpo->version)));
255 DEBUGADD(lvl,("filesyspath:\t\t%s\n", gpo->file_sys_path));
256 DEBUGADD(lvl,("dspath:\t\t%s\n", gpo->ds_path));
258 DEBUGADD(lvl,("options:\t\t%d ", gpo->options));
259 switch (gpo->options) {
260 case GPFLAGS_ALL_ENABLED:
261 DEBUGADD(lvl,("GPFLAGS_ALL_ENABLED\n"));
262 break;
263 case GPFLAGS_USER_SETTINGS_DISABLED:
264 DEBUGADD(lvl,("GPFLAGS_USER_SETTINGS_DISABLED\n"));
265 break;
266 case GPFLAGS_MACHINE_SETTINGS_DISABLED:
267 DEBUGADD(lvl,("GPFLAGS_MACHINE_SETTINGS_DISABLED\n"));
268 break;
269 case GPFLAGS_ALL_DISABLED:
270 DEBUGADD(lvl,("GPFLAGS_ALL_DISABLED\n"));
271 break;
272 default:
273 DEBUGADD(lvl,("unknown option: %d\n", gpo->options));
274 break;
277 DEBUGADD(lvl,("link:\t\t\t%s\n", gpo->link));
278 DEBUGADD(lvl,("link_type:\t\t%d ", gpo->link_type));
279 switch (gpo->link_type) {
280 case GP_LINK_UNKOWN:
281 DEBUGADD(lvl,("GP_LINK_UNKOWN\n"));
282 break;
283 case GP_LINK_OU:
284 DEBUGADD(lvl,("GP_LINK_OU\n"));
285 break;
286 case GP_LINK_DOMAIN:
287 DEBUGADD(lvl,("GP_LINK_DOMAIN\n"));
288 break;
289 case GP_LINK_SITE:
290 DEBUGADD(lvl,("GP_LINK_SITE\n"));
291 break;
292 case GP_LINK_MACHINE:
293 DEBUGADD(lvl,("GP_LINK_MACHINE\n"));
294 break;
295 default:
296 break;
299 DEBUGADD(lvl,("machine_extensions:\t%s\n", gpo->machine_extensions));
301 if (gpo->machine_extensions) {
303 struct GP_EXT *gp_ext = NULL;
305 if (!ads_parse_gp_ext(mem_ctx, gpo->machine_extensions,
306 &gp_ext)) {
307 return;
309 dump_gp_ext(gp_ext, lvl);
312 DEBUGADD(lvl,("user_extensions:\t%s\n", gpo->user_extensions));
314 if (gpo->user_extensions) {
316 struct GP_EXT *gp_ext = NULL;
318 if (!ads_parse_gp_ext(mem_ctx, gpo->user_extensions,
319 &gp_ext)) {
320 return;
322 dump_gp_ext(gp_ext, lvl);
325 DEBUGADD(lvl,("security descriptor:\n"));
327 NDR_PRINT_DEBUG(security_descriptor, gpo->security_descriptor);
330 /****************************************************************
331 ****************************************************************/
333 void dump_gpo_list(ADS_STRUCT *ads,
334 TALLOC_CTX *mem_ctx,
335 struct GROUP_POLICY_OBJECT *gpo_list,
336 int debuglevel)
338 struct GROUP_POLICY_OBJECT *gpo = NULL;
340 for (gpo = gpo_list; gpo; gpo = gpo->next) {
341 dump_gpo(ads, mem_ctx, gpo, debuglevel);
345 /****************************************************************
346 ****************************************************************/
348 void dump_gplink(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GP_LINK *gp_link)
350 ADS_STATUS status;
351 int i;
352 int lvl = 10;
354 if (gp_link == NULL) {
355 return;
358 DEBUG(lvl,("---------------------\n\n"));
360 DEBUGADD(lvl,("gplink: %s\n", gp_link->gp_link));
361 DEBUGADD(lvl,("gpopts: %d ", gp_link->gp_opts));
362 switch (gp_link->gp_opts) {
363 case GPOPTIONS_INHERIT:
364 DEBUGADD(lvl,("GPOPTIONS_INHERIT\n"));
365 break;
366 case GPOPTIONS_BLOCK_INHERITANCE:
367 DEBUGADD(lvl,("GPOPTIONS_BLOCK_INHERITANCE\n"));
368 break;
369 default:
370 break;
373 DEBUGADD(lvl,("num links: %d\n", gp_link->num_links));
375 for (i = 0; i < gp_link->num_links; i++) {
377 DEBUGADD(lvl,("---------------------\n\n"));
379 DEBUGADD(lvl,("link: #%d\n", i + 1));
380 DEBUGADD(lvl,("name: %s\n", gp_link->link_names[i]));
382 DEBUGADD(lvl,("opt: %d ", gp_link->link_opts[i]));
383 if (gp_link->link_opts[i] & GPO_LINK_OPT_ENFORCED) {
384 DEBUGADD(lvl,("GPO_LINK_OPT_ENFORCED "));
386 if (gp_link->link_opts[i] & GPO_LINK_OPT_DISABLED) {
387 DEBUGADD(lvl,("GPO_LINK_OPT_DISABLED"));
389 DEBUGADD(lvl,("\n"));
391 if (ads != NULL && mem_ctx != NULL) {
393 struct GROUP_POLICY_OBJECT gpo;
395 status = ads_get_gpo(ads, mem_ctx,
396 gp_link->link_names[i],
397 NULL, NULL, &gpo);
398 if (!ADS_ERR_OK(status)) {
399 DEBUG(lvl,("get gpo for %s failed: %s\n",
400 gp_link->link_names[i],
401 ads_errstr(status)));
402 return;
404 dump_gpo(ads, mem_ctx, &gpo, lvl);
409 #endif /* HAVE_LDAP */
411 /****************************************************************
412 ****************************************************************/
414 static bool gpo_get_gp_ext_from_gpo(TALLOC_CTX *mem_ctx,
415 uint32_t flags,
416 struct GROUP_POLICY_OBJECT *gpo,
417 struct GP_EXT **gp_ext)
419 ZERO_STRUCTP(*gp_ext);
421 if (flags & GPO_INFO_FLAG_MACHINE) {
423 if (gpo->machine_extensions) {
425 if (!ads_parse_gp_ext(mem_ctx, gpo->machine_extensions,
426 gp_ext)) {
427 return false;
430 } else {
432 if (gpo->user_extensions) {
434 if (!ads_parse_gp_ext(mem_ctx, gpo->user_extensions,
435 gp_ext)) {
436 return false;
441 return true;
444 /****************************************************************
445 ****************************************************************/
447 ADS_STATUS gpo_process_a_gpo(ADS_STRUCT *ads,
448 TALLOC_CTX *mem_ctx,
449 const NT_USER_TOKEN *token,
450 struct registry_key *root_key,
451 struct GROUP_POLICY_OBJECT *gpo,
452 const char *extension_guid_filter,
453 uint32_t flags)
455 struct GP_EXT *gp_ext = NULL;
456 int i;
458 DEBUG(10,("gpo_process_a_gpo: processing gpo %s (%s)\n",
459 gpo->name, gpo->display_name));
460 if (extension_guid_filter) {
461 DEBUGADD(10,("gpo_process_a_gpo: using filter %s (%s)\n",
462 extension_guid_filter,
463 cse_gpo_guid_string_to_name(extension_guid_filter)));
466 if (!gpo_get_gp_ext_from_gpo(mem_ctx, flags, gpo, &gp_ext)) {
467 return ADS_ERROR_NT(NT_STATUS_INVALID_PARAMETER);
470 if (!gp_ext || !gp_ext->num_exts) {
471 if (flags & GPO_INFO_FLAG_VERBOSE) {
472 DEBUG(0,("gpo_process_a_gpo: "
473 "no policies in %s (%s) for this extension\n",
474 gpo->name, gpo->display_name));
476 return ADS_SUCCESS;
479 for (i=0; i<gp_ext->num_exts; i++) {
481 NTSTATUS ntstatus;
483 if (extension_guid_filter &&
484 !strequal(extension_guid_filter,
485 gp_ext->extensions_guid[i])) {
486 continue;
489 ntstatus = gpext_process_extension(ads, mem_ctx,
490 flags, token, root_key, gpo,
491 gp_ext->extensions_guid[i],
492 gp_ext->snapins_guid[i]);
493 if (!NT_STATUS_IS_OK(ntstatus)) {
494 ADS_ERROR_NT(ntstatus);
498 return ADS_SUCCESS;
501 /****************************************************************
502 ****************************************************************/
504 static ADS_STATUS gpo_process_gpo_list_by_ext(ADS_STRUCT *ads,
505 TALLOC_CTX *mem_ctx,
506 const NT_USER_TOKEN *token,
507 struct registry_key *root_key,
508 struct GROUP_POLICY_OBJECT *gpo_list,
509 const char *extensions_guid,
510 uint32_t flags)
512 ADS_STATUS status;
513 struct GROUP_POLICY_OBJECT *gpo;
515 for (gpo = gpo_list; gpo; gpo = gpo->next) {
517 if (gpo->link_type == GP_LINK_LOCAL) {
518 continue;
522 /* FIXME: we need to pass down the *list* down to the
523 * extension, otherwise we cannot store the e.g. the *list* of
524 * logon-scripts correctly (for more then one GPO) */
526 status = gpo_process_a_gpo(ads, mem_ctx, token, root_key,
527 gpo, extensions_guid, flags);
529 if (!ADS_ERR_OK(status)) {
530 DEBUG(0,("failed to process gpo by ext: %s\n",
531 ads_errstr(status)));
532 return status;
536 return ADS_SUCCESS;
539 /****************************************************************
540 ****************************************************************/
542 ADS_STATUS gpo_process_gpo_list(ADS_STRUCT *ads,
543 TALLOC_CTX *mem_ctx,
544 const NT_USER_TOKEN *token,
545 struct GROUP_POLICY_OBJECT *gpo_list,
546 const char *extensions_guid_filter,
547 uint32_t flags)
549 ADS_STATUS status = ADS_SUCCESS;
550 struct gp_extension *gp_ext_list = NULL;
551 struct gp_extension *gp_ext = NULL;
552 struct registry_key *root_key = NULL;
553 struct gp_registry_context *reg_ctx = NULL;
554 #if 0
555 WERROR werr;
556 #endif
557 status = ADS_ERROR_NT(init_gp_extensions(mem_ctx));
558 if (!ADS_ERR_OK(status)) {
559 return status;
562 gp_ext_list = get_gp_extension_list();
563 if (!gp_ext_list) {
564 return ADS_ERROR_NT(NT_STATUS_DLL_INIT_FAILED);
566 /* FIXME Needs to be replaced with new patchfile_preg calls */
567 #if 0
568 /* get the key here */
569 if (flags & GPO_LIST_FLAG_MACHINE) {
570 werr = gp_init_reg_ctx(mem_ctx, KEY_HKLM, REG_KEY_WRITE,
571 get_system_token(),
572 &reg_ctx);
573 } else {
574 werr = gp_init_reg_ctx(mem_ctx, KEY_HKCU, REG_KEY_WRITE,
575 token,
576 &reg_ctx);
578 if (!W_ERROR_IS_OK(werr)) {
579 talloc_free(reg_ctx);
580 return ADS_ERROR_NT(werror_to_ntstatus(werr));
582 #endif
584 root_key = reg_ctx->curr_key;
586 for (gp_ext = gp_ext_list; gp_ext; gp_ext = gp_ext->next) {
588 const char *guid_str = NULL;
590 guid_str = GUID_string(mem_ctx, gp_ext->guid);
591 if (!guid_str) {
592 status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
593 goto done;
596 if (extensions_guid_filter &&
597 (!strequal(guid_str, extensions_guid_filter))) {
598 continue;
601 DEBUG(0,("-------------------------------------------------\n"));
602 DEBUG(0,("gpo_process_gpo_list: processing ext: %s {%s}\n",
603 gp_ext->name, guid_str));
606 status = gpo_process_gpo_list_by_ext(ads, mem_ctx, token,
607 root_key, gpo_list,
608 guid_str, flags);
609 if (!ADS_ERR_OK(status)) {
610 goto done;
614 done:
615 talloc_free(reg_ctx);
616 talloc_free(root_key);
617 free_gp_extensions();
619 return status;
623 /****************************************************************
624 check wether the version number in a GROUP_POLICY_OBJECT match those of the
625 locally stored version. If not, fetch the required policy via CIFS
626 ****************************************************************/
628 NTSTATUS check_refresh_gpo(ADS_STRUCT *ads,
629 TALLOC_CTX *mem_ctx,
630 const char *cache_dir,
631 struct loadparm_context *lp_ctx,
632 uint32_t flags,
633 struct GROUP_POLICY_OBJECT *gpo)
635 NTSTATUS result;
636 char *server = NULL;
637 char *share = NULL;
638 char *nt_path = NULL;
639 char *unix_path = NULL;
640 uint32_t sysvol_gpt_version = 0;
641 char *display_name = NULL;
643 result = gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
644 &server, &share, &nt_path, &unix_path);
646 if (!NT_STATUS_IS_OK(result)) {
647 goto out;
650 result = gpo_get_sysvol_gpt_version(mem_ctx,
651 unix_path,
652 &sysvol_gpt_version,
653 &display_name);
654 if (!NT_STATUS_IS_OK(result) &&
655 !NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_FILE)) {
656 DEBUG(10,("check_refresh_gpo: "
657 "failed to get local gpt version: %s\n",
658 nt_errstr(result)));
659 goto out;
662 DEBUG(10,("check_refresh_gpo: versions gpo %d sysvol %d\n",
663 gpo->version, sysvol_gpt_version));
665 /* FIXME: handle GPO_INFO_FLAG_FORCED_REFRESH from flags */
667 while (gpo->version > sysvol_gpt_version) {
669 DEBUG(1,("check_refresh_gpo: need to refresh GPO\n"));
671 result = gpo_fetch_files(mem_ctx, ads, lp_ctx, cache_dir, gpo);
672 if (!NT_STATUS_IS_OK(result)) {
673 goto out;
676 result = gpo_get_sysvol_gpt_version(mem_ctx,
677 unix_path,
678 &sysvol_gpt_version,
679 &display_name);
680 if (!NT_STATUS_IS_OK(result)) {
681 DEBUG(10,("check_refresh_gpo: "
682 "failed to get local gpt version: %s\n",
683 nt_errstr(result)));
684 goto out;
687 if (gpo->version == sysvol_gpt_version) {
688 break;
692 DEBUG(10,("Name:\t\t\t%s (%s)\n", gpo->display_name, gpo->name));
693 DEBUGADD(10,("sysvol GPT version:\t%d (user: %d, machine: %d)\n",
694 sysvol_gpt_version,
695 GPO_VERSION_USER(sysvol_gpt_version),
696 GPO_VERSION_MACHINE(sysvol_gpt_version)));
697 DEBUGADD(10,("LDAP GPO version:\t%d (user: %d, machine: %d)\n",
698 gpo->version,
699 GPO_VERSION_USER(gpo->version),
700 GPO_VERSION_MACHINE(gpo->version)));
701 DEBUGADD(10,("LDAP GPO link:\t\t%s\n", gpo->link));
703 result = NT_STATUS_OK;
705 out:
706 return result;
710 /****************************************************************
711 check wether the version numbers in the gpo_list match the locally stored, if
712 not, go and get each required GPO via CIFS
713 ****************************************************************/
715 NTSTATUS check_refresh_gpo_list(ADS_STRUCT *ads,
716 TALLOC_CTX *mem_ctx,
717 const char *cache_dir,
718 struct loadparm_context *lp_ctx,
719 uint32_t flags,
720 struct GROUP_POLICY_OBJECT *gpo_list)
722 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
723 struct GROUP_POLICY_OBJECT *gpo;
725 if (!gpo_list) {
726 return NT_STATUS_INVALID_PARAMETER;
729 for (gpo = gpo_list; gpo; gpo = gpo->next) {
731 result = check_refresh_gpo(ads, mem_ctx, cache_dir, lp_ctx, flags, gpo);
732 if (!NT_STATUS_IS_OK(result)) {
733 goto out;
737 result = NT_STATUS_OK;
739 out:
740 /* FIXME close cli connection */
742 return result;
745 /****************************************************************
746 ****************************************************************/
748 NTSTATUS gpo_get_unix_path(TALLOC_CTX *mem_ctx,
749 const char *cache_dir,
750 struct GROUP_POLICY_OBJECT *gpo,
751 char **unix_path)
753 char *server, *share, *nt_path;
754 return gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
755 &server, &share, &nt_path, unix_path);
758 /****************************************************************
759 ****************************************************************/
761 char *gpo_flag_str(TALLOC_CTX *ctx, uint32_t flags)
763 char *str = NULL;
765 if (flags == 0) {
766 return NULL;
769 if (flags & GPO_INFO_FLAG_SLOWLINK)
770 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_SLOWLINK ");
771 if (flags & GPO_INFO_FLAG_VERBOSE)
772 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_VERBOSE ");
773 if (flags & GPO_INFO_FLAG_SAFEMODE_BOOT)
774 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_SAFEMODE_BOOT ");
775 if (flags & GPO_INFO_FLAG_NOCHANGES)
776 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_NOCHANGES ");
777 if (flags & GPO_INFO_FLAG_MACHINE)
778 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_MACHINE ");
779 if (flags & GPO_INFO_FLAG_LOGRSOP_TRANSITION)
780 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_LOGRSOP_TRANSITION ");
781 if (flags & GPO_INFO_FLAG_LINKTRANSITION)
782 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_LINKTRANSITION ");
783 if (flags & GPO_INFO_FLAG_FORCED_REFRESH)
784 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_FORCED_REFRESH ");
785 if (flags & GPO_INFO_FLAG_BACKGROUND)
786 str = talloc_append_string(ctx, str, "GPO_INFO_FLAG_BACKGROUND ");
788 return str;
791 /****************************************************************
792 ****************************************************************/
794 NTSTATUS gp_find_file(TALLOC_CTX *mem_ctx,
795 uint32_t flags,
796 const char *filename,
797 const char *suffix,
798 const char **filename_out)
800 const char *tmp = NULL;
801 struct stat sbuf;
802 const char *path = NULL;
804 if (flags & GPO_LIST_FLAG_MACHINE) {
805 path = "Machine";
806 } else {
807 path = "User";
810 tmp = talloc_asprintf(mem_ctx, "%s/%s/%s", filename,
811 path, suffix);
812 NT_STATUS_HAVE_NO_MEMORY(tmp);
814 if (stat(tmp, &sbuf) == 0) {
815 *filename_out = tmp;
816 return NT_STATUS_OK;
819 path = talloc_strdup_upper(mem_ctx, path);
820 NT_STATUS_HAVE_NO_MEMORY(path);
822 tmp = talloc_asprintf(mem_ctx, "%s/%s/%s", filename,
823 path, suffix);
824 NT_STATUS_HAVE_NO_MEMORY(tmp);
826 if (stat(tmp, &sbuf) == 0) {
827 *filename_out = tmp;
828 return NT_STATUS_OK;
831 return NT_STATUS_NO_SUCH_FILE;
834 /****************************************************************
835 ****************************************************************/
837 ADS_STATUS gp_get_machine_token(ADS_STRUCT *ads,
838 TALLOC_CTX *mem_ctx,
839 struct loadparm_context *lp_ctx,
840 const char *dn,
841 NT_USER_TOKEN **token)
843 NT_USER_TOKEN *ad_token = NULL;
844 ADS_STATUS status;
845 #if _SAMBA_BUILD_ == 4
846 struct auth_session_info *info;
847 #else
848 NTSTATUS ntstatus;
849 #endif
851 #ifndef HAVE_ADS
852 return ADS_ERROR_NT(NT_STATUS_NOT_SUPPORTED);
853 #endif
854 status = ads_get_sid_token(ads, mem_ctx, dn, &ad_token);
855 if (!ADS_ERR_OK(status)) {
856 return status;
858 #if _SAMBA_BUILD_ == 4
859 info = system_session(mem_ctx, lp_ctx);
860 *token = info->security_token;
861 #else
862 ntstatus = merge_nt_token(mem_ctx, ad_token, get_system_token(),
863 token);
864 if (!NT_STATUS_IS_OK(ntstatus)) {
865 return ADS_ERROR_NT(ntstatus);
867 #endif
868 return ADS_SUCCESS;