ReactOS 0.4.15-dev-7924-g5949c20
logport.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS EventLog Service
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/eventlog/logport.c
5 * PURPOSE: LPC Port Interface support
6 * COPYRIGHT: Copyright 2002 Eric Kohl
7 * Copyright 2005 Saveliy Tretiakov
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include "eventlog.h"
13#include <ndk/lpcfuncs.h>
14#include <iolog/iolog.h>
15
16#define NDEBUG
17#include <debug.h>
18
19/* GLOBALS ******************************************************************/
20
23extern BOOL onLiveCD;
24
25/* FUNCTIONS ****************************************************************/
26
28{
30
32 if (!NT_SUCCESS(Status))
33 return Status;
34
35 while (NT_SUCCESS(Status))
37
40
43
44 return Status;
45}
46
48{
53
56
58
61 0,
62 PORT_MAXIMUM_MESSAGE_LENGTH, // IO_ERROR_LOG_MESSAGE_LENGTH,
63 2 * PAGE_SIZE);
64 if (!NT_SUCCESS(Status))
65 {
66 DPRINT1("NtCreatePort() failed (Status %lx)\n", Status);
67 goto ByeBye;
68 }
69
71 if (!NT_SUCCESS(Status))
72 {
73 DPRINT1("NtListenPort() failed (Status %lx)\n", Status);
74 goto ByeBye;
75 }
76
78 &Request, TRUE, NULL, NULL);
79 if (!NT_SUCCESS(Status))
80 {
81 DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status);
82 goto ByeBye;
83 }
84
86 if (!NT_SUCCESS(Status))
87 {
88 DPRINT1("NtCompleteConnectPort() failed (Status %lx)\n", Status);
89 goto ByeBye;
90 }
91
92ByeBye:
93 if (!NT_SUCCESS(Status))
94 {
97
100 }
101 return Status;
102}
103
105{
107 PLOGFILE SystemLog = NULL;
108 UCHAR Buffer[PORT_MAXIMUM_MESSAGE_LENGTH]; // IO_ERROR_LOG_MESSAGE_LENGTH
111 PEVENTLOGRECORD LogBuffer;
112 SIZE_T RecSize;
113 ULONG Time;
115 UNICODE_STRING SourceName, ComputerName;
116 DWORD dwComputerNameLength;
117 WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
118
119 DPRINT("ProcessPortMessage() called\n");
120
121 SystemLog = LogfListItemByName(L"System");
122
123 while (TRUE)
124 {
126 NULL,
127 NULL,
128 &Message->Header);
129
130 if (!NT_SUCCESS(Status))
131 {
132 DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status);
133 break;
134 }
135
136 DPRINT("Received message\n");
137
138 if (Message->Header.u2.s2.Type == LPC_PORT_CLOSED)
139 {
140 DPRINT("Port closed\n");
141 return STATUS_SUCCESS;
142 }
143
144 if (Message->Header.u2.s2.Type == LPC_REQUEST)
145 {
146 DPRINT("Received request\n");
147 }
148 else if (Message->Header.u2.s2.Type == LPC_DATAGRAM)
149 {
150 DPRINT("Received datagram (0x%x, 0x%x)\n",
151 Message->Unknown[0], Message->Unknown[1]);
152 ErrorMessage = &Message->IoErrorMessage;
153
154 // ASSERT(ErrorMessage->Type == IO_TYPE_ERROR_MESSAGE);
155
156 RtlInitEmptyUnicodeString(&SourceName, NULL, 0);
157 if (ErrorMessage->DriverNameLength > sizeof(UNICODE_NULL)) // DriverNameLength counts NULL-terminator
158 {
159 SourceName.Buffer = (PWSTR)((ULONG_PTR)ErrorMessage + ErrorMessage->DriverNameOffset);
160 SourceName.MaximumLength = ErrorMessage->DriverNameLength;
161 SourceName.Length = SourceName.MaximumLength - sizeof(UNICODE_NULL);
162 }
163
164 dwComputerNameLength = ARRAYSIZE(szComputerName);
165 if (!GetComputerNameW(szComputerName, &dwComputerNameLength))
166 szComputerName[0] = L'\0';
167
168 RtlInitUnicodeString(&ComputerName, szComputerName);
169
171
172 /* Set the event type based on the error code severity */
173 EventType = (USHORT)(ErrorMessage->EntryData.ErrorCode >> 30);
175 {
177 }
178 else if (EventType == STATUS_SEVERITY_INFORMATIONAL) // NT_INFORMATION
179 {
181 }
182 else if (EventType == STATUS_SEVERITY_WARNING) // NT_WARNING
183 {
185 }
186 else if (EventType == STATUS_SEVERITY_ERROR) // NT_ERROR
187 {
189 }
190 else
191 {
192 /* Unknown severity, set to error */
194 }
195
196 /*
197 * The data being saved consists of the IO_ERROR_LOG_PACKET structure
198 * header, plus the additional raw data from the driver.
199 */
200 LogBuffer = LogfAllocAndBuildNewRecord(
201 &RecSize,
202 Time,
203 EventType,
204 ErrorMessage->EntryData.EventCategory,
205 ErrorMessage->EntryData.ErrorCode,
206 &SourceName,
207 &ComputerName,
208 0,
209 NULL,
210 ErrorMessage->EntryData.NumberOfStrings,
212 ErrorMessage->EntryData.StringOffset),
214 ErrorMessage->EntryData.DumpDataSize,
215 (PVOID)&ErrorMessage->EntryData);
216 if (LogBuffer == NULL)
217 {
218 DPRINT1("LogfAllocAndBuildNewRecord failed!\n");
219 // return STATUS_NO_MEMORY;
220 continue;
221 }
222
223 if (!onLiveCD && SystemLog)
224 {
225 Status = LogfWriteRecord(SystemLog, LogBuffer, RecSize);
226 if (!NT_SUCCESS(Status))
227 {
228 DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n",
229 SystemLog->LogName, Status);
230 }
231 }
232 else
233 {
234 DPRINT1("\n--- EVENTLOG RECORD ---\n");
235 PRINT_RECORD(LogBuffer);
236 DPRINT1("\n");
237 }
238
239 LogfFreeRecord(LogBuffer);
240 }
241 }
242
243 return Status;
244}
static UNICODE_STRING PortName
WCHAR SourceName[256]
Definition: arping.c:28
static VOID ErrorMessage(_In_ DWORD dwErrorCode, _In_opt_ PCWSTR pszMsg,...)
Definition: attrib.c:33
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
VOID PRINT_RECORD(PEVENTLOGRECORD pRec)
Definition: eventlog.c:544
Definition: bufpool.h:45
NTSTATUS NTAPI NtAcceptConnectPort(OUT PHANDLE PortHandle, IN PVOID PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage, IN BOOLEAN AcceptConnection, IN OUT PPORT_VIEW ServerView OPTIONAL, OUT PREMOTE_PORT_VIEW ClientView OPTIONAL)
Definition: complete.c:40
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:423
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static const WCHAR Message[]
Definition: register.c:74
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define STATUS_SEVERITY_WARNING
Definition: errmsg.h:58
#define STATUS_SEVERITY_ERROR
Definition: errmsg.h:61
#define STATUS_SEVERITY_INFORMATIONAL
Definition: errmsg.h:60
#define STATUS_SEVERITY_SUCCESS
Definition: errmsg.h:59
PLOGFILE LogfListItemByName(LPCWSTR Name)
Definition: file.c:33
NTSTATUS LogfWriteRecord(PLOGFILE LogFile, PEVENTLOGRECORD Record, SIZE_T BufSize)
Definition: file.c:858
PEVENTLOGRECORD LogfAllocAndBuildNewRecord(PSIZE_T pRecSize, ULONG Time, USHORT wType, USHORT wCategory, ULONG dwEventId, PUNICODE_STRING SourceName, PUNICODE_STRING ComputerName, ULONG dwSidLength, PSID pUserSid, USHORT wNumStrings, PWSTR pStrings, ULONG dwDataSize, PVOID pRawData)
Definition: file.c:896
static __inline void LogfFreeRecord(PEVENTLOGRECORD Record)
Definition: eventlog.h:143
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
struct _ELF_API_MSG * PELF_API_MSG
#define ELF_PORT_NAME
Definition: iolog.h:15
NTSTATUS ProcessPortMessage(VOID)
Definition: logport.c:104
BOOL onLiveCD
Definition: eventlog.c:33
static HANDLE ConnectPortHandle
Definition: logport.c:21
NTSTATUS InitLogPort(VOID)
Definition: logport.c:47
static HANDLE MessagePortHandle
Definition: logport.c:22
NTSTATUS WINAPI PortThreadRoutine(PVOID Param)
Definition: logport.c:27
#define LPC_REQUEST
Definition: port.c:93
#define LPC_DATAGRAM
Definition: port.c:95
#define LPC_PORT_CLOSED
Definition: port.c:97
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static PLARGE_INTEGER Time
Definition: time.c:105
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE EventType
Definition: exfuncs.h:167
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define UNICODE_NULL
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:222
NTSTATUS NTAPI NtListenPort(IN HANDLE PortHandle, OUT PPORT_MESSAGE ConnectMessage)
Definition: listen.c:22
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
WCHAR * LogName
Definition: eventlog.h:38
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PWSTR
Definition: typedefs.h:56
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243
#define WINAPI
Definition: msvc.h:6
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2834
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2836
#define EVENTLOG_SUCCESS
Definition: winnt_old.h:2833
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2835
#define PORT_MAXIMUM_MESSAGE_LENGTH
Definition: iotypes.h:2029
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180