@@ -0,0 +1,3002 @@
+%22%22%22 This module contains two distinct ident server implemtations: %0A%60%60IdentServer%60%60 and %60%60FakeIdentServer%60%60. IdentServer is a fully functional %0A(RFC-1413 compatible) ident server for Unix machines. FakeIdentServer can be %0Aused instead in order to specify your own output data. Typically, this is ideal.%0A%0A%22%22%22%0Aimport asyncore, asynchat%0Aimport os%0A%0A%0Adef get_operating_system():%0A    %22%22%22 Retreives an RFC-1340 compliant name of the operating system. If a name%0A    doesn't seem to be available, then UNKNOWN is returned instead. This%0A    function is limited by the possibilities of os.name values.%0A    %22%22%22%0A    os_map = %7B%0A        %22nt%22: %22WIN32%22,%0A        %22posix%22: %22UNIX%22,%0A        %22mac%22: %22MACOS%22,%0A        %22os2%22: %22OS/2%22,%0A        %22ce%22: %22WIN32%22%0A        %7D%0A    return os_map.get(os.name, %22UNKNOWN%22)%0A%0A%0A%0Adef generate_fake_userid():%0A    %22%22%22 Create a fake user id. This gets used when FakeIdentServer is being used%0A    and the userid was initially set to None. It creates a random UUID as%0A    specified by RFC 4122.%0A    %22%22%22%0A    return str(uuid.uuid4())%0A%0A%0A%0Aclass _IdentChannel(asynchat.async_chat):%0A    %22%22%22 An instance of _IdentChannel represents a single request from a client%0A    to the IdentServer. It isn't designed to be used directly.%0A    %22%22%22%0A    %0A    def __init__(self, server, sock, addr):%0A        %22%22%22 Set up the object by specifying the terminator and initializing the%0A        input buffer and using the socket passed from the dispatcher. The %0A        terminator for the ident protocol is CR+LF.%0A        %22%22%22%0A        asynchat.async_chat.__init__(self, sock)%0A        self.set_terminator(%22%5Cr%5Cn%22)%0A        self.server = server%0A%0A    def found_terminator(self):%0A        %22%22%22 When this is activated, it means that the terminator (%5Cr%5Cn) has been%0A        read. When that happens, we get the input data, clear the buffer,%0A        and then handle the data collected.%0A        %22%22%22%0A        response = self.handle_request(%22%22.join(self.incoming))%0A        self.incoming = %5B%5D%0A        self.push(%22:%22.join(response))%0A        self.close_when_done()%0A    %0A    def handle_request(self, request):%0A        if self.server.response != USERID:%0A            return request, ERROR, self.server.response%0A        %0A        sysos = get_operating_system()%0A        userid = generate_fake_userid()%0A        %0A        return request, %22USERID%22, sysos, userid%0A%0A%0A%0Aclass IdentServer(asyncore.dispatcher):%0A    %22%22%22 A simple and configurable ident server. %22%22%22%0A    %0A    def __init__(self, port=113):%0A        %22%22%22 Create the ident server by creating a typical socket and then %0A        binding it to the port specified. %0A       %0A        %22%22%22%0A        asyncore.dispatcher.__init__(self)%0A        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)%0A        self.bind((%22%22, port))%0A        self.listen(5)%0A%0A    def handle_accept(self):%0A        %22%22%22 Dispatch a request onto an _IdentChannel instance. %22%22%22%0A        _IdentChannel(self, *self.accept())%0A    %0A    def start(self):%0A        %22%22%22 Begin serving ident requests on the port specified. %22%22%22%0A        asyncore.loop(map=self._map)

Cut out the fat from the ident