source: openpam/trunk/include/security/openpam.h @ 400

Last change on this file since 400 was 400, checked in by Dag-Erling Smørgrav, 12 years ago

Constify.

  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1/*-
2 * Copyright (c) 2002-2003 Networks Associates Technology, Inc.
3 * All rights reserved.
4 *
5 * This software was developed for the FreeBSD Project by ThinkSec AS and
6 * Network Associates Laboratories, the Security Research Division of
7 * Network Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
8 * ("CBOSS"), as part of the 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 * $Id: openpam.h 400 2007-10-24 15:04:23Z des $
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#include <security/pam_attributes.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51struct passwd;
52
53/*
54 * API extensions
55 */
56int
57openpam_borrow_cred(pam_handle_t *_pamh,
58        const struct passwd *_pwd)
59        OPENPAM_NONNULL((1,2));
60
61void
62openpam_free_data(pam_handle_t *_pamh,
63        void *_data,
64        int _status);
65
66void
67openpam_free_envlist(char **_envlist);
68
69const char *
70openpam_get_option(pam_handle_t *_pamh,
71        const char *_option);
72
73int
74openpam_restore_cred(pam_handle_t *_pamh)
75        OPENPAM_NONNULL((1));
76
77int
78openpam_set_option(pam_handle_t *_pamh,
79        const char *_option,
80        const char *_value);
81
82int
83pam_error(const pam_handle_t *_pamh,
84        const char *_fmt,
85        ...)
86        OPENPAM_FORMAT ((__printf__, 2, 3))
87        OPENPAM_NONNULL((1,2));
88
89int
90pam_get_authtok(pam_handle_t *_pamh,
91        int _item,
92        const char **_authtok,
93        const char *_prompt)
94        OPENPAM_NONNULL((1,3));
95
96int
97pam_info(const pam_handle_t *_pamh,
98        const char *_fmt,
99        ...)
100        OPENPAM_FORMAT ((__printf__, 2, 3))
101        OPENPAM_NONNULL((1,2));
102
103int
104pam_prompt(const pam_handle_t *_pamh,
105        int _style,
106        char **_resp,
107        const char *_fmt,
108        ...)
109        OPENPAM_FORMAT ((__printf__, 4, 5))
110        OPENPAM_NONNULL((1,4));
111
112int
113pam_setenv(pam_handle_t *_pamh,
114        const char *_name,
115        const char *_value,
116        int _overwrite)
117        OPENPAM_NONNULL((1,2,3));
118
119int
120pam_vinfo(const pam_handle_t *_pamh,
121        const char *_fmt,
122        va_list _ap)
123        OPENPAM_FORMAT ((__printf__, 2, 0))
124        OPENPAM_NONNULL((1,2));
125
126int
127pam_verror(const pam_handle_t *_pamh,
128        const char *_fmt,
129        va_list _ap)
130        OPENPAM_FORMAT ((__printf__, 2, 0))
131        OPENPAM_NONNULL((1,2));
132
133int
134pam_vprompt(const pam_handle_t *_pamh,
135        int _style,
136        char **_resp,
137        const char *_fmt,
138        va_list _ap)
139        OPENPAM_FORMAT ((__printf__, 4, 0))
140        OPENPAM_NONNULL((1,4));
141
142/*
143 * Read cooked lines.
144 * Checking for _IOFBF is a fairly reliable way to detect the presence
145 * of <stdio.h>, as SUSv3 requires it to be defined there.
146 */
147#ifdef _IOFBF
148char *
149openpam_readline(FILE *_f,
150        int *_lineno,
151        size_t *_lenp)
152        OPENPAM_NONNULL((1));
153#endif
154
155/*
156 * Log levels
157 */
158enum {
159        PAM_LOG_DEBUG,
160        PAM_LOG_VERBOSE,
161        PAM_LOG_NOTICE,
162        PAM_LOG_ERROR
163};
164
165/*
166 * Log to syslog
167 */
168void
169_openpam_log(int _level,
170        const char *_func,
171        const char *_fmt,
172        ...)
173        OPENPAM_FORMAT ((__printf__, 3, 4))
174        OPENPAM_NONNULL((3));
175
176#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
177#define openpam_log(lvl, ...) \
178        _openpam_log((lvl), __func__, __VA_ARGS__)
179#elif defined(__GNUC__) && (__GNUC__ >= 3)
180#define openpam_log(lvl, ...) \
181        _openpam_log((lvl), __func__, __VA_ARGS__)
182#elif defined(__GNUC__) && (__GNUC__ >= 2) && (__GNUC_MINOR__ >= 95)
183#define openpam_log(lvl, fmt...) \
184        _openpam_log((lvl), __func__, ##fmt)
185#elif defined(__GNUC__) && defined(__FUNCTION__)
186#define openpam_log(lvl, fmt...) \
187        _openpam_log((lvl), __FUNCTION__, ##fmt)
188#else
189void
190openpam_log(int _level,
191        const char *_format,
192        ...)
193        OPENPAM_FORMAT ((__printf__, 2, 3))
194        OPENPAM_NONNULL((2));
195#endif
196
197/*
198 * Generic conversation function
199 */
200struct pam_message;
201struct pam_response;
202int openpam_ttyconv(int _n,
203        const struct pam_message **_msg,
204        struct pam_response **_resp,
205        void *_data);
206
207extern int openpam_ttyconv_timeout;
208
209/*
210 * Null conversation function
211 */
212int openpam_nullconv(int _n,
213        const struct pam_message **_msg,
214        struct pam_response **_resp,
215        void *_data);
216
217/*
218 * PAM primitives
219 */
220enum {
221        PAM_SM_AUTHENTICATE,
222        PAM_SM_SETCRED,
223        PAM_SM_ACCT_MGMT,
224        PAM_SM_OPEN_SESSION,
225        PAM_SM_CLOSE_SESSION,
226        PAM_SM_CHAUTHTOK,
227        /* keep this last */
228        PAM_NUM_PRIMITIVES
229};
230
231/*
232 * Dummy service module function
233 */
234#define PAM_SM_DUMMY(type)                                              \
235PAM_EXTERN int                                                          \
236pam_sm_##type(pam_handle_t *pamh, int flags,                            \
237    int argc, const char *argv[])                                       \
238{                                                                       \
239        return (PAM_IGNORE);                                            \
240}
241
242/*
243 * PAM service module functions match this typedef
244 */
245struct pam_handle;
246typedef int (*pam_func_t)(struct pam_handle *, int, int, const char **);
247
248/*
249 * A struct that describes a module.
250 */
251typedef struct pam_module pam_module_t;
252struct pam_module {
253        char            *path;
254        pam_func_t       func[PAM_NUM_PRIMITIVES];
255        void            *dlh;
256        int              refcount;
257        pam_module_t    *prev;
258        pam_module_t    *next;
259};
260
261/*
262 * Source-code compatibility with Linux-PAM modules
263 */
264#if defined(PAM_SM_AUTH) || defined(PAM_SM_ACCOUNT) || \
265        defined(PAM_SM_SESSION) || defined(PAM_SM_PASSWORD)
266#define LINUX_PAM_MODULE
267#endif
268#if defined(LINUX_PAM_MODULE) && !defined(PAM_SM_AUTH)
269#define _PAM_SM_AUTHENTICATE    0
270#define _PAM_SM_SETCRED         0
271#else
272#undef PAM_SM_AUTH
273#define PAM_SM_AUTH
274#define _PAM_SM_AUTHENTICATE    pam_sm_authenticate
275#define _PAM_SM_SETCRED         pam_sm_setcred
276#endif
277#if defined(LINUX_PAM_MODULE) && !defined(PAM_SM_ACCOUNT)
278#define _PAM_SM_ACCT_MGMT       0
279#else
280#undef PAM_SM_ACCOUNT
281#define PAM_SM_ACCOUNT
282#define _PAM_SM_ACCT_MGMT       pam_sm_acct_mgmt
283#endif
284#if defined(LINUX_PAM_MODULE) && !defined(PAM_SM_SESSION)
285#define _PAM_SM_OPEN_SESSION    0
286#define _PAM_SM_CLOSE_SESSION   0
287#else
288#undef PAM_SM_SESSION
289#define PAM_SM_SESSION
290#define _PAM_SM_OPEN_SESSION    pam_sm_open_session
291#define _PAM_SM_CLOSE_SESSION   pam_sm_close_session
292#endif
293#if defined(LINUX_PAM_MODULE) && !defined(PAM_SM_PASSWORD)
294#define _PAM_SM_CHAUTHTOK       0
295#else
296#undef PAM_SM_PASSWORD
297#define PAM_SM_PASSWORD
298#define _PAM_SM_CHAUTHTOK       pam_sm_chauthtok
299#endif
300
301/*
302 * Infrastructure for static modules using GCC linker sets.
303 * You are not expected to understand this.
304 */
305#if defined(__FreeBSD__)
306#define PAM_SOEXT ".so"
307#else
308#ifndef NO_STATIC_MODULES
309#define NO_STATIC_MODULES
310#endif
311#endif
312#if defined(__GNUC__) && !defined(__PIC__) && !defined(NO_STATIC_MODULES)
313/* gcc, static linking */
314#include <sys/cdefs.h>
315#include <linker_set.h>
316#define OPENPAM_STATIC_MODULES
317#define PAM_EXTERN static
318#define PAM_MODULE_ENTRY(name)                                          \
319static char _pam_name[] = name PAM_SOEXT;                               \
320static struct pam_module _pam_module = { _pam_name, {                   \
321    _PAM_SM_AUTHENTICATE, _PAM_SM_SETCRED, _PAM_SM_ACCT_MGMT,           \
322    _PAM_SM_OPEN_SESSION, _PAM_SM_CLOSE_SESSION, _PAM_SM_CHAUTHTOK },   \
323    NULL, 0, NULL, NULL };                                              \
324DATA_SET(_openpam_static_modules, _pam_module)
325#else
326/* normal case */
327#define PAM_EXTERN
328#define PAM_MODULE_ENTRY(name)
329#endif
330
331#ifdef __cplusplus
332}
333#endif
334
335#endif
Note: See TracBrowser for help on using the repository browser.