pam_private.h 11 KB

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