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.

135 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1997.
  5. //
  6. // File: EVENT.C
  7. //
  8. // Contents: Routines used by the event viewer to map GUIDs to names
  9. //
  10. // History: 25-Oct-97 CliffV Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <rpc.h>
  18. #include <rpcdce.h>
  19. #include <lucache.h>
  20. DWORD
  21. EventGuidToName(
  22. IN LPCWSTR Source,
  23. IN LPCWSTR GuidString,
  24. OUT LPWSTR *NameString
  25. )
  26. /*++
  27. Routine Description:
  28. General purpose routine used by the event viewer to translate from a GUID
  29. in an event log message to a name of the GUID.
  30. This instance of the routine translates the following GUID types:
  31. Object Class Guids (e.g., user)
  32. Property set Guids (e.g., ATT_USER_PRINCIPLE_NAME)
  33. Property Guids (e.g., adminDisplayName)
  34. Object Guids (e.g., <DnsDomainName>/Users/<UserName>)
  35. Arguments:
  36. Source - Specifies the source of the GUID. The routine will use this field
  37. to differentiate between multiple sources potentially implemented by
  38. the routine.
  39. This instance of the routine requires the Source to be
  40. ACCESS_DS_SOURCE_W.
  41. GuidString - A string-ized version of the GUID to translate. The GUID should
  42. be in the form 33ff431c-4d78-11d1-b61a-00c04fd8ebaa.
  43. NameString - Returns the name that corresponds to the GUID. If the name cannot
  44. be found, a stringized version of the GUID is returned.
  45. The name should be freed by calling EventNameFree.
  46. Return Value:
  47. NO_ERROR - The Name was successfully translated.
  48. ERROR_NOT_ENOUGH_MEMORY - There was not enough memory to complete the operation.
  49. ERROR_INVALID_PARAMETER - Source is not supported.
  50. RPC_S_INVALID_STRING_UUID - Syntax of GuidString is invalid
  51. --*/
  52. {
  53. DWORD dwErr;
  54. GUID Guid;
  55. //
  56. // Ensure the source is one we recognize.
  57. //
  58. if ( _wcsicmp( Source, ACCESS_DS_SOURCE_W) != 0 ) {
  59. return ERROR_INVALID_PARAMETER;
  60. }
  61. //
  62. // Convert the specified GUID to binary.
  63. //
  64. dwErr = UuidFromString((LPWSTR)GuidString, &Guid);
  65. if ( dwErr != NO_ERROR ) {
  66. return dwErr;
  67. }
  68. //
  69. // Convert the GUID to a name.
  70. //
  71. dwErr = AccctrlLookupIdName(
  72. NULL, // No existing LDAP handle
  73. L"", // Only the root path
  74. &Guid,
  75. TRUE, // Allocate the return buffer
  76. TRUE, // Handle individual object GUIDs
  77. NameString );
  78. return dwErr;
  79. }
  80. VOID
  81. EventNameFree(
  82. IN LPCWSTR NameString
  83. )
  84. /*++
  85. Routine Description:
  86. Routine to free strings returned by EventNameFree.
  87. Arguments:
  88. NameString - Returns the name that corresponds to the GUID.
  89. Return Value:
  90. None.
  91. --*/
  92. {
  93. LocalFree((PVOID)NameString);
  94. }