Create parent dirs for useradd -m#2
Conversation
Code from pwdutils 3.2.2 with slight adaptations.
|
A polite ping - is this PR still of interest? |
|
|
||
| path[0] = '\0'; | ||
| bhome = strdup (user_home); | ||
| ++bhome; |
There was a problem hiding this comment.
Need to check for strdup failure before incrementing here.
|
Thanks for doing this patch, sorry for the delay. Indeed it seems worth doing, although the alternative (for which there is an open debian bug) is to simply drop this functionality from shadow and have everyone switch to other implemenetations. |
|
Hi - one last ping; If no reply (or if you ask me to) I'll update the patch myself and apply. Thanks. |
| ++bhome; | ||
|
|
||
| #ifdef WITH_SELINUX | ||
| if (set_selinux_file_context (user_home) != 0) { |
There was a problem hiding this comment.
One more change - this set_selinux_file_context() must happen after the parent directories have been created, else it will apply to the parent directories we create.
There was a problem hiding this comment.
Ah yes please, I've somewhat moved on from that code. Given my response latency, perhaps best if you roll your proposed changes in.
|
What's the current state of this PR? Is there still interest in adding this feature? |
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.
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.
A crypt method needs to be specified before the rounds can set:
#0 __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse4_2.S:227
shadow-maint#1 0x0000555555557755 in process_flags (argv=0x7fffffffe4d8, argc=3) at chgpasswd.c:188
shadow-maint#2 main (argc=3, argv=0x7fffffffe4d8) at chgpasswd.c:427
chgpasswd.c:188:42: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
A crypt method needs to be specified before the rounds can set:
#0 __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse4_2.S:227
shadow-maint#1 0x0000555555557755 in process_flags (argv=0x7fffffffe4d8, argc=3) at chgpasswd.c:188
shadow-maint#2 main (argc=3, argv=0x7fffffffe4d8) at chgpasswd.c:427
chgpasswd.c:188:42: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
A crypt method needs to be specified before the rounds can set:
#0 __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse4_2.S:227
shadow-maint#1 0x0000555555557755 in process_flags (argv=0x7fffffffe4d8, argc=3) at chgpasswd.c:188
shadow-maint#2 main (argc=3, argv=0x7fffffffe4d8) at chgpasswd.c:427
chgpasswd.c:188:42: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
Free the actual struct of the removed entry.
Example userdel report:
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x55b230efe857 in reallocarray (./src/userdel+0xda857)
shadow-maint#1 0x55b230f6041f in mallocarray ./lib/./alloc.h:97:9
shadow-maint#2 0x55b230f6041f in commonio_open ./lib/commonio.c:563:7
shadow-maint#3 0x55b230f39098 in open_files ./src/userdel.c:555:6
shadow-maint#4 0x55b230f39098 in main ./src/userdel.c:1189:2
shadow-maint#5 0x7f9b48c64189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
A crypt method needs to be specified before the rounds can set:
#0 __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse4_2.S:227
shadow-maint#1 0x0000555555557755 in process_flags (argv=0x7fffffffe4d8, argc=3) at chgpasswd.c:188
shadow-maint#2 main (argc=3, argv=0x7fffffffe4d8) at chgpasswd.c:427
chgpasswd.c:188:42: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
Free the actual struct of the removed entry.
Example userdel report:
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x55b230efe857 in reallocarray (./src/userdel+0xda857)
#1 0x55b230f6041f in mallocarray ./lib/./alloc.h:97:9
#2 0x55b230f6041f in commonio_open ./lib/commonio.c:563:7
#3 0x55b230f39098 in open_files ./src/userdel.c:555:6
#4 0x55b230f39098 in main ./src/userdel.c:1189:2
#5 0x7f9b48c64189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
'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>
Code from pwdutils 3.2.2 with slight adaptations, under BSD-3-clause project license of course. Fixes the 'XXX - create missing parent directories. --marekm' problem.