8000 logindefs: Add function to set PATH · util-linux/util-linux@7b0423d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b0423d

Browse files
committed
logindefs: Add function to set PATH
Let's avoid duplicate code in su() and login(1). Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent 4e41733 commit 7b0423d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/logindefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ extern int getlogindefs_bool(const char *name, int dflt);
2828
extern unsigned long getlogindefs_num(const char *name, unsigned long dflt);
2929
extern const char *getlogindefs_str(const char *name, const char *dflt);
3030
extern void free_getlogindefs_data(void);
31+
3132
extern int logindefs_setenv(const char *name, const char *conf, const char *dflt);
33+
extern int logindefs_setenv_path(uid_t uid);
34+
3235
extern int effective_access(const char *path, int mode);
3336
extern int get_hushlogin_status(struct passwd *pwd, const char *override_home, int force_check);
3437

lib/logindefs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,22 @@ int logindefs_setenv(const char *name, const char *conf, const char *dflt)
424424
return val ? setenv(name, val, 1) : -1;
425425
}
426426

427+
/*
428+
* logindefs based setenv("PATH")
429+
*/
430+
int logindefs_setenv_path(uid_t uid)
431+
{
432+
int rc = 0;
433+
434+
if (uid)
435+
rc = logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);
436+
437+
else if ((rc = logindefs_setenv("PATH", "ENV_SUPATH", NULL)) != 0)
438+
rc = logindefs_setenv("PATH", "ENV_ROOTPATH", _PATH_DEFPATH_ROOT);
439+
440+
return rc;
441+
}
442+
427443
/*
428444
* We need to check the effective UID/GID. For example, $HOME could be on a
429445
* root-squashed NFS or on an NFS with UID mapping, and access(2) uses the

0 commit comments

Comments
 (0)
0