當前位置: 首頁>>代碼示例>>Python>>正文


Python Auth.authenticate方法代碼示例

本文整理匯總了Python中pykolab.auth.Auth.authenticate方法的典型用法代碼示例。如果您正苦於以下問題:Python Auth.authenticate方法的具體用法?Python Auth.authenticate怎麽用?Python Auth.authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pykolab.auth.Auth的用法示例。


在下文中一共展示了Auth.authenticate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: do_saslauthd

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import authenticate [as 別名]
    def do_saslauthd(self):
        """
            Create the actual listener socket, and handle the authentication.

            The actual authentication handling is passed on to the appropriate
            backend authentication classes through the more generic Auth().
        """
        import binascii
        import socket
        import struct

        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

        # TODO: The saslauthd socket path could be a setting.
        try:
            os.remove(conf.socketfile)
        except:
            # TODO: Do the "could not remove, could not start" dance
            pass

        s.bind(conf.socketfile)
        os.chmod(conf.socketfile, 0777)

        s.listen(5)

        while 1:
            max_tries = 20
            cur_tries = 0
            bound = False
            while not bound:
                cur_tries += 1
                try:
                    (clientsocket, address) = s.accept()
                    bound = True
                except Exception, errmsg:
                    log.error(
                            _("kolab-saslauthd could not accept " + \
                            "connections on socket: %r") % (errmsg)
                        )

                    if cur_tries >= max_tries:
                        log.fatal(_("Maximum tries exceeded, exiting"))
                        sys.exit(1)

                    time.sleep(1)

            received = clientsocket.recv(4096)

            login = []

            start = 0
            end = 2

            while end < len(received):
                (length,) = struct.unpack("!H", received[start:end])
                start += 2
                end += length
                (value,) = struct.unpack("!%ds" % (length), received[start:end])
                start += length
                end = start + 2
                login.append(value)

            if len(login) == 4:
                realm = login[3]
            elif len(login[0].split('@')) > 1:
                realm = login[0].split('@')[1]
            else:
                realm = conf.get('kolab', 'primary_domain')

            auth = Auth(domain=realm)
            auth.connect()

            success = False

            try:
                success = auth.authenticate(login)
            except:
                success = False

            if success:
                # #1170: Catch broken pipe error (incomplete authentication request)
                try:
                    clientsocket.send(struct.pack("!H2s", 2, "OK"))
                except:
                    pass
            else:
                # #1170: Catch broken pipe error (incomplete authentication request)
                try:
                    clientsocket.send(struct.pack("!H2s", 2, "NO"))
                except:
                    pass

            clientsocket.close()
            auth.disconnect()
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:96,代碼來源:__init__.py

示例2: do_saslauthd

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import authenticate [as 別名]
    def do_saslauthd(self):
        """
            Create the actual listener socket, and handle the authentication.

            The actual authentication handling is passed on to the appropriate
            backend authentication classes through the more generic Auth().
        """
        import binascii
        import socket
        import struct

        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

        utils.ensure_directory(
                '/var/run/saslauthd/',
                conf.process_username,
                conf.process_groupname
            )

        # TODO: The saslauthd socket path could be a setting.
        try:
            os.remove('/var/run/saslauthd/mux')
        except:
            # TODO: Do the "could not remove, could not start" dance
            pass

        s.bind('/var/run/saslauthd/mux')
        os.chmod('/var/run/saslauthd/mux', 0777)

        s.listen(5)

        while 1:
            (clientsocket, address) = s.accept()
            received = clientsocket.recv(4096)

            login = []

            start = 0
            end = 2

            while end < len(received):
                (length,) = struct.unpack("!H", received[start:end])
                start += 2
                end += length
                (value,) = struct.unpack("!%ds" % (length), received[start:end])
                start += length
                end = start + 2
                login.append(value)

            if len(login) == 4:
                realm = login[3]
            elif len(login[0].split('@')) > 1:
                realm = login[0].split('@')[1]
            else:
                realm = conf.get('kolab', 'primary_domain')

            auth = Auth(domain=realm)
            auth.connect()

            if auth.authenticate(login):
                # #1170: Catch broken pipe error (incomplete authentication request)
                try:
                    clientsocket.send(struct.pack("!H2s", 2, "OK"))
                except:
                    pass
            else:
                # #1170: Catch broken pipe error (incomplete authentication request)
                try:
                    clientsocket.send(struct.pack("!H2s", 2, "NO"))
                except:
                    pass

            clientsocket.close()
            auth.disconnect()
開發者ID:detrout,項目名稱:pykolab,代碼行數:76,代碼來源:__init__.py


注:本文中的pykolab.auth.Auth.authenticate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。