~ubuntu-branches/ubuntu/precise/virtualbox/precise-updates

« back to all changes in this revision

Viewing changes to src/VBox/RDP/client/disk.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-07-04 13:02:31 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110704130231-l843es6wqhx614n7
Tags: 4.0.10-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Add the Modaliases control field manually for maximum backportability.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- c-basic-offset: 8 -*-
2
2
   rdesktop: A Remote Desktop Protocol client.
3
3
   Disk Redirection
4
 
   Copyright (C) Jeroen Meijer 2003-2007
 
4
   Copyright (C) Jeroen Meijer <jeroen@oldambt7.com> 2003-2008
 
5
   Copyright 2003-2011 Peter Astrand <astrand@cendio.se> for Cendio AB
5
6
 
6
 
   This program is free software; you can redistribute it and/or modify
 
7
   This program is free software: you can redistribute it and/or modify
7
8
   it under the terms of the GNU General Public License as published by
8
 
   the Free Software Foundation; either version 2 of the License, or
 
9
   the Free Software Foundation, either version 3 of the License, or
9
10
   (at your option) any later version.
10
11
 
11
12
   This program is distributed in the hope that it will be useful,
14
15
   GNU General Public License for more details.
15
16
 
16
17
   You should have received a copy of the GNU General Public License
17
 
   along with this program; if not, write to the Free Software
18
 
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
*/
20
20
 
21
21
/*
369
369
        sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename);
370
370
#endif
371
371
 
 
372
        /* Protect against mailicous servers:
 
373
           somelongpath/..     not allowed
 
374
           somelongpath/../b   not allowed
 
375
           somelongpath/..b    in principle ok, but currently not allowed
 
376
           somelongpath/b..    ok
 
377
           somelongpath/b..b   ok
 
378
           somelongpath/b../c  ok
 
379
         */
 
380
        if (strstr(path, "/.."))
 
381
        {
 
382
                return RD_STATUS_ACCESS_DENIED;
 
383
        }
 
384
 
372
385
        switch (create_disposition)
