]> git.ipfire.org Git - pakfire.git/commitdiff
cli: Read credentials from the configuration file (for now)
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 10:25:23 +0000 (10:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 10:25:23 +0000 (10:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/pakfire.c

index d8e8b0efd44ffb3dd2993171abee9be6b0ed5374..15db3c1d4091fe44741af6cc17f5460ce30c109f 100644 (file)
@@ -141,8 +141,22 @@ ERROR:
 }
 
 static int auth_callback(struct pakfire_client* client, void* data) {
-       // XXX DEBUG
-       return pakfire_client_auth_user(client, "ms", "XXX");
+       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);
+
+       // Fail if we have no credentials
+       if (!username || !password) {
+               fprintf(stderr, "Client credentials are missing\n");
+               return -EINVAL;
+       }
+
+       // Authenticate!
+       return pakfire_client_auth_user(client, username, password);
 }
 
 int cli_setup_client(struct pakfire_client** client, struct cli_global_args* args) {
@@ -166,7 +180,7 @@ int cli_setup_client(struct pakfire_client** client, struct cli_global_args* arg
        }
 
        // Set authentication callback
-       pakfire_client_set_auth_callback(*client, auth_callback, NULL);
+       pakfire_client_set_auth_callback(*client, auth_callback, config);
 
 ERROR:
        if (config)