From 58c343f4a85b8fcafc4e444e7a7f38a1f4293303 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 Mar 2016 21:12:28 -0500 Subject: [PATCH 1/5] authd: also check size correctly --- authd/authd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authd/authd.c b/authd/authd.c index 8040406c8..202dae8c3 100644 --- a/authd/authd.c +++ b/authd/authd.c @@ -64,7 +64,7 @@ handle_reload(int parc, char *parv[]) if(parc < 2) { /* Reload all handlers */ - for(size_t i = 0; i < sizeof(authd_reload_handlers); i++) + for(size_t i = 0; i < 256; i++) { if ((handler = authd_reload_handlers[(unsigned char) i]) != NULL) handler(parv[1][0]); From 0a659bf0ab74e7f93840877eae51ac2d65a6fb6c Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Fri, 25 Mar 2016 21:57:42 -0500 Subject: [PATCH 2/5] Port notice stuff over from authd-framework-2 and use it. This allows things like oper warnings from authd using the W message type also. --- authd/Makefile.am | 2 +- authd/authd.c | 5 ++++- authd/notice.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ authd/notice.h | 35 ++++++++++++++++++++++++++++++++++ ircd/authd.c | 33 ++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 authd/notice.c create mode 100644 authd/notice.h diff --git a/authd/Makefile.am b/authd/Makefile.am index 1b8ebf710..a26fdb390 100644 --- a/authd/Makefile.am +++ b/authd/Makefile.am @@ -3,5 +3,5 @@ AM_CFLAGS=$(WARNFLAGS) AM_CPPFLAGS = -I../include -I../librb/include -authd_SOURCES = authd.c res.c reslib.c reslist.c getnameinfo.c getaddrinfo.c dns.c +authd_SOURCES = authd.c res.c reslib.c reslist.c getnameinfo.c getaddrinfo.c dns.c notice.c authd_LDADD = ../librb/src/librb.la diff --git a/authd/authd.c b/authd/authd.c index 202dae8c3..7f210f628 100644 --- a/authd/authd.c +++ b/authd/authd.c @@ -20,6 +20,7 @@ #include "authd.h" #include "dns.h" +#include "notice.h" #define MAXPARA 10 @@ -47,8 +48,10 @@ handle_stat(int parc, char *parv[]) authd_stat_handler handler; if(parc < 3) - /* XXX Should log this somehow */ + { + warn_opers(L_CRIT, "BUG: handle_stat received too few parameters (at least 3 expected, got %d)", parc); return; + } if (!(handler = authd_stat_handlers[(unsigned char)parv[2][0]])) return; diff --git a/authd/notice.c b/authd/notice.c new file mode 100644 index 000000000..3e1d3f8a7 --- /dev/null +++ b/authd/notice.c @@ -0,0 +1,48 @@ +/* authd/notice.c - send notices back to the ircd and to clients + * Copyright (c) 2016 Elizabeth Myers + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "authd.h" +#include "notice.h" + +/* Send a notice to a client */ +void notice_client(uint32_t cid, const char *fmt, ...) +{ + char buf[BUFSIZE]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + rb_helper_write(authd_helper, "N %x :%s", cid, buf); +} + +/* Send a warning to the IRC daemon for logging, etc. */ +void warn_opers(notice_level_t level, const char *fmt, ...) +{ + char buf[BUFSIZE]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + rb_helper_write(authd_helper, "W %c :%s", level, buf); +} diff --git a/authd/notice.h b/authd/notice.h new file mode 100644 index 000000000..1e48bccfe --- /dev/null +++ b/authd/notice.h @@ -0,0 +1,35 @@ +/* authd/notice.h - send notices back to the ircd and to clients + * Copyright (c) 2016 Elizabeth Myers + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __CHARYBDIS_AUTHD_NOTICE_H__ +#define __CHARYBDIS_AUTHD_NOTICE_H__ + +typedef enum +{ + L_DEBUG = 'D', + L_INFO = 'I', + L_WARN = 'W', + L_CRIT ='C', +} notice_level_t; + +void notice_client(uint32_t cid, const char *fmt, ...); +void warn_opers(notice_level_t level, const char *fmt, ...); + +#endif /* __CHARYBDIS_AUTHD_NOTICE_H__ */ diff --git a/ircd/authd.c b/ircd/authd.c index 30dd30cbb..9c657a3b3 100644 --- a/ircd/authd.c +++ b/ircd/authd.c @@ -114,6 +114,39 @@ parse_authd_reply(rb_helper * helper) } dns_results_callback(parv[1], parv[2], parv[3], parv[4]); break; + case 'W': + if(parc != 3) + { + ilog(L_MAIN, "authd sent a result with wrong number of arguments: got %d", parc); + restart_authd(); + return; + } + + switch(*parv[2]) + { + case 'D': + sendto_realops_snomask(SNO_DEBUG, L_ALL, "authd debug: %s", parv[3]); + break; + case 'I': + sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd info: %s", parv[3]); + inotice("authd info: %s", parv[3]); + break; + case 'W': + sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd WARNING: %s", parv[3]); + iwarn("authd warning: %s", parv[3]); + break; + case 'C': + sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd CRITICAL: %s", parv[3]); + ierror("authd critical: %s", parv[3]); + break; + default: + sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd sent us an unknown oper notice type (%s): %s", parv[2], parv[3]); + ilog(L_MAIN, "authd unknown oper notice type (%s): %s", parv[2], parv[3]); + break; + } + + /* NOTREACHED */ + break; case 'X': case 'Y': case 'Z': From 1fcba3740482e30e305a0fb281a3ea81672a7b96 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Mar 2016 01:29:59 -0500 Subject: [PATCH 3/5] wsockd: conn_t.stream is not needed --- wsockd/wsockd.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/wsockd/wsockd.c b/wsockd/wsockd.c index 5c5262cc7..40ded64c2 100644 --- a/wsockd/wsockd.c +++ b/wsockd/wsockd.c @@ -82,7 +82,6 @@ typedef struct _conn uint64_t plain_in; uint64_t plain_out; uint8_t flags; - void *stream; } conn_t; #define FLAG_CORK 0x01 @@ -218,7 +217,6 @@ make_conn(mod_ctl_t * ctl, rb_fde_t *mod_fd, rb_fde_t *plain_fd) conn->mod_fd = mod_fd; conn->plain_fd = plain_fd; conn->id = -1; - conn->stream = NULL; rb_set_nb(mod_fd); rb_set_nb(plain_fd); return conn; From 05e0aa9ac97e9598b1f8986ad670858ba2f74168 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Mar 2016 05:30:52 -0500 Subject: [PATCH 4/5] wsockd: add some stub i/o code --- wsockd/wsockd.c | 184 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 151 insertions(+), 33 deletions(-) diff --git a/wsockd/wsockd.c b/wsockd/wsockd.c index 40ded64c2..7c6bbab24 100644 --- a/wsockd/wsockd.c +++ b/wsockd/wsockd.c @@ -111,6 +111,8 @@ typedef struct _conn static rb_dlink_list connid_hash_table[CONN_HASH_SIZE]; static rb_dlink_list dead_list; +static void conn_plain_read_shutdown_cb(rb_fde_t *fd, void *data); + #ifndef _WIN32 static void dummy_handler(int sig) @@ -207,6 +209,87 @@ clean_dead_conns(void *unused) dead_list.tail = dead_list.head = NULL; } +static void +mod_write_ctl(rb_fde_t *F, void *data) +{ + mod_ctl_t *ctl = data; + mod_ctl_buf_t *ctl_buf; + rb_dlink_node *ptr, *next; + int retlen, x; + + RB_DLINK_FOREACH_SAFE(ptr, next, ctl->writeq.head) + { + ctl_buf = ptr->data; + retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, + ctl_buf->buflen, ppid); + if(retlen > 0) + { + rb_dlinkDelete(ptr, &ctl->writeq); + for(x = 0; x < ctl_buf->nfds; x++) + rb_close(ctl_buf->F[x]); + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + + } + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) + exit(0); + + } + if(rb_dlink_list_length(&ctl->writeq) > 0) + rb_setselect(ctl->F, RB_SELECT_WRITE, mod_write_ctl, ctl); +} + +static void +mod_cmd_write_queue(mod_ctl_t * ctl, const void *data, size_t len) +{ + mod_ctl_buf_t *ctl_buf; + ctl_buf = rb_malloc(sizeof(mod_ctl_buf_t)); + ctl_buf->buf = rb_malloc(len); + ctl_buf->buflen = len; + memcpy(ctl_buf->buf, data, len); + ctl_buf->nfds = 0; + rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->writeq); + mod_write_ctl(ctl->F, ctl); +} + +static void +close_conn(conn_t * conn, int wait_plain, const char *fmt, ...) +{ + va_list ap; + char reason[128]; /* must always be under 250 bytes */ + uint8_t buf[256]; + int len; + if(IsDead(conn)) + return; + + rb_rawbuf_flush(conn->modbuf_out, conn->mod_fd); + rb_rawbuf_flush(conn->plainbuf_out, conn->plain_fd); + rb_close(conn->mod_fd); + SetDead(conn); + + rb_dlinkDelete(&conn->node, connid_hash(conn->id)); + + if(!wait_plain || fmt == NULL) + { + rb_close(conn->plain_fd); + rb_dlinkAdd(conn, &conn->node, &dead_list); + return; + } + + rb_setselect(conn->plain_fd, RB_SELECT_READ, conn_plain_read_shutdown_cb, conn); + rb_setselect(conn->plain_fd, RB_SELECT_WRITE, NULL, NULL); + + va_start(ap, fmt); + vsnprintf(reason, sizeof(reason), fmt, ap); + va_end(ap); + + buf[0] = 'D'; + uint32_to_buf(&buf[1], conn->id); + rb_strlcpy((char *) &buf[5], reason, sizeof(buf) - 5); + len = (strlen(reason) + 1) + 5; + mod_cmd_write_queue(conn->ctl, buf, len); +} + static conn_t * make_conn(mod_ctl_t * ctl, rb_fde_t *mod_fd, rb_fde_t *plain_fd) { @@ -233,7 +316,72 @@ cleanup_bad_message(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) } static void -wsock_process_accept(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) +conn_mod_handshake_cb(rb_fde_t *fd, void *data) +{ + char inbuf[READBUF_SIZE]; + conn_t *conn = data; + int length = 0; + if (conn == NULL) + return; + + if (IsDead(conn)) + return; + + while (1) + { + if (IsDead(conn)) + return; + + length = rb_read(conn->plain_fd, inbuf, sizeof(inbuf)); + if (length == 0 || (length < 0 && !rb_ignore_errno(errno))) + { + close_conn(conn, NO_WAIT, "Connection closed"); + return; + } + } +} + +static void +conn_mod_read_cb(rb_fde_t *fd, void *data) +{ +} + +static void +conn_plain_read_cb(rb_fde_t *fd, void *data) +{ +} + +static void +conn_plain_read_shutdown_cb(rb_fde_t *fd, void *data) +{ + char inbuf[READBUF_SIZE]; + conn_t *conn = data; + int length = 0; + + if(conn == NULL) + return; + + while(1) + { + length = rb_read(conn->plain_fd, inbuf, sizeof(inbuf)); + + if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) + { + rb_close(conn->plain_fd); + rb_dlinkAdd(conn, &conn->node, &dead_list); + return; + } + + if(length < 0) + { + rb_setselect(conn->plain_fd, RB_SELECT_READ, conn_plain_read_shutdown_cb, conn); + return; + } + } +} + +static void +wsock_process(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { conn_t *conn; uint32_t id; @@ -250,7 +398,7 @@ wsock_process_accept(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) if(rb_get_type(conn->plain_fd) == RB_FD_UNKNOWN) rb_set_type(conn->plain_fd, RB_FD_SOCKET); - // XXX todo + conn_mod_handshake_cb(conn->mod_fd, conn); } static void @@ -272,7 +420,7 @@ mod_process_cmd_recv(mod_ctl_t * ctl) cleanup_bad_message(ctl, ctl_buf); break; } - wsock_process_accept(ctl, ctl_buf); + wsock_process(ctl, ctl_buf); break; } default: @@ -324,36 +472,6 @@ mod_read_ctl(rb_fde_t *F, void *data) rb_setselect(ctl->F, RB_SELECT_READ, mod_read_ctl, ctl); } -static void -mod_write_ctl(rb_fde_t *F, void *data) -{ - mod_ctl_t *ctl = data; - mod_ctl_buf_t *ctl_buf; - rb_dlink_node *ptr, *next; - int retlen, x; - - RB_DLINK_FOREACH_SAFE(ptr, next, ctl->writeq.head) - { - ctl_buf = ptr->data; - retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, - ctl_buf->buflen, ppid); - if(retlen > 0) - { - rb_dlinkDelete(ptr, &ctl->writeq); - for(x = 0; x < ctl_buf->nfds; x++) - rb_close(ctl_buf->F[x]); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - - } - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - exit(0); - - } - if(rb_dlink_list_length(&ctl->writeq) > 0) - rb_setselect(ctl->F, RB_SELECT_WRITE, mod_write_ctl, ctl); -} - static void read_pipe_ctl(rb_fde_t *F, void *data) { From de8b3b7174f33d5ed7051cddaf211d9058230469 Mon Sep 17 00:00:00 2001 From: Matt Ullman Date: Sat, 26 Mar 2016 16:41:36 -0400 Subject: [PATCH 5/5] sslproc: Remove unused variable --- ircd/sslproc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ircd/sslproc.c b/ircd/sslproc.c index 709504ac8..55c7ba6dc 100644 --- a/ircd/sslproc.c +++ b/ircd/sslproc.c @@ -809,7 +809,6 @@ start_zlib_session(void *data) rb_fde_t *F[2]; rb_fde_t *xF1, *xF2; char *buf; - char buf2[9]; void *recvq_start; size_t hdr = (sizeof(uint8_t) * 2) + sizeof(uint32_t);