Beispiel #1
0
static int create_service(WCHAR *svc, WCHAR *name, WCHAR *image)
{
	WCHAR tmp[PATH_MAX];
	DWORD dw;
	wcscpy(svc, SVC_BASE);
	if (name) {
		wcscat(svc, name);
	} else {
		int p = wcslen(svc);
		for (WCHAR *i = name = image; *i; i++)
			if (*i == L'\\')
				name = i+1;
		while (*name && *name != '.')
			svc[p++] = *name++;
		svc[p] = 0;
	}

	if (!NT_SUCCESS(RtlCreateRegistryKey(0, svc)))
		return 0;
	RtlWriteRegistryValue(0, svc, L"ImagePath", REG_SZ, tmp, nt_path(tmp, image));
	dw = 1;
	RtlWriteRegistryValue(0,svc, L"Type", REG_DWORD, &dw, sizeof(dw));
	DBG("created service reg=%S, image=%S", svc, image);
	return 1;
}
Beispiel #2
0
/*
 * @implemented
 */
NTSTATUS
NTAPI
ChangeUniqueIdRoutine(IN PWSTR ValueName,
                      IN ULONG ValueType,
                      IN PVOID ValueData,
                      IN ULONG ValueLength,
                      IN PVOID Context,
                      IN PVOID EntryContext)
{
    PMOUNTDEV_UNIQUE_ID OldUniqueId = Context;
    PMOUNTDEV_UNIQUE_ID NewUniqueId = EntryContext;

    /* Validate parameters not to corrupt registry */
    if ((ValueType != REG_BINARY) ||
        (OldUniqueId->UniqueIdLength != ValueLength))
    {
        return STATUS_SUCCESS;
    }

    if (RtlCompareMemory(OldUniqueId->UniqueId, ValueData, ValueLength) == ValueLength)
    {
        /* Write new data */
        RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                              DatabasePath,
                              ValueName,
                              REG_BINARY,
                              NewUniqueId,
                              NewUniqueId->UniqueIdLength);
    }

    return STATUS_SUCCESS;
}
Beispiel #3
0
/**
 * @internal
 * @brief Saves the list of boot
 * execute programs to registry.
 * @return Zero for success,
 * negative value otherwise.
 */
static int save_boot_exec_list(struct cmd *list)
{
    struct cmd *c;
    int length = 1;
    wchar_t *commands, *p;
    NTSTATUS status;
    
    for(c = list; c; c = c->next){
        if(c->cmd[0]) length += (int)wcslen(c->cmd) + 1;
        if(c->next == list) break;
    }
    commands = winx_malloc(length * sizeof(wchar_t));
    memset(commands,0,length * sizeof(wchar_t));
    for(c = list, p = commands; c; c = c->next){
        if(c->cmd[0]){
            wcscpy(p,c->cmd);
            p += wcslen(c->cmd) + 1;
        }
        if(c->next == list) break;
    }
    
    status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
        L"Session Manager",L"BootExecute",REG_MULTI_SZ,
        commands,length * sizeof(wchar_t));
    winx_free(commands);
    if(!NT_SUCCESS(status)){
        strace(status,"cannot save list of boot execute commands");
        return (-1);
    }
    return 0;
}
Beispiel #4
0
/*
 * @implemented
 */
VOID
CreateNoDriveLetterEntry(IN PMOUNTDEV_UNIQUE_ID UniqueId)
{
    UUID Guid;
    PWCHAR String;
    UNICODE_STRING GuidString;

    /* Entry with no drive letter are made that way:
     * Instead of having a path with the letter,
     * you have GUID with the unique ID.
     */
    if (!NT_SUCCESS(ExUuidCreate(&Guid)))
    {
        return;
    }

    /* Convert to string */
    if (!NT_SUCCESS(RtlStringFromGUID(&Guid, &GuidString)))
    {
        return;
    }

    /* No letter entries must start with #, so allocate a proper string */
    String = AllocatePool(GuidString.Length + 2 * sizeof(WCHAR));
    if (!String)
    {
        ExFreePoolWithTag(GuidString.Buffer, 0);
        return;
    }

    /* Write the complete string */
    String[0] = L'#';
    RtlCopyMemory(String + 1, GuidString.Buffer, GuidString.Length);
    String[GuidString.Length / sizeof(WCHAR)] = UNICODE_NULL;

    /* Don't need that one anymore */
    ExFreePoolWithTag(GuidString.Buffer, 0);

    /* Write the entry */
    RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                          DatabasePath,
                          String,
                          REG_BINARY,
                          UniqueId->UniqueId,
                          UniqueId->UniqueIdLength);

    FreePool(String);

    return;
}
Beispiel #5
0
VOID
SoundSaveMixerSettings(
    PGLOBAL_DEVICE_INFO pGDI
)
{
    PLOCAL_MIXER_DATA   LocalMixerData;
    MIXER_REGISTRY_DATA RegData;

    int i;
    int SetIndex;

    LocalMixerData = &pGDI->LocalMixerData;

    RegData.MixerVersion     = DRIVER_VERSION;
    RegData.DSPVersion       = pGDI->Hw.DSPVersion;
    RegData.NumberOfControls = LocalMixerData->MaxSettableItems;

    /*
    **  Condense the data for storing in the registry
    */

    for (i = 0, SetIndex = 0; i < pGDI->LocalMixerData.NumberOfControls; i++) {
        if (pGDI->LocalMixerData.ControlInfo[i].SetIndex != MIXER_SET_INDEX_INVALID) {

            ASSERT(SetIndex == pGDI->LocalMixerData.ControlInfo[i].SetIndex);

            RegData.ControlData[SetIndex] = pGDI->LocalMixerData.ControlInfo[i].Data;
            SetIndex++;
        }
    }

    ASSERT(SetIndex == pGDI->LocalMixerData.MaxSettableItems);

    /*
    **  Write the data to save
    */

    RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                          pGDI->RegistryPathName,
                          SOUND_MIXER_SETTINGS_NAME,
                          REG_BINARY,
                          (PVOID)&RegData,
                          FIELD_OFFSET(MIXER_REGISTRY_DATA,
                                       ControlData[RegData.NumberOfControls]));
}
Beispiel #6
0
NTSTATUS
SoundWriteRegistryDWORD(
    IN   PCWSTR RegistryPath,
    IN   PCWSTR ValueName,
    IN   ULONG  Value
)
/*++

Routine Description :

    Write the given DWORD into the registry using the path and
    value name supplied by calling RtlWriteRegistryValue

Arguments :

    RegistryPath- path to registry key

    ValueName - name of value to write

    Value - value to store

Return Value :

    NTSTATUS code

--*/
{
    NTSTATUS Status;

    Status = RtlWriteRegistryValue(
                 RTL_REGISTRY_ABSOLUTE,
                 (LPWSTR)RegistryPath,
                 (LPWSTR)ValueName,
                 REG_DWORD,
                 &Value,
                 sizeof(Value));

    if (!NT_SUCCESS(Status)) {
        dprintf1(("Writing parameter %ls to registry failed status %8X",
                  ValueName, Status));
    }

    return Status;
}
Beispiel #7
0
VOID
SecMgrpSaveSecurityLevel( VOID )

