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.

572 lines
15 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. winsafer.h
  5. Abstract:
  6. This file implements the publicly exported functions, data types,
  7. data structures, and definitions usable by programs that directly
  8. interact with the Windows SAFER APIs.
  9. --*/
  10. #ifndef _WINSAFER_H
  11. #define _WINSAFER_H
  12. #include <guiddef.h>
  13. #include <wincrypt.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. //
  18. // Opaque datatype for representing handles to Safer objects.
  19. //
  20. DECLARE_HANDLE(SAFER_LEVEL_HANDLE);
  21. //
  22. // Constants to represent scope with SaferCreateLevel and others.
  23. //
  24. #define SAFER_SCOPEID_MACHINE 1
  25. #define SAFER_SCOPEID_USER 2
  26. //
  27. // Pre-defined levels that can be used with SaferCreateLevel
  28. //
  29. #define SAFER_LEVELID_FULLYTRUSTED 0x40000
  30. #define SAFER_LEVELID_NORMALUSER 0x20000
  31. #define SAFER_LEVELID_CONSTRAINED 0x10000
  32. #define SAFER_LEVELID_UNTRUSTED 0x01000
  33. #define SAFER_LEVELID_DISALLOWED 0x00000
  34. //
  35. // Flags to use when creating/opening a Level with SaferCreateLevel
  36. //
  37. #define SAFER_LEVEL_OPEN 1
  38. //
  39. // Maximum string size.
  40. //
  41. #define SAFER_MAX_FRIENDLYNAME_SIZE 256
  42. #define SAFER_MAX_DESCRIPTION_SIZE 256
  43. #define SAFER_MAX_HASH_SIZE 64
  44. //
  45. // Flags to use with SaferComputeTokenFromLevel.
  46. //
  47. #define SAFER_TOKEN_NULL_IF_EQUAL 0x00000001
  48. #define SAFER_TOKEN_COMPARE_ONLY 0x00000002
  49. #define SAFER_TOKEN_MAKE_INERT 0x00000004
  50. #define SAFER_TOKEN_WANT_FLAGS 0x00000008
  51. //
  52. // Flags for specifying what criteria within SAFER_CODE_PROPERTIES to evaluate
  53. // when finding code identity with SaferIdentifyLevel.
  54. //
  55. #define SAFER_CRITERIA_IMAGEPATH 0x00001
  56. #define SAFER_CRITERIA_NOSIGNEDHASH 0x00002
  57. #define SAFER_CRITERIA_IMAGEHASH 0x00004
  58. #define SAFER_CRITERIA_AUTHENTICODE 0x00008
  59. #define SAFER_CRITERIA_URLZONE 0x00010
  60. #define SAFER_CRITERIA_IMAGEPATH_NT 0x01000
  61. //
  62. // Code image information structure passed to SaferIdentifyLevel.
  63. //
  64. #include <pshpack8.h>
  65. typedef struct _SAFER_CODE_PROPERTIES
  66. {
  67. //
  68. // Must be initialized to be the size of this structure,
  69. // for the purposes of future/backwards compatibility.
  70. //
  71. DWORD cbSize;
  72. //
  73. // Must be initialized to the types of criteria that should
  74. // be considered when evaluating this structure. This can be
  75. // a combination of the SAFER_CRITERIA_xxxx flags. If not enough
  76. // of the structure elements needed to evaluate the criteria
  77. // types indicated were supplied, then some of those criteria
  78. // flags may be silently ignored. Specifying 0 for this value
  79. // will cause the entire structure's contents to be ignored.
  80. //
  81. DWORD dwCheckFlags;
  82. //
  83. // Optionally specifies the fully-qualified path and filename
  84. // to be used for discrimination checks based on the path.
  85. // The ImagePath will additionally be used to open and read the
  86. // file to identify any other discrimination criteria that was
  87. // unsupplied in this structure.
  88. //
  89. LPCWSTR ImagePath;
  90. //
  91. // Optionally specifies a file handle that has been opened to
  92. // code image with at least GENERIC_READ access. The handle will
  93. // be used instead of explicitly opening the file again to compute
  94. // other discrimination criteria that was unsupplied in this structure.
  95. //
  96. HANDLE hImageFileHandle;
  97. //
  98. // Optionally specifies the pre-determined Internet Explorer
  99. // security zone. These enums are defined within urlmon.h
  100. // For example: URLZONE_LOCAL_MACHINE, URLZONE_INTRANET,
  101. // URLZONE_TRUSTED, URLZONE_INTERNET, or URLZONE_UNTRUSTED.
  102. //
  103. DWORD UrlZoneId;
  104. //
  105. // Optionally specifies the pre-computed hash of the image.
  106. // The supplied hash is interpreted as being valid if ImageSize
  107. // is non-zero and dwImageHashSize is non-zero and HashAlgorithm
  108. // represents a valid hashing algorithm from wincrypt.h
  109. //
  110. // If the supplied hash fails to meet the conditions above, then
  111. // the hash will be automatically computed against:
  112. // 1) by using ImageSize and pByteBlock if both are non-zero.
  113. // 2) by using hImageFileHandle if it is non-null.
  114. // 3) by attempting to open ImagePath if it is non-null.
  115. //
  116. BYTE ImageHash[SAFER_MAX_HASH_SIZE];
  117. DWORD dwImageHashSize;
  118. LARGE_INTEGER ImageSize;
  119. ALG_ID HashAlgorithm;
  120. //
  121. // Optionally specifies a memory block of memory representing
  122. // the image for which the trust is being requested for. When
  123. // this member is specified, ImageSize must also be supplied.
  124. //
  125. LPBYTE pByteBlock;
  126. //
  127. // Optionally gives the arguments used for Authenticode signer
  128. // certificate verification. These arguments are supplied to the
  129. // WinVerifyTrust() API and control the user-interface prompting
  130. // to accept untrusted certificates.
  131. //
  132. HWND hWndParent;
  133. DWORD dwWVTUIChoice;
  134. } SAFER_CODE_PROPERTIES, *PSAFER_CODE_PROPERTIES;
  135. #include <poppack.h>
  136. //
  137. // Masks for the per-identity WinSafer flags
  138. //
  139. #define SAFER_POLICY_JOBID_MASK 0xFF000000
  140. #define SAFER_POLICY_JOBID_CONSTRAINED 0x04000000
  141. #define SAFER_POLICY_JOBID_UNTRUSTED 0x03000000
  142. #define SAFER_POLICY_ONLY_EXES 0x00010000
  143. #define SAFER_POLICY_SANDBOX_INERT 0x00020000
  144. #define SAFER_POLICY_UIFLAGS_MASK 0x000000FF
  145. #define SAFER_POLICY_UIFLAGS_INFORMATION_PROMPT 0x00000001
  146. #define SAFER_POLICY_UIFLAGS_OPTION_PROMPT 0x00000002
  147. //
  148. // Information classes on the overall policy that can be queried
  149. // with SaferSet/GetPolicyInformation and set at different
  150. // policy scopes based on access of the caller.
  151. //
  152. typedef enum _SAFER_POLICY_INFO_CLASS
  153. {
  154. //
  155. // Accesses the list of all Levels defined in a policy.
  156. // The corresponding data element is a buffer that is filled
  157. // with multiple DWORDs, each representing the LevelIds that
  158. // are defined within this scope.
  159. //
  160. SaferPolicyLevelList = 1,
  161. //
  162. // for transparent enforcement of policy in the execution
  163. // framework -- will be used by native code execution but can
  164. // be used by any policy enforcement environment.
  165. // Corresponding data element is a DWORD holding a Boolean value.
  166. //
  167. SaferPolicyEnableTransparentEnforcement,
  168. //
  169. // Returns the name of the Level that has been designed
  170. // as the default level within the specified scope.
  171. // The corresponding data element is a single DWORD buffer
  172. // representing the LevelId of the default Level. If no
  173. // level has been configured to be the default, then the
  174. // GetInfo API will return FALSE and GetLastError will
  175. // return ERROR_NOT_FOUND.
  176. //
  177. SaferPolicyDefaultLevel,
  178. //
  179. // Returns whether Code Identities or Default Level within the
  180. // user scope can be considered during identification.
  181. //
  182. SaferPolicyEvaluateUserScope,
  183. //
  184. // Control Flags for for safer policy scope.
  185. //
  186. SaferPolicyScopeFlags
  187. } SAFER_POLICY_INFO_CLASS;
  188. //
  189. // Enumerations used for retrieving specific information about a
  190. // single authorization Level via SaferGet/SetInformationFromLevel.
  191. //
  192. typedef enum _SAFER_OBJECT_INFO_CLASS
  193. {
  194. SaferObjectLevelId = 1, // get: DWORD
  195. SaferObjectScopeId, // get: DWORD
  196. SaferObjectFriendlyName, // get/set: LPCWSTR
  197. SaferObjectDescription, // get/set: LPCWSTR
  198. SaferObjectBuiltin, // get: DWORD boolean
  199. SaferObjectDisallowed, // get: DWORD boolean
  200. SaferObjectDisableMaxPrivilege, // get: DWORD boolean
  201. SaferObjectInvertDeletedPrivileges, // get: DWORD boolean
  202. SaferObjectDeletedPrivileges, // get: TOKEN_PRIVILEGES
  203. SaferObjectDefaultOwner, // get: TOKEN_OWNER
  204. SaferObjectSidsToDisable, // get: TOKEN_GROUPS
  205. SaferObjectRestrictedSidsInverted, // get: TOKEN_GROUPS
  206. SaferObjectRestrictedSidsAdded, // get: TOKEN_GROUPS
  207. //
  208. // To enumerate all identities, call GetInfo with
  209. // SaferObjectAllIdentificationGuids.
  210. //
  211. SaferObjectAllIdentificationGuids, // get: SAFER_IDENTIFICATION_GUIDS
  212. //
  213. // To create a new identity, call SetInfo with
  214. // SaferObjectSingleIdentification with a new
  215. // unique GUID that you have generated.
  216. // To get details on a single identity, call GetInfo with
  217. // SaferObjectSingleIdentification with desired GUID.
  218. // To modify details of a single identity, call SetInfo with
  219. // SaferObjectSingleIdentification with desired info and GUID.
  220. // To delete an identity, call SetInfo with
  221. // SaferObjectSingleIdentification with the
  222. // header.dwIdentificationType set to 0.
  223. //
  224. SaferObjectSingleIdentification, // get/set: SAFER_IDENTIFICATION_*
  225. SaferObjectExtendedError // get: DWORD dwError
  226. } SAFER_OBJECT_INFO_CLASS;
  227. //
  228. // Structures and enums used by the SaferGet/SetLevelInformation APIs.
  229. //
  230. #include <pshpack8.h>
  231. typedef enum _SAFER_IDENTIFICATION_TYPES
  232. {
  233. SaferIdentityDefault,
  234. SaferIdentityTypeImageName = 1,
  235. SaferIdentityTypeImageHash,
  236. SaferIdentityTypeUrlZone,
  237. SaferIdentityTypeCertificate
  238. } SAFER_IDENTIFICATION_TYPES;
  239. typedef struct _SAFER_IDENTIFICATION_HEADER
  240. {
  241. //
  242. // indicates the type of the structure, one of SaferIdentityType*
  243. //
  244. SAFER_IDENTIFICATION_TYPES dwIdentificationType;
  245. //
  246. // size of the whole structure, not just the common header.
  247. //
  248. DWORD cbStructSize;
  249. //
  250. // the unique GUID of the Identity in question.
  251. //
  252. GUID IdentificationGuid;
  253. //
  254. // last change of this identification.
  255. //
  256. FILETIME lastModified;
  257. } SAFER_IDENTIFICATION_HEADER, *PSAFER_IDENTIFICATION_HEADER;
  258. typedef struct _SAFER_PATHNAME_IDENTIFICATION
  259. {
  260. //
  261. // header.dwIdentificationType must be SaferIdentityTypeImageName
  262. // header.cbStructSize must be sizeof(SAFER_PATHNAME_IDENTIFICATION)
  263. //
  264. SAFER_IDENTIFICATION_HEADER header;
  265. //
  266. // user-entered description
  267. //
  268. WCHAR Description[SAFER_MAX_DESCRIPTION_SIZE];
  269. //
  270. // filepath or name, possibly with vars
  271. //
  272. PWCHAR ImageName;
  273. //
  274. // any combo of SAFER_POL_SAFERFLAGS_*
  275. //
  276. DWORD dwSaferFlags;
  277. } SAFER_PATHNAME_IDENTIFICATION, *PSAFER_PATHNAME_IDENTIFICATION;
  278. typedef struct _SAFER_HASH_IDENTIFICATION
  279. {
  280. //
  281. // header.dwIdentificationType must be SaferIdentityTypeImageHash
  282. // header.cbStructSize must be sizeof(SAFER_HASH_IDENTIFICATION)
  283. //
  284. SAFER_IDENTIFICATION_HEADER header;
  285. //
  286. // user-entered friendly name, initially from file's resources.
  287. //
  288. WCHAR Description[SAFER_MAX_DESCRIPTION_SIZE];
  289. //
  290. // user-entered description.
  291. //
  292. WCHAR FriendlyName[SAFER_MAX_FRIENDLYNAME_SIZE];
  293. //
  294. // amount of ImageHash actually used, in bytes (MD5 is 16 bytes).
  295. //
  296. DWORD HashSize;
  297. //
  298. // computed hash data itself.
  299. //
  300. BYTE ImageHash[SAFER_MAX_HASH_SIZE];
  301. //
  302. // algorithm in which the hash was computed (CALG_MD5, etc).
  303. //
  304. ALG_ID HashAlgorithm;
  305. //
  306. // size of the original file in bytes.
  307. //
  308. LARGE_INTEGER ImageSize;
  309. //
  310. // any combo of SAFER_POL_SAFERFLAGS_*
  311. //
  312. DWORD dwSaferFlags;
  313. } SAFER_HASH_IDENTIFICATION, *PSAFER_HASH_IDENTIFICATION;
  314. typedef struct _SAFER_URLZONE_IDENTIFICATION
  315. {
  316. //
  317. // header.dwIdentificationType must be SaferIdentityTypeUrlZone
  318. // header.cbStructSize must be sizeof(SAFER_URLZONE_IDENTIFICATION)
  319. //
  320. SAFER_IDENTIFICATION_HEADER header;
  321. //
  322. // any single URLZONE_* from urlmon.h
  323. //
  324. DWORD UrlZoneId;
  325. //
  326. // any combo of SAFER_POLICY_*
  327. //
  328. DWORD dwSaferFlags;
  329. } SAFER_URLZONE_IDENTIFICATION, *PSAFER_URLZONE_IDENTIFICATION;
  330. #include <poppack.h>
  331. //
  332. // Functions related to querying and setting the global policy
  333. // controls to disable transparent enforcement, and perform level
  334. // enumeration operations.
  335. //
  336. WINADVAPI
  337. BOOL WINAPI
  338. SaferGetPolicyInformation(
  339. IN DWORD dwScopeId,
  340. IN SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
  341. IN DWORD InfoBufferSize,
  342. IN OUT PVOID InfoBuffer,
  343. IN OUT PDWORD InfoBufferRetSize,
  344. IN LPVOID lpReserved
  345. );
  346. WINADVAPI
  347. BOOL WINAPI
  348. SaferSetPolicyInformation(
  349. IN DWORD dwScopeId,
  350. IN SAFER_POLICY_INFO_CLASS SaferPolicyInfoClass,
  351. IN DWORD InfoBufferSize,
  352. IN PVOID InfoBuffer,
  353. IN LPVOID lpReserved
  354. );
  355. //
  356. // Functions to open or close a handle to a Safer Level.
  357. //
  358. WINADVAPI
  359. BOOL WINAPI
  360. SaferCreateLevel(
  361. IN DWORD dwScopeId,
  362. IN DWORD dwLevelId,
  363. IN DWORD OpenFlags,
  364. OUT SAFER_LEVEL_HANDLE * pLevelHandle,
  365. IN LPVOID lpReserved
  366. );
  367. WINADVAPI
  368. BOOL WINAPI
  369. SaferCloseLevel(
  370. IN SAFER_LEVEL_HANDLE hLevelHandle
  371. );
  372. WINADVAPI
  373. BOOL WINAPI
  374. SaferIdentifyLevel(
  375. IN DWORD dwNumProperties,
  376. IN PSAFER_CODE_PROPERTIES pCodeProperties,
  377. OUT SAFER_LEVEL_HANDLE * pLevelHandle,
  378. IN LPVOID lpReserved
  379. );
  380. WINADVAPI
  381. BOOL WINAPI
  382. SaferComputeTokenFromLevel(
  383. IN SAFER_LEVEL_HANDLE LevelHandle,
  384. IN HANDLE InAccessToken OPTIONAL,
  385. OUT PHANDLE OutAccessToken,
  386. IN DWORD dwFlags,
  387. IN LPVOID lpReserved
  388. );
  389. WINADVAPI
  390. BOOL WINAPI
  391. SaferGetLevelInformation(
  392. IN SAFER_LEVEL_HANDLE LevelHandle,
  393. IN SAFER_OBJECT_INFO_CLASS dwInfoType,
  394. OUT LPVOID lpQueryBuffer OPTIONAL,
  395. IN DWORD dwInBufferSize,
  396. OUT LPDWORD lpdwOutBufferSize
  397. );
  398. WINADVAPI
  399. BOOL WINAPI
  400. SaferSetLevelInformation(
  401. IN SAFER_LEVEL_HANDLE LevelHandle,
  402. IN SAFER_OBJECT_INFO_CLASS dwInfoType,
  403. IN LPVOID lpQueryBuffer,
  404. IN DWORD dwInBufferSize
  405. );
  406. //
  407. // This function performs logging of messages to the Application
  408. // event log. This is called by the hooks within CreateProcess,
  409. // ShellExecute and cmd when a lower trust evaluation result occurs.
  410. //
  411. WINADVAPI
  412. BOOL WINAPI
  413. SaferRecordEventLogEntry(
  414. IN SAFER_LEVEL_HANDLE hLevel,
  415. IN LPCWSTR szTargetPath,
  416. IN LPVOID lpReserved
  417. );
  418. WINADVAPI
  419. BOOL WINAPI
  420. SaferiIsExecutableFileType(
  421. IN LPCWSTR szFullPathname,
  422. IN BOOLEAN bFromShellExecute
  423. );
  424. #ifdef __cplusplus
  425. }
  426. #endif
  427. #endif