Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1060 lines
22 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // logfile.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class LogFile.
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include "ias.h"
  15. #include "logfile.h"
  16. #include <climits>
  17. #include <new>
  18. #include "iasevent.h"
  19. #include "iastrace.h"
  20. #include "iasutil.h"
  21. #include "mprlog.h"
  22. inline StringSentry::StringSentry(wchar_t* p) throw ()
  23. : sz(p)
  24. {
  25. }
  26. inline StringSentry::~StringSentry() throw ()
  27. {
  28. delete[] sz;
  29. }
  30. inline const wchar_t* StringSentry::Get() const throw ()
  31. {
  32. return sz;
  33. }
  34. inline bool StringSentry::IsNull() const throw ()
  35. {
  36. return sz == 0;
  37. }
  38. inline StringSentry::operator const wchar_t*() const throw ()
  39. {
  40. return sz;
  41. }
  42. inline StringSentry::operator wchar_t*() throw ()
  43. {
  44. return sz;
  45. }
  46. inline void StringSentry::Swap(StringSentry& other) throw ()
  47. {
  48. wchar_t* temp = sz;
  49. sz = other.sz;
  50. other.sz = temp;
  51. }
  52. inline StringSentry& StringSentry::operator=(wchar_t* p) throw ()
  53. {
  54. if (sz != p)
  55. {
  56. delete[] sz;
  57. sz = p;
  58. }
  59. return *this;
  60. }
  61. LogFile::LogFile() throw ()
  62. : deleteIfFull(true),
  63. period(IAS_LOGGING_UNLIMITED_SIZE),
  64. seqNum(0),
  65. file(INVALID_HANDLE_VALUE),
  66. firstDayOfWeek(0),
  67. iasEventSource(RegisterEventSourceW(0, L"IAS")),
  68. rasEventSource(RegisterEventSourceW(0, L"RemoteAccess"))
  69. {
  70. maxSize.QuadPart = _UI64_MAX;
  71. wchar_t buffer[4];
  72. if (GetLocaleInfo(
  73. LOCALE_SYSTEM_DEFAULT,
  74. LOCALE_IFIRSTDAYOFWEEK,
  75. buffer,
  76. sizeof(buffer)/sizeof(wchar_t)
  77. ))
  78. {
  79. // The locale info calls Monday day zero, while SYSTEMTIME calls
  80. // Sunday day zero.
  81. firstDayOfWeek = (1 + static_cast<DWORD>(_wtoi(buffer))) % 7;
  82. }
  83. }
  84. LogFile::~LogFile() throw ()
  85. {
  86. Close();
  87. if (iasEventSource != 0)
  88. {
  89. DeregisterEventSource(iasEventSource);
  90. }
  91. if (rasEventSource != 0)
  92. {
  93. DeregisterEventSource(rasEventSource);
  94. }
  95. }
  96. void LogFile::SetDeleteIfFull(bool newVal) throw ()
  97. {
  98. Lock();
  99. deleteIfFull = newVal;
  100. Unlock();
  101. IASTracePrintf("LogFile.DeleteIfFull = %s", (newVal ? "true" : "false"));
  102. }
  103. DWORD LogFile::SetDirectory(const wchar_t* newVal) throw ()
  104. {
  105. if (newVal == 0)
  106. {
  107. return ERROR_INVALID_PARAMETER;
  108. }
  109. // How big is the expanded directory string?
  110. DWORD len = ExpandEnvironmentStringsW(
  111. newVal,
  112. 0,
  113. 0
  114. );
  115. if (len == 0)
  116. {
  117. return GetLastError();
  118. }
  119. // Allocate memory to hold the new directory and expand any variables.
  120. StringSentry newDirectory(new (std::nothrow) wchar_t[len]);
  121. if (newDirectory.IsNull())
  122. {
  123. return E_OUTOFMEMORY;
  124. }
  125. len = ExpandEnvironmentStringsW(
  126. newVal,
  127. newDirectory,
  128. len
  129. );
  130. if (len == 0)
  131. {
  132. return GetLastError();
  133. }
  134. // Does it end in a backlash ?
  135. if ((len > 1) && (newDirectory[len - 2] == L'\\'))
  136. {
  137. // Null out the backslash.
  138. newDirectory[len - 2] = L'\0';
  139. }
  140. Lock();
  141. DWORD error = NO_ERROR;
  142. // Is this a new directory?
  143. if (directory.IsNull() || (wcscmp(newDirectory, directory) != 0))
  144. {
  145. // Save the new value.
  146. directory.Swap(newDirectory);
  147. // Close the old file.
  148. Close();
  149. // Rescan the sequence number.
  150. error = UpdateSequence();
  151. }
  152. Unlock();
  153. IASTracePrintf("LogFile.Directory = %S", directory.Get());
  154. return error;
  155. }
  156. void LogFile::SetMaxSize(const ULONGLONG& newVal) throw ()
  157. {
  158. Lock();
  159. maxSize.QuadPart = newVal;
  160. Unlock();
  161. IASTracePrintf(
  162. "LogFile.MaxSize = 0x%08X%08X",
  163. maxSize.HighPart,
  164. maxSize.LowPart
  165. );
  166. }
  167. DWORD LogFile::SetPeriod(NEW_LOG_FILE_FREQUENCY newVal) throw ()
  168. {
  169. DWORD error = NO_ERROR;
  170. Lock();
  171. if (newVal != period)
  172. {
  173. // A new period means a new filename.
  174. Close();
  175. period = newVal;
  176. if (!directory.IsNull())
  177. {
  178. error = UpdateSequence();
  179. }
  180. }
  181. Unlock();
  182. IASTracePrintf("LogFile.Period = %u", newVal);
  183. return error;
  184. }
  185. bool LogFile::Write(
  186. IASPROTOCOL protocol,
  187. const SYSTEMTIME& st,
  188. const BYTE* buf,
  189. DWORD buflen,
  190. bool allowRetry
  191. ) throw ()
  192. {
  193. Lock();
  194. // Save the currently cached file handle (may be null or stale).
  195. HANDLE cached = file;
  196. // Get the correct handle for the write.
  197. CheckFileHandle(protocol, st, buflen);
  198. bool success = false;
  199. if (file != INVALID_HANDLE_VALUE)
  200. {
  201. DWORD error;
  202. do
  203. {
  204. DWORD bytesWritten;
  205. if (WriteFile(file, buf, buflen, &bytesWritten, 0))
  206. {
  207. currentSize.QuadPart += buflen;
  208. success = true;
  209. error = NO_ERROR;
  210. }
  211. else
  212. {
  213. error = GetLastError();
  214. IASTracePrintf("WriteFile failed; error = %lu", error);
  215. }
  216. }
  217. while ((error == ERROR_DISK_FULL) && DeleteOldestFile(protocol, st));
  218. if ((error != NO_ERROR) && (error != ERROR_DISK_FULL))
  219. {
  220. // If we used a cached handle and allowRetry, then try again.
  221. bool retry = (cached == file) && allowRetry;
  222. // Prevent others from using the bad handle.
  223. Close();
  224. // Now that we've closed the bad handle try again.
  225. if (retry)
  226. {
  227. // Set allowRetry to false to prevent an infinite recursion.
  228. success = Write(protocol, st, buf, buflen, false);
  229. }
  230. }
  231. }
  232. Unlock();
  233. return success;
  234. }
  235. void LogFile::Close() throw ()
  236. {
  237. Lock();
  238. if (file != INVALID_HANDLE_VALUE)
  239. {
  240. CloseHandle(file);
  241. file = INVALID_HANDLE_VALUE;
  242. }
  243. Unlock();
  244. }
  245. void LogFile::CheckFileHandle(
  246. IASPROTOCOL protocol,
  247. const SYSTEMTIME& st,
  248. DWORD buflen
  249. ) throw ()
  250. {
  251. // Do we have a valid handle?
  252. if (file == INVALID_HANDLE_VALUE)
  253. {
  254. OpenFile(protocol, st);
  255. }
  256. // Have we reached the next period?
  257. switch (period)
  258. {
  259. case IAS_LOGGING_DAILY:
  260. {
  261. if ((st.wDay != whenOpened.wDay) ||
  262. (st.wMonth != whenOpened.wMonth) ||
  263. (st.wYear != whenOpened.wYear))
  264. {
  265. OpenFile(protocol, st);
  266. }
  267. break;
  268. }
  269. case IAS_LOGGING_WEEKLY:
  270. {
  271. if ((GetWeekOfMonth(st) != weekOpened) ||
  272. (st.wMonth != whenOpened.wMonth) ||
  273. (st.wYear != whenOpened.wYear))
  274. {
  275. OpenFile(protocol, st);
  276. }
  277. break;
  278. }
  279. case IAS_LOGGING_MONTHLY:
  280. {
  281. if ((st.wMonth != whenOpened.wMonth) ||
  282. (st.wYear != whenOpened.wYear))
  283. {
  284. OpenFile(protocol, st);
  285. }
  286. break;
  287. }
  288. case IAS_LOGGING_WHEN_FILE_SIZE_REACHES:
  289. {
  290. while ((currentSize.QuadPart + buflen) > maxSize.QuadPart)
  291. {
  292. ++seqNum;
  293. OpenFile(protocol, st);
  294. }
  295. break;
  296. }
  297. case IAS_LOGGING_UNLIMITED_SIZE:
  298. default:
  299. {
  300. break;
  301. }
  302. }
  303. }
  304. HANDLE LogFile::CreateDirectoryAndFile() throw ()
  305. {
  306. if (filename.IsNull())
  307. {
  308. SetLastError(ERROR_INVALID_FUNCTION);
  309. return INVALID_HANDLE_VALUE;
  310. }
  311. // Open the file if it exists or else create a new one.
  312. HANDLE newFile = CreateFileW(
  313. filename,
  314. GENERIC_WRITE,
  315. FILE_SHARE_READ,
  316. 0,
  317. OPEN_ALWAYS,
  318. FILE_FLAG_SEQUENTIAL_SCAN,
  319. 0
  320. );
  321. if (newFile != INVALID_HANDLE_VALUE)
  322. {
  323. return newFile;
  324. }
  325. if (GetLastError() != ERROR_PATH_NOT_FOUND)
  326. {
  327. return INVALID_HANDLE_VALUE;
  328. }
  329. // If the path is just a drive letter, there's nothing we can do.
  330. size_t len = wcslen(directory);
  331. if ((len != 0) && (directory[len - 1] == L':'))
  332. {
  333. return INVALID_HANDLE_VALUE;
  334. }
  335. // Otherwise, let's try to create the directory.
  336. if (!CreateDirectoryW(directory, NULL))
  337. {
  338. IASTracePrintf(
  339. "CreateDirectoryW(%S) failed; error = %lu",
  340. directory.Get(),
  341. GetLastError()
  342. );
  343. return INVALID_HANDLE_VALUE;
  344. }
  345. // Then try again to create the file.
  346. newFile = CreateFileW(
  347. filename,
  348. GENERIC_WRITE,
  349. FILE_SHARE_READ,
  350. 0,
  351. OPEN_ALWAYS,
  352. FILE_FLAG_SEQUENTIAL_SCAN,
  353. 0
  354. );
  355. if (newFile == INVALID_HANDLE_VALUE)
  356. {
  357. IASTracePrintf(
  358. "CreateFileW(%S) failed; error = %lu",
  359. filename.Get(),
  360. GetLastError()
  361. );
  362. }
  363. return newFile;
  364. }
  365. bool LogFile::DeleteOldestFile(
  366. IASPROTOCOL protocol,
  367. const SYSTEMTIME& st
  368. ) throw ()
  369. {
  370. if (!deleteIfFull ||
  371. (period == IAS_LOGGING_UNLIMITED_SIZE) ||
  372. directory.IsNull() ||
  373. filename.IsNull())
  374. {
  375. return false;
  376. }
  377. bool success = false;
  378. // Find the lowest (oldest) file number.
  379. unsigned int number;
  380. DWORD error = FindFileNumber(st, true, number);
  381. switch (error)
  382. {
  383. case NO_ERROR:
  384. {
  385. // Convert the file number to a file name.
  386. StringSentry oldfile(FormatFileName(number));
  387. if (oldfile.IsNull())
  388. {
  389. ReportOldFileDeleteError(protocol, L"", ERROR_NOT_ENOUGH_MEMORY);
  390. }
  391. else if (_wcsicmp(oldfile, filename) == 0)
  392. {
  393. // Oldest file is the current file.
  394. ReportOldFileNotFound(protocol);
  395. }
  396. else if (DeleteFileW(oldfile))
  397. {
  398. ReportOldFileDeleted(protocol, oldfile);
  399. success = true;
  400. }
  401. else
  402. {
  403. ReportOldFileDeleteError(protocol, oldfile, GetLastError());
  404. }
  405. break;
  406. }
  407. case ERROR_FILE_NOT_FOUND:
  408. case ERROR_PATH_NOT_FOUND:
  409. {
  410. ReportOldFileNotFound(protocol);
  411. break;
  412. }
  413. default:
  414. {
  415. ReportOldFileDeleteError(protocol, L"", error);
  416. break;
  417. }
  418. }
  419. return success;
  420. }
  421. unsigned int LogFile::ExtendFileNumber(
  422. const SYSTEMTIME& st,
  423. unsigned int narrow
  424. ) const throw ()
  425. {
  426. unsigned int wide = narrow;
  427. switch (period)
  428. {
  429. case IAS_LOGGING_DAILY:
  430. case IAS_LOGGING_WEEKLY:
  431. {
  432. unsigned int century = st.wYear / 100;
  433. if (GetFileNumber(st) >= narrow)
  434. {
  435. wide += century * 1000000;
  436. }
  437. else
  438. {
  439. // We assume that log files are never from the future, so this file
  440. // must be from the previous century.
  441. wide += (century - 1) * 1000000;
  442. }
  443. break;
  444. }
  445. case IAS_LOGGING_MONTHLY:
  446. {
  447. unsigned int century = st.wYear / 100;
  448. if (GetFileNumber(st) >= narrow)
  449. {
  450. wide += century * 10000;
  451. }
  452. else
  453. {
  454. // We assume that log files are never from the future, so this file
  455. // must be from the previous century.
  456. wide += (century - 1) * 10000;
  457. }
  458. break;
  459. }
  460. case IAS_LOGGING_UNLIMITED_SIZE:
  461. case IAS_LOGGING_WHEN_FILE_SIZE_REACHES:
  462. default:
  463. {
  464. break;
  465. }
  466. }
  467. return wide;
  468. }
  469. DWORD LogFile::FindFileNumber(
  470. const SYSTEMTIME& st,
  471. bool findLowest,
  472. unsigned int& result
  473. ) const throw ()
  474. {
  475. // Can't call this function until after the directory's been initialized.
  476. if (directory.IsNull())
  477. {
  478. return ERROR_INVALID_FUNCTION;
  479. }
  480. // The search filter passed to FindFirstFileW.
  481. StringSentry filter(
  482. ias_makewcs(
  483. directory.Get(),
  484. L"\\",
  485. GetFileNameFilter(),
  486. 0
  487. )
  488. );
  489. if (filter.IsNull())
  490. {
  491. return ERROR_NOT_ENOUGH_MEMORY;
  492. }
  493. // Format string used for extracting the numeric portion of the filename.
  494. const wchar_t* format = GetFileNameFormat();
  495. WIN32_FIND_DATAW findData;
  496. HANDLE hFind = FindFirstFileW(filter, &findData);
  497. if (hFind == INVALID_HANDLE_VALUE)
  498. {
  499. return GetLastError();
  500. }
  501. // Stores the best extended result found so far.
  502. unsigned int bestWideMatch = findLowest ? UINT_MAX : 0;
  503. // Stores the narrow version of bestWideMatch.
  504. unsigned int bestNarrowMatch = UINT_MAX;
  505. // Iterate through all the files that match the filter.
  506. do
  507. {
  508. // Extract the numeric portion and test its validity.
  509. unsigned int narrow;
  510. if (swscanf(findData.cFileName, format, &narrow) == 1)
  511. {
  512. if (IsValidFileNumber(wcslen(findData.cFileName), narrow))
  513. {
  514. // Extend the file number to include the century.
  515. unsigned int wide = ExtendFileNumber(st, narrow);
  516. // Update bestMatch as appropriate.
  517. if (wide < bestWideMatch)
  518. {
  519. if (findLowest)
  520. {
  521. bestWideMatch = wide;
  522. bestNarrowMatch = narrow;
  523. }
  524. }
  525. else
  526. {
  527. if (!findLowest)
  528. {
  529. bestWideMatch = wide;
  530. bestNarrowMatch = narrow;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. while (FindNextFileW(hFind, &findData));
  537. FindClose(hFind);
  538. // Did we find a valid file?
  539. if (bestNarrowMatch == UINT_MAX)
  540. {
  541. return ERROR_FILE_NOT_FOUND;
  542. }
  543. // We found a valid file, so return the result.
  544. result = bestNarrowMatch;
  545. return NO_ERROR;
  546. }
  547. wchar_t* LogFile::FormatFileName(unsigned int number) const throw ()
  548. {
  549. // Longest filename is iaslog4294967295.log
  550. wchar_t buffer[21];
  551. swprintf(buffer, GetFileNameFormat(), number);
  552. return ias_makewcs(directory.Get(), L"\\", buffer, 0);
  553. }
  554. const wchar_t* LogFile::GetFileNameFilter() const throw ()
  555. {
  556. const wchar_t* filter;
  557. switch (period)
  558. {
  559. case IAS_LOGGING_WHEN_FILE_SIZE_REACHES:
  560. {
  561. filter = L"iaslog*.log";
  562. break;
  563. }
  564. case IAS_LOGGING_DAILY:
  565. case IAS_LOGGING_WEEKLY:
  566. case IAS_LOGGING_MONTHLY:
  567. {
  568. filter = L"IN*.log";
  569. break;
  570. }
  571. case IAS_LOGGING_UNLIMITED_SIZE:
  572. default:
  573. {
  574. filter = L"iaslog.log";
  575. break;
  576. }
  577. }
  578. return filter;
  579. }
  580. const wchar_t* LogFile::GetFileNameFormat() const throw ()
  581. {
  582. const wchar_t* format;
  583. switch (period)
  584. {
  585. case IAS_LOGGING_WHEN_FILE_SIZE_REACHES:
  586. {
  587. format = L"iaslog%u.log";
  588. break;
  589. }
  590. case IAS_LOGGING_DAILY:
  591. case IAS_LOGGING_WEEKLY:
  592. {
  593. format = L"IN%06u.log";
  594. break;
  595. }
  596. case IAS_LOGGING_MONTHLY:
  597. {
  598. format = L"IN%04u.log";
  599. break;
  600. }
  601. case IAS_LOGGING_UNLIMITED_SIZE:
  602. default:
  603. {
  604. format = L"iaslog.log";
  605. break;
  606. }
  607. }
  608. return format;
  609. }
  610. unsigned int LogFile::GetFileNumber(const SYSTEMTIME& st) const throw ()
  611. {
  612. unsigned int number;
  613. switch (period)
  614. {
  615. case IAS_LOGGING_WHEN_FILE_SIZE_REACHES:
  616. {
  617. number = seqNum;
  618. break;
  619. }
  620. case IAS_LOGGING_DAILY:
  621. {
  622. number = ((st.wYear % 100) * 10000) + (st.wMonth * 100) + st.wDay;
  623. break;
  624. }
  625. case IAS_LOGGING_WEEKLY:
  626. {
  627. number = ((st.wYear % 100) * 10000) + (st.wMonth * 100) +
  628. GetWeekOfMonth(st);
  629. break;
  630. }
  631. case IAS_LOGGING_MONTHLY:
  632. {
  633. number = ((st.wYear % 100) * 100) + st.wMonth;
  634. break;
  635. }
  636. case IAS_LOGGING_UNLIMITED_SIZE:
  637. default:
  638. {
  639. number = 0;
  640. break;
  641. }
  642. }
  643. return number;
  644. }
  645. DWORD LogFile::GetWeekOfMonth(const SYSTEMTIME& st) const throw ()
  646. {
  647. DWORD dom = st.wDay - 1;
  648. DWORD wom = 1 + dom / 7;
  649. if ((dom % 7) > ((st.wDayOfWeek + 7 - firstDayOfWeek) % 7))
  650. {
  651. ++wom;
  652. }
  653. return wom;
  654. }
  655. bool LogFile::IsValidFileNumber(size_t len, unsigned int num) const throw ()
  656. {
  657. bool valid;
  658. switch (period)
  659. {
  660. case IAS_LOGGING_DAILY:
  661. {
  662. // INyymmdd.log
  663. unsigned int day = num % 100;
  664. unsigned int month = (num / 100) % 100;
  665. valid = (len == 12) &&
  666. (day >= 1) && (day <= 31) &&
  667. (month >= 1) && (month <= 12);
  668. break;
  669. }
  670. case IAS_LOGGING_WEEKLY:
  671. {
  672. // INyymmww.log
  673. unsigned int week = num % 100;
  674. unsigned int month = (num / 100) % 100;
  675. valid = (len == 12) &&
  676. (week >= 1) && (week <= 5) &&
  677. (month >= 1) && (month <= 12);
  678. break;
  679. }
  680. case IAS_LOGGING_MONTHLY:
  681. {
  682. // INyymm.log
  683. unsigned int month = num % 100;
  684. valid = (len == 10) && (month >= 1) && (month <= 12);
  685. break;
  686. }
  687. case IAS_LOGGING_WHEN_FILE_SIZE_REACHES:
  688. {
  689. // iaslogN.log
  690. valid = (len > 10);
  691. break;
  692. }
  693. case IAS_LOGGING_UNLIMITED_SIZE:
  694. default:
  695. {
  696. // Doesn't contain a number, so never valid.
  697. valid = false;
  698. break;
  699. }
  700. }
  701. return valid;
  702. }
  703. void LogFile::OpenFile(IASPROTOCOL protocol, const SYSTEMTIME& st) throw ()
  704. {
  705. // Save the time when the file was opened.
  706. whenOpened = st;
  707. weekOpened = GetWeekOfMonth(st);
  708. // Assume the currentSize is zero until we successfully open a file.
  709. currentSize.QuadPart = 0;
  710. // Close the exisisting file.
  711. Close();
  712. filename = FormatFileName(GetFileNumber(st));
  713. if (!filename.IsNull())
  714. {
  715. HANDLE newFile;
  716. do
  717. {
  718. newFile = CreateDirectoryAndFile();
  719. }
  720. while ((newFile == INVALID_HANDLE_VALUE) &&
  721. (GetLastError() == ERROR_DISK_FULL) &&
  722. DeleteOldestFile(protocol, st));
  723. if (newFile != INVALID_HANDLE_VALUE)
  724. {
  725. file = newFile;
  726. // Get the size of the file.
  727. currentSize.LowPart = GetFileSize(file, &currentSize.HighPart);
  728. if ((currentSize.LowPart == 0xFFFFFFFF) &&
  729. (GetLastError() != NO_ERROR))
  730. {
  731. Close();
  732. }
  733. else
  734. {
  735. // Start writing new information at the end of the file.
  736. SetFilePointer(file, 0, 0, FILE_END);
  737. }
  738. }
  739. }
  740. }
  741. DWORD LogFile::UpdateSequence() throw ()
  742. {
  743. if (period != IAS_LOGGING_WHEN_FILE_SIZE_REACHES)
  744. {
  745. seqNum = 0;
  746. }
  747. else
  748. {
  749. // SYSTEMTIME is ignored for sized files, so we can simply pass an
  750. // unitialized struct.
  751. SYSTEMTIME st;
  752. DWORD error = FindFileNumber(st, false, seqNum);
  753. switch (error)
  754. {
  755. case NO_ERROR:
  756. {
  757. break;
  758. }
  759. case ERROR_FILE_NOT_FOUND:
  760. case ERROR_PATH_NOT_FOUND:
  761. {
  762. seqNum = 0;
  763. break;
  764. }
  765. default:
  766. {
  767. return error;
  768. }
  769. }
  770. }
  771. return NO_ERROR;
  772. }
  773. void LogFile::ReportOldFileDeleteError(
  774. IASPROTOCOL protocol,
  775. const wchar_t* oldfile,
  776. DWORD error
  777. ) const throw ()
  778. {
  779. HANDLE eventLog;
  780. DWORD eventId;
  781. switch (protocol)
  782. {
  783. case IAS_PROTOCOL_RADIUS:
  784. {
  785. eventLog = iasEventSource;
  786. eventId = ACCT_E_OLD_LOG_DELETE_ERROR;
  787. break;
  788. }
  789. case IAS_PROTOCOL_RAS:
  790. {
  791. eventLog = rasEventSource;
  792. eventId = ROUTERLOG_OLD_LOG_DELETE_ERROR;
  793. break;
  794. }
  795. default:
  796. {
  797. return;
  798. }
  799. }
  800. ReportEventW(
  801. eventLog,
  802. EVENTLOG_ERROR_TYPE,
  803. 0,
  804. eventId,
  805. 0,
  806. 1,
  807. sizeof(error),
  808. &oldfile,
  809. &error
  810. );
  811. }
  812. void LogFile::ReportOldFileDeleted(
  813. IASPROTOCOL protocol,
  814. const wchar_t* oldfile
  815. ) const throw ()
  816. {
  817. HANDLE eventLog;
  818. DWORD eventId;
  819. switch (protocol)
  820. {
  821. case IAS_PROTOCOL_RADIUS:
  822. {
  823. eventLog = iasEventSource;
  824. eventId = ACCT_S_OLD_LOG_DELETED;
  825. break;
  826. }
  827. case IAS_PROTOCOL_RAS:
  828. {
  829. eventLog = rasEventSource;
  830. eventId = ROUTERLOG_OLD_LOG_DELETED;
  831. break;
  832. }
  833. default:
  834. {
  835. return;
  836. }
  837. }
  838. ReportEventW(
  839. eventLog,
  840. EVENTLOG_SUCCESS,
  841. 0,
  842. eventId,
  843. 0,
  844. 1,
  845. 0,
  846. &oldfile,
  847. 0
  848. );
  849. }
  850. void LogFile::ReportOldFileNotFound(
  851. IASPROTOCOL protocol
  852. ) const throw ()
  853. {
  854. HANDLE eventLog;
  855. DWORD eventId;
  856. switch (protocol)
  857. {
  858. case IAS_PROTOCOL_RADIUS:
  859. {
  860. eventLog = iasEventSource;
  861. eventId = ACCT_I_OLD_LOG_NOT_FOUND;
  862. break;
  863. }
  864. case IAS_PROTOCOL_RAS:
  865. {
  866. eventLog = rasEventSource;
  867. eventId = ROUTERLOG_OLD_LOG_NOT_FOUND;
  868. break;
  869. }
  870. default:
  871. {
  872. return;
  873. }
  874. }
  875. ReportEventW(
  876. eventLog,
  877. EVENTLOG_INFORMATION_TYPE,
  878. 0,
  879. eventId,
  880. 0,
  881. 0,
  882. 0,
  883. 0,
  884. 0
  885. );
  886. }