root/experimental/NT-based/NTSpecific/SecurityDescriptor.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. get
  2. get
  3. SD

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

/* [<][>][^][v][top][bottom][index][help] */