]> git.ipfire.org Git - pakfire.git/commitdiff
client: Add some principal to the client
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 11:57:06 +0000 (11:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 11:57:06 +0000 (11:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/auth.c
src/cli/lib/pakfire.c
src/pakfire/client.c
src/pakfire/client.h
src/pakfire/daemon.c

index 56d80ba47e4812591a00ed47b661bda6381c8e67..714d149097b2d3e95be661064c49c538660cf11b 100644 (file)
 #include "command.h"
 #include "pakfire.h"
 
-static const char* args_doc = "USERNAME [OPTIONS...]";
+static const char* args_doc = "[OPTIONS...]";
 
 static const char* doc = "Authenticate a user against the build service";
 
 struct cli_local_args {
-       const char* username;
        const char* password;
 };
 
@@ -38,10 +37,7 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
 
        switch (key) {
                case ARGP_KEY_ARG:
-                       if (!args->username)
-                               args->username = arg;
-
-                       else if (!args->password)
+                       if (!args->password)
                                args->password = arg;
 
                        else
@@ -85,7 +81,7 @@ int cli_auth(void* data, int argc, char* argv[]) {
        pakfire_client_set_ready_callback(client, ready_callback, &status);
 
        // Authenticate
-       r = pakfire_client_auth_user(client, local_args.username, local_args.password);
+       r = pakfire_client_auth_user(client, local_args.password);
        if (r < 0)
                goto ERROR;
 
index 737a07cc86585eb47598b6a0f3b8febed19fdc9c..8218e0d639ce2e5468129e4c6b3a9bc164540ac6 100644 (file)
@@ -142,7 +142,6 @@ ERROR:
 }
 
 struct auth_credentials {
-       char username[NAME_MAX];
        char password[NAME_MAX];
 };
 
@@ -150,7 +149,7 @@ static int auth_callback(struct pakfire_client* client, void* data) {
        const struct auth_credentials* creds = data;
 
        // Authenticate!
-       return pakfire_client_auth_user(client, creds->username, creds->password);
+       return pakfire_client_auth_user(client, creds->password);
 }
 
 int cli_setup_client(struct pakfire_client** client, struct cli_global_args* args) {
@@ -185,18 +184,13 @@ int cli_setup_client(struct pakfire_client** client, struct cli_global_args* arg
                goto ERROR;
        }
 
-       // Copy the username
-       r = pakfire_string_set(creds.username, username);
-       if (r < 0)
-               goto ERROR;
-
        // Copy the password
        r = pakfire_string_set(creds.password, password);
        if (r < 0)
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_client_create(client, args->ctx, NULL, url);
+       r = pakfire_client_create(client, args->ctx, NULL, url, username);
        if (r < 0) {
                fprintf(stderr, "Could not setup the build service: %s\n", strerror(-r));
                goto ERROR;
index 859bb2064d8e8b98bf1b0d73596e1c0f1acd92f5..a94bd83dac18eb5b9cb7dfc28e1375f2d67d3403 100644 (file)
@@ -83,6 +83,9 @@ struct pakfire_client {
        // URL
        char url[PATH_MAX];
 
+       // Principal
+       char principal[NAME_MAX];
+
        // Ready
        struct pakfire_client_ready {
                // Callback
@@ -275,7 +278,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) {
+               struct pakfire_ctx* ctx, sd_event* loop, const char* url, const char* principal) {
        struct pakfire_client* self = NULL;
        int r;
 
@@ -303,11 +306,16 @@ int pakfire_client_create(struct pakfire_client** client,
        if (r < 0)
                goto ERROR;
 
+       // Store the principal
+       r = pakfire_string_set(self->principal, principal);
+       if (r < 0)
+               goto ERROR;
+
        // Initialize uploads
        STAILQ_INIT(&self->uploads);
 
-       DEBUG(self->ctx, "Pakfire Build Service initialized for %s\n",
-               pakfire_client_get_url(self));
+       DEBUG(self->ctx, "Pakfire Build Service initialized for %s as %s\n",
+               pakfire_client_get_url(self), self->principal);
 
        // Schedule to run the init function as soon as the event loop has started
        r = sd_event_add_defer(self->loop, NULL, pakfire_client_init, self);
@@ -494,8 +502,7 @@ static int pakfire_client_auth_response(struct pakfire_xfer* xfer,
        return 0;
 }
 
-int pakfire_client_auth_user(struct pakfire_client* self,
-               const char* username, const char* password) {
+int pakfire_client_auth_user(struct pakfire_client* self, const char* password) {
        struct pakfire_xfer* xfer = NULL;
        struct {
                char* username;
@@ -515,7 +522,7 @@ int pakfire_client_auth_user(struct pakfire_client* self,
                goto ERROR;
 
        // Escape the credentials
-       credentials.username = pakfire_xfer_escape(xfer, username);
+       credentials.username = pakfire_xfer_escape(xfer, self->principal);
        credentials.password = pakfire_xfer_escape(xfer, password);
 
        // Format the payload
index 0f66c32275f908d1cc2c880995cb2d8b64ac80c7..0b9a488b16bd79fd52dcdfdc542f17270bd82bb9 100644 (file)
@@ -29,7 +29,7 @@ struct pakfire_client;
 #include <pakfire/ctx.h>
 
 int pakfire_client_create(struct pakfire_client** client,
-       struct pakfire_ctx* ctx, sd_event* loop, const char* url);
+       struct pakfire_ctx* ctx, sd_event* loop, const char* url, const char* principal);
 
 struct pakfire_client* pakfire_client_ref(struct pakfire_client* client);
 struct pakfire_client* pakfire_client_unref(struct pakfire_client* client);
@@ -58,8 +58,7 @@ typedef int (*pakfire_client_auth_callback)
 int pakfire_client_set_auth_callback(struct pakfire_client* client,
        pakfire_client_auth_callback callback, void* data);
 
-int pakfire_client_auth_user(struct pakfire_client* client,
-       const char* username, const char* password);
+int pakfire_client_auth_user(struct pakfire_client* client, const char* password);
 
 // Builds
 
index 7620894ad7b7491872f8d67bfd8039c469ac41b7..d550ba806df5d31eb853e58bea55985a68d5a79f 100644 (file)
@@ -1108,7 +1108,7 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_client_create(&d->client, d->ctx, d->loop, d->url);
+       r = pakfire_client_create(&d->client, d->ctx, d->loop, d->url, NULL);
        if (r < 0)
                goto ERROR;