本文整理汇总了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()
示例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()