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
33 #include "wine/debug.h"
35 #include "advapi32_misc.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
38 WINE_DECLARE_DEBUG_CHANNEL(eventlog
);
40 /******************************************************************************
41 * BackupEventLogA [ADVAPI32.@]
43 * Saves the event log to a backup file.
46 * hEventLog [I] Handle to event log to backup.
47 * lpBackupFileName [I] Name of the backup file.
50 * Success: nonzero. File lpBackupFileName will contain the contents of
54 BOOL WINAPI
BackupEventLogA( HANDLE hEventLog
, LPCSTR lpBackupFileName
)
59 backupW
= strdupAW(lpBackupFileName
);
60 ret
= BackupEventLogW(hEventLog
, backupW
);
66 /******************************************************************************
67 * BackupEventLogW [ADVAPI32.@]
69 * See BackupEventLogA.
71 BOOL WINAPI
BackupEventLogW( HANDLE hEventLog
, LPCWSTR lpBackupFileName
)
73 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_w(lpBackupFileName
));
75 if (!lpBackupFileName
)
77 SetLastError(ERROR_INVALID_PARAMETER
);
83 SetLastError(ERROR_INVALID_HANDLE
);
87 if (GetFileAttributesW(lpBackupFileName
) != INVALID_FILE_ATTRIBUTES
)
89 SetLastError(ERROR_ALREADY_EXISTS
);
96 /******************************************************************************
97 * ClearEventLogA [ADVAPI32.@]
99 * Clears the event log and optionally saves the log to a backup file.
102 * hEvenLog [I] Handle to event log to clear.
103 * lpBackupFileName [I] Name of the backup file.
106 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
107 * contain the contents of hEvenLog and the log will be cleared.
108 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
111 BOOL WINAPI
ClearEventLogA( HANDLE hEventLog
, LPCSTR lpBackupFileName
)
116 backupW
= strdupAW(lpBackupFileName
);
117 ret
= ClearEventLogW(hEventLog
, backupW
);
123 /******************************************************************************
124 * ClearEventLogW [ADVAPI32.@]
126 * See ClearEventLogA.
128 BOOL WINAPI
ClearEventLogW( HANDLE hEventLog
, LPCWSTR lpBackupFileName
)
130 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_w(lpBackupFileName
));
134 SetLastError(ERROR_INVALID_HANDLE
);
141 /******************************************************************************
142 * CloseEventLog [ADVAPI32.@]
144 * Closes a read handle to the event log.
147 * hEventLog [I/O] Handle of the event log to close.
153 BOOL WINAPI
CloseEventLog( HANDLE hEventLog
)
155 FIXME("(%p) stub\n", hEventLog
);
159 SetLastError(ERROR_INVALID_HANDLE
);
166 /******************************************************************************
167 * FlushTraceA [ADVAPI32.@]
169 ULONG WINAPI
FlushTraceA ( TRACEHANDLE hSession
, LPCSTR SessionName
, PEVENT_TRACE_PROPERTIES Properties
)
171 return ControlTraceA( hSession
, SessionName
, Properties
, EVENT_TRACE_CONTROL_FLUSH
);
174 /******************************************************************************
175 * FlushTraceW [ADVAPI32.@]
177 ULONG WINAPI
FlushTraceW ( TRACEHANDLE hSession
, LPCWSTR SessionName
, PEVENT_TRACE_PROPERTIES Properties
)
179 return ControlTraceW( hSession
, SessionName
, Properties
, EVENT_TRACE_CONTROL_FLUSH
);
183 /******************************************************************************
184 * DeregisterEventSource [ADVAPI32.@]
186 * Closes a write handle to an event log
189 * hEventLog [I/O] Handle of the event log.
195 BOOL WINAPI
DeregisterEventSource( HANDLE hEventLog
)
197 FIXME("(%p) stub\n", hEventLog
);
201 /******************************************************************************
202 * EnableTraceEx [ADVAPI32.@]
204 ULONG WINAPI
EnableTraceEx( LPCGUID provider
, LPCGUID source
, TRACEHANDLE hSession
, ULONG enable
,
205 UCHAR level
, ULONGLONG anykeyword
, ULONGLONG allkeyword
, ULONG enableprop
,
206 PEVENT_FILTER_DESCRIPTOR filterdesc
)
208 FIXME("(%s, %s, %s, %u, %u, %s, %s, %u, %p): stub\n", debugstr_guid(provider
),
209 debugstr_guid(source
), wine_dbgstr_longlong(hSession
), enable
, level
,
210 wine_dbgstr_longlong(anykeyword
), wine_dbgstr_longlong(allkeyword
),
211 enableprop
, filterdesc
);
213 return ERROR_SUCCESS
;
216 /******************************************************************************
217 * EnableTrace [ADVAPI32.@]
219 ULONG WINAPI
EnableTrace( ULONG enable
, ULONG flag
, ULONG level
, LPCGUID guid
, TRACEHANDLE hSession
)
221 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable
, flag
, level
,
222 debugstr_guid(guid
), wine_dbgstr_longlong(hSession
));
224 return ERROR_SUCCESS
;
227 /******************************************************************************
228 * GetEventLogInformation [ADVAPI32.@]
230 * Retrieve some information about an event log.
233 * hEventLog [I] Handle to an open event log.
234 * dwInfoLevel [I] Level of information (only EVENTLOG_FULL_INFO)
235 * lpBuffer [I/O] The buffer for the returned information
236 * cbBufSize [I] The size of the buffer
237 * pcbBytesNeeded [O] The needed bytes to hold the information
240 * Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
241 * the needed buffer size.
244 BOOL WINAPI
GetEventLogInformation( HANDLE hEventLog
, DWORD dwInfoLevel
, LPVOID lpBuffer
, DWORD cbBufSize
, LPDWORD pcbBytesNeeded
)
246 EVENTLOG_FULL_INFORMATION
*efi
;
248 FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
250 if (dwInfoLevel
!= EVENTLOG_FULL_INFO
)
252 SetLastError(ERROR_INVALID_LEVEL
);
258 SetLastError(ERROR_INVALID_HANDLE
);
262 if (!lpBuffer
|| !pcbBytesNeeded
)
264 /* FIXME: This will be handled properly when eventlog is moved
267 SetLastError(RPC_X_NULL_REF_POINTER
);
271 *pcbBytesNeeded
= sizeof(EVENTLOG_FULL_INFORMATION
);
272 if (cbBufSize
< sizeof(EVENTLOG_FULL_INFORMATION
))
274 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
278 /* Pretend the log is not full */
279 efi
= (EVENTLOG_FULL_INFORMATION
*)lpBuffer
;
285 /******************************************************************************
286 * GetNumberOfEventLogRecords [ADVAPI32.@]
288 * Retrieves the number of records in an event log.
291 * hEventLog [I] Handle to an open event log.
292 * NumberOfRecords [O] Number of records in the log.
295 * Success: nonzero. NumberOfRecords will contain the number of records in
299 BOOL WINAPI
GetNumberOfEventLogRecords( HANDLE hEventLog
, PDWORD NumberOfRecords
)
301 FIXME("(%p,%p) stub\n", hEventLog
, NumberOfRecords
);
303 if (!NumberOfRecords
)
305 SetLastError(ERROR_INVALID_PARAMETER
);
311 SetLastError(ERROR_INVALID_HANDLE
);
315 *NumberOfRecords
= 0;
320 /******************************************************************************
321 * GetOldestEventLogRecord [ADVAPI32.@]
323 * Retrieves the absolute record number of the oldest record in an even log.
326 * hEventLog [I] Handle to an open event log.
327 * OldestRecord [O] Absolute record number of the oldest record.
330 * Success: nonzero. OldestRecord contains the record number of the oldest
334 BOOL WINAPI
GetOldestEventLogRecord( HANDLE hEventLog
, PDWORD OldestRecord
)
336 FIXME("(%p,%p) stub\n", hEventLog
, OldestRecord
);
340 SetLastError(ERROR_INVALID_PARAMETER
);
346 SetLastError(ERROR_INVALID_HANDLE
);
355 /******************************************************************************
356 * NotifyChangeEventLog [ADVAPI32.@]
358 * Enables an application to receive notification when an event is written
362 * hEventLog [I] Handle to an event log.
363 * hEvent [I] Handle to a manual-reset event object.
369 BOOL WINAPI
NotifyChangeEventLog( HANDLE hEventLog
, HANDLE hEvent
)
371 FIXME("(%p,%p) stub\n", hEventLog
, hEvent
);
375 /******************************************************************************
376 * OpenBackupEventLogA [ADVAPI32.@]
378 * Opens a handle to a backup event log.
381 * lpUNCServerName [I] Universal Naming Convention name of the server on which
382 * this will be performed.
383 * lpFileName [I] Specifies the name of the backup file.
386 * Success: Handle to the backup event log.
389 HANDLE WINAPI
OpenBackupEventLogA( LPCSTR lpUNCServerName
, LPCSTR lpFileName
)
391 LPWSTR uncnameW
, filenameW
;
394 uncnameW
= strdupAW(lpUNCServerName
);
395 filenameW
= strdupAW(lpFileName
);
396 handle
= OpenBackupEventLogW(uncnameW
, filenameW
);
398 heap_free(filenameW
);
403 /******************************************************************************
404 * OpenBackupEventLogW [ADVAPI32.@]
406 * See OpenBackupEventLogA.
408 HANDLE WINAPI
OpenBackupEventLogW( LPCWSTR lpUNCServerName
, LPCWSTR lpFileName
)
410 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpFileName
));
414 SetLastError(ERROR_INVALID_PARAMETER
);
418 if (lpUNCServerName
&& lpUNCServerName
[0])
420 FIXME("Remote server not supported\n");
421 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
425 if (GetFileAttributesW(lpFileName
) == INVALID_FILE_ATTRIBUTES
)
427 SetLastError(ERROR_FILE_NOT_FOUND
);
431 return (HANDLE
)0xcafe4242;
434 /******************************************************************************
435 * OpenEventLogA [ADVAPI32.@]
437 * Opens a handle to the specified event log.
440 * lpUNCServerName [I] UNC name of the server on which the event log is
442 * lpSourceName [I] Name of the log.
445 * Success: Handle to an event log.
448 HANDLE WINAPI
OpenEventLogA( LPCSTR uncname
, LPCSTR source
)
450 LPWSTR uncnameW
, sourceW
;
453 uncnameW
= strdupAW(uncname
);
454 sourceW
= strdupAW(source
);
455 handle
= OpenEventLogW(uncnameW
, sourceW
);
462 /******************************************************************************
463 * OpenEventLogW [ADVAPI32.@]
467 HANDLE WINAPI
OpenEventLogW( LPCWSTR uncname
, LPCWSTR source
)
469 FIXME("(%s,%s) stub\n", debugstr_w(uncname
), debugstr_w(source
));
473 SetLastError(ERROR_INVALID_PARAMETER
);
477 if (uncname
&& uncname
[0])
479 FIXME("Remote server not supported\n");
480 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
484 return (HANDLE
)0xcafe4242;
487 /******************************************************************************
488 * ReadEventLogA [ADVAPI32.@]
490 * Reads a whole number of entries from an event log.
493 * hEventLog [I] Handle of the event log to read.
494 * dwReadFlags [I] see MSDN doc.
495 * dwRecordOffset [I] Log-entry record number to start at.
496 * lpBuffer [O] Buffer for the data read.
497 * nNumberOfBytesToRead [I] Size of lpBuffer.
498 * pnBytesRead [O] Receives number of bytes read.
499 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
506 BOOL WINAPI
ReadEventLogA( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
507 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
509 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog
, dwReadFlags
,
510 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
512 SetLastError(ERROR_HANDLE_EOF
);
516 /******************************************************************************
517 * ReadEventLogW [ADVAPI32.@]
521 BOOL WINAPI
ReadEventLogW( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
522 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
524 FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog
, dwReadFlags
,
525 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
527 SetLastError(ERROR_HANDLE_EOF
);
531 /******************************************************************************
532 * RegisterEventSourceA [ADVAPI32.@]
534 * Returns a registered handle to an event log.
537 * lpUNCServerName [I] UNC name of the source server.
538 * lpSourceName [I] Specifies the name of the event source to retrieve.
541 * Success: Handle to the event log.
542 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
543 * Security event log.
545 HANDLE WINAPI
RegisterEventSourceA( LPCSTR lpUNCServerName
, LPCSTR lpSourceName
)
547 UNICODE_STRING lpUNCServerNameW
;
548 UNICODE_STRING lpSourceNameW
;
551 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName
), debugstr_a(lpSourceName
));
553 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW
, lpUNCServerName
);
554 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW
, lpSourceName
);
555 ret
= RegisterEventSourceW(lpUNCServerNameW
.Buffer
,lpSourceNameW
.Buffer
);
556 RtlFreeUnicodeString (&lpUNCServerNameW
);
557 RtlFreeUnicodeString (&lpSourceNameW
);
561 /******************************************************************************
562 * RegisterEventSourceW [ADVAPI32.@]
564 * See RegisterEventSourceA.
566 HANDLE WINAPI
RegisterEventSourceW( LPCWSTR lpUNCServerName
, LPCWSTR lpSourceName
)
568 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpSourceName
));
569 return (HANDLE
)0xcafe4242;
572 /******************************************************************************
573 * ReportEventA [ADVAPI32.@]
575 * Writes an entry at the end of an event log.
578 * hEventLog [I] Handle of an event log.
579 * wType [I] See MSDN doc.
580 * wCategory [I] Event category.
581 * dwEventID [I] Event identifier.
582 * lpUserSid [I] Current user's security identifier.
583 * wNumStrings [I] Number of insert strings in lpStrings.
584 * dwDataSize [I] Size of event-specific raw data to write.
585 * lpStrings [I] Buffer containing an array of string to be merged.
586 * lpRawData [I] Buffer containing the binary data.
589 * Success: nonzero. Entry was written to the log.
593 * The ReportEvent function adds the time, the entry's length, and the
594 * offsets before storing the entry in the log. If lpUserSid != NULL, the
595 * username is also logged.
597 BOOL WINAPI
ReportEventA ( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
598 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCSTR
*lpStrings
, LPVOID lpRawData
)
600 LPWSTR
*wideStrArray
;
605 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog
,
606 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
608 if (wNumStrings
== 0) return TRUE
;
609 if (!lpStrings
) return TRUE
;
611 wideStrArray
= heap_alloc(sizeof(LPWSTR
) * wNumStrings
);
612 for (i
= 0; i
< wNumStrings
; i
++)
614 RtlCreateUnicodeStringFromAsciiz(&str
, lpStrings
[i
]);
615 wideStrArray
[i
] = str
.Buffer
;
617 ret
= ReportEventW(hEventLog
, wType
, wCategory
, dwEventID
, lpUserSid
,
618 wNumStrings
, dwDataSize
, (LPCWSTR
*)wideStrArray
, lpRawData
);
619 for (i
= 0; i
< wNumStrings
; i
++)
620 heap_free( wideStrArray
[i
] );
621 heap_free(wideStrArray
);
625 /******************************************************************************
626 * ReportEventW [ADVAPI32.@]
630 BOOL WINAPI
ReportEventW( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
631 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCWSTR
*lpStrings
, LPVOID lpRawData
)
635 FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog
,
636 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
640 if (wNumStrings
== 0) return TRUE
;
641 if (!lpStrings
) return TRUE
;
643 for (i
= 0; i
< wNumStrings
; i
++)
647 case EVENTLOG_SUCCESS
:
648 TRACE_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
650 case EVENTLOG_ERROR_TYPE
:
651 ERR_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
653 case EVENTLOG_WARNING_TYPE
:
654 WARN_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
657 TRACE_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
664 /******************************************************************************
665 * StopTraceA [ADVAPI32.@]
670 ULONG WINAPI
StopTraceA( TRACEHANDLE session
, LPCSTR session_name
, PEVENT_TRACE_PROPERTIES properties
)
672 FIXME("(%s, %s, %p) stub\n", wine_dbgstr_longlong(session
), debugstr_a(session_name
), properties
);
673 return ERROR_SUCCESS
;
676 /******************************************************************************
677 * QueryTraceW [ADVAPI32.@]
679 ULONG WINAPI
QueryTraceW( TRACEHANDLE handle
, LPCWSTR sessionname
, PEVENT_TRACE_PROPERTIES properties
)
681 FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle
), debugstr_w(sessionname
), properties
);
682 return ERROR_CALL_NOT_IMPLEMENTED
;
685 /******************************************************************************
686 * OpenTraceA [ADVAPI32.@]
688 TRACEHANDLE WINAPI
OpenTraceA( PEVENT_TRACE_LOGFILEA logfile
)
692 if (!once
++) FIXME("%p: stub\n", logfile
);
693 SetLastError(ERROR_ACCESS_DENIED
);
694 return INVALID_PROCESSTRACE_HANDLE
;
697 /******************************************************************************
698 * EnumerateTraceGuids [ADVAPI32.@]
700 ULONG WINAPI
EnumerateTraceGuids(PTRACE_GUID_PROPERTIES
*propertiesarray
,
701 ULONG arraycount
, PULONG guidcount
)
703 FIXME("%p %d %p: stub\n", propertiesarray
, arraycount
, guidcount
);
704 return ERROR_INVALID_PARAMETER
;