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.

169 lines
3.9 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. wspriv.cpp
  5. Abstract:
  6. This file can be used to get the privileges with the respective display
  7. names in the current access token on a local system.
  8. Authors:
  9. Christophe Robert
  10. Revision History:
  11. 02-July-2001 : Updated by Wipro Technologies.
  12. --*/
  13. //common header files needed for this file
  14. #include "pch.h"
  15. #include "CommonHeaderFiles.h"
  16. WsPrivilege::WsPrivilege ( IN LUID Luid,
  17. IN DWORD Attributes )
  18. /*++
  19. Routine Description:
  20. This function intializes the members of WsPrivilege.
  21. Arguments:
  22. [IN] LUID Luid : LUID
  23. [OUT] DWORD Attributes : Attributes
  24. Return Value:
  25. None
  26. --*/
  27. {
  28. // initialize the member variables
  29. memcpy ( (LPSTR) &this->Luid, (LPSTR) &Luid, sizeof(LUID) ) ;
  30. this->Attributes = Attributes ;
  31. }
  32. WsPrivilege::WsPrivilege (
  33. IN LUID_AND_ATTRIBUTES *lpLuaa
  34. )
  35. /*++
  36. Routine Description:
  37. This function intializes the members of WsPrivilege.
  38. Arguments:
  39. [IN] LUID_AND_ATTRIBUTES *lpLuaa ; LUID attributes
  40. Return Value:
  41. None
  42. --*/
  43. {
  44. // set the attributes
  45. memcpy ( (LPSTR) &Luid, (LPSTR) &lpLuaa->Luid, sizeof(LUID) ) ;
  46. Attributes = lpLuaa->Attributes ;
  47. }
  48. DWORD
  49. WsPrivilege::GetName (
  50. OUT LPWSTR wszPrivName
  51. )
  52. /*++
  53. Routine Description:
  54. This function gets the privilege name.
  55. Arguments:
  56. [OUT] LPWSTR wszPrivName : Stores privilege name
  57. Return Value:
  58. EXIT_SUCCESS : On success
  59. EXIT_FAILURE : On failure
  60. --*/
  61. {
  62. // sub-local variables
  63. DWORD dwSize = 0 ;
  64. WCHAR wszTempPrivName [ MAX_RES_STRING ];
  65. SecureZeroMemory ( wszTempPrivName, SIZE_OF_ARRAY(wszTempPrivName) );
  66. //Get the name
  67. dwSize = SIZE_OF_ARRAY ( wszTempPrivName ) ;
  68. if ( FALSE == LookupPrivilegeName ( NULL,
  69. &Luid,
  70. wszTempPrivName,
  71. &dwSize ) ){
  72. // return WIN32 error code
  73. return GetLastError() ;
  74. }
  75. StringCopy ( wszPrivName, wszTempPrivName, MAX_RES_STRING );
  76. return EXIT_SUCCESS ;
  77. }
  78. DWORD
  79. WsPrivilege::GetDisplayName ( IN LPWSTR wszName,
  80. OUT LPWSTR wszDispName )
  81. /*++
  82. Routine Description:
  83. This function gets the privilege description.
  84. Arguments:
  85. [OUT] LPWSTR szName : Stores privilege name
  86. [OUT] LPWSTR szDispName : Stores privilege description
  87. Return Value:
  88. EXIT_SUCCESS : On success
  89. EXIT_FAILURE : On failure
  90. --*/
  91. {
  92. // sub-local variables
  93. DWORD dwSize = 0 ;
  94. DWORD dwLang = 0 ;
  95. WCHAR wszTempDispName [ MAX_RES_STRING ];
  96. SecureZeroMemory ( wszTempDispName, SIZE_OF_ARRAY(wszTempDispName) );
  97. //Get the display name
  98. dwSize = SIZE_OF_ARRAY ( wszTempDispName ) ;
  99. // get the description for the privilege name
  100. if ( FALSE == LookupPrivilegeDisplayName ( NULL,
  101. (LPWSTR) wszName,
  102. wszTempDispName,
  103. &dwSize,
  104. &dwLang ) ){
  105. return GetLastError () ;
  106. }
  107. StringCopy ( wszDispName, wszTempDispName, MAX_RES_STRING );
  108. // return success
  109. return EXIT_SUCCESS ;
  110. }
  111. BOOL
  112. WsPrivilege::IsEnabled ( VOID )
  113. /*++
  114. Routine Description:
  115. This function checks whether the privilege is enabled or not.
  116. Arguments:
  117. None
  118. Return Value:
  119. TRUE : On success
  120. FALSE : On failure
  121. --*/
  122. {
  123. // check if prvilege is enabled
  124. if ( Attributes & SE_PRIVILEGE_ENABLED ){
  125. return TRUE ;
  126. }
  127. else{
  128. return FALSE ;
  129. }
  130. }