373
386
        {
374
387
                case CREATE_ALWAYS:
493
506
        {
494
507
                error("Maximum number of open files (%s) reached. Increase MAX_OPEN_FILES!\n",
495
508
                      handle);
496
 
                exit(1);
 
509
                exit(EX_SOFTWARE);
497
510
        }
498
511
 
499
512
        if (dirp)
713
726
RD_NTSTATUS
714
727
disk_set_information(RD_NTHANDLE handle, uint32 info_class, STREAM in, STREAM out)
715
728
{
716
 
        uint32 length, file_attributes, ft_high, ft_low, delete_on_close;
 
729
        uint32 length, file_attributes, ft_high, ft_low;
717
730
        char newname[PATH_MAX], fullpath[PATH_MAX];
718
731
        struct fileinfo *pfinfo;
719
732
        int mode;
848
861
                           the delete. See
849
862
                           http://www.osronline.com/article.cfm?article=245. */
850
863
 
851
 
                        in_uint32_le(in, delete_on_close);
852
 
 
853
 
                        if (delete_on_close ||
854
 
                            (pfinfo->
855
 
                             accessmask & (FILE_DELETE_ON_CLOSE | FILE_COMPLETE_IF_OPLOCKED)))
 
864
                        /* FileDispositionInformation always sets delete_on_close to true.
 
865
                           "STREAM in" includes Length(4bytes) , Padding(24bytes) and SetBuffer(zero byte).
 
866
                           Length is always set to zero.
 
867
                           [MS-RDPEFS] http://msdn.microsoft.com/en-us/library/cc241305%28PROT.10%29.aspx
 
868
                           - 2.2.3.3.9 Server Drive Set Information Request
 
869
                         */
 
870
                        in_uint8s(in, 4);       /* length of SetBuffer */
 
871
                        in_uint8s(in, 24);      /* padding */
 
872
 
 
873
 
 
874
                        if ((pfinfo->accessmask &
 
875
                             (FILE_DELETE_ON_CLOSE | FILE_COMPLETE_IF_OPLOCKED)))
856
876
                        {
 
877
                                /* if file exists in directory , necessary to return RD_STATUS_DIRECTORY_NOT_EMPTY with win2008
 
878
                                   [MS-RDPEFS] http://msdn.microsoft.com/en-us/library/cc241305%28PROT.10%29.aspx
 
879
                                   - 2.2.3.3.9 Server Drive Set Information Request
 
880
                                   - 2.2.3.4.9 Client Drive Set Information Response
 
881
                                   [MS-FSCC] http://msdn.microsoft.com/en-us/library/cc231987%28PROT.10%29.aspx
 
882
                                   - 2.4.11 FileDispositionInformation
 
883
                                   [FSBO] http://msdn.microsoft.com/en-us/library/cc246487%28PROT.13%29.aspx
 
884
                                   - 4.3.2 Set Delete-on-close using FileDispositionInformation Information Class (IRP_MJ_SET_INFORMATION)
 
885
                                 */
 
886
                                if (pfinfo->pdir)
 
887
                                {
 
888
                                        DIR *dp = opendir(pfinfo->path);
 
889
                                        struct dirent *dir;
 
890
 
 
891
                                        while ((dir = readdir(dp)) != NULL)
 
892
                                        {
 
893
                                                if (strcmp(dir->d_name, ".") != 0
 
894
                                                    && strcmp(dir->d_name, "..") != 0)
 
895
                                                {
 
896
                                                        closedir(dp);
 
897
                                                        return RD_STATUS_DIRECTORY_NOT_EMPTY;
 
898
                                                }
 
899
                                        }
 
900
                                        closedir(dp);
 
901
                                }
 
902
 
857
903
                                pfinfo->delete_on_close = True;
858
904
                        }
859
905
 
1105
1151
                        out_uint32_le(out, 0x200);      /* Bytes per sector */
1106
1152
                        break;
1107
1153
 
 
1154
                case FileFsFullSizeInformation:
 
1155
 
 
1156
                        out_uint32_le(out, stat_fs.f_blocks);   /* Total allocation units low */
 
1157
                        out_uint32_le(out, 0);  /* Total allocation units high */
 
1158
                        out_uint32_le(out, stat_fs.f_blocks);   /* Caller allocation units low */
 
1159
                        out_uint32_le(out, 0);  /* Caller allocation units high */
 
1160
                        out_uint32_le(out, stat_fs.f_bfree);    /* Available allocation units */
 
1161
                        out_uint32_le(out, 0);  /* Available allowcation units */
 
1162
                        out_uint32_le(out, stat_fs.f_bsize / 0x200);    /* Sectors per allocation unit */
 
1163
                        out_uint32_le(out, 0x200);      /* Bytes per sector */
 
1164
                        break;
 
1165
 
1108
1166
                case FileFsAttributeInformation:
1109
1167
 
1110
1168
                        out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED);   /* fs attributes */
1117
1175
                case FileFsLabelInformation:
1118
1176
                case FileFsDeviceInformation:
1119
1177
                case FileFsControlInformation:
1120
 
                case FileFsFullSizeInformation:
1121
1178
                case FileFsObjectIdInformation:
1122
1179
                case FileFsMaximumInformation:
1123
1180
 
1144
1201
        dirname = pfinfo->path;
1145
1202
        file_attributes = 0;
1146
1203
 
 
1204
 
1147
1205
        switch (info_class)
1148
1206
        {
1149
1207
                case FileBothDirectoryInformation:
 
1208
                case FileDirectoryInformation:
 
1209
                case FileFullDirectoryInformation:
 
1210
                case FileNamesInformation:
1150
1211
 
1151
1212
                        /* If a search pattern is received, remember this pattern, and restart search */
1152
1213
                        if (pattern[0] != 0)
1199
1260
                                file_attributes |= FILE_ATTRIBUTE_READONLY;
1200
1261
 
1201
1262
                        /* Return requested information */
1202
 
                        out_uint8s(out, 8);     /* unknown zero */
1203
 
 
1204
 
                        seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,
1205
 
                                                       &ft_low);
1206
 
                        out_uint32_le(out, ft_low);     /* create time */
1207
 
                        out_uint32_le(out, ft_high);
1208
 
 
1209
 
                        seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);
1210
 
                        out_uint32_le(out, ft_low);     /* last_access_time */
1211
 
                        out_uint32_le(out, ft_high);
1212
 
 
1213
 
                        seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);
1214
 
                        out_uint32_le(out, ft_low);     /* last_write_time */
1215
 
                        out_uint32_le(out, ft_high);
1216
 
 
1217
 
                        seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);
1218
 
                        out_uint32_le(out, ft_low);     /* change_write_time */
1219
 
                        out_uint32_le(out, ft_high);
1220
 
 
1221
 
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
1222
 
                        out_uint32_le(out, 0);  /* filesize high */
1223
 
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
1224
 
                        out_uint32_le(out, 0);  /* filesize high */
1225
 
                        out_uint32_le(out, file_attributes);
1226
 
                        out_uint8(out, 2 * strlen(pdirent->d_name) + 2);        /* unicode length */
1227
 
                        out_uint8s(out, 7);     /* pad? */
1228
 
                        out_uint8(out, 0);      /* 8.3 file length */
1229
 
                        out_uint8s(out, 2 * 12);        /* 8.3 unicode length */
1230
 
                        rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
1231
 
                        break;
1232
 
 
1233
 
                default:
1234
 
                        /* FIXME: Support FileDirectoryInformation,
1235
 
                           FileFullDirectoryInformation, and
1236
 
                           FileNamesInformation */
 
1263
                        out_uint32_le(out, 0);  /* NextEntryOffset */
 
1264
                        out_uint32_le(out, 0);  /* FileIndex zero */
 
1265
                        break;
 
1266
 
 
1267
                default:
 
1268
                        unimpl("IRP Query Directory sub: 0x%x\n", info_class);
 
1269
                        return RD_STATUS_INVALID_PARAMETER;
 
