| 1 | /* ctx.h - Poldi context structure. |
| 2 | Copyright (C) 2008, 2009 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_CTX_H |
| 21 | #define POLDI_CTX_H |
| 22 | |
| 23 | #define PAM_SM_AUTH |
| 24 | #include <security/pam_modules.h> |
| 25 | |
| 26 | #include <util/simplelog.h> |
| 27 | #include <util/simpleparse.h> |
| 28 | |
| 29 | #include "scd/scd.h" |
| 30 | #include "auth-support/conv.h" |
| 31 | |
| 32 | /* We use a "context" object in Poldi, since a PAM Module should not |
| 33 | contain static variables. (In theory) this allows for a |
| 34 | multithreaded application to authenticate users concurrently. |
| 35 | |
| 36 | There are certain objects which are to be accessed by many |
| 37 | functions contained in Poldi, like: debug flag, pam_handle, scd, |
| 38 | logging stream, etc. |
| 39 | |
| 40 | So we have two choices: either these variables are globally visible |
| 41 | or they are allocated in pam_sm_authenticate() and passed down to |
| 42 | each function. For the above mentioned reasons, solution one is not |
| 43 | applicable for a PAM module. Therefore we need go down route two. |
| 44 | But surely we do not want to pass each and every of the useful |
| 45 | variables down to every function, thus we encapsulate everything |
| 46 | which might be useful to other functions in a context object. |
| 47 | Then, this context object (allocated and dealloacted in |
| 48 | pam_sm_authenticate) is passed down. |
| 49 | */ |
| 50 | |
| 51 | struct poldi_ctx_s |
| 52 | { |
| 53 | /* Options. */ |
| 54 | |
| 55 | char *logfile; |
| 56 | log_handle_t loghandle; /* Our handle for simplelog. */ |
| 57 | simpleparse_handle_t parsehandle; /* Handle for simpleparse. */ |
| 58 | int auth_method; /* The ID of the authentication method |
| 59 | in use. */ |
| 60 | void *cookie; /* Cookie for authentication |
| 61 | method. */ |
| 62 | |
| 63 | int debug; /* Debug flag. If true, functions |
| 64 | should emmit debugging |
| 65 | messages. */ |
| 66 | int modify_environment; /* Set Poldi-related variables in the |
| 67 | PAM environment. */ |
| 68 | int quiet; /* Be more quiet during PAM |
| 69 | conversation with user. */ |
| 70 | int use_agent; /* Use gpg-agent to connect scdaemon. */ |
| 71 | |
| 72 | /* Scdaemon. */ |
| 73 | char *scdaemon_program; /* Path of Scdaemon program to execute. */ |
| 74 | char *scdaemon_options; /* Path of Scdaemon configuration file. */ |
| 75 | scd_context_t scd; /* Handle for the Scdaemon access |
| 76 | layer. */ |
| 77 | |
| 78 | pam_handle_t *pam_handle; /* PAM handle. */ |
| 79 | |
| 80 | conv_t conv; /* Handle for the conv(ersation) |
| 81 | subsystem. */ |
| 82 | |
| 83 | /* PAM username. */ |
| 84 | const char *username; /* Username retrieved by PAM. */ |
| 85 | |
| 86 | struct scd_cardinfo cardinfo; /* Smartcard information |
| 87 | structure. */ |
| 88 | }; |
| 89 | |
| 90 | typedef struct poldi_ctx_s *poldi_ctx_t; |
| 91 | |
| 92 | #endif |