]> git.ipfire.org Git - thirdparty/systemd.git/commit
user-util: add get{pw,gr}{uid,gid,name}_malloc() helpers 31011/head
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Jan 2024 10:38:54 +0000 (11:38 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Jan 2024 16:55:07 +0000 (17:55 +0100)
commit75673cd8aee5c6174538e71dd36c7a353c836973
treebba42f8ced8fd93b616b70add9e0245f5f32bb82
parent829854afa5e38db30be207fc8f8f80705e623795
user-util: add get{pw,gr}{uid,gid,name}_malloc() helpers

These are wrappers around getpwuid_r() and friends, and will allocate the
right-sized buffer for this call.

We so far had multiple implementations of a buffer allocation loop
around getpwuid_r() and friends, and they all suck in some way. Let's
clean this up and add a common implementation, and use it everywhere.

Also, be more careful with error numbers, in particular systematically
turn ENOENT into ENOSRCH (the former is what is returned if /etc/passwd
is absent, which we want to consider identical to user not existing,
which is ENOSRCH). We so far did this at some invocations, but not all.

There are some invocations of getpwuid() left in the codebase. We really
should fix those too, and have a single unified implementation of the
logic, but those are not as trivial to convert, so left for another
time.
src/basic/user-util.c
src/basic/user-util.h
src/core/dynamic-user.c
src/firstboot/firstboot.c
src/home/homed-manager-bus.c
src/home/homed-manager.c
src/login/logind-dbus.c
src/nspawn/nspawn.c
src/shared/user-record-nss.c
src/sysusers/sysusers.c