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 )
67 FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
71 /******************************************************************************
72 * BackupEventLogW [ADVAPI32.@]
74 * See BackupEventLogA.
76 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
78 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
82 /******************************************************************************
83 * ClearEventLogA [ADVAPI32.@]
85 * Clears the event log and/or saves the log to a backup file.
88 * hEvenLog [I] Handle to event log to clear.
89 * lpBackupFileName [I] Name of the backup file.
92 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
93 * contain the contents of hEvenLog and the log will be cleared.
94 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
97 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
99 FIXME("(%p,%s) stub\n", hEventLog, debugstr_a(lpBackupFileName));
103 /******************************************************************************
104 * ClearEventLogW [ADVAPI32.@]
106 * See ClearEventLogA.
108 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
110 FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
114 /******************************************************************************
115 * CloseEventLog [ADVAPI32.@]
117 * Closes a read handle to the event log.
120 * hEventLog [I/O] Handle of the event log to close.
126 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
128 FIXME("(%p) stub\n", hEventLog);
132 /******************************************************************************
133 * ControlTraceW [ADVAPI32.@]
135 * Control a givel event trace session
138 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
140 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
141 return ERROR_SUCCESS;
144 /******************************************************************************
145 * ControlTraceA [ADVAPI32.@]
150 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
152 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
153 return ERROR_SUCCESS;
156 /******************************************************************************
157 * DeregisterEventSource [ADVAPI32.@]
159 * Closes a write handle to an event log
162 * hEventLog [I/O] Handle of the event log.
168 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
170 FIXME("(%p) stub\n", hEventLog);
174 /******************************************************************************
175 * EnableTrace [ADVAPI32.@]
177 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
179 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
180 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
182 return ERROR_SUCCESS;
185 /******************************************************************************
186 * GetNumberOfEventLogRecords [ADVAPI32.@]
188 * Retrieves the number of records in an event log.
191 * hEventLog [I] Handle to an open event log.
192 * NumberOfRecords [O] Number of records in the log.
195 * Success: nonzero. NumberOfRecords will contain the number of records in
199 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
201 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
203 if (!NumberOfRecords) return FALSE;
204 *NumberOfRecords = 0;
209 /******************************************************************************
210 * GetOldestEventLogRecord [ADVAPI32.@]
212 * Retrieves the absolute record number of the oldest record in an even log.
215 * hEventLog [I] Handle to an open event log.
216 * OldestRecord [O] Absolute record number of the oldest record.
219 * Success: nonzero. OldestRecord contains the record number of the oldest
223 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
225 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
227 if (!OldestRecord) return FALSE;
233 /******************************************************************************
234 * NotifyChangeEventLog [ADVAPI32.@]
236 * Enables an application to receive notification when an event is written
240 * hEventLog [I] Handle to an event log.
241 * hEvent [I] Handle to a manual-reset event object.
247 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
249 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
253 /******************************************************************************
254 * OpenBackupEventLogA [ADVAPI32.@]
256 * Opens a handle to a backup event log.
259 * lpUNCServerName [I] Universal Naming Convention name of the server on which
260 * this will be performed.
261 * lpFileName [I] Specifies the name of the backup file.
264 * Success: Handle to the backup event log.
267 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
269 FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpFileName));
270 return (HANDLE)0xcafe4242;
273 /******************************************************************************
274 * OpenBackupEventLogW [ADVAPI32.@]
276 * See OpenBackupEventLogA.
278 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
280 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
281 return (HANDLE)0xcafe4242;
284 /******************************************************************************
285 * OpenEventLogA [ADVAPI32.@]
287 * Opens a handle to the specified event log.
290 * lpUNCServerName [I] UNC name of the server on which the event log is
292 * lpSourceName [I] Name of the log.
295 * Success: Handle to an event log.
298 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
300 LPWSTR uncnameW, sourceW;
303 uncnameW = SERV_dup(uncname);
304 sourceW = SERV_dup(source);
305 handle = OpenEventLogW(uncnameW, sourceW);
306 HeapFree(GetProcessHeap(), 0, uncnameW);
307 HeapFree(GetProcessHeap(), 0, sourceW);
312 /******************************************************************************
313 * OpenEventLogW [ADVAPI32.@]
317 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
319 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
323 SetLastError(ERROR_INVALID_PARAMETER);
327 if (uncname && uncname[0])
329 FIXME("Remote server not supported\n");
330 SetLastError(RPC_S_SERVER_UNAVAILABLE);
334 return (HANDLE)0xcafe4242;
337 /******************************************************************************
338 * QueryAllTracesW [ADVAPI32.@]
340 * Query informations for started event trace sessions
343 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
345 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
347 if (psessioncount) *psessioncount = 0;
348 return ERROR_SUCCESS;
351 /******************************************************************************
352 * QueryAllTracesA [ADVAPI32.@]
354 * See QueryAllTracesW.
356 ULONG WINAPI QueryAllTracesA( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
358 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
360 if (psessioncount) *psessioncount = 0;
361 return ERROR_SUCCESS;
364 /******************************************************************************
365 * ReadEventLogA [ADVAPI32.@]
367 * Reads a whole number of entries from an event log.
370 * hEventLog [I] Handle of the event log to read.
371 * dwReadFlags [I] see MSDN doc.
372 * dwRecordOffset [I] Log-entry record number to start at.
373 * lpBuffer [O] Buffer for the data read.
374 * nNumberOfBytesToRead [I] Size of lpBuffer.
375 * pnBytesRead [O] Receives number of bytes read.
376 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
383 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
384 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
386 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
387 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
391 /******************************************************************************
392 * ReadEventLogW [ADVAPI32.@]
396 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
397 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
399 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
400 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
404 /******************************************************************************
405 * RegisterEventSourceA [ADVAPI32.@]
407 * Returns a registered handle to an event log.
410 * lpUNCServerName [I] UNC name of the source server.
411 * lpSourceName [I] Specifies the name of the event source to retrieve.
414 * Success: Handle to the event log.
415 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
416 * Security event log.
418 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
420 UNICODE_STRING lpUNCServerNameW;
421 UNICODE_STRING lpSourceNameW;
424 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
426 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
427 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
428 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
429 RtlFreeUnicodeString (&lpUNCServerNameW);
430 RtlFreeUnicodeString (&lpSourceNameW);
434 /******************************************************************************
435 * RegisterEventSourceW [ADVAPI32.@]
437 * See RegisterEventSourceA.
439 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
441 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
442 return (HANDLE)0xcafe4242;
445 /******************************************************************************
446 * ReportEventA [ADVAPI32.@]
448 * Writes an entry at the end of an event log.
451 * hEventLog [I] Handle of an event log.
452 * wType [I] See MSDN doc.
453 * wCategory [I] Event category.
454 * dwEventID [I] Event identifier.
455 * lpUserSid [I] Current user's security identifier.
456 * wNumStrings [I] Number of insert strings in lpStrings.
457 * dwDataSize [I] Size of event-specific raw data to write.
458 * lpStrings [I] Buffer containing an array of string to be merged.
459 * lpRawData [I] Buffer containing the binary data.
462 * Success: nonzero. Entry was written to the log.
466 * The ReportEvent function adds the time, the entry's length, and the
467 * offsets before storing the entry in the log. If lpUserSid != NULL, the
468 * username is also logged.
470 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
471 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
473 LPWSTR *wideStrArray;
478 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
479 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
481 if (wNumStrings == 0) return TRUE;
482 if (!lpStrings) return TRUE;
484 wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR) * wNumStrings);
485 for (i = 0; i < wNumStrings; i++)
487 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
488 wideStrArray[i] = str.Buffer;
490 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
491 wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
492 for (i = 0; i < wNumStrings; i++)
494 HeapFree( GetProcessHeap(), 0, wideStrArray[i] );
496 HeapFree(GetProcessHeap(), 0, wideStrArray);
500 /******************************************************************************
501 * ReportEventW [ADVAPI32.@]
505 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
506 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
510 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
511 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
515 if (wNumStrings == 0) return TRUE;
516 if (!lpStrings) return TRUE;
518 for (i = 0; i < wNumStrings; i++)
522 case EVENTLOG_SUCCESS:
523 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
525 case EVENTLOG_ERROR_TYPE:
526 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
528 case EVENTLOG_WARNING_TYPE:
529 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
532 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
539 /******************************************************************************
540 * RegisterTraceGuidsW [ADVAPI32.@]
542 * Register an event trace provider and the event trace classes that it uses
543 * to generate events.
546 * RequestAddress [I] ControlCallback function
547 * RequestContext [I] Optional provider-defined context
548 * ControlGuid [I] GUID of the registering provider
549 * GuidCount [I] Number of elements in the TraceGuidReg array
550 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
551 * MofImagePath [I] not supported, set to NULL
552 * MofResourceNmae [I] not supported, set to NULL
553 * RegistrationHandle [O] Provider's registration handle
556 * Success: ERROR_SUCCESS
557 * Failure: System error code
562 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
563 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
564 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
565 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
567 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress, RequestContext,
568 ControlGuid, GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
569 debugstr_w(MofResourceName), RegistrationHandle);
570 return ERROR_CALL_NOT_IMPLEMENTED;
573 /******************************************************************************
574 * RegisterTraceGuidsA [ADVAPI32.@]
576 * See RegisterTraceGuidsW.
581 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
582 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
583 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
584 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
586 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress, RequestContext,
587 ControlGuid, GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
588 debugstr_a(MofResourceName), RegistrationHandle);
589 return ERROR_CALL_NOT_IMPLEMENTED;
592 /******************************************************************************
593 * StartTraceW [ADVAPI32.@]
595 * Register and start an event trace session
598 ULONG WINAPI StartTraceW( PTRACEHANDLE pSessionHandle, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
600 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_w(SessionName), Properties);
601 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
602 return ERROR_SUCCESS;
605 /******************************************************************************
606 * StartTraceA [ADVAPI32.@]
611 ULONG WINAPI StartTraceA( PTRACEHANDLE pSessionHandle, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
613 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_a(SessionName), Properties);
614 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
615 return ERROR_SUCCESS;
618 /******************************************************************************
619 * TraceEvent [ADVAPI32.@]
621 ULONG WINAPI TraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
623 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
624 return ERROR_CALL_NOT_IMPLEMENTED;
627 /******************************************************************************
628 * UnregisterTraceGuids [ADVAPI32.@]
630 * See RegisterTraceGuids
635 ULONG WINAPI UnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
637 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
638 return ERROR_CALL_NOT_IMPLEMENTED;