auth.py
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import auth
from mailutils.error import AuthError
MU_AF_QUOTA = 0x1
def register_module (name = None):
if name == None:
status = auth.register_module ()
elif isinstance (name, types.TupleType) \
or isinstance (name, types.ListType):
for n in name:
status = auth.register_module (n)
else:
status = auth.register_module (name)
if status:
raise AuthError (status)
def get_auth_by_name (username):
return auth.get_auth_by_name (username)
def get_auth_by_uid (uid):
return auth.get_auth_by_uid (uid)
def authenticate (auth_data, password):
status = auth.authenticate (auth_data, password)
if status:
raise AuthError (status)
def set_pam_service (pam_service):
auth.set_pam_service (pam_service)
class Authority:
__owner = False
def __init__ (self, authority = None):
if isinstance (authority, auth.AuthorityType):
self.authority = authority
else:
self.authority = auth.AuthorityType ()
self.__owner = True
status = auth.authority_create (self.authority)
if status:
raise AuthError (status)
def __del__ (self):
if self.__owner:
auth.authority_destroy (self.authority)
del self.authority
def get_ticket (self):
status, ticket = auth.authority_get_ticket (self.authority)
if status:
raise AuthError (status)
return Ticket (ticket)
def set_ticket (self, ticket):
status = auth.authority_set_ticket (self.authority, ticket.ticket)
if status:
raise AuthError (status)
def authenticate (self):
status = auth.authority_authenticate (self.authority)
if status:
raise AuthError (status)
class Ticket:
__owner = False
def __init__ (self, ticket = None):
if isinstance (ticket, auth.TicketType):
self.ticket = ticket
else:
self.ticket = auth.TicketType ()
self.__owner = True
status = auth.ticket_create (self.ticket)
if status:
raise AuthError (status)
def __del__ (self):
if self.__owner:
auth.ticket_destroy (self.ticket)
del self.ticket
def set_secret (self, secret):
status = auth.ticket_set_secret (self.ticket, secret.secret)
if status:
raise AuthError (status)
class Wicket:
__owner = False
def __init__ (self, wicket = None):
if isinstance (wicket, auth.WicketType):
self.wicket = wicket
else:
self.wicket = auth.WicketType ()
self.__owner = True
status = auth.wicket_create (self.wicket)
if status:
raise AuthError (status)
def __del__ (self):
if self.__owner:
auth.wicket_destroy (self.wicket)
del self.wicket
def get_ticket (self, user):
status, ticket = auth.wicket_get_ticket (self.wicket, user)
if status:
raise AuthError (status)
return Ticket (ticket)