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
34 #include "wine/debug.h"
36 #include "advapi32_misc.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
39 WINE_DECLARE_DEBUG_CHANNEL(eventlog
);
41 /******************************************************************************
42 * BackupEventLogA [ADVAPI32.@]
44 * Saves the event log to a backup file.
47 * hEventLog [I] Handle to event log to backup.
48 * lpBackupFileName [I] Name of the backup file.
51 * Success: nonzero. File lpBackupFileName will contain the contents of
55 BOOL WINAPI
BackupEventLogA( HANDLE hEventLog
, LPCSTR lpBackupFileName
)
60 backupW
= strdupAW(lpBackupFileName
);
61 ret
= BackupEventLogW(hEventLog
, backupW
);
67 /******************************************************************************
68 * BackupEventLogW [ADVAPI32.@]
70 * See BackupEventLogA.
72 BOOL WINAPI
BackupEventLogW( HANDLE hEventLog
, LPCWSTR lpBackupFileName
)
74 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_w(lpBackupFileName
));
76 if (!lpBackupFileName
)
78 SetLastError(ERROR_INVALID_PARAMETER
);
84 SetLastError(ERROR_INVALID_HANDLE
);
88 if (GetFileAttributesW(lpBackupFileName
) != INVALID_FILE_ATTRIBUTES
)
90 SetLastError(ERROR_ALREADY_EXISTS
);
97 /******************************************************************************
98 * ClearEventLogA [ADVAPI32.@]
100 * Clears the event log and optionally saves the log to a backup file.
103 * hEvenLog [I] Handle to event log to clear.
104 * lpBackupFileName [I] Name of the backup file.
107 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
108 * contain the contents of hEvenLog and the log will be cleared.
109 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
112 BOOL WINAPI
ClearEventLogA( HANDLE hEventLog
, LPCSTR lpBackupFileName
)
117 backupW
= strdupAW(lpBackupFileName
);
118 ret
= ClearEventLogW(hEventLog
, backupW
);
124 /******************************************************************************
125 * ClearEventLogW [ADVAPI32.@]
127 * See ClearEventLogA.
129 BOOL WINAPI
ClearEventLogW( HANDLE hEventLog
, LPCWSTR lpBackupFileName
)
131 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_w(lpBackupFileName
));
135 SetLastError(ERROR_INVALID_HANDLE
);
142 /******************************************************************************
143 * CloseEventLog [ADVAPI32.@]
145 * Closes a read handle to the event log.
148 * hEventLog [I/O] Handle of the event log to close.
154 BOOL WINAPI
CloseEventLog( HANDLE hEventLog
)
156 FIXME("(%p) stub\n", hEventLog
);
160 SetLastError(ERROR_INVALID_HANDLE
);
167 /******************************************************************************
168 * FlushTraceA [ADVAPI32.@]
170 ULONG WINAPI
FlushTraceA ( TRACEHANDLE hSession
, LPCSTR SessionName
, PEVENT_TRACE_PROPERTIES Properties
)
172 return ControlTraceA( hSession
, SessionName
, Properties
, EVENT_TRACE_CONTROL_FLUSH
);
175 /******************************************************************************
176 * FlushTraceW [ADVAPI32.@]
178 ULONG WINAPI
FlushTraceW ( TRACEHANDLE hSession
, LPCWSTR SessionName
, PEVENT_TRACE_PROPERTIES Properties
)
180 return ControlTraceW( hSession
, SessionName
, Properties
, EVENT_TRACE_CONTROL_FLUSH
);
184 /******************************************************************************
185 * DeregisterEventSource [ADVAPI32.@]
187 * Closes a write handle to an event log
190 * hEventLog [I/O] Handle of the event log.
196 BOOL WINAPI
DeregisterEventSource( HANDLE hEventLog
)
198 FIXME("(%p) stub\n", hEventLog
);
202 /******************************************************************************
203 * EnableTraceEx [ADVAPI32.@]
205 ULONG WINAPI
EnableTraceEx( LPCGUID provider
, LPCGUID source
, TRACEHANDLE hSession
, ULONG enable
,
206 UCHAR level
, ULONGLONG anykeyword
, ULONGLONG allkeyword
, ULONG enableprop
,
207 PEVENT_FILTER_DESCRIPTOR filterdesc
)
209 FIXME("(%s, %s, %s, %lu, %u, %s, %s, %lu, %p): stub\n", debugstr_guid(provider
),
210 debugstr_guid(source
), wine_dbgstr_longlong(hSession
), enable
, level
,
211 wine_dbgstr_longlong(anykeyword
), wine_dbgstr_longlong(allkeyword
),
212 enableprop
, filterdesc
);
214 return ERROR_SUCCESS
;
217 /******************************************************************************
218 * EnableTrace [ADVAPI32.@]
220 ULONG WINAPI
EnableTrace( ULONG enable
, ULONG flag
, ULONG level
, LPCGUID guid
, TRACEHANDLE hSession
)
222 FIXME("(%ld, 0x%lx, %ld, %s, %s): stub\n", enable
, flag
, level
,
223 debugstr_guid(guid
), wine_dbgstr_longlong(hSession
));
225 return ERROR_SUCCESS
;
228 /******************************************************************************
229 * GetEventLogInformation [ADVAPI32.@]
231 * Retrieve some information about an event log.
234 * hEventLog [I] Handle to an open event log.
235 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
236 * lpBuffer [I/O] The buffer for the returned information
237 * cbBufSize [I] The size of the buffer
238 * pcbBytesNeeded [O] The needed bytes to hold the information
241 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
242 * the needed buffer size.
245 BOOL WINAPI
GetEventLogInformation( HANDLE hEventLog
, DWORD dwInfoLevel
, LPVOID lpBuffer
, DWORD cbBufSize
, LPDWORD pcbBytesNeeded
)
247 EVENTLOG_FULL_INFORMATION
*efi
;
249 FIXME("(%p, %ld, %p, %ld, %p) stub\n", hEventLog
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
251 if (dwInfoLevel
!= EVENTLOG_FULL_INFO
)
253 SetLastError(ERROR_INVALID_LEVEL
);
259 SetLastError(ERROR_INVALID_HANDLE
);
263 if (!lpBuffer
|| !pcbBytesNeeded
)
265 /* FIXME: This will be handled properly when eventlog is moved
268 SetLastError(RPC_X_NULL_REF_POINTER
);
272 *pcbBytesNeeded
= sizeof(EVENTLOG_FULL_INFORMATION
);
273 if (cbBufSize
< sizeof(EVENTLOG_FULL_INFORMATION
))
275 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
279 /* Pretend the log is not full */
280 efi
= (EVENTLOG_FULL_INFORMATION
*)lpBuffer
;
286 /******************************************************************************
287 * GetNumberOfEventLogRecords [ADVAPI32.@]
289 * Retrieves the number of records in an event log.
292 * hEventLog [I] Handle to an open event log.
293 * NumberOfRecords [O] Number of records in the log.
296 * Success: nonzero. NumberOfRecords will contain the number of records in
300 BOOL WINAPI
GetNumberOfEventLogRecords( HANDLE hEventLog
, PDWORD NumberOfRecords
)
302 FIXME("(%p,%p) stub\n", hEventLog
, NumberOfRecords
);
304 if (!NumberOfRecords
)
306 SetLastError(ERROR_INVALID_PARAMETER
);
312 SetLastError(ERROR_INVALID_HANDLE
);
316 *NumberOfRecords
= 0;
321 /******************************************************************************
322 * GetOldestEventLogRecord [ADVAPI32.@]
324 * Retrieves the absolute record number of the oldest record in an even log.
327 * hEventLog [I] Handle to an open event log.
328 * OldestRecord [O] Absolute record number of the oldest record.
331 * Success: nonzero. OldestRecord contains the record number of the oldest
335 BOOL WINAPI
GetOldestEventLogRecord( HANDLE hEventLog
, PDWORD OldestRecord
)
337 FIXME("(%p,%p) stub\n", hEventLog
, OldestRecord
);
341 SetLastError(ERROR_INVALID_PARAMETER
);
347 SetLastError(ERROR_INVALID_HANDLE
);
356 /******************************************************************************
357 * NotifyChangeEventLog [ADVAPI32.@]
359 * Enables an application to receive notification when an event is written
363 * hEventLog [I] Handle to an event log.
364 * hEvent [I] Handle to a manual-reset event object.
370 BOOL WINAPI
NotifyChangeEventLog( HANDLE hEventLog
, HANDLE hEvent
)
372 FIXME("(%p,%p) stub\n", hEventLog
, hEvent
);
376 /******************************************************************************
377 * OpenBackupEventLogA [ADVAPI32.@]
379 * Opens a handle to a backup event log.
382 * lpUNCServerName [I] Universal Naming Convention name of the server on which
383 * this will be performed.
384 * lpFileName [I] Specifies the name of the backup file.
387 * Success: Handle to the backup event log.
390 HANDLE WINAPI
OpenBackupEventLogA( LPCSTR lpUNCServerName
, LPCSTR lpFileName
)
392 LPWSTR uncnameW
, filenameW
;
395 uncnameW
= strdupAW(lpUNCServerName
);
396 filenameW
= strdupAW(lpFileName
);
397 handle
= OpenBackupEventLogW(uncnameW
, filenameW
);
404 /******************************************************************************
405 * OpenBackupEventLogW [ADVAPI32.@]
407 * See OpenBackupEventLogA.
409 HANDLE WINAPI
OpenBackupEventLogW( LPCWSTR lpUNCServerName
, LPCWSTR lpFileName
)
411 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpFileName
));
415 SetLastError(ERROR_INVALID_PARAMETER
);
419 if (lpUNCServerName
&& lpUNCServerName
[0])
421 FIXME("Remote server not supported\n");
422 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
426 if (GetFileAttributesW(lpFileName
) == INVALID_FILE_ATTRIBUTES
)
428 SetLastError(ERROR_FILE_NOT_FOUND
);
432 return (HANDLE
)0xcafe4242;
435 /******************************************************************************
436 * OpenEventLogA [ADVAPI32.@]
438 * Opens a handle to the specified event log.
441 * lpUNCServerName [I] UNC name of the server on which the event log is
443 * lpSourceName [I] Name of the log.
446 * Success: Handle to an event log.
449 HANDLE WINAPI
OpenEventLogA( LPCSTR uncname
, LPCSTR source
)
451 LPWSTR uncnameW
, sourceW
;
454 uncnameW
= strdupAW(uncname
);
455 sourceW
= strdupAW(source
);
456 handle
= OpenEventLogW(uncnameW
, sourceW
);
463 /******************************************************************************
464 * OpenEventLogW [ADVAPI32.@]
468 HANDLE WINAPI
OpenEventLogW( LPCWSTR uncname
, LPCWSTR source
)
470 FIXME("(%s,%s) stub\n", debugstr_w(uncname
), debugstr_w(source
));
474 SetLastError(ERROR_INVALID_PARAMETER
);
478 if (uncname
&& uncname
[0])
480 FIXME("Remote server not supported\n");
481 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
485 return (HANDLE
)0xcafe4242;
488 /******************************************************************************
489 * ReadEventLogA [ADVAPI32.@]
491 * Reads a whole number of entries from an event log.
494 * hEventLog [I] Handle of the event log to read.
495 * dwReadFlags [I] see MSDN doc.
496 * dwRecordOffset [I] Log-entry record number to start at.
497 * lpBuffer [O] Buffer for the data read.
498 * nNumberOfBytesToRead [I] Size of lpBuffer.
499 * pnBytesRead [O] Receives number of bytes read.
500 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
507 BOOL WINAPI
ReadEventLogA( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
508 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
510 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog
, dwReadFlags
,
511 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
513 SetLastError(ERROR_HANDLE_EOF
);
517 /******************************************************************************
518 * ReadEventLogW [ADVAPI32.@]
522 BOOL WINAPI
ReadEventLogW( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
523 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
525 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog
, dwReadFlags
,
526 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
528 SetLastError(ERROR_HANDLE_EOF
);
532 /******************************************************************************
533 * RegisterEventSourceA [ADVAPI32.@]
535 * Returns a registered handle to an event log.
538 * lpUNCServerName [I] UNC name of the source server.
539 * lpSourceName [I] Specifies the name of the event source to retrieve.
542 * Success: Handle to the event log.
543 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
544 * Security event log.
546 HANDLE WINAPI
RegisterEventSourceA( LPCSTR lpUNCServerName
, LPCSTR lpSourceName
)
548 UNICODE_STRING lpUNCServerNameW
;
549 UNICODE_STRING lpSourceNameW
;
552 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName
), debugstr_a(lpSourceName
));
554 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW
, lpUNCServerName
);
555 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW
, lpSourceName
);
556 ret
= RegisterEventSourceW(lpUNCServerNameW
.Buffer
,lpSourceNameW
.Buffer
);
557 RtlFreeUnicodeString (&lpUNCServerNameW
);
558 RtlFreeUnicodeString (&lpSourceNameW
);
562 /******************************************************************************
563 * RegisterEventSourceW [ADVAPI32.@]
565 * See RegisterEventSourceA.
567 HANDLE WINAPI
RegisterEventSourceW( LPCWSTR lpUNCServerName
, LPCWSTR lpSourceName
)
569 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpSourceName
));
570 return (HANDLE
)0xcafe4242;
573 /******************************************************************************
574 * ReportEventA [ADVAPI32.@]
576 * Writes an entry at the end of an event log.
579 * hEventLog [I] Handle of an event log.
580 * wType [I] See MSDN doc.
581 * wCategory [I] Event category.
582 * dwEventID [I] Event identifier.
583 * lpUserSid [I] Current user's security identifier.
584 * wNumStrings [I] Number of insert strings in lpStrings.
585 * dwDataSize [I] Size of event-specific raw data to write.
586 * lpStrings [I] Buffer containing an array of string to be merged.
587 * lpRawData [I] Buffer containing the binary data.
590 * Success: nonzero. Entry was written to the log.
594 * The ReportEvent function adds the time, the entry's length, and the
595 * offsets before storing the entry in the log. If lpUserSid != NULL, the
596 * username is also logged.
598 BOOL WINAPI
ReportEventA ( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
599 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCSTR
*lpStrings
, LPVOID lpRawData
)
601 LPWSTR
*wideStrArray
;
606 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog
,
607 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
609 if (wNumStrings
== 0) return TRUE
;
610 if (!lpStrings
) return TRUE
;
612 wideStrArray
= malloc(sizeof(WCHAR
*) * wNumStrings
);
613 for (i
= 0; i
< wNumStrings
; i
++)
615 RtlCreateUnicodeStringFromAsciiz(&str
, lpStrings
[i
]);
616 wideStrArray
[i
] = str
.Buffer
;
618 ret
= ReportEventW(hEventLog
, wType
, wCategory
, dwEventID
, lpUserSid
,
619 wNumStrings
, dwDataSize
, (LPCWSTR
*)wideStrArray
, lpRawData
);
620 for (i
= 0; i
< wNumStrings
; i
++)
621 free(wideStrArray
[i
]);
626 /******************************************************************************
627 * ReportEventW [ADVAPI32.@]
631 BOOL WINAPI
ReportEventW( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
632 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCWSTR
*lpStrings
, LPVOID lpRawData
)
636 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog
,
637 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
641 if (wNumStrings
== 0) return TRUE
;
642 if (!lpStrings
) return TRUE
;
644 for (i
= 0; i
< wNumStrings
; i
++)
646 const WCHAR
*line
= lpStrings
[i
];
650 const WCHAR
*next
= wcschr( line
, '\n' );
655 next
= line
+ wcslen( line
);
659 case EVENTLOG_SUCCESS
:
660 TRACE_(eventlog
)("%s\n", debugstr_wn(line
, next
- line
));
662 case EVENTLOG_ERROR_TYPE
:
663 ERR_(eventlog
)("%s\n", debugstr_wn(line
, next
- line
));
665 case EVENTLOG_WARNING_TYPE
:
666 WARN_(eventlog
)("%s\n", debugstr_wn(line
, next
- line
));
669 TRACE_(eventlog
)("%s\n", debugstr_wn(line
, next
- line
));
679 /******************************************************************************
680 * StopTraceA [ADVAPI32.@]
685 ULONG WINAPI
StopTraceA( TRACEHANDLE session
, LPCSTR session_name
, PEVENT_TRACE_PROPERTIES properties
)
687 FIXME("(%s, %s, %p) stub\n", wine_dbgstr_longlong(session
), debugstr_a(session_name
), properties
);
688 return ERROR_SUCCESS
;
691 /******************************************************************************
692 * QueryTraceA [ADVAPI32.@]
694 ULONG WINAPI
QueryTraceA( TRACEHANDLE handle
, LPCSTR sessionname
, PEVENT_TRACE_PROPERTIES properties
)
696 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle
), debugstr_a(sessionname
), properties
);
697 return ERROR_WMI_INSTANCE_NOT_FOUND
;
700 /******************************************************************************
701 * QueryTraceW [ADVAPI32.@]
703 ULONG WINAPI
QueryTraceW( TRACEHANDLE handle
, LPCWSTR sessionname
, PEVENT_TRACE_PROPERTIES properties
)
705 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle
), debugstr_w(sessionname
), properties
);
706 return ERROR_CALL_NOT_IMPLEMENTED
;
709 /******************************************************************************
710 * OpenTraceA [ADVAPI32.@]
712 TRACEHANDLE WINAPI
OpenTraceA( PEVENT_TRACE_LOGFILEA logfile
)
716 if (!once
++) FIXME("%p: stub\n", logfile
);
717 SetLastError(ERROR_ACCESS_DENIED
);
718 return INVALID_PROCESSTRACE_HANDLE
;
721 /******************************************************************************
722 * EnumerateTraceGuids [ADVAPI32.@]
724 ULONG WINAPI
EnumerateTraceGuids(PTRACE_GUID_PROPERTIES
*propertiesarray
,
725 ULONG arraycount
, PULONG guidcount
)
727 FIXME("%p %ld %p: stub\n", propertiesarray
, arraycount
, guidcount
);
728 return ERROR_INVALID_PARAMETER
;