static bool ad_unconvert_open_ad(TALLOC_CTX *mem_ctx,
				 struct vfs_handle_struct *handle,
				 struct smb_filename *smb_fname,
				 struct smb_filename *adpath,
				 files_struct **_fsp)
{
	files_struct *fsp = NULL;
	NTSTATUS status;
	int ret;

	ret = vfs_stat(handle->conn, adpath);
	if (ret == -1 && errno != ENOENT) {
		return false;
	}

	if (VALID_STAT(adpath->st)) {
		status = openat_pathref_fsp(handle->conn->cwd_fsp, adpath);
		if (!NT_STATUS_IS_OK(status)) {
			return false;
		}
	}

	status = SMB_VFS_CREATE_FILE(
		handle->conn,
		NULL,				/* req */
		adpath,
		FILE_READ_DATA|FILE_WRITE_DATA,
		FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
		FILE_OPEN_IF,
		0,				/* create_options */
		0,				/* file_attributes */
		INTERNAL_OPEN_ONLY,
		NULL,				/* lease */
		0,				/* allocation_size */
		0,				/* private_flags */
		NULL,				/* sd */
		NULL,				/* ea_list */
		&fsp,
		NULL,				/* info */
		NULL, NULL);			/* create context */
	if (!NT_STATUS_IS_OK(status)) {
		DBG_ERR("SMB_VFS_CREATE_FILE [%s] failed: %s\n",
			smb_fname_str_dbg(adpath), nt_errstr(status));
		return false;
	}

	if (fsp->fsp_name->st.st_ex_uid != smb_fname->st.st_ex_uid ||
	    fsp->fsp_name->st.st_ex_gid != smb_fname->st.st_ex_gid)
	{
		ret = SMB_VFS_FCHOWN(fsp,
				     smb_fname->st.st_ex_uid,
				     smb_fname->st.st_ex_gid);
		if (ret != 0) {
			DBG_ERR("SMB_VFS_FCHOWN [%s] failed: %s\n",
				fsp_str_dbg(fsp), nt_errstr(status));
			close_file(NULL, fsp, NORMAL_CLOSE);
			return false;
		}
	}

	*_fsp = fsp;
	return true;
}
static bool ad_unconvert_open_ad(TALLOC_CTX *mem_ctx,
				 struct vfs_handle_struct *handle,
				 struct smb_filename *smb_fname,
				 struct smb_filename *adpath,
				 files_struct **_fsp)
{
	files_struct *fsp = NULL;
	NTSTATUS status;
	int ret;

	ret = vfs_stat(handle->conn, adpath);
	if (ret == -1 && errno != ENOENT) {
		return false;
	}

	if (VALID_STAT(adpath->st)) {
		status = openat_pathref_fsp(handle->conn->cwd_fsp, adpath);
		if (!NT_STATUS_IS_OK(status)) {
			return false;
		}
	}

	status = SMB_VFS_CREATE_FILE(
		handle->conn,
		NULL,				 
		adpath,
		FILE_READ_DATA|FILE_WRITE_DATA,
		FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
		FILE_OPEN_IF,
		0,				 
		0,				 
		INTERNAL_OPEN_ONLY,
		NULL,				 
		0,				 
		0,				 
		NULL,				 
		NULL,				 
		&fsp,
		NULL,				 
		NULL, NULL);			 
	if (!NT_STATUS_IS_OK(status)) {
		DBG_ERR("SMB_VFS_CREATE_FILE [%s] failed: %s\n",
			smb_fname_str_dbg(adpath), nt_errstr(status));
		return false;
	}

	if (fsp->fsp_name->st.st_ex_uid != smb_fname->st.st_ex_uid ||
	    fsp->fsp_name->st.st_ex_gid != smb_fname->st.st_ex_gid)
	{
		ret = SMB_VFS_FCHOWN(fsp,
				     smb_fname->st.st_ex_uid,
				     smb_fname->st.st_ex_gid);
		if (ret != 0) {
			DBG_ERR("SMB_VFS_FCHOWN [%s] failed: %s\n",
				fsp_str_dbg(fsp), nt_errstr(status));
			close_file(NULL, fsp, NORMAL_CLOSE);
			return false;
		}
	}

	*_fsp = fsp;
	return true;
}