static NTSTATUS delete_trust_user(TALLOC_CTX *mem_ctx,
				  struct pdb_samba_dsdb_state *state,
				  const char *trust_user)
{
	const char *attrs[] = { "userAccountControl", NULL };
	struct ldb_message **msgs;
	uint32_t uac;
	int ret;

	ret = gendb_search(state->ldb,
			   mem_ctx,
			   ldb_get_default_basedn(state->ldb),
			   &msgs,
			   attrs,
			   "samAccountName=%s$",
			   trust_user);
	if (ret > 1) {
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	if (ret == 0) {
		return NT_STATUS_OK;
	}

	uac = ldb_msg_find_attr_as_uint(msgs[0],
					"userAccountControl",
					0);
	if (!(uac & UF_INTERDOMAIN_TRUST_ACCOUNT)) {
		return NT_STATUS_OBJECT_NAME_COLLISION;
	}

	ret = ldb_delete(state->ldb, msgs[0]->dn);
	switch (ret) {
	case LDB_SUCCESS:
		break;
	case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
		return NT_STATUS_ACCESS_DENIED;
	default:
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	return NT_STATUS_OK;
}
static NTSTATUS delete_trust_user(TALLOC_CTX *mem_ctx,
				  struct pdb_samba_dsdb_state *state,
				  const char *trust_user)
{
	const char *attrs[] = { "userAccountControl", NULL };
	struct ldb_message **msgs;
	uint32_t uac;
	int ret;

	ret = gendb_search(state->ldb,
			   mem_ctx,
			   ldb_get_default_basedn(state->ldb),
			   &msgs,
			   attrs,
			   "samAccountName=%s$",
			   trust_user);
	if (ret > 1) {
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	if (ret == 0) {
		return NT_STATUS_OK;
	}

	uac = ldb_msg_find_attr_as_uint(msgs[0],
					"userAccountControl",
					0);
	if (!(uac & UF_INTERDOMAIN_TRUST_ACCOUNT)) {
		return NT_STATUS_OBJECT_NAME_COLLISION;
	}

	ret = ldb_delete(state->ldb, msgs[0]->dn);
	switch (ret) {
	case LDB_SUCCESS:
		break;
	case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
		return NT_STATUS_ACCESS_DENIED;
	default:
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	return NT_STATUS_OK;
}