summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0001-Make-root-s-home-directory-configurable.patch
blob: a86c8410df3e11fcfa5b0641fef00257c1515f9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
From 4dc8dee0435bb63cbe474004b0a8df0363fe94dd Mon Sep 17 00:00:00 2001
From: Dan McGregor <dan.mcgregor@usask.ca>
Date: Fri, 5 Sep 2014 06:28:58 -0600
Subject: [PATCH] Make root's home directory configurable.

OpenEmbedded has a configurable home directory for root. Allow
systemd to be built using its idea of what root's home directory
should be.

Upstream-Status: Pending

Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
---
 Makefile.am                       | 2 ++
 configure.ac                      | 7 +++++++
 src/core/unit-printf.c            | 2 +-
 src/nspawn/nspawn.c               | 4 ++--
 src/shared/util.c                 | 4 ++--
 units/console-shell.service.m4.in | 4 ++--
 units/emergency.service.in        | 4 ++--
 units/rescue.service.m4.in        | 4 ++--
 8 files changed, 20 insertions(+), 11 deletions(-)

Index: git/Makefile.am
===================================================================
--- git.orig/Makefile.am
+++ git/Makefile.am
@@ -195,6 +195,7 @@ AM_CPPFLAGS = \
 	-DKEXEC=\"$(KEXEC)\" \
 	-DLIBDIR=\"$(libdir)\" \
 	-DROOTLIBDIR=\"$(rootlibdir)\" \
+	-DROOTHOMEDIR=\"$(roothomedir)\" \
 	-DTEST_DIR=\"$(abs_top_srcdir)/test\" \
 	-I $(top_srcdir)/src \
 	-I $(top_builddir)/src/shared \
@@ -5830,6 +5831,7 @@ EXTRA_DIST += \
 substitutions = \
        '|rootlibexecdir=$(rootlibexecdir)|' \
        '|rootbindir=$(rootbindir)|' \
+       '|roothomedir=$(roothomedir)|' \
        '|bindir=$(bindir)|' \
        '|SYSTEMCTL=$(rootbindir)/systemctl|' \
        '|SYSTEMD_NOTIFY=$(rootbindir)/systemd-notify|' \
Index: git/configure.ac
===================================================================
--- git.orig/configure.ac
+++ git/configure.ac
@@ -1310,6 +1310,11 @@ AC_ARG_WITH([rootlibdir],
         [],
         [with_rootlibdir=${libdir}])
 