/*++

Routine Description:

    This function is used to save the current security level
    from to the registry.

Arguments

    None.


Return Values:

    None.

--*/

{
    NTSTATUS
        NtStatus;


    NtStatus = RtlWriteRegistryValue( RTL_REGISTRY_CONTROL,
                                      SECMGRP_STATE_KEY,
                                      L"Current Level",
                                      REG_DWORD,
                                      (PVOID)&SecMgrpCurrentLevel,
                                      sizeof(DWORD)
                                      );
    if (!NT_SUCCESS(NtStatus)) {
        DbgPrint(("SecMgr: couldn't save security level\n"));
    }

    return;

}
Beispiel #8
0
VOID
SoundSaveMixerSettings(
    PGLOBAL_DEVICE_INFO pGDI
)
{
    PLOCAL_MIXER_DATA LocalMixerData;
    MIXER_CONTROL_DATA_ITEM SavedControlData[MAXSETTABLECONTROLS];
    int i;
    int SetIndex;

    LocalMixerData = &pGDI->LocalMixerData;

    /*
    **  Condense the data for storing in the registry
    */

    for (i = 0, SetIndex = 0; i < MAXCONTROLS; i++) {
        if (pGDI->LocalMixerData.ControlInfo[i].SetIndex != MIXER_SET_INDEX_INVALID) {

            ASSERT(SetIndex == pGDI->LocalMixerData.ControlInfo[i].SetIndex);

            SavedControlData[SetIndex] = pGDI->LocalMixerData.ControlInfo[i].Data;
            SetIndex++;
        }
    }

    /*
    **  Write the saved data
    */

    RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                          pGDI->RegistryPathName,
                          SOUND_MIXER_SETTINGS_NAME,
                          REG_BINARY,
                          (PVOID)SavedControlData,
                          sizeof(SavedControlData));
}
Beispiel #9
0
BOOLEAN
ProcessDisplayRegistry(HINF InfFile, PGENERIC_LIST List)
{
    PGENERIC_LIST_ENTRY Entry;
    INFCONTEXT Context;
    PWCHAR ServiceName;
    ULONG StartValue;
    NTSTATUS Status;
    WCHAR RegPath [255];
    PWCHAR Buffer;
    ULONG Width, Height, Bpp;

    DPRINT("ProcessDisplayRegistry() called\n");

    Entry = GetCurrentListEntry(List);
    if (Entry == NULL)
    {
        DPRINT("GetCurrentListEntry() failed\n");
        return FALSE;
    }

    if (!SetupFindFirstLineW(InfFile, L"Display", (WCHAR*)GetListEntryUserData(Entry), &Context))
    {
        DPRINT("SetupFindFirstLineW() failed\n");
        return FALSE;
    }

    /* Enable the right driver */
    if (!INF_GetDataField(&Context, 3, &ServiceName))
    {
        DPRINT("INF_GetDataField() failed\n");
        return FALSE;
    }

    ASSERT(wcslen(ServiceName) < 10);
    DPRINT("Service name: %S\n", ServiceName);

    StartValue = 1;
    Status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,
        ServiceName,
        L"Start",
        REG_DWORD,
        &StartValue,
        sizeof(ULONG));

    if (!NT_SUCCESS(Status))
    {
        DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
        return FALSE;
    }

    /* Set the resolution */
    swprintf(RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", ServiceName);

    if (!INF_GetDataField(&Context, 4, &Buffer))
    {
        DPRINT("INF_GetDataField() failed\n");
        return FALSE;
    }

    Width = wcstoul(Buffer, NULL, 10);
    Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
        RegPath,
        L"DefaultSettings.XResolution",
        REG_DWORD,
        &Width,
        sizeof(ULONG));
    if (!NT_SUCCESS(Status))
    {
        DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
        return FALSE;
    }

    if (!INF_GetDataField(&Context, 5, &Buffer))
    {
        DPRINT("INF_GetDataField() failed\n");
        return FALSE;
    }

    Height = wcstoul(Buffer, 0, 0);
    Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
        RegPath,
        L"DefaultSettings.YResolution",
        REG_DWORD,
        &Height,
        sizeof(ULONG));
    if (!NT_SUCCESS(Status))
    {
        DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
        return FALSE;
    }

    if (!INF_GetDataField(&Context, 6, &Buffer))
    {
        DPRINT("INF_GetDataField() failed\n");
        return FALSE;
    }

    Bpp = wcstoul(Buffer, 0, 0);
    Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
        RegPath,
        L"DefaultSettings.BitsPerPel",
        REG_DWORD,
        &Bpp,
        sizeof(ULONG));
    if (!NT_SUCCESS(Status))
    {
        DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
        return FALSE;
    }

    DPRINT("ProcessDisplayRegistry() done\n");

    return TRUE;
}
Beispiel #10
0
NTSTATUS NTAPI ClassSetDeviceParameter(
    IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
    IN PWSTR SubkeyName OPTIONAL,
    IN PWSTR ParameterName,
    IN ULONG ParameterValue)
{
    NTSTATUS                 status;
    HANDLE                   deviceParameterHandle;
    HANDLE                   deviceSubkeyHandle;

    PAGED_CODE();

    //
    // open the given parameter
    //

    status = IoOpenDeviceRegistryKey(FdoExtension->LowerPdo,
                                     PLUGPLAY_REGKEY_DEVICE,
                                     KEY_READ | KEY_WRITE,
                                     &deviceParameterHandle);

    if (NT_SUCCESS(status) && (SubkeyName != NULL)) {

        UNICODE_STRING subkeyName;
        OBJECT_ATTRIBUTES objectAttributes;

        RtlInitUnicodeString(&subkeyName, SubkeyName);
        InitializeObjectAttributes(&objectAttributes,
                                   &subkeyName,
                                   OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
                                   deviceParameterHandle,
                                   NULL);

        status = ZwCreateKey(&deviceSubkeyHandle,
                             KEY_READ | KEY_WRITE,
                             &objectAttributes,
                             0, NULL, 0, NULL);
        if (!NT_SUCCESS(status)) {
            ZwClose(deviceParameterHandle);
        }

    }

    if (NT_SUCCESS(status)) {

        status = RtlWriteRegistryValue(
            RTL_REGISTRY_HANDLE,
            (PWSTR) (SubkeyName ?
                     deviceSubkeyHandle :
                     deviceParameterHandle),
            ParameterName,
            REG_DWORD,
            &ParameterValue,
            sizeof(ULONG));

        //
        // close what we open
        //

        if (SubkeyName) {
            ZwClose(deviceSubkeyHandle);
        }

        ZwClose(deviceParameterHandle);
    }

    return status;

} // end ClassSetDeviceParameter()
Beispiel #11
0
VOID
IpxWriteDefaultAutoDetectType(
    IN PUNICODE_STRING RegistryPath,
    IN struct _ADAPTER * Adapter,
    IN ULONG FrameType
    )

