Пример #1
0
NTSTATUS
SampRegDeleteKey(IN HANDLE ParentKeyHandle,
                 IN LPCWSTR KeyName)
{
    OBJECT_ATTRIBUTES ObjectAttributes;
    UNICODE_STRING SubKeyName;
    HANDLE TargetKey;
    NTSTATUS Status;

    RtlInitUnicodeString(&SubKeyName,
                         (LPWSTR)KeyName);
    InitializeObjectAttributes(&ObjectAttributes,
                               &SubKeyName,
                               OBJ_CASE_INSENSITIVE,
                               ParentKeyHandle,
                               NULL);
    Status = NtOpenKey(&TargetKey,
                       DELETE,
                       &ObjectAttributes);
    if (!NT_SUCCESS(Status))
        return Status;

    Status = NtDeleteKey(TargetKey);

    NtClose(TargetKey);

    return Status;
}
Пример #2
0
void DeleteKeyTest(void)
{
  OBJECT_ATTRIBUTES ObjectAttributes;
  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\testkey");
  HANDLE hKey;
  NTSTATUS Status;

  dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n");

  InitializeObjectAttributes(&ObjectAttributes,
			     &KeyName,
			     OBJ_CASE_INSENSITIVE,
			     NULL,
			     NULL);
  dprintf("NtOpenKey:\n");
  Status = NtOpenKey(&hKey,
		     KEY_ALL_ACCESS,
		     &ObjectAttributes);
  dprintf("  Status = %lx\n",Status);
  if (!NT_SUCCESS(Status))
    return;

  dprintf("NtDeleteKey:\n");
  Status = NtDeleteKey(hKey);
  dprintf("  Status = %lx\n",Status);
  NtClose(hKey);
}
Пример #3
0
static VOID
DestroyProtoHive(
    IN HANDLE KeyHandle)
{
    NtDeleteKey(KeyHandle);
    NtClose(KeyHandle);
}
Пример #4
0
BOOL
DeleteGroup(
    HANDLE GroupsKey,
    PWSTR GroupName
    )
{
    NTSTATUS Status;
    UNICODE_STRING KeyName, ValueName;
    HANDLE Key;
    OBJECT_ATTRIBUTES ObjectAttributes;
    ULONG CreateDisposition;
    LONG ValueLength;


    RtlInitUnicodeString( &KeyName, GroupName );
    InitializeObjectAttributes( &ObjectAttributes,
                                &KeyName,
                                OBJ_CASE_INSENSITIVE,
                                GroupsKey,
                                NULL
                              );
    Status = NtOpenKey( &Key,
                        STANDARD_RIGHTS_WRITE |
                          DELETE |
                          KEY_QUERY_VALUE |
                          KEY_ENUMERATE_SUB_KEYS |
                          KEY_SET_VALUE |
                          KEY_CREATE_SUB_KEY,
                        &ObjectAttributes
                      );
    if (!NT_SUCCESS( Status )) {
        if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
            return TRUE;
            }
        else {
            BaseSetLastNTError( Status );
            return FALSE;
            }
        }

    Status = NtDeleteKey( Key );
    NtClose( Key );
    if (!NT_SUCCESS( Status )) {
        return FALSE;
        }
    else {
        return TRUE;
        }
}
Пример #5
0
/* registry link delete test */
void test7(void)
{
  HANDLE hKey;
  OBJECT_ATTRIBUTES ObjectAttributes;
  UNICODE_STRING KeyName,ValueName;
  NTSTATUS Status;

  dprintf("Open link key\n");
  dprintf("  Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
  RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Test");
  InitializeObjectAttributes(&ObjectAttributes,
			     &KeyName,
			     OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_OPENLINK,
			     NULL,
			     NULL);
  Status = NtCreateKey(&hKey,
		       KEY_ALL_ACCESS,
		       &ObjectAttributes,
		       0,
		       NULL,
		       REG_OPTION_VOLATILE | REG_OPTION_OPEN_LINK,
		       NULL);
  dprintf("  NtCreateKey() called (Status %lx)\n",Status);
  if (!NT_SUCCESS(Status))
    {
      dprintf("Could not open the link key. Please run the link create test first!\n");
      return;
    }

  dprintf("Delete link value\n");
  RtlRosInitUnicodeStringFromLiteral(&ValueName, L"SymbolicLinkValue");
  Status = NtDeleteValueKey(hKey,
			    &ValueName);
  dprintf("  NtDeleteValueKey() called (Status %lx)\n",Status);

  dprintf("Delete link key\n");
  Status=NtDeleteKey(hKey);
  dprintf("  NtDeleteKey() called (Status %lx)\n",Status);

  dprintf("Close link key\n");
  NtClose(hKey);
}
Пример #6
0
void test3(void)
{
 HANDLE hKey;
 OBJECT_ATTRIBUTES ObjectAttributes;
 UNICODE_STRING KeyName;
 NTSTATUS Status;
 char Buffer[10];
 DWORD Result;
  dprintf("NtCreateKey non volatile: \n");
  dprintf("  \\Registry\\Machine\\Software\\test3reactos: ");
  RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
  InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
				, NULL, NULL);
  Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
		,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
  dprintf("\t\tStatus=%x\n",Status);
  NtClose(hKey);

  dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
  ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
  if (Buffer[0] != 'y' && Buffer[0] != 'Y') return;

  dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
  RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
  InitializeObjectAttributes(&ObjectAttributes,
                               &KeyName,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);
  dprintf("NtOpenKey : ");
  Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
  dprintf("\t\t\t\tStatus =%x\n",Status);
  dprintf("NtDeleteKey : ");
  Status=NtDeleteKey(hKey);
  dprintf("\t\t\t\tStatus =%x\n",Status);
  NtClose(hKey);
}
Пример #7
0
BOOLEAN
IopInitializeDeviceInstanceKey(
    IN HANDLE KeyHandle,
    IN PUNICODE_STRING KeyName,
    IN OUT PVOID WorkName
    )

