(authority_authenticate): Authentication methods are now stored as a list.
Showing
1 changed file
with
35 additions
and
6 deletions
... | @@ -24,9 +24,9 @@ | ... | @@ -24,9 +24,9 @@ |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #include <mailutils/errno.h> | ||
27 | #include <auth0.h> | 28 | #include <auth0.h> |
28 | 29 | ||
29 | |||
30 | static int | 30 | static int |
31 | _authenticate_null (authority_t auth ARG_UNUSED) | 31 | _authenticate_null (authority_t auth ARG_UNUSED) |
32 | { | 32 | { |
... | @@ -37,9 +37,9 @@ int | ... | @@ -37,9 +37,9 @@ int |
37 | authority_create_null (authority_t *pauthority, void *owner) | 37 | authority_create_null (authority_t *pauthority, void *owner) |
38 | { | 38 | { |
39 | int rc = authority_create(pauthority, NULL, owner); | 39 | int rc = authority_create(pauthority, NULL, owner); |
40 | if(rc) | 40 | if (rc) |
41 | return rc; | 41 | return rc; |
42 | (*pauthority)->_authenticate = _authenticate_null; | 42 | authority_set_authenticate (*pauthority, _authenticate_null, owner); |
43 | return 0; | 43 | return 0; |
44 | } | 44 | } |
45 | 45 | ||
... | @@ -105,12 +105,35 @@ authority_get_ticket (authority_t authority, ticket_t *pticket) | ... | @@ -105,12 +105,35 @@ authority_get_ticket (authority_t authority, ticket_t *pticket) |
105 | return 0; | 105 | return 0; |
106 | } | 106 | } |
107 | 107 | ||
108 | struct auth_cb | ||
109 | { | ||
110 | int status; | ||
111 | authority_t authority; | ||
112 | }; | ||
113 | |||
114 | static int | ||
115 | try_auth (void *item, void *data) | ||
116 | { | ||
117 | int (*authenticate) __P ((authority_t)) = item; | ||
118 | struct auth_cb *cb = data; | ||
119 | if (authenticate (cb->authority) == 0) | ||
120 | { | ||
121 | cb->status = 0; | ||
122 | return 1; | ||
123 | } | ||
124 | return 0; | ||
125 | } | ||
126 | |||
108 | int | 127 | int |
109 | authority_authenticate (authority_t authority) | 128 | authority_authenticate (authority_t authority) |
110 | { | 129 | { |
111 | if (authority && authority->_authenticate) | 130 | if (authority && authority->auth_methods) |
112 | { | 131 | { |
113 | return authority->_authenticate (authority); | 132 | struct auth_cb cb; |
133 | cb.status = MU_ERR_AUTH_FAILURE; | ||
134 | cb.authority = authority; | ||
135 | list_do (authority->auth_methods, try_auth, &cb); | ||
136 | return cb.status; | ||
114 | } | 137 | } |
115 | return EINVAL; | 138 | return EINVAL; |
116 | } | 139 | } |
... | @@ -125,6 +148,12 @@ authority_set_authenticate (authority_t authority, | ... | @@ -125,6 +148,12 @@ authority_set_authenticate (authority_t authority, |
125 | 148 | ||
126 | if (authority->owner != owner) | 149 | if (authority->owner != owner) |
127 | return EACCES; | 150 | return EACCES; |
128 | authority->_authenticate = _authenticate; | 151 | if (!authority->auth_methods) |
152 | { | ||
153 | int rc = list_create (&authority->auth_methods); | ||
154 | if (rc) | ||
155 | return rc; | ||
156 | } | ||
157 | list_append (authority->auth_methods, _authenticate); | ||
129 | return 0; | 158 | return 0; |
130 | } | 159 | } | ... | ... |
-
Please register or sign in to post a comment