1270
        }
 
1271
 
 
1272
        switch (info_class)
 
1273
        {
 
1274
                case FileBothDirectoryInformation:
 
1275
 
 
1276
                        seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,
 
1277
                                                       &ft_low);
 
1278
                        out_uint32_le(out, ft_low);     /* create time */
 
1279
                        out_uint32_le(out, ft_high);
 
1280
 
 
1281
                        seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);
 
1282
                        out_uint32_le(out, ft_low);     /* last_access_time */
 
1283
                        out_uint32_le(out, ft_high);
 
1284
 
 
1285
                        seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);
 
1286
                        out_uint32_le(out, ft_low);     /* last_write_time */
 
1287
                        out_uint32_le(out, ft_high);
 
1288
 
 
1289
                        seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);
 
1290
                        out_uint32_le(out, ft_low);     /* change_write_time */
 
1291
                        out_uint32_le(out, ft_high);
 
1292
 
 
1293
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
 
1294
                        out_uint32_le(out, 0);  /* filesize high */
 
1295
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
 
1296
                        out_uint32_le(out, 0);  /* filesize high */
 
1297
                        out_uint32_le(out, file_attributes);    /* FileAttributes */
 
1298
                        out_uint32_le(out, 2 * strlen(pdirent->d_name) + 2);    /* unicode length */
 
1299
                        out_uint32_le(out, 0);  /* EaSize */
 
1300
                        out_uint8(out, 0);      /* ShortNameLength */
 
1301
                        /* this should be correct according to MS-FSCC specification
 
1302
                           but it only works when commented out... */
 
1303
                        /* out_uint8(out, 0); *//* Reserved/Padding */
 
1304
                        out_uint8s(out, 2 * 12);        /* ShortName (8.3 name) */
 
1305
                        rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
 
1306
                        break;
 
1307
 
 
1308
 
 
1309
                case FileDirectoryInformation:
 
1310
 
 
1311
                        seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,
 
1312
                                                       &ft_low);
 
1313
                        out_uint32_le(out, ft_low);     /* create time */
 
1314
                        out_uint32_le(out, ft_high);
 
1315
 
 
1316
                        seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);
 
1317
                        out_uint32_le(out, ft_low);     /* last_access_time */
 
1318
                        out_uint32_le(out, ft_high);
 
1319
 
 
1320
                        seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);
 
1321
                        out_uint32_le(out, ft_low);     /* last_write_time */
 
1322
                        out_uint32_le(out, ft_high);
 
1323
 
 
1324
                        seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);
 
1325
                        out_uint32_le(out, ft_low);     /* change_write_time */
 
1326
                        out_uint32_le(out, ft_high);
 
1327
 
 
1328
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
 
1329
                        out_uint32_le(out, 0);  /* filesize high */
 
1330
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
 
1331
                        out_uint32_le(out, 0);  /* filesize high */
 
1332
                        out_uint32_le(out, file_attributes);
 
1333
                        out_uint32_le(out, 2 * strlen(pdirent->d_name) + 2);    /* unicode length */
 
1334
                        rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
 
1335
                        break;
 
1336
 
 
1337
 
 
1338
                case FileFullDirectoryInformation:
 
1339
 
 
1340
                        seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,
 
1341
                                                       &ft_low);
 
1342
                        out_uint32_le(out, ft_low);     /* create time */
 
1343
                        out_uint32_le(out, ft_high);
 
1344
 
 
1345
                        seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);
 
1346
                        out_uint32_le(out, ft_low);     /* last_access_time */
 
1347
                        out_uint32_le(out, ft_high);
 
1348
 
 
1349
                        seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);
 
1350
                        out_uint32_le(out, ft_low);     /* last_write_time */
 
1351
                        out_uint32_le(out, ft_high);
 
1352
 
 
1353
                        seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);
 
1354
                        out_uint32_le(out, ft_low);     /* change_write_time */
 
1355
                        out_uint32_le(out, ft_high);
 
1356
 
 
1357
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
 
1358
                        out_uint32_le(out, 0);  /* filesize high */
 
1359
                        out_uint32_le(out, filestat.st_size);   /* filesize low */
 
1360
                        out_uint32_le(out, 0);  /* filesize high */
 
1361
                        out_uint32_le(out, file_attributes);
 
1362
                        out_uint32_le(out, 2 * strlen(pdirent->d_name) + 2);    /* unicode length */
 
1363
                        out_uint32_le(out, 0);  /* EaSize */
 
1364
                        rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
 
1365
                        break;
 
1366
 
 
1367
 
 
1368
                case FileNamesInformation:
 
1369
 
 
1370
                        out_uint32_le(out, 2 * strlen(pdirent->d_name) + 2);    /* unicode length */
 
1371
                        rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
 
1372
                        break;
 
1373
 
 
1374
 
 
1375
                default:
1237
1376
 
1238
1377
                        unimpl("IRP Query Directory sub: 0x%x\n", info_class);
1239
1378
                        return RD_STATUS_INVALID_PARAMETER;