win32u: Respect per-monitor thread dpi awareness when getting window from point.
[wine.git] / dlls / advapi32 / eventlog.c
blob58db53f5536a6a61aa519594f37b1cf23ff8340b
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 #define _WMI_SOURCE_
31 #include "evntrace.h"
32 #include "evntprov.h"
34 #include "wine/debug.h"
36 #include "advapi32_misc.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
39 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
41 /******************************************************************************
42 * BackupEventLogA [ADVAPI32.@]
44 * Saves the event log to a backup file.
46 * PARAMS
47 * hEventLog [I] Handle to event log to backup.
48 * lpBackupFileName [I] Name of the backup file.
50 * RETURNS
51 * Success: nonzero. File lpBackupFileName will contain the contents of
52 * hEvenLog.
53 * Failure: zero.
55 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
57 LPWSTR backupW;
58 BOOL ret;
60 backupW = strdupAW(lpBackupFileName);
61 ret = BackupEventLogW(hEventLog, backupW);
62 free(backupW);
64 return ret;
67 /******************************************************************************
68 * BackupEventLogW [ADVAPI32.@]
70 * See BackupEventLogA.
72 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
74 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
76 if (!lpBackupFileName)
78 SetLastError(ERROR_INVALID_PARAMETER);
79 return FALSE;
82 if (!hEventLog)
84 SetLastError(ERROR_INVALID_HANDLE);
85 return FALSE;
88 if (GetFileAttributesW(lpBackupFileName) != INVALID_FILE_ATTRIBUTES)
90 SetLastError(ERROR_ALREADY_EXISTS);
91 return FALSE;
94 return TRUE;
97 /******************************************************************************
98 * ClearEventLogA [ADVAPI32.@]
100 * Clears the event log and optionally saves the log to a backup file.
102 * PARAMS
103 * hEvenLog [I] Handle to event log to clear.
104 * lpBackupFileName [I] Name of the backup file.
106 * RETURNS
107 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
108 * contain the contents of hEvenLog and the log will be cleared.
109 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
110 * exists.
112 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
114 LPWSTR backupW;
115 BOOL ret;
117 backupW = strdupAW(lpBackupFileName);
118 ret = ClearEventLogW(hEventLog, backupW);
119 free(backupW);
121 return ret;
124 /******************************************************************************
125 * ClearEventLogW [ADVAPI32.@]
127 * See ClearEventLogA.
129 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
131 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
133 if (!hEventLog)
135 SetLastError(ERROR_INVALID_HANDLE);
136 return FALSE;
139 return TRUE;
142 /******************************************************************************
143 * CloseEventLog [ADVAPI32.@]
145 * Closes a read handle to the event log.
147 * PARAMS
148 * hEventLog [I/O] Handle of the event log to close.
150 * RETURNS
151 * Success: nonzero
152 * Failure: zero
154 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
156 FIXME("(%p) stub\n", hEventLog);
158 if (!hEventLog)
160 SetLastError(ERROR_INVALID_HANDLE);
161 return FALSE;
164 return TRUE;
167 /******************************************************************************
168 * FlushTraceA [ADVAPI32.@]
170 ULONG WINAPI FlushTraceA ( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
172 return ControlTraceA( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
175 /******************************************************************************
176 * FlushTraceW [ADVAPI32.@]
178 ULONG WINAPI FlushTraceW ( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
180 return ControlTraceW( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
184 /******************************************************************************
185 * DeregisterEventSource [ADVAPI32.@]
187 * Closes a write handle to an event log
189 * PARAMS
190 * hEventLog [I/O] Handle of the event log.
192 * RETURNS
193 * Success: nonzero
194 * Failure: zero
196 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
198 FIXME("(%p) stub\n", hEventLog);
199 return TRUE;
202 /******************************************************************************
203 * EnableTraceEx [ADVAPI32.@]
205 ULONG WINAPI EnableTraceEx( LPCGUID provider, LPCGUID source, TRACEHANDLE hSession, ULONG enable,
206 UCHAR level, ULONGLONG anykeyword, ULONGLONG allkeyword, ULONG enableprop,
207 PEVENT_FILTER_DESCRIPTOR filterdesc )
209 FIXME("(%s, %s, %s, %lu, %u, %s, %s, %lu, %p): stub\n", debugstr_guid(provider),
210 debugstr_guid(source), wine_dbgstr_longlong(hSession), enable, level,
211 wine_dbgstr_longlong(anykeyword), wine_dbgstr_longlong(allkeyword),
212 enableprop, filterdesc);
214 return ERROR_SUCCESS;
217 /******************************************************************************
218 * EnableTrace [ADVAPI32.@]
220 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
222 FIXME("(%ld, 0x%lx, %ld, %s, %s): stub\n", enable, flag, level,
223 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
225 return ERROR_SUCCESS;
228 /******************************************************************************
229 * GetEventLogInformation [ADVAPI32.@]
231 * Retrieve some information about an event log.
233 * PARAMS
234 * hEventLog [I] Handle to an open event log.
235 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
236 * lpBuffer [I/O] The buffer for the returned information
237 * cbBufSize [I] The size of the buffer
238 * pcbBytesNeeded [O] The needed bytes to hold the information
240 * RETURNS
241 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
242 * the needed buffer size.
243 * Failure: FALSE.
245 BOOL WINAPI GetEventLogInformation( HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
247 EVENTLOG_FULL_INFORMATION *efi;
249 FIXME("(%p, %ld, %p, %ld, %p) stub\n", hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
251 if (dwInfoLevel != EVENTLOG_FULL_INFO)
253 SetLastError(ERROR_INVALID_LEVEL);
254 return FALSE;
257 if (!hEventLog)
259 SetLastError(ERROR_INVALID_HANDLE);
260 return FALSE;
263 if (!lpBuffer || !pcbBytesNeeded)
265 /* FIXME: This will be handled properly when eventlog is moved
266 * to a higher level
268 SetLastError(RPC_X_NULL_REF_POINTER);
269 return FALSE;
272 *pcbBytesNeeded = sizeof(EVENTLOG_FULL_INFORMATION);
273 if (cbBufSize < sizeof(EVENTLOG_FULL_INFORMATION))
275 SetLastError(ERROR_INSUFFICIENT_BUFFER);
276 return FALSE;
279 /* Pretend the log is not full */
280 efi = (EVENTLOG_FULL_INFORMATION *)lpBuffer;
281 efi->dwFull = 0;
283 return TRUE;
286 /******************************************************************************
287 * GetNumberOfEventLogRecords [ADVAPI32.@]
289 * Retrieves the number of records in an event log.
291 * PARAMS
292 * hEventLog [I] Handle to an open event log.
293 * NumberOfRecords [O] Number of records in the log.
295 * RETURNS
296 * Success: nonzero. NumberOfRecords will contain the number of records in
297 * the log.
298 * Failure: zero
300 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
302 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
304 if (!NumberOfRecords)
306 SetLastError(ERROR_INVALID_PARAMETER);
307 return FALSE;
310 if (!hEventLog)
312 SetLastError(ERROR_INVALID_HANDLE);
313 return FALSE;
316 *NumberOfRecords = 0;
318 return TRUE;
321 /******************************************************************************
322 * GetOldestEventLogRecord [ADVAPI32.@]
324 * Retrieves the absolute record number of the oldest record in an even log.
326 * PARAMS
327 * hEventLog [I] Handle to an open event log.
328 * OldestRecord [O] Absolute record number of the oldest record.
330 * RETURNS
331 * Success: nonzero. OldestRecord contains the record number of the oldest
332 * record in the log.
333 * Failure: zero
335 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
337 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
339 if (!OldestRecord)
341 SetLastError(ERROR_INVALID_PARAMETER);
342 return FALSE;
345 if (!hEventLog)
347 SetLastError(ERROR_INVALID_HANDLE);
348 return FALSE;
351 *OldestRecord = 0;
353 return TRUE;
356 /******************************************************************************
357 * NotifyChangeEventLog [ADVAPI32.@]
359 * Enables an application to receive notification when an event is written
360 * to an event log.
362 * PARAMS
363 * hEventLog [I] Handle to an event log.
364 * hEvent [I] Handle to a manual-reset event object.
366 * RETURNS
367 * Success: nonzero
368 * Failure: zero
370 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
372 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
373 return TRUE;
376 /******************************************************************************
377 * OpenBackupEventLogA [ADVAPI32.@]
379 * Opens a handle to a backup event log.
381 * PARAMS
382 * lpUNCServerName [I] Universal Naming Convention name of the server on which
383 * this will be performed.
384 * lpFileName [I] Specifies the name of the backup file.
386 * RETURNS
387 * Success: Handle to the backup event log.
388 * Failure: NULL
390 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
392 LPWSTR uncnameW, filenameW;
393 HANDLE handle;
395 uncnameW = strdupAW(lpUNCServerName);
396 filenameW = strdupAW(lpFileName);
397 handle = OpenBackupEventLogW(uncnameW, filenameW);
398 free(uncnameW);
399 free(filenameW);
401 return handle;
404 /******************************************************************************
405 * OpenBackupEventLogW [ADVAPI32.@]
407 * See OpenBackupEventLogA.
409 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
411 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
413 if (!lpFileName)
415 SetLastError(ERROR_INVALID_PARAMETER);
416 return NULL;
419 if (lpUNCServerName && lpUNCServerName[0])
421 FIXME("Remote server not supported\n");
422 SetLastError(RPC_S_SERVER_UNAVAILABLE);
423 return NULL;
426 if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES)
428 SetLastError(ERROR_FILE_NOT_FOUND);
429 return NULL;
432 return (HANDLE)0xcafe4242;
435 /******************************************************************************
436 * OpenEventLogA [ADVAPI32.@]
438 * Opens a handle to the specified event log.
440 * PARAMS
441 * lpUNCServerName [I] UNC name of the server on which the event log is
442 * opened.
443 * lpSourceName [I] Name of the log.
445 * RETURNS
446 * Success: Handle to an event log.
447 * Failure: NULL
449 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
451 LPWSTR uncnameW, sourceW;
452 HANDLE handle;
454 uncnameW = strdupAW(uncname);
455 sourceW = strdupAW(source);
456 handle = OpenEventLogW(uncnameW, sourceW);
457 free(uncnameW);
458 free(sourceW);
460 return handle;
463 /******************************************************************************
464 * OpenEventLogW [ADVAPI32.@]
466 * See OpenEventLogA.
468 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
470 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
472 if (!source)
474 SetLastError(ERROR_INVALID_PARAMETER);
475 return NULL;
478 if (uncname && uncname[0])
480 FIXME("Remote server not supported\n");
481 SetLastError(RPC_S_SERVER_UNAVAILABLE);
482 return NULL;
485 return (HANDLE)0xcafe4242;
488 /******************************************************************************
489 * ReadEventLogA [ADVAPI32.@]
491 * Reads a whole number of entries from an event log.
493 * PARAMS
494 * hEventLog [I] Handle of the event log to read.
495 * dwReadFlags [I] see MSDN doc.
496 * dwRecordOffset [I] Log-entry record number to start at.
497 * lpBuffer [O] Buffer for the data read.
498 * nNumberOfBytesToRead [I] Size of lpBuffer.
499 * pnBytesRead [O] Receives number of bytes read.
500 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
501 * next log entry.
503 * RETURNS
504 * Success: nonzero
505 * Failure: zero
507 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
508 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
510 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
511 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
513 SetLastError(ERROR_HANDLE_EOF);
514 return FALSE;
517 /******************************************************************************
518 * ReadEventLogW [ADVAPI32.@]
520 * See ReadEventLogA.
522 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
523 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
525 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog, dwReadFlags,
526 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
528 SetLastError(ERROR_HANDLE_EOF);
529 return FALSE;
532 /******************************************************************************
533 * RegisterEventSourceA [ADVAPI32.@]
535 * Returns a registered handle to an event log.
537 * PARAMS
538 * lpUNCServerName [I] UNC name of the source server.
539 * lpSourceName [I] Specifies the name of the event source to retrieve.
541 * RETURNS
542 * Success: Handle to the event log.
543 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
544 * Security event log.
546 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
548 UNICODE_STRING lpUNCServerNameW;
549 UNICODE_STRING lpSourceNameW;
550 HANDLE ret;
552 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
554 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
555 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
556 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
557 RtlFreeUnicodeString (&lpUNCServerNameW);
558 RtlFreeUnicodeString (&lpSourceNameW);
559 return ret;
562 /******************************************************************************
563 * RegisterEventSourceW [ADVAPI32.@]
565 * See RegisterEventSourceA.
567 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
569 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
570 return (HANDLE)0xcafe4242;
573 /******************************************************************************
574 * ReportEventA [ADVAPI32.@]
576 * Writes an entry at the end of an event log.
578 * PARAMS
579 * hEventLog [I] Handle of an event log.
580 * wType [I] See MSDN doc.
581 * wCategory [I] Event category.
582 * dwEventID [I] Event identifier.
583 * lpUserSid [I] Current user's security identifier.
584 * wNumStrings [I] Number of insert strings in lpStrings.
585 * dwDataSize [I] Size of event-specific raw data to write.
586 * lpStrings [I] Buffer containing an array of string to be merged.
587 * lpRawData [I] Buffer containing the binary data.
589 * RETURNS
590 * Success: nonzero. Entry was written to the log.
591 * Failure: zero.
593 * NOTES
594 * The ReportEvent function adds the time, the entry's length, and the
595 * offsets before storing the entry in the log. If lpUserSid != NULL, the
596 * username is also logged.
598 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
599 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
601 LPWSTR *wideStrArray;
602 UNICODE_STRING str;
603 UINT i;
604 BOOL ret;
606 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
607 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
609 if (wNumStrings == 0) return TRUE;
610 if (!lpStrings) return TRUE;
612 wideStrArray = malloc(sizeof(WCHAR *) * wNumStrings);
613 for (i = 0; i < wNumStrings; i++)
615 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
616 wideStrArray[i] = str.Buffer;
618 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
619 wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
620 for (i = 0; i < wNumStrings; i++)
621 free(wideStrArray[i]);
622 free(wideStrArray);
623 return ret;
626 /******************************************************************************
627 * ReportEventW [ADVAPI32.@]
629 * See ReportEventA.
631 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
632 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
634 UINT i;
636 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog,
637 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
639 /* partial stub */
641 if (wNumStrings == 0) return TRUE;
642 if (!lpStrings) return TRUE;
644 for (i = 0; i < wNumStrings; i++)
646 const WCHAR *line = lpStrings[i];
648 while (*line)
650 const WCHAR *next = wcschr( line, '\n' );
652 if (next)
653 ++next;
654 else
655 next = line + wcslen( line );
657 switch (wType)
659 case EVENTLOG_SUCCESS:
660 TRACE_(eventlog)("%s\n", debugstr_wn(line, next - line));
661 break;
662 case EVENTLOG_ERROR_TYPE:
663 ERR_(eventlog)("%s\n", debugstr_wn(line, next - line));
664 break;
665 case EVENTLOG_WARNING_TYPE:
666 WARN_(eventlog)("%s\n", debugstr_wn(line, next - line));
667 break;
668 default:
669 TRACE_(eventlog)("%s\n", debugstr_wn(line, next - line));
670 break;
673 line = next;
676 return TRUE;
679 /******************************************************************************
680 * StopTraceA [ADVAPI32.@]
682 * See StopTraceW.
685 ULONG WINAPI StopTraceA( TRACEHANDLE session, LPCSTR session_name, PEVENT_TRACE_PROPERTIES properties )
687 FIXME("(%s, %s, %p) stub\n", wine_dbgstr_longlong(session), debugstr_a(session_name), properties);
688 return ERROR_SUCCESS;
691 /******************************************************************************
692 * QueryTraceA [ADVAPI32.@]
694 ULONG WINAPI QueryTraceA( TRACEHANDLE handle, LPCSTR sessionname, PEVENT_TRACE_PROPERTIES properties )
696 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle), debugstr_a(sessionname), properties);
697 return ERROR_WMI_INSTANCE_NOT_FOUND;
700 /******************************************************************************
701 * QueryTraceW [ADVAPI32.@]
703 ULONG WINAPI QueryTraceW( TRACEHANDLE handle, LPCWSTR sessionname, PEVENT_TRACE_PROPERTIES properties )
705 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle), debugstr_w(sessionname), properties);
706 return ERROR_CALL_NOT_IMPLEMENTED;
709 /******************************************************************************
710 * OpenTraceA [ADVAPI32.@]
712 TRACEHANDLE WINAPI OpenTraceA( PEVENT_TRACE_LOGFILEA logfile )
714 static int once;
716 if (!once++) FIXME("%p: stub\n", logfile);
717 SetLastError(ERROR_ACCESS_DENIED);
718 return INVALID_PROCESSTRACE_HANDLE;
721 /******************************************************************************
722 * EnumerateTraceGuids [ADVAPI32.@]
724 ULONG WINAPI EnumerateTraceGuids(PTRACE_GUID_PROPERTIES *propertiesarray,
725 ULONG arraycount, PULONG guidcount)
727 FIXME("%p %ld %p: stub\n", propertiesarray, arraycount, guidcount);
728 return ERROR_INVALID_PARAMETER;