4 * This file was written by Andrew G. Morgan <morgan@parc.power.net>
11 #include <security/pam_misc.h>
14 * This is a useful function for dumping the Linux-PAM environment
15 * into some local memory, prior to it all getting lost when pam_end()
18 * Initially it was assumed that libpam did not do this part correctly
19 * (based on a loose email definition). The X/Open XSSO spec makes it
20 * clear that this function is a duplicate of the one already in
21 * libpam and therefore unnecessary. IT WILL BE COMPLETELY REMOVED
22 * IN libpam_misc 1.0 */
24 char **pam_misc_copy_env(pam_handle_t *pamh);
25 char **pam_misc_copy_env(pam_handle_t *pamh)
27 return pam_getenvlist(pamh);
31 * This function should be used to carefully dispose of the copied
34 * usage: env = pam_misc_drop_env(env);
37 char **pam_misc_drop_env(char **dump)
41 for (i=0; dump[i] != NULL; ++i) {
42 D(("dump[%d]=`%s'", i, dump[i]));
43 _pam_overwrite(dump[i]);
52 * This function takes the supplied environment and uploads it to be
56 int pam_misc_paste_env(pam_handle_t *pamh, const char * const * user_env)
58 for (; user_env && *user_env; ++user_env) {
61 D(("uploading: %s", *user_env));
62 retval = pam_putenv(pamh, *user_env);
63 if (retval != PAM_SUCCESS) {
64 D(("error setting %s: %s", *user_env, pam_strerror(pamh,retval)));
73 * This is a wrapper to make pam behave in the way that setenv() does.
76 int pam_misc_setenv(pam_handle_t *pamh, const char *name
77 , const char *value, int readonly)
85 /* we check if the variable is there already */
86 etmp = pam_getenv(pamh, name);
88 D(("failed to set readonly variable: %s", name));
89 return PAM_PERM_DENIED; /* not allowed to overwrite */
92 tmp = malloc(2+strlen(name)+strlen(value));
94 sprintf(tmp,"%s=%s",name,value);
95 D(("pam_putt()ing: %s", tmp));
96 retval = pam_putenv(pamh, tmp);
97 _pam_overwrite(tmp); /* purge */
98 _pam_drop(tmp); /* forget */
100 D(("malloc failure"));
101 retval = PAM_BUF_ERR;