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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
34 WINE_DECLARE_DEBUG_CHANNEL(eventlog
);
36 /******************************************************************************
37 * BackupEventLogA [ADVAPI32.@]
39 * Saves the event log to a backup file.
42 * hEventLog [I] Handle to event log to backup.
43 * lpBackupFileName [I] Name of the backup file.
46 * Success: nonzero. File lpBackupFileName will contain the contents of
50 BOOL WINAPI
BackupEventLogA( HANDLE hEventLog
, LPCSTR lpBackupFileName
)
52 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_a(lpBackupFileName
));
56 /******************************************************************************
57 * BackupEventLogW [ADVAPI32.@]
61 BOOL WINAPI
BackupEventLogW( HANDLE hEventLog
, LPCWSTR lpBackupFileName
)
63 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_w(lpBackupFileName
));
67 /******************************************************************************
68 * ClearEventLogA [ADVAPI32.@]
70 * Clears the event log and/or saves the log to a backup file.
73 * hEvenLog [I] Handle to event log to clear.
74 * lpBackupFileName [I] Name of the backup file.
77 * Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will
78 * contain the contents of hEvenLog and the log will be cleared.
79 * Failure: zero. Fails if the event log is empty or if lpBackupFileName
82 BOOL WINAPI
ClearEventLogA( HANDLE hEventLog
, LPCSTR lpBackupFileName
)
84 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_a(lpBackupFileName
));
88 /******************************************************************************
89 * ClearEventLogW [ADVAPI32.@]
93 BOOL WINAPI
ClearEventLogW( HANDLE hEventLog
, LPCWSTR lpBackupFileName
)
95 FIXME("(%p,%s) stub\n", hEventLog
, debugstr_w(lpBackupFileName
));
99 /******************************************************************************
100 * CloseEventLog [ADVAPI32.@]
102 * Closes a read handle to the event log.
105 * hEventLog [I/O] Handle of the event log to close.
111 BOOL WINAPI
CloseEventLog( HANDLE hEventLog
)
113 FIXME("(%p) stub\n", hEventLog
);
117 /******************************************************************************
118 * DeregisterEventSource [ADVAPI32.@]
120 * Closes a write handle to an event log
123 * hEventLog [I/O] Handle of the event log.
129 BOOL WINAPI
DeregisterEventSource( HANDLE hEventLog
)
131 FIXME("(%p) stub\n", hEventLog
);
135 /******************************************************************************
136 * GetNumberOfEventLogRecords [ADVAPI32.@]
138 * Retrieves the number of records in an event log.
141 * hEventLog [I] Handle to an open event log.
142 * NumberOfRecords [O] Number of records in the log.
145 * Success: nonzero. NumberOfRecords will contain the number of records in
149 BOOL WINAPI
GetNumberOfEventLogRecords( HANDLE hEventLog
, PDWORD NumberOfRecords
)
151 FIXME("(%p,%p) stub\n", hEventLog
, NumberOfRecords
);
153 if (!NumberOfRecords
) return FALSE
;
154 *NumberOfRecords
= 0;
159 /******************************************************************************
160 * GetOldestEventLogRecord [ADVAPI32.@]
162 * Retrieves the absolute record number of the oldest record in an even log.
165 * hEventLog [I] Handle to an open event log.
166 * OldestRecord [O] Absolute record number of the oldest record.
169 * Success: nonzero. OldestRecord contains the record number of the oldest
173 BOOL WINAPI
GetOldestEventLogRecord( HANDLE hEventLog
, PDWORD OldestRecord
)
175 FIXME("(%p,%p) stub\n", hEventLog
, OldestRecord
);
177 if (!OldestRecord
) return FALSE
;
183 /******************************************************************************
184 * NotifyChangeEventLog [ADVAPI32.@]
186 * Enables an application to receive notification when an event is written
190 * hEventLog [I] Handle to an event log.
191 * hEvent [I] Handle to a manual-reset event object.
197 BOOL WINAPI
NotifyChangeEventLog( HANDLE hEventLog
, HANDLE hEvent
)
199 FIXME("(%p,%p) stub\n", hEventLog
, hEvent
);
203 /******************************************************************************
204 * OpenBackupEventLogA [ADVAPI32.@]
206 * Opens a handle to a backup event log.
209 * lpUNCServerName [I] Universal Naming Convention name of the server on which
210 * this will be performed.
211 * lpFileName [I] Specifies the name of the backup file.
214 * Success: Handle to the backup event log.
217 HANDLE WINAPI
OpenBackupEventLogA( LPCSTR lpUNCServerName
, LPCSTR lpFileName
)
219 FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName
), debugstr_a(lpFileName
));
220 return (HANDLE
)0xcafe4242;
223 /******************************************************************************
224 * OpenBackupEventLogW [ADVAPI32.@]
226 * see OpenBackupEventLogA
228 HANDLE WINAPI
OpenBackupEventLogW( LPCWSTR lpUNCServerName
, LPCWSTR lpFileName
)
230 FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpFileName
));
231 return (HANDLE
)0xcafe4242;
234 /******************************************************************************
235 * OpenEventLogA [ADVAPI32.@]
237 * Opens a handle to the specified event log.
240 * lpUNCServerName [I] UNC name of the server on which the event log is
242 * lpSourceName [I] Name of the log.
245 * Success: Handle to an event log.
248 HANDLE WINAPI
OpenEventLogA( LPCSTR uncname
, LPCSTR source
)
250 FIXME("(%s,%s) stub\n", debugstr_a(uncname
), debugstr_a(source
));
251 return (HANDLE
)0xcafe4242;
254 /******************************************************************************
255 * OpenEventLogW [ADVAPI32.@]
259 HANDLE WINAPI
OpenEventLogW( LPCWSTR uncname
, LPCWSTR source
)
261 FIXME("(%s,%s) stub\n", debugstr_w(uncname
), debugstr_w(source
));
262 return (HANDLE
)0xcafe4242;
265 /******************************************************************************
266 * ReadEventLogA [ADVAPI32.@]
268 * Reads a whole number of entries from an event log.
271 * hEventLog [I] Handle of the event log to read.
272 * dwReadFlags [I] see MSDN doc.
273 * dwRecordOffset [I] Log-entry record number to start at.
274 * lpBuffer [O] Buffer for the data read.
275 * nNumberOfBytesToRead [I] Size of lpBuffer.
276 * pnBytesRead [O] Receives number of bytes read.
277 * pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
284 BOOL WINAPI
ReadEventLogA( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
285 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
287 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog
, dwReadFlags
,
288 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
292 /******************************************************************************
293 * ReadEventLogW [ADVAPI32.@]
297 BOOL WINAPI
ReadEventLogW( HANDLE hEventLog
, DWORD dwReadFlags
, DWORD dwRecordOffset
,
298 LPVOID lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
*pnBytesRead
, DWORD
*pnMinNumberOfBytesNeeded
)
300 FIXME("(%p,0x%08lx,0x%08lx,%p,0x%08lx,%p,%p) stub\n", hEventLog
, dwReadFlags
,
301 dwRecordOffset
, lpBuffer
, nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
305 /******************************************************************************
306 * RegisterEventSourceA [ADVAPI32.@]
308 * Returns a registered handle to an event log.
311 * lpUNCServerName [I] UNC name of the source server.
312 * lpSourceName [I] Specifies the name of the event source to retrieve.
315 * Success: Handle to the event log.
316 * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
317 * Security event log.
319 HANDLE WINAPI
RegisterEventSourceA( LPCSTR lpUNCServerName
, LPCSTR lpSourceName
)
321 UNICODE_STRING lpUNCServerNameW
;
322 UNICODE_STRING lpSourceNameW
;
325 FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName
), debugstr_a(lpSourceName
));
327 RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW
, lpUNCServerName
);
328 RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW
, lpSourceName
);
329 ret
= RegisterEventSourceW(lpUNCServerNameW
.Buffer
,lpSourceNameW
.Buffer
);
330 RtlFreeUnicodeString (&lpUNCServerNameW
);
331 RtlFreeUnicodeString (&lpSourceNameW
);
335 /******************************************************************************
336 * RegisterEventSourceW [ADVAPI32.@]
338 * see RegisterEventSourceA
340 HANDLE WINAPI
RegisterEventSourceW( LPCWSTR lpUNCServerName
, LPCWSTR lpSourceName
)
342 FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName
), debugstr_w(lpSourceName
));
343 return (HANDLE
)0xcafe4242;
346 /******************************************************************************
347 * ReportEventA [ADVAPI32.@]
349 * Writes an entry at the end of an event log.
352 * hEventLog [I] Handle of an event log.
353 * wType [I] See MSDN doc.
354 * wCategory [I] Event category.
355 * dwEventID [I] Event identifier.
356 * lpUserSid [I] Current user's security identifier.
357 * wNumStrings [I] Number of insert strings in lpStrings.
358 * dwDataSize [I] Size of event-specific raw data to write.
359 * lpStrings [I] Buffer containing an array of string to be merged.
360 * lpRawData [I] Buffer containing the binary data.
363 * Success: nonzero. Entry was written to the log.
367 * The ReportEvent function adds the time, the entry's length, and the
368 * offsets before storing the entry in the log. If lpUserSid != NULL, the
369 * username is also logged.
371 BOOL WINAPI
ReportEventA ( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
372 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCSTR
*lpStrings
, LPVOID lpRawData
)
374 LPCWSTR
*wideStrArray
;
379 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog
,
380 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
382 if (wNumStrings
== 0) return TRUE
;
383 if (!lpStrings
) return TRUE
;
385 wideStrArray
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR
) * wNumStrings
);
386 for (i
= 0; i
< wNumStrings
; i
++)
388 RtlCreateUnicodeStringFromAsciiz(&str
, lpStrings
[i
]);
389 wideStrArray
[i
] = str
.Buffer
;
391 ret
= ReportEventW(hEventLog
, wType
, wCategory
, dwEventID
, lpUserSid
,
392 wNumStrings
, dwDataSize
, wideStrArray
, lpRawData
);
393 for (i
= 0; i
< wNumStrings
; i
++)
395 HeapFree( GetProcessHeap(), 0, (LPSTR
)wideStrArray
[i
] );
397 HeapFree(GetProcessHeap(), 0, wideStrArray
);
401 /******************************************************************************
402 * ReportEventW [ADVAPI32.@]
406 BOOL WINAPI
ReportEventW( HANDLE hEventLog
, WORD wType
, WORD wCategory
, DWORD dwEventID
,
407 PSID lpUserSid
, WORD wNumStrings
, DWORD dwDataSize
, LPCWSTR
*lpStrings
, LPVOID lpRawData
)
411 FIXME("(%p,0x%04x,0x%04x,0x%08lx,%p,0x%04x,0x%08lx,%p,%p): stub\n", hEventLog
,
412 wType
, wCategory
, dwEventID
, lpUserSid
, wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
416 if (wNumStrings
== 0) return TRUE
;
417 if (!lpStrings
) return TRUE
;
419 for (i
= 0; i
< wNumStrings
; i
++)
423 case EVENTLOG_SUCCESS
:
424 TRACE_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
426 case EVENTLOG_ERROR_TYPE
:
427 ERR_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
429 case EVENTLOG_WARNING_TYPE
:
430 WARN_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));
433 TRACE_(eventlog
)("%s\n", debugstr_w(lpStrings
[i
]));