/*++

Routine Description:

    This routine is called when we were unable to detect the default
    auto-detect type and instead found a different one. We update
    the "DefaultAutoDetectType" in the registry.

Arguments:

    RegistryPath - The name of IPX's node in the registry.

    Adapter - The adapter which we auto-detected on.

    FrameType - The new auto-detected value.

Return Value:

    None.

--*/

{
    PWSTR FullRegistryPath;
    PUCHAR CurRegistryPath;
    ULONG FullRegistryPathLength;
    ULONG AdapterNameLength;
    WCHAR NetConfigName[] = L"\\NetConfig";
    static PWCHAR FrameTypeNames[4] = { L"Ethernet II", L"802.3", L"802.2", L"SNAP" };
    PWCHAR CurAdapterName;
    NTSTATUS Status;


    //
    // We need to allocate a buffer which contains the registry path,
    // followed by "NetConfig", followed by the adapter name, and
    // then NULL-terminated.
    //

    CurAdapterName = &Adapter->AdapterName[(Adapter->AdapterNameLength/sizeof(WCHAR))-2];
    while (*CurAdapterName != L'\\') {
        --CurAdapterName;
    }
    CurAdapterName;
    AdapterNameLength = Adapter->AdapterNameLength - ((CurAdapterName - Adapter->AdapterName) * sizeof(WCHAR)) - sizeof(WCHAR);

    FullRegistryPathLength = RegistryPath->Length + sizeof(NetConfigName) + AdapterNameLength;

    FullRegistryPath = (PWSTR)IpxAllocateMemory (FullRegistryPathLength, MEMORY_CONFIG, "FullRegistryPath");
    if (FullRegistryPath == NULL) {
        IpxWriteResourceErrorLog(
            IpxDevice->DeviceObject,
            EVENT_TRANSPORT_RESOURCE_POOL,
            FullRegistryPathLength,
            MEMORY_CONFIG);
        return;
    }

    CurRegistryPath = (PUCHAR)FullRegistryPath;
    RtlCopyMemory (CurRegistryPath, RegistryPath->Buffer, RegistryPath->Length);
    CurRegistryPath += RegistryPath->Length;
    RtlCopyMemory (CurRegistryPath, NetConfigName, sizeof(NetConfigName) - sizeof(WCHAR));
    CurRegistryPath += (sizeof(NetConfigName) - sizeof(WCHAR));
    RtlCopyMemory (CurRegistryPath, CurAdapterName, AdapterNameLength);
    CurRegistryPath += AdapterNameLength;
    *(PWCHAR)CurRegistryPath = L'\0';

    Status = RtlWriteRegistryValue(
                 RTL_REGISTRY_ABSOLUTE,
                 FullRegistryPath,
                 L"DefaultAutoDetectType",
                 REG_DWORD,
                 &FrameType,
                 sizeof(ULONG));

    IpxFreeMemory (FullRegistryPath, FullRegistryPathLength, MEMORY_CONFIG, "FullRegistryPath");

    IpxWriteGeneralErrorLog(
        IpxDevice->DeviceObject,
        EVENT_IPX_NEW_DEFAULT_TYPE,
        888,
        STATUS_SUCCESS,
        FrameTypeNames[FrameType],
        0,
        NULL);

}   /* IpxWriteDefaultAutoDetectType */
Beispiel #12
0
NTSTATUS
FmCreateDosDevicesSymbolicLink(
                              WDFDEVICE       Device,
                              PFM_DEVICE_DATA FmDeviceData
                              )
{
    NTSTATUS        status;
    UNICODE_STRING  comPort;
    UNICODE_STRING  pdoName;
    UNICODE_STRING  symbolicLink;
    WDFKEY          hKey = NULL;
    DECLARE_CONST_UNICODE_STRING(valueName, L"PortName");
    WDFSTRING       string = NULL;
    WDFMEMORY       memory;
    WDF_OBJECT_ATTRIBUTES  memoryAttributes;
    size_t          bufferLength;


    PAGED_CODE();

    symbolicLink.Buffer = NULL;

    //
    // Open the device registry and read the "PortName" value written by the
    // class installer.
    //
    status = WdfDeviceOpenRegistryKey(Device,
                                      PLUGPLAY_REGKEY_DEVICE,
                                      STANDARD_RIGHTS_ALL,
                                      NULL, // PWDF_OBJECT_ATTRIBUTES
                                      &hKey);

    if (!NT_SUCCESS (status)) {
        goto Error;
    }
    status = WdfStringCreate(
                            NULL,
                            WDF_NO_OBJECT_ATTRIBUTES ,
                            &string
                            );

    if (!NT_SUCCESS(status)) {
        goto Error;
    }

    //
    // Retrieve the value of ValueName from registry
    //
    status = WdfRegistryQueryString(
                                   hKey,
                                   &valueName,
                                   string
                                   );


    if (!NT_SUCCESS (status)) {
        goto Error;
    }

    //
    // Retrieve the UNICODE_STRING from string object
    //
    WdfStringGetUnicodeString(
                             string,
                             &comPort
                             );

    WdfRegistryClose(hKey);
    hKey = NULL;

    symbolicLink.Length=0;
    symbolicLink.MaximumLength = sizeof(OBJECT_DIRECTORY) + comPort.MaximumLength;

    symbolicLink.Buffer = ExAllocatePoolWithTag(PagedPool,
                                                symbolicLink.MaximumLength + sizeof(WCHAR),
                                                'wkaF');

    if (symbolicLink.Buffer == NULL) {
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto Error;
    }
    RtlZeroMemory(symbolicLink.Buffer, symbolicLink.MaximumLength);
    RtlAppendUnicodeToString(&symbolicLink, OBJECT_DIRECTORY);
    RtlAppendUnicodeStringToString(&symbolicLink, &comPort);
    //
    // This DDI will get the underlying PDO name and create a symbolic to that
    // because our FDO doesn't have a name.
    //
    status = WdfDeviceCreateSymbolicLink(Device,
                                         &symbolicLink);

    if (!NT_SUCCESS(status)) {
        goto Error;
    }

    WDF_OBJECT_ATTRIBUTES_INIT(&memoryAttributes);
    memoryAttributes.ParentObject = Device;

    status = WdfDeviceAllocAndQueryProperty(Device,
                                            DevicePropertyPhysicalDeviceObjectName,
                                            PagedPool,
                                            &memoryAttributes,
                                            &memory);
    if (!NT_SUCCESS(status)) {
        //
        // We expect a zero length buffer. Anything else is fatal.
        //
        goto Error;
    }

    pdoName.Buffer = WdfMemoryGetBuffer(memory, &bufferLength);

    if (pdoName.Buffer == NULL) {
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto Error;

    }
    pdoName.MaximumLength = (USHORT) bufferLength;
    pdoName.Length = (USHORT) bufferLength - sizeof(UNICODE_NULL);

    status = RtlWriteRegistryValue(RTL_REGISTRY_DEVICEMAP,
                                   L"SERIALCOMM",
                                   pdoName.Buffer,
                                   REG_SZ,
                                   comPort.Buffer,
                                   comPort.Length);

    if (!NT_SUCCESS(status)) {
        goto Error;
    }
    FmDeviceData->Flags |= REG_VALUE_CREATED_FLAG;
    //
    // Store it so it can be deleted later.
    //

    FmDeviceData->PdoName = pdoName;

    Error:

    if (symbolicLink.Buffer != NULL) {
        ExFreePool(symbolicLink.Buffer);
    }

    if (hKey != NULL) {
        WdfRegistryClose(hKey);
    }
    if (string != NULL) {
        WdfObjectDelete(string);
    }

    return status;
}
Beispiel #13
0
BOOLEAN
SecMgrpSetFontLoadingSetting(
    HWND        hwnd,
    BOOLEAN     Secure
    )
