Is there a way to enumerate the symbolic links from my kernel-mode driver?
/Magnus
NTSYSAPI NTSTATUS NTAPI ZwQuerySymbolicLinkObject( HANDLE Handle,
PUNICODE_STRING
LinkName, PUINT SymLinkLen );
Lukasz Foltyn
Magnus Wennergren <magnus.w...@axis.com> wrote in message
news:7kj3tr$ff...@news.ajou.ac.kr...
But he wanted to do it in kernel-mode...
What people usually do is just construct names in a loop and wait until
IoCreateDevice or IoCreateSymbolicLink succeeds. Neither of them should
crash the system just because given an existing name -- they return an
error status.
--
Walter Oney
http://www.oneysoft.com
Walter Oney wrote in message <376FB27D...@oneysoft.com>...
// FindAvailableDriveLetter()
NTSTATUS FindAvailableDriveLetter
(
PUCHAR DriveLetter
)
{
NTSTATUS ntStatus;
UNICODE_STRING ntUnicodeString;
CCHAR ntNameBuffer[MAXIMUM_FILENAME_LENGTH];
STRING ntNameString;
OBJECT_ATTRIBUTES attributes;
HANDLE directoryHandle;
HANDLE linkHandle = NULL;
ULONG i;
PAGED_CODE();
// Open the Win32 object name-space directory
RtlInitUnicodeString(&ntUnicodeString, (PWCHAR)L"\\DosDevices");
InitializeObjectAttributes
(
&attributes,
&ntUnicodeString,
OBJ_CASE_INSENSITIVE,
NULL,
NULL
);
ntStatus = ZwOpenDirectoryObject
(
&directoryHandle,
DIRECTORY_QUERY,
&attributes
);
if (!NT_SUCCESS(ntStatus))
{
RtlInitUnicodeString(&ntUnicodeString, (PWCHAR)L"\\??");
InitializeObjectAttributes
(
&attributes,
&ntUnicodeString,
OBJ_CASE_INSENSITIVE,
NULL,
NULL
);
ntStatus = ZwOpenDirectoryObject
(
&directoryHandle,
DIRECTORY_QUERY,
&attributes
);
if (!NT_SUCCESS(ntStatus))
{
goto FindAvailableDriveLetterExit;
}
}
// Open symbolic link object(s)
for (i = 2; i < 26; i++)
{
sprintf(ntNameBuffer, "%C:", i + 'A');
RtlInitString(&ntNameString, ntNameBuffer);
ntStatus = RtlAnsiStringToUnicodeString
(
&ntUnicodeString,
&ntNameString,
TRUE
);
if (!NT_SUCCESS(ntStatus))
break;
InitializeObjectAttributes
(
&attributes,
&ntUnicodeString,
OBJ_CASE_INSENSITIVE,
directoryHandle,
NULL
);
ntStatus = ZwOpenSymbolicLinkObject
(
&linkHandle,
SYMBOLIC_LINK_QUERY,
&attributes
);
if (!NT_SUCCESS(ntStatus))
{
*DriveLetter = (CHAR)((CHAR)i + (CHAR)'A');
ntStatus = STATUS_SUCCESS;
}
else
{
ZwClose(linkHandle);
ntStatus = STATUS_OBJECT_NAME_COLLISION;
}
RtlFreeUnicodeString(&ntUnicodeString);
if (NT_SUCCESS(ntStatus))
break;
}
ZwClose(directoryHandle);
FindAvailableDriveLetterExit:
return (ntStatus);