2011-08-07 07:21:42 +04:00
|
|
|
/**
|
2012-10-09 05:00:07 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-07 07:21:42 +04:00
|
|
|
* File System Virtual Channel
|
|
|
|
*
|
2012-10-09 05:00:07 +04:00
|
|
|
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-08-07 07:21:42 +04:00
|
|
|
* Copyright 2010-2011 Vic Lee
|
2012-10-09 05:00:07 +04:00
|
|
|
* Copyright 2012 Gerald Richter
|
2015-06-03 16:33:59 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-08-07 07:21:42 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-17 07:54:42 +04:00
|
|
|
#ifndef _WIN32
|
2012-03-09 14:53:32 +04:00
|
|
|
#define __USE_LARGEFILE64
|
|
|
|
#define _LARGEFILE_SOURCE
|
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
|
2011-08-17 07:54:42 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-19 17:43:04 +04:00
|
|
|
#include <errno.h>
|
2011-08-07 07:21:42 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2011-08-07 20:23:36 +04:00
|
|
|
#include <sys/stat.h>
|
2012-09-24 02:41:07 +04:00
|
|
|
|
2012-10-07 18:21:54 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-11-04 07:54:54 +04:00
|
|
|
#include <winpr/file.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-10-17 23:56:56 +04:00
|
|
|
|
2012-10-09 05:00:07 +04:00
|
|
|
#include <freerdp/channels/rdpdr.h>
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2012-11-03 04:58:58 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
#ifdef HAVE_FCNTL_H
|
2014-09-02 17:42:44 +04:00
|
|
|
#define __USE_GNU /* for O_PATH */
|
2011-08-07 07:21:42 +04:00
|
|
|
#include <fcntl.h>
|
2014-09-02 17:42:44 +04:00
|
|
|
#undef __USE_GNU
|
2011-08-07 07:21:42 +04:00
|
|
|
#endif
|
|
|
|
|
2014-08-18 12:00:34 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma comment(lib, "Shlwapi.lib")
|
|
|
|
#include <Shlwapi.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
#include "drive_file.h"
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2012-10-16 21:31:16 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4244)
|
|
|
|
#endif
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static void drive_file_fix_path(char* path)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
|
|
|
int i;
|
2012-10-07 01:49:56 +04:00
|
|
|
int length;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2014-02-10 10:06:11 +04:00
|
|
|
length = (int) strlen(path);
|
2012-10-07 01:49:56 +04:00
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2011-08-07 20:37:31 +04:00
|
|
|
if (path[i] == '\\')
|
|
|
|
path[i] = '/';
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
2012-10-07 01:49:56 +04:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
if ((length == 3) && (path[1] == ':') && (path[2] == '/'))
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
if ((length == 1) && (path[0] == '/'))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((length > 0) && (path[length - 1] == '/'))
|
|
|
|
path[length - 1] = '\0';
|
2011-08-07 20:37:31 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static char* drive_file_combine_fullpath(const char* base_path, const char* path)
|
2011-08-07 20:37:31 +04:00
|
|
|
{
|
|
|
|
char* fullpath;
|
|
|
|
|
2012-10-07 18:21:54 +04:00
|
|
|
fullpath = (char*) malloc(strlen(base_path) + strlen(path) + 1);
|
2015-06-03 16:33:59 +03:00
|
|
|
if (!fullpath)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "malloc failed!");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-07 20:37:31 +04:00
|
|
|
strcpy(fullpath, base_path);
|
|
|
|
strcat(fullpath, path);
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_file_fix_path(fullpath);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
return fullpath;
|
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static BOOL drive_file_remove_dir(const char* path)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
|
|
|
DIR* dir;
|
|
|
|
char* p;
|
2012-10-07 18:21:54 +04:00
|
|
|
struct STAT st;
|
|
|
|
struct dirent* pdirent;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL ret = TRUE;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
dir = opendir(path);
|
2012-10-02 18:57:39 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
if (dir == NULL)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
pdirent = readdir(dir);
|
2012-10-02 18:57:39 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
while (pdirent)
|
|
|
|
{
|
|
|
|
if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0)
|
|
|
|
{
|
|
|
|
pdirent = readdir(dir);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-07 18:21:54 +04:00
|
|
|
p = (char*) malloc(strlen(path) + strlen(pdirent->d_name) + 2);
|
2015-06-03 16:33:59 +03:00
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "malloc failed!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
sprintf(p, "%s/%s", path, pdirent->d_name);
|
2012-10-07 18:21:54 +04:00
|
|
|
|
2012-03-09 14:53:32 +04:00
|
|
|
if (STAT(p, &st) != 0)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
ret = FALSE;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
else if (S_ISDIR(st.st_mode))
|
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
ret = drive_file_remove_dir(p);
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
else if (unlink(p) < 0)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
ret = FALSE;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
else
|
2012-10-07 18:21:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
ret = TRUE;
|
2012-10-07 18:21:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(p);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pdirent = readdir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
2012-10-07 18:21:54 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (rmdir(path) < 0)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
ret = FALSE;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static void drive_file_set_fullpath(DRIVE_FILE* file, char* fullpath)
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(file->fullpath);
|
2011-08-07 20:23:36 +04:00
|
|
|
file->fullpath = fullpath;
|
|
|
|
file->filename = strrchr(file->fullpath, '/');
|
2012-10-02 18:57:39 +04:00
|
|
|
|
2011-08-07 20:23:36 +04:00
|
|
|
if (file->filename == NULL)
|
|
|
|
file->filename = file->fullpath;
|
|
|
|
else
|
|
|
|
file->filename += 1;
|
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static BOOL drive_file_init(DRIVE_FILE* file, UINT32 DesiredAccess, UINT32 CreateDisposition, UINT32 CreateOptions)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-03-09 21:00:56 +04:00
|
|
|
struct STAT st;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL exists;
|
2012-10-02 10:58:54 +04:00
|
|
|
#ifdef WIN32
|
2014-02-12 07:34:33 +04:00
|
|
|
const static int mode = _S_IREAD | _S_IWRITE ;
|
2012-10-02 10:58:54 +04:00
|
|
|
#else
|
2014-02-12 07:34:33 +04:00
|
|
|
const static int mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL largeFile = FALSE;
|
2012-04-18 13:52:49 +04:00
|
|
|
#endif
|
2011-08-07 07:21:42 +04:00
|
|
|
int oflag = 0;
|
|
|
|
|
2012-03-09 21:00:56 +04:00
|
|
|
if (STAT(file->fullpath, &st) == 0)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
file->is_dir = (S_ISDIR(st.st_mode) ? TRUE : FALSE);
|
2014-09-02 17:42:44 +04:00
|
|
|
if (!file->is_dir && !S_ISREG(st.st_mode))
|
|
|
|
{
|
|
|
|
file->err = EPERM;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-03-09 14:53:32 +04:00
|
|
|
#ifndef WIN32
|
2012-11-04 07:54:54 +04:00
|
|
|
if (st.st_size > (unsigned long) 0x07FFFFFFF)
|
|
|
|
largeFile = TRUE;
|
2012-04-18 13:52:49 +04:00
|
|
|
#endif
|
2012-10-09 10:31:28 +04:00
|
|
|
exists = TRUE;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
file->is_dir = ((CreateOptions & FILE_DIRECTORY_FILE) ? TRUE : FALSE);
|
2011-08-07 07:21:42 +04:00
|
|
|
if (file->is_dir)
|
|
|
|
{
|
2012-11-04 07:54:54 +04:00
|
|
|
/* Should only create the directory if the disposition allows for it */
|
2012-08-02 00:05:33 +04:00
|
|
|
if ((CreateDisposition == FILE_OPEN_IF) || (CreateDisposition == FILE_CREATE))
|
2011-10-19 17:43:04 +04:00
|
|
|
{
|
2012-11-04 07:54:54 +04:00
|
|
|
if (mkdir(file->fullpath, mode) != 0)
|
|
|
|
{
|
|
|
|
file->err = errno;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-10-19 17:43:04 +04:00
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
exists = FALSE;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
2012-03-09 14:53:32 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
if (file->is_dir)
|
|
|
|
{
|
|
|
|
file->dir = opendir(file->fullpath);
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
if (file->dir == NULL)
|
2011-10-19 17:43:04 +04:00
|
|
|
{
|
|
|
|
file->err = errno;
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-10-19 17:43:04 +04:00
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (CreateDisposition)
|
|
|
|
{
|
|
|
|
case FILE_SUPERSEDE:
|
|
|
|
oflag = O_TRUNC | O_CREAT;
|
|
|
|
break;
|
|
|
|
case FILE_OPEN:
|
|
|
|
break;
|
|
|
|
case FILE_CREATE:
|
|
|
|
oflag = O_CREAT | O_EXCL;
|
|
|
|
break;
|
|
|
|
case FILE_OPEN_IF:
|
|
|
|
oflag = O_CREAT;
|
|
|
|
break;
|
|
|
|
case FILE_OVERWRITE:
|
|
|
|
oflag = O_TRUNC;
|
|
|
|
break;
|
|
|
|
case FILE_OVERWRITE_IF:
|
|
|
|
oflag = O_TRUNC | O_CREAT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-12-31 23:03:00 +04:00
|
|
|
|
2012-11-04 07:54:54 +04:00
|
|
|
if ((CreateOptions & FILE_DELETE_ON_CLOSE) && (DesiredAccess & DELETE))
|
2011-12-31 23:03:00 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
file->delete_pending = TRUE;
|
2011-12-31 23:03:00 +04:00
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
if ((DesiredAccess & GENERIC_ALL)
|
|
|
|
|| (DesiredAccess & GENERIC_WRITE)
|
|
|
|
|| (DesiredAccess & FILE_WRITE_DATA)
|
|
|
|
|| (DesiredAccess & FILE_APPEND_DATA))
|
|
|
|
{
|
|
|
|
oflag |= O_RDWR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
oflag |= O_RDONLY;
|
|
|
|
}
|
2012-03-09 14:53:32 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
if (largeFile)
|
|
|
|
{
|
2014-02-12 07:34:33 +04:00
|
|
|
oflag |= O_LARGEFILE;
|
2012-03-09 14:53:32 +04:00
|
|
|
}
|
2014-02-12 13:45:17 +04:00
|
|
|
#else
|
|
|
|
oflag |= O_BINARY;
|
2012-03-09 14:53:32 +04:00
|
|
|
#endif
|
|
|
|
file->fd = OPEN(file->fullpath, oflag, mode);
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
if (file->fd == -1)
|
2011-10-19 17:43:04 +04:00
|
|
|
{
|
|
|
|
file->err = errno;
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-10-19 17:43:04 +04:00
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* drive_file_new(const char* base_path, const char* path, UINT32 id,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 DesiredAccess, UINT32 CreateDisposition, UINT32 CreateOptions)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2015-06-03 16:33:59 +03:00
|
|
|
file = (DRIVE_FILE*) calloc(1, sizeof(DRIVE_FILE));
|
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
file->id = id;
|
2011-11-25 20:24:47 +04:00
|
|
|
file->basepath = (char*) base_path;
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_file_set_fullpath(file, drive_file_combine_fullpath(base_path, path));
|
2011-08-07 07:21:42 +04:00
|
|
|
file->fd = -1;
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
if (!drive_file_init(file, DesiredAccess, CreateDisposition, CreateOptions))
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_file_free(file);
|
2011-08-07 07:21:42 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-02 17:42:44 +04:00
|
|
|
#if defined(__linux__) && defined(O_PATH)
|
|
|
|
if (file->fd < 0 && file->err == EACCES)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* We have no access permissions for the file or directory but if the
|
|
|
|
* peer is only interested in reading the object's attributes we can try
|
|
|
|
* to obtain a file descriptor who's only purpose is to perform
|
|
|
|
* operations that act purely at the file descriptor level.
|
|
|
|
* See open(2)
|
|
|
|
**/
|
|
|
|
{
|
|
|
|
if ((file->fd = OPEN(file->fullpath, O_PATH)) >= 0)
|
|
|
|
{
|
|
|
|
file->err = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
void drive_file_free(DRIVE_FILE* file)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
|
|
|
if (file->fd != -1)
|
|
|
|
close(file->fd);
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
if (file->dir != NULL)
|
|
|
|
closedir(file->dir);
|
|
|
|
|
|
|
|
if (file->delete_pending)
|
|
|
|
{
|
|
|
|
if (file->is_dir)
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_file_remove_dir(file->fullpath);
|
2011-08-07 07:21:42 +04:00
|
|
|
else
|
|
|
|
unlink(file->fullpath);
|
|
|
|
}
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(file->pattern);
|
|
|
|
free(file->fullpath);
|
|
|
|
free(file);
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
BOOL drive_file_seek(DRIVE_FILE* file, UINT64 Offset)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
if (file->is_dir || file->fd == -1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2012-03-09 14:53:32 +04:00
|
|
|
if (LSEEK(file->fd, Offset, SEEK_SET) == (off_t)-1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
BOOL drive_file_read(DRIVE_FILE* file, BYTE* buffer, UINT32* Length)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
ssize_t r;
|
|
|
|
|
|
|
|
if (file->is_dir || file->fd == -1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
|
|
|
r = read(file->fd, buffer, *Length);
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 09:11:52 +04:00
|
|
|
if (r < 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-11-04 07:54:54 +04:00
|
|
|
|
|
|
|
*Length = (UINT32) r;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
BOOL drive_file_write(DRIVE_FILE* file, BYTE* buffer, UINT32 Length)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
ssize_t r;
|
|
|
|
|
|
|
|
if (file->is_dir || file->fd == -1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
|
|
|
while (Length > 0)
|
|
|
|
{
|
|
|
|
r = write(file->fd, buffer, Length);
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 09:11:52 +04:00
|
|
|
if (r == -1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 09:11:52 +04:00
|
|
|
Length -= r;
|
|
|
|
buffer += r;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, wStream* output)
|
2011-08-07 11:17:06 +04:00
|
|
|
{
|
2012-03-09 14:53:32 +04:00
|
|
|
struct STAT st;
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2012-03-09 14:53:32 +04:00
|
|
|
if (STAT(file->fullpath, &st) != 0)
|
2011-08-07 11:17:06 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 11:17:06 +04:00
|
|
|
}
|
2012-11-04 07:54:54 +04:00
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
switch (FsInformationClass)
|
|
|
|
{
|
|
|
|
case FileBasicInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232094.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 36))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 36); /* Length */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_atime)); /* LastAccessTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* LastWriteTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* ChangeTime */
|
|
|
|
Stream_Write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
|
2011-08-07 15:24:29 +04:00
|
|
|
/* Reserved(4), MUST NOT be added! */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileStandardInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232088.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 22))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 22); /* Length */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* AllocationSize */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* EndOfFile */
|
|
|
|
Stream_Write_UINT32(output, st.st_nlink); /* NumberOfLinks */
|
|
|
|
Stream_Write_UINT8(output, file->delete_pending ? 1 : 0); /* DeletePending */
|
|
|
|
Stream_Write_UINT8(output, file->is_dir ? 1 : 0); /* Directory */
|
2011-08-07 15:24:29 +04:00
|
|
|
/* Reserved(2), MUST NOT be added! */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileAttributeTagInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232093.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 8))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 8); /* Length */
|
|
|
|
Stream_Write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
|
|
|
|
Stream_Write_UINT32(output, 0); /* ReparseTag */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-03-26 19:09:47 +03:00
|
|
|
/* Unhandled FsInformationClass */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 11:17:06 +04:00
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2015-03-26 19:09:47 +03:00
|
|
|
|
|
|
|
out_fail:
|
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
|
|
|
return FALSE;
|
2011-08-07 11:17:06 +04:00
|
|
|
}
|
2011-08-07 15:24:29 +04:00
|
|
|
|
2014-08-18 12:00:34 +04:00
|
|
|
int dir_empty(const char *path)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return PathIsDirectoryEmptyA(path);
|
|
|
|
#else
|
|
|
|
struct dirent *dp;
|
|
|
|
int empty = 1;
|
|
|
|
|
|
|
|
DIR *dir = opendir(path);
|
|
|
|
if (dir == NULL) //Not a directory or doesn't exist
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
while ((dp = readdir(dir)) != NULL) {
|
|
|
|
if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
|
|
|
|
continue; /* Skip . and .. */
|
|
|
|
|
|
|
|
empty = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
return empty;
|
|
|
|
#endif
|
|
|
|
}
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UINT32 Length, wStream* input)
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
2013-01-16 04:14:03 +04:00
|
|
|
char* s = NULL;
|
2014-02-12 07:34:33 +04:00
|
|
|
mode_t m;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 size;
|
2012-12-17 08:34:07 +04:00
|
|
|
int status;
|
2011-11-25 20:24:47 +04:00
|
|
|
char* fullpath;
|
2012-03-09 14:53:32 +04:00
|
|
|
struct STAT st;
|
2015-02-02 19:48:54 +03:00
|
|
|
#if defined(__linux__) && !defined(ANDROID) || defined(sun)
|
2014-08-07 06:06:01 +04:00
|
|
|
struct timespec tv[2];
|
2014-08-07 14:47:33 +04:00
|
|
|
#else
|
2011-08-07 20:23:36 +04:00
|
|
|
struct timeval tv[2];
|
2014-08-07 06:06:01 +04:00
|
|
|
#endif
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT64 LastWriteTime;
|
|
|
|
UINT32 FileAttributes;
|
|
|
|
UINT32 FileNameLength;
|
2011-08-07 20:23:36 +04:00
|
|
|
|
2012-10-16 21:31:16 +04:00
|
|
|
m = 0;
|
|
|
|
|
2011-08-07 20:23:36 +04:00
|
|
|
switch (FsInformationClass)
|
|
|
|
{
|
|
|
|
case FileBasicInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232094.aspx */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT64(input); /* CreationTime */
|
|
|
|
Stream_Seek_UINT64(input); /* LastAccessTime */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT64(input, LastWriteTime);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT64(input); /* ChangeTime */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(input, FileAttributes);
|
2011-08-07 20:23:36 +04:00
|
|
|
|
2012-03-09 14:53:32 +04:00
|
|
|
if (FSTAT(file->fd, &st) != 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-11-25 20:24:47 +04:00
|
|
|
|
2011-08-07 20:23:36 +04:00
|
|
|
tv[0].tv_sec = st.st_atime;
|
|
|
|
tv[1].tv_sec = (LastWriteTime > 0 ? FILE_TIME_RDP_TO_SYSTEM(LastWriteTime) : st.st_mtime);
|
2012-10-02 10:58:54 +04:00
|
|
|
#ifndef WIN32
|
2014-02-12 07:34:33 +04:00
|
|
|
/* TODO on win32 */
|
2013-04-25 18:30:33 +04:00
|
|
|
#ifdef ANDROID
|
2014-08-07 06:06:01 +04:00
|
|
|
tv[0].tv_usec = 0;
|
|
|
|
tv[1].tv_usec = 0;
|
2013-04-25 18:30:33 +04:00
|
|
|
utimes(file->fullpath, tv);
|
2015-02-02 19:48:54 +03:00
|
|
|
#elif defined (__linux__) || defined (sun)
|
2014-08-07 06:06:01 +04:00
|
|
|
tv[0].tv_nsec = 0;
|
|
|
|
tv[1].tv_nsec = 0;
|
|
|
|
futimens(file->fd, tv);
|
2013-04-25 18:30:33 +04:00
|
|
|
#else
|
2014-08-07 14:47:33 +04:00
|
|
|
tv[0].tv_usec = 0;
|
|
|
|
tv[1].tv_usec = 0;
|
2013-04-25 18:30:33 +04:00
|
|
|
futimes(file->fd, tv);
|
|
|
|
#endif
|
2011-08-07 20:23:36 +04:00
|
|
|
|
|
|
|
if (FileAttributes > 0)
|
|
|
|
{
|
|
|
|
m = st.st_mode;
|
|
|
|
if ((FileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
|
|
|
|
m |= S_IWUSR;
|
|
|
|
else
|
|
|
|
m &= ~S_IWUSR;
|
|
|
|
if (m != st.st_mode)
|
|
|
|
fchmod(file->fd, st.st_mode);
|
|
|
|
}
|
2012-10-02 10:58:54 +04:00
|
|
|
#endif
|
2014-02-12 07:34:33 +04:00
|
|
|
break;
|
2011-08-07 20:23:36 +04:00
|
|
|
|
|
|
|
case FileEndOfFileInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232067.aspx */
|
|
|
|
case FileAllocationInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232076.aspx */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT64(input, size);
|
2014-05-10 17:50:36 +04:00
|
|
|
#ifndef _WIN32
|
2011-08-10 01:42:10 +04:00
|
|
|
if (ftruncate(file->fd, size) != 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-02-12 13:52:28 +04:00
|
|
|
#endif
|
2011-08-07 20:23:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileDispositionInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232098.aspx */
|
2011-12-31 23:03:00 +04:00
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc241371.aspx */
|
2014-08-18 12:00:34 +04:00
|
|
|
if (file->is_dir && !dir_empty(file->fullpath))
|
|
|
|
break;
|
|
|
|
|
2011-12-31 23:03:00 +04:00
|
|
|
if (Length)
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(input, file->delete_pending);
|
2011-12-31 23:03:00 +04:00
|
|
|
else
|
|
|
|
file->delete_pending = 1;
|
2011-08-07 20:23:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRenameInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232085.aspx */
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(input); /* ReplaceIfExists */
|
|
|
|
Stream_Seek_UINT8(input); /* RootDirectory */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(input, FileNameLength);
|
2012-09-24 02:41:07 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(input),
|
2012-12-17 08:34:07 +04:00
|
|
|
FileNameLength / 2, &s, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (status < 1)
|
2015-06-03 16:33:59 +03:00
|
|
|
if (!(s = (char*) calloc(1, 1)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-24 10:29:12 +04:00
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
fullpath = drive_file_combine_fullpath(file->basepath, s);
|
2015-06-03 16:33:59 +03:00
|
|
|
if (!fullpath)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drive_file_combine_fullpath failed!");
|
2015-08-28 12:01:34 +03:00
|
|
|
free (s);
|
2015-06-03 16:33:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-09 07:21:26 +04:00
|
|
|
free(s);
|
2011-08-07 20:23:36 +04:00
|
|
|
|
2014-02-12 14:13:42 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (file->fd)
|
|
|
|
close(file->fd);
|
|
|
|
#endif
|
2014-02-12 07:34:33 +04:00
|
|
|
if (rename(file->fullpath, fullpath) == 0)
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_file_set_fullpath(file, fullpath);
|
2014-02-12 14:13:42 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
file->fd = OPEN(fullpath, O_RDWR | O_BINARY);
|
|
|
|
#endif
|
2011-08-07 20:23:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(fullpath);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 20:23:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 20:23:36 +04:00
|
|
|
}
|
2011-11-25 20:24:47 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-07 20:23:36 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYTE InitialQuery,
|
2013-03-21 23:19:33 +04:00
|
|
|
const char* path, wStream* output)
|
2011-08-07 15:24:29 +04:00
|
|
|
{
|
2012-09-24 03:49:13 +04:00
|
|
|
int length;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL ret;
|
2012-09-24 03:49:13 +04:00
|
|
|
WCHAR* ent_path;
|
|
|
|
struct STAT st;
|
|
|
|
struct dirent* ent;
|
2011-08-07 15:24:29 +04:00
|
|
|
|
2011-12-06 07:04:27 +04:00
|
|
|
if (!file->dir)
|
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
|
|
|
Stream_Write_UINT8(output, 0); /* Padding */
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-12-06 07:04:27 +04:00
|
|
|
}
|
2011-08-07 15:24:29 +04:00
|
|
|
|
|
|
|
if (InitialQuery != 0)
|
|
|
|
{
|
|
|
|
rewinddir(file->dir);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(file->pattern);
|
2011-12-06 07:04:27 +04:00
|
|
|
|
|
|
|
if (path[0])
|
2015-06-03 16:33:59 +03:00
|
|
|
{
|
|
|
|
if (!(file->pattern = _strdup(strrchr(path, '\\') + 1)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "_strdup failed!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 07:04:27 +04:00
|
|
|
else
|
|
|
|
file->pattern = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file->pattern)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ent = readdir(file->dir);
|
2012-09-24 02:41:07 +04:00
|
|
|
|
2011-12-06 07:04:27 +04:00
|
|
|
if (ent == NULL)
|
|
|
|
continue;
|
|
|
|
|
2012-11-04 07:54:54 +04:00
|
|
|
if (FilePatternMatchA(ent->d_name, file->pattern))
|
2011-12-06 07:04:27 +04:00
|
|
|
break;
|
2012-11-04 07:54:54 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
while (ent);
|
2011-12-06 07:04:27 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ent = readdir(file->dir);
|
2011-08-07 15:24:29 +04:00
|
|
|
}
|
|
|
|
|
2013-10-17 23:56:56 +04:00
|
|
|
if (!ent)
|
2011-08-07 15:24:29 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
|
|
|
Stream_Write_UINT8(output, 0); /* Padding */
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 15:24:29 +04:00
|
|
|
}
|
|
|
|
|
2012-03-09 14:53:32 +04:00
|
|
|
memset(&st, 0, sizeof(struct STAT));
|
2012-09-24 03:49:13 +04:00
|
|
|
ent_path = (WCHAR*) malloc(strlen(file->fullpath) + strlen(ent->d_name) + 2);
|
2015-06-03 16:33:59 +03:00
|
|
|
if (!ent_path)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "malloc failed!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-09-24 03:49:13 +04:00
|
|
|
sprintf((char*) ent_path, "%s/%s", file->fullpath, ent->d_name);
|
2012-09-24 02:41:07 +04:00
|
|
|
|
2012-09-24 03:49:13 +04:00
|
|
|
if (STAT((char*) ent_path, &st) != 0)
|
2011-08-07 15:24:29 +04:00
|
|
|
{
|
2013-10-17 23:56:56 +04:00
|
|
|
|
2011-08-07 15:24:29 +04:00
|
|
|
}
|
2012-03-09 14:53:32 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(ent_path);
|
2013-01-11 00:30:32 +04:00
|
|
|
ent_path = NULL;
|
2011-12-06 20:03:24 +04:00
|
|
|
|
2013-10-23 14:16:27 +04:00
|
|
|
length = ConvertToUnicode(sys_code_page, 0, ent->d_name, -1, &ent_path, 0) * 2;
|
2011-08-07 15:24:29 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
ret = TRUE;
|
2012-09-24 03:49:13 +04:00
|
|
|
|
2011-08-07 15:24:29 +04:00
|
|
|
switch (FsInformationClass)
|
|
|
|
{
|
|
|
|
case FileDirectoryInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232097.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 64 + length))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 64 + length); /* Length */
|
|
|
|
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
|
|
|
|
Stream_Write_UINT32(output, 0); /* FileIndex */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_atime)); /* LastAccessTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* LastWriteTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* ChangeTime */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* EndOfFile */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* AllocationSize */
|
|
|
|
Stream_Write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
|
|
|
|
Stream_Write_UINT32(output, length); /* FileNameLength */
|
|
|
|
Stream_Write(output, ent_path, length);
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFullDirectoryInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232068.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 68 + length))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 68 + length); /* Length */
|
|
|
|
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
|
|
|
|
Stream_Write_UINT32(output, 0); /* FileIndex */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_atime)); /* LastAccessTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* LastWriteTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* ChangeTime */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* EndOfFile */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* AllocationSize */
|
|
|
|
Stream_Write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
|
|
|
|
Stream_Write_UINT32(output, length); /* FileNameLength */
|
|
|
|
Stream_Write_UINT32(output, 0); /* EaSize */
|
|
|
|
Stream_Write(output, ent_path, length);
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileBothDirectoryInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232095.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 93 + length))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 93 + length); /* Length */
|
|
|
|
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
|
|
|
|
Stream_Write_UINT32(output, 0); /* FileIndex */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_atime)); /* LastAccessTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* LastWriteTime */
|
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* ChangeTime */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* EndOfFile */
|
|
|
|
Stream_Write_UINT64(output, st.st_size); /* AllocationSize */
|
|
|
|
Stream_Write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
|
|
|
|
Stream_Write_UINT32(output, length); /* FileNameLength */
|
|
|
|
Stream_Write_UINT32(output, 0); /* EaSize */
|
|
|
|
Stream_Write_UINT8(output, 0); /* ShortNameLength */
|
2011-08-07 15:24:29 +04:00
|
|
|
/* Reserved(1), MUST NOT be added! */
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Zero(output, 24); /* ShortName */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(output, ent_path, length);
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileNamesInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232077.aspx */
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(output, 4 + 12 + length))
|
2015-03-26 19:09:47 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 12 + length); /* Length */
|
|
|
|
Stream_Write_UINT32(output, 0); /* NextEntryOffset */
|
|
|
|
Stream_Write_UINT32(output, 0); /* FileIndex */
|
|
|
|
Stream_Write_UINT32(output, length); /* FileNameLength */
|
|
|
|
Stream_Write(output, ent_path, length);
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-03-26 19:09:47 +03:00
|
|
|
/* Unhandled FsInformationClass */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
|
|
|
Stream_Write_UINT8(output, 0); /* Padding */
|
2012-10-09 10:31:28 +04:00
|
|
|
ret = FALSE;
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(ent_path);
|
2011-08-07 15:24:29 +04:00
|
|
|
return ret;
|
2015-03-26 19:09:47 +03:00
|
|
|
|
|
|
|
out_fail:
|
|
|
|
free(ent_path);
|
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
|
|
|
Stream_Write_UINT8(output, 0); /* Padding */
|
|
|
|
return FALSE;
|
2011-08-07 15:24:29 +04:00
|
|
|
}
|
2012-10-16 21:31:16 +04:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|