24 |
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 |
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 |
25 |
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 |
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 |
26 |
#define FILE_ATTRIBUTE_DEVICE 0x00000040 |
#define FILE_ATTRIBUTE_DEVICE 0x00000040 |
27 |
|
#define FILE_ATTRIBUTE_UNKNOWNXXX0 0x00000060 /* ??? ACTION i.e. 0x860 == compress this file ? */ |
28 |
#define FILE_ATTRIBUTE_NORMAL 0x00000080 |
#define FILE_ATTRIBUTE_NORMAL 0x00000080 |
29 |
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 |
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 |
30 |
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 |
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 |
34 |
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 |
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 |
35 |
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 |
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 |
36 |
|
|
37 |
|
#define FILE_FLAG_OPEN_NO_RECALL 0x00100000 |
38 |
|
#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000 |
39 |
|
#define FILE_FLAG_POSIX_SEMANTICS 0x01000000 |
40 |
|
#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000 /* sometimes used to create a directory */ |
41 |
|
#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000 |
42 |
|
#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 |
43 |
|
#define FILE_FLAG_RANDOM_ACCESS 0x10000000 |
44 |
|
#define FILE_FLAG_NO_BUFFERING 0x20000000 |
45 |
|
#define FILE_FLAG_OVERLAPPED 0x40000000 |
46 |
|
#define FILE_FLAG_WRITE_THROUGH 0x80000000 |
47 |
|
|
48 |
|
#define FILE_SHARE_READ 0x01 |
49 |
|
#define FILE_SHARE_WRITE 0x02 |
50 |
|
#define FILE_SHARE_DELETE 0x04 |
51 |
|
|
52 |
#define FILE_BASIC_INFORMATION 0x04 |
#define FILE_BASIC_INFORMATION 0x04 |
53 |
#define FILE_STANDARD_INFORMATION 0x05 |
#define FILE_STANDARD_INFORMATION 0x05 |
54 |
|
|
80 |
|
|
81 |
#define MAX_OPEN_FILES 0x100 |
#define MAX_OPEN_FILES 0x100 |
82 |
|
|
83 |
|
#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) |
84 |
|
#define SOLARIS |
85 |
|
#endif |
86 |
|
|
87 |
|
#ifdef SOLARIS |
88 |
|
#define DIRFD(a) ((a)->dd_fd) |
89 |
|
#else |
90 |
|
#define DIRFD(a) (dirfd(a)) |
91 |
|
#endif |
92 |
|
|
93 |
#include <sys/types.h> |
#include <sys/types.h> |
94 |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
#include <sys/vfs.h> /* linux statfs */ |
|
95 |
#include <unistd.h> |
#include <unistd.h> |
96 |
#include <fcntl.h> /* open, close */ |
#include <fcntl.h> /* open, close */ |
97 |
#include <dirent.h> /* opendir, closedir, readdir */ |
#include <dirent.h> /* opendir, closedir, readdir */ |
98 |
#include <fnmatch.h> |
#include <fnmatch.h> |
99 |
#include <errno.h> /* errno */ |
#include <errno.h> /* errno */ |
100 |
|
|
101 |
|
#if defined(SOLARIS) |
102 |
|
#include <sys/statvfs.h> /* solaris statvfs */ |
103 |
|
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
104 |
|
#define STATFS_T statvfs |
105 |
|
#define F_NAMELEN(buf) ((buf).f_namemax) |
106 |
|
|
107 |
|
#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) |
108 |
|
#include <sys/param.h> |
109 |
|
#include <sys/mount.h> |
110 |
|
#define STATFS_FN(path, buf) (statfs(path,buf)) |
111 |
|
#define STATFS_T statfs |
112 |
|
#define F_NAMELEN(buf) (NAME_MAX) |
113 |
|
|
114 |
|
#else |
115 |
|
#include <sys/vfs.h> /* linux statfs */ |
116 |
|
#define STATFS_FN(path, buf) (statfs(path,buf)) |
117 |
|
#define STATFS_T statfs |
118 |
|
#define F_NAMELEN(buf) ((buf).f_namelen) |
119 |
|
#endif |
120 |
|
|
121 |
#include "rdesktop.h" |
#include "rdesktop.h" |
122 |
|
|
123 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
162 |
pos2 = next_arg(optarg, '='); |
pos2 = next_arg(optarg, '='); |
163 |
strcpy(g_rdpdr_device[*id].name, optarg); |
strcpy(g_rdpdr_device[*id].name, optarg); |
164 |
|
|
165 |
toupper(g_rdpdr_device[*id].name); |
toupper_str(g_rdpdr_device[*id].name); |
166 |
|
|
167 |
/* add trailing colon to name. */ |
/* add trailing colon to name. */ |
168 |
strcat(g_rdpdr_device[*id].name, ":"); |
strcat(g_rdpdr_device[*id].name, ":"); |
179 |
return count; |
return count; |
180 |
} |
} |
181 |
|
|
182 |
/* Opens of creates a file or directory */ |
/* Opens or creates a file or directory */ |
183 |
NTSTATUS |
NTSTATUS |
184 |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
185 |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
197 |
if (filename[strlen(filename) - 1] == '/') |
if (filename[strlen(filename) - 1] == '/') |
198 |
filename[strlen(filename) - 1] = 0; |
filename[strlen(filename) - 1] = 0; |
199 |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
|
//printf("Open: %s\n", path); |
|
200 |
|
|
201 |
switch (create_disposition) |
switch (create_disposition) |
202 |
{ |
{ |
231 |
break; |
break; |
232 |
} |
} |
233 |
|
|
234 |
|
//printf("Open: \"%s\" flags: %u, accessmask: %u sharemode: %u create disp: %u\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); |
235 |
|
|
236 |
|
/* since we can't trust the FILE_DIRECTORY_FILE flag */ |
237 |
|
/* we need to double check that the file isn't a dir */ |
238 |
|
struct stat filestat; |
239 |
|
|
240 |
|
// Get information about file and set that flag ourselfs |
241 |
|
if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
242 |
|
flags_and_attributes |= FILE_DIRECTORY_FILE; |
243 |
|
|
244 |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
245 |
{ |
{ |
246 |
if (flags & O_CREAT) |
if (flags & O_CREAT) |
267 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
268 |
} |
} |
269 |
} |
} |
270 |
handle = dirfd(dirp); |
handle = DIRFD(dirp); |
271 |
} |
} |
272 |
else |
else |
273 |
{ |
{ |
274 |
|
|
275 |
if (accessmask & GENERIC_ALL |
if (accessmask & GENERIC_ALL |
276 |
|| (accessmask & GENERIC_READ && accessmask & GENERIC_WRITE)) |
|| (accessmask & GENERIC_READ && accessmask & GENERIC_WRITE)) |
277 |
{ |
{ |
298 |
case ENOENT: |
case ENOENT: |
299 |
|
|
300 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
|
|
|
301 |
default: |
default: |
302 |
|
|
303 |
perror("open"); |
perror("open"); |
304 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
305 |
} |
} |
306 |
} |
} |
307 |
|
|
308 |
|
/* all read and writes of files should be non blocking */ |
309 |
|
if (fcntl(handle, F_SETFL, O_NONBLOCK) == -1) |
310 |
|
perror("fcntl"); |
311 |
} |
} |
312 |
|
|
313 |
if (handle >= MAX_OPEN_FILES) |
if (handle >= MAX_OPEN_FILES) |
352 |
{ |
{ |
353 |
int n; |
int n; |
354 |
|
|
355 |
|
/* browsing dir ???? */ |
356 |
|
/* each request is 24 bytes */ |
357 |
|
if (g_fileinfo[handle].flags_and_attributes & FILE_DIRECTORY_FILE) |
358 |
|
{ |
359 |
|
*result = 0; |
360 |
|
return STATUS_SUCCESS; |
361 |
|
} |
362 |
|
|
363 |
if (offset) |
if (offset) |
364 |
lseek(handle, offset, SEEK_SET); |
lseek(handle, offset, SEEK_SET); |
365 |
n = read(handle, data, length); |
n = read(handle, data, length); |
543 |
disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) |
disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) |
544 |
{ |
{ |
545 |
char *volume, *fs_type; |
char *volume, *fs_type; |
546 |
struct statfs stat_fs; |
struct STATFS_T stat_fs; |
547 |
struct fileinfo *pfinfo; |
struct fileinfo *pfinfo; |
548 |
|
|
549 |
pfinfo = &(g_fileinfo[handle]); |
pfinfo = &(g_fileinfo[handle]); |
550 |
volume = "RDESKTOP"; |
volume = "RDESKTOP"; |
551 |
fs_type = "RDPFS"; |
fs_type = "RDPFS"; |
552 |
|
|
553 |
if (statfs(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ |
if (STATFS_FN(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ |
554 |
{ |
{ |
555 |
perror("statfs"); |
perror("statfs"); |
556 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
581 |
case 5: /* FileFsAttributeInformation */ |
case 5: /* FileFsAttributeInformation */ |
582 |
|
|
583 |
out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED); /* fs attributes */ |
out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED); /* fs attributes */ |
584 |
out_uint32_le(out, stat_fs.f_namelen); /* max length of filename */ |
out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */ |
585 |
out_uint32_le(out, 2 * strlen(fs_type)); /* length of fs_type */ |
out_uint32_le(out, 2 * strlen(fs_type)); /* length of fs_type */ |
586 |
rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2); |
rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2); |
587 |
break; |
break; |
640 |
|
|
641 |
// Get information for directory entry |
// Get information for directory entry |
642 |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
643 |
/* JIF |
/* JIF |
644 |
printf("Stat: %s\n", fullpath); */ |
printf("Stat: %s\n", fullpath); */ |
645 |
if (stat(fullpath, &fstat)) |
if (stat(fullpath, &fstat)) |
646 |
{ |
{ |