Exemplo n.º 1
0
/*
  dump a set of cldap results
*/
static void cldap_dump_results(struct cldap_search *search)
{
	struct ldb_ldif ldif;
	struct ldb_context *ldb;

	if (!search || !(search->out.response)) {
		return;
	}

	/* we need a ldb context to use ldb_ldif_write_file() */
	ldb = ldb_init(NULL);

	ZERO_STRUCT(ldif);
	ldif.msg = ldap_msg_to_ldb(ldb, ldb, search->out.response);

	ldb_ldif_write_file(ldb, stdout, &ldif);

	talloc_free(ldb);
}
Exemplo n.º 2
0
Arquivo: cldap.c Projeto: gojdic/samba
/*
  test cldap netlogon server type flag "NBT_SERVER_DS_DNS_FOREST"
*/
static bool test_cldap_netlogon_flag_ds_dns_forest(struct torture_context *tctx,
	const char *dest)
{
	struct cldap_socket *cldap;
	NTSTATUS status;
	struct cldap_netlogon search;
	uint32_t server_type;
	struct netlogon_samlogon_response n1;
	struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);

	bool result = true;

	status = cldap_socket_init(tctx, NULL, NULL, NULL, &cldap);
	CHECK_STATUS(status, NT_STATUS_OK);

	printf("Testing netlogon server type flag NBT_SERVER_DS_DNS_FOREST: ");

	ZERO_STRUCT(search);
	search.in.dest_address = dest;
	search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
	search.in.acct_control = -1;
	search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
	search.in.map_response = true;

	status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
	CHECK_STATUS(status, NT_STATUS_OK);

	n1 = search.out.netlogon;
	if (n1.ntver == NETLOGON_NT_VERSION_5)
		server_type = n1.data.nt5.server_type;
	else if (n1.ntver == NETLOGON_NT_VERSION_5EX)
		server_type = n1.data.nt5_ex.server_type;

	if (server_type & DS_DNS_FOREST) {
		struct cldap_search search2;
		const char *attrs[] = { "defaultNamingContext", "rootDomainNamingContext", 
			NULL };
		struct ldb_context *ldb;
		struct ldb_message *msg;

		/* Trying to fetch the attributes "defaultNamingContext" and
		   "rootDomainNamingContext" */
		ZERO_STRUCT(search2);
		search2.in.dest_address = dest;
		search2.in.dest_port = lp_cldap_port(tctx->lp_ctx);
		search2.in.timeout = 10;
		search2.in.retries = 3;
		search2.in.filter = "(objectclass=*)";
		search2.in.attributes = attrs;

		status = cldap_search(cldap, tctx, &search2);
		CHECK_STATUS(status, NT_STATUS_OK);

		ldb = ldb_init(NULL, NULL);

		msg = ldap_msg_to_ldb(ldb, ldb, search2.out.response);

		/* Try to compare the two attributes */
		if (ldb_msg_element_compare(ldb_msg_find_element(msg, attrs[0]),
			ldb_msg_find_element(msg, attrs[1])))
			result = false;

		talloc_free(ldb);
	}

	if (result)
		printf("passed\n");
	else
		printf("failed\n");

	return result;
}