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.

214 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Support.c
  5. Abstract:
  6. This module contains support routines for the Win32 Registry API.
  7. Author:
  8. David J. Gilman (davegi) 15-Nov-1991
  9. --*/
  10. /*++
  11. Copyright (c) 1991 Microsoft Corporation
  12. Module Name:
  13. error.c
  14. Abstract:
  15. This module contains a routine for converting NT status codes
  16. to DOS/OS|2 error codes.
  17. Author:
  18. David Treadwell (davidtr) 04-Apr-1991
  19. Revision History:
  20. --*/
  21. #include <rpc.h>
  22. #include "regrpc.h"
  23. #include <stdio.h>
  24. LONG
  25. MapSAToRpcSA (
  26. IN LPSECURITY_ATTRIBUTES lpSA,
  27. OUT PRPC_SECURITY_ATTRIBUTES lpRpcSA
  28. )
  29. /*++
  30. Routine Description:
  31. Maps a SECURITY_ATTRIBUTES structure to a RPC_SECURITY_ATTRIBUTES
  32. structure by converting the SECURITY_DESCRIPTOR to a form where it can
  33. be marshalled/unmarshalled.
  34. Arguments:
  35. lpSA - Supplies a pointer to the SECURITY_ATTRIBUTES structure to be
  36. converted.
  37. lpRpcSA - Supplies a pointer to the converted RPC_SECURITY_ATTRIBUTES
  38. structure. The caller should free (using RtlFreeHeap) the field
  39. lpSecurityDescriptor when its finished using it.
  40. Return Value:
  41. LONG - Returns ERROR_SUCCESS if the SECURITY_ATTRIBUTES is
  42. succesfully mapped.
  43. --*/
  44. {
  45. LONG Error;
  46. ASSERT( lpSA != NULL );
  47. ASSERT( lpRpcSA != NULL );
  48. //
  49. // Map the SECURITY_DESCRIPTOR to a RPC_SECURITY_DESCRIPTOR.
  50. //
  51. lpRpcSA->RpcSecurityDescriptor.lpSecurityDescriptor = NULL;
  52. if( lpSA->lpSecurityDescriptor != NULL ) {
  53. Error = MapSDToRpcSD(
  54. lpSA->lpSecurityDescriptor,
  55. &lpRpcSA->RpcSecurityDescriptor
  56. );
  57. } else {
  58. lpRpcSA->RpcSecurityDescriptor.cbInSecurityDescriptor = 0;
  59. lpRpcSA->RpcSecurityDescriptor.cbOutSecurityDescriptor = 0;
  60. Error = ERROR_SUCCESS;
  61. }
  62. if( Error == ERROR_SUCCESS ) {
  63. //
  64. //
  65. // The supplied SECURITY_DESCRIPTOR was successfully converted
  66. // to self relative format so assign the remaining fields.
  67. //
  68. lpRpcSA->nLength = lpSA->nLength;
  69. lpRpcSA->bInheritHandle = ( BOOLEAN ) lpSA->bInheritHandle;
  70. }
  71. return Error;
  72. }
  73. LONG
  74. MapSDToRpcSD (
  75. IN PSECURITY_DESCRIPTOR lpSD,
  76. IN OUT PRPC_SECURITY_DESCRIPTOR lpRpcSD
  77. )
  78. /*++
  79. Routine Description:
  80. Maps a SECURITY_DESCRIPTOR to a RPC_SECURITY_DESCRIPTOR by converting
  81. it to a form where it can be marshalled/unmarshalled.
  82. Arguments:
  83. lpSD - Supplies a pointer to the SECURITY_DESCRIPTOR
  84. structure to be converted.
  85. lpRpcSD - Supplies a pointer to the converted RPC_SECURITY_DESCRIPTOR
  86. structure. Memory for the security descriptor is allocated if
  87. not provided. The caller must take care of freeing up the memory
  88. if necessary.
  89. Return Value:
  90. LONG - Returns ERROR_SUCCESS if the SECURITY_DESCRIPTOR is
  91. succesfully mapped.
  92. --*/
  93. {
  94. DWORD cbLen;
  95. ASSERT( lpSD != NULL );
  96. ASSERT( lpRpcSD != NULL );
  97. if( RtlValidSecurityDescriptor( lpSD )) {
  98. cbLen = RtlLengthSecurityDescriptor( lpSD );
  99. ASSERT( cbLen > 0 );
  100. //
  101. // If we're not provided a buffer for the security descriptor,
  102. // allocate it.
  103. //
  104. if ( !lpRpcSD->lpSecurityDescriptor ) {
  105. //
  106. // Allocate space for the converted SECURITY_DESCRIPTOR.
  107. //
  108. lpRpcSD->lpSecurityDescriptor =
  109. ( PBYTE ) RtlAllocateHeap(
  110. RtlProcessHeap( ), 0,
  111. cbLen
  112. );
  113. //
  114. // If the memory allocation failed, return.
  115. //
  116. if( lpRpcSD->lpSecurityDescriptor == NULL ) {
  117. return ERROR_OUTOFMEMORY;
  118. }
  119. lpRpcSD->cbInSecurityDescriptor = cbLen;
  120. } else {
  121. //
  122. // Make sure that the buffer provided is big enough
  123. //
  124. if ( lpRpcSD->cbInSecurityDescriptor < cbLen ) {
  125. return ERROR_OUTOFMEMORY;
  126. }
  127. }
  128. //
  129. // Set the size of the transmittable buffer
  130. //
  131. lpRpcSD->cbOutSecurityDescriptor = cbLen;
  132. //
  133. // Convert the supplied SECURITY_DESCRIPTOR to self relative form.
  134. //
  135. return RtlNtStatusToDosError(
  136. RtlMakeSelfRelativeSD(
  137. lpSD,
  138. lpRpcSD->lpSecurityDescriptor,
  139. &lpRpcSD->cbInSecurityDescriptor
  140. )
  141. );
  142. } else {
  143. //
  144. // The supplied SECURITY_DESCRIPTOR is invalid.
  145. //
  146. return ERROR_INVALID_PARAMETER;
  147. }
  148. }