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.

2573 lines
61 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1990 - 1999
  6. //
  7. // File: hndlsvr.hxx
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. Microsoft OS/2 LAN Manager
  12. Copyright(c) Microsoft Corp., 1990
  13. -------------------------------------------------------------------- */
  14. /* --------------------------------------------------------------------
  15. File : hndlsvr.hxx
  16. Description :
  17. The classes in the handle management layer which are specific to the
  18. server runtime live in this file. Classes common to both the client
  19. and server runtimes are in handle.hxx. The classes described here
  20. are independent of specific RPC protocol as well as transport.
  21. The class GENERIC_OBJECT is defined in handle.hxx.
  22. A pointer to a SERVER_HANDLE object is returned by the
  23. RpcCreateServer API.
  24. The INTERFACE_HANDLE class represents an interface and each
  25. INTERFACE_HANDLE object hangs from a SERVER_HANDLE object.
  26. An ADDRESS_HANDLE object is a transport address. When the
  27. ADDRESS_HANDLE object is added to a SERVER_HANDLE object, a manager
  28. will be started for the ADDRESS_HANDLE object.
  29. The SCONNECTION class represents a call handle on the server side.
  30. The ASSOCIATION_HANDLE class represents a client from the servers
  31. perspective.
  32. GENERIC_OBJECT
  33. SERVER_HANDLE
  34. INTERFACE_HANDLE
  35. ADDRESS_HANDLE
  36. MESSAGE_OBJECT
  37. SCONNECTION
  38. ASSOCIATION_HANDLE
  39. History :
  40. mikemon ??-??-?? Beginning of recorded history.
  41. mikemon 10-15-90 Changed the shutdown functionality to PauseExecution
  42. rather than suspending and resuming a thread.
  43. mikemon 12-28-90 Updated the comments to match reality.
  44. davidst ?? Add DG_SCALL as friend of RPC_SERVER
  45. connieh 8-2-93 Remove DG_SCALL as friend of RPC_SERVER
  46. tonychan 7-15-95 change RPC_ADDRESS class to have a list of NetAddr
  47. -------------------------------------------------------------------- */
  48. // Each association handle has a set of rundown routines associated with
  49. // it.
  50. #ifndef __HNDLSVR_HXX__
  51. #define __HNDLSVR_HXX__
  52. //typedef RPC_STATUS RPC_FORWARD_FUNCTION(
  53. // IN RPC_UUID InterfaceId,
  54. // IN RPC_VERSION * InterfaceVersion,
  55. // IN RPC_UUID ObjectId,
  56. // IN RPC_CHAR PAPI * RpcProtocolSequence,
  57. // IN void * * ppDestEndpoint);
  58. #define MAX_IF_CALLS 0xFFFFFFFF
  59. #define EP_REGISTER_NOREPLACE 0x00L
  60. #define EP_REGISTER_REPLACE 0x01L
  61. class RPC_SERVER;
  62. class SCONNECTION;
  63. class SCALL;
  64. RPC_STATUS
  65. RegisterEntries(
  66. IN RPC_IF_HANDLE IfSpec,
  67. IN RPC_BINDING_VECTOR * BindingVector,
  68. IN UUID_VECTOR * ObjUuidVector,
  69. IN unsigned char * Annotation,
  70. IN unsigned long ReplaceNoReplace
  71. );
  72. class RPC_INTERFACE_MANAGER
  73. /*++
  74. Class Description:
  75. An instance of this class is the manager for a particular type UUID
  76. for a particular interface. Each RPC_INTERFACE instance will contain
  77. a dictionary of these objects. Rather than keep a count of the calls
  78. using each manager, we just never delete these objects.
  79. Fields:
  80. TypeUuid - Contains the type of this interface manager. This is the
  81. key which we will use to find the correct interface manager in
  82. dictionary of interface managers maintained by each rpc interface.
  83. ManagerEpv - Contains a pointer to the manager entry point vector
  84. for this interface manager.
  85. ValidManagerFlag - Contains a flag indicating whether or not this
  86. manager is valid (that it has been registered more recently that
  87. it has been unregistered). The flag is zero if the the manager
  88. is not valid, and non-zero otherwise.
  89. ActiveCallCount - Contains a count of the number of calls which are
  90. active on this type manager.
  91. --*/
  92. {
  93. private:
  94. RPC_UUID TypeUuid;
  95. RPC_MGR_EPV PAPI * ManagerEpv;
  96. unsigned int ValidManagerFlag;
  97. INTERLOCKED_INTEGER ActiveCallCount;
  98. public:
  99. RPC_INTERFACE_MANAGER (
  100. IN RPC_UUID PAPI * TypeUuid,
  101. IN RPC_MGR_EPV PAPI * ManagerEpv
  102. );
  103. unsigned int
  104. ValidManager (
  105. );
  106. void
  107. SetManagerEpv (
  108. IN RPC_MGR_EPV PAPI * ManagerEpv
  109. );
  110. int
  111. MatchTypeUuid (
  112. IN RPC_UUID PAPI * TypeUuid
  113. );
  114. void
  115. InvalidateManager (
  116. );
  117. RPC_MGR_EPV PAPI *
  118. QueryManagerEpv (
  119. );
  120. void
  121. CallBeginning (
  122. );
  123. void
  124. CallEnding (
  125. );
  126. unsigned int
  127. InquireActiveCallCount (
  128. );
  129. };
  130. inline
  131. RPC_INTERFACE_MANAGER::RPC_INTERFACE_MANAGER (
  132. IN RPC_UUID PAPI * TypeUuid,
  133. IN RPC_MGR_EPV PAPI * ManagerEpv
  134. ) : ActiveCallCount(0)
  135. /*++
  136. Routine Description:
  137. An RPC_INTERFACE_MANAGER instance starts out being valid, so
  138. we make sure of that here. We also need make the type UUID of
  139. this be the same as the specified type UUID.
  140. --*/
  141. {
  142. ValidManagerFlag = 1;
  143. this->TypeUuid.CopyUuid(TypeUuid);
  144. this->ManagerEpv = ManagerEpv;
  145. }
  146. inline unsigned int
  147. RPC_INTERFACE_MANAGER::ValidManager (
  148. )
  149. /*++
  150. Routine Description:
  151. An indication of whether this manager is valid manager or not is
  152. returned.
  153. Return Value:
  154. Zero will be returned if this manager is not a valid manager;
  155. otherwise, non-zero will be returned.
  156. --*/
  157. {
  158. return(ValidManagerFlag);
  159. }
  160. inline void
  161. RPC_INTERFACE_MANAGER::SetManagerEpv (
  162. IN RPC_MGR_EPV PAPI * ManagerEpv
  163. )
  164. /*++
  165. Routine Description:
  166. This writer is used to set the manager entry point vector for
  167. this interface manager.
  168. Arguments:
  169. ManagerEpv - Supplies the new manager entry point vector for this.
  170. --*/
  171. {
  172. this->ManagerEpv = ManagerEpv;
  173. ValidManagerFlag = 1;
  174. }
  175. inline int
  176. RPC_INTERFACE_MANAGER::MatchTypeUuid (
  177. IN RPC_UUID PAPI * TypeUuid
  178. )
  179. /*++
  180. Routine Description:
  181. This method compares the supplied type UUID against the type UUID
  182. contained in this rpc interface manager.
  183. Arguments:
  184. TypeUuid - Supplies the type UUID.
  185. Return Value:
  186. Zero will be returned if the supplied type UUID is the same as the
  187. type UUID contained in this.
  188. --*/
  189. {
  190. return(this->TypeUuid.MatchUuid(TypeUuid));
  191. }
  192. inline void
  193. RPC_INTERFACE_MANAGER::InvalidateManager (
  194. )
  195. /*++
  196. Routine Description:
  197. This method is used to invalidate a manager
  198. --*/
  199. {
  200. ValidManagerFlag = 0;
  201. }
  202. inline RPC_MGR_EPV PAPI *
  203. RPC_INTERFACE_MANAGER::QueryManagerEpv (
  204. )
  205. /*++
  206. Routine Description:
  207. This method is called to obtain the manager entry point vector
  208. for this interface manager.
  209. Return Value:
  210. The manager entry point vector for this interface manager is returned.
  211. --*/
  212. {
  213. return(ManagerEpv);
  214. }
  215. inline void
  216. RPC_INTERFACE_MANAGER::CallBeginning (
  217. )
  218. /*++
  219. Routine Description:
  220. This method is used to indicate that a remote procedure call using this
  221. type manager is beginning.
  222. --*/
  223. {
  224. ActiveCallCount.Increment();
  225. }
  226. inline void
  227. RPC_INTERFACE_MANAGER::CallEnding (
  228. )
  229. /*++
  230. Routine Description:
  231. We are being notified that a remote procedure call using this type
  232. manager is done.
  233. --*/
  234. {
  235. ActiveCallCount.Decrement();
  236. }
  237. inline unsigned int
  238. RPC_INTERFACE_MANAGER::InquireActiveCallCount (
  239. )
  240. /*++
  241. Return Value:
  242. The number of remote procedure calls actively using this type manager
  243. will be returned.
  244. --*/
  245. {
  246. return((unsigned int) ActiveCallCount.GetInteger());
  247. }
  248. class RPC_INTERFACE;
  249. #if !defined(NO_LOCATOR_CODE)
  250. class NS_ENTRY
  251. {
  252. friend class RPC_INTERFACE;
  253. public:
  254. int Key;
  255. private:
  256. unsigned long EntryNameSyntax;
  257. RPC_CHAR *EntryName;
  258. public:
  259. NS_ENTRY(
  260. IN unsigned long MyEntryNameSyntax,
  261. RPC_CHAR *MyEntryName,
  262. OUT RPC_STATUS *Status
  263. );
  264. ~NS_ENTRY(
  265. );
  266. BOOL
  267. Match (
  268. IN unsigned long MyEntryNameSyntax,
  269. IN RPC_CHAR *MyEntryName
  270. );
  271. };
  272. inline
  273. NS_ENTRY::NS_ENTRY(
  274. IN unsigned long MyEntryNameSyntax,
  275. IN RPC_CHAR *MyEntryName,
  276. IN RPC_STATUS *Status
  277. )
  278. {
  279. int Length = (RpcpStringLength(MyEntryName)+1) * sizeof(RPC_CHAR);
  280. EntryNameSyntax = MyEntryNameSyntax;
  281. Key = -1;
  282. EntryName = (RPC_CHAR *) RpcpFarAllocate(Length);
  283. if (EntryName == 0)
  284. {
  285. *Status = RPC_S_OUT_OF_MEMORY;
  286. return;
  287. }
  288. RpcpStringCopy(EntryName, MyEntryName);
  289. *Status = RPC_S_OK;
  290. }
  291. inline
  292. NS_ENTRY::~NS_ENTRY(
  293. )
  294. {
  295. if (EntryName)
  296. {
  297. RpcpFarFree(EntryName);
  298. }
  299. }
  300. inline
  301. BOOL
  302. NS_ENTRY::Match (
  303. IN unsigned long MyEntryNameSyntax,
  304. IN RPC_CHAR *MyEntryName
  305. )
  306. {
  307. if (MyEntryNameSyntax == EntryNameSyntax
  308. && RpcpStringCompare(MyEntryName, EntryName) == 0)
  309. {
  310. return TRUE;
  311. }
  312. return FALSE;
  313. }
  314. NEW_SDICT(NS_ENTRY);
  315. #endif
  316. NEW_SDICT(RPC_INTERFACE_MANAGER);
  317. #if DBG
  318. typedef enum tagInterfaceUsesStrictContextHandles
  319. {
  320. iuschNo,
  321. iuschDontKnow,
  322. iuschYes
  323. } InterfaceUsesStrictContextHandles;
  324. #endif
  325. class RPC_INTERFACE
  326. /*++
  327. Class Description:
  328. This class represents an RPC interface. Rather than keep a count
  329. of the number of calls active (and bindings in the connection
  330. oriented runtimes), we never delete instances of this class. Hence,
  331. we need a flag indicating whether this interface is active or not.
  332. What we do is to keep a count of the number of managers for this
  333. interface.
  334. Once an interface is loaded, it can not be unloaded. The application
  335. has no way of knowing when all calls using stubs for the interface
  336. have completed.
  337. Fields:
  338. RpcInterfaceInformation - Contains a description of this interface.
  339. The interface UUID and version, as well as transfer syntax, live
  340. in this field. In addition, the stub dispatch table can be
  341. found here as well.
  342. InterfaceManagerDictionary - Contains the dictionary of interface
  343. managers for this interface.
  344. NullManagerEpv - Contains the manager entry point vector for the
  345. NULL type UUID. This is an optimization for the case in which
  346. object UUIDs are not used.
  347. NullManagerFlag - Contains a flag indictating whether or not this
  348. interface has a manager for the NULL type UUID. A non-zero value
  349. indicates there is a manager for the NULL type UUID.
  350. ManagerCount - Contains a count of the number of managers for this
  351. interface.
  352. Server - Contains a pointer to the rpc server which owns this
  353. interface.
  354. NullManagerActiveCallCount - Contains a count of the number of calls
  355. which are active on this interface using the manager for the NULL
  356. type UUID.
  357. --*/
  358. {
  359. private:
  360. RPC_SERVER * Server;
  361. unsigned int Flags ;
  362. unsigned int NullManagerFlag;
  363. RPC_MGR_EPV PAPI * NullManagerEpv;
  364. RPC_IF_CALLBACK_FN PAPI *CallbackFn ;
  365. RPC_SERVER_INTERFACE RpcInterfaceInformation;
  366. MIDL_SYNTAX_INFO *TransferSyntaxesArray;
  367. // the count of elements in the TransferSyntaxesArray. If this is 0,
  368. // the server supports only one transfer syntax and this is the transfer
  369. // syntax in the RpcInterfaceInformation->TransferSyntax
  370. ULONG NumberOfSupportedTransferSyntaxes;
  371. // the index of the transfer syntax preferred by the server
  372. ULONG PreferredTransferSyntax;
  373. int PipeInterfaceFlag ; // if 1, the interface contains methods that use pipes
  374. unsigned int ManagerCount;
  375. unsigned int MaxCalls ;
  376. BOOL fReplace;
  377. UUID_VECTOR *UuidVector;
  378. RPC_INTERFACE_MANAGER_DICT InterfaceManagerDictionary;
  379. unsigned char Annotation[64];
  380. #if !defined(NO_LOCATOR_CODE)
  381. NS_ENTRY_DICT NsEntries;
  382. #endif
  383. unsigned int MaxRpcSize;
  384. BOOL fBindingsExported;
  385. // These are call reference counts. They do not correspond to the number of active calls.
  386. // Every sync call takes 1 CallCount and every async call take up to 2 CallsCounts.
  387. // These values are used when unregistering an interface to wait for call completion.
  388. INTERLOCKED_INTEGER NullManagerActiveCallCount;
  389. INTERLOCKED_INTEGER AutoListenCallCount;
  390. // This is the actual number of auto listen calls in progress.
  391. INTERLOCKED_INTEGER AutoListenCallNumber;
  392. #if DBG
  393. InterfaceUsesStrictContextHandles Strict;
  394. #endif
  395. RPC_STATUS
  396. DispatchToStubWorker (
  397. IN OUT PRPC_MESSAGE Message,
  398. IN unsigned int CallbackFlag,
  399. IN PRPC_DISPATCH_TABLE DispatchTableToUse,
  400. OUT RPC_STATUS PAPI * ExceptionCode
  401. );
  402. public:
  403. unsigned long SequenceNumber ;
  404. RPC_INTERFACE (
  405. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  406. IN RPC_SERVER * Server,
  407. IN unsigned int Flags,
  408. IN unsigned int MaxCalls,
  409. IN unsigned int MaxRpcSize,
  410. IN RPC_IF_CALLBACK_FN PAPI *IfCallbackFn,
  411. OUT RPC_STATUS *Status
  412. );
  413. ~RPC_INTERFACE (
  414. );
  415. int
  416. MatchRpcInterfaceInformation (
  417. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation
  418. );
  419. RPC_STATUS
  420. RegisterTypeManager (
  421. IN RPC_UUID PAPI * ManagerTypeUuid OPTIONAL,
  422. IN RPC_MGR_EPV PAPI * ManagerEpv OPTIONAL
  423. );
  424. RPC_INTERFACE_MANAGER *
  425. FindInterfaceManager (
  426. IN RPC_UUID PAPI * ManagerTypeUuid
  427. );
  428. RPC_STATUS
  429. DispatchToStub (
  430. IN OUT PRPC_MESSAGE Message,
  431. IN unsigned int CallbackFlag,
  432. IN PRPC_DISPATCH_TABLE DispatchTableToUse,
  433. OUT RPC_STATUS PAPI * ExceptionCode
  434. );
  435. RPC_STATUS
  436. DispatchToStubWithObject (
  437. IN OUT PRPC_MESSAGE Message,
  438. IN RPC_UUID * ObjectUuid,
  439. IN unsigned int CallbackFlag,
  440. IN PRPC_DISPATCH_TABLE DispatchTableToUse,
  441. OUT RPC_STATUS PAPI * ExceptionCode
  442. );
  443. unsigned int
  444. MatchInterfaceIdentifier (
  445. IN PRPC_SYNTAX_IDENTIFIER InterfaceIdentifier
  446. );
  447. unsigned int
  448. SelectTransferSyntax (
  449. IN PRPC_SYNTAX_IDENTIFIER ProposedTransferSyntaxes,
  450. IN unsigned int NumberOfTransferSyntaxes,
  451. OUT PRPC_SYNTAX_IDENTIFIER AcceptedTransferSyntax,
  452. OUT BOOL *fIsInterfaceTransferPreferred,
  453. OUT int *ProposedTransferSyntaxIndex,
  454. OUT int *AvailableTransferSyntaxIndex
  455. );
  456. RPC_STATUS
  457. UnregisterManagerEpv (
  458. IN RPC_UUID PAPI * ManagerTypeUuid, OPTIONAL
  459. IN unsigned int WaitForCallsToComplete
  460. );
  461. RPC_STATUS
  462. InquireManagerEpv (
  463. IN RPC_UUID PAPI * ManagerTypeUuid, OPTIONAL
  464. OUT RPC_MGR_EPV PAPI * PAPI * ManagerEpv
  465. );
  466. RPC_STATUS
  467. UpdateRpcInterfaceInformation (
  468. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  469. IN unsigned int Flags,
  470. IN unsigned int MaxCalls,
  471. IN unsigned int MaxRpcSize,
  472. IN RPC_IF_CALLBACK_FN PAPI *IfCallbackFn
  473. );
  474. RPC_IF_ID __RPC_FAR *
  475. InquireInterfaceId (
  476. );
  477. inline int
  478. IsAutoListenInterface(
  479. ) ;
  480. inline BOOL
  481. IsUnknownAuthorityAllowed();
  482. inline BOOL
  483. IsAllowingUnsecureCallbacks();
  484. void
  485. BeginAutoListenCall (
  486. BOOL fIncCallNumber
  487. ) ;
  488. void
  489. EndAutoListenCall (
  490. BOOL fDecCallNumber
  491. ) ;
  492. long
  493. InqAutoListenCallCount(
  494. );
  495. RPC_SERVER_INTERFACE *
  496. InqInterfaceInformation (
  497. );
  498. RPC_STATUS
  499. CheckSecurityIfNecessary(
  500. IN void * Context
  501. );
  502. inline int
  503. IsSecurityCallbackReqd(
  504. );
  505. inline int
  506. IsSecure(
  507. );
  508. inline int
  509. IsOle(
  510. );
  511. inline int
  512. IsPipeInterface(
  513. ) ;
  514. BOOL
  515. IsObjectSupported (
  516. IN RPC_UUID * ObjectUuid
  517. );
  518. void
  519. BeginNullManagerCall (
  520. void
  521. )
  522. {
  523. NullManagerActiveCallCount.Increment();
  524. LogEvent(SU_IF, EV_INC, this, 0, NullManagerActiveCallCount.GetInteger(), 1, 0);
  525. }
  526. void
  527. EndNullManagerCall (
  528. void
  529. )
  530. {
  531. ASSERT(NullManagerActiveCallCount.GetInteger());
  532. NullManagerActiveCallCount.Decrement();
  533. LogEvent(SU_IF, EV_DEC, this, 0, NullManagerActiveCallCount.GetInteger(), 1, 0);
  534. }
  535. void
  536. EndCall(
  537. IN unsigned int CallbackFlag,
  538. IN BOOL fAsync = 0
  539. ) ;
  540. RPC_STATUS
  541. UpdateBindings(
  542. IN RPC_BINDING_VECTOR *BindingVector
  543. );
  544. inline BOOL
  545. NeedToUpdateBindings(
  546. void
  547. );
  548. RPC_STATUS
  549. InterfaceExported (
  550. IN UUID_VECTOR *MyObjectUuidVector,
  551. IN unsigned char *MyAnnotation,
  552. IN BOOL MyfReplace
  553. );
  554. void
  555. WaitForCalls(
  556. void
  557. );
  558. #if !defined(NO_LOCATOR_CODE)
  559. RPC_STATUS
  560. NsInterfaceExported (
  561. IN unsigned long EntryNameSyntax,
  562. IN RPC_CHAR *EntryName
  563. );
  564. RPC_STATUS
  565. NsInterfaceUnexported (
  566. IN unsigned long EntryNameSyntax,
  567. IN RPC_CHAR *EntryName
  568. );
  569. NS_ENTRY *
  570. FindEntry (
  571. IN unsigned long EntryNameSyntax,
  572. IN RPC_CHAR *EntryName
  573. );
  574. #endif
  575. BOOL
  576. CallSizeLimitReached (
  577. IN DWORD CurrentCallSize
  578. )
  579. {
  580. return (CurrentCallSize > MaxRpcSize);
  581. }
  582. DWORD GetInterfaceFirstDWORD(void)
  583. {
  584. return RpcInterfaceInformation.InterfaceId.SyntaxGUID.Data1;
  585. }
  586. PRPC_DISPATCH_TABLE GetDefaultDispatchTable(void)
  587. {
  588. return RpcInterfaceInformation.DispatchTable;
  589. }
  590. void GetSelectedTransferSyntaxAndDispatchTable(IN int SelectedTransferSyntaxIndex,
  591. OUT RPC_SYNTAX_IDENTIFIER **SelectedTransferSyntax,
  592. OUT PRPC_DISPATCH_TABLE *SelectedDispatchTable);
  593. #if DBG
  594. inline void
  595. InterfaceDoesNotUseStrict (
  596. void
  597. )
  598. {
  599. // it can go from No to No and from DontKnow to No,
  600. // but not from Yes to No
  601. ASSERT(Strict != iuschYes);
  602. if (Strict != iuschNo)
  603. Strict = iuschNo;
  604. }
  605. inline BOOL
  606. DoesInterfaceUseNonStrict (
  607. void
  608. )
  609. {
  610. // in this interface using non-strict?
  611. return (Strict == iuschNo);
  612. }
  613. #endif
  614. private:
  615. inline BOOL AreMultipleTransferSyntaxesSupported(void)
  616. {
  617. return NumberOfSupportedTransferSyntaxes;
  618. }
  619. };
  620. inline
  621. RPC_INTERFACE::~RPC_INTERFACE (
  622. )
  623. {
  624. #if !defined(NO_LOCATOR_CODE)
  625. NS_ENTRY *NsEntry;
  626. #endif
  627. unsigned int Length;
  628. DictionaryCursor cursor;
  629. if (fBindingsExported)
  630. {
  631. RpcpFarFree(UuidVector);
  632. }
  633. #if !defined(NO_LOCATOR_CODE)
  634. NsEntries.Reset(cursor);
  635. while (NsEntry = NsEntries.Next(cursor))
  636. {
  637. delete NsEntry;
  638. }
  639. #endif
  640. }
  641. // check if the interface has methods that use pipes
  642. inline int
  643. RPC_INTERFACE::IsPipeInterface (
  644. )
  645. {
  646. return (PipeInterfaceFlag) ;
  647. }
  648. inline int
  649. RPC_INTERFACE::IsSecurityCallbackReqd(
  650. )
  651. {
  652. if (CallbackFn)
  653. {
  654. return TRUE;
  655. }
  656. return FALSE;
  657. }
  658. inline int
  659. RPC_INTERFACE::IsSecure(
  660. )
  661. {
  662. if (CallbackFn || Flags & RPC_IF_ALLOW_SECURE_ONLY)
  663. {
  664. return TRUE;
  665. }
  666. return FALSE;
  667. }
  668. inline int
  669. RPC_INTERFACE::IsOle(
  670. )
  671. {
  672. if (Flags & RPC_IF_OLE)
  673. {
  674. return TRUE;
  675. }
  676. return FALSE;
  677. }
  678. inline void
  679. RPC_INTERFACE::BeginAutoListenCall (
  680. BOOL fIncCallNumber = FALSE
  681. )
  682. {
  683. int Number, Count;
  684. if (fIncCallNumber)
  685. {
  686. Number = AutoListenCallNumber.Increment();
  687. }
  688. Count = AutoListenCallCount.Increment() ;
  689. LogEvent(SU_HANDLE, EV_INC, this, UlongToPtr(Number), Count, 1);
  690. }
  691. inline void
  692. RPC_INTERFACE::EndAutoListenCall (
  693. BOOL fDecCallNumber = FALSE
  694. )
  695. {
  696. int Number, Count;
  697. if (fDecCallNumber)
  698. {
  699. ASSERT(AutoListenCallNumber.GetInteger() >= 1);
  700. Number = AutoListenCallNumber.Decrement();
  701. }
  702. ASSERT(AutoListenCallCount.GetInteger() >= 1);
  703. Count = AutoListenCallCount.Decrement() ;
  704. // As soon as we decrement AutoListenCallCount the interface may be unregistered and
  705. // freed since the count may drop to 0. Don't touch the object after this point.
  706. LogEvent(SU_HANDLE, EV_DEC, this, UlongToPtr(Number), Count, 1);
  707. }
  708. inline long
  709. RPC_INTERFACE::InqAutoListenCallCount (
  710. )
  711. {
  712. return AutoListenCallCount.GetInteger() ;
  713. }
  714. inline RPC_SERVER_INTERFACE *
  715. RPC_INTERFACE::InqInterfaceInformation (
  716. )
  717. {
  718. return &RpcInterfaceInformation;
  719. }
  720. inline int
  721. RPC_INTERFACE::IsAutoListenInterface (
  722. )
  723. {
  724. return (Flags & RPC_IF_AUTOLISTEN) ;
  725. }
  726. inline BOOL
  727. RPC_INTERFACE::IsUnknownAuthorityAllowed()
  728. {
  729. return ((Flags & RPC_IF_ALLOW_UNKNOWN_AUTHORITY) != 0);
  730. }
  731. inline BOOL
  732. RPC_INTERFACE::IsAllowingUnsecureCallbacks()
  733. {
  734. return ((Flags & RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH) != 0);
  735. }
  736. inline int
  737. RPC_INTERFACE::MatchRpcInterfaceInformation (
  738. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation
  739. )
  740. /*++
  741. Routine Description:
  742. This method compares the supplied rpc interface information against
  743. that contained in this rpc interface.
  744. Arguments:
  745. RpcInterfaceInformation - Supplies the rpc interface information.
  746. Return Value:
  747. Zero will be returned if the supplied rpc interface information
  748. (interface and transfer syntaxes) is the same as in this rpc interface;
  749. otherwise, non-zero will be returned.
  750. --*/
  751. {
  752. return(RpcpMemoryCompare(&(this->RpcInterfaceInformation),
  753. RpcInterfaceInformation, sizeof(RPC_SYNTAX_IDENTIFIER) * 2));
  754. }
  755. inline BOOL
  756. RPC_INTERFACE::NeedToUpdateBindings(
  757. void
  758. )
  759. /*++
  760. Function Name:NeedToUpdateBindings
  761. Parameters:
  762. Description:
  763. Returns TRUE if this interface has been exported to the epmapper
  764. or the name service. In this case, we need to update the
  765. bindings via UpdateBindings
  766. Returns:
  767. TRUE - the bindings need updating
  768. FALSE - the bindings don't need updating
  769. --*/
  770. {
  771. #if defined(NO_LOCATOR_CODE)
  772. return (fBindingsExported);
  773. #else
  774. return (fBindingsExported || (NsEntries.Size() > 0));
  775. #endif
  776. }
  777. extern RPC_INTERFACE *GlobalManagementInterface;
  778. class RPC_ADDRESS : public GENERIC_OBJECT
  779. /*++
  780. Class Description:
  781. This class represents an address (or protocol sequence in the DCE
  782. lingo). An address is responsible for receiving calls, dispatching
  783. them to an interface, and then returning the reply.
  784. Fields:
  785. StaticEndpointFlag - This field specifies whether this address has
  786. a static endpoint or a dynamic endpoint. This information is
  787. necessary so that when we create a binding handle from this
  788. address we know whether or not to specify an endpoint. See
  789. the InquireBinding method of this class. A value of zero
  790. indicates a dynamic endpoint, and a value of non-zero indicates
  791. a static endpoint.
  792. --*/
  793. {
  794. protected:
  795. TRANS_INFO *TransInfo;
  796. private:
  797. RPC_CHAR PAPI * Endpoint;
  798. RPC_CHAR PAPI * RpcProtocolSequence;
  799. RPC_CHAR PAPI * NetworkAddress;
  800. unsigned int StaticEndpointFlag;
  801. protected:
  802. int ActiveCallCount;
  803. unsigned int PendingQueueSize;
  804. void PAPI *SecurityDescriptor;
  805. unsigned long NICFlags;
  806. unsigned long EndpointFlags;
  807. RPC_ADDRESS (
  808. IN OUT RPC_STATUS PAPI * RpcStatus
  809. );
  810. public:
  811. RPC_SERVER * Server;
  812. MUTEX AddressMutex;
  813. int DictKey;
  814. virtual ~RPC_ADDRESS (
  815. );
  816. virtual RPC_STATUS
  817. ServerSetupAddress (
  818. IN RPC_CHAR PAPI * NetworkAddress,
  819. IN RPC_CHAR PAPI * PAPI *Endpoint,
  820. IN unsigned int PendingQueueSize,
  821. IN void PAPI * SecurityDescriptor, OPTIONAL
  822. IN unsigned long EndpointFlags,
  823. IN unsigned long NICFlags
  824. ) = 0;
  825. virtual void
  826. PnpNotify (
  827. ) {};
  828. virtual void
  829. EncourageCallCleanup(
  830. RPC_INTERFACE * Interface
  831. );
  832. RPC_CHAR *
  833. GetListNetworkAddress (IN unsigned int Index
  834. );
  835. unsigned int
  836. InqNumNetworkAddress();
  837. RPC_STATUS
  838. SetEndpointAndStuff (
  839. IN RPC_CHAR PAPI * NetworkAddress,
  840. IN RPC_CHAR PAPI * Endpoint,
  841. IN RPC_CHAR PAPI * RpcProtocolSequence,
  842. IN RPC_SERVER * Server,
  843. IN unsigned int StaticEndpointFlag,
  844. IN unsigned int PendingQueueSize,
  845. IN void PAPI *SecurityDescriptor,
  846. IN unsigned long EndpointFlags,
  847. IN unsigned long NICFlags
  848. );
  849. RPC_STATUS
  850. FindInterfaceTransfer (
  851. IN PRPC_SYNTAX_IDENTIFIER InterfaceIdentifier,
  852. IN PRPC_SYNTAX_IDENTIFIER ProposedTransferSyntaxes,
  853. IN unsigned int NumberOfTransferSyntaxes,
  854. OUT PRPC_SYNTAX_IDENTIFIER AcceptedTransferSyntax,
  855. OUT RPC_INTERFACE ** RpcInterface,
  856. OUT BOOL *fIsInterfaceTransferPreferred,
  857. OUT int *ProposedTransferSyntaxIndex,
  858. OUT int *AvailableTransferSyntaxIndex
  859. );
  860. virtual RPC_STATUS
  861. CompleteListen (
  862. ) ;
  863. BINDING_HANDLE *
  864. InquireBinding (RPC_CHAR * LocalNetworkAddress = 0
  865. );
  866. virtual RPC_STATUS
  867. ServerStartingToListen (
  868. IN unsigned int MinimumCallThreads,
  869. IN unsigned int MaximumConcurrentCalls
  870. );
  871. virtual void
  872. ServerStoppedListening (
  873. );
  874. int
  875. SameEndpointAndProtocolSequence (
  876. IN RPC_CHAR PAPI * NetworkAddress,
  877. IN RPC_CHAR PAPI * RpcProtocolSequence,
  878. IN RPC_CHAR PAPI * Endpoint
  879. );
  880. RPC_STATUS
  881. SameProtocolSequenceAndSD (
  882. IN RPC_CHAR PAPI * NetworkAddress,
  883. IN RPC_CHAR PAPI * RpcProtocolSequence,
  884. IN SECURITY_DESCRIPTOR *SecurityDescriptor OPTIONAL,
  885. OUT BOOL *IsEqual
  886. );
  887. virtual long
  888. InqNumberOfActiveCalls (
  889. );
  890. RPC_CHAR *
  891. InqEndpoint (
  892. )
  893. {
  894. return(Endpoint);
  895. }
  896. RPC_CHAR *
  897. InqRpcProtocolSequence (
  898. );
  899. virtual void
  900. WaitForCalls(
  901. ) ;
  902. RPC_STATUS
  903. RestartAddress (
  904. IN unsigned int MinThreads,
  905. IN unsigned int MaxCalls
  906. );
  907. RPC_STATUS
  908. CopyDescriptor (
  909. IN void *SecurityDescriptor,
  910. OUT void **OutDescriptor
  911. );
  912. virtual void
  913. DestroyContextHandlesForInterface (
  914. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  915. IN BOOL RundownContextHandles
  916. );
  917. virtual void
  918. CleanupIdleSContexts (
  919. void
  920. );
  921. virtual NETWORK_ADDRESS_VECTOR *
  922. GetNetworkAddressVector (
  923. void
  924. );
  925. };
  926. inline void
  927. RPC_ADDRESS::EncourageCallCleanup(
  928. RPC_INTERFACE * Interface
  929. )
  930. {
  931. }
  932. inline void
  933. RPC_ADDRESS::WaitForCalls(
  934. )
  935. {
  936. }
  937. inline RPC_STATUS
  938. RPC_ADDRESS::CompleteListen (
  939. )
  940. {
  941. return RPC_S_OK ;
  942. }
  943. inline int
  944. RPC_ADDRESS::SameEndpointAndProtocolSequence (
  945. IN RPC_CHAR PAPI * NetworkAddress,
  946. IN RPC_CHAR PAPI * ProtocolSequence,
  947. IN RPC_CHAR PAPI * Endpoint
  948. )
  949. /*++
  950. Routine Description:
  951. This routine is used to determine if the rpc address has the same
  952. endpoint and protocol sequence as the endpoint and protocol sequence
  953. supplied as arguments.
  954. Arguments:
  955. ProtocolSequence - Supplies the protocol sequence to compare against
  956. the protocol sequence of this address.
  957. Endpoint - Supplies the endpoint to compare against the endpoint in this
  958. address.
  959. Return Value:
  960. Non-zero will be returned if this address and the supplied endpoint and
  961. protocol sequence are the same, otherwise, zero will be returned.
  962. --*/
  963. {
  964. if (NetworkAddress == NULL && this->NetworkAddress == NULL)
  965. {
  966. return(( RpcpStringCompare(this->Endpoint, Endpoint) == 0 )
  967. && ( RpcpStringCompare(this->RpcProtocolSequence,
  968. ProtocolSequence) == 0 ));
  969. }
  970. else if (NetworkAddress == NULL || this->NetworkAddress == NULL)
  971. {
  972. return 0;
  973. }
  974. return(( RpcpStringCompare(this->Endpoint, Endpoint) == 0 )
  975. && ( RpcpStringCompare(this->RpcProtocolSequence, ProtocolSequence) == 0 )
  976. && ( RpcpStringCompare(this->NetworkAddress, NetworkAddress) == 0 ));
  977. }
  978. inline RPC_CHAR *
  979. RPC_ADDRESS::InqRpcProtocolSequence (
  980. )
  981. {
  982. return(RpcProtocolSequence);
  983. }
  984. inline unsigned int
  985. RPC_ADDRESS::InqNumNetworkAddress (
  986. )
  987. {
  988. return(GetNetworkAddressVector()->Count);
  989. }
  990. NEW_SDICT(RPC_INTERFACE);
  991. NEW_SDICT(RPC_ADDRESS);
  992. class RPC_AUTHENTICATION
  993. {
  994. public:
  995. RPC_CHAR __RPC_FAR * ServerPrincipalName;
  996. unsigned long AuthenticationService;
  997. RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFunction;
  998. void __RPC_FAR * Argument;
  999. };
  1000. NEW_SDICT(RPC_AUTHENTICATION);
  1001. class TIMER
  1002. {
  1003. private:
  1004. HANDLE hThread;
  1005. public:
  1006. TIMER(RPC_STATUS *Status, int fManualReset)
  1007. {
  1008. hThread = 0;
  1009. *Status = RPC_S_OK;
  1010. ASSERT(fManualReset == 0);
  1011. }
  1012. BOOL Wait(
  1013. IN DWORD Milliseconds
  1014. )
  1015. {
  1016. NTSTATUS NtStatus;
  1017. LARGE_INTEGER Timeout;
  1018. Timeout.QuadPart = Int32x32To64(Milliseconds, -10000);
  1019. rewait:
  1020. {
  1021. NtStatus = NtDelayExecution(TRUE, &Timeout);
  1022. if (NtStatus == STATUS_USER_APC)
  1023. goto rewait;
  1024. }
  1025. if (NtStatus == STATUS_ALERTED)
  1026. {
  1027. return 0;
  1028. }
  1029. return 1;
  1030. }
  1031. void Raise()
  1032. {
  1033. NTSTATUS NtStatus;
  1034. ASSERT(hThread);
  1035. NtStatus = NtAlertThread(hThread);
  1036. ASSERT(NT_SUCCESS(NtStatus));
  1037. }
  1038. void SetThread(THREAD *pThread)
  1039. {
  1040. hThread = pThread->ThreadHandle();
  1041. ASSERT(hThread);
  1042. }
  1043. };
  1044. typedef enum CachedThreadWorkAvailableTag
  1045. {
  1046. WorkIsNotAvailable = 0,
  1047. WorkIsAvailable
  1048. } CachedThreadWorkAvailable;
  1049. class CACHED_THREAD
  1050. /*++
  1051. Class Description:
  1052. This class is used to implement a thread cache. Each thread which
  1053. has been cached is represented by an object of this class. All of the
  1054. fields of this class are protected by the server mutex of the owning
  1055. rpc server.
  1056. Fields:
  1057. Next - Forward link pointer of cached thread list.
  1058. Previous - Backward link pointer of cached thread list.
  1059. Procedure - The procedure which the thread should execute will be
  1060. placed here before the event gets kicked.
  1061. Parameter - The parameter which the thread should pass to the procedure
  1062. will be placed here.
  1063. OwningRpcServer - Contains a pointer to the rpc server which owns this
  1064. cached thread. This is necessary so that we can put this cached
  1065. thread into the cache.
  1066. WaitForWorkEvent - Contains the event which this cached thread will
  1067. wait on for more work to do.
  1068. WorkAvailableFlag - A non-zero value of this flag indicates that there
  1069. is work available for this thread. This is necessary to close a
  1070. race condition between the thread timing out waiting for work, and
  1071. the server requesting this thread to do work.
  1072. --*/
  1073. {
  1074. friend class RPC_SERVER;
  1075. friend void
  1076. BaseCachedThreadRoutine (
  1077. IN CACHED_THREAD * CachedThread
  1078. );
  1079. private:
  1080. CACHED_THREAD * Next;
  1081. CACHED_THREAD * Previous;
  1082. THREAD_PROC Procedure;
  1083. PVOID Parameter;
  1084. RPC_SERVER * OwningRpcServer;
  1085. CachedThreadWorkAvailable WorkAvailableFlag;
  1086. TIMER WaitForWorkEvent;
  1087. public:
  1088. CACHED_THREAD (
  1089. IN THREAD_PROC Procedure,
  1090. IN void * Parameter,
  1091. IN RPC_SERVER * RpcServer,
  1092. IN RPC_STATUS * RpcStatus
  1093. ) : WaitForWorkEvent(RpcStatus, 0),
  1094. Procedure(Procedure),
  1095. Parameter(Parameter),
  1096. OwningRpcServer(RpcServer),
  1097. WorkAvailableFlag(WorkIsNotAvailable),
  1098. Next(0),
  1099. Previous(0)
  1100. {
  1101. }
  1102. BOOL
  1103. CallProcedure (
  1104. )
  1105. {
  1106. // by convention, IOCP worker threads will return non-zero,
  1107. // while LRPC worker threads will return 0.
  1108. return((*Procedure)(Parameter));
  1109. }
  1110. void SetThread(THREAD *p)
  1111. {
  1112. WaitForWorkEvent.SetThread(p);
  1113. }
  1114. void SetWakeUpThreadParams(THREAD_PROC Procedure, PVOID Parameter)
  1115. {
  1116. this->Procedure = Procedure;
  1117. this->Parameter = Parameter;
  1118. WorkAvailableFlag = WorkIsAvailable;
  1119. }
  1120. void WakeUpThread(void)
  1121. {
  1122. WaitForWorkEvent.Raise();
  1123. }
  1124. inline void *GetParameter(void)
  1125. {
  1126. return Parameter;
  1127. }
  1128. };
  1129. typedef (*NS_EXPORT_FUNC) (
  1130. IN unsigned long EntryNameSyntax,
  1131. IN RPC_CHAR *EntryName,
  1132. IN RPC_IF_HANDLE RpcInterfaceInformation,
  1133. IN RPC_BINDING_VECTOR * BindingVector,
  1134. IN UUID_VECTOR *UuidVector
  1135. );
  1136. typedef (*NS_UNEXPORT_FUNC) (
  1137. IN unsigned long EntryNameSyntax,
  1138. IN RPC_CHAR *EntryName,
  1139. IN RPC_IF_HANDLE RpcInterfaceInformation,
  1140. IN UUID_VECTOR *UuidVector
  1141. );
  1142. class RPC_SERVER
  1143. /*++
  1144. Class Description:
  1145. This class represents an RPC server. Interfaces and addresses get
  1146. hung from an rpc server object.
  1147. Fields:
  1148. RpcInterfaceDictionary - Contains a dictionary of rpc interfaces
  1149. which have been registered with this server.
  1150. ServerMutex - Contains a mutex used to serialize access to this
  1151. data structure.
  1152. AvailableCallCount - Contains a count of the number of available calls
  1153. on all rpc interfaces owned by this server.
  1154. ServerListeningFlag - Contains an indication of whether or not
  1155. this rpc server is listening for remote procedure calls. If
  1156. this flag is zero, the server is not listening; otherwise, if
  1157. the flag is non-zero, the server is listening.
  1158. RpcAddressDictionary - Contains a dictionary of rpc addresses which
  1159. have been registered with this server.
  1160. ListeningThreadFlag - Contains a flag which indicates whether or
  1161. not there is a thread in the ServerListen method. The
  1162. ServerListeningFlag can not be used because it will be zero
  1163. will the listening thread is waiting for all active calls to
  1164. complete.
  1165. StopListeningEvent - Contains an event which the thread which called
  1166. ServerListen will wait on. When StopServerListening is called,
  1167. this event will get kicked. If a non-recoverable error occurs,
  1168. the event will also get kicked.
  1169. ListenStatusCode - Contains the status code which ServerListen will
  1170. return.
  1171. MaximumConcurrentCalls - Contains the maximum number of concurrent
  1172. remote procedure calls allowed for this rpc server.
  1173. MinimumCallThreads - Contains the minimum number of call threads
  1174. which should be available to service remote procedure calls on
  1175. each protocol sequence.
  1176. IncomingRpcCount - This field keeps track of the number of incoming
  1177. remote procedure calls (or callbacks) which this server has
  1178. received.
  1179. OutgoingRpcCount - This field keeps track of the number of outgoing
  1180. remote procedure callbacks initiated by this server.
  1181. ReceivedPacketCount - Contains the number of network packets received
  1182. by this server.
  1183. SentPacketCount - Contains the number of network packets sent by this
  1184. server.
  1185. AuthenticationDictionary - Contains the set of authentication services
  1186. supported by this server.
  1187. WaitingThreadFlag - Contains a flag indicating whether or not there
  1188. is a thread waiting for StopServerListening to be called and then
  1189. for all calls to complete.
  1190. ThreadCache - This field points to the top of the stack of CACHED_THREAD
  1191. objects which forms the thread cache. This field is protected by the
  1192. thread cache mutex rather than the server mutex.
  1193. ThreadCacheMutex - This field is used to serialize access to the thread
  1194. cache. We need to do this to prevent deadlocks between the server
  1195. mutex and an address mutex.
  1196. pEpmapperForwardFunction - Function to determine if and where a
  1197. packet is to be forwarded to.
  1198. --*/
  1199. {
  1200. friend void
  1201. BaseCachedThreadRoutine (
  1202. IN CACHED_THREAD * CachedThread
  1203. );
  1204. public:
  1205. // accessed by all threads independently - put in separate cache line
  1206. MUTEX ServerMutex;
  1207. private:
  1208. #if !defined(NO_LOCATOR_CODE)
  1209. NS_EXPORT_FUNC pNsBindingExport;
  1210. #endif
  1211. RPC_STATUS ListenStatusCode;
  1212. unsigned int ListeningThreadFlag;
  1213. public:
  1214. unsigned int MinimumCallThreads;
  1215. private:
  1216. unsigned int WaitingThreadFlag;
  1217. unsigned long OutgoingRpcCount;
  1218. long padding0;
  1219. // accessed by all threads independently - put in separate cache line
  1220. unsigned long IncomingRpcCount;
  1221. RPC_ADDRESS_DICT RpcAddressDictionary;
  1222. // accessed by all threads independently - put in separate cache line
  1223. INTERLOCKED_INTEGER AvailableCallCount;
  1224. QUEUE RpcDormantAddresses;
  1225. // accessed by all threads independently - put in separate cache line
  1226. unsigned long SentPacketCount;
  1227. CACHED_THREAD *ThreadCache;
  1228. MUTEX ThreadCacheMutex;
  1229. // accessed by all threads independently - put in separate cache line
  1230. unsigned int MaximumConcurrentCalls;
  1231. EVENT StopListeningEvent;
  1232. INTERLOCKED_INTEGER NumAutoListenInterfaces ;
  1233. #if !defined(NO_LOCATOR_CODE)
  1234. NS_UNEXPORT_FUNC pNsBindingUnexport;
  1235. #endif
  1236. long padding1[4];
  1237. // accessed by all threads independently - put in separate cache line
  1238. RPC_INTERFACE_DICT RpcInterfaceDictionary;
  1239. public:
  1240. // accessed by all threads independently - put in separate cache line
  1241. unsigned int ServerListeningFlag;
  1242. BOOL fAccountForMaxCalls;
  1243. long padding2[6];
  1244. // accessed by all threads independently - put in separate cache line
  1245. unsigned long ReceivedPacketCount;
  1246. public:
  1247. RPC_FORWARD_FUNCTION * pRpcForwardFunction;
  1248. private:
  1249. long padding3[6];
  1250. // accessed by all threads independently - put in separate cache line
  1251. RPC_AUTHENTICATION_DICT AuthenticationDictionary;
  1252. public:
  1253. RPC_SERVER (
  1254. IN OUT RPC_STATUS PAPI * RpcStatus
  1255. );
  1256. RPC_INTERFACE *
  1257. FindInterface (
  1258. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation
  1259. );
  1260. int
  1261. AddInterface (
  1262. IN RPC_INTERFACE * RpcInterface
  1263. );
  1264. unsigned int
  1265. IsServerListening (
  1266. );
  1267. long InqNumAutoListenInterfaces (
  1268. ) ;
  1269. unsigned int
  1270. CallBeginning (
  1271. );
  1272. void
  1273. CallEnding (
  1274. );
  1275. RPC_STATUS
  1276. FindInterfaceTransfer (
  1277. IN PRPC_SYNTAX_IDENTIFIER InterfaceIdentifier,
  1278. IN PRPC_SYNTAX_IDENTIFIER ProposedTransferSyntaxes,
  1279. IN unsigned int NumberOfTransferSyntaxes,
  1280. OUT PRPC_SYNTAX_IDENTIFIER AcceptedTransferSyntax,
  1281. OUT RPC_INTERFACE ** RpcInterface,
  1282. OUT BOOL *fInterfaceTransferIsPreferred,
  1283. OUT int *ProposedTransferSyntaxIndex,
  1284. OUT int *AvailableTransferSyntaxIndex
  1285. );
  1286. RPC_INTERFACE *
  1287. FindInterface (
  1288. IN PRPC_SYNTAX_IDENTIFIER InterfaceIdentifier
  1289. );
  1290. RPC_STATUS
  1291. ServerListen (
  1292. IN unsigned int MinimumCallThreads,
  1293. IN unsigned int MaximumConcurrentCalls,
  1294. IN unsigned int DontWait
  1295. );
  1296. RPC_STATUS
  1297. WaitForStopServerListening (
  1298. );
  1299. RPC_STATUS
  1300. WaitServerListen (
  1301. );
  1302. void
  1303. InquireStatistics (
  1304. OUT RPC_STATS_VECTOR * Statistics
  1305. );
  1306. RPC_STATUS
  1307. StopServerListening (
  1308. );
  1309. RPC_STATUS
  1310. UseRpcProtocolSequence (
  1311. IN RPC_CHAR PAPI * NetworkAddress,
  1312. IN RPC_CHAR PAPI * RpcProtocolSequence,
  1313. IN unsigned int PendingQueueSize,
  1314. IN RPC_CHAR PAPI *Endpoint,
  1315. IN void PAPI * SecurityDescriptor,
  1316. IN unsigned long EndpointFlags,
  1317. IN unsigned long NICFlags,
  1318. IN RPC_CHAR PAPI **pEndpointListenedOn = NULL, OPTIONAL
  1319. IN BOOL fUseDuplicateEndpoints = FALSE OPTIONAL
  1320. );
  1321. RPC_STATUS
  1322. UnregisterEndpoint (
  1323. IN RPC_CHAR __RPC_FAR * RpcProtocolSequence,
  1324. IN RPC_CHAR __RPC_FAR * Endpoint
  1325. );
  1326. int
  1327. AddAddress (
  1328. IN RPC_ADDRESS * RpcAddress
  1329. );
  1330. RPC_STATUS
  1331. UnregisterIf (
  1332. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1333. IN RPC_UUID PAPI * ManagerTypeUuid OPTIONAL,
  1334. IN unsigned int WaitForCallsToComplete
  1335. );
  1336. RPC_STATUS
  1337. InquireManagerEpv (
  1338. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1339. IN RPC_UUID PAPI * ManagerTypeUuid, OPTIONAL
  1340. OUT RPC_MGR_EPV PAPI * PAPI * ManagerEpv
  1341. );
  1342. RPC_STATUS
  1343. InquireBindings (
  1344. OUT RPC_BINDING_VECTOR PAPI * PAPI * BindingVector
  1345. );
  1346. RPC_STATUS
  1347. AutoRegisterAuthSvc(
  1348. IN RPC_CHAR * ServerPrincipalName,
  1349. IN unsigned long AuthenticationService
  1350. );
  1351. RPC_STATUS
  1352. RegisterAuthInfoHelper (
  1353. IN RPC_CHAR PAPI * ServerPrincipalName,
  1354. IN unsigned long AuthenticationService,
  1355. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFunction, OPTIONAL
  1356. IN void PAPI * Argument OPTIONAL
  1357. );
  1358. RPC_STATUS
  1359. RegisterAuthInformation (
  1360. IN RPC_CHAR PAPI * ServerPrincipalName,
  1361. IN unsigned long AuthenticationService,
  1362. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFunction, OPTIONAL
  1363. IN void PAPI * Argument OPTIONAL
  1364. );
  1365. RPC_STATUS
  1366. AcquireCredentials (
  1367. IN unsigned long AuthenticationService,
  1368. IN unsigned long AuthenticationLevel,
  1369. OUT SECURITY_CREDENTIALS ** SecurityCredentials
  1370. );
  1371. void
  1372. FreeCredentials (
  1373. IN SECURITY_CREDENTIALS * SecurityCredentials
  1374. );
  1375. RPC_STATUS
  1376. RegisterInterface (
  1377. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1378. IN RPC_UUID PAPI * ManagerTypeUuid,
  1379. IN RPC_MGR_EPV PAPI * ManagerEpv,
  1380. IN unsigned int Flags,
  1381. IN unsigned int MaxCalls,
  1382. IN unsigned int MaxRpcSize,
  1383. IN RPC_IF_CALLBACK_FN PAPI *IfCallbackFn
  1384. );
  1385. void IncomingCall(void);
  1386. void OutgoingCallback(void);
  1387. void PacketReceived(void);
  1388. void PacketSent(void);
  1389. RPC_STATUS
  1390. CreateThread (
  1391. IN THREAD_PROC Procedure,
  1392. IN void * Parameter);
  1393. RPC_STATUS
  1394. InquireInterfaceIds (
  1395. OUT RPC_IF_ID_VECTOR __RPC_FAR * __RPC_FAR * InterfaceIdVector
  1396. );
  1397. RPC_STATUS
  1398. InquirePrincipalName (
  1399. IN unsigned long AuthenticationService,
  1400. OUT RPC_CHAR __RPC_FAR * __RPC_FAR * ServerPrincipalName
  1401. );
  1402. unsigned int
  1403. InquireInterfaceCount (
  1404. );
  1405. void
  1406. RegisterRpcForwardFunction(
  1407. RPC_FORWARD_FUNCTION * pForwardFunction
  1408. );
  1409. void
  1410. IncrementAutoListenInterfaceCount (
  1411. ) ;
  1412. void
  1413. DecrementAutoListenInterfaceCount (
  1414. ) ;
  1415. void
  1416. InsertIntoFreeList(
  1417. CACHED_THREAD *CachedThread
  1418. );
  1419. void
  1420. RemoveFromFreeList(
  1421. CACHED_THREAD *CachedThread
  1422. );
  1423. CACHED_THREAD *RemoveHeadFromFreeList(void);
  1424. void CreateOrUpdateAddresses (void);
  1425. RPC_INTERFACE *
  1426. FindOrCreateInterface (
  1427. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1428. OUT RPC_STATUS *Status
  1429. );
  1430. RPC_STATUS
  1431. InterfaceExported (
  1432. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1433. IN UUID_VECTOR *MyObjectUuidVector,
  1434. IN unsigned char *MyAnnotation,
  1435. IN BOOL MyfReplace
  1436. );
  1437. #if !defined(NO_LOCATOR_CODE)
  1438. RPC_STATUS
  1439. NsInterfaceExported (
  1440. IN unsigned long EntryNameSyntax,
  1441. IN RPC_CHAR *EntryName,
  1442. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1443. IN BOOL fUnexport
  1444. );
  1445. RPC_STATUS
  1446. NsBindingUnexport (
  1447. IN unsigned long EntryNameSyntax,
  1448. IN RPC_CHAR *EntryName,
  1449. IN RPC_IF_HANDLE IfSpec
  1450. );
  1451. RPC_STATUS
  1452. NsBindingExport(
  1453. IN unsigned long EntryNameSyntax,
  1454. IN RPC_CHAR *EntryName,
  1455. IN RPC_IF_HANDLE IfSpec,
  1456. IN RPC_BINDING_VECTOR *BindingVector
  1457. );
  1458. #endif
  1459. typedef enum
  1460. {
  1461. actDestroyContextHandle = 0,
  1462. actCleanupIdleSContext
  1463. } AddressCallbackType;
  1464. RPC_STATUS
  1465. EnumerateAndCallEachAddress (
  1466. IN AddressCallbackType actType,
  1467. IN OUT void *Context OPTIONAL
  1468. );
  1469. private:
  1470. RPC_INTERFACE *
  1471. RPC_SERVER::FindOrCreateInterfaceInternal (
  1472. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1473. IN unsigned int Flags,
  1474. IN unsigned int MaxCalls,
  1475. IN unsigned int MaxRpcSize,
  1476. IN RPC_IF_CALLBACK_FN PAPI *IfCallbackFn,
  1477. OUT RPC_STATUS *Status,
  1478. OUT BOOL *fInterfaceFound
  1479. );
  1480. };
  1481. #if !defined(NO_LOCATOR_CODE)
  1482. inline RPC_STATUS
  1483. RPC_SERVER::NsBindingUnexport (
  1484. IN unsigned long EntryNameSyntax,
  1485. IN RPC_CHAR *EntryName,
  1486. IN RPC_IF_HANDLE IfSpec
  1487. )
  1488. {
  1489. return (*pNsBindingUnexport)
  1490. (EntryNameSyntax, EntryName, IfSpec, NULL);
  1491. }
  1492. inline RPC_STATUS
  1493. RPC_SERVER::NsBindingExport (
  1494. IN unsigned long EntryNameSyntax,
  1495. IN RPC_CHAR *EntryName,
  1496. IN RPC_IF_HANDLE IfSpec,
  1497. IN RPC_BINDING_VECTOR *BindingVector
  1498. )
  1499. {
  1500. return (*pNsBindingExport)
  1501. (EntryNameSyntax, EntryName, IfSpec, BindingVector, NULL);
  1502. }
  1503. #endif
  1504. inline void
  1505. RPC_SERVER::IncrementAutoListenInterfaceCount (
  1506. )
  1507. {
  1508. NumAutoListenInterfaces.Increment() ;
  1509. }
  1510. inline void
  1511. RPC_SERVER::DecrementAutoListenInterfaceCount (
  1512. )
  1513. {
  1514. NumAutoListenInterfaces.Decrement() ;
  1515. }
  1516. inline long
  1517. RPC_SERVER::InqNumAutoListenInterfaces (
  1518. )
  1519. {
  1520. return (NumAutoListenInterfaces.GetInteger()) ;
  1521. }
  1522. inline unsigned int
  1523. RPC_SERVER::InquireInterfaceCount (
  1524. )
  1525. {
  1526. return RpcInterfaceDictionary.Size();
  1527. }
  1528. inline unsigned int
  1529. RPC_SERVER::IsServerListening (
  1530. )
  1531. /*++
  1532. Routine Description:
  1533. This method returns an indication of whether or not this rpc server
  1534. is listening for remote procedure calls.
  1535. Return Value:
  1536. Zero will be returned if this rpc server is not listening for
  1537. remote procedure calls; otherwise, non-zero will be returned.
  1538. --*/
  1539. {
  1540. return(ServerListeningFlag);
  1541. }
  1542. inline unsigned int
  1543. RPC_SERVER::CallBeginning (
  1544. )
  1545. /*++
  1546. Routine Description:
  1547. Before dispatching a new remote procedure call to a stub, this method
  1548. will get called. It checks to see if this call will cause there to
  1549. be too many concurrent remote procedure calls. If the call is allowed
  1550. the call count is updated so we can tell when all calls have
  1551. completed.
  1552. Zero will be returned if another concurrent remote procedure call
  1553. is not allowed; otherwise, non-zero will be returned.
  1554. --*/
  1555. {
  1556. if (AvailableCallCount.Decrement() >= 0)
  1557. return TRUE;
  1558. else
  1559. {
  1560. AvailableCallCount.Increment();
  1561. return FALSE;
  1562. }
  1563. }
  1564. inline void
  1565. RPC_SERVER::CallEnding (
  1566. )
  1567. /*++
  1568. Routine Description:
  1569. This method is the mirror image of RPC_SERVER::CallBeginning; it
  1570. is used to notify this rpc server that a call using an rpc
  1571. interface owned by this rpc server is ending.
  1572. --*/
  1573. {
  1574. long Temp;
  1575. Temp = AvailableCallCount.Increment();
  1576. ASSERT(Temp <= (long)MaximumConcurrentCalls);
  1577. }
  1578. inline void RPC_SERVER::IncomingCall (void)
  1579. /*++
  1580. Routine Description:
  1581. RPC_INTERFACE::DispatchToStub calls this method so that the server
  1582. can keep track of the number of incoming remote procedure calls (and
  1583. callbacks).
  1584. --*/
  1585. {
  1586. IncomingRpcCount += 1;
  1587. }
  1588. inline void RPC_SERVER::OutgoingCallback (void)
  1589. /*++
  1590. Routine Description:
  1591. Each protocol module must call this method when it sends a callback
  1592. from the server to the client; we need to do this so that the server
  1593. can keep track of the number of outgoing remote procedure callbacks.
  1594. --*/
  1595. {
  1596. OutgoingRpcCount += 1;
  1597. }
  1598. inline void RPC_SERVER::PacketReceived (void)
  1599. /*++
  1600. Routine Description:
  1601. In order for the server to keep track of the number of incoming
  1602. packets, each protocol module must call this method each time a
  1603. packet is received from the network.
  1604. --*/
  1605. {
  1606. ReceivedPacketCount += 1;
  1607. }
  1608. inline void RPC_SERVER::PacketSent (void)
  1609. /*++
  1610. Routine Description:
  1611. This method is the same as RPC_SERVER::PacketReceived, except that
  1612. it should be called for each packet sent rather than received.
  1613. --*/
  1614. {
  1615. SentPacketCount += 1;
  1616. }
  1617. inline CACHED_THREAD *RPC_SERVER::RemoveHeadFromFreeList(void)
  1618. /*++
  1619. Routine Description:
  1620. Removes a cached thread object for the ThreadCache list.
  1621. Note: ThreadCachedMutex() should be held when called.
  1622. --*/
  1623. {
  1624. CACHED_THREAD *pFirst = ThreadCache;
  1625. #if DBG
  1626. ThreadCacheMutex.VerifyOwned();
  1627. #endif
  1628. if (pFirst)
  1629. {
  1630. ThreadCache = pFirst->Next;
  1631. if (ThreadCache)
  1632. ThreadCache->Previous = NULL;
  1633. }
  1634. return pFirst;
  1635. }
  1636. inline void
  1637. RPC_SERVER::RemoveFromFreeList(
  1638. IN CACHED_THREAD *CachedThread)
  1639. /*++
  1640. Routine Description:
  1641. Removes a cached thread object for the ThreadCache list.
  1642. Note: ThreadCachedMutex() should be held when called.
  1643. --*/
  1644. {
  1645. if (CachedThread->Previous)
  1646. {
  1647. ASSERT(CachedThread->Previous->Next == CachedThread);
  1648. CachedThread->Previous->Next = CachedThread->Next;
  1649. }
  1650. if (CachedThread->Next)
  1651. {
  1652. ASSERT(CachedThread->Next->Previous == CachedThread);
  1653. CachedThread->Next->Previous = CachedThread->Previous;
  1654. }
  1655. if (ThreadCache == CachedThread)
  1656. {
  1657. ASSERT(CachedThread->Previous == NULL);
  1658. ASSERT( (CachedThread->Next == 0)
  1659. || (CachedThread->Next->Previous == NULL));
  1660. ThreadCache = CachedThread->Next;
  1661. }
  1662. }
  1663. inline void
  1664. RPC_SERVER::InsertIntoFreeList(
  1665. IN CACHED_THREAD *CachedThread
  1666. )
  1667. /*++
  1668. Routine Description:
  1669. Inserts a cached thread object into ThreadCache list.
  1670. Note: ThreadCachedMutex() should be held when called.
  1671. --*/
  1672. {
  1673. CachedThread->Next = ThreadCache;
  1674. if (ThreadCache)
  1675. {
  1676. ASSERT(ThreadCache->Previous == 0);
  1677. ThreadCache->Previous = CachedThread;
  1678. }
  1679. CachedThread->Previous = 0;
  1680. ThreadCache = CachedThread;
  1681. }
  1682. NEW_SDICT(ServerContextHandle);
  1683. class NO_VTABLE SCALL : public CALL
  1684. /*++
  1685. Class Description:
  1686. --*/
  1687. {
  1688. public:
  1689. inline
  1690. SCALL (
  1691. IN CLIENT_AUTH_INFO * myAuthInfo,
  1692. OUT RPC_STATUS * pStatus
  1693. )
  1694. {
  1695. }
  1696. inline SCALL (
  1697. void
  1698. )
  1699. {
  1700. IsMultiContextHandleCall = FALSE;
  1701. }
  1702. inline
  1703. ~SCALL (
  1704. )
  1705. {
  1706. }
  1707. virtual RPC_STATUS
  1708. NegotiateTransferSyntax (
  1709. IN OUT PRPC_MESSAGE Message
  1710. )
  1711. {
  1712. // we shouldn't be here at all
  1713. ASSERT(!"Negotiating a transfer syntax is not supported on the server side");
  1714. return RPC_S_CANNOT_SUPPORT;
  1715. }
  1716. RPC_STATUS
  1717. AddToActiveContextHandles (
  1718. IN ServerContextHandle *ContextHandle
  1719. );
  1720. ServerContextHandle *
  1721. RemoveFromActiveContextHandles (
  1722. IN ServerContextHandle *ContextHandle
  1723. );
  1724. void
  1725. DoPreDispatchProcessing (
  1726. IN PRPC_MESSAGE Message,
  1727. IN BOOL CallbackFlag
  1728. ) ;
  1729. void
  1730. DoPostDispatchProcessing (
  1731. void
  1732. ) ;
  1733. virtual void
  1734. InquireObjectUuid (
  1735. OUT RPC_UUID PAPI * ObjectUuid
  1736. ) = 0;
  1737. virtual RPC_STATUS
  1738. InquireAuthClient (
  1739. OUT RPC_AUTHZ_HANDLE PAPI * Privileges,
  1740. OUT RPC_CHAR PAPI * PAPI * ServerPrincipalName, OPTIONAL
  1741. OUT unsigned long PAPI * AuthenticationLevel,
  1742. OUT unsigned long PAPI * AuthenticationService,
  1743. OUT unsigned long PAPI * AuthorizationService,
  1744. IN unsigned long Flags
  1745. ) = 0;
  1746. virtual RPC_STATUS
  1747. InquireCallAttributes (
  1748. IN OUT void *
  1749. )
  1750. {
  1751. return RPC_S_CANNOT_SUPPORT;
  1752. }
  1753. virtual RPC_STATUS // Value to be returned by RpcImpersonateClient.
  1754. ImpersonateClient ( // Impersonate the client represented (at the other
  1755. );// end of) by this connection.
  1756. virtual RPC_STATUS // Value to be returned by RpcRevertToSelf.
  1757. RevertToSelf ( // Stop impersonating a client, if the server thread
  1758. );// is impersonating a client.
  1759. virtual RPC_STATUS
  1760. GetAssociationContextCollection (
  1761. OUT ContextCollection **CtxCollection
  1762. ) = 0;
  1763. virtual RPC_STATUS
  1764. ToStringBinding (
  1765. OUT RPC_CHAR PAPI * PAPI * StringBinding
  1766. ) = 0;
  1767. virtual RPC_STATUS
  1768. IsClientLocal (
  1769. OUT unsigned int PAPI * ClientLocalFlag
  1770. ) = 0;
  1771. virtual void
  1772. IsClientDisconnected (
  1773. OUT BOOL *ClientIsDisconnected
  1774. ) = 0;
  1775. virtual RPC_STATUS
  1776. ConvertToServerBinding (
  1777. OUT RPC_BINDING_HANDLE __RPC_FAR * ServerBinding
  1778. ) = 0;
  1779. virtual RPC_STATUS
  1780. InqTransportType (
  1781. OUT unsigned int __RPC_FAR * Type
  1782. ) = 0;
  1783. virtual RPC_STATUS
  1784. InqConnection (
  1785. OUT void **ConnId,
  1786. OUT BOOL *pfFirstCall
  1787. ) = 0;
  1788. #if DBG
  1789. virtual void
  1790. InterfaceForCallDoesNotUseStrict (
  1791. void
  1792. )
  1793. {
  1794. }
  1795. #endif
  1796. virtual RPC_STATUS
  1797. GetAuthorizationContext (
  1798. IN BOOL ImpersonateOnReturn,
  1799. IN AUTHZ_RESOURCE_MANAGER_HANDLE AuthzResourceManager,
  1800. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  1801. IN LUID Identifier,
  1802. IN DWORD Flags,
  1803. IN PVOID DynamicGroupArgs OPTIONAL,
  1804. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext
  1805. )
  1806. {
  1807. // we shouldn't be here at all
  1808. ASSERT(!"Get authz context should have landed in a derived class method");
  1809. return RPC_S_CANNOT_SUPPORT;
  1810. }
  1811. virtual RPC_STATUS
  1812. TurnOnOffKeepAlives (
  1813. IN BOOL TurnOn,
  1814. IN ULONG Timeout,
  1815. IN ULONG Interval
  1816. )
  1817. {
  1818. // we shouldn't be here at all
  1819. ASSERT(!"TurnOnOffKeepAlives called in an unsupporting class.");
  1820. return RPC_S_CANNOT_SUPPORT;
  1821. }
  1822. protected:
  1823. static RPC_STATUS
  1824. CreateAndSaveAuthzContextFromToken (
  1825. IN OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContextPlaceholder OPTIONAL,
  1826. IN HANDLE ImpersonationToken,
  1827. IN AUTHZ_RESOURCE_MANAGER_HANDLE AuthzResourceManager,
  1828. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  1829. IN LUID Identifier,
  1830. IN DWORD Flags,
  1831. IN PVOID DynamicGroupArgs OPTIONAL,
  1832. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext
  1833. );
  1834. static RPC_STATUS
  1835. DuplicateAuthzContext (
  1836. IN AUTHZ_CLIENT_CONTEXT_HANDLE AuthzClientContext,
  1837. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  1838. IN LUID Identifier,
  1839. IN DWORD Flags,
  1840. IN PVOID DynamicGroupArgs OPTIONAL,
  1841. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext
  1842. );
  1843. void __RPC_FAR * DispatchBuffer ;
  1844. // This flag is set to indicate that this call
  1845. // is using more than one [in] or [in,out] context
  1846. // handles. It is set when AddToActiveContextHandles is
  1847. // called for the second handle in the call.
  1848. BOOL IsMultiContextHandleCall;
  1849. public:
  1850. static const int DictionaryEntryIsBuffer = 1;
  1851. ServerContextHandle_DICT ActiveContextHandles;
  1852. };
  1853. inline void
  1854. SCALL::DoPreDispatchProcessing (
  1855. IN PRPC_MESSAGE Message,
  1856. IN BOOL CallbackFlag
  1857. )
  1858. {
  1859. if (CallbackFlag == 0)
  1860. {
  1861. ASSERT(ActiveContextHandles.Size() == 0);
  1862. }
  1863. DispatchBuffer = Message->Buffer ;
  1864. }
  1865. class NO_VTABLE SCONNECTION : public REFERENCED_OBJECT
  1866. /*++
  1867. Class Description:
  1868. This class represents a call on the server side. The name of the
  1869. class, SCONNECTION, is slightly misleading; this is a historical
  1870. artifact due to the connection oriented protocol module being
  1871. implemented first. We add some more methods to this class to
  1872. be implemented by each protocol module.
  1873. --*/
  1874. {
  1875. public:
  1876. inline
  1877. SCONNECTION(
  1878. )
  1879. {
  1880. }
  1881. inline
  1882. ~SCONNECTION(
  1883. )
  1884. {
  1885. }
  1886. virtual RPC_STATUS
  1887. IsClientLocal (
  1888. OUT unsigned int PAPI * ClientLocalFlag
  1889. );
  1890. virtual RPC_STATUS
  1891. InqTransportType(
  1892. OUT unsigned int __RPC_FAR * Type
  1893. ) = 0;
  1894. };
  1895. /* ====================================================================
  1896. ASSOCIATION_HANDLE :
  1897. An association represents a client. We need to take care of the
  1898. rundown routines here as well as the association context and
  1899. association id. This is all independent of RPC protocol and
  1900. transport (well except for datagrams).
  1901. ====================================================================
  1902. */
  1903. class NO_VTABLE ASSOCIATION_HANDLE : public REFERENCED_OBJECT
  1904. {
  1905. protected:
  1906. unsigned long AssociationID;
  1907. ASSOCIATION_HANDLE ( // Constructor.
  1908. void
  1909. );
  1910. public:
  1911. ContextCollection *CtxCollection;
  1912. virtual ~ASSOCIATION_HANDLE ( // Destructor.
  1913. );
  1914. // Returns the context handle collection for this association.
  1915. RPC_STATUS
  1916. GetAssociationContextCollection (
  1917. ContextCollection **CtxCollectionPlaceholder
  1918. ) ;
  1919. void
  1920. FireRundown (
  1921. void
  1922. );
  1923. virtual RPC_STATUS
  1924. CreateThread (
  1925. void
  1926. );
  1927. virtual void
  1928. RundownNotificationCompleted(
  1929. void
  1930. );
  1931. void
  1932. DestroyContextHandlesForInterface (
  1933. IN RPC_SERVER_INTERFACE PAPI * RpcInterfaceInformation,
  1934. IN BOOL RundownContextHandles
  1935. );
  1936. };
  1937. extern int
  1938. InitializeServerDLL ( // This routine will be called at DLL load time.
  1939. );
  1940. extern int
  1941. InitializeRpcServer (
  1942. );
  1943. extern void PAPI *
  1944. OsfServerMapRpcProtocolSequence (
  1945. IN RPC_CHAR * RpcProtocolSequence,
  1946. OUT RPC_STATUS PAPI * Status
  1947. );
  1948. extern int
  1949. InitializeRpcProtocolLrpc (
  1950. ) ;
  1951. extern RPC_ADDRESS *
  1952. LrpcCreateRpcAddress (
  1953. ) ;
  1954. extern RPC_ADDRESS *
  1955. OsfCreateRpcAddress (
  1956. IN TRANS_INFO PAPI * TransportInfo
  1957. );
  1958. extern RPC_ADDRESS *
  1959. DgCreateRpcAddress (
  1960. IN TRANS_INFO PAPI * TransportInfo
  1961. );
  1962. RPC_STATUS
  1963. SetThreadSecurityContext(
  1964. SECURITY_CONTEXT * Context
  1965. );
  1966. SECURITY_CONTEXT *
  1967. QueryThreadSecurityContext(
  1968. );
  1969. SECURITY_CONTEXT *
  1970. ClearThreadSecurityContext(
  1971. );
  1972. typedef AUTHZAPI
  1973. BOOL
  1974. (WINAPI *AuthzInitializeContextFromTokenFnType)(
  1975. IN DWORD Flags,
  1976. IN HANDLE TokenHandle,
  1977. IN AUTHZ_RESOURCE_MANAGER_HANDLE AuthzResourceManager,
  1978. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  1979. IN LUID Identifier,
  1980. IN PVOID DynamicGroupArgs OPTIONAL,
  1981. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext
  1982. );
  1983. typedef AUTHZAPI
  1984. BOOL
  1985. (WINAPI *AuthzInitializeContextFromSidFnType)(
  1986. IN DWORD Flags,
  1987. IN PSID UserSid,
  1988. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager,
  1989. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  1990. IN LUID Identifier,
  1991. IN PVOID DynamicGroupArgs OPTIONAL,
  1992. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phAuthzClientContext
  1993. );
  1994. typedef AUTHZAPI
  1995. BOOL
  1996. (WINAPI *AuthzInitializeContextFromAuthzContextFnType)(
  1997. IN DWORD Flags OPTIONAL,
  1998. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  1999. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  2000. IN LUID Identifier OPTIONAL,
  2001. IN PVOID DynamicGroupArgs OPTIONAL,
  2002. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phNewAuthzClientContext
  2003. );
  2004. typedef AUTHZAPI
  2005. BOOL
  2006. (WINAPI *AuthzFreeContextFnType)(
  2007. IN OUT AUTHZ_CLIENT_CONTEXT_HANDLE AuthzClientContext
  2008. );
  2009. extern AuthzInitializeContextFromTokenFnType AuthzInitializeContextFromTokenFn;
  2010. extern AuthzInitializeContextFromSidFnType AuthzInitializeContextFromSidFn;
  2011. extern AuthzInitializeContextFromAuthzContextFnType AuthzInitializeContextFromAuthzContextFn;
  2012. extern AuthzFreeContextFnType AuthzFreeContextFn;
  2013. #define MO(_Message) ((MESSAGE_OBJECT *) _Message->Handle)
  2014. #define SCALL(_Message) ((SCALL *) _Message->Handle)
  2015. RPC_STATUS
  2016. InqLocalConnAddress (
  2017. IN SCALL *SCall,
  2018. IN OUT void *Buffer,
  2019. IN OUT unsigned long *BufferSize,
  2020. OUT unsigned long *AddressFormat
  2021. );
  2022. typedef struct tagDestroyContextHandleCallbackContext
  2023. {
  2024. RPC_SERVER_INTERFACE *RpcInterfaceInformation;
  2025. BOOL RundownContextHandles;
  2026. } DestroyContextHandleCallbackContext;
  2027. #endif // __HNDLSVR_HXX__