Server passwords from the environment in irssi
Posted on
irssi is a well known IRC client. It's been around since the early 2000.
It's been my go-to IRC client since then. Anyhow, this is not really a tutorial for it or anything.
One thing that you may have encountered is about the server password: unless you authenticate manually to a network each time, you can store your password in the ~/.irssi/config file. In plain-text. :-/
This - unreviewed - patch allows to populate the password from the environment. Edit your ~/.irssi/config and for each server password field you can specify $ENV: followed by the environment variable from which populate the password. Example:
...
servers = (
...
{
address = "irc.azzurra.org";
chatnet = "Azzurra";
port = "6697";
use_tls = "yes";
tls_verify = "yes";
password = "$ENV:AZZURRA_PWD";
}
...
);
...
Then just set your environment variable, either explicitely or from a text file, and you're done. Example: export AZZURRA_PWD="my_pwd".
In case you use it feel free to shoot me an email and let me know what you think. Here:
diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c
index 8747eea3..31700cbc 100644
--- a/src/core/servers-setup.c
+++ b/src/core/servers-setup.c
@@ -29,6 +29,8 @@
#include <irssi/src/core/servers.h>
#include <irssi/src/core/servers-setup.h>
+#define IRSSI_ENV_PWD_PREFIX "$ENV:"
+
GSList *setupservers;
static char *old_source_host;
@@ -462,6 +464,10 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
int port;
char *value = NULL;
+ GString *error;
+ char *env_var_pwd = NULL;
+ const char *env_value_pwd;
+
g_return_val_if_fail(node != NULL, NULL);
server = config_node_get_str(node, "address", NULL);
@@ -513,7 +519,31 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
AF_INET6 :
(g_ascii_strcasecmp(family, "inet") == 0 ? AF_INET : 0);
rec->address = g_strdup(server);
- rec->password = g_strdup(config_node_get_str(node, "password", NULL));
+
+ value = config_node_get_str(node, "password", NULL);
+ if (value && g_str_has_prefix(value, IRSSI_ENV_PWD_PREFIX)) {
+ env_var_pwd = value + sizeof(IRSSI_ENV_PWD_PREFIX) - 1;
+ if (env_var_pwd[0] != '\0' && g_str_is_ascii(env_var_pwd) && (env_value_pwd = g_getenv(env_var_pwd)) != NULL) {
+ rec->password = g_strdup(env_value_pwd);
+ } else {
+ rec->password = NULL;
+ error = g_string_new(NULL);
+ g_string_printf(error, "No suitable value for environment var=%s", env_var_pwd);
+ signal_emit("settings errors", 1, error->str);
+ g_string_free(error, TRUE);
+ }
+ } else {
+ rec->password = g_strdup(value);
+ }
rec->use_tls = config_node_get_bool(node, "use_tls", FALSE) || config_node_get_bool(node, "use_ssl", FALSE);
rec->tls_verify = config_node_find(node, "tls_verify") != NULL ?