/
elevation.hpp
132 lines (106 loc) · 4.71 KB
/
elevation.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef ELEVATION_HPP_19857862_0EE5_4709_B3E9_C7E50239C2E0
#define ELEVATION_HPP_19857862_0EE5_4709_B3E9_C7E50239C2E0
#pragma once
/*
elevation.hpp
Elevation
*/
/*
Copyright © 2010 Far Group
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "synchro.hpp"
enum class lng : int;
enum ELEVATION_MODE
{
ELEVATION_MODIFY_REQUEST = 0x00000001,
ELEVATION_READ_REQUEST = 0x00000002,
ELEVATION_USE_PRIVILEGES = 0xf0000000,
};
enum ELEVATION_COMMAND: int;
class elevation: noncopyable
{
public:
elevation();
~elevation();
void ResetApprove();
bool Elevated() const {return m_Elevation;}
bool fCreateDirectoryEx(const string& TemplateObject, const string& Object, LPSECURITY_ATTRIBUTES Attributes);
bool fRemoveDirectory(const string& Object);
bool fDeleteFile(const string& Object);
void fCallbackRoutine(LPPROGRESS_ROUTINE ProgressRoutine) const;
bool fCopyFileEx(const string& From, const string& To, LPPROGRESS_ROUTINE ProgressRoutine, LPVOID Data, LPBOOL Cancel, DWORD Flags);
bool fMoveFileEx(const string& From, const string& To, DWORD Flags);
DWORD fGetFileAttributes(const string& Object);
bool fSetFileAttributes(const string& Object, DWORD FileAttributes);
bool fCreateHardLink(const string& Object,const string& Target,LPSECURITY_ATTRIBUTES SecurityAttributes);
bool fCreateSymbolicLink(const string& Object, const string& Target, DWORD Flags);
int fMoveToRecycleBin(SHFILEOPSTRUCT& FileOpStruct);
bool fSetOwner(const string& Object, const string& Owner);
HANDLE fCreateFile(const string& Object, DWORD DesiredAccess, DWORD ShareMode, LPSECURITY_ATTRIBUTES SecurityAttributes, DWORD CreationDistribution, DWORD FlagsAndAttributes, HANDLE TemplateFile);
bool fSetFileEncryption(const string& Object, bool Encrypt);
bool fDetachVirtualDisk(const string& Object, VIRTUAL_STORAGE_TYPE& VirtualStorageType);
bool fGetDiskFreeSpaceEx(const string& Object, ULARGE_INTEGER* FreeBytesAvailableToCaller, ULARGE_INTEGER* TotalNumberOfBytes, ULARGE_INTEGER* TotalNumberOfFreeBytes);
class suppress: noncopyable
{
public:
suppress(): m_owner(Global? Global->Elevation : nullptr) { if (m_owner) ++m_owner->m_Suppressions; }
~suppress() { if (m_owner) --m_owner->m_Suppressions; }
private:
elevation* m_owner;
};
private:
void Write(const blob_view& Data) const;
template<typename T>
T Read() const;
template<typename T>
void Read(T& Data) const { Data = Read<T>(); }
static void Write() {};
template<typename T, typename... args>
void Write(const T& Data, args&&... Args) const;
template<typename... args>
void SendCommand(ELEVATION_COMMAND Command, args&&... Args) const;
void RetrieveLastError() const;
template<typename T>
T RetrieveLastErrorAndResult() const;
bool Initialize();
bool ElevationApproveDlg(lng Why, const string& Object);
void TerminateChildProcess() const;
template<typename T, typename F1, typename F2>
auto execute(lng Why, const string& Object, T Fallback, const F1& PrivilegedHander, const F2& ElevatedHandler);
std::atomic_ulong m_Suppressions;
os::handle m_Pipe;
os::handle m_Process;
os::handle m_Job;
bool m_IsApproved;
bool m_AskApprove;
bool m_Elevation;
bool m_DontAskAgain;
int m_Recurse;
os::critical_section m_CS;
string m_PipeName;
};
bool ElevationRequired(ELEVATION_MODE Mode, bool UseNtStatus = true);
int ElevationMain(const wchar_t* guid, DWORD PID, bool UsePrivileges);
bool IsElevationArgument(const wchar_t* Argument);
#endif // ELEVATION_HPP_19857862_0EE5_4709_B3E9_C7E50239C2E0