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