コード例 #1
0
ファイル: winbindd_rpc.c プロジェクト: niubl/camera_project
/* find the sequence number for a domain */
static NTSTATUS sequence_number(struct winbindd_domain *domain, uint32 *seq)
{
	TALLOC_CTX *mem_ctx;
	CLI_POLICY_HND *hnd;
	SAM_UNK_CTR ctr;
	uint16 switch_value = 2;
	NTSTATUS result;
	POLICY_HND dom_pol;
	BOOL got_dom_pol = False;
	uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
	int retry;

	DEBUG(10,("rpc: fetch sequence_number for %s\n", domain->name));

	*seq = DOM_SEQUENCE_NONE;

	if (!(mem_ctx = talloc_init("sequence_number[rpc]")))
		return NT_STATUS_NO_MEMORY;

	retry = 0;
	do {
#ifdef HAVE_LDAP
		if ( domain->native_mode ) 
		{
			DEBUG(8,("using get_ldap_seq() to retrieve the sequence number\n"));

			if ( get_ldap_sequence_number( domain->name, seq ) == 0 ) {			
				result = NT_STATUS_OK;
				DEBUG(10,("domain_sequence_number: LDAP for domain %s is %u\n",
					domain->name, *seq));
				goto done;
			}

			DEBUG(10,("domain_sequence_number: failed to get LDAP sequence number for domain %s\n",
			domain->name ));
		}
#endif /* HAVE_LDAP */
	        /* Get sam handle */
		if (!NT_STATUS_IS_OK(result = cm_get_sam_handle(domain, &hnd)))
			goto done;

		/* Get domain handle */
		result = cli_samr_open_domain(hnd->cli, mem_ctx, &hnd->pol, 
				      des_access, &domain->sid, &dom_pol);
	} while (!NT_STATUS_IS_OK(result) && (retry++ < 1) && hnd && hnd->cli && hnd->cli->fd == -1);

	if (!NT_STATUS_IS_OK(result))
		goto done;

	got_dom_pol = True;

	/* Query domain info */

	result = cli_samr_query_dom_info(hnd->cli, mem_ctx, &dom_pol,
					 switch_value, &ctr);

	if (NT_STATUS_IS_OK(result)) {
		*seq = ctr.info.inf2.seq_num;
		DEBUG(10,("domain_sequence_number: for domain %s is %u\n", domain->name, (unsigned)*seq));
	} else {
		DEBUG(10,("domain_sequence_number: failed to get sequence number (%u) for domain %s\n",
			(unsigned)*seq, domain->name ));
	}

  done:

	if (got_dom_pol)
		cli_samr_close(hnd->cli, mem_ctx, &dom_pol);

	talloc_destroy(mem_ctx);

	return result;
}
コード例 #2
0
ファイル: cmd_samr.c プロジェクト: jophxy/samba
static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli, 
                                       TALLOC_CTX *mem_ctx,
                                       int argc, char **argv) 
{
	POLICY_HND connect_pol, domain_pol;
	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
	int switch_value = 2;
	SAM_UNK_CTR ctr;

	if (argc > 2) {
		printf("Usage: %s [infolevel]\n", argv[0]);
		return NT_STATUS_OK;
	}

	if (argc == 2)
                sscanf(argv[1], "%i", &switch_value);

	/* Get sam policy handle */

	result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, 
				  &connect_pol);
	if (!NT_STATUS_IS_OK(result)) {
		goto done;
	}

	/* Get domain policy handle */

	result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
				      MAXIMUM_ALLOWED_ACCESS,
				      &domain_sid, &domain_pol);
	if (!NT_STATUS_IS_OK(result)) {
		goto done;
	}

	/* Query domain info */

	result = cli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
					 switch_value, &ctr);
	if (!NT_STATUS_IS_OK(result)) {
		goto done;
	}

	/* Display domain info */

	switch (switch_value) {
	case 1:
		display_sam_unk_info_1(&ctr.info.inf1);
		break;
	case 2:
		display_sam_unk_info_2(&ctr.info.inf2);
		break;
	default:
		printf("cannot display domain info for switch value %d\n",
		       switch_value);
		break;
	}

 done:
 
 	cli_samr_close(cli, mem_ctx, &domain_pol);
 	cli_samr_close(cli, mem_ctx, &connect_pol);
	return result;
}