ReactOS  0.4.14-dev-1233-gf5658fd
connect.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: reactos/lib/smlib/connect.c
5  * PURPOSE: Connect to the API LPC port exposed by the SM
6  */
7 
8 #include "precomp.h"
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 /**********************************************************************
14  * NAME EXPORTED
15  * SmConnectApiPort/4
16  *
17  * DESCRIPTION
18  * Connect to SM API port and register a session "begin" port (Sb)
19  * or to issue API requests to SmApiPort.
20  *
21  * ARGUMENTS
22  * pSbApiPortName: name of the Sb port the calling subsystem
23  * server already created in the system name space;
24  * hSbApiPort: LPC port handle (checked, but not used: the
25  * subsystem is required to have already created
26  * the callback port before it connects to the SM);
27  * wSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
28  * phSmApiPort: a pointer to a HANDLE, which will be
29  * filled with a valid client-side LPC comm port.
30  *
31  * There should be only two ways to call this API:
32  * a) subsystems willing to register with SM will use it
33  * with full parameters (the function checks them);
34  * b) regular SM clients, will set to 0 the 1st, the 2nd,
35  * and the 3rd parameter.
36  *
37  * RETURN VALUE
38  * If all three optional values are omitted, an LPC status.
39  * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
40  * both hSbApiPort and wSubsystem are 0.
41  */
45  IN WORD wSubSystemId OPTIONAL,
46  IN OUT PHANDLE phSmApiPort)
47 {
48  UNICODE_STRING SmApiPortName;
49  SECURITY_QUALITY_OF_SERVICE SecurityQos;
51  SM_CONNECT_DATA ConnectData = {0,0,{0}};
52  ULONG ConnectDataLength = 0;
53 
54  DPRINT("SMLIB: %s called\n", __FUNCTION__);
55 
56  if (pSbApiPortName)
57  {
58  if (pSbApiPortName->Length > (sizeof pSbApiPortName->Buffer[0] * SM_SB_NAME_MAX_LENGTH))
59  {
61  }
62  if (NULL == hSbApiPort || IMAGE_SUBSYSTEM_UNKNOWN == wSubSystemId)
63  {
65  }
66  RtlZeroMemory (& ConnectData, sizeof ConnectData);
67  ConnectData.Unused = 0;
68  ConnectData.SubSystemId = wSubSystemId;
69  if (pSbApiPortName->Length > 0)
70  {
71  RtlCopyMemory (& ConnectData.SbName,
72  pSbApiPortName->Buffer,
73  pSbApiPortName->Length);
74  }
75  }
76  ConnectDataLength = sizeof ConnectData;
77 
78  SecurityQos.Length = sizeof (SecurityQos);
81  SecurityQos.EffectiveOnly = TRUE;
82 
83  RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
84 
86  phSmApiPort,
87  & SmApiPortName,
88  & SecurityQos,
89  NULL,
90  NULL,
91  NULL,
92  & ConnectData,
93  & ConnectDataLength
94  );
95  if (NT_SUCCESS(Status))
96  {
97  return STATUS_SUCCESS;
98  }
99  DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
100  return Status;
101 }
102 
103 /* EOF */
NTSTATUS WINAPI SmConnectApiPort(IN PUNICODE_STRING pSbApiPortName OPTIONAL, IN HANDLE hSbApiPort OPTIONAL, IN WORD wSubSystemId OPTIONAL, IN OUT PHANDLE phSmApiPort)
Definition: connect.c:43
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
#define SM_SB_NAME_MAX_LENGTH
Definition: api.h:8
#define STATUS_INVALID_PARAMETER_MIX
Definition: ntstatus.h:271
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
WCHAR SbName[SM_SB_NAME_MAX_LENGTH]
Definition: api.h:17
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
USHORT SubSystemId
Definition: api.h:15
WORD Unused
Definition: api.h:16
NTSTATUS NTAPI NtConnectPort(OUT PHANDLE PortHandle, IN PUNICODE_STRING PortName, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos, IN OUT PPORT_VIEW ClientView OPTIONAL, IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL, OUT PULONG MaxMessageLength OPTIONAL, IN OUT PVOID ConnectionInformation OPTIONAL, IN OUT PULONG ConnectionInformationLength OPTIONAL)
Definition: connect.c:753
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
#define SM_API_PORT_NAME
Definition: ns.h:7
#define IMAGE_SUBSYSTEM_UNKNOWN
Definition: ntimage.h:435
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:461
Status
Definition: gdiplustypes.h:24
HANDLE hSbApiPort
Definition: init.c:32
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define __FUNCTION__
Definition: types.h:112
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68