mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Use popen for eval_password (reintroduce old behavior)
Old commit that implemented the old behavior:
bc9e6b79cd
This commit is contained in:
parent
32cfea4bd2
commit
695a1d3c8c
@ -36,6 +36,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@ -200,35 +201,49 @@ account_eval_password(ProfAccount* account)
|
||||
assert(account != NULL);
|
||||
assert(account->eval_password != NULL);
|
||||
|
||||
gchar* std_out = NULL;
|
||||
gchar* std_err = NULL;
|
||||
errno = 0;
|
||||
|
||||
gchar* argv[] = { "sh", "-c", account->eval_password, NULL };
|
||||
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);
|
||||
FILE* stream = popen(account->eval_password, "r");
|
||||
if (stream == NULL) {
|
||||
const char* errmsg = strerror(errno);
|
||||
if (errmsg) {
|
||||
log_error("Could not execute `eval_password` command (%s).",
|
||||
errmsg);
|
||||
} else {
|
||||
log_error("Failed to allocate memory for `eval_password` command.");
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!std_out || !std_out[0]) {
|
||||
log_error("Password command returned empty output.");
|
||||
g_free(std_out);
|
||||
g_free(std_err);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
account->password = g_malloc(READ_BUF_SIZE);
|
||||
if (!account->password) {
|
||||
log_error("Failed to allocate enough memory to read password command "
|
||||
"output");
|
||||
log_error("Failed to allocate enough memory to read `eval_password` "
|
||||
"output.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
account->password = fgets(account->password, READ_BUF_SIZE, stream);
|
||||
if (!account->password) {
|
||||
log_error("Failed to read password from stream.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int exit_status = pclose(stream);
|
||||
if (exit_status > 0) {
|
||||
log_error("Command for `eval_password` returned error status (%s).",
|
||||
exit_status);
|
||||
return FALSE;
|
||||
} else if (exit_status < 0) {
|
||||
log_error("Failed to close stream for `eval_password` command output "
|
||||
"(%s).",
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
// Remove leading and trailing whitespace from output.
|
||||
g_strstrip(account->password);
|
||||
if (!account->password) {
|
||||
log_error("Empty password returned by `eval_password` command.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user