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.

678 lines
15 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. fpnwutil.cxx
  5. Abstract:
  6. Contains functions that are used by all ADS FPNW APIs
  7. Author:
  8. Ram Viswanathan (ramv) 14-May-1996
  9. Environment:
  10. User Mode -Win32
  11. Notes:
  12. Much of it cloned off private\windows\mpr
  13. Revision History:
  14. --*/
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. //
  19. // global defines
  20. //
  21. #define FPNW_DLL_NAME TEXT("fpnwclnt.dll")
  22. HMODULE vhFpnwDll = NULL;
  23. extern HANDLE FpnwLoadLibSemaphore;
  24. PF_NwApiBufferFree pfNwApiBufferFree = NULL;
  25. PF_NwServerGetInfo pfNwServerGetInfo = NULL;
  26. PF_NwServerSetInfo pfNwServerSetInfo = NULL;
  27. PF_NwVolumeAdd pfNwVolumeAdd = NULL;
  28. PF_NwVolumeDel pfNwVolumeDel = NULL;
  29. PF_NwVolumeEnum pfNwVolumeEnum = NULL;
  30. PF_NwVolumeGetInfo pfNwVolumeGetInfo = NULL;
  31. PF_NwVolumeSetInfo pfNwVolumeSetInfo = NULL;
  32. PF_NwConnectionEnum pfNwConnectionEnum = NULL;
  33. PF_NwConnectionDel pfNwConnectionDel = NULL;
  34. PF_NwFileEnum pfNwFileEnum = NULL;
  35. //
  36. // global functions
  37. //
  38. BOOL MakeSureFpnwDllIsLoaded (VOID);
  39. DWORD FpnwEnterLoadLibCritSect (VOID);
  40. DWORD FpnwLeaveLoadLibCritSect (VOID);
  41. DWORD ADsNwApiBufferFree (
  42. LPVOID pBuffer
  43. )
  44. {
  45. DWORD err ;
  46. // enter critical section to for global data
  47. err = FpnwEnterLoadLibCritSect();
  48. if (0 != err)
  49. {
  50. return err;
  51. }
  52. // if function has not been used before, get its address.
  53. if (pfNwApiBufferFree == NULL)
  54. {
  55. // make sure DLL Is loaded
  56. if (!MakeSureFpnwDllIsLoaded())
  57. {
  58. (void) FpnwLeaveLoadLibCritSect() ;
  59. return(GetLastError()) ;
  60. }
  61. pfNwApiBufferFree = (PF_NwApiBufferFree)
  62. GetProcAddress(vhFpnwDll, "NwApiBufferFree");
  63. }
  64. // if cannot get address, return error
  65. if (pfNwApiBufferFree == NULL)
  66. {
  67. (void) FpnwLeaveLoadLibCritSect() ;
  68. return(GetLastError()) ;
  69. }
  70. // else call it
  71. (void) FpnwLeaveLoadLibCritSect() ;
  72. return (*pfNwApiBufferFree)(pBuffer);
  73. }
  74. DWORD ADsNwServerGetInfo (
  75. IN LPWSTR pServerName OPTIONAL,
  76. IN DWORD dwLevel,
  77. OUT PNWSERVERINFO *ppServerInfo
  78. )
  79. {
  80. DWORD err ;
  81. // enter critical section to for global data
  82. err = FpnwEnterLoadLibCritSect();
  83. if (0 != err)
  84. {
  85. return err;
  86. }
  87. // if function has not been used before, get its address.
  88. if (pfNwServerGetInfo == NULL)
  89. {
  90. // make sure DLL Is loaded
  91. if (!MakeSureFpnwDllIsLoaded())
  92. {
  93. (void) FpnwLeaveLoadLibCritSect() ;
  94. return(GetLastError()) ;
  95. }
  96. pfNwServerGetInfo = (PF_NwServerGetInfo)
  97. GetProcAddress(vhFpnwDll, "NwServerGetInfo");
  98. }
  99. // if cannot get address, return error
  100. if (pfNwServerGetInfo == NULL)
  101. {
  102. (void) FpnwLeaveLoadLibCritSect() ;
  103. return(GetLastError()) ;
  104. }
  105. // else call it
  106. (void) FpnwLeaveLoadLibCritSect() ;
  107. return (*pfNwServerGetInfo)(pServerName,
  108. dwLevel,
  109. ppServerInfo);
  110. }
  111. DWORD ADsNwServerSetInfo (
  112. IN LPWSTR pServerName OPTIONAL,
  113. IN DWORD dwLevel,
  114. IN PNWSERVERINFO pServerInfo
  115. )
  116. {
  117. DWORD err ;
  118. // enter critical section to for global data
  119. err = FpnwEnterLoadLibCritSect();
  120. if (0 != err)
  121. {
  122. return err;
  123. }
  124. // if function has not been used before, get its address.
  125. if (pfNwServerSetInfo == NULL)
  126. {
  127. // make sure DLL Is loaded
  128. if (!MakeSureFpnwDllIsLoaded())
  129. {
  130. (void) FpnwLeaveLoadLibCritSect() ;
  131. return(GetLastError()) ;
  132. }
  133. pfNwServerSetInfo = (PF_NwServerSetInfo)
  134. GetProcAddress(vhFpnwDll, "NwServerSetInfo");
  135. }
  136. // if cannot get address, return error
  137. if (pfNwServerSetInfo == NULL)
  138. {
  139. (void) FpnwLeaveLoadLibCritSect() ;
  140. return(GetLastError()) ;
  141. }
  142. // else call it
  143. (void) FpnwLeaveLoadLibCritSect() ;
  144. return (*pfNwServerSetInfo)(pServerName,
  145. dwLevel,
  146. pServerInfo);
  147. }
  148. DWORD ADsNwVolumeAdd (
  149. IN LPWSTR pServerName OPTIONAL,
  150. IN DWORD dwLevel,
  151. IN PNWVOLUMEINFO pVolumeInfo
  152. )
  153. {
  154. DWORD err ;
  155. // enter critical section to for global data
  156. err = FpnwEnterLoadLibCritSect();
  157. if (0 != err)
  158. {
  159. return err;
  160. }
  161. // if function has not been used before, get its address.
  162. if (pfNwVolumeAdd == NULL)
  163. {
  164. // make sure DLL Is loaded
  165. if (!MakeSureFpnwDllIsLoaded())
  166. {
  167. (void) FpnwLeaveLoadLibCritSect() ;
  168. return(GetLastError()) ;
  169. }
  170. pfNwVolumeAdd = (PF_NwVolumeAdd)
  171. GetProcAddress(vhFpnwDll, "NwVolumeAdd");
  172. }
  173. // if cannot get address, return error
  174. if (pfNwVolumeAdd == NULL)
  175. {
  176. (void) FpnwLeaveLoadLibCritSect() ;
  177. return(GetLastError()) ;
  178. }
  179. // else call it
  180. (void) FpnwLeaveLoadLibCritSect() ;
  181. return (*pfNwVolumeAdd)(pServerName,
  182. dwLevel,
  183. pVolumeInfo);
  184. }
  185. DWORD ADsNwVolumeDel (
  186. IN LPWSTR pServerName OPTIONAL,
  187. IN LPWSTR pVolumeName
  188. )
  189. {
  190. DWORD err ;
  191. // enter critical section to for global data
  192. err = FpnwEnterLoadLibCritSect();
  193. if (0 != err)
  194. {
  195. return err;
  196. }
  197. // if function has not been used before, get its address.
  198. if (pfNwVolumeDel == NULL)
  199. {
  200. // make sure DLL Is loaded
  201. if (!MakeSureFpnwDllIsLoaded())
  202. {
  203. (void) FpnwLeaveLoadLibCritSect() ;
  204. return(GetLastError()) ;
  205. }
  206. pfNwVolumeDel = (PF_NwVolumeDel)
  207. GetProcAddress(vhFpnwDll, "NwVolumeDel");
  208. }
  209. // if cannot get address, return error
  210. if (pfNwVolumeDel == NULL)
  211. {
  212. (void) FpnwLeaveLoadLibCritSect() ;
  213. return(GetLastError()) ;
  214. }
  215. // else call it
  216. (void) FpnwLeaveLoadLibCritSect() ;
  217. return (*pfNwVolumeDel)(pServerName,
  218. pVolumeName);
  219. }
  220. DWORD ADsNwVolumeEnum (
  221. IN LPWSTR pServerName OPTIONAL,
  222. IN DWORD dwLevel,
  223. OUT PNWVOLUMEINFO *ppVolumeInfo,
  224. OUT PDWORD pEntriesRead,
  225. IN OUT PDWORD resumeHandle OPTIONAL
  226. )
  227. {
  228. DWORD err ;
  229. // enter critical section to for global data
  230. err = FpnwEnterLoadLibCritSect();
  231. if (0 != err)
  232. {
  233. return err;
  234. }
  235. // if function has not been used before, get its address.
  236. if (pfNwVolumeEnum == NULL)
  237. {
  238. // make sure DLL Is loaded
  239. if (!MakeSureFpnwDllIsLoaded())
  240. {
  241. (void) FpnwLeaveLoadLibCritSect() ;
  242. return(GetLastError()) ;
  243. }
  244. pfNwVolumeEnum = (PF_NwVolumeEnum)
  245. GetProcAddress(vhFpnwDll, "NwVolumeEnum");
  246. }
  247. // if cannot get address, return error
  248. if (pfNwVolumeEnum == NULL)
  249. {
  250. (void) FpnwLeaveLoadLibCritSect() ;
  251. return(GetLastError()) ;
  252. }
  253. // else call it
  254. (void) FpnwLeaveLoadLibCritSect() ;
  255. return (*pfNwVolumeEnum)(pServerName ,
  256. dwLevel,
  257. ppVolumeInfo,
  258. pEntriesRead,
  259. resumeHandle );
  260. }
  261. DWORD ADsNwVolumeGetInfo (
  262. IN LPWSTR pServerName OPTIONAL,
  263. IN LPWSTR pVolumeName,
  264. IN DWORD dwLevel,
  265. OUT PNWVOLUMEINFO *ppVolumeInfo
  266. )
  267. {
  268. DWORD err ;
  269. // enter critical section to for global data
  270. err = FpnwEnterLoadLibCritSect();
  271. if (0 != err)
  272. {
  273. return err;
  274. }
  275. // if function has not been used before, get its address.
  276. if (pfNwVolumeGetInfo == NULL)
  277. {
  278. // make sure DLL Is loaded
  279. if (!MakeSureFpnwDllIsLoaded())
  280. {
  281. (void) FpnwLeaveLoadLibCritSect() ;
  282. return(GetLastError()) ;
  283. }
  284. pfNwVolumeGetInfo = (PF_NwVolumeGetInfo)
  285. GetProcAddress(vhFpnwDll, "NwVolumeGetInfo");
  286. }
  287. // if cannot get address, return error
  288. if (pfNwVolumeGetInfo == NULL)
  289. {
  290. (void) FpnwLeaveLoadLibCritSect() ;
  291. return(GetLastError()) ;
  292. }
  293. // else call it
  294. (void) FpnwLeaveLoadLibCritSect() ;
  295. return (*pfNwVolumeGetInfo)(pServerName ,
  296. pVolumeName,
  297. dwLevel,
  298. ppVolumeInfo );
  299. }
  300. DWORD ADsNwVolumeSetInfo (
  301. IN LPWSTR pServerName OPTIONAL,
  302. IN LPWSTR pVolumeName,
  303. IN DWORD dwLevel,
  304. IN PNWVOLUMEINFO pVolumeInfo
  305. )
  306. {
  307. DWORD err ;
  308. // enter critical section to for global data
  309. err = FpnwEnterLoadLibCritSect();
  310. if (0 != err)
  311. {
  312. return err;
  313. }
  314. // if function has not been used before, get its address.
  315. if (pfNwVolumeSetInfo == NULL)
  316. {
  317. // make sure DLL Is loaded
  318. if (!MakeSureFpnwDllIsLoaded())
  319. {
  320. (void) FpnwLeaveLoadLibCritSect() ;
  321. return(GetLastError()) ;
  322. }
  323. pfNwVolumeSetInfo = (PF_NwVolumeSetInfo)
  324. GetProcAddress(vhFpnwDll, "NwVolumeSetInfo");
  325. }
  326. // if cannot get address, return error
  327. if (pfNwVolumeSetInfo == NULL)
  328. {
  329. (void) FpnwLeaveLoadLibCritSect() ;
  330. return(GetLastError()) ;
  331. }
  332. // else call it
  333. (void) FpnwLeaveLoadLibCritSect() ;
  334. return (*pfNwVolumeSetInfo)(pServerName ,
  335. pVolumeName,
  336. dwLevel,
  337. pVolumeInfo );
  338. }
  339. DWORD ADsNwConnectionEnum (
  340. IN LPWSTR pServerName OPTIONAL,
  341. IN DWORD dwLevel,
  342. OUT PNWCONNECTIONINFO *ppConnectionInfo,
  343. OUT PDWORD pEntriesRead,
  344. IN OUT PDWORD resumeHandle OPTIONAL
  345. )
  346. {
  347. DWORD err ;
  348. // enter critical section to for global data
  349. err = FpnwEnterLoadLibCritSect();
  350. if (0 != err)
  351. {
  352. return err;
  353. }
  354. // if function has not been used before, get its address.
  355. if (pfNwConnectionEnum == NULL)
  356. {
  357. // make sure DLL Is loaded
  358. if (!MakeSureFpnwDllIsLoaded())
  359. {
  360. (void) FpnwLeaveLoadLibCritSect() ;
  361. return(GetLastError()) ;
  362. }
  363. pfNwConnectionEnum = (PF_NwConnectionEnum)
  364. GetProcAddress(vhFpnwDll, "NwConnectionEnum");
  365. }
  366. // if cannot get address, return error
  367. if (pfNwConnectionEnum == NULL)
  368. {
  369. (void) FpnwLeaveLoadLibCritSect() ;
  370. return(GetLastError()) ;
  371. }
  372. // else call it
  373. (void) FpnwLeaveLoadLibCritSect() ;
  374. return (*pfNwConnectionEnum)(pServerName ,
  375. dwLevel,
  376. ppConnectionInfo,
  377. pEntriesRead,
  378. resumeHandle );
  379. }
  380. DWORD ADsNwConnectionDel (
  381. IN LPWSTR pServerName OPTIONAL,
  382. IN DWORD dwConnectionId
  383. )
  384. {
  385. DWORD err ;
  386. // enter critical section to for global data
  387. err = FpnwEnterLoadLibCritSect();
  388. if (0 != err)
  389. {
  390. return err;
  391. }
  392. // if function has not been used before, get its address.
  393. if (pfNwConnectionDel == NULL)
  394. {
  395. // make sure DLL Is loaded
  396. if (!MakeSureFpnwDllIsLoaded())
  397. {
  398. (void) FpnwLeaveLoadLibCritSect() ;
  399. return(GetLastError()) ;
  400. }
  401. pfNwConnectionDel = (PF_NwConnectionDel)
  402. GetProcAddress(vhFpnwDll, "NwConnectionDel");
  403. }
  404. // if cannot get address, return error
  405. if (pfNwConnectionDel == NULL)
  406. {
  407. (void) FpnwLeaveLoadLibCritSect() ;
  408. return(GetLastError()) ;
  409. }
  410. // else call it
  411. (void) FpnwLeaveLoadLibCritSect() ;
  412. return (*pfNwConnectionDel)(pServerName,
  413. dwConnectionId);
  414. }
  415. DWORD ADsNwFileEnum (
  416. IN LPWSTR pServerName OPTIONAL,
  417. IN DWORD dwLevel,
  418. IN LPWSTR pPathName OPTIONAL,
  419. OUT PNWFILEINFO *ppFileInfo,
  420. OUT PDWORD pEntriesRead,
  421. IN OUT PDWORD resumeHandle OPTIONAL
  422. )
  423. {
  424. DWORD err ;
  425. // enter critical section to for global data
  426. err = FpnwEnterLoadLibCritSect();
  427. if (0 != err)
  428. {
  429. return err;
  430. }
  431. // if function has not been used before, get its address.
  432. if (pfNwFileEnum == NULL)
  433. {
  434. // make sure DLL Is loaded
  435. if (!MakeSureFpnwDllIsLoaded())
  436. {
  437. (void) FpnwLeaveLoadLibCritSect() ;
  438. return(GetLastError()) ;
  439. }
  440. pfNwFileEnum = (PF_NwFileEnum)
  441. GetProcAddress(vhFpnwDll, "NwFileEnum");
  442. }
  443. // if cannot get address, return error
  444. if (pfNwFileEnum == NULL)
  445. {
  446. (void) FpnwLeaveLoadLibCritSect() ;
  447. return(GetLastError()) ;
  448. }
  449. // else call it
  450. (void) FpnwLeaveLoadLibCritSect() ;
  451. return (*pfNwFileEnum)(pServerName ,
  452. dwLevel,
  453. pPathName,
  454. ppFileInfo,
  455. pEntriesRead,
  456. resumeHandle );
  457. }
  458. DWORD
  459. FpnwEnterLoadLibCritSect (
  460. VOID
  461. )
  462. /*++
  463. Routine Description:
  464. This function enters the critical section defined by
  465. FpnwLoadLibrarySemaphore.
  466. Arguments:
  467. none
  468. Return Value:
  469. 0 - The operation was successful.
  470. error code otherwise.
  471. --*/
  472. #define LOADLIBRARY_TIMEOUT 10000L
  473. {
  474. switch( WaitForSingleObject( FpnwLoadLibSemaphore, LOADLIBRARY_TIMEOUT ))
  475. {
  476. case 0:
  477. return 0 ;
  478. case WAIT_TIMEOUT:
  479. return WN_FUNCTION_BUSY ;
  480. case 0xFFFFFFFF:
  481. return (GetLastError()) ;
  482. default:
  483. return WN_WINDOWS_ERROR ;
  484. }
  485. }
  486. DWORD
  487. FpnwLeaveLoadLibCritSect (
  488. VOID
  489. )
  490. /*++
  491. Routine Description:
  492. This function leaves the critical section defined by
  493. FpnwLoadLibrarySemaphore.
  494. Arguments:
  495. none
  496. Return Value:
  497. 0 - The operation was successful.
  498. error code otherwise.
  499. --*/
  500. {
  501. if (!ReleaseSemaphore( FpnwLoadLibSemaphore, 1, NULL ))
  502. return (GetLastError()) ;
  503. return 0 ;
  504. }
  505. /*******************************************************************
  506. NAME: MakeSureFpnwDllIsLoaded
  507. SYNOPSIS: loads the FPNWClnt dll if need.
  508. EXIT: returns TRUE if dll already loaded, or loads
  509. successfully. Returns false otherwise. Caller
  510. should call GetLastError() to determine error.
  511. NOTES: it is up to the caller to call FpnwEnterLoadLibCritSect
  512. before he calls this.
  513. HISTORY:
  514. chuckc 29-Jul-1992 Created
  515. ramv 14-May-1996 Cloned off windows\mpr\mprui.cxx
  516. ********************************************************************/
  517. BOOL MakeSureFpnwDllIsLoaded(void)
  518. {
  519. HMODULE handle ;
  520. // if already load, just return TRUE
  521. if (vhFpnwDll != NULL)
  522. return TRUE ;
  523. // load the library. if it fails, it would have done a SetLastError.
  524. if (!(handle = LoadLibrary(FPNW_DLL_NAME)))
  525. return FALSE ;
  526. // we are cool.
  527. vhFpnwDll = handle ;
  528. return TRUE ;
  529. }