]> jfr.im git - solanum.git/blobdiff - ssld/ssld.c
providers/opm: use a name that makes more sense for this variable
[solanum.git] / ssld / ssld.c
index 0ec7c851de88b1ebfb7970139fa0c55112134f36..226ee8fac1db59f43442c227d4d59737826ea285 100644 (file)
@@ -17,8 +17,6 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
  *  USA
- *
- *  $Id$
  */
 
 
@@ -51,11 +49,6 @@ uint32_to_buf(uint8_t *buf, uint32_t x)
        return;
 }
 
-static char inbuf[READBUF_SIZE];
-#ifdef HAVE_LIBZ
-static char outbuf[READBUF_SIZE];
-#endif
-
 typedef struct _mod_ctl_buf
 {
        rb_dlink_node node;
@@ -97,10 +90,10 @@ typedef struct _conn
 
        rb_fde_t *mod_fd;
        rb_fde_t *plain_fd;
-       unsigned long long mod_out;
-       unsigned long long mod_in;
-       unsigned long long plain_in;
-       unsigned long long plain_out;
+       uint64_t mod_out;
+       uint64_t mod_in;
+       uint64_t plain_in;
+       uint64_t plain_out;
        uint8_t flags;
        void *stream;
 } conn_t;
@@ -158,12 +151,12 @@ 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);
 static void mod_cmd_write_queue(mod_ctl_t * ctl, const void *data, size_t len);
 static const char *remote_closed = "Remote host closed the connection";
-static int ssl_ok;
+static bool ssld_ssl_ok;
 static int certfp_method = RB_SSL_CERTFP_METH_SHA1;
 #ifdef HAVE_LIBZ
-static int zlib_ok = 1;
+static bool zlib_ok = true;
 #else
-static int zlib_ok = 0;
+static bool zlib_ok = false;
 #endif
 
 
@@ -214,6 +207,7 @@ free_conn(conn_t * conn)
                zlib_stream_t *stream = conn->stream;
                inflateEnd(&stream->instream);
                deflateEnd(&stream->outstream);
+               rb_free(stream);
        }
 #endif
        rb_free(conn);
@@ -260,7 +254,7 @@ close_conn(conn_t * conn, int wait_plain, const char *fmt, ...)
        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);
-       rb_vsnprintf(reason, sizeof(reason), fmt, ap);
+       vsnprintf(reason, sizeof(reason), fmt, ap);
        va_end(ap);
 
        buf[0] = 'D';
