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
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
36 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
38 static inline LPWSTR SERV_dup( LPCSTR str )
45 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
46 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
47 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len );
51 /******************************************************************************
52 * BackupEventLogA [ADVAPI32.@]
54 * Saves the event log to a backup file.
57 * hEventLog [I] Handle to event log to backup.
58 * lpBackupFileName [I] Name of the backup file.
61 * Success: nonzero. File lpBackupFileName will contain the contents of
65 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
70 backupW = SERV_dup(lpBackupFileName);
71 ret = BackupEventLogW(hEventLog, backupW);
72 HeapFree(GetProcessHeap(), 0, backupW);
77 /******************************************************************************
78 * BackupEventLogW [ADVAPI32.@]
80 * See BackupEventLogA.
82 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
84 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
86 if (!lpBackupFileName)
88 SetLastError(ERROR_INVALID_PARAMETER);
94 SetLastError(ERROR_INVALID_HANDLE);
98 if (GetFileAttributesW(lpBackupFileName) != INVALID_FILE_ATTRIBUTES)
100 SetLastError(ERROR_ALREADY_EXISTS);
107 /******************************************************************************
108 * ClearEventLogA [ADVAPI32.@]
110 * Clears the event log and optionally saves the log to a backup file.
113 * hEvenLog [I] Handle to event log to clear.
114 * lpBackupFileName [I] Name of the backup file.
117 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
118 * contain the contents of hEvenLog and the log will be cleared.
119 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
122 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
127 backupW = SERV_dup(lpBackupFileName);
128 ret = ClearEventLogW(hEventLog, backupW);
129 HeapFree(GetProcessHeap(), 0, backupW);
134 /******************************************************************************
135 * ClearEventLogW [ADVAPI32.@]
137 * See ClearEventLogA.
139 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
141 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
145 SetLastError(ERROR_INVALID_HANDLE);
152 /******************************************************************************
153 * CloseEventLog [ADVAPI32.@]
155 * Closes a read handle to the event log.
158 * hEventLog [I/O] Handle of the event log to close.
164 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
166 FIXME("(%p) stub\n", hEventLog);
170 SetLastError(ERROR_INVALID_HANDLE);
177 /******************************************************************************
178 * ControlTraceW [ADVAPI32.@]
180 * Control a givel event trace session
183 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
185 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
186 return ERROR_SUCCESS;
189 /******************************************************************************
190 * ControlTraceA [ADVAPI32.@]
195 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
197 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
198 return ERROR_SUCCESS;
201 /******************************************************************************
202 * DeregisterEventSource [ADVAPI32.@]
204 * Closes a write handle to an event log
207 * hEventLog [I/O] Handle of the event log.
213 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
215 FIXME("(%p) stub\n", hEventLog);
219 /******************************************************************************
220 * EnableTrace [ADVAPI32.@]
222 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
224 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
225 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
227 return ERROR_SUCCESS;
230 /******************************************************************************
231 * GetEventLogInformation [ADVAPI32.@]
233 * Retrieve some information about an event log.
236 * hEventLog [I] Handle to an open event log.
237 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
238 * lpBuffer [I/O] The buffer for the returned information
239 * cbBufSize [I] The size of the buffer
240 * pcbBytesNeeded [O] The needed bytes to hold the information
243 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
244 * the needed buffer size.
247 BOOL WINAPI GetEventLogInformation( HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
249 EVENTLOG_FULL_INFORMATION *efi;
251 FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
253 if (dwInfoLevel != EVENTLOG_FULL_INFO)
255 SetLastError(ERROR_INVALID_LEVEL);
261 SetLastError(ERROR_INVALID_HANDLE);
265 if (!lpBuffer || !pcbBytesNeeded)
267 /* FIXME: This will be handled properly when eventlog is moved
270 SetLastError(RPC_X_NULL_REF_POINTER);
274 *pcbBytesNeeded = sizeof(EVENTLOG_FULL_INFORMATION);
275 if (cbBufSize < sizeof(EVENTLOG_FULL_INFORMATION))
277 SetLastError(ERROR_INSUFFICIENT_BUFFER);
281 /* Pretend the log is not full */
282 efi = (EVENTLOG_FULL_INFORMATION *)lpBuffer;
288 /******************************************************************************
289 * GetNumberOfEventLogRecords [ADVAPI32.@]
291 * Retrieves the number of records in an event log.
294 * hEventLog [I] Handle to an open event log.
295 * NumberOfRecords [O] Number of records in the log.
298 * Success: nonzero. NumberOfRecords will contain the number of records in
302 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
304 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
306 if (!NumberOfRecords)
308 SetLastError(ERROR_INVALID_PARAMETER);
314 SetLastError(ERROR_INVALID_HANDLE);
318 *NumberOfRecords = 0;
323 /******************************************************************************
324 * GetOldestEventLogRecord [ADVAPI32.@]
326 * Retrieves the absolute record number of the oldest record in an even log.
329 * hEventLog [I] Handle to an open event log.
330 * OldestRecord [O] Absolute record number of the oldest record.
333 * Success: nonzero. OldestRecord contains the record number of the oldest
337 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
339 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
343 SetLastError(ERROR_INVALID_PARAMETER);
349 SetLastError(ERROR_INVALID_HANDLE);
358 /******************************************************************************
359 * NotifyChangeEventLog [ADVAPI32.@]
361 * Enables an application to receive notification when an event is written
365 * hEventLog [I] Handle to an event log.
366 * hEvent [I] Handle to a manual-reset event object.
372 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
374 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
378 /******************************************************************************
379 * OpenBackupEventLogA [ADVAPI32.@]
381 * Opens a handle to a backup event log.
384 * lpUNCServerName [I] Universal Naming Convention name of the server on which
385 * this will be performed.
386 * lpFileName [I] Specifies the name of the backup file.
389 * Success: Handle to the backup event log.
392 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
394 LPWSTR uncnameW, filenameW;
397 uncnameW = SERV_dup(lpUNCServerName);
398 filenameW = SERV_dup(lpFileName);
399 handle = OpenBackupEventLogW(uncnameW, filenameW);
400 HeapFree(GetProcessHeap(), 0, uncnameW);
401 HeapFree(GetProcessHeap(), 0, filenameW);
406 /******************************************************************************
407 * OpenBackupEventLogW [ADVAPI32.@]
409 * See OpenBackupEventLogA.
411 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
413 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
417 SetLastError(ERROR_INVALID_PARAMETER);
421 if (lpUNCServerName && lpUNCServerName[0])
423 FIXME("Remote server not supported\n");
424 SetLastError(RPC_S_SERVER_UNAVAILABLE);
428 if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES)
430 SetLastError(ERROR_FILE_NOT_FOUND);
434 return (HANDLE)0xcafe4242;
437 /******************************************************************************
438 * OpenEventLogA [ADVAPI32.@]
440 * Opens a handle to the specified event log.
443 * lpUNCServerName [I] UNC name of the server on which the event log is
445 * lpSourceName [I] Name of the log.
448 * Success: Handle to an event log.
451 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
453 LPWSTR uncnameW, sourceW;
456 uncnameW = SERV_dup(uncname);
457 sourceW = SERV_dup(source);
458 handle = OpenEventLogW(uncnameW, sourceW);
459 HeapFree(GetProcessHeap(), 0, uncnameW);
460 HeapFree(GetProcessHeap(), 0, sourceW);
465 /******************************************************************************
466 * OpenEventLogW [ADVAPI32.@]
470 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
472 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
476 SetLastError(ERROR_INVALID_PARAMETER);
480 if (uncname && uncname[0])
482 FIXME("Remote server not supported\n");
483 SetLastError(RPC_S_SERVER_UNAVAILABLE);
487 return (HANDLE)0xcafe4242;
490 /******************************************************************************
491 * QueryAllTracesW [ADVAPI32.@]
493 * Query information for started event trace sessions
496 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
498 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
500 if (psessioncount) *psessioncount = 0;
501 return ERROR_SUCCESS;
504 /******************************************************************************
505 * QueryAllTracesA [ADVAPI32.@]
507 * See QueryAllTracesW.
509 ULONG WINAPI QueryAllTracesA( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
511 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
513 if (psessioncount) *psessioncount = 0;
514 return ERROR_SUCCESS;
517 /******************************************************************************
518 * ReadEventLogA [ADVAPI32.@]
520 * Reads a whole number of entries from an event log.
523 * hEventLog [I] Handle of the event log to read.
524 * dwReadFlags [I] see MSDN doc.
525 * dwRecordOffset [I] Log-entry record number to start at.
526 * lpBuffer [O] Buffer for the data read.
527 * nNumberOfBytesToRead [I] Size of lpBuffer.
528 * pnBytesRead [O] Receives number of bytes read.
529 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
536 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
537 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
539 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
540 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
544 /******************************************************************************
545 * ReadEventLogW [ADVAPI32.@]
549 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
550 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
552 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
553 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
557 /******************************************************************************
558 * RegisterEventSourceA [ADVAPI32.@]
560 * Returns a registered handle to an event log.
563 * lpUNCServerName [I] UNC name of the source server.
564 * lpSourceName [I] Specifies the name of the event source to retrieve.
567 * Success: Handle to the event log.
568 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
569 * Security event log.
571 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
573 UNICODE_STRING lpUNCServerNameW;
574 UNICODE_STRING lpSourceNameW;
577 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
579 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
580 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
581 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
582 RtlFreeUnicodeString (&lpUNCServerNameW);
583 RtlFreeUnicodeString (&lpSourceNameW);
587 /******************************************************************************
588 * RegisterEventSourceW [ADVAPI32.@]
590 * See RegisterEventSourceA.
592 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
594 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
595 return (HANDLE)0xcafe4242;
598 /******************************************************************************
599 * ReportEventA [ADVAPI32.@]
601 * Writes an entry at the end of an event log.
604 * hEventLog [I] Handle of an event log.
605 * wType [I] See MSDN doc.
606 * wCategory [I] Event category.
607 * dwEventID [I] Event identifier.
608 * lpUserSid [I] Current user's security identifier.
609 * wNumStrings [I] Number of insert strings in lpStrings.
610 * dwDataSize [I] Size of event-specific raw data to write.
611 * lpStrings [I] Buffer containing an array of string to be merged.
612 * lpRawData [I] Buffer containing the binary data.
615 * Success: nonzero. Entry was written to the log.
619 * The ReportEvent function adds the time, the entry's length, and the
620 * offsets before storing the entry in the log. If lpUserSid != NULL, the
621 * username is also logged.
623 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
624 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
626 LPWSTR *wideStrArray;
631 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
632 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
634 if (wNumStrings == 0) return TRUE;
635 if (!lpStrings) return TRUE;
637 wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR) * wNumStrings);
638 for (i = 0; i < wNumStrings; i++)
640 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
641 wideStrArray[i] = str.Buffer;
643 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
644 wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
645 for (i = 0; i < wNumStrings; i++)
647 HeapFree( GetProcessHeap(), 0, wideStrArray[i] );
649 HeapFree(GetProcessHeap(), 0, wideStrArray);
653 /******************************************************************************
654 * ReportEventW [ADVAPI32.@]
658 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
659 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
663 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
664 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
668 if (wNumStrings == 0) return TRUE;
669 if (!lpStrings) return TRUE;
671 for (i = 0; i < wNumStrings; i++)
675 case EVENTLOG_SUCCESS:
676 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
678 case EVENTLOG_ERROR_TYPE:
679 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
681 case EVENTLOG_WARNING_TYPE:
682 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
685 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
692 /******************************************************************************
693 * RegisterTraceGuidsW [ADVAPI32.@]
695 * Register an event trace provider and the event trace classes that it uses
696 * to generate events.
699 * RequestAddress [I] ControlCallback function
700 * RequestContext [I] Optional provider-defined context
701 * ControlGuid [I] GUID of the registering provider
702 * GuidCount [I] Number of elements in the TraceGuidReg array
703 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
704 * MofImagePath [I] not supported, set to NULL
705 * MofResourceNmae [I] not supported, set to NULL
706 * RegistrationHandle [O] Provider's registration handle
709 * Success: ERROR_SUCCESS
710 * Failure: System error code
715 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
716 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
717 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
718 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
720 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p,)\n", RequestAddress, RequestContext,
721 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
722 debugstr_w(MofResourceName), RegistrationHandle);
723 return ERROR_CALL_NOT_IMPLEMENTED;
726 /******************************************************************************
727 * RegisterTraceGuidsA [ADVAPI32.@]
729 * See RegisterTraceGuidsW.
734 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
735 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
736 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
737 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
739 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p,)\n", RequestAddress, RequestContext,
740 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
741 debugstr_a(MofResourceName), RegistrationHandle);
742 return ERROR_CALL_NOT_IMPLEMENTED;
745 /******************************************************************************
746 * StartTraceW [ADVAPI32.@]
748 * Register and start an event trace session
751 ULONG WINAPI StartTraceW( PTRACEHANDLE pSessionHandle, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
753 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_w(SessionName), Properties);
754 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
755 return ERROR_SUCCESS;
758 /******************************************************************************
759 * StartTraceA [ADVAPI32.@]
764 ULONG WINAPI StartTraceA( PTRACEHANDLE pSessionHandle, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
766 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_a(SessionName), Properties);
767 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
768 return ERROR_SUCCESS;
771 /******************************************************************************
772 * TraceEvent [ADVAPI32.@]
774 ULONG WINAPI TraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
776 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
777 return ERROR_CALL_NOT_IMPLEMENTED;
780 /******************************************************************************
781 * UnregisterTraceGuids [ADVAPI32.@]
783 * See RegisterTraceGuids
788 ULONG WINAPI UnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
790 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
791 return ERROR_CALL_NOT_IMPLEMENTED;