libgpo: remove some unnecessary usage of ADS_STATUS.
[Samba.git] / libgpo / gpo_util.c
blob7378cfcd6e689e54bb701c79a1db4670253239d4
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/>.
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "librpc/gen_ndr/ndr_misc.h"
23 #include "../librpc/gen_ndr/ndr_security.h"
24 #include "../libgpo/gpo.h"
25 #include "../libcli/security/security.h"
26 #include "registry.h"
27 #include "libgpo/gpo_proto.h"
29 #if 0
30 #define DEFAULT_DOMAIN_POLICY "Default Domain Policy"
31 #define DEFAULT_DOMAIN_CONTROLLERS_POLICY "Default Domain Controllers Policy"
32 #endif
34 /* should we store a parsed guid ? */
35 struct gp_table {
36 const char *name;
37 const char *guid_string;
40 #if 0 /* unused */
41 static struct gp_table gpo_default_policy[] = {
42 { DEFAULT_DOMAIN_POLICY,
43 "31B2F340-016D-11D2-945F-00C04FB984F9" },
44 { DEFAULT_DOMAIN_CONTROLLERS_POLICY,
45 "6AC1786C-016F-11D2-945F-00C04fB984F9" },
46 { NULL, NULL }
48 #endif
50 /* the following is seen in gPCMachineExtensionNames / gPCUserExtensionNames */
52 static struct gp_table gpo_cse_extensions[] = {
53 /* used to be "Administrative Templates Extension" */
54 /* "Registry Settings"
55 (http://support.microsoft.com/kb/216357/EN-US/) */
56 { "Registry Settings",
57 GP_EXT_GUID_REGISTRY },
58 { "Microsoft Disc Quota",
59 "3610EDA5-77EF-11D2-8DC5-00C04FA31A66" },
60 { "EFS recovery",
61 "B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A" },
62 { "Folder Redirection",
63 "25537BA6-77A8-11D2-9B6C-0000F8080861" },
64 { "IP Security",
65 "E437BC1C-AA7D-11D2-A382-00C04F991E27" },
66 { "Internet Explorer Branding",
67 "A2E30F80-D7DE-11d2-BBDE-00C04F86AE3B" },
68 { "QoS Packet Scheduler",
69 "426031c0-0b47-4852-b0ca-ac3d37bfcb39" },
70 { "Scripts",
71 GP_EXT_GUID_SCRIPTS },
72 { "Security",
73 GP_EXT_GUID_SECURITY },
74 { "Software Installation",
75 "C6DC5466-785A-11D2-84D0-00C04FB169F7" },
76 { "Wireless Group Policy",
77 "0ACDD40C-75AC-BAA0-BF6DE7E7FE63" },
78 { "Application Management",
79 "C6DC5466-785A-11D2-84D0-00C04FB169F7" },
80 { "unknown",
81 "3060E8D0-7020-11D2-842D-00C04FA372D4" },
82 { NULL, NULL }
85 /* guess work */
86 static struct gp_table gpo_cse_snapin_extensions[] = {
87 { "Administrative Templates",
88 "0F6B957D-509E-11D1-A7CC-0000F87571E3" },
89 { "Certificates",
90 "53D6AB1D-2488-11D1-A28C-00C04FB94F17" },
91 { "EFS recovery policy processing",
92 "B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A" },
93 { "Folder Redirection policy processing",
94 "25537BA6-77A8-11D2-9B6C-0000F8080861" },
95 { "Folder Redirection",
96 "88E729D6-BDC1-11D1-BD2A-00C04FB9603F" },
97 { "Registry policy processing",
98 "35378EAC-683F-11D2-A89A-00C04FBBCFA2" },
99 { "Remote Installation Services",
100 "3060E8CE-7020-11D2-842D-00C04FA372D4" },
101 { "Security Settings",
102 "803E14A0-B4FB-11D0-A0D0-00A0C90F574B" },
103 { "Security policy processing",
104 "827D319E-6EAC-11D2-A4EA-00C04F79F83A" },
105 { "unknown",
106 "3060E8D0-7020-11D2-842D-00C04FA372D4" },
107 { "unknown2",
108 "53D6AB1B-2488-11D1-A28C-00C04FB94F17" },
109 { NULL, NULL }
112 /****************************************************************
113 ****************************************************************/
115 static const char *name_to_guid_string(const char *name,
116 struct gp_table *table)
118 int i;
120 for (i = 0; table[i].name; i++) {
121 if (strequal(name, table[i].name)) {
122 return table[i].guid_string;
126 return NULL;
129 /****************************************************************
130 ****************************************************************/
132 static const char *guid_string_to_name(const char *guid_string,
133 struct gp_table *table)
135 int i;
137 for (i = 0; table[i].guid_string; i++) {
138 if (strequal(guid_string, table[i].guid_string)) {
139 return table[i].name;
143 return NULL;
146 /****************************************************************
147 ****************************************************************/
149 static const char *snapin_guid_string_to_name(const char *guid_string,
150 struct gp_table *table)
152 int i;
153 for (i = 0; table[i].guid_string; i++) {
154 if (strequal(guid_string, table[i].guid_string)) {
155 return table[i].name;
158 return NULL;
161 #if 0 /* unused */
162 static const char *default_gpo_name_to_guid_string(const char *name)
164 return name_to_guid_string(name, gpo_default_policy);
167 static const char *default_gpo_guid_string_to_name(const char *guid)
169 return guid_string_to_name(guid, gpo_default_policy);
171 #endif
173 /****************************************************************
174 ****************************************************************/
176 const char *cse_gpo_guid_string_to_name(const char *guid)
178 return guid_string_to_name(guid, gpo_cse_extensions);
181 /****************************************************************
182 ****************************************************************/
184 const char *cse_gpo_name_to_guid_string(const char *name)
186 return name_to_guid_string(name, gpo_cse_extensions);
189 /****************************************************************
190 ****************************************************************/
192 const char *cse_snapin_gpo_guid_string_to_name(const char *guid)
194 return snapin_guid_string_to_name(guid, gpo_cse_snapin_extensions);
197 /****************************************************************
198 ****************************************************************/
200 void dump_gp_ext(struct GP_EXT *gp_ext, int debuglevel)
202 int lvl = debuglevel;
203 int i;
205 if (gp_ext == NULL) {
206 return;
209 DEBUG(lvl,("\t---------------------\n\n"));
210 DEBUGADD(lvl,("\tname:\t\t\t%s\n", gp_ext->gp_extension));
212 for (i=0; i< gp_ext->num_exts; i++) {
214 DEBUGADD(lvl,("\textension:\t\t\t%s\n",
215 gp_ext->extensions_guid[i]));
216 DEBUGADD(lvl,("\textension (name):\t\t\t%s\n",
217 gp_ext->extensions[i]));
219 DEBUGADD(lvl,("\tsnapin:\t\t\t%s\n",
220 gp_ext->snapins_guid[i]));
221 DEBUGADD(lvl,("\tsnapin (name):\t\t\t%s\n",
222 gp_ext->snapins[i]));
226 #ifdef HAVE_LDAP
228 /****************************************************************
229 ****************************************************************/
231 void dump_gpo(ADS_STRUCT *ads,
232 TALLOC_CTX *mem_ctx,
233 struct GROUP_POLICY_OBJECT *gpo,
234 int debuglevel)
236 int lvl = debuglevel;
238 if (gpo == NULL) {
239 return;
242 DEBUG(lvl,("---------------------\n\n"));
244 DEBUGADD(lvl,("name:\t\t\t%s\n", gpo->name));
245 DEBUGADD(lvl,("displayname:\t\t%s\n", gpo->display_name));
246 DEBUGADD(lvl,("version:\t\t%d (0x%08x)\n", gpo->version, gpo->version));
247 DEBUGADD(lvl,("version_user:\t\t%d (0x%04x)\n",
248 GPO_VERSION_USER(gpo->version),
249 GPO_VERSION_USER(gpo->version)));
250 DEBUGADD(lvl,("version_machine:\t%d (0x%04x)\n",
251 GPO_VERSION_MACHINE(gpo->version),
252 GPO_VERSION_MACHINE(gpo->version)));
253 DEBUGADD(lvl,("filesyspath:\t\t%s\n", gpo->file_sys_path));
254 DEBUGADD(lvl,("dspath:\t\t%s\n", gpo->ds_path));
256 DEBUGADD(lvl,("options:\t\t%d ", gpo->options));
257 switch (gpo->options) {
258 case GPFLAGS_ALL_ENABLED:
259 DEBUGADD(lvl,("GPFLAGS_ALL_ENABLED\n"));
260 break;
261 case GPFLAGS_USER_SETTINGS_DISABLED:
262 DEBUGADD(lvl,("GPFLAGS_USER_SETTINGS_DISABLED\n"));
263 break;
264 case GPFLAGS_MACHINE_SETTINGS_DISABLED:
265 DEBUGADD(lvl,("GPFLAGS_MACHINE_SETTINGS_DISABLED\n"));
266 break;
267 case GPFLAGS_ALL_DISABLED:
268 DEBUGADD(lvl,("GPFLAGS_ALL_DISABLED\n"));
269 break;
270 default:
271 DEBUGADD(lvl,("unknown option: %d\n", gpo->options));
272 break;
275 DEBUGADD(lvl,("link:\t\t\t%s\n", gpo->link));
276 DEBUGADD(lvl,("link_type:\t\t%d ", gpo->link_type));
277 switch (gpo->link_type) {
278 case GP_LINK_UNKOWN:
279 DEBUGADD(lvl,("GP_LINK_UNKOWN\n"));
280 break;
281 case GP_LINK_OU:
282 DEBUGADD(lvl,("GP_LINK_OU\n"));
283 break;
284 case GP_LINK_DOMAIN:
285 DEBUGADD(lvl,("GP_LINK_DOMAIN\n"));
286 break;
287 case GP_LINK_SITE:
288 DEBUGADD(lvl,("GP_LINK_SITE\n"));
289 break;
290 case GP_LINK_MACHINE:
291 DEBUGADD(lvl,("GP_LINK_MACHINE\n"));
292 break;
293 default:
294 break;
297 DEBUGADD(lvl,("machine_extensions:\t%s\n", gpo->machine_extensions));
299 if (gpo->machine_extensions) {
301 struct GP_EXT *gp_ext = NULL;
303 if (!ads_parse_gp_ext(mem_ctx, gpo->machine_extensions,
304 &gp_ext)) {
305 return;
307 dump_gp_ext(gp_ext, lvl);
310 DEBUGADD(lvl,("user_extensions:\t%s\n", gpo->user_extensions));
312 if (gpo->user_extensions) {
314 struct GP_EXT *gp_ext = NULL;
316 if (!ads_parse_gp_ext(mem_ctx, gpo->user_extensions,
317 &gp_ext)) {
318 return;
320 dump_gp_ext(gp_ext, lvl);
322 if (gpo->security_descriptor) {
323 DEBUGADD(lvl,("security descriptor:\n"));
325 NDR_PRINT_DEBUG(security_descriptor, gpo->security_descriptor);
329 /****************************************************************
330 ****************************************************************/
332 void dump_gpo_list(ADS_STRUCT *ads,
333 TALLOC_CTX *mem_ctx,
334 struct GROUP_POLICY_OBJECT *gpo_list,
335 int debuglevel)
337 struct GROUP_POLICY_OBJECT *gpo = NULL;
339 for (gpo = gpo_list; gpo; gpo = gpo->next) {
340 dump_gpo(ads, mem_ctx, gpo, debuglevel);
344 /****************************************************************
345 ****************************************************************/
347 void dump_gplink(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GP_LINK *gp_link)
349 ADS_STATUS status;
350 int i;
351 int lvl = 10;
353 if (gp_link == NULL) {
354 return;
357 DEBUG(lvl,("---------------------\n\n"));
359 DEBUGADD(lvl,("gplink: %s\n", gp_link->gp_link));
360 DEBUGADD(lvl,("gpopts: %d ", gp_link->gp_opts));
361 switch (gp_link->gp_opts) {
362 case GPOPTIONS_INHERIT:
363 DEBUGADD(lvl,("GPOPTIONS_INHERIT\n"));
364 break;
365 case GPOPTIONS_BLOCK_INHERITANCE:
366 DEBUGADD(lvl,("GPOPTIONS_BLOCK_INHERITANCE\n"));
367 break;
368 default:
369 break;
372 DEBUGADD(lvl,("num links: %d\n", gp_link->num_links));
374 for (i = 0; i < gp_link->num_links; i++) {
376 DEBUGADD(lvl,("---------------------\n\n"));
378 DEBUGADD(lvl,("link: #%d\n", i + 1));
379 DEBUGADD(lvl,("name: %s\n", gp_link->link_names[i]));
381 DEBUGADD(lvl,("opt: %d ", gp_link->link_opts[i]));
382 if (gp_link->link_opts[i] & GPO_LINK_OPT_ENFORCED) {
383 DEBUGADD(lvl,("GPO_LINK_OPT_ENFORCED "));
385 if (gp_link->link_opts[i] & GPO_LINK_OPT_DISABLED) {
386 DEBUGADD(lvl,("GPO_LINK_OPT_DISABLED"));
388 DEBUGADD(lvl,("\n"));
390 if (ads != NULL && mem_ctx != NULL) {
392 struct GROUP_POLICY_OBJECT gpo;
394 status = ads_get_gpo(ads, mem_ctx,
395 gp_link->link_names[i],
396 NULL, NULL, &gpo);
397 if (!ADS_ERR_OK(status)) {
398 DEBUG(lvl,("get gpo for %s failed: %s\n",
399 gp_link->link_names[i],
400 ads_errstr(status)));
401 return;
403 dump_gpo(ads, mem_ctx, &gpo, lvl);
408 #endif /* HAVE_LDAP */
410 /****************************************************************
411 ****************************************************************/
413 static bool gpo_get_gp_ext_from_gpo(TALLOC_CTX *mem_ctx,
414 uint32_t flags,
415 struct GROUP_POLICY_OBJECT *gpo,
416 struct GP_EXT **gp_ext)
418 ZERO_STRUCTP(*gp_ext);
420 if (flags & GPO_INFO_FLAG_MACHINE) {
422 if (gpo->machine_extensions) {
424 if (!ads_parse_gp_ext(mem_ctx, gpo->machine_extensions,
425 gp_ext)) {
426 return false;
429 } else {
431 if (gpo->user_extensions) {
433 if (!ads_parse_gp_ext(mem_ctx, gpo->user_extensions,
434 gp_ext)) {
435 return false;
440 return true;
443 /****************************************************************
444 ****************************************************************/
446 NTSTATUS gpo_process_a_gpo(TALLOC_CTX *mem_ctx,
447 const struct security_token *token,
448 struct registry_key *root_key,
449 struct GROUP_POLICY_OBJECT *gpo,
450 const char *extension_guid_filter,
451 uint32_t flags)
453 struct GP_EXT *gp_ext = NULL;
454 int i;
456 DEBUG(10,("gpo_process_a_gpo: processing gpo %s (%s)\n",
457 gpo->name, gpo->display_name));
458 if (extension_guid_filter) {
459 DEBUGADD(10,("gpo_process_a_gpo: using filter %s (%s)\n",
460 extension_guid_filter,
461 cse_gpo_guid_string_to_name(extension_guid_filter)));
464 if (!gpo_get_gp_ext_from_gpo(mem_ctx, flags, gpo, &gp_ext)) {
465 return NT_STATUS_INVALID_PARAMETER;
468 if (!gp_ext || !gp_ext->num_exts) {
469 if (flags & GPO_INFO_FLAG_VERBOSE) {
470 DEBUG(0,("gpo_process_a_gpo: "
471 "no policies in %s (%s) for this extension\n",
472 gpo->name, gpo->display_name));
474 return NT_STATUS_OK;
477 for (i=0; i<gp_ext->num_exts; i++) {
479 NTSTATUS ntstatus;
481 if (extension_guid_filter &&
482 !strequal(extension_guid_filter,
483 gp_ext->extensions_guid[i])) {
484 continue;
487 ntstatus = gpext_process_extension(mem_ctx,
488 flags, token, root_key, gpo,
489 gp_ext->extensions_guid[i],
490 gp_ext->snapins_guid[i]);
491 if (!NT_STATUS_IS_OK(ntstatus)) {
492 return ntstatus;
496 return NT_STATUS_OK;
499 /****************************************************************
500 ****************************************************************/
502 static NTSTATUS gpo_process_gpo_list_by_ext(TALLOC_CTX *mem_ctx,
503 const struct security_token *token,
504 struct registry_key *root_key,
505 struct GROUP_POLICY_OBJECT *gpo_list,
506 const char *extensions_guid,
507 uint32_t flags)
509 NTSTATUS status;
510 struct GROUP_POLICY_OBJECT *gpo;
512 for (gpo = gpo_list; gpo; gpo = gpo->next) {
514 if (gpo->link_type == GP_LINK_LOCAL) {
515 continue;
519 /* FIXME: we need to pass down the *list* down to the
520 * extension, otherwise we cannot store the e.g. the *list* of
521 * logon-scripts correctly (for more then one GPO) */
523 status = gpo_process_a_gpo(mem_ctx, token, root_key,
524 gpo, extensions_guid, flags);
526 if (!NT_STATUS_IS_OK(status)) {
527 DEBUG(0,("failed to process gpo by ext: %s\n",
528 nt_errstr(status)));
529 return status;
533 return NT_STATUS_OK;
536 /****************************************************************
537 ****************************************************************/
539 NTSTATUS gpo_process_gpo_list(TALLOC_CTX *mem_ctx,
540 const struct security_token *token,
541 struct GROUP_POLICY_OBJECT *gpo_list,
542 const char *extensions_guid_filter,
543 uint32_t flags)
545 NTSTATUS status = NT_STATUS_OK;
546 struct gp_extension *gp_ext_list = NULL;
547 struct gp_extension *gp_ext = NULL;
548 struct registry_key *root_key = NULL;
549 struct gp_registry_context *reg_ctx = NULL;
550 WERROR werr;
552 status = init_gp_extensions(mem_ctx);
553 if (!NT_STATUS_IS_OK(status)) {
554 return status;
557 gp_ext_list = get_gp_extension_list();
558 if (!gp_ext_list) {
559 return NT_STATUS_DLL_INIT_FAILED;
562 /* get the key here */
563 if (flags & GPO_LIST_FLAG_MACHINE) {
564 werr = gp_init_reg_ctx(mem_ctx, KEY_HKLM, REG_KEY_WRITE,
565 get_system_token(),
566 &reg_ctx);
567 } else {
568 werr = gp_init_reg_ctx(mem_ctx, KEY_HKCU, REG_KEY_WRITE,
569 token,
570 &reg_ctx);
572 if (!W_ERROR_IS_OK(werr)) {
573 talloc_free(reg_ctx);
574 return werror_to_ntstatus(werr);
577 root_key = reg_ctx->curr_key;
579 for (gp_ext = gp_ext_list; gp_ext; gp_ext = gp_ext->next) {
581 const char *guid_str = NULL;
583 guid_str = GUID_string(mem_ctx, gp_ext->guid);
584 if (!guid_str) {
585 status = NT_STATUS_NO_MEMORY;
586 goto done;
589 if (extensions_guid_filter &&
590 (!strequal(guid_str, extensions_guid_filter))) {
591 continue;
594 DEBUG(0,("-------------------------------------------------\n"));
595 DEBUG(0,("gpo_process_gpo_list: processing ext: %s {%s}\n",
596 gp_ext->name, guid_str));
599 status = gpo_process_gpo_list_by_ext(mem_ctx, token,
600 root_key, gpo_list,
601 guid_str, flags);
602 if (!NT_STATUS_IS_OK(status)) {
603 goto done;
607 done:
608 talloc_free(reg_ctx);
609 talloc_free(root_key);
610 free_gp_extensions();
612 return status;
616 /****************************************************************
617 check wether the version number in a GROUP_POLICY_OBJECT match those of the
618 locally stored version. If not, fetch the required policy via CIFS
619 ****************************************************************/
621 NTSTATUS check_refresh_gpo(ADS_STRUCT *ads,
622 TALLOC_CTX *mem_ctx,
623 const char *cache_dir,
624 uint32_t flags,
625 struct GROUP_POLICY_OBJECT *gpo)
627 NTSTATUS result;
628 char *server = NULL;
629 char *share = NULL;
630 char *nt_path = NULL;
631 char *unix_path = NULL;
632 uint32_t sysvol_gpt_version = 0;
633 char *display_name = NULL;
635 result = gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
636 &server, &share, &nt_path, &unix_path);
638 if (!NT_STATUS_IS_OK(result)) {
639 goto out;
642 result = gpo_get_sysvol_gpt_version(mem_ctx,
643 unix_path,
644 &sysvol_gpt_version,
645 &display_name);
646 if (!NT_STATUS_IS_OK(result) &&
647 !NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_FILE)) {
648 DEBUG(10,("check_refresh_gpo: "
649 "failed to get local gpt version: %s\n",
650 nt_errstr(result)));
651 goto out;
654 DEBUG(10,("check_refresh_gpo: versions gpo %d sysvol %d\n",
655 gpo->version, sysvol_gpt_version));
657 /* FIXME: handle GPO_INFO_FLAG_FORCED_REFRESH from flags */
659 while (gpo->version > sysvol_gpt_version) {
661 DEBUG(1,("check_refresh_gpo: need to refresh GPO\n"));
663 result = gpo_fetch_files(mem_ctx, ads, cache_dir, gpo);
664 if (!NT_STATUS_IS_OK(result)) {
665 goto out;
668 result = gpo_get_sysvol_gpt_version(mem_ctx,
669 unix_path,
670 &sysvol_gpt_version,
671 &display_name);
672 if (!NT_STATUS_IS_OK(result)) {
673 DEBUG(10,("check_refresh_gpo: "
674 "failed to get local gpt version: %s\n",
675 nt_errstr(result)));
676 goto out;
679 if (gpo->version == sysvol_gpt_version) {
680 break;
684 DEBUG(10,("Name:\t\t\t%s (%s)\n", gpo->display_name, gpo->name));
685 DEBUGADD(10,("sysvol GPT version:\t%d (user: %d, machine: %d)\n",
686 sysvol_gpt_version,
687 GPO_VERSION_USER(sysvol_gpt_version),
688 GPO_VERSION_MACHINE(sysvol_gpt_version)));
689 DEBUGADD(10,("LDAP GPO version:\t%d (user: %d, machine: %d)\n",
690 gpo->version,
691 GPO_VERSION_USER(gpo->version),
692 GPO_VERSION_MACHINE(gpo->version)));
693 DEBUGADD(10,("LDAP GPO link:\t\t%s\n", gpo->link));
695 result = NT_STATUS_OK;
697 out:
698 return result;
702 /****************************************************************
703 check wether the version numbers in the gpo_list match the locally stored, if
704 not, go and get each required GPO via CIFS
705 ****************************************************************/
707 NTSTATUS check_refresh_gpo_list(ADS_STRUCT *ads,
708 TALLOC_CTX *mem_ctx,
709 const char *cache_dir,
710 uint32_t flags,
711 struct GROUP_POLICY_OBJECT *gpo_list)
713 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
714 struct GROUP_POLICY_OBJECT *gpo;
716 if (!gpo_list) {
717 return NT_STATUS_INVALID_PARAMETER;
720 for (gpo = gpo_list; gpo; gpo = gpo->next) {
722 result = check_refresh_gpo(ads, mem_ctx, cache_dir, flags, gpo);
723 if (!NT_STATUS_IS_OK(result)) {
724 goto out;
728 result = NT_STATUS_OK;
730 out:
731 /* FIXME close cli connection */
733 return result;
736 /****************************************************************
737 ****************************************************************/
739 NTSTATUS gpo_get_unix_path(TALLOC_CTX *mem_ctx,
740 const char *cache_dir,
741 struct GROUP_POLICY_OBJECT *gpo,
742 char **unix_path)
744 char *server, *share, *nt_path;
745 return gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
746 &server, &share, &nt_path, unix_path);
749 /****************************************************************
750 ****************************************************************/
752 char *gpo_flag_str(TALLOC_CTX *ctx, uint32_t flags)
754 char *str = NULL;
756 if (flags == 0) {
757 return NULL;
760 str = talloc_strdup(ctx, "");
761 if (!str) {
762 return NULL;
765 if (flags & GPO_INFO_FLAG_SLOWLINK)
766 str = talloc_strdup_append(str, "GPO_INFO_FLAG_SLOWLINK ");
767 if (flags & GPO_INFO_FLAG_VERBOSE)
768 str = talloc_strdup_append(str, "GPO_INFO_FLAG_VERBOSE ");
769 if (flags & GPO_INFO_FLAG_SAFEMODE_BOOT)
770 str = talloc_strdup_append(str, "GPO_INFO_FLAG_SAFEMODE_BOOT ");
771 if (flags & GPO_INFO_FLAG_NOCHANGES)
772 str = talloc_strdup_append(str, "GPO_INFO_FLAG_NOCHANGES ");
773 if (flags & GPO_INFO_FLAG_MACHINE)
774 str = talloc_strdup_append(str, "GPO_INFO_FLAG_MACHINE ");
775 if (flags & GPO_INFO_FLAG_LOGRSOP_TRANSITION)
776 str = talloc_strdup_append(str, "GPO_INFO_FLAG_LOGRSOP_TRANSITION ");
777 if (flags & GPO_INFO_FLAG_LINKTRANSITION)
778 str = talloc_strdup_append(str, "GPO_INFO_FLAG_LINKTRANSITION ");
779 if (flags & GPO_INFO_FLAG_FORCED_REFRESH)
780 str = talloc_strdup_append(str, "GPO_INFO_FLAG_FORCED_REFRESH ");
781 if (flags & GPO_INFO_FLAG_BACKGROUND)
782 str = talloc_strdup_append(str, "GPO_INFO_FLAG_BACKGROUND ");
784 return str;
787 /****************************************************************
788 ****************************************************************/
790 NTSTATUS gp_find_file(TALLOC_CTX *mem_ctx,
791 uint32_t flags,
792 const char *filename,
793 const char *suffix,
794 const char **filename_out)
796 const char *tmp = NULL;
797 struct stat sbuf;
798 const char *path = NULL;
800 if (flags & GPO_LIST_FLAG_MACHINE) {
801 path = "Machine";
802 } else {
803 path = "User";
806 tmp = talloc_asprintf(mem_ctx, "%s/%s/%s", filename,
807 path, suffix);
808 NT_STATUS_HAVE_NO_MEMORY(tmp);
810 if (stat(tmp, &sbuf) == 0) {
811 *filename_out = tmp;
812 return NT_STATUS_OK;
815 path = talloc_strdup_upper(mem_ctx, path);
816 NT_STATUS_HAVE_NO_MEMORY(path);
818 tmp = talloc_asprintf(mem_ctx, "%s/%s/%s", filename,
819 path, suffix);
820 NT_STATUS_HAVE_NO_MEMORY(tmp);
822 if (stat(tmp, &sbuf) == 0) {
823 *filename_out = tmp;
824 return NT_STATUS_OK;
827 return NT_STATUS_NO_SUCH_FILE;
830 /****************************************************************
831 ****************************************************************/
833 ADS_STATUS gp_get_machine_token(ADS_STRUCT *ads,
834 TALLOC_CTX *mem_ctx,
835 const char *dn,
836 struct security_token **token)
838 #ifdef HAVE_ADS
839 struct security_token *ad_token = NULL;
840 ADS_STATUS status;
841 NTSTATUS ntstatus;
843 status = ads_get_sid_token(ads, mem_ctx, dn, &ad_token);
844 if (!ADS_ERR_OK(status)) {
845 return status;
847 ntstatus = merge_nt_token(mem_ctx, ad_token, get_system_token(),
848 token);
849 if (!NT_STATUS_IS_OK(ntstatus)) {
850 return ADS_ERROR_NT(ntstatus);
852 return ADS_SUCCESS;
853 #else
854 return ADS_ERROR_NT(NT_STATUS_NOT_SUPPORTED);
855 #endif