2 * $Id: help_env.c,v 1.2 1997/01/04 20:19:20 morgan Exp morgan $
3 * $FreeBSD: src/contrib/libpam/libpam_misc/help_env.c,v 1.1.1.1.6.2 2001/06/11 15:28:15 markm Exp $
4 * $DragonFly: src/contrib/libpam/libpam_misc/Attic/help_env.c,v 1.2 2003/06/17 04:24:03 dillon Exp $
6 * This file was written by Andrew G. Morgan <morgan@parc.power.net>
9 * Revision 1.2 1997/01/04 20:19:20 morgan
10 * added a prototype (no warning) and fixed paste function
12 * Revision 1.1 1996/12/01 03:25:37 morgan
20 #include <security/pam_misc.h>
23 * This is a useful function for dumping the Linux-PAM environment
24 * into some local memory, prior to it all getting lost when pam_end()
27 * Initially it was assumed that libpam did not do this part correctly
28 * (based on a loose email definition). The X/Open XSSO spec makes it
29 * clear that this function is a duplicate of the one already in
30 * libpam and therefore unnecessary. IT WILL BE COMPLETELY REMOVED
31 * IN libpam_misc 1.0 */
33 char **pam_misc_copy_env(pam_handle_t *pamh);
34 char **pam_misc_copy_env(pam_handle_t *pamh)
36 return pam_getenvlist(pamh);
40 * This function should be used to carefully dispose of the copied
43 * usage: env = pam_misc_drop_env(env);
46 char **pam_misc_drop_env(char **dump)
50 for (i=0; dump[i] != NULL; ++i) {
51 D(("dump[%d]=`%s'", i, dump[i]));
52 _pam_overwrite(dump[i]);
61 * This function takes the supplied environment and uploads it to be
65 int pam_misc_paste_env(pam_handle_t *pamh, const char * const * user_env)
67 for (; user_env && *user_env; ++user_env) {
70 D(("uploading: %s", *user_env));
71 retval = pam_putenv(pamh, *user_env);
72 if (retval != PAM_SUCCESS) {
73 D(("error setting %s: %s", *user_env, pam_strerror(pamh,retval)));
82 * This is a wrapper to make pam behave in the way that setenv() does.
85 int pam_misc_setenv(pam_handle_t *pamh, const char *name
86 , const char *value, int readonly)
94 /* we check if the variable is there already */
95 etmp = pam_getenv(pamh, name);
97 D(("failed to set readonly variable: %s", name));
98 return PAM_PERM_DENIED; /* not allowed to overwrite */
101 tmp = malloc(2+strlen(name)+strlen(value));
103 sprintf(tmp,"%s=%s",name,value);
104 D(("pam_putt()ing: %s", tmp));
105 retval = pam_putenv(pamh, tmp);
106 _pam_overwrite(tmp); /* purge */
107 _pam_drop(tmp); /* forget */
109 D(("malloc failure"));
110 retval = PAM_BUF_ERR;