]> git.ipfire.org Git - pakfire.git/commitdiff
buildservice: Initialize a Kerberos context
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 10:18:41 +0000 (10:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 10:18:41 +0000 (10:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/buildservice.c

index 096a0d92b1049b43c9beedb5ca2d540f90f11477..d750684873496d8104cf79de3b39fc8bc2fdbaa8 100644 (file)
@@ -30,6 +30,8 @@
 #include <pakfire/private.h>
 #include <pakfire/string.h>
 
+#include <krb5/krb5.h>
+
 #define DEFAULT_KEYTAB "/etc/krb5.keytab"
 
 struct pakfire_buildservice {
@@ -42,8 +44,30 @@ struct pakfire_buildservice {
 
        // A HTTP Client
        struct pakfire_downloader* httpclient;
+
+       // Kerberos Context
+       krb5_context krb5_ctx;
 };
 
+static int pakfire_buildservice_setup_auth(struct pakfire_buildservice* service) {
+       const char* error = NULL;
+       int r;
+
+       // Setup a Kerberos context
+       r = krb5_init_context(&service->krb5_ctx);
+       if (r) {
+               error = krb5_get_error_message(service->krb5_ctx, r);
+
+               CTX_ERROR(service->ctx, "Could not initialize Kerberos: %s\n", error);
+               krb5_free_error_message(service->krb5_ctx, error);
+
+               goto ERROR;
+       }
+
+ERROR:
+       return r;
+}
+
 static int pakfire_buildservice_setup(struct pakfire_buildservice* service) {
        struct pakfire_config* config = NULL;
        const char* url = NULL;
@@ -83,6 +107,11 @@ static int pakfire_buildservice_setup(struct pakfire_buildservice* service) {
        if (r)
                goto ERROR;
 
+       // Setup authentication
+       r = pakfire_buildservice_setup_auth(service);
+       if (r)
+               goto ERROR;
+
 ERROR:
        if (config)
                pakfire_config_unref(config);
@@ -91,6 +120,8 @@ ERROR:
 }
 
 static void pakfire_buildservice_free(struct pakfire_buildservice* service) {
+       if (service->krb5_ctx)
+               krb5_free_context(service->krb5_ctx);
        if (service->httpclient)
                pakfire_downloader_unref(service->httpclient);
        if (service->ctx)