def __init__(self, address, host_key=None, authurl=None, max_children=20): self.log = paramiko.util.get_logger("paramiko") self.log.debug("%s: start server" % self.__class__.__name__) self.fs = CloudFilesFS(None, None, authurl=authurl) # unauthorized self.host_key = host_key self.max_children = max_children ForkingTCPServer.__init__(self, address, CloudFilesSFTPRequestHandler)
class CloudFilesSFTPServer(ForkingTCPServer, paramiko.ServerInterface): """ Expose a CloudFilesFS object over SFTP """ allow_reuse_address = True def __init__(self, address, host_key=None, authurl=None, max_children=20): self.log = paramiko.util.get_logger("paramiko") self.log.debug("%s: start server" % self.__class__.__name__) self.fs = CloudFilesFS(None, None, authurl=authurl) # unauthorized self.host_key = host_key self.max_children = max_children ForkingTCPServer.__init__(self, address, CloudFilesSFTPRequestHandler) def check_channel_request(self, kind, chanid): if kind == 'session': return paramiko.OPEN_SUCCEEDED self.log.warning("Channel request denied from %s, kind=%s" \ % (self.client_address, kind)) # all the check_channel_*_request return False by default but # sftp subsystem because of the set_subsystem_handler call in # the CloudFilesSFTPRequestHandler return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED def check_auth_none(self, username): """Check whether the user can proceed without authentication.""" return paramiko.AUTH_FAILED def check_auth_publickey(self, username, key): """Check whether the given public key is valid for authentication.""" return paramiko.AUTH_FAILED def check_auth_password(self, username, password): """Check whether the given password is valid for authentication.""" self.log.info("Auth request (type=password), username=%s, from=%s" \ % (username, self.client_address)) try: if not password: raise EnvironmentError("no password provided") self.fs.authenticate(username, password) self.fs.connection.real_ip = self.client_address[0] except EnvironmentError, e: self.log.warning("%s: Failed to authenticate: %s" % (self.client_address, e)) self.log.error( "Authentication failure for %s from %s port %s" % (username, self.client_address[0], self.client_address[1])) return paramiko.AUTH_FAILED self.log.info("%s authenticated from %s" % (username, self.client_address)) return paramiko.AUTH_SUCCESSFUL
class CloudFilesSFTPServer(ForkingTCPServer, paramiko.ServerInterface): """ Expose a CloudFilesFS object over SFTP """ allow_reuse_address = True def __init__(self, address, host_key=None, authurl=None, max_children=20): self.log = paramiko.util.get_logger("paramiko") self.log.debug("%s: start server" % self.__class__.__name__) self.fs = CloudFilesFS(None, None, authurl=authurl) # unauthorized self.host_key = host_key self.max_children = max_children ForkingTCPServer.__init__(self, address, CloudFilesSFTPRequestHandler) def check_channel_request(self, kind, chanid): if kind == 'session': return paramiko.OPEN_SUCCEEDED self.log.warning("Channel request denied from %s, kind=%s" \ % (self.client_address, kind)) # all the check_channel_*_request return False by default but # sftp subsystem because of the set_subsystem_handler call in # the CloudFilesSFTPRequestHandler return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED def check_auth_none(self, username): """Check whether the user can proceed without authentication.""" return paramiko.AUTH_FAILED def check_auth_publickey(self, username, key): """Check whether the given public key is valid for authentication.""" return paramiko.AUTH_FAILED def check_auth_password(self, username, password): """Check whether the given password is valid for authentication.""" self.log.info("Auth request (type=password), username=%s, from=%s" \ % (username, self.client_address)) try: if not password: raise EnvironmentError("no password provided") self.fs.authenticate(username, password) self.fs.connection.real_ip = self.client_address[0] except EnvironmentError, e: self.log.warning("%s: Failed to authenticate: %s" % (self.client_address, e)) self.log.error("Authentication failure for %s from %s port %s" % (username, self.client_address[0], self.client_address[1])) return paramiko.AUTH_FAILED self.log.info("%s authenticated from %s" % (username, self.client_address)) return paramiko.AUTH_SUCCESSFUL
def setUp(self): if not hasattr(self, 'username'): cls = self.__class__ if not all([ 'RCLOUD_API_KEY' in os.environ, 'RCLOUD_API_USER' in os.environ ]): print "env RCLOUD_API_USER or RCLOUD_API_KEY not found." sys.exit(1) cls.username = os.environ['RCLOUD_API_USER'] cls.api_key = os.environ['RCLOUD_API_KEY'] cls.auth_url = os.environ.get('RCLOUD_AUTH_URL') cls.cnx = CloudFilesFS(self.username, self.api_key, authurl=self.auth_url) cls.conn = cloudfiles.get_connection(self.username, self.api_key, authurl=self.auth_url) self.cnx.mkdir("/ftpcloudfs_testing") self.cnx.chdir("/ftpcloudfs_testing") self.container = self.conn.get_container('ftpcloudfs_testing')
class Main(object): def __init__(self): """Parse configuration and CLI options.""" global config_file # look for an alternative configuration file try: alt_config_file = sys.argv.index('--config') alt_config_file = sys.argv[alt_config_file + 1] config_file = alt_config_file except (ValueError, IndexError): pass config = RawConfigParser({ 'auth-url': None, 'host-key-file': None, 'bind-address': "127.0.0.1", 'port': 8022, 'memcache': None, 'max-children': 20, 'log-file': None, 'syslog': 'no', 'verbose': 'no', 'pid-file': None, 'uid': None, 'gid': None, }) config.read(config_file) if not config.has_section('sftpcloudfs'): config.add_section('sftpcloudfs') parser = OptionParser(version="%prog " + version, description="This is a SFTP interface to Rackspace " + \ "Cloud Files and Open Stack Object Storage (Swift).", epilog="Contact and support at: %s" % project_url) parser.add_option("-a", "--auth-url", dest="authurl", default=config.get('sftpcloudfs', 'auth-url'), help="Authentication URL") parser.add_option("-k", "--host-key-file", dest="host_key", default=config.get('sftpcloudfs', 'host-key-file'), help="Host RSA key used by the server") parser.add_option("-b", "--bind-address", dest="bind_address", default=config.get('sftpcloudfs', 'bind-address'), help="Address to bind (default: 127.0.0.1)") parser.add_option("-p", "--port", dest="port", type="int", default=config.get('sftpcloudfs', 'port'), help="Port to bind (default: 8022)") memcache = config.get('sftpcloudfs', 'memcache') if memcache: memcache = [x.strip() for x in memcache.split(',')] parser.add_option( '--memcache', type="str", dest="memcache", action="append", default=memcache, help="Memcache server(s) to be used for cache (ip:port)") parser.add_option("-l", "--log-file", dest="log_file", default=config.get('sftpcloudfs', 'log-file'), help="Log into provided file") parser.add_option( "-f", "--foreground", dest="foreground", action="store_true", default=False, help="Run in the foreground (don't detach from terminal)") parser.add_option( "--syslog", dest="syslog", action="store_true", default=config.getboolean('sftpcloudfs', 'syslog'), help="Enable logging to system logger (daemon facility)") parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=config.getboolean('sftpcloudfs', 'verbose'), help="Show detailed information on logging") parser.add_option('--pid-file', type="str", dest="pid_file", default=config.get('sftpcloudfs', 'pid-file'), help="Pid file location when in daemon mode") parser.add_option( '--uid', type="int", dest="uid", default=config.get('sftpcloudfs', 'uid'), help="UID to drop the privileges to when in daemon mode") parser.add_option( '--gid', type="int", dest="gid", default=config.get('sftpcloudfs', 'gid'), help="GID to drop the privileges to when in daemon mode") parser.add_option('--config', type="str", dest="config", default=config_file, help="Use an alternative configuration file") (options, args) = parser.parse_args() # required parameters if not options.authurl: parser.error("No auth-url provided") if not options.host_key: parser.error("No host-key-file provided") try: self.host_key = paramiko.RSAKey(filename=options.host_key) except (IOError, paramiko.SSHException), e: parser.error("host-key-file: %s" % e) if not options.pid_file: options.pid_file = "%s/%s.pid" % (tempfile.gettempdir(), __package__) if options.memcache: CloudFilesFS.memcache_hosts = options.memcache try: CloudFilesFS(None, None) except (ValueError, TypeError): parser.error( "memcache: invalid server address, ip:port expected") else: # default is True, and there's no single worker operation CloudFilesFS.single_cache = False self.pidfile = PIDFile(options.pid_file) if self.pidfile.is_locked(): parser.error("pid-file found: %s\nIs the server already running?" % options.pid_file) options.max_children = config.get('sftpcloudfs', 'max-children') self.options = options