diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-02-19 00:08:39 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-02-20 12:38:06 +0900 |
commit | e99ca1474145f7fad38bb0255d344f4ad7717ef5 (patch) | |
tree | 4c8662608ea96da642bc293d4838deeac860ed18 /src/shared/pkcs11-util.c | |
parent | 5cf84d2545fc314d970e0eded0258d1650bed3cd (diff) | |
download | systemd-e99ca1474145f7fad38bb0255d344f4ad7717ef5.tar.gz |
env-util: replace unsetenv_erase() by new getenv_steal_erase() helper
The new helper combines a bunch of steps every invocation of
unsetenv_erase() did so far: getenv() + strdup() + unsetenv_erase().
Let's unify this into one helper that is harder to use incorrectly. It's
in inspired by TAKE_PTR() in a way: get the env var out and invalidate
where it was before.
Diffstat (limited to 'src/shared/pkcs11-util.c')
-rw-r--r-- | src/shared/pkcs11-util.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c index 67ea44515a..b01b9983c2 100644 --- a/src/shared/pkcs11-util.c +++ b/src/shared/pkcs11-util.c @@ -275,15 +275,17 @@ int pkcs11_token_login( for (unsigned tries = 0; tries < 3; tries++) { _cleanup_strv_free_erase_ char **passwords = NULL; - char **i, *e; + _cleanup_(erase_and_freep) char *envpin = NULL; + char **i; - e = getenv("PIN"); - if (e) { - passwords = strv_new(e); + r = getenv_steal_erase("PIN", &envpin); + if (r < 0) + return log_error_errno(r, "Failed to acquire PIN from environment: %m"); + if (r > 0) { + passwords = strv_new(envpin); if (!passwords) return log_oom(); - assert_se(unsetenv_erase("PIN") >= 0); } else if (headless) return log_error_errno(SYNTHETIC_ERRNO(ENOPKG), "PIN querying disabled via 'headless' option. Use the 'PIN' environment variable."); else { |