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.

121 lines
3.4 KiB

  1. //
  2. // REGDYKEY.C
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // Implementation of RegCreateDynKey and supporting functions.
  7. //
  8. #include "pch.h"
  9. #ifdef WANT_DYNKEY_SUPPORT
  10. #ifdef VXD
  11. #pragma VxD_RARE_CODE_SEG
  12. #endif
  13. //
  14. // VMMRegCreateDynKey
  15. //
  16. // See VMM DDK of _RegCreateDynKey.
  17. //
  18. LONG
  19. REGAPI
  20. VMMRegCreateDynKey(
  21. LPCSTR lpKeyName,
  22. LPVOID KeyContext,
  23. PPROVIDER pProvider,
  24. PPVALUE pValueList,
  25. DWORD ValueCount,
  26. LPHKEY lphKey
  27. )
  28. {
  29. LONG ErrorCode;
  30. HKEY hKey;
  31. PINTERNAL_PROVIDER pProviderCopy;
  32. PPVALUE pCurrentValue;
  33. if (IsBadHugeReadPtr(pProvider, sizeof(REG_PROVIDER)) ||
  34. (IsNullPtr(pProvider-> pi_R0_1val) &&
  35. IsNullPtr(pProvider-> pi_R0_allvals)) ||
  36. IsBadHugeReadPtr(pValueList, sizeof(PVALUE) * ValueCount))
  37. return ERROR_INVALID_PARAMETER;
  38. // The key could currently exist. Win95 didn't handle this case,
  39. // so would we have problems changing this behavior now?
  40. if ((ErrorCode = RgCreateOrOpenKey(HKEY_DYN_DATA, lpKeyName, &hKey,
  41. LK_CREATE | LK_CREATEDYNDATA)) != ERROR_SUCCESS)
  42. return ErrorCode;
  43. if (!RgLockRegistry())
  44. ErrorCode = ERROR_LOCK_FAILED;
  45. else {
  46. pProviderCopy = RgSmAllocMemory(sizeof(INTERNAL_PROVIDER));
  47. if (IsNullPtr(pProviderCopy))
  48. ErrorCode = ERROR_OUTOFMEMORY;
  49. else {
  50. // ErrorCode = ERROR_SUCCESS; // Must be true if we're here...
  51. hKey-> pProvider = pProviderCopy;
  52. // If no "get single" callback was provided, we can just use the
  53. // "get atomic" callback.
  54. if (IsNullPtr(pProvider-> pi_R0_1val))
  55. pProviderCopy-> ipi_R0_1val = pProvider-> pi_R0_allvals;
  56. else
  57. pProviderCopy-> ipi_R0_1val = pProvider-> pi_R0_1val;
  58. pProviderCopy-> ipi_R0_allvals = pProvider-> pi_R0_allvals;
  59. pProviderCopy-> ipi_key_context = KeyContext;
  60. // No point in keeping a whole DWORD for one bit when we can fit
  61. // it inside the main key structure.
  62. if (pProvider-> pi_flags & PROVIDER_KEEPS_VALUE_LENGTH)
  63. hKey-> Flags |= KEYF_PROVIDERHASVALUELENGTH;
  64. // Loop over all the values and store each name in the registry
  65. // with a partial PVALUE record as the value's data.
  66. for (pCurrentValue = pValueList; ValueCount > 0; ValueCount--,
  67. pCurrentValue++) {
  68. if (IsBadStringPtr(pCurrentValue-> pv_valuename, (UINT) -1)) {
  69. ErrorCode = ERROR_INVALID_PARAMETER;
  70. break;
  71. }
  72. // Skip storing the pv_valuename field.
  73. if ((ErrorCode = RgSetValue(hKey, pCurrentValue-> pv_valuename,
  74. REG_BINARY, (LPBYTE) &(pCurrentValue-> pv_valuelen),
  75. sizeof(PVALUE) - FIELD_OFFSET(PVALUE, pv_valuelen))) !=
  76. ERROR_SUCCESS) {
  77. TRAP();
  78. break;
  79. }
  80. }
  81. }
  82. RgUnlockRegistry();
  83. }
  84. // Win95 difference: on an error, don't modify lphKey and close the key
  85. // created above.
  86. if (ErrorCode == ERROR_SUCCESS)
  87. *lphKey = hKey;
  88. else
  89. VMMRegCloseKey(hKey);
  90. return ErrorCode;
  91. }
  92. #endif // WANT_DYNKEY_SUPPORT