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.

265 lines
6.6 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // File: RPCIF.CXX
  4. //
  5. // Contents: RPC Interface specific functions
  6. //
  7. //
  8. // History: 23 Feb 92 RichardW Created
  9. //
  10. // BUG 453652: Socket errors are tranlated to STATUS_OBJECT_NAME_NOT_FOUND
  11. //
  12. //------------------------------------------------------------------------
  13. #include "kdcsvr.hxx"
  14. #include "rpcif.h"
  15. extern "C" {
  16. #include <kdcdbg.h>
  17. }
  18. #define MAX_EXPR_LEN 50
  19. ////////////////////////////////////////////////////////////////////
  20. //
  21. // Name: RET_IF_ERROR
  22. //
  23. // Synopsis: Evaluates an expression, returns from the caller if error.
  24. //
  25. // Arguments: l - Error level to print error message at.
  26. // e - expression to evaluate
  27. //
  28. // NOTE: THIS MACRO WILL RETURN FROM THE CALLING FUNCTION ON ERROR!!!!
  29. //
  30. // This will execute the expression (e), and check the return code. If the
  31. // return code indicates a failure, it prints an error message and returns
  32. // from the calling function.
  33. //
  34. #define RET_IF_ERROR(l,e) \
  35. { ULONG X_hr_XX__=(e) ; \
  36. if (X_hr_XX__ != ERROR_SUCCESS) { \
  37. DebugLog(( (l), (sizeof( #e ) > MAX_EXPR_LEN)? \
  38. "%s(%d):\n\t %.*s ... == %d\n" \
  39. : \
  40. "%s(%d):\n\t %.*s == %d\n" \
  41. , __FILE__, __LINE__, MAX_EXPR_LEN, #e, X_hr_XX__ )); \
  42. return(I_RpcMapWin32Status(X_hr_XX__)); \
  43. } \
  44. }
  45. ////////////////////////////////////////////////////////////////////
  46. //
  47. // Name: WARN_IF_ERROR
  48. //
  49. // Synopsis: Evaluates an expression, prints warning if error.
  50. //
  51. // Arguments: l - Error level to print warning at.
  52. // e - expression to evaluate
  53. //
  54. // Notes: This calls DebugLog(()) to print. In retail, it just
  55. // evaluates the expression.
  56. //
  57. #if DBG
  58. #define WARN_IF_ERROR(l,e) \
  59. { ULONG X_hr_XX__=(e) ; \
  60. if (X_hr_XX__ != ERROR_SUCCESS) { \
  61. DebugLog(( (l), (sizeof( #e ) > MAX_EXPR_LEN)? \
  62. "%s(%d):\n\t %.*s ... == %d\n" \
  63. : \
  64. "%s(%d):\n\t %.*s == %d\n" \
  65. , __FILE__, __LINE__, MAX_EXPR_LEN, #e, X_hr_XX__ )); \
  66. } \
  67. }
  68. #else
  69. #define WARN_IF_ERROR(l,e) (e)
  70. #endif
  71. //+-------------------------------------------------------------------------
  72. //
  73. // Function: StartAllProtSeqs
  74. //
  75. // Synopsis: Checks which protocols are running and then starts those
  76. // protocols for the three KDC interfaces: kdc, locator, privilege
  77. // server. It will, if USE_SECURE_RPC is defined, establish
  78. // credentials for the KDC.. Does not register interfaces.
  79. //
  80. // Effects:
  81. //
  82. // Arguments:
  83. //
  84. // Requires:
  85. //
  86. // Returns:
  87. //
  88. // Notes:
  89. //
  90. //
  91. //--------------------------------------------------------------------------
  92. HRESULT
  93. StartAllProtSeqs()
  94. {
  95. TRACE(KDC, StartAllProtSeqs, DEB_FUNCTION);
  96. // Use all but ncacn_np. We'd like not to use LRPC as well, but
  97. // first spmgr and the security packages would have to be
  98. // changed. So, we live with it.
  99. DWORD dwErr;
  100. dwErr = RpcServerUseProtseq(L"ncalrpc",
  101. MAX_CONCURRENT_CALLS,
  102. 0);
  103. if(dwErr)
  104. {
  105. DebugLog((DEB_ERROR, "UseProtseq failed %ws %d\n",
  106. L"ncalrpc", dwErr));
  107. }
  108. dwErr = RpcServerUseProtseq(L"ncacn_ip_tcp",
  109. MAX_CONCURRENT_CALLS,
  110. 0);
  111. if(dwErr)
  112. {
  113. DebugLog((DEB_ERROR, "UseProtseq failed %ws %d\n",
  114. L"ncalrpc", dwErr));
  115. }
  116. return(STATUS_SUCCESS);
  117. }
  118. //+-------------------------------------------------------------------------
  119. //
  120. // Function: RegsiterKdcEps
  121. //
  122. // Synopsis: Registers Eps for the KDC and locator interfaces
  123. //
  124. // Effects:
  125. //
  126. // Arguments:
  127. //
  128. // Requires:
  129. //
  130. // Returns:
  131. //
  132. // Notes:
  133. //
  134. //
  135. //--------------------------------------------------------------------------
  136. HRESULT
  137. RegisterKdcEps()
  138. {
  139. TRACE(KDC, RegisterKdcEps, DEB_FUNCTION);
  140. RPC_BINDING_VECTOR * ppvVector;
  141. RET_IF_ERROR(DEB_ERROR, RpcServerInqBindings(&ppvVector));
  142. RET_IF_ERROR(DEB_ERROR, RpcEpRegister(KdcDebug_ServerIfHandle, ppvVector, 0, L"")) ;
  143. RET_IF_ERROR(DEB_ERROR, RpcServerRegisterIf(KdcDebug_ServerIfHandle, 0, 0)) ;
  144. RpcBindingVectorFree(&ppvVector);
  145. return(STATUS_SUCCESS);
  146. }
  147. //+-------------------------------------------------------------------------
  148. //
  149. // Function: UnRegsiterKdcEps
  150. //
  151. // Synopsis: UnRegisters Eps for the KDC and locator interfaces
  152. //
  153. // Effects:
  154. //
  155. // Arguments:
  156. //
  157. // Requires:
  158. //
  159. // Returns:
  160. //
  161. // Notes:
  162. //
  163. //
  164. //--------------------------------------------------------------------------
  165. HRESULT
  166. UnRegisterKdcEps()
  167. {
  168. TRACE(KDC, RegisterKdcEps, DEB_FUNCTION);
  169. RPC_BINDING_VECTOR * ppvVector;
  170. RET_IF_ERROR(DEB_ERROR, RpcServerInqBindings(&ppvVector));
  171. WARN_IF_ERROR(DEB_ERROR, RpcServerUnregisterIf(KdcDebug_ServerIfHandle, 0, 0)) ;
  172. RpcBindingVectorFree(&ppvVector);
  173. return(STATUS_SUCCESS);
  174. }
  175. void *
  176. MIDL_user_allocate(size_t size)
  177. {
  178. // TRACE(KDC, MIDL_user_allocate, DEB_FUNCTION);
  179. PVOID pvMem;
  180. //
  181. // The ASN.1 marshalling code may allocate odd sizes that can't be
  182. // encrypted with a block cipher. By rounding up the size to 8 we can
  183. // handle block sizes up to 8 bytes.
  184. //
  185. pvMem = RtlAllocateHeap(
  186. RtlProcessHeap(),
  187. 0,
  188. ROUND_UP_COUNT(size,8)
  189. );
  190. if ( pvMem == NULL )
  191. {
  192. DebugLog((DEB_ERROR, "MIDL allocate failed\n"));
  193. }
  194. else
  195. {
  196. RtlZeroMemory(pvMem, ROUND_UP_COUNT(size,8));
  197. }
  198. return(pvMem);
  199. }
  200. void
  201. MIDL_user_free(void * ptr)
  202. {
  203. // TRACE(KDC, MIDL_user_free, DEB_FUNCTION);
  204. RtlFreeHeap(RtlProcessHeap(),0, ptr);
  205. }
  206. extern "C"
  207. void
  208. KdcFreeMemory(void * ptr)
  209. {
  210. KdcFreeEncodedData(ptr);
  211. }