summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2012-02-28 11:16:16 +0100
committerKarel Zak2012-02-28 11:16:16 +0100
commit607e6b7ce8658e552fdffbb99c51cdb01828e27b (patch)
treeee07bcca5f4375c653c557104dbd8dcb42251d87 /login-utils
parenttest: test 'none' source for mount(8) (diff)
downloadkernel-qcow2-util-linux-607e6b7ce8658e552fdffbb99c51cdb01828e27b.tar.gz
kernel-qcow2-util-linux-607e6b7ce8658e552fdffbb99c51cdb01828e27b.tar.xz
kernel-qcow2-util-linux-607e6b7ce8658e552fdffbb99c51cdb01828e27b.zip
login: support crazy shadow-utils syntax in login.defs
standard syntax for FOO=data: ENV_FOO data additional syntax: ENV_FOO FOO=data Reported-by: Colin Guthrie colin@mageia.org Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/login.c11
-rw-r--r--login-utils/logindefs.c37
-rw-r--r--login-utils/logindefs.h1
3 files changed, 42 insertions, 7 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index 84d8b1bdb..bc0eaec26 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -1145,13 +1145,10 @@ static void init_environ(struct login_context *cxt)
setenv("TERM", termenv, 1);
if (pwd->pw_uid)
- setenv("PATH", getlogindefs_str("ENV_PATH", _PATH_DEFPATH), 1);
- else {
- const char *x = getlogindefs_str("ENV_ROOTPATH", NULL);
- if (!x)
- x = getlogindefs_str("ENV_SUPATH", _PATH_DEFPATH_ROOT);
- setenv("PATH", x, 1);
- }
+ logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);
+
+ else if (logindefs_setenv("PATH", "ENV_ROOTPATH", NULL) != 0)
+ logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT);
/* mailx will give a funny error msg if you forget this one */
len = snprintf(tmp, sizeof(tmp), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
diff --git a/login-utils/logindefs.c b/login-utils/logindefs.c
index fe590e990..e9517acac 100644
--- a/login-utils/logindefs.c
+++ b/login-utils/logindefs.c
@@ -211,6 +211,43 @@ const char *getlogindefs_str(const char *name, const char *dflt)
return ptr->value;
}
+/*
+ * For compatibililty with shadow-utils we have tu support additional
+ * syntax for environment variables in login.defs(5) file. The standard
+ * syntax is:
+ *
+ * ENV_FOO data
+ *
+ * but shadow-utils supports also
+ *
+ * ENV_FOO FOO=data
+ *
+ * the FOO= prefix has to be remove before we call setenv().
+ */
+int logindefs_setenv(const char *name, const char *conf, const char *dflt)
+{
+ const char *val = getlogindefs_str(conf, dflt);
+ const char *p;
+
+ if (!val)
+ return -1;
+
+ p = strchr(val, '=');
+ if (p) {
+ size_t sz = strlen(name);
+
+ if (strncmp(val, name, sz) == 0 && *(p + 1)) {
+ val = p + 1;
+ if (*val == '"')
+ val++;
+ if (!*val)
+ val = dflt;
+ }
+ }
+
+ return val ? setenv(name, val, 1) : -1;
+}
+
#ifdef TEST_PROGRAM
int main(int argc, char *argv[])
{
diff --git a/login-utils/logindefs.h b/login-utils/logindefs.h
index 37d19e1f7..163869dfd 100644
--- a/login-utils/logindefs.h
+++ b/login-utils/logindefs.h
@@ -5,5 +5,6 @@ extern int getlogindefs_bool(const char *name, int dflt);
extern long getlogindefs_num(const char *name, long dflt);
extern const char *getlogindefs_str(const char *name, const char *dflt);
extern void free_getlogindefs_data(void);
+extern int logindefs_setenv(const char *name, const char *conf, const char *dflt);
#endif /* UTIL_LINUX_LOGINDEFS_H */