Create parent dirs for useradd -m#112
Conversation
Equivalent of `mkdir -p`. It will create all parent directories. Example: `useradd -d /home2/testu1 -m testu1` Based on shadow-maint#2 by Thorsten Kukuk and Thorsten Behrens which was Code from pwdutils 3.2.2 with slight adaptations. Adapted to so it applies to current code.
|
Thanks! Will take a look. |
|
FYI, there is an issue if the username contains a |
This seems like a Debian related bug as I'm unable to reproduce it in Fedora: I'd recommend you to open a bug in their tracking system. |
Someone tested it for me now on Debian Bookworm and Bullseye and reported that it works in both cases. |
|
Yes it has to do with Debian patching chkname.c to allow almost all characters in usernames by default. That and this change to create parent directories will create the issue. My issue is that when creating the directories it will do strtok("/") on the home path (create with /home/<username>), but it does not distinguish between a "/" in the path and one in the username itself. I beelive that if the "/" is in the username itself, it should not attempt to create it as a parent directory since it is not, but rather part of the username. So that is a bug I think here. |
|
@jubalh in Bullseye and Bookworm, I just tested in docker, and I don't se the "chown" error, but behavior is the same. The other issue is due to the ambiguity of "/" in username and home path, it doesn't remove correctly when removing the user with "userdel -r": |
Correction: they confused useradd and adduser ;) |
'path' will only copy contents from 'bhome', which itself is a dup of 'prefix_user_home'. Thus it only needs to be able to hold the contents of that string (thus, strlen(3) + 1 for the NUL). We don't add any characters that were not present in the original string (but we do collapse adjacent slashes), and thus the 'path' string may be shorter or as long as 'bhome', but certainly not longer. This seems to have been an off-by-one calculation, as this code has never needed space for an extra byte, AFAICS. Fixes: b3b6d9d (2018-05-15; "Create parent dirs for useradd -m") Link: <shadow-maint#112> Link: <shadow-maint#2> Cc: Michael Vetter <jubalh@iodoru.org> Cc: Thorsten Behrens <thb@documentfoundation.org> Cc: Thorsten Kukuk <kukuk@suse.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Eric Seifert <seiferteric@gmail.com> Cc: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
'path' will only copy contents from 'bhome', which itself is a dup of 'prefix_user_home'. Thus it only needs to be able to hold the contents of that string (thus, strlen(3) + 1 for the NUL). We don't add any characters that were not present in the original string (but we do collapse adjacent slashes), and thus the 'path' string may be shorter or as long as 'bhome', but certainly not longer. This seems to have been an off-by-one calculation, as this code has never needed space for an extra byte, AFAICS. Fixes: b3b6d9d (2018-05-15; "Create parent dirs for useradd -m") Link: <shadow-maint#112> Link: <shadow-maint#2> Cc: Michael Vetter <jubalh@iodoru.org> Cc: Thorsten Behrens <thb@documentfoundation.org> Cc: Thorsten Kukuk <kukuk@suse.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Eric Seifert <seiferteric@gmail.com> Cc: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
'path' will only copy contents from 'bhome', which itself is a dup of 'prefix_user_home'. Thus it only needs to be able to hold the contents of that string (thus, strlen(3) + 1 for the NUL). We don't add any characters that were not present in the original string (but we do collapse adjacent slashes), and thus the 'path' string may be shorter or as long as 'bhome', but certainly not longer. This seems to have been an off-by-one calculation, as this code has never needed space for an extra byte, AFAICS. Fixes: b3b6d9d (2018-05-15; "Create parent dirs for useradd -m") Link: <shadow-maint#112> Link: <shadow-maint#2> Cc: Michael Vetter <jubalh@iodoru.org> Cc: Thorsten Behrens <thb@documentfoundation.org> Cc: Thorsten Kukuk <kukuk@suse.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Eric Seifert <seiferteric@gmail.com> Cc: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Equivalent of
mkdir -p. It will create all parent directories.Example:
useradd -d /home2/testu1 -m testu1Based on #2 by Thorsten Kukuk
and Thorsten Behrens which was Code from pwdutils 3.2.2 with slight adaptations.
Adapted to so it applies to current code.