Skip to content

Commit 4d728b7

Browse files
author
Pan
committed
Added none checks on method arguments.
Added docstrings. Removed unused parameter from agent get identities method. Updated example for changed API. Updated tests to only start one server. Updated embedded server config. Updated tests to correctly decode output.
1 parent cd75d96 commit 4d728b7

File tree

18 files changed

+2848
-1716
lines changed

18 files changed

+2848
-1716
lines changed

embedded_server/openssh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, port=2222):
3232

3333
def start_server(self):
3434
cmd = ['/usr/sbin/sshd', '-D', '-p', str(self.port),
35-
'-h', SERVER_KEY, '-f', SSHD_CONFIG]
35+
'-q', '-h', SERVER_KEY, '-f', SSHD_CONFIG]
3636
server = Popen(cmd)
3737
self.server_proc = server
3838
self._wait_for_port()
@@ -41,7 +41,7 @@ def _wait_for_port(self):
4141
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4242
while sock.connect_ex(('127.0.0.1', self.port)) != 0:
4343
sleep(.1)
44-
sleep(.2)
44+
sleep(.3)
4545
del sock
4646

4747
def stop(self):

embedded_server/sshd_config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RhostsRSAAuthentication no
55
HostbasedAuthentication no
66
IgnoreUserKnownHosts yes
77
GSSAPIAuthentication no
8-
8+
ListenAddress 127.0.0.1
99
KeyRegenerationInterval 3600
1010
ServerKeyBits 1024
1111

examples/example_echo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Agent capabilities
2727
agent = session.agent_init()
2828
agent.connect()
29-
identities = agent.get_identities(user)
29+
identities = agent.get_identities()
3030
print(identities)
3131
print(identities[0].magic)
3232
del agent

ssh2/agent.c

Lines changed: 42 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/agent.pyx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ cdef class Agent:
9393
prev = identity
9494
return identities
9595

96-
def userauth(self, username,
96+
def userauth(self, username not None,
9797
PublicKey pkey):
9898
"""Perform user authentication with specific public key
9999
100100
:param username: User name to authenticate as
101101
:type username: str
102102
:param pkey: Public key to authenticate with
103-
:type pkey: py:class:`PublicKey`
103+
:type pkey: py:class:`ssh2.pkey.PublicKey`
104104
105105
:raises: :py:class:`ssh2.exceptions.AgentAuthenticationError` on errors
106106
authenticating.
@@ -120,12 +120,21 @@ cdef class Agent:
120120
return rc
121121

122122
def disconnect(self):
123+
"""Disconnect from agent.
124+
125+
:rtype: int"""
123126
cdef int rc
124127
with nogil:
125128
rc = c_ssh2.libssh2_agent_disconnect(self._agent)
126129
return rc
127130

128131
def connect(self):
132+
"""Connect to agent.
133+
134+
:raises: :py:class:`ssh2.exceptions.AgentConnectError` on errors
135+
connecting to agent.
136+
137+
:rtype: int"""
129138
cdef int rc
130139
with nogil:
131140
rc = c_ssh2.libssh2_agent_connect(self._agent)

ssh2/c_sftp.pxd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ cdef extern from "libssh2_sftp.h" nogil:
4242
uint64_t f_fsid # file system ID
4343
uint64_t f_flag # mount flags
4444
uint64_t f_namemax # maximum filename length
45+
# SFTP File Transfer Flags
46+
enum:
47+
LIBSSH2_FXF_READ
48+
LIBSSH2_FXF_WRITE
49+
LIBSSH2_FXF_APPEND
50+
LIBSSH2_FXF_CREAT
51+
LIBSSH2_FXF_TRUNC
52+
LIBSSH2_FXF_EXCL
53+
# SFTP File modes
54+
enum:
55+
# Read, write, execute/search by owner
56+
LIBSSH2_SFTP_S_IRWXU # RWX mask for owner
57+
LIBSSH2_SFTP_S_IRUSR # R for owner
58+
LIBSSH2_SFTP_S_IWUSR # W for owner
59+
LIBSSH2_SFTP_S_IXUSR # X for owner
60+
# Read, write, execute/search by group
61+
LIBSSH2_SFTP_S_IRWXG # RWX mask for group
62+
LIBSSH2_SFTP_S_IRGRP # R for group
63+
LIBSSH2_SFTP_S_IWGRP # W for group
64+
LIBSSH2_SFTP_S_IXGRP # X for group
65+
# Read, write, execute/search by others
66+
LIBSSH2_SFTP_S_IRWXO # RWX mask for other
67+
LIBSSH2_SFTP_S_IROTH # R for other
68+
LIBSSH2_SFTP_S_IWOTH # W for other
69+
LIBSSH2_SFTP_S_IXOTH # X for other
4570
LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session)
4671
int libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp)
4772
unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp)

0 commit comments

Comments
 (0)