4 * This file was written by Andrew G. Morgan <morgan@parc.power.net>
7 * Revision 1.1 2000/06/20 22:11:24 agmorgan
10 * Revision 1.1.1.1 1998/07/12 05:17:15 morgan
11 * Linux PAM sources pre-0.66
13 * Revision 1.2 1997/01/04 20:19:20 morgan
14 * added a prototype (no warning) and fixed paste function
16 * Revision 1.1 1996/12/01 03:25:37 morgan
24 #include <security/pam_misc.h>
27 * This is a useful function for dumping the Linux-PAM environment
28 * into some local memory, prior to it all getting lost when pam_end()
31 * Initially it was assumed that libpam did not do this part correctly
32 * (based on a loose email definition). The X/Open XSSO spec makes it
33 * clear that this function is a duplicate of the one already in
34 * libpam and therefore unnecessary. IT WILL BE COMPLETELY REMOVED
35 * IN libpam_misc 1.0 */
37 char **pam_misc_copy_env(pam_handle_t *pamh);
38 char **pam_misc_copy_env(pam_handle_t *pamh)
40 return pam_getenvlist(pamh);
44 * This function should be used to carefully dispose of the copied
47 * usage: env = pam_misc_drop_env(env);
50 char **pam_misc_drop_env(char **dump)
54 for (i=0; dump[i] != NULL; ++i) {
55 D(("dump[%d]=`%s'", i, dump[i]));
56 _pam_overwrite(dump[i]);
65 * This function takes the supplied environment and uploads it to be
69 int pam_misc_paste_env(pam_handle_t *pamh, const char * const * user_env)
71 for (; user_env && *user_env; ++user_env) {
74 D(("uploading: %s", *user_env));
75 retval = pam_putenv(pamh, *user_env);
76 if (retval != PAM_SUCCESS) {
77 D(("error setting %s: %s", *user_env, pam_strerror(pamh,retval)));
86 * This is a wrapper to make pam behave in the way that setenv() does.
89 int pam_misc_setenv(pam_handle_t *pamh, const char *name
90 , const char *value, int readonly)
98 /* we check if the variable is there already */
99 etmp = pam_getenv(pamh, name);
101 D(("failed to set readonly variable: %s", name));
102 return PAM_PERM_DENIED; /* not allowed to overwrite */
105 tmp = malloc(2+strlen(name)+strlen(value));
107 sprintf(tmp,"%s=%s",name,value);
108 D(("pam_putt()ing: %s", tmp));
109 retval = pam_putenv(pamh, tmp);
110 _pam_overwrite(tmp); /* purge */
111 _pam_drop(tmp); /* forget */
113 D(("malloc failure"));
114 retval = PAM_BUF_ERR;