Source code of Windows XP (NT5)
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.

140 lines
3.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // extension.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class BaseCampExtension.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 12/01/1998 Original version.
  16. // 04/01/1999 Add new entry points.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <new>
  21. #include <extension.h>
  22. BaseCampExtension::BaseCampExtension() throw ()
  23. : hModule(NULL),
  24. name(NULL),
  25. initFn(NULL),
  26. termFn(NULL),
  27. processFn(NULL),
  28. processExFn(NULL),
  29. freeAttrsFn(NULL)
  30. { }
  31. BaseCampExtension::~BaseCampExtension() throw ()
  32. {
  33. if (termFn) { termFn(); }
  34. FreeLibrary(hModule);
  35. delete[] name;
  36. }
  37. // Loads the extension DLL.
  38. DWORD BaseCampExtension::load(PCWSTR dllPath) throw ()
  39. {
  40. // Load the extension DLL.
  41. hModule = LoadLibraryW(dllPath);
  42. if (!hModule)
  43. {
  44. DWORD error = GetLastError();
  45. IASTraceFailure("LoadLibraryW", error);
  46. return error;
  47. }
  48. // Look-up the entry points.
  49. initFn = (PRADIUS_EXTENSION_INIT)
  50. GetProcAddress(
  51. hModule,
  52. RADIUS_EXTENSION_INIT
  53. );
  54. processFn = (PRADIUS_EXTENSION_PROCESS)
  55. GetProcAddress(
  56. hModule,
  57. RADIUS_EXTENSION_PROCESS
  58. );
  59. processExFn = (PRADIUS_EXTENSION_PROCESS_EX)
  60. GetProcAddress(
  61. hModule,
  62. RADIUS_EXTENSION_PROCESS_EX
  63. );
  64. freeAttrsFn = (PRADIUS_EXTENSION_FREE_ATTRIBUTES)
  65. GetProcAddress(
  66. hModule,
  67. RADIUS_EXTENSION_FREE_ATTRIBUTES
  68. );
  69. // Validate the entry points.
  70. if (!processFn && !processExFn)
  71. {
  72. IASTraceString("Either RadiusExtensionProcess or "
  73. "RadiusExtensionProcessEx must be defined.");
  74. return ERROR_PROC_NOT_FOUND;
  75. }
  76. if (processExFn && !freeAttrsFn)
  77. {
  78. IASTraceString("RadiusExtensionFreeAttributes must be defined if "
  79. "RadiusExtensionProcessEx is defined.");
  80. return ERROR_PROC_NOT_FOUND;
  81. }
  82. // Initialize the DLL.
  83. if (initFn)
  84. {
  85. DWORD error = initFn();
  86. if (error)
  87. {
  88. IASTraceFailure("RadiusExtensionInit", error);
  89. return error;
  90. }
  91. }
  92. // We look up the term function last, so that it won't get invoked in
  93. // the destructor unless everything else succeeded.
  94. termFn = (PRADIUS_EXTENSION_TERM)
  95. GetProcAddress(
  96. hModule,
  97. RADIUS_EXTENSION_TERM
  98. );
  99. // Strip everything before the last backslash.
  100. const WCHAR* basename = wcsrchr(dllPath, L'\\');
  101. if (basename == NULL)
  102. {
  103. basename = dllPath;
  104. }
  105. else
  106. {
  107. ++basename;
  108. }
  109. // Save the basename.
  110. if (name = new (std::nothrow) WCHAR[wcslen(basename) + 1])
  111. {
  112. wcscpy(name, basename);
  113. }
  114. return NO_ERROR;
  115. }
  116. // Process a request.
  117. DWORD BaseCampExtension::process(
  118. IN CONST RADIUS_ATTRIBUTE* pInAttrs,
  119. OUT PRADIUS_ATTRIBUTE* pOutAttrs,
  120. OUT PRADIUS_ACTION pfAction
  121. ) throw ()
  122. {
  123. // Prefer the new entry point.
  124. return processExFn ? processExFn(pInAttrs, pOutAttrs, pfAction)
  125. : processFn(pInAttrs, pfAction);
  126. }