diff options
Diffstat (limited to 'ident/ident.c')
-rw-r--r-- | ident/ident.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ident/ident.c b/ident/ident.c new file mode 100644 index 0000000..38ae1a8 --- /dev/null +++ b/ident/ident.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* This file is part of GNU Pies. | ||
2 | Copyright (C) 2015 Sergey Poznyakoff | ||
3 | |||
4 | GNU Pies is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Pies is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "ident.h" | ||
18 | |||
19 | pies_identity_t | ||
20 | pies_identity_create (char const *user) | ||
21 | { | ||
22 | pies_identity_t id = xmalloc (sizeof (*id)); | ||
23 | id->provider = NULL; | ||
24 | id->username = xstrdup (user); | ||
25 | id->data = NULL; | ||
26 | return id; | ||
27 | } | ||
28 | |||
29 | int | ||
30 | pies_authenticate (pies_identity_provider_t pr, pies_identity_t id, | ||
31 | char const *passwd) | ||
32 | { | ||
33 | if (!pr || !id) | ||
34 | return -1; | ||
35 | |||
36 | if (pr->mech->authenticate (pr, id, passwd) == 0) | ||
37 | { | ||
38 | id->provider = pr; | ||
39 | return 0; | ||
40 | } | ||
41 | return 1; | ||
42 | } | ||
43 | |||
44 | int | ||
45 | pies_identity_is_user (pies_identity_t id, char * const * users) | ||
46 | { | ||
47 | if (!id) | ||
48 | return 0; | ||
49 | return is_array_member (users, id->username); | ||
50 | } | ||
51 | |||
52 | int | ||
53 | pies_identity_is_group_member (pies_identity_t id, char * const * groups) | ||
54 | { | ||
55 | pies_identity_provider_t provider; | ||
56 | if (!id) | ||
57 | return 0; | ||
58 | provider = id->provider; | ||
59 | if (!provider) | ||
60 | return 0; | ||
61 | return provider->mech->is_group_member (provider, id, groups); | ||
62 | } | ||
63 | |||
64 | void | ||
65 | pies_identity_destroy (pies_identity_t id) | ||
66 | { | ||
67 | pies_identity_provider_t provider = id->provider; | ||
68 | if (provider && provider->mech->destroy_identity) | ||
69 | provider->mech->destroy_identity (provider, id); | ||
70 | free (id); | ||
71 | } | ||
72 | |||
73 | |||
74 | |||