summaryrefslogtreecommitdiffstats
path: root/src/shared/creds-util.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-01-09 08:00:53 +0100
committerLennart Poettering <lennart@poettering.net>2024-01-10 09:54:39 +0100
commit95bcaa4e81dc148692e26764a6a5d3b53b155fe1 (patch)
tree5fef8c81c649ac519d97616f4f652759d94734a8 /src/shared/creds-util.c
parentMerge pull request #30853 from YHNdnzj/mount-accept-fstab-node (diff)
downloadsystemd-95bcaa4e81dc148692e26764a6a5d3b53b155fe1.tar.xz
systemd-95bcaa4e81dc148692e26764a6a5d3b53b155fe1.zip
creds-util: make read_credential_strings_many behave the same as comment
The comment states "If the specified buffers are already non-NULL frees them if a credential is found". Also return 1 if all credentials are found.
Diffstat (limited to 'src/shared/creds-util.c')
-rw-r--r--src/shared/creds-util.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c
index 08d915cb8d..434907c998 100644
--- a/src/shared/creds-util.c
+++ b/src/shared/creds-util.c
@@ -219,6 +219,7 @@ int read_credential_strings_many_internal(
...) {
_cleanup_free_ void *b = NULL;
+ bool all = true;
int r, ret = 0;
/* Reads a bunch of credentials into the specified buffers. If the specified buffers are already
@@ -234,10 +235,11 @@ int read_credential_strings_many_internal(
r = read_credential(first_name, &b, NULL);
if (r == -ENXIO) /* No creds passed at all? Bail immediately. */
return 0;
- if (r < 0) {
- if (r != -ENOENT)
- ret = r;
- } else
+ if (r == -ENOENT)
+ all = false;
+ else if (r < 0)
+ RET_GATHER(ret, r);
+ else
free_and_replace(*first_value, b);
va_list ap;
@@ -252,20 +254,19 @@ int read_credential_strings_many_internal(
if (!name)
break;
- value = va_arg(ap, char **);
- if (*value)
- continue;
+ value = ASSERT_PTR(va_arg(ap, char **));
r = read_credential(name, &bb, NULL);
- if (r < 0) {
- if (ret >= 0 && r != -ENOENT)
- ret = r;
- } else
+ if (r == -ENOENT)
+ all = false;
+ else if (r < 0)
+ RET_GATHER(ret, r);
+ else
free_and_replace(*value, bb);
}
va_end(ap);
- return ret;
+ return ret < 0 ? ret : all;
}
int read_credential_bool(const char *name) {