3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: reactos/lib/smdll/connect.c
6 * PURPOSE: Connect to the API LPC port exposed by the SM
11 #include <sm/helper.h>
17 /**********************************************************************
22 * Connect to SM API port and register a session "begin" port (Sb)
23 * or to issue API requests to SmApiPort.
26 * pSbApiPortName: name of the Sb port the calling subsystem
27 * server already created in the system name space;
28 * hSbApiPort: LPC port handle (checked, but not used);
29 * dwSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
30 * phSmApiPort: a pointer to a HANDLE, which will be
31 * filled with a valid client-side LPC comm port.
34 * If all three optional values are omitted, an LPC status.
35 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
36 * both hSbApiPort and dwSubsystem are 0.
39 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL
,
40 IN HANDLE hSbApiPort OPTIONAL
,
41 IN DWORD dwSubsystem OPTIONAL
,
42 IN OUT PHANDLE phSmApiPort
)
44 UNICODE_STRING SmApiPortName
;
45 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
46 NTSTATUS Status
= STATUS_SUCCESS
;
47 SM_CONNECT_DATA ConnectData
= {0,{0}};
48 ULONG ConnectDataLength
= 0;
50 DPRINT("SMDLL: %s called\n", __FUNCTION__
);
54 if (pSbApiPortName
->Length
> (sizeof pSbApiPortName
->Buffer
[0] * SM_SB_NAME_MAX_LENGTH
))
56 return STATUS_INVALID_PARAMETER_1
;
58 if (NULL
== hSbApiPort
|| IMAGE_SUBSYSTEM_UNKNOWN
== dwSubsystem
)
60 return STATUS_INVALID_PARAMETER_MIX
;
62 RtlZeroMemory (& ConnectData
, sizeof ConnectData
);
63 ConnectData
.Subsystem
= dwSubsystem
;
64 if (pSbApiPortName
->Length
> 0)
66 RtlCopyMemory (& ConnectData
.SbName
,
67 pSbApiPortName
->Buffer
,
68 pSbApiPortName
->Length
);
71 ConnectDataLength
= sizeof ConnectData
;
73 SecurityQos
.Length
= sizeof (SecurityQos
);
74 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
75 SecurityQos
.ContextTrackingMode
= TRUE
;
76 SecurityQos
.EffectiveOnly
= TRUE
;
78 RtlInitUnicodeString (& SmApiPortName
, SM_API_PORT_NAME
);
80 Status
= NtConnectPort (
90 if (NT_SUCCESS(Status
))
92 return STATUS_SUCCESS
;
94 DPRINT("SMDLL: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);