| 4186 | } |
| 4187 | |
| 4188 | static bool win_directory_component_secure(win_security_t *security, const wchar_t *path) { |
| 4189 | HANDLE directory = |
| 4190 | CreateFileW(path, FILE_READ_ATTRIBUTES | READ_CONTROL, |
| 4191 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, |
| 4192 | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); |
| 4193 | if (directory == INVALID_HANDLE_VALUE) { |
| 4194 | return false; |
| 4195 | } |
| 4196 | BY_HANDLE_FILE_INFORMATION info; |
| 4197 | /* Default Windows profile ancestors grant cross-account add-subdirectory. |
| 4198 | * That permits siblings but cannot replace the existing next path |
| 4199 | * component. Keep every other mutation right forbidden; the final runtime |
| 4200 | * directory is separately owner-validated and given a protected DACL. */ |
| 4201 | DWORD mutation = win_private_mutation_rights() & ~((DWORD)FILE_ADD_SUBDIRECTORY); |
| 4202 | bool valid = GetFileInformationByHandle(directory, &info) != 0 && |
| 4203 | (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && |
| 4204 | (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 && |
| 4205 | win_file_security_secure(security, directory, false, mutation); |
| 4206 | (void)CloseHandle(directory); |
| 4207 | return valid; |
| 4208 | } |
| 4209 | |
| 4210 | static bool win_private_directory_tree_secure(const wchar_t *directory_path) { |
| 4211 | if (!directory_path) { |
no test coverage detected