/*++

Routine Description:

    This function is used to secure or unsecure Font Loading.

    If it is to be secured, for the time being we set a hardcoded
    list of trusted directories in the Font-Loading path.  These
    directories are:

            %WinDir%\System


Arguments

    hwnd - The caller's window.  This is used if we need to put
        up an error popup.

    Secure - A boolean indicating whether font-loading should be
        secured (TRUE) or left unsecured (FALSE).

        

Return Values:

    TRUE - The value has been successfully set

    FALSE - we ran into trouble setting the new setting.

        If an error is encountered, then an error popup will be
        displayed by this routine.

--*/
{
    NTSTATUS
        NtStatus;

    WCHAR
        SecuredPath[] = L"%WinDir%\\System";

    PWSTR
        PathToAssign;

    ULONG
        PathLength;

    //
    // Set the new value
    //

    if ( Secure ) {
        PathToAssign = SecuredPath;
        PathLength = sizeof(SecuredPath);
    } else {
        PathToAssign = NULL;
        PathLength = 0;
    }
    NtStatus = RtlWriteRegistryValue( RTL_REGISTRY_WINDOWS_NT, // RelativeTo
                                      L"FontPath",          // Path
                                      NULL,                 // ValueName
                                      REG_SZ,               // ValueType
                                      PathToAssign,         //ValueData
                                      PathLength            // ValueLength
                                      );

    if (!NT_SUCCESS(NtStatus)) {

        //
        // Put up a pop-up
        //

        SecMgrpPopUp( hwnd, SECMGRP_STRING_ERROR_SETTING_FONT_PATH );

        return(FALSE);

    }

    return(TRUE);
}
Beispiel #14
0
/*
 * @implemented
 */
