void dump_gplink(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GP_LINK *gp_link) { ADS_STATUS status; int i; int lvl = 10; if (gp_link == NULL) { return; } DEBUG(lvl,("---------------------\n\n")); DEBUGADD(lvl,("gplink: %s\n", gp_link->gp_link)); DEBUGADD(lvl,("gpopts: %d ", gp_link->gp_opts)); switch (gp_link->gp_opts) { case GPOPTIONS_INHERIT: DEBUGADD(lvl,("GPOPTIONS_INHERIT\n")); break; case GPOPTIONS_BLOCK_INHERITANCE: DEBUGADD(lvl,("GPOPTIONS_BLOCK_INHERITANCE\n")); break; default: break; } DEBUGADD(lvl,("num links: %d\n", gp_link->num_links)); for (i = 0; i < gp_link->num_links; i++) { DEBUGADD(lvl,("---------------------\n\n")); DEBUGADD(lvl,("link: #%d\n", i + 1)); DEBUGADD(lvl,("name: %s\n", gp_link->link_names[i])); DEBUGADD(lvl,("opt: %d ", gp_link->link_opts[i])); if (gp_link->link_opts[i] & GPO_LINK_OPT_ENFORCED) { DEBUGADD(lvl,("GPO_LINK_OPT_ENFORCED ")); } if (gp_link->link_opts[i] & GPO_LINK_OPT_DISABLED) { DEBUGADD(lvl,("GPO_LINK_OPT_DISABLED")); } DEBUGADD(lvl,("\n")); if (ads != NULL && mem_ctx != NULL) { struct GROUP_POLICY_OBJECT gpo; status = ads_get_gpo(ads, mem_ctx, gp_link->link_names[i], NULL, NULL, &gpo); if (!ADS_ERR_OK(status)) { DEBUG(lvl,("get gpo for %s failed: %s\n", gp_link->link_names[i], ads_errstr(status))); return; } dump_gpo(ads, mem_ctx, &gpo, lvl); } } }
void dump_gpo_list(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GROUP_POLICY_OBJECT *gpo_list, int debuglevel) { struct GROUP_POLICY_OBJECT *gpo = NULL; for (gpo = gpo_list; gpo; gpo = gpo->next) { dump_gpo(ads, mem_ctx, gpo, debuglevel); } }
static int net_ads_gpo_get_gpo(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; TALLOC_CTX *mem_ctx; struct GROUP_POLICY_OBJECT gpo; if (argc < 1 || c->display_usage) { d_printf("Usage:\n" "net ads gpo getgpo <gpo>\n" " List speciefied GPO\n" " gpo\t\tGPO to list\n"); return -1; } mem_ctx = talloc_init("ads_gpo_get_gpo"); if (mem_ctx == NULL) { return -1; } status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } if (strnequal(argv[0], "CN={", strlen("CN={"))) { status = ads_get_gpo(ads, mem_ctx, argv[0], NULL, NULL, &gpo); } else { status = ads_get_gpo(ads, mem_ctx, NULL, argv[0], NULL, &gpo); } if (!ADS_ERR_OK(status)) { d_printf("get gpo for [%s] failed: %s\n", argv[0], ads_errstr(status)); goto out; } dump_gpo(ads, mem_ctx, &gpo, 1); out: talloc_destroy(mem_ctx); ads_destroy(&ads); return 0; }
static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *mem_ctx; ADS_STRUCT *ads; ADS_STATUS status; const char *dn = NULL; struct GROUP_POLICY_OBJECT *gpo_list = NULL; struct GROUP_POLICY_OBJECT *read_list = NULL; uint32 uac = 0; uint32 flags = 0; struct GROUP_POLICY_OBJECT *gpo; NTSTATUS result; struct nt_user_token *token = NULL; if (argc < 1 || c->display_usage) { d_printf("Usage:\n" "net ads gpo refresh <username|machinename>\n" " Lists all GPOs assigned to an account and " "downloads them\n" " username\tUser to refresh GPOs for\n" " machinename\tMachine to refresh GPOs for\n"); return -1; } mem_ctx = talloc_init("net_ads_gpo_refresh"); if (mem_ctx == NULL) { return -1; } status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { d_printf("failed to connect AD server: %s\n", ads_errstr(status)); goto out; } status = ads_find_samaccount(ads, mem_ctx, argv[0], &uac, &dn); if (!ADS_ERR_OK(status)) { d_printf("failed to find samaccount for %s\n", argv[0]); goto out; } if (uac & UF_WORKSTATION_TRUST_ACCOUNT) { flags |= GPO_LIST_FLAG_MACHINE; } d_printf("\n%s: '%s' has dn: '%s'\n\n", (uac & UF_WORKSTATION_TRUST_ACCOUNT) ? "machine" : "user", argv[0], dn); d_printf("* fetching token "); if (uac & UF_WORKSTATION_TRUST_ACCOUNT) { status = gp_get_machine_token(ads, mem_ctx, dn, &token); } else { status = ads_get_sid_token(ads, mem_ctx, dn, &token); } if (!ADS_ERR_OK(status)) { d_printf("failed: %s\n", ads_errstr(status)); goto out; } d_printf("finished\n"); d_printf("* fetching GPO List "); status = ads_get_gpo_list(ads, mem_ctx, dn, flags, token, &gpo_list); if (!ADS_ERR_OK(status)) { d_printf("failed: %s\n", ads_errstr(status)); goto out; } d_printf("finished\n"); d_printf("* refreshing Group Policy Data "); if (!NT_STATUS_IS_OK(result = check_refresh_gpo_list(ads, mem_ctx, flags, gpo_list))) { d_printf("failed: %s\n", nt_errstr(result)); goto out; } d_printf("finished\n"); d_printf("* storing GPO list to registry "); { WERROR werr = gp_reg_state_store(mem_ctx, flags, dn, token, gpo_list); if (!W_ERROR_IS_OK(werr)) { d_printf("failed: %s\n", win_errstr(werr)); goto out; } } d_printf("finished\n"); if (c->opt_verbose) { d_printf("* dumping GPO list\n"); for (gpo = gpo_list; gpo; gpo = gpo->next) { dump_gpo(ads, mem_ctx, gpo, 0); #if 0 char *server, *share, *nt_path, *unix_path; d_printf("--------------------------------------\n"); d_printf("Name:\t\t\t%s\n", gpo->display_name); d_printf("LDAP GPO version:\t%d (user: %d, machine: %d)\n", gpo->version, GPO_VERSION_USER(gpo->version), GPO_VERSION_MACHINE(gpo->version)); result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path, &server, &share, &nt_path, &unix_path); if (!NT_STATUS_IS_OK(result)) { d_printf("got: %s\n", nt_errstr(result)); } d_printf("GPO stored on server: %s, share: %s\n", server, share); d_printf("\tremote path:\t%s\n", nt_path); d_printf("\tlocal path:\t%s\n", unix_path); #endif } } d_printf("* re-reading GPO list from registry "); { WERROR werr = gp_reg_state_read(mem_ctx, flags, &token->user_sids[0], &read_list); if (!W_ERROR_IS_OK(werr)) { d_printf("failed: %s\n", win_errstr(werr)); goto out; } } d_printf("finished\n"); if (c->opt_verbose) { d_printf("* dumping GPO list from registry\n"); for (gpo = read_list; gpo; gpo = gpo->next) { dump_gpo(ads, mem_ctx, gpo, 0); #if 0 char *server, *share, *nt_path, *unix_path; d_printf("--------------------------------------\n"); d_printf("Name:\t\t\t%s\n", gpo->display_name); d_printf("LDAP GPO version:\t%d (user: %d, machine: %d)\n", gpo->version, GPO_VERSION_USER(gpo->version), GPO_VERSION_MACHINE(gpo->version)); result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path, &server, &share, &nt_path, &unix_path); if (!NT_STATUS_IS_OK(result)) { d_printf("got: %s\n", nt_errstr(result)); } d_printf("GPO stored on server: %s, share: %s\n", server, share); d_printf("\tremote path:\t%s\n", nt_path); d_printf("\tlocal path:\t%s\n", unix_path); #endif } } out: ads_destroy(&ads); talloc_destroy(mem_ctx); return 0; }
static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; LDAPMessage *res = NULL; int num_reply = 0; LDAPMessage *msg = NULL; struct GROUP_POLICY_OBJECT gpo; TALLOC_CTX *mem_ctx; char *dn; const char *attrs[] = { "versionNumber", "flags", "gPCFileSysPath", "displayName", "name", "gPCMachineExtensionNames", "gPCUserExtensionNames", "ntSecurityDescriptor", NULL }; if (c->display_usage) { d_printf("Usage:\n" "net ads gpo listall\n" " List all GPOs on the DC\n"); return 0; } mem_ctx = talloc_init("net_ads_gpo_list_all"); if (mem_ctx == NULL) { return -1; } status = ads_startup(c, false, &ads); if (!ADS_ERR_OK(status)) { goto out; } status = ads_do_search_all_sd_flags(ads, ads->config.bind_path, LDAP_SCOPE_SUBTREE, "(objectclass=groupPolicyContainer)", attrs, DACL_SECURITY_INFORMATION, &res); if (!ADS_ERR_OK(status)) { d_printf("search failed: %s\n", ads_errstr(status)); goto out; } num_reply = ads_count_replies(ads, res); d_printf("Got %d replies\n\n", num_reply); /* dump the results */ for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { if ((dn = ads_get_dn(ads, mem_ctx, msg)) == NULL) { goto out; } status = ads_parse_gpo(ads, mem_ctx, msg, dn, &gpo); if (!ADS_ERR_OK(status)) { d_printf("ads_parse_gpo failed: %s\n", ads_errstr(status)); goto out; } dump_gpo(ads, mem_ctx, &gpo, 0); } out: ads_msgfree(ads, res); TALLOC_FREE(mem_ctx); ads_destroy(&ads); return 0; }