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.

4346 lines
96 KiB

  1. /* ----------------------------------------------------------------------
  2. Module: ULS.DLL (Service Provider)
  3. File: ldapsp.cpp
  4. Content: This file contains the ldap service provider interface.
  5. History:
  6. 10/15/96 Chu, Lon-Chan [lonchanc]
  7. Created.
  8. Copyright (c) Microsoft Corporation 1996-1997
  9. ---------------------------------------------------------------------- */
  10. #include "ulsp.h"
  11. #include "spinc.h"
  12. // Window handle of this layer's hidden window
  13. //
  14. HWND g_hWndHidden = NULL;
  15. // Window handle of the COM layer's hidden window
  16. //
  17. HWND g_hWndNotify = NULL;
  18. // Internal request thread
  19. //
  20. HANDLE g_hReqThread = NULL;
  21. DWORD g_dwReqThreadID = 0;
  22. // Hidden window class
  23. //
  24. extern TCHAR c_szWindowClassName[];
  25. // Global generator for response ID
  26. //
  27. ULONG g_uRespID = 1;
  28. // Global
  29. //
  30. DWORD g_dwClientSig = 0;
  31. // Global counter for the times of initializations
  32. //
  33. LONG g_cInitialized = 0;
  34. // Internal functions prototypes
  35. //
  36. VOID BuildStdAttrNameArray ( VOID );
  37. TCHAR *AddBaseToFilter ( TCHAR *, const TCHAR * );
  38. HRESULT _EnumClientsEx ( ULONG, TCHAR *, TCHAR *, ULONG, TCHAR *, LDAP_ASYNCINFO * );
  39. /* ----------------------------------------------------------------------
  40. UlsLdap_Initialize
  41. History:
  42. 10/15/96 Chu, Lon-Chan [lonchanc]
  43. Created.
  44. 10/30/96 Chu, Lon-Chan [lonchanc]
  45. Tested on ILS (7438)
  46. ---------------------------------------------------------------------- */
  47. HRESULT UlsLdap_Initialize ( HWND hWndCallback )
  48. {
  49. HRESULT hr;
  50. // Make sure this service provider is not initialized twice
  51. //
  52. if (g_cInitialized++ != 0)
  53. return S_OK;
  54. #ifdef DEBUG
  55. // Validate handler table
  56. //
  57. extern VOID DbgValidateHandlerTable ( VOID );
  58. DbgValidateHandlerTable ();
  59. #endif
  60. // Validate standard attribute name table
  61. //
  62. #ifdef DEBUG
  63. extern VOID DbgValidateStdAttrNameArray ( VOID );
  64. DbgValidateStdAttrNameArray ();
  65. #endif
  66. // Clean up the events for safe rollback
  67. //
  68. ZeroMemory (&g_ahThreadWaitFor[0], NUM_THREAD_WAIT_FOR * sizeof (HANDLE));
  69. // Initialize global settings via registry
  70. //
  71. if (! GetRegistrySettings ())
  72. {
  73. MyAssert (FALSE);
  74. }
  75. // Make sure the uls window handle is valid
  76. //
  77. if (! MyIsWindow (hWndCallback))
  78. {
  79. MyAssert (FALSE);
  80. g_cInitialized--;
  81. MyAssert (g_cInitialized == 0);
  82. return ILS_E_HANDLE;
  83. }
  84. // Cache the uls window handle
  85. //
  86. g_hWndNotify = hWndCallback;
  87. // Initialize ILS specifics
  88. //
  89. hr = IlsInitialize ();
  90. if (hr != S_OK)
  91. return hr;
  92. // Create events for inter-thread synchronization
  93. //
  94. g_fExitNow = FALSE;
  95. for (INT i = 0; i < NUM_THREAD_WAIT_FOR; i++)
  96. {
  97. g_ahThreadWaitFor[i] = CreateEvent (NULL, // no security
  98. FALSE, // auto reset
  99. FALSE, // not signaled initially
  100. NULL); // no event name
  101. if (g_ahThreadWaitFor[i] == NULL)
  102. {
  103. hr = ILS_E_FAIL;
  104. goto MyExit;
  105. }
  106. }
  107. // Create an internal session container
  108. //
  109. g_pSessionContainer = new SP_CSessionContainer;
  110. if (g_pSessionContainer == NULL)
  111. {
  112. hr = ILS_E_MEMORY;
  113. goto MyExit;
  114. }
  115. // Initialize the internal session container
  116. //
  117. hr = g_pSessionContainer->Initialize (8, NULL);
  118. if (hr != S_OK)
  119. goto MyExit;
  120. // Create an internal pending request queue
  121. //
  122. g_pReqQueue = new SP_CRequestQueue;
  123. if (g_pReqQueue == NULL)
  124. {
  125. hr = ILS_E_MEMORY;
  126. goto MyExit;
  127. }
  128. // Create an internal pending response queue
  129. //
  130. g_pRespQueue = new SP_CResponseQueue;
  131. if (g_pRespQueue == NULL)
  132. {
  133. hr = ILS_E_MEMORY;
  134. goto MyExit;
  135. }
  136. // Create an internal refresh scheduler
  137. //
  138. g_pRefreshScheduler = new SP_CRefreshScheduler;
  139. if (g_pRefreshScheduler == NULL)
  140. {
  141. hr = ILS_E_MEMORY;
  142. goto MyExit;
  143. }
  144. // Create the hidden window
  145. //
  146. if (! MyCreateWindow ())
  147. {
  148. hr = ILS_E_MEMORY;
  149. goto MyExit;
  150. }
  151. // Start WSA for subsequent host query in this service provider
  152. //
  153. WSADATA WSAData;
  154. if (WSAStartup (MAKEWORD (1, 1), &WSAData))
  155. {
  156. hr = ILS_E_WINSOCK;
  157. goto MyExit;
  158. }
  159. // Create an internal hidden request thread that
  160. // sends request and keep alive messages
  161. //
  162. g_hReqThread = CreateThread (NULL, 0,
  163. ReqThread,
  164. NULL, 0,
  165. &g_dwReqThreadID);
  166. if (g_hReqThread == NULL)
  167. {
  168. hr = ILS_E_THREAD;
  169. goto MyExit;
  170. }
  171. // Everything seems successful
  172. //
  173. hr = S_OK;
  174. MyExit:
  175. if (hr != S_OK)
  176. {
  177. // Something wrong, roll back
  178. //
  179. g_cInitialized--;
  180. for (i = 0; i < NUM_THREAD_WAIT_FOR; i++)
  181. {
  182. if (g_ahThreadWaitFor[i] != NULL)
  183. {
  184. CloseHandle (g_ahThreadWaitFor[i]);
  185. g_ahThreadWaitFor[i] = NULL;
  186. }
  187. }
  188. IlsCleanup ();
  189. if (g_pSessionContainer != NULL)
  190. {
  191. delete g_pSessionContainer;
  192. g_pSessionContainer = NULL;
  193. }
  194. if (g_pReqQueue != NULL)
  195. {
  196. delete g_pReqQueue;
  197. g_pReqQueue = NULL;
  198. }
  199. if (g_pRespQueue != NULL)
  200. {
  201. delete g_pRespQueue;
  202. g_pRespQueue = NULL;
  203. }
  204. if (g_pRefreshScheduler != NULL)
  205. {
  206. delete g_pRefreshScheduler;
  207. g_pRefreshScheduler = NULL;
  208. }
  209. // Unconditional call to WSACleanup() will not cause any problem
  210. // because it simply returns WSAEUNINITIALIZED.
  211. //
  212. WSACleanup ();
  213. MyAssert (g_hReqThread == NULL);
  214. MyAssert (g_cInitialized == 0);
  215. }
  216. return hr;
  217. }
  218. /* ----------------------------------------------------------------------
  219. UlsLdap_Deinitialize
  220. History:
  221. 10/15/96 Chu, Lon-Chan [lonchanc]
  222. Created.
  223. 10/30/96 Chu, Lon-Chan [lonchanc]
  224. Tested on ILS (7438)
  225. ---------------------------------------------------------------------- */
  226. HRESULT UlsLdap_Deinitialize ( VOID )
  227. {
  228. HRESULT hr = S_OK;
  229. // Make sure this service provider is initialized
  230. //
  231. if (--g_cInitialized != 0)
  232. {
  233. if (g_cInitialized < 0)
  234. {
  235. MyAssert (FALSE);
  236. g_cInitialized = 0;
  237. return ILS_E_NOT_INITIALIZED;
  238. }
  239. return S_OK;
  240. }
  241. // Make sure we have a valid internal hidden window handle
  242. //
  243. if (MyIsWindow (g_hWndHidden))
  244. {
  245. // Kill poll timer
  246. //
  247. KillTimer (g_hWndHidden, ID_TIMER_POLL_RESULT);
  248. // Destroy the hidden window
  249. //
  250. DestroyWindow (g_hWndHidden);
  251. // Unregister the window class
  252. //
  253. UnregisterClass (c_szWindowClassName, g_hInstance);
  254. }
  255. else
  256. {
  257. MyAssert (FALSE);
  258. }
  259. // Is the request thread alive?
  260. //
  261. if (g_hReqThread != NULL)
  262. {
  263. // Signal the request thread to exit
  264. //
  265. SetEvent (g_hevExitReqThread);
  266. g_fExitNow = TRUE;
  267. // Wait for the request thread to respond
  268. //
  269. DWORD dwResult;
  270. #define REQ_THREAD_EXIT_TIMEOUT 10000 // 10 seconds timeout
  271. ULONG tcTimeout = REQ_THREAD_EXIT_TIMEOUT;
  272. ULONG tcTarget = GetTickCount () + tcTimeout;
  273. do
  274. {
  275. dwResult = (g_hReqThread != NULL) ?
  276. MsgWaitForMultipleObjects (
  277. 1,
  278. &g_hReqThread,
  279. FALSE,
  280. tcTimeout,
  281. QS_ALLINPUT) :
  282. WAIT_OBJECT_0;
  283. if (dwResult == (WAIT_OBJECT_0 + 1))
  284. {
  285. // Insure that this thread continues to respond
  286. //
  287. if (! KeepUiResponsive ())
  288. {
  289. dwResult = WAIT_TIMEOUT;
  290. break;
  291. }
  292. }
  293. // Make sure we only wait for 90 seconds totally
  294. //
  295. tcTimeout = tcTarget - GetTickCount ();
  296. }
  297. // If the thread does not exit, let's continue to wait.
  298. //
  299. while ( dwResult == (WAIT_OBJECT_0 + 1) &&
  300. tcTimeout <= REQ_THREAD_EXIT_TIMEOUT);
  301. // Make sure we propagate back the error that
  302. // the internal request thread is not responding
  303. //
  304. if (dwResult == WAIT_TIMEOUT)
  305. {
  306. #ifdef _DEBUG
  307. DBG_REF("ULS Terminating internal thread");
  308. #endif
  309. hr = ILS_E_THREAD;
  310. TerminateThread (g_hReqThread, (DWORD) -1);
  311. }
  312. // Clean up the internal hidden thread descriptor
  313. //
  314. CloseHandle (g_hReqThread);
  315. g_hReqThread = NULL;
  316. g_dwReqThreadID = 0;
  317. } // if (g_hReqThread != NULL)
  318. // Clean up inter-thread synchronization
  319. //
  320. for (INT i = 0; i < NUM_THREAD_WAIT_FOR; i++)
  321. {
  322. if (g_ahThreadWaitFor[i] != NULL)
  323. {
  324. CloseHandle (g_ahThreadWaitFor[i]);
  325. g_ahThreadWaitFor[i] = NULL;
  326. }
  327. }
  328. IlsCleanup();
  329. // Free the internal session container
  330. //
  331. if (g_pSessionContainer != NULL)
  332. {
  333. delete g_pSessionContainer;
  334. g_pSessionContainer = NULL;
  335. }
  336. // Free the internal pending request queue
  337. //
  338. if (g_pReqQueue != NULL)
  339. {
  340. delete g_pReqQueue;
  341. g_pReqQueue = NULL;
  342. }
  343. // Free the internal pending response queue
  344. //
  345. if (g_pRespQueue != NULL)
  346. {
  347. delete g_pRespQueue;
  348. g_pRespQueue = NULL;
  349. }
  350. // Free the refresh scheduler object
  351. //
  352. if (g_pRefreshScheduler != NULL)
  353. {
  354. delete g_pRefreshScheduler;
  355. g_pRefreshScheduler = NULL;
  356. }
  357. // Unconditional call to WSACleanup() will not cause any problem
  358. // because it simply returns WSAEUNINITIALIZED.
  359. //
  360. WSACleanup ();
  361. return hr;
  362. }
  363. /* ----------------------------------------------------------------------
  364. UlsLdap_Cancel
  365. History:
  366. 10/30/96 Chu, Lon-Chan [lonchanc]
  367. Created.
  368. ---------------------------------------------------------------------- */
  369. HRESULT UlsLdap_Cancel ( ULONG uMsgID )
  370. {
  371. HRESULT hr = ILS_E_FAIL;
  372. // Make sure this service provider is initialized
  373. //
  374. if (g_cInitialized <= 0)
  375. return ILS_E_NOT_INITIALIZED;
  376. if (g_pRespQueue == NULL || g_pReqQueue == NULL)
  377. {
  378. MyAssert (FALSE);
  379. return ILS_E_FAIL;
  380. }
  381. // The locking order is
  382. // Lock(PendingOpQueue), Lock(RequestQueue), Lock (CurrOp)
  383. //
  384. g_pRespQueue->WriteLock ();
  385. g_pReqQueue->WriteLock ();
  386. g_pReqQueue->LockCurrOp ();
  387. // Redirect the call to the pending op queue object
  388. //
  389. hr = g_pRespQueue->Cancel (uMsgID);
  390. if (hr != S_OK)
  391. {
  392. // Redirect the call to the request queue object
  393. //
  394. hr = g_pReqQueue->Cancel (uMsgID);
  395. }
  396. // Unlock is always in the reverse order of lock
  397. //
  398. g_pReqQueue->UnlockCurrOp ();
  399. g_pReqQueue->WriteUnlock ();
  400. g_pRespQueue->WriteUnlock ();
  401. return S_OK;
  402. }
  403. LPARAM
  404. AsynReq_Cancel ( MARSHAL_REQ *pReq )
  405. {
  406. HRESULT hr = S_OK;
  407. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  408. MyAssert (pReq != NULL);
  409. MyAssert (pReq->uNotifyMsg == WM_ILS_CANCEL);
  410. // Delinearize parameters
  411. //
  412. ULONG uRespID = (ULONG) MarshalReq_GetParam (pReq, 0);
  413. // Cancelling in request queue is easy and done in UlsLdap_Cancel()
  414. // because the request is not sent to the server yet.
  415. // Cancelling in CurrOp is also easy because the request thread will
  416. // find out that the current request is cancelled and then can call
  417. // g_pRespQueue->Cancel() in the request thread (not UI thread).
  418. // Cancelling in pending op queue is tricky. I have to marshal it to
  419. // the request thread to do it. This is why AsynReq_Cancel is called!!!
  420. // Redirect the call to the pending op queue object
  421. //
  422. if (g_pRespQueue != NULL)
  423. {
  424. hr = g_pRespQueue->Cancel (uRespID);
  425. }
  426. else
  427. {
  428. MyAssert (FALSE);
  429. }
  430. return (LPARAM) hr;
  431. }
  432. /* ----------------------------------------------------------------------
  433. UlsLdap_RegisterClient
  434. History:
  435. 10/15/96 Chu, Lon-Chan [lonchanc]
  436. Created.
  437. 10/30/96 Chu, Lon-Chan [lonchanc]
  438. Tested on ILS (7438)
  439. 1/14/97 Chu, Lon-Chan [lonchanc]
  440. Collapsed user/app objects.
  441. ---------------------------------------------------------------------- */
  442. HRESULT
  443. UlsLdap_RegisterClient (
  444. DWORD_PTR dwContext,
  445. SERVER_INFO *pServer,
  446. LDAP_CLIENTINFO *pInfo,
  447. HANDLE *phClient,
  448. LDAP_ASYNCINFO *pAsyncInfo )
  449. {
  450. // Make sure this service provider is initialized
  451. //
  452. if (g_cInitialized <= 0)
  453. return ILS_E_NOT_INITIALIZED;
  454. // Maks sure the server name is valid
  455. //
  456. if (MyIsBadServerInfo (pServer))
  457. return ILS_E_POINTER;
  458. // Make sure the returned handle
  459. //
  460. if (phClient == NULL)
  461. return ILS_E_POINTER;
  462. // Make sure the async info structure is valid
  463. //
  464. if (pAsyncInfo == NULL)
  465. return ILS_E_POINTER;
  466. // Make sure the client info structure is valid
  467. //
  468. #ifdef STRICT_CHECK
  469. if (MyIsBadWritePtr (pInfo, sizeof (*pInfo)))
  470. return ILS_E_POINTER;
  471. #endif
  472. // Make sure the unique id is valid
  473. //
  474. TCHAR *pszCN = (TCHAR *) ((BYTE *) pInfo + pInfo->uOffsetCN);
  475. if (pInfo->uOffsetCN == INVALID_OFFSET || *pszCN == TEXT ('\0'))
  476. return ILS_E_PARAMETER;
  477. // Make sure no modify/remove extended attributes
  478. // Registration only allows ToAdd
  479. //
  480. if (pInfo->cAttrsToModify != 0 || pInfo->cAttrsToRemove != 0)
  481. return ILS_E_PARAMETER;
  482. // Compute the total size of the data
  483. //
  484. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  485. ULONG cParams = 3;
  486. ULONG cbSize = cbServer + pInfo->uSize;
  487. // Allocate marshall request buffer
  488. //
  489. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_REGISTER_CLIENT, cbSize, cParams);
  490. if (pReq == NULL)
  491. return ILS_E_MEMORY;
  492. // Get the response ID
  493. //
  494. ULONG uRespID = pReq->uRespID;
  495. // Create a local client object
  496. //
  497. HRESULT hr;
  498. SP_CClient *pClient = new SP_CClient (dwContext);
  499. if (pClient == NULL)
  500. {
  501. hr = ILS_E_MEMORY;
  502. goto MyExit;
  503. }
  504. // Make sure this client object will not go away unexpectedly
  505. //
  506. pClient->AddRef ();
  507. // Linearize parameters
  508. //
  509. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  510. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pInfo, pInfo->uSize);
  511. MarshalReq_SetParam (pReq, 2, (DWORD_PTR) pClient, 0);
  512. // Enter the request
  513. //
  514. if (g_pReqQueue != NULL)
  515. {
  516. hr = g_pReqQueue->Enter (pReq);
  517. }
  518. else
  519. {
  520. MyAssert (FALSE);
  521. hr = ILS_E_FAIL;
  522. }
  523. MyExit:
  524. if (hr == S_OK)
  525. {
  526. *phClient = (HANDLE) pClient;
  527. pAsyncInfo->uMsgID = uRespID;
  528. }
  529. else
  530. {
  531. MemFree (pReq);
  532. }
  533. return hr;
  534. }
  535. LPARAM
  536. AsynReq_RegisterClient ( MARSHAL_REQ *pReq )
  537. {
  538. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  539. MyAssert (pReq != NULL);
  540. MyAssert (pReq->uNotifyMsg == WM_ILS_REGISTER_CLIENT);
  541. // Delinearize parameters
  542. //
  543. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  544. LDAP_CLIENTINFO *pInfo = (LDAP_CLIENTINFO *) MarshalReq_GetParam (pReq, 1);
  545. SP_CClient *pClient = (SP_CClient *) MarshalReq_GetParam (pReq, 2);
  546. // Register the client object on the server
  547. //
  548. HRESULT hr = pClient->Register (pReq->uRespID, pServer, pInfo);
  549. if (hr != S_OK)
  550. {
  551. // Release this newly allocated local user object
  552. //
  553. pClient->Release ();
  554. }
  555. return (LPARAM) hr;
  556. }
  557. /* ----------------------------------------------------------------------
  558. UlsLdap_RegisterProtocol
  559. History:
  560. 10/15/96 Chu, Lon-Chan [lonchanc]
  561. Created.
  562. 10/30/96 Chu, Lon-Chan [lonchanc]
  563. Blocked by ILS (7438, 7442)
  564. ---------------------------------------------------------------------- */
  565. HRESULT
  566. UlsLdap_RegisterProtocol (
  567. HANDLE hClient,
  568. LDAP_PROTINFO *pInfo,
  569. HANDLE *phProt,
  570. LDAP_ASYNCINFO *pAsyncInfo )
  571. {
  572. HRESULT hr;
  573. // Make sure this service provider is initialized
  574. //
  575. if (g_cInitialized <= 0)
  576. return ILS_E_NOT_INITIALIZED;
  577. // Convert handle to pointer
  578. //
  579. SP_CClient *pClient = (SP_CClient *) hClient;
  580. // Make sure the parent local app object is valid
  581. //
  582. if (MyIsBadWritePtr (pClient, sizeof (*pClient)) ||
  583. ! pClient->IsValidObject () ||
  584. ! pClient->IsRegistered ())
  585. return ILS_E_HANDLE;
  586. // Make sure the returned handle
  587. //
  588. if (phProt == NULL)
  589. return ILS_E_POINTER;
  590. // Make sure the prot info structure is valid
  591. //
  592. #ifdef STRICT_CHECK
  593. if (MyIsBadWritePtr (pInfo, sizeof (*pInfo)))
  594. return ILS_E_POINTER;
  595. #endif
  596. // Make sure the async info structure is valid
  597. //
  598. if (pAsyncInfo == NULL)
  599. return ILS_E_POINTER;
  600. // Make sure the protocol name is valid
  601. //
  602. TCHAR *pszProtName = (TCHAR *) ((BYTE *) pInfo + pInfo->uOffsetName);
  603. if (pInfo->uOffsetName == INVALID_OFFSET || *pszProtName == TEXT ('\0'))
  604. return ILS_E_PARAMETER;
  605. // Compute the total size of the data
  606. //
  607. ULONG cParams = 3;
  608. ULONG cbSize = pInfo->uSize;
  609. // Allocate marshall request buffer
  610. //
  611. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_REGISTER_PROTOCOL, cbSize, cParams);
  612. if (pReq == NULL)
  613. return ILS_E_MEMORY;
  614. // Get the response ID
  615. //
  616. ULONG uRespID = pReq->uRespID;
  617. // Create a local prot object
  618. //
  619. SP_CProtocol *pProt = new SP_CProtocol (pClient);
  620. if (pProt == NULL)
  621. {
  622. hr = ILS_E_MEMORY;
  623. goto MyExit;
  624. }
  625. // Make sure the local prot object will not be deleted randomly
  626. //
  627. pProt->AddRef ();
  628. // Linearize parameters
  629. //
  630. MarshalReq_SetParam (pReq, 0, (DWORD_PTR) pClient, 0);
  631. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pInfo, pInfo->uSize);
  632. MarshalReq_SetParam (pReq, 2, (DWORD_PTR) pProt, 0);
  633. // Enter the request
  634. //
  635. if (g_pReqQueue != NULL)
  636. {
  637. hr = g_pReqQueue->Enter (pReq);
  638. }
  639. else
  640. {
  641. MyAssert (FALSE);
  642. hr = ILS_E_FAIL;
  643. }
  644. MyExit:
  645. if (hr == S_OK)
  646. {
  647. *phProt = (HANDLE) pProt;
  648. pAsyncInfo->uMsgID = uRespID;
  649. }
  650. else
  651. {
  652. MemFree (pReq);
  653. }
  654. return hr;
  655. }
  656. LPARAM
  657. AsynReq_RegisterProtocol ( MARSHAL_REQ *pReq )
  658. {
  659. HRESULT hr;
  660. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  661. MyAssert (pReq != NULL);
  662. MyAssert (pReq->uNotifyMsg == WM_ILS_REGISTER_PROTOCOL);
  663. // Delinearize parameters
  664. //
  665. SP_CClient *pClient = (SP_CClient *) MarshalReq_GetParam (pReq, 0);
  666. LDAP_PROTINFO *pInfo = (LDAP_PROTINFO *) MarshalReq_GetParam (pReq, 1);
  667. SP_CProtocol *pProt = (SP_CProtocol *) MarshalReq_GetParam (pReq, 2);
  668. // Make sure the parent local app object is valid
  669. //
  670. if (MyIsBadWritePtr (pClient, sizeof (*pClient)) ||
  671. ! pClient->IsValidObject () ||
  672. ! pClient->IsRegistered ())
  673. {
  674. hr = ILS_E_HANDLE;
  675. }
  676. else
  677. {
  678. // Make the local prot object do prot registration
  679. //
  680. hr = pProt->Register (pReq->uRespID, pInfo);
  681. if (hr != S_OK)
  682. {
  683. // Release the newly allocated local prot object
  684. //
  685. pProt->Release ();
  686. }
  687. }
  688. return (LPARAM) hr;
  689. }
  690. /* ----------------------------------------------------------------------
  691. UlsLdap_RegisterMeeting
  692. Input:
  693. pszServer: A pointer to the server name.
  694. pMeetInfo: A pointer to meeting info structure.
  695. phMtg: A return meeting object handle.
  696. pAsyncInfo: A pointer to async info structure.
  697. History:
  698. 12/02/96 Chu, Lon-Chan [lonchanc]
  699. Created.
  700. ---------------------------------------------------------------------- */
  701. #ifdef ENABLE_MEETING_PLACE
  702. HRESULT
  703. UlsLdap_RegisterMeeting (
  704. DWORD dwContext,
  705. SERVER_INFO *pServer,
  706. LDAP_MEETINFO *pInfo,
  707. HANDLE *phMtg,
  708. LDAP_ASYNCINFO *pAsyncInfo )
  709. {
  710. HRESULT hr;
  711. // Make sure this service provider is initialized
  712. //
  713. if (g_cInitialized <= 0)
  714. return ILS_E_NOT_INITIALIZED;
  715. // Maks sure the server name is valid
  716. //
  717. if (MyIsBadServerInfo (pServer))
  718. return ILS_E_POINTER;
  719. // Make sure the returned handle
  720. //
  721. if (phMtg == NULL)
  722. return ILS_E_POINTER;
  723. // Make sure the async info structure is valid
  724. //
  725. if (pAsyncInfo == NULL)
  726. return ILS_E_POINTER;
  727. // Make sure the user info structure is valid
  728. //
  729. #ifdef STRICT_CHECK
  730. if (MyIsBadWritePtr (pInfo, sizeof (*pInfo)))
  731. return ILS_E_POINTER;
  732. #endif
  733. // Make sure the unique id is valid
  734. //
  735. TCHAR *pszName = (TCHAR *) ((BYTE *) pInfo + pInfo->uOffsetMeetingPlaceID);
  736. if (pInfo->uOffsetMeetingPlaceID == INVALID_OFFSET || *pszName == TEXT ('\0'))
  737. return ILS_E_PARAMETER;
  738. // Make sure no modify/remove extended attributes
  739. // Registration only allows ToAdd
  740. //
  741. if (pInfo->cAttrsToModify != 0 || pInfo->cAttrsToRemove != 0)
  742. return ILS_E_PARAMETER;
  743. // Compute the total size of the data
  744. //
  745. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  746. ULONG cParams = 3;
  747. ULONG cbSize = cbServer + pInfo->uSize;
  748. // Allocate marshall request buffer
  749. //
  750. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_REGISTER_MEETING, cbSize, cParams);
  751. if (pReq == NULL)
  752. return ILS_E_MEMORY;
  753. // Get the response ID
  754. //
  755. ULONG uRespID = pReq->uRespID;
  756. // Create a local user object
  757. //
  758. SP_CMeeting *pMtg = new SP_CMeeting (dwContext);
  759. if (pMtg == NULL)
  760. {
  761. hr = ILS_E_MEMORY;
  762. goto MyExit;
  763. }
  764. // Make sure this local user object will not go away randomly
  765. //
  766. pMtg->AddRef ();
  767. // Linearize parameters
  768. //
  769. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  770. MarshalReq_SetParam (pReq, 1, (DWORD) pInfo, pInfo->uSize);
  771. MarshalReq_SetParam (pReq, 2, (DWORD) pMtg, 0);
  772. // Enter the request
  773. //
  774. if (g_pReqQueue != NULL)
  775. {
  776. hr = g_pReqQueue->Enter (pReq);
  777. }
  778. else
  779. {
  780. MyAssert (FALSE);
  781. hr = ILS_E_FAIL;
  782. }
  783. MyExit:
  784. if (hr == S_OK)
  785. {
  786. *phMtg = (HANDLE) pMtg;
  787. pAsyncInfo->uMsgID = uRespID;
  788. }
  789. else
  790. {
  791. MemFree (pReq);
  792. }
  793. return hr;
  794. }
  795. LPARAM
  796. AsynReq_RegisterMeeting ( MARSHAL_REQ *pReq )
  797. {
  798. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  799. MyAssert (pReq != NULL);
  800. MyAssert (pReq->uNotifyMsg == WM_ILS_REGISTER_MEETING);
  801. // Delinearize parameters
  802. //
  803. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  804. LDAP_MEETINFO *pInfo = (LDAP_MEETINFO *) MarshalReq_GetParam (pReq, 1);
  805. SP_CMeeting *pMtg = (SP_CMeeting *) MarshalReq_GetParam (pReq, 2);
  806. // Make the local meeting object do meeting registration
  807. //
  808. HRESULT hr = pMtg->Register (pReq->uRespID, pServer, pInfo);
  809. if (hr != S_OK)
  810. {
  811. // Release this newly allocated local user object
  812. //
  813. pMtg->Release ();
  814. }
  815. return (LPARAM) hr;
  816. }
  817. #endif // ENABLE_MEETING_PLACE
  818. /* ----------------------------------------------------------------------
  819. UlsLdap_UnRegisterClient
  820. History:
  821. 10/15/96 Chu, Lon-Chan [lonchanc]
  822. Created.
  823. 10/30/96 Chu, Lon-Chan [lonchanc]
  824. Tested on ILS (7438)
  825. 1/14/97 Chu, Lon-Chan [lonchanc]
  826. Collapsed user/app objects.
  827. ---------------------------------------------------------------------- */
  828. HRESULT
  829. UlsLdap_UnRegisterClient (
  830. HANDLE hClient,
  831. LDAP_ASYNCINFO *pAsyncInfo )
  832. {
  833. HRESULT hr;
  834. // Make sure this service provider is initialized
  835. //
  836. if (g_cInitialized <= 0)
  837. return ILS_E_NOT_INITIALIZED;
  838. // Convert handle to pointer
  839. //
  840. SP_CClient *pClient = (SP_CClient *) hClient;
  841. // Make sure the local client object is valid
  842. //
  843. if (MyIsBadWritePtr (pClient, sizeof (*pClient)) ||
  844. ! pClient->IsValidObject () ||
  845. ! pClient->IsRegistered ())
  846. return ILS_E_HANDLE;
  847. // Make sure the async info structure is valid
  848. //
  849. if (pAsyncInfo == NULL)
  850. return ILS_E_POINTER;
  851. // Compute the total size of the data
  852. //
  853. ULONG cParams = 1;
  854. ULONG cbSize = 0;
  855. // Allocate marshall request buffer
  856. //
  857. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_UNREGISTER_CLIENT, cbSize, cParams);
  858. if (pReq == NULL)
  859. return ILS_E_MEMORY;
  860. // Get the response ID
  861. //
  862. ULONG uRespID = pReq->uRespID;
  863. // Linearize parameters
  864. //
  865. MarshalReq_SetParam (pReq, 0, (DWORD_PTR) pClient, 0);
  866. // Enter the request
  867. //
  868. if (g_pReqQueue != NULL)
  869. {
  870. hr = g_pReqQueue->Enter (pReq);
  871. }
  872. else
  873. {
  874. MyAssert (FALSE);
  875. hr = ILS_E_FAIL;
  876. }
  877. if (hr == S_OK)
  878. {
  879. pAsyncInfo->uMsgID = uRespID;
  880. }
  881. else
  882. {
  883. MemFree (pReq);
  884. }
  885. return hr;
  886. }
  887. LPARAM
  888. AsynReq_UnRegisterClient ( MARSHAL_REQ *pReq )
  889. {
  890. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  891. MyAssert (pReq != NULL);
  892. MyAssert (pReq->uNotifyMsg == WM_ILS_UNREGISTER_CLIENT);
  893. // Delinearize parameters
  894. //
  895. SP_CClient *pClient = (SP_CClient *) MarshalReq_GetParam (pReq, 0);
  896. // Make sure the local client object is valid
  897. //
  898. HRESULT hr;
  899. if (MyIsBadWritePtr (pClient, sizeof (*pClient)) ||
  900. ! pClient->IsValidObject () ||
  901. ! pClient->IsRegistered ())
  902. {
  903. // When submitting this request, the client object is fine
  904. // but now it is not, so it must have been unregistered and released.
  905. //
  906. MyAssert (FALSE); // to see if any one tries to break it this way!!!
  907. hr = S_OK;
  908. }
  909. else
  910. {
  911. // Make the client object do user unregistration
  912. //
  913. hr = pClient->UnRegister (pReq->uRespID);
  914. // Free this client object
  915. //
  916. pClient->Release ();
  917. }
  918. return (LPARAM) hr;
  919. }
  920. /* ----------------------------------------------------------------------
  921. UlsLdap_UnRegisterProtocol
  922. History:
  923. 10/15/96 Chu, Lon-Chan [lonchanc]
  924. Created.
  925. 10/30/96 Chu, Lon-Chan [lonchanc]
  926. Tested on ILS (7438)
  927. ---------------------------------------------------------------------- */
  928. HRESULT UlsLdap_VirtualUnRegisterProtocol ( HANDLE hProt )
  929. {
  930. // Make sure this service provider is initialized
  931. //
  932. if (g_cInitialized <= 0)
  933. return ILS_E_NOT_INITIALIZED;
  934. // Convert handle to pointer
  935. //
  936. SP_CProtocol *pProt = (SP_CProtocol *) hProt;
  937. // Make sure the local prot object is valid
  938. //
  939. if (MyIsBadWritePtr (pProt, sizeof (*pProt)))
  940. return ILS_E_HANDLE;
  941. // Free this local prot object
  942. //
  943. pProt->Release ();
  944. return S_OK;
  945. }
  946. HRESULT UlsLdap_UnRegisterProtocol (
  947. HANDLE hProt,
  948. LDAP_ASYNCINFO *pAsyncInfo )
  949. {
  950. HRESULT hr;
  951. // Make sure this service provider is initialized
  952. //
  953. if (g_cInitialized <= 0)
  954. return ILS_E_NOT_INITIALIZED;
  955. // Convert handle to pointer
  956. //
  957. SP_CProtocol *pProt = (SP_CProtocol *) hProt;
  958. // Make sure the local prot object is valid
  959. //
  960. if (MyIsBadWritePtr (pProt, sizeof (*pProt)) ||
  961. ! pProt->IsValidObject () ||
  962. ! pProt->IsRegistered ())
  963. return ILS_E_HANDLE;
  964. // Make sure the async info structure is valid
  965. //
  966. if (pAsyncInfo == NULL)
  967. return ILS_E_POINTER;
  968. // Compute the total size of the data
  969. //
  970. ULONG cParams = 1;
  971. ULONG cbSize = 0;
  972. // Allocate marshall request buffer
  973. //
  974. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_UNREGISTER_PROTOCOL, cbSize, cParams);
  975. if (pReq == NULL)
  976. return ILS_E_MEMORY;
  977. // Get the response ID
  978. //
  979. ULONG uRespID = pReq->uRespID;
  980. // Linearize parameters
  981. //
  982. MarshalReq_SetParam (pReq, 0, (DWORD_PTR) pProt, 0);
  983. // Enter the request
  984. //
  985. if (g_pReqQueue != NULL)
  986. {
  987. hr = g_pReqQueue->Enter (pReq);
  988. }
  989. else
  990. {
  991. MyAssert (FALSE);
  992. hr = ILS_E_FAIL;
  993. }
  994. if (hr == S_OK)
  995. {
  996. pAsyncInfo->uMsgID = uRespID;
  997. }
  998. else
  999. {
  1000. MemFree (pReq);
  1001. }
  1002. return hr;
  1003. }
  1004. LPARAM
  1005. AsynReq_UnRegisterProt ( MARSHAL_REQ *pReq )
  1006. {
  1007. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1008. MyAssert (pReq != NULL);
  1009. MyAssert (pReq->uNotifyMsg == WM_ILS_UNREGISTER_PROTOCOL);
  1010. // Delinearize parameters
  1011. //
  1012. SP_CProtocol *pProt = (SP_CProtocol *) MarshalReq_GetParam (pReq, 0);
  1013. // Make sure the local prot object is valid
  1014. //
  1015. HRESULT hr;
  1016. if (MyIsBadWritePtr (pProt, sizeof (*pProt)) ||
  1017. ! pProt->IsValidObject () ||
  1018. ! pProt->IsRegistered ())
  1019. {
  1020. // When submitting this request, the client object is fine
  1021. // but now it is not, so it must have been unregistered and released.
  1022. //
  1023. MyAssert (FALSE); // to see if any one tries to break it this way!!!
  1024. hr = S_OK;
  1025. }
  1026. else
  1027. {
  1028. // Make the local prot object do prot unregistration
  1029. //
  1030. hr = pProt->UnRegister (pReq->uRespID);
  1031. // Free this local prot object
  1032. //
  1033. pProt->Release ();
  1034. }
  1035. return (LPARAM) hr;
  1036. }
  1037. /* ----------------------------------------------------------------------
  1038. UlsLdap_UnRegisterMeeting
  1039. Input:
  1040. pszServer: server name.
  1041. hMeeting: a handle to the meeting object.
  1042. pAsyncInfo: a pointer to async info structure.
  1043. History:
  1044. 12/02/96 Chu, Lon-Chan [lonchanc]
  1045. Created.
  1046. ---------------------------------------------------------------------- */
  1047. #ifdef ENABLE_MEETING_PLACE
  1048. HRESULT UlsLdap_UnRegisterMeeting (
  1049. HANDLE hMtg,
  1050. LDAP_ASYNCINFO *pAsyncInfo )
  1051. {
  1052. HRESULT hr;
  1053. // Make sure this service provider is initialized
  1054. //
  1055. if (g_cInitialized <= 0)
  1056. return ILS_E_NOT_INITIALIZED;
  1057. // Convert handle to pointer
  1058. //
  1059. SP_CMeeting *pMtg = (SP_CMeeting *) hMtg;
  1060. // Make sure the local user object is valid
  1061. //
  1062. if (MyIsBadWritePtr (pMtg, sizeof (*pMtg)) ||
  1063. ! pMtg->IsValidObject () ||
  1064. ! pMtg->IsRegistered ())
  1065. return ILS_E_HANDLE;
  1066. // Make sure the async info structure is valid
  1067. //
  1068. if (pAsyncInfo == NULL)
  1069. return ILS_E_POINTER;
  1070. // Compute the total size of the data
  1071. //
  1072. ULONG cParams = 1;
  1073. ULONG cbSize = 0;
  1074. // Allocate marshall request buffer
  1075. //
  1076. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_UNREGISTER_MEETING, cbSize, cParams);
  1077. if (pReq == NULL)
  1078. return ILS_E_MEMORY;
  1079. // Get the response ID
  1080. //
  1081. ULONG uRespID = pReq->uRespID;
  1082. // Linearize parameters
  1083. //
  1084. MarshalReq_SetParam (pReq, 0, (DWORD) pMtg, 0);
  1085. // Enter the request
  1086. //
  1087. if (g_pReqQueue != NULL)
  1088. {
  1089. hr = g_pReqQueue->Enter (pReq);
  1090. }
  1091. else
  1092. {
  1093. MyAssert (FALSE);
  1094. hr = ILS_E_FAIL;
  1095. }
  1096. if (hr == S_OK)
  1097. {
  1098. pAsyncInfo->uMsgID = uRespID;
  1099. }
  1100. else
  1101. {
  1102. MemFree (pReq);
  1103. }
  1104. return hr;
  1105. }
  1106. LPARAM
  1107. AsynReq_UnRegisterMeeting ( MARSHAL_REQ *pReq )
  1108. {
  1109. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1110. MyAssert (pReq != NULL);
  1111. MyAssert (pReq->uNotifyMsg == WM_ILS_UNREGISTER_MEETING);
  1112. // Delinearize parameters
  1113. //
  1114. SP_CMeeting *pMtg = (SP_CMeeting *) MarshalReq_GetParam (pReq, 0);
  1115. // Make sure the local user object is valid
  1116. //
  1117. HRESULT hr;
  1118. if (MyIsBadWritePtr (pMtg, sizeof (*pMtg)) ||
  1119. ! pMtg->IsValidObject () ||
  1120. ! pMtg->IsRegistered ())
  1121. {
  1122. // When submitting this request, the client object is fine
  1123. // but now it is not, so it must have been unregistered and released.
  1124. //
  1125. MyAssert (FALSE); // to see if any one tries to break it this way!!!
  1126. hr = S_OK;
  1127. }
  1128. else
  1129. {
  1130. // Make the local user object do user unregistration
  1131. //
  1132. hr = pMtg->UnRegister (pReq->uRespID);
  1133. // Free this local user object
  1134. //
  1135. pMtg->Release ();
  1136. }
  1137. return (LPARAM) hr;
  1138. }
  1139. #endif // ENABLE_MEETING_PLACE
  1140. /* ----------------------------------------------------------------------
  1141. UlsLdap_SetClientInfo
  1142. History:
  1143. 10/15/96 Chu, Lon-Chan [lonchanc]
  1144. Created.
  1145. 10/30/96 Chu, Lon-Chan [lonchanc]
  1146. Tested on ILS (7438)
  1147. 1/14/97 Chu, Lon-Chan [lonchanc]
  1148. Collapsed user/app objects.
  1149. ---------------------------------------------------------------------- */
  1150. HRESULT
  1151. UlsLdap_SetClientInfo (
  1152. HANDLE hClient,
  1153. LDAP_CLIENTINFO *pInfo,
  1154. LDAP_ASYNCINFO *pAsyncInfo )
  1155. {
  1156. HRESULT hr;
  1157. // Make sure this service provider is initialized
  1158. //
  1159. if (g_cInitialized <= 0)
  1160. return ILS_E_NOT_INITIALIZED;
  1161. // Convert handle to pointer
  1162. //
  1163. SP_CClient *pClient = (SP_CClient *) hClient;
  1164. // Make sure the client object is valid
  1165. //
  1166. if (MyIsBadWritePtr (pClient, sizeof (*pClient)) ||
  1167. ! pClient->IsValidObject () ||
  1168. ! pClient->IsRegistered ())
  1169. return ILS_E_HANDLE;
  1170. // Make sure the async info structure is valid
  1171. //
  1172. if (pAsyncInfo == NULL)
  1173. return ILS_E_POINTER;
  1174. // Make sure the user info structure is valid
  1175. //
  1176. #ifdef STRICT_CHECK
  1177. if (MyIsBadWritePtr (pInfo, sizeof (*pInfo)))
  1178. return ILS_E_POINTER;
  1179. #endif
  1180. // We should not change the app name here
  1181. //
  1182. if (pInfo->uOffsetAppName != INVALID_OFFSET || pInfo->uOffsetCN != INVALID_OFFSET)
  1183. return ILS_E_PARAMETER; // ILS_E_READ_ONLY;
  1184. // lonchanc: BUGS
  1185. // ISBU requires us to block any change of components of dn
  1186. //
  1187. pInfo->uOffsetCountryName = 0;
  1188. // Compute the total size of the data
  1189. //
  1190. ULONG cParams = 2;
  1191. ULONG cbSize = pInfo->uSize;
  1192. // Allocate marshall request buffer
  1193. //
  1194. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_SET_CLIENT_INFO, cbSize, cParams);
  1195. if (pReq == NULL)
  1196. return ILS_E_MEMORY;
  1197. // Get the response ID
  1198. //
  1199. ULONG uRespID = pReq->uRespID;
  1200. // Linearize parameters
  1201. //
  1202. MarshalReq_SetParam (pReq, 0, (DWORD_PTR) pClient, 0);
  1203. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pInfo, pInfo->uSize);
  1204. // Enter the request
  1205. //
  1206. if (g_pReqQueue != NULL)
  1207. {
  1208. hr = g_pReqQueue->Enter (pReq);
  1209. }
  1210. else
  1211. {
  1212. MyAssert (FALSE);
  1213. hr = ILS_E_FAIL;
  1214. }
  1215. if (hr == S_OK)
  1216. {
  1217. pAsyncInfo->uMsgID = uRespID;
  1218. }
  1219. else
  1220. {
  1221. MemFree (pReq);
  1222. }
  1223. return hr;
  1224. }
  1225. LPARAM
  1226. AsynReq_SetClientInfo ( MARSHAL_REQ *pReq )
  1227. {
  1228. HRESULT hr = S_OK;
  1229. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1230. MyAssert (pReq != NULL);
  1231. MyAssert (pReq->uNotifyMsg == WM_ILS_SET_CLIENT_INFO);
  1232. // Delinearize parameters
  1233. //
  1234. SP_CClient *pClient = (SP_CClient *) MarshalReq_GetParam (pReq, 0);
  1235. LDAP_CLIENTINFO *pInfo = (LDAP_CLIENTINFO *) MarshalReq_GetParam (pReq, 1);
  1236. // Make sure the local client object is valid
  1237. //
  1238. if (MyIsBadWritePtr (pClient, sizeof (*pClient)) ||
  1239. ! pClient->IsValidObject () ||
  1240. ! pClient->IsRegistered ())
  1241. {
  1242. // When submitting this request, the client object is fine
  1243. // but now it is not, so it must have been unregistered and released.
  1244. //
  1245. MyAssert (FALSE); // to see if any one tries to break it this way!!!
  1246. hr = ILS_E_HANDLE;
  1247. }
  1248. else
  1249. {
  1250. // Set standard attributes
  1251. //
  1252. hr = pClient->SetAttributes (pReq->uRespID, pInfo);
  1253. }
  1254. return (LPARAM) hr;
  1255. }
  1256. /* ----------------------------------------------------------------------
  1257. UlsLdap_SetProtocolInfo
  1258. History:
  1259. 10/15/96 Chu, Lon-Chan [lonchanc]
  1260. Created.
  1261. 10/30/96 Chu, Lon-Chan [lonchanc]
  1262. Blocked by ILS (7438, 7442)
  1263. ---------------------------------------------------------------------- */
  1264. HRESULT UlsLdap_SetProtocolInfo (
  1265. HANDLE hProt,
  1266. LDAP_PROTINFO *pInfo,
  1267. LDAP_ASYNCINFO *pAsyncInfo )
  1268. {
  1269. HRESULT hr;
  1270. // Make sure this service provider is initialized
  1271. //
  1272. if (g_cInitialized <= 0)
  1273. return ILS_E_NOT_INITIALIZED;
  1274. // Convert handle to pointer
  1275. //
  1276. SP_CProtocol *pProt = (SP_CProtocol *) hProt;
  1277. // Make sure the local prot object is valid
  1278. //
  1279. if (MyIsBadWritePtr (pProt, sizeof (*pProt)) ||
  1280. ! pProt->IsValidObject () ||
  1281. ! pProt->IsRegistered ())
  1282. return ILS_E_HANDLE;
  1283. // Make sure the prot info structure is valid
  1284. //
  1285. #ifdef STRICT_CHECK
  1286. if (MyIsBadWritePtr (pInfo, sizeof (*pInfo)))
  1287. return ILS_E_POINTER;
  1288. #endif
  1289. // Make sure the async info structure is valid
  1290. //
  1291. if (pAsyncInfo == NULL)
  1292. return ILS_E_POINTER;
  1293. // Compute the total size of the data
  1294. //
  1295. ULONG cParams = 2;
  1296. ULONG cbSize = pInfo->uSize;
  1297. // Allocate marshall request buffer
  1298. //
  1299. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_SET_PROTOCOL_INFO, cbSize, cParams);
  1300. if (pReq == NULL)
  1301. return ILS_E_MEMORY;
  1302. // Get the response ID
  1303. //
  1304. ULONG uRespID = pReq->uRespID;
  1305. // Linearize parameters
  1306. //
  1307. MarshalReq_SetParam (pReq, 0, (DWORD_PTR) pProt, 0);
  1308. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pInfo, pInfo->uSize);
  1309. // Enter the request
  1310. //
  1311. if (g_pReqQueue != NULL)
  1312. {
  1313. hr = g_pReqQueue->Enter (pReq);
  1314. }
  1315. else
  1316. {
  1317. MyAssert (FALSE);
  1318. hr = ILS_E_FAIL;
  1319. }
  1320. if (hr == S_OK)
  1321. {
  1322. pAsyncInfo->uMsgID = uRespID;
  1323. }
  1324. else
  1325. {
  1326. MemFree (pReq);
  1327. }
  1328. return hr;
  1329. }
  1330. LPARAM
  1331. AsynReq_SetProtocolInfo ( MARSHAL_REQ *pReq )
  1332. {
  1333. HRESULT hr = S_OK;
  1334. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1335. MyAssert (pReq != NULL);
  1336. MyAssert (pReq->uNotifyMsg == WM_ILS_SET_PROTOCOL_INFO);
  1337. // Delinearize parameters
  1338. //
  1339. SP_CProtocol *pProt = (SP_CProtocol *) MarshalReq_GetParam (pReq, 0);
  1340. LDAP_PROTINFO *pInfo = (LDAP_PROTINFO *) MarshalReq_GetParam (pReq, 1);
  1341. // Make sure the local client object is valid
  1342. //
  1343. if (MyIsBadWritePtr (pProt, sizeof (*pProt)) ||
  1344. ! pProt->IsValidObject () ||
  1345. ! pProt->IsRegistered ())
  1346. {
  1347. // When submitting this request, the client object is fine
  1348. // but now it is not, so it must have been unregistered and released.
  1349. //
  1350. MyAssert (FALSE); // to see if any one tries to break it this way!!!
  1351. hr = ILS_E_HANDLE;
  1352. }
  1353. else
  1354. {
  1355. // Set standard attributes
  1356. //
  1357. hr = pProt->SetAttributes (pReq->uRespID, pInfo);
  1358. }
  1359. return (LPARAM) hr;
  1360. }
  1361. /* ----------------------------------------------------------------------
  1362. UlsLdap_SetMeetingInfo
  1363. Input:
  1364. pszServer: A server name.
  1365. pszMtgName: A meeting id string.
  1366. pMeetInfo: A pointer to meeting info structure.
  1367. pAsyncInfo: A pointer to async info structure.
  1368. History:
  1369. 12/02/96 Chu, Lon-Chan [lonchanc]
  1370. Created.
  1371. ---------------------------------------------------------------------- */
  1372. #ifdef ENABLE_MEETING_PLACE
  1373. HRESULT UlsLdap_SetMeetingInfo (
  1374. SERVER_INFO *pServer,
  1375. TCHAR *pszMtgName,
  1376. LDAP_MEETINFO *pInfo,
  1377. LDAP_ASYNCINFO *pAsyncInfo )
  1378. {
  1379. HRESULT hr;
  1380. // Make sure this service provider is initialized
  1381. //
  1382. if (g_cInitialized <= 0)
  1383. return ILS_E_NOT_INITIALIZED;
  1384. // Make sure we have valid pointers
  1385. //
  1386. if (MyIsBadServerInfo (pServer) || MyIsBadString (pszMtgName))
  1387. return ILS_E_POINTER;
  1388. // Make sure the app info structure is valid
  1389. //
  1390. #ifdef STRICT_CHECK
  1391. if (MyIsBadWritePtr (pInfo, sizeof (*pInfo)))
  1392. return ILS_E_POINTER;
  1393. #endif
  1394. // Make sure we do not change meeting name
  1395. //
  1396. if (pInfo->uOffsetMeetingPlaceID != 0)
  1397. return ILS_E_PARAMETER;
  1398. // Make sure the async info structure is valid
  1399. //
  1400. if (pAsyncInfo == NULL)
  1401. return ILS_E_POINTER;
  1402. // Compute the total size of the data
  1403. //
  1404. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  1405. ULONG cbSizeMtgName = (lstrlen (pszMtgName) + 1) * sizeof (TCHAR);
  1406. ULONG cParams = 3;
  1407. ULONG cbSize = cbServer + cbSizeMtgName + pInfo->uSize;
  1408. // Allocate marshall request buffer
  1409. //
  1410. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_SET_MEETING_INFO, cbSize, cParams);
  1411. if (pReq == NULL)
  1412. return ILS_E_MEMORY;
  1413. // Get the response ID
  1414. //
  1415. ULONG uRespID = pReq->uRespID;
  1416. // Linearize parameters
  1417. //
  1418. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  1419. MarshalReq_SetParam (pReq, 1, (DWORD) pszMtgName, cbSizeMtgName);
  1420. MarshalReq_SetParam (pReq, 2, (DWORD) pInfo, pInfo->uSize);
  1421. // Enter the request
  1422. //
  1423. if (g_pReqQueue != NULL)
  1424. {
  1425. hr = g_pReqQueue->Enter (pReq);
  1426. }
  1427. else
  1428. {
  1429. MyAssert (FALSE);
  1430. hr = ILS_E_FAIL;
  1431. }
  1432. if (hr == S_OK)
  1433. {
  1434. pAsyncInfo->uMsgID = uRespID;
  1435. }
  1436. else
  1437. {
  1438. MemFree (pReq);
  1439. }
  1440. return hr;
  1441. }
  1442. LPARAM
  1443. AsynReq_SetMeetingInfo ( MARSHAL_REQ *pReq )
  1444. {
  1445. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1446. MyAssert (pReq != NULL);
  1447. MyAssert (pReq->uNotifyMsg == WM_ILS_SET_MEETING_INFO);
  1448. // Delinearize parameters
  1449. //
  1450. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  1451. TCHAR *pszMtgName = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  1452. LDAP_MEETINFO *pInfo = (LDAP_MEETINFO *) MarshalReq_GetParam (pReq, 2);
  1453. MyAssert (! MyIsBadServerInfo (pServer));
  1454. MyAssert (MyIsGoodString (pszMtgName));
  1455. MyAssert (! MyIsBadWritePtr (pInfo, pInfo->uSize));
  1456. // Set standard/arbitrary attributes
  1457. //
  1458. return (LPARAM) MtgSetAttrs (pServer, pszMtgName, pInfo, pReq->uRespID);
  1459. }
  1460. #endif // ENABLE_MEETING_PLACE
  1461. /* ----------------------------------------------------------------------
  1462. My_EnumClientsEx
  1463. History:
  1464. 10/15/96 Chu, Lon-Chan [lonchanc]
  1465. Created.
  1466. 10/30/96 Chu, Lon-Chan [lonchanc]
  1467. Tested on ILS (7438)
  1468. 1/14/97 Chu, Lon-Chan [lonchanc]
  1469. Collapsed user/app objects.
  1470. ---------------------------------------------------------------------- */
  1471. HRESULT
  1472. My_EnumClientsEx (
  1473. ULONG uNotifyMsg,
  1474. SERVER_INFO *pServer,
  1475. TCHAR *pszAnyAttrNameList,
  1476. ULONG cAnyAttrNames,
  1477. TCHAR *pszFilter,
  1478. LDAP_ASYNCINFO *pAsyncInfo )
  1479. {
  1480. HRESULT hr;
  1481. // Make sure we only deal with the following messages
  1482. //
  1483. MyAssert ( uNotifyMsg == WM_ILS_ENUM_CLIENTINFOS ||
  1484. uNotifyMsg == WM_ILS_ENUM_CLIENTS);
  1485. // Make sure this service provider is initialized
  1486. //
  1487. if (g_cInitialized <= 0)
  1488. return ILS_E_NOT_INITIALIZED;
  1489. // Make sure the async info structure is valid
  1490. //
  1491. if (pAsyncInfo == NULL)
  1492. return ILS_E_POINTER;
  1493. // Maks sure the server name is valid
  1494. //
  1495. if (MyIsBadServerInfo (pServer))
  1496. return ILS_E_POINTER;
  1497. // Compute the total size of the data
  1498. //
  1499. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  1500. ULONG cbSizeAnyAttrNames = 0;
  1501. TCHAR *psz = pszAnyAttrNameList;
  1502. ULONG cch;
  1503. for (ULONG i = 0; i < cAnyAttrNames; i++)
  1504. {
  1505. cch = lstrlen (psz) + 1;
  1506. cbSizeAnyAttrNames += cch * sizeof (TCHAR);
  1507. psz += cch;
  1508. }
  1509. ULONG cbSizeFilter = (pszFilter != NULL) ? (lstrlen (pszFilter) + 1) * sizeof (TCHAR) : 0;
  1510. ULONG cParams = 4;
  1511. ULONG cbSize = cbServer + cbSizeAnyAttrNames + cbSizeFilter;
  1512. // Allocate marshall request buffer
  1513. //
  1514. MARSHAL_REQ *pReq = MarshalReq_Alloc (uNotifyMsg, cbSize, cParams);
  1515. if (pReq == NULL)
  1516. return ILS_E_MEMORY;
  1517. // Get the response ID
  1518. //
  1519. ULONG uRespID = pReq->uRespID;
  1520. // Linearize parameters
  1521. //
  1522. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  1523. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pszAnyAttrNameList, cbSizeAnyAttrNames);
  1524. MarshalReq_SetParam (pReq, 2, (DWORD) cAnyAttrNames, 0);
  1525. MarshalReq_SetParam (pReq, 3, (DWORD_PTR) pszFilter, cbSizeFilter);
  1526. // Enter the request
  1527. //
  1528. if (g_pReqQueue != NULL)
  1529. {
  1530. hr = g_pReqQueue->Enter (pReq);
  1531. }
  1532. else
  1533. {
  1534. MyAssert (FALSE);
  1535. hr = ILS_E_FAIL;
  1536. }
  1537. if (hr == S_OK)
  1538. {
  1539. pAsyncInfo->uMsgID = uRespID;
  1540. }
  1541. else
  1542. {
  1543. MemFree (pReq);
  1544. }
  1545. return hr;
  1546. }
  1547. LPARAM
  1548. AsynReq_EnumClientsEx ( MARSHAL_REQ *pReq )
  1549. {
  1550. HRESULT hr = S_OK;
  1551. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1552. MyAssert (pReq != NULL);
  1553. ULONG uNotifyMsg = pReq->uNotifyMsg;
  1554. // Delinearize parameters
  1555. //
  1556. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  1557. TCHAR *pszAnyAttrNameList = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  1558. ULONG cAnyAttrNames = (ULONG) MarshalReq_GetParam (pReq, 2);
  1559. TCHAR *pszFilter = (TCHAR *) MarshalReq_GetParam (pReq, 3);
  1560. // Clean locals
  1561. //
  1562. SP_CSession *pSession = NULL;
  1563. LDAP *ld;
  1564. ULONG uMsgID = (ULONG) -1;
  1565. // Create an array of names of attributes to return
  1566. //
  1567. TCHAR *apszAttrNames[COUNT_ENUM_DIR_CLIENT_INFO+1];
  1568. TCHAR **ppszNameList = &apszAttrNames[0];
  1569. ULONG cTotalNames;
  1570. // See the input filter string
  1571. //
  1572. if (pszFilter != NULL)
  1573. {
  1574. MyDebugMsg ((ZONE_FILTER, "EC: in-filter=[%s]\r\n", pszFilter));
  1575. }
  1576. // Create a enum client filter
  1577. //
  1578. pszFilter = AddBaseToFilter (pszFilter, STR_DEF_CLIENT_BASE_DN);
  1579. if (pszFilter == NULL)
  1580. {
  1581. hr = ILS_E_MEMORY;
  1582. goto MyExit;
  1583. }
  1584. // See the enhanced filter string
  1585. //
  1586. if (pszFilter != NULL)
  1587. {
  1588. MyDebugMsg ((ZONE_FILTER, "EC: out-filter=[%s]\r\n", pszFilter));
  1589. }
  1590. // Ask directory standard attributes only if enum client info
  1591. //
  1592. if (uNotifyMsg == WM_ILS_ENUM_CLIENTINFOS)
  1593. {
  1594. // Default total number of attributes
  1595. //
  1596. cTotalNames = COUNT_ENUM_DIR_CLIENT_INFO;
  1597. // Do we want any extended attribute to be returned?
  1598. //
  1599. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  1600. {
  1601. // Prefix arbitrary attribute names
  1602. //
  1603. pszAnyAttrNameList = IlsPrefixNameValueArray (FALSE, cAnyAttrNames,
  1604. (const TCHAR *) pszAnyAttrNameList);
  1605. if (pszAnyAttrNameList == NULL)
  1606. {
  1607. MemFree (pszFilter);
  1608. hr = ILS_E_MEMORY;
  1609. goto MyExit;
  1610. }
  1611. // Allocate memory for returned attributes' names
  1612. //
  1613. cTotalNames += cAnyAttrNames;
  1614. ppszNameList = (TCHAR **) MemAlloc (sizeof (TCHAR *) * (cTotalNames + 1));
  1615. if (ppszNameList == NULL)
  1616. {
  1617. MemFree (pszFilter);
  1618. MemFree (pszAnyAttrNameList);
  1619. hr = ILS_E_MEMORY;
  1620. goto MyExit;
  1621. }
  1622. }
  1623. }
  1624. else
  1625. {
  1626. cTotalNames = 1;
  1627. }
  1628. // Ask to return cn only if enum names only
  1629. //
  1630. ppszNameList[0] = STR_CLIENT_CN;
  1631. // Add names of standard/extended attributes to return
  1632. //
  1633. if (uNotifyMsg == WM_ILS_ENUM_CLIENTINFOS)
  1634. {
  1635. // Set up standard attribtues now
  1636. //
  1637. for (ULONG i = 1; i < COUNT_ENUM_DIR_CLIENT_INFO; i++)
  1638. {
  1639. ppszNameList[i] = (TCHAR *) c_apszClientStdAttrNames[i];
  1640. }
  1641. // Set arbitrary attribute names if needed
  1642. //
  1643. TCHAR *psz = pszAnyAttrNameList;
  1644. for (i = COUNT_ENUM_DIR_CLIENT_INFO; i < cTotalNames; i++)
  1645. {
  1646. ppszNameList[i] = psz;
  1647. psz += lstrlen (psz) + 1;
  1648. }
  1649. }
  1650. // Terminate the list
  1651. //
  1652. ppszNameList[cTotalNames] = NULL;
  1653. // Get a session object
  1654. //
  1655. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  1656. if (hr == S_OK)
  1657. {
  1658. // Get an ldap session
  1659. //
  1660. MyAssert (pSession != NULL);
  1661. ld = pSession->GetLd ();
  1662. MyAssert (ld != NULL);
  1663. // Update options in ld
  1664. //
  1665. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  1666. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  1667. ld->ld_deref = LDAP_DEREF_ALWAYS;
  1668. // Send search query
  1669. //
  1670. uMsgID = ldap_search ( ld,
  1671. STR_DEF_CLIENT_BASE_DN, // base DN
  1672. LDAP_SCOPE_BASE, // scope
  1673. pszFilter, // filter
  1674. ppszNameList, // attrs[]
  1675. 0); // both type and value
  1676. if (uMsgID == -1)
  1677. {
  1678. // This ldap_search failed.
  1679. // Convert ldap error code to hr
  1680. //
  1681. hr = ::LdapError2Hresult (ld->ld_errno);
  1682. // Free the session object
  1683. //
  1684. pSession->Disconnect ();
  1685. }
  1686. }
  1687. // Free the filter string
  1688. //
  1689. MemFree (pszFilter);
  1690. // Free the buffer holding all returned attribute names if needed
  1691. //
  1692. if (ppszNameList != &apszAttrNames[0])
  1693. MemFree (ppszNameList);
  1694. // Report failure if so
  1695. //
  1696. if (hr != S_OK)
  1697. {
  1698. // Free extended attribute name list
  1699. //
  1700. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  1701. MemFree (pszAnyAttrNameList);
  1702. // Report failure
  1703. //
  1704. goto MyExit;
  1705. }
  1706. // Construct a pending info structure
  1707. //
  1708. RESP_INFO ri;
  1709. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  1710. ri.uNotifyMsg = uNotifyMsg;
  1711. ri.cAnyAttrs = cAnyAttrNames;
  1712. ri.pszAnyAttrNameList = pszAnyAttrNameList;
  1713. // Queue this pending response
  1714. //
  1715. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  1716. if (hr != S_OK)
  1717. {
  1718. // Abort the ldap_search
  1719. //
  1720. ldap_abandon (ld, uMsgID);
  1721. // Free the session object
  1722. //
  1723. pSession->Disconnect ();
  1724. MyAssert (FALSE);
  1725. }
  1726. MyExit:
  1727. LDAP_ENUM *pEnum = NULL;
  1728. if (hr != S_OK)
  1729. {
  1730. pEnum = (LDAP_ENUM *) MemAlloc (sizeof (LDAP_ENUM));
  1731. if (pEnum != NULL)
  1732. {
  1733. pEnum->uSize = sizeof (*pEnum);
  1734. pEnum->hResult = hr;
  1735. }
  1736. }
  1737. return (LPARAM) pEnum;
  1738. }
  1739. /* ----------------------------------------------------------------------
  1740. UlsLdap_EnumClients
  1741. History:
  1742. 10/15/96 Chu, Lon-Chan [lonchanc]
  1743. Created.
  1744. 10/30/96 Chu, Lon-Chan [lonchanc]
  1745. Tested on ILS (7438)
  1746. 1/14/97 Chu, Lon-Chan [lonchanc]
  1747. Collapsed user/app objects.
  1748. ---------------------------------------------------------------------- */
  1749. HRESULT
  1750. UlsLdap_EnumClients (
  1751. SERVER_INFO *pServer,
  1752. TCHAR *pszFilter,
  1753. LDAP_ASYNCINFO *pAsyncInfo )
  1754. {
  1755. // Dispatch the call to a common subroutine
  1756. //
  1757. return My_EnumClientsEx (WM_ILS_ENUM_CLIENTS,
  1758. pServer,
  1759. NULL,
  1760. 0,
  1761. pszFilter,
  1762. pAsyncInfo);
  1763. }
  1764. /* ----------------------------------------------------------------------
  1765. UlsLdap_EnumClientInfos
  1766. History:
  1767. 10/15/96 Chu, Lon-Chan [lonchanc]
  1768. Created.
  1769. 10/30/96 Chu, Lon-Chan [lonchanc]
  1770. Tested on ILS (7438)
  1771. 1/14/97 Chu, Lon-Chan [lonchanc]
  1772. Collapsed user/app objects.
  1773. ---------------------------------------------------------------------- */
  1774. HRESULT
  1775. UlsLdap_EnumClientInfos (
  1776. SERVER_INFO *pServer,
  1777. TCHAR *pszAnyAttrNameList,
  1778. ULONG cAnyAttrNames,
  1779. TCHAR *pszFilter,
  1780. LDAP_ASYNCINFO *pAsyncInfo )
  1781. {
  1782. // Dispatch the call to a common subroutine
  1783. //
  1784. return My_EnumClientsEx (WM_ILS_ENUM_CLIENTINFOS,
  1785. pServer,
  1786. pszAnyAttrNameList,
  1787. cAnyAttrNames,
  1788. pszFilter,
  1789. pAsyncInfo);
  1790. }
  1791. /* ----------------------------------------------------------------------
  1792. UlsLdap_EnumProtocols
  1793. History:
  1794. 10/15/96 Chu, Lon-Chan [lonchanc]
  1795. Created.
  1796. 10/30/96 Chu, Lon-Chan [lonchanc]
  1797. Blocked by ILS (7438, 7442)
  1798. ---------------------------------------------------------------------- */
  1799. HRESULT
  1800. UlsLdap_EnumProtocols (
  1801. SERVER_INFO *pServer,
  1802. TCHAR *pszUserName,
  1803. TCHAR *pszAppName,
  1804. LDAP_ASYNCINFO *pAsyncInfo )
  1805. {
  1806. HRESULT hr;
  1807. // Make sure this service provider is initialized
  1808. //
  1809. if (g_cInitialized <= 0)
  1810. return ILS_E_NOT_INITIALIZED;
  1811. if (MyIsBadServerInfo (pServer) || MyIsBadString (pszUserName) ||
  1812. MyIsBadString (pszAppName))
  1813. return ILS_E_POINTER;
  1814. // Make sure the async info structure is valid
  1815. //
  1816. if (pAsyncInfo == NULL)
  1817. return ILS_E_POINTER;
  1818. // Compute the total size of the data
  1819. //
  1820. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  1821. ULONG cbSizeUserName = (lstrlen (pszUserName) + 1) * sizeof (TCHAR);
  1822. ULONG cbSizeAppName = (lstrlen (pszAppName) + 1) * sizeof (TCHAR);
  1823. ULONG cParams = 3;
  1824. ULONG cbSize = cbServer + cbSizeUserName + cbSizeAppName;
  1825. // Allocate marshall request buffer
  1826. //
  1827. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_ENUM_PROTOCOLS, cbSize, cParams);
  1828. if (pReq == NULL)
  1829. return ILS_E_MEMORY;
  1830. // Get the response ID
  1831. //
  1832. ULONG uRespID = pReq->uRespID;
  1833. // Linearize parameters
  1834. //
  1835. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  1836. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pszUserName, cbSizeUserName);
  1837. MarshalReq_SetParam (pReq, 2, (DWORD_PTR) pszAppName, cbSizeAppName);
  1838. // Enter the request
  1839. //
  1840. if (g_pReqQueue != NULL)
  1841. {
  1842. hr = g_pReqQueue->Enter (pReq);
  1843. }
  1844. else
  1845. {
  1846. MyAssert (FALSE);
  1847. hr = ILS_E_FAIL;
  1848. }
  1849. if (hr == S_OK)
  1850. {
  1851. pAsyncInfo->uMsgID = uRespID;
  1852. }
  1853. else
  1854. {
  1855. MemFree (pReq);
  1856. }
  1857. return hr;
  1858. }
  1859. LPARAM
  1860. AsynReq_EnumProtocols ( MARSHAL_REQ *pReq )
  1861. {
  1862. HRESULT hr = S_OK;
  1863. SP_CSession *pSession = NULL;
  1864. LDAP *ld;
  1865. ULONG uMsgID = (ULONG) -1;
  1866. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  1867. MyAssert (pReq != NULL);
  1868. MyAssert (pReq->uNotifyMsg == WM_ILS_ENUM_PROTOCOLS);
  1869. // Delinearize parameters
  1870. //
  1871. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  1872. TCHAR *pszUserName = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  1873. TCHAR *pszAppName = (TCHAR *) MarshalReq_GetParam (pReq, 2);
  1874. // Create enum protocols filter
  1875. //
  1876. TCHAR *pszFilter = ProtCreateEnumFilter (pszUserName, pszAppName);
  1877. if (pszFilter == NULL)
  1878. {
  1879. hr = ILS_E_MEMORY;
  1880. goto MyExit;
  1881. }
  1882. // Get the session object
  1883. //
  1884. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  1885. if (hr != S_OK)
  1886. {
  1887. MemFree (pszFilter);
  1888. goto MyExit;
  1889. }
  1890. MyAssert (pSession != NULL);
  1891. // Get an ldap session
  1892. //
  1893. ld = pSession->GetLd ();
  1894. MyAssert (ld != NULL);
  1895. // Create an array of names of attributes to return
  1896. //
  1897. TCHAR *apszAttrNames[2];
  1898. apszAttrNames[0] = (TCHAR *) c_apszProtStdAttrNames[ENUM_PROTATTR_NAME];
  1899. apszAttrNames[1] = NULL;
  1900. // Update options in ld
  1901. //
  1902. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  1903. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  1904. ld->ld_deref = LDAP_DEREF_ALWAYS;
  1905. // Send the search query
  1906. //
  1907. uMsgID = ldap_search (ld, (TCHAR *) &c_szDefClientBaseDN[0], // base DN
  1908. LDAP_SCOPE_BASE, // scope
  1909. pszFilter,
  1910. &apszAttrNames[0], // attrs[]
  1911. 0); // both type and value
  1912. // Free the search filter
  1913. //
  1914. MemFree (pszFilter);
  1915. // Check the return of ldap_search
  1916. //
  1917. if (uMsgID == -1)
  1918. {
  1919. // This ldap_search failed.
  1920. // Convert ldap error code to hr
  1921. //
  1922. hr = ::LdapError2Hresult (ld->ld_errno);
  1923. // Free the session object
  1924. //
  1925. pSession->Disconnect ();
  1926. goto MyExit;
  1927. }
  1928. // Construct a pending info structure
  1929. //
  1930. RESP_INFO ri;
  1931. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  1932. ri.uNotifyMsg = WM_ILS_ENUM_PROTOCOLS;
  1933. // Queue this pending response
  1934. //
  1935. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  1936. if (hr != S_OK)
  1937. {
  1938. // Abort the ldap_search
  1939. //
  1940. ldap_abandon (ld, uMsgID);
  1941. // Free the session object
  1942. //
  1943. pSession->Disconnect ();
  1944. MyAssert (FALSE);
  1945. }
  1946. MyExit:
  1947. LDAP_ENUM *pEnum = NULL;
  1948. if (hr != S_OK)
  1949. {
  1950. pEnum = (LDAP_ENUM *) MemAlloc (sizeof (LDAP_ENUM));
  1951. if (pEnum != NULL)
  1952. {
  1953. pEnum->uSize = sizeof (*pEnum);
  1954. pEnum->hResult = hr;
  1955. }
  1956. }
  1957. return (LPARAM) pEnum;
  1958. }
  1959. /* ----------------------------------------------------------------------
  1960. My_EnumMtgsEx
  1961. Input:
  1962. uNotifyMsg: A notification message.
  1963. pszServer: A pointer to the server name.
  1964. pszFilter: A pointer to a filter string.
  1965. pAsyncInfo: A pointer to async info structure.
  1966. History:
  1967. 12/02/96 Chu, Lon-Chan [lonchanc]
  1968. Created.
  1969. ---------------------------------------------------------------------- */
  1970. #ifdef ENABLE_MEETING_PLACE
  1971. HRESULT
  1972. My_EnumMtgsEx (
  1973. ULONG uNotifyMsg,
  1974. SERVER_INFO *pServer,
  1975. TCHAR *pszAnyAttrNameList,
  1976. ULONG cAnyAttrNames,
  1977. TCHAR *pszFilter,
  1978. LDAP_ASYNCINFO *pAsyncInfo )
  1979. {
  1980. HRESULT hr;
  1981. // Make sure we only deal with the following messages
  1982. //
  1983. MyAssert ( uNotifyMsg == WM_ILS_ENUM_MEETINGINFOS ||
  1984. uNotifyMsg == WM_ILS_ENUM_MEETINGS);
  1985. // Make sure this service provider is initialized
  1986. //
  1987. if (g_cInitialized <= 0)
  1988. return ILS_E_NOT_INITIALIZED;
  1989. // Maks sure the server name is valid
  1990. //
  1991. if (MyIsBadServerInfo (pServer))
  1992. return ILS_E_POINTER;
  1993. // Make sure the async info structure is valid
  1994. //
  1995. if (pAsyncInfo == NULL)
  1996. return ILS_E_POINTER;
  1997. // Compute the total size of the data
  1998. //
  1999. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  2000. ULONG cbSizeAnyAttrNames = 0;
  2001. TCHAR *psz = pszAnyAttrNameList;
  2002. ULONG cch;
  2003. for (ULONG i = 0; i < cAnyAttrNames; i++)
  2004. {
  2005. cch = lstrlen (psz) + 1;
  2006. cbSizeAnyAttrNames += cch * sizeof (TCHAR);
  2007. psz += cch;
  2008. }
  2009. ULONG cbSizeFilter = (pszFilter != NULL) ? (lstrlen (pszFilter) + 1) * sizeof (TCHAR) : 0;
  2010. ULONG cParams = 4;
  2011. ULONG cbSize = cbServer + cbSizeAnyAttrNames + cbSizeFilter;
  2012. // Allocate marshall request buffer
  2013. //
  2014. MARSHAL_REQ *pReq = MarshalReq_Alloc (uNotifyMsg, cbSize, cParams);
  2015. if (pReq == NULL)
  2016. return ILS_E_MEMORY;
  2017. // Get the response ID
  2018. //
  2019. ULONG uRespID = pReq->uRespID;
  2020. // Linearize parameters
  2021. //
  2022. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  2023. MarshalReq_SetParam (pReq, 1, (DWORD) pszAnyAttrNameList, cbSizeAnyAttrNames);
  2024. MarshalReq_SetParam (pReq, 2, (DWORD) cAnyAttrNames, 0);
  2025. MarshalReq_SetParam (pReq, 3, (DWORD) pszFilter, cbSizeFilter);
  2026. // Enter the request
  2027. //
  2028. if (g_pReqQueue != NULL)
  2029. {
  2030. hr = g_pReqQueue->Enter (pReq);
  2031. }
  2032. else
  2033. {
  2034. MyAssert (FALSE);
  2035. hr = ILS_E_FAIL;
  2036. }
  2037. if (hr == S_OK)
  2038. {
  2039. pAsyncInfo->uMsgID = uRespID;
  2040. }
  2041. else
  2042. {
  2043. MemFree (pReq);
  2044. }
  2045. return hr;
  2046. }
  2047. LPARAM
  2048. AsynReq_EnumMtgsEx ( MARSHAL_REQ *pReq )
  2049. {
  2050. HRESULT hr = S_OK;
  2051. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  2052. MyAssert (pReq != NULL);
  2053. ULONG uNotifyMsg = pReq->uNotifyMsg;
  2054. // Delinearize parameters
  2055. //
  2056. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  2057. TCHAR *pszAnyAttrNameList = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  2058. ULONG cAnyAttrNames = (ULONG) MarshalReq_GetParam (pReq, 2);
  2059. TCHAR *pszFilter = (TCHAR *) MarshalReq_GetParam (pReq, 3);
  2060. // Clean locals
  2061. //
  2062. SP_CSession *pSession = NULL;
  2063. LDAP *ld;
  2064. ULONG uMsgID = (ULONG) -1;
  2065. // Create an array of names of attributes to return
  2066. //
  2067. TCHAR *apszAttrNames[COUNT_ENUM_DIRMTGINFO+1];
  2068. TCHAR **ppszNameList = &apszAttrNames[0];
  2069. ULONG cTotalNames;
  2070. // See the input filter string
  2071. //
  2072. if (pszFilter != NULL)
  2073. {
  2074. MyDebugMsg ((ZONE_FILTER, "EU: in-filter=[%s]\r\n", pszFilter));
  2075. }
  2076. // Create a enum user filter
  2077. //
  2078. pszFilter = AddBaseToFilter (pszFilter, &c_szDefMtgBaseDN[0]);
  2079. if (pszFilter == NULL)
  2080. {
  2081. hr = ILS_E_MEMORY;
  2082. goto MyExit;
  2083. }
  2084. // See the enhanced filter string
  2085. //
  2086. if (pszFilter != NULL)
  2087. {
  2088. MyDebugMsg ((ZONE_FILTER, "EU: out-filter=[%s]\r\n", pszFilter));
  2089. }
  2090. // Ask directory standard attributes only if enum dir user info
  2091. //
  2092. if (uNotifyMsg == WM_ILS_ENUM_MEETINGINFOS)
  2093. {
  2094. // Default total number of attributes
  2095. //
  2096. cTotalNames = COUNT_ENUM_DIRMTGINFO;
  2097. // Do we want any extended attribute to be returned?
  2098. //
  2099. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  2100. {
  2101. // Prefix arbitrary attribute names
  2102. //
  2103. pszAnyAttrNameList = IlsPrefixNameValueArray (FALSE, cAnyAttrNames,
  2104. (const TCHAR *) pszAnyAttrNameList);
  2105. if (pszAnyAttrNameList == NULL)
  2106. {
  2107. MemFree (pszFilter);
  2108. hr = ILS_E_MEMORY;
  2109. goto MyExit;
  2110. }
  2111. // Allocate memory for returned attributes' names
  2112. //
  2113. cTotalNames += cAnyAttrNames;
  2114. ppszNameList = (TCHAR **) MemAlloc (sizeof (TCHAR *) * (cTotalNames + 1));
  2115. if (ppszNameList == NULL)
  2116. {
  2117. MemFree (pszFilter);
  2118. MemFree (pszAnyAttrNameList);
  2119. hr = ILS_E_MEMORY;
  2120. goto MyExit;
  2121. }
  2122. }
  2123. }
  2124. else
  2125. {
  2126. cTotalNames = 1;
  2127. }
  2128. // Ask to return cn only if enum names only
  2129. //
  2130. ppszNameList[0] = STR_MTG_NAME;
  2131. // Add names of standard/extended attributes to return
  2132. //
  2133. if (uNotifyMsg == WM_ILS_ENUM_MEETINGINFOS)
  2134. {
  2135. // Set up standard attribtues now
  2136. //
  2137. for (ULONG i = 1; i < COUNT_ENUM_DIRMTGINFO; i++)
  2138. {
  2139. ppszNameList[i] = (TCHAR *) c_apszMtgStdAttrNames[i];
  2140. }
  2141. // Set arbitrary attribute names if needed
  2142. //
  2143. TCHAR *psz = pszAnyAttrNameList;
  2144. for (i = COUNT_ENUM_DIRMTGINFO; i < cTotalNames; i++)
  2145. {
  2146. ppszNameList[i] = psz;
  2147. psz += lstrlen (psz) + 1;
  2148. }
  2149. }
  2150. // Terminate the list
  2151. //
  2152. ppszNameList[cTotalNames] = NULL;
  2153. // Get a session object
  2154. //
  2155. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  2156. if (hr == S_OK)
  2157. {
  2158. // Get an ldap session
  2159. //
  2160. MyAssert (pSession != NULL);
  2161. ld = pSession->GetLd ();
  2162. MyAssert (ld != NULL);
  2163. // Update options in ld
  2164. //
  2165. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  2166. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  2167. ld->ld_deref = LDAP_DEREF_ALWAYS;
  2168. // Send search query
  2169. //
  2170. uMsgID = ldap_search (ld, (TCHAR *) &c_szDefMtgBaseDN[0], // base DN
  2171. LDAP_SCOPE_BASE, // scope
  2172. pszFilter, // filter
  2173. ppszNameList, // attrs[]
  2174. 0); // both type and value
  2175. if (uMsgID == -1)
  2176. {
  2177. // This ldap_search failed.
  2178. // Convert ldap error code to hr
  2179. //
  2180. hr = ::LdapError2Hresult (ld->ld_errno);
  2181. // Free the session object
  2182. //
  2183. pSession->Disconnect ();
  2184. }
  2185. }
  2186. // Free the filter string
  2187. //
  2188. MemFree (pszFilter);
  2189. // Free the buffer holding all returned attribute names if needed
  2190. //
  2191. if (ppszNameList != &apszAttrNames[0])
  2192. MemFree (ppszNameList);
  2193. // Report failure if so
  2194. //
  2195. if (hr != S_OK)
  2196. {
  2197. // Free extended attribute name list
  2198. //
  2199. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  2200. MemFree (pszAnyAttrNameList);
  2201. // Report failure
  2202. //
  2203. goto MyExit;
  2204. }
  2205. // Construct a pending info structure
  2206. //
  2207. RESP_INFO ri;
  2208. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  2209. ri.uNotifyMsg = uNotifyMsg;
  2210. ri.cAnyAttrs = cAnyAttrNames;
  2211. // Queue this pending response
  2212. //
  2213. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  2214. if (hr != S_OK)
  2215. {
  2216. // Abort the ldap_search
  2217. //
  2218. ldap_abandon (ld, uMsgID);
  2219. // Free the session object
  2220. //
  2221. pSession->Disconnect ();
  2222. MyAssert (FALSE);
  2223. }
  2224. MyExit:
  2225. LDAP_ENUM *pEnum = NULL;
  2226. if (hr != S_OK)
  2227. {
  2228. pEnum = (LDAP_ENUM *) MemAlloc (sizeof (LDAP_ENUM));
  2229. if (pEnum != NULL)
  2230. {
  2231. pEnum->uSize = sizeof (*pEnum);
  2232. pEnum->hResult = hr;
  2233. }
  2234. }
  2235. return (LPARAM) pEnum;
  2236. }
  2237. #endif // ENABLE_MEETING_PLACE
  2238. /* ----------------------------------------------------------------------
  2239. UlsLdap_EnumMeetingInfos
  2240. Input:
  2241. pszServer: server name.
  2242. pszFilter: a filter string.
  2243. pAsyncInfo: a pointer to async info structure.
  2244. History:
  2245. 12/02/96 Chu, Lon-Chan [lonchanc]
  2246. Created.
  2247. ---------------------------------------------------------------------- */
  2248. #ifdef ENABLE_MEETING_PLACE
  2249. HRESULT
  2250. UlsLdap_EnumMeetingInfos (
  2251. SERVER_INFO *pServer,
  2252. TCHAR *pszAnyAttrNameList,
  2253. ULONG cAnyAttrNames,
  2254. TCHAR *pszFilter,
  2255. LDAP_ASYNCINFO *pAsyncInfo )
  2256. {
  2257. // Dispatch the call to a common subroutine
  2258. //
  2259. return My_EnumMtgsEx (WM_ILS_ENUM_MEETINGINFOS,
  2260. pServer,
  2261. pszAnyAttrNameList,
  2262. cAnyAttrNames,
  2263. pszFilter,
  2264. pAsyncInfo);
  2265. }
  2266. #endif // ENABLE_MEETING_PLACE
  2267. /* ----------------------------------------------------------------------
  2268. UlsLdap_EnumMeetings
  2269. Input:
  2270. pszServer: server name.
  2271. pszFilter: a filter string.
  2272. pAsyncInfo: a pointer to async info structure.
  2273. History:
  2274. 12/02/96 Chu, Lon-Chan [lonchanc]
  2275. Created.
  2276. ---------------------------------------------------------------------- */
  2277. #ifdef ENABLE_MEETING_PLACE
  2278. HRESULT
  2279. UlsLdap_EnumMeetings (
  2280. SERVER_INFO *pServer,
  2281. TCHAR *pszFilter,
  2282. LDAP_ASYNCINFO *pAsyncInfo )
  2283. {
  2284. // Make sure this service provider is initialized
  2285. //
  2286. if (g_cInitialized <= 0)
  2287. return ILS_E_NOT_INITIALIZED;
  2288. // Dispatch the call to a common subroutine
  2289. //
  2290. return My_EnumMtgsEx (WM_ILS_ENUM_MEETINGS,
  2291. pServer,
  2292. NULL,
  2293. 0,
  2294. pszFilter,
  2295. pAsyncInfo);
  2296. }
  2297. #endif // ENABLE_MEETING_PLACE
  2298. /* ----------------------------------------------------------------------
  2299. UlsLdap_EnumAttendee
  2300. Input:
  2301. pszServer: server name.
  2302. pszMeetingID: a meeting id string.
  2303. pszFilter: a filter string.
  2304. pAsyncInfo: a pointer to async info structure.
  2305. History:
  2306. 12/02/96 Chu, Lon-Chan [lonchanc]
  2307. Created.
  2308. ---------------------------------------------------------------------- */
  2309. #ifdef ENABLE_MEETING_PLACE
  2310. HRESULT
  2311. UlsLdap_EnumAttendees(
  2312. SERVER_INFO *pServer,
  2313. TCHAR *pszMtgName,
  2314. TCHAR *pszFilter,
  2315. LDAP_ASYNCINFO *pAsyncInfo )
  2316. {
  2317. HRESULT hr;
  2318. // Make sure this service provider is initialized
  2319. //
  2320. if (g_cInitialized <= 0)
  2321. return ILS_E_NOT_INITIALIZED;
  2322. if (MyIsBadServerInfo (pServer) || MyIsBadString (pszMtgName))
  2323. return ILS_E_POINTER;
  2324. // Make sure the async info structure is valid
  2325. //
  2326. if (pAsyncInfo == NULL)
  2327. return ILS_E_POINTER;
  2328. // Compute the total size of the data
  2329. //
  2330. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  2331. ULONG cbSizeMtgName = (lstrlen (pszMtgName) + 1) * sizeof (TCHAR);
  2332. ULONG cbSizeFilter = (pszFilter != NULL) ? (lstrlen (pszFilter) + 1) * sizeof (TCHAR) : 0;
  2333. ULONG cParams = 3;
  2334. ULONG cbSize = cbServer + cbSizeMtgName + cbSizeFilter;
  2335. // Allocate marshall request buffer
  2336. //
  2337. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_ENUM_ATTENDEES, cbSize, cParams);
  2338. if (pReq == NULL)
  2339. return ILS_E_MEMORY;
  2340. // Get the response ID
  2341. //
  2342. ULONG uRespID = pReq->uRespID;
  2343. // Linearize parameters
  2344. //
  2345. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  2346. MarshalReq_SetParam (pReq, 1, (DWORD) pszMtgName, cbSizeMtgName);
  2347. MarshalReq_SetParam (pReq, 2, (DWORD) pszFilter, cbSizeFilter);
  2348. // Enter the request
  2349. //
  2350. if (g_pReqQueue != NULL)
  2351. {
  2352. hr = g_pReqQueue->Enter (pReq);
  2353. }
  2354. else
  2355. {
  2356. MyAssert (FALSE);
  2357. hr = ILS_E_FAIL;
  2358. }
  2359. if (hr == S_OK)
  2360. {
  2361. pAsyncInfo->uMsgID = uRespID;
  2362. }
  2363. else
  2364. {
  2365. MemFree (pReq);
  2366. }
  2367. return hr;
  2368. }
  2369. LPARAM
  2370. AsynReq_EnumAttendees ( MARSHAL_REQ *pReq )
  2371. {
  2372. HRESULT hr = S_OK;
  2373. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  2374. MyAssert (pReq != NULL);
  2375. MyAssert (pReq->uNotifyMsg == WM_ILS_ENUM_ATTENDEES);
  2376. // Delinearize parameters
  2377. //
  2378. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  2379. TCHAR *pszMtgName = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  2380. TCHAR *pszFilter = (TCHAR *) MarshalReq_GetParam (pReq, 2);
  2381. // Clean up locals
  2382. //
  2383. SP_CSession *pSession = NULL;
  2384. LDAP *ld;
  2385. ULONG uMsgID = (ULONG) -1;
  2386. // BUGS: ignore the input filter
  2387. //
  2388. pszFilter = MtgCreateEnumMembersFilter (pszMtgName);
  2389. if (pszFilter == NULL)
  2390. {
  2391. hr = ILS_E_MEMORY;
  2392. goto MyExit;
  2393. }
  2394. // Create an array of names of attributes to return
  2395. //
  2396. TCHAR *apszAttrNames[3];
  2397. apszAttrNames[0] = STR_MTG_NAME;
  2398. apszAttrNames[1] = (TCHAR *) c_apszMtgStdAttrNames[ENUM_MTGATTR_MEMBERS];
  2399. apszAttrNames[2] = NULL;
  2400. // Get the session object
  2401. //
  2402. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  2403. if (hr != S_OK)
  2404. {
  2405. MemFree (pszFilter);
  2406. goto MyExit;
  2407. }
  2408. MyAssert (pSession != NULL);
  2409. // Get an ldap session
  2410. //
  2411. ld = pSession->GetLd ();
  2412. MyAssert (ld != NULL);
  2413. // Update options in ld
  2414. //
  2415. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  2416. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  2417. ld->ld_deref = LDAP_DEREF_ALWAYS;
  2418. // Send the search query
  2419. //
  2420. uMsgID = ldap_search (ld, (TCHAR *) &c_szDefMtgBaseDN[0], // base DN
  2421. LDAP_SCOPE_BASE, // scope
  2422. pszFilter,
  2423. &apszAttrNames[0], // attrs[]
  2424. 0); // both type and value
  2425. // Free the search filter
  2426. //
  2427. MemFree (pszFilter);
  2428. // Check the return of ldap_search
  2429. //
  2430. if (uMsgID == -1)
  2431. {
  2432. // This ldap_search failed.
  2433. // Convert ldap error code to hr
  2434. //
  2435. hr = ::LdapError2Hresult (ld->ld_errno);
  2436. // Free the session object
  2437. //
  2438. pSession->Disconnect ();
  2439. goto MyExit;
  2440. }
  2441. // Construct a pending info structure
  2442. //
  2443. RESP_INFO ri;
  2444. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  2445. ri.uNotifyMsg = WM_ILS_ENUM_ATTENDEES;
  2446. // Queue this pending response
  2447. //
  2448. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  2449. if (hr != S_OK)
  2450. {
  2451. // Abort the ldap_search
  2452. //
  2453. ldap_abandon (ld, uMsgID);
  2454. // Free the session object
  2455. //
  2456. pSession->Disconnect ();
  2457. MyAssert (FALSE);
  2458. }
  2459. MyExit:
  2460. LDAP_ENUM *pEnum = NULL;
  2461. if (hr != S_OK)
  2462. {
  2463. pEnum = (LDAP_ENUM *) MemAlloc (sizeof (LDAP_ENUM));
  2464. if (pEnum != NULL)
  2465. {
  2466. pEnum->uSize = sizeof (*pEnum);
  2467. pEnum->hResult = hr;
  2468. }
  2469. }
  2470. return (LPARAM) pEnum;
  2471. }
  2472. #endif // ENABLE_MEETING_PLACE
  2473. /* ----------------------------------------------------------------------
  2474. UlsLdap_ResolveClient
  2475. History:
  2476. 10/15/96 Chu, Lon-Chan [lonchanc]
  2477. Created.
  2478. 10/30/96 Chu, Lon-Chan [lonchanc]
  2479. Tested on ILS (7438)
  2480. 1/14/97 Chu, Lon-Chan [lonchanc]
  2481. Collapsed user/app objects.
  2482. ---------------------------------------------------------------------- */
  2483. HRESULT
  2484. UlsLdap_ResolveClient (
  2485. SERVER_INFO *pServer,
  2486. TCHAR *pszCN,
  2487. TCHAR *pszAppName,
  2488. TCHAR *pszProtName,
  2489. TCHAR *pszAnyAttrNameList,
  2490. ULONG cAnyAttrNames,
  2491. LDAP_ASYNCINFO *pAsyncInfo )
  2492. {
  2493. HRESULT hr;
  2494. // Make sure this service provider is initialized
  2495. //
  2496. if (g_cInitialized <= 0)
  2497. return ILS_E_NOT_INITIALIZED;
  2498. // Maks sure the server name is valid
  2499. //
  2500. if (MyIsBadServerInfo (pServer))
  2501. return ILS_E_POINTER;
  2502. // Maks sure the user name is valid
  2503. //
  2504. if (MyIsBadString (pszCN))
  2505. return ILS_E_POINTER;
  2506. // Make sure the async info structure is valid
  2507. //
  2508. if (pAsyncInfo == NULL)
  2509. return ILS_E_POINTER;
  2510. // Compute the total size of the data
  2511. //
  2512. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  2513. ULONG cbSizeCN = (lstrlen (pszCN) + 1) * sizeof (TCHAR);
  2514. ULONG cbSizeAppName = (pszAppName != NULL) ? (lstrlen (pszAppName) + 1) * sizeof (TCHAR) : 0;
  2515. ULONG cbSizeProtName = (pszProtName != NULL) ? (lstrlen (pszProtName) + 1) * sizeof (TCHAR) : 0;
  2516. ULONG cbSizeAnyAttrNames = 0;
  2517. TCHAR *psz = pszAnyAttrNameList;
  2518. ULONG cch;
  2519. for (ULONG i = 0; i < cAnyAttrNames; i++)
  2520. {
  2521. cch = lstrlen (psz) + 1;
  2522. cbSizeAnyAttrNames += cch * sizeof (TCHAR);
  2523. psz += cch;
  2524. }
  2525. ULONG cParams = 6;
  2526. ULONG cbSize = cbServer + cbSizeCN + cbSizeAppName + cbSizeProtName + cbSizeAnyAttrNames;
  2527. // Allocate marshall request buffer
  2528. //
  2529. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_RESOLVE_CLIENT, cbSize, cParams);
  2530. if (pReq == NULL)
  2531. return ILS_E_MEMORY;
  2532. // Get the response ID
  2533. //
  2534. ULONG uRespID = pReq->uRespID;
  2535. // Linearize parameters
  2536. //
  2537. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  2538. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pszCN, cbSizeCN);
  2539. MarshalReq_SetParam (pReq, 2, (DWORD_PTR) pszAppName, cbSizeAppName);
  2540. MarshalReq_SetParam (pReq, 3, (DWORD_PTR) pszProtName, cbSizeProtName);
  2541. MarshalReq_SetParam (pReq, 4, (DWORD_PTR) pszAnyAttrNameList, cbSizeAnyAttrNames);
  2542. MarshalReq_SetParam (pReq, 5, (DWORD) cAnyAttrNames, 0);
  2543. // Enter the request
  2544. //
  2545. if (g_pReqQueue != NULL)
  2546. {
  2547. hr = g_pReqQueue->Enter (pReq);
  2548. }
  2549. else
  2550. {
  2551. MyAssert (FALSE);
  2552. hr = ILS_E_FAIL;
  2553. }
  2554. if (hr == S_OK)
  2555. {
  2556. pAsyncInfo->uMsgID = uRespID;
  2557. }
  2558. else
  2559. {
  2560. MemFree (pReq);
  2561. }
  2562. return hr;
  2563. }
  2564. LPARAM
  2565. AsynReq_ResolveClient ( MARSHAL_REQ *pReq )
  2566. {
  2567. HRESULT hr = S_OK;
  2568. SP_CSession *pSession = NULL;
  2569. LDAP *ld;
  2570. ULONG uMsgID = (ULONG) -1;
  2571. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  2572. MyAssert (pReq != NULL);
  2573. MyAssert (pReq->uNotifyMsg == WM_ILS_RESOLVE_CLIENT);
  2574. // Delinearize parameters
  2575. //
  2576. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  2577. TCHAR *pszCN = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  2578. TCHAR *pszAppName = (TCHAR *) MarshalReq_GetParam (pReq, 2);
  2579. TCHAR *pszProtName = (TCHAR *) MarshalReq_GetParam (pReq, 3);
  2580. TCHAR *pszAnyAttrNameList = (TCHAR *) MarshalReq_GetParam (pReq, 4);
  2581. ULONG cAnyAttrNames = (ULONG) MarshalReq_GetParam (pReq, 5);
  2582. // Create a resolve client filter
  2583. //
  2584. TCHAR *pszFilter = ClntCreateResolveFilter (pszCN, pszAppName, pszProtName);
  2585. if (pszFilter == NULL)
  2586. {
  2587. hr = ILS_E_MEMORY;
  2588. goto MyExit;
  2589. }
  2590. // Create an array of names of attributes to return
  2591. //
  2592. TCHAR *apszAttrNames[COUNT_ENUM_RES_CLIENT_INFO+1];
  2593. TCHAR **ppszNameList;
  2594. ppszNameList = &apszAttrNames[0];
  2595. ULONG cTotalNames;
  2596. cTotalNames = COUNT_ENUM_RES_CLIENT_INFO;
  2597. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  2598. {
  2599. // Prefix arbitrary attribute names
  2600. //
  2601. pszAnyAttrNameList = IlsPrefixNameValueArray (FALSE, cAnyAttrNames,
  2602. (const TCHAR *) pszAnyAttrNameList);
  2603. if (pszAnyAttrNameList == NULL)
  2604. {
  2605. MemFree (pszFilter);
  2606. hr = ILS_E_MEMORY;
  2607. goto MyExit;
  2608. }
  2609. // NOTE that pszAnyAttrNameList must be freed if failed in this routine
  2610. // If success, it will be freed in notification.
  2611. // Allocate memory for keeping returned attributes' names
  2612. //
  2613. cTotalNames += cAnyAttrNames;
  2614. ppszNameList = (TCHAR **) MemAlloc (sizeof (TCHAR *) * (cTotalNames + 1));
  2615. if (ppszNameList == NULL)
  2616. {
  2617. MemFree (pszFilter);
  2618. MemFree (pszAnyAttrNameList);
  2619. hr = ILS_E_MEMORY;
  2620. goto MyExit;
  2621. }
  2622. }
  2623. // Set standard attribute names
  2624. //
  2625. ULONG i;
  2626. for (i = 0; i < COUNT_ENUM_RES_CLIENT_INFO; i++)
  2627. {
  2628. ppszNameList[i] = (TCHAR *) c_apszClientStdAttrNames[i];
  2629. }
  2630. // Set arbitrary attribute names if needed
  2631. //
  2632. TCHAR *psz;
  2633. psz = pszAnyAttrNameList;
  2634. for (i = COUNT_ENUM_RES_CLIENT_INFO; i < cTotalNames; i++)
  2635. {
  2636. ppszNameList[i] = psz;
  2637. psz += lstrlen (psz) + 1;
  2638. }
  2639. // Terminate the list
  2640. //
  2641. ppszNameList[cTotalNames] = NULL;
  2642. // Get the session object
  2643. //
  2644. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  2645. if (hr == S_OK)
  2646. {
  2647. // Get an ldap session
  2648. //
  2649. MyAssert (pSession != NULL);
  2650. ld = pSession->GetLd ();
  2651. MyAssert (ld != NULL);
  2652. // Update options in ld
  2653. //
  2654. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  2655. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  2656. ld->ld_deref = LDAP_DEREF_ALWAYS;
  2657. // Send the search query
  2658. //
  2659. uMsgID = ldap_search ( ld,
  2660. (TCHAR *) &c_szDefClientBaseDN[0], // base DN
  2661. LDAP_SCOPE_BASE, // scope
  2662. pszFilter, // filter
  2663. ppszNameList, // attrs[]
  2664. 0); // both type and value
  2665. if (uMsgID == -1)
  2666. {
  2667. // This ldap_search failed.
  2668. // Convert ldap error code to hr
  2669. //
  2670. hr = ::LdapError2Hresult (ld->ld_errno);
  2671. MyAssert (hr != S_OK);
  2672. // Free the session object
  2673. //
  2674. pSession->Disconnect ();
  2675. }
  2676. }
  2677. // Free the filter string
  2678. //
  2679. MemFree (pszFilter);
  2680. // Free the buffer holding all returned attribute names if needed
  2681. //
  2682. if (ppszNameList != &apszAttrNames[0])
  2683. MemFree (ppszNameList);
  2684. // If failed, exit with cleanup
  2685. //
  2686. if (hr != S_OK)
  2687. {
  2688. // Free extended attribute names list if needed
  2689. //
  2690. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  2691. MemFree (pszAnyAttrNameList);
  2692. // Report failure
  2693. //
  2694. goto MyExit;
  2695. }
  2696. // Construct a pending info structure
  2697. //
  2698. RESP_INFO ri;
  2699. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  2700. ri.uNotifyMsg = WM_ILS_RESOLVE_CLIENT;
  2701. ri.cAnyAttrs = cAnyAttrNames;
  2702. ri.pszAnyAttrNameList = pszAnyAttrNameList;
  2703. // Queue this pending response
  2704. //
  2705. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  2706. if (hr != S_OK)
  2707. {
  2708. // Abort the ldap_search
  2709. //
  2710. ldap_abandon (ld, uMsgID);
  2711. // Free the session object
  2712. //
  2713. pSession->Disconnect ();
  2714. MyAssert (FALSE);
  2715. }
  2716. MyExit:
  2717. LDAP_CLIENTINFO_RES *pcir = NULL;
  2718. if (hr != S_OK)
  2719. {
  2720. pcir = (LDAP_CLIENTINFO_RES *) MemAlloc (sizeof (LDAP_CLIENTINFO_RES));
  2721. if (pcir != NULL)
  2722. {
  2723. pcir->uSize = sizeof (*pcir);
  2724. pcir->hResult = hr;
  2725. }
  2726. }
  2727. return (LPARAM) pcir;
  2728. }
  2729. /* ----------------------------------------------------------------------
  2730. UlsLdap_ResolveProtocol
  2731. History:
  2732. 10/15/96 Chu, Lon-Chan [lonchanc]
  2733. Created.
  2734. 10/30/96 Chu, Lon-Chan [lonchanc]
  2735. Blocked by ILS (7438, 7442)
  2736. ---------------------------------------------------------------------- */
  2737. HRESULT UlsLdap_ResolveProtocol (
  2738. SERVER_INFO *pServer,
  2739. TCHAR *pszUserName,
  2740. TCHAR *pszAppName,
  2741. TCHAR *pszProtName,
  2742. TCHAR *pszAnyAttrNameList,
  2743. ULONG cAnyAttrNames,
  2744. LDAP_ASYNCINFO *pAsyncInfo )
  2745. {
  2746. HRESULT hr;
  2747. // Make sure this service provider is initialized
  2748. //
  2749. if (g_cInitialized <= 0)
  2750. return ILS_E_NOT_INITIALIZED;
  2751. if (MyIsBadServerInfo (pServer) || MyIsBadString (pszUserName) ||
  2752. MyIsBadString (pszAppName) || MyIsBadString (pszProtName) ||
  2753. pAsyncInfo == NULL)
  2754. return ILS_E_POINTER;
  2755. // Make sure the async info structure is valid
  2756. //
  2757. if (pAsyncInfo == NULL)
  2758. return ILS_E_POINTER;
  2759. // Compute the total size of the data
  2760. //
  2761. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  2762. ULONG cbSizeUserName = (lstrlen (pszUserName) + 1) * sizeof (TCHAR);
  2763. ULONG cbSizeAppName = (lstrlen (pszAppName) + 1) * sizeof (TCHAR);
  2764. ULONG cbSizeProtName = (lstrlen (pszProtName) + 1) * sizeof (TCHAR);
  2765. ULONG cbSizeAnyAttrNames = 0;
  2766. TCHAR *psz = pszAnyAttrNameList;
  2767. ULONG cch;
  2768. for (ULONG i = 0; i < cAnyAttrNames; i++)
  2769. {
  2770. cch = lstrlen (psz) + 1;
  2771. cbSizeAnyAttrNames += cch * sizeof (TCHAR);
  2772. psz += cch;
  2773. }
  2774. ULONG cParams = 6;
  2775. ULONG cbSize = cbServer + cbSizeUserName + cbSizeAppName +
  2776. cbSizeProtName + cbSizeAnyAttrNames;
  2777. // Allocate marshall request buffer
  2778. //
  2779. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_RESOLVE_PROTOCOL, cbSize, cParams);
  2780. if (pReq == NULL)
  2781. return ILS_E_MEMORY;
  2782. // Get the response ID
  2783. //
  2784. ULONG uRespID = pReq->uRespID;
  2785. // Linearize parameters
  2786. //
  2787. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  2788. MarshalReq_SetParam (pReq, 1, (DWORD_PTR) pszUserName, cbSizeUserName);
  2789. MarshalReq_SetParam (pReq, 2, (DWORD_PTR) pszAppName, cbSizeAppName);
  2790. MarshalReq_SetParam (pReq, 3, (DWORD_PTR) pszProtName, cbSizeProtName);
  2791. MarshalReq_SetParam (pReq, 4, (DWORD_PTR) pszAnyAttrNameList, cbSizeAnyAttrNames);
  2792. MarshalReq_SetParam (pReq, 5, (DWORD) cAnyAttrNames, 0);
  2793. // Enter the request
  2794. //
  2795. if (g_pReqQueue != NULL)
  2796. {
  2797. hr = g_pReqQueue->Enter (pReq);
  2798. }
  2799. else
  2800. {
  2801. MyAssert (FALSE);
  2802. hr = ILS_E_FAIL;
  2803. }
  2804. if (hr == S_OK)
  2805. {
  2806. pAsyncInfo->uMsgID = uRespID;
  2807. }
  2808. else
  2809. {
  2810. MemFree (pReq);
  2811. }
  2812. return hr;
  2813. }
  2814. LPARAM
  2815. AsynReq_ResolveProtocol ( MARSHAL_REQ *pReq )
  2816. {
  2817. HRESULT hr = S_OK;
  2818. SP_CSession *pSession = NULL;
  2819. LDAP *ld;
  2820. ULONG uMsgID = (ULONG) -1;
  2821. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  2822. MyAssert (pReq != NULL);
  2823. MyAssert (pReq->uNotifyMsg == WM_ILS_RESOLVE_PROTOCOL);
  2824. // Delinearize parameters
  2825. //
  2826. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  2827. TCHAR *pszUserName = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  2828. TCHAR *pszAppName = (TCHAR *) MarshalReq_GetParam (pReq, 2);
  2829. TCHAR *pszProtName = (TCHAR *) MarshalReq_GetParam (pReq, 3);
  2830. TCHAR *pszAnyAttrNameList = (TCHAR *) MarshalReq_GetParam (pReq, 4);
  2831. ULONG cAnyAttrNames = (ULONG) MarshalReq_GetParam (pReq, 5);
  2832. TCHAR *pszFilter = NULL;
  2833. // Duplicate the protocol name to resolve
  2834. //
  2835. TCHAR *pszProtNameToResolve = My_strdup (pszProtName);
  2836. if (pszProtNameToResolve == NULL)
  2837. {
  2838. hr = ILS_E_MEMORY;
  2839. goto MyExit;
  2840. }
  2841. // Create a resolve client filter
  2842. //
  2843. pszFilter = ProtCreateResolveFilter (pszUserName, pszAppName, pszProtName);
  2844. if (pszFilter == NULL)
  2845. {
  2846. MemFree (pszProtNameToResolve);
  2847. hr = ILS_E_MEMORY;
  2848. goto MyExit;
  2849. }
  2850. // Create an array of names of attributes to return
  2851. //
  2852. TCHAR *apszAttrNames[COUNT_ENUM_PROTATTR+1];
  2853. TCHAR **ppszNameList;
  2854. ppszNameList = &apszAttrNames[0];
  2855. ULONG cTotalNames;
  2856. cTotalNames = COUNT_ENUM_PROTATTR;
  2857. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  2858. {
  2859. // Prefix arbitrary attribute names
  2860. //
  2861. pszAnyAttrNameList = IlsPrefixNameValueArray (FALSE, cAnyAttrNames,
  2862. (const TCHAR *) pszAnyAttrNameList);
  2863. if (pszAnyAttrNameList == NULL)
  2864. {
  2865. MemFree (pszProtNameToResolve);
  2866. MemFree (pszFilter);
  2867. hr = ILS_E_MEMORY;
  2868. goto MyExit;
  2869. }
  2870. // Allocate memory for returned attributes' names
  2871. //
  2872. cTotalNames += cAnyAttrNames;
  2873. ppszNameList = (TCHAR **) MemAlloc (sizeof (TCHAR *) * (cTotalNames + 1));
  2874. if (ppszNameList == NULL)
  2875. {
  2876. MemFree (pszProtNameToResolve);
  2877. MemFree (pszFilter);
  2878. MemFree (pszAnyAttrNameList);
  2879. hr = ILS_E_MEMORY;
  2880. goto MyExit;
  2881. }
  2882. }
  2883. // Set standard attribute names
  2884. //
  2885. ULONG i;
  2886. for (i = 0; i < COUNT_ENUM_PROTATTR; i++)
  2887. {
  2888. ppszNameList[i] = (TCHAR *) c_apszProtStdAttrNames[i];
  2889. }
  2890. // Set arbitrary attribute names if needed
  2891. //
  2892. TCHAR *psz;
  2893. psz = pszAnyAttrNameList;
  2894. for (i = COUNT_ENUM_PROTATTR; i < cTotalNames; i++)
  2895. {
  2896. ppszNameList[i] = psz;
  2897. psz += lstrlen (psz) + 1;
  2898. }
  2899. // Terminate the list
  2900. //
  2901. ppszNameList[cTotalNames] = NULL;
  2902. // Get the session object
  2903. //
  2904. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  2905. if (hr == S_OK)
  2906. {
  2907. // Get an ldap session
  2908. //
  2909. MyAssert (pSession != NULL);
  2910. ld = pSession->GetLd ();
  2911. MyAssert (ld != NULL);
  2912. // Update options in ld
  2913. //
  2914. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  2915. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  2916. ld->ld_deref = LDAP_DEREF_ALWAYS;
  2917. // Send the search query
  2918. //
  2919. uMsgID = ldap_search (ld, (TCHAR *) &c_szDefClientBaseDN[0], // base DN
  2920. LDAP_SCOPE_BASE, // scope
  2921. pszFilter,
  2922. ppszNameList, // attrs[]
  2923. 0); // both type and value
  2924. if (uMsgID == -1)
  2925. {
  2926. // This ldap_search failed.
  2927. // Convert ldap error code to hr
  2928. //
  2929. hr = ::LdapError2Hresult (ld->ld_errno);
  2930. MyAssert (hr != S_OK);
  2931. // Free the session object
  2932. //
  2933. pSession->Disconnect ();
  2934. }
  2935. }
  2936. // Free the filter string
  2937. //
  2938. MemFree (pszFilter);
  2939. // Free the buffer holding all returned attribute names if needed
  2940. //
  2941. if (ppszNameList != &apszAttrNames[0])
  2942. MemFree (ppszNameList);
  2943. // If failed, exit with cleanup
  2944. //
  2945. if (hr != S_OK)
  2946. {
  2947. // Free duplicated protocol name
  2948. //
  2949. MemFree (pszProtNameToResolve);
  2950. // Free extended attribute names list if needed
  2951. //
  2952. if (cAnyAttrNames != 0)
  2953. MemFree (pszAnyAttrNameList);
  2954. // Report failure
  2955. //
  2956. goto MyExit;
  2957. }
  2958. // Construct a pending info structure
  2959. //
  2960. RESP_INFO ri;
  2961. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  2962. ri.uNotifyMsg = WM_ILS_RESOLVE_PROTOCOL;
  2963. ri.cAnyAttrs = cAnyAttrNames;
  2964. ri.pszAnyAttrNameList = pszAnyAttrNameList;
  2965. ri.pszProtNameToResolve = pszProtNameToResolve;
  2966. // Queue this pending response
  2967. //
  2968. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  2969. if (hr != S_OK)
  2970. {
  2971. // Free duplicated protocol name
  2972. //
  2973. MemFree (pszProtNameToResolve);
  2974. // Free extended attribute names list if needed
  2975. //
  2976. if (cAnyAttrNames != 0)
  2977. MemFree (pszAnyAttrNameList);
  2978. // Abort the ldap_search
  2979. //
  2980. ldap_abandon (ld, uMsgID);
  2981. // Free the session object
  2982. //
  2983. pSession->Disconnect ();
  2984. MyAssert (FALSE);
  2985. }
  2986. MyExit:
  2987. LDAP_PROTINFO_RES *ppir = NULL;
  2988. if (hr != S_OK)
  2989. {
  2990. ppir = (LDAP_PROTINFO_RES *) MemAlloc (sizeof (LDAP_PROTINFO_RES));
  2991. if (ppir != NULL)
  2992. {
  2993. ppir->uSize = sizeof (*ppir);
  2994. ppir->hResult = hr;
  2995. }
  2996. }
  2997. return (LPARAM) ppir;
  2998. }
  2999. /* ----------------------------------------------------------------------
  3000. UlsLdap_ResolveMeeting
  3001. Input:
  3002. pszServer: A server name.
  3003. pszMeetingID: A meeting id string.
  3004. pszAnyAttrName: A pointer to a series of strings.
  3005. cAnyAttrNames: A count of strings in the series.
  3006. pAsyncInfo: a pointer to async info structure.
  3007. History:
  3008. 12/02/96 Chu, Lon-Chan [lonchanc]
  3009. Created.
  3010. ---------------------------------------------------------------------- */
  3011. #ifdef ENABLE_MEETING_PLACE
  3012. HRESULT UlsLdap_ResolveMeeting (
  3013. SERVER_INFO *pServer,
  3014. TCHAR *pszMtgName,
  3015. TCHAR *pszAnyAttrNameList,
  3016. ULONG cAnyAttrNames,
  3017. LDAP_ASYNCINFO *pAsyncInfo )
  3018. {
  3019. HRESULT hr;
  3020. // Make sure this service provider is initialized
  3021. //
  3022. if (g_cInitialized <= 0)
  3023. return ILS_E_NOT_INITIALIZED;
  3024. if (MyIsBadServerInfo (pServer) || MyIsBadString (pszMtgName))
  3025. return ILS_E_POINTER;
  3026. // Make sure the async info structure is valid
  3027. //
  3028. if (pAsyncInfo == NULL)
  3029. return ILS_E_POINTER;
  3030. // Compute the total size of the data
  3031. //
  3032. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  3033. ULONG cbSizeMtgName = (lstrlen (pszMtgName) + 1) * sizeof (TCHAR);
  3034. ULONG cbSizeAnyAttrNames = 0;
  3035. TCHAR *psz = pszAnyAttrNameList;
  3036. ULONG cch;
  3037. for (ULONG i = 0; i < cAnyAttrNames; i++)
  3038. {
  3039. cch = lstrlen (psz) + 1;
  3040. cbSizeAnyAttrNames += cch * sizeof (TCHAR);
  3041. psz += cch;
  3042. }
  3043. ULONG cParams = 4;
  3044. ULONG cbSize = cbServer + cbSizeMtgName + cbSizeAnyAttrNames;
  3045. // Allocate marshall request buffer
  3046. //
  3047. MARSHAL_REQ *pReq = MarshalReq_Alloc (WM_ILS_RESOLVE_MEETING, cbSize, cParams);
  3048. if (pReq == NULL)
  3049. return ILS_E_MEMORY;
  3050. // Get the response ID
  3051. //
  3052. ULONG uRespID = pReq->uRespID;
  3053. // Linearize parameters
  3054. //
  3055. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  3056. MarshalReq_SetParam (pReq, 1, (DWORD) pszMtgName, cbSizeMtgName);
  3057. MarshalReq_SetParam (pReq, 2, (DWORD) pszAnyAttrNameList, cbSizeAnyAttrNames);
  3058. MarshalReq_SetParam (pReq, 3, (DWORD) cAnyAttrNames, 0);
  3059. // Enter the request
  3060. //
  3061. if (g_pReqQueue != NULL)
  3062. {
  3063. hr = g_pReqQueue->Enter (pReq);
  3064. }
  3065. else
  3066. {
  3067. MyAssert (FALSE);
  3068. hr = ILS_E_FAIL;
  3069. }
  3070. if (hr == S_OK)
  3071. {
  3072. pAsyncInfo->uMsgID = uRespID;
  3073. }
  3074. else
  3075. {
  3076. MemFree (pReq);
  3077. }
  3078. return hr;
  3079. }
  3080. LPARAM
  3081. AsynReq_ResolveMeeting ( MARSHAL_REQ *pReq )
  3082. {
  3083. HRESULT hr = S_OK;
  3084. SP_CSession *pSession = NULL;
  3085. LDAP *ld;
  3086. ULONG uMsgID = (ULONG) -1;
  3087. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  3088. MyAssert (pReq != NULL);
  3089. MyAssert (pReq->uNotifyMsg == WM_ILS_RESOLVE_MEETING);
  3090. // Delinearize parameters
  3091. //
  3092. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  3093. TCHAR *pszMtgName = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  3094. TCHAR *pszAnyAttrNameList = (TCHAR *) MarshalReq_GetParam (pReq, 2);
  3095. ULONG cAnyAttrNames = (ULONG) MarshalReq_GetParam (pReq, 3);
  3096. // Create a resolve client filter
  3097. //
  3098. TCHAR *pszFilter = MtgCreateResolveFilter (pszMtgName);
  3099. if (pszFilter == NULL)
  3100. {
  3101. hr = ILS_E_MEMORY;
  3102. goto MyExit;
  3103. }
  3104. // Create an array of names of attributes to return
  3105. //
  3106. TCHAR *apszAttrNames[COUNT_ENUM_MTGATTR+1];
  3107. TCHAR **ppszNameList;
  3108. ppszNameList = &apszAttrNames[0];
  3109. ULONG cTotalNames;
  3110. cTotalNames = COUNT_ENUM_MTGATTR;
  3111. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  3112. {
  3113. // Prefix arbitrary attribute names
  3114. //
  3115. pszAnyAttrNameList = IlsPrefixNameValueArray (FALSE, cAnyAttrNames,
  3116. (const TCHAR *) pszAnyAttrNameList);
  3117. if (pszAnyAttrNameList == NULL)
  3118. {
  3119. MemFree (pszFilter);
  3120. hr = ILS_E_MEMORY;
  3121. goto MyExit;
  3122. }
  3123. // Allocate memory for returned attributes' names
  3124. //
  3125. cTotalNames += cAnyAttrNames;
  3126. ppszNameList = (TCHAR **) MemAlloc (sizeof (TCHAR *) * (cTotalNames + 1));
  3127. if (ppszNameList == NULL)
  3128. {
  3129. MemFree (pszFilter);
  3130. MemFree (pszAnyAttrNameList);
  3131. hr = ILS_E_MEMORY;
  3132. goto MyExit;
  3133. }
  3134. }
  3135. // Set standard attribute names
  3136. //
  3137. ULONG i;
  3138. for (i = 0; i < COUNT_ENUM_MTGATTR; i++)
  3139. {
  3140. ppszNameList[i] = (TCHAR *) c_apszMtgStdAttrNames[i];
  3141. }
  3142. // Set arbitrary attribute names if needed
  3143. //
  3144. TCHAR *psz;
  3145. psz = pszAnyAttrNameList;
  3146. for (i = COUNT_ENUM_MTGATTR; i < cTotalNames; i++)
  3147. {
  3148. ppszNameList[i] = psz;
  3149. psz += lstrlen (psz) + 1;
  3150. }
  3151. // Terminate the list
  3152. //
  3153. ppszNameList[cTotalNames] = NULL;
  3154. // Get the session object
  3155. //
  3156. hr = g_pSessionContainer->GetSession (&pSession, pServer);
  3157. if (hr == S_OK)
  3158. {
  3159. // Get an ldap session
  3160. //
  3161. MyAssert (pSession != NULL);
  3162. ld = pSession->GetLd ();
  3163. MyAssert (ld != NULL);
  3164. // Update options in ld
  3165. //
  3166. ld->ld_sizelimit = 0; // no limit in the num of entries to return
  3167. ld->ld_timelimit = 0; // no limit on the time to spend on the search
  3168. ld->ld_deref = LDAP_DEREF_ALWAYS;
  3169. // Send the search query
  3170. //
  3171. uMsgID = ldap_search (ld, (TCHAR *) &c_szDefMtgBaseDN[0], // base DN
  3172. LDAP_SCOPE_BASE, // scope
  3173. pszFilter,
  3174. ppszNameList, // attrs[]
  3175. 0); // both type and value
  3176. if (uMsgID == -1)
  3177. {
  3178. // This ldap_search failed.
  3179. // Convert ldap error code to hr
  3180. //
  3181. hr = ::LdapError2Hresult (ld->ld_errno);
  3182. MyAssert (hr != S_OK);
  3183. // Free the session object
  3184. //
  3185. pSession->Disconnect ();
  3186. }
  3187. }
  3188. // Free the filter string
  3189. //
  3190. MemFree (pszFilter);
  3191. // Free the buffer holding all returned attribute names if needed
  3192. //
  3193. if (ppszNameList != &apszAttrNames[0])
  3194. MemFree (ppszNameList);
  3195. // If failed, exit with cleanup
  3196. //
  3197. if (hr != S_OK)
  3198. {
  3199. // Free extended attribute names list if needed
  3200. //
  3201. if (pszAnyAttrNameList != NULL && cAnyAttrNames != 0)
  3202. MemFree (pszAnyAttrNameList);
  3203. // Report failure
  3204. //
  3205. goto MyExit;
  3206. }
  3207. // Construct a pending info structure
  3208. //
  3209. RESP_INFO ri;
  3210. FillDefRespInfo (&ri, pReq->uRespID, ld, uMsgID, INVALID_MSG_ID);
  3211. ri.uNotifyMsg = WM_ILS_RESOLVE_MEETING;
  3212. ri.cAnyAttrs = cAnyAttrNames;
  3213. ri.pszAnyAttrNameList = pszAnyAttrNameList;
  3214. // Queue this pending response
  3215. //
  3216. hr = g_pRespQueue->EnterRequest (pSession, &ri);
  3217. if (hr != S_OK)
  3218. {
  3219. // Abort the ldap_search
  3220. //
  3221. ldap_abandon (ld, uMsgID);
  3222. // Free the session object
  3223. //
  3224. pSession->Disconnect ();
  3225. MyAssert (FALSE);
  3226. }
  3227. MyExit:
  3228. LDAP_MEETINFO_RES *pmir = NULL;
  3229. if (hr != S_OK)
  3230. {
  3231. pmir = (LDAP_MEETINFO_RES *) MemAlloc (sizeof (LDAP_MEETINFO_RES));
  3232. if (pmir != NULL)
  3233. {
  3234. pmir->uSize = sizeof (*pmir);
  3235. pmir->hResult = hr;
  3236. }
  3237. }
  3238. return (LPARAM) pmir;
  3239. }
  3240. #endif // ENABLE_MEETING_PLACE
  3241. /* ----------------------------------------------------------------------
  3242. UlsLdap_AddAttendee
  3243. Input:
  3244. pszServer: server name.
  3245. pszMeetingID: a meeting id string.
  3246. pszAttendeeID: an attendee id string.
  3247. pAsyncInfo: a pointer to async info structure.
  3248. History:
  3249. 12/02/96 Chu, Lon-Chan [lonchanc]
  3250. Created.
  3251. ---------------------------------------------------------------------- */
  3252. #ifdef ENABLE_MEETING_PLACE
  3253. HRESULT My_UpdateAttendees (
  3254. ULONG uNotifyMsg,
  3255. SERVER_INFO *pServer,
  3256. TCHAR *pszMtgName,
  3257. ULONG cMembers,
  3258. TCHAR *pszMemberNames,
  3259. LDAP_ASYNCINFO *pAsyncInfo )
  3260. {
  3261. HRESULT hr;
  3262. MyAssert ( uNotifyMsg == WM_ILS_ADD_ATTENDEE ||
  3263. uNotifyMsg == WM_ILS_REMOVE_ATTENDEE);
  3264. // Make sure this service provider is initialized
  3265. //
  3266. if (g_cInitialized <= 0)
  3267. return ILS_E_NOT_INITIALIZED;
  3268. // Make sure we there are members to add
  3269. //
  3270. if (cMembers == 0)
  3271. return ILS_E_PARAMETER;
  3272. // Make sure we have valid pointers
  3273. //
  3274. if (MyIsBadServerInfo (pServer) || MyIsBadString (pszMtgName) ||
  3275. MyIsBadString (pszMemberNames))
  3276. return ILS_E_POINTER;
  3277. // Make sure the async info structure is valid
  3278. //
  3279. if (pAsyncInfo == NULL)
  3280. return ILS_E_POINTER;
  3281. // Compute the total size of the data
  3282. //
  3283. ULONG cbServer = IlsGetLinearServerInfoSize (pServer);
  3284. ULONG cbSizeMtgName = (lstrlen (pszMtgName) + 1) * sizeof (TCHAR);
  3285. ULONG cbSizeMemberNames = 0;
  3286. TCHAR *psz = pszMemberNames;
  3287. for (ULONG i = 0; i < cMembers; i++)
  3288. {
  3289. ULONG cchName = lstrlen (psz) + 1;
  3290. cbSizeMemberNames += cchName * sizeof (TCHAR);
  3291. psz += cchName;
  3292. }
  3293. ULONG cParams = 4;
  3294. ULONG cbSize = cbServer + cbSizeMtgName + cbSizeMemberNames;
  3295. // Allocate marshall request buffer
  3296. //
  3297. MARSHAL_REQ *pReq = MarshalReq_Alloc (uNotifyMsg, cbSize, cParams);
  3298. if (pReq == NULL)
  3299. return ILS_E_MEMORY;
  3300. // Get the response ID
  3301. //
  3302. ULONG uRespID = pReq->uRespID;
  3303. // Linearize parameters
  3304. //
  3305. MarshalReq_SetParamServer (pReq, 0, pServer, cbServer);
  3306. MarshalReq_SetParam (pReq, 1, (DWORD) pszMtgName, cbSizeMtgName);
  3307. MarshalReq_SetParam (pReq, 2, (DWORD) cMembers, 0);
  3308. MarshalReq_SetParam (pReq, 3, (DWORD) pszMemberNames, cbSizeMemberNames);
  3309. // Enter the request
  3310. //
  3311. if (g_pReqQueue != NULL)
  3312. {
  3313. hr = g_pReqQueue->Enter (pReq);
  3314. }
  3315. else
  3316. {
  3317. MyAssert (FALSE);
  3318. hr = ILS_E_FAIL;
  3319. }
  3320. if (hr == S_OK)
  3321. {
  3322. pAsyncInfo->uMsgID = uRespID;
  3323. }
  3324. else
  3325. {
  3326. MemFree (pReq);
  3327. }
  3328. return hr;
  3329. }
  3330. LPARAM
  3331. AsynReq_UpdateAttendees ( MARSHAL_REQ *pReq )
  3332. {
  3333. MyAssert (GetCurrentThreadId () == g_dwReqThreadID);
  3334. MyAssert (pReq != NULL);
  3335. MyAssert ( pReq->uNotifyMsg == WM_ILS_ADD_ATTENDEE ||
  3336. pReq->uNotifyMsg == WM_ILS_REMOVE_ATTENDEE);
  3337. // Delinearize parameters
  3338. //
  3339. SERVER_INFO *pServer = (SERVER_INFO *) MarshalReq_GetParam (pReq, 0);
  3340. TCHAR *pszMtgName = (TCHAR *) MarshalReq_GetParam (pReq, 1);
  3341. ULONG cMembers = (ULONG) MarshalReq_GetParam (pReq, 2);
  3342. TCHAR *pszMemberNames = (TCHAR *) MarshalReq_GetParam (pReq, 3);
  3343. // Set standard attributes
  3344. //
  3345. return (LPARAM) MtgUpdateMembers (pReq->uNotifyMsg,
  3346. pServer,
  3347. pszMtgName,
  3348. cMembers,
  3349. pszMemberNames,
  3350. pReq->uRespID);
  3351. }
  3352. #endif // ENABLE_MEETING_PLACE
  3353. #ifdef ENABLE_MEETING_PLACE
  3354. HRESULT UlsLdap_AddAttendee(
  3355. SERVER_INFO *pServer,
  3356. TCHAR *pszMtgName,
  3357. ULONG cMembers,
  3358. TCHAR *pszMemberNames,
  3359. LDAP_ASYNCINFO *pAsyncInfo )
  3360. {
  3361. return My_UpdateAttendees ( WM_ILS_ADD_ATTENDEE,
  3362. pServer,
  3363. pszMtgName,
  3364. cMembers,
  3365. pszMemberNames,
  3366. pAsyncInfo);
  3367. }
  3368. #endif // ENABLE_MEETING_PLACE
  3369. /* ----------------------------------------------------------------------
  3370. UlsLdap_RemoveAttendee
  3371. Input:
  3372. pszServer: server name.
  3373. pszMeetingID: a meeting id string.
  3374. pszAttendeeID: an attendee id string.
  3375. pAsyncInfo: a pointer to async info structure.
  3376. History:
  3377. 12/02/96 Chu, Lon-Chan [lonchanc]
  3378. Created.
  3379. ---------------------------------------------------------------------- */
  3380. #ifdef ENABLE_MEETING_PLACE
  3381. HRESULT UlsLdap_RemoveAttendee(
  3382. SERVER_INFO *pServer,
  3383. TCHAR *pszMtgName,
  3384. ULONG cMembers,
  3385. TCHAR *pszMemberNames,
  3386. LDAP_ASYNCINFO *pAsyncInfo )
  3387. {
  3388. return My_UpdateAttendees ( WM_ILS_REMOVE_ATTENDEE,
  3389. pServer,
  3390. pszMtgName,
  3391. cMembers,
  3392. pszMemberNames,
  3393. pAsyncInfo);
  3394. }
  3395. #endif // ENABLE_MEETING_PLACE
  3396. /* ----------------------------------------------------------------------
  3397. UlsLdap_GetStdAttrNameString
  3398. Input:
  3399. StdName: a standard attribute index.
  3400. History:
  3401. 12/02/96 Chu, Lon-Chan [lonchanc]
  3402. Created.
  3403. ---------------------------------------------------------------------- */
  3404. typedef struct
  3405. {
  3406. #ifdef DEBUG
  3407. LONG nIndex;
  3408. #endif
  3409. const TCHAR **ppszName;
  3410. }
  3411. ATTR_NAME_ENTRY;
  3412. const ATTR_NAME_ENTRY c_aAttrNameTbl[ILS_NUM_OF_STDATTRS] =
  3413. {
  3414. {
  3415. #ifdef DEBUG
  3416. (LONG) ILS_STDATTR_NULL,
  3417. #endif
  3418. NULL
  3419. },
  3420. // User standard attribute names
  3421. //
  3422. {
  3423. #ifdef DEBUG
  3424. (LONG) ILS_STDATTR_USER_ID,
  3425. #endif
  3426. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_CN]
  3427. },
  3428. {
  3429. #ifdef DEBUG
  3430. (LONG) ILS_STDATTR_IP_ADDRESS,
  3431. #endif
  3432. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_IP_ADDRESS]
  3433. },
  3434. {
  3435. #ifdef DEBUG
  3436. (LONG) ILS_STDATTR_EMAIL_NAME,
  3437. #endif
  3438. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_EMAIL_NAME]
  3439. },
  3440. {
  3441. #ifdef DEBUG
  3442. (LONG) ILS_STDATTR_FIRST_NAME,
  3443. #endif
  3444. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_FIRST_NAME]
  3445. },
  3446. {
  3447. #ifdef DEBUG
  3448. (LONG) ILS_STDATTR_LAST_NAME,
  3449. #endif
  3450. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_LAST_NAME]
  3451. },
  3452. {
  3453. #ifdef DEBUG
  3454. (LONG) ILS_STDATTR_CITY_NAME,
  3455. #endif
  3456. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_CITY_NAME]
  3457. },
  3458. {
  3459. #ifdef DEBUG
  3460. (LONG) ILS_STDATTR_COUNTRY_NAME,
  3461. #endif
  3462. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_C]
  3463. },
  3464. {
  3465. #ifdef DEBUG
  3466. (LONG) ILS_STDATTR_COMMENT,
  3467. #endif
  3468. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_COMMENT]
  3469. },
  3470. {
  3471. #ifdef DEBUG
  3472. (LONG) ILS_STDATTR_FLAGS,
  3473. #endif
  3474. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_FLAGS]
  3475. },
  3476. // Application standard attribute names
  3477. //
  3478. {
  3479. #ifdef DEBUG
  3480. (LONG) ILS_STDATTR_APP_NAME,
  3481. #endif
  3482. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_APP_NAME]
  3483. },
  3484. {
  3485. #ifdef DEBUG
  3486. (LONG) ILS_STDATTR_APP_MIME_TYPE,
  3487. #endif
  3488. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_APP_MIME_TYPE]
  3489. },
  3490. {
  3491. #ifdef DEBUG
  3492. (LONG) ILS_STDATTR_APP_GUID,
  3493. #endif
  3494. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_APP_GUID]
  3495. },
  3496. // Protocol standard attribute names
  3497. //
  3498. {
  3499. #ifdef DEBUG
  3500. (LONG) ILS_STDATTR_PROTOCOL_NAME,
  3501. #endif
  3502. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_PROT_NAME]
  3503. },
  3504. {
  3505. #ifdef DEBUG
  3506. (LONG) ILS_STDATTR_PROTOCOL_MIME_TYPE,
  3507. #endif
  3508. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_PROT_MIME]
  3509. },
  3510. {
  3511. #ifdef DEBUG
  3512. (LONG) ILS_STDATTR_PROTOCOL_PORT,
  3513. #endif
  3514. &c_apszClientStdAttrNames[ENUM_CLIENTATTR_PROT_PORT]
  3515. },
  3516. #ifdef ENABLE_MEETING_PLACE
  3517. // Meeting place attribute names
  3518. //
  3519. {
  3520. #ifdef DEBUG
  3521. (LONG) ILS_STDATTR_MEETING_ID,
  3522. #endif
  3523. &c_apszMtgStdAttrNames[ENUM_MTGATTR_CN]
  3524. },
  3525. {
  3526. #ifdef DEBUG
  3527. (LONG) ILS_STDATTR_MEETING_HOST_NAME,
  3528. #endif
  3529. &c_apszMtgStdAttrNames[ENUM_MTGATTR_HOST_NAME]
  3530. },
  3531. {
  3532. #ifdef DEBUG
  3533. (LONG) ILS_STDATTR_MEETING_HOST_IP_ADDRESS,
  3534. #endif
  3535. &c_apszMtgStdAttrNames[ENUM_MTGATTR_IP_ADDRESS]
  3536. },
  3537. {
  3538. #ifdef DEBUG
  3539. (LONG) ILS_STDATTR_MEETING_DESCRIPTION,
  3540. #endif
  3541. &c_apszMtgStdAttrNames[ENUM_MTGATTR_DESCRIPTION]
  3542. },
  3543. {
  3544. #ifdef DEBUG
  3545. (LONG) ILS_STDATTR_MEETING_TYPE,
  3546. #endif
  3547. &c_apszMtgStdAttrNames[ENUM_MTGATTR_MTG_TYPE]
  3548. },
  3549. {
  3550. #ifdef DEBUG
  3551. (LONG) ILS_STDATTR_ATTENDEE_TYPE,
  3552. #endif
  3553. &c_apszMtgStdAttrNames[ENUM_MTGATTR_MEMBER_TYPE]
  3554. },
  3555. #endif // ENABLE_MEETING_PLACE
  3556. };
  3557. const TCHAR *UlsLdap_GetStdAttrNameString ( ILS_STD_ATTR_NAME StdName )
  3558. {
  3559. ULONG nIndex = (LONG) StdName;
  3560. MyAssert (((LONG) ILS_STDATTR_NULL < nIndex) && (nIndex < (LONG) ILS_NUM_OF_STDATTRS));
  3561. return *(c_aAttrNameTbl[nIndex].ppszName);
  3562. }
  3563. #ifdef DEBUG
  3564. VOID DbgValidateStdAttrNameArray ( VOID )
  3565. {
  3566. MyAssert (ARRAY_ELEMENTS (c_aAttrNameTbl) == ILS_NUM_OF_STDATTRS);
  3567. for (LONG i = 0; i < ILS_NUM_OF_STDATTRS; i++)
  3568. {
  3569. if (i == c_aAttrNameTbl[i].nIndex)
  3570. {
  3571. if (i != ILS_STDATTR_NULL &&
  3572. My_lstrlen (*(c_aAttrNameTbl[i].ppszName)) == 0)
  3573. {
  3574. MyAssert (FALSE);
  3575. }
  3576. }
  3577. else
  3578. {
  3579. MyAssert (FALSE);
  3580. break;
  3581. }
  3582. }
  3583. }
  3584. #endif
  3585. /* =============== helper functions =============== */
  3586. const TCHAR g_szShowEntries[] = TEXT ("(cn=");
  3587. const INT g_nLengthShowEntries = ARRAY_ELEMENTS (g_szShowEntries) - 1;
  3588. const TCHAR g_szShowAllEntries[] = TEXT ("(cn=*)");
  3589. const INT g_nShowAllEntries = ARRAY_ELEMENTS (g_szShowAllEntries) - 1;
  3590. TCHAR *AddBaseToFilter ( TCHAR *pszFilter, const TCHAR *pszDefBase )
  3591. {
  3592. MyAssert (pszDefBase != NULL);
  3593. // Calculate the size for "(&(objectclass=RTPerson)())"
  3594. //
  3595. ULONG cbSize = (lstrlen (pszDefBase) + 8 + g_nShowAllEntries) * sizeof (TCHAR);
  3596. // Look through the filter string to figure out that
  3597. // will this string shows entries???
  3598. //
  3599. TCHAR *pszShowEntries = (TCHAR *) &g_szShowAllEntries[0];
  3600. if (pszFilter != NULL)
  3601. {
  3602. for (TCHAR *psz = pszFilter; *psz != TEXT ('\0'); psz = CharNext (psz))
  3603. {
  3604. if (lstrlen (psz) > g_nLengthShowEntries)
  3605. {
  3606. TCHAR ch = psz[g_nLengthShowEntries]; // remember
  3607. psz[g_nLengthShowEntries] = TEXT ('\0');
  3608. INT nCmp = lstrcmpi (psz, &g_szShowEntries[0]);
  3609. psz[g_nLengthShowEntries] = ch; // restore
  3610. if (nCmp == 0)
  3611. {
  3612. // Matched
  3613. //
  3614. pszShowEntries = STR_EMPTY;
  3615. break;
  3616. }
  3617. }
  3618. else
  3619. {
  3620. // It is impossible to match it
  3621. //
  3622. break;
  3623. }
  3624. }
  3625. }
  3626. // If the filter is null, then only provide "(objectclass=RTPerson)"
  3627. //
  3628. if (pszFilter != NULL)
  3629. cbSize += lstrlen (pszFilter) * sizeof (TCHAR);
  3630. // Allocate new memory for filter
  3631. //
  3632. TCHAR *pszNewFilter = (TCHAR *) MemAlloc (cbSize);
  3633. if (pszNewFilter != NULL)
  3634. {
  3635. wsprintf (pszNewFilter, TEXT ("(&(%s)%s"), pszDefBase, pszShowEntries);
  3636. TCHAR *psz = pszNewFilter + lstrlen (pszNewFilter);
  3637. if (pszFilter != NULL)
  3638. {
  3639. wsprintf (psz, (*pszFilter == TEXT ('(')) ? TEXT ("%s") : TEXT ("(%s)"),
  3640. pszFilter);
  3641. }
  3642. lstrcat (psz, TEXT (")"));
  3643. // Go through the filter and convert '*' to '%'
  3644. //
  3645. for (psz = pszNewFilter; *psz != TEXT ('\0'); psz = CharNext (psz))
  3646. {
  3647. if (*psz == TEXT ('*'))
  3648. *psz = TEXT ('%');
  3649. }
  3650. }
  3651. return pszNewFilter;
  3652. }
  3653.