| Index: base/test/test_file_util_win.cc
|
| diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc
|
| index 70ca907f7b431634eb5e38a959c48c9210e07878..22b884b17496dc8b57a0f0839db207749cbfa45f 100644
|
| --- a/base/test/test_file_util_win.cc
|
| +++ b/base/test/test_file_util_win.cc
|
| @@ -23,6 +23,11 @@ static const ptrdiff_t kOneMB = 1024 * 1024;
|
|
|
| namespace {
|
|
|
| +struct PermissionInfo {
|
| + PSECURITY_DESCRIPTOR security_descriptor;
|
| + ACL dacl;
|
| +};
|
| +
|
| // Deny |permission| on the file |path|, for the current user.
|
| bool DenyFilePermission(const FilePath& path, DWORD permission) {
|
| PACL old_dacl;
|
| @@ -278,4 +283,42 @@ bool MakeFileUnwritable(const FilePath& path) {
|
| return DenyFilePermission(path, GENERIC_WRITE);
|
| }
|
|
|
| +void* GetPermissionInfo(const FilePath& path, size_t* length) {
|
| + DCHECK(length != NULL);
|
| + *length = 0;
|
| + PACL dacl = NULL;
|
| + PSECURITY_DESCRIPTOR security_descriptor;
|
| + if (GetNamedSecurityInfo(const_cast<wchar_t*>(path.value().c_str()),
|
| + SE_FILE_OBJECT,
|
| + DACL_SECURITY_INFORMATION, NULL, NULL, &dacl,
|
| + NULL, &security_descriptor) != ERROR_SUCCESS) {
|
| + return NULL;
|
| + }
|
| + DCHECK(dacl != NULL);
|
| +
|
| + *length = sizeof(PSECURITY_DESCRIPTOR) + dacl->AclSize;
|
| + PermissionInfo* info = reinterpret_cast<PermissionInfo*>(new char[*length]);
|
| + info->security_descriptor = security_descriptor;
|
| + memcpy(&info->dacl, dacl, dacl->AclSize);
|
| +
|
| + return info;
|
| +}
|
| +
|
| +bool RestorePermissionInfo(const FilePath& path, void* info, size_t length) {
|
| + if (!info || !length)
|
| + return false;
|
| +
|
| + PermissionInfo* perm = reinterpret_cast<PermissionInfo*>(info);
|
| +
|
| + DWORD rc = SetNamedSecurityInfo(const_cast<wchar_t*>(path.value().c_str()),
|
| + SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
|
| + NULL, NULL, &perm->dacl, NULL);
|
| + LocalFree(perm->security_descriptor);
|
| +
|
| + char* char_array = reinterpret_cast<char*>(info);
|
| + delete [] char_array;
|
| +
|
| + return rc == ERROR_SUCCESS;
|
| +}
|
| +
|
| } // namespace file_util
|
|
|