+AC_ARG_WITH([roothomedir],
+        AS_HELP_STRING([--with-roothomedir=DIR], [Home directory for the root user]),
+        [],
+        [with_roothomedir=/root])
+
 AC_ARG_WITH([pamlibdir],
         AS_HELP_STRING([--with-pamlibdir=DIR], [Directory for PAM modules]),
         [],
@@ -1362,6 +1367,7 @@ AC_SUBST([pamlibdir], [$with_pamlibdir])
 AC_SUBST([pamconfdir], [$with_pamconfdir])
 AC_SUBST([rootprefix], [$with_rootprefix])
 AC_SUBST([rootlibdir], [$with_rootlibdir])
+AC_SUBST([roothomedir], [$with_roothomedir])
 
 AC_CONFIG_FILES([
         Makefile po/Makefile.in
@@ -1446,6 +1452,7 @@ AC_MSG_RESULT([
         include_prefix:          ${INCLUDE_PREFIX}
         lib dir:                 ${libdir}
         rootlib dir:             ${with_rootlibdir}
+        root home dir:           ${with_roothomedir}
         SysV init scripts:       ${SYSTEM_SYSVINIT_PATH}
         SysV rc?.d directories:  ${SYSTEM_SYSVRCND_PATH}
         Build Python:            ${PYTHON}
Index: git/src/core/unit-printf.c
===================================================================
--- git.orig/src/core/unit-printf.c
+++ git/src/core/unit-printf.c
@@ -259,7 +259,7 @@ static int specifier_user_home(char spec
                  * best of it if we can, but fail if we can't */
 
                 if (!c->user || streq(c->user, "root") || streq(c->user, "0"))
-                        n = strdup("/root");
+                        n = strdup(ROOTHOMEDIR);
                 else
                         return -ENOTSUP;
 
Index: git/src/nspawn/nspawn.c
===================================================================
--- git.orig/src/nspawn/nspawn.c
+++ git/src/nspawn/nspawn.c
@@ -3183,7 +3183,7 @@ int main(int argc, char *argv[]) {
                         if (r < 0)
                                 _exit(EXIT_FAILURE);
 
-                        if ((asprintf((char**)(envp + n_env++), "HOME=%s", home ? home: "/root") < 0) ||
+                        if ((asprintf((char**)(envp + n_env++), "HOME=%s", home ? home: ROOTHOMEDIR) < 0) ||
                             (asprintf((char**)(envp + n_env++), "USER=%s", arg_user ? arg_user : "root") < 0) ||
                             (asprintf((char**)(envp + n_env++), "LOGNAME=%s", arg_user ? arg_user : "root") < 0)) {
                                 log_oom();
@@ -3278,7 +3278,7 @@ int main(int argc, char *argv[]) {
                                 execvp(argv[optind], argv + optind);
 #endif /* HAVE_EXECVPE */                      
                         else {
-                                chdir(home ? home : "/root");
+                                chdir(home ? home : ROOTHOMEDIR);
                                 execle("/bin/bash", "-bash", NULL, env_use);
                                 execle("/bin/sh", "-sh", NULL, env_use);
                         }
Index: git/src/shared/util.c
===================================================================
--- git.orig/src/shared/util.c
+++ git/src/shared/util.c
@@ -4523,7 +4523,7 @@ int get_user_creds(
                         *gid = 0;
 
                 if (home)
-                        *home = "/root";
+                        *home = ROOTHOMEDIR;
 
                 if (shell)
                         *shell = "/bin/sh";
@@ -5491,7 +5491,7 @@ int get_home_dir(char **_h) {
         /* Hardcode home directory for root to avoid NSS */
         u = getuid();
         if (u == 0) {
-                h = strdup("/root");
+                h = strdup(ROOTHOMEDIR);
                 if (!h)
                         return -ENOMEM;
 
Index: git/units/console-shell.service.m4.in
===================================================================
--- git.orig/units/console-shell.service.m4.in
+++ git/units/console-shell.service.m4.in
@@ -15,8 +15,8 @@ After=rc-local.service
 Before=getty.target
 
 [Service]
-Environment=HOME=/root
-WorkingDirectory=/root
+Environment=HOME=@roothomedir@
+WorkingDirectory=@roothomedir@
 ExecStart=-/sbin/sulogin
 ExecStopPost=-@SYSTEMCTL@ poweroff
 Type=idle
Index: git/units/emergency.service.in
===================================================================
--- git.orig/units/emergency.service.in
+++ git/units/emergency.service.in
@@ -14,8 +14,8 @@ Conflicts=rescue.service
 Before=shutdown.target
 
 [Service]
-Environment=HOME=/root
-WorkingDirectory=/root
+Environment=HOME=@roothomedir@
+WorkingDirectory=@roothomedir@
 ExecStartPre=-/bin/plymouth quit
 ExecStartPre=-/bin/echo -e 'Welcome to emergency mode! After logging in, type "journalctl -xb" to view\\nsystem logs, "systemctl reboot" to reboot, "systemctl default" or ^D to\\ntry again to boot into default mode.'
 ExecStart=-/bin/sh -c "/sbin/sulogin; @SYSTEMCTL@ --fail --no-block default"
Index: git/units/rescue.service.in
===================================================================
--- git.orig/units/rescue.service.in
+++ git/units/rescue.service.in
@@ -14,8 +14,8 @@ After=sysinit.target plymouth-start.serv
 Before=shutdown.target
 
 [Service]
-Environment=HOME=/root
-WorkingDirectory=/root
+Environment=HOME=@roothomedir@
+WorkingDirectory=@roothomedir@
 ExecStartPre=-/bin/plymouth quit
 ExecStartPre=-/bin/echo -e 'Welcome to emergency mode! After logging in, type "journalctl -xb" to view\\nsystem logs, "systemctl reboot" to reboot, "systemctl default" or ^D to\\nboot into default mode.'
 ExecStart=-/bin/sh -c "/sbin/sulogin; @SYSTEMCTL@ --fail --no-block default"