1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*++
Copyright (c) 1995 Microsoft Corporation
Module Name:
LOGALERT.C
Abstract:
This file contains the routine to log a Cairo alert in the system log.
Author:
Ravi Rudrappa (ravir) 18-Jan-1995
Revision History:
18-Jan-1995 RaviR
Created
--*/
#ifdef _CAIRO_
#include <elfclntp.h>
NTSTATUS
ElfLogCairoAlertInSystemLog(
IN HANDLE hLogHandle,
IN LARGE_INTEGER liEventTime,
IN USHORT usEventType,
IN USHORT usEventCategory,
IN ULONG ulEventID,
IN USHORT usNumStrings,
IN ULONG ulDataSize,
IN WCHAR *pwszComputerName,
IN WCHAR **ppwszStrings,
IN PBYTE pbData
)
/*++
Routine Description:
This routine logs the given Cairo Alert in the given log, through the
ElfrReportEventW function.
Arguments:
Return Value:
Returns an NTSTATUS code.
Note:
--*/
{
NTSTATUS s = STATUS_SUCCESS;
ULONG ulEventTime;
PRPC_SID psidUser = NULL;
USHORT usFlags;
PUNICODE_STRING pusComputerName = NULL;
PUNICODE_STRING *ppusStrings = NULL;
ULONG i;
ULONG ulNumofAllocatedStrings = 0;
LPBYTE pbString = NULL;
//
// parameter validation
//
if ((hLogHandle == NULL) ||
(pwszComputerName == NULL) ||
((usNumStrings > 0) && (ppwszStrings == NULL)) ||
((ulDataSize > 0) && (pbData == NULL)))
{
return STATUS_INVALID_PARAMETER;
}
//
// user Sid
//
psidUser = NULL; // BUGBUG: is this ok?
//
// Map creation time
//
RtlTimeToSecondsSince1970(&liEventTime, &ulEventTime);
//
// Convert the array of Alert description insert strings
// to an array of UNICODE_STRINGs.
//
if (usNumStrings > 0)
{
LPBYTE pbPtr;
//
// allocate memory in one shot.
//
pbPtr = pbString = MIDL_user_allocate(
sizeof(PUNICODE_STRING) * usNumStrings +
sizeof(UNICODE_STRING) * usNumStrings);
if (pbString == NULL)
{
s = STATUS_NO_MEMORY;
goto LCleanUp;
}
ppusStrings = (PUNICODE_STRING *)pbPtr;
pbPtr += sizeof(PUNICODE_STRING) * usNumStrings;
//
// For each string passed in, allocate a UNICODE_STRING structure
// and set it to the matching string.
//
for (i = 0; i < usNumStrings; i++)
{
ppusStrings[i] = (PUNICODE_STRING)pbPtr;
pbPtr += sizeof(UNICODE_STRING);
RtlInitUnicodeString(ppusStrings[i], ppwszStrings[i]);
}
}
//
// Map the ComputerName to UNICODE_STRING.
//
pusComputerName = MIDL_user_allocate(sizeof(UNICODE_STRING));
if (pusComputerName == NULL)
{
s = STATUS_NO_MEMORY;
goto LCleanUp;
}
RtlInitUnicodeString(pusComputerName, pwszComputerName);
//
// Do the RPC call with an exception handler since RPC will raise an
// exception if anything fails. It is up to us to figure out what
// to do once the exception is raised.
//
RpcTryExcept {
// Call service
s = ElfrReportEventW (
(IELF_HANDLE)hLogHandle,
ulEventTime,
usEventType,
usEventCategory,
ulEventID,
usNumStrings,
ulDataSize,
(PRPC_UNICODE_STRING)pusComputerName,
psidUser,
(PRPC_UNICODE_STRING *)ppusStrings,
pbData,
0, // Flags,
NULL, // RecordNumber,
NULL); // TimeWritten
}
RpcExcept (1) {
s = I_RpcMapWin32Status(RpcExceptionCode());
}
RpcEndExcept
LCleanUp:
//
// Free the space allocated for the inserts
// and then free the space for ComputerName.
//
if (pbString)
{
MIDL_user_free(pbString);
}
if (pusComputerName)
{
MIDL_user_free(pusComputerName);
}
return (s);
}
#endif // _CAIRO_
|