Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1396 lines
30 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: getobj.cxx
  7. //
  8. // Contents: NetWare 3.12 GetObject functionality
  9. //
  10. // History:
  11. //----------------------------------------------------------------------------
  12. #include "NWCOMPAT.hxx"
  13. #pragma hdrstop
  14. //+---------------------------------------------------------------------------
  15. // Function: GetObject
  16. //
  17. // Synopsis: Called by ResolvePathName to return an object
  18. //
  19. // Arguments: [LPWSTR szBuffer]
  20. // [LPVOID *ppObject]
  21. //
  22. // Returns: HRESULT
  23. //
  24. // Modifies: -
  25. //
  26. // History: 11-Jan-96 t-ptam Created.
  27. //
  28. //----------------------------------------------------------------------------
  29. HRESULT
  30. GetObject(
  31. LPWSTR szBuffer,
  32. LPVOID * ppObject
  33. )
  34. {
  35. OBJECTINFO ObjectInfo;
  36. POBJECTINFO pObjectInfo = &ObjectInfo;
  37. CLexer Lexer(szBuffer);
  38. HRESULT hr = S_OK;
  39. memset(pObjectInfo, 0, sizeof(OBJECTINFO));
  40. hr = Object(&Lexer, pObjectInfo);
  41. BAIL_ON_FAILURE(hr);
  42. hr = ValidateProvider(pObjectInfo);
  43. BAIL_ON_FAILURE(hr);
  44. if (pObjectInfo->NumComponents >= 1) {
  45. hr = NWApiLoginToServer(pObjectInfo->ComponentArray[0],
  46. NULL,
  47. NULL) ;
  48. BAIL_ON_FAILURE(hr);
  49. }
  50. switch (pObjectInfo->ObjectType) {
  51. case TOKEN_COMPUTER:
  52. hr = GetComputerObject(pObjectInfo, ppObject);
  53. break;
  54. case TOKEN_USER:
  55. hr = GetUserObject(pObjectInfo, ppObject);
  56. break;
  57. case TOKEN_GROUP:
  58. hr = GetGroupObject(pObjectInfo, ppObject);
  59. break;
  60. case TOKEN_SCHEMA:
  61. hr = GetSchemaObject(pObjectInfo, ppObject);
  62. break;
  63. case TOKEN_CLASS:
  64. hr = GetClassObject(pObjectInfo, ppObject);
  65. break;
  66. case TOKEN_PROPERTY:
  67. hr = GetPropertyObject(pObjectInfo, ppObject);
  68. break;
  69. case TOKEN_SYNTAX:
  70. hr = GetSyntaxObject(pObjectInfo, ppObject);
  71. break;
  72. case TOKEN_FILESERVICE:
  73. hr = GetFileServiceObject(pObjectInfo, ppObject);
  74. break;
  75. case TOKEN_FILESHARE:
  76. hr = GetFileShareObject(pObjectInfo, ppObject);
  77. break;
  78. case TOKEN_PRINTER:
  79. hr = GetPrinterObject(pObjectInfo, ppObject);
  80. break;
  81. default:
  82. hr = HeuristicGetObject(pObjectInfo, ppObject);
  83. break;
  84. }
  85. error:
  86. FreeObjectInfo( &ObjectInfo, TRUE );
  87. RRETURN(hr);
  88. }
  89. //+---------------------------------------------------------------------------
  90. // Function: HeuristicGetObject
  91. //
  92. // Synopsis: Get object of yet undetermined type.
  93. //
  94. // Arguments: [POBJECTINFO pObjectInfo]
  95. // [LPVOID *ppObject]
  96. //
  97. // Returns: HRESULT
  98. //
  99. // Modifies:
  100. //
  101. // History: 11-Jan-96 t-ptam Created.
  102. //
  103. //----------------------------------------------------------------------------
  104. HRESULT
  105. HeuristicGetObject(
  106. POBJECTINFO pObjectInfo,
  107. LPVOID * ppObject
  108. )
  109. {
  110. HRESULT hr = S_OK;
  111. //
  112. // Case 0: No componenet - Namespace object.
  113. //
  114. if (pObjectInfo->NumComponents == 0) {
  115. RRETURN(GetNamespaceObject(pObjectInfo, ppObject));
  116. }
  117. //
  118. // Case 1: Single component - Computer object.
  119. //
  120. if (pObjectInfo->NumComponents == 1) {
  121. RRETURN(GetComputerObject(pObjectInfo, ppObject));
  122. }
  123. //
  124. // Case 2: Two components - FileService object
  125. // Group object
  126. // Schema object
  127. // User object
  128. // Printer object
  129. //
  130. if (pObjectInfo->NumComponents == 2) {
  131. hr = GetSchemaObject(pObjectInfo, ppObject);
  132. if (FAILED(hr)) {
  133. hr = GetUserObject(pObjectInfo, ppObject);
  134. if (FAILED(hr)) {
  135. hr = GetGroupObject(pObjectInfo, ppObject);
  136. if (FAILED(hr)) {
  137. hr = GetFileServiceObject(pObjectInfo, ppObject);
  138. if (FAILED(hr)) {
  139. hr = GetPrinterObject(pObjectInfo, ppObject);
  140. }
  141. }
  142. }
  143. }
  144. if (FAILED(hr)) {
  145. hr = E_ADS_UNKNOWN_OBJECT;
  146. }
  147. else {
  148. RRETURN(S_OK);
  149. }
  150. }
  151. //
  152. // Case 3: Three components - FileShare object
  153. // Schema Class object
  154. // Schema FunctionSet object
  155. // Schema Syntax object
  156. //
  157. if (pObjectInfo->NumComponents == 3) {
  158. hr = GetFileShareObject(pObjectInfo, ppObject);
  159. if (FAILED(hr)) {
  160. if ( _wcsicmp( pObjectInfo->ComponentArray[1], SCHEMA_NAME ) == 0 ){
  161. hr = GetClassObject(pObjectInfo, ppObject);
  162. if (FAILED(hr)) {
  163. hr = GetPropertyObject(pObjectInfo, ppObject);
  164. }
  165. if (FAILED(hr)) {
  166. hr = GetSyntaxObject(pObjectInfo, ppObject);
  167. }
  168. }
  169. }
  170. if (FAILED(hr)) {
  171. hr = E_ADS_UNKNOWN_OBJECT;
  172. }
  173. else {
  174. RRETURN(S_OK);
  175. }
  176. }
  177. //
  178. // Case 4: Four components - Schema FunctionSetAlias object
  179. // Schema Property object
  180. //
  181. RRETURN(hr);
  182. }
  183. //+---------------------------------------------------------------------------
  184. // Function: GetNamespaceObject
  185. //
  186. // Synopsis:
  187. //
  188. // Arguments: POBJECTINFO pObjectInfo
  189. // LPVOID * ppObject
  190. //
  191. // Returns: HRESULT
  192. //
  193. // Modifies:
  194. //
  195. // History: 04-Mar-96 t-ptam Created.
  196. //
  197. //----------------------------------------------------------------------------
  198. HRESULT
  199. GetNamespaceObject(
  200. POBJECTINFO pObjectInfo,
  201. LPVOID * ppObject
  202. )
  203. {
  204. HRESULT hr = S_OK;
  205. hr = ValidateNamespaceObject(
  206. pObjectInfo
  207. );
  208. BAIL_ON_FAILURE(hr);
  209. hr = CoCreateInstance(
  210. CLSID_NWCOMPATNamespace,
  211. NULL,
  212. CLSCTX_INPROC_SERVER,
  213. IID_IUnknown,
  214. (void **)ppObject
  215. );
  216. RRETURN(hr);
  217. error:
  218. RRETURN(hr);
  219. }
  220. //+---------------------------------------------------------------------------
  221. // Function: GetComputerObject
  222. //
  223. // Synopsis:
  224. //
  225. // Arguments: POBJECTINFO pObjectInfo
  226. // LPVOID * ppObject
  227. //
  228. // Returns: HRESULT
  229. //
  230. // Modifies:
  231. //
  232. // History: 11-Jan-96 t-ptam Created.
  233. //
  234. //----------------------------------------------------------------------------
  235. HRESULT
  236. GetComputerObject(
  237. POBJECTINFO pObjectInfo,
  238. LPVOID * ppObject
  239. )
  240. {
  241. HRESULT hr = S_OK;
  242. WCHAR ADsParent[MAX_ADS_PATH];
  243. hr = ValidateComputerObject(
  244. pObjectInfo
  245. );
  246. BAIL_ON_FAILURE(hr);
  247. hr = BuildParent(
  248. pObjectInfo,
  249. ADsParent
  250. );
  251. BAIL_ON_FAILURE(hr);
  252. hr = CNWCOMPATComputer::CreateComputer(
  253. ADsParent,
  254. pObjectInfo->ComponentArray[0],
  255. ADS_OBJECT_BOUND,
  256. IID_IUnknown,
  257. ppObject
  258. );
  259. error:
  260. RRETURN(hr);
  261. }
  262. //+---------------------------------------------------------------------------
  263. // Function: GetUserObject
  264. //
  265. // Synopsis:
  266. //
  267. // Arguments: POBJECTINFO pObjectInfo
  268. // LPVOID * ppObject
  269. //
  270. // Returns: HRESULT
  271. //
  272. // Modifies:
  273. //
  274. // History: 29-Feb-96 t-ptam Created.
  275. //
  276. //----------------------------------------------------------------------------
  277. HRESULT
  278. GetUserObject(
  279. POBJECTINFO pObjectInfo,
  280. LPVOID * ppObject
  281. )
  282. {
  283. HRESULT hr = S_OK;
  284. WCHAR ADsParent[MAX_ADS_PATH];
  285. hr = ValidateUserObject(
  286. pObjectInfo
  287. );
  288. BAIL_ON_FAILURE(hr);
  289. hr = BuildParent(
  290. pObjectInfo,
  291. ADsParent
  292. );
  293. BAIL_ON_FAILURE(hr);
  294. hr = CNWCOMPATUser::CreateUser(
  295. ADsParent,
  296. NWCOMPAT_COMPUTER_ID,
  297. pObjectInfo->ComponentArray[0],
  298. pObjectInfo->ComponentArray[1],
  299. ADS_OBJECT_BOUND,
  300. IID_IUnknown,
  301. ppObject
  302. );
  303. error:
  304. RRETURN(hr);
  305. }
  306. //+---------------------------------------------------------------------------
  307. // Function: GetGroupObject
  308. //
  309. // Synopsis:
  310. //
  311. // Arguments: POBJECTINFO pObjectInfo
  312. // LPVOID * ppObject
  313. //
  314. // Returns: HRESULT
  315. //
  316. // Modifies:
  317. //
  318. // History: 29-Feb-96 t-ptam Created.
  319. //
  320. //----------------------------------------------------------------------------
  321. HRESULT
  322. GetGroupObject(
  323. POBJECTINFO pObjectInfo,
  324. LPVOID * ppObject
  325. )
  326. {
  327. HRESULT hr = S_OK;
  328. WCHAR ADsParent[MAX_ADS_PATH];
  329. hr = ValidateGroupObject(
  330. pObjectInfo
  331. );
  332. BAIL_ON_FAILURE(hr);
  333. hr = BuildParent(
  334. pObjectInfo,
  335. ADsParent
  336. );
  337. BAIL_ON_FAILURE(hr);
  338. hr = CNWCOMPATGroup::CreateGroup(
  339. ADsParent,
  340. NWCOMPAT_COMPUTER_ID,
  341. pObjectInfo->ComponentArray[0],
  342. pObjectInfo->ComponentArray[1],
  343. ADS_OBJECT_BOUND,
  344. IID_IUnknown,
  345. ppObject
  346. );
  347. error:
  348. RRETURN(hr);
  349. }
  350. //+---------------------------------------------------------------------------
  351. // Function: GetSchemaObject
  352. //
  353. // Synopsis:
  354. //
  355. // Arguments:
  356. //
  357. // Returns:
  358. //
  359. // Modifies:
  360. //
  361. // History: 1-17-96 yihsins Created.
  362. //
  363. //----------------------------------------------------------------------------
  364. HRESULT
  365. GetSchemaObject(
  366. POBJECTINFO pObjectInfo,
  367. LPVOID * ppObject
  368. )
  369. {
  370. LPUNKNOWN pUnknown = NULL;
  371. WCHAR ADsParent[MAX_ADS_PATH];
  372. HRESULT hr = S_OK;
  373. if (pObjectInfo->NumComponents != 2)
  374. RRETURN(E_ADS_BAD_PATHNAME);
  375. if ( _wcsicmp( pObjectInfo->ComponentArray[1], SCHEMA_NAME ) != 0 )
  376. {
  377. hr = E_ADS_BAD_PATHNAME;
  378. BAIL_ON_FAILURE(hr);
  379. }
  380. hr = BuildParent(pObjectInfo, ADsParent);
  381. BAIL_ON_FAILURE(hr);
  382. hr = CNWCOMPATSchema::CreateSchema(
  383. ADsParent,
  384. pObjectInfo->ComponentArray[1],
  385. ADS_OBJECT_BOUND,
  386. IID_IUnknown,
  387. (void **)&pUnknown
  388. );
  389. BAIL_ON_FAILURE(hr);
  390. *ppObject = pUnknown;
  391. RRETURN(hr);
  392. error:
  393. if (pUnknown)
  394. pUnknown->Release();
  395. *ppObject = NULL;
  396. RRETURN(hr);
  397. }
  398. //+---------------------------------------------------------------------------
  399. // Function: GetClassObject
  400. //
  401. // Synopsis:
  402. //
  403. // Arguments:
  404. //
  405. // Returns:
  406. //
  407. // Modifies:
  408. //
  409. // History: 1-17-96 yihsins Created.
  410. //
  411. //----------------------------------------------------------------------------
  412. HRESULT
  413. GetClassObject(
  414. POBJECTINFO pObjectInfo,
  415. LPVOID * ppObject
  416. )
  417. {
  418. LPUNKNOWN pUnknown = NULL;
  419. WCHAR ADsParent[MAX_ADS_PATH];
  420. HRESULT hr = S_OK;
  421. DWORD i;
  422. if (pObjectInfo->NumComponents != 3)
  423. RRETURN(E_ADS_BAD_PATHNAME);
  424. if ( _wcsicmp( pObjectInfo->ComponentArray[1], SCHEMA_NAME ) != 0 )
  425. {
  426. hr = E_ADS_BAD_PATHNAME;
  427. BAIL_ON_FAILURE(hr);
  428. }
  429. //
  430. // Look for the given class name
  431. //
  432. for ( i = 0; i < g_cNWCOMPATClasses; i++ )
  433. {
  434. if ( _wcsicmp( g_aNWCOMPATClasses[i].bstrName,
  435. pObjectInfo->ComponentArray[2] ) == 0 )
  436. break;
  437. }
  438. if ( i == g_cNWCOMPATClasses )
  439. {
  440. //
  441. // Class name not found, return error
  442. //
  443. hr = E_ADS_BAD_PATHNAME;
  444. BAIL_ON_FAILURE(hr);
  445. }
  446. //
  447. // Class name found, create and return the object
  448. //
  449. hr = BuildParent(pObjectInfo, ADsParent);
  450. BAIL_ON_FAILURE(hr);
  451. hr = CNWCOMPATClass::CreateClass(
  452. ADsParent,
  453. &g_aNWCOMPATClasses[i],
  454. ADS_OBJECT_BOUND,
  455. IID_IUnknown,
  456. (void **)&pUnknown
  457. );
  458. BAIL_ON_FAILURE(hr);
  459. *ppObject = pUnknown;
  460. RRETURN(hr);
  461. error:
  462. if (pUnknown)
  463. pUnknown->Release();
  464. *ppObject = NULL;
  465. RRETURN(hr);
  466. }
  467. //+---------------------------------------------------------------------------
  468. // Function: GetSyntaxObject
  469. //
  470. // Synopsis:
  471. //
  472. // Arguments:
  473. //
  474. // Returns:
  475. //
  476. // Modifies:
  477. //
  478. // History: 1-17-96 yihsins Created.
  479. //
  480. //----------------------------------------------------------------------------
  481. HRESULT
  482. GetSyntaxObject(
  483. POBJECTINFO pObjectInfo,
  484. LPVOID * ppObject
  485. )
  486. {
  487. LPUNKNOWN pUnknown = NULL;
  488. WCHAR ADsParent[MAX_ADS_PATH];
  489. HRESULT hr = S_OK;
  490. DWORD i;
  491. if (pObjectInfo->NumComponents != 3)
  492. RRETURN(E_ADS_BAD_PATHNAME);
  493. if ( _wcsicmp( pObjectInfo->ComponentArray[1], SCHEMA_NAME ) != 0 )
  494. {
  495. hr = E_ADS_BAD_PATHNAME;
  496. BAIL_ON_FAILURE(hr);
  497. }
  498. //
  499. // Look for the given syntax name
  500. //
  501. for ( i = 0; i < g_cNWCOMPATSyntax; i++ )
  502. {
  503. if ( _wcsicmp( g_aNWCOMPATSyntax[i].bstrName,
  504. pObjectInfo->ComponentArray[2] ) == 0 )
  505. break;
  506. }
  507. if ( i == g_cNWCOMPATSyntax )
  508. {
  509. //
  510. // Syntax name not found, return error
  511. //
  512. hr = E_ADS_BAD_PATHNAME;
  513. BAIL_ON_FAILURE(hr);
  514. }
  515. //
  516. // Syntax name found, create and return the object
  517. //
  518. hr = BuildParent(pObjectInfo, ADsParent);
  519. BAIL_ON_FAILURE(hr);
  520. hr = CNWCOMPATSyntax::CreateSyntax(
  521. ADsParent,
  522. &g_aNWCOMPATSyntax[i],
  523. ADS_OBJECT_BOUND,
  524. IID_IUnknown,
  525. (void **)&pUnknown
  526. );
  527. BAIL_ON_FAILURE(hr);
  528. *ppObject = pUnknown;
  529. RRETURN(hr);
  530. error:
  531. if (pUnknown)
  532. pUnknown->Release();
  533. *ppObject = NULL;
  534. RRETURN(hr);
  535. }
  536. //+---------------------------------------------------------------------------
  537. // Function: GetPropertyObject
  538. //
  539. // Synopsis:
  540. //
  541. // Arguments:
  542. //
  543. // Returns:
  544. //
  545. // Modifies:
  546. //
  547. // History: 1-17-96 yihsins Created.
  548. //
  549. //----------------------------------------------------------------------------
  550. HRESULT
  551. GetPropertyObject(
  552. POBJECTINFO pObjectInfo,
  553. LPVOID * ppObject
  554. )
  555. {
  556. LPUNKNOWN pUnknown = NULL;
  557. WCHAR ADsParent[MAX_ADS_PATH];
  558. WCHAR ADsGrandParent[MAX_ADS_PATH];
  559. HRESULT hr = S_OK;
  560. DWORD nClass, nProp;
  561. if (pObjectInfo->NumComponents != 3)
  562. RRETURN(E_ADS_BAD_PATHNAME);
  563. if ( _wcsicmp( pObjectInfo->ComponentArray[1], SCHEMA_NAME ) != 0 )
  564. {
  565. hr = E_ADS_BAD_PATHNAME;
  566. BAIL_ON_FAILURE(hr);
  567. }
  568. //
  569. // We found the specified functional set, now see if we can locate
  570. // the given property name
  571. //
  572. for ( nProp = 0; nProp < g_cNWCOMPATProperties; nProp++ )
  573. {
  574. if ( _wcsicmp(g_aNWCOMPATProperties[nProp].szPropertyName,
  575. pObjectInfo->ComponentArray[2] ) == 0 )
  576. break;
  577. }
  578. if ( nProp == g_cNWCOMPATProperties )
  579. {
  580. // Return error because the given property name is not found
  581. hr = E_ADS_BAD_PATHNAME;
  582. BAIL_ON_FAILURE(hr);
  583. }
  584. //
  585. // Property name is found, so create and return the object
  586. //
  587. hr = BuildParent(pObjectInfo, ADsParent);
  588. BAIL_ON_FAILURE(hr);
  589. hr = BuildGrandParent(pObjectInfo, ADsGrandParent);
  590. BAIL_ON_FAILURE(hr);
  591. hr = CNWCOMPATProperty::CreateProperty(
  592. ADsParent,
  593. &(g_aNWCOMPATProperties[nProp]),
  594. ADS_OBJECT_BOUND,
  595. IID_IUnknown,
  596. (void **)&pUnknown
  597. );
  598. BAIL_ON_FAILURE(hr);
  599. *ppObject = pUnknown;
  600. RRETURN(hr);
  601. error:
  602. if (pUnknown)
  603. pUnknown->Release();
  604. *ppObject = NULL;
  605. RRETURN(hr);
  606. }
  607. //+---------------------------------------------------------------------------
  608. // Function: GetFileServiceObject
  609. //
  610. // Synopsis:
  611. //
  612. // Arguments: POBJECTINFO pObjectInfo
  613. // LPVOID * ppObject
  614. //
  615. // Returns: HRESULT
  616. //
  617. // Modifies:
  618. //
  619. // History: 22-Apr-96 t-ptam Created.
  620. //
  621. //----------------------------------------------------------------------------
  622. HRESULT
  623. GetFileServiceObject(
  624. POBJECTINFO pObjectInfo,
  625. LPVOID * ppObject
  626. )
  627. {
  628. HRESULT hr = S_OK;
  629. WCHAR ADsParent[MAX_ADS_PATH];
  630. hr = ValidateFileServiceObject(
  631. pObjectInfo
  632. );
  633. BAIL_ON_FAILURE(hr);
  634. hr = BuildParent(
  635. pObjectInfo,
  636. ADsParent
  637. );
  638. BAIL_ON_FAILURE(hr);
  639. hr = CNWCOMPATFileService::CreateFileService(
  640. ADsParent,
  641. pObjectInfo->ComponentArray[0],
  642. pObjectInfo->ComponentArray[1],
  643. ADS_OBJECT_BOUND,
  644. IID_IUnknown,
  645. ppObject
  646. );
  647. error:
  648. RRETURN(hr);
  649. }
  650. //+---------------------------------------------------------------------------
  651. // Function: GetFileShareObject
  652. //
  653. // Synopsis:
  654. //
  655. // Arguments: POBJECTINFO pObjectInfo
  656. // LPVOID * ppObject
  657. //
  658. // Returns: HRESULT
  659. //
  660. // Modifies:
  661. //
  662. // History: 22-Apr-96 t-ptam Created.
  663. //
  664. //----------------------------------------------------------------------------
  665. HRESULT
  666. GetFileShareObject(
  667. POBJECTINFO pObjectInfo,
  668. LPVOID * ppObject
  669. )
  670. {
  671. HRESULT hr = S_OK;
  672. WCHAR ADsParent[MAX_ADS_PATH];
  673. hr = ValidateFileShareObject(
  674. pObjectInfo
  675. );
  676. BAIL_ON_FAILURE(hr);
  677. hr = BuildParent(
  678. pObjectInfo,
  679. ADsParent
  680. );
  681. BAIL_ON_FAILURE(hr);
  682. hr = CNWCOMPATFileShare::CreateFileShare(
  683. ADsParent,
  684. pObjectInfo->ComponentArray[2],
  685. ADS_OBJECT_BOUND,
  686. IID_IUnknown,
  687. ppObject
  688. );
  689. error:
  690. RRETURN(hr);
  691. }
  692. //+---------------------------------------------------------------------------
  693. // Function: GetPrinterObject
  694. //
  695. // Synopsis:
  696. //
  697. // Arguments: POBJECTINFO pObjectInfo
  698. // LPVOID * ppObject
  699. //
  700. // Returns: HRESULT
  701. //
  702. // Modifies:
  703. //
  704. // History: 2-May-96 t-ptam Created.
  705. //
  706. //----------------------------------------------------------------------------
  707. HRESULT
  708. GetPrinterObject(
  709. POBJECTINFO pObjectInfo,
  710. LPVOID * ppObject
  711. )
  712. {
  713. HRESULT hr = S_OK;
  714. WCHAR ADsParent[MAX_ADS_PATH];
  715. hr = ValidatePrinterObject(
  716. pObjectInfo
  717. );
  718. BAIL_ON_FAILURE(hr);
  719. hr = BuildParent(
  720. pObjectInfo,
  721. ADsParent
  722. );
  723. BAIL_ON_FAILURE(hr);
  724. hr = CNWCOMPATPrintQueue::CreatePrintQueue(
  725. ADsParent,
  726. pObjectInfo->ComponentArray[1],
  727. ADS_OBJECT_BOUND,
  728. IID_IUnknown,
  729. ppObject
  730. );
  731. error:
  732. RRETURN(hr);
  733. }
  734. //+---------------------------------------------------------------------------
  735. // Function: ValidateNamespaceObject
  736. //
  737. // Synopsis:
  738. //
  739. // Arguments: POBJECTINFO pObjectInfo
  740. //
  741. // Returns: HRESULT
  742. //
  743. // Modifies:
  744. //
  745. // History: 16-Jan-96 t-ptam (Patrick) Created.
  746. //
  747. //----------------------------------------------------------------------------
  748. HRESULT
  749. ValidateNamespaceObject(
  750. POBJECTINFO pObjectInfo
  751. )
  752. {
  753. if (!_wcsicmp(pObjectInfo->ProviderName, bstrProviderName)) {
  754. }
  755. RRETURN(S_OK);
  756. }
  757. //+---------------------------------------------------------------------------
  758. // Function: ValidateComputerObject
  759. //
  760. // Synopsis: Validate the existence of a computer object by obtaining
  761. // a handle to it. A computer object must exist if a handle
  762. // to it can be obtained.
  763. //
  764. // Arguments: [LPWSTR szComputerName]
  765. //
  766. // Returns: HRESULT
  767. //
  768. // Modifies:
  769. //
  770. // History: 16-Jan-96 t-ptam (Patrick) Created.
  771. //
  772. //----------------------------------------------------------------------------
  773. HRESULT
  774. ValidateComputerObject(
  775. POBJECTINFO pObjectInfo
  776. )
  777. {
  778. //
  779. // A handle of a certain bindery can only be obtained if the bindery
  780. // exist. Therefore we used this fact to validate the existence of
  781. // a computer object.
  782. //
  783. NWCONN_HANDLE hConn = NULL;
  784. HRESULT hr = S_OK;
  785. if (pObjectInfo->NumComponents != 1) {
  786. RRETURN(E_ADS_BAD_PATHNAME);
  787. }
  788. //
  789. // Try to obtain a handle to a NWCOMPAT Server.
  790. //
  791. hr = NWApiGetBinderyHandle(
  792. &hConn,
  793. pObjectInfo->ComponentArray[0]
  794. );
  795. BAIL_ON_FAILURE(hr);
  796. //
  797. // Detach handle.
  798. //
  799. hr = NWApiReleaseBinderyHandle(
  800. hConn
  801. );
  802. error:
  803. RRETURN(hr);
  804. }
  805. //+---------------------------------------------------------------------------
  806. // Function: ValidateUserObject
  807. //
  808. // Synopsis: Validate the existence of a computer object by obtaining
  809. // a handle to it. A computer object must exist if a handle
  810. // to it can be obtained.
  811. //
  812. // Arguments: [LPWSTR szComputerName]
  813. //
  814. // Returns: HRESULT
  815. //
  816. // Modifies: pObjectInfo->ComponentArray[1] is upper-cased
  817. //
  818. // History: 29-Feb-96 t-ptam (Patrick) Created.
  819. // 29-Jul-96 t-danal Uppercase fix.
  820. //
  821. // Note: Netware will let you create a lowercase user name but will
  822. // internally store only uppercase. However, it will not
  823. // return the uppercase user name on a lowercase request.
  824. //
  825. //----------------------------------------------------------------------------
  826. HRESULT
  827. ValidateUserObject(
  828. POBJECTINFO pObjectInfo
  829. )
  830. {
  831. NWCONN_HANDLE hConn = NULL;
  832. HRESULT hr = S_OK;
  833. DWORD dwResumeObjectID = 0xffffffff;
  834. if (pObjectInfo->NumComponents != 2) {
  835. RRETURN(E_ADS_BAD_PATHNAME);
  836. }
  837. //
  838. // Obtain a handle to a NetWare Server.
  839. //
  840. hr = NWApiGetBinderyHandle(
  841. &hConn,
  842. pObjectInfo->ComponentArray[0]
  843. );
  844. BAIL_ON_FAILURE(hr);
  845. //
  846. // Get the specified (uppercased) user object.
  847. //
  848. hr = NWApiValidateObject(
  849. hConn,
  850. OT_USER,
  851. _wcsupr(pObjectInfo->ComponentArray[1]),
  852. &dwResumeObjectID
  853. );
  854. BAIL_ON_FAILURE(hr);
  855. error:
  856. if (hConn) {
  857. NWApiReleaseBinderyHandle(hConn);
  858. }
  859. RRETURN(hr);
  860. }
  861. //+---------------------------------------------------------------------------
  862. // Function: ValidateGroupObject
  863. //
  864. // Synopsis: Validate the existence of a group object by scanning
  865. // for it in the bindery.
  866. //
  867. // Arguments: [POBJECTINFO pObjectInfo]
  868. //
  869. // Returns: HRESULT
  870. //
  871. // Modifies: pObjectInfo->ComponentArray[1] is upper-cased
  872. //
  873. // History: 29-Feb-96 t-ptam (Patrick) Created.
  874. // 29-Jul-96 t-danal Uppercase fix.
  875. //
  876. // Note: Netware will let you create a lowercase user name but will
  877. // internally store only uppercase. However, it will not
  878. // return the uppercase user name on a lowercase request.
  879. //
  880. //----------------------------------------------------------------------------
  881. HRESULT
  882. ValidateGroupObject(
  883. POBJECTINFO pObjectInfo
  884. )
  885. {
  886. NWCONN_HANDLE hConn = NULL;
  887. HRESULT hr = S_OK;
  888. DWORD dwResumeObjectID = 0xffffffff;
  889. if (pObjectInfo->NumComponents != 2) {
  890. RRETURN(E_ADS_BAD_PATHNAME);
  891. }
  892. //
  893. // Obtain a handle to a NetWare Server.
  894. //
  895. hr = NWApiGetBinderyHandle(
  896. &hConn,
  897. pObjectInfo->ComponentArray[0]
  898. );
  899. BAIL_ON_FAILURE(hr);
  900. //
  901. // Get the specified (uppercased) group object.
  902. //
  903. hr = NWApiValidateObject(
  904. hConn,
  905. OT_USER_GROUP,
  906. _wcsupr(pObjectInfo->ComponentArray[1]),
  907. &dwResumeObjectID
  908. );
  909. BAIL_ON_FAILURE(hr);
  910. error:
  911. if (hConn) {
  912. NWApiReleaseBinderyHandle(hConn);
  913. }
  914. RRETURN(hr);
  915. }
  916. //+---------------------------------------------------------------------------
  917. // Function: ValidateFileServiceObject
  918. //
  919. // Synopsis:
  920. //
  921. // Arguments: [POBJECTINFO pObjectInfo]
  922. //
  923. // Returns: HRESULT
  924. //
  925. // Modifies:
  926. //
  927. // History: 22-Apr-96 t-ptam (Patrick) Created.
  928. //
  929. //----------------------------------------------------------------------------
  930. HRESULT
  931. ValidateFileServiceObject(
  932. POBJECTINFO pObjectInfo
  933. )
  934. {
  935. //
  936. // In NetWare, a FileService object represents a bindery, which is also
  937. // represented as a computer object. Therefore validation of file service
  938. // object can be done the same way as the computer object.
  939. //
  940. //
  941. // A handle of a certain bindery can only be obtained if the bindery exist.
  942. // Therefore we used this fact to validate the existence of a computer
  943. // object.
  944. //
  945. NWCONN_HANDLE hConn = NULL;
  946. HRESULT hr = S_OK;
  947. if (pObjectInfo->NumComponents != 2) {
  948. RRETURN(E_ADS_BAD_PATHNAME);
  949. }
  950. //
  951. // Check for valid NetWare File Server name.
  952. //
  953. if (_wcsicmp(pObjectInfo->ComponentArray[1], bstrNWFileServiceName)) {
  954. RRETURN(E_ADS_BAD_PATHNAME);
  955. }
  956. //
  957. // Try to obtain a handle to a NWCOMPAT Server.
  958. //
  959. hr = NWApiGetBinderyHandle(
  960. &hConn,
  961. pObjectInfo->ComponentArray[0]
  962. );
  963. BAIL_ON_FAILURE(hr);
  964. //
  965. // Detach handle.
  966. //
  967. hr = NWApiReleaseBinderyHandle(
  968. hConn
  969. );
  970. error:
  971. RRETURN(hr);
  972. }
  973. //+---------------------------------------------------------------------------
  974. // Function: ValidateFileShareObject
  975. //
  976. // Synopsis:
  977. //
  978. // Arguments: [POBJECTINFO pObjectInfo]
  979. //
  980. // Returns: HRESULT
  981. //
  982. // Modifies:
  983. //
  984. // History: 29-Apr-96 t-ptam (Patrick) Created.
  985. //
  986. //----------------------------------------------------------------------------
  987. HRESULT
  988. ValidateFileShareObject(
  989. POBJECTINFO pObjectInfo
  990. )
  991. {
  992. HRESULT hr = S_OK;
  993. DWORD dwResumeObjectID = 0xffffffff;
  994. NWCONN_HANDLE hConn = NULL;
  995. NWVOL_NUM VolumeNumber = 0;
  996. if (pObjectInfo->NumComponents != 3) {
  997. RRETURN(E_ADS_BAD_PATHNAME);
  998. }
  999. //
  1000. // Obtain a handle to a NetWare Server.
  1001. //
  1002. hr = NWApiGetBinderyHandle(
  1003. &hConn,
  1004. pObjectInfo->ComponentArray[0]
  1005. );
  1006. BAIL_ON_FAILURE(hr);
  1007. //
  1008. // Try to get the Volume ID that correspond to the Volume name. If it
  1009. // succeeds, the FileShare is valid.
  1010. //
  1011. hr = NWApiGetVolumeNumber(
  1012. hConn,
  1013. pObjectInfo->ComponentArray[2],
  1014. &VolumeNumber
  1015. );
  1016. BAIL_ON_FAILURE(hr);
  1017. error:
  1018. if (hConn) {
  1019. NWApiReleaseBinderyHandle(hConn);
  1020. }
  1021. RRETURN(hr);
  1022. }
  1023. //+---------------------------------------------------------------------------
  1024. // Function: ValidatePrinterObject
  1025. //
  1026. // Synopsis:
  1027. //
  1028. // Arguments: [POBJECTINFO pObjectInfo]
  1029. //
  1030. // Returns: HRESULT
  1031. //
  1032. // Modifies:
  1033. //
  1034. // History: 2-May-96 t-ptam (Patrick) Created.
  1035. //
  1036. //----------------------------------------------------------------------------
  1037. HRESULT
  1038. ValidatePrinterObject(
  1039. POBJECTINFO pObjectInfo
  1040. )
  1041. {
  1042. HANDLE hPrinter = NULL;
  1043. HRESULT hr = S_OK;
  1044. WCHAR szUncName[MAX_PATH];
  1045. if (pObjectInfo->NumComponents != 2) {
  1046. RRETURN(E_ADS_BAD_PATHNAME);
  1047. }
  1048. //
  1049. // Build UNC name from ObjectInfo.
  1050. //
  1051. wsprintf(
  1052. szUncName,
  1053. L"\\\\%s\\%s",
  1054. pObjectInfo->ComponentArray[0],
  1055. pObjectInfo->ComponentArray[1]
  1056. );
  1057. //
  1058. // Get a handle of the printer.
  1059. //
  1060. hr = NWApiOpenPrinter(
  1061. szUncName,
  1062. &hPrinter,
  1063. PRINTER_ACCESS_USE
  1064. );
  1065. BAIL_ON_FAILURE(hr);
  1066. //
  1067. // Release it.
  1068. //
  1069. hr = NWApiClosePrinter(
  1070. hPrinter
  1071. );
  1072. error:
  1073. RRETURN(hr);
  1074. }
  1075. //+---------------------------------------------------------------------------
  1076. // Function: BuildParent
  1077. //
  1078. // Synopsis:
  1079. //
  1080. // Arguments: [POBJECTINFO pObjectInfo]
  1081. // [LPWSTR szBuffer]
  1082. //
  1083. // Returns: HRESULT
  1084. //
  1085. // Modifies:
  1086. //
  1087. // History: 11-3-95 krishnag Created.
  1088. //
  1089. //----------------------------------------------------------------------------
  1090. HRESULT
  1091. BuildParent(
  1092. POBJECTINFO pObjectInfo,
  1093. LPWSTR szBuffer
  1094. )
  1095. {
  1096. DWORD i = 0;
  1097. if (!pObjectInfo->ProviderName) {
  1098. RRETURN(E_ADS_BAD_PATHNAME);
  1099. }
  1100. wsprintf(szBuffer,L"%s:", pObjectInfo->ProviderName);
  1101. if (pObjectInfo->NumComponents - 1) {
  1102. wcscat(szBuffer, L"//");
  1103. wcscat(szBuffer, pObjectInfo->DisplayComponentArray[0]);
  1104. for (i = 1; i < (pObjectInfo->NumComponents - 1); i++) {
  1105. wcscat(szBuffer, L"/");
  1106. wcscat(szBuffer, pObjectInfo->DisplayComponentArray[i]);
  1107. }
  1108. }
  1109. RRETURN(S_OK);
  1110. }
  1111. //+---------------------------------------------------------------------------
  1112. // Function: BuildGrandParent
  1113. //
  1114. // Synopsis:
  1115. //
  1116. // Arguments: [POBJECTINFO pObjectInfo]
  1117. // [LPWSTR szBuffer]
  1118. //
  1119. // Returns: HRESULT
  1120. //
  1121. // Modifies:
  1122. //
  1123. // History: 11-3-95 krishnag Created.
  1124. //
  1125. //----------------------------------------------------------------------------
  1126. HRESULT
  1127. BuildGrandParent(POBJECTINFO pObjectInfo, LPWSTR szBuffer)
  1128. {
  1129. DWORD i = 0;
  1130. if (!pObjectInfo->ProviderName) {
  1131. RRETURN(E_ADS_BAD_PATHNAME);
  1132. }
  1133. wsprintf(szBuffer,L"%s:", pObjectInfo->ProviderName);
  1134. if (pObjectInfo->NumComponents - 2) {
  1135. wcscat(szBuffer, L"//");
  1136. wcscat(szBuffer, pObjectInfo->DisplayComponentArray[0]);
  1137. for (i = 1; i < (pObjectInfo->NumComponents - 2); i++) {
  1138. wcscat(szBuffer, L"/");
  1139. wcscat(szBuffer, pObjectInfo->DisplayComponentArray[i]);
  1140. }
  1141. }
  1142. RRETURN(S_OK);
  1143. }
  1144. //+---------------------------------------------------------------------------
  1145. // Function: BuildADsPath
  1146. //
  1147. // Synopsis:
  1148. //
  1149. // Arguments: [POBJECTINFO pObjectInfo]
  1150. // [LPWSTR szBuffer]
  1151. //
  1152. // Returns: HRESULT
  1153. //
  1154. // Modifies:
  1155. //
  1156. // History: 11-3-95 krishnag Created.
  1157. //
  1158. //----------------------------------------------------------------------------
  1159. HRESULT
  1160. BuildADsPath(
  1161. POBJECTINFO pObjectInfo,
  1162. LPWSTR szBuffer
  1163. )
  1164. {
  1165. DWORD i = 0;
  1166. if (!pObjectInfo->ProviderName) {
  1167. RRETURN(E_ADS_BAD_PATHNAME);
  1168. }
  1169. wsprintf(szBuffer,L"%s:", pObjectInfo->ProviderName);
  1170. if (pObjectInfo->NumComponents) {
  1171. wcscat(szBuffer, L"//");
  1172. wcscat(szBuffer, pObjectInfo->DisplayComponentArray[0]);
  1173. for (i = 1; i < (pObjectInfo->NumComponents); i++) {
  1174. wcscat(szBuffer, L"/");
  1175. wcscat(szBuffer, pObjectInfo->DisplayComponentArray[i]);
  1176. }
  1177. }
  1178. RRETURN(S_OK);
  1179. }