]> git.ipfire.org Git - pakfire.git/commitdiff
client: Call the auth callback when we need authentication
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 10:01:44 +0000 (10:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 10:01:44 +0000 (10:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c
src/pakfire/client.h

index 96bf46c39f064090119a983578e7865e457f9d05..2c3046a6bbf59bb5208a2269b367e848f68ab5fc 100644 (file)
@@ -220,12 +220,30 @@ static int pakfire_client_xfer_auth(struct pakfire_client* self, struct pakfire_
        return 0;
 }
 
+/*
+       This function is being called when the client needs authentication and
+       does not have any credentials whatsoever.
+*/
+static int pakfire_client_auth_required(struct pakfire_client* self) {
+       // Call the authentication callback
+       if (self->auth.callback)
+               return self->auth.callback(self, self->auth.data);
+
+       ERROR(self->ctx, "Authentication required but no authentication callback set\n");
+
+       return -ENOTSUP;
+}
+
 static int pakfire_client_init(sd_event_source* event, void* data) {
        struct pakfire_client* self = data;
+       int r;
 
        DEBUG(self->ctx, "Initializing client...\n");
 
-       // XXX TODO
+       // Request authentication
+       r = pakfire_client_auth_required(self);
+       if (r < 0)
+               return r;
 
        return 0;
 }
index b7b9b11efb75be3468d9b260dcf9a28ce0b6e35c..6e0b8fd65782263cd93c3c90bd3f2fd702d97811 100644 (file)
@@ -53,7 +53,7 @@ typedef enum {
 } pakfire_client_auth_status;
 
 typedef int (*pakfire_client_auth_callback)
-       (struct pakfire_client* client, pakfire_client_auth_status status, void* data);
+       (struct pakfire_client* client, void* data);
 
 int pakfire_client_set_auth_callback(struct pakfire_client* client,
        pakfire_client_auth_callback callback, void* data);