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.

2246 lines
58 KiB

  1. //============================================================
  2. //
  3. // WBEMNetAPI32.cpp - implementation of NetAPI32.DLL access class
  4. //
  5. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  6. //
  7. //============================================================
  8. #include "precomp.h"
  9. #include <winerror.h>
  10. #include "WBEMNETAPI32.h"
  11. /*****************************************************************************
  12. *
  13. * FUNCTION : CNetAPI32::CNetAPI32
  14. *
  15. * DESCRIPTION : Constructor
  16. *
  17. * INPUTS : none
  18. *
  19. * OUTPUTS : none
  20. *
  21. * RETURNS : nothing
  22. *
  23. * COMMENTS :
  24. *
  25. *****************************************************************************/
  26. CNetAPI32::CNetAPI32()
  27. #ifdef NTONLY
  28. : m_pnetapi(NULL)
  29. #endif
  30. #ifdef WIN9XONLY
  31. : m_psvrapi(NULL)
  32. #endif
  33. {
  34. }
  35. /*****************************************************************************
  36. *
  37. * FUNCTION : CNetAPI32::~CNetAPI32
  38. *
  39. * DESCRIPTION : Destructor
  40. *
  41. * INPUTS : none
  42. *
  43. * OUTPUTS : none
  44. *
  45. * RETURNS : nothing
  46. *
  47. * COMMENTS :
  48. *
  49. *****************************************************************************/
  50. CNetAPI32::~CNetAPI32()
  51. {
  52. #ifdef NTONLY
  53. if(m_pnetapi != NULL)
  54. {
  55. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidNetApi32Api, m_pnetapi);
  56. }
  57. #endif
  58. #ifdef WIN9XONLY
  59. if(m_psvrapi != NULL)
  60. {
  61. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidSvrApiApi, m_psvrapi);
  62. }
  63. #endif
  64. }
  65. /*****************************************************************************
  66. *
  67. * FUNCTION : CNetAPI32::Init
  68. *
  69. * DESCRIPTION : Loads CSAPI.DLL, locates entry points
  70. *
  71. * INPUTS : none
  72. *
  73. * OUTPUTS : none
  74. *
  75. * RETURNS : ERROR_SUCCESS or windows error code
  76. *
  77. * COMMENTS :
  78. *
  79. *****************************************************************************/
  80. LONG CNetAPI32::Init()
  81. {
  82. LONG lRetCode = ERROR_SUCCESS;
  83. #ifdef WIN9XONLY
  84. m_psvrapi = (CSvrApiApi*) CResourceManager::sm_TheResourceManager.GetResource(g_guidSvrApiApi, NULL);
  85. if(m_psvrapi == NULL)
  86. {
  87. // Couldn't get one or more entry points
  88. //======================================
  89. lRetCode = ERROR_PROC_NOT_FOUND;
  90. }
  91. #endif
  92. #ifdef NTONLY
  93. m_pnetapi = (CNetApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidNetApi32Api, NULL);
  94. if(m_pnetapi == NULL)
  95. {
  96. // Couldn't get one or more entry points
  97. //======================================
  98. lRetCode = ERROR_PROC_NOT_FOUND;
  99. }
  100. #endif
  101. return lRetCode;
  102. }
  103. /*****************************************************************************
  104. *
  105. * SVRAPIAPI.DLL WRAPPERS
  106. *
  107. *****************************************************************************/
  108. #ifdef WIN9XONLY
  109. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareEnum95(char FAR *servername,
  110. short level,
  111. char FAR *bufptr,
  112. unsigned short prefmaxlen,
  113. unsigned short FAR *entriesread,
  114. unsigned short FAR *totalentries)
  115. {
  116. NET_API_STATUS ns = NERR_NetworkError;
  117. if(m_psvrapi != NULL)
  118. {
  119. ns = m_psvrapi->NetShareEnum(servername, level, bufptr, prefmaxlen,
  120. entriesread, totalentries);
  121. }
  122. return ns;
  123. }
  124. #endif
  125. #ifdef WIN9XONLY
  126. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareGetInfo95(char FAR *servername,
  127. char FAR *netname,
  128. short level,
  129. char FAR *bufptr,
  130. unsigned short buflen,
  131. unsigned short FAR *totalavail)
  132. {
  133. NET_API_STATUS ns = NERR_NetworkError;
  134. if(m_psvrapi != NULL)
  135. {
  136. ns = m_psvrapi->NetShareGetInfo(servername, netname, level,
  137. bufptr, buflen, totalavail);
  138. }
  139. return ns;
  140. }
  141. #endif
  142. #ifdef WIN9XONLY
  143. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareAdd95 (
  144. IN const char FAR * servername,
  145. IN short level,
  146. IN const char FAR * buf,
  147. unsigned short cbBuffer
  148. )
  149. {
  150. NET_API_STATUS ns = NERR_NetworkError;
  151. if(m_psvrapi != NULL)
  152. {
  153. ns = m_psvrapi->NetShareAdd(servername, level, buf , cbBuffer);
  154. }
  155. return ns;
  156. }
  157. #endif
  158. #ifdef WIN9XONLY
  159. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareSetInfo95 (
  160. IN const char FAR * servername,
  161. IN const char FAR * netname,
  162. IN short level,
  163. IN const char FAR* buf,
  164. IN unsigned short cbBuffer,
  165. IN short sParmNum
  166. )
  167. {
  168. NET_API_STATUS ns = NERR_NetworkError;
  169. if(m_psvrapi != NULL)
  170. {
  171. ns = m_psvrapi->NetShareSetInfo(servername, netname, level,
  172. buf, cbBuffer, sParmNum);
  173. }
  174. return ns;
  175. }
  176. #endif
  177. #ifdef WIN9XONLY
  178. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareDel95 (
  179. IN LPTSTR servername,
  180. IN LPTSTR netname,
  181. IN DWORD reserved
  182. )
  183. {
  184. NET_API_STATUS ns = NERR_NetworkError;
  185. if(m_psvrapi != NULL)
  186. {
  187. ns = m_psvrapi->NetShareDel(servername, netname, reserved);
  188. }
  189. return ns;
  190. }
  191. #endif
  192. #ifdef WIN9XONLY
  193. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetServerGetInfo95(char FAR *servername,
  194. short level,
  195. char FAR *bufptr,
  196. unsigned short buflen,
  197. unsigned short FAR *totalavail)
  198. {
  199. NET_API_STATUS ns = NERR_NetworkError;
  200. if(m_psvrapi != NULL)
  201. {
  202. ns = m_psvrapi->NetServerGetInfo(servername, level, bufptr, buflen,
  203. totalavail);
  204. }
  205. return ns;
  206. }
  207. #endif
  208. /*****************************************************************************
  209. *
  210. * NETAPI32API.DLL WRAPPERS
  211. *
  212. *****************************************************************************/
  213. #ifdef NTONLY
  214. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetGroupEnum(LPCWSTR servername,
  215. DWORD level,
  216. LPBYTE *bufptr,
  217. DWORD prefmaxlen,
  218. LPDWORD entriesread,
  219. LPDWORD totalentries,
  220. PDWORD_PTR resume_handle)
  221. {
  222. NET_API_STATUS ns = NERR_NetworkError;
  223. if(m_pnetapi != NULL)
  224. {
  225. ns = m_pnetapi->NetGroupEnum(servername, level, bufptr, prefmaxlen,
  226. entriesread, totalentries, resume_handle);
  227. }
  228. return ns;
  229. }
  230. #endif
  231. #ifdef NTONLY
  232. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetGroupGetInfo(LPCWSTR servername,
  233. LPCWSTR groupname,
  234. DWORD level,
  235. LPBYTE *bufptr)
  236. {
  237. NET_API_STATUS ns = NERR_NetworkError;
  238. if(m_pnetapi != NULL)
  239. {
  240. ns = m_pnetapi->NetGroupGetInfo(servername, groupname, level, bufptr);
  241. }
  242. return ns;
  243. }
  244. #endif
  245. #ifdef NTONLY
  246. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetGroupSetInfo(
  247. LPCWSTR servername,
  248. LPCWSTR groupname,
  249. DWORD level,
  250. LPBYTE buf,
  251. LPDWORD parm_err
  252. )
  253. {
  254. NET_API_STATUS ns = NERR_NetworkError;
  255. if(m_pnetapi != NULL)
  256. {
  257. ns = m_pnetapi->NetGroupSetInfo( servername, groupname, level, buf, parm_err) ;
  258. }
  259. return ns;
  260. }
  261. #endif
  262. #ifdef NTONLY
  263. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetLocalGroupGetInfo(LPCWSTR servername,
  264. LPCWSTR groupname,
  265. DWORD level,
  266. LPBYTE *bufptr)
  267. {
  268. NET_API_STATUS ns = NERR_NetworkError;
  269. if(m_pnetapi != NULL)
  270. {
  271. ns = m_pnetapi->NetLocalGroupGetInfo(servername, groupname, level,
  272. bufptr);
  273. }
  274. return ns;
  275. }
  276. #endif
  277. #ifdef NTONLY
  278. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetLocalGroupSetInfo(
  279. LPCWSTR a_servername,
  280. LPCWSTR a_groupname,
  281. DWORD a_level,
  282. LPBYTE a_buf,
  283. LPDWORD a_parm_err
  284. )
  285. {
  286. NET_API_STATUS ns = NERR_NetworkError;
  287. if(m_pnetapi != NULL)
  288. {
  289. ns = m_pnetapi->NetLocalGroupSetInfo( a_servername,
  290. a_groupname,
  291. a_level,
  292. a_buf,
  293. a_parm_err);
  294. }
  295. return ns;
  296. }
  297. #endif
  298. #ifdef NTONLY
  299. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetGroupGetUsers(LPCWSTR servername,
  300. LPCWSTR groupname,
  301. DWORD level,
  302. LPBYTE *bufptr,
  303. DWORD prefmaxlen,
  304. LPDWORD entriesread,
  305. LPDWORD totalentries,
  306. PDWORD_PTR ResumeHandle)
  307. {
  308. NET_API_STATUS ns = NERR_NetworkError;
  309. if(m_pnetapi != NULL)
  310. {
  311. ns = m_pnetapi->NetGroupGetUsers(servername, groupname, level, bufptr,
  312. prefmaxlen, entriesread, totalentries,
  313. ResumeHandle);
  314. }
  315. return ns;
  316. }
  317. #endif
  318. #ifdef NTONLY
  319. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetLocalGroupGetMembers(LPCWSTR servername,
  320. LPCWSTR groupname,
  321. DWORD level,
  322. LPBYTE *bufptr,
  323. DWORD prefmaxlen,
  324. LPDWORD entriesread,
  325. LPDWORD totalentries,
  326. PDWORD_PTR ResumeHandle)
  327. {
  328. NET_API_STATUS ns = NERR_NetworkError;
  329. if(m_pnetapi != NULL)
  330. {
  331. ns = m_pnetapi->NetLocalGroupGetMembers(servername, groupname, level,
  332. bufptr, prefmaxlen, entriesread,
  333. totalentries, ResumeHandle);
  334. }
  335. return ns;
  336. }
  337. #endif
  338. #ifdef NTONLY
  339. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetLocalGroupEnum(LPCWSTR servername,
  340. DWORD level,
  341. LPBYTE *bufptr,
  342. DWORD prefmaxlen,
  343. LPDWORD entriesread,
  344. LPDWORD totalentries,
  345. PDWORD_PTR resume_handle)
  346. {
  347. NET_API_STATUS ns = NERR_NetworkError;
  348. if(m_pnetapi != NULL)
  349. {
  350. ns = m_pnetapi->NetLocalGroupEnum(servername, level, bufptr, prefmaxlen,
  351. entriesread, totalentries,
  352. resume_handle);
  353. }
  354. return ns;
  355. }
  356. #endif
  357. #ifdef NTONLY
  358. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareEnum(LPTSTR servername,
  359. DWORD level,
  360. LPBYTE *bufptr,
  361. DWORD prefmaxlen,
  362. LPDWORD entriesread,
  363. LPDWORD totalentries,
  364. LPDWORD resume_handle)
  365. {
  366. NET_API_STATUS ns = NERR_NetworkError;
  367. if(m_pnetapi != NULL)
  368. {
  369. ns = m_pnetapi->NetShareEnum(servername, level, bufptr, prefmaxlen,
  370. entriesread, totalentries, resume_handle);
  371. }
  372. return ns;
  373. }
  374. #endif
  375. #ifdef NTONLY
  376. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareGetInfo(LPTSTR servername,
  377. LPTSTR netname,
  378. DWORD level,
  379. LPBYTE *bufptr)
  380. {
  381. NET_API_STATUS ns = NERR_NetworkError;
  382. if(m_pnetapi != NULL)
  383. {
  384. ns = m_pnetapi->NetShareGetInfo(servername, netname, level, bufptr);
  385. }
  386. return ns;
  387. }
  388. #endif
  389. #ifdef NTONLY
  390. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareAdd (
  391. IN LPTSTR servername,
  392. IN DWORD level,
  393. IN LPBYTE buf,
  394. OUT LPDWORD parm_err
  395. )
  396. {
  397. NET_API_STATUS ns = NERR_NetworkError;
  398. if(m_pnetapi != NULL)
  399. {
  400. ns = m_pnetapi->NetShareAdd(servername, level, buf , parm_err);
  401. }
  402. return ns;
  403. }
  404. #endif
  405. #ifdef NTONLY
  406. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareEnumSticky (
  407. IN LPTSTR servername,
  408. IN DWORD level,
  409. OUT LPBYTE *bufptr,
  410. IN DWORD prefmaxlen,
  411. OUT LPDWORD entriesread,
  412. OUT LPDWORD totalentries,
  413. IN OUT LPDWORD resume_handle
  414. )
  415. {
  416. NET_API_STATUS ns = NERR_NetworkError;
  417. if(m_pnetapi != NULL)
  418. {
  419. ns = m_pnetapi->NetShareEnumSticky(servername, level, bufptr, prefmaxlen,
  420. entriesread, totalentries,
  421. resume_handle);
  422. }
  423. return ns;
  424. }
  425. #endif
  426. #ifdef NTONLY
  427. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareSetInfo (
  428. IN LPTSTR servername,
  429. IN LPTSTR netname,
  430. IN DWORD level,
  431. IN LPBYTE buf,
  432. OUT LPDWORD parm_err
  433. )
  434. {
  435. NET_API_STATUS ns = NERR_NetworkError;
  436. if(m_pnetapi != NULL)
  437. {
  438. ns = m_pnetapi->NetShareSetInfo(servername, netname,level,buf,parm_err);
  439. }
  440. return ns;
  441. }
  442. #endif
  443. #ifdef NTONLY
  444. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareDel (
  445. IN LPTSTR servername,
  446. IN LPTSTR netname,
  447. IN DWORD reserved
  448. )
  449. {
  450. NET_API_STATUS ns = NERR_NetworkError;
  451. if(m_pnetapi != NULL)
  452. {
  453. ns = m_pnetapi->NetShareDel(servername, netname, reserved);
  454. }
  455. return ns;
  456. }
  457. #endif
  458. #ifdef NTONLY
  459. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareDelSticky (
  460. IN LPTSTR servername,
  461. IN LPTSTR netname,
  462. IN DWORD reserved
  463. )
  464. {
  465. NET_API_STATUS ns = NERR_NetworkError;
  466. if(m_pnetapi != NULL)
  467. {
  468. ns = m_pnetapi->NetShareDelSticky(servername, netname, reserved);
  469. }
  470. return ns;
  471. }
  472. #endif
  473. #ifdef NTONLY
  474. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetShareCheck (
  475. IN LPTSTR servername,
  476. IN LPTSTR device,
  477. OUT LPDWORD type
  478. )
  479. {
  480. NET_API_STATUS ns = NERR_NetworkError;
  481. if(m_pnetapi != NULL)
  482. {
  483. ns = m_pnetapi->NetShareCheck(servername, device, type);
  484. }
  485. return ns;
  486. }
  487. #endif
  488. #ifdef NTONLY
  489. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetUserEnum(LPCWSTR servername,
  490. DWORD level,
  491. DWORD filter,
  492. LPBYTE *bufptr,
  493. DWORD prefmaxlen,
  494. LPDWORD entriesread,
  495. LPDWORD totalentries,
  496. LPDWORD resume_handle)
  497. {
  498. NET_API_STATUS ns = NERR_NetworkError;
  499. if(m_pnetapi != NULL)
  500. {
  501. int i = 1;
  502. // try with longer preferred lengths if it fails
  503. // might only be germaine to NT 3.51, dunno but it works.
  504. do
  505. {
  506. ns = m_pnetapi->NetUserEnum(servername, level, filter, bufptr,
  507. prefmaxlen * i, entriesread, totalentries,
  508. resume_handle);
  509. i *= 2;
  510. } while (ns == NERR_BufTooSmall && i <= 16);
  511. }
  512. return ns;
  513. }
  514. #endif
  515. #ifdef NTONLY
  516. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetUserGetInfo(LPCWSTR servername,
  517. LPCWSTR username,
  518. DWORD level,
  519. LPBYTE *bufptr)
  520. {
  521. NET_API_STATUS ns = NERR_NetworkError;
  522. if(m_pnetapi != NULL)
  523. {
  524. ns = m_pnetapi->NetUserGetInfo(servername, username, level, bufptr);
  525. }
  526. return ns;
  527. }
  528. #endif
  529. #ifdef NTONLY
  530. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetUserSetInfo(
  531. LPCWSTR a_servername,
  532. LPCWSTR a_username,
  533. DWORD a_level,
  534. LPBYTE a_buf,
  535. LPDWORD a_parm_err
  536. )
  537. {
  538. NET_API_STATUS t_ns = NERR_NetworkError;
  539. if( m_pnetapi != NULL )
  540. {
  541. t_ns = m_pnetapi->NetUserSetInfo( a_servername, a_username, a_level, a_buf, a_parm_err ) ;
  542. }
  543. return t_ns ;
  544. }
  545. #endif
  546. #ifdef NTONLY
  547. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetApiBufferFree(void *bufptr)
  548. {
  549. NET_API_STATUS ns = NERR_NetworkError;
  550. if(m_pnetapi != NULL)
  551. {
  552. ns = m_pnetapi->NetApiBufferFree(bufptr);
  553. }
  554. return ns;
  555. }
  556. #endif
  557. #ifdef NTONLY
  558. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetQueryDisplayInformation( LPWSTR ServerName,
  559. DWORD Level,
  560. DWORD Index,
  561. DWORD EntriesRequested,
  562. DWORD PreferredMaximumLength,
  563. LPDWORD ReturnedEntryCount,
  564. PVOID *SortedBuffer)
  565. {
  566. NET_API_STATUS ns = NERR_NetworkError;
  567. if(m_pnetapi != NULL)
  568. {
  569. ns = m_pnetapi->NetQueryDisplayInformation(ServerName, Level, Index,
  570. EntriesRequested,
  571. PreferredMaximumLength,
  572. ReturnedEntryCount, SortedBuffer);
  573. }
  574. return ns;
  575. }
  576. #endif
  577. #ifdef NTONLY
  578. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetServerSetInfo(LPTSTR servername,
  579. DWORD level,
  580. LPBYTE bufptr,
  581. LPDWORD ParmError)
  582. {
  583. NET_API_STATUS ns = NERR_NetworkError;
  584. if(m_pnetapi != NULL)
  585. {
  586. ns = m_pnetapi->NetServerSetInfo(servername, level, bufptr, ParmError);
  587. }
  588. return ns;
  589. }
  590. #endif
  591. #ifdef NTONLY
  592. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetServerGetInfo(LPTSTR servername,
  593. DWORD level,
  594. LPBYTE *bufptr)
  595. {
  596. NET_API_STATUS ns = NERR_NetworkError;
  597. if(m_pnetapi != NULL)
  598. {
  599. ns = m_pnetapi->NetServerGetInfo(servername, level, bufptr);
  600. }
  601. return ns;
  602. }
  603. #endif
  604. #ifdef NTONLY
  605. NET_API_STATUS NET_API_FUNCTION CNetAPI32::DSRoleGetPrimaryDomainInfo(LPCWSTR servername,
  606. DSROLE_PRIMARY_DOMAIN_INFO_LEVEL level,
  607. LPBYTE *bufptr)
  608. {
  609. NET_API_STATUS ns = NERR_NetworkError;
  610. if(m_pnetapi != NULL)
  611. {
  612. // Check if the machine is running an NT5 version of netapi32.dll...
  613. if(!m_pnetapi->DSRoleGetPrimaryDomainInformation(servername,
  614. level, bufptr, &ns))
  615. {
  616. ns = NERR_InternalError;
  617. }
  618. }
  619. return ns;
  620. }
  621. #endif
  622. #ifdef NTONLY
  623. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetRenameMachineInDomain(LPCWSTR a_lpServer,
  624. LPCWSTR a_lpNewMachineName,
  625. LPCWSTR a_lpAccount,
  626. LPCWSTR a_lpPassword,
  627. DWORD a_fRenameOptions)
  628. {
  629. NET_API_STATUS ns = NERR_NetworkError;
  630. if(m_pnetapi != NULL)
  631. {
  632. // Check if the machine is running an NT5 version of netapi32.dll...
  633. if(!m_pnetapi->NetRenameMachineInDomain(a_lpServer, a_lpNewMachineName,
  634. a_lpAccount, a_lpPassword,
  635. a_fRenameOptions, &ns))
  636. {
  637. ns = NERR_InternalError;
  638. }
  639. }
  640. return ns;
  641. }
  642. #endif
  643. #ifdef NTONLY
  644. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetUnjoinDomain( LPCWSTR lpServer,
  645. LPCWSTR lpAccount,
  646. LPCWSTR lpPassword,
  647. DWORD fUnjoinOptions)
  648. {
  649. NET_API_STATUS ns = NERR_NetworkError;
  650. if(m_pnetapi != NULL)
  651. {
  652. // Check if the machine is running an NT5 version of netapi32.dll...
  653. if(!m_pnetapi->NetUnjoinDomain(lpServer, lpAccount, lpPassword, fUnjoinOptions, &ns))
  654. {
  655. ns = NERR_InternalError;
  656. }
  657. }
  658. return ns;
  659. }
  660. #endif
  661. #ifdef NTONLY
  662. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetJoinDomain( LPCWSTR lpServer,
  663. LPCWSTR lpDomain,
  664. LPCWSTR lpAccountOU,
  665. LPCWSTR lpAccount,
  666. LPCWSTR lpPassword,
  667. DWORD fJoinOptions)
  668. {
  669. NET_API_STATUS ns = NERR_NetworkError;
  670. if(m_pnetapi != NULL)
  671. {
  672. // Check if the machine is running an NT5 version of netapi32.dll...
  673. if(!m_pnetapi->NetJoinDomain(lpServer, lpDomain, lpAccountOU, lpAccount, lpPassword, fJoinOptions, &ns))
  674. {
  675. ns = NERR_InternalError;
  676. }
  677. }
  678. return ns;
  679. }
  680. #endif
  681. #ifdef NTONLY
  682. NET_API_STATUS NET_API_FUNCTION CNetAPI32::DSRoleFreeMemory(LPBYTE bufptr)
  683. {
  684. NET_API_STATUS ns = NERR_NetworkError;
  685. if(m_pnetapi != NULL)
  686. {
  687. // Check if the machine is running an NT5 version of netapi32.dll...
  688. if(!m_pnetapi->DSRoleFreeMemory(bufptr, &ns))
  689. {
  690. ns = NERR_InternalError;
  691. }
  692. }
  693. return ns;
  694. }
  695. #endif
  696. #ifdef NTONLY
  697. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetGetDCName( LPCWSTR ServerName,
  698. LPCWSTR DomainName,
  699. LPBYTE* bufptr )
  700. {
  701. NET_API_STATUS ns = NERR_NetworkError;
  702. if(m_pnetapi != NULL)
  703. {
  704. ns = m_pnetapi->NetGetDCName(ServerName, DomainName, bufptr);
  705. }
  706. return ns;
  707. }
  708. #endif
  709. #ifdef NTONLY
  710. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetWkstaGetInfo( LPWSTR ServerName,
  711. DWORD level,
  712. LPBYTE *bufptr )
  713. {
  714. NET_API_STATUS ns = NERR_NetworkError;
  715. if(m_pnetapi != NULL)
  716. {
  717. ns = m_pnetapi->NetWkstaGetInfo(ServerName, level, bufptr);
  718. }
  719. return ns;
  720. }
  721. #endif
  722. #ifdef NTONLY
  723. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetGetAnyDCName( LPWSTR ServerName,
  724. LPWSTR DomainName,
  725. LPBYTE* bufptr )
  726. {
  727. NET_API_STATUS ns = NERR_NetworkError;
  728. if(m_pnetapi != NULL)
  729. {
  730. ns = m_pnetapi->NetGetAnyDCName(ServerName, DomainName, bufptr);
  731. }
  732. return ns;
  733. }
  734. #endif
  735. #ifdef NTONLY
  736. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetServerEnum( LPTSTR servername,
  737. DWORD level,
  738. LPBYTE *bufptr,
  739. DWORD prefmaxlen,
  740. LPDWORD entriesread,
  741. LPDWORD totalentries,
  742. DWORD servertype,
  743. LPTSTR domain,
  744. LPDWORD resume_handle )
  745. {
  746. NET_API_STATUS ns = NERR_NetworkError;
  747. if(m_pnetapi != NULL)
  748. {
  749. ns = m_pnetapi->NetServerEnum(servername, level, bufptr, prefmaxlen,
  750. entriesread, totalentries, servertype,
  751. domain, resume_handle);
  752. }
  753. return ns;
  754. }
  755. #endif
  756. #ifdef NTONLY
  757. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetEnumerateTrustedDomains( LPWSTR servername,
  758. LPWSTR* domainNames )
  759. {
  760. NET_API_STATUS ns = NERR_NetworkError;
  761. if(m_pnetapi != NULL)
  762. {
  763. // Check if the machine is running an NT5 version of netapi32.dll...
  764. if(!m_pnetapi->NetEnumerateTrustedDomains(servername, domainNames, &ns))
  765. { // The function doesn't exist.
  766. ns = NERR_InternalError;
  767. }
  768. }
  769. return ns;
  770. }
  771. #endif
  772. #ifdef NTONLY
  773. NET_API_STATUS NET_API_FUNCTION CNetAPI32::DsGetDcName( LPCTSTR ComputerName,
  774. LPCTSTR DomainName,
  775. GUID *DomainGuid,
  776. LPCTSTR SiteName,
  777. ULONG Flags,
  778. PDOMAIN_CONTROLLER_INFO *DomainControllerInfo )
  779. {
  780. NET_API_STATUS ns = NERR_NetworkError;
  781. if(m_pnetapi != NULL)
  782. {
  783. // Check if the machine is running an NT5 version of netapi32.dll...
  784. if(!m_pnetapi->DsGetDCName(ComputerName, DomainName, DomainGuid,
  785. SiteName, Flags, DomainControllerInfo, &ns))
  786. { // The function does not exist.
  787. ns = NERR_InternalError;
  788. }
  789. }
  790. return ns;
  791. }
  792. #endif
  793. #ifdef NTONLY
  794. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetUserModalsGet( LPWSTR servername,
  795. DWORD level,
  796. LPBYTE *bufptr )
  797. {
  798. NET_API_STATUS ns = NERR_NetworkError;
  799. if(m_pnetapi != NULL)
  800. {
  801. ns = m_pnetapi->NetUserModalsGet(servername, level, bufptr);
  802. }
  803. return ns;
  804. }
  805. #endif
  806. #ifdef NTONLY
  807. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetScheduleJobAdd (
  808. IN LPCWSTR Servername OPTIONAL,
  809. IN LPBYTE Buffer,
  810. OUT LPDWORD JobId
  811. )
  812. {
  813. NET_API_STATUS ns = NERR_NetworkError;
  814. if(m_pnetapi != NULL)
  815. {
  816. ns = m_pnetapi->NetScheduleJobAdd(Servername, Buffer, JobId);
  817. }
  818. return ns;
  819. }
  820. #endif
  821. #ifdef NTONLY
  822. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetScheduleJobDel (
  823. IN LPCWSTR Servername OPTIONAL,
  824. IN DWORD MinJobId,
  825. IN DWORD MaxJobId
  826. )
  827. {
  828. NET_API_STATUS ns = NERR_NetworkError;
  829. if(m_pnetapi != NULL)
  830. {
  831. ns = m_pnetapi->NetScheduleJobDel(Servername, MinJobId , MaxJobId);
  832. }
  833. return ns;
  834. }
  835. #endif
  836. #ifdef NTONLY
  837. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetScheduleJobEnum (
  838. IN LPCWSTR Servername OPTIONAL,
  839. OUT LPBYTE * PointerToBuffer,
  840. IN DWORD PrefferedMaximumLength,
  841. OUT LPDWORD EntriesRead,
  842. OUT LPDWORD TotalEntries,
  843. IN OUT LPDWORD ResumeHandle
  844. )
  845. {
  846. NET_API_STATUS ns = NERR_NetworkError;
  847. if(m_pnetapi != NULL)
  848. {
  849. ns = m_pnetapi->NetScheduleJobEnum(Servername, PointerToBuffer,
  850. PrefferedMaximumLength, EntriesRead,
  851. TotalEntries, ResumeHandle);
  852. }
  853. return ns;
  854. }
  855. #endif
  856. #ifdef NTONLY
  857. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetScheduleJobGetInfo (
  858. IN LPCWSTR Servername OPTIONAL,
  859. IN DWORD JobId,
  860. OUT LPBYTE * PointerToBuffer
  861. )
  862. {
  863. NET_API_STATUS ns = NERR_NetworkError;
  864. if(m_pnetapi != NULL)
  865. {
  866. ns = m_pnetapi->NetScheduleJobGetInfo(Servername, JobId , PointerToBuffer);
  867. }
  868. return ns;
  869. }
  870. #endif
  871. #ifdef NTONLY
  872. NET_API_STATUS NET_API_FUNCTION CNetAPI32::NetUseGetInfo(
  873. IN LPCWSTR UncServerName OPTIONAL,
  874. IN LPCWSTR UseName,
  875. IN DWORD Level,
  876. OUT LPBYTE *BufPtr)
  877. {
  878. NET_API_STATUS ns = NERR_NetworkError;
  879. if(m_pnetapi != NULL)
  880. {
  881. ns = m_pnetapi->NetUseGetInfo(UncServerName, UseName, Level, BufPtr);
  882. }
  883. return ns;
  884. }
  885. #endif
  886. /////////////////////////////////////////////////////////////////////////////
  887. //
  888. // Function: CWin32UserAccount::GetTrustedDomainsNT
  889. //
  890. // Obtains Names of trusted domains and stuffs them in a user supplied
  891. // CHStringArray.
  892. //
  893. // Inputs:
  894. //
  895. // Outputs: CHStringArray& strarrayTrustedDomains;
  896. //
  897. // Returns: TRUE/FALSE Success/Failure
  898. //
  899. // Comments:
  900. //
  901. /////////////////////////////////////////////////////////////////////////////
  902. #ifdef NTONLY
  903. BOOL CNetAPI32::GetTrustedDomainsNT(CHStringArray& achsTrustList)
  904. {
  905. LSA_HANDLE PolicyHandle = INVALID_HANDLE_VALUE;
  906. NTSTATUS Status =0;
  907. NET_API_STATUS nas = NERR_Success; // assume success
  908. BOOL bSuccess = FALSE; // assume this function will fail
  909. CAdvApi32Api *t_padvapi = (CAdvApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidAdvApi32Api, NULL) ;
  910. if( t_padvapi == NULL)
  911. {
  912. return FALSE;
  913. }
  914. try
  915. {
  916. PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomain = NULL;
  917. //
  918. // open the policy on the specified machine
  919. //
  920. {
  921. Status = OpenPolicy(
  922. t_padvapi ,
  923. NULL,
  924. POLICY_VIEW_LOCAL_INFORMATION,
  925. &PolicyHandle
  926. );
  927. if(Status != STATUS_SUCCESS)
  928. {
  929. SetLastError( t_padvapi->LsaNtStatusToWinError(Status) );
  930. if ( t_padvapi )
  931. {
  932. CResourceManager::sm_TheResourceManager.ReleaseResource (g_guidAdvApi32Api , t_padvapi ) ;
  933. t_padvapi = NULL ;
  934. return FALSE;
  935. }
  936. }
  937. //
  938. // obtain the AccountDomain, which is common to all three cases
  939. //
  940. Status = t_padvapi->LsaQueryInformationPolicy(
  941. PolicyHandle,
  942. PolicyAccountDomainInformation,
  943. (PVOID *)&AccountDomain
  944. );
  945. }
  946. if(Status == STATUS_SUCCESS)
  947. {
  948. try
  949. {
  950. //
  951. // Note: AccountDomain->DomainSid will contain binary Sid
  952. //
  953. achsTrustList.Add(CHString(AccountDomain->DomainName.Buffer));
  954. }
  955. catch ( ... )
  956. {
  957. t_padvapi->LsaFreeMemory(AccountDomain);
  958. throw ;
  959. }
  960. //
  961. // free memory allocated for account domain
  962. //
  963. t_padvapi->LsaFreeMemory(AccountDomain);
  964. //
  965. // find out if the target machine is a domain controller
  966. //
  967. if(!IsDomainController(NULL))
  968. {
  969. PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomain;
  970. CHString sPrimaryDomainName;
  971. //
  972. // get the primary domain
  973. //
  974. {
  975. Status = t_padvapi->LsaQueryInformationPolicy(
  976. PolicyHandle,
  977. PolicyPrimaryDomainInformation,
  978. (PVOID *)&PrimaryDomain
  979. );
  980. }
  981. if(Status == STATUS_SUCCESS)
  982. {
  983. //
  984. // if the primary domain Sid is NULL, we are a non-member, and
  985. // our work is done.
  986. //
  987. if(PrimaryDomain->Sid == NULL)
  988. {
  989. t_padvapi->LsaFreeMemory(PrimaryDomain);
  990. bSuccess = TRUE;
  991. t_padvapi->LsaClose(PolicyHandle);
  992. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  993. }
  994. else
  995. {
  996. try
  997. {
  998. achsTrustList.Add(CHString(PrimaryDomain->Name.Buffer));
  999. //
  1000. // build a copy of what we just added. This is necessary in order
  1001. // to lookup the domain controller for the specified domain.
  1002. // the Domain name must be NULL terminated for NetGetDCName(),
  1003. // and the LSA_UNICODE_STRING buffer is not necessarilly NULL
  1004. // terminated. Note that in a practical implementation, we
  1005. // could just extract the element we added, since it ends up
  1006. // NULL terminated.
  1007. //
  1008. sPrimaryDomainName = CHString(PrimaryDomain->Name.Buffer);
  1009. }
  1010. catch ( ... )
  1011. {
  1012. t_padvapi->LsaFreeMemory(PrimaryDomain);
  1013. throw ;
  1014. }
  1015. t_padvapi->LsaFreeMemory(PrimaryDomain);
  1016. //
  1017. // get the primary domain controller computer name
  1018. //
  1019. LPWSTR DomainController = NULL;
  1020. nas = NetGetDCName(
  1021. NULL,
  1022. sPrimaryDomainName,
  1023. (LPBYTE *)&DomainController
  1024. );
  1025. if(nas == NERR_Success)
  1026. {
  1027. try
  1028. {
  1029. //
  1030. // close the policy handle, because we don't need it anymore
  1031. // for the workstation case, as we open a handle to a DC
  1032. // policy below
  1033. //
  1034. {
  1035. t_padvapi->LsaClose(PolicyHandle);
  1036. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1037. //
  1038. // open the policy on the domain controller
  1039. //
  1040. Status = OpenPolicy(
  1041. t_padvapi ,
  1042. DomainController,
  1043. POLICY_VIEW_LOCAL_INFORMATION,
  1044. &PolicyHandle
  1045. );
  1046. }
  1047. }
  1048. catch ( ... )
  1049. {
  1050. NetApiBufferFree(DomainController);
  1051. throw ;
  1052. }
  1053. //
  1054. // free the domaincontroller buffer
  1055. //
  1056. NetApiBufferFree(DomainController);
  1057. if(Status != STATUS_SUCCESS)
  1058. {
  1059. PolicyHandle = INVALID_HANDLE_VALUE;
  1060. }
  1061. }
  1062. else
  1063. {
  1064. t_padvapi->LsaClose(PolicyHandle);
  1065. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1066. }
  1067. }
  1068. }
  1069. else
  1070. {
  1071. t_padvapi->LsaClose(PolicyHandle);
  1072. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1073. }
  1074. }
  1075. //
  1076. // build additional trusted domain(s) list and indicate if successful
  1077. //
  1078. if ((PolicyHandle != INVALID_HANDLE_VALUE) && (PolicyHandle != NULL))
  1079. {
  1080. bSuccess = EnumTrustedDomains(PolicyHandle, achsTrustList);
  1081. }
  1082. }
  1083. // close the policy handle
  1084. // policy handle is actually a pointer (per comments in the header)
  1085. // will check for NULL case
  1086. {
  1087. if ((PolicyHandle != INVALID_HANDLE_VALUE) && (PolicyHandle != NULL))
  1088. {
  1089. t_padvapi->LsaClose(PolicyHandle);
  1090. PolicyHandle = INVALID_HANDLE_VALUE ;
  1091. }
  1092. }
  1093. if(!bSuccess)
  1094. {
  1095. if(Status != STATUS_SUCCESS)
  1096. {
  1097. SetLastError( t_padvapi->LsaNtStatusToWinError(Status) );
  1098. }
  1099. else if(nas != NERR_Success)
  1100. {
  1101. SetLastError( nas );
  1102. }
  1103. }
  1104. if ( t_padvapi )
  1105. {
  1106. CResourceManager::sm_TheResourceManager.ReleaseResource (g_guidAdvApi32Api , t_padvapi ) ;
  1107. t_padvapi = NULL ;
  1108. }
  1109. return bSuccess;
  1110. }
  1111. catch ( ... )
  1112. {
  1113. if ((PolicyHandle != INVALID_HANDLE_VALUE) && (PolicyHandle != NULL))
  1114. {
  1115. t_padvapi->LsaClose(PolicyHandle);
  1116. PolicyHandle = INVALID_HANDLE_VALUE;
  1117. }
  1118. if ( t_padvapi )
  1119. {
  1120. CResourceManager::sm_TheResourceManager.ReleaseResource (g_guidAdvApi32Api , t_padvapi ) ;
  1121. t_padvapi = NULL ;
  1122. }
  1123. throw ;
  1124. }
  1125. }
  1126. #endif
  1127. /////////////////////////////////////////////////////////////////////////////
  1128. //
  1129. // Function: CWin32UserAccount::GetTrustedDomainsNT
  1130. //
  1131. // Obtains Names of trusted domains and stuffs them in a user supplied
  1132. // standard template library stack of _bstr_t's.
  1133. //
  1134. // Inputs: reference to stack of _bstr_t's
  1135. //
  1136. // Outputs: CHStringArray& strarrayTrustedDomains;
  1137. //
  1138. // Returns: TRUE/FALSE Success/Failure
  1139. //
  1140. // Comments:
  1141. //
  1142. /////////////////////////////////////////////////////////////////////////////
  1143. #ifdef NTONLY
  1144. BOOL CNetAPI32::GetTrustedDomainsNT(std::vector<_bstr_t>& vectorTrustList)
  1145. {
  1146. LSA_HANDLE PolicyHandle = INVALID_HANDLE_VALUE;
  1147. NTSTATUS Status =0;
  1148. NET_API_STATUS nas = NERR_Success; // assume success
  1149. BOOL bSuccess = FALSE; // assume this function will fail
  1150. CAdvApi32Api *t_padvapi = (CAdvApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidAdvApi32Api, NULL) ;
  1151. if( t_padvapi == NULL)
  1152. {
  1153. return FALSE;
  1154. }
  1155. try
  1156. {
  1157. PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomain = NULL;
  1158. //
  1159. // open the policy on the specified machine
  1160. //
  1161. {
  1162. Status = OpenPolicy(
  1163. t_padvapi,
  1164. NULL,
  1165. POLICY_VIEW_LOCAL_INFORMATION,
  1166. &PolicyHandle
  1167. );
  1168. if(Status != STATUS_SUCCESS)
  1169. {
  1170. SetLastError( t_padvapi->LsaNtStatusToWinError(Status) );
  1171. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1172. t_padvapi = NULL ;
  1173. return FALSE;
  1174. }
  1175. //
  1176. // obtain the AccountDomain, which is common to all three cases
  1177. //
  1178. Status = t_padvapi->LsaQueryInformationPolicy(
  1179. PolicyHandle,
  1180. PolicyAccountDomainInformation,
  1181. (PVOID *)&AccountDomain
  1182. );
  1183. }
  1184. if(Status == STATUS_SUCCESS)
  1185. {
  1186. try
  1187. {
  1188. //
  1189. // Note: AccountDomain->DomainSid will contain binary Sid
  1190. //
  1191. _bstr_t t_bstrtTemp(AccountDomain->DomainName.Buffer);
  1192. if(!AlreadyAddedToList(vectorTrustList, t_bstrtTemp))
  1193. {
  1194. vectorTrustList.push_back(t_bstrtTemp);
  1195. }
  1196. }
  1197. catch ( ... )
  1198. {
  1199. t_padvapi->LsaFreeMemory(AccountDomain);
  1200. throw ;
  1201. }
  1202. //
  1203. // free memory allocated for account domain
  1204. //
  1205. t_padvapi->LsaFreeMemory(AccountDomain);
  1206. //
  1207. // find out if the target machine is a domain controller
  1208. //
  1209. if(!IsDomainController(NULL))
  1210. {
  1211. PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomain;
  1212. CHString sPrimaryDomainName;
  1213. //
  1214. // get the primary domain
  1215. //
  1216. {
  1217. Status = t_padvapi->LsaQueryInformationPolicy(
  1218. PolicyHandle,
  1219. PolicyPrimaryDomainInformation,
  1220. (PVOID *)&PrimaryDomain
  1221. );
  1222. }
  1223. if(Status == STATUS_SUCCESS)
  1224. {
  1225. //
  1226. // if the primary domain Sid is NULL, we are a non-member, and
  1227. // our work is done.
  1228. //
  1229. if(PrimaryDomain->Sid == NULL)
  1230. {
  1231. t_padvapi->LsaFreeMemory(PrimaryDomain);
  1232. bSuccess = TRUE;
  1233. t_padvapi->LsaClose(PolicyHandle);
  1234. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1235. }
  1236. else
  1237. {
  1238. try
  1239. {
  1240. _bstr_t t_bstrtTemp(PrimaryDomain->Name.Buffer) ;
  1241. if(!AlreadyAddedToList(vectorTrustList, t_bstrtTemp))
  1242. {
  1243. vectorTrustList.push_back(t_bstrtTemp);
  1244. }
  1245. //
  1246. // build a copy of what we just added. This is necessary in order
  1247. // to lookup the domain controller for the specified domain.
  1248. // the Domain name must be NULL terminated for NetGetDCName(),
  1249. // and the LSA_UNICODE_STRING buffer is not necessarilly NULL
  1250. // terminated. Note that in a practical implementation, we
  1251. // could just extract the element we added, since it ends up
  1252. // NULL terminated.
  1253. //
  1254. sPrimaryDomainName = PrimaryDomain->Name.Buffer;
  1255. }
  1256. catch ( ... )
  1257. {
  1258. t_padvapi->LsaFreeMemory(PrimaryDomain);
  1259. throw ;
  1260. }
  1261. t_padvapi->LsaFreeMemory(PrimaryDomain);
  1262. //
  1263. // get the primary domain controller computer name
  1264. //
  1265. LPWSTR DomainController = NULL;
  1266. nas = NetGetDCName(
  1267. NULL,
  1268. sPrimaryDomainName,
  1269. (LPBYTE *)&DomainController
  1270. );
  1271. if(nas == NERR_Success)
  1272. {
  1273. try
  1274. {
  1275. //
  1276. // close the policy handle, because we don't need it anymore
  1277. // for the workstation case, as we open a handle to a DC
  1278. // policy below
  1279. //
  1280. {
  1281. t_padvapi->LsaClose(PolicyHandle);
  1282. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1283. //
  1284. // open the policy on the domain controller
  1285. //
  1286. Status = OpenPolicy(
  1287. t_padvapi ,
  1288. DomainController,
  1289. POLICY_VIEW_LOCAL_INFORMATION,
  1290. &PolicyHandle
  1291. );
  1292. }
  1293. }
  1294. catch ( ... )
  1295. {
  1296. NetApiBufferFree(DomainController);
  1297. throw ;
  1298. }
  1299. //
  1300. // free the domaincontroller buffer
  1301. //
  1302. NetApiBufferFree(DomainController);
  1303. if(Status != STATUS_SUCCESS)
  1304. {
  1305. PolicyHandle = INVALID_HANDLE_VALUE;
  1306. }
  1307. }
  1308. else
  1309. {
  1310. t_padvapi->LsaClose(PolicyHandle);
  1311. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1312. }
  1313. }
  1314. }
  1315. else
  1316. {
  1317. t_padvapi->LsaClose(PolicyHandle);
  1318. PolicyHandle = INVALID_HANDLE_VALUE; // invalidate handle value
  1319. }
  1320. }
  1321. //
  1322. // build additional trusted domain(s) list and indicate if successful
  1323. //
  1324. if ((PolicyHandle != INVALID_HANDLE_VALUE) && (PolicyHandle != NULL))
  1325. {
  1326. bSuccess = EnumTrustedDomains(PolicyHandle, vectorTrustList);
  1327. }
  1328. }
  1329. // close the policy handle
  1330. // policy handle is actually a pointer (per comments in the header)
  1331. // will check for NULL case
  1332. {
  1333. if ((PolicyHandle != INVALID_HANDLE_VALUE) && (PolicyHandle != NULL))
  1334. {
  1335. t_padvapi->LsaClose(PolicyHandle);
  1336. PolicyHandle = INVALID_HANDLE_VALUE ;
  1337. }
  1338. }
  1339. if(!bSuccess)
  1340. {
  1341. if(Status != STATUS_SUCCESS)
  1342. {
  1343. SetLastError( t_padvapi->LsaNtStatusToWinError(Status) );
  1344. }
  1345. else if(nas != NERR_Success)
  1346. {
  1347. SetLastError( nas );
  1348. }
  1349. }
  1350. if ( t_padvapi )
  1351. {
  1352. CResourceManager::sm_TheResourceManager.ReleaseResource (g_guidAdvApi32Api , t_padvapi ) ;
  1353. t_padvapi = NULL ;
  1354. }
  1355. return bSuccess;
  1356. }
  1357. catch ( ... )
  1358. {
  1359. if ((PolicyHandle != INVALID_HANDLE_VALUE) && (PolicyHandle != NULL))
  1360. {
  1361. t_padvapi->LsaClose(PolicyHandle);
  1362. PolicyHandle = INVALID_HANDLE_VALUE;
  1363. }
  1364. if ( t_padvapi )
  1365. {
  1366. CResourceManager::sm_TheResourceManager.ReleaseResource (g_guidAdvApi32Api , t_padvapi ) ;
  1367. t_padvapi = NULL ;
  1368. }
  1369. throw;
  1370. }
  1371. }
  1372. #endif
  1373. ///////////////////////////////////////////////////////
  1374. #ifdef NTONLY
  1375. BOOL CNetAPI32::EnumTrustedDomains(LSA_HANDLE PolicyHandle, CHStringArray &achsTrustList)
  1376. {
  1377. LSA_ENUMERATION_HANDLE lsaEnumHandle=0; // start an enum
  1378. PLSA_TRUST_INFORMATION TrustInfo = NULL ;
  1379. ULONG ulReturned; // number of items returned
  1380. ULONG ulCounter; // cunter for items returned
  1381. NTSTATUS Status;
  1382. CAdvApi32Api *t_padvapi = (CAdvApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidAdvApi32Api, NULL) ;
  1383. if( t_padvapi == NULL)
  1384. {
  1385. return FALSE;
  1386. }
  1387. try
  1388. {
  1389. do
  1390. {
  1391. Status = t_padvapi->LsaEnumerateTrustedDomains(
  1392. PolicyHandle, // open policy handle
  1393. &lsaEnumHandle, // enumeration tracker
  1394. (PVOID *)&TrustInfo, // buffer to receive data
  1395. 32000, // recommended buffer size
  1396. &ulReturned // number of items returned
  1397. );
  1398. //
  1399. // get out if an error occurred
  1400. //
  1401. if( (Status != STATUS_SUCCESS) &&
  1402. (Status != STATUS_MORE_ENTRIES) &&
  1403. (Status != STATUS_NO_MORE_ENTRIES)
  1404. )
  1405. {
  1406. SetLastError( t_padvapi->LsaNtStatusToWinError(Status) );
  1407. if ( t_padvapi )
  1408. {
  1409. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1410. t_padvapi = NULL ;
  1411. }
  1412. return FALSE;
  1413. }
  1414. //
  1415. // Display results
  1416. // Note: Sids are in TrustInfo[ulCounter].Sid
  1417. //
  1418. for(ulCounter = 0 ; ulCounter < ulReturned ; ulCounter++)
  1419. {
  1420. achsTrustList.Add(CHString(TrustInfo[ulCounter].Name.Buffer));
  1421. }
  1422. //
  1423. // free the buffer
  1424. //
  1425. if ( TrustInfo )
  1426. {
  1427. t_padvapi->LsaFreeMemory ( TrustInfo ) ;
  1428. TrustInfo = NULL ;
  1429. }
  1430. } while (Status != STATUS_NO_MORE_ENTRIES);
  1431. if ( t_padvapi )
  1432. {
  1433. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1434. t_padvapi = NULL ;
  1435. }
  1436. return TRUE;
  1437. }
  1438. catch ( ... )
  1439. {
  1440. if ( TrustInfo )
  1441. {
  1442. t_padvapi->LsaFreeMemory ( TrustInfo ) ;
  1443. TrustInfo = NULL ;
  1444. }
  1445. if ( t_padvapi )
  1446. {
  1447. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1448. }
  1449. throw ;
  1450. }
  1451. }
  1452. #endif
  1453. ///////////////////////////////////////////////////////////////////////////////
  1454. #ifdef NTONLY
  1455. BOOL CNetAPI32::EnumTrustedDomains(LSA_HANDLE PolicyHandle, std::vector<_bstr_t>& vectorTrustList)
  1456. {
  1457. LSA_ENUMERATION_HANDLE lsaEnumHandle=0; // start an enum
  1458. PLSA_TRUST_INFORMATION TrustInfo = NULL ;
  1459. ULONG ulReturned; // number of items returned
  1460. ULONG ulCounter; // counter for items returned
  1461. NTSTATUS Status;
  1462. CAdvApi32Api *t_padvapi = (CAdvApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidAdvApi32Api, NULL) ;
  1463. if( t_padvapi == NULL )
  1464. {
  1465. return FALSE;
  1466. }
  1467. try
  1468. {
  1469. do {
  1470. Status = t_padvapi->LsaEnumerateTrustedDomains(
  1471. PolicyHandle, // open policy handle
  1472. &lsaEnumHandle, // enumeration tracker
  1473. (PVOID *)&TrustInfo, // buffer to receive data
  1474. 32000, // recommended buffer size
  1475. &ulReturned // number of items returned
  1476. );
  1477. //
  1478. // get out if an error occurred
  1479. //
  1480. if( (Status != STATUS_SUCCESS) &&
  1481. (Status != STATUS_MORE_ENTRIES) &&
  1482. (Status != STATUS_NO_MORE_ENTRIES)
  1483. )
  1484. {
  1485. SetLastError( t_padvapi->LsaNtStatusToWinError(Status) );
  1486. if ( t_padvapi )
  1487. {
  1488. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1489. t_padvapi = NULL ;
  1490. }
  1491. return FALSE;
  1492. }
  1493. //
  1494. // Display results
  1495. // Note: Sids are in TrustInfo[ulCounter].Sid
  1496. //
  1497. for(ulCounter = 0 ; ulCounter < ulReturned ; ulCounter++)
  1498. {
  1499. _bstr_t t_bstrtTemp(TrustInfo[ulCounter].Name.Buffer);
  1500. if(!AlreadyAddedToList(vectorTrustList, t_bstrtTemp))
  1501. {
  1502. vectorTrustList.push_back(t_bstrtTemp);
  1503. }
  1504. }
  1505. //
  1506. // free the buffer
  1507. //
  1508. if ( TrustInfo )
  1509. {
  1510. t_padvapi->LsaFreeMemory(TrustInfo);
  1511. TrustInfo = NULL ;
  1512. }
  1513. } while (Status != STATUS_NO_MORE_ENTRIES);
  1514. if ( t_padvapi )
  1515. {
  1516. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1517. t_padvapi = NULL ;
  1518. }
  1519. return TRUE;
  1520. }
  1521. catch ( ... )
  1522. {
  1523. if ( TrustInfo )
  1524. {
  1525. t_padvapi->LsaFreeMemory ( TrustInfo ) ;
  1526. TrustInfo = NULL ;
  1527. }
  1528. if ( t_padvapi )
  1529. {
  1530. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1531. t_padvapi = NULL ;
  1532. }
  1533. throw ;
  1534. }
  1535. }
  1536. #endif
  1537. ///////////////////////////////////////////////////////////////////////////////
  1538. #ifdef NTONLY
  1539. BOOL CNetAPI32::IsDomainController(LPTSTR Server)
  1540. {
  1541. PSERVER_INFO_101 si101;
  1542. BOOL bRet = FALSE; // Gotta return something
  1543. if (NetServerGetInfo(
  1544. Server,
  1545. 101, // info-level
  1546. (LPBYTE *)&si101
  1547. ) == NERR_Success) {
  1548. if( (si101->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
  1549. (si101->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) ) {
  1550. //
  1551. // we are dealing with a DC
  1552. //
  1553. bRet = TRUE;
  1554. } else {
  1555. bRet = FALSE;
  1556. }
  1557. NetApiBufferFree(si101);
  1558. }
  1559. return bRet;
  1560. }
  1561. #endif
  1562. #ifdef NTONLY
  1563. void CNetAPI32::InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String )
  1564. {
  1565. DWORD StringLength;
  1566. if (String == NULL) {
  1567. LsaString->Buffer = NULL;
  1568. LsaString->Length = 0;
  1569. LsaString->MaximumLength = 0;
  1570. return;
  1571. }
  1572. StringLength = lstrlenW(String);
  1573. LsaString->Buffer = String;
  1574. LsaString->Length = (USHORT) StringLength * sizeof(WCHAR);
  1575. LsaString->MaximumLength = (USHORT) (StringLength + 1) * sizeof(WCHAR);
  1576. }
  1577. #endif
  1578. #ifdef NTONLY
  1579. NTSTATUS CNetAPI32::OpenPolicy( CAdvApi32Api * a_padvapi , LPWSTR ServerName, DWORD DesiredAccess, PLSA_HANDLE PolicyHandle)
  1580. {
  1581. LSA_OBJECT_ATTRIBUTES ObjectAttributes;
  1582. LSA_UNICODE_STRING ServerString;
  1583. PLSA_UNICODE_STRING Server;
  1584. //
  1585. // Always initialize the object attributes to all zeroes
  1586. //
  1587. ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
  1588. if(ServerName != NULL)
  1589. {
  1590. //
  1591. // Make a LSA_UNICODE_STRING out of the LPWSTR passed in
  1592. //
  1593. InitLsaString(&ServerString, ServerName);
  1594. Server = &ServerString;
  1595. }
  1596. else
  1597. {
  1598. Server = NULL;
  1599. }
  1600. //
  1601. // Attempt to open the policy
  1602. //
  1603. return a_padvapi->LsaOpenPolicy(
  1604. Server,
  1605. &ObjectAttributes,
  1606. DesiredAccess,
  1607. PolicyHandle
  1608. );
  1609. }
  1610. #endif
  1611. bool CNetAPI32::AlreadyAddedToList(std::vector<_bstr_t> &vecbstrtList, _bstr_t &bstrtItem)
  1612. {
  1613. _bstr_t t_bstrtTemp1;
  1614. _bstr_t t_bstrtTemp2;
  1615. for(LONG m = 0; m < vecbstrtList.size(); m++)
  1616. {
  1617. t_bstrtTemp1 = _tcsupr((LPTSTR)vecbstrtList[m]);
  1618. t_bstrtTemp2 = _tcsupr((LPTSTR)bstrtItem);
  1619. if(t_bstrtTemp1 == t_bstrtTemp2)
  1620. {
  1621. return TRUE;
  1622. }
  1623. }
  1624. return FALSE;
  1625. }
  1626. #ifdef NTONLY
  1627. BOOL CNetAPI32::DsRolepGetPrimaryDomainInformationDownlevel
  1628. (
  1629. DSROLE_MACHINE_ROLE &a_rMachineRole,
  1630. DWORD &a_rdwWin32Err
  1631. )
  1632. {
  1633. a_rdwWin32Err = ERROR_SUCCESS ;
  1634. BOOL t_bRet = FALSE ;
  1635. NTSTATUS t_Status ;
  1636. LSA_HANDLE t_hPolicyHandle = NULL ;
  1637. PPOLICY_PRIMARY_DOMAIN_INFO t_pPDI = NULL ;
  1638. PPOLICY_LSA_SERVER_ROLE_INFO t_pServerRole = NULL ;
  1639. PPOLICY_ACCOUNT_DOMAIN_INFO t_pADI = NULL ;
  1640. NT_PRODUCT_TYPE t_ProductType ;
  1641. a_rMachineRole = DsRole_RoleStandaloneServer ;
  1642. CAdvApi32Api *t_padvapi = (CAdvApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidAdvApi32Api, NULL) ;
  1643. if( t_padvapi == NULL)
  1644. {
  1645. return FALSE;
  1646. }
  1647. try
  1648. {
  1649. if ( !DsRolepGetProductTypeForServer ( t_ProductType , a_rdwWin32Err ) )
  1650. {
  1651. if ( a_rdwWin32Err == ERROR_SUCCESS )
  1652. {
  1653. a_rdwWin32Err = ERROR_UNKNOWN_PRODUCT ;
  1654. }
  1655. return t_bRet ;
  1656. }
  1657. {
  1658. t_Status = OpenPolicy (
  1659. t_padvapi ,
  1660. NULL ,
  1661. POLICY_VIEW_LOCAL_INFORMATION ,
  1662. &t_hPolicyHandle
  1663. );
  1664. }
  1665. if ( NT_SUCCESS( t_Status ) )
  1666. {
  1667. {
  1668. t_Status = t_padvapi->LsaQueryInformationPolicy (
  1669. t_hPolicyHandle ,
  1670. PolicyPrimaryDomainInformation ,
  1671. ( PVOID * ) &t_pPDI
  1672. ) ;
  1673. }
  1674. if ( NT_SUCCESS ( t_Status ) )
  1675. {
  1676. switch ( t_ProductType )
  1677. {
  1678. case NtProductWinNt:
  1679. {
  1680. t_bRet = TRUE ;
  1681. if ( t_pPDI->Sid == NULL )
  1682. {
  1683. a_rMachineRole = DsRole_RoleStandaloneWorkstation ;
  1684. }
  1685. else
  1686. {
  1687. a_rMachineRole = DsRole_RoleMemberWorkstation ;
  1688. }
  1689. break;
  1690. }
  1691. case NtProductServer:
  1692. {
  1693. t_bRet = TRUE ;
  1694. if ( t_pPDI->Sid == NULL )
  1695. {
  1696. a_rMachineRole = DsRole_RoleStandaloneServer ;
  1697. }
  1698. else
  1699. {
  1700. a_rMachineRole = DsRole_RoleMemberServer ;
  1701. }
  1702. break;
  1703. }
  1704. case NtProductLanManNt:
  1705. {
  1706. {
  1707. t_Status = t_padvapi->LsaQueryInformationPolicy (
  1708. t_hPolicyHandle ,
  1709. PolicyLsaServerRoleInformation ,
  1710. ( PVOID * )&t_pServerRole
  1711. ) ;
  1712. }
  1713. if ( NT_SUCCESS( t_Status ) )
  1714. {
  1715. if ( t_pServerRole->LsaServerRole == PolicyServerRolePrimary )
  1716. {
  1717. {
  1718. //
  1719. // If we think we're a primary domain controller, we'll need to
  1720. // guard against the case where we're actually standalone during setup
  1721. //
  1722. t_Status = t_padvapi->LsaQueryInformationPolicy (
  1723. t_hPolicyHandle,
  1724. PolicyAccountDomainInformation ,
  1725. ( PVOID * )&t_pADI
  1726. ) ;
  1727. }
  1728. if ( NT_SUCCESS( t_Status ) )
  1729. {
  1730. t_bRet = TRUE ;
  1731. if ( t_pPDI->Sid == NULL ||
  1732. t_pADI->DomainSid == NULL ||
  1733. ! EqualSid ( t_pADI->DomainSid, t_pPDI->Sid )
  1734. )
  1735. {
  1736. a_rMachineRole = DsRole_RoleStandaloneServer ;
  1737. }
  1738. else
  1739. {
  1740. a_rMachineRole = DsRole_RolePrimaryDomainController ;
  1741. }
  1742. }
  1743. }
  1744. else
  1745. {
  1746. t_bRet = TRUE ;
  1747. a_rMachineRole = DsRole_RoleBackupDomainController;
  1748. }
  1749. }
  1750. break;
  1751. }
  1752. default:
  1753. {
  1754. t_Status = STATUS_INVALID_PARAMETER;
  1755. break;
  1756. }
  1757. }
  1758. }
  1759. if ( t_hPolicyHandle )
  1760. {
  1761. t_padvapi->LsaClose ( t_hPolicyHandle ) ;
  1762. t_hPolicyHandle = NULL ;
  1763. }
  1764. if ( t_pPDI )
  1765. {
  1766. t_padvapi->LsaFreeMemory ( t_pPDI ) ;
  1767. t_pPDI = NULL ;
  1768. }
  1769. if ( t_pADI != NULL )
  1770. {
  1771. t_padvapi->LsaFreeMemory( t_pADI ) ;
  1772. t_pADI = NULL ;
  1773. }
  1774. if ( t_pServerRole != NULL )
  1775. {
  1776. t_padvapi->LsaFreeMemory( t_pServerRole ) ;
  1777. }
  1778. }
  1779. a_rdwWin32Err = t_padvapi->LsaNtStatusToWinError( t_Status ) ;
  1780. if ( t_padvapi )
  1781. {
  1782. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1783. t_padvapi = NULL ;
  1784. }
  1785. return t_bRet ;
  1786. }
  1787. catch ( ... )
  1788. {
  1789. if ( t_hPolicyHandle )
  1790. {
  1791. t_padvapi->LsaClose ( t_hPolicyHandle ) ;
  1792. t_hPolicyHandle = NULL ;
  1793. }
  1794. if ( t_pPDI )
  1795. {
  1796. t_padvapi->LsaFreeMemory ( t_pPDI ) ;
  1797. t_pPDI = NULL ;
  1798. }
  1799. if ( t_pADI != NULL )
  1800. {
  1801. t_padvapi->LsaFreeMemory( t_pADI ) ;
  1802. t_pADI = NULL ;
  1803. }
  1804. if ( t_pServerRole != NULL )
  1805. {
  1806. t_padvapi->LsaFreeMemory( t_pServerRole ) ;
  1807. }
  1808. if ( t_padvapi )
  1809. {
  1810. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidAdvApi32Api, t_padvapi ) ;
  1811. t_padvapi = NULL ;
  1812. }
  1813. throw ;
  1814. }
  1815. }
  1816. /*
  1817. * This function will return true if it succeeds. If the return value is false & the Win32 error code in a_rdwWin32Err parameter
  1818. * is ERROR_SUCCESS, that means we don't know what the product type is
  1819. */
  1820. BOOL CNetAPI32::DsRolepGetProductTypeForServer
  1821. (
  1822. NT_PRODUCT_TYPE &a_rProductType ,
  1823. DWORD &a_rdwWin32Err
  1824. )
  1825. {
  1826. HKEY t_hProductKey = NULL ;
  1827. PBYTE t_pBuffer = NULL;
  1828. ULONG t_lType, t_lSize = 0;
  1829. BOOL t_bRet = FALSE ;
  1830. try
  1831. {
  1832. a_rdwWin32Err = RegOpenKeyEx (
  1833. HKEY_LOCAL_MACHINE,
  1834. L"system\\currentcontrolset\\control\\productoptions",
  1835. 0,
  1836. KEY_READ,
  1837. &t_hProductKey
  1838. ) ;
  1839. if ( a_rdwWin32Err == ERROR_SUCCESS )
  1840. {
  1841. a_rdwWin32Err = RegQueryValueEx (
  1842. t_hProductKey,
  1843. L"ProductType",
  1844. 0,
  1845. &t_lType,
  1846. 0,
  1847. &t_lSize
  1848. ) ;
  1849. if ( a_rdwWin32Err == ERROR_SUCCESS )
  1850. {
  1851. t_pBuffer = new BYTE [t_lSize] ;
  1852. if ( t_pBuffer )
  1853. {
  1854. a_rdwWin32Err = RegQueryValueEx(
  1855. t_hProductKey,
  1856. L"ProductType",
  1857. 0,
  1858. &t_lType,
  1859. t_pBuffer,
  1860. &t_lSize
  1861. ) ;
  1862. if ( a_rdwWin32Err == ERROR_SUCCESS )
  1863. {
  1864. t_bRet = TRUE ;
  1865. if ( !_wcsicmp( ( PWSTR )t_pBuffer, L"LanmanNt" ) )
  1866. {
  1867. a_rProductType = NtProductLanManNt;
  1868. }
  1869. else if ( !_wcsicmp( ( PWSTR )t_pBuffer, L"ServerNt" ) )
  1870. {
  1871. a_rProductType = NtProductServer;
  1872. }
  1873. else if ( !_wcsicmp( ( PWSTR )t_pBuffer, L"WinNt" ) )
  1874. {
  1875. a_rProductType = NtProductWinNt;
  1876. }
  1877. else
  1878. {
  1879. t_bRet = FALSE ;
  1880. }
  1881. }
  1882. delete [] t_pBuffer;
  1883. t_pBuffer = NULL ;
  1884. }
  1885. else
  1886. {
  1887. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  1888. }
  1889. }
  1890. RegCloseKey ( t_hProductKey ) ;
  1891. t_hProductKey = NULL ;
  1892. }
  1893. return t_bRet ;
  1894. }
  1895. catch ( ... )
  1896. {
  1897. if ( t_hProductKey )
  1898. {
  1899. RegCloseKey ( t_hProductKey ) ;
  1900. t_hProductKey = NULL ;
  1901. }
  1902. if ( t_pBuffer )
  1903. {
  1904. delete [] t_pBuffer ;
  1905. t_pBuffer = NULL ;
  1906. }
  1907. throw ;
  1908. }
  1909. }
  1910. #endif
  1911. #ifdef NTONLY
  1912. DWORD CNetAPI32::GetDCName(
  1913. LPCWSTR wstrDomain,
  1914. CHString& chstrDCName)
  1915. {
  1916. DWORD dwRet = ERROR_SUCCESS;
  1917. #if NTONLY < 5
  1918. LPBYTE lpbBuff = NULL;
  1919. dwRet = NetGetDCName(
  1920. NULL,
  1921. wstrDomain,
  1922. &lpbBuff);
  1923. if(dwRet == NO_ERROR)
  1924. {
  1925. try
  1926. {
  1927. chstrDCName = (LPCWSTR)lpbBuff;
  1928. }
  1929. catch(...)
  1930. {
  1931. NetApiBufferFree(lpbBuff);
  1932. lpbBuff = NULL;
  1933. throw;
  1934. }
  1935. NetApiBufferFree(lpbBuff);
  1936. lpbBuff = NULL;
  1937. }
  1938. else
  1939. {
  1940. dwRet = NetGetAnyDCName(
  1941. NULL,
  1942. _bstr_t(wstrDomain),
  1943. &lpbBuff);
  1944. if(dwRet == NO_ERROR)
  1945. {
  1946. try
  1947. {
  1948. chstrDCName = (LPCWSTR)lpbBuff;
  1949. }
  1950. catch(...)
  1951. {
  1952. NetApiBufferFree(lpbBuff);
  1953. lpbBuff = NULL;
  1954. throw;
  1955. }
  1956. NetApiBufferFree(lpbBuff);
  1957. lpbBuff = NULL;
  1958. }
  1959. }
  1960. #else
  1961. PDOMAIN_CONTROLLER_INFO pDomInfo = NULL;
  1962. dwRet = DsGetDcName(
  1963. NULL,
  1964. wstrDomain,
  1965. NULL,
  1966. NULL,
  1967. /*DS_PDC_REQUIRED*/ 0,
  1968. &pDomInfo);
  1969. if(dwRet != NO_ERROR)
  1970. {
  1971. dwRet = DsGetDcName(
  1972. NULL,
  1973. wstrDomain,
  1974. NULL,
  1975. NULL,
  1976. /*DS_PDC_REQUIRED | */ DS_FORCE_REDISCOVERY,
  1977. &pDomInfo);
  1978. }
  1979. if(dwRet == NO_ERROR)
  1980. {
  1981. try
  1982. {
  1983. chstrDCName = pDomInfo->DomainControllerName;
  1984. }
  1985. catch(...)
  1986. {
  1987. NetApiBufferFree(pDomInfo);
  1988. pDomInfo = NULL;
  1989. throw;
  1990. }
  1991. NetApiBufferFree(pDomInfo);
  1992. pDomInfo = NULL;
  1993. }
  1994. #endif
  1995. return dwRet;
  1996. }
  1997. #endif