server: Do not bother clearing events in IOCTL_AFD_WINE_CONNECT.
[wine.git] / dlls / advapi32 / eventlog.c
blob22e5a3f9d59c2701043477b8d68638c8e36b631f
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winternl.h"
29 #include "wmistr.h"
30 #include "evntrace.h"
31 #include "evntprov.h"
33 #include "wine/debug.h"
35 #include "advapi32_misc.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
38 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
40 /******************************************************************************
41 * BackupEventLogA [ADVAPI32.@]
43 * Saves the event log to a backup file.
45 * PARAMS
46 * hEventLog [I] Handle to event log to backup.
47 * lpBackupFileName [I] Name of the backup file.
49 * RETURNS
50 * Success: nonzero. File lpBackupFileName will contain the contents of
51 * hEvenLog.
52 * Failure: zero.
54 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
56 LPWSTR backupW;
57 BOOL ret;
59 backupW = strdupAW(lpBackupFileName);
60 ret = BackupEventLogW(hEventLog, backupW);
61 heap_free(backupW);
63 return ret;
66 /******************************************************************************
67 * BackupEventLogW [ADVAPI32.@]
69 * See BackupEventLogA.
71 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
73 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
75 if (!lpBackupFileName)
77 SetLastError(ERROR_INVALID_PARAMETER);
78 return FALSE;
81 if (!hEventLog)
83 SetLastError(ERROR_INVALID_HANDLE);
84 return FALSE;
87 if (GetFileAttributesW(lpBackupFileName) != INVALID_FILE_ATTRIBUTES)
89 SetLastError(ERROR_ALREADY_EXISTS);
90 return FALSE;
93 return TRUE;
96 /******************************************************************************
97 * ClearEventLogA [ADVAPI32.@]
99 * Clears the event log and optionally saves the log to a backup file.
101 * PARAMS
102 * hEvenLog [I] Handle to event log to clear.
103 * lpBackupFileName [I] Name of the backup file.
105 * RETURNS
106 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
107 * contain the contents of hEvenLog and the log will be cleared.
108 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
109 * exists.
111 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
113 LPWSTR backupW;
114 BOOL ret;
116 backupW = strdupAW(lpBackupFileName);
117 ret = ClearEventLogW(hEventLog, backupW);
118 heap_free(backupW);
120 return ret;
123 /******************************************************************************
124 * ClearEventLogW [ADVAPI32.@]
126 * See ClearEventLogA.
128 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
130 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
132 if (!hEventLog)
134 SetLastError(ERROR_INVALID_HANDLE);
135 return FALSE;
138 return TRUE;
141 /******************************************************************************
142 * CloseEventLog [ADVAPI32.@]
144 * Closes a read handle to the event log.
146 * PARAMS
147 * hEventLog [I/O] Handle of the event log to close.
149 * RETURNS
150 * Success: nonzero
151 * Failure: zero
153 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
155 FIXME("(%p) stub\n", hEventLog);
157 if (!hEventLog)
159 SetLastError(ERROR_INVALID_HANDLE);
160 return FALSE;
163 return TRUE;
166 /******************************************************************************
167 * FlushTraceA [ADVAPI32.@]
169 ULONG WINAPI FlushTraceA ( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
171 return ControlTraceA( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
174 /******************************************************************************
175 * FlushTraceW [ADVAPI32.@]
177 ULONG WINAPI FlushTraceW ( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
179 return ControlTraceW( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
183 /******************************************************************************
184 * DeregisterEventSource [ADVAPI32.@]
186 * Closes a write handle to an event log
188 * PARAMS
189 * hEventLog [I/O] Handle of the event log.
191 * RETURNS
192 * Success: nonzero
193 * Failure: zero
195 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
197 FIXME("(%p) stub\n", hEventLog);
198 return TRUE;
201 /******************************************************************************
202 * EnableTraceEx [ADVAPI32.@]
204 ULONG WINAPI EnableTraceEx( LPCGUID provider, LPCGUID source, TRACEHANDLE hSession, ULONG enable,
205 UCHAR level, ULONGLONG anykeyword, ULONGLONG allkeyword, ULONG enableprop,
206 PEVENT_FILTER_DESCRIPTOR filterdesc )
208 FIXME("(%s, %s, %s, %u, %u, %s, %s, %u, %p): stub\n", debugstr_guid(provider),
209 debugstr_guid(source), wine_dbgstr_longlong(hSession), enable, level,
210 wine_dbgstr_longlong(anykeyword), wine_dbgstr_longlong(allkeyword),
211 enableprop, filterdesc);
213 return ERROR_SUCCESS;
216 /******************************************************************************
217 * EnableTrace [ADVAPI32.@]
219 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
221 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
222 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
224 return ERROR_SUCCESS;
227 /******************************************************************************
228 * GetEventLogInformation [ADVAPI32.@]
230 * Retrieve some information about an event log.
232 * PARAMS
233 * hEventLog [I] Handle to an open event log.
234 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
235 * lpBuffer [I/O] The buffer for the returned information
236 * cbBufSize [I] The size of the buffer
237 * pcbBytesNeeded [O] The needed bytes to hold the information
239 * RETURNS
240 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
241 * the needed buffer size.
242 * Failure: FALSE.
244 BOOL WINAPI GetEventLogInformation( HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
246 EVENTLOG_FULL_INFORMATION *efi;
248 FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
250 if (dwInfoLevel != EVENTLOG_FULL_INFO)
252 SetLastError(ERROR_INVALID_LEVEL);
253 return FALSE;
256 if (!hEventLog)
258 SetLastError(ERROR_INVALID_HANDLE);
259 return FALSE;
262 if (!lpBuffer || !pcbBytesNeeded)
264 /* FIXME: This will be handled properly when eventlog is moved
265 * to a higher level
267 SetLastError(RPC_X_NULL_REF_POINTER);
268 return FALSE;
271 *pcbBytesNeeded = sizeof(EVENTLOG_FULL_INFORMATION);
272 if (cbBufSize < sizeof(EVENTLOG_FULL_INFORMATION))
274 SetLastError(ERROR_INSUFFICIENT_BUFFER);
275 return FALSE;
278 /* Pretend the log is not full */
279 efi = (EVENTLOG_FULL_INFORMATION *)lpBuffer;
280 efi->dwFull = 0;
282 return TRUE;
285 /******************************************************************************
286 * GetNumberOfEventLogRecords [ADVAPI32.@]
288 * Retrieves the number of records in an event log.
290 * PARAMS
291 * hEventLog [I] Handle to an open event log.
292 * NumberOfRecords [O] Number of records in the log.
294 * RETURNS
295 * Success: nonzero. NumberOfRecords will contain the number of records in
296 * the log.
297 * Failure: zero
299 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
301 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
303 if (!NumberOfRecords)
305 SetLastError(ERROR_INVALID_PARAMETER);
306 return FALSE;
309 if (!hEventLog)
311 SetLastError(ERROR_INVALID_HANDLE);
312 return FALSE;
315 *NumberOfRecords = 0;
317 return TRUE;
320 /******************************************************************************
321 * GetOldestEventLogRecord [ADVAPI32.@]
323 * Retrieves the absolute record number of the oldest record in an even log.
325 * PARAMS
326 * hEventLog [I] Handle to an open event log.
327 * OldestRecord [O] Absolute record number of the oldest record.
329 * RETURNS
330 * Success: nonzero. OldestRecord contains the record number of the oldest
331 * record in the log.
332 * Failure: zero
334 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
336 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
338 if (!OldestRecord)
340 SetLastError(ERROR_INVALID_PARAMETER);
341 return FALSE;
344 if (!hEventLog)
346 SetLastError(ERROR_INVALID_HANDLE);
347 return FALSE;
350 *OldestRecord = 0;
352 return TRUE;
355 /******************************************************************************
356 * NotifyChangeEventLog [ADVAPI32.@]
358 * Enables an application to receive notification when an event is written
359 * to an event log.
361 * PARAMS
362 * hEventLog [I] Handle to an event log.
363 * hEvent [I] Handle to a manual-reset event object.
365 * RETURNS
366 * Success: nonzero
367 * Failure: zero
369 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
371 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
372 return TRUE;
375 /******************************************************************************
376 * OpenBackupEventLogA [ADVAPI32.@]
378 * Opens a handle to a backup event log.
380 * PARAMS
381 * lpUNCServerName [I] Universal Naming Convention name of the server on which
382 * this will be performed.
383 * lpFileName [I] Specifies the name of the backup file.
385 * RETURNS
386 * Success: Handle to the backup event log.
387 * Failure: NULL
389 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
391 LPWSTR uncnameW, filenameW;
392 HANDLE handle;
394 uncnameW = strdupAW(lpUNCServerName);
395 filenameW = strdupAW(lpFileName);
396 handle = OpenBackupEventLogW(uncnameW, filenameW);
397 heap_free(uncnameW);
398 heap_free(filenameW);
400 return handle;
403 /******************************************************************************
404 * OpenBackupEventLogW [ADVAPI32.@]
406 * See OpenBackupEventLogA.
408 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
410 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
412 if (!lpFileName)
414 SetLastError(ERROR_INVALID_PARAMETER);
415 return NULL;
418 if (lpUNCServerName && lpUNCServerName[0])
420 FIXME("Remote server not supported\n");
421 SetLastError(RPC_S_SERVER_UNAVAILABLE);
422 return NULL;
425 if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES)
427 SetLastError(ERROR_FILE_NOT_FOUND);
428 return NULL;
431 return (HANDLE)0xcafe4242;
434 /******************************************************************************
435 * OpenEventLogA [ADVAPI32.@]
437 * Opens a handle to the specified event log.
439 * PARAMS
440 * lpUNCServerName [I] UNC name of the server on which the event log is
441 * opened.
442 * lpSourceName [I] Name of the log.
444 * RETURNS
445 * Success: Handle to an event log.
446 * Failure: NULL
448 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
450 LPWSTR uncnameW, sourceW;
451 HANDLE handle;
453 uncnameW = strdupAW(uncname);
454 sourceW = strdupAW(source);
455 handle = OpenEventLogW(uncnameW, sourceW);
456 heap_free(uncnameW);
457 heap_free(sourceW);
459 return handle;
462 /******************************************************************************
463 * OpenEventLogW [ADVAPI32.@]
465 * See OpenEventLogA.
467 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
469 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
471 if (!source)
473 SetLastError(ERROR_INVALID_PARAMETER);
474 return NULL;
477 if (uncname && uncname[0])
479 FIXME("Remote server not supported\n");
480 SetLastError(RPC_S_SERVER_UNAVAILABLE);
481 return NULL;
484 return (HANDLE)0xcafe4242;
487 /******************************************************************************
488 * ReadEventLogA [ADVAPI32.@]
490 * Reads a whole number of entries from an event log.
492 * PARAMS
493 * hEventLog [I] Handle of the event log to read.
494 * dwReadFlags [I] see MSDN doc.
495 * dwRecordOffset [I] Log-entry record number to start at.
496 * lpBuffer [O] Buffer for the data read.
497 * nNumberOfBytesToRead [I] Size of lpBuffer.
498 * pnBytesRead [O] Receives number of bytes read.
499 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
500 * next log entry.
502 * RETURNS
503 * Success: nonzero
504 * Failure: zero
506 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
507 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
509 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
510 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
512 SetLastError(ERROR_HANDLE_EOF);
513 return FALSE;
516 /******************************************************************************
517 * ReadEventLogW [ADVAPI32.@]
519 * See ReadEventLogA.
521 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
522 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
524 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
525 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
527 SetLastError(ERROR_HANDLE_EOF);
528 return FALSE;
531 /******************************************************************************
532 * RegisterEventSourceA [ADVAPI32.@]
534 * Returns a registered handle to an event log.
536 * PARAMS
537 * lpUNCServerName [I] UNC name of the source server.
538 * lpSourceName [I] Specifies the name of the event source to retrieve.
540 * RETURNS
541 * Success: Handle to the event log.
542 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
543 * Security event log.
545 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
547 UNICODE_STRING lpUNCServerNameW;
548 UNICODE_STRING lpSourceNameW;
549 HANDLE ret;
551 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
553 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
554 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
555 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
556 RtlFreeUnicodeString (&lpUNCServerNameW);
557 RtlFreeUnicodeString (&lpSourceNameW);
558 return ret;
561 /******************************************************************************
562 * RegisterEventSourceW [ADVAPI32.@]
564 * See RegisterEventSourceA.
566 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
568 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
569 return (HANDLE)0xcafe4242;
572 /******************************************************************************
573 * ReportEventA [ADVAPI32.@]
575 * Writes an entry at the end of an event log.
577 * PARAMS
578 * hEventLog [I] Handle of an event log.
579 * wType [I] See MSDN doc.
580 * wCategory [I] Event category.
581 * dwEventID [I] Event identifier.
582 * lpUserSid [I] Current user's security identifier.
583 * wNumStrings [I] Number of insert strings in lpStrings.
584 * dwDataSize [I] Size of event-specific raw data to write.
585 * lpStrings [I] Buffer containing an array of string to be merged.
586 * lpRawData [I] Buffer containing the binary data.
588 * RETURNS
589 * Success: nonzero. Entry was written to the log.
590 * Failure: zero.
592 * NOTES
593 * The ReportEvent function adds the time, the entry's length, and the
594 * offsets before storing the entry in the log. If lpUserSid != NULL, the
595 * username is also logged.
597 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
598 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
600 LPWSTR *wideStrArray;
601 UNICODE_STRING str;
602 UINT i;
603 BOOL ret;
605 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
606 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
608 if (wNumStrings == 0) return TRUE;
609 if (!lpStrings) return TRUE;
611 wideStrArray = heap_alloc(sizeof(LPWSTR) * wNumStrings);
612 for (i = 0; i < wNumStrings; i++)
614 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
615 wideStrArray[i] = str.Buffer;
617 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
618 wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
619 for (i = 0; i < wNumStrings; i++)
620 heap_free( wideStrArray[i] );
621 heap_free(wideStrArray);
622 return ret;
625 /******************************************************************************
626 * ReportEventW [ADVAPI32.@]
628 * See ReportEventA.
630 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
631 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
633 UINT i;
635 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
636 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
638 /* partial stub */
640 if (wNumStrings == 0) return TRUE;
641 if (!lpStrings) return TRUE;
643 for (i = 0; i < wNumStrings; i++)
645 switch (wType)
647 case EVENTLOG_SUCCESS:
648 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
649 break;
650 case EVENTLOG_ERROR_TYPE:
651 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
652 break;
653 case EVENTLOG_WARNING_TYPE:
654 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
655 break;
656 default:
657 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
658 break;
661 return TRUE;
664 /******************************************************************************
665 * StopTraceA [ADVAPI32.@]
667 * See StopTraceW.
670 ULONG WINAPI StopTraceA( TRACEHANDLE session, LPCSTR session_name, PEVENT_TRACE_PROPERTIES properties )
672 FIXME("(%s, %s, %p) stub\n", wine_dbgstr_longlong(session), debugstr_a(session_name), properties);
673 return ERROR_SUCCESS;
676 /******************************************************************************
677 * QueryTraceA [ADVAPI32.@]
679 ULONG WINAPI QueryTraceA( TRACEHANDLE handle, LPCSTR sessionname, PEVENT_TRACE_PROPERTIES properties )
681 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle), debugstr_a(sessionname), properties);
682 return ERROR_WMI_INSTANCE_NOT_FOUND;
685 /******************************************************************************
686 * QueryTraceW [ADVAPI32.@]
688 ULONG WINAPI QueryTraceW( TRACEHANDLE handle, LPCWSTR sessionname, PEVENT_TRACE_PROPERTIES properties )
690 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle), debugstr_w(sessionname), properties);
691 return ERROR_CALL_NOT_IMPLEMENTED;
694 /******************************************************************************
695 * OpenTraceA [ADVAPI32.@]
697 TRACEHANDLE WINAPI OpenTraceA( PEVENT_TRACE_LOGFILEA logfile )
699 static int once;
701 if (!once++) FIXME("%p: stub\n", logfile);
702 SetLastError(ERROR_ACCESS_DENIED);
703 return INVALID_PROCESSTRACE_HANDLE;
706 /******************************************************************************
707 * EnumerateTraceGuids [ADVAPI32.@]
709 ULONG WINAPI EnumerateTraceGuids(PTRACE_GUID_PROPERTIES *propertiesarray,
710 ULONG arraycount, PULONG guidcount)
712 FIXME("%p %d %p: stub\n", propertiesarray, arraycount, guidcount);
713 return ERROR_INVALID_PARAMETER;