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.

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