|
40 | 40 | #define WINDOWS_LEAN_AND_MEAN |
41 | 41 | #include "windows.h" |
42 | 42 | #include <crtdbg.h> |
43 | | -#include "winreparse.h" |
44 | 43 |
|
45 | 44 | #if defined(MS_WIN32) && !defined(MS_WIN64) |
46 | 45 | #define HANDLE_TO_PYNUM(handle) \ |
@@ -401,112 +400,6 @@ winapi_CreateFile(PyObject *self, PyObject *args) |
401 | 400 | return Py_BuildValue(F_HANDLE, handle); |
402 | 401 | } |
403 | 402 |
|
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 | | - |
510 | 403 | static PyObject * |
511 | 404 | winapi_CreateNamedPipe(PyObject *self, PyObject *args) |
512 | 405 | { |
@@ -1332,8 +1225,6 @@ static PyMethodDef winapi_functions[] = { |
1332 | 1225 | METH_VARARGS | METH_KEYWORDS, ""}, |
1333 | 1226 | {"CreateFile", winapi_CreateFile, METH_VARARGS, |
1334 | 1227 | ""}, |
1335 | | - {"CreateJunction", winapi_CreateJunction, METH_VARARGS, |
1336 | | - ""}, |
1337 | 1228 | {"CreateNamedPipe", winapi_CreateNamedPipe, METH_VARARGS, |
1338 | 1229 | ""}, |
1339 | 1230 | {"CreatePipe", winapi_CreatePipe, METH_VARARGS, |
|
0 commit comments