in TestSuites/ADFamily/src/MS-FRS2/Adapter/FRS2ManagedAdapter.cs [3053:3679]
public error_status_t InitializeFileTransferAsync(int connectionId,
int frsUpdateContentSetID,
bool rdcCheck)
{
_FRS_RDC_FILEINFO[] fileInfo = new _FRS_RDC_FILEINFO[10];
int rdcDesired;
_FRS_REQUESTED_STAGING_POLICY stagingPolicy = _FRS_REQUESTED_STAGING_POLICY.SERVER_DEFAULT;
_FRS_REQUESTED_STAGING_POLICY stagingPolicyCopy = stagingPolicy;
IntPtr frsFileInfo = Marshal.AllocHGlobal(10000);
IntPtr dataBufferPtr = Marshal.AllocHGlobal(10000);
IntPtr test1 = Marshal.AllocHGlobal(700);
uint sizeRead;
uint bufferSize = Convert.ToUInt32(ConfigStore.BufferSize);
Guid updateGuid = new Guid();
switch (frsUpdateContentSetID)
{
case 1: updateGuid = serverControllerAdapter.InitializeGuid(ConfigStore.ContentId1,
"(objectClass=msDFSR-ContentSet)");
break;
case 2: updateGuid = serverControllerAdapter.InitializeGuid(ConfigStore.ContentId2,
"(objectClass=msDFSR-ContentSet)");
break;
case 3: updateGuid = serverControllerAdapter.InitializeGuid(ConfigStore.ContentId3,
"(objectClass=msDFSR-ContentSet)");
break;
case 4: updateGuid = serverControllerAdapter.InitializeGuid(ConfigStore.ContentId4,
"(objectClass=msDFSR-ContentSet)");
break;
case 5: updateGuid = new Guid(ConfigStore.ContentId5);
break;
case 6: updateGuid = serverControllerAdapter.InitializeGuid(ConfigStore.ContentId6,
"(objectClass=msDFSR-ContentSet)");
break;
}
if (!flagTradTestCaseCheck && !flagTradTestCaseForPushSourceNeeds &&
!flagTradTestCaseForRdcClose && !flagTradTestCaseForRdcGetSig
&& !flagTradTestCaseForRdcGetSigfail && !flagTradTestCaseForRdcGetSigfailForLevel
&& !flagTradTestCaseForPushSourceNeedsForNeedCount)
{
if (frsUpdate.Length < 2 && ConfigStore.IsTestSYSVOL)
FRSSite.Assert.Fail("Should not come here");
frsUpdate[1].contentSetId = updateGuid;
}
else
{
frsUpdate[countOfAsyncCall].contentSetId = updateGuid;
}
ConnectionSetId = getConnectionSetId(connectionId);
if (rdcCheck == true)
{
rdcDesired = 1;
clientRdcDesired = 1;
}
else
{
rdcDesired = 0;
clientRdcDesired = 0;
}
_FRS_UPDATE reqUpdate;
if (!flagTradTestCaseCheck && !flagTradTestCaseForPushSourceNeeds &&
!flagTradTestCaseForRdcClose && !flagTradTestCaseForRdcGetSig
&& !flagTradTestCaseForRdcGetSigfail && !flagTradTestCaseForRdcGetSigfailForLevel
&& !flagTradTestCaseForPushSourceNeedsForNeedCount)
{
reqUpdate = frsUpdate[1];
}
else
{
reqUpdate = frsUpdate[countOfAsyncCall];
}
byte[] frsUpdatebuff = FRS2Helpers.FrsUpdateStructToByteArray(reqUpdate);
IntPtr frsUpdatePtr = Marshal.AllocHGlobal(frsUpdatebuff.Length);
Marshal.Copy(frsUpdatebuff, 0, frsUpdatePtr, frsUpdatebuff.Length);
uint retVal = GenerateMessages.FRS2InitializeFileTransferAsync(bindingHandle,
ConnectionSetId,
frsUpdatePtr,
rdcDesired,
ref stagingPolicy,
out servContext,
frsFileInfo,
dataBufferPtr,
bufferSize,
out sizeRead,
out isEndofFile);
if (retVal == 0)
{
RDCFileInfo = FRS2Helpers.GetRdcFileInfo(frsFileInfo);
Marshal.FreeHGlobal(frsFileInfo);
ServerContext serverContext;
RDC_Sig_Level signatureLevels;
bool isEOF;
if (servContext == IntPtr.Zero)
{
serverContext = ServerContext.InvalidContext;
}
else
{
serverContext = ServerContext.ValidContext;
}
if (RDCFileInfo.rdcSignatureLevels == 0)
{
signatureLevels = RDC_Sig_Level.forRAWFileLevel;
}
else
{
signatureLevels = RDC_Sig_Level.forRDCFileLevel;
}
if (isEndofFile == 0)
{
isEOF = false;
}
else
{
isEOF = true;
}
//if (!flagTradTestCaseCheck && !flagTradTestCaseForPushSourceNeeds &&
// !flagTradTestCaseForRdcClose && !flagTradTestCaseForRdcGetSig &&
// !flagTradTestCaseForRdcGetSigfail && !flagTradTestCaseForRdcGetSigfailForLevel
// && !flagTradTestCaseForPushSourceNeedsForNeedCount)
//{
if (InitializeFileTransferAsyncEvent != null)
InitializeFileTransferAsyncEvent(serverContext, signatureLevels, isEOF);
//}
if (rdcCheck == true)
{
// for SYSVOL, by default the file is too small so no need RDC Chunk
if (!ConfigStore.IsTestSYSVOL)
{
//Verifying whether the value of RDC_CHUNKER_ALGORITHM enumeration is 1 or not.
FRSSite.CaptureRequirementIfIsTrue((RDCFileInfo.rdcFilterParameters.rdcChunkerAlgorithm == 1),
81, "When the value of RDC_CHUNKER_ALGORITHM enumeration is 1 it" +
" implies, RDC_FILTERMAX means FilterMax chunker algorithm is used.");
//Verifying whether the RDC_FILTERMAX = 1 value is sent when an RDC_CHUNKER_ALGORITHM enum value is required.
FRSSite.CaptureRequirementIfIsTrue((RDCFileInfo.rdcFilterParameters.rdcChunkerAlgorithm == 1),
82, "RDC_FILTERMAX value MUST be sent whenever an RDC_CHUNKER_ALGORITHM enum value is required.");
//Verifying whether in the FRS_RDC_PARAMETERS structure, the rdcChunkerAlgorithm field is RDC_FILTERMAX,
//for compatibility.
FRSSite.CaptureRequirementIfIsTrue((RDCFileInfo.rdcFilterParameters.rdcChunkerAlgorithm == 1),
208, "In FRS_RDC_PARAMETERS structure, rdcChunkerAlgorithm field MUST" +
" be RDC_FILTERMAX,for compatibility.");
}
}
_FRS_UPDATE[] retUpdates = new _FRS_UPDATE[1];
_FRS_UPDATE retFRSUpdates = new _FRS_UPDATE();
FRS2Helpers.getUpdates(frsUpdatePtr, 1, out retUpdates);
retFRSUpdates = retUpdates[0];
Marshal.FreeHGlobal(frsUpdatePtr);
if (isEndofFile == 1 && ConfigStore.IsWindows)
{
byte[] dataBuffer = new byte[sizeRead];
long bufferAddress = (long)dataBufferPtr;
for (int i = 0; i < sizeRead; i++)
{
dataBuffer[i] = Marshal.ReadByte((IntPtr)bufferAddress);
bufferAddress += sizeof(byte);
}
ASCIIEncoding encoding = new ASCIIEncoding();
FSCCAdapter objParser = new FSCCAdapter();
Helper objHelper = new Helper();
ReplicatedFileStructure objDataBuffer = new ReplicatedFileStructure();
bool ParserResult = objParser.ValidateDataBuffer(dataBuffer, out objDataBuffer);
if (ParserResult)
{
#region MS-FRS2_R822
FRSSite.CaptureRequirementIfIsTrue(
ParserResult && (sizeRead <= bufferSize),
822, "In the Custom Marshaling Format if a stream" +
" requires multiple chunks, only the last header" +
" from that stream MUST have the" +
" HEADER_FLAGS_END_OF_STREAM bit set");
#endregion
#region MS-FRS2_R824
FRSSite.CaptureRequirementIfIsTrue(ParserResult,
824, "In the Custom Marshaling Format, the data MUST be tightly packed.");
#endregion
#region MS-FRS2_R825
FRSSite.CaptureRequirementIfIsTrue(ParserResult,
825, "In the Custom Marshaling Format There" +
" MUST NOT be any additional bytes of padding.");
#endregion
int countOfStreams = objDataBuffer.streamdata.Count;
#region MS-FRS2_R848
//Implicitly verified by the parser since, the parser
//reads the header before evaluating the stream.
FRSSite.CaptureRequirementIfIsTrue(ParserResult,
848, "In the Compressed Data Format Each block of data MUST have" +
" a data block header.");
#endregion
byte[] sig = objHelper.GetSubArray(
objDataBuffer.signature.BlockSignature,
0,
4);
string signature = encoding.GetString(sig);
#region MS-FRS2_R849
FRSSite.CaptureRequirementIfAreEqual(4,
sig.Length,
849,
"In the Compressed Data Format, the data stream header" +
" MUST consist of a 4-byte signature");
#endregion
#region MS-FRS2_R851
FRSSite.CaptureRequirementIfAreEqual<string>("FRSX", signature,
851, "In the Compressed Data Format, the data stream header" +
" MUST consist of a 4-byte signature");
#endregion
#region MS-FRS2_R853
FRSSite.CaptureRequirementIfAreNotEqual((UInt32)0,
objDataBuffer.signature.BlockCompressedSize,
853, "In the Compressed Data Format The compressed size MUST NOT" +
" be equal to 0 for Block Compressed Size field.");
#endregion
#region MS-FRS2_R855
FRSSite.CaptureRequirementIfIsTrue(
objDataBuffer.signature.BlockUncompressedSize <= 8192,
855, "In the Compressed Data Format The uncompressed size MUST" +
" be less than or equal to 8192 bytes for Block Uncompressed Size. ");
#endregion
#region MS-FRS2_R856
FRSSite.CaptureRequirementIfIsTrue(
objDataBuffer.signature.BlockCompressedSize <=
objDataBuffer.signature.BlockUncompressedSize,
856, "In the Compressed Data Format The compressed size MUST be" +
" less than or equal to the uncompressed size.");
#endregion
#region MS-FRS2_R859
//Validated in the parser.
FRSSite.CaptureRequirementIfIsTrue(ParserResult,
859, "In the Compressed Data Format The uncompressed size MUST" +
" be equal to 8192 bytes, except for the last block of a file" +
" transfer, which may be smaller, and except when this data is" +
" from RdcGetFileData");
#endregion
Validate_FSCC_BKUP_Requirements(objDataBuffer, ParserResult);
}
}
else if ((isEndofFile == 0) && (rdcDesired == 0))
{
//If EndofFile is not reached then the dataBuffer
//can not be fed to the parser since the FLAT
//Stream data would be splitted and entire data
//will not present in this dataBuffer.
#region MS-FRS2_R823
FRSSite.CaptureRequirementIfIsTrue(
sizeRead == bufferSize,
823,
"In the Custom Marshaling Format all other" +
" headers MUST have the flags set to 0 besides" +
" HEADER_FLAGS_END_OF_STREAM for sending multiple chunks.");
#endregion
}
#region RequirementValidation
#region MS-FRS2_R757
if (ConfigStore.IsWindows)
{
//Verifing frsUpdate fields except the UID are cleared (zeroed out).<30>
FRSSite.CaptureRequirementIfIsNotNull(reqUpdate.uidDbGuid,
757,
@"frsUpdate fields except the UID are cleared (zeroed out).<30>");
}
#endregion
#region MS-FRS2_R791
//Verifying Upon successfully validating the file transfer request, the server MUST retrieve
//the file data associated with the requested UID in the supplied update.
FRSSite.CaptureRequirementIfIsNotNull(fileInfo, 791, "Upon successfully validating the file transfer request, the server MUST retrieve" +
"the file data associated with the requested UID in the supplied update. ");
#endregion
#region MS-FRS2_R792
//Verifying that the RDCSignaturelevels are equal to "0" implies raw file transfer
if (RDCFileInfo.rdcSignatureLevels == 0)
{
FRSSite.CaptureRequirement(792, "[InitializeFileTransferAsync]" +
"The server MUST then [upon retrieving the file " +
"data associated with the requested UID in the supplied update] " +
"send the file data in the way that the client has specified if " +
"possible (not using RDC).");
}
#endregion
#region MS-FRS2_R793
//Verifying that the RDCSignaturelevels are equal to "0" implies raw file transfer
if (RDCFileInfo.rdcSignatureLevels != 0)
{
FRSSite.CaptureRequirement(793,
"[InitializeFileTransferAsync]" +
"The server MUST then [upon retrieving the file " +
"data associated with the requested UID in the supplied update] " +
"send the file data in the way that the client has specified if " +
"possible (using RDC).");
}
#endregion
#region MS-FRS2_R796
//Verifying The server MUST provide the file metadata that is associated with
//the file that it serves. It does so by providing its own view of
//the update associated with the requested UID in the return valueof frsUpdate.
FRSSite.CaptureRequirementIfIsNotNull(fileInfo, 796, "The server MUST provide the file metadata that is associated with " +
"the file that it serves. It does so by providing its own view of " +
"the update associated with the requested UID in the return value" +
"of frsUpdate.");
#endregion
if (!ConfigStore.WillingToCheckReq[798])
{
#region MS-FRS2_R798
//Verifying that the RDCSignaturelevels are equal to "0" implies raw file transfer
if (bufferSize == 0)
{
FRSSite.CaptureRequirementIfIsTrue(((retVal != 0) || ((sizeRead == 0) && (retVal == 0))), 798,
"[InitializeFileTransferAsync]If bufferSize is " +
"zero then the server MAY complete the call " +
"successfully with sizeRead set to zero, or fail " +
"the call with an implementation-defined failure value.");
}
#endregion
}
#region MS-FRS2_R1279
//Verifying The default behavior of a Windows Server 2008 and Windows 7
//[if bufferSize is zero] is to complete the request successfully
//and return sizeRead equal to zero.
if (ConfigStore.IsWindows)
{
if (bufferSize == 0)
{
FRSSite.CaptureRequirementIfIsTrue(retVal == 0,
1279,
@" The default behavior of Windows Server 2008 and" +
"Windows 7 [if bufferSize is zero] is to complete the request" +
"successfully and return sizeRead equal to zero.");
}
}
#endregion
#region MS-FRS2_R799
if (ConfigStore.IsWindows)
{
//Verifying The default behavior of a Windows-based server
//[if bufferSize is zero] is to complete the request successfully
//and return sizeRead equal to zero.
if (bufferSize == 0)
{
FRSSite.CaptureRequirementIfIsTrue(retVal == 0,
799,
@"WB> The default behavior of a Windows-based server [if bufferSize is zero] is to
complete the request successfully and return sizeRead equal to zero. </WB>");
}
}
#endregion
#region MS-FRS2_R965
// Verifying if In RDC File Transfer if a server determines that the file to be served is not
//suitable for the RDC protocol, it sets rdcSignatureLevels to 0 in the FRS_RDC_FILEINFO structure.
if (RDCFileInfo.rdcSignatureLevels == 0)
{
FRSSite.CaptureRequirement(965,
"In RDC File Transfer if a server determines " +
"that the file to be served is not suitable " +
"for the RDC protocol, it sets rdcSignatureLevels " +
"to 0 in the FRS_RDC_FILEINFO structure.");
}
#endregion
if (ConfigStore.Should)
{
#region MS-FRS2_R1113
//The server should honour the staging policy set by the client and return success.
FRSSite.CaptureRequirement(1113,
"For stagingPolicy Parameter: The server SHOULD honor the " +
"InitializeFileTransferAsync request.");
#endregion
}
else
{
#region MS-FRS2_R1277
//The Windows Server does honour the staging policy set by the client and return success.
FRSSite.CaptureRequirement(1277,
"[For stagingPolicy Parameter]" +
"Windows Server does honor the InitializeFileTransferAsync request.");
#endregion
}
#region MS-FRS2_R1116
//Verifying If the server context handle returned by InitializeFileTransferAsync is set to 0,
//the entire contents of the downloaded file fit in the buffer provided as part of the output
//parameters of InitializeFileTransferAsync.
if (servContext == IntPtr.Zero)
{
FRSSite.CaptureRequirementIfIsTrue((sizeRead < bufferSize) && (sizeRead != 0),
1116,
"If the server context handle returned by InitializeFileTransferAsync" +
"is set to 0, the entire contents of the downloaded file fit " +
"in the buffer provided as part of the output parameters of " +
"InitializeFileTransferAsync. ");
}
#endregion
#region MS-FRS2_R771
if (isEndofFile == 1)
{
//Verifying The value of isEndOfFile is TRUE if the end of the specified file has been reached
//and there is no more file data to replicate to the client; otherwise, the value is FALSE.
//Verified by comparing the sizeRead with BufferSize, if the sizeRead is Less than BufferSize, it means
//that no more data available to replicate to the client.
FRSSite.CaptureRequirementIfIsTrue(sizeRead < bufferSize,
771,
@"The value of isEndOfFile is TRUE if the end of the specified file
has been reached and there is no more file data to replicate to
the client; otherwise, the value is FALSE.");
}
#endregion
#region MS-FRS2_R764
if (!Convert.ToBoolean(ConfigStore.Reqnoblocked764))
{
if (rdcCheck == true)
{
//Verifying If the client-supplied value of rdcDesired is TRUE and the client-supplied value of stagingPolicy
//is SERVER_DEFAULT, then the server MUST set stagingPolicy to STAGING_REQUIRED.
FRSSite.CaptureRequirementIfIsTrue(stagingPolicyCopy == _FRS_REQUESTED_STAGING_POLICY.SERVER_DEFAULT &&
stagingPolicy == _FRS_REQUESTED_STAGING_POLICY.STAGING_REQUIRED,
764,
@"If the client-supplied value of rdcDesired is TRUE and the client-supplied
value of stagingPolicy is SERVER_DEFAULT, then the server MUST set stagingPolicy
to STAGING_REQUIRED. ");
}
}
#endregion
#region MS-FRS2_R772
if (isEndofFile == 1)
{
//Verifying the value of isEndOfFile is TRUE if the end of the specified file has been reached and
//there is no more file data to replicate to the client.
FRSSite.CaptureRequirementIfIsTrue((bufferSize > sizeRead),
772,
@"The value of isEndOfFile is TRUE if the end of the specified file has
been reached and there is no more file data to replicate to the client.");
}
#endregion
#region MS-FRS2_R773
if (isEndofFile == 0)
{
//Verifying The value of isEndOfFile is FALSE if the end of the specified file has not been reached
//and there is more file data to replicate to the client.
FRSSite.CaptureRequirementIfIsTrue((sizeRead == bufferSize) || (sizeRead == 0),
773,
@"The value of isEndOfFile is FALSE if the end of the specified file
has not been reached and there is more file data to replicate to the client.");
}
#endregion
#region MS-FRS2_R785
if (frsUpdate[0].present == present_Values.V1)
{
//Verifying If the file on the server has been deleted and if the corresponding file metadata
//has been updated with the present flag set to 0 then the server MUST fail the call with an
//implementation-defined failure value.
FRSSite.CaptureRequirementIfAreNotEqual<uint>(retVal, 0,
785,
@"If the file on the server has been deleted and if the corresponding file
metadata has been updated with the present flag set to 0 then the server
MUST fail the call with an implementation-defined failure value.");
}
#endregion
#region MS-FRS2_R226
if (RDCFileInfo.rdcSignatureLevels == 0)
{
//Verifying whether the value of 0 indicates that a non-RDC file transfer is required.
FRSSite.CaptureRequirement(226,
@"A value of 0 indicates that a non-RDC file transfer is required.");
}
#endregion
if (ConfigStore.Should)
{
#region MS-FRS2_R217
//Verifying The server SHOULD make the estimate of onDiskFileSize field in FRS_RDC_FILEINFO
//structure as accurate as possible, but the protocol does not require that it be exact.
FRSSite.CaptureRequirementIfIsNotNull(RDCFileInfo.onDiskFileSize,
217,
"The server SHOULD make the estimate of onDiskFileSize " +
"field in FRS_RDC_FILEINFO structure as accurate as " +
"possible, but the protocol does not require that it be" +
"exact.");
#endregion
}
if (ConfigStore.Should)
{
#region MS-FRS_R219
//Verifying The server SHOULD make the estimate of fileSizeEstimate field in FRS_RDC_FILEINFO structure
//as accurate as possible, but the protocol does not require that it be exact.
FRSSite.CaptureRequirementIfIsNotNull(RDCFileInfo.fileSizeEstimate,
219,
"The server SHOULD make the estimate of fileSizeEstimate" +
"field in FRS_RDC_FILEINFO structure as accurate as possible," +
"but the protocol does not require that it be exact.");
#endregion
}
//Verifying The compressionAlgorithm field in FRS_RDC_FILEINFO structure MUST be
//set to RDC_UNCOMPRESSED.
bool flag = false;
if (RDCFileInfo.compressionAlgorithm == _RDC_FILE_COMPRESSION_TYPES.RDC_UNCOMPRESSED)
{
flag = true;
#region MS-FRS2_R228
FRSSite.CaptureRequirementIfIsTrue(flag,
228,
"The compressionAlgorithm field in FRS_RDC_FILEINFO " +
"structure MUST be set to RDC_UNCOMPRESSED.");
#endregion
#region MS-FRS2_R74
//Verifying When the value of RDC_FILE_COMPRESSION_TYPES enumeration is 0 it implies,
//RDC_UNCOMPRESSED means data is not compressed.
FRSSite.CaptureRequirementIfIsTrue(flag,
74,
"When the value of RDC_FILE_COMPRESSION_TYPES enumeration is 0" +
"it implies, RDC_UNCOMPRESSED means data is not compressed. ");
#endregion
#region MS-FRS2_R75
//Verifying RDC_UNCOMPRESSED MUST be sent whenever an RDC_FILE_COMPRESSION_TYPES enum value is required.
FRSSite.CaptureRequirementIfIsTrue(flag,
75,
"RDC_UNCOMPRESSED MUST be set whenever an RDC_FILE_COMPRESSION_TYPES"
+ "enum value is required.");
#endregion
}
#region MS-FRS2_R221
//Verifying The rdcVersion field in FRS_RDC_FILEINFO structure MUST be 1.
FRSSite.CaptureRequirementIfIsTrue((RDCFileInfo.rdcVersion == 1),
221,
"The rdcVersion field in FRS_RDC_FILEINFO structure MUST be 1.");
#endregion
#region MS-FRS2_R223
FRSSite.CaptureRequirementIfIsTrue((RDCFileInfo.rdcMinimumCompatibleVersion == 1),
223,
"The rdcMinimumCompatibleVersion field in FRS_RDC_FILEINFO" +
"structure MUST be 1.");
#endregion
#endregion
}
Marshal.FreeHGlobal(dataBufferPtr);
switch (retVal)
{
case (uint)Error.FRS_ERROR_CONNECTION_INVALID:
return error_status_t.FRS_ERROR_CONNECTION_INVALID;
case (uint)Error.FRS_ERROR_CONTENTSET_NOT_FOUND:
return error_status_t.FRS_ERROR_CONTENTSET_NOT_FOUND;
default: return error_status_t.ERROR_SUCCESS;
}
}