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.

152 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. custom.cpp
  5. Abstract:
  6. This module implements routines to evaluate
  7. custom mode values by loading the helper dll.
  8. Author:
  9. Vishnu Patankar (VishnuP) - Oct 2001
  10. Environment:
  11. User mode only.
  12. Exported Functions:
  13. Revision History:
  14. Created - Oct 2001
  15. --*/
  16. #include "stdafx.h"
  17. #include "kbproc.h"
  18. #include "process.h"
  19. DWORD
  20. process::SsrpEvaluateCustomFunction(
  21. IN PWSTR pszMachineName,
  22. IN BSTR bstrDLLName,
  23. IN BSTR bstrFunctionName,
  24. OUT BOOL *pbSelect
  25. )
  26. /*++
  27. Routine Description:
  28. Routine called to evaluate custom mode values per role or service
  29. Arguments:
  30. pszMachineName - name of machine to evaluate custom function on
  31. bstrDLLName - name of DLL to load
  32. bstrFunctionName - name of function to evaluate
  33. pbSelect - to emit the boolean evaluation result
  34. Return:
  35. Win32 error code
  36. ++*/
  37. {
  38. DWORD rc = ERROR_SUCCESS;
  39. HINSTANCE hDll = NULL;
  40. typedef DWORD (*PFN_SSR_CUSTOM_FUNCTION)(PWSTR, BOOL *);
  41. PFN_SSR_CUSTOM_FUNCTION pfnSsrpCustomFunction = NULL;
  42. PCHAR pStr = NULL;
  43. DWORD dwBytes = 0;
  44. if (pbSelect == NULL ) {
  45. rc = ERROR_INVALID_PARAMETER;
  46. goto ExitHandler;
  47. }
  48. *pbSelect = FALSE;
  49. hDll = LoadLibrary(bstrDLLName);
  50. if ( hDll == NULL ) {
  51. rc = GetLastError();
  52. goto ExitHandler;
  53. }
  54. //
  55. // convert WCHAR into ASCII
  56. //
  57. dwBytes = WideCharToMultiByte(CP_THREAD_ACP,
  58. 0,
  59. bstrFunctionName,
  60. wcslen(bstrFunctionName),
  61. NULL,
  62. 0,
  63. NULL,
  64. NULL
  65. );
  66. if (dwBytes <= 0) {
  67. rc = ERROR_INVALID_PARAMETER;
  68. goto ExitHandler;
  69. }
  70. pStr = (PCHAR)LocalAlloc(LPTR, dwBytes+1);
  71. if ( pStr == NULL ) {
  72. rc = ERROR_NOT_ENOUGH_MEMORY;
  73. goto ExitHandler;
  74. }
  75. dwBytes = WideCharToMultiByte(CP_THREAD_ACP,
  76. 0,
  77. bstrFunctionName,
  78. wcslen(bstrFunctionName),
  79. pStr,
  80. dwBytes,
  81. NULL,
  82. NULL
  83. );
  84. pfnSsrpCustomFunction =
  85. (PFN_SSR_CUSTOM_FUNCTION)GetProcAddress(
  86. hDll,
  87. pStr);
  88. if ( pfnSsrpCustomFunction == NULL ) {
  89. rc = ERROR_PROC_NOT_FOUND;
  90. goto ExitHandler;
  91. }
  92. rc = (*pfnSsrpCustomFunction )( pszMachineName, pbSelect );
  93. ExitHandler:
  94. if (hDll) {
  95. FreeLibrary(hDll);
  96. }
  97. if (pStr) {
  98. LocalFree(pStr);
  99. }
  100. if (m_bDbg)
  101. wprintf(L" Error %i when processing function %s in dll %s \n",rc, bstrFunctionName, bstrDLLName);
  102. return rc;
  103. }