A mount-point reparse fixture uses an owned empty directory and an owned * target. It does not depend on symbolic-link privilege or developer mode. */
| 2214 | /* A mount-point reparse fixture uses an owned empty directory and an owned |
| 2215 | * target. It does not depend on symbolic-link privilege or developer mode. */ |
| 2216 | static bool pt_junction(const char *path, const char *target) { |
| 2217 | wchar_t wide[PT_PATH], destination[PT_PATH]; |
| 2218 | if (!pt_wide(path, wide) || !pt_wide(target, destination)) |
| 2219 | return false; |
| 2220 | for (wchar_t *p = destination; *p; p++) |
| 2221 | if (*p == L'/') |
| 2222 | *p = L'\\'; |
| 2223 | if (!destination[0] || destination[1] != L':') |
| 2224 | return false; |
| 2225 | struct { |
| 2226 | DWORD tag; |
| 2227 | WORD data_length, reserved, substitute_offset, substitute_length, print_offset, |
| 2228 | print_length; |
| 2229 | WCHAR path[PT_PATH + 8]; |
| 2230 | } buffer = {0}; |
| 2231 | size_t length = wcslen(destination); |
| 2232 | if (length + 5 >= sizeof(buffer.path) / sizeof(buffer.path[0])) |
| 2233 | return false; |
| 2234 | buffer.tag = IO_REPARSE_TAG_MOUNT_POINT; |
| 2235 | memcpy(buffer.path, L"\\??\\", 4 * sizeof(WCHAR)); |
| 2236 | memcpy(buffer.path + 4, destination, (length + 1) * sizeof(WCHAR)); |
| 2237 | buffer.substitute_length = (WORD)((length + 4) * sizeof(WCHAR)); |
| 2238 | buffer.print_offset = (WORD)(buffer.substitute_length + sizeof(WCHAR)); |
| 2239 | buffer.print_length = 0; |
| 2240 | buffer.path[length + 5] = 0; |
| 2241 | buffer.data_length = (WORD)(8 + buffer.substitute_length + 2 * sizeof(WCHAR)); |
| 2242 | HANDLE directory = CreateFileW(wide, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, |
| 2243 | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); |
| 2244 | if (directory == INVALID_HANDLE_VALUE) |
| 2245 | return false; |
| 2246 | DWORD returned = 0; |
| 2247 | bool ok = DeviceIoControl(directory, FSCTL_SET_REPARSE_POINT, &buffer, |
| 2248 | (DWORD)(8 + buffer.data_length), NULL, 0, &returned, NULL) != 0; |
| 2249 | return CloseHandle(directory) && ok; |
| 2250 | } |
| 2251 | #endif |
| 2252 | |
| 2253 | static bool pt_link_case(pt_fixture *fx) { |
no test coverage detected