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