summaryrefslogtreecommitdiffstats
path: root/private/nw/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'private/nw/rpc')
-rw-r--r--private/nw/rpc/client.c184
-rw-r--r--private/nw/rpc/makefile6
-rw-r--r--private/nw/rpc/midluser.c211
-rw-r--r--private/nw/rpc/server.c362
-rw-r--r--private/nw/rpc/sources41
5 files changed, 804 insertions, 0 deletions
diff --git a/private/nw/rpc/client.c b/private/nw/rpc/client.c
new file mode 100644
index 000000000..56dcfbfe1
--- /dev/null
+++ b/private/nw/rpc/client.c
@@ -0,0 +1,184 @@
+/*++
+
+Copyright (c) 1990-93 Microsoft Corporation
+
+Module Name:
+
+ client.c
+
+Abstract:
+
+ This file contains commonly used client-side RPC control functions.
+
+Author:
+
+ Dan Lafferty danl 06-Feb-1991
+
+Environment:
+
+ User Mode - Win32
+
+Revision History:
+
+ 06-Feb-1991 danl
+ Created
+ 26-Apr-1991 JohnRo
+ Split out MIDL user (allocate,free) so linker doesn't get confused.
+ Deleted tabs.
+ 03-July-1991 JimK
+ Copied from LM specific file.
+ 27-Feb-1992 JohnRo
+ Fixed heap trashing bug in RpcpBindRpc().
+
+ 10-Feb-1993 RitaW
+ Copied to the NetWare tree so that the LPC transport can used for
+ the local case.
+
+--*/
+
+#include <nt.h> // needed for NTSTATUS
+#include <ntrtl.h> // needed for nturtl.h
+#include <nturtl.h> // needed for windows.h
+#include <windows.h> // win32 typedefs
+#include <rpc.h> // rpc prototypes
+
+#include <stdlib.h> // for wcscpy wcscat
+#include <tstr.h> // WCSSIZE
+
+#include <nwrpcp.h>
+
+#define NT_PIPE_PREFIX TEXT("\\PIPE\\")
+#define NT_PIPE_PREFIX_W L"\\PIPE\\"
+
+
+
+RPC_STATUS
+RpcpBindRpc(
+#if 0
+ IN LPWSTR ServerName,
+#endif
+ IN LPWSTR ServiceName,
+ IN LPWSTR NetworkOptions,
+ OUT RPC_BINDING_HANDLE *pBindingHandle
+ )
+
+/*++
+
+Routine Description:
+
+ Binds to the RPC server if possible.
+
+Arguments:
+
+ ServerName - Name of server to bind with.
+
+ ServiceName - Name of service to bind with.
+
+ pBindingHandle - Location where binding handle is to be placed
+
+Return Value:
+
+ RPC_S_OK - The binding has been successfully completed.
+
+ RPC error, if failed.
+
+--*/
+
+{
+ RPC_STATUS RpcStatus;
+ LPWSTR StringBinding;
+
+#if 0
+ LPWSTR Endpoint;
+ WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
+ LPWSTR NewServerName = NULL;
+ DWORD bufLen = MAX_COMPUTERNAME_LENGTH + 1;
+
+
+ if (ServerName != NULL) {
+ if (GetComputerNameW(ComputerName,&bufLen)) {
+ if (_wcsicmp(ComputerName,&(ServerName[2]))==0) {
+ NewServerName = NULL;
+ }
+ else {
+ NewServerName = ServerName;
+ }
+ }
+ }
+
+ if ( NewServerName == NULL ) {
+#endif
+
+ RpcStatus = RpcStringBindingComposeW(0, L"ncalrpc", 0, ServiceName,
+ NetworkOptions, &StringBinding);
+
+#if 0
+ }
+ else {
+ // We need to concatenate \pipe\ to the front of the service
+ // name.
+
+ Endpoint = (LPWSTR)LocalAlloc(
+ 0,
+ sizeof(NT_PIPE_PREFIX_W) + WCSSIZE(ServiceName));
+ if (Endpoint == 0) {
+ return(STATUS_NO_MEMORY);
+ }
+ wcscpy(Endpoint,NT_PIPE_PREFIX_W);
+ wcscat(Endpoint,ServiceName);
+
+ RpcStatus = RpcStringBindingComposeW(0, L"ncacn_np", NewServerName,
+ Endpoint, NetworkOptions, &StringBinding);
+ LocalFree(Endpoint);
+ }
+#endif
+
+ if ( RpcStatus != RPC_S_OK ) {
+ KdPrint(("NWRPCUTIL: RpcStringBindingComposeW failed %ld\n", RpcStatus));
+ return RpcStatus;
+ }
+
+ RpcStatus = RpcBindingFromStringBindingW(StringBinding, pBindingHandle);
+
+ RpcStringFreeW(&StringBinding);
+
+ if ( RpcStatus != RPC_S_OK ) {
+ KdPrint(("NWRPCUTIL: RpcBindingFromStringBindingW failed %ld\n", RpcStatus));
+ return RpcStatus;
+ }
+
+ return RPC_S_OK;
+}
+
+
+VOID
+RpcpUnbindRpc(
+ IN RPC_BINDING_HANDLE BindingHandle
+ )
+
+/*++
+
+Routine Description:
+
+ Unbinds from the RPC interface.
+ If we decide to cache bindings, this routine will do something more
+ interesting.
+
+Arguments:
+
+ BindingHandle - This points to the binding handle that is to be closed.
+
+
+Return Value:
+
+ None.
+
+--*/
+{
+ RPC_STATUS RpcStatus;
+
+
+ RpcStatus = RpcBindingFree(&BindingHandle);
+
+ ASSERT(RpcStatus == RPC_S_OK);
+}
diff --git a/private/nw/rpc/makefile b/private/nw/rpc/makefile
new file mode 100644
index 000000000..6ee4f43fa
--- /dev/null
+++ b/private/nw/rpc/makefile
@@ -0,0 +1,6 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the components of NT OS/2
+#
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/private/nw/rpc/midluser.c b/private/nw/rpc/midluser.c
new file mode 100644
index 000000000..8d6e53206
--- /dev/null
+++ b/private/nw/rpc/midluser.c
@@ -0,0 +1,211 @@
+/*++
+
+Copyright (c) 1990-1993 Microsoft Corporation
+
+Module Name:
+
+ MidlUser.c
+
+Abstract:
+
+ This file contains common functions and utilities that the API
+ DLLs can use in making remote calls. This includes the
+ MIDL_USER_ALLOCATE functions.
+
+Author:
+
+ Dan Lafferty danl 06-Feb-1991
+
+Environment:
+
+ User Mode - Win32
+
+Revision History:
+
+ 06-Feb-1991 danl
+ Created
+ 25-Apr-1991 JohnRo
+ Split out MIDL user (allocate,free) into seperate source file, so
+ linker doesn't get confused.
+ 03-July-1991 JimK
+ Moved to a common directory so services available to more than just
+ LM code.
+ 03-Dec-1991 JohnRo
+ Added MIDL_user_reallocate and MIDL_user_size APIs. (These are so we
+ create the NetApiBufferAllocate, NetApiBufferReallocate, and
+ NetApiBufferSize APIs.)
+ Also check alignment of allocated data.
+
+ 10-Feb-1993 RitaW
+ Copied to the NetWare tree so that the LPC transport can used for
+ the local case.
+
+--*/
+
+#include <nt.h>
+#include <ntrtl.h> // needed for nturtl.h
+#include <nturtl.h> // needed for windows.h
+#include <windows.h> // win32 typedefs
+#include <rpc.h> // rpc prototypes
+
+#include <align.h> // POINTER_IS_ALIGNED(), ALIGN_WORST.
+#include <winbase.h> // LocalAlloc
+
+#include <nwrpcp.h> // MIDL_user_allocate(), MIDL_user_free().
+
+
+PVOID
+MIDL_user_allocate (
+ IN unsigned int NumBytes
+ )
+
+/*++
+
+Routine Description:
+
+ Allocates storage for RPC transactions. The RPC stubs will either call
+ MIDL_user_allocate when it needs to un-marshall data into a buffer
+ that the user must free. RPC servers will use MIDL_user_allocate to
+ allocate storage that the RPC server stub will free after marshalling
+ the data.
+
+Arguments:
+
+ NumBytes - The number of bytes to allocate.
+
+Return Value:
+
+ none
+
+Note:
+
+
+--*/
+
+{
+ LPVOID NewPointer;
+
+ NewPointer = (LPVOID) LocalAlloc(
+ LMEM_ZEROINIT,
+ NumBytes
+ );
+
+ ASSERT( POINTER_IS_ALIGNED( NewPointer, ALIGN_WORST) );
+
+ return (NewPointer);
+
+} // MIDL_user_allocate
+
+
+
+VOID
+MIDL_user_free (
+ IN void *MemPointer
+ )
+
+/*++
+
+Routine Description:
+
+ Frees storage used in RPC transactions. The RPC client can call this
+ function to free buffer space that was allocated by the RPC client
+ stub when un-marshalling data that is to be returned to the client.
+ The Client calls MIDL_user_free when it is finished with the data and
+ desires to free up the storage.
+ The RPC server stub calls MIDL_user_free when it has completed
+ marshalling server data that is to be passed back to the client.
+
+Arguments:
+
+ MemPointer - This points to the memory block that is to be released.
+
+Return Value:
+
+ none.
+
+Note:
+
+
+--*/
+{
+ ASSERT( POINTER_IS_ALIGNED( MemPointer, ALIGN_WORST) );
+ (void) LocalFree((HLOCAL) MemPointer);
+
+} // MIDL_user_free
+
+void *
+MIDL_user_reallocate(
+ IN void * OldPointer OPTIONAL,
+ IN unsigned long NewByteCount
+ )
+{
+ LPVOID NewPointer; // may be NULL.
+
+
+ ASSERT( POINTER_IS_ALIGNED( OldPointer, ALIGN_WORST) );
+
+
+ // Special cases: something into nothing, or nothing into something.
+ if (OldPointer == NULL) {
+
+ NewPointer = (LPVOID) LocalAlloc(
+ LMEM_ZEROINIT,
+ NewByteCount
+ );
+
+ } else if (NewByteCount == 0) {
+
+ (void) LocalFree((HLOCAL) OldPointer );
+ NewPointer = NULL;
+
+ } else { // must be realloc of something to something else.
+
+ HANDLE hOldMem;
+ HANDLE hNewMem; // handle for new (may = old handle)
+
+ hOldMem = LocalHandle( (LPSTR) OldPointer);
+ ASSERT(hOldMem != NULL);
+
+ hNewMem = (PVOID) LocalReAlloc(
+ hOldMem, // old handle
+ NewByteCount, // new size in bytes
+ LMEM_ZEROINIT | // flags
+ LMEM_MOVEABLE // (motion okay)
+ );
+
+ if (hNewMem == NULL) {
+ return (NULL);
+ }
+
+ NewPointer = (LPVOID) hNewMem;
+
+ } // must be realloc of something to something else
+
+ ASSERT( POINTER_IS_ALIGNED( NewPointer, ALIGN_WORST) );
+
+ return (NewPointer);
+
+} // MIDL_user_reallocate
+
+
+unsigned long
+MIDL_user_size(
+ IN void * Pointer
+ )
+{
+ DWORD ByteCount;
+ HANDLE hMemory;
+
+ ASSERT( Pointer != NULL );
+ ASSERT( POINTER_IS_ALIGNED( Pointer, ALIGN_WORST ) );
+
+ hMemory = LocalHandle( (LPSTR) Pointer );
+ ASSERT( hMemory != NULL );
+
+ ByteCount = LocalSize( hMemory );
+
+ ASSERT( ByteCount > 0 );
+
+ return (ByteCount);
+
+} // MIDL_user_size
diff --git a/private/nw/rpc/server.c b/private/nw/rpc/server.c
new file mode 100644
index 000000000..f9825d3ef
--- /dev/null
+++ b/private/nw/rpc/server.c
@@ -0,0 +1,362 @@
+/*++
+
+Copyright (c) 1990-1993 Microsoft Corporation
+
+Module Name:
+
+ server.c
+
+Abstract:
+
+ This file contains commonly used server-side RPC functions,
+ such as starting and stoping RPC servers.
+
+Author:
+
+ Dan Lafferty danl 09-May-1991
+
+Environment:
+
+ User Mode - Win32
+
+Revision History:
+
+ 09-May-1991 Danl
+ Created
+
+ 03-July-1991 JimK
+ Copied from a net-specific file.
+
+ 18-Feb-1992 Danl
+ Added support for multiple endpoints & interfaces per server.
+
+ 10-Feb-1993 RitaW
+ Copied to the NetWare tree so that the LPC transport can used for
+ the local case.
+
+--*/
+
+//
+// INCLUDES
+//
+
+#include <nt.h> // DbgPrint
+#include <ntrtl.h> // DbgPrint
+#include <windef.h> // win32 typedefs
+#include <rpc.h> // rpc prototypes
+#include <nturtl.h> // needed for winbase.h
+#include <winbase.h> // LocalAlloc
+
+#include <stdlib.h> // for wcscpy wcscat
+#include <tstr.h> // WCSSIZE
+
+#include <nwrpcp.h>
+
+
+#define NT_PIPE_PREFIX_W L"\\PIPE\\"
+
+//
+// GLOBALS
+//
+
+static CRITICAL_SECTION RpcpCriticalSection;
+static DWORD RpcpNumInstances;
+
+
+
+VOID
+RpcpInitRpcServer(
+ VOID
+ )
+
+/*++
+
+Routine Description:
+
+ This function initializes the critical section used to protect the
+ global server handle and instance count.
+
+Arguments:
+
+ none
+
+Return Value:
+
+ none
+
+--*/
+{
+ InitializeCriticalSection(&RpcpCriticalSection);
+ RpcpNumInstances = 0;
+}
+
+
+RPC_STATUS
+RpcpAddInterface(
+ IN LPWSTR InterfaceName,
+ IN RPC_IF_HANDLE InterfaceSpecification
+ )
+
+/*++
+
+Routine Description:
+
+ Starts an RPC Server, adds the address (or port/pipe), and adds the
+ interface (dispatch table).
+
+Arguments:
+
+ InterfaceName - points to the name of the interface.
+
+ InterfaceSpecification - Supplies the interface handle for the
+ interface which we wish to add.
+
+Return Value:
+
+ RPC_S_OK - Indicates the server was successfully started.
+
+ Other - Status values that may be returned by:
+
+ RpcServerRegisterIf()
+ RpcServerUseProtseqEp()
+
+ , or any RPC error codes, or any windows error codes that
+ can be returned by LocalAlloc.
+
+--*/
+{
+ RPC_STATUS RpcStatus;
+ LPWSTR Endpoint = NULL;
+
+ PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
+ BOOL Bool;
+
+
+#if 0
+ // We need to concatenate \pipe\ to the front of the interface name.
+
+ Endpoint = LocalAlloc(0, sizeof(NT_PIPE_PREFIX_W) + WCSSIZE(InterfaceName));
+ if (Endpoint == 0) {
+ return(STATUS_NO_MEMORY);
+ }
+ wcscpy(Endpoint, NT_PIPE_PREFIX_W );
+ wcscat(Endpoint,InterfaceName);
+#endif
+
+ //
+ // Croft up a security descriptor that will grant everyone
+ // all access to the object (basically, no security)
+ //
+ // We do this by putting in a NULL Dacl.
+ //
+ // BUGBUG: rpc should copy the security descriptor,
+ // Since it currently doesn't, simply allocate it for now and
+ // leave it around forever.
+ //
+
+ SecurityDescriptor = (PVOID) LocalAlloc(LMEM_FIXED, sizeof( SECURITY_DESCRIPTOR));
+ if (SecurityDescriptor == 0) {
+ RpcStatus = RPC_S_OUT_OF_MEMORY;
+ goto CleanExit;
+ }
+
+ InitializeSecurityDescriptor( SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION );
+
+ Bool = SetSecurityDescriptorDacl (
+ SecurityDescriptor,
+ TRUE, // Dacl present
+ NULL, // NULL Dacl
+ FALSE // Not defaulted
+ );
+
+ //
+ // There's no way the above call can fail. But check anyway.
+ //
+ ASSERT( Bool );
+
+#if 0
+ // Ignore the second argument for now.
+
+ RpcStatus = RpcServerUseProtseqEpW(L"ncacn_np", 10, Endpoint, SecurityDescriptor);
+
+ // If RpcpStartRpcServer and then RpcpStopRpcServer have already
+ // been called, the endpoint will have already been added but not
+ // removed (because there is no way to do it). If the endpoint is
+ // already there, it is ok.
+
+ if ( (RpcStatus != RPC_S_OK)
+ && (RpcStatus != RPC_S_DUPLICATE_ENDPOINT)) {
+
+ KdPrint(("RpcServerUseProtseqW failed! rpcstatus = %u\n",RpcStatus));
+ goto CleanExit;
+ }
+#endif // #if 0
+
+
+ RpcStatus = RpcServerUseProtseqEpW(L"ncalrpc", 10, InterfaceName, SecurityDescriptor);
+
+ // If RpcpStartRpcServer and then RpcpStopRpcServer have already
+ // been called, the endpoint will have already been added but not
+ // removed (because there is no way to do it). If the endpoint is
+ // already there, it is ok.
+
+ if ((RpcStatus != RPC_S_OK)
+ && (RpcStatus != RPC_S_DUPLICATE_ENDPOINT)) {
+
+ KdPrint(("RpcServerUseProtseqW failed! rpcstatus = %u\n",RpcStatus));
+ goto CleanExit;
+ }
+
+ RpcStatus = RpcServerRegisterIf(InterfaceSpecification, 0, 0);
+
+CleanExit:
+ if ( Endpoint != NULL ) {
+ LocalFree(Endpoint);
+ }
+
+ return RpcStatus;
+}
+
+
+RPC_STATUS
+RpcpStartRpcServer(
+ IN LPWSTR InterfaceName,
+ IN RPC_IF_HANDLE InterfaceSpecification
+ )
+
+/*++
+
+Routine Description:
+
+ Starts an RPC Server, adds the address (or port/pipe), and adds the
+ interface (dispatch table).
+
+Arguments:
+
+ InterfaceName - points to the name of the interface.
+
+ InterfaceSpecification - Supplies the interface handle for the
+ interface which we wish to add.
+
+Return Value:
+
+ RPC_S_OK - Indicates the server was successfully started.
+
+ Other - Status values that may be returned by:
+
+ RpcServerRegisterIf()
+ RpcServerUseProtseqEp()
+
+ , or any RPC error codes, or any windows error codes that
+ can be returned by LocalAlloc.
+
+--*/
+{
+ RPC_STATUS RpcStatus;
+
+ EnterCriticalSection(&RpcpCriticalSection);
+
+ RpcStatus = RpcpAddInterface( InterfaceName,
+ InterfaceSpecification );
+
+ if ( RpcStatus != RPC_S_OK ) {
+ LeaveCriticalSection(&RpcpCriticalSection);
+ return RpcStatus;
+ }
+
+ RpcpNumInstances++;
+
+ if (RpcpNumInstances == 1) {
+
+
+ // The first argument specifies the minimum number of threads to
+ // be created to handle calls; the second argument specifies the
+ // maximum number of concurrent calls allowed. The last argument
+ // indicates not to wait.
+
+ RpcStatus = RpcServerListen(1,12345, 1);
+ if ( RpcStatus == RPC_S_ALREADY_LISTENING ) {
+ RpcStatus = RPC_S_OK;
+ }
+ }
+
+ LeaveCriticalSection(&RpcpCriticalSection);
+ return RpcStatus;
+}
+
+
+RPC_STATUS
+RpcpDeleteInterface(
+ IN RPC_IF_HANDLE InterfaceSpecification
+ )
+
+/*++
+
+Routine Description:
+
+ Deletes the interface. This is likely
+ to be caused by an invalid handle. If an attempt to add the same
+ interface or address again, then an error will be generated at that
+ time.
+
+Arguments:
+
+ InterfaceSpecification - A handle for the interface that is to be removed.
+
+Return Value:
+
+ RPC_S_OK, or any RPC error codes that can be returned from
+ RpcServerUnregisterIf.
+
+--*/
+{
+ RPC_STATUS RpcStatus;
+
+
+ RpcStatus = RpcServerUnregisterIf(InterfaceSpecification, 0, 1);
+
+ return RpcStatus;
+}
+
+
+RPC_STATUS
+RpcpStopRpcServer(
+ IN RPC_IF_HANDLE InterfaceSpecification
+ )
+
+/*++
+
+Routine Description:
+
+ Deletes the interface. This is likely
+ to be caused by an invalid handle. If an attempt to add the same
+ interface or address again, then an error will be generated at that
+ time.
+
+Arguments:
+
+ InterfaceSpecification - A handle for the interface that is to be removed.
+
+Return Value:
+
+ RPC_S_OK, or any RPC error codes that can be returned from
+ RpcServerUnregisterIf.
+
+--*/
+{
+ RPC_STATUS RpcStatus;
+
+
+ RpcStatus = RpcServerUnregisterIf(InterfaceSpecification, 0, 1);
+ EnterCriticalSection(&RpcpCriticalSection);
+
+ RpcpNumInstances--;
+ if (RpcpNumInstances == 0) {
+ RpcMgmtStopServerListening(0);
+ RpcMgmtWaitServerListen();
+ }
+
+ LeaveCriticalSection(&RpcpCriticalSection);
+
+ return RpcStatus;
+}
diff --git a/private/nw/rpc/sources b/private/nw/rpc/sources
new file mode 100644
index 000000000..8fcc5555f
--- /dev/null
+++ b/private/nw/rpc/sources
@@ -0,0 +1,41 @@
+!IF 0
+
+Copyright (c) 1989 Microsoft Corporation
+
+Module Name:
+
+ sources.
+
+Abstract:
+
+ This file specifies the target component being built and the list of
+ sources files needed to build that component. Also specifies optional
+ compiler switches and libraries that are unique for the component being
+ built.
+
+
+Author:
+
+ Jim Kelly (JimK) 3-July-1991
+
+NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
+
+!ENDIF
+
+MAJORCOMP=nw
+MINORCOMP=rpc
+
+TARGETNAME=nwrpc
+TARGETPATH=obj
+TARGETTYPE=LIBRARY
+
+INCLUDES=..\inc;$(_NTROOT)\private\inc
+
+SOURCES=midluser.c \
+ client.c \
+ server.c
+
+NET_C_DEFINES=-DRPC_NO_WINDOWS_H
+UMTYPE=nt
+UMTEST=
+OPTIONAL_UMTEST=