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.

2782 lines
58 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. nsepm.cxx
  5. Abstract:
  6. This module defines Name Space Extension for mapping
  7. Author:
  8. Philippe Choquier 29-Nov-1996
  9. --*/
  10. #define INITGUID
  11. extern "C" {
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. }
  16. #include <dbgutil.h>
  17. #include <ole2.h>
  18. #include <imd.h>
  19. #include <windows.h>
  20. #include <xbf.hxx>
  21. #include "nsepimp.hxx"
  22. #include "nsepm.hxx"
  23. #include <stringau.hxx>
  24. //#define TEST_ADMACL
  25. #if defined(TEST_ADMACL)
  26. #include <admacl.hxx>
  27. #endif
  28. #define NSEPM_NOISY 0 // set to 1 for really noisy debug output
  29. #if NSEPM_NOISY
  30. #define NOISYPRINTF(x) DBGPRINTF(x)
  31. #else
  32. #define NOISYPRINTF(x)
  33. #endif
  34. OPEN_CTX** OPEN_CTX::sm_pHandleTable;
  35. CRITICAL_SECTION OPEN_CTX::sm_csHandleTableLock;
  36. DWORD OPEN_CTX::sm_cHandleEntries;
  37. DWORD OPEN_CTX::sm_cMaxHandleEntries;
  38. DWORD
  39. OPEN_CTX::InitializeHandleTable(
  40. VOID
  41. )
  42. /*++
  43. Routine Description:
  44. Initialize Handle Table. This table maps DWORD handles to pointers to
  45. OPEN_CTX objects. This is an Sundown-ism
  46. Arguments:
  47. None
  48. Returns:
  49. Returns ERROR_SUCCESS if successful, else Win32 Error
  50. --*/
  51. {
  52. INITIALIZE_CRITICAL_SECTION( &sm_csHandleTableLock );
  53. sm_cHandleEntries = 0;
  54. sm_cMaxHandleEntries = INITIAL_HANDLE_TABLE_SIZE;
  55. sm_pHandleTable = (POPEN_CTX*) LocalAlloc( LPTR,
  56. sizeof( POPEN_CTX ) *
  57. sm_cMaxHandleEntries );
  58. if ( sm_pHandleTable == NULL )
  59. {
  60. return GetLastError();
  61. }
  62. return ERROR_SUCCESS;
  63. }
  64. DWORD
  65. OPEN_CTX::TerminateHandleTable(
  66. VOID
  67. )
  68. /*++
  69. Routine Description:
  70. Destroy Handle Table.
  71. Arguments:
  72. None
  73. Returns:
  74. Returns ERROR_SUCCESS if successful, else Win32 Error
  75. --*/
  76. {
  77. EnterCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  78. sm_cHandleEntries = 0;
  79. sm_cMaxHandleEntries = 0;
  80. if ( sm_pHandleTable )
  81. {
  82. LocalFree( sm_pHandleTable );
  83. sm_pHandleTable = NULL;
  84. }
  85. LeaveCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  86. DeleteCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  87. return ERROR_SUCCESS;
  88. }
  89. POPEN_CTX
  90. OPEN_CTX::MapHandleToContext(
  91. IN DWORD dwHandle
  92. )
  93. {
  94. POPEN_CTX pOpenCtx = NULL;
  95. EnterCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  96. if ( dwHandle &&
  97. dwHandle <= OPEN_CTX::sm_cMaxHandleEntries )
  98. {
  99. pOpenCtx = OPEN_CTX::sm_pHandleTable[ dwHandle - 1 ];
  100. }
  101. LeaveCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  102. return pOpenCtx;
  103. }
  104. OPEN_CTX::OPEN_CTX( DWORD dwAccess )
  105. : m_dwAccess( dwAccess ),
  106. m_dwHandle( 0 )
  107. /*++
  108. Routine Description:
  109. Constructor for OPEN_CTX objects. Responsible for generating a DWORD
  110. handle to be passed back to caller of NSEPM.
  111. Arguments:
  112. dwAccess - Access required for NSEPM call
  113. Returns:
  114. None. Successful if GetHandle() selector returns non-zero handle
  115. --*/
  116. {
  117. DWORD cNewCount;
  118. DWORD iCounter;
  119. EnterCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  120. cNewCount = sm_cHandleEntries + 1;
  121. if ( cNewCount > sm_cMaxHandleEntries )
  122. {
  123. sm_cMaxHandleEntries += HANDLE_TABLE_REALLOC_JUMP;
  124. sm_pHandleTable = (POPEN_CTX*) LocalReAlloc( sm_pHandleTable,
  125. sm_cMaxHandleEntries *
  126. sizeof( POPEN_CTX ),
  127. LMEM_MOVEABLE );
  128. if ( sm_pHandleTable == NULL )
  129. {
  130. LeaveCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  131. return;
  132. }
  133. }
  134. sm_cHandleEntries = cNewCount;
  135. for( iCounter = 0;
  136. iCounter < sm_cMaxHandleEntries;
  137. iCounter++ )
  138. {
  139. if ( sm_pHandleTable[ iCounter ] == NULL )
  140. {
  141. sm_pHandleTable[ iCounter ] = this;
  142. // Handle is index+1, so that 0 can represent failure.
  143. m_dwHandle = iCounter + 1;
  144. break;
  145. }
  146. }
  147. LeaveCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  148. }
  149. OPEN_CTX::~OPEN_CTX()
  150. /*++
  151. Routine Description:
  152. Destructor for OPEN_CTX object
  153. Arguments:
  154. Returns:
  155. None
  156. --*/
  157. {
  158. DWORD iCounter;
  159. EnterCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  160. if ( m_dwHandle )
  161. {
  162. sm_pHandleTable[ m_dwHandle - 1 ] = NULL;
  163. sm_cHandleEntries--;
  164. }
  165. LeaveCriticalSection( &OPEN_CTX::sm_csHandleTableLock );
  166. }
  167. //
  168. // Local class
  169. //
  170. class CDirPath : public CAllocString {
  171. public:
  172. BOOL Append( LPSTR );
  173. private:
  174. } ;
  175. CDirPath::Append(
  176. LPSTR pszPath
  177. )
  178. {
  179. LPSTR pCur = Get();
  180. int ch;
  181. if ( pCur && *pCur && (ch=pCur[strlen(pCur)-1])!='/' && ch!='\\' &&
  182. pszPath && *pszPath && *pszPath != '/' && *pszPath != '\\' )
  183. {
  184. if ( !CAllocString::Append( "\\" ) )
  185. {
  186. return FALSE;
  187. }
  188. }
  189. return CAllocString::Append( pszPath );
  190. }
  191. //
  192. // Globals
  193. //
  194. #include <initguid.h>
  195. DEFINE_GUID(IisNsepmGuid,
  196. 0x784d8916, 0xaa8c, 0x11d2, 0x92, 0x5e, 0x00, 0xc0, 0x4f, 0x72, 0xd9, 0x0e);
  197. DECLARE_DEBUG_PRINTS_OBJECT();
  198. IMDCOM* g_pMdIf = NULL;
  199. DWORD g_dwInitialized = 0;
  200. ULONG g_dwRefCount = 0;
  201. ULONG g_dwLockCount = 0;
  202. CRITICAL_SECTION g_csInitCritSec;
  203. class CInitNsep {
  204. public:
  205. #ifndef _NO_TRACING_
  206. CInitNsep() { CREATE_DEBUG_PRINT_OBJECT( "NSEPM", IisNsepmGuid ); INITIALIZE_CRITICAL_SECTION( &g_csInitCritSec ); }
  207. #else
  208. CInitNsep() { CREATE_DEBUG_PRINT_OBJECT( "NSEPM" ); INITIALIZE_CRITICAL_SECTION( &g_csInitCritSec ); }
  209. #endif
  210. ~CInitNsep() { DELETE_DEBUG_PRINT_OBJECT(); DeleteCriticalSection( &g_csInitCritSec ); }
  211. } g_cinitnsep;
  212. //
  213. // Class factory
  214. //
  215. class NSEPCOMSrvFactory : public IClassFactory {
  216. public:
  217. NSEPCOMSrvFactory();
  218. ~NSEPCOMSrvFactory();
  219. HRESULT _stdcall
  220. QueryInterface(REFIID riid, void** ppObject);
  221. ULONG _stdcall
  222. AddRef();
  223. ULONG _stdcall
  224. Release();
  225. HRESULT _stdcall
  226. CreateInstance(IUnknown *pUnkOuter, REFIID riid,
  227. void ** pObject);
  228. HRESULT _stdcall
  229. LockServer(BOOL fLock);
  230. private:
  231. ULONG m_dwRefCount;
  232. NSEPCOM m_mdcObject;
  233. };
  234. NSEPCOMSrvFactory::NSEPCOMSrvFactory(
  235. )
  236. :m_mdcObject()
  237. /*++
  238. Routine Description:
  239. Class factory constructor
  240. Arguments:
  241. None
  242. Returns:
  243. Nothing
  244. --*/
  245. {
  246. m_dwRefCount = 0;
  247. }
  248. NSEPCOMSrvFactory::~NSEPCOMSrvFactory(
  249. )
  250. /*++
  251. Routine Description:
  252. Class factory destructor
  253. Arguments:
  254. None
  255. Returns:
  256. Nothing
  257. --*/
  258. {
  259. }
  260. HRESULT
  261. NSEPCOMSrvFactory::CreateInstance(
  262. IUnknown * pUnkOuter,
  263. REFIID riid,
  264. void ** ppObject
  265. )
  266. /*++
  267. Routine Description:
  268. Create NSECOM instance
  269. Arguments:
  270. pUnkOuter - controlling unknown
  271. riid - interface ID
  272. ppObject - updated with interface ptr if success
  273. Returns:
  274. status
  275. --*/
  276. {
  277. NOISYPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::CreateInstance]\n" ) );
  278. NSEPCOM* pC = new NSEPCOM;
  279. if ( pC == NULL )
  280. {
  281. return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
  282. }
  283. if (FAILED( pC->QueryInterface(riid, ppObject)))
  284. {
  285. DBGPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::CreateInstance] no I/F\n" ) );
  286. delete pC;
  287. return E_NOINTERFACE;
  288. }
  289. InterlockedIncrement((long *)&g_dwRefCount);
  290. return NO_ERROR;
  291. }
  292. HRESULT
  293. NSEPCOMSrvFactory::LockServer(
  294. BOOL fLock
  295. )
  296. /*++
  297. Routine Description:
  298. Lock server
  299. Arguments:
  300. fLock - TRUE to lock server, FALSE to unlock it
  301. Returns:
  302. status
  303. --*/
  304. {
  305. if (fLock)
  306. {
  307. InterlockedIncrement((long *)&g_dwLockCount);
  308. }
  309. else
  310. {
  311. InterlockedDecrement((long *)&g_dwLockCount);
  312. }
  313. return NO_ERROR;
  314. }
  315. HRESULT
  316. NSEPCOMSrvFactory::QueryInterface(
  317. REFIID riid,
  318. void **ppObject
  319. )
  320. /*++
  321. Routine Description:
  322. Lock server
  323. Arguments:
  324. None
  325. Returns:
  326. status
  327. --*/
  328. {
  329. NOISYPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::QueryInterface]\n" ) );
  330. if (riid==IID_IUnknown || riid == IID_IClassFactory)
  331. {
  332. *ppObject = (IMDCOM *) this;
  333. }
  334. else
  335. {
  336. DBGPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::QueryInterface] no I/F\n") );
  337. return E_NOINTERFACE;
  338. }
  339. AddRef();
  340. return NO_ERROR;
  341. }
  342. ULONG
  343. NSEPCOMSrvFactory::AddRef(
  344. )
  345. /*++
  346. Routine Description:
  347. Increment refcount to class factory
  348. Arguments:
  349. None
  350. Returns:
  351. >0 if new refcount >0, 0 if new refcount is 0, otherwise <0
  352. --*/
  353. {
  354. DWORD dwRefCount;
  355. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  356. return dwRefCount;
  357. }
  358. ULONG
  359. NSEPCOMSrvFactory::Release(
  360. )
  361. /*++
  362. Routine Description:
  363. Decrement refcount to class factory
  364. Arguments:
  365. None
  366. Returns:
  367. >0 if new refcount >0, 0 if new refcount is 0, otherwise <0
  368. --*/
  369. {
  370. DWORD dwRefCount;
  371. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  372. if (dwRefCount == 0)
  373. {
  374. NOISYPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::Release] delete object\n" ) );
  375. delete this;
  376. }
  377. return dwRefCount;
  378. }
  379. STDAPI
  380. DllGetClassObject(
  381. REFCLSID rclsid,
  382. REFIID riid,
  383. void** ppObject
  384. )
  385. /*++
  386. Routine Description:
  387. Create instance of class factory
  388. Arguments:
  389. rclsid - class ID
  390. riid - interface ID
  391. ppObject - updated with ptr to interface if success
  392. Returns:
  393. status
  394. --*/
  395. {
  396. NOISYPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::DllGetClassObject]\n" ) );
  397. if ( rclsid != CLSID_NSEPMCOM )
  398. {
  399. DBGPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::DllGetClassObject] bad class\n" ) );
  400. return CLASS_E_CLASSNOTAVAILABLE;
  401. }
  402. NSEPCOMSrvFactory *pFactory = new NSEPCOMSrvFactory;
  403. if (FAILED(pFactory->QueryInterface(riid, ppObject)))
  404. {
  405. delete pFactory;
  406. *ppObject = NULL;
  407. DBGPRINTF( (DBG_CONTEXT, "[NSEPCOMSrvFactory::DllGetClassObject] no I/F\n" ) );
  408. return E_INVALIDARG;
  409. }
  410. return NO_ERROR;
  411. }
  412. HRESULT _stdcall
  413. DllCanUnloadNow(
  414. )
  415. /*++
  416. Routine Description:
  417. return S_OK if dll can be unloaded
  418. Arguments:
  419. None
  420. Returns:
  421. S_OK if OK to unload, otherwise S_FALSE
  422. --*/
  423. {
  424. if ( g_dwRefCount || g_dwLockCount )
  425. {
  426. return S_FALSE;
  427. }
  428. else
  429. {
  430. return S_OK;
  431. }
  432. }
  433. STDAPI
  434. DllRegisterServer(
  435. void
  436. )
  437. /*++
  438. Routine Description:
  439. Register NSECOM class & interface in registry
  440. Arguments:
  441. None
  442. Returns:
  443. status
  444. --*/
  445. {
  446. HKEY hKeyCLSID, hKeyInproc32;
  447. HKEY hKeyIF, hKeyStub32;
  448. DWORD dwDisposition;
  449. HMODULE hModule;
  450. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  451. TEXT("CLSID\\{05dc3bb0-4337-11d0-a5c8-00a0c922e752}"),
  452. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  453. &hKeyCLSID, &dwDisposition)!=ERROR_SUCCESS) {
  454. return E_UNEXPECTED;
  455. }
  456. if (RegSetValueEx(hKeyCLSID, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("NSEPM COM Server"), sizeof(TEXT("NSEPM COM Server")))!=ERROR_SUCCESS) {
  457. RegCloseKey(hKeyCLSID);
  458. return E_UNEXPECTED;
  459. }
  460. if (RegCreateKeyEx(hKeyCLSID,
  461. "InprocServer32",
  462. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  463. &hKeyInproc32, &dwDisposition)!=ERROR_SUCCESS) {
  464. RegCloseKey(hKeyCLSID);
  465. return E_UNEXPECTED;
  466. }
  467. hModule=GetModuleHandle("NSEPM.DLL");
  468. if (!hModule) {
  469. RegCloseKey(hKeyInproc32);
  470. RegCloseKey(hKeyCLSID);
  471. return E_UNEXPECTED;
  472. }
  473. TCHAR szName[MAX_PATH+1];
  474. if (GetModuleFileName(hModule, szName, sizeof(szName))==0) {
  475. RegCloseKey(hKeyInproc32);
  476. RegCloseKey(hKeyCLSID);
  477. return E_UNEXPECTED;
  478. }
  479. if (RegSetValueEx(hKeyInproc32, TEXT(""), NULL, REG_SZ, (BYTE*) szName, sizeof(TCHAR)*(lstrlen(szName)+1))!=ERROR_SUCCESS) {
  480. RegCloseKey(hKeyInproc32);
  481. RegCloseKey(hKeyCLSID);
  482. return E_UNEXPECTED;
  483. }
  484. if (RegSetValueEx(hKeyInproc32, TEXT("ThreadingModel"), NULL, REG_SZ, (BYTE*) "Both", sizeof("Both")-1 )!=ERROR_SUCCESS) {
  485. RegCloseKey(hKeyInproc32);
  486. RegCloseKey(hKeyCLSID);
  487. return E_UNEXPECTED;
  488. }
  489. RegCloseKey(hKeyInproc32);
  490. RegCloseKey(hKeyCLSID);
  491. //
  492. // Register Interface, proxy is IMDCOM
  493. //
  494. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  495. TEXT("Interface\\{4810a750-4318-11d0-a5c8-00a0c922e752}"),
  496. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  497. &hKeyIF, &dwDisposition)!=ERROR_SUCCESS) {
  498. return E_UNEXPECTED;
  499. }
  500. if (RegSetValueEx(hKeyIF, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("NSECOM"), sizeof(TEXT("NSECOM")))!=ERROR_SUCCESS) {
  501. RegCloseKey(hKeyIF);
  502. return E_UNEXPECTED;
  503. }
  504. if (RegCreateKeyEx(hKeyIF,
  505. "ProxyStubClsid32",
  506. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  507. &hKeyStub32, &dwDisposition)!=ERROR_SUCCESS) {
  508. RegCloseKey(hKeyIF);
  509. return E_UNEXPECTED;
  510. }
  511. if (RegSetValueEx(hKeyStub32, TEXT(""), NULL, REG_SZ, (BYTE*)"{C1AA48C0-FACC-11cf-9D1A-00AA00A70D51}", sizeof("{C1AA48C0-FACC-11cf-9D1A-00AA00A70D51}") )!=ERROR_SUCCESS) {
  512. RegCloseKey(hKeyStub32);
  513. RegCloseKey(hKeyIF);
  514. return E_UNEXPECTED;
  515. }
  516. RegCloseKey(hKeyStub32);
  517. RegCloseKey(hKeyIF);
  518. return NOERROR;
  519. }
  520. STDAPI
  521. DllUnregisterServer(
  522. void
  523. )
  524. /*++
  525. Routine Description:
  526. Unregister NSECOM class & interface from registry
  527. Arguments:
  528. None
  529. Returns:
  530. status
  531. --*/
  532. {
  533. if (RegDeleteKey(HKEY_CLASSES_ROOT,
  534. TEXT("CLSID\\{05dc3bb0-4337-11d0-a5c8-00a0c922e752}\\InprocServer32"))!=ERROR_SUCCESS)
  535. {
  536. return E_UNEXPECTED;
  537. }
  538. if (RegDeleteKey(HKEY_CLASSES_ROOT,
  539. TEXT("CLSID\\{05dc3bb0-4337-11d0-a5c8-00a0c922e752}"))!=ERROR_SUCCESS)
  540. {
  541. return E_UNEXPECTED;
  542. }
  543. if (RegDeleteKey(HKEY_CLASSES_ROOT,
  544. TEXT("Interface\\{4810a750-4318-11d0-a5c8-00a0c922e752}\\ProxyStubClsid32"))!=ERROR_SUCCESS)
  545. {
  546. return E_UNEXPECTED;
  547. }
  548. if (RegDeleteKey(HKEY_CLASSES_ROOT,
  549. TEXT("Interface\\{4810a750-4318-11d0-a5c8-00a0c922e752}"))!=ERROR_SUCCESS)
  550. {
  551. return E_UNEXPECTED;
  552. }
  553. return NOERROR;
  554. }
  555. //
  556. // NSEPCOM implementation
  557. //
  558. NSEPCOM::NSEPCOM(
  559. )
  560. /*++
  561. Routine Description:
  562. NSEPCOM constructor
  563. Arguments:
  564. None
  565. Returns:
  566. Nothing
  567. --*/
  568. {
  569. m_dwRefCount = 0;
  570. }
  571. NSEPCOM::~NSEPCOM(
  572. )
  573. /*++
  574. Routine Description:
  575. NSEPCOM destructor
  576. Arguments:
  577. None
  578. Returns:
  579. Nothing
  580. --*/
  581. {
  582. }
  583. HRESULT
  584. NSEPCOM::QueryInterface(
  585. REFIID riid,
  586. void **ppObject
  587. )
  588. /*++
  589. Routine Description:
  590. NSEPCOM query interface
  591. recognize IID_IUnknown & IID_NSECOM
  592. Arguments:
  593. riid - interface ID
  594. ppObject - updated with ptr to interface if success
  595. Returns:
  596. status
  597. --*/
  598. {
  599. NOISYPRINTF( (DBG_CONTEXT, "[NSEPCOM::QueryInterface]\n" ) );
  600. if (riid==IID_IUnknown || riid==IID_NSECOM)
  601. {
  602. *ppObject = (NSEPCOM *) this;
  603. }
  604. else
  605. {
  606. DBGPRINTF( (DBG_CONTEXT, "[NSEPCOM::QueryInterface] no I/F\n" ) );
  607. return E_NOINTERFACE;
  608. }
  609. AddRef();
  610. return NO_ERROR;
  611. }
  612. ULONG
  613. NSEPCOM::AddRef(
  614. )
  615. /*++
  616. Routine Description:
  617. Add reference to NSECOM interface
  618. Arguments:
  619. None
  620. Returns:
  621. >0 if new refcount >0, 0 if new refcount is 0, otherwise <0
  622. --*/
  623. {
  624. DWORD dwRefCount;
  625. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  626. return dwRefCount;
  627. }
  628. ULONG
  629. NSEPCOM::Release(
  630. )
  631. /*++
  632. Routine Description:
  633. Remove reference to NSECOM interface
  634. Arguments:
  635. None
  636. Returns:
  637. >0 if new refcount >0, 0 if new refcount is 0, otherwise <0
  638. --*/
  639. {
  640. DWORD dwRefCount;
  641. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  642. if ( !dwRefCount )
  643. {
  644. delete this;
  645. InterlockedDecrement((long *)&g_dwRefCount);
  646. }
  647. return dwRefCount;
  648. }
  649. HRESULT
  650. NSEPCOM::ComMDInitialize(
  651. )
  652. /*++
  653. Routine Description:
  654. Initialize access to NSE for mappings
  655. Arguments:
  656. None
  657. Returns:
  658. status
  659. --*/
  660. {
  661. DWORD RetCode = ERROR_SUCCESS;
  662. HRESULT hRes = S_OK;
  663. EnterCriticalSection( &g_csInitCritSec );
  664. if ( g_dwInitialized++ == 0 )
  665. {
  666. hRes = CoCreateInstance(CLSID_MDCOM, NULL, CLSCTX_INPROC_SERVER, IID_IMDCOM, (void**) &g_pMdIf);
  667. if (FAILED(hRes))
  668. {
  669. g_pMdIf = NULL;
  670. }
  671. else
  672. {
  673. hRes = ReturnCodeToHresult( OPEN_CTX::InitializeHandleTable() );
  674. if ( SUCCEEDED( hRes ) )
  675. {
  676. hRes = g_pMdIf->ComMDInitialize();
  677. if ( SUCCEEDED( hRes ) )
  678. {
  679. hRes = NseMappingInitialize() ? S_OK : ReturnCodeToHresult( GetLastError() );
  680. }
  681. }
  682. }
  683. }
  684. if ( FAILED( hRes ) )
  685. {
  686. --g_dwInitialized;
  687. }
  688. LeaveCriticalSection( &g_csInitCritSec );
  689. return hRes;
  690. }
  691. HRESULT
  692. NSEPCOM::ComMDTerminate(
  693. IN BOOL bSaveData
  694. )
  695. /*++
  696. Routine Description:
  697. Terminate access to NSE for mappings
  698. Arguments:
  699. bSaveData - TRUE to save data on persistent storage
  700. Returns:
  701. status
  702. --*/
  703. {
  704. DWORD RetCode = ERROR_SUCCESS;
  705. HRESULT hRes = S_OK;
  706. EnterCriticalSection( &g_csInitCritSec );
  707. if ( g_dwInitialized && (--g_dwInitialized == 0) )
  708. {
  709. if ( bSaveData )
  710. {
  711. NseSaveObjs();
  712. }
  713. hRes = NseMappingTerminate() ? S_OK : ReturnCodeToHresult( GetLastError() );
  714. if ( g_pMdIf )
  715. {
  716. g_pMdIf->ComMDTerminate(TRUE);
  717. g_pMdIf->Release();
  718. g_pMdIf = NULL;
  719. }
  720. DBG_REQUIRE( OPEN_CTX::TerminateHandleTable() == ERROR_SUCCESS );
  721. }
  722. LeaveCriticalSection( &g_csInitCritSec );
  723. return hRes;
  724. }
  725. HRESULT STDMETHODCALLTYPE
  726. NSEPCOM::ComMDShutdown( void)
  727. {
  728. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  729. }
  730. HRESULT
  731. NSEPCOM::ComMDAddMetaObjectA(
  732. IN METADATA_HANDLE hMDHandle,
  733. IN PBYTE pszMDPath
  734. )
  735. /*++
  736. Routine Description:
  737. Add object
  738. Arguments:
  739. hMDHandle - open handle
  740. pszMDPath - path of object to add
  741. Returns:
  742. status
  743. --*/
  744. {
  745. DWORD RetCode;
  746. CDirPath asPath;
  747. POPEN_CTX pOpenCtx;
  748. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  749. // BugFix: 117734 Whistler
  750. // Prefix bug pOpenCtx being used when it could be null
  751. // EBK 5/15/2000
  752. if (pOpenCtx == NULL)
  753. {
  754. RetCode = ERROR_INVALID_PARAMETER;
  755. }
  756. else if (g_dwInitialized == 0)
  757. {
  758. RetCode = MD_ERROR_NOT_INITIALIZED;
  759. }
  760. else if (((LPSTR)pszMDPath == NULL) || (*(LPSTR)pszMDPath == (TCHAR)'\0'))
  761. {
  762. RetCode = ERROR_INVALID_PARAMETER;
  763. }
  764. else if ( !(pOpenCtx->GetAccess() & METADATA_PERMISSION_WRITE) )
  765. {
  766. RetCode = ERROR_ACCESS_DENIED;
  767. }
  768. else
  769. {
  770. if ( asPath.Set( pOpenCtx->GetPath() ) &&
  771. asPath.Append( (LPSTR)pszMDPath ) )
  772. {
  773. RetCode = NseAddObj( asPath.Get() ) ? ERROR_SUCCESS : GetLastError();
  774. }
  775. else
  776. {
  777. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  778. }
  779. }
  780. return ReturnCodeToHresult(RetCode);
  781. }
  782. HRESULT STDMETHODCALLTYPE
  783. NSEPCOM::ComMDAddMetaObjectW(
  784. /* [in] */ METADATA_HANDLE hMDHandle,
  785. /* [string][in][unique] */ LPCWSTR pszMDPath)
  786. {
  787. STRAU strauPath;
  788. LPSTR pszPathA = NULL;
  789. if ( pszMDPath )
  790. {
  791. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  792. {
  793. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  794. }
  795. pszPathA = strauPath.QueryStrA();
  796. if (pszPathA == NULL) {
  797. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  798. }
  799. }
  800. return ComMDAddMetaObjectA( hMDHandle, (LPBYTE)pszPathA );
  801. }
  802. HRESULT
  803. NSEPCOM::ComMDDeleteMetaObjectA(
  804. IN METADATA_HANDLE hMDHandle,
  805. IN PBYTE pszMDPath
  806. )
  807. /*++
  808. Routine Description:
  809. Delete object
  810. Arguments:
  811. hMDHandle - open handle
  812. pszMDPath - path of object to delete
  813. Returns:
  814. status
  815. --*/
  816. {
  817. DWORD RetCode;
  818. CDirPath asPath;
  819. POPEN_CTX pOpenCtx;
  820. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  821. // BugFix: 117747 Whistler
  822. // Prefix bug pOpenCtx being used when it could be null
  823. // EBK 5/15/2000
  824. if (pOpenCtx == NULL)
  825. {
  826. RetCode = ERROR_INVALID_PARAMETER;
  827. }
  828. else if (g_dwInitialized == 0)
  829. {
  830. RetCode = MD_ERROR_NOT_INITIALIZED;
  831. }
  832. else if ((LPSTR)pszMDPath == NULL)
  833. {
  834. RetCode = ERROR_INVALID_PARAMETER;
  835. }
  836. else if ( !(pOpenCtx->GetAccess() & METADATA_PERMISSION_WRITE) )
  837. {
  838. RetCode = ERROR_ACCESS_DENIED;
  839. }
  840. else
  841. {
  842. if ( asPath.Set( pOpenCtx->GetPath() ) &&
  843. asPath.Append( (LPSTR)pszMDPath ) )
  844. {
  845. RetCode = NseDeleteObj( asPath.Get() ) ? ERROR_SUCCESS : GetLastError();
  846. }
  847. else
  848. {
  849. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  850. }
  851. }
  852. return ReturnCodeToHresult(RetCode);
  853. }
  854. HRESULT STDMETHODCALLTYPE
  855. NSEPCOM::ComMDDeleteMetaObjectW(
  856. /* [in] */ METADATA_HANDLE hMDHandle,
  857. /* [string][in][unique] */ LPCWSTR pszMDPath)
  858. {
  859. STRAU strauPath;
  860. LPSTR pszPathA = NULL;
  861. if ( pszMDPath )
  862. {
  863. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  864. {
  865. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  866. }
  867. pszPathA = strauPath.QueryStrA();
  868. if (pszPathA == NULL) {
  869. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  870. }
  871. }
  872. return ComMDDeleteMetaObjectA( hMDHandle, (LPBYTE)pszPathA );
  873. }
  874. HRESULT STDMETHODCALLTYPE
  875. NSEPCOM::ComMDDeleteChildMetaObjectsA(
  876. /* [in] */ METADATA_HANDLE hMDHandle,
  877. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath
  878. )
  879. /*++
  880. Routine Description:
  881. Not supported
  882. Arguments:
  883. Returns:
  884. error : either NSE not initialized or not supported
  885. --*/
  886. {
  887. DWORD RetCode;
  888. if (g_dwInitialized == 0)
  889. {
  890. RetCode = MD_ERROR_NOT_INITIALIZED;
  891. }
  892. else
  893. {
  894. RetCode = ERROR_NOT_SUPPORTED;
  895. }
  896. return ReturnCodeToHresult(RetCode);
  897. }
  898. HRESULT STDMETHODCALLTYPE
  899. NSEPCOM::ComMDDeleteChildMetaObjectsW(
  900. /* [in] */ METADATA_HANDLE hMDHandle,
  901. /* [string][in][unique] */ LPCWSTR pszMDPath)
  902. {
  903. STRAU strauPath;
  904. LPSTR pszPathA = NULL;
  905. if ( pszMDPath )
  906. {
  907. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  908. {
  909. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  910. }
  911. pszPathA = strauPath.QueryStrA();
  912. if (pszPathA == NULL) {
  913. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  914. }
  915. }
  916. return ComMDDeleteChildMetaObjectsA( hMDHandle, (LPBYTE)pszPathA );
  917. }
  918. HRESULT STDMETHODCALLTYPE
  919. NSEPCOM::ComMDEnumMetaObjectsA(
  920. /* [in] */ METADATA_HANDLE hMDHandle,
  921. /* [size_is][in] */ unsigned char __RPC_FAR *pszMDPath,
  922. /* [size_is][out] */ unsigned char __RPC_FAR *pszMDName,
  923. /* [in] */ DWORD dwMDEnumObjectIndex
  924. )
  925. /*++
  926. Routine Description:
  927. Enumerate objects in path
  928. Arguments:
  929. hMDHandle - open handle
  930. pszMDPath - path where to enumerate objects
  931. pszMDName - updated with object name
  932. dwMDEnumObjectIndex - object index ( 0 based )
  933. Returns:
  934. status
  935. --*/
  936. {
  937. DWORD RetCode;
  938. LPSTR pszPath = (LPSTR)pszMDPath;
  939. CDirPath asPath;
  940. POPEN_CTX pOpenCtx;
  941. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  942. // BugFix: 117725 Whistler
  943. // Prefix bug pOpenCtx being used when it could be null
  944. // EBK 5/15/2000
  945. if (pOpenCtx == NULL)
  946. {
  947. RetCode = ERROR_INVALID_PARAMETER;
  948. }
  949. else if (g_dwInitialized == 0)
  950. {
  951. RetCode = MD_ERROR_NOT_INITIALIZED;
  952. }
  953. else if ((LPSTR)pszMDName == NULL)
  954. {
  955. RetCode = ERROR_INVALID_PARAMETER;
  956. }
  957. else
  958. {
  959. if ( asPath.Set( pOpenCtx->GetPath() ) &&
  960. asPath.Append( (LPSTR)pszMDPath ) )
  961. {
  962. RetCode = NseEnumObj( asPath.Get(), pszMDName, dwMDEnumObjectIndex )
  963. ? ERROR_SUCCESS : GetLastError();
  964. }
  965. else
  966. {
  967. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  968. }
  969. }
  970. return ReturnCodeToHresult(RetCode);
  971. }
  972. HRESULT STDMETHODCALLTYPE
  973. NSEPCOM::ComMDEnumMetaObjectsW(
  974. /* [in] */ METADATA_HANDLE hMDHandle,
  975. /* [string][in][unique] */ LPCWSTR pszMDPath,
  976. /* [size_is][out] */ LPWSTR pszMDName,
  977. /* [in] */ DWORD dwMDEnumObjectIndex)
  978. {
  979. STRAU strauPath;
  980. STRAU strauName;
  981. LPSTR pszPathA = NULL;
  982. CHAR achNameA[METADATA_MAX_NAME_LEN];
  983. HRESULT hres;
  984. if ( pszMDPath )
  985. {
  986. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  987. {
  988. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  989. }
  990. pszPathA = strauPath.QueryStrA();
  991. if (pszPathA == NULL) {
  992. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  993. }
  994. }
  995. hres = ComMDEnumMetaObjectsA( hMDHandle, (LPBYTE)pszPathA, (LPBYTE)achNameA, dwMDEnumObjectIndex );
  996. if ( SUCCEEDED(hres) )
  997. {
  998. if ( (!strauName.Copy( achNameA )) || (strauName.QueryStrW() == NULL))
  999. {
  1000. hres = ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1001. }
  1002. else
  1003. {
  1004. memcpy( pszMDName, strauName.QueryStrW(), strauName.QueryCBW() + sizeof(WCHAR) );
  1005. }
  1006. }
  1007. return hres;
  1008. }
  1009. HRESULT STDMETHODCALLTYPE
  1010. NSEPCOM::ComMDCopyMetaObjectA(
  1011. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  1012. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDSourcePath,
  1013. /* [in] */ METADATA_HANDLE hMDDestHandle,
  1014. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDDestPath,
  1015. /* [in] */ BOOL bOverwriteFlag,
  1016. /* [in] */ BOOL bCopyFlag
  1017. )
  1018. /*++
  1019. Routine Description:
  1020. Not supported
  1021. Arguments:
  1022. Returns:
  1023. error : either NSE not initialized or not supported
  1024. --*/
  1025. {
  1026. DWORD RetCode = ERROR_SUCCESS;
  1027. if (g_dwInitialized == 0)
  1028. {
  1029. RetCode = MD_ERROR_NOT_INITIALIZED;
  1030. }
  1031. else
  1032. {
  1033. RetCode = ERROR_NOT_SUPPORTED;
  1034. }
  1035. return ReturnCodeToHresult(RetCode);
  1036. }
  1037. HRESULT STDMETHODCALLTYPE
  1038. NSEPCOM::ComMDCopyMetaObjectW(
  1039. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  1040. /* [string][in][unique] */ LPCWSTR pszMDSourcePath,
  1041. /* [in] */ METADATA_HANDLE hMDDestHandle,
  1042. /* [string][in][unique] */ LPCWSTR pszMDDestPath,
  1043. /* [in] */ BOOL bMDOverwriteFlag,
  1044. /* [in] */ BOOL bMDCopyFlag)
  1045. {
  1046. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1047. }
  1048. HRESULT STDMETHODCALLTYPE
  1049. NSEPCOM::ComMDRenameMetaObjectA(
  1050. /* [in] */ METADATA_HANDLE hMDHandle,
  1051. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  1052. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDNewName)
  1053. {
  1054. DWORD RetCode = ERROR_SUCCESS;
  1055. if (g_dwInitialized == 0)
  1056. {
  1057. RetCode = MD_ERROR_NOT_INITIALIZED;
  1058. }
  1059. else
  1060. {
  1061. RetCode = ERROR_NOT_SUPPORTED;
  1062. }
  1063. return ReturnCodeToHresult(RetCode);
  1064. }
  1065. HRESULT STDMETHODCALLTYPE
  1066. NSEPCOM::ComMDRenameMetaObjectW(
  1067. /* [in] */ METADATA_HANDLE hMDHandle,
  1068. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1069. /* [string][in][unique] */ LPCWSTR pszMDNewName)
  1070. {
  1071. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1072. }
  1073. HRESULT STDMETHODCALLTYPE
  1074. NSEPCOM::ComMDSetMetaDataA(
  1075. /* [in] */ METADATA_HANDLE hMDHandle,
  1076. /* [size_is][in] */ unsigned char __RPC_FAR *pszMDPath,
  1077. /* [in] */ PMETADATA_RECORD pmdrMDData
  1078. )
  1079. /*++
  1080. Routine Description:
  1081. Set property of object
  1082. Arguments:
  1083. hMDHandle - open handle
  1084. pszMDPath - path to object
  1085. pmdrMDData - metadata descriptor
  1086. Returns:
  1087. status
  1088. --*/
  1089. {
  1090. DWORD RetCode;
  1091. LPSTR pszPath = (LPSTR)pszMDPath;
  1092. CDirPath asPath;
  1093. POPEN_CTX pOpenCtx;
  1094. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  1095. // BugFix: 117743 Whistler
  1096. // Prefix bug pOpenCtx being used when it could be null
  1097. // EBK 5/15/2000
  1098. if (pOpenCtx == NULL)
  1099. {
  1100. RetCode = ERROR_INVALID_PARAMETER;
  1101. }
  1102. else if (g_dwInitialized == 0)
  1103. {
  1104. RetCode = MD_ERROR_NOT_INITIALIZED;
  1105. }
  1106. else if ( !( pOpenCtx->GetAccess() & METADATA_PERMISSION_WRITE) )
  1107. {
  1108. RetCode = ERROR_ACCESS_DENIED;
  1109. }
  1110. else
  1111. {
  1112. #if defined(TEST_ADMACL)
  1113. METADATA_HANDLE hMB;
  1114. HRESULT hRes;
  1115. hRes = g_pMdIf->ComMDOpenMetaObject( METADATA_MASTER_ROOT_HANDLE,
  1116. (BYTE *) "/LM/W3SVC/1",
  1117. METADATA_PERMISSION_READ,
  1118. 5000,
  1119. &hMB );
  1120. AdminAclNotifyOpen( hMB, (LPBYTE)"/LM/W3SVC/1", FALSE );
  1121. if ( SUCCEEDED( hRes ) )
  1122. {
  1123. BOOL fSt = AdminAclAccessCheck(
  1124. hMB,
  1125. pszMDPath,
  1126. pmdrMDData->dwMDIdentifier,
  1127. METADATA_PERMISSION_WRITE
  1128. );
  1129. AdminAclNotifyClose( hMB );
  1130. g_pMdIf->ComMDCloseMetaObject( hMB );
  1131. if ( !fSt )
  1132. {
  1133. return ReturnCodeToHresult( ERROR_ACCESS_DENIED );
  1134. }
  1135. }
  1136. AdminAclNotifyOpen( hMDHandle, (LPBYTE)"/LM/W3SVC/1/<nsepm>/", TRUE );
  1137. AdminAclAccessCheck(
  1138. hMDHandle,
  1139. pszMDPath,
  1140. pmdrMDData->dwMDIdentifier,
  1141. METADATA_PERMISSION_WRITE
  1142. );
  1143. AdminAclNotifyClose( hMDHandle );
  1144. #endif
  1145. if ( asPath.Set( pOpenCtx->GetPath() ) &&
  1146. asPath.Append( (LPSTR)pszMDPath ) )
  1147. {
  1148. RetCode = NseSetProp( asPath.Get(), pmdrMDData )
  1149. ? ERROR_SUCCESS : GetLastError();
  1150. }
  1151. else
  1152. {
  1153. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1154. }
  1155. }
  1156. return ReturnCodeToHresult(RetCode);
  1157. }
  1158. HRESULT STDMETHODCALLTYPE
  1159. NSEPCOM::ComMDSetMetaDataW(
  1160. /* [in] */ METADATA_HANDLE hMDHandle,
  1161. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1162. /* [in] */ PMETADATA_RECORD pmdrMDData)
  1163. {
  1164. STRAU strauPath;
  1165. LPSTR pszPathA = NULL;
  1166. if ( pszMDPath )
  1167. {
  1168. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  1169. {
  1170. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1171. }
  1172. pszPathA = strauPath.QueryStrA();
  1173. if (pszPathA == NULL) {
  1174. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1175. }
  1176. }
  1177. return ComMDSetMetaDataA( hMDHandle, (LPBYTE)pszPathA, pmdrMDData );
  1178. }
  1179. HRESULT STDMETHODCALLTYPE
  1180. NSEPCOM::ComMDGetMetaDataA(
  1181. /* [in] */ METADATA_HANDLE hMDHandle,
  1182. /* [string][in] */ unsigned char __RPC_FAR *pszMDPath,
  1183. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  1184. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen
  1185. )
  1186. /*++
  1187. Routine Description:
  1188. Get property of object
  1189. Arguments:
  1190. hMDHandle - open handle
  1191. pszMDPath - path to object
  1192. pmdrMDData - metadata descriptor
  1193. pdwMDRequiredDataLen - updated with required length to get property
  1194. Returns:
  1195. status
  1196. --*/
  1197. {
  1198. DWORD RetCode;
  1199. CDirPath asPath;
  1200. LPSTR pszPath = (LPSTR)pszMDPath;
  1201. POPEN_CTX pOpenCtx;
  1202. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  1203. // BugFix: 117745 Whistler
  1204. // Prefix bug pOpenCtx being used when it could be null
  1205. // EBK 5/15/2000
  1206. if (pOpenCtx == NULL)
  1207. {
  1208. RetCode = ERROR_INVALID_PARAMETER;
  1209. }
  1210. else if (g_dwInitialized == 0)
  1211. {
  1212. RetCode = MD_ERROR_NOT_INITIALIZED;
  1213. }
  1214. else if ((pmdrMDData == NULL) ||
  1215. ((pmdrMDData->dwMDDataLen != 0) && (pmdrMDData->pbMDData == NULL)) ||
  1216. ((pmdrMDData->dwMDAttributes & METADATA_PARTIAL_PATH) &&
  1217. !(pmdrMDData->dwMDAttributes & METADATA_INHERIT)))
  1218. {
  1219. RetCode = ERROR_INVALID_PARAMETER;
  1220. }
  1221. else
  1222. {
  1223. if ( asPath.Set( hMDHandle ? pOpenCtx->GetPath() : "" ) &&
  1224. asPath.Append( pszMDPath ? (LPSTR)pszMDPath : "" ))
  1225. {
  1226. RetCode = NseGetProp( asPath.Get(), pmdrMDData, pdwMDRequiredDataLen )
  1227. ? ERROR_SUCCESS : GetLastError();
  1228. }
  1229. else
  1230. {
  1231. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1232. }
  1233. }
  1234. return ReturnCodeToHresult(RetCode);
  1235. }
  1236. HRESULT STDMETHODCALLTYPE
  1237. NSEPCOM::ComMDGetMetaDataW(
  1238. /* [in] */ METADATA_HANDLE hMDHandle,
  1239. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1240. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  1241. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen)
  1242. {
  1243. STRAU strauPath;
  1244. LPSTR pszPathA = NULL;
  1245. if ( pszMDPath )
  1246. {
  1247. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  1248. {
  1249. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1250. }
  1251. pszPathA = strauPath.QueryStrA();
  1252. if (pszPathA == NULL) {
  1253. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1254. }
  1255. }
  1256. return ComMDGetMetaDataA( hMDHandle, (LPBYTE)pszPathA, pmdrMDData, pdwMDRequiredDataLen );
  1257. }
  1258. HRESULT STDMETHODCALLTYPE
  1259. NSEPCOM::ComMDEnumMetaDataA(
  1260. /* [in] */ METADATA_HANDLE hMDHandle,
  1261. /* [string][in] */ unsigned char __RPC_FAR *pszMDPath,
  1262. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  1263. /* [in] */ DWORD dwMDEnumDataIndex,
  1264. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen
  1265. )
  1266. /*++
  1267. Routine Description:
  1268. Enumerate properties of object
  1269. Arguments:
  1270. hMDHandle - open handle
  1271. pszMDPath - path to object
  1272. pmdrMDData - metadata descriptor
  1273. dwMDEnumDataIndex - index to property
  1274. pdwMDRequiredDataLen - updated with required length to get property
  1275. Returns:
  1276. status
  1277. --*/
  1278. {
  1279. DWORD RetCode;
  1280. LPSTR pszPath = (LPSTR)pszMDPath;
  1281. CDirPath asPath;
  1282. POPEN_CTX pOpenCtx;
  1283. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  1284. // BugFix: 117715 Whistler
  1285. // Prefix bug pOpenCtx being used when it could be null
  1286. // EBK 5/15/2000
  1287. if (pOpenCtx == NULL)
  1288. {
  1289. RetCode = ERROR_INVALID_PARAMETER;
  1290. }
  1291. else if (g_dwInitialized == 0)
  1292. {
  1293. RetCode = MD_ERROR_NOT_INITIALIZED;
  1294. }
  1295. else if ((pmdrMDData == NULL) ||
  1296. ((pmdrMDData->dwMDDataLen != 0) && (pmdrMDData->pbMDData == NULL)) ||
  1297. ((pmdrMDData->dwMDAttributes & METADATA_PARTIAL_PATH) &&
  1298. !(pmdrMDData->dwMDAttributes & METADATA_INHERIT)))
  1299. {
  1300. RetCode = ERROR_INVALID_PARAMETER;
  1301. }
  1302. else
  1303. {
  1304. if ( asPath.Set( pOpenCtx->GetPath() ) &&
  1305. asPath.Append( (LPSTR)pszMDPath ) )
  1306. {
  1307. RetCode = NseGetPropByIndex( asPath.Get(), pmdrMDData, dwMDEnumDataIndex, pdwMDRequiredDataLen )
  1308. ? ERROR_SUCCESS : GetLastError();
  1309. }
  1310. else
  1311. {
  1312. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1313. }
  1314. }
  1315. return ReturnCodeToHresult(RetCode);
  1316. }
  1317. HRESULT STDMETHODCALLTYPE
  1318. NSEPCOM::ComMDEnumMetaDataW(
  1319. /* [in] */ METADATA_HANDLE hMDHandle,
  1320. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1321. /* [out][in] */ PMETADATA_RECORD pmdrMDData,
  1322. /* [in] */ DWORD dwMDEnumDataIndex,
  1323. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredDataLen)
  1324. {
  1325. STRAU strauPath;
  1326. LPSTR pszPathA = NULL;
  1327. if ( pszMDPath )
  1328. {
  1329. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  1330. {
  1331. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1332. }
  1333. pszPathA = strauPath.QueryStrA();
  1334. if (pszPathA == NULL) {
  1335. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1336. }
  1337. }
  1338. return ComMDEnumMetaDataA( hMDHandle, (LPBYTE)pszPathA, pmdrMDData, dwMDEnumDataIndex, pdwMDRequiredDataLen );
  1339. }
  1340. HRESULT STDMETHODCALLTYPE
  1341. NSEPCOM::ComMDDeleteMetaDataA(
  1342. /* [in] */ METADATA_HANDLE hMDHandle,
  1343. /* [string][in] */ unsigned char __RPC_FAR *pszMDPath,
  1344. /* [in] */ DWORD dwMDIdentifier,
  1345. /* [in] */ DWORD dwMDDataType
  1346. )
  1347. /*++
  1348. Routine Description:
  1349. Not supported
  1350. Arguments:
  1351. Returns:
  1352. error : either NSE not initialized or not supported
  1353. --*/
  1354. {
  1355. DWORD RetCode;
  1356. LPSTR pszPath = (LPSTR)pszMDPath;
  1357. if (g_dwInitialized == 0)
  1358. {
  1359. RetCode = MD_ERROR_NOT_INITIALIZED;
  1360. }
  1361. else
  1362. {
  1363. RetCode = ERROR_NOT_SUPPORTED;
  1364. }
  1365. return ReturnCodeToHresult(RetCode);
  1366. }
  1367. HRESULT STDMETHODCALLTYPE
  1368. NSEPCOM::ComMDDeleteMetaDataW(
  1369. /* [in] */ METADATA_HANDLE hMDHandle,
  1370. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1371. /* [in] */ DWORD dwMDIdentifier,
  1372. /* [in] */ DWORD dwMDDataType)
  1373. {
  1374. STRAU strauPath;
  1375. LPSTR pszPathA = NULL;
  1376. if ( pszMDPath )
  1377. {
  1378. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  1379. {
  1380. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1381. }
  1382. pszPathA = strauPath.QueryStrA();
  1383. if (pszPathA == NULL) {
  1384. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1385. }
  1386. }
  1387. return ComMDDeleteMetaDataA( hMDHandle, (LPBYTE)pszPathA, dwMDIdentifier, dwMDDataType );
  1388. }
  1389. HRESULT STDMETHODCALLTYPE
  1390. NSEPCOM::ComMDGetAllMetaDataA(
  1391. /* [in] */ METADATA_HANDLE hMDHandle,
  1392. /* [string][in] */ unsigned char __RPC_FAR *pszMDPath,
  1393. /* [in] */ DWORD dwMDAttributes,
  1394. /* [in] */ DWORD dwMDUserType,
  1395. /* [in] */ DWORD dwMDDataType,
  1396. /* [out] */ DWORD __RPC_FAR *pdwMDNumDataEntries,
  1397. /* [out] */ DWORD __RPC_FAR *pdwMDDataSetNumber,
  1398. /* [in] */ DWORD dwMDBufferSize,
  1399. /* [size_is][out] */ unsigned char __RPC_FAR *pbBuffer,
  1400. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize
  1401. )
  1402. /*++
  1403. Routine Description:
  1404. Get all properties of object
  1405. Arguments:
  1406. hMDHandle - open handle
  1407. pszMDPath - path to object
  1408. dwMDAttributes - metadata attribute, ignored
  1409. dwMDUserType - metadata user type, ignored
  1410. dwMDDataType - metadata data type, ignored
  1411. pdwMDNumDataEntries - updated with count of properties
  1412. pdwMDDataSetNumber - ignored
  1413. dwMDBufferSize - size of pbBuffer
  1414. pbBuffer - buffer where to store properties descriptor and values
  1415. pdwMDRequiredBufferSize - updated with required length of buffer
  1416. Returns:
  1417. status
  1418. --*/
  1419. {
  1420. DWORD RetCode;
  1421. CDirPath asPath;
  1422. POPEN_CTX pOpenCtx;
  1423. pOpenCtx = OPEN_CTX::MapHandleToContext( hMDHandle );
  1424. // BugFix: 117707 Whistler
  1425. // Prefix bug pOpenCtx being used when it could be null
  1426. // EBK 5/15/2000
  1427. if (pOpenCtx == NULL)
  1428. {
  1429. RetCode = ERROR_INVALID_PARAMETER;
  1430. }
  1431. else if (g_dwInitialized == 0)
  1432. {
  1433. RetCode = MD_ERROR_NOT_INITIALIZED;
  1434. }
  1435. else if ((pdwMDNumDataEntries == NULL) || ((dwMDBufferSize != 0) && (pbBuffer == NULL)) ||
  1436. ((dwMDAttributes & METADATA_PARTIAL_PATH) && !(dwMDAttributes & METADATA_INHERIT)))
  1437. {
  1438. RetCode = ERROR_INVALID_PARAMETER;
  1439. }
  1440. else
  1441. {
  1442. if ( asPath.Set( pOpenCtx->GetPath() ) &&
  1443. asPath.Append( (LPSTR)pszMDPath ) )
  1444. {
  1445. RetCode = NseGetAllProp( asPath.Get(),
  1446. dwMDAttributes,
  1447. dwMDUserType,
  1448. dwMDDataType,
  1449. pdwMDNumDataEntries,
  1450. pdwMDDataSetNumber,
  1451. dwMDBufferSize,
  1452. pbBuffer,
  1453. pdwMDRequiredBufferSize
  1454. )
  1455. ? ERROR_SUCCESS : GetLastError();
  1456. }
  1457. else
  1458. {
  1459. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1460. }
  1461. }
  1462. return ReturnCodeToHresult(RetCode);
  1463. }
  1464. HRESULT STDMETHODCALLTYPE
  1465. NSEPCOM::ComMDGetAllMetaDataW(
  1466. /* [in] */ METADATA_HANDLE hMDHandle,
  1467. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1468. /* [in] */ DWORD dwMDAttributes,
  1469. /* [in] */ DWORD dwMDUserType,
  1470. /* [in] */ DWORD dwMDDataType,
  1471. /* [out] */ DWORD __RPC_FAR *pdwMDNumDataEntries,
  1472. /* [out] */ DWORD __RPC_FAR *pdwMDDataSetNumber,
  1473. /* [in] */ DWORD dwMDBufferSize,
  1474. /* [size_is][out] */ unsigned char __RPC_FAR *pbBuffer,
  1475. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize)
  1476. {
  1477. STRAU strauPath;
  1478. LPSTR pszPathA = NULL;
  1479. if ( pszMDPath )
  1480. {
  1481. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  1482. {
  1483. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1484. }
  1485. pszPathA = strauPath.QueryStrA();
  1486. if (pszPathA == NULL) {
  1487. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1488. }
  1489. }
  1490. return ComMDGetAllMetaDataA( hMDHandle,
  1491. (LPBYTE)pszPathA,
  1492. dwMDAttributes,
  1493. dwMDUserType,
  1494. dwMDDataType,
  1495. pdwMDNumDataEntries,
  1496. pdwMDDataSetNumber,
  1497. dwMDBufferSize,
  1498. pbBuffer,
  1499. pdwMDRequiredBufferSize );
  1500. }
  1501. HRESULT STDMETHODCALLTYPE
  1502. NSEPCOM::ComMDDeleteAllMetaDataA(
  1503. /* [in] */ METADATA_HANDLE hMDHandle,
  1504. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  1505. /* [in] */ DWORD dwMDUserType,
  1506. /* [in] */ DWORD dwMDDataType
  1507. )
  1508. /*++
  1509. Routine Description:
  1510. Not supported
  1511. Arguments:
  1512. Returns:
  1513. error : either NSE not initialized or not supported
  1514. --*/
  1515. {
  1516. DWORD RetCode;
  1517. if (g_dwInitialized == 0)
  1518. {
  1519. RetCode = MD_ERROR_NOT_INITIALIZED;
  1520. }
  1521. else
  1522. {
  1523. RetCode = ERROR_NOT_SUPPORTED;
  1524. }
  1525. return ReturnCodeToHresult(RetCode);
  1526. }
  1527. HRESULT STDMETHODCALLTYPE
  1528. NSEPCOM::ComMDDeleteAllMetaDataW(
  1529. /* [in] */ METADATA_HANDLE hMDHandle,
  1530. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1531. /* [in] */ DWORD dwMDUserType,
  1532. /* [in] */ DWORD dwMDDataType)
  1533. {
  1534. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1535. }
  1536. HRESULT STDMETHODCALLTYPE
  1537. NSEPCOM::ComMDCopyMetaDataA(
  1538. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  1539. /* [string][in] */ unsigned char __RPC_FAR *pszMDSourcePath,
  1540. /* [in] */ METADATA_HANDLE hMDDestHandle,
  1541. /* [string][in] */ unsigned char __RPC_FAR *pszMDDestPath,
  1542. /* [in] */ DWORD dwMDAttributes,
  1543. /* [in] */ DWORD dwMDUserType,
  1544. /* [in] */ DWORD dwMDDataType,
  1545. /* [in] */ BOOL bCopyFlag
  1546. )
  1547. /*++
  1548. Routine Description:
  1549. Not supported
  1550. Arguments:
  1551. Returns:
  1552. error : either NSE not initialized or not supported
  1553. --*/
  1554. {
  1555. DWORD RetCode;
  1556. if (g_dwInitialized == 0)
  1557. {
  1558. RetCode = MD_ERROR_NOT_INITIALIZED;
  1559. }
  1560. else if (((!bCopyFlag) && (dwMDAttributes & METADATA_INHERIT)) ||
  1561. ((dwMDAttributes & METADATA_PARTIAL_PATH) && !(dwMDAttributes & METADATA_INHERIT)))
  1562. {
  1563. RetCode = ERROR_INVALID_PARAMETER;
  1564. }
  1565. else
  1566. {
  1567. RetCode = ERROR_NOT_SUPPORTED;
  1568. }
  1569. return ReturnCodeToHresult(RetCode);
  1570. }
  1571. HRESULT STDMETHODCALLTYPE
  1572. NSEPCOM::ComMDCopyMetaDataW(
  1573. /* [in] */ METADATA_HANDLE hMDSourceHandle,
  1574. /* [string][in][unique] */ LPCWSTR pszMDSourcePath,
  1575. /* [in] */ METADATA_HANDLE hMDDestHandle,
  1576. /* [string][in][unique] */ LPCWSTR pszMDDestPath,
  1577. /* [in] */ DWORD dwMDAttributes,
  1578. /* [in] */ DWORD dwMDUserType,
  1579. /* [in] */ DWORD dwMDDataType,
  1580. /* [in] */ BOOL bMDCopyFlag)
  1581. {
  1582. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1583. }
  1584. HRESULT STDMETHODCALLTYPE
  1585. NSEPCOM::ComMDGetMetaDataPathsA(
  1586. /* [in] */ METADATA_HANDLE hMDHandle,
  1587. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  1588. /* [in] */ DWORD dwMDIdentifier,
  1589. /* [in] */ DWORD dwMDDataType,
  1590. /* [in] */ DWORD dwMDBufferSize,
  1591. /* [size_is][out] */ unsigned char __RPC_FAR *pszMDBuffer,
  1592. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize)
  1593. {
  1594. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1595. }
  1596. HRESULT STDMETHODCALLTYPE
  1597. NSEPCOM::ComMDGetMetaDataPathsW(
  1598. /* [in] */ METADATA_HANDLE hMDHandle,
  1599. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1600. /* [in] */ DWORD dwMDIdentifier,
  1601. /* [in] */ DWORD dwMDDataType,
  1602. /* [in] */ DWORD dwMDBufferSize,
  1603. /* [size_is][out] */ LPWSTR pszMDBuffer,
  1604. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize)
  1605. {
  1606. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1607. }
  1608. HRESULT STDMETHODCALLTYPE
  1609. NSEPCOM::ComMDOpenMetaObjectA(
  1610. /* [in] */ METADATA_HANDLE hMDHandle,
  1611. /* [string][in] */ unsigned char __RPC_FAR *pszMDPath,
  1612. /* [in] */ DWORD dwMDAccessRequested,
  1613. /* [in] */ DWORD dwMDTimeOut,
  1614. /* [out] */ PMETADATA_HANDLE phMDNewHandle
  1615. )
  1616. /*++
  1617. Routine Description:
  1618. Open access to metadata
  1619. Arguments:
  1620. hMDHandle - open handle where to open
  1621. pszMDPath - path to open
  1622. dwMDAccessRequested - access rights, ignored
  1623. dwMDTimeOut - ignored
  1624. phMDNewHandle - updated with new handle
  1625. Returns:
  1626. status
  1627. --*/
  1628. {
  1629. DWORD RetCode;
  1630. POPEN_CTX pOpCtx;
  1631. if (g_dwInitialized == 0)
  1632. {
  1633. RetCode = MD_ERROR_NOT_INITIALIZED;
  1634. }
  1635. else if ((phMDNewHandle == NULL) || ((dwMDAccessRequested & (METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE)) == 0))
  1636. {
  1637. RetCode = ERROR_INVALID_PARAMETER;
  1638. }
  1639. else
  1640. {
  1641. if ( pOpCtx = new OPEN_CTX(dwMDAccessRequested) )
  1642. {
  1643. if ( pOpCtx->GetHandle() &&
  1644. pOpCtx->SetPath( "" ) &&
  1645. pOpCtx->AppendPath( pszMDPath ? (LPSTR)pszMDPath : "") )
  1646. {
  1647. CDirPath asTemp;
  1648. asTemp.Set( pOpCtx->GetPath() );
  1649. for ( ;; )
  1650. {
  1651. // BugFix: 117700 Whistler
  1652. // Prefix bug asTemp.Get being null
  1653. // EBK 5/15/2000
  1654. if (asTemp.Get() == NULL)
  1655. {
  1656. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1657. break;
  1658. }
  1659. if ( NseOpenObjs( asTemp.Get() ) )
  1660. {
  1661. *phMDNewHandle = pOpCtx->GetHandle();
  1662. RetCode = ERROR_SUCCESS;
  1663. break;
  1664. }
  1665. else
  1666. {
  1667. RetCode = GetLastError();
  1668. if ( RetCode == ERROR_PATH_BUSY &&
  1669. dwMDTimeOut )
  1670. {
  1671. DWORD dwDelay = min( dwMDTimeOut, 100 );
  1672. Sleep( dwDelay );
  1673. dwMDTimeOut -= dwDelay;
  1674. }
  1675. else
  1676. {
  1677. break;
  1678. }
  1679. }
  1680. }
  1681. if ( RetCode != ERROR_SUCCESS )
  1682. {
  1683. delete pOpCtx;
  1684. }
  1685. }
  1686. else
  1687. {
  1688. delete pOpCtx;
  1689. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1690. }
  1691. }
  1692. else
  1693. {
  1694. RetCode = ERROR_NOT_ENOUGH_MEMORY;
  1695. }
  1696. }
  1697. return ReturnCodeToHresult(RetCode);
  1698. }
  1699. HRESULT STDMETHODCALLTYPE
  1700. NSEPCOM::ComMDOpenMetaObjectW(
  1701. /* [in] */ METADATA_HANDLE hMDHandle,
  1702. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1703. /* [in] */ DWORD dwMDAccessRequested,
  1704. /* [in] */ DWORD dwMDTimeOut,
  1705. /* [out] */ PMETADATA_HANDLE phMDNewHandle)
  1706. {
  1707. STRAU strauPath;
  1708. LPSTR pszPathA = NULL;
  1709. if ( pszMDPath )
  1710. {
  1711. if ( !strauPath.Copy( (LPWSTR)pszMDPath ) )
  1712. {
  1713. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1714. }
  1715. pszPathA = strauPath.QueryStrA();
  1716. if (pszPathA == NULL) {
  1717. return ReturnCodeToHresult(ERROR_NOT_ENOUGH_MEMORY);
  1718. }
  1719. }
  1720. return ComMDOpenMetaObjectA( hMDHandle,
  1721. (LPBYTE)pszPathA,
  1722. dwMDAccessRequested,
  1723. dwMDTimeOut,
  1724. phMDNewHandle );
  1725. }
  1726. HRESULT STDMETHODCALLTYPE
  1727. NSEPCOM::ComMDCloseMetaObject(
  1728. /* [in] */ METADATA_HANDLE hMDHandle
  1729. )
  1730. /*++
  1731. Routine Description:
  1732. Close access to metadata
  1733. Arguments:
  1734. hMDHandle - open handle to close
  1735. Returns:
  1736. status
  1737. --*/
  1738. {
  1739. DWORD RetCode;
  1740. BOOL bPulseWrite = FALSE;
  1741. BOOL bPulseRead = FALSE;
  1742. if (g_dwInitialized == 0)
  1743. {
  1744. RetCode = MD_ERROR_NOT_INITIALIZED;
  1745. }
  1746. else
  1747. {
  1748. NseCloseObjs( TRUE );
  1749. delete OPEN_CTX::MapHandleToContext( hMDHandle );
  1750. RetCode = ERROR_SUCCESS;
  1751. }
  1752. return ReturnCodeToHresult(RetCode);
  1753. }
  1754. HRESULT STDMETHODCALLTYPE
  1755. NSEPCOM::ComMDChangePermissions(
  1756. /* [in] */ METADATA_HANDLE hMDHandle,
  1757. /* [in] */ DWORD dwMDTimeOut,
  1758. /* [in] */ DWORD dwMDAccessRequested
  1759. )
  1760. /*++
  1761. Routine Description:
  1762. Not supported
  1763. Arguments:
  1764. Returns:
  1765. error : either NSE not initialized or not supported
  1766. --*/
  1767. {
  1768. DWORD RetCode = ERROR_SUCCESS;
  1769. if (g_dwInitialized == 0)
  1770. {
  1771. RetCode = MD_ERROR_NOT_INITIALIZED;
  1772. }
  1773. else
  1774. {
  1775. RetCode = ERROR_NOT_SUPPORTED;
  1776. }
  1777. return ReturnCodeToHresult(RetCode);
  1778. }
  1779. HRESULT STDMETHODCALLTYPE
  1780. NSEPCOM::ComMDSaveData(
  1781. METADATA_HANDLE hMDHandle
  1782. )
  1783. /*++
  1784. Routine Description:
  1785. Save data to persistent storage
  1786. Arguments:
  1787. None
  1788. Returns:
  1789. status
  1790. --*/
  1791. {
  1792. DWORD RetCode = ERROR_SUCCESS;
  1793. if (g_dwInitialized == 0)
  1794. {
  1795. RetCode = MD_ERROR_NOT_INITIALIZED;
  1796. }
  1797. else
  1798. {
  1799. if ( !NseSaveObjs() )
  1800. {
  1801. RetCode = GetLastError();
  1802. }
  1803. }
  1804. return ReturnCodeToHresult(RetCode);
  1805. }
  1806. HRESULT STDMETHODCALLTYPE
  1807. NSEPCOM::ComMDGetHandleInfo(
  1808. /* [in] */ METADATA_HANDLE hMDHandle,
  1809. /* [out] */ PMETADATA_HANDLE_INFO pmdhiInfo
  1810. )
  1811. /*++
  1812. Routine Description:
  1813. Not supported
  1814. Arguments:
  1815. Returns:
  1816. error : either NSE not initialized or not supported
  1817. --*/
  1818. {
  1819. DWORD RetCode = ERROR_SUCCESS;
  1820. if (g_dwInitialized == 0)
  1821. {
  1822. RetCode = MD_ERROR_NOT_INITIALIZED;
  1823. }
  1824. else if (pmdhiInfo == NULL)
  1825. {
  1826. RetCode = ERROR_INVALID_PARAMETER;
  1827. }
  1828. else
  1829. {
  1830. RetCode = ERROR_NOT_SUPPORTED;
  1831. }
  1832. return ReturnCodeToHresult(RetCode);
  1833. }
  1834. HRESULT STDMETHODCALLTYPE
  1835. NSEPCOM::ComMDGetSystemChangeNumber(
  1836. /* [out] */ DWORD __RPC_FAR *pdwSystemChangeNumber
  1837. )
  1838. /*++
  1839. Routine Description:
  1840. Not supported
  1841. Arguments:
  1842. Returns:
  1843. error : either NSE not initialized or not supported
  1844. --*/
  1845. {
  1846. DWORD RetCode = ERROR_SUCCESS;
  1847. if (g_dwInitialized == 0)
  1848. {
  1849. RetCode = MD_ERROR_NOT_INITIALIZED;
  1850. }
  1851. else if (pdwSystemChangeNumber == NULL)
  1852. {
  1853. RetCode = ERROR_INVALID_PARAMETER;
  1854. }
  1855. else
  1856. {
  1857. RetCode = ERROR_NOT_SUPPORTED;
  1858. }
  1859. return ReturnCodeToHresult(RetCode);
  1860. }
  1861. HRESULT STDMETHODCALLTYPE
  1862. NSEPCOM::ComMDGetDataSetNumberA(
  1863. /* [in] */ METADATA_HANDLE hMDHandle,
  1864. /* [string][in] */ unsigned char __RPC_FAR *pszMDPath,
  1865. /* [out] */ DWORD __RPC_FAR *pdwMDDataSetNumber
  1866. )
  1867. /*++
  1868. Routine Description:
  1869. Not supported
  1870. Arguments:
  1871. Returns:
  1872. error : either NSE not initialized or not supported
  1873. --*/
  1874. {
  1875. DWORD RetCode;
  1876. LPSTR pszPath = (LPSTR)pszMDPath;
  1877. if (g_dwInitialized == 0)
  1878. {
  1879. RetCode = MD_ERROR_NOT_INITIALIZED;
  1880. }
  1881. else if (pdwMDDataSetNumber == NULL)
  1882. {
  1883. RetCode = ERROR_INVALID_PARAMETER;
  1884. }
  1885. else
  1886. {
  1887. RetCode = ERROR_NOT_SUPPORTED;
  1888. }
  1889. return ReturnCodeToHresult(RetCode);
  1890. }
  1891. HRESULT STDMETHODCALLTYPE
  1892. NSEPCOM::ComMDGetDataSetNumberW(
  1893. /* [in] */ METADATA_HANDLE hMDHandle,
  1894. /* [string][in][unique] */ LPCWSTR pszMDPath,
  1895. /* [out] */ DWORD __RPC_FAR *pdwMDDataSetNumber)
  1896. {
  1897. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  1898. }
  1899. HRESULT STDMETHODCALLTYPE
  1900. NSEPCOM::ComMDAddRefReferenceData(
  1901. /* [in] */ DWORD dwMDDataTag
  1902. )
  1903. /*++
  1904. Routine Description:
  1905. Not supported
  1906. Arguments:
  1907. Returns:
  1908. error : either NSE not initialized or not supported
  1909. --*/
  1910. {
  1911. DWORD RetCode = ERROR_SUCCESS;
  1912. if (g_dwInitialized == 0)
  1913. {
  1914. RetCode = MD_ERROR_NOT_INITIALIZED;
  1915. }
  1916. else if (dwMDDataTag == 0)
  1917. {
  1918. RetCode = ERROR_INVALID_PARAMETER;
  1919. }
  1920. else
  1921. {
  1922. RetCode = ERROR_NOT_SUPPORTED;
  1923. }
  1924. return ReturnCodeToHresult(RetCode);
  1925. }
  1926. HRESULT STDMETHODCALLTYPE
  1927. NSEPCOM::ComMDReleaseReferenceData(
  1928. /* [in] */ DWORD dwMDDataTag
  1929. )
  1930. /*++
  1931. Routine Description:
  1932. Not supported
  1933. Arguments:
  1934. Returns:
  1935. error : either NSE not initialized or not supported
  1936. --*/
  1937. {
  1938. DWORD RetCode = ERROR_SUCCESS;
  1939. if (g_dwInitialized == 0)
  1940. {
  1941. RetCode = MD_ERROR_NOT_INITIALIZED;
  1942. }
  1943. else if (dwMDDataTag == 0)
  1944. {
  1945. RetCode = ERROR_INVALID_PARAMETER;
  1946. }
  1947. else
  1948. {
  1949. RetCode = ERROR_NOT_SUPPORTED;
  1950. }
  1951. return ReturnCodeToHresult(RetCode);
  1952. }
  1953. inline HRESULT
  1954. NSEPCOM::ReturnCodeToHresult(
  1955. DWORD dwReturnCode
  1956. )
  1957. /*++
  1958. Routine Description:
  1959. Convert NT error code to HRESULT
  1960. Arguments:
  1961. dwReturnCode - NT Error code
  1962. Return Value:
  1963. HRESULT
  1964. --*/
  1965. {
  1966. DWORD hrReturn;
  1967. if (dwReturnCode < 0x10000)
  1968. {
  1969. hrReturn = HRESULT_FROM_WIN32(dwReturnCode);
  1970. }
  1971. else
  1972. {
  1973. hrReturn = (DWORD)E_FAIL;
  1974. }
  1975. return(hrReturn);
  1976. }
  1977. HRESULT STDMETHODCALLTYPE
  1978. NSEPCOM::ComMDSetLastChangeTimeA(
  1979. /* [in] */ METADATA_HANDLE hMDHandle,
  1980. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  1981. /* [in] */ PFILETIME pftMDLastChangeTime
  1982. )
  1983. /*++
  1984. Routine Description:
  1985. Set the last change time associated with a Meta Object.
  1986. Arguments:
  1987. Handle - METADATA_MASTER_ROOT_HANDLE or a handle returned by MDOpenMetaObject with write permission.
  1988. Path - The path of the affected meta object, relative to the path of Handle.
  1989. LastChangeTime - The new change time for the meta object.
  1990. Return Value:
  1991. DWORD - ERROR_SUCCESS
  1992. MD_ERROR_NOT_INITIALIZED
  1993. ERROR_INVALID_PARAMETER
  1994. ERROR_PATH_NOT_FOUND
  1995. ERROR_NOT_SUPPORTED
  1996. Notes:
  1997. Last change times are also updated whenever data or child objects are set, added, or deleted.
  1998. --*/
  1999. {
  2000. DWORD RetCode = ERROR_NOT_SUPPORTED;
  2001. return RETURNCODETOHRESULT(RetCode);
  2002. }
  2003. HRESULT STDMETHODCALLTYPE
  2004. NSEPCOM::ComMDSetLastChangeTimeW(
  2005. /* [in] */ METADATA_HANDLE hMDHandle,
  2006. /* [string][in][unique] */ LPCWSTR pszMDPath,
  2007. /* [in] */ PFILETIME pftMDLastChangeTime)
  2008. {
  2009. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2010. }
  2011. HRESULT STDMETHODCALLTYPE
  2012. NSEPCOM::ComMDGetLastChangeTimeA(
  2013. /* [in] */ METADATA_HANDLE hMDHandle,
  2014. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDPath,
  2015. /* [out] */ PFILETIME pftMDLastChangeTime
  2016. )
  2017. /*++
  2018. Routine Description:
  2019. Set the last change time associated with a Meta Object.
  2020. Arguments:
  2021. Handle - METADATA_MASTER_ROOT_HANDLE or a handle returned by MDOpenMetaObject with write permission.
  2022. Path - The path of the affected meta object, relative to the path of Handle.
  2023. LastChangeTime - Place to return the change time for the meta object.
  2024. Return Value:
  2025. DWORD - ERROR_SUCCESS
  2026. MD_ERROR_NOT_INITIALIZED
  2027. ERROR_INVALID_PARAMETER
  2028. ERROR_PATH_NOT_FOUND
  2029. ERROR_NOT_SUPPORTED
  2030. Notes:
  2031. Last change times are also updated whenever data or child objects are set, added, or deleted.
  2032. --*/
  2033. {
  2034. DWORD RetCode = ERROR_NOT_SUPPORTED;
  2035. return RETURNCODETOHRESULT(RetCode);
  2036. }
  2037. HRESULT STDMETHODCALLTYPE
  2038. NSEPCOM::ComMDGetLastChangeTimeW(
  2039. /* [in] */ METADATA_HANDLE hMDHandle,
  2040. /* [string][in][unique] */ LPCWSTR pszMDPath,
  2041. /* [out] */ PFILETIME pftMDLastChangeTime)
  2042. {
  2043. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2044. }
  2045. HRESULT STDMETHODCALLTYPE
  2046. NSEPCOM::ComMDBackupA(
  2047. /* [in] */ METADATA_HANDLE hMDHandle,
  2048. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDBackupLocation,
  2049. /* [in] */ DWORD dwMDVersion,
  2050. /* [in] */ DWORD dwMDFlags)
  2051. {
  2052. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2053. }
  2054. HRESULT STDMETHODCALLTYPE
  2055. NSEPCOM::ComMDBackupW(
  2056. /* [in] */ METADATA_HANDLE hMDHandle,
  2057. /* [string][in][unique] */ LPCWSTR pszMDBackupLocation,
  2058. /* [in] */ DWORD dwMDVersion,
  2059. /* [in] */ DWORD dwMDFlags)
  2060. {
  2061. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2062. }
  2063. HRESULT STDMETHODCALLTYPE
  2064. NSEPCOM::ComMDRestoreA(
  2065. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDBackupLocation,
  2066. /* [in] */ DWORD dwMDVersion,
  2067. /* [in] */ DWORD dwMDFlags)
  2068. {
  2069. return ComMDRestoreW( (LPCWSTR)pszMDBackupLocation, dwMDVersion, dwMDFlags );
  2070. }
  2071. HRESULT STDMETHODCALLTYPE
  2072. NSEPCOM::ComMDRestoreW(
  2073. /* [string][in][unique] */ LPCWSTR pszMDBackupLocation,
  2074. /* [in] */ DWORD dwMDVersion,
  2075. /* [in] */ DWORD dwMDFlags)
  2076. {
  2077. //
  2078. // disregard current in-memory changes
  2079. //
  2080. // Any open handle ( should be at most one, as NSEPM reject Open request
  2081. // if an open handle exist ) will cause a small memory leak ( the open context )
  2082. // because ADMCOM disable handles w/o closing them.
  2083. //
  2084. NseCloseObjs( FALSE );
  2085. return S_OK;
  2086. }
  2087. HRESULT STDMETHODCALLTYPE
  2088. NSEPCOM::ComMDEnumBackupsA(
  2089. /* [size_is (MD_BACKUP_MAX_LEN)][in, out] */ unsigned char __RPC_FAR *pszMDBackupLocation,
  2090. /* [out] */ DWORD *pdwMDVersion,
  2091. /* [out] */ PFILETIME pftMDBackupTime,
  2092. /* [in] */ DWORD dwMDEnumIndex)
  2093. {
  2094. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2095. }
  2096. HRESULT STDMETHODCALLTYPE
  2097. NSEPCOM::ComMDEnumBackupsW(
  2098. /* [size_is (MD_BACKUP_MAX_LEN)][in, out] */ LPWSTR pszMDBackupLocation,
  2099. /* [out] */ DWORD *pdwVersion,
  2100. /* [out] */ PFILETIME pftMDBackupTime,
  2101. /* [in] */ DWORD dwMDEnumIndex)
  2102. {
  2103. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2104. }
  2105. HRESULT STDMETHODCALLTYPE
  2106. NSEPCOM::ComMDDeleteBackupA(
  2107. /* [string][in][unique] */ unsigned char __RPC_FAR *pszMDBackupLocation,
  2108. /* [in] */ DWORD dwMDVersion)
  2109. {
  2110. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2111. }
  2112. HRESULT STDMETHODCALLTYPE
  2113. NSEPCOM::ComMDDeleteBackupW(
  2114. /* [string][in][unique] */ LPCWSTR pszMDBackupLocation,
  2115. /* [in] */ DWORD dwMDVersion)
  2116. {
  2117. return ReturnCodeToHresult(ERROR_NOT_SUPPORTED);
  2118. }
  2119. #if 0
  2120. HRESULT
  2121. NSEPCOM::SetMdIf(
  2122. LPBYTE pMd
  2123. )
  2124. /*++
  2125. Routine Description:
  2126. Set the metadata interface to be used by NSE
  2127. Arguments:
  2128. pMD - ptr to IMDCOM interface
  2129. Return Value:
  2130. status
  2131. --*/
  2132. {
  2133. m_pMdIf = (IMDCOM*)pMd;
  2134. g_pMdIf = (IMDCOM*)pMd;
  2135. #if defined(TEST_ADMACL)
  2136. InitializeAdminAcl( g_pMdIf );
  2137. #endif
  2138. return S_OK;
  2139. }
  2140. #endif