]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logindefs: Add function to set PATH
authorKarel Zak <kzak@redhat.com>
Wed, 7 May 2025 10:03:51 +0000 (12:03 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 7 May 2025 10:03:51 +0000 (12:03 +0200)
Let's avoid duplicate code in su() and login(1).

Signed-off-by: Karel Zak <kzak@redhat.com>
include/logindefs.h
lib/logindefs.c

index 24732ca70d331869fdbe8f2b3cd5e76034ee0f4f..35d65621e9b9ded9e0099395125340a11a7a45a5 100644 (file)
@@ -28,7 +28,10 @@ extern int getlogindefs_bool(const char *name, int dflt);
 extern unsigned long getlogindefs_num(const char *name, unsigned 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);
+extern int logindefs_setenv_path(uid_t uid);
+
 extern int effective_access(const char *path, int mode);
 extern int get_hushlogin_status(struct passwd *pwd, const char *override_home, int force_check);
 
index 4fee83957a07f8290d6c6e7a18568e4f5339ab2b..079f2dabf9af68ca360f90bf20c14529259aeda8 100644 (file)
@@ -424,6 +424,22 @@ int logindefs_setenv(const char *name, const char *conf, const char *dflt)
        return val ? setenv(name, val, 1) : -1;
 }
 
+/*
+ * logindefs based setenv("PATH")
+ */
+int logindefs_setenv_path(uid_t uid)
+{
+       int rc = 0;
+
+       if (uid)
+               rc = logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);
+
+       else if ((rc = logindefs_setenv("PATH", "ENV_SUPATH", NULL)) != 0)
+               rc = logindefs_setenv("PATH", "ENV_ROOTPATH", _PATH_DEFPATH_ROOT);
+
+       return rc;
+}
+
 /*
  * We need to check the effective UID/GID. For example, $HOME could be on a
  * root-squashed NFS or on an NFS with UID mapping, and access(2) uses the