| 1 | /*- |
|---|
| 2 | * Copyright (c) 2002 Networks Associates Technology, Inc. |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | * |
|---|
| 5 | * This software was developed for the FreeBSD Project by ThinkSec AS and |
|---|
| 6 | * NAI Labs, the Security Research Division of Network Associates, Inc. |
|---|
| 7 | * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the |
|---|
| 8 | * DARPA CHATS research program. |
|---|
| 9 | * |
|---|
| 10 | * Redistribution and use in source and binary forms, with or without |
|---|
| 11 | * modification, are permitted provided that the following conditions |
|---|
| 12 | * are met: |
|---|
| 13 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 14 | * notice, this list of conditions and the following disclaimer. |
|---|
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 16 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 17 | * documentation and/or other materials provided with the distribution. |
|---|
| 18 | * 3. The name of the author may not be used to endorse or promote |
|---|
| 19 | * products derived from this software without specific prior written |
|---|
| 20 | * permission. |
|---|
| 21 | * |
|---|
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|---|
| 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|---|
| 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|---|
| 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|---|
| 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|---|
| 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|---|
| 32 | * SUCH DAMAGE. |
|---|
| 33 | * |
|---|
| 34 | * $P4: //depot/projects/openpam/include/security/openpam.h#12 $ |
|---|
| 35 | */ |
|---|
| 36 | |
|---|
| 37 | #ifndef _SECURITY_OPENPAM_H_INCLUDED |
|---|
| 38 | #define _SECURITY_OPENPAM_H_INCLUDED |
|---|
| 39 | |
|---|
| 40 | /* |
|---|
| 41 | * Annoying but necessary header pollution |
|---|
| 42 | */ |
|---|
| 43 | #include <stdarg.h> |
|---|
| 44 | |
|---|
| 45 | #ifdef __cplusplus |
|---|
| 46 | extern "C" { |
|---|
| 47 | #endif |
|---|
| 48 | |
|---|
| 49 | /* |
|---|
| 50 | * API extensions |
|---|
| 51 | */ |
|---|
| 52 | const char * |
|---|
| 53 | openpam_get_option(pam_handle_t *_pamh, |
|---|
| 54 | const char *_option); |
|---|
| 55 | |
|---|
| 56 | int |
|---|
| 57 | openpam_set_option(pam_handle_t *_pamh, |
|---|
| 58 | const char *_option, |
|---|
| 59 | const char *_value); |
|---|
| 60 | |
|---|
| 61 | int |
|---|
| 62 | pam_error(pam_handle_t *_pamh, |
|---|
| 63 | const char *_fmt, |
|---|
| 64 | ...); |
|---|
| 65 | |
|---|
| 66 | int |
|---|
| 67 | pam_get_authtok(pam_handle_t *_pamh, |
|---|
| 68 | const char **_authtok, |
|---|
| 69 | const char *_prompt); |
|---|
| 70 | |
|---|
| 71 | int |
|---|
| 72 | pam_info(pam_handle_t *_pamh, |
|---|
| 73 | const char *_fmt, |
|---|
| 74 | ...); |
|---|
| 75 | |
|---|
| 76 | int |
|---|
| 77 | pam_prompt(pam_handle_t *_pamh, |
|---|
| 78 | int _style, |
|---|
| 79 | char **_resp, |
|---|
| 80 | const char *_fmt, |
|---|
| 81 | ...); |
|---|
| 82 | |
|---|
| 83 | int |
|---|
| 84 | pam_setenv(pam_handle_t *_pamh, |
|---|
| 85 | const char *_name, |
|---|
| 86 | const char *_value, |
|---|
| 87 | int _overwrite); |
|---|
| 88 | |
|---|
| 89 | int |
|---|
| 90 | pam_vinfo(pam_handle_t *_pamh, |
|---|
| 91 | const char *_fmt, |
|---|
| 92 | va_list _ap); |
|---|
| 93 | |
|---|
| 94 | int |
|---|
| 95 | pam_verror(pam_handle_t *_pamh, |
|---|
| 96 | const char *_fmt, |
|---|
| 97 | va_list _ap); |
|---|
| 98 | |
|---|
| 99 | int |
|---|
| 100 | pam_vprompt(pam_handle_t *_pamh, |
|---|
| 101 | int _style, |
|---|
| 102 | char **_resp, |
|---|
| 103 | const char *_fmt, |
|---|
| 104 | va_list _ap); |
|---|
| 105 | |
|---|
| 106 | /* |
|---|
| 107 | * Log levels |
|---|
| 108 | */ |
|---|
| 109 | enum { |
|---|
| 110 | PAM_LOG_DEBUG, |
|---|
| 111 | PAM_LOG_VERBOSE, |
|---|
| 112 | PAM_LOG_NOTICE, |
|---|
| 113 | PAM_LOG_ERROR |
|---|
| 114 | }; |
|---|
| 115 | |
|---|
| 116 | /* |
|---|
| 117 | * Log to syslog |
|---|
| 118 | */ |
|---|
| 119 | void _openpam_log(int _level, |
|---|
| 120 | const char *_func, |
|---|
| 121 | const char *_fmt, |
|---|
| 122 | ...); |
|---|
| 123 | |
|---|
| 124 | #if defined(__STDC__) && (__STDC_VERSION__ > 199901L) |
|---|
| 125 | #define openpam_log(lvl, fmt, ...) \ |
|---|
| 126 | _openpam_log((lvl), __func__, fmt, __VA_ARGS__) |
|---|
| 127 | #elif defined(__GNUC__) |
|---|
| 128 | #define openpam_log(lvl, fmt...) \ |
|---|
| 129 | _openpam_log((lvl), __func__, ##fmt) |
|---|
| 130 | #else |
|---|
| 131 | extern openpam_log(int _level, const char *_format, ...); |
|---|
| 132 | #endif |
|---|
| 133 | |
|---|
| 134 | /* |
|---|
| 135 | * Generic conversation function |
|---|
| 136 | */ |
|---|
| 137 | struct pam_message; |
|---|
| 138 | struct pam_response; |
|---|
| 139 | int openpam_ttyconv(int _n, |
|---|
| 140 | const struct pam_message **_msg, |
|---|
| 141 | struct pam_response **_resp, |
|---|
| 142 | void *_data); |
|---|
| 143 | |
|---|
| 144 | /* |
|---|
| 145 | * PAM primitives |
|---|
| 146 | */ |
|---|
| 147 | enum { |
|---|
| 148 | PAM_SM_AUTHENTICATE, |
|---|
| 149 | PAM_SM_SETCRED, |
|---|
| 150 | PAM_SM_ACCT_MGMT, |
|---|
| 151 | PAM_SM_OPEN_SESSION, |
|---|
| 152 | PAM_SM_CLOSE_SESSION, |
|---|
| 153 | PAM_SM_CHAUTHTOK, |
|---|
| 154 | /* keep this last */ |
|---|
| 155 | PAM_NUM_PRIMITIVES |
|---|
| 156 | }; |
|---|
| 157 | |
|---|
| 158 | /* |
|---|
| 159 | * Dummy service module function |
|---|
| 160 | */ |
|---|
| 161 | #define PAM_SM_DUMMY(type) \ |
|---|
| 162 | PAM_EXTERN int \ |
|---|
| 163 | pam_sm_##type(pam_handle_t *pamh, int flags, \ |
|---|
| 164 | int argc, const char *argv[]) \ |
|---|
| 165 | { \ |
|---|
| 166 | return (PAM_IGNORE); \ |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /* |
|---|
| 170 | * PAM service module functions match this typedef |
|---|
| 171 | */ |
|---|
| 172 | struct pam_handle; |
|---|
| 173 | typedef int (*pam_func_t)(struct pam_handle *, int, int, const char **); |
|---|
| 174 | |
|---|
| 175 | /* |
|---|
| 176 | * A struct that describes a module. |
|---|
| 177 | */ |
|---|
| 178 | typedef struct pam_module pam_module_t; |
|---|
| 179 | struct pam_module { |
|---|
| 180 | char *path; |
|---|
| 181 | pam_func_t func[PAM_NUM_PRIMITIVES]; |
|---|
| 182 | void *dlh; |
|---|
| 183 | int refcount; |
|---|
| 184 | pam_module_t *prev; |
|---|
| 185 | pam_module_t *next; |
|---|
| 186 | }; |
|---|
| 187 | |
|---|
| 188 | /* |
|---|
| 189 | * Infrastructure for static modules using GCC linker sets. |
|---|
| 190 | * You are not expected to understand this. |
|---|
| 191 | */ |
|---|
| 192 | #if defined(__GNUC__) && !defined(__PIC__) |
|---|
| 193 | #if defined(__FreeBSD__) |
|---|
| 194 | #define PAM_SOEXT ".so" |
|---|
| 195 | #else |
|---|
| 196 | #error Static linking is not supported on your platform |
|---|
| 197 | #endif |
|---|
| 198 | /* gcc, static linking */ |
|---|
| 199 | #include <sys/cdefs.h> |
|---|
| 200 | #include <linker_set.h> |
|---|
| 201 | #define OPENPAM_STATIC_MODULES |
|---|
| 202 | #define PAM_EXTERN static |
|---|
| 203 | #define PAM_MODULE_ENTRY(name) \ |
|---|
| 204 | static char _pam_name[] = name PAM_SOEXT; \ |
|---|
| 205 | static struct pam_module _pam_module = { _pam_name, { \ |
|---|
| 206 | pam_sm_authenticate, pam_sm_setcred, pam_sm_acct_mgmt, \ |
|---|
| 207 | pam_sm_open_session, pam_sm_close_session, pam_sm_chauthtok }, \ |
|---|
| 208 | NULL, 0, NULL, NULL }; \ |
|---|
| 209 | DATA_SET(_openpam_static_modules, _pam_module) |
|---|
| 210 | #else |
|---|
| 211 | /* normal case */ |
|---|
| 212 | #define PAM_EXTERN |
|---|
| 213 | #define PAM_MODULE_ENTRY(name) |
|---|
| 214 | #endif |
|---|
| 215 | |
|---|
| 216 | #ifdef __cplusplus |
|---|
| 217 | } |
|---|
| 218 | #endif |
|---|
| 219 | |
|---|
| 220 | #endif |
|---|