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.

960 lines
23 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: postjob.cpp
  6. //
  7. // Contents: Post various job to job manager
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "pch.cpp"
  13. #include "postjob.h"
  14. #include "tlsjob.h"
  15. #include "globals.h"
  16. ////////////////////////////////////////////////////////////////
  17. BOOL
  18. IsLicensePackRepl(
  19. IN TLSLICENSEPACK* pLicensePack
  20. )
  21. /*++
  22. Abstract:
  23. Determine if license pack is replicable.
  24. Parameter:
  25. pLicensePack - License Pack.
  26. Returns:
  27. TRUE if license pack can be replicated to other serve
  28. FALSE otherwise.
  29. Remark:
  30. Do not replicate FREE or special license pack.
  31. --*/
  32. {
  33. BOOL bYes = TRUE;
  34. if(
  35. (pLicensePack->ucAgreementType == LSKEYPACKTYPE_FREE) ||
  36. (pLicensePack->ucAgreementType & (LSKEYPACK_REMOTE_TYPE | LSKEYPACK_HIDDEN_TYPE | LSKEYPACK_LOCAL_TYPE)) ||
  37. (pLicensePack->ucKeyPackStatus & (LSKEYPACKSTATUS_HIDDEN | LSKEYPACKSTATUS_REMOTE | LSKEYPACKSTATUS_LOCAL))
  38. )
  39. {
  40. bYes = FALSE;
  41. }
  42. if( bYes == TRUE )
  43. {
  44. UCHAR ucKeyPackStatus = (pLicensePack->ucKeyPackStatus & ~LSKEYPACKSTATUS_RESERVED);
  45. // don't replicate temp. license pack.
  46. if( ucKeyPackStatus == LSKEYPACKSTATUS_TEMPORARY )
  47. {
  48. bYes = FALSE;
  49. }
  50. }
  51. return bYes;
  52. }
  53. ////////////////////////////////////////////////////////////////
  54. BOOL
  55. TLSCanForwardRequest(
  56. IN DWORD dwLocalServerVersion,
  57. IN DWORD dwTargetServerVersion
  58. )
  59. /*++
  60. Abstract:
  61. Determine if version of server is compatible.
  62. Parameter:
  63. dwLocalServerVersion : Local server version.
  64. dwTargetServerVersion : Targer server version.
  65. Returns:
  66. TRUE/FALSE.
  67. Remark:
  68. Rules
  69. 1) No forward to server version older than 5.1.
  70. 2) Enforce to enforce, non-enforce to non-enforce only.
  71. 3) Enterprise to enterprise only.
  72. 4) domain/workgroup server to enterprise no enterprise
  73. to domain/workgroup.
  74. --*/
  75. {
  76. BOOL bCanForward;
  77. BOOL bLocalEnforce;
  78. BOOL bRemoteEnforce;
  79. bCanForward = TLSIsServerCompatible(
  80. dwLocalServerVersion,
  81. dwTargetServerVersion
  82. );
  83. //bLocalEnforce = IS_ENFORCE_SERVER(dwLocalServerVersion);
  84. //bRemoteEnforce = IS_ENFORCE_SERVER(dwTargetServerVersion);
  85. //
  86. // No enforce to non-enforce replication
  87. //
  88. //if( bLocalEnforce != bRemoteEnforce )
  89. //{
  90. // bCanForward = FALSE;
  91. //}
  92. if(bCanForward == TRUE)
  93. {
  94. BOOL bEnterpriseLocal = IS_ENTERPRISE_SERVER(dwLocalServerVersion);
  95. BOOL bEnterpriseRemote = IS_ENTERPRISE_SERVER(dwTargetServerVersion);
  96. if( g_SrvRole & TLSERVER_ENTERPRISE_SERVER )
  97. {
  98. bEnterpriseLocal = TRUE;
  99. }
  100. if(bEnterpriseLocal == TRUE && bEnterpriseRemote == FALSE)
  101. {
  102. bCanForward = FALSE;
  103. }
  104. }
  105. return bCanForward;
  106. }
  107. ////////////////////////////////////////////////////////////////
  108. BOOL
  109. TLSIsServerCompatible(
  110. IN DWORD dwLocalServerVersion,
  111. IN DWORD dwTargetServerVersion
  112. )
  113. /*++
  114. Abstract:
  115. Determine if two server is compatible.
  116. Parameters:
  117. dwLocalServerVersion : Local server version.
  118. dwTargetServerVersion : Target server version.
  119. Return:
  120. TRUE/FALSE.
  121. Remark:
  122. 1) No server older than 5.1
  123. 2) Enforce to enforce and non-enforce to non-enforce only
  124. --*/
  125. {
  126. DWORD dwTargetMajor = GET_SERVER_MAJOR_VERSION(dwTargetServerVersion);
  127. DWORD dwTargetMinor = GET_SERVER_MINOR_VERSION(dwTargetServerVersion);
  128. //
  129. // This version of License Server is not compatible with anyother
  130. if(dwTargetMajor == 5 && dwTargetMinor == 0)
  131. {
  132. return FALSE;
  133. }
  134. return (IS_ENFORCE_SERVER(dwLocalServerVersion) == IS_ENFORCE_SERVER(dwTargetServerVersion));
  135. }
  136. ////////////////////////////////////////////////////////////////
  137. BOOL
  138. TLSCanPushReplicateData(
  139. IN DWORD dwLocalServerVersion,
  140. IN DWORD dwTargetServerVersion
  141. )
  142. /*++
  143. Abstract:
  144. Determine if local server can 'push' replicate
  145. data to remote server.
  146. Parameters:
  147. dwLocalServerVersion : Local server version.
  148. dwTargetServerVersion : Target server version.
  149. Returns:
  150. TRUE/FALSE.
  151. Remark:
  152. 1) See TLSIsServerCompatible().
  153. 2) only one-way from enterprise to
  154. domain/workgroup server.
  155. --*/
  156. {
  157. BOOL bCanReplicate;
  158. BOOL bLocalEnforce;
  159. BOOL bRemoteEnforce;
  160. bCanReplicate = TLSIsServerCompatible(
  161. dwLocalServerVersion,
  162. dwTargetServerVersion
  163. );
  164. bLocalEnforce = IS_ENFORCE_SERVER(dwLocalServerVersion);
  165. bRemoteEnforce = IS_ENFORCE_SERVER(dwTargetServerVersion);
  166. //
  167. // No enforce to non-enforce replication
  168. //
  169. if( bLocalEnforce != bRemoteEnforce )
  170. {
  171. bCanReplicate = FALSE;
  172. }
  173. if(bCanReplicate == TRUE)
  174. {
  175. BOOL bEnterpriseLocal = IS_ENTERPRISE_SERVER(dwLocalServerVersion);
  176. BOOL bEnterpriseRemote = IS_ENTERPRISE_SERVER(dwTargetServerVersion);
  177. if( g_SrvRole & TLSERVER_ENTERPRISE_SERVER )
  178. {
  179. bEnterpriseLocal = TRUE;
  180. }
  181. if(bEnterpriseLocal == FALSE && bEnterpriseRemote == TRUE)
  182. {
  183. bCanReplicate = FALSE;
  184. }
  185. }
  186. return bCanReplicate;
  187. }
  188. ////////////////////////////////////////////////////////////////
  189. DWORD
  190. PostSsyncLkpJob(
  191. IN PSSYNCLICENSEPACK syncLkp
  192. )
  193. /*++
  194. Abstract:
  195. Wrapper to post a sync. license pack job to work manager.
  196. Parameter:
  197. syncLkp : License pack and other info to be sync.
  198. Returns:
  199. ERROR_SUCCESS or error code.
  200. --*/
  201. {
  202. DWORD dwStatus = ERROR_SUCCESS;
  203. CSsyncLicensePack* pSyncLicensePack;
  204. try {
  205. pSyncLicensePack = new CSsyncLicensePack(
  206. TRUE,
  207. syncLkp,
  208. sizeof(SSYNCLICENSEPACK)
  209. );
  210. //
  211. // Set work default interval/retry times
  212. //
  213. TLSWorkManagerSetJobDefaults(pSyncLicensePack);
  214. dwStatus = TLSWorkManagerSchedule(0, pSyncLicensePack);
  215. if(dwStatus != ERROR_SUCCESS)
  216. {
  217. TLSLogEvent(
  218. EVENTLOG_ERROR_TYPE,
  219. TLS_E_WORKMANAGERGENERAL,
  220. TLS_E_WORKMANAGER_SCHEDULEJOB,
  221. dwStatus
  222. );
  223. delete pSyncLicensePack;
  224. }
  225. }
  226. catch( SE_Exception e )
  227. {
  228. dwStatus = e.getSeNumber();
  229. TLSLogEvent(
  230. EVENTLOG_ERROR_TYPE,
  231. TLS_E_WORKMANAGERGENERAL,
  232. TLS_E_CREATEJOB,
  233. dwStatus
  234. );
  235. }
  236. catch( ... )
  237. {
  238. dwStatus = TLS_E_INTERNAL;
  239. TLSLogErrorEvent(TLS_E_INTERNAL);
  240. }
  241. return dwStatus;
  242. }
  243. //--------------------------------------------------------------------
  244. DWORD
  245. TLSAnnounceLKPToAllRemoteServer(
  246. IN DWORD dwKeyPackId,
  247. IN DWORD dwDelayTime
  248. )
  249. /*++
  250. Abstract:
  251. Announce a license pack by its internal ID to all
  252. known server.
  253. Parameter:
  254. dwKeyPackId : License keypack's internal tracking Id.
  255. Returns:
  256. ERROR_SUCCESS or error code.
  257. --*/
  258. {
  259. PTLServerInfo pServerInfo = NULL;
  260. DWORD dwStatus = ERROR_SUCCESS;
  261. DWORD dwCount;
  262. DBGPrintf(
  263. DBG_INFORMATION,
  264. DBG_FACILITY_JOB,
  265. DBGLEVEL_FUNCTION_TRACE,
  266. _TEXT("Announce %d LKP to servers...\n"),
  267. dwKeyPackId
  268. );
  269. SSYNCLICENSEPACK SsyncLkp;
  270. memset(
  271. &SsyncLkp,
  272. 0,
  273. sizeof(SSYNCLICENSEPACK)
  274. );
  275. SsyncLkp.dwStructVersion = CURRENT_SSYNCLICENSEKEYPACK_STRUCT_VER;
  276. SsyncLkp.dwStructSize = sizeof(SSYNCLICENSEPACK);
  277. SsyncLkp.dwSyncType = SSYNC_ONE_LKP;
  278. SsyncLkp.dwKeyPackId = dwKeyPackId;
  279. SsyncLkp.dwNumServer = 0;
  280. SAFESTRCPY(SsyncLkp.m_szServerId, g_pszServerPid);
  281. SAFESTRCPY(SsyncLkp.m_szServerName, g_szComputerName);
  282. //
  283. // Lock known server list
  284. //
  285. TLSBeginEnumKnownServerList();
  286. while((pServerInfo = TLSGetNextKnownServer()) != NULL)
  287. {
  288. if(TLSCanPushReplicateData(
  289. TLS_CURRENT_VERSION,
  290. pServerInfo->GetServerVersion()
  291. ) == FALSE)
  292. {
  293. continue;
  294. }
  295. if(pServerInfo->IsServerSupportReplication() == FALSE)
  296. {
  297. continue;
  298. }
  299. if(SsyncLkp.dwNumServer >= SSYNCLKP_MAX_TARGET)
  300. {
  301. dwStatus = PostSsyncLkpJob(&SsyncLkp);
  302. if(dwStatus != ERROR_SUCCESS)
  303. {
  304. break;
  305. }
  306. SsyncLkp.dwNumServer = 0;
  307. }
  308. SAFESTRCPY(
  309. SsyncLkp.m_szTargetServer[SsyncLkp.dwNumServer],
  310. pServerInfo->GetServerName()
  311. );
  312. SsyncLkp.dwNumServer++;
  313. }
  314. TLSEndEnumKnownServerList();
  315. if(dwStatus == ERROR_SUCCESS && SsyncLkp.dwNumServer != 0)
  316. {
  317. dwStatus = PostSsyncLkpJob(&SsyncLkp);
  318. }
  319. return dwStatus;
  320. }
  321. /////////////////////////////////////////////////////////////////////////
  322. DWORD
  323. TLSPushSyncLocalLkpToServer(
  324. IN LPTSTR pszSetupId,
  325. IN LPTSTR pszDomainName,
  326. IN LPTSTR pszLserverName,
  327. IN FILETIME* pSyncTime
  328. )
  329. /*++
  330. Abstract:
  331. 'Push' sync registered license pack to other server.
  332. Parameters:
  333. pszSetupId : Remote server's setup ID.
  334. pszDomainName : Remote server's domain name.
  335. pszLserverName : Remote server name.
  336. pSyncTime : Pointer to FILETIME, sync. all license pack with the time stamp
  337. greater or equal to this time will be 'push' sync.
  338. Returns:
  339. ERROR_SUCCESS or error code.
  340. --*/
  341. {
  342. DWORD dwStatus = ERROR_SUCCESS;
  343. TLServerInfo ServerInfo;
  344. SSYNCLICENSEPACK SsyncLkp;
  345. //
  346. // resolve ServerId to server name
  347. //
  348. dwStatus = TLSLookupRegisteredServer(
  349. pszSetupId,
  350. pszDomainName,
  351. pszLserverName,
  352. &ServerInfo
  353. );
  354. if(dwStatus != ERROR_SUCCESS)
  355. {
  356. goto cleanup;
  357. }
  358. //
  359. // Make sure local server can push replicate
  360. // data to remote server.
  361. //
  362. if(TLSCanPushReplicateData(
  363. TLS_CURRENT_VERSION,
  364. ServerInfo.GetServerVersion()
  365. ) == FALSE)
  366. {
  367. goto cleanup;
  368. }
  369. //
  370. // Form a sync work object and post it to work manager.
  371. //
  372. memset(
  373. &SsyncLkp,
  374. 0,
  375. sizeof(SSYNCLICENSEPACK)
  376. );
  377. SsyncLkp.dwStructVersion = CURRENT_SSYNCLICENSEKEYPACK_STRUCT_VER;
  378. SsyncLkp.dwStructSize = sizeof(SSYNCLICENSEPACK);
  379. SAFESTRCPY(SsyncLkp.m_szServerId, g_pszServerPid);
  380. SAFESTRCPY(SsyncLkp.m_szServerName, g_szComputerName);
  381. SsyncLkp.dwSyncType = SSYNC_ALL_LKP;
  382. SsyncLkp.dwNumServer = 1;
  383. SAFESTRCPY(
  384. SsyncLkp.m_szTargetServer[0],
  385. ServerInfo.GetServerName()
  386. );
  387. SsyncLkp.m_ftStartSyncTime = *pSyncTime;
  388. dwStatus = PostSsyncLkpJob(&SsyncLkp);
  389. cleanup:
  390. return dwStatus;
  391. }
  392. ////////////////////////////////////////////////////////////////
  393. DWORD
  394. TLSStartAnnounceResponseJob(
  395. IN LPTSTR pszTargetServerId,
  396. IN LPTSTR pszTargetServerDomain,
  397. IN LPTSTR pszTargetServerName,
  398. IN FILETIME* pftTime
  399. )
  400. /*++
  401. Abstract:
  402. Create a License Server Announcement response work object and post it
  403. to work manager.
  404. Parameter:
  405. pszTargetServerId : Target server Id.
  406. pszTargetServerDomain : Target server's domain.
  407. pszTargetServerName : Target server name.
  408. pftTime : Pointer to FILE, local server's last shutdown time.
  409. Returns:
  410. ERROR_SUCCESS or error code.
  411. --*/
  412. {
  413. DWORD dwStatus = ERROR_SUCCESS;
  414. ANNOUNCERESPONSEWO response;
  415. TLServerInfo ServerInfo;
  416. CAnnounceResponse* pAnnounceResponse = NULL;
  417. //
  418. // Perform lookup on server to determine its eligibility
  419. //
  420. dwStatus = TLSLookupRegisteredServer(
  421. pszTargetServerId,
  422. pszTargetServerDomain,
  423. pszTargetServerName,
  424. &ServerInfo
  425. );
  426. if(dwStatus != ERROR_SUCCESS)
  427. {
  428. // can't find server, no response
  429. goto cleanup;
  430. }
  431. memset(&response, 0, sizeof(response));
  432. response.dwStructVersion = CURRENT_ANNOUNCERESPONSEWO_STRUCT_VER;
  433. response.dwStructSize = sizeof(response);
  434. response.bCompleted = FALSE;
  435. SAFESTRCPY(response.m_szTargetServerId, pszTargetServerId);
  436. SAFESTRCPY(response.m_szLocalServerId, g_pszServerPid);
  437. SAFESTRCPY(response.m_szLocalServerName, g_szComputerName);
  438. SAFESTRCPY(response.m_szLocalScope, g_szScope);
  439. response.m_ftLastShutdownTime = *pftTime;
  440. try {
  441. pAnnounceResponse = new CAnnounceResponse(
  442. TRUE,
  443. &response,
  444. sizeof(response)
  445. );
  446. //
  447. // Set work default interval/retry times
  448. //
  449. TLSWorkManagerSetJobDefaults(pAnnounceResponse);
  450. dwStatus = TLSWorkManagerSchedule(0, pAnnounceResponse);
  451. if(dwStatus != ERROR_SUCCESS)
  452. {
  453. TLSLogEvent(
  454. EVENTLOG_ERROR_TYPE,
  455. TLS_E_WORKMANAGERGENERAL,
  456. TLS_E_WORKMANAGER_SCHEDULEJOB,
  457. dwStatus
  458. );
  459. delete pAnnounceResponse;
  460. }
  461. }
  462. catch( SE_Exception e )
  463. {
  464. dwStatus = e.getSeNumber();
  465. TLSLogEvent(
  466. EVENTLOG_ERROR_TYPE,
  467. TLS_E_WORKMANAGERGENERAL,
  468. TLS_E_CREATEJOB,
  469. dwStatus
  470. );
  471. }
  472. catch( ... )
  473. {
  474. dwStatus = TLS_E_INTERNAL;
  475. TLSLogErrorEvent(TLS_E_INTERNAL);
  476. }
  477. cleanup:
  478. return dwStatus;
  479. }
  480. /////////////////////////////////////////////////////////////////////
  481. DWORD
  482. TLSStartAnnounceToEServerJob(
  483. IN LPCTSTR pszServerId,
  484. IN LPCTSTR pszServerDomain,
  485. IN LPCTSTR pszServerName,
  486. IN FILETIME* pftFileTime
  487. )
  488. /*++
  489. Abstract:
  490. Create a Enterprise server discovery job and post it to work
  491. manager.
  492. Parameters:
  493. pszServerId : Local server's ID.
  494. pszServerDomain : Local server's domain.
  495. pszServerName : Local server name.
  496. pftFileTime : Pointer to FILETIME, local server's last shutdown time.
  497. Returns:
  498. ERROR_SUCCESS or error code.
  499. --*/
  500. {
  501. DWORD dwStatus = ERROR_SUCCESS;
  502. ANNOUNCETOESERVERWO AnnounceToES;
  503. memset(&AnnounceToES, 0, sizeof(AnnounceToES));
  504. AnnounceToES.dwStructVersion = CURRENT_ANNOUNCETOESERVEWO_STRUCT_VER;
  505. AnnounceToES.dwStructSize = sizeof(ANNOUNCETOESERVERWO);
  506. AnnounceToES.bCompleted = FALSE;
  507. SAFESTRCPY(AnnounceToES.m_szServerId, pszServerId);
  508. SAFESTRCPY(AnnounceToES.m_szServerName, pszServerName);
  509. SAFESTRCPY(AnnounceToES.m_szScope, pszServerDomain);
  510. AnnounceToES.m_ftLastShutdownTime = *pftFileTime;
  511. CAnnounceToEServer* pAnnounceESWO = NULL;
  512. try {
  513. pAnnounceESWO = new CAnnounceToEServer(
  514. TRUE,
  515. &AnnounceToES,
  516. sizeof(ANNOUNCETOESERVERWO)
  517. );
  518. //
  519. // Set work default interval/retry times
  520. //
  521. TLSWorkManagerSetJobDefaults(pAnnounceESWO);
  522. dwStatus = TLSWorkManagerSchedule(0, pAnnounceESWO);
  523. if(dwStatus != ERROR_SUCCESS)
  524. {
  525. TLSLogEvent(
  526. EVENTLOG_ERROR_TYPE,
  527. TLS_E_WORKMANAGERGENERAL,
  528. TLS_E_WORKMANAGER_SCHEDULEJOB,
  529. dwStatus
  530. );
  531. delete pAnnounceESWO;
  532. }
  533. }
  534. catch( SE_Exception e )
  535. {
  536. dwStatus = e.getSeNumber();
  537. TLSLogEvent(
  538. EVENTLOG_ERROR_TYPE,
  539. TLS_E_WORKMANAGERGENERAL,
  540. TLS_E_CREATEJOB,
  541. dwStatus
  542. );
  543. }
  544. catch( ... )
  545. {
  546. dwStatus = TLS_E_INTERNAL;
  547. TLSLogErrorEvent(TLS_E_INTERNAL);
  548. }
  549. return dwStatus;
  550. }
  551. /////////////////////////////////////////////////////////////////////////
  552. DWORD
  553. TLSStartAnnounceLicenseServerJob(
  554. IN LPCTSTR pszServerId,
  555. IN LPCTSTR pszServerDomain,
  556. IN LPCTSTR pszServerName,
  557. IN FILETIME* pftFileTime
  558. )
  559. /*++
  560. Abstract:
  561. Create a license server announcement job and post it to work
  562. manager.
  563. Parameters:
  564. pszServerId : Local server's ID.
  565. pszServerDomain : Local server domain.
  566. pszServerName : Local server name.
  567. pftFileTime : Pointer to FILETIME, local server's last shutdown time.
  568. Returns:
  569. ERROR_SUCCESS or error code.
  570. --*/
  571. {
  572. DWORD dwStatus = ERROR_SUCCESS;
  573. //
  574. // Create a CAnnounce Server work.
  575. //
  576. ANNOUNCESERVERWO AnnounceLs;
  577. memset(&AnnounceLs, 0, sizeof(AnnounceLs));
  578. AnnounceLs.dwStructVersion = CURRENT_ANNOUNCETOESERVEWO_STRUCT_VER;
  579. AnnounceLs.dwStructSize = sizeof(ANNOUNCETOESERVERWO);
  580. AnnounceLs.dwRetryTimes = 0;
  581. SAFESTRCPY(AnnounceLs.m_szServerId, pszServerId);
  582. SAFESTRCPY(AnnounceLs.m_szServerName, pszServerName);
  583. SAFESTRCPY(AnnounceLs.m_szScope, pszServerDomain);
  584. AnnounceLs.m_ftLastShutdownTime = *pftFileTime;
  585. CAnnounceLserver* pAnnounceWO = NULL;
  586. try {
  587. pAnnounceWO = new CAnnounceLserver(
  588. TRUE,
  589. &AnnounceLs,
  590. sizeof(ANNOUNCETOESERVERWO)
  591. );
  592. //
  593. // Set work default interval/retry times
  594. //
  595. // Don't take other parameter for Announce Server
  596. // TLSWorkManagerSetJobDefaults(pAnnounceWO);
  597. dwStatus = TLSWorkManagerSchedule(0, pAnnounceWO);
  598. if(dwStatus != ERROR_SUCCESS)
  599. {
  600. TLSLogEvent(
  601. EVENTLOG_ERROR_TYPE,
  602. TLS_E_WORKMANAGERGENERAL,
  603. TLS_E_WORKMANAGER_SCHEDULEJOB,
  604. dwStatus
  605. );
  606. delete pAnnounceWO;
  607. }
  608. }
  609. catch( SE_Exception e )
  610. {
  611. dwStatus = e.getSeNumber();
  612. TLSLogEvent(
  613. EVENTLOG_ERROR_TYPE,
  614. TLS_E_WORKMANAGERGENERAL,
  615. TLS_E_CREATEJOB,
  616. dwStatus
  617. );
  618. }
  619. catch( ... )
  620. {
  621. dwStatus = TLS_E_INTERNAL;
  622. TLSLogErrorEvent(TLS_E_INTERNAL);
  623. }
  624. return dwStatus;
  625. }
  626. ////////////////////////////////////////////////////////////////
  627. DWORD
  628. TLSPostReturnClientLicenseJob(
  629. IN PLICENSEDPRODUCT pLicProduct
  630. )
  631. /*++
  632. Abstract:
  633. Create a return license work object and post it to work manager.
  634. Parameters:
  635. pLicProduct : Licensed product to be return/revoke...
  636. Returns:
  637. ERROR_SUCCESS or error success.
  638. Remark:
  639. Return license is a persistent job.
  640. --*/
  641. {
  642. DWORD dwStatus = ERROR_SUCCESS;
  643. RETURNLICENSEWO retlic;
  644. CReturnLicense* pReturnLicenseWO = NULL;
  645. //---------------------------------------------------------------
  646. if( pLicProduct == NULL || pLicProduct->pLicensedVersion == NULL ||
  647. pLicProduct->LicensedProduct.cbEncryptedHwid >= sizeof(retlic.pbEncryptedHwid) )
  648. {
  649. TLSASSERT(FALSE);
  650. SetLastError(dwStatus = ERROR_INVALID_DATA);
  651. goto cleanup;
  652. }
  653. memset(&retlic, 0, sizeof(retlic));
  654. retlic.dwStructVersion = CURRENT_RETURNLICENSEWO_STRUCT_VER;
  655. retlic.dwStructSize = sizeof(retlic);
  656. retlic.dwNumRetry = 0;
  657. SAFESTRCPY(retlic.szTargetServerId, pLicProduct->szIssuerId);
  658. SAFESTRCPY(retlic.szTargetServerName, pLicProduct->szIssuer);
  659. retlic.dwQuantity = pLicProduct->dwQuantity;
  660. retlic.dwKeyPackId = pLicProduct->ulSerialNumber.HighPart;
  661. retlic.dwLicenseId = pLicProduct->ulSerialNumber.LowPart;
  662. retlic.dwReturnReason = LICENSERETURN_UPGRADE;
  663. retlic.dwPlatformId = pLicProduct->LicensedProduct.dwPlatformID;
  664. retlic.cbEncryptedHwid = pLicProduct->LicensedProduct.cbEncryptedHwid;
  665. memcpy(
  666. retlic.pbEncryptedHwid,
  667. pLicProduct->LicensedProduct.pbEncryptedHwid,
  668. pLicProduct->LicensedProduct.cbEncryptedHwid
  669. );
  670. retlic.dwProductVersion = MAKELONG(
  671. pLicProduct->pLicensedVersion->wMinorVersion,
  672. pLicProduct->pLicensedVersion->wMajorVersion
  673. );
  674. memcpy(
  675. retlic.szOrgProductID,
  676. pLicProduct->pbOrgProductID,
  677. min(sizeof(retlic.szOrgProductID) - sizeof(TCHAR), pLicProduct->cbOrgProductID)
  678. );
  679. memcpy(
  680. retlic.szCompanyName,
  681. pLicProduct->LicensedProduct.pProductInfo->pbCompanyName,
  682. min(sizeof(retlic.szCompanyName)-sizeof(TCHAR), pLicProduct->LicensedProduct.pProductInfo->cbCompanyName)
  683. );
  684. memcpy(
  685. retlic.szProductId,
  686. pLicProduct->LicensedProduct.pProductInfo->pbProductID,
  687. min(sizeof(retlic.szProductId)-sizeof(TCHAR), pLicProduct->LicensedProduct.pProductInfo->cbProductID)
  688. );
  689. lstrcpy(
  690. retlic.szUserName,
  691. pLicProduct->szLicensedUser
  692. );
  693. lstrcpy(
  694. retlic.szMachineName,
  695. pLicProduct->szLicensedClient
  696. );
  697. try {
  698. pReturnLicenseWO = new CReturnLicense(
  699. TRUE,
  700. &retlic,
  701. sizeof(retlic)
  702. );
  703. //
  704. // Set work default interval/retry times
  705. //
  706. // Don't take other parameter for Announce Server
  707. // TLSWorkManagerSetJobDefaults(pAnnounceWO);
  708. dwStatus = TLSWorkManagerSchedule(0, pReturnLicenseWO);
  709. if(dwStatus != ERROR_SUCCESS)
  710. {
  711. TLSLogEvent(
  712. EVENTLOG_ERROR_TYPE,
  713. TLS_E_WORKMANAGERGENERAL,
  714. TLS_E_WORKMANAGER_SCHEDULEJOB,
  715. dwStatus
  716. );
  717. }
  718. //
  719. // Work storage will make a copy of this job so we need
  720. // to delete it.
  721. //
  722. delete pReturnLicenseWO;
  723. }
  724. catch( SE_Exception e )
  725. {
  726. dwStatus = e.getSeNumber();
  727. TLSLogEvent(
  728. EVENTLOG_ERROR_TYPE,
  729. TLS_E_WORKMANAGERGENERAL,
  730. TLS_E_CREATEJOB,
  731. dwStatus
  732. );
  733. }
  734. catch( ... )
  735. {
  736. dwStatus = TLS_E_INTERNAL;
  737. TLSLogErrorEvent(TLS_E_INTERNAL);
  738. }
  739. cleanup:
  740. return dwStatus;
  741. }