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.

205 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. strsd.c
  5. Abstract:
  6. This Module implements wrapper functions to convert from a specialized
  7. string representation of a security descriptor to the security descriptor
  8. itself, and the opposite function.
  9. Author:
  10. Environment:
  11. User Mode
  12. Revision History:
  13. --*/
  14. #include "headers.h"
  15. //#include <lmcons.h>
  16. //#include <secobj.h>
  17. //#include <netlib.h>
  18. //#include <ntsecapi.h>
  19. #include "sddl.h"
  20. #pragma hdrstop
  21. DWORD
  22. ScepGetSecurityInformation(
  23. IN PSECURITY_DESCRIPTOR pSD,
  24. OUT SECURITY_INFORMATION *pSeInfo
  25. );
  26. DWORD
  27. WINAPI
  28. ConvertTextSecurityDescriptor (
  29. IN PWSTR pwszTextSD,
  30. OUT PSECURITY_DESCRIPTOR *ppSD,
  31. OUT PULONG pcSDSize OPTIONAL,
  32. OUT PSECURITY_INFORMATION pSeInfo OPTIONAL
  33. )
  34. {
  35. DWORD rc=ERROR_SUCCESS;
  36. if ( NULL == pwszTextSD || NULL == ppSD ) {
  37. return(ERROR_INVALID_PARAMETER);
  38. }
  39. //
  40. // initialize output buffers
  41. //
  42. *ppSD = NULL;
  43. if ( pSeInfo ) {
  44. *pSeInfo = 0;
  45. }
  46. if ( pcSDSize ) {
  47. *pcSDSize = 0;
  48. }
  49. //
  50. // call SDDL convert apis
  51. //
  52. if ( ConvertStringSecurityDescriptorToSecurityDescriptorW(
  53. pwszTextSD,
  54. SDDL_REVISION_1,
  55. ppSD,
  56. pcSDSize
  57. ) ) {
  58. //
  59. // conversion succeeds
  60. //
  61. if ( pSeInfo && *ppSD ) {
  62. //
  63. // get the SeInfo
  64. //
  65. rc = ScepGetSecurityInformation(
  66. *ppSD,
  67. pSeInfo
  68. );
  69. if ( rc != ERROR_SUCCESS ) {
  70. LocalFree(*ppSD);
  71. *ppSD = NULL;
  72. if ( pcSDSize ) {
  73. *pcSDSize = 0;
  74. }
  75. }
  76. }
  77. } else {
  78. rc = GetLastError();
  79. }
  80. return(rc);
  81. }
  82. DWORD
  83. WINAPI
  84. ConvertSecurityDescriptorToText (
  85. IN PSECURITY_DESCRIPTOR pSD,
  86. IN SECURITY_INFORMATION SecurityInfo,
  87. OUT PWSTR *ppwszTextSD,
  88. OUT PULONG pcTextSize
  89. )
  90. {
  91. if ( ConvertSecurityDescriptorToStringSecurityDescriptorW(
  92. pSD,
  93. SDDL_REVISION_1,
  94. SecurityInfo,
  95. ppwszTextSD,
  96. pcTextSize
  97. ) ) {
  98. return(ERROR_SUCCESS);
  99. } else {
  100. return(GetLastError());
  101. }
  102. }
  103. DWORD
  104. ScepGetSecurityInformation(
  105. IN PSECURITY_DESCRIPTOR pSD,
  106. OUT SECURITY_INFORMATION *pSeInfo
  107. )
  108. {
  109. PSID Owner = NULL, Group = NULL;
  110. BOOLEAN Defaulted;
  111. NTSTATUS Status;
  112. SECURITY_DESCRIPTOR_CONTROL ControlCode=0;
  113. ULONG Revision;
  114. if ( !pSeInfo ) {
  115. return(ERROR_INVALID_PARAMETER);
  116. }
  117. *pSeInfo = 0;
  118. if ( !pSD ) {
  119. return(ERROR_SUCCESS);
  120. }
  121. Status = RtlGetOwnerSecurityDescriptor( pSD, &Owner, &Defaulted );
  122. if ( NT_SUCCESS( Status ) ) {
  123. if ( Owner && !Defaulted ) {
  124. *pSeInfo |= OWNER_SECURITY_INFORMATION;
  125. }
  126. Status = RtlGetGroupSecurityDescriptor( pSD, &Group, &Defaulted );
  127. }
  128. if ( NT_SUCCESS( Status ) ) {
  129. if ( Group && !Defaulted ) {
  130. *pSeInfo |= GROUP_SECURITY_INFORMATION;
  131. }
  132. Status = RtlGetControlSecurityDescriptor ( pSD, &ControlCode, &Revision);
  133. }
  134. if ( NT_SUCCESS( Status ) ) {
  135. if ( ControlCode & SE_DACL_PRESENT ) {
  136. *pSeInfo |= DACL_SECURITY_INFORMATION;
  137. }
  138. if ( ControlCode & SE_SACL_PRESENT ) {
  139. *pSeInfo |= SACL_SECURITY_INFORMATION;
  140. }
  141. } else {
  142. *pSeInfo = 0;
  143. }
  144. return( RtlNtStatusToDosError(Status) );
  145. }