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.

160 lines
4.0 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: remotedb.cpp
  7. //
  8. // Contents:
  9. // all routine deal with cross table query
  10. //
  11. // History:
  12. // Feb 4, 98 HueiWang Created
  13. //---------------------------------------------------------------------------
  14. #include "pch.cpp"
  15. #include "globals.h"
  16. #include "remotedb.h"
  17. #include "kp.h"
  18. #include "lkpdesc.h"
  19. #include "keypack.h"
  20. #include "misc.h"
  21. ////////////////////////////////////////////////////////////////////////////
  22. DWORD
  23. TLSDBRemoteKeyPackAdd(
  24. IN PTLSDbWorkSpace pDbWkSpace,
  25. IN OUT PTLSLICENSEPACK lpKeyPack
  26. )
  27. /*++
  28. --*/
  29. {
  30. DWORD dwStatus = ERROR_SUCCESS;
  31. BOOL bSuccess = TRUE;
  32. TLSLICENSEPACK found;
  33. if(pDbWkSpace == NULL || lpKeyPack == NULL)
  34. {
  35. SetLastError(dwStatus = ERROR_INVALID_PARAMETER);
  36. TLSASSERT(FALSE);
  37. return dwStatus;
  38. }
  39. //
  40. // Lock table for update
  41. //
  42. TLSDBLockKeyPackTable();
  43. //
  44. // Quick fix so that find keypack will work.
  45. lpKeyPack->dwPlatformType |= LSKEYPACK_PLATFORM_REMOTE;
  46. //lpKeyPack->ucAgreementType |= (LSKEYPACK_REMOTE_TYPE | LSKEYPACK_HIDDEN_TYPE);
  47. lpKeyPack->ucKeyPackStatus |= (LSKEYPACKSTATUS_REMOTE | LSKEYPACKSTATUS_HIDDEN);
  48. LicPackTable& licpackTable = pDbWkSpace->m_LicPackTable;
  49. dwStatus = TLSDBKeyPackEnumBegin(
  50. pDbWkSpace,
  51. TRUE,
  52. LICENSEDPACK_FIND_PRODUCT,
  53. lpKeyPack
  54. );
  55. if(dwStatus != ERROR_SUCCESS)
  56. {
  57. goto cleanup;
  58. }
  59. while(TRUE)
  60. {
  61. dwStatus = TLSDBKeyPackEnumNext(
  62. pDbWkSpace,
  63. &found
  64. );
  65. if(dwStatus == TLS_I_NO_MORE_DATA)
  66. {
  67. break;
  68. }
  69. if(_tcsicmp(found.szInstallId, lpKeyPack->szInstallId) == 0)
  70. {
  71. // find product is based on company name,
  72. // keypack id, product id, platform type, so
  73. // this is duplicate
  74. //
  75. dwStatus = TLS_E_DUPLICATE_RECORD;
  76. if( lpKeyPack->dwNumberOfLicenses == 0 ||
  77. (lpKeyPack->ucKeyPackStatus & ~LSKEYPACK_RESERVED_TYPE) == LSKEYPACKSTATUS_REVOKED )
  78. {
  79. //
  80. // Try to be as fast as possible
  81. //
  82. licpackTable.DeleteRecord();
  83. }
  84. else
  85. {
  86. licpackTable.UpdateRecord(*lpKeyPack);
  87. }
  88. break;
  89. }
  90. }
  91. TLSDBKeyPackEnumEnd(pDbWkSpace);
  92. if(dwStatus == TLS_I_NO_MORE_DATA && lpKeyPack->dwNumberOfLicenses > 0)
  93. {
  94. lpKeyPack->dwKeyPackId = TLSDBGetNextKeyPackId();
  95. bSuccess = licpackTable.InsertRecord(*lpKeyPack);
  96. if(bSuccess == FALSE)
  97. {
  98. if(licpackTable.GetLastJetError() == JET_errKeyDuplicate)
  99. {
  100. TLSASSERT(FALSE); // this should no happen
  101. SetLastError(dwStatus=TLS_E_DUPLICATE_RECORD);
  102. }
  103. else
  104. {
  105. LPTSTR pString = NULL;
  106. TLSGetESEError(licpackTable.GetLastJetError(), &pString);
  107. TLSLogEvent(
  108. EVENTLOG_ERROR_TYPE,
  109. TLS_E_DBGENERAL,
  110. TLS_E_JB_BASE,
  111. licpackTable.GetLastJetError(),
  112. (pString != NULL) ? pString : _TEXT("")
  113. );
  114. if(pString != NULL)
  115. {
  116. LocalFree(pString);
  117. }
  118. SetLastError(dwStatus = SET_JB_ERROR(licpackTable.GetLastJetError()));
  119. TLSASSERT(FALSE);
  120. }
  121. }
  122. else
  123. {
  124. dwStatus = ERROR_SUCCESS;
  125. }
  126. }
  127. cleanup:
  128. TLSDBUnlockKeyPackTable();
  129. SetLastError(dwStatus);
  130. return dwStatus;
  131. }