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.

256 lines
5.4 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. BOOL
  99. CSurrogateList::RemoveMatchingEntry(
  100. IN CServerListEntry* pServerListEntry
  101. )
  102. {
  103. BOOL fRemoved = FALSE;
  104. CListElement* pEntry = NULL;
  105. CSurrogateListEntry* pSurrogateListEntry = NULL;
  106. gpClassLock->LockExclusive();
  107. for (pEntry = First(); pEntry; pEntry = pEntry->Next())
  108. {
  109. pSurrogateListEntry = (CSurrogateListEntry*)pEntry;
  110. if (pSurrogateListEntry->_pServerListEntry == pServerListEntry)
  111. {
  112. // found matching surrogate entry; remove it
  113. gpSurrogateList->Remove(pSurrogateListEntry);
  114. fRemoved = TRUE;
  115. break;
  116. }
  117. }
  118. gpClassLock->UnlockExclusive();
  119. if (fRemoved)
  120. pSurrogateListEntry->Release();
  121. return fRemoved;
  122. }
  123. //
  124. // CSurrogateListEntry
  125. //
  126. CSurrogateListEntry::CSurrogateListEntry(
  127. IN WCHAR * pwszAppid,
  128. IN CServerListEntry * pServerListEntry
  129. )
  130. {
  131. pServerListEntry->Reference();
  132. _pServerListEntry = pServerListEntry;
  133. lstrcpyW( _wszAppid, pwszAppid );
  134. }
  135. CSurrogateListEntry::~CSurrogateListEntry()
  136. {
  137. _pServerListEntry->Release();
  138. }
  139. BOOL
  140. CSurrogateListEntry::Match(
  141. IN CToken * pToken,
  142. IN BOOL bRemoteActivation,
  143. IN BOOL bClientImpersonating,
  144. IN WCHAR * pwszWinstaDesktop,
  145. IN WCHAR * pwszAppid
  146. )
  147. {
  148. if ( lstrcmpW( pwszAppid, _wszAppid ) != 0 )
  149. return FALSE;
  150. return _pServerListEntry->Match( pToken,
  151. bRemoteActivation,
  152. bClientImpersonating,
  153. pwszWinstaDesktop,
  154. TRUE );
  155. }
  156. BOOL
  157. CSurrogateListEntry::LoadDll(
  158. IN ACTIVATION_PARAMS * pActParams,
  159. OUT HRESULT * phr
  160. )
  161. {
  162. DWORD BusyRetries;
  163. HRESULT hr;
  164. BOOL bRemove;
  165. HANDLE hBinding;
  166. error_status_t status;
  167. hBinding = _pServerListEntry->RpcHandle();
  168. if (!hBinding)
  169. return FALSE;
  170. ASSERT(pActParams->pToken);
  171. pActParams->pToken->Impersonate();
  172. BusyRetries = 0;
  173. do
  174. {
  175. hr = ObjectServerLoadDll(
  176. hBinding,
  177. pActParams->ORPCthis,
  178. pActParams->Localthis,
  179. pActParams->ORPCthat,
  180. &pActParams->Clsid,
  181. &status );
  182. } while ( (RPC_S_SERVER_TOO_BUSY == status) &&
  183. (BusyRetries++ < 5) );
  184. pActParams->pToken->Revert();
  185. if ( (status != RPC_S_OK) || (CO_E_SERVER_STOPPING == hr) )
  186. {
  187. gpClassLock->LockExclusive();
  188. bRemove = gpSurrogateList->InList( this );
  189. if ( bRemove )
  190. gpSurrogateList->Remove( this );
  191. gpClassLock->UnlockExclusive();
  192. if ( bRemove )
  193. Release();
  194. return FALSE;
  195. }
  196. *phr = hr;
  197. return TRUE;
  198. }