Source code of Windows XP (NT5)
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.

214 lines
7.9 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. public:
  100. TFileSD(const LPWSTR fpath);
  101. ~TFileSD();
  102. virtual bool WriteSD();
  103. virtual bool ReadSD(const LPWSTR path);
  104. };
  105. class TShareSD : public TSecurableObject
  106. {
  107. private:
  108. SHARE_INFO_502 * shareInfo;
  109. WCHAR * serverName;
  110. public:
  111. TShareSD(const LPWSTR name);
  112. ~TShareSD() { if (shareInfo)
  113. { NetApiBufferFree(shareInfo);
  114. shareInfo = NULL;
  115. }
  116. if ( serverName )
  117. {
  118. delete serverName;
  119. serverName = NULL;
  120. }
  121. }
  122. virtual bool WriteSD();
  123. virtual bool ReadSD(const LPWSTR path);
  124. };
  125. class TMapiSD : public TSecurableObject
  126. {
  127. WCHAR name[LEN_DistName];
  128. public:
  129. TMapiSD(SECURITY_DESCRIPTOR * pSD) { m_sd = new TSD(pSD,McsMailboxSD,FALSE); }
  130. void SetName(WCHAR const * str) { safecopy(name,str); }
  131. bool ReadSD(const LPWSTR path) { MCSASSERT(FALSE); return false; }
  132. bool WriteSD() { MCSASSERT(FALSE);return false; }
  133. };
  134. class TRegSD : public TSecurableObject
  135. {
  136. HKEY m_hKey;
  137. WCHAR name[LEN_DistName];
  138. public:
  139. TRegSD(const LPWSTR name, HKEY hKey);
  140. ~TRegSD() { }
  141. virtual bool WriteSD();
  142. virtual bool ReadSD(HKEY hKey);
  143. virtual bool ReadSD(const LPWSTR path) { MCSASSERT(FALSE); return false; }
  144. };
  145. class TPrintSD: public TSecurableObject
  146. {
  147. WCHAR name[MAX_PATH];
  148. HANDLE hPrinter;
  149. BYTE * buffer;
  150. public:
  151. TPrintSD(const LPWSTR name);
  152. ~TPrintSD()
  153. {
  154. if ( hPrinter != INVALID_HANDLE_VALUE )
  155. ClosePrinter(hPrinter);
  156. if ( buffer )
  157. delete buffer;
  158. }
  159. virtual bool WriteSD();
  160. virtual bool ReadSD(const LPWSTR path);
  161. };
  162. #ifdef SDRESOLVE
  163. int
  164. ResolveAll(
  165. SecurityTranslatorArgs * args, // in - arguments that determine settings for the translation
  166. TSDResolveStats * stats // in - object used for counting objects examined, modified, etc.
  167. );
  168. #endif
  169. WCHAR * // ret -machine-name prefix of pathname if pathname is a UNC path, otherwise returns NULL
  170. GetMachineName(
  171. const LPWSTR pathname // in -pathname from which to extract machine name
  172. );
  173. int EqualSignIndex(char * str);
  174. int ColonIndex(TCHAR * str);
  175. BOOL BuiltinRid(DWORD rid);
  176. #ifdef SDRESOLVE
  177. DWORD PrintSD(SECURITY_DESCRIPTOR * sd,WCHAR const * path);
  178. DWORD PermsPrint(WCHAR* path,objectType objType);
  179. #endif