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/or 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 )
124 FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
128 /******************************************************************************
129 * ClearEventLogW [ADVAPI32.@]
131 * See ClearEventLogA.
133 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
135 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
139 /******************************************************************************
140 * CloseEventLog [ADVAPI32.@]
142 * Closes a read handle to the event log.
145 * hEventLog [I/O] Handle of the event log to close.
151 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
153 FIXME("(%p) stub\n", hEventLog);
157 SetLastError(ERROR_INVALID_HANDLE);
164 /******************************************************************************
165 * ControlTraceW [ADVAPI32.@]
167 * Control a givel event trace session
170 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
172 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
173 return ERROR_SUCCESS;
176 /******************************************************************************
177 * ControlTraceA [ADVAPI32.@]
182 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
184 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
185 return ERROR_SUCCESS;
188 /******************************************************************************
189 * DeregisterEventSource [ADVAPI32.@]
191 * Closes a write handle to an event log
194 * hEventLog [I/O] Handle of the event log.
200 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
202 FIXME("(%p) stub\n", hEventLog);
206 /******************************************************************************
207 * EnableTrace [ADVAPI32.@]
209 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
211 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
212 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
214 return ERROR_SUCCESS;
217 /******************************************************************************
218 * GetEventLogInformation [ADVAPI32.@]
220 * Retrieve some information about an event log.
223 * hEventLog [I] Handle to an open event log.
224 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
225 * lpBuffer [I/O] The buffer for the returned information
226 * cbBufSize [I] The size of the buffer
227 * pcbBytesNeeded [O] The needed bytes to hold the information
230 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
231 * the needed buffer size.
234 BOOL WINAPI GetEventLogInformation( HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
236 EVENTLOG_FULL_INFORMATION *efi;
238 FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
240 if (dwInfoLevel != EVENTLOG_FULL_INFO)
242 SetLastError(ERROR_INVALID_LEVEL);
248 SetLastError(ERROR_INVALID_HANDLE);
252 if (!lpBuffer || !pcbBytesNeeded)
254 /* FIXME: This will be handled properly when eventlog is moved
257 SetLastError(RPC_X_NULL_REF_POINTER);
261 *pcbBytesNeeded = sizeof(EVENTLOG_FULL_INFORMATION);
262 if (cbBufSize < sizeof(EVENTLOG_FULL_INFORMATION))
264 SetLastError(ERROR_INSUFFICIENT_BUFFER);
268 /* Pretend the log is not full */
269 efi = (EVENTLOG_FULL_INFORMATION *)lpBuffer;
275 /******************************************************************************
276 * GetNumberOfEventLogRecords [ADVAPI32.@]
278 * Retrieves the number of records in an event log.
281 * hEventLog [I] Handle to an open event log.
282 * NumberOfRecords [O] Number of records in the log.
285 * Success: nonzero. NumberOfRecords will contain the number of records in
289 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
291 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
293 if (!NumberOfRecords)
295 SetLastError(ERROR_INVALID_PARAMETER);
301 SetLastError(ERROR_INVALID_HANDLE);
305 *NumberOfRecords = 0;
310 /******************************************************************************
311 * GetOldestEventLogRecord [ADVAPI32.@]
313 * Retrieves the absolute record number of the oldest record in an even log.
316 * hEventLog [I] Handle to an open event log.
317 * OldestRecord [O] Absolute record number of the oldest record.
320 * Success: nonzero. OldestRecord contains the record number of the oldest
324 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
326 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
330 SetLastError(ERROR_INVALID_PARAMETER);
336 SetLastError(ERROR_INVALID_HANDLE);
345 /******************************************************************************
346 * NotifyChangeEventLog [ADVAPI32.@]
348 * Enables an application to receive notification when an event is written
352 * hEventLog [I] Handle to an event log.
353 * hEvent [I] Handle to a manual-reset event object.
359 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
361 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
365 /******************************************************************************
366 * OpenBackupEventLogA [ADVAPI32.@]
368 * Opens a handle to a backup event log.
371 * lpUNCServerName [I] Universal Naming Convention name of the server on which
372 * this will be performed.
373 * lpFileName [I] Specifies the name of the backup file.
376 * Success: Handle to the backup event log.
379 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
381 LPWSTR uncnameW, filenameW;
384 uncnameW = SERV_dup(lpUNCServerName);
385 filenameW = SERV_dup(lpFileName);
386 handle = OpenBackupEventLogW(uncnameW, filenameW);
387 HeapFree(GetProcessHeap(), 0, uncnameW);
388 HeapFree(GetProcessHeap(), 0, filenameW);
393 /******************************************************************************
394 * OpenBackupEventLogW [ADVAPI32.@]
396 * See OpenBackupEventLogA.
398 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
400 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
404 SetLastError(ERROR_INVALID_PARAMETER);
408 if (lpUNCServerName && lpUNCServerName[0])
410 FIXME("Remote server not supported\n");
411 SetLastError(RPC_S_SERVER_UNAVAILABLE);
415 if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES)
417 SetLastError(ERROR_FILE_NOT_FOUND);
421 return (HANDLE)0xcafe4242;
424 /******************************************************************************
425 * OpenEventLogA [ADVAPI32.@]
427 * Opens a handle to the specified event log.
430 * lpUNCServerName [I] UNC name of the server on which the event log is
432 * lpSourceName [I] Name of the log.
435 * Success: Handle to an event log.
438 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
440 LPWSTR uncnameW, sourceW;
443 uncnameW = SERV_dup(uncname);
444 sourceW = SERV_dup(source);
445 handle = OpenEventLogW(uncnameW, sourceW);
446 HeapFree(GetProcessHeap(), 0, uncnameW);
447 HeapFree(GetProcessHeap(), 0, sourceW);
452 /******************************************************************************
453 * OpenEventLogW [ADVAPI32.@]
457 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
459 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
463 SetLastError(ERROR_INVALID_PARAMETER);
467 if (uncname && uncname[0])
469 FIXME("Remote server not supported\n");
470 SetLastError(RPC_S_SERVER_UNAVAILABLE);
474 return (HANDLE)0xcafe4242;
477 /******************************************************************************
478 * QueryAllTracesW [ADVAPI32.@]
480 * Query informations for started event trace sessions
483 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
485 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
487 if (psessioncount) *psessioncount = 0;
488 return ERROR_SUCCESS;
491 /******************************************************************************
492 * QueryAllTracesA [ADVAPI32.@]
494 * See QueryAllTracesW.
496 ULONG WINAPI QueryAllTracesA( 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 * ReadEventLogA [ADVAPI32.@]
507 * Reads a whole number of entries from an event log.
510 * hEventLog [I] Handle of the event log to read.
511 * dwReadFlags [I] see MSDN doc.
512 * dwRecordOffset [I] Log-entry record number to start at.
513 * lpBuffer [O] Buffer for the data read.
514 * nNumberOfBytesToRead [I] Size of lpBuffer.
515 * pnBytesRead [O] Receives number of bytes read.
516 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
523 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
524 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
526 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
527 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
531 /******************************************************************************
532 * ReadEventLogW [ADVAPI32.@]
536 BOOL WINAPI ReadEventLogW( 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 * RegisterEventSourceA [ADVAPI32.@]
547 * Returns a registered handle to an event log.
550 * lpUNCServerName [I] UNC name of the source server.
551 * lpSourceName [I] Specifies the name of the event source to retrieve.
554 * Success: Handle to the event log.
555 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
556 * Security event log.
558 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
560 UNICODE_STRING lpUNCServerNameW;
561 UNICODE_STRING lpSourceNameW;
564 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
566 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
567 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
568 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
569 RtlFreeUnicodeString (&lpUNCServerNameW);
570 RtlFreeUnicodeString (&lpSourceNameW);
574 /******************************************************************************
575 * RegisterEventSourceW [ADVAPI32.@]
577 * See RegisterEventSourceA.
579 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
581 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
582 return (HANDLE)0xcafe4242;
585 /******************************************************************************
586 * ReportEventA [ADVAPI32.@]
588 * Writes an entry at the end of an event log.
591 * hEventLog [I] Handle of an event log.
592 * wType [I] See MSDN doc.
593 * wCategory [I] Event category.
594 * dwEventID [I] Event identifier.
595 * lpUserSid [I] Current user's security identifier.
596 * wNumStrings [I] Number of insert strings in lpStrings.
597 * dwDataSize [I] Size of event-specific raw data to write.
598 * lpStrings [I] Buffer containing an array of string to be merged.
599 * lpRawData [I] Buffer containing the binary data.
602 * Success: nonzero. Entry was written to the log.
606 * The ReportEvent function adds the time, the entry's length, and the
607 * offsets before storing the entry in the log. If lpUserSid != NULL, the
608 * username is also logged.
610 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
611 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
613 LPWSTR *wideStrArray;
618 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
619 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
621 if (wNumStrings == 0) return TRUE;
622 if (!lpStrings) return TRUE;
624 wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR) * wNumStrings);
625 for (i = 0; i < wNumStrings; i++)
627 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
628 wideStrArray[i] = str.Buffer;
630 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
631 wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
632 for (i = 0; i < wNumStrings; i++)
634 HeapFree( GetProcessHeap(), 0, wideStrArray[i] );
636 HeapFree(GetProcessHeap(), 0, wideStrArray);
640 /******************************************************************************
641 * ReportEventW [ADVAPI32.@]
645 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
646 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
650 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
651 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
655 if (wNumStrings == 0) return TRUE;
656 if (!lpStrings) return TRUE;
658 for (i = 0; i < wNumStrings; i++)
662 case EVENTLOG_SUCCESS:
663 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
665 case EVENTLOG_ERROR_TYPE:
666 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
668 case EVENTLOG_WARNING_TYPE:
669 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
672 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
679 /******************************************************************************
680 * RegisterTraceGuidsW [ADVAPI32.@]
682 * Register an event trace provider and the event trace classes that it uses
683 * to generate events.
686 * RequestAddress [I] ControlCallback function
687 * RequestContext [I] Optional provider-defined context
688 * ControlGuid [I] GUID of the registering provider
689 * GuidCount [I] Number of elements in the TraceGuidReg array
690 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
691 * MofImagePath [I] not supported, set to NULL
692 * MofResourceNmae [I] not supported, set to NULL
693 * RegistrationHandle [O] Provider's registration handle
696 * Success: ERROR_SUCCESS
697 * Failure: System error code
702 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
703 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
704 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
705 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
707 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress, RequestContext,
708 ControlGuid, GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
709 debugstr_w(MofResourceName), RegistrationHandle);
710 return ERROR_CALL_NOT_IMPLEMENTED;
713 /******************************************************************************
714 * RegisterTraceGuidsA [ADVAPI32.@]
716 * See RegisterTraceGuidsW.
721 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
722 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
723 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
724 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
726 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress, RequestContext,
727 ControlGuid, GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
728 debugstr_a(MofResourceName), RegistrationHandle);
729 return ERROR_CALL_NOT_IMPLEMENTED;
732 /******************************************************************************
733 * StartTraceW [ADVAPI32.@]
735 * Register and start an event trace session
738 ULONG WINAPI StartTraceW( PTRACEHANDLE pSessionHandle, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
740 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_w(SessionName), Properties);
741 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
742 return ERROR_SUCCESS;
745 /******************************************************************************
746 * StartTraceA [ADVAPI32.@]
751 ULONG WINAPI StartTraceA( PTRACEHANDLE pSessionHandle, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
753 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_a(SessionName), Properties);
754 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
755 return ERROR_SUCCESS;
758 /******************************************************************************
759 * TraceEvent [ADVAPI32.@]
761 ULONG WINAPI TraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
763 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
764 return ERROR_CALL_NOT_IMPLEMENTED;
767 /******************************************************************************
768 * UnregisterTraceGuids [ADVAPI32.@]
770 * See RegisterTraceGuids
775 ULONG WINAPI UnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
777 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
778 return ERROR_CALL_NOT_IMPLEMENTED;