1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """
20 Common constants and global variables.
21 """
22
23 MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, MSG_SERVICE_REQUEST, \
24 MSG_SERVICE_ACCEPT = range(1, 7)
25 MSG_KEXINIT, MSG_NEWKEYS = range(20, 22)
26 MSG_USERAUTH_REQUEST, MSG_USERAUTH_FAILURE, MSG_USERAUTH_SUCCESS, \
27 MSG_USERAUTH_BANNER = range(50, 54)
28 MSG_USERAUTH_PK_OK = 60
29 MSG_USERAUTH_INFO_REQUEST, MSG_USERAUTH_INFO_RESPONSE = range(60, 62)
30 MSG_GLOBAL_REQUEST, MSG_REQUEST_SUCCESS, MSG_REQUEST_FAILURE = range(80, 83)
31 MSG_CHANNEL_OPEN, MSG_CHANNEL_OPEN_SUCCESS, MSG_CHANNEL_OPEN_FAILURE, \
32 MSG_CHANNEL_WINDOW_ADJUST, MSG_CHANNEL_DATA, MSG_CHANNEL_EXTENDED_DATA, \
33 MSG_CHANNEL_EOF, MSG_CHANNEL_CLOSE, MSG_CHANNEL_REQUEST, \
34 MSG_CHANNEL_SUCCESS, MSG_CHANNEL_FAILURE = range(90, 101)
35
36
37
38 MSG_NAMES = {
39 MSG_DISCONNECT: 'disconnect',
40 MSG_IGNORE: 'ignore',
41 MSG_UNIMPLEMENTED: 'unimplemented',
42 MSG_DEBUG: 'debug',
43 MSG_SERVICE_REQUEST: 'service-request',
44 MSG_SERVICE_ACCEPT: 'service-accept',
45 MSG_KEXINIT: 'kexinit',
46 MSG_NEWKEYS: 'newkeys',
47 30: 'kex30',
48 31: 'kex31',
49 32: 'kex32',
50 33: 'kex33',
51 34: 'kex34',
52 MSG_USERAUTH_REQUEST: 'userauth-request',
53 MSG_USERAUTH_FAILURE: 'userauth-failure',
54 MSG_USERAUTH_SUCCESS: 'userauth-success',
55 MSG_USERAUTH_BANNER: 'userauth--banner',
56 MSG_USERAUTH_PK_OK: 'userauth-60(pk-ok/info-request)',
57 MSG_USERAUTH_INFO_RESPONSE: 'userauth-info-response',
58 MSG_GLOBAL_REQUEST: 'global-request',
59 MSG_REQUEST_SUCCESS: 'request-success',
60 MSG_REQUEST_FAILURE: 'request-failure',
61 MSG_CHANNEL_OPEN: 'channel-open',
62 MSG_CHANNEL_OPEN_SUCCESS: 'channel-open-success',
63 MSG_CHANNEL_OPEN_FAILURE: 'channel-open-failure',
64 MSG_CHANNEL_WINDOW_ADJUST: 'channel-window-adjust',
65 MSG_CHANNEL_DATA: 'channel-data',
66 MSG_CHANNEL_EXTENDED_DATA: 'channel-extended-data',
67 MSG_CHANNEL_EOF: 'channel-eof',
68 MSG_CHANNEL_CLOSE: 'channel-close',
69 MSG_CHANNEL_REQUEST: 'channel-request',
70 MSG_CHANNEL_SUCCESS: 'channel-success',
71 MSG_CHANNEL_FAILURE: 'channel-failure'
72 }
73
74
75
76 AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED = range(3)
77
78
79
80 (OPEN_SUCCEEDED,
81 OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED,
82 OPEN_FAILED_CONNECT_FAILED,
83 OPEN_FAILED_UNKNOWN_CHANNEL_TYPE,
84 OPEN_FAILED_RESOURCE_SHORTAGE) = range(0, 5)
85
86
87 CONNECTION_FAILED_CODE = {
88 1: 'Administratively prohibited',
89 2: 'Connect failed',
90 3: 'Unknown channel type',
91 4: 'Resource shortage'
92 }
93
94
95 DISCONNECT_SERVICE_NOT_AVAILABLE, DISCONNECT_AUTH_CANCELLED_BY_USER, \
96 DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 7, 13, 14
97
98 from rng import StrongLockingRandomPool
99
100
101 randpool = StrongLockingRandomPool()
102
103 import sys
104 if sys.version_info < (2, 3):
105 try:
106 import logging
107 except:
108 import logging22 as logging
109 import select
110 PY22 = True
111
112 import socket
113 if not hasattr(socket, 'timeout'):
115 socket.timeout = timeout
116 del timeout
117 else:
118 import logging
119 PY22 = False
120
121
122 DEBUG = logging.DEBUG
123 INFO = logging.INFO
124 WARNING = logging.WARNING
125 ERROR = logging.ERROR
126 CRITICAL = logging.CRITICAL
127