Pretend there are 0 log records.
[wine/dcerpc.git] / dlls / advapi32 / eventlog.c
blobd559d6b190aa905f83aec7ea66957febb8c1e579
1 /*
2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
5 * Copyright 1998 Juergen Schmied
6 * Copyright 2003 Mike Hearn
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.
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.
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
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
29 #include "winternl.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
34 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
36 /******************************************************************************
37 * BackupEventLogA [ADVAPI32.@]
39 * Saves the event log to a backup file.
41 * PARAMS
42 * hEventLog [I] Handle to event log to backup.
43 * lpBackupFileName [I] Name of the backup file.
45 * RETURNS
46 * Success: nonzero. File lpBackupFileName will contain the contents of
47 * hEvenLog.
48 * Failure: zero.
50 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
52 FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
53 return TRUE;
56 /******************************************************************************
57 * BackupEventLogW [ADVAPI32.@]
59 * see BackupEventLogA
61 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
63 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
64 return TRUE;
67 /******************************************************************************
68 * ClearEventLogA [ADVAPI32.@]
70 * Clears the event log and/or saves the log to a backup file.
72 * PARAMS
73 * hEvenLog [I] Handle to event log to clear.
74 * lpBackupFileName [I] Name of the backup file.
76 * RETURNS
77 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
78 * contain the contents of hEvenLog and the log will be cleared.
79 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
80 * exists.
82 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
84 FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
85 return TRUE;
88 /******************************************************************************
89 * ClearEventLogW [ADVAPI32.@]
91 * see ClearEventLogA
93 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
95 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
96 return TRUE;
99 /******************************************************************************
100 * CloseEventLog [ADVAPI32.@]
102 * Closes a read handle to the event log.
104 * PARAMS
105 * hEventLog [I/O] Handle of the event log to close.
107 * RETURNS
108 * Success: nonzero
109 * Failure: zero
111 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
113 FIXME("(%p) stub\n", hEventLog);
114 return TRUE;
117 /******************************************************************************
118 * DeregisterEventSource [ADVAPI32.@]
120 * Closes a write handle to an event log
122 * PARAMS
123 * hEventLog [I/O] Handle of the event log.
125 * RETURNS
126 * Success: nonzero
127 * Failure: zero
129 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
131 FIXME("(%p) stub\n", hEventLog);
132 return TRUE;
135 /******************************************************************************
136 * GetNumberOfEventLogRecords [ADVAPI32.@]
138 * Retrieves the number of records in an event log.
140 * PARAMS
141 * hEventLog [I] Handle to an open event log.
142 * NumberOfRecords [O] Number of records in the log.
144 * RETURNS
145 * Success: nonzero. NumberOfRecords will contain the number of records in
146 * the log.
147 * Failure: zero
149 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
151 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
153 if (!NumberOfRecords) return FALSE;
154 *NumberOfRecords = 0;
156 return TRUE;
159 /******************************************************************************
160 * GetOldestEventLogRecord [ADVAPI32.@]
162 * Retrieves the absolute record number of the oldest record in an even log.
164 * PARAMS
165 * hEventLog [I] Handle to an open event log.
166 * OldestRecord [O] Absolute record number of the oldest record.
168 * RETURNS
169 * Success: nonzero. OldestRecord contains the record number of the oldest
170 * record in the log.
171 * Failure: zero
173 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
175 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
177 if (!OldestRecord) return FALSE;
178 *OldestRecord = 0;
180 return TRUE;
183 /******************************************************************************
184 * NotifyChangeEventLog [ADVAPI32.@]
186 * Enables an application to receive notification when an event is written
187 * to an event log.
189 * PARAMS
190 * hEventLog [I] Handle to an event log.
191 * hEvent [I] Handle to a manual-reset event object.
193 * RETURNS
194 * Success: nonzero
195 * Failure: zero
197 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
199 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
200 return TRUE;
203 /******************************************************************************
204 * OpenBackupEventLogA [ADVAPI32.@]
206 * Opens a handle to a backup event log.
208 * PARAMS
209 * lpUNCServerName [I] Universal Naming Convention name of the server on which
210 * this will be performed.
211 * lpFileName [I] Specifies the name of the backup file.
213 * RETURNS
214 * Success: Handle to the backup event log.
215 * Failure: NULL
217 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
219 FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpFileName));
220 return (HANDLE)0xcafe4242;
223 /******************************************************************************
224 * OpenBackupEventLogW [ADVAPI32.@]
226 * see OpenBackupEventLogA
228 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
230 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
231 return (HANDLE)0xcafe4242;
234 /******************************************************************************
235 * OpenEventLogA [ADVAPI32.@]
237 * Opens a handle to the specified event log.
239 * PARAMS
240 * lpUNCServerName [I] UNC name of the server on which the event log is
241 * opened.
242 * lpSourceName [I] Name of the log.
244 * RETURNS
245 * Success: Handle to an event log.
246 * Failure: NULL
248 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
250 FIXME("(%s,%s) stub\n", debugstr_a(uncname), debugstr_a(source));
251 return (HANDLE)0xcafe4242;
254 /******************************************************************************
255 * OpenEventLogW [ADVAPI32.@]
257 * see OpenEventLogA
259 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
261 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
262 return (HANDLE)0xcafe4242;
265 /******************************************************************************
266 * ReadEventLogA [ADVAPI32.@]
268 * Reads a whole number of entries from an event log.
270 * PARAMS
271 * hEventLog [I] Handle of the event log to read.
272 * dwReadFlags [I] see MSDN doc.
273 * dwRecordOffset [I] Log-entry record number to start at.
274 * lpBuffer [O] Buffer for the data read.
275 * nNumberOfBytesToRead [I] Size of lpBuffer.
276 * pnBytesRead [O] Receives number of bytes read.
277 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
278 * next log entry.
280 * RETURNS
281 * Success: nonzero
282 * Failure: zero
284 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
285 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
287 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
288 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
289 return FALSE;
292 /******************************************************************************
293 * ReadEventLogW [ADVAPI32.@]
295 * see ReadEventLogA
297 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
298 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
300 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
301 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
302 return FALSE;
305 /******************************************************************************
306 * RegisterEventSourceA [ADVAPI32.@]
308 * Returns a registered handle to an event log.
310 * PARAMS
311 * lpUNCServerName [I] UNC name of the source server.
312 * lpSourceName [I] Specifies the name of the event source to retrieve.
314 * RETURNS
315 * Success: Handle to the event log.
316 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
317 * Security event log.
319 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
321 UNICODE_STRING lpUNCServerNameW;
322 UNICODE_STRING lpSourceNameW;
323 HANDLE ret;
325 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
327 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
328 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
329 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
330 RtlFreeUnicodeString (&lpUNCServerNameW);
331 RtlFreeUnicodeString (&lpSourceNameW);
332 return ret;
335 /******************************************************************************
336 * RegisterEventSourceW [ADVAPI32.@]
338 * see RegisterEventSourceA
340 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
342 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
343 return (HANDLE)0xcafe4242;
346 /******************************************************************************
347 * ReportEventA [ADVAPI32.@]
349 * Writes an entry at the end of an event log.
351 * PARAMS
352 * hEventLog [I] Handle of an event log.
353 * wType [I] See MSDN doc.
354 * wCategory [I] Event category.
355 * dwEventID [I] Event identifier.
356 * lpUserSid [I] Current user's security identifier.
357 * wNumStrings [I] Number of insert strings in lpStrings.
358 * dwDataSize [I] Size of event-specific raw data to write.
359 * lpStrings [I] Buffer containing an array of string to be merged.
360 * lpRawData [I] Buffer containing the binary data.
362 * RETURNS
363 * Success: nonzero. Entry was written to the log.
364 * Failure: zero.
366 * NOTES
367 * The ReportEvent function adds the time, the entry's length, and the
368 * offsets before storing the entry in the log. If lpUserSid != NULL, the
369 * username is also logged.
371 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
372 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
374 LPCWSTR *wideStrArray;
375 UNICODE_STRING str;
376 int i;
377 BOOL ret;
379 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
380 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
382 if (wNumStrings == 0) return TRUE;
383 if (!lpStrings) return TRUE;
385 wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings);
386 for (i = 0; i < wNumStrings; i++)
388 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
389 wideStrArray[i] = str.Buffer;
391 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
392 wNumStrings, dwDataSize, wideStrArray, lpRawData);
393 for (i = 0; i < wNumStrings; i++)
395 HeapFree( GetProcessHeap(), 0, (LPSTR)wideStrArray[i] );
397 HeapFree(GetProcessHeap(), 0, wideStrArray);
398 return ret;
401 /******************************************************************************
402 * ReportEventW [ADVAPI32.@]
404 * see ReportEventA
406 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
407 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
409 int i;
411 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
412 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
414 /* partial stub */
416 if (wNumStrings == 0) return TRUE;
417 if (!lpStrings) return TRUE;
419 for (i = 0; i < wNumStrings; i++)
421 switch (wType)
423 case EVENTLOG_SUCCESS:
424 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
425 break;
426 case EVENTLOG_ERROR_TYPE:
427 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
428 break;
429 case EVENTLOG_WARNING_TYPE:
430 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
431 break;
432 default:
433 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
434 break;
437 return TRUE;