- Go away STDCALL, time has come for WINAPI and NTAPI
[reactos.git] / reactos / lib / smlib / connect.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: reactos/lib/smlib/connect.c
6 * PURPOSE: Connect to the API LPC port exposed by the SM
7 */
8
9 #include "precomp.h"
10
11 #define NDEBUG
12 #include <debug.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: the
26 * subsystem is required to have already created
27 * the callback port before it connects to the SM);
28 * wSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
29 * phSmApiPort: a pointer to a HANDLE, which will be
30 * filled with a valid client-side LPC comm port.
31 *
32 * There should be only two ways to call this API:
33 * a) subsystems willing to register with SM will use it
34 * with full parameters (the function checks them);
35 * b) regular SM clients, will set to 0 the 1st, the 2nd,
36 * and the 3rd parameter.
37 *
38 * RETURN VALUE
39 * If all three optional values are omitted, an LPC status.
40 * STATUS_INVALID_PARAMETER_MIX if PortName is defined and
41 * both hSbApiPort and wSubsystem are 0.
42 */
43 NTSTATUS WINAPI
44 SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL,
45 IN HANDLE hSbApiPort OPTIONAL,
46 IN WORD wSubSystemId OPTIONAL,
47 IN OUT PHANDLE phSmApiPort)
48 {
49 UNICODE_STRING SmApiPortName;
50 SECURITY_QUALITY_OF_SERVICE SecurityQos;
51 NTSTATUS Status = STATUS_SUCCESS;
52 SM_CONNECT_DATA ConnectData = {0,0,{0}};
53 ULONG ConnectDataLength = 0;
54
55 DPRINT("SMLIB: %s called\n", __FUNCTION__);
56
57 if (pSbApiPortName)
58 {
59 if (pSbApiPortName->Length > (sizeof pSbApiPortName->Buffer[0] * SM_SB_NAME_MAX_LENGTH))
60 {
61 return STATUS_INVALID_PARAMETER_1;
62 }
63 if (NULL == hSbApiPort || IMAGE_SUBSYSTEM_UNKNOWN == wSubSystemId)
64 {
65 return STATUS_INVALID_PARAMETER_MIX;
66 }
67 RtlZeroMemory (& ConnectData, sizeof ConnectData);
68 ConnectData.Unused = 0;
69 ConnectData.SubSystemId = wSubSystemId;
70 if (pSbApiPortName->Length > 0)
71 {
72 RtlCopyMemory (& ConnectData.SbName,
73 pSbApiPortName->Buffer,
74 pSbApiPortName->Length);
75 }
76 }
77 ConnectDataLength = sizeof ConnectData;
78
79 SecurityQos.Length = sizeof (SecurityQos);
80 SecurityQos.ImpersonationLevel = SecurityIdentification;
81 SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
82 SecurityQos.EffectiveOnly = TRUE;
83
84 RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
85
86 Status = NtConnectPort (
87 phSmApiPort,
88 & SmApiPortName,
89 & SecurityQos,
90 NULL,
91 NULL,
92 NULL,
93 & ConnectData,
94 & ConnectDataLength
95 );
96 if (NT_SUCCESS(Status))
97 {
98 return STATUS_SUCCESS;
99 }
100 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
101 return Status;
102 }
103
104 /* EOF */