There's no standard function that copies from a null-padded character sequence into a string. A few standard functions can be workarounded to do that: - strncat(3): This function is designed to catenate from a null-padded character sequence into a string. The catch is that there's no *cpy() equivalent of it --strncpy(3) is not at all related to strncat(3); don't be fooled by the confusing name--, so one would need to zero the first byte before the call to strncat(3). It also has the inconvenient that it returns a useless value. - strncpy(3): This function is designed to copy from a string to a null-padded character sequence; the opposite of what we want to do. If one passes the size of src instead of the size of dst, and then manually zeroes the last byte of the dst buffer, something similar to what we want happens. However, this does more than what we want: it also padds with NUL the remaining bytes after the terminating NUL. That extra work can confuse maintainers to believe that it's necessary. That is exactly what happens in logout.c. src/logoutd.c-46- /* src/logoutd.c-47- * ut_user may not have the terminating NUL. src/logoutd.c-48- */ src/logoutd.c:49: strncpy (user, ut->ut_user, sizeof (ut->ut_user)); src/logoutd.c-50- user[sizeof (ut->ut_user)] = '\0'; In that logout.c case --and in most invocations of strncpy(3), which is usually a wrong tool-- the extra work is not wanted, so it's preferrable to use the right tool, a function that does exactly what's needed and nothing more than that. That tool is zustr2stp(). Read string_copying(7) for a more complete comparison of string copying functions. Cc: Christian Göttsche <cgzones@googlemail.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
shadow-utils
Introduction
The shadow-utils package includes the necessary programs for converting UNIX password files to the shadow password format, plus programs for managing user and group accounts. The pwconv command converts passwords to the shadow password format. The pwunconv command unconverts shadow passwords and generates a passwd file (a standard UNIX password file). The pwck command checks the integrity of password and shadow files. The lastlog command prints out the last login times for all users. The useradd, userdel, and usermod commands are used for managing user accounts. The groupadd, groupdel, and groupmod commands are used for managing group accounts.
Sites
Contacts
There are several ways to contact us:
- the general discussion mailing list
- the #shadow IRC channel on libera.chat:
- irc://irc.libera.chat/shadow
Mailing archives
- the general discussion mailing list archive
- the commit mailing list archive, only used for historical purposes
Contributions
Contributions are welcome. Follow the guidelines before posting any patches.
Authors and maintainers
Authors and maintainers are listed in AUTHORS.md.