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.

122 lines
3.8 KiB

  1. //=================================================================
  2. //
  3. // UserEnvAPI.cpp
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include <cominit.h>
  10. #include "UserEnvApi.h"
  11. #include "DllWrapperCreatorReg.h"
  12. // {C2BB0B38-8549-48a6-A58E-E704DFC19D80}
  13. static const GUID g_guidUserEnvApi =
  14. { 0xc2bb0b38, 0x8549, 0x48a6, { 0xa5, 0x8e, 0xe7, 0x4, 0xdf, 0xc1, 0x9d, 0x80 } };
  15. static const TCHAR g_tstrUserEnv[] = _T("userenv.dll");
  16. /******************************************************************************
  17. * Register this class with the CResourceManager.
  18. *****************************************************************************/
  19. CDllApiWraprCreatrReg<CUserEnvApi, &g_guidUserEnvApi, g_tstrUserEnv> MyRegisteredUserEnvWrapper;
  20. /******************************************************************************
  21. * Constructor
  22. ******************************************************************************/
  23. CUserEnvApi :: CUserEnvApi (
  24. LPCTSTR a_tstrWrappedDllName
  25. ) : CDllWrapperBase(a_tstrWrappedDllName),
  26. m_pfnDestroyEnvironmentBlock(NULL),
  27. m_pfnCreateEnvironmentBlock(NULL)
  28. {
  29. }
  30. /******************************************************************************
  31. * Destructor
  32. ******************************************************************************/
  33. CUserEnvApi :: ~CUserEnvApi ()
  34. {
  35. }
  36. /******************************************************************************
  37. * Initialization function to check that we obtained function addresses.
  38. * Init should fail only if the minimum set of functions was not available;
  39. * functions added in later versions may or may not be present - it is the
  40. * client's responsibility in such cases to check, in their code, for the
  41. * version of the dll before trying to call such functions. Not doing so
  42. * when the function is not present will result in an AV.
  43. *
  44. * The Init function is called by the WrapperCreatorRegistation class.
  45. ******************************************************************************/
  46. bool CUserEnvApi :: Init ()
  47. {
  48. bool fRet = LoadLibrary () ;
  49. if ( fRet )
  50. {
  51. #ifdef NTONLY
  52. m_pfnDestroyEnvironmentBlock = ( PFN_UserEnv_DESTROYENVIRONMENTBLOCK ) GetProcAddress ( "DestroyEnvironmentBlock" ) ;
  53. m_pfnCreateEnvironmentBlock = ( PFN_UserEnv_CREATEENVIRONMENTBLOCK ) GetProcAddress ( "CreateEnvironmentBlock" ) ;
  54. if ( m_pfnDestroyEnvironmentBlock == NULL ||
  55. m_pfnCreateEnvironmentBlock == NULL )
  56. {
  57. fRet = false ;
  58. LogErrorMessage(L"Failed find entrypoint in userenvapi");
  59. }
  60. #endif
  61. // Check that we have function pointers to functions that should be
  62. // present in all versions of this dll...
  63. // ( in this case, ALL these are functions that may or may not be
  64. // present, so don't bother)
  65. }
  66. return fRet;
  67. }
  68. /******************************************************************************
  69. * Member functions wrapping UserEnv api functions. Add new functions here
  70. * as required.
  71. ******************************************************************************/
  72. // This member function's wrapped pointer has not been validated as it may
  73. // not exist on all versions of the dll. Hence the wrapped function's normal
  74. // return value is returned via the last parameter, while the result of the
  75. // function indicates whether the function existed or not in the wrapped dll.
  76. BOOL CUserEnvApi :: CreateEnvironmentBlock (
  77. OUT LPVOID *lpEnvironment,
  78. IN HANDLE hToken,
  79. IN BOOL bInherit
  80. )
  81. {
  82. return m_pfnCreateEnvironmentBlock (
  83. lpEnvironment,
  84. hToken,
  85. bInherit
  86. ) ;
  87. }
  88. BOOL CUserEnvApi :: DestroyEnvironmentBlock (
  89. IN LPVOID lpEnvironment
  90. )
  91. {
  92. return m_pfnDestroyEnvironmentBlock (
  93. lpEnvironment
  94. ) ;
  95. }