📄 ea.c
字号:
IN PUCHAR UserEaList; - Supplies the Ea names required.
IN ULONG UserEaListLength;
OUT PFEALIST *ServerEaList - Eas returned by the server. Caller is responsible for
freeing memory.
Return Value:
Status - Result of the operation.
--*/
{
RxCaptureFobx;
PMRX_SMB_SRV_OPEN smbSrvOpen;
NTSTATUS Status;
USHORT Setup = TRANS2_QUERY_FILE_INFORMATION;
REQ_QUERY_FILE_INFORMATION QueryFileInfoRequest;
RESP_QUERY_FILE_INFORMATION QueryFileInfoResponse;
PBYTE pInputParamBuffer = NULL;
PBYTE pOutputParamBuffer = NULL;
PBYTE pInputDataBuffer = NULL;
PBYTE pOutputDataBuffer = NULL;
ULONG InputParamBufferLength = 0;
ULONG OutputParamBufferLength = 0;
ULONG InputDataBufferLength = 0;
ULONG OutputDataBufferLength = 0;
CLONG OutDataCount = EA_QUERY_SIZE;
CLONG OutSetupCount = 0;
PFEALIST Buffer;
PGEALIST ServerQueryEaList = NULL;
CLONG InDataCount;
PAGED_CODE();
RxDbgTrace(+1, Dbg, ("MRxSmbLoadEaList...\n"));
Status = STATUS_MORE_PROCESSING_REQUIRED;
smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
//
// Convert the supplied UserEaList to a GEALIST. The server will return just the Eas
// requested by the application.
//
//
// If the application specified a subset of EaNames then convert to OS/2 1.2 format and
// pass that to the server. ie. Use the server to filter out the names.
//
Buffer = RxAllocatePool ( PagedPool, OutDataCount );
if ( Buffer == NULL ) {
Status = STATUS_INSUFFICIENT_RESOURCES;
goto FINALLY;
}
if ( UserEaList != NULL) {
//
// OS/2 format is always a little less than or equal to the NT UserEaList size.
// This code relies on the I/O system verifying the EaList is valid.
//
ServerQueryEaList = RxAllocatePool ( PagedPool, UserEaListLength );
if ( ServerQueryEaList == NULL ) {
Status = STATUS_INSUFFICIENT_RESOURCES;
goto FINALLY;
};
MRxSmbNtGeaListToOs2((PFILE_GET_EA_INFORMATION )UserEaList, UserEaListLength, ServerQueryEaList );
InDataCount = (CLONG)ServerQueryEaList->cbList;
} else {
InDataCount = 0;
}
if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
QueryFileInfoRequest.Fid = smbSrvOpen->Fid;
if ( UserEaList != NULL) {
QueryFileInfoRequest.InformationLevel = SMB_INFO_QUERY_EAS_FROM_LIST;
} else {
QueryFileInfoRequest.InformationLevel = SMB_INFO_QUERY_ALL_EAS;
}
Status = SmbCeTransact(
RxContext, // the RXContext for the transaction
pTransactionOptions, // transaction options
&Setup, // the setup buffer
sizeof(Setup), // setup buffer length
NULL, // the output setup buffer
0, // output setup buffer length
&QueryFileInfoRequest, // Input Param Buffer
sizeof(QueryFileInfoRequest), // Input param buffer length
&QueryFileInfoResponse, // Output param buffer
sizeof(QueryFileInfoResponse),// output param buffer length
ServerQueryEaList, // Input data buffer
InDataCount, // Input data buffer length
Buffer, // output data buffer
OutDataCount, // output data buffer length
&ResumptionContext // the resumption context
);
if ( NT_SUCCESS(Status) ) {
ULONG ReturnedDataCount = ResumptionContext.DataBytesReceived;
RxDbgTrace(0, Dbg, ("MRxSmbLoadEaList...ReturnedDataCount=%08lx\n",ReturnedDataCount));
ASSERT(ResumptionContext.ParameterBytesReceived == sizeof(RESP_QUERY_FILE_INFORMATION));
if ( SmbGetUlong( &((PFEALIST)Buffer)->cbList) != ReturnedDataCount ){
Status = STATUS_EA_CORRUPT_ERROR;
}
if ( ReturnedDataCount == 0 ) {
Status = STATUS_NO_EAS_ON_FILE;
}
}
}
FINALLY:
if ( NT_SUCCESS(Status) ) {
*ServerEaList = Buffer;
} else {
if (Buffer != NULL) {
RxFreePool(Buffer);
}
}
if ( ServerQueryEaList != NULL) {
RxFreePool(ServerQueryEaList);
}
RxDbgTrace(-1, Dbg, ("MRxSmbLoadEaList...exit, st=%08lx\n",Status));
return Status;
}
VOID
MRxSmbNtGeaListToOs2 (
IN PFILE_GET_EA_INFORMATION NtGetEaList,
IN ULONG GeaListLength,
IN PGEALIST GeaList
)
/*++
Routine Description:
Converts a single NT GET EA list to OS/2 GEALIST style. The GEALIST
need not have any particular alignment.
Arguments:
NtGetEaList - An NT style get EA list to be converted to OS/2 format.
GeaListLength - the maximum possible length of the GeaList.
GeaList - Where to place the OS/2 1.2 style GEALIST.
Return Value:
none.
--*/
{
PGEA gea = GeaList->list;
PFILE_GET_EA_INFORMATION ntGetEa = NtGetEaList;
PAGED_CODE();
//
// Copy the Eas up until the last one
//
while ( ntGetEa->NextEntryOffset != 0 ) {
//
// Copy the NT format EA to OS/2 1.2 format and set the gea
// pointer for the next iteration.
//
gea = MRxSmbNtGetEaToOs2( gea, ntGetEa );
ASSERT( (ULONG_PTR)gea <= (ULONG_PTR)GeaList + GeaListLength );
ntGetEa = (PFILE_GET_EA_INFORMATION)((PCHAR)ntGetEa + ntGetEa->NextEntryOffset);
}
// Now copy the last entry.
gea = MRxSmbNtGetEaToOs2( gea, ntGetEa );
ASSERT( (ULONG_PTR)gea <= (ULONG_PTR)GeaList + GeaListLength );
//
// Set the number of bytes in the GEALIST.
//
SmbPutUlong(
&GeaList->cbList,
(ULONG)((PCHAR)gea - (PCHAR)GeaList)
);
UNREFERENCED_PARAMETER( GeaListLength );
}
PGEA
MRxSmbNtGetEaToOs2 (
OUT PGEA Gea,
IN PFILE_GET_EA_INFORMATION NtGetEa
)
/*++
Routine Description:
Converts a single NT Get EA entry to OS/2 GEA style. The GEA need not have
any particular alignment. This routine makes no checks on buffer
overrunning--this is the responsibility of the calling routine.
Arguments:
Gea - a pointer to the location where the OS/2 GEA is to be written.
NtGetEa - a pointer to the NT Get EA.
Return Value:
A pointer to the location after the last byte written.
--*/
{
PCHAR ptr;
PAGED_CODE();
Gea->cbName = NtGetEa->EaNameLength;
ptr = (PCHAR)(Gea) + 1;
RtlCopyMemory( ptr, NtGetEa->EaName, NtGetEa->EaNameLength );
ptr += NtGetEa->EaNameLength;
*ptr++ = '\0';
return ( (PGEA)ptr );
}
NTSTATUS
MRxSmbQueryEasFromServer(
IN PRX_CONTEXT RxContext,
IN PFEALIST ServerEaList,
IN PVOID Buffer,
IN OUT PULONG BufferLengthRemaining,
IN BOOLEAN ReturnSingleEntry,
IN BOOLEAN UserEaListSupplied
)
/*++
Routine Description:
This routine copies the required number of Eas from the ServerEaList
starting from the offset indicated in the Icb. The Icb is also updated
to show the last Ea returned.
Arguments:
IN PFEALIST ServerEaList - Supplies the Ea List in OS/2 format.
IN PVOID Buffer - Supplies where to put the NT format EAs
IN OUT PULONG BufferLengthRemaining - Supplies the user buffer space.
IN BOOLEAN ReturnSingleEntry
IN BOOLEAN UserEaListSupplied - ServerEaList is a subset of the Eas
Return Value:
NTSTATUS - The status for the Irp.
--*/
{
RxCaptureFobx;
ULONG EaIndex = capFobx->OffsetOfNextEaToReturn;
ULONG Index = 1;
ULONG Size;
ULONG OriginalLengthRemaining = *BufferLengthRemaining;
BOOLEAN Overflow = FALSE;
PFEA LastFeaStartLocation;
PFEA Fea = NULL;
PFEA LastFea = NULL;
PFILE_FULL_EA_INFORMATION NtFullEa = Buffer;
PFILE_FULL_EA_INFORMATION LastNtFullEa = Buffer;
PAGED_CODE();
RxDbgTrace(0, Dbg, ("MRxSmbQueryEasFromServer...EaIndex/Buffer/Remaining=%08lx/%08lx/%08lx\n",
EaIndex,Buffer,((BufferLengthRemaining)?*BufferLengthRemaining:0xbadbad)
));
//
// If there are no Ea's present in the list, return the appropriate
// error.
//
// Os/2 servers indicate that a list is null if cbList==4.
//
if ( SmbGetUlong(&ServerEaList->cbList) == FIELD_OFFSET(FEALIST, list) ) {
return STATUS_NO_EAS_ON_FILE;
}
//
// Find the last location at which an FEA can start.
//
LastFeaStartLocation = (PFEA)( (PCHAR)ServerEaList +
SmbGetUlong( &ServerEaList->cbList ) -
sizeof(FEA) - 1 );
//
// Go through the ServerEaList until we find the entry corresponding to EaIndex
//
for ( Fea = ServerEaList->list;
(Fea <= LastFeaStartLocation) && (Index < EaIndex);
Index+= 1,
Fea = (PFEA)( (PCHAR)Fea + sizeof(FEA) +
Fea->cbName + 1 + SmbGetUshort( &Fea->cbValue ) ) ) {
NOTHING;
}
if ( Index != EaIndex ) {
if ( Index == EaIndex+1 ) {
return STATUS_NO_MORE_EAS;
}
//
// No such index
//
return STATUS_NONEXISTENT_EA_ENTRY;
}
//
// Go through the rest of the FEA list, converting from OS/2 1.2 format to NT
// until we pass the last possible location in which an FEA can start.
//
for ( ;
Fea <= LastFeaStartLocation;
Fea = (PFEA)( (PCHAR)Fea + sizeof(FEA) +
Fea->cbName + 1 + SmbGetUshort( &Fea->cbValue ) ) ) {
PCHAR ptr;
//
// Calculate the size of this Fea when converted to an NT EA structure.
//
// The last field shouldn't be padded.
//
if ((PFEA)((PCHAR)Fea+sizeof(FEA)+Fea->cbName+1+SmbGetUshort(&Fea->cbValue)) < LastFeaStartLocation) {
Size = SmbGetNtSizeOfFea( Fea );
} else {
Size = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) +
Fea->cbName + 1 + SmbGetUshort(&Fea->cbValue);
}
//
// Will the next Ea fit?
//
if ( *BufferLengthRemaining < Size ) {
if ( LastNtFullEa != NtFullEa ) {
if ( UserEaListSupplied == TRUE ) {
*BufferLengthRemaining = OriginalLengthRemaining;
return STATUS_BUFFER_OVERFLOW;
}
Overflow = TRUE;
break;
} else {
// Not even room for a single EA!
return STATUS_BUFFER_OVERFLOW;
}
} else {
*BufferLengthRemaining -= Size;
}
//
// We are comitted to copy the Os2 Fea to Nt format in the users buffer
//
LastNtFullEa = NtFullEa;
LastFea = Fea;
EaIndex++;
// Create new Nt Ea
NtFullEa->Flags = Fea->fEA;
NtFullEa->EaNameLength = Fea->cbName;
NtFullEa->EaValueLength = SmbGetUshort( &Fea->cbValue );
ptr = NtFullEa->EaName;
RtlCopyMemory( ptr, (PCHAR)(Fea+1), Fea->cbName );
ptr += NtFullEa->EaNameLength;
*ptr++ = '\0';
//
// Copy the EA value to the NT full EA.
//
RtlCopyMemory(
ptr,
(PCHAR)(Fea+1) + NtFullEa->EaNameLength + 1,
NtFullEa->EaValueLength
);
ptr += NtFullEa->EaValueLength;
//
// Longword-align ptr to determine the offset to the next location
// for an NT full EA.
//
ptr = (PCHAR)( ((ULONG_PTR)ptr + 3) & ~3 );
NtFullEa->NextEntryOffset = (ULONG)( ptr - (PCHAR)NtFullEa );
NtFullEa = (PFILE_FULL_EA_INFORMATION)ptr;
if ( ReturnSingleEntry == TRUE ) {
break;
}
}
//
// Set the NextEntryOffset field of the last full EA to 0 to indicate
// the end of the list.
//
LastNtFullEa->NextEntryOffset = 0;
//
// Record position the default start position for the next query
//
capFobx->OffsetOfNextEaToReturn = EaIndex;
if ( Overflow == FALSE ) {
return STATUS_SUCCESS;
} else {
return STATUS_BUFFER_OVERFLOW;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -