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 SetLastError(ERROR_INVALID_HANDLE);
139 /******************************************************************************
140 * ControlTraceW [ADVAPI32.@]
142 * Control a givel event trace session
145 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
147 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
148 return ERROR_SUCCESS;
151 /******************************************************************************
152 * ControlTraceA [ADVAPI32.@]
157 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
159 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
160 return ERROR_SUCCESS;
163 /******************************************************************************
164 * DeregisterEventSource [ADVAPI32.@]
166 * Closes a write handle to an event log
169 * hEventLog [I/O] Handle of the event log.
175 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
177 FIXME("(%p) stub\n", hEventLog);
181 /******************************************************************************
182 * EnableTrace [ADVAPI32.@]
184 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
186 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
187 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
189 return ERROR_SUCCESS;
192 /******************************************************************************
193 * GetNumberOfEventLogRecords [ADVAPI32.@]
195 * Retrieves the number of records in an event log.
198 * hEventLog [I] Handle to an open event log.
199 * NumberOfRecords [O] Number of records in the log.
202 * Success: nonzero. NumberOfRecords will contain the number of records in
206 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
208 FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
210 if (!NumberOfRecords) return FALSE;
211 *NumberOfRecords = 0;
216 /******************************************************************************
217 * GetOldestEventLogRecord [ADVAPI32.@]
219 * Retrieves the absolute record number of the oldest record in an even log.
222 * hEventLog [I] Handle to an open event log.
223 * OldestRecord [O] Absolute record number of the oldest record.
226 * Success: nonzero. OldestRecord contains the record number of the oldest
230 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
232 FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
234 if (!OldestRecord) return FALSE;
240 /******************************************************************************
241 * NotifyChangeEventLog [ADVAPI32.@]
243 * Enables an application to receive notification when an event is written
247 * hEventLog [I] Handle to an event log.
248 * hEvent [I] Handle to a manual-reset event object.
254 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
256 FIXME("(%p,%p) stub\n", hEventLog, hEvent);
260 /******************************************************************************
261 * OpenBackupEventLogA [ADVAPI32.@]
263 * Opens a handle to a backup event log.
266 * lpUNCServerName [I] Universal Naming Convention name of the server on which
267 * this will be performed.
268 * lpFileName [I] Specifies the name of the backup file.
271 * Success: Handle to the backup event log.
274 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
276 FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpFileName));
277 return (HANDLE)0xcafe4242;
280 /******************************************************************************
281 * OpenBackupEventLogW [ADVAPI32.@]
283 * See OpenBackupEventLogA.
285 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
287 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
288 return (HANDLE)0xcafe4242;
291 /******************************************************************************
292 * OpenEventLogA [ADVAPI32.@]
294 * Opens a handle to the specified event log.
297 * lpUNCServerName [I] UNC name of the server on which the event log is
299 * lpSourceName [I] Name of the log.
302 * Success: Handle to an event log.
305 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
307 LPWSTR uncnameW, sourceW;
310 uncnameW = SERV_dup(uncname);
311 sourceW = SERV_dup(source);
312 handle = OpenEventLogW(uncnameW, sourceW);
313 HeapFree(GetProcessHeap(), 0, uncnameW);
314 HeapFree(GetProcessHeap(), 0, sourceW);
319 /******************************************************************************
320 * OpenEventLogW [ADVAPI32.@]
324 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
326 FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
330 SetLastError(ERROR_INVALID_PARAMETER);
334 if (uncname && uncname[0])
336 FIXME("Remote server not supported\n");
337 SetLastError(RPC_S_SERVER_UNAVAILABLE);
341 return (HANDLE)0xcafe4242;
344 /******************************************************************************
345 * QueryAllTracesW [ADVAPI32.@]
347 * Query informations for started event trace sessions
350 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
352 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
354 if (psessioncount) *psessioncount = 0;
355 return ERROR_SUCCESS;
358 /******************************************************************************
359 * QueryAllTracesA [ADVAPI32.@]
361 * See QueryAllTracesW.
363 ULONG WINAPI QueryAllTracesA( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
365 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
367 if (psessioncount) *psessioncount = 0;
368 return ERROR_SUCCESS;
371 /******************************************************************************
372 * ReadEventLogA [ADVAPI32.@]
374 * Reads a whole number of entries from an event log.
377 * hEventLog [I] Handle of the event log to read.
378 * dwReadFlags [I] see MSDN doc.
379 * dwRecordOffset [I] Log-entry record number to start at.
380 * lpBuffer [O] Buffer for the data read.
381 * nNumberOfBytesToRead [I] Size of lpBuffer.
382 * pnBytesRead [O] Receives number of bytes read.
383 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
390 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
391 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
393 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
394 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
398 /******************************************************************************
399 * ReadEventLogW [ADVAPI32.@]
403 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
404 LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
406 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
407 dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
411 /******************************************************************************
412 * RegisterEventSourceA [ADVAPI32.@]
414 * Returns a registered handle to an event log.
417 * lpUNCServerName [I] UNC name of the source server.
418 * lpSourceName [I] Specifies the name of the event source to retrieve.
421 * Success: Handle to the event log.
422 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
423 * Security event log.
425 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
427 UNICODE_STRING lpUNCServerNameW;
428 UNICODE_STRING lpSourceNameW;
431 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
433 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
434 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
435 ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
436 RtlFreeUnicodeString (&lpUNCServerNameW);
437 RtlFreeUnicodeString (&lpSourceNameW);
441 /******************************************************************************
442 * RegisterEventSourceW [ADVAPI32.@]
444 * See RegisterEventSourceA.
446 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
448 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
449 return (HANDLE)0xcafe4242;
452 /******************************************************************************
453 * ReportEventA [ADVAPI32.@]
455 * Writes an entry at the end of an event log.
458 * hEventLog [I] Handle of an event log.
459 * wType [I] See MSDN doc.
460 * wCategory [I] Event category.
461 * dwEventID [I] Event identifier.
462 * lpUserSid [I] Current user's security identifier.
463 * wNumStrings [I] Number of insert strings in lpStrings.
464 * dwDataSize [I] Size of event-specific raw data to write.
465 * lpStrings [I] Buffer containing an array of string to be merged.
466 * lpRawData [I] Buffer containing the binary data.
469 * Success: nonzero. Entry was written to the log.
473 * The ReportEvent function adds the time, the entry's length, and the
474 * offsets before storing the entry in the log. If lpUserSid != NULL, the
475 * username is also logged.
477 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
478 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
480 LPWSTR *wideStrArray;
485 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
486 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
488 if (wNumStrings == 0) return TRUE;
489 if (!lpStrings) return TRUE;
491 wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR) * wNumStrings);
492 for (i = 0; i < wNumStrings; i++)
494 RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
495 wideStrArray[i] = str.Buffer;
497 ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
498 wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
499 for (i = 0; i < wNumStrings; i++)
501 HeapFree( GetProcessHeap(), 0, wideStrArray[i] );
503 HeapFree(GetProcessHeap(), 0, wideStrArray);
507 /******************************************************************************
508 * ReportEventW [ADVAPI32.@]
512 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
513 PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
517 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
518 wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
522 if (wNumStrings == 0) return TRUE;
523 if (!lpStrings) return TRUE;
525 for (i = 0; i < wNumStrings; i++)
529 case EVENTLOG_SUCCESS:
530 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
532 case EVENTLOG_ERROR_TYPE:
533 ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
535 case EVENTLOG_WARNING_TYPE:
536 WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
539 TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
546 /******************************************************************************
547 * RegisterTraceGuidsW [ADVAPI32.@]
549 * Register an event trace provider and the event trace classes that it uses
550 * to generate events.
553 * RequestAddress [I] ControlCallback function
554 * RequestContext [I] Optional provider-defined context
555 * ControlGuid [I] GUID of the registering provider
556 * GuidCount [I] Number of elements in the TraceGuidReg array
557 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
558 * MofImagePath [I] not supported, set to NULL
559 * MofResourceNmae [I] not supported, set to NULL
560 * RegistrationHandle [O] Provider's registration handle
563 * Success: ERROR_SUCCESS
564 * Failure: System error code
569 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
570 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
571 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
572 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
574 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress, RequestContext,
575 ControlGuid, GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
576 debugstr_w(MofResourceName), RegistrationHandle);
577 return ERROR_CALL_NOT_IMPLEMENTED;
580 /******************************************************************************
581 * RegisterTraceGuidsA [ADVAPI32.@]
583 * See RegisterTraceGuidsW.
588 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
589 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
590 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
591 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
593 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress, RequestContext,
594 ControlGuid, GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
595 debugstr_a(MofResourceName), RegistrationHandle);
596 return ERROR_CALL_NOT_IMPLEMENTED;
599 /******************************************************************************
600 * StartTraceW [ADVAPI32.@]
602 * Register and start an event trace session
605 ULONG WINAPI StartTraceW( PTRACEHANDLE pSessionHandle, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
607 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_w(SessionName), Properties);
608 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
609 return ERROR_SUCCESS;
612 /******************************************************************************
613 * StartTraceA [ADVAPI32.@]
618 ULONG WINAPI StartTraceA( PTRACEHANDLE pSessionHandle, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
620 FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_a(SessionName), Properties);
621 if (pSessionHandle) *pSessionHandle = 0xcafe4242;
622 return ERROR_SUCCESS;
625 /******************************************************************************
626 * TraceEvent [ADVAPI32.@]
628 ULONG WINAPI TraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
630 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
631 return ERROR_CALL_NOT_IMPLEMENTED;
634 /******************************************************************************
635 * UnregisterTraceGuids [ADVAPI32.@]
637 * See RegisterTraceGuids
642 ULONG WINAPI UnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
644 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
645 return ERROR_CALL_NOT_IMPLEMENTED;