aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/SecurityUtils.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/SecurityUtils.h83
1 files changed, 32 insertions, 51 deletions
diff --git a/CPP/Windows/SecurityUtils.h b/CPP/Windows/SecurityUtils.h
index 8966dfd..c0d7b12 100644
--- a/CPP/Windows/SecurityUtils.h
+++ b/CPP/Windows/SecurityUtils.h
@@ -7,6 +7,31 @@
7 7
8#include "Defs.h" 8#include "Defs.h"
9 9
10#ifndef _UNICODE
11
12extern "C" {
13typedef NTSTATUS (NTAPI *Func_LsaOpenPolicy)(PLSA_UNICODE_STRING SystemName,
14 PLSA_OBJECT_ATTRIBUTES ObjectAttributes, ACCESS_MASK DesiredAccess, PLSA_HANDLE PolicyHandle);
15typedef NTSTATUS (NTAPI *Func_LsaClose)(LSA_HANDLE ObjectHandle);
16typedef NTSTATUS (NTAPI *Func_LsaAddAccountRights)(LSA_HANDLE PolicyHandle,
17 PSID AccountSid, PLSA_UNICODE_STRING UserRights, ULONG CountOfRights );
18#define MY_STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002L)
19}
20
21#define POLICY_FUNC_CALL(fff, str) \
22 if (hModule == NULL) return MY_STATUS_NOT_IMPLEMENTED; \
23 Func_ ## fff v = (Func_ ## fff) (void(*)()) GetProcAddress(hModule, str); \
24 if (!v) return MY_STATUS_NOT_IMPLEMENTED; \
25 const NTSTATUS res = v
26
27#else
28
29#define POLICY_FUNC_CALL(fff, str) \
30 const NTSTATUS res = ::fff
31
32#endif
33
34
10namespace NWindows { 35namespace NWindows {
11namespace NSecurity { 36namespace NSecurity {
12 37
@@ -53,15 +78,9 @@ public:
53 78
54}; 79};
55 80
56#ifndef _UNICODE
57typedef NTSTATUS (NTAPI *LsaOpenPolicyP)(PLSA_UNICODE_STRING SystemName,
58 PLSA_OBJECT_ATTRIBUTES ObjectAttributes, ACCESS_MASK DesiredAccess, PLSA_HANDLE PolicyHandle);
59typedef NTSTATUS (NTAPI *LsaCloseP)(LSA_HANDLE ObjectHandle);
60typedef NTSTATUS (NTAPI *LsaAddAccountRightsP)(LSA_HANDLE PolicyHandle,
61 PSID AccountSid, PLSA_UNICODE_STRING UserRights, ULONG CountOfRights );
62#define MY_STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002L)
63#endif
64 81
82
83
65struct CPolicy 84struct CPolicy
66{ 85{
67protected: 86protected:
@@ -82,43 +101,17 @@ public:
82 NTSTATUS Open(PLSA_UNICODE_STRING systemName, PLSA_OBJECT_ATTRIBUTES objectAttributes, 101 NTSTATUS Open(PLSA_UNICODE_STRING systemName, PLSA_OBJECT_ATTRIBUTES objectAttributes,
83 ACCESS_MASK desiredAccess) 102 ACCESS_MASK desiredAccess)
84 { 103 {
85 #ifndef _UNICODE
86 if (hModule == NULL)
87 return MY_STATUS_NOT_IMPLEMENTED;
88 LsaOpenPolicyP lsaOpenPolicy = (LsaOpenPolicyP)GetProcAddress(hModule, "LsaOpenPolicy");
89 if (lsaOpenPolicy == NULL)
90 return MY_STATUS_NOT_IMPLEMENTED;
91 #endif
92
93 Close(); 104 Close();
94 return 105 POLICY_FUNC_CALL (LsaOpenPolicy, "LsaOpenPolicy")
95 #ifdef _UNICODE
96 ::LsaOpenPolicy
97 #else
98 lsaOpenPolicy
99 #endif
100 (systemName, objectAttributes, desiredAccess, &_handle); 106 (systemName, objectAttributes, desiredAccess, &_handle);
107 return res;
101 } 108 }
102 109
103 NTSTATUS Close() 110 NTSTATUS Close()
104 { 111 {
105 if (_handle == NULL) 112 if (_handle == NULL)
106 return 0; 113 return 0;
107 114 POLICY_FUNC_CALL (LsaClose, "LsaClose")
108 #ifndef _UNICODE
109 if (hModule == NULL)
110 return MY_STATUS_NOT_IMPLEMENTED;
111 LsaCloseP lsaClose = (LsaCloseP)GetProcAddress(hModule, "LsaClose");
112 if (lsaClose == NULL)
113 return MY_STATUS_NOT_IMPLEMENTED;
114 #endif
115
116 NTSTATUS res =
117 #ifdef _UNICODE
118 ::LsaClose
119 #else
120 lsaClose
121 #endif
122 (_handle); 115 (_handle);
123 _handle = NULL; 116 _handle = NULL;
124 return res; 117 return res;
@@ -137,21 +130,9 @@ public:
137 130
138 NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights, ULONG countOfRights) 131 NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights, ULONG countOfRights)
139 { 132 {
140 #ifndef _UNICODE 133 POLICY_FUNC_CALL (LsaAddAccountRights, "LsaAddAccountRights")
141 if (hModule == NULL)
142 return MY_STATUS_NOT_IMPLEMENTED;
143 LsaAddAccountRightsP lsaAddAccountRights = (LsaAddAccountRightsP)GetProcAddress(hModule, "LsaAddAccountRights");
144 if (lsaAddAccountRights == NULL)
145 return MY_STATUS_NOT_IMPLEMENTED;
146 #endif
147
148 return
149 #ifdef _UNICODE
150 ::LsaAddAccountRights
151 #else
152 lsaAddAccountRights
153 #endif
154 (_handle, accountSid, userRights, countOfRights); 134 (_handle, accountSid, userRights, countOfRights);
135 return res;
155 } 136 }
156 NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights) 137 NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights)
157 { return AddAccountRights(accountSid, userRights, 1); } 138 { return AddAccountRights(accountSid, userRights, 1); }