Skip to content

Create parent dirs for useradd -m#2

Closed
thorstenb wants to merge 1 commit intoshadow-maint:masterfrom
thorstenb:master
Closed

Create parent dirs for useradd -m#2
thorstenb wants to merge 1 commit intoshadow-maint:masterfrom
thorstenb:master

Conversation

@thorstenb
Copy link
Copy Markdown

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.

Code from pwdutils 3.2.2 with slight adaptations.
@thorstenb
Copy link
Copy Markdown
Author

A polite ping - is this PR still of interest?


path[0] = '\0';
bhome = strdup (user_home);
++bhome;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check for strdup failure before incrementing here.

@hallyn
Copy link
Copy Markdown
Member

hallyn commented Aug 5, 2016

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.

@hallyn
Copy link
Copy Markdown
Member

hallyn commented Mar 24, 2018

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes please, I've somewhat moved on from that code. Given my response latency, perhaps best if you roll your proposed changes in.

@jubalh
Copy link
Copy Markdown
Member

jubalh commented May 14, 2018

What's the current state of this PR?

Is there still interest in adding this feature?

jubalh added a commit to jubalh/shadow that referenced this pull request May 15, 2018
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.
jubalh added a commit to jubalh/shadow that referenced this pull request May 15, 2018
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.
@hallyn hallyn closed this May 23, 2018
cgzones added a commit to cgzones/shadow that referenced this pull request Jan 30, 2023
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]
cgzones added a commit to cgzones/shadow that referenced this pull request Feb 28, 2023
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]
cgzones added a commit to cgzones/shadow that referenced this pull request Mar 31, 2023
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]
cgzones added a commit to cgzones/shadow that referenced this pull request Apr 1, 2023
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
cgzones added a commit to cgzones/shadow that referenced this pull request Apr 11, 2023
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]
hallyn pushed a commit that referenced this pull request Apr 26, 2023
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
alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request Mar 1, 2026
'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>
alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request Mar 1, 2026
'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>
alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request Mar 4, 2026
'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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants