xref: /freebsd/contrib/openpam/lib/libpam/openpam_impl.h (revision 3ba4c8c81a28de3e00ccf6d7f92c6f8e58bef456)
1f7e6344dSDag-Erling Smørgrav /*-
2f7e6344dSDag-Erling Smørgrav  * Copyright (c) 2001-2003 Networks Associates Technology, Inc.
3*49e56509SDag-Erling Smørgrav  * Copyright (c) 2004-2017 Dag-Erling Smørgrav
4f7e6344dSDag-Erling Smørgrav  * All rights reserved.
5f7e6344dSDag-Erling Smørgrav  *
6f7e6344dSDag-Erling Smørgrav  * This software was developed for the FreeBSD Project by ThinkSec AS and
7f7e6344dSDag-Erling Smørgrav  * Network Associates Laboratories, the Security Research Division of
8f7e6344dSDag-Erling Smørgrav  * Network Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
9f7e6344dSDag-Erling Smørgrav  * ("CBOSS"), as part of the DARPA CHATS research program.
10f7e6344dSDag-Erling Smørgrav  *
11f7e6344dSDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
12f7e6344dSDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
13f7e6344dSDag-Erling Smørgrav  * are met:
14f7e6344dSDag-Erling Smørgrav  * 1. Redistributions of source code must retain the above copyright
15f7e6344dSDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer.
16f7e6344dSDag-Erling Smørgrav  * 2. Redistributions in binary form must reproduce the above copyright
17f7e6344dSDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer in the
18f7e6344dSDag-Erling Smørgrav  *    documentation and/or other materials provided with the distribution.
19f7e6344dSDag-Erling Smørgrav  * 3. The name of the author may not be used to endorse or promote
20f7e6344dSDag-Erling Smørgrav  *    products derived from this software without specific prior written
21f7e6344dSDag-Erling Smørgrav  *    permission.
22f7e6344dSDag-Erling Smørgrav  *
23f7e6344dSDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24f7e6344dSDag-Erling Smørgrav  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25f7e6344dSDag-Erling Smørgrav  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26f7e6344dSDag-Erling Smørgrav  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27f7e6344dSDag-Erling Smørgrav  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28f7e6344dSDag-Erling Smørgrav  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29f7e6344dSDag-Erling Smørgrav  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30f7e6344dSDag-Erling Smørgrav  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31f7e6344dSDag-Erling Smørgrav  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32f7e6344dSDag-Erling Smørgrav  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33f7e6344dSDag-Erling Smørgrav  * SUCH DAMAGE.
34f7e6344dSDag-Erling Smørgrav  */
35f7e6344dSDag-Erling Smørgrav 
36f7e6344dSDag-Erling Smørgrav #ifndef OPENPAM_IMPL_H_INCLUDED
37f7e6344dSDag-Erling Smørgrav #define OPENPAM_IMPL_H_INCLUDED
38f7e6344dSDag-Erling Smørgrav 
39f7e6344dSDag-Erling Smørgrav #include <security/openpam.h>
40f7e6344dSDag-Erling Smørgrav 
41f7e6344dSDag-Erling Smørgrav extern int openpam_debug;
42f7e6344dSDag-Erling Smørgrav 
43f7e6344dSDag-Erling Smørgrav /*
44f7e6344dSDag-Erling Smørgrav  * Control flags
45f7e6344dSDag-Erling Smørgrav  */
46f7e6344dSDag-Erling Smørgrav typedef enum {
47f7e6344dSDag-Erling Smørgrav 	PAM_BINDING,
48f7e6344dSDag-Erling Smørgrav 	PAM_REQUIRED,
49f7e6344dSDag-Erling Smørgrav 	PAM_REQUISITE,
50f7e6344dSDag-Erling Smørgrav 	PAM_SUFFICIENT,
51f7e6344dSDag-Erling Smørgrav 	PAM_OPTIONAL,
52f7e6344dSDag-Erling Smørgrav 	PAM_NUM_CONTROL_FLAGS
53f7e6344dSDag-Erling Smørgrav } pam_control_t;
54f7e6344dSDag-Erling Smørgrav 
55f7e6344dSDag-Erling Smørgrav /*
56f7e6344dSDag-Erling Smørgrav  * Facilities
57f7e6344dSDag-Erling Smørgrav  */
58f7e6344dSDag-Erling Smørgrav typedef enum {
59f7e6344dSDag-Erling Smørgrav 	PAM_FACILITY_ANY = -1,
60f7e6344dSDag-Erling Smørgrav 	PAM_AUTH = 0,
61f7e6344dSDag-Erling Smørgrav 	PAM_ACCOUNT,
62f7e6344dSDag-Erling Smørgrav 	PAM_SESSION,
63f7e6344dSDag-Erling Smørgrav 	PAM_PASSWORD,
64f7e6344dSDag-Erling Smørgrav 	PAM_NUM_FACILITIES
65f7e6344dSDag-Erling Smørgrav } pam_facility_t;
66f7e6344dSDag-Erling Smørgrav 
67f7e6344dSDag-Erling Smørgrav /*
68f7e6344dSDag-Erling Smørgrav  * Module chains
69f7e6344dSDag-Erling Smørgrav  */
70f7e6344dSDag-Erling Smørgrav typedef struct pam_chain pam_chain_t;
71f7e6344dSDag-Erling Smørgrav struct pam_chain {
72f7e6344dSDag-Erling Smørgrav 	pam_module_t	*module;
73f7e6344dSDag-Erling Smørgrav 	int		 flag;
74f7e6344dSDag-Erling Smørgrav 	int		 optc;
75f7e6344dSDag-Erling Smørgrav 	char	       **optv;
76f7e6344dSDag-Erling Smørgrav 	pam_chain_t	*next;
77f7e6344dSDag-Erling Smørgrav };
78f7e6344dSDag-Erling Smørgrav 
79f7e6344dSDag-Erling Smørgrav /*
80f7e6344dSDag-Erling Smørgrav  * Service policies
81f7e6344dSDag-Erling Smørgrav  */
82f7e6344dSDag-Erling Smørgrav #if defined(OPENPAM_EMBEDDED)
83f7e6344dSDag-Erling Smørgrav typedef struct pam_policy pam_policy_t;
84f7e6344dSDag-Erling Smørgrav struct pam_policy {
85f7e6344dSDag-Erling Smørgrav 	const char	*service;
86f7e6344dSDag-Erling Smørgrav 	pam_chain_t	*chains[PAM_NUM_FACILITIES];
87f7e6344dSDag-Erling Smørgrav };
88f7e6344dSDag-Erling Smørgrav extern pam_policy_t *pam_embedded_policies[];
89f7e6344dSDag-Erling Smørgrav #endif
90f7e6344dSDag-Erling Smørgrav 
91f7e6344dSDag-Erling Smørgrav /*
92f7e6344dSDag-Erling Smørgrav  * Module-specific data
93f7e6344dSDag-Erling Smørgrav  */
94f7e6344dSDag-Erling Smørgrav typedef struct pam_data pam_data_t;
95f7e6344dSDag-Erling Smørgrav struct pam_data {
96f7e6344dSDag-Erling Smørgrav 	char		*name;
97f7e6344dSDag-Erling Smørgrav 	void		*data;
98f7e6344dSDag-Erling Smørgrav 	void		(*cleanup)(pam_handle_t *, void *, int);
99f7e6344dSDag-Erling Smørgrav 	pam_data_t	*next;
100f7e6344dSDag-Erling Smørgrav };
101f7e6344dSDag-Erling Smørgrav 
102f7e6344dSDag-Erling Smørgrav /*
103f7e6344dSDag-Erling Smørgrav  * PAM context
104f7e6344dSDag-Erling Smørgrav  */
105f7e6344dSDag-Erling Smørgrav struct pam_handle {
106f7e6344dSDag-Erling Smørgrav 	char		*service;
107f7e6344dSDag-Erling Smørgrav 
108f7e6344dSDag-Erling Smørgrav 	/* chains */
109f7e6344dSDag-Erling Smørgrav 	pam_chain_t	*chains[PAM_NUM_FACILITIES];
110f7e6344dSDag-Erling Smørgrav 	pam_chain_t	*current;
111f7e6344dSDag-Erling Smørgrav 	int		 primitive;
112f7e6344dSDag-Erling Smørgrav 
113f7e6344dSDag-Erling Smørgrav 	/* items and data */
114f7e6344dSDag-Erling Smørgrav 	void		*item[PAM_NUM_ITEMS];
115f7e6344dSDag-Erling Smørgrav 	pam_data_t	*module_data;
116f7e6344dSDag-Erling Smørgrav 
117f7e6344dSDag-Erling Smørgrav 	/* environment list */
118f7e6344dSDag-Erling Smørgrav 	char	       **env;
119f7e6344dSDag-Erling Smørgrav 	int		 env_count;
120f7e6344dSDag-Erling Smørgrav 	int		 env_size;
121f7e6344dSDag-Erling Smørgrav };
122f7e6344dSDag-Erling Smørgrav 
123f7e6344dSDag-Erling Smørgrav /*
124f7e6344dSDag-Erling Smørgrav  * Default policy
125f7e6344dSDag-Erling Smørgrav  */
126f7e6344dSDag-Erling Smørgrav #define PAM_OTHER	"other"
127f7e6344dSDag-Erling Smørgrav 
128f7e6344dSDag-Erling Smørgrav /*
129f7e6344dSDag-Erling Smørgrav  * Internal functions
130f7e6344dSDag-Erling Smørgrav  */
131f3b0ac34SDag-Erling Smørgrav int		 openpam_configure(pam_handle_t *, const char *)
132f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
133f3b0ac34SDag-Erling Smørgrav int		 openpam_dispatch(pam_handle_t *, int, int)
134f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
135f3b0ac34SDag-Erling Smørgrav int		 openpam_findenv(pam_handle_t *, const char *, size_t)
136f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1,2));
137f3b0ac34SDag-Erling Smørgrav pam_module_t	*openpam_load_module(const char *)
138f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
139f3b0ac34SDag-Erling Smørgrav void		 openpam_clear_chains(pam_chain_t **)
140f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
141f7e6344dSDag-Erling Smørgrav 
142f3b0ac34SDag-Erling Smørgrav int		 openpam_check_desc_owner_perms(const char *, int)
143f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
144f3b0ac34SDag-Erling Smørgrav int		 openpam_check_path_owner_perms(const char *)
145f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
146f7e6344dSDag-Erling Smørgrav 
147f7e6344dSDag-Erling Smørgrav #ifdef OPENPAM_STATIC_MODULES
148f3b0ac34SDag-Erling Smørgrav pam_module_t	*openpam_static(const char *)
149f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
150f7e6344dSDag-Erling Smørgrav #endif
151f3b0ac34SDag-Erling Smørgrav pam_module_t	*openpam_dynamic(const char *)
152f3b0ac34SDag-Erling Smørgrav 	OPENPAM_NONNULL((1));
153f7e6344dSDag-Erling Smørgrav 
154f7e6344dSDag-Erling Smørgrav #define	FREE(p)					\
155f7e6344dSDag-Erling Smørgrav 	do {					\
156f7e6344dSDag-Erling Smørgrav 		free(p);			\
157f7e6344dSDag-Erling Smørgrav 		(p) = NULL;			\
158f7e6344dSDag-Erling Smørgrav 	} while (0)
159f7e6344dSDag-Erling Smørgrav 
160f7e6344dSDag-Erling Smørgrav #define FREEV(c, v)				\
161f7e6344dSDag-Erling Smørgrav 	do {					\
162f3b0ac34SDag-Erling Smørgrav 		if ((v) != NULL) {		\
163f3b0ac34SDag-Erling Smørgrav 			while ((c)-- > 0)	\
164f7e6344dSDag-Erling Smørgrav 				FREE((v)[(c)]);	\
165f7e6344dSDag-Erling Smørgrav 			FREE(v);		\
166f3b0ac34SDag-Erling Smørgrav 		}				\
167f7e6344dSDag-Erling Smørgrav 	} while (0)
168f7e6344dSDag-Erling Smørgrav 
169f7e6344dSDag-Erling Smørgrav #include "openpam_constants.h"
170f7e6344dSDag-Erling Smørgrav #include "openpam_debug.h"
171f7e6344dSDag-Erling Smørgrav #include "openpam_features.h"
172f7e6344dSDag-Erling Smørgrav 
173f7e6344dSDag-Erling Smørgrav #endif
174