From 0aaa37f721c1cf0eb4e769fccbd220a04331d3d7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 Mar 2016 18:13:15 -0500 Subject: [PATCH 1/5] ircd: only relocate_paths on windows, no point on posix --- ircd/ircd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ircd/ircd.c b/ircd/ircd.c index 627d469b..8a16ffa4 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -396,6 +396,7 @@ initialize_server_capabs(void) * output - none * side effects - items in ircd_paths[] array are relocated */ +#ifdef _WIN32 static void relocate_paths(void) { @@ -466,6 +467,7 @@ relocate_paths(void) ircd_paths[IRCD_PATH_BIN] = rb_strdup(workbuf); ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(workbuf); } +#endif /* * write_pidfile @@ -656,7 +658,7 @@ charybdis_main(int argc, char *argv[]) } #endif -#ifndef ENABLE_FHS_PATHS +#ifdef _WIN32 relocate_paths(); #endif From 45c58544606c616c7b472bab33f84d5692a97db1 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 Mar 2016 18:25:00 -0500 Subject: [PATCH 2/5] appveyor: make the build less hacky --- .appveyor-build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.appveyor-build.sh b/.appveyor-build.sh index 7aa1682c..8ea6283e 100644 --- a/.appveyor-build.sh +++ b/.appveyor-build.sh @@ -1,8 +1,9 @@ set -v +export MSYSTEM=MINGW64 export PATH=/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl sh ./autogen.sh -./configure --prefix=c:/projects/charybdis/build --enable-openssl=/mingw64 --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 +./configure --prefix=c:/projects/charybdis/build --enable-openssl=/mingw64 make -j2 make install From fdba4417dc375620864c6f10b7eb39d2e2c94173 Mon Sep 17 00:00:00 2001 From: Matt Ullman Date: Fri, 25 Mar 2016 19:40:12 -0400 Subject: [PATCH 3/5] .gitignore: Ignore serno.h from librb as well --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 72de63ae..35560150 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ librb/aclocal.m4 librb/include/librb_config.h librb/include/librb_config.h.in librb/include/librb-config.h +librb/include/serno.h librb/librb.pc librb/ltmain.sh librb/missing From afba2488ec133af3070e09c1eda7b5a750d4df35 Mon Sep 17 00:00:00 2001 From: Matt Ullman Date: Fri, 25 Mar 2016 19:47:30 -0400 Subject: [PATCH 4/5] extb_combi: More int to bool conversion Cleanup whitespace in ircd_lexer.l --- extensions/extb_combi.c | 26 +++++++++++++------------- ircd/ircd_lexer.l | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/extensions/extb_combi.c b/extensions/extb_combi.c index 6b06fdb9..c9f35642 100644 --- a/extensions/extb_combi.c +++ b/extensions/extb_combi.c @@ -52,7 +52,7 @@ static int _modinit(void); static void _moddeinit(void); static int eb_or(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_and(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); -static int eb_combi(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type, int is_and); +static int eb_combi(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type, bool is_and); static int recursion_depth = 0; DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); @@ -76,20 +76,20 @@ _moddeinit(void) static int eb_or(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type) { - return eb_combi(data, client_p, chptr, mode_type, FALSE); + return eb_combi(data, client_p, chptr, mode_type, false); } static int eb_and(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type) { - return eb_combi(data, client_p, chptr, mode_type, TRUE); + return eb_combi(data, client_p, chptr, mode_type, true); } static int eb_combi(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type, int is_and) + struct Channel *chptr, long mode_type, bool is_and) { const char *p, *banend; - int have_result = FALSE; + bool have_result = false; int allowed_nodes = 11; size_t datalen; @@ -143,12 +143,12 @@ static int eb_combi(const char *data, struct Client *client_p, recursion_depth++; while (--allowed_nodes) { - int invert = FALSE; + bool invert = false; char *child_data, child_data_buf[BANLEN]; ExtbanFunc f; if (*p == '~') { - invert = TRUE; + invert = true; p++; if (p == banend) { MOD_DEBUG("combo invalid: no data after ~"); @@ -164,7 +164,7 @@ static int eb_combi(const char *data, struct Client *client_p, if (*p == ':') { unsigned int parencount = 0; - int escaped = FALSE, done = FALSE; + bool escaped = false, done = false; char *o; p++; @@ -173,7 +173,7 @@ static int eb_combi(const char *data, struct Client *client_p, * we already have_result. */ o = child_data = child_data_buf; - while (TRUE) { + while (true) { if (p == banend) { if (parencount) { MOD_DEBUG("combo invalid: EOD while in parens"); @@ -186,11 +186,11 @@ static int eb_combi(const char *data, struct Client *client_p, if (*p != '(' && *p != ')' && *p != '\\' && *p != ',') *o++ = '\\'; *o++ = *p++; - escaped = FALSE; + escaped = false; } else { switch (*p) { case '\\': - escaped = TRUE; + escaped = true; break; case '(': parencount++; @@ -208,7 +208,7 @@ static int eb_combi(const char *data, struct Client *client_p, if (parencount) *o++ = *p; else - done = TRUE; + done = true; break; default: *o++ = *p; @@ -239,7 +239,7 @@ static int eb_combi(const char *data, struct Client *client_p, child_result = child_result == EXTBAN_MATCH; if (is_and ? !child_result : child_result) - have_result = TRUE; + have_result = true; } if (p == banend) diff --git a/ircd/ircd_lexer.l b/ircd/ircd_lexer.l index ae96b407..ccaf2e99 100644 --- a/ircd/ircd_lexer.l +++ b/ircd/ircd_lexer.l @@ -66,7 +66,7 @@ char linebuf[512]; #define YY_INPUT(buf,result,max_size) \ if (!(result = conf_fgets(buf, max_size, conf_fbfile_in))) \ - YY_FATAL_ERROR("input in flex scanner failed"); + YY_FATAL_ERROR("input in flex scanner failed"); %} ws [ \t]* @@ -101,9 +101,9 @@ include \.include{ws}(\<.*\>|\".*\") { int i,j; yylval.string[yyleng-2] = '\0'; /* remove close - * quote + * quote */ - + for (j=i=0 ;yylval.string[i] != '\0'; i++,j++) { if (yylval.string[i] != '\\') @@ -113,7 +113,7 @@ include \.include{ws}(\<.*\>|\".*\") else { i++; - if (yylval.string[i] == '\0') /* XXX + if (yylval.string[i] == '\0') /* XXX * should not * happen */ @@ -133,7 +133,7 @@ include \.include{ws}(\<.*\>|\".*\") loadmodule { return LOADMODULE; } -{string} { +{string} { strcpy(yylval.string, yytext); yylval.string[yyleng] = '\0'; return STRING; @@ -148,7 +148,7 @@ loadmodule { return LOADMODULE; } void ccomment() { int c; - + /* log(L_NOTICE, "got comment"); */ while (1) { @@ -157,7 +157,7 @@ void ccomment() if (c == '*') { while ((c = input()) == '*'); - if (c == '/') + if (c == '/') break; if (c == '\n') ++lineno; } @@ -182,15 +182,15 @@ void cinclude(void) else *strchr(++c, '>') = 0; - /* do stacking and co. */ + /* do stacking and co. */ if (include_stack_ptr >= MAX_INCLUDE_DEPTH) conf_report_error("Includes nested too deep (max is %d)", MAX_INCLUDE_DEPTH); else { FILE *tmp_fbfile_in; - + tmp_fbfile_in = fopen(c, "r"); - + if (tmp_fbfile_in == NULL) { /* if its not found in PREFIX, look in IRCD_PATH_ETC */ From de7cf7e0091182dcef5d5a046bc1303a762c2877 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 Mar 2016 19:49:01 -0500 Subject: [PATCH 5/5] ircd: client: substantially rework the connid registry system now connid's are allocated on demand and clients may have as many connid's as necessary. this allows us to build chains of helpers while ensuring the ircd properly tracks and GCs the resources. --- include/client.h | 10 +++-- include/hash.h | 7 +--- ircd/client.c | 89 +++++++++++++++++++++++++++++++++++++------- ircd/hash.c | 34 +++-------------- ircd/listener.c | 2 +- ircd/s_serv.c | 2 +- ircd/sslproc.c | 14 +------ modules/m_starttls.c | 2 +- ssld/ssld.c | 5 --- 9 files changed, 93 insertions(+), 72 deletions(-) diff --git a/include/client.h b/include/client.h index f844aac7..b9a612bf 100644 --- a/include/client.h +++ b/include/client.h @@ -166,7 +166,9 @@ struct Client struct LocalUser { - rb_dlink_node tnode; /* This is the node for the local list type the client is on*/ + rb_dlink_node tnode; /* This is the node for the local list type the client is on */ + rb_dlink_list connids; /* This is the list of connids to free */ + /* * The following fields are allocated only for local clients * (directly connected to *this* server with a socket. @@ -233,7 +235,6 @@ struct LocalUser time_t next_away; /* Don't allow next away before... */ time_t last; - uint32_t connid; /* clients allowed to talk through +g */ rb_dlink_list allow_list; @@ -272,7 +273,6 @@ struct LocalUser struct _ssl_ctl *ssl_ctl; /* which ssl daemon we're associate with */ struct _ssl_ctl *z_ctl; /* second ctl for ssl+zlib */ - uint32_t zconnid; uint32_t localflags; struct ZipStats *zipstats; /* zipstats */ uint16_t cork_count; /* used for corking/uncorking connections */ @@ -605,4 +605,8 @@ extern char *generate_uid(void); void allocate_away(struct Client *); void free_away(struct Client *); +uint32_t connid_get(struct Client *client_p); +void connid_put(uint32_t id); +void client_release_connids(struct Client *client_p); + #endif /* INCLUDED_client_h */ diff --git a/include/hash.h b/include/hash.h index c2d220db..aa0ef79e 100644 --- a/include/hash.h +++ b/include/hash.h @@ -95,11 +95,8 @@ extern void del_from_resv_hash(const char *name, struct ConfItem *aconf); extern struct ConfItem *hash_find_resv(const char *name); extern void clear_resv_hash(void); -void add_to_cli_connid_hash(struct Client *client_p); -void del_from_cli_connid_hash(struct Client *client_p); +void add_to_cli_connid_hash(struct Client *client_p, uint32_t id); +void del_from_cli_connid_hash(uint32_t id); struct Client *find_cli_connid_hash(uint32_t connid); -void add_to_zconnid_hash(struct Client *client_p); -void del_from_zconnid_hash(struct Client *client_p); - #endif /* INCLUDED_hash_h */ diff --git a/ircd/client.c b/ircd/client.c index f411848b..268f61b2 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -76,7 +76,7 @@ static rb_bh *pclient_heap = NULL; static rb_bh *user_heap = NULL; static rb_bh *away_heap = NULL; static char current_uid[IDLEN]; -static int32_t current_connid = 0; +static uint32_t current_connid = 0; rb_dictionary *nd_dict = NULL; @@ -129,6 +129,78 @@ init_client(void) nd_dict = rb_dictionary_create("nickdelay", irccmp); } +/* + * connid_get - allocate a connid + * + * inputs - none + * outputs - a connid token which is used to represent a logical circuit + * side effects - current_connid is incremented, possibly multiple times. + * the association of the connid to it's client is committed. + */ +uint32_t +connid_get(struct Client *client_p) +{ + s_assert(MyClient(client_p)); + if (!MyClient(client_p)) + return 0; + + /* find a connid that is available */ + while (find_cli_connid_hash(++current_connid) != NULL) + { + /* handle wraparound, current_connid must NEVER be 0 */ + if (current_connid == 0) + ++current_connid; + } + + add_to_cli_connid_hash(client_p, current_connid); + rb_dlinkAddAlloc(RB_UINT_TO_POINTER(current_connid), &client_p->localClient->connids); + + return current_connid; +} + +/* + * connid_put - free a connid + * + * inputs - connid to free + * outputs - nothing + * side effects - connid bookkeeping structures are freed + */ +void +connid_put(uint32_t id) +{ + struct Client *client_p; + + s_assert(id != 0); + if (id == 0) + return; + + client_p = find_cli_connid_hash(id); + if (client_p == NULL) + return; + + del_from_cli_connid_hash(id); + rb_dlinkFindDestroy(RB_UINT_TO_POINTER(id), &client_p->localClient->connids); +} + +/* + * client_release_connids - release any connids still attached to a client + * + * inputs - client to garbage collect + * outputs - none + * side effects - client's connids are garbage collected + */ +void +client_release_connids(struct Client *client_p) +{ + rb_dlink_node *ptr, *ptr2; + + s_assert(MyClient(client_p)); + if (!MyClient(client_p)) + return; + + RB_DLINK_FOREACH_SAFE(ptr, ptr2, client_p->localClient->connids.head) + connid_put(RB_POINTER_TO_UINT(ptr->data)); +} /* * make_client - create a new Client struct and set it to initial state. @@ -160,17 +232,6 @@ make_client(struct Client *from) client_p->localClient->F = NULL; - if(current_connid+1 == 0) - current_connid++; - - client_p->localClient->connid = ++current_connid; - - if(current_connid+1 == 0) - current_connid++; - - client_p->localClient->zconnid = ++current_connid; - add_to_cli_connid_hash(client_p); - client_p->preClient = rb_bh_alloc(pclient_heap); /* as good a place as any... */ @@ -229,7 +290,7 @@ free_local_client(struct Client *client_p) client_p->localClient->listener = 0; } - del_from_cli_connid_hash(client_p); + client_release_connids(client_p); if(client_p->localClient->F != NULL) { rb_close(client_p->localClient->F); @@ -1949,7 +2010,7 @@ close_connection(struct Client *client_p) else ServerStats.is_ni++; - del_from_cli_connid_hash(client_p); + client_release_connids(client_p); if(client_p->localClient->F != NULL) { diff --git a/ircd/hash.c b/ircd/hash.c index 172734d3..0d3fb128 100644 --- a/ircd/hash.c +++ b/ircd/hash.c @@ -40,7 +40,6 @@ #include "rb_radixtree.h" rb_dictionary *client_connid_tree = NULL; -rb_dictionary *client_zconnid_tree = NULL; rb_radixtree *client_id_tree = NULL; rb_radixtree *client_name_tree = NULL; @@ -60,7 +59,6 @@ void init_hash(void) { client_connid_tree = rb_dictionary_create("client connid", rb_uint32cmp); - client_zconnid_tree = rb_dictionary_create("client zconnid", rb_uint32cmp); client_id_tree = rb_radixtree_create("client id", NULL); client_name_tree = rb_radixtree_create("client name", irccasecanon); @@ -493,41 +491,19 @@ clear_resv_hash(void) } void -add_to_zconnid_hash(struct Client *client_p) +add_to_cli_connid_hash(struct Client *client_p, uint32_t id) { - rb_dictionary_add(client_zconnid_tree, RB_UINT_TO_POINTER(client_p->localClient->zconnid), client_p); + rb_dictionary_add(client_connid_tree, RB_UINT_TO_POINTER(id), client_p); } void -del_from_zconnid_hash(struct Client *client_p) +del_from_cli_connid_hash(uint32_t id) { - rb_dictionary_delete(client_zconnid_tree, RB_UINT_TO_POINTER(client_p->localClient->zconnid)); -} - -void -add_to_cli_connid_hash(struct Client *client_p) -{ - rb_dictionary_add(client_connid_tree, RB_UINT_TO_POINTER(client_p->localClient->connid), client_p); -} - -void -del_from_cli_connid_hash(struct Client *client_p) -{ - rb_dictionary_delete(client_connid_tree, RB_UINT_TO_POINTER(client_p->localClient->connid)); + rb_dictionary_delete(client_connid_tree, RB_UINT_TO_POINTER(id)); } struct Client * find_cli_connid_hash(uint32_t connid) { - struct Client *target_p; - - target_p = rb_dictionary_retrieve(client_connid_tree, RB_UINT_TO_POINTER(connid)); - if (target_p != NULL) - return target_p; - - target_p = rb_dictionary_retrieve(client_zconnid_tree, RB_UINT_TO_POINTER(connid)); - if (target_p != NULL) - return target_p; - - return NULL; + return rb_dictionary_retrieve(client_connid_tree, RB_UINT_TO_POINTER(connid)); } diff --git a/ircd/listener.c b/ircd/listener.c index a3d08cba..aeff94e9 100644 --- a/ircd/listener.c +++ b/ircd/listener.c @@ -481,7 +481,7 @@ add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, str free_client(new_client); return; } - new_client->localClient->ssl_ctl = start_ssld_accept(F, xF[1], new_client->localClient->connid); /* this will close F for us */ + new_client->localClient->ssl_ctl = start_ssld_accept(F, xF[1], connid_get(new_client)); /* this will close F for us */ if(new_client->localClient->ssl_ctl == NULL) { free_client(new_client); diff --git a/ircd/s_serv.c b/ircd/s_serv.c index 619ab51f..79a0a487 100644 --- a/ircd/s_serv.c +++ b/ircd/s_serv.c @@ -1157,7 +1157,7 @@ serv_connect_ssl_callback(rb_fde_t *F, int status, void *data) } client_p->localClient->F = xF[0]; - client_p->localClient->ssl_ctl = start_ssld_connect(F, xF[1], rb_get_fd(xF[0])); + client_p->localClient->ssl_ctl = start_ssld_connect(F, xF[1], connid_get(client_p)); if(!client_p->localClient->ssl_ctl) { serv_connect_callback(client_p->localClient->F, RB_ERROR, data); diff --git a/ircd/sslproc.c b/ircd/sslproc.c index 2edd091e..709504ac 100644 --- a/ircd/sslproc.c +++ b/ircd/sslproc.c @@ -863,23 +863,11 @@ start_zlib_session(void *data) return; } - if(IsSSL(server)) - { - /* tell ssld the new connid for the ssl part*/ - buf2[0] = 'Y'; - uint32_to_buf(&buf2[1], rb_get_fd(server->localClient->F)); - uint32_to_buf(&buf2[5], rb_get_fd(xF2)); - ssl_cmd_write_queue(server->localClient->ssl_ctl, NULL, 0, buf2, sizeof(buf2)); - } - - F[0] = server->localClient->F; F[1] = xF1; - del_from_zconnid_hash(server); server->localClient->F = xF2; /* need to redo as what we did before isn't valid now */ - uint32_to_buf(&buf[1], server->localClient->zconnid); - add_to_zconnid_hash(server); + uint32_to_buf(&buf[1], connid_get(server)); server->localClient->z_ctl = which_ssld(); if(!server->localClient->z_ctl) diff --git a/modules/m_starttls.c b/modules/m_starttls.c index f49abb46..62b7feb6 100644 --- a/modules/m_starttls.c +++ b/modules/m_starttls.c @@ -95,7 +95,7 @@ mr_starttls(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou sendto_one_numeric(client_p, RPL_STARTTLS, form_str(RPL_STARTTLS)); send_queued(client_p); - ctl = start_ssld_accept(client_p->localClient->F, F[1], client_p->localClient->connid); + ctl = start_ssld_accept(client_p->localClient->F, F[1], connid_get(client_p)); if (ctl != NULL) { client_p->localClient->F = F[0]; diff --git a/ssld/ssld.c b/ssld/ssld.c index 7a0dc20f..6eb942c2 100644 --- a/ssld/ssld.c +++ b/ssld/ssld.c @@ -1067,11 +1067,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':