Skip to content

Commit 671f0f8

Browse files
keszybzpoettering
authored andcommitted
Remove /sbin from paths if split-bin is false (systemd#8324)
Follow-up for 157baa8.
1 parent 7df4b83 commit 671f0f8

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

meson.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ if get_option('split-usr') == 'auto'
5959
else
6060
split_usr = get_option('split-usr') == 'true'
6161
endif
62-
conf.set10('HAVE_SPLIT_USR', split_usr)
62+
conf.set10('HAVE_SPLIT_USR', split_usr,
63+
description : '/usr/bin and /bin directories are separate')
6364

6465
if get_option('split-bin') == 'auto'
6566
split_bin = run_command('test', '-L', '/usr/sbin').returncode() != 0
6667
else
6768
split_bin = get_option('split-bin') == 'true'
6869
endif
70+
conf.set10('HAVE_SPLIT_BIN', split_bin,
71+
description : 'bin and sbin directories are separate')
6972

7073
rootprefixdir = get_option('rootprefix')
7174
# Unusual rootprefixdir values are used by some distros

src/basic/path-util.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@
2828
#include "string-util.h"
2929
#include "time-util.h"
3030

31-
#define DEFAULT_PATH_NORMAL "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
32-
#define DEFAULT_PATH_SPLIT_USR DEFAULT_PATH_NORMAL ":/sbin:/bin"
31+
#if HAVE_SPLIT_BIN
32+
# define PATH_SBIN_BIN(x) x "sbin:" x "bin"
33+
#else
34+
# define PATH_SBIN_BIN(x) x "bin"
35+
#endif
36+
37+
#define DEFAULT_PATH_NORMAL PATH_SBIN_BIN("/usr/local/") ":" PATH_SBIN_BIN("/usr/")
38+
#define DEFAULT_PATH_SPLIT_USR DEFAULT_PATH_NORMAL ":" PATH_SBIN_BIN("/")
3339

3440
#if HAVE_SPLIT_USR
3541
# define DEFAULT_PATH DEFAULT_PATH_SPLIT_USR

src/core/namespace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ static const MountEntry protect_system_yes_table[] = {
152152
{ "/lib", READONLY, true },
153153
{ "/lib64", READONLY, true },
154154
{ "/bin", READONLY, true },
155+
# if HAVE_SPLIT_BIN
155156
{ "/sbin", READONLY, true },
157+
# endif
156158
#endif
157159
};
158160

@@ -166,7 +168,9 @@ static const MountEntry protect_system_full_table[] = {
166168
{ "/lib", READONLY, true },
167169
{ "/lib64", READONLY, true },
168170
{ "/bin", READONLY, true },
171+
# if HAVE_SPLIT_BIN
169172
{ "/sbin", READONLY, true },
173+
# endif
170174
#endif
171175
};
172176

src/libsystemd/sd-path/sd-path.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ static int search_from_environment(
478478
return 0;
479479
}
480480

481+
#if HAVE_SPLIT_BIN
482+
# define ARRAY_SBIN_BIN(x) x "sbin", x "bin"
483+
#else
484+
# define ARRAY_SBIN_BIN(x) x "bin"
485+
#endif
486+
481487
static int get_search(uint64_t type, char ***list) {
482488

483489
assert(list);
@@ -490,13 +496,10 @@ static int get_search(uint64_t type, char ***list) {
490496
".local/bin",
491497
"PATH",
492498
true,
493-
"/usr/local/sbin",
494-
"/usr/local/bin",
495-
"/usr/sbin",
496-
"/usr/bin",
499+
ARRAY_SBIN_BIN("/usr/local/"),
500+
ARRAY_SBIN_BIN("/usr/"),
497501
#if HAVE_SPLIT_USR
498-
"/sbin",
499-
"/bin",
502+
ARRAY_SBIN_BIN("/"),
500503
#endif
501504
NULL);
502505

0 commit comments

Comments
 (0)