#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;
};
switch (key) {
case ARGP_KEY_ARG:
- if (!args->username)
- args->username = arg;
-
- else if (!args->password)
+ if (!args->password)
args->password = arg;
else
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;
}
struct auth_credentials {
- char username[NAME_MAX];
char password[NAME_MAX];
};
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) {
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;
// URL
char url[PATH_MAX];
+ // Principal
+ char principal[NAME_MAX];
+
// Ready
struct pakfire_client_ready {
// Callback
}
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;
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);
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;
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
#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);
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
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;