#include <pakfire/config.h>
#include <pakfire/pakfire.h>
#include <pakfire/repo.h>
+#include <pakfire/string.h>
#include "config.h"
#include "pakfire.h"
return r;
}
-static int auth_callback(struct pakfire_client* client, void* data) {
- struct pakfire_config* config = data;
- const char* username = NULL;
- const char* password = NULL;
-
- // Fetch the credentials from the configuration
- username = pakfire_config_get(config, "client", "username", NULL);
- password = pakfire_config_get(config, "client", "password", NULL);
+struct auth_credentials {
+ char username[NAME_MAX];
+ char password[NAME_MAX];
+};
- // Fail if we have no credentials
- if (!username || !password) {
- fprintf(stderr, "Client credentials are missing\n");
- return -EINVAL;
- }
+static int auth_callback(struct pakfire_client* client, void* data) {
+ const struct auth_credentials* creds = data;
// Authenticate!
- return pakfire_client_auth_user(client, username, password);
+ return pakfire_client_auth_user(client, creds->username, creds->password);
}
int cli_setup_client(struct pakfire_client** client, struct cli_global_args* args) {
+ static struct auth_credentials creds = {};
struct pakfire_config* config = NULL;
+ const char* username = NULL;
+ const char* password = NULL;
const char* url = NULL;
int r;
// Fetch the URL
url = pakfire_config_get(config, "client", "url", "https://pakfire.ipfire.org/");
+ // Fetch the credentials from the configuration
+ username = pakfire_config_get(config, "client", "username", NULL);
+ password = pakfire_config_get(config, "client", "password", NULL);
+
+ // Fail if we have no credentials
+ if (!username || !password) {
+ fprintf(stderr, "Client credentials are missing\n");
+ r = -EINVAL;
+ 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);
if (r < 0) {
}
// Set authentication callback
- pakfire_client_set_auth_callback(*client, auth_callback, config);
+ pakfire_client_set_auth_callback(*client, auth_callback, &creds);
ERROR:
if (config)