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.

120 lines
4.1 KiB

  1. /**********************************************************************
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name :
  4. chkrobust.cxx
  5. Abstract :
  6. This file contains the routines to check if -robust flag is presented on all the methods
  7. in an interface. This includes both raw rpc interfaces and DCOM interfaces.
  8. Author :
  9. Yong Qu yongqu March 2002
  10. Revision History :
  11. **********************************************************************/
  12. #include "ndrp.h"
  13. #include "ndrole.h"
  14. static const RPC_SYNTAX_IDENTIFIER gOleServer[] =
  15. {
  16. {0x69C09EA0, 0x4A09, 0x101B, 0xAE, 0x4B, 0x08, 0x00, 0x2B, 0x34, 0x9A, 0x02,
  17. {0, 0}},
  18. {0x00000131, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
  19. {0, 0}},
  20. {0x69C09EA0, 0x4A09, 0x101B, 0xAE, 0x4B, 0x08, 0x00, 0x2B, 0x34, 0x9A, 0x02,
  21. {0, 0}}
  22. };
  23. // called from RpcServerRegisterIf(x) family
  24. RPC_STATUS
  25. CheckForRobust (
  26. RPC_SERVER_INTERFACE * pRpcServerIf )
  27. {
  28. NDR_ASSERT( pRpcServerIf != NULL, "invalid input RPC_SERVER_INTERFACE" );
  29. if ( pRpcServerIf->DefaultManagerEpv )
  30. {
  31. // use_epv, it's not secure
  32. return RPC_X_BAD_STUB_DATA;
  33. }
  34. // either OLE or /Os stub altogether.
  35. if ( pRpcServerIf->InterpreterInfo == NULL )
  36. {
  37. // there are three "fake" ole interfaces that do their own dispatching
  38. for ( ulong i = 0; i < 3; i++)
  39. {
  40. if ( memcmp(&(pRpcServerIf->InterfaceId), &gOleServer[i], sizeof(RPC_SYNTAX_IDENTIFIER) )== 0 )
  41. return RPC_S_OK;
  42. }
  43. return RPC_X_BAD_STUB_DATA;
  44. }
  45. #if !defined(__RPC_WIN64__)
  46. // I don't like this. This is the only way to check for /Oi,Oic stub for raw rpc interface
  47. for ( ulong i = 0; i < pRpcServerIf->DispatchTable->DispatchTableCount ; i ++ )
  48. {
  49. if (pRpcServerIf->DispatchTable->DispatchTable[i] == NdrServerCall )
  50. return RPC_X_BAD_STUB_DATA;
  51. }
  52. #endif
  53. return NdrpCheckMIDLRobust ( (MIDL_SERVER_INFO *)pRpcServerIf->InterpreterInfo, pRpcServerIf->DispatchTable->DispatchTableCount , FALSE);
  54. }
  55. // called from NdrpCheckRpcServerRobust or from NdrDllRegisterProxy
  56. DWORD
  57. NdrpCheckMIDLRobust( IN const MIDL_SERVER_INFO * pMServerInfo, ulong ProcCount , BOOL IsObjectIntf )
  58. {
  59. NDR_ASSERT( pMServerInfo != NULL, "invalid MIDL_SERVER_INFO" );
  60. PMIDL_STUB_DESC pStubDesc = pMServerInfo->pStubDesc;
  61. BOOL fHasNoRobust = FALSE;
  62. // ulong i = IsObjectIntf? 2:0;
  63. if (pStubDesc->mFlags & RPCFLG_HAS_MULTI_SYNTAXES )
  64. {
  65. // -protocol ndr64 or -protocol all has to be robust
  66. return RPC_S_OK;
  67. }
  68. if ( MIDL_VERSION_3_0_39 > pStubDesc->MIDLVersion )
  69. {
  70. // we don't support ROBUST in early version of MIDL
  71. return RPC_X_BAD_STUB_DATA;
  72. }
  73. if ( pStubDesc->Version < NDR_VERSION_2_0 )
  74. {
  75. // we don't support ROBUST in early version of NDR
  76. return RPC_X_BAD_STUB_DATA;
  77. }
  78. NDR_ASSERT( pMServerInfo->FmtStringOffset != NULL, "invalid format string offset" );
  79. // there might be some interpreter mode method in this interface
  80. //
  81. // We are just checking the last one for performance; we don't care about mixed case (where
  82. // midl roll back to /Os mode
  83. // we can't check delegation case.
  84. if ( pMServerInfo->FmtStringOffset[ProcCount-1] != 0xffff )
  85. {
  86. PFORMAT_STRING ProcFormat = &(pMServerInfo->ProcString[pMServerInfo->FmtStringOffset[ProcCount-1]] );
  87. NDR_PROC_CONTEXT ProcContext;
  88. if ( !IsObjectIntf || ( ProcFormat[1] & Oi_OBJ_USE_V2_INTERPRETER ) )
  89. {
  90. MulNdrpInitializeContextFromProc(XFER_SYNTAX_DCE , ProcFormat, &ProcContext , NULL , FALSE );
  91. if (ProcContext.NdrInfo.pProcDesc->Oi2Flags.HasExtensions && ProcContext.NdrInfo.pProcDesc->NdrExts.Flags2.HasNewCorrDesc )
  92. return RPC_S_OK;
  93. }
  94. }
  95. return RPC_X_BAD_STUB_DATA;
  96. }