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.

150 lines
3.8 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. licpackTable.UpdateRecord(*lpKeyPack);
  77. break;
  78. }
  79. }
  80. TLSDBKeyPackEnumEnd(pDbWkSpace);
  81. if(dwStatus == TLS_I_NO_MORE_DATA && lpKeyPack->dwNumberOfLicenses > 0)
  82. {
  83. lpKeyPack->dwKeyPackId = TLSDBGetNextKeyPackId();
  84. bSuccess = licpackTable.InsertRecord(*lpKeyPack);
  85. if(bSuccess == FALSE)
  86. {
  87. if(licpackTable.GetLastJetError() == JET_errKeyDuplicate)
  88. {
  89. TLSASSERT(FALSE); // this should no happen
  90. SetLastError(dwStatus=TLS_E_DUPLICATE_RECORD);
  91. }
  92. else
  93. {
  94. LPTSTR pString = NULL;
  95. TLSGetESEError(licpackTable.GetLastJetError(), &pString);
  96. TLSLogEvent(
  97. EVENTLOG_ERROR_TYPE,
  98. TLS_E_DBGENERAL,
  99. TLS_E_JB_BASE,
  100. licpackTable.GetLastJetError(),
  101. (pString != NULL) ? pString : _TEXT("")
  102. );
  103. if(pString != NULL)
  104. {
  105. LocalFree(pString);
  106. }
  107. SetLastError(dwStatus = SET_JB_ERROR(licpackTable.GetLastJetError()));
  108. TLSASSERT(FALSE);
  109. }
  110. }
  111. else
  112. {
  113. dwStatus = ERROR_SUCCESS;
  114. }
  115. }
  116. cleanup:
  117. TLSDBUnlockKeyPackTable();
  118. SetLastError(dwStatus);
  119. return dwStatus;
  120. }