2018-05-16 16:26:18 +02:00
|
|
|
https://github.com/shadow-maint/shadow/pull/112
|
|
|
|
|
|
|
|
useradd-mkdirs.patch adapted to two comments in https://github.com/shadow-maint/shadow/pull/2
|
|
|
|
* check for stdup failure
|
|
|
|
* create dirs with 0755 instead of 0777
|
|
|
|
diff -urEbwB shadow-4.6/src/useradd.c shadow-4.6.new-useradd-mkdirs/src/useradd.c
|
|
|
|
--- shadow-4.6/src/useradd.c 2018-04-29 18:42:37.000000000 +0200
|
|
|
|
+++ shadow-4.6.new-useradd-mkdirs/src/useradd.c 2018-05-15 17:11:03.706371270 +0200
|
|
|
|
@@ -2018,6 +2018,19 @@
|
2014-04-01 17:44:20 +02:00
|
|
|
static void create_home (void)
|
|
|
|
{
|
2018-05-16 16:26:18 +02:00
|
|
|
if (access (prefix_user_home, F_OK) != 0) {
|
|
|
|
+ char path[strlen (prefix_user_home) + 2];
|
2014-04-01 17:44:20 +02:00
|
|
|
+ char *bhome, *cp;
|
|
|
|
+
|
|
|
|
+ path[0] = '\0';
|
2018-05-16 16:26:18 +02:00
|
|
|
+ bhome = strdup (prefix_user_home);
|
|
|
|
+ if (!bhome) {
|
|
|
|
+ fprintf (stderr,
|
|
|
|
+ _("%s: error while duplicating string %s\n"),
|
|
|
|
+ Prog, user_home);
|
|
|
|
+ fail_exit (E_HOMEDIR);
|
|
|
|
+ }
|
2014-04-01 17:44:20 +02:00
|
|
|
+ ++bhome;
|
|
|
|
+
|
|
|
|
#ifdef WITH_SELINUX
|
2018-05-16 16:26:18 +02:00
|
|
|
if (set_selinux_file_context (prefix_user_home) != 0) {
|
2017-05-23 14:25:13 +02:00
|
|
|
fprintf (stderr,
|
2018-05-16 16:26:18 +02:00
|
|
|
@@ -2026,11 +2039,20 @@
|
2014-04-01 17:44:20 +02:00
|
|
|
fail_exit (E_HOMEDIR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
- /* XXX - create missing parent directories. --marekm */
|
2018-05-16 16:26:18 +02:00
|
|
|
- if (mkdir (prefix_user_home, 0) != 0) {
|
2014-04-01 17:44:20 +02:00
|
|
|
+
|
|
|
|
+ /* Check for every part of the path, if the directory
|
|
|
|
+ exists. If not, create it with permissions 755 and
|
|
|
|
+ owner root:root.
|
|
|
|
+ */
|
|
|
|
+ cp = strtok (bhome, "/");
|
|
|
|
+ while (cp) {
|
|
|
|
+ strcat (path, "/");
|
|
|
|
+ strcat (path, cp);
|
|
|
|
+ if (access (path, F_OK) != 0) {
|
|
|
|
+ if (mkdir (path, 0) != 0) {
|
2018-05-16 16:26:18 +02:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot create directory %s\n"),
|
|
|
|
- Prog, prefix_user_home);
|
2014-04-01 17:44:20 +02:00
|
|
|
+ Prog, path);
|
|
|
|
#ifdef WITH_AUDIT
|
2018-05-16 16:26:18 +02:00
|
|
|
audit_logger (AUDIT_ADD_USER, Prog,
|
|
|
|
"adding home directory",
|
|
|
|
@@ -2039,6 +2061,20 @@
|
2014-04-01 17:44:20 +02:00
|
|
|
#endif
|
2018-05-16 16:26:18 +02:00
|
|
|
fail_exit (E_HOMEDIR);
|
|
|
|
}
|
2014-04-01 17:44:20 +02:00
|
|
|
+ if (chown (path, 0, 0) < 0) {
|
|
|
|
+ fprintf (stderr,
|
|
|
|
+ _("%s: warning: chown on `%s' failed: %m\n"),
|
|
|
|
+ Prog, path);
|
|
|
|
+ }
|
2018-05-16 16:26:18 +02:00
|
|
|
+ if (chmod (path, 0755) < 0) {
|
2014-04-01 17:44:20 +02:00
|
|
|
+ fprintf (stderr,
|
|
|
|
+ _("%s: warning: chmod on `%s' failed: %m\n"),
|
|
|
|
+ Prog, path);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cp = strtok (NULL, "/");
|
2018-05-16 16:26:18 +02:00
|
|
|
+ }
|
2014-04-01 17:44:20 +02:00
|
|
|
+
|
2018-05-16 16:26:18 +02:00
|
|
|
(void) chown (prefix_user_home, user_id, user_gid);
|
|
|
|
chmod (prefix_user_home,
|
2014-04-01 17:44:20 +02:00
|
|
|
0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
|