ReactOS 0.4.15-dev-8191-gbc6c731
rpcsrv.c File Reference
#include "svchost.h"
Include dependency graph for rpcsrv.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI RpcpInitRpcServer (VOID)
 
NTSTATUS NTAPI RpcpStopRpcServer (_In_ RPC_IF_HANDLE IfSpec)
 
NTSTATUS NTAPI RpcpStopRpcServerEx (_In_ RPC_IF_HANDLE IfSpec)
 
NTSTATUS NTAPI RpcpAddInterface (_In_ PCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
 
NTSTATUS NTAPI RpcpStartRpcServer (_In_ PCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
 

Variables

LONG RpcpNumInstances
 
CRITICAL_SECTION RpcpCriticalSection
 

Function Documentation

◆ RpcpAddInterface()

NTSTATUS NTAPI RpcpAddInterface ( _In_ PCWSTR  IfName,
_In_ RPC_IF_HANDLE  IfSpec 
)

Definition at line 83 of file rpcsrv.c.

87{
88 PWCHAR endpointName;
89 NTSTATUS ntStatus;
90 RPC_STATUS rpcStatus;
91
92 /* Allocate space for the interface name and the \\PIPE\\ prefix */
93 endpointName = LocalAlloc(0, sizeof(WCHAR) * wcslen(IfName) + 16);
94 if (endpointName)
95 {
96 /* Copy the prefix, and then the interface name */
97 wcscpy(endpointName, L"\\PIPE\\");
98 wcscat(endpointName, IfName);
99
100 /* Create a named pipe endpoint with this name */
101 rpcStatus = RpcServerUseProtseqEpW(L"ncacn_np",
103 endpointName, NULL);
104 if ((rpcStatus != RPC_S_OK) && (rpcStatus != RPC_S_DUPLICATE_ENDPOINT))
105 {
106 /* We couldn't create it, or it already existed... */
107 DbgPrint("RpcServerUseProtseqW failed! rpcstatus = %u\n", rpcStatus);
108 }
109 else
110 {
111 /* It worked, register an interface on this endpoint now */
112 rpcStatus = RpcServerRegisterIf(IfSpec, 0, 0);
113 }
114
115 /* In both success and failure, free the name, and convert the status */
116 LocalFree(endpointName);
117 ntStatus = I_RpcMapWin32Status(rpcStatus);
118 }
119 else
120 {
121 /* No memory, bail out */
122 ntStatus = STATUS_NO_MEMORY;
123 }
124
125 /* Return back to the caller */
126 return ntStatus;
127}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define DbgPrint
Definition: hal.h:12
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
RPC_STATUS WINAPI RpcServerRegisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, RPC_MGR_EPV *MgrEpv)
Definition: rpc_server.c:1116
RPC_STATUS WINAPI RpcServerUseProtseqEpW(RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor)
Definition: rpc_server.c:927
#define RPC_C_PROTSEQ_MAX_REQS_DEFAULT
Definition: rpcdce.h:123
#define RPC_S_OK
Definition: rpcnterr.h:22
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:740
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
long RPC_STATUS
Definition: rpc.h:52
uint16_t * PWCHAR
Definition: typedefs.h:56
#define RPC_S_DUPLICATE_ENDPOINT
Definition: winerror.h:1048
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by RpcpStartRpcServer().

◆ RpcpInitRpcServer()

NTSTATUS NTAPI RpcpInitRpcServer ( VOID  )

Definition at line 22 of file rpcsrv.c.

25{
26 /* Clear the reference count and initialize the critical section */
29}
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
LONG RpcpNumInstances
Definition: rpcsrv.c:15

Referenced by SvchostBuildSharedGlobals().

◆ RpcpStartRpcServer()

NTSTATUS NTAPI RpcpStartRpcServer ( _In_ PCWSTR  IfName,
_In_ RPC_IF_HANDLE  IfSpec 
)

Definition at line 131 of file rpcsrv.c.

135{
136 NTSTATUS ntStatus;
137
138 /* Acquire the lock while we instantiate a new interface */
140
141 /* Add this interface to the service */
142 ntStatus = RpcpAddInterface(IfName, IfSpec);
143 if (!ntStatus)
144 {
145 /* Increment the reference count to see if this was the first interface */
146 if (++RpcpNumInstances == 1)
147 {
148 /* It was, so put the server into listening mode now */
149 ntStatus = RpcServerListen(1, 12345, TRUE);
150 if (ntStatus == RPC_S_ALREADY_LISTENING) ntStatus = STATUS_SUCCESS;
151 }
152 }
153
154 /* Release the lock and return back the result to the caller */
156 return I_RpcMapWin32Status(ntStatus);
157}
#define TRUE
Definition: types.h:120
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1520
NTSTATUS NTAPI RpcpAddInterface(_In_ PCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:83
#define STATUS_SUCCESS
Definition: shellext.h:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define RPC_S_ALREADY_LISTENING
Definition: winerror.h:1024

Referenced by SvchostBuildSharedGlobals().

◆ RpcpStopRpcServer()

NTSTATUS NTAPI RpcpStopRpcServer ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 33 of file rpcsrv.c.

36{
37 RPC_STATUS rpcStatus;
38
39 /* Unregister the interface */
40 rpcStatus = RpcServerUnregisterIf(IfSpec, NULL, TRUE);
41
42 /* Acquire the lock while we dereference the RPC services */
44 if (--RpcpNumInstances == 0)
45 {
46 /* All RPC services stopped, rundown the server */
49 }
50
51 /* Release the lock and return the unregister result */
53 return I_RpcMapWin32Status(rpcStatus);
54}
RPC_STATUS WINAPI RpcMgmtWaitServerListen(void)
Definition: rpc_server.c:1539
RPC_STATUS WINAPI RpcServerUnregisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, UINT WaitForCallsToComplete)
Definition: rpc_server.c:1202
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596

Referenced by SvchostBuildSharedGlobals().

◆ RpcpStopRpcServerEx()

NTSTATUS NTAPI RpcpStopRpcServerEx ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 58 of file rpcsrv.c.

61{
62 RPC_STATUS rpcStatus;
63
64 /* Unregister the interface */
65 rpcStatus = RpcServerUnregisterIfEx(IfSpec, NULL, TRUE);
66
67 /* Acquire the lock while we dereference the RPC services */
69 if (--RpcpNumInstances == 0)
70 {
71 /* All RPC services stopped, rundown the server */
74 }
75
76 /* Release the lock and return the unregister result */
78 return I_RpcMapWin32Status(rpcStatus);
79}
RPC_STATUS WINAPI RpcServerUnregisterIfEx(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, int RundownContextHandles)
Definition: rpc_server.c:1253

Referenced by SvchostBuildSharedGlobals().

Variable Documentation

◆ RpcpCriticalSection

CRITICAL_SECTION RpcpCriticalSection

◆ RpcpNumInstances

LONG RpcpNumInstances