unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

win32acl.cpp
Go to the documentation of this file.
1static void SetACLPrivileges();
2
3static bool ReadSacl=false;
4
5
6
7#ifndef SFX_MODULE
8void ExtractACL20(Archive &Arc,const wchar *FileName)
9{
11
12 if (Arc.BrokenHeader)
13 {
14 uiMsg(UIERROR_ACLBROKEN,Arc.FileName,FileName);
16 return;
17 }
18
19 if (Arc.EAHead.Method<0x31 || Arc.EAHead.Method>0x35 || Arc.EAHead.UnpVer>VER_PACK)
20 {
21 uiMsg(UIERROR_ACLUNKNOWN,Arc.FileName,FileName);
23 return;
24 }
25
26 ComprDataIO DataIO;
27 Unpack Unpack(&DataIO);
28 Unpack.Init(0x10000,false);
29
30 Array<byte> UnpData(Arc.EAHead.UnpSize);
31 DataIO.SetUnpackToMemory(&UnpData[0],Arc.EAHead.UnpSize);
33 DataIO.EnableShowProgress(false);
34 DataIO.SetFiles(&Arc,NULL);
35 DataIO.UnpHash.Init(HASH_CRC32,1);
37 Unpack.DoUnpack(Arc.EAHead.UnpVer,false);
38
39 if (Arc.EAHead.EACRC!=DataIO.UnpHash.GetCRC32())
40 {
41 uiMsg(UIERROR_ACLBROKEN,Arc.FileName,FileName);
43 return;
44 }
45
46 SECURITY_INFORMATION si=OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|
47 DACL_SECURITY_INFORMATION;
48 if (ReadSacl)
49 si|=SACL_SECURITY_INFORMATION;
50 SECURITY_DESCRIPTOR *sd=(SECURITY_DESCRIPTOR *)&UnpData[0];
51
52 int SetCode=SetFileSecurity(FileName,si,sd);
53
54 if (!SetCode)
55 {
56 uiMsg(UIERROR_ACLSET,Arc.FileName,FileName);
57 DWORD LastError=GetLastError();
59 if (LastError==ERROR_ACCESS_DENIED && !IsUserAdmin())
62 }
63}
64#endif
65
66
67void ExtractACL(Archive &Arc,const wchar *FileName)
68{
69 Array<byte> SubData;
70 if (!Arc.ReadSubData(&SubData,NULL,false))
71 return;
72
74
75 SECURITY_INFORMATION si=OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|
76 DACL_SECURITY_INFORMATION;
77 if (ReadSacl)
78 si|=SACL_SECURITY_INFORMATION;
79 SECURITY_DESCRIPTOR *sd=(SECURITY_DESCRIPTOR *)&SubData[0];
80
81 int SetCode=SetFileSecurity(FileName,si,sd);
82 if (!SetCode)
83 {
84 wchar LongName[NM];
85 if (GetWinLongPath(FileName,LongName,ASIZE(LongName)))
86 SetCode=SetFileSecurity(LongName,si,sd);
87 }
88
89 if (!SetCode)
90 {
91 uiMsg(UIERROR_ACLSET,Arc.FileName,FileName);
92 DWORD LastError=GetLastError();
94 if (LastError==ERROR_ACCESS_DENIED && !IsUserAdmin())
97 }
98}
99
100
102{
103 static bool InitDone=false;
104 if (InitDone)
105 return;
106
107 if (SetPrivilege(SE_SECURITY_NAME))
108 ReadSacl=true;
109 SetPrivilege(SE_RESTORE_NAME);
110
111 InitDone=true;
112}
113
114
115bool SetPrivilege(LPCTSTR PrivName)
116{
117 bool Success=false;
118
119 HANDLE hToken;
120 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
121 {
122 TOKEN_PRIVILEGES tp;
123 tp.PrivilegeCount = 1;
124 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
125
126 if (LookupPrivilegeValue(NULL,PrivName,&tp.Privileges[0].Luid) &&
127 AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL) &&
128 GetLastError() == ERROR_SUCCESS)
129 Success=true;
130
131 CloseHandle(hToken);
132 }
133
134 return Success;
135}
ErrorHandler ErrHandler
EAHeader EAHead
Definition: archive.hpp:111
bool BrokenHeader
Definition: archive.hpp:128
bool ReadSubData(Array< byte > *UnpData, File *DestFile, bool TestMode)
Definition: arcread.cpp:1431
DataHash UnpHash
Definition: rdwrfn.hpp:99
void SetPackedSizeToRead(int64 Size)
Definition: rdwrfn.hpp:66
void SetFiles(File *SrcFile, File *DestFile)
Definition: rdwrfn.cpp:232
void EnableShowProgress(bool Show)
Definition: rdwrfn.hpp:64
void SetUnpackToMemory(byte *Addr, uint Size)
Definition: rdwrfn.cpp:282
void Init(HASH_TYPE Type, uint MaxThreads)
Definition: hash.cpp:67
uint GetCRC32()
Definition: hash.cpp:122
void SetErrorCode(RAR_EXIT Code)
Definition: errhnd.cpp:243
void SysErrMsg()
Definition: errhnd.cpp:368
wchar FileName[NM]
Definition: file.hpp:88
void Init(size_t WinSize, bool Solid)
Definition: unpack.cpp:73
void DoUnpack(uint Method, bool Solid)
Definition: unpack.cpp:149
void SetDestSize(int64 DestSize)
Definition: unpack.hpp:381
@ RARX_CRC
Definition: errhnd.hpp:9
@ RARX_WARNING
Definition: errhnd.hpp:7
@ HASH_CRC32
Definition: hash.hpp:4
#define VER_PACK
Definition: headers.hpp:17
#define FALSE
Definition: os.hpp:4
#define ASIZE(x)
Definition: rardefs.hpp:10
wchar_t wchar
Definition: rartypes.hpp:13
uint DataSize
Definition: headers.hpp:156
byte Method
Definition: headers.hpp:338
uint UnpSize
Definition: headers.hpp:336
uint EACRC
Definition: headers.hpp:339
byte UnpVer
Definition: headers.hpp:337
void uiMsg(UIMESSAGE_CODE Code)
Definition: ui.hpp:148
@ UIERROR_ACLUNKNOWN
Definition: ui.hpp:36
@ UIERROR_NEEDADMIN
Definition: ui.hpp:17
@ UIERROR_ACLBROKEN
Definition: ui.hpp:36
@ UIERROR_ACLSET
Definition: ui.hpp:36
static void SetACLPrivileges()
Definition: win32acl.cpp:101
void ExtractACL20(Archive &Arc, const wchar *FileName)
Definition: win32acl.cpp:8
void ExtractACL(Archive &Arc, const wchar *FileName)
Definition: win32acl.cpp:67
bool SetPrivilege(LPCTSTR PrivName)
Definition: win32acl.cpp:115
static bool ReadSacl
Definition: win32acl.cpp:3