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

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

Add support for static linking. Also rename a handful of constants
to reduce the chance of every running into a naming conflict.

Sponsored by: DARPA, NAI Labs

  • Property svn:keywords set to Id LastChangedRevision HeadURL LastChangedDate LastChangedBy
File size: 4.1 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 32 2002-02-04 23:22:40Z des $
35 */
36
37#ifndef _SECURITY_OPENPAM_H_INCLUDED
38#define _SECURITY_OPENPAM_H_INCLUDED
39
40/*
41 * Log levels
42 */
43enum {
44        PAM_LOG_DEBUG,
45        PAM_LOG_VERBOSE,
46        PAM_LOG_NOTICE,
47        PAM_LOG_ERROR
48};
49
50/*
51 * Log to syslog
52 */
53void _openpam_log(int _level,
54        const char *_func,
55        const char *_fmt,
56        ...);
57
58#if defined(__STDC__) && (__STDC_VERSION__ > 199901L)
59#define openpam_log(lvl, fmt, ...) \
60        _openpam_log((lvl), __func__, fmt, __VA_ARGS__)
61#elif defined(__GNUC__)
62#define openpam_log(lvl, fmt...) \
63        _openpam_log((lvl), __func__, ##fmt)
64#else
65extern openpam_log(int _level, const char *_format, ...);
66#endif
67
68/*
69 * Generic conversation function
70 */
71struct pam_message;
72struct pam_response;
73int openpam_ttyconv(int _n,
74        const struct pam_message **_msg,
75        struct pam_response **_resp,
76        void *_data);
77
78/*
79 * PAM primitives
80 */
81enum {
82        PAM_SM_AUTHENTICATE,
83        PAM_SM_SETCRED,
84        PAM_SM_ACCT_MGMT,
85        PAM_SM_OPEN_SESSION,
86        PAM_SM_CLOSE_SESSION,
87        PAM_SM_CHAUTHTOK,
88        /* keep this last */
89        PAM_NUM_PRIMITIVES
90};
91
92/*
93 * Dummy service module function
94 */
95#define PAM_SM_DUMMY(type)                                              \
96PAM_EXTERN int                                                          \
97pam_sm_##type(pam_handle_t *pamh, int flags,                            \
98    int argc, const char *argv[])                                       \
99{                                                                       \
100        return (PAM_IGNORE);                                            \
101}
102
103/*
104 * PAM service module functions match this typedef
105 */
106struct pam_handle;
107typedef int (*pam_func_t)(struct pam_handle *, int, int, const char **);
108
109/*
110 * A struct that describes a module.
111 */
112typedef struct pam_module pam_module_t;
113struct pam_module {
114        const char      *path;
115        pam_func_t       func[PAM_NUM_PRIMITIVES];
116        void            *dlh;
117        int              refcount;
118        pam_module_t    *prev;
119        pam_module_t    *next;
120};
121
122/*
123 * Infrastructure for static modules using GCC linker sets.
124 * You are not expected to understand this.
125 */
126#if defined(__GNUC__) && !defined(__PIC__)
127#if defined(__FreeBSD__)
128#define PAM_SOEXT ".so"
129#else
130#error Static linking is not supported on your platform
131#endif
132/* gcc, static linking */
133#include <sys/cdefs.h>
134#include <linker_set.h>
135#define OPENPAM_STATIC_MODULES
136#define PAM_EXTERN static
137#define PAM_MODULE_ENTRY(name)                                          \
138static struct pam_module _pam_module = { name PAM_SOEXT, {              \
139    pam_sm_authenticate, pam_sm_setcred, pam_sm_acct_mgmt,              \
140    pam_sm_open_session, pam_sm_close_session, pam_sm_chauthtok },      \
141    NULL, 0, NULL, NULL };                                              \
142DATA_SET(_openpam_modules, _pam_module)
143#else
144/* normal case */
145#define PAM_EXTERN
146#define PAM_MODULE_ENTRY(name)
147#endif
148
149#endif
Note: See TracBrowser for help on using the repository browser.