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.

246 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Misc.hxx
  5. Abstract:
  6. Header for random helpers functions.
  7. Author:
  8. Mario Goertzel [MarioGo]
  9. Revision History:
  10. MarioGo 02-11-95 Bits 'n pieces
  11. --*/
  12. #ifndef __MISC_HXX
  13. #define __MISC_HXX
  14. #include <memapi.hxx>
  15. #include <list.hxx>
  16. #define RPC_CHAR WCHAR
  17. // This is the new W2K server principal name prefix; to form a full SPN
  18. // you construct a string of the form "RPCSS/machine". For W2K RTM such
  19. // a string will simply be mapped to HOST (ie local system account) but
  20. // doing it this way gives us more flexibility for the future.
  21. #define RPCSS_SPN_PREFIX L"RPCSS/"
  22. extern ORSTATUS StartListeningIfNecessary();
  23. extern RPC_STATUS CopyMyOrBindings(DUALSTRINGARRAY **ppdsaOrBindings, DWORD64* pdwBindingsID);
  24. extern void PushCurrentBindings();
  25. extern RPC_STATUS ComputeNewResolverBindings(void);
  26. extern ID AllocateId(LONG cRange = 1);
  27. extern error_status_t ResolveClientOXID(
  28. handle_t hClient,
  29. PHPROCESS phProcess,
  30. OXID *poxidServer,
  31. DUALSTRINGARRAY *pdsaServerBindings,
  32. LONG fApartment,
  33. USHORT wProtseqId,
  34. WCHAR *pMachineName,
  35. OXID_INFO *poxidInfo,
  36. MID *pDestinationMid,
  37. BOOL fUnsecure,
  38. USHORT wAuthnSvc,
  39. BOOL *pIsLocalOxid,
  40. USHORT *pusAuthnSvc);
  41. //
  42. // Magic constants used in rpc security callback code:
  43. //
  44. #define INITIAL_NON_AUTHNSVC_VALUE 0xFFBB
  45. #define ERROR_AUTHNSVC_VALUE 0xFFBC
  46. //+-------------------------------------------------------------------------
  47. //
  48. // CRpcSecurityCallback
  49. //
  50. // This class represents a single rpc security callback for a single calling
  51. // thread.
  52. //
  53. class CRpcSecurityCallback : public CListElement
  54. {
  55. public:
  56. // Ctor
  57. CRpcSecurityCallback(handle_t hRpc, DWORD dwRegisteredThreadId)
  58. {
  59. _usAuthSvc = INITIAL_NON_AUTHNSVC_VALUE; // anything but a valid RPC_C_AUTHN_xxx value
  60. _dwThreadId = dwRegisteredThreadId;
  61. _hRpcBindingHandle = hRpc; // this is just a numeric copy! I am assuming that no two
  62. // binding handles will ever have the same value
  63. }
  64. ~CRpcSecurityCallback() {} // dtor currently unused
  65. DWORD GetRegisteredThreadId() { return _dwThreadId; };
  66. void SetAuthSvc(USHORT usAuthSvc) { _usAuthSvc = usAuthSvc; };
  67. BOOL WasAuthSvcSet() { return _usAuthSvc != INITIAL_NON_AUTHNSVC_VALUE; };
  68. USHORT GetAuthSvcResult() { return _usAuthSvc; };
  69. handle_t RegisteredHandle() { return _hRpcBindingHandle; };
  70. private:
  71. DWORD _dwThreadId;
  72. handle_t _hRpcBindingHandle;
  73. USHORT _usAuthSvc;
  74. };
  75. //+-------------------------------------------------------------------------
  76. //
  77. // Class for registering/receiving/storing rpc security
  78. // callback information; see bug 406902
  79. //
  80. class CRpcSecurityCallbackManager
  81. {
  82. public:
  83. // ctor
  84. CRpcSecurityCallbackManager(ORSTATUS& status)
  85. {
  86. _plistlock = new CSharedLock(status);
  87. if (!_plistlock)
  88. status = OR_NOMEM;
  89. };
  90. ~CRpcSecurityCallbackManager() {};
  91. // Registration function; a thread calls this before making an rpc call
  92. BOOL RegisterForRpcAuthSvcCallBack(handle_t hRpc);
  93. // Retrieval function; a thread calls this after making the rpc call
  94. BOOL GetAuthSvcAndTurnOffCallback(handle_t hRpc, USHORT* pusAuthSvc);
  95. private:
  96. // Function to just turn off the callback
  97. BOOL TurnOffCallback(handle_t hRpc);
  98. // Static callback function; has same signature as
  99. // RPC_SECURITY_CALLBACK_FN which is defined in rpcdce.h
  100. static void RPC_ENTRY RpcSecurityCallbackFunction(void* pvContext);
  101. // Helper function for storing results
  102. void StoreCallbackResult(USHORT usAuthSvc);
  103. CList _CallbackList; // list for holding the callbacks
  104. CSharedLock* _plistlock; // the lock
  105. };
  106. // external defn of the single instance of this class
  107. extern CRpcSecurityCallbackManager* gpCRpcSecurityCallbackMgr;
  108. //+-------------------------------------------------------------------------
  109. //
  110. // CUserPingSetCount
  111. //
  112. // Holds the current # of ping sets per SID
  113. //
  114. class CUserPingSetCount : public CListElement
  115. {
  116. public:
  117. // Ctor
  118. CUserPingSetCount(ORSTATUS &status, PSID pSid)
  119. {
  120. status = OR_OK;
  121. _dwCount = 0;
  122. _pSid = NULL; // NULL pSid is for unsecure user.
  123. if (pSid)
  124. {
  125. status = OR_NOMEM;
  126. DWORD dwLenSid = GetLengthSid(pSid);
  127. _pSid = (PSID*)new BYTE[dwLenSid];
  128. if (_pSid)
  129. {
  130. BOOL b = CopySid(dwLenSid, _pSid, pSid);
  131. ASSERT(b == TRUE);
  132. if (b)
  133. {
  134. status = OR_OK;
  135. }
  136. }
  137. }
  138. }
  139. ~CUserPingSetCount()
  140. {
  141. if (_pSid)
  142. delete []_pSid;
  143. }
  144. void Increment() { InterlockedIncrement((PLONG)&_dwCount); }
  145. void Decrement() { InterlockedDecrement((PLONG)&_dwCount); }
  146. DWORD GetCount() { return _dwCount;}
  147. BOOL IsEqual (PSID pSid) {
  148. if (pSid && _pSid)
  149. return EqualSid(pSid, _pSid);
  150. else
  151. return (pSid == _pSid);
  152. }
  153. private:
  154. DWORD _dwCount;
  155. PSID _pSid;
  156. };
  157. //+-------------------------------------------------------------------------
  158. //
  159. //
  160. // Mgr object for CUserPingSetCount
  161. //
  162. class CPingSetQuotaManager
  163. {
  164. public:
  165. // ctor
  166. CPingSetQuotaManager(ORSTATUS& status)
  167. {
  168. _plistlock = new CSharedLock(status);
  169. if (!_plistlock)
  170. status = OR_NOMEM;
  171. };
  172. ~CPingSetQuotaManager() { delete _plistlock; }
  173. void SetPerUserPingSetQuota(DWORD dwQuota);
  174. BOOL ManageQuotaForUser(PSID pSid, BOOL fAlloc);
  175. BOOL IsUserQuotaExceeded (PSID pSid);
  176. private:
  177. CList _UserPingSetCountList; // list for holding the callbacks
  178. CSharedLock* _plistlock; // the lock
  179. static DWORD _dwPerUserPingSetQuota;
  180. };
  181. extern CPingSetQuotaManager* gpPingSetQuotaManager;
  182. //
  183. // Memory allocation
  184. //
  185. // Inside of the object exporter, new and delete go to PrivMemAlloc.
  186. inline void* __cdecl operator new(size_t cbSize)
  187. {
  188. return PrivMemAlloc(cbSize);
  189. }
  190. inline void* __cdecl operator new(size_t cbSize, size_t cbExtra)
  191. {
  192. return PrivMemAlloc(cbSize + cbExtra);
  193. }
  194. inline void __cdecl operator delete(void *pvMem)
  195. {
  196. PrivMemFree(pvMem);
  197. }
  198. #endif // __MISC_HXX