Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
8.2 KiB

  1. //#pragma title( "SDResolve.hpp - SDResolve Class definitions" )
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - SecureObject.hpp
  6. System - Domain Consolidation Toolkit
  7. Author - Christy Boles
  8. Created - 97/06/27
  9. Description - Securable object classes (File, Share, and Exchange) for FST and EST.
  10. Updates -
  11. ===============================================================================
  12. */
  13. #include <lm.h>
  14. #include <lmshare.h>
  15. #include <winspool.h>
  16. //#include "stdafx.h"
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <process.h>
  20. #ifndef TNODEINCLUDED
  21. #include "Tnode.hpp"
  22. #define TNODEINCLUDED
  23. #endif
  24. #ifdef SDRESOLVE
  25. #include "sdstat.hpp"
  26. #include "STArgs.hpp"
  27. #endif
  28. #include "UString.hpp"
  29. #include "EaLen.hpp"
  30. class TSecurableObject
  31. {
  32. protected:
  33. TNodeList changelog;
  34. WCHAR pathname[LEN_Path];
  35. HANDLE handle;
  36. bool owner_changed;
  37. bool group_changed;
  38. bool dacl_changed;
  39. bool sacl_changed;
  40. TSD * m_sd;
  41. public:
  42. TSecurableObject(){
  43. pathname[0]=0; handle = INVALID_HANDLE_VALUE;
  44. daceNS = 0;saceNS = 0;daceEx = 0;saceEx = 0;
  45. daceU = 0;saceU = 0;daceNT = 0;saceNT = 0;
  46. unkown = false; unkgrp = false; m_sd = NULL;
  47. }
  48. ~TSecurableObject();
  49. LPWSTR GetPathName() const { return (LPWSTR) &pathname; }
  50. void ResetHandle() { handle = INVALID_HANDLE_VALUE; }
  51. bool Changed() const { return (owner_changed || group_changed || dacl_changed || sacl_changed) ; }
  52. void Changed(bool bChanged) { m_sd->MarkAllChanged(bChanged); }
  53. int daceNS; // not selected
  54. int saceNS;
  55. int daceU; // unknown
  56. int saceU;
  57. int daceEx; // examined
  58. int saceEx;
  59. int daceNT; // no target
  60. int saceNT;
  61. bool unkown; // unknown owners
  62. bool unkgrp; // unknown groups
  63. bool UnknownOwner() const { return unkown;}
  64. bool UnknownGroup() const { return unkgrp; }
  65. void CopyAccessData(TSecurableObject * sourceFSD);
  66. virtual bool WriteSD() = 0;
  67. virtual bool ReadSD(const LPWSTR path) = 0;
  68. bool HasSecurity() const { return m_sd != NULL; }
  69. bool HasDacl() const { return ( m_sd && (m_sd->GetDacl()!=NULL) ) ; }
  70. bool HasSacl() const { return ( m_sd && (m_sd->GetSacl()!=NULL) ) ; }
  71. bool IsDaclChanged() const { return dacl_changed; }
  72. bool IsSaclChanged() const { return sacl_changed; }
  73. TSD * GetSecurity() { return m_sd; }
  74. #ifdef SDRESOLVE
  75. const TNodeList * GetChangeLog() const { return &changelog; }
  76. void LogOwnerChange(TAcctNode *acct){ changelog.InsertTop((TNode *)new TStatNode(acct,TStatNode::owner,TRUE)); }
  77. void LogGroupChange(TAcctNode *acct){ changelog.InsertTop((TNode *)new TStatNode(acct,TStatNode::group,TRUE)); }
  78. void LogDACEChange(TAcctNode *acct) { changelog.InsertTop((TNode *)new TStatNode(acct,TStatNode::dace,TRUE)); }
  79. void LogSACEChange(TAcctNode *acct) { changelog.InsertTop((TNode *)new TStatNode(acct,TStatNode::sace,TRUE)); }
  80. bool ResolveSD(
  81. SecurityTranslatorArgs * args, // in -cache to lookup accounts in
  82. TSDResolveStats * stat, // in -stats object to increment counters
  83. objectType type, // in -is this file or dir or share
  84. TSecurableObject * Last // in -Last SD for cache comparison
  85. );
  86. protected:
  87. PACL ResolveACL(PACL acl, TAccountCache *cache, TSDResolveStats *stat,
  88. bool *changes, BOOL verbose,int opType,objectType objType, BOOL bUseMapFile);
  89. public:
  90. bool ResolveSDInternal( TAccountCache *cache, TSDResolveStats *stat, BOOL verbose,int opType, objectType objType, BOOL bUseMapFile);
  91. #endif
  92. };
  93. /////////////////////////////////////////////////////////////////////////////////
  94. ///////////File and directory Acls
  95. /////////////////////////////////////////////////////////////////////////////////
  96. class TFileSD:public TSecurableObject
  97. {
  98. protected:
  99. bool m_bSystemFile;
  100. public:
  101. TFileSD(const LPWSTR fpath, bool bSystemFile = false);
  102. ~TFileSD();
  103. virtual bool WriteSD();
  104. virtual bool ReadSD(const LPWSTR path);
  105. };
  106. class TShareSD : public TSecurableObject
  107. {
  108. private:
  109. SHARE_INFO_502 * shareInfo;
  110. WCHAR * serverName;
  111. public:
  112. TShareSD(const LPWSTR name);
  113. ~TShareSD() { if (shareInfo)
  114. { NetApiBufferFree(shareInfo);
  115. shareInfo = NULL;
  116. }
  117. if ( serverName )
  118. {
  119. delete serverName;
  120. serverName = NULL;
  121. }
  122. }
  123. virtual bool WriteSD();
  124. virtual bool ReadSD(const LPWSTR path);
  125. bool SetSD(TSD* sd);
  126. };
  127. class TMapiSD : public TSecurableObject
  128. {
  129. WCHAR name[LEN_DistName];
  130. public:
  131. TMapiSD(SECURITY_DESCRIPTOR * pSD) { m_sd = new TSD(pSD,McsMailboxSD,FALSE); }
  132. void SetName(WCHAR const * str) { safecopy(name,str); }
  133. bool ReadSD(const LPWSTR path) { MCSASSERT(FALSE); return false; }
  134. bool WriteSD() { MCSASSERT(FALSE);return false; }
  135. };
  136. class TRegSD : public TSecurableObject
  137. {
  138. HKEY m_hKey;
  139. WCHAR name[LEN_DistName];
  140. public:
  141. TRegSD(const LPWSTR name, HKEY hKey);
  142. ~TRegSD() { }
  143. virtual bool WriteSD();
  144. virtual bool ReadSD(HKEY hKey);
  145. virtual bool ReadSD(const LPWSTR path) { MCSASSERT(FALSE); return false; }
  146. };
  147. class TPrintSD: public TSecurableObject
  148. {
  149. WCHAR name[MAX_PATH];
  150. HANDLE hPrinter;
  151. BYTE * buffer;
  152. public:
  153. TPrintSD(const LPWSTR name);
  154. ~TPrintSD()
  155. {
  156. if ( hPrinter != INVALID_HANDLE_VALUE )
  157. ClosePrinter(hPrinter);
  158. if ( buffer )
  159. delete buffer;
  160. }
  161. virtual bool WriteSD();
  162. virtual bool ReadSD(const LPWSTR path);
  163. };
  164. #ifdef SDRESOLVE
  165. int
  166. ResolveAll(
  167. SecurityTranslatorArgs * args, // in - arguments that determine settings for the translation
  168. TSDResolveStats * stats // in - object used for counting objects examined, modified, etc.
  169. );
  170. #endif
  171. WCHAR * // ret -machine-name prefix of pathname if pathname is a UNC path, otherwise returns NULL
  172. GetMachineName(
  173. const LPWSTR pathname // in -pathname from which to extract machine name
  174. );
  175. int EqualSignIndex(char * str);
  176. int ColonIndex(TCHAR * str);
  177. BOOL BuiltinRid(DWORD rid);
  178. #ifdef SDRESOLVE
  179. DWORD PrintSD(SECURITY_DESCRIPTOR * sd,WCHAR const * path);
  180. DWORD PermsPrint(WCHAR* path,objectType objType);
  181. #endif