Exemplo n.º 1
0
NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
			 struct cli_state *cli,
			 struct GROUP_POLICY_OBJECT *gpo)
{
	NTSTATUS result;
	char *server, *service, *nt_path, *unix_path;
	char *nt_ini_path, *unix_ini_path;

	result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
					 &server, &service, &nt_path,
					 &unix_path);
	NT_STATUS_NOT_OK_RETURN(result);

	result = gpo_prepare_local_store(mem_ctx, unix_path);
	NT_STATUS_NOT_OK_RETURN(result);

	unix_ini_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
	nt_ini_path = talloc_asprintf(mem_ctx, "%s\\%s", nt_path, GPT_INI);
	NT_STATUS_HAVE_NO_MEMORY(unix_ini_path);
	NT_STATUS_HAVE_NO_MEMORY(nt_ini_path);

	result = gpo_copy_file(mem_ctx, cli, nt_ini_path, unix_ini_path);
	NT_STATUS_NOT_OK_RETURN(result);

	result = gpo_sync_directories(mem_ctx, cli, nt_path, unix_path);
	NT_STATUS_NOT_OK_RETURN(result);

	return NT_STATUS_OK;
}
Exemplo n.º 2
0
NTSTATUS gpo_get_unix_path(TALLOC_CTX *mem_ctx,
                           const char *cache_dir,
			   struct GROUP_POLICY_OBJECT *gpo,
			   char **unix_path)
{
	char *server, *share, *nt_path;
	return gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
				       &server, &share, &nt_path, unix_path);
}
Exemplo n.º 3
0
NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
                         ADS_STRUCT *ads,
                         const char *cache_dir,
			 const struct GROUP_POLICY_OBJECT *gpo)
{
	NTSTATUS result;
	char *server, *service, *nt_path, *unix_path;
	char *nt_ini_path, *unix_ini_path;
	struct cli_state *cli;


	result = gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
					 &server, &service, &nt_path,
					 &unix_path);
	NT_STATUS_NOT_OK_RETURN(result);

	/* for now reuse the existing ds connection */

	result = gpo_connect_server(ads, ads->server.ldap_server, service, &cli);
	NT_STATUS_NOT_OK_RETURN(result);

	result = gpo_prepare_local_store(mem_ctx, cache_dir, unix_path);
	NT_STATUS_NOT_OK_RETURN(result);

	unix_ini_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
	nt_ini_path = talloc_asprintf(mem_ctx, "%s\\%s", nt_path, GPT_INI);
	NT_STATUS_HAVE_NO_MEMORY(unix_ini_path);
	NT_STATUS_HAVE_NO_MEMORY(nt_ini_path);

	result = gpo_copy_file(mem_ctx, cli, nt_ini_path, unix_ini_path);
	NT_STATUS_NOT_OK_RETURN(result);

	result = gpo_sync_directories(mem_ctx, cli, nt_path, unix_path);
	NT_STATUS_NOT_OK_RETURN(result);

	return NT_STATUS_OK;
}
Exemplo n.º 4
0
NTSTATUS check_refresh_gpo(ADS_STRUCT *ads,
			   TALLOC_CTX *mem_ctx,
                           const char *cache_dir,
                           struct loadparm_context *lp_ctx,
			   uint32_t flags,
			   struct GROUP_POLICY_OBJECT *gpo)
{
	NTSTATUS result;
	char *server = NULL;
	char *share = NULL;
	char *nt_path = NULL;
	char *unix_path = NULL;
	uint32_t sysvol_gpt_version = 0;
	char *display_name = NULL;

	result = gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
					 &server, &share, &nt_path, &unix_path);

	if (!NT_STATUS_IS_OK(result)) {
		goto out;
	}

	result = gpo_get_sysvol_gpt_version(mem_ctx,
					    unix_path,
					    &sysvol_gpt_version,
					    &display_name);
	if (!NT_STATUS_IS_OK(result) &&
	    !NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_FILE)) {
		DEBUG(10,("check_refresh_gpo: "
			"failed to get local gpt version: %s\n",
			nt_errstr(result)));
		goto out;
	}

	DEBUG(10,("check_refresh_gpo: versions gpo %d sysvol %d\n",
		gpo->version, sysvol_gpt_version));

	/* FIXME: handle GPO_INFO_FLAG_FORCED_REFRESH from flags */

	while (gpo->version > sysvol_gpt_version) {

		DEBUG(1,("check_refresh_gpo: need to refresh GPO\n"));

		result = gpo_fetch_files(mem_ctx, ads, lp_ctx, cache_dir, gpo);
		if (!NT_STATUS_IS_OK(result)) {
			goto out;
		}

		result = gpo_get_sysvol_gpt_version(mem_ctx,
						    unix_path,
						    &sysvol_gpt_version,
						    &display_name);
		if (!NT_STATUS_IS_OK(result)) {
			DEBUG(10,("check_refresh_gpo: "
				"failed to get local gpt version: %s\n",
				nt_errstr(result)));
			goto out;
		}

		if (gpo->version == sysvol_gpt_version) {
			break;
		}
	}

	DEBUG(10,("Name:\t\t\t%s (%s)\n", gpo->display_name, gpo->name));
	DEBUGADD(10,("sysvol GPT version:\t%d (user: %d, machine: %d)\n",
		sysvol_gpt_version,
		GPO_VERSION_USER(sysvol_gpt_version),
		GPO_VERSION_MACHINE(sysvol_gpt_version)));
	DEBUGADD(10,("LDAP GPO version:\t%d (user: %d, machine: %d)\n",
		gpo->version,
		GPO_VERSION_USER(gpo->version),
		GPO_VERSION_MACHINE(gpo->version)));
	DEBUGADD(10,("LDAP GPO link:\t\t%s\n", gpo->link));

	result = NT_STATUS_OK;

 out:
	return result;

}
Exemplo n.º 5
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;
}