source: openpam/trunk/lib/openpam_impl.h @ 200

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

More debugging macros: ENTERI() (item type), ENTERN() (int),
ENTERS() (string). Rename RETURNI() to RETURNN() for consistency.

File size: 5.1 KB
Line 
1/*-
2 * Copyright (c) 2001 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 * $P4: //depot/projects/openpam/lib/openpam_impl.h#20 $
35 */
36
37#ifndef _OPENPAM_IMPL_H_INCLUDED
38#define _OPENPAM_IMPL_H_INCLUDED
39
40#include <security/openpam.h>
41
42extern const char *_pam_func_name[PAM_NUM_PRIMITIVES];
43extern const char *_pam_sm_func_name[PAM_NUM_PRIMITIVES];
44extern const char *_pam_err_name[PAM_NUM_ERRORS];
45extern const char *_pam_item_name[PAM_NUM_ITEMS];
46
47/*
48 * Control flags
49 */
50#define PAM_REQUIRED            1
51#define PAM_REQUISITE           2
52#define PAM_SUFFICIENT          3
53#define PAM_OPTIONAL            4
54#define PAM_BINDING             5
55#define PAM_NUM_CONTROLFLAGS    6
56
57/*
58 * Chains
59 */
60#define PAM_AUTH                0
61#define PAM_ACCOUNT             1
62#define PAM_SESSION             2
63#define PAM_PASSWORD            3
64#define PAM_NUM_CHAINS          4
65
66typedef struct pam_chain pam_chain_t;
67struct pam_chain {
68        pam_module_t    *module;
69        int              flag;
70        int              optc;
71        char           **optv;
72        pam_chain_t     *next;
73};
74
75typedef struct pam_data pam_data_t;
76struct pam_data {
77        char            *name;
78        void            *data;
79        void            (*cleanup)(pam_handle_t *, void *, int);
80        pam_data_t      *next;
81};
82
83struct pam_handle {
84        char            *service;
85
86        /* chains */
87        pam_chain_t     *chains[PAM_NUM_CHAINS];
88        pam_chain_t     *current;
89        int              primitive;
90
91        /* items and data */
92        void            *item[PAM_NUM_ITEMS];
93        pam_data_t      *module_data;
94
95        /* environment list */
96        char           **env;
97        int              env_count;
98        int              env_size;
99};
100
101#ifdef NGROUPS_MAX
102#define PAM_SAVED_CRED "pam_saved_cred"
103struct pam_saved_cred {
104        uid_t    euid;
105        gid_t    egid;
106        gid_t    groups[NGROUPS_MAX];
107        int      ngroups;
108};
109#endif
110
111#define PAM_OTHER       "other"
112
113int             openpam_configure(pam_handle_t *, const char *);
114int             openpam_dispatch(pam_handle_t *, int, int);
115int             openpam_findenv(pam_handle_t *, const char *, size_t);
116int             openpam_add_module(pam_chain_t **, int, int,
117                                   const char *, int, const char **);
118void            openpam_clear_chains(pam_chain_t **);
119
120#ifdef OPENPAM_STATIC_MODULES
121pam_module_t   *openpam_static(const char *);
122#endif
123pam_module_t   *openpam_dynamic(const char *);
124
125#ifdef DEBUG
126#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering")
127#define ENTERI(i) do { \
128        if ((i) > 0 && (i) < PAM_NUM_ITEMS) \
129                openpam_log(PAM_LOG_DEBUG, "entering: %s", _pam_item_name[i]); \
130        else \
131                openpam_log(PAM_LOG_DEBUG, "entering: %d", (i)); \
132} while (0);
133#define ENTERN(n) do { \
134        openpam_log(PAM_LOG_DEBUG, "entering: %d", (n)); \
135} while (0);
136#define ENTERS(s) do { \
137        if ((s) == NULL) \
138                openpam_log(PAM_LOG_DEBUG, "entering: NULL"); \
139        else \
140                openpam_log(PAM_LOG_DEBUG, "entering: '%s'", (s)); \
141} while (0);
142#define RETURNV() openpam_log(PAM_LOG_DEBUG, "returning")
143#define RETURNC(c) do { \
144        if ((c) >= 0 && (c) < PAM_NUM_ERRORS) \
145                openpam_log(PAM_LOG_DEBUG, "returning %s", _pam_err_name[c]); \
146        else \
147                openpam_log(PAM_LOG_DEBUG, "returning %d!", (c)); \
148        return (c); \
149} while (0)
150#define RETURNN(n) do { \
151        openpam_log(PAM_LOG_DEBUG, "returning %d", (n)); \
152        return (n); \
153} while (0)
154#define RETURNP(p) do { \
155        if ((p) == NULL) \
156                openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
157        else \
158                openpam_log(PAM_LOG_DEBUG, "returning %p", (p)); \
159        return (p); \
160} while (0)
161#define RETURNS(s) do { \
162        if ((s) == NULL) \
163                openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
164        else \
165                openpam_log(PAM_LOG_DEBUG, "returning '%s'", (s)); \
166        return (s); \
167} while (0)
168#else
169#define ENTER()
170#define ENTERI(i)
171#define ENTERN(n)
172#define ENTERS(s)
173#define RETURNV() return
174#define RETURNC(c) return (c)
175#define RETURNN(n) return (n)
176#define RETURNP(p) return (p)
177#define RETURNS(s) return (s)
178#endif
179
180#endif
Note: See TracBrowser for help on using the repository browser.