From 9fc300fe00047a11978d9f4a5365ab563c2a991f Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 25 Jun 2025 12:00:31 +0000 Subject: [PATCH] client: Use the hostname as default principal Signed-off-by: Michael Tremer --- src/pakfire/client.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pakfire/client.c b/src/pakfire/client.c index a94bd83d..96e83893 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -280,6 +280,7 @@ static void pakfire_client_free(struct pakfire_client* self) { int pakfire_client_create(struct pakfire_client** client, struct pakfire_ctx* ctx, sd_event* loop, const char* url, const char* principal) { struct pakfire_client* self = NULL; + char hostname[HOST_NAME_MAX]; int r; // Allocate some memory @@ -306,6 +307,19 @@ int pakfire_client_create(struct pakfire_client** client, if (r < 0) goto ERROR; + // Use the hostname if no principal given + if (!principal) { + r = gethostname(hostname, sizeof(hostname)); + if (r < 0) { + ERROR(self->ctx, "Failed to fetch hostname: %m\n"); + r = -errno; + goto ERROR; + } + + // Use the hostname as principal + principal = hostname; + } + // Store the principal r = pakfire_string_set(self->principal, principal); if (r < 0) -- 2.47.2