Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.SFTP.Version5Types

Feature notes: SFTP implementation notes

Classes, interfaces and records

classtSupportedStructure

inherits from TPersistent

Holds the contents of the SFTP version 5 "supported" extension - the capability record a server advertises in its SSH_FXP_VERSION reply. This unit only decodes it, so in practice an application sees this populated on the client side (as the transport's/client's ServerSupported), where it is consulted to discover which attributes, bits, open-flags, access-mask bits and named extensions the peer server will honour.

constructor Create(aOwner: TPersistent);
Creates the record and its empty ExtensionNames list; aOwner is the persistent object that owns this instance (typically the SFTP transport or client that exposes it as ServerSupported). Applications normally let the transport construct it rather than creating one directly.
destructor Destroy; override;
Frees the ExtensionNames list. Invoked when the owning transport/client is destroyed; not called directly by application code.
procedure Decode(const aBuf: tBytes; aOffset: Integer; aCount: Integer);
Parses a wire-format "supported" extension body from aBuf (aOffset/aCount delimit it), filling all the properties below. Full description »
property AttributeMask: tValidFileAttrFlags5 read fAttributeMask write SetAttributeMask;
The set of file-attribute fields (size, permissions, times, ACL, owner/group, ...) the server is prepared to report and accept. A client reads this before requesting or setting attributes to avoid asking for ones the server does not support.
property AttributeBits: tAttribBits read fAttributeBits write SetAttributeBits;
The subset of attribute bit-flags (read-only, system, hidden, archive, ...) the server understands; advisory for a client deciding which bits are meaningful to send.
property OpenFlags: tFileOpenFlags5 read fOpenFlags write SetOpenFlags;
The file open/disposition flags (create/truncate, append, locking, text mode) the server supports; a client should restrict SSH_FXP_OPEN requests to this set.
property AccessMask: tACEMask read fAccessMask write SetAccessMask;
The ACE access-mask bits (read/write data, read/write attributes, ACL, ...) the server honours when opening files or evaluating ACLs.
property MaxReadSize: UInt32 read fMaxReadSize write SetMaxReadSize;
The largest byte count the server guarantees to return in full for a single SSH_FXP_READ; a client uses it to size reads so that any shorter result can be treated unambiguously as end-of-file.
property ExtensionNames: TStrings read fExtensionNames write SetExtensionNames;
The names of the protocol extensions (e.g. 'md5-hash-handle', 'text-seek') the server advertises; a client checks this list before issuing the corresponding SSH_FXP_EXTENDED request. A name of 0 octets names no extension and is left out.

interfaceiACLItem

A single Access Control Entry (ACE) within an SFTP version 5 file ACL, in the NFSv4 style. Applications obtain these from iFileAttributes5.ACL (or add them via AddACLItem) to inspect or build the per-file access-control list carried in file attributes; the same objects are used on both the client and the server side, differing only in who fills them in.

function GetACEFlag: tACEFlags;
Getter for ACEFlag.
function GetACEMask: tACEMask;
Getter for ACEMask.
function GetACEType: tACEType;
Getter for ACEType.
function GetWho: string;
Getter for Who.
procedure SetACEFlag(const Value: tACEFlags);
Setter for ACEFlag.
procedure SetACEMask(const Value: tACEMask);
Setter for ACEMask.
procedure SetACEType(const Value: tACEType);
Setter for ACEType.
procedure SetWho(const Value: string);
Setter for Who.
function EncodeLength: Integer;
Returns the number of wire bytes this entry occupies once encoded, so the caller can size the ACL buffer before serialising the surrounding file attributes.
procedure Decode(const aBuf: tBytes; var aOffset, aCount: Integer);
Reads one ACE (type, flags, mask and the UTF-8 'who' name) from aBuf, advancing aOffset and decrementing aCount. Used when parsing a file's ACL received from the peer.
procedure Encode(const aBuf: tBytes; var aOffset, aCount: Integer);
Writes this ACE into aBuf in SFTP version 5 wire form, advancing aOffset. Used when transmitting a file's ACL to the peer.
property ACEType: tACEType read GetACEType write SetACEType;
Whether the entry allows, denies, audits or alarms the access described by ACEMask (NFSv4 ace-type).
property ACEFlag: tACEFlags read GetACEFlag write SetACEFlag;
The inheritance and audit flags for the entry (file/directory inherit, inherit-only, group identifier, ...).
property ACEMask: tACEMask read GetACEMask write SetACEMask;
The set of access rights (read/write data, read/write attributes, ACL, ...) this entry grants or denies.
property Who: string read GetWho write SetWho;
The principal the entry applies to - a user or group name, or a special identifier such as 'OWNER@', 'GROUP@' or 'EVERYONE@'.

