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.

122 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. snmpevts.c
  5. Abstract:
  6. Eventlog message routines for the SNMP Service.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-Feb-1997 DonRyan
  11. Rewrote to implement SNMPv2 support.
  12. --*/
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // //
  15. // Include files //
  16. // //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include "globals.h"
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // //
  21. // Public procedures //
  22. // //
  23. ///////////////////////////////////////////////////////////////////////////////
  24. VOID
  25. SNMP_FUNC_TYPE
  26. ReportSnmpEvent(
  27. DWORD nMsgId,
  28. DWORD nSubStrings,
  29. LPTSTR *ppSubStrings,
  30. DWORD nErrorCode
  31. )
  32. /*++
  33. Routine Description:
  34. Reports event with EventLog service.
  35. Arguments:
  36. nMsgId - message identifier.
  37. nSubStrings - number of message strings.
  38. ppSubStrings - pointer to array of message strings.
  39. nErrorCode - error code to be attached to event.
  40. Return Values:
  41. Returns true if successful.
  42. --*/
  43. {
  44. HANDLE lh;
  45. WORD wEventType;
  46. LPVOID lpData;
  47. WORD cbData;
  48. //
  49. // determine type of event from message id. note that
  50. // all debug messages regardless of their severity are
  51. // listed under SNMP_EVENT_DEBUG_TRACE (informational).
  52. // see snmpevts.h for the entire list of event messages.
  53. //
  54. switch ( nMsgId >> 30 ) {
  55. case STATUS_SEVERITY_INFORMATIONAL:
  56. case STATUS_SEVERITY_SUCCESS:
  57. wEventType = EVENTLOG_INFORMATION_TYPE;
  58. break;
  59. case STATUS_SEVERITY_WARNING:
  60. wEventType = EVENTLOG_WARNING_TYPE;
  61. break;
  62. case STATUS_SEVERITY_ERROR:
  63. default:
  64. wEventType = EVENTLOG_ERROR_TYPE;
  65. break;
  66. }
  67. // determine size of data by whether error present
  68. cbData = (nErrorCode == NO_ERROR) ? 0 : sizeof(DWORD);
  69. lpData = (nErrorCode == NO_ERROR) ? NULL : &nErrorCode;
  70. // attempt to register event sources
  71. if (lh = RegisterEventSource(NULL, TEXT("SNMP"))) {
  72. // report
  73. ReportEvent(
  74. lh,
  75. wEventType,
  76. 0, // event category
  77. nMsgId,
  78. NULL, // user sids
  79. (WORD)nSubStrings,
  80. cbData,
  81. ppSubStrings,
  82. lpData
  83. );
  84. // deregister event source
  85. DeregisterEventSource(lh);
  86. }
  87. }