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 $
5 * This file was written by Andrew G. Morgan <morgan@parc.power.net>
8 * Revision 1.2 1997/01/04 20:19:20 morgan
9 * added a prototype (no warning) and fixed paste function
11 * Revision 1.1 1996/12/01 03:25:37 morgan
19 #include <security/pam_misc.h>
22 * This is a useful function for dumping the Linux-PAM environment
23 * into some local memory, prior to it all getting lost when pam_end()
26 * Initially it was assumed that libpam did not do this part correctly
27 * (based on a loose email definition). The X/Open XSSO spec makes it
28 * clear that this function is a duplicate of the one already in
29 * libpam and therefore unnecessary. IT WILL BE COMPLETELY REMOVED
30 * IN libpam_misc 1.0 */
32 char **pam_misc_copy_env(pam_handle_t *pamh);
33 char **pam_misc_copy_env(pam_handle_t *pamh)
35 return pam_getenvlist(pamh);
39 * This function should be used to carefully dispose of the copied
42 * usage: env = pam_misc_drop_env(env);
45 char **pam_misc_drop_env(char **dump)
49 for (i=0; dump[i] != NULL; ++i) {
50 D(("dump[%d]=`%s'", i, dump[i]));
51 _pam_overwrite(dump[i]);
60 * This function takes the supplied environment and uploads it to be
64 int pam_misc_paste_env(pam_handle_t *pamh, const char * const * user_env)
66 for (; user_env && *user_env; ++user_env) {
69 D(("uploading: %s", *user_env));
70 retval = pam_putenv(pamh, *user_env);
71 if (retval != PAM_SUCCESS) {
72 D(("error setting %s: %s", *user_env, pam_strerror(pamh,retval)));
81 * This is a wrapper to make pam behave in the way that setenv() does.
84 int pam_misc_setenv(pam_handle_t *pamh, const char *name
85 , const char *value, int readonly)
93 /* we check if the variable is there already */
94 etmp = pam_getenv(pamh, name);
96 D(("failed to set readonly variable: %s", name));
97 return PAM_PERM_DENIED; /* not allowed to overwrite */
100 tmp = malloc(2+strlen(name)+strlen(value));
102 sprintf(tmp,"%s=%s",name,value);
103 D(("pam_putt()ing: %s", tmp));
104 retval = pam_putenv(pamh, tmp);
105 _pam_overwrite(tmp); /* purge */
106 _pam_drop(tmp); /* forget */
108 D(("malloc failure"));
109 retval = PAM_BUF_ERR;