NTSTATUS
MountMgrCreatePointWorker(IN PDEVICE_EXTENSION DeviceExtension,
                          IN PUNICODE_STRING SymbolicLinkName,
                          IN PUNICODE_STRING DeviceName)
{
    NTSTATUS Status;
    PLIST_ENTRY DeviceEntry;
    PMOUNTDEV_UNIQUE_ID UniqueId;
    PSYMLINK_INFORMATION SymlinkInformation;
    UNICODE_STRING SymLink, TargetDeviceName;
    PDEVICE_INFORMATION DeviceInformation = NULL, DeviceInfo;

    /* Get device name */
    Status = QueryDeviceInformation(SymbolicLinkName,
                                    &TargetDeviceName,
                                    NULL, NULL, NULL,
                                    NULL, NULL, NULL);
    if (!NT_SUCCESS(Status))
    {
        return Status;
    }

    /* First of all, try to find device */
    for (DeviceEntry = DeviceExtension->DeviceListHead.Flink;
         DeviceEntry != &(DeviceExtension->DeviceListHead);
         DeviceEntry = DeviceEntry->Flink)
    {
        DeviceInformation = CONTAINING_RECORD(DeviceEntry, DEVICE_INFORMATION, DeviceListEntry);

        if (RtlCompareUnicodeString(&TargetDeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
        {
            break;
        }
    }

    /* Copy symbolic link name and null terminate it */
    SymLink.Buffer = AllocatePool(SymbolicLinkName->Length + sizeof(UNICODE_NULL));
    if (!SymLink.Buffer)
    {
        FreePool(TargetDeviceName.Buffer);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    RtlCopyMemory(SymLink.Buffer, SymbolicLinkName->Buffer, SymbolicLinkName->Length);
    SymLink.Buffer[SymbolicLinkName->Length / sizeof(WCHAR)] = UNICODE_NULL;
    SymLink.Length = SymbolicLinkName->Length;
    SymLink.MaximumLength = SymbolicLinkName->Length + sizeof(UNICODE_NULL);

    /* If we didn't find device */
    if (DeviceEntry == &(DeviceExtension->DeviceListHead))
    {
        /* Then, try with unique ID */
        Status = QueryDeviceInformation(SymbolicLinkName,
                                        NULL, &UniqueId,
                                        NULL, NULL, NULL,
                                        NULL, NULL);
        if (!NT_SUCCESS(Status))
        {
            FreePool(TargetDeviceName.Buffer);
            FreePool(SymLink.Buffer);
            return Status;
        }

        /* Create a link to the device */
        Status = GlobalCreateSymbolicLink(&SymLink, &TargetDeviceName);
        if (!NT_SUCCESS(Status))
        {
            FreePool(UniqueId);
            FreePool(TargetDeviceName.Buffer);
            FreePool(SymLink.Buffer);
            return Status;
        }

        /* If caller provided driver letter, delete it */
        if (IsDriveLetter(&SymLink))
        {
            DeleteRegistryDriveLetter(UniqueId);
        }

        /* Device will be identified with its unique ID */
        Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                                       DatabasePath,
                                       SymLink.Buffer,
                                       REG_BINARY,
                                       UniqueId->UniqueId,
                                       UniqueId->UniqueIdLength);

        FreePool(UniqueId);
        FreePool(TargetDeviceName.Buffer);
        FreePool(SymLink.Buffer);
        return Status;
    }

    /* If call provided a driver letter whereas device already has one
     * fail, this is not doable
     */
    if (IsDriveLetter(&SymLink) && HasDriveLetter(DeviceInformation))
    {
        FreePool(TargetDeviceName.Buffer);
        FreePool(SymLink.Buffer);
        return STATUS_INVALID_PARAMETER;
    }

    /* Now, create a link */
    Status = GlobalCreateSymbolicLink(&SymLink, &TargetDeviceName);
    FreePool(TargetDeviceName.Buffer);
    if (!NT_SUCCESS(Status))
    {
        FreePool(SymLink.Buffer);
        return Status;
    }

    /* Associate Unique ID <-> symbolic name */
    UniqueId = DeviceInformation->UniqueId;
    Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                                   DatabasePath,
                                   SymLink.Buffer,
                                   REG_BINARY,
                                   UniqueId->UniqueId,
                                   UniqueId->UniqueIdLength);
    if (!NT_SUCCESS(Status))
    {
        GlobalDeleteSymbolicLink(&SymLink);
        FreePool(SymLink.Buffer);
        return Status;
    }

    /* Now, prepare to save the link with the device */
    SymlinkInformation = AllocatePool(sizeof(SYMLINK_INFORMATION));
    if (!SymlinkInformation)
    {
        Status = STATUS_INSUFFICIENT_RESOURCES;
        GlobalDeleteSymbolicLink(&SymLink);
        FreePool(SymLink.Buffer);
        return Status;
    }

    SymlinkInformation->Name.Length = SymLink.Length;
    SymlinkInformation->Name.MaximumLength = SymLink.Length + sizeof(UNICODE_NULL);
    SymlinkInformation->Name.Buffer = AllocatePool(SymlinkInformation->Name.MaximumLength);
    if (!SymlinkInformation->Name.Buffer)
    {
        Status = STATUS_INSUFFICIENT_RESOURCES;
        FreePool(SymlinkInformation);
        GlobalDeleteSymbolicLink(&SymLink);
        FreePool(SymLink.Buffer);
        return Status;
    }

    /* Save the link and mark it online */
    RtlCopyMemory(SymlinkInformation->Name.Buffer, SymLink.Buffer, SymlinkInformation->Name.Length);
    SymlinkInformation->Name.Buffer[SymlinkInformation->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
    SymlinkInformation->Online = TRUE;
    InsertTailList(&DeviceInformation->SymbolicLinksListHead, &SymlinkInformation->SymbolicLinksListEntry);
    SendLinkCreated(&(SymlinkInformation->Name));

    /* If we have a drive letter */
    if (IsDriveLetter(&SymLink))
    {
        /* Then, delete the no drive letter entry */
        DeleteNoDriveLetterEntry(UniqueId);

        /* And post online notification if asked */
        if (!DeviceInformation->SkipNotifications)
        {
            PostOnlineNotification(DeviceExtension, &DeviceInformation->SymbolicName);
        }
    }

    /* If that's a volume with automatic drive letter, it's now time to resync databases */
    if (MOUNTMGR_IS_VOLUME_NAME(&SymLink) && DeviceExtension->AutomaticDriveLetter)
    {
        for (DeviceEntry = DeviceExtension->DeviceListHead.Flink;
             DeviceEntry != &(DeviceExtension->DeviceListHead);
             DeviceEntry = DeviceEntry->Flink)
        {
            DeviceInfo = CONTAINING_RECORD(DeviceEntry, DEVICE_INFORMATION, DeviceListEntry);

            /* If there's one, ofc! */
            if (!DeviceInfo->NoDatabase)
            {
                ReconcileThisDatabaseWithMaster(DeviceExtension, DeviceInfo);
            }
        }
    }

    /* Notify & quit */
    FreePool(SymLink.Buffer);
    MountMgrNotify(DeviceExtension);

    if (!DeviceInformation->Volume)
    {
        MountMgrNotifyNameChange(DeviceExtension, DeviceName, FALSE);
    }

    return Status;
}
Beispiel #15
0
NTSTATUS DigiRegisterAtlasName( IN PUNICODE_STRING DeviceName,
                                IN PUNICODE_STRING ValueName,
                                IN PUNICODE_STRING ValueEntry )
/*++

Routine Description:

    This routine will register the passed in value name and its associated
    value for Atlas to find.  In addition, we will create a symbolic
    link to a name which is accessible for Atlas to open and exchange
    information.

Arguments:

   DeviceName - pointer to unicode string to use when creating a
                symbolic link.  It is assumed this device name is all ready
                created and ready to have symbolic links created.

   ValueName - pointer to unicode string to be used as the registry
               value name.

   Value - pointer to unicode string to be used as the value associated
           with ValueName.

Return Value:

    - STATUS_SUCCESS if successful

    - Error indicating problem

--*/
{
#define DEFAULT_DIGI_ATLAS_DEVICEMAP L"DigiAtlas"
   NTSTATUS Status;
   UNICODE_STRING LinkName;
   WCHAR LinkNameBuffer[32];

   //
   // First, we create the required link symbolic name from the passed
   // in value name.
   //
   RtlInitUnicodeString( &LinkName, NULL );
   LinkName.Buffer = &LinkNameBuffer[0];
   LinkName.MaximumLength = sizeof(LinkNameBuffer);
   LinkName.Length = 0;

   RtlAppendUnicodeToString( &LinkName, L"\\DosDevices\\" );
   RtlAppendUnicodeStringToString( &LinkName, ValueEntry );

   //
   // Create the symbolic link first.
   //

   Status = IoCreateSymbolicLink( &LinkName,
                                  DeviceName );

   if( NT_ERROR(Status) )
      return( Status );

   //
   // We need to add a \\.\ to the beginning of ValueEntry.
   //
   LinkName.Length = 0;
   RtlZeroMemory( LinkName.Buffer, LinkName.MaximumLength );
   RtlAppendUnicodeToString( &LinkName, L"\\\\.\\" );
   RtlAppendUnicodeStringToString( &LinkName, ValueEntry );

   Status = RtlWriteRegistryValue( RTL_REGISTRY_DEVICEMAP,
                                   DEFAULT_DIGI_ATLAS_DEVICEMAP,
                                   ValueName->Buffer,
                                   REG_SZ,
                                   LinkName.Buffer,
                                   LinkName.Length + sizeof(WCHAR) );

   return( Status );

}  // end DigiRegisterAtlasName
Beispiel #16
0
BOOLEAN ShowPort(IN PC0C_FDOPORT_EXTENSION pDevExt)
{
    BOOLEAN res;
    NTSTATUS status;

    if ((pDevExt->shown & C0C_SHOW_SHOWN) != 0)
        return TRUE;

    res = TRUE;

    if (!pDevExt->pIoPortLocal->isComClass &&
            (pDevExt->shown & C0C_SHOW_PORTNAME) == 0 &&
            (pDevExt->hide & C0C_SHOW_PORTNAME) == 0)
    {
        HANDLE hKey;

        status = IoOpenDeviceRegistryKey(pDevExt->pIoPortLocal->pPhDevObj,
                                         PLUGPLAY_REGKEY_DEVICE,
                                         STANDARD_RIGHTS_WRITE,
                                         &hKey);

        if (NT_SUCCESS(status)) {
            UNICODE_STRING keyName;

            RtlInitUnicodeString(&keyName, L"PortName");

            status = ZwSetValueKey(hKey,
                                   &keyName,
                                   0,
                                   REG_SZ,
                                   pDevExt->portName,
                                   (ULONG)((wcslen(pDevExt->portName) + 1) * sizeof(WCHAR)));

            if (NT_SUCCESS(status)) {
                pDevExt->shown |= C0C_SHOW_PORTNAME;
                Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown PORTNAME");
            } else {
                res = FALSE;
                Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort ZwSetValueKey(PortName) FAIL");
            }

            ZwClose(hKey);
        } else {
            res = FALSE;
            Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoOpenDeviceRegistryKey(PLUGPLAY_REGKEY_DEVICE) FAIL");
        }
    }

    if (pDevExt->ntDeviceName.Buffer) {
        if (pDevExt->win32DeviceName.Buffer &&
                (pDevExt->shown & C0C_SHOW_SYMLINK) == 0 &&
                (pDevExt->hide & C0C_SHOW_SYMLINK) == 0)
        {
            status = IoCreateSymbolicLink(&pDevExt->win32DeviceName, &pDevExt->ntDeviceName);

            if (NT_SUCCESS(status)) {
                pDevExt->shown |= C0C_SHOW_SYMLINK;
                Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown SYMLINK");
            } else {
                res = FALSE;
                Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoCreateSymbolicLink FAIL");
            }
        }

        if ((pDevExt->shown & C0C_SHOW_SYMLINK) != 0 &&
                (pDevExt->shown & C0C_SHOW_DEVICEMAP) == 0 &&
                (pDevExt->hide & C0C_SHOW_DEVICEMAP) == 0)
        {
            status = RtlWriteRegistryValue(RTL_REGISTRY_DEVICEMAP, C0C_SERIAL_DEVICEMAP,
                                           pDevExt->ntDeviceName.Buffer, REG_SZ,
                                           pDevExt->portName,
                                           (ULONG)((wcslen(pDevExt->portName) + 1) * sizeof(WCHAR)));

            if (NT_SUCCESS(status)) {
                pDevExt->shown |= C0C_SHOW_DEVICEMAP;
                Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown DEVICEMAP");
            } else {
                res = FALSE;
                Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort RtlWriteRegistryValue " C0C_SERIAL_DEVICEMAP L" FAIL");
            }
        }
    }

    if (pDevExt->symbolicLinkName.Buffer &&
            (pDevExt->shown & C0C_SHOW_INTERFACE) == 0 &&
            (pDevExt->hide & C0C_SHOW_INTERFACE) == 0)
    {
        status = IoSetDeviceInterfaceState(&pDevExt->symbolicLinkName, TRUE);

        if (NT_SUCCESS(status)) {
            pDevExt->shown |= C0C_SHOW_INTERFACE;
            Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown INTERFACE");
        } else {
            res = FALSE;
            Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoSetDeviceInterfaceState FAIL");
        }
    }

    if ((pDevExt->shown & C0C_SHOW_WMIREG) == 0 && (pDevExt->hide & C0C_SHOW_WMIREG) == 0) {
        status = IoWMIRegistrationControl(pDevExt->pDevObj, WMIREG_ACTION_REGISTER);

        if (NT_SUCCESS(status)) {
            pDevExt->shown |= C0C_SHOW_WMIREG;
            Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown WMIREG");
        } else {
            res = FALSE;
            Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoWMIRegistrationControl FAIL");
        }
    }

    pDevExt->shown |= C0C_SHOW_SHOWN;

    Trace00((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort - ", res ? L"OK" : L"FAIL");

    return res;
}
Beispiel #17
0
/*
 * @implemented
 */
NTSTATUS
QuerySymbolicLinkNamesFromStorage(IN PDEVICE_EXTENSION DeviceExtension,
                                  IN PDEVICE_INFORMATION DeviceInformation,
                                  IN PUNICODE_STRING SuggestedLinkName,
                                  IN BOOLEAN UseOnlyIfThereAreNoOtherLinks,
                                  OUT PUNICODE_STRING * SymLinks,
                                  OUT PULONG SymLinkCount,
                                  IN BOOLEAN HasGuid,
                                  IN LPGUID Guid)
{
    NTSTATUS Status;
    BOOLEAN WriteNew;
    RTL_QUERY_REGISTRY_TABLE QueryTable[2];

    UNREFERENCED_PARAMETER(DeviceExtension);

    /* First of all, count links */
    RtlZeroMemory(QueryTable, sizeof(QueryTable));
    QueryTable[0].QueryRoutine = SymbolicLinkNamesFromUniqueIdCount;
    QueryTable[0].EntryContext = SymLinkCount;
    *SymLinkCount = 0;

    Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
                                    DatabasePath,
                                    QueryTable,
                                    DeviceInformation->UniqueId,
                                    NULL);
    if (!NT_SUCCESS(Status))
    {
        *SymLinkCount = 0;
    }

    /* Check if we have to write a new one first */
    if (SuggestedLinkName && !IsDriveLetter(SuggestedLinkName) &&
        UseOnlyIfThereAreNoOtherLinks && *SymLinkCount == 0)
    {
        WriteNew = TRUE;
    }
    else
    {
        WriteNew = FALSE;
    }

    /* If has GUID, it makes one more link */
    if (HasGuid)
    {
        (*SymLinkCount)++;
    }

    if (WriteNew)
    {
        /* Write link */
        RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
                              DatabasePath,
                              SuggestedLinkName->Buffer,
                              REG_BINARY,
                              DeviceInformation->UniqueId->UniqueId,
                              DeviceInformation->UniqueId->UniqueIdLength);

        /* And recount all the needed links */
        RtlZeroMemory(QueryTable, sizeof(QueryTable));
        QueryTable[0].QueryRoutine = SymbolicLinkNamesFromUniqueIdCount;
        QueryTable[0].EntryContext = SymLinkCount;
        *SymLinkCount = 0;

        Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
                                        DatabasePath,
                                        QueryTable,
                                        DeviceInformation->UniqueId,
                                        NULL);
        if (!NT_SUCCESS(Status))
        {
            return STATUS_NOT_FOUND;
        }
    }

    /* Not links found? */
    if (!*SymLinkCount)
    {
        return STATUS_NOT_FOUND;
    }

    /* Allocate a buffer big enough to hold symlinks (table of unicode strings) */
    *SymLinks = AllocatePool(*SymLinkCount * sizeof(UNICODE_STRING));
    if (!*SymLinks)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* Prepare to query links */
    RtlZeroMemory(*SymLinks, *SymLinkCount * sizeof(UNICODE_STRING));
    RtlZeroMemory(QueryTable, sizeof(QueryTable));
    QueryTable[0].QueryRoutine = SymbolicLinkNamesFromUniqueIdQuery;

    /* No GUID? Keep it that way */
    if (!HasGuid)
    {
        QueryTable[0].EntryContext = *SymLinks;
    }
    /* Otherwise, first create volume name */
    else
    {
        Status = CreateNewVolumeName(SymLinks[0], Guid);
        if (!NT_SUCCESS(Status))
        {
            FreePool(*SymLinks);
            return Status;
        }

        /* Skip first link (ours) */
        QueryTable[0].EntryContext = *SymLinks + 1;
    }

    /* Now, query */
    RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
                           DatabasePath,
                           QueryTable,
                           DeviceInformation->UniqueId,
                           NULL);

    return STATUS_SUCCESS;
}
Beispiel #18
0
VOID
NdisWriteConfiguration(
	OUT PNDIS_STATUS				Status,
	IN NDIS_HANDLE					ConfigurationHandle,
	IN PNDIS_STRING					Keyword,
	PNDIS_CONFIGURATION_PARAMETER	ParameterValue
	)
