diff options
-rw-r--r-- | docs/capsicum.txt | 1 | ||||
-rw-r--r-- | docs/help/in/network.in | 1 | ||||
-rw-r--r-- | src/core/capsicum.c | 49 | ||||
-rw-r--r-- | src/core/network.c | 1 | ||||
-rw-r--r-- | src/fe-common/core/themes.c | 7 | ||||
-rw-r--r-- | src/fe-common/irc/fe-ircnet.c | 11 | ||||
-rw-r--r-- | src/irc/core/irc-chatnets.c | 7 | ||||
-rw-r--r-- | src/irc/core/irc-chatnets.h | 1 | ||||
-rw-r--r-- | src/irc/core/irc-servers-setup.c | 5 |
9 files changed, 76 insertions, 7 deletions
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 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/capsicum.c b/src/core/capsicum.c index 3b0708cb..568b5542 100644 --- a/src/core/capsicum.c +++ b/src/core/capsicum.c @@ -32,12 +32,14 @@ #include "settings.h" #include "signals.h" -#include <sys/types.h> +#include <sys/param.h> #include <sys/capsicum.h> +#include <sys/filio.h> #include <sys/nv.h> #include <sys/procdesc.h> #include <sys/socket.h> #include <string.h> +#include <termios.h> #define OPCODE_CONNECT 1 #define OPCODE_GETHOSTBYNAME 2 @@ -181,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] != '/' || @@ -359,6 +365,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; @@ -410,6 +448,13 @@ static void cmd_capsicum_enter(void) */ signal(SIGCHLD, SIG_IGN); + 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; + } + error = cap_enter(); if (error != 0) { signal_emit("capability mode failed", 1, strerror(errno)); @@ -444,7 +489,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); diff --git a/src/core/network.c b/src/core/network.c index 4494dbc6..b38c9102 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -489,6 +489,7 @@ int net_gethostbyaddr(IPADDR *ip, char **name) int net_ip2host(IPADDR *ip, char *host) { + host[0] = '\0'; return inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN) ? 0 : -1; } 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, '%'); } } 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 <nick>] [-user <user>] [-realname <name>] +/* SYNTAX: NETWORK ADD|MODIFY [-nick <nick>] [-alternate_nick <nick>] [-user <user>] [-realname <name>] [-host <host>] [-usermode <mode>] [-autosendcmd <cmd>] [-querychans <count>] [-whois <count>] [-msgs <count>] [-kicks <count>] [-modes <count>] [-cmdspeed <ms>] @@ -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-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 6040d3a5..bae7d3b4 100644 --- a/src/irc/core/irc-servers-setup.c +++ b/src/irc/core/irc-servers-setup.c @@ -69,7 +69,10 @@ 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->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); |