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.

784 lines
24 KiB

  1. /*---------------------------------------------------------------------------
  2. File: DCTInstaller.cpp
  3. Comments: implementation of COM object that installs the DCT agent service.
  4. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 02/18/99 11:34:16
  9. ---------------------------------------------------------------------------
  10. */
  11. // DCTInstaller.cpp : Implementation of CDCTInstaller
  12. #include "stdafx.h"
  13. //#include "McsDispatcher.h"
  14. #include "Dispatch.h"
  15. #include "DInst.h"
  16. #include "Common.hpp"
  17. #include "Err.hpp"
  18. #include "ErrDct.hpp"
  19. #include "UString.hpp"
  20. #include "QProcess.hpp"
  21. #include "IsAdmin.hpp"
  22. #include "TSync.hpp"
  23. #include "TReg.hpp"
  24. #include "TInst.h"
  25. #include "TFile.hpp"
  26. #include "ResStr.h"
  27. #include "sd.hpp"
  28. #include "CommaLog.hpp"
  29. #include <lm.h>
  30. //#import "\bin\McsVarSetMin.tlb" no_namespace
  31. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  32. TErrorDct err;
  33. TError & errCommon = err;
  34. StringLoader gString;
  35. extern TErrorDct errLog;
  36. extern BOOL gbCacheFileBuilt;
  37. #ifdef OFA
  38. #define AGENT_EXE L"OFAAgent.exe"
  39. #define SERVICE_EXE L"OFAAgentService.exe"
  40. #else
  41. #define AGENT_EXE GET_STRING(IDS_AGENT_EXE)
  42. #define SERVICE_EXE GET_STRING(IDS_SERVICE_EXE)
  43. #endif
  44. #define WORKER_DLL GET_STRING(IDS_WORKER_DLL)
  45. #define VARSET_DLL GET_STRING(IDS_VARSET_DLL)
  46. #define DATA_FILE GET_STRING(IDS_DATA_FILE)
  47. #define RESOURCE_DLL L"McsDmRes.dll"
  48. #define MESSAGE_DLL L"McsDmMsg.dll"
  49. #define CACHE_FILE L"DCTCache"
  50. #define AGENT_INTEL_DIR GET_STRING(IDS_AGENT_INTEL_DIR)
  51. #define AGENT_ALPHA_DIR GET_STRING(IDS_AGENT_ALPHA_DIR)
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CDCTInstaller
  54. namespace {
  55. class workerDeleteFile {
  56. _bstr_t m_strFile;
  57. public:
  58. workerDeleteFile(_bstr_t strFile):m_strFile(strFile)
  59. {}
  60. ~workerDeleteFile()
  61. { ::DeleteFile(m_strFile); }
  62. };
  63. union Time {
  64. FILETIME m_stFileTime;
  65. LONGLONG m_llTime;
  66. };
  67. bool IsServiceInstalling(_bstr_t sDirSysTgt, _bstr_t strTemp1, _bstr_t strTemp2)
  68. {
  69. bool bRes = false;
  70. HANDLE hFind;
  71. WIN32_FIND_DATA findData1;
  72. if((hFind = FindFirstFile(strTemp1, &findData1)) != INVALID_HANDLE_VALUE)
  73. {
  74. WIN32_FIND_DATA findData2;
  75. ::FindClose(hFind);
  76. hFind = CreateFile(
  77. strTemp2, // pointer to name of the file
  78. GENERIC_WRITE, // access (read-write) mode
  79. 0, // share mode
  80. 0,
  81. // pointer to security attributes
  82. CREATE_ALWAYS, // how to create
  83. FILE_ATTRIBUTE_NORMAL, // file attributes
  84. 0 // handle to file with attributes to
  85. );
  86. if(hFind != INVALID_HANDLE_VALUE)
  87. {
  88. CloseHandle(hFind);
  89. hFind = FindFirstFile(strTemp2, &findData2);
  90. ::DeleteFile(strTemp2);
  91. if(hFind != INVALID_HANDLE_VALUE)
  92. {
  93. ::FindClose(hFind);
  94. // look at difference in file creation times
  95. Time t1, t2;
  96. t1.m_stFileTime = findData1.ftCreationTime;
  97. t2.m_stFileTime = findData2.ftCreationTime;
  98. LONGLONG lldiff = t2.m_llTime - t1.m_llTime;
  99. if((lldiff/10000000) <= 600)
  100. bRes = true;
  101. }
  102. }
  103. }
  104. if(!bRes)
  105. {
  106. hFind = CreateFile(
  107. strTemp1, // pointer to name of the file
  108. GENERIC_WRITE, // access (read-write) mode
  109. 0, // share mode
  110. 0,
  111. // pointer to security attributes
  112. CREATE_ALWAYS, // how to create
  113. FILE_ATTRIBUTE_NORMAL, // file attributes
  114. 0 // handle to file with attributes to
  115. );
  116. if(hFind != INVALID_HANDLE_VALUE)
  117. ::CloseHandle(hFind);
  118. }
  119. return bRes;
  120. }
  121. bool IsServiceRunning(_bstr_t strServer)
  122. {
  123. SC_HANDLE hScm = OpenSCManager(strServer, NULL, GENERIC_READ);
  124. if(!hScm)
  125. {
  126. err.DbgMsgWrite(ErrW,L"Could not open SCManager on %s : GetLastError() returned %d",
  127. (WCHAR*)strServer, GetLastError());
  128. return false;
  129. }
  130. CComBSTR bstrServiceName(L"OnePointFileAdminService");
  131. SC_HANDLE hSvc = OpenService(hScm, GET_STRING(IDS_SERVICE_NAME), GENERIC_READ);
  132. if(!hSvc)
  133. {
  134. if ( GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST )
  135. err.DbgMsgWrite(ErrW,L"Could not open service on %s : GetLastError() returned %d",
  136. (WCHAR*)strServer, GetLastError());
  137. CloseServiceHandle(hScm);
  138. return false;
  139. }
  140. CloseServiceHandle(hScm);
  141. SERVICE_STATUS status;
  142. BOOL bRes = QueryServiceStatus(hSvc, &status);
  143. if(!bRes)
  144. {
  145. err.DbgMsgWrite(ErrW,L"Could not get service status on %s : GetLastError() returned %d",
  146. (WCHAR*)strServer, GetLastError());
  147. CloseServiceHandle(hSvc);
  148. return false;
  149. }
  150. CloseServiceHandle(hSvc);
  151. if(status.dwCurrentState != SERVICE_STOPPED)
  152. return true;
  153. else
  154. return false;
  155. }
  156. }
  157. int GetTargetOSVersion(LPWSTR sServerName)
  158. {
  159. DWORD rc = NERR_Success;
  160. SERVER_INFO_101 * servInfo = NULL;
  161. int nVersion = 4;
  162. // Check version info
  163. rc = NetServerGetInfo(sServerName, 101, (LPBYTE *)&servInfo);
  164. if (rc == NERR_Success)
  165. {
  166. if(servInfo->sv101_version_major >= 5)
  167. nVersion = 5;
  168. else
  169. nVersion = 4;
  170. NetApiBufferFree(servInfo);
  171. }
  172. return nVersion;
  173. }
  174. DWORD // ret- OS return code
  175. CDCTInstaller::GetLocalMachineName()
  176. {
  177. DWORD rc = 0;
  178. WKSTA_INFO_100 * buf = NULL;
  179. rc = NetWkstaGetInfo(NULL,100,(LPBYTE*)&buf);
  180. if ( ! rc )
  181. {
  182. safecopy(m_LocalComputer,L"\\\\");
  183. UStrCpy(m_LocalComputer+2,buf->wki100_computername);
  184. NetApiBufferFree(buf);
  185. }
  186. return rc;
  187. }
  188. DWORD // ret- OS return code
  189. GetPlugInDirectory(
  190. WCHAR * directory // out- directory where plug-in files are
  191. )
  192. {
  193. TRegKey key;
  194. DWORD rc;
  195. // Get the plug-ins directory from the registry
  196. rc = key.Open(GET_STRING(IDS_HKLM_DomainAdmin_Key),HKEY_LOCAL_MACHINE);
  197. if ( ! rc )
  198. {
  199. rc = key.ValueGetStr(L"PlugInDirectory",directory,MAX_PATH * (sizeof WCHAR));
  200. }
  201. return rc;
  202. }
  203. DWORD // ret- OS return code
  204. GetInstallationDirectory(
  205. WCHAR * directory // out- directory we were installed to
  206. )
  207. {
  208. TRegKey key;
  209. DWORD rc;
  210. // Get the plug-ins directory from the registry
  211. rc = key.Open(GET_STRING(IDS_HKLM_DomainAdmin_Key),HKEY_LOCAL_MACHINE);
  212. if ( ! rc )
  213. {
  214. rc = key.ValueGetStr(L"Directory",directory,MAX_PATH * (sizeof WCHAR));
  215. }
  216. return rc;
  217. }
  218. DWORD // ret- OS return code
  219. GetProgramFilesDirectory(
  220. WCHAR * directory, // out- location of program files directory
  221. WCHAR const * computer // in - computer to find PF directory on
  222. )
  223. {
  224. TRegKey hklm;
  225. TRegKey key;
  226. DWORD rc;
  227. rc = hklm.Connect(HKEY_LOCAL_MACHINE,computer);
  228. if ( ! rc )
  229. {
  230. rc = key.Open(L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",&hklm);
  231. }
  232. if ( !rc )
  233. {
  234. rc = key.ValueGetStr(L"ProgramFilesDir",directory,MAX_PATH * (sizeof WCHAR));
  235. }
  236. return rc;
  237. }
  238. STDMETHODIMP // ret- HRESULT
  239. CDCTInstaller::InstallToServer(
  240. BSTR serverName, // in - computer name to install to
  241. BSTR configurationFile // in - full path to job file (varset file, copied as part of install)
  242. )
  243. {
  244. DWORD rcOs=0; // OS return code
  245. if ( ! *m_LocalComputer )
  246. {
  247. rcOs = GetLocalMachineName();
  248. if ( rcOs )
  249. {
  250. err.SysMsgWrite(ErrE,rcOs,DCT_MSG_NO_LOCAL_MACHINE_NAME_D,rcOs);
  251. return HRESULT_FROM_WIN32(rcOs);
  252. }
  253. }
  254. // Check for admin privileges on the server
  255. rcOs = IsAdminRemote((WCHAR*)serverName);
  256. if ( rcOs == ERROR_ACCESS_DENIED )
  257. {
  258. err.MsgWrite(ErrE,DCT_MSG_NOT_ADMIN_ON_SERVER_S,(WCHAR*)serverName);
  259. return HRESULT_FROM_WIN32(rcOs);
  260. }
  261. else if ( rcOs == ERROR_BAD_NET_NAME )
  262. {
  263. err.MsgWrite(ErrE,DCT_MSG_NO_ADMIN_SHARES_S,(WCHAR*)serverName);
  264. return HRESULT_FROM_WIN32(rcOs);
  265. }
  266. else if ( rcOs == ERROR_BAD_NETPATH )
  267. {
  268. err.MsgWrite(ErrE,DCT_MSG_COMPUTER_NOT_FOUND_S,(WCHAR*)serverName);
  269. return HRESULT_FROM_WIN32(rcOs);
  270. }
  271. else if ( rcOs )
  272. {
  273. err.SysMsgWrite(ErrE,rcOs,DCT_MSG_NO_ADMIN_SHARE_SD,(WCHAR*)serverName,rcOs);
  274. return HRESULT_FROM_WIN32(rcOs);
  275. }
  276. TDCTInstall x( serverName, m_LocalComputer );
  277. DWORD typeThis = 0;
  278. DWORD typeTarg = 0;
  279. BOOL bNoProgramFiles = FALSE;
  280. BOOL bShareCreated = FALSE;
  281. SHARE_INFO_502 shareInfo;
  282. errCommon = err;
  283. do // once or until break
  284. {
  285. typeThis = QProcessor( m_LocalComputer );
  286. typeTarg = QProcessor( serverName );
  287. //do not install to ALPHAs, atleast for Whistler Beta 2
  288. if (typeTarg == PROCESSOR_IS_ALPHA)
  289. return CO_E_NOT_SUPPORTED;
  290. // Set installation directories for source and target
  291. WCHAR sDirInstall[MAX_PATH];
  292. WCHAR sDirPlugIn[MAX_PATH];
  293. WCHAR sDirSrc[MAX_PATH];
  294. WCHAR sDirTgt[MAX_PATH];
  295. WCHAR sDirSysTgt[MAX_PATH];
  296. WCHAR sDirTgtProgramFiles[MAX_PATH];
  297. WCHAR sDirTgtProgramFilesLocal[MAX_PATH];
  298. WCHAR sDestination[MAX_PATH];
  299. WCHAR sSvc[MAX_PATH];
  300. SHARE_INFO_1 * shInfo1 = NULL;
  301. rcOs = GetInstallationDirectory(sDirInstall);
  302. if ( rcOs ) break;
  303. rcOs = GetPlugInDirectory(sDirPlugIn);
  304. //if ( rcOs ) break;
  305. rcOs = GetProgramFilesDirectory(sDirTgtProgramFiles,serverName);
  306. if ( rcOs )
  307. {
  308. if ( rcOs != ERROR_FILE_NOT_FOUND )
  309. {
  310. break;
  311. }
  312. // this doesn't work on NT 3.51, so if we can't get the program files directory, we'll
  313. // create a directory off the system root.
  314. safecopy(sDirTgtProgramFiles,"\\ADMIN$");
  315. bNoProgramFiles = TRUE;
  316. rcOs = 0;
  317. }
  318. safecopy(sDirTgtProgramFilesLocal,sDirTgtProgramFiles);
  319. // See if the admin$ shares exist already
  320. if ( sDirTgtProgramFiles[1] == L':' && sDirTgtProgramFiles[2] == L'\\' )
  321. {
  322. BOOL bNeedToCreateShare = FALSE;
  323. sDirTgtProgramFiles[1] = L'$';
  324. sDirTgtProgramFiles[2] = 0;
  325. rcOs = NetShareGetInfo(serverName,sDirTgtProgramFiles,1,(LPBYTE*)&shInfo1);
  326. if ( rcOs )
  327. {
  328. if ( rcOs == NERR_NetNameNotFound )
  329. {
  330. bNeedToCreateShare = TRUE;
  331. }
  332. else
  333. {
  334. bNeedToCreateShare = FALSE;
  335. err.SysMsgWrite(ErrE,rcOs,DCT_MSG_ADMIN_SHARE_GETINFO_FAILED_SSD,serverName,sDirTgtProgramFiles,rcOs);
  336. // put the program files path name back like it was
  337. sDirTgtProgramFiles[1] = L':';
  338. sDirTgtProgramFiles[2] = L'\\';
  339. }
  340. }
  341. else
  342. {
  343. if ( shInfo1->shi1_type & STYPE_SPECIAL )
  344. {
  345. // the admin share exists -- we'll just use it
  346. bNeedToCreateShare = FALSE;
  347. // put the program files path name back like it was
  348. sDirTgtProgramFiles[1] = L':';
  349. sDirTgtProgramFiles[2] = L'\\';
  350. }
  351. else
  352. {
  353. err.MsgWrite(0,DCT_MSG_SHARE_IS_NOT_ADMIN_SHARE_SS,serverName,shInfo1->shi1_netname);
  354. bNeedToCreateShare = TRUE;
  355. }
  356. NetApiBufferFree(shInfo1);
  357. }
  358. if ( bNeedToCreateShare )
  359. {
  360. SECURITY_DESCRIPTOR emptySD;
  361. WCHAR shareName[LEN_Path];
  362. WCHAR remark[LEN_Path];
  363. BYTE emptyRelSD[LEN_Path];
  364. DWORD lenEmptyRelSD = DIM(emptyRelSD);
  365. sDirTgtProgramFiles[1] = L':';
  366. sDirTgtProgramFiles[2] = L'\\';
  367. memset(&emptySD,0,(sizeof SECURITY_DESCRIPTOR));
  368. InitializeSecurityDescriptor(&emptySD,SECURITY_DESCRIPTOR_REVISION);
  369. MakeSelfRelativeSD(&emptySD,emptyRelSD,&lenEmptyRelSD);
  370. TSD pSD((SECURITY_DESCRIPTOR*)emptyRelSD,McsShareSD,FALSE);
  371. PACL dacl = NULL;
  372. TACE ace(ACCESS_ALLOWED_ACE_TYPE,0,DACL_FULLCONTROL_MASK,GetWellKnownSid(1/*ADMINISTRATORS*/));
  373. DWORD lenInfo = (sizeof shareInfo);
  374. pSD.ACLAddAce(&dacl,&ace,0);
  375. pSD.SetDacl(dacl);
  376. UStrCpy(shareName,GET_STRING(IDS_HiddenShare));
  377. UStrCpy(remark,GET_STRING(IDS_HiddenShareRemark));
  378. memset(&shareInfo,0,(sizeof shareInfo));
  379. shareInfo.shi502_netname = shareName;
  380. shareInfo.shi502_type = STYPE_DISKTREE;
  381. shareInfo.shi502_remark = remark;
  382. shareInfo.shi502_max_uses = 1;
  383. shareInfo.shi502_path = sDirTgtProgramFiles;
  384. shareInfo.shi502_security_descriptor = pSD.MakeRelSD();
  385. rcOs = NetShareAdd(serverName,502,(LPBYTE)&shareInfo,&lenInfo);
  386. if ( rcOs )
  387. {
  388. err.SysMsgWrite(ErrE,rcOs,DCT_MSG_TEMP_SHARE_CREATE_FAILED_SSD,serverName,shareName,rcOs);
  389. break;
  390. }
  391. else
  392. {
  393. safecopy(sDirTgtProgramFiles,shareName);
  394. bShareCreated = TRUE;
  395. }
  396. free(shareInfo.shi502_security_descriptor);
  397. shareInfo.shi502_security_descriptor = NULL;
  398. }
  399. }
  400. else
  401. {
  402. // something went wrong...the program files directory is not in drive:\path format
  403. err.MsgWrite(ErrW,DCT_MSG_INVALID_PROGRAM_FILES_DIR_SS,serverName,sDirTgtProgramFiles);
  404. }
  405. // setup source directory name for install
  406. UStrCpy( sDirSrc, sDirInstall );
  407. switch ( typeTarg )
  408. {
  409. case PROCESSOR_IS_INTEL:
  410. if ( typeTarg != typeThis )
  411. {
  412. UStrCpy(sDirSrc + UStrLen(sDirSrc),AGENT_INTEL_DIR);
  413. UStrCpy(sDirPlugIn + UStrLen(sDirPlugIn),AGENT_INTEL_DIR);
  414. }
  415. break;
  416. case PROCESSOR_IS_ALPHA:
  417. if ( typeTarg != typeThis )
  418. {
  419. UStrCpy(sDirSrc + UStrLen(sDirSrc),AGENT_ALPHA_DIR);
  420. UStrCpy(sDirPlugIn + UStrLen(sDirPlugIn),AGENT_ALPHA_DIR);
  421. }
  422. break;
  423. default:
  424. rcOs = ERROR_CAN_NOT_COMPLETE;
  425. break;
  426. }
  427. if ( rcOs ) break;
  428. //if the target machine is downlevel (NT4), dispatch NT4, non-robust, agent files
  429. int nVer = GetTargetOSVersion(serverName);
  430. if (nVer == 4)
  431. {
  432. _bstr_t sAgentDir = GET_STRING(IDS_AGENT_NT4_DIR);
  433. if (UStrLen(sDirSrc) + sAgentDir.length() < MAX_PATH)
  434. wcscat(sDirSrc, (WCHAR*)sAgentDir);
  435. if (UStrLen(sDirPlugIn) + sAgentDir.length() < MAX_PATH)
  436. wcscat(sDirPlugIn, (WCHAR*)sAgentDir);
  437. }
  438. // setup target directory name for install
  439. UStrCpy( sDirTgt, serverName );
  440. UStrCpy( sDirTgt+UStrLen(sDirTgt), L"\\" );
  441. if ( sDirTgtProgramFiles[1] == L':' )
  442. {
  443. sDirTgtProgramFiles[1] = L'$';
  444. }
  445. UStrCpy(sDirTgt + UStrLen(sDirTgt),sDirTgtProgramFiles);
  446. #ifdef OFA
  447. UStrCpy(sDirTgt + UStrLen(sDirTgt),L"\\OnePointFileAdminAgent\\");
  448. #else
  449. UStrCpy(sDirTgt + UStrLen(sDirTgt),GET_STRING(IDS_AgentDirectoryName));
  450. #endif
  451. UStrCpy( sDirSysTgt, serverName );
  452. UStrCpy( sDirSysTgt+UStrLen(sDirSysTgt), L"\\ADMIN$\\System32\\" );
  453. _bstr_t strTemp1(sDirSysTgt), strTemp2(sDirSysTgt);
  454. strTemp1 += (BSTR)GET_STRING(IDS_TEMP_FILE_1);
  455. strTemp2 += (BSTR)GET_STRING(IDS_TEMP_FILE_2);
  456. if(IsServiceInstalling(sDirSysTgt, strTemp1, strTemp2))
  457. {
  458. err.MsgWrite(ErrE,DCT_MSG_AGENT_SERVICE_ALREADY_RUNNING,(WCHAR*)serverName);
  459. #ifdef OFA
  460. return 0x88070040;
  461. #else
  462. return HRESULT_FROM_WIN32(ERROR_SERVICE_ALREADY_RUNNING);
  463. #endif
  464. }
  465. workerDeleteFile wrk(strTemp1);
  466. if(IsServiceRunning(serverName))
  467. {
  468. err.MsgWrite(ErrE,DCT_MSG_AGENT_SERVICE_ALREADY_RUNNING,(WCHAR*)serverName);
  469. #ifdef OFA
  470. return 0x88070040;
  471. #else
  472. return HRESULT_FROM_WIN32(ERROR_SERVICE_ALREADY_RUNNING);
  473. #endif
  474. }
  475. if ( bNoProgramFiles )
  476. {
  477. #ifdef OFA
  478. UStrCpy(sSvc,"%systemroot%\\OnePointFileAdminAgent\\");
  479. #else
  480. UStrCpy(sSvc,"%systemroot%\\OnePointDomainAgent\\");
  481. #endif
  482. UStrCpy( sSvc + UStrLen(sSvc),SERVICE_EXE );
  483. }
  484. else
  485. {
  486. UStrCpy( sSvc, sDirTgtProgramFilesLocal );
  487. #ifdef OFA
  488. UStrCpy( sSvc + UStrLen(sSvc),L"\\OnePointFileAdminAgent\\");
  489. #else
  490. UStrCpy( sSvc + UStrLen(sSvc),L"\\OnePointDomainAgent\\");
  491. #endif
  492. UStrCpy( sSvc + UStrLen(sSvc),SERVICE_EXE );
  493. sSvc[1] = L':';
  494. }
  495. if ( UStrICmp(m_LocalComputer,serverName) )
  496. {
  497. x.SetServiceInformation(GET_STRING(IDS_DISPLAY_NAME),GET_STRING(IDS_SERVICE_NAME),sSvc,NULL);
  498. }
  499. else
  500. {
  501. safecopy(sSvc,sDirSrc);
  502. UStrCpy(sSvc + UStrLen(sSvc),GET_STRING(IDS_SERVICE_EXE));
  503. x.SetServiceInformation(GET_STRING(IDS_DISPLAY_NAME),GET_STRING(IDS_SERVICE_NAME),sSvc,NULL);
  504. }
  505. rcOs = x.ScmOpen();
  506. if ( rcOs ) break;
  507. x.ServiceStop();
  508. if ( UStrICmp( m_LocalComputer, serverName ) )
  509. {
  510. // Create the target directory, if it does not exist
  511. if ( ! CreateDirectory(sDirTgt,NULL) )
  512. {
  513. rcOs = GetLastError();
  514. if ( rcOs && rcOs != ERROR_ALREADY_EXISTS )
  515. {
  516. err.SysMsgWrite(ErrE,rcOs,DCT_MSG_CREATE_DIR_FAILED_SD,sDirTgt,rcOs);
  517. break;
  518. }
  519. }
  520. // shared MCS files
  521. // source files
  522. TInstallFile varset(VARSET_DLL,sDirSrc);
  523. // target\system32 files
  524. TInstallFile varsettargetsys(VARSET_DLL,sDirSysTgt,TRUE);
  525. // target\OnePoint files
  526. TInstallFile varsettarget(VARSET_DLL,sDirTgt,TRUE);
  527. // agent specific files
  528. TInstallFile worker(WORKER_DLL,sDirSrc);
  529. TInstallFile agent(AGENT_EXE,sDirSrc);
  530. TInstallFile service(SERVICE_EXE,sDirSrc);
  531. TInstallFile resourceMsg(RESOURCE_DLL,sDirSrc);
  532. TInstallFile eventMsg(MESSAGE_DLL,sDirSrc);
  533. TInstallFile workertarget(WORKER_DLL,sDirTgt,TRUE);
  534. TInstallFile agenttarget(AGENT_EXE,sDirTgt,TRUE);
  535. TInstallFile servicetarget(SERVICE_EXE,sDirTgt,TRUE);
  536. TInstallFile resourceMsgtarget(RESOURCE_DLL,sDirTgt,TRUE);
  537. TInstallFile eventMsgtarget(MESSAGE_DLL,sDirTgt,TRUE);
  538. #ifdef OFA
  539. if ( varset.CompareFile(&varsettargetsys) > 0 )
  540. #endif
  541. {
  542. swprintf(sDestination,L"%s%s",sDirTgt,VARSET_DLL);
  543. varset.CopyTo(sDestination);
  544. }
  545. #ifdef OFA
  546. if ( worker.CompareFile(&workertarget) > 0 )
  547. #endif
  548. {
  549. swprintf(sDestination,L"%s%s",sDirTgt,WORKER_DLL);
  550. worker.CopyTo(sDestination);
  551. }
  552. #ifdef OFA
  553. if ( agent.CompareFile(&agenttarget) > 0 )
  554. #endif
  555. {
  556. swprintf(sDestination,L"%s%s",sDirTgt,AGENT_EXE);
  557. agent.CopyTo(sDestination);
  558. }
  559. #ifdef OFA
  560. if ( service.CompareFile(&servicetarget) > 0 )
  561. #endif
  562. {
  563. swprintf(sDestination,L"%s%s",sDirTgt,SERVICE_EXE);
  564. service.CopyTo(sDestination);
  565. }
  566. #ifdef OFA
  567. if ( resourceMsg.CompareFile(&resourceMsgtarget) > 0 )
  568. #endif
  569. {
  570. swprintf(sDestination,L"%s%s",sDirTgt,RESOURCE_DLL);
  571. resourceMsg.CopyTo(sDestination);
  572. }
  573. #ifdef OFA
  574. if ( eventMsg.CompareFile(&eventMsgtarget) > 0 )
  575. #endif
  576. {
  577. swprintf(sDestination,L"%s%s",sDirTgt,MESSAGE_DLL);
  578. eventMsg.CopyTo(sDestination);
  579. }
  580. // Copy files needed for plug-ins
  581. if ( m_PlugInFileList )
  582. {
  583. TNodeListEnum e;
  584. TFileNode * pNode;
  585. for ( pNode = (TFileNode*)e.OpenFirst(m_PlugInFileList) ; pNode ; pNode = (TFileNode*)e.Next() )
  586. {
  587. TInstallFile plugInSource(pNode->FileName(),sDirPlugIn);
  588. TInstallFile plugInTarget(pNode->FileName(),sDirTgt,TRUE);
  589. swprintf(sDestination,L"%s%s",sDirTgt,pNode->FileName());
  590. plugInSource.CopyTo(sDestination);
  591. }
  592. e.Close();
  593. }
  594. }
  595. else
  596. {
  597. safecopy(sDirTgt,sDirSrc);
  598. }
  599. // Copy the job file
  600. // separate the directory and filename
  601. WCHAR sConfigPath[MAX_PATH];
  602. safecopy(sConfigPath,(WCHAR*)configurationFile);
  603. WCHAR * lastslash = wcsrchr(sConfigPath,L'\\');
  604. if ( lastslash )
  605. {
  606. *lastslash = 0;
  607. }
  608. WCHAR const * sConfigFile = lastslash + 1;
  609. TInstallFile config(sConfigFile,sConfigPath);
  610. swprintf(sDestination,L"%s%s",sDirTgt,sConfigFile);
  611. config.CopyTo(sDestination);
  612. if ( gbCacheFileBuilt )
  613. {
  614. // also copy the dct cache file
  615. TInstallFile cache(CACHE_FILE,sConfigPath);
  616. swprintf(sDestination,L"%s%s",sDirTgt,CACHE_FILE);
  617. cache.CopyTo(sDestination);
  618. }
  619. // start the service
  620. rcOs = x.ServiceStart();
  621. } while ( FALSE );
  622. if ( bShareCreated )
  623. {
  624. rcOs = NetShareDel(serverName,GET_STRING(IDS_HiddenShare),0);
  625. if ( rcOs )
  626. {
  627. err.SysMsgWrite(ErrW,rcOs,DCT_MSG_SHARE_DEL_FAILED_SSD,serverName,GET_STRING(IDS_HiddenShare),rcOs);
  628. }
  629. }
  630. if ( rcOs && rcOs != E_ABORT )
  631. {
  632. err.SysMsgWrite(
  633. ErrW,
  634. rcOs,
  635. DCT_MSG_AGENT_INSTALL_FAILED_SD,
  636. (WCHAR*)serverName,
  637. rcOs);
  638. }
  639. if ( SUCCEEDED(rcOs) )
  640. {
  641. return HRESULT_FROM_WIN32(rcOs);
  642. }
  643. else
  644. {
  645. return rcOs;
  646. }
  647. }
  648. STDMETHODIMP // ret- HRESULT
  649. CDCTInstaller::SetCredentials(
  650. BSTR account, // in - account name
  651. BSTR password // in - password
  652. )
  653. {
  654. m_Account = account;
  655. m_Password = password;
  656. return S_OK;
  657. }
  658. // Installs the agent to a computer
  659. // VarSet input:
  660. // InstallToServer - computer to install agent on
  661. // ConfigurationFile - file containing varset for job, installed with agent
  662. //
  663. STDMETHODIMP // ret- HRESULT
  664. CDCTInstaller::Process(
  665. IUnknown * pWorkItem // in - varset containing data
  666. )
  667. {
  668. HRESULT hr = S_OK;
  669. IVarSetPtr pVarSet = pWorkItem;
  670. _bstr_t serverName;
  671. _bstr_t dataFile;
  672. // Read the server name
  673. serverName = pVarSet->get(GET_BSTR(DCTVS_InstallToServer));
  674. dataFile = pVarSet->get(GET_BSTR(DCTVS_ConfigurationFile));
  675. if ( serverName.length() )
  676. {
  677. errLog.DbgMsgWrite(0,L"%ls\t%ls\t%ls",(WCHAR*)serverName,L"JobFile",(WCHAR*)dataFile);
  678. hr = InstallToServer(serverName,dataFile);
  679. _bstr_t strChoice = pVarSet->get(GET_BSTR(DCTVS_Options_DeleteJobFile));
  680. if(strChoice == _bstr_t(GET_STRING(IDS_YES)))
  681. ::DeleteFile(dataFile);
  682. errLog.DbgMsgWrite(0,L"%ls\t%ls\t%ld",(WCHAR*)serverName,L"Install",HRESULT_CODE(hr));
  683. }
  684. return hr;
  685. }