Skip to content

Commit d1eab7a

Browse files
author
Pan
committed
Added ssh options and exceptions implementation.
Updated definition file. Added basic tests and embedded server.
1 parent b0bfbeb commit d1eab7a

18 files changed

+531
-66
lines changed

ssh/c_ssh.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ cdef extern from "libssh/libssh.h" nogil:
532532
ssh_string ssh_string_new(size_t size)
533533
const char *ssh_string_get_char(ssh_string str)
534534
char *ssh_string_to_char(ssh_string str)
535-
ssh_string_free_char(char *s)
535+
void ssh_string_free_char(char *s)
536536

537537
int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
538538
int verify)

ssh/exceptions.pyx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
18+
class OptionError(Exception):
19+
"""Raised on errors getting/setting options"""
20+
21+
22+
class BaseSSHError(Exception):
23+
"""Base class for all errors produced by libssh"""
24+
25+
26+
class RequestDenied(BaseSSHError):
27+
"""Raised on request denied by server errors"""
28+
29+
30+
class FatalError(BaseSSHError):
31+
"""Raised on unrecoverable errors"""
32+
33+
34+
class OtherError(BaseSSHError):
35+
"""Raised on other non-specific fatal errors"""

ssh/options.pxd

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
from c_ssh cimport ssh_options_e
18+
19+
20+
cdef class Option:
21+
cdef ssh_options_e _option
22+
23+
@staticmethod
24+
cdef object from_option(ssh_options_e option)
25+
26+
27+
# cdef ssh_options_e HOST
28+
# cdef ssh_options_e USER
29+
# cdef ssh_options_e PORT
30+
# cdef ssh_options_e PORT_STR
31+
# cdef ssh_options_e FD
32+
# cdef ssh_options_e USER
33+
# cdef ssh_options_e SSH_DIR
34+
# cdef ssh_options_e IDENTITY
35+
# cdef ssh_options_e ADD_IDENTITY
36+
# cdef ssh_options_e KNOWNHOSTS
37+
# cdef ssh_options_e TIMEOUT
38+
# cdef ssh_options_e TIMEOUT_USEC
39+
# cdef ssh_options_e SSH1
40+
# cdef ssh_options_e SSH2
41+
# cdef ssh_options_e LOG_VERBOSITY
42+
# cdef ssh_options_e LOG_VERBOSITY_STR
43+
# cdef ssh_options_e CIPHERS_C_S
44+
# cdef ssh_options_e CIPHERS_S_C
45+
# cdef ssh_options_e COMPRESSION_C_S
46+
# cdef ssh_options_e COMPRESSION_S_C
47+
# cdef ssh_options_e PROXYCOMMAND
48+
# cdef ssh_options_e BINDADDR
49+
# cdef ssh_options_e STRICTHOSTKEYCHECK
50+
# cdef ssh_options_e COMPRESSION
51+
# cdef ssh_options_e COMPRESSION_LEVEL
52+
# cdef ssh_options_e KEY_EXCHANGE
53+
# cdef ssh_options_e HOSTKEYS
54+
# cdef ssh_options_e GSSAPI_SERVER_IDENTITY
55+
# cdef ssh_options_e GSSAPI_CLIENT_IDENTITY
56+
# cdef ssh_options_e GSSAPI_DELEGATE_CREDENTIALS
57+
# cdef ssh_options_e HMAC_C_S
58+
# cdef ssh_options_e HMAC_S_C
59+
# cdef ssh_options_e PASSWORD_AUTH
60+
# cdef ssh_options_e PUBKEY_AUTH
61+
# cdef ssh_options_e KBDINT_AUTH
62+
# cdef ssh_options_e GSSAPI_AUTH
63+
# cdef ssh_options_e GLOBAL_KNOWNHOSTS
64+
# cdef ssh_options_e NODELAY

