Ejemplo n.º 1
0
        private string GetFileName(CreateFileNameType fileNameType)
        {
            string fileName;

            switch (fileNameType)
            {
            case CreateFileNameType.StartWithPathSeparator:
                fileName = testConfig.PathSeparator + "CreateClose" + Guid.NewGuid();
                break;

            case CreateFileNameType.OtherInvalidFileName:
                // [MS-FSCC] Section 2.1.5.2   Filename
                // All Unicode characters are legal in a filename except the following:
                // The characters
                // " \ / : | < > * ?
                // Control characters, ranging from 0x00 through 0x1F.
                fileName = "*" + "CreateClose" + Guid.NewGuid();
                break;

            case CreateFileNameType.ValidFileName:
                fileName = "CreateClose" + Guid.NewGuid();
                break;

            default:
                throw new ArgumentException("fileNameType");
            }

            return(fileName);
        }
Ejemplo n.º 2
0
 public ModelCreateRequest(
     CreateFileNameType nameType,
     CreateOptionsFileOpenReparsePointType fileOpenReparsePointType,
     CreateOptionsFileDeleteOnCloseType fileDeleteOnCloseType,
     CreateContextType contextType,
     ImpersonationLevelType impersonationType) : base(0)
 {
     NameType = nameType;
     FileOpenReparsePointType = fileOpenReparsePointType;
     FileDeleteOnCloseType    = fileDeleteOnCloseType;
     ContextType       = contextType;
     ImpersonationType = impersonationType;
 }
Ejemplo n.º 3
0
        public static void CreateRequest(
            CreateFileNameType fileNameType,
            CreateOptionsFileOpenReparsePointType fileOpenReparsePointType,
            CreateOptionsFileDeleteOnCloseType fileDeleteOnCloseType,
            CreateContextType contextType,
            ImpersonationLevelType impersonationType,
            CreateFileType fileType)
        {
            Condition.IsTrue(State == ModelState.Connected);
            Condition.IsNull(Request);

            Combination.Isolated(fileNameType == CreateFileNameType.StartWithPathSeparator);
            Combination.Isolated(fileNameType == CreateFileNameType.OtherInvalidFileName);

            // Reduce expanded cases
            Combination.Pairwise(fileNameType, fileOpenReparsePointType, fileDeleteOnCloseType, contextType, impersonationType, fileType);

            Combination.Isolated(contextType == CreateContextType.InvalidCreateContext);
            Combination.Isolated(contextType == CreateContextType.InvalidCreateContextSize);
            Combination.Isolated(impersonationType == ImpersonationLevelType.InvalidImpersonationLevel);


            Request = new ModelCreateRequest(fileNameType, fileOpenReparsePointType, fileDeleteOnCloseType, contextType, impersonationType);
        }
 public ModelCreateRequest(
     CreateFileNameType nameType,
     CreateOptionsFileOpenReparsePointType fileOpenReparsePointType,
     CreateOptionsFileDeleteOnCloseType fileDeleteOnCloseType,
     CreateContextType contextType,
     ImpersonationLevelType impersonationType)
     : base(0)
 {
     NameType = nameType;
     FileOpenReparsePointType = fileOpenReparsePointType;
     FileDeleteOnCloseType = fileDeleteOnCloseType;
     ContextType = contextType;
     ImpersonationType = impersonationType;
 }
Ejemplo n.º 5
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);
        }
        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);
        }
        private string GetFileName(CreateFileNameType fileNameType)
        {
            string fileName;
            switch (fileNameType)
            {
                case CreateFileNameType.StartWithPathSeparator:
                    fileName = testConfig.PathSeparator + "CreateClose" + Guid.NewGuid();
                    break;
                case CreateFileNameType.OtherInvalidFileName:
                    // [MS-FSCC] Section 2.1.5.2   Filename
                    // All Unicode characters are legal in a filename except the following:
                    // The characters
                    // " \ / : | < > * ?
                    // Control characters, ranging from 0x00 through 0x1F.
                    fileName = "*" + "CreateClose" + Guid.NewGuid();
                    break;
                case CreateFileNameType.ValidFileName:
                    fileName = "CreateClose" + Guid.NewGuid();
                    break;
                default:
                    throw new ArgumentException("fileNameType");
            }

            return fileName;
        }