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.

229 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1995-1997 Microsoft Corporation
  3. Module Name:
  4. surrogat.cxx
  5. Abstract:
  6. Author:
  7. Revision History:
  8. --*/
  9. #include "act.hxx"
  10. CSurrogateList * gpSurrogateList;
  11. //
  12. // CSurrogateList
  13. //
  14. CSurrogateListEntry *
  15. CSurrogateList::Lookup(
  16. IN CToken * pToken,
  17. IN BOOL bRemoteActivation,
  18. IN BOOL bClientImpersonating,
  19. IN WCHAR * pwszWinstaDesktop,
  20. IN WCHAR * pwszAppid
  21. )
  22. {
  23. CSurrogateListEntry * pEntry;
  24. gpClassLock->LockShared();
  25. for ( pEntry = (CSurrogateListEntry *) First();
  26. pEntry;
  27. pEntry = (CSurrogateListEntry *) pEntry->Next() )
  28. {
  29. if ( pEntry->Match(pToken,
  30. bRemoteActivation,
  31. bClientImpersonating,
  32. pwszWinstaDesktop,
  33. pwszAppid ) )
  34. {
  35. pEntry->Reference();
  36. break;
  37. }
  38. }
  39. gpClassLock->UnlockShared();
  40. return pEntry;
  41. }
  42. CSurrogateListEntry *
  43. CSurrogateList::Lookup(
  44. IN const CProcess * pProcess
  45. )
  46. {
  47. CSurrogateListEntry * pEntry;
  48. gpClassLock->LockShared();
  49. for ( pEntry = (CSurrogateListEntry *) First();
  50. pEntry;
  51. pEntry = (CSurrogateListEntry *) pEntry->Next() )
  52. {
  53. if ( pEntry->Process() == pProcess )
  54. break;
  55. }
  56. gpClassLock->UnlockShared();
  57. return pEntry;
  58. }
  59. void
  60. CSurrogateList::Insert(
  61. IN CSurrogateListEntry * pSurrogateListEntry
  62. )
  63. {
  64. CSurrogateListEntry * pEntry;
  65. CProcess * pProcess;
  66. pProcess = pSurrogateListEntry->Process();
  67. gpClassLock->LockShared();
  68. for ( pEntry = (CSurrogateListEntry *) First();
  69. pEntry;
  70. pEntry = (CSurrogateListEntry *) pEntry->Next() )
  71. {
  72. if ( pEntry->Match( pProcess->GetToken(),
  73. FALSE,
  74. FALSE,
  75. pProcess->WinstaDesktop(),
  76. pSurrogateListEntry->_wszAppid ) )
  77. {
  78. pSurrogateListEntry->Release();
  79. pSurrogateListEntry = 0;
  80. break;
  81. }
  82. }
  83. if ( pSurrogateListEntry )
  84. CList::Insert( pSurrogateListEntry );
  85. gpClassLock->UnlockShared();
  86. }
  87. BOOL
  88. CSurrogateList::InList(
  89. IN CSurrogateListEntry * pSurrogateListEntry
  90. )
  91. {
  92. CListElement * pEntry;
  93. for ( pEntry = First(); pEntry; pEntry = pEntry->Next() )
  94. if ( pEntry == (CListElement *) pSurrogateListEntry )
  95. return TRUE;
  96. return FALSE;
  97. }
  98. //
  99. // CSurrogateListEntry
  100. //
  101. CSurrogateListEntry::CSurrogateListEntry(
  102. IN WCHAR * pwszAppid,
  103. IN CServerListEntry * pServerListEntry
  104. )
  105. {
  106. pServerListEntry->Reference();
  107. _pServerListEntry = pServerListEntry;
  108. lstrcpyW( _wszAppid, pwszAppid );
  109. }
  110. CSurrogateListEntry::~CSurrogateListEntry()
  111. {
  112. _pServerListEntry->Release();
  113. }
  114. BOOL
  115. CSurrogateListEntry::Match(
  116. IN CToken * pToken,
  117. IN BOOL bRemoteActivation,
  118. IN BOOL bClientImpersonating,
  119. IN WCHAR * pwszWinstaDesktop,
  120. IN WCHAR * pwszAppid
  121. )
  122. {
  123. if ( lstrcmpW( pwszAppid, _wszAppid ) != 0 )
  124. return FALSE;
  125. return _pServerListEntry->Match( pToken,
  126. bRemoteActivation,
  127. bClientImpersonating,
  128. pwszWinstaDesktop,
  129. TRUE );
  130. }
  131. BOOL
  132. CSurrogateListEntry::LoadDll(
  133. IN ACTIVATION_PARAMS * pActParams,
  134. OUT HRESULT * phr
  135. )
  136. {
  137. DWORD BusyRetries;
  138. HRESULT hr;
  139. BOOL bRemove;
  140. error_status_t RpcStatus;
  141. HANDLE hBinding;
  142. hBinding = _pServerListEntry->RpcHandle( pActParams->UnsecureActivation );
  143. if ( ! hBinding )
  144. return FALSE;
  145. if ( ! pActParams->UnsecureActivation &&
  146. pActParams->pToken != NULL )
  147. pActParams->pToken->Impersonate();
  148. BusyRetries = 0;
  149. do
  150. {
  151. hr = ObjectServerLoadDll(
  152. hBinding,
  153. pActParams->ORPCthis,
  154. pActParams->Localthis,
  155. pActParams->ORPCthat,
  156. &pActParams->Clsid,
  157. &RpcStatus );
  158. } while ( (RPC_S_SERVER_TOO_BUSY == RpcStatus) &&
  159. (BusyRetries++ < 5) );
  160. if ( ! pActParams->UnsecureActivation &&
  161. pActParams->pToken != NULL )
  162. pActParams->pToken->Revert();
  163. if ( (RpcStatus != RPC_S_OK) || (CO_E_SERVER_STOPPING == hr) )
  164. {
  165. gpClassLock->LockExclusive();
  166. bRemove = gpSurrogateList->InList( this );
  167. if ( bRemove )
  168. gpSurrogateList->Remove( this );
  169. gpClassLock->UnlockExclusive();
  170. if ( bRemove )
  171. Release();
  172. return FALSE;
  173. }
  174. *phr = hr;
  175. return TRUE;
  176. }