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.

455 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. util.h
  5. Abstract:
  6. Definitions of Utility routines
  7. Author:
  8. Cliff Van Dyke (cliffv) 11-Apr-2001
  9. --*/
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Macros
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Macros for locking the global resource
  20. //
  21. #define AzpLockResourceExclusive( _Resource ) \
  22. SafeAcquireResourceExclusive( _Resource, TRUE )
  23. #define AzpIsLockedExclusive( _Resource ) \
  24. (SafeNumberOfActive( _Resource ) < 0 )
  25. #define AzpLockResourceShared( _Resource ) \
  26. SafeAcquireResourceShared( _Resource, TRUE )
  27. #define AzpLockResourceSharedToExclusive( _Resource ) \
  28. SafeConvertSharedToExclusive( _Resource )
  29. #define AzpLockResourceExclusiveToShared( _Resource ) \
  30. SafeConvertExclusiveToShared( _Resource )
  31. #define AzpIsLockedShared( _Resource ) \
  32. (SafeNumberOfActive( _Resource ) != 0 )
  33. #define AzpUnlockResource( _Resource ) \
  34. SafeReleaseResource( _Resource )
  35. //
  36. // Macros for safe critsect
  37. //
  38. #define AzpIsCritsectLocked( _CritSect ) \
  39. ( SafeCritsecLockCount( _CritSect ) != -1L)
  40. /////////////////////////////////////////////////////////////////////////////
  41. //
  42. // Structure definitions
  43. //
  44. /////////////////////////////////////////////////////////////////////////////
  45. //
  46. // Generic counted string.
  47. // Can't use UNICODE_STRING since that is limited to 32K characters.
  48. //
  49. typedef struct _AZP_STRING {
  50. //
  51. // Pointer to the string
  52. //
  53. LPWSTR String;
  54. //
  55. // Size of the string in bytes (including trailing zero)
  56. //
  57. ULONG StringSize;
  58. //
  59. // String is a binary SID
  60. //
  61. BOOL IsSid;
  62. } AZP_STRING, *PAZP_STRING;
  63. //
  64. // Generic expandable array of pointers
  65. //
  66. typedef struct _AZP_PTR_ARRAY {
  67. //
  68. // Pointer to allocated array of pointers
  69. //
  70. PVOID *Array;
  71. //
  72. // Number of elements actually used in array
  73. //
  74. ULONG UsedCount;
  75. //
  76. // Number of elemets allocated in the array
  77. //
  78. ULONG AllocatedCount;
  79. #define AZP_PTR_ARRAY_INCREMENT 4 // Amount to grow the array by
  80. } AZP_PTR_ARRAY, *PAZP_PTR_ARRAY;
  81. /////////////////////////////////////////////////////////////////////////////
  82. //
  83. // Global definitions
  84. //
  85. /////////////////////////////////////////////////////////////////////////////
  86. extern LIST_ENTRY AzGlAllocatedBlocks;
  87. extern SAFE_CRITICAL_SECTION AzGlAllocatorCritSect;
  88. extern PSID AzGlCreatorOwnerSid;
  89. extern PSID AzGlCreatorGroupSid;
  90. extern PSID AzGlWorldSid;
  91. extern ULONG AzGlWorldSidSize;
  92. /////////////////////////////////////////////////////////////////////////////
  93. //
  94. // Procedure definitions
  95. //
  96. /////////////////////////////////////////////////////////////////////////////
  97. PVOID
  98. AzpAllocateHeap(
  99. IN SIZE_T Size,
  100. IN LPSTR pDescr OPTIONAL
  101. );
  102. PVOID
  103. AzpAllocateHeapSafe(
  104. IN SIZE_T Size
  105. );
  106. VOID
  107. AzpFreeHeap(
  108. IN PVOID Buffer
  109. );
  110. PVOID
  111. AzpAvlAllocate(
  112. IN PRTL_GENERIC_TABLE Table,
  113. IN CLONG ByteSize
  114. );
  115. VOID
  116. AzpAvlFree(
  117. IN PRTL_GENERIC_TABLE Table,
  118. IN PVOID Buffer
  119. );
  120. VOID
  121. AzpInitString(
  122. OUT PAZP_STRING AzpString,
  123. IN LPCWSTR String OPTIONAL
  124. );
  125. DWORD
  126. AzpDuplicateString(
  127. OUT PAZP_STRING AzpOutString,
  128. IN PAZP_STRING AzpInString
  129. );
  130. DWORD
  131. AzpCaptureString(
  132. OUT PAZP_STRING AzpString,
  133. IN LPCWSTR String,
  134. IN ULONG MaximumLength,
  135. IN BOOLEAN NullOk
  136. );
  137. VOID
  138. AzpInitSid(
  139. OUT PAZP_STRING AzpString,
  140. IN PSID Sid
  141. );
  142. DWORD
  143. AzpCaptureSid(
  144. OUT PAZP_STRING AzpString,
  145. IN PSID Sid
  146. );
  147. DWORD
  148. AzpCaptureLong(
  149. IN PVOID PropertyValue,
  150. OUT PLONG UlongValue
  151. );
  152. BOOL
  153. AzpEqualStrings(
  154. IN PAZP_STRING AzpString1,
  155. IN PAZP_STRING AzpString2
  156. );
  157. LONG
  158. AzpCompareSidString(
  159. IN PAZP_STRING AzpString1,
  160. IN PAZP_STRING AzpString2
  161. );
  162. LONG
  163. AzpCompareSid(
  164. IN PSID Sid1,
  165. IN PSID Sid2
  166. );
  167. LONG
  168. AzpCompareStrings(
  169. IN PAZP_STRING AzpString1,
  170. IN PAZP_STRING AzpString2
  171. );
  172. LONG
  173. AzpCompareDeltaEntries(
  174. const void *DeltaEntry1,
  175. const void *DeltaEntry2
  176. );
  177. VOID
  178. AzpSwapStrings(
  179. IN OUT PAZP_STRING AzpString1,
  180. IN OUT PAZP_STRING AzpString2
  181. );
  182. VOID
  183. AzpFreeString(
  184. IN PAZP_STRING AzpString
  185. );
  186. BOOLEAN
  187. AzpBsearchPtr (
  188. IN PAZP_PTR_ARRAY AzpPtrArray,
  189. IN PVOID Key,
  190. IN LONG (*Compare)(const void *, const void *),
  191. OUT PULONG InsertionPoint OPTIONAL
  192. );
  193. #define AZP_ADD_ENDOFLIST 0xFFFFFFFF
  194. DWORD
  195. AzpAddPtr(
  196. IN PAZP_PTR_ARRAY AzpPtrArray,
  197. IN PVOID Pointer,
  198. IN ULONG Index
  199. );
  200. VOID
  201. AzpRemovePtrByIndex(
  202. IN PAZP_PTR_ARRAY AzpPtrArray,
  203. IN ULONG Index
  204. );
  205. VOID
  206. AzpRemovePtrByPtr(
  207. IN PAZP_PTR_ARRAY AzpPtrArray,
  208. IN PVOID Pointer
  209. );
  210. PVOID
  211. AzpGetStringProperty(
  212. IN PAZP_STRING AzpString
  213. );
  214. PVOID
  215. AzpGetUlongProperty(
  216. IN ULONG UlongValue
  217. );
  218. BOOLEAN
  219. AzpTimeHasElapsed(
  220. IN PLARGE_INTEGER StartTime,
  221. IN DWORD Timeout
  222. );
  223. BOOL
  224. AzDllInitialize(VOID);
  225. BOOL
  226. AzDllUnInitialize(VOID);
  227. DWORD
  228. AzpHresultToWinStatus(
  229. HRESULT hr
  230. );
  231. DWORD
  232. AzpSafeArrayPointerFromVariant(
  233. IN VARIANT* Variant,
  234. IN BOOLEAN NullOk,
  235. OUT SAFEARRAY **retSafeArray
  236. );
  237. DWORD
  238. AzpGetCurrentToken(
  239. OUT PHANDLE hToken
  240. );
  241. DWORD
  242. AzpChangeSinglePrivilege(
  243. IN DWORD PrivilegeValue,
  244. IN HANDLE hToken,
  245. IN PTOKEN_PRIVILEGES NewPrivilegeState,
  246. OUT PTOKEN_PRIVILEGES OldPrivilegeState OPTIONAL
  247. );
  248. DWORD
  249. AzpConvertAbsoluteSDToSelfRelative(
  250. IN PSECURITY_DESCRIPTOR pAbsoluteSd,
  251. OUT PSECURITY_DESCRIPTOR *ppSelfRelativeSd
  252. );
  253. //
  254. // This routine sets our default common ldap binding options
  255. //
  256. DWORD
  257. AzpADSetDefaultLdapOptions (
  258. IN OUT PLDAP pHandle,
  259. IN PCWSTR pDomainName OPTIONAL
  260. );
  261. //
  262. // This routine convert JScript style array object to
  263. // safearrays that our functions use.
  264. //
  265. HRESULT
  266. AzpGetSafearrayFromArrayObject (
  267. IN VARIANT varSAorObj,
  268. OUT SAFEARRAY** ppsaData
  269. );
  270. //
  271. // This routine returns the sequence number for an application object
  272. // to check the validity of COM handles after the application has been
  273. // closed
  274. DWORD
  275. AzpRetrieveApplicationSequenceNumber(
  276. IN AZ_HANDLE AzHandle
  277. );
  278. /////////////////////////////////////////////////////////////////////////////
  279. //
  280. // Debugging Support
  281. //
  282. /////////////////////////////////////////////////////////////////////////////
  283. #if DBG
  284. #define AZROLESDBG 1
  285. #endif // DBG
  286. #ifdef AZROLESDBG
  287. #define AzPrint(_x_) AzpPrintRoutine _x_
  288. VOID
  289. AzpPrintRoutine(
  290. IN DWORD DebugFlag,
  291. IN LPSTR FORMATSTRING, // PRINTF()-STYLE FORMAT STRING.
  292. ... // OTHER ARGUMENTS ARE POSSIBLE.
  293. );
  294. VOID
  295. AzpDumpGuid(
  296. IN DWORD DebugFlag,
  297. IN GUID *Guid
  298. );
  299. VOID
  300. AzpDumpGoRef(
  301. IN LPSTR Text,
  302. IN struct _GENERIC_OBJECT *GenericObject
  303. );
  304. //
  305. // Values of DebugFlag
  306. // The values of this flag are organized into bytes:
  307. // The least significant byte are flags that one always wants on
  308. // The next byte are flags that provider a reasonable level of verbosity
  309. // The next byte are flags that correspond to levels from the 2nd byte but are more verbose
  310. // The most significant byte are flags that are generally very verbose
  311. //
  312. #define AZD_CRITICAL 0x00000001 // Debug most critical errors
  313. #define AZD_INVPARM 0x00000002 // Invalid Parameter
  314. #define AZD_PERSIST 0x00000100 // Persistence code
  315. #define AZD_ACCESS 0x00000200 // Debug access check
  316. #define AZD_SCRIPT 0x00000400 // Debug bizrule scripts
  317. #define AZD_DISPATCH 0x00000800 // Debug IDispatch interface code
  318. #define AZD_XML 0x00001000 // xml store
  319. #define AZD_AD 0x00002000 // Debug LDAP provider
  320. #define AZD_PERSIST_MORE 0x00010000 // Persistence code (verbose mode)
  321. #define AZD_ACCESS_MORE 0x00020000 // Debug access check (verbose mode)
  322. #define AZD_SCRIPT_MORE 0x00040000 // Debug bizrule scripts (verbose mode)
  323. #define AZD_HANDLE 0x01000000 // Debug handle open/close
  324. #define AZD_OBJLIST 0x02000000 // Object list linking
  325. #define AZD_REF 0x04000000 // Debug object ref count
  326. #define AZD_DOMREF 0x08000000 // Debug domain ref count
  327. #define AZD_ALL 0xFFFFFFFF
  328. //
  329. // The order below defines the order in which locks must be acquired.
  330. // Violating this order will result in asserts firing in debug builds.
  331. //
  332. // Do not change the order without first verifying thoroughly that the change is safe.
  333. //
  334. enum {
  335. SAFE_CLOSE_APPLICATION = 1,
  336. SAFE_CLIENT_CONTEXT,
  337. SAFE_PERSIST_LOCK,
  338. SAFE_GLOBAL_LOCK,
  339. SAFE_DOMAIN_LIST,
  340. SAFE_DOMAIN,
  341. SAFE_FREE_SCRIPT_LIST,
  342. SAFE_RUNNING_SCRIPT_LIST,
  343. SAFE_LOGFILE,
  344. SAFE_ALLOCATOR,
  345. SAFE_MAX_LOCK
  346. };
  347. //
  348. // Globals
  349. //
  350. extern SAFE_CRITICAL_SECTION AzGlLogFileCritSect;
  351. extern ULONG AzGlDbFlag;
  352. #else
  353. // Non debug version
  354. #define AzPrint(_x_)
  355. #define AzpDumpGuid(_x_, _y_)
  356. #define AzpDumpGoRef(_x_, _y_)
  357. #endif
  358. #ifdef __cplusplus
  359. }
  360. #endif