about summary refs log tree commit diff stats
path: root/src/config/account.c
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-12-11 15:51:01 +0100
committerWilliam Wennerström <william@wstrm.dev>2020-12-11 15:51:01 +0100
commit32cfea4bd28ff70bae1c2e80c603877b5b35515c (patch)
treecd1284eaf4c4905f1ad5293863badf1f3806a35b /src/config/account.c
parent46e938b638114dd979656badecb99acbdf65cd4a (diff)
downloadprofani-tty-32cfea4bd28ff70bae1c2e80c603877b5b35515c.tar.gz
Refactor call_external
Diffstat (limited to 'src/config/account.c')
-rw-r--r--src/config/account.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/config/account.c b/src/config/account.c
index c0f508b4..7e5297af 100644
--- a/src/config/account.c
+++ b/src/config/account.c
@@ -200,27 +200,35 @@ account_eval_password(ProfAccount* account)
     assert(account != NULL);
     assert(account->eval_password != NULL);
 
-    gchar** output = NULL;
-    gchar** error = NULL;
+    gchar* std_out = NULL;
+    gchar* std_err = NULL;
 
     gchar* argv[] = { "sh", "-c", account->eval_password, NULL };
-    if (!call_external(argv, &output, &error)) {
+    if (!call_external(argv, &std_out, &std_err)) {
+        log_error("Password command failed with: %s", std_err);
+        g_free(std_out);
+        g_free(std_err);
         return FALSE;
     }
 
-    if (!output || !output[0]) {
-        log_error("Failed to read eval_password output");
-        g_strfreev(output);
-        output = NULL;
+    if (!std_out || !std_out[0]) {
+        log_error("Password command returned empty output.");
+        g_free(std_out);
+        g_free(std_err);
         return FALSE;
     }
 
-    account->password = strdup(output[0]);
-    g_strfreev(output);
-    output = NULL;
+    // Remove leading and trailing whitespace from command output.
+    gchar* password = g_strdup(std_out);
+    g_strstrip(password);
+
+    account->password = password;
+    g_free(std_out);
+    g_free(std_err);
 
     if (!account->password) {
-        log_error("Failed to allocate enough memory to read eval_password output");
+        log_error("Failed to allocate enough memory to read password command "
+                  "output");
         return FALSE;
     }