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

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

Introduce pam_v{info,error,prompt}().
Move OpenPAM API extensions into <security/openpam.h> to avoid
namespace pollution for apps or modules that do not use them.

Sponsored by: DARPA, NAI Labs

  • Property svn:keywords set to Id LastChangedRevision HeadURL LastChangedDate LastChangedBy
File size: 4.8 KB
Line 
1/*-
2 * Copyright (c) 2002 Networks Associates Technologies, 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 * $Id: openpam.h 39 2002-02-07 12:22:08Z 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/*
46 * API extensions
47 */
48int
49pam_error(pam_handle_t *_pamh,
50        const char *_fmt,
51        ...);
52
53int
54pam_get_authtok(pam_handle_t *_pamh,
55        const char **_authtok,
56        const char *_prompt);
57
58int
59pam_info(pam_handle_t *_pamh,
60        const char *_fmt,
61        ...);
62
63int
64pam_prompt(pam_handle_t *_pamh,
65        int _style,
66        char **_resp,
67        const char *_fmt,
68        ...);
69
70int
71pam_setenv(pam_handle_t *_pamh,
72        const char *_name,
73        const char *_value,
74        int _overwrite);
75
76int
77pam_vinfo(pam_handle_t *_pamh,
78        const char *_fmt,
79        va_list _ap);
80
81int
82pam_verror(pam_handle_t *_pamh,
83        const char *_fmt,
84        va_list _ap);
85
86int
87pam_vprompt(pam_handle_t *_pamh,
88        int _style,
89        char **_resp,
90        const char *_fmt,
91        va_list _ap);
92
93/*
94 * Log levels
95 */
96enum {
97        PAM_LOG_DEBUG,
98        PAM_LOG_VERBOSE,
99        PAM_LOG_NOTICE,
100        PAM_LOG_ERROR
101};
102
103/*
104 * Log to syslog
105 */
106void _openpam_log(int _level,
107        const char *_func,
108        const char *_fmt,
109        ...);
110
111#if defined(__STDC__) && (__STDC_VERSION__ > 199901L)
112#define openpam_log(lvl, fmt, ...) \
113        _openpam_log((lvl), __func__, fmt, __VA_ARGS__)
114#elif defined(__GNUC__)
115#define openpam_log(lvl, fmt...) \
116        _openpam_log((lvl), __func__, ##fmt)
117#else
118extern openpam_log(int _level, const char *_format, ...);
119#endif
120
121/*
122 * Generic conversation function
123 */
124struct pam_message;
125struct pam_response;
126int openpam_ttyconv(int _n,
127        const struct pam_message **_msg,
128        struct pam_response **_resp,
129        void *_data);
130
131/*
132 * PAM primitives
133 */
134enum {
135        PAM_SM_AUTHENTICATE,
136        PAM_SM_SETCRED,
137        PAM_SM_ACCT_MGMT,
138        PAM_SM_OPEN_SESSION,
139        PAM_SM_CLOSE_SESSION,
140        PAM_SM_CHAUTHTOK,
141        /* keep this last */
142        PAM_NUM_PRIMITIVES
143};
144
145/*
146 * Dummy service module function
147 */
148#define PAM_SM_DUMMY(type)                                              \
149PAM_EXTERN int                                                          \
150pam_sm_##type(pam_handle_t *pamh, int flags,                            \
151    int argc, const char *argv[])                                       \
152{                                                                       \
153        return (PAM_IGNORE);                                            \
154}
155
156/*
157 * PAM service module functions match this typedef
158 */
159struct pam_handle;
160typedef int (*pam_func_t)(struct pam_handle *, int, int, const char **);
161
162/*
163 * A struct that describes a module.
164 */
165typedef struct pam_module pam_module_t;
166struct pam_module {
167        const char      *path;
168        pam_func_t       func[PAM_NUM_PRIMITIVES];
169        void            *dlh;
170        int              refcount;
171        pam_module_t    *prev;
172        pam_module_t    *next;
173};
174
175/*
176 * Infrastructure for static modules using GCC linker sets.
177 * You are not expected to understand this.
178 */
179#if defined(__GNUC__) && !defined(__PIC__)
180#if defined(__FreeBSD__)
181#define PAM_SOEXT ".so"
182#else
183#error Static linking is not supported on your platform
184#endif
185/* gcc, static linking */
186#include <sys/cdefs.h>
187#include <linker_set.h>
188#define OPENPAM_STATIC_MODULES
189#define PAM_EXTERN static
190#define PAM_MODULE_ENTRY(name)                                          \
191static struct pam_module _pam_module = { name PAM_SOEXT, {              \
192    pam_sm_authenticate, pam_sm_setcred, pam_sm_acct_mgmt,              \
193    pam_sm_open_session, pam_sm_close_session, pam_sm_chauthtok },      \
194    NULL, 0, NULL, NULL };                                              \
195DATA_SET(_openpam_modules, _pam_module)
196#else
197/* normal case */
198#define PAM_EXTERN
199#define PAM_MODULE_ENTRY(name)
200#endif
201
202#endif
Note: See TracBrowser for help on using the repository browser.