You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

service.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. The parent class for all the SSH services. Currently implemented services
  5. are ssh-userauth and ssh-connection.
  6. Maintainer: Paul Swartz
  7. """
  8. from __future__ import division, absolute_import
  9. from twisted.python import log
  10. class SSHService(log.Logger):
  11. name = None # this is the ssh name for the service
  12. protocolMessages = {} # these map #'s -> protocol names
  13. transport = None # gets set later
  14. def serviceStarted(self):
  15. """
  16. called when the service is active on the transport.
  17. """
  18. def serviceStopped(self):
  19. """
  20. called when the service is stopped, either by the connection ending
  21. or by another service being started
  22. """
  23. def logPrefix(self):
  24. return "SSHService %r on %s" % (self.name,
  25. self.transport.transport.logPrefix())
  26. def packetReceived(self, messageNum, packet):
  27. """
  28. called when we receive a packet on the transport
  29. """
  30. #print self.protocolMessages
  31. if messageNum in self.protocolMessages:
  32. messageType = self.protocolMessages[messageNum]
  33. f = getattr(self,'ssh_%s' % messageType[4:],
  34. None)
  35. if f is not None:
  36. return f(packet)
  37. log.msg("couldn't handle %r" % messageNum)
  38. log.msg(repr(packet))
  39. self.transport.sendUnimplemented()