Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

631 lines
13 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997
  5. //
  6. // File: ccomp.cxx
  7. //
  8. // Contents: Contains methods for CIISComputer object
  9. //
  10. // History: 20-1-98 SophiaC Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "iisext.hxx"
  14. #pragma hdrstop
  15. // Class CIISComputer
  16. DEFINE_IPrivateDispatch_Implementation(CIISComputer)
  17. DEFINE_DELEGATING_IDispatch_Implementation(CIISComputer)
  18. DEFINE_CONTAINED_IADs_Implementation(CIISComputer)
  19. DEFINE_IADsExtension_Implementation(CIISComputer)
  20. CIISComputer::CIISComputer():
  21. _pUnkOuter(NULL),
  22. _pADs(NULL),
  23. _pszServerName(NULL),
  24. _pszMetaBasePath(NULL),
  25. _pAdminBase(NULL),
  26. _pDispMgr(NULL),
  27. _fDispInitialized(FALSE)
  28. {
  29. ENLIST_TRACKING(CIISComputer);
  30. }
  31. HRESULT
  32. CIISComputer::CreateComputer(
  33. IUnknown *pUnkOuter,
  34. REFIID riid,
  35. void **ppvObj
  36. )
  37. {
  38. CCredentials Credentials;
  39. CIISComputer FAR * pComputer = NULL;
  40. HRESULT hr = S_OK;
  41. BSTR bstrAdsPath = NULL;
  42. OBJECTINFO ObjectInfo;
  43. POBJECTINFO pObjectInfo = &ObjectInfo;
  44. CLexer * pLexer = NULL;
  45. LPWSTR pszIISPathName = NULL;
  46. hr = AllocateComputerObject(pUnkOuter, Credentials, &pComputer);
  47. BAIL_ON_FAILURE(hr);
  48. //
  49. // get ServerName and pszPath
  50. //
  51. hr = pComputer->_pADs->get_ADsPath(&bstrAdsPath);
  52. BAIL_ON_FAILURE(hr);
  53. pLexer = new CLexer();
  54. hr = pLexer->Initialize(bstrAdsPath);
  55. BAIL_ON_FAILURE(hr);
  56. //
  57. // Parse the pathname
  58. //
  59. memset(pObjectInfo, 0, sizeof(OBJECTINFO));
  60. hr = ADsObject(pLexer, pObjectInfo);
  61. BAIL_ON_FAILURE(hr);
  62. pszIISPathName = AllocADsStr(bstrAdsPath);
  63. if (!pszIISPathName) {
  64. hr = E_OUTOFMEMORY;
  65. BAIL_ON_FAILURE(hr);
  66. }
  67. *pszIISPathName = L'\0';
  68. hr = BuildIISPathFromADsPath(
  69. pObjectInfo,
  70. pszIISPathName
  71. );
  72. BAIL_ON_FAILURE(hr);
  73. hr = pComputer->InitializeComputerObject(
  74. pObjectInfo->TreeName,
  75. pszIISPathName );
  76. BAIL_ON_FAILURE(hr);
  77. //
  78. // pass non-delegating IUnknown back to the aggregator
  79. //
  80. *ppvObj = (INonDelegatingUnknown FAR *) pComputer;
  81. if (bstrAdsPath)
  82. {
  83. ADsFreeString(bstrAdsPath);
  84. }
  85. if (pLexer) {
  86. delete pLexer;
  87. }
  88. if (pszIISPathName ) {
  89. FreeADsStr( pszIISPathName );
  90. }
  91. FreeObjectInfo( &ObjectInfo );
  92. RRETURN(hr);
  93. error:
  94. if (bstrAdsPath) {
  95. ADsFreeString(bstrAdsPath);
  96. }
  97. if (pLexer) {
  98. delete pLexer;
  99. }
  100. if (pszIISPathName ) {
  101. FreeADsStr( pszIISPathName );
  102. }
  103. FreeObjectInfo( &ObjectInfo );
  104. *ppvObj = NULL;
  105. delete pComputer;
  106. RRETURN(hr);
  107. }
  108. CIISComputer::~CIISComputer( )
  109. {
  110. if (_pszServerName) {
  111. FreeADsStr(_pszServerName);
  112. }
  113. if (_pszMetaBasePath) {
  114. FreeADsStr(_pszMetaBasePath);
  115. }
  116. delete _pDispMgr;
  117. }
  118. STDMETHODIMP
  119. CIISComputer::QueryInterface(
  120. REFIID iid,
  121. LPVOID FAR* ppv
  122. )
  123. {
  124. HRESULT hr = S_OK;
  125. hr = _pUnkOuter->QueryInterface(iid,ppv);
  126. RRETURN(hr);
  127. }
  128. HRESULT
  129. CIISComputer::AllocateComputerObject(
  130. IUnknown *pUnkOuter,
  131. CCredentials& Credentials,
  132. CIISComputer ** ppComputer
  133. )
  134. {
  135. CIISComputer FAR * pComputer = NULL;
  136. IADs FAR * pADs = NULL;
  137. CAggregateeDispMgr FAR * pDispMgr = NULL;
  138. HRESULT hr = S_OK;
  139. pComputer = new CIISComputer();
  140. if (pComputer == NULL) {
  141. hr = E_OUTOFMEMORY;
  142. }
  143. BAIL_ON_FAILURE(hr);
  144. pDispMgr = new CAggregateeDispMgr;
  145. if (pDispMgr == NULL) {
  146. hr = E_OUTOFMEMORY;
  147. }
  148. BAIL_ON_FAILURE(hr);
  149. hr = pDispMgr->LoadTypeInfoEntry(
  150. LIBID_IISExt,
  151. IID_IISComputer2,
  152. (IISComputer2 *)pComputer,
  153. DISPID_REGULAR
  154. );
  155. BAIL_ON_FAILURE(hr);
  156. //
  157. // Store the IADs Pointer, but again do NOT ref-count
  158. // this pointer - we keep the pointer around, but do
  159. // a release immediately.
  160. //
  161. hr = pUnkOuter->QueryInterface(IID_IADs, (void **)&pADs);
  162. pADs->Release();
  163. pComputer->_pADs = pADs;
  164. //
  165. // Store the pointer to the pUnkOuter object
  166. // AND DO NOT add ref this pointer
  167. //
  168. pComputer->_pUnkOuter = pUnkOuter;
  169. pComputer->_Credentials = Credentials;
  170. pComputer->_pDispMgr = pDispMgr;
  171. *ppComputer = pComputer;
  172. RRETURN(hr);
  173. error:
  174. delete pDispMgr;
  175. delete pComputer;
  176. RRETURN(hr);
  177. }
  178. HRESULT
  179. CIISComputer::InitializeComputerObject(
  180. LPWSTR pszServerName,
  181. LPWSTR pszPath
  182. )
  183. {
  184. HRESULT hr = S_OK;
  185. if (pszServerName) {
  186. _pszServerName = AllocADsStr(pszServerName);
  187. if (!_pszServerName) {
  188. hr = E_OUTOFMEMORY;
  189. BAIL_ON_FAILURE(hr);
  190. }
  191. }
  192. if (pszPath) {
  193. _pszMetaBasePath = AllocADsStr(pszPath);
  194. if (!_pszMetaBasePath) {
  195. hr = E_OUTOFMEMORY;
  196. BAIL_ON_FAILURE(hr);
  197. }
  198. }
  199. hr = InitServerInfo(pszServerName, &_pAdminBase);
  200. BAIL_ON_FAILURE(hr);
  201. error:
  202. RRETURN(hr);
  203. }
  204. //+---------------------------------------------------------------------------
  205. //
  206. // Function: CIISComputer::Backup
  207. //
  208. // Synopsis:
  209. //
  210. // Arguments:
  211. //
  212. // Returns: HRESULT.
  213. //
  214. // Modifies:
  215. //
  216. // History: 07/14/97 SophiaC Created
  217. //
  218. // Notes:
  219. //----------------------------------------------------------------------------
  220. STDMETHODIMP
  221. CIISComputer::Backup(
  222. BSTR bstrLocation,
  223. LONG lVersion,
  224. LONG lFlags
  225. )
  226. {
  227. HRESULT hr = S_OK;
  228. hr = _pAdminBase->Backup((LPWSTR)bstrLocation,
  229. lVersion,
  230. lFlags);
  231. RRETURN(hr);
  232. }
  233. STDMETHODIMP
  234. CIISComputer::BackupWithPassword(
  235. BSTR bstrLocation,
  236. LONG lVersion,
  237. LONG lFlags,
  238. BSTR bstrPassword
  239. )
  240. {
  241. HRESULT hr = S_OK;
  242. IMSAdminBase2 * pInterface2 = NULL;
  243. if (SUCCEEDED(hr = _pAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pInterface2)))
  244. {
  245. hr = pInterface2->BackupWithPasswd(bstrLocation, lVersion, lFlags, bstrPassword);
  246. pInterface2->Release();
  247. }
  248. RRETURN(hr);
  249. }
  250. STDMETHODIMP
  251. CIISComputer::SaveData()
  252. {
  253. HRESULT hr = S_OK;
  254. hr = _pAdminBase->SaveData();
  255. RRETURN(hr);
  256. }
  257. STDMETHODIMP
  258. CIISComputer::Export(
  259. BSTR bstrPassword,
  260. BSTR bstrFilename,
  261. BSTR bstrSourcePath,
  262. LONG lFlags
  263. )
  264. {
  265. HRESULT hr = S_OK;
  266. IMSAdminBase2 * pInterface2 = NULL;
  267. if (SUCCEEDED(hr = _pAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pInterface2)))
  268. {
  269. hr = pInterface2->Export(bstrPassword, bstrFilename, bstrSourcePath, lFlags);
  270. pInterface2->Release();
  271. }
  272. RRETURN(hr);
  273. }
  274. STDMETHODIMP
  275. CIISComputer::Import(
  276. BSTR bstrPassword,
  277. BSTR bstrFilename,
  278. BSTR bstrSourcePath,
  279. BSTR bstrDestPath,
  280. LONG lFlags
  281. )
  282. {
  283. HRESULT hr = S_OK;
  284. IMSAdminBase2 * pInterface2 = NULL;
  285. if (SUCCEEDED(hr = _pAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pInterface2)))
  286. {
  287. hr = pInterface2->Import(bstrPassword, bstrFilename, bstrSourcePath, bstrDestPath, lFlags);
  288. pInterface2->Release();
  289. }
  290. RRETURN(hr);
  291. }
  292. //+---------------------------------------------------------------------------
  293. //
  294. // Function: CIISComputer::Restore
  295. //
  296. // Synopsis:
  297. //
  298. // Arguments:
  299. //
  300. // Returns: HRESULT.
  301. //
  302. // Modifies:
  303. //
  304. // History: 07/14/96 SophiaC Created
  305. //
  306. //----------------------------------------------------------------------------
  307. STDMETHODIMP
  308. CIISComputer::Restore(
  309. BSTR bstrLocation,
  310. LONG lVersion,
  311. LONG lFlags
  312. )
  313. {
  314. HRESULT hr = S_OK;
  315. hr = _pAdminBase->Restore((LPWSTR)bstrLocation,
  316. lVersion,
  317. lFlags);
  318. RRETURN(hr);
  319. }
  320. STDMETHODIMP
  321. CIISComputer::RestoreWithPassword(
  322. BSTR bstrLocation,
  323. LONG lVersion,
  324. LONG lFlags,
  325. BSTR bstrPassword
  326. )
  327. {
  328. HRESULT hr = S_OK;
  329. IMSAdminBase2 * pInterface2 = NULL;
  330. if (SUCCEEDED(hr = _pAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pInterface2)))
  331. {
  332. hr = pInterface2->RestoreWithPasswd(bstrLocation, lVersion, lFlags, bstrPassword);
  333. pInterface2->Release();
  334. }
  335. RRETURN(hr);
  336. }
  337. //+---------------------------------------------------------------------------
  338. //
  339. // Function: CIISComputer::EnumBackups
  340. //
  341. // Synopsis:
  342. //
  343. // Arguments:
  344. //
  345. // Returns: HRESULT.
  346. //
  347. // Modifies:
  348. //
  349. // History: 07-14-96 SophiaC Created
  350. //
  351. //----------------------------------------------------------------------------
  352. STDMETHODIMP
  353. CIISComputer::EnumBackups(
  354. BSTR bstrLocation,
  355. LONG lIndex,
  356. VARIANT *pvVersion,
  357. VARIANT *pvLocation,
  358. VARIANT *pvDate
  359. )
  360. {
  361. HRESULT hr = S_OK;
  362. FILETIME ftBackupTime;
  363. WORD wFatDate;
  364. WORD wFatTime;
  365. WCHAR Location[MD_BACKUP_MAX_LEN];
  366. DWORD dwVersion;
  367. VariantInit( pvVersion );
  368. VariantInit( pvLocation );
  369. VariantInit( pvDate );
  370. Location[0] = L'\0';
  371. if (bstrLocation) {
  372. wcscpy((LPWSTR)Location, (LPWSTR)bstrLocation);
  373. }
  374. hr = _pAdminBase->EnumBackups((LPWSTR)Location,
  375. (PDWORD)&dwVersion,
  376. &ftBackupTime,
  377. lIndex);
  378. if (SUCCEEDED(hr)) {
  379. pvVersion->vt = VT_I4;
  380. pvLocation->vt = VT_BSTR;
  381. pvDate->vt = VT_DATE;
  382. if (!FileTimeToDosDateTime( &ftBackupTime, &wFatDate, &wFatTime)){
  383. hr = HRESULT_FROM_WIN32(GetLastError());
  384. BAIL_ON_FAILURE(hr);
  385. }
  386. if (!DosDateTimeToVariantTime(wFatDate, wFatTime, &pvDate->date)){
  387. hr = HRESULT_FROM_WIN32(GetLastError());
  388. BAIL_ON_FAILURE(hr);
  389. }
  390. pvVersion->lVal = (long)dwVersion;
  391. hr = ADsAllocString(
  392. (LPWSTR)Location,
  393. &pvLocation->bstrVal
  394. );
  395. }
  396. error :
  397. RRETURN(hr);
  398. }
  399. //+---------------------------------------------------------------------------
  400. //
  401. // Function: CIISComputer::DeleteBackup
  402. //
  403. // Synopsis:
  404. //
  405. // Arguments:
  406. //
  407. // Returns: HRESULT.
  408. //
  409. // Modifies:
  410. //
  411. // History: 07/14/96 SophiaC Created
  412. //
  413. //----------------------------------------------------------------------------
  414. STDMETHODIMP
  415. CIISComputer::DeleteBackup(
  416. BSTR bstrLocation,
  417. LONG lVersion
  418. )
  419. {
  420. HRESULT hr = S_OK;
  421. hr = _pAdminBase->DeleteBackup((LPWSTR)bstrLocation,
  422. lVersion
  423. );
  424. RRETURN(hr);
  425. }
  426. STDMETHODIMP
  427. CIISComputer::ADSIInitializeDispatchManager(
  428. long dwExtensionId
  429. )
  430. {
  431. HRESULT hr = S_OK;
  432. if (_fDispInitialized) {
  433. RRETURN(E_FAIL);
  434. }
  435. hr = _pDispMgr->InitializeDispMgr(dwExtensionId);
  436. if (SUCCEEDED(hr)) {
  437. _fDispInitialized = TRUE;
  438. }
  439. RRETURN(hr);
  440. }
  441. STDMETHODIMP
  442. CIISComputer::ADSIInitializeObject(
  443. THIS_ BSTR lpszUserName,
  444. BSTR lpszPassword,
  445. long lnReserved
  446. )
  447. {
  448. CCredentials NewCredentials(lpszUserName, lpszPassword, lnReserved);
  449. _Credentials = NewCredentials;
  450. RRETURN(S_OK);
  451. }
  452. STDMETHODIMP
  453. CIISComputer::ADSIReleaseObject()
  454. {
  455. delete this;
  456. RRETURN(S_OK);
  457. }
  458. STDMETHODIMP
  459. CIISComputer::NonDelegatingQueryInterface(
  460. REFIID iid,
  461. LPVOID FAR* ppv
  462. )
  463. {
  464. ASSERT(ppv);
  465. if (IsEqualIID(iid, IID_IISComputer)) {
  466. *ppv = (IADsUser FAR *) this;
  467. } else if (IsEqualIID(iid, IID_IISComputer2)) {
  468. *ppv = (IADsUser FAR *) this;
  469. } else if (IsEqualIID(iid, IID_IADsExtension)) {
  470. *ppv = (IADsExtension FAR *) this;
  471. } else if (IsEqualIID(iid, IID_IUnknown)) {
  472. //
  473. // probably not needed since our 3rd party extension does not stand
  474. // alone and provider does not ask for this, but to be safe
  475. //
  476. *ppv = (INonDelegatingUnknown FAR *) this;
  477. } else {
  478. *ppv = NULL;
  479. return E_NOINTERFACE;
  480. }
  481. //
  482. // Delegating AddRef to aggregator for IADsExtesnion and IISComputer.
  483. // AddRef on itself for IPrivateUnknown. (both tested.)
  484. //
  485. ((IUnknown *) (*ppv)) -> AddRef();
  486. return S_OK;
  487. }
  488. //
  489. // IADsExtension::Operate()
  490. //
  491. STDMETHODIMP
  492. CIISComputer::Operate(
  493. THIS_ DWORD dwCode,
  494. VARIANT varUserName,
  495. VARIANT varPassword,
  496. VARIANT varFlags
  497. )
  498. {
  499. RRETURN(E_NOTIMPL);
  500. }