paramiko.common

Package paramiko :: Module common |
[frames] | no frames]

# Source Code for Module paramiko.common

      1  # Copyright (C) 2003-2007  Robey Pointer <robeypointer@gmail.com>
      2  #
      3  # This file is part of paramiko.
      4  #
      5  # Paramiko is free software; you can redistribute it and/or modify it under the
      6  # terms of the GNU Lesser General Public License as published by the Free
      7  # Software Foundation; either version 2.1 of the License, or (at your option)
      8  # any later version.
      9  #
     10  # Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
     11  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
     13  # details.
     14  #
     15  # You should have received a copy of the GNU Lesser General Public License
     16  # along with Paramiko; if not, write to the Free Software Foundation, Inc.,
     17  # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
     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  # for debugging:
     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  # authentication request return codes:
     76  AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED = range(3)
     77
     78
     79  # channel request failed reasons:
     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 Crypto import Random
     99
    100  # keep a crypto-strong PRNG nearby
    101  rng = Random.new()
    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'):
    114 -        class timeout(socket.error): pass
    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