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.

464 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: util.h
  7. //
  8. // Contents: definition of CWriteHtmlFile
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __SECMGR_UTIL__
  12. #define __SECMGR_UTIL__
  13. #define MULTISZ_DELIMITER L','
  14. #define MULTISZ_QUOTE L'"'
  15. #define DIALOG_TYPE_ANALYZE 0
  16. #define DIALOG_TYPE_APPLY 1
  17. #define DIALOG_DEFAULT_ANALYZE 2
  18. #define DIALOG_TYPE_REAPPLY 3
  19. #define DIALOG_TYPE_ADD_LOCATION 4
  20. #define DIALOG_FULLPATH_PROFILE 5
  21. #define DIALOG_TYPE_PROFILE 6
  22. #define DIALOG_SAVE_PROFILE 7
  23. #define DW_VALUE_FOREVER 1
  24. #define DW_VALUE_NEVER 2
  25. #define DW_VALUE_NOZERO 4
  26. #define DW_VALUE_OFF 8
  27. #define MERGED_TEMPLATE 1
  28. #define MERGED_INSPECT 2
  29. /////////////////////////////////////////////////////////////////////////////////////////
  30. // CWriteHtmlFile
  31. // Class for writting an html file.
  32. //
  33. // Call Create to create an html file. If [pszFile] is NULL then, a temporary SCE###.htm
  34. // file is created in the GetTempPath() directory.
  35. //
  36. // After Create has been called, Call Write to write the body of the HTML.
  37. // After the class has been destroyed, the file will be closed.
  38. //
  39. // Get the file name of the HTML by called GetFileName().
  40. class CWriteHtmlFile
  41. {
  42. public:
  43. CWriteHtmlFile();
  44. virtual ~CWriteHtmlFile();
  45. DWORD Create(LPCTSTR pszFile = NULL);
  46. DWORD Write( LPCTSTR pszString, ... );
  47. DWORD Write( UINT uRes );
  48. DWORD CopyTextFile( LPCTSTR pszFile, DWORD dwPosLow = 0, BOOL gInterpret = TRUE);
  49. DWORD Close( BOOL bDelete );
  50. public:
  51. int GetFileName( LPTSTR pszFileName, UINT nSize );
  52. protected:
  53. HANDLE m_hFileHandle; // The handle of the file.
  54. BOOL m_bErrored; // This is true if an operation fails.
  55. CString m_strFileName; // The file name.
  56. };
  57. DWORD MyRegSetValue( HKEY hKeyRoot,
  58. LPCTSTR SubKey,
  59. LPCTSTR ValueName,
  60. const BYTE *Value,
  61. const DWORD cbValue,
  62. const DWORD pRegType );
  63. DWORD MyRegQueryValue( HKEY hKeyRoot, LPCTSTR SubKey,
  64. LPCTSTR ValueName, PVOID *Value, LPDWORD pRegType );
  65. BOOL FilePathExist(LPCTSTR Name, BOOL IsPath, int Flag);
  66. void MyFormatResMessage(SCESTATUS rc, UINT residMessage, PSCE_ERROR_LOG_INFO errBuf,
  67. CString& strOut);
  68. void MyFormatMessage(SCESTATUS rc, LPCTSTR mes, PSCE_ERROR_LOG_INFO errBuf,
  69. CString& strOut);
  70. DWORD SceStatusToDosError(SCESTATUS SceStatus);
  71. BOOL CreateNewProfile(CString ProfileName, PSCE_PROFILE_INFO *ppspi = NULL);
  72. BOOL SetProfileInfo(LONG_PTR,LONG_PTR,PEDITTEMPLATE);
  73. BOOL GetSceStatusString(SCESTATUS status, CString *strStatus);
  74. void ErrorHandlerEx(WORD, LPTSTR);
  75. #define ErrorHandler() ErrorHandlerEx(__LINE__,TEXT( __FILE__))
  76. bool GetRightDisplayName(LPCTSTR szSystemName, LPCTSTR szName, LPTSTR szDisp, LPDWORD cbDisp);
  77. void DumpProfileInfo(PSCE_PROFILE_INFO pInfo);
  78. HRESULT MyMakeSelfRelativeSD(
  79. PSECURITY_DESCRIPTOR psdOriginal,
  80. PSECURITY_DESCRIPTOR* ppsdNew );
  81. PSCE_NAME_STATUS_LIST
  82. MergeNameStatusList(PSCE_NAME_LIST pTemplate, PSCE_NAME_LIST pInspect);
  83. BOOL VerifyKerberosInfo(PSCE_PROFILE_INFO pspi);
  84. DWORD
  85. SceRegEnumAllValues(
  86. IN OUT PDWORD pCount,
  87. IN OUT PSCE_REGISTRY_VALUE_INFO *paRegValues
  88. );
  89. #define STATUS_GROUP_MEMBERS 1
  90. #define STATUS_GROUP_MEMBEROF 2
  91. #define STATUS_GROUP_RECORD 3
  92. #define MY__SCE_MEMBEROF_NOT_APPLICABLE (DWORD)-100
  93. DWORD
  94. GetGroupStatus(
  95. DWORD status,
  96. int flag
  97. );
  98. //+--------------------------------------------------------------------------
  99. //
  100. // Function: AllocGetTempFileName
  101. //
  102. // Synopsis: Allocate and return a string with a temporary file name.
  103. //
  104. // Returns: The temporary file name, or 0 if a temp file can't be found
  105. //
  106. // History:
  107. //
  108. //---------------------------------------------------------------------------
  109. LPTSTR AllocGetTempFileName();
  110. //+--------------------------------------------------------------------------
  111. //
  112. // Function: UnexpandEnvironmentVariables
  113. //
  114. // Synopsis: Given a path, contract any leading members to use matching
  115. // environment variables, if any
  116. //
  117. // Arguments:
  118. // [szPath] - The path to expand
  119. //
  120. // Returns: The newly allocated path (NULL if it can't allocate memory)
  121. //
  122. // History:
  123. //
  124. //---------------------------------------------------------------------------
  125. LPTSTR UnexpandEnvironmentVariables(LPCTSTR szPath);
  126. //
  127. // change system database reg value from "DefaultProfile" to "SystemDatabase"
  128. // temporarily - until UI design change is checked in.
  129. //
  130. #define SYSTEM_DB_REG_VALUE TEXT("DefaultProfile")
  131. //+--------------------------------------------------------------------------
  132. //
  133. // Function: IsSystemDatabase
  134. //
  135. // Synopsis: Determine if a specific databse is the system database or a private one
  136. //
  137. // Arguments:
  138. // [szDBPath] - The database path to check
  139. //
  140. // Returns: True if szDBPath is the system database, false otherwise
  141. //
  142. // History:
  143. //
  144. //---------------------------------------------------------------------------
  145. BOOL IsSystemDatabase(LPCTSTR szDBPath);
  146. //+--------------------------------------------------------------------------
  147. //
  148. // Function: GetSystemDatabase
  149. //
  150. // Synopsis: Get the name of the current system database
  151. //
  152. // Arguments:
  153. // [szDBPath] - [in/out] a pointer for the name of the system database
  154. // The caller is responsible for freeing it.
  155. //
  156. //
  157. // Returns: S_OK if the system database is found, otherwise an error
  158. //
  159. // History:
  160. //
  161. //---------------------------------------------------------------------------
  162. HRESULT GetSystemDatabase(CString *szDBPath);
  163. //+--------------------------------------------------------------------------
  164. //
  165. // Function: ObjectStatusToString
  166. //
  167. // Synopsis: Convert an object status value to a printable string
  168. //
  169. // Arguments:
  170. // [status] - [in] The status value to convert
  171. // [str] - [out] The string to store the value in
  172. //
  173. //
  174. //---------------------------------------------------------------------------
  175. UINT ObjectStatusToString(DWORD status, CString *str);
  176. BOOL
  177. IsSecurityTemplate( // Returns TRUE if [pszFileName] is a valid security template
  178. LPCTSTR pszFileName
  179. );
  180. DWORD
  181. FormatDBErrorMessage( // Returns the string error message for a database return code
  182. SCESTATUS sceStatus,
  183. LPCTSTR pszDatabase,
  184. CString &strOut
  185. );
  186. int
  187. WriteSprintf( // Write format string to file
  188. IStream *pStm,
  189. LPCTSTR pszStr,
  190. ...
  191. );
  192. int
  193. ReadSprintf( // Read format string from IStream
  194. IStream *pStm,
  195. LPCTSTR pszStr,
  196. ...
  197. );
  198. #define FCE_IGNORE_FILEEXISTS 0x0001 // Ignore file exists problem and delete the
  199. // the file.
  200. DWORD
  201. FileCreateError(
  202. LPCTSTR pszFile,
  203. DWORD dwFlags
  204. );
  205. //+--------------------------------------------------------------------------
  206. //
  207. // Function: IsDBCSPath
  208. //
  209. // Synopsis: Check if a path contains DBCS characters
  210. //
  211. // Arguments: [pszFile] - [in] The path to check
  212. //
  213. // Returns: TRUE if pszFile contains characters that can't be
  214. // represented by a LPSTR
  215. //
  216. // FALSE if pszFile only contains characters that can
  217. // be represented by a LPSTR
  218. //
  219. //
  220. //+--------------------------------------------------------------------------
  221. BOOL
  222. IsDBCSPath(LPCTSTR pszFile);
  223. //+--------------------------------------------------------------------------
  224. //
  225. // Function: GetSeceditHelpFilename
  226. //
  227. // Synopsis: Return the fully qualified path the help file for Secedit
  228. //
  229. // Arguments: None
  230. //
  231. // Returns: a CString containing the fully qualified help file name.
  232. //
  233. //
  234. //+--------------------------------------------------------------------------
  235. CString
  236. GetSeceditHelpFilename();
  237. //+--------------------------------------------------------------------------
  238. //
  239. // Function: GetGpeditHelpFilename
  240. //
  241. // Synopsis: Return the fully qualified path the help file for Secedit
  242. //
  243. // Arguments: None
  244. //
  245. // Returns: a CString containing the fully qualified help file name.
  246. //
  247. //
  248. //+--------------------------------------------------------------------------
  249. CString GetGpeditHelpFilename();
  250. //+--------------------------------------------------------------------------
  251. //
  252. // Function: ExpandEnvironmentStringWrapper
  253. //
  254. // Synopsis: Takes an LPTSTR and expands the enviroment variables in it
  255. //
  256. // Arguments: Pointer to the string to expand.
  257. //
  258. // Returns: a CString containing the fully expanded string.
  259. //
  260. //+--------------------------------------------------------------------------
  261. CString ExpandEnvironmentStringWrapper(LPCTSTR psz);
  262. //+--------------------------------------------------------------------------
  263. //
  264. // Function: ExpandAndCreateFile
  265. //
  266. // Synopsis: Just does a normal CreateFile(), but expands the filename before
  267. // creating the file.
  268. //
  269. // Arguments: Same as CreateFile().
  270. //
  271. // Returns: HANDLE to the created file.
  272. //
  273. //+--------------------------------------------------------------------------
  274. HANDLE WINAPI ExpandAndCreateFile (
  275. LPCTSTR lpFileName,
  276. DWORD dwDesiredAccess,
  277. DWORD dwShareMode,
  278. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  279. DWORD dwCreationDisposition,
  280. DWORD dwFlagsAndAttributes,
  281. HANDLE hTemplateFile
  282. );
  283. //+--------------------------------------------------------------------------
  284. //
  285. // Function: GetDefault
  286. //
  287. // Synopsis: Find the default values for undefined policies
  288. //
  289. // Arguments: The IDS_* for the name of the policy
  290. //
  291. // Returns: The DWORD to assign as the default value for the policy.
  292. //
  293. //+--------------------------------------------------------------------------
  294. DWORD GetDefault(DWORD dwPolicy);
  295. //+--------------------------------------------------------------------------
  296. //
  297. // Function: GetRegDefault
  298. //
  299. // Synopsis: Free the default values for undefined policies
  300. //
  301. // Arguments: The PSCE_REGISTRY_VALUE to find the default for
  302. //
  303. // Returns: The DWORD to assign as the default value for the policy.
  304. //
  305. //+--------------------------------------------------------------------------
  306. DWORD GetRegDefault(PSCE_REGISTRY_VALUE_INFO pRV);
  307. //+--------------------------------------------------------------------------
  308. //
  309. // Function: IsAdmin
  310. //
  311. // Synopsis: Detects if the process is being run in an admin context
  312. //
  313. // Returns: TRUE if an admin, FALSE otherwise
  314. //
  315. //+--------------------------------------------------------------------------
  316. BOOL IsAdmin(void);
  317. //+--------------------------------------------------------------------------
  318. //
  319. // Function: MultiSZToSZ
  320. //
  321. // Synopsis: Converts a multiline string to a comma delimited normal string
  322. //
  323. // Returns: The converted string
  324. //
  325. //+--------------------------------------------------------------------------
  326. PWSTR MultiSZToSZ(PCWSTR sz);
  327. //+--------------------------------------------------------------------------
  328. //
  329. // Function: SZToMultiSZ
  330. //
  331. // Synopsis: Converts a comma delimited string to a multiline string
  332. //
  333. // Returns: The converted string
  334. //
  335. //+--------------------------------------------------------------------------
  336. PWSTR SZToMultiSZ(PCWSTR sz);
  337. //+--------------------------------------------------------------------------
  338. //
  339. // Function: MultiSZToDisp
  340. //
  341. // Synopsis: Converts a comma delimited multiline string to a display string
  342. //
  343. // Returns: The converted string
  344. //
  345. //+--------------------------------------------------------------------------
  346. void MultiSZToDisp(PCWSTR sz, CString &pszOut);
  347. //+--------------------------------------------------------------------------
  348. //
  349. // Function: GetDefaultTemplate
  350. //
  351. // Synopsis: Retrieves the default template from the system
  352. //
  353. // Returns: The template
  354. //
  355. //+--------------------------------------------------------------------------
  356. SCE_PROFILE_INFO *GetDefaultTemplate();
  357. //+--------------------------------------------------------------------------
  358. //
  359. // Function: GetDefaultFileSecurity
  360. //
  361. // Synopsis: Retrieves the default file security from the system. The
  362. // caller is responsible for freeing ppSD and pSeInfo
  363. //
  364. //+--------------------------------------------------------------------------
  365. HRESULT GetDefaultFileSecurity(PSECURITY_DESCRIPTOR *ppSD, SECURITY_INFORMATION *pSeInfo);
  366. //+--------------------------------------------------------------------------
  367. //
  368. // Function: GetDefaultRegKeySecurity
  369. //
  370. // Synopsis: Retrieves the default registry key security from the system. The
  371. // caller is responsible for freeing ppSD and pSeInfo
  372. //
  373. //+--------------------------------------------------------------------------
  374. HRESULT GetDefaultRegKeySecurity(PSECURITY_DESCRIPTOR *ppSD, SECURITY_INFORMATION *pSeInfo);
  375. //+--------------------------------------------------------------------------
  376. //
  377. // Function: GetDefaultserviceSecurity
  378. //
  379. // Synopsis: Retrieves the default service security from the system. The
  380. // caller is responsible for freeing ppSD and pSeInfo
  381. //
  382. //+--------------------------------------------------------------------------
  383. HRESULT GetDefaultServiceSecurity(PSECURITY_DESCRIPTOR *ppSD, SECURITY_INFORMATION *pSeInfo);
  384. BOOL
  385. LookupRegValueProperty(
  386. IN LPTSTR RegValueFullName,
  387. OUT LPTSTR *pDisplayName,
  388. OUT PDWORD displayType,
  389. OUT LPTSTR *pUnits OPTIONAL,
  390. OUT PREGCHOICE *pChoices OPTIONAL,
  391. OUT PREGFLAGS *pFlags OPTIONAL
  392. );
  393. BOOL
  394. GetSecureWizardName(
  395. OUT LPTSTR *ppstrPathName OPTIONAL,
  396. OUT LPTSTR *ppstrDisplayName OPTIONAL
  397. );
  398. #endif