private ISMBClient GetConnection(SmbType smbType) { var result = (smbType == SmbType.Smb1) ? (ISMBClient) new SMB1Client() : (ISMBClient) new SMB2Client(); return(result.Connect(this._pathSet.IpAddress, SMBTransportType.DirectTCPTransport) ? result : null); }
internal static FixedParamSet Parse( ParamSet paramSet, SmbType smbType ) { if (paramSet == null) { throw new ArgumentException("Required paramSet."); } return(new FixedParamSet() { UserName = paramSet.UserName ?? string.Empty, Password = paramSet.Password ?? string.Empty, DomainName = paramSet.DomainName ?? string.Empty, SmbType = smbType }); }
public HandlerBase( SmbType smbType, ISMBFileStore store, string path, HandleType handleType, NodeType nodeType ) { this.Handle = null; this.Succeeded = false; if (store == null || nodeType == NodeType.Server) { return; } this._store = store; var args = handleType.ToArgs(smbType, nodeType); var status = this._store.CreateFile( out var handle, out var handleStatus, path, args.AccessMask, args.FileAttributes, args.ShareAccess, args.CreateDisposition, args.CreateOptions, null ); if (status == NTStatus.STATUS_SUCCESS) { this.Handle = handle; this.FileStatus = handleStatus; this.Succeeded = true; } }
public static HandleArgs ToArgs( this HandleType handleType, SmbType smbType, NodeType nodeType ) { if (nodeType == NodeType.Server) { throw new ArgumentException("NodeType.Server Not Supported."); } var result = new HandleArgs() { FileAttributes = (handleType == HandleType.Move) // !! INPORTANT !! Move(=Rename) to 0. ? 0 // else, file or directory : ((nodeType == NodeType.File) ? FileAttributes.Normal : FileAttributes.Directory), CreateOptions = (nodeType == NodeType.File) ? CreateOptions.FILE_NON_DIRECTORY_FILE : CreateOptions.FILE_DIRECTORY_FILE }; if (smbType == SmbType.Smb2) { result.CreateOptions |= CreateOptions.FILE_SYNCHRONOUS_IO_ALERT; } switch (handleType) { case HandleType.Read: result.AccessMask = AccessMask.GENERIC_READ | AccessMask.SYNCHRONIZE; result.ShareAccess = ShareAccess.Read | ShareAccess.Write; result.CreateDisposition = CreateDisposition.FILE_OPEN; break; case HandleType.Write: result.AccessMask = AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE; result.ShareAccess = ShareAccess.None; // * Create directory fail if exists. result.CreateDisposition = (nodeType == NodeType.File) ? CreateDisposition.FILE_SUPERSEDE : CreateDisposition.FILE_CREATE; break; case HandleType.Delete: // AccessMask.GENERIC_ALL is failed in SMB1. result.AccessMask = AccessMask.GENERIC_WRITE | AccessMask.DELETE | AccessMask.SYNCHRONIZE; result.ShareAccess = ShareAccess.None; result.CreateDisposition = CreateDisposition.FILE_OPEN; break; case HandleType.Move: // AccessMask.GENERIC_WRITE is failed in SMB2. Reqired GENERIC_ALL. result.AccessMask = AccessMask.GENERIC_ALL | AccessMask.SYNCHRONIZE; result.ShareAccess = ShareAccess.Read; result.CreateDisposition = CreateDisposition.FILE_OPEN; break; default: throw new ArgumentException($"Unexpected HandleType: {handleType}"); } return(result); }