Skip to content

Commit fbf963c

Browse files
committed
Backed out changeset: 17df50df62c7
1 parent 15efd2b commit fbf963c

5 files changed

Lines changed: 36 additions & 208 deletions

File tree

Lib/test/test_os.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
import fcntl
4040
except ImportError:
4141
fcntl = None
42-
try:
43-
import _winapi
44-
except ImportError:
45-
_winapi = None
4642

4743
from test.script_helper import assert_python_ok
4844

@@ -1777,37 +1773,6 @@ def test_12084(self):
17771773
shutil.rmtree(level1)
17781774

17791775

1780-
@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
1781-
class Win32JunctionTests(unittest.TestCase):
1782-
junction = 'junctiontest'
1783-
junction_target = os.path.dirname(os.path.abspath(__file__))
1784-
1785-
def setUp(self):
1786-
assert os.path.exists(self.junction_target)
1787-
assert not os.path.exists(self.junction)
1788-
1789-
def tearDown(self):
1790-
if os.path.exists(self.junction):
1791-
# os.rmdir delegates to Windows' RemoveDirectoryW,
1792-
# which removes junction points safely.
1793-
os.rmdir(self.junction)
1794-
1795-
def test_create_junction(self):
1796-
_winapi.CreateJunction(self.junction_target, self.junction)
1797-
self.assertTrue(os.path.exists(self.junction))
1798-
self.assertTrue(os.path.isdir(self.junction))
1799-
1800-
# Junctions are not recognized as links.
1801-
self.assertFalse(os.path.islink(self.junction))
1802-
1803-
def test_unlink_removes_junction(self):
1804-
_winapi.CreateJunction(self.junction_target, self.junction)
1805-
self.assertTrue(os.path.exists(self.junction))
1806-
1807-
os.unlink(self.junction)
1808-
self.assertFalse(os.path.exists(self.junction))
1809-
1810-
18111776
@support.skip_unless_symlink
18121777
class NonLocalSymlinkTests(unittest.TestCase):
18131778

@@ -2579,7 +2544,6 @@ def test_main():
25792544
RemoveDirsTests,
25802545
CPUCountTests,
25812546
FDInheritanceTests,
2582-
Win32JunctionTests,
25832547
)
25842548

25852549
if __name__ == "__main__":

Misc/ACKS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ Chris Gonnerman
468468
Shelley Gooch
469469
David Goodger
470470
Hans de Graaff
471-
Kim Gräsman
472471
Nathaniel Gray
473472
Eddy De Greef
474473
Grant Griffin

Modules/_winapi.c

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#define WINDOWS_LEAN_AND_MEAN
4141
#include "windows.h"
4242
#include <crtdbg.h>
43-
#include "winreparse.h"
4443

4544
#if defined(MS_WIN32) && !defined(MS_WIN64)
4645
#define HANDLE_TO_PYNUM(handle) \
@@ -401,112 +400,6 @@ winapi_CreateFile(PyObject *self, PyObject *args)
401400
return Py_BuildValue(F_HANDLE, handle);
402401
}
403402

