libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
SecurityDescriptor.hpp
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright � 2002 by J.M.McGuiness, coder@hussar.me.uk
3
**
4
** This library is free software; you can redistribute it and/or
5
** modify it under the terms of the GNU Lesser General Public
6
** License as published by the Free Software Foundation; either
7
** version 2.1 of the License, or (at your option) any later version.
8
**
9
** This library is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
** Lesser General Public License for more details.
13
**
14
** You should have received a copy of the GNU Lesser General Public
15
** License along with this library; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*/
18
19
#
pragma
once
20
21
#
include
"LoadLibraryWrapper.hpp"
22
23
namespace
jmmcg
{
namespace
NTUtils
{
24
25
class
win_exception;
26
27
class
ACL_wrapper
:
virtual
protected
LoadLibraryWrapper
{
28
public
:
29
__stdcall
ACL_wrapper
();
30
__stdcall
ACL_wrapper
(
const
unsigned
long
acl_size);
31
__stdcall
ACL_wrapper
(
ACL_wrapper
&);
32
__stdcall
~
ACL_wrapper
();
33
ACL_wrapper
&
__fastcall
operator
=(
ACL_wrapper
&);
34
35
void
__fastcall
copy
(
const
ACL_wrapper
&)
noexcept
(
true
);
36
bool
__fastcall
initialize
()
noexcept
(
true
);
37
bool
__fastcall
add_ACE
(
const
DWORD access_mask,SID *sid)
noexcept
(
true
);
38
39
unsigned
long
size
()
const
noexcept
(
true
);
40
const
ACL
*
__fastcall
get
()
const
noexcept
(
true
);
41
ACL
*
__fastcall
get
()
noexcept
(
true
);
42
43
private
:
44
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
InitializeAclType
)(
PACL
pAcl
,
DWORD
nAclLength
,
DWORD
dwAclRevision
);
45
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
AddAccessAllowedAceType
)(
PACL
pAcl
,
DWORD
dwAceRevision
,
DWORD
AccessMask
,
PSID
pSid
);
46
#
ifdef
_DEBUG
47
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
IsValidAclType
)(
PACL
pAcl
);
48
#
endif
49
50
const
InitializeAclType pInitializeAcl;
51
const
AddAccessAllowedAceType pAddAccessAllowedAce;
52
#
ifdef
_DEBUG
53
const
IsValidAclType
pIsValidAcl
;
54
#
endif
55
56
unsigned
long
size_;
57
std::auto_ptr<BYTE> buff;
58
};
59
60
class
SID_wrapper
{
61
public
:
62
__stdcall
SID_wrapper
(
const
unsigned
int
sid_size=96)
63
:
buff
(
new
BYTE
[
sid_size
]) {
64
}
65
__stdcall
SID_wrapper
(
const
SID_wrapper
&sw)
66
:
buff
(
new
BYTE
[
GetLengthSid
(
const_cast
<
SID_wrapper
&>(
sw
).
get
())]) {
67
CopySid
(
GetLengthSid
(
const_cast
<
SID_wrapper
&>(
sw
).
get
()),
get
(),
const_cast
<
SID_wrapper
&>(
sw
).
get
());
68
}
69
__stdcall
~
SID_wrapper
() {
70
}
71
72
const
SID
*
__fastcall
get
()
const
noexcept
(
true
) {
73
return
reinterpret_cast
<
const
SID *>(buff.get());
74
}
75
SID
*
__fastcall
get
()
noexcept
(
true
) {
76
return
reinterpret_cast
<SID *>(buff.get());
77
}
78
79
private
:
80
const
std::auto_ptr<BYTE> buff;
81
82
SID_wrapper
&
__fastcall
operator=(
const
SID_wrapper
&);
83
};
84
85
class
AFX_EXT_CLASS
SecurityDescriptor
:
virtual
protected
LoadLibraryWrapper
{
86
public
:
87
typedef
win_exception
exception_type
;
88
89
__stdcall
SecurityDescriptor
();
90
__stdcall
~
SecurityDescriptor
();
91
92
const
SECURITY_DESCRIPTOR
&
__fastcall
SD
()
const
noexcept
(
true
) {
93
return
sd
;
94
}
95
unsigned
long
__fastcall
Allow
(
const
TCHAR
*
const
machine
,
const
TCHAR
*
const
username
,
const
DWORD
access_mask
)
noexcept
(
true
);
96
97
private
:
98
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
LookupAccountNameType
)(
LPCTSTR
lpSystemName
,
LPCTSTR
lpAccountName
,
PSID
Sid
,
LPDWORD
cbSid
,
LPTSTR
ReferencedDomainName
,
LPDWORD
cbReferencedDomainName
,
PSID_NAME_USE
peUse
);
99
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
InitializeSecurityDescriptorType
)(
PSECURITY_DESCRIPTOR
pSecurityDescriptor
,
DWORD
dwRevision
);
100
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
SetSecurityDescriptorDaclType
)(
PSECURITY_DESCRIPTOR
pSecurityDescriptor
,
BOOL
bDaclPresent
,
PACL
pDacl
,
BOOL
bDaclDefaulted
);
101
typedef
/*WINADVAPI*/
DWORD
(
WINAPI
*
const
GetLengthSidType
)(
PSID
pSid
);
102
#
ifdef
_DEBUG
103
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
IsValidSidType
)(
PSID
pSid
);
104
typedef
/*WINADVAPI*/
BOOL
(
WINAPI
*
const
IsValidSecurityDescriptorType
)(
PSECURITY_DESCRIPTOR
pSecurityDescriptor
);
105
#
endif
106
107
const
LookupAccountNameType
pLookupAccountName
;
108
const
InitializeSecurityDescriptorType
pInitializeSecurityDescriptor
;
109
const
SetSecurityDescriptorDaclType
pSetSecurityDescriptorDacl
;
110
const
GetLengthSidType
pGetLengthSid
;
111
#
ifdef
_DEBUG
112
const
IsValidSidType
pIsValidSid
;
113
const
IsValidSecurityDescriptorType
pIsValidSecurityDescriptor
;
114
#
endif
115
116
std
::
vector
<
SID
*>
sids
;
117
SECURITY_DESCRIPTOR
sd
;
118
ACL_wrapper
acl
;
119
120
// Stop any compiler silliness...
121
SecurityDescriptor
(
const
SecurityDescriptor
&);
122
SecurityDescriptor
&
__fastcall
operator
=(
const
SecurityDescriptor
&);
123
};
124
125
} }
experimental
NT-based
NTSpecific
SecurityDescriptor.hpp
Generated on Tue May 11 2021 17:21:39 for libjmmcg by
1.9.2