@@ -394,6 +388,7 @@ mod_cmd_write_queue(mod_ctl_t * ctl, const void *data, size_t len)
 static void
 common_zlib_deflate(conn_t * conn, void *buf, size_t len)
 {
+       char outbuf[READBUF_SIZE];
        int ret, have;
        z_stream *outstream = &((zlib_stream_t *) conn->stream)->outstream;
        outstream->next_in = buf;
@@ -427,6 +422,7 @@ common_zlib_deflate(conn_t * conn, void *buf, size_t len)
 static void
 common_zlib_inflate(conn_t * conn, void *buf, size_t len)
 {
+       char outbuf[READBUF_SIZE];
        int ret, have = 0;
        ((zlib_stream_t *) conn->stream)->instream.next_in = buf;
        ((zlib_stream_t *) conn->stream)->instream.avail_in = len;
@@ -463,7 +459,7 @@ common_zlib_inflate(conn_t * conn, void *buf, size_t len)
 }
 #endif
 
-static int
+static bool
 plain_check_cork(conn_t * conn)
 {
        if(rb_rawbuf_length(conn->modbuf_out) >= 4096)
@@ -474,15 +470,16 @@ plain_check_cork(conn_t * conn)
                rb_setselect(conn->plain_fd, RB_SELECT_READ, NULL, NULL);
                /* try to write */
                conn_mod_write_sendq(conn->mod_fd, conn);
-               return 1;
+               return true;
        }
-       return 0;
+       return false;
 }
 
 
 static void
 conn_plain_read_cb(rb_fde_t *fd, void *data)
 {
+       char inbuf[READBUF_SIZE];
        conn_t *conn = data;
        int length = 0;
        if(conn == NULL)
@@ -531,6 +528,7 @@ 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;
 
@@ -559,6 +557,7 @@ conn_plain_read_shutdown_cb(rb_fde_t *fd, void *data)
 static void
 conn_mod_read_cb(rb_fde_t *fd, void *data)
 {
+       char inbuf[READBUF_SIZE];
        conn_t *conn = data;
        const char *err = remote_closed;
        int length;
@@ -663,9 +662,8 @@ maxconn(void)
 static void
 ssl_send_cipher(conn_t *conn)
 {
-#if 0
        size_t len;
-       char buf[512];
+       uint8_t buf[512];
        char cstring[256];
        const char *p;
        if(!IsSSL(conn))
@@ -680,10 +678,9 @@ ssl_send_cipher(conn_t *conn)
 
        buf[0] = 'C';
        uint32_to_buf(&buf[1], conn->id);
-       strcpy(&buf[5], cstring);
+       strcpy((char *) &buf[5], cstring);
        len = (strlen(cstring) + 1) + 5;
        mod_cmd_write_queue(conn->ctl, buf, len);
-#endif
 }
 
 static void
@@ -764,11 +761,9 @@ ssl_process_accept(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
        SetSSL(conn);
 
        if(rb_get_type(conn->mod_fd) & RB_FD_UNKNOWN)
-       {
-
                rb_set_type(conn->mod_fd, RB_FD_SOCKET);
-       }
-       if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN)
+
+       if(rb_get_type(conn->plain_fd) == RB_FD_UNKNOWN)
                rb_set_type(conn->plain_fd, RB_FD_SOCKET);
 
        rb_ssl_start_accepted(ctlb->F[0], ssl_process_accept_cb, conn, 10);
@@ -794,7 +789,7 @@ ssl_process_connect(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
        if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN)
                rb_set_type(conn->mod_fd, RB_FD_SOCKET);
 
-       if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN)
+       if(rb_get_type(conn->plain_fd) == RB_FD_UNKNOWN)
                rb_set_type(conn->plain_fd, RB_FD_SOCKET);
 
 
@@ -817,8 +812,11 @@ process_stats(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
        if(conn == NULL)
                return;
 
-       rb_snprintf(outstat, sizeof(outstat), "S %s %llu %llu %llu %llu", odata,
-                   conn->plain_out, conn->mod_in, conn->plain_in, conn->mod_out);
+       snprintf(outstat, sizeof(outstat), "S %s %llu %llu %llu %llu", odata,
+                       (unsigned long long)conn->plain_out,
+                       (unsigned long long)conn->mod_in,
+                       (unsigned long long)conn->plain_in,
+                       (unsigned long long)conn->mod_out);
        conn->plain_out = 0;
        conn->plain_in = 0;
        conn->mod_in = 0;
@@ -826,17 +824,6 @@ process_stats(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
        mod_cmd_write_queue(ctl, outstat, strlen(outstat) + 1); /* +1 is so we send the \0 as well */
 }
 
-static void
-change_connid(mod_ctl_t *ctl, mod_ctl_buf_t *ctlb)
-{
-       uint32_t id = buf_to_uint32(&ctlb->buf[1]);
-       uint32_t newid = buf_to_uint32(&ctlb->buf[5]);
-       conn_t *conn = conn_find_by_id(id);
-       rb_dlinkDelete(&conn->node, connid_hash(conn->id));
-       SetZipSSL(conn);
-       conn->id = newid;
-}
-
 #ifdef HAVE_LIBZ
 static void
 zlib_process(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
@@ -912,7 +899,7 @@ static void
 ssl_new_keys(mod_ctl_t * ctl, mod_ctl_buf_t * ctl_buf)
 {
        char *buf;
-       char *cert, *key, *dhparam;
+       char *cert, *key, *dhparam, *cipher_list;
 
        buf = (char *) &ctl_buf->buf[2];
        cert = buf;
@@ -922,8 +909,12 @@ ssl_new_keys(mod_ctl_t * ctl, mod_ctl_buf_t * ctl_buf)
        dhparam = buf;
        if(strlen(dhparam) == 0)
                dhparam = NULL;
+       buf += strlen(dhparam) + 1;
+       cipher_list = buf;
+       if(strlen(cipher_list) == 0)
+               cipher_list = NULL;
 
-       if(!rb_setup_ssl_server(cert, key, dhparam))
+       if(!rb_setup_ssl_server(cert, key, dhparam, cipher_list))
        {
                const char *invalid = "I";
                mod_cmd_write_queue(ctl, invalid, strlen(invalid));
@@ -955,6 +946,14 @@ send_i_am_useless(mod_ctl_t * ctl)
        mod_cmd_write_queue(ctl, useless, strlen(useless));
 }
 
+static void
+send_version(mod_ctl_t * ctl)
+{
+       char version[256] = { 'V', 0 };
+       strncpy(&version[1], rb_lib_version(), sizeof(version) - 2);
+       mod_cmd_write_queue(ctl, version, strlen(version));
+}
+
 static void
 send_nozlib_support(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
 {
@@ -991,7 +990,7 @@ mod_process_cmd_recv(mod_ctl_t * ctl)
                                        break;
                                }
 
-                               if(!ssl_ok)
+                               if(!ssld_ssl_ok)
                                {
                                        send_nossl_support(ctl, ctl_buf);
                                        break;
@@ -1007,7 +1006,7 @@ mod_process_cmd_recv(mod_ctl_t * ctl)
                                        break;
                                }
 
-                               if(!ssl_ok)
+                               if(!ssld_ssl_ok)
                                {
                                        send_nossl_support(ctl, ctl_buf);
                                        break;
@@ -1027,7 +1026,7 @@ mod_process_cmd_recv(mod_ctl_t * ctl)
                        }
                case 'K':
                        {
-                               if(!ssl_ok)
+                               if(!ssld_ssl_ok)
                                {
                                        send_nossl_support(ctl, ctl_buf);
                                        break;
@@ -1043,11 +1042,6 @@ mod_process_cmd_recv(mod_ctl_t * ctl)
                                process_stats(ctl, ctl_buf);
                                break;
                        }
-               case 'Y':
-                       {
-                               change_connid(ctl, ctl_buf);
-                               break;
-                       }
 
 #ifdef HAVE_LIBZ
                case 'Z':
@@ -1154,6 +1148,7 @@ mod_write_ctl(rb_fde_t *F, void *data)
 static void
 read_pipe_ctl(rb_fde_t *F, void *data)
 {
+       char inbuf[READBUF_SIZE];
        int retlen;
        while((retlen = rb_read(F, inbuf, sizeof(inbuf))) > 0)
        {
@@ -1179,10 +1174,9 @@ main(int argc, char **argv)
        if(s_ctlfd == NULL || s_pipe == NULL || s_pid == NULL)
        {
                fprintf(stderr,
-                       "This is ircd-ratbox ssld.  You know you aren't supposed to run me directly?\n");
+                       "This is the charybdis ssld for internal ircd use.\n");
                fprintf(stderr,
-                       "You get an Id tag for this: $Id$\n");
-               fprintf(stderr, "Have a nice life\n");
+                       "You aren't supposed to run me directly. Exiting.\n");
                exit(1);
        }
 
@@ -1213,7 +1207,7 @@ main(int argc, char **argv)
        setup_signals();
        rb_lib_init(NULL, NULL, NULL, 0, maxfd, 1024, 4096);
        rb_init_rawbuffers(1024);
-       ssl_ok = rb_supports_ssl();
+       ssld_ssl_ok = rb_supports_ssl();
        mod_ctl = rb_malloc(sizeof(mod_ctl_t));
        mod_ctl->F = rb_open(ctlfd, RB_FD_SOCKET, "ircd control socket");
        mod_ctl->F_pipe = rb_open(pipefd, RB_FD_PIPE, "ircd pipe");
@@ -1223,7 +1217,8 @@ main(int argc, char **argv)
        rb_event_add("check_handshake_flood", check_handshake_flood, NULL, 10);
        read_pipe_ctl(mod_ctl->F_pipe, NULL);
        mod_read_ctl(mod_ctl->F, mod_ctl);
-       if(!zlib_ok && !ssl_ok)
+       send_version(mod_ctl);
+       if(!zlib_ok && !ssld_ssl_ok)
        {
                /* this is really useless... */
                send_i_am_useless(mod_ctl);
@@ -1234,7 +1229,7 @@ main(int argc, char **argv)
 
        if(!zlib_ok)
                send_nozlib_support(mod_ctl, NULL);
-       if(!ssl_ok)
+       if(!ssld_ssl_ok)
                send_nossl_support(mod_ctl, NULL);
        rb_lib_loop(0);
        return 0;