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 * GetEventLogInformation [ADVAPI32.@]
195 * Retrieve some information about an event log.
198 * hEventLog [I] Handle to an open event log.
199 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
200 * lpBuffer [I/O] The buffer for the returned information
201 * cbBufSize [I] The size of the buffer
202 * pcbBytesNeeded [O] The needed bytes to hold the information
205 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
206 * the needed buffer size.
209 BOOL WINAPI
GetEventLogInformation( HANDLE hEventLog
, DWORD dwInfoLevel
, LPVOID lpBuffer
, DWORD cbBufSize
, LPDWORD pcbBytesNeeded
)
211 EVENTLOG_FULL_INFORMATION
*efi
;
213 FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
215 if (dwInfoLevel
!= EVENTLOG_FULL_INFO
)
217 SetLastError(ERROR_INVALID_LEVEL
);
223 SetLastError(ERROR_INVALID_HANDLE
);
227 if (!lpBuffer
|| !pcbBytesNeeded
)
229 /* FIXME: This will be handled properly when eventlog is moved
232 SetLastError(RPC_X_NULL_REF_POINTER
);
236 *pcbBytesNeeded
= sizeof(EVENTLOG_FULL_INFORMATION
);
237 if (cbBufSize
< sizeof(EVENTLOG_FULL_INFORMATION
))
239 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
243 /* Pretend the log is not full */
244 efi
= (EVENTLOG_FULL_INFORMATION
*)lpBuffer
;
250 /******************************************************************************
251 * GetNumberOfEventLogRecords [ADVAPI32.@]
253 * Retrieves the number of records in an event log.
256 * hEventLog [I] Handle to an open event log.
257 * NumberOfRecords [O] Number of records in the log.
260 * Success: nonzero. NumberOfRecords will contain the number of records in
264 BOOL WINAPI
GetNumberOfEventLogRecords( HANDLE hEventLog
, PDWORD NumberOfRecords
)
266 FIXME("(%p,%p) stub\n", hEventLog
, NumberOfRecords
);
268 if (!NumberOfRecords
)
270 SetLastError(ERROR_INVALID_PARAMETER
);
276 SetLastError(ERROR_INVALID_HANDLE
);
280 *NumberOfRecords
= 0;
285 /******************************************************************************
286 * GetOldestEventLogRecord [ADVAPI32.@]
288 * Retrieves the absolute record number of the oldest record in an even log.
291 * hEventLog [I] Handle to an open event log.
292 * OldestRecord [O] Absolute record number of the oldest record.
295 * Success: nonzero. OldestRecord contains the record number of the oldest
299 BOOL WINAPI
GetOldestEventLogRecord( HANDLE hEventLog
, PDWORD OldestRecord
)
301 FIXME("(%p,%p) stub\n", hEventLog
, OldestRecord
);
305 SetLastError(ERROR_INVALID_PARAMETER
);
311 SetLastError(ERROR_INVALID_HANDLE
);
320 /******************************************************************************
321 * NotifyChangeEventLog [ADVAPI32.@]
323 * Enables an application to receive notification when an event is written
327 * hEventLog [I] Handle to an event log.
328 * hEvent [I] Handle to a manual-reset event object.
334 BOOL WINAPI
NotifyChangeEventLog( HANDLE hEventLog
, HANDLE hEvent
)
336 FIXME("(%p,%p) stub\n", hEventLog
, hEvent
);
340 /******************************************************************************
341 * OpenBackupEventLogA [ADVAPI32.@]
343 * Opens a handle to a backup event log.
346 * lpUNCServerName [I] Universal Naming Convention name of the server on which
347 * this will be performed.
348 * lpFileName [I] Specifies the name of the backup file.
351 * Success: Handle to the backup event log.
354 HANDLE WINAPI
OpenBackupEventLogA( LPCSTR lpUNCServerName
, LPCSTR lpFileName
)
356 FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName
), debugstr_a(lpFileName
));
357 return (HANDLE
)0xcafe4242;
360 /******************************************************************************
361 * OpenBackupEventLogW [ADVAPI32.@]
363 * See OpenBackupEventLogA.
365 HANDLE WINAPI
OpenBackupEventLogW( LPCWSTR lpUNCServerName
, LPCWSTR lpFileName
)
367 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpFileName
));
368 return (HANDLE
)0xcafe4242;
371 /******************************************************************************
372 * OpenEventLogA [ADVAPI32.@]
374 * Opens a handle to the specified event log.
377 * lpUNCServerName [I] UNC name of the server on which the event log is
379 * lpSourceName [I] Name of the log.
382 * Success: Handle to an event log.
385 HANDLE WINAPI
OpenEventLogA( LPCSTR uncname
, LPCSTR source
)
387 LPWSTR uncnameW
, sourceW
;
390 uncnameW
= SERV_dup(uncname
);
391 sourceW
= SERV_dup(source
);
392 handle
= OpenEventLogW(uncnameW
, sourceW
);
393 HeapFree(GetProcessHeap(), 0, uncnameW
);
394 HeapFree(GetProcessHeap(), 0, sourceW
);
399 /******************************************************************************
400 * OpenEventLogW [ADVAPI32.@]
404 HANDLE WINAPI
OpenEventLogW( LPCWSTR uncname
, LPCWSTR source
)
406 FIXME("(%s,%s) stub\n", debugstr_w(uncname
), debugstr_w(source
));
410 SetLastError(ERROR_INVALID_PARAMETER
);
414 if (uncname
&& uncname
[0])
416 FIXME("Remote server not supported\n");
417 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
421 return (HANDLE
)0xcafe4242;
424 /******************************************************************************
425 * QueryAllTracesW [ADVAPI32.@]
427 * Query informations for started event trace sessions
430 ULONG WINAPI
QueryAllTracesW( PEVENT_TRACE_PROPERTIES
* parray
, ULONG arraycount
, PULONG psessioncount
)
432 FIXME("(%p, %d, %p) stub\n", parray
, arraycount
, psessioncount
);
434 if (psessioncount
) *psessioncount
= 0;
435 return ERROR_SUCCESS
;
438 /******************************************************************************
439 * QueryAllTracesA [ADVAPI32.@]
441 * See QueryAllTracesW.
443 ULONG WINAPI
QueryAllTracesA( PEVENT_TRACE_PROPERTIES
* parray
, ULONG arraycount
, PULONG psessioncount
)
445 FIXME("(%p, %d, %p) stub\n", parray
, arraycount
, psessioncount
);
447 if (psessioncount
) *psessioncount
= 0;
448 return ERROR_SUCCESS
;
451 /******************************************************************************
452 * ReadEventLogA [ADVAPI32.@]
454 * Reads a whole number of entries from an event log.
457 * hEventLog [I] Handle of the event log to read.
458 * dwReadFlags [I] see MSDN doc.
459 * dwRecordOffset [I] Log-entry record number to start at.
460 * lpBuffer [O] Buffer for the data read.
461 * nNumberOfBytesToRead [I] Size of lpBuffer.
462 * pnBytesRead [O] Receives number of bytes read.
463 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
470 BOOL WINAPI
ReadEventLogA( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
471 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
473 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog
, dwReadFlags
,
474 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
478 /******************************************************************************
479 * ReadEventLogW [ADVAPI32.@]
483 BOOL WINAPI
ReadEventLogW( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
484 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
486 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog
, dwReadFlags
,
487 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
491 /******************************************************************************
492 * RegisterEventSourceA [ADVAPI32.@]
494 * Returns a registered handle to an event log.
497 * lpUNCServerName [I] UNC name of the source server.
498 * lpSourceName [I] Specifies the name of the event source to retrieve.
501 * Success: Handle to the event log.
502 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
503 * Security event log.
505 HANDLE WINAPI
RegisterEventSourceA( LPCSTR lpUNCServerName
, LPCSTR lpSourceName
)
507 UNICODE_STRING lpUNCServerNameW
;
508 UNICODE_STRING lpSourceNameW
;
511 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName
), debugstr_a(lpSourceName
));
513 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW
, lpUNCServerName
);
514 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW
, lpSourceName
);
515 ret
= RegisterEventSourceW(lpUNCServerNameW
.Buffer
,lpSourceNameW
.Buffer
);
516 RtlFreeUnicodeString (&lpUNCServerNameW
);
517 RtlFreeUnicodeString (&lpSourceNameW
);
521 /******************************************************************************
522 * RegisterEventSourceW [ADVAPI32.@]
524 * See RegisterEventSourceA.
526 HANDLE WINAPI
RegisterEventSourceW( LPCWSTR lpUNCServerName
, LPCWSTR lpSourceName
)
528 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpSourceName
));
529 return (HANDLE
)0xcafe4242;
532 /******************************************************************************
533 * ReportEventA [ADVAPI32.@]
535 * Writes an entry at the end of an event log.
538 * hEventLog [I] Handle of an event log.
539 * wType [I] See MSDN doc.
540 * wCategory [I] Event category.
541 * dwEventID [I] Event identifier.
542 * lpUserSid [I] Current user's security identifier.
543 * wNumStrings [I] Number of insert strings in lpStrings.
544 * dwDataSize [I] Size of event-specific raw data to write.
545 * lpStrings [I] Buffer containing an array of string to be merged.
546 * lpRawData [I] Buffer containing the binary data.
549 * Success: nonzero. Entry was written to the log.
553 * The ReportEvent function adds the time, the entry's length, and the
554 * offsets before storing the entry in the log. If lpUserSid != NULL, the
555 * username is also logged.
557 BOOL WINAPI
ReportEventA ( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
558 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCSTR
*lpStrings
, LPVOID lpRawData
)
560 LPWSTR
*wideStrArray
;
565 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog
,
566 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
568 if (wNumStrings
== 0) return TRUE
;
569 if (!lpStrings
) return TRUE
;
571 wideStrArray
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR
) * wNumStrings
);
572 for (i
= 0; i
< wNumStrings
; i
++)
574 RtlCreateUnicodeStringFromAsciiz(&str
, lpStrings
[i
]);
575 wideStrArray
[i
] = str
.Buffer
;
577 ret
= ReportEventW(hEventLog
, wType
, wCategory
, dwEventID
, lpUserSid
,
578 wNumStrings
, dwDataSize
, (LPCWSTR
*)wideStrArray
, lpRawData
);
579 for (i
= 0; i
< wNumStrings
; i
++)
581 HeapFree( GetProcessHeap(), 0, wideStrArray
[i
] );
583 HeapFree(GetProcessHeap(), 0, wideStrArray
);
587 /******************************************************************************
588 * ReportEventW [ADVAPI32.@]
592 BOOL WINAPI
ReportEventW( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
593 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCWSTR
*lpStrings
, LPVOID lpRawData
)
597 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog
,
598 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
602 if (wNumStrings
== 0) return TRUE
;
603 if (!lpStrings
) return TRUE
;
605 for (i
= 0; i
< wNumStrings
; i
++)
609 case EVENTLOG_SUCCESS
:
610 TRACE_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
612 case EVENTLOG_ERROR_TYPE
:
613 ERR_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
615 case EVENTLOG_WARNING_TYPE
:
616 WARN_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
619 TRACE_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
626 /******************************************************************************
627 * RegisterTraceGuidsW [ADVAPI32.@]
629 * Register an event trace provider and the event trace classes that it uses
630 * to generate events.
633 * RequestAddress [I] ControlCallback function
634 * RequestContext [I] Optional provider-defined context
635 * ControlGuid [I] GUID of the registering provider
636 * GuidCount [I] Number of elements in the TraceGuidReg array
637 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
638 * MofImagePath [I] not supported, set to NULL
639 * MofResourceNmae [I] not supported, set to NULL
640 * RegistrationHandle [O] Provider's registration handle
643 * Success: ERROR_SUCCESS
644 * Failure: System error code
649 ULONG WINAPI
RegisterTraceGuidsW( WMIDPREQUEST RequestAddress
,
650 PVOID RequestContext
, LPCGUID ControlGuid
, ULONG GuidCount
,
651 PTRACE_GUID_REGISTRATION TraceGuidReg
, LPCWSTR MofImagePath
,
652 LPCWSTR MofResourceName
, PTRACEHANDLE RegistrationHandle
)
654 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress
, RequestContext
,
655 ControlGuid
, GuidCount
, TraceGuidReg
, debugstr_w(MofImagePath
),
656 debugstr_w(MofResourceName
), RegistrationHandle
);
657 return ERROR_CALL_NOT_IMPLEMENTED
;
660 /******************************************************************************
661 * RegisterTraceGuidsA [ADVAPI32.@]
663 * See RegisterTraceGuidsW.
668 ULONG WINAPI
RegisterTraceGuidsA( WMIDPREQUEST RequestAddress
,
669 PVOID RequestContext
, LPCGUID ControlGuid
, ULONG GuidCount
,
670 PTRACE_GUID_REGISTRATION TraceGuidReg
, LPCSTR MofImagePath
,
671 LPCSTR MofResourceName
, PTRACEHANDLE RegistrationHandle
)
673 FIXME("%p %p %p %u %p %s %s %p\n", RequestAddress
, RequestContext
,
674 ControlGuid
, GuidCount
, TraceGuidReg
, debugstr_a(MofImagePath
),
675 debugstr_a(MofResourceName
), RegistrationHandle
);
676 return ERROR_CALL_NOT_IMPLEMENTED
;
679 /******************************************************************************
680 * StartTraceW [ADVAPI32.@]
682 * Register and start an event trace session
685 ULONG WINAPI
StartTraceW( PTRACEHANDLE pSessionHandle
, LPCWSTR SessionName
, PEVENT_TRACE_PROPERTIES Properties
)
687 FIXME("(%p, %s, %p) stub\n", pSessionHandle
, debugstr_w(SessionName
), Properties
);
688 if (pSessionHandle
) *pSessionHandle
= 0xcafe4242;
689 return ERROR_SUCCESS
;
692 /******************************************************************************
693 * StartTraceA [ADVAPI32.@]
698 ULONG WINAPI
StartTraceA( PTRACEHANDLE pSessionHandle
, LPCSTR SessionName
, PEVENT_TRACE_PROPERTIES Properties
)
700 FIXME("(%p, %s, %p) stub\n", pSessionHandle
, debugstr_a(SessionName
), Properties
);
701 if (pSessionHandle
) *pSessionHandle
= 0xcafe4242;
702 return ERROR_SUCCESS
;
705 /******************************************************************************
706 * TraceEvent [ADVAPI32.@]
708 ULONG WINAPI
TraceEvent( TRACEHANDLE SessionHandle
, PEVENT_TRACE_HEADER EventTrace
)
710 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle
), EventTrace
);
711 return ERROR_CALL_NOT_IMPLEMENTED
;
714 /******************************************************************************
715 * UnregisterTraceGuids [ADVAPI32.@]
717 * See RegisterTraceGuids
722 ULONG WINAPI
UnregisterTraceGuids( TRACEHANDLE RegistrationHandle
)
724 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle
));
725 return ERROR_CALL_NOT_IMPLEMENTED
;