Forward RegisterEventSourceW and DeregisterEventSource to eventlog service
[reactos.git] / reactos / dll / win32 / advapi32 / service / eventlog.c
1 /*
2 * Win32 advapi functions
3 *
4 * Copyright 1995 Sven Verdoolaege
5 * Copyright 1998 Juergen Schmied
6 * Copyright 2003 Mike Hearn
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include <advapi32.h>
24 #define NDEBUG
25 #include <debug.h>
26
27
28 /******************************************************************************
29 * BackupEventLogA [ADVAPI32.@]
30 */
31 BOOL WINAPI
32 BackupEventLogA (HANDLE hEventLog,
33 LPCSTR lpBackupFileName)
34 {
35 DPRINT1("stub\n");
36 return TRUE;
37 }
38
39 /******************************************************************************
40 * BackupEventLogW [ADVAPI32.@]
41 *
42 * PARAMS
43 * hEventLog []
44 * lpBackupFileName []
45 */
46 BOOL WINAPI
47 BackupEventLogW (HANDLE hEventLog,
48 LPCWSTR lpBackupFileName)
49 {
50 DPRINT1("stub\n");
51 return TRUE;
52 }
53
54
55 /******************************************************************************
56 * ClearEventLogA [ADVAPI32.@]
57 */
58 BOOL WINAPI
59 ClearEventLogA (HANDLE hEventLog,
60 LPCSTR lpBackupFileName)
61 {
62 DPRINT1("stub\n");
63 return TRUE;
64 }
65
66
67 /******************************************************************************
68 * ClearEventLogW [ADVAPI32.@]
69 */
70 BOOL WINAPI
71 ClearEventLogW (HANDLE hEventLog,
72 LPCWSTR lpBackupFileName)
73 {
74 DPRINT1("stub\n");
75 return TRUE;
76 }
77
78
79 /******************************************************************************
80 * CloseEventLog [ADVAPI32.@]
81 */
82 BOOL WINAPI
83 CloseEventLog (HANDLE hEventLog)
84 {
85 DPRINT1("stub\n");
86 return TRUE;
87 }
88
89
90 /******************************************************************************
91 * DeregisterEventSource [ADVAPI32.@]
92 * Closes a handle to the specified event log
93 *
94 * PARAMS
95 * hEventLog [I] Handle to event log
96 *
97 * RETURNS STD
98 */
99 BOOL WINAPI
100 DeregisterEventSource(
101 IN HANDLE hEventLog)
102 {
103 RPC_BINDING_HANDLE BindingHandle = NULL;
104 LOGHANDLE Handle = (LOGHANDLE)hEventLog;
105 NTSTATUS Status;
106
107 DPRINT("%p\n", hEventLog);
108
109 if (!EvtGetLocalHandle(&BindingHandle))
110 {
111 SetLastError(ERROR_GEN_FAILURE);
112 return FALSE;
113 }
114
115 Status = ElfrDeregisterEventSource(
116 BindingHandle,
117 &Handle);
118 if (!NT_SUCCESS(Status))
119 {
120 SetLastError(RtlNtStatusToDosError(Status));
121 return FALSE;
122 }
123 return TRUE;
124 }
125
126
127 /******************************************************************************
128 * GetNumberOfEventLogRecords [ADVAPI32.@]
129 *
130 * PARAMS
131 * hEventLog []
132 * NumberOfRecords []
133 */
134 BOOL WINAPI
135 GetNumberOfEventLogRecords (HANDLE hEventLog,
136 PDWORD NumberOfRecords)
137 {
138 DPRINT1("stub\n");
139 return TRUE;
140 }
141
142
143 /******************************************************************************
144 * GetOldestEventLogRecord [ADVAPI32.@]
145 *
146 * PARAMS
147 * hEventLog []
148 * OldestRecord []
149 */
150 BOOL WINAPI
151 GetOldestEventLogRecord (HANDLE hEventLog,
152 PDWORD OldestRecord)
153 {
154 DPRINT1("stub\n");
155 return TRUE;
156 }
157
158
159 /******************************************************************************
160 * NotifyChangeEventLog [ADVAPI32.@]
161 *
162 * PARAMS
163 * hEventLog []
164 * hEvent []
165 */
166 BOOL WINAPI
167 NotifyChangeEventLog (HANDLE hEventLog,
168 HANDLE hEvent)
169 {
170 DPRINT1("stub\n");
171 return TRUE;
172 }
173
174
175 /******************************************************************************
176 * OpenBackupEventLogA [ADVAPI32.@]
177 */
178 HANDLE WINAPI
179 OpenBackupEventLogA (LPCSTR lpUNCServerName,
180 LPCSTR lpFileName)
181 {
182 DPRINT1("stub\n");
183 return (HANDLE)1;
184 }
185
186
187 /******************************************************************************
188 * OpenBackupEventLogW [ADVAPI32.@]
189 *
190 * PARAMS
191 * lpUNCServerName []
192 * lpFileName []
193 */
194 HANDLE WINAPI
195 OpenBackupEventLogW (LPCWSTR lpUNCServerName,
196 LPCWSTR lpFileName)
197 {
198 DPRINT1("stub\n");
199 return (HANDLE)1;
200 }
201
202
203 /******************************************************************************
204 * OpenEventLogA [ADVAPI32.@]
205 */
206 HANDLE WINAPI
207 OpenEventLogA (LPCSTR lpUNCServerName,
208 LPCSTR lpSourceName)
209 {
210 DPRINT1("(%s,%s),stub!\n",
211 lpUNCServerName, lpSourceName);
212 return (HANDLE)0xcafe4242;
213 }
214
215
216 /******************************************************************************
217 * OpenEventLogW [ADVAPI32.@]
218 *
219 * PARAMS
220 * uncname []
221 * source []
222 */
223 HANDLE WINAPI
224 OpenEventLogW (LPCWSTR lpUNCServerName,
225 LPCWSTR lpSourceName)
226 {
227 DPRINT1("stub\n");
228 return (HANDLE)1;
229 }
230
231
232 /******************************************************************************
233 * ReadEventLogA [ADVAPI32.@]
234 */
235 BOOL WINAPI
236 ReadEventLogA (HANDLE hEventLog,
237 DWORD dwReadFlags,
238 DWORD dwRecordOffset,
239 LPVOID lpBuffer,
240 DWORD nNumberOfBytesToRead,
241 DWORD *pnBytesRead,
242 DWORD *pnMinNumberOfBytesNeeded)
243 {
244 DPRINT1("stub\n");
245 return TRUE;
246 }
247
248
249 /******************************************************************************
250 * ReadEventLogW [ADVAPI32.@]
251 *
252 * PARAMS
253 * hEventLog []
254 * dwReadFlags []
255 * dwRecordOffset []
256 * lpBuffer []
257 * nNumberOfBytesToRead []
258 * pnBytesRead []
259 * pnMinNumberOfBytesNeeded []
260 */
261 BOOL WINAPI
262 ReadEventLogW (HANDLE hEventLog,
263 DWORD dwReadFlags,
264 DWORD dwRecordOffset,
265 LPVOID lpBuffer,
266 DWORD nNumberOfBytesToRead,
267 DWORD *pnBytesRead,
268 DWORD *pnMinNumberOfBytesNeeded)
269 {
270 DPRINT1("stub\n");
271 return TRUE;
272 }
273
274
275 /******************************************************************************
276 * RegisterEventSourceA [ADVAPI32.@]
277 */
278 HANDLE WINAPI
279 RegisterEventSourceA (LPCSTR lpUNCServerName,
280 LPCSTR lpSourceName)
281 {
282 UNICODE_STRING UNCServerName;
283 UNICODE_STRING SourceName;
284 HANDLE ret;
285
286 RtlCreateUnicodeStringFromAsciiz (&UNCServerName,
287 (PSTR)lpUNCServerName);
288 RtlCreateUnicodeStringFromAsciiz (&SourceName,
289 (PSTR)lpSourceName);
290
291 ret = RegisterEventSourceW (UNCServerName.Buffer,
292 SourceName.Buffer);
293
294 RtlFreeUnicodeString (&UNCServerName);
295 RtlFreeUnicodeString (&SourceName);
296
297 return ret;
298 }
299
300
301 /******************************************************************************
302 * RegisterEventSourceW [ADVAPI32.@]
303 * Returns a registered handle to an event log
304 *
305 * PARAMS
306 * lpUNCServerName [I] Server name for source
307 * lpSourceName [I] Source name for registered handle
308 *
309 * RETURNS
310 * Success: Handle
311 * Failure: NULL
312 */
313 HANDLE WINAPI
314 RegisterEventSourceW(
315 IN LPCWSTR lpUNCServerName,
316 IN LPCWSTR lpSourceName)
317 {
318 RPC_BINDING_HANDLE BindingHandle = NULL;
319 LOGHANDLE Handle;
320 NTSTATUS Status;
321
322 DPRINT("%S, %S\n", lpUNCServerName, lpSourceName);
323
324 if (lpUNCServerName != NULL)
325 {
326 DPRINT1("lpUNCServerName argument not supported\n");
327 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
328 return NULL;
329 }
330
331 if (!EvtGetLocalHandle(&BindingHandle))
332 {
333 SetLastError(ERROR_GEN_FAILURE);
334 return NULL;
335 }
336
337 Status = ElfrRegisterEventSourceW(
338 BindingHandle,
339 (LPWSTR)lpUNCServerName,
340 (LPWSTR)lpSourceName,
341 L"",
342 0,
343 0,
344 &Handle);
345 if (!NT_SUCCESS(Status))
346 {
347 SetLastError(RtlNtStatusToDosError(Status));
348 return NULL;
349 }
350
351 return (HANDLE)Handle;
352 }
353
354
355 /******************************************************************************
356 * ReportEventA [ADVAPI32.@]
357 */
358 BOOL WINAPI
359 ReportEventA (HANDLE hEventLog,
360 WORD wType,
361 WORD wCategory,
362 DWORD dwEventID,
363 PSID lpUserSid,
364 WORD wNumStrings,
365 DWORD dwDataSize,
366 LPCSTR *lpStrings,
367 LPVOID lpRawData)
368 {
369 LPCWSTR *wideStrArray;
370 UNICODE_STRING str;
371 int i;
372 BOOL ret;
373
374 if (wNumStrings == 0)
375 return TRUE;
376
377 if (lpStrings == NULL)
378 return TRUE;
379
380 wideStrArray = HeapAlloc (GetProcessHeap (),
381 0,
382 sizeof(LPCWSTR) * wNumStrings);
383
384 for (i = 0; i < wNumStrings; i++)
385 {
386 RtlCreateUnicodeStringFromAsciiz (&str,
387 (PSTR)lpStrings[i]);
388 wideStrArray[i] = str.Buffer;
389 }
390
391 ret = ReportEventW (hEventLog,
392 wType,
393 wCategory,
394 dwEventID,
395 lpUserSid,
396 wNumStrings,
397 dwDataSize,
398 wideStrArray,
399 lpRawData);
400
401 for (i = 0; i < wNumStrings; i++)
402 {
403 if (wideStrArray[i])
404 {
405 HeapFree (GetProcessHeap (),
406 0,
407 (LPSTR)wideStrArray[i]);
408 }
409 }
410
411 HeapFree (GetProcessHeap(),
412 0,
413 wideStrArray);
414
415 return ret;
416 }
417
418
419 /******************************************************************************
420 * ReportEventW [ADVAPI32.@]
421 *
422 * PARAMS
423 * hEventLog []
424 * wType []
425 * wCategory []
426 * dwEventID []
427 * lpUserSid []
428 * wNumStrings []
429 * dwDataSize []
430 * lpStrings []
431 * lpRawData []
432 */
433 BOOL WINAPI
434 ReportEventW (HANDLE hEventLog,
435 WORD wType,
436 WORD wCategory,
437 DWORD dwEventID,
438 PSID lpUserSid,
439 WORD wNumStrings,
440 DWORD dwDataSize,
441 LPCWSTR *lpStrings,
442 LPVOID lpRawData)
443 {
444 int i;
445
446 /* partial stub */
447
448 if (wNumStrings == 0)
449 return TRUE;
450
451 if (lpStrings == NULL)
452 return TRUE;
453
454 for (i = 0; i < wNumStrings; i++)
455 {
456 switch (wType)
457 {
458 case EVENTLOG_SUCCESS:
459 DPRINT1("Success: %S\n", lpStrings[i]);
460 break;
461
462 case EVENTLOG_ERROR_TYPE:
463 DPRINT1("Error: %S\n", lpStrings[i]);
464 break;
465
466 case EVENTLOG_WARNING_TYPE:
467 DPRINT1("Warning: %S\n", lpStrings[i]);
468 break;
469
470 case EVENTLOG_INFORMATION_TYPE:
471 DPRINT1("Info: %S\n", lpStrings[i]);
472 break;
473
474 default:
475 DPRINT1("Type %hu: %S\n", wType, lpStrings[i]);
476 break;
477 }
478 }
479
480 return TRUE;
481 }