Repository: mina-sshd Updated Branches: refs/heads/master 91a721e94 -> 4039a11ae
[SSHD-427] Avoid duplicate SFTP protocol definitions Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/6debaf59 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/6debaf59 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/6debaf59 Branch: refs/heads/master Commit: 6debaf591d63bf352eef870b5e23840d15827a0d Parents: 91a721e Author: Guillaume Nodet <[email protected]> Authored: Tue Mar 17 12:04:15 2015 +0100 Committer: Guillaume Nodet <[email protected]> Committed: Tue Mar 17 12:05:04 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/sshd/client/SftpClient.java | 29 +-- .../sshd/client/sftp/DefaultSftpClient.java | 122 +--------- .../sshd/client/sftp/SftpFileChannel.java | 4 +- .../client/sftp/SftpFileSystemProvider.java | 20 +- .../apache/sshd/common/sftp/SftpConstants.java | 223 +++++++++++++++++++ .../apache/sshd/server/sftp/SftpSubsystem.java | 199 +---------------- .../src/test/java/org/apache/sshd/SftpTest.java | 18 +- 7 files changed, 267 insertions(+), 348 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java index 4001aaf..ce1b00e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java @@ -26,35 +26,16 @@ import java.util.Collection; import java.util.EnumSet; import java.util.concurrent.TimeUnit; +import static org.apache.sshd.common.sftp.SftpConstants.S_IFDIR; +import static org.apache.sshd.common.sftp.SftpConstants.S_IFLNK; +import static org.apache.sshd.common.sftp.SftpConstants.S_IFMT; +import static org.apache.sshd.common.sftp.SftpConstants.S_IFREG; + /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public interface SftpClient extends AutoCloseable { - // - // Permission flags - // - int S_IFMT = 0170000; // bitmask for the file type bitfields - int S_IFSOCK = 0140000; // socket - int S_IFLNK = 0120000; // symbolic link - int S_IFREG = 0100000; // regular file - int S_IFBLK = 0060000; // block device - int S_IFDIR = 0040000; // directory - int S_IFCHR = 0020000; // character device - int S_IFIFO = 0010000; // fifo - int S_ISUID = 0004000; // set UID bit - int S_ISGID = 0002000; // set GID bit - int S_ISVTX = 0001000; // sticky bit - int S_IRUSR = 0000400; - int S_IWUSR = 0000200; - int S_IXUSR = 0000100; - int S_IRGRP = 0000040; - int S_IWGRP = 0000020; - int S_IXGRP = 0000010; - int S_IROTH = 0000004; - int S_IWOTH = 0000002; - int S_IXOTH = 0000001; - enum OpenMode { Read, Write, http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java index a793cc6..99e60af 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java @@ -41,125 +41,13 @@ import org.apache.sshd.client.SftpException; import org.apache.sshd.client.channel.ChannelSubsystem; import org.apache.sshd.common.SshException; import org.apache.sshd.common.util.Buffer; -import org.apache.sshd.server.sftp.SftpSubsystem; + +import static org.apache.sshd.common.sftp.SftpConstants.*; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class DefaultSftpClient implements SftpClient { - - public static final int SSH_FXP_INIT = 1; - public static final int SSH_FXP_VERSION = 2; - public static final int SSH_FXP_OPEN = 3; - public static final int SSH_FXP_CLOSE = 4; - public static final int SSH_FXP_READ = 5; - public static final int SSH_FXP_WRITE = 6; - public static final int SSH_FXP_LSTAT = 7; - public static final int SSH_FXP_FSTAT = 8; - public static final int SSH_FXP_SETSTAT = 9; - public static final int SSH_FXP_FSETSTAT = 10; - public static final int SSH_FXP_OPENDIR = 11; - public static final int SSH_FXP_READDIR = 12; - public static final int SSH_FXP_REMOVE = 13; - public static final int SSH_FXP_MKDIR = 14; - public static final int SSH_FXP_RMDIR = 15; - public static final int SSH_FXP_REALPATH = 16; - public static final int SSH_FXP_STAT = 17; - public static final int SSH_FXP_RENAME = 18; - public static final int SSH_FXP_READLINK = 19; - public static final int SSH_FXP_SYMLINK = 20; - public static final int SSH_FXP_LINK = 21; // v6 - public static final int SSH_FXP_BLOCK = 22; // v6 - public static final int SSH_FXP_UNBLOCK = 23; // v6 - public static final int SSH_FXP_STATUS = 101; - public static final int SSH_FXP_HANDLE = 102; - public static final int SSH_FXP_DATA = 103; - public static final int SSH_FXP_NAME = 104; - public static final int SSH_FXP_ATTRS = 105; - public static final int SSH_FXP_EXTENDED = 200; - public static final int SSH_FXP_EXTENDED_REPLY = 201; - - public static final int SSH_FX_OK = 0; - public static final int SSH_FX_EOF = 1; - public static final int SSH_FX_NO_SUCH_FILE = 2; - public static final int SSH_FX_PERMISSION_DENIED = 3; - public static final int SSH_FX_FAILURE = 4; - public static final int SSH_FX_BAD_MESSAGE = 5; - public static final int SSH_FX_NO_CONNECTION = 6; - public static final int SSH_FX_CONNECTION_LOST = 7; - public static final int SSH_FX_OP_UNSUPPORTED = 8; - public static final int SSH_FX_FILE_ALREADY_EXISTS = 11; - public static final int SSH_FX_LOCK_CONFLICT = 17; - - public static final int SSH_FILEXFER_ATTR_SIZE = 0x00000001; - public static final int SSH_FILEXFER_ATTR_UIDGID = 0x00000002; - public static final int SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004; - public static final int SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008; // v3 naming convention - public static final int SSH_FILEXFER_ATTR_ACCESSTIME = 0x00000008; // v4 - public static final int SSH_FILEXFER_ATTR_CREATETIME = 0x00000010; // v4 - public static final int SSH_FILEXFER_ATTR_MODIFYTIME = 0x00000020; // v4 - public static final int SSH_FILEXFER_ATTR_ACL = 0x00000040; // v4 - public static final int SSH_FILEXFER_ATTR_OWNERGROUP = 0x00000080; // v4 - public static final int SSH_FILEXFER_ATTR_SUBSECOND_TIMES = 0x00000100; // v4 - public static final int SSH_FILEXFER_ATTR_EXTENDED = 0x80000000; - - public static final int SSH_FXF_READ = 0x00000001; - public static final int SSH_FXF_WRITE = 0x00000002; - public static final int SSH_FXF_APPEND = 0x00000004; - public static final int SSH_FXF_CREAT = 0x00000008; - public static final int SSH_FXF_TRUNC = 0x00000010; - public static final int SSH_FXF_EXCL = 0x00000020; - - public static final int SSH_FILEXFER_TYPE_REGULAR = 1; - public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2; - public static final int SSH_FILEXFER_TYPE_SYMLINK = 3; - public static final int SSH_FILEXFER_TYPE_SPECIAL = 4; - public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5; - public static final int SSH_FILEXFER_TYPE_SOCKET = 6; // v5 - public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7; // v5 - public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8; // v5 - public static final int SSH_FILEXFER_TYPE_FIFO = 9; // v5 - - public static final int SSH_FXF_ACCESS_DISPOSITION = 0x00000007; - public static final int SSH_FXF_CREATE_NEW = 0x00000000; - public static final int SSH_FXF_CREATE_TRUNCATE = 0x00000001; - public static final int SSH_FXF_OPEN_EXISTING = 0x00000002; - public static final int SSH_FXF_OPEN_OR_CREATE = 0x00000003; - public static final int SSH_FXF_TRUNCATE_EXISTING = 0x00000004; - public static final int SSH_FXF_APPEND_DATA = 0x00000008; - public static final int SSH_FXF_APPEND_DATA_ATOMIC = 0x00000010; - public static final int SSH_FXF_TEXT_MODE = 0x00000020; - public static final int SSH_FXF_READ_LOCK = 0x00000040; - public static final int SSH_FXF_WRITE_LOCK = 0x00000080; - public static final int SSH_FXF_DELETE_LOCK = 0x00000100; - - public static final int SSH_FXP_RENAME_OVERWRITE = 0x00000001; - public static final int SSH_FXP_RENAME_ATOMIC = 0x00000002; - public static final int SSH_FXP_RENAME_NATIVE = 0x00000004; - - public static final int ACE4_READ_DATA = 0x00000001; - public static final int ACE4_LIST_DIRECTORY = 0x00000001; - public static final int ACE4_WRITE_DATA = 0x00000002; - public static final int ACE4_ADD_FILE = 0x00000002; - public static final int ACE4_APPEND_DATA = 0x00000004; - public static final int ACE4_ADD_SUBDIRECTORY = 0x00000004; - public static final int ACE4_READ_NAMED_ATTRS = 0x00000008; - public static final int ACE4_WRITE_NAMED_ATTRS = 0x00000010; - public static final int ACE4_EXECUTE = 0x00000020; - public static final int ACE4_DELETE_CHILD = 0x00000040; - public static final int ACE4_READ_ATTRIBUTES = 0x00000080; - public static final int ACE4_WRITE_ATTRIBUTES = 0x00000100; - public static final int ACE4_DELETE = 0x00010000; - public static final int ACE4_READ_ACL = 0x00020000; - public static final int ACE4_WRITE_ACL = 0x00040000; - public static final int ACE4_WRITE_OWNER = 0x00080000; - public static final int ACE4_SYNCHRONIZE = 0x00100000; - - public static int SFTP_V3 = 3; - public static int SFTP_V4 = 4; - public static int SFTP_V5 = 5; - public static int SFTP_V6 = 6; - private final ClientSession clientSession; private final ChannelSubsystem channel; private final Map<Integer, Buffer> messages; @@ -837,7 +725,7 @@ public class DefaultSftpClient implements SftpClient { Buffer buffer = new Buffer(); buffer.putString(path); if (version >= SFTP_V4) { - buffer.putInt(SftpSubsystem.SSH_FILEXFER_ATTR_ALL); + buffer.putInt(SSH_FILEXFER_ATTR_ALL); } return checkAttributes(receive(send(SSH_FXP_STAT, buffer))); } @@ -846,7 +734,7 @@ public class DefaultSftpClient implements SftpClient { Buffer buffer = new Buffer(); buffer.putString(path); if (version >= SFTP_V4) { - buffer.putInt(SftpSubsystem.SSH_FILEXFER_ATTR_ALL); + buffer.putInt(SSH_FILEXFER_ATTR_ALL); } return checkAttributes(receive(send(SSH_FXP_LSTAT, buffer))); } @@ -855,7 +743,7 @@ public class DefaultSftpClient implements SftpClient { Buffer buffer = new Buffer(); buffer.putString(handle.id); if (version >= SFTP_V4) { - buffer.putInt(SftpSubsystem.SSH_FILEXFER_ATTR_ALL); + buffer.putInt(SSH_FILEXFER_ATTR_ALL); } return checkAttributes(receive(send(SSH_FXP_FSTAT, buffer))); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileChannel.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileChannel.java index 52a02d0..e599793 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileChannel.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileChannel.java @@ -37,6 +37,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.sshd.client.SftpClient; import org.apache.sshd.client.SftpException; +import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_LOCK_CONFLICT; + public class SftpFileChannel extends FileChannel { final SftpPath p; @@ -288,7 +290,7 @@ public class SftpFileChannel extends FileChannel { try { sftp.lock(handle, position, size, 0); } catch (SftpException e) { - if (e.getStatus() == DefaultSftpClient.SSH_FX_LOCK_CONFLICT) { + if (e.getStatus() == SSH_FX_LOCK_CONFLICT) { throw new OverlappingFileLockException(); } throw e; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java index c9f9a70..cc77055 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java @@ -65,11 +65,22 @@ import org.apache.sshd.ClientSession; import org.apache.sshd.SshBuilder; import org.apache.sshd.SshClient; import org.apache.sshd.client.SftpClient; +import org.apache.sshd.client.SftpClient.Attributes; import org.apache.sshd.client.SftpException; import org.apache.sshd.common.SshException; +import org.apache.sshd.common.sftp.SftpConstants; import org.apache.sshd.common.util.IoUtils; -import static org.apache.sshd.client.SftpClient.*; +import static org.apache.sshd.common.sftp.SftpConstants.SFTP_V3; +import static org.apache.sshd.common.sftp.SftpConstants.S_IRGRP; +import static org.apache.sshd.common.sftp.SftpConstants.S_IROTH; +import static org.apache.sshd.common.sftp.SftpConstants.S_IRUSR; +import static org.apache.sshd.common.sftp.SftpConstants.S_IWGRP; +import static org.apache.sshd.common.sftp.SftpConstants.S_IWOTH; +import static org.apache.sshd.common.sftp.SftpConstants.S_IWUSR; +import static org.apache.sshd.common.sftp.SftpConstants.S_IXGRP; +import static org.apache.sshd.common.sftp.SftpConstants.S_IXOTH; +import static org.apache.sshd.common.sftp.SftpConstants.S_IXUSR; public class SftpFileSystemProvider extends FileSystemProvider { @@ -220,7 +231,8 @@ public class SftpFileSystemProvider extends FileSystemProvider { try { sftp.mkdir(dir.toString()); } catch (SftpException e) { - if (sftp.getVersion() == 3 && e.getStatus() == DefaultSftpClient.SSH_FX_FAILURE) { + int sftpStatus=e.getStatus(); + if ((sftp.getVersion() == SFTP_V3) && (sftpStatus == SftpConstants.SSH_FX_FAILURE)) { try { Attributes attributes = sftp.stat(dir.toString()); if (attributes != null) { @@ -230,7 +242,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { e.addSuppressed(e2); } } - if (e.getStatus() == DefaultSftpClient.SSH_FX_FILE_ALREADY_EXISTS) { + if (sftpStatus == SftpConstants.SSH_FX_FILE_ALREADY_EXISTS) { throw new FileAlreadyExistsException(p.toString()); } throw e; @@ -463,7 +475,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { attributes = client.lstat(p.toString()); } } catch (SftpException e) { - if (e.getStatus() == DefaultSftpClient.SSH_FX_NO_SUCH_FILE) { + if (e.getStatus() == SftpConstants.SSH_FX_NO_SUCH_FILE) { throw new NoSuchFileException(p.toString()); } throw e; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/main/java/org/apache/sshd/common/sftp/SftpConstants.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/sftp/SftpConstants.java b/sshd-core/src/main/java/org/apache/sshd/common/sftp/SftpConstants.java new file mode 100644 index 0000000..80d0667 --- /dev/null +++ b/sshd-core/src/main/java/org/apache/sshd/common/sftp/SftpConstants.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sshd.common.sftp; + +/** + * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> + */ +public class SftpConstants { + + public static final int SSH_FXP_INIT = 1; + public static final int SSH_FXP_VERSION = 2; + public static final int SSH_FXP_OPEN = 3; + public static final int SSH_FXP_CLOSE = 4; + public static final int SSH_FXP_READ = 5; + public static final int SSH_FXP_WRITE = 6; + public static final int SSH_FXP_LSTAT = 7; + public static final int SSH_FXP_FSTAT = 8; + public static final int SSH_FXP_SETSTAT = 9; + public static final int SSH_FXP_FSETSTAT = 10; + public static final int SSH_FXP_OPENDIR = 11; + public static final int SSH_FXP_READDIR = 12; + public static final int SSH_FXP_REMOVE = 13; + public static final int SSH_FXP_MKDIR = 14; + public static final int SSH_FXP_RMDIR = 15; + public static final int SSH_FXP_REALPATH = 16; + public static final int SSH_FXP_STAT = 17; + public static final int SSH_FXP_RENAME = 18; + public static final int SSH_FXP_READLINK = 19; + public static final int SSH_FXP_SYMLINK = 20; // v3 -> v5 + public static final int SSH_FXP_LINK = 21; // v6 + public static final int SSH_FXP_BLOCK = 22; // v6 + public static final int SSH_FXP_UNBLOCK = 23; // v6 + public static final int SSH_FXP_STATUS = 101; + public static final int SSH_FXP_HANDLE = 102; + public static final int SSH_FXP_DATA = 103; + public static final int SSH_FXP_NAME = 104; + public static final int SSH_FXP_ATTRS = 105; + public static final int SSH_FXP_EXTENDED = 200; + public static final int SSH_FXP_EXTENDED_REPLY = 201; + + public static final int SSH_FX_OK = 0; + public static final int SSH_FX_EOF = 1; + public static final int SSH_FX_NO_SUCH_FILE = 2; + public static final int SSH_FX_PERMISSION_DENIED = 3; + public static final int SSH_FX_FAILURE = 4; + public static final int SSH_FX_BAD_MESSAGE = 5; + public static final int SSH_FX_NO_CONNECTION = 6; + public static final int SSH_FX_CONNECTION_LOST = 7; + public static final int SSH_FX_OP_UNSUPPORTED = 8; + public static final int SSH_FX_INVALID_HANDLE = 9; + public static final int SSH_FX_NO_SUCH_PATH = 10; + public static final int SSH_FX_FILE_ALREADY_EXISTS = 11; + public static final int SSH_FX_WRITE_PROTECT = 12; + public static final int SSH_FX_NO_MEDIA = 13; + public static final int SSH_FX_NO_SPACE_ON_FILESYSTEM = 14; + public static final int SSH_FX_QUOTA_EXCEEDED = 15; + public static final int SSH_FX_UNKNOWN_PRINCIPLE = 16; + public static final int SSH_FX_LOCK_CONFLICT = 17; + public static final int SSH_FX_DIR_NOT_EMPTY = 18; + public static final int SSH_FX_NOT_A_DIRECTORY = 19; + public static final int SSH_FX_INVALID_FILENAME = 20; + public static final int SSH_FX_LINK_LOOP = 21; + public static final int SSH_FX_CANNOT_DELETE = 22; + public static final int SSH_FX_INVALID_PARAMETER = 23; + public static final int SSH_FX_FILE_IS_A_DIRECTORY = 24; + public static final int SSH_FX_BYTE_RANGE_LOCK_CONFLICT = 25; + public static final int SSH_FX_BYTE_RANGE_LOCK_REFUSED = 26; + public static final int SSH_FX_DELETE_PENDING = 27; + public static final int SSH_FX_FILE_CORRUPT = 28; + public static final int SSH_FX_OWNER_INVALID = 29; + public static final int SSH_FX_GROUP_INVALID = 30; + public static final int SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK = 31; + + public static final int SSH_FILEXFER_ATTR_SIZE = 0x00000001; + public static final int SSH_FILEXFER_ATTR_UIDGID = 0x00000002; + public static final int SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004; + public static final int SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008; // v3 naming convention + public static final int SSH_FILEXFER_ATTR_ACCESSTIME = 0x00000008; // v4 + public static final int SSH_FILEXFER_ATTR_CREATETIME = 0x00000010; // v4 + public static final int SSH_FILEXFER_ATTR_MODIFYTIME = 0x00000020; // v4 + public static final int SSH_FILEXFER_ATTR_ACL = 0x00000040; // v4 + public static final int SSH_FILEXFER_ATTR_OWNERGROUP = 0x00000080; // v4 + public static final int SSH_FILEXFER_ATTR_SUBSECOND_TIMES = 0x00000100; // v5 + public static final int SSH_FILEXFER_ATTR_BITS = 0x00000200; // v5 + public static final int SSH_FILEXFER_ATTR_ALLOCATION_SIZE = 0x00000400; // v6 + public static final int SSH_FILEXFER_ATTR_TEXT_HINT = 0x00000800; // v6 + public static final int SSH_FILEXFER_ATTR_MIME_TYPE = 0x00001000; // v6 + public static final int SSH_FILEXFER_ATTR_LINK_COUNT = 0x00002000; // v6 + public static final int SSH_FILEXFER_ATTR_UNTRANSLATED_NAME = 0x00004000; // v6 + public static final int SSH_FILEXFER_ATTR_CTIME = 0x00008000; // v6 + public static final int SSH_FILEXFER_ATTR_EXTENDED = 0x80000000; + + public static final int SSH_FILEXFER_ATTR_ALL = 0x0000FFFF; // All attributes + + public static final int SSH_FILEXFER_ATTR_FLAGS_READONLY = 0x00000001; + public static final int SSH_FILEXFER_ATTR_FLAGS_SYSTEM = 0x00000002; + public static final int SSH_FILEXFER_ATTR_FLAGS_HIDDEN = 0x00000004; + public static final int SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE = 0x00000008; + public static final int SSH_FILEXFER_ATTR_FLAGS_ARCHIVE = 0x00000010; + public static final int SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED = 0x00000020; + public static final int SSH_FILEXFER_ATTR_FLAGS_COMPRESSED = 0x00000040; + public static final int SSH_FILEXFER_ATTR_FLAGS_SPARSE = 0x00000080; + public static final int SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY = 0x00000100; + public static final int SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE = 0x00000200; + public static final int SSH_FILEXFER_ATTR_FLAGS_SYNC = 0x00000400; + + public static final int SSH_FILEXFER_TYPE_REGULAR = 1; + public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2; + public static final int SSH_FILEXFER_TYPE_SYMLINK = 3; + public static final int SSH_FILEXFER_TYPE_SPECIAL = 4; + public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5; + public static final int SSH_FILEXFER_TYPE_SOCKET = 6; // v5 + public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7; // v5 + public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8; // v5 + public static final int SSH_FILEXFER_TYPE_FIFO = 9; // v5 + + public static final int SSH_FXF_READ = 0x00000001; + public static final int SSH_FXF_WRITE = 0x00000002; + public static final int SSH_FXF_APPEND = 0x00000004; + public static final int SSH_FXF_CREAT = 0x00000008; + public static final int SSH_FXF_TRUNC = 0x00000010; + public static final int SSH_FXF_EXCL = 0x00000020; + public static final int SSH_FXF_TEXT = 0x00000040; + + public static final int SSH_FXF_ACCESS_DISPOSITION = 0x00000007; + public static final int SSH_FXF_CREATE_NEW = 0x00000000; + public static final int SSH_FXF_CREATE_TRUNCATE = 0x00000001; + public static final int SSH_FXF_OPEN_EXISTING = 0x00000002; + public static final int SSH_FXF_OPEN_OR_CREATE = 0x00000003; + public static final int SSH_FXF_TRUNCATE_EXISTING = 0x00000004; + public static final int SSH_FXF_APPEND_DATA = 0x00000008; + public static final int SSH_FXF_APPEND_DATA_ATOMIC = 0x00000010; + public static final int SSH_FXF_TEXT_MODE = 0x00000020; + public static final int SSH_FXF_READ_LOCK = 0x00000040; + public static final int SSH_FXF_WRITE_LOCK = 0x00000080; + public static final int SSH_FXF_DELETE_LOCK = 0x00000100; + + public static final int SSH_FXP_RENAME_OVERWRITE = 0x00000001; + public static final int SSH_FXP_RENAME_ATOMIC = 0x00000002; + public static final int SSH_FXP_RENAME_NATIVE = 0x00000004; + + public static final int SSH_FXP_REALPATH_NO_CHECK = 0x00000001; + public static final int SSH_FXP_REALPATH_STAT_IF = 0x00000002; + public static final int SSH_FXP_REALPATH_STAT_ALWAYS = 0x00000003; + + public static final int SSH_FXF_RENAME_OVERWRITE = 0x00000001; + public static final int SSH_FXF_RENAME_ATOMIC = 0x00000002; + public static final int SSH_FXF_RENAME_NATIVE = 0x00000004; + + public static final int ACE4_ACCESS_ALLOWED_ACE_TYPE = 0x00000000; + public static final int ACE4_ACCESS_DENIED_ACE_TYPE = 0x00000001; + public static final int ACE4_SYSTEM_AUDIT_ACE_TYPE = 0x00000002; + public static final int ACE4_SYSTEM_ALARM_ACE_TYPE = 0x00000003; + + public static final int ACE4_FILE_INHERIT_ACE = 0x00000001; + public static final int ACE4_DIRECTORY_INHERIT_ACE = 0x00000002; + public static final int ACE4_NO_PROPAGATE_INHERIT_ACE = 0x00000004; + public static final int ACE4_INHERIT_ONLY_ACE = 0x00000008; + public static final int ACE4_SUCCESSFUL_ACCESS_ACE_FLAG = 0x00000010; + public static final int ACE4_FAILED_ACCESS_ACE_FLAG = 0x00000020; + public static final int ACE4_IDENTIFIER_GROUP = 0x00000040; + + public static final int ACE4_READ_DATA = 0x00000001; + public static final int ACE4_LIST_DIRECTORY = 0x00000001; + public static final int ACE4_WRITE_DATA = 0x00000002; + public static final int ACE4_ADD_FILE = 0x00000002; + public static final int ACE4_APPEND_DATA = 0x00000004; + public static final int ACE4_ADD_SUBDIRECTORY = 0x00000004; + public static final int ACE4_READ_NAMED_ATTRS = 0x00000008; + public static final int ACE4_WRITE_NAMED_ATTRS = 0x00000010; + public static final int ACE4_EXECUTE = 0x00000020; + public static final int ACE4_DELETE_CHILD = 0x00000040; + public static final int ACE4_READ_ATTRIBUTES = 0x00000080; + public static final int ACE4_WRITE_ATTRIBUTES = 0x00000100; + public static final int ACE4_DELETE = 0x00010000; + public static final int ACE4_READ_ACL = 0x00020000; + public static final int ACE4_WRITE_ACL = 0x00040000; + public static final int ACE4_WRITE_OWNER = 0x00080000; + public static final int ACE4_SYNCHRONIZE = 0x00100000; + + public static final int S_IFMT = 0170000; // bitmask for the file type bitfields + public static final int S_IFSOCK = 0140000; // socket + public static final int S_IFLNK = 0120000; // symbolic link + public static final int S_IFREG = 0100000; // regular file + public static final int S_IFBLK = 0060000; // block device + public static final int S_IFDIR = 0040000; // directory + public static final int S_IFCHR = 0020000; // character device + public static final int S_IFIFO = 0010000; // fifo + public static final int S_ISUID = 0004000; // set UID bit + public static final int S_ISGID = 0002000; // set GID bit + public static final int S_ISVTX = 0001000; // sticky bit + public static final int S_IRUSR = 0000400; + public static final int S_IWUSR = 0000200; + public static final int S_IXUSR = 0000100; + public static final int S_IRGRP = 0000040; + public static final int S_IWGRP = 0000020; + public static final int S_IXGRP = 0000010; + public static final int S_IROTH = 0000004; + public static final int S_IWOTH = 0000002; + public static final int S_IXOTH = 0000001; + + public static int SFTP_V3 = 3; + public static int SFTP_V4 = 4; + public static int SFTP_V5 = 5; + public static int SFTP_V6 = 6; + +} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java index 16fc902..721fe8a 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java @@ -90,6 +90,8 @@ import org.apache.sshd.server.session.ServerSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.sshd.common.sftp.SftpConstants.*; + /** * SFTP subsystem * @@ -174,203 +176,6 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste public static final String ALL_SFTP_IMPL = "3,4,5,6"; public static final int MAX_PACKET_LENGTH = 1024 * 16; - public static final int SSH_FXP_INIT = 1; - public static final int SSH_FXP_VERSION = 2; - public static final int SSH_FXP_OPEN = 3; - public static final int SSH_FXP_CLOSE = 4; - public static final int SSH_FXP_READ = 5; - public static final int SSH_FXP_WRITE = 6; - public static final int SSH_FXP_LSTAT = 7; - public static final int SSH_FXP_FSTAT = 8; - public static final int SSH_FXP_SETSTAT = 9; - public static final int SSH_FXP_FSETSTAT = 10; - public static final int SSH_FXP_OPENDIR = 11; - public static final int SSH_FXP_READDIR = 12; - public static final int SSH_FXP_REMOVE = 13; - public static final int SSH_FXP_MKDIR = 14; - public static final int SSH_FXP_RMDIR = 15; - public static final int SSH_FXP_REALPATH = 16; - public static final int SSH_FXP_STAT = 17; - public static final int SSH_FXP_RENAME = 18; - public static final int SSH_FXP_READLINK = 19; - public static final int SSH_FXP_SYMLINK = 20; // v3 -> v5 - public static final int SSH_FXP_LINK = 21; // v6 - public static final int SSH_FXP_BLOCK = 22; // v6 - public static final int SSH_FXP_UNBLOCK = 23; // v6 - public static final int SSH_FXP_STATUS = 101; - public static final int SSH_FXP_HANDLE = 102; - public static final int SSH_FXP_DATA = 103; - public static final int SSH_FXP_NAME = 104; - public static final int SSH_FXP_ATTRS = 105; - public static final int SSH_FXP_EXTENDED = 200; - public static final int SSH_FXP_EXTENDED_REPLY = 201; - - public static final int SSH_FX_OK = 0; - public static final int SSH_FX_EOF = 1; - public static final int SSH_FX_NO_SUCH_FILE = 2; - public static final int SSH_FX_PERMISSION_DENIED = 3; - public static final int SSH_FX_FAILURE = 4; - public static final int SSH_FX_BAD_MESSAGE = 5; - public static final int SSH_FX_NO_CONNECTION = 6; - public static final int SSH_FX_CONNECTION_LOST = 7; - public static final int SSH_FX_OP_UNSUPPORTED = 8; - public static final int SSH_FX_INVALID_HANDLE = 9; - public static final int SSH_FX_NO_SUCH_PATH = 10; - public static final int SSH_FX_FILE_ALREADY_EXISTS = 11; - public static final int SSH_FX_WRITE_PROTECT = 12; - public static final int SSH_FX_NO_MEDIA = 13; - public static final int SSH_FX_NO_SPACE_ON_FILESYSTEM = 14; - public static final int SSH_FX_QUOTA_EXCEEDED = 15; - public static final int SSH_FX_UNKNOWN_PRINCIPLE = 16; - public static final int SSH_FX_LOCK_CONFLICT = 17; - public static final int SSH_FX_DIR_NOT_EMPTY = 18; - public static final int SSH_FX_NOT_A_DIRECTORY = 19; - public static final int SSH_FX_INVALID_FILENAME = 20; - public static final int SSH_FX_LINK_LOOP = 21; - public static final int SSH_FX_CANNOT_DELETE = 22; - public static final int SSH_FX_INVALID_PARAMETER = 23; - public static final int SSH_FX_FILE_IS_A_DIRECTORY = 24; - public static final int SSH_FX_BYTE_RANGE_LOCK_CONFLICT = 25; - public static final int SSH_FX_BYTE_RANGE_LOCK_REFUSED = 26; - public static final int SSH_FX_DELETE_PENDING = 27; - public static final int SSH_FX_FILE_CORRUPT = 28; - public static final int SSH_FX_OWNER_INVALID = 29; - public static final int SSH_FX_GROUP_INVALID = 30; - public static final int SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK = 31; - - public static final int SSH_FILEXFER_ATTR_SIZE = 0x00000001; - public static final int SSH_FILEXFER_ATTR_UIDGID = 0x00000002; - public static final int SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004; - public static final int SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008; // v3 naming convention - public static final int SSH_FILEXFER_ATTR_ACCESSTIME = 0x00000008; // v4 - public static final int SSH_FILEXFER_ATTR_CREATETIME = 0x00000010; // v4 - public static final int SSH_FILEXFER_ATTR_MODIFYTIME = 0x00000020; // v4 - public static final int SSH_FILEXFER_ATTR_ACL = 0x00000040; // v4 - public static final int SSH_FILEXFER_ATTR_OWNERGROUP = 0x00000080; // v4 - public static final int SSH_FILEXFER_ATTR_SUBSECOND_TIMES = 0x00000100; // v5 - public static final int SSH_FILEXFER_ATTR_BITS = 0x00000200; // v5 - public static final int SSH_FILEXFER_ATTR_ALLOCATION_SIZE = 0x00000400; // v6 - public static final int SSH_FILEXFER_ATTR_TEXT_HINT = 0x00000800; // v6 - public static final int SSH_FILEXFER_ATTR_MIME_TYPE = 0x00001000; // v6 - public static final int SSH_FILEXFER_ATTR_LINK_COUNT = 0x00002000; // v6 - public static final int SSH_FILEXFER_ATTR_UNTRANSLATED_NAME = 0x00004000; // v6 - public static final int SSH_FILEXFER_ATTR_CTIME = 0x00008000; // v6 - public static final int SSH_FILEXFER_ATTR_EXTENDED = 0x80000000; - - public static final int SSH_FILEXFER_ATTR_ALL = 0x0000FFFF; // All attributes - - public static final int SSH_FILEXFER_ATTR_FLAGS_READONLY = 0x00000001; - public static final int SSH_FILEXFER_ATTR_FLAGS_SYSTEM = 0x00000002; - public static final int SSH_FILEXFER_ATTR_FLAGS_HIDDEN = 0x00000004; - public static final int SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE = 0x00000008; - public static final int SSH_FILEXFER_ATTR_FLAGS_ARCHIVE = 0x00000010; - public static final int SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED = 0x00000020; - public static final int SSH_FILEXFER_ATTR_FLAGS_COMPRESSED = 0x00000040; - public static final int SSH_FILEXFER_ATTR_FLAGS_SPARSE = 0x00000080; - public static final int SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY = 0x00000100; - public static final int SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE = 0x00000200; - public static final int SSH_FILEXFER_ATTR_FLAGS_SYNC = 0x00000400; - - public static final int SSH_FILEXFER_TYPE_REGULAR = 1; - public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2; - public static final int SSH_FILEXFER_TYPE_SYMLINK = 3; - public static final int SSH_FILEXFER_TYPE_SPECIAL = 4; - public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5; - public static final int SSH_FILEXFER_TYPE_SOCKET = 6; // v5 - public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7; // v5 - public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8; // v5 - public static final int SSH_FILEXFER_TYPE_FIFO = 9; // v5 - - public static final int SSH_FXF_READ = 0x00000001; - public static final int SSH_FXF_WRITE = 0x00000002; - public static final int SSH_FXF_APPEND = 0x00000004; - public static final int SSH_FXF_CREAT = 0x00000008; - public static final int SSH_FXF_TRUNC = 0x00000010; - public static final int SSH_FXF_EXCL = 0x00000020; - public static final int SSH_FXF_TEXT = 0x00000040; - - public static final int SSH_FXF_ACCESS_DISPOSITION = 0x00000007; - public static final int SSH_FXF_CREATE_NEW = 0x00000000; - public static final int SSH_FXF_CREATE_TRUNCATE = 0x00000001; - public static final int SSH_FXF_OPEN_EXISTING = 0x00000002; - public static final int SSH_FXF_OPEN_OR_CREATE = 0x00000003; - public static final int SSH_FXF_TRUNCATE_EXISTING = 0x00000004; - public static final int SSH_FXF_APPEND_DATA = 0x00000008; - public static final int SSH_FXF_APPEND_DATA_ATOMIC = 0x00000010; - public static final int SSH_FXF_TEXT_MODE = 0x00000020; - public static final int SSH_FXF_READ_LOCK = 0x00000040; - public static final int SSH_FXF_WRITE_LOCK = 0x00000080; - public static final int SSH_FXF_DELETE_LOCK = 0x00000100; - - public static final int SSH_FXP_RENAME_OVERWRITE = 0x00000001; - public static final int SSH_FXP_RENAME_ATOMIC = 0x00000002; - public static final int SSH_FXP_RENAME_NATIVE = 0x00000004; - - public static final int SSH_FXP_REALPATH_NO_CHECK = 0x00000001; - public static final int SSH_FXP_REALPATH_STAT_IF = 0x00000002; - public static final int SSH_FXP_REALPATH_STAT_ALWAYS = 0x00000003; - - public static final int SSH_FXF_RENAME_OVERWRITE = 0x00000001; - public static final int SSH_FXF_RENAME_ATOMIC = 0x00000002; - public static final int SSH_FXF_RENAME_NATIVE = 0x00000004; - - public static final int ACE4_ACCESS_ALLOWED_ACE_TYPE = 0x00000000; - public static final int ACE4_ACCESS_DENIED_ACE_TYPE = 0x00000001; - public static final int ACE4_SYSTEM_AUDIT_ACE_TYPE = 0x00000002; - public static final int ACE4_SYSTEM_ALARM_ACE_TYPE = 0x00000003; - - public static final int ACE4_FILE_INHERIT_ACE = 0x00000001; - public static final int ACE4_DIRECTORY_INHERIT_ACE = 0x00000002; - public static final int ACE4_NO_PROPAGATE_INHERIT_ACE = 0x00000004; - public static final int ACE4_INHERIT_ONLY_ACE = 0x00000008; - public static final int ACE4_SUCCESSFUL_ACCESS_ACE_FLAG = 0x00000010; - public static final int ACE4_FAILED_ACCESS_ACE_FLAG = 0x00000020; - public static final int ACE4_IDENTIFIER_GROUP = 0x00000040; - - public static final int ACE4_READ_DATA = 0x00000001; - public static final int ACE4_LIST_DIRECTORY = 0x00000001; - public static final int ACE4_WRITE_DATA = 0x00000002; - public static final int ACE4_ADD_FILE = 0x00000002; - public static final int ACE4_APPEND_DATA = 0x00000004; - public static final int ACE4_ADD_SUBDIRECTORY = 0x00000004; - public static final int ACE4_READ_NAMED_ATTRS = 0x00000008; - public static final int ACE4_WRITE_NAMED_ATTRS = 0x00000010; - public static final int ACE4_EXECUTE = 0x00000020; - public static final int ACE4_DELETE_CHILD = 0x00000040; - public static final int ACE4_READ_ATTRIBUTES = 0x00000080; - public static final int ACE4_WRITE_ATTRIBUTES = 0x00000100; - public static final int ACE4_DELETE = 0x00010000; - public static final int ACE4_READ_ACL = 0x00020000; - public static final int ACE4_WRITE_ACL = 0x00040000; - public static final int ACE4_WRITE_OWNER = 0x00080000; - public static final int ACE4_SYNCHRONIZE = 0x00100000; - - public static final int S_IFMT = 0170000; // bitmask for the file type bitfields - public static final int S_IFSOCK = 0140000; // socket - public static final int S_IFLNK = 0120000; // symbolic link - public static final int S_IFREG = 0100000; // regular file - public static final int S_IFBLK = 0060000; // block device - public static final int S_IFDIR = 0040000; // directory - public static final int S_IFCHR = 0020000; // character device - public static final int S_IFIFO = 0010000; // fifo - public static final int S_ISUID = 0004000; // set UID bit - public static final int S_ISGID = 0002000; // set GID bit - public static final int S_ISVTX = 0001000; // sticky bit - public static final int S_IRUSR = 0000400; - public static final int S_IWUSR = 0000200; - public static final int S_IXUSR = 0000100; - public static final int S_IRGRP = 0000040; - public static final int S_IWGRP = 0000020; - public static final int S_IXGRP = 0000010; - public static final int S_IROTH = 0000004; - public static final int S_IWOTH = 0000002; - public static final int S_IXOTH = 0000001; - - public static int SFTP_V3 = 3; - public static int SFTP_V4 = 4; - public static int SFTP_V5 = 5; - public static int SFTP_V6 = 6; - private ExitCallback callback; private InputStream in; private OutputStream out; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6debaf59/sshd-core/src/test/java/org/apache/sshd/SftpTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java index 78cb70a..e39bd57 100644 --- a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java @@ -33,7 +33,6 @@ import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; import com.jcraft.jsch.SftpException; import org.apache.sshd.client.SftpClient; -import org.apache.sshd.client.sftp.DefaultSftpClient; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.util.Buffer; import org.apache.sshd.common.util.OsUtils; @@ -52,7 +51,16 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; +import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_FILE_ALREADY_EXISTS; +import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_NO_SUCH_FILE; +import static org.apache.sshd.common.sftp.SftpConstants.S_IRUSR; +import static org.apache.sshd.common.sftp.SftpConstants.S_IWUSR; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class SftpTest extends BaseTest { @@ -143,7 +151,7 @@ public class SftpTest extends BaseTest { // NOTE: on Windows files are always readable int perms=sftp.stat(file).perms; - int permsMask=SftpClient.S_IWUSR | (isWindows ? 0 : SftpClient.S_IRUSR); + int permsMask=S_IWUSR | (isWindows ? 0 : S_IRUSR); Assert.assertEquals("Mismatched permissions - 0x" + Integer.toHexString(perms), 0, (perms & permsMask)); javaFile.setWritable(true, false); @@ -474,7 +482,7 @@ public class SftpTest extends BaseTest { sftp.rename("target/sftp/test2.txt", "target/sftp/test3.txt"); fail("Expected an SftpException"); } catch (org.apache.sshd.client.SftpException e) { - assertEquals(DefaultSftpClient.SSH_FX_NO_SUCH_FILE, e.getStatus()); + assertEquals(SSH_FX_NO_SUCH_FILE, e.getStatus()); } try (OutputStream os = sftp.write("target/sftp/test2.txt")) { @@ -485,7 +493,7 @@ public class SftpTest extends BaseTest { sftp.rename("target/sftp/test.txt", "target/sftp/test2.txt"); fail("Expected an SftpException"); } catch (org.apache.sshd.client.SftpException e) { - assertEquals(DefaultSftpClient.SSH_FX_FILE_ALREADY_EXISTS, e.getStatus()); + assertEquals(SSH_FX_FILE_ALREADY_EXISTS, e.getStatus()); } sftp.rename("target/sftp/test.txt", "target/sftp/test2.txt", SftpClient.CopyMode.Overwrite); }