classtACLItem

inherits from TInterfacedObject

implements iACLItem

The concrete implementation of iACLItem. Applications work through the iACLItem interface (returned by iFileAttributes5.ACL / AddACLItem) rather than this class directly; it caches its own encoded form and clears that cache whenever a property is changed.

(no public members)

interfaceiFileAttributes5

inherits from iFileAttributes

function GetAccessTime: Int64;
Getter for AccessTime.
function GetAccessTimeNanoSec: UInt32;
Getter for AccessTimeNanoSec.
function GetACLCount: Integer;
Getter for ACLCount.
function GetAttributeType: tFileAttributeType;
Getter for AttributeType.
function GetCreateTime: Int64;
Getter for CreateTime.
function GetCreateTimeNanoSec: UInt32;
Getter for CreateTimeNanoSec.
function GetGroup: string;
Getter for Group.
function GetModifyTime: Int64;
Getter for ModifyTime.
function GetModifyTimeNanoSec: UInt32;
Getter for ModifyTimeNanoSec.
function GetOwner: string;
Getter for Owner.
function GetValidAttributeFlags: tValidFileAttrFlags5;
Getter for ValidAttributeFlags.
function GetACL(aIndex: Integer): iACLItem;
Getter behind the ACL indexed property; resolves the stored ACE at aIndex.
function GetBits: tAttribBits;
Getter for Bits.
function GetExtended: TStrings;
Getter for Extended.
procedure SetAccessTime(const Value: Int64);
Setter for AccessTime; also flags the access-time field present so Encode emits it.
procedure SetAccessTimeNanoSec(const Value: UInt32);
Setter for AccessTimeNanoSec; flags both the access-time and sub-second fields present.
procedure SetACL(aIndex: Integer; const Value: iACLItem);
Setter behind the ACL indexed property; replaces the ACE stored at aIndex.
procedure SetAttributeType(const Value: tFileAttributeType);
Setter for AttributeType (the file-kind byte, always transmitted on v5).
procedure SetCreateTime(const Value: Int64);
Setter for CreateTime; also flags the create-time field present for encoding.
procedure SetCreateTimeNanoSec(const Value: UInt32);
Setter for CreateTimeNanoSec; flags both the create-time and sub-second fields present.
procedure SetGroup(const Value: string);
Setter for Group; also flags the owner-and-group pair present for encoding.
procedure SetModifyTime(const Value: Int64);
Setter for ModifyTime; also flags the modify-time field present for encoding.
procedure SetModifyTimeNanoSec(const Value: UInt32);
Setter for ModifyTimeNanoSec; flags both the modify-time and sub-second fields present.
procedure SetOwner(const Value: string);
Setter for Owner; also flags the owner-and-group pair present for encoding.
procedure SetValidAttributeFlags(const Value: tValidFileAttrFlags5);
Setter for ValidAttributeFlags; overwrites the whole present-fields mask wholesale (unlike the field setters that only add their own flag).
procedure SetBits(const Value: tAttribBits);
Setter for Bits; also flags the attrib-bits field present for encoding.
procedure SetExtended(const Value: TStrings);
Setter for Extended; flags the extended field present when a non-empty list is assigned, or clears it and the flag when nil or empty.
function AddACLItem(const aName: AnsiString): iACLItem; overload;
Appends a new, empty ACE to the file's ACL with its 'who' preset to aName, flags the ACL present, and returns it for further configuration; used when building the access-control list to send in a setstat or a server reply.
function AddACLItem(aWho: tACLWho): iACLItem; overload;
As above, but presets 'who' to one of the NFSv4 special identifiers (OWNER@, GROUP@, EVERYONE@, ...) named by aWho.
function FindACLItem(const aName: AnsiString): iACLItem; overload;
Returns the existing ACE whose 'who' equals aName, or nil if none; used to inspect or update a specific entry in an ACL received from the peer.
function FindACLItem(aWho: tACLWho): iACLItem; overload;
As above, matching against the NFSv4 special-identifier string for aWho.
property ValidAttributeFlags: tValidFileAttrFlags5 read GetValidAttributeFlags write SetValidAttributeFlags;
The bitmask naming which optional attribute fields are actually present in this record; it governs what Encode writes and reflects what Decode found. A client tests it before trusting a stat field; the field setters add their own flag automatically as an app populates a setstat.
property AttributeType: tFileAttributeType read GetAttributeType write SetAttributeType;
The file kind - regular, directory, symlink, special, etc. Unlike the other fields this byte is always present in a v5 attribute record.
property Owner: string read GetOwner write SetOwner;
The textual owner name (v5 replaces v3's numeric uid); read from a stat result, or assign it to request a chown via setstat.
property Group: string read GetGroup write SetGroup;
The textual group name (v5 replaces v3's numeric gid); assigning it, like Owner, marks the owner-and-group pair to be sent.
property AccessTime: Int64 read GetAccessTime write SetAccessTime;
Last file-data access time in Unix seconds; read from a stat result or set before a setstat to change it.
property AccessTimeNanoSec: UInt32 read GetAccessTimeNanoSec write SetAccessTimeNanoSec;
Fractional (nanosecond) part of AccessTime; only meaningful and transmitted when the sub-second-times valid flag is set, which assigning it enables.
property CreateTime: Int64 read GetCreateTime write SetCreateTime;
File creation time in Unix seconds; a v5 field with no v3 equivalent.
property CreateTimeNanoSec: UInt32 read GetCreateTimeNanoSec write SetCreateTimeNanoSec;
Fractional (nanosecond) part of CreateTime; only present when the sub-second-times valid flag is set.
property ModifyTime: Int64 read GetModifyTime write SetModifyTime;
Last content-modification time in Unix seconds; read from a stat result or set before a setstat to change it.
property ModifyTimeNanoSec: UInt32 read GetModifyTimeNanoSec write SetModifyTimeNanoSec;
Fractional (nanosecond) part of ModifyTime; only present when the sub-second-times valid flag is set.
property ACLCount: Integer read GetACLCount;
The number of ACEs currently in the file's ACL; read-only, use it to bound an iteration over the ACL indexed property.
property ACL[aIndex: Integer]: iACLItem read GetACL write SetACL;
Indexed access to the individual NFSv4-style ACEs of the file's ACL; iterate from zero to ACLCount minus one to inspect an ACL parsed from the peer.
property Bits: tAttribBits read GetBits write SetBits;
The advisory attrib-bits set (read-only, hidden, system, archive, immutable, ...) largely mirroring Windows/DOS file flags; assigning it marks the field present to send.
property Extended: TStrings read GetExtended write SetExtended;
Vendor extension attributes as name=value pairs; a client reads any the server chose to include, or an app assigns a non-empty list to have them encoded into the record.

classtFileAttributes5

The concrete v5 implementation of iFileAttributes / iFileAttributes5. The SFTP transport creates one (via its NewFileAttributes factory) to hold a decoded stat/readdir result or to build a setstat/reply record; applications use it through the iFileAttributes5 interface rather than this class directly.

constructor Create;
Creates an empty v5 attribute record with its ACL list and Extended name-value list ready. An app rarely calls this directly: the SFTP client builds one to hold a decoded stat/readdir result, or to populate a setstat request, and hands out the iFileAttributes5 interface.
destructor Destroy; override;
Frees the Extended list. Runs when the last interface reference is released, not from application code.

Types (enumerations, sets, aliases)

enumtValidFileAttr5

  tValidFileAttr5 = (
    vfaSize,
    vfa1,
    vfaPermissions,
    vfaAccessTime,
    vfaCreateTime,
    vfaModifyTime,
    vfaACL,
    vfaOwnerGroup,
    vfaSubSecondTimes,
    vfaBits,
    vfa10,
    vfa11,
    vfa12,
    vfa13,
    vfa14,
    vfa15,
    vfa16,
    vfa17,
    vfa18,
    vfa19,
    vfa20,
    vfa21,
    vfa22,
    vfa23,
    vfa24,
    vfa25,
    vfa26,
    vfa27,
    vfa28,
    vfa29,
    vfa30,
    vfaExtended
  );

settValidFileAttrFlags5

  tValidFileAttrFlags5 = set of tValidFileAttr5;

enumtFileAttributeType

  tFileAttributeType = (
    fat0,
    fatRegular,
    fatDirectory,
    fatSymLink,
    fatSpecial,
    fatUnknown,
    fatSocket,
    fatCharDevice,
    fatBlockDevice,
    fatFIFO
  );

enumtACEType

  tACEType = (
    acetAccessAllowed,
    acetAccessDenied,
    acetSystemAudit,
    acetSystemAlarm
  );

enumtACEFlag

  tACEFlag = (
    acefFileInherit,
    acefDirectoryInherit,
    acefNoPropagateInherit,
    acefInheritOnly,
    acefSuccessfulAccess,
    acefFailedAccess,
    acefIdentifierGroup
  );

settACEFlags

  tACEFlags = set of tACEFlag;

enumtACEMaskEnum

The NFSv4 access rights of draft-ietf-secsh-filexfer-05 section 5.7, as used in the desired-access field of SSH_FXP_OPEN, the ace-mask of an ACL entry and the supported-access-mask of the "supported" extension. The ordinal of a member is not its value on the wire: cACEMaskACE4 gives that, and ACEMaskToACE4 and ACE4ToACEMask convert a whole set.

  tACEMaskEnum = (
    acemReadData,
    acemListDirectory,
    acemWriteData,
    acemAddFile,
    acemAppendData,
    acemAddSubDirectory,
    acemReadNamedAttrs,
    acemWriteNamedAttrs,
    acemExecute,
    acemDeleteChild,
    acemReadAttributes,
    acemWriteAttributes,
    acemDelete,
    acemReadACL,
    acemWriteACL,
    acemWriteOwner,
    acemSynchronize
  );

settACEMask

  tACEMask = set of tACEMaskEnum;

enumtAttribBit

  tAttribBit = (
    abReadOnly,
    abSystem,
    abHidden,
    abCaseInsensitive,
    abArchive,
    abEncrypted,
    abCompressed,
    abSparse,
    abAppendOnly,
    abImmutable,
    abSync
  );

settAttribBits

  tAttribBits = set of tAttribBit;

enumtFileOpenFlag5

  tFileOpenFlag5 = (
    foCreateTruncate,
    foOpenExisting,
    foTruncateExisting,
    foAccessAppendData,
    foAccessAppendDataAtomic,
    foAccessTextMode,
    foAccessReadLock,
    foAccessWriteLock,
    foAccessDeleteLock
  );

settFileOpenFlags5

  tFileOpenFlags5 = set of tFileOpenFlag5;

enumtRenameFlag

  tRenameFlag = (
    rfOverwrite,
    rfAtomic,
    rfNative
  );

settRenameFlags

  tRenameFlags = set of tRenameFlag;

enumtACLWho

  tACLWho = (awOwner,awGroup,awEveryone,awInteractive,awNetwork,awDialup,
             awBatch,awAnonymous,awAuthenticated);

Routines