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.

1090 lines
27 KiB

  1. /******************************************************************
  2. DfsJnPt.CPP -- WMI provider class implementation
  3. Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  4. Description: Win32 Dfs Provider
  5. ******************************************************************/
  6. #include "precomp.h"
  7. #include <computerAPI.h>
  8. CDfsJnPt MyDfsTable (
  9. PROVIDER_NAME_DFSJNPT ,
  10. Namespace
  11. ) ;
  12. /*****************************************************************************
  13. *
  14. * FUNCTION : CDfsJnPt::CDfsJnPt
  15. *
  16. * DESCRIPTION : Constructor
  17. *
  18. *****************************************************************************/
  19. CDfsJnPt :: CDfsJnPt (
  20. LPCWSTR lpwszName,
  21. LPCWSTR lpwszNameSpace
  22. ) : Provider ( lpwszName , lpwszNameSpace )
  23. {
  24. m_ComputerName = GetLocalComputerName();
  25. }
  26. /*****************************************************************************
  27. *
  28. * FUNCTION : CDfsJnPt::~CDfsJnPt
  29. *
  30. * DESCRIPTION : Destructor
  31. *
  32. *****************************************************************************/
  33. CDfsJnPt :: ~CDfsJnPt ()
  34. {
  35. }
  36. /*****************************************************************************
  37. *
  38. * FUNCTION : CDfsJnPt::EnumerateInstances
  39. *
  40. * DESCRIPTION : Returns all the instances of this class.
  41. *
  42. *****************************************************************************/
  43. HRESULT CDfsJnPt :: EnumerateInstances (
  44. MethodContext *pMethodContext,
  45. long lFlags
  46. )
  47. {
  48. HRESULT hRes = WBEM_S_NO_ERROR ;
  49. DWORD dwPropertiesReq = DFSJNPT_ALL_PROPS;
  50. hRes = EnumerateAllJnPts ( pMethodContext, dwPropertiesReq );
  51. return hRes;
  52. }
  53. /*****************************************************************************
  54. *
  55. * FUNCTION : CDfsJnPt::GetObject
  56. *
  57. * DESCRIPTION : Find a single instance based on the key properties for the
  58. * class.
  59. *
  60. *****************************************************************************/
  61. HRESULT CDfsJnPt :: GetObject (
  62. CInstance *pInstance,
  63. long lFlags ,
  64. CFrameworkQuery &Query
  65. )
  66. {
  67. HRESULT hRes = WBEM_S_NO_ERROR;
  68. DWORD dwPropertiesReq = 0;
  69. CHString t_Key ;
  70. if ( pInstance->GetCHString ( DFSNAME , t_Key ) == FALSE )
  71. {
  72. hRes = WBEM_E_INVALID_PARAMETER ;
  73. }
  74. if ( SUCCEEDED ( hRes ) )
  75. {
  76. if ( Query.AllPropertiesAreRequired() )
  77. {
  78. dwPropertiesReq = DFSJNPT_ALL_PROPS;
  79. }
  80. else
  81. {
  82. SetRequiredProperties ( Query, dwPropertiesReq );
  83. }
  84. hRes = FindAndSetDfsEntry ( t_Key, dwPropertiesReq, pInstance, eGet );
  85. }
  86. return hRes ;
  87. }
  88. /*****************************************************************************
  89. *
  90. * FUNCTION : CDfsJnPt::PutInstance
  91. *
  92. * DESCRIPTION : Adding a Instance if it already doesnt exist, or modify it
  93. * if it already exists, based on the kind of operation requested
  94. *
  95. *****************************************************************************/
  96. HRESULT CDfsJnPt :: PutInstance (
  97. const CInstance &Instance,
  98. long lFlags
  99. )
  100. {
  101. HRESULT hRes = WBEM_E_FAILED ;
  102. CHString t_Key ;
  103. DWORD dwOperation;
  104. if ( Instance.GetCHString ( DFSNAME , t_Key ) )
  105. {
  106. hRes = WBEM_S_NO_ERROR;
  107. DWORD dwPossibleOperations = 0;
  108. dwPossibleOperations = (WBEM_FLAG_CREATE_OR_UPDATE | WBEM_FLAG_UPDATE_ONLY | WBEM_FLAG_CREATE_ONLY);
  109. switch ( lFlags & dwPossibleOperations )
  110. {
  111. case WBEM_FLAG_CREATE_OR_UPDATE:
  112. {
  113. dwOperation = eUpdate;
  114. break;
  115. }
  116. case WBEM_FLAG_UPDATE_ONLY:
  117. {
  118. dwOperation = eModify;
  119. break;
  120. }
  121. case WBEM_FLAG_CREATE_ONLY:
  122. {
  123. hRes = WBEM_E_INVALID_PARAMETER;
  124. break;
  125. }
  126. }
  127. }
  128. if ( SUCCEEDED ( hRes ) )
  129. {
  130. // This call is made with 2nd parameter 0, indicating that it should not load an instance
  131. // with any parameter, it should simple search.
  132. hRes = FindAndSetDfsEntry ( t_Key, 0, NULL, eGet );
  133. if ( SUCCEEDED ( hRes ) || ( hRes == WBEM_E_NOT_FOUND ) )
  134. {
  135. switch ( dwOperation )
  136. {
  137. case eModify:
  138. {
  139. if ( SUCCEEDED ( hRes ) )
  140. {
  141. hRes = UpdateDfsJnPt ( Instance, eModify );
  142. break;
  143. }
  144. }
  145. case eAdd:
  146. {
  147. hRes = WBEM_E_INVALID_PARAMETER;
  148. break; // Create not currently supported
  149. }
  150. case eUpdate:
  151. {
  152. if ( hRes == WBEM_E_NOT_FOUND )
  153. {
  154. hRes = WBEM_E_INVALID_PARAMETER; // Create not currently supported
  155. }
  156. else
  157. {
  158. hRes = UpdateDfsJnPt ( Instance, eModify );
  159. }
  160. break;
  161. }
  162. }
  163. }
  164. }
  165. return hRes ;
  166. }
  167. /*****************************************************************************
  168. *
  169. * FUNCTION : CDfsJnPt::CheckParameters
  170. *
  171. * DESCRIPTION : Performs the validity checks of the parameters to add/modify
  172. * the Dfs Jn Pts.
  173. *
  174. *****************************************************************************/
  175. HRESULT CDfsJnPt :: CheckParameters (
  176. const CInstance &a_Instance ,
  177. int a_State
  178. )
  179. {
  180. // Getall the Properties from the Instance to Verify
  181. bool t_Exists ;
  182. VARTYPE t_Type ;
  183. HRESULT hr = WBEM_S_NO_ERROR ;
  184. if ( a_State != WBEM_E_ALREADY_EXISTS )
  185. {
  186. // need to validate the dfsEntryPath, if it already exists, means it was already verified and was in DFS tree and
  187. // hence need not verify
  188. if ( a_Instance.GetStatus ( DFSNAME , t_Exists , t_Type ) )
  189. {
  190. if ( t_Exists && ( t_Type == VT_BSTR ) )
  191. {
  192. CHString t_DfsEntryPath;
  193. if ( a_Instance.GetCHString ( DFSNAME , t_DfsEntryPath ) && ! t_DfsEntryPath.IsEmpty () )
  194. {
  195. }
  196. else
  197. {
  198. // Zero Length string
  199. hr = WBEM_E_INVALID_PARAMETER ;
  200. }
  201. }
  202. else
  203. {
  204. hr = WBEM_E_INVALID_PARAMETER ;
  205. }
  206. }
  207. }
  208. if ( SUCCEEDED ( hr ) )
  209. {
  210. if ( a_Instance.GetStatus ( STATE , t_Exists , t_Type ) )
  211. {
  212. if ( t_Exists && ( t_Type == VT_I4 ) )
  213. {
  214. DWORD dwState;
  215. if ( a_Instance.GetDWORD ( STATE, dwState ) )
  216. {
  217. if (( dwState != 0 ) && ( dwState != 1 ) && ( dwState != 2 ) && ( dwState != 3 ) )
  218. {
  219. hr = WBEM_E_INVALID_PARAMETER;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. if ( SUCCEEDED ( hr ) )
  226. {
  227. if ( a_Instance.GetStatus ( TIMEOUT , t_Exists , t_Type ) )
  228. {
  229. if ( t_Exists )
  230. {
  231. if ( t_Type != VT_I4 )
  232. {
  233. hr = WBEM_E_INVALID_PARAMETER;
  234. }
  235. }
  236. }
  237. }
  238. return hr;
  239. }
  240. /*****************************************************************************
  241. *
  242. * FUNCTION : CDfsJnPt:: DeleteInstance
  243. *
  244. * DESCRIPTION : Deleting a Dfs Jn Pt if it exists
  245. *
  246. *****************************************************************************/
  247. HRESULT CDfsJnPt :: DeleteInstance (
  248. const CInstance &Instance,
  249. long lFlags
  250. )
  251. {
  252. HRESULT hRes = WBEM_S_NO_ERROR ;
  253. CHString t_Key ;
  254. NET_API_STATUS t_Status = NERR_Success;
  255. if ( Instance.GetCHString ( DFSNAME , t_Key ) == FALSE )
  256. {
  257. hRes = WBEM_E_INVALID_PARAMETER;
  258. }
  259. if ( SUCCEEDED ( hRes ) )
  260. {
  261. hRes = FindAndSetDfsEntry ( t_Key, 0, NULL, eDelete );
  262. }
  263. return hRes ;
  264. }
  265. /*****************************************************************************
  266. *
  267. * FUNCTION : CDfsJnPt::EnumerateAllJnPts
  268. *
  269. * DESCRIPTION : Enumerates all the Junction points and calls the method to load
  270. * Instance and then commit
  271. *
  272. ******************************************************************************/
  273. HRESULT CDfsJnPt::EnumerateAllJnPts ( MethodContext *pMethodContext, DWORD dwPropertiesReq )
  274. {
  275. HRESULT hRes = WBEM_S_NO_ERROR;
  276. PDFS_INFO_300 pData300 = NULL;
  277. DWORD er300 = 0;
  278. DWORD tr300 = 0;
  279. // Call the NetDfsEnum function, specifying level 300.
  280. DWORD res = NetDfsEnum( m_ComputerName.GetBuffer ( 0 ), 300, -1, (LPBYTE *) &pData300, &er300, &tr300 );
  281. // If no error occurred,
  282. if(res==NERR_Success)
  283. {
  284. if ( pData300 != NULL )
  285. {
  286. try
  287. {
  288. PDFS_INFO_300 p300 = pData300;
  289. CInstancePtr pInstance;
  290. for ( int i = 0; (i < er300) && SUCCEEDED( hRes ); i++, p300++ )
  291. {
  292. DWORD er4 = 0;
  293. DWORD tr4 = 0;
  294. PDFS_INFO_4 pData4 = NULL;
  295. if (p300->DfsName != NULL)
  296. {
  297. if ( ( res = NetDfsEnum(p300->DfsName, 4, -1, (LPBYTE *) &pData4, &er4, &tr4) ) == NERR_Success)
  298. {
  299. if ( pData4 != NULL )
  300. {
  301. try
  302. {
  303. PDFS_INFO_4 p4 = pData4;
  304. for ( int j = 0; (j < er4) && SUCCEEDED ( hRes ); j++, p4++ )
  305. {
  306. pInstance.Attach(CreateNewInstance( pMethodContext ));
  307. hRes = LoadDfsJnPt ( dwPropertiesReq, pInstance, p4, p4 == pData4 );
  308. if ( SUCCEEDED ( hRes ) )
  309. {
  310. hRes = pInstance->Commit();
  311. }
  312. }
  313. }
  314. catch(...)
  315. {
  316. NetApiBufferFree(pData4);
  317. pData4 = NULL;
  318. throw;
  319. }
  320. NetApiBufferFree(pData4);
  321. pData4 = NULL;
  322. }
  323. }
  324. // Check to see if there are ANY roots
  325. else if (
  326. (res != ERROR_NO_MORE_ITEMS) &&
  327. (res != ERROR_NO_SUCH_DOMAIN) &&
  328. (res != ERROR_NOT_FOUND) &&
  329. (res != ERROR_ACCESS_DENIED)
  330. )
  331. {
  332. hRes = WBEM_E_FAILED;
  333. }
  334. }
  335. }
  336. }
  337. catch ( ... )
  338. {
  339. NetApiBufferFree(pData300);
  340. pData300 = NULL;
  341. throw;
  342. }
  343. NetApiBufferFree(pData300);
  344. pData300 = NULL;
  345. }
  346. }
  347. else if ( (res != ERROR_NO_MORE_ITEMS) && (res != ERROR_NO_SUCH_DOMAIN) && (res != ERROR_NOT_FOUND) ) // Check to see if there are ANY roots
  348. {
  349. if ( ERROR_ACCESS_DENIED == res )
  350. {
  351. hRes = WBEM_E_ACCESS_DENIED ;
  352. }
  353. else
  354. {
  355. hRes = WBEM_E_FAILED ;
  356. }
  357. }
  358. return hRes;
  359. }
  360. /*****************************************************************************
  361. *
  362. * FUNCTION : CDfsJnPt::FindAndSetDfsEntry
  363. *
  364. * DESCRIPTION : Finds an entry matching the dfsEntryPath and loads the
  365. * Instance if found or acts based on the Operation passed
  366. *
  367. ******************************************************************************/
  368. HRESULT CDfsJnPt::FindAndSetDfsEntry ( LPCWSTR a_Key, DWORD dwPropertiesReq, CInstance *pInstance, DWORD eOperation )
  369. {
  370. HRESULT hRes = WBEM_E_NOT_FOUND;
  371. PDFS_INFO_300 pData300 = NULL;
  372. DWORD er300 = 0;
  373. DWORD tr300 = 0;
  374. DWORD res = NERR_Success;
  375. // Call the NetDfsEnum function, specifying level 300.
  376. if( ( res = NetDfsEnum( m_ComputerName.GetBuffer ( 0 ), 300, -1, (LPBYTE *) &pData300, &er300, &tr300 ) ) == NERR_Success )
  377. {
  378. if ( pData300 != NULL )
  379. {
  380. try
  381. {
  382. BOOL bContinue = TRUE;
  383. PDFS_INFO_300 p300 = pData300;
  384. for ( int i = 0; (i < er300) && bContinue; i++, p300++ )
  385. {
  386. if ( p300->DfsName != NULL )
  387. {
  388. PDFS_INFO_4 pData4 = NULL;
  389. DWORD er4=0;
  390. DWORD tr4=0;
  391. if ( ( res = NetDfsEnum(p300->DfsName, 4, -1, (LPBYTE *) &pData4, &er4, &tr4) ) == NERR_Success )
  392. {
  393. if ( pData4 != NULL )
  394. {
  395. try
  396. {
  397. BOOL bFound = FALSE;
  398. PDFS_INFO_4 p4 = pData4;
  399. for ( int j = 0; (j < er4) && bContinue; j++, bContinue && (j < er4) ? p4++ : p4 )
  400. {
  401. if ( _wcsicmp ( a_Key, p4->EntryPath ) == 0 )
  402. {
  403. bFound = TRUE;
  404. bContinue = FALSE;
  405. }
  406. }
  407. if ( bFound )
  408. {
  409. switch ( eOperation )
  410. {
  411. case eGet :
  412. {
  413. hRes = LoadDfsJnPt ( dwPropertiesReq, pInstance, p4, p4 == pData4 );
  414. break;
  415. }
  416. case eDelete:
  417. {
  418. hRes = DeleteDfsJnPt ( p4 );
  419. break;
  420. }
  421. }
  422. }
  423. }
  424. catch(...)
  425. {
  426. NetApiBufferFree(pData4);
  427. pData4 = NULL;
  428. throw;
  429. }
  430. NetApiBufferFree(pData4);
  431. pData4 = NULL;
  432. }
  433. }
  434. // Check to see if there are ANY roots
  435. else if (
  436. (res != ERROR_NO_MORE_ITEMS) &&
  437. (res != ERROR_NO_SUCH_DOMAIN) &&
  438. (res != ERROR_NOT_FOUND) &&
  439. (res != ERROR_ACCESS_DENIED)
  440. )
  441. {
  442. hRes = WBEM_E_FAILED;
  443. bContinue = FALSE;
  444. }
  445. }
  446. }
  447. }
  448. catch ( ... )
  449. {
  450. NetApiBufferFree(pData300);
  451. pData300 = NULL;
  452. throw;
  453. }
  454. NetApiBufferFree(pData300);
  455. pData300 = NULL;
  456. }
  457. }
  458. else if ( (res != ERROR_NO_MORE_ITEMS) && (res != ERROR_NO_SUCH_DOMAIN) && (res != ERROR_NOT_FOUND) ) // Check to see if there are ANY roots
  459. {
  460. if ( ERROR_ACCESS_DENIED == res )
  461. {
  462. hRes = WBEM_E_ACCESS_DENIED ;
  463. }
  464. else
  465. {
  466. hRes = WBEM_E_FAILED ;
  467. }
  468. }
  469. return hRes;
  470. }
  471. /*****************************************************************************
  472. *
  473. * FUNCTION : CDfsJnPt::LoadDfsJnPt
  474. *
  475. * DESCRIPTION : Loads a Dfs Junction point entry into the instance
  476. *
  477. ******************************************************************************/
  478. HRESULT CDfsJnPt::LoadDfsJnPt ( DWORD dwPropertiesReq, CInstance *pInstance, PDFS_INFO_4 pJnPtBuf, bool bRoot )
  479. {
  480. HRESULT hRes = WBEM_S_NO_ERROR;
  481. if (NULL != pInstance)
  482. {
  483. if ( dwPropertiesReq & DFSJNPT_PROP_DfsEntryPath )
  484. {
  485. if ( pInstance->SetWCHARSplat ( DFSNAME, pJnPtBuf->EntryPath ) == FALSE )
  486. {
  487. hRes = WBEM_E_FAILED;
  488. }
  489. }
  490. if ( pInstance->Setbool ( L"Root", bRoot ) == FALSE )
  491. {
  492. hRes = WBEM_E_FAILED;
  493. }
  494. if ( dwPropertiesReq & DFSJNPT_PROP_State )
  495. {
  496. // need to check the state and then valuemap
  497. DWORD dwState = 0;
  498. switch ( pJnPtBuf->State )
  499. {
  500. case DFS_VOLUME_STATE_OK :
  501. {
  502. dwState = 0;
  503. break;
  504. }
  505. case DFS_VOLUME_STATE_INCONSISTENT :
  506. {
  507. dwState = 1;
  508. break;
  509. }
  510. case DFS_VOLUME_STATE_ONLINE :
  511. {
  512. dwState = 2;
  513. break;
  514. }
  515. case DFS_VOLUME_STATE_OFFLINE :
  516. {
  517. dwState = 3;
  518. break;
  519. }
  520. }
  521. if ( pInstance->SetDWORD ( STATE, dwState ) == FALSE )
  522. {
  523. hRes = WBEM_E_FAILED;
  524. }
  525. }
  526. if ( dwPropertiesReq & DFSJNPT_PROP_Comment )
  527. {
  528. if ( pInstance->SetWCHARSplat ( COMMENT, pJnPtBuf->Comment ) == FALSE )
  529. {
  530. hRes = WBEM_E_FAILED;
  531. }
  532. }
  533. if ( dwPropertiesReq & DFSJNPT_PROP_Caption )
  534. {
  535. if ( pInstance->SetWCHARSplat ( CAPTION, pJnPtBuf->Comment ) == FALSE )
  536. {
  537. hRes = WBEM_E_FAILED;
  538. }
  539. }
  540. if ( dwPropertiesReq & DFSJNPT_PROP_Timeout )
  541. {
  542. if ( pInstance->SetDWORD ( TIMEOUT, pJnPtBuf->Timeout ) == FALSE )
  543. {
  544. hRes = WBEM_E_FAILED;
  545. }
  546. }
  547. }
  548. else
  549. {
  550. if (0 != dwPropertiesReq)
  551. {
  552. hRes = WBEM_E_FAILED;
  553. }
  554. }
  555. return hRes;
  556. }
  557. /*****************************************************************************
  558. *
  559. * FUNCTION : CDfsJnPt::DeleteDfsJnPt
  560. *
  561. * DESCRIPTION : Deletes a Junction Pt if it exists
  562. *
  563. ******************************************************************************/
  564. HRESULT CDfsJnPt::DeleteDfsJnPt ( PDFS_INFO_4 pDfsJnPt )
  565. {
  566. HRESULT hRes = WBEM_S_NO_ERROR;
  567. NET_API_STATUS t_Status = NERR_Success;
  568. if ( IsDfsRoot ( pDfsJnPt->EntryPath ) )
  569. {
  570. if ((wcslen(pDfsJnPt->EntryPath) > 4) &&
  571. (pDfsJnPt->EntryPath[0] == pDfsJnPt->EntryPath[1]) &&
  572. (pDfsJnPt->EntryPath[0] == L'\\'))
  573. {
  574. wchar_t *pSlash = wcschr(&(pDfsJnPt->EntryPath[2]), L'\\');
  575. if (pSlash > &(pDfsJnPt->EntryPath[2]))
  576. {
  577. wchar_t *pServer = new wchar_t[pSlash - &(pDfsJnPt->EntryPath[2]) + 1];
  578. BOOL bRemove = FALSE;
  579. try
  580. {
  581. wcsncpy(pServer, &(pDfsJnPt->EntryPath[2]), pSlash - &(pDfsJnPt->EntryPath[2]));
  582. pServer[pSlash - &(pDfsJnPt->EntryPath[2])] = L'\0';
  583. if (0 == m_ComputerName.CompareNoCase(pServer))
  584. {
  585. bRemove = TRUE;
  586. }
  587. else
  588. {
  589. DWORD dwDnsName = 256;
  590. DWORD dwDnsNameSize = 256;
  591. wchar_t *pDnsName = new wchar_t[dwDnsName];
  592. try
  593. {
  594. while (!ProviderGetComputerNameEx(ComputerNamePhysicalDnsHostname, pDnsName, &dwDnsName))
  595. {
  596. if (GetLastError() != ERROR_MORE_DATA)
  597. {
  598. delete [] pDnsName;
  599. pDnsName = NULL;
  600. break;
  601. }
  602. else
  603. {
  604. delete [] pDnsName;
  605. pDnsName = NULL;
  606. dwDnsName = dwDnsNameSize * 2;
  607. dwDnsNameSize = dwDnsName;
  608. pDnsName = new wchar_t[dwDnsName];
  609. }
  610. }
  611. }
  612. catch (...)
  613. {
  614. if (pDnsName)
  615. {
  616. delete [] pDnsName;
  617. pDnsName = NULL;
  618. }
  619. throw;
  620. }
  621. if (pDnsName)
  622. {
  623. if (_wcsicmp(pDnsName, pServer) == 0)
  624. {
  625. bRemove = TRUE;
  626. }
  627. delete [] pDnsName;
  628. pDnsName = NULL;
  629. }
  630. }
  631. }
  632. catch(...)
  633. {
  634. if (pServer)
  635. {
  636. delete [] pServer;
  637. }
  638. throw;
  639. }
  640. if (bRemove)
  641. {
  642. t_Status = NetDfsRemoveStdRoot ( pDfsJnPt->Storage->ServerName,
  643. pDfsJnPt->Storage->ShareName,
  644. 0
  645. );
  646. if ( t_Status != NERR_Success )
  647. {
  648. hRes = WBEM_E_FAILED;
  649. }
  650. }
  651. else
  652. {
  653. //can't delete roots not on this machine
  654. hRes = WBEM_E_PROVIDER_NOT_CAPABLE;
  655. }
  656. delete [] pServer;
  657. }
  658. else
  659. {
  660. hRes = WBEM_E_FAILED;
  661. }
  662. }
  663. else
  664. {
  665. hRes = WBEM_E_FAILED;
  666. }
  667. }
  668. else
  669. {
  670. // Apparently there is no way to explicitly remove a link. However, if
  671. // you remove all the replicas, the link gets deleted automatically.
  672. for ( int StorageNo = 0; StorageNo < pDfsJnPt->NumberOfStorages; StorageNo++ )
  673. {
  674. t_Status = NetDfsRemove (
  675. pDfsJnPt->EntryPath,
  676. pDfsJnPt->Storage[StorageNo].ServerName,
  677. pDfsJnPt->Storage[StorageNo].ShareName
  678. );
  679. if ( t_Status != NERR_Success )
  680. {
  681. hRes = WBEM_E_FAILED;
  682. break;
  683. }
  684. }
  685. }
  686. return hRes;
  687. }
  688. /*****************************************************************************
  689. *
  690. * FUNCTION : CDfsJnPt::UpdateDfsJnPt
  691. *
  692. * DESCRIPTION : Adds / Modifies the Dfs Jn Pt
  693. *
  694. ******************************************************************************/
  695. HRESULT CDfsJnPt::UpdateDfsJnPt ( const CInstance &Instance, DWORD dwOperation )
  696. {
  697. HRESULT hRes = WBEM_S_NO_ERROR;
  698. NET_API_STATUS t_Status = NERR_Success;
  699. if ( SUCCEEDED ( hRes ) )
  700. {
  701. NET_API_STATUS t_Status = NERR_Success;
  702. CHString t_EntryPath;
  703. Instance.GetCHString ( DFSNAME, t_EntryPath );
  704. if ( dwOperation == eAdd )
  705. {
  706. hRes = WBEM_E_INVALID_PARAMETER;
  707. }
  708. else
  709. if ( dwOperation == eModify )
  710. {
  711. CHString t_Comment;
  712. if (( t_Status == NERR_Success ) && (Instance.GetCHString ( COMMENT, t_Comment )))
  713. {
  714. DFS_INFO_100 t_dfsCommentData;
  715. t_dfsCommentData.Comment = t_Comment.GetBuffer( 0 );
  716. t_Status = NetDfsSetInfo ( t_EntryPath.GetBuffer ( 0 ),
  717. NULL,
  718. NULL,
  719. 100,
  720. (LPBYTE) &t_dfsCommentData
  721. );
  722. }
  723. if ( t_Status == NERR_Success )
  724. {
  725. DFS_INFO_102 t_dfsTimeoutData;
  726. if (Instance.GetDWORD ( TIMEOUT, t_dfsTimeoutData.Timeout))
  727. {
  728. t_Status = NetDfsSetInfo ( t_EntryPath.GetBuffer ( 0 ),
  729. NULL,
  730. NULL,
  731. 102,
  732. (LPBYTE) &t_dfsTimeoutData
  733. );
  734. }
  735. }
  736. }
  737. if ((SUCCEEDED(hRes)) && ( t_Status != NERR_Success ))
  738. {
  739. hRes = WBEM_E_FAILED ;
  740. }
  741. }
  742. return hRes;
  743. }
  744. /*****************************************************************************
  745. *
  746. * FUNCTION : CDfsJnPt::AddDfsJnPt
  747. *
  748. * DESCRIPTION : Adds the New Dfs Jn Pt
  749. *
  750. ******************************************************************************/
  751. NET_API_STATUS CDfsJnPt :: AddDfsJnPt (
  752. LPWSTR a_DfsEntry,
  753. LPWSTR a_ServerName,
  754. LPWSTR a_ShareName,
  755. LPWSTR a_Comment
  756. )
  757. {
  758. NET_API_STATUS t_Status = NERR_Success;
  759. wchar_t *t_slash = NULL;
  760. //simple analysis on the parameters...
  761. if ((a_ServerName == NULL) ||
  762. (a_ShareName == NULL) ||
  763. (a_ServerName[0] == L'\0') ||
  764. (a_ShareName[0] == L'\0') ||
  765. (a_DfsEntry == NULL) ||
  766. (wcslen(a_DfsEntry) < 5) ||
  767. (wcsncmp(a_DfsEntry, L"\\\\", 2) != 0))
  768. {
  769. t_Status = ERROR_INVALID_PARAMETER;
  770. }
  771. else
  772. {
  773. t_slash = wcschr((const wchar_t*)(&(a_DfsEntry[2])), L'\\');
  774. if ((t_slash == NULL) || (t_slash == &(a_DfsEntry[2])))
  775. {
  776. t_Status = ERROR_INVALID_PARAMETER;
  777. }
  778. else
  779. {
  780. //let's find the next slash if there is one...
  781. t_slash++;
  782. if ((*t_slash == L'\0') || (*t_slash == L'\\'))
  783. {
  784. t_Status = ERROR_INVALID_PARAMETER;
  785. }
  786. else
  787. {
  788. //if t_slash is null we have a root
  789. t_slash = wcschr(t_slash, L'\\');
  790. }
  791. }
  792. }
  793. if (t_Status == NERR_Success)
  794. {
  795. if ( t_slash )
  796. {
  797. // this is a a junction point other than the root
  798. t_Status = NetDfsAdd ( a_DfsEntry,
  799. a_ServerName,
  800. a_ShareName,
  801. a_Comment,
  802. DFS_ADD_VOLUME
  803. );
  804. }
  805. else
  806. {
  807. // it is DFSRoot
  808. DWORD dwErr = GetFileAttributes ( a_DfsEntry );
  809. if ( dwErr != 0xffffffff )
  810. {
  811. t_Status = NetDfsAddStdRoot ( a_ServerName,
  812. a_ShareName,
  813. a_Comment,
  814. 0
  815. );
  816. }
  817. else
  818. {
  819. t_Status = GetLastError();
  820. }
  821. }
  822. }
  823. return t_Status;
  824. }
  825. /*****************************************************************************
  826. *
  827. * FUNCTION : CDfsJnPt::SetRequiredProperties
  828. *
  829. * DESCRIPTION : Sets the bitmap for the required properties
  830. *
  831. ******************************************************************************/
  832. void CDfsJnPt::SetRequiredProperties ( CFrameworkQuery &Query, DWORD &dwPropertiesReq )
  833. {
  834. dwPropertiesReq = 0;
  835. if ( Query.IsPropertyRequired ( DFSNAME ) )
  836. {
  837. dwPropertiesReq |= DFSJNPT_PROP_DfsEntryPath;
  838. }
  839. if ( Query.IsPropertyRequired ( STATE ) )
  840. {
  841. dwPropertiesReq |= DFSJNPT_PROP_State;
  842. }
  843. if ( Query.IsPropertyRequired ( COMMENT ) )
  844. {
  845. dwPropertiesReq |= DFSJNPT_PROP_Comment;
  846. }
  847. if ( Query.IsPropertyRequired ( TIMEOUT ) )
  848. {
  849. dwPropertiesReq |= DFSJNPT_PROP_Timeout;
  850. }
  851. }
  852. /*****************************************************************************
  853. *
  854. * FUNCTION : CDfsJnPt::DfsRoot
  855. *
  856. * DESCRIPTION : Checks if the Dfs Jn Pt is a root.
  857. *
  858. ******************************************************************************/
  859. BOOL CDfsJnPt::IsDfsRoot ( LPCWSTR lpKey )
  860. {
  861. BOOL bRetVal = TRUE;
  862. int i = 0;
  863. if ( lpKey [ i ] == L'\\' )
  864. {
  865. i++;
  866. }
  867. if ( lpKey [ i ] == L'\\' )
  868. {
  869. i++;
  870. }
  871. while ( lpKey [ i ] != L'\\' )
  872. {
  873. i++;
  874. }
  875. i++;
  876. while ( lpKey [ i ] != L'\0' )
  877. {
  878. if ( lpKey [ i ] == L'\\' )
  879. {
  880. bRetVal = FALSE;
  881. break;
  882. }
  883. i++;
  884. }
  885. return bRetVal;
  886. }
  887. /*****************************************************************************
  888. *
  889. * FUNCTION : CDfsJnPt::ExecMethod
  890. *
  891. * DESCRIPTION : Executes a method
  892. *
  893. * INPUTS : Instance to execute against, method name, input parms instance
  894. * Output parms instance.
  895. *
  896. * OUTPUTS : none
  897. *
  898. * RETURNS : nothing
  899. *
  900. * COMMENTS :
  901. *
  902. *****************************************************************************/
  903. HRESULT CDfsJnPt::ExecMethod (
  904. const CInstance& a_Instance,
  905. const BSTR a_MethodName ,
  906. CInstance *a_InParams ,
  907. CInstance *a_OutParams ,
  908. long a_Flags
  909. )
  910. {
  911. HRESULT hr = WBEM_E_INVALID_METHOD;
  912. if (_wcsicmp(a_MethodName, L"Create") == 0)
  913. {
  914. CHString sDfsEntry, sServerName, sShareName, sDescription;
  915. if (a_InParams->GetCHString(DFSENTRYPATH, sDfsEntry) && sDfsEntry.GetLength() &&
  916. a_InParams->GetCHString(SERVERNAME, sServerName) && sServerName.GetLength() &&
  917. a_InParams->GetCHString(SHARENAME, sShareName) && sShareName.GetLength())
  918. {
  919. // At the point, the *wmi* method call has succeeded. All that
  920. // remains is to determine the *class's* return code
  921. hr = WBEM_S_NO_ERROR;
  922. a_InParams->GetCHString(COMMENT, sDescription);
  923. NET_API_STATUS status = AddDfsJnPt (
  924. sDfsEntry.GetBuffer(0),
  925. sServerName.GetBuffer(0),
  926. sShareName.GetBuffer(0),
  927. sDescription.GetLength() > 0 ? sDescription.GetBuffer(0) : NULL
  928. );
  929. a_OutParams->SetDWORD(L"ReturnValue", status);
  930. }
  931. else
  932. {
  933. hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  934. }
  935. }
  936. return hr;
  937. }