static NTSTATUS pdb_samba_dsdb_enum_alias_memberships(struct pdb_methods *m,
					       TALLOC_CTX *mem_ctx,
					       const struct dom_sid *domain_sid,
					       const struct dom_sid *members,
					       size_t num_members,
					       uint32_t **palias_rids,
					       size_t *pnum_alias_rids)
{
	struct pdb_samba_dsdb_state *state = talloc_get_type_abort(
		m->private_data, struct pdb_samba_dsdb_state);
	uint32_t *alias_rids = NULL;
	size_t num_alias_rids = 0;
	int i;
	struct dom_sid *groupSIDs = NULL;
	unsigned int num_groupSIDs = 0;
	char *filter;
	NTSTATUS status;
	const char *sid_dn;
	DATA_BLOB sid_blob;

	TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
	NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
	/*
	 * TODO: Get the filter right so that we only get the aliases from
	 * either the SAM or BUILTIN
	 */

	filter = talloc_asprintf(tmp_ctx, "(&(objectClass=group)(groupType:1.2.840.113556.1.4.803:=%u))",
				 GROUP_TYPE_BUILTIN_LOCAL_GROUP);
	if (filter == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	for (i = 0; i < num_members; i++) {
		struct dom_sid_buf buf;

		sid_dn = talloc_asprintf(
			tmp_ctx,
			"<SID=%s>",
			dom_sid_str_buf(&members[i], &buf));
		if (sid_dn == NULL) {
			TALLOC_FREE(tmp_ctx);
			return NT_STATUS_NO_MEMORY;
		}

		sid_blob = data_blob_string_const(sid_dn);

		status = dsdb_expand_nested_groups(state->ldb, &sid_blob, true, filter,
						   tmp_ctx, &groupSIDs, &num_groupSIDs);
		if (!NT_STATUS_IS_OK(status)) {
			talloc_free(tmp_ctx);
			return status;
		}
	}

	alias_rids = talloc_array(mem_ctx, uint32_t, num_groupSIDs);
	if (alias_rids == NULL) {
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	for (i=0; i<num_groupSIDs; i++) {
		if (sid_peek_check_rid(domain_sid, &groupSIDs[i],
				       &alias_rids[num_alias_rids])) {
			num_alias_rids++;;
		}
	}

	*palias_rids = alias_rids;
	*pnum_alias_rids = num_alias_rids;
	return NT_STATUS_OK;
}
static NTSTATUS pdb_samba_dsdb_enum_alias_memberships(struct pdb_methods *m,
					       TALLOC_CTX *mem_ctx,
					       const struct dom_sid *domain_sid,
					       const struct dom_sid *members,
					       size_t num_members,
					       uint32_t **palias_rids,
					       size_t *pnum_alias_rids)
{
	struct pdb_samba_dsdb_state *state = talloc_get_type_abort(
		m->private_data, struct pdb_samba_dsdb_state);
	uint32_t *alias_rids = NULL;
	size_t num_alias_rids = 0;
	int i;
	struct dom_sid *groupSIDs = NULL;
	unsigned int num_groupSIDs = 0;
	char *filter;
	NTSTATUS status;
	const char *sid_dn;
	DATA_BLOB sid_blob;

	TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
	NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
	 

	filter = talloc_asprintf(tmp_ctx, "(&(objectClass=group)(groupType:1.2.840.113556.1.4.803:=%u))",
				 GROUP_TYPE_BUILTIN_LOCAL_GROUP);
	if (filter == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	for (i = 0; i < num_members; i++) {
		struct dom_sid_buf buf;

		sid_dn = talloc_asprintf(
			tmp_ctx,
			"<SID=%s>",
			dom_sid_str_buf(&members[i], &buf));
		if (sid_dn == NULL) {
			TALLOC_FREE(tmp_ctx);
			return NT_STATUS_NO_MEMORY;
		}

		sid_blob = data_blob_string_const(sid_dn);

		status = dsdb_expand_nested_groups(state->ldb, &sid_blob, true, filter,
						   tmp_ctx, &groupSIDs, &num_groupSIDs);
		if (!NT_STATUS_IS_OK(status)) {
			talloc_free(tmp_ctx);
			return status;
		}
	}

	alias_rids = talloc_array(mem_ctx, uint32_t, num_groupSIDs);
	if (alias_rids == NULL) {
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	for (i=0; i<num_groupSIDs; i++) {
		if (sid_peek_check_rid(domain_sid, &groupSIDs[i],
				       &alias_rids[num_alias_rids])) {
			num_alias_rids++;;
		}
	}

	*palias_rids = alias_rids;
	*pnum_alias_rids = num_alias_rids;
	return NT_STATUS_OK;
}