diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-01-15 10:04:30 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-01-16 21:57:00 +0100 |
commit | 192aee3cae72bf4ca36c849061894e07250b93b0 (patch) | |
tree | 2d36817a5e7d47ed40b2c8d12daa2a1a50608f19 | |
parent | c7d26acce6dcb0e72be6160873fac758e9b7c440 (diff) | |
download | systemd-192aee3cae72bf4ca36c849061894e07250b93b0.tar.gz |
shared/user-record-nss: shorten code a bit
free_and_strdup() already does comparison internally.
-rw-r--r-- | src/shared/user-record-nss.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/shared/user-record-nss.c b/src/shared/user-record-nss.c index 11c085d63d..cf273653de 100644 --- a/src/shared/user-record-nss.c +++ b/src/shared/user-record-nss.c @@ -31,29 +31,18 @@ int nss_passwd_to_user_record( if (r < 0) return r; - if (isempty(pwd->pw_gecos) || streq_ptr(pwd->pw_gecos, hr->user_name)) - hr->real_name = mfree(hr->real_name); - else { - r = free_and_strdup(&hr->real_name, pwd->pw_gecos); - if (r < 0) - return r; - } + r = free_and_strdup(&hr->real_name, + streq_ptr(pwd->pw_gecos, hr->user_name) ? NULL : empty_to_null(pwd->pw_gecos)); + if (r < 0) + return r; - if (isempty(pwd->pw_dir)) - hr->home_directory = mfree(hr->home_directory); - else { - r = free_and_strdup(&hr->home_directory, pwd->pw_dir); - if (r < 0) - return r; - } + r = free_and_strdup(&hr->home_directory, empty_to_null(pwd->pw_dir)); + if (r < 0) + return r; - if (isempty(pwd->pw_shell)) - hr->shell = mfree(hr->shell); - else { - r = free_and_strdup(&hr->shell, pwd->pw_shell); - if (r < 0) - return r; - } + r = free_and_strdup(&hr->shell, empty_to_null(pwd->pw_shell)); + if (r < 0) + return r; hr->uid = pwd->pw_uid; hr->gid = pwd->pw_gid; |