404-
static PyObject *
405-
winapi_CreateJunction(PyObject *self, PyObject *args)
406-
{
407-
/* Input arguments */
408-
LPWSTR src_path = NULL;
409-
LPWSTR dst_path = NULL;
410-
411-
/* Privilege adjustment */
412-
HANDLE token = NULL;
413-
TOKEN_PRIVILEGES tp;
414-
415-
/* Reparse data buffer */
416-
const USHORT prefix_len = 4;
417-
USHORT print_len = 0;
418-
USHORT rdb_size = 0;
419-
PREPARSE_DATA_BUFFER rdb = NULL;
420-
421-
/* Junction point creation */
422-
HANDLE junction = NULL;
423-
DWORD ret = 0;
424-
425-
if (!PyArg_ParseTuple(args, "uu",
426-
&src_path, &dst_path))
427-
return NULL;
428-
429-
if (memcmp(src_path, L"\\??\\", prefix_len * sizeof(WCHAR)) == 0)
430-
return PyErr_SetFromWindowsErr(ERROR_INVALID_PARAMETER);
431-
432-
/* Adjust privileges to allow rewriting directory entry as a
433-
junction point. */
434-
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))
435-
goto cleanup;
436-
437-
if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tp.Privileges[0].Luid))
438-
goto cleanup;
439-
440-
tp.PrivilegeCount = 1;
441-
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
442-
if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
443-
NULL, NULL))
444-
goto cleanup;
445-
446-
if (GetFileAttributesW(src_path) == INVALID_FILE_ATTRIBUTES)
447-
goto cleanup;
448-
449-
print_len = (USHORT)GetFullPathNameW(src_path, 0, NULL, NULL);
450-
if (print_len == 0)
451-
goto cleanup;
452-
453-
/* NUL terminator should not be part of print_len */
454-
--print_len;
455-
456-
rdb_size = REPARSE_DATA_BUFFER_HEADER_SIZE +
457-
sizeof(rdb->MountPointReparseBuffer) -
458-
sizeof(rdb->MountPointReparseBuffer.PathBuffer) +
459-
/* Two +1's for NUL terminators. */
460-
(prefix_len + print_len + 1 + print_len + 1) * sizeof(WCHAR);
461-
rdb = (PREPARSE_DATA_BUFFER)PyMem_RawMalloc(rdb_size, 1);
462-
463-
rdb->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
464-
rdb->ReparseDataLength = rdb_size - REPARSE_DATA_BUFFER_HEADER_SIZE;
465-
rdb->MountPointReparseBuffer.SubstituteNameOffset = 0;
466-
rdb->MountPointReparseBuffer.SubstituteNameLength =
467-
(prefix_len + print_len) * sizeof(WCHAR);
468-
rdb->MountPointReparseBuffer.PrintNameOffset =
469-
rdb->MountPointReparseBuffer.SubstituteNameLength + sizeof(WCHAR);
470-
rdb->MountPointReparseBuffer.PrintNameLength = print_len * sizeof(WCHAR);
471-
472-
lstrcpyW(rdb->MountPointReparseBuffer.PathBuffer, L"\\??\\");
473-
if (GetFullPathNameW(src_path, print_len + 1,
474-
rdb->MountPointReparseBuffer.PathBuffer + prefix_len,
475-
NULL) == 0)
476-
goto cleanup;
477-
478-
lstrcpyW(rdb->MountPointReparseBuffer.PathBuffer +
479-
prefix_len + print_len + 1,
480-
rdb->MountPointReparseBuffer.PathBuffer + prefix_len);
481-
482-
/* Create a directory for the junction point. */
483-
if (!CreateDirectoryW(dst_path, NULL))
484-
goto cleanup;
485-
486-
junction = CreateFileW(dst_path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
487-
OPEN_EXISTING,
488-
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL);
489-
if (junction == INVALID_HANDLE_VALUE)
490-
goto cleanup;
491-
492-
/* Make the directory entry a junction point. */
493-
if (!DeviceIoControl(junction, FSCTL_SET_REPARSE_POINT, rdb, rdb_size,
494-
NULL, 0, &ret, NULL))
495-
goto cleanup;
496-
497-
cleanup:
498-
ret = GetLastError();
499-
500-
CloseHandle(token);
501-
CloseHandle(junction);
502-
free(rdb);
503-
504-
if (ret != 0)
505-
return PyErr_SetFromWindowsErr(ret);
506-
507-
Py_RETURN_NONE;
508-
}
509-
510403
static PyObject *
511404
winapi_CreateNamedPipe(PyObject *self, PyObject *args)
512405
{
@@ -1332,8 +1225,6 @@ static PyMethodDef winapi_functions[] = {
13321225
METH_VARARGS | METH_KEYWORDS, ""},
13331226
{"CreateFile", winapi_CreateFile, METH_VARARGS,
13341227
""},
1335-
{"CreateJunction", winapi_CreateJunction, METH_VARARGS,
1336-
""},
13371228
{"CreateNamedPipe", winapi_CreateNamedPipe, METH_VARARGS,
13381229
""},
13391230
{"CreatePipe", winapi_CreatePipe, METH_VARARGS,

Modules/posixmodule.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include "Python.h"
2828
#ifndef MS_WINDOWS
2929
#include "posixmodule.h"
30-
#else
31-
#include "winreparse.h"
3230
#endif
3331

3432
#ifdef __cplusplus
@@ -303,9 +301,6 @@ extern int lstat(const char *, struct stat *);
303301
#ifndef IO_REPARSE_TAG_SYMLINK
304302
#define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
305303
#endif
306-
#ifndef IO_REPARSE_TAG_MOUNT_POINT
307-
#define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
308-
#endif
309304
#include "osdefs.h"
310305
#include <malloc.h>
311306
#include <windows.h>
@@ -1114,6 +1109,41 @@ _PyVerify_fd_dup2(int fd1, int fd2)
11141109
#endif
11151110

11161111
#ifdef MS_WINDOWS
1112+
/* The following structure was copied from
1113+
http://msdn.microsoft.com/en-us/library/ms791514.aspx as the required
1114+
include doesn't seem to be present in the Windows SDK (at least as included
1115+
with Visual Studio Express). */
1116+
typedef struct _REPARSE_DATA_BUFFER {
1117+
ULONG ReparseTag;
1118+
USHORT ReparseDataLength;
1119+
USHORT Reserved;
1120+
union {
1121+
struct {
1122+
USHORT SubstituteNameOffset;
1123+
USHORT SubstituteNameLength;
1124+
USHORT PrintNameOffset;
1125+
USHORT PrintNameLength;
1126+
ULONG Flags;
1127+
WCHAR PathBuffer[1];
1128+
} SymbolicLinkReparseBuffer;
1129+
1130+
struct {
1131+
USHORT SubstituteNameOffset;
1132+
USHORT SubstituteNameLength;
1133+
USHORT PrintNameOffset;
1134+
USHORT PrintNameLength;
1135+
WCHAR PathBuffer[1];
1136+
} MountPointReparseBuffer;
1137+
1138+
struct {
1139+
UCHAR DataBuffer[1];
1140+
} GenericReparseBuffer;
1141+
};
1142+
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
1143+
1144+
#define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER,\
1145+
GenericReparseBuffer)
1146+
#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
11171147

11181148
static int
11191149
win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
@@ -4462,10 +4492,7 @@ BOOL WINAPI Py_DeleteFileW(LPCWSTR lpFileName)
44624492
find_data_handle = FindFirstFileW(lpFileName, &find_data);
44634493

44644494
if(find_data_handle != INVALID_HANDLE_VALUE) {
4465-
/* IO_REPARSE_TAG_SYMLINK if it is a symlink and
4466-
IO_REPARSE_TAG_MOUNT_POINT if it is a junction point. */
4467-
is_link = find_data.dwReserved0 == IO_REPARSE_TAG_SYMLINK ||
4468-
find_data.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT;
4495+
is_link = find_data.dwReserved0 == IO_REPARSE_TAG_SYMLINK;
44694496
FindClose(find_data_handle);
44704497
}
44714498
}

Modules/winreparse.h

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)