Example #1
0
/* Query display info for a domain.  This returns enough information plus a
   bit extra to give an overview of domain users for the User Manager
   application. */
static NTSTATUS query_user_list(struct winbindd_domain *domain,
			       TALLOC_CTX *mem_ctx,
			       uint32 *num_entries, 
			       WINBIND_USERINFO **info)
{
	CLI_POLICY_HND *hnd;
	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
	POLICY_HND dom_pol;
	BOOL got_dom_pol = False;
	uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
	unsigned int i, start_idx, retry;
	uint32 loop_count;

	DEBUG(3,("rpc: query_user_list\n"));

	*num_entries = 0;
	*info = NULL;

	retry = 0;
	do {
		/* Get sam handle */

		if ( !NT_STATUS_IS_OK(result = cm_get_sam_handle(domain, &hnd)) )
			return result;

		/* 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;

	i = start_idx = 0;
	loop_count = 0;

	do {
		TALLOC_CTX *ctx2;
		uint32 num_dom_users, j;
		uint32 max_entries, max_size;
		SAM_DISPINFO_CTR ctr;
		SAM_DISPINFO_1 info1;

		ZERO_STRUCT( ctr );
		ZERO_STRUCT( info1 );
		ctr.sam.info1 = &info1;
	
		if (!(ctx2 = talloc_init("winbindd enum_users"))) {
			result = NT_STATUS_NO_MEMORY;
			goto done;
		}		

		/* this next bit is copied from net_user_list_internal() */

		get_query_dispinfo_params( loop_count, &max_entries, &max_size );

		result = cli_samr_query_dispinfo(hnd->cli, mem_ctx, &dom_pol,
			&start_idx, 1, &num_dom_users, max_entries, max_size, &ctr);

		loop_count++;

		*num_entries += num_dom_users;

		*info = talloc_realloc( mem_ctx, *info, 
			(*num_entries) * sizeof(WINBIND_USERINFO));

		if (!(*info)) {
			result = NT_STATUS_NO_MEMORY;
			talloc_destroy(ctx2);
			goto done;
		}

		for (j = 0; j < num_dom_users; i++, j++) {
			fstring username, fullname;
			uint32 rid = ctr.sam.info1->sam[j].rid_user;
			
			unistr2_to_ascii( username, &(&ctr.sam.info1->str[j])->uni_acct_name, sizeof(username)-1);
			unistr2_to_ascii( fullname, &(&ctr.sam.info1->str[j])->uni_full_name, sizeof(fullname)-1);
			
			(*info)[i].acct_name = talloc_strdup(mem_ctx, username );
			(*info)[i].full_name = talloc_strdup(mem_ctx, fullname );
			(*info)[i].user_sid = rid_to_talloced_sid(domain, mem_ctx, rid );
			
			/* For the moment we set the primary group for
			   every user to be the Domain Users group.
			   There are serious problems with determining
			   the actual primary group for large domains.
			   This should really be made into a 'winbind
			   force group' smb.conf parameter or
			   something like that. */
			   
			(*info)[i].group_sid = rid_to_talloced_sid(domain, 
				mem_ctx, DOMAIN_GROUP_RID_USERS);
		}

		talloc_destroy(ctx2);

	} while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));

 done:

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

	return result;
}
Example #2
0
static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli, 
                                        TALLOC_CTX *mem_ctx,
                                        int argc, char **argv) 
{
	POLICY_HND connect_pol, domain_pol;
	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
	uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries, i;
	int info_level = 1;
	SAM_DISPINFO_CTR ctr;
	SAM_DISPINFO_1 info1;
	SAM_DISPINFO_2 info2;
	SAM_DISPINFO_3 info3;
	SAM_DISPINFO_4 info4;
	SAM_DISPINFO_5 info5;
	int loop_count = 0;
	BOOL got_params = False; /* Use get_query_dispinfo_params() or not? */

	if (argc > 4) {
		printf("Usage: %s [info level] [start index] [max entries] [max_size]\n", argv[0]);
		return NT_STATUS_OK;
	}

	if (argc >= 2)
                sscanf(argv[1], "%i", &info_level);
        
	if (argc >= 3)
                sscanf(argv[2], "%i", &start_idx);
        
	if (argc >= 4) {
                sscanf(argv[3], "%i", &max_entries);
		got_params = True;
	}

	if (argc >= 5) {
                sscanf(argv[4], "%i", &max_size);
		got_params = True;
	}

	/* 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 display info */

	ZERO_STRUCT(ctr);
	ZERO_STRUCT(info1);

	switch (info_level) {
	case 1:
		ZERO_STRUCT(info1);
	ctr.sam.info1 = &info1;
		break;
	case 2:
		ZERO_STRUCT(info2);
		ctr.sam.info2 = &info2;
		break;
	case 3:
		ZERO_STRUCT(info3);
		ctr.sam.info3 = &info3;
		break;
	case 4:
		ZERO_STRUCT(info4);
		ctr.sam.info4 = &info4;
		break;
	case 5:
		ZERO_STRUCT(info5);
		ctr.sam.info5 = &info5;
		break;
	}


	do {	

	if (!got_params)
		get_query_dispinfo_params(
			loop_count, &max_entries, &max_size);

	result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
					 &start_idx, info_level,
					 &num_entries, max_entries, 
					 max_size, &ctr);

	loop_count++;

	for (i = 0; i < num_entries; i++) {
		switch (info_level) {
		case 1:
			display_sam_info_1(&ctr.sam.info1->sam[i], &ctr.sam.info1->str[i]);
			break;
			case 2:
				display_sam_info_2(&ctr.sam.info2->sam[i], &ctr.sam.info2->str[i]);
				break;
			case 3:
				display_sam_info_3(&ctr.sam.info3->sam[i], &ctr.sam.info3->str[i]);
				break;
		case 4:
			display_sam_info_4(&ctr.sam.info4->sam[i], &ctr.sam.info4->str[i]);
			break;
			case 5:
				display_sam_info_5(&ctr.sam.info5->sam[i], &ctr.sam.info5->str[i]);
				break;
		}
	}
	} while (!NT_STATUS_IS_OK(result));
 done:
	return result;
}