ssh/options.pyx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
from c_ssh cimport ssh_options_e
18+
19+
20+
cdef class Option:
21+
"""Class for representing an SSH option."""
22+
23+
@staticmethod
24+
cdef object from_option(ssh_options_e option):
25+
cdef Option _option = Option.__new__(Option)
26+
_option._option = option
27+
return _option
28+
29+
@property
30+
def value(self):
31+
return self._option
32+
33+
def __str__(self):
34+
return str(self._option)
35+
36+
def __repr__(self):
37+
return self.__str__()
38+
39+
40+
HOST = Option.from_option(ssh_options_e.SSH_OPTIONS_HOST)
41+
USER = Option.from_option(ssh_options_e.SSH_OPTIONS_USER)
42+
PORT = Option.from_option(ssh_options_e.SSH_OPTIONS_PORT)
43+
PORT_STR = Option.from_option(ssh_options_e.SSH_OPTIONS_PORT_STR)
44+
FD = Option.from_option(ssh_options_e.SSH_OPTIONS_FD)
45+
USER = Option.from_option(ssh_options_e.SSH_OPTIONS_USER)
46+
SSH_DIR = Option.from_option(ssh_options_e.SSH_OPTIONS_SSH_DIR)
47+
IDENTITY = Option.from_option(ssh_options_e.SSH_OPTIONS_IDENTITY)
48+
ADD_IDENTITY = Option.from_option(ssh_options_e.SSH_OPTIONS_ADD_IDENTITY)
49+
KNOWNHOSTS = Option.from_option(ssh_options_e.SSH_OPTIONS_KNOWNHOSTS)
50+
TIMEOUT = Option.from_option(ssh_options_e.SSH_OPTIONS_TIMEOUT)
51+
TIMEOUT_USEC = Option.from_option(ssh_options_e.SSH_OPTIONS_TIMEOUT_USEC)
52+
SSH1 = Option.from_option(ssh_options_e.SSH_OPTIONS_SSH1)
53+
SSH2 = Option.from_option(ssh_options_e.SSH_OPTIONS_SSH2)
54+
LOG_VERBOSITY = Option.from_option(ssh_options_e.SSH_OPTIONS_LOG_VERBOSITY)
55+
LOG_VERBOSITY_STR = Option.from_option(ssh_options_e.SSH_OPTIONS_LOG_VERBOSITY_STR)
56+
CIPHERS_C_S = Option.from_option(ssh_options_e.SSH_OPTIONS_CIPHERS_C_S)
57+
CIPHERS_S_C = Option.from_option(ssh_options_e.SSH_OPTIONS_CIPHERS_S_C)
58+
COMPRESSION_C_S = Option.from_option(ssh_options_e.SSH_OPTIONS_COMPRESSION_C_S)
59+
COMPRESSION_S_C = Option.from_option(ssh_options_e.SSH_OPTIONS_COMPRESSION_S_C)
60+
PROXYCOMMAND = Option.from_option(ssh_options_e.SSH_OPTIONS_PROXYCOMMAND)
61+
BINDADDR = Option.from_option(ssh_options_e.SSH_OPTIONS_BINDADDR)
62+
STRICTHOSTKEYCHECK = Option.from_option(ssh_options_e.SSH_OPTIONS_STRICTHOSTKEYCHECK)
63+
COMPRESSION = Option.from_option(ssh_options_e.SSH_OPTIONS_COMPRESSION)
64+
COMPRESSION_LEVEL = Option.from_option(ssh_options_e.SSH_OPTIONS_COMPRESSION_LEVEL)
65+
KEY_EXCHANGE = Option.from_option(ssh_options_e.SSH_OPTIONS_KEY_EXCHANGE)
66+
HOSTKEYS = Option.from_option(ssh_options_e.SSH_OPTIONS_HOSTKEYS)
67+
GSSAPI_SERVER_IDENTITY = Option.from_option(ssh_options_e.SSH_OPTIONS_GSSAPI_SERVER_IDENTITY)
68+
GSSAPI_CLIENT_IDENTITY = Option.from_option(ssh_options_e.SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY)
69+
GSSAPI_DELEGATE_CREDENTIALS = Option.from_option(ssh_options_e.SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS)
70+
HMAC_C_S = Option.from_option(ssh_options_e.SSH_OPTIONS_HMAC_C_S)
71+
HMAC_S_C = Option.from_option(ssh_options_e.SSH_OPTIONS_HMAC_S_C)
72+
PASSWORD_AUTH = Option.from_option(ssh_options_e.SSH_OPTIONS_PASSWORD_AUTH)
73+
PUBKEY_AUTH = Option.from_option(ssh_options_e.SSH_OPTIONS_PUBKEY_AUTH)
74+
KBDINT_AUTH = Option.from_option(ssh_options_e.SSH_OPTIONS_KBDINT_AUTH)
75+
GSSAPI_AUTH = Option.from_option(ssh_options_e.SSH_OPTIONS_GSSAPI_AUTH)
76+
GLOBAL_KNOWNHOSTS = Option.from_option(ssh_options_e.SSH_OPTIONS_GLOBAL_KNOWNHOSTS)
77+
NODELAY = Option.from_option(ssh_options_e.SSH_OPTIONS_NODELAY)

0 commit comments

Comments
 (0)