]> git.ipfire.org Git - pakfire.git/commitdiff
client: Use the hostname as default principal
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 12:00:31 +0000 (12:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 12:00:31 +0000 (12:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c

index a94bd83dac18eb5b9cb7dfc28e1375f2d67d3403..96e838933a9707d24f3afaffc2c2fbcb82a10c17 100644 (file)
@@ -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)