1
from zope.interface import Interface
3
class IConchUser(Interface):
4
"""A user who has been authenticated to Cred through Conch. This is
5
the interface between the SSH connection and the user.
7
@ivar conn: The SSHConnection object for this user.
10
def lookupChannel(channelType, windowSize, maxPacket, data):
12
The other side requested a channel of some sort.
13
channelType is the type of channel being requested,
14
windowSize is the initial size of the remote window,
15
maxPacket is the largest packet we should send,
16
data is any other packet data (often nothing).
18
We return a subclass of L{SSHChannel<ssh.channel.SSHChannel>}. If
19
an appropriate channel can not be found, an exception will be
20
raised. If a L{ConchError<error.ConchError>} is raised, the .value
21
will be the message, and the .data will be the error code.
23
@type channelType: C{str}
24
@type windowSize: C{int}
25
@type maxPacket: C{int}
27
@rtype: subclass of L{SSHChannel}/C{tuple}
30
def lookupSubsystem(subsystem, data):
32
The other side requested a subsystem.
33
subsystem is the name of the subsystem being requested.
34
data is any other packet data (often nothing).
36
We return a L{Protocol}.
39
def gotGlobalRequest(requestType, data):
41
A global request was sent from the other side.
43
By default, this dispatches to a method 'channel_channelType' with any
44
non-alphanumerics in the channelType replace with _'s. If it cannot
45
find a suitable method, it returns an OPEN_UNKNOWN_CHANNEL_TYPE error.
46
The method is called with arguments of windowSize, maxPacket, data.
49
class ISession(Interface):
51
def getPty(term, windowSize, modes):
53
Get a psuedo-terminal for use by a shell or command.
55
If a psuedo-terminal is not available, or the request otherwise
56
fails, raise an exception.
61
Open a shell and connect it to proto.
63
@param proto: a L{ProcessProtocol} instance.
66
def execCommand(proto, command):
70
@param proto: a L{ProcessProtocol} instance.
73
def windowChanged(newWindowSize):
75
Called when the size of the remote screen has changed.
80
Called when the other side has indicated no more data will be sent.
85
Called when the session is closed.
89
class ISFTPServer(Interface):
91
The only attribute of this class is "avatar". It is the avatar
92
returned by the Realm that we are authenticated with, and
93
represents the logged-in user. Each method should check to verify
94
that the user has permission for their actions.
97
def gotVersion(otherVersion, extData):
99
Called when the client sends their version info.
101
otherVersion is an integer representing the version of the SFTP
102
protocol they are claiming.
103
extData is a dictionary of extended_name : extended_data items.
104
These items are sent by the client to indicate additional features.
106
This method should return a dictionary of extended_name : extended_data
107
items. These items are the additional features (if any) supported
112
def openFile(filename, flags, attrs):
114
Called when the clients asks to open a file.
116
@param filename: a string representing the file to open.
118
@param flags: an integer of the flags to open the file with, ORed together.
119
The flags and their values are listed at the bottom of this file.
121
@param attrs: a list of attributes to open the file with. It is a
122
dictionary, consisting of 0 or more keys. The possible keys are::
124
size: the size of the file in bytes
125
uid: the user ID of the file as an integer
126
gid: the group ID of the file as an integer
127
permissions: the permissions of the file with as an integer.
128
the bit representation of this field is defined by POSIX.
129
atime: the access time of the file as seconds since the epoch.
130
mtime: the modification time of the file as seconds since the epoch.
131
ext_*: extended attributes. The server is not required to
132
understand this, but it may.
134
NOTE: there is no way to indicate text or binary files. it is up
135
to the SFTP client to deal with this.
137
This method returns an object that meets the ISFTPFile interface.
138
Alternatively, it can return a L{Deferred} that will be called back
142
def removeFile(filename):
144
Remove the given file.
146
This method returns when the remove succeeds, or a Deferred that is
147
called back when it succeeds.
149
@param filename: the name of the file as a string.
152
def renameFile(oldpath, newpath):
154
Rename the given file.
156
This method returns when the rename succeeds, or a L{Deferred} that is
157
called back when it succeeds.
159
@param oldpath: the current location of the file.
160
@param newpath: the new file name.
163
def makeDirectory(path, attrs):
167
This method returns when the directory is created, or a Deferred that
168
is called back when it is created.
170
@param path: the name of the directory to create as a string.
171
@param attrs: a dictionary of attributes to create the directory with.
172
Its meaning is the same as the attrs in the L{openFile} method.
175
def removeDirectory(path):
177
Remove a directory (non-recursively)
179
It is an error to remove a directory that has files or directories in
182
This method returns when the directory is removed, or a Deferred that
183
is called back when it is removed.
185
@param path: the directory to remove.
188
def openDirectory(path):
190
Open a directory for scanning.
192
This method returns an iterable object that has a close() method,
193
or a Deferred that is called back with same.
195
The close() method is called when the client is finished reading
196
from the directory. At this point, the iterable will no longer
199
The iterable should return triples of the form (filename,
200
longname, attrs) or Deferreds that return the same. The
201
sequence must support __getitem__, but otherwise may be any
202
'sequence-like' object.
204
filename is the name of the file relative to the directory.
205
logname is an expanded format of the filename. The recommended format
207
-rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
208
1234567890 123 12345678 12345678 12345678 123456789012
210
The first line is sample output, the second is the length of the field.
211
The fields are: permissions, link count, user owner, group owner,
212
size in bytes, modification time.
214
attrs is a dictionary in the format of the attrs argument to openFile.
216
@param path: the directory to open.
219
def getAttrs(path, followLinks):
221
Return the attributes for the given path.
223
This method returns a dictionary in the same format as the attrs
224
argument to openFile or a Deferred that is called back with same.
226
@param path: the path to return attributes for as a string.
227
@param followLinks: a boolean. If it is True, follow symbolic links
228
and return attributes for the real path at the base. If it is False,
229
return attributes for the specified path.
232
def setAttrs(path, attrs):
234
Set the attributes for the path.
236
This method returns when the attributes are set or a Deferred that is
237
called back when they are.
239
@param path: the path to set attributes for as a string.
240
@param attrs: a dictionary in the same format as the attrs argument to
246
Find the root of a set of symbolic links.
248
This method returns the target of the link, or a Deferred that
251
@param path: the path of the symlink to read.
254
def makeLink(linkPath, targetPath):
256
Create a symbolic link.
258
This method returns when the link is made, or a Deferred that
261
@param linkPath: the pathname of the symlink as a string.
262
@param targetPath: the path of the target of the link as a string.
267
Convert any path to an absolute path.
269
This method returns the absolute path as a string, or a Deferred
270
that returns the same.
272
@param path: the path to convert as a string.
275
def extendedRequest(extendedName, extendedData):
277
This is the extension mechanism for SFTP. The other side can send us
280
If we don't implement the request given by extendedName, raise
283
The return value is a string, or a Deferred that will be called
286
@param extendedName: the name of the request as a string.
287
@param extendedData: the data the other side sent with the request,
291
class ISFTPFile(Interface):
293
This represents an open file on the server. An object adhering to this
294
interface should be returned from L{openFile}().
301
This method returns nothing if the close succeeds immediately, or a
302
Deferred that is called back when the close succeeds.
305
def readChunk(offset, length):
309
If EOF is reached before any data is read, raise EOFError.
311
This method returns the data as a string, or a Deferred that is
312
called back with same.
314
@param offset: an integer that is the index to start from in the file.
315
@param length: the maximum length of data to return. The actual amount
316
returned may less than this. For normal disk files, however,
317
this should read the requested number (up to the end of the file).
320
def writeChunk(offset, data):
324
This method returns when the write completes, or a Deferred that is
325
called when it completes.
327
@param offset: an integer that is the index to start from in the file.
328
@param data: a string that is the data to write.
333
Return the attributes for the file.
335
This method returns a dictionary in the same format as the attrs
336
argument to L{openFile} or a L{Deferred} that is called back with same.
341
Set the attributes for the file.
343
This method returns when the attributes are set or a Deferred that is
344
called back when they are.
346
@param attrs: a dictionary in the same format as the attrs argument to