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.

225 lines
4.8 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 2000
  6. //
  7. // File: A D T G E N . C
  8. //
  9. // Contents: definitions of types/functions required for
  10. // generating generic audits.
  11. //
  12. //
  13. // History:
  14. // 07-January-2000 kumarp created
  15. //
  16. //------------------------------------------------------------------------
  17. #include "pch.h"
  18. #pragma hdrstop
  19. #include "authz.h"
  20. //------------------------------------------------------------------------
  21. //
  22. // internal routines
  23. //
  24. NTSTATUS
  25. LsapApiReturnResult(
  26. ULONG ExceptionCode
  27. );
  28. //------------------------------------------------------------------------
  29. BOOL
  30. AuthzpRegisterAuditEvent(
  31. IN PAUTHZ_AUDIT_EVENT_TYPE_OLD pAuditEventType,
  32. OUT AUDIT_HANDLE* phAuditContext
  33. )
  34. /*++
  35. Routine Description:
  36. Register the specified event with LSA. This causes LSA to
  37. generate and return an audit context. This context handle
  38. is required to publish event of the specified type.
  39. Arguments:
  40. pAuditEventType - pointer to audit event info structure
  41. that defines which event to register.
  42. phAuditContext - pointer to audit context handle returned
  43. Return Value:
  44. NTSTATUS - Standard Nt Result Code
  45. Notes:
  46. Note that this function does NOT register the schema of an event. It is
  47. assumed that the schema has been registered *before* calling
  48. this function.
  49. The schema of legacy audit events is stored in a .mc file.
  50. --*/
  51. {
  52. DWORD dwStatus;
  53. //
  54. // since we use the same var to store NTSTATUS and win32 error
  55. // make sure that this is not a problem
  56. //
  57. ASSERT( sizeof(NTSTATUS) == sizeof(DWORD) );
  58. //
  59. // we generate a unique ID and store it in the audit handle
  60. // the server will copy this into the corresponding structure
  61. // on the server side. This ID allows us to track which server side
  62. // audit-context corresponds to which client side event handle.
  63. // This is very useful in debugging.
  64. //
  65. NtAllocateLocallyUniqueId( &pAuditEventType->LinkId );
  66. RpcTryExcept
  67. {
  68. dwStatus = LsarRegisterAuditEvent( pAuditEventType, phAuditContext );
  69. }
  70. RpcExcept( EXCEPTION_EXECUTE_HANDLER )
  71. {
  72. dwStatus = LsapApiReturnResult(I_RpcMapWin32Status(RpcExceptionCode()));
  73. } RpcEndExcept;
  74. if (!NT_SUCCESS(dwStatus))
  75. {
  76. dwStatus = RtlNtStatusToDosError( dwStatus );
  77. SetLastError( dwStatus );
  78. return FALSE;
  79. }
  80. return TRUE;
  81. }
  82. BOOL
  83. AuthzpSendAuditToLsa(
  84. IN AUDIT_HANDLE hAuditContext,
  85. IN DWORD dwFlags,
  86. IN AUDIT_PARAMS* pAuditParams,
  87. IN PVOID pReserved
  88. )
  89. /*++
  90. Routine Description:
  91. Send an event to LSA for publishing.
  92. Arguments:
  93. hAuditContext - handle of audit-context previously obtained
  94. by calling LsaRegisterAuditEvent
  95. dwFlags - TBD
  96. pAuditParams - pointer to audit event parameters
  97. pReserved - reserved for future enhancements
  98. Return Value:
  99. STATUS_SUCCESS -- if all is well
  100. NTSTATUS error code otherwise.
  101. Notes:
  102. --*/
  103. {
  104. DWORD dwStatus;
  105. UNREFERENCED_PARAMETER(pReserved);
  106. //
  107. // since we use the same var to store NTSTATUS and win32 error
  108. // make sure that this is not a problem
  109. //
  110. ASSERT( sizeof(NTSTATUS) == sizeof(DWORD) );
  111. RpcTryExcept
  112. {
  113. dwStatus = LsarGenAuditEvent( hAuditContext, dwFlags, pAuditParams );
  114. }
  115. RpcExcept( EXCEPTION_EXECUTE_HANDLER )
  116. {
  117. dwStatus = LsapApiReturnResult(I_RpcMapWin32Status(RpcExceptionCode()));
  118. } RpcEndExcept;
  119. if (!NT_SUCCESS(dwStatus))
  120. {
  121. dwStatus = RtlNtStatusToDosError( dwStatus );
  122. SetLastError( dwStatus );
  123. return FALSE;
  124. }
  125. return TRUE;
  126. }
  127. BOOL
  128. AuthzpUnregisterAuditEvent(
  129. IN OUT AUDIT_HANDLE* phAuditContext
  130. )
  131. /*++
  132. Routine Description:
  133. Unregister the specified event. This causes LSA to
  134. free resources associated with the context.
  135. Arguments:
  136. hAuditContext - handle to the audit context to unregister
  137. Return Value:
  138. NTSTATUS - Standard Nt Result Code
  139. Notes:
  140. --*/
  141. {
  142. DWORD dwStatus;
  143. //
  144. // since we use the same var to store NTSTATUS and win32 error
  145. // make sure that this is not a problem
  146. //
  147. ASSERT( sizeof(NTSTATUS) == sizeof(DWORD) );
  148. RpcTryExcept
  149. {
  150. dwStatus = LsarUnregisterAuditEvent( phAuditContext );
  151. }
  152. RpcExcept( EXCEPTION_EXECUTE_HANDLER )
  153. {
  154. dwStatus = LsapApiReturnResult(I_RpcMapWin32Status(RpcExceptionCode()));
  155. } RpcEndExcept;
  156. if (!NT_SUCCESS(dwStatus))
  157. {
  158. dwStatus = RtlNtStatusToDosError( dwStatus );
  159. SetLastError( dwStatus );
  160. return FALSE;
  161. }
  162. return TRUE;
  163. }