[SHELL32]
[reactos.git] / deprecated / csr.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Interface to csrss
5 * FILE: subsys/win32k/ntuser/csr.c
6 * PROGRAMER: Ge van Geldorp (ge@gse.nl)
7 */
8
9 #include <win32k.h>
10
11 static HANDLE WindowsApiPort = NULL;
12 PEPROCESS CsrProcess = NULL;
13
14 NTSTATUS FASTCALL
15 CsrInit(void)
16 {
17 NTSTATUS Status;
18 UNICODE_STRING PortName;
19 ULONG ConnectInfoLength;
20 SECURITY_QUALITY_OF_SERVICE Qos;
21
22 RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
23 ConnectInfoLength = 0;
24 Qos.Length = sizeof(Qos);
25 Qos.ImpersonationLevel = SecurityDelegation;
26 Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
27 Qos.EffectiveOnly = FALSE;
28
29 Status = ZwConnectPort(&WindowsApiPort,
30 &PortName,
31 &Qos,
32 NULL,
33 NULL,
34 NULL,
35 NULL,
36 &ConnectInfoLength);
37 if (! NT_SUCCESS(Status))
38 {
39 return Status;
40 }
41
42 CsrProcess = PsGetCurrentProcess();
43
44 return STATUS_SUCCESS;
45 }
46
47
48 NTSTATUS FASTCALL
49 co_CsrNotify(PCSR_API_MESSAGE Request)
50 {
51 NTSTATUS Status;
52 PEPROCESS OldProcess;
53
54 if (NULL == CsrProcess)
55 {
56 return STATUS_INVALID_PORT_HANDLE;
57 }
58
59 Request->Header.u2.ZeroInit = 0;
60 Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
61 Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
62
63 /* Switch to the process in which the WindowsApiPort handle is valid */
64 OldProcess = PsGetCurrentProcess();
65 if (CsrProcess != OldProcess)
66 {
67 KeAttachProcess(&CsrProcess->Pcb);
68 }
69
70 UserLeaveCo();
71
72 Status = ZwRequestWaitReplyPort(WindowsApiPort,
73 &Request->Header,
74 &Request->Header);
75
76 UserEnterCo();
77
78 if (CsrProcess != OldProcess)
79 {
80 KeDetachProcess();
81 }
82
83 if (NT_SUCCESS(Status))
84 {
85 Status = Request->Status;
86 }
87
88 return Status;
89 }
90
91 /* EOF */