本文整理匯總了Python中pykolab.auth.Auth.disconnect方法的典型用法代碼示例。如果您正苦於以下問題:Python Auth.disconnect方法的具體用法?Python Auth.disconnect怎麽用?Python Auth.disconnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pykolab.auth.Auth
的用法示例。
在下文中一共展示了Auth.disconnect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: do_saslauthd
# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import disconnect [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 disconnect [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()