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.

169 lines
5.0 KiB

  1. //=================================================================
  2. //
  3. // Ws2_32Api.cpp
  4. //
  5. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include <cominit.h>
  10. #include "DllWrapperBase.h"
  11. #include "SecurityApi.h"
  12. #include "DllWrapperCreatorReg.h"
  13. // {C9369990-F3A8-4bac-A360-47BAA0EC47A0}
  14. static const GUID g_guidSecurApi =
  15. { 0xc9369990, 0xf3a8, 0x4bac, { 0xa3, 0x60, 0x47, 0xba, 0xa0, 0xec, 0x47, 0xa0 } };
  16. #if NTONLY >= 5
  17. static const TCHAR g_tstrSecur[] = _T("SECURITY.DLL");
  18. #else
  19. static const TCHAR g_tstrSecur[] = _T("SECUR32.DLL");
  20. #endif
  21. /******************************************************************************
  22. * Register this class with the CResourceManager.
  23. *****************************************************************************/
  24. CDllApiWraprCreatrReg<CSecurityApi, &g_guidSecurApi, g_tstrSecur> g_RegisteredCSecurityWrapper;
  25. /******************************************************************************
  26. * Constructor
  27. ******************************************************************************/
  28. CSecurityApi::CSecurityApi( LPCTSTR a_tstrWrappedDllName )
  29. : CDllWrapperBase( a_tstrWrappedDllName ),
  30. m_pfnInitSecurityInterface(NULL),
  31. m_pSecFuncTable(NULL)
  32. {
  33. }
  34. /******************************************************************************
  35. * Destructor
  36. ******************************************************************************/
  37. CSecurityApi::~CSecurityApi()
  38. {
  39. }
  40. /******************************************************************************
  41. * Initialization function to check that we obtained function addresses.
  42. * Init should fail only if the minimum set of functions was not available;
  43. * functions added in later versions may or may not be present - it is the
  44. * client's responsibility in such cases to check, in their code, for the
  45. * version of the dll before trying to call such functions. Not doing so
  46. * when the function is not present will result in an AV.
  47. *
  48. * The Init function is called by the WrapperCreatorRegistation class.
  49. ******************************************************************************/
  50. bool CSecurityApi::Init()
  51. {
  52. bool fRet = LoadLibrary();
  53. if(fRet)
  54. {
  55. m_pfnInitSecurityInterface =
  56. (PSecurityFunctionTableW(WINAPI *)())GetProcAddress( "InitSecurityInterfaceW" );
  57. m_pSecFuncTable = (PSecurityFunctionTableW)((*m_pfnInitSecurityInterface)());
  58. // Check that we have function pointers to functions that should be
  59. // present in all versions of this dll...
  60. if(m_pfnInitSecurityInterface == NULL ||
  61. m_pSecFuncTable == NULL )
  62. {
  63. fRet = false;
  64. LogErrorMessage(L"Failed find entrypoint in securityapi");
  65. }
  66. else
  67. {
  68. fRet = true;
  69. }
  70. }
  71. return fRet;
  72. }
  73. /******************************************************************************
  74. * Member functions wrapping Ws2_32 api functions. Add new functions here
  75. * as required.
  76. ******************************************************************************/
  77. //
  78. SECURITY_STATUS CSecurityApi::AcquireCredentialsHandleW
  79. (
  80. SEC_WCHAR SEC_FAR *a_pszPrincipal, // Name of principal
  81. SEC_WCHAR SEC_FAR *a_pszPackage, // Name of package
  82. unsigned long a_fCredentialUse, // Flags indicating use
  83. void SEC_FAR *a_pvLogonId, // Pointer to logon ID
  84. void SEC_FAR *a_pAuthData, // Package specific data
  85. SEC_GET_KEY_FN a_pGetKeyFn, // Pointer to GetKey() func
  86. void SEC_FAR *a_pvGetKeyArgument, // Value to pass to GetKey()
  87. PCredHandle a_phCredential, // (out) Cred Handle
  88. PTimeStamp a_ptsExpiry // (out) Lifetime (optional)
  89. )
  90. {
  91. if( m_pSecFuncTable && m_pSecFuncTable->AcquireCredentialsHandleW )
  92. {
  93. return (*m_pSecFuncTable->AcquireCredentialsHandleW)(
  94. a_pszPrincipal,
  95. a_pszPackage,
  96. a_fCredentialUse,
  97. a_pvLogonId,
  98. a_pAuthData,
  99. a_pGetKeyFn,
  100. a_pvGetKeyArgument,
  101. a_phCredential,
  102. a_ptsExpiry ) ;
  103. }
  104. else
  105. {
  106. return E_POINTER ;
  107. }
  108. }
  109. //
  110. SECURITY_STATUS CSecurityApi::QueryCredentialsAttributesW(
  111. PCredHandle a_phCredential, // Credential to query
  112. unsigned long a_ulAttribute, // Attribute to query
  113. void SEC_FAR *a_pBuffer // Buffer for attributes
  114. )
  115. {
  116. if( m_pSecFuncTable && m_pSecFuncTable->QueryCredentialsAttributesW )
  117. {
  118. return (*m_pSecFuncTable->QueryCredentialsAttributesW)(
  119. a_phCredential,
  120. a_ulAttribute,
  121. a_pBuffer ) ;
  122. }
  123. else
  124. {
  125. return E_POINTER ;
  126. }
  127. }
  128. //
  129. SECURITY_STATUS CSecurityApi::FreeCredentialsHandle(
  130. PCredHandle a_phCredential // Handle to free
  131. )
  132. {
  133. if( m_pSecFuncTable && m_pSecFuncTable->FreeCredentialsHandle )
  134. {
  135. return (*m_pSecFuncTable->FreeCredentialsHandle)(
  136. a_phCredential ) ;
  137. }
  138. else
  139. {
  140. return E_POINTER ;
  141. }
  142. }