Ticket #2902: blargh.2.diff

File blargh.2.diff, 5.6 KB (added by Michael Hudson-Doyle, 13 years ago)
  • twisted/conch/test/test_filetransfer.py

     
    44
    55
    66import os
     7import re
    78import struct
    89import sys
    910
     
    2526from twisted.internet import defer
    2627from twisted.protocols import loopback
    2728from twisted.python import components
     29from twisted.python.util import sibpath
    2830
    2931
    3032class TestAvatar(avatar.ConchUser):
     
    569571        conn.serviceStopped()
    570572
    571573        self.assertSFTPConnectionLost()
     574
     575
     576# What follows is a series of excerpts from the
     577# draft-ietf-secsh-filexfer-02.txt (draft) specification of the SFTP protocol.
     578# There are more recent drafts of the specification, but this one describes
     579# version 3, which is what conch implements.
     580filexfer_spec_excerpts = [
     581"""
     582   The following values are defined for packet types.
     583
     584        #define SSH_FXP_INIT                1
     585        #define SSH_FXP_VERSION             2
     586        #define SSH_FXP_OPEN                3
     587        #define SSH_FXP_CLOSE               4
     588        #define SSH_FXP_READ                5
     589        #define SSH_FXP_WRITE               6
     590        #define SSH_FXP_LSTAT               7
     591        #define SSH_FXP_FSTAT               8
     592        #define SSH_FXP_SETSTAT             9
     593        #define SSH_FXP_FSETSTAT           10
     594        #define SSH_FXP_OPENDIR            11
     595        #define SSH_FXP_READDIR            12
     596        #define SSH_FXP_REMOVE             13
     597        #define SSH_FXP_MKDIR              14
     598        #define SSH_FXP_RMDIR              15
     599        #define SSH_FXP_REALPATH           16
     600        #define SSH_FXP_STAT               17
     601        #define SSH_FXP_RENAME             18
     602        #define SSH_FXP_READLINK           19
     603        #define SSH_FXP_SYMLINK            20
     604        #define SSH_FXP_STATUS            101
     605        #define SSH_FXP_HANDLE            102
     606        #define SSH_FXP_DATA              103
     607        #define SSH_FXP_NAME              104
     608        #define SSH_FXP_ATTRS             105
     609        #define SSH_FXP_EXTENDED          200
     610        #define SSH_FXP_EXTENDED_REPLY    201
     611
     612   Additional packet types should only be defined if the protocol
     613   version number (see Section ``Protocol Initialization'') is
     614   incremented, and their use MUST be negotiated using the version
     615   number.  However, the SSH_FXP_EXTENDED and SSH_FXP_EXTENDED_REPLY
     616   packets can be used to implement vendor-specific extensions.  See
     617   Section ``Vendor-Specific-Extensions'' for more details.
     618""",
     619"""
     620    The flags bits are defined to have the following values:
     621
     622        #define SSH_FILEXFER_ATTR_SIZE          0x00000001
     623        #define SSH_FILEXFER_ATTR_UIDGID        0x00000002
     624        #define SSH_FILEXFER_ATTR_PERMISSIONS   0x00000004
     625        #define SSH_FILEXFER_ATTR_ACMODTIME     0x00000008
     626        #define SSH_FILEXFER_ATTR_EXTENDED      0x80000000
     627
     628""",
     629"""
     630    The `pflags' field is a bitmask.  The following bits have been
     631   defined.
     632
     633        #define SSH_FXF_READ            0x00000001
     634        #define SSH_FXF_WRITE           0x00000002
     635        #define SSH_FXF_APPEND          0x00000004
     636        #define SSH_FXF_CREAT           0x00000008
     637        #define SSH_FXF_TRUNC           0x00000010
     638        #define SSH_FXF_EXCL            0x00000020
     639""",
     640"""
     641    Currently, the following values are defined (other values may be
     642   defined by future versions of this protocol):
     643
     644        #define SSH_FX_OK                            0
     645        #define SSH_FX_EOF                           1
     646        #define SSH_FX_NO_SUCH_FILE                  2
     647        #define SSH_FX_PERMISSION_DENIED             3
     648        #define SSH_FX_FAILURE                       4
     649        #define SSH_FX_BAD_MESSAGE                   5
     650        #define SSH_FX_NO_CONNECTION                 6
     651        #define SSH_FX_CONNECTION_LOST               7
     652        #define SSH_FX_OP_UNSUPPORTED                8
     653"""]
     654
     655class TestConstants(unittest.TestCase):
     656
     657    def test_constants_against_spec(self):
     658        constants = {}
     659        for excerpt in filexfer_spec_excerpts:
     660            for line in excerpt.splitlines():
     661                m = re.match('^\s*#define SSH_([A-Z_]+)\s+([0-9x]*)\s*$', line)
     662                if m:
     663                    constants[m.group(1)] = int(m.group(2), 0)
     664        self.assert_(len(constants) > 0)
     665        for k, v in constants.items():
     666            self.assertEqual(v, getattr(filetransfer, k))
  • twisted/conch/ssh/filetransfer.py

     
    866866FXP_EXTENDED_REPLY  = 201
    867867
    868868FILEXFER_ATTR_SIZE        = 0x00000001
    869 FILEXFER_ATTR_OWNERGROUP  = 0x00000002
     869FILEXFER_ATTR_UIDGID      = 0x00000002
     870FILEXFER_ATTR_OWNERGROUP  = FILEXFER_ATTR_UIDGID
    870871FILEXFER_ATTR_PERMISSIONS = 0x00000004
    871 FILEXFER_ATTR_ACMODTIME   = 0x00000009
     872FILEXFER_ATTR_ACMODTIME   = 0x00000008
    872873FILEXFER_ATTR_EXTENDED    = 0x80000000L
    873874
    874875FILEXFER_TYPE_REGULAR        = 1
     
    895896FX_CONNECTION_LOST             = 7
    896897FX_OP_UNSUPPORTED              = 8
    897898FX_FILE_ALREADY_EXISTS         = 11
    898 # https://datatracker.ietf.org/idtracker/draft-ietf-secsh-filexfer/ defines
    899 # more useful error codes, but so far OpenSSH doesn't implement them.  We use
    900 # them internally for clarity, but for now define them all as FX_FAILURE to be
     899# http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/ defines more
     900# useful error codes, but so far OpenSSH doesn't implement them.  We use them
     901# internally for clarity, but for now define them all as FX_FAILURE to be
    901902# compatible with existing software.
    902903FX_NOT_A_DIRECTORY             = FX_FAILURE
    903904FX_FILE_IS_A_DIRECTORY         = FX_FAILURE