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.

269 lines
6.3 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. ////////////////////////////////////////////////////////////////////
  19. //
  20. // Name: RET_IF_ERROR
  21. //
  22. // Synopsis: Evaluates an expression, returns from the caller if error.
  23. //
  24. // Arguments: l - Error level to print error message at.
  25. // e - expression to evaluate
  26. //
  27. // NOTE: THIS MACRO WILL RETURN FROM THE CALLING FUNCTION ON ERROR!!!!
  28. //
  29. // This will execute the expression (e), and check the return code. If the
  30. // return code indicates a failure, it prints an error message and returns
  31. // from the calling function.
  32. //
  33. #define RET_IF_ERROR(l,e) \
  34. { ULONG X_hr_XX__=(e) ; \
  35. if (X_hr_XX__ != ERROR_SUCCESS) { \
  36. DebugLog(( (l), (sizeof( #e ) > MAX_EXPR_LEN)? \
  37. "%s(%d):\n\t %.*s ... == %d\n" \
  38. : \
  39. "%s(%d):\n\t %.*s == %d\n" \
  40. , __FILE__, __LINE__, MAX_EXPR_LEN, #e, X_hr_XX__ )); \
  41. return(I_RpcMapWin32Status(X_hr_XX__)); \
  42. } \
  43. }
  44. ////////////////////////////////////////////////////////////////////
  45. //
  46. // Name: WARN_IF_ERROR
  47. //
  48. // Synopsis: Evaluates an expression, prints warning if error.
  49. //
  50. // Arguments: l - Error level to print warning at.
  51. // e - expression to evaluate
  52. //
  53. // Notes: This calls DebugLog(()) to print. In retail, it just
  54. // evaluates the expression.
  55. //
  56. #if DBG
  57. #define WARN_IF_ERROR(l,e) \
  58. { ULONG X_hr_XX__=(e) ; \
  59. if (X_hr_XX__ != ERROR_SUCCESS) { \
  60. DebugLog(( (l), (sizeof( #e ) > MAX_EXPR_LEN)? \
  61. "%s(%d):\n\t %.*s ... == %d\n" \
  62. : \
  63. "%s(%d):\n\t %.*s == %d\n" \
  64. , __FILE__, __LINE__, MAX_EXPR_LEN, #e, X_hr_XX__ )); \
  65. } \
  66. }
  67. #else
  68. #define WARN_IF_ERROR(l,e) (e)
  69. #endif
  70. //+-------------------------------------------------------------------------
  71. //
  72. // Function: StartAllProtSeqs
  73. //
  74. // Synopsis: Checks which protocols are running and then starts those
  75. // protocols for the three KDC interfaces: kdc, locator, privilege
  76. // server. It will, if USE_SECURE_RPC is defined, establish
  77. // credentials for the KDC.. Does not register interfaces.
  78. //
  79. // Effects:
  80. //
  81. // Arguments:
  82. //
  83. // Requires:
  84. //
  85. // Returns:
  86. //
  87. // Notes:
  88. //
  89. //
  90. //--------------------------------------------------------------------------
  91. HRESULT
  92. StartAllProtSeqs()
  93. {
  94. TRACE(KDC, StartAllProtSeqs, DEB_FUNCTION);
  95. ULONG i;
  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. }