18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
*/ |
20 |
|
|
|
#include "rdesktop.h" |
|
21 |
#include "disk.h" |
#include "disk.h" |
22 |
|
|
23 |
#include <sys/types.h> |
#include <sys/types.h> |
27 |
#include <dirent.h> /* opendir, closedir, readdir */ |
#include <dirent.h> /* opendir, closedir, readdir */ |
28 |
#include <fnmatch.h> |
#include <fnmatch.h> |
29 |
#include <errno.h> /* errno */ |
#include <errno.h> /* errno */ |
30 |
|
#include <stdio.h> |
31 |
|
|
32 |
#include <utime.h> |
#include <utime.h> |
33 |
#include <time.h> /* ctime */ |
#include <time.h> /* ctime */ |
38 |
#define DIRFD(a) ((a)->DIR_FD_MEMBER_NAME) |
#define DIRFD(a) ((a)->DIR_FD_MEMBER_NAME) |
39 |
#endif |
#endif |
40 |
|
|
41 |
/* TODO: let autoconf figure out everything below... */ |
/* TODO: Fix mntent-handling for solaris |
42 |
#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) |
* #include <sys/mntent.h> */ |
43 |
#define SOLARIS |
#if (defined(HAVE_MNTENT_H) && defined(HAVE_SETMNTENT)) |
44 |
|
#include <mntent.h> |
45 |
|
#define MNTENT_PATH "/etc/mtab" |
46 |
|
#define USE_SETMNTENT |
47 |
#endif |
#endif |
48 |
|
|
49 |
#if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__)) |
#ifdef HAVE_SYS_VFS_H |
50 |
#include <sys/statvfs.h> /* solaris statvfs */ |
#include <sys/vfs.h> |
51 |
/* TODO: Fix mntent-handling for solaris/hpux |
#endif |
52 |
* #include <sys/mntent.h> */ |
|
53 |
#undef HAVE_MNTENT_H |
#ifdef HAVE_SYS_STATVFS_H |
54 |
#define MNTENT_PATH "/etc/mnttab" |
#include <sys/statvfs.h> |
55 |
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
#endif |
56 |
#define STATFS_T statvfs |
|
57 |
#define F_NAMELEN(buf) ((buf).f_namemax) |
#ifdef HAVE_SYS_STATFS_H |
58 |
|
#include <sys/statfs.h> |
59 |
|
#endif |
60 |
|
|
61 |
#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__)) |
#ifdef HAVE_SYS_PARAM_H |
62 |
#include <sys/param.h> |
#include <sys/param.h> |
63 |
|
#endif |
64 |
|
|
65 |
|
#ifdef HAVE_SYS_MOUNT_H |
66 |
#include <sys/mount.h> |
#include <sys/mount.h> |
67 |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
#endif |
68 |
|
|
69 |
|
#include "rdesktop.h" |
70 |
|
|
71 |
|
#ifdef STAT_STATFS3_OSF1 |
72 |
|
#define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf))) |
73 |
#define STATFS_T statfs |
#define STATFS_T statfs |
74 |
#define F_NAMELEN(buf) (NAME_MAX) |
#define USE_STATFS |
75 |
|
#endif |
76 |
|
|
77 |
#elif (defined(__SGI_IRIX__)) |
#ifdef STAT_STATVFS |
|
#include <sys/types.h> |
|
|
#include <sys/statvfs.h> |
|
78 |
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
79 |
#define STATFS_T statvfs |
#define STATFS_T statvfs |
80 |
#define F_NAMELEN(buf) ((buf).f_namemax) |
#define USE_STATVFS |
81 |
|
#endif |
82 |
|
|
83 |
#elif (defined(__alpha) && !defined(linux)) |
#ifdef STAT_STATVFS64 |
84 |
#include <sys/mount.h> /* osf1 statfs */ |
#define STATFS_FN(path, buf) (statvfs64(path,buf)) |
85 |
#define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf))) |
#define STATFS_T statvfs64 |
86 |
#define STATFS_T statfs |
#define USE_STATVFS |
87 |
#define F_NAMELEN(buf) (255) |
#endif |
88 |
|
|
89 |
#else |
#if (defined(STAT_STATFS2_FS_DATA) || defined(STAT_STATFS2_BSIZE) || defined(STAT_STATFS2_FSIZE)) |
|
#include <sys/vfs.h> /* linux statfs */ |
|
|
#include <mntent.h> |
|
|
#define HAVE_MNTENT_H |
|
|
#define MNTENT_PATH "/etc/mtab" |
|
90 |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
91 |
#define STATFS_T statfs |
#define STATFS_T statfs |
92 |
|
#define USE_STATFS |
93 |
|
#endif |
94 |
|
|
95 |
|
#ifdef STAT_STATFS4 |
96 |
|
#define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf),0)) |
97 |
|
#define STATFS_T statfs |
98 |
|
#define USE_STATFS |
99 |
|
#endif |
100 |
|
|
101 |
|
#if ((defined(USE_STATFS) && defined(HAVE_STRUCT_STATFS_F_NAMEMAX)) || (defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_NAMEMAX))) |
102 |
|
#define F_NAMELEN(buf) ((buf).f_namemax) |
103 |
|
#endif |
104 |
|
|
105 |
|
#if ((defined(USE_STATFS) && defined(HAVE_STRUCT_STATFS_F_NAMELEN)) || (defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_NAMELEN))) |
106 |
#define F_NAMELEN(buf) ((buf).f_namelen) |
#define F_NAMELEN(buf) ((buf).f_namelen) |
107 |
#endif |
#endif |
108 |
|
|
109 |
|
#ifndef F_NAMELEN |
110 |
|
#define F_NAMELEN(buf) (255) |
111 |
|
#endif |
112 |
|
|
113 |
|
/* Dummy statfs fallback */ |
114 |
|
#ifndef STATFS_T |
115 |
|
struct dummy_statfs_t |
116 |
|
{ |
117 |
|
long f_bfree; |
118 |
|
long f_bsize; |
119 |
|
long f_blocks; |
120 |
|
int f_namelen; |
121 |
|
int f_namemax; |
122 |
|
}; |
123 |
|
|
124 |
|
static int |
125 |
|
dummy_statfs(struct dummy_statfs_t *buf) |
126 |
|
{ |
127 |
|
buf->f_blocks = 262144; |
128 |
|
buf->f_bfree = 131072; |
129 |
|
buf->f_bsize = 512; |
130 |
|
buf->f_namelen = 255; |
131 |
|
buf->f_namemax = 255; |
132 |
|
|
133 |
|
return 0; |
134 |
|
} |
135 |
|
|
136 |
|
#define STATFS_T dummy_statfs_t |
137 |
|
#define STATFS_FN(path,buf) (dummy_statfs(buf)) |
138 |
|
#endif |
139 |
|
|
140 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
141 |
|
|
142 |
FILEINFO g_fileinfo[MAX_OPEN_FILES]; |
FILEINFO g_fileinfo[MAX_OPEN_FILES]; |
144 |
|
|
145 |
typedef struct |
typedef struct |
146 |
{ |
{ |
147 |
char name[256]; |
char name[PATH_MAX]; |
148 |
char label[256]; |
char label[PATH_MAX]; |
149 |
unsigned long serial; |
unsigned long serial; |
150 |
char type[256]; |
char type[PATH_MAX]; |
151 |
} FsInfoType; |
} FsInfoType; |
152 |
|
|
153 |
static NTSTATUS NotifyInfo(NTHANDLE handle, uint32 info_class, NOTIFY * p); |
static NTSTATUS NotifyInfo(NTHANDLE handle, uint32 info_class, NOTIFY * p); |
201 |
{ |
{ |
202 |
int ret; |
int ret; |
203 |
off_t pos; |
off_t pos; |
204 |
static const char zero; |
static const char zero = 0; |
205 |
|
|
206 |
/* Try the simple method first */ |
/* Try the simple method first */ |
207 |
if ((ret = ftruncate(fd, length)) != -1) |
if ((ret = ftruncate(fd, length)) != -1) |
209 |
return ret; |
return ret; |
210 |
} |
} |
211 |
|
|
212 |
/* |
/* |
213 |
* Some kind of error. Perhaps we were trying to grow. Retry |
* Some kind of error. Perhaps we were trying to grow. Retry |
214 |
* in a safe way. |
* in a safe way. |
215 |
*/ |
*/ |
325 |
fprintf(stderr, "share name %s truncated to %s\n", optarg, |
fprintf(stderr, "share name %s truncated to %s\n", optarg, |
326 |
g_rdpdr_device[*id].name); |
g_rdpdr_device[*id].name); |
327 |
|
|
328 |
g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); |
g_rdpdr_device[*id].local_path = (char *) xmalloc(strlen(pos2) + 1); |
329 |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
330 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_DISK; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_DISK; |
331 |
count++; |
count++; |
344 |
NTHANDLE handle; |
NTHANDLE handle; |
345 |
DIR *dirp; |
DIR *dirp; |
346 |
int flags, mode; |
int flags, mode; |
347 |
char path[256]; |
char path[PATH_MAX]; |
348 |
struct stat filestat; |
struct stat filestat; |
349 |
|
|
350 |
handle = 0; |
handle = 0; |
389 |
break; |
break; |
390 |
} |
} |
391 |
|
|
392 |
/*printf("Open: \"%s\" flags: %X, accessmask: %X sharemode: %X create disp: %X\n", path, flags_and_attributes, accessmask, sharemode, create_disposition);*/ |
/*printf("Open: \"%s\" flags: %X, accessmask: %X sharemode: %X create disp: %X\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); */ |
393 |
|
|
394 |
/* Get information about file and set that flag ourselfs */ |
/* Get information about file and set that flag ourselfs */ |
395 |
if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
491 |
g_fileinfo[handle].device_id = device_id; |
g_fileinfo[handle].device_id = device_id; |
492 |
g_fileinfo[handle].flags_and_attributes = flags_and_attributes; |
g_fileinfo[handle].flags_and_attributes = flags_and_attributes; |
493 |
g_fileinfo[handle].accessmask = accessmask; |
g_fileinfo[handle].accessmask = accessmask; |
494 |
strncpy(g_fileinfo[handle].path, path, 255); |
strncpy(g_fileinfo[handle].path, path, PATH_MAX - 1); |
495 |
g_fileinfo[handle].delete_on_close = False; |
g_fileinfo[handle].delete_on_close = False; |
496 |
g_notify_stamp = True; |
g_notify_stamp = True; |
497 |
|
|
698 |
disk_set_information(NTHANDLE handle, uint32 info_class, STREAM in, STREAM out) |
disk_set_information(NTHANDLE handle, uint32 info_class, STREAM in, STREAM out) |
699 |
{ |
{ |
700 |
uint32 length, file_attributes, ft_high, ft_low, delete_on_close; |
uint32 length, file_attributes, ft_high, ft_low, delete_on_close; |
701 |
char newname[256], fullpath[256]; |
char newname[PATH_MAX], fullpath[PATH_MAX]; |
702 |
struct fileinfo *pfinfo; |
struct fileinfo *pfinfo; |
703 |
int mode; |
int mode; |
704 |
struct stat filestat; |
struct stat filestat; |
889 |
|
|
890 |
if (memcmp(&pfinfo->notify, ¬ify, sizeof(NOTIFY))) |
if (memcmp(&pfinfo->notify, ¬ify, sizeof(NOTIFY))) |
891 |
{ |
{ |
892 |
/*printf("disk_check_notify found changed event\n");*/ |
/*printf("disk_check_notify found changed event\n"); */ |
893 |
memcpy(&pfinfo->notify, ¬ify, sizeof(NOTIFY)); |
memcpy(&pfinfo->notify, ¬ify, sizeof(NOTIFY)); |
894 |
status = STATUS_NOTIFY_ENUM_DIR; |
status = STATUS_NOTIFY_ENUM_DIR; |
895 |
} |
} |
960 |
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) |
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) |
961 |
continue; |
continue; |
962 |
p->num_entries++; |
p->num_entries++; |
963 |
fullname = xmalloc(strlen(pfinfo->path) + strlen(dp->d_name) + 2); |
fullname = (char *) xmalloc(strlen(pfinfo->path) + strlen(dp->d_name) + 2); |
964 |
sprintf(fullname, "%s/%s", pfinfo->path, dp->d_name); |
sprintf(fullname, "%s/%s", pfinfo->path, dp->d_name); |
965 |
|
|
966 |
if (!stat(fullname, &buf)) |
if (!stat(fullname, &buf)) |
980 |
{ |
{ |
981 |
|
|
982 |
static FsInfoType info; |
static FsInfoType info; |
983 |
#ifdef HAVE_MNTENT_H |
#ifdef USE_SETMNTENT |
984 |
FILE *fdfs; |
FILE *fdfs; |
985 |
struct mntent *e; |
struct mntent *e; |
986 |
#endif |
#endif |
990 |
strcpy(info.label, "RDESKTOP"); |
strcpy(info.label, "RDESKTOP"); |
991 |
strcpy(info.type, "RDPFS"); |
strcpy(info.type, "RDPFS"); |
992 |
|
|
993 |
#ifdef HAVE_MNTENT_H |
#ifdef USE_SETMNTENT |
994 |
fdfs = setmntent(MNTENT_PATH, "r"); |
fdfs = setmntent(MNTENT_PATH, "r"); |
995 |
if (!fdfs) |
if (!fdfs) |
996 |
return &info; |
return &info; |
997 |
|
|
998 |
while ((e = getmntent(fdfs))) |
while ((e = getmntent(fdfs))) |
999 |
{ |
{ |
1000 |
if (strncmp(fpath, e->mnt_dir, strlen(fpath)) == 0) |
if (str_startswith(e->mnt_dir, fpath)) |
1001 |
{ |
{ |
1002 |
strcpy(info.type, e->mnt_type); |
strcpy(info.type, e->mnt_type); |
1003 |
strcpy(info.name, e->mnt_fsname); |
strcpy(info.name, e->mnt_fsname); |
1112 |
disk_query_directory(NTHANDLE handle, uint32 info_class, char *pattern, STREAM out) |
disk_query_directory(NTHANDLE handle, uint32 info_class, char *pattern, STREAM out) |
1113 |
{ |
{ |
1114 |
uint32 file_attributes, ft_low, ft_high; |
uint32 file_attributes, ft_low, ft_high; |
1115 |
char *dirname, fullpath[256]; |
char *dirname, fullpath[PATH_MAX]; |
1116 |
DIR *pdir; |
DIR *pdir; |
1117 |
struct dirent *pdirent; |
struct dirent *pdirent; |
1118 |
struct stat fstat; |
struct stat fstat; |
1130 |
/* If a search pattern is received, remember this pattern, and restart search */ |
/* If a search pattern is received, remember this pattern, and restart search */ |
1131 |
if (pattern[0] != 0) |
if (pattern[0] != 0) |
1132 |
{ |
{ |
1133 |
strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), 64); |
strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), PATH_MAX - 1); |
1134 |
rewinddir(pdir); |
rewinddir(pdir); |
1135 |
} |
} |
1136 |
|
|