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.

277 lines
7.7 KiB

  1. /*****************************************************************************
  2. *
  3. * fnd.c - Find ... On the Internet
  4. *
  5. *****************************************************************************/
  6. #include "fnd.h"
  7. #include <advpub.h>
  8. #include <shlwapi.h>
  9. #ifdef _WIN64
  10. #pragma pack(push,8)
  11. #endif // _WIN64
  12. /*****************************************************************************
  13. *
  14. * The sqiffle for this file.
  15. *
  16. *****************************************************************************/
  17. #define sqfl sqflDll
  18. /*****************************************************************************
  19. *
  20. * DllGetClassObject
  21. *
  22. * OLE entry point. Produces an IClassFactory for the indicated GUID.
  23. *
  24. *****************************************************************************/
  25. STDAPI
  26. DllGetClassObject(REFCLSID rclsid, RIID riid, PPV ppvObj)
  27. {
  28. HRESULT hres;
  29. EnterProc(DllGetClassObject, (_ "G", rclsid));
  30. if (IsEqualIID(rclsid, &CLSID_Fnd)) {
  31. hres = CFndFactory_New(riid, ppvObj);
  32. } else {
  33. *ppvObj = 0;
  34. hres = CLASS_E_CLASSNOTAVAILABLE;
  35. }
  36. ExitOleProcPpv(ppvObj);
  37. return hres;
  38. }
  39. /*****************************************************************************
  40. *
  41. * DllCanUnloadNow
  42. *
  43. * OLE entry point. Fail iff there are outstanding refs.
  44. *
  45. ;begin_internal
  46. * There is an unavoidable race condition between DllCanUnloadNow
  47. * and the creation of a new reference: Between the time we
  48. * return from DllCanUnloadNow() and the caller inspects the value,
  49. * another thread in the same process may decide to call
  50. * DllGetClassObject, thus suddenly creating an object in this DLL
  51. * when there previously was none.
  52. *
  53. * It is the caller's responsibility to prepare for this possibility;
  54. * there is nothing we can do about it.
  55. ;end_internal
  56. *
  57. *****************************************************************************/
  58. STDMETHODIMP
  59. DllCanUnloadNow(void)
  60. {
  61. return g_cRef ? S_FALSE : S_OK;
  62. }
  63. extern void GetWABDllPath(LPTSTR szPath, ULONG cb);
  64. typedef HINSTANCE (STDAPICALLTYPE *PFNMLLOADLIBARY)(LPCTSTR lpLibFileName, HMODULE hModule, DWORD dwCrossCodePage);
  65. static const TCHAR c_szShlwapiDll[] = TEXT("shlwapi.dll");
  66. static const char c_szDllGetVersion[] = "DllGetVersion";
  67. static const TCHAR c_szWABResourceDLL[] = TEXT("wab32res.dll");
  68. static const TCHAR c_szWABDLL[] = TEXT("wab32.dll");
  69. HINSTANCE LoadWABResourceDLL(HINSTANCE hInstWAB32)
  70. {
  71. TCHAR szPath[MAX_PATH];
  72. HINSTANCE hinstShlwapi;
  73. PFNMLLOADLIBARY pfn;
  74. DLLGETVERSIONPROC pfnVersion;
  75. int iEnd;
  76. DLLVERSIONINFO info;
  77. HINSTANCE hInst = NULL;
  78. hinstShlwapi = LoadLibrary(c_szShlwapiDll);
  79. if (hinstShlwapi != NULL)
  80. {
  81. pfnVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstShlwapi, c_szDllGetVersion);
  82. if (pfnVersion != NULL)
  83. {
  84. info.cbSize = sizeof(DLLVERSIONINFO);
  85. if (SUCCEEDED(pfnVersion(&info)))
  86. {
  87. if (info.dwMajorVersion >= 5)
  88. {
  89. #ifdef UNICODE
  90. pfn = (PFNMLLOADLIBARY)GetProcAddress(hinstShlwapi, (LPCSTR)378);
  91. #else
  92. pfn = (PFNMLLOADLIBARY)GetProcAddress(hinstShlwapi, (LPCSTR)377);
  93. #endif // UNICODE
  94. if (pfn != NULL)
  95. hInst = pfn(c_szWABResourceDLL, hInstWAB32, 0);
  96. }
  97. }
  98. }
  99. FreeLibrary(hinstShlwapi);
  100. }
  101. if (NULL == hInst)
  102. {
  103. GetWABDllPath(szPath, sizeof(szPath));
  104. iEnd = lstrlen(szPath);
  105. if (iEnd > 0)
  106. {
  107. iEnd = iEnd - lstrlen(c_szWABDLL);
  108. StrCpyN(&szPath[iEnd], c_szWABResourceDLL, sizeof(szPath)/sizeof(TCHAR)-iEnd);
  109. hInst = LoadLibrary(szPath);
  110. }
  111. }
  112. return(hInst);
  113. }
  114. /*****************************************************************************
  115. *
  116. * Entry32
  117. *
  118. * DLL entry point.
  119. *
  120. *****************************************************************************/
  121. BOOL APIENTRY
  122. Entry32(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  123. {
  124. switch (dwReason)
  125. {
  126. case DLL_PROCESS_ATTACH:
  127. g_hinstApp = hinst;
  128. g_hinst = LoadWABResourceDLL(hinst);
  129. DisableThreadLibraryCalls(hinst);
  130. break;
  131. case DLL_PROCESS_DETACH:
  132. if (g_hinst)
  133. {
  134. FreeLibrary(g_hinst);
  135. g_hinst = 0;
  136. }
  137. if (g_hinstWABDLL)
  138. {
  139. FreeLibrary(g_hinstWABDLL);
  140. g_hinstWABDLL = 0;
  141. }
  142. break;
  143. }
  144. return 1;
  145. }
  146. /*****************************************************************************
  147. *
  148. * The long-awaited CLSID
  149. *
  150. *****************************************************************************/
  151. #include <initguid.h>
  152. // {37865980-75d1-11cf-bfc7-444553540000}
  153. //DEFINE_GUID(CLSID_Fnd, 0x37865980, 0x75d1, 0x11cf,
  154. // 0xbf,0xc7,0x44,0x45,0x53,0x54,0,0);
  155. // {32714800-2E5F-11d0-8B85-00AA0044F941}
  156. DEFINE_GUID(CLSID_Fnd,
  157. 0x32714800, 0x2e5f, 0x11d0, 0x8b, 0x85, 0x0, 0xaa, 0x0, 0x44, 0xf9, 0x41);
  158. const static char c_szReg[] = "Reg";
  159. const static char c_szUnReg[] = "UnReg";
  160. const static char c_szAdvPackDll[] = "ADVPACK.DLL";
  161. // Selfreg.inx strings
  162. const static char c_szWABPEOPLE[] = "WAB_PEOPLE";
  163. const static char c_szWABFIND[] = "WABFIND";
  164. #define CCHMAX_RES 255
  165. #ifndef ARRAYSIZE
  166. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  167. #endif
  168. HRESULT CallRegInstall(LPCSTR szSection)
  169. {
  170. HRESULT hr;
  171. HINSTANCE hAdvPack;
  172. REGINSTALL pfnri;
  173. char szWabfindDll[MAX_PATH];
  174. char szMenuText[CCHMAX_RES];
  175. char szLocMenuText[CCHMAX_RES];
  176. STRENTRY seReg[3];
  177. STRTABLE stReg;
  178. hr = E_FAIL;
  179. hAdvPack = LoadLibraryA(c_szAdvPackDll);
  180. if (hAdvPack != NULL)
  181. {
  182. // Get Proc Address for registration util
  183. pfnri = (REGINSTALL)GetProcAddress(hAdvPack, achREGINSTALL);
  184. if (pfnri != NULL)
  185. {
  186. UINT ids;
  187. // Figure out the OS we are running on for correct menu text (&People or For &People)
  188. OSVERSIONINFO verinfo;
  189. verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  190. if (GetVersionEx(&verinfo) &&
  191. (VER_PLATFORM_WIN32_NT == verinfo.dwPlatformId) && (5 <= verinfo.dwMajorVersion))
  192. // NT5+
  193. ids = IDS_FORPEOPLE;
  194. else
  195. // Something else
  196. ids = IDS_PEOPLE;
  197. LoadString(g_hinst, ids, szMenuText, CCHMAX_RES);
  198. seReg[0].pszName = (LPSTR)c_szWABPEOPLE;
  199. seReg[0].pszValue = (LPSTR)szMenuText;
  200. // Borrow szWabfindDll to hold the resource DLL name
  201. GetModuleFileName(g_hinst, szWabfindDll, ARRAYSIZE(szWabfindDll));
  202. seReg[1].pszName = "LOC_WAB_PEOPLE";
  203. wnsprintf(szLocMenuText, ARRAYSIZE(szLocMenuText), "@%s,-%d", szWabfindDll, ids);
  204. seReg[1].pszValue = szLocMenuText;
  205. GetModuleFileName(g_hinstApp, szWabfindDll, ARRAYSIZE(szWabfindDll));
  206. seReg[2].pszName = (LPSTR)c_szWABFIND;
  207. seReg[2].pszValue = szWabfindDll;
  208. stReg.cEntries = 3;
  209. stReg.pse = seReg;
  210. // Call the self-reg routine
  211. hr = pfnri(g_hinstApp, szSection, &stReg);
  212. }
  213. FreeLibrary(hAdvPack);
  214. }
  215. return(hr);
  216. }
  217. STDAPI DllRegisterServer(void)
  218. {
  219. HRESULT hr;
  220. hr = CallRegInstall(c_szReg);
  221. return(hr);
  222. }
  223. STDAPI DllUnregisterServer(void)
  224. {
  225. HRESULT hr;
  226. hr = CallRegInstall(c_szUnReg);
  227. return(hr);
  228. }
  229. #ifdef _WIN64
  230. #pragma pack(pop)
  231. #endif //_WIN64