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.

104 lines
2.4 KiB

  1. //
  2. // REGDVAL.C
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // Implementation of RegDeleteValue and supporting functions.
  7. //
  8. #include "pch.h"
  9. //
  10. // RgDeleteValueRecord
  11. //
  12. // Deletes the specified VALUE_RECORD from the provided KEY_RECORD.
  13. //
  14. VOID
  15. INTERNAL
  16. RgDeleteValueRecord(
  17. LPKEY_RECORD lpKeyRecord,
  18. LPVALUE_RECORD lpValueRecord
  19. )
  20. {
  21. UINT ValueRecordLength;
  22. LPBYTE lpSource;
  23. UINT BytesToPushDown;
  24. ASSERT(lpKeyRecord-> ValueCount > 0);
  25. ValueRecordLength = sizeof(VALUE_RECORD) + lpValueRecord-> NameLength +
  26. lpValueRecord-> DataLength - 1;
  27. ASSERT(lpKeyRecord-> RecordSize >= ValueRecordLength);
  28. //
  29. // If this isn't the last value of this KEY_RECORD, then push down any
  30. // VALUE_RECORDs after the VALUE_RECORD to delete.
  31. //
  32. if (--lpKeyRecord-> ValueCount) {
  33. lpSource = (LPBYTE) lpValueRecord + ValueRecordLength;
  34. BytesToPushDown = (UINT) ((LPBYTE) lpKeyRecord + lpKeyRecord->
  35. RecordSize - lpSource);
  36. MoveMemory((LPBYTE) lpValueRecord, lpSource, BytesToPushDown);
  37. }
  38. lpKeyRecord-> RecordSize -= ValueRecordLength;
  39. }
  40. //
  41. // VMMRegDeleteValue
  42. //
  43. // See Win32 documentation of RegDeleteValue.
  44. //
  45. LONG
  46. REGAPI
  47. VMMRegDeleteValue(
  48. HKEY hKey,
  49. LPCSTR lpValueName
  50. )
  51. {
  52. int ErrorCode;
  53. LPKEY_RECORD lpKeyRecord;
  54. LPVALUE_RECORD lpValueRecord;
  55. if (IsBadOptionalStringPtr(lpValueName, (UINT) -1))
  56. return ERROR_INVALID_PARAMETER;
  57. if (!RgLockRegistry())
  58. return ERROR_LOCK_FAILED;
  59. if ((ErrorCode = RgValidateAndConvertKeyHandle(&hKey)) == ERROR_SUCCESS) {
  60. if ((ErrorCode = RgLookupValueByName(hKey, lpValueName, &lpKeyRecord,
  61. &lpValueRecord)) == ERROR_SUCCESS) {
  62. if ((hKey-> PredefinedKeyIndex == INDEX_DYN_DATA) || (hKey->
  63. lpFileInfo-> Flags & FI_READONLY))
  64. ErrorCode = ERROR_ACCESS_DENIED;
  65. else {
  66. RgDeleteValueRecord(lpKeyRecord, lpValueRecord);
  67. RgSignalWaitingNotifies(hKey-> lpFileInfo, hKey-> KeynodeIndex,
  68. REG_NOTIFY_CHANGE_LAST_SET);
  69. }
  70. RgUnlockDatablock(hKey-> lpFileInfo, hKey-> BlockIndex, TRUE);
  71. }
  72. }
  73. RgUnlockRegistry();
  74. return ErrorCode;
  75. }