/*++

Routine Description:

	This routine is used to write a parameter to the configuration database.

Arguments:

	Status - Returns the status of the request.

	ConfigurationHandle - Handle passed to the driver's AddAdapter routine.

	Keyword - The keyword to set.

	ParameterValue - Specifies the new value for this keyword.

Return Value:

	None.

--*/
{
	//
	// Status of our requests
	//
	NTSTATUS	RegistryStatus;

	//
	// The ConfigurationHandle is really a pointer to a registry query table.
	//
	PNDIS_CONFIGURATION_HANDLE NdisConfigHandle = (PNDIS_CONFIGURATION_HANDLE)ConfigurationHandle;

	//
	// Holds a null-terminated version of the keyword.
	//
	PWSTR		KeywordBuffer;

	//
	// Variables describing the parameter value.
	//
	PVOID		ValueData;
	ULONG		ValueLength;
	ULONG		ValueType;

	ASSERT (KeGetCurrentIrql() < DISPATCH_LEVEL);

	*Status == NDIS_STATUS_SUCCESS;
	do
	{
		//
		// Get the value data.
		//
		switch (ParameterValue->ParameterType)
		{
		  case NdisParameterInteger:
			ValueData = &ParameterValue->ParameterData.IntegerData;
			ValueLength = sizeof(ParameterValue->ParameterData.IntegerData);
			ValueType = REG_DWORD;
			break;

		  case NdisParameterString:
			ValueData = ParameterValue->ParameterData.StringData.Buffer;
			ValueLength = ParameterValue->ParameterData.StringData.Length;
			ValueType = REG_SZ;
			break;

		  case NdisParameterMultiString:
			ValueData = ParameterValue->ParameterData.StringData.Buffer;
			ValueLength = ParameterValue->ParameterData.StringData.Length;
			ValueType = REG_MULTI_SZ;
			break;

		  case NdisParameterBinary:
			ValueData = ParameterValue->ParameterData.BinaryData.Buffer;
			ValueLength = ParameterValue->ParameterData.BinaryData.Length;
			ValueType = REG_BINARY;
			break;

		  default:
			*Status = NDIS_STATUS_NOT_SUPPORTED;
			break;
		}

		if (*Status != NDIS_STATUS_SUCCESS)
			break;

		KeywordBuffer = Keyword->Buffer;
		if (Keyword->MaximumLength <= (Keyword->MaximumLength + sizeof(WCHAR)))
		{
			KeywordBuffer = (PWSTR)ALLOC_FROM_POOL(Keyword->Length + sizeof(WCHAR), NDIS_TAG_DEFAULT);
			if (KeywordBuffer == NULL)
			{
				*Status = NDIS_STATUS_RESOURCES;
				break;
			}
			CopyMemory(KeywordBuffer, Keyword->Buffer, Keyword->Length);
		}
		*(PWCHAR)(((PUCHAR)KeywordBuffer)+Keyword->Length) = (WCHAR)L'\0';

		//
		// Write the value to the registry.
		//
		RegistryStatus = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,
											   NdisConfigHandle->KeyQueryTable[3].Name,
											   KeywordBuffer,
											   ValueType,
											   ValueData,
											   ValueLength);

		if (KeywordBuffer != Keyword->Buffer)
		{
			FREE_POOL(KeywordBuffer);	// no longer needed
		}

		if (!NT_SUCCESS(RegistryStatus))
		{
			*Status = NDIS_STATUS_FAILURE;
		}
	} while (FALSE);
}