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.

263 lines
6.4 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1997.
  5. //
  6. // File: util.cpp
  7. //
  8. // Contents: Defnes the utility class CUtility
  9. //
  10. // Classes:
  11. //
  12. // Methods:
  13. //
  14. // History: 23-Apr-96 BruceMa Created.
  15. //
  16. //----------------------------------------------------------------------
  17. #ifndef _UTIL_H_
  18. #define _UTIL_H_
  19. // note dependencies on the following two files
  20. #include "datapkt.h"
  21. #if !defined(STANDALONE_BUILD)
  22. extern "C"
  23. {
  24. #include <getuser.h>
  25. }
  26. #endif
  27. #define COM_RIGHTS_EXECUTE 1
  28. typedef struct
  29. {
  30. HKEY hRoot;
  31. TCHAR *szKeyPath;
  32. TCHAR *szValueName;
  33. } SSingleCallBack;
  34. typedef struct
  35. {
  36. HKEY hKey;
  37. HKEY *phClsids;
  38. unsigned cClsids;
  39. TCHAR *szTitle;
  40. } SRegKeyCallBack;
  41. typedef struct tagCallBackContext
  42. {
  43. PACKETTYPE pktType;
  44. int *pIndex;
  45. SECURITY_DESCRIPTOR *origSD;
  46. BOOL fIsIAC;
  47. union
  48. {
  49. SSingleCallBack single;
  50. SRegKeyCallBack regKey;
  51. } info;
  52. } SCallBackContext, *PCallBackContext;
  53. typedef struct
  54. {
  55. WORD Control;
  56. BYTE Reserved1;
  57. BYTE Revision;
  58. DWORD Owner;
  59. DWORD Group;
  60. DWORD Sacl;
  61. DWORD Dacl;
  62. } SSrSecurityDescriptor, *PSrSecurityDescriptor;
  63. typedef struct
  64. {
  65. BYTE Revision;
  66. BYTE Reserved1;
  67. WORD AclSize;
  68. WORD AceCount;
  69. WORD Reserved2;
  70. } SSrAcl, *PSrAcl;
  71. typedef struct
  72. {
  73. BYTE Type;
  74. BYTE Flags;
  75. WORD AceSize;
  76. ULONG AccessMask;
  77. } SSrAce, *PSrAce;
  78. #if !defined(STANDALONE_BUILD)
  79. #define USER_DETAILS_BUFFER_SIZE 1024
  80. typedef struct tagUserDetailsPlus
  81. {
  82. USERDETAILS sUserDetails;
  83. BYTE bBuffer[USER_DETAILS_BUFFER_SIZE];
  84. } SUserDetailsPlus;
  85. #endif
  86. enum dcomAclType { dcomAclAccess, dcomAclLaunch, dcomAclConfig };
  87. class CUtility
  88. {
  89. public:
  90. CUtility(void);
  91. ~CUtility(void);
  92. void PostErrorMessage(void);
  93. void PostErrorMessage(int err);
  94. void CkForAccessDenied(int err);
  95. BOOL CkAccessRights(HKEY hRoot, LPCTSTR szKeyPath);
  96. int WriteRegSzNamedValue(HKEY hRoot,
  97. LPCTSTR szKeyPath,
  98. LPCTSTR szValueName,
  99. LPCTSTR szVal,
  100. DWORD dwSize);
  101. int WriteRegMultiSzNamedValue(HKEY hRoot,
  102. LPCTSTR szKeyPath,
  103. LPCTSTR szValueName,
  104. LPCTSTR szVal,
  105. DWORD dwSize);
  106. int WriteRegDwordNamedValue(HKEY hRoot,
  107. LPCTSTR szKeyPath,
  108. LPCTSTR szValueName,
  109. DWORD dwVal);
  110. int WriteRegSingleACL(HKEY hRoot,
  111. LPCTSTR szKeyPath,
  112. LPCTSTR szValueName,
  113. PSECURITY_DESCRIPTOR pSec);
  114. int WriteRegKeyACL(HKEY hKey,
  115. HKEY *phClsids,
  116. unsigned cClsids,
  117. PSECURITY_DESCRIPTOR pSec,
  118. PSECURITY_DESCRIPTOR pSecOrig);
  119. int WriteRegKeyACL2(HKEY hRoot,
  120. HKEY hKey,
  121. PSECURITY_DESCRIPTOR pSec,
  122. PSECURITY_DESCRIPTOR pSecOrig);
  123. int WriteLsaPassword(CLSID appid,
  124. LPCTSTR szPassword);
  125. int WriteSrvIdentity(LPCTSTR szService,
  126. LPCTSTR szIdentity);
  127. int DeleteRegKey(HKEY hRoot, LPCTSTR szKeyPath);
  128. int DeleteRegValue(HKEY hRoot, LPCTSTR szKeyPath, LPCTSTR szValueName);
  129. int ACLEditor(HWND hWnd,
  130. HKEY hRoot,
  131. LPCTSTR szKeyPath,
  132. LPCTSTR szValueName,
  133. int *nIndex,
  134. PACKETTYPE pktType,
  135. dcomAclType eAclType);
  136. int ACLEditor2(HWND hWnd,
  137. HKEY hKey,
  138. HKEY *phClsids,
  139. unsigned cClsids,
  140. TCHAR *szTitle,
  141. int *nIndex,
  142. PACKETTYPE pktType);
  143. BOOL InvokeUserBrowser(HWND hWnd, TCHAR *szUser);
  144. BOOL InvokeMachineBrowser(TCHAR *szMachine);
  145. int StringFromGUID(GUID &rguid, TCHAR *lpsz, int cbMax);
  146. BOOL IsEqualGuid(GUID &guid1, GUID &guid2);
  147. BOOL AdjustPrivilege(TCHAR *szPrivilege);
  148. BOOL VerifyRemoteMachine(TCHAR *szRemoteMachine);
  149. BOOL RetrieveUserPassword(TCHAR *szAppid, CString &sPassword);
  150. BOOL StoreUserPassword(TCHAR *szAppid, CString &sPassword);
  151. BOOL LookupProcessInfo(SID **ppSid, TCHAR **ppszPrincName);
  152. BOOL MakeSecDesc(SID *pSid, SECURITY_DESCRIPTOR **ppSD);
  153. BOOL ChangeService(LPCTSTR szService,
  154. LPCTSTR szIdentity,
  155. LPCTSTR szPassword,
  156. LPCTSTR szDisplay);
  157. int UpdateDCOMInfo(void);
  158. void FixHelp(CWnd* pWnd);
  159. BOOL CompareSDs(PSrSecurityDescriptor pSD1, PSrSecurityDescriptor pSD2);
  160. int SetAccountRights( LPCTSTR szUser, TCHAR *szPrivilege);
  161. BOOL CopySD(SECURITY_DESCRIPTOR *pSrc, SECURITY_DESCRIPTOR **pDest);
  162. void CopyAbsoluteSD(SECURITY_DESCRIPTOR *pSrc, SECURITY_DESCRIPTOR **pDest);
  163. void SetInheritanceFlags(SECURITY_DESCRIPTOR *pSec);
  164. BOOL CheckForValidSD(SECURITY_DESCRIPTOR *pSD);
  165. BOOL SDisIAC(SECURITY_DESCRIPTOR *pSD);
  166. SECURITY_DESCRIPTOR * IACfromSD(SECURITY_DESCRIPTOR * pSD);
  167. SECURITY_DESCRIPTOR * SDfromIAC(SECURITY_DESCRIPTOR * pIAC);
  168. // added for BDC fix
  169. HRESULT GetPrincipalSID (LPCTSTR Principal, PSID *Sid);
  170. // checks if we're on a BDC
  171. BOOL IsBackupDC();
  172. TCHAR* PrimaryDCName();
  173. private:
  174. BOOL CheckSDForCOM_RIGHTS_EXECUTE(SECURITY_DESCRIPTOR *pSD);
  175. SCallBackContext m_sCallBackContext;
  176. void *m_args[8];
  177. HANDLE m_hRpc;
  178. BOOL m_bCheckedDC;
  179. BOOL m_bIsBdc;
  180. TCHAR* m_pszDomainController;
  181. };
  182. extern CUtility g_util;
  183. extern HKEY g_hAppid;
  184. extern HKEY *g_rghkCLSID;
  185. extern unsigned g_cCLSIDs;
  186. extern TCHAR *g_szAppTitle;
  187. extern BOOL g_fReboot;
  188. extern TCHAR *g_szAppid;
  189. #endif //_UTIL_H_