/*++

Routine Description:

    This routine is a callback function for IopApplyFunctionToSubKeys.
    It is called for each subkey under HKLM\System\Enum\BusKey\DeviceKey.

Arguments:

    KeyHandle - Supplies a handle to this key.

    KeyName - Supplies the name of this key.

    WorkName - points to the unicodestring which describes the path up to
        this key.

Returns:

    TRUE to continue the enumeration.
    FALSE to abort it.

--*/
{
    UNICODE_STRING unicodeName, serviceName;
    PKEY_VALUE_FULL_INFORMATION keyValueInformation;
    NTSTATUS status;
    BOOLEAN duplicate = FALSE;
    ULONG foundAtEnum, deviceFlags, instance, tmpValue1, tmpValue2;
    USHORT length;
    PUNICODE_STRING pUnicode;

    //
    // Get the "Problem" value entry to determine what we need to do with
    // the device instance key.
    //

    deviceFlags = 0;
    status = IopGetRegistryValue ( KeyHandle,
                                   REGSTR_VALUE_PROBLEM,
                                   &keyValueInformation
                                   );
    if (NT_SUCCESS(status)) {
        if ((keyValueInformation->Type == REG_DWORD) &&
            (keyValueInformation->DataLength >= sizeof(ULONG))) {
            deviceFlags = *(PULONG)KEY_VALUE_DATA(keyValueInformation);
        }
        ExFreePool(keyValueInformation);
    }

    if (deviceFlags == CM_PROB_MOVED) {

        //
        // If the device instance was moved, we simply delete the key.
        // The key will be deleted once the caller close the open handle.
        //

        NtDeleteKey(KeyHandle);
        return TRUE;
    }

    //
    // The device instance key exists.  We need to propagate the ConfigFlag
    // to problem and StatusFlags
    //

    deviceFlags = 0;
    status = IopGetRegistryValue(KeyHandle,
                                 REGSTR_VALUE_CONFIG_FLAGS,
                                 &keyValueInformation);
    if (NT_SUCCESS(status)) {
        if ((keyValueInformation->Type == REG_DWORD) &&
            (keyValueInformation->DataLength >= sizeof(ULONG))) {
            deviceFlags = *(PULONG)KEY_VALUE_DATA(keyValueInformation);
        }
        ExFreePool(keyValueInformation);
    }
    if (deviceFlags & CONFIGFLAG_REINSTALL) {

        tmpValue1 = CM_PROB_REINSTALL;      // Problem
        tmpValue2 = DN_HAS_PROBLEM;         // StatusFlags
    } else {
        tmpValue1 = tmpValue2 = 0;
    }
    PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_PROBLEM);
    NtSetValueKey(KeyHandle,
                  &unicodeName,
                  TITLE_INDEX_VALUE,
                  REG_DWORD,
                  &tmpValue1,
                  sizeof(tmpValue1)
                  );

    PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_STATUSFLAGS);
    NtSetValueKey(KeyHandle,
                  &unicodeName,
                  TITLE_INDEX_VALUE,
                  REG_DWORD,
                  &tmpValue2,
                  sizeof(tmpValue2)
                  );

    //
    // Get the "DuplicateOf" value entry to determine if the device instance
    // should be registered.  If the device instance is duplicate, We don't
    // add it to its service key's enum branch.
    //

    status = IopGetRegistryValue ( KeyHandle,
                                   REGSTR_VALUE_DUPLICATEOF,
                                   &keyValueInformation
                                   );
    if (NT_SUCCESS(status)) {
        if ((keyValueInformation->Type == REG_SZ) &&
            (keyValueInformation->DataLength > 0)) {
            duplicate = TRUE;
        }
        ExFreePool(keyValueInformation);
    }

    if (!duplicate) {

        //
        // Combine WorkName and KeyName to form device instance path
        // and register this device instance by
        // constructing new value entry for ServiceKeyName\Enum key.
        // i.e., <Number> = <PathToSystemEnumBranch>
        //

        pUnicode = (PUNICODE_STRING)WorkName;
        length = pUnicode->Length;                  // Save WorkName
        if (pUnicode->Buffer[pUnicode->Length / sizeof(WCHAR) - 1] != OBJ_NAME_PATH_SEPARATOR) {
            pUnicode->Buffer[pUnicode->Length / sizeof(WCHAR)] = OBJ_NAME_PATH_SEPARATOR;
            pUnicode->Length += 2;
        }
        RtlAppendStringToString((PSTRING)pUnicode, (PSTRING)KeyName);
        PpDeviceRegistration(pUnicode, TRUE);
        pUnicode->Length = length;                  // Restore WorkName
    }

    //
    // Get the "Service=" value entry from KeyHandle
    //

    keyValueInformation = NULL;
    serviceName.Length = 0;
    status = IopGetRegistryValue ( KeyHandle,
                                   REGSTR_VALUE_SERVICE,
                                   &keyValueInformation
                                   );
    if (NT_SUCCESS(status)) {

        //
        // Append the new instance to its corresponding
        // Service\Name\Enum.
        //

        if ((keyValueInformation->Type == REG_SZ) &&
            (keyValueInformation->DataLength != 0)) {

            //
            // Set up ServiceKeyName unicode string
            //

            IopRegistryDataToUnicodeString(
                              &serviceName,
                              (PWSTR)KEY_VALUE_DATA(keyValueInformation),
                              keyValueInformation->DataLength
                              );
        }

        //
        // Do not Free keyValueInformation
        //

    }

    //
    // The Pnp mgr set FoundAtEnum to 0 for everything under system\ccs\enum.
    // For the stuff under Root we need to set them to 1 except if their
    // CsConfigFlags was set to CSCONFIGFLAG_DO_NOT_CREATE.
    //

    foundAtEnum = 1;
    status = RtlUnicodeStringToInteger(KeyName, 10, &instance);
    if (NT_SUCCESS(status)) {
        if (serviceName.Length != 0) {
            status = IopGetDeviceInstanceCsConfigFlags(
                         &serviceName,
                         instance,
                         &deviceFlags
                         );

            if (NT_SUCCESS(status) && (deviceFlags & CSCONFIGFLAG_DO_NOT_CREATE)) {
                foundAtEnum = 0;
            }
        }
    }
    if (keyValueInformation) {
        ExFreePool(keyValueInformation);
    }
    PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_FOUNDATENUM);
    NtSetValueKey(KeyHandle,
                  &unicodeName,
                  TITLE_INDEX_VALUE,
                  REG_DWORD,
                  &foundAtEnum,
                  sizeof(foundAtEnum)
                  );

    //
    // Clean up "NtLogicalDevicePaths=" and "NtPhysicalDevicePaths=" of this key
    //

    PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_NT_PHYSICAL_DEVICE_PATHS);
    NtDeleteValueKey(KeyHandle, &unicodeName);

    PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_NT_LOGICAL_DEVICE_PATHS);
    NtDeleteValueKey(KeyHandle, &unicodeName);

    return TRUE;
}
Пример #8
0
NTSTATUS KphSetParameters(
    _In_opt_ PWSTR DeviceName,
    _In_ PKPH_PARAMETERS Parameters
    )
{
    NTSTATUS status;
    HANDLE parametersKeyHandle = NULL;
    PPH_STRING parametersKeyName;
    ULONG disposition;
    UNICODE_STRING valueName;

    if (!DeviceName)
        DeviceName = KPH_DEVICE_SHORT_NAME;

    parametersKeyName = PhConcatStrings(
        3,
        L"System\\CurrentControlSet\\Services\\",
        DeviceName,
        L"\\Parameters"
        );
    status = PhCreateKey(
        &parametersKeyHandle,
        KEY_WRITE | DELETE,
        PH_KEY_LOCAL_MACHINE,
        &parametersKeyName->sr,
        0,
        0,
        &disposition
        );
    PhDereferenceObject(parametersKeyName);

    if (!NT_SUCCESS(status))
        return status;

    RtlInitUnicodeString(&valueName, L"SecurityLevel");
    status = NtSetValueKey(parametersKeyHandle, &valueName, 0, REG_DWORD, &Parameters->SecurityLevel, sizeof(ULONG));

    if (!NT_SUCCESS(status))
        goto SetValuesEnd;

    if (Parameters->CreateDynamicConfiguration)
    {
        KPH_DYN_CONFIGURATION configuration;

        RtlInitUnicodeString(&valueName, L"DynamicConfiguration");

        configuration.Version = KPH_DYN_CONFIGURATION_VERSION;
        configuration.NumberOfPackages = 1;

        if (NT_SUCCESS(KphInitializeDynamicPackage(&configuration.Packages[0])))
        {
            status = NtSetValueKey(parametersKeyHandle, &valueName, 0, REG_BINARY, &configuration, sizeof(KPH_DYN_CONFIGURATION));

            if (!NT_SUCCESS(status))
                goto SetValuesEnd;
        }
    }

    // Put more parameters here...

SetValuesEnd:
    if (!NT_SUCCESS(status))
    {
        // Delete the key if we created it.
        if (disposition == REG_CREATED_NEW_KEY)
            NtDeleteKey(parametersKeyHandle);
    }

    NtClose(parametersKeyHandle);

    return status;
}
Пример #9
0
NTSTATUS
LsapRegDeleteKey(IN HANDLE KeyHandle)
{
    return NtDeleteKey(KeyHandle);
}