SMDLL: helper to use the SM
[reactos.git] / reactos / lib / smdll / connect.c
1 /* $Id$
2 *
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
7 */
8 #define NTOS_MODE_USER
9 #include <ntos.h>
10 #include <sm/api.h>
11 #include <sm/helper.h>
12 #include <pe.h>
13
14 /**********************************************************************
15 * NAME EXPORTED
16 * SmConnectApiPort/4
17 *
18 * DESCRIPTION
19 * Connect to SM API port and register a session "begin" port (Sb)
20 * or to issue API requests to SmApiPort.
21 *
22 * ARGUMENTS
23 * pSbApiPortName: name of the Sb port the calling subsystem
24 * server already created in the system name space;
25 * hSbApiPort: LPC port handle (checked, but not used);
26 * dwSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
27 * phSmApiPort: a pointer to a HANDLE, which will be
28 * filled with a valid client-side LPC comm port.
29 *
30 * RETURN VALUE
31 * If all three optional values are omitted, an LPC status.
32 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
33 * both hSbApiPort and dwSubsystem are 0.
34 */
35 NTSTATUS STDCALL
36 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL,
37 IN HANDLE hSbApiPort OPTIONAL,
38 IN DWORD dwSubsystem OPTIONAL,
39 IN OUT PHANDLE phSmApiPort)
40 {
41 UNICODE_STRING SmApiPortName;
42 SECURITY_QUALITY_OF_SERVICE SecurityQos;
43 NTSTATUS Status = STATUS_SUCCESS;
44 SM_CONNECT_DATA ConnectData = {0,{0}};
45 ULONG ConnectDataLength = 0;
46
47 if (pSbApiPortName)
48 {
49 if (NULL == hSbApiPort || IMAGE_SUBSYSTEM_UNKNOWN == dwSubsystem)
50 {
51 return STATUS_INVALID_PARAMETER_MIX;
52 }
53 ConnectData.Subsystem = dwSubsystem;
54 memmove (& ConnectData.SbName, pSbApiPortName->Buffer, pSbApiPortName->Length);
55 }
56 ConnectDataLength = sizeof (ConnectData);
57
58 SecurityQos.Length = sizeof (SecurityQos);
59 SecurityQos.ImpersonationLevel = SecurityIdentification;
60 SecurityQos.ContextTrackingMode = TRUE;
61 SecurityQos.EffectiveOnly = TRUE;
62
63 RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
64
65 Status = NtConnectPort (
66 phSmApiPort,
67 & SmApiPortName,
68 & SecurityQos,
69 NULL,
70 NULL,
71 NULL,
72 & ConnectData,
73 & ConnectDataLength
74 );
75 if (NT_SUCCESS(Status))
76 {
77 return STATUS_SUCCESS;
78 }
79 DbgPrint ("%s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
80 return Status;
81 }
82
83 /* EOF */