From: Michael Tremer Date: Wed, 25 Jun 2025 11:57:06 +0000 (+0000) Subject: client: Add some principal to the client X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c90464d61ec96acb97abd8ab51804c81a63cf57c;p=pakfire.git client: Add some principal to the client Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/auth.c b/src/cli/lib/auth.c index 56d80ba4..714d1490 100644 --- a/src/cli/lib/auth.c +++ b/src/cli/lib/auth.c @@ -24,12 +24,11 @@ #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; diff --git a/src/cli/lib/pakfire.c b/src/cli/lib/pakfire.c index 737a07cc..8218e0d6 100644 --- a/src/cli/lib/pakfire.c +++ b/src/cli/lib/pakfire.c @@ -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; diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 859bb206..a94bd83d 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -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 diff --git a/src/pakfire/client.h b/src/pakfire/client.h index 0f66c322..0b9a488b 100644 --- a/src/pakfire/client.h +++ b/src/pakfire/client.h @@ -29,7 +29,7 @@ struct pakfire_client; #include 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 diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index 7620894a..d550ba80 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -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;