From f468008b25c7218a03cc0b327082d4d69d5481ef Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Tue, 25 Jul 2017 19:39:15 +0100
Subject: [PATCH 01/76] Make autotools detect Capsicum.
Signed-off-by: Edward Tomasz Napierala
---
configure.ac | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/configure.ac b/configure.ac
index c7c8edef..f0c4cc5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,15 @@ AC_ARG_ENABLE(gregex,
fi,
want_gregex=yes)
+AC_ARG_WITH(capsicum,
+[ --with-capsicum Build with Capsicum support],
+ if test x$withval = xno; then
+ want_capsicum=no
+ else
+ want_capsicum=yes
+ fi,
+ want_capsicum=yes)
+
dnl **
dnl ** just some generic stuff...
dnl **
@@ -499,6 +508,18 @@ if test "$want_perl" != "no"; then
fi
fi
+dnl **
+dnl ** check for capsicum
+dnl **
+
+if test "x$want_capsicum" = "xyes"; then
+ AC_CHECK_LIB(c, cap_enter, [
+ AC_DEFINE(HAVE_CAPSICUM,, Build with Capsicum support)
+ ], [
+ want_capsicum="no, cap_enter not found"
+ ])
+fi
+
dnl ** check what we want to build
AM_CONDITIONAL(BUILD_TEXTUI, test "$want_textui" = "yes")
AM_CONDITIONAL(BUILD_IRSSIBOT, test "$want_irssibot" = "yes")
@@ -713,6 +734,7 @@ echo
echo "Building with 64bit DCC support .. : $offt_64bit"
echo "Building with true color support.. : $want_truecolor"
echo "Building with GRegex ............. : $want_gregex"
+echo "Building with Capsicum ........... : $want_capsicum"
echo
echo "If there are any problems, read the INSTALL file."
From 56c94570b420dea28b253af5f2c91184423acee1 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Tue, 25 Jul 2017 20:15:14 +0100
Subject: [PATCH 02/76] Implement /cap_enter.
Signed-off-by: Edward Tomasz Napierala
---
configure.ac | 3 ++-
src/core/Makefile.am | 5 +++++
src/core/capsicum.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
src/core/capsicum.h | 7 +++++++
src/core/core.c | 3 +++
5 files changed, 63 insertions(+), 1 deletion(-)
create mode 100644 src/core/capsicum.c
create mode 100644 src/core/capsicum.h
diff --git a/configure.ac b/configure.ac
index f0c4cc5d..773f9eea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -167,7 +167,7 @@ AC_ARG_ENABLE(gregex,
want_gregex=yes)
AC_ARG_WITH(capsicum,
-[ --with-capsicum Build with Capsicum support],
+[ --with-capsicum Build with Capsicum support],
if test x$withval = xno; then
want_capsicum=no
else
@@ -526,6 +526,7 @@ AM_CONDITIONAL(BUILD_IRSSIBOT, test "$want_irssibot" = "yes")
AM_CONDITIONAL(BUILD_IRSSIFUZZER, test "$want_irssifuzzer" = "yes")
AM_CONDITIONAL(BUILD_IRSSIPROXY, test "$want_irssiproxy" = "yes")
AM_CONDITIONAL(HAVE_PERL, test "$want_perl" != "no")
+AM_CONDITIONAL(HAVE_CAPSICUM, test "x$want_capsicum" = "xyes")
AM_CONDITIONAL(USE_GREGEX, test "x$want_gregex" = "xyes")
# move LIBS to PROG_LIBS so they're not tried to be used when linking eg. perl libraries
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 91daba3f..f3bc1674 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -56,6 +56,11 @@ libcore_a_SOURCES = \
tls.c \
write-buffer.c
+if HAVE_CAPSICUM
+libcore_a_SOURCES += \
+ capsicum.c
+endif
+
structure_headers = \
channel-rec.h \
channel-setup-rec.h \
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
new file mode 100644
index 00000000..702b895a
--- /dev/null
+++ b/src/core/capsicum.c
@@ -0,0 +1,46 @@
+/*
+ capsicum.c : Capsicum sandboxing support
+
+ Copyright (C) 2017 Edward Tomasz Napierala
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "module.h"
+#include "signals.h"
+#include "commands.h"
+
+#include
+#include
+
+static void cmd_cap_enter(void)
+{
+ int error;
+
+ error = cap_enter();
+ if (error != 0)
+ g_error("cap_enter(2) failed: %s", strerror(errno));
+}
+
+void capsicum_init(void)
+{
+
+ command_bind("cap_enter", NULL, (SIGNAL_FUNC) cmd_cap_enter);
+}
+
+void capsicum_deinit(void)
+{
+ command_unbind("cap_enter", (SIGNAL_FUNC) cmd_cap_enter);
+}
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
new file mode 100644
index 00000000..75c70080
--- /dev/null
+++ b/src/core/capsicum.h
@@ -0,0 +1,7 @@
+#ifndef __CAPSICUM_H
+#define __CAPSICUM_H
+
+void capsicum_init(void);
+void capsicum_deinit(void);
+
+#endif
diff --git a/src/core/core.c b/src/core/core.c
index bf7cdd6b..72631f91 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -29,6 +29,7 @@
#include "signals.h"
#include "settings.h"
#include "session.h"
+#include "capsicum.h"
#include "chat-protocols.h"
#include "servers.h"
@@ -235,6 +236,7 @@ void core_init(void)
commands_init();
nickmatch_cache_init();
session_init();
+ capsicum_init();
chat_protocols_init();
chatnets_init();
@@ -292,6 +294,7 @@ void core_deinit(void)
chatnets_deinit();
chat_protocols_deinit();
+ capsicum_deinit();
session_deinit();
nickmatch_cache_deinit();
commands_deinit();
From d5d45c29b8e00c304a6b6656983cafee84fe6bc8 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 26 Jul 2017 01:00:25 +0100
Subject: [PATCH 03/76] Add capability mode error/success messages.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 24 +++++++++++-
src/fe-common/core/Makefile.am | 5 +++
src/fe-common/core/fe-capsicum.c | 60 +++++++++++++++++++++++++++++
src/fe-common/core/fe-capsicum.h | 7 ++++
src/fe-common/core/fe-common-core.c | 3 ++
src/fe-common/core/module-formats.c | 3 ++
src/fe-common/core/module-formats.h | 3 ++
7 files changed, 103 insertions(+), 2 deletions(-)
create mode 100644 src/fe-common/core/fe-capsicum.c
create mode 100644 src/fe-common/core/fe-capsicum.h
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 702b895a..eb30fef3 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -30,17 +30,37 @@ static void cmd_cap_enter(void)
int error;
error = cap_enter();
- if (error != 0)
- g_error("cap_enter(2) failed: %s", strerror(errno));
+ if (error != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ } else {
+ signal_emit("capability mode enabled", 0);
+ }
+}
+
+static void cmd_cap_getmode(void)
+{
+ u_int mode;
+ int error;
+
+ error = cap_getmode(&mode);
+ if (error != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ } else if (mode == 0) {
+ signal_emit("capability mode disabled", 0);
+ } else {
+ signal_emit("capability mode enabled", 0);
+ }
}
void capsicum_init(void)
{
command_bind("cap_enter", NULL, (SIGNAL_FUNC) cmd_cap_enter);
+ command_bind("cap_getmode", NULL, (SIGNAL_FUNC) cmd_cap_getmode);
}
void capsicum_deinit(void)
{
command_unbind("cap_enter", (SIGNAL_FUNC) cmd_cap_enter);
+ command_unbind("cap_getmode", (SIGNAL_FUNC) cmd_cap_getmode);
}
diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am
index 6efff411..08e41520 100644
--- a/src/fe-common/core/Makefile.am
+++ b/src/fe-common/core/Makefile.am
@@ -38,6 +38,11 @@ libfe_common_core_a_SOURCES = \
windows-layout.c \
fe-windows.c
+if HAVE_CAPSICUM
+libfe_common_core_a_SOURCES += \
+ fe-capsicum.c
+endif
+
pkginc_fe_common_coredir=$(pkgincludedir)/src/fe-common/core
pkginc_fe_common_core_HEADERS = \
command-history.h \
diff --git a/src/fe-common/core/fe-capsicum.c b/src/fe-common/core/fe-capsicum.c
new file mode 100644
index 00000000..5816b223
--- /dev/null
+++ b/src/fe-common/core/fe-capsicum.c
@@ -0,0 +1,60 @@
+/*
+ fe-capsicum.c : irssi
+
+ Copyright (C) 2017 Edward Tomasz Napierala
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "module.h"
+#include "module-formats.h"
+#include "signals.h"
+#include "printtext.h"
+
+#include "levels.h"
+#include "servers.h"
+
+static void capability_mode_enabled(void)
+{
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CAPSICUM_ENABLED);
+}
+
+static void capability_mode_disabled(void)
+{
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CAPSICUM_DISABLED);
+}
+
+static void capability_mode_failed(gchar *msg)
+{
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_CAPSICUM_FAILED, msg);
+}
+
+void fe_capsicum_init(void)
+{
+
+ signal_add("capability mode enabled", (SIGNAL_FUNC) capability_mode_enabled);
+ signal_add("capability mode disabled", (SIGNAL_FUNC) capability_mode_disabled);
+ signal_add("capability mode failed", (SIGNAL_FUNC) capability_mode_failed);
+}
+
+void fe_capsicum_deinit(void)
+{
+ signal_remove("capability mode enabled", (SIGNAL_FUNC) capability_mode_enabled);
+ signal_remove("capability mode disabled", (SIGNAL_FUNC) capability_mode_disabled);
+ signal_remove("capability mode failed", (SIGNAL_FUNC) capability_mode_failed);
+}
diff --git a/src/fe-common/core/fe-capsicum.h b/src/fe-common/core/fe-capsicum.h
new file mode 100644
index 00000000..a7cb743b
--- /dev/null
+++ b/src/fe-common/core/fe-capsicum.h
@@ -0,0 +1,7 @@
+#ifndef __FE_CAPSICUM_H
+#define __FE_CAPSICUM_H
+
+void fe_capsicum_init(void);
+void fe_capsicum_deinit(void);
+
+#endif
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c
index 512fc84c..a0388827 100644
--- a/src/fe-common/core/fe-common-core.c
+++ b/src/fe-common/core/fe-common-core.c
@@ -32,6 +32,7 @@
#include "special-vars.h"
#include "fe-core-commands.h"
#include "fe-queries.h"
+#include "fe-capsicum.h"
#include "hilight-text.h"
#include "command-history.h"
#include "completion.h"
@@ -179,6 +180,7 @@ void fe_common_core_init(void)
fe_server_init();
fe_settings_init();
fe_tls_init();
+ fe_capsicum_init();
windows_init();
window_activity_init();
window_commands_init();
@@ -221,6 +223,7 @@ void fe_common_core_deinit(void)
fe_server_deinit();
fe_settings_deinit();
fe_tls_deinit();
+ fe_capsicum_deinit();
windows_deinit();
window_activity_deinit();
window_commands_deinit();
diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c
index da9705be..eb0ddb61 100644
--- a/src/fe-common/core/module-formats.c
+++ b/src/fe-common/core/module-formats.c
@@ -290,6 +290,9 @@ FORMAT_REC fecommon_core_formats[] = {
{ "completion_header", "%#Key Value Auto", 0 },
{ "completion_line", "%#$[10]0 $[!40]1 $2", 3, { 0, 0, 0 } },
{ "completion_footer", "", 0 },
+ { "capsicum_enabled", "Capability mode enabled", 0 },
+ { "capsicum_disabled", "Capability mode not enabled", 0 },
+ { "capsicum_failed", "Capability mode failed: $0", 1, { 0 } },
/* ---- */
{ NULL, "TLS", 0 },
diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h
index a9ed28c5..4e2f72d9 100644
--- a/src/fe-common/core/module-formats.h
+++ b/src/fe-common/core/module-formats.h
@@ -255,6 +255,9 @@ enum {
TXT_COMPLETION_HEADER,
TXT_COMPLETION_LINE,
TXT_COMPLETION_FOOTER,
+ TXT_CAPSICUM_ENABLED,
+ TXT_CAPSICUM_DISABLED,
+ TXT_CAPSICUM_FAILED,
TLS_FILL_15,
From 3200c381dbcb02e99c7667bd955c90ee859d15a0 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 26 Jul 2017 02:11:46 +0100
Subject: [PATCH 04/76] Rename to "/capability enter" and "/capability status".
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index eb30fef3..69a379e2 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -25,7 +25,12 @@
#include
#include
-static void cmd_cap_enter(void)
+static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
+{
+ command_runsub("capsicum", data, server, item);
+}
+
+static void cmd_capsicum_enter(void)
{
int error;
@@ -37,7 +42,7 @@ static void cmd_cap_enter(void)
}
}
-static void cmd_cap_getmode(void)
+static void cmd_capsicum_status(void)
{
u_int mode;
int error;
@@ -55,12 +60,14 @@ static void cmd_cap_getmode(void)
void capsicum_init(void)
{
- command_bind("cap_enter", NULL, (SIGNAL_FUNC) cmd_cap_enter);
- command_bind("cap_getmode", NULL, (SIGNAL_FUNC) cmd_cap_getmode);
+ command_bind("capsicum", NULL, (SIGNAL_FUNC) cmd_capsicum);
+ command_bind("capsicum enter", NULL, (SIGNAL_FUNC) cmd_capsicum_enter);
+ command_bind("capsicum status", NULL, (SIGNAL_FUNC) cmd_capsicum_status);
}
void capsicum_deinit(void)
{
- command_unbind("cap_enter", (SIGNAL_FUNC) cmd_cap_enter);
- command_unbind("cap_getmode", (SIGNAL_FUNC) cmd_cap_getmode);
+ command_unbind("capsicum", (SIGNAL_FUNC) cmd_capsicum);
+ command_unbind("capsicum enter", (SIGNAL_FUNC) cmd_capsicum_enter);
+ command_unbind("capsicum status", (SIGNAL_FUNC) cmd_capsicum_status);
}
From cec68557aa436b4f16505d2095af02f83d154eda Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Thu, 27 Jul 2017 14:20:47 +0100
Subject: [PATCH 05/76] /connect works - although only with IP addresses.
---
configure.ac | 7 ++-
src/core/capsicum.c | 126 ++++++++++++++++++++++++++++++++++++++++++++
src/core/capsicum.h | 3 ++
src/core/network.c | 33 ++++++++++--
src/core/network.h | 2 +
5 files changed, 165 insertions(+), 6 deletions(-)
diff --git a/configure.ac b/configure.ac
index 773f9eea..9c026c5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -514,7 +514,12 @@ dnl **
if test "x$want_capsicum" = "xyes"; then
AC_CHECK_LIB(c, cap_enter, [
- AC_DEFINE(HAVE_CAPSICUM,, Build with Capsicum support)
+ AC_CHECK_LIB(nv, nvlist_create, [
+ AC_DEFINE(HAVE_CAPSICUM,, Build with Capsicum support)
+ LIBS="$LIBS -lnv"
+ ], [
+ want_capsicum="no, nvlist_create not found"
+ ])
], [
want_capsicum="no, cap_enter not found"
])
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 69a379e2..19ca858e 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -19,21 +19,147 @@
*/
#include "module.h"
+#include "network.h"
#include "signals.h"
#include "commands.h"
+#include
#include
+#include
+#include
+#include
#include
+static int symbiontfds[2];
+
+gboolean capsicum_enabled(void)
+{
+ u_int mode;
+ int error;
+
+ error = cap_getmode(&mode);
+ if (error != 0)
+ return FALSE;
+
+ if (mode == 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+{
+ nvlist_t *nvl;
+ int error, saved_errno, sock;
+
+ /* Send request to the symbiont. */
+ nvl = nvlist_create(0);
+ nvlist_add_binary(nvl, "ip", ip, sizeof(*ip));
+ nvlist_add_number(nvl, "port", port);
+ if (my_ip != NULL) {
+ /* nvlist_add_binary(3) can't handle NULL values. */
+ nvlist_add_binary(nvl, "my_ip", my_ip, sizeof(*my_ip));
+ }
+ error = nvlist_send(symbiontfds[1], nvl);
+ nvlist_destroy(nvl);
+ if (error != 0) {
+ g_warning("nvlist_send: %s", strerror(errno));
+ return -1;
+ }
+
+ /* Receive response. */
+ nvl = nvlist_recv(symbiontfds[1], 0);
+ if (nvl == NULL) {
+ g_warning("nvlist_recv: %s", strerror(errno));
+ return -1;
+ }
+ if (nvlist_exists_descriptor(nvl, "sock")) {
+ sock = nvlist_take_descriptor(nvl, "sock");
+ } else {
+ sock = -1;
+ }
+ saved_errno = nvlist_get_number(nvl, "errno");
+ nvlist_destroy(nvl);
+ errno = saved_errno;
+
+ return sock;
+}
+
static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
{
command_runsub("capsicum", data, server, item);
}
+static int start_symbiont(void)
+{
+ pid_t pid;
+ nvlist_t *nvl;
+ IPADDR *ip, *my_ip;
+ int childfd, error, port, saved_errno, sock;
+
+ error = socketpair(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, symbiontfds);
+ if (error != 0) {
+ g_warning("socketpair: %s", strerror(errno));
+ return 1;
+ }
+
+ pid = pdfork(&childfd, PD_CLOEXEC);
+ if (pid < 0) {
+ g_warning("pdfork: %s", strerror(errno));
+ return 1;
+ }
+
+ if (pid > 0) {
+ close(symbiontfds[0]);
+ return 0;
+ }
+
+ /* We're the child, running outside the Capsicum sandbox. */
+ setproctitle("capsicum symbiont");
+ close(symbiontfds[1]);
+ close(0);
+ close(1);
+ close(2);
+ for (;;) {
+ /* Receive parameters from the main irssi process. */
+ nvl = nvlist_recv(symbiontfds[0], 0);
+ if (nvl == NULL)
+ exit(1);
+ ip = nvlist_get_binary(nvl, "ip", NULL);
+ port = (int)nvlist_get_number(nvl, "port");
+ if (nvlist_exists(nvl, "my_ip"))
+ my_ip = nvlist_get_binary(nvl, "my_ip", NULL);
+ else
+ my_ip = NULL;
+
+ /* Connect. */
+ sock = net_connect_ip_handle(ip, port, my_ip);
+ saved_errno = errno;
+
+ /* Send back the socket fd. */
+ nvlist_destroy(nvl);
+ nvl = nvlist_create(0);
+
+ if (sock != -1)
+ nvlist_move_descriptor(nvl, "sock", sock);
+ nvlist_add_number(nvl, "errno", saved_errno);
+ error = nvlist_send(symbiontfds[0], nvl);
+ if (error != 0)
+ exit(1);
+ nvlist_destroy(nvl);
+ }
+}
+
static void cmd_capsicum_enter(void)
{
int error;
+ error = start_symbiont();
+ if (error != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
error = cap_enter();
if (error != 0) {
signal_emit("capability mode failed", 1, strerror(errno));
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
index 75c70080..f8cec28e 100644
--- a/src/core/capsicum.h
+++ b/src/core/capsicum.h
@@ -1,6 +1,9 @@
#ifndef __CAPSICUM_H
#define __CAPSICUM_H
+gboolean capsicum_enabled(void);
+int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
+
void capsicum_init(void);
void capsicum_deinit(void);
diff --git a/src/core/network.c b/src/core/network.c
index 3e1b7c70..b182d19f 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -20,6 +20,9 @@
#include "module.h"
#include "network.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include
@@ -144,8 +147,7 @@ GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip)
return net_connect_ip(ip, port, my_ip);
}
-/* Connect to socket with ip address */
-GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+int net_connect_ip_handle(IPADDR *ip, int port, IPADDR *my_ip)
{
union sockaddr_union so;
int handle, ret, opt = 1;
@@ -161,7 +163,7 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
handle = socket(ip->family, SOCK_STREAM, 0);
if (handle == -1)
- return NULL;
+ return -1;
/* set socket options */
fcntl(handle, F_SETFL, O_NONBLOCK);
@@ -176,7 +178,7 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
close(handle);
errno = old_errno;
- return NULL;
+ return -1;
}
}
@@ -190,9 +192,30 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
int old_errno = errno;
close(handle);
errno = old_errno;
- return NULL;
+ return -1;
}
+ return handle;
+}
+
+
+/* Connect to socket with ip address */
+GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+{
+ int handle = -1;
+
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ handle = capsicum_net_connect_ip(ip, port, my_ip);
+ else
+ handle = net_connect_ip_handle(ip, port, my_ip);
+#else
+ handle = net_connect_ip_handle(ip, port, my_ip);
+#endif
+
+ if (handle == -1)
+ return (NULL);
+
return g_io_channel_new(handle);
}
diff --git a/src/core/network.h b/src/core/network.h
index 8757f78c..5ccacc0d 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -36,6 +36,8 @@ GIOChannel *g_io_channel_new(int handle);
/* returns 1 if IPADDRs are the same */
int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
+int net_connect_ip_handle(IPADDR *ip, int port, IPADDR *my_ip);
+
/* Connect to socket */
GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip) G_GNUC_DEPRECATED;
/* Connect to socket with ip address and SSL*/
From 925240155e5c0c20569bcb5fafe4d3047055768a Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Thu, 27 Jul 2017 14:56:35 +0100
Subject: [PATCH 06/76] Config file support for "capsicum" parameter.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 19ca858e..7674ca4d 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -19,9 +19,10 @@
*/
#include "module.h"
-#include "network.h"
-#include "signals.h"
#include "commands.h"
+#include "network.h"
+#include "settings.h"
+#include "signals.h"
#include
#include
@@ -183,8 +184,17 @@ static void cmd_capsicum_status(void)
}
}
+void sig_init_finished(void)
+{
+ if (settings_get_bool("capsicum"))
+ cmd_capsicum_enter();
+}
+
void capsicum_init(void)
{
+ settings_add_bool("misc", "capsicum", FALSE);
+
+ signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
command_bind("capsicum", NULL, (SIGNAL_FUNC) cmd_capsicum);
command_bind("capsicum enter", NULL, (SIGNAL_FUNC) cmd_capsicum_enter);
@@ -193,6 +203,8 @@ void capsicum_init(void)
void capsicum_deinit(void)
{
+ signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+
command_unbind("capsicum", (SIGNAL_FUNC) cmd_capsicum);
command_unbind("capsicum enter", (SIGNAL_FUNC) cmd_capsicum_enter);
command_unbind("capsicum status", (SIGNAL_FUNC) cmd_capsicum_status);
From f4546be7ecb8a0801fb0d30415586c15d721494a Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Thu, 27 Jul 2017 15:35:14 +0100
Subject: [PATCH 07/76] Reorder functions.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 7674ca4d..a0375077 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -86,11 +86,6 @@ int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
return sock;
}
-static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
-{
- command_runsub("capsicum", data, server, item);
-}
-
static int start_symbiont(void)
{
pid_t pid;
@@ -151,6 +146,11 @@ static int start_symbiont(void)
}
}
+static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
+{
+ command_runsub("capsicum", data, server, item);
+}
+
static void cmd_capsicum_enter(void)
{
int error;
From 509eca76f0755e94b5981f464f9f9a882499180a Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Fri, 28 Jul 2017 02:21:40 +0100
Subject: [PATCH 08/76] Make DNS work in capability mode.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 173 ++++++++++++++++++++++++++++++++++----------
src/core/capsicum.h | 1 +
src/core/network.c | 5 ++
3 files changed, 142 insertions(+), 37 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index a0375077..99f7ff0f 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -31,6 +31,9 @@
#include
#include
+#define OPCODE_CONNECT 1
+#define OPCODE_GETHOSTBYNAME 2
+
static int symbiontfds[2];
gboolean capsicum_enabled(void)
@@ -55,6 +58,7 @@ int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
/* Send request to the symbiont. */
nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "opcode", OPCODE_CONNECT);
nvlist_add_binary(nvl, "ip", ip, sizeof(*ip));
nvlist_add_number(nvl, "port", port);
if (my_ip != NULL) {
@@ -86,12 +90,139 @@ int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
return sock;
}
+int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
+{
+ nvlist_t *nvl;
+ IPADDR *received_ip4, *received_ip6;
+ int error, ret, saved_errno;
+
+ /* Send request to the symbiont. */
+ nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "opcode", OPCODE_GETHOSTBYNAME);
+ nvlist_add_string(nvl, "addr", addr);
+ error = nvlist_send(symbiontfds[1], nvl);
+ nvlist_destroy(nvl);
+ if (error != 0) {
+ g_warning("nvlist_send: %s", strerror(errno));
+ return -1;
+ }
+
+ /* Receive response. */
+ nvl = nvlist_recv(symbiontfds[1], 0);
+ if (nvl == NULL) {
+ g_warning("nvlist_recv: %s", strerror(errno));
+ return -1;
+ }
+
+ received_ip4 = nvlist_get_binary(nvl, "ip4", NULL);
+ received_ip6 = nvlist_get_binary(nvl, "ip6", NULL);
+ memcpy(ip4, received_ip4, sizeof(*ip4));
+ memcpy(ip6, received_ip6, sizeof(*ip6));
+
+ ret = nvlist_get_number(nvl, "ret");
+ saved_errno = nvlist_get_number(nvl, "errno");
+ nvlist_destroy(nvl);
+ errno = saved_errno;
+
+ return ret;
+}
+
+nvlist_t *symbiont_connect(const nvlist_t *request)
+{
+ nvlist_t *response;
+ IPADDR *ip, *my_ip;
+ int port, saved_errno, sock;
+
+ ip = nvlist_get_binary(request, "ip", NULL);
+ port = (int)nvlist_get_number(request, "port");
+ if (nvlist_exists(request, "my_ip"))
+ my_ip = nvlist_get_binary(request, "my_ip", NULL);
+ else
+ my_ip = NULL;
+
+ /* Connect. */
+ sock = net_connect_ip_handle(ip, port, my_ip);
+ saved_errno = errno;
+
+ /* Send back the socket fd. */
+ response = nvlist_create(0);
+
+ if (sock != -1)
+ nvlist_move_descriptor(response, "sock", sock);
+ nvlist_add_number(response, "errno", saved_errno);
+
+ return (response);
+}
+
+nvlist_t *symbiont_gethostbyname(const nvlist_t *request)
+{
+ nvlist_t *response;
+ IPADDR ip4, ip6;
+ const char *addr;
+ int ret, saved_errno;
+
+ addr = nvlist_get_string(request, "addr");
+
+ /* Connect. */
+ ret = net_gethostbyname(addr, &ip4, &ip6);
+ saved_errno = errno;
+
+ /* Send back the IPs. */
+ response = nvlist_create(0);
+
+ nvlist_add_number(response, "ret", ret);
+ nvlist_add_number(response, "errno", saved_errno);
+ nvlist_add_binary(response, "ip4", &ip4, sizeof(ip4));
+ nvlist_add_binary(response, "ip6", &ip6, sizeof(ip6));
+
+ return (response);
+}
+
+/*
+ * Child process, running outside the Capsicum sandbox.
+ */
+_Noreturn static void symbiont(void)
+{
+ nvlist_t *request, *response;
+ int error, opcode;
+
+ setproctitle("capsicum symbiont");
+ close(symbiontfds[1]);
+ close(0);
+ close(1);
+ close(2);
+
+ for (;;) {
+ /* Receive parameters from the main irssi process. */
+ request = nvlist_recv(symbiontfds[0], 0);
+ if (request == NULL)
+ exit(1);
+
+ opcode = nvlist_get_number(request, "opcode");
+ switch (opcode) {
+ case OPCODE_CONNECT:
+ response = symbiont_connect(request);
+ break;
+ case OPCODE_GETHOSTBYNAME:
+ response = symbiont_gethostbyname(request);
+ break;
+ default:
+ exit(1);
+ }
+
+ /* Send back the response. */
+ error = nvlist_send(symbiontfds[0], response);
+ if (error != 0)
+ exit(1);
+ nvlist_destroy(request);
+ nvlist_destroy(response);
+ }
+}
+
static int start_symbiont(void)
{
+ int childfd, error;
pid_t pid;
- nvlist_t *nvl;
- IPADDR *ip, *my_ip;
- int childfd, error, port, saved_errno, sock;
error = socketpair(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, symbiontfds);
if (error != 0) {
@@ -110,40 +241,8 @@ static int start_symbiont(void)
return 0;
}
- /* We're the child, running outside the Capsicum sandbox. */
- setproctitle("capsicum symbiont");
- close(symbiontfds[1]);
- close(0);
- close(1);
- close(2);
- for (;;) {
- /* Receive parameters from the main irssi process. */
- nvl = nvlist_recv(symbiontfds[0], 0);
- if (nvl == NULL)
- exit(1);
- ip = nvlist_get_binary(nvl, "ip", NULL);
- port = (int)nvlist_get_number(nvl, "port");
- if (nvlist_exists(nvl, "my_ip"))
- my_ip = nvlist_get_binary(nvl, "my_ip", NULL);
- else
- my_ip = NULL;
-
- /* Connect. */
- sock = net_connect_ip_handle(ip, port, my_ip);
- saved_errno = errno;
-
- /* Send back the socket fd. */
- nvlist_destroy(nvl);
- nvl = nvlist_create(0);
-
- if (sock != -1)
- nvlist_move_descriptor(nvl, "sock", sock);
- nvlist_add_number(nvl, "errno", saved_errno);
- error = nvlist_send(symbiontfds[0], nvl);
- if (error != 0)
- exit(1);
- nvlist_destroy(nvl);
- }
+ symbiont();
+ /* NOTREACHED */
}
static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
index f8cec28e..2733c1ea 100644
--- a/src/core/capsicum.h
+++ b/src/core/capsicum.h
@@ -3,6 +3,7 @@
gboolean capsicum_enabled(void);
int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
+int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
void capsicum_init(void);
void capsicum_deinit(void);
diff --git a/src/core/network.c b/src/core/network.c
index b182d19f..2954af54 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -406,6 +406,11 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
struct addrinfo hints, *ai, *ailist;
int ret, count_v4, count_v6, use_v4, use_v6;
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ return (capsicum_net_gethostbyname(addr, ip4, ip6));
+#endif
+
g_return_val_if_fail(addr != NULL, -1);
memset(ip4, 0, sizeof(IPADDR));
From 1f57ceec4c4e7c3d42f341921e36fe4aab612e57 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Fri, 28 Jul 2017 18:10:45 +0100
Subject: [PATCH 09/76] Prevent the user from calling "/capsicum enter" twice.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 99f7ff0f..f44b326d 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -252,8 +252,15 @@ static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
static void cmd_capsicum_enter(void)
{
+ u_int mode;
int error;
+ error = cap_getmode(&mode);
+ if (error == 0 && mode != 0) {
+ g_warning("Already in capability mode");
+ return;
+ }
+
error = start_symbiont();
if (error != 0) {
signal_emit("capability mode failed", 1, strerror(errno));
From 939371aa1dfdbf11fe98648e1eafc4c95e80bb9e Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Fri, 28 Jul 2017 18:44:18 +0100
Subject: [PATCH 10/76] Fix warnings.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 4 ++--
src/core/network.c | 2 +-
src/core/network.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index f44b326d..5a59adcd 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -93,7 +93,7 @@ int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
{
nvlist_t *nvl;
- IPADDR *received_ip4, *received_ip6;
+ const IPADDR *received_ip4, *received_ip6;
int error, ret, saved_errno;
/* Send request to the symbiont. */
@@ -130,7 +130,7 @@ int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
nvlist_t *symbiont_connect(const nvlist_t *request)
{
nvlist_t *response;
- IPADDR *ip, *my_ip;
+ const IPADDR *ip, *my_ip;
int port, saved_errno, sock;
ip = nvlist_get_binary(request, "ip", NULL);
diff --git a/src/core/network.c b/src/core/network.c
index 2954af54..01e56eb5 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -147,7 +147,7 @@ GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip)
return net_connect_ip(ip, port, my_ip);
}
-int net_connect_ip_handle(IPADDR *ip, int port, IPADDR *my_ip)
+int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip)
{
union sockaddr_union so;
int handle, ret, opt = 1;
diff --git a/src/core/network.h b/src/core/network.h
index 5ccacc0d..d1582a2e 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -36,7 +36,7 @@ GIOChannel *g_io_channel_new(int handle);
/* returns 1 if IPADDRs are the same */
int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
-int net_connect_ip_handle(IPADDR *ip, int port, IPADDR *my_ip);
+int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
/* Connect to socket */
GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip) G_GNUC_DEPRECATED;
From 241dd66ac11d54b37c671cd56f1320fe5b83803d Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Fri, 28 Jul 2017 05:08:34 +0100
Subject: [PATCH 11/76] Working /log and /rawlog.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 33 +++++++++++++++++++++++++++++++++
src/core/capsicum.h | 1 +
src/core/log.c | 15 ++++++++++++++-
src/core/log.h | 2 ++
src/core/network.c | 1 -
src/core/rawlog.c | 17 +++++++++++++++--
6 files changed, 65 insertions(+), 4 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 5a59adcd..6667276c 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -20,6 +20,8 @@
#include "module.h"
#include "commands.h"
+#include "log.h"
+#include "misc.h"
#include "network.h"
#include "settings.h"
#include "signals.h"
@@ -34,6 +36,9 @@
#define OPCODE_CONNECT 1
#define OPCODE_GETHOSTBYNAME 2
+static char *irclogs_path;
+static size_t irclogs_path_len;
+static int irclogs_fd;
static int symbiontfds[2];
gboolean capsicum_enabled(void)
@@ -127,6 +132,23 @@ int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
return ret;
}
+int capsicum_open(const char *path, int flags, int mode)
+{
+ int fd;
+
+ /* +1 is for slash separating irclogs_path and the rest. */
+ if (strlen(path) > irclogs_path_len + 1 && strncmp(path, irclogs_path, irclogs_path_len) == 0) {
+ fd = openat(irclogs_fd, path + irclogs_path_len + 1, flags, mode);
+ } else {
+ fd = open(path, flags, mode);
+ }
+
+ if (fd < 0 && (errno == ENOTCAPABLE || errno == ECAPMODE))
+ g_warning("File system access restricted to %s due to capability mode", irclogs_path);
+
+ return (fd);
+}
+
nvlist_t *symbiont_connect(const nvlist_t *request)
{
nvlist_t *response;
@@ -261,6 +283,16 @@ static void cmd_capsicum_enter(void)
return;
}
+ irclogs_path = convert_home(settings_get_str("capsicum_irclogs_path"));
+ g_mkdir_with_parents(irclogs_path, log_dir_create_mode);
+ irclogs_path_len = strlen(irclogs_path);
+ irclogs_fd = open(irclogs_path, O_DIRECTORY | O_CLOEXEC);
+ if (irclogs_fd < 0) {
+ g_warning("Unable to open %s: %s", irclogs_path, strerror(errno));
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
error = start_symbiont();
if (error != 0) {
signal_emit("capability mode failed", 1, strerror(errno));
@@ -299,6 +331,7 @@ void sig_init_finished(void)
void capsicum_init(void)
{
settings_add_bool("misc", "capsicum", FALSE);
+ settings_add_str("misc", "capsicum_irclogs_path", "~/irclogs");
signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
index 2733c1ea..ca35fd05 100644
--- a/src/core/capsicum.h
+++ b/src/core/capsicum.h
@@ -4,6 +4,7 @@
gboolean capsicum_enabled(void);
int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
+int capsicum_open(const char *path, int flags, int mode);
void capsicum_init(void);
void capsicum_deinit(void);
diff --git a/src/core/log.c b/src/core/log.c
index cee1dab5..00686bee 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -26,6 +26,9 @@
#include "servers.h"
#include "log.h"
#include "write-buffer.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "lib-config/iconfig.h"
#include "settings.h"
@@ -73,6 +76,16 @@ static void log_write_timestamp(int handle, const char *format,
if (text != NULL) write_buffer(handle, text, strlen(text));
}
+static int log_open_wrapper(const char *path, int flags, int mode)
+{
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ return capsicum_open(path, flags, mode);
+#endif
+
+ return open(path, flags, mode);
+}
+
static char *log_filename(LOG_REC *log)
{
char *str, fname[1024];
@@ -119,7 +132,7 @@ int log_start_logging(LOG_REC *log)
}
log->handle = log->real_fname == NULL ? -1 :
- open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
+ log_open_wrapper(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
if (log->handle == -1) {
signal_emit("log create failed", 1, log);
diff --git a/src/core/log.h b/src/core/log.h
index 5a07859b..52660bb9 100644
--- a/src/core/log.h
+++ b/src/core/log.h
@@ -38,6 +38,8 @@ extern GSList *logs;
extern int log_file_create_mode;
extern int log_dir_create_mode;
+extern int log_dir_create_mode;
+
/* Create log record - you still need to call log_update() to actually add it
into log list */
LOG_REC *log_create_rec(const char *fname, int level);
diff --git a/src/core/network.c b/src/core/network.c
index 01e56eb5..4494dbc6 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -198,7 +198,6 @@ int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip)
return handle;
}
-
/* Connect to socket with ip address */
GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
{
diff --git a/src/core/rawlog.c b/src/core/rawlog.c
index 2ec155fa..5df02981 100644
--- a/src/core/rawlog.c
+++ b/src/core/rawlog.c
@@ -27,12 +27,25 @@
#include "misc.h"
#include "write-buffer.h"
#include "settings.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "servers.h"
static int rawlog_lines;
static int signal_rawlog;
+static int rawlog_open_wrapper(const char *path, int flags, int mode)
+{
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ return capsicum_open(path, flags, mode);
+#endif
+
+ return open(path, flags, mode);
+}
+
RAWLOG_REC *rawlog_create(void)
{
RAWLOG_REC *rec;
@@ -126,7 +139,7 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname)
return;
path = convert_home(fname);
- rawlog->handle = open(path, O_WRONLY | O_APPEND | O_CREAT,
+ rawlog->handle = rawlog_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
g_free(path);
@@ -158,7 +171,7 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
g_free(dir);
path = convert_home(fname);
- f = open(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
+ f = rawlog_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
g_free(path);
if (f < 0) {
From e777ae986d64863a444132885b160ab2e9c7458e Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 29 Jul 2017 10:32:24 +0100
Subject: [PATCH 12/76] Working autolog.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 51 ++++++++++++++++++++++++++++++++++---
src/core/capsicum.h | 1 +
src/core/log.c | 7 +++++
src/core/rawlog.c | 9 ++++++-
src/fe-common/core/fe-log.c | 10 ++++++++
5 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 6667276c..c554fcf7 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -136,19 +136,62 @@ int capsicum_open(const char *path, int flags, int mode)
{
int fd;
- /* +1 is for slash separating irclogs_path and the rest. */
- if (strlen(path) > irclogs_path_len + 1 && strncmp(path, irclogs_path, irclogs_path_len) == 0) {
- fd = openat(irclogs_fd, path + irclogs_path_len + 1, flags, mode);
+ /* +1 is for the slash separating irclogs_path and the rest. */
+ if (strlen(path) > irclogs_path_len + 1 &&
+ strncmp(path, irclogs_path, irclogs_path_len) == 0) {
+ fd = openat(irclogs_fd, path + irclogs_path_len + 1,
+ flags, mode);
} else {
fd = open(path, flags, mode);
}
if (fd < 0 && (errno == ENOTCAPABLE || errno == ECAPMODE))
- g_warning("File system access restricted to %s due to capability mode", irclogs_path);
+ g_warning("File system access restricted to %s "
+ "due to capability mode", irclogs_path);
return (fd);
}
+void capsicum_mkdir_with_parents(const char *path, int mode)
+{
+ char *component, *copy, *tofree;
+ int error, fd, newfd;
+
+ /* +1 is for the slash separating irclogs_path and the rest. */
+ if (strlen(path) <= irclogs_path_len + 1 ||
+ strncmp(path, irclogs_path, irclogs_path_len) != 0) {
+ g_warning("Cannot create %s: file system access restricted "
+ "to %s due to capability mode", path, irclogs_path);
+ return;
+ }
+
+ copy = tofree = g_strdup(path + irclogs_path_len + 1);
+ fd = irclogs_fd;
+ for (;;) {
+ component = strsep(©, "/");
+ if (component == NULL)
+ break;
+ error = mkdirat(fd, component, mode);
+ if (error != 0 && errno != EEXIST) {
+ g_warning("cannot create %s: %s",
+ component, strerror(errno));
+ break;
+ }
+ newfd = openat(fd, component, O_DIRECTORY);
+ if (newfd < 0) {
+ g_warning("cannot open %s: %s",
+ component, strerror(errno));
+ break;
+ }
+ if (fd != irclogs_fd)
+ close(fd);
+ fd = newfd;
+ }
+ g_free(tofree);
+ if (fd != irclogs_fd)
+ close(fd);
+}
+
nvlist_t *symbiont_connect(const nvlist_t *request)
{
nvlist_t *response;
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
index ca35fd05..1eb56402 100644
--- a/src/core/capsicum.h
+++ b/src/core/capsicum.h
@@ -5,6 +5,7 @@ gboolean capsicum_enabled(void);
int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
int capsicum_open(const char *path, int flags, int mode);
+void capsicum_mkdir_with_parents(const char *path, int mode);
void capsicum_init(void);
void capsicum_deinit(void);
diff --git a/src/core/log.c b/src/core/log.c
index 00686bee..9394263f 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -127,7 +127,14 @@ int log_start_logging(LOG_REC *log)
/* path may contain variables (%time, $vars),
make sure the directory is created */
dir = g_path_get_dirname(log->real_fname);
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ capsicum_mkdir_with_parents(dir, log_dir_create_mode);
+ else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#else
g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
}
diff --git a/src/core/rawlog.c b/src/core/rawlog.c
index 5df02981..dd86af7c 100644
--- a/src/core/rawlog.c
+++ b/src/core/rawlog.c
@@ -167,7 +167,14 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
- g_mkdir_with_parents(dir, log_dir_create_mode);
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ capsicum_mkdir_with_parents(dir, log_dir_create_mode);
+ else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
path = convert_home(fname);
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index 37b29990..deb70991 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -30,6 +30,9 @@
#include "special-vars.h"
#include "settings.h"
#include "lib-config/iconfig.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "fe-windows.h"
#include "window-items.h"
@@ -451,7 +454,14 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
dir = g_path_get_dirname(log->real_fname);
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ capsicum_mkdir_with_parents(dir, log_dir_create_mode);
+ else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#else
g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
log->temp = TRUE;
From c00d4753aee732b5a815f12dda3c9fced41ef1f5 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 29 Jul 2017 11:41:56 +0100
Subject: [PATCH 13/76] Restrict port range available in capability mode.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index c554fcf7..e87704dd 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -40,6 +40,8 @@ static char *irclogs_path;
static size_t irclogs_path_len;
static int irclogs_fd;
static int symbiontfds[2];
+static int port_min;
+static int port_max;
gboolean capsicum_enabled(void)
{
@@ -90,6 +92,13 @@ int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
}
saved_errno = nvlist_get_number(nvl, "errno");
nvlist_destroy(nvl);
+
+ if (sock == -1 && (port < port_min || port > port_max)) {
+ g_warning("Access restricted to ports between %d and %d "
+ "due to capability mode",
+ port_min, port_max);
+ }
+
errno = saved_errno;
return sock;
@@ -205,9 +214,19 @@ nvlist_t *symbiont_connect(const nvlist_t *request)
else
my_ip = NULL;
- /* Connect. */
- sock = net_connect_ip_handle(ip, port, my_ip);
- saved_errno = errno;
+ /*
+ * Check if the port is in allowed range. This is to minimize
+ * the chance of the attacker rooting another system in case of
+ * compromise.
+ */
+ if (port < port_min || port > port_max) {
+ sock = -1;
+ saved_errno = EPERM;
+ } else {
+ /* Connect. */
+ sock = net_connect_ip_handle(ip, port, my_ip);
+ saved_errno = errno;
+ }
/* Send back the socket fd. */
response = nvlist_create(0);
@@ -326,6 +345,9 @@ static void cmd_capsicum_enter(void)
return;
}
+ port_min = settings_get_int("capsicum_port_min");
+ port_max = settings_get_int("capsicum_port_max");
+
irclogs_path = convert_home(settings_get_str("capsicum_irclogs_path"));
g_mkdir_with_parents(irclogs_path, log_dir_create_mode);
irclogs_path_len = strlen(irclogs_path);
@@ -375,6 +397,8 @@ void capsicum_init(void)
{
settings_add_bool("misc", "capsicum", FALSE);
settings_add_str("misc", "capsicum_irclogs_path", "~/irclogs");
+ settings_add_int("misc", "capsicum_port_min", 6667);
+ settings_add_int("misc", "capsicum_port_max", 6697);
signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
From 12e2c46d6a778f131c1ca6a7134af1cd5e722dbe Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 29 Jul 2017 12:28:49 +0100
Subject: [PATCH 14/76] Add wrappers to reduce #ifdefs.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 17 +++++++++++++++++
src/core/capsicum.h | 12 +++++++++++-
src/core/log.c | 23 ++---------------------
src/core/rawlog.c | 29 ++++++-----------------------
src/fe-common/core/fe-log.c | 11 +----------
5 files changed, 37 insertions(+), 55 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index e87704dd..99a4e795 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -161,6 +161,14 @@ int capsicum_open(const char *path, int flags, int mode)
return (fd);
}
+int capsicum_open_wrapper(const char *path, int flags, int mode)
+{
+ if (capsicum_enabled()) {
+ return capsicum_open(path, flags, mode);
+ }
+ return open(path, flags, mode);
+}
+
void capsicum_mkdir_with_parents(const char *path, int mode)
{
char *component, *copy, *tofree;
@@ -201,6 +209,15 @@ void capsicum_mkdir_with_parents(const char *path, int mode)
close(fd);
}
+void capsicum_mkdir_with_parents_wrapper(const char *path, int mode)
+{
+ if (capsicum_enabled()) {
+ capsicum_mkdir_with_parents(path, mode);
+ return;
+ }
+ g_mkdir_with_parents(path, mode);
+}
+
nvlist_t *symbiont_connect(const nvlist_t *request)
{
nvlist_t *response;
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
index 1eb56402..3c1234e1 100644
--- a/src/core/capsicum.h
+++ b/src/core/capsicum.h
@@ -7,7 +7,17 @@ int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
int capsicum_open(const char *path, int flags, int mode);
void capsicum_mkdir_with_parents(const char *path, int mode);
+#ifdef HAVE_CAPSICUM
+int capsicum_open_wrapper(const char *path, int flags, int mode);
+void capsicum_mkdir_with_parents_wrapper(const char *path, int mode);
+#else
+#define capsicum_open_wrapper(P, F, M) \
+ open(P, F, M)
+#define capsicum_mkdir_with_parents_wrapper(P, M) \
+ g_mkdir_with_parents(P, M)
+#endif
+
void capsicum_init(void);
void capsicum_deinit(void);
-#endif
+#endif /* !__CAPSICUM_H */
diff --git a/src/core/log.c b/src/core/log.c
index 9394263f..ea2f1a1d 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -26,9 +26,7 @@
#include "servers.h"
#include "log.h"
#include "write-buffer.h"
-#ifdef HAVE_CAPSICUM
#include "capsicum.h"
-#endif
#include "lib-config/iconfig.h"
#include "settings.h"
@@ -76,16 +74,6 @@ static void log_write_timestamp(int handle, const char *format,
if (text != NULL) write_buffer(handle, text, strlen(text));
}
-static int log_open_wrapper(const char *path, int flags, int mode)
-{
-#ifdef HAVE_CAPSICUM
- if (capsicum_enabled())
- return capsicum_open(path, flags, mode);
-#endif
-
- return open(path, flags, mode);
-}
-
static char *log_filename(LOG_REC *log)
{
char *str, fname[1024];
@@ -127,19 +115,12 @@ int log_start_logging(LOG_REC *log)
/* path may contain variables (%time, $vars),
make sure the directory is created */
dir = g_path_get_dirname(log->real_fname);
-#ifdef HAVE_CAPSICUM
- if (capsicum_enabled())
- capsicum_mkdir_with_parents(dir, log_dir_create_mode);
- else
- g_mkdir_with_parents(dir, log_dir_create_mode);
-#else
- g_mkdir_with_parents(dir, log_dir_create_mode);
-#endif
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
g_free(dir);
}
log->handle = log->real_fname == NULL ? -1 :
- log_open_wrapper(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
+ capsicum_open_wrapper(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
if (log->handle == -1) {
signal_emit("log create failed", 1, log);
diff --git a/src/core/rawlog.c b/src/core/rawlog.c
index dd86af7c..8f674e6b 100644
--- a/src/core/rawlog.c
+++ b/src/core/rawlog.c
@@ -27,25 +27,13 @@
#include "misc.h"
#include "write-buffer.h"
#include "settings.h"
-#ifdef HAVE_CAPSICUM
#include "capsicum.h"
-#endif
#include "servers.h"
static int rawlog_lines;
static int signal_rawlog;
-static int rawlog_open_wrapper(const char *path, int flags, int mode)
-{
-#ifdef HAVE_CAPSICUM
- if (capsicum_enabled())
- return capsicum_open(path, flags, mode);
-#endif
-
- return open(path, flags, mode);
-}
-
RAWLOG_REC *rawlog_create(void)
{
RAWLOG_REC *rec;
@@ -139,8 +127,9 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname)
return;
path = convert_home(fname);
- rawlog->handle = rawlog_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
- log_file_create_mode);
+ rawlog->handle = capsicum_open_wrapper(path,
+ O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
g_free(path);
if (rawlog->handle == -1) {
@@ -167,18 +156,12 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
-#ifdef HAVE_CAPSICUM
- if (capsicum_enabled())
- capsicum_mkdir_with_parents(dir, log_dir_create_mode);
- else
- g_mkdir_with_parents(dir, log_dir_create_mode);
-#else
- g_mkdir_with_parents(dir, log_dir_create_mode);
-#endif
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
g_free(dir);
path = convert_home(fname);
- f = rawlog_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
+ f = capsicum_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
g_free(path);
if (f < 0) {
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index deb70991..3d8910c9 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -30,9 +30,7 @@
#include "special-vars.h"
#include "settings.h"
#include "lib-config/iconfig.h"
-#ifdef HAVE_CAPSICUM
#include "capsicum.h"
-#endif
#include "fe-windows.h"
#include "window-items.h"
@@ -454,14 +452,7 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
dir = g_path_get_dirname(log->real_fname);
-#ifdef HAVE_CAPSICUM
- if (capsicum_enabled())
- capsicum_mkdir_with_parents(dir, log_dir_create_mode);
- else
- g_mkdir_with_parents(dir, log_dir_create_mode);
-#else
- g_mkdir_with_parents(dir, log_dir_create_mode);
-#endif
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
g_free(dir);
log->temp = TRUE;
From 8c04c2be14fc053bd7b5ff03b8e4ba8cb5023700 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 29 Jul 2017 12:30:27 +0100
Subject: [PATCH 15/76] Fix build without Capsicum.
Signed-off-by: Edward Tomasz Napierala
---
src/core/core.c | 4 ++++
src/fe-common/core/fe-common-core.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/src/core/core.c b/src/core/core.c
index 72631f91..c95879de 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -236,7 +236,9 @@ void core_init(void)
commands_init();
nickmatch_cache_init();
session_init();
+#ifdef HAVE_CAPSICUM
capsicum_init();
+#endif
chat_protocols_init();
chatnets_init();
@@ -294,7 +296,9 @@ void core_deinit(void)
chatnets_deinit();
chat_protocols_deinit();
+#ifdef HAVE_CAPSICUM
capsicum_deinit();
+#endif
session_deinit();
nickmatch_cache_deinit();
commands_deinit();
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c
index a0388827..67c9e20c 100644
--- a/src/fe-common/core/fe-common-core.c
+++ b/src/fe-common/core/fe-common-core.c
@@ -180,7 +180,9 @@ void fe_common_core_init(void)
fe_server_init();
fe_settings_init();
fe_tls_init();
+#ifdef HAVE_CAPSICUM
fe_capsicum_init();
+#endif
windows_init();
window_activity_init();
window_commands_init();
@@ -223,7 +225,9 @@ void fe_common_core_deinit(void)
fe_server_deinit();
fe_settings_deinit();
fe_tls_deinit();
+#ifdef HAVE_CAPSICUM
fe_capsicum_deinit();
+#endif
windows_deinit();
window_activity_deinit();
window_commands_deinit();
From 7f2697d30744d1f33cf67430aa48013b8f4ae9cd Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 29 Jul 2017 12:38:06 +0100
Subject: [PATCH 16/76] Cosmetics.
Signed-off-by: Edward Tomasz Napierala
---
src/core/log.h | 2 --
src/core/rawlog.c | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/core/log.h b/src/core/log.h
index 52660bb9..5a07859b 100644
--- a/src/core/log.h
+++ b/src/core/log.h
@@ -38,8 +38,6 @@ extern GSList *logs;
extern int log_file_create_mode;
extern int log_dir_create_mode;
-extern int log_dir_create_mode;
-
/* Create log record - you still need to call log_update() to actually add it
into log list */
LOG_REC *log_create_rec(const char *fname, int level);
diff --git a/src/core/rawlog.c b/src/core/rawlog.c
index 8f674e6b..a95b9a92 100644
--- a/src/core/rawlog.c
+++ b/src/core/rawlog.c
@@ -156,7 +156,7 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
- capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
g_free(dir);
path = convert_home(fname);
From a29eeaa9f2e85630b08fc46b3a2b8749b9719efd Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 29 Jul 2017 20:04:28 +0100
Subject: [PATCH 17/76] Fix trailing slash handling for capsicum_irclogs_path.
This is mostly an anti-footshooting measure, but still.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 99a4e795..01f5f95c 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -147,6 +147,7 @@ int capsicum_open(const char *path, int flags, int mode)
/* +1 is for the slash separating irclogs_path and the rest. */
if (strlen(path) > irclogs_path_len + 1 &&
+ path[irclogs_path_len] == '/' &&
strncmp(path, irclogs_path, irclogs_path_len) == 0) {
fd = openat(irclogs_fd, path + irclogs_path_len + 1,
flags, mode);
@@ -176,6 +177,7 @@ void capsicum_mkdir_with_parents(const char *path, int mode)
/* +1 is for the slash separating irclogs_path and the rest. */
if (strlen(path) <= irclogs_path_len + 1 ||
+ path[irclogs_path_len] != '/' ||
strncmp(path, irclogs_path, irclogs_path_len) != 0) {
g_warning("Cannot create %s: file system access restricted "
"to %s due to capability mode", path, irclogs_path);
@@ -366,8 +368,15 @@ static void cmd_capsicum_enter(void)
port_max = settings_get_int("capsicum_port_max");
irclogs_path = convert_home(settings_get_str("capsicum_irclogs_path"));
- g_mkdir_with_parents(irclogs_path, log_dir_create_mode);
irclogs_path_len = strlen(irclogs_path);
+
+ /* Strip trailing slashes, if any. */
+ while (irclogs_path_len > 0 && irclogs_path[irclogs_path_len - 1] == '/') {
+ irclogs_path[irclogs_path_len - 1] = '\0';
+ irclogs_path_len--;
+ }
+
+ g_mkdir_with_parents(irclogs_path, log_dir_create_mode);
irclogs_fd = open(irclogs_path, O_DIRECTORY | O_CLOEXEC);
if (irclogs_fd < 0) {
g_warning("Unable to open %s: %s", irclogs_path, strerror(errno));
From 8bb392a3f47d74cccb9e2d7e3633e3e534306968 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sun, 30 Jul 2017 01:27:33 +0100
Subject: [PATCH 18/76] Hook up capsicum.h and fe-capsicum.h to autotools.
This hopefully fixes Travis build.
Signed-off-by: Edward Tomasz Napierala
---
src/core/Makefile.am | 1 +
src/fe-common/core/Makefile.am | 1 +
2 files changed, 2 insertions(+)
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index f3bc1674..983f7e32 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -74,6 +74,7 @@ structure_headers = \
pkginc_coredir=$(pkgincludedir)/src/core
pkginc_core_HEADERS = \
args.h \
+ capsicum.h \
channels.h \
channels-setup.h \
commands.h \
diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am
index 08e41520..29cc941a 100644
--- a/src/fe-common/core/Makefile.am
+++ b/src/fe-common/core/Makefile.am
@@ -48,6 +48,7 @@ pkginc_fe_common_core_HEADERS = \
command-history.h \
chat-completion.h \
completion.h \
+ fe-capsicum.h \
fe-channels.h \
fe-common-core.h \
fe-core-commands.h \
From 5551b4fe9504f5d5b4e81a680741cab72bec82e9 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sun, 30 Jul 2017 11:47:08 +0100
Subject: [PATCH 19/76] Update copyrights.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 4 ++++
src/fe-common/core/fe-capsicum.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 01f5f95c..b5f704f7 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -3,6 +3,10 @@
Copyright (C) 2017 Edward Tomasz Napierala
+ This software was developed by SRI International and the University of
+ Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
+ ("CTSRD"), as part of the DARPA CRASH research programme.
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
diff --git a/src/fe-common/core/fe-capsicum.c b/src/fe-common/core/fe-capsicum.c
index 5816b223..4666eda7 100644
--- a/src/fe-common/core/fe-capsicum.c
+++ b/src/fe-common/core/fe-capsicum.c
@@ -3,6 +3,10 @@
Copyright (C) 2017 Edward Tomasz Napierala
+ This software was developed by SRI International and the University of
+ Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
+ ("CTSRD"), as part of the DARPA CRASH research programme.
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
From aeaa420ad330a528391ed149371b55581a808655 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Tue, 1 Aug 2017 01:15:25 +0100
Subject: [PATCH 20/76] Clean up includes a bit.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 1 +
src/fe-common/core/fe-capsicum.c | 9 ++++-----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index b5f704f7..06cb8d9b 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -23,6 +23,7 @@
*/
#include "module.h"
+#include "capsicum.h"
#include "commands.h"
#include "log.h"
#include "misc.h"
diff --git a/src/fe-common/core/fe-capsicum.c b/src/fe-common/core/fe-capsicum.c
index 4666eda7..54a43d27 100644
--- a/src/fe-common/core/fe-capsicum.c
+++ b/src/fe-common/core/fe-capsicum.c
@@ -23,12 +23,11 @@
*/
#include "module.h"
-#include "module-formats.h"
-#include "signals.h"
-#include "printtext.h"
-
+#include "fe-capsicum.h"
#include "levels.h"
-#include "servers.h"
+#include "module-formats.h"
+#include "printtext.h"
+#include "signals.h"
static void capability_mode_enabled(void)
{
From 96f4fe10c6081cf441122039c39eb6422eef13e8 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Tue, 1 Aug 2017 01:47:45 +0100
Subject: [PATCH 21/76] Change the way we load default CA certificates so it
works with Capsicum.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 8 ++++++++
src/core/network-openssl.c | 23 ++++++++++++++++++++---
src/core/network-openssl.h | 6 ++++++
3 files changed, 34 insertions(+), 3 deletions(-)
create mode 100644 src/core/network-openssl.h
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 06cb8d9b..79db780a 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -28,6 +28,7 @@
#include "log.h"
#include "misc.h"
#include "network.h"
+#include "network-openssl.h"
#include "settings.h"
#include "signals.h"
@@ -361,6 +362,7 @@ static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
static void cmd_capsicum_enter(void)
{
u_int mode;
+ gboolean inited;
int error;
error = cap_getmode(&mode);
@@ -369,6 +371,12 @@ static void cmd_capsicum_enter(void)
return;
}
+ inited = irssi_ssl_init();
+ if (!inited) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
port_min = settings_get_int("capsicum_port_min");
port_max = settings_get_int("capsicum_port_max");
diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index 4de3cb3c..78bdcce4 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -20,6 +20,7 @@
#include "module.h"
#include "network.h"
+#include "network-openssl.h"
#include "net-sendbuffer.h"
#include "misc.h"
#include "servers.h"
@@ -58,6 +59,7 @@ typedef struct
} GIOSSLChannel;
static int ssl_inited = FALSE;
+static X509_STORE *store = NULL;
static void irssi_ssl_free(GIOChannel *handle)
{
@@ -362,8 +364,10 @@ static GIOFuncs irssi_ssl_channel_funcs = {
irssi_ssl_get_flags
};
-static gboolean irssi_ssl_init(void)
+gboolean irssi_ssl_init(void)
{
+ int success;
+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
if (!OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL)) {
g_error("Could not initialize OpenSSL");
@@ -374,6 +378,20 @@ static gboolean irssi_ssl_init(void)
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
#endif
+ store = X509_STORE_new();
+ if (store == NULL) {
+ g_error("Could not initialize OpenSSL: X509_STORE_new() failed");
+ return FALSE;
+ }
+
+ success = X509_STORE_set_default_paths(store);
+ if (success == 0) {
+ g_error("Could not load default certificates");
+ X509_STORE_free(store);
+ store = NULL;
+ return FALSE;
+ }
+
ssl_inited = TRUE;
return TRUE;
@@ -492,8 +510,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
g_free(scapath);
verify = TRUE;
} else {
- if (!SSL_CTX_set_default_verify_paths(ctx))
- g_warning("Could not load default certificates");
+ SSL_CTX_set_cert_store(ctx, store);
}
if(!(ssl = SSL_new(ctx)))
diff --git a/src/core/network-openssl.h b/src/core/network-openssl.h
new file mode 100644
index 00000000..4cd6d711
--- /dev/null
+++ b/src/core/network-openssl.h
@@ -0,0 +1,6 @@
+#ifndef __NETWORK_OPENSSL_H
+#define __NETWORK_OPENSSL_H
+
+gboolean irssi_ssl_init(void);
+
+#endif /* !__NETWORK_OPENSSL_H */
From 5db6caee0d17eb125d8c7f3090c325ffbee35920 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Tue, 1 Aug 2017 01:50:16 +0100
Subject: [PATCH 22/76] Attempt to fix build by adding the forgotten header.
Signed-off-by: Edward Tomasz Napierala
---
src/core/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 983f7e32..f64d9e2e 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -95,6 +95,7 @@ pkginc_core_HEADERS = \
net-nonblock.h \
net-sendbuffer.h \
network.h \
+ network-openssl.h \
nick-rec.h \
nicklist.h \
nickmatch-cache.h \
From 0c49a84ffb8d74506a13653183bfa1ef8ffd2554 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 9 Aug 2017 11:06:36 +0100
Subject: [PATCH 23/76] Add back some ifdefs.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.h | 10 +---------
src/core/core.c | 2 ++
src/core/log.c | 12 ++++++++++++
src/core/rawlog.c | 16 ++++++++++++++++
src/fe-common/core/fe-common-core.c | 2 ++
src/fe-common/core/fe-log.c | 6 ++++++
6 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
index 3c1234e1..7d89f2aa 100644
--- a/src/core/capsicum.h
+++ b/src/core/capsicum.h
@@ -5,17 +5,9 @@ gboolean capsicum_enabled(void);
int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
int capsicum_open(const char *path, int flags, int mode);
-void capsicum_mkdir_with_parents(const char *path, int mode);
-
-#ifdef HAVE_CAPSICUM
int capsicum_open_wrapper(const char *path, int flags, int mode);
+void capsicum_mkdir_with_parents(const char *path, int mode);
void capsicum_mkdir_with_parents_wrapper(const char *path, int mode);
-#else
-#define capsicum_open_wrapper(P, F, M) \
- open(P, F, M)
-#define capsicum_mkdir_with_parents_wrapper(P, M) \
- g_mkdir_with_parents(P, M)
-#endif
void capsicum_init(void);
void capsicum_deinit(void);
diff --git a/src/core/core.c b/src/core/core.c
index c95879de..506d6a13 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -29,7 +29,9 @@
#include "signals.h"
#include "settings.h"
#include "session.h"
+#ifdef HAVE_CAPSICUM
#include "capsicum.h"
+#endif
#include "chat-protocols.h"
#include "servers.h"
diff --git a/src/core/log.c b/src/core/log.c
index ea2f1a1d..f7741d3d 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -26,7 +26,9 @@
#include "servers.h"
#include "log.h"
#include "write-buffer.h"
+#ifdef HAVE_CAPSICUM
#include "capsicum.h"
+#endif
#include "lib-config/iconfig.h"
#include "settings.h"
@@ -115,13 +117,23 @@ int log_start_logging(LOG_REC *log)
/* path may contain variables (%time, $vars),
make sure the directory is created */
dir = g_path_get_dirname(log->real_fname);
+#ifdef HAVE_CAPSICUM
capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+#else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
}
+#ifdef HAVE_CAPSICUM
log->handle = log->real_fname == NULL ? -1 :
capsicum_open_wrapper(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
+#else
+ log->handle = log->real_fname == NULL ? -1 :
+ open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
+#endif
if (log->handle == -1) {
signal_emit("log create failed", 1, log);
log->failed = TRUE;
diff --git a/src/core/rawlog.c b/src/core/rawlog.c
index a95b9a92..fdd51241 100644
--- a/src/core/rawlog.c
+++ b/src/core/rawlog.c
@@ -27,7 +27,9 @@
#include "misc.h"
#include "write-buffer.h"
#include "settings.h"
+#ifdef HAVE_CAPSICUM
#include "capsicum.h"
+#endif
#include "servers.h"
@@ -127,9 +129,15 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname)
return;
path = convert_home(fname);
+#ifdef HAVE_CAPSICUM
rawlog->handle = capsicum_open_wrapper(path,
O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
+#else
+ rawlog->handle = open(path, O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
+#endif
+
g_free(path);
if (rawlog->handle == -1) {
@@ -156,12 +164,20 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
+#ifdef HAVE_CAPSICUM
capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+#else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
path = convert_home(fname);
+#ifdef HAVE_CAPSICUM
f = capsicum_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
+#else
+ f = open(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
+#endif
g_free(path);
if (f < 0) {
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c
index 67c9e20c..a3b7364c 100644
--- a/src/fe-common/core/fe-common-core.c
+++ b/src/fe-common/core/fe-common-core.c
@@ -32,7 +32,9 @@
#include "special-vars.h"
#include "fe-core-commands.h"
#include "fe-queries.h"
+#ifdef HAVE_CAPSICUM
#include "fe-capsicum.h"
+#endif
#include "hilight-text.h"
#include "command-history.h"
#include "completion.h"
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index 3d8910c9..0fed8642 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -30,7 +30,9 @@
#include "special-vars.h"
#include "settings.h"
#include "lib-config/iconfig.h"
+#ifdef HAVE_CAPSICUM
#include "capsicum.h"
+#endif
#include "fe-windows.h"
#include "window-items.h"
@@ -452,7 +454,11 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
dir = g_path_get_dirname(log->real_fname);
+#ifdef HAVE_CAPSICUM
capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+#else
+ g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
log->temp = TRUE;
From edee0ba587069a860eac43f9219f8ecfa49fe1fa Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Thu, 10 Aug 2017 14:35:34 +0100
Subject: [PATCH 24/76] Don't error out on failure to load default certificate
store.
This restores the previous behaviour.
Signed-off-by: Edward Tomasz Napierala
---
src/core/network-openssl.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index 78bdcce4..2054f28a 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -386,10 +386,10 @@ gboolean irssi_ssl_init(void)
success = X509_STORE_set_default_paths(store);
if (success == 0) {
- g_error("Could not load default certificates");
+ g_warning("Could not load default certificates");
X509_STORE_free(store);
store = NULL;
- return FALSE;
+ /* Don't return an error; the user might have their own cafile/capath. */
}
ssl_inited = TRUE;
@@ -509,7 +509,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
g_free(scafile);
g_free(scapath);
verify = TRUE;
- } else {
+ } else if (store != NULL) {
SSL_CTX_set_cert_store(ctx, store);
}
From 245a3fd4c1afb86b38eb17477a42c60c52cef793 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Mon, 28 Aug 2017 06:13:28 +0100
Subject: [PATCH 25/76] Add docs/capsicum.txt.
Signed-off-by: Edward Tomasz Napierala
---
docs/Makefile.am | 1 +
docs/capsicum.txt | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
create mode 100644 docs/capsicum.txt
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 861a2ca4..32722391 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -2,6 +2,7 @@ man_MANS = \
irssi.1
doc_DATA = \
+ capsicum.txt \
design.txt \
formats.txt \
manual.txt \
diff --git a/docs/capsicum.txt b/docs/capsicum.txt
new file mode 100644
index 00000000..3093bfe5
--- /dev/null
+++ b/docs/capsicum.txt
@@ -0,0 +1,30 @@
+Capsicum is a lightweight OS capability and sandbox framework provided
+by FreeBSD. When built with Capsicum support - which is the default under
+FreeBSD - Irssi can enter a Capsicum capability mode (a sandbox), greatly
+limiting possible consequences of a potential security hole in Irssi
+or the libraries it depends on.
+
+To make Irssi enter capability mode on startup, add
+
+capsicum = "yes";
+
+to your ~/.irssi/config and restart the client. Alternatively you can
+enter it "by hand", using the "/capsicum enter" command. From the security
+point of view it's strongly preferable to use the former method, to avoid
+establishing connections without the sandbox protection; the "/capsicum"
+command is only intended for experimentation, and in cases where you need
+to do something that's not possible in capability mode - run scripts,
+for example - before continuing.
+
+There is no way to leave the capability mode, apart from exiting Irssi.
+When running in capability mode, there are certain restrictions - Irssi
+won't be able to access any files outside the directory pointed to by
+capsicum_irclogs_path (which defaults to ~/irclogs/). If you change
+the path when already in capability mode it won't be effective until
+you restart Irssi. Capability mode also makes it impossible to use
+the "/save" command.
+
+Currently there is no way to use custom SSL certificates. As a workaround
+you can establish connections and enter the capability mode afterwards
+using the "/capsicum enter" command.
+
From b529e1a9df134bbc5618752abcf19af0110b6868 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Fri, 1 Sep 2017 10:39:14 +0100
Subject: [PATCH 26/76] Fix /back in Capsicum capability mode.
Signed-off-by: Edward Tomasz Napierala
---
src/fe-common/core/fe-core-commands.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c
index 97a246ec..fb98cc25 100644
--- a/src/fe-common/core/fe-core-commands.c
+++ b/src/fe-common/core/fe-core-commands.c
@@ -28,6 +28,9 @@
#include "settings.h"
#include "irssi-version.h"
#include "servers.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "fe-windows.h"
#include "printtext.h"
@@ -120,6 +123,9 @@ static void cmd_cat(const char *data)
GIOChannel *handle;
GString *buf;
gsize tpos;
+#ifdef HAVE_CAPSICUM
+ int fd;
+#endif
if (!cmd_get_params(data, &free_arg, 2, &fname, &fposstr))
return;
@@ -128,7 +134,15 @@ static void cmd_cat(const char *data)
fpos = atoi(fposstr);
cmd_params_free(free_arg);
+#ifdef HAVE_CAPSICUM
+ fd = capsicum_open_wrapper(fname, O_RDONLY, 0);
+ if (fd > 0)
+ handle = g_io_channel_unix_new(fd);
+ else
+ handle = NULL;
+#else
handle = g_io_channel_new_file(fname, "r", NULL);
+#endif
g_free(fname);
if (handle == NULL) {
From 96d5a4669d696d57a511119963ae5c651346e167 Mon Sep 17 00:00:00 2001
From: LemonBoy
Date: Mon, 11 Sep 2017 16:32:36 +0200
Subject: [PATCH 27/76] Increment the X509_STORE refcount during the connection
OpenSSL doesn't increment the reference count when the store is assigned
to a SSL_CTX.
---
src/core/network-openssl.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index 2054f28a..feb2295d 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -510,6 +510,10 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
g_free(scapath);
verify = TRUE;
} else if (store != NULL) {
+ /* Make sure to increment the refcount every time the store is
+ * used, that's essential not to get it free'd by OpenSSL when
+ * the SSL_CTX is destroyed. */
+ X509_STORE_up_ref(store);
SSL_CTX_set_cert_store(ctx, store);
}
From 36d8b974fc42ed8eb1ff88811e09d0910ae61187 Mon Sep 17 00:00:00 2001
From: LemonBoy
Date: Mon, 11 Sep 2017 17:07:50 +0200
Subject: [PATCH 28/76] Restore compatibility with old OpenSSL versions
Let's implement X509_STORE_up_ref on our own.
---
src/core/network-openssl.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index feb2295d..7ec902fb 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -45,6 +45,19 @@
#define ASN1_STRING_data(x) ASN1_STRING_get0_data(x)
#endif
+/* OpenSSL 1.1.0 also introduced some useful additions to the api */
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined (LIBRESSL_VERSION_NUMBER)
+static int X509_STORE_up_ref(X509_STORE *vfy)
+{
+ int n;
+
+ n = CRYPTO_add(&vfy->references, 1, CRYPTO_LOCK_X509_STORE);
+ g_assert(n > 1);
+
+ return (n > 1) ? 1 : 0;
+}
+#endif
+
/* ssl i/o channel object */
typedef struct
{
From 624ef4a696fc736779c6b7af94c7e376b7033590 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Tue, 12 Sep 2017 14:19:17 +0100
Subject: [PATCH 29/76] Get rid of the zombies in Capsicum capability mode.
Signed-off-by: Edward Tomasz Napierala
---
src/core/capsicum.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 79db780a..3b0708cb 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -403,6 +403,13 @@ static void cmd_capsicum_enter(void)
return;
}
+ /*
+ * XXX: We should use pdwait(2) to wait for children. Unfortunately
+ * it's not implemented yet. Thus the workaround, to get rid
+ * of the zombies at least.
+ */
+ signal(SIGCHLD, SIG_IGN);
+
error = cap_enter();
if (error != 0) {
signal_emit("capability mode failed", 1, strerror(errno));
From 0468c5d912fc8a89bd552611ef6243bd1c889df7 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Wed, 13 Sep 2017 13:58:00 +0200
Subject: [PATCH 30/76] add new function to set the position in bytes
fixes #752
---
src/fe-text/gui-entry.c | 20 ++++++++++++++++++++
src/fe-text/gui-entry.h | 1 +
src/fe-text/gui-readline.c | 6 ++----
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c
index f05decd2..e91fcfb3 100644
--- a/src/fe-text/gui-entry.c
+++ b/src/fe-text/gui-entry.c
@@ -936,6 +936,26 @@ void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos)
gui_entry_draw(entry);
}
+void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes)
+{
+ int pos;
+ const char *ptr;
+
+ g_return_if_fail(entry != NULL);
+
+ gui_entry_set_text(entry, str);
+
+ if (entry->utf8) {
+ g_utf8_validate(str, pos_bytes, &ptr);
+ pos = g_utf8_pointer_to_offset(str, ptr);
+ } else if (term_type == TERM_TYPE_BIG5)
+ pos = strlen_big5((const unsigned char *)str) - strlen_big5((const unsigned char *)(str + pos_bytes));
+ else
+ pos = pos_bytes;
+
+ gui_entry_set_pos(entry, pos);
+}
+
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
{
g_return_if_fail(entry != NULL);
diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h
index 8777f083..000c5f03 100644
--- a/src/fe-text/gui-entry.h
+++ b/src/fe-text/gui-entry.h
@@ -50,6 +50,7 @@ void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8);
void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str);
char *gui_entry_get_text(GUI_ENTRY_REC *entry);
char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos);
+void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes);
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str);
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr);
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index 2c2eac21..3688f15e 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -878,8 +878,7 @@ static void key_completion(int erase, int backward)
g_free(text);
if (line != NULL) {
- gui_entry_set_text(active_entry, line);
- gui_entry_set_pos(active_entry, pos);
+ gui_entry_set_text_and_pos_bytes(active_entry, line, pos);
g_free(line);
}
}
@@ -909,8 +908,7 @@ static void key_check_replaces(void)
g_free(text);
if (line != NULL) {
- gui_entry_set_text(active_entry, line);
- gui_entry_set_pos(active_entry, pos);
+ gui_entry_set_text_and_pos_bytes(active_entry, line, pos);
g_free(line);
}
}
From 32f33e7bb34598e8603b9f6a931ef063f6bd31f2 Mon Sep 17 00:00:00 2001
From: Robert Bisewski
Date: Tue, 3 Oct 2017 22:49:21 -0500
Subject: [PATCH 31/76] improving HOWTO document
---
docs/startup-HOWTO.html | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/startup-HOWTO.html b/docs/startup-HOWTO.html
index 07a9f47c..fe317ad9 100644
--- a/docs/startup-HOWTO.html
+++ b/docs/startup-HOWTO.html
@@ -635,7 +635,7 @@ separated by :
from the actual proxy password.
12. Statusbar
-/STATUSBAR
displays a list of statusbars:
+/STATUSBAR
displays a list of the current statusbars, along with their position and visibility:
Name Type Placement Position Visible
window window bottom 0 always
@@ -644,9 +644,9 @@ separated by :
from the actual proxy password.
topic root top 1 always
-/STATUSBAR <name>
prints the statusbar settings and it’s items. /STATUSBAR <name> ENABLE|DISABLE
enables/disables the statusbar. /STATUSBAR <name> RESET
resets the statusbar to it’s default settings, or if the statusbar was created by you, it will be removed.
+/STATUSBAR <name>
prints the statusbar settings (type, placement, position, visibility) as well as its items. /STATUSBAR <name> ENABLE|DISABLE
enables/disables the statusbar. /STATUSBAR <name> RESET
resets the statusbar to its default settings, or if the statusbar was created by you, it will be removed.
-Type can be window or root, meaning if the statusbar should be created for each split window, or just once. Placement can be top or bottom. Position is a number, the higher the value the lower in screen it is. Visible can be always, active or inactive. Active/inactive is useful only with split windows, one split window is active and the rest are inactive. These settings can be changed with:
+The statusbar type can be either window or root. If the type is window, then a statusbar will be created for each split window, otherwise it will be created only once. Placement can be top or bottom, which refers to the top or bottom of the screen. Position is a number, the higher the value the lower it will appear in-screen. Visible can be always, active or inactive. Active/inactive is useful only with split windows; one split window is active and the rest are inactive. To adjust these settings, the following commands are available:
/STATUSBAR <name> TYPE window|root
/STATUSBAR <name> PLACEMENT top|bottom
@@ -654,10 +654,10 @@ separated by :
from the actual proxy password.
/STATUSBAR <name> VISIBLE always|active|inactive
-When loading a new statusbar scripts, you’ll need to also specify where you want to show it. Statusbar items can be modified with:
+Statusbar items can also be added or removed via command. Note that when loading new statusbar scripts that add items, you will need to specify where you want to show the item and how it is aligned. This can be accomplished using the below commands:
/STATUSBAR <name> ADD [-before | -after <item>] [-priority #] [-alignment left|right] <item>
/STATUSBAR <name> REMOVE <item>
-The item name with statusbar scripts is usually same as the script’s name. Script’s documentation should tell if this isn’t the case. So, to add mail.pl before the window activity item (see the list with /STATUSBAR
window), use: /STATUSBAR window ADD -before act mail
.
+For statusbar scripts, the item name is usually equivalent to the script name. The documentation of the script ought to tell you if this is not the case. For example, to add mail.pl before the window activity item, use: /STATUSBAR window ADD -before act mail
.
From 1f7de4c3bd8cb03af76c14aff71fc535ce9f23de Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Thu, 5 Oct 2017 11:31:33 +0200
Subject: [PATCH 32/76] up abi
---
src/common.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/common.h b/src/common.h
index 100d00cb..159f7124 100644
--- a/src/common.h
+++ b/src/common.h
@@ -6,7 +6,7 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
-#define IRSSI_ABI_VERSION 10
+#define IRSSI_ABI_VERSION 11
#define DEFAULT_SERVER_ADD_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697
From e1e632d31e1d8efc3370db76ddcc4bda200e4d31 Mon Sep 17 00:00:00 2001
From: Robert Bisewski
Date: Thu, 5 Oct 2017 22:47:15 -0500
Subject: [PATCH 33/76] correcting and expanding content of statusbar help text
---
docs/help/in/statusbar.in | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/docs/help/in/statusbar.in b/docs/help/in/statusbar.in
index ac475dd5..7fff7fb8 100644
--- a/docs/help/in/statusbar.in
+++ b/docs/help/in/statusbar.in
@@ -5,22 +5,31 @@
%9Parameters:%9
- ENABLE: Enables the statusbar.
- DISABLE: Disabled the statusbar.
+ ENABLE: Adds a statusbar to the list of statusbars.
+ DISABLE: Removes a statusbar from the list.
RESET: Restores the default statusbar configuration.
- TYPE: Identifies the type of statusbar.
- PLACEMENT: Identifies the placement of the statusbar.
- POSITION: Identifies the position of the statusbar.
- VISIBLE: Identifies the visibility of the statusbar.
- ADD: Adds a statusbar into the configuration.
- REMOVE: Removes a statusbar from the configuration.
+ TYPE: Refers to the type of statusbar, for each split window
+ or only for the current root screen.
+ PLACEMENT: Refers to the placement of the statusbar, either at the
+ top or the bottom of the screen.
+ POSITION: Refers to the position of the statusbar. Represented as
+ an unsigned integer, with 0 implying the first position.
+ VISIBLE: Refers to the visibility of the statusbar or item. If set
+ to always it is visible on all screens, otherwise if set
+ to inactive or active then it is only visible on inactive
+ or active screens, respectively.
+ ADD: Adds an item to the specified statusbar. It can be set to
+ appear before/after another item and left/right aligned
+ to a specified position on the screen.
+ REMOVE: Removes an item from the specified statusbar.
- The name of the statusbar; if no argument is given, the list of statusbars
- will be displayed.
+ Where name refers to the name of the statusbar; if no argument is
+ given, the entire list of statusbars will be displayed.
%9Description:%9
- Modified the attributes of the statusbar.
+ Allows adjustment of the attributes and items of a statusbar, as well
+ as where it is located and whether or not it is currently visible.
%9Examples:%9
From 0883ff8d320be47336e05aa38cf11427bd79b3af Mon Sep 17 00:00:00 2001
From: Robert Bisewski
Date: Fri, 6 Oct 2017 07:13:30 -0500
Subject: [PATCH 34/76] reverting changes to startup HOWTO
---
docs/startup-HOWTO.html | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/startup-HOWTO.html b/docs/startup-HOWTO.html
index fe317ad9..07a9f47c 100644
--- a/docs/startup-HOWTO.html
+++ b/docs/startup-HOWTO.html
@@ -635,7 +635,7 @@ separated by :
from the actual proxy password.
12. Statusbar
-/STATUSBAR
displays a list of the current statusbars, along with their position and visibility:
+/STATUSBAR
displays a list of statusbars:
Name Type Placement Position Visible
window window bottom 0 always
@@ -644,9 +644,9 @@ separated by :
from the actual proxy password.
topic root top 1 always
-/STATUSBAR <name>
prints the statusbar settings (type, placement, position, visibility) as well as its items. /STATUSBAR <name> ENABLE|DISABLE
enables/disables the statusbar. /STATUSBAR <name> RESET
resets the statusbar to its default settings, or if the statusbar was created by you, it will be removed.
+/STATUSBAR <name>
prints the statusbar settings and it’s items. /STATUSBAR <name> ENABLE|DISABLE
enables/disables the statusbar. /STATUSBAR <name> RESET
resets the statusbar to it’s default settings, or if the statusbar was created by you, it will be removed.
-The statusbar type can be either window or root. If the type is window, then a statusbar will be created for each split window, otherwise it will be created only once. Placement can be top or bottom, which refers to the top or bottom of the screen. Position is a number, the higher the value the lower it will appear in-screen. Visible can be always, active or inactive. Active/inactive is useful only with split windows; one split window is active and the rest are inactive. To adjust these settings, the following commands are available:
+Type can be window or root, meaning if the statusbar should be created for each split window, or just once. Placement can be top or bottom. Position is a number, the higher the value the lower in screen it is. Visible can be always, active or inactive. Active/inactive is useful only with split windows, one split window is active and the rest are inactive. These settings can be changed with:
/STATUSBAR <name> TYPE window|root
/STATUSBAR <name> PLACEMENT top|bottom
@@ -654,10 +654,10 @@ separated by :
from the actual proxy password.
/STATUSBAR <name> VISIBLE always|active|inactive
-Statusbar items can also be added or removed via command. Note that when loading new statusbar scripts that add items, you will need to specify where you want to show the item and how it is aligned. This can be accomplished using the below commands:
+When loading a new statusbar scripts, you’ll need to also specify where you want to show it. Statusbar items can be modified with:
/STATUSBAR <name> ADD [-before | -after <item>] [-priority #] [-alignment left|right] <item>
/STATUSBAR <name> REMOVE <item>
-For statusbar scripts, the item name is usually equivalent to the script name. The documentation of the script ought to tell you if this is not the case. For example, to add mail.pl before the window activity item, use: /STATUSBAR window ADD -before act mail
.
+The item name with statusbar scripts is usually same as the script’s name. Script’s documentation should tell if this isn’t the case. So, to add mail.pl before the window activity item (see the list with /STATUSBAR
window), use: /STATUSBAR window ADD -before act mail
.
From 84bfea52af8776e13d754e2ee20387f07556fc90 Mon Sep 17 00:00:00 2001
From: Robert Bisewski
Date: Fri, 6 Oct 2017 07:54:54 -0500
Subject: [PATCH 35/76] adjusting text content as per the pull-request
discussion
---
docs/help/in/statusbar.in | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/docs/help/in/statusbar.in b/docs/help/in/statusbar.in
index 7fff7fb8..13977891 100644
--- a/docs/help/in/statusbar.in
+++ b/docs/help/in/statusbar.in
@@ -6,15 +6,17 @@
%9Parameters:%9
ENABLE: Adds a statusbar to the list of statusbars.
- DISABLE: Removes a statusbar from the list.
+ DISABLE: Removes a statusbar from the list. Note that for
+ built-in statusbars they can be enabled again should the
+ user wish to add back the default statusbars.
RESET: Restores the default statusbar configuration.
- TYPE: Refers to the type of statusbar, for each split window
- or only for the current root screen.
- PLACEMENT: Refers to the placement of the statusbar, either at the
- top or the bottom of the screen.
- POSITION: Refers to the position of the statusbar. Represented as
- an unsigned integer, with 0 implying the first position.
- VISIBLE: Refers to the visibility of the statusbar or item. If set
+ TYPE: Sets the type of statusbar, for each split window or only
+ for the current root screen.
+ PLACEMENT: Sets the placement of the statusbar, either at the top or
+ the bottom of the screen.
+ POSITION: Sets the position of the statusbar. Represented as a
+ number, with 0 implying the first position.
+ VISIBLE: Sets the visibility of the statusbar or item. If set to
to always it is visible on all screens, otherwise if set
to inactive or active then it is only visible on inactive
or active screens, respectively.
From 4b42eca7c57fdd3d5ded8d5b1d4c75d01fc28569 Mon Sep 17 00:00:00 2001
From: Robert Bisewski
Date: Fri, 6 Oct 2017 07:58:27 -0500
Subject: [PATCH 36/76] minor word correction
---
docs/help/in/statusbar.in | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/help/in/statusbar.in b/docs/help/in/statusbar.in
index 13977891..7d64b816 100644
--- a/docs/help/in/statusbar.in
+++ b/docs/help/in/statusbar.in
@@ -17,8 +17,8 @@
POSITION: Sets the position of the statusbar. Represented as a
number, with 0 implying the first position.
VISIBLE: Sets the visibility of the statusbar or item. If set to
- to always it is visible on all screens, otherwise if set
- to inactive or active then it is only visible on inactive
+ always it is visible on all screens, otherwise if set to
+ inactive or active then it is only visible on inactive
or active screens, respectively.
ADD: Adds an item to the specified statusbar. It can be set to
appear before/after another item and left/right aligned
From 1fd285dccfd43b740e88f7f4e168132387d39843 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Fri, 6 Oct 2017 14:58:47 +0200
Subject: [PATCH 37/76] refactor history to use history_entries list
this allows access to the global history even when a using /window history
named or /set window_history on, and you want to recall something from one
of the other windows' histories.
usage (default): ctrl+up/down
---
src/fe-common/core/command-history.c | 187 +++++++++++++++++++++------
src/fe-common/core/command-history.h | 16 ++-
src/fe-text/gui-readline.c | 28 ++++
src/perl/ui/Window.xs | 5 +-
4 files changed, 196 insertions(+), 40 deletions(-)
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index 55474b1b..5de76969 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -30,10 +30,93 @@
#include "command-history.h"
/* command history */
+static GList *history_entries;
static HISTORY_REC *global_history;
static int window_history;
static GSList *histories;
+static HISTORY_ENTRY_REC *history_entry_new(HISTORY_REC *history, const char *text)
+{
+ HISTORY_ENTRY_REC *entry;
+
+ entry = g_new0(HISTORY_ENTRY_REC, 1);
+ entry->text = g_strdup(text);
+ entry->history = history;
+ entry->time = time(NULL);
+
+ return entry;
+}
+
+static void history_entry_destroy(HISTORY_ENTRY_REC *entry)
+{
+ g_free((char *)entry->text);
+ g_free(entry);
+}
+
+GList *command_history_list_last(HISTORY_REC *history)
+{
+ GList *link;
+
+ link = g_list_last(history_entries);
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->prev;
+ }
+
+ return link;
+}
+
+GList *command_history_list_first(HISTORY_REC *history)
+{
+ GList *link;
+
+ link = history_entries;
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->next;
+ }
+
+ return link;
+}
+
+GList *command_history_list_prev(HISTORY_REC *history, GList *pos)
+{
+ GList *link;
+
+ link = pos != NULL ? pos->prev : NULL;
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->prev;
+ }
+
+ return link;
+}
+
+GList *command_history_list_next(HISTORY_REC *history, GList *pos)
+{
+ GList *link;
+
+ link = pos != NULL ? pos->next : NULL;
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->next;
+ }
+
+ return link;
+}
+
+static void command_history_clear_pos_for_unlink_func(HISTORY_REC *history, GList* link)
+{
+ if (history->pos == link) {
+ history->pos = command_history_list_next(history, link);
+ history->redo = 1;
+ }
+}
+
+static void history_list_delete_link_and_destroy(GList *link)
+{
+ g_slist_foreach(histories,
+ (GFunc) command_history_clear_pos_for_unlink_func, link);
+ history_entry_destroy(link->data);
+ history_entries = g_list_delete_link(history_entries, link);
+}
+
void command_history_add(HISTORY_REC *history, const char *text)
{
GList *link;
@@ -41,21 +124,19 @@ void command_history_add(HISTORY_REC *history, const char *text)
g_return_if_fail(history != NULL);
g_return_if_fail(text != NULL);
- link = g_list_last(history->list);
- if (link != NULL && g_strcmp0(link->data, text) == 0)
- return; /* same as previous entry */
+ link = command_history_list_last(history);
+ if (link != NULL && g_strcmp0(((HISTORY_ENTRY_REC *)link->data)->text, text) == 0)
+ return; /* same as previous entry */
if (settings_get_int("max_command_history") < 1 ||
history->lines < settings_get_int("max_command_history"))
history->lines++;
else {
- link = history->list;
- g_free(link->data);
- history->list = g_list_remove_link(history->list, link);
- g_list_free_1(link);
+ link = command_history_list_first(history);
+ history_list_delete_link_and_destroy(link);
}
- history->list = g_list_append(history->list, g_strdup(text));
+ history_entries = g_list_append(history_entries, history_entry_new(history, text));
}
HISTORY_REC *command_history_find(HISTORY_REC *history)
@@ -104,7 +185,44 @@ HISTORY_REC *command_history_current(WINDOW_REC *window)
return global_history;
}
+static const char *command_history_prev_int(WINDOW_REC *window, const char *text, gboolean global)
+{
+ HISTORY_REC *history;
+ GList *pos;
+
+ history = command_history_current(window);
+ pos = history->pos;
+ history->redo = 0;
+
+ if (pos != NULL) {
+ /* don't go past the first entry (no wrap around) */
+ GList *prev = command_history_list_prev(global ? NULL : history, history->pos);
+ if (prev != NULL)
+ history->pos = prev;
+ } else {
+ history->pos = command_history_list_last(global ? NULL : history);
+ }
+
+ if (*text != '\0' &&
+ (pos == NULL || g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) != 0)) {
+ /* save the old entry to history */
+ command_history_add(history, text);
+ }
+
+ return history->pos == NULL ? text : ((HISTORY_ENTRY_REC *)history->pos->data)->text;
+}
+
const char *command_history_prev(WINDOW_REC *window, const char *text)
+{
+ return command_history_prev_int(window, text, FALSE);
+}
+
+const char *command_global_history_prev(WINDOW_REC *window, const char *text)
+{
+ return command_history_prev_int(window, text, TRUE);
+}
+
+static const char *command_history_next_int(WINDOW_REC *window, const char *text, gboolean global)
{
HISTORY_REC *history;
GList *pos;
@@ -112,40 +230,26 @@ const char *command_history_prev(WINDOW_REC *window, const char *text)
history = command_history_current(window);
pos = history->pos;
- if (pos != NULL) {
- /* don't go past the first entry (no wrap around) */
- if (history->pos->prev != NULL)
- history->pos = history->pos->prev;
- } else {
- history->pos = g_list_last(history->list);
- }
+ if (!(history->redo) && pos != NULL)
+ history->pos = command_history_list_next(global ? NULL : history, history->pos);
+ history->redo = 0;
if (*text != '\0' &&
- (pos == NULL || g_strcmp0(pos->data, text) != 0)) {
+ (pos == NULL || g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) != 0)) {
/* save the old entry to history */
command_history_add(history, text);
}
-
- return history->pos == NULL ? text : history->pos->data;
+ return history->pos == NULL ? "" : ((HISTORY_ENTRY_REC *)history->pos->data)->text;
}
const char *command_history_next(WINDOW_REC *window, const char *text)
{
- HISTORY_REC *history;
- GList *pos;
+ return command_history_next_int(window, text, FALSE);
+}
- history = command_history_current(window);
- pos = history->pos;
-
- if (pos != NULL)
- history->pos = history->pos->next;
-
- if (*text != '\0' &&
- (pos == NULL || g_strcmp0(pos->data, text) != 0)) {
- /* save the old entry to history */
- command_history_add(history, text);
- }
- return history->pos == NULL ? "" : history->pos->data;
+const char *command_global_history_next(WINDOW_REC *window, const char *text)
+{
+ return command_history_next_int(window, text, TRUE);
}
void command_history_clear_pos_func(HISTORY_REC *history, gpointer user_data)
@@ -175,12 +279,17 @@ HISTORY_REC *command_history_create(const char *name)
void command_history_clear(HISTORY_REC *history)
{
+ GList *link, *next;
+
g_return_if_fail(history != NULL);
command_history_clear_pos_func(history, NULL);
- g_list_foreach(history->list, (GFunc) g_free, NULL);
- g_list_free(history->list);
- history->list = NULL;
+ link = command_history_list_first(history);
+ while (link != NULL) {
+ next = command_history_list_next(history, link);
+ history_list_delete_link_and_destroy(link);
+ link = next;
+ }
history->lines = 0;
}
@@ -264,8 +373,8 @@ static char *special_history_func(const char *text, void *item, int *free_ret)
ret = NULL;
history = command_history_current(window);
- for (tmp = history->list; tmp != NULL; tmp = tmp->next) {
- const char *line = tmp->data;
+ for (tmp = command_history_list_first(history); tmp != NULL; tmp = command_history_list_next(history, tmp)) {
+ const char *line = ((HISTORY_ENTRY_REC *)tmp->data)->text;
if (match_wildcards(findtext, line)) {
*free_ret = TRUE;
@@ -289,6 +398,8 @@ void command_history_init(void)
special_history_func_set(special_history_func);
+ history_entries = NULL;
+
global_history = command_history_create(NULL);
read_settings();
@@ -308,4 +419,6 @@ void command_history_deinit(void)
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
command_history_destroy(global_history);
+
+ g_list_free_full(history_entries, (GDestroyNotify) history_entry_destroy);
}
diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h
index 45126092..ddc8f5e6 100644
--- a/src/fe-common/core/command-history.h
+++ b/src/fe-common/core/command-history.h
@@ -6,12 +6,19 @@
typedef struct {
char *name;
- GList *list, *pos;
+ GList *pos;
int lines;
int refcount;
+ int redo:1;
} HISTORY_REC;
+typedef struct {
+ const char *text;
+ HISTORY_REC *history;
+ time_t time;
+} HISTORY_ENTRY_REC;
+
HISTORY_REC *command_history_find(HISTORY_REC *history);
HISTORY_REC *command_history_find_name(const char *name);
@@ -22,8 +29,15 @@ void command_history_deinit(void);
void command_history_add(HISTORY_REC *history, const char *text);
+GList *command_history_list_last(HISTORY_REC *history);
+GList *command_history_list_first(HISTORY_REC *history);
+GList *command_history_list_prev(HISTORY_REC *history, GList *pos);
+GList *command_history_list_next(HISTORY_REC *history, GList *pos);
+
const char *command_history_prev(WINDOW_REC *window, const char *text);
const char *command_history_next(WINDOW_REC *window, const char *text);
+const char *command_global_history_prev(WINDOW_REC *window, const char *text);
+const char *command_global_history_next(WINDOW_REC *window, const char *text);
void command_history_clear_pos(WINDOW_REC *window);
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index 3688f15e..0528ed94 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -530,6 +530,28 @@ static void key_forward_history(void)
g_free(line);
}
+static void key_backward_global_history(void)
+{
+ const char *text;
+ char *line;
+
+ line = gui_entry_get_text(active_entry);
+ text = command_global_history_prev(active_win, line);
+ gui_entry_set_text(active_entry, text);
+ g_free(line);
+}
+
+static void key_forward_global_history(void)
+{
+ const char *text;
+ char *line;
+
+ line = gui_entry_get_text(active_entry);
+ text = command_global_history_next(active_win, line);
+ gui_entry_set_text(active_entry, text);
+ g_free(line);
+}
+
static void key_beginning_of_line(void)
{
gui_entry_set_pos(active_entry, 0);
@@ -1176,6 +1198,8 @@ void gui_readline_init(void)
key_bind("key", NULL, "meta2-5C", "cright", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;5D", "cleft", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;5C", "cright", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-1;5A", "cup", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-1;5B", "cdown", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;3A", "mup", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;3B", "mdown", (SIGNAL_FUNC) key_combo);
@@ -1217,6 +1241,8 @@ void gui_readline_init(void)
/* history */
key_bind("backward_history", "Go back one line in the history", "up", NULL, (SIGNAL_FUNC) key_backward_history);
key_bind("forward_history", "Go forward one line in the history", "down", NULL, (SIGNAL_FUNC) key_forward_history);
+ key_bind("backward_global_history", "Go back one line in the global history", "cup", NULL, (SIGNAL_FUNC) key_backward_global_history);
+ key_bind("forward_global_history", "Go forward one line in the global history", "cdown", NULL, (SIGNAL_FUNC) key_forward_global_history);
/* line editing */
key_bind("backspace", "Delete the previous character", "backspace", NULL, (SIGNAL_FUNC) key_backspace);
@@ -1310,6 +1336,8 @@ void gui_readline_deinit(void)
key_unbind("backward_history", (SIGNAL_FUNC) key_backward_history);
key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history);
+ key_unbind("backward_global_history", (SIGNAL_FUNC) key_backward_global_history);
+ key_unbind("forward_global_history", (SIGNAL_FUNC) key_forward_global_history);
key_unbind("backspace", (SIGNAL_FUNC) key_backspace);
key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character);
diff --git a/src/perl/ui/Window.xs b/src/perl/ui/Window.xs
index 8c994cc2..b8d68ad8 100644
--- a/src/perl/ui/Window.xs
+++ b/src/perl/ui/Window.xs
@@ -252,8 +252,9 @@ PREINIT:
GList *tmp;
PPCODE:
rec = command_history_current(window);
- for (tmp = rec->list; tmp != NULL; tmp = tmp->next)
- XPUSHs(sv_2mortal(new_pv(tmp->data)));
+ for (tmp = command_history_list_first(rec); tmp != NULL; tmp = command_history_list_next(rec, tmp))
+ XPUSHs(sv_2mortal(new_pv(((HISTORY_ENTRY_REC *)tmp->data)->text)));
+
#*******************************
MODULE = Irssi::UI::Window PACKAGE = Irssi::Windowitem PREFIX = window_item_
From 16d68a86ca75b73c53aa81fe6d3d36361cb35b99 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Fri, 6 Oct 2017 15:02:15 +0200
Subject: [PATCH 38/76] add two XSFuncs to manipulate command history entries
it is possible to use Irssi::UI::Window::get_history_entries to save the
history entries, load_history_entries to load entries into the command
history and delete_history_entries to remove history entries (for example
to remove history selectively)
---
src/fe-common/core/command-history.c | 55 +++++++++++
src/fe-common/core/command-history.h | 2 +
src/perl/ui/Window.xs | 139 +++++++++++++++++++++++++++
3 files changed, 196 insertions(+)
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index 5de76969..a6a800d3 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -168,6 +168,61 @@ HISTORY_REC *command_history_find_name(const char *name)
return NULL;
}
+static int history_entry_after_time_sort(const HISTORY_ENTRY_REC *a, const HISTORY_ENTRY_REC *b)
+{
+ return a->time == b->time ? 1 : a->time - b->time;
+}
+
+void command_history_load_entry(time_t history_time, HISTORY_REC *history, const char *text)
+{
+ HISTORY_ENTRY_REC *entry;
+
+ g_return_if_fail(history != NULL);
+ g_return_if_fail(text != NULL);
+
+ entry = g_new0(HISTORY_ENTRY_REC, 1);
+ entry->text = g_strdup(text);
+ entry->history = history;
+ entry->time = history_time;
+
+ history->lines++;
+
+ history_entries = g_list_insert_sorted(history_entries, entry, (GCompareFunc)history_entry_after_time_sort);
+}
+
+static int history_entry_find_func(const HISTORY_ENTRY_REC *data, const HISTORY_ENTRY_REC *user_data)
+{
+ if ((user_data->time == -1 || (data->time == user_data->time)) &&
+ (user_data->history == NULL || (data->history == user_data->history)) &&
+ g_strcmp0(data->text, user_data->text) == 0) {
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+gboolean command_history_delete_entry(time_t history_time, HISTORY_REC *history, const char *text)
+{
+ GList *link;
+ HISTORY_ENTRY_REC entry;
+
+ g_return_val_if_fail(history != NULL, FALSE);
+ g_return_val_if_fail(text != NULL, FALSE);
+
+ entry.text = text;
+ entry.history = history;
+ entry.time = history_time;
+
+ link = g_list_find_custom(history_entries, &entry, (GCompareFunc)history_entry_find_func);
+ if (link != NULL) {
+ ((HISTORY_ENTRY_REC *)link->data)->history->lines--;
+ history_list_delete_link_and_destroy(link);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
HISTORY_REC *command_history_current(WINDOW_REC *window)
{
HISTORY_REC *rec;
diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h
index ddc8f5e6..dc4d46da 100644
--- a/src/fe-common/core/command-history.h
+++ b/src/fe-common/core/command-history.h
@@ -28,6 +28,8 @@ void command_history_init(void);
void command_history_deinit(void);
void command_history_add(HISTORY_REC *history, const char *text);
+void command_history_load_entry(time_t time, HISTORY_REC *history, const char *text);
+gboolean command_history_delete_entry(time_t history_time, HISTORY_REC *history, const char *text);
GList *command_history_list_last(HISTORY_REC *history);
GList *command_history_list_first(HISTORY_REC *history);
diff --git a/src/perl/ui/Window.xs b/src/perl/ui/Window.xs
index b8d68ad8..85e284bb 100644
--- a/src/perl/ui/Window.xs
+++ b/src/perl/ui/Window.xs
@@ -255,6 +255,145 @@ PPCODE:
for (tmp = command_history_list_first(rec); tmp != NULL; tmp = command_history_list_next(rec, tmp))
XPUSHs(sv_2mortal(new_pv(((HISTORY_ENTRY_REC *)tmp->data)->text)));
+void
+window_get_history_entries(window)
+ Irssi::UI::Window window
+PREINIT:
+ HISTORY_REC *rec;
+ HISTORY_ENTRY_REC *ent;
+ WINDOW_REC *win;
+ GList *tmp;
+ GSList *stmp;
+ HV *hv;
+PPCODE:
+ rec = window == NULL ? NULL : command_history_current(window);
+ for (tmp = command_history_list_first(rec); tmp != NULL; tmp = command_history_list_next(rec, tmp)) {
+ hv = (HV*)sv_2mortal((SV*)newHV());
+ ent = tmp->data;
+ hv_store(hv, "text", 4, newSVpv(ent->text, 0), 0);
+ hv_store(hv, "time", 4, newSViv(ent->time), 0);
+ if (ent->history == command_history_current(NULL)) {
+ hv_store(hv, "history", 7, newSV(0), 0);
+ hv_store(hv, "window", 6, newSV(0), 0);
+ } else {
+ if (ent->history->name == NULL) {
+ hv_store(hv, "history", 7, newSV(0), 0);
+ for (stmp = windows; stmp != NULL; stmp = stmp->next) {
+ win = stmp->data;
+ if (win->history == ent->history) {
+ hv_store(hv, "window", 6, newSViv(win->refnum), 0);
+ break;
+ }
+ }
+ } else {
+ hv_store(hv, "history", 7, new_pv(ent->history->name), 0);
+ hv_store(hv, "window", 6, newSV(0), 0);
+ }
+ }
+ XPUSHs(sv_2mortal(newRV_inc((SV*)hv)));
+ }
+
+void
+window_load_history_entries(window, ...)
+ Irssi::UI::Window window
+PREINIT:
+ HV *hv;
+ SV **sv;
+ HISTORY_REC *history;
+ WINDOW_REC *tmp;
+ const char *text;
+ long hist_time;
+ int i;
+PPCODE:
+ for (i = 1; i < items; i++) {
+ if (!is_hvref(ST(i))) {
+ croak("Usage: Irssi::UI::Window::load_history_entries(window, hash...)");
+ }
+ hv = hvref(ST(i));
+ if (hv != NULL) {
+ tmp = NULL;
+ text = NULL;
+ hist_time = time(NULL);
+ history = command_history_current(NULL);
+
+ sv = hv_fetch(hv, "text", 4, 0);
+ if (sv != NULL) text = SvPV_nolen(*sv);
+ sv = hv_fetch(hv, "time", 4, 0);
+ if (sv != NULL && SvOK(*sv)) hist_time = SvIV(*sv);
+
+ if (window != NULL) {
+ history = command_history_current(window);
+ } else {
+ sv = hv_fetch(hv, "history", 7, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ history = command_history_find_name(SvPV_nolen(*sv));
+ }
+
+ sv = hv_fetch(hv, "window", 6, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ tmp = window_find_refnum(SvIV(*sv));
+ if (tmp != NULL) {
+ history = tmp->history;
+ }
+ }
+ }
+
+ if (text != NULL && history != NULL) {
+ command_history_load_entry(hist_time, history, text);
+ }
+ }
+ }
+
+void
+window_delete_history_entries(window, ...)
+ Irssi::UI::Window window
+PREINIT:
+ HV *hv;
+ SV **sv;
+ HISTORY_REC *history;
+ WINDOW_REC *tmp;
+ const char *text;
+ long hist_time;
+ int i;
+PPCODE:
+ for (i = 1; i < items; i++) {
+ if (!is_hvref(ST(i))) {
+ croak("Usage: Irssi::UI::Window::delete_history_entries(window, hash...)");
+ }
+ hv = hvref(ST(i));
+ if (hv != NULL) {
+ tmp = NULL;
+ text = NULL;
+ hist_time = -1;
+ history = command_history_current(NULL);
+
+ sv = hv_fetch(hv, "text", 4, 0);
+ if (sv != NULL) text = SvPV_nolen(*sv);
+ sv = hv_fetch(hv, "time", 4, 0);
+ if (sv != NULL && SvOK(*sv)) hist_time = SvIV(*sv);
+
+ if (window != NULL) {
+ history = command_history_current(window);
+ } else {
+ sv = hv_fetch(hv, "history", 7, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ history = command_history_find_name(SvPV_nolen(*sv));
+ }
+
+ sv = hv_fetch(hv, "window", 6, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ tmp = window_find_refnum(SvIV(*sv));
+ if (tmp != NULL) {
+ history = tmp->history;
+ }
+ }
+ }
+
+ if (text != NULL && history != NULL) {
+ XPUSHs(boolSV(command_history_delete_entry(hist_time, history, text)));
+ }
+ }
+ }
#*******************************
MODULE = Irssi::UI::Window PACKAGE = Irssi::Windowitem PREFIX = window_item_
From deac66f33c0fb1d6914d15ce63bde3f030a9c06d Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Fri, 6 Oct 2017 15:31:52 +0200
Subject: [PATCH 39/76] add a key binding to erase history entries
it is possible to delete the current history entry using the
erase_history_entry key binding
---
src/fe-common/core/command-history.c | 17 +++++++++++++++++
src/fe-common/core/command-history.h | 1 +
src/fe-text/gui-readline.c | 13 +++++++++++++
3 files changed, 31 insertions(+)
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index a6a800d3..32d7adaa 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -307,6 +307,23 @@ const char *command_global_history_next(WINDOW_REC *window, const char *text)
return command_history_next_int(window, text, TRUE);
}
+const char *command_history_delete_current(WINDOW_REC *window, const char *text)
+{
+ HISTORY_REC *history;
+ GList *pos;
+
+ history = command_history_current(window);
+ pos = history->pos;
+
+ if (pos != NULL && g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) == 0) {
+ ((HISTORY_ENTRY_REC *)pos->data)->history->lines--;
+ history_list_delete_link_and_destroy(pos);
+ }
+
+ history->redo = 0;
+ return history->pos == NULL ? "" : ((HISTORY_ENTRY_REC *)history->pos->data)->text;
+}
+
void command_history_clear_pos_func(HISTORY_REC *history, gpointer user_data)
{
history->pos = NULL;
diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h
index dc4d46da..ed093415 100644
--- a/src/fe-common/core/command-history.h
+++ b/src/fe-common/core/command-history.h
@@ -40,6 +40,7 @@ const char *command_history_prev(WINDOW_REC *window, const char *text);
const char *command_history_next(WINDOW_REC *window, const char *text);
const char *command_global_history_prev(WINDOW_REC *window, const char *text);
const char *command_global_history_next(WINDOW_REC *window, const char *text);
+const char *command_history_delete_current(WINDOW_REC *window, const char *text);
void command_history_clear_pos(WINDOW_REC *window);
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index 0528ed94..b3a78396 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -552,6 +552,17 @@ static void key_forward_global_history(void)
g_free(line);
}
+static void key_erase_history_entry(void)
+{
+ const char *text;
+ char *line;
+
+ line = gui_entry_get_text(active_entry);
+ text = command_history_delete_current(active_win, line);
+ gui_entry_set_text(active_entry, text);
+ g_free(line);
+}
+
static void key_beginning_of_line(void)
{
gui_entry_set_pos(active_entry, 0);
@@ -1243,6 +1254,7 @@ void gui_readline_init(void)
key_bind("forward_history", "Go forward one line in the history", "down", NULL, (SIGNAL_FUNC) key_forward_history);
key_bind("backward_global_history", "Go back one line in the global history", "cup", NULL, (SIGNAL_FUNC) key_backward_global_history);
key_bind("forward_global_history", "Go forward one line in the global history", "cdown", NULL, (SIGNAL_FUNC) key_forward_global_history);
+ key_bind("erase_history_entry", "Erase the currently active entry from the history", NULL, NULL, (SIGNAL_FUNC) key_erase_history_entry);
/* line editing */
key_bind("backspace", "Delete the previous character", "backspace", NULL, (SIGNAL_FUNC) key_backspace);
@@ -1338,6 +1350,7 @@ void gui_readline_deinit(void)
key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history);
key_unbind("backward_global_history", (SIGNAL_FUNC) key_backward_global_history);
key_unbind("forward_global_history", (SIGNAL_FUNC) key_forward_global_history);
+ key_unbind("erase_history_entry", (SIGNAL_FUNC) key_erase_history_entry);
key_unbind("backspace", (SIGNAL_FUNC) key_backspace);
key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character);
From 5da0b73a12b3b319a2c7d6b18657ec13d52b6476 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Fri, 6 Oct 2017 15:31:59 +0200
Subject: [PATCH 40/76] up abi
---
src/common.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/common.h b/src/common.h
index 159f7124..a7eaa7cf 100644
--- a/src/common.h
+++ b/src/common.h
@@ -6,7 +6,7 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
-#define IRSSI_ABI_VERSION 11
+#define IRSSI_ABI_VERSION 12
#define DEFAULT_SERVER_ADD_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697
From 40ae8f5fa67cb7ec529f9fea5816fb8804c9bba8 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Sat, 7 Oct 2017 03:28:02 +0100
Subject: [PATCH 41/76] Limit capsicum rights to stdio.
This requires FreeBSD fix (https://reviews.freebsd.org/D12622)
to work properly.
---
src/core/capsicum.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 3b0708cb..1c5c59da 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -37,6 +37,7 @@
#include
#include
#include
+#include
#include
#define OPCODE_CONNECT 1
@@ -410,6 +411,13 @@ static void cmd_capsicum_enter(void)
*/
signal(SIGCHLD, SIG_IGN);
+ error = caph_limit_stdio();
+ if (error != 0) {
+ g_warning("caph_limit_stdio(3) failed: %s", strerror(errno));
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
error = cap_enter();
if (error != 0) {
signal_emit("capability mode failed", 1, strerror(errno));
From 00c80cb6fcca40cfc421fe3fc181115ac4907191 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Sat, 7 Oct 2017 20:45:13 +0200
Subject: [PATCH 42/76] fix out of bounds read in compress_colors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reported by Hanno Böck.
Fixes GL#12
---
src/fe-common/core/themes.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c
index 2b1459be..cb1cce8f 100644
--- a/src/fe-common/core/themes.c
+++ b/src/fe-common/core/themes.c
@@ -587,7 +587,7 @@ static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
/* a normal character */
g_string_append_c(str, *format);
format++;
- } else {
+ } else if (format[1] != '\0') {
/* %format */
format++;
if (IS_OLD_FORMAT(*format, last_fg, last_bg)) {
@@ -614,6 +614,11 @@ static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
last_bg = '\0';
}
format++;
+ } else {
+ /* % at end of string */
+ format++;
+ g_string_append_c(str, '%');
+ g_string_append_c(str, '%');
}
}
From 49ace3251b79a9e97c6e4d0bc640f9143dc71b90 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Sun, 8 Oct 2017 19:47:50 +0200
Subject: [PATCH 43/76] fix uaf in chanquery module
the chanquery needs to be removed in any case if a channel rec is
destroyed, regardless of any state
Fixes GL#13
---
src/irc/core/channels-query.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/irc/core/channels-query.c b/src/irc/core/channels-query.c
index 857ebaf0..d161aec1 100644
--- a/src/irc/core/channels-query.c
+++ b/src/irc/core/channels-query.c
@@ -125,15 +125,15 @@ static void query_remove_all(IRC_CHANNEL_REC *channel)
rec->queries[n] = g_slist_remove(rec->queries[n], channel);
rec->current_queries = g_slist_remove(rec->current_queries, channel);
- query_check(channel->server);
+ if (!channel->server->disconnected)
+ query_check(channel->server);
}
static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
{
g_return_if_fail(channel != NULL);
- if (IS_IRC_CHANNEL(channel) && !channel->server->disconnected &&
- !channel->synced)
+ if (IS_IRC_CHANNEL(channel))
query_remove_all(channel);
}
From 2edd816e7db13b4ac0b20df9bf7fe55ee7718215 Mon Sep 17 00:00:00 2001
From: Joseph Bisch
Date: Sun, 8 Oct 2017 22:02:44 -0400
Subject: [PATCH 44/76] Fix segfault in query_remove_all
It is possible for rec to be NULL in query_remove_all, resulting in a
segfault. So return without doing anything if rec is NULL.
---
src/irc/core/channels-query.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/irc/core/channels-query.c b/src/irc/core/channels-query.c
index d161aec1..d7dadf04 100644
--- a/src/irc/core/channels-query.c
+++ b/src/irc/core/channels-query.c
@@ -119,6 +119,7 @@ static void query_remove_all(IRC_CHANNEL_REC *channel)
int n;
rec = channel->server->chanqueries;
+ if (rec == NULL) return;
/* remove channel from query lists */
for (n = 0; n < CHANNEL_QUERIES; n++)
From 4ccff71f678f79da71713a29d8528812379bb584 Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Mon, 9 Oct 2017 12:50:04 -0700
Subject: [PATCH 45/76] Set host to an empty string on error
While investigating #317, I noticed that it was possible we would access
an uninitialized buffer due to failing to check the return value of
net_ip2host(). This is done in several places. To make such uses safe,
set the host buffer to an empty string on error. It is possible callers
could be improved by handling the error in each spot, but this gives us
some safety.
---
src/core/network.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/core/network.c b/src/core/network.c
index 4494dbc6..8d9c6b06 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -489,7 +489,16 @@ int net_gethostbyaddr(IPADDR *ip, char **name)
int net_ip2host(IPADDR *ip, char *host)
{
- return inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN) ? 0 : -1;
+ if (inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN)) {
+ return 0;
+ }
+
+ // For callers that do not check our return value and pass in an
+ // uninitialized buffer assuming it will be set, ensure the buffer is a valid
+ // string. Ideally callers should check what we return and handle
+ // appropriately, but this at least gives us safety.
+ host[0] = '\0';
+ return -1;
}
int net_host2ip(const char *host, IPADDR *ip)
From cb5f3cba1f2b5dbad67bcc107f3fe4a1875cc52d Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Mon, 9 Oct 2017 13:14:34 -0700
Subject: [PATCH 46/76] Delete unused function net_ip_compare()
---
src/core/network.c | 12 ------------
src/core/network.h | 3 ---
2 files changed, 15 deletions(-)
diff --git a/src/core/network.c b/src/core/network.c
index 4494dbc6..36e04c7a 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -60,18 +60,6 @@ IPADDR ip4_any = {
#endif
};
-int net_ip_compare(IPADDR *ip1, IPADDR *ip2)
-{
- if (ip1->family != ip2->family)
- return 0;
-
- if (ip1->family == AF_INET6)
- return memcmp(&ip1->ip, &ip2->ip, sizeof(ip1->ip)) == 0;
-
- return memcmp(&ip1->ip, &ip2->ip, 4) == 0;
-}
-
-
static void sin_set_ip(union sockaddr_union *so, const IPADDR *ip)
{
if (ip == NULL) {
diff --git a/src/core/network.h b/src/core/network.h
index d1582a2e..471ab2d8 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -33,9 +33,6 @@ extern IPADDR ip4_any;
GIOChannel *g_io_channel_new(int handle);
-/* returns 1 if IPADDRs are the same */
-int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
-
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
/* Connect to socket */
From 3b3939b146bb2f80182d572a2afc08ba405037a1 Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Mon, 9 Oct 2017 13:14:59 -0700
Subject: [PATCH 47/76] Delete commented out CYGWIN define
---
src/core/network.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/core/network.c b/src/core/network.c
index 36e04c7a..38f4e65a 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -48,9 +48,6 @@ GIOChannel *g_io_channel_new(int handle)
return chan;
}
-/* Cygwin need this, don't know others.. */
-/*#define BLOCKING_SOCKETS 1*/
-
IPADDR ip4_any = {
AF_INET,
#if defined(IN6ADDR_ANY_INIT)
From b8b90c76d4ea87d7e50c2a34fbc36ab732e3e89e Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Mon, 9 Oct 2017 13:20:44 -0700
Subject: [PATCH 48/76] Delete unused function net_connect()
---
src/core/network.c | 34 ----------------------------------
src/core/network.h | 2 --
2 files changed, 36 deletions(-)
diff --git a/src/core/network.c b/src/core/network.c
index 38f4e65a..52619e4f 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -98,40 +98,6 @@ static int sin_get_port(union sockaddr_union *so)
so->sin.sin_port);
}
-/* Connect to socket */
-GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip)
-{
- IPADDR ip4, ip6, *ip;
-
- g_return_val_if_fail(addr != NULL, NULL);
-
- if (net_gethostbyname(addr, &ip4, &ip6) == -1)
- return NULL;
-
- if (my_ip == NULL) {
- /* prefer IPv4 addresses */
- ip = ip4.family != 0 ? &ip4 : &ip6;
- } else if (IPADDR_IS_V6(my_ip)) {
- /* my_ip is IPv6 address, use it if possible */
- if (ip6.family != 0)
- ip = &ip6;
- else {
- my_ip = NULL;
- ip = &ip4;
- }
- } else {
- /* my_ip is IPv4 address, use it if possible */
- if (ip4.family != 0)
- ip = &ip4;
- else {
- my_ip = NULL;
- ip = &ip6;
- }
- }
-
- return net_connect_ip(ip, port, my_ip);
-}
-
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip)
{
union sockaddr_union so;
diff --git a/src/core/network.h b/src/core/network.h
index 471ab2d8..a02f0db9 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -35,8 +35,6 @@ GIOChannel *g_io_channel_new(int handle);
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
-/* Connect to socket */
-GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip) G_GNUC_DEPRECATED;
/* Connect to socket with ip address and SSL*/
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server);
/* Start TLS */
From 174adee9dd91c23615f79b979b3b3c5f72ad1240 Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Tue, 10 Oct 2017 18:21:05 -0700
Subject: [PATCH 49/76] Always initialize the host string
This also removes a wordy comment
---
src/core/network.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/core/network.c b/src/core/network.c
index 8d9c6b06..b38c9102 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -489,16 +489,8 @@ int net_gethostbyaddr(IPADDR *ip, char **name)
int net_ip2host(IPADDR *ip, char *host)
{
- if (inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN)) {
- return 0;
- }
-
- // For callers that do not check our return value and pass in an
- // uninitialized buffer assuming it will be set, ensure the buffer is a valid
- // string. Ideally callers should check what we return and handle
- // appropriately, but this at least gives us safety.
host[0] = '\0';
- return -1;
+ return inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN) ? 0 : -1;
}
int net_host2ip(const char *host, IPADDR *ip)
From 17b195021dc35b95b24c1cce6f2e891e0e6b85ec Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 11 Oct 2017 14:34:38 +0100
Subject: [PATCH 50/76] Bump default capsicum_port_max to 9999.
This is needed for servers like ssl.efnet.org, which, per default
config, listen on 9999.
---
src/core/capsicum.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 1c5c59da..945d3197 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -452,7 +452,7 @@ void capsicum_init(void)
settings_add_bool("misc", "capsicum", FALSE);
settings_add_str("misc", "capsicum_irclogs_path", "~/irclogs");
settings_add_int("misc", "capsicum_port_min", 6667);
- settings_add_int("misc", "capsicum_port_max", 6697);
+ settings_add_int("misc", "capsicum_port_max", 9999);
signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
From 87955b69cb82314becf1aa9f66c707705f517d0f Mon Sep 17 00:00:00 2001
From: Paul Townsend
Date: Wed, 11 Oct 2017 21:33:14 +0100
Subject: [PATCH 51/76] Add alternate_nick as a network-specific property.
---
docs/help/in/network.in | 1 +
src/core/chatnet-rec.h | 1 +
src/fe-common/irc/fe-ircnet.c | 11 ++++++++---
src/irc/core/irc-servers-setup.c | 9 ++++++++-
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/docs/help/in/network.in b/docs/help/in/network.in
index 4c2eeed4..fbdaa0b4 100644
--- a/docs/help/in/network.in
+++ b/docs/help/in/network.in
@@ -11,6 +11,7 @@
REMOVE: Removes a network from your configuration.
-nick: Specifies the nickname to use.
+ -alternate_nick Specifies the alternate nickname to use.
-user: Specifies the user identity to use.
-realname: Specifies the real name to use.
-host: Specifies the hostname to use.
diff --git a/src/core/chatnet-rec.h b/src/core/chatnet-rec.h
index e3ed8aa0..96ef6914 100644
--- a/src/core/chatnet-rec.h
+++ b/src/core/chatnet-rec.h
@@ -4,6 +4,7 @@ int chat_type; /* chat_protocol_lookup(xx) */
char *name;
char *nick;
+char *alternate_nick;
char *username;
char *realname;
diff --git a/src/fe-common/irc/fe-ircnet.c b/src/fe-common/irc/fe-ircnet.c
index 24dad63f..8f1d2efd 100644
--- a/src/fe-common/irc/fe-ircnet.c
+++ b/src/fe-common/irc/fe-ircnet.c
@@ -48,6 +48,8 @@ static void cmd_network_list(void)
g_string_truncate(str, 0);
if (rec->nick != NULL)
g_string_append_printf(str, "nick: %s, ", rec->nick);
+ if (rec->alternate_nick != NULL)
+ g_string_append_printf(str, "alternate_nick: %s, ", rec->alternate_nick);
if (rec->username != NULL)
g_string_append_printf(str, "username: %s, ", rec->username);
if (rec->realname != NULL)
@@ -114,6 +116,7 @@ static void cmd_network_add_modify(const char *data, gboolean add)
rec->name = g_strdup(name);
} else {
if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
+ if (g_hash_table_lookup(optlist, "alternate_nick")) g_free_and_null(rec->alternate_nick);
if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
if (g_hash_table_lookup(optlist, "host")) {
@@ -145,6 +148,8 @@ static void cmd_network_add_modify(const char *data, gboolean add)
value = g_hash_table_lookup(optlist, "nick");
if (value != NULL && *value != '\0') rec->nick = g_strdup(value);
+ value = g_hash_table_lookup(optlist, "alternate_nick");
+ if (value != NULL && *value != '\0') rec->alternate_nick = g_strdup(value);
value = g_hash_table_lookup(optlist, "user");
if (value != NULL && *value != '\0') rec->username = g_strdup(value);
value = g_hash_table_lookup(optlist, "realname");
@@ -175,7 +180,7 @@ static void cmd_network_add_modify(const char *data, gboolean add)
cmd_params_free(free_arg);
}
-/* SYNTAX: NETWORK ADD|MODIFY [-nick ] [-user ] [-realname ]
+/* SYNTAX: NETWORK ADD|MODIFY [-nick ] [-alternate_nick ] [-user ] [-realname ]
[-host ] [-usermode ] [-autosendcmd ]
[-querychans ] [-whois ] [-msgs ]
[-kicks ] [-modes ] [-cmdspeed ]
@@ -228,9 +233,9 @@ void fe_ircnet_init(void)
command_bind("network remove", NULL, (SIGNAL_FUNC) cmd_network_remove);
command_set_options("network add", "-kicks -msgs -modes -whois -cmdspeed "
- "-cmdmax -nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
+ "-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
command_set_options("network modify", "-kicks -msgs -modes -whois -cmdspeed "
- "-cmdmax -nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
+ "-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
}
void fe_ircnet_deinit(void)
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index 6040d3a5..a51ce2e2 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -69,7 +69,14 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
return;
g_return_if_fail(IS_IRCNET(ircnet));
- if (ircnet->nick != NULL) g_free_and_null(conn->alternate_nick);
+ if (ircnet->nick != NULL) {
+ g_free_and_null(conn->nick);
+ conn->nick = g_strdup(ircnet->nick);
+ }
+ if (ircnet->alternate_nick != NULL) {
+ g_free_and_null(conn->alternate_nick);
+ conn->alternate_nick = g_strdup(ircnet->alternate_nick);
+ }
if (ircnet->usermode != NULL) {
g_free_and_null(conn->usermode);
conn->usermode = g_strdup(ircnet->usermode);
From 1e66cbd62e231f8ae47589cf4f1c0c6c62bb7ca8 Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 11 Oct 2017 23:13:06 +0100
Subject: [PATCH 52/76] Improve Capsicum stdio limits to fix terminal state on
exit.
---
src/core/capsicum.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 945d3197..5f2556ab 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -360,6 +360,38 @@ static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
command_runsub("capsicum", data, server, item);
}
+/*
+ * The main difference between this and caph_limit_stdio(3) is that this
+ * one permits TIOCSETAW, which is requred for restoring the terminal state
+ * on exit.
+ */
+static int
+limit_stdio_fd(int fd)
+{
+ cap_rights_t rights;
+ unsigned long cmds[] = { TIOCGETA, TIOCGWINSZ, TIOCSETAW, FIODTYPE };
+
+ cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT, CAP_FCNTL,
+ CAP_FSTAT, CAP_IOCTL, CAP_SEEK);
+
+ if (cap_rights_limit(fd, &rights) < 0) {
+ g_warning("cap_rights_limit(3) failed: %s", strerror(errno));
+ return (-1);
+ }
+
+ if (cap_ioctls_limit(fd, cmds, nitems(cmds)) < 0) {
+ g_warning("cap_ioctls_limit(3) failed: %s", strerror(errno));
+ return (-1);
+ }
+
+ if (cap_fcntls_limit(fd, CAP_FCNTL_GETFL) < 0) {
+ g_warning("cap_fcntls_limit(3) failed: %s", strerror(errno));
+ return (-1);
+ }
+
+ return (0);
+}
+
static void cmd_capsicum_enter(void)
{
u_int mode;
@@ -411,9 +443,9 @@ static void cmd_capsicum_enter(void)
*/
signal(SIGCHLD, SIG_IGN);
- error = caph_limit_stdio();
- if (error != 0) {
- g_warning("caph_limit_stdio(3) failed: %s", strerror(errno));
+ if (limit_stdio_fd(STDIN_FILENO) != 0 ||
+ limit_stdio_fd(STDOUT_FILENO) != 0 ||
+ limit_stdio_fd(STDERR_FILENO) != 0) {
signal_emit("capability mode failed", 1, strerror(errno));
return;
}
From 5c0b4aeb0572827877654b65bb05fb7b37a3117a Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 11 Oct 2017 23:31:26 +0100
Subject: [PATCH 53/76] Sort Capsicum headers.
---
src/core/capsicum.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 5f2556ab..5647a302 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -32,13 +32,14 @@
#include "settings.h"
#include "signals.h"
-#include
+#include
#include
+#include
#include
#include
#include
-#include
#include
+#include
#define OPCODE_CONNECT 1
#define OPCODE_GETHOSTBYNAME 2
From 9895e7b28a3767bbe4430cbffd3662b4ef92b37f Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 11 Oct 2017 23:52:36 +0100
Subject: [PATCH 54/76] Silence down a warning that would appear on "/away" in
Capability mode.
---
src/core/capsicum.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
index 5647a302..568b5542 100644
--- a/src/core/capsicum.c
+++ b/src/core/capsicum.c
@@ -183,6 +183,10 @@ void capsicum_mkdir_with_parents(const char *path, int mode)
char *component, *copy, *tofree;
int error, fd, newfd;
+ /* The directory already exists, nothing to do. */
+ if (strcmp(path, irclogs_path) == 0)
+ return;
+
/* +1 is for the slash separating irclogs_path and the rest. */
if (strlen(path) <= irclogs_path_len + 1 ||
path[irclogs_path_len] != '/' ||
From 711b2d7df7da4a3010214909ed1b260c55f6befa Mon Sep 17 00:00:00 2001
From: Edward Tomasz Napierala
Date: Wed, 11 Oct 2017 23:53:41 +0100
Subject: [PATCH 55/76] Document that one needs to change the awaylog_file path
for "/away" to work with Capsicum.
---
docs/capsicum.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/capsicum.txt b/docs/capsicum.txt
index 3093bfe5..a3a1b8a7 100644
--- a/docs/capsicum.txt
+++ b/docs/capsicum.txt
@@ -7,6 +7,7 @@ or the libraries it depends on.
To make Irssi enter capability mode on startup, add
capsicum = "yes";
+awaylog_file = "~/irclogs/away.log";
to your ~/.irssi/config and restart the client. Alternatively you can
enter it "by hand", using the "/capsicum enter" command. From the security
From da59fd7c2dd0641f623db2c67a244ddca3013d65 Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Fri, 13 Oct 2017 18:28:26 -0700
Subject: [PATCH 56/76] Revert "Delete unused function net_ip_compare()"
This reverts commit cb5f3cba1f2b5dbad67bcc107f3fe4a1875cc52d.
---
src/core/network.c | 12 ++++++++++++
src/core/network.h | 3 +++
2 files changed, 15 insertions(+)
diff --git a/src/core/network.c b/src/core/network.c
index 52619e4f..4963a542 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -57,6 +57,18 @@ IPADDR ip4_any = {
#endif
};
+int net_ip_compare(IPADDR *ip1, IPADDR *ip2)
+{
+ if (ip1->family != ip2->family)
+ return 0;
+
+ if (ip1->family == AF_INET6)
+ return memcmp(&ip1->ip, &ip2->ip, sizeof(ip1->ip)) == 0;
+
+ return memcmp(&ip1->ip, &ip2->ip, 4) == 0;
+}
+
+
static void sin_set_ip(union sockaddr_union *so, const IPADDR *ip)
{
if (ip == NULL) {
diff --git a/src/core/network.h b/src/core/network.h
index a02f0db9..84f3a56c 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -33,6 +33,9 @@ extern IPADDR ip4_any;
GIOChannel *g_io_channel_new(int handle);
+/* returns 1 if IPADDRs are the same */
+int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
+
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
/* Connect to socket with ip address and SSL*/
From 233be9f580290ff3efa66e6256e46303b01781da Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Fri, 13 Oct 2017 18:30:57 -0700
Subject: [PATCH 57/76] Mark net_ip_compare() deprecated
---
src/core/network.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/core/network.h b/src/core/network.h
index 84f3a56c..e60f607f 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -33,8 +33,9 @@ extern IPADDR ip4_any;
GIOChannel *g_io_channel_new(int handle);
-/* returns 1 if IPADDRs are the same */
-int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
+/* Returns 1 if IPADDRs are the same. */
+/* Deprecated since it is unused. It will be deleted in a later release. */
+int net_ip_compare(IPADDR *ip1, IPADDR *ip2) G_GNUC_DEPRECATED;
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
From 7b94015f8f3a7f9f9348a57243632a98cb5e2a56 Mon Sep 17 00:00:00 2001
From: Paul Townsend
Date: Sat, 14 Oct 2017 17:42:45 +0100
Subject: [PATCH 58/76] Changes based on comments in pull #771.
---
src/core/chatnet-rec.h | 1 -
src/irc/core/irc-chatnets.c | 7 +++++++
src/irc/core/irc-chatnets.h | 1 +
src/irc/core/irc-servers-setup.c | 4 ----
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/core/chatnet-rec.h b/src/core/chatnet-rec.h
index 96ef6914..e3ed8aa0 100644
--- a/src/core/chatnet-rec.h
+++ b/src/core/chatnet-rec.h
@@ -4,7 +4,6 @@ int chat_type; /* chat_protocol_lookup(xx) */
char *name;
char *nick;
-char *alternate_nick;
char *username;
char *realname;
diff --git a/src/irc/core/irc-chatnets.c b/src/irc/core/irc-chatnets.c
index 0796e0cb..98ce89c3 100644
--- a/src/irc/core/irc-chatnets.c
+++ b/src/irc/core/irc-chatnets.c
@@ -43,6 +43,9 @@ static void sig_chatnet_read(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
value = config_node_get_str(node, "usermode", NULL);
rec->usermode = (value != NULL && *value != '\0') ? g_strdup(value) : NULL;
+ value = config_node_get_str(node, "alternate_nick", NULL);
+ rec->alternate_nick = (value != NULL && *value != '\0') ? g_strdup(value) : NULL;
+
rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);
rec->max_query_chans = config_node_get_int(node, "max_query_chans", 0);
@@ -65,6 +68,9 @@ static void sig_chatnet_saved(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
if (rec->usermode != NULL)
iconfig_node_set_str(node, "usermode", rec->usermode);
+ if (rec->alternate_nick != NULL)
+ iconfig_node_set_str(node, "alternate_nick", rec->alternate_nick);
+
if (rec->max_cmds_at_once > 0)
iconfig_node_set_int(node, "cmdmax", rec->max_cmds_at_once);
if (rec->cmd_queue_speed > 0)
@@ -93,6 +99,7 @@ static void sig_chatnet_destroyed(IRC_CHATNET_REC *rec)
{
if (IS_IRC_CHATNET(rec)) {
g_free(rec->usermode);
+ g_free(rec->alternate_nick);
g_free(rec->sasl_mechanism);
g_free(rec->sasl_username);
g_free(rec->sasl_password);
diff --git a/src/irc/core/irc-chatnets.h b/src/irc/core/irc-chatnets.h
index 2bb10fa9..3fd44472 100644
--- a/src/irc/core/irc-chatnets.h
+++ b/src/irc/core/irc-chatnets.h
@@ -18,6 +18,7 @@ struct _IRC_CHATNET_REC {
#include "chatnet-rec.h"
char *usermode;
+ char *alternate_nick;
char *sasl_mechanism;
char *sasl_username;
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index a51ce2e2..bae7d3b4 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -69,10 +69,6 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
return;
g_return_if_fail(IS_IRCNET(ircnet));
- if (ircnet->nick != NULL) {
- g_free_and_null(conn->nick);
- conn->nick = g_strdup(ircnet->nick);
- }
if (ircnet->alternate_nick != NULL) {
g_free_and_null(conn->alternate_nick);
conn->alternate_nick = g_strdup(ircnet->alternate_nick);
From 45dfe2ba3889c5dc23a9bea3214f158cc651a043 Mon Sep 17 00:00:00 2001
From: LemonBoy
Date: Thu, 19 Oct 2017 11:17:56 +0200
Subject: [PATCH 59/76] Prevent a OOB read when parsing IRCNet ! channels
Make sure the string has enough data.
Fixes #16
---
src/irc/core/channel-events.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c
index 6cb9b088..b0bddab2 100644
--- a/src/irc/core/channel-events.c
+++ b/src/irc/core/channel-events.c
@@ -37,7 +37,7 @@ static void check_join_failure(IRC_SERVER_REC *server, const char *channel)
channel++; /* server didn't understand !channels */
chanrec = channel_find(SERVER(server), channel);
- if (chanrec == NULL && channel[0] == '!') {
+ if (chanrec == NULL && channel[0] == '!' && strlen(channel) > 6) {
/* it probably replied with the full !channel name,
find the channel with the short name.. */
chan2 = g_strdup_printf("!%s", channel+6);
From 9f0dc4766c7aa80e34aa2cde94323fb49971abdf Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Fri, 13 Oct 2017 17:54:57 +0200
Subject: [PATCH 60/76] fix dcc issue
---
src/irc/dcc/dcc-chat.c | 21 +++++++++++++++++++++
src/irc/dcc/dcc-get.c | 17 +++++++++++++++--
src/irc/dcc/dcc-send.c | 10 ++++++++++
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c
index ca90b8d8..88c577f7 100644
--- a/src/irc/dcc/dcc-chat.c
+++ b/src/irc/dcc/dcc-chat.c
@@ -66,6 +66,13 @@ CHAT_DCC_REC *dcc_chat_create(IRC_SERVER_REC *server,
dcc->id = dcc_chat_get_new_id(nick);
dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ if (dcc->module_data == NULL) {
+ /* failed to successfully init; TODO: change init_rec API */
+ g_free(dcc->id);
+ g_free(dcc);
+ return NULL;
+ }
+
return dcc;
}
@@ -471,6 +478,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
/* We are accepting a passive DCC CHAT. */
dcc_chat_passive(dcc);
}
+ cmd_params_free(free_arg);
return;
}
@@ -485,6 +493,11 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
cmd_param_error(CMDERR_NOT_CONNECTED);
dcc = dcc_chat_create(server, NULL, nick, "chat");
+ if (dcc == NULL) {
+ cmd_params_free(free_arg);
+ g_warn_if_reached();
+ return;
+ }
if (g_hash_table_lookup(optlist, "passive") == NULL) {
/* Standard DCC CHAT... let's listen for incoming connections */
@@ -627,6 +640,9 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
}
passive = paramcount == 4 && g_strcmp0(params[2], "0") == 0;
+ if (nick == NULL)
+ nick = "";
+
dcc = DCC_CHAT(dcc_find_request(DCC_CHAT_TYPE, nick, NULL));
if (dcc != NULL) {
if (dcc_is_listening(dcc)) {
@@ -658,6 +674,11 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
}
dcc = dcc_chat_create(server, chat, nick, params[0]);
+ if (dcc == NULL) {
+ g_strfreev(params);
+ g_warn_if_reached();
+ return;
+ }
dcc->target = g_strdup(target);
dcc->port = atoi(params[2]);
diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c
index 107f68fa..cecbb076 100644
--- a/src/irc/dcc/dcc-get.c
+++ b/src/irc/dcc/dcc-get.c
@@ -43,6 +43,12 @@ GET_DCC_REC *dcc_get_create(IRC_SERVER_REC *server, CHAT_DCC_REC *chat,
dcc->fhandle = -1;
dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ if (dcc->module_data == NULL) {
+ /* failed to successfully init; TODO: change API */
+ g_free(dcc);
+ return NULL;
+ }
+
return dcc;
}
@@ -430,9 +436,10 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
int p_id = -1;
int passive = FALSE;
- if (addr == NULL) {
+ if (addr == NULL)
addr = "";
- }
+ if (nick == NULL)
+ nick = "";
/* SEND [...] */
/* SEND 0 (DCC SEND passive protocol) */
@@ -512,6 +519,12 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
dcc_destroy(DCC(dcc)); /* remove the old DCC */
dcc = dcc_get_create(server, chat, nick, fname);
+ if (dcc == NULL) {
+ g_free(address);
+ g_free(fname);
+ g_warn_if_reached();
+ return;
+ }
dcc->target = g_strdup(target);
if (passive && port == 0)
diff --git a/src/irc/dcc/dcc-send.c b/src/irc/dcc/dcc-send.c
index ca29b9b9..912129b7 100644
--- a/src/irc/dcc/dcc-send.c
+++ b/src/irc/dcc/dcc-send.c
@@ -237,6 +237,12 @@ static SEND_DCC_REC *dcc_send_create(IRC_SERVER_REC *server,
dcc->queue = -1;
dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ if (dcc->module_data == NULL) {
+ /* failed to successfully init; TODO: change API */
+ g_free(dcc);
+ return NULL;
+ }
+
return dcc;
}
@@ -417,6 +423,10 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
dcc = dcc_send_create(server, chat, target, str);
g_free(str);
+ if (dcc == NULL) {
+ g_warn_if_reached();
+ return FALSE;
+ }
dcc->handle = handle;
dcc->port = port;
From 73d7b9d7753d35c63f24defe6d26c7c06ffa3cce Mon Sep 17 00:00:00 2001
From: Joseph Bisch
Date: Mon, 16 Oct 2017 16:21:10 -0400
Subject: [PATCH 61/76] Don't proceed with cmd_msg if there was an error
splitting msg
There may be cases (such as if target or server->nick is very long)
where the split_message function returns NULL, indicating an error. To
avoid a potential segfault, we now check to see if splitmsgs is NULL.
---
src/core/chat-commands.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c
index d5a133f8..77f02aa2 100644
--- a/src/core/chat-commands.c
+++ b/src/core/chat-commands.c
@@ -404,7 +404,10 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
else
splitmsgs = singlemsg;
- while ((m = splitmsgs[n++])) {
+ /* splitmsgs may be NULL if there was an error */
+ g_warn_if_fail(splitmsgs != NULL);
+
+ while (splitmsgs && (m = splitmsgs[n++])) {
signal_emit("server sendmsg", 4, server, target, m,
GINT_TO_POINTER(target_type));
signal_emit(target_type == SEND_TARGET_CHANNEL ?
From beb2beba3b4802c6969a5595197e25e7a5483fa3 Mon Sep 17 00:00:00 2001
From: Joseph Bisch
Date: Wed, 18 Oct 2017 14:33:02 -0400
Subject: [PATCH 62/76] Revert "Don't proceed with cmd_msg if there was an
error splitting msg"
This reverts commit bd83852d646de28f2e0fe01efe7c9236aa4074d4.
---
src/core/chat-commands.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c
index 77f02aa2..d5a133f8 100644
--- a/src/core/chat-commands.c
+++ b/src/core/chat-commands.c
@@ -404,10 +404,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
else
splitmsgs = singlemsg;
- /* splitmsgs may be NULL if there was an error */
- g_warn_if_fail(splitmsgs != NULL);
-
- while (splitmsgs && (m = splitmsgs[n++])) {
+ while ((m = splitmsgs[n++])) {
signal_emit("server sendmsg", 4, server, target, m,
GINT_TO_POINTER(target_type));
signal_emit(target_type == SEND_TARGET_CHANNEL ?
From 0840eaec7bf56740029aae614e393f8cf76f6946 Mon Sep 17 00:00:00 2001
From: Joseph Bisch
Date: Wed, 18 Oct 2017 14:52:04 -0400
Subject: [PATCH 63/76] Make split functions return an array with NULL instead
of NULL
This avoids undefined behavior in functions that call these split
functions and expect an array back instead of just a NULL pointer.
---
src/core/recode.c | 7 ++++++-
src/irc/core/irc-servers.c | 5 ++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/core/recode.c b/src/core/recode.c
index d001a46a..d3fc91e7 100644
--- a/src/core/recode.c
+++ b/src/core/recode.c
@@ -198,7 +198,12 @@ char **recode_split(const SERVER_REC *server, const char *str,
int n = 0;
char **ret;
- g_return_val_if_fail(str != NULL, NULL);
+ g_warn_if_fail(str != NULL);
+ if (str == NULL) {
+ ret = g_new(char *, 1);
+ ret[0] = NULL;
+ return ret;
+ }
if (settings_get_bool("recode")) {
to = find_conversion(server, target);
diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c
index 3117e345..4eaab712 100644
--- a/src/irc/core/irc-servers.c
+++ b/src/irc/core/irc-servers.c
@@ -116,11 +116,14 @@ static char **split_line(const SERVER_REC *server, const char *line,
* the code much simpler. It's worth it.
*/
len -= strlen(recoded_start) + strlen(recoded_end);
+ g_warn_if_fail(len > 0);
if (len <= 0) {
/* There is no room for anything. */
g_free(recoded_start);
g_free(recoded_end);
- return NULL;
+ lines = g_new(char *, 1);
+ lines[0] = NULL;
+ return lines;
}
lines = recode_split(server, line, target, len, onspace);
From 956bc592a94d5f4cce03f5762f1976d98de637ef Mon Sep 17 00:00:00 2001
From: Will Storey
Date: Sat, 21 Oct 2017 22:00:11 -0700
Subject: [PATCH 64/76] Fix a typo in the readme
Also uppercase Irssi in a couple places, and escape an argument not
shown due to looking like an HTML tag
---
README.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index d6577fdf..8d91f4cb 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ think of currently:
queries when msgs/notices are received or when you send a msg, closing
queries when it's been idle for some time, etc.
- - **Multiserver friendy** - I think Irssi has clearly the best support
+ - **Multiserver friendly** - I think Irssi has clearly the best support
for handling multiple server connections. You can have as many as you
want in as many ircnets as you want. Having several connections in one
server works too, for example when you hit the (ircnet's) 10
@@ -84,7 +84,7 @@ think of currently:
search command that jumps around in scrollback in GUI-style is still
missing from Irssi, but there's something that's almost as good as it.
/LASTLOG always shows timestamps when the line was printed, even if you
- didn't have timestamps on. Now doing /SB GOTO jumps
+ didn't have timestamps on. Now doing /SB GOTO \ jumps
directly to the position in scrollback you wanted. Great feature when
you want to browse a bit of the discussion what happened when someone
said your name (as seen in awaylog) or topic was changed (/last
@@ -96,9 +96,9 @@ think of currently:
- `startup-HOWTO.txt` - new users should read this
- `manual.txt` - manual I started writing but didn't get it very far :)
- `perl.txt` - Perl scripting help
- - `formats.txt` - How to use colors, etc. with irssi
+ - `formats.txt` - How to use colors, etc. with Irssi
- `faq.txt` - Frequently Asked Questions
- - `special_vars.txt` - some predefined $variables you can use with irssi
+ - `special_vars.txt` - some predefined $variables you can use with Irssi
## Bugs / Suggestions
From 816df6d153e937734bdac258ad6bf43173361451 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Sun, 22 Oct 2017 15:38:54 +0200
Subject: [PATCH 65/76] Merge tag '1.0.5' into integrate/1.0.5
---
NEWS | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/NEWS b/NEWS
index feb52275..cc301365 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,23 @@
v1.1-head 2017-xx-xx The Irssi team
+v1.0.5 2017-10-23 The Irssi team
+ - Fix missing -sasl_method '' in /NETWORK (#718, #719).
+ - Fix incorrect restoration of term state when hitting SUSP
+ inside screen (#737, #733).
+ - Fix out of bounds read when compressing colour
+ sequences. Found by Hanno Böck (GL#12, GL!18).
+ - Fix use after free condition during a race condition when
+ waiting on channel sync during a rejoin (GL#13, GL!19).
+ - Fix null pointer dereference when parsing certain malformed
+ CTCP DCC messages (GL#14, GL!20).
+ - Fix crash due to null pointer dereference when failing to
+ split messages due to overlong nick or target (GL#15, GL!21).
+ - Fix out of bounds read when trying to skip a safe channel ID
+ without verifying that the ID is long enough (GL#16, GL!22).
+ - Fix return of random memory when inet_ntop failed (#769).
+ - Minor statusbar help update. By Robert Bisewski (#758,
+ #763).
+
v1.0.4 2017-07-07 The Irssi team
- Fix null pointer dereference when parsing invalid timestamp (GL#10,
GL!15). Reported by Brian 'geeknik' Carpenter.
From 87550541e745627cc78507ce573d68b8453959c9 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Tue, 24 Oct 2017 22:04:13 +0200
Subject: [PATCH 66/76] fix key length checker to actually do some work
---
autogen.sh | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/autogen.sh b/autogen.sh
index 60eb4fb8..a9e354c9 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -29,20 +29,6 @@ cat docs/help/in/Makefile.am.gen|sed "s/@HELPFILES@/$files/g"|sed 's/?/\\?/g'|tr
files=`echo $files|sed 's/\.in//g'`
cat docs/help/Makefile.am.gen|sed "s/@HELPFILES@/$files/g"|sed 's/?/\\?/g'|tr '!?' '\t\n' > docs/help/Makefile.am
-# .html -> .txt with lynx or elinks
-echo "Documentation: html -> txt..."
-if type lynx >/dev/null 2>&1 ; then
- LC_ALL=en_IE.utf8 lynx -dump docs/faq.html|perl -pe 's/^ *//; if ($_ eq "\n" && $state eq "Q") { $_ = ""; } elsif (/^([QA]):/) { $state = $1 } elsif ($_ ne "\n") { $_ = " $_"; };' > docs/faq.txt
-elif type elinks >/dev/null 2>&1 ; then
- elinks -dump docs/faq.html|perl -pe 's/^ *//; if ($_ eq "\n" && $state eq "Q") { $_ = ""; } elsif (/^([QA]):/) { $state = $1 } elsif ($_ ne "\n") { $_ = " $_"; };' > docs/faq.txt
-elif type links >/dev/null 2>&1 ; then
- links -dump docs/faq.html|perl -pe 's/^ *//; if ($_ eq "\n" && $state eq "Q") { $_ = ""; } elsif (/^([QA]):/) { $state = $1 } elsif ($_ ne "\n") { $_ = " $_"; };' > docs/faq.txt
-else
- echo "**Error**: No lynx or elinks present"
- echo "Install lynx or elinks, then run autogen.sh again"
- exit 1
-fi
-
if test x$NOCONFIGURE = x && test -z "$*"; then
echo "**Warning**: I am going to run \`configure' with no arguments."
echo "If you wish to pass any to it, please specify them on the"
@@ -65,4 +51,4 @@ else
fi
# make sure perl hashes have correct length
-find src/perl -name *.c -o -name *.xs | xargs grep -n hv_store | perl -ne 'if (/"(\w+)",\s*(\d+)/) { print unless $2 == length $1 }'
+find src/perl -name '*.c' -o -name '*.xs' -exec grep -n hv_store {} + | perl -l -ne 'if (/"(\w+)",\s*(\d+)/ && $2 != length $1) { $X=1; print "Incorrect key length in $_" } END { exit $X }'
From 245bd5579cc680e8eeba4769da87bccb8a4d0de3 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Tue, 24 Oct 2017 22:12:34 +0200
Subject: [PATCH 67/76] remove lynx from autogen and make a separate syncdocs
script
---
.gitignore | 1 -
docs/Makefile.am | 3 +-
docs/faq.html | 4 +-
docs/faq.txt | 124 +++++++
docs/startup-HOWTO.html | 512 ++++++++++++++------------
docs/startup-HOWTO.txt | 797 ++++++++++++++++++++++++++++++++++++++++
syncdocs.sh | 101 +++++
7 files changed, 1295 insertions(+), 247 deletions(-)
create mode 100644 docs/faq.txt
create mode 100644 docs/startup-HOWTO.txt
create mode 100755 syncdocs.sh
diff --git a/.gitignore b/.gitignore
index 9af0c4b1..efc579cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,6 @@ config.status
configure
default-config.h
default-theme.h
-faq.txt
irssi-config
irssi-config.h
irssi-config.h.in
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 32722391..8998ffb4 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -11,7 +11,8 @@ doc_DATA = \
perl.txt \
signals.txt \
special_vars.txt \
- startup-HOWTO.html
+ startup-HOWTO.html \
+ startup-HOWTO.txt
EXTRA_DIST = $(doc_DATA) $(man_MANS)
diff --git a/docs/faq.html b/docs/faq.html
index 345060dc..70e90bb5 100644
--- a/docs/faq.html
+++ b/docs/faq.html
@@ -1,4 +1,6 @@
+
Frequently Asked Questions
+
A: They force ANSI colors even if terminal doesn’t support them. By default, irssi uses colors only if terminfo/termcap so says. The correct way to fix this would be to change your TERM environment to a value where colors work, like xterm-color or color_xterm (eg. TERM=xterm-color irssi
). If this doesn’t help, then use the evil way of /SET term_force_colors ON
.
@@ -77,4 +79,4 @@
-A: Check here
+A: Check here
\ No newline at end of file
diff --git a/docs/faq.txt b/docs/faq.txt
new file mode 100644
index 00000000..719fbb9a
--- /dev/null
+++ b/docs/faq.txt
@@ -0,0 +1,124 @@
+ Frequently Asked Questions
+
+Q: Why doesn’t irssi display colors even when ircii etc. displays them?
+A: They force ANSI colors even if terminal doesn’t support them. By default,
+ irssi uses colors only if terminfo/termcap so says. The correct way to fix this
+ would be to change your TERM environment to a value where colors work, like
+ xterm-color or color_xterm (eg. TERM=xterm-color irssi). If this doesn’t help,
+ then use the evil way of /SET term_force_colors ON.
+
+Q: How do I easily write text to channel that starts with ‘/’ character?
+A: / /text
+
+Q: Why doesn’t irssi update my realname (or whatever) after I change it with /
+ SET realname and reconnect with /RECONNECT or /SERVER?
+A: Irssi is trying to be too smart. This will be fixed in future, but for now
+ you should use /DISCONNECT and /CONNECT.
+
+Q: I connected to some server which isn’t responding but now irssi tries to
+ connect back to it all the time! How can I stop it?
+A: Two ways. The “good way” to do it is with /DISCONNECT. Check the server tags
+ first with /SERVER without giving it any parameters, reconnections are those
+ that have tag starting with “recon” text. So most probably you’re going to do /
+ DISCONNECT recon-1. The other way is to remove all the reconnections with /
+ RMRECONNS, easier but may remove some connections you actually wanted to
+ reconnect (if you used multiple servers..).
+
+Q: How do I add seconds to timestamp?
+A: /FORMAT timestamp {timestamp %%H:%%M:%%S} - and remember to add the trailing
+ space :)
+
+Q: Why does irssi say “Irssi: Channel not fully synchronized yet, try again
+ after a while” when I try to use /BAN etc?
+A: Possibly a bug in irssi, or ircd you’re using does something that irssi
+ didn’t really notice. The new code should make this happen far less often than
+ before, but one known reason for this is when irssi doesn’t notice that you
+ were unable to join some channel. Currently however I don’t know of any such
+ events irssi doesn’t know about.
+
+ Anyway, if this does happen, do /RAWLOG SAVE ~/rawlog soon after joining to
+ channel, and either try to figure out yourself why irssi didn’t get reply to
+ WHO request, or open a Github issue with the full log included. Note that the
+ rawlog is by default only 200 lines and it may not be enough to show all needed
+ information, so you might want to do /SET rawlog_lines 1000 or so.
+
+ MODE +b still works fine though.
+
+Q: Where’s the GUI version?
+A: There was one on [1]irssi-import/xirssi but it has not been maintained for a
+ long time.
+
+Q: How do I autorejoin channels after being kicked?
+A: That’s evil and you shouldn’t do it. If you get kicked, you should stay out,
+ at least until the channel forgot you existed :) Most channels I’ve joined just
+ ban you if you autorejoin after kick. If you’re joined to channels who kick
+ people for fun, try changing channels or something.
+
+ Anyway, if you REALLY want to do that, and you understand that you’re doing
+ evilness, you can use the autorejoin.pl script that comes with irssi. You’ll
+ still need to specify the channels you wish to rejoin with /SET
+ autorejoin_channels #chan1 #chan2 ...
+
+Q: How do I announce that I’m away/back in all channels I’ve joined? Or how do
+ I change my nick when setting myself away/back?
+A: That’s even worse than autorejoin. Who could possibly care every time you
+ come and go? Many channels will kick you for using this, and I for example have
+ added several ignores so I’d never need to see these messages. Learn to use /
+ AWAY command properly and tell its existence to people who don’t know about it.
+ /WII yournick shows your away reason much better for people who actually want
+ to know if you’re there or not.
+
+Q: Why does irssi autojoin on invite by default?
+A: The setting is /SET join_auto_chans_on_invite - it’s not the same as regular
+ autojoin-on-invite, which irssi doesn’t even have. The only channels that are
+ joined on invite, are the ones you’ve added to config with /CHANNEL ADD -auto.
+ This is very useful with +i channels when you need to first send an invite
+ request to bot, or if you get accidentally kicked from channel, the kicker can
+ invite you back immediately.
+
+ I don’t see any bad side effects with this feature, so it’s ON by default. I
+ guess someone could start kicking/inviting you all the time but server
+ connection shouldn’t drop because of that, and you shouldn’t join channels
+ whose operators are that evil.
+
+Q: How to make UTF-8 support work with irssi?
+A: Make sure your terminal supports UTF-8 (for example, xterm -u8). If you use
+ screen, you may have to do screen -U. And in Irssi do /SET term_charset utf-8.
+ (for 0.8.9 and older: /SET term_type utf-8)
+
+Q: Will there be /DETACH-like feature?
+A: [2]tmux, [3]screen and [4]dtach can be used to do it just fine.
+
+Q: How do I run scripts automatically at startup?
+A: Put them into ~/.irssi/scripts/autorun/ directory. Or better would be if you
+ placed them in ~/.irssi/scripts/ and created symlinks to autorun directory (eg.
+ cd ~/.irssi/scripts/autorun/ ; ln -s ../script.pl .)
+
+Q: How do I execute commands automatically at startup?
+A: Put them into ~/.irssi/startup file, each command on its own line. The
+ preceding slash (/) is not necessary.
+
+Q: How do I easily edit existing topic?
+A: /TOPIC
+
+Q: How can I have /WHOIS replies to active window?
+A: You can disable the status window, or do /WINDOW LEVEL -CRAP in it which
+ would also make several other messages show up in active window. You can also
+ use a [5]script.
+
+Q: How do I add the active network to the statusbar
+A: Modify the window-line in statusbar section in config file to window = "{sb
+ $winref:$tag/$T{sbmode $M}}";
+
+Q: How to pronounce Irssi?
+A: Check [6]here
+
+
+ References:
+
+ [1] https://github.com/irssi-import/xirssi
+ [2] http://tmux.github.io/
+ [3] http://www.gnu.org/software/screen/screen.html
+ [4] http://dtach.sf.net/
+ [5] http://dgl.cx/irssi/hack-whois-in-current-window.pl
+ [6] https://irssi.org/assets/irssi.wav
diff --git a/docs/startup-HOWTO.html b/docs/startup-HOWTO.html
index 07a9f47c..aaf9e5fe 100644
--- a/docs/startup-HOWTO.html
+++ b/docs/startup-HOWTO.html
@@ -1,4 +1,6 @@
- Startup How-To
+
+Startup How-To
+
Copyright (c) 2000-2002 by Timo Sirainen, release under GNU FDL 1.1 license.
@@ -6,11 +8,7 @@
Index with some FAQ questions that are answered in the chapter:
- - For all the ircII people
-
- - This window management is just weird, I want it exactly like ircII
-
-
+ - First steps
- Basic user interface usage
- Split windows work in weird way
@@ -50,7 +48,11 @@
- Proxies and IRC bouncers
- - Irssi’s settings
+ - Irssi’s settings
+
+
- Statusbar
- I loaded a statusbar script but it’s not visible anywhere!
@@ -58,169 +60,176 @@
-1. For all the ircII people
+1. First steps
-These settings should give you pretty good defaults (the ones I use):
+IRC Networks are made of servers, and servers have channels. The default config has a few predefined networks, to list them:
-If colors don’t work, and you know you’re not going to use some weird non-VT compatible terminal (you most probably aren’t), just say:
+
- /SET term_force_colors ON
-
+And to connect to one of those networks and join a channel:
-I don’t like automatic query windows, I don’t like status window, I do like msgs window where all messages go:
+/CONNECT Freenode
+/JOIN #irssi
+
- /SET autocreate_own_query OFF
- /SET autocreate_query_level DCCMSGS
- /SET use_status_window OFF
- /SET use_msgs_window ON
-
+To add more networks:
-Disable automatic window closing when /PART
ing channel or /UNQUERY
ing query:
+/NETWORK ADD ExampleNet
+
- /SET autoclose_windows OFF
- /SET reuse_unused_windows ON
-
+Then add some servers (with -auto to automatically connect):
-Here’s the settings that make irssi work exactly like ircII in window management (send me a note if you can think of more):
+/SERVER ADD -auto -network ExampleNet irc.example.net
+
- /SET autocreate_own_query OFF
- /SET autocreate_query_level NONE
- /SET use_status_window OFF
- /SET use_msgs_window OFF
- /SET reuse_unused_windows ON
- /SET windows_auto_renumber OFF
+Automatically join to channels after connected to server:
- /SET autostick_split_windows OFF
- /SET autoclose_windows OFF
- /SET print_active_channel ON
-
+/CHANNEL ADD -auto #lounge ExampleNet
+
-And example how to add servers:
+To modify existing networks (or servers, or channels) just ADD again using the same name as before. This configures a network to identify with nickserv and wait for 2 seconds before joining channels:
-(OFTC network, identify with nickserv and wait for 2 seconds before joining channels)
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" ExampleNet
+
- /NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
-
+If you have irssi 0.8.18 or higher and the irc network supports it, you can use SASL instead of nickserv, which is more reliable:
-(NOTE: use /IRCNET with 0.8.9 and older)
+/NETWORK ADD -sasl_username yourname -sasl_password yourpassword -sasl_mechanism PLAIN Freenode
+
-Then add some servers to different networks (network is already set up for them), irc.kpnqwest.fi is used by default for IRCNet but if it fails, irc.funet.fi is tried next:
+These commands have many more options, see their help for details:
- /SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
- /SERVER ADD -network IRCnet irc.funet.fi 6667
- /SERVER ADD -auto -network efnet efnet.cs.hut.fi 6667
-
-
-Automatically join to channels after connected to server, send op request to bot after joined to efnet/#irssi:
-
- /CHANNEL ADD -auto #irssi IRCnet
- /CHANNEL ADD -auto -bots *!*bot@host.org -botcmd "/^msg $0 op pass" #irssi efnet
-
+/HELP NETWORK
+/HELP SERVER
+/HELP CHANNEL
+/HELP
+
If you want lines containing your nick to hilight:
- /HILIGHT nick
-
+
+
+Or, for irssi 0.8.18 or higher:
+
+/SET hilight_nick_matches_everywhere ON
+
+
+To get beeps on private messages or highlights:
+
+/SET beep_msg_level MSGS HILIGHT DCCMSGS
+
+
+No other irssi settings are needed (don’t enable bell_beeps), but there may be settings to change in your terminal multiplexer (screen/tmux), your terminal, or your desktop environment.
2. Basic user interface usage
Windows can be scrolled up/down with PgUp and PgDown keys. If they don’t work for you, use Meta-p and Meta-n keys. For jumping to beginning or end of the buffer, use /SB HOME
and /SB END
commands.
-By default, irssi uses “hidden windows” for everything. Hidden window is created every time you /JOIN
a channel or /QUERY
someone. There’s several ways you can change between these windows:
+By default, irssi uses “hidden windows” for everything. Hidden windows are created every time you /JOIN
a channel or /QUERY
someone. There’s several ways you can change between these windows:
- Meta-1, Meta-2, .. Meta-0 - Jump directly between windows 1-10
- Meta-q .. Meta-o - Jump directly between windows 11-19
- /WINDOW <number> - Jump to any window with specified number
- Ctrl-P, Ctrl-N - Jump to previous / next window
-
+Meta-1, Meta-2, .. Meta-0 - Jump directly between windows 1-10
+Meta-q .. Meta-o - Jump directly between windows 11-19
+/WINDOW <number> - Jump to any window with specified number
+Ctrl-P, Ctrl-N - Jump to previous / next window
+
-Clearly the easiest way is to use Meta-number keys. And what is the Meta key? ESC key always works as Meta, but there’s also easier ways. ALT could work as Meta, or if you have Windows keyboard, left Windows key might work as Meta. If they don’t work directly, you’ll need to set a few X resources (NOTE: these work with both xterm and rxvt):
+Clearly the easiest way is to use Meta-number keys. Meta usually means the ALT key, but if that doesn’t work, you can use ESC.
- XTerm*eightBitInput: false
+Mac OS X users with ALT key issues might prefer using iTerm2 instead of the default terminal emulator.
+
+
+
+If you use xterm or rxvt, you may need to set a few X resources:
+
+ XTerm*eightBitInput: false
XTerm*metaSendsEscape: true
-
+
With rxvt, you can also specify which key acts as Meta key. So if you want to use ALT instead of Windows key for it, use:
- rxvt*modifier: alt
-
+
You could do this by changing the X key mappings:
- xmodmap -e "keysym Alt_L = Meta_L Alt_L"
-
+ xmodmap -e "keysym Alt_L = Meta_L Alt_L"
+
And how exactly do you set these X resources? For Debian, there’s /etc/X11/Xresources/xterm
file where you can put them and it’s read automatically when X starts. ~/.Xresources
and ~/.Xdefaults
files might also work. If you can’t get anything else to work, just copy and paste those lines to ~/.Xresources
and directly call xrdb -merge ~/.Xresources
in some xterm. The resources affect only the new xterms you start, not existing ones.
-Many windows SSH clients also don’t allow usage of ALT. One excellent client that does allow is putty, you can download it from http://www.chiark.greenend.org.uk/~sgtatham/putty/.
+Split windows and window items
+
+Note: this guide might be a better introduction to window splits
Irssi also supports split windows, they’ve had some problems in past but I think they should work pretty well now :) Here’s some commands related to them:
- /WINDOW NEW - Create new split window
- /WINDOW NEW HIDE - Create new hidden window
- /WINDOW CLOSE - Close split or hidden window
+/WINDOW NEW - Create new split window
+/WINDOW NEW HIDE - Create new hidden window
+/WINDOW CLOSE - Close split or hidden window
- /WINDOW HIDE [<number>|<name>] - Make the split window hidden window
- /WINDOW SHOW <number>|<name> - Make the hidden window a split window
+/WINDOW HIDE [<number>|<name>] - Make the split window hidden window
+/WINDOW SHOW <number>|<name> - Make the hidden window a split window
- /WINDOW SHRINK [<lines>] - Shrink the split window
- /WINDOW GROW [<lines>] - Grow the split window
- /WINDOW BALANCE - Balance the sizes of all split windows
-
+/WINDOW SHRINK [<lines>] - Shrink the split window
+/WINDOW GROW [<lines>] - Grow the split window
+/WINDOW BALANCE - Balance the sizes of all split windows
+
By default, irssi uses “sticky windowing” for split windows. This means that windows created inside one split window cannot be moved to another split window without some effort. For example you could have following window layout:
- Split window 1: win#1 - Status window, win#2 - Messages window
+ Split window 1: win#1 - Status window, win#2 - Messages window
Split window 2: win#3 - IRCnet/#channel1, win#4 - IRCnet/#channel2
Split window 3: win#5 - efnet/#channel1, win#6 - efnet/#channel2
-
+
When you are in win#1 and press ALT-6, irssi jumps to split window #3 and moves the efnet/#channel2 the active window.
With non-sticky windowing the windows don’t have any relationship with split windows, pressing ALT-6 in win#1 moves win#6 to split window 1 and sets it active, except if win#6 was already visible in some other split window irssi just changes to that split window. This it the way windows work with ircii, if you prefer it you can set it with
- /SET autostick_split_windows OFF
-
+/SET autostick_split_windows OFF
+
Each window can have multiple channels, queries and other “window items” inside them. If you don’t like windows at all, you disable automatic creating of them with
- /SET autocreate_windows OFF
-
+/SET autocreate_windows OFF
+
And if you keep all channels in one window, you most probably want the channel name printed in each line:
- /SET print_active_channel ON
-
+/SET print_active_channel ON
+
If you want to group only some channels or queries in one window, use
- /JOIN -window #channel
- /QUERY -window nick
-
+/JOIN -window #channel
+/QUERY -window nick
+
3. Server and channel automation
Irssi’s multiple IRC network support is IMHO very good - at least compared to other clients :) Even if you’re only in one IRC network you should group all your servers to be in the same IRC network as this helps with reconnecting if your primary server breaks and is probably useful in some other ways too :) For information how to actually use irssi correctly with multiple servers see the chapter 6.
-First you need to have your IRC network set, use /NETWORK
command to see if it’s already there. If it isn’t, use /NETWORK ADD yournetwork
. If you want to execute some commands automatically when you’re connected to some network, use -autosendcmd
option. (NOTE: use /IRCNET with 0.8.9 and older.) Here’s some examples:
+First you need to have your IRC network set, use /NETWORK
command to see if it’s already there. If it isn’t, use /NETWORK ADD yournetwork
. If you want to execute some commands automatically when you’re connected to some network, use -autosendcmd
option. Here’s some examples:
- /NETWORK ADD -autosendcmd '^msg bot invite' IRCnet
- /NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
-
+/NETWORK ADD -autosendcmd '^msg bot invite' IRCnet
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
+
After that you need to add your servers. For example:
- /SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
- /SERVER ADD -auto -network worknet irc.mycompany.com 6667 password
-
+/SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
+/SERVER ADD -auto -network worknet irc.mycompany.com 6667 password
+
The -auto
option specifies that this server is automatically connected at startup. You don’t need to make more than one server with -auto
option to one IRC network, other servers are automatically connected in same network if the -auto
server fails.
And finally channels:
- /CHANNEL ADD -auto -bots *!*bot@host.org -botcmd "/^msg $0 op pass" #irssi efnet
- /CHANNEL ADD -auto #secret IRCnet password
-
+/CHANNEL ADD -auto -bots *!*user@host -botcmd "/^msg $0 op pass" #irssi efnet
+/CHANNEL ADD -auto #secret IRCnet password
+
-bots
and -botcmd
should be the only ones needing a bit of explaining. They’re used to send commands automatically to bot when channel is joined, usually to get ops automatically. You can specify multiple bot masks with -bots
option separated with spaces (and remember to quote the string then). The $0 in -botcmd
specifies the first found bot in the list. If you don’t need the bot masks (ie. the bot is always with the same nick, like chanserv) you can give only the -botcmd
option and the command is always sent.
@@ -228,9 +237,9 @@
First connect to all the servers, join the channels and create the queries you want. If you want to move the windows or channels around use commands:
- /WINDOW MOVE LEFT/RIGHT/number - move window elsewhere
- /WINDOW ITEM MOVE <number>|<name> - move channel/query to another window
-
+/WINDOW MOVE LEFT/RIGHT/number - move window elsewhere
+/WINDOW ITEM MOVE <number>|<name> - move channel/query to another window
+
When everything looks the way you like, use /LAYOUT SAVE
command (and /SAVE
, if you don’t have autosaving enabled) and when you start irssi next time, irssi remembers the positions of the channels, queries and everything. This “remembering” doesn’t mean that simply using /LAYOUT SAVE
would automatically make irssi reconnect to all servers and join all channels, you’ll need the /SERVER ADD -auto
and /CHANNEL ADD -auto
commands to do that.
@@ -240,32 +249,32 @@
By default, all the “extra messages” go to status window. This means pretty much all messages that don’t clearly belong to some channel or query. Some people like it, some don’t. If you want to remove it, use
- /SET use_status_window OFF
-
+/SET use_status_window OFF
+
This doesn’t have any effect until you restart irssi. If you want to remove it immediately, just /WINDOW CLOSE
it.
Another common window is “messages window”, where all private messages go. By default it’s disabled and query windows are created instead. To make all private messages go to msgs window, say:
- /SET use_msgs_window ON
- /SET autocreate_query_level DCCMSGS (or if you don't want queries to
+/SET use_msgs_window ON
+/SET autocreate_query_level DCCMSGS (or if you don't want queries to
dcc chats either, say NONE)
-
+
use_msgs_window either doesn’t have any effect until restarting irssi. To create it immediately say:
- /WINDOW NEW HIDE - create the window
- /WINDOW NAME (msgs) - name it to "(msgs)"
- /WINDOW LEVEL MSGS - make all private messages go to this window
- /WINDOW MOVE 1 - move it to first window
-
+/WINDOW NEW HIDE - create the window
+/WINDOW NAME (msgs) - name it to "(msgs)"
+/WINDOW LEVEL MSGS - make all private messages go to this window
+/WINDOW MOVE 1 - move it to first window
+
Note that neither use_msgs_window nor use_status_window have any effect at all if /LAYOUT SAVE
has been used.
This brings us to message levels.. What are they? All messages that irssi prints have one or more “message levels”. Most common are PUBLIC for public messages in channels, MSGS for private messages and CRAP for all sorts of messages with no real classification. You can get a whole list of levels with
- /HELP levels
-
+
Status window has message level ALL -MSGS
, meaning that all messages, except private messages, without more specific place go to status window. The -MSGS
is there so it doesn’t conflict with messages window.
@@ -273,15 +282,15 @@
ircii and several other clients support multiple servers by placing the connection into some window. IRSSI DOES NOT. There is no required relationship between window and server. You can connect to 10 servers and manage them all in just one window, or join channel in each one of them to one single window if you really want to. That being said, here’s how you do connect to new server without closing the old connection:
- /CONNECT irc.server.org
-
+/CONNECT irc.server.org
+
Instead of the /SERVER
which disconnects the existing connection. To see list of all active connections, use /SERVER
without any parameters. You should see a list of something like:
- -!- IRCNet: irc.song.fi:6667 (IRCNet)
+ -!- IRCNet: irc.song.fi:6667 (IRCNet)
-!- OFTC: irc.oftc.net:6667 (OFTC)
-!- RECON-1: 192.168.0.1:6667 () (02:59 left before reconnecting)
-
+
Here you see that we’re connected to IRCNet and OFTC networks. The IRCNet at the beginning is called the “server tag” while the (IRCnet) at the end shows the IRC network. Server tag specifies unique tag to refer to the server, usually it’s the same as the IRC network. When the IRC network isn’t known it’s some part of the server name. When there’s multiple connections to same IRC network or server, irssi adds a number after the tag so there could be network, network2, network3 etc.
@@ -289,63 +298,63 @@
To disconnect one of the servers, or to stop irssi from reconnecting, use
- /DISCONNECT network - disconnect server with tag "network"
- /DISCONNECT recon-1 - stop trying to reconnect to RECON-1 server
- /RMRECONNS - stop all server reconnections
+/DISCONNECT network - disconnect server with tag "network"
+/DISCONNECT recon-1 - stop trying to reconnect to RECON-1 server
+/RMRECONNS - stop all server reconnections
- /RECONNECT recon-1 - immediately try reconnecting back to RECON-1
- /RECONNECT ALL - immediately try reconnecting back to all
+/RECONNECT recon-1 - immediately try reconnecting back to RECON-1
+/RECONNECT ALL - immediately try reconnecting back to all
servers in reconnection queue
-
+
Now that you’re connected to all your servers, you’ll have to know how to specify which one of them you want to use. One way is to have an empty window, like status or msgs window. In it, you can specify which server to set active with
- /WINDOW SERVER tag - set server "tag" active
- Ctrl-X - set the next server in list active
-
+/WINDOW SERVER tag - set server "tag" active
+Ctrl-X - set the next server in list active
+
When the server is active, you can use it normally. When there’s multiple connected servers, irssi adds [servertag] prefix to all messages in non-channel/query messages so you’ll know where it came from.
Several commands also accept -servertag
option to specify which server it should use:
- /MSG -tag nick message
- /JOIN -tag #channel
- /QUERY -tag nick
-
+/MSG -tag nick message
+/JOIN -tag #channel
+/QUERY -tag nick
+
/MSG
tab completion also automatically adds the -tag
option when nick isn’t in active server.
Window’s server can be made sticky. When sticky, it will never automatically change to anything else, and if server gets disconnected, the window won’t have any active server. When the server gets connected again, it is automatically set active in the window. To set the window’s server sticky use
- /WINDOW SERVER -sticky tag
-
+/WINDOW SERVER -sticky tag
+
This is useful if you wish to have multiple status or msgs windows, one for each server. Here’s how to do them (repeat for each server)
- /WINDOW NEW HIDE
- /WINDOW NAME (status)
- /WINDOW LEVEL ALL -MSGS
- /WINDOW SERVER -sticky network
+/WINDOW NEW HIDE
+/WINDOW NAME (status)
+/WINDOW LEVEL ALL -MSGS
+/WINDOW SERVER -sticky network
- /WINDOW NEW HIDE
- /WINDOW NAME (msgs)
- /WINDOW LEVEL MSGS
- /WINDOW SERVER -sticky network
-
+/WINDOW NEW HIDE
+/WINDOW NAME (msgs)
+/WINDOW LEVEL MSGS
+/WINDOW SERVER -sticky network
+
/LASTLOG
command can be used for searching texts in scrollback buffer. Simplest usages are
- /LASTLOG word - print all lines with "word" in them
- /LASTLOG word 10 - print last 10 occurances of "word"
- /LASTLOG -topics - print all topic changes
-
+/LASTLOG word - print all lines with "word" in them
+/LASTLOG word 10 - print last 10 occurances of "word"
+/LASTLOG -topics - print all topic changes
+
If there’s more than 1000 lines to be printed, irssi thinks that you probably made some mistake and won’t print them without -force
option. If you want to save the full lastlog to file, use
- /LASTLOG -file ~/irc.log
-
+/LASTLOG -file ~/irc.log
+
With -file
option you don’t need -force
even if there’s more than 1000 lines. /LASTLOG
has a lot of other options too, see /HELP lastlog
for details.
@@ -355,29 +364,29 @@
Irssi can automatically log important messages when you’re set away (/AWAY reason
). When you set yourself unaway (/AWAY
), the new messages in away log are printed to screen. You can configure it with:
- /SET awaylog_level MSGS HILIGHT - Specifies what messages to log
- /SET awaylog_file ~/.irssi/away.log - Specifies the file to use
-
+/SET awaylog_level MSGS HILIGHT - Specifies what messages to log
+/SET awaylog_file ~/.irssi/away.log - Specifies the file to use
+
Easiest way to start logging with Irssi is to use autologging. With it Irssi logs all channels and private messages to specified directory. You can turn it on with
- /SET autolog ON
-
+
By default it logs pretty much everything execept CTCPS or CRAP (/WHOIS
requests, etc). You can specify the logging level yourself with
- /SET autolog_level ALL -CRAP -CLIENTCRAP -CTCPS (this is the default)
-
+/SET autolog_level ALL -CRAP -CLIENTCRAP -CTCPS (this is the default)
+
By default irssi logs to ~/irclogs//.log. You can change this with
- /SET autolog_path ~/irclogs/$tag/$0.log (this is the default)
-
+/SET autolog_path ~/irclogs/$tag/$0.log (this is the default)
+
The path is automatically created if it doesn’t exist. $0 specifies the target (channel/nick). You can make irssi automatically rotate the logs by adding date/time formats to the file name. The formats are in “man strftime” format. For example
- /SET autolog_path ~/irclogs/%Y/$tag/$0.%m-%d.log
-
+/SET autolog_path ~/irclogs/%Y/$tag/$0.%m-%d.log
+
For logging only some specific channels or nicks, see /HELP log
@@ -387,16 +396,16 @@
/HELP bind
tells pretty much everything there is to know about keyboard bindings. However, there’s the problem of how to bind some non-standard keys. They might differ a bit with each terminal, so you’ll need to find out what exactly the keypress produces. Easiest way to check that would be to see what it prints in cat
. Here’s an example for pressing F1 key:
- [cras@hurina] ~% cat
+ [user@host] ~% cat
^[OP
-
+
So in irssi you would use /BIND ^[OP /ECHO F1 pressed
. If you use multiple terminals which have different bindings for the key, it would be better to use eg.:
- /BIND ^[OP key F1
- /BIND ^[11~ key F1
- /BIND F1 /ECHO F1 pressed.
-
+/BIND ^[OP key F1
+/BIND ^[11~ key F1
+/BIND F1 /ECHO F1 pressed.
+
10. Proxies and IRC bouncers
@@ -404,20 +413,20 @@
Here’s an example: You have your bouncer (lets say, BNC or BNC-like) listening in irc.bouncer.org port 5000. You want to use it to connect to servers irc.dalnet and irc.efnet.org. First you’d need to setup the bouncer:
- /SET use_proxy ON
- /SET proxy_address irc.bouncer.org
- /SET proxy_port 5000
+/SET use_proxy ON
+/SET proxy_address irc.bouncer.org
+/SET proxy_port 5000
- /SET proxy_password YOUR_BNC_PASSWORD_HERE
- /SET -clear proxy_string
- /SET proxy_string_after conn %s %d
-
+/SET proxy_password YOUR_BNC_PASSWORD_HERE
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+
Then you’ll need to add the server connections. These are done exactly as if you’d want to connect directly to them. Nothing special about them:
- /SERVER ADD -auto -network dalnet irc.dal.net
- /SERVER ADD -auto -network efnet irc.efnet.org
-
+/SERVER ADD -auto -network dalnet irc.dal.net
+/SERVER ADD -auto -network efnet irc.efnet.org
+
With the proxy /SET
s however, irssi now connects to those servers through your BNC. All server connections are made through them so you can just forget that your bouncer even exists.
@@ -427,36 +436,36 @@
All proxies have these settings in common:
- /SET use_proxy ON
- /SET proxy_address <Proxy host address>
- /SET proxy_port <Proxy port>
-
+/SET use_proxy ON
+/SET proxy_address <Proxy host address>
+/SET proxy_port <Proxy port>
+
HTTP proxy
Use these settings with HTTP proxies:
- /SET -clear proxy_password
- /EVAL SET proxy_string CONNECT %s:%d HTTP/1.0\n\n
-
+/SET -clear proxy_password
+/EVAL SET proxy_string CONNECT %s:%d HTTP/1.0\n\n
+
BNC
- /SET proxy_password your_pass
- /SET -clear proxy_string
- /SET proxy_string_after conn %s %d
-
+/SET proxy_password your_pass
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+
dircproxy
dircproxy separates the server connections by passwords. So, if you for example have network connection with password ircpass and OFTC connection with oftcpass, you would do something like this:
- /SET -clear proxy_password
- /SET -clear proxy_string
+/SET -clear proxy_password
+/SET -clear proxy_string
- /SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
- /SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
-
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+
The server name and port you give isn’t used anywhere, so you can put anything you want in there.
@@ -464,19 +473,17 @@
psyBNC has internal support for multiple servers. However, it could be a bit annoying to use, and some people just use different users for connecting to different servers. You can manage this in a bit same way as with dircproxy, by creating fake connections:
- /SET -clear proxy_password
- /SET -clear proxy_string
+/SET -clear proxy_password
+/SET -clear proxy_string
- /NETWORK ADD -user networkuser IRCnet
- /SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
- /NETWORK ADD -user oftcuser OFTC
- /SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
-
+/NETWORK ADD -user networkuser IRCnet
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/NETWORK ADD -user oftcuser OFTC
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+
So, you’ll specify the usernames with /NETWORK ADD
command, and the user’s password with /SERVER ADD
.
-(NOTE: use /IRCNET with 0.8.9 and older.)
-
Irssi proxy
Irssi contains it’s own proxy which you can build giving \--with-proxy
option to configure. You’ll still need to run irssi in a screen to use it though.
@@ -487,65 +494,52 @@
Usage in proxy side:
- /LOAD proxy
- /SET irssiproxy_password <password>
- /SET irssiproxy_ports <network>=<port> ... (eg. IRCnet=2777 efnet=2778)
-
+/LOAD proxy
+/SET irssiproxy_password <password>
+/SET irssiproxy_ports <network>=<port> ... (eg. IRCnet=2777 efnet=2778)
+
NOTE: you MUST add all the servers you are using to server and network lists with /SERVER ADD
and /NETWORK ADD
. ..Except if you really don’t want to for some reason, and you only use one server connection, you may simply set:
- /SET irssiproxy_ports *=2777
-
-
-The special network name ?
allows the client to select the
-network dynamically on connect (see below):
-
-
-/SET irssiproxy_ports ?=2777
-
+/SET irssiproxy_ports *=2777
+
Usage in client side:
Just connect to the irssi proxy like it is a normal server with password specified in /SET irssiproxy_password
. For example:
- /SERVER ADD -network IRCnet my.irssi-proxy.org 2777 secret
- /SERVER ADD -network efnet my.irssi-proxy.org 2778 secret
-
-
-Or, if you used ?
in irssiproxy_ports
:
-
-
-/SERVER ADD -network IRCnet my.irssi-proxy.org 2777 IRCnet:secret
-/SERVER ADD -network efnet my.irssi-proxy.org 2777 efnet:secret
-
-
-I.e. the network to connect to is specified as part of the password,
-separated by :
from the actual proxy password.
+/SERVER ADD -network IRCnet my.irssi-proxy.org 2777 secret
+/SERVER ADD -network efnet my.irssi-proxy.org 2778 secret
+
Irssi proxy works fine with other IRC clients as well.
SOCKS
-Irssi can be compiled with socks support (\--with-socks
option to configure), but I don’t really know how it works, if at all. /SET proxy
settings don’t have anything to do with socks however.
+Irssi can be compiled with socks support (\--with-socks
option to configure), which requires “dante” and routes all connections through the proxy specified in the system-wide /etc/socks.conf. This method is known to have issues in Mac OS X.
+
+Note that /SET proxy
settings don’t have anything to do with socks.
+
+Using proxychains-ng is recommended over recompiling irssi.
Others
IRC bouncers usually work like IRC servers, and want a password. You can give it with:
- /SET proxy_password <password>
-
+/SET proxy_password <password>
+
Irssi’s defaults for connect strings are
- /SET proxy_string CONNECT %s %d
- /SET proxy_string_after
-
+/SET proxy_string CONNECT %s %d
+/SET proxy_string_after
+
The proxy_string is sent before NICK/USER commands, the proxy_string_after is sent after them. %s and %d can be used with both of them.
-You probably don’t like Irssi’s default settings. I don’t like them. But I’m still convinced that they’re pretty good defaults. Here’s some of them you might want to change (the default value is shown): Also check the Settings Documentation
+Here’s some settings you might want to change (the default value is shown): Also check the Settings Documentation
Queries
@@ -633,31 +627,61 @@ separated by :
from the actual proxy password.
Completion character to use.
+For all the ircII people
+
+I don’t like automatic query windows, I don’t like status window, I do like msgs window where all messages go:
+
+/SET autocreate_own_query OFF
+/SET autocreate_query_level DCCMSGS
+/SET use_status_window OFF
+/SET use_msgs_window ON
+
+
+Disable automatic window closing when /PART
ing channel or /UNQUERY
ing query:
+
+/SET autoclose_windows OFF
+/SET reuse_unused_windows ON
+
+
+Here’s the settings that make irssi work exactly like ircII in window management (send me a note if you can think of more):
+
+/SET autocreate_own_query OFF
+/SET autocreate_query_level NONE
+/SET use_status_window OFF
+/SET use_msgs_window OFF
+/SET reuse_unused_windows ON
+/SET windows_auto_renumber OFF
+
+/SET autostick_split_windows OFF
+/SET autoclose_windows OFF
+/SET print_active_channel ON
+
+
12. Statusbar
-/STATUSBAR
displays a list of statusbars:
+/STATUSBAR
displays a list of the current statusbars, along with their position and visibility:
- Name Type Placement Position Visible
+ Name Type Placement Position Visible
window window bottom 0 always
window_inact window bottom 1 inactive
prompt root bottom 100 always
topic root top 1 always
-
+
-/STATUSBAR <name>
prints the statusbar settings and it’s items. /STATUSBAR <name> ENABLE|DISABLE
enables/disables the statusbar. /STATUSBAR <name> RESET
resets the statusbar to it’s default settings, or if the statusbar was created by you, it will be removed.
+/STATUSBAR <name>
prints the statusbar settings (type, placement, position, visibility) as well as its items. /STATUSBAR <name> ENABLE|DISABLE
enables/disables the statusbar. /STATUSBAR <name> RESET
resets the statusbar to its default settings, or if the statusbar was created by you, it will be removed.
-Type can be window or root, meaning if the statusbar should be created for each split window, or just once. Placement can be top or bottom. Position is a number, the higher the value the lower in screen it is. Visible can be always, active or inactive. Active/inactive is useful only with split windows, one split window is active and the rest are inactive. These settings can be changed with:
+The statusbar type can be either window or root. If the type is window, then a statusbar will be created for each split window, otherwise it will be created only once. Placement can be top or bottom, which refers to the top or bottom of the screen. Position is a number, the higher the value the lower it will appear in-screen. Visible can be always, active or inactive. Active/inactive is useful only with split windows; one split window is active and the rest are inactive. To adjust these settings, the following commands are available:
- /STATUSBAR <name> TYPE window|root
- /STATUSBAR <name> PLACEMENT top|bottom
- /STATUSBAR <name> POSITION <num>
- /STATUSBAR <name> VISIBLE always|active|inactive
-
+/STATUSBAR <name> TYPE window|root
+/STATUSBAR <name> PLACEMENT top|bottom
+/STATUSBAR <name> POSITION <num>
+/STATUSBAR <name> VISIBLE always|active|inactive
+
-When loading a new statusbar scripts, you’ll need to also specify where you want to show it. Statusbar items can be modified with:
+Statusbar items can also be added or removed via command. Note that when loading new statusbar scripts that add items, you will need to specify where you want to show the item and how it is aligned. This can be accomplished using the below commands:
- /STATUSBAR <name> ADD [-before | -after <item>] [-priority #] [-alignment left|right] <item>
- /STATUSBAR <name> REMOVE <item>
-
+/STATUSBAR <name> ADD [-before | -after <item>] [-priority #] [-alignment left|right] <item>
+/STATUSBAR <name> REMOVE <item>
+
-The item name with statusbar scripts is usually same as the script’s name. Script’s documentation should tell if this isn’t the case. So, to add mail.pl before the window activity item (see the list with /STATUSBAR
window), use: /STATUSBAR window ADD -before act mail
.
+For statusbar scripts, the item name is usually equivalent to the script name. The documentation of the script ought to tell you if this is not the case. For example, to add mail.pl before the window activity item, use: /STATUSBAR window ADD -before act mail
.
\ No newline at end of file
diff --git a/docs/startup-HOWTO.txt b/docs/startup-HOWTO.txt
new file mode 100644
index 00000000..23d7cf94
--- /dev/null
+++ b/docs/startup-HOWTO.txt
@@ -0,0 +1,797 @@
+Startup How-To
+
+To new Irssi users (not to new IRC users ..)
+
+Copyright (c) 2000-2002 by Timo Sirainen, release under [1]GNU FDL 1.1 license.
+
+Index with some FAQ questions that are answered in the chapter:
+
+ 1. First steps
+ 2. Basic user interface usage
+ □ Split windows work in weird way
+ □ How can I easily switch between windows?
+ □ But alt-1 etc. don’t work!
+ 3. Server and channel automation
+ □ How do I automatically connect to servers at startup?
+ □ How do I automatically join to channels at startup?
+ □ How do I automatically send commands to server at connect?
+ 4. Setting up windows and automatically restoring them at startup
+ 5. Status and msgs windows & message levels
+ □ I want /WHOIS to print reply to current window
+ □ I want all messages to go to one window, not create new windows
+ 6. How support for multiple servers works in irssi
+ □ I connected to some server that doesn’t respond and now irssi keeps
+ trying to reconnect to it again and again, how can I stop it??
+ □ I want to have own status and/or msgs window for each servers
+ 7. /LASTLOG and jumping around in scrollback
+ □ How can I save all texts in a window to file?
+ 8. Logging
+ 9. Changing keyboard bindings
+ □ How do I make F1 key do something?
+10. Proxies and IRC bouncers
+11. Irssi’s settings
+ □ For all the ircII people
+12. Statusbar
+ □ I loaded a statusbar script but it’s not visible anywhere!
+
+1. First steps
+
+IRC Networks are made of servers, and servers have channels. The default config
+has a few predefined networks, to list them:
+
+/NETWORK LIST
+
+And to connect to one of those networks and join a channel:
+
+/CONNECT Freenode
+/JOIN #irssi
+
+To add more networks:
+
+/NETWORK ADD ExampleNet
+
+Then add some servers (with -auto to automatically connect):
+
+/SERVER ADD -auto -network ExampleNet irc.example.net
+
+Automatically join to channels after connected to server:
+
+/CHANNEL ADD -auto #lounge ExampleNet
+
+To modify existing networks (or servers, or channels) just ADD again using the
+same name as before. This configures a network to identify with nickserv and
+wait for 2 seconds before joining channels:
+
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" ExampleNet
+
+If you have irssi 0.8.18 or higher and the irc network supports it, you can use
+SASL instead of nickserv, which is more reliable:
+
+/NETWORK ADD -sasl_username yourname -sasl_password yourpassword -sasl_mechanism PLAIN Freenode
+
+These commands have many more options, see their help for details:
+
+/HELP NETWORK
+/HELP SERVER
+/HELP CHANNEL
+/HELP
+
+If you want lines containing your nick to hilight:
+
+/HILIGHT nick
+
+Or, for irssi 0.8.18 or higher:
+
+/SET hilight_nick_matches_everywhere ON
+
+To get beeps on private messages or highlights:
+
+/SET beep_msg_level MSGS HILIGHT DCCMSGS
+
+No other irssi settings are needed (don’t enable bell_beeps), but there may be
+settings to change in your terminal multiplexer (screen/tmux), your terminal,
+or your desktop environment.
+
+2. Basic user interface usage
+
+Windows can be scrolled up/down with PgUp and PgDown keys. If they don’t work
+for you, use Meta-p and Meta-n keys. For jumping to beginning or end of the
+buffer, use /SB HOME and /SB END commands.
+
+By default, irssi uses “hidden windows” for everything. Hidden windows are
+created every time you /JOIN a channel or /QUERY someone. There’s several ways
+you can change between these windows:
+
+Meta-1, Meta-2, .. Meta-0 - Jump directly between windows 1-10
+Meta-q .. Meta-o - Jump directly between windows 11-19
+/WINDOW - Jump to any window with specified number
+Ctrl-P, Ctrl-N - Jump to previous / next window
+
+Clearly the easiest way is to use Meta-number keys. Meta usually means the ALT
+key, but if that doesn’t work, you can use ESC.
+
+Mac OS X users with ALT key issues might prefer using [2]iTerm2 instead of the
+default terminal emulator.
+
+Alt key as meta, for xterm/rxvt users
+
+If you use xterm or rxvt, you may need to set a few X resources:
+
+ XTerm*eightBitInput: false
+ XTerm*metaSendsEscape: true
+
+With rxvt, you can also specify which key acts as Meta key. So if you want to
+use ALT instead of Windows key for it, use:
+
+ rxvt*modifier: alt
+
+You could do this by changing the X key mappings:
+
+ xmodmap -e "keysym Alt_L = Meta_L Alt_L"
+
+And how exactly do you set these X resources? For Debian, there’s /etc/X11/
+Xresources/xterm file where you can put them and it’s read automatically when X
+starts. ~/.Xresources and ~/.Xdefaults files might also work. If you can’t get
+anything else to work, just copy and paste those lines to ~/.Xresources and
+directly call xrdb -merge ~/.Xresources in some xterm. The resources affect
+only the new xterms you start, not existing ones.
+
+Split windows and window items
+
+Note: [3]this guide might be a better introduction to window splits
+
+Irssi also supports split windows, they’ve had some problems in past but I
+think they should work pretty well now :) Here’s some commands related to them:
+
+/WINDOW NEW - Create new split window
+/WINDOW NEW HIDE - Create new hidden window
+/WINDOW CLOSE - Close split or hidden window
+
+/WINDOW HIDE [|] - Make the split window hidden window
+/WINDOW SHOW | - Make the hidden window a split window
+
+/WINDOW SHRINK [] - Shrink the split window
+/WINDOW GROW [] - Grow the split window
+/WINDOW BALANCE - Balance the sizes of all split windows
+
+By default, irssi uses “sticky windowing” for split windows. This means that
+windows created inside one split window cannot be moved to another split window
+without some effort. For example you could have following window layout:
+
+ Split window 1: win#1 - Status window, win#2 - Messages window
+ Split window 2: win#3 - IRCnet/#channel1, win#4 - IRCnet/#channel2
+ Split window 3: win#5 - efnet/#channel1, win#6 - efnet/#channel2
+
+When you are in win#1 and press ALT-6, irssi jumps to split window #3 and moves
+the efnet/#channel2 the active window.
+
+With non-sticky windowing the windows don’t have any relationship with split
+windows, pressing ALT-6 in win#1 moves win#6 to split window 1 and sets it
+active, except if win#6 was already visible in some other split window irssi
+just changes to that split window. This it the way windows work with ircii, if
+you prefer it you can set it with
+
+/SET autostick_split_windows OFF
+
+Each window can have multiple channels, queries and other “window items” inside
+them. If you don’t like windows at all, you disable automatic creating of them
+with
+
+/SET autocreate_windows OFF
+
+And if you keep all channels in one window, you most probably want the channel
+name printed in each line:
+
+/SET print_active_channel ON
+
+If you want to group only some channels or queries in one window, use
+
+/JOIN -window #channel
+/QUERY -window nick
+
+3. Server and channel automation
+
+Irssi’s multiple IRC network support is IMHO very good - at least compared to
+other clients :) Even if you’re only in one IRC network you should group all
+your servers to be in the same IRC network as this helps with reconnecting if
+your primary server breaks and is probably useful in some other ways too :) For
+information how to actually use irssi correctly with multiple servers see the
+chapter 6.
+
+First you need to have your IRC network set, use /NETWORK command to see if
+it’s already there. If it isn’t, use /NETWORK ADD yournetwork. If you want to
+execute some commands automatically when you’re connected to some network, use
+-autosendcmd option. Here’s some examples:
+
+/NETWORK ADD -autosendcmd '^msg bot invite' IRCnet
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
+
+After that you need to add your servers. For example:
+
+/SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
+/SERVER ADD -auto -network worknet irc.mycompany.com 6667 password
+
+The -auto option specifies that this server is automatically connected at
+startup. You don’t need to make more than one server with -auto option to one
+IRC network, other servers are automatically connected in same network if the
+-auto server fails.
+
+And finally channels:
+
+/CHANNEL ADD -auto -bots *!*user@host -botcmd "/^msg $0 op pass" #irssi efnet
+/CHANNEL ADD -auto #secret IRCnet password
+
+-bots and -botcmd should be the only ones needing a bit of explaining. They’re
+used to send commands automatically to bot when channel is joined, usually to
+get ops automatically. You can specify multiple bot masks with -bots option
+separated with spaces (and remember to quote the string then). The $0 in
+-botcmd specifies the first found bot in the list. If you don’t need the bot
+masks (ie. the bot is always with the same nick, like chanserv) you can give
+only the -botcmd option and the command is always sent.
+
+4. Setting up windows and automatically restoring them at startup
+
+First connect to all the servers, join the channels and create the queries you
+want. If you want to move the windows or channels around use commands:
+
+/WINDOW MOVE LEFT/RIGHT/number - move window elsewhere
+/WINDOW ITEM MOVE | - move channel/query to another window
+
+When everything looks the way you like, use /LAYOUT SAVE command (and /SAVE, if
+you don’t have autosaving enabled) and when you start irssi next time, irssi
+remembers the positions of the channels, queries and everything. This
+“remembering” doesn’t mean that simply using /LAYOUT SAVE would automatically
+make irssi reconnect to all servers and join all channels, you’ll need the /
+SERVER ADD -auto and /CHANNEL ADD -auto commands to do that.
+
+If you want to change the layout, you just rearrange the layout like you want
+it and use /LAYOUT SAVE again. If you want to remove the layout for some
+reason, use /LAYOUT RESET.
+
+5. Status and msgs windows & message levels
+
+By default, all the “extra messages” go to status window. This means pretty
+much all messages that don’t clearly belong to some channel or query. Some
+people like it, some don’t. If you want to remove it, use
+
+/SET use_status_window OFF
+
+This doesn’t have any effect until you restart irssi. If you want to remove it
+immediately, just /WINDOW CLOSE it.
+
+Another common window is “messages window”, where all private messages go. By
+default it’s disabled and query windows are created instead. To make all
+private messages go to msgs window, say:
+
+/SET use_msgs_window ON
+/SET autocreate_query_level DCCMSGS (or if you don't want queries to
+ dcc chats either, say NONE)
+
+use_msgs_window either doesn’t have any effect until restarting irssi. To
+create it immediately say:
+
+/WINDOW NEW HIDE - create the window
+/WINDOW NAME (msgs) - name it to "(msgs)"
+/WINDOW LEVEL MSGS - make all private messages go to this window
+/WINDOW MOVE 1 - move it to first window
+
+Note that neither use_msgs_window nor use_status_window have any effect at all
+if /LAYOUT SAVE has been used.
+
+This brings us to message levels.. What are they? All messages that irssi
+prints have one or more “message levels”. Most common are PUBLIC for public
+messages in channels, MSGS for private messages and CRAP for all sorts of
+messages with no real classification. You can get a whole list of levels with
+
+/HELP levels
+
+Status window has message level ALL -MSGS, meaning that all messages, except
+private messages, without more specific place go to status window. The -MSGS is
+there so it doesn’t conflict with messages window.
+
+6. How support for multiple servers works in irssi
+
+ircii and several other clients support multiple servers by placing the
+connection into some window. IRSSI DOES NOT. There is no required relationship
+between window and server. You can connect to 10 servers and manage them all in
+just one window, or join channel in each one of them to one single window if
+you really want to. That being said, here’s how you do connect to new server
+without closing the old connection:
+
+/CONNECT irc.server.org
+
+Instead of the /SERVER which disconnects the existing connection. To see list
+of all active connections, use /SERVER without any parameters. You should see a
+list of something like:
+
+ -!- IRCNet: irc.song.fi:6667 (IRCNet)
+ -!- OFTC: irc.oftc.net:6667 (OFTC)
+ -!- RECON-1: 192.168.0.1:6667 () (02:59 left before reconnecting)
+
+Here you see that we’re connected to IRCNet and OFTC networks. The IRCNet at
+the beginning is called the “server tag” while the (IRCnet) at the end shows
+the IRC network. Server tag specifies unique tag to refer to the server,
+usually it’s the same as the IRC network. When the IRC network isn’t known it’s
+some part of the server name. When there’s multiple connections to same IRC
+network or server, irssi adds a number after the tag so there could be network,
+network2, network3 etc.
+
+Server tags beginning with RECON- mean server reconnections. Above we see that
+connection to server at 192.168.0.1 wasn’t successful and irssi will try to
+connect it again in 3 minutes.
+
+To disconnect one of the servers, or to stop irssi from reconnecting, use
+
+/DISCONNECT network - disconnect server with tag "network"
+/DISCONNECT recon-1 - stop trying to reconnect to RECON-1 server
+/RMRECONNS - stop all server reconnections
+
+/RECONNECT recon-1 - immediately try reconnecting back to RECON-1
+/RECONNECT ALL - immediately try reconnecting back to all
+ servers in reconnection queue
+
+Now that you’re connected to all your servers, you’ll have to know how to
+specify which one of them you want to use. One way is to have an empty window,
+like status or msgs window. In it, you can specify which server to set active
+with
+
+/WINDOW SERVER tag - set server "tag" active
+Ctrl-X - set the next server in list active
+
+When the server is active, you can use it normally. When there’s multiple
+connected servers, irssi adds [servertag] prefix to all messages in non-channel
+/query messages so you’ll know where it came from.
+
+Several commands also accept -servertag option to specify which server it
+should use:
+
+/MSG -tag nick message
+/JOIN -tag #channel
+/QUERY -tag nick
+
+/MSG tab completion also automatically adds the -tag option when nick isn’t in
+active server.
+
+Window’s server can be made sticky. When sticky, it will never automatically
+change to anything else, and if server gets disconnected, the window won’t have
+any active server. When the server gets connected again, it is automatically
+set active in the window. To set the window’s server sticky use
+
+/WINDOW SERVER -sticky tag
+
+This is useful if you wish to have multiple status or msgs windows, one for
+each server. Here’s how to do them (repeat for each server)
+
+/WINDOW NEW HIDE
+/WINDOW NAME (status)
+/WINDOW LEVEL ALL -MSGS
+/WINDOW SERVER -sticky network
+
+/WINDOW NEW HIDE
+/WINDOW NAME (msgs)
+/WINDOW LEVEL MSGS
+/WINDOW SERVER -sticky network
+
+7. /LASTLOG and jumping around in scrollback
+
+/LASTLOG command can be used for searching texts in scrollback buffer. Simplest
+usages are
+
+/LASTLOG word - print all lines with "word" in them
+/LASTLOG word 10 - print last 10 occurances of "word"
+/LASTLOG -topics - print all topic changes
+
+If there’s more than 1000 lines to be printed, irssi thinks that you probably
+made some mistake and won’t print them without -force option. If you want to
+save the full lastlog to file, use
+
+/LASTLOG -file ~/irc.log
+
+With -file option you don’t need -force even if there’s more than 1000 lines. /
+LASTLOG has a lot of other options too, see /HELP lastlog for details.
+
+Once you’ve found the lines you were interested in, you might want to check the
+discussion around them. Irssi has /SCROLLBACK (or alias /SB) command for
+jumping around in scrollback buffer. Since /LASTLOG prints the timestamp when
+the message was originally printed, you can use /SB GOTO hh:mm to jump directly
+there. To get back to the bottom of scrollback, use /SB END command.
+
+8. Logging
+
+Irssi can automatically log important messages when you’re set away (/AWAY
+reason). When you set yourself unaway (/AWAY), the new messages in away log are
+printed to screen. You can configure it with:
+
+/SET awaylog_level MSGS HILIGHT - Specifies what messages to log
+/SET awaylog_file ~/.irssi/away.log - Specifies the file to use
+
+Easiest way to start logging with Irssi is to use autologging. With it Irssi
+logs all channels and private messages to specified directory. You can turn it
+on with
+
+/SET autolog ON
+
+By default it logs pretty much everything execept CTCPS or CRAP (/WHOIS
+requests, etc). You can specify the logging level yourself with
+
+/SET autolog_level ALL -CRAP -CLIENTCRAP -CTCPS (this is the default)
+
+By default irssi logs to ~/irclogs//.log. You can change this with
+
+/SET autolog_path ~/irclogs/$tag/$0.log (this is the default)
+
+The path is automatically created if it doesn’t exist. $0 specifies the target
+(channel/nick). You can make irssi automatically rotate the logs by adding date
+/time formats to the file name. The formats are in “man strftime” format. For
+example
+
+/SET autolog_path ~/irclogs/%Y/$tag/$0.%m-%d.log
+
+For logging only some specific channels or nicks, see /HELP log
+
+9. Changing keyboard bindings
+
+You can change any keyboard binding that terminal lets irssi know about. It
+doesn’t let irssi know everything, so for example shift-backspace can’t be
+bound unless you modify xterm resources somehow.
+
+/HELP bind tells pretty much everything there is to know about keyboard
+bindings. However, there’s the problem of how to bind some non-standard keys.
+They might differ a bit with each terminal, so you’ll need to find out what
+exactly the keypress produces. Easiest way to check that would be to see what
+it prints in cat. Here’s an example for pressing F1 key:
+
+ [user@host] ~% cat
+ ^[OP
+
+So in irssi you would use /BIND ^[OP /ECHO F1 pressed. If you use multiple
+terminals which have different bindings for the key, it would be better to use
+eg.:
+
+/BIND ^[OP key F1
+/BIND ^[11~ key F1
+/BIND F1 /ECHO F1 pressed.
+
+10. Proxies and IRC bouncers
+
+Irssi supports connecting to IRC servers via a proxy. All server connections
+are then made through it, and if you’ve set up everything properly, you don’t
+need to do any /QUOTE SERVER commands manually.
+
+Here’s an example: You have your bouncer (lets say, BNC or BNC-like) listening
+in irc.bouncer.org port 5000. You want to use it to connect to servers
+irc.dalnet and irc.efnet.org. First you’d need to setup the bouncer:
+
+/SET use_proxy ON
+/SET proxy_address irc.bouncer.org
+/SET proxy_port 5000
+
+/SET proxy_password YOUR_BNC_PASSWORD_HERE
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+
+Then you’ll need to add the server connections. These are done exactly as if
+you’d want to connect directly to them. Nothing special about them:
+
+/SERVER ADD -auto -network dalnet irc.dal.net
+/SERVER ADD -auto -network efnet irc.efnet.org
+
+With the proxy /SETs however, irssi now connects to those servers through your
+BNC. All server connections are made through them so you can just forget that
+your bouncer even exists.
+
+If you don’t want to use the proxy for some reason, there’s -noproxy option
+which you can give to /SERVER and /SERVER ADD commands.
+
+Proxy specific settings:
+
+All proxies have these settings in common:
+
+/SET use_proxy ON
+/SET proxy_address
+/SET proxy_port
+
+HTTP proxy
+
+Use these settings with HTTP proxies:
+
+/SET -clear proxy_password
+/EVAL SET proxy_string CONNECT %s:%d HTTP/1.0\n\n
+
+BNC
+
+/SET proxy_password your_pass
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+
+dircproxy
+
+dircproxy separates the server connections by passwords. So, if you for example
+have network connection with password ircpass and OFTC connection with
+oftcpass, you would do something like this:
+
+/SET -clear proxy_password
+/SET -clear proxy_string
+
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+
+The server name and port you give isn’t used anywhere, so you can put anything
+you want in there.
+
+psyBNC
+
+psyBNC has internal support for multiple servers. However, it could be a bit
+annoying to use, and some people just use different users for connecting to
+different servers. You can manage this in a bit same way as with dircproxy, by
+creating fake connections:
+
+/SET -clear proxy_password
+/SET -clear proxy_string
+
+/NETWORK ADD -user networkuser IRCnet
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/NETWORK ADD -user oftcuser OFTC
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+
+So, you’ll specify the usernames with /NETWORK ADD command, and the user’s
+password with /SERVER ADD.
+
+Irssi proxy
+
+Irssi contains it’s own proxy which you can build giving \--with-proxy option
+to configure. You’ll still need to run irssi in a screen to use it though.
+
+Irssi proxy is a bit different than most proxies, normally proxies create a new
+connection to IRC server when you connect to it, but irssi proxy shares your
+existing IRC connection(s) to multiple clients. And even more clearly: You can
+use only one IRC server connection to IRC with as many clients as you want. Can
+anyone figure out even more easier ways to say this, so I wouldn’t need to try
+to explain this thing for minutes every time? :)
+
+Irssi proxy supports sharing multiple server connections in different ports,
+like you can share network in port 2777 and efnet in port 2778.
+
+Usage in proxy side:
+
+/LOAD proxy
+/SET irssiproxy_password
+/SET irssiproxy_ports = ... (eg. IRCnet=2777 efnet=2778)
+
+NOTE: you MUST add all the servers you are using to server and network lists
+with /SERVER ADD and /NETWORK ADD. ..Except if you really don’t want to for
+some reason, and you only use one server connection, you may simply set:
+
+/SET irssiproxy_ports *=2777
+
+Usage in client side:
+
+Just connect to the irssi proxy like it is a normal server with password
+specified in /SET irssiproxy_password. For example:
+
+/SERVER ADD -network IRCnet my.irssi-proxy.org 2777 secret
+/SERVER ADD -network efnet my.irssi-proxy.org 2778 secret
+
+Irssi proxy works fine with other IRC clients as well.
+
+SOCKS
+
+Irssi can be compiled with socks support (\--with-socks option to configure),
+which requires “dante” and routes all connections through the proxy specified
+in the system-wide /etc/socks.conf. This method is known to have issues in Mac
+OS X.
+
+Note that /SET proxy settings don’t have anything to do with socks.
+
+Using [4]proxychains-ng is recommended over recompiling irssi.
+
+Others
+
+IRC bouncers usually work like IRC servers, and want a password. You can give
+it with:
+
+/SET proxy_password
+
+Irssi’s defaults for connect strings are
+
+/SET proxy_string CONNECT %s %d
+/SET proxy_string_after
+
+The proxy_string is sent before NICK/USER commands, the proxy_string_after is
+sent after them. %s and %d can be used with both of them.
+
+11. Irssi’s settings
+
+Here’s some settings you might want to change (the default value is shown):
+Also check the [5]Settings Documentation
+
+Queries
+
+/SET autocreate_own_query ON
+ Should new query window be created when you send message to someone (with /
+ MSG).
+/SET autocreate_query_level MSGS
+ New query window should be created when receiving messages with this level.
+ MSGS, DCCMSGS and NOTICES levels work currently. You can disable this with
+ /SET -clear autocreate_query_level.
+/SET autoclose_query 0
+ Query windows can be automatically closed after certain time of inactivity.
+ Queries with unread messages aren’t closed and active window is neither
+ never closed. The value is given in seconds.
+
+Windows
+
+/SET use_msgs_window OFF
+ Create messages window at startup. All private messages go to this window.
+ This only makes sense if you’ve disabled automatic query windows. Message
+ window can also be created manually with /WINDOW LEVEL MSGS, /WINDOW NAME
+ (msgs).
+/SET use_status_window ON
+ Create status window at startup. All messages that don’t really have better
+ place go here, like all /WHOIS replies etc. Status window can also be
+ created manually with /WINDOW LEVEL ALL -MSGS, /WINDOW NAME (status).
+/SET autocreate_windows ON
+ Should we create new windows for new window items or just place everything
+ in one window
+/SET autoclose_windows ON
+ Should window be automatically closed when the last item in them is removed
+ (ie. /PART, /UNQUERY).
+/SET reuse_unused_windows OFF
+ When finding where to place new window item (channel, query) Irssi first
+ tries to use already existing empty windows. If this is set ON, new window
+ will always be created for all window items. This setting is ignored if
+ autoclose_windows is set ON.
+/SET window_auto_change OFF
+ Should Irssi automatically change to automatically created windows -
+ usually queries when someone sends you a message. To prevent accidentally
+ sending text meant to some other channel/nick, Irssi clears the input
+ buffer when changing the window. The text is still in scrollback buffer,
+ you can get it back with pressing arrow up key.
+/SET print_active_channel OFF
+ When you keep more than one channel in same window, Irssi prints the
+ messages coming to active channel as text and other channels as
+ text. If this setting is set ON, the messages to active
+ channels are also printed in the latter way.
+/SET window_history OFF
+ Should command history be kept separate for each window.
+
+User information
+
+/SET nick
+ Your nick name
+/SET alternate_nick
+ Your alternate nick.
+/SET user_name
+ Your username, if you have ident enabled this doesn’t affect anything
+/SET real_name
+ Your real name.
+
+Server information
+
+/SET skip_motd OFF
+ Should we hide server’s MOTD (Message Of The Day).
+/SET server_reconnect_time 300
+ Seconds to wait before connecting to same server again. Don’t set this too
+ low since it usually doesn’t help at all - if the host is down, the few
+ extra minutes of waiting won’t hurt much.
+/SET lag_max_before_disconnect 300
+ Maximum server lag in seconds before disconnecting and trying to reconnect.
+ This happens mostly only when network breaks between you and IRC server.
+
+Appearance
+
+/SET timestamps ON
+ Show timestamps before each message.
+/SET hide_text_style OFF
+ Hide all bolds, underlines, MIRC colors, etc.
+/SET show_nickmode ON
+ Show the nick’s mode before nick in channels, ie. ops have <@nick>, voices
+ <+nick> and others < nick>
+/SET show_nickmode_empty ON
+ If the nick doesn’t have a mode, use one space. ie. ON: < nick>, OFF:
+
+/SET show_quit_once OFF
+ Show quit message only once in some of the channel windows the nick was in
+ instead of in all windows.
+/SET lag_min_show 100
+ Show the server lag in status bar if it’s bigger than this, the unit is 1/
+ 100 of seconds (ie. the default value of 100 = 1 second).
+/SET indent 10
+ When lines are longer than screen width they have to be split to multiple
+ lines. This specifies how much space to put at the beginning of the line
+ before the text begins. This can be overridden in text formats with %|
+ format.
+/SET activity_hide_targets
+ If you don’t want to see window activity in some certain channels or
+ queries, list them here. For example #boringchannel =bot1 =bot2. If any
+ highlighted text or message for you appears in that window, this setting is
+ ignored and the activity is shown.
+
+Nick completion
+
+/SET completion_auto OFF
+ Automatically complete the nick if line begins with start of nick and the
+ completion character. Learn to use the tab-completion instead, it’s a lot
+ better ;)
+/SET completion_char :
+ Completion character to use.
+
+For all the ircII people
+
+I don’t like automatic query windows, I don’t like status window, I do like
+msgs window where all messages go:
+
+/SET autocreate_own_query OFF
+/SET autocreate_query_level DCCMSGS
+/SET use_status_window OFF
+/SET use_msgs_window ON
+
+Disable automatic window closing when /PARTing channel or /UNQUERYing query:
+
+/SET autoclose_windows OFF
+/SET reuse_unused_windows ON
+
+Here’s the settings that make irssi work exactly like ircII in window
+management (send me a note if you can think of more):
+
+/SET autocreate_own_query OFF
+/SET autocreate_query_level NONE
+/SET use_status_window OFF
+/SET use_msgs_window OFF
+/SET reuse_unused_windows ON
+/SET windows_auto_renumber OFF
+
+/SET autostick_split_windows OFF
+/SET autoclose_windows OFF
+/SET print_active_channel ON
+
+12. Statusbar
+
+/STATUSBAR displays a list of the current statusbars, along with their position
+and visibility:
+
+ Name Type Placement Position Visible
+ window window bottom 0 always
+ window_inact window bottom 1 inactive
+ prompt root bottom 100 always
+ topic root top 1 always
+
+/STATUSBAR prints the statusbar settings (type, placement, position,
+visibility) as well as its items. /STATUSBAR ENABLE|DISABLE enables/
+disables the statusbar. /STATUSBAR RESET resets the statusbar to its
+default settings, or if the statusbar was created by you, it will be removed.
+
+The statusbar type can be either window or root. If the type is window, then a
+statusbar will be created for each split window, otherwise it will be created
+only once. Placement can be top or bottom, which refers to the top or bottom of
+the screen. Position is a number, the higher the value the lower it will appear
+in-screen. Visible can be always, active or inactive. Active/inactive is useful
+only with split windows; one split window is active and the rest are inactive.
+To adjust these settings, the following commands are available:
+
+/STATUSBAR TYPE window|root
+/STATUSBAR PLACEMENT top|bottom
+/STATUSBAR POSITION
+/STATUSBAR VISIBLE always|active|inactive
+
+Statusbar items can also be added or removed via command. Note that when
+loading new statusbar scripts that add items, you will need to specify where
+you want to show the item and how it is aligned. This can be accomplished using
+the below commands:
+
+/STATUSBAR ADD [-before | -after - ] [-priority #] [-alignment left|right]
-
+/STATUSBAR REMOVE
-
+
+For statusbar scripts, the item name is usually equivalent to the script name.
+The documentation of the script ought to tell you if this is not the case. For
+example, to add mail.pl before the window activity item, use: /STATUSBAR window
+ADD -before act mail.
+
+
+References:
+
+[1] http://www.gnu.org/licenses/fdl.html
+[2] https://www.iterm2.com/
+[3] http://quadpoint.org/articles/irssisplit/
+[4] https://github.com/rofl0r/proxychains-ng
+[5] https://irssi.org/documentation/settings/
diff --git a/syncdocs.sh b/syncdocs.sh
new file mode 100755
index 00000000..1187eec9
--- /dev/null
+++ b/syncdocs.sh
@@ -0,0 +1,101 @@
+#!/bin/sh -e
+# Run this to download FAQ and startup-HOWTO from irssi.org
+
+PKG_NAME="Irssi"
+
+site=https://irssi.org
+
+faq=$site/documentation/faq/
+howto=$site/documentation/startup/
+
+# remove everything until H1 and optionally 2 DIVs before the
+# FOOTER. May need to be adjusted as the source pages change
+pageclean_regex='s{.*(?=
\s*)?(\s*)?)}{\1\2}g;'
+
+srcdir=`dirname "$0"`
+test -z "$srcdir" && srcdir=.
+
+if test ! -f "$srcdir"/configure.ac; then
+ echo -n "**Error**: Directory \`$srcdir' does not look like the"
+ echo " top-level $PKG_NAME directory"
+ exit 1
+fi
+
+# detect downloader app
+downloader=false
+
+if type curl >/dev/null 2>&1 ; then
+ downloader="curl -Ssf"
+elif type wget >/dev/null 2>&1 ; then
+ downloader="wget -nv -O-"
+else
+ echo "**Error**: No wget or curl present"
+ echo "Install wget or curl, then run syncdocs.sh again"
+fi
+
+# detect html converter app
+converter=false
+if [ "$1" = "-any" ]; then
+ any=true
+else
+ any=false
+fi
+
+if type w3m >/dev/null 2>&1 ; then
+ converter="w3m -o display_link_number=1 -dump -T text/html"
+ any=true
+elif type lynx >/dev/null 2>&1 ; then
+ converter="lynx -dump -stdin -force_html"
+elif type elinks >/dev/null 2>&1 ; then
+ converter="elinks -dump -force-html"
+else
+ echo "**Error**: Neither w3m, nor lynx or elinks present"
+ echo "Install w3m, then run syncdocs.sh again"
+ exit 1
+fi
+
+if ! $any ; then
+ echo "**Error**: w3m not present"
+ echo "If you want to use lynx or elinks, run syncdocs.sh -any"
+ exit 1
+fi
+
+check_download() {
+ if test "$1" -ne 0 || test ! -e "$2" || test "$(wc -l "$2" | awk '{print $1}')" -le 1 ; then
+ rm -f "$2"
+ echo "... download failed ( $1 )"
+ exit 2
+ fi
+}
+
+download_it() {
+ echo "Downloading $1 from $2 ..."
+ ret=0
+ $downloader "$2" > "$3".tmp || ret=$?
+ check_download "$ret" "$3".tmp
+ perl -i -0777 -p -e "$pageclean_regex" "$3".tmp
+ perl -i -0777 -p -e 's{\A}{'""'\n}' "$3".tmp
+ perl -i -0777 -p -e 's{\[email protected\]}{user\@host}g' "$3".tmp
+ mv "$3".tmp "$3"
+}
+
+download_it "FAQ" "$faq" "$srcdir"/docs/faq.html
+download_it "Startup How-To" "$howto" "$srcdir"/docs/startup-HOWTO.html
+
+# .html -> .txt with lynx or elinks
+echo "Documentation: html -> txt..."
+
+cat "$srcdir"/docs/faq.html \
+ | LC_ALL=en_IE.utf8 $converter \
+ | perl -pe '
+ s/^ *//;
+ if ($_ eq "\n" && $state eq "Q") { $_ = ""; }
+ elsif (/^([QA]):/) { $state = $1 }
+ elsif ($_ ne "\n") { $_ = " $_"; };
+' > docs/faq.txt
+
+cat "$srcdir"/docs/startup-HOWTO.html \
+ | perl -pe "s/\\bhref=([\"\'])#.*?\\1//" \
+ | LC_ALL=en_IE.utf8 $converter > "$srcdir"/docs/startup-HOWTO.txt
From 9a3c0bce48d3f172d5638ecb37967528812129b1 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Tue, 24 Oct 2017 22:22:39 +0200
Subject: [PATCH 68/76] add a script to sync scripts as well
---
syncscripts.sh | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100755 syncscripts.sh
diff --git a/syncscripts.sh b/syncscripts.sh
new file mode 100755
index 00000000..eee95a5e
--- /dev/null
+++ b/syncscripts.sh
@@ -0,0 +1,38 @@
+#!/bin/sh -e
+# Run this script to sync dual lived scripts from scripts.irssi.org to scripts/
+
+PKG_NAME="Irssi"
+
+scriptbase=https://scripts.irssi.org/scripts
+
+srcdir=`dirname "$0"`
+test -z "$srcdir" && srcdir=.
+
+if test ! -f "$srcdir"/configure.ac; then
+ echo -n "**Error**: Directory \`$srcdir' does not look like the"
+ echo " top-level $PKG_NAME directory"
+ exit 1
+fi
+
+dl2='curl -Ssf'
+
+dl_it() {
+ echo "$1"
+ $dl2 -o "$srcdir/scripts/$1" "$scriptbase/$1"
+}
+
+for script in \
+ autoop.pl \
+ autorejoin.pl \
+ buf.pl \
+ dns.pl \
+ kills.pl \
+ mail.pl \
+ mlock.pl \
+ quitmsg.pl \
+ scriptassist.pl \
+ usercount.pl \
+ ;
+do
+ dl_it $script
+done
From ca3498d42d29383024382b0eb983f97ab4e6b614 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Wed, 25 Oct 2017 16:22:57 +0200
Subject: [PATCH 69/76] move some files into subdirs
---
Makefile.am | 21 ++++++-----------
autogen.sh | 27 +++++++++++++---------
configure.ac | 2 ++
themes/Makefile.am | 5 ++++
colorless.theme => themes/colorless.theme | 0
default.theme => themes/default.theme | 0
utils/Makefile.am | 4 ++++
file2header.sh => utils/file2header.sh | 0
irssi-version.sh => utils/irssi-version.sh | 0
syncdocs.sh => utils/syncdocs.sh | 3 ++-
syncscripts.sh => utils/syncscripts.sh | 1 +
syntax.pl => utils/syntax.pl | 0
12 files changed, 37 insertions(+), 26 deletions(-)
create mode 100644 themes/Makefile.am
rename colorless.theme => themes/colorless.theme (100%)
rename default.theme => themes/default.theme (100%)
create mode 100644 utils/Makefile.am
rename file2header.sh => utils/file2header.sh (100%)
rename irssi-version.sh => utils/irssi-version.sh (100%)
rename syncdocs.sh => utils/syncdocs.sh (98%)
rename syncscripts.sh => utils/syncscripts.sh (97%)
rename syntax.pl => utils/syntax.pl (100%)
diff --git a/Makefile.am b/Makefile.am
index 75d502f1..f52ac92f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,33 +7,26 @@ CLEANFILES = default-config.h default-theme.h
@MAINTAINER_MODE_TRUE@.PHONY: irssi-version.h
default-config.h: $(srcdir)/irssi.conf
- $(srcdir)/file2header.sh $(srcdir)/irssi.conf default_config > default-config.h
+ $(srcdir)/utils/file2header.sh $(srcdir)/irssi.conf default_config > default-config.h
-default-theme.h: $(srcdir)/default.theme
- $(srcdir)/file2header.sh $(srcdir)/default.theme default_theme > default-theme.h
+default-theme.h: $(srcdir)/themes/default.theme
+ $(srcdir)/utils/file2header.sh $(srcdir)/themes/default.theme default_theme > default-theme.h
irssi-version.h:
- VERSION="$(VERSION)" $(srcdir)/irssi-version.sh $(srcdir) | \
- cmp -s - $@ || VERSION="$(VERSION)" $(srcdir)/irssi-version.sh $(srcdir) >$@
+ VERSION="$(VERSION)" $(srcdir)/utils/irssi-version.sh $(srcdir) | \
+ cmp -s - $@ || VERSION="$(VERSION)" $(srcdir)/utils/irssi-version.sh $(srcdir) >$@
-SUBDIRS = src docs scripts
+SUBDIRS = src docs scripts themes utils
confdir = $(sysconfdir)
conf_DATA = irssi.conf
-themedir = $(datadir)/irssi/themes
-theme_DATA = default.theme colorless.theme
-
pkginclude_HEADERS = irssi-config.h irssi-version.h
EXTRA_DIST = \
ChangeLog \
autogen.sh \
README.md \
- file2header.sh \
$(conf_DATA) \
- $(theme_DATA) \
irssi-config.in \
- irssi-icon.png \
- irssi-version.sh \
- syntax.pl
+ irssi-icon.png
diff --git a/autogen.sh b/autogen.sh
index a9e354c9..9feb0872 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -3,21 +3,24 @@
PKG_NAME="Irssi"
-srcdir=`dirname $0`
+srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
+mydir=`pwd`
-if test ! -f $srcdir/configure.ac; then
- echo -n "**Error**: Directory \`$srcdir\' does not look like the"
+if test ! -f "$srcdir"/configure.ac; then
+ echo -n "**Error**: Directory \`$srcdir' does not look like the"
echo " top-level $PKG_NAME directory"
exit 1
fi
+cd "$srcdir"
+
# create help files
echo "Creating help files..."
-perl syntax.pl
+perl utils/syntax.pl
echo "Creating ChangeLog..."
-git log > $srcdir/ChangeLog
+git log > ChangeLog
if test "$?" -ne 0; then
echo "**Error**: ${PKG_NAME} Autogen must be run in a git clone, cannot proceed."
exit 1
@@ -38,17 +41,19 @@ fi
rm -f aclocal.m4
echo "Running autoreconf ..."
-autoreconf -i || exit 1
+autoreconf -i || exit $?
+
+# make sure perl hashes have correct length
+find src/perl -name '*.c' -o -name '*.xs' -exec grep -n hv_store {} + | perl -l -ne 'if (/"(\w+)",\s*(\d+)/ && $2 != length $1) { $X=1; print "Incorrect key length in $_" } END { exit $X }'
+
+cd "$mydir"
conf_flags="--enable-maintainer-mode"
if test x$NOCONFIGURE = x; then
- echo Running $srcdir/configure $conf_flags "$@" ...
- $srcdir/configure $conf_flags "$@" \
+ echo Running "$srcdir"/configure $conf_flags "$@" ...
+ "$srcdir"/configure $conf_flags "$@" \
&& echo Now type \`make\' to compile $PKG_NAME || exit 1
else
echo Skipping configure process.
fi
-
-# make sure perl hashes have correct length
-find src/perl -name '*.c' -o -name '*.xs' -exec grep -n hv_store {} + | perl -l -ne 'if (/"(\w+)",\s*(\d+)/ && $2 != length $1) { $X=1; print "Incorrect key length in $_" } END { exit $X }'
diff --git a/configure.ac b/configure.ac
index 9c026c5d..4b65d434 100644
--- a/configure.ac
+++ b/configure.ac
@@ -661,6 +661,8 @@ scripts/examples/Makefile
docs/Makefile
docs/help/Makefile
docs/help/in/Makefile
+utils/Makefile
+themes/Makefile
irssi-config
])
diff --git a/themes/Makefile.am b/themes/Makefile.am
new file mode 100644
index 00000000..ad0707c2
--- /dev/null
+++ b/themes/Makefile.am
@@ -0,0 +1,5 @@
+themedir = $(datadir)/irssi/themes
+theme_DATA = default.theme colorless.theme
+
+EXTRA_DIST = \
+ $(theme_DATA)
diff --git a/colorless.theme b/themes/colorless.theme
similarity index 100%
rename from colorless.theme
rename to themes/colorless.theme
diff --git a/default.theme b/themes/default.theme
similarity index 100%
rename from default.theme
rename to themes/default.theme
diff --git a/utils/Makefile.am b/utils/Makefile.am
new file mode 100644
index 00000000..be24c17f
--- /dev/null
+++ b/utils/Makefile.am
@@ -0,0 +1,4 @@
+EXTRA_DIST = \
+ file2header.sh \
+ irssi-version.sh \
+ syntax.pl
diff --git a/file2header.sh b/utils/file2header.sh
similarity index 100%
rename from file2header.sh
rename to utils/file2header.sh
diff --git a/irssi-version.sh b/utils/irssi-version.sh
similarity index 100%
rename from irssi-version.sh
rename to utils/irssi-version.sh
diff --git a/syncdocs.sh b/utils/syncdocs.sh
similarity index 98%
rename from syncdocs.sh
rename to utils/syncdocs.sh
index 1187eec9..e723edd2 100755
--- a/syncdocs.sh
+++ b/utils/syncdocs.sh
@@ -16,6 +16,7 @@ s{(<.*?)\sclass="(?:highlighter-rouge|highlight)"(.*?>)}{\1\2}g;'
srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
+srcdir="$srcdir"/..
if test ! -f "$srcdir"/configure.ac; then
echo -n "**Error**: Directory \`$srcdir' does not look like the"
@@ -94,7 +95,7 @@ cat "$srcdir"/docs/faq.html \
if ($_ eq "\n" && $state eq "Q") { $_ = ""; }
elsif (/^([QA]):/) { $state = $1 }
elsif ($_ ne "\n") { $_ = " $_"; };
-' > docs/faq.txt
+' > "$srcdir"/docs/faq.txt
cat "$srcdir"/docs/startup-HOWTO.html \
| perl -pe "s/\\bhref=([\"\'])#.*?\\1//" \
diff --git a/syncscripts.sh b/utils/syncscripts.sh
similarity index 97%
rename from syncscripts.sh
rename to utils/syncscripts.sh
index eee95a5e..533b77cc 100755
--- a/syncscripts.sh
+++ b/utils/syncscripts.sh
@@ -7,6 +7,7 @@ scriptbase=https://scripts.irssi.org/scripts
srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
+srcdir="$srcdir"/..
if test ! -f "$srcdir"/configure.ac; then
echo -n "**Error**: Directory \`$srcdir' does not look like the"
diff --git a/syntax.pl b/utils/syntax.pl
similarity index 100%
rename from syntax.pl
rename to utils/syntax.pl
From 8c0e0c81ee79684201020f843eeb0a4d656ed14c Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Wed, 25 Oct 2017 16:23:14 +0200
Subject: [PATCH 70/76] run syncscripts.sh
---
scripts/autorejoin.pl | 49 ++++++++++++++++++++++++++++---------------
scripts/mail.pl | 1 +
scripts/usercount.pl | 1 +
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/scripts/autorejoin.pl b/scripts/autorejoin.pl
index 42c97da7..e5be21b2 100644
--- a/scripts/autorejoin.pl
+++ b/scripts/autorejoin.pl
@@ -1,6 +1,9 @@
-# automatically rejoin to channel after kick
+# automatically rejoin to channel after kicked
# delayed rejoin: Lam 28.10.2001 (lam@lac.pl)
+# /SET autorejoin_channels #channel1 #channel2 ...
+# /SET autorejoin_delay 5
+
# NOTE: I personally don't like this feature, in most channels I'm in it
# will just result as ban. You've probably misunderstood the idea of /KICK
# if you kick/get kicked all the time "just for fun" ...
@@ -9,31 +12,22 @@ use Irssi;
use Irssi::Irc;
use strict;
use vars qw($VERSION %IRSSI);
-$VERSION = "1.0.0";
+$VERSION = "1.1.0";
%IRSSI = (
authors => "Timo 'cras' Sirainen, Leszek Matok",
contact => "lam\@lac.pl",
name => "autorejoin",
- description => "Automatically rejoin to channel after being kick, after a (short) user-defined delay",
+ description => "Automatically rejoin to channel after being kicked, after a (short) user-defined delay",
license => "GPLv2",
changed => "10.3.2002 14:00"
);
-
-# How many seconds to wait before the rejoin?
-# TODO: make this a /setting
-my $delay = 5;
-
-my @tags;
-my $acttag = 0;
-
sub rejoin {
my ( $data ) = @_;
- my ( $tag, $servtag, $channel, $pass ) = split( / +/, $data );
+ my ( $servtag, $channel, $pass ) = @{$data};
my $server = Irssi::server_find_tag( $servtag );
$server->send_raw( "JOIN $channel $pass" ) if ( $server );
- Irssi::timeout_remove( $tags[$tag] );
}
sub event_rejoin_kick {
@@ -48,10 +42,31 @@ sub event_rejoin_kick {
my $rejoinchan = $chanrec->{ name } if ( $chanrec );
my $servtag = $server->{ tag };
- Irssi::print "Rejoining $rejoinchan in $delay seconds.";
- $tags[$acttag] = Irssi::timeout_add( $delay * 1000, "rejoin", "$acttag $servtag $rejoinchan $password" );
- $acttag++;
- $acttag = 0 if ( $acttag > 60 );
+ # check if we want to autorejoin this channel
+ my $chans = Irssi::settings_get_str( 'autorejoin_channels' );
+
+ if ( $chans ) {
+ my $found = 0;
+ foreach my $chan ( split( /[ ,]/, $chans ) ) {
+ if ( lc( $chan ) eq lc( $channel ) ) {
+ $found = 1;
+ last;
+ }
+ }
+ return unless $found;
+ }
+
+ my @args = ($servtag, $rejoinchan, $password);
+ my $delay = Irssi::settings_get_int( "autorejoin_delay" );
+
+ if ($delay) {
+ Irssi::print "Rejoining $rejoinchan in $delay seconds.";
+ Irssi::timeout_add_once( $delay * 1000, "rejoin", \@args );
+ } else {
+ rejoin( \@args );
+ }
}
+Irssi::settings_add_int('misc', 'autorejoin_delay', 5);
+Irssi::settings_add_str('misc', 'autorejoin_channels', '');
Irssi::signal_add( 'event kick', 'event_rejoin_kick' );
diff --git a/scripts/mail.pl b/scripts/mail.pl
index ded02120..23f99c01 100644
--- a/scripts/mail.pl
+++ b/scripts/mail.pl
@@ -6,6 +6,7 @@ $VERSION = "2.92";
contact => "tss\@iki.fi, matti\@hiljanen.com, joost\@carnique.nl, bart\@dreamflow.nl",
name => "mail",
description => "Fully customizable mail counter statusbar item with multiple mailbox and multiple Maildir support",
+ sbitems => "mail",
license => "Public Domain",
url => "http://irssi.org, http://scripts.irssi.de",
);
diff --git a/scripts/usercount.pl b/scripts/usercount.pl
index 613da1de..650f9f36 100644
--- a/scripts/usercount.pl
+++ b/scripts/usercount.pl
@@ -7,6 +7,7 @@ $VERSION = "1.19";
contact => 'dgl@dgl.cx, tss@iki.fi, georg@boerde.de',
name => 'usercount',
description => 'Adds a usercount for a channel as a statusbar item',
+ sbitems => 'usercount',
license => 'GNU GPLv2 or later',
url => 'http://irssi.dgl.cx/',
changes => 'Only show halfops if server supports them',
From 96c7f68b3579ae5f83b635d946dc705d6322a16c Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Thu, 26 Oct 2017 16:15:25 +0200
Subject: [PATCH 71/76] clean up file path after move
---
src/perl/Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/perl/Makefile.am b/src/perl/Makefile.am
index 427c5492..db52744e 100644
--- a/src/perl/Makefile.am
+++ b/src/perl/Makefile.am
@@ -59,7 +59,7 @@ perl-signals-list.h: $(top_srcdir)/docs/signals.txt $(srcdir)/get-signals.pl
cat $(top_srcdir)/docs/signals.txt | $(perlpath) $(srcdir)/get-signals.pl > perl-signals-list.h
irssi-core.pl.h: irssi-core.pl
- $(top_srcdir)/file2header.sh $(srcdir)/irssi-core.pl irssi_core_code > irssi-core.pl.h
+ $(top_srcdir)/utils/file2header.sh $(srcdir)/irssi-core.pl irssi_core_code > irssi-core.pl.h
common_sources = \
common/Irssi.xs \
From 7e619ed990503faf45fc1ae1e28a3a6062dc7532 Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Mon, 30 Oct 2017 16:54:32 +0100
Subject: [PATCH 72/76] Update README.md
---
README.md | 128 ++++++++++++++++++++----------------------------------
1 file changed, 46 insertions(+), 82 deletions(-)
diff --git a/README.md b/README.md
index 8d91f4cb..0f54ccf5 100644
--- a/README.md
+++ b/README.md
@@ -1,109 +1,73 @@
-# Irssi
+# [Irssi](https://irssi.org/)
[![Build Status](https://travis-ci.org/irssi/irssi.svg?branch=master)](https://travis-ci.org/irssi/irssi)
Irssi is a modular chat client that is most commonly known for its
text mode user interface, but 80% of the code isn't text mode
-specific. We have a working but currently unmaintained GTK2 frontend
-called xirssi. Irssi comes with IRC support built in, and there are
+specific. Irssi comes with IRC support built in, and there are
third party [ICB](https://github.com/jperkin/irssi-icb),
[SILC](http://www.silcnet.org/),
[XMPP](http://cybione.org/~irssi-xmpp/) (Jabber),
-[PSYC](https://github.com/electric-blue/irssyc) and
+[PSYC](http://about.psyc.eu/Irssyc) and
[Quassel](https://github.com/phhusson/quassel-irssi) protocol modules
available.
-## Installation
+![irssi](https://user-images.githubusercontent.com/5665186/32180643-cf127f60-bd92-11e7-8aa2-882313ce1d8e.png)
-See the `INSTALL` file.
+## [Download information](https://irssi.org/download/)
-## Features
+#### Development source installation
-So what's so great about Irssi? Here's a list of some features I can
-think of currently:
+```
+git clone https://github.com/irssi/irssi
+cd irssi
+./autogen.sh
+make && sudo make install
+```
- - **Optional automation** - There's lots of things Irssi does for you
- automatically that some people like and others just hate. Things like:
- nick completion, creating new window for newly joined channel, creating
- queries when msgs/notices are received or when you send a msg, closing
- queries when it's been idle for some time, etc.
+#### Release source installation
- - **Multiserver friendly** - I think Irssi has clearly the best support
- for handling multiple server connections. You can have as many as you
- want in as many ircnets as you want. Having several connections in one
- server works too, for example when you hit the (ircnet's) 10
- channels/connection limit you can just create another connection and
- you hardly notice it. If connection to server is lost, Irssi tries to
- connect back until it's successful. Also channels you were joined
- before disconnection are restored, even if they're "temporarily
- unavailable" because of netsplits, Irssi keeps rejoining back to them.
- Also worth noticing - there's not that stupid "server is bound to this
- window, if this window gets closed the connection closes" thing that
- ircII based clients have.
+* Download [release](https://github.com/irssi/irssi/releases)
+* [Verify](https://irssi.org/download/#release-sources) signature
+```
+tar xJf irssi-*.tar.xz
+cd irssi-*
+./configure
+make && sudo make install
+```
- - **Channel automation** - You can specify what channels to join to
- immediately after connected to some server or IRC network. After joined
- to channel, Irssi can automatically request ops for you (or do
- anything, actually) from channel's bots.
+### Requirements
- - **Window content saving** - Say /LAYOUT SAVE when you've put all the
- channels and queries to their correct place, and after restarting
- Irssi, the channels will be joined back into windows where they were
- saved.
+- [glib-2.28](https://wiki.gnome.org/Projects/GLib) or greater
+- [openssl](https://www.openssl.org/)
+- [perl-5.6](https://www.perl.org/) or greater (for perl support)
+- terminfo or ncurses (for text frontend)
- - **Tab completing anything** - You can complete lots of things with tab:
- nicks, commands, command -options, file names, settings, text format
- names, channels and server names. There's also an excellent /msg
- completion that works transparently with multiple IRC networks.
- Completing channel nicks is also pretty intelligent, it first goes
- through the people who have talked to you recently, then the people who
- have talked to anyone recently and only then it fallbacks to rest of
- the nicks. You can also complete a set of words you've specified, for
- example homepage changes it to your actual home page URL.
+#### See the [INSTALL](INSTALL) file for details
- - **Excellent logging** - You can log any way you want and as easily or
- hard as you want. With autologging Irssi logs everything to specified
- directory, one file per channel/nick. ircII style /WINDOW LOG ON is
- also supported. There's also the "hard way" of logging - /LOG command
- which lets you specify exactly what you wish to log and where. Log
- rotating is supported with all the different logging methods, you can
- specify how often you want it to rotate and what kind of time stamp to
- use.
+## [Documentation](https://irssi.org/documentation/)
- - **Excellent ignoring** - You can most probably ignore anything any way
- you want. Nick masks, words, regular expressions. You can add
- exceptions to ignores. You can ignore other people's replies in
- channels to nicks you have ignored. You can also specify that the
- specific ignores work only in specific channel(s).
+* [Frequently Asked Questions](https://irssi.org/documentation/faq)
+* [Startup How-To](https://irssi.org/documentation/startup)
+* Check the built-in `/HELP`, it has all the details on command syntax
- - **Lastlog and scrollback handling** - /LASTLOG command has some new
- features: -new option checks only lines that came since you last did
- /LASTLOG command, -away option checks new lines since you last went
- away. Regular expression matches work also, of course. Going to some
- wanted place at scrollback has always been hard with non-GUI clients. A
- search command that jumps around in scrollback in GUI-style is still
- missing from Irssi, but there's something that's almost as good as it.
- /LASTLOG always shows timestamps when the line was printed, even if you
- didn't have timestamps on. Now doing /SB GOTO \ jumps
- directly to the position in scrollback you wanted. Great feature when
- you want to browse a bit of the discussion what happened when someone
- said your name (as seen in awaylog) or topic was changed (/last
- -topics)
+## [Themes](https://irssi-import.github.io/themes/)
-## Files
+## [Scripts](http://scripts.irssi.org/)
- - The `docs/` directory contains several documents:
- - `startup-HOWTO.txt` - new users should read this
- - `manual.txt` - manual I started writing but didn't get it very far :)
- - `perl.txt` - Perl scripting help
- - `formats.txt` - How to use colors, etc. with Irssi
- - `faq.txt` - Frequently Asked Questions
- - `special_vars.txt` - some predefined $variables you can use with Irssi
+## [Modules](https://irssi.org/modules/)
-## Bugs / Suggestions
+## [Security information](https://irssi.org/security/)
-See the `TODO` file, http://bugs.irssi.org and the GitHub issues if it is
-already listed in there; if not, open an issue on GitHub or send a mail to
-[staff@irssi.org](mailto:staff@irssi.org).
+Please report security issues to staff@irssi.org. Thanks!
-You can also contact the Irssi developers in #irssi on freenode.
+## [Bugs](https://github.com/irssi/irssi/issues) / Suggestions / [Contributing](https://irssi.org/development/)
+
+Check the GitHub issues if it is already listed in there; if not, open
+an issue on GitHub or send a mail to [staff@irssi.org](mailto:staff@irssi.org).
+
+Irssi is always looking for developers. Feel free to submit patches through
+GitHub pull requests.
+
+You can also contact the Irssi developers in
+[#irssi](https://irssi.org/support/irc/) on freenode.
From b0fa4dd46d8bf1cf63880fabf2105dd9134100df Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Wed, 1 Nov 2017 15:48:35 +0100
Subject: [PATCH 73/76] show initial nick and name on first start
---
src/core/settings.c | 10 +++++++
src/fe-common/core/Makefile.am | 1 +
src/fe-common/core/fe-settings.c | 7 ++++-
src/fe-common/core/fe-settings.h | 6 ++++
src/fe-text/irssi.c | 49 ++++++++++++++++----------------
src/fe-text/module-formats.c | 21 ++++++++++++++
src/fe-text/module-formats.h | 6 ++++
src/irc/core/irc-servers-setup.c | 11 ++++++-
8 files changed, 85 insertions(+), 26 deletions(-)
create mode 100644 src/fe-common/core/fe-settings.h
diff --git a/src/core/settings.c b/src/core/settings.c
index 4e0717cd..48d6640e 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -39,6 +39,7 @@ static GString *last_errors;
static GSList *last_invalid_modules;
static int fe_initialized;
static int config_changed; /* FIXME: remove after .98 (unless needed again) */
+static int user_settings_changed;
static GHashTable *settings;
static int timeout_tag;
@@ -464,6 +465,11 @@ SETTINGS_REC *settings_get_record(const char *key)
return g_hash_table_lookup(settings, key);
}
+static void sig_init_userinfo_changed(gpointer changedp)
+{
+ user_settings_changed = GPOINTER_TO_INT(changedp);
+}
+
static void sig_init_finished(void)
{
fe_initialized = TRUE;
@@ -479,6 +485,8 @@ static void sig_init_finished(void)
"updated, please /SAVE");
signal_emit("setup changed", 0);
}
+
+ signal_emit("settings userinfo changed", 1, GINT_TO_POINTER(user_settings_changed));
}
static void settings_clean_invalid_module(const char *module)
@@ -875,6 +883,7 @@ void settings_init(void)
timeout_tag = g_timeout_add(SETTINGS_AUTOSAVE_TIMEOUT,
(GSourceFunc) sig_autosave, NULL);
signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+ signal_add("irssi init userinfo changed", (SIGNAL_FUNC) sig_init_userinfo_changed);
signal_add("gui exit", (SIGNAL_FUNC) sig_autosave);
}
@@ -887,6 +896,7 @@ void settings_deinit(void)
{
g_source_remove(timeout_tag);
signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+ signal_remove("irssi init userinfo changed", (SIGNAL_FUNC) sig_init_userinfo_changed);
signal_remove("gui exit", (SIGNAL_FUNC) sig_autosave);
g_slist_foreach(last_invalid_modules, (GFunc) g_free, NULL);
diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am
index 29cc941a..cf4e8ee3 100644
--- a/src/fe-common/core/Makefile.am
+++ b/src/fe-common/core/Makefile.am
@@ -55,6 +55,7 @@ pkginc_fe_common_core_HEADERS = \
fe-exec.h \
fe-messages.h \
fe-queries.h \
+ fe-settings.h \
fe-tls.h \
formats.h \
hilight-text.h \
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index abbd45a8..de9f67a1 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -26,7 +26,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
-
+#include "fe-settings.h"
#include "levels.h"
#include "printtext.h"
#include "keyboard.h"
@@ -41,6 +41,11 @@ static void set_print(SETTINGS_REC *rec)
g_free(value);
}
+void fe_settings_set_print(const char *key)
+{
+ set_print(settings_get_record(key));
+}
+
static void set_print_pattern(const char *pattern)
{
GSList *sets, *tmp;
diff --git a/src/fe-common/core/fe-settings.h b/src/fe-common/core/fe-settings.h
new file mode 100644
index 00000000..dd33f223
--- /dev/null
+++ b/src/fe-common/core/fe-settings.h
@@ -0,0 +1,6 @@
+#ifndef __FE_CHANNELS_H
+#define __FE_CHANNELS_H
+
+void fe_settings_set_print(const char *key);
+
+#endif
diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
index b5df47c9..6349ae2a 100644
--- a/src/fe-text/irssi.c
+++ b/src/fe-text/irssi.c
@@ -31,6 +31,7 @@
#include "printtext.h"
#include "fe-common-core.h"
+#include "fe-settings.h"
#include "themes.h"
#include "term.h"
@@ -79,25 +80,8 @@ static int dirty, full_redraw;
static GMainLoop *main_loop;
int quitting;
-static const char *banner_text =
- " ___ _\n"
- "|_ _|_ _ _____(_)\n"
- " | || '_(_-<_-< |\n"
- "|___|_| /__/__/_|\n"
- "Irssi v" PACKAGE_VERSION " - http://www.irssi.org";
-
-static const char *firsttimer_text =
- "- - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"
- "Hi there! If this is your first time using Irssi, you\n"
- "might want to go to our website and read the startup\n"
- "documentation to get you going.\n\n"
- "Our community and staff are available to assist you or\n"
- "to answer any questions you may have.\n\n"
- "Use the /HELP command to get detailed information about\n"
- "the available commands.\n"
- "- - - - - - - - - - - - - - - - - - - - - - - - - - - -";
-
static int display_firsttimer = FALSE;
+static int user_settings_changed = 0;
static void sig_exit(void)
@@ -105,6 +89,11 @@ static void sig_exit(void)
quitting = TRUE;
}
+static void sig_settings_userinfo_changed(gpointer changedp)
+{
+ user_settings_changed = GPOINTER_TO_INT(changedp);
+}
+
/* redraw irssi's screen.. */
void irssi_redraw(void)
{
@@ -161,6 +150,7 @@ static void textui_init(void)
fe_common_irc_init();
theme_register(gui_text_formats);
+ signal_add("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed);
signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit);
}
@@ -199,14 +189,24 @@ static void textui_finish_init(void)
statusbar_redraw(NULL, TRUE);
if (servers == NULL && lookup_servers == NULL) {
- printtext(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT,
- "%s", banner_text);
+ printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_IRSSI_BANNER);
}
if (display_firsttimer) {
- printtext(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT,
- "%s", firsttimer_text);
+ printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_WELCOME_FIRSTTIME);
}
+
+ /* see irc-servers-setup.c:init_userinfo */
+ if (user_settings_changed)
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WELCOME_INIT_SETTINGS);
+ if (user_settings_changed & (1<<0))
+ fe_settings_set_print("real_name");
+ if (user_settings_changed & (1<<1))
+ fe_settings_set_print("user_name");
+ if (user_settings_changed & (1<<2))
+ fe_settings_set_print("nick");
+ if (user_settings_changed & (1<<3))
+ fe_settings_set_print("hostname");
}
static void textui_deinit(void)
@@ -223,6 +223,7 @@ static void textui_deinit(void)
#endif
dirty_check(); /* one last time to print any quit messages */
+ signal_remove("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed);
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
lastlog_deinit();
@@ -249,6 +250,7 @@ static void textui_deinit(void)
core_deinit();
}
+
static void check_files(void)
{
struct stat statbuf;
@@ -259,12 +261,11 @@ static void check_files(void)
}
}
-
int main(int argc, char **argv)
{
static int version = 0;
static GOptionEntry options[] = {
- { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display irssi version", NULL },
+ { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL },
{ NULL }
};
int loglev;
diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c
index 899827c2..c4606197 100644
--- a/src/fe-text/module-formats.c
+++ b/src/fe-text/module-formats.c
@@ -78,5 +78,26 @@ FORMAT_REC gui_text_formats[] =
{ "paste_warning", "Pasting $0 lines to $1. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.", 2, { 1, 0 } },
{ "paste_prompt", "Hit Ctrl-K to paste, Ctrl-C to abort?", 0 },
+ /* ---- */
+ { NULL, "Welcome", 0 },
+
+ { "irssi_banner",
+ " ___ _%:"
+ "|_ _|_ _ _____(_)%:"
+ " | || '_(_-<_-< |%:"
+ "|___|_| /__/__/_|%:"
+ "Irssi v$J - http://www.irssi.org", 0 },
+ { "welcome_firsttime",
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"
+ "Hi there! If this is your first time using Irssi, you%:"
+ "might want to go to our website and read the startup%:"
+ "documentation to get you going.%:%:"
+ "Our community and staff are available to assist you or%:"
+ "to answer any questions you may have.%:%:"
+ "Use the /HELP command to get detailed information about%:"
+ "the available commands.%:"
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - -", 0 },
+ { "welcome_init_settings", "The following settings were initialized", 0 },
+
{ NULL, NULL, 0 }
};
diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h
index 3fa8c511..05e9438d 100644
--- a/src/fe-text/module-formats.h
+++ b/src/fe-text/module-formats.h
@@ -52,6 +52,12 @@ enum {
TXT_PASTE_WARNING,
TXT_PASTE_PROMPT,
+ TXT_FILL_5, /* Welcome */
+
+ TXT_IRSSI_BANNER,
+ TXT_WELCOME_FIRSTTIME,
+ TXT_WELCOME_INIT_SETTINGS,
+
TXT_COUNT
};
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index bae7d3b4..22c86f57 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -116,14 +116,17 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
static void init_userinfo(void)
{
+ int changed;
const char *set, *nick, *user_name, *str;
+ changed = 0;
/* check if nick/username/realname wasn't read from setup.. */
set = settings_get_str("real_name");
if (set == NULL || *set == '\0') {
str = g_getenv("IRCNAME");
settings_set_str("real_name",
str != NULL ? str : g_get_real_name());
+ changed |= 1<<0;
}
/* username */
@@ -134,6 +137,7 @@ static void init_userinfo(void)
str != NULL ? str : g_get_user_name());
user_name = settings_get_str("user_name");
+ changed |= 1<<1;
}
/* nick */
@@ -143,15 +147,20 @@ static void init_userinfo(void)
settings_set_str("nick", str != NULL ? str : user_name);
nick = settings_get_str("nick");
+ changed |= 1<<2;
}
/* host name */
set = settings_get_str("hostname");
if (set == NULL || *set == '\0') {
str = g_getenv("IRCHOST");
- if (str != NULL)
+ if (str != NULL) {
settings_set_str("hostname", str);
+ changed |= 1<<3;
+ }
}
+
+ signal_emit("irssi init userinfo changed", 1, GINT_TO_POINTER(changed));
}
static void sig_server_setup_read(IRC_SERVER_SETUP_REC *rec, CONFIG_NODE *node)
From 4d6822b1c43d876856a5df07ce69fb4e67c3591a Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Wed, 1 Nov 2017 15:52:45 +0100
Subject: [PATCH 74/76] up abi
---
src/common.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/common.h b/src/common.h
index 159f7124..a7eaa7cf 100644
--- a/src/common.h
+++ b/src/common.h
@@ -6,7 +6,7 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
-#define IRSSI_ABI_VERSION 11
+#define IRSSI_ABI_VERSION 12
#define DEFAULT_SERVER_ADD_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697
From 66b2c9bc91a3b6e34ba59491c95747db75d21c6b Mon Sep 17 00:00:00 2001
From: LemonBoy
Date: Fri, 3 Nov 2017 16:37:04 +0100
Subject: [PATCH 75/76] Keep a copy of the strings coming from the config
The "HILIGHT_REC" structure used to keep a pointer to the "servertag"
string, owned by the "CONFIG_NODE", causing a double-free.
---
src/fe-common/core/hilight-text.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index 62e6f0de..b9912457 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -106,6 +106,7 @@ static void hilight_destroy(HILIGHT_REC *rec)
if (rec->channels != NULL) g_strfreev(rec->channels);
g_free_not_null(rec->color);
g_free_not_null(rec->act_color);
+ g_free_not_null(rec->servertag);
g_free(rec->text);
g_free(rec);
}
@@ -424,7 +425,7 @@ static void read_hilight_config(void)
CONFIG_NODE *node;
HILIGHT_REC *rec;
GSList *tmp;
- char *text, *color;
+ char *text, *color, *servertag;
hilights_destroy_all();
@@ -467,7 +468,9 @@ static void read_hilight_config(void)
rec->nickmask = config_node_get_bool(node, "mask", FALSE);
rec->fullword = config_node_get_bool(node, "fullword", FALSE);
rec->regexp = config_node_get_bool(node, "regexp", FALSE);
- rec->servertag = config_node_get_str(node, "servertag", NULL);
+ servertag = config_node_get_str(node, "servertag", NULL);
+ rec->servertag = servertag == NULL || *servertag == '\0' ? NULL :
+ g_strdup(servertag);
hilight_init_rec(rec);
node = iconfig_node_section(node, "channels", -1);
From 02c677f467b398f8b91b1e90544502ff98a6e0da Mon Sep 17 00:00:00 2001
From: ailin-nemui
Date: Fri, 10 Nov 2017 22:02:36 +0100
Subject: [PATCH 76/76] use enum
---
src/core/settings.c | 6 +++---
src/core/settings.h | 7 +++++++
src/fe-text/irssi.c | 15 +++++++--------
src/irc/core/irc-servers-setup.c | 12 ++++++------
4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/src/core/settings.c b/src/core/settings.c
index 48d6640e..3ebb9e4a 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -39,7 +39,7 @@ static GString *last_errors;
static GSList *last_invalid_modules;
static int fe_initialized;
static int config_changed; /* FIXME: remove after .98 (unless needed again) */
-static int user_settings_changed;
+static unsigned int user_settings_changed;
static GHashTable *settings;
static int timeout_tag;
@@ -467,7 +467,7 @@ SETTINGS_REC *settings_get_record(const char *key)
static void sig_init_userinfo_changed(gpointer changedp)
{
- user_settings_changed = GPOINTER_TO_INT(changedp);
+ user_settings_changed |= GPOINTER_TO_UINT(changedp);
}
static void sig_init_finished(void)
@@ -486,7 +486,7 @@ static void sig_init_finished(void)
signal_emit("setup changed", 0);
}
- signal_emit("settings userinfo changed", 1, GINT_TO_POINTER(user_settings_changed));
+ signal_emit("settings userinfo changed", 1, GUINT_TO_POINTER(user_settings_changed));
}
static void settings_clean_invalid_module(const char *module)
diff --git a/src/core/settings.h b/src/core/settings.h
index d174f250..b67a9e44 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -30,6 +30,13 @@ typedef struct {
char **choices;
} SETTINGS_REC;
+enum {
+ USER_SETTINGS_REAL_NAME = 0x1,
+ USER_SETTINGS_USER_NAME = 0x2,
+ USER_SETTINGS_NICK = 0x4,
+ USER_SETTINGS_HOSTNAME = 0x8,
+};
+
/* macros for handling the default Irssi configuration */
#define iconfig_get_str(a, b, c) config_get_str(mainconfig, a, b, c)
#define iconfig_get_int(a, b, c) config_get_int(mainconfig, a, b, c)
diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
index 6349ae2a..ef443670 100644
--- a/src/fe-text/irssi.c
+++ b/src/fe-text/irssi.c
@@ -81,7 +81,7 @@ static GMainLoop *main_loop;
int quitting;
static int display_firsttimer = FALSE;
-static int user_settings_changed = 0;
+static unsigned int user_settings_changed = 0;
static void sig_exit(void)
@@ -91,7 +91,7 @@ static void sig_exit(void)
static void sig_settings_userinfo_changed(gpointer changedp)
{
- user_settings_changed = GPOINTER_TO_INT(changedp);
+ user_settings_changed = GPOINTER_TO_UINT(changedp);
}
/* redraw irssi's screen.. */
@@ -199,13 +199,13 @@ static void textui_finish_init(void)
/* see irc-servers-setup.c:init_userinfo */
if (user_settings_changed)
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WELCOME_INIT_SETTINGS);
- if (user_settings_changed & (1<<0))
+ if (user_settings_changed & USER_SETTINGS_REAL_NAME)
fe_settings_set_print("real_name");
- if (user_settings_changed & (1<<1))
+ if (user_settings_changed & USER_SETTINGS_USER_NAME)
fe_settings_set_print("user_name");
- if (user_settings_changed & (1<<2))
+ if (user_settings_changed & USER_SETTINGS_NICK)
fe_settings_set_print("nick");
- if (user_settings_changed & (1<<3))
+ if (user_settings_changed & USER_SETTINGS_HOSTNAME)
fe_settings_set_print("hostname");
}
@@ -222,7 +222,7 @@ static void textui_deinit(void)
fe_perl_deinit();
#endif
- dirty_check(); /* one last time to print any quit messages */
+ dirty_check(); /* one last time to print any quit messages */
signal_remove("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed);
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
@@ -250,7 +250,6 @@ static void textui_deinit(void)
core_deinit();
}
-
static void check_files(void)
{
struct stat statbuf;
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index 22c86f57..e79557ab 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -116,7 +116,7 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
static void init_userinfo(void)
{
- int changed;
+ unsigned int changed;
const char *set, *nick, *user_name, *str;
changed = 0;
@@ -126,7 +126,7 @@ static void init_userinfo(void)
str = g_getenv("IRCNAME");
settings_set_str("real_name",
str != NULL ? str : g_get_real_name());
- changed |= 1<<0;
+ changed |= USER_SETTINGS_REAL_NAME;
}
/* username */
@@ -137,7 +137,7 @@ static void init_userinfo(void)
str != NULL ? str : g_get_user_name());
user_name = settings_get_str("user_name");
- changed |= 1<<1;
+ changed |= USER_SETTINGS_USER_NAME;
}
/* nick */
@@ -147,7 +147,7 @@ static void init_userinfo(void)
settings_set_str("nick", str != NULL ? str : user_name);
nick = settings_get_str("nick");
- changed |= 1<<2;
+ changed |= USER_SETTINGS_NICK;
}
/* host name */
@@ -156,11 +156,11 @@ static void init_userinfo(void)
str = g_getenv("IRCHOST");
if (str != NULL) {
settings_set_str("hostname", str);
- changed |= 1<<3;
+ changed |= USER_SETTINGS_HOSTNAME;
}
}
- signal_emit("irssi init userinfo changed", 1, GINT_TO_POINTER(changed));
+ signal_emit("irssi init userinfo changed", 1, GUINT_TO_POINTER(changed));
}
static void sig_server_setup_read(IRC_SERVER_SETUP_REC *rec, CONFIG_NODE *node)