summaryrefslogtreecommitdiffstats
path: root/login-utils/su.c
diff options
context:
space:
mode:
authorLudwig Nussel2012-06-01 14:51:18 +0200
committerKarel Zak2012-06-05 15:16:18 +0200
commite557efdeddaf0496e846b5b1079ab8c91f56419b (patch)
treee2dc790abcd4377050ecad1e1ee6a92893da8264 /login-utils/su.c
parentsu: use ENV_PATH resp ENV_SUPATH to be consistent with login (diff)
downloadkernel-qcow2-util-linux-e557efdeddaf0496e846b5b1079ab8c91f56419b.tar.gz
kernel-qcow2-util-linux-e557efdeddaf0496e846b5b1079ab8c91f56419b.tar.xz
kernel-qcow2-util-linux-e557efdeddaf0496e846b5b1079ab8c91f56419b.zip
su: introduce xsetenv globally
Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Diffstat (limited to 'login-utils/su.c')
-rw-r--r--login-utils/su.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/login-utils/su.c b/login-utils/su.c
index 22b9ccc08..cdaf31e7d 100644
--- a/login-utils/su.c
+++ b/login-utils/su.c
@@ -62,6 +62,7 @@ enum
#include "xalloc.h"
#include "nls.h"
#include "pathnames.h"
+#include "env.h"
/* name of the pam configuration files. separate configs for su and su - */
#define PAM_SERVICE_NAME "su"
@@ -111,21 +112,6 @@ static struct option const longopts[] =
{NULL, 0, NULL, 0}
};
-/* Add NAME=VAL to the environment, checking for out of memory errors. */
-
-static void
-xsetenv (char const *name, char const *val)
-{
- size_t namelen = strlen (name);
- size_t vallen = strlen (val);
- char *string = xmalloc (namelen + 1 + vallen + 1);
- strcpy (string, name);
- string[namelen] = '=';
- strcpy (string + namelen + 1, val);
- if (putenv (string) != 0)
- error (EXIT_FAILURE, 0, _("out of memory"));
-}
-
/* Log the fact that someone has run su to the user given by PW;
if SUCCESSFUL is true, they gave the correct password, etc. */
@@ -506,11 +492,11 @@ modify_environment (const struct passwd *pw, const char *shell)
environ = xmalloc ((6 + !!term) * sizeof (char *));
environ[0] = NULL;
if (term)
- xsetenv ("TERM", term);
- xsetenv ("HOME", pw->pw_dir);
- xsetenv ("SHELL", shell);
- xsetenv ("USER", pw->pw_name);
- xsetenv ("LOGNAME", pw->pw_name);
+ xsetenv ("TERM", term, 1);
+ xsetenv ("HOME", pw->pw_dir, 1);
+ xsetenv ("SHELL", shell, 1);
+ xsetenv ("USER", pw->pw_name, 1);
+ xsetenv ("LOGNAME", pw->pw_name, 1);
set_path(pw);
}
else
@@ -519,8 +505,8 @@ modify_environment (const struct passwd *pw, const char *shell)
USER and LOGNAME. */
if (change_environment)
{
- xsetenv ("HOME", pw->pw_dir);
- xsetenv ("SHELL", shell);
+ xsetenv ("HOME", pw->pw_dir, 1);
+ xsetenv ("SHELL", shell, 1);
if (getlogindefs_bool ("ALWAYS_SET_PATH", 0))
set_path(pw);
else
@@ -535,14 +521,14 @@ modify_environment (const struct passwd *pw, const char *shell)
if (new)
{
- xsetenv ("PATH", new);
+ xsetenv ("PATH", new, 1);
free (new);
}
}
if (pw->pw_uid)
{
- xsetenv ("USER", pw->pw_name);
- xsetenv ("LOGNAME", pw->pw_name);
+ xsetenv ("USER", pw->pw_name, 1);
+ xsetenv ("LOGNAME", pw->pw_name, 1);
}
}
}