Parent

Class/Module Index [+]

Quicksearch

Rex::Post::FileStat

This class emulates the ruby FileStat class against a remote entity in a generic fashion. Refer to the ruby documentation for expected behavior.

Attributes

stathash[RW]

Public Class Methods

new(buf='') click to toggle source
# File lib/rex/post/file_stat.rb, line 29
def initialize(buf='')
        self.stathash = {}
        update(buf) if (buf and not buf.empty?)
end

Public Instance Methods

atime() click to toggle source
# File lib/rex/post/file_stat.rb, line 64
def atime
        Time.at(self.stathash['st_atime'])
end
blksize() click to toggle source
# File lib/rex/post/file_stat.rb, line 58
def blksize
        self.stathash['st_blksize']
end
blockdev?() click to toggle source
# File lib/rex/post/file_stat.rb, line 103
def blockdev?
        filetype?(060000)
end
blocks() click to toggle source
# File lib/rex/post/file_stat.rb, line 61
def blocks
        self.stathash['st_blocks']
end
chardev?() click to toggle source
# File lib/rex/post/file_stat.rb, line 106
def chardev?
        filetype?(020000)
end
ctime() click to toggle source
# File lib/rex/post/file_stat.rb, line 70
def ctime
        Time.at(self.stathash['st_ctime'])
end
dev() click to toggle source
# File lib/rex/post/file_stat.rb, line 34
def dev
        self.stathash['st_dev']
end
directory?() click to toggle source
# File lib/rex/post/file_stat.rb, line 109
def directory?
        filetype?(040000)
end
executable?() click to toggle source
# File lib/rex/post/file_stat.rb, line 162
def executable?
        raise NotImplementedError
end
executable_real?() click to toggle source
# File lib/rex/post/file_stat.rb, line 165
def executable_real?
        raise NotImplementedError
end
file?() click to toggle source
# File lib/rex/post/file_stat.rb, line 112
def file?
        filetype?(0100000)
end
filetype?(mask) click to toggle source

this is my own, just a helper...

# File lib/rex/post/file_stat.rb, line 98
def filetype?(mask)
        return true if mode & 0170000 == mask
        return false
end
ftype() click to toggle source
# File lib/rex/post/file_stat.rb, line 125
def ftype
        return @@ftypes[(mode & 0170000) >> 13].dup
end
gid() click to toggle source
# File lib/rex/post/file_stat.rb, line 49
def gid
        self.stathash['st_gid']
end
grpowned?() click to toggle source
# File lib/rex/post/file_stat.rb, line 168
def grpowned?
        raise NotImplementedError
end
ino() click to toggle source
# File lib/rex/post/file_stat.rb, line 37
def ino
        self.stathash['st_ino']
end
mode() click to toggle source
# File lib/rex/post/file_stat.rb, line 40
def mode
        self.stathash['st_mode']
end
mtime() click to toggle source
# File lib/rex/post/file_stat.rb, line 67
def mtime
        Time.at(self.stathash['st_mtime'])
end
owned?() click to toggle source
# File lib/rex/post/file_stat.rb, line 171
def owned?
        raise NotImplementedError
end
perm?(mask) click to toggle source

S_ISUID 0004000 set UID bit S_ISGID 0002000 set GID bit (see below) S_ISVTX 0001000 sticky bit (see below) S_IRWXU 00700 mask for file owner permissions S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permission S_IRWXG 00070 mask for group permissions S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission S_IRWXO 00007 mask for permissions for others (not in group) S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permisson S_IXOTH 00001 others have execute permission

# File lib/rex/post/file_stat.rb, line 147
def perm?(mask)
        return true if mode & mask == mask
        return false
end
pipe?() click to toggle source
# File lib/rex/post/file_stat.rb, line 115
def pipe?
        filetype?(010000) # ??? fifo?
end
pretty() click to toggle source

Return pretty information about a file.

# File lib/rex/post/file_stat.rb, line 208
def pretty
        "  Size: #{size}   Blocks: #{blocks}   IO Block: #{blksize}   Type: #{rdev}\n"                 "Device: #{dev}  Inode: #{ino}  Links: #{nlink}\n"                 "  Mode: #{prettymode}\n"                 "   Uid: #{uid}  Gid: #{gid}\n"                 "Access: #{atime}\n"                 "Modify: #{mtime}\n"                 "Change: #{ctime}\n"
end
prettymode() click to toggle source

Return pretty information about a file's permissions.

# File lib/rex/post/file_stat.rb, line 190
def prettymode
        m  = mode
        om = '%04o' % m
        perms = ''

        3.times {
                perms = ((m & 01) == 01 ? 'x' : '-') + perms
                perms = ((m & 02) == 02 ? 'w' : '-') + perms
                perms = ((m & 04) == 04 ? 'r' : '-') + perms
                m >>= 3
        }

        return "#{om}/#{perms}"
end
rdev() click to toggle source
# File lib/rex/post/file_stat.rb, line 52
def rdev
        self.stathash['st_rdev']
end
readable?() click to toggle source
# File lib/rex/post/file_stat.rb, line 174
def readable?
        raise NotImplementedError
end
readable_real?() click to toggle source
# File lib/rex/post/file_stat.rb, line 177
def readable_real?
        raise NotImplementedError
end
setgid?() click to toggle source
# File lib/rex/post/file_stat.rb, line 152
def setgid?
        perm?(02000)
end
setuid?() click to toggle source
# File lib/rex/post/file_stat.rb, line 155
def setuid?
        perm?(04000)
end
size() click to toggle source
# File lib/rex/post/file_stat.rb, line 55
def size
        self.stathash['st_size']
end
socket?() click to toggle source
# File lib/rex/post/file_stat.rb, line 118
def socket?
        filetype(0140000)
end
sticky?() click to toggle source
# File lib/rex/post/file_stat.rb, line 158
def sticky?
        perm?(01000)
end
uid() click to toggle source
# File lib/rex/post/file_stat.rb, line 46
def uid
        self.stathash['st_uid']
end
update(buf) click to toggle source
# File lib/rex/post/file_stat.rb, line 74
def update(buf)

        # XXX: This needs to understand more than just 'stat' structures
        # Windows can also return _stat32, _stat32i64, _stat64i32, and _stat64 structures
        
        skeys = %{st_dev st_ino st_mode st_wtf st_nlink st_uid st_gid st_rdev st_size st_ctime st_atime st_mtime}
        svals = buf.unpack("VvvvvvvVVVVV")
        skeys.each_index do |i|
                self.stathash[ skeys[i] ] = svals[i]
        end
end
writeable?() click to toggle source
# File lib/rex/post/file_stat.rb, line 180
def writeable?
        raise NotImplementedError
end
writeable_real?() click to toggle source
# File lib/rex/post/file_stat.rb, line 183
def writeable_real?
        raise NotImplementedError
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.