4 * This file was written by Andrew G. Morgan <morgan@parc.power.net>
13 #include <security/pam_misc.h>
16 * This function should be used to carefully dispose of the copied
19 * usage: env = pam_misc_drop_env(env);
22 char **pam_misc_drop_env(char **dump)
26 for (i=0; dump[i] != NULL; ++i) {
27 D(("dump[%d]=`%s'", i, dump[i]));
28 _pam_overwrite(dump[i]);
37 * This function takes the supplied environment and uploads it to be
41 int pam_misc_paste_env(pam_handle_t *pamh, const char * const * user_env)
43 for (; user_env && *user_env; ++user_env) {
46 D(("uploading: %s", *user_env));
47 retval = pam_putenv(pamh, *user_env);
48 if (retval != PAM_SUCCESS) {
49 D(("error setting %s: %s", *user_env, pam_strerror(pamh,retval)));
58 * This is a wrapper to make pam behave in the way that setenv() does.
61 int pam_misc_setenv(pam_handle_t *pamh, const char *name
62 , const char *value, int readonly)
70 /* we check if the variable is there already */
71 etmp = pam_getenv(pamh, name);
73 D(("failed to set readonly variable: %s", name));
74 return PAM_PERM_DENIED; /* not allowed to overwrite */
77 if (asprintf(&tmp, "%s=%s", name, value) >= 0) {
78 D(("pam_putt()ing: %s", tmp));
79 retval = pam_putenv(pamh, tmp);
80 _pam_overwrite(tmp); /* purge */
81 _pam_drop(tmp); /* forget */
83 D(("malloc failure"));