]> granicus.if.org Git - linux-pam/blob - libpam/pam_private.h
Relevant BUGIDs: 129775
[linux-pam] / libpam / pam_private.h
1 /*
2  * pam_private.h
3  *
4  * $Id$
5  *
6  * This is the Linux-PAM Library Private Header. It contains things
7  * internal to the Linux-PAM library. Things not needed by either an
8  * application or module.
9  *
10  * Please see end of file for copyright.
11  *
12  * Creator: Marc Ewing.
13  * Maintained: CVS
14  */
15
16 #ifndef _PAM_PRIVATE_H
17 #define _PAM_PRIVATE_H
18
19 #include <security/_pam_aconf.h>
20
21 /* this is not used at the moment --- AGM */
22 #define LIBPAM_VERSION (LIBPAM_VERSION_MAJOR*0x100 + LIBPAM_VERSION_MINOR)
23
24 #include <security/pam_appl.h>
25 #include <security/pam_modules.h>
26
27 /* the Linux-PAM configuration file */
28
29 #define PAM_CONFIG    "/etc/pam.conf"
30 #define PAM_CONFIG_D  "/etc/pam.d"
31 #define PAM_CONFIG_DF "/etc/pam.d/%s"
32
33 #define PAM_DEFAULT_SERVICE        "other"     /* lower case */
34 #define PAM_DEFAULT_SERVICE_FILE   PAM_CONFIG_D "/" PAM_DEFAULT_SERVICE
35
36 #ifdef PAM_LOCKING
37 /*
38  * the Linux-PAM lock file. If it exists Linux-PAM will abort. Use it
39  * to block access to libpam
40  */
41 #define PAM_LOCK_FILE "/var/lock/subsys/PAM"
42 #endif
43
44 /* components of the pam_handle structure */
45
46 struct handler {
47     int must_fail;
48     int (*func)(pam_handle_t *pamh, int flags, int argc, char **argv);
49     int actions[_PAM_RETURN_VALUES];
50     /* set by authenticate, open_session, chauthtok(1st)
51        consumed by setcred, close_session, chauthtok(2nd) */
52     int cached_retval; int *cached_retval_p;
53     int argc;
54     char **argv;
55     struct handler *next;
56 };
57
58 struct loaded_module {
59     char *name;
60     int type; /* PAM_STATIC_MOD or PAM_DYNAMIC_MOD */
61     void *dl_handle;
62 };
63
64 #define PAM_MT_DYNAMIC_MOD 0
65 #define PAM_MT_STATIC_MOD  1
66 #define PAM_MT_FAULTY_MOD 2
67
68 struct handlers {
69     struct handler *authenticate;
70     struct handler *setcred;
71     struct handler *acct_mgmt;
72     struct handler *open_session;
73     struct handler *close_session;
74     struct handler *chauthtok;
75 };
76
77 struct service {
78     struct loaded_module *module; /* Only used for dynamic loading */
79     int modules_allocated;
80     int modules_used;
81     int handlers_loaded;
82
83     struct handlers conf;        /* the configured handlers */
84     struct handlers other;       /* the default handlers */
85 };
86
87 /*
88  * Environment helper functions
89  */
90
91 #define PAM_ENV_CHUNK         10 /* chunks of memory calloc()'d      *
92                                   * at once                          */
93
94 struct pam_environ {
95     int entries;                 /* the number of pointers available */
96     int requested;               /* the number of pointers used:     *
97                                   *     1 <= requested <= entries    */
98     char **list;                 /* the environment storage (a list  *
99                                   * of pointers to malloc() memory)  */
100 };
101
102 #include <sys/time.h>
103
104 typedef enum { PAM_FALSE, PAM_TRUE } _pam_boolean;
105
106 struct _pam_fail_delay {
107     _pam_boolean set;
108     unsigned int delay;
109     time_t begin;
110     const void *delay_fn_ptr;
111 };
112
113 struct _pam_former_state {
114 /* this is known and set by _pam_dispatch() */
115     int choice;            /* which flavor of module function did we call? */
116
117 /* state info for the _pam_dispatch_aux() function */
118     int depth;             /* how deep in the stack were we? */
119     int impression;        /* the impression at that time */
120     int status;            /* the status before returning incomplete */
121
122 /* state info used by pam_get_user() function */
123     int want_user;
124     char *prompt;          /* saved prompt information */
125
126 /* state info for the pam_chauthtok() function */
127     _pam_boolean update;
128 };
129
130 struct pam_handle {
131     char *authtok;
132     unsigned caller_is;
133     struct pam_conv *pam_conversation;
134     char *oldauthtok;
135     char *prompt;                /* for use by pam_get_user() */
136     char *service_name;
137     char *user;
138     char *rhost;
139     char *ruser;
140     char *tty;
141     struct pam_data *data;
142     struct pam_environ *env;      /* structure to maintain environment list */
143     struct _pam_fail_delay fail_delay;   /* helper function for easy delays */
144     struct service handlers;
145     struct _pam_former_state former;  /* library state - support for
146                                          event driven applications */
147 };
148
149 /* Values for select arg to _pam_dispatch() */
150 #define PAM_NOT_STACKED   0
151 #define PAM_AUTHENTICATE  1
152 #define PAM_SETCRED       2
153 #define PAM_ACCOUNT       3
154 #define PAM_OPEN_SESSION  4
155 #define PAM_CLOSE_SESSION 5
156 #define PAM_CHAUTHTOK     6
157
158 #define _PAM_ACTION_IS_JUMP(x)  ((x) > 0)
159 #define _PAM_ACTION_IGNORE      0
160 #define _PAM_ACTION_OK         -1
161 #define _PAM_ACTION_DONE       -2
162 #define _PAM_ACTION_BAD        -3
163 #define _PAM_ACTION_DIE        -4
164 #define _PAM_ACTION_RESET      -5
165 /* Add any new entries here.  Will need to change ..._UNDEF and then
166  * need to change pam_tokens.h */
167 #define _PAM_ACTION_UNDEF      -6   /* this is treated as an error
168                                        ( = _PAM_ACTION_BAD) */
169
170 /* character tables for parsing config files */
171 extern const char * const _pam_token_actions[-_PAM_ACTION_UNDEF];
172 extern const char * const _pam_token_returns[_PAM_RETURN_VALUES+1];
173
174 /*
175  * internally defined functions --- these should not be directly
176  * called by applications or modules
177  */
178 int _pam_dispatch(pam_handle_t *pamh, int flags, int choice);
179
180 /* Free various allocated structures and dlclose() the libs */
181 int _pam_free_handlers(pam_handle_t *pamh);
182
183 /* Parse config file, allocate handler structures, dlopen() */
184 int _pam_init_handlers(pam_handle_t *pamh);
185
186 /* Set all hander stuff to 0/NULL - called once from pam_start() */
187 void _pam_start_handlers(pam_handle_t *pamh);
188
189 /* environment helper functions */
190
191 /* create the environment structure */
192 int _pam_make_env(pam_handle_t *pamh);
193
194 /* delete the environment structure */
195 void _pam_drop_env(pam_handle_t *pamh);
196
197 /* these functions deal with failure delays as required by the
198    authentication modules and application. Their *interface* is likely
199    to remain the same although their function is hopefully going to
200    improve */
201
202 /* reset the timer to no-delay */
203 void _pam_reset_timer(pam_handle_t *pamh);
204
205 /* this sets the clock ticking */
206 void _pam_start_timer(pam_handle_t *pamh);
207
208 /* this waits for the clock to stop ticking if status != PAM_SUCCESS */
209 void _pam_await_timer(pam_handle_t *pamh, int status);
210
211 typedef void (*voidfunc(void))(void);
212 #ifdef PAM_STATIC
213
214 /* The next two in ../modules/_pam_static/pam_static.c */
215
216 /* Return pointer to data structure used to define a static module */
217 struct pam_module * _pam_open_static_handler(const char *path);
218
219 /* Return pointer to function requested from static module */
220
221 voidfunc *_pam_get_static_sym(struct pam_module *mod, const char *symname);
222
223 #endif
224
225 /* For now we just use a stack and linear search for module data. */
226 /* If it becomes apparent that there is a lot of data, it should  */
227 /* changed to either a sorted list or a hash table.               */
228
229 struct pam_data {
230      char *name;
231      void *data;
232      void (*cleanup)(pam_handle_t *pamh, void *data, int error_status);
233      struct pam_data *next;
234 };
235
236 void _pam_free_data(pam_handle_t *pamh, int status);
237
238 int _pam_strCMP(const char *s, const char *t);
239 char *_pam_StrTok(char *from, const char *format, char **next);
240
241 char *_pam_strdup(const char *s);
242
243 int _pam_mkargv(char *s, char ***argv, int *argc);
244
245 void _pam_sanitize(pam_handle_t *pamh);
246
247 void _pam_set_default_control(int *control_array, int default_action);
248
249 void _pam_parse_control(int *control_array, char *tok);
250
251 void _pam_system_log(int priority, const char *format,  ... );
252 #define _PAM_SYSTEM_LOG_PREFIX "PAM "
253
254 /*
255  * XXX - Take care with this. It could confuse the logic of a trailing
256  *       else
257  */
258
259 #define IF_NO_PAMH(X,pamh,ERR)                    \
260 if ((pamh) == NULL) {                             \
261     _pam_system_log(LOG_ERR, X ": NULL pam handle passed"); \
262     return ERR;                                   \
263 }
264
265 /* Definition for the default username prompt used by pam_get_user() */
266
267 #define PAM_DEFAULT_PROMPT "Please enter username: "
268
269 /*
270  * include some helpful macros
271  */
272
273 #include <security/_pam_macros.h>
274
275 /* used to work out where control currently resides (in an application
276    or in a module) */
277
278 #define _PAM_CALLED_FROM_MODULE         1
279 #define _PAM_CALLED_FROM_APP            2
280
281 #define __PAM_FROM_MODULE(pamh)  ((pamh)->caller_is == _PAM_CALLED_FROM_MODULE)
282 #define __PAM_FROM_APP(pamh)     ((pamh)->caller_is == _PAM_CALLED_FROM_APP)
283 #define __PAM_TO_MODULE(pamh) \
284         do { (pamh)->caller_is = _PAM_CALLED_FROM_MODULE; } while (0)
285 #define __PAM_TO_APP(pamh)    \
286         do { (pamh)->caller_is = _PAM_CALLED_FROM_APP; } while (0)
287
288 /*
289  * Copyright (C) 1995 by Red Hat Software, Marc Ewing
290  * Copyright (c) 1996-8,2001 by Andrew G. Morgan <morgan@kernel.org>
291  *
292  * All rights reserved
293  *
294  * Redistribution and use in source and binary forms, with or without
295  * modification, are permitted provided that the following conditions
296  * are met:
297  * 1. Redistributions of source code must retain the above copyright
298  *    notice, and the entire permission notice in its entirety,
299  *    including the disclaimer of warranties.
300  * 2. Redistributions in binary form must reproduce the above copyright
301  *    notice, this list of conditions and the following disclaimer in the
302  *    documentation and/or other materials provided with the distribution.
303  * 3. The name of the author may not be used to endorse or promote
304  *    products derived from this software without specific prior
305  *    written permission.
306  * 
307  * ALTERNATIVELY, this product may be distributed under the terms of
308  * the GNU Public License, in which case the provisions of the GPL are
309  * required INSTEAD OF the above restrictions.  (This clause is
310  * necessary due to a potential bad interaction between the GPL and
311  * the restrictions contained in a BSD-style copyright.)
312  * 
313  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
314  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
315  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
316  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
317  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
318  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
319  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
320  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
321  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
322  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
323  * OF THE POSSIBILITY OF SUCH DAMAGE.
324  */
325
326 #endif /* _PAM_PRIVATE_H_ */