@@ -772,6 +772,15 @@ process_open(u_int32_t id)
772
772
debug3 ("request %u: open flags %d" , id , pflags );
773
773
flags = flags_from_portable (pflags );
774
774
mode = (a .flags & SSH2_FILEXFER_ATTR_PERMISSIONS ) ? a .perm : 0666 ;
775
+ #ifdef WIN32_FIXME
776
+ char resolvedname [MAXPATHLEN ];
777
+ if (realpathWin32i (name , resolvedname ))
778
+ {
779
+ free (name );
780
+ name = strdup (resolvedname );
781
+ }
782
+ #endif
783
+
775
784
logit ("open \"%s\" flags %s mode 0%o" ,
776
785
name , string_from_portable (pflags ), mode );
777
786
if (readonly &&
@@ -915,10 +924,9 @@ process_do_stat(u_int32_t id, int do_lstat)
915
924
if ((r = sshbuf_get_cstring (iqueue , & name , NULL )) != 0 )
916
925
fatal ("%s: buffer error: %s" , __func__ , ssh_err (r ));
917
926
918
- if (realpathWin32 (name , resolvedname ))
927
+ if (realpathWin32i (name , resolvedname ))
919
928
{
920
- free (name );
921
-
929
+ free (name );
922
930
name = strdup (resolvedname );
923
931
}
924
932
@@ -1130,10 +1138,19 @@ process_opendir(u_int32_t id)
1130
1138
1131
1139
if ((r = sshbuf_get_cstring (iqueue , & path , NULL )) != 0 )
1132
1140
fatal ("%s: buffer error: %s" , __func__ , ssh_err (r ));
1133
-
1141
+
1142
+ #ifdef WIN32_FIXME
1143
+ char resolvedname [MAXPATHLEN ];
1144
+ if (realpathWin32i (path , resolvedname ))
1145
+ {
1146
+ free (path );
1147
+ path = strdup (resolvedname );
1148
+ }
1149
+ #endif
1134
1150
1135
1151
debug3 ("request %u: opendir" , id );
1136
1152
logit ("opendir \"%s\"" , path );
1153
+
1137
1154
dirp = opendir (path );
1138
1155
if (dirp == NULL ) {
1139
1156
status = errno_to_portable (errno );
@@ -1238,6 +1255,17 @@ process_remove(u_int32_t id)
1238
1255
1239
1256
debug3 ("request %u: remove" , id );
1240
1257
logit ("remove name \"%s\"" , name );
1258
+
1259
+ #ifdef WIN32_FIXME
1260
+ char resolvedname [MAXPATHLEN ];
1261
+ if (realpathWin32i (name , resolvedname ))
1262
+ {
1263
+ free (name );
1264
+
1265
+ name = strdup (resolvedname );
1266
+ }
1267
+ #endif
1268
+
1241
1269
r = unlink (name );
1242
1270
status = (r == -1 ) ? errno_to_portable (errno ) : SSH2_FX_OK ;
1243
1271
send_status (id , status );
@@ -1261,6 +1289,16 @@ process_mkdir(u_int32_t id)
1261
1289
a .perm & 07777 : 0777 ;
1262
1290
debug3 ("request %u: mkdir" , id );
1263
1291
logit ("mkdir name \"%s\" mode 0%o" , name , mode );
1292
+
1293
+ #ifdef WIN32_FIXME
1294
+ char resolvedname [MAXPATHLEN ];
1295
+ if (realpathWin32i (name , resolvedname ))
1296
+ {
1297
+ free (name );
1298
+
1299
+ name = strdup (resolvedname );
1300
+ }
1301
+ #endif
1264
1302
r = mkdir (name , mode );
1265
1303
status = (r == -1 ) ? errno_to_portable (errno ) : SSH2_FX_OK ;
1266
1304
send_status (id , status );
@@ -1278,6 +1316,15 @@ process_rmdir(u_int32_t id)
1278
1316
1279
1317
debug3 ("request %u: rmdir" , id );
1280
1318
logit ("rmdir name \"%s\"" , name );
1319
+ #ifdef WIN32_FIXME
1320
+ char resolvedname [MAXPATHLEN ];
1321
+ if (realpathWin32i (name , resolvedname ))
1322
+ {
1323
+ free (name );
1324
+
1325
+ name = strdup (resolvedname );
1326
+ }
1327
+ #endif
1281
1328
r = rmdir (name );
1282
1329
status = (r == -1 ) ? errno_to_portable (errno ) : SSH2_FX_OK ;
1283
1330
send_status (id , status );
@@ -1306,16 +1353,48 @@ process_realpath(u_int32_t id)
1306
1353
#else
1307
1354
if ( (path [0 ] == '\0' ) || ( strcmp (path , "." )== 0 ) ) {
1308
1355
free (path );
1309
- _getcwd (resolvedname , sizeof (resolvedname ));
1356
+ // add an extra / in front of paths to make them sftp spec compliant
1357
+ // c:/users/test1 will become /c:/users/test1
1358
+ resolvedname [0 ] = '/' ;
1359
+
1360
+ _getcwd (& resolvedname [1 ], sizeof (resolvedname ));
1310
1361
// convert back slashes to forward slashes to be compatibale with unix naming
1311
1362
char * cptr = resolvedname ;
1312
1363
while (* cptr ) {
1313
1364
if (* cptr == '\\' )
1314
1365
* cptr = '/' ;
1315
1366
cptr ++ ;
1316
1367
}
1317
- path = xstrdup (resolvedname );
1368
+ path = strdup (resolvedname );
1318
1369
}
1370
+ else {
1371
+ // see if we were given rooted form /dir or /x:/home/x:/dir
1372
+ if (path [2 ] != ':' ) {
1373
+ // absolute form given /dir
1374
+ // no drive letter, so was given in absolute form like cd /debug and we got "/debug" to process
1375
+ // we have to attach current drive letter in front
1376
+ resolvedname [0 ] = '/' ;
1377
+ resolvedname [1 ] = _getdrive () + 'A' - 1 ; // convert current drive letter to Windows driver Char
1378
+ resolvedname [2 ] = ':' ;
1379
+ strcpy (& resolvedname [3 ], path );
1380
+ free (path );
1381
+ path = strdup (resolvedname );
1382
+ }
1383
+ else {
1384
+ char * pch = strchr (path , ':' );
1385
+ if (pch != NULL && (pch = strrchr (pch + 1 , ':' )) ) {
1386
+ if (path [0 ] == '/' ) { // it was /x:/home/x:/dir form, use last drive letter part
1387
+ pch -- ;
1388
+ resolvedname [0 ] = '/' ;
1389
+ strcpy (resolvedname + 1 , pch );
1390
+ free (path );
1391
+ path = strdup (resolvedname );
1392
+ }
1393
+ }
1394
+ }
1395
+
1396
+ }
1397
+
1319
1398
#endif
1320
1399
1321
1400
debug3 ("request %u: realpath" , id );
@@ -1341,7 +1420,19 @@ process_rename(u_int32_t id)
1341
1420
if ((r = sshbuf_get_cstring (iqueue , & oldpath , NULL )) != 0 ||
1342
1421
(r = sshbuf_get_cstring (iqueue , & newpath , NULL )) != 0 )
1343
1422
fatal ("%s: buffer error: %s" , __func__ , ssh_err (r ));
1344
-
1423
+ #ifdef WIN32_FIXME
1424
+ char resolvedname [MAXPATHLEN ];
1425
+ if (realpathWin32i (oldpath , resolvedname ))
1426
+ {
1427
+ free (oldpath );
1428
+ oldpath = strdup (resolvedname );
1429
+ }
1430
+ if (realpathWin32i (newpath , resolvedname ))
1431
+ {
1432
+ free (newpath );
1433
+ newpath = strdup (resolvedname );
1434
+ }
1435
+ #endif
1345
1436
1346
1437
debug3 ("request %u: rename" , id );
1347
1438
logit ("rename old \"%s\" new \"%s\"" , oldpath , newpath );
@@ -1502,6 +1593,19 @@ process_extended_posix_rename(u_int32_t id)
1502
1593
(r = sshbuf_get_cstring (iqueue , & newpath , NULL )) != 0 )
1503
1594
fatal ("%s: buffer error: %s" , __func__ , ssh_err (r ));
1504
1595
1596
+ #ifdef WIN32_FIXME
1597
+ char resolvedname [MAXPATHLEN ];
1598
+ if (realpathWin32i (oldpath , resolvedname ))
1599
+ {
1600
+ free (oldpath );
1601
+ oldpath = strdup (resolvedname );
1602
+ }
1603
+ if (realpathWin32i (newpath , resolvedname ))
1604
+ {
1605
+ free (newpath );
1606
+ newpath = strdup (resolvedname );
1607
+ }
1608
+ #endif
1505
1609
1506
1610
debug3 ("request %u: posix-rename" , id );
1507
1611
logit ("posix-rename old \"%s\" new \"%s\"" , oldpath , newpath );
@@ -1707,6 +1811,8 @@ if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 ||
1707
1811
#ifndef WIN32_FIXME
1708
1812
r = link (oldpath , newpath );
1709
1813
status = (r == -1 ) ? errno_to_portable (errno ) : SSH2_FX_OK ;
1814
+ #else
1815
+ status = SSH2_FX_OP_UNSUPPORTED ;
1710
1816
#endif
1711
1817
send_status (id , status );
1712
1818
free (oldpath );
0 commit comments