Exemple #1
0
 public ModelCreateLeaseRequest(
     CreateOptions_Values createOptions,
     RequestedOplockLevel_Values requestedOplockLevel_Values,
     ModelCreateContextRequest leaseContext,
     LeaseContextType leaseContextType)
     : base(0)
 {
     this.CreateOptions        = createOptions;
     this.RequestedOplockLevel = requestedOplockLevel_Values;
     this.LeaseContext         = leaseContext;
     this.ContextType          = leaseContextType;
 }
        public uint Create(
            uint treeId,
            string fileName,
            CreateOptions_Values createOptions,
            out FILEID fileId,
            out Smb2CreateContextResponse[] serverCreateContexts,
            RequestedOplockLevel_Values requestedOplockLevel_Values = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
            Smb2CreateContextRequest[] createContexts = null,
            Packet_Header_Flags_Values headerFlag     = Packet_Header_Flags_Values.FLAGS_SIGNED,
            AccessMask accessMask                     = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE,
            ShareAccess_Values shareAccess            = ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
            ResponseChecker <CREATE_Response> checker = null,
            ushort creditRequest = 64)
        {
            Packet_Header   header;
            CREATE_Response createResponse;

            uint status = client.Create(
                1,
                creditRequest,
                headerFlag,
                messageId++,
                sessionId,
                treeId,
                fileName,
                accessMask,
                shareAccess,
                createOptions,
                CreateDisposition_Values.FILE_OPEN_IF,
                File_Attributes.NONE,
                ImpersonationLevel_Values.Impersonation,
                SecurityFlags_Values.NONE,
                requestedOplockLevel_Values,
                createContexts,
                out fileId,
                out serverCreateContexts,
                out header,
                out createResponse);

            InnerResponseChecker(checker, header, createResponse);

            grantedCredit = header.CreditRequestResponse;

            return(status);
        }
        /// <summary>
        /// Conflict requests sent from the two clients
        /// </summary>
        /// <param name="requestFromFirstClient">Type of the specified request from the first client</param>
        /// <param name="requestFromSecondClient">Type of the specified request from the second client</param> 
        public void ConflictRequest(RequestType requestFromFirstClient, RequestType requestFromSecondClient)
        {
            // Create an open for the second client before the first client deletes the file
            if (requestFromFirstClient == RequestType.UncommitedDelete)
            {
                CreateOptions_Values createOptions = (requestFromSecondClient == RequestType.Delete) ?
                    (CreateOptions_Values.FILE_NON_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE)
                    : CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
                Smb2CreateContextResponse[] contexts;
                secondClient.Create(
                    treeId2,
                    fileName,
                    createOptions,
                    out fileId2,
                    out contexts,
                    RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE);
            }

            RequestFromFirstClient(requestFromFirstClient);
            RequestFromSecondClient(requestFromSecondClient);
        }
 public ModelCreateLeaseRequest(
     CreateOptions_Values createOptions,
     RequestedOplockLevel_Values requestedOplockLevel_Values,
     ModelCreateContextRequest leaseContext,
     LeaseContextType leaseContextType)
     : base(0)
 {
     this.CreateOptions = createOptions;
     this.RequestedOplockLevel = requestedOplockLevel_Values;
     this.LeaseContext = leaseContext;
     this.ContextType = leaseContextType;
 }
        /// <summary>
        /// Check the status code of create response
        /// </summary>
        /// <param name="isNonAdmin">true for non admin credential</param>
        /// <param name="createOption">The create option set in create request</param>
        /// <param name="accessMask">The access mark set in create request</param>
        /// <param name="header">Header of create response</param>
        /// <param name="response">create response</param>
        /// <param name="fileNameType">file name type</param>
        private void CheckCreateResponse(bool isNonAdmin, CreateOptions_Values createOption, AccessMask accessMask, Packet_Header header, CREATE_Response response, FileNameType fileNameType)
        {
            switch (fileNameType)
            {
            case FileNameType.SymbolicLinkInMiddle:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                    header.Status,
                    "3.3.5.9: If any intermediate component of the path specified in the create request is a symbolic link, " +
                    "the server MUST return an error as specified in section 2.2.2.1. " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                break;
            }

            case FileNameType.SymbolicLinkAtLast:
            {
                if (!createOption.HasFlag(CreateOptions_Values.FILE_OPEN_REPARSE_POINT))
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                        header.Status,
                        "3.3.5.9: If the final component of the path is a symbolic link, the server behavior depends on whether the flag FILE_OPEN_REPARSE_POINT was specified in the CreateOptions field of the request. " +
                        "If FILE_OPEN_REPARSE_POINT was specified, the server MUST open the underlying file or directory and return a handle to it. " +
                        "Otherwise, the server MUST return an error as specified in section 2.2.2.1. " +
                        "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                }
                break;
            }

            case FileNameType.InvalidSymbolicLink:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                    header.Status,
                    "3.3.5.9: If the underlying object store returns a failure indicating that the attempted open operation failed due to the presence of a symbolic link in the target path name, " +
                    "the server MUST fail the create operation with the error code STATUS_STOPPED_ON_SYMLINK. " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                break;
            }

            case FileNameType.NotExistedValidFileName:
            {
                if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) &&
                    !(accessMask.HasFlag(AccessMask.DELETE) || accessMask.HasFlag(AccessMask.GENERIC_ALL)))
                {
                    if (testConfig.Platform == Platform.NonWindows)
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2008 ||
                             testConfig.Platform == Platform.WindowsServer2008R2)
                    {
                        //TD does not specify the behavior of windows 2008 and 2008R2, not check here
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2012)
                    {
                        //For platform windows 2012
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_INVALID_PARAMETER,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else
                    {
                        //For platform windows 2012R2 and above
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_ACCESS_DENIED,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                }
                else if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) && isNonAdmin)
                {
                    //NonAdminAccountCredential does not include DELETE or GENERIC_ALL in MaximalAccess
                    if (testConfig.Platform == Platform.NonWindows)
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2008 ||
                             testConfig.Platform == Platform.WindowsServer2008R2)
                    {
                        //TD does not specify te behavior of windows 2008 and 2008R2, not check here
                    }
                    else
                    {
                        //For platform win2012 and 2012R2
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_ACCESS_DENIED,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                }
                else
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_SUCCESS,
                        header.Status,
                        "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                }
                break;
            }

            case FileNameType.ExistedValidFileName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            }
            break;

            case FileNameType.NotExistedValidFileNameWithDotDirectoryName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            }
            break;

            case FileNameType.NotExistedValidFileNameWithDoubleDotDirectoryName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_INVALID_PARAMETER,
                    header.Status,
                    "3.3.5.9: Windows-based servers accept the path names containing Dot Directory Names specified in [MS-FSCC] section 2.1.5.1 and attempt to normalize the path name by removing the pathname components of \".\"  and \"..\"." +
                    "Windows-based servers fail the CREATE request with STATUS_INVALID_PARAMETER if the file name in the Buffer field of the request begins in the form \"subfolder\\..\\\", for example \"x\\..\\y.txt\". " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
            }
            break;

            default:
                throw new ArgumentException("fileNameType");
            }
        }
