CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/file.rb
Views: 11779
1
# -*- coding: binary -*-
2
3
require 'rex/post/io'
4
5
module Rex
6
module Post
7
8
# make this a module so we can mix it in, and have inheritance like..
9
# => [Rex::Post::DispatchNinja::File, Rex::Post::File,
10
# Rex::Post::DispatchNinja::IO, Rex::Post::IO, Object, Kernel]
11
12
###
13
#
14
# This module simulates the behavior that one would expect from the Ruby File
15
# class against a remote entity. Refer to the ruby documentation for expected
16
# behavior.
17
#
18
###
19
module File
20
21
protected
22
# inherits fd and mode from IO
23
attr_accessor :filename
24
public
25
26
# f = File.new("testfile", "r")
27
# f = File.new("newfile", "w+")
28
# f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
29
# !!! I suppose I should figure out the correct default for perm..
30
def initialize(name, mode='r', perm=0)
31
end
32
33
def path
34
filename
35
end
36
37
# ctime/atime blah need fstat..
38
# need lchown/chown/fchown, etc, etc
39
40
# proxy these methods
41
def File.basename(*a)
42
::File.basename(*a)
43
end
44
def File.dirname(*a)
45
::File.dirname(*a)
46
end
47
def File.extname(*a)
48
::File.extname(*a)
49
end
50
# !!! we might actually want to handle this File::SEPARATOR stuff
51
# for win32 support, etc.
52
def File.join(*a)
53
::File.join(*a)
54
end
55
56
def File.chmod
57
raise NotImplementedError
58
end
59
def File.chown
60
raise NotImplementedError
61
end
62
def File.delete(*a)
63
unlink(*a)
64
end
65
def File.unlink
66
raise NotImplementedError
67
end
68
def File.lchmod
69
raise NotImplementedError
70
end
71
def File.lchown
72
raise NotImplementedError
73
end
74
def File.link
75
raise NotImplementedError
76
end
77
def File.lstat
78
raise NotImplementedError
79
end
80
81
# this, along with all the other globbing/search stuff, probably
82
# won't get implemented, at least for a bit...
83
def File.expand_path
84
raise NotImplementedError
85
end
86
def File.fnmatch(*a)
87
fnmatch?(*a)
88
end
89
def File.fnmatch?
90
raise NotImplementedError
91
end
92
93
#
94
# autogen'd stat passthroughs
95
#
96
def File.atime(name)
97
stat(name).atime
98
end
99
def File.blockdev?(name)
100
stat(name).blockdev?
101
end
102
def File.chardev?(name)
103
stat(name).chardev?
104
end
105
def File.ctime(name)
106
stat(name).ctime
107
end
108
def File.directory?(name)
109
stat(name).directory?
110
end
111
def File.executable?(name)
112
stat(name).executable?
113
end
114
def File.executable_real?(name)
115
stat(name).executable_real?
116
end
117
def File.file?(name)
118
stat(name).file?
119
end
120
def File.ftype(name)
121
stat(name).ftype
122
end
123
def File.grpowned?(name)
124
stat(name).grpowned?
125
end
126
def File.mtime(name)
127
stat(name).mtime
128
end
129
def File.owned?(name)
130
stat(name).owned?
131
end
132
def File.pipe?(name)
133
stat(name).pipe?
134
end
135
def File.readable?(name)
136
stat(name).readable?
137
end
138
def File.readable_real?(name)
139
stat(name).readable_real?
140
end
141
def File.setuid?(name)
142
stat(name).setuid?
143
end
144
def File.setgid?(name)
145
stat(name).setgid?
146
end
147
def File.size(name)
148
stat(name).size
149
end
150
def File.socket?(name)
151
stat(name).socket?
152
end
153
def File.sticky?(name)
154
stat(name).sticky?
155
end
156
def File.symlink?(name)
157
stat(name).symlink?
158
end
159
def File.writeable?(name)
160
stat(name).writeable?
161
end
162
def File.writeable_real?(name)
163
stat(name).writeable_real?
164
end
165
def File.zero?(name)
166
stat(name).zero?
167
end
168
169
end
170
171
end; end # Post/Rex
172
173
174