[Zope-CVS] CVS: Packages/SFTPGateway/src/sftpgateway - application.py:1.14

Fred L. Drake, Jr. fred at zope.com
Thu Jan 29 10:55:24 EST 2004


Update of /cvs-repository/Packages/SFTPGateway/src/sftpgateway
In directory cvs.zope.org:/tmp/cvs-serv21635

Modified Files:
	application.py 
Log Message:
make sure we reasonable report and log errors reading the key files


=== Packages/SFTPGateway/src/sftpgateway/application.py 1.13 => 1.14 ===
--- Packages/SFTPGateway/src/sftpgateway/application.py:1.13	Mon Jan  5 17:33:44 2004
+++ Packages/SFTPGateway/src/sftpgateway/application.py	Thu Jan 29 10:55:22 2004
@@ -17,6 +17,7 @@
 import logging
 import os
 import pwd
+import sys
 
 import ZConfig
 
@@ -31,7 +32,6 @@
 class Application:
     def __init__(self, options):
         self.logger = options.logger
-        log.startLogging(log.NullFile())
         self.options = options
         self.portal = authentication.createPortal()
         self._child_logger_info = {}
@@ -42,7 +42,15 @@
         host = host or ""
         if not port:
             port = 22
-        factory = SFTPFactory(self)
+        try:
+            factory = SFTPFactory(self)
+        except IOError, e:
+            print >>sys.stderr, \
+                  "could not load key file: %s" % e.filename
+            print >>sys.stderr, e.strerror
+            self.error("could not load key file: %s" % str(e))
+            self.error("failed to start SFTP Gateway")
+            return 1
         self.info("starting; listening on %s:%s", host, port)
         user = self.options.effective_user
         if user:
@@ -57,6 +65,7 @@
                 os.seteuid(euid)
         else:
             reactor.listenTCP(port, factory, interface=host)
+        log.startLogging(log.NullFile())
         reactor.run()
         self.info("stopping")
         return 0
@@ -166,22 +175,30 @@
             'ssh-userauth': userauth.SSHUserAuthServer,
             'ssh-connection': makeConnection,
             }
-
-    def buildProtocol(self, address):
-        self.app.debug("received connection from %s:%s" % address)
-        return factory.SSHFactory.buildProtocol(self, address)
-
-    def getPrivateKeys(self):
+        #
+        # Load the keys early so we can report failures during startup
+        # more sensibly than after the reactor has started running.
+        #
+        # load the private key:
         o = keys.getPrivateKeyObject(filename=self.privkeyfile)
         t = keys.objectType(o)
         self.app.debug("loaded %s private key from %s"
-                          % (t, self.privkeyfile))
-        return {t: o}
-
-    def getPublicKeys(self):
+                       % (t, self.privkeyfile))
+        self.__private_keys = {t: o}
+        # load the public key:
         s = keys.getPublicKeyString(filename=self.pubkeyfile)
         o = keys.getPublicKeyObject(s)
         t = keys.objectType(o)
         self.app.debug("loaded %s public key from %s"
                           % (t, self.pubkeyfile))
-        return {t: s}
+        self.__public_keys = {t: s}
+
+    def buildProtocol(self, address):
+        self.app.debug("received connection from %s:%s" % address)
+        return factory.SSHFactory.buildProtocol(self, address)
+
+    def getPrivateKeys(self):
+        return self.__private_keys.copy()
+
+    def getPublicKeys(self):
+        return self.__public_keys.copy()




More information about the Zope-CVS mailing list