Exemple #6
0
        public void CreateRequest(
            CreateFileNameType fileNameType,
            CreateOptionsFileOpenReparsePointType fileOpenReparsePointType,
            CreateOptionsFileDeleteOnCloseType fileDeleteOnCloseType,
            CreateContextType contextType,
            ImpersonationLevelType impersonationType,
            CreateFileType fileType)
        {
            #region Header
            Packet_Header_Flags_Values headerFlag = testConfig.SendSignedRequest ? Packet_Header_Flags_Values.FLAGS_SIGNED : Packet_Header_Flags_Values.NONE;

            #endregion

            #region File Name
            string fileName = GetFileName(fileNameType);
            #endregion

            #region CreateOptions
            CreateOptions_Values createOptions = fileType == CreateFileType.DirectoryFile ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            if (fileOpenReparsePointType == CreateOptionsFileOpenReparsePointType.FileOpenReparsePointSet)
            {
                createOptions |= CreateOptions_Values.FILE_OPEN_REPARSE_POINT;
            }
            if (fileDeleteOnCloseType == CreateOptionsFileDeleteOnCloseType.FileDeteteOnCloseSet)
            {
                createOptions |= CreateOptions_Values.FILE_DELETE_ON_CLOSE;
            }
            #endregion

            #region CreateContexts
            Smb2CreateContextRequest[] createContexts = new Smb2CreateContextRequest[] { };
            Create_ContextType = contextType;
            switch (contextType)
            {
            case CreateContextType.NoCreateContext:
                break;

            case CreateContextType.InvalidCreateContext:
            case CreateContextType.InvalidCreateContextSize:
                testClient.BeforeSendingPacket(ReplacePacketByInvalidCreateContext);
                break;

            case CreateContextType.ValidCreateContext:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_QUERY_ON_DISK_ID);

                createContexts = createContexts.Append(new Smb2CreateQueryOnDiskId());
                break;

            default:
                throw new ArgumentException("contextType");
            }
            #endregion

            #region ImpersonationLevel
            ImpersonationLevel_Values impersonation = ImpersonationLevel_Values.Impersonation;
            if (impersonationType == ImpersonationLevelType.InvalidImpersonationLevel)
            {
                impersonation = (ImpersonationLevel_Values)0x00000004; //Non-existed impersonation level
            }

            #endregion

            #region DesiredAccess
            AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;
            #endregion

            Smb2CreateContextResponse[] contextResponse;

            uint status = testClient.Create(
                treeId,
                fileName,
                createOptions,
                headerFlag,
                out fileID,
                out contextResponse,
                createContexts: createContexts,
                accessMask: accessMask,
                checker: (header, response) => { },
                impersonationLevel: impersonation);

            CreateResponse((ModelSmb2Status)status, createCloseConfig);
        }
 /// <summary>
 /// Check the status code of create response
 /// </summary>
 /// <param name="isNonAdmin">true for non admin credential</param>
 /// <param name="createOption">The create option set in create request</param>
 /// <param name="accessMask">The access mark set in create request</param>
 /// <param name="header">Header of create response</param>
 /// <param name="response">create response</param>
 /// <param name="fileNameType">file name type</param>
 private void CheckCreateResponse(bool isNonAdmin, CreateOptions_Values createOption, AccessMask accessMask, Packet_Header header, CREATE_Response response, FileNameType fileNameType)
 {
     switch (fileNameType)
     {
         case FileNameType.SymbolicLinkInMiddle:
             {
                 BaseTestSite.Assert.AreEqual(
                     Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                     header.Status,
                     "3.3.5.9: If any intermediate component of the path specified in the create request is a symbolic link, " +
                     "the server MUST return an error as specified in section 2.2.2.1. " +
                     "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                 break;
             }
         case FileNameType.SymbolicLinkAtLast:
             {
                 if (!createOption.HasFlag(CreateOptions_Values.FILE_OPEN_REPARSE_POINT))
                 {
                     BaseTestSite.Assert.AreEqual(
                         Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                         header.Status,
                         "3.3.5.9: If the final component of the path is a symbolic link, the server behavior depends on whether the flag FILE_OPEN_REPARSE_POINT was specified in the CreateOptions field of the request. " +
                         "If FILE_OPEN_REPARSE_POINT was specified, the server MUST open the underlying file or directory and return a handle to it. " +
                         "Otherwise, the server MUST return an error as specified in section 2.2.2.1. " +
                         "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                 }
                 break;
             }
         case FileNameType.InvalidSymbolicLink:
             {
                 BaseTestSite.Assert.AreEqual(
                     Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                     header.Status,
                     "3.3.5.9: If the underlying object store returns a failure indicating that the attempted open operation failed due to the presence of a symbolic link in the target path name, " +
                     "the server MUST fail the create operation with the error code STATUS_STOPPED_ON_SYMLINK. " +
                     "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                 break;
             }
         case FileNameType.NotExistedValidFileName:
             {
                 if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE)
                     && !(accessMask.HasFlag(AccessMask.DELETE) || accessMask.HasFlag(AccessMask.GENERIC_ALL)))
                 {
                     if (testConfig.Platform == Platform.NonWindows)
                     {
                         BaseTestSite.Assert.AreNotEqual(
                             Smb2Status.STATUS_SUCCESS,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "DesiredAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                     else if (testConfig.Platform == Platform.WindowsServer2008
                         || testConfig.Platform == Platform.WindowsServer2008R2)
                     {
                         //TD does not specify the behavior of windows 2008 and 2008R2, not check here
                     }
                     else if(testConfig.Platform == Platform.WindowsServer2012)
                     {
                         //For platform windows 2012
                         BaseTestSite.Assert.AreEqual(
                             Smb2Status.STATUS_INVALID_PARAMETER,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "DesiredAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                     else
                     {
                         //For platform windows 2012R2 and above
                         BaseTestSite.Assert.AreEqual(
                             Smb2Status.STATUS_ACCESS_DENIED,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "DesiredAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                 }
                 else if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) && isNonAdmin)
                 {
                     //NonAdminAccountCredential does not include DELETE or GENERIC_ALL in MaximalAccess
                     if (testConfig.Platform == Platform.NonWindows)
                     {
                         BaseTestSite.Assert.AreNotEqual(
                             Smb2Status.STATUS_SUCCESS,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                     else if (testConfig.Platform == Platform.WindowsServer2008
                         || testConfig.Platform == Platform.WindowsServer2008R2)
                     {
                         //TD does not specify te behavior of windows 2008 and 2008R2, not check here
                     }
                     else
                     {
                         //For platform win2012 and 2012R2
                         BaseTestSite.Assert.AreEqual(
                             Smb2Status.STATUS_ACCESS_DENIED,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                 }
                 else
                 {
                     BaseTestSite.Assert.AreEqual(
                         Smb2Status.STATUS_SUCCESS,
                         header.Status,
                         "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                 }
                 break;
             }
         case FileNameType.ExistedValidFileName:
             {
                 BaseTestSite.Assert.AreEqual(
                         Smb2Status.STATUS_SUCCESS,
                         header.Status,
                         "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
             }
             break;
         default:
             throw new ArgumentException("fileNameType");
     }
 }
        private void AsyncCreateRequest(Smb2FunctionalClient client, bool isDirectory, FileNameType fileNameType, CreateOptions_Values createOption,
                                        CreateDisposition_Values createDisposition, uint treeId, AccessMask accessMask, List <ulong> messageIdsList)
        {
            fileName = GetFileName(isDirectory, fileNameType);
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with create option: {0} and create disposition: {1}", createOption, createDisposition);

            Task <ulong> t1 = Task.Factory.StartNew(() => client.Create1(
                                                        treeId,
                                                        fileName,
                                                        createOption,
                                                        accessMask: accessMask,
                                                        createDisposition: createDisposition));

            //ulong msgId = client.Create1(
            //     treeId,
            //     fileName,
            //     createOption,
            //     accessMask: accessMask,
            //     createDisposition: createDisposition);

            //Task.Factory.StartNew(() => WaitForResponse(t1.Result, client));
            //t1.Wait();
            messageIdsList.Add(t1.Result);
        }