ReactOS  0.4.11-dev-946-g431643b
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_ LPCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
 
NTSTATUS NTAPI RpcpStartRpcServer (_In_ LPCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
 

Variables

LONG RpcpNumInstances
 
CRITICAL_SECTION RpcpCriticalSection
 

Function Documentation

◆ RpcpAddInterface()

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

Definition at line 83 of file rpcsrv.c.

Referenced by RpcpStartRpcServer().

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 }
#define DbgPrint
Definition: loader.c:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
long RPC_STATUS
Definition: rpc.h:52
smooth NULL
Definition: ftsmooth.c:416
#define RPC_S_DUPLICATE_ENDPOINT
Definition: winerror.h:1048
RPC_STATUS WINAPI RpcServerRegisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, RPC_MGR_EPV *MgrEpv)
Definition: rpc_server.c:1123
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
RPC_STATUS WINAPI RpcServerUseProtseqEpW(RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor)
Definition: rpc_server.c:934
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define RPC_C_PROTSEQ_MAX_REQS_DEFAULT
Definition: rpcdce.h:123
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RPC_S_OK
Definition: rpcnterr.h:22
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

◆ RpcpInitRpcServer()

NTSTATUS NTAPI RpcpInitRpcServer ( VOID  )

Definition at line 22 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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

◆ RpcpStartRpcServer()

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

Definition at line 131 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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
NTSTATUS NTAPI RpcpAddInterface(_In_ LPCWSTR IfName, _In_ RPC_IF_HANDLE IfSpec)
Definition: rpcsrv.c:83
LONG NTSTATUS
Definition: precomp.h:26
LONG RpcpNumInstances
Definition: rpcsrv.c:15
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1527
#define RPC_S_ALREADY_LISTENING
Definition: winerror.h:1024
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
return STATUS_SUCCESS
Definition: btrfs.c:2710
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

◆ RpcpStopRpcServer()

NTSTATUS NTAPI RpcpStopRpcServer ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 33 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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 }
#define TRUE
Definition: types.h:120
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1599
LONG RpcpNumInstances
Definition: rpcsrv.c:15
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
RPC_STATUS WINAPI RpcServerUnregisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, UINT WaitForCallsToComplete)
Definition: rpc_server.c:1209
long RPC_STATUS
Definition: rpc.h:52
smooth NULL
Definition: ftsmooth.c:416
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
RPC_STATUS WINAPI RpcMgmtWaitServerListen(void)
Definition: rpc_server.c:1546
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

◆ RpcpStopRpcServerEx()

NTSTATUS NTAPI RpcpStopRpcServerEx ( _In_ RPC_IF_HANDLE  IfSpec)

Definition at line 58 of file rpcsrv.c.

Referenced by SvchostBuildSharedGlobals().

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 }
#define TRUE
Definition: types.h:120
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1599
LONG RpcpNumInstances
Definition: rpcsrv.c:15
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
long RPC_STATUS
Definition: rpc.h:52
RPC_STATUS WINAPI RpcServerUnregisterIfEx(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, int RundownContextHandles)
Definition: rpc_server.c:1260
smooth NULL
Definition: ftsmooth.c:416
CRITICAL_SECTION RpcpCriticalSection
Definition: rpcsrv.c:16
RPC_STATUS WINAPI RpcMgmtWaitServerListen(void)
Definition: rpc_server.c:1546
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:741

Variable Documentation

◆ RpcpCriticalSection

CRITICAL_SECTION RpcpCriticalSection

Definition at line 16 of file rpcsrv.c.

◆ RpcpNumInstances

LONG RpcpNumInstances