smbmrxnp.c
来自「winddk src目录下的文件系统驱动源码压缩!」· C语言 代码 · 共 1,729 行 · 第 1/4 页
C
1,729 行
}
break;
case RESOURCE_CONTEXT:
default:
Status = WN_NOT_SUPPORTED;
break;
}
DbgP((TEXT("NPOpenEnum returning Status %lx\n"),Status));
return(Status);
}
DWORD APIENTRY
NPEnumResource(
HANDLE hEnum,
LPDWORD lpcCount,
LPVOID lpBuffer,
LPDWORD lpBufferSize)
/*++
Routine Description:
This routine uses the handle obtained by a call to NPOpenEnum for
enuerating the connected shares
Arguments:
hEnum - the enumeration handle
lpcCount - the number of resources returned
lpBuffer - the buffere for passing back the entries
lpBufferSize - the size of the buffer
Return Value:
WN_SUCCESS if successful, otherwise the appropriate error
WN_NO_MORE_ENTRIES - if the enumeration has exhausted the entries
WN_MORE_DATA - if nmore data is available
Notes:
The sample only supports the notion of enumerating connected shares
The handle passed back is merely the index of the last entry returned
--*/
{
DWORD Status = WN_SUCCESS;
LPNETRESOURCEW pBufferResource;
DWORD StringOffset;
DWORD AvailableBufferSize;
HANDLE hMutex, hMemory;
PSMBMRXNP_ENUMERATION_HANDLE pEnumHandle;
PSMBMRXNP_SHARED_MEMORY pSharedMemory;
DbgP((TEXT("NPEnumResource\n")));
DbgP((TEXT("NPEnumResource Count Requested %d\n"),*lpcCount));
AvailableBufferSize = *lpBufferSize;
StringOffset = *lpBufferSize;
pBufferResource = (LPNETRESOURCEW)lpBuffer;
pEnumHandle = (PSMBMRXNP_ENUMERATION_HANDLE)hEnum;
*lpcCount = 0;
if (pEnumHandle->LastIndex >= SMBMRXNP_MAX_DEVICES)
{
return WN_NO_MORE_ENTRIES;
}
Status = OpenSharedMemory(
&hMutex,
&hMemory,
(PVOID)&pSharedMemory);
if (Status == WN_SUCCESS)
{
INT Index;
PSMBMRXNP_NETRESOURCE pNetResource;
DbgP((TEXT("NPEnumResource: Highest Index %d Number Of resources %d\n"),
pSharedMemory->HighestIndexInUse,pSharedMemory->NumberOfResourcesInUse));
for (Index = pEnumHandle->LastIndex; Index <= pSharedMemory->HighestIndexInUse; Index++) {
pNetResource = &pSharedMemory->NetResources[Index];
DbgP((TEXT("NPEnumResource: Examining Index %d\n"),Index));
if (pNetResource->InUse)
{
DWORD ResourceSize;
ResourceSize = sizeof(NETRESOURCE) +
pNetResource->LocalNameLength + sizeof(WCHAR) +
pNetResource->RemoteNameLength + sizeof(WCHAR) +
SmbMrxProviderName.Length + sizeof(WCHAR);
if (AvailableBufferSize >= ResourceSize)
{
*lpcCount = *lpcCount + 1;
AvailableBufferSize -= ResourceSize;
pBufferResource->dwScope = RESOURCE_CONNECTED;
pBufferResource->dwType = pNetResource->dwType;
pBufferResource->dwDisplayType = pNetResource->dwDisplayType;
pBufferResource->dwUsage = pNetResource->dwUsage;
DbgP((TEXT("NPEnumResource: Copying local name Index %d\n"),Index));
// set up the strings in the resource
StringOffset -= (pNetResource->LocalNameLength + sizeof(WCHAR));
pBufferResource->lpLocalName = (PWCHAR)((PBYTE)lpBuffer + StringOffset);
CopyMemory(pBufferResource->lpLocalName,
pNetResource->LocalName,
pNetResource->LocalNameLength);
pBufferResource->lpLocalName[
pNetResource->LocalNameLength/sizeof(WCHAR)] = L'\0';
DbgP((TEXT("NPEnumResource: Copying remote name Index %d\n"),Index));
StringOffset -= (pNetResource->RemoteNameLength + sizeof(WCHAR));
pBufferResource->lpRemoteName = (PWCHAR)((PBYTE)lpBuffer + StringOffset);
CopyMemory(pBufferResource->lpRemoteName,
pNetResource->RemoteName,
pNetResource->RemoteNameLength);
pBufferResource->lpRemoteName[
pNetResource->RemoteNameLength/sizeof(WCHAR)] = L'\0';
DbgP((TEXT("NPEnumResource: Copying provider name Index %d\n"),Index));
StringOffset -= (SmbMrxProviderName.Length + sizeof(WCHAR));
pBufferResource->lpProvider = (PWCHAR)((PBYTE)lpBuffer + StringOffset);
CopyMemory(pBufferResource->lpProvider,
SmbMrxProviderName.Buffer,
SmbMrxProviderName.Length);
pBufferResource->lpProvider[
SmbMrxProviderName.Length/sizeof(WCHAR)] = L'\0';
pBufferResource->lpComment = NULL;
pBufferResource++;
}
else
{
DbgP((TEXT("NPEnumResource: Buffer Overflow Index %d\n"),Index));
Status = WN_MORE_DATA;
break;
}
}
}
pEnumHandle->LastIndex = Index;
if ((Status == WN_SUCCESS) &&
(pEnumHandle->LastIndex > pSharedMemory->HighestIndexInUse) &&
(*lpcCount == 0))
{
Status = WN_NO_MORE_ENTRIES;
}
CloseSharedMemory(
&hMutex,
&hMemory,
(PVOID)&pSharedMemory);
}
DbgP((TEXT("NPEnumResource returning Count %d\n"),*lpcCount));
DbgP((TEXT("NPEnumResource returning Status %lx\n"),Status));
return Status;
}
DWORD APIENTRY
NPCloseEnum(
HANDLE hEnum )
/*++
Routine Description:
This routine closes the handle for enumeration of resources.
Arguments:
hEnum - the enumeration handle
Return Value:
WN_SUCCESS if successful, otherwise the appropriate error
Notes:
The sample only supports the notion of enumerating connected shares
--*/
{
DbgP((TEXT("NPCloseEnum\n")));
LocalFree(hEnum);
return WN_SUCCESS;
}
ULONG
SendToMiniRdr(
IN ULONG IoctlCode,
IN PVOID InputDataBuf,
IN ULONG InputDataLen,
IN PVOID OutputDataBuf,
IN PULONG pOutputDataLen)
/*++
Routine Description:
This routine sends a device ioctl to the Mini Rdr.
Arguments:
IoctlCode - Function code for the Mini Rdr driver
InputDataBuf - Input buffer pointer
InputDataLen - Lenth of the input buffer
OutputDataBuf - Output buffer pointer
pOutputDataLen - Pointer to the length of the output buffer
Return Value:
WN_SUCCESS if successful, otherwise the appropriate error
Notes:
--*/
{
HANDLE DeviceHandle; // The mini rdr device handle
ULONG BytesRet;
BOOL rc;
ULONG Status;
Status = WN_SUCCESS;
// Grab a handle to the redirector device object
DeviceHandle = CreateFile(
DD_SMBMRX_USERMODE_DEV_NAME,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
0,
(HANDLE) NULL );
if ( INVALID_HANDLE_VALUE != DeviceHandle )
{
rc = DeviceIoControl( DeviceHandle,
IoctlCode,
InputDataBuf,
InputDataLen,
OutputDataBuf,
*pOutputDataLen,
pOutputDataLen,
NULL );
if ( !rc )
{
DbgP(( L"SendToMiniRdr - returning error from DeviceIoctl\n" ));
Status = GetLastError( );
}
else
{
DbgP(( L"SendToMiniRdr - The DeviceIoctl call succeded\n" ));
}
CloseHandle(DeviceHandle);
}
else
{
Status = GetLastError( );
DbgP(( L"SendToMiniRdr - error %lx opening device \n", Status ));
}
return Status;
}
ULONG FillInEaBuffer( LPTSTR pUserName, LPTSTR pPassword, PBYTE pEaData )
{
PFILE_FULL_EA_INFORMATION thisEa = (PFILE_FULL_EA_INFORMATION) pEaData;
PBYTE valuePtr = pEaData;
PWKSTA_INFO_100 WkStaInfo;
ULONG status;
PWCHAR pDomain;
// get the domain that this workstation is a member of
status = NetWkstaGetInfo( NULL, 100, (PBYTE *) &WkStaInfo );
if ( status == ERROR_SUCCESS )
{
pDomain = WkStaInfo->wki100_langroup;
}
else
{
pDomain = NULL;
}
DbgP((L"FillInEaBuffer - domain name=%s\n", pDomain));
thisEa->EaValueLength = 0;
thisEa->NextEntryOffset = 0;
// Set the user name EA
if ( pUserName )
{
thisEa->Flags = 0;
thisEa->EaNameLength = sizeof("UserName");
CopyMemory( thisEa->EaName, "UserName\0", thisEa->EaNameLength + 1 );
valuePtr = (PBYTE) thisEa->EaName + thisEa->EaNameLength + 1;
thisEa->EaValueLength = (USHORT)( *pUserName ? lstrlenW( pUserName ) : 1 ) * sizeof( WCHAR );
CopyMemory( valuePtr, pUserName, thisEa->EaValueLength );
thisEa->NextEntryOffset = (ULONG)(((PBYTE) valuePtr + thisEa->EaValueLength ) -
(PBYTE) thisEa);
thisEa->NextEntryOffset = ((thisEa->NextEntryOffset + 3) / sizeof(LONG)) * sizeof(LONG);
}
// Set the password EA.
if ( pPassword )
{
thisEa = (PFILE_FULL_EA_INFORMATION) ((PBYTE) thisEa + thisEa->NextEntryOffset);
thisEa->Flags = 0;
thisEa->EaNameLength = sizeof("Password");
CopyMemory( thisEa->EaName, "Password\0", thisEa->EaNameLength + 1 );
valuePtr = (PBYTE) thisEa->EaName + thisEa->EaNameLength + 1;
thisEa->EaValueLength = (USHORT)( *pPassword ? lstrlenW( pPassword ) : 1 ) * sizeof( WCHAR );
CopyMemory( valuePtr, pPassword, thisEa->EaValueLength );
thisEa->NextEntryOffset = (ULONG)(((PBYTE) valuePtr + thisEa->EaValueLength ) -
(PBYTE) thisEa);
thisEa->NextEntryOffset = ((thisEa->NextEntryOffset + 3) / sizeof(LONG)) * sizeof(LONG);
}
// Set the domain EA
if ( pDomain )
{
thisEa = (PFILE_FULL_EA_INFORMATION) ((PBYTE) thisEa + thisEa->NextEntryOffset);
thisEa->Flags = 0;
thisEa->EaNameLength = sizeof("Domain");
RtlCopyMemory( thisEa->EaName, "Domain\0", thisEa->EaNameLength + 1 );
valuePtr = (PBYTE) thisEa->EaName + thisEa->EaNameLength + 1;
thisEa->EaValueLength = (USHORT)( *pDomain ? lstrlenW( pDomain ) : 1 ) * sizeof( WCHAR );
RtlCopyMemory( valuePtr, pDomain, thisEa->EaValueLength );
thisEa->NextEntryOffset = 0;
}
thisEa->NextEntryOffset = 0;
return (ULONG)(((PBYTE) valuePtr + thisEa->EaValueLength) - (PBYTE) pEaData);
}
DWORD APIENTRY
NPAddConnection(
LPNETRESOURCE lpNetResource,
LPWSTR lpPassword,
LPWSTR lpUserName )
/*++
Routine Description:
This routine adds a connection to the list of connections associated
with this network provider
Arguments:
lpNetResource - the NETRESOURCE struct
lpPassword - the password
lpUserName - the user name
Return Value:
WN_SUCCESS if successful, otherwise the appropriate error
Notes:
--*/
{
return NPAddConnection3(NULL, lpNetResource, lpPassword, lpUserName, 0);
}
DWORD APIENTRY
NPAddConnection3(
HWND hwndOwner,
LPNETRESOURCE lpNetResource,
LPWSTR lpPassword,
LPWSTR lpUserName,
DWORD dwFlags )
/*++
Routine Description:
This routine adds a connection to the list of connections associated
with this network provider
Arguments:
hwndOwner - the owner handle
lpNetResource - the NETRESOURCE struct
lpPassword - the password
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?