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.

190 lines
3.6 KiB

  1. /*
  2. * server.c - Server vtable functions module.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.h"
  7. #pragma hdrstop
  8. #include "server.h"
  9. /* Module Variables
  10. *******************/
  11. /*
  12. * Assume that we don't need to serialize access to MhinstServerDLL and Msvt
  13. * since they are only modified during first PROCESS_ATTACH. Access to shared
  14. * data is protected during AttachProcess().
  15. */
  16. PRIVATE_DATA HINSTANCE MhinstServerDLL = NULL;
  17. PRIVATE_DATA SERVERVTABLE Msvt =
  18. {
  19. NULL,
  20. NULL
  21. };
  22. /***************************** Private Functions *****************************/
  23. /* Module Prototypes
  24. ********************/
  25. #ifdef DEBUG
  26. PRIVATE_CODE BOOL IsValidPCSERVERVTABLE(PCSERVERVTABLE);
  27. #endif
  28. #ifdef DEBUG
  29. /*
  30. ** IsValidPCSERVERVTABLE()
  31. **
  32. **
  33. **
  34. ** Arguments:
  35. **
  36. ** Returns:
  37. **
  38. ** Side Effects: none
  39. */
  40. PRIVATE_CODE BOOL IsValidPCSERVERVTABLE(PCSERVERVTABLE pcsvt)
  41. {
  42. return(IS_VALID_READ_PTR(pcsvt, CSERVERVTABLE) &&
  43. IS_VALID_CODE_PTR(pcsvt->GetNetResourceFromLocalPath, PFNGETNETRESOURCEFROMLOCALPATH) &&
  44. IS_VALID_CODE_PTR(pcsvt->GetLocalPathFromNetResource, PFNGETLOCALPATHFROMNETRESOURCE));
  45. }
  46. #endif
  47. /****************************** Public Functions *****************************/
  48. /*
  49. ** ProcessInitServerModule()
  50. **
  51. **
  52. **
  53. ** Arguments:
  54. **
  55. ** Returns:
  56. **
  57. ** Side Effects: none
  58. */
  59. PUBLIC_CODE BOOL ProcessInitServerModule(void)
  60. {
  61. TCHAR rgchDLLPath[MAX_PATH_LEN];
  62. LONG lcb;
  63. /* Load server DLL. */
  64. lcb = SIZEOF(rgchDLLPath);
  65. if (RegQueryValue(HKEY_CLASSES_ROOT, TEXT("Network\\SharingHandler"), rgchDLLPath,
  66. &lcb) == ERROR_SUCCESS)
  67. {
  68. if (rgchDLLPath[0])
  69. {
  70. HINSTANCE hinst;
  71. hinst = LoadLibrary(rgchDLLPath);
  72. if (hinst)
  73. {
  74. PFNGETNETRESOURCEFROMLOCALPATH GetNetResourceFromLocalPath;
  75. PFNGETLOCALPATHFROMNETRESOURCE GetLocalPathFromNetResource;
  76. GetNetResourceFromLocalPath = (PFNGETNETRESOURCEFROMLOCALPATH)
  77. GetProcAddress(hinst, "GetNetResourceFromLocalPathW");
  78. GetLocalPathFromNetResource = (PFNGETLOCALPATHFROMNETRESOURCE)
  79. GetProcAddress(hinst, "GetLocalPathFromNetResourceW");
  80. if (GetNetResourceFromLocalPath && GetLocalPathFromNetResource)
  81. {
  82. ASSERT(AccessIsExclusive());
  83. Msvt.GetNetResourceFromLocalPath = GetNetResourceFromLocalPath;
  84. Msvt.GetLocalPathFromNetResource = GetLocalPathFromNetResource;
  85. MhinstServerDLL = hinst;
  86. ASSERT(IS_VALID_STRUCT_PTR((PCSERVERVTABLE)&Msvt, CSERVERVTABLE));
  87. ASSERT(IS_VALID_HANDLE(MhinstServerDLL, INSTANCE));
  88. TRACE_OUT((TEXT("ProcessInitServerModule(): Loaded sharing handler DLL %s."),
  89. rgchDLLPath));
  90. }
  91. }
  92. }
  93. }
  94. return(TRUE);
  95. }
  96. /*
  97. ** ProcessExitServerModule()
  98. **
  99. **
  100. **
  101. ** Arguments:
  102. **
  103. ** Returns:
  104. **
  105. ** Side Effects: none
  106. */
  107. PUBLIC_CODE void ProcessExitServerModule(void)
  108. {
  109. /* Unload server DLL. */
  110. if (MhinstServerDLL)
  111. {
  112. ASSERT(IS_VALID_HANDLE(MhinstServerDLL, INSTANCE));
  113. EVAL(FreeLibrary(MhinstServerDLL));
  114. MhinstServerDLL = NULL;
  115. TRACE_OUT((TEXT("ProcessExitServerModule(): Unloaded sharing handler DLL.")));
  116. }
  117. return;
  118. }
  119. /*
  120. ** GetServerVTable()
  121. **
  122. **
  123. **
  124. ** Arguments:
  125. **
  126. ** Returns:
  127. **
  128. ** Side Effects: none
  129. */
  130. PUBLIC_CODE BOOL GetServerVTable(PCSERVERVTABLE *ppcsvt)
  131. {
  132. BOOL bResult;
  133. ASSERT(IS_VALID_WRITE_PTR(ppcsvt, PCSERVERVTABLE));
  134. if (MhinstServerDLL)
  135. {
  136. *ppcsvt = &Msvt;
  137. bResult = TRUE;
  138. }
  139. else
  140. bResult = FALSE;
  141. ASSERT(! bResult || IS_VALID_STRUCT_PTR(*ppcsvt, CSERVERVTABLE));
  142. return(bResult);
  143. }