a geicko-2 based round robin ranking system designed to test c++ battleship submissions battleship.dunkirk.sh
at main 2.0 kB view raw
1package sftp 2 3// Methods on the Request object to make working with the Flags bitmasks and 4// Attr(ibutes) byte blob easier. Use Pflags() when working with an Open/Write 5// request and AttrFlags() and Attributes() when working with SetStat requests. 6 7// FileOpenFlags defines Open and Write Flags. Correlate directly with with os.OpenFile flags 8// (https://golang.org/pkg/os/#pkg-constants). 9type FileOpenFlags struct { 10 Read, Write, Append, Creat, Trunc, Excl bool 11} 12 13func newFileOpenFlags(flags uint32) FileOpenFlags { 14 return FileOpenFlags{ 15 Read: flags&sshFxfRead != 0, 16 Write: flags&sshFxfWrite != 0, 17 Append: flags&sshFxfAppend != 0, 18 Creat: flags&sshFxfCreat != 0, 19 Trunc: flags&sshFxfTrunc != 0, 20 Excl: flags&sshFxfExcl != 0, 21 } 22} 23 24// Pflags converts the bitmap/uint32 from SFTP Open packet pflag values, 25// into a FileOpenFlags struct with booleans set for flags set in bitmap. 26func (r *Request) Pflags() FileOpenFlags { 27 return newFileOpenFlags(r.Flags) 28} 29 30// FileAttrFlags that indicate whether SFTP file attributes were passed. When a flag is 31// true the corresponding attribute should be available from the FileStat 32// object returned by Attributes method. Used with SetStat. 33type FileAttrFlags struct { 34 Size, UidGid, Permissions, Acmodtime bool 35} 36 37func newFileAttrFlags(flags uint32) FileAttrFlags { 38 return FileAttrFlags{ 39 Size: (flags & sshFileXferAttrSize) != 0, 40 UidGid: (flags & sshFileXferAttrUIDGID) != 0, 41 Permissions: (flags & sshFileXferAttrPermissions) != 0, 42 Acmodtime: (flags & sshFileXferAttrACmodTime) != 0, 43 } 44} 45 46// AttrFlags returns a FileAttrFlags boolean struct based on the 47// bitmap/uint32 file attribute flags from the SFTP packaet. 48func (r *Request) AttrFlags() FileAttrFlags { 49 return newFileAttrFlags(r.Flags) 50} 51 52// Attributes parses file attributes byte blob and return them in a 53// FileStat object. 54func (r *Request) Attributes() *FileStat { 55 fs, _, _ := unmarshalFileStat(r.Flags, r.Attrs) 56 return fs 57}