From 9dd33dce76d961534c38b44c6989c61295cd5fda Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 18 Sep 2025 09:19:28 +0200 Subject: [PATCH] machine-credential: replace machine_credentials_contains() by machine_credential_find() --- src/shared/machine-credential.c | 10 +++++----- src/shared/machine-credential.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/shared/machine-credential.c b/src/shared/machine-credential.c index a3dd7f1cc24..407bd18bff2 100644 --- a/src/shared/machine-credential.c +++ b/src/shared/machine-credential.c @@ -28,15 +28,15 @@ void machine_credential_context_done(MachineCredentialContext *ctx) { free(ctx->credentials); } -bool machine_credentials_contains(const MachineCredentialContext *ctx, const char *id) { +MachineCredential* machine_credential_find(MachineCredentialContext *ctx, const char *id) { assert(ctx); assert(id); FOREACH_ARRAY(cred, ctx->credentials, ctx->n_credentials) if (streq(cred->id, id)) - return true; + return cred; - return false; + return NULL; } int machine_credential_set(MachineCredentialContext *ctx, const char *cred_str) { @@ -58,7 +58,7 @@ int machine_credential_set(MachineCredentialContext *ctx, const char *cred_str) if (!credential_name_valid(cred.id)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Credential name is not valid: %s", cred.id); - if (machine_credentials_contains(ctx, cred.id)) + if (machine_credential_find(ctx, cred.id)) return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Duplicate credential '%s', refusing.", cred.id); l = cunescape(p, UNESCAPE_ACCEPT_NUL, &cred.data); @@ -93,7 +93,7 @@ int machine_credential_load(MachineCredentialContext *ctx, const char *cred_path if (!credential_name_valid(cred.id)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Credential name is not valid: %s", cred.id); - if (machine_credentials_contains(ctx, cred.id)) + if (machine_credential_find(ctx, cred.id)) return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Duplicate credential '%s', refusing.", cred.id); if (is_path(p) && path_is_valid(p)) diff --git a/src/shared/machine-credential.h b/src/shared/machine-credential.h index 9734e528781..1b5f4fa1121 100644 --- a/src/shared/machine-credential.h +++ b/src/shared/machine-credential.h @@ -16,7 +16,7 @@ typedef struct MachineCredentialContext { void machine_credential_context_done(MachineCredentialContext *ctx); -bool machine_credentials_contains(const MachineCredentialContext *ctx, const char *id); +MachineCredential* machine_credential_find(MachineCredentialContext *ctx, const char *id); int machine_credential_set(MachineCredentialContext *ctx, const char *cred_str); int machine_credential_load(MachineCredentialContext *ctx, const char *cred_path); -- 2.47.3