| 1 | /* auth-methods.h - Auth method definitions (Poldi) |
| 2 | Copyright (C) 2008 g10 Code GmbH |
| 3 | |
| 4 | This file is part of Poldi. |
| 5 | |
| 6 | Poldi is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | Poldi is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, see |
| 18 | <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #ifndef POLDI_AUTH_METHODS_H |
| 21 | #define POLDI_AUTH_METHODS_H |
| 22 | |
| 23 | #include <poldi.h> |
| 24 | |
| 25 | #include <util/simpleparse.h> |
| 26 | |
| 27 | #include "auth-support/ctx.h" |
| 28 | |
| 29 | |
| 30 | |
| 31 | /* This function is called at initialization time (before |
| 32 | authentication method specific argument parsing is done) in order |
| 33 | to properly setup an authentication method specific cookie |
| 34 | object. */ |
| 35 | typedef gpg_error_t (*auth_method_func_init_t) (void **cookie); |
| 36 | |
| 37 | /* This function is called after an authentication run in order to |
| 38 | free any resources allocated through the call to the initialization |
| 39 | function. */ |
| 40 | typedef void (*auth_method_func_deinit_t) (void *cookie); |
| 41 | |
| 42 | /* Try to authenticate a user. The user's identity on the system is |
| 43 | figured out during the authentication process. COOKIE is the |
| 44 | cookie for this authentication method. CTX is the Poldi context |
| 45 | object. On successful authentication, the newly allocated username |
| 46 | as which the user has been authenticated is stored in *USERNAME. |
| 47 | Returns TRUE on success, FALSE on failure. */ |
| 48 | typedef int (*auth_method_func_auth_t) (poldi_ctx_t ctx, void *cookie, |
| 49 | char **username); |
| 50 | |
| 51 | /* Try to authenticate a user as USERNAME. COOKIE is the cookie for |
| 52 | this authentication method. CTX is the Poldi context object. |
| 53 | Returns TRUE on success, FALSE on failure. */ |
| 54 | typedef int (*auth_method_func_auth_as_t) (poldi_ctx_t ctx, void *cookie, |
| 55 | const char *username); |
| 56 | |
| 57 | struct auth_method_parse_cookie |
| 58 | { |
| 59 | poldi_ctx_t poldi_ctx; |
| 60 | void *method_ctx; |
| 61 | }; |
| 62 | |
| 63 | /* Each authentication method must define one such object. */ |
| 64 | struct auth_method_s |
| 65 | { |
| 66 | auth_method_func_init_t func_init; |
| 67 | auth_method_func_deinit_t func_deinit; |
| 68 | auth_method_func_auth_t func_auth; |
| 69 | auth_method_func_auth_as_t func_auth_as; |
| 70 | simpleparse_opt_spec_t *opt_specs; |
| 71 | simpleparse_parse_cb_t parsecb; |
| 72 | const char *config; |
| 73 | }; |
| 74 | |
| 75 | typedef struct auth_method_s *auth_method_t; |
| 76 | |
| 77 | #endif |