diff --git a/bandb/bandb.c b/bandb/bandb.c index 33166b1..773f68c 100644 --- a/bandb/bandb.c +++ b/bandb/bandb.c @@ -40,21 +40,20 @@ #define COMMIT_INTERVAL 3 /* seconds */ -typedef enum -{ - BANDB_KLINE, - BANDB_DLINE, - BANDB_XLINE, - BANDB_RESV, - LAST_BANDB_TYPE +typedef enum { + BANDB_KLINE, + BANDB_DLINE, + BANDB_XLINE, + BANDB_RESV, + LAST_BANDB_TYPE } bandb_type; static char bandb_letter[LAST_BANDB_TYPE] = { - 'K', 'D', 'X', 'R' + 'K', 'D', 'X', 'R' }; static const char *bandb_table[LAST_BANDB_TYPE] = { - "kline", "dline", "xline", "resv" + "kline", "dline", "xline", "resv" }; @@ -66,191 +65,181 @@ static void check_schema(void); static void bandb_commit(void *unused) { - rsdb_transaction(RSDB_TRANS_END); - in_transaction = 0; + rsdb_transaction(RSDB_TRANS_END); + in_transaction = 0; } static void parse_ban(bandb_type type, char *parv[], int parc) { - const char *mask1 = NULL; - const char *mask2 = NULL; - const char *oper = NULL; - const char *curtime = NULL; - const char *reason = NULL; - const char *perm = NULL; - int para = 1; + const char *mask1 = NULL; + const char *mask2 = NULL; + const char *oper = NULL; + const char *curtime = NULL; + const char *reason = NULL; + const char *perm = NULL; + int para = 1; - if(type == BANDB_KLINE) - { - if(parc != 7) - return; - } - else if(parc != 6) - return; + if(type == BANDB_KLINE) { + if(parc != 7) + return; + } else if(parc != 6) + return; - mask1 = parv[para++]; + mask1 = parv[para++]; - if(type == BANDB_KLINE) - mask2 = parv[para++]; + if(type == BANDB_KLINE) + mask2 = parv[para++]; - oper = parv[para++]; - curtime = parv[para++]; - perm = parv[para++]; - reason = parv[para++]; + oper = parv[para++]; + curtime = parv[para++]; + perm = parv[para++]; + reason = parv[para++]; - if(!in_transaction) - { - rsdb_transaction(RSDB_TRANS_START); - in_transaction = 1; - rb_event_addonce("bandb_commit", bandb_commit, NULL, - COMMIT_INTERVAL); - } + if(!in_transaction) { + rsdb_transaction(RSDB_TRANS_START); + in_transaction = 1; + rb_event_addonce("bandb_commit", bandb_commit, NULL, + COMMIT_INTERVAL); + } - rsdb_exec(NULL, - "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES('%Q', '%Q', '%Q', %s, %s, '%Q')", - bandb_table[type], mask1, mask2 ? mask2 : "", oper, curtime, perm, reason); + rsdb_exec(NULL, + "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES('%Q', '%Q', '%Q', %s, %s, '%Q')", + bandb_table[type], mask1, mask2 ? mask2 : "", oper, curtime, perm, reason); } static void parse_unban(bandb_type type, char *parv[], int parc) { - const char *mask1 = NULL; - const char *mask2 = NULL; + const char *mask1 = NULL; + const char *mask2 = NULL; - if(type == BANDB_KLINE) - { - if(parc != 3) - return; - } - else if(parc != 2) - return; + if(type == BANDB_KLINE) { + if(parc != 3) + return; + } else if(parc != 2) + return; - mask1 = parv[1]; + mask1 = parv[1]; - if(type == BANDB_KLINE) - mask2 = parv[2]; + if(type == BANDB_KLINE) + mask2 = parv[2]; - if(!in_transaction) - { - rsdb_transaction(RSDB_TRANS_START); - in_transaction = 1; - rb_event_addonce("bandb_commit", bandb_commit, NULL, - COMMIT_INTERVAL); - } + if(!in_transaction) { + rsdb_transaction(RSDB_TRANS_START); + in_transaction = 1; + rb_event_addonce("bandb_commit", bandb_commit, NULL, + COMMIT_INTERVAL); + } - rsdb_exec(NULL, "DELETE FROM %s WHERE mask1='%Q' AND mask2='%Q'", - bandb_table[type], mask1, mask2 ? mask2 : ""); + rsdb_exec(NULL, "DELETE FROM %s WHERE mask1='%Q' AND mask2='%Q'", + bandb_table[type], mask1, mask2 ? mask2 : ""); } static void list_bans(void) { - static char buf[512]; - struct rsdb_table table; - int i, j; + static char buf[512]; + struct rsdb_table table; + int i, j; - /* schedule a clear of anything already pending */ - rb_helper_write_queue(bandb_helper, "C"); + /* schedule a clear of anything already pending */ + rb_helper_write_queue(bandb_helper, "C"); - for(i = 0; i < LAST_BANDB_TYPE; i++) - { - rsdb_exec_fetch(&table, "SELECT mask1,mask2,oper,reason FROM %s WHERE 1", - bandb_table[i]); + for(i = 0; i < LAST_BANDB_TYPE; i++) { + rsdb_exec_fetch(&table, "SELECT mask1,mask2,oper,reason FROM %s WHERE 1", + bandb_table[i]); - for(j = 0; j < table.row_count; j++) - { - if(i == BANDB_KLINE) - rb_snprintf(buf, sizeof(buf), "%c %s %s %s :%s", - bandb_letter[i], table.row[j][0], - table.row[j][1], table.row[j][2], table.row[j][3]); - else - rb_snprintf(buf, sizeof(buf), "%c %s %s :%s", - bandb_letter[i], table.row[j][0], - table.row[j][2], table.row[j][3]); + for(j = 0; j < table.row_count; j++) { + if(i == BANDB_KLINE) + rb_snprintf(buf, sizeof(buf), "%c %s %s %s :%s", + bandb_letter[i], table.row[j][0], + table.row[j][1], table.row[j][2], table.row[j][3]); + else + rb_snprintf(buf, sizeof(buf), "%c %s %s :%s", + bandb_letter[i], table.row[j][0], + table.row[j][2], table.row[j][3]); - rb_helper_write_queue(bandb_helper, "%s", buf); - } + rb_helper_write_queue(bandb_helper, "%s", buf); + } - rsdb_exec_fetch_end(&table); - } + rsdb_exec_fetch_end(&table); + } - rb_helper_write(bandb_helper, "F"); + rb_helper_write(bandb_helper, "F"); } static void parse_request(rb_helper *helper) { - static char *parv[MAXPARA + 1]; - static char readbuf[READBUF_SIZE]; - int parc; - int len; + static char *parv[MAXPARA + 1]; + static char readbuf[READBUF_SIZE]; + int parc; + int len; - while((len = rb_helper_read(helper, readbuf, sizeof(readbuf))) > 0) - { - parc = rb_string_to_array(readbuf, parv, MAXPARA); + while((len = rb_helper_read(helper, readbuf, sizeof(readbuf))) > 0) { + parc = rb_string_to_array(readbuf, parv, MAXPARA); - if(parc < 1) - continue; + if(parc < 1) + continue; - switch (parv[0][0]) - { - case 'K': - parse_ban(BANDB_KLINE, parv, parc); - break; + switch (parv[0][0]) { + case 'K': + parse_ban(BANDB_KLINE, parv, parc); + break; - case 'D': - parse_ban(BANDB_DLINE, parv, parc); - break; + case 'D': + parse_ban(BANDB_DLINE, parv, parc); + break; - case 'X': - parse_ban(BANDB_XLINE, parv, parc); - break; + case 'X': + parse_ban(BANDB_XLINE, parv, parc); + break; - case 'R': - parse_ban(BANDB_RESV, parv, parc); - break; + case 'R': + parse_ban(BANDB_RESV, parv, parc); + break; - case 'k': - parse_unban(BANDB_KLINE, parv, parc); - break; + case 'k': + parse_unban(BANDB_KLINE, parv, parc); + break; - case 'd': - parse_unban(BANDB_DLINE, parv, parc); - break; + case 'd': + parse_unban(BANDB_DLINE, parv, parc); + break; - case 'x': - parse_unban(BANDB_XLINE, parv, parc); - break; + case 'x': + parse_unban(BANDB_XLINE, parv, parc); + break; - case 'r': - parse_unban(BANDB_RESV, parv, parc); - break; + case 'r': + parse_unban(BANDB_RESV, parv, parc); + break; - case 'L': - list_bans(); - break; - default: - break; - } - } + case 'L': + list_bans(); + break; + default: + break; + } + } } static void error_cb(rb_helper *helper) { - if(in_transaction) - rsdb_transaction(RSDB_TRANS_END); - exit(1); + if(in_transaction) + rsdb_transaction(RSDB_TRANS_END); + exit(1); } #ifndef WINDOWS static void dummy_handler(int sig) { - return; + return; } #endif @@ -258,28 +247,28 @@ static void setup_signals() { #ifndef WINDOWS - struct sigaction act; + struct sigaction act; - act.sa_flags = 0; - act.sa_handler = SIG_IGN; - sigemptyset(&act.sa_mask); - sigaddset(&act.sa_mask, SIGPIPE); - sigaddset(&act.sa_mask, SIGALRM); + act.sa_flags = 0; + act.sa_handler = SIG_IGN; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGPIPE); + sigaddset(&act.sa_mask, SIGALRM); #ifdef SIGTRAP - sigaddset(&act.sa_mask, SIGTRAP); + sigaddset(&act.sa_mask, SIGTRAP); #endif #ifdef SIGWINCH - sigaddset(&act.sa_mask, SIGWINCH); - sigaction(SIGWINCH, &act, 0); + sigaddset(&act.sa_mask, SIGWINCH); + sigaction(SIGWINCH, &act, 0); #endif - sigaction(SIGPIPE, &act, 0); + sigaction(SIGPIPE, &act, 0); #ifdef SIGTRAP - sigaction(SIGTRAP, &act, 0); + sigaction(SIGTRAP, &act, 0); #endif - act.sa_handler = dummy_handler; - sigaction(SIGALRM, &act, 0); + act.sa_handler = dummy_handler; + sigaction(SIGALRM, &act, 0); #endif } @@ -287,51 +276,49 @@ setup_signals() static void db_error_cb(const char *errstr) { - char buf[256]; - rb_snprintf(buf, sizeof(buf), "! :%s", errstr); - rb_helper_write(bandb_helper, buf); - rb_sleep(2 << 30, 0); - exit(1); + char buf[256]; + rb_snprintf(buf, sizeof(buf), "! :%s", errstr); + rb_helper_write(bandb_helper, buf); + rb_sleep(2 << 30, 0); + exit(1); } int main(int argc, char *argv[]) { - setup_signals(); - bandb_helper = rb_helper_child(parse_request, error_cb, NULL, NULL, NULL, 256, 256, 256, 256); /* XXX fix me */ - if(bandb_helper == NULL) - { - fprintf(stderr, - "This is ircd-ratbox bandb. You aren't supposed to run me directly. Maybe you want bantool?\n"); - fprintf(stderr, - "However I will print my Id tag $Id: bandb.c 26094 2008-09-19 15:33:46Z androsyn $\n"); - fprintf(stderr, "Have a nice day\n"); - exit(1); - } - rsdb_init(db_error_cb); - check_schema(); - rb_helper_loop(bandb_helper, 0); + setup_signals(); + bandb_helper = rb_helper_child(parse_request, error_cb, NULL, NULL, NULL, 256, 256, 256, 256); /* XXX fix me */ + if(bandb_helper == NULL) { + fprintf(stderr, + "This is ircd-ratbox bandb. You aren't supposed to run me directly. Maybe you want bantool?\n"); + fprintf(stderr, + "However I will print my Id tag $Id: bandb.c 26094 2008-09-19 15:33:46Z androsyn $\n"); + fprintf(stderr, "Have a nice day\n"); + exit(1); + } + rsdb_init(db_error_cb); + check_schema(); + rb_helper_loop(bandb_helper, 0); - return 0; + return 0; } static void check_schema(void) { - struct rsdb_table table; - int i; + struct rsdb_table table; + int i; - for(i = 0; i < LAST_BANDB_TYPE; i++) - { - rsdb_exec_fetch(&table, - "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", - bandb_table[i]); + for(i = 0; i < LAST_BANDB_TYPE; i++) { + rsdb_exec_fetch(&table, + "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", + bandb_table[i]); - rsdb_exec_fetch_end(&table); + rsdb_exec_fetch_end(&table); - if(!table.row_count) - rsdb_exec(NULL, - "CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", - bandb_table[i]); - } + if(!table.row_count) + rsdb_exec(NULL, + "CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", + bandb_table[i]); + } } diff --git a/bandb/bantool.c b/bandb/bantool.c index 8179744..03511e3 100644 --- a/bandb/bantool.c +++ b/bandb/bantool.c @@ -51,60 +51,57 @@ #define BT_VERSION "0.4.1" -typedef enum -{ - BANDB_KLINE, - BANDB_KLINE_PERM, - BANDB_DLINE, - BANDB_DLINE_PERM, - BANDB_XLINE, - BANDB_XLINE_PERM, - BANDB_RESV, - BANDB_RESV_PERM, - LAST_BANDB_TYPE +typedef enum { + BANDB_KLINE, + BANDB_KLINE_PERM, + BANDB_DLINE, + BANDB_DLINE_PERM, + BANDB_XLINE, + BANDB_XLINE_PERM, + BANDB_RESV, + BANDB_RESV_PERM, + LAST_BANDB_TYPE } bandb_type; static char bandb_letter[LAST_BANDB_TYPE] = { - 'K', 'K', 'D', 'D', 'X', 'X', 'R', 'R' + 'K', 'K', 'D', 'D', 'X', 'X', 'R', 'R' }; static const char *bandb_table[LAST_BANDB_TYPE] = { - "kline", "kline", "dline", "dline", "xline", "xline", "resv", "resv" + "kline", "kline", "dline", "dline", "xline", "xline", "resv", "resv" }; static const char *bandb_suffix[LAST_BANDB_TYPE] = { - "", ".perm", - "", ".perm", - "", ".perm", - "", ".perm" + "", ".perm", + "", ".perm", + "", ".perm", + "", ".perm" }; static char me[PATH_MAX]; /* *INDENT-OFF* */ /* report counters */ -struct counter -{ - unsigned int klines; - unsigned int dlines; - unsigned int xlines; - unsigned int resvs; - unsigned int error; +struct counter { + unsigned int klines; + unsigned int dlines; + unsigned int xlines; + unsigned int resvs; + unsigned int error; } count = {0, 0, 0, 0, 0}; /* flags set by command line options */ -struct flags -{ - int none; - int export; - int import; - int verify; - int vacuum; - int pretend; - int verbose; - int wipe; - int dupes_ok; +struct flags { + int none; + int export; + int import; + int verify; + int vacuum; + int pretend; + int verbose; + int wipe; + int dupes_ok; } flag = {YES, NO, NO, NO, NO, NO, NO, NO, NO}; /* *INDENT-ON* */ @@ -128,148 +125,140 @@ static void wipe_schema(void); static void drop_dupes(const char *user, const char *host, const char *t); /** - * swing your pants + * swing your pants */ int main(int argc, char *argv[]) { - char etc[PATH_MAX]; - char conf[PATH_MAX]; - int opt; - int i; + char etc[PATH_MAX]; + char conf[PATH_MAX]; + int opt; + int i; - rb_strlcpy(me, argv[0], sizeof(me)); + rb_strlcpy(me, argv[0], sizeof(me)); - while((opt = getopt(argc, argv, "hieuspvwd")) != -1) - { - switch (opt) - { - case 'h': - print_help(EXIT_SUCCESS); - break; - case 'i': - flag.none = NO; - flag.import = YES; - break; - case 'e': - flag.none = NO; - flag.export = YES; - break; - case 'u': - flag.none = NO; - flag.verify = YES; - break; - case 's': - flag.none = NO; - flag.vacuum = YES; - break; - case 'p': - flag.pretend = YES; - break; - case 'v': - flag.verbose = YES; - break; - case 'w': - flag.wipe = YES; - break; - case 'd': - flag.dupes_ok = YES; - break; - default: /* '?' */ - print_help(EXIT_FAILURE); - } - } + while((opt = getopt(argc, argv, "hieuspvwd")) != -1) { + switch (opt) { + case 'h': + print_help(EXIT_SUCCESS); + break; + case 'i': + flag.none = NO; + flag.import = YES; + break; + case 'e': + flag.none = NO; + flag.export = YES; + break; + case 'u': + flag.none = NO; + flag.verify = YES; + break; + case 's': + flag.none = NO; + flag.vacuum = YES; + break; + case 'p': + flag.pretend = YES; + break; + case 'v': + flag.verbose = YES; + break; + case 'w': + flag.wipe = YES; + break; + case 'd': + flag.dupes_ok = YES; + break; + default: /* '?' */ + print_help(EXIT_FAILURE); + } + } - /* they should really read the help. */ - if(flag.none) - print_help(EXIT_FAILURE); + /* they should really read the help. */ + if(flag.none) + print_help(EXIT_FAILURE); - if((flag.import && flag.export) || (flag.export && flag.wipe) - || (flag.verify && flag.pretend) || (flag.export && flag.pretend)) - { - fprintf(stderr, "* Error: Conflicting flags.\n"); - if(flag.export && flag.pretend) - fprintf(stderr, "* There is nothing to 'pretend' when exporting.\n"); + if((flag.import && flag.export) || (flag.export && flag.wipe) + || (flag.verify && flag.pretend) || (flag.export && flag.pretend)) { + fprintf(stderr, "* Error: Conflicting flags.\n"); + if(flag.export && flag.pretend) + fprintf(stderr, "* There is nothing to 'pretend' when exporting.\n"); - fprintf(stderr, "* For an explination of commands, run: %s -h\n", me); - exit(EXIT_FAILURE); - } + fprintf(stderr, "* For an explination of commands, run: %s -h\n", me); + exit(EXIT_FAILURE); + } - if(argv[optind] != NULL) - rb_strlcpy(etc, argv[optind], sizeof(etc)); - else - rb_strlcpy(etc, ETCPATH, sizeof(ETCPATH)); + if(argv[optind] != NULL) + rb_strlcpy(etc, argv[optind], sizeof(etc)); + else + rb_strlcpy(etc, ETCPATH, sizeof(ETCPATH)); - fprintf(stdout, - "* ircd-ratbox bantool v.%s ($Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $)\n", - BT_VERSION); + fprintf(stdout, + "* ircd-ratbox bantool v.%s ($Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $)\n", + BT_VERSION); - if(flag.pretend == NO) - { - if(rsdb_init(db_error_cb) == -1) - { - fprintf(stderr, "* Error: Unable to open database\n"); - exit(EXIT_FAILURE); - } - check_schema(); + if(flag.pretend == NO) { + if(rsdb_init(db_error_cb) == -1) { + fprintf(stderr, "* Error: Unable to open database\n"); + exit(EXIT_FAILURE); + } + check_schema(); - if(flag.vacuum) - db_reclaim_slack(); + if(flag.vacuum) + db_reclaim_slack(); - if(flag.import && flag.wipe) - { - flag.dupes_ok = YES; /* dont check for dupes if we are wiping the db clean */ - for(i = 0; i < 3; i++) - fprintf(stdout, - "* WARNING: YOU ARE ABOUT TO WIPE YOUR DATABASE!\n"); + if(flag.import && flag.wipe) { + flag.dupes_ok = YES; /* dont check for dupes if we are wiping the db clean */ + for(i = 0; i < 3; i++) + fprintf(stdout, + "* WARNING: YOU ARE ABOUT TO WIPE YOUR DATABASE!\n"); - fprintf(stdout, "* Press ^C to abort! "); - fflush(stdout); - rb_sleep(10, 0); - fprintf(stdout, "Carrying on...\n"); - wipe_schema(); - } - } - if(flag.verbose && flag.dupes_ok == YES) - fprintf(stdout, "* Allowing duplicate bans...\n"); + fprintf(stdout, "* Press ^C to abort! "); + fflush(stdout); + rb_sleep(10, 0); + fprintf(stdout, "Carrying on...\n"); + wipe_schema(); + } + } + if(flag.verbose && flag.dupes_ok == YES) + fprintf(stdout, "* Allowing duplicate bans...\n"); - /* checking for our files to import or export */ - for(i = 0; i < LAST_BANDB_TYPE; i++) - { - rb_snprintf(conf, sizeof(conf), "%s/%s.conf%s", - etc, bandb_table[i], bandb_suffix[i]); + /* checking for our files to import or export */ + for(i = 0; i < LAST_BANDB_TYPE; i++) { + rb_snprintf(conf, sizeof(conf), "%s/%s.conf%s", + etc, bandb_table[i], bandb_suffix[i]); - if(flag.import && flag.pretend == NO) - rsdb_transaction(RSDB_TRANS_START); + if(flag.import && flag.pretend == NO) + rsdb_transaction(RSDB_TRANS_START); - if(flag.import) - import_config(conf, i); + if(flag.import) + import_config(conf, i); - if(flag.export) - export_config(conf, i); + if(flag.export) + export_config(conf, i); - if(flag.import && flag.pretend == NO) - rsdb_transaction(RSDB_TRANS_END); - } + if(flag.import && flag.pretend == NO) + rsdb_transaction(RSDB_TRANS_END); + } - if(flag.import) - { - if(count.error && flag.verbose) - fprintf(stderr, "* I was unable to locate %i config files to import.\n", - count.error); + if(flag.import) { + if(count.error && flag.verbose) + fprintf(stderr, "* I was unable to locate %i config files to import.\n", + count.error); - fprintf(stdout, "* Import Stats: Klines: %i, Dlines: %i, Xlines: %i, Resvs: %i \n", - count.klines, count.dlines, count.xlines, count.resvs); + fprintf(stdout, "* Import Stats: Klines: %i, Dlines: %i, Xlines: %i, Resvs: %i \n", + count.klines, count.dlines, count.xlines, count.resvs); - fprintf(stdout, - "*\n* If your IRC server is currently running, newly imported bans \n* will not take effect until you issue the command: /quote rehash bans\n"); + fprintf(stdout, + "*\n* If your IRC server is currently running, newly imported bans \n* will not take effect until you issue the command: /quote rehash bans\n"); - if(flag.pretend) - fprintf(stdout, - "* Pretend mode engaged. Nothing was actually entered into the database.\n"); - } + if(flag.pretend) + fprintf(stdout, + "* Pretend mode engaged. Nothing was actually entered into the database.\n"); + } - return 0; + return 0; } @@ -279,101 +268,97 @@ main(int argc, char *argv[]) static void export_config(const char *conf, int id) { - struct rsdb_table table; - static char sql[BUFSIZE * 2]; - static char buf[512]; - FILE *fd = NULL; - int j; + struct rsdb_table table; + static char sql[BUFSIZE * 2]; + static char buf[512]; + FILE *fd = NULL; + int j; - /* for sanity sake */ - const int mask1 = 0; - const int mask2 = 1; - const int reason = 2; - const int oper = 3; - const int ts = 4; - /* const int perm = 5; */ + /* for sanity sake */ + const int mask1 = 0; + const int mask2 = 1; + const int reason = 2; + const int oper = 3; + const int ts = 4; + /* const int perm = 5; */ - if(!table_has_rows(bandb_table[id])) - return; + if(!table_has_rows(bandb_table[id])) + return; - if(strstr(conf, ".perm") != 0) - rb_snprintf(sql, sizeof(sql), - "SELECT DISTINCT mask1,mask2,reason,oper,time FROM %s WHERE perm = 1 ORDER BY time", - bandb_table[id]); - else - rb_snprintf(sql, sizeof(sql), - "SELECT DISTINCT mask1,mask2,reason,oper,time FROM %s WHERE perm = 0 ORDER BY time", - bandb_table[id]); + if(strstr(conf, ".perm") != 0) + rb_snprintf(sql, sizeof(sql), + "SELECT DISTINCT mask1,mask2,reason,oper,time FROM %s WHERE perm = 1 ORDER BY time", + bandb_table[id]); + else + rb_snprintf(sql, sizeof(sql), + "SELECT DISTINCT mask1,mask2,reason,oper,time FROM %s WHERE perm = 0 ORDER BY time", + bandb_table[id]); - rsdb_exec_fetch(&table, sql); - if(table.row_count <= 0) - { - rsdb_exec_fetch_end(&table); - return; - } + rsdb_exec_fetch(&table, sql); + if(table.row_count <= 0) { + rsdb_exec_fetch_end(&table); + return; + } - if(flag.verbose) - fprintf(stdout, "* checking for %s: ", conf); /* debug */ + if(flag.verbose) + fprintf(stdout, "* checking for %s: ", conf); /* debug */ - /* open config for reading, or skip to the next */ - if(!(fd = fopen(conf, "w"))) - { - if(flag.verbose) - fprintf(stdout, "\tmissing.\n"); - count.error++; - return; - } + /* open config for reading, or skip to the next */ + if(!(fd = fopen(conf, "w"))) { + if(flag.verbose) + fprintf(stdout, "\tmissing.\n"); + count.error++; + return; + } - for(j = 0; j < table.row_count; j++) - { - switch (id) - { - case BANDB_DLINE: - case BANDB_DLINE_PERM: - rb_snprintf(buf, sizeof(buf), - "\"%s\",\"%s\",\"\",\"%s\",\"%s\",%s\n", - table.row[j][mask1], - mangle_reason(table.row[j][reason]), - bt_smalldate(table.row[j][ts]), - table.row[j][oper], table.row[j][ts]); - break; + for(j = 0; j < table.row_count; j++) { + switch (id) { + case BANDB_DLINE: + case BANDB_DLINE_PERM: + rb_snprintf(buf, sizeof(buf), + "\"%s\",\"%s\",\"\",\"%s\",\"%s\",%s\n", + table.row[j][mask1], + mangle_reason(table.row[j][reason]), + bt_smalldate(table.row[j][ts]), + table.row[j][oper], table.row[j][ts]); + break; - case BANDB_XLINE: - case BANDB_XLINE_PERM: - rb_snprintf(buf, sizeof(buf), - "\"%s\",\"0\",\"%s\",\"%s\",%s\n", - escape_quotes(table.row[j][mask1]), - mangle_reason(table.row[j][reason]), - table.row[j][oper], table.row[j][ts]); - break; + case BANDB_XLINE: + case BANDB_XLINE_PERM: + rb_snprintf(buf, sizeof(buf), + "\"%s\",\"0\",\"%s\",\"%s\",%s\n", + escape_quotes(table.row[j][mask1]), + mangle_reason(table.row[j][reason]), + table.row[j][oper], table.row[j][ts]); + break; - case BANDB_RESV: - case BANDB_RESV_PERM: - rb_snprintf(buf, sizeof(buf), - "\"%s\",\"%s\",\"%s\",%s\n", - table.row[j][mask1], - mangle_reason(table.row[j][reason]), - table.row[j][oper], table.row[j][ts]); - break; + case BANDB_RESV: + case BANDB_RESV_PERM: + rb_snprintf(buf, sizeof(buf), + "\"%s\",\"%s\",\"%s\",%s\n", + table.row[j][mask1], + mangle_reason(table.row[j][reason]), + table.row[j][oper], table.row[j][ts]); + break; - default: /* Klines */ - rb_snprintf(buf, sizeof(buf), - "\"%s\",\"%s\",\"%s\",\"\",\"%s\",\"%s\",%s\n", - table.row[j][mask1], table.row[j][mask2], - mangle_reason(table.row[j][reason]), - bt_smalldate(table.row[j][ts]), table.row[j][oper], - table.row[j][ts]); - break; - } + default: /* Klines */ + rb_snprintf(buf, sizeof(buf), + "\"%s\",\"%s\",\"%s\",\"\",\"%s\",\"%s\",%s\n", + table.row[j][mask1], table.row[j][mask2], + mangle_reason(table.row[j][reason]), + bt_smalldate(table.row[j][ts]), table.row[j][oper], + table.row[j][ts]); + break; + } - fprintf(fd, "%s", buf); - } + fprintf(fd, "%s", buf); + } - rsdb_exec_fetch_end(&table); - if(flag.verbose) - fprintf(stdout, "\twritten.\n"); - fclose(fd); + rsdb_exec_fetch_end(&table); + if(flag.verbose) + fprintf(stdout, "\twritten.\n"); + fclose(fd); } /** @@ -382,167 +367,159 @@ export_config(const char *conf, int id) static void import_config(const char *conf, int id) { - FILE *fd; + FILE *fd; - char line[BUFSIZE]; - char *p; - int i = 0; + char line[BUFSIZE]; + char *p; + int i = 0; - char f_perm = 0; - const char *f_mask1 = NULL; - const char *f_mask2 = NULL; - const char *f_oper = NULL; - const char *f_time = NULL; - const char *f_reason = NULL; - const char *f_oreason = NULL; - char newreason[REASONLEN]; + char f_perm = 0; + const char *f_mask1 = NULL; + const char *f_mask2 = NULL; + const char *f_oper = NULL; + const char *f_time = NULL; + const char *f_reason = NULL; + const char *f_oreason = NULL; + char newreason[REASONLEN]; - if(flag.verbose) - fprintf(stdout, "* checking for %s: ", conf); /* debug */ + if(flag.verbose) + fprintf(stdout, "* checking for %s: ", conf); /* debug */ - /* open config for reading, or skip to the next */ - if(!(fd = fopen(conf, "r"))) - { - if(flag.verbose) - fprintf(stdout, "%*s", strlen(bandb_suffix[id]) > 0 ? 10 : 15, - "missing.\n"); - count.error++; - return; - } + /* open config for reading, or skip to the next */ + if(!(fd = fopen(conf, "r"))) { + if(flag.verbose) + fprintf(stdout, "%*s", strlen(bandb_suffix[id]) > 0 ? 10 : 15, + "missing.\n"); + count.error++; + return; + } - if(strstr(conf, ".perm") != 0) - f_perm = 1; + if(strstr(conf, ".perm") != 0) + f_perm = 1; - /* xline - * "SYSTEM","0","banned","stevoo!stevoo@efnet.port80.se{stevoo}",1111080437 - * resv - * "OseK","banned nickname","stevoo!stevoo@efnet.port80.se{stevoo}",1111031619 - * dline - * "194.158.192.0/19","laptop scammers","","2005/3/17 05.33","stevoo!stevoo@efnet.port80.se{stevoo}",1111033988 - */ - while(fgets(line, sizeof(line), fd)) - { - if((p = strpbrk(line, "\r\n")) != NULL) - *p = '\0'; + /* xline + * "SYSTEM","0","banned","stevoo!stevoo@efnet.port80.se{stevoo}",1111080437 + * resv + * "OseK","banned nickname","stevoo!stevoo@efnet.port80.se{stevoo}",1111031619 + * dline + * "194.158.192.0/19","laptop scammers","","2005/3/17 05.33","stevoo!stevoo@efnet.port80.se{stevoo}",1111033988 + */ + while(fgets(line, sizeof(line), fd)) { + if((p = strpbrk(line, "\r\n")) != NULL) + *p = '\0'; - if((*line == '\0') || (*line == '#')) - continue; + if((*line == '\0') || (*line == '#')) + continue; - /* mask1 */ - f_mask1 = getfield(line); + /* mask1 */ + f_mask1 = getfield(line); - if(EmptyString(f_mask1)) - continue; + if(EmptyString(f_mask1)) + continue; - /* mask2 */ - switch (id) - { - case BANDB_XLINE: - case BANDB_XLINE_PERM: - f_mask1 = escape_quotes(clean_gecos_field(f_mask1)); - getfield(NULL); /* empty field */ - break; + /* mask2 */ + switch (id) { + case BANDB_XLINE: + case BANDB_XLINE_PERM: + f_mask1 = escape_quotes(clean_gecos_field(f_mask1)); + getfield(NULL); /* empty field */ + break; - case BANDB_RESV: - case BANDB_RESV_PERM: - case BANDB_DLINE: - case BANDB_DLINE_PERM: - break; + case BANDB_RESV: + case BANDB_RESV_PERM: + case BANDB_DLINE: + case BANDB_DLINE_PERM: + break; - default: - f_mask2 = getfield(NULL); - if(EmptyString(f_mask2)) - continue; - break; - } + default: + f_mask2 = getfield(NULL); + if(EmptyString(f_mask2)) + continue; + break; + } - /* reason */ - f_reason = getfield(NULL); - if(EmptyString(f_reason)) - continue; + /* reason */ + f_reason = getfield(NULL); + if(EmptyString(f_reason)) + continue; - /* oper comment */ - switch (id) - { - case BANDB_KLINE: - case BANDB_KLINE_PERM: - case BANDB_DLINE: - case BANDB_DLINE_PERM: - f_oreason = getfield(NULL); - getfield(NULL); - break; + /* oper comment */ + switch (id) { + case BANDB_KLINE: + case BANDB_KLINE_PERM: + case BANDB_DLINE: + case BANDB_DLINE_PERM: + f_oreason = getfield(NULL); + getfield(NULL); + break; - default: - break; - } + default: + break; + } - f_oper = getfield(NULL); - f_time = strip_quotes(f_oper + strlen(f_oper) + 2); - if(EmptyString(f_oper)) - f_oper = "unknown"; + f_oper = getfield(NULL); + f_time = strip_quotes(f_oper + strlen(f_oper) + 2); + if(EmptyString(f_oper)) + f_oper = "unknown"; - /* meh */ - if(id == BANDB_KLINE || id == BANDB_KLINE_PERM) - { - if(strstr(f_mask1, "!") != NULL) - { - fprintf(stderr, - "* SKIPPING INVALID KLINE %s@%s set by %s\n", - f_mask1, f_mask2, f_oper); - fprintf(stderr, " You may wish to re-apply it correctly.\n"); - continue; - } - } + /* meh */ + if(id == BANDB_KLINE || id == BANDB_KLINE_PERM) { + if(strstr(f_mask1, "!") != NULL) { + fprintf(stderr, + "* SKIPPING INVALID KLINE %s@%s set by %s\n", + f_mask1, f_mask2, f_oper); + fprintf(stderr, " You may wish to re-apply it correctly.\n"); + continue; + } + } - /* append operreason_field to reason_field */ - if(!EmptyString(f_oreason)) - rb_snprintf(newreason, sizeof(newreason), "%s | %s", f_reason, f_oreason); - else - rb_snprintf(newreason, sizeof(newreason), "%s", f_reason); + /* append operreason_field to reason_field */ + if(!EmptyString(f_oreason)) + rb_snprintf(newreason, sizeof(newreason), "%s | %s", f_reason, f_oreason); + else + rb_snprintf(newreason, sizeof(newreason), "%s", f_reason); - if(flag.pretend == NO) - { - if(flag.dupes_ok == NO) - drop_dupes(f_mask1, f_mask2, bandb_table[id]); + if(flag.pretend == NO) { + if(flag.dupes_ok == NO) + drop_dupes(f_mask1, f_mask2, bandb_table[id]); - rsdb_exec(NULL, - "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES('%Q','%Q','%Q','%Q','%d','%Q')", - bandb_table[id], f_mask1, f_mask2, f_oper, f_time, f_perm, - newreason); - } + rsdb_exec(NULL, + "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES('%Q','%Q','%Q','%Q','%d','%Q')", + bandb_table[id], f_mask1, f_mask2, f_oper, f_time, f_perm, + newreason); + } - if(flag.pretend && flag.verbose) - fprintf(stdout, - "%s: perm(%d) mask1(%s) mask2(%s) oper(%s) reason(%s) time(%s)\n", - bandb_table[id], f_perm, f_mask1, f_mask2, f_oper, newreason, - f_time); + if(flag.pretend && flag.verbose) + fprintf(stdout, + "%s: perm(%d) mask1(%s) mask2(%s) oper(%s) reason(%s) time(%s)\n", + bandb_table[id], f_perm, f_mask1, f_mask2, f_oper, newreason, + f_time); - i++; - } + i++; + } - switch (bandb_letter[id]) - { - case 'K': - count.klines += i; - break; - case 'D': - count.dlines += i; - break; - case 'X': - count.xlines += i; - break; - case 'R': - count.resvs += i; - break; - default: - break; - } + switch (bandb_letter[id]) { + case 'K': + count.klines += i; + break; + case 'D': + count.dlines += i; + break; + case 'X': + count.xlines += i; + break; + case 'R': + count.resvs += i; + break; + default: + break; + } - if(flag.verbose) - fprintf(stdout, "%*s\n", strlen(bandb_suffix[id]) > 0 ? 10 : 15, "imported."); + if(flag.verbose) + fprintf(stdout, "%*s\n", strlen(bandb_suffix[id]) > 0 ? 10 : 15, "imported."); - return; + return; } /** @@ -555,59 +532,52 @@ import_config(const char *conf, int id) char * getfield(char *newline) { - static char *line = NULL; - char *end, *field; + static char *line = NULL; + char *end, *field; - if(newline != NULL) - line = newline; + if(newline != NULL) + line = newline; - if(line == NULL) - return (NULL); + if(line == NULL) + return (NULL); - field = line; + field = line; - /* XXX make this skip to first " if present */ - if(*field == '"') - field++; - else - return (NULL); /* mal-formed field */ + /* XXX make this skip to first " if present */ + if(*field == '"') + field++; + else + return (NULL); /* mal-formed field */ - end = strchr(line, ','); + end = strchr(line, ','); - while(1) - { - /* no trailing , - last field */ - if(end == NULL) - { - end = line + strlen(line); - line = NULL; + while(1) { + /* no trailing , - last field */ + if(end == NULL) { + end = line + strlen(line); + line = NULL; - if(*end == '"') - { - *end = '\0'; - return field; - } - else - return NULL; - } - else - { - /* look for a ", to mark the end of a field.. */ - if(*(end - 1) == '"') - { - line = end + 1; - end--; - *end = '\0'; - return field; - } + if(*end == '"') { + *end = '\0'; + return field; + } else + return NULL; + } else { + /* look for a ", to mark the end of a field.. */ + if(*(end - 1) == '"') { + line = end + 1; + end--; + *end = '\0'; + return field; + } - /* search for the next ',' */ - end++; - end = strchr(end, ','); - } - } + /* search for the next ',' */ + end++; + end = strchr(end, ','); + } + } - return NULL; + return NULL; } /** @@ -616,22 +586,20 @@ getfield(char *newline) static char * strip_quotes(const char *string) { - static char buf[14]; /* int(11) + 2 + \0 */ - char *str = buf; + static char buf[14]; /* int(11) + 2 + \0 */ + char *str = buf; - if(string == NULL) - return NULL; + if(string == NULL) + return NULL; - while(*string) - { - if(*string != '"') - { - *str++ = *string; - } - string++; - } - *str = '\0'; - return buf; + while(*string) { + if(*string != '"') { + *str++ = *string; + } + string++; + } + *str = '\0'; + return buf; } /** @@ -640,58 +608,52 @@ strip_quotes(const char *string) static char * escape_quotes(const char *string) { - static char buf[BUFSIZE * 2]; - char *str = buf; + static char buf[BUFSIZE * 2]; + char *str = buf; - if(string == NULL) - return NULL; + if(string == NULL) + return NULL; - while(*string) - { - if(*string == '"') - { - *str++ = '\\'; - *str++ = '"'; - } - else - { - *str++ = *string; - } - string++; - } - *str = '\0'; - return buf; + while(*string) { + if(*string == '"') { + *str++ = '\\'; + *str++ = '"'; + } else { + *str++ = *string; + } + string++; + } + *str = '\0'; + return buf; } static char * mangle_reason(const char *string) { - static char buf[BUFSIZE * 2]; - char *str = buf; + static char buf[BUFSIZE * 2]; + char *str = buf; - if(string == NULL) - return NULL; + if(string == NULL) + return NULL; - while(*string) - { - switch (*string) - { - case '"': - *str = '\''; - break; - case ':': - *str = ' '; - break; - default: - *str = *string; - } - string++; - str++; + while(*string) { + switch (*string) { + case '"': + *str = '\''; + break; + case ':': + *str = ' '; + break; + default: + *str = *string; + } + string++; + str++; - } - *str = '\0'; - return buf; + } + *str = '\0'; + return buf; } @@ -701,25 +663,22 @@ mangle_reason(const char *string) static const char * clean_gecos_field(const char *gecos) { - static char buf[BUFSIZE * 2]; - char *str = buf; + static char buf[BUFSIZE * 2]; + char *str = buf; - if(gecos == NULL) - return NULL; + if(gecos == NULL) + return NULL; - while(*gecos) - { - if(*gecos == ' ') - { - *str++ = '\\'; - *str++ = 's'; - } - else - *str++ = *gecos; - gecos++; - } - *str = '\0'; - return buf; + while(*gecos) { + if(*gecos == ' ') { + *str++ = '\\'; + *str++ = 's'; + } else + *str++ = *gecos; + gecos++; + } + *str = '\0'; + return buf; } /** @@ -728,59 +687,55 @@ clean_gecos_field(const char *gecos) static void check_schema(void) { - int i, j; - char type[8]; /* longest string is 'INTEGER\0' */ + int i, j; + char type[8]; /* longest string is 'INTEGER\0' */ - if(flag.verify || flag.verbose) - fprintf(stdout, "* Verifying database.\n"); + if(flag.verify || flag.verbose) + fprintf(stdout, "* Verifying database.\n"); - const char *columns[] = { - "perm", - "mask1", - "mask2", - "oper", - "time", - "reason", - NULL - }; + const char *columns[] = { + "perm", + "mask1", + "mask2", + "oper", + "time", + "reason", + NULL + }; - for(i = 0; i < LAST_BANDB_TYPE; i++) - { - if(!table_exists(bandb_table[i])) - { - rsdb_exec(NULL, - "CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", - bandb_table[i]); - } + for(i = 0; i < LAST_BANDB_TYPE; i++) { + if(!table_exists(bandb_table[i])) { + rsdb_exec(NULL, + "CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", + bandb_table[i]); + } - /* - * i can't think of any better way to do this, other then attempt to - * force the creation of column that may, or may not already exist. --dubkat - */ - else - { - for(j = 0; columns[j] != NULL; j++) - { - if(!strcmp(columns[j], "time") && !strcmp(columns[j], "perm")) - rb_strlcpy(type, "INTEGER", sizeof(type)); - else - rb_strlcpy(type, "TEXT", sizeof(type)); + /* + * i can't think of any better way to do this, other then attempt to + * force the creation of column that may, or may not already exist. --dubkat + */ + else { + for(j = 0; columns[j] != NULL; j++) { + if(!strcmp(columns[j], "time") && !strcmp(columns[j], "perm")) + rb_strlcpy(type, "INTEGER", sizeof(type)); + else + rb_strlcpy(type, "TEXT", sizeof(type)); - /* attempt to add a column with extreme prejudice, errors are ignored */ - rsdb_exec(NULL, "ALTER TABLE %s ADD COLUMN %s %s", bandb_table[i], - columns[j], type); - } - } + /* attempt to add a column with extreme prejudice, errors are ignored */ + rsdb_exec(NULL, "ALTER TABLE %s ADD COLUMN %s %s", bandb_table[i], + columns[j], type); + } + } - i++; /* skip over .perm */ - } + i++; /* skip over .perm */ + } } static void db_reclaim_slack(void) { - fprintf(stdout, "* Reclaiming free space.\n"); - rsdb_exec(NULL, "VACUUM"); + fprintf(stdout, "* Reclaiming free space.\n"); + rsdb_exec(NULL, "VACUUM"); } @@ -790,11 +745,11 @@ db_reclaim_slack(void) static int table_exists(const char *dbtab) { - struct rsdb_table table; - rsdb_exec_fetch(&table, "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", - dbtab); - rsdb_exec_fetch_end(&table); - return table.row_count; + struct rsdb_table table; + rsdb_exec_fetch(&table, "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", + dbtab); + rsdb_exec_fetch_end(&table); + return table.row_count; } /** @@ -803,10 +758,10 @@ table_exists(const char *dbtab) static int table_has_rows(const char *dbtab) { - struct rsdb_table table; - rsdb_exec_fetch(&table, "SELECT * FROM %s", dbtab); - rsdb_exec_fetch_end(&table); - return table.row_count; + struct rsdb_table table; + rsdb_exec_fetch(&table, "SELECT * FROM %s", dbtab); + rsdb_exec_fetch_end(&table); + return table.row_count; } /** @@ -815,16 +770,15 @@ table_has_rows(const char *dbtab) static void wipe_schema(void) { - int i; - rsdb_transaction(RSDB_TRANS_START); - for(i = 0; i < LAST_BANDB_TYPE; i++) - { - rsdb_exec(NULL, "DROP TABLE %s", bandb_table[i]); - i++; /* double increment to skip over .perm */ - } - rsdb_transaction(RSDB_TRANS_END); + int i; + rsdb_transaction(RSDB_TRANS_START); + for(i = 0; i < LAST_BANDB_TYPE; i++) { + rsdb_exec(NULL, "DROP TABLE %s", bandb_table[i]); + i++; /* double increment to skip over .perm */ + } + rsdb_transaction(RSDB_TRANS_END); - check_schema(); + check_schema(); } /** @@ -834,13 +788,13 @@ wipe_schema(void) void drop_dupes(const char *user, const char *host, const char *t) { - rsdb_exec(NULL, "DELETE FROM %s WHERE mask1='%Q' AND mask2='%Q'", t, user, host); + rsdb_exec(NULL, "DELETE FROM %s WHERE mask1='%Q' AND mask2='%Q'", t, user, host); } static void db_error_cb(const char *errstr) { - return; + return; } @@ -850,16 +804,16 @@ db_error_cb(const char *errstr) static char * bt_smalldate(const char *string) { - static char buf[MAX_DATE_STRING]; - struct tm *lt; - time_t t; - t = strtol(string, NULL, 10); - lt = gmtime(&t); - if(lt == NULL) - return NULL; - rb_snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", - lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min); - return buf; + static char buf[MAX_DATE_STRING]; + struct tm *lt; + time_t t; + t = strtol(string, NULL, 10); + lt = gmtime(&t); + if(lt == NULL) + return NULL; + rb_snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", + lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min); + return buf; } /** @@ -868,34 +822,34 @@ bt_smalldate(const char *string) void print_help(int i_exit) { - fprintf(stderr, "bantool v.%s - the ircd-ratbox database tool.\n", BT_VERSION); - fprintf(stderr, "Copyright (C) 2008 Daniel J Reidy \n"); - fprintf(stderr, "$Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $\n\n"); - fprintf(stderr, "This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n\n"); + fprintf(stderr, "bantool v.%s - the ircd-ratbox database tool.\n", BT_VERSION); + fprintf(stderr, "Copyright (C) 2008 Daniel J Reidy \n"); + fprintf(stderr, "$Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $\n\n"); + fprintf(stderr, "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n\n"); - fprintf(stderr, "Usage: %s <-i|-e> [-p] [-v] [-h] [-d] [-w] [path]\n", me); - fprintf(stderr, " -h : Display some slightly useful help.\n"); - fprintf(stderr, " -i : Actually import configs into your database.\n"); - fprintf(stderr, " -e : Export your database to old-style flat files.\n"); - fprintf(stderr, - " This is suitable for redistrubuting your banlists, or creating backups.\n"); - fprintf(stderr, " -s : Reclaim empty slack space the database may be taking up.\n"); - fprintf(stderr, " -u : Update the database tables to support any new features.\n"); - fprintf(stderr, - " This is automaticlly done if you are importing or exporting\n"); - fprintf(stderr, " but should be run whenever you upgrade the ircd.\n"); - fprintf(stderr, - " -p : pretend, checks for the configs, and parses them, then tells you some data...\n"); - fprintf(stderr, " but does not touch your database.\n"); - fprintf(stderr, - " -v : Be verbose... and it *is* very verbose! (intended for debugging)\n"); - fprintf(stderr, " -d : Enable checking for redunant entries.\n"); - fprintf(stderr, " -w : Completly wipe your database clean. May be used with -i \n"); - fprintf(stderr, - " path : An optional directory containing old ratbox configs for import, or export.\n"); - fprintf(stderr, " If not specified, it looks in PREFIX/etc.\n"); - exit(i_exit); + fprintf(stderr, "Usage: %s <-i|-e> [-p] [-v] [-h] [-d] [-w] [path]\n", me); + fprintf(stderr, " -h : Display some slightly useful help.\n"); + fprintf(stderr, " -i : Actually import configs into your database.\n"); + fprintf(stderr, " -e : Export your database to old-style flat files.\n"); + fprintf(stderr, + " This is suitable for redistrubuting your banlists, or creating backups.\n"); + fprintf(stderr, " -s : Reclaim empty slack space the database may be taking up.\n"); + fprintf(stderr, " -u : Update the database tables to support any new features.\n"); + fprintf(stderr, + " This is automaticlly done if you are importing or exporting\n"); + fprintf(stderr, " but should be run whenever you upgrade the ircd.\n"); + fprintf(stderr, + " -p : pretend, checks for the configs, and parses them, then tells you some data...\n"); + fprintf(stderr, " but does not touch your database.\n"); + fprintf(stderr, + " -v : Be verbose... and it *is* very verbose! (intended for debugging)\n"); + fprintf(stderr, " -d : Enable checking for redunant entries.\n"); + fprintf(stderr, " -w : Completly wipe your database clean. May be used with -i \n"); + fprintf(stderr, + " path : An optional directory containing old ratbox configs for import, or export.\n"); + fprintf(stderr, " If not specified, it looks in PREFIX/etc.\n"); + exit(i_exit); } diff --git a/bandb/rsdb.h b/bandb/rsdb.h index 5b55d5d..f62b894 100644 --- a/bandb/rsdb.h +++ b/bandb/rsdb.h @@ -6,19 +6,17 @@ typedef void rsdb_error_cb(const char *); typedef int (*rsdb_callback) (int, const char **); -typedef enum rsdb_transtype -{ - RSDB_TRANS_START, - RSDB_TRANS_END +typedef enum rsdb_transtype { + RSDB_TRANS_START, + RSDB_TRANS_END } rsdb_transtype; -struct rsdb_table -{ - char ***row; - int row_count; - int col_count; - void *arg; +struct rsdb_table { + char ***row; + int row_count; + int col_count; + void *arg; }; int rsdb_init(rsdb_error_cb *); diff --git a/bandb/rsdb_snprintf.c b/bandb/rsdb_snprintf.c index 2fb35de..a8ba7e7 100644 --- a/bandb/rsdb_snprintf.c +++ b/bandb/rsdb_snprintf.c @@ -39,206 +39,206 @@ #define TABLE_MAX 1000 static const char *IntTable[] = { - "000", "100", "200", "300", "400", - "500", "600", "700", "800", "900", - "010", "110", "210", "310", "410", - "510", "610", "710", "810", "910", - "020", "120", "220", "320", "420", - "520", "620", "720", "820", "920", - "030", "130", "230", "330", "430", - "530", "630", "730", "830", "930", - "040", "140", "240", "340", "440", - "540", "640", "740", "840", "940", - "050", "150", "250", "350", "450", - "550", "650", "750", "850", "950", - "060", "160", "260", "360", "460", - "560", "660", "760", "860", "960", - "070", "170", "270", "370", "470", - "570", "670", "770", "870", "970", - "080", "180", "280", "380", "480", - "580", "680", "780", "880", "980", - "090", "190", "290", "390", "490", - "590", "690", "790", "890", "990", - "001", "101", "201", "301", "401", - "501", "601", "701", "801", "901", - "011", "111", "211", "311", "411", - "511", "611", "711", "811", "911", - "021", "121", "221", "321", "421", - "521", "621", "721", "821", "921", - "031", "131", "231", "331", "431", - "531", "631", "731", "831", "931", - "041", "141", "241", "341", "441", - "541", "641", "741", "841", "941", - "051", "151", "251", "351", "451", - "551", "651", "751", "851", "951", - "061", "161", "261", "361", "461", - "561", "661", "761", "861", "961", - "071", "171", "271", "371", "471", - "571", "671", "771", "871", "971", - "081", "181", "281", "381", "481", - "581", "681", "781", "881", "981", - "091", "191", "291", "391", "491", - "591", "691", "791", "891", "991", - "002", "102", "202", "302", "402", - "502", "602", "702", "802", "902", - "012", "112", "212", "312", "412", - "512", "612", "712", "812", "912", - "022", "122", "222", "322", "422", - "522", "622", "722", "822", "922", - "032", "132", "232", "332", "432", - "532", "632", "732", "832", "932", - "042", "142", "242", "342", "442", - "542", "642", "742", "842", "942", - "052", "152", "252", "352", "452", - "552", "652", "752", "852", "952", - "062", "162", "262", "362", "462", - "562", "662", "762", "862", "962", - "072", "172", "272", "372", "472", - "572", "672", "772", "872", "972", - "082", "182", "282", "382", "482", - "582", "682", "782", "882", "982", - "092", "192", "292", "392", "492", - "592", "692", "792", "892", "992", - "003", "103", "203", "303", "403", - "503", "603", "703", "803", "903", - "013", "113", "213", "313", "413", - "513", "613", "713", "813", "913", - "023", "123", "223", "323", "423", - "523", "623", "723", "823", "923", - "033", "133", "233", "333", "433", - "533", "633", "733", "833", "933", - "043", "143", "243", "343", "443", - "543", "643", "743", "843", "943", - "053", "153", "253", "353", "453", - "553", "653", "753", "853", "953", - "063", "163", "263", "363", "463", - "563", "663", "763", "863", "963", - "073", "173", "273", "373", "473", - "573", "673", "773", "873", "973", - "083", "183", "283", "383", "483", - "583", "683", "783", "883", "983", - "093", "193", "293", "393", "493", - "593", "693", "793", "893", "993", - "004", "104", "204", "304", "404", - "504", "604", "704", "804", "904", - "014", "114", "214", "314", "414", - "514", "614", "714", "814", "914", - "024", "124", "224", "324", "424", - "524", "624", "724", "824", "924", - "034", "134", "234", "334", "434", - "534", "634", "734", "834", "934", - "044", "144", "244", "344", "444", - "544", "644", "744", "844", "944", - "054", "154", "254", "354", "454", - "554", "654", "754", "854", "954", - "064", "164", "264", "364", "464", - "564", "664", "764", "864", "964", - "074", "174", "274", "374", "474", - "574", "674", "774", "874", "974", - "084", "184", "284", "384", "484", - "584", "684", "784", "884", "984", - "094", "194", "294", "394", "494", - "594", "694", "794", "894", "994", - "005", "105", "205", "305", "405", - "505", "605", "705", "805", "905", - "015", "115", "215", "315", "415", - "515", "615", "715", "815", "915", - "025", "125", "225", "325", "425", - "525", "625", "725", "825", "925", - "035", "135", "235", "335", "435", - "535", "635", "735", "835", "935", - "045", "145", "245", "345", "445", - "545", "645", "745", "845", "945", - "055", "155", "255", "355", "455", - "555", "655", "755", "855", "955", - "065", "165", "265", "365", "465", - "565", "665", "765", "865", "965", - "075", "175", "275", "375", "475", - "575", "675", "775", "875", "975", - "085", "185", "285", "385", "485", - "585", "685", "785", "885", "985", - "095", "195", "295", "395", "495", - "595", "695", "795", "895", "995", - "006", "106", "206", "306", "406", - "506", "606", "706", "806", "906", - "016", "116", "216", "316", "416", - "516", "616", "716", "816", "916", - "026", "126", "226", "326", "426", - "526", "626", "726", "826", "926", - "036", "136", "236", "336", "436", - "536", "636", "736", "836", "936", - "046", "146", "246", "346", "446", - "546", "646", "746", "846", "946", - "056", "156", "256", "356", "456", - "556", "656", "756", "856", "956", - "066", "166", "266", "366", "466", - "566", "666", "766", "866", "966", - "076", "176", "276", "376", "476", - "576", "676", "776", "876", "976", - "086", "186", "286", "386", "486", - "586", "686", "786", "886", "986", - "096", "196", "296", "396", "496", - "596", "696", "796", "896", "996", - "007", "107", "207", "307", "407", - "507", "607", "707", "807", "907", - "017", "117", "217", "317", "417", - "517", "617", "717", "817", "917", - "027", "127", "227", "327", "427", - "527", "627", "727", "827", "927", - "037", "137", "237", "337", "437", - "537", "637", "737", "837", "937", - "047", "147", "247", "347", "447", - "547", "647", "747", "847", "947", - "057", "157", "257", "357", "457", - "557", "657", "757", "857", "957", - "067", "167", "267", "367", "467", - "567", "667", "767", "867", "967", - "077", "177", "277", "377", "477", - "577", "677", "777", "877", "977", - "087", "187", "287", "387", "487", - "587", "687", "787", "887", "987", - "097", "197", "297", "397", "497", - "597", "697", "797", "897", "997", - "008", "108", "208", "308", "408", - "508", "608", "708", "808", "908", - "018", "118", "218", "318", "418", - "518", "618", "718", "818", "918", - "028", "128", "228", "328", "428", - "528", "628", "728", "828", "928", - "038", "138", "238", "338", "438", - "538", "638", "738", "838", "938", - "048", "148", "248", "348", "448", - "548", "648", "748", "848", "948", - "058", "158", "258", "358", "458", - "558", "658", "758", "858", "958", - "068", "168", "268", "368", "468", - "568", "668", "768", "868", "968", - "078", "178", "278", "378", "478", - "578", "678", "778", "878", "978", - "088", "188", "288", "388", "488", - "588", "688", "788", "888", "988", - "098", "198", "298", "398", "498", - "598", "698", "798", "898", "998", - "009", "109", "209", "309", "409", - "509", "609", "709", "809", "909", - "019", "119", "219", "319", "419", - "519", "619", "719", "819", "919", - "029", "129", "229", "329", "429", - "529", "629", "729", "829", "929", - "039", "139", "239", "339", "439", - "539", "639", "739", "839", "939", - "049", "149", "249", "349", "449", - "549", "649", "749", "849", "949", - "059", "159", "259", "359", "459", - "559", "659", "759", "859", "959", - "069", "169", "269", "369", "469", - "569", "669", "769", "869", "969", - "079", "179", "279", "379", "479", - "579", "679", "779", "879", "979", - "089", "189", "289", "389", "489", - "589", "689", "789", "889", "989", - "099", "199", "299", "399", "499", - "599", "699", "799", "899", "999" + "000", "100", "200", "300", "400", + "500", "600", "700", "800", "900", + "010", "110", "210", "310", "410", + "510", "610", "710", "810", "910", + "020", "120", "220", "320", "420", + "520", "620", "720", "820", "920", + "030", "130", "230", "330", "430", + "530", "630", "730", "830", "930", + "040", "140", "240", "340", "440", + "540", "640", "740", "840", "940", + "050", "150", "250", "350", "450", + "550", "650", "750", "850", "950", + "060", "160", "260", "360", "460", + "560", "660", "760", "860", "960", + "070", "170", "270", "370", "470", + "570", "670", "770", "870", "970", + "080", "180", "280", "380", "480", + "580", "680", "780", "880", "980", + "090", "190", "290", "390", "490", + "590", "690", "790", "890", "990", + "001", "101", "201", "301", "401", + "501", "601", "701", "801", "901", + "011", "111", "211", "311", "411", + "511", "611", "711", "811", "911", + "021", "121", "221", "321", "421", + "521", "621", "721", "821", "921", + "031", "131", "231", "331", "431", + "531", "631", "731", "831", "931", + "041", "141", "241", "341", "441", + "541", "641", "741", "841", "941", + "051", "151", "251", "351", "451", + "551", "651", "751", "851", "951", + "061", "161", "261", "361", "461", + "561", "661", "761", "861", "961", + "071", "171", "271", "371", "471", + "571", "671", "771", "871", "971", + "081", "181", "281", "381", "481", + "581", "681", "781", "881", "981", + "091", "191", "291", "391", "491", + "591", "691", "791", "891", "991", + "002", "102", "202", "302", "402", + "502", "602", "702", "802", "902", + "012", "112", "212", "312", "412", + "512", "612", "712", "812", "912", + "022", "122", "222", "322", "422", + "522", "622", "722", "822", "922", + "032", "132", "232", "332", "432", + "532", "632", "732", "832", "932", + "042", "142", "242", "342", "442", + "542", "642", "742", "842", "942", + "052", "152", "252", "352", "452", + "552", "652", "752", "852", "952", + "062", "162", "262", "362", "462", + "562", "662", "762", "862", "962", + "072", "172", "272", "372", "472", + "572", "672", "772", "872", "972", + "082", "182", "282", "382", "482", + "582", "682", "782", "882", "982", + "092", "192", "292", "392", "492", + "592", "692", "792", "892", "992", + "003", "103", "203", "303", "403", + "503", "603", "703", "803", "903", + "013", "113", "213", "313", "413", + "513", "613", "713", "813", "913", + "023", "123", "223", "323", "423", + "523", "623", "723", "823", "923", + "033", "133", "233", "333", "433", + "533", "633", "733", "833", "933", + "043", "143", "243", "343", "443", + "543", "643", "743", "843", "943", + "053", "153", "253", "353", "453", + "553", "653", "753", "853", "953", + "063", "163", "263", "363", "463", + "563", "663", "763", "863", "963", + "073", "173", "273", "373", "473", + "573", "673", "773", "873", "973", + "083", "183", "283", "383", "483", + "583", "683", "783", "883", "983", + "093", "193", "293", "393", "493", + "593", "693", "793", "893", "993", + "004", "104", "204", "304", "404", + "504", "604", "704", "804", "904", + "014", "114", "214", "314", "414", + "514", "614", "714", "814", "914", + "024", "124", "224", "324", "424", + "524", "624", "724", "824", "924", + "034", "134", "234", "334", "434", + "534", "634", "734", "834", "934", + "044", "144", "244", "344", "444", + "544", "644", "744", "844", "944", + "054", "154", "254", "354", "454", + "554", "654", "754", "854", "954", + "064", "164", "264", "364", "464", + "564", "664", "764", "864", "964", + "074", "174", "274", "374", "474", + "574", "674", "774", "874", "974", + "084", "184", "284", "384", "484", + "584", "684", "784", "884", "984", + "094", "194", "294", "394", "494", + "594", "694", "794", "894", "994", + "005", "105", "205", "305", "405", + "505", "605", "705", "805", "905", + "015", "115", "215", "315", "415", + "515", "615", "715", "815", "915", + "025", "125", "225", "325", "425", + "525", "625", "725", "825", "925", + "035", "135", "235", "335", "435", + "535", "635", "735", "835", "935", + "045", "145", "245", "345", "445", + "545", "645", "745", "845", "945", + "055", "155", "255", "355", "455", + "555", "655", "755", "855", "955", + "065", "165", "265", "365", "465", + "565", "665", "765", "865", "965", + "075", "175", "275", "375", "475", + "575", "675", "775", "875", "975", + "085", "185", "285", "385", "485", + "585", "685", "785", "885", "985", + "095", "195", "295", "395", "495", + "595", "695", "795", "895", "995", + "006", "106", "206", "306", "406", + "506", "606", "706", "806", "906", + "016", "116", "216", "316", "416", + "516", "616", "716", "816", "916", + "026", "126", "226", "326", "426", + "526", "626", "726", "826", "926", + "036", "136", "236", "336", "436", + "536", "636", "736", "836", "936", + "046", "146", "246", "346", "446", + "546", "646", "746", "846", "946", + "056", "156", "256", "356", "456", + "556", "656", "756", "856", "956", + "066", "166", "266", "366", "466", + "566", "666", "766", "866", "966", + "076", "176", "276", "376", "476", + "576", "676", "776", "876", "976", + "086", "186", "286", "386", "486", + "586", "686", "786", "886", "986", + "096", "196", "296", "396", "496", + "596", "696", "796", "896", "996", + "007", "107", "207", "307", "407", + "507", "607", "707", "807", "907", + "017", "117", "217", "317", "417", + "517", "617", "717", "817", "917", + "027", "127", "227", "327", "427", + "527", "627", "727", "827", "927", + "037", "137", "237", "337", "437", + "537", "637", "737", "837", "937", + "047", "147", "247", "347", "447", + "547", "647", "747", "847", "947", + "057", "157", "257", "357", "457", + "557", "657", "757", "857", "957", + "067", "167", "267", "367", "467", + "567", "667", "767", "867", "967", + "077", "177", "277", "377", "477", + "577", "677", "777", "877", "977", + "087", "187", "287", "387", "487", + "587", "687", "787", "887", "987", + "097", "197", "297", "397", "497", + "597", "697", "797", "897", "997", + "008", "108", "208", "308", "408", + "508", "608", "708", "808", "908", + "018", "118", "218", "318", "418", + "518", "618", "718", "818", "918", + "028", "128", "228", "328", "428", + "528", "628", "728", "828", "928", + "038", "138", "238", "338", "438", + "538", "638", "738", "838", "938", + "048", "148", "248", "348", "448", + "548", "648", "748", "848", "948", + "058", "158", "258", "358", "458", + "558", "658", "758", "858", "958", + "068", "168", "268", "368", "468", + "568", "668", "768", "868", "968", + "078", "178", "278", "378", "478", + "578", "678", "778", "878", "978", + "088", "188", "288", "388", "488", + "588", "688", "788", "888", "988", + "098", "198", "298", "398", "498", + "598", "698", "798", "898", "998", + "009", "109", "209", "309", "409", + "509", "609", "709", "809", "909", + "019", "119", "219", "319", "419", + "519", "619", "719", "819", "919", + "029", "129", "229", "329", "429", + "529", "629", "729", "829", "929", + "039", "139", "239", "339", "439", + "539", "639", "739", "839", "939", + "049", "149", "249", "349", "449", + "549", "649", "749", "849", "949", + "059", "159", "259", "359", "459", + "559", "659", "759", "859", "959", + "069", "169", "269", "369", "469", + "569", "669", "769", "869", "969", + "079", "179", "279", "379", "479", + "579", "679", "779", "879", "979", + "089", "189", "289", "389", "489", + "589", "689", "789", "889", "989", + "099", "199", "299", "399", "499", + "599", "699", "799", "899", "999" }; /* @@ -274,328 +274,290 @@ NOTE: This function handles the following flags only: int rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args) { - char ch; - int written = 0; /* bytes written so far */ - int maxbytes = bytes - 1; + char ch; + int written = 0; /* bytes written so far */ + int maxbytes = bytes - 1; - while((ch = *format++) && (written < maxbytes)) - { - if(ch == '%') - { - /* - * Advance past the % - */ - ch = *format++; + while((ch = *format++) && (written < maxbytes)) { + if(ch == '%') { + /* + * Advance past the % + */ + ch = *format++; - /* - * Put the most common cases first - %s %d etc - */ + /* + * Put the most common cases first - %s %d etc + */ - if(ch == 's') - { - const char *str = va_arg(args, const char *); + if(ch == 's') { + const char *str = va_arg(args, const char *); - while((*dest = *str)) - { - ++dest; - ++str; + while((*dest = *str)) { + ++dest; + ++str; - if(++written >= maxbytes) - break; - } + if(++written >= maxbytes) + break; + } - continue; - } + continue; + } - if(ch == 'd') - { - int num = va_arg(args, int); - int quotient; - const char *str; - char *digitptr = TempBuffer; + if(ch == 'd') { + int num = va_arg(args, int); + int quotient; + const char *str; + char *digitptr = TempBuffer; - /* - * We have to special-case "0" unfortunately - */ - if(num == 0) - { - *dest++ = '0'; - ++written; - continue; - } + /* + * We have to special-case "0" unfortunately + */ + if(num == 0) { + *dest++ = '0'; + ++written; + continue; + } - if(num < 0) - { - *dest++ = '-'; - if(++written >= maxbytes) - continue; + if(num < 0) { + *dest++ = '-'; + if(++written >= maxbytes) + continue; - num = -num; - } + num = -num; + } - do - { - quotient = num / TABLE_MAX; + do { + quotient = num / TABLE_MAX; - /* - * We'll start with the right-most digits of 'num'. - * Dividing by TABLE_MAX cuts off all but the X - * right-most digits, where X is such that: - * - * 10^X = TABLE_MAX - * - * For example, if num = 1200, and TABLE_MAX = 1000, - * quotient will be 1. Multiplying this by 1000 and - * subtracting from 1200 gives: 1200 - (1 * 1000) = 200. - * We then go right to slot 200 in our array and behold! - * The string "002" (200 backwards) is conveniently - * waiting for us. Then repeat the process with the - * digits left. - * - * The reason we need to have the integers written - * backwards, is because we don't know how many digits - * there are. If we want to express the number 12130 - * for example, our first pass would leave us with 130, - * whose slot in the array yields "031", which we - * plug into our TempBuffer[]. The next pass gives us - * 12, whose slot yields "21" which we append to - * TempBuffer[], leaving us with "03121". This is the - * exact number we want, only backwards, so it is - * a simple matter to reverse the string. If we used - * straightfoward numbers, we would have a TempBuffer - * looking like this: "13012" which would be a nightmare - * to deal with. - */ + /* + * We'll start with the right-most digits of 'num'. + * Dividing by TABLE_MAX cuts off all but the X + * right-most digits, where X is such that: + * + * 10^X = TABLE_MAX + * + * For example, if num = 1200, and TABLE_MAX = 1000, + * quotient will be 1. Multiplying this by 1000 and + * subtracting from 1200 gives: 1200 - (1 * 1000) = 200. + * We then go right to slot 200 in our array and behold! + * The string "002" (200 backwards) is conveniently + * waiting for us. Then repeat the process with the + * digits left. + * + * The reason we need to have the integers written + * backwards, is because we don't know how many digits + * there are. If we want to express the number 12130 + * for example, our first pass would leave us with 130, + * whose slot in the array yields "031", which we + * plug into our TempBuffer[]. The next pass gives us + * 12, whose slot yields "21" which we append to + * TempBuffer[], leaving us with "03121". This is the + * exact number we want, only backwards, so it is + * a simple matter to reverse the string. If we used + * straightfoward numbers, we would have a TempBuffer + * looking like this: "13012" which would be a nightmare + * to deal with. + */ - str = IntTable[num - (quotient * TABLE_MAX)]; + str = IntTable[num - (quotient * TABLE_MAX)]; - while((*digitptr = *str)) - { - ++digitptr; - ++str; - } - } - while((num = quotient) != 0); + while((*digitptr = *str)) { + ++digitptr; + ++str; + } + } while((num = quotient) != 0); - /* - * If the last quotient was a 1 or 2 digit number, there - * will be one or more leading zeroes in TempBuffer[] - - * get rid of them. - */ - while(*(digitptr - 1) == '0') - --digitptr; + /* + * If the last quotient was a 1 or 2 digit number, there + * will be one or more leading zeroes in TempBuffer[] - + * get rid of them. + */ + while(*(digitptr - 1) == '0') + --digitptr; - while(digitptr != TempBuffer) - { - *dest++ = *--digitptr; - if(++written >= maxbytes) - break; - } + while(digitptr != TempBuffer) { + *dest++ = *--digitptr; + if(++written >= maxbytes) + break; + } - continue; - } /* if (ch == 'd') */ + continue; + } /* if (ch == 'd') */ - if(ch == 'c') - { - *dest++ = va_arg(args, int); + if(ch == 'c') { + *dest++ = va_arg(args, int); - ++written; + ++written; - continue; - } /* if (ch == 'c') */ + continue; + } /* if (ch == 'c') */ - if(ch == 'u') - { - unsigned int num = va_arg(args, unsigned int); - unsigned int quotient; - const char *str; - char *digitptr = TempBuffer; + if(ch == 'u') { + unsigned int num = va_arg(args, unsigned int); + unsigned int quotient; + const char *str; + char *digitptr = TempBuffer; - if(num == 0) - { - *dest++ = '0'; - ++written; - continue; - } + if(num == 0) { + *dest++ = '0'; + ++written; + continue; + } - do - { - quotient = num / TABLE_MAX; + do { + quotient = num / TABLE_MAX; - /* - * Very similar to case 'd' - */ + /* + * Very similar to case 'd' + */ - str = IntTable[num - (quotient * TABLE_MAX)]; + str = IntTable[num - (quotient * TABLE_MAX)]; - while((*digitptr = *str)) - { - ++digitptr; - ++str; - } - } - while((num = quotient) != 0); + while((*digitptr = *str)) { + ++digitptr; + ++str; + } + } while((num = quotient) != 0); - while(*(digitptr - 1) == '0') - --digitptr; + while(*(digitptr - 1) == '0') + --digitptr; - while(digitptr != TempBuffer) - { - *dest++ = *--digitptr; - if(++written >= maxbytes) - break; - } + while(digitptr != TempBuffer) { + *dest++ = *--digitptr; + if(++written >= maxbytes) + break; + } - continue; - } /* if (ch == 'u') */ + continue; + } /* if (ch == 'u') */ - if(ch == 'Q') - { - const char *arg = va_arg(args, const char *); + if(ch == 'Q') { + const char *arg = va_arg(args, const char *); - if(arg == NULL) - continue; + if(arg == NULL) + continue; - const char *str = rsdb_quote(arg); + const char *str = rsdb_quote(arg); - while((*dest = *str)) - { - ++dest; - ++str; + while((*dest = *str)) { + ++dest; + ++str; - if(++written >= maxbytes) - break; - } + if(++written >= maxbytes) + break; + } - continue; - } + continue; + } - if(ch == 'l') - { - if(*format == 'u') - { - unsigned long num = va_arg(args, unsigned long); - unsigned long quotient; - const char *str; - char *digitptr = TempBuffer; + if(ch == 'l') { + if(*format == 'u') { + unsigned long num = va_arg(args, unsigned long); + unsigned long quotient; + const char *str; + char *digitptr = TempBuffer; - ++format; + ++format; - if(num == 0) - { - *dest++ = '0'; - ++written; - continue; - } + if(num == 0) { + *dest++ = '0'; + ++written; + continue; + } - do - { - quotient = num / TABLE_MAX; + do { + quotient = num / TABLE_MAX; - /* - * Very similar to case 'u' - */ + /* + * Very similar to case 'u' + */ - str = IntTable[num - (quotient * TABLE_MAX)]; + str = IntTable[num - (quotient * TABLE_MAX)]; - while((*digitptr = *str)) - { - ++digitptr; - ++str; - } - } - while((num = quotient) != 0); + while((*digitptr = *str)) { + ++digitptr; + ++str; + } + } while((num = quotient) != 0); - while(*(digitptr - 1) == '0') - --digitptr; + while(*(digitptr - 1) == '0') + --digitptr; - while(digitptr != TempBuffer) - { - *dest++ = *--digitptr; - if(++written >= maxbytes) - break; - } + while(digitptr != TempBuffer) { + *dest++ = *--digitptr; + if(++written >= maxbytes) + break; + } - continue; - } - else - /* if (*format == 'u') */ if(*format == 'd') - { - long num = va_arg(args, long); - long quotient; - const char *str; - char *digitptr = TempBuffer; + continue; + } else + /* if (*format == 'u') */ if(*format == 'd') { + long num = va_arg(args, long); + long quotient; + const char *str; + char *digitptr = TempBuffer; - ++format; + ++format; - if(num == 0) - { - *dest++ = '0'; - ++written; - continue; - } + if(num == 0) { + *dest++ = '0'; + ++written; + continue; + } - if(num < 0) - { - *dest++ = '-'; - if(++written >= maxbytes) - continue; + if(num < 0) { + *dest++ = '-'; + if(++written >= maxbytes) + continue; - num = -num; - } + num = -num; + } - do - { - quotient = num / TABLE_MAX; + do { + quotient = num / TABLE_MAX; - str = IntTable[num - (quotient * TABLE_MAX)]; + str = IntTable[num - (quotient * TABLE_MAX)]; - while((*digitptr = *str)) - { - ++digitptr; - ++str; - } - } - while((num = quotient) != 0); + while((*digitptr = *str)) { + ++digitptr; + ++str; + } + } while((num = quotient) != 0); - while(*(digitptr - 1) == '0') - --digitptr; + while(*(digitptr - 1) == '0') + --digitptr; - while(digitptr != TempBuffer) - { - *dest++ = *--digitptr; - if(++written >= maxbytes) - break; - } + while(digitptr != TempBuffer) { + *dest++ = *--digitptr; + if(++written >= maxbytes) + break; + } - continue; - } - else /* if (*format == 'd') */ - { - /* XXX error */ - exit(1); - } + continue; + } else { /* if (*format == 'd') */ + /* XXX error */ + exit(1); + } - } /* if (ch == 'l') */ + } /* if (ch == 'l') */ - if(ch != '%') - { - /* XXX error */ - exit(1); - } /* if (ch != '%') */ - } /* if (ch == '%') */ + if(ch != '%') { + /* XXX error */ + exit(1); + } /* if (ch != '%') */ + } /* if (ch == '%') */ - *dest++ = ch; - ++written; - } /* while ((ch = *format++) && (written < maxbytes)) */ + *dest++ = ch; + ++written; + } /* while ((ch = *format++) && (written < maxbytes)) */ - /* - * Terminate the destination buffer with a \0 - */ - *dest = '\0'; + /* + * Terminate the destination buffer with a \0 + */ + *dest = '\0'; - return (written); + return (written); } /* vSnprintf() */ /* @@ -614,14 +576,14 @@ Return: number of characters copied, NOT including the terminating int rs_snprintf(char *dest, const size_t bytes, const char *format, ...) { - va_list args; - int count; + va_list args; + int count; - va_start(args, format); + va_start(args, format); - count = rs_vsnprintf(dest, bytes, format, args); + count = rs_vsnprintf(dest, bytes, format, args); - va_end(args); + va_end(args); - return (count); + return (count); } /* Snprintf() */ diff --git a/bandb/rsdb_sqlite3.c b/bandb/rsdb_sqlite3.c index bec35fb..7587e2a 100644 --- a/bandb/rsdb_sqlite3.c +++ b/bandb/rsdb_sqlite3.c @@ -3,7 +3,7 @@ * * Copyright (C) 2003-2006 Lee Hardy * Copyright (C) 2003-2006 ircd-ratbox development team - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: @@ -27,7 +27,7 @@ * 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 "stdinc.h" #include "rsdb.h" @@ -41,224 +41,206 @@ rsdb_error_cb *error_cb; static void mlog(const char *errstr, ...) { - if(error_cb != NULL) - { - char buf[256]; - va_list ap; - va_start(ap, errstr); - rb_vsnprintf(buf, sizeof(buf), errstr, ap); - va_end(ap); - error_cb(buf); - } - else - exit(1); + if(error_cb != NULL) { + char buf[256]; + va_list ap; + va_start(ap, errstr); + rb_vsnprintf(buf, sizeof(buf), errstr, ap); + va_end(ap); + error_cb(buf); + } else + exit(1); } int rsdb_init(rsdb_error_cb * ecb) { - const char *bandb_dbpath_env; - char dbpath[PATH_MAX]; - char errbuf[128]; - error_cb = ecb; + const char *bandb_dbpath_env; + char dbpath[PATH_MAX]; + char errbuf[128]; + error_cb = ecb; - /* try a path from the environment first, useful for basedir overrides */ - bandb_dbpath_env = getenv("BANDB_DBPATH"); + /* try a path from the environment first, useful for basedir overrides */ + bandb_dbpath_env = getenv("BANDB_DBPATH"); - if(bandb_dbpath_env != NULL) - rb_strlcpy(dbpath, bandb_dbpath_env, sizeof(dbpath)); - else - rb_strlcpy(dbpath, DBPATH, sizeof(dbpath)); + if(bandb_dbpath_env != NULL) + rb_strlcpy(dbpath, bandb_dbpath_env, sizeof(dbpath)); + else + rb_strlcpy(dbpath, DBPATH, sizeof(dbpath)); - if(sqlite3_open(dbpath, &rb_bandb) != SQLITE_OK) - { - rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database: %s", - sqlite3_errmsg(rb_bandb)); - mlog(errbuf); - return -1; - } - if(access(dbpath, W_OK)) - { - rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database for write: %s", strerror(errno)); - mlog(errbuf); - return -1; - } - return 0; + if(sqlite3_open(dbpath, &rb_bandb) != SQLITE_OK) { + rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database: %s", + sqlite3_errmsg(rb_bandb)); + mlog(errbuf); + return -1; + } + if(access(dbpath, W_OK)) { + rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database for write: %s", strerror(errno)); + mlog(errbuf); + return -1; + } + return 0; } void rsdb_shutdown(void) { - if(rb_bandb) - sqlite3_close(rb_bandb); + if(rb_bandb) + sqlite3_close(rb_bandb); } const char * rsdb_quote(const char *src) { - static char buf[BUFSIZE * 4]; - char *p = buf; + static char buf[BUFSIZE * 4]; + char *p = buf; - /* cheap and dirty length check.. */ - if(strlen(src) >= (sizeof(buf) / 2)) - return NULL; + /* cheap and dirty length check.. */ + if(strlen(src) >= (sizeof(buf) / 2)) + return NULL; - while(*src) - { - if(*src == '\'') - *p++ = '\''; + while(*src) { + if(*src == '\'') + *p++ = '\''; - *p++ = *src++; - } + *p++ = *src++; + } - *p = '\0'; - return buf; + *p = '\0'; + return buf; } static int rsdb_callback_func(void *cbfunc, int argc, char **argv, char **colnames) { - rsdb_callback cb = (rsdb_callback)((uintptr_t)cbfunc); - (cb) (argc, (const char **)argv); - return 0; + rsdb_callback cb = (rsdb_callback)((uintptr_t)cbfunc); + (cb) (argc, (const char **)argv); + return 0; } void rsdb_exec(rsdb_callback cb, const char *format, ...) { - static char buf[BUFSIZE * 4]; - va_list args; - char *errmsg; - unsigned int i; - int j; + static char buf[BUFSIZE * 4]; + va_list args; + char *errmsg; + unsigned int i; + int j; - va_start(args, format); - i = rs_vsnprintf(buf, sizeof(buf), format, args); - va_end(args); + va_start(args, format); + i = rs_vsnprintf(buf, sizeof(buf), format, args); + va_end(args); - if(i >= sizeof(buf)) - { - mlog("fatal error: length problem with compiling sql"); - } + if(i >= sizeof(buf)) { + mlog("fatal error: length problem with compiling sql"); + } - if((i = sqlite3_exec(rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg))) - { - switch (i) - { - case SQLITE_BUSY: - for(j = 0; j < 5; j++) - { - rb_sleep(0, 500000); - if(!sqlite3_exec - (rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg)) - return; - } + if((i = sqlite3_exec(rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg))) { + switch (i) { + case SQLITE_BUSY: + for(j = 0; j < 5; j++) { + rb_sleep(0, 500000); + if(!sqlite3_exec + (rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg)) + return; + } - /* failed, fall through to default */ - mlog("fatal error: problem with db file: %s", errmsg); - break; + /* failed, fall through to default */ + mlog("fatal error: problem with db file: %s", errmsg); + break; - default: - mlog("fatal error: problem with db file: %s", errmsg); - break; - } - } + default: + mlog("fatal error: problem with db file: %s", errmsg); + break; + } + } } void rsdb_exec_fetch(struct rsdb_table *table, const char *format, ...) { - static char buf[BUFSIZE * 4]; - va_list args; - char *errmsg; - char **data; - int pos; - unsigned int retval; - int i, j; + static char buf[BUFSIZE * 4]; + va_list args; + char *errmsg; + char **data; + int pos; + unsigned int retval; + int i, j; - va_start(args, format); - retval = rs_vsnprintf(buf, sizeof(buf), format, args); - va_end(args); + va_start(args, format); + retval = rs_vsnprintf(buf, sizeof(buf), format, args); + va_end(args); - if(retval >= sizeof(buf)) - { - mlog("fatal error: length problem with compiling sql"); - } + if(retval >= sizeof(buf)) { + mlog("fatal error: length problem with compiling sql"); + } - if((retval = - sqlite3_get_table(rb_bandb, buf, &data, &table->row_count, &table->col_count, &errmsg))) - { - int success = 0; + if((retval = + sqlite3_get_table(rb_bandb, buf, &data, &table->row_count, &table->col_count, &errmsg))) { + int success = 0; - switch (retval) - { - case SQLITE_BUSY: - for(i = 0; i < 5; i++) - { - rb_sleep(0, 500000); - if(!sqlite3_get_table - (rb_bandb, buf, &data, &table->row_count, &table->col_count, - &errmsg)) - { - success++; - break; - } - } + switch (retval) { + case SQLITE_BUSY: + for(i = 0; i < 5; i++) { + rb_sleep(0, 500000); + if(!sqlite3_get_table + (rb_bandb, buf, &data, &table->row_count, &table->col_count, + &errmsg)) { + success++; + break; + } + } - if(success) - break; + if(success) + break; - mlog("fatal error: problem with db file: %s", errmsg); - break; + mlog("fatal error: problem with db file: %s", errmsg); + break; - default: - mlog("fatal error: problem with db file: %s", errmsg); - break; - } - } + default: + mlog("fatal error: problem with db file: %s", errmsg); + break; + } + } - /* we need to be able to free data afterward */ - table->arg = data; + /* we need to be able to free data afterward */ + table->arg = data; - if(table->row_count == 0) - { - table->row = NULL; - return; - } + if(table->row_count == 0) { + table->row = NULL; + return; + } - /* sqlite puts the column names as the first row */ - pos = table->col_count; - table->row = rb_malloc(sizeof(char **) * table->row_count); - for(i = 0; i < table->row_count; i++) - { - table->row[i] = rb_malloc(sizeof(char *) * table->col_count); + /* sqlite puts the column names as the first row */ + pos = table->col_count; + table->row = rb_malloc(sizeof(char **) * table->row_count); + for(i = 0; i < table->row_count; i++) { + table->row[i] = rb_malloc(sizeof(char *) * table->col_count); - for(j = 0; j < table->col_count; j++) - { - table->row[i][j] = data[pos++]; - } - } + for(j = 0; j < table->col_count; j++) { + table->row[i][j] = data[pos++]; + } + } } void rsdb_exec_fetch_end(struct rsdb_table *table) { - int i; + int i; - for(i = 0; i < table->row_count; i++) - { - rb_free(table->row[i]); - } - rb_free(table->row); + for(i = 0; i < table->row_count; i++) { + rb_free(table->row[i]); + } + rb_free(table->row); - sqlite3_free_table((char **)table->arg); + sqlite3_free_table((char **)table->arg); } void rsdb_transaction(rsdb_transtype type) { - if(type == RSDB_TRANS_START) - rsdb_exec(NULL, "BEGIN TRANSACTION"); - else if(type == RSDB_TRANS_END) - rsdb_exec(NULL, "COMMIT TRANSACTION"); + if(type == RSDB_TRANS_START) + rsdb_exec(NULL, "BEGIN TRANSACTION"); + else if(type == RSDB_TRANS_END) + rsdb_exec(NULL, "COMMIT TRANSACTION"); } diff --git a/extensions/chm_adminonly.c b/extensions/chm_adminonly.c index c478e91..9fd6e01 100644 --- a/extensions/chm_adminonly.c +++ b/extensions/chm_adminonly.c @@ -13,8 +13,8 @@ static void h_can_join(hook_data_channel *); mapi_hfn_list_av1 adminonly_hfnlist[] = { - { "can_join", (hookfn) h_can_join }, - { NULL, NULL } + { "can_join", (hookfn) h_can_join }, + { NULL, NULL } }; static unsigned int mymode; @@ -22,17 +22,17 @@ static unsigned int mymode; static int _modinit(void) { - mymode = cflag_add('A', chm_staff); - if (mymode == 0) - return -1; + mymode = cflag_add('A', chm_staff); + if (mymode == 0) + return -1; - return 0; + return 0; } static void _moddeinit(void) { - cflag_orphan('A'); + cflag_orphan('A'); } DECLARE_MODULE_AV1(chm_adminonly, _modinit, _moddeinit, NULL, NULL, adminonly_hfnlist, "$Revision$"); @@ -40,12 +40,12 @@ DECLARE_MODULE_AV1(chm_adminonly, _modinit, _moddeinit, NULL, NULL, adminonly_hf static void h_can_join(hook_data_channel *data) { - struct Client *source_p = data->client; - struct Channel *chptr = data->chptr; + struct Client *source_p = data->client; + struct Channel *chptr = data->chptr; - if((chptr->mode.mode & mymode) && !IsAdmin(source_p)) { - sendto_one_numeric(source_p, 519, "%s :Cannot join channel (+A) - you are not an IRC server administrator", chptr->chname); - data->approved = ERR_CUSTOM; - } + if((chptr->mode.mode & mymode) && !IsAdmin(source_p)) { + sendto_one_numeric(source_p, 519, "%s :Cannot join channel (+A) - you are not an IRC server administrator", chptr->chname); + data->approved = ERR_CUSTOM; + } } diff --git a/extensions/chm_operonly.c b/extensions/chm_operonly.c index 5cb87ab..fe3afe4 100644 --- a/extensions/chm_operonly.c +++ b/extensions/chm_operonly.c @@ -13,8 +13,8 @@ static void h_can_join(hook_data_channel *); mapi_hfn_list_av1 operonly_hfnlist[] = { - { "can_join", (hookfn) h_can_join }, - { NULL, NULL } + { "can_join", (hookfn) h_can_join }, + { NULL, NULL } }; static unsigned int mymode; @@ -26,18 +26,18 @@ static unsigned int mymode; static int _modinit(void) { - mymode = cflag_add('O', chm_staff); - if (mymode == 0) - return -1; + mymode = cflag_add('O', chm_staff); + if (mymode == 0) + return -1; - return 0; + return 0; } static void _moddeinit(void) { - cflag_orphan('O'); + cflag_orphan('O'); } DECLARE_MODULE_AV1(chm_operonly, _modinit, _moddeinit, NULL, NULL, operonly_hfnlist, "$Revision$"); @@ -45,12 +45,12 @@ DECLARE_MODULE_AV1(chm_operonly, _modinit, _moddeinit, NULL, NULL, operonly_hfnl static void h_can_join(hook_data_channel *data) { - struct Client *source_p = data->client; - struct Channel *chptr = data->chptr; + struct Client *source_p = data->client; + struct Channel *chptr = data->chptr; - if((chptr->mode.mode & mymode) && !IsOper(source_p)) { - sendto_one_numeric(source_p, 520, "%s :Cannot join channel (+O) - you are not an IRC operator", chptr->chname); - data->approved = ERR_CUSTOM; - } + if((chptr->mode.mode & mymode) && !IsOper(source_p)) { + sendto_one_numeric(source_p, 520, "%s :Cannot join channel (+O) - you are not an IRC operator", chptr->chname); + data->approved = ERR_CUSTOM; + } } diff --git a/extensions/chm_operonly_compat.c b/extensions/chm_operonly_compat.c index 73fe269..5d20fe1 100644 --- a/extensions/chm_operonly_compat.c +++ b/extensions/chm_operonly_compat.c @@ -12,41 +12,41 @@ static int _modinit(void); static void _moddeinit(void); static void chm_operonly(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); DECLARE_MODULE_AV1(chm_operonly_compat, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision$"); static int _modinit(void) { - chmode_table['O'].set_func = chm_operonly; - chmode_table['O'].mode_type = 0; + chmode_table['O'].set_func = chm_operonly; + chmode_table['O'].mode_type = 0; - return 0; + return 0; } static void _moddeinit(void) { - chmode_table['O'].set_func = chm_nosuch; - chmode_table['O'].mode_type = 0; + chmode_table['O'].set_func = chm_nosuch; + chmode_table['O'].mode_type = 0; } static void chm_operonly(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - int newparn = 0; - const char *newparv[] = { "$o" }; + int newparn = 0; + const char *newparv[] = { "$o" }; - if (MyClient(source_p)) { - chm_simple(source_p, chptr, alevel, parc, parn, parv, - errors, dir, 'i', MODE_INVITEONLY); - chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, - errors, dir, 'I', CHFL_INVEX); - } else - chm_nosuch(source_p, chptr, alevel, parc, parn, parv, - errors, dir, c, mode_type); + if (MyClient(source_p)) { + chm_simple(source_p, chptr, alevel, parc, parn, parv, + errors, dir, 'i', MODE_INVITEONLY); + chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, + errors, dir, 'I', CHFL_INVEX); + } else + chm_nosuch(source_p, chptr, alevel, parc, parn, parv, + errors, dir, c, mode_type); } diff --git a/extensions/chm_quietunreg_compat.c b/extensions/chm_quietunreg_compat.c index a0d822d..6a859e8 100644 --- a/extensions/chm_quietunreg_compat.c +++ b/extensions/chm_quietunreg_compat.c @@ -13,39 +13,39 @@ static int _modinit(void); static void _moddeinit(void); static void chm_quietunreg(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); DECLARE_MODULE_AV1(chm_quietunreg_compat, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision$"); static int _modinit(void) { - chmode_table['R'].set_func = chm_quietunreg; - chmode_table['R'].mode_type = 0; + chmode_table['R'].set_func = chm_quietunreg; + chmode_table['R'].mode_type = 0; - return 0; + return 0; } static void _moddeinit(void) { - chmode_table['R'].set_func = chm_nosuch; - chmode_table['R'].mode_type = 0; + chmode_table['R'].set_func = chm_nosuch; + chmode_table['R'].mode_type = 0; } static void chm_quietunreg(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - int newparn = 0; - const char *newparv[] = { "$~a" }; + int newparn = 0; + const char *newparv[] = { "$~a" }; - if (MyClient(source_p)) - chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, - errors, dir, 'q', CHFL_QUIET); - else - chm_nosuch(source_p, chptr, alevel, parc, parn, parv, - errors, dir, c, mode_type); + if (MyClient(source_p)) + chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, + errors, dir, 'q', CHFL_QUIET); + else + chm_nosuch(source_p, chptr, alevel, parc, parn, parv, + errors, dir, c, mode_type); } diff --git a/extensions/chm_sslonly.c b/extensions/chm_sslonly.c index 7ae8e8b..ab494c7 100644 --- a/extensions/chm_sslonly.c +++ b/extensions/chm_sslonly.c @@ -13,8 +13,8 @@ static void h_can_join(hook_data_channel *); mapi_hfn_list_av1 sslonly_hfnlist[] = { - { "can_join", (hookfn) h_can_join }, - { NULL, NULL } + { "can_join", (hookfn) h_can_join }, + { NULL, NULL } }; static unsigned int mymode; @@ -22,18 +22,18 @@ static unsigned int mymode; static int _modinit(void) { - mymode = cflag_add('S', chm_simple); - if (mymode == 0) - return -1; + mymode = cflag_add('S', chm_simple); + if (mymode == 0) + return -1; - return 0; + return 0; } static void _moddeinit(void) { - cflag_orphan('S'); + cflag_orphan('S'); } DECLARE_MODULE_AV1(chm_sslonly, _modinit, _moddeinit, NULL, NULL, sslonly_hfnlist, "$Revision$"); @@ -41,12 +41,12 @@ DECLARE_MODULE_AV1(chm_sslonly, _modinit, _moddeinit, NULL, NULL, sslonly_hfnlis static void h_can_join(hook_data_channel *data) { - struct Client *source_p = data->client; - struct Channel *chptr = data->chptr; + struct Client *source_p = data->client; + struct Channel *chptr = data->chptr; - if((chptr->mode.mode & mymode) && !IsSSLClient(source_p)) { - sendto_one_notice(source_p, ":Only users using SSL can join this channel!"); - data->approved = ERR_CUSTOM; - } + if((chptr->mode.mode & mymode) && !IsSSLClient(source_p)) { + sendto_one_notice(source_p, ":Only users using SSL can join this channel!"); + data->approved = ERR_CUSTOM; + } } diff --git a/extensions/chm_sslonly_compat.c b/extensions/chm_sslonly_compat.c index 63b875e..87ecc47 100644 --- a/extensions/chm_sslonly_compat.c +++ b/extensions/chm_sslonly_compat.c @@ -12,39 +12,39 @@ static int _modinit(void); static void _moddeinit(void); static void chm_sslonly(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); DECLARE_MODULE_AV1(chm_sslonly_compat, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision$"); static int _modinit(void) { - chmode_table['S'].set_func = chm_sslonly; - chmode_table['S'].mode_type = 0; + chmode_table['S'].set_func = chm_sslonly; + chmode_table['S'].mode_type = 0; - return 0; + return 0; } static void _moddeinit(void) { - chmode_table['S'].set_func = chm_nosuch; - chmode_table['S'].mode_type = 0; + chmode_table['S'].set_func = chm_nosuch; + chmode_table['S'].mode_type = 0; } static void chm_sslonly(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - int newparn = 0; - const char *newparv[] = { "$~z" }; + int newparn = 0; + const char *newparv[] = { "$~z" }; - if (MyClient(source_p)) - chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, - errors, dir, 'b', CHFL_BAN); - else - chm_nosuch(source_p, chptr, alevel, parc, parn, parv, - errors, dir, c, mode_type); + if (MyClient(source_p)) + chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, + errors, dir, 'b', CHFL_BAN); + else + chm_nosuch(source_p, chptr, alevel, parc, parn, parv, + errors, dir, c, mode_type); } diff --git a/extensions/createauthonly.c b/extensions/createauthonly.c index 87440b9..ecc7163 100644 --- a/extensions/createauthonly.c +++ b/extensions/createauthonly.c @@ -20,8 +20,8 @@ static void h_can_create_channel_authenticated(hook_data_client_approval *); mapi_hfn_list_av1 restrict_hfnlist[] = { - { "can_create_channel", (hookfn) h_can_create_channel_authenticated }, - { NULL, NULL } + { "can_create_channel", (hookfn) h_can_create_channel_authenticated }, + { NULL, NULL } }; DECLARE_MODULE_AV1(createauthonly, NULL, NULL, NULL, NULL, restrict_hfnlist, "$Revision: 833 $"); @@ -29,8 +29,8 @@ DECLARE_MODULE_AV1(createauthonly, NULL, NULL, NULL, NULL, restrict_hfnlist, "$R static void h_can_create_channel_authenticated(hook_data_client_approval *data) { - struct Client *source_p = data->client; + struct Client *source_p = data->client; - if (*source_p->user->suser == '\0' && !IsOper(source_p)) - data->approved = ERR_NEEDREGGEDNICK; + if (*source_p->user->suser == '\0' && !IsOper(source_p)) + data->approved = ERR_NEEDREGGEDNICK; } diff --git a/extensions/createoperonly.c b/extensions/createoperonly.c index 0045c89..526fc86 100644 --- a/extensions/createoperonly.c +++ b/extensions/createoperonly.c @@ -20,8 +20,8 @@ static void h_can_create_channel_authenticated(hook_data_client_approval *); mapi_hfn_list_av1 restrict_hfnlist[] = { - { "can_create_channel", (hookfn) h_can_create_channel_authenticated }, - { NULL, NULL } + { "can_create_channel", (hookfn) h_can_create_channel_authenticated }, + { NULL, NULL } }; DECLARE_MODULE_AV1(createoperonly, NULL, NULL, NULL, NULL, restrict_hfnlist, "$Revision: 3476 $"); @@ -29,11 +29,10 @@ DECLARE_MODULE_AV1(createoperonly, NULL, NULL, NULL, NULL, restrict_hfnlist, "$R static void h_can_create_channel_authenticated(hook_data_client_approval *data) { - struct Client *source_p = data->client; + struct Client *source_p = data->client; - if (!IsOper(source_p)) - { - sendto_one_notice(source_p, ":*** Channel creation is restricted to network staff only."); - data->approved = ERR_NEEDREGGEDNICK; - } + if (!IsOper(source_p)) { + sendto_one_notice(source_p, ":*** Channel creation is restricted to network staff only."); + data->approved = ERR_NEEDREGGEDNICK; + } } diff --git a/extensions/example_module.c b/extensions/example_module.c index 5fcfa17..602a751 100644 --- a/extensions/example_module.c +++ b/extensions/example_module.c @@ -47,25 +47,25 @@ static int moper_test(struct Client *client_p, struct Client *source_p, int parc */ struct Message test_msgtab = { - "TEST", /* the /COMMAND you want */ - 0, /* SET TO ZERO -- number of times command used by clients */ - 0, /* SET TO ZERO -- number of times command used by clients */ - 0, /* SET TO ZERO -- number of times command used by clients */ - MFLG_SLOW, /* ALWAYS SET TO MFLG_SLOW */ + "TEST", /* the /COMMAND you want */ + 0, /* SET TO ZERO -- number of times command used by clients */ + 0, /* SET TO ZERO -- number of times command used by clients */ + 0, /* SET TO ZERO -- number of times command used by clients */ + MFLG_SLOW, /* ALWAYS SET TO MFLG_SLOW */ - /* the functions to call for each handler. If not using the generic - * handlers, the first param is the function to call, the second is the - * required number of parameters. NOTE: If you specify a min para of 2, - * then parv[1] must *also* be non-empty. - */ - { - {munreg_test, 0}, /* function call for unregistered clients, 0 parms required */ - {mclient_test, 0}, /* function call for local clients, 0 parms required */ - {mrclient_test, 0}, /* function call for remote clients, 0 parms required */ - {mserver_test, 0}, /* function call for servers, 0 parms required */ - mg_ignore, /* function call for ENCAP, unused in this test */ - {moper_test, 0} /* function call for operators, 0 parms required */ - } + /* the functions to call for each handler. If not using the generic + * handlers, the first param is the function to call, the second is the + * required number of parameters. NOTE: If you specify a min para of 2, + * then parv[1] must *also* be non-empty. + */ + { + {munreg_test, 0}, /* function call for unregistered clients, 0 parms required */ + {mclient_test, 0}, /* function call for local clients, 0 parms required */ + {mrclient_test, 0}, /* function call for remote clients, 0 parms required */ + {mserver_test, 0}, /* function call for servers, 0 parms required */ + mg_ignore, /* function call for ENCAP, unused in this test */ + {moper_test, 0} /* function call for operators, 0 parms required */ + } }; /* * There are also some macros for the above function calls and parameter counts. @@ -93,9 +93,9 @@ mapi_clist_av1 test_clist[] = { &test_msgtab, NULL }; * terminated with NULLs. */ int doing_example_hook; -mapi_hlist_av1 test_hlist[] = { - { "doing_example_hook", &doing_example_hook, }, - { NULL, NULL } +mapi_hlist_av1 test_hlist[] = { + { "doing_example_hook", &doing_example_hook, }, + { NULL, NULL } }; /* The mapi_hfn_list_av1 declares the hook functions which other modules can @@ -106,44 +106,44 @@ mapi_hlist_av1 test_hlist[] = { static void show_example_hook(void *unused); mapi_hfn_list_av1 test_hfnlist[] = { - { "doing_example_hook", (hookfn) show_example_hook }, - { NULL, NULL } + { "doing_example_hook", (hookfn) show_example_hook }, + { NULL, NULL } }; /* Here we tell it what to do when the module is loaded */ static int modinit(void) { - /* Nothing to do for the example module. */ - /* The init function should return -1 on failure, - which will cause the module to be unloaded, - otherwise 0 to indicate success. */ - return 0; + /* Nothing to do for the example module. */ + /* The init function should return -1 on failure, + which will cause the module to be unloaded, + otherwise 0 to indicate success. */ + return 0; } /* here we tell it what to do when the module is unloaded */ static void moddeinit(void) { - /* Again, nothing to do. */ + /* Again, nothing to do. */ } /* DECLARE_MODULE_AV1() actually declare the MAPI header. */ DECLARE_MODULE_AV1( - /* The first argument is the name */ - example, - /* The second argument is the function to call on load */ - modinit, - /* And the function to call on unload */ - moddeinit, - /* Then the MAPI command list */ - test_clist, - /* Next the hook list, if we have one. */ - test_hlist, - /* Then the hook function list, if we have one */ - test_hfnlist, - /* And finally the version number of this module. */ - "$Revision: 3161 $"); + /* The first argument is the name */ + example, + /* The second argument is the function to call on load */ + modinit, + /* And the function to call on unload */ + moddeinit, + /* Then the MAPI command list */ + test_clist, + /* Next the hook list, if we have one. */ + test_hlist, + /* Then the hook function list, if we have one */ + test_hfnlist, + /* And finally the version number of this module. */ + "$Revision: 3161 $"); /* Any of the above arguments can be NULL to indicate they aren't used. */ @@ -159,19 +159,16 @@ DECLARE_MODULE_AV1( static int munreg_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc < 2) - { - sendto_one_notice(source_p, ":You are unregistered and sent no parameters"); - } - else - { - sendto_one_notice(source_p, ":You are unregistered and sent parameter: %s", parv[1]); - } + if(parc < 2) { + sendto_one_notice(source_p, ":You are unregistered and sent no parameters"); + } else { + sendto_one_notice(source_p, ":You are unregistered and sent parameter: %s", parv[1]); + } - /* illustration of how to call a hook function */ - call_hook(doing_example_hook, NULL); + /* illustration of how to call a hook function */ + call_hook(doing_example_hook, NULL); - return 0; + return 0; } /* @@ -181,19 +178,16 @@ munreg_test(struct Client *client_p, struct Client *source_p, int parc, const ch static int mclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc < 2) - { - sendto_one_notice(source_p, ":You are a normal user, and sent no parameters"); - } - else - { - sendto_one_notice(source_p, ":You are a normal user, and send parameters: %s", parv[1]); - } + if(parc < 2) { + sendto_one_notice(source_p, ":You are a normal user, and sent no parameters"); + } else { + sendto_one_notice(source_p, ":You are a normal user, and send parameters: %s", parv[1]); + } - /* illustration of how to call a hook function */ - call_hook(doing_example_hook, NULL); + /* illustration of how to call a hook function */ + call_hook(doing_example_hook, NULL); - return 0; + return 0; } /* @@ -203,15 +197,12 @@ mclient_test(struct Client *client_p, struct Client *source_p, int parc, const c static int mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc < 2) - { - sendto_one_notice(source_p, ":You are a remote client, and sent no parameters"); - } - else - { - sendto_one_notice(source_p, ":You are a remote client, and sent parameters: %s", parv[1]); - } - return 0; + if(parc < 2) { + sendto_one_notice(source_p, ":You are a remote client, and sent no parameters"); + } else { + sendto_one_notice(source_p, ":You are a remote client, and sent parameters: %s", parv[1]); + } + return 0; } /* @@ -221,15 +212,12 @@ mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const static int mserver_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc < 2) - { - sendto_one_notice(source_p, ":You are a server, and sent no parameters"); - } - else - { - sendto_one_notice(source_p, ":You are a server, and sent parameters: %s", parv[1]); - } - return 0; + if(parc < 2) { + sendto_one_notice(source_p, ":You are a server, and sent no parameters"); + } else { + sendto_one_notice(source_p, ":You are a server, and sent parameters: %s", parv[1]); + } + return 0; } /* @@ -239,21 +227,18 @@ mserver_test(struct Client *client_p, struct Client *source_p, int parc, const c static int moper_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc < 2) - { - sendto_one_notice(source_p, ":You are an operator, and sent no parameters"); - } - else - { - sendto_one_notice(source_p, ":You are an operator, and sent parameters: %s", parv[1]); - } - return 0; + if(parc < 2) { + sendto_one_notice(source_p, ":You are an operator, and sent no parameters"); + } else { + sendto_one_notice(source_p, ":You are an operator, and sent parameters: %s", parv[1]); + } + return 0; } static void show_example_hook(void *unused) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Called example hook!"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Called example hook!"); } /* END OF EXAMPLE MODULE */ diff --git a/extensions/extb_account.c b/extensions/extb_account.c index 2e622fd..62f1ed6 100644 --- a/extensions/extb_account.c +++ b/extensions/extb_account.c @@ -18,25 +18,25 @@ DECLARE_MODULE_AV1(extb_account, _modinit, _moddeinit, NULL, NULL, NULL, "$Revis static int _modinit(void) { - extban_table['a'] = eb_account; + extban_table['a'] = eb_account; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['a'] = NULL; + extban_table['a'] = NULL; } static int eb_account(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - (void)chptr; - /* $a alone matches any logged in user */ - if (data == NULL) - return EmptyString(client_p->user->suser) ? EXTBAN_NOMATCH : EXTBAN_MATCH; - /* $a:MASK matches users logged in under matching account */ - return match(data, client_p->user->suser) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + (void)chptr; + /* $a alone matches any logged in user */ + if (data == NULL) + return EmptyString(client_p->user->suser) ? EXTBAN_NOMATCH : EXTBAN_MATCH; + /* $a:MASK matches users logged in under matching account */ + return match(data, client_p->user->suser) ? EXTBAN_MATCH : EXTBAN_NOMATCH; } diff --git a/extensions/extb_canjoin.c b/extensions/extb_canjoin.c index 9f55a76..5ee9b48 100644 --- a/extensions/extb_canjoin.c +++ b/extensions/extb_canjoin.c @@ -21,46 +21,46 @@ DECLARE_MODULE_AV1(extb_canjoin, _modinit, _moddeinit, NULL, NULL, NULL, "$Revis static int _modinit(void) { - extban_table['j'] = eb_canjoin; + extban_table['j'] = eb_canjoin; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['j'] = NULL; + extban_table['j'] = NULL; } static int eb_canjoin(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - struct Channel *chptr2; - int ret; - static int recurse = 0; + struct Channel *chptr2; + int ret; + static int recurse = 0; - (void)mode_type; - /* don't process a $j in a $j'ed list */ - if (recurse) - return EXTBAN_INVALID; - if (data == NULL) - return EXTBAN_INVALID; - chptr2 = find_channel(data); - /* must exist, and no point doing this with the same channel */ - if (chptr2 == NULL || chptr2 == chptr) - return EXTBAN_INVALID; - /* require consistent target */ - if (chptr->chname[0] == '#' && data[0] == '&') - return EXTBAN_INVALID; - /* this allows getting some information about ban exceptions - * but +s/+p doesn't seem the right criterion */ + (void)mode_type; + /* don't process a $j in a $j'ed list */ + if (recurse) + return EXTBAN_INVALID; + if (data == NULL) + return EXTBAN_INVALID; + chptr2 = find_channel(data); + /* must exist, and no point doing this with the same channel */ + if (chptr2 == NULL || chptr2 == chptr) + return EXTBAN_INVALID; + /* require consistent target */ + if (chptr->chname[0] == '#' && data[0] == '&') + return EXTBAN_INVALID; + /* this allows getting some information about ban exceptions + * but +s/+p doesn't seem the right criterion */ #if 0 - /* privacy! don't allow +s/+p channels to influence another channel */ - if (!PubChannel(chptr2)) - return EXTBAN_INVALID; + /* privacy! don't allow +s/+p channels to influence another channel */ + if (!PubChannel(chptr2)) + return EXTBAN_INVALID; #endif - recurse = 1; - ret = is_banned(chptr2, client_p, NULL, NULL, NULL) == CHFL_BAN ? EXTBAN_MATCH : EXTBAN_NOMATCH; - recurse = 0; - return ret; + recurse = 1; + ret = is_banned(chptr2, client_p, NULL, NULL, NULL) == CHFL_BAN ? EXTBAN_MATCH : EXTBAN_NOMATCH; + recurse = 0; + return ret; } diff --git a/extensions/extb_channel.c b/extensions/extb_channel.c index 2e657b1..b1cd4a2 100644 --- a/extensions/extb_channel.c +++ b/extensions/extb_channel.c @@ -20,34 +20,34 @@ DECLARE_MODULE_AV1(extb_channel, _modinit, _moddeinit, NULL, NULL, NULL, "$Revis static int _modinit(void) { - extban_table['c'] = eb_channel; + extban_table['c'] = eb_channel; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['c'] = NULL; + extban_table['c'] = NULL; } static int eb_channel(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - struct Channel *chptr2; + struct Channel *chptr2; - (void)chptr; - (void)mode_type; - if (data == NULL) - return EXTBAN_INVALID; - chptr2 = find_channel(data); - if (chptr2 == NULL) - return EXTBAN_INVALID; - /* require consistent target */ - if (chptr->chname[0] == '#' && data[0] == '&') - return EXTBAN_INVALID; - /* privacy! don't allow +s/+p channels to influence another channel */ - if (!PubChannel(chptr2)) - return EXTBAN_INVALID; - return IsMember(client_p, chptr2) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + (void)chptr; + (void)mode_type; + if (data == NULL) + return EXTBAN_INVALID; + chptr2 = find_channel(data); + if (chptr2 == NULL) + return EXTBAN_INVALID; + /* require consistent target */ + if (chptr->chname[0] == '#' && data[0] == '&') + return EXTBAN_INVALID; + /* privacy! don't allow +s/+p channels to influence another channel */ + if (!PubChannel(chptr2)) + return EXTBAN_INVALID; + return IsMember(client_p, chptr2) ? EXTBAN_MATCH : EXTBAN_NOMATCH; } diff --git a/extensions/extb_extgecos.c b/extensions/extb_extgecos.c index 45cd320..b563be2 100644 --- a/extensions/extb_extgecos.c +++ b/extensions/extb_extgecos.c @@ -19,40 +19,39 @@ DECLARE_MODULE_AV1(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, "$Revi static int _modinit(void) { - extban_table['x'] = eb_extended; + extban_table['x'] = eb_extended; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['x'] = NULL; + extban_table['x'] = NULL; } static int eb_extended(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - char buf[BUFSIZE]; - int ret; + char buf[BUFSIZE]; + int ret; - (void)chptr; + (void)chptr; - if (data == NULL) - return EXTBAN_INVALID; + if (data == NULL) + return EXTBAN_INVALID; - rb_snprintf(buf, BUFSIZE, "%s!%s@%s#%s", - client_p->name, client_p->username, client_p->host, client_p->info); + rb_snprintf(buf, BUFSIZE, "%s!%s@%s#%s", + client_p->name, client_p->username, client_p->host, client_p->info); - ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; - if (ret == EXTBAN_NOMATCH && IsDynSpoof(client_p)) - { - rb_snprintf(buf, BUFSIZE, "%s!%s@%s#%s", - client_p->name, client_p->username, client_p->orighost, client_p->info); + if (ret == EXTBAN_NOMATCH && IsDynSpoof(client_p)) { + rb_snprintf(buf, BUFSIZE, "%s!%s@%s#%s", + client_p->name, client_p->username, client_p->orighost, client_p->info); - ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; - } + ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + } - return ret; + return ret; } diff --git a/extensions/extb_oper.c b/extensions/extb_oper.c index 5c1f62f..220e811 100644 --- a/extensions/extb_oper.c +++ b/extensions/extb_oper.c @@ -18,26 +18,26 @@ DECLARE_MODULE_AV1(extb_oper, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision static int _modinit(void) { - extban_table['o'] = eb_oper; + extban_table['o'] = eb_oper; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['o'] = NULL; + extban_table['o'] = NULL; } static int eb_oper(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - (void)chptr; - (void)mode_type; - /* perhaps use data somehow? (opernick/flags?) */ - /* so deny any bans with data for now */ - if (data != NULL) - return EXTBAN_INVALID; - return IsOper(client_p) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + (void)chptr; + (void)mode_type; + /* perhaps use data somehow? (opernick/flags?) */ + /* so deny any bans with data for now */ + if (data != NULL) + return EXTBAN_INVALID; + return IsOper(client_p) ? EXTBAN_MATCH : EXTBAN_NOMATCH; } diff --git a/extensions/extb_realname.c b/extensions/extb_realname.c index f01301e..274e73f 100644 --- a/extensions/extb_realname.c +++ b/extensions/extb_realname.c @@ -18,26 +18,26 @@ DECLARE_MODULE_AV1(extb_realname, _modinit, _moddeinit, NULL, NULL, NULL, "$Revi static int _modinit(void) { - extban_table['r'] = eb_realname; + extban_table['r'] = eb_realname; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['r'] = NULL; + extban_table['r'] = NULL; } static int eb_realname(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - (void)chptr; - /* This type is not safe for exceptions */ - if (mode_type == CHFL_EXCEPTION || mode_type == CHFL_INVEX) - return EXTBAN_INVALID; - if (data == NULL) - return EXTBAN_INVALID; - return match(data, client_p->info) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + (void)chptr; + /* This type is not safe for exceptions */ + if (mode_type == CHFL_EXCEPTION || mode_type == CHFL_INVEX) + return EXTBAN_INVALID; + if (data == NULL) + return EXTBAN_INVALID; + return match(data, client_p->info) ? EXTBAN_MATCH : EXTBAN_NOMATCH; } diff --git a/extensions/extb_server.c b/extensions/extb_server.c index cbea7dc..8c8a54d 100644 --- a/extensions/extb_server.c +++ b/extensions/extb_server.c @@ -18,26 +18,26 @@ DECLARE_MODULE_AV1(extb_server, _modinit, _moddeinit, NULL, NULL, NULL, "$Revisi static int _modinit(void) { - extban_table['s'] = eb_server; + extban_table['s'] = eb_server; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['s'] = NULL; + extban_table['s'] = NULL; } static int eb_server(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - (void)chptr; - /* This type is not safe for exceptions */ - if (mode_type == CHFL_EXCEPTION || mode_type == CHFL_INVEX) - return EXTBAN_INVALID; - if (data == NULL) - return EXTBAN_INVALID; - return match(data, me.name) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + (void)chptr; + /* This type is not safe for exceptions */ + if (mode_type == CHFL_EXCEPTION || mode_type == CHFL_INVEX) + return EXTBAN_INVALID; + if (data == NULL) + return EXTBAN_INVALID; + return match(data, me.name) ? EXTBAN_MATCH : EXTBAN_NOMATCH; } diff --git a/extensions/extb_ssl.c b/extensions/extb_ssl.c index 73e835b..d519d72 100644 --- a/extensions/extb_ssl.c +++ b/extensions/extb_ssl.c @@ -14,24 +14,24 @@ DECLARE_MODULE_AV1(extb_ssl, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision$ static int _modinit(void) { - extban_table['z'] = eb_ssl; + extban_table['z'] = eb_ssl; - return 0; + return 0; } static void _moddeinit(void) { - extban_table['z'] = NULL; + extban_table['z'] = NULL; } static int eb_ssl(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type) + struct Channel *chptr, long mode_type) { - (void)chptr; - (void)mode_type; - if (data != NULL) - return EXTBAN_INVALID; - return IsSSLClient(client_p) ? EXTBAN_MATCH : EXTBAN_NOMATCH; + (void)chptr; + (void)mode_type; + if (data != NULL) + return EXTBAN_INVALID; + return IsSSLClient(client_p) ? EXTBAN_MATCH : EXTBAN_NOMATCH; } diff --git a/extensions/force_user_invis.c b/extensions/force_user_invis.c index a2c8247..dda6798 100644 --- a/extensions/force_user_invis.c +++ b/extensions/force_user_invis.c @@ -18,8 +18,8 @@ static void h_noi_umode_changed(hook_data_umode_changed *); mapi_hfn_list_av1 noi_hfnlist[] = { - { "umode_changed", (hookfn) h_noi_umode_changed }, - { NULL, NULL } + { "umode_changed", (hookfn) h_noi_umode_changed }, + { NULL, NULL } }; DECLARE_MODULE_AV1(force_user_invis, NULL, NULL, NULL, NULL, noi_hfnlist, "1.0.0"); @@ -27,9 +27,9 @@ DECLARE_MODULE_AV1(force_user_invis, NULL, NULL, NULL, NULL, noi_hfnlist, "1.0.0 static void h_noi_umode_changed(hook_data_umode_changed *hdata) { - struct Client *source_p = hdata->client; + struct Client *source_p = hdata->client; - if (MyClient(source_p) && !IsOper(source_p) && !IsInvisible(source_p)) { - SetInvisible(source_p); - } + if (MyClient(source_p) && !IsOper(source_p) && !IsInvisible(source_p)) { + SetInvisible(source_p); + } } diff --git a/extensions/hurt.c b/extensions/hurt.c index 9001d11..0ec4433 100644 --- a/extensions/hurt.c +++ b/extensions/hurt.c @@ -23,25 +23,25 @@ #define HURT_EXIT_REASON "Hurt: Failed to identify to services" enum { - HEAL_NICK = 0, - HEAL_IP + HEAL_NICK = 0, + HEAL_IP }; typedef struct _hurt_state { - time_t start_time; - uint32_t n_hurts; - rb_dlink_list hurt_clients; - uint16_t cutoff; - time_t default_expire; - const char *exit_reason; + time_t start_time; + uint32_t n_hurts; + rb_dlink_list hurt_clients; + uint16_t cutoff; + time_t default_expire; + const char *exit_reason; } hurt_state_t; typedef struct _hurt { - char *ip; - struct sockaddr *saddr; - int saddr_bits; - char *reason; - time_t expire; + char *ip; + struct sockaddr *saddr; + int saddr_bits; + char *reason; + time_t expire; } hurt_t; /* }}} */ @@ -82,45 +82,45 @@ rb_dlink_list hurt_confs = { NULL, NULL, 0 }; /* {{{ Messages */ struct Message hurt_msgtab = { - "HURT", 0, 0, 0, MFLG_SLOW, { - mg_ignore, mg_ignore, mg_ignore, - mg_ignore, {me_hurt, 0}, {mo_hurt, 3} - } + "HURT", 0, 0, 0, MFLG_SLOW, { + mg_ignore, mg_ignore, mg_ignore, + mg_ignore, {me_hurt, 0}, {mo_hurt, 3} + } }; struct Message heal_msgtab = { - "HEAL", 0, 0, 0, MFLG_SLOW, { - mg_ignore, mg_ignore, mg_ignore, - mg_ignore, {me_heal, 0}, {mo_heal, 2} - } + "HEAL", 0, 0, 0, MFLG_SLOW, { + mg_ignore, mg_ignore, mg_ignore, + mg_ignore, {me_heal, 0}, {mo_heal, 2} + } }; /* }}} */ /* {{{ Misc module stuff */ mapi_hfn_list_av1 hurt_hfnlist[] = { - {"client_exit", (hookfn) client_exit_hook}, - {"new_local_user", (hookfn) new_local_user_hook}, - {"doing_stats", (hookfn) doing_stats_hook}, - {NULL, NULL}, + {"client_exit", (hookfn) client_exit_hook}, + {"new_local_user", (hookfn) new_local_user_hook}, + {"doing_stats", (hookfn) doing_stats_hook}, + {NULL, NULL}, }; mapi_clist_av1 hurt_clist[] = { &hurt_msgtab, &heal_msgtab, NULL }; DECLARE_MODULE_AV1( - hurt, - modinit, - modfini, - hurt_clist, - NULL, - hurt_hfnlist, - "$Revision: 3161 $" + hurt, + modinit, + modfini, + hurt_clist, + NULL, + hurt_hfnlist, + "$Revision: 3161 $" ); /* }}} */ hurt_state_t hurt_state = { - .cutoff = HURT_CUTOFF, - .default_expire = HURT_DEFAULT_EXPIRE, - .exit_reason = HURT_EXIT_REASON, + .cutoff = HURT_CUTOFF, + .default_expire = HURT_DEFAULT_EXPIRE, + .exit_reason = HURT_EXIT_REASON, }; /* @@ -135,14 +135,14 @@ struct ev_entry *hurt_check_ev = NULL; static int modinit(void) { - /* set-up hurt_state. */ - hurt_state.start_time = rb_current_time(); + /* set-up hurt_state. */ + hurt_state.start_time = rb_current_time(); - /* add our event handlers. */ - hurt_expire_ev = rb_event_add("hurt_expire", hurt_expire_event, NULL, 60); - hurt_check_ev = rb_event_add("hurt_check", hurt_check_event, NULL, 5); + /* add our event handlers. */ + hurt_expire_ev = rb_event_add("hurt_expire", hurt_expire_event, NULL, 60); + hurt_check_ev = rb_event_add("hurt_check", hurt_check_event, NULL, 5); - return 0; + return 0; } /* }}} */ @@ -150,16 +150,15 @@ modinit(void) static void modfini(void) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - /* and delete our events. */ - rb_event_delete(hurt_expire_ev); - rb_event_delete(hurt_check_ev); + /* and delete our events. */ + rb_event_delete(hurt_expire_ev); + rb_event_delete(hurt_check_ev); - RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) - { - rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); - } + RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) { + rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); + } } /* }}} */ @@ -170,84 +169,79 @@ modfini(void) /* {{{ static int mo_hurt() * * HURT [] - * + * * parv[1] - expire or ip * parv[2] - ip or reason * parv[3] - reason or NULL */ static int mo_hurt(struct Client *client_p, struct Client *source_p, - int parc, const char **parv) + int parc, const char **parv) { - const char *ip, *expire, *reason; - int expire_time; - hurt_t *hurt; - struct Client *target_p; + const char *ip, *expire, *reason; + int expire_time; + hurt_t *hurt; + struct Client *target_p; - if (!IsOperK(source_p)) { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, - source_p->name, "kline"); - return 0; - } + if (!IsOperK(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, + source_p->name, "kline"); + return 0; + } - if (parc == 3) - expire = NULL, ip = parv[1], reason = parv[2]; - else - expire = parv[1], ip = parv[2], reason = parv[3]; + if (parc == 3) + expire = NULL, ip = parv[1], reason = parv[2]; + else + expire = parv[1], ip = parv[2], reason = parv[3]; - if (!expire) - expire_time = HURT_DEFAULT_EXPIRE; - if (expire && (expire_time = valid_temp_time(expire)) < 1) { - sendto_one_notice(source_p, ":Permanent HURTs are not supported"); - return 0; - } - if (EmptyString(reason)) { - sendto_one_notice(source_p, ":Empty HURT reasons are bad for business"); - return 0; - } + if (!expire) + expire_time = HURT_DEFAULT_EXPIRE; + if (expire && (expire_time = valid_temp_time(expire)) < 1) { + sendto_one_notice(source_p, ":Permanent HURTs are not supported"); + return 0; + } + if (EmptyString(reason)) { + sendto_one_notice(source_p, ":Empty HURT reasons are bad for business"); + return 0; + } - /* Is this a client? */ - if (strchr(ip, '.') == NULL && strchr(ip, ':') == NULL) - { - target_p = find_named_person(ip); - if (target_p == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), ip); - return 0; - } - ip = target_p->orighost; - } - else - { - if (!strncmp(ip, "*@", 2)) - ip += 2; - if (strchr(ip, '!') || strchr(ip, '@')) - { - sendto_one_notice(source_p, ":Invalid HURT mask [%s]", - ip); - return 0; - } - } + /* Is this a client? */ + if (strchr(ip, '.') == NULL && strchr(ip, ':') == NULL) { + target_p = find_named_person(ip); + if (target_p == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), ip); + return 0; + } + ip = target_p->orighost; + } else { + if (!strncmp(ip, "*@", 2)) + ip += 2; + if (strchr(ip, '!') || strchr(ip, '@')) { + sendto_one_notice(source_p, ":Invalid HURT mask [%s]", + ip); + return 0; + } + } - if (hurt_find(ip) != NULL) { - sendto_one(source_p, ":[%s] already HURT", ip); - return 0; - } + if (hurt_find(ip) != NULL) { + sendto_one(source_p, ":[%s] already HURT", ip); + return 0; + } - /* - * okay, we've got this far, now it's time to add the the HURT locally - * and propagate it to other servers on the network. - */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added HURT on [%s] for %ld minutes with reason [%s]", - get_oper_name(source_p), ip, (long) expire_time / 60, reason); + /* + * okay, we've got this far, now it's time to add the the HURT locally + * and propagate it to other servers on the network. + */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added HURT on [%s] for %ld minutes with reason [%s]", + get_oper_name(source_p), ip, (long) expire_time / 60, reason); - hurt = hurt_new(expire_time, ip, reason); - hurt_add(hurt); - hurt_propagate(NULL, source_p, hurt); + hurt = hurt_new(expire_time, ip, reason); + hurt_add(hurt); + hurt_propagate(NULL, source_p, hurt); - return 0; + return 0; } /* }}} */ @@ -261,32 +255,32 @@ mo_hurt(struct Client *client_p, struct Client *source_p, */ static int me_hurt(struct Client *client_p, struct Client *source_p, - int parc, const char **parv) + int parc, const char **parv) { - time_t expire_time; - hurt_t *hurt; + time_t expire_time; + hurt_t *hurt; - /* - * right... if we don't get enough arguments, or if we get any invalid - * arguments, just ignore this request - shit happens, and it's not worth - * dropping a server over. - */ - if (parc < 4 || !IsPerson(source_p)) - return 0; - if ((expire_time = atoi(parv[1])) < 1) - return 0; - if (hurt_find(parv[2]) != NULL) - return 0; - if (EmptyString(parv[3])) - return 0; + /* + * right... if we don't get enough arguments, or if we get any invalid + * arguments, just ignore this request - shit happens, and it's not worth + * dropping a server over. + */ + if (parc < 4 || !IsPerson(source_p)) + return 0; + if ((expire_time = atoi(parv[1])) < 1) + return 0; + if (hurt_find(parv[2]) != NULL) + return 0; + if (EmptyString(parv[3])) + return 0; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added HURT on [%s] for %ld minutes with reason [%s]", - get_oper_name(source_p), parv[2], (long) expire_time / 60, parv[3]); - hurt = hurt_new(expire_time, parv[2], parv[3]); - hurt_add(hurt); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added HURT on [%s] for %ld minutes with reason [%s]", + get_oper_name(source_p), parv[2], (long) expire_time / 60, parv[3]); + hurt = hurt_new(expire_time, parv[2], parv[3]); + hurt_add(hurt); - return 0; + return 0; } /* }}} */ @@ -298,88 +292,76 @@ me_hurt(struct Client *client_p, struct Client *source_p, */ static int mo_heal(struct Client *client_p, struct Client *source_p, - int parc, const char **parv) + int parc, const char **parv) { - struct Client *target_p; + struct Client *target_p; - if (!IsOperUnkline(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "unkline"); - return 0; - } + if (!IsOperUnkline(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "unkline"); + return 0; + } - if (nick_is_valid(parv[1])) - { - target_p = find_named_person(parv[1]); - if (target_p == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), parv[1]); - return 0; - } - if (MyConnect(target_p)) - heal_nick(source_p, target_p); - else - sendto_one(target_p, ":%s ENCAP %s HEAL %s", - get_id(source_p, target_p), - target_p->servptr->name, - get_id(target_p, target_p)); - } - else if (strchr(parv[1], '.')) - { - if (hurt_find_exact(parv[1]) == NULL) - { - sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]); - return 0; - } - hurt_remove(parv[1]); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s", - get_oper_name(source_p), parv[1]); - sendto_server(NULL, NULL, NOCAPS, NOCAPS, ":%s ENCAP * HEAL %s", - source_p->name, parv[1]); - } - else - { - sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]); - return 0; - } + if (nick_is_valid(parv[1])) { + target_p = find_named_person(parv[1]); + if (target_p == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), parv[1]); + return 0; + } + if (MyConnect(target_p)) + heal_nick(source_p, target_p); + else + sendto_one(target_p, ":%s ENCAP %s HEAL %s", + get_id(source_p, target_p), + target_p->servptr->name, + get_id(target_p, target_p)); + } else if (strchr(parv[1], '.')) { + if (hurt_find_exact(parv[1]) == NULL) { + sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]); + return 0; + } + hurt_remove(parv[1]); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s", + get_oper_name(source_p), parv[1]); + sendto_server(NULL, NULL, NOCAPS, NOCAPS, ":%s ENCAP * HEAL %s", + source_p->name, parv[1]); + } else { + sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]); + return 0; + } - return 0; + return 0; } /* }}} */ static int me_heal(struct Client *client_p, struct Client *source_p, - int parc, const char **parv) + int parc, const char **parv) { - struct Client *target_p; + struct Client *target_p; - /* as noted in me_hurt(), if we don't get sufficient arguments... - * *poof*, it's dropped... - */ - if (parc < 2) - return 0; + /* as noted in me_hurt(), if we don't get sufficient arguments... + * *poof*, it's dropped... + */ + if (parc < 2) + return 0; - if (nick_is_valid(parv[1])) - { - target_p = find_person(parv[1]); - if (target_p != NULL && MyConnect(target_p)) - heal_nick(source_p, target_p); - } - else if (strchr(parv[1], '.')) /* host or mask to remove ban for */ - { - if (hurt_find_exact(parv[1]) == NULL) - return 0; + if (nick_is_valid(parv[1])) { + target_p = find_person(parv[1]); + if (target_p != NULL && MyConnect(target_p)) + heal_nick(source_p, target_p); + } else if (strchr(parv[1], '.')) { /* host or mask to remove ban for */ + if (hurt_find_exact(parv[1]) == NULL) + return 0; - hurt_remove(parv[1]); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s", - get_oper_name(source_p), parv[1]); - } - else - return 0; + hurt_remove(parv[1]); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s", + get_oper_name(source_p), parv[1]); + } else + return 0; - return 0; + return 0; } /* @@ -390,20 +372,18 @@ me_heal(struct Client *client_p, struct Client *source_p, static void hurt_check_event(void *arg) { - rb_dlink_node *ptr, *next_ptr; - struct Client *client_p; + rb_dlink_node *ptr, *next_ptr; + struct Client *client_p; - RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) { - client_p = ptr->data; - if (!EmptyString(client_p->user->suser)) - { - rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); - sendto_one_notice(client_p, ":HURT restriction removed for this session"); - client_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */ - } - else if (client_p->localClient->receiveM > hurt_state.cutoff) - exit_client(NULL, client_p, &me, hurt_state.exit_reason); - } + RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) { + client_p = ptr->data; + if (!EmptyString(client_p->user->suser)) { + rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); + sendto_one_notice(client_p, ":HURT restriction removed for this session"); + client_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */ + } else if (client_p->localClient->receiveM > hurt_state.cutoff) + exit_client(NULL, client_p, &me, hurt_state.exit_reason); + } } /* }}} */ @@ -411,19 +391,17 @@ hurt_check_event(void *arg) static void hurt_expire_event(void *unused) { - rb_dlink_node *ptr, *next_ptr; - hurt_t *hurt; + rb_dlink_node *ptr, *next_ptr; + hurt_t *hurt; - RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; + RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head) { + hurt = (hurt_t *) ptr->data; - if (hurt->expire <= rb_current_time()) - { - rb_dlinkFindDestroy(hurt, &hurt_confs); - hurt_destroy(hurt); - } - } + if (hurt->expire <= rb_current_time()) { + rb_dlinkFindDestroy(hurt, &hurt_confs); + hurt_destroy(hurt); + } + } } /* }}} */ @@ -435,10 +413,10 @@ hurt_expire_event(void *unused) static void client_exit_hook(hook_data_client_exit *data) { - s_assert(data != NULL); - s_assert(data->target != NULL); + s_assert(data != NULL); + s_assert(data->target != NULL); - rb_dlinkFindDestroy(data->target, &hurt_state.hurt_clients); + rb_dlinkFindDestroy(data->target, &hurt_state.hurt_clients); } /* }}} */ @@ -446,17 +424,16 @@ client_exit_hook(hook_data_client_exit *data) static void new_local_user_hook(struct Client *source_p) { - if (IsAnyDead(source_p) || !EmptyString(source_p->user->suser) || - IsExemptKline(source_p)) - return; + if (IsAnyDead(source_p) || !EmptyString(source_p->user->suser) || + IsExemptKline(source_p)) + return; - if (hurt_find(source_p->sockhost) || hurt_find(source_p->orighost)) - { - source_p->localClient->target_last = rb_current_time() + 600; /* don't ask --nenolod */ - SetTGChange(source_p); - rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients); - sendto_one_notice(source_p, ":You are hurt. Please identify to services immediately, or use /stats p for assistance."); - } + if (hurt_find(source_p->sockhost) || hurt_find(source_p->orighost)) { + source_p->localClient->target_last = rb_current_time() + 600; /* don't ask --nenolod */ + SetTGChange(source_p); + rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients); + sendto_one_notice(source_p, ":You are hurt. Please identify to services immediately, or use /stats p for assistance."); + } } /* }}} */ @@ -464,47 +441,43 @@ new_local_user_hook(struct Client *source_p) static void doing_stats_hook(hook_data_int *hdata) { - rb_dlink_node *ptr; - hurt_t *hurt; - struct Client *source_p; + rb_dlink_node *ptr; + hurt_t *hurt; + struct Client *source_p; - s_assert(hdata); - s_assert(hdata->client); + s_assert(hdata); + s_assert(hdata->client); - source_p = hdata->client; - if(hdata->arg2 != (int) 's') - return; - if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p)) - return; - if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p)) - { - hurt = hurt_find(source_p->sockhost); - if (hurt != NULL) - { - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), 's', - "*", hurt->ip, hurt->reason, "", ""); - return; - } + source_p = hdata->client; + if(hdata->arg2 != (int) 's') + return; + if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p)) + return; + if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p)) { + hurt = hurt_find(source_p->sockhost); + if (hurt != NULL) { + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), 's', + "*", hurt->ip, hurt->reason, "", ""); + return; + } - hurt = hurt_find(source_p->orighost); - if (hurt != NULL) - { - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), 's', - "*", hurt->ip, hurt->reason, "", ""); - return; - } - return; - } + hurt = hurt_find(source_p->orighost); + if (hurt != NULL) { + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), 's', + "*", hurt->ip, hurt->reason, "", ""); + return; + } + return; + } - RB_DLINK_FOREACH(ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), 's', - "*", hurt->ip, hurt->reason, "", ""); - } + RB_DLINK_FOREACH(ptr, hurt_confs.head) { + hurt = (hurt_t *) ptr->data; + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), 's', + "*", hurt->ip, hurt->reason, "", ""); + } } /* }}} */ @@ -518,18 +491,18 @@ doing_stats_hook(hook_data_int *hdata) static void hurt_propagate(struct Client *client_p, struct Client *source_p, hurt_t *hurt) { - if (client_p) - sendto_one(client_p, - ":%s ENCAP %s HURT %ld %s :%s", - source_p->name, client_p->name, - (long)(hurt->expire - rb_current_time()), - hurt->ip, hurt->reason); - else - sendto_server(&me, NULL, NOCAPS, NOCAPS, - ":%s ENCAP * HURT %ld %s :%s", - source_p->name, - (long)(hurt->expire - rb_current_time()), - hurt->ip, hurt->reason); + if (client_p) + sendto_one(client_p, + ":%s ENCAP %s HURT %ld %s :%s", + source_p->name, client_p->name, + (long)(hurt->expire - rb_current_time()), + hurt->ip, hurt->reason); + else + sendto_server(&me, NULL, NOCAPS, NOCAPS, + ":%s ENCAP * HURT %ld %s :%s", + source_p->name, + (long)(hurt->expire - rb_current_time()), + hurt->ip, hurt->reason); } /* }}} */ @@ -537,15 +510,15 @@ hurt_propagate(struct Client *client_p, struct Client *source_p, hurt_t *hurt) static hurt_t * hurt_new(time_t expire, const char *ip, const char *reason) { - hurt_t *hurt; + hurt_t *hurt; - hurt = rb_malloc(sizeof(hurt_t)); + hurt = rb_malloc(sizeof(hurt_t)); - hurt->ip = rb_strdup(ip); - hurt->reason = rb_strdup(reason); - hurt->expire = rb_current_time() + expire; + hurt->ip = rb_strdup(ip); + hurt->reason = rb_strdup(reason); + hurt->expire = rb_current_time() + expire; - return hurt; + return hurt; } /* }}} */ @@ -553,85 +526,80 @@ hurt_new(time_t expire, const char *ip, const char *reason) static void hurt_destroy(void *hurt) { - hurt_t *h; + hurt_t *h; - if (!hurt) - return; + if (!hurt) + return; - h = (hurt_t *) hurt; - rb_free(h->ip); - rb_free(h->reason); - rb_free(h); + h = (hurt_t *) hurt; + rb_free(h->ip); + rb_free(h->reason); + rb_free(h); } /* }}} */ static void hurt_add(hurt_t *hurt) { - rb_dlinkAddAlloc(hurt, &hurt_confs); + rb_dlinkAddAlloc(hurt, &hurt_confs); } static hurt_t * hurt_find_exact(const char *ip) { - rb_dlink_node *ptr; - hurt_t *hurt; + rb_dlink_node *ptr; + hurt_t *hurt; - RB_DLINK_FOREACH(ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; + RB_DLINK_FOREACH(ptr, hurt_confs.head) { + hurt = (hurt_t *) ptr->data; - if (!strcasecmp(ip, hurt->ip)) - return hurt; - } + if (!strcasecmp(ip, hurt->ip)) + return hurt; + } - return NULL; + return NULL; } static hurt_t * hurt_find(const char *ip) { - rb_dlink_node *ptr; - hurt_t *hurt; + rb_dlink_node *ptr; + hurt_t *hurt; - RB_DLINK_FOREACH(ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; + RB_DLINK_FOREACH(ptr, hurt_confs.head) { + hurt = (hurt_t *) ptr->data; - if (match(hurt->ip, ip)) - return hurt; - } + if (match(hurt->ip, ip)) + return hurt; + } - return NULL; + return NULL; } static void hurt_remove(const char *ip) { - hurt_t *hurt = hurt_find_exact(ip); + hurt_t *hurt = hurt_find_exact(ip); - rb_dlinkFindDestroy(hurt, &hurt_confs); - hurt_destroy(hurt); + rb_dlinkFindDestroy(hurt, &hurt_confs); + hurt_destroy(hurt); } /* {{{ static int heal_nick() */ static int heal_nick(struct Client *source_p, struct Client *target_p) { - if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s used HEAL on %s", - get_oper_name(source_p), get_client_name(target_p, HIDE_IP)); - sendto_one_notice(target_p, ":HURT restriction temporarily removed by operator"); - sendto_one_notice(source_p, ":HURT restriction on %s temporarily removed", target_p->name); - target_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */ - return 1; - } - else - { - sendto_one_notice(source_p, ":%s was not hurt", target_p->name); - return 0; - } + if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s used HEAL on %s", + get_oper_name(source_p), get_client_name(target_p, HIDE_IP)); + sendto_one_notice(target_p, ":HURT restriction temporarily removed by operator"); + sendto_one_notice(source_p, ":HURT restriction on %s temporarily removed", target_p->name); + target_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */ + return 1; + } else { + sendto_one_notice(source_p, ":%s was not hurt", target_p->name); + return 0; + } } /* }}} */ @@ -643,14 +611,14 @@ heal_nick(struct Client *source_p, struct Client *target_p) static int nick_is_valid(const char *nick) { - const char *s = nick; + const char *s = nick; - for (; *s != '\0'; s++) { - if (!IsNickChar(*s)) - return 0; - } + for (; *s != '\0'; s++) { + if (!IsNickChar(*s)) + return 0; + } - return 1; + return 1; } /* }}} */ diff --git a/extensions/ip_cloaking-5.c b/extensions/ip_cloaking-5.c index ec085e8..4f2522c 100644 --- a/extensions/ip_cloaking-5.c +++ b/extensions/ip_cloaking-5.c @@ -1,4 +1,4 @@ -/* +/* * Charybdis: an advanced ircd * ip_cloaking.c: provide user hostname cloaking * @@ -25,145 +25,136 @@ char *secretsalt = "32qwnqoWI@DpMd&w"; static void conf_set_secretsalt(void *data) { - secretsalt = rb_strdup(data); + secretsalt = rb_strdup(data); } static int _modinit(void) { - /* add the usermode to the available slot */ - user_modes['x'] = find_umode_slot(); - construct_umodebuf(); + /* add the usermode to the available slot */ + user_modes['x'] = find_umode_slot(); + construct_umodebuf(); - add_top_conf("cloaking", NULL, NULL, NULL); - add_conf_item("cloaking", "secretsalt", CF_QSTRING, conf_set_secretsalt); + add_top_conf("cloaking", NULL, NULL, NULL); + add_conf_item("cloaking", "secretsalt", CF_QSTRING, conf_set_secretsalt); - return 0; + return 0; } static void _moddeinit(void) { - /* disable the umode and remove it from the available list */ - user_modes['x'] = 0; - construct_umodebuf(); + /* disable the umode and remove it from the available list */ + user_modes['x'] = 0; + construct_umodebuf(); - add_top_conf("cloaking", NULL, NULL, NULL); - add_conf_item("cloaking", "secretsalt", CF_QSTRING, conf_set_secretsalt); + add_top_conf("cloaking", NULL, NULL, NULL); + add_conf_item("cloaking", "secretsalt", CF_QSTRING, conf_set_secretsalt); } static void check_umode_change(void *data); static void check_new_user(void *data); mapi_hfn_list_av1 ip_cloaking_hfnlist[] = { - { "umode_changed", (hookfn) check_umode_change }, - { "new_local_user", (hookfn) check_new_user }, - { NULL, NULL } + { "umode_changed", (hookfn) check_umode_change }, + { "new_local_user", (hookfn) check_new_user }, + { NULL, NULL } }; DECLARE_MODULE_AV1(ip_cloaking, _modinit, _moddeinit, NULL, NULL, - ip_cloaking_hfnlist, "$Revision: 3526 $"); + ip_cloaking_hfnlist, "$Revision: 3526 $"); static void distribute_hostchange(struct Client *client_p, char *newhost) { - if (newhost != client_p->orighost) - sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", - newhost); - else - sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :hostname reset", - newhost); + if (newhost != client_p->orighost) + sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", + newhost); + else + sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :hostname reset", + newhost); - sendto_server(NULL, NULL, - CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", - use_id(&me), use_id(client_p), newhost); - sendto_server(NULL, NULL, - CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", - use_id(&me), use_id(client_p), newhost); + sendto_server(NULL, NULL, + CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", + use_id(&me), use_id(client_p), newhost); + sendto_server(NULL, NULL, + CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", + use_id(&me), use_id(client_p), newhost); - change_nick_user_host(client_p, client_p->name, client_p->username, newhost, 0, "Changing host"); + change_nick_user_host(client_p, client_p->name, client_p->username, newhost, 0, "Changing host"); - if (newhost != client_p->orighost) - SetDynSpoof(client_p); - else - ClearDynSpoof(client_p); + if (newhost != client_p->orighost) + SetDynSpoof(client_p); + else + ClearDynSpoof(client_p); } static void do_host_cloak(const char *inbuf, char *outbuf) { - unsigned char *hash; - char buf[3]; - char output[HOSTLEN+1]; - int i; + unsigned char *hash; + char buf[3]; + char output[HOSTLEN+1]; + int i; - hash = HMAC(EVP_sha256(), secretsalt, strlen(secretsalt), (unsigned char*)inbuf, strlen(inbuf), NULL, NULL); + hash = HMAC(EVP_sha256(), secretsalt, strlen(secretsalt), (unsigned char*)inbuf, strlen(inbuf), NULL, NULL); - output[0]=0; + output[0]=0; - for (i = 0; i < 32; i++) { - sprintf(buf, "%.2x", hash[i]); - strcat(output,buf); - } + for (i = 0; i < 32; i++) { + sprintf(buf, "%.2x", hash[i]); + strcat(output,buf); + } - rb_strlcpy(outbuf,output,HOSTLEN+1); + rb_strlcpy(outbuf,output,HOSTLEN+1); } static void check_umode_change(void *vdata) { - hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; - struct Client *source_p = data->client; + hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; + struct Client *source_p = data->client; - if (!MyClient(source_p)) - return; + if (!MyClient(source_p)) + return; - /* didn't change +h umode, we don't need to do anything */ - if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) - return; + /* didn't change +h umode, we don't need to do anything */ + if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) + return; - if (source_p->umodes & user_modes['h']) - { - if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) - { - source_p->umodes &= ~user_modes['x']; - return; - } - if (strcmp(source_p->host, source_p->localClient->mangledhost)) - { - distribute_hostchange(source_p, source_p->localClient->mangledhost); - } - else /* not really nice, but we need to send this numeric here */ - sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", - source_p->host); - } - else if (!(source_p->umodes & user_modes['x'])) - { - if (source_p->localClient->mangledhost != NULL && - !strcmp(source_p->host, source_p->localClient->mangledhost)) - { - distribute_hostchange(source_p, source_p->orighost); - } - } + if (source_p->umodes & user_modes['h']) { + if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) { + source_p->umodes &= ~user_modes['x']; + return; + } + if (strcmp(source_p->host, source_p->localClient->mangledhost)) { + distribute_hostchange(source_p, source_p->localClient->mangledhost); + } else /* not really nice, but we need to send this numeric here */ + sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", + source_p->host); + } else if (!(source_p->umodes & user_modes['x'])) { + if (source_p->localClient->mangledhost != NULL && + !strcmp(source_p->host, source_p->localClient->mangledhost)) { + distribute_hostchange(source_p, source_p->orighost); + } + } } static void check_new_user(void *vdata) { - struct Client *source_p = (void *)vdata; + struct Client *source_p = (void *)vdata; - if (IsIPSpoof(source_p)) - { - source_p->umodes &= ~user_modes['x']; - return; - } - source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1); - do_host_cloak(source_p->orighost, source_p->localClient->mangledhost); - if (IsDynSpoof(source_p)) - source_p->umodes &= ~user_modes['x']; - if (source_p->umodes & user_modes['x']) - { - rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); - if (irccmp(source_p->host, source_p->orighost)) - SetDynSpoof(source_p); - } + if (IsIPSpoof(source_p)) { + source_p->umodes &= ~user_modes['x']; + return; + } + source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1); + do_host_cloak(source_p->orighost, source_p->localClient->mangledhost); + if (IsDynSpoof(source_p)) + source_p->umodes &= ~user_modes['x']; + if (source_p->umodes & user_modes['x']) { + rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); + if (irccmp(source_p->host, source_p->orighost)) + SetDynSpoof(source_p); + } } diff --git a/extensions/ip_cloaking.c b/extensions/ip_cloaking.c index 9e4e729..7352afc 100644 --- a/extensions/ip_cloaking.c +++ b/extensions/ip_cloaking.c @@ -1,4 +1,4 @@ -/* +/* * Charybdis: an advanced ircd * ip_cloaking.c: provide user hostname cloaking * @@ -20,206 +20,191 @@ static int _modinit(void) { - /* add the usermode to the available slot */ - user_modes['x'] = find_umode_slot(); - construct_umodebuf(); + /* add the usermode to the available slot */ + user_modes['x'] = find_umode_slot(); + construct_umodebuf(); - return 0; + return 0; } static void _moddeinit(void) { - /* disable the umode and remove it from the available list */ - user_modes['x'] = 0; - construct_umodebuf(); + /* disable the umode and remove it from the available list */ + user_modes['x'] = 0; + construct_umodebuf(); } static void check_umode_change(void *data); static void check_new_user(void *data); mapi_hfn_list_av1 ip_cloaking_hfnlist[] = { - { "umode_changed", (hookfn) check_umode_change }, - { "new_local_user", (hookfn) check_new_user }, - { NULL, NULL } + { "umode_changed", (hookfn) check_umode_change }, + { "new_local_user", (hookfn) check_new_user }, + { NULL, NULL } }; DECLARE_MODULE_AV1(ip_cloaking, _modinit, _moddeinit, NULL, NULL, - ip_cloaking_hfnlist, "$Revision: 3526 $"); + ip_cloaking_hfnlist, "$Revision: 3526 $"); static void distribute_hostchange(struct Client *client_p, char *newhost) { - if (newhost != client_p->orighost) - sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", - newhost); - else - sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :hostname reset", - newhost); + if (newhost != client_p->orighost) + sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", + newhost); + else + sendto_one_numeric(client_p, RPL_HOSTHIDDEN, "%s :hostname reset", + newhost); - sendto_server(NULL, NULL, - CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", - use_id(&me), use_id(client_p), newhost); - sendto_server(NULL, NULL, - CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", - use_id(&me), use_id(client_p), newhost); + sendto_server(NULL, NULL, + CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", + use_id(&me), use_id(client_p), newhost); + sendto_server(NULL, NULL, + CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", + use_id(&me), use_id(client_p), newhost); - change_nick_user_host(client_p, client_p->name, client_p->username, newhost, 0, "Changing host"); + change_nick_user_host(client_p, client_p->name, client_p->username, newhost, 0, "Changing host"); - if (newhost != client_p->orighost) - SetDynSpoof(client_p); - else - ClearDynSpoof(client_p); + if (newhost != client_p->orighost) + SetDynSpoof(client_p); + else + ClearDynSpoof(client_p); } static void do_host_cloak_ip(const char *inbuf, char *outbuf) { - /* None of the characters in this table can be valid in an IP */ - char chartable[] = "ghijklmnopqrstuvwxyz"; - char *tptr; - uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32); - int sepcount = 0; - int totalcount = 0; - int ipv6 = 0; + /* None of the characters in this table can be valid in an IP */ + char chartable[] = "ghijklmnopqrstuvwxyz"; + char *tptr; + uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32); + int sepcount = 0; + int totalcount = 0; + int ipv6 = 0; - rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); + rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); - if (strchr(outbuf, ':')) - { - ipv6 = 1; + if (strchr(outbuf, ':')) { + ipv6 = 1; - /* Damn you IPv6... - * We count the number of colons so we can calculate how much - * of the host to cloak. This is because some hostmasks may not - * have as many octets as we'd like. - * - * We have to do this ahead of time because doing this during - * the actual cloaking would get ugly - */ - for (tptr = outbuf; *tptr != '\0'; tptr++) - if (*tptr == ':') - totalcount++; - } - else if (!strchr(outbuf, '.')) - return; + /* Damn you IPv6... + * We count the number of colons so we can calculate how much + * of the host to cloak. This is because some hostmasks may not + * have as many octets as we'd like. + * + * We have to do this ahead of time because doing this during + * the actual cloaking would get ugly + */ + for (tptr = outbuf; *tptr != '\0'; tptr++) + if (*tptr == ':') + totalcount++; + } else if (!strchr(outbuf, '.')) + return; - for (tptr = outbuf; *tptr != '\0'; tptr++) - { - if (*tptr == ':' || *tptr == '.') - { - sepcount++; - continue; - } + for (tptr = outbuf; *tptr != '\0'; tptr++) { + if (*tptr == ':' || *tptr == '.') { + sepcount++; + continue; + } - if (ipv6 && sepcount < totalcount / 2) - continue; + if (ipv6 && sepcount < totalcount / 2) + continue; - if (!ipv6 && sepcount < 2) - continue; + if (!ipv6 && sepcount < 2) + continue; - *tptr = chartable[(*tptr + accum) % 20]; - accum = (accum << 1) | (accum >> 31); - } + *tptr = chartable[(*tptr + accum) % 20]; + accum = (accum << 1) | (accum >> 31); + } } static void do_host_cloak_host(const char *inbuf, char *outbuf) { - char b26_alphabet[] = "abcdefghijklmnopqrstuvwxyz"; - char *tptr; - uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32); + char b26_alphabet[] = "abcdefghijklmnopqrstuvwxyz"; + char *tptr; + uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32); - rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); + rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); - /* pass 1: scramble first section of hostname using base26 - * alphabet toasted against the FNV hash of the string. - * - * numbers are not changed at this time, only letters. - */ - for (tptr = outbuf; *tptr != '\0'; tptr++) - { - if (*tptr == '.') - break; + /* pass 1: scramble first section of hostname using base26 + * alphabet toasted against the FNV hash of the string. + * + * numbers are not changed at this time, only letters. + */ + for (tptr = outbuf; *tptr != '\0'; tptr++) { + if (*tptr == '.') + break; - if (isdigit(*tptr) || *tptr == '-') - continue; + if (isdigit(*tptr) || *tptr == '-') + continue; - *tptr = b26_alphabet[(*tptr + accum) % 26]; + *tptr = b26_alphabet[(*tptr + accum) % 26]; - /* Rotate one bit to avoid all digits being turned odd or even */ - accum = (accum << 1) | (accum >> 31); - } + /* Rotate one bit to avoid all digits being turned odd or even */ + accum = (accum << 1) | (accum >> 31); + } - /* pass 2: scramble each number in the address */ - for (tptr = outbuf; *tptr != '\0'; tptr++) - { - if (isdigit(*tptr)) - *tptr = '0' + (*tptr + accum) % 10; + /* pass 2: scramble each number in the address */ + for (tptr = outbuf; *tptr != '\0'; tptr++) { + if (isdigit(*tptr)) + *tptr = '0' + (*tptr + accum) % 10; - accum = (accum << 1) | (accum >> 31); - } + accum = (accum << 1) | (accum >> 31); + } } static void check_umode_change(void *vdata) { - hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; - struct Client *source_p = data->client; + hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; + struct Client *source_p = data->client; - if (!MyClient(source_p)) - return; + if (!MyClient(source_p)) + return; - /* didn't change +h umode, we don't need to do anything */ - if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) - return; + /* didn't change +h umode, we don't need to do anything */ + if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) + return; - if (source_p->umodes & user_modes['x']) - { - if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) - { - source_p->umodes &= ~user_modes['x']; - return; - } - if (strcmp(source_p->host, source_p->localClient->mangledhost)) - { - distribute_hostchange(source_p, source_p->localClient->mangledhost); - } - else /* not really nice, but we need to send this numeric here */ - sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", - source_p->host); - } - else if (!(source_p->umodes & user_modes['x'])) - { - if (source_p->localClient->mangledhost != NULL && - !strcmp(source_p->host, source_p->localClient->mangledhost)) - { - distribute_hostchange(source_p, source_p->orighost); - } - } + if (source_p->umodes & user_modes['x']) { + if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) { + source_p->umodes &= ~user_modes['x']; + return; + } + if (strcmp(source_p->host, source_p->localClient->mangledhost)) { + distribute_hostchange(source_p, source_p->localClient->mangledhost); + } else /* not really nice, but we need to send this numeric here */ + sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", + source_p->host); + } else if (!(source_p->umodes & user_modes['x'])) { + if (source_p->localClient->mangledhost != NULL && + !strcmp(source_p->host, source_p->localClient->mangledhost)) { + distribute_hostchange(source_p, source_p->orighost); + } + } } static void check_new_user(void *vdata) { - struct Client *source_p = (void *)vdata; + struct Client *source_p = (void *)vdata; - if (IsIPSpoof(source_p)) - { - source_p->umodes &= ~user_modes['x']; - return; - } - source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1); - if (!irccmp(source_p->orighost, source_p->sockhost)) - do_host_cloak_ip(source_p->orighost, source_p->localClient->mangledhost); - else - do_host_cloak_host(source_p->orighost, source_p->localClient->mangledhost); - if (IsDynSpoof(source_p)) - source_p->umodes &= ~user_modes['x']; - if (source_p->umodes & user_modes['x']) - { - rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); - if (irccmp(source_p->host, source_p->orighost)) - SetDynSpoof(source_p); - } + if (IsIPSpoof(source_p)) { + source_p->umodes &= ~user_modes['x']; + return; + } + source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1); + if (!irccmp(source_p->orighost, source_p->sockhost)) + do_host_cloak_ip(source_p->orighost, source_p->localClient->mangledhost); + else + do_host_cloak_host(source_p->orighost, source_p->localClient->mangledhost); + if (IsDynSpoof(source_p)) + source_p->umodes &= ~user_modes['x']; + if (source_p->umodes & user_modes['x']) { + rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); + if (irccmp(source_p->host, source_p->orighost)) + SetDynSpoof(source_p); + } } diff --git a/extensions/m_42.c b/extensions/m_42.c index 35d0d1a..3bf29ec 100644 --- a/extensions/m_42.c +++ b/extensions/m_42.c @@ -1,7 +1,7 @@ /* * Copyright (C) infinity-infinity God * - * Bob was here + * Bob was here */ #include "stdinc.h" @@ -13,9 +13,10 @@ static int mclient_42(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message hgtg_msgtab = { - "42", 0, 0, 0, MFLG_SLOW, - { mg_ignore, {mclient_42, 0}, mg_ignore, mg_ignore, mg_ignore, {mclient_42, 0} - } + "42", 0, 0, 0, MFLG_SLOW, + { + mg_ignore, {mclient_42, 0}, mg_ignore, mg_ignore, mg_ignore, {mclient_42, 0} + } }; mapi_clist_av1 hgtg_clist[] = { &hgtg_msgtab, NULL }; @@ -27,8 +28,8 @@ DECLARE_MODULE_AV1(42, NULL, NULL, hgtg_clist, NULL, NULL, "Revision 0.42"); static int mclient_42(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - sendto_one_notice(source_p, ":The Answer to Life, the Universe, and Everything."); - return 0; + sendto_one_notice(source_p, ":The Answer to Life, the Universe, and Everything."); + return 0; } diff --git a/extensions/m_adminwall.c b/extensions/m_adminwall.c index 04ff744..81be185 100644 --- a/extensions/m_adminwall.c +++ b/extensions/m_adminwall.c @@ -41,10 +41,10 @@ static int mo_adminwall(struct Client *, struct Client *, int, const char **); static int me_adminwall(struct Client *, struct Client *, int, const char **); struct Message adminwall_msgtab = { - "ADMINWALL", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_adminwall, 2}, {mo_adminwall, 2}} + "ADMINWALL", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_adminwall, 2}, {mo_adminwall, 2}} }; - + mapi_clist_av1 adminwall_clist[] = { &adminwall_msgtab, NULL }; DECLARE_MODULE_AV1(adminwall, NULL, NULL, adminwall_clist, NULL, NULL, "$Revision: 20702 $"); @@ -56,22 +56,21 @@ DECLARE_MODULE_AV1(adminwall, NULL, NULL, adminwall_clist, NULL, NULL, "$Revisio */ static int -mo_adminwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) -{ - if(!IsAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "adminwall"); - return 0; - } - sendto_wallops_flags(UMODE_ADMIN, source_p, "ADMINWALL - %s", parv[1]); - sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ADMINWALL :%s", parv[1]); +mo_adminwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) +{ + if(!IsAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "adminwall"); return 0; -} + } + sendto_wallops_flags(UMODE_ADMIN, source_p, "ADMINWALL - %s", parv[1]); + sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ADMINWALL :%s", parv[1]); + return 0; +} static int -me_adminwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) -{ - sendto_wallops_flags(UMODE_ADMIN, source_p, "ADMINWALL - %s", parv[1]); - return 0; +me_adminwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) +{ + sendto_wallops_flags(UMODE_ADMIN, source_p, "ADMINWALL - %s", parv[1]); + return 0; } diff --git a/extensions/m_cycle.c b/extensions/m_cycle.c index a0e8933..4e441e7 100644 --- a/extensions/m_cycle.c +++ b/extensions/m_cycle.c @@ -25,8 +25,8 @@ extern struct module **modlist; static int m_cycle(struct Client *, struct Client *, int, const char **); struct Message cycle_msgtab = { - "CYCLE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_cycle, 2}, {m_cycle, 2}, mg_ignore, mg_ignore, {m_cycle, 2}} + "CYCLE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_cycle, 2}, {m_cycle, 2}, mg_ignore, mg_ignore, {m_cycle, 2}} }; mapi_clist_av1 cycle_clist[] = { &cycle_msgtab, NULL }; @@ -35,64 +35,58 @@ DECLARE_MODULE_AV1(cycle, NULL, NULL, cycle_clist, NULL, NULL, "$Revision$"); static int m_cycle(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *p, *name; - char *s = LOCAL_COPY(parv[1]); - struct Channel *chptr; - struct membership *msptr; + char *p, *name; + char *s = LOCAL_COPY(parv[1]); + struct Channel *chptr; + struct membership *msptr; - name = rb_strtok_r(s, ",", &p); + name = rb_strtok_r(s, ",", &p); - /* Finish the flood grace period... */ - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + /* Finish the flood grace period... */ + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - while(name) - { - if((chptr = find_channel(name)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + while(name) { + if((chptr = find_channel(name)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - msptr = find_channel_membership(chptr, source_p); - if(msptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); - return 0; - } + msptr = find_channel_membership(chptr, source_p); + if(msptr == NULL) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); + return 0; + } - if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) - check_spambot_warning(source_p, NULL); - - if((is_any_op(msptr) || !MyConnect(source_p) || - ((can_send(chptr, source_p, msptr) > 0 && - (source_p->localClient->firsttime + - ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) - { - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s PART %s :Cycling", use_id(source_p), chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :Cycling", - source_p->name, source_p->username, - source_p->host, chptr->chname); - } - else - { - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s PART %s", use_id(source_p), chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", - source_p->name, source_p->username, - source_p->host, chptr->chname); - } - - remove_user_from_channel(msptr); - - chptr = NULL; - msptr = NULL; - - name = rb_strtok_r(NULL, ",", &p); - } - - user_join(client_p, source_p, parv[1], parc > 2 ? parv[2] : NULL); + if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) + check_spambot_warning(source_p, NULL); - return 0; + if((is_any_op(msptr) || !MyConnect(source_p) || + ((can_send(chptr, source_p, msptr) > 0 && + (source_p->localClient->firsttime + + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) { + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s PART %s :Cycling", use_id(source_p), chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :Cycling", + source_p->name, source_p->username, + source_p->host, chptr->chname); + } else { + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s PART %s", use_id(source_p), chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", + source_p->name, source_p->username, + source_p->host, chptr->chname); + } + + remove_user_from_channel(msptr); + + chptr = NULL; + msptr = NULL; + + name = rb_strtok_r(NULL, ",", &p); + } + + user_join(client_p, source_p, parv[1], parc > 2 ? parv[2] : NULL); + + return 0; } diff --git a/extensions/m_findforwards.c b/extensions/m_findforwards.c index e3d28c4..bf2ac18 100644 --- a/extensions/m_findforwards.c +++ b/extensions/m_findforwards.c @@ -35,11 +35,11 @@ #include "packet.h" static int m_findforwards(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); struct Message findforwards_msgtab = { - "FINDFORWARDS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_findforwards, 2}, mg_ignore, mg_ignore, mg_ignore, {m_findforwards, 2}} + "FINDFORWARDS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_findforwards, 2}, mg_ignore, mg_ignore, mg_ignore, {m_findforwards, 2}} }; mapi_clist_av1 findforwards_clist[] = { &findforwards_msgtab, NULL }; @@ -53,62 +53,54 @@ DECLARE_MODULE_AV1(findforwards, NULL, NULL, findforwards_clist, NULL, NULL, "$R static int m_findforwards(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; - struct Channel *chptr; - struct membership *msptr; - rb_dlink_node *ptr; - char buf[414]; - char *p = buf, *end = buf + sizeof buf - 1; - *p = '\0'; + static time_t last_used = 0; + struct Channel *chptr; + struct membership *msptr; + rb_dlink_node *ptr; + char buf[414]; + char *p = buf, *end = buf + sizeof buf - 1; + *p = '\0'; - /* Allow ircops to search for forwards to nonexistent channels */ - if(!IsOper(source_p)) - { - if((chptr = find_channel(parv[1])) == NULL || (msptr = find_channel_membership(chptr, source_p)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), parv[1]); - return 0; - } + /* Allow ircops to search for forwards to nonexistent channels */ + if(!IsOper(source_p)) { + if((chptr = find_channel(parv[1])) == NULL || (msptr = find_channel_membership(chptr, source_p)) == NULL) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), parv[1]); + return 0; + } - if(!is_any_op(msptr)) - { - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, parv[1]); - return 0; - } + if(!is_any_op(msptr)) { + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, parv[1]); + return 0; + } - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "FINDFORWARDS"); - return 0; - } - else - last_used = rb_current_time(); - } - - RB_DLINK_FOREACH(ptr, global_channel_list.head) - { - chptr = ptr->data; - if(chptr->mode.forward && !irccmp(chptr->mode.forward, parv[1])) - { - if(p + strlen(chptr->chname) >= end - 13) - { - strcpy(p, " "); - p += 12; - break; - } - strcpy(p, chptr->chname); - p += strlen(chptr->chname); - *p++ = ' '; - } - } + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "FINDFORWARDS"); + return 0; + } else + last_used = rb_current_time(); + } - if(buf[0]) - *(--p) = '\0'; + RB_DLINK_FOREACH(ptr, global_channel_list.head) { + chptr = ptr->data; + if(chptr->mode.forward && !irccmp(chptr->mode.forward, parv[1])) { + if(p + strlen(chptr->chname) >= end - 13) { + strcpy(p, " "); + p += 12; + break; + } + strcpy(p, chptr->chname); + p += strlen(chptr->chname); + *p++ = ' '; + } + } - sendto_one_notice(source_p, ":Forwards for %s: %s", parv[1], buf); + if(buf[0]) + *(--p) = '\0'; - return 0; + sendto_one_notice(source_p, ":Forwards for %s: %s", parv[1], buf); + + return 0; } diff --git a/extensions/m_force.c b/extensions/m_force.c index e23113b..edaf55f 100644 --- a/extensions/m_force.c +++ b/extensions/m_force.c @@ -48,11 +48,11 @@ #include "modules.h" static int mo_forcejoin(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); struct Message forcejoin_msgtab = { - "FORCEJOIN", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcejoin, 3}} + "FORCEJOIN", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcejoin, 3}} }; mapi_clist_av1 force_clist[] = { &forcejoin_msgtab, NULL }; @@ -67,152 +67,137 @@ DECLARE_MODULE_AV1(force, NULL, NULL, force_clist, NULL, NULL, "$Revision: 3297 static int mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - struct Channel *chptr; - int type; - char mode; - char sjmode; - char *newch; + struct Client *target_p; + struct Channel *chptr; + int type; + char mode; + char sjmode; + char *newch; - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); + return 0; + } - if((hunt_server(client_p, source_p, ":%s FORCEJOIN %s %s", 1, parc, parv)) != HUNTED_ISME) - return 0; + if((hunt_server(client_p, source_p, ":%s FORCEJOIN %s %s", 1, parc, parv)) != HUNTED_ISME) + return 0; - /* if target_p is not existant, print message - * to source_p and bail - scuzzy - */ - if((target_p = find_client(parv[1])) == NULL) - { - sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); - return 0; - } + /* if target_p is not existant, print message + * to source_p and bail - scuzzy + */ + if((target_p = find_client(parv[1])) == NULL) { + sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); + return 0; + } - if(!IsPerson(target_p)) - return 0; + if(!IsPerson(target_p)) + return 0; - sendto_wallops_flags(UMODE_WALLOP, &me, - "FORCEJOIN called for %s %s by %s!%s@%s", - parv[1], parv[2], source_p->name, source_p->username, source_p->host); - ilog(L_MAIN, "FORCEJOIN called for %s %s by %s!%s@%s", - parv[1], parv[2], source_p->name, source_p->username, source_p->host); - sendto_server(NULL, NULL, NOCAPS, NOCAPS, - ":%s WALLOPS :FORCEJOIN called for %s %s by %s!%s@%s", - me.name, parv[1], parv[2], - source_p->name, source_p->username, source_p->host); + sendto_wallops_flags(UMODE_WALLOP, &me, + "FORCEJOIN called for %s %s by %s!%s@%s", + parv[1], parv[2], source_p->name, source_p->username, source_p->host); + ilog(L_MAIN, "FORCEJOIN called for %s %s by %s!%s@%s", + parv[1], parv[2], source_p->name, source_p->username, source_p->host); + sendto_server(NULL, NULL, NOCAPS, NOCAPS, + ":%s WALLOPS :FORCEJOIN called for %s %s by %s!%s@%s", + me.name, parv[1], parv[2], + source_p->name, source_p->username, source_p->host); - /* select our modes from parv[2] if they exist... (chanop) */ - if(*parv[2] == '@') - { - type = CHFL_CHANOP; - mode = 'o'; - sjmode = '@'; - } - else if(*parv[2] == '+') - { - type = CHFL_VOICE; - mode = 'v'; - sjmode = '+'; - } - else - { - type = CHFL_PEON; - mode = sjmode = '\0'; - } + /* select our modes from parv[2] if they exist... (chanop) */ + if(*parv[2] == '@') { + type = CHFL_CHANOP; + mode = 'o'; + sjmode = '@'; + } else if(*parv[2] == '+') { + type = CHFL_VOICE; + mode = 'v'; + sjmode = '+'; + } else { + type = CHFL_PEON; + mode = sjmode = '\0'; + } - if(mode != '\0') - parv[2]++; + if(mode != '\0') + parv[2]++; - if((chptr = find_channel(parv[2])) != NULL) - { - if(IsMember(target_p, chptr)) - { - /* debugging is fun... */ - sendto_one_notice(source_p, ":*** Notice -- %s is already in %s", - target_p->name, chptr->chname); - return 0; - } + if((chptr = find_channel(parv[2])) != NULL) { + if(IsMember(target_p, chptr)) { + /* debugging is fun... */ + sendto_one_notice(source_p, ":*** Notice -- %s is already in %s", + target_p->name, chptr->chname); + return 0; + } - add_user_to_channel(chptr, target_p, type); + add_user_to_channel(chptr, target_p, type); - sendto_server(target_p, chptr, NOCAPS, NOCAPS, - ":%s SJOIN %ld %s + :%c%s", - me.name, (long) chptr->channelts, - chptr->chname, type ? sjmode : ' ', target_p->name); + sendto_server(target_p, chptr, NOCAPS, NOCAPS, + ":%s SJOIN %ld %s + :%c%s", + me.name, (long) chptr->channelts, + chptr->chname, type ? sjmode : ' ', target_p->name); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", - target_p->name, target_p->username, - target_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", + target_p->name, target_p->username, + target_p->host, chptr->chname); - if(type) - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s", - me.name, chptr->chname, mode, target_p->name); + if(type) + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s", + me.name, chptr->chname, mode, target_p->name); - if(chptr->topic != NULL) - { - sendto_one(target_p, form_str(RPL_TOPIC), me.name, - target_p->name, chptr->chname, chptr->topic); - sendto_one(target_p, form_str(RPL_TOPICWHOTIME), - me.name, source_p->name, chptr->chname, - chptr->topic_info, chptr->topic_time); - } + if(chptr->topic != NULL) { + sendto_one(target_p, form_str(RPL_TOPIC), me.name, + target_p->name, chptr->chname, chptr->topic); + sendto_one(target_p, form_str(RPL_TOPICWHOTIME), + me.name, source_p->name, chptr->chname, + chptr->topic_info, chptr->topic_time); + } - channel_member_names(chptr, target_p, 1); - } - else - { - newch = LOCAL_COPY(parv[2]); - if(!check_channel_name(newch)) - { - sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, - source_p->name, (unsigned char *) newch); - return 0; - } + channel_member_names(chptr, target_p, 1); + } else { + newch = LOCAL_COPY(parv[2]); + if(!check_channel_name(newch)) { + sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, + source_p->name, (unsigned char *) newch); + return 0; + } - /* channel name must begin with & or # */ - if(!IsChannelName(newch)) - { - sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, - source_p->name, (unsigned char *) newch); - return 0; - } + /* channel name must begin with & or # */ + if(!IsChannelName(newch)) { + sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, + source_p->name, (unsigned char *) newch); + return 0; + } - /* newch can't be longer than CHANNELLEN */ - if(strlen(newch) > CHANNELLEN) - { - sendto_one_notice(source_p, ":Channel name is too long"); - return 0; - } + /* newch can't be longer than CHANNELLEN */ + if(strlen(newch) > CHANNELLEN) { + sendto_one_notice(source_p, ":Channel name is too long"); + return 0; + } - chptr = get_or_create_channel(target_p, newch, NULL); - add_user_to_channel(chptr, target_p, CHFL_CHANOP); + chptr = get_or_create_channel(target_p, newch, NULL); + add_user_to_channel(chptr, target_p, CHFL_CHANOP); - /* send out a join, make target_p join chptr */ - sendto_server(target_p, chptr, NOCAPS, NOCAPS, - ":%s SJOIN %ld %s +nt :@%s", me.name, - (long) chptr->channelts, chptr->chname, target_p->name); + /* send out a join, make target_p join chptr */ + sendto_server(target_p, chptr, NOCAPS, NOCAPS, + ":%s SJOIN %ld %s +nt :@%s", me.name, + (long) chptr->channelts, chptr->chname, target_p->name); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", - target_p->name, target_p->username, - target_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", + target_p->name, target_p->username, + target_p->host, chptr->chname); - chptr->mode.mode |= MODE_TOPICLIMIT; - chptr->mode.mode |= MODE_NOPRIVMSGS; + chptr->mode.mode |= MODE_TOPICLIMIT; + chptr->mode.mode |= MODE_NOPRIVMSGS; - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +nt", me.name, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +nt", me.name, chptr->chname); - target_p->localClient->last_join_time = rb_current_time(); - channel_member_names(chptr, target_p, 1); + target_p->localClient->last_join_time = rb_current_time(); + channel_member_names(chptr, target_p, 1); - /* we do this to let the oper know that a channel was created, this will be - * seen from the server handling the command instead of the server that - * the oper is on. - */ - sendto_one_notice(source_p, ":*** Notice -- Creating channel %s", chptr->chname); - } - return 0; + /* we do this to let the oper know that a channel was created, this will be + * seen from the server handling the command instead of the server that + * the oper is on. + */ + sendto_one_notice(source_p, ":*** Notice -- Creating channel %s", chptr->chname); + } + return 0; } diff --git a/extensions/m_identify.c b/extensions/m_identify.c index 35bc48b..bac6d0f 100644 --- a/extensions/m_identify.c +++ b/extensions/m_identify.c @@ -52,49 +52,45 @@ char *reconstruct_parv(int parc, const char *parv[]); static int m_identify(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message identify_msgtab = { - "IDENTIFY", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_identify, 0}, mg_ignore, mg_ignore, mg_ignore, {m_identify, 0}} + "IDENTIFY", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_identify, 0}, mg_ignore, mg_ignore, mg_ignore, {m_identify, 0}} }; mapi_clist_av1 identify_clist[] = { - &identify_msgtab, - NULL + &identify_msgtab, + NULL }; DECLARE_MODULE_AV1(identify, NULL, NULL, identify_clist, NULL, NULL, "$Revision: 2729 $"); char *reconstruct_parv(int parc, const char *parv[]) { - static char tmpbuf[BUFSIZE]; int i; + static char tmpbuf[BUFSIZE]; + int i; - rb_strlcpy(tmpbuf, parv[0], BUFSIZE); - for (i = 1; i < parc; i++) - { - rb_strlcat(tmpbuf, " ", BUFSIZE); - rb_strlcat(tmpbuf, parv[i], BUFSIZE); - } - return tmpbuf; + rb_strlcpy(tmpbuf, parv[0], BUFSIZE); + for (i = 1; i < parc; i++) { + rb_strlcat(tmpbuf, " ", BUFSIZE); + rb_strlcat(tmpbuf, parv[i], BUFSIZE); + } + return tmpbuf; } static int m_identify(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *nick; - struct Client *target_p; + const char *nick; + struct Client *target_p; - if (parc < 2 || EmptyString(parv[1])) - { - sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); - return 0; - } + if (parc < 2 || EmptyString(parv[1])) { + sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); + return 0; + } - nick = parv[1][0] == '#' ? SVS_chanserv_NICK : SVS_nickserv_NICK; - if ((target_p = find_named_person(nick)) && IsService(target_p)) - { - sendto_one(target_p, ":%s PRIVMSG %s :IDENTIFY %s", get_id(source_p, target_p), get_id(target_p, target_p), reconstruct_parv(parc - 1, &parv[1])); - } - else - { - sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), nick); - } - return 0; + nick = parv[1][0] == '#' ? SVS_chanserv_NICK : SVS_nickserv_NICK; + if ((target_p = find_named_person(nick)) && IsService(target_p)) { + sendto_one(target_p, ":%s PRIVMSG %s :IDENTIFY %s", get_id(source_p, target_p), get_id(target_p, target_p), reconstruct_parv(parc - 1, &parv[1])); + } else { + sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), nick); + } + return 0; } diff --git a/extensions/m_mkpasswd.c b/extensions/m_mkpasswd.c index 677ae73..487d05e 100644 --- a/extensions/m_mkpasswd.c +++ b/extensions/m_mkpasswd.c @@ -15,9 +15,9 @@ #include static int m_mkpasswd(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); static int mo_mkpasswd(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); static char *make_md5_salt(int); static char *make_sha256_salt(int); @@ -26,11 +26,11 @@ static char *generate_random_salt(char *, int); static char *generate_poor_salt(char *, int); static char saltChars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - /* 0 .. 63, ascii - 64 */ +/* 0 .. 63, ascii - 64 */ struct Message mkpasswd_msgtab = { - "MKPASSWD", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_mkpasswd, 2}, mg_ignore, mg_ignore, mg_ignore, {mo_mkpasswd, 2}} + "MKPASSWD", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_mkpasswd, 2}, mg_ignore, mg_ignore, mg_ignore, {mo_mkpasswd, 2}} }; mapi_clist_av1 mkpasswd_clist[] = { &mkpasswd_msgtab, NULL }; @@ -45,46 +45,42 @@ DECLARE_MODULE_AV1(mkpasswd, NULL, NULL, mkpasswd_clist, NULL, NULL, "$Revision$ static int m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; - char *salt; - const char *hashtype; - const char hashdefault[] = "SHA512"; + static time_t last_used = 0; + char *salt; + const char *hashtype; + const char hashdefault[] = "SHA512"; - if(EmptyString(parv[1])) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD"); - return 0; - } + if(EmptyString(parv[1])) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD"); + return 0; + } - if(parc < 3) - hashtype = hashdefault; - else - hashtype = parv[2]; + if(parc < 3) + hashtype = hashdefault; + else + hashtype = parv[2]; - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD"); - return 0; - } - else - last_used = rb_current_time(); + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + /* safe enough to give this on a local connect only */ + sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD"); + return 0; + } else + last_used = rb_current_time(); - if(!irccmp(hashtype, "SHA256")) - salt = make_sha256_salt(16); - else if(!irccmp(hashtype, "SHA512")) - salt = make_sha512_salt(16); - else if(!irccmp(hashtype, "MD5")) - salt = make_md5_salt(8); - else - { - sendto_one_notice(source_p, - ":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]"); - return 0; - } + if(!irccmp(hashtype, "SHA256")) + salt = make_sha256_salt(16); + else if(!irccmp(hashtype, "SHA512")) + salt = make_sha512_salt(16); + else if(!irccmp(hashtype, "MD5")) + salt = make_md5_salt(8); + else { + sendto_one_notice(source_p, + ":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]"); + return 0; + } - sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt)); - return 0; + sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt)); + return 0; } /* mo_mkpasswd - mkpasswd message handler @@ -94,124 +90,115 @@ m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const cha static int mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *salt; - const char *hashtype; - const char hashdefault[] = "SHA512"; + char *salt; + const char *hashtype; + const char hashdefault[] = "SHA512"; - if(EmptyString(parv[1])) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD"); - return 0; - } + if(EmptyString(parv[1])) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD"); + return 0; + } - if(parc < 3) - hashtype = hashdefault; - else - hashtype = parv[2]; + if(parc < 3) + hashtype = hashdefault; + else + hashtype = parv[2]; - if(!irccmp(hashtype, "SHA256")) - salt = make_sha256_salt(16); - else if(!irccmp(hashtype, "SHA512")) - salt = make_sha512_salt(16); - else if(!irccmp(hashtype, "MD5")) - salt = make_md5_salt(8); - else - { - sendto_one_notice(source_p, - ":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]"); - return 0; - } + if(!irccmp(hashtype, "SHA256")) + salt = make_sha256_salt(16); + else if(!irccmp(hashtype, "SHA512")) + salt = make_sha512_salt(16); + else if(!irccmp(hashtype, "MD5")) + salt = make_md5_salt(8); + else { + sendto_one_notice(source_p, + ":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]"); + return 0; + } - sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt)); - return 0; + sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt)); + return 0; } char * make_md5_salt(int length) { - static char salt[21]; - if(length > 16) - { - printf("MD5 salt length too long\n"); - exit(0); - } - salt[0] = '$'; - salt[1] = '1'; - salt[2] = '$'; - generate_random_salt(&salt[3], length); - salt[length + 3] = '$'; - salt[length + 4] = '\0'; - return salt; + static char salt[21]; + if(length > 16) { + printf("MD5 salt length too long\n"); + exit(0); + } + salt[0] = '$'; + salt[1] = '1'; + salt[2] = '$'; + generate_random_salt(&salt[3], length); + salt[length + 3] = '$'; + salt[length + 4] = '\0'; + return salt; } char * make_sha256_salt(int length) { - static char salt[21]; - if(length > 16) - { - printf("SHA256 salt length too long\n"); - exit(0); - } - salt[0] = '$'; - salt[1] = '5'; - salt[2] = '$'; - generate_random_salt(&salt[3], length); - salt[length + 3] = '$'; - salt[length + 4] = '\0'; - return salt; + static char salt[21]; + if(length > 16) { + printf("SHA256 salt length too long\n"); + exit(0); + } + salt[0] = '$'; + salt[1] = '5'; + salt[2] = '$'; + generate_random_salt(&salt[3], length); + salt[length + 3] = '$'; + salt[length + 4] = '\0'; + return salt; } char * make_sha512_salt(int length) { - static char salt[21]; - if(length > 16) - { - printf("SHA512 salt length too long\n"); - exit(0); - } - salt[0] = '$'; - salt[1] = '6'; - salt[2] = '$'; - generate_random_salt(&salt[3], length); - salt[length + 3] = '$'; - salt[length + 4] = '\0'; - return salt; + static char salt[21]; + if(length > 16) { + printf("SHA512 salt length too long\n"); + exit(0); + } + salt[0] = '$'; + salt[1] = '6'; + salt[2] = '$'; + generate_random_salt(&salt[3], length); + salt[length + 3] = '$'; + salt[length + 4] = '\0'; + return salt; } char * generate_poor_salt(char *salt, int length) { - int i; - srand(time(NULL)); - for(i = 0; i < length; i++) - { - salt[i] = saltChars[rand() % 64]; - } - return (salt); + int i; + srand(time(NULL)); + for(i = 0; i < length; i++) { + salt[i] = saltChars[rand() % 64]; + } + return (salt); } char * generate_random_salt(char *salt, int length) { - char *buf; - int fd, i; - if((fd = open("/dev/random", O_RDONLY)) < 0) - { - return (generate_poor_salt(salt, length)); - } - buf = calloc(1, length); - if(read(fd, buf, length) != length) - { - free(buf); - return (generate_poor_salt(salt, length)); - } + char *buf; + int fd, i; + if((fd = open("/dev/random", O_RDONLY)) < 0) { + return (generate_poor_salt(salt, length)); + } + buf = calloc(1, length); + if(read(fd, buf, length) != length) { + free(buf); + return (generate_poor_salt(salt, length)); + } - for(i = 0; i < length; i++) - { - salt[i] = saltChars[abs(buf[i]) % 64]; - } - free(buf); - return (salt); + for(i = 0; i < length; i++) { + salt[i] = saltChars[abs(buf[i]) % 64]; + } + free(buf); + return (salt); } diff --git a/extensions/m_oaccept.c b/extensions/m_oaccept.c index 268d443..fc03425 100644 --- a/extensions/m_oaccept.c +++ b/extensions/m_oaccept.c @@ -9,9 +9,9 @@ static int mo_oaccept(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message oaccept_msgtab = { - "OACCEPT", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_oaccept, 2}} -}; + "OACCEPT", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_oaccept, 2}} +}; mapi_clist_av1 oaccept_clist[] = { &oaccept_msgtab, NULL }; @@ -20,46 +20,42 @@ DECLARE_MODULE_AV1(oaccept, NULL, NULL, oaccept_clist, NULL, NULL, "$Id $"); static int mo_oaccept(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Metadata *md; - struct DictionaryIter iter; - struct Client *target_p; - char text[10]; + struct Metadata *md; + struct DictionaryIter iter; + struct Client *target_p; + char text[10]; - if(!(target_p = find_client(parv[1]))) - { - sendto_one(source_p, form_str(ERR_NOSUCHNICK), parv[1]); - return 0; - } + if(!(target_p = find_client(parv[1]))) { + sendto_one(source_p, form_str(ERR_NOSUCHNICK), parv[1]); + return 0; + } - /* If we don't check for this, and some idiot tries to OACCEPT a server... */ - if(!IsPerson(target_p)) - { - sendto_one_notice(source_p, ":That is a server, not a user. What are you doing?"); - return 0; - } + /* If we don't check for this, and some idiot tries to OACCEPT a server... */ + if(!IsPerson(target_p)) { + sendto_one_notice(source_p, ":That is a server, not a user. What are you doing?"); + return 0; + } - rb_snprintf(text, sizeof(text), "O%s", source_p->id); + rb_snprintf(text, sizeof(text), "O%s", source_p->id); - /* Provide a nice error message if you try to OACCEPT someone - * who you've already OACCEPTed. */ - DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) - { - if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text)) - { - sendto_one_notice(source_p, ":You're already on %s's OACCEPT list", target_p->name); - return 0; - } - } + /* Provide a nice error message if you try to OACCEPT someone + * who you've already OACCEPTed. */ + DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) { + if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text)) { + sendto_one_notice(source_p, ":You're already on %s's OACCEPT list", target_p->name); + return 0; + } + } - user_metadata_add(target_p, text, "OACCEPT", 1); + user_metadata_add(target_p, text, "OACCEPT", 1); - sendto_wallops_flags(UMODE_WALLOP, &me, - "OACCEPT called for %s by %s!%s@%s", - target_p->name, - source_p->name, source_p->username, source_p->host); - sendto_server(NULL, NULL, NOCAPS, NOCAPS, - ":%s WALLOPS :OACCEPT called for %s by %s!%s@%s", - me.name, target_p->name, source_p->name, source_p->username, - source_p->host); - return 0; + sendto_wallops_flags(UMODE_WALLOP, &me, + "OACCEPT called for %s by %s!%s@%s", + target_p->name, + source_p->name, source_p->username, source_p->host); + sendto_server(NULL, NULL, NOCAPS, NOCAPS, + ":%s WALLOPS :OACCEPT called for %s by %s!%s@%s", + me.name, target_p->name, source_p->name, source_p->username, + source_p->host); + return 0; } diff --git a/extensions/m_ojoin.c b/extensions/m_ojoin.c index ce2b9da..b4b1e4c 100644 --- a/extensions/m_ojoin.c +++ b/extensions/m_ojoin.c @@ -20,17 +20,17 @@ #include "stdinc.h" #include "channel.h" -#include "client.h" +#include "client.h" #include "ircd.h" #include "numeric.h" #include "logger.h" #include "s_serv.h" #include "s_conf.h" -#include "s_newconf.h" +#include "s_newconf.h" #include "send.h" #include "whowas.h" #include "match.h" -#include "hash.h" +#include "hash.h" #include "msg.h" #include "parse.h" #include "modules.h" @@ -39,8 +39,8 @@ static int mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, struct Message ojoin_msgtab = { - "OJOIN", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_ojoin, 2}} + "OJOIN", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_ojoin, 2}} }; mapi_clist_av1 ojoin_clist[] = { &ojoin_msgtab, NULL }; @@ -54,133 +54,117 @@ DECLARE_MODULE_AV1(ojoin, NULL, NULL, ojoin_clist, NULL, NULL, "$Revision: 3554 static int mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; - int move_me = 0; + struct Channel *chptr; + int move_me = 0; - /* admins only */ - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); - return 0; - } + /* admins only */ + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); + return 0; + } - if(*parv[1] == '@' || *parv[1] == '%' || *parv[1] == '+' || *parv[1] == '!' || *parv[1] == '~') - { - parv[1]++; - move_me = 1; - } + if(*parv[1] == '@' || *parv[1] == '%' || *parv[1] == '+' || *parv[1] == '!' || *parv[1] == '~') { + parv[1]++; + move_me = 1; + } - if((chptr = find_channel(parv[1])) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[1]); - return 0; - } + if((chptr = find_channel(parv[1])) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[1]); + return 0; + } - if(IsMember(source_p, chptr)) - { - sendto_one_notice(source_p, ":Please part %s before using OJOIN", parv[1]); - return 0; - } + if(IsMember(source_p, chptr)) { + sendto_one_notice(source_p, ":Please part %s before using OJOIN", parv[1]); + return 0; + } - if(move_me == 1) - parv[1]--; + if(move_me == 1) + parv[1]--; - sendto_wallops_flags(UMODE_WALLOP, &me, - "OJOIN called for %s by %s!%s@%s", - parv[1], source_p->name, source_p->username, source_p->host); - ilog(L_MAIN, "OJOIN called for %s by %s", - parv[1], get_oper_name(source_p)); - /* only sends stuff for #channels remotely */ - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :OJOIN called for %s by %s!%s@%s", - me.name, parv[1], - source_p->name, source_p->username, source_p->host); + sendto_wallops_flags(UMODE_WALLOP, &me, + "OJOIN called for %s by %s!%s@%s", + parv[1], source_p->name, source_p->username, source_p->host); + ilog(L_MAIN, "OJOIN called for %s by %s", + parv[1], get_oper_name(source_p)); + /* only sends stuff for #channels remotely */ + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :OJOIN called for %s by %s!%s@%s", + me.name, parv[1], + source_p->name, source_p->username, source_p->host); - if(*parv[1] == '~' && ConfigChannel.use_owner) - { - add_user_to_channel(chptr, source_p, CHFL_OWNER); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s + :~%s", - me.id, (long) chptr->channelts, chptr->chname, source_p->id); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +y %s", - me.name, chptr->chname, source_p->name); - } - else if(*parv[1] == '!' && ConfigChannel.use_admin) - { - add_user_to_channel(chptr, source_p, CHFL_ADMIN); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s + :!%s", - me.id, (long) chptr->channelts, chptr->chname, source_p->id); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s", - me.name, chptr->chname, source_p->name); + if(*parv[1] == '~' && ConfigChannel.use_owner) { + add_user_to_channel(chptr, source_p, CHFL_OWNER); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s + :~%s", + me.id, (long) chptr->channelts, chptr->chname, source_p->id); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +y %s", + me.name, chptr->chname, source_p->name); + } else if(*parv[1] == '!' && ConfigChannel.use_admin) { + add_user_to_channel(chptr, source_p, CHFL_ADMIN); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s + :!%s", + me.id, (long) chptr->channelts, chptr->chname, source_p->id); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s", + me.name, chptr->chname, source_p->name); - } - else if(*parv[1] == '@') - { - add_user_to_channel(chptr, source_p, CHFL_CHANOP); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s + :@%s", - me.id, (long) chptr->channelts, chptr->chname, source_p->id); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s", - me.name, chptr->chname, source_p->name); + } else if(*parv[1] == '@') { + add_user_to_channel(chptr, source_p, CHFL_CHANOP); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s + :@%s", + me.id, (long) chptr->channelts, chptr->chname, source_p->id); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s", + me.name, chptr->chname, source_p->name); - } - else if(*parv[1] == '%' && ConfigChannel.use_halfop) - { - add_user_to_channel(chptr, source_p, CHFL_HALFOP); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s + :%s%s", - me.id, (long) chptr->channelts, chptr->chname, "%", source_p->id); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s", - me.name, chptr->chname, source_p->name); - } - else if(*parv[1] == '+') - { - add_user_to_channel(chptr, source_p, CHFL_VOICE); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s + :+%s", - me.id, (long) chptr->channelts, chptr->chname, source_p->id); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +v %s", - me.name, chptr->chname, source_p->name); - } - else - { - add_user_to_channel(chptr, source_p, CHFL_PEON); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s JOIN %ld %s +", - source_p->id, (long) chptr->channelts, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - } + } else if(*parv[1] == '%' && ConfigChannel.use_halfop) { + add_user_to_channel(chptr, source_p, CHFL_HALFOP); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s + :%s%s", + me.id, (long) chptr->channelts, chptr->chname, "%", source_p->id); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s", + me.name, chptr->chname, source_p->name); + } else if(*parv[1] == '+') { + add_user_to_channel(chptr, source_p, CHFL_VOICE); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s + :+%s", + me.id, (long) chptr->channelts, chptr->chname, source_p->id); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +v %s", + me.name, chptr->chname, source_p->name); + } else { + add_user_to_channel(chptr, source_p, CHFL_PEON); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s JOIN %ld %s +", + source_p->id, (long) chptr->channelts, chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + } - /* send the topic... */ - if(chptr->topic != NULL) - { - sendto_one(source_p, form_str(RPL_TOPIC), me.name, - source_p->name, chptr->chname, chptr->topic); - sendto_one(source_p, form_str(RPL_TOPICWHOTIME), me.name, - source_p->name, chptr->chname, chptr->topic_info, chptr->topic_time); - } + /* send the topic... */ + if(chptr->topic != NULL) { + sendto_one(source_p, form_str(RPL_TOPIC), me.name, + source_p->name, chptr->chname, chptr->topic); + sendto_one(source_p, form_str(RPL_TOPICWHOTIME), me.name, + source_p->name, chptr->chname, chptr->topic_info, chptr->topic_time); + } - source_p->localClient->last_join_time = rb_current_time(); - channel_member_names(chptr, source_p, 1); + source_p->localClient->last_join_time = rb_current_time(); + channel_member_names(chptr, source_p, 1); - return 0; + return 0; } diff --git a/extensions/m_okick.c b/extensions/m_okick.c index bf1ea2c..6ac3cda 100644 --- a/extensions/m_okick.c +++ b/extensions/m_okick.c @@ -41,8 +41,8 @@ static int mo_okick(struct Client *client_p, struct Client *source_p, int parc, struct Message okick_msgtab = { - "OKICK", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_okick, 4}} + "OKICK", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_okick, 4}} }; mapi_clist_av1 okick_clist[] = { &okick_msgtab, NULL }; @@ -58,89 +58,84 @@ DECLARE_MODULE_AV1(okick, NULL, NULL, okick_clist, NULL, NULL, "$Revision: 3554 static int mo_okick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *who; - struct Client *target_p; - struct Channel *chptr; - struct membership *msptr; - int chasing = 0; - char *comment; - char *name; - char *p = NULL; - char *user; - char text[10]; - static char buf[BUFSIZE]; + struct Client *who; + struct Client *target_p; + struct Channel *chptr; + struct membership *msptr; + int chasing = 0; + char *comment; + char *name; + char *p = NULL; + char *user; + char text[10]; + static char buf[BUFSIZE]; - if(*parv[2] == '\0') - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "KICK"); - return 0; - } + if(*parv[2] == '\0') { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "KICK"); + return 0; + } - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - comment = (EmptyString(LOCAL_COPY(parv[3]))) ? LOCAL_COPY(parv[2]) : LOCAL_COPY(parv[3]); - if(strlen(comment) > (size_t) TOPICLEN) - comment[TOPICLEN] = '\0'; + comment = (EmptyString(LOCAL_COPY(parv[3]))) ? LOCAL_COPY(parv[2]) : LOCAL_COPY(parv[3]); + if(strlen(comment) > (size_t) TOPICLEN) + comment[TOPICLEN] = '\0'; - *buf = '\0'; - if((p = strchr(parv[1], ','))) - *p = '\0'; + *buf = '\0'; + if((p = strchr(parv[1], ','))) + *p = '\0'; - name = LOCAL_COPY(parv[1]); + name = LOCAL_COPY(parv[1]); - chptr = find_channel(name); - if(!chptr) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + chptr = find_channel(name); + if(!chptr) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - if((p = strchr(parv[2], ','))) - *p = '\0'; - user = LOCAL_COPY(parv[2]); // strtoken(&p2, parv[2], ","); - if(!(who = find_chasing(source_p, user, &chasing))) - { - return 0; - } + if((p = strchr(parv[2], ','))) + *p = '\0'; + user = LOCAL_COPY(parv[2]); // strtoken(&p2, parv[2], ","); + if(!(who = find_chasing(source_p, user, &chasing))) { + return 0; + } - if((target_p = find_client(user)) == NULL) - { - sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, user); - return 0; - } + if((target_p = find_client(user)) == NULL) { + sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, user); + return 0; + } - if((msptr = find_channel_membership(chptr, target_p)) == NULL) - { - sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), - me.name, source_p->name, parv[1], parv[2]); - return 0; - } + if((msptr = find_channel_membership(chptr, target_p)) == NULL) { + sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), + me.name, source_p->name, parv[1], parv[2]); + return 0; + } - sendto_wallops_flags(UMODE_WALLOP, &me, - "OKICK called for %s %s by %s!%s@%s", - chptr->chname, target_p->name, - source_p->name, source_p->username, source_p->host); - ilog(L_MAIN, "OKICK called for %s %s by %s", - chptr->chname, target_p->name, - get_oper_name(source_p)); - /* only sends stuff for #channels remotely */ - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :OKICK called for %s %s by %s!%s@%s", - me.name, chptr->chname, target_p->name, - source_p->name, source_p->username, source_p->host); + sendto_wallops_flags(UMODE_WALLOP, &me, + "OKICK called for %s %s by %s!%s@%s", + chptr->chname, target_p->name, + source_p->name, source_p->username, source_p->host); + ilog(L_MAIN, "OKICK called for %s %s by %s", + chptr->chname, target_p->name, + get_oper_name(source_p)); + /* only sends stuff for #channels remotely */ + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :OKICK called for %s %s by %s!%s@%s", + me.name, chptr->chname, target_p->name, + source_p->name, source_p->username, source_p->host); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s", - me.name, chptr->chname, who->name, comment); - sendto_server(&me, chptr, CAP_TS6, NOCAPS, - ":%s KICK %s %s :%s", me.id, chptr->chname, who->id, comment); - remove_user_from_channel(msptr); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s", + me.name, chptr->chname, who->name, comment); + sendto_server(&me, chptr, CAP_TS6, NOCAPS, + ":%s KICK %s %s :%s", me.id, chptr->chname, who->id, comment); + remove_user_from_channel(msptr); - rb_snprintf(text, sizeof(text), "K%s", who->id); + rb_snprintf(text, sizeof(text), "K%s", who->id); - /* we don't need to track NOREJOIN stuff unless it's our client being kicked */ - if(MyClient(who) && chptr->mode.mode & MODE_NOREJOIN) - channel_metadata_time_add(chptr, text, rb_current_time(), "KICKNOREJOIN"); - return 0; + /* we don't need to track NOREJOIN stuff unless it's our client being kicked */ + if(MyClient(who) && chptr->mode.mode & MODE_NOREJOIN) + channel_metadata_time_add(chptr, text, rb_current_time(), "KICKNOREJOIN"); + return 0; } diff --git a/extensions/m_olist.c b/extensions/m_olist.c index 65a81da..472dcb1 100644 --- a/extensions/m_olist.c +++ b/extensions/m_olist.c @@ -46,8 +46,8 @@ static int mo_olist(struct Client *, struct Client *, int parc, const char *parv #ifndef STATIC_MODULES struct Message olist_msgtab = { - "OLIST", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_olist, 1}} + "OLIST", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_olist, 1}} }; mapi_clist_av1 olist_clist[] = { &olist_msgtab, NULL }; @@ -66,23 +66,22 @@ static void list_named_channel(struct Client *source_p, const char *name); static int mo_olist(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(!IsOperSpy(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "oper_spy"); - sendto_one(source_p, form_str(RPL_LISTEND), - me.name, source_p->name); - return 0; - } + if(!IsOperSpy(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "oper_spy"); + sendto_one(source_p, form_str(RPL_LISTEND), + me.name, source_p->name); + return 0; + } - /* If no arg, do all channels *whee*, else just one channel */ - if(parc < 2 || EmptyString(parv[1])) - list_all_channels(source_p); - else - list_named_channel(source_p, parv[1]); + /* If no arg, do all channels *whee*, else just one channel */ + if(parc < 2 || EmptyString(parv[1])) + list_all_channels(source_p); + else + list_named_channel(source_p, parv[1]); - sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); - return 0; + sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); + return 0; } @@ -95,24 +94,23 @@ mo_olist(struct Client *client_p, struct Client *source_p, int parc, const char static void list_all_channels(struct Client *source_p) { - struct Channel *chptr; - rb_dlink_node *ptr; + struct Channel *chptr; + rb_dlink_node *ptr; - report_operspy(source_p, "LIST", NULL); - sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); + report_operspy(source_p, "LIST", NULL); + sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); - RB_DLINK_FOREACH(ptr, global_channel_list.head) - { - chptr = ptr->data; + RB_DLINK_FOREACH(ptr, global_channel_list.head) { + chptr = ptr->data; - sendto_one(source_p, ":%s 322 %s %s %lu :[%s] %s", - me.name, source_p->name, chptr->chname, - rb_dlink_list_length(&chptr->members), - channel_modes(chptr, &me), - chptr->topic == NULL ? "" : chptr->topic); - } + sendto_one(source_p, ":%s 322 %s %s %lu :[%s] %s", + me.name, source_p->name, chptr->chname, + rb_dlink_list_length(&chptr->members), + channel_modes(chptr, &me), + chptr->topic == NULL ? "" : chptr->topic); + } - return; + return; } /* @@ -124,28 +122,28 @@ list_all_channels(struct Client *source_p) static void list_named_channel(struct Client *source_p, const char *name) { - struct Channel *chptr; - char *p; - char *n = LOCAL_COPY(name); + struct Channel *chptr; + char *p; + char *n = LOCAL_COPY(name); - if((p = strchr(n, ','))) - *p = '\0'; + if((p = strchr(n, ','))) + *p = '\0'; - /* Put operspy notice before any output, but only if channel exists */ - chptr = EmptyString(n) ? NULL : find_channel(n); - if(chptr != NULL) - report_operspy(source_p, "LIST", chptr->chname); + /* Put operspy notice before any output, but only if channel exists */ + chptr = EmptyString(n) ? NULL : find_channel(n); + if(chptr != NULL) + report_operspy(source_p, "LIST", chptr->chname); - sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); + sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); - if(EmptyString(n)) - return; + if(EmptyString(n)) + return; - if(chptr == NULL) - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), n); - else - sendto_one(source_p, ":%s 322 %s %s %lu :[%s] %s", me.name, source_p->name, - chptr->chname, rb_dlink_list_length(&chptr->members), - channel_modes(chptr, &me), chptr->topic ? chptr->topic : ""); + if(chptr == NULL) + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), n); + else + sendto_one(source_p, ":%s 322 %s %s %lu :[%s] %s", me.name, source_p->name, + chptr->chname, rb_dlink_list_length(&chptr->members), + channel_modes(chptr, &me), chptr->topic ? chptr->topic : ""); } diff --git a/extensions/m_omode.c b/extensions/m_omode.c index 084208e..18e3427 100644 --- a/extensions/m_omode.c +++ b/extensions/m_omode.c @@ -44,8 +44,8 @@ static int mo_omode(struct Client *, struct Client *, int, const char **); struct Message omode_msgtab = { - "OMODE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_omode, 3}} + "OMODE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_omode, 3}} }; mapi_clist_av1 omode_clist[] = { &omode_msgtab, NULL }; @@ -59,199 +59,174 @@ DECLARE_MODULE_AV1(omode, NULL, NULL, omode_clist, NULL, NULL, "$Revision: 3121 static int mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr = NULL; - struct membership *msptr; - char params[512]; - int i; - int wasonchannel; + struct Channel *chptr = NULL; + struct membership *msptr; + char params[512]; + int i; + int wasonchannel; - /* admins only */ - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); - return 0; - } + /* admins only */ + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); + return 0; + } - /* Now, try to find the channel in question */ - if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1])) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), parv[1]); - return 0; - } + /* Now, try to find the channel in question */ + if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1])) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), parv[1]); + return 0; + } - chptr = find_channel(parv[1]); + chptr = find_channel(parv[1]); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[1]); - return 0; - } + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[1]); + return 0; + } - /* Now know the channel exists */ - msptr = find_channel_membership(chptr, source_p); - wasonchannel = msptr != NULL; + /* Now know the channel exists */ + msptr = find_channel_membership(chptr, source_p); + wasonchannel = msptr != NULL; - if (is_any_op(msptr)) - { - sendto_one_notice(source_p, ":Use a normal MODE you idiot"); - return 0; - } + if (is_any_op(msptr)) { + sendto_one_notice(source_p, ":Use a normal MODE you idiot"); + return 0; + } - params[0] = '\0'; - for (i = 2; i < parc; i++) - { - if (i != 2) - rb_strlcat(params, " ", sizeof params); - rb_strlcat(params, parv[i], sizeof params); - } + params[0] = '\0'; + for (i = 2; i < parc; i++) { + if (i != 2) + rb_strlcat(params, " ", sizeof params); + rb_strlcat(params, parv[i], sizeof params); + } - sendto_wallops_flags(UMODE_WALLOP, &me, - "OMODE called for [%s] [%s] by %s!%s@%s", - parv[1], params, source_p->name, source_p->username, source_p->host); - ilog(L_MAIN, "OMODE called for [%s] [%s] by %s", - parv[1], params, get_oper_name(source_p)); + sendto_wallops_flags(UMODE_WALLOP, &me, + "OMODE called for [%s] [%s] by %s!%s@%s", + parv[1], params, source_p->name, source_p->username, source_p->host); + ilog(L_MAIN, "OMODE called for [%s] [%s] by %s", + parv[1], params, get_oper_name(source_p)); - if(*chptr->chname != '&') - sendto_server(NULL, NULL, NOCAPS, NOCAPS, - ":%s WALLOPS :OMODE called for [%s] [%s] by %s!%s@%s", - me.name, parv[1], params, source_p->name, source_p->username, - source_p->host); + if(*chptr->chname != '&') + sendto_server(NULL, NULL, NOCAPS, NOCAPS, + ":%s WALLOPS :OMODE called for [%s] [%s] by %s!%s@%s", + me.name, parv[1], params, source_p->name, source_p->username, + source_p->host); #if 0 - set_channel_mode(client_p, source_p->servptr, chptr, msptr, - parc - 2, parv + 2); + set_channel_mode(client_p, source_p->servptr, chptr, msptr, + parc - 2, parv + 2); #else - if (parc == 4 && !strcmp(parv[2], "+y") && !irccmp(parv[3], source_p->name)) - { - /* Ownering themselves */ - if (!wasonchannel) - { - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); - return 0; - } - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +y %s", - me.name, parv[1], source_p->name); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, - ":%s TMODE %ld %s +y %s", - me.id, (long) chptr->channelts, parv[1], - source_p->id); - msptr->flags |= CHFL_OWNER; + if (parc == 4 && !strcmp(parv[2], "+y") && !irccmp(parv[3], source_p->name)) { + /* Ownering themselves */ + if (!wasonchannel) { + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); + return 0; } - else if (parc == 4 && !strcmp(parv[2], "+a") && !irccmp(parv[3], source_p->name)) - { - /* Admining themselves */ - if (!wasonchannel) - { - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); - return 0; - } - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s", - me.name, parv[1], source_p->name); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, - ":%s TMODE %ld %s +a %s", - me.id, (long) chptr->channelts, parv[1], - source_p->id); - msptr->flags |= CHFL_ADMIN; - } - else if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name)) - { - /* Opping themselves */ - if (!wasonchannel) - { - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); - return 0; - } - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s", - me.name, parv[1], source_p->name); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, - ":%s TMODE %ld %s +o %s", - me.id, (long) chptr->channelts, parv[1], - source_p->id); - msptr->flags |= CHFL_CHANOP; - } - else if (parc == 4 && !strcmp(parv[2], "+h") && !irccmp(parv[3], source_p->name)) - { - /* Halfopping themselves */ - if (!wasonchannel) - { - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); - return 0; - } - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s", - me.name, parv[1], source_p->name); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, - ":%s TMODE %ld %s +h %s", - me.id, (long) chptr->channelts, parv[1], - source_p->id); - msptr->flags |= CHFL_HALFOP; - } - else if (ConfigChannel.use_owner) - { - /* I hope this is correct. - * -- Kabaka */ + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +y %s", + me.name, parv[1], source_p->name); + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, + ":%s TMODE %ld %s +y %s", + me.id, (long) chptr->channelts, parv[1], + source_p->id); + msptr->flags |= CHFL_OWNER; + } else if (parc == 4 && !strcmp(parv[2], "+a") && !irccmp(parv[3], source_p->name)) { + /* Admining themselves */ + if (!wasonchannel) { + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); + return 0; + } + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s", + me.name, parv[1], source_p->name); + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, + ":%s TMODE %ld %s +a %s", + me.id, (long) chptr->channelts, parv[1], + source_p->id); + msptr->flags |= CHFL_ADMIN; + } else if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name)) { + /* Opping themselves */ + if (!wasonchannel) { + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); + return 0; + } + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s", + me.name, parv[1], source_p->name); + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, + ":%s TMODE %ld %s +o %s", + me.id, (long) chptr->channelts, parv[1], + source_p->id); + msptr->flags |= CHFL_CHANOP; + } else if (parc == 4 && !strcmp(parv[2], "+h") && !irccmp(parv[3], source_p->name)) { + /* Halfopping themselves */ + if (!wasonchannel) { + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); + return 0; + } + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s", + me.name, parv[1], source_p->name); + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, + ":%s TMODE %ld %s +h %s", + me.id, (long) chptr->channelts, parv[1], + source_p->id); + msptr->flags |= CHFL_HALFOP; + } else if (ConfigChannel.use_owner) { + /* I hope this is correct. + * -- Kabaka */ - /* Hack it so set_channel_mode() will accept */ - if (wasonchannel) - msptr->flags |= CHFL_OWNER; - else - { - add_user_to_channel(chptr, source_p, CHFL_CHANOP); - msptr = find_channel_membership(chptr, source_p); - } - set_channel_mode(client_p, source_p, chptr, msptr, - parc - 2, parv + 2); - if (wasonchannel) - msptr->flags &= ~CHFL_OWNER; - else - remove_user_from_channel(msptr); + /* Hack it so set_channel_mode() will accept */ + if (wasonchannel) + msptr->flags |= CHFL_OWNER; + else { + add_user_to_channel(chptr, source_p, CHFL_CHANOP); + msptr = find_channel_membership(chptr, source_p); } - else if (ConfigChannel.use_admin) - { - /* Hack it so set_channel_mode() will accept */ - if (wasonchannel) - msptr->flags |= CHFL_ADMIN; - else - { - add_user_to_channel(chptr, source_p, CHFL_CHANOP); - msptr = find_channel_membership(chptr, source_p); - } - set_channel_mode(client_p, source_p, chptr, msptr, - parc - 2, parv + 2); - /* We know they were not opped before and they can't have opped - * themselves as set_channel_mode() does not allow that - * -- jilles */ - if (wasonchannel) - msptr->flags &= ~CHFL_ADMIN; - else - remove_user_from_channel(msptr); - } - else - { - /* CHFL_ADMIN is only useful if admin is enabled - * so hack it with op if it is not. */ - if (wasonchannel) - msptr->flags |= CHFL_CHANOP; - else - { - add_user_to_channel(chptr, source_p, CHFL_CHANOP); - msptr = find_channel_membership(chptr, source_p); - } - set_channel_mode(client_p, source_p, chptr, msptr, - parc - 2, parv + 2); - /* We know they were not opped before and they can't have opped - * themselves as set_channel_mode() does not allow that - * -- jilles */ - if (wasonchannel) - msptr->flags &= ~CHFL_CHANOP; - else - remove_user_from_channel(msptr); - } + set_channel_mode(client_p, source_p, chptr, msptr, + parc - 2, parv + 2); + if (wasonchannel) + msptr->flags &= ~CHFL_OWNER; + else + remove_user_from_channel(msptr); + } else if (ConfigChannel.use_admin) { + /* Hack it so set_channel_mode() will accept */ + if (wasonchannel) + msptr->flags |= CHFL_ADMIN; + else { + add_user_to_channel(chptr, source_p, CHFL_CHANOP); + msptr = find_channel_membership(chptr, source_p); + } + set_channel_mode(client_p, source_p, chptr, msptr, + parc - 2, parv + 2); + /* We know they were not opped before and they can't have opped + * themselves as set_channel_mode() does not allow that + * -- jilles */ + if (wasonchannel) + msptr->flags &= ~CHFL_ADMIN; + else + remove_user_from_channel(msptr); + } else { + /* CHFL_ADMIN is only useful if admin is enabled + * so hack it with op if it is not. */ + if (wasonchannel) + msptr->flags |= CHFL_CHANOP; + else { + add_user_to_channel(chptr, source_p, CHFL_CHANOP); + msptr = find_channel_membership(chptr, source_p); + } + set_channel_mode(client_p, source_p, chptr, msptr, + parc - 2, parv + 2); + /* We know they were not opped before and they can't have opped + * themselves as set_channel_mode() does not allow that + * -- jilles */ + if (wasonchannel) + msptr->flags &= ~CHFL_CHANOP; + else + remove_user_from_channel(msptr); + } #endif - return 0; + return 0; } diff --git a/extensions/m_opme.c b/extensions/m_opme.c index 87d6cc8..9ac9fbd 100644 --- a/extensions/m_opme.c +++ b/extensions/m_opme.c @@ -37,8 +37,8 @@ static int mo_opme(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message opme_msgtab = { - "OPME", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_opme, 2}} + "OPME", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_opme, 2}} }; mapi_clist_av1 opme_clist[] = { &opme_msgtab, NULL }; @@ -53,62 +53,57 @@ DECLARE_MODULE_AV1(opme, NULL, NULL, opme_clist, NULL, NULL, "$Revision: 3554 $" static int mo_opme(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; - struct membership *msptr; - rb_dlink_node *ptr; + struct Channel *chptr; + struct membership *msptr; + rb_dlink_node *ptr; - /* admins only */ - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); - return 0; - } + /* admins only */ + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); + return 0; + } - if((chptr = find_channel(parv[1])) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[1]); - return 0; - } + if((chptr = find_channel(parv[1])) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[1]); + return 0; + } - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; - if(is_chanop(msptr) || is_admin(msptr) || is_owner(msptr)) - { - sendto_one_notice(source_p, ":%s Channel is not opless", parv[1]); - return 0; - } - } + if(is_chanop(msptr) || is_admin(msptr) || is_owner(msptr)) { + sendto_one_notice(source_p, ":%s Channel is not opless", parv[1]); + return 0; + } + } - msptr = find_channel_membership(chptr, source_p); + msptr = find_channel_membership(chptr, source_p); - if(msptr == NULL) - return 0; + if(msptr == NULL) + return 0; - msptr->flags |= CHFL_CHANOP; + msptr->flags |= CHFL_CHANOP; - sendto_wallops_flags(UMODE_WALLOP, &me, - "OPME called for [%s] by %s!%s@%s", - parv[1], source_p->name, source_p->username, source_p->host); - ilog(L_MAIN, "OPME called for [%s] by %s", - parv[1], get_oper_name(source_p)); + sendto_wallops_flags(UMODE_WALLOP, &me, + "OPME called for [%s] by %s!%s@%s", + parv[1], source_p->name, source_p->username, source_p->host); + ilog(L_MAIN, "OPME called for [%s] by %s", + parv[1], get_oper_name(source_p)); - /* dont send stuff for local channels remotely. */ - if(*chptr->chname != '&') - { - sendto_server(NULL, NULL, NOCAPS, NOCAPS, - ":%s WALLOPS :OPME called for [%s] by %s!%s@%s", - me.name, parv[1], source_p->name, source_p->username, source_p->host); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, ":%s PART %s", source_p->id, parv[1]); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s + :@%s", - me.id, (long) chptr->channelts, parv[1], source_p->id); - } + /* dont send stuff for local channels remotely. */ + if(*chptr->chname != '&') { + sendto_server(NULL, NULL, NOCAPS, NOCAPS, + ":%s WALLOPS :OPME called for [%s] by %s!%s@%s", + me.name, parv[1], source_p->name, source_p->username, source_p->host); + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, ":%s PART %s", source_p->id, parv[1]); + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s + :@%s", + me.id, (long) chptr->channelts, parv[1], source_p->id); + } - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s +o %s", me.name, parv[1], source_p->name); + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s +o %s", me.name, parv[1], source_p->name); - return 0; + return 0; } diff --git a/extensions/m_roleplay.c b/extensions/m_roleplay.c index 45148e0..305388d 100644 --- a/extensions/m_roleplay.c +++ b/extensions/m_roleplay.c @@ -6,9 +6,9 @@ * to clearly show that it is fake. SCENE is a special case and not underlined. * these commands only work on channels set +N * - * also adds oper commands FSAY and FACTION, which are like NPC and NPCA + * also adds oper commands FSAY and FACTION, which are like NPC and NPCA * except without the underline. - * + * * all of these messages have the hostmask npc.fakeuser.invalid, and their ident * is the nickname of the user running the commands. */ @@ -39,57 +39,57 @@ static unsigned int mymode; static int _modinit(void) { - /* initalize the +N cmode */ - mymode = cflag_add('N', chm_simple); - if (mymode == 0) - return -1; + /* initalize the +N cmode */ + mymode = cflag_add('N', chm_simple); + if (mymode == 0) + return -1; - return 0; + return 0; } static void _moddeinit(void) { - /* orphan the +N cmode on modunload */ - cflag_orphan('N'); + /* orphan the +N cmode on modunload */ + cflag_orphan('N'); } struct Message scene_msgtab = { - "SCENE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}} + "SCENE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}} }; /* this serves as an alias for people who are used to inspircd/unreal m_roleplay */ struct Message ambiance_msgtab = { - "AMBIANCE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}} -}; + "AMBIANCE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}} +}; struct Message fsay_msgtab = { - "FSAY", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}} -}; + "FSAY", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}} +}; struct Message faction_msgtab = { - "FACTION", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}} -}; + "FACTION", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}} +}; struct Message npc_msgtab = { - "NPC", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}} -}; + "NPC", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}} +}; struct Message npca_msgtab = { - "NPCA", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}} -}; + "NPCA", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}} +}; struct Message roleplay_msgtab = { - "ROLEPLAY", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 4}, mg_ignore} -}; + "ROLEPLAY", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 4}, mg_ignore} +}; mapi_clist_av1 roleplay_clist[] = { &scene_msgtab, &ambiance_msgtab, &fsay_msgtab, &faction_msgtab, &npc_msgtab, &npca_msgtab, &roleplay_msgtab, NULL }; @@ -98,118 +98,112 @@ DECLARE_MODULE_AV1(roleplay, _modinit, _moddeinit, roleplay_clist, NULL, NULL, " static int m_scene(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - m_displaymsg(source_p, parv[1], 0, 0, "=Scene=", parv[2]); - return 0; + m_displaymsg(source_p, parv[1], 0, 0, "=Scene=", parv[2]); + return 0; } static int m_fsay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - m_displaymsg(source_p, parv[1], 0, 0, parv[2], parv[3]); - return 0; + m_displaymsg(source_p, parv[1], 0, 0, parv[2], parv[3]); + return 0; } static int m_faction(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - m_displaymsg(source_p, parv[1], 0, 1, parv[2], parv[3]); - return 0; + m_displaymsg(source_p, parv[1], 0, 1, parv[2], parv[3]); + return 0; } static int m_npc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - m_displaymsg(source_p, parv[1], 1, 0, parv[2], parv[3]); - return 0; + m_displaymsg(source_p, parv[1], 1, 0, parv[2], parv[3]); + return 0; } static int m_npca(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - m_displaymsg(source_p, parv[1], 1, 1, parv[2], parv[3]); - return 0; + m_displaymsg(source_p, parv[1], 1, 1, parv[2], parv[3]); + return 0; } static int m_displaymsg(struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text) { - struct Channel *chptr; - struct membership *msptr; - char nick2[NICKLEN+1]; - char *nick3 = rb_strdup(nick); - char text2[BUFSIZE]; + struct Channel *chptr; + struct membership *msptr; + char nick2[NICKLEN+1]; + char *nick3 = rb_strdup(nick); + char text2[BUFSIZE]; - if((chptr = find_channel(channel)) == NULL) - { - sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), channel); - return 0; - } + if((chptr = find_channel(channel)) == NULL) { + sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), channel); + return 0; + } - if(!(msptr = find_channel_membership(chptr, source_p))) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), chptr->chname); - return 0; - } + if(!(msptr = find_channel_membership(chptr, source_p))) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), chptr->chname); + return 0; + } - if(!(chptr->mode.mode & chmode_flags['N'])) - { - sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname); - return 0; - } + if(!(chptr->mode.mode & chmode_flags['N'])) { + sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname); + return 0; + } - if(!can_send(chptr, source_p, msptr)) - { - sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname); - return 0; - } + if(!can_send(chptr, source_p, msptr)) { + sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname); + return 0; + } - /* enforce flood stuff on roleplay commands */ - if(flood_attack_channel(0, source_p, chptr, chptr->chname)) - return 0; + /* enforce flood stuff on roleplay commands */ + if(flood_attack_channel(0, source_p, chptr, chptr->chname)) + return 0; - /* enforce target change on roleplay commands */ - if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr)) - { - sendto_one(source_p, form_str(ERR_TARGCHANGE), - me.name, source_p->name, chptr->chname); - return 0; - } + /* enforce target change on roleplay commands */ + if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr)) { + sendto_one(source_p, form_str(ERR_TARGCHANGE), + me.name, source_p->name, chptr->chname); + return 0; + } - if(underline) - rb_snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3)); - else - rb_snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3)); + if(underline) + rb_snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3)); + else + rb_snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3)); - /* don't allow nicks to be empty after stripping - * this prevents nastiness like fake factions, etc. */ - if(EmptyString(nick3)) - { - sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname); - return 0; - } + /* don't allow nicks to be empty after stripping + * this prevents nastiness like fake factions, etc. */ + if(EmptyString(nick3)) { + sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname); + return 0; + } - if(action) - rb_snprintf(text2, sizeof(text2), "\1ACTION %s\1", text); - else - rb_snprintf(text2, sizeof(text2), "%s", text); + if(action) + rb_snprintf(text2, sizeof(text2), "\1ACTION %s\1", text); + else + rb_snprintf(text2, sizeof(text2), "%s", text); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s (%s)", nick2, source_p->name, channel, text2, source_p->name); - sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s :%s", - channel, nick2, text2); - return 0; + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s (%s)", nick2, source_p->name, channel, text2, source_p->name); + sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s :%s", + channel, nick2, text2); + return 0; } static int me_roleplay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; + struct Channel *chptr; - /* Don't segfault if we get ROLEPLAY with an invalid channel. - * This shouldn't happen but it's best to be on the safe side. */ - if((chptr = find_channel(parv[1])) == NULL) - return 0; + /* Don't segfault if we get ROLEPLAY with an invalid channel. + * This shouldn't happen but it's best to be on the safe side. */ + if((chptr = find_channel(parv[1])) == NULL) + return 0; - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s (%s)", parv[2], source_p->name, parv[1], parv[3], source_p->name); - return 0; + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s (%s)", parv[2], source_p->name, parv[1], parv[3], source_p->name); + return 0; } diff --git a/extensions/m_sendbans.c b/extensions/m_sendbans.c index a623cf1..22ab31f 100644 --- a/extensions/m_sendbans.c +++ b/extensions/m_sendbans.c @@ -46,130 +46,120 @@ static int mo_sendbans(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message sendbans_msgtab = { - "SENDBANS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_sendbans, 2}} + "SENDBANS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_sendbans, 2}} }; mapi_clist_av1 sendbans_clist[] = { - &sendbans_msgtab, - NULL + &sendbans_msgtab, + NULL }; DECLARE_MODULE_AV1(sendbans, NULL, NULL, sendbans_clist, NULL, NULL, "$Revision$"); static const char *expand_xline(const char *mask) { - static char buf[512]; - const char *p; - char *q; + static char buf[512]; + const char *p; + char *q; - if (!strchr(mask, ' ')) - return mask; - if (strlen(mask) > 250) - return NULL; - p = mask; - q = buf; - while (*p != '\0') - { - if (*p == ' ') - *q++ = '\\', *q++ = 's'; - else - *q++ = *p; - p++; - } - *q = '\0'; - return buf; + if (!strchr(mask, ' ')) + return mask; + if (strlen(mask) > 250) + return NULL; + p = mask; + q = buf; + while (*p != '\0') { + if (*p == ' ') + *q++ = '\\', *q++ = 's'; + else + *q++ = *p; + p++; + } + *q = '\0'; + return buf; } static int mo_sendbans(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - int i, count; - const char *target, *mask2; - struct Client *server_p; + struct ConfItem *aconf; + rb_dlink_node *ptr; + int i, count; + const char *target, *mask2; + struct Client *server_p; - if (!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } - if (!IsOperXline(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "xline"); - return 0; - } - if (!IsOperResv(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "resv"); - return 0; - } + if (!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } + if (!IsOperXline(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "xline"); + return 0; + } + if (!IsOperResv(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "resv"); + return 0; + } - target = parv[1]; - count = 0; - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - server_p = ptr->data; - if (IsMe(server_p)) - continue; - if (match(target, server_p->name)) - count++; - } - if (count == 0) - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), target); - return 0; - } + target = parv[1]; + count = 0; + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + server_p = ptr->data; + if (IsMe(server_p)) + continue; + if (match(target, server_p->name)) + count++; + } + if (count == 0) { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), target); + return 0; + } - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "%s!%s@%s is sending resvs and xlines to %s", - source_p->name, source_p->username, source_p->host, - target); + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "%s!%s@%s is sending resvs and xlines to %s", + source_p->name, source_p->username, source_p->host, + target); - RB_DLINK_FOREACH(ptr, resv_conf_list.head) - { - aconf = ptr->data; - if (aconf->hold) - continue; - sendto_match_servs(source_p, target, - CAP_ENCAP, NOCAPS, - "ENCAP %s RESV 0 %s 0 :%s", - target, aconf->host, aconf->passwd); - } + RB_DLINK_FOREACH(ptr, resv_conf_list.head) { + aconf = ptr->data; + if (aconf->hold) + continue; + sendto_match_servs(source_p, target, + CAP_ENCAP, NOCAPS, + "ENCAP %s RESV 0 %s 0 :%s", + target, aconf->host, aconf->passwd); + } - HASH_WALK(i, R_MAX, ptr, resvTable) - { - aconf = ptr->data; - if (aconf->hold) - continue; - sendto_match_servs(source_p, target, - CAP_ENCAP, NOCAPS, - "ENCAP %s RESV 0 %s 0 :%s", - target, aconf->host, aconf->passwd); - } - HASH_WALK_END + HASH_WALK(i, R_MAX, ptr, resvTable) { + aconf = ptr->data; + if (aconf->hold) + continue; + sendto_match_servs(source_p, target, + CAP_ENCAP, NOCAPS, + "ENCAP %s RESV 0 %s 0 :%s", + target, aconf->host, aconf->passwd); + } + HASH_WALK_END - RB_DLINK_FOREACH(ptr, xline_conf_list.head) - { - aconf = ptr->data; - if (aconf->hold) - continue; - mask2 = expand_xline(aconf->host); - if (mask2 == NULL) - { - sendto_one_notice(source_p, ":Skipping xline [%s]", - aconf->host); - continue; - } - sendto_match_servs(source_p, target, - CAP_ENCAP, NOCAPS, - "ENCAP %s XLINE 0 %s 2 :%s", - target, mask2, aconf->passwd); - } + RB_DLINK_FOREACH(ptr, xline_conf_list.head) { + aconf = ptr->data; + if (aconf->hold) + continue; + mask2 = expand_xline(aconf->host); + if (mask2 == NULL) { + sendto_one_notice(source_p, ":Skipping xline [%s]", + aconf->host); + continue; + } + sendto_match_servs(source_p, target, + CAP_ENCAP, NOCAPS, + "ENCAP %s XLINE 0 %s 2 :%s", + target, mask2, aconf->passwd); + } - return 0; + return 0; } diff --git a/extensions/m_webirc.c b/extensions/m_webirc.c index fa3ad22..43d3c27 100644 --- a/extensions/m_webirc.c +++ b/extensions/m_webirc.c @@ -57,8 +57,8 @@ static int mr_webirc(struct Client *, struct Client *, int, const char **); struct Message webirc_msgtab = { - "WEBIRC", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_webirc, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} + "WEBIRC", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_webirc, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} }; mapi_clist_av1 webirc_clist[] = { &webirc_msgtab, NULL }; @@ -68,74 +68,68 @@ DECLARE_MODULE_AV1(webirc, NULL, NULL, webirc_clist, NULL, NULL, "$Revision: 207 * mr_webirc - webirc message handler * parv[1] = password * parv[2] = fake username (we ignore this) - * parv[3] = fake hostname + * parv[3] = fake hostname * parv[4] = fake ip */ static int mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct ConfItem *aconf; - const char *encr; + struct ConfItem *aconf; + const char *encr; - if (!strchr(parv[4], '.') && !strchr(parv[4], ':')) - { - sendto_one(source_p, "NOTICE * :Invalid IP"); - return 0; - } + if (!strchr(parv[4], '.') && !strchr(parv[4], ':')) { + sendto_one(source_p, "NOTICE * :Invalid IP"); + return 0; + } - aconf = find_address_conf(client_p->host, client_p->sockhost, - IsGotId(client_p) ? client_p->username : "webirc", - IsGotId(client_p) ? client_p->username : "webirc", - (struct sockaddr *) &client_p->localClient->ip, - client_p->localClient->ip.ss_family, NULL); - if (aconf == NULL || !(aconf->status & CONF_CLIENT)) - return 0; - if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc.")) - { - /* XXX */ - sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block"); - return 0; - } - if (EmptyString(aconf->passwd)) - { - sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password"); - return 0; - } + aconf = find_address_conf(client_p->host, client_p->sockhost, + IsGotId(client_p) ? client_p->username : "webirc", + IsGotId(client_p) ? client_p->username : "webirc", + (struct sockaddr *) &client_p->localClient->ip, + client_p->localClient->ip.ss_family, NULL); + if (aconf == NULL || !(aconf->status & CONF_CLIENT)) + return 0; + if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc.")) { + /* XXX */ + sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block"); + return 0; + } + if (EmptyString(aconf->passwd)) { + sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password"); + return 0; + } - if (EmptyString(parv[1])) - encr = ""; - else if (IsConfEncrypted(aconf)) - encr = rb_crypt(parv[1], aconf->passwd); - else - encr = parv[1]; + if (EmptyString(parv[1])) + encr = ""; + else if (IsConfEncrypted(aconf)) + encr = rb_crypt(parv[1], aconf->passwd); + else + encr = parv[1]; - if (strcmp(encr, aconf->passwd)) - { - sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect"); - return 0; - } + if (strcmp(encr, aconf->passwd)) { + sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect"); + return 0; + } - rb_strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost)); + rb_strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost)); - if(strlen(parv[3]) <= HOSTLEN) - rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host)); - else - rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); - - rb_inet_pton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip); + if(strlen(parv[3]) <= HOSTLEN) + rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host)); + else + rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); - /* Check dlines now, klines will be checked on registration */ - if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, - source_p->localClient->ip.ss_family))) - { - if(!(aconf->status & CONF_EXEMPTDLINE)) - { - exit_client(client_p, source_p, &me, "D-lined"); - return 0; - } - } + rb_inet_pton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip); - sendto_one(source_p, "NOTICE * :CGI:IRC host/IP set to %s %s", parv[3], parv[4]); - return 0; + /* Check dlines now, klines will be checked on registration */ + if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, + source_p->localClient->ip.ss_family))) { + if(!(aconf->status & CONF_EXEMPTDLINE)) { + exit_client(client_p, source_p, &me, "D-lined"); + return 0; + } + } + + sendto_one(source_p, "NOTICE * :CGI:IRC host/IP set to %s %s", parv[3], parv[4]); + return 0; } diff --git a/extensions/no_locops.c b/extensions/no_locops.c index e71b924..40fb3aa 100644 --- a/extensions/no_locops.c +++ b/extensions/no_locops.c @@ -15,8 +15,8 @@ static void h_nl_umode_changed(hook_data_umode_changed *); mapi_hfn_list_av1 nl_hfnlist[] = { - { "umode_changed", (hookfn) h_nl_umode_changed }, - { NULL, NULL } + { "umode_changed", (hookfn) h_nl_umode_changed }, + { NULL, NULL } }; DECLARE_MODULE_AV1(no_locops, NULL, NULL, NULL, NULL, nl_hfnlist, "$Revision: 3219 $"); @@ -24,10 +24,9 @@ DECLARE_MODULE_AV1(no_locops, NULL, NULL, NULL, NULL, nl_hfnlist, "$Revision: 32 static void h_nl_umode_changed(hook_data_umode_changed *hdata) { - struct Client *source_p = hdata->client; + struct Client *source_p = hdata->client; - if (MyClient(source_p) && source_p->umodes & UMODE_LOCOPS) - { - source_p->umodes &= ~UMODE_LOCOPS; - } + if (MyClient(source_p) && source_p->umodes & UMODE_LOCOPS) { + source_p->umodes &= ~UMODE_LOCOPS; + } } diff --git a/extensions/no_oper_invis.c b/extensions/no_oper_invis.c index cc94530..192e008 100644 --- a/extensions/no_oper_invis.c +++ b/extensions/no_oper_invis.c @@ -17,8 +17,8 @@ static void h_noi_umode_changed(hook_data_umode_changed *); mapi_hfn_list_av1 noi_hfnlist[] = { - { "umode_changed", (hookfn) h_noi_umode_changed }, - { NULL, NULL } + { "umode_changed", (hookfn) h_noi_umode_changed }, + { NULL, NULL } }; DECLARE_MODULE_AV1(no_oper_invis, NULL, NULL, NULL, NULL, noi_hfnlist, "$Revision: 3219 $"); @@ -26,15 +26,14 @@ DECLARE_MODULE_AV1(no_oper_invis, NULL, NULL, NULL, NULL, noi_hfnlist, "$Revisio static void h_noi_umode_changed(hook_data_umode_changed *hdata) { - struct Client *source_p = hdata->client; + struct Client *source_p = hdata->client; - if (MyClient(source_p) && IsOper(source_p) && !IsOperInvis(source_p) && - IsInvisible(source_p)) - { - ClearInvisible(source_p); - /* If they tried /umode +i, complain; do not complain - * if they opered up while invisible -- jilles */ - if (hdata->oldumodes & UMODE_OPER) - sendto_one_notice(source_p, ":*** Opers may not set themselves invisible"); - } + if (MyClient(source_p) && IsOper(source_p) && !IsOperInvis(source_p) && + IsInvisible(source_p)) { + ClearInvisible(source_p); + /* If they tried /umode +i, complain; do not complain + * if they opered up while invisible -- jilles */ + if (hdata->oldumodes & UMODE_OPER) + sendto_one_notice(source_p, ":*** Opers may not set themselves invisible"); + } } diff --git a/extensions/sno_farconnect.c b/extensions/sno_farconnect.c index 02ce5af..fa9eb8b 100644 --- a/extensions/sno_farconnect.c +++ b/extensions/sno_farconnect.c @@ -22,9 +22,9 @@ static void h_gcn_new_remote_user(struct Client *); static void h_gcn_client_exit(hook_data_client_exit *); mapi_hfn_list_av1 gcn_hfnlist[] = { - { "new_remote_user", (hookfn) h_gcn_new_remote_user }, - { "client_exit", (hookfn) h_gcn_client_exit }, - { NULL, NULL } + { "new_remote_user", (hookfn) h_gcn_new_remote_user }, + { "client_exit", (hookfn) h_gcn_client_exit }, + { NULL, NULL } }; DECLARE_MODULE_AV1(globalconnexit, _modinit, _moddeinit, NULL, NULL, gcn_hfnlist, "$Revision: 1869 $"); @@ -32,49 +32,49 @@ DECLARE_MODULE_AV1(globalconnexit, _modinit, _moddeinit, NULL, NULL, gcn_hfnlist static int _modinit(void) { - /* add the snomask to the available slot */ - snomask_modes['F'] = find_snomask_slot(); + /* add the snomask to the available slot */ + snomask_modes['F'] = find_snomask_slot(); - /* show the fact that we are showing user information in /version */ - opers_see_all_users = 1; + /* show the fact that we are showing user information in /version */ + opers_see_all_users = 1; - return 0; + return 0; } static void _moddeinit(void) { - /* disable the snomask and remove it from the available list */ - snomask_modes['F'] = 0; + /* disable the snomask and remove it from the available list */ + snomask_modes['F'] = 0; } static void h_gcn_new_remote_user(struct Client *source_p) { - if (!HasSentEob(source_p->servptr)) - return; - sendto_realops_snomask_from(snomask_modes['F'], L_ALL, source_p->servptr, - "Client connecting: %s (%s@%s) [%s] {%s} [%s]", - source_p->name, source_p->username, source_p->orighost, - show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255", - "?", source_p->info); + if (!HasSentEob(source_p->servptr)) + return; + sendto_realops_snomask_from(snomask_modes['F'], L_ALL, source_p->servptr, + "Client connecting: %s (%s@%s) [%s] {%s} [%s]", + source_p->name, source_p->username, source_p->orighost, + show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255", + "?", source_p->info); } static void h_gcn_client_exit(hook_data_client_exit *hdata) { - struct Client *source_p; + struct Client *source_p; - source_p = hdata->target; + source_p = hdata->target; - if (MyConnect(source_p) || !IsClient(source_p)) - return; - if (!HasSentEob(source_p->servptr)) - return; - sendto_realops_snomask_from(snomask_modes['F'], L_ALL, source_p->servptr, - "Client exiting: %s (%s@%s) [%s] [%s]", - source_p->name, - source_p->username, source_p->host, hdata->comment, - show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255"); + if (MyConnect(source_p) || !IsClient(source_p)) + return; + if (!HasSentEob(source_p->servptr)) + return; + sendto_realops_snomask_from(snomask_modes['F'], L_ALL, source_p->servptr, + "Client exiting: %s (%s@%s) [%s] [%s]", + source_p->name, + source_p->username, source_p->host, hdata->comment, + show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255"); } diff --git a/extensions/sno_globalkline.c b/extensions/sno_globalkline.c index 8fb26e8..7a41123 100644 --- a/extensions/sno_globalkline.c +++ b/extensions/sno_globalkline.c @@ -19,8 +19,8 @@ static void h_gla_client_exit(hook_data_client_exit *); mapi_hfn_list_av1 gla_hfnlist[] = { - { "client_exit", (hookfn) h_gla_client_exit }, - { NULL, NULL } + { "client_exit", (hookfn) h_gla_client_exit }, + { NULL, NULL } }; DECLARE_MODULE_AV1(globallineactive, NULL, NULL, NULL, NULL, gla_hfnlist, "$Revision: 613 $"); @@ -28,35 +28,28 @@ DECLARE_MODULE_AV1(globallineactive, NULL, NULL, NULL, NULL, gla_hfnlist, "$Revi static void h_gla_client_exit(hook_data_client_exit *hdata) { - struct Client *source_p; + struct Client *source_p; - source_p = hdata->target; + source_p = hdata->target; - if (MyConnect(source_p) || !IsClient(source_p)) - return; - if (!strcmp(hdata->comment, "Bad user info")) - { - sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, - "XLINE active for %s[%s@%s]", - source_p->name, source_p->username, source_p->host); - } - else if (ConfigFileEntry.kline_reason != NULL && - !strcmp(hdata->comment, ConfigFileEntry.kline_reason)) - { - sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, - "K/DLINE active for %s[%s@%s]", - source_p->name, source_p->username, source_p->host); - } - else if (!strncmp(hdata->comment, "Temporary K-line ", 17)) - { - sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, - "K/DLINE active for %s[%s@%s]", - source_p->name, source_p->username, source_p->host); - } - else if (!strncmp(hdata->comment, "Temporary D-line ", 17)) - { - sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, - "K/DLINE active for %s[%s@%s]", - source_p->name, source_p->username, source_p->host); - } + if (MyConnect(source_p) || !IsClient(source_p)) + return; + if (!strcmp(hdata->comment, "Bad user info")) { + sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, + "XLINE active for %s[%s@%s]", + source_p->name, source_p->username, source_p->host); + } else if (ConfigFileEntry.kline_reason != NULL && + !strcmp(hdata->comment, ConfigFileEntry.kline_reason)) { + sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, + "K/DLINE active for %s[%s@%s]", + source_p->name, source_p->username, source_p->host); + } else if (!strncmp(hdata->comment, "Temporary K-line ", 17)) { + sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, + "K/DLINE active for %s[%s@%s]", + source_p->name, source_p->username, source_p->host); + } else if (!strncmp(hdata->comment, "Temporary D-line ", 17)) { + sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, + "K/DLINE active for %s[%s@%s]", + source_p->name, source_p->username, source_p->host); + } } diff --git a/extensions/sno_globaloper.c b/extensions/sno_globaloper.c index 1d52b66..305b8cc 100644 --- a/extensions/sno_globaloper.c +++ b/extensions/sno_globaloper.c @@ -15,8 +15,8 @@ static void h_sgo_umode_changed(void *); mapi_hfn_list_av1 sgo_hfnlist[] = { - { "umode_changed", (hookfn) h_sgo_umode_changed }, - { NULL, NULL } + { "umode_changed", (hookfn) h_sgo_umode_changed }, + { NULL, NULL } }; DECLARE_MODULE_AV1(sno_globaloper, NULL, NULL, NULL, NULL, sgo_hfnlist, "$Revision: 639 $"); @@ -24,14 +24,14 @@ DECLARE_MODULE_AV1(sno_globaloper, NULL, NULL, NULL, NULL, sgo_hfnlist, "$Revisi static void h_sgo_umode_changed(void *vdata) { - hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; - struct Client *source_p = data->client; + hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; + struct Client *source_p = data->client; - if (MyConnect(source_p) || !HasSentEob(source_p->servptr)) - return; + if (MyConnect(source_p) || !HasSentEob(source_p->servptr)) + return; - if (!(data->oldumodes & UMODE_OPER) && IsOper(source_p)) - sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, - "%s (%s@%s) is now an operator", - source_p->name, source_p->username, source_p->host); + if (!(data->oldumodes & UMODE_OPER) && IsOper(source_p)) + sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, + "%s (%s@%s) is now an operator", + source_p->name, source_p->username, source_p->host); } diff --git a/extensions/sno_whois.c b/extensions/sno_whois.c index f1a4346..1875e82 100644 --- a/extensions/sno_whois.c +++ b/extensions/sno_whois.c @@ -20,23 +20,23 @@ void show_whois(hook_data_client *); mapi_hfn_list_av1 whois_hfnlist[] = { - {"doing_whois", (hookfn) show_whois}, - {"doing_whois_global", (hookfn) show_whois}, - {NULL, NULL} + {"doing_whois", (hookfn) show_whois}, + {"doing_whois_global", (hookfn) show_whois}, + {NULL, NULL} }; static int init(void) { - snomask_modes['W'] = find_snomask_slot(); + snomask_modes['W'] = find_snomask_slot(); - return 0; + return 0; } static void fini(void) { - snomask_modes['W'] = find_snomask_slot(); + snomask_modes['W'] = find_snomask_slot(); } DECLARE_MODULE_AV1(sno_whois, init, fini, NULL, NULL, whois_hfnlist, "$Revision: 3498 $"); @@ -44,20 +44,19 @@ DECLARE_MODULE_AV1(sno_whois, init, fini, NULL, NULL, whois_hfnlist, "$Revision: void show_whois(hook_data_client *data) { - struct Client *source_p = data->client; - struct Client *target_p = data->target; + struct Client *source_p = data->client; + struct Client *target_p = data->target; - if(MyClient(target_p) && + if(MyClient(target_p) && #ifdef OPERONLY - IsOper(target_p) && + IsOper(target_p) && #endif - (source_p != target_p) && - (target_p->snomask & snomask_modes['W'])) - { - sendto_one_notice(target_p, - ":*** Notice -- %s (%s@%s) is doing a whois on you [%s]", - source_p->name, - source_p->username, source_p->host, - source_p->servptr->name); - } + (source_p != target_p) && + (target_p->snomask & snomask_modes['W'])) { + sendto_one_notice(target_p, + ":*** Notice -- %s (%s@%s) is doing a whois on you [%s]", + source_p->name, + source_p->username, source_p->host, + source_p->servptr->name); + } } diff --git a/extensions/spy_admin_notice.c b/extensions/spy_admin_notice.c index 2e07a9c..1fc3c61 100644 --- a/extensions/spy_admin_notice.c +++ b/extensions/spy_admin_notice.c @@ -30,8 +30,8 @@ void show_admin(hook_data *); mapi_hfn_list_av1 admin_hfnlist[] = { - {"doing_admin", (hookfn) show_admin}, - {NULL, NULL} + {"doing_admin", (hookfn) show_admin}, + {NULL, NULL} }; DECLARE_MODULE_AV1(admin_spy, NULL, NULL, NULL, NULL, admin_hfnlist, "$Revision: 498 $"); @@ -39,8 +39,8 @@ DECLARE_MODULE_AV1(admin_spy, NULL, NULL, NULL, NULL, admin_hfnlist, "$Revision: void show_admin(hook_data *data) { - sendto_realops_snomask(SNO_SPY, L_ALL, - "admin requested by %s (%s@%s) [%s]", - data->client->name, data->client->username, - data->client->host, data->client->servptr->name); + sendto_realops_snomask(SNO_SPY, L_ALL, + "admin requested by %s (%s@%s) [%s]", + data->client->name, data->client->username, + data->client->host, data->client->servptr->name); } diff --git a/extensions/spy_info_notice.c b/extensions/spy_info_notice.c index 148be6e..84b137d 100644 --- a/extensions/spy_info_notice.c +++ b/extensions/spy_info_notice.c @@ -30,8 +30,8 @@ void show_info(hook_data *); mapi_hfn_list_av1 info_hfnlist[] = { - {"doing_info", (hookfn) show_info}, - {NULL, NULL} + {"doing_info", (hookfn) show_info}, + {NULL, NULL} }; DECLARE_MODULE_AV1(info_spy, NULL, NULL, NULL, NULL, info_hfnlist, "$Revision: 498 $"); @@ -39,8 +39,8 @@ DECLARE_MODULE_AV1(info_spy, NULL, NULL, NULL, NULL, info_hfnlist, "$Revision: 4 void show_info(hook_data *data) { - sendto_realops_snomask(SNO_SPY, L_ALL, - "info requested by %s (%s@%s) [%s]", - data->client->name, data->client->username, - data->client->host, data->client->servptr->name); + sendto_realops_snomask(SNO_SPY, L_ALL, + "info requested by %s (%s@%s) [%s]", + data->client->name, data->client->username, + data->client->host, data->client->servptr->name); } diff --git a/extensions/spy_links_notice.c b/extensions/spy_links_notice.c index 5f138e6..3cc3a21 100644 --- a/extensions/spy_links_notice.c +++ b/extensions/spy_links_notice.c @@ -30,8 +30,8 @@ void show_links(hook_data *); mapi_hfn_list_av1 links_hfnlist[] = { - {"doing_links", (hookfn) show_links}, - {NULL, NULL} + {"doing_links", (hookfn) show_links}, + {NULL, NULL} }; DECLARE_MODULE_AV1(links_spy, NULL, NULL, NULL, NULL, links_hfnlist, "$Revision: 498 $"); @@ -39,10 +39,10 @@ DECLARE_MODULE_AV1(links_spy, NULL, NULL, NULL, NULL, links_hfnlist, "$Revision: void show_links(hook_data *data) { - const char *mask = data->arg1; + const char *mask = data->arg1; - sendto_realops_snomask(SNO_SPY, L_ALL, - "LINKS '%s' requested by %s (%s@%s) [%s]", - mask, data->client->name, data->client->username, - data->client->host, data->client->servptr->name); + sendto_realops_snomask(SNO_SPY, L_ALL, + "LINKS '%s' requested by %s (%s@%s) [%s]", + mask, data->client->name, data->client->username, + data->client->host, data->client->servptr->name); } diff --git a/extensions/spy_motd_notice.c b/extensions/spy_motd_notice.c index eb77070..c4c201f 100644 --- a/extensions/spy_motd_notice.c +++ b/extensions/spy_motd_notice.c @@ -30,8 +30,8 @@ void show_motd(hook_data *); mapi_hfn_list_av1 motd_hfnlist[] = { - {"doing_motd", (hookfn) show_motd}, - {NULL, NULL} + {"doing_motd", (hookfn) show_motd}, + {NULL, NULL} }; DECLARE_MODULE_AV1(motd_spy, NULL, NULL, NULL, NULL, motd_hfnlist, "$Revision: 498 $"); @@ -39,8 +39,8 @@ DECLARE_MODULE_AV1(motd_spy, NULL, NULL, NULL, NULL, motd_hfnlist, "$Revision: 4 void show_motd(hook_data *data) { - sendto_realops_snomask(SNO_SPY, L_ALL, - "motd requested by %s (%s@%s) [%s]", - data->client->name, data->client->username, - data->client->host, data->client->servptr->name); + sendto_realops_snomask(SNO_SPY, L_ALL, + "motd requested by %s (%s@%s) [%s]", + data->client->name, data->client->username, + data->client->host, data->client->servptr->name); } diff --git a/extensions/spy_stats_notice.c b/extensions/spy_stats_notice.c index 5f942ec..357b018 100644 --- a/extensions/spy_stats_notice.c +++ b/extensions/spy_stats_notice.c @@ -30,8 +30,8 @@ void show_stats(hook_data_int *); mapi_hfn_list_av1 stats_hfnlist[] = { - {"doing_stats", (hookfn) show_stats}, - {NULL, NULL} + {"doing_stats", (hookfn) show_stats}, + {NULL, NULL} }; DECLARE_MODULE_AV1(stats_spy, NULL, NULL, NULL, NULL, stats_hfnlist, "$Revision: 498 $"); @@ -39,31 +39,28 @@ DECLARE_MODULE_AV1(stats_spy, NULL, NULL, NULL, NULL, stats_hfnlist, "$Revision: void show_stats(hook_data_int *data) { - char statchar = (char) data->arg2; + char statchar = (char) data->arg2; - if(statchar == 'L' || statchar == 'l') - { - const char *name = data->arg1; + if(statchar == 'L' || statchar == 'l') { + const char *name = data->arg1; - if(!EmptyString(name)) - sendto_realops_snomask(SNO_SPY, L_ALL, - "STATS %c requested by %s (%s@%s) [%s] on %s", - statchar, data->client->name, - data->client->username, - data->client->host, - data->client->servptr->name, name); - else - sendto_realops_snomask(SNO_SPY, L_ALL, - "STATS %c requested by %s (%s@%s) [%s]", - statchar, data->client->name, - data->client->username, - data->client->host, data->client->servptr->name); - } - else - { - sendto_realops_snomask(SNO_SPY, L_ALL, - "STATS %c requested by %s (%s@%s) [%s]", - statchar, data->client->name, data->client->username, - data->client->host, data->client->servptr->name); - } + if(!EmptyString(name)) + sendto_realops_snomask(SNO_SPY, L_ALL, + "STATS %c requested by %s (%s@%s) [%s] on %s", + statchar, data->client->name, + data->client->username, + data->client->host, + data->client->servptr->name, name); + else + sendto_realops_snomask(SNO_SPY, L_ALL, + "STATS %c requested by %s (%s@%s) [%s]", + statchar, data->client->name, + data->client->username, + data->client->host, data->client->servptr->name); + } else { + sendto_realops_snomask(SNO_SPY, L_ALL, + "STATS %c requested by %s (%s@%s) [%s]", + statchar, data->client->name, data->client->username, + data->client->host, data->client->servptr->name); + } } diff --git a/extensions/spy_stats_p_notice.c b/extensions/spy_stats_p_notice.c index f3fb400..055a91e 100644 --- a/extensions/spy_stats_p_notice.c +++ b/extensions/spy_stats_p_notice.c @@ -30,8 +30,8 @@ void show_stats_p(hook_data *); mapi_hfn_list_av1 stats_p_hfnlist[] = { - {"doing_stats_p", (hookfn) show_stats_p}, - {NULL, NULL} + {"doing_stats_p", (hookfn) show_stats_p}, + {NULL, NULL} }; DECLARE_MODULE_AV1(stats_p_spy, NULL, NULL, NULL, NULL, stats_p_hfnlist, "$Revision: 498 $"); @@ -39,8 +39,8 @@ DECLARE_MODULE_AV1(stats_p_spy, NULL, NULL, NULL, NULL, stats_p_hfnlist, "$Revis void show_stats_p(hook_data *data) { - sendto_realops_snomask(SNO_SPY, L_ALL, - "STATS p requested by %s (%s@%s) [%s]", - data->client->name, data->client->username, - data->client->host, data->client->servptr->name); + sendto_realops_snomask(SNO_SPY, L_ALL, + "STATS p requested by %s (%s@%s) [%s]", + data->client->name, data->client->username, + data->client->host, data->client->servptr->name); } diff --git a/extensions/spy_trace_notice.c b/extensions/spy_trace_notice.c index 01c9e7d..f290eb9 100644 --- a/extensions/spy_trace_notice.c +++ b/extensions/spy_trace_notice.c @@ -30,8 +30,8 @@ void show_trace(hook_data_client *); mapi_hfn_list_av1 trace_hfnlist[] = { - {"doing_trace", (hookfn) show_trace}, - {NULL, NULL} + {"doing_trace", (hookfn) show_trace}, + {NULL, NULL} }; DECLARE_MODULE_AV1(trace_spy, NULL, NULL, NULL, NULL, trace_hfnlist, "$Revision: 498 $"); @@ -39,15 +39,15 @@ DECLARE_MODULE_AV1(trace_spy, NULL, NULL, NULL, NULL, trace_hfnlist, "$Revision: void show_trace(hook_data_client *data) { - if(data->target) - sendto_realops_snomask(SNO_SPY, L_ALL, - "trace requested by %s (%s@%s) [%s] on %s", - data->client->name, data->client->username, - data->client->host, data->client->servptr->name, - data->target->name); - else - sendto_realops_snomask(SNO_SPY, L_ALL, - "trace requested by %s (%s@%s) [%s]", - data->client->name, data->client->username, - data->client->host, data->client->servptr->name); + if(data->target) + sendto_realops_snomask(SNO_SPY, L_ALL, + "trace requested by %s (%s@%s) [%s] on %s", + data->client->name, data->client->username, + data->client->host, data->client->servptr->name, + data->target->name); + else + sendto_realops_snomask(SNO_SPY, L_ALL, + "trace requested by %s (%s@%s) [%s]", + data->client->name, data->client->username, + data->client->host, data->client->servptr->name); } diff --git a/extra/services/anope1.8/elemental-ircd.c b/extra/services/anope1.8/elemental-ircd.c index dcc9bcc..3db2bb9 100644 --- a/extra/services/anope1.8/elemental-ircd.c +++ b/extra/services/anope1.8/elemental-ircd.c @@ -8,7 +8,7 @@ * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * Based on the original code of Services by Andy Church. */ #include "services.h" @@ -17,135 +17,137 @@ #include "version.h" IRCDVar myIrcd[] = { - {"Elemental-IRCd 6.5", /* ircd name */ - "+oiS", /* nickserv mode */ - "+oiS", /* chanserv mode */ - "+oiS", /* memoserv mode */ - "+oiS", /* hostserv mode */ - "+oaiS", /* operserv mode */ - "+oiS", /* botserv mode */ - "+oiS", /* helpserv mode */ - "+oiS", /* Dev/Null mode */ - "+oiS", /* Global mode */ - "+oiS", /* nickserv alias mode */ - "+oiS", /* chanserv alias mode */ - "+oiS", /* memoserv alias mode */ - "+oiS", /* hostserv alias mode */ - "+oaiS", /* operserv alias mode */ - "+oiS", /* botserv alias mode */ - "+oiS", /* helpserv alias mode */ - "+oiS", /* Dev/Null alias mode */ - "+oiS", /* Global alias mode */ - "+oiS", /* Used by BotServ Bots */ - 2, /* Chan Max Symbols */ - "-cijlmnpstrgzQF", /* Modes to Remove */ - "+ao", /* Channel Umode used by Botserv bots */ - 1, /* SVSNICK */ - 1, /* Vhost */ - 1, /* Has Owner */ - "+y", /* Mode to set for an owner */ - "-y", /* Mode to unset for an owner */ - "+a", /* Mode to set for chan admin */ - "-a", /* Mode to unset for chan admin */ - NULL, /* Mode On Reg */ - NULL, /* Mode on ID for Roots */ - NULL, /* Mode on ID for Admins */ - NULL, /* Mode on ID for Opers */ - NULL, /* Mode on UnReg */ - NULL, /* Mode on Nick Change */ - 1, /* Supports SGlines */ - 1, /* Supports SQlines */ - 1, /* Supports SZlines */ - 1, /* Supports Halfop +h */ - 3, /* Number of server args */ - 1, /* Join 2 Set */ - 1, /* Join 2 Message */ - 1, /* Has exceptions +e */ - 0, /* TS Topic Forward */ - 0, /* TS Topci Backward */ - 0, /* Protected Umode */ - 1, /* Has Admin */ - 1, /* Chan SQlines */ - 0, /* Quit on Kill */ - 0, /* SVSMODE unban */ - 1, /* Has Protect */ - 0, /* Reverse */ - 0, /* Chan Reg */ - 0, /* Channel Mode */ - 0, /* vidents */ - 1, /* svshold */ - 0, /* time stamp on mode */ - 0, /* NICKIP */ - 0, /* UMODE */ - 0, /* O:LINE */ - 1, /* VHOST ON NICK */ - 0, /* Change RealName */ - CMODE_p, /* No Knock */ - 0, /* Admin Only */ - DEFAULT_MLOCK, /* Default MLOCK */ - 0, /* Vhost Mode */ - 1, /* +f */ - 1, /* +L */ - CMODE_j, /* +f Mode */ - CMODE_f, /* +L Mode (+f ) */ - 1, /* On nick change check if they could be identified */ - 0, /* No Knock requires +i */ - NULL, /* CAPAB Chan Modes */ - 0, /* We support TOKENS */ - 1, /* TOKENS are CASE inSensitive */ - 0, /* TIME STAMPS are BASE64 */ - 1, /* +I support */ - 0, /* SJOIN ban char */ - 0, /* SJOIN except char */ - 0, /* SJOIN invite char */ - 0, /* Can remove User Channel Modes with SVSMODE */ - 0, /* Sglines are not enforced until user reconnects */ - NULL, /* vhost char */ - 1, /* ts6 */ - 0, /* support helper umode */ - 0, /* p10 */ - NULL, /* character set */ - 0, /* reports sync state */ - 1, /* CIDR channelbans */ - 0, /* +j */ - 0, /* +j Mode */ - 0, /* Use delayed client introduction. */ - } + { + "Elemental-IRCd 6.5", /* ircd name */ + "+oiS", /* nickserv mode */ + "+oiS", /* chanserv mode */ + "+oiS", /* memoserv mode */ + "+oiS", /* hostserv mode */ + "+oaiS", /* operserv mode */ + "+oiS", /* botserv mode */ + "+oiS", /* helpserv mode */ + "+oiS", /* Dev/Null mode */ + "+oiS", /* Global mode */ + "+oiS", /* nickserv alias mode */ + "+oiS", /* chanserv alias mode */ + "+oiS", /* memoserv alias mode */ + "+oiS", /* hostserv alias mode */ + "+oaiS", /* operserv alias mode */ + "+oiS", /* botserv alias mode */ + "+oiS", /* helpserv alias mode */ + "+oiS", /* Dev/Null alias mode */ + "+oiS", /* Global alias mode */ + "+oiS", /* Used by BotServ Bots */ + 2, /* Chan Max Symbols */ + "-cijlmnpstrgzQF", /* Modes to Remove */ + "+ao", /* Channel Umode used by Botserv bots */ + 1, /* SVSNICK */ + 1, /* Vhost */ + 1, /* Has Owner */ + "+y", /* Mode to set for an owner */ + "-y", /* Mode to unset for an owner */ + "+a", /* Mode to set for chan admin */ + "-a", /* Mode to unset for chan admin */ + NULL, /* Mode On Reg */ + NULL, /* Mode on ID for Roots */ + NULL, /* Mode on ID for Admins */ + NULL, /* Mode on ID for Opers */ + NULL, /* Mode on UnReg */ + NULL, /* Mode on Nick Change */ + 1, /* Supports SGlines */ + 1, /* Supports SQlines */ + 1, /* Supports SZlines */ + 1, /* Supports Halfop +h */ + 3, /* Number of server args */ + 1, /* Join 2 Set */ + 1, /* Join 2 Message */ + 1, /* Has exceptions +e */ + 0, /* TS Topic Forward */ + 0, /* TS Topci Backward */ + 0, /* Protected Umode */ + 1, /* Has Admin */ + 1, /* Chan SQlines */ + 0, /* Quit on Kill */ + 0, /* SVSMODE unban */ + 1, /* Has Protect */ + 0, /* Reverse */ + 0, /* Chan Reg */ + 0, /* Channel Mode */ + 0, /* vidents */ + 1, /* svshold */ + 0, /* time stamp on mode */ + 0, /* NICKIP */ + 0, /* UMODE */ + 0, /* O:LINE */ + 1, /* VHOST ON NICK */ + 0, /* Change RealName */ + CMODE_p, /* No Knock */ + 0, /* Admin Only */ + DEFAULT_MLOCK, /* Default MLOCK */ + 0, /* Vhost Mode */ + 1, /* +f */ + 1, /* +L */ + CMODE_j, /* +f Mode */ + CMODE_f, /* +L Mode (+f ) */ + 1, /* On nick change check if they could be identified */ + 0, /* No Knock requires +i */ + NULL, /* CAPAB Chan Modes */ + 0, /* We support TOKENS */ + 1, /* TOKENS are CASE inSensitive */ + 0, /* TIME STAMPS are BASE64 */ + 1, /* +I support */ + 0, /* SJOIN ban char */ + 0, /* SJOIN except char */ + 0, /* SJOIN invite char */ + 0, /* Can remove User Channel Modes with SVSMODE */ + 0, /* Sglines are not enforced until user reconnects */ + NULL, /* vhost char */ + 1, /* ts6 */ + 0, /* support helper umode */ + 0, /* p10 */ + NULL, /* character set */ + 0, /* reports sync state */ + 1, /* CIDR channelbans */ + 0, /* +j */ + 0, /* +j Mode */ + 0, /* Use delayed client introduction. */ + } , {NULL} }; IRCDCAPAB myIrcdcap[] = { { - 0, /* NOQUIT */ - 0, /* TSMODE */ - 0, /* UNCONNECT */ - 0, /* NICKIP */ - 0, /* SJOIN */ - CAPAB_ZIP, /* ZIP */ - 0, /* BURST */ - CAPAB_TS5, /* TS5 */ - 0, /* TS3 */ - 0, /* DKEY */ - 0, /* PT4 */ - 0, /* SCS */ - CAPAB_QS, /* QS */ - CAPAB_UID, /* UID */ - CAPAB_KNOCK, /* KNOCK */ - 0, /* CLIENT */ - 0, /* IPV6 */ - 0, /* SSJ5 */ - 0, /* SN2 */ - 0, /* TOKEN */ - 0, /* VHOST */ - 0, /* SSJ3 */ - 0, /* NICK2 */ - 0, /* UMODE2 */ - 0, /* VL */ - 0, /* TLKEXT */ - 0, /* DODKEY */ - 0, /* DOZIP */ - 0, 0, 0} + 0, /* NOQUIT */ + 0, /* TSMODE */ + 0, /* UNCONNECT */ + 0, /* NICKIP */ + 0, /* SJOIN */ + CAPAB_ZIP, /* ZIP */ + 0, /* BURST */ + CAPAB_TS5, /* TS5 */ + 0, /* TS3 */ + 0, /* DKEY */ + 0, /* PT4 */ + 0, /* SCS */ + CAPAB_QS, /* QS */ + CAPAB_UID, /* UID */ + CAPAB_KNOCK, /* KNOCK */ + 0, /* CLIENT */ + 0, /* IPV6 */ + 0, /* SSJ5 */ + 0, /* SN2 */ + 0, /* TOKEN */ + 0, /* VHOST */ + 0, /* SSJ3 */ + 0, /* NICK2 */ + 0, /* UMODE2 */ + 0, /* VL */ + 0, /* TLKEXT */ + 0, /* DODKEY */ + 0, /* DOZIP */ + 0, 0, 0 + } }; /*******************************************************************/ @@ -471,8 +473,8 @@ void charybdis_cmd_notice(char *source, char *dest, char *buf) ud = find_uid(source); u = finduser(dest); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), - "NOTICE %s :%s", (UseTS6 ? (u ? u->uid : dest) : dest), - buf); + "NOTICE %s :%s", (UseTS6 ? (u ? u->uid : dest) : dest), + buf); } } @@ -484,7 +486,7 @@ void charybdis_cmd_notice2(char *source, char *dest, char *msg) ud = find_uid(source); u = finduser(dest); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "NOTICE %s :%s", - (UseTS6 ? (u ? u->uid : dest) : dest), msg); + (UseTS6 ? (u ? u->uid : dest) : dest), msg); } void charybdis_cmd_privmsg(char *source, char *dest, char *buf) @@ -498,7 +500,7 @@ void charybdis_cmd_privmsg(char *source, char *dest, char *buf) ud2 = find_uid(dest); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "PRIVMSG %s :%s", - (UseTS6 ? (ud2 ? ud2->uid : dest) : dest), buf); + (UseTS6 ? (ud2 ? ud2->uid : dest) : dest), buf); } void charybdis_cmd_privmsg2(char *source, char *dest, char *msg) @@ -509,7 +511,7 @@ void charybdis_cmd_privmsg2(char *source, char *dest, char *msg) ud2 = find_uid(dest); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "PRIVMSG %s :%s", - (UseTS6 ? (ud2 ? ud2->uid : dest) : dest), msg); + (UseTS6 ? (ud2 ? ud2->uid : dest) : dest), msg); } void charybdis_cmd_serv_notice(char *source, char *dest, char *msg) @@ -645,7 +647,7 @@ int anope_event_euid(char *source, int ac, char **av) s = findserver_uid(servlist, source); /* Source is always the server */ *source = '\0'; - ts = strtoul(av[2], NULL, 10); + ts = strtoul(av[2], NULL, 10); user = do_nick(source, av[0], av[4], !strcmp(av[8], "*") ? av[5] : av[8], s->name, av[10], ts, !stricmp(av[0], av[9]) ? ts : 0, 0, av[5], av[7]); if (user) { @@ -696,11 +698,11 @@ int anope_event_topic(char *source, int ac, char **av) c->topic_time = topic_time; record_topic(av[0]); - - if (ac > 1 && *av[1]) - send_event(EVENT_TOPIC_UPDATED, 2, av[0], av[1]); - else - send_event(EVENT_TOPIC_UPDATED, 2, av[0], ""); + + if (ac > 1 && *av[1]) + send_event(EVENT_TOPIC_UPDATED, 2, av[0], av[1]); + else + send_event(EVENT_TOPIC_UPDATED, 2, av[0], ""); } return MOD_CONT; } @@ -748,10 +750,10 @@ int anope_event_tburst(char *source, int ac, char **av) record_topic(av[0]); - if (ac > 1 && *av[3]) - send_event(EVENT_TOPIC_UPDATED, 2, av[0], av[3]); - else - send_event(EVENT_TOPIC_UPDATED, 2, av[0], ""); + if (ac > 1 && *av[3]) + send_event(EVENT_TOPIC_UPDATED, 2, av[0], av[3]); + else + send_event(EVENT_TOPIC_UPDATED, 2, av[0], ""); if (setter) free(setter); @@ -770,54 +772,92 @@ int anope_event_436(char *source, int ac, char **av) /* *INDENT-OFF* */ -void moduleAddIRCDMsgs(void) +void moduleAddIRCDMsgs(void) { Message *m; - + updateProtectDetails("PROTECT","PROTECTME","protect","deprotect","AUTOPROTECT","+","-"); if (UseTS6) { TS6SID = sstrdup(Numeric); } - m = createMessage("401", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("402", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("436", anope_event_436); addCoreMessage(IRCD,m); - m = createMessage("AWAY", anope_event_away); addCoreMessage(IRCD,m); - m = createMessage("INVITE", anope_event_invite); addCoreMessage(IRCD,m); - m = createMessage("JOIN", anope_event_join); addCoreMessage(IRCD,m); - m = createMessage("KICK", anope_event_kick); addCoreMessage(IRCD,m); - m = createMessage("KILL", anope_event_kill); addCoreMessage(IRCD,m); - m = createMessage("MODE", anope_event_mode); addCoreMessage(IRCD,m); - m = createMessage("TMODE", anope_event_tmode); addCoreMessage(IRCD,m); - m = createMessage("MOTD", anope_event_motd); addCoreMessage(IRCD,m); - m = createMessage("NICK", anope_event_nick); addCoreMessage(IRCD,m); - m = createMessage("BMASK", anope_event_bmask); addCoreMessage(IRCD,m); - m = createMessage("UID", anope_event_nick); addCoreMessage(IRCD,m); - m = createMessage("NOTICE", anope_event_notice); addCoreMessage(IRCD,m); - m = createMessage("PART", anope_event_part); addCoreMessage(IRCD,m); - m = createMessage("PASS", anope_event_pass); addCoreMessage(IRCD,m); - m = createMessage("PING", anope_event_ping); addCoreMessage(IRCD,m); - m = createMessage("PRIVMSG", anope_event_privmsg); addCoreMessage(IRCD,m); - m = createMessage("QUIT", anope_event_quit); addCoreMessage(IRCD,m); - m = createMessage("SERVER", anope_event_server); addCoreMessage(IRCD,m); - m = createMessage("SQUIT", anope_event_squit); addCoreMessage(IRCD,m); - m = createMessage("TOPIC", anope_event_topic); addCoreMessage(IRCD,m); - m = createMessage("TB", anope_event_tburst); addCoreMessage(IRCD,m); - m = createMessage("USER", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("WALLOPS", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("WHOIS", anope_event_whois); addCoreMessage(IRCD,m); - m = createMessage("SVSMODE", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("SVSNICK", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("CAPAB", anope_event_capab); addCoreMessage(IRCD,m); - m = createMessage("SJOIN", anope_event_sjoin); addCoreMessage(IRCD,m); - m = createMessage("SVINFO", anope_event_svinfo); addCoreMessage(IRCD,m); - m = createMessage("ADMIN", anope_event_admin); addCoreMessage(IRCD,m); - m = createMessage("ERROR", anope_event_error); addCoreMessage(IRCD,m); - m = createMessage("421", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("ENCAP", anope_event_null); addCoreMessage(IRCD,m); - m = createMessage("SID", anope_event_sid); addCoreMessage(IRCD,m); - m = createMessage("EUID", anope_event_euid); addCoreMessage(IRCD,m); + m = createMessage("401", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("402", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("436", anope_event_436); + addCoreMessage(IRCD,m); + m = createMessage("AWAY", anope_event_away); + addCoreMessage(IRCD,m); + m = createMessage("INVITE", anope_event_invite); + addCoreMessage(IRCD,m); + m = createMessage("JOIN", anope_event_join); + addCoreMessage(IRCD,m); + m = createMessage("KICK", anope_event_kick); + addCoreMessage(IRCD,m); + m = createMessage("KILL", anope_event_kill); + addCoreMessage(IRCD,m); + m = createMessage("MODE", anope_event_mode); + addCoreMessage(IRCD,m); + m = createMessage("TMODE", anope_event_tmode); + addCoreMessage(IRCD,m); + m = createMessage("MOTD", anope_event_motd); + addCoreMessage(IRCD,m); + m = createMessage("NICK", anope_event_nick); + addCoreMessage(IRCD,m); + m = createMessage("BMASK", anope_event_bmask); + addCoreMessage(IRCD,m); + m = createMessage("UID", anope_event_nick); + addCoreMessage(IRCD,m); + m = createMessage("NOTICE", anope_event_notice); + addCoreMessage(IRCD,m); + m = createMessage("PART", anope_event_part); + addCoreMessage(IRCD,m); + m = createMessage("PASS", anope_event_pass); + addCoreMessage(IRCD,m); + m = createMessage("PING", anope_event_ping); + addCoreMessage(IRCD,m); + m = createMessage("PRIVMSG", anope_event_privmsg); + addCoreMessage(IRCD,m); + m = createMessage("QUIT", anope_event_quit); + addCoreMessage(IRCD,m); + m = createMessage("SERVER", anope_event_server); + addCoreMessage(IRCD,m); + m = createMessage("SQUIT", anope_event_squit); + addCoreMessage(IRCD,m); + m = createMessage("TOPIC", anope_event_topic); + addCoreMessage(IRCD,m); + m = createMessage("TB", anope_event_tburst); + addCoreMessage(IRCD,m); + m = createMessage("USER", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("WALLOPS", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("WHOIS", anope_event_whois); + addCoreMessage(IRCD,m); + m = createMessage("SVSMODE", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("SVSNICK", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("CAPAB", anope_event_capab); + addCoreMessage(IRCD,m); + m = createMessage("SJOIN", anope_event_sjoin); + addCoreMessage(IRCD,m); + m = createMessage("SVINFO", anope_event_svinfo); + addCoreMessage(IRCD,m); + m = createMessage("ADMIN", anope_event_admin); + addCoreMessage(IRCD,m); + m = createMessage("ERROR", anope_event_error); + addCoreMessage(IRCD,m); + m = createMessage("421", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("ENCAP", anope_event_null); + addCoreMessage(IRCD,m); + m = createMessage("SID", anope_event_sid); + addCoreMessage(IRCD,m); + m = createMessage("EUID", anope_event_euid); + addCoreMessage(IRCD,m); } /* *INDENT-ON* */ @@ -829,7 +869,7 @@ void charybdis_cmd_sqline(char *mask, char *reason) ud = find_uid(s_OperServ); send_cmd((UseTS6 ? (ud ? ud->uid : s_OperServ) : s_OperServ), - "RESV * %s :%s", mask, reason); + "RESV * %s :%s", mask, reason); } void charybdis_cmd_unsgline(char *mask) @@ -838,7 +878,7 @@ void charybdis_cmd_unsgline(char *mask) ud = find_uid(s_OperServ); send_cmd((UseTS6 ? (ud ? ud->uid : s_OperServ) : s_OperServ), - "UNXLINE * %s", mask); + "UNXLINE * %s", mask); } void charybdis_cmd_unszline(char *mask) @@ -867,7 +907,7 @@ void charybdis_cmd_sgline(char *mask, char *reason) ud = find_uid(s_OperServ); send_cmd((UseTS6 ? (ud ? ud->uid : s_OperServ) : s_OperServ), - "XLINE * %s 0 :%s", mask, reason); + "XLINE * %s 0 :%s", mask, reason); } void charybdis_cmd_remove_akill(char *user, char *host) @@ -879,17 +919,17 @@ void charybdis_cmd_remove_akill(char *user, char *host) ud = find_uid(s_OperServ); send_cmd((UseTS6 ? (ud ? ud->uid : s_OperServ) : s_OperServ), - "UNKLINE * %s %s", user, host); + "UNKLINE * %s %s", user, host); } void charybdis_cmd_topic(char *whosets, char *chan, char *whosetit, - char *topic, time_t when) + char *topic, time_t when) { Uid *ud; ud = find_uid(whosets); send_cmd((UseTS6 ? (ud ? ud->uid : whosets) : whosets), "TOPIC %s :%s", - chan, topic); + chan, topic); } void charybdis_cmd_vhost_off(User * u) @@ -910,7 +950,7 @@ void charybdis_cmd_unsqline(char *user) ud = find_uid(s_OperServ); send_cmd((UseTS6 ? (ud ? ud->uid : s_OperServ) : s_OperServ), - "UNRESV * %s", user); + "UNRESV * %s", user); } void charybdis_cmd_join(char *user, char *channel, time_t chantime) @@ -932,15 +972,15 @@ reason: the reason for the kline. */ void charybdis_cmd_akill(char *user, char *host, char *who, time_t when, - time_t expires, char *reason) + time_t expires, char *reason) { Uid *ud; ud = find_uid(s_OperServ); send_cmd((UseTS6 ? (ud ? ud->uid : s_OperServ) : s_OperServ), - "KLINE * %ld %s %s :%s", - (long int) (expires - (long) time(NULL)), user, host, reason); + "KLINE * %ld %s %s :%s", + (long int) (expires - (long) time(NULL)), user, host, reason); } void charybdis_cmd_svskill(char *source, char *user, char *buf) @@ -958,7 +998,7 @@ void charybdis_cmd_svskill(char *source, char *user, char *buf) ud = find_uid(source); ud2 = find_uid(user); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "KILL %s :%s", - (UseTS6 ? (ud2 ? ud2->uid : user) : user), buf); + (UseTS6 ? (ud2 ? ud2->uid : user) : user), buf); } void charybdis_cmd_svsmode(User * u, int ac, char **av) @@ -988,18 +1028,18 @@ void charybdis_cmd_svsinfo() /* CAPAB */ /* QS - Can handle quit storm removal - EX - Can do channel +e exemptions + EX - Can do channel +e exemptions CHW - Can do channel wall @# - LL - Can do lazy links - IE - Can do invite exceptions + LL - Can do lazy links + IE - Can do invite exceptions EOB - Can do EOB message - KLN - Can do KLINE message - GLN - Can do GLINE message - HUB - This server is a HUB + KLN - Can do KLINE message + GLN - Can do GLINE message + HUB - This server is a HUB UID - Can do UIDs ZIP - Can do ZIPlinks - ENC - Can do ENCrypted links - KNOCK - supports KNOCK + ENC - Can do ENCrypted links + KNOCK - supports KNOCK TBURST - supports TBURST PARA - supports invite broadcasting for +p ENCAP - supports message encapsulation @@ -1056,7 +1096,7 @@ void charybdis_cmd_bob() } void charybdis_cmd_bot_nick(char *nick, char *user, char *host, char *real, - char *modes) + char *modes) { EnforceQlinedNick(nick, NULL); if (UseTS6) { @@ -1103,7 +1143,7 @@ int anope_event_away(char *source, int ac, char **av) } m_away((UseTS6 ? (u ? u->nick : source) : source), - (ac ? av[0] : NULL)); + (ac ? av[0] : NULL)); return MOD_CONT; } @@ -1140,7 +1180,7 @@ void charybdis_cmd_eob() int anope_event_join(char *source, int ac, char **av) { if (ac != 1) { - /* ignore cmodes in JOIN as per TS6 v8 */ + /* ignore cmodes in JOIN as per TS6 v8 */ do_sjoin(source, ac > 2 ? 2 : ac, av); return MOD_CONT; } else { @@ -1171,7 +1211,7 @@ int anope_event_privmsg(char *source, int ac, char **av) u = find_byuid(source); ud = find_nickuid(av[0]); m_privmsg((UseTS6 ? (u ? u->nick : source) : source), - (UseTS6 ? (ud ? ud->nick : av[0]) : av[0]), av[1]); + (UseTS6 ? (ud ? ud->nick : av[0]) : av[0]), av[1]); return MOD_CONT; } @@ -1409,7 +1449,7 @@ void charybdis_cmd_mode(char *source, char *dest, char *buf) if (source) { ud = find_uid(source); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "MODE %s %s", - dest, buf); + dest, buf); } else { send_cmd(NULL, "MODE %s %s", dest, buf); } @@ -1460,11 +1500,11 @@ void charybdis_cmd_kick(char *source, char *chan, char *user, char *buf) if (buf) { send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), - "KICK %s %s :%s", chan, - (UseTS6 ? (u ? u->uid : user) : user), buf); + "KICK %s %s :%s", chan, + (UseTS6 ? (u ? u->uid : user) : user), buf); } else { send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "KICK %s %s", - chan, (UseTS6 ? (u ? u->uid : user) : user)); + chan, (UseTS6 ? (u ? u->uid : user) : user)); } } @@ -1487,7 +1527,7 @@ void charybdis_cmd_bot_chan_mode(char *nick, char *chan) if (UseTS6) { u = find_uid(nick); charybdis_cmd_tmode(nick, chan, "%s %s", ircd->botchanumode, - (u ? u->uid : nick)); + (u ? u->uid : nick)); } else { anope_cmd_mode(ServerName, chan, "%s %s", ircd->botchanumode, nick); } @@ -1501,7 +1541,7 @@ void charybdis_cmd_quit(char *source, char *buf) if (buf) { send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "QUIT :%s", - buf); + buf); } else { send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "QUIT"); } @@ -1532,7 +1572,7 @@ void charybdis_cmd_invite(char *source, char *chan, char *nick) u = finduser(nick); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "INVITE %s %s", - (UseTS6 ? (u ? u->uid : nick) : nick), chan); + (UseTS6 ? (u ? u->uid : nick) : nick), chan); } /* SQUIT */ @@ -1646,7 +1686,7 @@ void charybdis_cmd_svsnick(char *nick, char *newnick, time_t when) } void charybdis_cmd_guest_nick(char *nick, char *user, char *host, char *real, - char *modes) + char *modes) { /* not supported */ } @@ -1833,7 +1873,7 @@ void charybdis_cmd_jupe(char *jserver, char *who, char *reason) new_server(me_server, jserver, rbuf, SERVER_JUPED, NULL); } -/* +/* 1 = valid nick 0 = nick is in valid */ @@ -1845,7 +1885,7 @@ int charybdis_valid_nick(char *nick) return 1; } -/* +/* 1 = valid chan 0 = chan is invalid */ @@ -1873,7 +1913,7 @@ void charybdis_cmd_ctcp(char *source, char *dest, char *buf) int charybdis_send_account(int argc, char **argv) { send_cmd((UseTS6 ? TS6SID : ServerName), "ENCAP * SU %s :%s", - argv[0], argv[0]); + argv[0], argv[0]); return MOD_CONT; } @@ -1883,7 +1923,7 @@ int charybdis_send_account(int argc, char **argv) int charybdis_send_deaccount(int argc, char **argv) { send_cmd((UseTS6 ? TS6SID : ServerName), "ENCAP * SU %s", - argv[0]); + argv[0]); return MOD_CONT; } @@ -1971,7 +2011,7 @@ void moduleAddAnopeCmds() pmodule_set_umode(charybdis_set_umode); } -/** +/** * Now tell anope how to use us. **/ int AnopeInit(int argc, char **argv) @@ -1994,7 +2034,7 @@ int AnopeInit(int argc, char **argv) pmodule_ircd_csmodes(myCsmodes); pmodule_ircd_useTSMode(0); - /** Deal with modes anope _needs_ to know **/ + /** Deal with modes anope _needs_ to know **/ pmodule_invis_umode(UMODE_i); pmodule_oper_umode(UMODE_o); pmodule_invite_cmode(CMODE_i); @@ -2014,7 +2054,7 @@ int AnopeInit(int argc, char **argv) moduleAddEventHook(hk); /* XXX: It'd be nice if we could have an event like this, but it's not there yet :( */ - /* It's there now! Trystan said so! -GD */ + /* It's there now! Trystan said so! -GD */ hk = createEventHook(EVENT_NICK_LOGOUT, charybdis_send_deaccount); moduleAddEventHook(hk); @@ -2024,8 +2064,8 @@ int AnopeInit(int argc, char **argv) /* Clean up allocated things in here */ void AnopeFini(void) { - if (UseTS6) - free(TS6SID); + if (UseTS6) + free(TS6SID); } /* EOF */ diff --git a/extra/services/atheme/elemental-ircd.c b/extra/services/atheme/elemental-ircd.c index 43c6b63..55c79ea 100644 --- a/extra/services/atheme/elemental-ircd.c +++ b/extra/services/atheme/elemental-ircd.c @@ -19,103 +19,103 @@ DECLARE_MODULE_V1("protocol/elemental-ircd", true, _modinit, NULL, PACKAGE_STRIN /* *INDENT-OFF* */ ircd_t elemental_ircd = { - "elemental-ircd", /* IRCd name */ - "$$", /* TLD Prefix, used by Global. */ - true, /* Whether or not we use IRCNet/TS6 UID */ - false, /* Whether or not we use RCOMMAND */ - true, /* Whether or not we support channel owners. */ - true, /* Whether or not we support channel protection. */ - true, /* Whether or not we support halfops. */ - false, /* Whether or not we use P10 */ - false, /* Whether or not we use vHosts. */ - CMODE_EXLIMIT | CMODE_PERM | CMODE_IMMUNE, /* Oper-only cmodes */ - CSTATUS_OWNER, /* Integer flag for owner channel flag. */ - CSTATUS_PROTECT, /* Integer flag for protect channel flag. */ - CSTATUS_HALFOP, /* Integer flag for halfops. */ - "+y", /* Mode we set for owner. */ - "+a", /* Mode we set for protect. */ - "+h", /* Mode we set for halfops. */ - PROTOCOL_SHADOWIRCD, /* Protocol type */ - CMODE_PERM, /* Permanent cmodes */ - CMODE_IMMUNE, /* Oper-immune cmode */ - "beIq", /* Ban-like cmodes */ - 'e', /* Except mchar */ - 'I', /* Invex mchar */ - IRCD_CIDR_BANS | IRCD_HOLDNICK /* Flags */ + "elemental-ircd", /* IRCd name */ + "$$", /* TLD Prefix, used by Global. */ + true, /* Whether or not we use IRCNet/TS6 UID */ + false, /* Whether or not we use RCOMMAND */ + true, /* Whether or not we support channel owners. */ + true, /* Whether or not we support channel protection. */ + true, /* Whether or not we support halfops. */ + false, /* Whether or not we use P10 */ + false, /* Whether or not we use vHosts. */ + CMODE_EXLIMIT | CMODE_PERM | CMODE_IMMUNE, /* Oper-only cmodes */ + CSTATUS_OWNER, /* Integer flag for owner channel flag. */ + CSTATUS_PROTECT, /* Integer flag for protect channel flag. */ + CSTATUS_HALFOP, /* Integer flag for halfops. */ + "+y", /* Mode we set for owner. */ + "+a", /* Mode we set for protect. */ + "+h", /* Mode we set for halfops. */ + PROTOCOL_SHADOWIRCD, /* Protocol type */ + CMODE_PERM, /* Permanent cmodes */ + CMODE_IMMUNE, /* Oper-immune cmode */ + "beIq", /* Ban-like cmodes */ + 'e', /* Except mchar */ + 'I', /* Invex mchar */ + IRCD_CIDR_BANS | IRCD_HOLDNICK /* Flags */ }; struct cmode_ elemental_mode_list[] = { - { 'i', CMODE_INVITE }, - { 'm', CMODE_MOD }, - { 'n', CMODE_NOEXT }, - { 'p', CMODE_PRIV }, - { 's', CMODE_SEC }, - { 't', CMODE_TOPIC }, - { 'c', CMODE_NOCOLOR}, - { 'r', CMODE_REGONLY}, - { 'z', CMODE_OPMOD }, - { 'g', CMODE_FINVITE}, - { 'L', CMODE_EXLIMIT}, - { 'P', CMODE_PERM }, - { 'F', CMODE_FTARGET}, - { 'Q', CMODE_DISFWD }, - { 'M', CMODE_IMMUNE }, - { 'C', CMODE_NOCTCP }, - { 'A', CMODE_ADMINONLY }, - { 'O', CMODE_OPERONLY }, - { 'S', CMODE_SSLONLY }, - { 'D', CMODE_NOACTIONS }, - { 'T', CMODE_NONOTICE }, - { 'G', CMODE_NOCAPS }, - { 'E', CMODE_NOKICKS }, - { 'd', CMODE_NONICKS }, - { 'K', CMODE_NOREPEAT }, - { 'J', CMODE_KICKNOREJOIN }, - { '\0', 0 } + { 'i', CMODE_INVITE }, + { 'm', CMODE_MOD }, + { 'n', CMODE_NOEXT }, + { 'p', CMODE_PRIV }, + { 's', CMODE_SEC }, + { 't', CMODE_TOPIC }, + { 'c', CMODE_NOCOLOR}, + { 'r', CMODE_REGONLY}, + { 'z', CMODE_OPMOD }, + { 'g', CMODE_FINVITE}, + { 'L', CMODE_EXLIMIT}, + { 'P', CMODE_PERM }, + { 'F', CMODE_FTARGET}, + { 'Q', CMODE_DISFWD }, + { 'M', CMODE_IMMUNE }, + { 'C', CMODE_NOCTCP }, + { 'A', CMODE_ADMINONLY }, + { 'O', CMODE_OPERONLY }, + { 'S', CMODE_SSLONLY }, + { 'D', CMODE_NOACTIONS }, + { 'T', CMODE_NONOTICE }, + { 'G', CMODE_NOCAPS }, + { 'E', CMODE_NOKICKS }, + { 'd', CMODE_NONICKS }, + { 'K', CMODE_NOREPEAT }, + { 'J', CMODE_KICKNOREJOIN }, + { '\0', 0 } }; struct cmode_ elemental_status_mode_list[] = { - { 'y', CSTATUS_OWNER }, - { 'a', CSTATUS_PROTECT }, - { 'o', CSTATUS_OP }, - { 'h', CSTATUS_HALFOP }, - { 'v', CSTATUS_VOICE }, - { '\0', 0 } + { 'y', CSTATUS_OWNER }, + { 'a', CSTATUS_PROTECT }, + { 'o', CSTATUS_OP }, + { 'h', CSTATUS_HALFOP }, + { 'v', CSTATUS_VOICE }, + { '\0', 0 } }; struct cmode_ elemental_prefix_mode_list[] = { - { '~', CSTATUS_OWNER }, - { '!', CSTATUS_PROTECT }, - { '@', CSTATUS_OP }, - { '%', CSTATUS_HALFOP }, - { '+', CSTATUS_VOICE }, - { '\0', 0 } + { '~', CSTATUS_OWNER }, + { '!', CSTATUS_PROTECT }, + { '@', CSTATUS_OP }, + { '%', CSTATUS_HALFOP }, + { '+', CSTATUS_VOICE }, + { '\0', 0 } }; struct cmode_ elemental_user_mode_list[] = { - { 'a', UF_ADMIN }, - { 'i', UF_INVIS }, - { 'o', UF_IRCOP }, - { 'D', UF_DEAF }, - { '\0', 0 } + { 'a', UF_ADMIN }, + { 'i', UF_INVIS }, + { 'o', UF_IRCOP }, + { 'D', UF_DEAF }, + { '\0', 0 } }; /* *INDENT-ON* */ void _modinit(module_t * m) { - MODULE_TRY_REQUEST_DEPENDENCY(m, "protocol/charybdis"); + MODULE_TRY_REQUEST_DEPENDENCY(m, "protocol/charybdis"); - mode_list = elemental_mode_list; - user_mode_list = elemental_user_mode_list; - status_mode_list = elemental_status_mode_list; - prefix_mode_list = elemental_prefix_mode_list; + mode_list = elemental_mode_list; + user_mode_list = elemental_user_mode_list; + status_mode_list = elemental_status_mode_list; + prefix_mode_list = elemental_prefix_mode_list; - ircd = &elemental_ircd; + ircd = &elemental_ircd; - m->mflags = MODTYPE_CORE; + m->mflags = MODTYPE_CORE; - pmodule_loaded = true; + pmodule_loaded = true; } /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs diff --git a/include/bandbi.h b/include/bandbi.h index aad0cf6..0e40903 100644 --- a/include/bandbi.h +++ b/include/bandbi.h @@ -3,17 +3,16 @@ void init_bandb(void); -typedef enum -{ - BANDB_KLINE, - BANDB_DLINE, - BANDB_XLINE, - BANDB_RESV, - LAST_BANDB_TYPE +typedef enum { + BANDB_KLINE, + BANDB_DLINE, + BANDB_XLINE, + BANDB_RESV, + LAST_BANDB_TYPE } bandb_type; void bandb_add(bandb_type, struct Client *source_p, const char *mask1, - const char *mask2, const char *reason, const char *oper_reason, int perm); + const char *mask2, const char *reason, const char *oper_reason, int perm); void bandb_del(bandb_type, const char *mask1, const char *mask2); void bandb_rehash_bans(void); #endif diff --git a/include/blacklist.h b/include/blacklist.h index a7f081a..2f3e553 100644 --- a/include/blacklist.h +++ b/include/blacklist.h @@ -26,26 +26,26 @@ /* A configured DNSBL */ struct Blacklist { - unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ - int refcount; - int ipv4; /* Does this blacklist support IPv4 lookups? */ - int ipv6; /* Does this blacklist support IPv6 lookups? */ - char host[IRCD_RES_HOSTLEN + 1]; - char reject_reason[IRCD_BUFSIZE]; - unsigned int hits; - time_t lastwarning; + unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ + int refcount; + int ipv4; /* Does this blacklist support IPv4 lookups? */ + int ipv6; /* Does this blacklist support IPv6 lookups? */ + char host[IRCD_RES_HOSTLEN + 1]; + char reject_reason[IRCD_BUFSIZE]; + unsigned int hits; + time_t lastwarning; }; /* A lookup in progress for a particular DNSBL for a particular client */ struct BlacklistClient { - struct Blacklist *blacklist; - struct Client *client_p; - struct DNSQuery dns_query; - rb_dlink_node node; + struct Blacklist *blacklist; + struct Client *client_p; + struct DNSQuery dns_query; + rb_dlink_node node; }; /* public interfaces */ -struct Blacklist *new_blacklist(char *host, char *reject_reason, int ipv4, int ipv6); +struct Blacklist *new_blacklist(char *host, char *reject_reason, int ipv4, int ipv6); void lookup_blacklists(struct Client *client_p); void abort_blacklist_queries(struct Client *client_p); void unref_blacklist(struct Blacklist *blptr); diff --git a/include/cache.h b/include/cache.h index ace0f19..2e05a04 100644 --- a/include/cache.h +++ b/include/cache.h @@ -14,17 +14,15 @@ struct Client; -struct cachefile -{ - char name[CACHEFILELEN]; - rb_dlink_list contents; - int flags; +struct cachefile { + char name[CACHEFILELEN]; + rb_dlink_list contents; + int flags; }; -struct cacheline -{ - char data[CACHELINELEN]; - rb_dlink_node linenode; +struct cacheline { + char data[CACHELINELEN]; + rb_dlink_node linenode; }; extern struct cachefile *user_motd; diff --git a/include/channel.h b/include/channel.h index 1a667cb..e287618 100644 --- a/include/channel.h +++ b/include/channel.h @@ -35,110 +35,102 @@ struct Client; /* mode structure for channels */ -struct Mode -{ - unsigned int mode; - int limit; - char key[KEYLEN]; - unsigned int join_num; - unsigned int join_time; - char forward[LOC_CHANNELLEN + 1]; +struct Mode { + unsigned int mode; + int limit; + char key[KEYLEN]; + unsigned int join_num; + unsigned int join_time; + char forward[LOC_CHANNELLEN + 1]; }; /* channel structure */ -struct Channel -{ - rb_dlink_node node; - struct Mode mode; - char *mode_lock; - char *topic; - char *topic_info; - time_t topic_time; - time_t last_knock; /* don't allow knock to flood */ +struct Channel { + rb_dlink_node node; + struct Mode mode; + char *mode_lock; + char *topic; + char *topic_info; + time_t topic_time; + time_t last_knock; /* don't allow knock to flood */ - rb_dlink_list members; /* channel members */ - rb_dlink_list locmembers; /* local channel members */ + rb_dlink_list members; /* channel members */ + rb_dlink_list locmembers; /* local channel members */ - rb_dlink_list invites; - rb_dlink_list banlist; - rb_dlink_list exceptlist; - rb_dlink_list invexlist; - rb_dlink_list quietlist; + rb_dlink_list invites; + rb_dlink_list banlist; + rb_dlink_list exceptlist; + rb_dlink_list invexlist; + rb_dlink_list quietlist; - time_t first_received_message_time; /* channel flood control */ - int received_number_of_privmsgs; - int flood_noticed; + time_t first_received_message_time; /* channel flood control */ + int received_number_of_privmsgs; + int flood_noticed; - unsigned int join_count; /* joins within delta */ - unsigned int join_delta; /* last ts of join */ + unsigned int join_count; /* joins within delta */ + unsigned int join_delta; /* last ts of join */ - struct Dictionary *metadata; + struct Dictionary *metadata; - unsigned long bants; - time_t channelts; - char *chname; + unsigned long bants; + time_t channelts; + char *chname; }; -struct membership -{ - rb_dlink_node channode; - rb_dlink_node locchannode; - rb_dlink_node usernode; +struct membership { + rb_dlink_node channode; + rb_dlink_node locchannode; + rb_dlink_node usernode; - struct Channel *chptr; - struct Client *client_p; - unsigned int flags; + struct Channel *chptr; + struct Client *client_p; + unsigned int flags; - unsigned long bants; + unsigned long bants; }; #define BANLEN 195 -struct Ban -{ - char *banstr; - char *who; - time_t when; - rb_dlink_node node; +struct Ban { + char *banstr; + char *who; + time_t when; + rb_dlink_node node; }; -struct mode_letter -{ - int mode; - char letter; +struct mode_letter { + int mode; + char letter; }; -struct ChModeChange -{ - char letter; - const char *arg; - const char *id; - int dir; - int caps; - int nocaps; - int mems; - int override; - struct Client *client; +struct ChModeChange { + char letter; + const char *arg; + const char *id; + int dir; + int caps; + int nocaps; + int mems; + int override; + struct Client *client; }; -struct ChCapCombo -{ - int count; - int cap_yes; - int cap_no; +struct ChCapCombo { + int count; + int cap_yes; + int cap_no; }; typedef void (*ChannelModeFunc)(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); -struct ChannelMode -{ - ChannelModeFunc set_func; - long mode_type; +struct ChannelMode { + ChannelModeFunc set_func; + long mode_type; }; typedef int (*ExtbanFunc)(const char *data, struct Client *client_p, - struct Channel *chptr, long mode_type); + struct Channel *chptr, long mode_type); /* can_send results */ #define CAN_SEND_NO 0 @@ -232,14 +224,14 @@ void free_ban(struct Ban *bptr); extern void destroy_channel(struct Channel *); -extern int can_send(struct Channel *chptr, struct Client *who, - struct membership *); +extern int can_send(struct Channel *chptr, struct Client *who, + struct membership *); extern int flood_attack_channel(int p_or_n, struct Client *source_p, - struct Channel *chptr, char *chname); + struct Channel *chptr, char *chname); extern int is_banned(struct Channel *chptr, struct Client *who, - struct membership *msptr, const char *, const char *); + struct membership *msptr, const char *, const char *); extern int is_quieted(struct Channel *chptr, struct Client *who, - struct membership *msptr, const char *, const char *); + struct membership *msptr, const char *, const char *); extern int can_join(struct Client *source_p, struct Channel *chptr, char *key); extern struct membership *find_channel_membership(struct Channel *, struct Client *); @@ -260,7 +252,7 @@ extern void free_channel_list(rb_dlink_list *); extern int check_channel_name(const char *name); extern void channel_member_names(struct Channel *chptr, struct Client *, - int show_eon); + int show_eon); extern void del_invite(struct Channel *chptr, struct Client *who); @@ -277,25 +269,25 @@ extern void check_spambot_warning(struct Client *source_p, const char *name); extern void check_splitmode(void *); void set_channel_topic(struct Channel *chptr, const char *topic, - const char *topic_info, time_t topicts); + const char *topic_info, time_t topicts); extern void init_chcap_usage_counts(void); extern void set_chcap_usage_counts(struct Client *serv_p); extern void unset_chcap_usage_counts(struct Client *serv_p); extern void send_cap_mode_changes(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, struct ChModeChange foo[], int); + struct Channel *chptr, struct ChModeChange foo[], int); void resv_chan_forcepart(const char *name, const char *reason, int temp_time); extern void set_channel_mode(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]); + struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]); extern void set_channel_mlock(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, const char *newmlock, int propagate); + struct Channel *chptr, const char *newmlock, int propagate); extern struct ChannelMode chmode_table[256]; extern int add_id(struct Client *source_p, struct Channel *chptr, const char *banid, - rb_dlink_list * list, long mode_type); + rb_dlink_list * list, long mode_type); extern int del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type); diff --git a/include/chmode.h b/include/chmode.h index e5d0b8e..2859132 100644 --- a/include/chmode.h +++ b/include/chmode.h @@ -37,50 +37,50 @@ extern int chmode_flags[256]; extern void chm_nosuch(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_orphaned(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_simple(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_ban(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_hidden(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_staff(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_forward(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_throttle(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_key(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_limit(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_owner(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_admin(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_op(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_halfop(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_voice(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type); + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern unsigned int cflag_add(char c, ChannelModeFunc function); extern void cflag_orphan(char c); diff --git a/include/class.h b/include/class.h index 85457b3..e3c08e7 100644 --- a/include/class.h +++ b/include/class.h @@ -30,22 +30,21 @@ struct ConfItem; struct Client; struct _patricia_tree_t; -struct Class -{ - struct Class *next; - char *class_name; - int max_total; - int max_local; - int max_global; - int max_ident; - int max_sendq; - int con_freq; - int ping_freq; - int total; - rb_patricia_tree_t *ip_limits; - int cidr_ipv4_bitlen; - int cidr_ipv6_bitlen; - int cidr_amount; +struct Class { + struct Class *next; + char *class_name; + int max_total; + int max_local; + int max_global; + int max_ident; + int max_sendq; + int con_freq; + int ping_freq; + int total; + rb_patricia_tree_t *ip_limits; + int cidr_ipv4_bitlen; + int cidr_ipv6_bitlen; + int cidr_amount; }; diff --git a/include/client.h b/include/client.h index a00e65f..70fd0d1 100644 --- a/include/client.h +++ b/include/client.h @@ -76,238 +76,231 @@ struct scache_entry; /* * Client structures */ -struct User -{ - rb_dlink_list channel; /* chain of channel pointer blocks */ - rb_dlink_list invited; /* chain of invite pointer blocks */ - char *away; /* pointer to away message */ - int refcnt; /* Number of times this block is referenced */ +struct User { + rb_dlink_list channel; /* chain of channel pointer blocks */ + rb_dlink_list invited; /* chain of invite pointer blocks */ + char *away; /* pointer to away message */ + int refcnt; /* Number of times this block is referenced */ - struct Dictionary *metadata; + struct Dictionary *metadata; - char suser[NICKLEN+1]; + char suser[NICKLEN+1]; }; -struct Server -{ - struct User *user; /* who activated this connection */ - char by[NICKLEN]; - rb_dlink_list servers; - rb_dlink_list users; - int caps; /* capabilities bit-field */ - char *fullcaps; - struct scache_entry *nameinfo; +struct Server { + struct User *user; /* who activated this connection */ + char by[NICKLEN]; + rb_dlink_list servers; + rb_dlink_list users; + int caps; /* capabilities bit-field */ + char *fullcaps; + struct scache_entry *nameinfo; }; -struct ZipStats -{ - unsigned long long in; - unsigned long long in_wire; - unsigned long long out; - unsigned long long out_wire; - double in_ratio; - double out_ratio; +struct ZipStats { + unsigned long long in; + unsigned long long in_wire; + unsigned long long out; + unsigned long long out_wire; + double in_ratio; + double out_ratio; }; -struct Client -{ - rb_dlink_node node; - rb_dlink_node lnode; - struct User *user; /* ...defined, if this is a User */ - struct Server *serv; /* ...defined, if this is a server */ - struct Client *servptr; /* Points to server this Client is on */ - struct Client *from; /* == self, if Local Client, *NEVER* NULL! */ +struct Client { + rb_dlink_node node; + rb_dlink_node lnode; + struct User *user; /* ...defined, if this is a User */ + struct Server *serv; /* ...defined, if this is a server */ + struct Client *servptr; /* Points to server this Client is on */ + struct Client *from; /* == self, if Local Client, *NEVER* NULL! */ - struct Whowas *whowas; /* Pointers to whowas structs */ - time_t tsinfo; /* TS on the nick, SVINFO on server */ - unsigned int umodes; /* opers, normal users subset */ - unsigned int flags; /* client flags */ - unsigned int flags2; /* ugh. overflow */ + struct Whowas *whowas; /* Pointers to whowas structs */ + time_t tsinfo; /* TS on the nick, SVINFO on server */ + unsigned int umodes; /* opers, normal users subset */ + unsigned int flags; /* client flags */ + unsigned int flags2; /* ugh. overflow */ - unsigned int snomask; /* server notice mask */ + unsigned int snomask; /* server notice mask */ - int hopcount; /* number of servers to this 0 = local */ - unsigned short status; /* Client type */ - unsigned char handler; /* Handler index */ - unsigned long serial; /* used to enforce 1 send per nick */ + int hopcount; /* number of servers to this 0 = local */ + unsigned short status; /* Client type */ + unsigned char handler; /* Handler index */ + unsigned long serial; /* used to enforce 1 send per nick */ - /* client->name is the unique name for a client nick or host */ - char name[HOSTLEN + 1]; + /* client->name is the unique name for a client nick or host */ + char name[HOSTLEN + 1]; - /* - * client->username is the username from ident or the USER message, - * If the client is idented the USER message is ignored, otherwise - * the username part of the USER message is put here prefixed with a - * tilde depending on the I:line, Once a client has registered, this - * field should be considered read-only. - */ - char username[USERLEN + 1]; /* client's username */ + /* + * client->username is the username from ident or the USER message, + * If the client is idented the USER message is ignored, otherwise + * the username part of the USER message is put here prefixed with a + * tilde depending on the I:line, Once a client has registered, this + * field should be considered read-only. + */ + char username[USERLEN + 1]; /* client's username */ - /* - * client->host contains the resolved name or ip address - * as a string for the user, it may be fiddled with for oper spoofing etc. - */ - char host[HOSTLEN + 1]; /* client's hostname */ - char orighost[HOSTLEN + 1]; /* original hostname (before dynamic spoofing) */ - char sockhost[HOSTIPLEN + 1]; /* clients ip */ - char info[REALLEN + 1]; /* Free form additional client info */ + /* + * client->host contains the resolved name or ip address + * as a string for the user, it may be fiddled with for oper spoofing etc. + */ + char host[HOSTLEN + 1]; /* client's hostname */ + char orighost[HOSTLEN + 1]; /* original hostname (before dynamic spoofing) */ + char sockhost[HOSTIPLEN + 1]; /* clients ip */ + char info[REALLEN + 1]; /* Free form additional client info */ - char id[IDLEN]; /* UID/SID, unique on the network */ + char id[IDLEN]; /* UID/SID, unique on the network */ - /* list of who has this client on their allow list, its counterpart - * is in LocalUser - */ - rb_dlink_list on_allow_list; + /* list of who has this client on their allow list, its counterpart + * is in LocalUser + */ + rb_dlink_list on_allow_list; - time_t first_received_message_time; - int received_number_of_privmsgs; - int flood_noticed; + time_t first_received_message_time; + int received_number_of_privmsgs; + int flood_noticed; - struct LocalUser *localClient; - struct PreClient *preClient; + struct LocalUser *localClient; + struct PreClient *preClient; - time_t large_ctcp_sent; /* ctcp to large group sent, relax flood checks */ - char *certfp; /* client certificate fingerprint */ + time_t large_ctcp_sent; /* ctcp to large group sent, relax flood checks */ + char *certfp; /* client certificate fingerprint */ }; -struct LocalUser -{ - rb_dlink_node tnode; /* This is the node for the local list type the client is on*/ - /* - * The following fields are allocated only for local clients - * (directly connected to *this* server with a socket. - */ - /* Anti flooding part, all because of lamers... */ - time_t last_join_time; /* when this client last +struct LocalUser { + rb_dlink_node tnode; /* This is the node for the local list type the client is on*/ + /* + * The following fields are allocated only for local clients + * (directly connected to *this* server with a socket. + */ + /* Anti flooding part, all because of lamers... */ + time_t last_join_time; /* when this client last joined a channel */ - time_t last_leave_time; /* when this client last + time_t last_leave_time; /* when this client last * left a channel */ - int join_leave_count; /* count of JOIN/LEAVE in less than + int join_leave_count; /* count of JOIN/LEAVE in less than MIN_JOIN_LEAVE_TIME seconds */ - int oper_warn_count_down; /* warn opers of this possible + int oper_warn_count_down; /* warn opers of this possible spambot every time this gets to 0 */ - time_t last_caller_id_time; + time_t last_caller_id_time; - time_t lasttime; /* last time we parsed something */ - time_t firsttime; /* time client was created */ + time_t lasttime; /* last time we parsed something */ + time_t firsttime; /* time client was created */ - /* Send and receive linebuf queues .. */ - buf_head_t buf_sendq; - buf_head_t buf_recvq; - /* - * we want to use unsigned int here so the sizes have a better chance of - * staying the same on 64 bit machines. The current trend is to use - * I32LP64, (32 bit ints, 64 bit longs and pointers) and since ircd - * will NEVER run on an operating system where ints are less than 32 bits, - * it's a relatively safe bet to use ints. Since right shift operations are - * performed on these, it's not safe to allow them to become negative, - * which is possible for long running server connections. Unsigned values - * generally overflow gracefully. --Bleep - */ - unsigned int sendM; /* Statistics: protocol messages send */ - unsigned int sendK; /* Statistics: total k-bytes send */ - unsigned int receiveM; /* Statistics: protocol messages received */ - unsigned int receiveK; /* Statistics: total k-bytes received */ - unsigned short sendB; /* counters to count upto 1-k lots of bytes */ - unsigned short receiveB; /* sent and received. */ - struct Listener *listener; /* listener accepted from */ - struct ConfItem *att_conf; /* attached conf */ - struct server_conf *att_sconf; + /* Send and receive linebuf queues .. */ + buf_head_t buf_sendq; + buf_head_t buf_recvq; + /* + * we want to use unsigned int here so the sizes have a better chance of + * staying the same on 64 bit machines. The current trend is to use + * I32LP64, (32 bit ints, 64 bit longs and pointers) and since ircd + * will NEVER run on an operating system where ints are less than 32 bits, + * it's a relatively safe bet to use ints. Since right shift operations are + * performed on these, it's not safe to allow them to become negative, + * which is possible for long running server connections. Unsigned values + * generally overflow gracefully. --Bleep + */ + unsigned int sendM; /* Statistics: protocol messages send */ + unsigned int sendK; /* Statistics: total k-bytes send */ + unsigned int receiveM; /* Statistics: protocol messages received */ + unsigned int receiveK; /* Statistics: total k-bytes received */ + unsigned short sendB; /* counters to count upto 1-k lots of bytes */ + unsigned short receiveB; /* sent and received. */ + struct Listener *listener; /* listener accepted from */ + struct ConfItem *att_conf; /* attached conf */ + struct server_conf *att_sconf; - struct rb_sockaddr_storage ip; - time_t last_nick_change; - int number_of_nick_changes; + struct rb_sockaddr_storage ip; + time_t last_nick_change; + int number_of_nick_changes; - /* - * XXX - there is no reason to save this, it should be checked when it's - * received and not stored, this is not used after registration - * - * agreed. lets get rid of it someday! --nenolod - */ - char *passwd; - char *auth_user; - char *opername; /* name of operator{} block being used or tried (challenge) */ - char *challenge; - char *fullcaps; + /* + * XXX - there is no reason to save this, it should be checked when it's + * received and not stored, this is not used after registration + * + * agreed. lets get rid of it someday! --nenolod + */ + char *passwd; + char *auth_user; + char *opername; /* name of operator{} block being used or tried (challenge) */ + char *challenge; + char *fullcaps; - int caps; /* capabilities bit-field */ - rb_fde_t *F; /* >= 0, for local clients */ + int caps; /* capabilities bit-field */ + rb_fde_t *F; /* >= 0, for local clients */ - /* time challenge response is valid for */ - time_t chal_time; + /* time challenge response is valid for */ + time_t chal_time; - struct DNSQuery *dnsquery; /* for outgoing server's name lookup */ + struct DNSQuery *dnsquery; /* for outgoing server's name lookup */ time_t next_away; /* Don't allow next away before... */ - time_t last; + time_t last; - /* clients allowed to talk through +g */ - rb_dlink_list allow_list; + /* clients allowed to talk through +g */ + rb_dlink_list allow_list; - /* nicknames theyre monitoring */ - rb_dlink_list monitor_list; + /* nicknames theyre monitoring */ + rb_dlink_list monitor_list; - /* - * Anti-flood stuff. We track how many messages were parsed and how - * many we were allowed in the current second, and apply a simple decay - * to avoid flooding. - * -- adrian - */ - int allow_read; /* how many we're allowed to read in this second */ - int actually_read; /* how many we've actually read in this second */ - int sent_parsed; /* how many messages we've parsed in this second */ - time_t last_knock; /* time of last knock */ - unsigned long random_ping; - struct AuthRequest *auth_request; + /* + * Anti-flood stuff. We track how many messages were parsed and how + * many we were allowed in the current second, and apply a simple decay + * to avoid flooding. + * -- adrian + */ + int allow_read; /* how many we're allowed to read in this second */ + int actually_read; /* how many we've actually read in this second */ + int sent_parsed; /* how many messages we've parsed in this second */ + time_t last_knock; /* time of last knock */ + unsigned long random_ping; + struct AuthRequest *auth_request; - /* target change stuff */ - /* targets we're aware of (fnv32(use_id(target_p))): - * 0..TGCHANGE_NUM-1 regular slots - * TGCHANGE_NUM..TGCHANGE_NUM+TGCHANGE_REPLY-1 reply slots - */ - uint32_t targets[TGCHANGE_NUM + TGCHANGE_REPLY]; - unsigned int targets_free; /* free targets */ - time_t target_last; /* last time we cleared a slot */ + /* target change stuff */ + /* targets we're aware of (fnv32(use_id(target_p))): + * 0..TGCHANGE_NUM-1 regular slots + * TGCHANGE_NUM..TGCHANGE_NUM+TGCHANGE_REPLY-1 reply slots + */ + uint32_t targets[TGCHANGE_NUM + TGCHANGE_REPLY]; + unsigned int targets_free; /* free targets */ + time_t target_last; /* last time we cleared a slot */ - struct ListClient *safelist_data; + struct ListClient *safelist_data; - char *mangledhost; /* non-NULL if host mangling module loaded and + char *mangledhost; /* non-NULL if host mangling module loaded and applicable to this client */ - struct _ssl_ctl *ssl_ctl; /* which ssl daemon we're associate with */ - struct _ssl_ctl *z_ctl; /* second ctl for ssl+zlib */ - uint32_t localflags; - struct ZipStats *zipstats; /* zipstats */ - uint16_t cork_count; /* used for corking/uncorking connections */ - struct ev_entry *event; /* used for associated events */ + struct _ssl_ctl *ssl_ctl; /* which ssl daemon we're associate with */ + struct _ssl_ctl *z_ctl; /* second ctl for ssl+zlib */ + uint32_t localflags; + struct ZipStats *zipstats; /* zipstats */ + uint16_t cork_count; /* used for corking/uncorking connections */ + struct ev_entry *event; /* used for associated events */ - struct PrivilegeSet *privset; /* privset... */ + struct PrivilegeSet *privset; /* privset... */ - struct ev_entry *override_timeout_event; + struct ev_entry *override_timeout_event; }; -struct PreClient -{ - char spoofnick[NICKLEN + 1]; - char spoofuser[USERLEN + 1]; - char spoofhost[HOSTLEN + 1]; +struct PreClient { + char spoofnick[NICKLEN + 1]; + char spoofuser[USERLEN + 1]; + char spoofhost[HOSTLEN + 1]; - char sasl_agent[IDLEN]; - unsigned char sasl_out; - unsigned char sasl_complete; + char sasl_agent[IDLEN]; + unsigned char sasl_out; + unsigned char sasl_complete; - rb_dlink_list dnsbl_queries; /* list of struct BlacklistClient * */ - struct Blacklist *dnsbl_listed; /* first dnsbl where it's listed */ + rb_dlink_list dnsbl_queries; /* list of struct BlacklistClient * */ + struct Blacklist *dnsbl_listed; /* first dnsbl where it's listed */ - struct rb_sockaddr_storage lip; /* address of our side of the connection */ + struct rb_sockaddr_storage lip; /* address of our side of the connection */ }; -struct ListClient -{ - unsigned int hash_indice; - unsigned int users_min, users_max; - time_t created_min, created_max, topic_min, topic_max; - int operspy; +struct ListClient { + unsigned int hash_indice; + unsigned int users_min, users_max; + time_t created_min, created_max, topic_min, topic_max; + int operspy; }; /* diff --git a/include/config.h b/include/config.h index f3e414d..94b238a 100644 --- a/include/config.h +++ b/include/config.h @@ -28,7 +28,7 @@ #include "setup.h" -/* +/* * Directory paths and filenames for UNIX systems. * IRCD_PREFIX is set using ./configure --prefix, see INSTALL. * The other defaults should be fine. @@ -52,7 +52,7 @@ #define LIBPATH IRCD_PREFIX "/lib/" #define MODPATH MODULE_DIR #define AUTOMODPATH MODULE_DIR "/autoload/" -#define ETCPATH ETC_DIR +#define ETCPATH ETC_DIR #define LOGPATH LOG_DIR #define UHPATH HELP_DIR "/users" #define HPATH HELP_DIR "/opers" @@ -94,7 +94,7 @@ #define KILLCHASETIMELIMIT 90 /* Recommended value: 90 */ /* RATBOX_SOMAXCONN - * Use SOMAXCONN if OS has it, otherwise use this value for the + * Use SOMAXCONN if OS has it, otherwise use this value for the * listen(); backlog. 5 for AIX/SUNOS, 25 for other OSs. */ #define RATBOX_SOMAXCONN 25 diff --git a/include/hook.h b/include/hook.h index 8e3c025..f11ef6b 100644 --- a/include/hook.h +++ b/include/hook.h @@ -6,10 +6,9 @@ #ifndef INCLUDED_HOOK_H #define INCLUDED_HOOK_H -typedef struct -{ - char *name; - rb_dlink_list hooks; +typedef struct { + char *name; + rb_dlink_list hooks; } hook; typedef void (*hookfn) (void *data); @@ -36,67 +35,58 @@ void add_hook(const char *name, hookfn fn); void remove_hook(const char *name, hookfn fn); void call_hook(int id, void *arg); -typedef struct -{ - struct Client *client; - const void *arg1; - const void *arg2; +typedef struct { + struct Client *client; + const void *arg1; + const void *arg2; } hook_data; -typedef struct -{ - struct Client *client; - const void *arg1; - int arg2; +typedef struct { + struct Client *client; + const void *arg1; + int arg2; } hook_data_int; -typedef struct -{ - struct Client *client; - struct Client *target; +typedef struct { + struct Client *client; + struct Client *target; } hook_data_client; -typedef struct -{ - struct Client *client; - struct Channel *chptr; - int approved; +typedef struct { + struct Client *client; + struct Channel *chptr; + int approved; } hook_data_channel; -typedef struct -{ - struct Client *client; - struct Channel *chptr; - char *key; +typedef struct { + struct Client *client; + struct Channel *chptr; + char *key; } hook_data_channel_activity; -typedef struct -{ - struct Client *client; - struct Channel *chptr; - struct Client *target; - int approved; +typedef struct { + struct Client *client; + struct Channel *chptr; + struct Client *target; + int approved; } hook_data_channel_approval; -typedef struct -{ - struct Client *client; - int approved; +typedef struct { + struct Client *client; + int approved; } hook_data_client_approval; -typedef struct -{ - struct Client *local_link; /* local client originating this, or NULL */ - struct Client *target; /* dying client */ - struct Client *from; /* causing client (could be &me or target) */ - const char *comment; +typedef struct { + struct Client *local_link; /* local client originating this, or NULL */ + struct Client *target; /* dying client */ + struct Client *from; /* causing client (could be &me or target) */ + const char *comment; } hook_data_client_exit; -typedef struct -{ - struct Client *client; - unsigned int oldumodes; - unsigned int oldsnomask; +typedef struct { + struct Client *client; + unsigned int oldumodes; + unsigned int oldsnomask; } hook_data_umode_changed; #endif diff --git a/include/hostmask.h b/include/hostmask.h index e181293..deef081 100644 --- a/include/hostmask.h +++ b/include/hostmask.h @@ -26,29 +26,28 @@ #ifndef INCLUDE_hostmask_h #define INCLUDE_hostmask_h 1 -enum -{ - HM_HOST, - HM_IPV4 +enum { + HM_HOST, + HM_IPV4 #ifdef RB_IPV6 - , HM_IPV6 + , HM_IPV6 #endif }; int parse_netmask(const char *, struct sockaddr *, int *); struct ConfItem *find_conf_by_address(const char *host, const char *sockhost, - const char *orighost, struct sockaddr *, - int, int, const char *, const char *); + const char *orighost, struct sockaddr *, + int, int, const char *, const char *); struct ConfItem *find_exact_conf_by_address(const char *address, int type, - const char *username); + const char *username); void add_conf_by_address(const char *, int, const char *, const char *, struct ConfItem *); void delete_one_address_conf(const char *, struct ConfItem *); void clear_out_address_conf(void); void clear_out_address_conf_bans(void); void init_host_hash(void); -struct ConfItem *find_address_conf(const char *host, const char *sockhost, - const char *, const char *, struct sockaddr *, - int, char *); +struct ConfItem *find_address_conf(const char *host, const char *sockhost, + const char *, const char *, struct sockaddr *, + int, char *); struct ConfItem *find_dline(struct sockaddr *, int); @@ -70,40 +69,37 @@ int match_ipv4(struct sockaddr *, struct sockaddr *, int); extern struct AddressRec *atable[ATABLE_SIZE]; -struct AddressRec -{ - /* masktype: HM_HOST, HM_IPV4, HM_IPV6 -A1kmm */ - int masktype; +struct AddressRec { + /* masktype: HM_HOST, HM_IPV4, HM_IPV6 -A1kmm */ + int masktype; - union - { - struct - { - /* Pointer into ConfItem... -A1kmm */ - struct rb_sockaddr_storage addr; - int bits; - } - ipa; + union { + struct { + /* Pointer into ConfItem... -A1kmm */ + struct rb_sockaddr_storage addr; + int bits; + } + ipa; - /* Pointer into ConfItem... -A1kmm */ - const char *hostname; - } - Mask; + /* Pointer into ConfItem... -A1kmm */ + const char *hostname; + } + Mask; - /* type: CONF_CLIENT, CONF_DLINE, CONF_KILL etc... -A1kmm */ - int type; + /* type: CONF_CLIENT, CONF_DLINE, CONF_KILL etc... -A1kmm */ + int type; - /* Higher precedences overrule lower ones... */ - unsigned long precedence; + /* Higher precedences overrule lower ones... */ + unsigned long precedence; - /* Only checked if !(type & 1)... */ - const char *username; - /* Only checked if type == CONF_CLIENT */ - const char *auth_user; - struct ConfItem *aconf; + /* Only checked if !(type & 1)... */ + const char *username; + /* Only checked if type == CONF_CLIENT */ + const char *auth_user; + struct ConfItem *aconf; - /* The next record in this hash bucket. */ - struct AddressRec *next; + /* The next record in this hash bucket. */ + struct AddressRec *next; }; diff --git a/include/inline/stringops.h b/include/inline/stringops.h index 8023763..0e14c1f 100644 --- a/include/inline/stringops.h +++ b/include/inline/stringops.h @@ -30,96 +30,90 @@ static inline char * strip_colour(char *string) { - char *c = string; - char *c2 = string; - char *last_non_space = NULL; + char *c = string; + char *c2 = string; + char *last_non_space = NULL; - /* c is source, c2 is target */ - for(; c && *c; c++) - switch (*c) - { - case 3: - if(isdigit(c[1])) - { - c++; - if(isdigit(c[1])) - c++; - if(c[1] == ',' && isdigit(c[2])) - { - c += 2; - if(isdigit(c[1])) - c++; - } - } - break; - case 2: - case 6: - case 7: - case 22: - case 23: - case 27: - case 29: - case 31: - break; - case 32: - *c2++ = *c; - break; - default: - *c2++ = *c; - last_non_space = c2; - break; - } + /* c is source, c2 is target */ + for(; c && *c; c++) + switch (*c) { + case 3: + if(isdigit(c[1])) { + c++; + if(isdigit(c[1])) + c++; + if(c[1] == ',' && isdigit(c[2])) { + c += 2; + if(isdigit(c[1])) + c++; + } + } + break; + case 2: + case 6: + case 7: + case 22: + case 23: + case 27: + case 29: + case 31: + break; + case 32: + *c2++ = *c; + break; + default: + *c2++ = *c; + last_non_space = c2; + break; + } - *c2 = '\0'; + *c2 = '\0'; - if(last_non_space) - *last_non_space = '\0'; + if(last_non_space) + *last_non_space = '\0'; - return string; + return string; } static inline char * strip_unprintable(char *string) { - char *c = string; - char *c2 = string; - char *last_non_space = NULL; + char *c = string; + char *c2 = string; + char *last_non_space = NULL; - /* c is source, c2 is target */ - for(; c && *c; c++) - switch (*c) - { - case 3: - if(isdigit(c[1])) - { - c++; - if(isdigit(c[1])) - c++; - if(c[1] == ',' && isdigit(c[2])) - { - c += 2; - if(isdigit(c[1])) - c++; - } - } - break; - case 32: - *c2++ = *c; - break; - default: - if (*c < 32 && *c >= 0) - break; - *c2++ = *c; - last_non_space = c2; - break; - } + /* c is source, c2 is target */ + for(; c && *c; c++) + switch (*c) { + case 3: + if(isdigit(c[1])) { + c++; + if(isdigit(c[1])) + c++; + if(c[1] == ',' && isdigit(c[2])) { + c += 2; + if(isdigit(c[1])) + c++; + } + } + break; + case 32: + *c2++ = *c; + break; + default: + if (*c < 32 && *c >= 0) + break; + *c2++ = *c; + last_non_space = c2; + break; + } - *c2 = '\0'; + *c2 = '\0'; - if(last_non_space) - *last_non_space = '\0'; + if(last_non_space) + *last_non_space = '\0'; - return string; + return string; } #endif diff --git a/include/irc_dictionary.h b/include/irc_dictionary.h index 69f3bab..4a464ef 100644 --- a/include/irc_dictionary.h +++ b/include/irc_dictionary.h @@ -29,17 +29,15 @@ struct Dictionary; /* defined in src/dictionary.c */ typedef int (*DCF)(const char *a, const char *b); -struct DictionaryElement -{ - struct DictionaryElement *left, *right, *prev, *next; - void *data; - const char *key; - int position; +struct DictionaryElement { + struct DictionaryElement *left, *right, *prev, *next; + void *data; + const char *key; + int position; }; -struct DictionaryIter -{ - struct DictionaryElement *cur, *next; +struct DictionaryIter { + struct DictionaryElement *cur, *next; }; /* @@ -65,7 +63,7 @@ extern struct Dictionary *irc_dictionary_create_named(const char *name, DCF comp * insertions in the DTree structure. */ extern void irc_dictionary_set_comparator_func(struct Dictionary *dict, - DCF compare_cb); + DCF compare_cb); /* * irc_dictionary_get_comparator_func() returns the comparator used for lookups and @@ -84,8 +82,8 @@ extern int irc_dictionary_get_linear_index(struct Dictionary *dict, const char * * a defined callback function to destroy any data attached to it. */ extern void irc_dictionary_destroy(struct Dictionary *dtree, - void (*destroy_cb)(struct DictionaryElement *delem, void *privdata), - void *privdata); + void (*destroy_cb)(struct DictionaryElement *delem, void *privdata), + void *privdata); /* * irc_dictionary_foreach() iterates all entries in a dtree, and also optionally calls @@ -94,8 +92,8 @@ extern void irc_dictionary_destroy(struct Dictionary *dtree, * To shortcircuit iteration, return non-zero from the callback function. */ extern void irc_dictionary_foreach(struct Dictionary *dtree, - int (*foreach_cb)(struct DictionaryElement *delem, void *privdata), - void *privdata); + int (*foreach_cb)(struct DictionaryElement *delem, void *privdata), + void *privdata); /* * irc_dictionary_search() iterates all entries in a dtree, and also optionally calls @@ -105,8 +103,8 @@ extern void irc_dictionary_foreach(struct Dictionary *dtree, * in that object being returned to the user. */ extern void *irc_dictionary_search(struct Dictionary *dtree, - void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata), - void *privdata); + void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata), + void *privdata); /* * irc_dictionary_foreach_start() begins an iteration over all items @@ -115,20 +113,20 @@ extern void *irc_dictionary_search(struct Dictionary *dtree, * of the iteration (but not any other element). */ extern void irc_dictionary_foreach_start(struct Dictionary *dtree, - struct DictionaryIter *state); + struct DictionaryIter *state); /* * irc_dictionary_foreach_cur() returns the current element of the iteration, * or NULL if there are no more elements. */ extern void *irc_dictionary_foreach_cur(struct Dictionary *dtree, - struct DictionaryIter *state); + struct DictionaryIter *state); /* * irc_dictionary_foreach_next() moves to the next element. */ extern void irc_dictionary_foreach_next(struct Dictionary *dtree, - struct DictionaryIter *state); + struct DictionaryIter *state); /* * irc_dictionary_add() adds a key->value entry to the dictionary tree. diff --git a/include/ircd.h b/include/ircd.h index 218b778..5b271d8 100644 --- a/include/ircd.h +++ b/include/ircd.h @@ -31,37 +31,34 @@ struct Client; struct rb_dlink_list; -struct SetOptions -{ - int maxclients; /* max clients allowed */ - int autoconn; /* autoconn enabled for all servers? */ +struct SetOptions { + int maxclients; /* max clients allowed */ + int autoconn; /* autoconn enabled for all servers? */ - int floodcount; /* Number of messages in 1 second */ - int ident_timeout; /* timeout for identd lookups */ + int floodcount; /* Number of messages in 1 second */ + int ident_timeout; /* timeout for identd lookups */ - int spam_num; - int spam_time; + int spam_num; + int spam_time; - char operhost[REALLEN]; - char operstring[REALLEN]; - char adminstring[REALLEN]; + char operhost[REALLEN]; + char operstring[REALLEN]; + char adminstring[REALLEN]; }; -struct Metadata -{ - const char *name; - const char *value; - time_t timevalue; +struct Metadata { + const char *name; + const char *value; + time_t timevalue; }; -struct Counter -{ - int oper; /* Opers */ - int total; /* total clients */ - int invisi; /* invisible clients */ - int max_loc; /* MAX local clients */ - int max_tot; /* MAX global clients */ - unsigned long totalrestartcount; /* Total client count ever */ +struct Counter { + int oper; /* Opers */ + int total; /* total clients */ + int invisi; /* invisible clients */ + int max_loc; /* MAX local clients */ + int max_tot; /* MAX global clients */ + unsigned long totalrestartcount; /* Total client count ever */ }; extern struct SetOptions GlobalSetOptions; /* defined in ircd.c */ diff --git a/include/ircd_defs.h b/include/ircd_defs.h index accf3d2..d851e03 100644 --- a/include/ircd_defs.h +++ b/include/ircd_defs.h @@ -26,7 +26,7 @@ /* * NOTE: NICKLEN and TOPICLEN do not live here anymore. Set it with configure - * Otherwise there are no user servicable part here. + * Otherwise there are no user servicable part here. * */ @@ -94,7 +94,7 @@ #endif #define HOSTLEN 63 /* Length of hostname. Updated to */ - /* comply with RFC1123 */ +/* comply with RFC1123 */ #define USERLEN 10 #define REALLEN 50 @@ -121,8 +121,8 @@ #define HELPLEN 400 -/* - * message return values +/* + * message return values */ #define CLIENT_EXITED -2 #define CLIENT_PARSE_ERROR -1 diff --git a/include/ircd_getopt.h b/include/ircd_getopt.h index f318ad3..a9bf620 100644 --- a/include/ircd_getopt.h +++ b/include/ircd_getopt.h @@ -26,14 +26,13 @@ #ifndef __GETOPT_H_INCLUDED__ #define __GETOPT_H_INCLUDED__ -struct lgetopt -{ - const char *opt; /* name of the argument */ - void *argloc; /* where we store the argument to it (-option argument) */ - enum - { INTEGER, YESNO, STRING, USAGE, ENDEBUG } - argtype; - const char *desc; /* description of the argument, usage for printing help */ +struct lgetopt { + const char *opt; /* name of the argument */ + void *argloc; /* where we store the argument to it (-option argument) */ + enum + { INTEGER, YESNO, STRING, USAGE, ENDEBUG } + argtype; + const char *desc; /* description of the argument, usage for printing help */ }; extern struct lgetopt myopts[]; diff --git a/include/ircd_linker.h b/include/ircd_linker.h index c38465f..4fcbcf2 100644 --- a/include/ircd_linker.h +++ b/include/ircd_linker.h @@ -37,10 +37,9 @@ #include -struct ircd_symbol -{ - char *sym; /* name of symbol to be bound to ptr */ - void *ptr; /* ptr to symbol in library */ +struct ircd_symbol { + char *sym; /* name of symbol to be bound to ptr */ + void *ptr; /* ptr to symbol in library */ }; extern void build_symtable(void *, struct ircd_symbol *); diff --git a/include/listener.h b/include/listener.h index 8a37db9..d5d637c 100644 --- a/include/listener.h +++ b/include/listener.h @@ -30,18 +30,17 @@ struct Client; -struct Listener -{ - struct Listener *next; /* list node pointer */ - const char *name; /* listener name */ - rb_fde_t *F; /* file descriptor */ - int ref_count; /* number of connection references */ - int active; /* current state of listener */ - int ssl; /* ssl listener */ - int defer_accept; /* use TCP_DEFER_ACCEPT */ - struct rb_sockaddr_storage addr; - struct DNSQuery *dns_query; - char vhost[HOSTLEN + 1]; /* virtual name of listener */ +struct Listener { + struct Listener *next; /* list node pointer */ + const char *name; /* listener name */ + rb_fde_t *F; /* file descriptor */ + int ref_count; /* number of connection references */ + int active; /* current state of listener */ + int ssl; /* ssl listener */ + int defer_accept; /* use TCP_DEFER_ACCEPT */ + struct rb_sockaddr_storage addr; + struct DNSQuery *dns_query; + char vhost[HOSTLEN + 1]; /* virtual name of listener */ }; extern void add_listener(int port, const char *vaddr_ip, int family, int ssl, int defer_accept); diff --git a/include/logger.h b/include/logger.h index 68b677c..5869c17 100644 --- a/include/logger.h +++ b/include/logger.h @@ -35,19 +35,18 @@ #include "ircd_defs.h" -typedef enum ilogfile -{ - L_MAIN, - L_USER, - L_FUSER, - L_OPERED, - L_FOPER, - L_SERVER, - L_KILL, - L_KLINE, - L_OPERSPY, - L_IOERROR, - LAST_LOGFILE +typedef enum ilogfile { + L_MAIN, + L_USER, + L_FUSER, + L_OPERED, + L_FOPER, + L_SERVER, + L_KILL, + L_KLINE, + L_OPERSPY, + L_IOERROR, + LAST_LOGFILE } ilogfile; struct Client; diff --git a/include/m_info.h b/include/m_info.h index 0291aef..dfaa18e 100644 --- a/include/m_info.h +++ b/include/m_info.h @@ -28,136 +28,155 @@ #include "config.h" -typedef struct Information -{ - const char *name; /* name of item */ - const char *strvalue; /* value of item if it's a boolean */ - int intvalue; /* value of item if it's an integer */ - const char *desc; /* short description of item */ +typedef struct Information { + const char *name; /* name of item */ + const char *strvalue; /* value of item if it's a boolean */ + int intvalue; /* value of item if it's an integer */ + const char *desc; /* short description of item */ } Info; Info MyInformation[] = { #ifdef CPATH - {"CPATH", CPATH, 0, "Path to Main Configuration File"}, + {"CPATH", CPATH, 0, "Path to Main Configuration File"}, #else - {"CPATH", "NONE", 0, "Path to Main Configuration File"}, + {"CPATH", "NONE", 0, "Path to Main Configuration File"}, #endif /* CPATH */ #ifdef DPATH - {"DPATH", DPATH, 0, "Directory Containing Configuration Files"}, + {"DPATH", DPATH, 0, "Directory Containing Configuration Files"}, #else - {"DPATH", "NONE", 0, "Directory Containing Configuration Files"}, + {"DPATH", "NONE", 0, "Directory Containing Configuration Files"}, #endif /* DPATH */ #ifdef HPATH - {"HPATH", HPATH, 0, "Path to Operator Help Files"}, + {"HPATH", HPATH, 0, "Path to Operator Help Files"}, #else - {"HPATH", "NONE", 0, "Path to Operator Help Files"}, + {"HPATH", "NONE", 0, "Path to Operator Help Files"}, #endif /* HPATH */ #ifdef UHPATH - {"UHPATH", UHPATH, 0, "Path to User Help Files"}, + {"UHPATH", UHPATH, 0, "Path to User Help Files"}, #else - {"UHPATH", "NONE", 0, "Path to User Help Files"}, + {"UHPATH", "NONE", 0, "Path to User Help Files"}, #endif /* UH PATH */ #ifdef SOMAXCONN - {"RATBOX_SOMAXCONN", "", SOMAXCONN, - "Maximum Queue Length of Pending Connections"}, + { + "RATBOX_SOMAXCONN", "", SOMAXCONN, + "Maximum Queue Length of Pending Connections" + }, #else - {"RATBOX_SOMAXCONN", "", RATBOX_SOMAXCONN, - "Maximum Queue Length of Pending Connections"}, + { + "RATBOX_SOMAXCONN", "", RATBOX_SOMAXCONN, + "Maximum Queue Length of Pending Connections" + }, #endif /* SOMAXCONN */ #ifdef RB_IPV6 - {"IPV6", "ON", 0, "IPv6 Support"}, + {"IPV6", "ON", 0, "IPv6 Support"}, #else - {"IPV6", "OFF", 0, "IPv6 Support"}, + {"IPV6", "OFF", 0, "IPv6 Support"}, #endif - {"JOIN_LEAVE_COUNT_EXPIRE_TIME", "", JOIN_LEAVE_COUNT_EXPIRE_TIME, - "Anti SpamBot Parameter"}, + { + "JOIN_LEAVE_COUNT_EXPIRE_TIME", "", JOIN_LEAVE_COUNT_EXPIRE_TIME, + "Anti SpamBot Parameter" + }, - {"KILLCHASETIMELIMIT", "", KILLCHASETIMELIMIT, - "Nick Change Tracker for KILL"}, + { + "KILLCHASETIMELIMIT", "", KILLCHASETIMELIMIT, + "Nick Change Tracker for KILL" + }, #ifdef LPATH - {"LPATH", LPATH, 0, "Path to Log File"}, + {"LPATH", LPATH, 0, "Path to Log File"}, #else - {"LPATH", "NONE", 0, "Path to Log File"}, + {"LPATH", "NONE", 0, "Path to Log File"}, #endif /* LPATH */ - {"MAX_BUFFER", "", MAX_BUFFER, "Maximum Buffer Connections Allowed"}, + {"MAX_BUFFER", "", MAX_BUFFER, "Maximum Buffer Connections Allowed"}, - {"MAX_JOIN_LEAVE_COUNT", "", MAX_JOIN_LEAVE_COUNT, - "Anti SpamBot Parameter"}, + { + "MAX_JOIN_LEAVE_COUNT", "", MAX_JOIN_LEAVE_COUNT, + "Anti SpamBot Parameter" + }, - {"MIN_JOIN_LEAVE_TIME", "", MIN_JOIN_LEAVE_TIME, - "Anti SpamBot Parameter"}, + { + "MIN_JOIN_LEAVE_TIME", "", MIN_JOIN_LEAVE_TIME, + "Anti SpamBot Parameter" + }, #ifdef MPATH - {"MPATH", MPATH, 0, "Path to MOTD File"}, + {"MPATH", MPATH, 0, "Path to MOTD File"}, #else - {"MPATH", "NONE", 0, "Path to MOTD File"}, + {"MPATH", "NONE", 0, "Path to MOTD File"}, #endif /* MPATH */ - {"NICKNAMEHISTORYLENGTH", "", NICKNAMEHISTORYLENGTH, - "Size of WHOWAS Array"}, + { + "NICKNAMEHISTORYLENGTH", "", NICKNAMEHISTORYLENGTH, + "Size of WHOWAS Array" + }, #ifdef OPATH - {"OPATH", OPATH, 0, "Path to Operator MOTD File"}, + {"OPATH", OPATH, 0, "Path to Operator MOTD File"}, #else - {"OPATH", "NONE", 0, "Path to Operator MOTD File"}, + {"OPATH", "NONE", 0, "Path to Operator MOTD File"}, #endif /* OPATH */ - {"OPER_SPAM_COUNTDOWN", "", OPER_SPAM_COUNTDOWN, - "Anti SpamBot Parameter"}, + { + "OPER_SPAM_COUNTDOWN", "", OPER_SPAM_COUNTDOWN, + "Anti SpamBot Parameter" + }, #ifdef HAVE_LIBCRYPTO - {"HAVE_LIBCRYPTO", "ON", 0, "Enable OpenSSL CHALLENGE Support"}, + {"HAVE_LIBCRYPTO", "ON", 0, "Enable OpenSSL CHALLENGE Support"}, #else - {"HAVE_LIBCRYPTO", "OFF", 0, "Enable OpenSSL CHALLENGE Support"}, + {"HAVE_LIBCRYPTO", "OFF", 0, "Enable OpenSSL CHALLENGE Support"}, #endif /* HAVE_LIBCRYPTO */ #ifdef HAVE_LIBZ - {"HAVE_LIBZ", "YES", 0, "zlib (ziplinks) support"}, + {"HAVE_LIBZ", "YES", 0, "zlib (ziplinks) support"}, #else - {"HAVE_LIBZ", "NO", 0, "zlib (ziplinks) support"}, + {"HAVE_LIBZ", "NO", 0, "zlib (ziplinks) support"}, #endif /* HAVE_LIBZ */ #ifdef PPATH - {"PPATH", PPATH, 0, "Path to Pid File"}, + {"PPATH", PPATH, 0, "Path to Pid File"}, #else - {"PPATH", "NONE", 0, "Path to Pid File"}, + {"PPATH", "NONE", 0, "Path to Pid File"}, #endif /* PPATH */ - {"SELECT_TYPE", SELECT_TYPE, 0, "Method of Multiplexed I/O"}, + {"SELECT_TYPE", SELECT_TYPE, 0, "Method of Multiplexed I/O"}, #ifdef SPATH - {"SPATH", SPATH, 0, "Path to Server Executable"}, + {"SPATH", SPATH, 0, "Path to Server Executable"}, #else - {"SPATH", "NONE", 0, "Path to Server Executable"}, + {"SPATH", "NONE", 0, "Path to Server Executable"}, #endif /* SPATH */ - {"TS_MAX_DELTA_DEFAULT", "", TS_MAX_DELTA_DEFAULT, - "Maximum Allowed TS Delta from another Server"}, - {"TS_WARN_DELTA_DEFAULT", "", TS_WARN_DELTA_DEFAULT, - "Maximum TS Delta before Sending Warning"}, + { + "TS_MAX_DELTA_DEFAULT", "", TS_MAX_DELTA_DEFAULT, + "Maximum Allowed TS Delta from another Server" + }, + { + "TS_WARN_DELTA_DEFAULT", "", TS_WARN_DELTA_DEFAULT, + "Maximum TS Delta before Sending Warning" + }, #ifdef USE_IODEBUG_HOOKS - {"USE_IODEBUG_HOOKS", "YES", 0, "IO Debugging support"}, + {"USE_IODEBUG_HOOKS", "YES", 0, "IO Debugging support"}, #else - {"USE_IODEBUG_HOOKS", "NO", 0, "IO Debugging support"}, + {"USE_IODEBUG_HOOKS", "NO", 0, "IO Debugging support"}, #endif - /* - * since we don't want to include the world here, NULL probably - * isn't defined by the time we read this, just use plain 0 instead - * 0 is guaranteed by the language to be assignable to ALL built - * in types with the correct results. - */ - {0, 0, 0, 0} + /* + * since we don't want to include the world here, NULL probably + * isn't defined by the time we read this, just use plain 0 instead + * 0 is guaranteed by the language to be assignable to ALL built + * in types with the correct results. + */ + {0, 0, 0, 0} }; diff --git a/include/match.h b/include/match.h index 7dbb291..7ceb333 100644 --- a/include/match.h +++ b/include/match.h @@ -51,9 +51,9 @@ int comp_with_mask(void *addr, void *dest, u_int mask); int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, u_int mask); /* - * collapse - collapse a string in place, converts multiple adjacent *'s + * collapse - collapse a string in place, converts multiple adjacent *'s * into a single *. - * collapse - modifies the contents of pattern + * collapse - modifies the contents of pattern * * collapse_esc() - collapse with support for escaping chars */ diff --git a/include/modules.h b/include/modules.h index 68a3768..1aeb210 100644 --- a/include/modules.h +++ b/include/modules.h @@ -41,19 +41,17 @@ #include "msg.h" #include "hook.h" -struct module -{ - char *name; - const char *version; - void *address; - int core; - int mapi_version; - void * mapi_header; /* actually struct mapi_mheader_av */ +struct module { + char *name; + const char *version; + void *address; + int core; + int mapi_version; + void * mapi_header; /* actually struct mapi_mheader_av */ }; -struct module_path -{ - char path[MAXPATHLEN]; +struct module_path { + char path[MAXPATHLEN]; }; #define MAPI_MAGIC_HDR 0x4D410000 @@ -65,28 +63,25 @@ struct module_path typedef struct Message* mapi_clist_av1; -typedef struct -{ - const char * hapi_name; - int * hapi_id; +typedef struct { + const char * hapi_name; + int * hapi_id; } mapi_hlist_av1; -typedef struct -{ - const char * hapi_name; - hookfn fn; +typedef struct { + const char * hapi_name; + hookfn fn; } mapi_hfn_list_av1; -struct mapi_mheader_av1 -{ - int mapi_version; /* Module API version */ - int (*mapi_register) (void); /* Register function; +struct mapi_mheader_av1 { + int mapi_version; /* Module API version */ + int (*mapi_register) (void); /* Register function; ret -1 = failure (unload) */ - void (*mapi_unregister) (void); /* Unregister function. */ - mapi_clist_av1 * mapi_command_list; /* List of commands to add. */ - mapi_hlist_av1 * mapi_hook_list; /* List of hooks to add. */ - mapi_hfn_list_av1 *mapi_hfn_list; /* List of hook_add_hook's to do */ - const char * mapi_module_version; /* Module's version (freeform) */ + void (*mapi_unregister) (void); /* Unregister function. */ + mapi_clist_av1 * mapi_command_list; /* List of commands to add. */ + mapi_hlist_av1 * mapi_hook_list; /* List of hooks to add. */ + mapi_hfn_list_av1 *mapi_hfn_list; /* List of hook_add_hook's to do */ + const char * mapi_module_version; /* Module's version (freeform) */ }; #ifndef STATIC_MODULES diff --git a/include/monitor.h b/include/monitor.h index 00af663..2c1d779 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -1,4 +1,4 @@ -/* +/* * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). * monitor.h: Code for server-side notify lists. * @@ -11,11 +11,10 @@ struct rb_bh; -struct monitor -{ - struct monitor *hnext; - char name[NICKLEN]; - rb_dlink_list users; +struct monitor { + struct monitor *hnext; + char name[NICKLEN]; + rb_dlink_list users; }; extern struct monitor *monitorTable[]; diff --git a/include/msg.h b/include/msg.h index 824e5f7..cde660d 100644 --- a/include/msg.h +++ b/include/msg.h @@ -31,15 +31,14 @@ struct Client; /* MessageHandler */ -typedef enum HandlerType -{ - UNREGISTERED_HANDLER, - CLIENT_HANDLER, - RCLIENT_HANDLER, - SERVER_HANDLER, - ENCAP_HANDLER, - OPER_HANDLER, - LAST_HANDLER_TYPE +typedef enum HandlerType { + UNREGISTERED_HANDLER, + CLIENT_HANDLER, + RCLIENT_HANDLER, + SERVER_HANDLER, + ENCAP_HANDLER, + OPER_HANDLER, + LAST_HANDLER_TYPE } HandlerType; @@ -50,27 +49,25 @@ HandlerType; */ typedef int (*MessageHandler) (struct Client *, struct Client *, int, const char *[]); -struct MessageEntry -{ - MessageHandler handler; - int min_para; +struct MessageEntry { + MessageHandler handler; + int min_para; }; /* Message table structure */ -struct Message -{ - const char *cmd; - unsigned int count; /* number of times command used */ - unsigned int rcount; /* number of times command used by server */ - unsigned long bytes; /* bytes received for this message */ - unsigned int flags; /* bit 0 set means that this command is allowed +struct Message { + const char *cmd; + unsigned int count; /* number of times command used */ + unsigned int rcount; /* number of times command used by server */ + unsigned long bytes; /* bytes received for this message */ + unsigned int flags; /* bit 0 set means that this command is allowed * to be used only on the average of once per 2 * seconds -SRB */ - /* handlers: - * UNREGISTERED, CLIENT, RCLIENT, SERVER, OPER, LAST - */ - struct MessageEntry handlers[LAST_HANDLER_TYPE]; + /* handlers: + * UNREGISTERED, CLIENT, RCLIENT, SERVER, OPER, LAST + */ + struct MessageEntry handlers[LAST_HANDLER_TYPE]; }; #define MFLG_SLOW 0x01 /* executed roughly once per 2s */ diff --git a/include/newconf.h b/include/newconf.h index d7181c2..2f01b43 100644 --- a/include/newconf.h +++ b/include/newconf.h @@ -5,22 +5,20 @@ #ifndef _NEWCONF_H_INCLUDED #define _NEWCONF_H_INCLUDED -struct ConfEntry -{ - const char *cf_name; - int cf_type; - void (*cf_func) (void *); - int cf_len; - void *cf_arg; +struct ConfEntry { + const char *cf_name; + int cf_type; + void (*cf_func) (void *); + int cf_len; + void *cf_arg; }; -struct TopConf -{ - const char *tc_name; - int (*tc_sfunc) (struct TopConf *); - int (*tc_efunc) (struct TopConf *); - rb_dlink_list tc_items; - struct ConfEntry *tc_entries; +struct TopConf { + const char *tc_name; + int (*tc_sfunc) (struct TopConf *); + int (*tc_efunc) (struct TopConf *); + rb_dlink_list tc_items; + struct ConfEntry *tc_entries; }; @@ -37,17 +35,15 @@ struct TopConf #define CF_FLIST 0x1000 #define CF_MFLAG 0xFF00 -typedef struct conf_parm_t_stru -{ - struct conf_parm_t_stru *next; - int type; - union - { - char *string; - int number; - struct conf_parm_t_stru *list; - } - v; +typedef struct conf_parm_t_stru { + struct conf_parm_t_stru *next; + int type; + union { + char *string; + int number; + struct conf_parm_t_stru *list; + } + v; } conf_parm_t; diff --git a/include/numeric.h b/include/numeric.h index d12f5e6..123ea1f 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -77,7 +77,7 @@ extern const char *form_str(int); #define RPL_STATSYLINE 218 #define RPL_ENDOFSTATS 219 /* note ircu uses 217 for STATSPLINE frip. conflict - * as RPL_STATSQLINE was used in old 2.8 for Q line + * as RPL_STATSQLINE was used in old 2.8 for Q line * I'm going to steal 220 for now *sigh* * -Dianora */ @@ -318,7 +318,7 @@ extern const char *form_str(int); #define ERR_USERNOTONSERV 504 -/* #define ERR_LAST_ERR_MSG 505 +/* #define ERR_LAST_ERR_MSG 505 * moved to 999 */ #define ERR_WRONGPONG 513 diff --git a/include/packet.h b/include/packet.h index fc0449b..118c777 100644 --- a/include/packet.h +++ b/include/packet.h @@ -35,7 +35,7 @@ * the network.. * -- adrian */ -/* MAX_FLOOD is the amount of lines in a 'burst' we allow from a client, +/* MAX_FLOOD is the amount of lines in a 'burst' we allow from a client, * anything beyond MAX_FLOOD is limited to about one line per second. * * MAX_FLOOD_CONN is the amount of lines we allow from a client who has diff --git a/include/parse.h b/include/parse.h index 3f79728..b2722b7 100644 --- a/include/parse.h +++ b/include/parse.h @@ -32,8 +32,8 @@ struct Message; struct Client; extern void parse(struct Client *, char *, char *); -extern void handle_encap(struct Client *, struct Client *, - const char *, int, const char *parv[]); +extern void handle_encap(struct Client *, struct Client *, + const char *, int, const char *parv[]); extern void clear_hash_parse(void); extern void mod_add_cmd(struct Message *msg); extern void mod_del_cmd(struct Message *msg); diff --git a/include/privilege.h b/include/privilege.h index a3e5bff..6d0c257 100644 --- a/include/privilege.h +++ b/include/privilege.h @@ -27,17 +27,17 @@ #include "stdinc.h" enum { - PRIV_NEEDOPER = 1 + PRIV_NEEDOPER = 1 }; typedef unsigned int PrivilegeFlags; struct PrivilegeSet { - unsigned int status; /* If CONF_ILLEGAL, delete when no refs */ - int refs; - char *name; - char *privs; - PrivilegeFlags flags; - rb_dlink_node node; + unsigned int status; /* If CONF_ILLEGAL, delete when no refs */ + int refs; + char *name; + char *privs; + PrivilegeFlags flags; + rb_dlink_node node; }; int privilegeset_in_set(struct PrivilegeSet *set, const char *priv); diff --git a/include/res.h b/include/res.h index 3b9851b..be06026 100644 --- a/include/res.h +++ b/include/res.h @@ -12,22 +12,20 @@ #include "match.h" #include "ircd.h" -/* Maximum number of nameservers in /etc/resolv.conf we care about +/* Maximum number of nameservers in /etc/resolv.conf we care about * In hybrid, this was 2 -- but in Charybdis, we want to track * a few more than that ;) --nenolod */ #define IRCD_MAXNS 10 -struct DNSReply -{ - char *h_name; - struct rb_sockaddr_storage addr; +struct DNSReply { + char *h_name; + struct rb_sockaddr_storage addr; }; -struct DNSQuery -{ - void *ptr; /* pointer used by callback to identify request */ - void (*callback)(void* vptr, struct DNSReply *reply); /* callback to call */ +struct DNSQuery { + void *ptr; /* pointer used by callback to identify request */ + void (*callback)(void* vptr, struct DNSReply *reply); /* callback to call */ }; extern struct rb_sockaddr_storage irc_nsaddr_list[]; diff --git a/include/reslib.h b/include/reslib.h index 031f22f..bf2408b 100644 --- a/include/reslib.h +++ b/include/reslib.h @@ -34,41 +34,40 @@ #define RRFIXEDSZ 10 #define HFIXEDSZ 12 -typedef struct -{ - unsigned id :16; /* query identification number */ +typedef struct { + unsigned id :16; /* query identification number */ #ifdef WORDS_BIGENDIAN - /* fields in third byte */ - unsigned qr: 1; /* response flag */ - unsigned opcode: 4; /* purpose of message */ - unsigned aa: 1; /* authoritive answer */ - unsigned tc: 1; /* truncated message */ - unsigned rd: 1; /* recursion desired */ - /* fields in fourth byte */ - unsigned ra: 1; /* recursion available */ - unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ - unsigned ad: 1; /* authentic data from named */ - unsigned cd: 1; /* checking disabled by resolver */ - unsigned rcode :4; /* response code */ + /* fields in third byte */ + unsigned qr: 1; /* response flag */ + unsigned opcode: 4; /* purpose of message */ + unsigned aa: 1; /* authoritive answer */ + unsigned tc: 1; /* truncated message */ + unsigned rd: 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /* recursion available */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned rcode :4; /* response code */ #else - /* fields in third byte */ - unsigned rd :1; /* recursion desired */ - unsigned tc :1; /* truncated message */ - unsigned aa :1; /* authoritive answer */ - unsigned opcode :4; /* purpose of message */ - unsigned qr :1; /* response flag */ - /* fields in fourth byte */ - unsigned rcode :4; /* response code */ - unsigned cd: 1; /* checking disabled by resolver */ - unsigned ad: 1; /* authentic data from named */ - unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ - unsigned ra :1; /* recursion available */ + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritive answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ #endif - /* remaining bytes */ - unsigned qdcount :16; /* number of question entries */ - unsigned ancount :16; /* number of answer entries */ - unsigned nscount :16; /* number of authority entries */ - unsigned arcount :16; /* number of resource entries */ + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ } HEADER; /* diff --git a/include/s_conf.h b/include/s_conf.h index 36858aa..df60d84 100644 --- a/include/s_conf.h +++ b/include/s_conf.h @@ -43,39 +43,36 @@ struct hostent; /* used by new parser */ /* yacc/lex love globals!!! */ -struct ip_value -{ - struct rb_sockaddr_storage ip; - int ip_mask; - int type; +struct ip_value { + struct rb_sockaddr_storage ip; + int ip_mask; + int type; }; extern FILE *conf_fbfile_in; extern char conf_line_in[256]; -struct ConfItem -{ - unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ - unsigned int flags; - int clients; /* Number of *LOCAL* clients using this */ - union - { - char *name; /* IRC name, nick, server name, or original u@h */ - const char *oper; - } info; - char *host; /* host part of user@host */ - char *passwd; /* doubles as kline reason *ugh* */ - char *spasswd; /* Password to send. */ - char *autojoin; /* channels for users to autojoin to on connect */ - char *autojoin_opers; /* channels for opers to autojoin on oper-up */ - char *user; /* user part of user@host */ - int port; - time_t hold; /* Hold action until this time (calendar time) */ - time_t created; /* Creation time (for klines etc) */ - time_t lifetime; /* Propagated lines: remember until this time */ - char *className; /* Name of class */ - struct Class *c_class; /* Class of connection */ - rb_patricia_node_t *pnode; /* Our patricia node */ +struct ConfItem { + unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ + unsigned int flags; + int clients; /* Number of *LOCAL* clients using this */ + union { + char *name; /* IRC name, nick, server name, or original u@h */ + const char *oper; + } info; + char *host; /* host part of user@host */ + char *passwd; /* doubles as kline reason *ugh* */ + char *spasswd; /* Password to send. */ + char *autojoin; /* channels for users to autojoin to on connect */ + char *autojoin_opers; /* channels for opers to autojoin on oper-up */ + char *user; /* user part of user@host */ + int port; + time_t hold; /* Hold action until this time (calendar time) */ + time_t created; /* Creation time (for klines etc) */ + time_t lifetime; /* Propagated lines: remember until this time */ + char *className; /* Name of class */ + struct Class *c_class; /* Class of connection */ + rb_patricia_node_t *pnode; /* Our patricia node */ }; #define CONF_ILLEGAL 0x80000000 @@ -137,192 +134,186 @@ struct ConfItem /* flag definitions for opers now in client.h */ -struct config_file_entry -{ - const char *dpath; /* DPATH if set from command line */ - const char *configfile; +struct config_file_entry { + const char *dpath; /* DPATH if set from command line */ + const char *configfile; - char *egdpool_path; + char *egdpool_path; - char *default_operstring; - char *default_adminstring; - char *default_operhost; - char *static_quit; - char *servicestring; - char *kline_reason; + char *default_operstring; + char *default_adminstring; + char *default_operhost; + char *static_quit; + char *servicestring; + char *kline_reason; - char *identifyservice; - char *identifycommand; - - char *fname_userlog; - char *fname_fuserlog; - char *fname_operlog; - char *fname_foperlog; - char *fname_serverlog; - char *fname_killlog; - char *fname_klinelog; - char *fname_operspylog; - char *fname_ioerrorlog; + char *identifyservice; + char *identifycommand; - unsigned char compression_level; - int disable_fake_channels; - int hide_channel_below_users; - int dots_in_ident; - int failed_oper_notice; - int anti_nick_flood; - int use_part_messages; - int anti_spam_exit_message_time; - int max_accept; - int max_monitor; - int max_nick_time; - int max_nick_changes; - int ts_max_delta; - int ts_warn_delta; - int dline_with_reason; - int kline_with_reason; - int kline_delay; - int warn_no_nline; - int nick_delay; - int non_redundant_klines; - int stats_e_disabled; - int stats_c_oper_only; - int stats_y_oper_only; - int stats_h_oper_only; - int stats_o_oper_only; - int stats_k_oper_only; - int stats_i_oper_only; - int stats_P_oper_only; - int map_oper_only; - int operspy_admin_only; - int pace_wait; - int pace_wait_simple; - int short_motd; - int no_oper_flood; - int true_no_oper_flood; - int hide_server; - int hide_spoof_ips; - int hide_error_messages; - int client_exit; - int oper_only_umodes; - int oper_umodes; - int oper_snomask; - int max_targets; - int caller_id_wait; - int min_nonwildcard; - int min_nonwildcard_simple; - int default_floodcount; - int client_flood; - int default_ident_timeout; - int use_egd; - int ping_cookie; - int tkline_expire_notices; - int use_whois_actually; - int disable_auth; - int connect_timeout; - int burst_away; - int reject_ban_time; - int reject_after_count; - int reject_duration; - int throttle_count; - int throttle_duration; - int target_change; - int collision_fnc; - int default_umodes; - int global_snotices; - int operspy_dont_care_user_info; - int use_propagated_bans; - int secret_channels_in_whois; - int expire_override_time; + char *fname_userlog; + char *fname_fuserlog; + char *fname_operlog; + char *fname_foperlog; + char *fname_serverlog; + char *fname_killlog; + char *fname_klinelog; + char *fname_operspylog; + char *fname_ioerrorlog; + + unsigned char compression_level; + int disable_fake_channels; + int hide_channel_below_users; + int dots_in_ident; + int failed_oper_notice; + int anti_nick_flood; + int use_part_messages; + int anti_spam_exit_message_time; + int max_accept; + int max_monitor; + int max_nick_time; + int max_nick_changes; + int ts_max_delta; + int ts_warn_delta; + int dline_with_reason; + int kline_with_reason; + int kline_delay; + int warn_no_nline; + int nick_delay; + int non_redundant_klines; + int stats_e_disabled; + int stats_c_oper_only; + int stats_y_oper_only; + int stats_h_oper_only; + int stats_o_oper_only; + int stats_k_oper_only; + int stats_i_oper_only; + int stats_P_oper_only; + int map_oper_only; + int operspy_admin_only; + int pace_wait; + int pace_wait_simple; + int short_motd; + int no_oper_flood; + int true_no_oper_flood; + int hide_server; + int hide_spoof_ips; + int hide_error_messages; + int client_exit; + int oper_only_umodes; + int oper_umodes; + int oper_snomask; + int max_targets; + int caller_id_wait; + int min_nonwildcard; + int min_nonwildcard_simple; + int default_floodcount; + int client_flood; + int default_ident_timeout; + int use_egd; + int ping_cookie; + int tkline_expire_notices; + int use_whois_actually; + int disable_auth; + int connect_timeout; + int burst_away; + int reject_ban_time; + int reject_after_count; + int reject_duration; + int throttle_count; + int throttle_duration; + int target_change; + int collision_fnc; + int default_umodes; + int global_snotices; + int operspy_dont_care_user_info; + int use_propagated_bans; + int secret_channels_in_whois; + int expire_override_time; int away_interval; }; -struct config_channel_entry -{ - char * autochanmodes; - char * exemptchanops; - char * disabledmodes; - int admin_on_channel_create; - int use_halfop; - int use_admin; - int use_owner; - int use_except; - int use_invex; - int use_knock; - int use_forward; - int use_local_channels; - int knock_delay; - int knock_delay_channel; - int max_bans; - int max_bans_large; - int max_chans_per_user; - int no_create_on_split; - int no_join_on_split; - int default_split_server_count; - int default_split_user_count; - int burst_topicwho; - int kick_on_split_riding; - int only_ascii_channels; - int cycle_host_change; - int host_in_topic; - int resv_forcepart; - int channel_target_change; +struct config_channel_entry { + char * autochanmodes; + char * exemptchanops; + char * disabledmodes; + int admin_on_channel_create; + int use_halfop; + int use_admin; + int use_owner; + int use_except; + int use_invex; + int use_knock; + int use_forward; + int use_local_channels; + int knock_delay; + int knock_delay_channel; + int max_bans; + int max_bans_large; + int max_chans_per_user; + int no_create_on_split; + int no_join_on_split; + int default_split_server_count; + int default_split_user_count; + int burst_topicwho; + int kick_on_split_riding; + int only_ascii_channels; + int cycle_host_change; + int host_in_topic; + int resv_forcepart; + int channel_target_change; - int exempt_cmode_c; - int exempt_cmode_C; - int exempt_cmode_D; - int exempt_cmode_T; - int exempt_cmode_N; - int exempt_cmode_G; - int exempt_cmode_K; + int exempt_cmode_c; + int exempt_cmode_C; + int exempt_cmode_D; + int exempt_cmode_T; + int exempt_cmode_N; + int exempt_cmode_G; + int exempt_cmode_K; }; -struct config_server_hide -{ - int flatten_links; - int links_delay; - int hidden; - int disable_hidden; +struct config_server_hide { + int flatten_links; + int links_delay; + int hidden; + int disable_hidden; }; -struct server_info -{ - char *name; - char sid[4]; - char *description; - char *network_name; - char *network_desc; - char *helpchan; - char *helpurl; - int hub; - struct sockaddr_in ip; - int default_max_clients; +struct server_info { + char *name; + char sid[4]; + char *description; + char *network_name; + char *network_desc; + char *helpchan; + char *helpurl; + int hub; + struct sockaddr_in ip; + int default_max_clients; #ifdef RB_IPV6 - struct sockaddr_in6 ip6; + struct sockaddr_in6 ip6; #endif - int specific_ipv4_vhost; + int specific_ipv4_vhost; #ifdef RB_IPV6 - int specific_ipv6_vhost; + int specific_ipv6_vhost; #endif - char *ssl_private_key; - char *ssl_ca_cert; - char *ssl_cert; - char *ssl_dh_params; - int ssld_count; + char *ssl_private_key; + char *ssl_ca_cert; + char *ssl_cert; + char *ssl_dh_params; + int ssld_count; }; -struct admin_info -{ - char *name; - char *description; - char *email; +struct admin_info { + char *name; + char *description; + char *email; }; -struct alias_entry -{ - char *name; - char *target; - int flags; /* reserved for later use */ - int hits; +struct alias_entry { + char *name; + char *target; + int flags; /* reserved for later use */ + int hits; }; /* All variables are GLOBAL */ @@ -339,13 +330,12 @@ extern rb_dlink_list service_list; extern rb_dlink_list prop_bans; -typedef enum temp_list -{ - TEMP_MIN, - TEMP_HOUR, - TEMP_DAY, - TEMP_WEEK, - LAST_TEMP_TYPE +typedef enum temp_list { + TEMP_MIN, + TEMP_HOUR, + TEMP_DAY, + TEMP_WEEK, + LAST_TEMP_TYPE } temp_list; extern rb_dlink_list temp_klines[LAST_TEMP_TYPE]; @@ -370,10 +360,10 @@ extern int detach_conf(struct Client *); extern struct ConfItem *find_tkline(const char *, const char *, struct sockaddr *); extern char *show_iline_prefix(struct Client *, struct ConfItem *, char *); extern void get_printable_conf(struct ConfItem *, - char **, char **, char **, char **, int *, char **); + char **, char **, char **, char **, int *, char **); extern char *get_user_ban_reason(struct ConfItem *aconf); extern void get_printable_kline(struct Client *, struct ConfItem *, - char **, char **, char **, char **); + char **, char **, char **, char **); extern void yyerror(const char *); extern int conf_yy_fatal_error(const char *); diff --git a/include/s_newconf.h b/include/s_newconf.h index dde364d..a1db9ba 100644 --- a/include/s_newconf.h +++ b/include/s_newconf.h @@ -59,25 +59,23 @@ extern void init_s_newconf(void); extern void clear_s_newconf(void); extern void clear_s_newconf_bans(void); -typedef struct -{ - char *ip; - time_t expiry; - rb_patricia_node_t *pnode; - rb_dlink_node node; +typedef struct { + char *ip; + time_t expiry; + rb_patricia_node_t *pnode; + rb_dlink_node node; } tgchange; void add_tgchange(const char *host); tgchange *find_tgchange(const char *host); /* shared/cluster/hub/leaf confs */ -struct remote_conf -{ - char *username; - char *host; - char *server; - int flags; - rb_dlink_node node; +struct remote_conf { + char *username; + char *host; + char *server; + int flags; + rb_dlink_node node; }; /* flags used in shared/cluster */ @@ -107,28 +105,27 @@ struct remote_conf #define CONF_HUB 0x0001 #define CONF_LEAF 0x0002 -struct oper_conf -{ - char *name; - char *username; - char *host; - char *passwd; - char *certfp; +struct oper_conf { + char *name; + char *username; + char *host; + char *passwd; + char *certfp; - int flags; - int umodes; + int flags; + int umodes; - unsigned int snomask; + unsigned int snomask; - char *vhost; - char *swhois; - char *operstring; + char *vhost; + char *swhois; + char *operstring; - struct PrivilegeSet *privset; + struct PrivilegeSet *privset; #ifdef HAVE_LIBCRYPTO - char *rsa_pubkey_file; - RSA *rsa_pubkey; + char *rsa_pubkey_file; + RSA *rsa_pubkey; #endif }; @@ -136,11 +133,11 @@ extern struct remote_conf *make_remote_conf(void); extern void free_remote_conf(struct remote_conf *); extern int find_shared_conf(const char *username, const char *host, - const char *server, int flags); + const char *server, int flags); extern void propagate_generic(struct Client *source_p, const char *command, - const char *target, int cap, const char *format, ...); + const char *target, int cap, const char *format, ...); extern void cluster_generic(struct Client *, const char *, int cltype, - int cap, const char *format, ...); + int cap, const char *format, ...); #define OPER_ENCRYPTED 0x00001 #define OPER_NEEDSSL 0x80000 @@ -177,28 +174,27 @@ extern void free_oper_conf(struct oper_conf *); extern void clear_oper_conf(void); extern struct oper_conf *find_oper_conf(const char *username, const char *host, - const char *locip, const char *oname); + const char *locip, const char *oname); extern const char *get_oper_privs(int flags); -struct server_conf -{ - char *name; - char *host; - char *passwd; - char *spasswd; - char *certfp; - int port; - int flags; - int servers; - time_t hold; +struct server_conf { + char *name; + char *host; + char *passwd; + char *spasswd; + char *certfp; + int port; + int flags; + int servers; + time_t hold; - int aftype; - struct rb_sockaddr_storage my_ipnum; + int aftype; + struct rb_sockaddr_storage my_ipnum; - char *class_name; - struct Class *class; - rb_dlink_node node; + char *class_name; + struct Class *class; + rb_dlink_node node; }; #define SERVER_ILLEGAL 0x0001 @@ -226,8 +222,8 @@ extern struct server_conf *find_server_conf(const char *name); extern void attach_server_conf(struct Client *, struct server_conf *); extern void detach_server_conf(struct Client *); -extern void set_server_conf_autoconn(struct Client *source_p, const char *name, - int newval); +extern void set_server_conf_autoconn(struct Client *source_p, const char *name, + int newval); extern void disable_server_conf_autoconn(const char *name); @@ -240,11 +236,10 @@ extern int valid_wild_card_simple(const char *); extern int clean_resv_nick(const char *); time_t valid_temp_time(const char *p); -struct nd_entry -{ - char name[NICKLEN+1]; - time_t expire; - rb_dlink_node lnode; /* node in ll */ +struct nd_entry { + char name[NICKLEN+1]; + time_t expire; + rb_dlink_node lnode; /* node in ll */ }; extern void add_nd_entry(const char *name); diff --git a/include/s_serv.h b/include/s_serv.h index f35feba..b8703c9 100644 --- a/include/s_serv.h +++ b/include/s_serv.h @@ -37,7 +37,7 @@ /* * number of seconds to wait after server starts up, before * starting try_connections() - * TOO SOON and you can nick collide like crazy. + * TOO SOON and you can nick collide like crazy. */ #define STARTUP_CONNECTIONS_TIME 60 @@ -46,11 +46,10 @@ struct server_conf; struct Channel; /* Capabilities */ -struct Capability -{ - const char *name; /* name of capability */ - unsigned int cap; /* mask value */ - unsigned int required; /* 1 if required, 0 if not */ +struct Capability { + const char *name; /* name of capability */ + unsigned int cap; /* mask value */ + unsigned int required; /* 1 if required, 0 if not */ }; #define CAP_CAP 0x00001 /* received a CAP to begin with */ @@ -110,7 +109,7 @@ extern int MaxConnectionCount; /* GLOBAL - highest number of connections */ extern int refresh_user_links; /* - * return values for hunt_server() + * return values for hunt_server() */ #define HUNTED_NOSUCH (-1) /* if the hunted server is not found */ #define HUNTED_ISME 0 /* if this server should execute the command */ @@ -118,8 +117,8 @@ extern int refresh_user_links; extern int hunt_server(struct Client *client_pt, - struct Client *source_pt, - const char *command, int server, int parc, const char **parv); + struct Client *source_pt, + const char *command, int server, int parc, const char **parv); extern void send_capabilities(struct Client *, int); extern const char *show_capabilities(struct Client *client); extern void try_connections(void *unused); diff --git a/include/s_stats.h b/include/s_stats.h index cbd2808..3519ed8 100644 --- a/include/s_stats.h +++ b/include/s_stats.h @@ -39,33 +39,32 @@ struct Client; /* * statistics structures */ -struct ServerStatistics -{ - unsigned int is_cl; /* number of client connections */ - unsigned int is_sv; /* number of server connections */ - unsigned int is_ni; /* connection but no idea who it was */ - unsigned long long int is_cbs; /* bytes sent to clients */ - unsigned long long int is_cbr; /* bytes received to clients */ - unsigned long long int is_sbs; /* bytes sent to servers */ - unsigned long long int is_sbr; /* bytes received to servers */ - unsigned long long int is_cti; /* time spent connected by clients */ - unsigned long long int is_sti; /* time spent connected by servers */ - unsigned int is_ac; /* connections accepted */ - unsigned int is_ref; /* accepts refused */ - unsigned int is_unco; /* unknown commands */ - unsigned int is_wrdi; /* command going in wrong direction */ - unsigned int is_unpf; /* unknown prefix */ - unsigned int is_empt; /* empty message */ - unsigned int is_num; /* numeric message */ - unsigned int is_kill; /* number of kills generated on collisions */ - unsigned int is_save; /* number of saves generated on collisions */ - unsigned int is_asuc; /* successful auth requests */ - unsigned int is_abad; /* bad auth requests */ - unsigned int is_rej; /* rejected from cache */ - unsigned int is_thr; /* number of throttled connections */ - unsigned int is_ssuc; /* successful sasl authentications */ - unsigned int is_sbad; /* failed sasl authentications */ - unsigned int is_tgch; /* messages blocked due to target change */ +struct ServerStatistics { + unsigned int is_cl; /* number of client connections */ + unsigned int is_sv; /* number of server connections */ + unsigned int is_ni; /* connection but no idea who it was */ + unsigned long long int is_cbs; /* bytes sent to clients */ + unsigned long long int is_cbr; /* bytes received to clients */ + unsigned long long int is_sbs; /* bytes sent to servers */ + unsigned long long int is_sbr; /* bytes received to servers */ + unsigned long long int is_cti; /* time spent connected by clients */ + unsigned long long int is_sti; /* time spent connected by servers */ + unsigned int is_ac; /* connections accepted */ + unsigned int is_ref; /* accepts refused */ + unsigned int is_unco; /* unknown commands */ + unsigned int is_wrdi; /* command going in wrong direction */ + unsigned int is_unpf; /* unknown prefix */ + unsigned int is_empt; /* empty message */ + unsigned int is_num; /* numeric message */ + unsigned int is_kill; /* number of kills generated on collisions */ + unsigned int is_save; /* number of saves generated on collisions */ + unsigned int is_asuc; /* successful auth requests */ + unsigned int is_abad; /* bad auth requests */ + unsigned int is_rej; /* rejected from cache */ + unsigned int is_thr; /* number of throttled connections */ + unsigned int is_ssuc; /* successful sasl authentications */ + unsigned int is_sbad; /* failed sasl authentications */ + unsigned int is_tgch; /* messages blocked due to target change */ }; extern struct ServerStatistics ServerStats; diff --git a/include/s_user.h b/include/s_user.h index d287cd2..fd110a9 100644 --- a/include/s_user.h +++ b/include/s_user.h @@ -42,11 +42,11 @@ extern void send_umode_out(struct Client *, struct Client *, int); extern int show_lusers(struct Client *source_p); extern int register_local_user(struct Client *, struct Client *, const char *); -extern int introduce_client(struct Client *client_p, struct Client *source_p, - struct User *user, const char *nick, int use_euid); +extern int introduce_client(struct Client *client_p, struct Client *source_p, + struct User *user, const char *nick, int use_euid); extern void change_nick_user_host(struct Client *target_p, const char *nick, const char *user, - const char *host, int newts, const char *format, ...); + const char *host, int newts, const char *format, ...); extern int user_modes[256]; extern unsigned int find_umode_slot(void); diff --git a/include/send.h b/include/send.h index 290f13a..983131c 100644 --- a/include/send.h +++ b/include/send.h @@ -46,19 +46,19 @@ extern void send_queued(struct Client *to); extern void sendto_one(struct Client *target_p, const char *, ...) AFP(2, 3); extern void sendto_one_notice(struct Client *target_p,const char *, ...) AFP(2, 3); extern void sendto_one_prefix(struct Client *target_p, struct Client *source_p, - const char *command, const char *, ...) AFP(4, 5); + const char *command, const char *, ...) AFP(4, 5); extern void sendto_one_numeric(struct Client *target_p, - int numeric, const char *, ...) AFP(3, 4); + int numeric, const char *, ...) AFP(3, 4); extern void sendto_server(struct Client *one, struct Channel *chptr, - unsigned long caps, unsigned long nocaps, - const char *format, ...) AFP(5, 6); + unsigned long caps, unsigned long nocaps, + const char *format, ...) AFP(5, 6); extern void sendto_channel_flags(struct Client *one, int type, struct Client *source_p, - struct Channel *chptr, const char *, ...) AFP(5, 6); + struct Channel *chptr, const char *, ...) AFP(5, 6); extern void sendto_channel_opmod(struct Client *one, struct Client *source_p, - struct Channel *chptr, const char *command, - const char *text); + struct Channel *chptr, const char *command, + const char *text); extern void sendto_channel_local(int type, struct Channel *, const char *, ...) AFP(3, 4); extern void sendto_channel_local_butone(struct Client *, int type, struct Channel *, const char *, ...) AFP(4, 5); @@ -70,14 +70,14 @@ extern void sendto_common_channels_local_butone(struct Client *, int cap, const extern void sendto_match_butone(struct Client *, struct Client *, - const char *, int, const char *, ...) AFP(5, 6); -extern void sendto_match_servs(struct Client *source_p, const char *mask, - int capab, int, const char *, ...) AFP(5, 6); + const char *, int, const char *, ...) AFP(5, 6); +extern void sendto_match_servs(struct Client *source_p, const char *mask, + int capab, int, const char *, ...) AFP(5, 6); extern void sendto_monitor(struct monitor *monptr, const char *, ...) AFP(2, 3); extern void sendto_anywhere(struct Client *, struct Client *, const char *, - const char *, ...) AFP(4, 5); + const char *, ...) AFP(4, 5); extern void sendto_realops_snomask(int, int, const char *, ...) AFP(3, 4); extern void sendto_realops_snomask_from(int, int, struct Client *, const char *, ...) AFP(4, 5); @@ -85,9 +85,9 @@ extern void sendto_realops_snomask_from(int, int, struct Client *, const char *, extern void sendto_wallops_flags(int, struct Client *, const char *, ...) AFP(3, 4); extern void kill_client(struct Client *client_p, struct Client *diedie, - const char *pattern, ...) AFP(3, 4); -extern void kill_client_serv_butone(struct Client *one, struct Client *source_p, - const char *pattern, ...) AFP(3, 4); + const char *pattern, ...) AFP(3, 4); +extern void kill_client_serv_butone(struct Client *one, struct Client *source_p, + const char *pattern, ...) AFP(3, 4); #define L_ALL 0 #define L_OPER 1 diff --git a/include/stdinc.h b/include/stdinc.h index 5f444a4..4a11c58 100644 --- a/include/stdinc.h +++ b/include/stdinc.h @@ -39,7 +39,7 @@ # include # else # ifdef _AIX - #pragma alloca +#pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); @@ -48,7 +48,7 @@ char *alloca (); # endif # endif #endif - + #ifdef HAVE_STDLIB_H #include @@ -142,7 +142,7 @@ extern int errno; #ifdef strdupa -#define LOCAL_COPY(s) strdupa(s) +#define LOCAL_COPY(s) strdupa(s) #else #if defined(__INTEL_COMPILER) || defined(__GNUC__) # define LOCAL_COPY(s) __extension__({ char *_s = alloca(strlen(s) + 1); strcpy(_s, s); _s; }) diff --git a/include/supported.h b/include/supported.h index 8c8b4d4..82107b0 100644 --- a/include/supported.h +++ b/include/supported.h @@ -4,11 +4,11 @@ * * Entirely rewritten, August 2006 by Jilles Tjoelker * Copyright (C) 2006 Jilles Tjoelker - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * 1.Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2.Redistributions in binary form must reproduce the above copyright @@ -16,7 +16,7 @@ * documentation and/or other materials provided with the distribution. * 3.The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * 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 diff --git a/include/whowas.h b/include/whowas.h index 0c809a9..a32ba9e 100644 --- a/include/whowas.h +++ b/include/whowas.h @@ -45,22 +45,21 @@ struct Client; also removed away information. *tough* - Dianora */ -struct Whowas -{ - int hashv; - char name[NICKLEN + 1]; - char username[USERLEN + 1]; - char hostname[HOSTLEN + 1]; - char sockhost[HOSTIPLEN + 1]; - char realname[REALLEN + 1]; - char suser[NICKLEN + 1]; - const char *servername; - time_t logoff; - struct Client *online; /* Pointer to new nickname for chasing or NULL */ - struct Whowas *next; /* for hash table... */ - struct Whowas *prev; /* for hash table... */ - struct Whowas *cnext; /* for client struct linked list */ - struct Whowas *cprev; /* for client struct linked list */ +struct Whowas { + int hashv; + char name[NICKLEN + 1]; + char username[USERLEN + 1]; + char hostname[HOSTLEN + 1]; + char sockhost[HOSTIPLEN + 1]; + char realname[REALLEN + 1]; + char suser[NICKLEN + 1]; + const char *servername; + time_t logoff; + struct Client *online; /* Pointer to new nickname for chasing or NULL */ + struct Whowas *next; /* for hash table... */ + struct Whowas *prev; /* for hash table... */ + struct Whowas *cnext; /* for client struct linked list */ + struct Whowas *cprev; /* for client struct linked list */ }; /* @@ -93,8 +92,8 @@ void off_history(struct Client *); ** one found... */ struct Client *get_history(const char *, time_t); - /* Nick name */ - /* Time limit in seconds */ +/* Nick name */ +/* Time limit in seconds */ /* ** for debugging...counts related structures stored in whowas array. diff --git a/libratbox/include/commio-int.h b/libratbox/include/commio-int.h index bd88089..a54e438 100644 --- a/libratbox/include/commio-int.h +++ b/libratbox/include/commio-int.h @@ -44,13 +44,13 @@ #ifdef HAVE_WRITEV #ifndef UIO_MAXIOV # if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__) - /* FreeBSD 4.7 defines it in sys/uio.h only if _KERNEL is specified */ +/* FreeBSD 4.7 defines it in sys/uio.h only if _KERNEL is specified */ # define RB_UIO_MAXIOV 1024 # elif defined(__sgi) - /* IRIX 6.5 has sysconf(_SC_IOV_MAX) which might return 512 or bigger */ +/* IRIX 6.5 has sysconf(_SC_IOV_MAX) which might return 512 or bigger */ # define RB_UIO_MAXIOV 512 # elif defined(__sun) - /* Solaris (and SunOS?) defines IOV_MAX instead */ +/* Solaris (and SunOS?) defines IOV_MAX instead */ # ifndef IOV_MAX # define RB_UIO_MAXIOV 16 # else @@ -68,24 +68,22 @@ #else #define RB_UIO_MAXIOV 16 #endif -struct conndata -{ - /* We don't need the host here ? */ - struct rb_sockaddr_storage S; - struct rb_sockaddr_storage hostaddr; - time_t t; - CNCB *callback; - void *data; - /* We'd also add the retry count here when we get to that -- adrian */ +struct conndata { + /* We don't need the host here ? */ + struct rb_sockaddr_storage S; + struct rb_sockaddr_storage hostaddr; + time_t t; + CNCB *callback; + void *data; + /* We'd also add the retry count here when we get to that -- adrian */ }; -struct acceptdata -{ - struct rb_sockaddr_storage S; - rb_socklen_t addrlen; - ACCB *callback; - ACPRE *precb; - void *data; +struct acceptdata { + struct rb_sockaddr_storage S; + rb_socklen_t addrlen; + ACCB *callback; + ACPRE *precb; + void *data; }; /* Only have open flags for now, could be more later */ @@ -95,40 +93,38 @@ struct acceptdata #define ClearFDOpen(F) (F->flags &= ~FLAG_OPEN) -struct _fde -{ - /* New-school stuff, again pretty much ripped from squid */ - /* - * Yes, this gives us only one pending read and one pending write per - * filedescriptor. Think though: when do you think we'll need more? - */ - rb_dlink_node node; - int fd; /* So we can use the rb_fde_t as a callback ptr */ - uint8_t flags; - uint8_t type; - int pflags; - char *desc; - PF *read_handler; - void *read_data; - PF *write_handler; - void *write_data; - struct timeout_data *timeout; - struct conndata *connect; - struct acceptdata *accept; - void *ssl; - unsigned int handshake_count; - unsigned long ssl_errno; +struct _fde { + /* New-school stuff, again pretty much ripped from squid */ + /* + * Yes, this gives us only one pending read and one pending write per + * filedescriptor. Think though: when do you think we'll need more? + */ + rb_dlink_node node; + int fd; /* So we can use the rb_fde_t as a callback ptr */ + uint8_t flags; + uint8_t type; + int pflags; + char *desc; + PF *read_handler; + void *read_data; + PF *write_handler; + void *write_data; + struct timeout_data *timeout; + struct conndata *connect; + struct acceptdata *accept; + void *ssl; + unsigned int handshake_count; + unsigned long ssl_errno; }; typedef void (*comm_event_cb_t) (void *); #ifdef USE_TIMER_CREATE -typedef struct timer_data -{ - timer_t td_timer_id; - comm_event_cb_t td_cb; - void *td_udata; - int td_repeat; +typedef struct timer_data { + timer_t td_timer_id; + comm_event_cb_t td_cb; + void *td_udata; + int td_repeat; } *comm_event_id; #endif @@ -137,24 +133,23 @@ extern rb_dlink_list *rb_fd_table; static inline rb_fde_t * rb_find_fd(int fd) { - rb_dlink_list *hlist; - rb_dlink_node *ptr; + rb_dlink_list *hlist; + rb_dlink_node *ptr; - if(rb_unlikely(fd < 0)) - return NULL; + if(rb_unlikely(fd < 0)) + return NULL; - hlist = &rb_fd_table[rb_hash_fd(fd)]; + hlist = &rb_fd_table[rb_hash_fd(fd)]; - if(hlist->head == NULL) - return NULL; + if(hlist->head == NULL) + return NULL; - RB_DLINK_FOREACH(ptr, hlist->head) - { - rb_fde_t *F = ptr->data; - if(F->fd == fd) - return F; - } - return NULL; + RB_DLINK_FOREACH(ptr, hlist->head) { + rb_fde_t *F = ptr->data; + if(F->fd == fd) + return F; + } + return NULL; } diff --git a/libratbox/include/commio-ssl.h b/libratbox/include/commio-ssl.h index 93e44f1..55ca498 100644 --- a/libratbox/include/commio-ssl.h +++ b/libratbox/include/commio-ssl.h @@ -35,7 +35,7 @@ const char *rb_get_ssl_strerror(rb_fde_t *F); void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout); void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout); void rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest, struct sockaddr *clocal, int socklen, - CNCB * callback, void *data, int timeout); + CNCB * callback, void *data, int timeout); void rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen); void rb_ssl_shutdown(rb_fde_t *F); ssize_t rb_ssl_read(rb_fde_t *F, void *buf, size_t count); diff --git a/libratbox/include/event-int.h b/libratbox/include/event-int.h index 4cabd31..d5cd564 100644 --- a/libratbox/include/event-int.h +++ b/libratbox/include/event-int.h @@ -22,16 +22,15 @@ * */ -struct ev_entry -{ - rb_dlink_node node; - EVH *func; - void *arg; - char *name; - time_t frequency; - time_t when; - time_t next; - void *data; - void *comm_ptr; +struct ev_entry { + rb_dlink_node node; + EVH *func; + void *arg; + char *name; + time_t frequency; + time_t when; + time_t next; + void *data; + void *comm_ptr; }; void rb_event_io_register_all(void); diff --git a/libratbox/include/ratbox_lib.h b/libratbox/include/ratbox_lib.h index d5df022..b7f2cdd 100644 --- a/libratbox/include/ratbox_lib.h +++ b/libratbox/include/ratbox_lib.h @@ -184,7 +184,7 @@ void rb_set_time(void); const char *rb_lib_version(void); void rb_lib_init(log_cb * xilog, restart_cb * irestart, die_cb * idie, int closeall, int maxfds, - size_t dh_size, size_t fd_heap_size); + size_t dh_size, size_t fd_heap_size); void rb_lib_loop(long delay); time_t rb_current_time(void); diff --git a/libratbox/include/rb_balloc.h b/libratbox/include/rb_balloc.h index 90a4b3c..49435d3 100644 --- a/libratbox/include/rb_balloc.h +++ b/libratbox/include/rb_balloc.h @@ -34,7 +34,7 @@ struct rb_bh; typedef struct rb_bh rb_bh; typedef void rb_bh_usage_cb (size_t bused, size_t bfree, size_t bmemusage, size_t heapalloc, - const char *desc, void *data); + const char *desc, void *data); int rb_bh_free(rb_bh *, void *); diff --git a/libratbox/include/rb_commio.h b/libratbox/include/rb_commio.h index a62e2b7..2bcbd83 100644 --- a/libratbox/include/rb_commio.h +++ b/libratbox/include/rb_commio.h @@ -48,16 +48,15 @@ typedef void ACCB(rb_fde_t *, int status, struct sockaddr *addr, rb_socklen_t le /* callback for pre-accept callback */ typedef int ACPRE(rb_fde_t *, struct sockaddr *addr, rb_socklen_t len, void *); -enum -{ - RB_OK, - RB_ERR_BIND, - RB_ERR_DNS, - RB_ERR_TIMEOUT, - RB_ERR_CONNECT, - RB_ERROR, - RB_ERROR_SSL, - RB_ERR_MAX +enum { + RB_OK, + RB_ERR_BIND, + RB_ERR_DNS, + RB_ERR_TIMEOUT, + RB_ERR_CONNECT, + RB_ERROR, + RB_ERROR_SSL, + RB_ERR_MAX }; #define RB_FD_NONE 0x01 @@ -78,10 +77,9 @@ enum #define RB_RW_SSL_NEED_WRITE -4 /* SSL Needs write */ -struct rb_iovec -{ - void *iov_base; - size_t iov_len; +struct rb_iovec { + void *iov_base; + size_t iov_len; }; @@ -115,7 +113,7 @@ int rb_connect_sockaddr(rb_fde_t *, struct sockaddr *addr, int len); const char *rb_errstr(int status); rb_fde_t *rb_socket(int family, int sock_type, int proto, const char *note); int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2, - const char *note); + const char *note); void rb_accept_tcp(rb_fde_t *, ACPRE * precb, ACCB * callback, void *data); ssize_t rb_write(rb_fde_t *, const void *buf, int count); @@ -154,14 +152,13 @@ uint8_t rb_get_type(rb_fde_t *F); const char *rb_get_iotype(void); -typedef enum -{ - RB_PRNG_EGD, - RB_PRNG_FILE, +typedef enum { + RB_PRNG_EGD, + RB_PRNG_FILE, #ifdef _WIN32 - RB_PRNGWIN32, + RB_PRNGWIN32, #endif - RB_PRNG_DEFAULT, + RB_PRNG_DEFAULT, } prng_seed_t; int rb_init_prng(const char *path, prng_seed_t seed_type); diff --git a/libratbox/include/rb_helper.h b/libratbox/include/rb_helper.h index 3d18eb6..7d77755 100644 --- a/libratbox/include/rb_helper.h +++ b/libratbox/include/rb_helper.h @@ -1,7 +1,7 @@ /* * ircd-ratbox: A slightly useful ircd * helper.h: Starts and deals with ircd helpers - * + * * Copyright (C) 2006 Aaron Sethman * * This program is free software; you can redistribute it and/or modify @@ -36,19 +36,19 @@ typedef void rb_helper_cb(rb_helper *); rb_helper *rb_helper_start(const char *name, const char *fullpath, rb_helper_cb * read_cb, - rb_helper_cb * error_cb); + rb_helper_cb * error_cb); rb_helper *rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb, - log_cb * ilog, restart_cb * irestart, die_cb * idie, - int maxcon, size_t lb_heap_size, size_t dh_size, size_t fd_heap_size); + log_cb * ilog, restart_cb * irestart, die_cb * idie, + int maxcon, size_t lb_heap_size, size_t dh_size, size_t fd_heap_size); void rb_helper_restart(rb_helper *helper); #ifdef __GNUC__ void rb_helper_write(rb_helper *helper, const char *format, ...) __attribute((format(printf, 2, 3))); - void rb_helper_write_queue(rb_helper *helper, const char *format, ...) - __attribute((format(printf, 2, 3))); +void rb_helper_write_queue(rb_helper *helper, const char *format, ...) +__attribute((format(printf, 2, 3))); #else void rb_helper_write(rb_helper *helper, const char *format, ...); void rb_helper_write_queue(rb_helper *helper, const char *format, ...); diff --git a/libratbox/include/rb_linebuf.h b/libratbox/include/rb_linebuf.h index 5644ce3..ac520a4 100644 --- a/libratbox/include/rb_linebuf.h +++ b/libratbox/include/rb_linebuf.h @@ -41,22 +41,20 @@ struct _buf_head; /* How big we want a buffer - 510 data bytes, plus space for a '\0' */ #define BUF_DATA_SIZE 511 -typedef struct _buf_line -{ - char buf[BUF_DATA_SIZE + 2]; - uint8_t terminated; /* Whether we've terminated the buffer */ - uint8_t raw; /* Whether this linebuf may hold 8-bit data */ - int len; /* How much data we've got */ - int refcount; /* how many linked lists are we in? */ +typedef struct _buf_line { + char buf[BUF_DATA_SIZE + 2]; + uint8_t terminated; /* Whether we've terminated the buffer */ + uint8_t raw; /* Whether this linebuf may hold 8-bit data */ + int len; /* How much data we've got */ + int refcount; /* how many linked lists are we in? */ } buf_line_t; -typedef struct _buf_head -{ - rb_dlink_list list; /* the actual dlink list */ - int len; /* length of all the data */ - int alloclen; /* Actual allocated data length */ - int writeofs; /* offset in the first line for the write */ - int numlines; /* number of lines */ +typedef struct _buf_head { + rb_dlink_list list; /* the actual dlink list */ + int len; /* length of all the data */ + int alloclen; /* Actual allocated data length */ + int writeofs; /* offset in the first line for the write */ + int numlines; /* number of lines */ } buf_head_t; diff --git a/libratbox/include/rb_memory.h b/libratbox/include/rb_memory.h index 1bc7af0..46b4028 100644 --- a/libratbox/include/rb_memory.h +++ b/libratbox/include/rb_memory.h @@ -38,48 +38,48 @@ void rb_outofmemory(void); static inline void * rb_malloc(size_t size) { - void *ret = calloc(1, size); - if(rb_unlikely(ret == NULL)) - rb_outofmemory(); - return (ret); + void *ret = calloc(1, size); + if(rb_unlikely(ret == NULL)) + rb_outofmemory(); + return (ret); } static inline void * rb_realloc(void *x, size_t y) { - void *ret = realloc(x, y); + void *ret = realloc(x, y); - if(rb_unlikely(ret == NULL)) - rb_outofmemory(); - return (ret); + if(rb_unlikely(ret == NULL)) + rb_outofmemory(); + return (ret); } static inline char * rb_strndup(const char *x, size_t y) { - char *ret = malloc(y); - if(rb_unlikely(ret == NULL)) - rb_outofmemory(); - rb_strlcpy(ret, x, y); - return (ret); + char *ret = malloc(y); + if(rb_unlikely(ret == NULL)) + rb_outofmemory(); + rb_strlcpy(ret, x, y); + return (ret); } static inline char * rb_strdup(const char *x) { - char *ret = malloc(strlen(x) + 1); - if(rb_unlikely(ret == NULL)) - rb_outofmemory(); - strcpy(ret, x); - return (ret); + char *ret = malloc(strlen(x) + 1); + if(rb_unlikely(ret == NULL)) + rb_outofmemory(); + strcpy(ret, x); + return (ret); } static inline void rb_free(void *ptr) { - if(rb_likely(ptr != NULL)) - free(ptr); + if(rb_likely(ptr != NULL)) + free(ptr); } #endif /* _I_MEMORY_H */ diff --git a/libratbox/include/rb_patricia.h b/libratbox/include/rb_patricia.h index 0340802..fe6c662 100644 --- a/libratbox/include/rb_patricia.h +++ b/libratbox/include/rb_patricia.h @@ -2,7 +2,7 @@ * Dave Plonka * * This product includes software developed by the University of Michigan, - * Merit Network, Inc., and their contributors. + * Merit Network, Inc., and their contributors. * * This file had been called "radix.h" in the MRT sources. * @@ -29,51 +29,47 @@ #define MAXLINE 1024 #define BIT_TEST(f, b) ((f) & (b)) -typedef struct _rb_prefix_t -{ - unsigned short family; /* AF_INET | AF_INET6 */ - unsigned short bitlen; /* same as mask? */ - int ref_count; /* reference count */ - union - { - struct in_addr sin; +typedef struct _rb_prefix_t { + unsigned short family; /* AF_INET | AF_INET6 */ + unsigned short bitlen; /* same as mask? */ + int ref_count; /* reference count */ + union { + struct in_addr sin; #ifdef RB_IPV6 - struct in6_addr sin6; + struct in6_addr sin6; #endif /* RB_IPV6 */ - } - add; + } + add; } rb_prefix_t; -typedef struct _rb_patricia_node_t -{ - unsigned int bit; /* flag if this node used */ - rb_prefix_t *prefix; /* who we are in patricia tree */ - struct _rb_patricia_node_t *l, *r; /* left and right children */ - struct _rb_patricia_node_t *parent; /* may be used */ - void *data; +typedef struct _rb_patricia_node_t { + unsigned int bit; /* flag if this node used */ + rb_prefix_t *prefix; /* who we are in patricia tree */ + struct _rb_patricia_node_t *l, *r; /* left and right children */ + struct _rb_patricia_node_t *parent; /* may be used */ + void *data; } rb_patricia_node_t; -typedef struct _rb_patricia_tree_t -{ - rb_patricia_node_t *head; - unsigned int maxbits; /* for IP, 32 bit addresses */ - int num_active_node; /* for debug purpose */ +typedef struct _rb_patricia_tree_t { + rb_patricia_node_t *head; + unsigned int maxbits; /* for IP, 32 bit addresses */ + int num_active_node; /* for debug purpose */ } rb_patricia_tree_t; rb_patricia_node_t *rb_match_ip(rb_patricia_tree_t *tree, struct sockaddr *ip); rb_patricia_node_t *rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip, - unsigned int len); + unsigned int len); rb_patricia_node_t *rb_match_string(rb_patricia_tree_t *tree, const char *string); rb_patricia_node_t *rb_match_exact_string(rb_patricia_tree_t *tree, const char *string); rb_patricia_node_t *rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix); rb_patricia_node_t *rb_patricia_search_best(rb_patricia_tree_t *patricia, rb_prefix_t *prefix); rb_patricia_node_t *rb_patricia_search_best2(rb_patricia_tree_t *patricia, - rb_prefix_t *prefix, int inclusive); + rb_prefix_t *prefix, int inclusive); rb_patricia_node_t *rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix); void rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node); diff --git a/libratbox/include/rb_snprintf.h b/libratbox/include/rb_snprintf.h index d64a2b7..7785f25 100644 --- a/libratbox/include/rb_snprintf.h +++ b/libratbox/include/rb_snprintf.h @@ -42,11 +42,11 @@ int rb_sprintf(char *str, const char *fmt, ...) __attribute((format(printf, 2, 3))); - int rb_snprintf(char *str, const size_t size, const char *, ...) - __attribute__ ((format(printf, 3, 4))); - int rb_sprintf_append(char *str, const char *format, ...) __attribute((format(printf, 2, 3))); - int rb_snprintf_append(char *str, size_t len, const char *format, ...) - __attribute__ ((format(printf, 3, 4))); +int rb_snprintf(char *str, const size_t size, const char *, ...) +__attribute__ ((format(printf, 3, 4))); +int rb_sprintf_append(char *str, const char *format, ...) __attribute((format(printf, 2, 3))); +int rb_snprintf_append(char *str, size_t len, const char *format, ...) +__attribute__ ((format(printf, 3, 4))); #else int rb_sprintf(char *str, const char *format, ...); int rb_snprintf(char *str, const size_t size, const char *, ...); diff --git a/libratbox/include/rb_tools.h b/libratbox/include/rb_tools.h index e601358..5d492be 100644 --- a/libratbox/include/rb_tools.h +++ b/libratbox/include/rb_tools.h @@ -44,19 +44,17 @@ int rb_string_to_array(char *string, char **parv, int maxpara); typedef struct _rb_dlink_node rb_dlink_node; typedef struct _rb_dlink_list rb_dlink_list; -struct _rb_dlink_node -{ - void *data; - rb_dlink_node *prev; - rb_dlink_node *next; +struct _rb_dlink_node { + void *data; + rb_dlink_node *prev; + rb_dlink_node *next; }; -struct _rb_dlink_list -{ - rb_dlink_node *head; - rb_dlink_node *tail; - unsigned long length; +struct _rb_dlink_list { + rb_dlink_node *head; + rb_dlink_node *tail; + unsigned long length; }; rb_dlink_node *rb_make_rb_dlink_node(void); @@ -68,14 +66,14 @@ void rb_init_rb_dlink_nodes(size_t dh_size); */ /* - * Walks forward of a list. + * Walks forward of a list. * pos is your node * head is your list head */ #define RB_DLINK_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next) /* - * Walks forward of a list safely while removing nodes + * Walks forward of a list safely while removing nodes * pos is your node * n is another list head for temporary storage * head is your list head @@ -93,7 +91,7 @@ void rb_init_rb_dlink_nodes(size_t dh_size); #define rb_dlinkDestroy(node, list) do { rb_dlinkDelete(node, list); rb_free_rb_dlink_node(node); } while(0) -/* +/* * dlink_ routines are stolen from squid, except for rb_dlinkAddBefore, * which is mine. * -- adrian @@ -102,122 +100,119 @@ void rb_init_rb_dlink_nodes(size_t dh_size); static inline void rb_dlinkMoveNode(rb_dlink_node *m, rb_dlink_list *oldlist, rb_dlink_list *newlist) { - /* Assumption: If m->next == NULL, then list->tail == m - * and: If m->prev == NULL, then list->head == m - */ - assert(m != NULL); - assert(oldlist != NULL); - assert(newlist != NULL); + /* Assumption: If m->next == NULL, then list->tail == m + * and: If m->prev == NULL, then list->head == m + */ + assert(m != NULL); + assert(oldlist != NULL); + assert(newlist != NULL); - if(m->next) - m->next->prev = m->prev; - else - oldlist->tail = m->prev; + if(m->next) + m->next->prev = m->prev; + else + oldlist->tail = m->prev; - if(m->prev) - m->prev->next = m->next; - else - oldlist->head = m->next; + if(m->prev) + m->prev->next = m->next; + else + oldlist->head = m->next; - m->prev = NULL; - m->next = newlist->head; - if(newlist->head != NULL) - newlist->head->prev = m; - else if(newlist->tail == NULL) - newlist->tail = m; - newlist->head = m; + m->prev = NULL; + m->next = newlist->head; + if(newlist->head != NULL) + newlist->head->prev = m; + else if(newlist->tail == NULL) + newlist->tail = m; + newlist->head = m; - oldlist->length--; - newlist->length++; + oldlist->length--; + newlist->length++; } static inline void rb_dlinkAdd(void *data, rb_dlink_node *m, rb_dlink_list *list) { - assert(data != NULL); - assert(m != NULL); - assert(list != NULL); + assert(data != NULL); + assert(m != NULL); + assert(list != NULL); - m->data = data; - m->prev = NULL; - m->next = list->head; + m->data = data; + m->prev = NULL; + m->next = list->head; - /* Assumption: If list->tail != NULL, list->head != NULL */ - if(list->head != NULL) - list->head->prev = m; - else if(list->tail == NULL) - list->tail = m; + /* Assumption: If list->tail != NULL, list->head != NULL */ + if(list->head != NULL) + list->head->prev = m; + else if(list->tail == NULL) + list->tail = m; - list->head = m; - list->length++; + list->head = m; + list->length++; } static inline void rb_dlinkAddBefore(rb_dlink_node *b, void *data, rb_dlink_node *m, rb_dlink_list *list) { - assert(b != NULL); - assert(data != NULL); - assert(m != NULL); - assert(list != NULL); + assert(b != NULL); + assert(data != NULL); + assert(m != NULL); + assert(list != NULL); - /* Shortcut - if its the first one, call rb_dlinkAdd only */ - if(b == list->head) - { - rb_dlinkAdd(data, m, list); - } - else - { - m->data = data; - b->prev->next = m; - m->prev = b->prev; - b->prev = m; - m->next = b; - list->length++; - } + /* Shortcut - if its the first one, call rb_dlinkAdd only */ + if(b == list->head) { + rb_dlinkAdd(data, m, list); + } else { + m->data = data; + b->prev->next = m; + m->prev = b->prev; + b->prev = m; + m->next = b; + list->length++; + } } static inline void rb_dlinkMoveTail(rb_dlink_node *m, rb_dlink_list *list) { - if(list->tail == m) - return; + if(list->tail == m) + return; - /* From here assume that m->next != NULL as that can only - * be at the tail and assume that the node is on the list - */ + /* From here assume that m->next != NULL as that can only + * be at the tail and assume that the node is on the list + */ - m->next->prev = m->prev; + m->next->prev = m->prev; - if(m->prev != NULL) - m->prev->next = m->next; - else - list->head = m->next; + if(m->prev != NULL) + m->prev->next = m->next; + else + list->head = m->next; - list->tail->next = m; - m->prev = list->tail; - m->next = NULL; - list->tail = m; + list->tail->next = m; + m->prev = list->tail; + m->next = NULL; + list->tail = m; } static inline void rb_dlinkAddTail(void *data, rb_dlink_node *m, rb_dlink_list *list) { - assert(m != NULL); - assert(list != NULL); - assert(data != NULL); + assert(m != NULL); + assert(list != NULL); + assert(data != NULL); - m->data = data; - m->next = NULL; - m->prev = list->tail; + m->data = data; + m->next = NULL; + m->prev = list->tail; - /* Assumption: If list->tail != NULL, list->head != NULL */ - if(list->tail != NULL) - list->tail->next = m; - else if(list->head == NULL) - list->head = m; + /* Assumption: If list->tail != NULL, list->head != NULL */ + if(list->tail != NULL) + list->tail->next = m; + else if(list->head == NULL) + list->head = m; - list->tail = m; - list->length++; + list->tail = m; + list->length++; } /* Execution profiles show that this function is called the most @@ -226,73 +221,71 @@ rb_dlinkAddTail(void *data, rb_dlink_node *m, rb_dlink_list *list) static inline void rb_dlinkDelete(rb_dlink_node *m, rb_dlink_list *list) { - assert(m != NULL); - assert(list != NULL); - /* Assumption: If m->next == NULL, then list->tail == m - * and: If m->prev == NULL, then list->head == m - */ - if(m->next) - m->next->prev = m->prev; - else - list->tail = m->prev; + assert(m != NULL); + assert(list != NULL); + /* Assumption: If m->next == NULL, then list->tail == m + * and: If m->prev == NULL, then list->head == m + */ + if(m->next) + m->next->prev = m->prev; + else + list->tail = m->prev; - if(m->prev) - m->prev->next = m->next; - else - list->head = m->next; + if(m->prev) + m->prev->next = m->next; + else + list->head = m->next; - m->next = m->prev = NULL; - list->length--; + m->next = m->prev = NULL; + list->length--; } static inline rb_dlink_node * rb_dlinkFindDelete(void *data, rb_dlink_list *list) { - rb_dlink_node *m; - assert(list != NULL); - assert(data != NULL); - RB_DLINK_FOREACH(m, list->head) - { - if(m->data != data) - continue; + rb_dlink_node *m; + assert(list != NULL); + assert(data != NULL); + RB_DLINK_FOREACH(m, list->head) { + if(m->data != data) + continue; - if(m->next) - m->next->prev = m->prev; - else - list->tail = m->prev; + if(m->next) + m->next->prev = m->prev; + else + list->tail = m->prev; - if(m->prev) - m->prev->next = m->next; - else - list->head = m->next; + if(m->prev) + m->prev->next = m->next; + else + list->head = m->next; - m->next = m->prev = NULL; - list->length--; - return m; - } - return NULL; + m->next = m->prev = NULL; + list->length--; + return m; + } + return NULL; } static inline int rb_dlinkFindDestroy(void *data, rb_dlink_list *list) { - void *ptr; + void *ptr; - assert(list != NULL); - assert(data != NULL); - ptr = rb_dlinkFindDelete(data, list); + assert(list != NULL); + assert(data != NULL); + ptr = rb_dlinkFindDelete(data, list); - if(ptr != NULL) - { - rb_free_rb_dlink_node(ptr); - return 1; - } - return 0; + if(ptr != NULL) { + rb_free_rb_dlink_node(ptr); + return 1; + } + return 0; } /* * rb_dlinkFind - * inputs - list to search + * inputs - list to search * - data * output - pointer to link or NULL if not found * side effects - Look for ptr in the linked listed pointed to by link. @@ -300,47 +293,45 @@ rb_dlinkFindDestroy(void *data, rb_dlink_list *list) static inline rb_dlink_node * rb_dlinkFind(void *data, rb_dlink_list *list) { - rb_dlink_node *ptr; - assert(list != NULL); - assert(data != NULL); + rb_dlink_node *ptr; + assert(list != NULL); + assert(data != NULL); - RB_DLINK_FOREACH(ptr, list->head) - { - if(ptr->data == data) - return (ptr); - } - return (NULL); + RB_DLINK_FOREACH(ptr, list->head) { + if(ptr->data == data) + return (ptr); + } + return (NULL); } static inline void rb_dlinkMoveList(rb_dlink_list *from, rb_dlink_list *to) { - assert(from != NULL); - assert(to != NULL); + assert(from != NULL); + assert(to != NULL); - /* There are three cases */ - /* case one, nothing in from list */ - if(from->head == NULL) - return; + /* There are three cases */ + /* case one, nothing in from list */ + if(from->head == NULL) + return; - /* case two, nothing in to list */ - if(to->head == NULL) - { - to->head = from->head; - to->tail = from->tail; - from->head = from->tail = NULL; - to->length = from->length; - from->length = 0; - return; - } + /* case two, nothing in to list */ + if(to->head == NULL) { + to->head = from->head; + to->tail = from->tail; + from->head = from->tail = NULL; + to->length = from->length; + from->length = 0; + return; + } - /* third case play with the links */ - from->tail->next = to->head; - to->head->prev = from->tail; - to->head = from->head; - from->head = from->tail = NULL; - to->length += from->length; - from->length = 0; + /* third case play with the links */ + from->tail->next = to->head; + to->head->prev = from->tail; + to->head = from->head; + from->head = from->tail = NULL; + to->length += from->length; + from->length = 0; } #endif /* __TOOLS_H__ */ diff --git a/libratbox/src/arc4random.c b/libratbox/src/arc4random.c index e508cee..846fb6f 100644 --- a/libratbox/src/arc4random.c +++ b/libratbox/src/arc4random.c @@ -40,11 +40,10 @@ -struct arc4_stream -{ - uint8_t i; - uint8_t j; - uint8_t s[256]; +struct arc4_stream { + uint8_t i; + uint8_t j; + uint8_t s[256]; }; @@ -60,160 +59,155 @@ static inline uint32_t arc4_getword(struct arc4_stream *); static inline void arc4_init(struct arc4_stream *as) { - int n; + int n; - for(n = 0; n < 256; n++) - as->s[n] = n; - as->i = 0; - as->j = 0; + for(n = 0; n < 256; n++) + as->s[n] = n; + as->i = 0; + as->j = 0; } static inline void arc4_addrandom(struct arc4_stream *as, uint8_t *dat, int datlen) { - int n; - uint8_t si; + int n; + uint8_t si; - as->i--; - for(n = 0; n < 256; n++) - { - as->i = (as->i + 1); - si = as->s[as->i]; - as->j = (as->j + si + dat[n % datlen]); - as->s[as->i] = as->s[as->j]; - as->s[as->j] = si; - } - as->j = as->i; + as->i--; + for(n = 0; n < 256; n++) { + as->i = (as->i + 1); + si = as->s[as->i]; + as->j = (as->j + si + dat[n % datlen]); + as->s[as->i] = as->s[as->j]; + as->s[as->j] = si; + } + as->j = as->i; } static void arc4_stir(struct arc4_stream *as) { - struct timeval tv; - pid_t pid; - int n; + struct timeval tv; + pid_t pid; + int n; #ifdef _WIN32 - HMODULE lib; + HMODULE lib; #endif - /* XXX this doesn't support egd sources or similiar */ + /* XXX this doesn't support egd sources or similiar */ - pid = getpid(); - arc4_addrandom(as, (void *)&pid, sizeof(pid)); + pid = getpid(); + arc4_addrandom(as, (void *)&pid, sizeof(pid)); - rb_gettimeofday(&tv, NULL); - arc4_addrandom(as, (void *)&tv.tv_sec, sizeof(&tv.tv_sec)); - arc4_addrandom(as, (void *)&tv.tv_usec, sizeof(&tv.tv_usec)); - rb_gettimeofday(&tv, NULL); - arc4_addrandom(as, (void *)&tv.tv_usec, sizeof(&tv.tv_usec)); + rb_gettimeofday(&tv, NULL); + arc4_addrandom(as, (void *)&tv.tv_sec, sizeof(&tv.tv_sec)); + arc4_addrandom(as, (void *)&tv.tv_usec, sizeof(&tv.tv_usec)); + rb_gettimeofday(&tv, NULL); + arc4_addrandom(as, (void *)&tv.tv_usec, sizeof(&tv.tv_usec)); #if defined(HAVE_GETRUSAGE) && RUSAGE_SELF - { - struct rusage buf; - getrusage(RUSAGE_SELF, &buf); - arc4_addrandom(as, (void *)&buf, sizeof(buf)); - memset(&buf, 0, sizeof(buf))} + { + struct rusage buf; + getrusage(RUSAGE_SELF, &buf); + arc4_addrandom(as, (void *)&buf, sizeof(buf)); + memset(&buf, 0, sizeof(buf)) + } #endif #if !defined(_WIN32) - { - uint8_t rnd[128]; - int fd; - fd = open("/dev/urandom", O_RDONLY); - if(fd != -1) - { - read(fd, rnd, sizeof(rnd)); - close(fd); - arc4_addrandom(as, (void *)rnd, sizeof(rnd)); - memset(&rnd, 0, sizeof(rnd)); - } + { + uint8_t rnd[128]; + int fd; + fd = open("/dev/urandom", O_RDONLY); + if(fd != -1) { + read(fd, rnd, sizeof(rnd)); + close(fd); + arc4_addrandom(as, (void *)rnd, sizeof(rnd)); + memset(&rnd, 0, sizeof(rnd)); + } - } + } #else - { - LARGE_INTEGER performanceCount; - if(QueryPerformanceCounter(&performanceCount)) - { - arc4_addrandom(as, (void *)&performanceCount, sizeof(performanceCount)); - } - lib = LoadLibrary("ADVAPI32.DLL"); - if(lib) - { - uint8_t rnd[128]; - BOOLEAN(APIENTRY * pfn) (void *, ULONG) = - (BOOLEAN(APIENTRY *) (void *, ULONG))GetProcAddress(lib, - "SystemFunction036"); - if(pfn) - { - if(pfn(rnd, sizeof(rnd)) == TRUE) - arc4_addrandom(as, (void *)rnd, sizeof(rnd)); - memset(&rnd, 0, sizeof(rnd)); - } - } - } + { + LARGE_INTEGER performanceCount; + if(QueryPerformanceCounter(&performanceCount)) { + arc4_addrandom(as, (void *)&performanceCount, sizeof(performanceCount)); + } + lib = LoadLibrary("ADVAPI32.DLL"); + if(lib) { + uint8_t rnd[128]; + BOOLEAN(APIENTRY * pfn) (void *, ULONG) = + (BOOLEAN(APIENTRY *) (void *, ULONG))GetProcAddress(lib, + "SystemFunction036"); + if(pfn) { + if(pfn(rnd, sizeof(rnd)) == TRUE) + arc4_addrandom(as, (void *)rnd, sizeof(rnd)); + memset(&rnd, 0, sizeof(rnd)); + } + } + } #endif - /* - * Throw away the first N words of output, as suggested in the - * paper "Weaknesses in the Key Scheduling Algorithm of RC4" - * by Fluher, Mantin, and Shamir. - * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps - * N = 256 in our case. - */ - for(n = 0; n < 256 * 4; n++) - arc4_getbyte(as); + /* + * Throw away the first N words of output, as suggested in the + * paper "Weaknesses in the Key Scheduling Algorithm of RC4" + * by Fluher, Mantin, and Shamir. + * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps + * N = 256 in our case. + */ + for(n = 0; n < 256 * 4; n++) + arc4_getbyte(as); } static inline uint8_t arc4_getbyte(struct arc4_stream *as) { - uint8_t si, sj; + uint8_t si, sj; - as->i = (as->i + 1); - si = as->s[as->i]; - as->j = (as->j + si); - sj = as->s[as->j]; - as->s[as->i] = sj; - as->s[as->j] = si; - return (as->s[(si + sj) & 0xff]); + as->i = (as->i + 1); + si = as->s[as->i]; + as->j = (as->j + si); + sj = as->s[as->j]; + as->s[as->i] = sj; + as->s[as->j] = si; + return (as->s[(si + sj) & 0xff]); } static inline uint32_t arc4_getword(struct arc4_stream *as) { - uint32_t val; - val = arc4_getbyte(as) << 24; - val |= arc4_getbyte(as) << 16; - val |= arc4_getbyte(as) << 8; - val |= arc4_getbyte(as); - return val; + uint32_t val; + val = arc4_getbyte(as) << 24; + val |= arc4_getbyte(as) << 16; + val |= arc4_getbyte(as) << 8; + val |= arc4_getbyte(as); + return val; } void arc4random_stir(void) { - if(!rs_initialized) - { - arc4_init(&rs); - rs_initialized = 1; - } - arc4_stir(&rs); + if(!rs_initialized) { + arc4_init(&rs); + rs_initialized = 1; + } + arc4_stir(&rs); } void arc4random_addrandom(uint8_t *dat, int datlen) { - if(!rs_initialized) - arc4random_stir(); - arc4_addrandom(&rs, dat, datlen); + if(!rs_initialized) + arc4random_stir(); + arc4_addrandom(&rs, dat, datlen); } uint32_t arc4random(void) { - if(!rs_initialized) - arc4random_stir(); - return arc4_getword(&rs); + if(!rs_initialized) + arc4random_stir(); + return arc4_getword(&rs); } #endif diff --git a/libratbox/src/balloc.c b/libratbox/src/balloc.c index 569d6ea..97755e2 100644 --- a/libratbox/src/balloc.c +++ b/libratbox/src/balloc.c @@ -6,11 +6,11 @@ * Copyright (C) 1996-2002 Hybrid Development Team * Copyright (C) 2002-2006 ircd-ratbox development team * - * Below are the orignal headers from the old blalloc.c + * Below are the orignal headers from the old blalloc.c * * File: blalloc.c * Owner: Wohali (Joan Touzet) - * + * * Modified 2001/11/29 for mmap() support by Aaron Sethman * * This program is free software; you can redistribute it and/or modify @@ -30,7 +30,7 @@ * */ -/* +/* * About the block allocator * * Basically we have three ways of getting memory off of the operating @@ -38,11 +38,11 @@ * * 1. mmap() anonymous pages with the MMAP_ANON flag. * 2. mmap() via the /dev/zero trick. - * 3. HeapCreate/HeapAlloc (on win32) - * 4. malloc() + * 3. HeapCreate/HeapAlloc (on win32) + * 4. malloc() * * The advantages of 1 and 2 are this. We can munmap() the pages which will - * return the pages back to the operating system, thus reducing the size + * return the pages back to the operating system, thus reducing the size * of the process as the memory is unused. malloc() on many systems just keeps * a heap of memory to itself, which never gets given back to the OS, except on * exit. This of course is bad, if say we have an event that causes us to allocate @@ -51,7 +51,7 @@ * malloc() has it locked up in its heap. With the mmap() method, we can munmap() * the block and return it back to the OS, thus causing our memory consumption to go * down after we no longer need it. - * + * * * */ @@ -73,24 +73,22 @@ static uintptr_t offset_pad; /* status information for an allocated block in heap */ -struct rb_heap_block -{ - size_t alloc_size; - rb_dlink_node node; - unsigned long free_count; - void *elems; /* Points to allocated memory */ +struct rb_heap_block { + size_t alloc_size; + rb_dlink_node node; + unsigned long free_count; + void *elems; /* Points to allocated memory */ }; typedef struct rb_heap_block rb_heap_block; /* information for the root node of the heap */ -struct rb_bh -{ - rb_dlink_node hlist; - size_t elemSize; /* Size of each element to be stored */ - unsigned long elemsPerBlock; /* Number of elements per block */ - rb_dlink_list block_list; - rb_dlink_list free_list; - char *desc; +struct rb_bh { + rb_dlink_node hlist; + size_t elemSize; /* Size of each element to be stored */ + unsigned long elemsPerBlock; /* Number of elements per block */ + rb_dlink_list block_list; + rb_dlink_list free_list; + char *desc; }; #ifndef NOBALLOC @@ -108,8 +106,8 @@ static HANDLE block_heap; static void _rb_bh_fail(const char *reason, const char *file, int line) { - rb_lib_log("rb_heap_blockheap failure: %s (%s:%d)", reason, file, line); - abort(); + rb_lib_log("rb_heap_blockheap failure: %s (%s:%d)", reason, file, line); + abort(); } #ifndef NOBALLOC @@ -124,12 +122,12 @@ static inline void free_block(void *ptr, size_t size) { #ifdef HAVE_MMAP - munmap(ptr, size); + munmap(ptr, size); #else #ifdef _WIN32 - HeapFree(block_heap, 0, ptr); + HeapFree(block_heap, 0, ptr); #else - free(ptr); + free(ptr); #endif #endif } @@ -137,7 +135,7 @@ free_block(void *ptr, size_t size) /* * void rb_init_bh(void) - * + * * Inputs: None * Outputs: None * Side Effects: Initializes the block heap @@ -146,31 +144,30 @@ free_block(void *ptr, size_t size) void rb_init_bh(void) { - heap_lists = rb_malloc(sizeof(rb_dlink_list)); - offset_pad = sizeof(void *); - /* XXX if you get SIGBUS when trying to use a long long..here is where you need to - * fix your shit - */ + heap_lists = rb_malloc(sizeof(rb_dlink_list)); + offset_pad = sizeof(void *); + /* XXX if you get SIGBUS when trying to use a long long..here is where you need to + * fix your shit + */ #ifdef __sparc__ - if((offset_pad % __alignof__(long long)) != 0) - { - offset_pad += __alignof__(long long); - offset_pad &= ~(__alignof__(long long) - 1); - } + if((offset_pad % __alignof__(long long)) != 0) { + offset_pad += __alignof__(long long); + offset_pad &= ~(__alignof__(long long) - 1); + } #endif #ifndef NOBALLOC #ifdef _WIN32 - block_heap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0); + block_heap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0); #endif - rb_event_addish("rb_bh_gc_event", rb_bh_gc_event, NULL, 300); + rb_event_addish("rb_bh_gc_event", rb_bh_gc_event, NULL, 300); #endif /* !NOBALLOC */ } #ifndef NOBALLOC /* * static inline void *get_block(size_t size) - * + * * Input: Size of block to allocate * Output: Pointer to new block * Side Effects: None @@ -178,39 +175,38 @@ rb_init_bh(void) static inline void * get_block(size_t size) { - void *ptr; + void *ptr; #ifdef HAVE_MMAP #ifdef MAP_ANON - ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); #else - int zero_fd; - zero_fd = open("/dev/zero", O_RDWR); - if(zero_fd < 0) - rb_bh_fail("Failed opening /dev/zero"); - ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0); - close(zero_fd); + int zero_fd; + zero_fd = open("/dev/zero", O_RDWR); + if(zero_fd < 0) + rb_bh_fail("Failed opening /dev/zero"); + ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0); + close(zero_fd); #endif /* MAP_ANON */ - if(ptr == MAP_FAILED) - ptr = NULL; + if(ptr == MAP_FAILED) + ptr = NULL; #else #ifdef _WIN32 - ptr = HeapAlloc(block_heap, 0, size); + ptr = HeapAlloc(block_heap, 0, size); #else - ptr = malloc(size); + ptr = malloc(size); #endif #endif - return (ptr); + return (ptr); } static void rb_bh_gc_event(void *unused) { - rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, heap_lists->head) - { - rb_bh_gc(ptr->data); - } + rb_dlink_node *ptr; + RB_DLINK_FOREACH(ptr, heap_lists->head) { + rb_bh_gc(ptr->data); + } } /* ************************************************************************ */ @@ -227,31 +223,29 @@ rb_bh_gc_event(void *unused) static int newblock(rb_bh *bh) { - rb_heap_block *b; - unsigned long i; - uintptr_t offset; - rb_dlink_node *node; - /* Setup the initial data structure. */ - b = rb_malloc(sizeof(rb_heap_block)); + rb_heap_block *b; + unsigned long i; + uintptr_t offset; + rb_dlink_node *node; + /* Setup the initial data structure. */ + b = rb_malloc(sizeof(rb_heap_block)); - b->alloc_size = bh->elemsPerBlock * bh->elemSize; + b->alloc_size = bh->elemsPerBlock * bh->elemSize; - b->elems = get_block(b->alloc_size); - if(rb_unlikely(b->elems == NULL)) - { - return (1); - } - offset = (uintptr_t)b->elems; - /* Setup our blocks now */ - for(i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize) - { - *((void **)offset) = b; - node = (void *)(offset + offset_pad); - rb_dlinkAdd((void *)offset, node, &bh->free_list); - } - rb_dlinkAdd(b, &b->node, &bh->block_list); - b->free_count = bh->elemsPerBlock; - return (0); + b->elems = get_block(b->alloc_size); + if(rb_unlikely(b->elems == NULL)) { + return (1); + } + offset = (uintptr_t)b->elems; + /* Setup our blocks now */ + for(i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize) { + *((void **)offset) = b; + node = (void *)(offset + offset_pad); + rb_dlinkAdd((void *)offset, node, &bh->free_list); + } + rb_dlinkAdd(b, &b->node, &bh->block_list); + b->free_count = bh->elemsPerBlock; + return (0); } #endif /* !NOBALLOC */ @@ -273,53 +267,49 @@ newblock(rb_bh *bh) rb_bh * rb_bh_create(size_t elemsize, int elemsperblock, const char *desc) { - rb_bh *bh; - lrb_assert(elemsize > 0 && elemsperblock > 0); - lrb_assert(elemsize >= sizeof(rb_dlink_node)); + rb_bh *bh; + lrb_assert(elemsize > 0 && elemsperblock > 0); + lrb_assert(elemsize >= sizeof(rb_dlink_node)); - /* Catch idiotic requests up front */ - if((elemsize == 0) || (elemsperblock <= 0)) - { - rb_bh_fail("Attempting to rb_bh_create idiotic sizes"); - } + /* Catch idiotic requests up front */ + if((elemsize == 0) || (elemsperblock <= 0)) { + rb_bh_fail("Attempting to rb_bh_create idiotic sizes"); + } - if(elemsize < sizeof(rb_dlink_node)) - rb_bh_fail("Attempt to rb_bh_create smaller than sizeof(rb_dlink_node)"); + if(elemsize < sizeof(rb_dlink_node)) + rb_bh_fail("Attempt to rb_bh_create smaller than sizeof(rb_dlink_node)"); - /* Allocate our new rb_bh */ - bh = rb_malloc(sizeof(rb_bh)); + /* Allocate our new rb_bh */ + bh = rb_malloc(sizeof(rb_bh)); #ifndef NOBALLOC - elemsize += offset_pad; - if((elemsize % sizeof(void *)) != 0) - { - /* Pad to even pointer boundary */ - elemsize += sizeof(void *); - elemsize &= ~(sizeof(void *) - 1); - } + elemsize += offset_pad; + if((elemsize % sizeof(void *)) != 0) { + /* Pad to even pointer boundary */ + elemsize += sizeof(void *); + elemsize &= ~(sizeof(void *) - 1); + } #endif - bh->elemSize = elemsize; - bh->elemsPerBlock = elemsperblock; - if(desc != NULL) - bh->desc = rb_strdup(desc); + bh->elemSize = elemsize; + bh->elemsPerBlock = elemsperblock; + if(desc != NULL) + bh->desc = rb_strdup(desc); #ifndef NOBALLOC - /* Be sure our malloc was successful */ - if(newblock(bh)) - { - if(bh != NULL) - free(bh); - rb_lib_log("newblock() failed"); - rb_outofmemory(); /* die.. out of memory */ - } + /* Be sure our malloc was successful */ + if(newblock(bh)) { + if(bh != NULL) + free(bh); + rb_lib_log("newblock() failed"); + rb_outofmemory(); /* die.. out of memory */ + } #endif /* !NOBALLOC */ - if(bh == NULL) - { - rb_bh_fail("bh == NULL when it shouldn't be"); - } - rb_dlinkAdd(bh, &bh->hlist, heap_lists); - return (bh); + if(bh == NULL) { + rb_bh_fail("bh == NULL when it shouldn't be"); + } + rb_dlinkAdd(bh, &bh->hlist, heap_lists); + return (bh); } /* ************************************************************************ */ @@ -338,43 +328,39 @@ void * rb_bh_alloc(rb_bh *bh) { #ifndef NOBALLOC - rb_dlink_node *new_node; - rb_heap_block **block; - void *ptr; + rb_dlink_node *new_node; + rb_heap_block **block; + void *ptr; #endif - lrb_assert(bh != NULL); - if(rb_unlikely(bh == NULL)) - { - rb_bh_fail("Cannot allocate if bh == NULL"); - } + lrb_assert(bh != NULL); + if(rb_unlikely(bh == NULL)) { + rb_bh_fail("Cannot allocate if bh == NULL"); + } #ifdef NOBALLOC - return (rb_malloc(bh->elemSize)); + return (rb_malloc(bh->elemSize)); #else - if(bh->free_list.head == NULL) - { - /* Allocate new block and assign */ - /* newblock returns 1 if unsuccessful, 0 if not */ + if(bh->free_list.head == NULL) { + /* Allocate new block and assign */ + /* newblock returns 1 if unsuccessful, 0 if not */ - if(rb_unlikely(newblock(bh))) - { - rb_lib_log("newblock() failed"); - rb_outofmemory(); /* Well that didn't work either...bail */ - } - if(bh->free_list.head == NULL) - { - rb_lib_log("out of memory after newblock()..."); - rb_outofmemory(); - } - } + if(rb_unlikely(newblock(bh))) { + rb_lib_log("newblock() failed"); + rb_outofmemory(); /* Well that didn't work either...bail */ + } + if(bh->free_list.head == NULL) { + rb_lib_log("out of memory after newblock()..."); + rb_outofmemory(); + } + } - new_node = bh->free_list.head; - block = (rb_heap_block **) new_node->data; - ptr = (void *)((uintptr_t)new_node->data + (uintptr_t)offset_pad); - rb_dlinkDelete(new_node, &bh->free_list); - (*block)->free_count--; - memset(ptr, 0, bh->elemSize - offset_pad); - return (ptr); + new_node = bh->free_list.head; + block = (rb_heap_block **) new_node->data; + ptr = (void *)((uintptr_t)new_node->data + (uintptr_t)offset_pad); + rb_dlinkDelete(new_node, &bh->free_list); + (*block)->free_count--; + memset(ptr, 0, bh->elemSize - offset_pad); + return (ptr); #endif } @@ -394,41 +380,38 @@ int rb_bh_free(rb_bh *bh, void *ptr) { #ifndef NOBALLOC - rb_heap_block *block; - void *data; + rb_heap_block *block; + void *data; #endif - lrb_assert(bh != NULL); - lrb_assert(ptr != NULL); + lrb_assert(bh != NULL); + lrb_assert(ptr != NULL); - if(rb_unlikely(bh == NULL)) - { - rb_lib_log("balloc.c:rb_bhFree() bh == NULL"); - return (1); - } + if(rb_unlikely(bh == NULL)) { + rb_lib_log("balloc.c:rb_bhFree() bh == NULL"); + return (1); + } - if(rb_unlikely(ptr == NULL)) - { - rb_lib_log("balloc.rb_bhFree() ptr == NULL"); - return (1); - } + if(rb_unlikely(ptr == NULL)) { + rb_lib_log("balloc.rb_bhFree() ptr == NULL"); + return (1); + } #ifdef NOBALLOC - rb_free(ptr); + rb_free(ptr); #else - data = (void *)((uintptr_t)ptr - (uintptr_t)offset_pad); - block = *(rb_heap_block **) data; - /* XXX */ - if(rb_unlikely - (!((uintptr_t)ptr >= (uintptr_t)block->elems - && (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size))) - { - rb_bh_fail("rb_bh_free() bogus pointer"); - } - block->free_count++; + data = (void *)((uintptr_t)ptr - (uintptr_t)offset_pad); + block = *(rb_heap_block **) data; + /* XXX */ + if(rb_unlikely + (!((uintptr_t)ptr >= (uintptr_t)block->elems + && (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size))) { + rb_bh_fail("rb_bh_free() bogus pointer"); + } + block->free_count++; - rb_dlinkAdd(data, (rb_dlink_node *)ptr, &bh->free_list); + rb_dlinkAdd(data, (rb_dlink_node *)ptr, &bh->free_list); #endif /* !NOBALLOC */ - return (0); + return (0); } @@ -446,154 +429,145 @@ int rb_bh_destroy(rb_bh *bh) { #ifndef NOBALLOC - rb_dlink_node *ptr, *next; - rb_heap_block *b; + rb_dlink_node *ptr, *next; + rb_heap_block *b; #endif - if(bh == NULL) - return (1); + if(bh == NULL) + return (1); #ifndef NOBALLOC - RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) - { - b = ptr->data; - free_block(b->elems, b->alloc_size); - rb_free(b); - } + RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) { + b = ptr->data; + free_block(b->elems, b->alloc_size); + rb_free(b); + } #endif /* !NOBALLOC */ - rb_dlinkDelete(&bh->hlist, heap_lists); - rb_free(bh->desc); - rb_free(bh); + rb_dlinkDelete(&bh->hlist, heap_lists); + rb_free(bh->desc); + rb_free(bh); - return (0); + return (0); } void rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const char **desc) { #ifndef NOBALLOC - size_t used, freem, memusage; + size_t used, freem, memusage; - if(bh == NULL) - { - return; - } + if(bh == NULL) { + return; + } - freem = rb_dlink_list_length(&bh->free_list); - used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; - memusage = used * bh->elemSize; - if(bused != NULL) - *bused = used; - if(bfree != NULL) - *bfree = freem; - if(bmemusage != NULL) - *bmemusage = memusage; - if(desc != NULL) - *desc = bh->desc; + freem = rb_dlink_list_length(&bh->free_list); + used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; + memusage = used * bh->elemSize; + if(bused != NULL) + *bused = used; + if(bfree != NULL) + *bfree = freem; + if(bmemusage != NULL) + *bmemusage = memusage; + if(desc != NULL) + *desc = bh->desc; #else - if(bused != NULL) - *bused = 0; - if(bfree != NULL) - *bfree = 0; - if(bmemusage != NULL) - *bmemusage = 0; - if(desc != NULL) - *desc = "no blockheap"; + if(bused != NULL) + *bused = 0; + if(bfree != NULL) + *bfree = 0; + if(bmemusage != NULL) + *bmemusage = 0; + if(desc != NULL) + *desc = "no blockheap"; #endif } void rb_bh_usage_all(rb_bh_usage_cb *cb, void *data) { - rb_dlink_node *ptr; - rb_bh *bh; - size_t used, freem, memusage, heapalloc; - static const char *unnamed = "(unnamed_heap)"; - const char *desc = unnamed; + rb_dlink_node *ptr; + rb_bh *bh; + size_t used, freem, memusage, heapalloc; + static const char *unnamed = "(unnamed_heap)"; + const char *desc = unnamed; - if(cb == NULL) - return; + if(cb == NULL) + return; - RB_DLINK_FOREACH(ptr, heap_lists->head) - { - bh = (rb_bh *)ptr->data; - freem = rb_dlink_list_length(&bh->free_list); - used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; - memusage = used * bh->elemSize; - heapalloc = (freem + used) * bh->elemSize; - if(bh->desc != NULL) - desc = bh->desc; - cb(used, freem, memusage, heapalloc, desc, data); - } - return; + RB_DLINK_FOREACH(ptr, heap_lists->head) { + bh = (rb_bh *)ptr->data; + freem = rb_dlink_list_length(&bh->free_list); + used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; + memusage = used * bh->elemSize; + heapalloc = (freem + used) * bh->elemSize; + if(bh->desc != NULL) + desc = bh->desc; + cb(used, freem, memusage, heapalloc, desc, data); + } + return; } void rb_bh_total_usage(size_t *total_alloc, size_t *total_used) { - rb_dlink_node *ptr; - size_t total_memory = 0, used_memory = 0, used, freem; - rb_bh *bh; + rb_dlink_node *ptr; + size_t total_memory = 0, used_memory = 0, used, freem; + rb_bh *bh; - RB_DLINK_FOREACH(ptr, heap_lists->head) - { - bh = (rb_bh *)ptr->data; - freem = rb_dlink_list_length(&bh->free_list); - used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; - used_memory += used * bh->elemSize; - total_memory += (freem + used) * bh->elemSize; - } + RB_DLINK_FOREACH(ptr, heap_lists->head) { + bh = (rb_bh *)ptr->data; + freem = rb_dlink_list_length(&bh->free_list); + used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; + used_memory += used * bh->elemSize; + total_memory += (freem + used) * bh->elemSize; + } - if(total_alloc != NULL) - *total_alloc = total_memory; - if(total_used != NULL) - *total_used = used_memory; + if(total_alloc != NULL) + *total_alloc = total_memory; + if(total_used != NULL) + *total_used = used_memory; } #ifndef NOBALLOC int rb_bh_gc(rb_bh *bh) { - rb_heap_block *b; - rb_dlink_node *ptr, *next; - unsigned long i; - uintptr_t offset; + rb_heap_block *b; + rb_dlink_node *ptr, *next; + unsigned long i; + uintptr_t offset; - if(bh == NULL) - { - /* somebody is smoking some craq..(probably lee, but don't tell him that) */ - return (1); - } + if(bh == NULL) { + /* somebody is smoking some craq..(probably lee, but don't tell him that) */ + return (1); + } - if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock) - || rb_dlink_list_length(&bh->block_list) == 1) - { - /* There couldn't possibly be an entire free block. Return. */ - return (0); - } + if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock) + || rb_dlink_list_length(&bh->block_list) == 1) { + /* There couldn't possibly be an entire free block. Return. */ + return (0); + } - RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) - { - b = ptr->data; - if(rb_dlink_list_length(&bh->block_list) == 1) - return (0); + RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) { + b = ptr->data; + if(rb_dlink_list_length(&bh->block_list) == 1) + return (0); - if(b->free_count == bh->elemsPerBlock) - { - /* i'm seriously going to hell for this.. */ + if(b->free_count == bh->elemsPerBlock) { + /* i'm seriously going to hell for this.. */ - offset = (uintptr_t)b->elems; - for(i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize) - { - rb_dlinkDelete((rb_dlink_node *)(offset + offset_pad), - &bh->free_list); - } - rb_dlinkDelete(&b->node, &bh->block_list); - free_block(b->elems, b->alloc_size); - rb_free(b); - } + offset = (uintptr_t)b->elems; + for(i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize) { + rb_dlinkDelete((rb_dlink_node *)(offset + offset_pad), + &bh->free_list); + } + rb_dlinkDelete(&b->node, &bh->block_list); + free_block(b->elems, b->alloc_size); + rb_free(b); + } - } - return (0); + } + return (0); } #endif /* !NOBALLOC */ diff --git a/libratbox/src/commio.c b/libratbox/src/commio.c index 036948d..54fc29c 100644 --- a/libratbox/src/commio.c +++ b/libratbox/src/commio.c @@ -37,13 +37,12 @@ #endif -struct timeout_data -{ - rb_fde_t *F; - rb_dlink_node node; - time_t timeout; - PF *timeout_handler; - void *timeout_data; +struct timeout_data { + rb_fde_t *F; + rb_dlink_node node; + time_t timeout; + PF *timeout_handler; + void *timeout_data; }; rb_dlink_list *rb_fd_table; @@ -56,10 +55,10 @@ static struct ev_entry *rb_timeout_ev; static const char *rb_err_str[] = { "Comm OK", "Error during bind()", - "Error during DNS lookup", "connect timeout", - "Error during connect()", - "Comm Error" -}; + "Error during DNS lookup", "connect timeout", + "Error during connect()", + "Comm Error" + }; /* Highest FD and number of open FDs .. */ static int number_fd = 0; @@ -79,38 +78,37 @@ static int rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2); static inline rb_fde_t * add_fd(int fd) { - rb_fde_t *F = rb_find_fd(fd); + rb_fde_t *F = rb_find_fd(fd); - /* look up to see if we have it already */ - if(F != NULL) - return F; + /* look up to see if we have it already */ + if(F != NULL) + return F; - F = rb_bh_alloc(fd_heap); - F->fd = fd; - rb_dlinkAdd(F, &F->node, &rb_fd_table[rb_hash_fd(fd)]); - return (F); + F = rb_bh_alloc(fd_heap); + F->fd = fd; + rb_dlinkAdd(F, &F->node, &rb_fd_table[rb_hash_fd(fd)]); + return (F); } static inline void remove_fd(rb_fde_t *F) { - if(F == NULL || !IsFDOpen(F)) - return; + if(F == NULL || !IsFDOpen(F)) + return; - rb_dlinkMoveNode(&F->node, &rb_fd_table[rb_hash_fd(F->fd)], &closed_list); + rb_dlinkMoveNode(&F->node, &rb_fd_table[rb_hash_fd(F->fd)], &closed_list); } static void free_fds(void) { - rb_fde_t *F; - rb_dlink_node *ptr, *next; - RB_DLINK_FOREACH_SAFE(ptr, next, closed_list.head) - { - F = ptr->data; - rb_dlinkDelete(ptr, &closed_list); - rb_bh_free(fd_heap, F); - } + rb_fde_t *F; + rb_dlink_node *ptr, *next; + RB_DLINK_FOREACH_SAFE(ptr, next, closed_list.head) { + F = ptr->data; + rb_dlinkDelete(ptr, &closed_list); + rb_bh_free(fd_heap, F); + } } /* 32bit solaris is kinda slow and stdio only supports fds < 256 @@ -122,15 +120,14 @@ free_fds(void) static void rb_fd_hack(int *fd) { - int newfd; - if(*fd > 256 || *fd < 0) - return; - if((newfd = fcntl(*fd, F_DUPFD, 256)) != -1) - { - close(*fd); - *fd = newfd; - } - return; + int newfd; + if(*fd > 256 || *fd < 0) + return; + if((newfd = fcntl(*fd, F_DUPFD, 256)) != -1) { + close(*fd); + *fd = newfd; + } + return; } #else #define rb_fd_hack(fd) @@ -143,14 +140,13 @@ static void rb_close_all(void) { #ifndef _WIN32 - int i; + int i; - /* XXX someone tell me why we care about 4 fd's ? */ - /* XXX btw, fd 3 is used for profiler ! */ - for(i = 3; i < rb_maxconnections; ++i) - { - close(i); - } + /* XXX someone tell me why we care about 4 fd's ? */ + /* XXX btw, fd 3 is used for profiler ! */ + for(i = 3; i < rb_maxconnections; ++i) { + close(i); + } #endif } @@ -164,26 +160,25 @@ rb_close_all(void) int rb_get_sockerr(rb_fde_t *F) { - int errtmp; - int err = 0; - rb_socklen_t len = sizeof(err); + int errtmp; + int err = 0; + rb_socklen_t len = sizeof(err); - if(!(F->type & RB_FD_SOCKET)) - return errno; + if(!(F->type & RB_FD_SOCKET)) + return errno; - rb_get_errno(); - errtmp = errno; + rb_get_errno(); + errtmp = errno; #ifdef SO_ERROR - if(F != NULL - && !getsockopt(rb_get_fd(F), SOL_SOCKET, SO_ERROR, (char *)&err, (rb_socklen_t *) & len)) - { - if(err) - errtmp = err; - } - errno = errtmp; + if(F != NULL + && !getsockopt(rb_get_fd(F), SOL_SOCKET, SO_ERROR, (char *)&err, (rb_socklen_t *) & len)) { + if(err) + errtmp = err; + } + errno = errtmp; #endif - return errtmp; + return errtmp; } /* @@ -192,12 +187,12 @@ rb_get_sockerr(rb_fde_t *F) int rb_getmaxconnect(void) { - return (rb_maxconnections); + return (rb_maxconnections); } /* * set_sock_buffers - set send and receive buffers for socket - * + * * inputs - fd file descriptor * - size to set * output - returns true (1) if successful, false (0) otherwise @@ -206,17 +201,17 @@ rb_getmaxconnect(void) int rb_set_buffers(rb_fde_t *F, int size) { - if(F == NULL) - return 0; - if(setsockopt - (F->fd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size)) - || setsockopt(F->fd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size))) - return 0; - return 1; + if(F == NULL) + return 0; + if(setsockopt + (F->fd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size)) + || setsockopt(F->fd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size))) + return 0; + return 1; } /* - * set_non_blocking - Set the client connection into non-blocking mode. + * set_non_blocking - Set the client connection into non-blocking mode. * * inputs - fd to set into non blocking mode * output - 1 if successful 0 if not @@ -226,28 +221,28 @@ rb_set_buffers(rb_fde_t *F, int size) int rb_set_nb(rb_fde_t *F) { - int nonb = 0; - int res; - int fd; - if(F == NULL) - return 0; - fd = F->fd; + int nonb = 0; + int res; + int fd; + if(F == NULL) + return 0; + fd = F->fd; - if((res = rb_setup_fd(F))) - return res; + if((res = rb_setup_fd(F))) + return res; #ifdef O_NONBLOCK - nonb |= O_NONBLOCK; - res = fcntl(fd, F_GETFL, 0); - if(-1 == res || fcntl(fd, F_SETFL, res | nonb) == -1) - return 0; + nonb |= O_NONBLOCK; + res = fcntl(fd, F_GETFL, 0); + if(-1 == res || fcntl(fd, F_SETFL, res | nonb) == -1) + return 0; #else - nonb = 1; - res = 0; - if(ioctl(fd, FIONBIO, (char *)&nonb) == -1) - return 0; + nonb = 1; + res = 0; + if(ioctl(fd, FIONBIO, (char *)&nonb) == -1) + return 0; #endif - return 1; + return 1; } /* @@ -258,40 +253,37 @@ rb_set_nb(rb_fde_t *F) void rb_settimeout(rb_fde_t *F, time_t timeout, PF * callback, void *cbdata) { - struct timeout_data *td; + struct timeout_data *td; - if(F == NULL) - return; + if(F == NULL) + return; - lrb_assert(IsFDOpen(F)); - td = F->timeout; - if(callback == NULL) /* user wants to remove */ - { - if(td == NULL) - return; - rb_dlinkDelete(&td->node, &timeout_list); - rb_free(td); - F->timeout = NULL; - if(rb_dlink_list_length(&timeout_list) == 0) - { - rb_event_delete(rb_timeout_ev); - rb_timeout_ev = NULL; - } - return; - } + lrb_assert(IsFDOpen(F)); + td = F->timeout; + if(callback == NULL) { /* user wants to remove */ + if(td == NULL) + return; + rb_dlinkDelete(&td->node, &timeout_list); + rb_free(td); + F->timeout = NULL; + if(rb_dlink_list_length(&timeout_list) == 0) { + rb_event_delete(rb_timeout_ev); + rb_timeout_ev = NULL; + } + return; + } - if(F->timeout == NULL) - td = F->timeout = rb_malloc(sizeof(struct timeout_data)); + if(F->timeout == NULL) + td = F->timeout = rb_malloc(sizeof(struct timeout_data)); - td->F = F; - td->timeout = rb_current_time() + timeout; - td->timeout_handler = callback; - td->timeout_data = cbdata; - rb_dlinkAdd(td, &td->node, &timeout_list); - if(rb_timeout_ev == NULL) - { - rb_timeout_ev = rb_event_add("rb_checktimeouts", rb_checktimeouts, NULL, 5); - } + td->F = F; + td->timeout = rb_current_time() + timeout; + td->timeout_handler = callback; + td->timeout_data = cbdata; + rb_dlinkAdd(td, &td->node, &timeout_list); + if(rb_timeout_ev == NULL) { + rb_timeout_ev = rb_event_add("rb_checktimeouts", rb_checktimeouts, NULL, 5); + } } /* @@ -304,90 +296,81 @@ rb_settimeout(rb_fde_t *F, time_t timeout, PF * callback, void *cbdata) void rb_checktimeouts(void *notused) { - rb_dlink_node *ptr, *next; - struct timeout_data *td; - rb_fde_t *F; - PF *hdl; - void *data; + rb_dlink_node *ptr, *next; + struct timeout_data *td; + rb_fde_t *F; + PF *hdl; + void *data; - RB_DLINK_FOREACH_SAFE(ptr, next, timeout_list.head) - { - td = ptr->data; - F = td->F; - if(F == NULL || !IsFDOpen(F)) - continue; + RB_DLINK_FOREACH_SAFE(ptr, next, timeout_list.head) { + td = ptr->data; + F = td->F; + if(F == NULL || !IsFDOpen(F)) + continue; - if(td->timeout < rb_current_time()) - { - hdl = td->timeout_handler; - data = td->timeout_data; - rb_dlinkDelete(&td->node, &timeout_list); - F->timeout = NULL; - rb_free(td); - hdl(F, data); - } - } + if(td->timeout < rb_current_time()) { + hdl = td->timeout_handler; + data = td->timeout_data; + rb_dlinkDelete(&td->node, &timeout_list); + F->timeout = NULL; + rb_free(td); + hdl(F, data); + } + } } static void rb_accept_tryaccept(rb_fde_t *F, void *data) { - struct rb_sockaddr_storage st; - rb_fde_t *new_F; - rb_socklen_t addrlen = sizeof(st); - int new_fd; + struct rb_sockaddr_storage st; + rb_fde_t *new_F; + rb_socklen_t addrlen = sizeof(st); + int new_fd; - while(1) - { - new_fd = accept(F->fd, (struct sockaddr *)&st, &addrlen); - rb_get_errno(); - if(new_fd < 0) - { - rb_setselect(F, RB_SELECT_ACCEPT, rb_accept_tryaccept, NULL); - return; - } + while(1) { + new_fd = accept(F->fd, (struct sockaddr *)&st, &addrlen); + rb_get_errno(); + if(new_fd < 0) { + rb_setselect(F, RB_SELECT_ACCEPT, rb_accept_tryaccept, NULL); + return; + } - rb_fd_hack(&new_fd); + rb_fd_hack(&new_fd); - new_F = rb_open(new_fd, RB_FD_SOCKET, "Incoming Connection"); + new_F = rb_open(new_fd, RB_FD_SOCKET, "Incoming Connection"); - if(new_F == NULL) - { - rb_lib_log - ("rb_accept: new_F == NULL on incoming connection. Closing new_fd == %d\n", - new_fd); - close(new_fd); - continue; - } + if(new_F == NULL) { + rb_lib_log + ("rb_accept: new_F == NULL on incoming connection. Closing new_fd == %d\n", + new_fd); + close(new_fd); + continue; + } - if(rb_unlikely(!rb_set_nb(new_F))) - { - rb_get_errno(); - rb_lib_log("rb_accept: Couldn't set FD %d non blocking!", new_F->fd); - rb_close(new_F); - } + if(rb_unlikely(!rb_set_nb(new_F))) { + rb_get_errno(); + rb_lib_log("rb_accept: Couldn't set FD %d non blocking!", new_F->fd); + rb_close(new_F); + } #ifdef RB_IPV6 - mangle_mapped_sockaddr((struct sockaddr *)&st); + mangle_mapped_sockaddr((struct sockaddr *)&st); #endif - if(F->accept->precb != NULL) - { - if(!F->accept->precb(new_F, (struct sockaddr *)&st, addrlen, F->accept->data)) /* pre-callback decided to drop it */ - continue; - } + if(F->accept->precb != NULL) { + if(!F->accept->precb(new_F, (struct sockaddr *)&st, addrlen, F->accept->data)) /* pre-callback decided to drop it */ + continue; + } #ifdef HAVE_SSL - if(F->type & RB_FD_SSL) - { - rb_ssl_accept_setup(F, new_F, (struct sockaddr *)&st, addrlen); - } - else + if(F->type & RB_FD_SSL) { + rb_ssl_accept_setup(F, new_F, (struct sockaddr *)&st, addrlen); + } else #endif /* HAVE_SSL */ - { - F->accept->callback(new_F, RB_OK, (struct sockaddr *)&st, addrlen, - F->accept->data); - } - } + { + F->accept->callback(new_F, RB_OK, (struct sockaddr *)&st, addrlen, + F->accept->data); + } + } } @@ -395,15 +378,15 @@ rb_accept_tryaccept(rb_fde_t *F, void *data) void rb_accept_tcp(rb_fde_t *F, ACPRE * precb, ACCB * callback, void *data) { - if(F == NULL) - return; - lrb_assert(callback); + if(F == NULL) + return; + lrb_assert(callback); - F->accept = rb_malloc(sizeof(struct acceptdata)); - F->accept->callback = callback; - F->accept->data = data; - F->accept->precb = precb; - rb_accept_tryaccept(F, NULL); + F->accept = rb_malloc(sizeof(struct acceptdata)); + F->accept->callback = callback; + F->accept->data = data; + F->accept->precb = precb; + rb_accept_tryaccept(F, NULL); } /* @@ -421,37 +404,36 @@ rb_accept_tcp(rb_fde_t *F, ACPRE * precb, ACCB * callback, void *data) */ void rb_connect_tcp(rb_fde_t *F, struct sockaddr *dest, - struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) + struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) { - if(F == NULL) - return; + if(F == NULL) + return; - lrb_assert(callback); - F->connect = rb_malloc(sizeof(struct conndata)); - F->connect->callback = callback; - F->connect->data = data; + lrb_assert(callback); + F->connect = rb_malloc(sizeof(struct conndata)); + F->connect->callback = callback; + F->connect->data = data; - memcpy(&F->connect->hostaddr, dest, sizeof(F->connect->hostaddr)); + memcpy(&F->connect->hostaddr, dest, sizeof(F->connect->hostaddr)); - /* Note that we're using a passed sockaddr here. This is because - * generally you'll be bind()ing to a sockaddr grabbed from - * getsockname(), so this makes things easier. - * XXX If NULL is passed as local, we should later on bind() to the - * virtual host IP, for completeness. - * -- adrian - */ - if((clocal != NULL) && (bind(F->fd, clocal, socklen) < 0)) - { - /* Failure, call the callback with RB_ERR_BIND */ - rb_connect_callback(F, RB_ERR_BIND); - /* ... and quit */ - return; - } + /* Note that we're using a passed sockaddr here. This is because + * generally you'll be bind()ing to a sockaddr grabbed from + * getsockname(), so this makes things easier. + * XXX If NULL is passed as local, we should later on bind() to the + * virtual host IP, for completeness. + * -- adrian + */ + if((clocal != NULL) && (bind(F->fd, clocal, socklen) < 0)) { + /* Failure, call the callback with RB_ERR_BIND */ + rb_connect_callback(F, RB_ERR_BIND); + /* ... and quit */ + return; + } - /* We have a valid IP, so we just call tryconnect */ - /* Make sure we actually set the timeout here .. */ - rb_settimeout(F, timeout, rb_connect_timeout, NULL); - rb_connect_tryconnect(F, NULL); + /* We have a valid IP, so we just call tryconnect */ + /* Make sure we actually set the timeout here .. */ + rb_settimeout(F, timeout, rb_connect_timeout, NULL); + rb_connect_tryconnect(F, NULL); } @@ -461,24 +443,24 @@ rb_connect_tcp(rb_fde_t *F, struct sockaddr *dest, void rb_connect_callback(rb_fde_t *F, int status) { - CNCB *hdl; - void *data; - int errtmp = errno; /* save errno as rb_settimeout clobbers it sometimes */ + CNCB *hdl; + void *data; + int errtmp = errno; /* save errno as rb_settimeout clobbers it sometimes */ - /* This check is gross..but probably necessary */ - if(F == NULL || F->connect == NULL || F->connect->callback == NULL) - return; - /* Clear the connect flag + handler */ - hdl = F->connect->callback; - data = F->connect->data; - F->connect->callback = NULL; + /* This check is gross..but probably necessary */ + if(F == NULL || F->connect == NULL || F->connect->callback == NULL) + return; + /* Clear the connect flag + handler */ + hdl = F->connect->callback; + data = F->connect->data; + F->connect->callback = NULL; - /* Clear the timeout handler */ - rb_settimeout(F, 0, NULL, NULL); - errno = errtmp; - /* Call the handler */ - hdl(F, status, data); + /* Clear the timeout handler */ + rb_settimeout(F, 0, NULL, NULL); + errno = errtmp; + /* Call the handler */ + hdl(F, status, data); } @@ -490,8 +472,8 @@ rb_connect_callback(rb_fde_t *F, int status) static void rb_connect_timeout(rb_fde_t *F, void *notused) { - /* error! */ - rb_connect_callback(F, RB_ERR_TIMEOUT); + /* error! */ + rb_connect_callback(F, RB_ERR_TIMEOUT); } /* static void rb_connect_tryconnect(int fd, void *notused) @@ -505,46 +487,45 @@ rb_connect_timeout(rb_fde_t *F, void *notused) static void rb_connect_tryconnect(rb_fde_t *F, void *notused) { - int retval; + int retval; - if(F == NULL || F->connect == NULL || F->connect->callback == NULL) - return; - /* Try the connect() */ - retval = connect(F->fd, - (struct sockaddr *)&F->connect->hostaddr, - GET_SS_LEN(&F->connect->hostaddr)); - /* Error? */ - if(retval < 0) - { - /* - * If we get EISCONN, then we've already connect()ed the socket, - * which is a good thing. - * -- adrian - */ - rb_get_errno(); - if(errno == EISCONN) - rb_connect_callback(F, RB_OK); - else if(rb_ignore_errno(errno)) - /* Ignore error? Reschedule */ - rb_setselect(F, RB_SELECT_CONNECT, rb_connect_tryconnect, NULL); - else - /* Error? Fail with RB_ERR_CONNECT */ - rb_connect_callback(F, RB_ERR_CONNECT); - return; - } - /* If we get here, we've suceeded, so call with RB_OK */ - rb_connect_callback(F, RB_OK); + if(F == NULL || F->connect == NULL || F->connect->callback == NULL) + return; + /* Try the connect() */ + retval = connect(F->fd, + (struct sockaddr *)&F->connect->hostaddr, + GET_SS_LEN(&F->connect->hostaddr)); + /* Error? */ + if(retval < 0) { + /* + * If we get EISCONN, then we've already connect()ed the socket, + * which is a good thing. + * -- adrian + */ + rb_get_errno(); + if(errno == EISCONN) + rb_connect_callback(F, RB_OK); + else if(rb_ignore_errno(errno)) + /* Ignore error? Reschedule */ + rb_setselect(F, RB_SELECT_CONNECT, rb_connect_tryconnect, NULL); + else + /* Error? Fail with RB_ERR_CONNECT */ + rb_connect_callback(F, RB_ERR_CONNECT); + return; + } + /* If we get here, we've suceeded, so call with RB_OK */ + rb_connect_callback(F, RB_OK); } int rb_connect_sockaddr(rb_fde_t *F, struct sockaddr *addr, int len) { - if(F == NULL) - return 0; + if(F == NULL) + return 0; - memcpy(addr, &F->connect->hostaddr, len); - return 1; + memcpy(addr, &F->connect->hostaddr, len); + return 1; } /* @@ -553,71 +534,65 @@ rb_connect_sockaddr(rb_fde_t *F, struct sockaddr *addr, int len) const char * rb_errstr(int error) { - if(error < 0 || error >= RB_ERR_MAX) - return "Invalid error number!"; - return rb_err_str[error]; + if(error < 0 || error >= RB_ERR_MAX) + return "Invalid error number!"; + return rb_err_str[error]; } int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2, const char *note) { - int nfd[2]; - if(number_fd >= rb_maxconnections) - { - errno = ENFILE; - return -1; - } + int nfd[2]; + if(number_fd >= rb_maxconnections) { + errno = ENFILE; + return -1; + } #ifdef HAVE_SOCKETPAIR - if(socketpair(family, sock_type, proto, nfd)) + if(socketpair(family, sock_type, proto, nfd)) #else - if(sock_type == SOCK_DGRAM) - { - return rb_inet_socketpair_udp(F1, F2); - } + if(sock_type == SOCK_DGRAM) { + return rb_inet_socketpair_udp(F1, F2); + } - if(rb_inet_socketpair(AF_INET, sock_type, proto, nfd)) + if(rb_inet_socketpair(AF_INET, sock_type, proto, nfd)) #endif - return -1; + return -1; - rb_fd_hack(&nfd[0]); - rb_fd_hack(&nfd[1]); + rb_fd_hack(&nfd[0]); + rb_fd_hack(&nfd[1]); - *F1 = rb_open(nfd[0], RB_FD_SOCKET, note); - *F2 = rb_open(nfd[1], RB_FD_SOCKET, note); + *F1 = rb_open(nfd[0], RB_FD_SOCKET, note); + *F2 = rb_open(nfd[1], RB_FD_SOCKET, note); - if(*F1 == NULL) - { - if(*F2 != NULL) - rb_close(*F2); - return -1; - } + if(*F1 == NULL) { + if(*F2 != NULL) + rb_close(*F2); + return -1; + } - if(*F2 == NULL) - { - rb_close(*F1); - return -1; - } + if(*F2 == NULL) { + rb_close(*F1); + return -1; + } - /* Set the socket non-blocking, and other wonderful bits */ - if(rb_unlikely(!rb_set_nb(*F1))) - { - rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", nfd[0], strerror(errno)); - rb_close(*F1); - rb_close(*F2); - return -1; - } + /* Set the socket non-blocking, and other wonderful bits */ + if(rb_unlikely(!rb_set_nb(*F1))) { + rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", nfd[0], strerror(errno)); + rb_close(*F1); + rb_close(*F2); + return -1; + } - if(rb_unlikely(!rb_set_nb(*F2))) - { - rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", nfd[1], strerror(errno)); - rb_close(*F1); - rb_close(*F2); - return -1; - } + if(rb_unlikely(!rb_set_nb(*F2))) { + rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", nfd[1], strerror(errno)); + rb_close(*F1); + rb_close(*F2); + return -1; + } - return 0; + return 0; } @@ -625,42 +600,39 @@ int rb_pipe(rb_fde_t **F1, rb_fde_t **F2, const char *desc) { #ifndef _WIN32 - int fd[2]; - if(number_fd >= rb_maxconnections) - { - errno = ENFILE; - return -1; - } - if(pipe(fd) == -1) - return -1; - rb_fd_hack(&fd[0]); - rb_fd_hack(&fd[1]); - *F1 = rb_open(fd[0], RB_FD_PIPE, desc); - *F2 = rb_open(fd[1], RB_FD_PIPE, desc); + int fd[2]; + if(number_fd >= rb_maxconnections) { + errno = ENFILE; + return -1; + } + if(pipe(fd) == -1) + return -1; + rb_fd_hack(&fd[0]); + rb_fd_hack(&fd[1]); + *F1 = rb_open(fd[0], RB_FD_PIPE, desc); + *F2 = rb_open(fd[1], RB_FD_PIPE, desc); - if(rb_unlikely(!rb_set_nb(*F1))) - { - rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", fd[0], strerror(errno)); - rb_close(*F1); - rb_close(*F2); - return -1; - } + if(rb_unlikely(!rb_set_nb(*F1))) { + rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", fd[0], strerror(errno)); + rb_close(*F1); + rb_close(*F2); + return -1; + } - if(rb_unlikely(!rb_set_nb(*F2))) - { - rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", fd[1], strerror(errno)); - rb_close(*F1); - rb_close(*F2); - return -1; - } + if(rb_unlikely(!rb_set_nb(*F2))) { + rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", fd[1], strerror(errno)); + rb_close(*F1); + rb_close(*F2); + return -1; + } - return 0; + return 0; #else - /* Its not a pipe..but its selectable. I'll take dirty hacks - * for $500 Alex. - */ - return rb_socketpair(AF_INET, SOCK_STREAM, 0, F1, F2, desc); + /* Its not a pipe..but its selectable. I'll take dirty hacks + * for $500 Alex. + */ + return rb_socketpair(AF_INET, SOCK_STREAM, 0, F1, F2, desc); #endif } @@ -674,60 +646,55 @@ rb_pipe(rb_fde_t **F1, rb_fde_t **F2, const char *desc) rb_fde_t * rb_socket(int family, int sock_type, int proto, const char *note) { - rb_fde_t *F; - int fd; - /* First, make sure we aren't going to run out of file descriptors */ - if(rb_unlikely(number_fd >= rb_maxconnections)) - { - errno = ENFILE; - return NULL; - } + rb_fde_t *F; + int fd; + /* First, make sure we aren't going to run out of file descriptors */ + if(rb_unlikely(number_fd >= rb_maxconnections)) { + errno = ENFILE; + return NULL; + } - /* - * Next, we try to open the socket. We *should* drop the reserved FD - * limit if/when we get an error, but we can deal with that later. - * XXX !!! -- adrian - */ - fd = socket(family, sock_type, proto); - rb_fd_hack(&fd); - if(rb_unlikely(fd < 0)) - return NULL; /* errno will be passed through, yay.. */ + /* + * Next, we try to open the socket. We *should* drop the reserved FD + * limit if/when we get an error, but we can deal with that later. + * XXX !!! -- adrian + */ + fd = socket(family, sock_type, proto); + rb_fd_hack(&fd); + if(rb_unlikely(fd < 0)) + return NULL; /* errno will be passed through, yay.. */ #if defined(RB_IPV6) && defined(IPV6_V6ONLY) - /* - * Make sure we can take both IPv4 and IPv6 connections - * on an AF_INET6 socket - */ - if(family == AF_INET6) - { - int off = 1; - if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off)) == -1) - { - rb_lib_log("rb_socket: Could not set IPV6_V6ONLY option to 1 on FD %d: %s", - fd, strerror(errno)); - close(fd); - return NULL; - } - } + /* + * Make sure we can take both IPv4 and IPv6 connections + * on an AF_INET6 socket + */ + if(family == AF_INET6) { + int off = 1; + if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off)) == -1) { + rb_lib_log("rb_socket: Could not set IPV6_V6ONLY option to 1 on FD %d: %s", + fd, strerror(errno)); + close(fd); + return NULL; + } + } #endif - F = rb_open(fd, RB_FD_SOCKET, note); - if(F == NULL) - { - rb_lib_log("rb_socket: rb_open returns NULL on FD %d: %s, closing fd", fd, - strerror(errno)); - close(fd); - return NULL; - } - /* Set the socket non-blocking, and other wonderful bits */ - if(rb_unlikely(!rb_set_nb(F))) - { - rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", fd, strerror(errno)); - rb_close(F); - return NULL; - } + F = rb_open(fd, RB_FD_SOCKET, note); + if(F == NULL) { + rb_lib_log("rb_socket: rb_open returns NULL on FD %d: %s, closing fd", fd, + strerror(errno)); + close(fd); + return NULL; + } + /* Set the socket non-blocking, and other wonderful bits */ + if(rb_unlikely(!rb_set_nb(F))) { + rb_lib_log("rb_open: Couldn't set FD %d non blocking: %s", fd, strerror(errno)); + rb_close(F); + return NULL; + } - return F; + return F; } /* @@ -738,21 +705,20 @@ rb_socket(int family, int sock_type, int proto, const char *note) static void mangle_mapped_sockaddr(struct sockaddr *in) { - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)in; + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)in; - if(in->sa_family == AF_INET) - return; + if(in->sa_family == AF_INET) + return; - if(in->sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&in6->sin6_addr)) - { - struct sockaddr_in in4; - memset(&in4, 0, sizeof(struct sockaddr_in)); - in4.sin_family = AF_INET; - in4.sin_port = in6->sin6_port; - in4.sin_addr.s_addr = ((uint32_t *)&in6->sin6_addr)[3]; - memcpy(in, &in4, sizeof(struct sockaddr_in)); - } - return; + if(in->sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&in6->sin6_addr)) { + struct sockaddr_in in4; + memset(&in4, 0, sizeof(struct sockaddr_in)); + in4.sin_family = AF_INET; + in4.sin_port = in6->sin6_port; + in4.sin_addr.s_addr = ((uint32_t *)&in6->sin6_addr)[3]; + memcpy(in, &in4, sizeof(struct sockaddr_in)); + } + return; } #endif @@ -762,58 +728,54 @@ mangle_mapped_sockaddr(struct sockaddr *in) int rb_listen(rb_fde_t *F, int backlog, int defer_accept) { - int result; + int result; - F->type = RB_FD_SOCKET | RB_FD_LISTEN; + F->type = RB_FD_SOCKET | RB_FD_LISTEN; - result = listen(F->fd, backlog); + result = listen(F->fd, backlog); #ifdef TCP_DEFER_ACCEPT - if (defer_accept && !result) - { - setsockopt(F->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &backlog, sizeof(int)); - } + if (defer_accept && !result) { + setsockopt(F->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &backlog, sizeof(int)); + } #endif #ifdef SO_ACCEPTFILTER - if (defer_accept && !result) - { - struct accept_filter_arg afa; + if (defer_accept && !result) { + struct accept_filter_arg afa; - memset(&afa, '\0', sizeof afa); - rb_strlcpy(afa.af_name, "dataready", sizeof afa.af_name); - (void)setsockopt(F->fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, - sizeof afa); - } + memset(&afa, '\0', sizeof afa); + rb_strlcpy(afa.af_name, "dataready", sizeof afa.af_name); + (void)setsockopt(F->fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, + sizeof afa); + } #endif - return result; + return result; } void rb_fdlist_init(int closeall, int maxfds, size_t heapsize) { - static int initialized = 0; + static int initialized = 0; #ifdef _WIN32 - WSADATA wsaData; - int err; - int vers = MAKEWORD(2, 0); + WSADATA wsaData; + int err; + int vers = MAKEWORD(2, 0); - err = WSAStartup(vers, &wsaData); - if(err != 0) - { - rb_lib_die("WSAStartup failed"); - } + err = WSAStartup(vers, &wsaData); + if(err != 0) { + rb_lib_die("WSAStartup failed"); + } #endif - if(!initialized) - { - rb_maxconnections = maxfds; - if(closeall) - rb_close_all(); - /* Since we're doing this once .. */ - initialized = 1; - } - fd_heap = rb_bh_create(sizeof(rb_fde_t), heapsize, "librb_fd_heap"); + if(!initialized) { + rb_maxconnections = maxfds; + if(closeall) + rb_close_all(); + /* Since we're doing this once .. */ + initialized = 1; + } + fd_heap = rb_bh_create(sizeof(rb_fde_t), heapsize, "librb_fd_heap"); } @@ -822,30 +784,29 @@ rb_fdlist_init(int closeall, int maxfds, size_t heapsize) rb_fde_t * rb_open(int fd, uint8_t type, const char *desc) { - rb_fde_t *F; - lrb_assert(fd >= 0); + rb_fde_t *F; + lrb_assert(fd >= 0); - F = add_fd(fd); + F = add_fd(fd); - lrb_assert(!IsFDOpen(F)); - if(rb_unlikely(IsFDOpen(F))) - { - const char *fdesc; - if(F != NULL && F->desc != NULL) - fdesc = F->desc; - else - fdesc = "NULL"; - rb_lib_log("Trying to rb_open an already open FD: %d desc: %s", fd, fdesc); - return NULL; - } - F->fd = fd; - F->type = type; - SetFDOpen(F); + lrb_assert(!IsFDOpen(F)); + if(rb_unlikely(IsFDOpen(F))) { + const char *fdesc; + if(F != NULL && F->desc != NULL) + fdesc = F->desc; + else + fdesc = "NULL"; + rb_lib_log("Trying to rb_open an already open FD: %d desc: %s", fd, fdesc); + return NULL; + } + F->fd = fd; + F->type = type; + SetFDOpen(F); - if(desc != NULL) - F->desc = rb_strndup(desc, FD_DESC_SZ); - number_fd++; - return F; + if(desc != NULL) + F->desc = rb_strndup(desc, FD_DESC_SZ); + number_fd++; + return F; } @@ -853,49 +814,44 @@ rb_open(int fd, uint8_t type, const char *desc) void rb_close(rb_fde_t *F) { - int type, fd; + int type, fd; - if(F == NULL) - return; + if(F == NULL) + return; - fd = F->fd; - type = F->type; - lrb_assert(IsFDOpen(F)); + fd = F->fd; + type = F->type; + lrb_assert(IsFDOpen(F)); - lrb_assert(!(type & RB_FD_FILE)); - if(rb_unlikely(type & RB_FD_FILE)) - { - lrb_assert(F->read_handler == NULL); - lrb_assert(F->write_handler == NULL); - } - rb_setselect(F, RB_SELECT_WRITE | RB_SELECT_READ, NULL, NULL); - rb_settimeout(F, 0, NULL, NULL); - rb_free(F->accept); - rb_free(F->connect); - rb_free(F->desc); + lrb_assert(!(type & RB_FD_FILE)); + if(rb_unlikely(type & RB_FD_FILE)) { + lrb_assert(F->read_handler == NULL); + lrb_assert(F->write_handler == NULL); + } + rb_setselect(F, RB_SELECT_WRITE | RB_SELECT_READ, NULL, NULL); + rb_settimeout(F, 0, NULL, NULL); + rb_free(F->accept); + rb_free(F->connect); + rb_free(F->desc); #ifdef HAVE_SSL - if(type & RB_FD_SSL) - { - rb_ssl_shutdown(F); - } + if(type & RB_FD_SSL) { + rb_ssl_shutdown(F); + } #endif /* HAVE_SSL */ - if(IsFDOpen(F)) - { - remove_fd(F); - ClearFDOpen(F); - } + if(IsFDOpen(F)) { + remove_fd(F); + ClearFDOpen(F); + } - number_fd--; + number_fd--; #ifdef _WIN32 - if(type & (RB_FD_SOCKET | RB_FD_PIPE)) - { - closesocket(fd); - return; - } - else + if(type & (RB_FD_SOCKET | RB_FD_PIPE)) { + closesocket(fd); + return; + } else #endif - close(fd); + close(fd); } @@ -905,28 +861,26 @@ rb_close(rb_fde_t *F) void rb_dump_fd(DUMPCB * cb, void *data) { - static const char *empty = ""; - rb_dlink_node *ptr; - rb_dlink_list *bucket; - rb_fde_t *F; - unsigned int i; + static const char *empty = ""; + rb_dlink_node *ptr; + rb_dlink_list *bucket; + rb_fde_t *F; + unsigned int i; - for(i = 0; i < RB_FD_HASH_SIZE; i++) - { - bucket = &rb_fd_table[i]; + for(i = 0; i < RB_FD_HASH_SIZE; i++) { + bucket = &rb_fd_table[i]; - if(rb_dlink_list_length(bucket) <= 0) - continue; + if(rb_dlink_list_length(bucket) <= 0) + continue; - RB_DLINK_FOREACH(ptr, bucket->head) - { - F = ptr->data; - if(F == NULL || !IsFDOpen(F)) - continue; + RB_DLINK_FOREACH(ptr, bucket->head) { + F = ptr->data; + if(F == NULL || !IsFDOpen(F)) + continue; - cb(F->fd, F->desc ? F->desc : empty, data); - } - } + cb(F->fd, F->desc ? F->desc : empty, data); + } + } } /* @@ -938,130 +892,122 @@ rb_dump_fd(DUMPCB * cb, void *data) void rb_note(rb_fde_t *F, const char *string) { - if(F == NULL) - return; + if(F == NULL) + return; - rb_free(F->desc); - F->desc = rb_strndup(string, FD_DESC_SZ); + rb_free(F->desc); + F->desc = rb_strndup(string, FD_DESC_SZ); } void rb_set_type(rb_fde_t *F, uint8_t type) { - /* if the caller is calling this, lets assume they have a clue */ - F->type = type; - return; + /* if the caller is calling this, lets assume they have a clue */ + F->type = type; + return; } uint8_t rb_get_type(rb_fde_t *F) { - return F->type; + return F->type; } int rb_fd_ssl(rb_fde_t *F) { - if(F == NULL) - return 0; - if(F->type & RB_FD_SSL) - return 1; - return 0; + if(F == NULL) + return 0; + if(F->type & RB_FD_SSL) + return 1; + return 0; } int rb_get_fd(rb_fde_t *F) { - if(F == NULL) - return -1; - return (F->fd); + if(F == NULL) + return -1; + return (F->fd); } rb_fde_t * rb_get_fde(int fd) { - return rb_find_fd(fd); + return rb_find_fd(fd); } ssize_t rb_read(rb_fde_t *F, void *buf, int count) { - ssize_t ret; - if(F == NULL) - return 0; + ssize_t ret; + if(F == NULL) + return 0; - /* This needs to be *before* RB_FD_SOCKET otherwise you'll process - * an SSL socket as a regular socket - */ + /* This needs to be *before* RB_FD_SOCKET otherwise you'll process + * an SSL socket as a regular socket + */ #ifdef HAVE_SSL - if(F->type & RB_FD_SSL) - { - return rb_ssl_read(F, buf, count); - } + if(F->type & RB_FD_SSL) { + return rb_ssl_read(F, buf, count); + } #endif - if(F->type & RB_FD_SOCKET) - { - ret = recv(F->fd, buf, count, 0); - if(ret < 0) - { - rb_get_errno(); - } - return ret; - } + if(F->type & RB_FD_SOCKET) { + ret = recv(F->fd, buf, count, 0); + if(ret < 0) { + rb_get_errno(); + } + return ret; + } - /* default case */ - return read(F->fd, buf, count); + /* default case */ + return read(F->fd, buf, count); } ssize_t rb_write(rb_fde_t *F, const void *buf, int count) { - ssize_t ret; - if(F == NULL) - return 0; + ssize_t ret; + if(F == NULL) + return 0; #ifdef HAVE_SSL - if(F->type & RB_FD_SSL) - { - return rb_ssl_write(F, buf, count); - } + if(F->type & RB_FD_SSL) { + return rb_ssl_write(F, buf, count); + } #endif - if(F->type & RB_FD_SOCKET) - { - ret = send(F->fd, buf, count, MSG_NOSIGNAL); - if(ret < 0) - { - rb_get_errno(); - } - return ret; - } + if(F->type & RB_FD_SOCKET) { + ret = send(F->fd, buf, count, MSG_NOSIGNAL); + if(ret < 0) { + rb_get_errno(); + } + return ret; + } - return write(F->fd, buf, count); + return write(F->fd, buf, count); } #if defined(HAVE_SSL) || defined(WIN32) || !defined(HAVE_WRITEV) static ssize_t rb_fake_writev(rb_fde_t *F, const struct rb_iovec *vp, size_t vpcount) { - ssize_t count = 0; + ssize_t count = 0; - while(vpcount-- > 0) - { - ssize_t written = rb_write(F, vp->iov_base, vp->iov_len); + while(vpcount-- > 0) { + ssize_t written = rb_write(F, vp->iov_base, vp->iov_len); - if(written <= 0) - { - if(count > 0) - return count; - else - return written; - } - count += written; - vp++; - } - return (count); + if(written <= 0) { + if(count > 0) + return count; + else + return written; + } + count += written; + vp++; + } + return (count); } #endif @@ -1069,70 +1015,67 @@ rb_fake_writev(rb_fde_t *F, const struct rb_iovec *vp, size_t vpcount) ssize_t rb_writev(rb_fde_t *F, struct rb_iovec * vecount, int count) { - return rb_fake_writev(F, vecount, count); + return rb_fake_writev(F, vecount, count); } #else ssize_t rb_writev(rb_fde_t *F, struct rb_iovec * vector, int count) { - if(F == NULL) - { - errno = EBADF; - return -1; - } + if(F == NULL) { + errno = EBADF; + return -1; + } #ifdef HAVE_SSL - if(F->type & RB_FD_SSL) - { - return rb_fake_writev(F, vector, count); - } + if(F->type & RB_FD_SSL) { + return rb_fake_writev(F, vector, count); + } #endif /* HAVE_SSL */ #ifdef HAVE_SENDMSG - if(F->type & RB_FD_SOCKET) - { - struct msghdr msg; - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = (struct iovec *)vector; - msg.msg_iovlen = count; - return sendmsg(F->fd, &msg, MSG_NOSIGNAL); - } + if(F->type & RB_FD_SOCKET) { + struct msghdr msg; + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = (struct iovec *)vector; + msg.msg_iovlen = count; + return sendmsg(F->fd, &msg, MSG_NOSIGNAL); + } #endif /* HAVE_SENDMSG */ - return writev(F->fd, (struct iovec *)vector, count); + return writev(F->fd, (struct iovec *)vector, count); } #endif -/* +/* * From: Thomas Helvey */ static const char *IpQuadTab[] = { - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", - "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", - "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", - "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", - "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", - "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", - "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", - "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", - "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", - "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", - "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", - "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", - "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", - "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", - "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", - "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", - "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", - "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", - "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", - "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", - "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", - "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", - "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", - "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", - "250", "251", "252", "253", "254", "255" + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", + "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", + "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", + "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", + "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", + "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", + "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", + "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", + "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", + "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", + "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", + "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", + "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", + "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", + "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", + "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", + "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", + "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", + "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", + "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", + "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", + "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", + "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", + "250", "251", "252", "253", "254", "255" }; /* @@ -1149,28 +1092,28 @@ static const char *IpQuadTab[] = { static const char * inetntoa(const char *in) { - static char buf[16]; - char *bufptr = buf; - const unsigned char *a = (const unsigned char *)in; - const char *n; + static char buf[16]; + char *bufptr = buf; + const unsigned char *a = (const unsigned char *)in; + const char *n; - n = IpQuadTab[*a++]; - while(*n) - *bufptr++ = *n++; - *bufptr++ = '.'; - n = IpQuadTab[*a++]; - while(*n) - *bufptr++ = *n++; - *bufptr++ = '.'; - n = IpQuadTab[*a++]; - while(*n) - *bufptr++ = *n++; - *bufptr++ = '.'; - n = IpQuadTab[*a]; - while(*n) - *bufptr++ = *n++; - *bufptr = '\0'; - return buf; + n = IpQuadTab[*a++]; + while(*n) + *bufptr++ = *n++; + *bufptr++ = '.'; + n = IpQuadTab[*a++]; + while(*n) + *bufptr++ = *n++; + *bufptr++ = '.'; + n = IpQuadTab[*a++]; + while(*n) + *bufptr++ = *n++; + *bufptr++ = '.'; + n = IpQuadTab[*a]; + while(*n) + *bufptr++ = *n++; + *bufptr = '\0'; + return buf; } @@ -1217,9 +1160,9 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, unsigned int static const char * inet_ntop4(const unsigned char *src, char *dst, unsigned int size) { - if(size < 16) - return NULL; - return strcpy(dst, inetntoa((const char *)src)); + if(size < 16) + return NULL; + return strcpy(dst, inetntoa((const char *)src)); } /* const char * @@ -1232,149 +1175,134 @@ inet_ntop4(const unsigned char *src, char *dst, unsigned int size) static const char * inet_ntop6(const unsigned char *src, char *dst, unsigned int size) { - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; - struct - { - int base, len; - } - best, cur; - unsigned int words[IN6ADDRSZ / INT16SZ]; - int i; + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + struct { + int base, len; + } + best, cur; + unsigned int words[IN6ADDRSZ / INT16SZ]; + int i; - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for(i = 0; i < IN6ADDRSZ; i += 2) - words[i / 2] = (src[i] << 8) | src[i + 1]; - best.base = -1; - best.len = 0; - cur.base = -1; - cur.len = 0; - for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) - { - if(words[i] == 0) - { - if(cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } - else - { - if(cur.base != -1) - { - if(best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if(cur.base != -1) - { - if(best.base == -1 || cur.len > best.len) - best = cur; - } - if(best.base != -1 && best.len < 2) - best.base = -1; + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof words); + for(i = 0; i < IN6ADDRSZ; i += 2) + words[i / 2] = (src[i] << 8) | src[i + 1]; + best.base = -1; + best.len = 0; + cur.base = -1; + cur.len = 0; + for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { + if(words[i] == 0) { + if(cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if(cur.base != -1) { + if(best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if(cur.base != -1) { + if(best.base == -1 || cur.len > best.len) + best = cur; + } + if(best.base != -1 && best.len < 2) + best.base = -1; - /* - * Format the result. - */ - tp = tmp; - for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) - { - /* Are we inside the best run of 0x00's? */ - if(best.base != -1 && i >= best.base && i < (best.base + best.len)) - { - if(i == best.base) - { - if(i == 0) - *tp++ = '0'; - *tp++ = ':'; - } - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if(i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if(i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) - { - if(!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen(tp); - break; - } - tp += SPRINTF((tp, "%x", words[i])); - } - /* Was it a trailing run of 0x00's? */ - if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; + /* + * Format the result. + */ + tp = tmp; + for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if(best.base != -1 && i >= best.base && i < (best.base + best.len)) { + if(i == best.base) { + if(i == 0) + *tp++ = '0'; + *tp++ = ':'; + } + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if(i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if(i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + if(!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp))) + return (NULL); + tp += strlen(tp); + break; + } + tp += SPRINTF((tp, "%x", words[i])); + } + /* Was it a trailing run of 0x00's? */ + if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; - /* - * Check for overflow, copy, and we're done. - */ + /* + * Check for overflow, copy, and we're done. + */ - if((unsigned int)(tp - tmp) > size) - { - return (NULL); - } - return memcpy(dst, tmp, tp - tmp); + if((unsigned int)(tp - tmp) > size) { + return (NULL); + } + return memcpy(dst, tmp, tp - tmp); } #endif int rb_inet_pton_sock(const char *src, struct sockaddr *dst) { - if(rb_inet_pton(AF_INET, src, &((struct sockaddr_in *)dst)->sin_addr)) - { - ((struct sockaddr_in *)dst)->sin_port = 0; - ((struct sockaddr_in *)dst)->sin_family = AF_INET; - SET_SS_LEN(dst, sizeof(struct sockaddr_in)); - return 1; - } + if(rb_inet_pton(AF_INET, src, &((struct sockaddr_in *)dst)->sin_addr)) { + ((struct sockaddr_in *)dst)->sin_port = 0; + ((struct sockaddr_in *)dst)->sin_family = AF_INET; + SET_SS_LEN(dst, sizeof(struct sockaddr_in)); + return 1; + } #ifdef RB_IPV6 - else if(rb_inet_pton(AF_INET6, src, &((struct sockaddr_in6 *)dst)->sin6_addr)) - { - ((struct sockaddr_in6 *)dst)->sin6_port = 0; - ((struct sockaddr_in6 *)dst)->sin6_family = AF_INET6; - SET_SS_LEN(dst, sizeof(struct sockaddr_in6)); - return 1; - } + else if(rb_inet_pton(AF_INET6, src, &((struct sockaddr_in6 *)dst)->sin6_addr)) { + ((struct sockaddr_in6 *)dst)->sin6_port = 0; + ((struct sockaddr_in6 *)dst)->sin6_family = AF_INET6; + SET_SS_LEN(dst, sizeof(struct sockaddr_in6)); + return 1; + } #endif - return 0; + return 0; } const char * rb_inet_ntop_sock(struct sockaddr *src, char *dst, unsigned int size) { - switch (src->sa_family) - { - case AF_INET: - return (rb_inet_ntop(AF_INET, &((struct sockaddr_in *)src)->sin_addr, dst, size)); - break; + switch (src->sa_family) { + case AF_INET: + return (rb_inet_ntop(AF_INET, &((struct sockaddr_in *)src)->sin_addr, dst, size)); + break; #ifdef RB_IPV6 - case AF_INET6: - return (rb_inet_ntop - (AF_INET6, &((struct sockaddr_in6 *)src)->sin6_addr, dst, size)); - break; + case AF_INET6: + return (rb_inet_ntop + (AF_INET6, &((struct sockaddr_in6 *)src)->sin6_addr, dst, size)); + break; #endif - default: - return NULL; - break; - } + default: + return NULL; + break; + } } /* char * @@ -1388,26 +1316,25 @@ rb_inet_ntop_sock(struct sockaddr *src, char *dst, unsigned int size) const char * rb_inet_ntop(int af, const void *src, char *dst, unsigned int size) { - switch (af) - { - case AF_INET: - return (inet_ntop4(src, dst, size)); + switch (af) { + case AF_INET: + return (inet_ntop4(src, dst, size)); #ifdef RB_IPV6 - case AF_INET6: - if(IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)src) || - IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)src)) - return (inet_ntop4 - ((const unsigned char *)&((const struct in6_addr *)src)-> - s6_addr[12], dst, size)); - else - return (inet_ntop6(src, dst, size)); + case AF_INET6: + if(IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)src) || + IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)src)) + return (inet_ntop4 + ((const unsigned char *)&((const struct in6_addr *)src)-> + s6_addr[12], dst, size)); + else + return (inet_ntop6(src, dst, size)); #endif - default: - return (NULL); - } - /* NOTREACHED */ + default: + return (NULL); + } + /* NOTREACHED */ } /* @@ -1440,43 +1367,37 @@ rb_inet_ntop(int af, const void *src, char *dst, unsigned int size) static int inet_pton4(const char *src, unsigned char *dst) { - int saw_digit, octets, ch; - unsigned char tmp[INADDRSZ], *tp; + int saw_digit, octets, ch; + unsigned char tmp[INADDRSZ], *tp; - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while((ch = *src++) != '\0') - { + saw_digit = 0; + octets = 0; + *(tp = tmp) = 0; + while((ch = *src++) != '\0') { - if(ch >= '0' && ch <= '9') - { - unsigned int new = *tp * 10 + (ch - '0'); + if(ch >= '0' && ch <= '9') { + unsigned int new = *tp * 10 + (ch - '0'); - if(new > 255) - return (0); - *tp = new; - if(!saw_digit) - { - if(++octets > 4) - return (0); - saw_digit = 1; - } - } - else if(ch == '.' && saw_digit) - { - if(octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } - else - return (0); - } - if(octets < 4) - return (0); - memcpy(dst, tmp, INADDRSZ); - return (1); + if(new > 255) + return (0); + *tp = new; + if(!saw_digit) { + if(++octets > 4) + return (0); + saw_digit = 1; + } + } else if(ch == '.' && saw_digit) { + if(octets == 4) + return (0); + *++tp = 0; + saw_digit = 0; + } else + return (0); + } + if(octets < 4) + return (0); + memcpy(dst, tmp, INADDRSZ); + return (1); } #ifdef RB_IPV6 @@ -1497,125 +1418,110 @@ inet_pton4(const char *src, unsigned char *dst) static int inet_pton6(const char *src, unsigned char *dst) { - static const char xdigits[] = "0123456789abcdef"; - unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; - const char *curtok; - int ch, saw_xdigit; - unsigned int val; + static const char xdigits[] = "0123456789abcdef"; + unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; + const char *curtok; + int ch, saw_xdigit; + unsigned int val; - tp = memset(tmp, '\0', IN6ADDRSZ); - endp = tp + IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if(*src == ':') - if(*++src != ':') - return (0); - curtok = src; - saw_xdigit = 0; - val = 0; - while((ch = tolower(*src++)) != '\0') - { - const char *pch; + tp = memset(tmp, '\0', IN6ADDRSZ); + endp = tp + IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if(*src == ':') + if(*++src != ':') + return (0); + curtok = src; + saw_xdigit = 0; + val = 0; + while((ch = tolower(*src++)) != '\0') { + const char *pch; - pch = strchr(xdigits, ch); - if(pch != NULL) - { - val <<= 4; - val |= (pch - xdigits); - if(val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } - if(ch == ':') - { - curtok = src; - if(!saw_xdigit) - { - if(colonp) - return (0); - colonp = tp; - continue; - } - else if(*src == '\0') - { - return (0); - } - if(tp + INT16SZ > endp) - return (0); - *tp++ = (unsigned char)(val >> 8) & 0xff; - *tp++ = (unsigned char)val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } - if(*src != '\0' && ch == '.') - { - if(((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) - { - tp += INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - } - else - continue; - return (0); - } - if(saw_xdigit) - { - if(tp + INT16SZ > endp) - return (0); - *tp++ = (unsigned char)(val >> 8) & 0xff; - *tp++ = (unsigned char)val & 0xff; - } - if(colonp != NULL) - { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = tp - colonp; - int i; + pch = strchr(xdigits, ch); + if(pch != NULL) { + val <<= 4; + val |= (pch - xdigits); + if(val > 0xffff) + return (0); + saw_xdigit = 1; + continue; + } + if(ch == ':') { + curtok = src; + if(!saw_xdigit) { + if(colonp) + return (0); + colonp = tp; + continue; + } else if(*src == '\0') { + return (0); + } + if(tp + INT16SZ > endp) + return (0); + *tp++ = (unsigned char)(val >> 8) & 0xff; + *tp++ = (unsigned char)val & 0xff; + saw_xdigit = 0; + val = 0; + continue; + } + if(*src != '\0' && ch == '.') { + if(((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) { + tp += INADDRSZ; + saw_xdigit = 0; + break; /* '\0' was seen by inet_pton4(). */ + } + } else + continue; + return (0); + } + if(saw_xdigit) { + if(tp + INT16SZ > endp) + return (0); + *tp++ = (unsigned char)(val >> 8) & 0xff; + *tp++ = (unsigned char)val & 0xff; + } + if(colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const int n = tp - colonp; + int i; - if(tp == endp) - return (0); - for(i = 1; i <= n; i++) - { - endp[-i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if(tp != endp) - return (0); - memcpy(dst, tmp, IN6ADDRSZ); - return (1); + if(tp == endp) + return (0); + for(i = 1; i <= n; i++) { + endp[-i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if(tp != endp) + return (0); + memcpy(dst, tmp, IN6ADDRSZ); + return (1); } #endif int rb_inet_pton(int af, const char *src, void *dst) { - switch (af) - { - case AF_INET: - return (inet_pton4(src, dst)); + switch (af) { + case AF_INET: + return (inet_pton4(src, dst)); #ifdef RB_IPV6 - case AF_INET6: - /* Somebody might have passed as an IPv4 address this is sick but it works */ - if(inet_pton4(src, dst)) - { - char tmp[HOSTIPLEN]; - rb_sprintf(tmp, "::ffff:%s", src); - return (inet_pton6(tmp, dst)); - } - else - return (inet_pton6(src, dst)); + case AF_INET6: + /* Somebody might have passed as an IPv4 address this is sick but it works */ + if(inet_pton4(src, dst)) { + char tmp[HOSTIPLEN]; + rb_sprintf(tmp, "::ffff:%s", src); + return (inet_pton6(tmp, dst)); + } else + return (inet_pton6(src, dst)); #endif - default: - return (-1); - } - /* NOTREACHED */ + default: + return (-1); + } + /* NOTREACHED */ } @@ -1625,194 +1531,184 @@ rb_inet_pton(int af, const char *src, void *dst) static int rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2) { - struct sockaddr_in addr[2]; - rb_socklen_t size = sizeof(struct sockaddr_in); - rb_fde_t *F[2]; - unsigned int fd[2]; - int i, got; - unsigned short port; - struct timeval wait = { 0, 100000 }; - int max; - fd_set rset; - struct sockaddr_in readfrom; - unsigned short buf[2]; - int o_errno; + struct sockaddr_in addr[2]; + rb_socklen_t size = sizeof(struct sockaddr_in); + rb_fde_t *F[2]; + unsigned int fd[2]; + int i, got; + unsigned short port; + struct timeval wait = { 0, 100000 }; + int max; + fd_set rset; + struct sockaddr_in readfrom; + unsigned short buf[2]; + int o_errno; - memset(&addr, 0, sizeof(addr)); + memset(&addr, 0, sizeof(addr)); - for(i = 0; i < 2; i++) - { - F[i] = rb_socket(AF_INET, SOCK_DGRAM, 0, "udp socketpair"); - if(F[i] == NULL) - goto failed; - addr[i].sin_family = AF_INET; - addr[i].sin_addr.s_addr = htonl(INADDR_LOOPBACK); - addr[i].sin_port = 0; - if(bind(rb_get_fd(F[i]), (struct sockaddr *)&addr[i], sizeof(struct sockaddr_in))) - goto failed; - fd[i] = rb_get_fd(F[i]); - } + for(i = 0; i < 2; i++) { + F[i] = rb_socket(AF_INET, SOCK_DGRAM, 0, "udp socketpair"); + if(F[i] == NULL) + goto failed; + addr[i].sin_family = AF_INET; + addr[i].sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr[i].sin_port = 0; + if(bind(rb_get_fd(F[i]), (struct sockaddr *)&addr[i], sizeof(struct sockaddr_in))) + goto failed; + fd[i] = rb_get_fd(F[i]); + } - for(i = 0; i < 2; i++) - { - if(getsockname(fd[i], (struct sockaddr *)&addr[i], &size)) - goto failed; - if(size != sizeof(struct sockaddr_in)) - goto failed; - if(connect(fd[!i], (struct sockaddr *)&addr[i], sizeof(struct sockaddr_in)) == -1) - goto failed; - } + for(i = 0; i < 2; i++) { + if(getsockname(fd[i], (struct sockaddr *)&addr[i], &size)) + goto failed; + if(size != sizeof(struct sockaddr_in)) + goto failed; + if(connect(fd[!i], (struct sockaddr *)&addr[i], sizeof(struct sockaddr_in)) == -1) + goto failed; + } - for(i = 0; i < 2; i++) - { - port = addr[i].sin_port; - got = rb_write(F[i], &port, sizeof(port)); - if(got != sizeof(port)) - { - if(got == -1) - goto failed; - goto abort_failed; - } - } + for(i = 0; i < 2; i++) { + port = addr[i].sin_port; + got = rb_write(F[i], &port, sizeof(port)); + if(got != sizeof(port)) { + if(got == -1) + goto failed; + goto abort_failed; + } + } - max = fd[1] > fd[0] ? fd[1] : fd[0]; - FD_ZERO(&rset); - FD_SET(fd[0], &rset); - FD_SET(fd[1], &rset); - got = select(max + 1, &rset, NULL, NULL, &wait); - if(got != 2 || !FD_ISSET(fd[0], &rset) || !FD_ISSET(fd[1], &rset)) - { - if(got == -1) - goto failed; - goto abort_failed; - } + max = fd[1] > fd[0] ? fd[1] : fd[0]; + FD_ZERO(&rset); + FD_SET(fd[0], &rset); + FD_SET(fd[1], &rset); + got = select(max + 1, &rset, NULL, NULL, &wait); + if(got != 2 || !FD_ISSET(fd[0], &rset) || !FD_ISSET(fd[1], &rset)) { + if(got == -1) + goto failed; + goto abort_failed; + } - for(i = 0; i < 2; i++) - { + for(i = 0; i < 2; i++) { #ifdef MSG_DONTWAIT - int flag = MSG_DONTWAIT + int flag = MSG_DONTWAIT #else - int flag = 0; + int flag = 0; #endif - got = recvfrom(rb_get_fd(F[i]), (char *)&buf, sizeof(buf), flag, - (struct sockaddr *)&readfrom, &size); - if(got == -1) - goto failed; - if(got != sizeof(port) - || size != sizeof(struct sockaddr_in) - || buf[0] != (unsigned short)addr[!i].sin_port - || readfrom.sin_family != addr[!i].sin_family - || readfrom.sin_addr.s_addr != addr[!i].sin_addr.s_addr - || readfrom.sin_port != addr[!i].sin_port) - goto abort_failed; - } + got = recvfrom(rb_get_fd(F[i]), (char *)&buf, sizeof(buf), flag, + (struct sockaddr *)&readfrom, &size); + if(got == -1) + goto failed; + if(got != sizeof(port) + || size != sizeof(struct sockaddr_in) + || buf[0] != (unsigned short)addr[!i].sin_port + || readfrom.sin_family != addr[!i].sin_family + || readfrom.sin_addr.s_addr != addr[!i].sin_addr.s_addr + || readfrom.sin_port != addr[!i].sin_port) + goto abort_failed; + } - *newF1 = F[0]; - *newF2 = F[1]; - return 0; + *newF1 = F[0]; + *newF2 = F[1]; + return 0; #ifdef _WIN32 #define ECONNABORTED WSAECONNABORTED #endif - abort_failed: - rb_get_errno(); - errno = ECONNABORTED; - failed: - if(errno != ECONNABORTED) - rb_get_errno(); - o_errno = errno; - if(F[0] != NULL) - rb_close(F[0]); - if(F[1] != NULL) - rb_close(F[1]); - errno = o_errno; - return -1; +abort_failed: + rb_get_errno(); + errno = ECONNABORTED; +failed: + if(errno != ECONNABORTED) + rb_get_errno(); + o_errno = errno; + if(F[0] != NULL) + rb_close(F[0]); + if(F[1] != NULL) + rb_close(F[1]); + errno = o_errno; + return -1; } int rb_inet_socketpair(int family, int type, int protocol, int fd[2]) { - int listener = -1; - int connector = -1; - int acceptor = -1; - struct sockaddr_in listen_addr; - struct sockaddr_in connect_addr; - rb_socklen_t size; + int listener = -1; + int connector = -1; + int acceptor = -1; + struct sockaddr_in listen_addr; + struct sockaddr_in connect_addr; + rb_socklen_t size; - if(protocol || family != AF_INET) - { - errno = EAFNOSUPPORT; - return -1; - } - if(!fd) - { - errno = EINVAL; - return -1; - } + if(protocol || family != AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + if(!fd) { + errno = EINVAL; + return -1; + } - listener = socket(AF_INET, type, 0); - if(listener == -1) - return -1; - memset(&listen_addr, 0, sizeof(listen_addr)); - listen_addr.sin_family = AF_INET; - listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - listen_addr.sin_port = 0; /* kernel choses port. */ - if(bind(listener, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) == -1) - goto tidy_up_and_fail; - if(listen(listener, 1) == -1) - goto tidy_up_and_fail; + listener = socket(AF_INET, type, 0); + if(listener == -1) + return -1; + memset(&listen_addr, 0, sizeof(listen_addr)); + listen_addr.sin_family = AF_INET; + listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + listen_addr.sin_port = 0; /* kernel choses port. */ + if(bind(listener, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) == -1) + goto tidy_up_and_fail; + if(listen(listener, 1) == -1) + goto tidy_up_and_fail; - connector = socket(AF_INET, type, 0); - if(connector == -1) - goto tidy_up_and_fail; - /* We want to find out the port number to connect to. */ - size = sizeof(connect_addr); - if(getsockname(listener, (struct sockaddr *)&connect_addr, &size) == -1) - goto tidy_up_and_fail; - if(size != sizeof(connect_addr)) - goto abort_tidy_up_and_fail; - if(connect(connector, (struct sockaddr *)&connect_addr, sizeof(connect_addr)) == -1) - goto tidy_up_and_fail; + connector = socket(AF_INET, type, 0); + if(connector == -1) + goto tidy_up_and_fail; + /* We want to find out the port number to connect to. */ + size = sizeof(connect_addr); + if(getsockname(listener, (struct sockaddr *)&connect_addr, &size) == -1) + goto tidy_up_and_fail; + if(size != sizeof(connect_addr)) + goto abort_tidy_up_and_fail; + if(connect(connector, (struct sockaddr *)&connect_addr, sizeof(connect_addr)) == -1) + goto tidy_up_and_fail; - size = sizeof(listen_addr); - acceptor = accept(listener, (struct sockaddr *)&listen_addr, &size); - if(acceptor == -1) - goto tidy_up_and_fail; - if(size != sizeof(listen_addr)) - goto abort_tidy_up_and_fail; - close(listener); - /* Now check we are talking to ourself by matching port and host on the - two sockets. */ - if(getsockname(connector, (struct sockaddr *)&connect_addr, &size) == -1) - goto tidy_up_and_fail; - if(size != sizeof(connect_addr) - || listen_addr.sin_family != connect_addr.sin_family - || listen_addr.sin_addr.s_addr != connect_addr.sin_addr.s_addr - || listen_addr.sin_port != connect_addr.sin_port) - { - goto abort_tidy_up_and_fail; - } - fd[0] = connector; - fd[1] = acceptor; - return 0; + size = sizeof(listen_addr); + acceptor = accept(listener, (struct sockaddr *)&listen_addr, &size); + if(acceptor == -1) + goto tidy_up_and_fail; + if(size != sizeof(listen_addr)) + goto abort_tidy_up_and_fail; + close(listener); + /* Now check we are talking to ourself by matching port and host on the + two sockets. */ + if(getsockname(connector, (struct sockaddr *)&connect_addr, &size) == -1) + goto tidy_up_and_fail; + if(size != sizeof(connect_addr) + || listen_addr.sin_family != connect_addr.sin_family + || listen_addr.sin_addr.s_addr != connect_addr.sin_addr.s_addr + || listen_addr.sin_port != connect_addr.sin_port) { + goto abort_tidy_up_and_fail; + } + fd[0] = connector; + fd[1] = acceptor; + return 0; - abort_tidy_up_and_fail: - errno = EINVAL; /* I hope this is portable and appropriate. */ +abort_tidy_up_and_fail: + errno = EINVAL; /* I hope this is portable and appropriate. */ - tidy_up_and_fail: - { - int save_errno = errno; - if(listener != -1) - close(listener); - if(connector != -1) - close(connector); - if(acceptor != -1) - close(acceptor); - errno = save_errno; - return -1; - } +tidy_up_and_fail: { + int save_errno = errno; + if(listener != -1) + close(listener); + if(connector != -1) + close(connector); + if(acceptor != -1) + close(acceptor); + errno = save_errno; + return -1; + } } #endif @@ -1830,286 +1726,263 @@ static char iotype[25]; const char * rb_get_iotype(void) { - return iotype; + return iotype; } static int rb_unsupported_event(void) { - return 0; + return 0; } static int try_kqueue(void) { - if(!rb_init_netio_kqueue()) - { - setselect_handler = rb_setselect_kqueue; - select_handler = rb_select_kqueue; - setup_fd_handler = rb_setup_fd_kqueue; - io_sched_event = rb_kqueue_sched_event; - io_unsched_event = rb_kqueue_unsched_event; - io_init_event = rb_kqueue_init_event; - io_supports_event = rb_kqueue_supports_event; - rb_strlcpy(iotype, "kqueue", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_kqueue()) { + setselect_handler = rb_setselect_kqueue; + select_handler = rb_select_kqueue; + setup_fd_handler = rb_setup_fd_kqueue; + io_sched_event = rb_kqueue_sched_event; + io_unsched_event = rb_kqueue_unsched_event; + io_init_event = rb_kqueue_init_event; + io_supports_event = rb_kqueue_supports_event; + rb_strlcpy(iotype, "kqueue", sizeof(iotype)); + return 0; + } + return -1; } static int try_epoll(void) { - if(!rb_init_netio_epoll()) - { - setselect_handler = rb_setselect_epoll; - select_handler = rb_select_epoll; - setup_fd_handler = rb_setup_fd_epoll; - io_sched_event = rb_epoll_sched_event; - io_unsched_event = rb_epoll_unsched_event; - io_supports_event = rb_epoll_supports_event; - io_init_event = rb_epoll_init_event; - rb_strlcpy(iotype, "epoll", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_epoll()) { + setselect_handler = rb_setselect_epoll; + select_handler = rb_select_epoll; + setup_fd_handler = rb_setup_fd_epoll; + io_sched_event = rb_epoll_sched_event; + io_unsched_event = rb_epoll_unsched_event; + io_supports_event = rb_epoll_supports_event; + io_init_event = rb_epoll_init_event; + rb_strlcpy(iotype, "epoll", sizeof(iotype)); + return 0; + } + return -1; } static int try_ports(void) { - if(!rb_init_netio_ports()) - { - setselect_handler = rb_setselect_ports; - select_handler = rb_select_ports; - setup_fd_handler = rb_setup_fd_ports; - io_sched_event = rb_ports_sched_event; - io_unsched_event = rb_ports_unsched_event; - io_init_event = rb_ports_init_event; - io_supports_event = rb_ports_supports_event; - rb_strlcpy(iotype, "ports", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_ports()) { + setselect_handler = rb_setselect_ports; + select_handler = rb_select_ports; + setup_fd_handler = rb_setup_fd_ports; + io_sched_event = rb_ports_sched_event; + io_unsched_event = rb_ports_unsched_event; + io_init_event = rb_ports_init_event; + io_supports_event = rb_ports_supports_event; + rb_strlcpy(iotype, "ports", sizeof(iotype)); + return 0; + } + return -1; } static int try_devpoll(void) { - if(!rb_init_netio_devpoll()) - { - setselect_handler = rb_setselect_devpoll; - select_handler = rb_select_devpoll; - setup_fd_handler = rb_setup_fd_devpoll; - io_sched_event = NULL; - io_unsched_event = NULL; - io_init_event = NULL; - io_supports_event = rb_unsupported_event; - rb_strlcpy(iotype, "devpoll", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_devpoll()) { + setselect_handler = rb_setselect_devpoll; + select_handler = rb_select_devpoll; + setup_fd_handler = rb_setup_fd_devpoll; + io_sched_event = NULL; + io_unsched_event = NULL; + io_init_event = NULL; + io_supports_event = rb_unsupported_event; + rb_strlcpy(iotype, "devpoll", sizeof(iotype)); + return 0; + } + return -1; } static int try_sigio(void) { - if(!rb_init_netio_sigio()) - { - setselect_handler = rb_setselect_sigio; - select_handler = rb_select_sigio; - setup_fd_handler = rb_setup_fd_sigio; - io_sched_event = rb_sigio_sched_event; - io_unsched_event = rb_sigio_unsched_event; - io_supports_event = rb_sigio_supports_event; - io_init_event = rb_sigio_init_event; + if(!rb_init_netio_sigio()) { + setselect_handler = rb_setselect_sigio; + select_handler = rb_select_sigio; + setup_fd_handler = rb_setup_fd_sigio; + io_sched_event = rb_sigio_sched_event; + io_unsched_event = rb_sigio_unsched_event; + io_supports_event = rb_sigio_supports_event; + io_init_event = rb_sigio_init_event; - rb_strlcpy(iotype, "sigio", sizeof(iotype)); - return 0; - } - return -1; + rb_strlcpy(iotype, "sigio", sizeof(iotype)); + return 0; + } + return -1; } static int try_poll(void) { - if(!rb_init_netio_poll()) - { - setselect_handler = rb_setselect_poll; - select_handler = rb_select_poll; - setup_fd_handler = rb_setup_fd_poll; - io_sched_event = NULL; - io_unsched_event = NULL; - io_init_event = NULL; - io_supports_event = rb_unsupported_event; - rb_strlcpy(iotype, "poll", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_poll()) { + setselect_handler = rb_setselect_poll; + select_handler = rb_select_poll; + setup_fd_handler = rb_setup_fd_poll; + io_sched_event = NULL; + io_unsched_event = NULL; + io_init_event = NULL; + io_supports_event = rb_unsupported_event; + rb_strlcpy(iotype, "poll", sizeof(iotype)); + return 0; + } + return -1; } static int try_win32(void) { - if(!rb_init_netio_win32()) - { - setselect_handler = rb_setselect_win32; - select_handler = rb_select_win32; - setup_fd_handler = rb_setup_fd_win32; - io_sched_event = NULL; - io_unsched_event = NULL; - io_init_event = NULL; - io_supports_event = rb_unsupported_event; - rb_strlcpy(iotype, "win32", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_win32()) { + setselect_handler = rb_setselect_win32; + select_handler = rb_select_win32; + setup_fd_handler = rb_setup_fd_win32; + io_sched_event = NULL; + io_unsched_event = NULL; + io_init_event = NULL; + io_supports_event = rb_unsupported_event; + rb_strlcpy(iotype, "win32", sizeof(iotype)); + return 0; + } + return -1; } static int try_select(void) { - if(!rb_init_netio_select()) - { - setselect_handler = rb_setselect_select; - select_handler = rb_select_select; - setup_fd_handler = rb_setup_fd_select; - io_sched_event = NULL; - io_unsched_event = NULL; - io_init_event = NULL; - io_supports_event = rb_unsupported_event; - rb_strlcpy(iotype, "select", sizeof(iotype)); - return 0; - } - return -1; + if(!rb_init_netio_select()) { + setselect_handler = rb_setselect_select; + select_handler = rb_select_select; + setup_fd_handler = rb_setup_fd_select; + io_sched_event = NULL; + io_unsched_event = NULL; + io_init_event = NULL; + io_supports_event = rb_unsupported_event; + rb_strlcpy(iotype, "select", sizeof(iotype)); + return 0; + } + return -1; } int rb_io_sched_event(struct ev_entry *ev, int when) { - if(ev == NULL || io_supports_event == NULL || io_sched_event == NULL - || !io_supports_event()) - return 0; - return io_sched_event(ev, when); + if(ev == NULL || io_supports_event == NULL || io_sched_event == NULL + || !io_supports_event()) + return 0; + return io_sched_event(ev, when); } void rb_io_unsched_event(struct ev_entry *ev) { - if(ev == NULL || io_supports_event == NULL || io_unsched_event == NULL - || !io_supports_event()) - return; - io_unsched_event(ev); + if(ev == NULL || io_supports_event == NULL || io_unsched_event == NULL + || !io_supports_event()) + return; + io_unsched_event(ev); } int rb_io_supports_event(void) { - if(io_supports_event == NULL) - return 0; - return io_supports_event(); + if(io_supports_event == NULL) + return 0; + return io_supports_event(); } void rb_io_init_event(void) { - io_init_event(); - rb_event_io_register_all(); + io_init_event(); + rb_event_io_register_all(); } void rb_init_netio(void) { - char *ioenv = getenv("LIBRB_USE_IOTYPE"); - rb_fd_table = rb_malloc(RB_FD_HASH_SIZE * sizeof(rb_dlink_list)); - rb_init_ssl(); + char *ioenv = getenv("LIBRB_USE_IOTYPE"); + rb_fd_table = rb_malloc(RB_FD_HASH_SIZE * sizeof(rb_dlink_list)); + rb_init_ssl(); - if(ioenv != NULL) - { - if(!strcmp("epoll", ioenv)) - { - if(!try_epoll()) - return; - } - else if(!strcmp("kqueue", ioenv)) - { - if(!try_kqueue()) - return; - } - else if(!strcmp("ports", ioenv)) - { - if(!try_ports()) - return; - } - else if(!strcmp("poll", ioenv)) - { - if(!try_poll()) - return; - } - else if(!strcmp("devpoll", ioenv)) - { - if(!try_devpoll()) - return; - } - else if(!strcmp("sigio", ioenv)) - { - if(!try_sigio()) - return; - } - else if(!strcmp("select", ioenv)) - { - if(!try_select()) - return; - } - if(!strcmp("win32", ioenv)) - { - if(!try_win32()) - return; - } + if(ioenv != NULL) { + if(!strcmp("epoll", ioenv)) { + if(!try_epoll()) + return; + } else if(!strcmp("kqueue", ioenv)) { + if(!try_kqueue()) + return; + } else if(!strcmp("ports", ioenv)) { + if(!try_ports()) + return; + } else if(!strcmp("poll", ioenv)) { + if(!try_poll()) + return; + } else if(!strcmp("devpoll", ioenv)) { + if(!try_devpoll()) + return; + } else if(!strcmp("sigio", ioenv)) { + if(!try_sigio()) + return; + } else if(!strcmp("select", ioenv)) { + if(!try_select()) + return; + } + if(!strcmp("win32", ioenv)) { + if(!try_win32()) + return; + } - } + } - if(!try_kqueue()) - return; - if(!try_epoll()) - return; - if(!try_ports()) - return; - if(!try_devpoll()) - return; - if(!try_sigio()) - return; - if(!try_poll()) - return; - if(!try_win32()) - return; - if(!try_select()) - return; + if(!try_kqueue()) + return; + if(!try_epoll()) + return; + if(!try_ports()) + return; + if(!try_devpoll()) + return; + if(!try_sigio()) + return; + if(!try_poll()) + return; + if(!try_win32()) + return; + if(!try_select()) + return; - rb_lib_log("rb_init_netio: Could not find any io handlers...giving up"); + rb_lib_log("rb_init_netio: Could not find any io handlers...giving up"); - abort(); + abort(); } void rb_setselect(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - setselect_handler(F, type, handler, client_data); + setselect_handler(F, type, handler, client_data); } int rb_select(unsigned long timeout) { - int ret = select_handler(timeout); - free_fds(); - return ret; + int ret = select_handler(timeout); + free_fds(); + return ret; } int rb_setup_fd(rb_fde_t *F) { - return setup_fd_handler(F); + return setup_fd_handler(F); } @@ -2117,31 +1990,30 @@ rb_setup_fd(rb_fde_t *F) int rb_ignore_errno(int error) { - switch (error) - { + switch (error) { #ifdef EINPROGRESS - case EINPROGRESS: + case EINPROGRESS: #endif #if defined EWOULDBLOCK - case EWOULDBLOCK: + case EWOULDBLOCK: #endif #if defined(EAGAIN) && (EWOULDBLOCK != EAGAIN) - case EAGAIN: + case EAGAIN: #endif #ifdef EINTR - case EINTR: + case EINTR: #endif #ifdef ERESTART - case ERESTART: + case ERESTART: #endif #ifdef ENOBUFS - case ENOBUFS: + case ENOBUFS: #endif - return 1; - default: - break; - } - return 0; + return 1; + default: + break; + } + return 0; } @@ -2149,133 +2021,119 @@ rb_ignore_errno(int error) int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds) { - struct msghdr msg; - struct cmsghdr *cmsg; - struct iovec iov[1]; - struct stat st; - uint8_t stype = RB_FD_UNKNOWN; - const char *desc; - int fd, len, x, rfds; + struct msghdr msg; + struct cmsghdr *cmsg; + struct iovec iov[1]; + struct stat st; + uint8_t stype = RB_FD_UNKNOWN; + const char *desc; + int fd, len, x, rfds; - int control_len = CMSG_SPACE(sizeof(int) * nfds); + int control_len = CMSG_SPACE(sizeof(int) * nfds); - iov[0].iov_base = data; - iov[0].iov_len = datasize; + iov[0].iov_base = data; + iov[0].iov_len = datasize; - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_iov = iov; - msg.msg_iovlen = 1; - msg.msg_flags = 0; - cmsg = alloca(control_len); - msg.msg_control = cmsg; - msg.msg_controllen = control_len; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_iov = iov; + msg.msg_iovlen = 1; + msg.msg_flags = 0; + cmsg = alloca(control_len); + msg.msg_control = cmsg; + msg.msg_controllen = control_len; - if((len = recvmsg(rb_get_fd(F), &msg, 0)) <= 0) - return len; + if((len = recvmsg(rb_get_fd(F), &msg, 0)) <= 0) + return len; - if(msg.msg_controllen > 0 && msg.msg_control != NULL - && (cmsg = CMSG_FIRSTHDR(&msg)) != NULL) - { - rfds = ((unsigned char *)cmsg + cmsg->cmsg_len - CMSG_DATA(cmsg)) / sizeof(int); + if(msg.msg_controllen > 0 && msg.msg_control != NULL + && (cmsg = CMSG_FIRSTHDR(&msg)) != NULL) { + rfds = ((unsigned char *)cmsg + cmsg->cmsg_len - CMSG_DATA(cmsg)) / sizeof(int); - for(x = 0; x < nfds && x < rfds; x++) - { - fd = ((int *)CMSG_DATA(cmsg))[x]; - stype = RB_FD_UNKNOWN; - desc = "remote unknown"; - if(!fstat(fd, &st)) - { - if(S_ISSOCK(st.st_mode)) - { - stype = RB_FD_SOCKET; - desc = "remote socket"; - } - else if(S_ISFIFO(st.st_mode)) - { - stype = RB_FD_PIPE; - desc = "remote pipe"; - } - else if(S_ISREG(st.st_mode)) - { - stype = RB_FD_FILE; - desc = "remote file"; - } - } - xF[x] = rb_open(fd, stype, desc); - } - } - else - *xF = NULL; - return len; + for(x = 0; x < nfds && x < rfds; x++) { + fd = ((int *)CMSG_DATA(cmsg))[x]; + stype = RB_FD_UNKNOWN; + desc = "remote unknown"; + if(!fstat(fd, &st)) { + if(S_ISSOCK(st.st_mode)) { + stype = RB_FD_SOCKET; + desc = "remote socket"; + } else if(S_ISFIFO(st.st_mode)) { + stype = RB_FD_PIPE; + desc = "remote pipe"; + } else if(S_ISREG(st.st_mode)) { + stype = RB_FD_FILE; + desc = "remote file"; + } + } + xF[x] = rb_open(fd, stype, desc); + } + } else + *xF = NULL; + return len; } int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid) { - int n; - struct msghdr msg; - struct cmsghdr *cmsg; - struct iovec iov[1]; - char empty = '0'; - char *buf; + int n; + struct msghdr msg; + struct cmsghdr *cmsg; + struct iovec iov[1]; + char empty = '0'; + char *buf; - memset(&msg, 0, sizeof(&msg)); - if(datasize == 0) - { - iov[0].iov_base = ∅ - iov[0].iov_len = 1; - } - else - { - iov[0].iov_base = data; - iov[0].iov_len = datasize; - } - msg.msg_iov = iov; - msg.msg_iovlen = 1; - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_flags = 0; - msg.msg_control = NULL; - msg.msg_controllen = 0; + memset(&msg, 0, sizeof(&msg)); + if(datasize == 0) { + iov[0].iov_base = ∅ + iov[0].iov_len = 1; + } else { + iov[0].iov_base = data; + iov[0].iov_len = datasize; + } + msg.msg_iov = iov; + msg.msg_iovlen = 1; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_flags = 0; + msg.msg_control = NULL; + msg.msg_controllen = 0; - if(count > 0) - { - int i; - int len = CMSG_SPACE(sizeof(int) * count); - buf = alloca(len); + if(count > 0) { + int i; + int len = CMSG_SPACE(sizeof(int) * count); + buf = alloca(len); - msg.msg_control = buf; - msg.msg_controllen = len; - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(int) * count); + msg.msg_control = buf; + msg.msg_controllen = len; + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof(int) * count); - for(i = 0; i < count; i++) - { - ((int *)CMSG_DATA(cmsg))[i] = rb_get_fd(F[i]); - } - msg.msg_controllen = cmsg->cmsg_len; - } - n = sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL); - return n; + for(i = 0; i < count; i++) { + ((int *)CMSG_DATA(cmsg))[i] = rb_get_fd(F[i]); + } + msg.msg_controllen = cmsg->cmsg_len; + } + n = sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL); + return n; } #else #ifndef _WIN32 int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif #endif diff --git a/libratbox/src/crypt.c b/libratbox/src/crypt.c index 3741e0b..d9179d2 100644 --- a/libratbox/src/crypt.c +++ b/libratbox/src/crypt.c @@ -39,32 +39,29 @@ static char *rb_blowfish_crypt(const char *key, const char *salt); char * rb_crypt(const char *key, const char *salt) { - /* First, check if we are supposed to be using a replacement - * hash instead of DES... */ - if(salt[0] == '$' && (salt[2] == '$' || salt[3] == '$')) - { - switch(salt[1]) - { - case '1': - return rb_md5_crypt(key, salt); - break; - case '2': - /* Handles both 2 and 2a --Elizabeth */ - return rb_blowfish_crypt(key, salt); - break; - case '5': - return rb_sha256_crypt(key, salt); - break; - case '6': - return rb_sha512_crypt(key, salt); - break; - default: - return NULL; - break; - }; - } - else - return rb_des_crypt(key, salt); + /* First, check if we are supposed to be using a replacement + * hash instead of DES... */ + if(salt[0] == '$' && (salt[2] == '$' || salt[3] == '$')) { + switch(salt[1]) { + case '1': + return rb_md5_crypt(key, salt); + break; + case '2': + /* Handles both 2 and 2a --Elizabeth */ + return rb_blowfish_crypt(key, salt); + break; + case '5': + return rb_sha256_crypt(key, salt); + break; + case '6': + return rb_sha512_crypt(key, salt); + break; + default: + return NULL; + break; + }; + } else + return rb_des_crypt(key, salt); } #define b64_from_24bit(B2, B1, B0, N) \ @@ -148,7 +145,7 @@ rb_crypt(const char *key, const char *salt) */ -/* Re-entrantify me -- all this junk needs to be in +/* Re-entrantify me -- all this junk needs to be in * struct crypt_data to make this really reentrant... */ static uint8_t inv_key_perm[64]; static uint8_t inv_comp_perm[56]; @@ -165,8 +162,8 @@ static uint32_t old_salt; static uint32_t old_rawkey0, old_rawkey1; -/* Static stuff that stays resident and doesn't change after - * being initialized, and therefore doesn't need to be made +/* Static stuff that stays resident and doesn't change after + * being initialized, and therefore doesn't need to be made * reentrant. */ static uint8_t init_perm[64], final_perm[64]; static uint8_t m_sbox[4][4096]; @@ -176,28 +173,28 @@ static uint32_t psbox[4][256]; static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static const uint8_t IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 }; static const uint8_t key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; static const uint8_t key_shifts[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 + 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; static const uint8_t comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; /* @@ -205,62 +202,70 @@ static const uint8_t comp_perm[48] = { */ static const uint8_t sbox[8][64] = { - { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}, - { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}, - { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}, - { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}, - { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}, - { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}, - { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}, - { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11} + { + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 + }, + { + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 + }, + { + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 + }, + { + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 + }, + { + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 + }, + { + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 + }, + { + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 + }, + { + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 + } }; static const uint8_t pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; static const uint32_t bits32[32] = { - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 + 0x80000000, 0x40000000, 0x20000000, 0x10000000, + 0x08000000, 0x04000000, 0x02000000, 0x01000000, + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; static const uint8_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; @@ -271,457 +276,431 @@ static const uint32_t *bits28, *bits24; static int rb_ascii_to_bin(char ch) { - if(ch > 'z') - return (0); - if(ch >= 'a') - return (ch - 'a' + 38); - if(ch > 'Z') - return (0); - if(ch >= 'A') - return (ch - 'A' + 12); - if(ch > '9') - return (0); - if(ch >= '.') - return (ch - '.'); - return (0); + if(ch > 'z') + return (0); + if(ch >= 'a') + return (ch - 'a' + 38); + if(ch > 'Z') + return (0); + if(ch >= 'A') + return (ch - 'A' + 12); + if(ch > '9') + return (0); + if(ch >= '.') + return (ch - '.'); + return (0); } static void rb_des_init(void) { - int i, j, b, k, inbit, obit; - uint32_t *p, *il, *ir, *fl, *fr; - static int rb_des_initialised = 0; + int i, j, b, k, inbit, obit; + uint32_t *p, *il, *ir, *fl, *fr; + static int rb_des_initialised = 0; - if(rb_des_initialised == 1) - return; + if(rb_des_initialised == 1) + return; - old_rawkey0 = old_rawkey1 = 0L; - saltbits = 0L; - old_salt = 0L; - bits24 = (bits28 = bits32 + 4) + 4; + old_rawkey0 = old_rawkey1 = 0L; + saltbits = 0L; + old_salt = 0L; + bits24 = (bits28 = bits32 + 4) + 4; - /* - * Invert the S-boxes, reordering the input bits. - */ - for(i = 0; i < 8; i++) - for(j = 0; j < 64; j++) - { - b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); - u_sbox[i][j] = sbox[i][b]; - } + /* + * Invert the S-boxes, reordering the input bits. + */ + for(i = 0; i < 8; i++) + for(j = 0; j < 64; j++) { + b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); + u_sbox[i][j] = sbox[i][b]; + } - /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. - * Each will handle 12 bits of the S-box input. - */ - for(b = 0; b < 4; b++) - for(i = 0; i < 64; i++) - for(j = 0; j < 64; j++) - m_sbox[b][(i << 6) | j] = - (uint8_t)((u_sbox[(b << 1)][i] << 4) | - u_sbox[(b << 1) + 1][j]); + /* + * Convert the inverted S-boxes into 4 arrays of 8 bits. + * Each will handle 12 bits of the S-box input. + */ + for(b = 0; b < 4; b++) + for(i = 0; i < 64; i++) + for(j = 0; j < 64; j++) + m_sbox[b][(i << 6) | j] = + (uint8_t)((u_sbox[(b << 1)][i] << 4) | + u_sbox[(b << 1) + 1][j]); - /* - * Set up the initial & final permutations into a useful form, and - * initialise the inverted key permutation. - */ - for(i = 0; i < 64; i++) - { - init_perm[final_perm[i] = IP[i] - 1] = (uint8_t)i; - inv_key_perm[i] = 255; - } + /* + * Set up the initial & final permutations into a useful form, and + * initialise the inverted key permutation. + */ + for(i = 0; i < 64; i++) { + init_perm[final_perm[i] = IP[i] - 1] = (uint8_t)i; + inv_key_perm[i] = 255; + } - /* - * Invert the key permutation and initialise the inverted key - * compression permutation. - */ - for(i = 0; i < 56; i++) - { - inv_key_perm[key_perm[i] - 1] = (uint8_t)i; - inv_comp_perm[i] = 255; - } + /* + * Invert the key permutation and initialise the inverted key + * compression permutation. + */ + for(i = 0; i < 56; i++) { + inv_key_perm[key_perm[i] - 1] = (uint8_t)i; + inv_comp_perm[i] = 255; + } - /* - * Invert the key compression permutation. - */ - for(i = 0; i < 48; i++) - { - inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i; - } + /* + * Invert the key compression permutation. + */ + for(i = 0; i < 48; i++) { + inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i; + } - /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. - */ - for(k = 0; k < 8; k++) - { - for(i = 0; i < 256; i++) - { - *(il = &ip_maskl[k][i]) = 0L; - *(ir = &ip_maskr[k][i]) = 0L; - *(fl = &fp_maskl[k][i]) = 0L; - *(fr = &fp_maskr[k][i]) = 0L; - for(j = 0; j < 8; j++) - { - inbit = 8 * k + j; - if(i & bits8[j]) - { - if((obit = init_perm[inbit]) < 32) - *il |= bits32[obit]; - else - *ir |= bits32[obit - 32]; - if((obit = final_perm[inbit]) < 32) - *fl |= bits32[obit]; - else - *fr |= bits32[obit - 32]; - } - } - } - for(i = 0; i < 128; i++) - { - *(il = &key_perm_maskl[k][i]) = 0L; - *(ir = &key_perm_maskr[k][i]) = 0L; - for(j = 0; j < 7; j++) - { - inbit = 8 * k + j; - if(i & bits8[j + 1]) - { - if((obit = inv_key_perm[inbit]) == 255) - continue; - if(obit < 28) - *il |= bits28[obit]; - else - *ir |= bits28[obit - 28]; - } - } - *(il = &comp_maskl[k][i]) = 0L; - *(ir = &comp_maskr[k][i]) = 0L; - for(j = 0; j < 7; j++) - { - inbit = 7 * k + j; - if(i & bits8[j + 1]) - { - if((obit = inv_comp_perm[inbit]) == 255) - continue; - if(obit < 24) - *il |= bits24[obit]; - else - *ir |= bits24[obit - 24]; - } - } - } - } + /* + * Set up the OR-mask arrays for the initial and final permutations, + * and for the key initial and compression permutations. + */ + for(k = 0; k < 8; k++) { + for(i = 0; i < 256; i++) { + *(il = &ip_maskl[k][i]) = 0L; + *(ir = &ip_maskr[k][i]) = 0L; + *(fl = &fp_maskl[k][i]) = 0L; + *(fr = &fp_maskr[k][i]) = 0L; + for(j = 0; j < 8; j++) { + inbit = 8 * k + j; + if(i & bits8[j]) { + if((obit = init_perm[inbit]) < 32) + *il |= bits32[obit]; + else + *ir |= bits32[obit - 32]; + if((obit = final_perm[inbit]) < 32) + *fl |= bits32[obit]; + else + *fr |= bits32[obit - 32]; + } + } + } + for(i = 0; i < 128; i++) { + *(il = &key_perm_maskl[k][i]) = 0L; + *(ir = &key_perm_maskr[k][i]) = 0L; + for(j = 0; j < 7; j++) { + inbit = 8 * k + j; + if(i & bits8[j + 1]) { + if((obit = inv_key_perm[inbit]) == 255) + continue; + if(obit < 28) + *il |= bits28[obit]; + else + *ir |= bits28[obit - 28]; + } + } + *(il = &comp_maskl[k][i]) = 0L; + *(ir = &comp_maskr[k][i]) = 0L; + for(j = 0; j < 7; j++) { + inbit = 7 * k + j; + if(i & bits8[j + 1]) { + if((obit = inv_comp_perm[inbit]) == 255) + continue; + if(obit < 24) + *il |= bits24[obit]; + else + *ir |= bits24[obit - 24]; + } + } + } + } - /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. - */ - for(i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = (uint8_t)i; + /* + * Invert the P-box permutation, and convert into OR-masks for + * handling the output of the S-box arrays setup above. + */ + for(i = 0; i < 32; i++) + un_pbox[pbox[i] - 1] = (uint8_t)i; - for(b = 0; b < 4; b++) - for(i = 0; i < 256; i++) - { - *(p = &psbox[b][i]) = 0L; - for(j = 0; j < 8; j++) - { - if(i & bits8[j]) - *p |= bits32[un_pbox[8 * b + j]]; - } - } + for(b = 0; b < 4; b++) + for(i = 0; i < 256; i++) { + *(p = &psbox[b][i]) = 0L; + for(j = 0; j < 8; j++) { + if(i & bits8[j]) + *p |= bits32[un_pbox[8 * b + j]]; + } + } - rb_des_initialised = 1; + rb_des_initialised = 1; } static void rb_setup_salt(long salt) { - uint32_t obit, saltbit; - int i; + uint32_t obit, saltbit; + int i; - if(salt == (long)old_salt) - return; - old_salt = salt; + if(salt == (long)old_salt) + return; + old_salt = salt; - saltbits = 0L; - saltbit = 1; - obit = 0x800000; - for(i = 0; i < 24; i++) - { - if(salt & saltbit) - saltbits |= obit; - saltbit <<= 1; - obit >>= 1; - } + saltbits = 0L; + saltbit = 1; + obit = 0x800000; + for(i = 0; i < 24; i++) { + if(salt & saltbit) + saltbits |= obit; + saltbit <<= 1; + obit >>= 1; + } } static int rb_des_setkey(const char *key) { - uint32_t k0, k1, rawkey0, rawkey1; - int shifts, round; + uint32_t k0, k1, rawkey0, rawkey1; + int shifts, round; - rb_des_init(); + rb_des_init(); - rawkey0 = ntohl(*(const uint32_t *)key); - rawkey1 = ntohl(*(const uint32_t *)(key + 4)); + rawkey0 = ntohl(*(const uint32_t *)key); + rawkey1 = ntohl(*(const uint32_t *)(key + 4)); - if((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) - { - /* - * Already setup for this key. - * This optimisation fails on a zero key (which is weak and - * has bad parity anyway) in order to simplify the starting - * conditions. - */ - return (0); - } - old_rawkey0 = rawkey0; - old_rawkey1 = rawkey1; + if((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) { + /* + * Already setup for this key. + * This optimisation fails on a zero key (which is weak and + * has bad parity anyway) in order to simplify the starting + * conditions. + */ + return (0); + } + old_rawkey0 = rawkey0; + old_rawkey1 = rawkey1; - /* - * Do key permutation and split into two 28-bit subkeys. - */ - k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; - k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; - /* - * Rotate subkeys and do compression permutation. - */ - shifts = 0; - for(round = 0; round < 16; round++) - { - uint32_t t0, t1; + /* + * Do key permutation and split into two 28-bit subkeys. + */ + k0 = key_perm_maskl[0][rawkey0 >> 25] + | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskl[4][rawkey1 >> 25] + | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; + k1 = key_perm_maskr[0][rawkey0 >> 25] + | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskr[4][rawkey1 >> 25] + | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; + /* + * Rotate subkeys and do compression permutation. + */ + shifts = 0; + for(round = 0; round < 16; round++) { + uint32_t t0, t1; - shifts += key_shifts[round]; + shifts += key_shifts[round]; - t0 = (k0 << shifts) | (k0 >> (28 - shifts)); - t1 = (k1 << shifts) | (k1 >> (28 - shifts)); + t0 = (k0 << shifts) | (k0 >> (28 - shifts)); + t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - de_keysl[15 - round] = - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] | comp_maskl[7][t1 & 0x7f]; + de_keysl[15 - round] = + en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] + | comp_maskl[1][(t0 >> 14) & 0x7f] + | comp_maskl[2][(t0 >> 7) & 0x7f] + | comp_maskl[3][t0 & 0x7f] + | comp_maskl[4][(t1 >> 21) & 0x7f] + | comp_maskl[5][(t1 >> 14) & 0x7f] + | comp_maskl[6][(t1 >> 7) & 0x7f] | comp_maskl[7][t1 & 0x7f]; - de_keysr[15 - round] = - en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] | comp_maskr[7][t1 & 0x7f]; - } - return (0); + de_keysr[15 - round] = + en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] + | comp_maskr[1][(t0 >> 14) & 0x7f] + | comp_maskr[2][(t0 >> 7) & 0x7f] + | comp_maskr[3][t0 & 0x7f] + | comp_maskr[4][(t1 >> 21) & 0x7f] + | comp_maskr[5][(t1 >> 14) & 0x7f] + | comp_maskr[6][(t1 >> 7) & 0x7f] | comp_maskr[7][t1 & 0x7f]; + } + return (0); } static int rb_do_des(uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int count) { - /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ - uint32_t l, r, *kl, *kr, *kl1, *kr1; - uint32_t f, r48l, r48r; - int round; + /* + * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + */ + uint32_t l, r, *kl, *kr, *kl1, *kr1; + uint32_t f, r48l, r48r; + int round; - if(count == 0) - { - return (1); - } - else if(count > 0) - { - /* - * Encrypting - */ - kl1 = en_keysl; - kr1 = en_keysr; - } - else - { - /* - * Decrypting - */ - count = -count; - kl1 = de_keysl; - kr1 = de_keysr; - } + if(count == 0) { + return (1); + } else if(count > 0) { + /* + * Encrypting + */ + kl1 = en_keysl; + kr1 = en_keysr; + } else { + /* + * Decrypting + */ + count = -count; + kl1 = de_keysl; + kr1 = de_keysr; + } - /* - * Do initial permutation (IP). - */ - l = ip_maskl[0][l_in >> 24] - | ip_maskl[1][(l_in >> 16) & 0xff] - | ip_maskl[2][(l_in >> 8) & 0xff] - | ip_maskl[3][l_in & 0xff] - | ip_maskl[4][r_in >> 24] - | ip_maskl[5][(r_in >> 16) & 0xff] - | ip_maskl[6][(r_in >> 8) & 0xff] | ip_maskl[7][r_in & 0xff]; - r = ip_maskr[0][l_in >> 24] - | ip_maskr[1][(l_in >> 16) & 0xff] - | ip_maskr[2][(l_in >> 8) & 0xff] - | ip_maskr[3][l_in & 0xff] - | ip_maskr[4][r_in >> 24] - | ip_maskr[5][(r_in >> 16) & 0xff] - | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff]; + /* + * Do initial permutation (IP). + */ + l = ip_maskl[0][l_in >> 24] + | ip_maskl[1][(l_in >> 16) & 0xff] + | ip_maskl[2][(l_in >> 8) & 0xff] + | ip_maskl[3][l_in & 0xff] + | ip_maskl[4][r_in >> 24] + | ip_maskl[5][(r_in >> 16) & 0xff] + | ip_maskl[6][(r_in >> 8) & 0xff] | ip_maskl[7][r_in & 0xff]; + r = ip_maskr[0][l_in >> 24] + | ip_maskr[1][(l_in >> 16) & 0xff] + | ip_maskr[2][(l_in >> 8) & 0xff] + | ip_maskr[3][l_in & 0xff] + | ip_maskr[4][r_in >> 24] + | ip_maskr[5][(r_in >> 16) & 0xff] + | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff]; - while(count--) - { - /* - * Do each round. - */ - kl = kl1; - kr = kr1; - round = 16; - while(round--) - { - /* - * Expand R to 48 bits (simulate the E-box). - */ - r48l = ((r & 0x00000001) << 23) - | ((r & 0xf8000000) >> 9) - | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) | ((r & 0x001f8000) >> 15); + while(count--) { + /* + * Do each round. + */ + kl = kl1; + kr = kr1; + round = 16; + while(round--) { + /* + * Expand R to 48 bits (simulate the E-box). + */ + r48l = ((r & 0x00000001) << 23) + | ((r & 0xf8000000) >> 9) + | ((r & 0x1f800000) >> 11) + | ((r & 0x01f80000) >> 13) | ((r & 0x001f8000) >> 15); - r48r = ((r & 0x0001f800) << 7) - | ((r & 0x00001f80) << 5) - | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) | ((r & 0x80000000) >> 31); - /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. - */ - f = (r48l ^ r48r) & saltbits; - r48l ^= f ^ *kl++; - r48r ^= f ^ *kr++; - /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. - */ - f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; - /* - * Now that we've permuted things, complete f(). - */ - f ^= l; - l = r; - r = f; - } - r = l; - l = f; - } - /* - * Do final permutation (inverse of IP). - */ - *l_out = fp_maskl[0][l >> 24] - | fp_maskl[1][(l >> 16) & 0xff] - | fp_maskl[2][(l >> 8) & 0xff] - | fp_maskl[3][l & 0xff] - | fp_maskl[4][r >> 24] - | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] - | fp_maskr[1][(l >> 16) & 0xff] - | fp_maskr[2][(l >> 8) & 0xff] - | fp_maskr[3][l & 0xff] - | fp_maskr[4][r >> 24] - | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] | fp_maskr[7][r & 0xff]; - return (0); + r48r = ((r & 0x0001f800) << 7) + | ((r & 0x00001f80) << 5) + | ((r & 0x000001f8) << 3) + | ((r & 0x0000001f) << 1) | ((r & 0x80000000) >> 31); + /* + * Do salting for crypt() and friends, and + * XOR with the permuted key. + */ + f = (r48l ^ r48r) & saltbits; + r48l ^= f ^ *kl++; + r48r ^= f ^ *kr++; + /* + * Do sbox lookups (which shrink it back to 32 bits) + * and do the pbox permutation at the same time. + */ + f = psbox[0][m_sbox[0][r48l >> 12]] + | psbox[1][m_sbox[1][r48l & 0xfff]] + | psbox[2][m_sbox[2][r48r >> 12]] + | psbox[3][m_sbox[3][r48r & 0xfff]]; + /* + * Now that we've permuted things, complete f(). + */ + f ^= l; + l = r; + r = f; + } + r = l; + l = f; + } + /* + * Do final permutation (inverse of IP). + */ + *l_out = fp_maskl[0][l >> 24] + | fp_maskl[1][(l >> 16) & 0xff] + | fp_maskl[2][(l >> 8) & 0xff] + | fp_maskl[3][l & 0xff] + | fp_maskl[4][r >> 24] + | fp_maskl[5][(r >> 16) & 0xff] + | fp_maskl[6][(r >> 8) & 0xff] | fp_maskl[7][r & 0xff]; + *r_out = fp_maskr[0][l >> 24] + | fp_maskr[1][(l >> 16) & 0xff] + | fp_maskr[2][(l >> 8) & 0xff] + | fp_maskr[3][l & 0xff] + | fp_maskr[4][r >> 24] + | fp_maskr[5][(r >> 16) & 0xff] + | fp_maskr[6][(r >> 8) & 0xff] | fp_maskr[7][r & 0xff]; + return (0); } static char * rb_des_crypt(const char *key, const char *setting) { - uint32_t count, salt, l, r0, r1, keybuf[2]; - uint8_t *p, *q; - static char output[21]; + uint32_t count, salt, l, r0, r1, keybuf[2]; + uint8_t *p, *q; + static char output[21]; - rb_des_init(); + rb_des_init(); - /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. - */ - q = (uint8_t *)keybuf; - while(q - (uint8_t *)keybuf - 8) - { - *q++ = *key << 1; - if(*(q - 1)) - key++; - } - if(rb_des_setkey((char *)keybuf)) - return (NULL); - { - /* - * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters - */ - count = 25; + /* + * Copy the key, shifting each character up by one bit + * and padding with zeros. + */ + q = (uint8_t *)keybuf; + while(q - (uint8_t *)keybuf - 8) { + *q++ = *key << 1; + if(*(q - 1)) + key++; + } + if(rb_des_setkey((char *)keybuf)) + return (NULL); + { + /* + * "old"-style: + * setting - 2 bytes of salt + * key - up to 8 characters + */ + count = 25; - salt = (rb_ascii_to_bin(setting[1]) << 6) | rb_ascii_to_bin(setting[0]); + salt = (rb_ascii_to_bin(setting[1]) << 6) | rb_ascii_to_bin(setting[0]); - output[0] = setting[0]; - /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! - */ - output[1] = setting[1] ? setting[1] : output[0]; + output[0] = setting[0]; + /* + * If the encrypted password that the salt was extracted from + * is only 1 character long, the salt will be corrupted. We + * need to ensure that the output string doesn't have an extra + * NUL in it! + */ + output[1] = setting[1] ? setting[1] : output[0]; - p = (uint8_t *)output + 2; - } - rb_setup_salt(salt); - /* - * Do it. - */ - if(rb_do_des(0L, 0L, &r0, &r1, (int)count)) - return (NULL); - /* - * Now encode the result... - */ - l = (r0 >> 8); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; + p = (uint8_t *)output + 2; + } + rb_setup_salt(salt); + /* + * Do it. + */ + if(rb_do_des(0L, 0L, &r0, &r1, (int)count)) + return (NULL); + /* + * Now encode the result... + */ + l = (r0 >> 8); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; - l = (r0 << 16) | ((r1 >> 16) & 0xffff); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; + l = (r0 << 16) | ((r1 >> 16) & 0xffff); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; - l = r1 << 2; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - *p = 0; + l = r1 << 2; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + *p = 0; - return (output); + return (output); } /* Now md5 crypt */ @@ -761,17 +740,17 @@ rb_des_crypt(const char *key, const char *setting) static void _crypt_to64(char *s, u_long v, int n) { - while (--n >= 0) { - *s++ = ascii64[v&0x3f]; - v >>= 6; - } + while (--n >= 0) { + *s++ = ascii64[v&0x3f]; + v >>= 6; + } } /* MD5 context. */ typedef struct MD5Context { - uint32_t state[4]; /* state (ABCD) */ - uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ + uint32_t state[4]; /* state (ABCD) */ + uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ } MD5_CTX; static void MD5Transform(uint32_t [4], const unsigned char [64]); @@ -782,7 +761,7 @@ static void MD5Final (unsigned char [16], MD5_CTX *); #ifndef WORDS_BIGENDIAN #define Encode memcpy #define Decode memcpy -#else +#else /* * Encodes input (uint32_t) into output (unsigned char). Assumes len is @@ -792,11 +771,11 @@ static void MD5Final (unsigned char [16], MD5_CTX *); static void Encode (unsigned char *output, uint32_t *input, unsigned int len) { - unsigned int i; - uint32_t *op = (uint32_t *)output; + unsigned int i; + uint32_t *op = (uint32_t *)output; - for (i = 0; i < len / 4; i++) - op[i] = htole32(input[i]); + for (i = 0; i < len / 4; i++) + op[i] = htole32(input[i]); } /* @@ -807,18 +786,18 @@ Encode (unsigned char *output, uint32_t *input, unsigned int len) static void Decode (uint32_t *output, const unsigned char *input, unsigned int len) { - unsigned int i; - const uint32_t *ip = (const uint32_t *)input; + unsigned int i; + const uint32_t *ip = (const uint32_t *)input; - for (i = 0; i < len / 4; i++) - output[i] = le32toh(ip[i]); + for (i = 0; i < len / 4; i++) + output[i] = le32toh(ip[i]); } #endif static unsigned char PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* F, G, H and I are basic MD5 functions. */ @@ -859,19 +838,19 @@ static unsigned char PADDING[64] = { static void MD5Init (context) - MD5_CTX *context; +MD5_CTX *context; { - context->count[0] = context->count[1] = 0; + context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; + /* Load magic initialization constants. */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; } -/* +/* * MD5 block update operation. Continues an MD5 message-digest * operation, processing another message block, and updating the * context. @@ -879,41 +858,40 @@ MD5Init (context) static void MD5Update (context, in, inputLen) - MD5_CTX *context; - const void *in; - unsigned int inputLen; +MD5_CTX *context; +const void *in; +unsigned int inputLen; { - unsigned int i, idx, partLen; - const unsigned char *input = in; + unsigned int i, idx, partLen; + const unsigned char *input = in; - /* Compute number of bytes mod 64 */ - idx = (unsigned int)((context->count[0] >> 3) & 0x3F); + /* Compute number of bytes mod 64 */ + idx = (unsigned int)((context->count[0] >> 3) & 0x3F); - /* Update number of bits */ - if ((context->count[0] += ((uint32_t)inputLen << 3)) - < ((uint32_t)inputLen << 3)) - context->count[1]++; - context->count[1] += ((uint32_t)inputLen >> 29); + /* Update number of bits */ + if ((context->count[0] += ((uint32_t)inputLen << 3)) + < ((uint32_t)inputLen << 3)) + context->count[1]++; + context->count[1] += ((uint32_t)inputLen >> 29); - partLen = 64 - idx; + partLen = 64 - idx; - /* Transform as many times as possible. */ - if (inputLen >= partLen) { - memcpy((void *)&context->buffer[idx], (const void *)input, - partLen); - MD5Transform (context->state, context->buffer); + /* Transform as many times as possible. */ + if (inputLen >= partLen) { + memcpy((void *)&context->buffer[idx], (const void *)input, + partLen); + MD5Transform (context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform (context->state, &input[i]); + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); - idx = 0; - } - else - i = 0; + idx = 0; + } else + i = 0; - /* Buffer remaining input */ - memcpy ((void *)&context->buffer[idx], (const void *)&input[i], - inputLen-i); + /* Buffer remaining input */ + memcpy ((void *)&context->buffer[idx], (const void *)&input[i], + inputLen-i); } /* @@ -922,21 +900,21 @@ MD5Update (context, in, inputLen) static void MD5Pad (context) - MD5_CTX *context; +MD5_CTX *context; { - unsigned char bits[8]; - unsigned int idx, padLen; + unsigned char bits[8]; + unsigned int idx, padLen; - /* Save number of bits */ - Encode (bits, context->count, 8); + /* Save number of bits */ + Encode (bits, context->count, 8); - /* Pad out to 56 mod 64. */ - idx = (unsigned int)((context->count[0] >> 3) & 0x3f); - padLen = (idx < 56) ? (56 - idx) : (120 - idx); - MD5Update (context, PADDING, padLen); + /* Pad out to 56 mod 64. */ + idx = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (idx < 56) ? (56 - idx) : (120 - idx); + MD5Update (context, PADDING, padLen); - /* Append length (before padding) */ - MD5Update (context, bits, 8); + /* Append length (before padding) */ + MD5Update (context, bits, 8); } /* @@ -946,125 +924,125 @@ MD5Pad (context) static void MD5Final (digest, context) - unsigned char digest[16]; - MD5_CTX *context; +unsigned char digest[16]; +MD5_CTX *context; { - /* Do padding. */ - MD5Pad (context); + /* Do padding. */ + MD5Pad (context); - /* Store state in digest */ - Encode (digest, context->state, 16); + /* Store state in digest */ + Encode (digest, context->state, 16); - /* Zeroize sensitive information. */ - memset ((void *)context, 0, sizeof (*context)); + /* Zeroize sensitive information. */ + memset ((void *)context, 0, sizeof (*context)); } /* MD5 basic transformation. Transforms state based on block. */ static void MD5Transform (state, block) - uint32_t state[4]; - const unsigned char block[64]; +uint32_t state[4]; +const unsigned char block[64]; { - uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - Decode (x, block, 64); + Decode (x, block, 64); - /* Round 1 */ + /* Round 1 */ #define S11 7 #define S12 12 #define S13 17 #define S14 22 - FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ - FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ - FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ - FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ - FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ - FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ - FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ - FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ - FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ - FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ - FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ - /* Round 2 */ + /* Round 2 */ #define S21 5 #define S22 9 #define S23 14 #define S24 20 - GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ - GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ - GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ - GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ - GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ - GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ - GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ - GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ - GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ - GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ - GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ - /* Round 3 */ + /* Round 3 */ #define S31 4 #define S32 11 #define S33 16 #define S34 23 - HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ - HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ - HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ - HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ - HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ - HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ - HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ - HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ - HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ - HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ - /* Round 4 */ + /* Round 4 */ #define S41 6 #define S42 10 #define S43 15 #define S44 21 - II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ - II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ - II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ - II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ - II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ - II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ - II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ - II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ - II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ - II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; - /* Zeroize sensitive information. */ - memset ((void *)x, 0, sizeof (x)); + /* Zeroize sensitive information. */ + memset ((void *)x, 0, sizeof (x)); } /* @@ -1074,112 +1052,118 @@ MD5Transform (state, block) static char * rb_md5_crypt(const char *pw, const char *salt) { - MD5_CTX ctx,ctx1; - unsigned long l; - int sl, pl; - u_int i; - u_char final[MD5_SIZE]; - static const char *sp, *ep; - static char passwd[120], *p; - static const char *magic = "$1$"; + MD5_CTX ctx,ctx1; + unsigned long l; + int sl, pl; + u_int i; + u_char final[MD5_SIZE]; + static const char *sp, *ep; + static char passwd[120], *p; + static const char *magic = "$1$"; - /* Refine the Salt first */ - sp = salt; + /* Refine the Salt first */ + sp = salt; - /* If it starts with the magic string, then skip that */ - if(!strncmp(sp, magic, strlen(magic))) - sp += strlen(magic); + /* If it starts with the magic string, then skip that */ + if(!strncmp(sp, magic, strlen(magic))) + sp += strlen(magic); - /* It stops at the first '$', max 8 chars */ - for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++) - continue; + /* It stops at the first '$', max 8 chars */ + for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++) + continue; - /* get the length of the true salt */ - sl = ep - sp; + /* get the length of the true salt */ + sl = ep - sp; - MD5Init(&ctx); + MD5Init(&ctx); - /* The password first, since that is what is most unknown */ - MD5Update(&ctx, (const u_char *)pw, strlen(pw)); + /* The password first, since that is what is most unknown */ + MD5Update(&ctx, (const u_char *)pw, strlen(pw)); - /* Then our magic string */ - MD5Update(&ctx, (const u_char *)magic, strlen(magic)); + /* Then our magic string */ + MD5Update(&ctx, (const u_char *)magic, strlen(magic)); - /* Then the raw salt */ - MD5Update(&ctx, (const u_char *)sp, (u_int)sl); + /* Then the raw salt */ + MD5Update(&ctx, (const u_char *)sp, (u_int)sl); - /* Then just as many characters of the MD5(pw,salt,pw) */ - MD5Init(&ctx1); - MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); - MD5Update(&ctx1, (const u_char *)sp, (u_int)sl); - MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); - MD5Final(final, &ctx1); - for(pl = (int)strlen(pw); pl > 0; pl -= MD5_SIZE) - MD5Update(&ctx, (const u_char *)final, - (u_int)(pl > MD5_SIZE ? MD5_SIZE : pl)); + /* Then just as many characters of the MD5(pw,salt,pw) */ + MD5Init(&ctx1); + MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); + MD5Update(&ctx1, (const u_char *)sp, (u_int)sl); + MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); + MD5Final(final, &ctx1); + for(pl = (int)strlen(pw); pl > 0; pl -= MD5_SIZE) + MD5Update(&ctx, (const u_char *)final, + (u_int)(pl > MD5_SIZE ? MD5_SIZE : pl)); - /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof(final)); + /* Don't leave anything around in vm they could use. */ + memset(final, 0, sizeof(final)); - /* Then something really weird... */ - for (i = strlen(pw); i; i >>= 1) - if(i & 1) - MD5Update(&ctx, (const u_char *)final, 1); - else - MD5Update(&ctx, (const u_char *)pw, 1); + /* Then something really weird... */ + for (i = strlen(pw); i; i >>= 1) + if(i & 1) + MD5Update(&ctx, (const u_char *)final, 1); + else + MD5Update(&ctx, (const u_char *)pw, 1); - /* Now make the output string */ - rb_strlcpy(passwd, magic, sizeof(passwd)); - strncat(passwd, sp, (u_int)sl); - rb_strlcat(passwd, "$", sizeof(passwd)); + /* Now make the output string */ + rb_strlcpy(passwd, magic, sizeof(passwd)); + strncat(passwd, sp, (u_int)sl); + rb_strlcat(passwd, "$", sizeof(passwd)); - MD5Final(final, &ctx); + MD5Final(final, &ctx); - /* - * and now, just to make sure things don't run too fast - * On a 60 Mhz Pentium this takes 34 msec, so you would - * need 30 seconds to build a 1000 entry dictionary... - */ - for(i = 0; i < 1000; i++) { - MD5Init(&ctx1); - if(i & 1) - MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); - else - MD5Update(&ctx1, (const u_char *)final, MD5_SIZE); + /* + * and now, just to make sure things don't run too fast + * On a 60 Mhz Pentium this takes 34 msec, so you would + * need 30 seconds to build a 1000 entry dictionary... + */ + for(i = 0; i < 1000; i++) { + MD5Init(&ctx1); + if(i & 1) + MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); + else + MD5Update(&ctx1, (const u_char *)final, MD5_SIZE); - if(i % 3) - MD5Update(&ctx1, (const u_char *)sp, (u_int)sl); + if(i % 3) + MD5Update(&ctx1, (const u_char *)sp, (u_int)sl); - if(i % 7) - MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); + if(i % 7) + MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); - if(i & 1) - MD5Update(&ctx1, (const u_char *)final, MD5_SIZE); - else - MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); - MD5Final(final, &ctx1); - } + if(i & 1) + MD5Update(&ctx1, (const u_char *)final, MD5_SIZE); + else + MD5Update(&ctx1, (const u_char *)pw, strlen(pw)); + MD5Final(final, &ctx1); + } - p = passwd + strlen(passwd); + p = passwd + strlen(passwd); - l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; - _crypt_to64(p, l, 4); p += 4; - l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; - _crypt_to64(p, l, 4); p += 4; - l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; - _crypt_to64(p, l, 4); p += 4; - l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; - _crypt_to64(p, l, 4); p += 4; - l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; - _crypt_to64(p, l, 4); p += 4; - l = final[11]; - _crypt_to64(p, l, 2); p += 2; - *p = '\0'; + l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; + _crypt_to64(p, l, 4); + p += 4; + l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; + _crypt_to64(p, l, 4); + p += 4; + l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; + _crypt_to64(p, l, 4); + p += 4; + l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; + _crypt_to64(p, l, 4); + p += 4; + l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; + _crypt_to64(p, l, 4); + p += 4; + l = final[11]; + _crypt_to64(p, l, 2); + p += 2; + *p = '\0'; - /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof(final)); + /* Don't leave anything around in vm they could use. */ + memset(final, 0, sizeof(final)); - return (passwd); + return (passwd); } @@ -1187,13 +1171,12 @@ rb_md5_crypt(const char *pw, const char *salt) Released into the Public Domain by Ulrich Drepper . */ /* Structure to save state of computation between the single steps. */ -struct sha256_ctx -{ - uint32_t H[8]; +struct sha256_ctx { + uint32_t H[8]; - uint32_t total[2]; - uint32_t buflen; - char buffer[128]; /* NB: always correctly aligned for uint32_t. */ + uint32_t total[2]; + uint32_t buflen; + char buffer[128]; /* NB: always correctly aligned for uint32_t. */ }; #ifndef WORDS_BIGENDIAN @@ -1210,22 +1193,22 @@ static const unsigned char SHA256_fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; /* Constants for SHA256 from FIPS 180-2:4.2.2. */ static const uint32_t SHA256_K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; @@ -1233,99 +1216,96 @@ static const uint32_t SHA256_K[64] = { It is assumed that LEN % 64 == 0. */ static void rb_sha256_process_block(const void *buffer, size_t len, struct sha256_ctx *ctx) { - const uint32_t *words = buffer; - size_t nwords = len / sizeof(uint32_t); - uint32_t a = ctx->H[0]; - uint32_t b = ctx->H[1]; - uint32_t c = ctx->H[2]; - uint32_t d = ctx->H[3]; - uint32_t e = ctx->H[4]; - uint32_t f = ctx->H[5]; - uint32_t g = ctx->H[6]; - uint32_t h = ctx->H[7]; + const uint32_t *words = buffer; + size_t nwords = len / sizeof(uint32_t); + uint32_t a = ctx->H[0]; + uint32_t b = ctx->H[1]; + uint32_t c = ctx->H[2]; + uint32_t d = ctx->H[3]; + uint32_t e = ctx->H[4]; + uint32_t f = ctx->H[5]; + uint32_t g = ctx->H[6]; + uint32_t h = ctx->H[7]; - /* First increment the byte count. FIPS 180-2 specifies the possible - length of the file up to 2^64 bits. Here we only compute the - number of bytes. Do a double word increment. */ - ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; + /* First increment the byte count. FIPS 180-2 specifies the possible + length of the file up to 2^64 bits. Here we only compute the + number of bytes. Do a double word increment. */ + ctx->total[0] += len; + if (ctx->total[0] < len) + ++ctx->total[1]; - /* Process all bytes in the buffer with 64 bytes in each round of - the loop. */ - while (nwords > 0) - { - uint32_t W[64]; - uint32_t a_save = a; - uint32_t b_save = b; - uint32_t c_save = c; - uint32_t d_save = d; - uint32_t e_save = e; - uint32_t f_save = f; - uint32_t g_save = g; - uint32_t h_save = h; - unsigned int t; + /* Process all bytes in the buffer with 64 bytes in each round of + the loop. */ + while (nwords > 0) { + uint32_t W[64]; + uint32_t a_save = a; + uint32_t b_save = b; + uint32_t c_save = c; + uint32_t d_save = d; + uint32_t e_save = e; + uint32_t f_save = f; + uint32_t g_save = g; + uint32_t h_save = h; + unsigned int t; - /* Operators defined in FIPS 180-2:4.1.2. */ - #define SHA256_Ch(x, y, z) ((x & y) ^ (~x & z)) - #define SHA256_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) - #define SHA256_S0(x) (SHA256_CYCLIC (x, 2) ^ SHA256_CYCLIC (x, 13) ^ SHA256_CYCLIC (x, 22)) - #define SHA256_S1(x) (SHA256_CYCLIC (x, 6) ^ SHA256_CYCLIC (x, 11) ^ SHA256_CYCLIC (x, 25)) - #define SHA256_R0(x) (SHA256_CYCLIC (x, 7) ^ SHA256_CYCLIC (x, 18) ^ (x >> 3)) - #define SHA256_R1(x) (SHA256_CYCLIC (x, 17) ^ SHA256_CYCLIC (x, 19) ^ (x >> 10)) + /* Operators defined in FIPS 180-2:4.1.2. */ +#define SHA256_Ch(x, y, z) ((x & y) ^ (~x & z)) +#define SHA256_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define SHA256_S0(x) (SHA256_CYCLIC (x, 2) ^ SHA256_CYCLIC (x, 13) ^ SHA256_CYCLIC (x, 22)) +#define SHA256_S1(x) (SHA256_CYCLIC (x, 6) ^ SHA256_CYCLIC (x, 11) ^ SHA256_CYCLIC (x, 25)) +#define SHA256_R0(x) (SHA256_CYCLIC (x, 7) ^ SHA256_CYCLIC (x, 18) ^ (x >> 3)) +#define SHA256_R1(x) (SHA256_CYCLIC (x, 17) ^ SHA256_CYCLIC (x, 19) ^ (x >> 10)) - /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ - #define SHA256_CYCLIC(w, s) ((w >> s) | (w << (32 - s))) + /* It is unfortunate that C does not provide an operator for + cyclic rotation. Hope the C compiler is smart enough. */ +#define SHA256_CYCLIC(w, s) ((w >> s) | (w << (32 - s))) - /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ - for (t = 0; t < 16; ++t) - { - W[t] = SHA256_SWAP(*words); - ++words; - } - for (t = 16; t < 64; ++t) - W[t] = SHA256_R1(W[t - 2]) + W[t - 7] + SHA256_R0(W[t - 15]) + W[t - 16]; + /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ + for (t = 0; t < 16; ++t) { + W[t] = SHA256_SWAP(*words); + ++words; + } + for (t = 16; t < 64; ++t) + W[t] = SHA256_R1(W[t - 2]) + W[t - 7] + SHA256_R0(W[t - 15]) + W[t - 16]; - /* The actual computation according to FIPS 180-2:6.2.2 step 3. */ - for (t = 0; t < 64; ++t) - { - uint32_t T1 = h + SHA256_S1(e) + SHA256_Ch(e, f, g) + SHA256_K[t] + W[t]; - uint32_t T2 = SHA256_S0(a) + SHA256_Maj(a, b, c); - h = g; - g = f; - f = e; - e = d + T1; - d = c; - c = b; - b = a; - a = T1 + T2; - } + /* The actual computation according to FIPS 180-2:6.2.2 step 3. */ + for (t = 0; t < 64; ++t) { + uint32_t T1 = h + SHA256_S1(e) + SHA256_Ch(e, f, g) + SHA256_K[t] + W[t]; + uint32_t T2 = SHA256_S0(a) + SHA256_Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + T1; + d = c; + c = b; + b = a; + a = T1 + T2; + } - /* Add the starting values of the context according to FIPS 180-2:6.2.2 - step 4. */ - a += a_save; - b += b_save; - c += c_save; - d += d_save; - e += e_save; - f += f_save; - g += g_save; - h += h_save; + /* Add the starting values of the context according to FIPS 180-2:6.2.2 + step 4. */ + a += a_save; + b += b_save; + c += c_save; + d += d_save; + e += e_save; + f += f_save; + g += g_save; + h += h_save; - /* Prepare for the next round. */ - nwords -= 16; - } + /* Prepare for the next round. */ + nwords -= 16; + } - /* Put checksum in context given as argument. */ - ctx->H[0] = a; - ctx->H[1] = b; - ctx->H[2] = c; - ctx->H[3] = d; - ctx->H[4] = e; - ctx->H[5] = f; - ctx->H[6] = g; - ctx->H[7] = h; + /* Put checksum in context given as argument. */ + ctx->H[0] = a; + ctx->H[1] = b; + ctx->H[2] = c; + ctx->H[3] = d; + ctx->H[4] = e; + ctx->H[5] = f; + ctx->H[6] = g; + ctx->H[7] = h; } @@ -1333,17 +1313,17 @@ static void rb_sha256_process_block(const void *buffer, size_t len, struct sha25 (FIPS 180-2:5.3.2) */ static void rb_sha256_init_ctx(struct sha256_ctx *ctx) { - ctx->H[0] = 0x6a09e667; - ctx->H[1] = 0xbb67ae85; - ctx->H[2] = 0x3c6ef372; - ctx->H[3] = 0xa54ff53a; - ctx->H[4] = 0x510e527f; - ctx->H[5] = 0x9b05688c; - ctx->H[6] = 0x1f83d9ab; - ctx->H[7] = 0x5be0cd19; + ctx->H[0] = 0x6a09e667; + ctx->H[1] = 0xbb67ae85; + ctx->H[2] = 0x3c6ef372; + ctx->H[3] = 0xa54ff53a; + ctx->H[4] = 0x510e527f; + ctx->H[5] = 0x9b05688c; + ctx->H[6] = 0x1f83d9ab; + ctx->H[7] = 0x5be0cd19; - ctx->total[0] = ctx->total[1] = 0; - ctx->buflen = 0; + ctx->total[0] = ctx->total[1] = 0; + ctx->buflen = 0; } @@ -1354,100 +1334,93 @@ static void rb_sha256_init_ctx(struct sha256_ctx *ctx) aligned for a 32 bits value. */ static void *rb_sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) { - /* Take yet unprocessed bytes into account. */ - uint32_t bytes = ctx->buflen; - size_t pad; - unsigned int i; + /* Take yet unprocessed bytes into account. */ + uint32_t bytes = ctx->buflen; + size_t pad; + unsigned int i; - /* Now count remaining bytes. */ - ctx->total[0] += bytes; - if (ctx->total[0] < bytes) - ++ctx->total[1]; + /* Now count remaining bytes. */ + ctx->total[0] += bytes; + if (ctx->total[0] < bytes) + ++ctx->total[1]; - pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; - memcpy(&ctx->buffer[bytes], SHA256_fillbuf, pad); + pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; + memcpy(&ctx->buffer[bytes], SHA256_fillbuf, pad); - /* Put the 64-bit file length in *bits* at the end of the buffer. */ - *(uint32_t *) & ctx->buffer[bytes + pad + 4] = SHA256_SWAP(ctx->total[0] << 3); - *(uint32_t *) & ctx->buffer[bytes + pad] = SHA256_SWAP((ctx->total[1] << 3) | - (ctx->total[0] >> 29)); + /* Put the 64-bit file length in *bits* at the end of the buffer. */ + *(uint32_t *) & ctx->buffer[bytes + pad + 4] = SHA256_SWAP(ctx->total[0] << 3); + *(uint32_t *) & ctx->buffer[bytes + pad] = SHA256_SWAP((ctx->total[1] << 3) | + (ctx->total[0] >> 29)); - /* Process last bytes. */ - rb_sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); + /* Process last bytes. */ + rb_sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); - /* Put result from CTX in first 32 bytes following RESBUF. */ - for (i = 0; i < 8; ++i) - ((uint32_t *) resbuf)[i] = SHA256_SWAP(ctx->H[i]); + /* Put result from CTX in first 32 bytes following RESBUF. */ + for (i = 0; i < 8; ++i) + ((uint32_t *) resbuf)[i] = SHA256_SWAP(ctx->H[i]); - return resbuf; + return resbuf; } static void rb_sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) { - /* When we already have some bits in our internal buffer concatenate - both inputs first. */ - if (ctx->buflen != 0) - { - size_t left_over = ctx->buflen; - size_t add = 128 - left_over > len ? len : 128 - left_over; + /* When we already have some bits in our internal buffer concatenate + both inputs first. */ + if (ctx->buflen != 0) { + size_t left_over = ctx->buflen; + size_t add = 128 - left_over > len ? len : 128 - left_over; - memcpy(&ctx->buffer[left_over], buffer, add); - ctx->buflen += add; + memcpy(&ctx->buffer[left_over], buffer, add); + ctx->buflen += add; - if (ctx->buflen > 64) - { - rb_sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); + if (ctx->buflen > 64) { + rb_sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); - ctx->buflen &= 63; - /* The regions in the following copy operation cannot overlap. */ - memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen); - } + ctx->buflen &= 63; + /* The regions in the following copy operation cannot overlap. */ + memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen); + } - buffer = (const char *)buffer + add; - len -= add; - } + buffer = (const char *)buffer + add; + len -= add; + } - /* Process available complete blocks. */ - if (len >= 64) - { - /* To check alignment gcc has an appropriate operator. Other - compilers don't. */ - #if __GNUC__ >= 2 - # define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) - #else - # define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0) - #endif - if (SHA256_UNALIGNED_P(buffer)) - while (len > 64) - { - rb_sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *)buffer + 64; - len -= 64; - } - else - { - rb_sha256_process_block(buffer, len & ~63, ctx); - buffer = (const char *)buffer + (len & ~63); - len &= 63; - } - } + /* Process available complete blocks. */ + if (len >= 64) { + /* To check alignment gcc has an appropriate operator. Other + compilers don't. */ +#if __GNUC__ >= 2 +# define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) +#else +# define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0) +#endif + if (SHA256_UNALIGNED_P(buffer)) + while (len > 64) { + rb_sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *)buffer + 64; + len -= 64; + } + else { + rb_sha256_process_block(buffer, len & ~63, ctx); + buffer = (const char *)buffer + (len & ~63); + len &= 63; + } + } - /* Move remaining bytes into internal buffer. */ - if (len > 0) - { - size_t left_over = ctx->buflen; + /* Move remaining bytes into internal buffer. */ + if (len > 0) { + size_t left_over = ctx->buflen; - memcpy(&ctx->buffer[left_over], buffer, len); - left_over += len; - if (left_over >= 64) - { - rb_sha256_process_block(ctx->buffer, 64, ctx); - left_over -= 64; - memcpy(ctx->buffer, &ctx->buffer[64], left_over); - } - ctx->buflen = left_over; - } + memcpy(&ctx->buffer[left_over], buffer, len); + left_over += len; + if (left_over >= 64) { + rb_sha256_process_block(ctx->buffer, 64, ctx); + left_over -= 64; + memcpy(ctx->buffer, &ctx->buffer[64], left_over); + } + ctx->buflen = left_over; + } } @@ -1469,238 +1442,227 @@ static const char sha256_rounds_prefix[] = "rounds="; static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer, int buflen) { - unsigned char alt_result[32] __attribute__ ((__aligned__(__alignof__(uint32_t)))); - unsigned char temp_result[32] __attribute__ ((__aligned__(__alignof__(uint32_t)))); - struct sha256_ctx ctx; - struct sha256_ctx alt_ctx; - size_t salt_len; - size_t key_len; - size_t cnt; - char *cp; - char *copied_key = NULL; - char *copied_salt = NULL; - char *p_bytes; - char *s_bytes; - /* Default number of rounds. */ - size_t rounds = SHA256_ROUNDS_DEFAULT; - int rounds_custom = 0; + unsigned char alt_result[32] __attribute__ ((__aligned__(__alignof__(uint32_t)))); + unsigned char temp_result[32] __attribute__ ((__aligned__(__alignof__(uint32_t)))); + struct sha256_ctx ctx; + struct sha256_ctx alt_ctx; + size_t salt_len; + size_t key_len; + size_t cnt; + char *cp; + char *copied_key = NULL; + char *copied_salt = NULL; + char *p_bytes; + char *s_bytes; + /* Default number of rounds. */ + size_t rounds = SHA256_ROUNDS_DEFAULT; + int rounds_custom = 0; - /* Find beginning of salt string. The prefix should normally always - be present. Just in case it is not. */ - if (strncmp(sha256_salt_prefix, salt, sizeof(sha256_salt_prefix) - 1) == 0) - /* Skip salt prefix. */ - salt += sizeof(sha256_salt_prefix) - 1; + /* Find beginning of salt string. The prefix should normally always + be present. Just in case it is not. */ + if (strncmp(sha256_salt_prefix, salt, sizeof(sha256_salt_prefix) - 1) == 0) + /* Skip salt prefix. */ + salt += sizeof(sha256_salt_prefix) - 1; - if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) - { - const char *num = salt + sizeof(sha256_rounds_prefix) - 1; - char *endp; - unsigned long int srounds = strtoul(num, &endp, 10); - if (*endp == '$') - { - salt = endp + 1; - rounds = MAX(SHA256_ROUNDS_MIN, MIN(srounds, SHA256_ROUNDS_MAX)); - rounds_custom = 1; - } - } + if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) { + const char *num = salt + sizeof(sha256_rounds_prefix) - 1; + char *endp; + unsigned long int srounds = strtoul(num, &endp, 10); + if (*endp == '$') { + salt = endp + 1; + rounds = MAX(SHA256_ROUNDS_MIN, MIN(srounds, SHA256_ROUNDS_MAX)); + rounds_custom = 1; + } + } - salt_len = MIN(strcspn(salt, "$"), SHA256_SALT_LEN_MAX); - key_len = strlen(key); + salt_len = MIN(strcspn(salt, "$"), SHA256_SALT_LEN_MAX); + key_len = strlen(key); - if ((key - (char *)0) % __alignof__(uint32_t) != 0) - { - char *tmp = (char *)alloca(key_len + __alignof__(uint32_t)); - key = copied_key = - memcpy(tmp + __alignof__(uint32_t) - - (tmp - (char *)0) % __alignof__(uint32_t), key, key_len); - } + if ((key - (char *)0) % __alignof__(uint32_t) != 0) { + char *tmp = (char *)alloca(key_len + __alignof__(uint32_t)); + key = copied_key = + memcpy(tmp + __alignof__(uint32_t) + - (tmp - (char *)0) % __alignof__(uint32_t), key, key_len); + } - if ((salt - (char *)0) % __alignof__(uint32_t) != 0) - { - char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t)); - salt = copied_salt = - memcpy(tmp + __alignof__(uint32_t) - - (tmp - (char *)0) % __alignof__(uint32_t), salt, salt_len); - } + if ((salt - (char *)0) % __alignof__(uint32_t) != 0) { + char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t)); + salt = copied_salt = + memcpy(tmp + __alignof__(uint32_t) + - (tmp - (char *)0) % __alignof__(uint32_t), salt, salt_len); + } - /* Prepare for the real work. */ - rb_sha256_init_ctx(&ctx); + /* Prepare for the real work. */ + rb_sha256_init_ctx(&ctx); - /* Add the key string. */ - rb_sha256_process_bytes(key, key_len, &ctx); + /* Add the key string. */ + rb_sha256_process_bytes(key, key_len, &ctx); - /* The last part is the salt string. This must be at most 16 - characters and it ends at the first `$' character (for - compatibility with existing implementations). */ - rb_sha256_process_bytes(salt, salt_len, &ctx); + /* The last part is the salt string. This must be at most 16 + characters and it ends at the first `$' character (for + compatibility with existing implementations). */ + rb_sha256_process_bytes(salt, salt_len, &ctx); - /* Compute alternate SHA256 sum with input KEY, SALT, and KEY. The - final result will be added to the first context. */ - rb_sha256_init_ctx(&alt_ctx); + /* Compute alternate SHA256 sum with input KEY, SALT, and KEY. The + final result will be added to the first context. */ + rb_sha256_init_ctx(&alt_ctx); - /* Add key. */ - rb_sha256_process_bytes(key, key_len, &alt_ctx); + /* Add key. */ + rb_sha256_process_bytes(key, key_len, &alt_ctx); - /* Add salt. */ - rb_sha256_process_bytes(salt, salt_len, &alt_ctx); + /* Add salt. */ + rb_sha256_process_bytes(salt, salt_len, &alt_ctx); - /* Add key again. */ - rb_sha256_process_bytes(key, key_len, &alt_ctx); + /* Add key again. */ + rb_sha256_process_bytes(key, key_len, &alt_ctx); - /* Now get result of this (32 bytes) and add it to the other - context. */ - rb_sha256_finish_ctx(&alt_ctx, alt_result); + /* Now get result of this (32 bytes) and add it to the other + context. */ + rb_sha256_finish_ctx(&alt_ctx, alt_result); - /* Add for any character in the key one byte of the alternate sum. */ - for (cnt = key_len; cnt > 32; cnt -= 32) - rb_sha256_process_bytes(alt_result, 32, &ctx); - rb_sha256_process_bytes(alt_result, cnt, &ctx); + /* Add for any character in the key one byte of the alternate sum. */ + for (cnt = key_len; cnt > 32; cnt -= 32) + rb_sha256_process_bytes(alt_result, 32, &ctx); + rb_sha256_process_bytes(alt_result, cnt, &ctx); - /* Take the binary representation of the length of the key and for every - 1 add the alternate sum, for every 0 the key. */ - for (cnt = key_len; cnt > 0; cnt >>= 1) - if ((cnt & 1) != 0) - rb_sha256_process_bytes(alt_result, 32, &ctx); - else - rb_sha256_process_bytes(key, key_len, &ctx); + /* Take the binary representation of the length of the key and for every + 1 add the alternate sum, for every 0 the key. */ + for (cnt = key_len; cnt > 0; cnt >>= 1) + if ((cnt & 1) != 0) + rb_sha256_process_bytes(alt_result, 32, &ctx); + else + rb_sha256_process_bytes(key, key_len, &ctx); - /* Create intermediate result. */ - rb_sha256_finish_ctx(&ctx, alt_result); + /* Create intermediate result. */ + rb_sha256_finish_ctx(&ctx, alt_result); - /* Start computation of P byte sequence. */ - rb_sha256_init_ctx(&alt_ctx); + /* Start computation of P byte sequence. */ + rb_sha256_init_ctx(&alt_ctx); - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < (size_t)(16 + alt_result[0]); ++cnt) - rb_sha256_process_bytes(key, key_len, &alt_ctx); + /* For every character in the password add the entire password. */ + for (cnt = 0; cnt < (size_t)(16 + alt_result[0]); ++cnt) + rb_sha256_process_bytes(key, key_len, &alt_ctx); - /* Finish the digest. */ - rb_sha256_finish_ctx(&alt_ctx, temp_result); + /* Finish the digest. */ + rb_sha256_finish_ctx(&alt_ctx, temp_result); - /* Create byte sequence P. */ - cp = p_bytes = alloca(key_len); - for (cnt = key_len; cnt >= 32; cnt -= 32) - { - memcpy(cp, temp_result, 32); - cp += 32; - } - memcpy(cp, temp_result, cnt); + /* Create byte sequence P. */ + cp = p_bytes = alloca(key_len); + for (cnt = key_len; cnt >= 32; cnt -= 32) { + memcpy(cp, temp_result, 32); + cp += 32; + } + memcpy(cp, temp_result, cnt); - /* Start computation of S byte sequence. */ - rb_sha256_init_ctx(&alt_ctx); + /* Start computation of S byte sequence. */ + rb_sha256_init_ctx(&alt_ctx); - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < (size_t)(16 + alt_result[0]); ++cnt) - rb_sha256_process_bytes(salt, salt_len, &alt_ctx); + /* For every character in the password add the entire password. */ + for (cnt = 0; cnt < (size_t)(16 + alt_result[0]); ++cnt) + rb_sha256_process_bytes(salt, salt_len, &alt_ctx); - /* Finish the digest. */ - rb_sha256_finish_ctx(&alt_ctx, temp_result); + /* Finish the digest. */ + rb_sha256_finish_ctx(&alt_ctx, temp_result); - /* Create byte sequence S. */ - cp = s_bytes = alloca(salt_len); - for (cnt = salt_len; cnt >= 32; cnt -= 32) - { - memcpy(cp, temp_result, 32); - cp += 32; - } - memcpy(cp, temp_result, cnt); + /* Create byte sequence S. */ + cp = s_bytes = alloca(salt_len); + for (cnt = salt_len; cnt >= 32; cnt -= 32) { + memcpy(cp, temp_result, 32); + cp += 32; + } + memcpy(cp, temp_result, cnt); - /* Repeatedly run the collected hash value through SHA256 to burn - CPU cycles. */ - for (cnt = 0; cnt < rounds; ++cnt) - { - /* New context. */ - rb_sha256_init_ctx(&ctx); + /* Repeatedly run the collected hash value through SHA256 to burn + CPU cycles. */ + for (cnt = 0; cnt < rounds; ++cnt) { + /* New context. */ + rb_sha256_init_ctx(&ctx); - /* Add key or last result. */ - if ((cnt & 1) != 0) - rb_sha256_process_bytes(p_bytes, key_len, &ctx); - else - rb_sha256_process_bytes(alt_result, 32, &ctx); + /* Add key or last result. */ + if ((cnt & 1) != 0) + rb_sha256_process_bytes(p_bytes, key_len, &ctx); + else + rb_sha256_process_bytes(alt_result, 32, &ctx); - /* Add salt for numbers not divisible by 3. */ - if (cnt % 3 != 0) - rb_sha256_process_bytes(s_bytes, salt_len, &ctx); + /* Add salt for numbers not divisible by 3. */ + if (cnt % 3 != 0) + rb_sha256_process_bytes(s_bytes, salt_len, &ctx); - /* Add key for numbers not divisible by 7. */ - if (cnt % 7 != 0) - rb_sha256_process_bytes(p_bytes, key_len, &ctx); + /* Add key for numbers not divisible by 7. */ + if (cnt % 7 != 0) + rb_sha256_process_bytes(p_bytes, key_len, &ctx); - /* Add key or last result. */ - if ((cnt & 1) != 0) - rb_sha256_process_bytes(alt_result, 32, &ctx); - else - rb_sha256_process_bytes(p_bytes, key_len, &ctx); + /* Add key or last result. */ + if ((cnt & 1) != 0) + rb_sha256_process_bytes(alt_result, 32, &ctx); + else + rb_sha256_process_bytes(p_bytes, key_len, &ctx); - /* Create intermediate result. */ - rb_sha256_finish_ctx(&ctx, alt_result); - } + /* Create intermediate result. */ + rb_sha256_finish_ctx(&ctx, alt_result); + } - /* Now we can construct the result string. It consists of three - parts. */ - memset(buffer, '\0', MAX(0, buflen)); - strncpy(buffer, sha256_salt_prefix, MAX(0, buflen)); - if((cp = strchr(buffer, '\0')) == NULL) - cp = buffer + MAX(0, buflen); - buflen -= sizeof(sha256_salt_prefix) - 1; + /* Now we can construct the result string. It consists of three + parts. */ + memset(buffer, '\0', MAX(0, buflen)); + strncpy(buffer, sha256_salt_prefix, MAX(0, buflen)); + if((cp = strchr(buffer, '\0')) == NULL) + cp = buffer + MAX(0, buflen); + buflen -= sizeof(sha256_salt_prefix) - 1; - if (rounds_custom) - { - int n = snprintf(cp, MAX(0, buflen), "%s%zu$", - sha256_rounds_prefix, rounds); - cp += n; - buflen -= n; - } + if (rounds_custom) { + int n = snprintf(cp, MAX(0, buflen), "%s%zu$", + sha256_rounds_prefix, rounds); + cp += n; + buflen -= n; + } - memset(cp, '\0', salt_len); - strncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len)); - if((cp = strchr(buffer, '\0')) == NULL) - cp += salt_len; - buflen -= MIN((size_t) MAX(0, buflen), salt_len); + memset(cp, '\0', salt_len); + strncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len)); + if((cp = strchr(buffer, '\0')) == NULL) + cp += salt_len; + buflen -= MIN((size_t) MAX(0, buflen), salt_len); - if (buflen > 0) - { - *cp++ = '$'; - --buflen; - } + if (buflen > 0) { + *cp++ = '$'; + --buflen; + } - b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4); - b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4); - b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4); - b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4); - b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4); - b64_from_24bit(alt_result[15], alt_result[25], alt_result[5], 4); - b64_from_24bit(alt_result[6], alt_result[16], alt_result[26], 4); - b64_from_24bit(alt_result[27], alt_result[7], alt_result[17], 4); - b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4); - b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4); - b64_from_24bit(0, alt_result[31], alt_result[30], 3); - if (buflen <= 0) - { - errno = ERANGE; - buffer = NULL; - } - else - *cp = '\0'; /* Terminate the string. */ + b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4); + b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4); + b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4); + b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4); + b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4); + b64_from_24bit(alt_result[15], alt_result[25], alt_result[5], 4); + b64_from_24bit(alt_result[6], alt_result[16], alt_result[26], 4); + b64_from_24bit(alt_result[27], alt_result[7], alt_result[17], 4); + b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4); + b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4); + b64_from_24bit(0, alt_result[31], alt_result[30], 3); + if (buflen <= 0) { + errno = ERANGE; + buffer = NULL; + } else + *cp = '\0'; /* Terminate the string. */ - /* Clear the buffer for the intermediate result so that people - attaching to processes or reading core dumps cannot get any - information. We do it in this way to clear correct_words[] - inside the SHA256 implementation as well. */ - rb_sha256_init_ctx(&ctx); - rb_sha256_finish_ctx(&ctx, alt_result); - memset(temp_result, '\0', sizeof(temp_result)); - memset(p_bytes, '\0', key_len); - memset(s_bytes, '\0', salt_len); - memset(&ctx, '\0', sizeof(ctx)); - memset(&alt_ctx, '\0', sizeof(alt_ctx)); - if (copied_key != NULL) - memset(copied_key, '\0', key_len); - if (copied_salt != NULL) - memset(copied_salt, '\0', salt_len); + /* Clear the buffer for the intermediate result so that people + attaching to processes or reading core dumps cannot get any + information. We do it in this way to clear correct_words[] + inside the SHA256 implementation as well. */ + rb_sha256_init_ctx(&ctx); + rb_sha256_finish_ctx(&ctx, alt_result); + memset(temp_result, '\0', sizeof(temp_result)); + memset(p_bytes, '\0', key_len); + memset(s_bytes, '\0', salt_len); + memset(&ctx, '\0', sizeof(ctx)); + memset(&alt_ctx, '\0', sizeof(alt_ctx)); + if (copied_key != NULL) + memset(copied_key, '\0', key_len); + if (copied_salt != NULL) + memset(copied_salt, '\0', salt_len); - return buffer; + return buffer; } @@ -1708,33 +1670,32 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer, libcs. */ static char *rb_sha256_crypt(const char *key, const char *salt) { - /* We don't want to have an arbitrary limit in the size of the - password. We can compute an upper bound for the size of the - result in advance and so we can prepare the buffer we pass to - `rb_sha256_crypt_r'. */ - static char *buffer; - static int buflen; - int needed = (sizeof(sha256_salt_prefix) - 1 - + sizeof(sha256_rounds_prefix) + 9 + 1 + strlen(salt) + 1 + 43 + 1); + /* We don't want to have an arbitrary limit in the size of the + password. We can compute an upper bound for the size of the + result in advance and so we can prepare the buffer we pass to + `rb_sha256_crypt_r'. */ + static char *buffer; + static int buflen; + int needed = (sizeof(sha256_salt_prefix) - 1 + + sizeof(sha256_rounds_prefix) + 9 + 1 + strlen(salt) + 1 + 43 + 1); - char *new_buffer = (char *)malloc(needed); - if (new_buffer == NULL) - return NULL; + char *new_buffer = (char *)malloc(needed); + if (new_buffer == NULL) + return NULL; - buffer = new_buffer; - buflen = needed; + buffer = new_buffer; + buflen = needed; - return rb_sha256_crypt_r(key, salt, buffer, buflen); + return rb_sha256_crypt_r(key, salt, buffer, buflen); } /* Structure to save state of computation between the single steps. */ -struct sha512_ctx -{ - uint64_t H[8]; +struct sha512_ctx { + uint64_t H[8]; - uint64_t total[2]; - uint64_t buflen; - char buffer[256]; /* NB: always correctly aligned for uint64_t. */ + uint64_t total[2]; + uint64_t buflen; + char buffer[256]; /* NB: always correctly aligned for uint64_t. */ }; @@ -1760,46 +1721,46 @@ static const unsigned char SHA512_fillbuf[128] = { 0x80, 0 /* , 0, 0, ... */ } /* Constants for SHA512 from FIPS 180-2:4.2.3. */ static const uint64_t SHA512_K[80] = { - 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, - 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, - 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, - 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, - 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, - 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, - 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, - 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, - 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, - 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, - 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, - 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, - 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, - 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, - 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, - 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, - 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, - 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, - 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, - 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, - 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, - 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, - 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, - 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, - 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, - 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, - 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, - 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, - 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, - 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, - 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, - 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, - 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, - 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, - 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, - 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, - 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, - 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, - 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, - 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL + 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, + 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, + 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, + 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, + 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, + 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, + 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, + 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, + 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, + 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, + 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, + 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, + 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, + 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, + 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, + 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, + 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, + 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, + 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, + 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, + 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, + 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, + 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, + 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, + 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, + 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, + 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, + 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, + 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, + 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, + 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, + 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, + 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, + 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, + 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, + 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, + 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, + 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, + 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, + 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL }; @@ -1807,99 +1768,96 @@ static const uint64_t SHA512_K[80] = { It is assumed that LEN % 128 == 0. */ static void rb_sha512_process_block(const void *buffer, size_t len, struct sha512_ctx *ctx) { - const uint64_t *words = buffer; - size_t nwords = len / sizeof(uint64_t); - uint64_t a = ctx->H[0]; - uint64_t b = ctx->H[1]; - uint64_t c = ctx->H[2]; - uint64_t d = ctx->H[3]; - uint64_t e = ctx->H[4]; - uint64_t f = ctx->H[5]; - uint64_t g = ctx->H[6]; - uint64_t h = ctx->H[7]; + const uint64_t *words = buffer; + size_t nwords = len / sizeof(uint64_t); + uint64_t a = ctx->H[0]; + uint64_t b = ctx->H[1]; + uint64_t c = ctx->H[2]; + uint64_t d = ctx->H[3]; + uint64_t e = ctx->H[4]; + uint64_t f = ctx->H[5]; + uint64_t g = ctx->H[6]; + uint64_t h = ctx->H[7]; - /* First increment the byte count. FIPS 180-2 specifies the possible - length of the file up to 2^128 bits. Here we only compute the - number of bytes. Do a double word increment. */ - ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; + /* First increment the byte count. FIPS 180-2 specifies the possible + length of the file up to 2^128 bits. Here we only compute the + number of bytes. Do a double word increment. */ + ctx->total[0] += len; + if (ctx->total[0] < len) + ++ctx->total[1]; - /* Process all bytes in the buffer with 128 bytes in each round of - the loop. */ - while (nwords > 0) - { - uint64_t W[80]; - uint64_t a_save = a; - uint64_t b_save = b; - uint64_t c_save = c; - uint64_t d_save = d; - uint64_t e_save = e; - uint64_t f_save = f; - uint64_t g_save = g; - uint64_t h_save = h; - unsigned int t; + /* Process all bytes in the buffer with 128 bytes in each round of + the loop. */ + while (nwords > 0) { + uint64_t W[80]; + uint64_t a_save = a; + uint64_t b_save = b; + uint64_t c_save = c; + uint64_t d_save = d; + uint64_t e_save = e; + uint64_t f_save = f; + uint64_t g_save = g; + uint64_t h_save = h; + unsigned int t; - /* Operators defined in FIPS 180-2:4.1.2. */ - #define SHA512_Ch(x, y, z) ((x & y) ^ (~x & z)) - #define SHA512_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) - #define SHA512_S0(x) (SHA512_CYCLIC (x, 28) ^ SHA512_CYCLIC (x, 34) ^ SHA512_CYCLIC (x, 39)) - #define SHA512_S1(x) (SHA512_CYCLIC (x, 14) ^ SHA512_CYCLIC (x, 18) ^ SHA512_CYCLIC (x, 41)) - #define SHA512_R0(x) (SHA512_CYCLIC (x, 1) ^ SHA512_CYCLIC (x, 8) ^ (x >> 7)) - #define SHA512_R1(x) (SHA512_CYCLIC (x, 19) ^ SHA512_CYCLIC (x, 61) ^ (x >> 6)) + /* Operators defined in FIPS 180-2:4.1.2. */ +#define SHA512_Ch(x, y, z) ((x & y) ^ (~x & z)) +#define SHA512_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define SHA512_S0(x) (SHA512_CYCLIC (x, 28) ^ SHA512_CYCLIC (x, 34) ^ SHA512_CYCLIC (x, 39)) +#define SHA512_S1(x) (SHA512_CYCLIC (x, 14) ^ SHA512_CYCLIC (x, 18) ^ SHA512_CYCLIC (x, 41)) +#define SHA512_R0(x) (SHA512_CYCLIC (x, 1) ^ SHA512_CYCLIC (x, 8) ^ (x >> 7)) +#define SHA512_R1(x) (SHA512_CYCLIC (x, 19) ^ SHA512_CYCLIC (x, 61) ^ (x >> 6)) - /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ - #define SHA512_CYCLIC(w, s) ((w >> s) | (w << (64 - s))) + /* It is unfortunate that C does not provide an operator for + cyclic rotation. Hope the C compiler is smart enough. */ +#define SHA512_CYCLIC(w, s) ((w >> s) | (w << (64 - s))) - /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ - for (t = 0; t < 16; ++t) - { - W[t] = SHA512_SWAP(*words); - ++words; - } - for (t = 16; t < 80; ++t) - W[t] = SHA512_R1(W[t - 2]) + W[t - 7] + SHA512_R0(W[t - 15]) + W[t - 16]; + /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ + for (t = 0; t < 16; ++t) { + W[t] = SHA512_SWAP(*words); + ++words; + } + for (t = 16; t < 80; ++t) + W[t] = SHA512_R1(W[t - 2]) + W[t - 7] + SHA512_R0(W[t - 15]) + W[t - 16]; - /* The actual computation according to FIPS 180-2:6.3.2 step 3. */ - for (t = 0; t < 80; ++t) - { - uint64_t T1 = h + SHA512_S1(e) + SHA512_Ch(e, f, g) + SHA512_K[t] + W[t]; - uint64_t T2 = SHA512_S0(a) + SHA512_Maj(a, b, c); - h = g; - g = f; - f = e; - e = d + T1; - d = c; - c = b; - b = a; - a = T1 + T2; - } + /* The actual computation according to FIPS 180-2:6.3.2 step 3. */ + for (t = 0; t < 80; ++t) { + uint64_t T1 = h + SHA512_S1(e) + SHA512_Ch(e, f, g) + SHA512_K[t] + W[t]; + uint64_t T2 = SHA512_S0(a) + SHA512_Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + T1; + d = c; + c = b; + b = a; + a = T1 + T2; + } - /* Add the starting values of the context according to FIPS 180-2:6.3.2 - step 4. */ - a += a_save; - b += b_save; - c += c_save; - d += d_save; - e += e_save; - f += f_save; - g += g_save; - h += h_save; + /* Add the starting values of the context according to FIPS 180-2:6.3.2 + step 4. */ + a += a_save; + b += b_save; + c += c_save; + d += d_save; + e += e_save; + f += f_save; + g += g_save; + h += h_save; - /* Prepare for the next round. */ - nwords -= 16; - } + /* Prepare for the next round. */ + nwords -= 16; + } - /* Put checksum in context given as argument. */ - ctx->H[0] = a; - ctx->H[1] = b; - ctx->H[2] = c; - ctx->H[3] = d; - ctx->H[4] = e; - ctx->H[5] = f; - ctx->H[6] = g; - ctx->H[7] = h; + /* Put checksum in context given as argument. */ + ctx->H[0] = a; + ctx->H[1] = b; + ctx->H[2] = c; + ctx->H[3] = d; + ctx->H[4] = e; + ctx->H[5] = f; + ctx->H[6] = g; + ctx->H[7] = h; } @@ -1907,17 +1865,17 @@ static void rb_sha512_process_block(const void *buffer, size_t len, struct sha51 (FIPS 180-2:5.3.3) */ static void rb_sha512_init_ctx(struct sha512_ctx *ctx) { - ctx->H[0] = 0x6a09e667f3bcc908ULL; - ctx->H[1] = 0xbb67ae8584caa73bULL; - ctx->H[2] = 0x3c6ef372fe94f82bULL; - ctx->H[3] = 0xa54ff53a5f1d36f1ULL; - ctx->H[4] = 0x510e527fade682d1ULL; - ctx->H[5] = 0x9b05688c2b3e6c1fULL; - ctx->H[6] = 0x1f83d9abfb41bd6bULL; - ctx->H[7] = 0x5be0cd19137e2179ULL; + ctx->H[0] = 0x6a09e667f3bcc908ULL; + ctx->H[1] = 0xbb67ae8584caa73bULL; + ctx->H[2] = 0x3c6ef372fe94f82bULL; + ctx->H[3] = 0xa54ff53a5f1d36f1ULL; + ctx->H[4] = 0x510e527fade682d1ULL; + ctx->H[5] = 0x9b05688c2b3e6c1fULL; + ctx->H[6] = 0x1f83d9abfb41bd6bULL; + ctx->H[7] = 0x5be0cd19137e2179ULL; - ctx->total[0] = ctx->total[1] = 0; - ctx->buflen = 0; + ctx->total[0] = ctx->total[1] = 0; + ctx->buflen = 0; } @@ -1928,102 +1886,96 @@ static void rb_sha512_init_ctx(struct sha512_ctx *ctx) aligned for a 32 bits value. */ static void *rb_sha512_finish_ctx(struct sha512_ctx *ctx, void *resbuf) { - /* Take yet unprocessed bytes into account. */ - uint64_t bytes = ctx->buflen; - size_t pad; - unsigned int i; + /* Take yet unprocessed bytes into account. */ + uint64_t bytes = ctx->buflen; + size_t pad; + unsigned int i; - /* Now count remaining bytes. */ - ctx->total[0] += bytes; - if (ctx->total[0] < bytes) - ++ctx->total[1]; + /* Now count remaining bytes. */ + ctx->total[0] += bytes; + if (ctx->total[0] < bytes) + ++ctx->total[1]; - pad = bytes >= 112 ? 128 + 112 - bytes : 112 - bytes; - memcpy(&ctx->buffer[bytes], SHA512_fillbuf, pad); + pad = bytes >= 112 ? 128 + 112 - bytes : 112 - bytes; + memcpy(&ctx->buffer[bytes], SHA512_fillbuf, pad); - /* Put the 128-bit file length in *bits* at the end of the buffer. */ - *(uint64_t *) & ctx->buffer[bytes + pad + 8] = SHA512_SWAP(ctx->total[0] << 3); - *(uint64_t *) & ctx->buffer[bytes + pad] = SHA512_SWAP((ctx->total[1] << 3) | - (ctx->total[0] >> 61)); + /* Put the 128-bit file length in *bits* at the end of the buffer. */ + *(uint64_t *) & ctx->buffer[bytes + pad + 8] = SHA512_SWAP(ctx->total[0] << 3); + *(uint64_t *) & ctx->buffer[bytes + pad] = SHA512_SWAP((ctx->total[1] << 3) | + (ctx->total[0] >> 61)); - /* Process last bytes. */ - rb_sha512_process_block(ctx->buffer, bytes + pad + 16, ctx); + /* Process last bytes. */ + rb_sha512_process_block(ctx->buffer, bytes + pad + 16, ctx); - /* Put result from CTX in first 64 bytes following RESBUF. */ - for (i = 0; i < 8; ++i) - ((uint64_t *) resbuf)[i] = SHA512_SWAP(ctx->H[i]); + /* Put result from CTX in first 64 bytes following RESBUF. */ + for (i = 0; i < 8; ++i) + ((uint64_t *) resbuf)[i] = SHA512_SWAP(ctx->H[i]); - return resbuf; + return resbuf; } static void rb_sha512_process_bytes(const void *buffer, size_t len, struct sha512_ctx *ctx) { - /* When we already have some bits in our internal buffer concatenate - both inputs first. */ - if (ctx->buflen != 0) - { - size_t left_over = ctx->buflen; - size_t add = 256 - left_over > len ? len : 256 - left_over; + /* When we already have some bits in our internal buffer concatenate + both inputs first. */ + if (ctx->buflen != 0) { + size_t left_over = ctx->buflen; + size_t add = 256 - left_over > len ? len : 256 - left_over; - memcpy(&ctx->buffer[left_over], buffer, add); - ctx->buflen += add; + memcpy(&ctx->buffer[left_over], buffer, add); + ctx->buflen += add; - if (ctx->buflen > 128) - { - rb_sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx); + if (ctx->buflen > 128) { + rb_sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx); - ctx->buflen &= 127; - /* The regions in the following copy operation cannot overlap. */ - memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~127], ctx->buflen); - } + ctx->buflen &= 127; + /* The regions in the following copy operation cannot overlap. */ + memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~127], ctx->buflen); + } - buffer = (const char *)buffer + add; - len -= add; - } + buffer = (const char *)buffer + add; + len -= add; + } - /* Process available complete blocks. */ - if (len >= 128) - { - #if !_STRING_ARCH_unaligned - /* To check alignment gcc has an appropriate operator. Other - compilers don't. */ - # if __GNUC__ >= 2 - # define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0) - # else - # define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0) - # endif - if (SHA512_UNALIGNED_P(buffer)) - while (len > 128) - { - rb_sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx); - buffer = (const char *)buffer + 128; - len -= 128; - } - else - #endif - { - rb_sha512_process_block(buffer, len & ~127, ctx); - buffer = (const char *)buffer + (len & ~127); - len &= 127; - } - } + /* Process available complete blocks. */ + if (len >= 128) { +#if !_STRING_ARCH_unaligned + /* To check alignment gcc has an appropriate operator. Other + compilers don't. */ +# if __GNUC__ >= 2 +# define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0) +# else +# define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0) +# endif + if (SHA512_UNALIGNED_P(buffer)) + while (len > 128) { + rb_sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx); + buffer = (const char *)buffer + 128; + len -= 128; + } + else +#endif + { + rb_sha512_process_block(buffer, len & ~127, ctx); + buffer = (const char *)buffer + (len & ~127); + len &= 127; + } + } - /* Move remaining bytes into internal buffer. */ - if (len > 0) - { - size_t left_over = ctx->buflen; + /* Move remaining bytes into internal buffer. */ + if (len > 0) { + size_t left_over = ctx->buflen; - memcpy(&ctx->buffer[left_over], buffer, len); - left_over += len; - if (left_over >= 128) - { - rb_sha512_process_block(ctx->buffer, 128, ctx); - left_over -= 128; - memcpy(ctx->buffer, &ctx->buffer[128], left_over); - } - ctx->buflen = left_over; - } + memcpy(&ctx->buffer[left_over], buffer, len); + left_over += len; + if (left_over >= 128) { + rb_sha512_process_block(ctx->buffer, 128, ctx); + left_over -= 128; + memcpy(ctx->buffer, &ctx->buffer[128], left_over); + } + ctx->buflen = left_over; + } } @@ -2045,250 +1997,239 @@ static const char sha512_rounds_prefix[] = "rounds="; static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) { - unsigned char alt_result[64] __attribute__ ((__aligned__(__alignof__(uint64_t)))); - unsigned char temp_result[64] __attribute__ ((__aligned__(__alignof__(uint64_t)))); - struct sha512_ctx ctx; - struct sha512_ctx alt_ctx; - size_t salt_len; - size_t key_len; - size_t cnt; - char *cp; - char *copied_key = NULL; - char *copied_salt = NULL; - char *p_bytes; - char *s_bytes; - /* Default number of rounds. */ - size_t rounds = SHA512_ROUNDS_DEFAULT; - int rounds_custom = 0; + unsigned char alt_result[64] __attribute__ ((__aligned__(__alignof__(uint64_t)))); + unsigned char temp_result[64] __attribute__ ((__aligned__(__alignof__(uint64_t)))); + struct sha512_ctx ctx; + struct sha512_ctx alt_ctx; + size_t salt_len; + size_t key_len; + size_t cnt; + char *cp; + char *copied_key = NULL; + char *copied_salt = NULL; + char *p_bytes; + char *s_bytes; + /* Default number of rounds. */ + size_t rounds = SHA512_ROUNDS_DEFAULT; + int rounds_custom = 0; - /* Find beginning of salt string. The prefix should normally always - be present. Just in case it is not. */ - if (strncmp(sha512_salt_prefix, salt, sizeof(sha512_salt_prefix) - 1) == 0) - /* Skip salt prefix. */ - salt += sizeof(sha512_salt_prefix) - 1; + /* Find beginning of salt string. The prefix should normally always + be present. Just in case it is not. */ + if (strncmp(sha512_salt_prefix, salt, sizeof(sha512_salt_prefix) - 1) == 0) + /* Skip salt prefix. */ + salt += sizeof(sha512_salt_prefix) - 1; - if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) == 0) - { - const char *num = salt + sizeof(sha512_rounds_prefix) - 1; - char *endp; - unsigned long int srounds = strtoul(num, &endp, 10); - if (*endp == '$') - { - salt = endp + 1; - rounds = MAX(SHA512_ROUNDS_MIN, MIN(srounds, SHA512_ROUNDS_MAX)); - rounds_custom = 1; - } - } + if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) == 0) { + const char *num = salt + sizeof(sha512_rounds_prefix) - 1; + char *endp; + unsigned long int srounds = strtoul(num, &endp, 10); + if (*endp == '$') { + salt = endp + 1; + rounds = MAX(SHA512_ROUNDS_MIN, MIN(srounds, SHA512_ROUNDS_MAX)); + rounds_custom = 1; + } + } - salt_len = MIN(strcspn(salt, "$"), SHA512_SALT_LEN_MAX); - key_len = strlen(key); + salt_len = MIN(strcspn(salt, "$"), SHA512_SALT_LEN_MAX); + key_len = strlen(key); - if ((key - (char *)0) % __alignof__(uint64_t) != 0) - { - char *tmp = (char *)alloca(key_len + __alignof__(uint64_t)); - key = copied_key = - memcpy(tmp + __alignof__(uint64_t) - - (tmp - (char *)0) % __alignof__(uint64_t), key, key_len); - } + if ((key - (char *)0) % __alignof__(uint64_t) != 0) { + char *tmp = (char *)alloca(key_len + __alignof__(uint64_t)); + key = copied_key = + memcpy(tmp + __alignof__(uint64_t) + - (tmp - (char *)0) % __alignof__(uint64_t), key, key_len); + } - if ((salt - (char *)0) % __alignof__(uint64_t) != 0) - { - char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t)); - salt = copied_salt = - memcpy(tmp + __alignof__(uint64_t) - - (tmp - (char *)0) % __alignof__(uint64_t), salt, salt_len); - } + if ((salt - (char *)0) % __alignof__(uint64_t) != 0) { + char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t)); + salt = copied_salt = + memcpy(tmp + __alignof__(uint64_t) + - (tmp - (char *)0) % __alignof__(uint64_t), salt, salt_len); + } - /* Prepare for the real work. */ - rb_sha512_init_ctx(&ctx); + /* Prepare for the real work. */ + rb_sha512_init_ctx(&ctx); - /* Add the key string. */ - rb_sha512_process_bytes(key, key_len, &ctx); + /* Add the key string. */ + rb_sha512_process_bytes(key, key_len, &ctx); - /* The last part is the salt string. This must be at most 16 - characters and it ends at the first `$' character (for - compatibility with existing implementations). */ - rb_sha512_process_bytes(salt, salt_len, &ctx); + /* The last part is the salt string. This must be at most 16 + characters and it ends at the first `$' character (for + compatibility with existing implementations). */ + rb_sha512_process_bytes(salt, salt_len, &ctx); - /* Compute alternate SHA512 sum with input KEY, SALT, and KEY. The - final result will be added to the first context. */ - rb_sha512_init_ctx(&alt_ctx); + /* Compute alternate SHA512 sum with input KEY, SALT, and KEY. The + final result will be added to the first context. */ + rb_sha512_init_ctx(&alt_ctx); - /* Add key. */ - rb_sha512_process_bytes(key, key_len, &alt_ctx); + /* Add key. */ + rb_sha512_process_bytes(key, key_len, &alt_ctx); - /* Add salt. */ - rb_sha512_process_bytes(salt, salt_len, &alt_ctx); + /* Add salt. */ + rb_sha512_process_bytes(salt, salt_len, &alt_ctx); - /* Add key again. */ - rb_sha512_process_bytes(key, key_len, &alt_ctx); + /* Add key again. */ + rb_sha512_process_bytes(key, key_len, &alt_ctx); - /* Now get result of this (64 bytes) and add it to the other - context. */ - rb_sha512_finish_ctx(&alt_ctx, alt_result); + /* Now get result of this (64 bytes) and add it to the other + context. */ + rb_sha512_finish_ctx(&alt_ctx, alt_result); - /* Add for any character in the key one byte of the alternate sum. */ - for (cnt = key_len; cnt > 64; cnt -= 64) - rb_sha512_process_bytes(alt_result, 64, &ctx); - rb_sha512_process_bytes(alt_result, cnt, &ctx); + /* Add for any character in the key one byte of the alternate sum. */ + for (cnt = key_len; cnt > 64; cnt -= 64) + rb_sha512_process_bytes(alt_result, 64, &ctx); + rb_sha512_process_bytes(alt_result, cnt, &ctx); - /* Take the binary representation of the length of the key and for every - 1 add the alternate sum, for every 0 the key. */ - for (cnt = key_len; cnt > 0; cnt >>= 1) - if ((cnt & 1) != 0) - rb_sha512_process_bytes(alt_result, 64, &ctx); - else - rb_sha512_process_bytes(key, key_len, &ctx); + /* Take the binary representation of the length of the key and for every + 1 add the alternate sum, for every 0 the key. */ + for (cnt = key_len; cnt > 0; cnt >>= 1) + if ((cnt & 1) != 0) + rb_sha512_process_bytes(alt_result, 64, &ctx); + else + rb_sha512_process_bytes(key, key_len, &ctx); - /* Create intermediate result. */ - rb_sha512_finish_ctx(&ctx, alt_result); + /* Create intermediate result. */ + rb_sha512_finish_ctx(&ctx, alt_result); - /* Start computation of P byte sequence. */ - rb_sha512_init_ctx(&alt_ctx); + /* Start computation of P byte sequence. */ + rb_sha512_init_ctx(&alt_ctx); - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < key_len; ++cnt) - rb_sha512_process_bytes(key, key_len, &alt_ctx); + /* For every character in the password add the entire password. */ + for (cnt = 0; cnt < key_len; ++cnt) + rb_sha512_process_bytes(key, key_len, &alt_ctx); - /* Finish the digest. */ - rb_sha512_finish_ctx(&alt_ctx, temp_result); + /* Finish the digest. */ + rb_sha512_finish_ctx(&alt_ctx, temp_result); - /* Create byte sequence P. */ - cp = p_bytes = alloca(key_len); - for (cnt = key_len; cnt >= 64; cnt -= 64) - { - memcpy(cp, temp_result, 64); - cp += 64; - } - memcpy(cp, temp_result, cnt); + /* Create byte sequence P. */ + cp = p_bytes = alloca(key_len); + for (cnt = key_len; cnt >= 64; cnt -= 64) { + memcpy(cp, temp_result, 64); + cp += 64; + } + memcpy(cp, temp_result, cnt); - /* Start computation of S byte sequence. */ - rb_sha512_init_ctx(&alt_ctx); + /* Start computation of S byte sequence. */ + rb_sha512_init_ctx(&alt_ctx); - /* For every character in the password add the entire password. */ - for (cnt = 0; cnt < (size_t)(16 + alt_result[0]); ++cnt) - rb_sha512_process_bytes(salt, salt_len, &alt_ctx); + /* For every character in the password add the entire password. */ + for (cnt = 0; cnt < (size_t)(16 + alt_result[0]); ++cnt) + rb_sha512_process_bytes(salt, salt_len, &alt_ctx); - /* Finish the digest. */ - rb_sha512_finish_ctx(&alt_ctx, temp_result); + /* Finish the digest. */ + rb_sha512_finish_ctx(&alt_ctx, temp_result); - /* Create byte sequence S. */ - cp = s_bytes = alloca(salt_len); - for (cnt = salt_len; cnt >= 64; cnt -= 64) - { - memcpy(cp, temp_result, 64); - cp += 64; - } - memcpy(cp, temp_result, cnt); + /* Create byte sequence S. */ + cp = s_bytes = alloca(salt_len); + for (cnt = salt_len; cnt >= 64; cnt -= 64) { + memcpy(cp, temp_result, 64); + cp += 64; + } + memcpy(cp, temp_result, cnt); - /* Repeatedly run the collected hash value through SHA512 to burn - CPU cycles. */ - for (cnt = 0; cnt < rounds; ++cnt) - { - /* New context. */ - rb_sha512_init_ctx(&ctx); + /* Repeatedly run the collected hash value through SHA512 to burn + CPU cycles. */ + for (cnt = 0; cnt < rounds; ++cnt) { + /* New context. */ + rb_sha512_init_ctx(&ctx); - /* Add key or last result. */ - if ((cnt & 1) != 0) - rb_sha512_process_bytes(p_bytes, key_len, &ctx); - else - rb_sha512_process_bytes(alt_result, 64, &ctx); + /* Add key or last result. */ + if ((cnt & 1) != 0) + rb_sha512_process_bytes(p_bytes, key_len, &ctx); + else + rb_sha512_process_bytes(alt_result, 64, &ctx); - /* Add salt for numbers not divisible by 3. */ - if (cnt % 3 != 0) - rb_sha512_process_bytes(s_bytes, salt_len, &ctx); + /* Add salt for numbers not divisible by 3. */ + if (cnt % 3 != 0) + rb_sha512_process_bytes(s_bytes, salt_len, &ctx); - /* Add key for numbers not divisible by 7. */ - if (cnt % 7 != 0) - rb_sha512_process_bytes(p_bytes, key_len, &ctx); + /* Add key for numbers not divisible by 7. */ + if (cnt % 7 != 0) + rb_sha512_process_bytes(p_bytes, key_len, &ctx); - /* Add key or last result. */ - if ((cnt & 1) != 0) - rb_sha512_process_bytes(alt_result, 64, &ctx); - else - rb_sha512_process_bytes(p_bytes, key_len, &ctx); + /* Add key or last result. */ + if ((cnt & 1) != 0) + rb_sha512_process_bytes(alt_result, 64, &ctx); + else + rb_sha512_process_bytes(p_bytes, key_len, &ctx); - /* Create intermediate result. */ - rb_sha512_finish_ctx(&ctx, alt_result); - } + /* Create intermediate result. */ + rb_sha512_finish_ctx(&ctx, alt_result); + } - /* Now we can construct the result string. It consists of three - parts. */ - memset(buffer, '\0', MAX(0, buflen)); - strncpy(buffer, sha512_salt_prefix, MAX(0, buflen)); - if((cp = strchr(buffer, '\0')) == NULL) - cp = buffer + MAX(0, buflen); - buflen -= sizeof(sha512_salt_prefix) - 1; + /* Now we can construct the result string. It consists of three + parts. */ + memset(buffer, '\0', MAX(0, buflen)); + strncpy(buffer, sha512_salt_prefix, MAX(0, buflen)); + if((cp = strchr(buffer, '\0')) == NULL) + cp = buffer + MAX(0, buflen); + buflen -= sizeof(sha512_salt_prefix) - 1; - if (rounds_custom) - { - int n = snprintf(cp, MAX(0, buflen), "%s%zu$", - sha512_rounds_prefix, rounds); - cp += n; - buflen -= n; - } + if (rounds_custom) { + int n = snprintf(cp, MAX(0, buflen), "%s%zu$", + sha512_rounds_prefix, rounds); + cp += n; + buflen -= n; + } - memset(cp, '\0', MIN((size_t) MAX(0, buflen), salt_len)); - strncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len)); - if((cp = strchr(buffer, '\0')) == NULL) - cp = buffer + salt_len; - buflen -= MIN((size_t) MAX(0, buflen), salt_len); + memset(cp, '\0', MIN((size_t) MAX(0, buflen), salt_len)); + strncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len)); + if((cp = strchr(buffer, '\0')) == NULL) + cp = buffer + salt_len; + buflen -= MIN((size_t) MAX(0, buflen), salt_len); - if (buflen > 0) - { - *cp++ = '$'; - --buflen; - } + if (buflen > 0) { + *cp++ = '$'; + --buflen; + } - b64_from_24bit(alt_result[0], alt_result[21], alt_result[42], 4); - b64_from_24bit(alt_result[22], alt_result[43], alt_result[1], 4); - b64_from_24bit(alt_result[44], alt_result[2], alt_result[23], 4); - b64_from_24bit(alt_result[3], alt_result[24], alt_result[45], 4); - b64_from_24bit(alt_result[25], alt_result[46], alt_result[4], 4); - b64_from_24bit(alt_result[47], alt_result[5], alt_result[26], 4); - b64_from_24bit(alt_result[6], alt_result[27], alt_result[48], 4); - b64_from_24bit(alt_result[28], alt_result[49], alt_result[7], 4); - b64_from_24bit(alt_result[50], alt_result[8], alt_result[29], 4); - b64_from_24bit(alt_result[9], alt_result[30], alt_result[51], 4); - b64_from_24bit(alt_result[31], alt_result[52], alt_result[10], 4); - b64_from_24bit(alt_result[53], alt_result[11], alt_result[32], 4); - b64_from_24bit(alt_result[12], alt_result[33], alt_result[54], 4); - b64_from_24bit(alt_result[34], alt_result[55], alt_result[13], 4); - b64_from_24bit(alt_result[56], alt_result[14], alt_result[35], 4); - b64_from_24bit(alt_result[15], alt_result[36], alt_result[57], 4); - b64_from_24bit(alt_result[37], alt_result[58], alt_result[16], 4); - b64_from_24bit(alt_result[59], alt_result[17], alt_result[38], 4); - b64_from_24bit(alt_result[18], alt_result[39], alt_result[60], 4); - b64_from_24bit(alt_result[40], alt_result[61], alt_result[19], 4); - b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4); - b64_from_24bit(0, 0, alt_result[63], 2); + b64_from_24bit(alt_result[0], alt_result[21], alt_result[42], 4); + b64_from_24bit(alt_result[22], alt_result[43], alt_result[1], 4); + b64_from_24bit(alt_result[44], alt_result[2], alt_result[23], 4); + b64_from_24bit(alt_result[3], alt_result[24], alt_result[45], 4); + b64_from_24bit(alt_result[25], alt_result[46], alt_result[4], 4); + b64_from_24bit(alt_result[47], alt_result[5], alt_result[26], 4); + b64_from_24bit(alt_result[6], alt_result[27], alt_result[48], 4); + b64_from_24bit(alt_result[28], alt_result[49], alt_result[7], 4); + b64_from_24bit(alt_result[50], alt_result[8], alt_result[29], 4); + b64_from_24bit(alt_result[9], alt_result[30], alt_result[51], 4); + b64_from_24bit(alt_result[31], alt_result[52], alt_result[10], 4); + b64_from_24bit(alt_result[53], alt_result[11], alt_result[32], 4); + b64_from_24bit(alt_result[12], alt_result[33], alt_result[54], 4); + b64_from_24bit(alt_result[34], alt_result[55], alt_result[13], 4); + b64_from_24bit(alt_result[56], alt_result[14], alt_result[35], 4); + b64_from_24bit(alt_result[15], alt_result[36], alt_result[57], 4); + b64_from_24bit(alt_result[37], alt_result[58], alt_result[16], 4); + b64_from_24bit(alt_result[59], alt_result[17], alt_result[38], 4); + b64_from_24bit(alt_result[18], alt_result[39], alt_result[60], 4); + b64_from_24bit(alt_result[40], alt_result[61], alt_result[19], 4); + b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4); + b64_from_24bit(0, 0, alt_result[63], 2); - if (buflen <= 0) - { - errno = ERANGE; - buffer = NULL; - } - else - *cp = '\0'; /* Terminate the string. */ + if (buflen <= 0) { + errno = ERANGE; + buffer = NULL; + } else + *cp = '\0'; /* Terminate the string. */ - /* Clear the buffer for the intermediate result so that people - attaching to processes or reading core dumps cannot get any - information. We do it in this way to clear correct_words[] - inside the SHA512 implementation as well. */ - rb_sha512_init_ctx(&ctx); - rb_sha512_finish_ctx(&ctx, alt_result); - memset(temp_result, '\0', sizeof(temp_result)); - memset(p_bytes, '\0', key_len); - memset(s_bytes, '\0', salt_len); - memset(&ctx, '\0', sizeof(ctx)); - memset(&alt_ctx, '\0', sizeof(alt_ctx)); - if (copied_key != NULL) - memset(copied_key, '\0', key_len); - if (copied_salt != NULL) - memset(copied_salt, '\0', salt_len); + /* Clear the buffer for the intermediate result so that people + attaching to processes or reading core dumps cannot get any + information. We do it in this way to clear correct_words[] + inside the SHA512 implementation as well. */ + rb_sha512_init_ctx(&ctx); + rb_sha512_finish_ctx(&ctx, alt_result); + memset(temp_result, '\0', sizeof(temp_result)); + memset(p_bytes, '\0', key_len); + memset(s_bytes, '\0', salt_len); + memset(&ctx, '\0', sizeof(ctx)); + memset(&alt_ctx, '\0', sizeof(alt_ctx)); + if (copied_key != NULL) + memset(copied_key, '\0', key_len); + if (copied_salt != NULL) + memset(copied_salt, '\0', salt_len); - return buffer; + return buffer; } @@ -2296,26 +2237,25 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer, libcs. */ static char *rb_sha512_crypt(const char *key, const char *salt) { - /* We don't want to have an arbitrary limit in the size of the - password. We can compute an upper bound for the size of the - result in advance and so we can prepare the buffer we pass to - `rb_sha512_crypt_r'. */ - static char *buffer; - static int buflen; - int needed = (sizeof(sha512_salt_prefix) - 1 - + sizeof(sha512_rounds_prefix) + 9 + 1 + strlen(salt) + 1 + 86 + 1); + /* We don't want to have an arbitrary limit in the size of the + password. We can compute an upper bound for the size of the + result in advance and so we can prepare the buffer we pass to + `rb_sha512_crypt_r'. */ + static char *buffer; + static int buflen; + int needed = (sizeof(sha512_salt_prefix) - 1 + + sizeof(sha512_rounds_prefix) + 9 + 1 + strlen(salt) + 1 + 86 + 1); - if (buflen < needed) - { - char *new_buffer = (char *)realloc(buffer, needed); - if (new_buffer == NULL) - return NULL; + if (buflen < needed) { + char *new_buffer = (char *)realloc(buffer, needed); + if (new_buffer == NULL) + return NULL; - buffer = new_buffer; - buflen = needed; - } + buffer = new_buffer; + buflen = needed; + } - return rb_sha512_crypt_r(key, salt, buffer, buflen); + return rb_sha512_crypt_r(key, salt, buffer, buflen); } @@ -2361,8 +2301,8 @@ static char *rb_sha512_crypt(const char *key, const char *salt) /* Blowfish context */ typedef struct BlowfishContext { - uint32_t S[4][256]; /* S-Boxes */ - uint32_t P[BLF_N + 2]; /* Subkeys */ + uint32_t S[4][256]; /* S-Boxes */ + uint32_t P[BLF_N + 2]; /* Subkeys */ } blf_ctx; /* Raw access to customized Blowfish @@ -2374,7 +2314,7 @@ typedef struct BlowfishContext { void Blowfish_initstate(blf_ctx *); void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t); void Blowfish_expandstate - (blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t); +(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t); uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *); void blf_enc(blf_ctx *, uint32_t *, uint16_t); @@ -2402,422 +2342,435 @@ void blf_enc(blf_ctx *, uint32_t *, uint16_t); static void Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr) { - uint32_t Xl; - uint32_t Xr; - uint32_t *s = c->S[0]; - uint32_t *p = c->P; + uint32_t Xl; + uint32_t Xr; + uint32_t *s = c->S[0]; + uint32_t *p = c->P; - Xl = *xl; - Xr = *xr; + Xl = *xl; + Xr = *xr; - Xl ^= p[0]; - BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2); - BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4); - BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6); - BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8); - BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10); - BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12); - BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14); - BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16); + Xl ^= p[0]; + BLFRND(s, p, Xr, Xl, 1); + BLFRND(s, p, Xl, Xr, 2); + BLFRND(s, p, Xr, Xl, 3); + BLFRND(s, p, Xl, Xr, 4); + BLFRND(s, p, Xr, Xl, 5); + BLFRND(s, p, Xl, Xr, 6); + BLFRND(s, p, Xr, Xl, 7); + BLFRND(s, p, Xl, Xr, 8); + BLFRND(s, p, Xr, Xl, 9); + BLFRND(s, p, Xl, Xr, 10); + BLFRND(s, p, Xr, Xl, 11); + BLFRND(s, p, Xl, Xr, 12); + BLFRND(s, p, Xr, Xl, 13); + BLFRND(s, p, Xl, Xr, 14); + BLFRND(s, p, Xr, Xl, 15); + BLFRND(s, p, Xl, Xr, 16); - *xl = Xr ^ p[17]; - *xr = Xl; + *xl = Xr ^ p[17]; + *xr = Xl; } void Blowfish_initstate(blf_ctx *c) { -/* P-box and S-box tables initialized with digits of Pi */ + /* P-box and S-box tables initialized with digits of Pi */ - const blf_ctx bf_initstate = + const blf_ctx bf_initstate = - { { - { - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, - 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, - 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, - 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, - 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, - 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, - 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, - 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, - 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, - 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, - 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, - 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, - 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, - 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, - 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, - 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, - 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, - 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, - 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, - 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, - 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, - 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, - 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, - 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, - 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, - 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, - 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, - 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, - 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, - 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, - 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, - 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, - 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, - 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, - 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, - 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, - 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, - 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, - 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, - 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, - 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, - 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, - 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a}, - { - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, - 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, - 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, - 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, - 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, - 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, - 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, - 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, - 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, - 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, - 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, - 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, - 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, - 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, - 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, - 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, - 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, - 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, - 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, - 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, - 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, - 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, - 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, - 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, - 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, - 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, - 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, - 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, - 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, - 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, - 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, - 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, - 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, - 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, - 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, - 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, - 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, - 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, - 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, - 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, - 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, - 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, - 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7}, - { - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, - 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, - 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, - 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, - 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, - 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, - 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, - 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, - 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, - 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, - 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, - 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, - 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, - 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, - 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, - 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, - 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, - 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, - 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, - 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, - 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, - 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, - 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, - 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, - 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, - 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, - 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, - 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, - 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, - 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, - 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, - 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, - 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, - 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, - 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, - 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, - 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, - 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, - 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, - 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, - 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, - 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, - 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0}, - { - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, - 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, - 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, - 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, - 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, - 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, - 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, - 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, - 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, - 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, - 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, - 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, - 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, - 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, - 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, - 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, - 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, - 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, - 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, - 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, - 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, - 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, - 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, - 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, - 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, - 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, - 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, - 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, - 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, - 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, - 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, - 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, - 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, - 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, - 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, - 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, - 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, - 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, - 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, - 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, - 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, - 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, - 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6} - }, - { - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, - 0x9216d5d9, 0x8979fb1b - } }; + { { + { + 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, + 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, + 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, + 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, + 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, + 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, + 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, + 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, + 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, + 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, + 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, + 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, + 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, + 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, + 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, + 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, + 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, + 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, + 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, + 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, + 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, + 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, + 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, + 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, + 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, + 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, + 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, + 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, + 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, + 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, + 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, + 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, + 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, + 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, + 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a + }, + { + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, + 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, + 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, + 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, + 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, + 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, + 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, + 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, + 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, + 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, + 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, + 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, + 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, + 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, + 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, + 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, + 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, + 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, + 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, + 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, + 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, + 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, + 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, + 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, + 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, + 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, + 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, + 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, + 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, + 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, + 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, + 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, + 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, + 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 + }, + { + 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, + 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, + 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, + 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, + 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, + 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, + 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, + 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, + 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, + 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, + 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, + 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, + 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, + 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, + 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, + 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, + 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, + 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, + 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, + 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, + 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, + 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, + 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, + 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, + 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, + 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, + 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, + 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, + 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, + 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, + 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, + 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, + 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, + 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, + 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 + }, + { + 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, + 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, + 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, + 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, + 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, + 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, + 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, + 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, + 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, + 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, + 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, + 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, + 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, + 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, + 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, + 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, + 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, + 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, + 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, + 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, + 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, + 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, + 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, + 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, + 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, + 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, + 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, + 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, + 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, + 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, + 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, + 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, + 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, + 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 + } + }, + { + 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, + 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, + 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, + 0x9216d5d9, 0x8979fb1b + } + }; - *c = bf_initstate; + *c = bf_initstate; } uint32_t Blowfish_stream2word(const uint8_t *data, uint16_t databytes, - uint16_t *current) + uint16_t *current) { - uint8_t i; - uint16_t j; - uint32_t temp; + uint8_t i; + uint16_t j; + uint32_t temp; - temp = 0x00000000; - j = *current; + temp = 0x00000000; + j = *current; - for (i = 0; i < 4; i++, j++) { - if (j >= databytes) - j = 0; - temp = (temp << 8) | data[j]; - } + for (i = 0; i < 4; i++, j++) { + if (j >= databytes) + j = 0; + temp = (temp << 8) | data[j]; + } - *current = j; - return temp; + *current = j; + return temp; } void Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes) { - uint16_t i; - uint16_t j; - uint16_t k; - uint32_t temp; - uint32_t datal; - uint32_t datar; + uint16_t i; + uint16_t j; + uint16_t k; + uint32_t temp; + uint32_t datal; + uint32_t datar; - j = 0; - for (i = 0; i < BLF_N + 2; i++) { - /* Extract 4 int8 to 1 int32 from keystream */ - temp = Blowfish_stream2word(key, keybytes, &j); - c->P[i] = c->P[i] ^ temp; - } + j = 0; + for (i = 0; i < BLF_N + 2; i++) { + /* Extract 4 int8 to 1 int32 from keystream */ + temp = Blowfish_stream2word(key, keybytes, &j); + c->P[i] = c->P[i] ^ temp; + } - j = 0; - datal = 0x00000000; - datar = 0x00000000; - for (i = 0; i < BLF_N + 2; i += 2) { - Blowfish_encipher(c, &datal, &datar); + j = 0; + datal = 0x00000000; + datar = 0x00000000; + for (i = 0; i < BLF_N + 2; i += 2) { + Blowfish_encipher(c, &datal, &datar); - c->P[i] = datal; - c->P[i + 1] = datar; - } + c->P[i] = datal; + c->P[i + 1] = datar; + } - for (i = 0; i < 4; i++) { - for (k = 0; k < 256; k += 2) { - Blowfish_encipher(c, &datal, &datar); + for (i = 0; i < 4; i++) { + for (k = 0; k < 256; k += 2) { + Blowfish_encipher(c, &datal, &datar); - c->S[i][k] = datal; - c->S[i][k + 1] = datar; - } - } + c->S[i][k] = datal; + c->S[i][k + 1] = datar; + } + } } void Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes, - const uint8_t *key, uint16_t keybytes) + const uint8_t *key, uint16_t keybytes) { - uint16_t i; - uint16_t j; - uint16_t k; - uint32_t temp; - uint32_t datal; - uint32_t datar; + uint16_t i; + uint16_t j; + uint16_t k; + uint32_t temp; + uint32_t datal; + uint32_t datar; - j = 0; - for (i = 0; i < BLF_N + 2; i++) { - /* Extract 4 int8 to 1 int32 from keystream */ - temp = Blowfish_stream2word(key, keybytes, &j); - c->P[i] = c->P[i] ^ temp; - } + j = 0; + for (i = 0; i < BLF_N + 2; i++) { + /* Extract 4 int8 to 1 int32 from keystream */ + temp = Blowfish_stream2word(key, keybytes, &j); + c->P[i] = c->P[i] ^ temp; + } - j = 0; - datal = 0x00000000; - datar = 0x00000000; - for (i = 0; i < BLF_N + 2; i += 2) { - datal ^= Blowfish_stream2word(data, databytes, &j); - datar ^= Blowfish_stream2word(data, databytes, &j); - Blowfish_encipher(c, &datal, &datar); + j = 0; + datal = 0x00000000; + datar = 0x00000000; + for (i = 0; i < BLF_N + 2; i += 2) { + datal ^= Blowfish_stream2word(data, databytes, &j); + datar ^= Blowfish_stream2word(data, databytes, &j); + Blowfish_encipher(c, &datal, &datar); - c->P[i] = datal; - c->P[i + 1] = datar; - } + c->P[i] = datal; + c->P[i + 1] = datar; + } - for (i = 0; i < 4; i++) { - for (k = 0; k < 256; k += 2) { - datal ^= Blowfish_stream2word(data, databytes, &j); - datar ^= Blowfish_stream2word(data, databytes, &j); - Blowfish_encipher(c, &datal, &datar); + for (i = 0; i < 4; i++) { + for (k = 0; k < 256; k += 2) { + datal ^= Blowfish_stream2word(data, databytes, &j); + datar ^= Blowfish_stream2word(data, databytes, &j); + Blowfish_encipher(c, &datal, &datar); - c->S[i][k] = datal; - c->S[i][k + 1] = datar; - } - } + c->S[i][k] = datal; + c->S[i][k + 1] = datar; + } + } } void blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks) { - uint32_t *d; - uint16_t i; + uint32_t *d; + uint16_t i; - d = data; - for (i = 0; i < blocks; i++) { - Blowfish_encipher(c, d, d + 1); - d += 2; - } + d = data; + for (i = 0; i < blocks; i++) { + Blowfish_encipher(c, d, d + 1); + d += 2; + } } /* This password hashing algorithm was designed by David Mazieres @@ -2855,59 +2808,58 @@ static char encrypted[512]; /* Shouldn't grow more than this */ static char error[] = ":"; static const uint8_t Base64Code[] = -"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; -static const uint8_t index_64[128] = -{ - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, - 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 255, 255, 255, 255, 255, 255, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 255, 255, 255, 255, 255 +static const uint8_t index_64[128] = { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, + 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 255, 255, 255, 255, 255, 255, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 255, 255, 255, 255, 255 }; #define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)]) static void decode_base64(uint8_t *buffer, uint16_t len, const uint8_t *data) { - uint8_t *bp = buffer; - const uint8_t *p = data; - uint8_t c1, c2, c3, c4; - while (bp < buffer + len) { - c1 = CHAR64(*p); - c2 = CHAR64(*(p + 1)); + uint8_t *bp = buffer; + const uint8_t *p = data; + uint8_t c1, c2, c3, c4; + while (bp < buffer + len) { + c1 = CHAR64(*p); + c2 = CHAR64(*(p + 1)); - /* Invalid data */ - if (c1 == 255 || c2 == 255) - break; + /* Invalid data */ + if (c1 == 255 || c2 == 255) + break; - *bp++ = (uint8_t)((c1 << 2) | ((c2 & 0x30) >> 4)); - if (bp >= buffer + len) - break; + *bp++ = (uint8_t)((c1 << 2) | ((c2 & 0x30) >> 4)); + if (bp >= buffer + len) + break; - c3 = CHAR64(*(p + 2)); - if (c3 == 255) - break; + c3 = CHAR64(*(p + 2)); + if (c3 == 255) + break; - *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); - if (bp >= buffer + len) - break; + *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); + if (bp >= buffer + len) + break; - c4 = CHAR64(*(p + 3)); - if (c4 == 255) - break; - *bp++ = ((c3 & 0x03) << 6) | c4; + c4 = CHAR64(*(p + 3)); + if (c4 == 255) + break; + *bp++ = ((c3 & 0x03) << 6) | c4; - p += 4; - } + p += 4; + } } /* We handle $Vers$log2(NumRounds)$salt+passwd$ @@ -2916,141 +2868,140 @@ decode_base64(uint8_t *buffer, uint16_t len, const uint8_t *data) char * rb_blowfish_crypt(const char *key, const char *salt) { - blf_ctx state; - uint32_t rounds, i, k; - uint16_t j; - uint8_t key_len, salt_len, logr, minr; - uint8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; - uint8_t csalt[BCRYPT_MAXSALT]; - uint32_t cdata[BCRYPT_BLOCKS]; - static const char *magic = "$2a$04$"; + blf_ctx state; + uint32_t rounds, i, k; + uint16_t j; + uint8_t key_len, salt_len, logr, minr; + uint8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; + uint8_t csalt[BCRYPT_MAXSALT]; + uint32_t cdata[BCRYPT_BLOCKS]; + static const char *magic = "$2a$04$"; - /* Defaults */ - minr = 'a'; - logr = 4; - rounds = 1 << logr; + /* Defaults */ + minr = 'a'; + logr = 4; + rounds = 1 << logr; - /* If it starts with the magic string, then skip that */ - if(!strncmp(salt, magic, strlen(magic))) { - salt += strlen(magic); - } - else if (*salt == '$') { + /* If it starts with the magic string, then skip that */ + if(!strncmp(salt, magic, strlen(magic))) { + salt += strlen(magic); + } else if (*salt == '$') { - /* Discard "$" identifier */ - salt++; + /* Discard "$" identifier */ + salt++; - if (*salt > BCRYPT_VERSION) { - /* How do I handle errors ? Return ':' */ - return error; - } + if (*salt > BCRYPT_VERSION) { + /* How do I handle errors ? Return ':' */ + return error; + } - /* Check for minor versions */ - if (salt[1] != '$') { - switch (salt[1]) { - case 'a': - /* 'ab' should not yield the same as 'abab' */ - minr = (uint8_t)salt[1]; - salt++; - break; - default: - return error; - } - } else - minr = 0; + /* Check for minor versions */ + if (salt[1] != '$') { + switch (salt[1]) { + case 'a': + /* 'ab' should not yield the same as 'abab' */ + minr = (uint8_t)salt[1]; + salt++; + break; + default: + return error; + } + } else + minr = 0; - /* Discard version + "$" identifier */ - salt += 2; + /* Discard version + "$" identifier */ + salt += 2; - if (salt[2] != '$') - /* Out of sync with passwd entry */ - return error; + if (salt[2] != '$') + /* Out of sync with passwd entry */ + return error; - /* Computer power doesnt increase linear, 2^x should be fine */ - logr = (uint8_t)atoi(salt); - rounds = 1 << logr; - if (rounds < BCRYPT_MINROUNDS) - return error; + /* Computer power doesnt increase linear, 2^x should be fine */ + logr = (uint8_t)atoi(salt); + rounds = 1 << logr; + if (rounds < BCRYPT_MINROUNDS) + return error; - /* Discard num rounds + "$" identifier */ - salt += 3; - } + /* Discard num rounds + "$" identifier */ + salt += 3; + } - /* We dont want the base64 salt but the raw data */ - decode_base64(csalt, BCRYPT_MAXSALT, (const uint8_t *)salt); - salt_len = BCRYPT_MAXSALT; - key_len = (uint8_t)(strlen(key) + (minr >= 'a' ? 1 : 0)); + /* We dont want the base64 salt but the raw data */ + decode_base64(csalt, BCRYPT_MAXSALT, (const uint8_t *)salt); + salt_len = BCRYPT_MAXSALT; + key_len = (uint8_t)(strlen(key) + (minr >= 'a' ? 1 : 0)); - /* Setting up S-Boxes and Subkeys */ - Blowfish_initstate(&state); - Blowfish_expandstate(&state, csalt, salt_len, - (const uint8_t *) key, key_len); - for (k = 0; k < rounds; k++) { - Blowfish_expand0state(&state, (const uint8_t *) key, key_len); - Blowfish_expand0state(&state, csalt, salt_len); - } + /* Setting up S-Boxes and Subkeys */ + Blowfish_initstate(&state); + Blowfish_expandstate(&state, csalt, salt_len, + (const uint8_t *) key, key_len); + for (k = 0; k < rounds; k++) { + Blowfish_expand0state(&state, (const uint8_t *) key, key_len); + Blowfish_expand0state(&state, csalt, salt_len); + } - /* This can be precomputed later */ - j = 0; - for (i = 0; i < BCRYPT_BLOCKS; i++) - cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_BLOCKS, &j); + /* This can be precomputed later */ + j = 0; + for (i = 0; i < BCRYPT_BLOCKS; i++) + cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_BLOCKS, &j); - /* Now do the encryption */ - for (k = 0; k < 64; k++) - blf_enc(&state, cdata, BCRYPT_BLOCKS / 2); + /* Now do the encryption */ + for (k = 0; k < 64; k++) + blf_enc(&state, cdata, BCRYPT_BLOCKS / 2); - for (i = 0; i < BCRYPT_BLOCKS; i++) { - ciphertext[4 * i + 3] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 2] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 1] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 0] = cdata[i] & 0xff; - } + for (i = 0; i < BCRYPT_BLOCKS; i++) { + ciphertext[4 * i + 3] = cdata[i] & 0xff; + cdata[i] = cdata[i] >> 8; + ciphertext[4 * i + 2] = cdata[i] & 0xff; + cdata[i] = cdata[i] >> 8; + ciphertext[4 * i + 1] = cdata[i] & 0xff; + cdata[i] = cdata[i] >> 8; + ciphertext[4 * i + 0] = cdata[i] & 0xff; + } - i = 0; - encrypted[i++] = '$'; - encrypted[i++] = BCRYPT_VERSION; - if (minr) - encrypted[i++] = (int8_t)minr; - encrypted[i++] = '$'; + i = 0; + encrypted[i++] = '$'; + encrypted[i++] = BCRYPT_VERSION; + if (minr) + encrypted[i++] = (int8_t)minr; + encrypted[i++] = '$'; - snprintf(encrypted + i, 4, "%2.2u$", logr); + snprintf(encrypted + i, 4, "%2.2u$", logr); - encode_base64((uint8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); - encode_base64((uint8_t *) encrypted + strlen(encrypted), ciphertext, - 4 * BCRYPT_BLOCKS - 1); - return encrypted; + encode_base64((uint8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); + encode_base64((uint8_t *) encrypted + strlen(encrypted), ciphertext, + 4 * BCRYPT_BLOCKS - 1); + return encrypted; } static void encode_base64(uint8_t *buffer, uint8_t *data, uint16_t len) { - uint8_t *bp = buffer; - uint8_t *p = data; - uint8_t c1, c2; - while (p < data + len) { - c1 = *p++; - *bp++ = Base64Code[(c1 >> 2)]; - c1 = (c1 & 0x03) << 4; - if (p >= data + len) { - *bp++ = Base64Code[c1]; - break; - } - c2 = *p++; - c1 |= (c2 >> 4) & 0x0f; - *bp++ = Base64Code[c1]; - c1 = (c2 & 0x0f) << 2; - if (p >= data + len) { - *bp++ = Base64Code[c1]; - break; - } - c2 = *p++; - c1 |= (c2 >> 6) & 0x03; - *bp++ = Base64Code[c1]; - *bp++ = Base64Code[c2 & 0x3f]; - } - *bp = '\0'; + uint8_t *bp = buffer; + uint8_t *p = data; + uint8_t c1, c2; + while (p < data + len) { + c1 = *p++; + *bp++ = Base64Code[(c1 >> 2)]; + c1 = (c1 & 0x03) << 4; + if (p >= data + len) { + *bp++ = Base64Code[c1]; + break; + } + c2 = *p++; + c1 |= (c2 >> 4) & 0x0f; + *bp++ = Base64Code[c1]; + c1 = (c2 & 0x0f) << 2; + if (p >= data + len) { + *bp++ = Base64Code[c1]; + break; + } + c2 = *p++; + c1 |= (c2 >> 6) & 0x03; + *bp++ = Base64Code[c1]; + *bp++ = Base64Code[c2 & 0x3f]; + } + *bp = '\0'; } diff --git a/libratbox/src/devpoll.c b/libratbox/src/devpoll.c index 58770d9..638d267 100644 --- a/libratbox/src/devpoll.c +++ b/libratbox/src/devpoll.c @@ -41,7 +41,7 @@ static void devpoll_write_update(int, int); int rb_setup_fd_devpoll(rb_fde_t *F) { - return 0; + return 0; } @@ -54,76 +54,72 @@ rb_setup_fd_devpoll(rb_fde_t *F) static void devpoll_write_update(int fd, int events) { - struct pollfd pollfds[1]; /* Just to be careful */ - int retval; + struct pollfd pollfds[1]; /* Just to be careful */ + int retval; - /* Build the pollfd entry */ - pollfds[0].revents = 0; - pollfds[0].fd = fd; - pollfds[0].events = events; + /* Build the pollfd entry */ + pollfds[0].revents = 0; + pollfds[0].fd = fd; + pollfds[0].events = events; - /* Write the thing to our poll fd */ - retval = write(dpfd, &pollfds[0], sizeof(struct pollfd)); - if(retval != sizeof(struct pollfd)) - rb_lib_log("devpoll_write_update: dpfd write failed %d: %s", errno, - strerror(errno)); - /* Done! */ + /* Write the thing to our poll fd */ + retval = write(dpfd, &pollfds[0], sizeof(struct pollfd)); + if(retval != sizeof(struct pollfd)) + rb_lib_log("devpoll_write_update: dpfd write failed %d: %s", errno, + strerror(errno)); + /* Done! */ } static void devpoll_update_events(rb_fde_t *F, short filter, PF * handler) { - int update_required = 0; - int fd = rb_get_fd(F); - int cur_mask = fdmask[fd]; - PF *cur_handler; - fdmask[fd] = 0; - switch (filter) - { - case RB_SELECT_READ: - cur_handler = F->read_handler; - if(handler) - fdmask[fd] |= POLLRDNORM; - else - fdmask[fd] &= ~POLLRDNORM; - if(F->write_handler) - fdmask[fd] |= POLLWRNORM; - break; - case RB_SELECT_WRITE: - cur_handler = F->write_handler; - if(handler) - fdmask[fd] |= POLLWRNORM; - else - fdmask[fd] &= ~POLLWRNORM; - if(F->read_handler) - fdmask[fd] |= POLLRDNORM; - break; - default: - return; - break; - } + int update_required = 0; + int fd = rb_get_fd(F); + int cur_mask = fdmask[fd]; + PF *cur_handler; + fdmask[fd] = 0; + switch (filter) { + case RB_SELECT_READ: + cur_handler = F->read_handler; + if(handler) + fdmask[fd] |= POLLRDNORM; + else + fdmask[fd] &= ~POLLRDNORM; + if(F->write_handler) + fdmask[fd] |= POLLWRNORM; + break; + case RB_SELECT_WRITE: + cur_handler = F->write_handler; + if(handler) + fdmask[fd] |= POLLWRNORM; + else + fdmask[fd] &= ~POLLWRNORM; + if(F->read_handler) + fdmask[fd] |= POLLRDNORM; + break; + default: + return; + break; + } - if(cur_handler == NULL && handler != NULL) - update_required++; - else if(cur_handler != NULL && handler == NULL) - update_required++; - if(cur_mask != fdmask[fd]) - update_required++; - if(update_required) - { - /* - * Ok, we can call devpoll_write_update() here now to re-build the - * fd struct. If we end up with nothing on this fd, it won't write - * anything. - */ - if(fdmask[fd]) - { - devpoll_write_update(fd, POLLREMOVE); - devpoll_write_update(fd, fdmask[fd]); - } - else - devpoll_write_update(fd, POLLREMOVE); - } + if(cur_handler == NULL && handler != NULL) + update_required++; + else if(cur_handler != NULL && handler == NULL) + update_required++; + if(cur_mask != fdmask[fd]) + update_required++; + if(update_required) { + /* + * Ok, we can call devpoll_write_update() here now to re-build the + * fd struct. If we end up with nothing on this fd, it won't write + * anything. + */ + if(fdmask[fd]) { + devpoll_write_update(fd, POLLREMOVE); + devpoll_write_update(fd, fdmask[fd]); + } else + devpoll_write_update(fd, POLLREMOVE); + } } @@ -143,15 +139,14 @@ devpoll_update_events(rb_fde_t *F, short filter, PF * handler) int rb_init_netio_devpoll(void) { - dpfd = open("/dev/poll", O_RDWR); - if(dpfd < 0) - { - return errno; - } - maxfd = getdtablesize() - 2; /* This makes more sense than HARD_FDLIMIT */ - fdmask = rb_malloc(sizeof(fdmask) * maxfd + 1); - rb_open(dpfd, RB_FD_UNKNOWN, "/dev/poll file descriptor"); - return 0; + dpfd = open("/dev/poll", O_RDWR); + if(dpfd < 0) { + return errno; + } + maxfd = getdtablesize() - 2; /* This makes more sense than HARD_FDLIMIT */ + fdmask = rb_malloc(sizeof(fdmask) * maxfd + 1); + rb_open(dpfd, RB_FD_UNKNOWN, "/dev/poll file descriptor"); + return 0; } /* @@ -163,20 +158,18 @@ rb_init_netio_devpoll(void) void rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - lrb_assert(IsFDOpen(F)); + lrb_assert(IsFDOpen(F)); - if(type & RB_SELECT_READ) - { - devpoll_update_events(F, RB_SELECT_READ, handler); - F->read_handler = handler; - F->read_data = client_data; - } - if(type & RB_SELECT_WRITE) - { - devpoll_update_events(F, RB_SELECT_WRITE, handler); - F->write_handler = handler; - F->write_data = client_data; - } + if(type & RB_SELECT_READ) { + devpoll_update_events(F, RB_SELECT_READ, handler); + F->read_handler = handler; + F->read_data = client_data; + } + if(type & RB_SELECT_WRITE) { + devpoll_update_events(F, RB_SELECT_WRITE, handler); + F->write_handler = handler; + F->write_data = client_data; + } } /* @@ -197,102 +190,94 @@ rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_ int rb_select_devpoll(long delay) { - int num, i; - struct pollfd pollfds[maxfd]; - struct dvpoll dopoll; + int num, i; + struct pollfd pollfds[maxfd]; + struct dvpoll dopoll; - do - { - for(;;) - { - dopoll.dp_timeout = delay; - dopoll.dp_nfds = maxfd; - dopoll.dp_fds = &pollfds[0]; - num = ioctl(dpfd, DP_POLL, &dopoll); - if(num >= 0) - break; - if(rb_ignore_errno(errno)) - break; - rb_set_time(); - return RB_ERROR; - } + do { + for(;;) { + dopoll.dp_timeout = delay; + dopoll.dp_nfds = maxfd; + dopoll.dp_fds = &pollfds[0]; + num = ioctl(dpfd, DP_POLL, &dopoll); + if(num >= 0) + break; + if(rb_ignore_errno(errno)) + break; + rb_set_time(); + return RB_ERROR; + } - rb_set_time(); - if(num == 0) - continue; + rb_set_time(); + if(num == 0) + continue; - for(i = 0; i < num; i++) - { - int fd = dopoll.dp_fds[i].fd; - PF *hdl = NULL; - rb_fde_t *F = rb_find_fd(fd); - if((dopoll.dp_fds[i].revents & (POLLRDNORM | POLLIN | POLLHUP | - POLLERR)) - && (dopoll.dp_fds[i].events & (POLLRDNORM | POLLIN))) - { - if((hdl = F->read_handler) != NULL) - { - F->read_handler = NULL; - hdl(F, F->read_data); - /* - * this call used to be with a NULL pointer, BUT - * in the devpoll case we only want to update the - * poll set *if* the handler changes state (active -> - * NULL or vice versa.) - */ - devpoll_update_events(F, RB_SELECT_READ, F->read_handler); - } - } + for(i = 0; i < num; i++) { + int fd = dopoll.dp_fds[i].fd; + PF *hdl = NULL; + rb_fde_t *F = rb_find_fd(fd); + if((dopoll.dp_fds[i].revents & (POLLRDNORM | POLLIN | POLLHUP | + POLLERR)) + && (dopoll.dp_fds[i].events & (POLLRDNORM | POLLIN))) { + if((hdl = F->read_handler) != NULL) { + F->read_handler = NULL; + hdl(F, F->read_data); + /* + * this call used to be with a NULL pointer, BUT + * in the devpoll case we only want to update the + * poll set *if* the handler changes state (active -> + * NULL or vice versa.) + */ + devpoll_update_events(F, RB_SELECT_READ, F->read_handler); + } + } - if(!IsFDOpen(F)) - continue; /* Read handler closed us..go on to do something more useful */ - if((dopoll.dp_fds[i].revents & (POLLWRNORM | POLLOUT | POLLHUP | - POLLERR)) - && (dopoll.dp_fds[i].events & (POLLWRNORM | POLLOUT))) - { - if((hdl = F->write_handler) != NULL) - { - F->write_handler = NULL; - hdl(F, F->write_data); - /* See above similar code in the read case */ - devpoll_update_events(F, - RB_SELECT_WRITE, F->write_handler); - } + if(!IsFDOpen(F)) + continue; /* Read handler closed us..go on to do something more useful */ + if((dopoll.dp_fds[i].revents & (POLLWRNORM | POLLOUT | POLLHUP | + POLLERR)) + && (dopoll.dp_fds[i].events & (POLLWRNORM | POLLOUT))) { + if((hdl = F->write_handler) != NULL) { + F->write_handler = NULL; + hdl(F, F->write_data); + /* See above similar code in the read case */ + devpoll_update_events(F, + RB_SELECT_WRITE, F->write_handler); + } - } - } - return RB_OK; - } - while(0); - /* XXX Get here, we broke! */ - return 0; + } + } + return RB_OK; + } while(0); + /* XXX Get here, we broke! */ + return 0; } #else /* /dev/poll not supported */ int rb_init_netio_devpoll(void) { - return ENOSYS; + return ENOSYS; } void rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_devpoll(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_devpoll(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif diff --git a/libratbox/src/epoll.c b/libratbox/src/epoll.c index b6c4e28..28d85ec 100644 --- a/libratbox/src/epoll.c +++ b/libratbox/src/epoll.c @@ -47,11 +47,10 @@ #endif #define RTSIGNAL SIGRTMIN -struct epoll_info -{ - int ep; - struct epoll_event *pfd; - int pfd_size; +struct epoll_info { + int ep; + struct epoll_event *pfd; + int pfd_size; }; static struct epoll_info *ep_info; @@ -67,25 +66,24 @@ static int can_do_timerfd; int rb_init_netio_epoll(void) { - can_do_event = 0; /* shut up gcc */ - can_do_timerfd = 0; - ep_info = rb_malloc(sizeof(struct epoll_info)); - ep_info->pfd_size = getdtablesize(); - ep_info->ep = epoll_create(ep_info->pfd_size); - if(ep_info->ep < 0) - { - return -1; - } - rb_open(ep_info->ep, RB_FD_UNKNOWN, "epoll file descriptor"); - ep_info->pfd = rb_malloc(sizeof(struct epoll_event) * ep_info->pfd_size); + can_do_event = 0; /* shut up gcc */ + can_do_timerfd = 0; + ep_info = rb_malloc(sizeof(struct epoll_info)); + ep_info->pfd_size = getdtablesize(); + ep_info->ep = epoll_create(ep_info->pfd_size); + if(ep_info->ep < 0) { + return -1; + } + rb_open(ep_info->ep, RB_FD_UNKNOWN, "epoll file descriptor"); + ep_info->pfd = rb_malloc(sizeof(struct epoll_event) * ep_info->pfd_size); - return 0; + return 0; } int rb_setup_fd_epoll(rb_fde_t *F) { - return 0; + return 0; } @@ -98,56 +96,53 @@ rb_setup_fd_epoll(rb_fde_t *F) void rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - struct epoll_event ep_event; - int old_flags = F->pflags; - int op = -1; + struct epoll_event ep_event; + int old_flags = F->pflags; + int op = -1; - lrb_assert(IsFDOpen(F)); + lrb_assert(IsFDOpen(F)); - /* Update the list, even though we're not using it .. */ - if(type & RB_SELECT_READ) - { - if(handler != NULL) - F->pflags |= EPOLLIN; - else - F->pflags &= ~EPOLLIN; - F->read_handler = handler; - F->read_data = client_data; - } + /* Update the list, even though we're not using it .. */ + if(type & RB_SELECT_READ) { + if(handler != NULL) + F->pflags |= EPOLLIN; + else + F->pflags &= ~EPOLLIN; + F->read_handler = handler; + F->read_data = client_data; + } - if(type & RB_SELECT_WRITE) - { - if(handler != NULL) - F->pflags |= EPOLLOUT; - else - F->pflags &= ~EPOLLOUT; - F->write_handler = handler; - F->write_data = client_data; - } + if(type & RB_SELECT_WRITE) { + if(handler != NULL) + F->pflags |= EPOLLOUT; + else + F->pflags &= ~EPOLLOUT; + F->write_handler = handler; + F->write_data = client_data; + } - if(old_flags == 0 && F->pflags == 0) - return; - else if(F->pflags <= 0) - op = EPOLL_CTL_DEL; - else if(old_flags == 0 && F->pflags > 0) - op = EPOLL_CTL_ADD; - else if(F->pflags != old_flags) - op = EPOLL_CTL_MOD; + if(old_flags == 0 && F->pflags == 0) + return; + else if(F->pflags <= 0) + op = EPOLL_CTL_DEL; + else if(old_flags == 0 && F->pflags > 0) + op = EPOLL_CTL_ADD; + else if(F->pflags != old_flags) + op = EPOLL_CTL_MOD; - if(op == -1) - return; + if(op == -1) + return; - ep_event.events = F->pflags; - ep_event.data.ptr = F; + ep_event.events = F->pflags; + ep_event.data.ptr = F; - if(op == EPOLL_CTL_ADD || op == EPOLL_CTL_MOD) - ep_event.events |= EPOLLET; + if(op == EPOLL_CTL_ADD || op == EPOLL_CTL_MOD) + ep_event.events |= EPOLLET; - if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) - { - rb_lib_log("rb_setselect_epoll(): epoll_ctl failed: %s", strerror(errno)); - abort(); - } + if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) { + rb_lib_log("rb_setselect_epoll(): epoll_ctl failed: %s", strerror(errno)); + abort(); + } } @@ -164,162 +159,150 @@ rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_da int rb_select_epoll(long delay) { - int num, i, flags, old_flags, op; - struct epoll_event ep_event; - int o_errno; - void *data; + int num, i, flags, old_flags, op; + struct epoll_event ep_event; + int o_errno; + void *data; - num = epoll_wait(ep_info->ep, ep_info->pfd, ep_info->pfd_size, delay); + num = epoll_wait(ep_info->ep, ep_info->pfd, ep_info->pfd_size, delay); - /* save errno as rb_set_time() will likely clobber it */ - o_errno = errno; - rb_set_time(); - errno = o_errno; + /* save errno as rb_set_time() will likely clobber it */ + o_errno = errno; + rb_set_time(); + errno = o_errno; - if(num < 0 && !rb_ignore_errno(o_errno)) - return RB_ERROR; + if(num < 0 && !rb_ignore_errno(o_errno)) + return RB_ERROR; - if(num <= 0) - return RB_OK; + if(num <= 0) + return RB_OK; - for(i = 0; i < num; i++) - { - PF *hdl; - rb_fde_t *F = ep_info->pfd[i].data.ptr; - old_flags = F->pflags; - if(ep_info->pfd[i].events & (EPOLLIN | EPOLLHUP | EPOLLERR)) - { - hdl = F->read_handler; - data = F->read_data; - F->read_handler = NULL; - F->read_data = NULL; - if(hdl) - { - hdl(F, data); - } - } + for(i = 0; i < num; i++) { + PF *hdl; + rb_fde_t *F = ep_info->pfd[i].data.ptr; + old_flags = F->pflags; + if(ep_info->pfd[i].events & (EPOLLIN | EPOLLHUP | EPOLLERR)) { + hdl = F->read_handler; + data = F->read_data; + F->read_handler = NULL; + F->read_data = NULL; + if(hdl) { + hdl(F, data); + } + } - if(!IsFDOpen(F)) - continue; - if(ep_info->pfd[i].events & (EPOLLOUT | EPOLLHUP | EPOLLERR)) - { - hdl = F->write_handler; - data = F->write_data; - F->write_handler = NULL; - F->write_data = NULL; + if(!IsFDOpen(F)) + continue; + if(ep_info->pfd[i].events & (EPOLLOUT | EPOLLHUP | EPOLLERR)) { + hdl = F->write_handler; + data = F->write_data; + F->write_handler = NULL; + F->write_data = NULL; - if(hdl) - { - hdl(F, data); - } - } + if(hdl) { + hdl(F, data); + } + } - if(!IsFDOpen(F)) - continue; + if(!IsFDOpen(F)) + continue; - flags = 0; + flags = 0; - if(F->read_handler != NULL) - flags |= EPOLLIN; - if(F->write_handler != NULL) - flags |= EPOLLOUT; + if(F->read_handler != NULL) + flags |= EPOLLIN; + if(F->write_handler != NULL) + flags |= EPOLLOUT; - if(old_flags != flags) - { - if(flags == 0) - op = EPOLL_CTL_DEL; - else - op = EPOLL_CTL_MOD; - F->pflags = ep_event.events = flags; - ep_event.data.ptr = F; - if(op == EPOLL_CTL_MOD || op == EPOLL_CTL_ADD) - ep_event.events |= EPOLLET; + if(old_flags != flags) { + if(flags == 0) + op = EPOLL_CTL_DEL; + else + op = EPOLL_CTL_MOD; + F->pflags = ep_event.events = flags; + ep_event.data.ptr = F; + if(op == EPOLL_CTL_MOD || op == EPOLL_CTL_ADD) + ep_event.events |= EPOLLET; - if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) - { - rb_lib_log("rb_select_epoll(): epoll_ctl failed: %s", - strerror(errno)); - } - } + if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) { + rb_lib_log("rb_select_epoll(): epoll_ctl failed: %s", + strerror(errno)); + } + } - } - return RB_OK; + } + return RB_OK; } #ifdef EPOLL_SCHED_EVENT int rb_epoll_supports_event(void) { - /* try to detect at runtime if everything we need actually works */ - timer_t timer; - struct sigevent ev; - struct stat st; - int fd; - sigset_t set; + /* try to detect at runtime if everything we need actually works */ + timer_t timer; + struct sigevent ev; + struct stat st; + int fd; + sigset_t set; - if(can_do_event == 1) - return 1; - if(can_do_event == -1) - return 0; + if(can_do_event == 1) + return 1; + if(can_do_event == -1) + return 0; - /* Check for openvz..it has a broken timerfd.. */ - if(stat("/proc/user_beancounters", &st) == 0) - { - can_do_event = -1; - return 0; - } + /* Check for openvz..it has a broken timerfd.. */ + if(stat("/proc/user_beancounters", &st) == 0) { + can_do_event = -1; + return 0; + } #ifdef USE_TIMERFD_CREATE - if((fd = timerfd_create(CLOCK_REALTIME, 0)) >= 0) - { - close(fd); - can_do_event = 1; - can_do_timerfd = 1; - return 1; - } + if((fd = timerfd_create(CLOCK_REALTIME, 0)) >= 0) { + close(fd); + can_do_event = 1; + can_do_timerfd = 1; + return 1; + } #endif - ev.sigev_signo = SIGVTALRM; - ev.sigev_notify = SIGEV_SIGNAL; - if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) - { - can_do_event = -1; - return 0; - } - timer_delete(timer); - sigemptyset(&set); - fd = signalfd(-1, &set, 0); - if(fd < 0) - { - can_do_event = -1; - return 0; - } - close(fd); - can_do_event = 1; - return 1; + ev.sigev_signo = SIGVTALRM; + ev.sigev_notify = SIGEV_SIGNAL; + if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) { + can_do_event = -1; + return 0; + } + timer_delete(timer); + sigemptyset(&set); + fd = signalfd(-1, &set, 0); + if(fd < 0) { + can_do_event = -1; + return 0; + } + close(fd); + can_do_event = 1; + return 1; } /* bleh..work around a glibc header bug on 32bit systems */ -struct our_signalfd_siginfo -{ - uint32_t signo; - int32_t err; - int32_t code; - uint32_t pid; - uint32_t uid; - int32_t fd; - uint32_t tid; - uint32_t band; - uint32_t overrun; - uint32_t trapno; - int32_t status; - int32_t svint; - uint64_t svptr; - uint64_t utime; - uint64_t stime; - uint64_t addr; - uint8_t pad[48]; +struct our_signalfd_siginfo { + uint32_t signo; + int32_t err; + int32_t code; + uint32_t pid; + uint32_t uid; + int32_t fd; + uint32_t tid; + uint32_t band; + uint32_t overrun; + uint32_t trapno; + int32_t status; + int32_t svint; + uint64_t svptr; + uint64_t utime; + uint64_t stime; + uint64_t addr; + uint8_t pad[48]; }; @@ -327,169 +310,156 @@ struct our_signalfd_siginfo static void signalfd_handler(rb_fde_t *F, void *data) { - static struct our_signalfd_siginfo fdsig[SIGFDIOV_COUNT]; - static struct iovec iov[SIGFDIOV_COUNT]; - struct ev_entry *ev; - int ret, x; + static struct our_signalfd_siginfo fdsig[SIGFDIOV_COUNT]; + static struct iovec iov[SIGFDIOV_COUNT]; + struct ev_entry *ev; + int ret, x; - for(x = 0; x < SIGFDIOV_COUNT; x++) - { - iov[x].iov_base = &fdsig[x]; - iov[x].iov_len = sizeof(struct our_signalfd_siginfo); - } + for(x = 0; x < SIGFDIOV_COUNT; x++) { + iov[x].iov_base = &fdsig[x]; + iov[x].iov_len = sizeof(struct our_signalfd_siginfo); + } - while(1) - { - ret = readv(rb_get_fd(F), iov, SIGFDIOV_COUNT); + while(1) { + ret = readv(rb_get_fd(F), iov, SIGFDIOV_COUNT); - if(ret == 0 || (ret < 0 && !rb_ignore_errno(errno))) - { - rb_close(F); - rb_epoll_init_event(); - return; - } + if(ret == 0 || (ret < 0 && !rb_ignore_errno(errno))) { + rb_close(F); + rb_epoll_init_event(); + return; + } - if(ret < 0) - { - rb_setselect(F, RB_SELECT_READ, signalfd_handler, NULL); - return; - } - for(x = 0; x < ret / (int)sizeof(struct our_signalfd_siginfo); x++) - { + if(ret < 0) { + rb_setselect(F, RB_SELECT_READ, signalfd_handler, NULL); + return; + } + for(x = 0; x < ret / (int)sizeof(struct our_signalfd_siginfo); x++) { #if __WORDSIZE == 32 && defined(__sparc__) - uint32_t *q = (uint32_t *)&fdsig[x].svptr; - ev = (struct ev_entry *)q[0]; + uint32_t *q = (uint32_t *)&fdsig[x].svptr; + ev = (struct ev_entry *)q[0]; #else - ev = (struct ev_entry *)(uintptr_t)(fdsig[x].svptr); + ev = (struct ev_entry *)(uintptr_t)(fdsig[x].svptr); #endif - if(ev == NULL) - continue; - rb_run_event(ev); - } - } + if(ev == NULL) + continue; + rb_run_event(ev); + } + } } void rb_epoll_init_event(void) { - sigset_t ss; - rb_fde_t *F; - int sfd; - rb_epoll_supports_event(); - if(!can_do_timerfd) - { - sigemptyset(&ss); - sigaddset(&ss, RTSIGNAL); - sigprocmask(SIG_BLOCK, &ss, 0); - sigemptyset(&ss); - sigaddset(&ss, RTSIGNAL); - sfd = signalfd(-1, &ss, 0); - if(sfd == -1) - { - can_do_event = -1; - return; - } - F = rb_open(sfd, RB_FD_UNKNOWN, "signalfd"); - rb_set_nb(F); - signalfd_handler(F, NULL); - } + sigset_t ss; + rb_fde_t *F; + int sfd; + rb_epoll_supports_event(); + if(!can_do_timerfd) { + sigemptyset(&ss); + sigaddset(&ss, RTSIGNAL); + sigprocmask(SIG_BLOCK, &ss, 0); + sigemptyset(&ss); + sigaddset(&ss, RTSIGNAL); + sfd = signalfd(-1, &ss, 0); + if(sfd == -1) { + can_do_event = -1; + return; + } + F = rb_open(sfd, RB_FD_UNKNOWN, "signalfd"); + rb_set_nb(F); + signalfd_handler(F, NULL); + } } static int rb_epoll_sched_event_signalfd(struct ev_entry *event, int when) { - timer_t *id; - struct sigevent ev; - struct itimerspec ts; + timer_t *id; + struct sigevent ev; + struct itimerspec ts; - memset(&ev, 0, sizeof(&ev)); - event->comm_ptr = rb_malloc(sizeof(timer_t)); - id = event->comm_ptr; - ev.sigev_notify = SIGEV_SIGNAL; - ev.sigev_signo = RTSIGNAL; - ev.sigev_value.sival_ptr = event; + memset(&ev, 0, sizeof(&ev)); + event->comm_ptr = rb_malloc(sizeof(timer_t)); + id = event->comm_ptr; + ev.sigev_notify = SIGEV_SIGNAL; + ev.sigev_signo = RTSIGNAL; + ev.sigev_value.sival_ptr = event; - if(timer_create(CLOCK_REALTIME, &ev, id) < 0) - { - rb_lib_log("timer_create: %s\n", strerror(errno)); - return 0; - } - memset(&ts, 0, sizeof(ts)); - ts.it_value.tv_sec = when; - ts.it_value.tv_nsec = 0; - if(event->frequency != 0) - ts.it_interval = ts.it_value; + if(timer_create(CLOCK_REALTIME, &ev, id) < 0) { + rb_lib_log("timer_create: %s\n", strerror(errno)); + return 0; + } + memset(&ts, 0, sizeof(ts)); + ts.it_value.tv_sec = when; + ts.it_value.tv_nsec = 0; + if(event->frequency != 0) + ts.it_interval = ts.it_value; - if(timer_settime(*id, 0, &ts, NULL) < 0) - { - rb_lib_log("timer_settime: %s\n", strerror(errno)); - return 0; - } - return 1; + if(timer_settime(*id, 0, &ts, NULL) < 0) { + rb_lib_log("timer_settime: %s\n", strerror(errno)); + return 0; + } + return 1; } #ifdef USE_TIMERFD_CREATE static void rb_read_timerfd(rb_fde_t *F, void *data) { - struct ev_entry *event = (struct ev_entry *)data; - int retlen; - uint64_t count; + struct ev_entry *event = (struct ev_entry *)data; + int retlen; + uint64_t count; - if(event == NULL) - { - rb_close(F); - return; - } + if(event == NULL) { + rb_close(F); + return; + } - retlen = rb_read(F, &count, sizeof(count)); + retlen = rb_read(F, &count, sizeof(count)); - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - rb_close(F); - rb_lib_log("rb_read_timerfd: timerfd[%s] closed on error: %s", event->name, - strerror(errno)); - return; - } - rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event); - rb_run_event(event); + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + rb_close(F); + rb_lib_log("rb_read_timerfd: timerfd[%s] closed on error: %s", event->name, + strerror(errno)); + return; + } + rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event); + rb_run_event(event); } static int rb_epoll_sched_event_timerfd(struct ev_entry *event, int when) { - struct itimerspec ts; - static char buf[FD_DESC_SZ + 8]; - int fd; - rb_fde_t *F; + struct itimerspec ts; + static char buf[FD_DESC_SZ + 8]; + int fd; + rb_fde_t *F; - if((fd = timerfd_create(CLOCK_REALTIME, 0)) < 0) - { - rb_lib_log("timerfd_create: %s\n", strerror(errno)); - return 0; - } + if((fd = timerfd_create(CLOCK_REALTIME, 0)) < 0) { + rb_lib_log("timerfd_create: %s\n", strerror(errno)); + return 0; + } - memset(&ts, 0, sizeof(ts)); - ts.it_value.tv_sec = when; - ts.it_value.tv_nsec = 0; - if(event->frequency != 0) - ts.it_interval = ts.it_value; + memset(&ts, 0, sizeof(ts)); + ts.it_value.tv_sec = when; + ts.it_value.tv_nsec = 0; + if(event->frequency != 0) + ts.it_interval = ts.it_value; - if(timerfd_settime(fd, 0, &ts, NULL) < 0) - { - rb_lib_log("timerfd_settime: %s\n", strerror(errno)); - close(fd); - return 0; - } - rb_snprintf(buf, sizeof(buf), "timerfd: %s", event->name); - F = rb_open(fd, RB_FD_UNKNOWN, buf); - rb_set_nb(F); - event->comm_ptr = F; - rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event); - return 1; + if(timerfd_settime(fd, 0, &ts, NULL) < 0) { + rb_lib_log("timerfd_settime: %s\n", strerror(errno)); + close(fd); + return 0; + } + rb_snprintf(buf, sizeof(buf), "timerfd: %s", event->name); + F = rb_open(fd, RB_FD_UNKNOWN, buf); + rb_set_nb(F); + event->comm_ptr = F; + rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event); + return 1; } #endif @@ -499,28 +469,26 @@ int rb_epoll_sched_event(struct ev_entry *event, int when) { #ifdef USE_TIMERFD_CREATE - if(can_do_timerfd) - { - return rb_epoll_sched_event_timerfd(event, when); - } + if(can_do_timerfd) { + return rb_epoll_sched_event_timerfd(event, when); + } #endif - return rb_epoll_sched_event_signalfd(event, when); + return rb_epoll_sched_event_signalfd(event, when); } void rb_epoll_unsched_event(struct ev_entry *event) { #ifdef USE_TIMERFD_CREATE - if(can_do_timerfd) - { - rb_close((rb_fde_t *)event->comm_ptr); - event->comm_ptr = NULL; - return; - } + if(can_do_timerfd) { + rb_close((rb_fde_t *)event->comm_ptr); + event->comm_ptr = NULL; + return; + } #endif - timer_delete(*((timer_t *) event->comm_ptr)); - rb_free(event->comm_ptr); - event->comm_ptr = NULL; + timer_delete(*((timer_t *) event->comm_ptr)); + rb_free(event->comm_ptr); + event->comm_ptr = NULL; } #endif /* EPOLL_SCHED_EVENT */ @@ -528,28 +496,28 @@ rb_epoll_unsched_event(struct ev_entry *event) int rb_init_netio_epoll(void) { - return ENOSYS; + return ENOSYS; } void rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_epoll(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_epoll(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } @@ -559,26 +527,26 @@ rb_setup_fd_epoll(rb_fde_t *F) void rb_epoll_init_event(void) { - return; + return; } int rb_epoll_sched_event(struct ev_entry *event, int when) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } void rb_epoll_unsched_event(struct ev_entry *event) { - return; + return; } int rb_epoll_supports_event(void) { - errno = ENOSYS; - return 0; + errno = ENOSYS; + return 0; } #endif /* !USING_EPOLL || !EPOLL_SCHED_EVENT */ diff --git a/libratbox/src/event.c b/libratbox/src/event.c index 58d5adb..2716b33 100644 --- a/libratbox/src/event.c +++ b/libratbox/src/event.c @@ -53,7 +53,7 @@ static rb_dlink_list event_list; static time_t event_time_min = -1; /* - * struct ev_entry * + * struct ev_entry * * rb_event_find(EVH *func, void *arg) * * Input: Event function and the argument passed to it @@ -63,20 +63,19 @@ static time_t event_time_min = -1; static struct ev_entry * rb_event_find(EVH * func, void *arg) { - rb_dlink_node *ptr; - struct ev_entry *ev; - RB_DLINK_FOREACH(ptr, event_list.head) - { - ev = ptr->data; - if((ev->func == func) && (ev->arg == arg)) - return ev; - } + rb_dlink_node *ptr; + struct ev_entry *ev; + RB_DLINK_FOREACH(ptr, event_list.head) { + ev = ptr->data; + if((ev->func == func) && (ev->arg == arg)) + return ev; + } - return NULL; + return NULL; } /* - * struct ev_entry * + * struct ev_entry * * rb_event_add(const char *name, EVH *func, void *arg, time_t when) * * Input: Name of event, function to call, arguments to pass, and frequency @@ -87,42 +86,41 @@ rb_event_find(EVH * func, void *arg) struct ev_entry * rb_event_add(const char *name, EVH * func, void *arg, time_t when) { - struct ev_entry *ev; - ev = rb_malloc(sizeof(struct ev_entry)); - ev->func = func; - ev->name = rb_strndup(name, EV_NAME_LEN); - ev->arg = arg; - ev->when = rb_current_time() + when; - ev->next = when; - ev->frequency = when; + struct ev_entry *ev; + ev = rb_malloc(sizeof(struct ev_entry)); + ev->func = func; + ev->name = rb_strndup(name, EV_NAME_LEN); + ev->arg = arg; + ev->when = rb_current_time() + when; + ev->next = when; + ev->frequency = when; - if((ev->when < event_time_min) || (event_time_min == -1)) - { - event_time_min = ev->when; - } - rb_dlinkAdd(ev, &ev->node, &event_list); - rb_io_sched_event(ev, when); - return ev; + if((ev->when < event_time_min) || (event_time_min == -1)) { + event_time_min = ev->when; + } + rb_dlinkAdd(ev, &ev->node, &event_list); + rb_io_sched_event(ev, when); + return ev; } struct ev_entry * rb_event_addonce(const char *name, EVH * func, void *arg, time_t when) { - struct ev_entry *ev; - ev = rb_malloc(sizeof(struct ev_entry)); - ev->func = func; - ev->name = rb_strndup(name, EV_NAME_LEN); - ev->arg = arg; - ev->when = rb_current_time() + when; - ev->next = when; - ev->frequency = 0; + struct ev_entry *ev; + ev = rb_malloc(sizeof(struct ev_entry)); + ev->func = func; + ev->name = rb_strndup(name, EV_NAME_LEN); + ev->arg = arg; + ev->when = rb_current_time() + when; + ev->next = when; + ev->frequency = 0; - if((ev->when < event_time_min) || (event_time_min == -1)) - event_time_min = ev->when; + if((ev->when < event_time_min) || (event_time_min == -1)) + event_time_min = ev->when; - rb_dlinkAdd(ev, &ev->node, &event_list); - rb_io_sched_event(ev, when); - return ev; + rb_dlinkAdd(ev, &ev->node, &event_list); + rb_io_sched_event(ev, when); + return ev; } /* @@ -135,13 +133,13 @@ rb_event_addonce(const char *name, EVH * func, void *arg, time_t when) void rb_event_delete(struct ev_entry *ev) { - if(ev == NULL) - return; + if(ev == NULL) + return; - rb_dlinkDelete(&ev->node, &event_list); - rb_io_unsched_event(ev); - rb_free(ev->name); - rb_free(ev); + rb_dlinkDelete(&ev->node, &event_list); + rb_io_unsched_event(ev); + rb_free(ev->name); + rb_free(ev); } /* @@ -154,10 +152,10 @@ rb_event_delete(struct ev_entry *ev) void rb_event_find_delete(EVH * func, void *arg) { - rb_event_delete(rb_event_find(func, arg)); + rb_event_delete(rb_event_find(func, arg)); } -/* +/* * struct ev_entry * * rb_event_addish(const char *name, EVH *func, void *arg, time_t delta_isa) * @@ -170,34 +168,32 @@ rb_event_find_delete(EVH * func, void *arg) struct ev_entry * rb_event_addish(const char *name, EVH * func, void *arg, time_t delta_ish) { - if(delta_ish >= 3.0) - { - const time_t two_third = (2 * delta_ish) / 3; - delta_ish = two_third + ((rand() % 1000) * two_third) / 1000; - /* - * XXX I hate the above magic, I don't even know if its right. - * Grr. -- adrian - */ - } - return rb_event_add(name, func, arg, delta_ish); + if(delta_ish >= 3.0) { + const time_t two_third = (2 * delta_ish) / 3; + delta_ish = two_third + ((rand() % 1000) * two_third) / 1000; + /* + * XXX I hate the above magic, I don't even know if its right. + * Grr. -- adrian + */ + } + return rb_event_add(name, func, arg, delta_ish); } void rb_run_event(struct ev_entry *ev) { - rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran)); - ev->func(ev->arg); - if(!ev->frequency) - { - rb_io_unsched_event(ev); - rb_dlinkDelete(&ev->node, &event_list); - rb_free(ev); - return; - } - ev->when = rb_current_time() + ev->frequency; - if((ev->when < event_time_min) || (event_time_min == -1)) - event_time_min = ev->when; + rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran)); + ev->func(ev->arg); + if(!ev->frequency) { + rb_io_unsched_event(ev); + rb_dlinkDelete(&ev->node, &event_list); + rb_free(ev); + return; + } + ev->when = rb_current_time() + ev->frequency; + if((ev->when < event_time_min) || (event_time_min == -1)) + event_time_min = ev->when; } /* @@ -210,56 +206,48 @@ rb_run_event(struct ev_entry *ev) void rb_event_run(void) { - rb_dlink_node *ptr, *next; - struct ev_entry *ev; + rb_dlink_node *ptr, *next; + struct ev_entry *ev; - if(rb_io_supports_event()) - return; + if(rb_io_supports_event()) + return; - event_time_min = -1; - RB_DLINK_FOREACH_SAFE(ptr, next, event_list.head) - { - ev = ptr->data; - if(ev->when <= rb_current_time()) - { - rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran)); - ev->func(ev->arg); + event_time_min = -1; + RB_DLINK_FOREACH_SAFE(ptr, next, event_list.head) { + ev = ptr->data; + if(ev->when <= rb_current_time()) { + rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran)); + ev->func(ev->arg); - /* event is scheduled more than once */ - if(ev->frequency) - { - ev->when = rb_current_time() + ev->frequency; - if((ev->when < event_time_min) || (event_time_min == -1)) - event_time_min = ev->when; - } - else - { - rb_dlinkDelete(&ev->node, &event_list); - rb_free(ev); - } - } - else - { - if((ev->when < event_time_min) || (event_time_min == -1)) - event_time_min = ev->when; - } - } + /* event is scheduled more than once */ + if(ev->frequency) { + ev->when = rb_current_time() + ev->frequency; + if((ev->when < event_time_min) || (event_time_min == -1)) + event_time_min = ev->when; + } else { + rb_dlinkDelete(&ev->node, &event_list); + rb_free(ev); + } + } else { + if((ev->when < event_time_min) || (event_time_min == -1)) + event_time_min = ev->when; + } + } } void rb_event_io_register_all(void) { - rb_dlink_node *ptr; - struct ev_entry *ev; + rb_dlink_node *ptr; + struct ev_entry *ev; - if(!rb_io_supports_event()) - return; + if(!rb_io_supports_event()) + return; - RB_DLINK_FOREACH(ptr, event_list.head) - { - ev = ptr->data; - rb_io_sched_event(ev, ev->next); - } + RB_DLINK_FOREACH(ptr, event_list.head) { + ev = ptr->data; + rb_io_sched_event(ev, ev->next); + } } /* @@ -267,39 +255,38 @@ rb_event_io_register_all(void) * * Input: None * Output: None - * Side Effects: Initializes the event system. + * Side Effects: Initializes the event system. */ void rb_event_init(void) { - rb_strlcpy(last_event_ran, "NONE", sizeof(last_event_ran)); + rb_strlcpy(last_event_ran, "NONE", sizeof(last_event_ran)); } void rb_dump_events(void (*func) (char *, void *), void *ptr) { - int len; - char buf[512]; - rb_dlink_node *dptr; - struct ev_entry *ev; - len = sizeof(buf); + int len; + char buf[512]; + rb_dlink_node *dptr; + struct ev_entry *ev; + len = sizeof(buf); - rb_snprintf(buf, len, "Last event to run: %s", last_event_ran); - func(buf, ptr); + rb_snprintf(buf, len, "Last event to run: %s", last_event_ran); + func(buf, ptr); - rb_strlcpy(buf, "Operation Next Execution", len); - func(buf, ptr); + rb_strlcpy(buf, "Operation Next Execution", len); + func(buf, ptr); - RB_DLINK_FOREACH(dptr, event_list.head) - { - ev = dptr->data; - rb_snprintf(buf, len, "%-28s %-4ld seconds", ev->name, - ev->when - (long)rb_current_time()); - func(buf, ptr); - } + RB_DLINK_FOREACH(dptr, event_list.head) { + ev = dptr->data; + rb_snprintf(buf, len, "%-28s %-4ld seconds", ev->name, + ev->when - (long)rb_current_time()); + func(buf, ptr); + } } -/* +/* * void rb_set_back_events(time_t by) * Input: Time to set back events by. * Output: None. @@ -308,36 +295,35 @@ rb_dump_events(void (*func) (char *, void *), void *ptr) void rb_set_back_events(time_t by) { - rb_dlink_node *ptr; - struct ev_entry *ev; - RB_DLINK_FOREACH(ptr, event_list.head) - { - ev = ptr->data; - if(ev->when > by) - ev->when -= by; - else - ev->when = 0; - } + rb_dlink_node *ptr; + struct ev_entry *ev; + RB_DLINK_FOREACH(ptr, event_list.head) { + ev = ptr->data; + if(ev->when > by) + ev->when -= by; + else + ev->when = 0; + } } void rb_event_update(struct ev_entry *ev, time_t freq) { - if(ev == NULL) - return; + if(ev == NULL) + return; - ev->frequency = freq; + ev->frequency = freq; - /* update when its scheduled to run if its higher - * than the new frequency - */ - if((rb_current_time() + freq) < ev->when) - ev->when = rb_current_time() + freq; - return; + /* update when its scheduled to run if its higher + * than the new frequency + */ + if((rb_current_time() + freq) < ev->when) + ev->when = rb_current_time() + freq; + return; } time_t rb_event_next(void) { - return event_time_min; + return event_time_min; } diff --git a/libratbox/src/gnutls.c b/libratbox/src/gnutls.c index 58bafdf..7e0c53f 100644 --- a/libratbox/src/gnutls.c +++ b/libratbox/src/gnutls.c @@ -14,7 +14,7 @@ * 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 @@ -42,116 +42,112 @@ static gnutls_dh_params dh_params; void rb_ssl_shutdown(rb_fde_t *F) { - int i; - if(F == NULL || F->ssl == NULL) - return; - for(i = 0; i < 4; i++) - { - if(gnutls_bye(SSL_P(F), GNUTLS_SHUT_RDWR) == GNUTLS_E_SUCCESS) - break; - } - gnutls_deinit(SSL_P(F)); - rb_free(F->ssl); + int i; + if(F == NULL || F->ssl == NULL) + return; + for(i = 0; i < 4; i++) { + if(gnutls_bye(SSL_P(F), GNUTLS_SHUT_RDWR) == GNUTLS_E_SUCCESS) + break; + } + gnutls_deinit(SSL_P(F)); + rb_free(F->ssl); } unsigned int rb_ssl_handshake_count(rb_fde_t *F) { - return F->handshake_count; + return F->handshake_count; } void rb_ssl_clear_handshake_count(rb_fde_t *F) { - F->handshake_count = 0; + F->handshake_count = 0; } static void rb_ssl_timeout(rb_fde_t *F, void *notused) { - lrb_assert(F->accept != NULL); - F->accept->callback(F, RB_ERR_TIMEOUT, NULL, 0, F->accept->data); + lrb_assert(F->accept != NULL); + F->accept->callback(F, RB_ERR_TIMEOUT, NULL, 0, F->accept->data); } static int do_ssl_handshake(rb_fde_t *F, PF * callback) { - int ret; - int flags; + int ret; + int flags; - ret = gnutls_handshake(SSL_P(F)); - if(ret < 0) - { - if((ret == GNUTLS_E_INTERRUPTED && rb_ignore_errno(errno)) || ret == GNUTLS_E_AGAIN) - { - if(gnutls_record_get_direction(SSL_P(F)) == 0) - flags = RB_SELECT_READ; - else - flags = RB_SELECT_WRITE; - rb_setselect(F, flags, callback, NULL); - return 0; - } - F->ssl_errno = ret; - return -1; - } - return 1; /* handshake is finished..go about life */ + ret = gnutls_handshake(SSL_P(F)); + if(ret < 0) { + if((ret == GNUTLS_E_INTERRUPTED && rb_ignore_errno(errno)) || ret == GNUTLS_E_AGAIN) { + if(gnutls_record_get_direction(SSL_P(F)) == 0) + flags = RB_SELECT_READ; + else + flags = RB_SELECT_WRITE; + rb_setselect(F, flags, callback, NULL); + return 0; + } + F->ssl_errno = ret; + return -1; + } + return 1; /* handshake is finished..go about life */ } static void rb_ssl_tryaccept(rb_fde_t *F, void *data) { - int ret; - struct acceptdata *ad; + int ret; + struct acceptdata *ad; - lrb_assert(F->accept != NULL); + lrb_assert(F->accept != NULL); - ret = do_ssl_handshake(F, rb_ssl_tryaccept); + ret = do_ssl_handshake(F, rb_ssl_tryaccept); - /* do_ssl_handshake does the rb_setselect */ - if(ret == 0) - return; + /* do_ssl_handshake does the rb_setselect */ + if(ret == 0) + return; - ad = F->accept; - F->accept = NULL; - rb_settimeout(F, 0, NULL, NULL); - rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL); - - if(ret > 0) - ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); - else - ad->callback(F, RB_ERROR_SSL, NULL, 0, ad->data); + ad = F->accept; + F->accept = NULL; + rb_settimeout(F, 0, NULL, NULL); + rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL); - rb_free(ad); + if(ret > 0) + ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); + else + ad->callback(F, RB_ERROR_SSL, NULL, 0, ad->data); + + rb_free(ad); } void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout) { - gnutls_session_t *ssl; - new_F->type |= RB_FD_SSL; - ssl = new_F->ssl = rb_malloc(sizeof(gnutls_session_t)); - new_F->accept = rb_malloc(sizeof(struct acceptdata)); + gnutls_session_t *ssl; + new_F->type |= RB_FD_SSL; + ssl = new_F->ssl = rb_malloc(sizeof(gnutls_session_t)); + new_F->accept = rb_malloc(sizeof(struct acceptdata)); - new_F->accept->callback = cb; - new_F->accept->data = data; - rb_settimeout(new_F, timeout, rb_ssl_timeout, NULL); + new_F->accept->callback = cb; + new_F->accept->data = data; + rb_settimeout(new_F, timeout, rb_ssl_timeout, NULL); - new_F->accept->addrlen = 0; + new_F->accept->addrlen = 0; - gnutls_init(ssl, GNUTLS_SERVER); - gnutls_set_default_priority(*ssl); - gnutls_credentials_set(*ssl, GNUTLS_CRD_CERTIFICATE, x509); - gnutls_dh_set_prime_bits(*ssl, 1024); - gnutls_transport_set_ptr(*ssl, (gnutls_transport_ptr_t) (long int)new_F->fd); - gnutls_certificate_server_set_request(*ssl, GNUTLS_CERT_REQUEST); - if(do_ssl_handshake(new_F, rb_ssl_tryaccept)) - { - struct acceptdata *ad = new_F->accept; - new_F->accept = NULL; - ad->callback(new_F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); - rb_free(ad); - } + gnutls_init(ssl, GNUTLS_SERVER); + gnutls_set_default_priority(*ssl); + gnutls_credentials_set(*ssl, GNUTLS_CRD_CERTIFICATE, x509); + gnutls_dh_set_prime_bits(*ssl, 1024); + gnutls_transport_set_ptr(*ssl, (gnutls_transport_ptr_t) (long int)new_F->fd); + gnutls_certificate_server_set_request(*ssl, GNUTLS_CERT_REQUEST); + if(do_ssl_handshake(new_F, rb_ssl_tryaccept)) { + struct acceptdata *ad = new_F->accept; + new_F->accept = NULL; + ad->callback(new_F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); + rb_free(ad); + } } @@ -161,29 +157,28 @@ rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout) void rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen) { - new_F->type |= RB_FD_SSL; - new_F->ssl = rb_malloc(sizeof(gnutls_session_t)); - new_F->accept = rb_malloc(sizeof(struct acceptdata)); + new_F->type |= RB_FD_SSL; + new_F->ssl = rb_malloc(sizeof(gnutls_session_t)); + new_F->accept = rb_malloc(sizeof(struct acceptdata)); - new_F->accept->callback = F->accept->callback; - new_F->accept->data = F->accept->data; - rb_settimeout(new_F, 10, rb_ssl_timeout, NULL); - memcpy(&new_F->accept->S, st, addrlen); - new_F->accept->addrlen = addrlen; + new_F->accept->callback = F->accept->callback; + new_F->accept->data = F->accept->data; + rb_settimeout(new_F, 10, rb_ssl_timeout, NULL); + memcpy(&new_F->accept->S, st, addrlen); + new_F->accept->addrlen = addrlen; - gnutls_init((gnutls_session_t *) new_F->ssl, GNUTLS_SERVER); - gnutls_set_default_priority(SSL_P(new_F)); - gnutls_credentials_set(SSL_P(new_F), GNUTLS_CRD_CERTIFICATE, x509); - gnutls_dh_set_prime_bits(SSL_P(new_F), 1024); - gnutls_transport_set_ptr(SSL_P(new_F), (gnutls_transport_ptr_t) (long int)rb_get_fd(new_F)); - gnutls_certificate_server_set_request(SSL_P(new_F), GNUTLS_CERT_REQUEST); - if(do_ssl_handshake(F, rb_ssl_tryaccept)) - { - struct acceptdata *ad = F->accept; - F->accept = NULL; - ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); - rb_free(ad); - } + gnutls_init((gnutls_session_t *) new_F->ssl, GNUTLS_SERVER); + gnutls_set_default_priority(SSL_P(new_F)); + gnutls_credentials_set(SSL_P(new_F), GNUTLS_CRD_CERTIFICATE, x509); + gnutls_dh_set_prime_bits(SSL_P(new_F), 1024); + gnutls_transport_set_ptr(SSL_P(new_F), (gnutls_transport_ptr_t) (long int)rb_get_fd(new_F)); + gnutls_certificate_server_set_request(SSL_P(new_F), GNUTLS_CERT_REQUEST); + if(do_ssl_handshake(F, rb_ssl_tryaccept)) { + struct acceptdata *ad = F->accept; + F->accept = NULL; + ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); + rb_free(ad); + } } @@ -192,371 +187,351 @@ rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrl static ssize_t rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size_t count) { - ssize_t ret; - gnutls_session_t *ssl = F->ssl; + ssize_t ret; + gnutls_session_t *ssl = F->ssl; - if(r_or_w == 0) - ret = gnutls_record_recv(*ssl, rbuf, count); - else - ret = gnutls_record_send(*ssl, wbuf, count); + if(r_or_w == 0) + ret = gnutls_record_recv(*ssl, rbuf, count); + else + ret = gnutls_record_send(*ssl, wbuf, count); - if(ret < 0) - { - switch (ret) - { - case GNUTLS_E_AGAIN: - case GNUTLS_E_INTERRUPTED: - if(rb_ignore_errno(errno)) - { - if(gnutls_record_get_direction(*ssl) == 0) - return RB_RW_SSL_NEED_READ; - else - return RB_RW_SSL_NEED_WRITE; - break; - } - default: - F->ssl_errno = ret; - errno = EIO; - return RB_RW_IO_ERROR; - } - } - return ret; + if(ret < 0) { + switch (ret) { + case GNUTLS_E_AGAIN: + case GNUTLS_E_INTERRUPTED: + if(rb_ignore_errno(errno)) { + if(gnutls_record_get_direction(*ssl) == 0) + return RB_RW_SSL_NEED_READ; + else + return RB_RW_SSL_NEED_WRITE; + break; + } + default: + F->ssl_errno = ret; + errno = EIO; + return RB_RW_IO_ERROR; + } + } + return ret; } ssize_t rb_ssl_read(rb_fde_t *F, void *buf, size_t count) { - return rb_ssl_read_or_write(0, F, buf, NULL, count); + return rb_ssl_read_or_write(0, F, buf, NULL, count); } ssize_t rb_ssl_write(rb_fde_t *F, const void *buf, size_t count) { - return rb_ssl_read_or_write(1, F, NULL, buf, count); + return rb_ssl_read_or_write(1, F, NULL, buf, count); } static void rb_gcry_random_seed(void *unused) { - gcry_fast_random_poll(); + gcry_fast_random_poll(); } int rb_init_ssl(void) { - gnutls_global_init(); + gnutls_global_init(); - if(gnutls_certificate_allocate_credentials(&x509) != GNUTLS_E_SUCCESS) - { - rb_lib_log("rb_init_ssl: Unable to allocate SSL/TLS certificate credentials"); - return 0; - } - rb_event_addish("rb_gcry_random_seed", rb_gcry_random_seed, NULL, 300); - return 1; + if(gnutls_certificate_allocate_credentials(&x509) != GNUTLS_E_SUCCESS) { + rb_lib_log("rb_init_ssl: Unable to allocate SSL/TLS certificate credentials"); + return 0; + } + rb_event_addish("rb_gcry_random_seed", rb_gcry_random_seed, NULL, 300); + return 1; } static void rb_free_datum_t(gnutls_datum_t * d) { - rb_free(d->data); - rb_free(d); + rb_free(d->data); + rb_free(d); } static gnutls_datum_t * rb_load_file_into_datum_t(const char *file) { - FILE *f; - gnutls_datum_t *datum; - struct stat fileinfo; - if((f = fopen(file, "r")) == NULL) - return NULL; - if(fstat(fileno(f), &fileinfo)) - return NULL; + FILE *f; + gnutls_datum_t *datum; + struct stat fileinfo; + if((f = fopen(file, "r")) == NULL) + return NULL; + if(fstat(fileno(f), &fileinfo)) + return NULL; - datum = rb_malloc(sizeof(gnutls_datum_t)); + datum = rb_malloc(sizeof(gnutls_datum_t)); - if(fileinfo.st_size > 131072) /* deal with retards */ - datum->size = 131072; - else - datum->size = fileinfo.st_size; + if(fileinfo.st_size > 131072) /* deal with retards */ + datum->size = 131072; + else + datum->size = fileinfo.st_size; - datum->data = rb_malloc(datum->size + 1); - fread(datum->data, datum->size, 1, f); - fclose(f); - return datum; + datum->data = rb_malloc(datum->size + 1); + fread(datum->data, datum->size, 1, f); + fclose(f); + return datum; } int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile) { - int ret; - gnutls_datum_t *d_cert, *d_key; - if(cert == NULL) - { - rb_lib_log("rb_setup_ssl_server: No certificate file"); - return 0; - } + int ret; + gnutls_datum_t *d_cert, *d_key; + if(cert == NULL) { + rb_lib_log("rb_setup_ssl_server: No certificate file"); + return 0; + } - if((d_cert = rb_load_file_into_datum_t(cert)) == NULL) - { - rb_lib_log("rb_setup_ssl_server: Error loading certificate: %s", strerror(errno)); - return 0; - } + if((d_cert = rb_load_file_into_datum_t(cert)) == NULL) { + rb_lib_log("rb_setup_ssl_server: Error loading certificate: %s", strerror(errno)); + return 0; + } - if((d_key = rb_load_file_into_datum_t(keyfile)) == NULL) - { - rb_lib_log("rb_setup_ssl_server: Error loading key: %s", strerror(errno)); - return 0; - } + if((d_key = rb_load_file_into_datum_t(keyfile)) == NULL) { + rb_lib_log("rb_setup_ssl_server: Error loading key: %s", strerror(errno)); + return 0; + } - if((ret = - gnutls_certificate_set_x509_key_mem(x509, d_cert, d_key, - GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) - { - rb_lib_log("rb_setup_ssl_server: Error loading certificate or key file: %s", - gnutls_strerror(ret)); - return 0; - } - rb_free_datum_t(d_cert); - rb_free_datum_t(d_key); + if((ret = + gnutls_certificate_set_x509_key_mem(x509, d_cert, d_key, + GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) { + rb_lib_log("rb_setup_ssl_server: Error loading certificate or key file: %s", + gnutls_strerror(ret)); + return 0; + } + rb_free_datum_t(d_cert); + rb_free_datum_t(d_key); - if(dhfile != NULL) - { - if(gnutls_dh_params_init(&dh_params) == GNUTLS_E_SUCCESS) - { - gnutls_datum_t *data; - int xret; - data = rb_load_file_into_datum_t(dhfile); - if(data != NULL) - { - xret = gnutls_dh_params_import_pkcs3(dh_params, data, - GNUTLS_X509_FMT_PEM); - if(xret < 0) - rb_lib_log - ("rb_setup_ssl_server: Error parsing DH file: %s\n", - gnutls_strerror(xret)); - rb_free_datum_t(data); - } - gnutls_certificate_set_dh_params(x509, dh_params); - } - else - rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters"); - } - return 1; + if(dhfile != NULL) { + if(gnutls_dh_params_init(&dh_params) == GNUTLS_E_SUCCESS) { + gnutls_datum_t *data; + int xret; + data = rb_load_file_into_datum_t(dhfile); + if(data != NULL) { + xret = gnutls_dh_params_import_pkcs3(dh_params, data, + GNUTLS_X509_FMT_PEM); + if(xret < 0) + rb_lib_log + ("rb_setup_ssl_server: Error parsing DH file: %s\n", + gnutls_strerror(xret)); + rb_free_datum_t(data); + } + gnutls_certificate_set_dh_params(x509, dh_params); + } else + rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters"); + } + return 1; } int rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept) { - int result; + int result; - result = listen(F->fd, backlog, defer_accept); - F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL; + result = listen(F->fd, backlog, defer_accept); + F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL; - return result; + return result; } -struct ssl_connect -{ - CNCB *callback; - void *data; - int timeout; +struct ssl_connect { + CNCB *callback; + void *data; + int timeout; }; static void rb_ssl_connect_realcb(rb_fde_t *F, int status, struct ssl_connect *sconn) { - F->connect->callback = sconn->callback; - F->connect->data = sconn->data; - rb_free(sconn); - rb_connect_callback(F, status); + F->connect->callback = sconn->callback; + F->connect->data = sconn->data; + rb_free(sconn); + rb_connect_callback(F, status); } static void rb_ssl_tryconn_timeout_cb(rb_fde_t *F, void *data) { - rb_ssl_connect_realcb(F, RB_ERR_TIMEOUT, data); + rb_ssl_connect_realcb(F, RB_ERR_TIMEOUT, data); } static void rb_ssl_tryconn_cb(rb_fde_t *F, void *data) { - struct ssl_connect *sconn = data; - int ret; + struct ssl_connect *sconn = data; + int ret; - ret = do_ssl_handshake(F, rb_ssl_tryconn_cb); + ret = do_ssl_handshake(F, rb_ssl_tryconn_cb); - switch (ret) - { - case -1: - rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); - break; - case 0: - /* do_ssl_handshake does the rb_setselect stuff */ - return; - default: - break; + switch (ret) { + case -1: + rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); + break; + case 0: + /* do_ssl_handshake does the rb_setselect stuff */ + return; + default: + break; - } - rb_ssl_connect_realcb(F, RB_OK, sconn); + } + rb_ssl_connect_realcb(F, RB_OK, sconn); } static void rb_ssl_tryconn(rb_fde_t *F, int status, void *data) { - struct ssl_connect *sconn = data; - if(status != RB_OK) - { - rb_ssl_connect_realcb(F, status, sconn); - return; - } + struct ssl_connect *sconn = data; + if(status != RB_OK) { + rb_ssl_connect_realcb(F, status, sconn); + return; + } - F->type |= RB_FD_SSL; + F->type |= RB_FD_SSL; - rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); - F->ssl = rb_malloc(sizeof(gnutls_session_t)); - gnutls_init(F->ssl, GNUTLS_CLIENT); - gnutls_set_default_priority(SSL_P(F)); - gnutls_credentials_set(SSL_P(F), GNUTLS_CRD_CERTIFICATE, x509); - gnutls_dh_set_prime_bits(SSL_P(F), 1024); - gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd); + rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); + F->ssl = rb_malloc(sizeof(gnutls_session_t)); + gnutls_init(F->ssl, GNUTLS_CLIENT); + gnutls_set_default_priority(SSL_P(F)); + gnutls_credentials_set(SSL_P(F), GNUTLS_CRD_CERTIFICATE, x509); + gnutls_dh_set_prime_bits(SSL_P(F), 1024); + gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd); - if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) - { - rb_ssl_connect_realcb(F, RB_OK, sconn); - } + if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) { + rb_ssl_connect_realcb(F, RB_OK, sconn); + } } void rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest, - struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) + struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) { - struct ssl_connect *sconn; - if(F == NULL) - return; + struct ssl_connect *sconn; + if(F == NULL) + return; - sconn = rb_malloc(sizeof(struct ssl_connect)); - sconn->data = data; - sconn->callback = callback; - sconn->timeout = timeout; - rb_connect_tcp(F, dest, clocal, socklen, rb_ssl_tryconn, sconn, timeout); + sconn = rb_malloc(sizeof(struct ssl_connect)); + sconn->data = data; + sconn->callback = callback; + sconn->timeout = timeout; + rb_connect_tcp(F, dest, clocal, socklen, rb_ssl_tryconn, sconn, timeout); } void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout) { - struct ssl_connect *sconn; - if(F == NULL) - return; + struct ssl_connect *sconn; + if(F == NULL) + return; - sconn = rb_malloc(sizeof(struct ssl_connect)); - sconn->data = data; - sconn->callback = callback; - sconn->timeout = timeout; - F->connect = rb_malloc(sizeof(struct conndata)); - F->connect->callback = callback; - F->connect->data = data; - F->type |= RB_FD_SSL; - F->ssl = rb_malloc(sizeof(gnutls_session_t)); + sconn = rb_malloc(sizeof(struct ssl_connect)); + sconn->data = data; + sconn->callback = callback; + sconn->timeout = timeout; + F->connect = rb_malloc(sizeof(struct conndata)); + F->connect->callback = callback; + F->connect->data = data; + F->type |= RB_FD_SSL; + F->ssl = rb_malloc(sizeof(gnutls_session_t)); - gnutls_init(F->ssl, GNUTLS_CLIENT); - gnutls_set_default_priority(SSL_P(F)); - gnutls_credentials_set(SSL_P(F), GNUTLS_CRD_CERTIFICATE, x509); - gnutls_dh_set_prime_bits(SSL_P(F), 1024); - gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd); + gnutls_init(F->ssl, GNUTLS_CLIENT); + gnutls_set_default_priority(SSL_P(F)); + gnutls_credentials_set(SSL_P(F), GNUTLS_CRD_CERTIFICATE, x509); + gnutls_dh_set_prime_bits(SSL_P(F), 1024); + gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd); - rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); + rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); - if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) - { - rb_ssl_connect_realcb(F, RB_OK, sconn); - } + if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) { + rb_ssl_connect_realcb(F, RB_OK, sconn); + } } int rb_init_prng(const char *path, prng_seed_t seed_type) { - gcry_fast_random_poll(); - return 1; + gcry_fast_random_poll(); + return 1; } int rb_get_random(void *buf, size_t length) { - gcry_randomize(buf, length, GCRY_STRONG_RANDOM); - return 1; + gcry_randomize(buf, length, GCRY_STRONG_RANDOM); + return 1; } int rb_get_pseudo_random(void *buf, size_t length) { - gcry_randomize(buf, length, GCRY_WEAK_RANDOM); - return 1; + gcry_randomize(buf, length, GCRY_WEAK_RANDOM); + return 1; } const char * rb_get_ssl_strerror(rb_fde_t *F) { - return gnutls_strerror(F->ssl_errno); + return gnutls_strerror(F->ssl_errno); } int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN]) { - gnutls_x509_crt_t cert; - unsigned int cert_list_size; - const gnutls_datum_t *cert_list; - uint8_t digest[RB_SSL_CERTFP_LEN * 2]; - size_t digest_size; + gnutls_x509_crt_t cert; + unsigned int cert_list_size; + const gnutls_datum_t *cert_list; + uint8_t digest[RB_SSL_CERTFP_LEN * 2]; + size_t digest_size; - if (gnutls_certificate_type_get(SSL_P(F)) != GNUTLS_CRT_X509) - return 0; + if (gnutls_certificate_type_get(SSL_P(F)) != GNUTLS_CRT_X509) + return 0; - if (gnutls_x509_crt_init(&cert) < 0) - return 0; + if (gnutls_x509_crt_init(&cert) < 0) + return 0; - cert_list_size = 0; - cert_list = gnutls_certificate_get_peers(SSL_P(F), &cert_list_size); - if (cert_list == NULL) - { - gnutls_x509_crt_deinit(cert); - return 0; - } + cert_list_size = 0; + cert_list = gnutls_certificate_get_peers(SSL_P(F), &cert_list_size); + if (cert_list == NULL) { + gnutls_x509_crt_deinit(cert); + return 0; + } - if (gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0) - { - gnutls_x509_crt_deinit(cert); - return 0; - } + if (gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0) { + gnutls_x509_crt_deinit(cert); + return 0; + } - if (gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, digest, &digest_size) < 0) - { - gnutls_x509_crt_deinit(cert); - return 0; - } + if (gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, digest, &digest_size) < 0) { + gnutls_x509_crt_deinit(cert); + return 0; + } - memcpy(certfp, digest, RB_SSL_CERTFP_LEN); + memcpy(certfp, digest, RB_SSL_CERTFP_LEN); - gnutls_x509_crt_deinit(cert); - return 1; + gnutls_x509_crt_deinit(cert); + return 1; } int rb_supports_ssl(void) { - return 1; + return 1; } void rb_get_ssl_info(char *buf, size_t len) { - rb_snprintf(buf, len, "GNUTLS: compiled (%s), library(%s)", - LIBGNUTLS_VERSION, gnutls_check_version(NULL)); + rb_snprintf(buf, len, "GNUTLS: compiled (%s), library(%s)", + LIBGNUTLS_VERSION, gnutls_check_version(NULL)); } - - + + #endif /* HAVE_GNUTLS */ diff --git a/libratbox/src/helper.c b/libratbox/src/helper.c index fa12911..bc07434 100644 --- a/libratbox/src/helper.c +++ b/libratbox/src/helper.c @@ -1,7 +1,7 @@ /* * ircd-ratbox: A slightly useful ircd * helper.c: Starts and deals with ircd helpers - * + * * Copyright (C) 2006 Aaron Sethman * * This program is free software; you can redistribute it and/or modify @@ -24,75 +24,73 @@ #include #include -struct _rb_helper -{ - char *path; - buf_head_t sendq; - buf_head_t recvq; - rb_fde_t *ifd; - rb_fde_t *ofd; - pid_t pid; - int fork_count; - rb_helper_cb *read_cb; - rb_helper_cb *error_cb; +struct _rb_helper { + char *path; + buf_head_t sendq; + buf_head_t recvq; + rb_fde_t *ifd; + rb_fde_t *ofd; + pid_t pid; + int fork_count; + rb_helper_cb *read_cb; + rb_helper_cb *error_cb; }; /* setup all the stuff a new child needs */ rb_helper * rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb, log_cb * ilog, - restart_cb * irestart, die_cb * idie, int maxcon, size_t lb_heap_size, - size_t dh_size, size_t fd_heap_size) + restart_cb * irestart, die_cb * idie, int maxcon, size_t lb_heap_size, + size_t dh_size, size_t fd_heap_size) { - rb_helper *helper; - int maxfd, x = 0; - int ifd, ofd; - char *tifd, *tofd, *tmaxfd; + rb_helper *helper; + int maxfd, x = 0; + int ifd, ofd; + char *tifd, *tofd, *tmaxfd; - tifd = getenv("IFD"); - tofd = getenv("OFD"); - tmaxfd = getenv("MAXFD"); + tifd = getenv("IFD"); + tofd = getenv("OFD"); + tmaxfd = getenv("MAXFD"); - if(tifd == NULL || tofd == NULL || tmaxfd == NULL) - return NULL; + if(tifd == NULL || tofd == NULL || tmaxfd == NULL) + return NULL; - helper = rb_malloc(sizeof(rb_helper)); - ifd = (int)strtol(tifd, NULL, 10); - ofd = (int)strtol(tofd, NULL, 10); - maxfd = (int)strtol(tmaxfd, NULL, 10); + helper = rb_malloc(sizeof(rb_helper)); + ifd = (int)strtol(tifd, NULL, 10); + ofd = (int)strtol(tofd, NULL, 10); + maxfd = (int)strtol(tmaxfd, NULL, 10); #ifndef _WIN32 - for(x = 0; x < maxfd; x++) - { - if(x != ifd && x != ofd) - close(x); - } - x = open("/dev/null", O_RDWR); - if(ifd != 0 && ofd != 0) - dup2(x, 0); - if(ifd != 1 && ofd != 1) - dup2(x, 1); - if(ifd != 2 && ofd != 2) - dup2(x, 2); - if(x > 2) /* don't undo what we just did */ - close(x); + for(x = 0; x < maxfd; x++) { + if(x != ifd && x != ofd) + close(x); + } + x = open("/dev/null", O_RDWR); + if(ifd != 0 && ofd != 0) + dup2(x, 0); + if(ifd != 1 && ofd != 1) + dup2(x, 1); + if(ifd != 2 && ofd != 2) + dup2(x, 2); + if(x > 2) /* don't undo what we just did */ + close(x); #else - x = 0; /* shut gcc up */ + x = 0; /* shut gcc up */ #endif - rb_lib_init(ilog, irestart, idie, 0, maxfd, dh_size, fd_heap_size); - rb_linebuf_init(lb_heap_size); - rb_linebuf_newbuf(&helper->sendq); - rb_linebuf_newbuf(&helper->recvq); + rb_lib_init(ilog, irestart, idie, 0, maxfd, dh_size, fd_heap_size); + rb_linebuf_init(lb_heap_size); + rb_linebuf_newbuf(&helper->sendq); + rb_linebuf_newbuf(&helper->recvq); - helper->ifd = rb_open(ifd, RB_FD_PIPE, "incoming connection"); - helper->ofd = rb_open(ofd, RB_FD_PIPE, "outgoing connection"); - rb_set_nb(helper->ifd); - rb_set_nb(helper->ofd); + helper->ifd = rb_open(ifd, RB_FD_PIPE, "incoming connection"); + helper->ofd = rb_open(ofd, RB_FD_PIPE, "outgoing connection"); + rb_set_nb(helper->ifd); + rb_set_nb(helper->ofd); - helper->read_cb = read_cb; - helper->error_cb = error_cb; - return helper; + helper->read_cb = read_cb; + helper->error_cb = error_cb; + return helper; } /* @@ -103,194 +101,186 @@ rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb, log_cb * ilog, rb_helper * rb_helper_start(const char *name, const char *fullpath, rb_helper_cb * read_cb, - rb_helper_cb * error_cb) + rb_helper_cb * error_cb) { - rb_helper *helper; - const char *parv[2]; - char buf[128]; - char fx[16], fy[16]; - rb_fde_t *in_f[2]; - rb_fde_t *out_f[2]; - pid_t pid; + rb_helper *helper; + const char *parv[2]; + char buf[128]; + char fx[16], fy[16]; + rb_fde_t *in_f[2]; + rb_fde_t *out_f[2]; + pid_t pid; - if(access(fullpath, X_OK) == -1) - return NULL; + if(access(fullpath, X_OK) == -1) + return NULL; - helper = rb_malloc(sizeof(rb_helper)); + helper = rb_malloc(sizeof(rb_helper)); - rb_snprintf(buf, sizeof(buf), "%s helper - read", name); - if(rb_pipe(&in_f[0], &in_f[1], buf) < 0) - { - rb_free(helper); - return NULL; - } - rb_snprintf(buf, sizeof(buf), "%s helper - write", name); - if(rb_pipe(&out_f[0], &out_f[1], buf) < 0) - { - rb_free(helper); - return NULL; - } + rb_snprintf(buf, sizeof(buf), "%s helper - read", name); + if(rb_pipe(&in_f[0], &in_f[1], buf) < 0) { + rb_free(helper); + return NULL; + } + rb_snprintf(buf, sizeof(buf), "%s helper - write", name); + if(rb_pipe(&out_f[0], &out_f[1], buf) < 0) { + rb_free(helper); + return NULL; + } - rb_snprintf(fx, sizeof(fx), "%d", rb_get_fd(in_f[1])); - rb_snprintf(fy, sizeof(fy), "%d", rb_get_fd(out_f[0])); + rb_snprintf(fx, sizeof(fx), "%d", rb_get_fd(in_f[1])); + rb_snprintf(fy, sizeof(fy), "%d", rb_get_fd(out_f[0])); - rb_set_nb(in_f[0]); - rb_set_nb(in_f[1]); - rb_set_nb(out_f[0]); - rb_set_nb(out_f[1]); + rb_set_nb(in_f[0]); + rb_set_nb(in_f[1]); + rb_set_nb(out_f[0]); + rb_set_nb(out_f[1]); - rb_setenv("IFD", fy, 1); - rb_setenv("OFD", fx, 1); - rb_setenv("MAXFD", "256", 1); + rb_setenv("IFD", fy, 1); + rb_setenv("OFD", fx, 1); + rb_setenv("MAXFD", "256", 1); - rb_snprintf(buf, sizeof(buf), "-ircd %s daemon", name); - parv[0] = buf; - parv[1] = NULL; + rb_snprintf(buf, sizeof(buf), "-ircd %s daemon", name); + parv[0] = buf; + parv[1] = NULL; #ifdef _WIN32 - SetHandleInformation((HANDLE) rb_get_fd(in_f[1]), HANDLE_FLAG_INHERIT, 1); - SetHandleInformation((HANDLE) rb_get_fd(out_f[0]), HANDLE_FLAG_INHERIT, 1); + SetHandleInformation((HANDLE) rb_get_fd(in_f[1]), HANDLE_FLAG_INHERIT, 1); + SetHandleInformation((HANDLE) rb_get_fd(out_f[0]), HANDLE_FLAG_INHERIT, 1); #endif - pid = rb_spawn_process(fullpath, (const char **)parv); + pid = rb_spawn_process(fullpath, (const char **)parv); - if(pid == -1) - { - rb_close(in_f[0]); - rb_close(in_f[1]); - rb_close(out_f[0]); - rb_close(out_f[1]); - rb_free(helper); - return NULL; - } + if(pid == -1) { + rb_close(in_f[0]); + rb_close(in_f[1]); + rb_close(out_f[0]); + rb_close(out_f[1]); + rb_free(helper); + return NULL; + } - rb_close(in_f[1]); - rb_close(out_f[0]); + rb_close(in_f[1]); + rb_close(out_f[0]); - rb_linebuf_newbuf(&helper->sendq); - rb_linebuf_newbuf(&helper->recvq); + rb_linebuf_newbuf(&helper->sendq); + rb_linebuf_newbuf(&helper->recvq); - helper->ifd = in_f[0]; - helper->ofd = out_f[1]; - helper->read_cb = read_cb; - helper->error_cb = error_cb; - helper->fork_count = 0; - helper->pid = pid; + helper->ifd = in_f[0]; + helper->ofd = out_f[1]; + helper->read_cb = read_cb; + helper->error_cb = error_cb; + helper->fork_count = 0; + helper->pid = pid; - return helper; + return helper; } void rb_helper_restart(rb_helper *helper) { - helper->error_cb(helper); + helper->error_cb(helper); } static void rb_helper_write_sendq(rb_fde_t *F, void *helper_ptr) { - rb_helper *helper = helper_ptr; - int retlen; + rb_helper *helper = helper_ptr; + int retlen; - if(rb_linebuf_len(&helper->sendq) > 0) - { - while((retlen = rb_linebuf_flush(F, &helper->sendq)) > 0) - ;; - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - rb_helper_restart(helper); - return; - } - } + if(rb_linebuf_len(&helper->sendq) > 0) { + while((retlen = rb_linebuf_flush(F, &helper->sendq)) > 0) + ;; + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + rb_helper_restart(helper); + return; + } + } - if(rb_linebuf_len(&helper->sendq) > 0) - rb_setselect(helper->ofd, RB_SELECT_WRITE, rb_helper_write_sendq, helper); + if(rb_linebuf_len(&helper->sendq) > 0) + rb_setselect(helper->ofd, RB_SELECT_WRITE, rb_helper_write_sendq, helper); } void rb_helper_write_queue(rb_helper *helper, const char *format, ...) { - va_list ap; - va_start(ap, format); - rb_linebuf_putmsg(&helper->sendq, format, &ap, NULL); - va_end(ap); + va_list ap; + va_start(ap, format); + rb_linebuf_putmsg(&helper->sendq, format, &ap, NULL); + va_end(ap); } void rb_helper_write_flush(rb_helper *helper) { - rb_helper_write_sendq(helper->ofd, helper); + rb_helper_write_sendq(helper->ofd, helper); } void rb_helper_write(rb_helper *helper, const char *format, ...) { - va_list ap; - va_start(ap, format); - rb_linebuf_putmsg(&helper->sendq, format, &ap, NULL); - va_end(ap); - rb_helper_write_flush(helper); + va_list ap; + va_start(ap, format); + rb_linebuf_putmsg(&helper->sendq, format, &ap, NULL); + va_end(ap); + rb_helper_write_flush(helper); } static void rb_helper_read_cb(rb_fde_t *F, void *data) { - rb_helper *helper = (rb_helper *)data; - static char buf[32768]; - int length; - if(helper == NULL) - return; + rb_helper *helper = (rb_helper *)data; + static char buf[32768]; + int length; + if(helper == NULL) + return; - while((length = rb_read(helper->ifd, buf, sizeof(buf))) > 0) - { - rb_linebuf_parse(&helper->recvq, buf, length, 0); - helper->read_cb(helper); - } + while((length = rb_read(helper->ifd, buf, sizeof(buf))) > 0) { + rb_linebuf_parse(&helper->recvq, buf, length, 0); + helper->read_cb(helper); + } - if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) - { - rb_helper_restart(helper); - return; - } + if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) { + rb_helper_restart(helper); + return; + } - rb_setselect(helper->ifd, RB_SELECT_READ, rb_helper_read_cb, helper); + rb_setselect(helper->ifd, RB_SELECT_READ, rb_helper_read_cb, helper); } void rb_helper_run(rb_helper *helper) { - if(helper == NULL) - return; - rb_helper_read_cb(helper->ifd, helper); + if(helper == NULL) + return; + rb_helper_read_cb(helper->ifd, helper); } void rb_helper_close(rb_helper *helper) { - if(helper == NULL) - return; - rb_kill(helper->pid, SIGKILL); - rb_close(helper->ifd); - rb_close(helper->ofd); - rb_free(helper); + if(helper == NULL) + return; + rb_kill(helper->pid, SIGKILL); + rb_close(helper->ifd); + rb_close(helper->ofd); + rb_free(helper); } int rb_helper_read(rb_helper *helper, void *buf, size_t bufsize) { - return rb_linebuf_get(&helper->recvq, buf, bufsize, LINEBUF_COMPLETE, LINEBUF_PARSED); + return rb_linebuf_get(&helper->recvq, buf, bufsize, LINEBUF_COMPLETE, LINEBUF_PARSED); } void rb_helper_loop(rb_helper *helper, long delay) { - rb_helper_run(helper); - while(1) - { - rb_lib_loop(delay); - } + rb_helper_run(helper); + while(1) { + rb_lib_loop(delay); + } } diff --git a/libratbox/src/kqueue.c b/libratbox/src/kqueue.c index 339c19a..eb2bea1 100644 --- a/libratbox/src/kqueue.c +++ b/libratbox/src/kqueue.c @@ -64,70 +64,63 @@ static int kqoff; /* offset into the buffer */ int rb_setup_fd_kqueue(rb_fde_t *F) { - return 0; + return 0; } static void kq_update_events(rb_fde_t *F, short filter, PF * handler) { - PF *cur_handler; - int kep_flags; + PF *cur_handler; + int kep_flags; - switch (filter) - { - case EVFILT_READ: - cur_handler = F->read_handler; - break; - case EVFILT_WRITE: - cur_handler = F->write_handler; - break; - default: - /* XXX bad! -- adrian */ - return; - break; - } + switch (filter) { + case EVFILT_READ: + cur_handler = F->read_handler; + break; + case EVFILT_WRITE: + cur_handler = F->write_handler; + break; + default: + /* XXX bad! -- adrian */ + return; + break; + } - if((cur_handler == NULL && handler != NULL) || (cur_handler != NULL && handler == NULL)) - { - struct kevent *kep; + if((cur_handler == NULL && handler != NULL) || (cur_handler != NULL && handler == NULL)) { + struct kevent *kep; - kep = kqlst + kqoff; + kep = kqlst + kqoff; - if(handler != NULL) - { - kep_flags = EV_ADD | EV_ONESHOT; - } - else - { - kep_flags = EV_DELETE; - } + if(handler != NULL) { + kep_flags = EV_ADD | EV_ONESHOT; + } else { + kep_flags = EV_DELETE; + } - EV_SET(kep, (uintptr_t)F->fd, filter, kep_flags, 0, 0, (void *)F); + EV_SET(kep, (uintptr_t)F->fd, filter, kep_flags, 0, 0, (void *)F); - if(++kqoff == kqmax) - { - int ret, i; + if(++kqoff == kqmax) { + int ret, i; - /* Add them one at a time, because there may be - * already closed fds in it. The kernel will try - * to report invalid fds in the output; if there - * is no space, it silently stops processing the - * array at that point. We cannot give output space - * because that would also return events we cannot - * process at this point. - */ - for(i = 0; i < kqoff; i++) - { - ret = kevent(kq, kqlst + i, 1, NULL, 0, &zero_timespec); - /* jdc -- someone needs to do error checking... */ - /* EBADF is normal here -- jilles */ - if(ret == -1 && errno != EBADF) - rb_lib_log("kq_update_events(): kevent(): %s", - strerror(errno)); - } - kqoff = 0; - } - } + /* Add them one at a time, because there may be + * already closed fds in it. The kernel will try + * to report invalid fds in the output; if there + * is no space, it silently stops processing the + * array at that point. We cannot give output space + * because that would also return events we cannot + * process at this point. + */ + for(i = 0; i < kqoff; i++) { + ret = kevent(kq, kqlst + i, 1, NULL, 0, &zero_timespec); + /* jdc -- someone needs to do error checking... */ + /* EBADF is normal here -- jilles */ + if(ret == -1 && errno != EBADF) + rb_lib_log("kq_update_events(): kevent(): %s", + strerror(errno)); + } + kqoff = 0; + } + } } @@ -145,19 +138,18 @@ kq_update_events(rb_fde_t *F, short filter, PF * handler) int rb_init_netio_kqueue(void) { - kq = kqueue(); - if(kq < 0) - { - return errno; - } - kqmax = getdtablesize(); - kqlst = rb_malloc(sizeof(struct kevent) * kqmax); - kqout = rb_malloc(sizeof(struct kevent) * kqmax); - rb_open(kq, RB_FD_UNKNOWN, "kqueue fd"); - zero_timespec.tv_sec = 0; - zero_timespec.tv_nsec = 0; + kq = kqueue(); + if(kq < 0) { + return errno; + } + kqmax = getdtablesize(); + kqlst = rb_malloc(sizeof(struct kevent) * kqmax); + kqout = rb_malloc(sizeof(struct kevent) * kqmax); + rb_open(kq, RB_FD_UNKNOWN, "kqueue fd"); + zero_timespec.tv_sec = 0; + zero_timespec.tv_nsec = 0; - return 0; + return 0; } /* @@ -169,20 +161,18 @@ rb_init_netio_kqueue(void) void rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - lrb_assert(IsFDOpen(F)); + lrb_assert(IsFDOpen(F)); - if(type & RB_SELECT_READ) - { - kq_update_events(F, EVFILT_READ, handler); - F->read_handler = handler; - F->read_data = client_data; - } - if(type & RB_SELECT_WRITE) - { - kq_update_events(F, EVFILT_WRITE, handler); - F->write_handler = handler; - F->write_data = client_data; - } + if(type & RB_SELECT_READ) { + kq_update_events(F, EVFILT_READ, handler); + F->read_handler = handler; + F->read_data = client_data; + } + if(type & RB_SELECT_WRITE) { + kq_update_events(F, EVFILT_WRITE, handler); + F->write_handler = handler; + F->write_data = client_data; + } } /* @@ -203,89 +193,80 @@ rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_d int rb_select_kqueue(long delay) { - int num, i; - struct timespec poll_time; - struct timespec *pt; - rb_fde_t *F; + int num, i; + struct timespec poll_time; + struct timespec *pt; + rb_fde_t *F; - if(delay < 0) - { - pt = NULL; - } - else - { - pt = &poll_time; - poll_time.tv_sec = delay / 1000; - poll_time.tv_nsec = (delay % 1000) * 1000000; - } + if(delay < 0) { + pt = NULL; + } else { + pt = &poll_time; + poll_time.tv_sec = delay / 1000; + poll_time.tv_nsec = (delay % 1000) * 1000000; + } - for(;;) - { - num = kevent(kq, kqlst, kqoff, kqout, kqmax, pt); - kqoff = 0; + for(;;) { + num = kevent(kq, kqlst, kqoff, kqout, kqmax, pt); + kqoff = 0; - if(num >= 0) - break; + if(num >= 0) + break; - if(rb_ignore_errno(errno)) - break; + if(rb_ignore_errno(errno)) + break; - rb_set_time(); + rb_set_time(); - return RB_ERROR; + return RB_ERROR; - /* NOTREACHED */ - } + /* NOTREACHED */ + } - rb_set_time(); + rb_set_time(); - if(num == 0) - return RB_OK; /* No error.. */ + if(num == 0) + return RB_OK; /* No error.. */ - for(i = 0; i < num; i++) - { - PF *hdl = NULL; + for(i = 0; i < num; i++) { + PF *hdl = NULL; - if(kqout[i].flags & EV_ERROR) - { - errno = kqout[i].data; - /* XXX error == bad! -- adrian */ - continue; /* XXX! */ - } + if(kqout[i].flags & EV_ERROR) { + errno = kqout[i].data; + /* XXX error == bad! -- adrian */ + continue; /* XXX! */ + } - switch (kqout[i].filter) - { + switch (kqout[i].filter) { - case EVFILT_READ: - F = kqout[i].udata; - if((hdl = F->read_handler) != NULL) - { - F->read_handler = NULL; - hdl(F, F->read_data); - } + case EVFILT_READ: + F = kqout[i].udata; + if((hdl = F->read_handler) != NULL) { + F->read_handler = NULL; + hdl(F, F->read_data); + } - break; + break; - case EVFILT_WRITE: - F = kqout[i].udata; - if((hdl = F->write_handler) != NULL) - { - F->write_handler = NULL; - hdl(F, F->write_data); - } - break; + case EVFILT_WRITE: + F = kqout[i].udata; + if((hdl = F->write_handler) != NULL) { + F->write_handler = NULL; + hdl(F, F->write_data); + } + break; #if defined(EVFILT_TIMER) - case EVFILT_TIMER: - rb_run_event(kqout[i].udata); - break; + case EVFILT_TIMER: + rb_run_event(kqout[i].udata); + break; #endif - default: - /* Bad! -- adrian */ - break; - } - } - return RB_OK; + default: + /* Bad! -- adrian */ + break; + } + } + return RB_OK; } #if defined(KQUEUE_SCHED_EVENT) @@ -293,59 +274,58 @@ static int can_do_event = 0; int rb_kqueue_supports_event(void) { - struct kevent kv; - struct timespec ts; - int xkq; + struct kevent kv; + struct timespec ts; + int xkq; - if(can_do_event == 1) - return 1; - if(can_do_event == -1) - return 0; + if(can_do_event == 1) + return 1; + if(can_do_event == -1) + return 0; - xkq = kqueue(); - ts.tv_sec = 0; - ts.tv_nsec = 1000; + xkq = kqueue(); + ts.tv_sec = 0; + ts.tv_nsec = 1000; - EV_SET(&kv, (uintptr_t)0x0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, 0); - if(kevent(xkq, &kv, 1, NULL, 0, NULL) < 0) - { - can_do_event = -1; - close(xkq); - return 0; - } - close(xkq); - can_do_event = 1; - return 1; + EV_SET(&kv, (uintptr_t)0x0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, 0); + if(kevent(xkq, &kv, 1, NULL, 0, NULL) < 0) { + can_do_event = -1; + close(xkq); + return 0; + } + close(xkq); + can_do_event = 1; + return 1; } int rb_kqueue_sched_event(struct ev_entry *event, int when) { - struct kevent kev; - int kep_flags; + struct kevent kev; + int kep_flags; - kep_flags = EV_ADD; - if(event->frequency == 0) - kep_flags |= EV_ONESHOT; - EV_SET(&kev, (uintptr_t)event, EVFILT_TIMER, kep_flags, 0, when * 1000, event); - if(kevent(kq, &kev, 1, NULL, 0, NULL) < 0) - return 0; - return 1; + kep_flags = EV_ADD; + if(event->frequency == 0) + kep_flags |= EV_ONESHOT; + EV_SET(&kev, (uintptr_t)event, EVFILT_TIMER, kep_flags, 0, when * 1000, event); + if(kevent(kq, &kev, 1, NULL, 0, NULL) < 0) + return 0; + return 1; } void rb_kqueue_unsched_event(struct ev_entry *event) { - struct kevent kev; - EV_SET(&kev, (uintptr_t)event, EVFILT_TIMER, EV_DELETE, 0, 0, event); - kevent(kq, &kev, 1, NULL, 0, NULL); + struct kevent kev; + EV_SET(&kev, (uintptr_t)event, EVFILT_TIMER, EV_DELETE, 0, 0, event); + kevent(kq, &kev, 1, NULL, 0, NULL); } void rb_kqueue_init_event(void) { - return; + return; } #endif /* KQUEUE_SCHED_EVENT */ @@ -353,29 +333,29 @@ rb_kqueue_init_event(void) int rb_init_netio_kqueue(void) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } void rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_kqueue(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_kqueue(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif @@ -384,26 +364,26 @@ rb_setup_fd_kqueue(rb_fde_t *F) void rb_kqueue_init_event(void) { - return; + return; } int rb_kqueue_sched_event(struct ev_entry *event, int when) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } void rb_kqueue_unsched_event(struct ev_entry *event) { - return; + return; } int rb_kqueue_supports_event(void) { - errno = ENOSYS; - return 0; + errno = ENOSYS; + return 0; } #endif /* !HAVE_KEVENT || !KQUEUE_SCHED_EVENT */ diff --git a/libratbox/src/linebuf.c b/libratbox/src/linebuf.c index f176412..ec6b0f0 100644 --- a/libratbox/src/linebuf.c +++ b/libratbox/src/linebuf.c @@ -44,22 +44,22 @@ static int bufline_count = 0; void rb_linebuf_init(size_t heap_size) { - rb_linebuf_heap = rb_bh_create(sizeof(buf_line_t), heap_size, "librb_linebuf_heap"); + rb_linebuf_heap = rb_bh_create(sizeof(buf_line_t), heap_size, "librb_linebuf_heap"); } static buf_line_t * rb_linebuf_allocate(void) { - buf_line_t *t; - t = rb_bh_alloc(rb_linebuf_heap); - return (t); + buf_line_t *t; + t = rb_bh_alloc(rb_linebuf_heap); + return (t); } static void rb_linebuf_free(buf_line_t * p) { - rb_bh_free(rb_linebuf_heap, p); + rb_bh_free(rb_linebuf_heap, p); } /* @@ -71,26 +71,26 @@ rb_linebuf_free(buf_line_t * p) static buf_line_t * rb_linebuf_new_line(buf_head_t * bufhead) { - buf_line_t *bufline; - rb_dlink_node *node; + buf_line_t *bufline; + rb_dlink_node *node; - bufline = rb_linebuf_allocate(); - if(bufline == NULL) - return NULL; - ++bufline_count; + bufline = rb_linebuf_allocate(); + if(bufline == NULL) + return NULL; + ++bufline_count; - node = rb_make_rb_dlink_node(); + node = rb_make_rb_dlink_node(); - /* Stick it at the end of the buf list */ - rb_dlinkAddTail(bufline, node, &bufhead->list); - bufline->refcount++; + /* Stick it at the end of the buf list */ + rb_dlinkAddTail(bufline, node, &bufhead->list); + bufline->refcount++; - /* And finally, update the allocated size */ - bufhead->alloclen++; - bufhead->numlines++; + /* And finally, update the allocated size */ + bufhead->alloclen++; + bufhead->numlines++; - return bufline; + return bufline; } @@ -102,25 +102,24 @@ rb_linebuf_new_line(buf_head_t * bufhead) static void rb_linebuf_done_line(buf_head_t * bufhead, buf_line_t * bufline, rb_dlink_node *node) { - /* Remove it from the linked list */ - rb_dlinkDestroy(node, &bufhead->list); + /* Remove it from the linked list */ + rb_dlinkDestroy(node, &bufhead->list); - /* Update the allocated size */ - bufhead->alloclen--; - bufhead->len -= bufline->len; - lrb_assert(bufhead->len >= 0); - bufhead->numlines--; + /* Update the allocated size */ + bufhead->alloclen--; + bufhead->len -= bufline->len; + lrb_assert(bufhead->len >= 0); + bufhead->numlines--; - bufline->refcount--; - lrb_assert(bufline->refcount >= 0); + bufline->refcount--; + lrb_assert(bufline->refcount >= 0); - if(bufline->refcount == 0) - { - /* and finally, deallocate the buf */ - --bufline_count; - lrb_assert(bufline_count >= 0); - rb_linebuf_free(bufline); - } + if(bufline->refcount == 0) { + /* and finally, deallocate the buf */ + --bufline_count; + lrb_assert(bufline_count >= 0); + rb_linebuf_free(bufline); + } } @@ -130,25 +129,23 @@ rb_linebuf_done_line(buf_head_t * bufhead, buf_line_t * bufline, rb_dlink_node * static inline int rb_linebuf_skip_crlf(char *ch, int len) { - int orig_len = len; + int orig_len = len; - /* First, skip until the first non-CRLF */ - for(; len; len--, ch++) - { - if(*ch == '\r') - break; - else if(*ch == '\n') - break; - } + /* First, skip until the first non-CRLF */ + for(; len; len--, ch++) { + if(*ch == '\r') + break; + else if(*ch == '\n') + break; + } - /* Then, skip until the last CRLF */ - for(; len; len--, ch++) - { - if((*ch != '\r') && (*ch != '\n')) - break; - } - lrb_assert(orig_len > len); - return (orig_len - len); + /* Then, skip until the last CRLF */ + for(; len; len--, ch++) { + if((*ch != '\r') && (*ch != '\n')) + break; + } + lrb_assert(orig_len > len); + return (orig_len - len); } @@ -161,8 +158,8 @@ rb_linebuf_skip_crlf(char *ch, int len) void rb_linebuf_newbuf(buf_head_t * bufhead) { - /* not much to do right now :) */ - memset(bufhead, 0, sizeof(buf_head_t)); + /* not much to do right now :) */ + memset(bufhead, 0, sizeof(buf_head_t)); } /* @@ -173,18 +170,17 @@ rb_linebuf_newbuf(buf_head_t * bufhead) void rb_linebuf_donebuf(buf_head_t * bufhead) { - while(bufhead->list.head != NULL) - { - rb_linebuf_done_line(bufhead, (buf_line_t *) bufhead->list.head->data, - bufhead->list.head); - } + while(bufhead->list.head != NULL) { + rb_linebuf_done_line(bufhead, (buf_line_t *) bufhead->list.head->data, + bufhead->list.head); + } } /* * rb_linebuf_copy_line * * Okay..this functions comments made absolutely no sense. - * + * * Basically what we do is this. Find the first chunk of text * and then scan for a CRLF. If we didn't find it, but we didn't * overflow our buffer..we wait for some more data. @@ -203,67 +199,63 @@ rb_linebuf_donebuf(buf_head_t * bufhead) static int rb_linebuf_copy_line(buf_head_t * bufhead, buf_line_t * bufline, char *data, int len) { - int cpylen = 0; /* how many bytes we've copied */ - char *ch = data; /* Pointer to where we are in the read data */ - char *bufch = bufline->buf + bufline->len; - int clen = 0; /* how many bytes we've processed, + int cpylen = 0; /* how many bytes we've copied */ + char *ch = data; /* Pointer to where we are in the read data */ + char *bufch = bufline->buf + bufline->len; + int clen = 0; /* how many bytes we've processed, and don't ever want to see again.. */ - /* If its full or terminated, ignore it */ + /* If its full or terminated, ignore it */ - bufline->raw = 0; - lrb_assert(bufline->len < BUF_DATA_SIZE); - if(bufline->terminated == 1) - return 0; + bufline->raw = 0; + lrb_assert(bufline->len < BUF_DATA_SIZE); + if(bufline->terminated == 1) + return 0; - clen = cpylen = rb_linebuf_skip_crlf(ch, len); - if(clen == -1) - return -1; + clen = cpylen = rb_linebuf_skip_crlf(ch, len); + if(clen == -1) + return -1; - /* This is the ~overflow case..This doesn't happen often.. */ - if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) - { - memcpy(bufch, ch, (BUF_DATA_SIZE - bufline->len - 1)); - bufline->buf[BUF_DATA_SIZE - 1] = '\0'; - bufch = bufline->buf + BUF_DATA_SIZE - 2; - while(cpylen && (*bufch == '\r' || *bufch == '\n')) - { - *bufch = '\0'; - cpylen--; - bufch--; - } - bufline->terminated = 1; - bufline->len = BUF_DATA_SIZE - 1; - bufhead->len += BUF_DATA_SIZE - 1; - return clen; - } + /* This is the ~overflow case..This doesn't happen often.. */ + if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) { + memcpy(bufch, ch, (BUF_DATA_SIZE - bufline->len - 1)); + bufline->buf[BUF_DATA_SIZE - 1] = '\0'; + bufch = bufline->buf + BUF_DATA_SIZE - 2; + while(cpylen && (*bufch == '\r' || *bufch == '\n')) { + *bufch = '\0'; + cpylen--; + bufch--; + } + bufline->terminated = 1; + bufline->len = BUF_DATA_SIZE - 1; + bufhead->len += BUF_DATA_SIZE - 1; + return clen; + } - memcpy(bufch, ch, cpylen); - bufch += cpylen; - *bufch = '\0'; - bufch--; + memcpy(bufch, ch, cpylen); + bufch += cpylen; + *bufch = '\0'; + bufch--; - if(*bufch != '\r' && *bufch != '\n') - { - /* No linefeed, bail for the next time */ - bufhead->len += cpylen; - bufline->len += cpylen; - bufline->terminated = 0; - return clen; - } + if(*bufch != '\r' && *bufch != '\n') { + /* No linefeed, bail for the next time */ + bufhead->len += cpylen; + bufline->len += cpylen; + bufline->terminated = 0; + return clen; + } - /* Yank the CRLF off this, replace with a \0 */ - while(cpylen && (*bufch == '\r' || *bufch == '\n')) - { - *bufch = '\0'; - cpylen--; - bufch--; - } + /* Yank the CRLF off this, replace with a \0 */ + while(cpylen && (*bufch == '\r' || *bufch == '\n')) { + *bufch = '\0'; + cpylen--; + bufch--; + } - bufline->terminated = 1; - bufhead->len += cpylen; - bufline->len += cpylen; - return clen; + bufline->terminated = 1; + bufhead->len += cpylen; + bufline->len += cpylen; + return clen; } /* @@ -276,54 +268,52 @@ rb_linebuf_copy_line(buf_head_t * bufhead, buf_line_t * bufline, char *data, int static int rb_linebuf_copy_raw(buf_head_t * bufhead, buf_line_t * bufline, char *data, int len) { - int cpylen = 0; /* how many bytes we've copied */ - char *ch = data; /* Pointer to where we are in the read data */ - char *bufch = bufline->buf + bufline->len; - int clen = 0; /* how many bytes we've processed, + int cpylen = 0; /* how many bytes we've copied */ + char *ch = data; /* Pointer to where we are in the read data */ + char *bufch = bufline->buf + bufline->len; + int clen = 0; /* how many bytes we've processed, and don't ever want to see again.. */ - /* If its full or terminated, ignore it */ + /* If its full or terminated, ignore it */ - bufline->raw = 1; - lrb_assert(bufline->len < BUF_DATA_SIZE); - if(bufline->terminated == 1) - return 0; + bufline->raw = 1; + lrb_assert(bufline->len < BUF_DATA_SIZE); + if(bufline->terminated == 1) + return 0; - clen = cpylen = rb_linebuf_skip_crlf(ch, len); - if(clen == -1) - return -1; + clen = cpylen = rb_linebuf_skip_crlf(ch, len); + if(clen == -1) + return -1; - /* This is the overflow case..This doesn't happen often.. */ - if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) - { - clen = BUF_DATA_SIZE - bufline->len - 1; - memcpy(bufch, ch, clen); - bufline->buf[BUF_DATA_SIZE - 1] = '\0'; - bufch = bufline->buf + BUF_DATA_SIZE - 2; - bufline->terminated = 1; - bufline->len = BUF_DATA_SIZE - 1; - bufhead->len += BUF_DATA_SIZE - 1; - return clen; - } + /* This is the overflow case..This doesn't happen often.. */ + if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) { + clen = BUF_DATA_SIZE - bufline->len - 1; + memcpy(bufch, ch, clen); + bufline->buf[BUF_DATA_SIZE - 1] = '\0'; + bufch = bufline->buf + BUF_DATA_SIZE - 2; + bufline->terminated = 1; + bufline->len = BUF_DATA_SIZE - 1; + bufhead->len += BUF_DATA_SIZE - 1; + return clen; + } - memcpy(bufch, ch, cpylen); - bufch += cpylen; - *bufch = '\0'; - bufch--; + memcpy(bufch, ch, cpylen); + bufch += cpylen; + *bufch = '\0'; + bufch--; - if(*bufch != '\r' && *bufch != '\n') - { - /* No linefeed, bail for the next time */ - bufhead->len += cpylen; - bufline->len += cpylen; - bufline->terminated = 0; - return clen; - } + if(*bufch != '\r' && *bufch != '\n') { + /* No linefeed, bail for the next time */ + bufhead->len += cpylen; + bufline->len += cpylen; + bufline->terminated = 0; + return clen; + } - bufline->terminated = 1; - bufhead->len += cpylen; - bufline->len += cpylen; - return clen; + bufline->terminated = 1; + bufhead->len += cpylen; + bufline->len += cpylen; + return clen; } @@ -347,56 +337,54 @@ rb_linebuf_copy_raw(buf_head_t * bufhead, buf_line_t * bufline, char *data, int int rb_linebuf_parse(buf_head_t * bufhead, char *data, int len, int raw) { - buf_line_t *bufline; - int cpylen; - int linecnt = 0; + buf_line_t *bufline; + int cpylen; + int linecnt = 0; - /* First, if we have a partial buffer, try to squeze data into it */ - if(bufhead->list.tail != NULL) - { - /* Check we're doing the partial buffer thing */ - bufline = bufhead->list.tail->data; - /* just try, the worst it could do is *reject* us .. */ - if(!raw) - cpylen = rb_linebuf_copy_line(bufhead, bufline, data, len); - else - cpylen = rb_linebuf_copy_raw(bufhead, bufline, data, len); + /* First, if we have a partial buffer, try to squeze data into it */ + if(bufhead->list.tail != NULL) { + /* Check we're doing the partial buffer thing */ + bufline = bufhead->list.tail->data; + /* just try, the worst it could do is *reject* us .. */ + if(!raw) + cpylen = rb_linebuf_copy_line(bufhead, bufline, data, len); + else + cpylen = rb_linebuf_copy_raw(bufhead, bufline, data, len); - if(cpylen == -1) - return -1; + if(cpylen == -1) + return -1; - linecnt++; - /* If we've copied the same as what we've got, quit now */ - if(cpylen == len) - return linecnt; /* all the data done so soon? */ + linecnt++; + /* If we've copied the same as what we've got, quit now */ + if(cpylen == len) + return linecnt; /* all the data done so soon? */ - /* Skip the data and update len .. */ - len -= cpylen; - lrb_assert(len >= 0); - data += cpylen; - } + /* Skip the data and update len .. */ + len -= cpylen; + lrb_assert(len >= 0); + data += cpylen; + } - /* Next, the loop */ - while(len > 0) - { - /* We obviously need a new buffer, so .. */ - bufline = rb_linebuf_new_line(bufhead); + /* Next, the loop */ + while(len > 0) { + /* We obviously need a new buffer, so .. */ + bufline = rb_linebuf_new_line(bufhead); - /* And parse */ - if(!raw) - cpylen = rb_linebuf_copy_line(bufhead, bufline, data, len); - else - cpylen = rb_linebuf_copy_raw(bufhead, bufline, data, len); + /* And parse */ + if(!raw) + cpylen = rb_linebuf_copy_line(bufhead, bufline, data, len); + else + cpylen = rb_linebuf_copy_raw(bufhead, bufline, data, len); - if(cpylen == -1) - return -1; + if(cpylen == -1) + return -1; - len -= cpylen; - lrb_assert(len >= 0); - data += cpylen; - linecnt++; - } - return linecnt; + len -= cpylen; + lrb_assert(len >= 0); + data += cpylen; + linecnt++; + } + return linecnt; } @@ -409,61 +397,58 @@ rb_linebuf_parse(buf_head_t * bufhead, char *data, int len, int raw) int rb_linebuf_get(buf_head_t * bufhead, char *buf, int buflen, int partial, int raw) { - buf_line_t *bufline; - int cpylen; - char *start, *ch; + buf_line_t *bufline; + int cpylen; + char *start, *ch; - /* make sure we have a line */ - if(bufhead->list.head == NULL) - return 0; /* Obviously not.. hrm. */ + /* make sure we have a line */ + if(bufhead->list.head == NULL) + return 0; /* Obviously not.. hrm. */ - bufline = bufhead->list.head->data; + bufline = bufhead->list.head->data; - /* make sure that the buffer was actually *terminated */ - if(!(partial || bufline->terminated)) - return 0; /* Wait for more data! */ + /* make sure that the buffer was actually *terminated */ + if(!(partial || bufline->terminated)) + return 0; /* Wait for more data! */ - if(buflen < bufline->len) - cpylen = buflen - 1; - else - cpylen = bufline->len; + if(buflen < bufline->len) + cpylen = buflen - 1; + else + cpylen = bufline->len; - /* Copy it */ - start = bufline->buf; + /* Copy it */ + start = bufline->buf; - /* if we left extraneous '\r\n' characters in the string, - * and we don't want to read the raw data, clean up the string. - */ - if(bufline->raw && !raw) - { - /* skip leading EOL characters */ - while(cpylen && (*start == '\r' || *start == '\n')) - { - start++; - cpylen--; - } - /* skip trailing EOL characters */ - ch = &start[cpylen - 1]; - while(cpylen && (*ch == '\r' || *ch == '\n')) - { - ch--; - cpylen--; - } - } + /* if we left extraneous '\r\n' characters in the string, + * and we don't want to read the raw data, clean up the string. + */ + if(bufline->raw && !raw) { + /* skip leading EOL characters */ + while(cpylen && (*start == '\r' || *start == '\n')) { + start++; + cpylen--; + } + /* skip trailing EOL characters */ + ch = &start[cpylen - 1]; + while(cpylen && (*ch == '\r' || *ch == '\n')) { + ch--; + cpylen--; + } + } - memcpy(buf, start, cpylen); + memcpy(buf, start, cpylen); - /* convert CR/LF to NULL */ - if(!raw) - buf[cpylen] = '\0'; + /* convert CR/LF to NULL */ + if(!raw) + buf[cpylen] = '\0'; - lrb_assert(cpylen >= 0); + lrb_assert(cpylen >= 0); - /* Deallocate the line */ - rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); + /* Deallocate the line */ + rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); - /* return how much we copied */ - return cpylen; + /* return how much we copied */ + return cpylen; } /* @@ -475,21 +460,20 @@ rb_linebuf_get(buf_head_t * bufhead, char *buf, int buflen, int partial, int raw void rb_linebuf_attach(buf_head_t * bufhead, buf_head_t * new) { - rb_dlink_node *ptr; - buf_line_t *line; + rb_dlink_node *ptr; + buf_line_t *line; - RB_DLINK_FOREACH(ptr, new->list.head) - { - line = ptr->data; - rb_dlinkAddTailAlloc(line, &bufhead->list); + RB_DLINK_FOREACH(ptr, new->list.head) { + line = ptr->data; + rb_dlinkAddTailAlloc(line, &bufhead->list); - /* Update the allocated size */ - bufhead->alloclen++; - bufhead->len += line->len; - bufhead->numlines++; + /* Update the allocated size */ + bufhead->alloclen++; + bufhead->len += line->len; + bufhead->numlines++; - line->refcount++; - } + line->refcount++; + } } @@ -504,119 +488,103 @@ rb_linebuf_attach(buf_head_t * bufhead, buf_head_t * new) */ void rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args, - const char *prefixfmt, ...) + const char *prefixfmt, ...) { - buf_line_t *bufline; - int len = 0; - va_list prefix_args; + buf_line_t *bufline; + int len = 0; + va_list prefix_args; - /* make sure the previous line is terminated */ + /* make sure the previous line is terminated */ #ifndef NDEBUG - if(bufhead->list.tail) - { - bufline = bufhead->list.tail->data; - lrb_assert(bufline->terminated); - } + if(bufhead->list.tail) { + bufline = bufhead->list.tail->data; + lrb_assert(bufline->terminated); + } #endif - /* Create a new line */ - bufline = rb_linebuf_new_line(bufhead); + /* Create a new line */ + bufline = rb_linebuf_new_line(bufhead); - if(prefixfmt != NULL) - { - va_start(prefix_args, prefixfmt); - len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, prefixfmt, prefix_args); - va_end(prefix_args); - } + if(prefixfmt != NULL) { + va_start(prefix_args, prefixfmt); + len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, prefixfmt, prefix_args); + va_end(prefix_args); + } - if(va_args != NULL) - { - len += rb_vsnprintf((bufline->buf + len), (BUF_DATA_SIZE - len), format, *va_args); - } + if(va_args != NULL) { + len += rb_vsnprintf((bufline->buf + len), (BUF_DATA_SIZE - len), format, *va_args); + } - bufline->terminated = 1; + bufline->terminated = 1; - /* Truncate the data if required */ - if(rb_unlikely(len > 510)) - { - len = 510; - bufline->buf[len++] = '\r'; - bufline->buf[len++] = '\n'; - } - else if(rb_unlikely(len == 0)) - { - bufline->buf[len++] = '\r'; - bufline->buf[len++] = '\n'; - bufline->buf[len] = '\0'; - } - else - { - /* Chop trailing CRLF's .. */ - while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') - || (bufline->buf[len] == '\0')) - { - len--; - } + /* Truncate the data if required */ + if(rb_unlikely(len > 510)) { + len = 510; + bufline->buf[len++] = '\r'; + bufline->buf[len++] = '\n'; + } else if(rb_unlikely(len == 0)) { + bufline->buf[len++] = '\r'; + bufline->buf[len++] = '\n'; + bufline->buf[len] = '\0'; + } else { + /* Chop trailing CRLF's .. */ + while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') + || (bufline->buf[len] == '\0')) { + len--; + } - bufline->buf[++len] = '\r'; - bufline->buf[++len] = '\n'; - bufline->buf[++len] = '\0'; - } + bufline->buf[++len] = '\r'; + bufline->buf[++len] = '\n'; + bufline->buf[++len] = '\0'; + } - bufline->len = len; - bufhead->len += len; + bufline->len = len; + bufhead->len += len; } void rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer) { - buf_line_t *bufline; - int len = 0; + buf_line_t *bufline; + int len = 0; - /* make sure the previous line is terminated */ + /* make sure the previous line is terminated */ #ifndef NDEBUG - if(bufhead->list.tail) - { - bufline = bufhead->list.tail->data; - lrb_assert(bufline->terminated); - } + if(bufhead->list.tail) { + bufline = bufhead->list.tail->data; + lrb_assert(bufline->terminated); + } #endif - /* Create a new line */ - bufline = rb_linebuf_new_line(bufhead); + /* Create a new line */ + bufline = rb_linebuf_new_line(bufhead); - if(rb_unlikely(buffer != NULL)) - len = rb_strlcpy(bufline->buf, buffer, BUF_DATA_SIZE); + if(rb_unlikely(buffer != NULL)) + len = rb_strlcpy(bufline->buf, buffer, BUF_DATA_SIZE); - bufline->terminated = 1; + bufline->terminated = 1; - /* Truncate the data if required */ - if(rb_unlikely(len > 510)) - { - len = 510; - bufline->buf[len++] = '\r'; - bufline->buf[len++] = '\n'; - } - else if(rb_unlikely(len == 0)) - { - bufline->buf[len++] = '\r'; - bufline->buf[len++] = '\n'; - bufline->buf[len] = '\0'; - } - else - { - /* Chop trailing CRLF's .. */ - while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') - || (bufline->buf[len] == '\0')) - { - len--; - } + /* Truncate the data if required */ + if(rb_unlikely(len > 510)) { + len = 510; + bufline->buf[len++] = '\r'; + bufline->buf[len++] = '\n'; + } else if(rb_unlikely(len == 0)) { + bufline->buf[len++] = '\r'; + bufline->buf[len++] = '\n'; + bufline->buf[len] = '\0'; + } else { + /* Chop trailing CRLF's .. */ + while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') + || (bufline->buf[len] == '\0')) { + len--; + } - bufline->buf[++len] = '\r'; - bufline->buf[++len] = '\n'; - bufline->buf[++len] = '\0'; - } + bufline->buf[++len] = '\r'; + bufline->buf[++len] = '\n'; + bufline->buf[++len] = '\0'; + } - bufline->len = len; - bufhead->len += len; + bufline->len = len; + bufhead->len += len; } @@ -624,59 +592,51 @@ rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer) void rb_linebuf_put(buf_head_t * bufhead, const char *format, ...) { - buf_line_t *bufline; - int len = 0; - va_list args; + buf_line_t *bufline; + int len = 0; + va_list args; - /* make sure the previous line is terminated */ + /* make sure the previous line is terminated */ #ifndef NDEBUG - if(bufhead->list.tail) - { - bufline = bufhead->list.tail->data; - lrb_assert(bufline->terminated); - } + if(bufhead->list.tail) { + bufline = bufhead->list.tail->data; + lrb_assert(bufline->terminated); + } #endif - /* Create a new line */ - bufline = rb_linebuf_new_line(bufhead); + /* Create a new line */ + bufline = rb_linebuf_new_line(bufhead); - if(rb_unlikely(format != NULL)) - { - va_start(args, format); - len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, format, args); - va_end(args); - } + if(rb_unlikely(format != NULL)) { + va_start(args, format); + len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, format, args); + va_end(args); + } - bufline->terminated = 1; + bufline->terminated = 1; - /* Truncate the data if required */ - if(rb_unlikely(len > 510)) - { - len = 510; - bufline->buf[len++] = '\r'; - bufline->buf[len++] = '\n'; - } - else if(rb_unlikely(len == 0)) - { - bufline->buf[len++] = '\r'; - bufline->buf[len++] = '\n'; - bufline->buf[len] = '\0'; - } - else - { - /* Chop trailing CRLF's .. */ - while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') - || (bufline->buf[len] == '\0')) - { - len--; - } + /* Truncate the data if required */ + if(rb_unlikely(len > 510)) { + len = 510; + bufline->buf[len++] = '\r'; + bufline->buf[len++] = '\n'; + } else if(rb_unlikely(len == 0)) { + bufline->buf[len++] = '\r'; + bufline->buf[len++] = '\n'; + bufline->buf[len] = '\0'; + } else { + /* Chop trailing CRLF's .. */ + while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') + || (bufline->buf[len] == '\0')) { + len--; + } - bufline->buf[++len] = '\r'; - bufline->buf[++len] = '\n'; - bufline->buf[++len] = '\0'; - } + bufline->buf[++len] = '\r'; + bufline->buf[++len] = '\n'; + bufline->buf[++len] = '\0'; + } - bufline->len = len; - bufhead->len += len; + bufline->len = len; + bufhead->len += len; } @@ -696,133 +656,120 @@ rb_linebuf_put(buf_head_t * bufhead, const char *format, ...) int rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead) { - buf_line_t *bufline; - int retval; + buf_line_t *bufline; + int retval; -/* - * autoconf checks for this..but really just want to use it if we have a - * native version even if libircd provides a fake version... - */ + /* + * autoconf checks for this..but really just want to use it if we have a + * native version even if libircd provides a fake version... + */ #ifdef HAVE_WRITEV - if(!rb_fd_ssl(F)) - { - rb_dlink_node *ptr; - int x = 0, y; - int xret; - static struct rb_iovec vec[RB_UIO_MAXIOV]; + if(!rb_fd_ssl(F)) { + rb_dlink_node *ptr; + int x = 0, y; + int xret; + static struct rb_iovec vec[RB_UIO_MAXIOV]; - memset(vec, 0, sizeof(vec)); - /* Check we actually have a first buffer */ - if(bufhead->list.head == NULL) - { - /* nope, so we return none .. */ - errno = EWOULDBLOCK; - return -1; - } + memset(vec, 0, sizeof(vec)); + /* Check we actually have a first buffer */ + if(bufhead->list.head == NULL) { + /* nope, so we return none .. */ + errno = EWOULDBLOCK; + return -1; + } - ptr = bufhead->list.head; + ptr = bufhead->list.head; - bufline = ptr->data; - if(!bufline->terminated) - { - errno = EWOULDBLOCK; - return -1; + bufline = ptr->data; + if(!bufline->terminated) { + errno = EWOULDBLOCK; + return -1; - } + } - vec[x].iov_base = bufline->buf + bufhead->writeofs; - vec[x++].iov_len = bufline->len - bufhead->writeofs; - ptr = ptr->next; + vec[x].iov_base = bufline->buf + bufhead->writeofs; + vec[x++].iov_len = bufline->len - bufhead->writeofs; + ptr = ptr->next; - do - { - if(ptr == NULL) - break; + do { + if(ptr == NULL) + break; - bufline = ptr->data; - if(!bufline->terminated) - break; + bufline = ptr->data; + if(!bufline->terminated) + break; - vec[x].iov_base = bufline->buf; - vec[x].iov_len = bufline->len; - ptr = ptr->next; + vec[x].iov_base = bufline->buf; + vec[x].iov_len = bufline->len; + ptr = ptr->next; - } - while(++x < RB_UIO_MAXIOV); + } while(++x < RB_UIO_MAXIOV); - if(x == 0) - { - errno = EWOULDBLOCK; - return -1; - } + if(x == 0) { + errno = EWOULDBLOCK; + return -1; + } - xret = retval = rb_writev(F, vec, x); - if(retval <= 0) - return retval; + xret = retval = rb_writev(F, vec, x); + if(retval <= 0) + return retval; - ptr = bufhead->list.head; + ptr = bufhead->list.head; - for(y = 0; y < x; y++) - { - bufline = ptr->data; + for(y = 0; y < x; y++) { + bufline = ptr->data; - if(xret >= bufline->len - bufhead->writeofs) - { - xret -= bufline->len - bufhead->writeofs; - ptr = ptr->next; - rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); - bufhead->writeofs = 0; - } - else - { - bufhead->writeofs += xret; - break; - } - } + if(xret >= bufline->len - bufhead->writeofs) { + xret -= bufline->len - bufhead->writeofs; + ptr = ptr->next; + rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); + bufhead->writeofs = 0; + } else { + bufhead->writeofs += xret; + break; + } + } - return retval; - } + return retval; + } #endif - /* this is the non-writev case */ + /* this is the non-writev case */ - /* Check we actually have a first buffer */ - if(bufhead->list.head == NULL) - { - /* nope, so we return none .. */ - errno = EWOULDBLOCK; - return -1; - } + /* Check we actually have a first buffer */ + if(bufhead->list.head == NULL) { + /* nope, so we return none .. */ + errno = EWOULDBLOCK; + return -1; + } - bufline = bufhead->list.head->data; + bufline = bufhead->list.head->data; - /* And that its actually full .. */ - if(!bufline->terminated) - { - errno = EWOULDBLOCK; - return -1; - } + /* And that its actually full .. */ + if(!bufline->terminated) { + errno = EWOULDBLOCK; + return -1; + } - /* Now, try writing data */ - retval = rb_write(F, bufline->buf + bufhead->writeofs, bufline->len - bufhead->writeofs); + /* Now, try writing data */ + retval = rb_write(F, bufline->buf + bufhead->writeofs, bufline->len - bufhead->writeofs); - if(retval <= 0) - return retval; + if(retval <= 0) + return retval; - /* we've got data, so update the write offset */ - bufhead->writeofs += retval; + /* we've got data, so update the write offset */ + bufhead->writeofs += retval; - /* if we've written everything *and* the CRLF, deallocate and update - bufhead */ - if(bufhead->writeofs == bufline->len) - { - bufhead->writeofs = 0; - lrb_assert(bufhead->len >= 0); - rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); - } + /* if we've written everything *and* the CRLF, deallocate and update + bufhead */ + if(bufhead->writeofs == bufline->len) { + bufhead->writeofs = 0; + lrb_assert(bufhead->len >= 0); + rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); + } - /* Return line length */ - return retval; + /* Return line length */ + return retval; } @@ -834,5 +781,5 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead) void rb_count_rb_linebuf_memory(size_t *count, size_t *rb_linebuf_memory_used) { - rb_bh_usage(rb_linebuf_heap, count, NULL, rb_linebuf_memory_used, NULL); + rb_bh_usage(rb_linebuf_heap, count, NULL, rb_linebuf_memory_used, NULL); } diff --git a/libratbox/src/nossl.c b/libratbox/src/nossl.c index 7f66123..74d9e34 100644 --- a/libratbox/src/nossl.c +++ b/libratbox/src/nossl.c @@ -1,4 +1,4 @@ -/* +/* * libratbox: a library used by ircd-ratbox and other things * nossl.c: ssl stub code * @@ -14,12 +14,12 @@ * 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 - * + * */ @@ -35,143 +35,142 @@ int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile) { - errno = ENOSYS; - return 0; + errno = ENOSYS; + return 0; } int rb_init_ssl(void) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } static void rb_stir_arc4random(void *unused) { - arc4random_stir(); + arc4random_stir(); } int rb_init_prng(const char *path, prng_seed_t seed_type) { - /* xxx this ignores the parameters above */ - arc4random_stir(); - rb_event_addish("rb_stir_arc4random", rb_stir_arc4random, NULL, 300); - return 1; + /* xxx this ignores the parameters above */ + arc4random_stir(); + rb_event_addish("rb_stir_arc4random", rb_stir_arc4random, NULL, 300); + return 1; } int rb_get_random(void *buf, size_t length) { - uint32_t rnd = 0, i; - uint8_t *xbuf = buf; - for(i = 0; i < length; i++) - { - if(i % 4 == 0) - rnd = arc4random(); - xbuf[i] = rnd; - rnd >>= 8; - } - return 1; + uint32_t rnd = 0, i; + uint8_t *xbuf = buf; + for(i = 0; i < length; i++) { + if(i % 4 == 0) + rnd = arc4random(); + xbuf[i] = rnd; + rnd >>= 8; + } + return 1; } int rb_get_pseudo_random(void *buf, size_t length) { - return rb_get_random(buf, length); + return rb_get_random(buf, length); } const char * rb_get_ssl_strerror(rb_fde_t *F) { - static const char *nosupport = "SSL/TLS not supported"; - return nosupport; + static const char *nosupport = "SSL/TLS not supported"; + return nosupport; } int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN]) { - return 0; + return 0; } void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout) { - return; + return; } void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout) { - return; + return; } void rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest, - struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) + struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) { - return; + return; } int rb_supports_ssl(void) { - return 0; + return 0; } void rb_ssl_shutdown(rb_fde_t *F) { - return; + return; } void rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen) { - return; + return; } ssize_t rb_ssl_read(rb_fde_t *F, void *buf, size_t count) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } ssize_t rb_ssl_write(rb_fde_t *F, const void *buf, size_t count) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } unsigned int rb_ssl_handshake_count(rb_fde_t *F) { - return 0; + return 0; } void rb_ssl_clear_handshake_count(rb_fde_t *F) { - return; + return; } void rb_get_ssl_info(char *buf, size_t len) { - rb_snprintf(buf, len, "Not compiled with SSL support"); + rb_snprintf(buf, len, "Not compiled with SSL support"); } - + #endif /* !HAVE_OPENSSL */ diff --git a/libratbox/src/openssl.c b/libratbox/src/openssl.c index 1606826..7747cb2 100644 --- a/libratbox/src/openssl.c +++ b/libratbox/src/openssl.c @@ -14,7 +14,7 @@ * 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 @@ -41,114 +41,109 @@ static int libratbox_index = -1; static unsigned long get_last_err(void) { - unsigned long t_err, err = 0; - err = ERR_get_error(); - if(err == 0) - return 0; + unsigned long t_err, err = 0; + err = ERR_get_error(); + if(err == 0) + return 0; - while((t_err = ERR_get_error()) > 0) - err = t_err; + while((t_err = ERR_get_error()) > 0) + err = t_err; - return err; + return err; } void rb_ssl_shutdown(rb_fde_t *F) { - int i; - if(F == NULL || F->ssl == NULL) - return; - SSL_set_shutdown((SSL *) F->ssl, SSL_RECEIVED_SHUTDOWN); + int i; + if(F == NULL || F->ssl == NULL) + return; + SSL_set_shutdown((SSL *) F->ssl, SSL_RECEIVED_SHUTDOWN); - for(i = 0; i < 4; i++) - { - if(SSL_shutdown((SSL *) F->ssl)) - break; - } - get_last_err(); - SSL_free((SSL *) F->ssl); + for(i = 0; i < 4; i++) { + if(SSL_shutdown((SSL *) F->ssl)) + break; + } + get_last_err(); + SSL_free((SSL *) F->ssl); } unsigned int rb_ssl_handshake_count(rb_fde_t *F) { - return F->handshake_count; + return F->handshake_count; } void rb_ssl_clear_handshake_count(rb_fde_t *F) { - F->handshake_count = 0; + F->handshake_count = 0; } static void rb_ssl_timeout(rb_fde_t *F, void *notused) { - lrb_assert(F->accept != NULL); - F->accept->callback(F, RB_ERR_TIMEOUT, NULL, 0, F->accept->data); + lrb_assert(F->accept != NULL); + F->accept->callback(F, RB_ERR_TIMEOUT, NULL, 0, F->accept->data); } static void rb_ssl_info_callback(SSL * ssl, int where, int ret) { - if(where & SSL_CB_HANDSHAKE_START) - { - rb_fde_t *F = SSL_get_ex_data(ssl, libratbox_index); - if(F == NULL) - return; - F->handshake_count++; - } + if(where & SSL_CB_HANDSHAKE_START) { + rb_fde_t *F = SSL_get_ex_data(ssl, libratbox_index); + if(F == NULL) + return; + F->handshake_count++; + } } static void rb_setup_ssl_cb(rb_fde_t *F) { - SSL_set_ex_data(F->ssl, libratbox_index, (char *)F); - SSL_set_info_callback((SSL *) F->ssl, (void (*)(const SSL *,int,int))rb_ssl_info_callback); + SSL_set_ex_data(F->ssl, libratbox_index, (char *)F); + SSL_set_info_callback((SSL *) F->ssl, (void (*)(const SSL *,int,int))rb_ssl_info_callback); } static void rb_ssl_tryaccept(rb_fde_t *F, void *data) { - int ssl_err; - lrb_assert(F->accept != NULL); - int flags; - struct acceptdata *ad; + int ssl_err; + lrb_assert(F->accept != NULL); + int flags; + struct acceptdata *ad; - if(!SSL_is_init_finished((SSL *) F->ssl)) - { - if((ssl_err = SSL_accept((SSL *) F->ssl)) <= 0) - { - switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) - { - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - if(ssl_err == SSL_ERROR_WANT_WRITE) - flags = RB_SELECT_WRITE; - else - flags = RB_SELECT_READ; - F->ssl_errno = get_last_err(); - rb_setselect(F, flags, rb_ssl_tryaccept, NULL); - break; - case SSL_ERROR_SYSCALL: - F->accept->callback(F, RB_ERROR, NULL, 0, F->accept->data); - break; - default: - F->ssl_errno = get_last_err(); - F->accept->callback(F, RB_ERROR_SSL, NULL, 0, F->accept->data); - break; - } - return; - } - } - rb_settimeout(F, 0, NULL, NULL); - rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL); + if(!SSL_is_init_finished((SSL *) F->ssl)) { + if((ssl_err = SSL_accept((SSL *) F->ssl)) <= 0) { + switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) { + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + if(ssl_err == SSL_ERROR_WANT_WRITE) + flags = RB_SELECT_WRITE; + else + flags = RB_SELECT_READ; + F->ssl_errno = get_last_err(); + rb_setselect(F, flags, rb_ssl_tryaccept, NULL); + break; + case SSL_ERROR_SYSCALL: + F->accept->callback(F, RB_ERROR, NULL, 0, F->accept->data); + break; + default: + F->ssl_errno = get_last_err(); + F->accept->callback(F, RB_ERROR_SSL, NULL, 0, F->accept->data); + break; + } + return; + } + } + rb_settimeout(F, 0, NULL, NULL); + rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL); - ad = F->accept; - F->accept = NULL; - ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); - rb_free(ad); + ad = F->accept; + F->accept = NULL; + ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); + rb_free(ad); } @@ -156,48 +151,43 @@ rb_ssl_tryaccept(rb_fde_t *F, void *data) static void rb_ssl_accept_common(rb_fde_t *new_F) { - int ssl_err; - if((ssl_err = SSL_accept((SSL *) new_F->ssl)) <= 0) - { - switch (ssl_err = SSL_get_error((SSL *) new_F->ssl, ssl_err)) - { - case SSL_ERROR_SYSCALL: - if(rb_ignore_errno(errno)) - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - { - new_F->ssl_errno = get_last_err(); - rb_setselect(new_F, RB_SELECT_READ | RB_SELECT_WRITE, - rb_ssl_tryaccept, NULL); - return; - } - default: - new_F->ssl_errno = get_last_err(); - new_F->accept->callback(new_F, RB_ERROR_SSL, NULL, 0, new_F->accept->data); - return; - } - } - else - { - rb_ssl_tryaccept(new_F, NULL); - } + int ssl_err; + if((ssl_err = SSL_accept((SSL *) new_F->ssl)) <= 0) { + switch (ssl_err = SSL_get_error((SSL *) new_F->ssl, ssl_err)) { + case SSL_ERROR_SYSCALL: + if(rb_ignore_errno(errno)) + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: { + new_F->ssl_errno = get_last_err(); + rb_setselect(new_F, RB_SELECT_READ | RB_SELECT_WRITE, + rb_ssl_tryaccept, NULL); + return; + } + default: + new_F->ssl_errno = get_last_err(); + new_F->accept->callback(new_F, RB_ERROR_SSL, NULL, 0, new_F->accept->data); + return; + } + } else { + rb_ssl_tryaccept(new_F, NULL); + } } void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout) { - new_F->type |= RB_FD_SSL; - new_F->ssl = SSL_new(ssl_server_ctx); - new_F->accept = rb_malloc(sizeof(struct acceptdata)); + new_F->type |= RB_FD_SSL; + new_F->ssl = SSL_new(ssl_server_ctx); + new_F->accept = rb_malloc(sizeof(struct acceptdata)); - new_F->accept->callback = cb; - new_F->accept->data = data; - rb_settimeout(new_F, timeout, rb_ssl_timeout, NULL); + new_F->accept->callback = cb; + new_F->accept->data = data; + rb_settimeout(new_F, timeout, rb_ssl_timeout, NULL); - new_F->accept->addrlen = 0; - SSL_set_fd((SSL *) new_F->ssl, rb_get_fd(new_F)); - rb_setup_ssl_cb(new_F); - rb_ssl_accept_common(new_F); + new_F->accept->addrlen = 0; + SSL_set_fd((SSL *) new_F->ssl, rb_get_fd(new_F)); + rb_setup_ssl_cb(new_F); + rb_ssl_accept_common(new_F); } @@ -206,464 +196,426 @@ rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout) void rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen) { - new_F->type |= RB_FD_SSL; - new_F->ssl = SSL_new(ssl_server_ctx); - new_F->accept = rb_malloc(sizeof(struct acceptdata)); + new_F->type |= RB_FD_SSL; + new_F->ssl = SSL_new(ssl_server_ctx); + new_F->accept = rb_malloc(sizeof(struct acceptdata)); - new_F->accept->callback = F->accept->callback; - new_F->accept->data = F->accept->data; - rb_settimeout(new_F, 10, rb_ssl_timeout, NULL); - memcpy(&new_F->accept->S, st, addrlen); - new_F->accept->addrlen = addrlen; + new_F->accept->callback = F->accept->callback; + new_F->accept->data = F->accept->data; + rb_settimeout(new_F, 10, rb_ssl_timeout, NULL); + memcpy(&new_F->accept->S, st, addrlen); + new_F->accept->addrlen = addrlen; - SSL_set_fd((SSL *) new_F->ssl, rb_get_fd(new_F)); - rb_setup_ssl_cb(new_F); - rb_ssl_accept_common(new_F); + SSL_set_fd((SSL *) new_F->ssl, rb_get_fd(new_F)); + rb_setup_ssl_cb(new_F); + rb_ssl_accept_common(new_F); } static ssize_t rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size_t count) { - ssize_t ret; - unsigned long err; - SSL *ssl = F->ssl; + ssize_t ret; + unsigned long err; + SSL *ssl = F->ssl; - if(r_or_w == 0) - ret = (ssize_t) SSL_read(ssl, rbuf, (int)count); - else - ret = (ssize_t) SSL_write(ssl, wbuf, (int)count); + if(r_or_w == 0) + ret = (ssize_t) SSL_read(ssl, rbuf, (int)count); + else + ret = (ssize_t) SSL_write(ssl, wbuf, (int)count); - if(ret < 0) - { - switch (SSL_get_error(ssl, ret)) - { - case SSL_ERROR_WANT_READ: - errno = EAGAIN; - return RB_RW_SSL_NEED_READ; - case SSL_ERROR_WANT_WRITE: - errno = EAGAIN; - return RB_RW_SSL_NEED_WRITE; - case SSL_ERROR_ZERO_RETURN: - return 0; - case SSL_ERROR_SYSCALL: - err = get_last_err(); - if(err == 0) - { - F->ssl_errno = 0; - return RB_RW_IO_ERROR; - } - break; - default: - err = get_last_err(); - break; - } - F->ssl_errno = err; - if(err > 0) - { - errno = EIO; /* not great but... */ - return RB_RW_SSL_ERROR; - } - return RB_RW_IO_ERROR; - } - return ret; + if(ret < 0) { + switch (SSL_get_error(ssl, ret)) { + case SSL_ERROR_WANT_READ: + errno = EAGAIN; + return RB_RW_SSL_NEED_READ; + case SSL_ERROR_WANT_WRITE: + errno = EAGAIN; + return RB_RW_SSL_NEED_WRITE; + case SSL_ERROR_ZERO_RETURN: + return 0; + case SSL_ERROR_SYSCALL: + err = get_last_err(); + if(err == 0) { + F->ssl_errno = 0; + return RB_RW_IO_ERROR; + } + break; + default: + err = get_last_err(); + break; + } + F->ssl_errno = err; + if(err > 0) { + errno = EIO; /* not great but... */ + return RB_RW_SSL_ERROR; + } + return RB_RW_IO_ERROR; + } + return ret; } ssize_t rb_ssl_read(rb_fde_t *F, void *buf, size_t count) { - return rb_ssl_read_or_write(0, F, buf, NULL, count); + return rb_ssl_read_or_write(0, F, buf, NULL, count); } ssize_t rb_ssl_write(rb_fde_t *F, const void *buf, size_t count) { - return rb_ssl_read_or_write(1, F, NULL, buf, count); + return rb_ssl_read_or_write(1, F, NULL, buf, count); } static int verify_accept_all_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) { - return 1; + return 1; } static const char * get_ssl_error(unsigned long err) { - static char buf[512]; + static char buf[512]; - ERR_error_string_n(err, buf, sizeof buf); - return buf; + ERR_error_string_n(err, buf, sizeof buf); + return buf; } int rb_init_ssl(void) { - int ret = 1; - char libratbox_data[] = "libratbox data"; - SSL_load_error_strings(); - SSL_library_init(); - libratbox_index = SSL_get_ex_new_index(0, libratbox_data, NULL, NULL, NULL); - ssl_server_ctx = SSL_CTX_new(SSLv23_server_method()); - if(ssl_server_ctx == NULL) - { - rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL server context: %s", - get_ssl_error(ERR_get_error())); - ret = 0; - } - /* Disable SSLv2, make the client use our settings */ - SSL_CTX_set_options(ssl_server_ctx, SSL_OP_NO_SSLv2 | SSL_OP_CIPHER_SERVER_PREFERENCE); - SSL_CTX_set_verify(ssl_server_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_accept_all_cb); + int ret = 1; + char libratbox_data[] = "libratbox data"; + SSL_load_error_strings(); + SSL_library_init(); + libratbox_index = SSL_get_ex_new_index(0, libratbox_data, NULL, NULL, NULL); + ssl_server_ctx = SSL_CTX_new(SSLv23_server_method()); + if(ssl_server_ctx == NULL) { + rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL server context: %s", + get_ssl_error(ERR_get_error())); + ret = 0; + } + /* Disable SSLv2, make the client use our settings */ + SSL_CTX_set_options(ssl_server_ctx, SSL_OP_NO_SSLv2 | SSL_OP_CIPHER_SERVER_PREFERENCE); + SSL_CTX_set_verify(ssl_server_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_accept_all_cb); - ssl_client_ctx = SSL_CTX_new(TLSv1_client_method()); + ssl_client_ctx = SSL_CTX_new(TLSv1_client_method()); - if(ssl_client_ctx == NULL) - { - rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL client context: %s", - get_ssl_error(ERR_get_error())); - ret = 0; - } - return ret; + if(ssl_client_ctx == NULL) { + rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL client context: %s", + get_ssl_error(ERR_get_error())); + ret = 0; + } + return ret; } int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile) { - DH *dh; - unsigned long err; - if(cert == NULL) - { - rb_lib_log("rb_setup_ssl_server: No certificate file"); - return 0; - } - if(!SSL_CTX_use_certificate_chain_file(ssl_server_ctx, cert) || !SSL_CTX_use_certificate_chain_file(ssl_client_ctx, cert)) - { - err = ERR_get_error(); - rb_lib_log("rb_setup_ssl_server: Error loading certificate file [%s]: %s", cert, - get_ssl_error(err)); - return 0; - } + DH *dh; + unsigned long err; + if(cert == NULL) { + rb_lib_log("rb_setup_ssl_server: No certificate file"); + return 0; + } + if(!SSL_CTX_use_certificate_chain_file(ssl_server_ctx, cert) || !SSL_CTX_use_certificate_chain_file(ssl_client_ctx, cert)) { + err = ERR_get_error(); + rb_lib_log("rb_setup_ssl_server: Error loading certificate file [%s]: %s", cert, + get_ssl_error(err)); + return 0; + } - if(keyfile == NULL) - { - rb_lib_log("rb_setup_ssl_server: No key file"); - return 0; - } + if(keyfile == NULL) { + rb_lib_log("rb_setup_ssl_server: No key file"); + return 0; + } - if(!SSL_CTX_use_PrivateKey_file(ssl_server_ctx, keyfile, SSL_FILETYPE_PEM) || !SSL_CTX_use_PrivateKey_file(ssl_client_ctx, keyfile, SSL_FILETYPE_PEM)) - { - err = ERR_get_error(); - rb_lib_log("rb_setup_ssl_server: Error loading keyfile [%s]: %s", keyfile, - get_ssl_error(err)); - return 0; - } + if(!SSL_CTX_use_PrivateKey_file(ssl_server_ctx, keyfile, SSL_FILETYPE_PEM) || !SSL_CTX_use_PrivateKey_file(ssl_client_ctx, keyfile, SSL_FILETYPE_PEM)) { + err = ERR_get_error(); + rb_lib_log("rb_setup_ssl_server: Error loading keyfile [%s]: %s", keyfile, + get_ssl_error(err)); + return 0; + } - if(dhfile != NULL) - { - /* DH parameters aren't necessary, but they are nice..if they didn't pass one..that is their problem */ - BIO *bio = BIO_new_file(dhfile, "r"); - if(bio != NULL) - { - dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); - if(dh == NULL) - { - err = ERR_get_error(); - rb_lib_log - ("rb_setup_ssl_server: Error loading DH params file [%s]: %s", - dhfile, get_ssl_error(err)); - BIO_free(bio); - return 0; - } - BIO_free(bio); - SSL_CTX_set_tmp_dh(ssl_server_ctx, dh); - } - else - { - err = ERR_get_error(); - rb_lib_log("rb_setup_ssl_server: Error loading DH params file [%s]: %s", - dhfile, get_ssl_error(err)); - } - } - return 1; + if(dhfile != NULL) { + /* DH parameters aren't necessary, but they are nice..if they didn't pass one..that is their problem */ + BIO *bio = BIO_new_file(dhfile, "r"); + if(bio != NULL) { + dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); + if(dh == NULL) { + err = ERR_get_error(); + rb_lib_log + ("rb_setup_ssl_server: Error loading DH params file [%s]: %s", + dhfile, get_ssl_error(err)); + BIO_free(bio); + return 0; + } + BIO_free(bio); + SSL_CTX_set_tmp_dh(ssl_server_ctx, dh); + } else { + err = ERR_get_error(); + rb_lib_log("rb_setup_ssl_server: Error loading DH params file [%s]: %s", + dhfile, get_ssl_error(err)); + } + } + return 1; } int rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept) { - int result; + int result; - result = rb_listen(F, backlog, defer_accept); - F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL; + result = rb_listen(F, backlog, defer_accept); + F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL; - return result; + return result; } -struct ssl_connect -{ - CNCB *callback; - void *data; - int timeout; +struct ssl_connect { + CNCB *callback; + void *data; + int timeout; }; static void rb_ssl_connect_realcb(rb_fde_t *F, int status, struct ssl_connect *sconn) { - F->connect->callback = sconn->callback; - F->connect->data = sconn->data; - rb_free(sconn); - rb_connect_callback(F, status); + F->connect->callback = sconn->callback; + F->connect->data = sconn->data; + rb_free(sconn); + rb_connect_callback(F, status); } static void rb_ssl_tryconn_timeout_cb(rb_fde_t *F, void *data) { - rb_ssl_connect_realcb(F, RB_ERR_TIMEOUT, data); + rb_ssl_connect_realcb(F, RB_ERR_TIMEOUT, data); } static void rb_ssl_tryconn_cb(rb_fde_t *F, void *data) { - struct ssl_connect *sconn = data; - int ssl_err; - if(!SSL_is_init_finished((SSL *) F->ssl)) - { - if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) - { - switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) - { - case SSL_ERROR_SYSCALL: - if(rb_ignore_errno(errno)) - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - { - F->ssl_errno = get_last_err(); - rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, - rb_ssl_tryconn_cb, sconn); - return; - } - default: - F->ssl_errno = get_last_err(); - rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); - return; - } - } - else - { - rb_ssl_connect_realcb(F, RB_OK, sconn); - } - } + struct ssl_connect *sconn = data; + int ssl_err; + if(!SSL_is_init_finished((SSL *) F->ssl)) { + if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) { + switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) { + case SSL_ERROR_SYSCALL: + if(rb_ignore_errno(errno)) + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: { + F->ssl_errno = get_last_err(); + rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, + rb_ssl_tryconn_cb, sconn); + return; + } + default: + F->ssl_errno = get_last_err(); + rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); + return; + } + } else { + rb_ssl_connect_realcb(F, RB_OK, sconn); + } + } } static void rb_ssl_tryconn(rb_fde_t *F, int status, void *data) { - struct ssl_connect *sconn = data; - int ssl_err; - if(status != RB_OK) - { - rb_ssl_connect_realcb(F, status, sconn); - return; - } + struct ssl_connect *sconn = data; + int ssl_err; + if(status != RB_OK) { + rb_ssl_connect_realcb(F, status, sconn); + return; + } - F->type |= RB_FD_SSL; - F->ssl = SSL_new(ssl_client_ctx); - SSL_set_fd((SSL *) F->ssl, F->fd); - rb_setup_ssl_cb(F); - rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); - if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) - { - switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) - { - case SSL_ERROR_SYSCALL: - if(rb_ignore_errno(errno)) - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - { - F->ssl_errno = get_last_err(); - rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, - rb_ssl_tryconn_cb, sconn); - return; - } - default: - F->ssl_errno = get_last_err(); - rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); - return; - } - } - else - { - rb_ssl_connect_realcb(F, RB_OK, sconn); - } + F->type |= RB_FD_SSL; + F->ssl = SSL_new(ssl_client_ctx); + SSL_set_fd((SSL *) F->ssl, F->fd); + rb_setup_ssl_cb(F); + rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); + if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) { + switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) { + case SSL_ERROR_SYSCALL: + if(rb_ignore_errno(errno)) + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: { + F->ssl_errno = get_last_err(); + rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, + rb_ssl_tryconn_cb, sconn); + return; + } + default: + F->ssl_errno = get_last_err(); + rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); + return; + } + } else { + rb_ssl_connect_realcb(F, RB_OK, sconn); + } } void rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest, - struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) + struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout) { - struct ssl_connect *sconn; - if(F == NULL) - return; + struct ssl_connect *sconn; + if(F == NULL) + return; - sconn = rb_malloc(sizeof(struct ssl_connect)); - sconn->data = data; - sconn->callback = callback; - sconn->timeout = timeout; - rb_connect_tcp(F, dest, clocal, socklen, rb_ssl_tryconn, sconn, timeout); + sconn = rb_malloc(sizeof(struct ssl_connect)); + sconn->data = data; + sconn->callback = callback; + sconn->timeout = timeout; + rb_connect_tcp(F, dest, clocal, socklen, rb_ssl_tryconn, sconn, timeout); } void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout) { - struct ssl_connect *sconn; - int ssl_err; - if(F == NULL) - return; + struct ssl_connect *sconn; + int ssl_err; + if(F == NULL) + return; - sconn = rb_malloc(sizeof(struct ssl_connect)); - sconn->data = data; - sconn->callback = callback; - sconn->timeout = timeout; - F->connect = rb_malloc(sizeof(struct conndata)); - F->connect->callback = callback; - F->connect->data = data; - F->type |= RB_FD_SSL; - F->ssl = SSL_new(ssl_client_ctx); + sconn = rb_malloc(sizeof(struct ssl_connect)); + sconn->data = data; + sconn->callback = callback; + sconn->timeout = timeout; + F->connect = rb_malloc(sizeof(struct conndata)); + F->connect->callback = callback; + F->connect->data = data; + F->type |= RB_FD_SSL; + F->ssl = SSL_new(ssl_client_ctx); - SSL_set_fd((SSL *) F->ssl, F->fd); - rb_setup_ssl_cb(F); - rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); - if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) - { - switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) - { - case SSL_ERROR_SYSCALL: - if(rb_ignore_errno(errno)) - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - { - F->ssl_errno = get_last_err(); - rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, - rb_ssl_tryconn_cb, sconn); - return; - } - default: - F->ssl_errno = get_last_err(); - rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); - return; - } - } - else - { - rb_ssl_connect_realcb(F, RB_OK, sconn); - } + SSL_set_fd((SSL *) F->ssl, F->fd); + rb_setup_ssl_cb(F); + rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); + if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) { + switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) { + case SSL_ERROR_SYSCALL: + if(rb_ignore_errno(errno)) + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: { + F->ssl_errno = get_last_err(); + rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, + rb_ssl_tryconn_cb, sconn); + return; + } + default: + F->ssl_errno = get_last_err(); + rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); + return; + } + } else { + rb_ssl_connect_realcb(F, RB_OK, sconn); + } } int rb_init_prng(const char *path, prng_seed_t seed_type) { - if(seed_type == RB_PRNG_DEFAULT) - { + if(seed_type == RB_PRNG_DEFAULT) { #ifdef _WIN32 - RAND_screen(); + RAND_screen(); #endif - return RAND_status(); - } - if(path == NULL) - return RAND_status(); + return RAND_status(); + } + if(path == NULL) + return RAND_status(); - switch (seed_type) - { - case RB_PRNG_EGD: - if(RAND_egd(path) == -1) - return -1; - break; - case RB_PRNG_FILE: - if(RAND_load_file(path, -1) == -1) - return -1; - break; + switch (seed_type) { + case RB_PRNG_EGD: + if(RAND_egd(path) == -1) + return -1; + break; + case RB_PRNG_FILE: + if(RAND_load_file(path, -1) == -1) + return -1; + break; #ifdef _WIN32 - case RB_PRNGWIN32: - RAND_screen(); - break; + case RB_PRNGWIN32: + RAND_screen(); + break; #endif - default: - return -1; - } + default: + return -1; + } - return RAND_status(); + return RAND_status(); } int rb_get_random(void *buf, size_t length) { - int ret; + int ret; - if((ret = RAND_bytes(buf, length)) == 0) - { - /* remove the error from the queue */ - ERR_get_error(); - } - return ret; + if((ret = RAND_bytes(buf, length)) == 0) { + /* remove the error from the queue */ + ERR_get_error(); + } + return ret; } int rb_get_pseudo_random(void *buf, size_t length) { - int ret; - ret = RAND_pseudo_bytes(buf, length); - if(ret < 0) - return 0; - return 1; + int ret; + ret = RAND_pseudo_bytes(buf, length); + if(ret < 0) + return 0; + return 1; } const char * rb_get_ssl_strerror(rb_fde_t *F) { - return get_ssl_error(F->ssl_errno); + return get_ssl_error(F->ssl_errno); } int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN]) { - X509 *cert; - int res; + X509 *cert; + int res; - if (F->ssl == NULL) - return 0; + if (F->ssl == NULL) + return 0; - cert = SSL_get_peer_certificate((SSL *) F->ssl); - if(cert != NULL) - { - res = SSL_get_verify_result((SSL *) F->ssl); - if(res == X509_V_OK || - res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN || - res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE || - res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) - { - memcpy(certfp, cert->sha1_hash, RB_SSL_CERTFP_LEN); - X509_free(cert); - return 1; - } - X509_free(cert); - } + cert = SSL_get_peer_certificate((SSL *) F->ssl); + if(cert != NULL) { + res = SSL_get_verify_result((SSL *) F->ssl); + if(res == X509_V_OK || + res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN || + res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE || + res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) { + memcpy(certfp, cert->sha1_hash, RB_SSL_CERTFP_LEN); + X509_free(cert); + return 1; + } + X509_free(cert); + } - return 0; + return 0; } int rb_supports_ssl(void) { - return 1; + return 1; } void rb_get_ssl_info(char *buf, size_t len) { - rb_snprintf(buf, len, "Using SSL: %s compiled: 0x%lx, library 0x%lx", - SSLeay_version(SSLEAY_VERSION), - (long)OPENSSL_VERSION_NUMBER, SSLeay()); + rb_snprintf(buf, len, "Using SSL: %s compiled: 0x%lx, library 0x%lx", + SSLeay_version(SSLEAY_VERSION), + (long)OPENSSL_VERSION_NUMBER, SSLeay()); } diff --git a/libratbox/src/patricia.c b/libratbox/src/patricia.c index 438763e..f0a84f2 100644 --- a/libratbox/src/patricia.c +++ b/libratbox/src/patricia.c @@ -1,13 +1,13 @@ /* * Yanked out of Net::Patricia by Aaron Sethman - * + * * This was then yanked out of the ratbox/devel/src tree and stuffed into * libratbox and had function names changed, but otherwise not really altered. * * Dave Plonka * * This product includes software developed by the University of Michigan, - * Merit Network, Inc., and their contributors. + * Merit Network, Inc., and their contributors. * * This file had been called "radix.c" in the MRT sources. * @@ -34,7 +34,7 @@ void rb_init_patricia(void) { - return; + return; } /* prefix_tochar @@ -43,44 +43,41 @@ rb_init_patricia(void) static uint8_t * prefix_tochar(rb_prefix_t *prefix) { - if(prefix == NULL) - return (NULL); + if(prefix == NULL) + return (NULL); - return ((uint8_t *)&prefix->add.sin); + return ((uint8_t *)&prefix->add.sin); } static int comp_with_mask(void *addr, void *dest, unsigned int mask) { - if( /* mask/8 == 0 || */ memcmp(addr, dest, mask / 8) == 0) - { - int n = mask / 8; - int m = ((-1) << (8 - (mask % 8))); + if( /* mask/8 == 0 || */ memcmp(addr, dest, mask / 8) == 0) { + int n = mask / 8; + int m = ((-1) << (8 - (mask % 8))); - if(mask % 8 == 0 || (((uint8_t *)addr)[n] & m) == (((uint8_t *)dest)[n] & m)) - return (1); - } - return (0); + if(mask % 8 == 0 || (((uint8_t *)addr)[n] & m) == (((uint8_t *)dest)[n] & m)) + return (1); + } + return (0); } #ifdef NOTYET static char * prefix_toa2x(rb_prefix_t *prefix, char *buf, int buf_len, int with_len) { - static char tmp[6]; - if(prefix == NULL) - { - rb_strlcpy(buf, "(NULL)", buf_len); - return (buf); - } - inet_ntop(prefix->family, &prefix->add.sin, buf, buf_len); - if(with_len) - { - rb_snprintf(tmp, sizeof(tmp), "/%d", prefix->bitlen); - strcat(buf, tmp); - } - return (buf); + static char tmp[6]; + if(prefix == NULL) { + rb_strlcpy(buf, "(NULL)", buf_len); + return (buf); + } + inet_ntop(prefix->family, &prefix->add.sin, buf, buf_len); + if(with_len) { + rb_snprintf(tmp, sizeof(tmp), "/%d", prefix->bitlen); + strcat(buf, tmp); + } + return (buf); } /* prefix_toa2 @@ -90,71 +87,63 @@ prefix_toa2x(rb_prefix_t *prefix, char *buf, int buf_len, int with_len) static char * prefix_toa2(rb_prefix_t *prefix, char *buff, int buf_len) { - return (prefix_toa2x(prefix, buff, buf_len, 0)); + return (prefix_toa2x(prefix, buff, buf_len, 0)); } static char * prefix_toa(rb_prefix_t *prefix) { #ifdef RB_IPV6 - static char buf[INET6_ADDRSTRLEN + 6]; + static char buf[INET6_ADDRSTRLEN + 6]; #else - static char buf[16 + 6]; + static char buf[16 + 6]; #endif - return (prefix_toa2(prefix, buf, sizeof(buf))); + return (prefix_toa2(prefix, buf, sizeof(buf))); } #endif static rb_prefix_t * New_Prefix2(int family, void *dest, int bitlen, rb_prefix_t *prefix) { - int dynamic_allocated = 0; + int dynamic_allocated = 0; #ifdef RB_IPV6 - int default_bitlen = 128; + int default_bitlen = 128; #else - int default_bitlen = 32; + int default_bitlen = 32; #endif #ifdef RB_IPV6 - if(family == AF_INET6) - { - default_bitlen = 128; - if(prefix == NULL) - { - prefix = rb_malloc(sizeof(rb_prefix_t)); - dynamic_allocated++; - } - memcpy(&prefix->add.sin6, dest, 16); - } - else + if(family == AF_INET6) { + default_bitlen = 128; + if(prefix == NULL) { + prefix = rb_malloc(sizeof(rb_prefix_t)); + dynamic_allocated++; + } + memcpy(&prefix->add.sin6, dest, 16); + } else #endif /* RB_IPV6 */ - if(family == AF_INET) - { - if(prefix == NULL) - { - prefix = rb_malloc(sizeof(rb_prefix_t)); - dynamic_allocated++; - } - memcpy(&prefix->add.sin, dest, 4); - } - else - { - return (NULL); - } + if(family == AF_INET) { + if(prefix == NULL) { + prefix = rb_malloc(sizeof(rb_prefix_t)); + dynamic_allocated++; + } + memcpy(&prefix->add.sin, dest, 4); + } else { + return (NULL); + } - prefix->bitlen = (bitlen >= 0) ? bitlen : default_bitlen; - prefix->family = family; - prefix->ref_count = 0; - if(dynamic_allocated) - { - prefix->ref_count++; - } - return (prefix); + prefix->bitlen = (bitlen >= 0) ? bitlen : default_bitlen; + prefix->family = family; + prefix->ref_count = 0; + if(dynamic_allocated) { + prefix->ref_count++; + } + return (prefix); } static rb_prefix_t * New_Prefix(int family, void *dest, int bitlen) { - return (New_Prefix2(family, dest, bitlen, NULL)); + return (New_Prefix2(family, dest, bitlen, NULL)); } /* ascii2prefix @@ -162,107 +151,97 @@ New_Prefix(int family, void *dest, int bitlen) static rb_prefix_t * ascii2prefix(int family, const char *string) { - long bitlen, maxbitlen = 0; - char *cp; - struct in_addr sinaddr; + long bitlen, maxbitlen = 0; + char *cp; + struct in_addr sinaddr; #ifdef RB_IPV6 - struct in6_addr sinaddr6; + struct in6_addr sinaddr6; #endif /* RB_IPV6 */ - int result; - char save[MAXLINE]; + int result; + char save[MAXLINE]; - if(string == NULL) - return (NULL); + if(string == NULL) + return (NULL); - /* easy way to handle both families */ - if(family == 0) - { - family = AF_INET; + /* easy way to handle both families */ + if(family == 0) { + family = AF_INET; #ifdef RB_IPV6 - if(strchr(string, ':')) - family = AF_INET6; + if(strchr(string, ':')) + family = AF_INET6; #endif /* RB_IPV6 */ - } - if(family == AF_INET) - { - maxbitlen = 32; - } + } + if(family == AF_INET) { + maxbitlen = 32; + } #ifdef RB_IPV6 - else if(family == AF_INET6) - { - maxbitlen = 128; - } + else if(family == AF_INET6) { + maxbitlen = 128; + } #endif /* RB_IPV6 */ - if((cp = strchr(string, '/')) != NULL) - { - bitlen = atol(cp + 1); - /* *cp = '\0'; */ - /* copy the string to save. Avoid destroying the string */ - assert(cp - string < MAXLINE); - memcpy(save, string, cp - string); - save[cp - string] = '\0'; - string = save; - if(bitlen <= 0 || bitlen > maxbitlen) - bitlen = maxbitlen; - } - else - { - bitlen = maxbitlen; - } + if((cp = strchr(string, '/')) != NULL) { + bitlen = atol(cp + 1); + /* *cp = '\0'; */ + /* copy the string to save. Avoid destroying the string */ + assert(cp - string < MAXLINE); + memcpy(save, string, cp - string); + save[cp - string] = '\0'; + string = save; + if(bitlen <= 0 || bitlen > maxbitlen) + bitlen = maxbitlen; + } else { + bitlen = maxbitlen; + } - if(family == AF_INET) - { - if((result = rb_inet_pton(AF_INET, string, &sinaddr)) <= 0) - return (NULL); - return (New_Prefix(AF_INET, &sinaddr, bitlen)); - } + if(family == AF_INET) { + if((result = rb_inet_pton(AF_INET, string, &sinaddr)) <= 0) + return (NULL); + return (New_Prefix(AF_INET, &sinaddr, bitlen)); + } #ifdef RB_IPV6 - else if(family == AF_INET6) - { - if((result = rb_inet_pton(AF_INET6, string, &sinaddr6)) <= 0) - return (NULL); - return (New_Prefix(AF_INET6, &sinaddr6, bitlen)); - } + else if(family == AF_INET6) { + if((result = rb_inet_pton(AF_INET6, string, &sinaddr6)) <= 0) + return (NULL); + return (New_Prefix(AF_INET6, &sinaddr6, bitlen)); + } #endif /* RB_IPV6 */ - else - return (NULL); + else + return (NULL); } static rb_prefix_t * Ref_Prefix(rb_prefix_t *prefix) { - if(prefix == NULL) - return (NULL); - if(prefix->ref_count == 0) - { - /* make a copy in case of a static prefix */ - return (New_Prefix2(prefix->family, &prefix->add, prefix->bitlen, NULL)); - } - prefix->ref_count++; - return (prefix); + if(prefix == NULL) + return (NULL); + if(prefix->ref_count == 0) { + /* make a copy in case of a static prefix */ + return (New_Prefix2(prefix->family, &prefix->add, prefix->bitlen, NULL)); + } + prefix->ref_count++; + return (prefix); } static void Deref_Prefix(rb_prefix_t *prefix) { - if(prefix == NULL) - return; - /* for secure programming, raise an assert. no static prefix can call this */ - assert(prefix->ref_count > 0); + if(prefix == NULL) + return; + /* for secure programming, raise an assert. no static prefix can call this */ + assert(prefix->ref_count > 0); - prefix->ref_count--; - assert(prefix->ref_count >= 0); - if(prefix->ref_count <= 0) - { - rb_free(prefix); - return; - } + prefix->ref_count--; + assert(prefix->ref_count >= 0); + if(prefix->ref_count <= 0) { + rb_free(prefix); + return; + } } /* } */ -// #define PATRICIA_DEBUG 1 +// #define PATRICIA_DEBUG 1 static int num_active_patricia = 0; @@ -271,14 +250,14 @@ static int num_active_patricia = 0; rb_patricia_tree_t * rb_new_patricia(int maxbits) { - rb_patricia_tree_t *patricia = rb_malloc(sizeof(rb_patricia_tree_t)); + rb_patricia_tree_t *patricia = rb_malloc(sizeof(rb_patricia_tree_t)); - patricia->maxbits = maxbits; - patricia->head = NULL; - patricia->num_active_node = 0; - assert(maxbits <= RB_PATRICIA_MAXBITS); /* XXX */ - num_active_patricia++; - return (patricia); + patricia->maxbits = maxbits; + patricia->head = NULL; + patricia->num_active_node = 0; + assert(maxbits <= RB_PATRICIA_MAXBITS); /* XXX */ + num_active_patricia++; + return (patricia); } @@ -290,64 +269,51 @@ rb_new_patricia(int maxbits) void rb_clear_patricia(rb_patricia_tree_t *patricia, void (*func) (void *)) { - assert(patricia); - if(patricia->head) - { + assert(patricia); + if(patricia->head) { - rb_patricia_node_t *Xstack[RB_PATRICIA_MAXBITS + 1]; - rb_patricia_node_t **Xsp = Xstack; - rb_patricia_node_t *Xrn = patricia->head; + rb_patricia_node_t *Xstack[RB_PATRICIA_MAXBITS + 1]; + rb_patricia_node_t **Xsp = Xstack; + rb_patricia_node_t *Xrn = patricia->head; - while(Xrn) - { - rb_patricia_node_t *l = Xrn->l; - rb_patricia_node_t *r = Xrn->r; + while(Xrn) { + rb_patricia_node_t *l = Xrn->l; + rb_patricia_node_t *r = Xrn->r; - if(Xrn->prefix) - { - Deref_Prefix(Xrn->prefix); - if(Xrn->data && func) - func(Xrn->data); - } - else - { - assert(Xrn->data == NULL); - } - rb_free(Xrn); - patricia->num_active_node--; + if(Xrn->prefix) { + Deref_Prefix(Xrn->prefix); + if(Xrn->data && func) + func(Xrn->data); + } else { + assert(Xrn->data == NULL); + } + rb_free(Xrn); + patricia->num_active_node--; - if(l) - { - if(r) - { - *Xsp++ = r; - } - Xrn = l; - } - else if(r) - { - Xrn = r; - } - else if(Xsp != Xstack) - { - Xrn = *(--Xsp); - } - else - { - Xrn = (rb_patricia_node_t *)0; - } - } - } - assert(patricia->num_active_node == 0); - rb_free(patricia); + if(l) { + if(r) { + *Xsp++ = r; + } + Xrn = l; + } else if(r) { + Xrn = r; + } else if(Xsp != Xstack) { + Xrn = *(--Xsp); + } else { + Xrn = (rb_patricia_node_t *)0; + } + } + } + assert(patricia->num_active_node == 0); + rb_free(patricia); } void rb_destroy_patricia(rb_patricia_tree_t *patricia, void (*func) (void *)) { - rb_clear_patricia(patricia, func); - num_active_patricia--; + rb_clear_patricia(patricia, func); + num_active_patricia--; } @@ -358,722 +324,643 @@ rb_destroy_patricia(rb_patricia_tree_t *patricia, void (*func) (void *)) void rb_patricia_process(rb_patricia_tree_t *patricia, void (*func) (rb_prefix_t *, void *)) { - rb_patricia_node_t *node; - assert(func); + rb_patricia_node_t *node; + assert(func); - RB_PATRICIA_WALK(patricia->head, node) - { - func(node->prefix, node->data); - } - RB_PATRICIA_WALK_END; + RB_PATRICIA_WALK(patricia->head, node) { + func(node->prefix, node->data); + } + RB_PATRICIA_WALK_END; } rb_patricia_node_t * rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix) { - rb_patricia_node_t *node; - uint8_t *addr; - unsigned int bitlen; + rb_patricia_node_t *node; + uint8_t *addr; + unsigned int bitlen; - assert(patricia); - assert(prefix); - assert(prefix->bitlen <= patricia->maxbits); + assert(patricia); + assert(prefix); + assert(prefix->bitlen <= patricia->maxbits); - if(patricia->head == NULL) - return (NULL); + if(patricia->head == NULL) + return (NULL); - node = patricia->head; - addr = rb_prefix_touchar(prefix); - bitlen = prefix->bitlen; + node = patricia->head; + addr = rb_prefix_touchar(prefix); + bitlen = prefix->bitlen; - while(node->bit < bitlen) - { + while(node->bit < bitlen) { - if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) - { + if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) { #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, - "patricia_search_exact: take right %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, - "patricia_search_exact: take right at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, + "patricia_search_exact: take right %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, + "patricia_search_exact: take right at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - node = node->r; - } - else - { + node = node->r; + } else { #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, - "patricia_search_exact: take left %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, - "patricia_search_exact: take left at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, + "patricia_search_exact: take left %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, + "patricia_search_exact: take left at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - node = node->l; - } + node = node->l; + } - if(node == NULL) - return (NULL); - } + if(node == NULL) + return (NULL); + } #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, "patricia_search_exact: stop at %s/%d %d\n", - prefix_toa(node->prefix), node->prefix->bitlen, node->bit); - else - fprintf(stderr, "patricia_search_exact: stop at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, "patricia_search_exact: stop at %s/%d %d\n", + prefix_toa(node->prefix), node->prefix->bitlen, node->bit); + else + fprintf(stderr, "patricia_search_exact: stop at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - if(node->bit > bitlen || node->prefix == NULL) - return (NULL); - assert(node->bit == bitlen); - assert(node->bit == node->prefix->bitlen); - if(comp_with_mask(prefix_tochar(node->prefix), prefix_tochar(prefix), bitlen)) - { + if(node->bit > bitlen || node->prefix == NULL) + return (NULL); + assert(node->bit == bitlen); + assert(node->bit == node->prefix->bitlen); + if(comp_with_mask(prefix_tochar(node->prefix), prefix_tochar(prefix), bitlen)) { #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_search_exact: found %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_search_exact: found %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - return (node); - } - return (NULL); + return (node); + } + return (NULL); } /* if inclusive != 0, "best" may be the given prefix itself */ rb_patricia_node_t * rb_patricia_search_best2(rb_patricia_tree_t *patricia, rb_prefix_t *prefix, int inclusive) { - rb_patricia_node_t *node; - rb_patricia_node_t *stack[RB_PATRICIA_MAXBITS + 1]; - uint8_t *addr; - unsigned int bitlen; - int cnt = 0; + rb_patricia_node_t *node; + rb_patricia_node_t *stack[RB_PATRICIA_MAXBITS + 1]; + uint8_t *addr; + unsigned int bitlen; + int cnt = 0; - assert(patricia); - assert(prefix); - assert(prefix->bitlen <= patricia->maxbits); + assert(patricia); + assert(prefix); + assert(prefix->bitlen <= patricia->maxbits); - if(patricia->head == NULL) - return (NULL); + if(patricia->head == NULL) + return (NULL); - node = patricia->head; - addr = rb_prefix_touchar(prefix); - bitlen = prefix->bitlen; + node = patricia->head; + addr = rb_prefix_touchar(prefix); + bitlen = prefix->bitlen; - while(node->bit < bitlen) - { + while(node->bit < bitlen) { - if(node->prefix) - { + if(node->prefix) { #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_search_best: push %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, + "patricia_search_best: push %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - stack[cnt++] = node; - } + stack[cnt++] = node; + } - if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) - { + if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) { #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, - "patricia_search_best: take right %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, - "patricia_search_best: take right at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, + "patricia_search_best: take right %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, + "patricia_search_best: take right at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - node = node->r; - } - else - { + node = node->r; + } else { #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, - "patricia_search_best: take left %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, - "patricia_search_best: take left at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, + "patricia_search_best: take left %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, + "patricia_search_best: take left at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - node = node->l; - } + node = node->l; + } - if(node == NULL) - break; - } + if(node == NULL) + break; + } - if(inclusive && node && node->prefix) - stack[cnt++] = node; + if(inclusive && node && node->prefix) + stack[cnt++] = node; #ifdef PATRICIA_DEBUG - if(node == NULL) - fprintf(stderr, "patricia_search_best: stop at null\n"); - else if(node->prefix) - fprintf(stderr, "patricia_search_best: stop at %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, "patricia_search_best: stop at %d\n", node->bit); + if(node == NULL) + fprintf(stderr, "patricia_search_best: stop at null\n"); + else if(node->prefix) + fprintf(stderr, "patricia_search_best: stop at %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, "patricia_search_best: stop at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - if(cnt <= 0) - return (NULL); + if(cnt <= 0) + return (NULL); - while(--cnt >= 0) - { - node = stack[cnt]; + while(--cnt >= 0) { + node = stack[cnt]; #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_search_best: pop %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_search_best: pop %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - if(comp_with_mask(prefix_tochar(node->prefix), - prefix_tochar(prefix), node->prefix->bitlen)) - { + if(comp_with_mask(prefix_tochar(node->prefix), + prefix_tochar(prefix), node->prefix->bitlen)) { #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_search_best: found %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, + "patricia_search_best: found %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - return (node); - } - } - return (NULL); + return (node); + } + } + return (NULL); } rb_patricia_node_t * rb_patricia_search_best(rb_patricia_tree_t *patricia, rb_prefix_t *prefix) { - return (rb_patricia_search_best2(patricia, prefix, 1)); + return (rb_patricia_search_best2(patricia, prefix, 1)); } rb_patricia_node_t * rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix) { - rb_patricia_node_t *node, *new_node, *parent, *glue; - uint8_t *addr, *test_addr; - unsigned int bitlen, check_bit, differ_bit; - unsigned int i, j, r; + rb_patricia_node_t *node, *new_node, *parent, *glue; + uint8_t *addr, *test_addr; + unsigned int bitlen, check_bit, differ_bit; + unsigned int i, j, r; - assert(patricia); - assert(prefix); - assert(prefix->bitlen <= patricia->maxbits); + assert(patricia); + assert(prefix); + assert(prefix->bitlen <= patricia->maxbits); - if(patricia->head == NULL) - { - node = rb_malloc(sizeof(rb_patricia_node_t)); - node->bit = prefix->bitlen; - node->prefix = Ref_Prefix(prefix); - node->parent = NULL; - node->l = node->r = NULL; - node->data = NULL; - patricia->head = node; + if(patricia->head == NULL) { + node = rb_malloc(sizeof(rb_patricia_node_t)); + node->bit = prefix->bitlen; + node->prefix = Ref_Prefix(prefix); + node->parent = NULL; + node->l = node->r = NULL; + node->data = NULL; + patricia->head = node; #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_lookup: new_node #0 %s/%d (head)\n", - prefix_toa(prefix), prefix->bitlen); + fprintf(stderr, + "patricia_lookup: new_node #0 %s/%d (head)\n", + prefix_toa(prefix), prefix->bitlen); #endif /* PATRICIA_DEBUG */ - patricia->num_active_node++; - return (node); - } + patricia->num_active_node++; + return (node); + } - addr = rb_prefix_touchar(prefix); - bitlen = prefix->bitlen; - node = patricia->head; + addr = rb_prefix_touchar(prefix); + bitlen = prefix->bitlen; + node = patricia->head; - while(node->bit < bitlen || node->prefix == NULL) - { + while(node->bit < bitlen || node->prefix == NULL) { - if(node->bit < patricia->maxbits && - BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) - { - if(node->r == NULL) - break; + if(node->bit < patricia->maxbits && + BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) { + if(node->r == NULL) + break; #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, - "patricia_lookup: take right %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, "patricia_lookup: take right at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, + "patricia_lookup: take right %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, "patricia_lookup: take right at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - node = node->r; - } - else - { - if(node->l == NULL) - break; + node = node->r; + } else { + if(node->l == NULL) + break; #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, - "patricia_lookup: take left %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, "patricia_lookup: take left at %d\n", node->bit); + if(node->prefix) + fprintf(stderr, + "patricia_lookup: take left %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, "patricia_lookup: take left at %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - node = node->l; - } + node = node->l; + } - assert(node); - } + assert(node); + } - assert(node->prefix); + assert(node->prefix); #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_lookup: stop at %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_lookup: stop at %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - test_addr = rb_prefix_touchar(node->prefix); - /* find the first bit different */ - check_bit = (node->bit < bitlen) ? node->bit : bitlen; - differ_bit = 0; - for(i = 0; i * 8 < check_bit; i++) - { - if((r = (addr[i] ^ test_addr[i])) == 0) - { - differ_bit = (i + 1) * 8; - continue; - } - /* I know the better way, but for now */ - for(j = 0; j < 8; j++) - { - if(BIT_TEST(r, (0x80 >> j))) - break; - } - /* must be found */ - assert(j < 8); - differ_bit = i * 8 + j; - break; - } - if(differ_bit > check_bit) - differ_bit = check_bit; + test_addr = rb_prefix_touchar(node->prefix); + /* find the first bit different */ + check_bit = (node->bit < bitlen) ? node->bit : bitlen; + differ_bit = 0; + for(i = 0; i * 8 < check_bit; i++) { + if((r = (addr[i] ^ test_addr[i])) == 0) { + differ_bit = (i + 1) * 8; + continue; + } + /* I know the better way, but for now */ + for(j = 0; j < 8; j++) { + if(BIT_TEST(r, (0x80 >> j))) + break; + } + /* must be found */ + assert(j < 8); + differ_bit = i * 8 + j; + break; + } + if(differ_bit > check_bit) + differ_bit = check_bit; #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_lookup: differ_bit %d\n", differ_bit); + fprintf(stderr, "patricia_lookup: differ_bit %d\n", differ_bit); #endif /* PATRICIA_DEBUG */ - parent = node->parent; - while(parent && parent->bit >= differ_bit) - { - node = parent; - parent = node->parent; + parent = node->parent; + while(parent && parent->bit >= differ_bit) { + node = parent; + parent = node->parent; #ifdef PATRICIA_DEBUG - if(node->prefix) - fprintf(stderr, "patricia_lookup: up to %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); - else - fprintf(stderr, "patricia_lookup: up to %d\n", node->bit); + if(node->prefix) + fprintf(stderr, "patricia_lookup: up to %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); + else + fprintf(stderr, "patricia_lookup: up to %d\n", node->bit); #endif /* PATRICIA_DEBUG */ - } + } - if(differ_bit == bitlen && node->bit == bitlen) - { - if(node->prefix) - { + if(differ_bit == bitlen && node->bit == bitlen) { + if(node->prefix) { #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_lookup: found %s/%d\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_lookup: found %s/%d\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - return (node); - } - node->prefix = Ref_Prefix(prefix); + return (node); + } + node->prefix = Ref_Prefix(prefix); #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_lookup: new node #1 %s/%d (glue mod)\n", - prefix_toa(prefix), prefix->bitlen); + fprintf(stderr, + "patricia_lookup: new node #1 %s/%d (glue mod)\n", + prefix_toa(prefix), prefix->bitlen); #endif /* PATRICIA_DEBUG */ - assert(node->data == NULL); - return (node); - } + assert(node->data == NULL); + return (node); + } - new_node = rb_malloc(sizeof(rb_patricia_node_t)); - new_node->bit = prefix->bitlen; - new_node->prefix = Ref_Prefix(prefix); - new_node->parent = NULL; - new_node->l = new_node->r = NULL; - new_node->data = NULL; - patricia->num_active_node++; + new_node = rb_malloc(sizeof(rb_patricia_node_t)); + new_node->bit = prefix->bitlen; + new_node->prefix = Ref_Prefix(prefix); + new_node->parent = NULL; + new_node->l = new_node->r = NULL; + new_node->data = NULL; + patricia->num_active_node++; - if(node->bit == differ_bit) - { - new_node->parent = node; - if(node->bit < patricia->maxbits && - BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) - { - assert(node->r == NULL); - node->r = new_node; - } - else - { - assert(node->l == NULL); - node->l = new_node; - } + if(node->bit == differ_bit) { + new_node->parent = node; + if(node->bit < patricia->maxbits && + BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) { + assert(node->r == NULL); + node->r = new_node; + } else { + assert(node->l == NULL); + node->l = new_node; + } #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_lookup: new_node #2 %s/%d (child)\n", - prefix_toa(prefix), prefix->bitlen); + fprintf(stderr, + "patricia_lookup: new_node #2 %s/%d (child)\n", + prefix_toa(prefix), prefix->bitlen); #endif /* PATRICIA_DEBUG */ - return (new_node); - } + return (new_node); + } - if(bitlen == differ_bit) - { - if(bitlen < patricia->maxbits && - BIT_TEST(test_addr[bitlen >> 3], 0x80 >> (bitlen & 0x07))) - { - new_node->r = node; - } - else - { - new_node->l = node; - } - new_node->parent = node->parent; - if(node->parent == NULL) - { - assert(patricia->head == node); - patricia->head = new_node; - } - else if(node->parent->r == node) - { - node->parent->r = new_node; - } - else - { - node->parent->l = new_node; - } - node->parent = new_node; + if(bitlen == differ_bit) { + if(bitlen < patricia->maxbits && + BIT_TEST(test_addr[bitlen >> 3], 0x80 >> (bitlen & 0x07))) { + new_node->r = node; + } else { + new_node->l = node; + } + new_node->parent = node->parent; + if(node->parent == NULL) { + assert(patricia->head == node); + patricia->head = new_node; + } else if(node->parent->r == node) { + node->parent->r = new_node; + } else { + node->parent->l = new_node; + } + node->parent = new_node; #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_lookup: new_node #3 %s/%d (parent)\n", - prefix_toa(prefix), prefix->bitlen); + fprintf(stderr, + "patricia_lookup: new_node #3 %s/%d (parent)\n", + prefix_toa(prefix), prefix->bitlen); #endif /* PATRICIA_DEBUG */ - } - else - { - glue = rb_malloc(sizeof(rb_patricia_node_t)); - glue->bit = differ_bit; - glue->prefix = NULL; - glue->parent = node->parent; - glue->data = NULL; - patricia->num_active_node++; - if(differ_bit < patricia->maxbits && - BIT_TEST(addr[differ_bit >> 3], 0x80 >> (differ_bit & 0x07))) - { - glue->r = new_node; - glue->l = node; - } - else - { - glue->r = node; - glue->l = new_node; - } - new_node->parent = glue; + } else { + glue = rb_malloc(sizeof(rb_patricia_node_t)); + glue->bit = differ_bit; + glue->prefix = NULL; + glue->parent = node->parent; + glue->data = NULL; + patricia->num_active_node++; + if(differ_bit < patricia->maxbits && + BIT_TEST(addr[differ_bit >> 3], 0x80 >> (differ_bit & 0x07))) { + glue->r = new_node; + glue->l = node; + } else { + glue->r = node; + glue->l = new_node; + } + new_node->parent = glue; - if(node->parent == NULL) - { - assert(patricia->head == node); - patricia->head = glue; - } - else if(node->parent->r == node) - { - node->parent->r = glue; - } - else - { - node->parent->l = glue; - } - node->parent = glue; + if(node->parent == NULL) { + assert(patricia->head == node); + patricia->head = glue; + } else if(node->parent->r == node) { + node->parent->r = glue; + } else { + node->parent->l = glue; + } + node->parent = glue; #ifdef PATRICIA_DEBUG - fprintf(stderr, - "patricia_lookup: new_node #4 %s/%d (glue+node)\n", - prefix_toa(prefix), prefix->bitlen); + fprintf(stderr, + "patricia_lookup: new_node #4 %s/%d (glue+node)\n", + prefix_toa(prefix), prefix->bitlen); #endif /* PATRICIA_DEBUG */ - } - return (new_node); + } + return (new_node); } void rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node) { - rb_patricia_node_t *parent, *child; + rb_patricia_node_t *parent, *child; - assert(patricia); - assert(node); + assert(patricia); + assert(node); - if(node->r && node->l) - { + if(node->r && node->l) { #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_remove: #0 %s/%d (r & l)\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_remove: #0 %s/%d (r & l)\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - /* this might be a placeholder node -- have to check and make sure - * there is a prefix aossciated with it ! */ - if(node->prefix != NULL) - Deref_Prefix(node->prefix); - node->prefix = NULL; - /* Also I needed to clear data pointer -- masaki */ - node->data = NULL; - return; - } + /* this might be a placeholder node -- have to check and make sure + * there is a prefix aossciated with it ! */ + if(node->prefix != NULL) + Deref_Prefix(node->prefix); + node->prefix = NULL; + /* Also I needed to clear data pointer -- masaki */ + node->data = NULL; + return; + } - if(node->r == NULL && node->l == NULL) - { + if(node->r == NULL && node->l == NULL) { #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_remove: #1 %s/%d (!r & !l)\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_remove: #1 %s/%d (!r & !l)\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - parent = node->parent; - Deref_Prefix(node->prefix); - rb_free(node); - patricia->num_active_node--; + parent = node->parent; + Deref_Prefix(node->prefix); + rb_free(node); + patricia->num_active_node--; - if(parent == NULL) - { - assert(patricia->head == node); - patricia->head = NULL; - return; - } + if(parent == NULL) { + assert(patricia->head == node); + patricia->head = NULL; + return; + } - if(parent->r == node) - { - parent->r = NULL; - child = parent->l; - } - else - { - assert(parent->l == node); - parent->l = NULL; - child = parent->r; - } + if(parent->r == node) { + parent->r = NULL; + child = parent->l; + } else { + assert(parent->l == node); + parent->l = NULL; + child = parent->r; + } - if(parent->prefix) - return; + if(parent->prefix) + return; - /* we need to remove parent too */ + /* we need to remove parent too */ - if(parent->parent == NULL) - { - assert(patricia->head == parent); - patricia->head = child; - } - else if(parent->parent->r == parent) - { - parent->parent->r = child; - } - else - { - assert(parent->parent->l == parent); - parent->parent->l = child; - } - child->parent = parent->parent; - rb_free(parent); - patricia->num_active_node--; - return; - } + if(parent->parent == NULL) { + assert(patricia->head == parent); + patricia->head = child; + } else if(parent->parent->r == parent) { + parent->parent->r = child; + } else { + assert(parent->parent->l == parent); + parent->parent->l = child; + } + child->parent = parent->parent; + rb_free(parent); + patricia->num_active_node--; + return; + } #ifdef PATRICIA_DEBUG - fprintf(stderr, "patricia_remove: #2 %s/%d (r ^ l)\n", - prefix_toa(node->prefix), node->prefix->bitlen); + fprintf(stderr, "patricia_remove: #2 %s/%d (r ^ l)\n", + prefix_toa(node->prefix), node->prefix->bitlen); #endif /* PATRICIA_DEBUG */ - if(node->r) - { - child = node->r; - } - else - { - assert(node->l); - child = node->l; - } - parent = node->parent; - child->parent = parent; + if(node->r) { + child = node->r; + } else { + assert(node->l); + child = node->l; + } + parent = node->parent; + child->parent = parent; - Deref_Prefix(node->prefix); - rb_free(node); - patricia->num_active_node--; + Deref_Prefix(node->prefix); + rb_free(node); + patricia->num_active_node--; - if(parent == NULL) - { - assert(patricia->head == node); - patricia->head = child; - return; - } + if(parent == NULL) { + assert(patricia->head == node); + patricia->head = child; + return; + } - if(parent->r == node) - { - parent->r = child; - } - else - { - assert(parent->l == node); - parent->l = child; - } + if(parent->r == node) { + parent->r = child; + } else { + assert(parent->l == node); + parent->l = child; + } } rb_patricia_node_t * make_and_lookup_ip(rb_patricia_tree_t *tree, struct sockaddr *in, int bitlen) { - rb_prefix_t *prefix; - rb_patricia_node_t *node; - void *ipptr = NULL; + rb_prefix_t *prefix; + rb_patricia_node_t *node; + void *ipptr = NULL; #ifdef RB_IPV6 - if(in->sa_family == AF_INET6) - ipptr = &((struct sockaddr_in6 *)in)->sin6_addr; - else + if(in->sa_family == AF_INET6) + ipptr = &((struct sockaddr_in6 *)in)->sin6_addr; + else #endif - ipptr = &((struct sockaddr_in *)in)->sin_addr; + ipptr = &((struct sockaddr_in *)in)->sin_addr; - prefix = New_Prefix(in->sa_family, ipptr, bitlen); + prefix = New_Prefix(in->sa_family, ipptr, bitlen); - if(prefix == NULL) - return NULL; + if(prefix == NULL) + return NULL; - node = rb_patricia_lookup(tree, prefix); + node = rb_patricia_lookup(tree, prefix); - Deref_Prefix(prefix); - return (node); + Deref_Prefix(prefix); + return (node); } rb_patricia_node_t * make_and_lookup(rb_patricia_tree_t *tree, const char *string) { - rb_prefix_t *prefix; - rb_patricia_node_t *node; + rb_prefix_t *prefix; + rb_patricia_node_t *node; - if((prefix = ascii2prefix(AF_INET, string)) != NULL) - { - node = rb_patricia_lookup(tree, prefix); - } - else + if((prefix = ascii2prefix(AF_INET, string)) != NULL) { + node = rb_patricia_lookup(tree, prefix); + } else #ifdef RB_IPV6 - if((prefix = ascii2prefix(AF_INET6, string)) != NULL) - { - node = rb_patricia_lookup(tree, prefix); - } - else + if((prefix = ascii2prefix(AF_INET6, string)) != NULL) { + node = rb_patricia_lookup(tree, prefix); + } else #endif - return NULL; + return NULL; #ifdef PATRICIA_DEBUG - printf("make_and_lookup: %s/%d\n", prefix_toa(prefix), prefix->bitlen); + printf("make_and_lookup: %s/%d\n", prefix_toa(prefix), prefix->bitlen); #endif - Deref_Prefix(prefix); - return (node); + Deref_Prefix(prefix); + return (node); } #ifdef NOTYET static rb_patricia_node_t * try_search_exact(rb_patricia_tree_t *tree, char *string) { - rb_prefix_t *prefix; - rb_patricia_node_t *node; - if((prefix = ascii2prefix(AF_INET, string)) != NULL) - { - node = rb_patricia_search_exact(tree, prefix); - Deref_Prefix(prefix); - return (node); - } + rb_prefix_t *prefix; + rb_patricia_node_t *node; + if((prefix = ascii2prefix(AF_INET, string)) != NULL) { + node = rb_patricia_search_exact(tree, prefix); + Deref_Prefix(prefix); + return (node); + } #ifdef RB_IPV6 - else if((prefix = ascii2prefix(AF_INET6, string)) != NULL) - { - node = rb_patricia_search_exact(tree, prefix); - Deref_Prefix(prefix); - return (node); - } + else if((prefix = ascii2prefix(AF_INET6, string)) != NULL) { + node = rb_patricia_search_exact(tree, prefix); + Deref_Prefix(prefix); + return (node); + } #endif - else - return NULL; + else + return NULL; } void lookup_then_remove(rb_patricia_tree_t *tree, char *string) { - rb_patricia_node_t *node; + rb_patricia_node_t *node; - if((node = try_search_exact(tree, string))) - patricia_remove(tree, node); + if((node = try_search_exact(tree, string))) + patricia_remove(tree, node); } #endif rb_patricia_node_t * rb_match_ip(rb_patricia_tree_t *tree, struct sockaddr *ip) { - rb_prefix_t *prefix; - rb_patricia_node_t *node; - void *ipptr; - unsigned int len; - int family; + rb_prefix_t *prefix; + rb_patricia_node_t *node; + void *ipptr; + unsigned int len; + int family; #ifndef RB_IPV6 - len = 32; - family = AF_INET; - ipptr = &((struct sockaddr_in *)ip)->sin_addr; + len = 32; + family = AF_INET; + ipptr = &((struct sockaddr_in *)ip)->sin_addr; #else - if(ip->sa_family == AF_INET6) - { - len = 128; - family = AF_INET6; - ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr; - } - else - { - len = 32; - family = AF_INET; - ipptr = &((struct sockaddr_in *)ip)->sin_addr; - } + if(ip->sa_family == AF_INET6) { + len = 128; + family = AF_INET6; + ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr; + } else { + len = 32; + family = AF_INET; + ipptr = &((struct sockaddr_in *)ip)->sin_addr; + } #endif - if((prefix = New_Prefix(family, ipptr, len)) != NULL) - { - node = rb_patricia_search_best(tree, prefix); - Deref_Prefix(prefix); - return (node); - } - return NULL; + if((prefix = New_Prefix(family, ipptr, len)) != NULL) { + node = rb_patricia_search_best(tree, prefix); + Deref_Prefix(prefix); + return (node); + } + return NULL; } rb_patricia_node_t * rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip, unsigned int len) { - rb_prefix_t *prefix; - rb_patricia_node_t *node; - void *ipptr; - int family; + rb_prefix_t *prefix; + rb_patricia_node_t *node; + void *ipptr; + int family; #ifndef RB_IPV6 - if(len > 128) - len = 128; + if(len > 128) + len = 128; - family = AF_INET; - ipptr = &((struct sockaddr_in *)ip)->sin_addr; + family = AF_INET; + ipptr = &((struct sockaddr_in *)ip)->sin_addr; #else - if(ip->sa_family == AF_INET6) - { - if(len > 128) - len = 128; - family = AF_INET6; - ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr; - } - else - { - if(len > 32) - len = 32; - family = AF_INET; - ipptr = &((struct sockaddr_in *)ip)->sin_addr; - } + if(ip->sa_family == AF_INET6) { + if(len > 128) + len = 128; + family = AF_INET6; + ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr; + } else { + if(len > 32) + len = 32; + family = AF_INET; + ipptr = &((struct sockaddr_in *)ip)->sin_addr; + } #endif - if((prefix = New_Prefix(family, ipptr, len)) != NULL) - { - node = rb_patricia_search_exact(tree, prefix); - Deref_Prefix(prefix); - return (node); - } - return NULL; + if((prefix = New_Prefix(family, ipptr, len)) != NULL) { + node = rb_patricia_search_exact(tree, prefix); + Deref_Prefix(prefix); + return (node); + } + return NULL; } @@ -1081,46 +968,38 @@ rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip, unsigned int le rb_patricia_node_t * rb_match_string(rb_patricia_tree_t *tree, const char *string) { - rb_patricia_node_t *node; - rb_prefix_t *prefix; + rb_patricia_node_t *node; + rb_prefix_t *prefix; - if((prefix = ascii2prefix(AF_INET, string)) != NULL) - { - node = rb_patricia_search_best(tree, prefix); - Deref_Prefix(prefix); - } - else + if((prefix = ascii2prefix(AF_INET, string)) != NULL) { + node = rb_patricia_search_best(tree, prefix); + Deref_Prefix(prefix); + } else #ifdef RB_IPV6 - if((prefix = ascii2prefix(AF_INET6, string)) != NULL) - { - node = rb_patricia_search_best(tree, prefix); - Deref_Prefix(prefix); - } - else + if((prefix = ascii2prefix(AF_INET6, string)) != NULL) { + node = rb_patricia_search_best(tree, prefix); + Deref_Prefix(prefix); + } else #endif - return NULL; - return node; + return NULL; + return node; } rb_patricia_node_t * rb_match_exact_string(rb_patricia_tree_t *tree, const char *string) { - rb_prefix_t *prefix; - rb_patricia_node_t *node; - if((prefix = ascii2prefix(AF_INET, string)) != NULL) - { - node = rb_patricia_search_exact(tree, prefix); - Deref_Prefix(prefix); - } - else + rb_prefix_t *prefix; + rb_patricia_node_t *node; + if((prefix = ascii2prefix(AF_INET, string)) != NULL) { + node = rb_patricia_search_exact(tree, prefix); + Deref_Prefix(prefix); + } else #ifdef RB_IPV6 - if((prefix = ascii2prefix(AF_INET6, string)) != NULL) - { - node = rb_patricia_search_exact(tree, prefix); - Deref_Prefix(prefix); - } - else + if((prefix = ascii2prefix(AF_INET6, string)) != NULL) { + node = rb_patricia_search_exact(tree, prefix); + Deref_Prefix(prefix); + } else #endif - return NULL; - return node; + return NULL; + return node; } diff --git a/libratbox/src/poll.c b/libratbox/src/poll.c index 6aeb28e..2ff8648 100644 --- a/libratbox/src/poll.c +++ b/libratbox/src/poll.c @@ -39,11 +39,10 @@ #define POLLWRNORM POLLOUT #endif -struct _pollfd_list -{ - struct pollfd *pollfds; - int maxindex; /* highest FD number */ - int allocated; /* number of pollfds allocated */ +struct _pollfd_list { + struct pollfd *pollfds; + int maxindex; /* highest FD number */ + int allocated; /* number of pollfds allocated */ }; typedef struct _pollfd_list pollfd_list_t; @@ -53,7 +52,7 @@ static pollfd_list_t pollfd_list; int rb_setup_fd_poll(rb_fde_t *F) { - return 0; + return 0; } @@ -66,33 +65,30 @@ rb_setup_fd_poll(rb_fde_t *F) int rb_init_netio_poll(void) { - int fd; - pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd))); - pollfd_list.allocated = rb_getmaxconnect(); - for(fd = 0; fd < rb_getmaxconnect(); fd++) - { - pollfd_list.pollfds[fd].fd = -1; - } - pollfd_list.maxindex = 0; - return 0; + int fd; + pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd))); + pollfd_list.allocated = rb_getmaxconnect(); + for(fd = 0; fd < rb_getmaxconnect(); fd++) { + pollfd_list.pollfds[fd].fd = -1; + } + pollfd_list.maxindex = 0; + return 0; } static void resize_pollarray(int fd) { - if(rb_unlikely(fd >= pollfd_list.allocated)) - { - int x, old_value = pollfd_list.allocated; - pollfd_list.allocated += 1024; - pollfd_list.pollfds = - rb_realloc(pollfd_list.pollfds, - pollfd_list.allocated * (sizeof(struct pollfd))); - memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024); - for(x = old_value + 1; x < pollfd_list.allocated; x++) - { - pollfd_list.pollfds[x].fd = -1; - } - } + if(rb_unlikely(fd >= pollfd_list.allocated)) { + int x, old_value = pollfd_list.allocated; + pollfd_list.allocated += 1024; + pollfd_list.pollfds = + rb_realloc(pollfd_list.pollfds, + pollfd_list.allocated * (sizeof(struct pollfd))); + memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024); + for(x = old_value + 1; x < pollfd_list.allocated; x++) { + pollfd_list.pollfds[x].fd = -1; + } + } } /* @@ -104,47 +100,41 @@ resize_pollarray(int fd) void rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - if(F == NULL) - return; + if(F == NULL) + return; - if(type & RB_SELECT_READ) - { - F->read_handler = handler; - F->read_data = client_data; - if(handler != NULL) - F->pflags |= POLLRDNORM; - else - F->pflags &= ~POLLRDNORM; - } - if(type & RB_SELECT_WRITE) - { - F->write_handler = handler; - F->write_data = client_data; - if(handler != NULL) - F->pflags |= POLLWRNORM; - else - F->pflags &= ~POLLWRNORM; - } - resize_pollarray(F->fd); + if(type & RB_SELECT_READ) { + F->read_handler = handler; + F->read_data = client_data; + if(handler != NULL) + F->pflags |= POLLRDNORM; + else + F->pflags &= ~POLLRDNORM; + } + if(type & RB_SELECT_WRITE) { + F->write_handler = handler; + F->write_data = client_data; + if(handler != NULL) + F->pflags |= POLLWRNORM; + else + F->pflags &= ~POLLWRNORM; + } + resize_pollarray(F->fd); - if(F->pflags <= 0) - { - pollfd_list.pollfds[F->fd].events = 0; - pollfd_list.pollfds[F->fd].fd = -1; - if(F->fd == pollfd_list.maxindex) - { - while(pollfd_list.maxindex >= 0 - && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1) - pollfd_list.maxindex--; - } - } - else - { - pollfd_list.pollfds[F->fd].events = F->pflags; - pollfd_list.pollfds[F->fd].fd = F->fd; - if(F->fd > pollfd_list.maxindex) - pollfd_list.maxindex = F->fd; - } + if(F->pflags <= 0) { + pollfd_list.pollfds[F->fd].events = 0; + pollfd_list.pollfds[F->fd].fd = -1; + if(F->fd == pollfd_list.maxindex) { + while(pollfd_list.maxindex >= 0 + && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1) + pollfd_list.maxindex--; + } + } else { + pollfd_list.pollfds[F->fd].events = F->pflags; + pollfd_list.pollfds[F->fd].fd = F->fd; + if(F->fd > pollfd_list.maxindex) + pollfd_list.maxindex = F->fd; + } } @@ -165,97 +155,93 @@ rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_dat int rb_select_poll(long delay) { - int num; - int fd; - int ci; - PF *hdl; - void *data; - struct pollfd *pfd; - int revents; + int num; + int fd; + int ci; + PF *hdl; + void *data; + struct pollfd *pfd; + int revents; - num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay); - rb_set_time(); - if(num < 0) - { - if(!rb_ignore_errno(errno)) - return RB_OK; - else - return RB_ERROR; - } - if(num == 0) - return RB_OK; + num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay); + rb_set_time(); + if(num < 0) { + if(!rb_ignore_errno(errno)) + return RB_OK; + else + return RB_ERROR; + } + if(num == 0) + return RB_OK; - /* XXX we *could* optimise by falling out after doing num fds ... */ - for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) - { - rb_fde_t *F; - pfd = &pollfd_list.pollfds[ci]; + /* XXX we *could* optimise by falling out after doing num fds ... */ + for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) { + rb_fde_t *F; + pfd = &pollfd_list.pollfds[ci]; - revents = pfd->revents; - fd = pfd->fd; - if(revents == 0 || fd == -1) - continue; + revents = pfd->revents; + fd = pfd->fd; + if(revents == 0 || fd == -1) + continue; - F = rb_find_fd(fd); - if(F == NULL) - continue; + F = rb_find_fd(fd); + if(F == NULL) + continue; - if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) - { - hdl = F->read_handler; - data = F->read_data; - F->read_handler = NULL; - F->read_data = NULL; - if(hdl) - hdl(F, data); - } + if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) { + hdl = F->read_handler; + data = F->read_data; + F->read_handler = NULL; + F->read_data = NULL; + if(hdl) + hdl(F, data); + } - if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) - { - hdl = F->write_handler; - data = F->write_data; - F->write_handler = NULL; - F->write_data = NULL; - if(hdl) - hdl(F, data); - } + if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) { + hdl = F->write_handler; + data = F->write_data; + F->write_handler = NULL; + F->write_data = NULL; + if(hdl) + hdl(F, data); + } - if(F->read_handler == NULL) - rb_setselect_poll(F, RB_SELECT_READ, NULL, NULL); - if(F->write_handler == NULL) - rb_setselect_poll(F, RB_SELECT_WRITE, NULL, NULL); + if(F->read_handler == NULL) + rb_setselect_poll(F, RB_SELECT_READ, NULL, NULL); + if(F->write_handler == NULL) + rb_setselect_poll(F, RB_SELECT_WRITE, NULL, NULL); - } - return 0; + } + return 0; } #else /* poll not supported */ int rb_init_netio_poll(void) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } void rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_poll(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_poll(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif diff --git a/libratbox/src/ports.c b/libratbox/src/ports.c index 9611dd9..3e5741c 100644 --- a/libratbox/src/ports.c +++ b/libratbox/src/ports.c @@ -44,7 +44,7 @@ static int pemax; /* max structs to buffer */ int rb_setup_fd_ports(rb_fde_t *F) { - return 0; + return 0; } /* @@ -57,16 +57,15 @@ rb_setup_fd_ports(rb_fde_t *F) int rb_init_netio_ports(void) { - if((pe = port_create()) < 0) - { - return errno; - } - pemax = getdtablesize(); - pelst = rb_malloc(sizeof(port_event_t) * pemax); - zero_timespec.tv_sec = 0; - zero_timespec.tv_nsec = 0; - rb_set_time(); - return 0; + if((pe = port_create()) < 0) { + return errno; + } + pemax = getdtablesize(); + pelst = rb_malloc(sizeof(port_event_t) * pemax); + zero_timespec.tv_sec = 0; + zero_timespec.tv_nsec = 0; + rb_set_time(); + return 0; } /* @@ -78,36 +77,33 @@ rb_init_netio_ports(void) void rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - lrb_assert(IsFDOpen(F)); - int old_flags = F->pflags; + lrb_assert(IsFDOpen(F)); + int old_flags = F->pflags; - if(type & RB_SELECT_READ) - { - F->read_handler = handler; - F->read_data = client_data; - } - if(type & RB_SELECT_WRITE) - { - F->write_handler = handler; - F->write_data = client_data; - } - F->pflags = 0; + if(type & RB_SELECT_READ) { + F->read_handler = handler; + F->read_data = client_data; + } + if(type & RB_SELECT_WRITE) { + F->write_handler = handler; + F->write_data = client_data; + } + F->pflags = 0; - if(F->read_handler != NULL) - F->pflags = POLLIN; - if(F->write_handler != NULL) - F->pflags |= POLLOUT; + if(F->read_handler != NULL) + F->pflags = POLLIN; + if(F->write_handler != NULL) + F->pflags |= POLLOUT; + + if(old_flags == 0 && F->pflags == 0) + return; + else if(F->pflags <= 0) { + port_dissociate(pe, PORT_SOURCE_FD, F->fd); + return; + } + + port_associate(pe, PORT_SOURCE_FD, F->fd, F->pflags, F); - if(old_flags == 0 && F->pflags == 0) - return; - else if(F->pflags <= 0) - { - port_dissociate(pe, PORT_SOURCE_FD, F->fd); - return; - } - - port_associate(pe, PORT_SOURCE_FD, F->fd, F->pflags, F); - } /* @@ -122,163 +118,155 @@ rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_da int rb_select_ports(long delay) { - int i, fd; - int nget = 1; - struct timespec poll_time; - struct timespec *p = NULL; - struct ev_entry *ev; + int i, fd; + int nget = 1; + struct timespec poll_time; + struct timespec *p = NULL; + struct ev_entry *ev; - if(delay >= 0) - { - poll_time.tv_sec = delay / 1000; - poll_time.tv_nsec = (delay % 1000) * 1000000; - p = &poll_time; - } + if(delay >= 0) { + poll_time.tv_sec = delay / 1000; + poll_time.tv_nsec = (delay % 1000) * 1000000; + p = &poll_time; + } - i = port_getn(pe, pelst, pemax, &nget, p); - rb_set_time(); + i = port_getn(pe, pelst, pemax, &nget, p); + rb_set_time(); - if(i == -1) - return RB_OK; + if(i == -1) + return RB_OK; - for(i = 0; i < nget; i++) - { - if(pelst[i].portev_source == PORT_SOURCE_FD) - { - fd = pelst[i].portev_object; - PF *hdl = NULL; - rb_fde_t *F = pelst[i].portev_user; - if((pelst[i].portev_events & (POLLIN | POLLHUP | POLLERR)) && (hdl = F->read_handler)) - { - F->read_handler = NULL; - hdl(F, F->read_data); - } - if((pelst[i].portev_events & (POLLOUT | POLLHUP | POLLERR)) && (hdl = F->write_handler)) - { - F->write_handler = NULL; - hdl(F, F->write_data); - } - } else if(pelst[i].portev_source == PORT_SOURCE_TIMER) - { - ev = (struct ev_entry *)pelst[i].portev_user; - rb_run_event(ev); - } - } - return RB_OK; + for(i = 0; i < nget; i++) { + if(pelst[i].portev_source == PORT_SOURCE_FD) { + fd = pelst[i].portev_object; + PF *hdl = NULL; + rb_fde_t *F = pelst[i].portev_user; + if((pelst[i].portev_events & (POLLIN | POLLHUP | POLLERR)) && (hdl = F->read_handler)) { + F->read_handler = NULL; + hdl(F, F->read_data); + } + if((pelst[i].portev_events & (POLLOUT | POLLHUP | POLLERR)) && (hdl = F->write_handler)) { + F->write_handler = NULL; + hdl(F, F->write_data); + } + } else if(pelst[i].portev_source == PORT_SOURCE_TIMER) { + ev = (struct ev_entry *)pelst[i].portev_user; + rb_run_event(ev); + } + } + return RB_OK; } int rb_ports_supports_event(void) { - return 1; + return 1; }; void rb_ports_init_event(void) { - return; + return; } int rb_ports_sched_event(struct ev_entry *event, int when) { - timer_t *id; - struct sigevent ev; - port_notify_t not; - struct itimerspec ts; + timer_t *id; + struct sigevent ev; + port_notify_t not; + struct itimerspec ts; - event->comm_ptr = rb_malloc(sizeof(timer_t)); - id = event->comm_ptr; - - memset(&ev, 0, sizeof(ev)); - ev.sigev_notify = SIGEV_PORT; - ev.sigev_value.sival_ptr = ¬ - - memset(¬, 0, sizeof(not)); - not.portnfy_port = pe; - not.portnfy_user = event; - - if(timer_create(CLOCK_REALTIME, &ev, id) < 0) - { - rb_lib_log("timer_create: %s\n", strerror(errno)); - return 0; - } - - memset(&ts, 0, sizeof(ts)); - ts.it_value.tv_sec = when; - ts.it_value.tv_nsec = 0; - if(event->frequency != 0) - ts.it_interval = ts.it_value; + event->comm_ptr = rb_malloc(sizeof(timer_t)); + id = event->comm_ptr; - if(timer_settime(*id, 0, &ts, NULL) < 0) - { - rb_lib_log("timer_settime: %s\n", strerror(errno)); - return 0; - } - return 1; + memset(&ev, 0, sizeof(ev)); + ev.sigev_notify = SIGEV_PORT; + ev.sigev_value.sival_ptr = ¬ + + memset(¬, 0, sizeof(not)); + not.portnfy_port = pe; + not.portnfy_user = event; + + if(timer_create(CLOCK_REALTIME, &ev, id) < 0) { + rb_lib_log("timer_create: %s\n", strerror(errno)); + return 0; + } + + memset(&ts, 0, sizeof(ts)); + ts.it_value.tv_sec = when; + ts.it_value.tv_nsec = 0; + if(event->frequency != 0) + ts.it_interval = ts.it_value; + + if(timer_settime(*id, 0, &ts, NULL) < 0) { + rb_lib_log("timer_settime: %s\n", strerror(errno)); + return 0; + } + return 1; } void rb_ports_unsched_event(struct ev_entry *event) { - timer_delete(*((timer_t *) event->comm_ptr)); - rb_free(event->comm_ptr); - event->comm_ptr = NULL; + timer_delete(*((timer_t *) event->comm_ptr)); + rb_free(event->comm_ptr); + event->comm_ptr = NULL; } #else /* ports not supported */ int rb_ports_supports_event(void) { - errno = ENOSYS; - return 0; + errno = ENOSYS; + return 0; } void rb_ports_init_event(void) { - return; + return; } - + int rb_ports_sched_event(struct ev_entry *event, int when) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } - + void rb_ports_unsched_event(struct ev_entry *event) { - return; + return; } int rb_init_netio_ports(void) { - return ENOSYS; + return ENOSYS; } void rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_ports(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_ports(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } diff --git a/libratbox/src/ratbox_lib.c b/libratbox/src/ratbox_lib.c index 028a91f..7d389e4 100644 --- a/libratbox/src/ratbox_lib.c +++ b/libratbox/src/ratbox_lib.c @@ -37,59 +37,55 @@ static char errbuf[512]; /* this doesn't do locales...oh well i guess */ static const char *months[] = { - "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December" + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" }; static const char *weekdays[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" }; static const char *s_month[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", - "Aug", "Sep", "Oct", "Nov", "Dec" + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", + "Aug", "Sep", "Oct", "Nov", "Dec" }; static const char *s_weekdays[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; char * rb_ctime(const time_t t, char *buf, size_t len) { - char *p; - struct tm *tp; - static char timex[128]; - size_t tlen; + char *p; + struct tm *tp; + static char timex[128]; + size_t tlen; #if defined(HAVE_GMTIME_R) - struct tm tmr; - tp = gmtime_r(&t, &tmr); + struct tm tmr; + tp = gmtime_r(&t, &tmr); #else - tp = gmtime(&t); + tp = gmtime(&t); #endif - if(buf == NULL) - { - p = timex; - tlen = sizeof(timex); - } - else - { - p = buf; - tlen = len; - } + if(buf == NULL) { + p = timex; + tlen = sizeof(timex); + } else { + p = buf; + tlen = len; + } - if(rb_unlikely(tp == NULL)) - { - rb_strlcpy(p, "", tlen); - return (p); - } + if(rb_unlikely(tp == NULL)) { + rb_strlcpy(p, "", tlen); + return (p); + } - rb_snprintf(p, tlen, "%s %s %d %02u:%02u:%02u %d", - s_weekdays[tp->tm_wday], s_month[tp->tm_mon], - tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, tp->tm_year + 1900); - return (p); + rb_snprintf(p, tlen, "%s %s %d %02u:%02u:%02u %d", + s_weekdays[tp->tm_wday], s_month[tp->tm_mon], + tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, tp->tm_year + 1900); + return (p); } @@ -97,89 +93,87 @@ rb_ctime(const time_t t, char *buf, size_t len) char * rb_date(const time_t t, char *buf, size_t len) { - struct tm *gm; + struct tm *gm; #if defined(HAVE_GMTIME_R) - struct tm gmbuf; - gm = gmtime_r(&t, &gmbuf); + struct tm gmbuf; + gm = gmtime_r(&t, &gmbuf); #else - gm = gmtime(&t); + gm = gmtime(&t); #endif - if(rb_unlikely(gm == NULL)) - { - rb_strlcpy(buf, "", len); - return (buf); - } + if(rb_unlikely(gm == NULL)) { + rb_strlcpy(buf, "", len); + return (buf); + } - rb_snprintf(buf, len, "%s %s %d %d -- %02u:%02u:%02u +00:00", - weekdays[gm->tm_wday], months[gm->tm_mon], gm->tm_mday, - gm->tm_year + 1900, gm->tm_hour, gm->tm_min, gm->tm_sec); - return (buf); + rb_snprintf(buf, len, "%s %s %d %d -- %02u:%02u:%02u +00:00", + weekdays[gm->tm_wday], months[gm->tm_mon], gm->tm_mday, + gm->tm_year + 1900, gm->tm_hour, gm->tm_min, gm->tm_sec); + return (buf); } time_t rb_current_time(void) { - return rb_time.tv_sec; + return rb_time.tv_sec; } const struct timeval * rb_current_time_tv(void) { - return &rb_time; + return &rb_time; } void rb_lib_log(const char *format, ...) { - va_list args; - if(rb_log == NULL) - return; - va_start(args, format); - rb_vsnprintf(errbuf, sizeof(errbuf), format, args); - va_end(args); - rb_log(errbuf); + va_list args; + if(rb_log == NULL) + return; + va_start(args, format); + rb_vsnprintf(errbuf, sizeof(errbuf), format, args); + va_end(args); + rb_log(errbuf); } void rb_lib_die(const char *format, ...) { - va_list args; - if(rb_die == NULL) - abort(); - va_start(args, format); - rb_vsnprintf(errbuf, sizeof(errbuf), format, args); - va_end(args); - rb_die(errbuf); + va_list args; + if(rb_die == NULL) + abort(); + va_start(args, format); + rb_vsnprintf(errbuf, sizeof(errbuf), format, args); + va_end(args); + rb_die(errbuf); } void rb_lib_restart(const char *format, ...) { - va_list args; - if(rb_restart == NULL) - abort(); - va_start(args, format); - rb_vsnprintf(errbuf, sizeof(errbuf), format, args); - va_end(args); - rb_restart(errbuf); + va_list args; + if(rb_restart == NULL) + abort(); + va_start(args, format); + rb_vsnprintf(errbuf, sizeof(errbuf), format, args); + va_end(args); + rb_restart(errbuf); } void rb_set_time(void) { - struct timeval newtime; + struct timeval newtime; - if(rb_unlikely(rb_gettimeofday(&newtime, NULL) == -1)) - { - rb_lib_log("Clock Failure (%s)", strerror(errno)); - rb_lib_restart("Clock Failure"); - } + if(rb_unlikely(rb_gettimeofday(&newtime, NULL) == -1)) { + rb_lib_log("Clock Failure (%s)", strerror(errno)); + rb_lib_restart("Clock Failure"); + } - if(newtime.tv_sec < rb_time.tv_sec) - rb_set_back_events(rb_time.tv_sec - newtime.tv_sec); + if(newtime.tv_sec < rb_time.tv_sec) + rb_set_back_events(rb_time.tv_sec - newtime.tv_sec); - memcpy(&rb_time, &newtime, sizeof(struct timeval)); + memcpy(&rb_time, &newtime, sizeof(struct timeval)); } extern const char *libratbox_serno; @@ -187,237 +181,218 @@ extern const char *libratbox_serno; const char * rb_lib_version(void) { - static char version_info[512]; - char ssl_info[512]; - rb_get_ssl_info(ssl_info, sizeof(ssl_info)); - rb_snprintf(version_info, sizeof(version_info), "libratbox version: %s - %s", libratbox_serno, ssl_info); - return version_info; + static char version_info[512]; + char ssl_info[512]; + rb_get_ssl_info(ssl_info, sizeof(ssl_info)); + rb_snprintf(version_info, sizeof(version_info), "libratbox version: %s - %s", libratbox_serno, ssl_info); + return version_info; } void rb_lib_init(log_cb * ilog, restart_cb * irestart, die_cb * idie, int closeall, int maxcon, - size_t dh_size, size_t fd_heap_size) + size_t dh_size, size_t fd_heap_size) { - rb_set_time(); - rb_log = ilog; - rb_restart = irestart; - rb_die = idie; - rb_event_init(); - rb_init_bh(); - rb_fdlist_init(closeall, maxcon, fd_heap_size); - rb_init_netio(); - rb_init_rb_dlink_nodes(dh_size); - if(rb_io_supports_event()) - { - rb_io_init_event(); - } + rb_set_time(); + rb_log = ilog; + rb_restart = irestart; + rb_die = idie; + rb_event_init(); + rb_init_bh(); + rb_fdlist_init(closeall, maxcon, fd_heap_size); + rb_init_netio(); + rb_init_rb_dlink_nodes(dh_size); + if(rb_io_supports_event()) { + rb_io_init_event(); + } } void rb_lib_loop(long delay) { - time_t next; - rb_set_time(); + time_t next; + rb_set_time(); - if(rb_io_supports_event()) - { - if(delay == 0) - delay = -1; - while(1) - rb_select(-1); - } + if(rb_io_supports_event()) { + if(delay == 0) + delay = -1; + while(1) + rb_select(-1); + } - while(1) - { - if(delay == 0) - { - if((next = rb_event_next()) > 0) - { - next -= rb_current_time(); - if(next <= 0) - next = 1000; - else - next *= 1000; - } - else - next = -1; - rb_select(next); - } - else - rb_select(delay); - rb_event_run(); - } + while(1) { + if(delay == 0) { + if((next = rb_event_next()) > 0) { + next -= rb_current_time(); + if(next <= 0) + next = 1000; + else + next *= 1000; + } else + next = -1; + rb_select(next); + } else + rb_select(delay); + rb_event_run(); + } } #ifndef HAVE_STRTOK_R char * rb_strtok_r(char *s, const char *delim, char **save) { - char *token; + char *token; - if(s == NULL) - s = *save; + if(s == NULL) + s = *save; - /* Scan leading delimiters. */ - s += strspn(s, delim); + /* Scan leading delimiters. */ + s += strspn(s, delim); - if(*s == '\0') - { - *save = s; - return NULL; - } + if(*s == '\0') { + *save = s; + return NULL; + } - token = s; - s = strpbrk(token, delim); + token = s; + s = strpbrk(token, delim); - if(s == NULL) - *save = (token + strlen(token)); - else - { - *s = '\0'; - *save = s + 1; - } - return token; + if(s == NULL) + *save = (token + strlen(token)); + else { + *s = '\0'; + *save = s + 1; + } + return token; } #else char * rb_strtok_r(char *s, const char *delim, char **save) { - return strtok_r(s, delim, save); + return strtok_r(s, delim, save); } #endif -static const char base64_table[] = - { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' +static const char base64_table[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' }; static const char base64_pad = '='; static const short base64_reverse_table[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; unsigned char * rb_base64_encode(const unsigned char *str, int length) { - const unsigned char *current = str; - unsigned char *p; - unsigned char *result; + const unsigned char *current = str; + unsigned char *p; + unsigned char *result; - if((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) - { - return NULL; - } + if((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) { + return NULL; + } - result = rb_malloc(((length + 2) / 3) * 5); - p = result; + result = rb_malloc(((length + 2) / 3) * 5); + p = result; - while(length > 2) - { - *p++ = base64_table[current[0] >> 2]; - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; - *p++ = base64_table[current[2] & 0x3f]; + while(length > 2) { + *p++ = base64_table[current[0] >> 2]; + *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; + *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; + *p++ = base64_table[current[2] & 0x3f]; - current += 3; - length -= 3; - } + current += 3; + length -= 3; + } - if(length != 0) - { - *p++ = base64_table[current[0] >> 2]; - if(length > 1) - { - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[(current[1] & 0x0f) << 2]; - *p++ = base64_pad; - } - else - { - *p++ = base64_table[(current[0] & 0x03) << 4]; - *p++ = base64_pad; - *p++ = base64_pad; - } - } - *p = '\0'; - return result; + if(length != 0) { + *p++ = base64_table[current[0] >> 2]; + if(length > 1) { + *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; + *p++ = base64_table[(current[1] & 0x0f) << 2]; + *p++ = base64_pad; + } else { + *p++ = base64_table[(current[0] & 0x03) << 4]; + *p++ = base64_pad; + *p++ = base64_pad; + } + } + *p = '\0'; + return result; } unsigned char * rb_base64_decode(const unsigned char *str, int length, int *ret) { - const unsigned char *current = str; - int ch, i = 0, j = 0, k; - unsigned char *result; + const unsigned char *current = str; + int ch, i = 0, j = 0, k; + unsigned char *result; - result = rb_malloc(length + 1); + result = rb_malloc(length + 1); - while((ch = *current++) != '\0' && length-- > 0) - { - if(ch == base64_pad) - break; + while((ch = *current++) != '\0' && length-- > 0) { + if(ch == base64_pad) + break; - ch = base64_reverse_table[ch]; - if(ch < 0) - continue; + ch = base64_reverse_table[ch]; + if(ch < 0) + continue; - switch (i % 4) - { - case 0: - result[j] = ch << 2; - break; - case 1: - result[j++] |= ch >> 4; - result[j] = (ch & 0x0f) << 4; - break; - case 2: - result[j++] |= ch >> 2; - result[j] = (ch & 0x03) << 6; - break; - case 3: - result[j++] |= ch; - break; - } - i++; - } + switch (i % 4) { + case 0: + result[j] = ch << 2; + break; + case 1: + result[j++] |= ch >> 4; + result[j] = (ch & 0x0f) << 4; + break; + case 2: + result[j++] |= ch >> 2; + result[j] = (ch & 0x03) << 6; + break; + case 3: + result[j++] |= ch; + break; + } + i++; + } - k = j; + k = j; - if(ch == base64_pad) - { - switch (i % 4) - { - case 1: - free(result); - return NULL; - case 2: - k++; - case 3: - result[k++] = 0; - } - } - result[j] = '\0'; - *ret = j; - return result; + if(ch == base64_pad) { + switch (i % 4) { + case 1: + free(result); + return NULL; + case 2: + k++; + case 3: + result[k++] = 0; + } + } + result[j] = '\0'; + *ret = j; + return result; } diff --git a/libratbox/src/rawbuf.c b/libratbox/src/rawbuf.c index 65cc06e..4710d3a 100644 --- a/libratbox/src/rawbuf.c +++ b/libratbox/src/rawbuf.c @@ -1,7 +1,7 @@ /* * ircd-ratbox: A slight useful ircd * rawbuf.c: raw buffer (non-line oriented buffering) - * + * * Copyright (C) 2007 Aaron Sethman * Copyright (C) 2007 ircd-ratbox development team * @@ -27,19 +27,17 @@ #include #define RAWBUF_SIZE 1024 -struct _rawbuf -{ - rb_dlink_node node; - uint8_t data[RAWBUF_SIZE]; - int len; - uint8_t flushing; +struct _rawbuf { + rb_dlink_node node; + uint8_t data[RAWBUF_SIZE]; + int len; + uint8_t flushing; }; -struct _rawbuf_head -{ - rb_dlink_list list; - int len; - int written; +struct _rawbuf_head { + rb_dlink_list list; + int len; + int written; }; static rb_bh *rawbuf_heap; @@ -48,255 +46,238 @@ static rb_bh *rawbuf_heap; static rawbuf_t * rb_rawbuf_alloc(void) { - rawbuf_t *t; - t = rb_bh_alloc(rawbuf_heap); - return t; + rawbuf_t *t; + t = rb_bh_alloc(rawbuf_heap); + return t; } static rawbuf_t * rb_rawbuf_newbuf(rawbuf_head_t * rb) { - rawbuf_t *buf; - buf = rb_rawbuf_alloc(); - rb_dlinkAddTail(buf, &buf->node, &rb->list); - return buf; + rawbuf_t *buf; + buf = rb_rawbuf_alloc(); + rb_dlinkAddTail(buf, &buf->node, &rb->list); + return buf; } static void rb_rawbuf_done(rawbuf_head_t * rb, rawbuf_t * buf) { - rawbuf_t *ptr = buf; - rb_dlinkDelete(&buf->node, &rb->list); - rb_bh_free(rawbuf_heap, ptr); + rawbuf_t *ptr = buf; + rb_dlinkDelete(&buf->node, &rb->list); + rb_bh_free(rawbuf_heap, ptr); } static int rb_rawbuf_flush_writev(rawbuf_head_t * rb, rb_fde_t *F) { - rb_dlink_node *ptr, *next; - rawbuf_t *buf; - int x = 0, y = 0; - int xret, retval; - struct rb_iovec vec[RB_UIO_MAXIOV]; - memset(vec, 0, sizeof(vec)); + rb_dlink_node *ptr, *next; + rawbuf_t *buf; + int x = 0, y = 0; + int xret, retval; + struct rb_iovec vec[RB_UIO_MAXIOV]; + memset(vec, 0, sizeof(vec)); - if(rb->list.head == NULL) - { - errno = EAGAIN; - return -1; - } + if(rb->list.head == NULL) { + errno = EAGAIN; + return -1; + } - RB_DLINK_FOREACH(ptr, rb->list.head) - { - if(x >= RB_UIO_MAXIOV) - break; + RB_DLINK_FOREACH(ptr, rb->list.head) { + if(x >= RB_UIO_MAXIOV) + break; - buf = ptr->data; - if(buf->flushing) - { - vec[x].iov_base = buf->data + rb->written; - vec[x++].iov_len = buf->len - rb->written; - continue; - } - vec[x].iov_base = buf->data; - vec[x++].iov_len = buf->len; + buf = ptr->data; + if(buf->flushing) { + vec[x].iov_base = buf->data + rb->written; + vec[x++].iov_len = buf->len - rb->written; + continue; + } + vec[x].iov_base = buf->data; + vec[x++].iov_len = buf->len; - } + } - if(x == 0) - { - errno = EAGAIN; - return -1; - } - xret = retval = rb_writev(F, vec, x); - if(retval <= 0) - return retval; + if(x == 0) { + errno = EAGAIN; + return -1; + } + xret = retval = rb_writev(F, vec, x); + if(retval <= 0) + return retval; - RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) - { - buf = ptr->data; - if(y++ >= x) - break; - if(buf->flushing) - { - if(xret >= buf->len - rb->written) - { - xret -= buf->len - rb->written; - rb->len -= buf->len - rb->written; - rb_rawbuf_done(rb, buf); - continue; - } - } + RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) { + buf = ptr->data; + if(y++ >= x) + break; + if(buf->flushing) { + if(xret >= buf->len - rb->written) { + xret -= buf->len - rb->written; + rb->len -= buf->len - rb->written; + rb_rawbuf_done(rb, buf); + continue; + } + } - if(xret >= buf->len) - { - xret -= buf->len; - rb->len -= buf->len; - rb_rawbuf_done(rb, buf); - } - else - { - buf->flushing = 1; - rb->written = xret; - rb->len -= xret; - break; - } + if(xret >= buf->len) { + xret -= buf->len; + rb->len -= buf->len; + rb_rawbuf_done(rb, buf); + } else { + buf->flushing = 1; + rb->written = xret; + rb->len -= xret; + break; + } - } - return retval; + } + return retval; } int rb_rawbuf_flush(rawbuf_head_t * rb, rb_fde_t *F) { - rawbuf_t *buf; - int retval; - if(rb->list.head == NULL) - { - errno = EAGAIN; - return -1; - } + rawbuf_t *buf; + int retval; + if(rb->list.head == NULL) { + errno = EAGAIN; + return -1; + } - if(!rb_fd_ssl(F)) - return rb_rawbuf_flush_writev(rb, F); + if(!rb_fd_ssl(F)) + return rb_rawbuf_flush_writev(rb, F); - buf = rb->list.head->data; - if(!buf->flushing) - { - buf->flushing = 1; - rb->written = 0; - } + buf = rb->list.head->data; + if(!buf->flushing) { + buf->flushing = 1; + rb->written = 0; + } - retval = rb_write(F, buf->data + rb->written, buf->len - rb->written); - if(retval <= 0) - return retval; + retval = rb_write(F, buf->data + rb->written, buf->len - rb->written); + if(retval <= 0) + return retval; - rb->written += retval; - if(rb->written == buf->len) - { - rb->written = 0; - rb_dlinkDelete(&buf->node, &rb->list); - rb_bh_free(rawbuf_heap, buf); - } - rb->len -= retval; - lrb_assert(rb->len >= 0); - return retval; + rb->written += retval; + if(rb->written == buf->len) { + rb->written = 0; + rb_dlinkDelete(&buf->node, &rb->list); + rb_bh_free(rawbuf_heap, buf); + } + rb->len -= retval; + lrb_assert(rb->len >= 0); + return retval; } void rb_rawbuf_append(rawbuf_head_t * rb, void *data, int len) { - rawbuf_t *buf = NULL; - int clen; - void *ptr; - if(rb->list.tail != NULL) - buf = rb->list.tail->data; + rawbuf_t *buf = NULL; + int clen; + void *ptr; + if(rb->list.tail != NULL) + buf = rb->list.tail->data; - if(buf != NULL && buf->len < RAWBUF_SIZE && !buf->flushing) - { - buf = (rawbuf_t *) rb->list.tail->data; - clen = RAWBUF_SIZE - buf->len; - ptr = (void *)(buf->data + buf->len); - if(len < clen) - clen = len; + if(buf != NULL && buf->len < RAWBUF_SIZE && !buf->flushing) { + buf = (rawbuf_t *) rb->list.tail->data; + clen = RAWBUF_SIZE - buf->len; + ptr = (void *)(buf->data + buf->len); + if(len < clen) + clen = len; - memcpy(ptr, data, clen); - buf->len += clen; - rb->len += clen; - len -= clen; - if(len == 0) - return; - data = (char *)data + clen; + memcpy(ptr, data, clen); + buf->len += clen; + rb->len += clen; + len -= clen; + if(len == 0) + return; + data = (char *)data + clen; - } + } - while(len > 0) - { - buf = rb_rawbuf_newbuf(rb); + while(len > 0) { + buf = rb_rawbuf_newbuf(rb); - if(len >= RAWBUF_SIZE) - clen = RAWBUF_SIZE; - else - clen = len; + if(len >= RAWBUF_SIZE) + clen = RAWBUF_SIZE; + else + clen = len; - memcpy(buf->data, data, clen); - buf->len += clen; - len -= clen; - data = (char *)data + clen; - rb->len += clen; - } + memcpy(buf->data, data, clen); + buf->len += clen; + len -= clen; + data = (char *)data + clen; + rb->len += clen; + } } int rb_rawbuf_get(rawbuf_head_t * rb, void *data, int len) { - rawbuf_t *buf; - int cpylen; - void *ptr; - if(rb->list.head == NULL) - return 0; + rawbuf_t *buf; + int cpylen; + void *ptr; + if(rb->list.head == NULL) + return 0; - buf = rb->list.head->data; + buf = rb->list.head->data; - if(buf->flushing) - ptr = (void *)(buf->data + rb->written); - else - ptr = buf->data; + if(buf->flushing) + ptr = (void *)(buf->data + rb->written); + else + ptr = buf->data; - if(len > buf->len) - cpylen = buf->len; - else - cpylen = len; + if(len > buf->len) + cpylen = buf->len; + else + cpylen = len; - memcpy(data, ptr, cpylen); + memcpy(data, ptr, cpylen); - if(cpylen == buf->len) - { - rb->written = 0; - rb_rawbuf_done(rb, buf); - rb->len -= len; - return cpylen; - } + if(cpylen == buf->len) { + rb->written = 0; + rb_rawbuf_done(rb, buf); + rb->len -= len; + return cpylen; + } - buf->flushing = 1; - buf->len -= cpylen; - rb->len -= cpylen; - rb->written += cpylen; - return cpylen; + buf->flushing = 1; + buf->len -= cpylen; + rb->len -= cpylen; + rb->written += cpylen; + return cpylen; } int rb_rawbuf_length(rawbuf_head_t * rb) { - if(rb_dlink_list_length(&rb->list) == 0 && rb->len != 0) - lrb_assert(1 == 0); - return rb->len; + if(rb_dlink_list_length(&rb->list) == 0 && rb->len != 0) + lrb_assert(1 == 0); + return rb->len; } rawbuf_head_t * rb_new_rawbuffer(void) { - return rb_malloc(sizeof(rawbuf_head_t)); + return rb_malloc(sizeof(rawbuf_head_t)); } void rb_free_rawbuffer(rawbuf_head_t * rb) { - rb_dlink_node *ptr, *next; - RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) - { - rb_rawbuf_done(rb, ptr->data); - } - rb_free(rb); + rb_dlink_node *ptr, *next; + RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) { + rb_rawbuf_done(rb, ptr->data); + } + rb_free(rb); } void rb_init_rawbuffers(int heap_size) { - if(rawbuf_heap == NULL) - rawbuf_heap = rb_bh_create(sizeof(rawbuf_t), heap_size, "librb_rawbuf_heap"); + if(rawbuf_heap == NULL) + rawbuf_heap = rb_bh_create(sizeof(rawbuf_t), heap_size, "librb_rawbuf_heap"); } diff --git a/libratbox/src/rb_memory.c b/libratbox/src/rb_memory.c index e8cc4d0..ca4d23a 100644 --- a/libratbox/src/rb_memory.c +++ b/libratbox/src/rb_memory.c @@ -28,13 +28,13 @@ void rb_outofmemory(void) { - static int was_here = 0; + static int was_here = 0; - if(was_here) - abort(); + if(was_here) + abort(); - was_here = 1; + was_here = 1; - rb_lib_log("Out of memory: restarting server..."); - rb_lib_restart("Out of Memory"); + rb_lib_log("Out of memory: restarting server..."); + rb_lib_restart("Out of Memory"); } diff --git a/libratbox/src/select.c b/libratbox/src/select.c index 56be72f..a5f2d37 100644 --- a/libratbox/src/select.c +++ b/libratbox/src/select.c @@ -70,48 +70,36 @@ static void select_update_selectfds(rb_fde_t *F, short event, PF * handler); static void select_update_selectfds(rb_fde_t *F, short event, PF * handler) { - /* Update the read / write set */ - if(event & RB_SELECT_READ) - { - if(handler) - { - MY_FD_SET(F->fd, &select_readfds); - F->pflags |= RB_SELECT_READ; - } - else - { - MY_FD_CLR(F->fd, &select_readfds); - F->pflags &= ~RB_SELECT_READ; - } - } + /* Update the read / write set */ + if(event & RB_SELECT_READ) { + if(handler) { + MY_FD_SET(F->fd, &select_readfds); + F->pflags |= RB_SELECT_READ; + } else { + MY_FD_CLR(F->fd, &select_readfds); + F->pflags &= ~RB_SELECT_READ; + } + } - if(event & RB_SELECT_WRITE) - { - if(handler) - { - MY_FD_SET(F->fd, &select_writefds); - F->pflags |= RB_SELECT_WRITE; - } - else - { - MY_FD_CLR(F->fd, &select_writefds); - F->pflags &= ~RB_SELECT_WRITE; - } - } + if(event & RB_SELECT_WRITE) { + if(handler) { + MY_FD_SET(F->fd, &select_writefds); + F->pflags |= RB_SELECT_WRITE; + } else { + MY_FD_CLR(F->fd, &select_writefds); + F->pflags &= ~RB_SELECT_WRITE; + } + } - if(F->pflags & (RB_SELECT_READ | RB_SELECT_WRITE)) - { - if(F->fd > rb_maxfd) - { - rb_maxfd = F->fd; - } - } - else if(F->fd <= rb_maxfd) - { - while(rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds) - && !FD_ISSET(rb_maxfd, &select_writefds)) - rb_maxfd--; - } + if(F->pflags & (RB_SELECT_READ | RB_SELECT_WRITE)) { + if(F->fd > rb_maxfd) { + rb_maxfd = F->fd; + } + } else if(F->fd <= rb_maxfd) { + while(rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds) + && !FD_ISSET(rb_maxfd, &select_writefds)) + rb_maxfd--; + } } @@ -121,7 +109,7 @@ select_update_selectfds(rb_fde_t *F, short event, PF * handler) int rb_setup_fd_select(rb_fde_t *F) { - return 0; + return 0; } @@ -135,11 +123,11 @@ extern int rb_maxconnections; int rb_init_netio_select(void) { - if(rb_maxconnections > FD_SETSIZE) - rb_maxconnections = FD_SETSIZE; /* override this */ - FD_ZERO(&select_readfds); - FD_ZERO(&select_writefds); - return 0; + if(rb_maxconnections > FD_SETSIZE) + rb_maxconnections = FD_SETSIZE; /* override this */ + FD_ZERO(&select_readfds); + FD_ZERO(&select_writefds); + return 0; } /* @@ -151,20 +139,18 @@ rb_init_netio_select(void) void rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - lrb_assert(IsFDOpen(F)); + lrb_assert(IsFDOpen(F)); - if(type & RB_SELECT_READ) - { - F->read_handler = handler; - F->read_data = client_data; - select_update_selectfds(F, RB_SELECT_READ, handler); - } - if(type & RB_SELECT_WRITE) - { - F->write_handler = handler; - F->write_data = client_data; - select_update_selectfds(F, RB_SELECT_WRITE, handler); - } + if(type & RB_SELECT_READ) { + F->read_handler = handler; + F->read_data = client_data; + select_update_selectfds(F, RB_SELECT_READ, handler); + } + if(type & RB_SELECT_WRITE) { + F->write_handler = handler; + F->write_data = client_data; + select_update_selectfds(F, RB_SELECT_WRITE, handler); + } } /* @@ -182,94 +168,90 @@ rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_d int rb_select_select(long delay) { - int num; - int fd; - PF *hdl; - rb_fde_t *F; - struct timeval to; + int num; + int fd; + PF *hdl; + rb_fde_t *F; + struct timeval to; - /* Copy over the read/write sets so we don't have to rebuild em */ - memcpy(&tmpreadfds, &select_readfds, sizeof(fd_set)); - memcpy(&tmpwritefds, &select_writefds, sizeof(fd_set)); + /* Copy over the read/write sets so we don't have to rebuild em */ + memcpy(&tmpreadfds, &select_readfds, sizeof(fd_set)); + memcpy(&tmpwritefds, &select_writefds, sizeof(fd_set)); - for(;;) - { - to.tv_sec = 0; - to.tv_usec = delay * 1000; - num = select(rb_maxfd + 1, &tmpreadfds, &tmpwritefds, NULL, &to); - if(num >= 0) - break; - if(rb_ignore_errno(errno)) - continue; - rb_set_time(); - /* error! */ - return -1; - /* NOTREACHED */ - } - rb_set_time(); + for(;;) { + to.tv_sec = 0; + to.tv_usec = delay * 1000; + num = select(rb_maxfd + 1, &tmpreadfds, &tmpwritefds, NULL, &to); + if(num >= 0) + break; + if(rb_ignore_errno(errno)) + continue; + rb_set_time(); + /* error! */ + return -1; + /* NOTREACHED */ + } + rb_set_time(); - if(num == 0) - return 0; + if(num == 0) + return 0; - /* XXX we *could* optimise by falling out after doing num fds ... */ - for(fd = 0; fd < rb_maxfd + 1; fd++) - { - F = rb_find_fd(fd); - if(F == NULL) - continue; - if(FD_ISSET(fd, &tmpreadfds)) - { - hdl = F->read_handler; - F->read_handler = NULL; - if(hdl) - hdl(F, F->read_data); - } + /* XXX we *could* optimise by falling out after doing num fds ... */ + for(fd = 0; fd < rb_maxfd + 1; fd++) { + F = rb_find_fd(fd); + if(F == NULL) + continue; + if(FD_ISSET(fd, &tmpreadfds)) { + hdl = F->read_handler; + F->read_handler = NULL; + if(hdl) + hdl(F, F->read_data); + } - if(!IsFDOpen(F)) - continue; /* Read handler closed us..go on */ + if(!IsFDOpen(F)) + continue; /* Read handler closed us..go on */ - if(FD_ISSET(fd, &tmpwritefds)) - { - hdl = F->write_handler; - F->write_handler = NULL; - if(hdl) - hdl(F, F->write_data); - } + if(FD_ISSET(fd, &tmpwritefds)) { + hdl = F->write_handler; + F->write_handler = NULL; + if(hdl) + hdl(F, F->write_data); + } - if(F->read_handler == NULL) - select_update_selectfds(F, RB_SELECT_READ, NULL); - if(F->write_handler == NULL) - select_update_selectfds(F, RB_SELECT_WRITE, NULL); - } - return 0; + if(F->read_handler == NULL) + select_update_selectfds(F, RB_SELECT_READ, NULL); + if(F->write_handler == NULL) + select_update_selectfds(F, RB_SELECT_WRITE, NULL); + } + return 0; } #else /* select not supported..what sort of garbage is this? */ int rb_init_netio_select(void) { - return ENOSYS; + return ENOSYS; } void rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_select(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_select(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif diff --git a/libratbox/src/sigio.c b/libratbox/src/sigio.c index e3ce4bc..d07fa6f 100644 --- a/libratbox/src/sigio.c +++ b/libratbox/src/sigio.c @@ -53,11 +53,10 @@ #define RTSIGTIM (SIGRTMIN+1) -struct _pollfd_list -{ - struct pollfd *pollfds; - int maxindex; /* highest FD number */ - int allocated; +struct _pollfd_list { + struct pollfd *pollfds; + int maxindex; /* highest FD number */ + int allocated; }; typedef struct _pollfd_list pollfd_list_t; @@ -77,50 +76,47 @@ static sigset_t our_sigset; int rb_init_netio_sigio(void) { - int fd; - pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd))); - pollfd_list.allocated = rb_getmaxconnect(); - for(fd = 0; fd < rb_getmaxconnect(); fd++) - { - pollfd_list.pollfds[fd].fd = -1; - } + int fd; + pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd))); + pollfd_list.allocated = rb_getmaxconnect(); + for(fd = 0; fd < rb_getmaxconnect(); fd++) { + pollfd_list.pollfds[fd].fd = -1; + } - pollfd_list.maxindex = 0; + pollfd_list.maxindex = 0; - sigio_is_screwed = 1; /* Start off with poll first.. */ + sigio_is_screwed = 1; /* Start off with poll first.. */ - sigemptyset(&our_sigset); - sigaddset(&our_sigset, RTSIGIO); - sigaddset(&our_sigset, SIGIO); + sigemptyset(&our_sigset); + sigaddset(&our_sigset, RTSIGIO); + sigaddset(&our_sigset, SIGIO); #ifdef SIGIO_SCHED_EVENT - sigaddset(&our_sigset, RTSIGTIM); + sigaddset(&our_sigset, RTSIGTIM); #endif - sigprocmask(SIG_BLOCK, &our_sigset, NULL); - return 0; + sigprocmask(SIG_BLOCK, &our_sigset, NULL); + return 0; } static inline void resize_pollarray(int fd) { - if(rb_unlikely(fd >= pollfd_list.allocated)) - { - int x, old_value = pollfd_list.allocated; - pollfd_list.allocated += 1024; - pollfd_list.pollfds = - rb_realloc(pollfd_list.pollfds, - pollfd_list.allocated * (sizeof(struct pollfd))); - memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024); - for(x = old_value + 1; x < pollfd_list.allocated; x++) - { - pollfd_list.pollfds[x].fd = -1; - } - } + if(rb_unlikely(fd >= pollfd_list.allocated)) { + int x, old_value = pollfd_list.allocated; + pollfd_list.allocated += 1024; + pollfd_list.pollfds = + rb_realloc(pollfd_list.pollfds, + pollfd_list.allocated * (sizeof(struct pollfd))); + memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024); + for(x = old_value + 1; x < pollfd_list.allocated; x++) { + pollfd_list.pollfds[x].fd = -1; + } + } } /* * void setup_sigio_fd(int fd) - * + * * Input: File descriptor * Output: None * Side Effect: Sets the FD up for SIGIO @@ -129,29 +125,28 @@ resize_pollarray(int fd) int rb_setup_fd_sigio(rb_fde_t *F) { - int flags = 0; - int fd = F->fd; - flags = fcntl(fd, F_GETFL, 0); - if(flags == -1) - return 0; - /* if set async, clear it so we can reset it in the kernel :/ */ - if(flags & O_ASYNC) - { - flags &= ~O_ASYNC; - fcntl(fd, F_SETFL, flags); - } + int flags = 0; + int fd = F->fd; + flags = fcntl(fd, F_GETFL, 0); + if(flags == -1) + return 0; + /* if set async, clear it so we can reset it in the kernel :/ */ + if(flags & O_ASYNC) { + flags &= ~O_ASYNC; + fcntl(fd, F_SETFL, flags); + } - flags |= O_ASYNC | O_NONBLOCK; + flags |= O_ASYNC | O_NONBLOCK; - if(fcntl(fd, F_SETFL, flags) == -1) - return 0; + if(fcntl(fd, F_SETFL, flags) == -1) + return 0; - if(fcntl(fd, F_SETSIG, RTSIGIO) == -1) - return 0; - if(fcntl(fd, F_SETOWN, getpid()) == -1) - return 0; + if(fcntl(fd, F_SETSIG, RTSIGIO) == -1) + return 0; + if(fcntl(fd, F_SETOWN, getpid()) == -1) + return 0; - return 1; + return 1; } /* @@ -163,48 +158,42 @@ rb_setup_fd_sigio(rb_fde_t *F) void rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - if(F == NULL) - return; + if(F == NULL) + return; - if(type & RB_SELECT_READ) - { - F->read_handler = handler; - F->read_data = client_data; - if(handler != NULL) - F->pflags |= POLLRDNORM; - else - F->pflags &= ~POLLRDNORM; - } - if(type & RB_SELECT_WRITE) - { - F->write_handler = handler; - F->write_data = client_data; - if(handler != NULL) - F->pflags |= POLLWRNORM; - else - F->pflags &= ~POLLWRNORM; - } + if(type & RB_SELECT_READ) { + F->read_handler = handler; + F->read_data = client_data; + if(handler != NULL) + F->pflags |= POLLRDNORM; + else + F->pflags &= ~POLLRDNORM; + } + if(type & RB_SELECT_WRITE) { + F->write_handler = handler; + F->write_data = client_data; + if(handler != NULL) + F->pflags |= POLLWRNORM; + else + F->pflags &= ~POLLWRNORM; + } - resize_pollarray(F->fd); + resize_pollarray(F->fd); - if(F->pflags <= 0) - { - pollfd_list.pollfds[F->fd].events = 0; - pollfd_list.pollfds[F->fd].fd = -1; - if(F->fd == pollfd_list.maxindex) - { - while(pollfd_list.maxindex >= 0 - && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1) - pollfd_list.maxindex--; - } - } - else - { - pollfd_list.pollfds[F->fd].events = F->pflags; - pollfd_list.pollfds[F->fd].fd = F->fd; - if(F->fd > pollfd_list.maxindex) - pollfd_list.maxindex = F->fd; - } + if(F->pflags <= 0) { + pollfd_list.pollfds[F->fd].events = 0; + pollfd_list.pollfds[F->fd].fd = -1; + if(F->fd == pollfd_list.maxindex) { + while(pollfd_list.maxindex >= 0 + && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1) + pollfd_list.maxindex--; + } + } else { + pollfd_list.pollfds[F->fd].events = F->pflags; + pollfd_list.pollfds[F->fd].fd = F->fd; + if(F->fd > pollfd_list.maxindex) + pollfd_list.maxindex = F->fd; + } } @@ -226,225 +215,205 @@ rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_da int rb_select_sigio(long delay) { - int num = 0; - int revents = 0; - int sig; - int fd; - int ci; - PF *hdl; - rb_fde_t *F; - void *data; - siginfo_t si; + int num = 0; + int revents = 0; + int sig; + int fd; + int ci; + PF *hdl; + rb_fde_t *F; + void *data; + siginfo_t si; - struct timespec timeout; - if(rb_sigio_supports_event() || delay >= 0) - { - timeout.tv_sec = (delay / 1000); - timeout.tv_nsec = (delay % 1000) * 1000000; - } + struct timespec timeout; + if(rb_sigio_supports_event() || delay >= 0) { + timeout.tv_sec = (delay / 1000); + timeout.tv_nsec = (delay % 1000) * 1000000; + } - for(;;) - { - if(!sigio_is_screwed) - { - if(can_do_event || delay < 0) - { - sig = sigwaitinfo(&our_sigset, &si); - } - else - sig = sigtimedwait(&our_sigset, &si, &timeout); + for(;;) { + if(!sigio_is_screwed) { + if(can_do_event || delay < 0) { + sig = sigwaitinfo(&our_sigset, &si); + } else + sig = sigtimedwait(&our_sigset, &si, &timeout); - if(sig > 0) - { + if(sig > 0) { - if(sig == SIGIO) - { - rb_lib_log - ("Kernel RT Signal queue overflowed. Is ulimit -i too small(or perhaps /proc/sys/kernel/rtsig-max on old kernels)"); - sigio_is_screwed = 1; - break; - } + if(sig == SIGIO) { + rb_lib_log + ("Kernel RT Signal queue overflowed. Is ulimit -i too small(or perhaps /proc/sys/kernel/rtsig-max on old kernels)"); + sigio_is_screwed = 1; + break; + } #ifdef SIGIO_SCHED_EVENT - if(sig == RTSIGTIM && can_do_event) - { - struct ev_entry *ev = (struct ev_entry *)si.si_ptr; - if(ev == NULL) - continue; - rb_run_event(ev); - continue; - } + if(sig == RTSIGTIM && can_do_event) { + struct ev_entry *ev = (struct ev_entry *)si.si_ptr; + if(ev == NULL) + continue; + rb_run_event(ev); + continue; + } #endif - fd = si.si_fd; - pollfd_list.pollfds[fd].revents |= si.si_band; - revents = pollfd_list.pollfds[fd].revents; - num++; - F = rb_find_fd(fd); - if(F == NULL) - continue; + fd = si.si_fd; + pollfd_list.pollfds[fd].revents |= si.si_band; + revents = pollfd_list.pollfds[fd].revents; + num++; + F = rb_find_fd(fd); + if(F == NULL) + continue; - if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) - { - hdl = F->read_handler; - data = F->read_data; - F->read_handler = NULL; - F->read_data = NULL; - if(hdl) - hdl(F, data); - } + if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) { + hdl = F->read_handler; + data = F->read_data; + F->read_handler = NULL; + F->read_data = NULL; + if(hdl) + hdl(F, data); + } - if(revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) - { - hdl = F->write_handler; - data = F->write_data; - F->write_handler = NULL; - F->write_data = NULL; - if(hdl) - hdl(F, data); - } - } - else - break; + if(revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) { + hdl = F->write_handler; + data = F->write_data; + F->write_handler = NULL; + F->write_data = NULL; + if(hdl) + hdl(F, data); + } + } else + break; - } - else - break; - } + } else + break; + } - if(!sigio_is_screwed) /* We don't need to proceed */ - { - rb_set_time(); - return 0; - } + if(!sigio_is_screwed) { /* We don't need to proceed */ + rb_set_time(); + return 0; + } - signal(RTSIGIO, SIG_IGN); - signal(RTSIGIO, SIG_DFL); - sigio_is_screwed = 0; + signal(RTSIGIO, SIG_IGN); + signal(RTSIGIO, SIG_DFL); + sigio_is_screwed = 0; - num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay); - rb_set_time(); - if(num < 0) - { - if(!rb_ignore_errno(errno)) - return RB_OK; - else - return RB_ERROR; - } - if(num == 0) - return RB_OK; + num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay); + rb_set_time(); + if(num < 0) { + if(!rb_ignore_errno(errno)) + return RB_OK; + else + return RB_ERROR; + } + if(num == 0) + return RB_OK; - /* XXX we *could* optimise by falling out after doing num fds ... */ - for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) - { - if(((revents = pollfd_list.pollfds[ci].revents) == 0) - || (pollfd_list.pollfds[ci].fd) == -1) - continue; - fd = pollfd_list.pollfds[ci].fd; - F = rb_find_fd(fd); - if(F == NULL) - continue; - if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) - { - hdl = F->read_handler; - data = F->read_data; - F->read_handler = NULL; - F->read_data = NULL; - if(hdl) - hdl(F, data); - } + /* XXX we *could* optimise by falling out after doing num fds ... */ + for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) { + if(((revents = pollfd_list.pollfds[ci].revents) == 0) + || (pollfd_list.pollfds[ci].fd) == -1) + continue; + fd = pollfd_list.pollfds[ci].fd; + F = rb_find_fd(fd); + if(F == NULL) + continue; + if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) { + hdl = F->read_handler; + data = F->read_data; + F->read_handler = NULL; + F->read_data = NULL; + if(hdl) + hdl(F, data); + } - if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) - { - hdl = F->write_handler; - data = F->write_data; - F->write_handler = NULL; - F->write_data = NULL; - if(hdl) - hdl(F, data); - } - if(F->read_handler == NULL) - rb_setselect_sigio(F, RB_SELECT_READ, NULL, NULL); - if(F->write_handler == NULL) - rb_setselect_sigio(F, RB_SELECT_WRITE, NULL, NULL); + if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) { + hdl = F->write_handler; + data = F->write_data; + F->write_handler = NULL; + F->write_data = NULL; + if(hdl) + hdl(F, data); + } + if(F->read_handler == NULL) + rb_setselect_sigio(F, RB_SELECT_READ, NULL, NULL); + if(F->write_handler == NULL) + rb_setselect_sigio(F, RB_SELECT_WRITE, NULL, NULL); - } + } - return 0; + return 0; } #if defined(SIGIO_SCHED_EVENT) void rb_sigio_init_event(void) { - rb_sigio_supports_event(); + rb_sigio_supports_event(); } int rb_sigio_supports_event(void) { - timer_t timer; - struct sigevent ev; - if(can_do_event == 1) - return 1; - if(can_do_event == -1) - return 0; + timer_t timer; + struct sigevent ev; + if(can_do_event == 1) + return 1; + if(can_do_event == -1) + return 0; - ev.sigev_signo = SIGVTALRM; - ev.sigev_notify = SIGEV_SIGNAL; - if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) - { - can_do_event = -1; - return 0; - } - timer_delete(timer); - can_do_event = 1; - return 1; + ev.sigev_signo = SIGVTALRM; + ev.sigev_notify = SIGEV_SIGNAL; + if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) { + can_do_event = -1; + return 0; + } + timer_delete(timer); + can_do_event = 1; + return 1; } int rb_sigio_sched_event(struct ev_entry *event, int when) { - timer_t *id; - struct sigevent ev; - struct itimerspec ts; - if(can_do_event <= 0) - return 0; + timer_t *id; + struct sigevent ev; + struct itimerspec ts; + if(can_do_event <= 0) + return 0; - memset(&ev, 0, sizeof(&ev)); - event->comm_ptr = rb_malloc(sizeof(timer_t)); - id = event->comm_ptr; - ev.sigev_notify = SIGEV_SIGNAL; - ev.sigev_signo = RTSIGTIM; - ev.sigev_value.sival_ptr = event; + memset(&ev, 0, sizeof(&ev)); + event->comm_ptr = rb_malloc(sizeof(timer_t)); + id = event->comm_ptr; + ev.sigev_notify = SIGEV_SIGNAL; + ev.sigev_signo = RTSIGTIM; + ev.sigev_value.sival_ptr = event; - if(timer_create(CLOCK_REALTIME, &ev, id) < 0) - { - rb_lib_log("timer_create: %s\n", strerror(errno)); - return 0; - } - memset(&ts, 0, sizeof(ts)); - ts.it_value.tv_sec = when; - ts.it_value.tv_nsec = 0; - if(event->frequency != 0) - ts.it_interval = ts.it_value; + if(timer_create(CLOCK_REALTIME, &ev, id) < 0) { + rb_lib_log("timer_create: %s\n", strerror(errno)); + return 0; + } + memset(&ts, 0, sizeof(ts)); + ts.it_value.tv_sec = when; + ts.it_value.tv_nsec = 0; + if(event->frequency != 0) + ts.it_interval = ts.it_value; - if(timer_settime(*id, 0, &ts, NULL) < 0) - { - rb_lib_log("timer_settime: %s\n", strerror(errno)); - return 0; - } - return 1; + if(timer_settime(*id, 0, &ts, NULL) < 0) { + rb_lib_log("timer_settime: %s\n", strerror(errno)); + return 0; + } + return 1; } void rb_sigio_unsched_event(struct ev_entry *event) { - if(can_do_event <= 0) - return; - timer_delete(*((timer_t *) event->comm_ptr)); - rb_free(event->comm_ptr); - event->comm_ptr = NULL; + if(can_do_event <= 0) + return; + timer_delete(*((timer_t *) event->comm_ptr)); + rb_free(event->comm_ptr); + event->comm_ptr = NULL; } #endif /* SIGIO_SCHED_EVENT */ @@ -453,28 +422,28 @@ rb_sigio_unsched_event(struct ev_entry *event) int rb_init_netio_sigio(void) { - return ENOSYS; + return ENOSYS; } void rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_sigio(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_sigio(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif @@ -483,26 +452,26 @@ rb_setup_fd_sigio(rb_fde_t *F) void rb_sigio_init_event(void) { - return; + return; } int rb_sigio_sched_event(struct ev_entry *event, int when) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } void rb_sigio_unsched_event(struct ev_entry *event) { - return; + return; } int rb_sigio_supports_event(void) { - errno = ENOSYS; - return 0; + errno = ENOSYS; + return 0; } #endif /* !USING_SIGIO || !SIGIO_SCHED_EVENT */ diff --git a/libratbox/src/snprintf.c b/libratbox/src/snprintf.c index be871cc..4c947f6 100644 --- a/libratbox/src/snprintf.c +++ b/libratbox/src/snprintf.c @@ -17,7 +17,7 @@ * Wirzenius wrote this portably, Torvalds fucked it up :-) */ -/* +/* * Fri Jul 13 2001 Crutcher Dunnavant * - changed to provide snprintf and vsnprintf functions * So Feb 1 16:51:32 CET 2004 Juergen Quade @@ -29,11 +29,11 @@ static int skip_atoi(const char **s) { - int i = 0; + int i = 0; - while(isdigit(**s)) - i = i * 10 + *((*s)++) - '0'; - return i; + while(isdigit(**s)) + i = i * 10 + *((*s)++) - '0'; + return i; } /* Decimal conversion is by far the most typical, and is used @@ -49,97 +49,93 @@ skip_atoi(const char **s) static char * put_dec_trunc(char *buf, unsigned q) { - unsigned d3, d2, d1, d0; - d1 = (q >> 4) & 0xf; - d2 = (q >> 8) & 0xf; - d3 = (q >> 12); + unsigned d3, d2, d1, d0; + d1 = (q >> 4) & 0xf; + d2 = (q >> 8) & 0xf; + d3 = (q >> 12); - d0 = 6 * (d3 + d2 + d1) + (q & 0xf); - q = (d0 * 0xcd) >> 11; - d0 = d0 - 10 * q; - *buf++ = d0 + '0'; /* least significant digit */ - d1 = q + 9 * d3 + 5 * d2 + d1; - if(d1 != 0) - { - q = (d1 * 0xcd) >> 11; - d1 = d1 - 10 * q; - *buf++ = d1 + '0'; /* next digit */ + d0 = 6 * (d3 + d2 + d1) + (q & 0xf); + q = (d0 * 0xcd) >> 11; + d0 = d0 - 10 * q; + *buf++ = d0 + '0'; /* least significant digit */ + d1 = q + 9 * d3 + 5 * d2 + d1; + if(d1 != 0) { + q = (d1 * 0xcd) >> 11; + d1 = d1 - 10 * q; + *buf++ = d1 + '0'; /* next digit */ - d2 = q + 2 * d2; - if((d2 != 0) || (d3 != 0)) - { - q = (d2 * 0xd) >> 7; - d2 = d2 - 10 * q; - *buf++ = d2 + '0'; /* next digit */ + d2 = q + 2 * d2; + if((d2 != 0) || (d3 != 0)) { + q = (d2 * 0xd) >> 7; + d2 = d2 - 10 * q; + *buf++ = d2 + '0'; /* next digit */ - d3 = q + 4 * d3; - if(d3 != 0) - { - q = (d3 * 0xcd) >> 11; - d3 = d3 - 10 * q; - *buf++ = d3 + '0'; /* next digit */ - if(q != 0) - *buf++ = q + '0'; /* most sign. digit */ - } - } - } - return buf; + d3 = q + 4 * d3; + if(d3 != 0) { + q = (d3 * 0xcd) >> 11; + d3 = d3 - 10 * q; + *buf++ = d3 + '0'; /* next digit */ + if(q != 0) + *buf++ = q + '0'; /* most sign. digit */ + } + } + } + return buf; } /* Same with if's removed. Always emits five digits */ static char * put_dec_full(char *buf, unsigned q) { - /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ - /* but anyway, gcc produces better code with full-sized ints */ - unsigned d3, d2, d1, d0; - d1 = (q >> 4) & 0xf; - d2 = (q >> 8) & 0xf; - d3 = (q >> 12); + /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ + /* but anyway, gcc produces better code with full-sized ints */ + unsigned d3, d2, d1, d0; + d1 = (q >> 4) & 0xf; + d2 = (q >> 8) & 0xf; + d3 = (q >> 12); - /* Possible ways to approx. divide by 10 */ - /* gcc -O2 replaces multiply with shifts and adds */ - // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) - // (x * 0x67) >> 10: 1100111 - // (x * 0x34) >> 9: 110100 - same - // (x * 0x1a) >> 8: 11010 - same - // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) + /* Possible ways to approx. divide by 10 */ + /* gcc -O2 replaces multiply with shifts and adds */ + // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) + // (x * 0x67) >> 10: 1100111 + // (x * 0x34) >> 9: 110100 - same + // (x * 0x1a) >> 8: 11010 - same + // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) - d0 = 6 * (d3 + d2 + d1) + (q & 0xf); - q = (d0 * 0xcd) >> 11; - d0 = d0 - 10 * q; - *buf++ = d0 + '0'; - d1 = q + 9 * d3 + 5 * d2 + d1; - q = (d1 * 0xcd) >> 11; - d1 = d1 - 10 * q; - *buf++ = d1 + '0'; + d0 = 6 * (d3 + d2 + d1) + (q & 0xf); + q = (d0 * 0xcd) >> 11; + d0 = d0 - 10 * q; + *buf++ = d0 + '0'; + d1 = q + 9 * d3 + 5 * d2 + d1; + q = (d1 * 0xcd) >> 11; + d1 = d1 - 10 * q; + *buf++ = d1 + '0'; - d2 = q + 2 * d2; - q = (d2 * 0xd) >> 7; - d2 = d2 - 10 * q; - *buf++ = d2 + '0'; + d2 = q + 2 * d2; + q = (d2 * 0xd) >> 7; + d2 = d2 - 10 * q; + *buf++ = d2 + '0'; - d3 = q + 4 * d3; - q = (d3 * 0xcd) >> 11; /* - shorter code */ - /* q = (d3 * 0x67) >> 10; - would also work */ - d3 = d3 - 10 * q; - *buf++ = d3 + '0'; - *buf++ = q + '0'; - return buf; + d3 = q + 4 * d3; + q = (d3 * 0xcd) >> 11; /* - shorter code */ + /* q = (d3 * 0x67) >> 10; - would also work */ + d3 = d3 - 10 * q; + *buf++ = d3 + '0'; + *buf++ = q + '0'; + return buf; } static char * put_dec(char *buf, unsigned long long int num) { - while(1) - { - unsigned rem; - if(num < 100000) - return put_dec_trunc(buf, num); - rem = num % 100000; - num = num / 100000; - buf = put_dec_full(buf, rem); - } + while(1) { + unsigned rem; + if(num < 100000) + return put_dec_trunc(buf, num); + rem = num % 100000; + num = num / 100000; + buf = put_dec_full(buf, rem); + } } #define ZEROPAD 1 /* pad with zero */ @@ -154,140 +150,120 @@ static size_t number(char *const buf, const size_t size, size_t idx, unsigned long long int num, int base, int field_width, int precision, int type) { - char sign, tmp[66]; - const char *digits; - /* we are called with base 8, 10 or 16, only, thus don't need "g..." */ - static const char small_digits[] = "0123456789abcdefx"; /* "ghijklmnopqrstuvwxyz"; */ - static const char large_digits[] = "0123456789ABCDEFX"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ - int need_pfx = ((type & SPECIAL) && base != 10); - int i; + char sign, tmp[66]; + const char *digits; + /* we are called with base 8, 10 or 16, only, thus don't need "g..." */ + static const char small_digits[] = "0123456789abcdefx"; /* "ghijklmnopqrstuvwxyz"; */ + static const char large_digits[] = "0123456789ABCDEFX"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ + int need_pfx = ((type & SPECIAL) && base != 10); + int i; - digits = (type & LARGE) ? large_digits : small_digits; - if(type & LEFT) - type &= ~ZEROPAD; - if(base < 2 || base > 36) - return idx; - sign = 0; - if(type & SIGN) - { - if((signed long long int)num < 0) - { - sign = '-'; - num = -(signed long long int)num; - field_width--; - } - else if(type & PLUS) - { - sign = '+'; - field_width--; - } - else if(type & SPACE) - { - sign = ' '; - field_width--; - } - } - if(need_pfx) - { - field_width--; - if(base == 16) - field_width--; - } + digits = (type & LARGE) ? large_digits : small_digits; + if(type & LEFT) + type &= ~ZEROPAD; + if(base < 2 || base > 36) + return idx; + sign = 0; + if(type & SIGN) { + if((signed long long int)num < 0) { + sign = '-'; + num = -(signed long long int)num; + field_width--; + } else if(type & PLUS) { + sign = '+'; + field_width--; + } else if(type & SPACE) { + sign = ' '; + field_width--; + } + } + if(need_pfx) { + field_width--; + if(base == 16) + field_width--; + } - /* generate full string in tmp[], in reverse order */ - i = 0; - if(num == 0) - tmp[i++] = '0'; - /* Generic code, for any base: - else do { - tmp[i++] = digits[do_div(num,base)]; - } while (num != 0); - */ - else if(base != 10) - { /* 8 or 16 */ - int mask = base - 1; - int shift = 3; - if(base == 16) - shift = 4; - do - { - tmp[i++] = digits[((unsigned char)num) & mask]; - num >>= shift; - } - while(num); - } - else - { /* base 10 */ - i = put_dec(tmp, num) - tmp; - } + /* generate full string in tmp[], in reverse order */ + i = 0; + if(num == 0) + tmp[i++] = '0'; + /* Generic code, for any base: + else do { + tmp[i++] = digits[do_div(num,base)]; + } while (num != 0); + */ + else if(base != 10) { + /* 8 or 16 */ + int mask = base - 1; + int shift = 3; + if(base == 16) + shift = 4; + do { + tmp[i++] = digits[((unsigned char)num) & mask]; + num >>= shift; + } while(num); + } else { + /* base 10 */ + i = put_dec(tmp, num) - tmp; + } - /* printing 100 using %2d gives "100", not "00" */ - if(i > precision) - precision = i; - /* leading space padding */ - field_width -= precision; - if(!(type & (ZEROPAD + LEFT))) - { - while(--field_width >= 0) - { - if(idx < size) - buf[idx] = ' '; - ++idx; - } - } - /* sign */ - if(sign) - { - if(idx < size) - buf[idx] = sign; - ++idx; - } - /* "0x" / "0" prefix */ - if(need_pfx) - { - if(idx < size) - buf[idx] = '0'; - ++idx; - if(base == 16) - { - if(idx < size) - buf[idx] = digits[16]; /* for arbitrary base: digits[33]; */ - ++idx; - } - } - /* zero or space padding */ - if(!(type & LEFT)) - { - char c = (type & ZEROPAD) ? '0' : ' '; - while(--field_width >= 0) - { - if(idx < size) - buf[idx] = c; - ++idx; - } - } - /* hmm even more zero padding? */ - while(i <= --precision) - { - if(idx < size) - buf[idx] = '0'; - ++idx; - } - /* actual digits of result */ - while(--i >= 0) - { - if(idx < size) - buf[idx] = tmp[i]; - ++idx; - } - /* trailing space padding */ - while(--field_width >= 0) - { - if(idx < size) - buf[idx] = ' '; - ++idx; - } - return idx; + /* printing 100 using %2d gives "100", not "00" */ + if(i > precision) + precision = i; + /* leading space padding */ + field_width -= precision; + if(!(type & (ZEROPAD + LEFT))) { + while(--field_width >= 0) { + if(idx < size) + buf[idx] = ' '; + ++idx; + } + } + /* sign */ + if(sign) { + if(idx < size) + buf[idx] = sign; + ++idx; + } + /* "0x" / "0" prefix */ + if(need_pfx) { + if(idx < size) + buf[idx] = '0'; + ++idx; + if(base == 16) { + if(idx < size) + buf[idx] = digits[16]; /* for arbitrary base: digits[33]; */ + ++idx; + } + } + /* zero or space padding */ + if(!(type & LEFT)) { + char c = (type & ZEROPAD) ? '0' : ' '; + while(--field_width >= 0) { + if(idx < size) + buf[idx] = c; + ++idx; + } + } + /* hmm even more zero padding? */ + while(i <= --precision) { + if(idx < size) + buf[idx] = '0'; + ++idx; + } + /* actual digits of result */ + while(--i >= 0) { + if(idx < size) + buf[idx] = tmp[i]; + ++idx; + } + /* trailing space padding */ + while(--field_width >= 0) { + if(idx < size) + buf[idx] = ' '; + ++idx; + } + return idx; } /** @@ -311,281 +287,243 @@ number(char *const buf, const size_t size, size_t idx, unsigned long long int nu int rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) { - int len; - unsigned long long int num; - int i, base; - char c; - size_t idx; - const char *s; + int len; + unsigned long long int num; + int i, base; + char c; + size_t idx; + const char *s; - int flags; /* flags to number() */ + int flags; /* flags to number() */ - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max number of chars for from string */ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - /* 'z' support added 23/7/1999 S.H. */ - /* 'z' changed to 'Z' --davidm 1/25/99 */ - /* 't' added for ptrdiff_t */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + /* 'z' support added 23/7/1999 S.H. */ + /* 'z' changed to 'Z' --davidm 1/25/99 */ + /* 't' added for ptrdiff_t */ - /* Reject out-of-range values early. Large positive sizes are - used for unknown buffer sizes. */ - if(rb_unlikely(size > INT_MAX)) - { - return 0; - } + /* Reject out-of-range values early. Large positive sizes are + used for unknown buffer sizes. */ + if(rb_unlikely(size > INT_MAX)) { + return 0; + } - idx = 0; + idx = 0; - for(; *fmt; ++fmt) - { - if(*fmt != '%') - { - if(idx < size) - buf[idx] = *fmt; - ++idx; - continue; - } + for(; *fmt; ++fmt) { + if(*fmt != '%') { + if(idx < size) + buf[idx] = *fmt; + ++idx; + continue; + } - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) - { - case '-': - flags |= LEFT; - goto repeat; - case '+': - flags |= PLUS; - goto repeat; - case ' ': - flags |= SPACE; - goto repeat; - case '#': - flags |= SPECIAL; - goto repeat; - case '0': - flags |= ZEROPAD; - goto repeat; - } + /* process flags */ + flags = 0; +repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': + flags |= LEFT; + goto repeat; + case '+': + flags |= PLUS; + goto repeat; + case ' ': + flags |= SPACE; + goto repeat; + case '#': + flags |= SPECIAL; + goto repeat; + case '0': + flags |= ZEROPAD; + goto repeat; + } - /* get field width */ - field_width = -1; - if(isdigit(*fmt)) - field_width = skip_atoi(&fmt); - else if(*fmt == '*') - { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if(field_width < 0) - { - field_width = -field_width; - flags |= LEFT; - } - } + /* get field width */ + field_width = -1; + if(isdigit(*fmt)) + field_width = skip_atoi(&fmt); + else if(*fmt == '*') { + ++fmt; + /* it's the next argument */ + field_width = va_arg(args, int); + if(field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } - /* get the precision */ - precision = -1; - if(*fmt == '.') - { - ++fmt; - if(isdigit(*fmt)) - precision = skip_atoi(&fmt); - else if(*fmt == '*') - { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if(precision < 0) - precision = 0; - } + /* get the precision */ + precision = -1; + if(*fmt == '.') { + ++fmt; + if(isdigit(*fmt)) + precision = skip_atoi(&fmt); + else if(*fmt == '*') { + ++fmt; + /* it's the next argument */ + precision = va_arg(args, int); + } + if(precision < 0) + precision = 0; + } - /* get the conversion qualifier */ - qualifier = -1; - if(*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || - *fmt == 'Z' || *fmt == 'z' || *fmt == 't') - { - qualifier = *fmt; - ++fmt; - if(qualifier == 'l' && *fmt == 'l') - { - qualifier = 'L'; - ++fmt; - } - } + /* get the conversion qualifier */ + qualifier = -1; + if(*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || + *fmt == 'Z' || *fmt == 'z' || *fmt == 't') { + qualifier = *fmt; + ++fmt; + if(qualifier == 'l' && *fmt == 'l') { + qualifier = 'L'; + ++fmt; + } + } - /* default base */ - base = 10; + /* default base */ + base = 10; - switch (*fmt) - { - case 'c': - if(!(flags & LEFT)) - { - while(--field_width > 0) - { - if(idx < size) - buf[idx] = ' '; - ++idx; - } - } - c = (unsigned char)va_arg(args, int); - if(idx < size) - buf[idx] = c; - ++idx; - while(--field_width > 0) - { - if(idx < size) - buf[idx] = ' '; - ++idx; - } - continue; + switch (*fmt) { + case 'c': + if(!(flags & LEFT)) { + while(--field_width > 0) { + if(idx < size) + buf[idx] = ' '; + ++idx; + } + } + c = (unsigned char)va_arg(args, int); + if(idx < size) + buf[idx] = c; + ++idx; + while(--field_width > 0) { + if(idx < size) + buf[idx] = ' '; + ++idx; + } + continue; - case 's': - s = va_arg(args, char *); - if(s == NULL) - { - abort(); /* prefer blowing up vs corrupt data */ - } - len = rb_strnlen(s, precision); + case 's': + s = va_arg(args, char *); + if(s == NULL) { + abort(); /* prefer blowing up vs corrupt data */ + } + len = rb_strnlen(s, precision); - if(!(flags & LEFT)) - { - while(len < field_width--) - { - if(idx < size) - buf[idx] = ' '; - ++idx; - } - } - for(i = 0; i < len; ++i) - { - if(idx < size) - buf[idx] = *s; - ++idx; - ++s; - } - while(len < field_width--) - { - if(idx < size) - buf[idx] = ' '; - ++idx; - } - continue; + if(!(flags & LEFT)) { + while(len < field_width--) { + if(idx < size) + buf[idx] = ' '; + ++idx; + } + } + for(i = 0; i < len; ++i) { + if(idx < size) + buf[idx] = *s; + ++idx; + ++s; + } + while(len < field_width--) { + if(idx < size) + buf[idx] = ' '; + ++idx; + } + continue; - case 'p': - if(field_width == -1) - { - field_width = 2 * sizeof(void *); - flags |= ZEROPAD; - } - idx = number(buf, size, idx, - (unsigned long)va_arg(args, void *), - 16, field_width, precision, flags); - continue; + case 'p': + if(field_width == -1) { + field_width = 2 * sizeof(void *); + flags |= ZEROPAD; + } + idx = number(buf, size, idx, + (unsigned long)va_arg(args, void *), + 16, field_width, precision, flags); + continue; - case 'n': - /* FIXME: - * What does C99 say about the overflow case here? */ - if(qualifier == 'l') - { - long *ip = va_arg(args, long *); - *ip = idx; - } - else if(qualifier == 'Z' || qualifier == 'z') - { - size_t *ip = va_arg(args, size_t *); - *ip = idx; - } - else - { - int *ip = va_arg(args, int *); - *ip = idx; - } - continue; + case 'n': + /* FIXME: + * What does C99 say about the overflow case here? */ + if(qualifier == 'l') { + long *ip = va_arg(args, long *); + *ip = idx; + } else if(qualifier == 'Z' || qualifier == 'z') { + size_t *ip = va_arg(args, size_t *); + *ip = idx; + } else { + int *ip = va_arg(args, int *); + *ip = idx; + } + continue; - case '%': - if(idx < size) - buf[idx] = '%'; - ++idx; - continue; + case '%': + if(idx < size) + buf[idx] = '%'; + ++idx; + continue; - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; + /* integer number formats - set up the flags and "break" */ + case 'o': + base = 8; + break; - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; + case 'X': + flags |= LARGE; + case 'x': + base = 16; + break; - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; + case 'd': + case 'i': + flags |= SIGN; + case 'u': + break; - default: - if(idx < size) - buf[idx] = '%'; - ++idx; - if(*fmt) - { - if(idx < size) - buf[idx] = *fmt; - ++idx; - } - else - { - --fmt; - } - continue; - } - if(qualifier == 'L') - num = va_arg(args, long long int); - else if(qualifier == 'l') - { - num = va_arg(args, unsigned long); - if(flags & SIGN) - num = (signed long)num; - } - else if(qualifier == 'Z' || qualifier == 'z') - { - num = va_arg(args, size_t); - } - else if(qualifier == 't') - { - num = va_arg(args, ptrdiff_t); - } - else if(qualifier == 'h') - { - num = (unsigned short)va_arg(args, int); - if(flags & SIGN) - num = (signed short)num; - } - else - { - num = va_arg(args, unsigned int); - if(flags & SIGN) - num = (signed int)num; - } - idx = number(buf, size, idx, num, base, field_width, precision, flags); - } - if(size > 0) - { - if(idx < size) - buf[idx] = '\0'; - else - buf[size - 1] = '\0'; - } - /* the trailing null byte doesn't count towards the total */ - return idx; + default: + if(idx < size) + buf[idx] = '%'; + ++idx; + if(*fmt) { + if(idx < size) + buf[idx] = *fmt; + ++idx; + } else { + --fmt; + } + continue; + } + if(qualifier == 'L') + num = va_arg(args, long long int); + else if(qualifier == 'l') { + num = va_arg(args, unsigned long); + if(flags & SIGN) + num = (signed long)num; + } else if(qualifier == 'Z' || qualifier == 'z') { + num = va_arg(args, size_t); + } else if(qualifier == 't') { + num = va_arg(args, ptrdiff_t); + } else if(qualifier == 'h') { + num = (unsigned short)va_arg(args, int); + if(flags & SIGN) + num = (signed short)num; + } else { + num = va_arg(args, unsigned int); + if(flags & SIGN) + num = (signed int)num; + } + idx = number(buf, size, idx, num, base, field_width, precision, flags); + } + if(size > 0) { + if(idx < size) + buf[idx] = '\0'; + else + buf[size - 1] = '\0'; + } + /* the trailing null byte doesn't count towards the total */ + return idx; } /** @@ -603,13 +541,13 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) int rb_snprintf(char *buf, size_t size, const char *fmt, ...) { - va_list args; - int i; + va_list args; + int i; - va_start(args, fmt); - i = rb_vsnprintf(buf, size, fmt, args); - va_end(args); - return i; + va_start(args, fmt); + i = rb_vsnprintf(buf, size, fmt, args); + va_end(args); + return i; } /** @@ -628,7 +566,7 @@ rb_snprintf(char *buf, size_t size, const char *fmt, ...) int rb_vsprintf(char *buf, const char *fmt, va_list args) { - return rb_vsnprintf(buf, INT_MAX, fmt, args); + return rb_vsnprintf(buf, INT_MAX, fmt, args); } /** @@ -644,13 +582,13 @@ rb_vsprintf(char *buf, const char *fmt, va_list args) int rb_sprintf(char *buf, const char *fmt, ...) { - va_list args; - int i; + va_list args; + int i; - va_start(args, fmt); - i = rb_vsnprintf(buf, INT_MAX, fmt, args); - va_end(args); - return i; + va_start(args, fmt); + i = rb_vsnprintf(buf, INT_MAX, fmt, args); + va_end(args); + return i; } /* @@ -661,8 +599,8 @@ rb_sprintf(char *buf, const char *fmt, ...) int rb_vsprintf_append(char *str, const char *format, va_list ap) { - size_t x = strlen(str); - return (rb_vsprintf(str + x, format, ap) + x); + size_t x = strlen(str); + return (rb_vsprintf(str + x, format, ap) + x); } /* @@ -672,12 +610,12 @@ rb_vsprintf_append(char *str, const char *format, va_list ap) int rb_sprintf_append(char *str, const char *format, ...) { - int x; - va_list ap; - va_start(ap, format); - x = rb_vsprintf_append(str, format, ap); - va_end(ap); - return (x); + int x; + va_list ap; + va_start(ap, format); + x = rb_vsprintf_append(str, format, ap); + va_end(ap); + return (x); } /* @@ -689,17 +627,16 @@ rb_sprintf_append(char *str, const char *format, ...) int rb_vsnprintf_append(char *str, size_t len, const char *format, va_list ap) { - size_t x; - if(len == 0) - return 0; - x = strlen(str); + size_t x; + if(len == 0) + return 0; + x = strlen(str); - if(len < x) - { - str[len - 1] = '\0'; - return len - 1; - } - return (rb_vsnprintf(str + x, len - x, format, ap) + x); + if(len < x) { + str[len - 1] = '\0'; + return len - 1; + } + return (rb_vsnprintf(str + x, len - x, format, ap) + x); } /* @@ -711,10 +648,10 @@ rb_vsnprintf_append(char *str, size_t len, const char *format, va_list ap) int rb_snprintf_append(char *str, size_t len, const char *format, ...) { - int x; - va_list ap; - va_start(ap, format); - x = rb_vsnprintf_append(str, len, format, ap); - va_end(ap); - return (x); + int x; + va_list ap; + va_start(ap, format); + x = rb_vsnprintf_append(str, len, format, ap); + va_end(ap); + return (x); } diff --git a/libratbox/src/tools.c b/libratbox/src/tools.c index 8c04dcd..5ed90c7 100644 --- a/libratbox/src/tools.c +++ b/libratbox/src/tools.c @@ -46,9 +46,9 @@ void rb_init_rb_dlink_nodes(size_t dh_size) { - dnode_heap = rb_bh_create(sizeof(rb_dlink_node), dh_size, "librb_dnode_heap"); - if(dnode_heap == NULL) - rb_outofmemory(); + dnode_heap = rb_bh_create(sizeof(rb_dlink_node), dh_size, "librb_dnode_heap"); + if(dnode_heap == NULL) + rb_outofmemory(); } /* @@ -61,7 +61,7 @@ rb_init_rb_dlink_nodes(size_t dh_size) rb_dlink_node * rb_make_rb_dlink_node(void) { - return (rb_bh_alloc(dnode_heap)); + return (rb_bh_alloc(dnode_heap)); } /* @@ -69,13 +69,13 @@ rb_make_rb_dlink_node(void) * * inputs - pointer to rb_dlink_node * output - NONE - * side effects - free given rb_dlink_node + * side effects - free given rb_dlink_node */ void rb_free_rb_dlink_node(rb_dlink_node *ptr) { - assert(ptr != NULL); - rb_bh_free(dnode_heap, ptr); + assert(ptr != NULL); + rb_bh_free(dnode_heap, ptr); } /* rb_string_to_array() @@ -88,76 +88,69 @@ rb_free_rb_dlink_node(rb_dlink_node *ptr) int rb_string_to_array(char *string, char **parv, int maxpara) { - char *p, *xbuf = string; - int x = 0; + char *p, *xbuf = string; + int x = 0; - parv[x] = NULL; + parv[x] = NULL; - if(string == NULL || string[0] == '\0') - return x; + if(string == NULL || string[0] == '\0') + return x; - while(*xbuf == ' ') /* skip leading spaces */ - xbuf++; - if(*xbuf == '\0') /* ignore all-space args */ - return x; + while(*xbuf == ' ') /* skip leading spaces */ + xbuf++; + if(*xbuf == '\0') /* ignore all-space args */ + return x; - do - { - if(*xbuf == ':') /* Last parameter */ - { - xbuf++; - parv[x++] = xbuf; - parv[x] = NULL; - return x; - } - else - { - parv[x++] = xbuf; - parv[x] = NULL; - if((p = strchr(xbuf, ' ')) != NULL) - { - *p++ = '\0'; - xbuf = p; - } - else - return x; - } - while(*xbuf == ' ') - xbuf++; - if(*xbuf == '\0') - return x; - } - while(x < maxpara - 1); + do { + if(*xbuf == ':') { /* Last parameter */ + xbuf++; + parv[x++] = xbuf; + parv[x] = NULL; + return x; + } else { + parv[x++] = xbuf; + parv[x] = NULL; + if((p = strchr(xbuf, ' ')) != NULL) { + *p++ = '\0'; + xbuf = p; + } else + return x; + } + while(*xbuf == ' ') + xbuf++; + if(*xbuf == '\0') + return x; + } while(x < maxpara - 1); - if(*p == ':') - p++; + if(*p == ':') + p++; - parv[x++] = p; - parv[x] = NULL; - return x; + parv[x++] = p; + parv[x] = NULL; + return x; } #ifndef HAVE_STRLCAT size_t rb_strlcat(char *dest, const char *src, size_t count) { - size_t dsize = strlen(dest); - size_t len = strlen(src); - size_t res = dsize + len; + size_t dsize = strlen(dest); + size_t len = strlen(src); + size_t res = dsize + len; - dest += dsize; - count -= dsize; - if(len >= count) - len = count - 1; - memcpy(dest, src, len); - dest[len] = 0; - return res; + dest += dsize; + count -= dsize; + if(len >= count) + len = count - 1; + memcpy(dest, src, len); + dest[len] = 0; + return res; } #else size_t rb_strlcat(char *dest, const char *src, size_t count) { - return strlcat(dest, src, count); + return strlcat(dest, src, count); } #endif @@ -165,21 +158,20 @@ rb_strlcat(char *dest, const char *src, size_t count) size_t rb_strlcpy(char *dest, const char *src, size_t size) { - size_t ret = strlen(src); + size_t ret = strlen(src); - if(size) - { - size_t len = (ret >= size) ? size - 1 : ret; - memcpy(dest, src, len); - dest[len] = '\0'; - } - return ret; + if(size) { + size_t len = (ret >= size) ? size - 1 : ret; + memcpy(dest, src, len); + dest[len] = '\0'; + } + return ret; } #else size_t rb_strlcpy(char *dest, const char *src, size_t size) { - return strlcpy(dest, src, size); + return strlcpy(dest, src, size); } #endif @@ -188,16 +180,16 @@ rb_strlcpy(char *dest, const char *src, size_t size) size_t rb_strnlen(const char *s, size_t count) { - const char *sc; - for(sc = s; count-- && *sc != '\0'; ++sc) - ;; - return sc - s; + const char *sc; + for(sc = s; count-- && *sc != '\0'; ++sc) + ;; + return sc - s; } #else size_t rb_strnlen(const char *s, size_t count) { - return strnlen(s, count); + return strnlen(s, count); } #endif @@ -205,18 +197,18 @@ rb_strnlen(const char *s, size_t count) * * input - * output - - * side effects - + * side effects - */ char * rb_basename(const char *path) { - const char *s; + const char *s; - if(!(s = strrchr(path, '/'))) - s = path; - else - s++; - return rb_strdup(s); + if(!(s = strrchr(path, '/'))) + s = path; + else + s++; + return rb_strdup(s); } /* @@ -226,17 +218,16 @@ rb_basename(const char *path) char * rb_dirname (const char *path) { - char *s; + char *s; - s = strrchr(path, '/'); - if(s == NULL) - { - return rb_strdup("."); - } + s = strrchr(path, '/'); + if(s == NULL) { + return rb_strdup("."); + } - /* remove extra slashes */ - while(s > path && *s == '/') - --s; + /* remove extra slashes */ + while(s > path && *s == '/') + --s; - return rb_strndup(path, ((uintptr_t)s - (uintptr_t)path) + 2); + return rb_strndup(path, ((uintptr_t)s - (uintptr_t)path) + 2); } diff --git a/libratbox/src/unix.c b/libratbox/src/unix.c index 397045e..05c1975 100644 --- a/libratbox/src/unix.c +++ b/libratbox/src/unix.c @@ -35,7 +35,7 @@ #include #ifdef __APPLE__ -#include +#include #endif #ifndef __APPLE__ @@ -44,40 +44,38 @@ extern char **environ; pid_t rb_spawn_process(const char *path, const char **argv) { - pid_t pid; - const void *arghack = argv; - char **myenviron; - int error; - posix_spawnattr_t spattr; - posix_spawnattr_init(&spattr); + pid_t pid; + const void *arghack = argv; + char **myenviron; + int error; + posix_spawnattr_t spattr; + posix_spawnattr_init(&spattr); #ifdef POSIX_SPAWN_USEVFORK - posix_spawnattr_setflags(&spattr, POSIX_SPAWN_USEVFORK); + posix_spawnattr_setflags(&spattr, POSIX_SPAWN_USEVFORK); #endif #ifdef __APPLE__ - myenviron = *_NSGetEnviron(); /* apple needs to go fuck themselves for this */ + myenviron = *_NSGetEnviron(); /* apple needs to go fuck themselves for this */ #else - myenviron = environ; + myenviron = environ; #endif - error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron); - posix_spawnattr_destroy(&spattr); - if (error != 0) - { - errno = error; - pid = -1; - } - return pid; + error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron); + posix_spawnattr_destroy(&spattr); + if (error != 0) { + errno = error; + pid = -1; + } + return pid; } #else pid_t rb_spawn_process(const char *path, const char **argv) { - pid_t pid; - if(!(pid = vfork())) - { - execv(path, (const void *)argv); /* make gcc shut up */ - _exit(1); /* if we're still here, we're screwed */ - } - return (pid); + pid_t pid; + if(!(pid = vfork())) { + execv(path, (const void *)argv); /* make gcc shut up */ + _exit(1); /* if we're still here, we're screwed */ + } + return (pid); } #endif @@ -85,21 +83,20 @@ rb_spawn_process(const char *path, const char **argv) int rb_gettimeofday(struct timeval *tv, void *tz) { - if(tv == NULL) - { - errno = EFAULT; - return -1; - } - tv->tv_usec = 0; - if(time(&tv->tv_sec) == -1) - return -1; - return 0; + if(tv == NULL) { + errno = EFAULT; + return -1; + } + tv->tv_usec = 0; + if(time(&tv->tv_sec) == -1) + return -1; + return 0; } #else int rb_gettimeofday(struct timeval *tv, void *tz) { - return (gettimeofday(tv, tz)); + return (gettimeofday(tv, tz)); } #endif @@ -107,15 +104,15 @@ void rb_sleep(unsigned int seconds, unsigned int useconds) { #ifdef HAVE_NANOSLEEP - struct timespec tv; - tv.tv_nsec = (useconds * 1000); - tv.tv_sec = seconds; - nanosleep(&tv, NULL); + struct timespec tv; + tv.tv_nsec = (useconds * 1000); + tv.tv_sec = seconds; + nanosleep(&tv, NULL); #else - struct timeval tv; - tv.tv_sec = seconds; - tv.tv_usec = useconds; - select(0, NULL, NULL, NULL, &tv); + struct timeval tv; + tv.tv_sec = seconds; + tv.tv_usec = useconds; + select(0, NULL, NULL, NULL, &tv); #endif } @@ -123,31 +120,31 @@ rb_sleep(unsigned int seconds, unsigned int useconds) char * rb_strerror(int error) { - return strerror(error); + return strerror(error); } int rb_kill(pid_t pid, int sig) { - return kill(pid, sig); + return kill(pid, sig); } int rb_setenv(const char *name, const char *value, int overwrite) { - return setenv(name, value, overwrite); + return setenv(name, value, overwrite); } pid_t rb_waitpid(pid_t pid, int *status, int options) { - return waitpid(pid, status, options); + return waitpid(pid, status, options); } pid_t rb_getpid(void) { - return getpid(); + return getpid(); } diff --git a/libratbox/src/win32.c b/libratbox/src/win32.c index 5c5e8ac..ec0c47a 100644 --- a/libratbox/src/win32.c +++ b/libratbox/src/win32.c @@ -38,10 +38,9 @@ static HWND hwnd; * having gettimeofday is nice... */ -typedef union -{ - unsigned __int64 ft_i64; - FILETIME ft_val; +typedef union { + unsigned __int64 ft_i64; + FILETIME ft_val; } FT_t; #ifdef __GNUC__ @@ -55,127 +54,115 @@ typedef union pid_t rb_getpid() { - return GetCurrentProcessId(); + return GetCurrentProcessId(); } int rb_gettimeofday(struct timeval *tp, void *not_used) { - FT_t ft; + FT_t ft; - /* this returns time in 100-nanosecond units (i.e. tens of usecs) */ - GetSystemTimeAsFileTime(&ft.ft_val); + /* this returns time in 100-nanosecond units (i.e. tens of usecs) */ + GetSystemTimeAsFileTime(&ft.ft_val); - /* seconds since epoch */ - tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000)); + /* seconds since epoch */ + tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000)); - /* microseconds remaining */ - tp->tv_usec = (long)((ft.ft_i64 / Const64(10)) % Const64(1000000)); + /* microseconds remaining */ + tp->tv_usec = (long)((ft.ft_i64 / Const64(10)) % Const64(1000000)); - return 0; + return 0; } pid_t rb_spawn_process(const char *path, const char **argv) { - PROCESS_INFORMATION pi; - STARTUPINFO si; - char cmd[MAX_PATH]; - memset(&pi, 0, sizeof(pi)); - memset(&si, 0, sizeof(si)); - rb_strlcpy(cmd, path, sizeof(cmd)); - if(CreateProcess(cmd, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == FALSE) - return -1; + PROCESS_INFORMATION pi; + STARTUPINFO si; + char cmd[MAX_PATH]; + memset(&pi, 0, sizeof(pi)); + memset(&si, 0, sizeof(si)); + rb_strlcpy(cmd, path, sizeof(cmd)); + if(CreateProcess(cmd, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == FALSE) + return -1; - return (pi.dwProcessId); + return (pi.dwProcessId); } pid_t rb_waitpid(int pid, int *status, int flags) { - DWORD timeout = (flags & WNOHANG) ? 0 : INFINITE; - HANDLE hProcess; - DWORD waitcode; + DWORD timeout = (flags & WNOHANG) ? 0 : INFINITE; + HANDLE hProcess; + DWORD waitcode; - hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); - if(hProcess) - { - waitcode = WaitForSingleObject(hProcess, timeout); - if(waitcode == WAIT_TIMEOUT) - { - CloseHandle(hProcess); - return 0; - } - else if(waitcode == WAIT_OBJECT_0) - { - if(GetExitCodeProcess(hProcess, &waitcode)) - { - *status = (int)((waitcode & 0xff) << 8); - CloseHandle(hProcess); - return pid; - } - } - CloseHandle(hProcess); - } - else - errno = ECHILD; + hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); + if(hProcess) { + waitcode = WaitForSingleObject(hProcess, timeout); + if(waitcode == WAIT_TIMEOUT) { + CloseHandle(hProcess); + return 0; + } else if(waitcode == WAIT_OBJECT_0) { + if(GetExitCodeProcess(hProcess, &waitcode)) { + *status = (int)((waitcode & 0xff) << 8); + CloseHandle(hProcess); + return pid; + } + } + CloseHandle(hProcess); + } else + errno = ECHILD; - return -1; + return -1; } int rb_setenv(const char *name, const char *value, int overwrite) { - char *buf; - int len; - if(!overwrite) - { - if((buf = getenv(name)) != NULL) - { - if(strlen(buf) > 0) - { - return 0; - } - } - } - if(name == NULL || value == NULL) - return -1; - len = strlen(name) + strlen(value) + 5; - buf = rb_malloc(len); - rb_snprintf(buf, len, "%s=%s", name, value); - len = putenv(buf); - rb_free(buf); - return (len); + char *buf; + int len; + if(!overwrite) { + if((buf = getenv(name)) != NULL) { + if(strlen(buf) > 0) { + return 0; + } + } + } + if(name == NULL || value == NULL) + return -1; + len = strlen(name) + strlen(value) + 5; + buf = rb_malloc(len); + rb_snprintf(buf, len, "%s=%s", name, value); + len = putenv(buf); + rb_free(buf); + return (len); } int rb_kill(int pid, int sig) { - HANDLE hProcess; - int ret = -1; - hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); - - if(hProcess) - { - switch (sig) - { - case 0: - ret = 0; - break; + HANDLE hProcess; + int ret = -1; + hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); - default: - if(TerminateProcess(hProcess, sig)) - ret = 0; - break; - } - CloseHandle(hProcess); - } - else - errno = EINVAL; + if(hProcess) { + switch (sig) { + case 0: + ret = 0; + break; - return ret; + default: + if(TerminateProcess(hProcess, sig)) + ret = 0; + break; + } + CloseHandle(hProcess); + } else + errno = EINVAL; + + return ret; } @@ -187,33 +174,31 @@ rb_kill(int pid, int sig) WSAPROTOCOL_INFO * count size_t datasize data - + */ static int make_wsaprotocol_info(pid_t process, rb_fde_t *F, WSAPROTOCOL_INFO * inf) { - WSAPROTOCOL_INFO info; - if(!WSADuplicateSocket((SOCKET) rb_get_fd(F), process, &info)) - { - memcpy(inf, &info, sizeof(WSAPROTOCOL_INFO)); - return 1; - } - return 0; + WSAPROTOCOL_INFO info; + if(!WSADuplicateSocket((SOCKET) rb_get_fd(F), process, &info)) { + memcpy(inf, &info, sizeof(WSAPROTOCOL_INFO)); + return 1; + } + return 0; } static rb_fde_t * make_fde_from_wsaprotocol_info(void *data) { - WSAPROTOCOL_INFO *info = data; - SOCKET t; - t = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, info, 0, 0); - if(t == INVALID_SOCKET) - { - rb_get_errno(); - return NULL; - } - return rb_open(t, RB_FD_SOCKET, "remote_socket"); + WSAPROTOCOL_INFO *info = data; + SOCKET t; + t = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, info, 0, 0); + if(t == INVALID_SOCKET) { + rb_get_errno(); + return NULL; + } + return rb_open(t, RB_FD_SOCKET, "remote_socket"); } static uint8_t fd_buf[16384]; @@ -222,39 +207,36 @@ static uint8_t fd_buf[16384]; int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid) { - size_t bufsize = - sizeof(uint32_t) + sizeof(uint8_t) + (sizeof(WSAPROTOCOL_INFO) * (size_t)count) + - sizeof(size_t) + datasize; - int i; - uint32_t magic = MAGIC_CONTROL; - void *ptr; - if(count > 4) - { - errno = EINVAL; - return -1; - } - if(bufsize > sizeof(fd_buf)) - { - errno = EINVAL; - return -1; - } - memset(fd_buf, 0, sizeof(fd_buf)); + size_t bufsize = + sizeof(uint32_t) + sizeof(uint8_t) + (sizeof(WSAPROTOCOL_INFO) * (size_t)count) + + sizeof(size_t) + datasize; + int i; + uint32_t magic = MAGIC_CONTROL; + void *ptr; + if(count > 4) { + errno = EINVAL; + return -1; + } + if(bufsize > sizeof(fd_buf)) { + errno = EINVAL; + return -1; + } + memset(fd_buf, 0, sizeof(fd_buf)); - ptr = fd_buf; - memcpy(ptr, &magic, sizeof(magic)); - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(magic)); - *((uint8_t *)ptr) = count; - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); + ptr = fd_buf; + memcpy(ptr, &magic, sizeof(magic)); + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(magic)); + *((uint8_t *)ptr) = count; + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); - for(i = 0; i < count; i++) - { - make_wsaprotocol_info(pid, F[i], (WSAPROTOCOL_INFO *) ptr); - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO)); - } - memcpy(ptr, &datasize, sizeof(size_t)); - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t)); - memcpy(ptr, data, datasize); - return rb_write(xF, fd_buf, bufsize); + for(i = 0; i < count; i++) { + make_wsaprotocol_info(pid, F[i], (WSAPROTOCOL_INFO *) ptr); + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO)); + } + memcpy(ptr, &datasize, sizeof(size_t)); + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t)); + memcpy(ptr, data, datasize); + return rb_write(xF, fd_buf, bufsize); } #ifdef MYMIN @@ -265,204 +247,185 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds) { - size_t minsize = sizeof(uint32_t) + sizeof(uint8_t) + sizeof(size_t); - size_t datalen; - ssize_t retlen; - uint32_t magic; - uint8_t count; - unsigned int i; - void *ptr; - ssize_t ret; - memset(fd_buf, 0, sizeof(fd_buf)); /* some paranoia here... */ - ret = rb_read(F, fd_buf, sizeof(fd_buf)); - if(ret <= 0) - { - return ret; - } - if(ret < (ssize_t) minsize) - { - errno = EINVAL; - return -1; - } - ptr = fd_buf; - memcpy(&magic, ptr, sizeof(uint32_t)); - if(magic != MAGIC_CONTROL) - { - errno = EAGAIN; - return -1; - } - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint32_t)); - memcpy(&count, ptr, sizeof(uint8_t)); - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); - for(i = 0; i < count && i < (unsigned int)nfds; i++) - { - rb_fde_t *tF = make_fde_from_wsaprotocol_info(ptr); - if(tF == NULL) - return -1; - xF[i] = tF; - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO)); - } - memcpy(&datalen, ptr, sizeof(size_t)); - ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t)); - retlen = MYMIN(datalen, datasize); - memcpy(data, ptr, datalen); - return retlen; + size_t minsize = sizeof(uint32_t) + sizeof(uint8_t) + sizeof(size_t); + size_t datalen; + ssize_t retlen; + uint32_t magic; + uint8_t count; + unsigned int i; + void *ptr; + ssize_t ret; + memset(fd_buf, 0, sizeof(fd_buf)); /* some paranoia here... */ + ret = rb_read(F, fd_buf, sizeof(fd_buf)); + if(ret <= 0) { + return ret; + } + if(ret < (ssize_t) minsize) { + errno = EINVAL; + return -1; + } + ptr = fd_buf; + memcpy(&magic, ptr, sizeof(uint32_t)); + if(magic != MAGIC_CONTROL) { + errno = EAGAIN; + return -1; + } + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint32_t)); + memcpy(&count, ptr, sizeof(uint8_t)); + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); + for(i = 0; i < count && i < (unsigned int)nfds; i++) { + rb_fde_t *tF = make_fde_from_wsaprotocol_info(ptr); + if(tF == NULL) + return -1; + xF[i] = tF; + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO)); + } + memcpy(&datalen, ptr, sizeof(size_t)); + ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t)); + retlen = MYMIN(datalen, datasize); + memcpy(data, ptr, datalen); + return retlen; } static LRESULT CALLBACK rb_process_events(HWND nhwnd, UINT umsg, WPARAM wparam, LPARAM lparam) { - rb_fde_t *F; - PF *hdl; - void *data; - switch (umsg) - { - case WM_SOCKET: - { - F = rb_find_fd(wparam); + rb_fde_t *F; + PF *hdl; + void *data; + switch (umsg) { + case WM_SOCKET: { + F = rb_find_fd(wparam); - if(F != NULL && IsFDOpen(F)) - { - switch (WSAGETSELECTEVENT(lparam)) - { - case FD_ACCEPT: - case FD_CLOSE: - case FD_READ: - { - if((hdl = F->read_handler) != NULL) - { - F->read_handler = NULL; - data = F->read_data; - F->read_data = NULL; - hdl(F, data); - } - break; - } + if(F != NULL && IsFDOpen(F)) { + switch (WSAGETSELECTEVENT(lparam)) { + case FD_ACCEPT: + case FD_CLOSE: + case FD_READ: { + if((hdl = F->read_handler) != NULL) { + F->read_handler = NULL; + data = F->read_data; + F->read_data = NULL; + hdl(F, data); + } + break; + } - case FD_CONNECT: - case FD_WRITE: - { - if((hdl = F->write_handler) != NULL) - { - F->write_handler = NULL; - data = F->write_data; - F->write_data = NULL; - hdl(F, data); - } - } - } + case FD_CONNECT: + case FD_WRITE: { + if((hdl = F->write_handler) != NULL) { + F->write_handler = NULL; + data = F->write_data; + F->write_data = NULL; + hdl(F, data); + } + } + } - } - return 0; - } - case WM_DESTROY: - { - PostQuitMessage(0); - return 0; - } + } + return 0; + } + case WM_DESTROY: { + PostQuitMessage(0); + return 0; + } - default: - return DefWindowProc(nhwnd, umsg, wparam, lparam); - } - return 0; + default: + return DefWindowProc(nhwnd, umsg, wparam, lparam); + } + return 0; } int rb_init_netio_win32(void) { - /* this muchly sucks, but i'm too lazy to do overlapped i/o, maybe someday... -androsyn */ - WNDCLASS wc; - static const char *classname = "ircd-ratbox-class"; + /* this muchly sucks, but i'm too lazy to do overlapped i/o, maybe someday... -androsyn */ + WNDCLASS wc; + static const char *classname = "ircd-ratbox-class"; - wc.style = 0; - wc.lpfnWndProc = (WNDPROC) rb_process_events; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = classname; - wc.hInstance = GetModuleHandle(NULL); + wc.style = 0; + wc.lpfnWndProc = (WNDPROC) rb_process_events; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = classname; + wc.hInstance = GetModuleHandle(NULL); - if(!RegisterClass(&wc)) - rb_lib_die("cannot register window class"); + if(!RegisterClass(&wc)) + rb_lib_die("cannot register window class"); - hwnd = CreateWindow(classname, classname, WS_POPUP, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - (HWND) NULL, (HMENU) NULL, wc.hInstance, NULL); - if(!hwnd) - rb_lib_die("could not create window"); - return 0; + hwnd = CreateWindow(classname, classname, WS_POPUP, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + (HWND) NULL, (HMENU) NULL, wc.hInstance, NULL); + if(!hwnd) + rb_lib_die("could not create window"); + return 0; } void rb_sleep(unsigned int seconds, unsigned int useconds) { - DWORD msec = seconds * 1000;; - Sleep(msec); + DWORD msec = seconds * 1000;; + Sleep(msec); } int rb_setup_fd_win32(rb_fde_t *F) { - if(F == NULL) - return 0; + if(F == NULL) + return 0; - SetHandleInformation((HANDLE) F->fd, HANDLE_FLAG_INHERIT, 0); - switch (F->type) - { - case RB_FD_SOCKET: - { - u_long nonb = 1; - if(ioctlsocket((SOCKET) F->fd, FIONBIO, &nonb) == -1) - { - rb_get_errno(); - return 0; - } - return 1; - } - default: - return 1; + SetHandleInformation((HANDLE) F->fd, HANDLE_FLAG_INHERIT, 0); + switch (F->type) { + case RB_FD_SOCKET: { + u_long nonb = 1; + if(ioctlsocket((SOCKET) F->fd, FIONBIO, &nonb) == -1) { + rb_get_errno(); + return 0; + } + return 1; + } + default: + return 1; - } + } } void rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - int old_flags = F->pflags; + int old_flags = F->pflags; - lrb_assert(IsFDOpen(F)); + lrb_assert(IsFDOpen(F)); - /* Update the list, even though we're not using it .. */ - if(type & RB_SELECT_READ) - { - if(handler != NULL) - F->pflags |= FD_CLOSE | FD_READ | FD_ACCEPT; - else - F->pflags &= ~(FD_CLOSE | FD_READ | FD_ACCEPT); - F->read_handler = handler; - F->read_data = client_data; - } + /* Update the list, even though we're not using it .. */ + if(type & RB_SELECT_READ) { + if(handler != NULL) + F->pflags |= FD_CLOSE | FD_READ | FD_ACCEPT; + else + F->pflags &= ~(FD_CLOSE | FD_READ | FD_ACCEPT); + F->read_handler = handler; + F->read_data = client_data; + } - if(type & RB_SELECT_WRITE) - { - if(handler != NULL) - F->pflags |= FD_WRITE | FD_CONNECT; - else - F->pflags &= ~(FD_WRITE | FD_CONNECT); - F->write_handler = handler; - F->write_data = client_data; - } + if(type & RB_SELECT_WRITE) { + if(handler != NULL) + F->pflags |= FD_WRITE | FD_CONNECT; + else + F->pflags &= ~(FD_WRITE | FD_CONNECT); + F->write_handler = handler; + F->write_data = client_data; + } - if(old_flags == 0 && F->pflags == 0) - return; + if(old_flags == 0 && F->pflags == 0) + return; - if(F->pflags != old_flags) - { - WSAAsyncSelect(F->fd, hwnd, WM_SOCKET, F->pflags); - } + if(F->pflags != old_flags) { + WSAAsyncSelect(F->fd, hwnd, WM_SOCKET, F->pflags); + } } @@ -472,24 +435,22 @@ static int has_set_timer = 0; int rb_select_win32(long delay) { - MSG msg; - if(has_set_timer == 0) - { - /* XXX should probably have this handle all the events - * instead of busy looping - */ - SetTimer(hwnd, 0, delay, NULL); - has_set_timer = 1; - } + MSG msg; + if(has_set_timer == 0) { + /* XXX should probably have this handle all the events + * instead of busy looping + */ + SetTimer(hwnd, 0, delay, NULL); + has_set_timer = 1; + } - if(GetMessage(&msg, NULL, 0, 0) == FALSE) - { - rb_lib_die("GetMessage failed..byebye"); - } - rb_set_time(); + if(GetMessage(&msg, NULL, 0, 0) == FALSE) { + rb_lib_die("GetMessage failed..byebye"); + } + rb_set_time(); - DispatchMessage(&msg); - return RB_OK; + DispatchMessage(&msg); + return RB_OK; } #ifdef strerror @@ -499,146 +460,145 @@ rb_select_win32(long delay) static const char * _rb_strerror(int error) { - switch (error) - { - case 0: - return "Success"; - case WSAEINTR: - return "Interrupted system call"; - case WSAEBADF: - return "Bad file number"; - case WSAEACCES: - return "Permission denied"; - case WSAEFAULT: - return "Bad address"; - case WSAEINVAL: - return "Invalid argument"; - case WSAEMFILE: - return "Too many open sockets"; - case WSAEWOULDBLOCK: - return "Operation would block"; - case WSAEINPROGRESS: - return "Operation now in progress"; - case WSAEALREADY: - return "Operation already in progress"; - case WSAENOTSOCK: - return "Socket operation on non-socket"; - case WSAEDESTADDRREQ: - return "Destination address required"; - case WSAEMSGSIZE: - return "Message too long"; - case WSAEPROTOTYPE: - return "Protocol wrong type for socket"; - case WSAENOPROTOOPT: - return "Bad protocol option"; - case WSAEPROTONOSUPPORT: - return "Protocol not supported"; - case WSAESOCKTNOSUPPORT: - return "Socket type not supported"; - case WSAEOPNOTSUPP: - return "Operation not supported on socket"; - case WSAEPFNOSUPPORT: - return "Protocol family not supported"; - case WSAEAFNOSUPPORT: - return "Address family not supported"; - case WSAEADDRINUSE: - return "Address already in use"; - case WSAEADDRNOTAVAIL: - return "Can't assign requested address"; - case WSAENETDOWN: - return "Network is down"; - case WSAENETUNREACH: - return "Network is unreachable"; - case WSAENETRESET: - return "Net connection reset"; - case WSAECONNABORTED: - return "Software caused connection abort"; - case WSAECONNRESET: - return "Connection reset by peer"; - case WSAENOBUFS: - return "No buffer space available"; - case WSAEISCONN: - return "Socket is already connected"; - case WSAENOTCONN: - return "Socket is not connected"; - case WSAESHUTDOWN: - return "Can't send after socket shutdown"; - case WSAETOOMANYREFS: - return "Too many references, can't splice"; - case WSAETIMEDOUT: - return "Connection timed out"; - case WSAECONNREFUSED: - return "Connection refused"; - case WSAELOOP: - return "Too many levels of symbolic links"; - case WSAENAMETOOLONG: - return "File name too long"; - case WSAEHOSTDOWN: - return "Host is down"; - case WSAEHOSTUNREACH: - return "No route to host"; - case WSAENOTEMPTY: - return "Directory not empty"; - case WSAEPROCLIM: - return "Too many processes"; - case WSAEUSERS: - return "Too many users"; - case WSAEDQUOT: - return "Disc quota exceeded"; - case WSAESTALE: - return "Stale NFS file handle"; - case WSAEREMOTE: - return "Too many levels of remote in path"; - case WSASYSNOTREADY: - return "Network system is unavailable"; - case WSAVERNOTSUPPORTED: - return "Winsock version out of range"; - case WSANOTINITIALISED: - return "WSAStartup not yet called"; - case WSAEDISCON: - return "Graceful shutdown in progress"; - case WSAHOST_NOT_FOUND: - return "Host not found"; - case WSANO_DATA: - return "No host data of that type was found"; - default: - return strerror(error); - } + switch (error) { + case 0: + return "Success"; + case WSAEINTR: + return "Interrupted system call"; + case WSAEBADF: + return "Bad file number"; + case WSAEACCES: + return "Permission denied"; + case WSAEFAULT: + return "Bad address"; + case WSAEINVAL: + return "Invalid argument"; + case WSAEMFILE: + return "Too many open sockets"; + case WSAEWOULDBLOCK: + return "Operation would block"; + case WSAEINPROGRESS: + return "Operation now in progress"; + case WSAEALREADY: + return "Operation already in progress"; + case WSAENOTSOCK: + return "Socket operation on non-socket"; + case WSAEDESTADDRREQ: + return "Destination address required"; + case WSAEMSGSIZE: + return "Message too long"; + case WSAEPROTOTYPE: + return "Protocol wrong type for socket"; + case WSAENOPROTOOPT: + return "Bad protocol option"; + case WSAEPROTONOSUPPORT: + return "Protocol not supported"; + case WSAESOCKTNOSUPPORT: + return "Socket type not supported"; + case WSAEOPNOTSUPP: + return "Operation not supported on socket"; + case WSAEPFNOSUPPORT: + return "Protocol family not supported"; + case WSAEAFNOSUPPORT: + return "Address family not supported"; + case WSAEADDRINUSE: + return "Address already in use"; + case WSAEADDRNOTAVAIL: + return "Can't assign requested address"; + case WSAENETDOWN: + return "Network is down"; + case WSAENETUNREACH: + return "Network is unreachable"; + case WSAENETRESET: + return "Net connection reset"; + case WSAECONNABORTED: + return "Software caused connection abort"; + case WSAECONNRESET: + return "Connection reset by peer"; + case WSAENOBUFS: + return "No buffer space available"; + case WSAEISCONN: + return "Socket is already connected"; + case WSAENOTCONN: + return "Socket is not connected"; + case WSAESHUTDOWN: + return "Can't send after socket shutdown"; + case WSAETOOMANYREFS: + return "Too many references, can't splice"; + case WSAETIMEDOUT: + return "Connection timed out"; + case WSAECONNREFUSED: + return "Connection refused"; + case WSAELOOP: + return "Too many levels of symbolic links"; + case WSAENAMETOOLONG: + return "File name too long"; + case WSAEHOSTDOWN: + return "Host is down"; + case WSAEHOSTUNREACH: + return "No route to host"; + case WSAENOTEMPTY: + return "Directory not empty"; + case WSAEPROCLIM: + return "Too many processes"; + case WSAEUSERS: + return "Too many users"; + case WSAEDQUOT: + return "Disc quota exceeded"; + case WSAESTALE: + return "Stale NFS file handle"; + case WSAEREMOTE: + return "Too many levels of remote in path"; + case WSASYSNOTREADY: + return "Network system is unavailable"; + case WSAVERNOTSUPPORTED: + return "Winsock version out of range"; + case WSANOTINITIALISED: + return "WSAStartup not yet called"; + case WSAEDISCON: + return "Graceful shutdown in progress"; + case WSAHOST_NOT_FOUND: + return "Host not found"; + case WSANO_DATA: + return "No host data of that type was found"; + default: + return strerror(error); + } }; char * rb_strerror(int error) { - static char buf[128]; - rb_strlcpy(buf, _rb_strerror(error), sizeof(buf)); - return buf; + static char buf[128]; + rb_strlcpy(buf, _rb_strerror(error), sizeof(buf)); + return buf; } #else /* win32 not supported */ int rb_init_netio_win32(void) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } void rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_data) { - errno = ENOSYS; - return; + errno = ENOSYS; + return; } int rb_select_win32(long delay) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } int rb_setup_fd_win32(rb_fde_t *F) { - errno = ENOSYS; - return -1; + errno = ENOSYS; + return -1; } #endif /* _WIN32 */ diff --git a/modules/core/m_ban.c b/modules/core/m_ban.c index ebc5152..678cd14 100644 --- a/modules/core/m_ban.c +++ b/modules/core/m_ban.c @@ -1,7 +1,7 @@ /* * charybdis: An advanced ircd. * m_ban.c: Propagates network bans across servers. - * + * * Copyright (C) 2010 Jilles Tjoelker * * Redistribution and use in source and binary forms, with or without @@ -49,8 +49,8 @@ static int m_ban(struct Client *client_p, struct Client *source_p, int parc, con static int ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message ban_msgtab = { - "BAN", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_ban, 0}, {ms_ban, 9}, {ms_ban, 9}, mg_ignore, {m_ban, 0}} + "BAN", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_ban, 0}, {ms_ban, 9}, {ms_ban, 9}, mg_ignore, {m_ban, 0}} }; mapi_clist_av1 ban_clist[] = { &ban_msgtab, NULL }; @@ -59,11 +59,11 @@ DECLARE_MODULE_AV1(ban, NULL, NULL, ban_clist, NULL, NULL, "$Revision: 1349 $"); static int m_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - sendto_one_notice(source_p, ":The BAN command is not user-accessible."); - sendto_one_notice(source_p, ":To ban a user from a channel, see /QUOTE HELP CMODE"); - if (IsOper(source_p)) - sendto_one_notice(source_p, ":To ban a user from a server or from the network, see /QUOTE HELP KLINE"); - return 0; + sendto_one_notice(source_p, ":The BAN command is not user-accessible."); + sendto_one_notice(source_p, ":To ban a user from a channel, see /QUOTE HELP CMODE"); + if (IsOper(source_p)) + sendto_one_notice(source_p, ":To ban a user from a server or from the network, see /QUOTE HELP KLINE"); + return 0; } /* ms_ban() @@ -80,255 +80,235 @@ m_ban(struct Client *client_p, struct Client *source_p, int parc, const char *pa static int ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - rb_dlink_node *ptr; - struct ConfItem *aconf; - unsigned int ntype; - const char *oper, *stype; - time_t created, hold, lifetime; - char *p; - int act; - int valid; + rb_dlink_node *ptr; + struct ConfItem *aconf; + unsigned int ntype; + const char *oper, *stype; + time_t created, hold, lifetime; + char *p; + int act; + int valid; - if (strlen(parv[1]) != 1) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Unknown BAN type %s from %s", - parv[1], source_p->name); - return 0; - } - switch (parv[1][0]) - { - case 'K': - ntype = CONF_KILL; - stype = "K-Line"; - break; - case 'X': - ntype = CONF_XLINE; - stype = "X-Line"; - break; - case 'R': - ntype = IsChannelName(parv[3]) ? CONF_RESV_CHANNEL : - CONF_RESV_NICK; - stype = "RESV"; - break; - default: - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Unknown BAN type %s from %s", - parv[1], source_p->name); - return 0; - } - created = atol(parv[4]); - hold = created + atoi(parv[5]); - lifetime = created + atoi(parv[6]); - if (!strcmp(parv[7], "*")) - oper = IsServer(source_p) ? source_p->name : get_oper_name(source_p); - else - oper = parv[7]; - ptr = find_prop_ban(ntype, parv[2], parv[3]); - if (ptr != NULL) - { - /* We already know about this ban mask. */ - aconf = ptr->data; - if (aconf->created > created || - (aconf->created == created && - aconf->lifetime >= lifetime)) - { - if (IsPerson(source_p)) - sendto_one_notice(source_p, - ":Your %s [%s%s%s] has been superseded", - stype, - aconf->user ? aconf->user : "", - aconf->user ? "@" : "", - aconf->host); - return 0; - } - /* act indicates if something happened (from the oper's - * point of view). This is the case if the ban was - * previously active (not deleted) or if the new ban - * is not a removal and not already expired. - */ - act = !(aconf->status & CONF_ILLEGAL) || (hold != created && - hold > rb_current_time()); - if (lifetime > aconf->lifetime) - aconf->lifetime = lifetime; - /* already expired, hmm */ - if (aconf->lifetime <= rb_current_time()) - return 0; - /* Deactivate, it will be reactivated later if appropriate. */ - deactivate_conf(aconf, ptr); - rb_free(aconf->user); - aconf->user = NULL; - rb_free(aconf->host); - aconf->host = NULL; - operhash_delete(aconf->info.oper); - aconf->info.oper = NULL; - rb_free(aconf->passwd); - aconf->passwd = NULL; - rb_free(aconf->spasswd); - aconf->spasswd = NULL; - } - else - { - /* New ban mask. */ - aconf = make_conf(); - aconf->status = CONF_ILLEGAL | ntype; - aconf->lifetime = lifetime; - rb_dlinkAddAlloc(aconf, &prop_bans); - act = hold != created && hold > rb_current_time(); - } - aconf->flags &= ~CONF_FLAGS_MYOPER; - aconf->flags |= CONF_FLAGS_TEMPORARY; - aconf->user = ntype == CONF_KILL ? rb_strdup(parv[2]) : NULL; - aconf->host = rb_strdup(parv[3]); - aconf->info.oper = operhash_add(oper); - aconf->created = created; - aconf->hold = hold; - if (ntype != CONF_KILL || (p = strchr(parv[parc - 1], '|')) == NULL) - aconf->passwd = rb_strdup(parv[parc - 1]); - else - { - aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1); - aconf->spasswd = rb_strdup(p + 1); - } - /* The ban is fully filled in and in the prop_bans list - * but still deactivated. Now determine if it should be activated - * and send the server notices. - */ - /* We only reject *@* and the like here. - * Otherwise malformed bans are fairly harmless and can be removed. - */ - switch (ntype) - { - case CONF_KILL: - valid = valid_wild_card(aconf->user, aconf->host); - break; - case CONF_RESV_CHANNEL: - valid = 1; - break; - default: - valid = valid_wild_card_simple(aconf->host); - break; - } - if (act && hold != created && !valid) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters", - (int)((hold - rb_current_time()) / 60), - stype, - IsServer(source_p) ? source_p->name : get_oper_name(source_p), - strcmp(parv[7], "*") ? " on behalf of " : "", - strcmp(parv[7], "*") ? parv[7] : "", - aconf->user ? aconf->user : "", - aconf->user ? "@" : "", - aconf->host); - if(IsPerson(source_p)) - sendto_one_notice(source_p, - ":Your %s [%s%s%s] has too few non-wildcard characters", - stype, - aconf->user ? aconf->user : "", - aconf->user ? "@" : "", - aconf->host); - /* Propagate it, but do not apply it locally. */ - } - else if (act && hold != created) - { - /* Keep the notices in sync with modules/m_kline.c etc. */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added global %d min. %s%s%s for [%s%s%s] [%s]", - IsServer(source_p) ? source_p->name : get_oper_name(source_p), - (int)((hold - rb_current_time()) / 60), - stype, - strcmp(parv[7], "*") ? " from " : "", - strcmp(parv[7], "*") ? parv[7] : "", - aconf->user ? aconf->user : "", - aconf->user ? "@" : "", - aconf->host, - parv[parc - 1]); - ilog(L_KLINE, "%s %s %d %s%s%s %s", parv[1], - IsServer(source_p) ? source_p->name : get_oper_name(source_p), - (int)((hold - rb_current_time()) / 60), - aconf->user ? aconf->user : "", - aconf->user ? " " : "", - aconf->host, - parv[parc - 1]); - aconf->status &= ~CONF_ILLEGAL; - } - else if (act) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the global %s for: [%s%s%s]%s%s", - IsServer(source_p) ? source_p->name : get_oper_name(source_p), - stype, - aconf->user ? aconf->user : "", - aconf->user ? "@" : "", - aconf->host, - strcmp(parv[7], "*") ? " on behalf of " : "", - strcmp(parv[7], "*") ? parv[7] : ""); - ilog(L_KLINE, "U%s %s %s%s %s", parv[1], - IsServer(source_p) ? source_p->name : get_oper_name(source_p), - aconf->user ? aconf->user : "", - aconf->user ? " " : "", - aconf->host); - } - /* If CONF_ILLEGAL is still set at this point, remove entries from the - * reject cache (for klines and xlines). - * If CONF_ILLEGAL is not set, add the ban to the type-specific data - * structure and take action on matched clients/channels. - */ - switch (ntype) - { - case CONF_KILL: - if (aconf->status & CONF_ILLEGAL) - remove_reject_mask(aconf->user, aconf->host); - else - { - add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); - if(ConfigFileEntry.kline_delay || - (IsServer(source_p) && - !HasSentEob(source_p))) - { - if(kline_queued == 0) - { - rb_event_addonce("check_klines", check_klines_event, NULL, - ConfigFileEntry.kline_delay); - kline_queued = 1; - } - } - else - check_klines(); - } - break; - case CONF_XLINE: - if (aconf->status & CONF_ILLEGAL) - remove_reject_mask(aconf->host, NULL); - else - { - rb_dlinkAddAlloc(aconf, &xline_conf_list); - check_xlines(); - } - break; - case CONF_RESV_CHANNEL: - if (!(aconf->status & CONF_ILLEGAL)) - { - add_to_resv_hash(aconf->host, aconf); - resv_chan_forcepart(aconf->host, aconf->passwd, hold - rb_current_time()); - } - break; - case CONF_RESV_NICK: - if (!(aconf->status & CONF_ILLEGAL)) - rb_dlinkAddAlloc(aconf, &resv_conf_list); - break; - } - sendto_server(client_p, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN %s %s %s %s %s %s %s :%s", - source_p->id, - parv[1], - parv[2], - parv[3], - parv[4], - parv[5], - parv[6], - parv[7], - parv[parc - 1]); - return 0; + if (strlen(parv[1]) != 1) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Unknown BAN type %s from %s", + parv[1], source_p->name); + return 0; + } + switch (parv[1][0]) { + case 'K': + ntype = CONF_KILL; + stype = "K-Line"; + break; + case 'X': + ntype = CONF_XLINE; + stype = "X-Line"; + break; + case 'R': + ntype = IsChannelName(parv[3]) ? CONF_RESV_CHANNEL : + CONF_RESV_NICK; + stype = "RESV"; + break; + default: + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Unknown BAN type %s from %s", + parv[1], source_p->name); + return 0; + } + created = atol(parv[4]); + hold = created + atoi(parv[5]); + lifetime = created + atoi(parv[6]); + if (!strcmp(parv[7], "*")) + oper = IsServer(source_p) ? source_p->name : get_oper_name(source_p); + else + oper = parv[7]; + ptr = find_prop_ban(ntype, parv[2], parv[3]); + if (ptr != NULL) { + /* We already know about this ban mask. */ + aconf = ptr->data; + if (aconf->created > created || + (aconf->created == created && + aconf->lifetime >= lifetime)) { + if (IsPerson(source_p)) + sendto_one_notice(source_p, + ":Your %s [%s%s%s] has been superseded", + stype, + aconf->user ? aconf->user : "", + aconf->user ? "@" : "", + aconf->host); + return 0; + } + /* act indicates if something happened (from the oper's + * point of view). This is the case if the ban was + * previously active (not deleted) or if the new ban + * is not a removal and not already expired. + */ + act = !(aconf->status & CONF_ILLEGAL) || (hold != created && + hold > rb_current_time()); + if (lifetime > aconf->lifetime) + aconf->lifetime = lifetime; + /* already expired, hmm */ + if (aconf->lifetime <= rb_current_time()) + return 0; + /* Deactivate, it will be reactivated later if appropriate. */ + deactivate_conf(aconf, ptr); + rb_free(aconf->user); + aconf->user = NULL; + rb_free(aconf->host); + aconf->host = NULL; + operhash_delete(aconf->info.oper); + aconf->info.oper = NULL; + rb_free(aconf->passwd); + aconf->passwd = NULL; + rb_free(aconf->spasswd); + aconf->spasswd = NULL; + } else { + /* New ban mask. */ + aconf = make_conf(); + aconf->status = CONF_ILLEGAL | ntype; + aconf->lifetime = lifetime; + rb_dlinkAddAlloc(aconf, &prop_bans); + act = hold != created && hold > rb_current_time(); + } + aconf->flags &= ~CONF_FLAGS_MYOPER; + aconf->flags |= CONF_FLAGS_TEMPORARY; + aconf->user = ntype == CONF_KILL ? rb_strdup(parv[2]) : NULL; + aconf->host = rb_strdup(parv[3]); + aconf->info.oper = operhash_add(oper); + aconf->created = created; + aconf->hold = hold; + if (ntype != CONF_KILL || (p = strchr(parv[parc - 1], '|')) == NULL) + aconf->passwd = rb_strdup(parv[parc - 1]); + else { + aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1); + aconf->spasswd = rb_strdup(p + 1); + } + /* The ban is fully filled in and in the prop_bans list + * but still deactivated. Now determine if it should be activated + * and send the server notices. + */ + /* We only reject *@* and the like here. + * Otherwise malformed bans are fairly harmless and can be removed. + */ + switch (ntype) { + case CONF_KILL: + valid = valid_wild_card(aconf->user, aconf->host); + break; + case CONF_RESV_CHANNEL: + valid = 1; + break; + default: + valid = valid_wild_card_simple(aconf->host); + break; + } + if (act && hold != created && !valid) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters", + (int)((hold - rb_current_time()) / 60), + stype, + IsServer(source_p) ? source_p->name : get_oper_name(source_p), + strcmp(parv[7], "*") ? " on behalf of " : "", + strcmp(parv[7], "*") ? parv[7] : "", + aconf->user ? aconf->user : "", + aconf->user ? "@" : "", + aconf->host); + if(IsPerson(source_p)) + sendto_one_notice(source_p, + ":Your %s [%s%s%s] has too few non-wildcard characters", + stype, + aconf->user ? aconf->user : "", + aconf->user ? "@" : "", + aconf->host); + /* Propagate it, but do not apply it locally. */ + } else if (act && hold != created) { + /* Keep the notices in sync with modules/m_kline.c etc. */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added global %d min. %s%s%s for [%s%s%s] [%s]", + IsServer(source_p) ? source_p->name : get_oper_name(source_p), + (int)((hold - rb_current_time()) / 60), + stype, + strcmp(parv[7], "*") ? " from " : "", + strcmp(parv[7], "*") ? parv[7] : "", + aconf->user ? aconf->user : "", + aconf->user ? "@" : "", + aconf->host, + parv[parc - 1]); + ilog(L_KLINE, "%s %s %d %s%s%s %s", parv[1], + IsServer(source_p) ? source_p->name : get_oper_name(source_p), + (int)((hold - rb_current_time()) / 60), + aconf->user ? aconf->user : "", + aconf->user ? " " : "", + aconf->host, + parv[parc - 1]); + aconf->status &= ~CONF_ILLEGAL; + } else if (act) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the global %s for: [%s%s%s]%s%s", + IsServer(source_p) ? source_p->name : get_oper_name(source_p), + stype, + aconf->user ? aconf->user : "", + aconf->user ? "@" : "", + aconf->host, + strcmp(parv[7], "*") ? " on behalf of " : "", + strcmp(parv[7], "*") ? parv[7] : ""); + ilog(L_KLINE, "U%s %s %s%s %s", parv[1], + IsServer(source_p) ? source_p->name : get_oper_name(source_p), + aconf->user ? aconf->user : "", + aconf->user ? " " : "", + aconf->host); + } + /* If CONF_ILLEGAL is still set at this point, remove entries from the + * reject cache (for klines and xlines). + * If CONF_ILLEGAL is not set, add the ban to the type-specific data + * structure and take action on matched clients/channels. + */ + switch (ntype) { + case CONF_KILL: + if (aconf->status & CONF_ILLEGAL) + remove_reject_mask(aconf->user, aconf->host); + else { + add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); + if(ConfigFileEntry.kline_delay || + (IsServer(source_p) && + !HasSentEob(source_p))) { + if(kline_queued == 0) { + rb_event_addonce("check_klines", check_klines_event, NULL, + ConfigFileEntry.kline_delay); + kline_queued = 1; + } + } else + check_klines(); + } + break; + case CONF_XLINE: + if (aconf->status & CONF_ILLEGAL) + remove_reject_mask(aconf->host, NULL); + else { + rb_dlinkAddAlloc(aconf, &xline_conf_list); + check_xlines(); + } + break; + case CONF_RESV_CHANNEL: + if (!(aconf->status & CONF_ILLEGAL)) { + add_to_resv_hash(aconf->host, aconf); + resv_chan_forcepart(aconf->host, aconf->passwd, hold - rb_current_time()); + } + break; + case CONF_RESV_NICK: + if (!(aconf->status & CONF_ILLEGAL)) + rb_dlinkAddAlloc(aconf, &resv_conf_list); + break; + } + sendto_server(client_p, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN %s %s %s %s %s %s %s :%s", + source_p->id, + parv[1], + parv[2], + parv[3], + parv[4], + parv[5], + parv[6], + parv[7], + parv[parc - 1]); + return 0; } diff --git a/modules/core/m_die.c b/modules/core/m_die.c index 7d2a058..7c2a41f 100644 --- a/modules/core/m_die.c +++ b/modules/core/m_die.c @@ -42,8 +42,8 @@ static int me_die(struct Client *, struct Client *, int, const char **); static int do_die(struct Client *, const char *); static struct Message die_msgtab = { - "DIE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_die, 1}, {mo_die, 0}} + "DIE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_die, 1}, {mo_die, 0}} }; mapi_clist_av1 die_clist[] = { &die_msgtab, NULL }; @@ -56,61 +56,54 @@ DECLARE_MODULE_AV1(die, NULL, NULL, die_clist, NULL, NULL, "$Revision: 3295 $"); static int mo_die(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[]) { - if(!IsOperDie(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "die"); - return 0; - } + if(!IsOperDie(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "die"); + return 0; + } - if(parc < 2 || EmptyString(parv[1])) - { - sendto_one_notice(source_p, ":Need server name /die %s", me.name); - return 0; - } + if(parc < 2 || EmptyString(parv[1])) { + sendto_one_notice(source_p, ":Need server name /die %s", me.name); + return 0; + } - if(parc > 2) - { - /* Remote die. Pass it along. */ - struct Client *server_p = find_server(NULL, parv[2]); - if (!server_p) - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]); - return 0; - } - if (!IsMe(server_p)) - { - sendto_one(server_p, ":%s ENCAP %s DIE %s", source_p->name, parv[2], parv[1]); - return 0; - } + if(parc > 2) { + /* Remote die. Pass it along. */ + struct Client *server_p = find_server(NULL, parv[2]); + if (!server_p) { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]); + return 0; } + if (!IsMe(server_p)) { + sendto_one(server_p, ":%s ENCAP %s DIE %s", source_p->name, parv[2], parv[1]); + return 0; + } + } - return do_die(source_p, parv[1]); + return do_die(source_p, parv[1]); } static int me_die(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[]) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_DIE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block to " - "remotely shut down this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_DIE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block to " + "remotely shut down this server."); + return 0; + } - return do_die(source_p, parv[1]); + return do_die(source_p, parv[1]); } static int do_die(struct Client *source_p, const char *servername) { - /* this makes sure both servernames match otherwise weirdness will occur */ - if(irccmp(servername, me.name)) - { - sendto_one_notice(source_p, ":Mismatch on /die %s", me.name); - return 0; - } + /* this makes sure both servernames match otherwise weirdness will occur */ + if(irccmp(servername, me.name)) { + sendto_one_notice(source_p, ":Mismatch on /die %s", me.name); + return 0; + } - ircd_shutdown(get_client_name(source_p, HIDE_IP)); + ircd_shutdown(get_client_name(source_p, HIDE_IP)); - return 0; + return 0; } diff --git a/modules/core/m_error.c b/modules/core/m_error.c index 07426b5..052f4ea 100644 --- a/modules/core/m_error.c +++ b/modules/core/m_error.c @@ -38,12 +38,12 @@ static int m_error(struct Client *, struct Client *, int, const char **); static int ms_error(struct Client *, struct Client *, int, const char **); struct Message error_msgtab = { - "ERROR", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{m_error, 0}, mg_ignore, mg_ignore, {ms_error, 0}, mg_ignore, mg_ignore} + "ERROR", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{m_error, 0}, mg_ignore, mg_ignore, {ms_error, 0}, mg_ignore, mg_ignore} }; mapi_clist_av1 error_clist[] = { - &error_msgtab, NULL + &error_msgtab, NULL }; DECLARE_MODULE_AV1(error, NULL, NULL, error_clist, NULL, NULL, "$Revision: 494 $"); @@ -52,31 +52,31 @@ DECLARE_MODULE_AV1(error, NULL, NULL, error_clist, NULL, NULL, "$Revision: 494 $ static int is_safe_error(const char *message) { - char prefix2[100]; - const char *p; + char prefix2[100]; + const char *p; - if (!strncmp(message, "Closing Link: 127.0.0.1 (", 25)) - return 1; - rb_snprintf(prefix2, sizeof prefix2, - "Closing Link: 127.0.0.1 %s (", me.name); - if (!strncmp(message, prefix2, strlen(prefix2))) - return 1; - if (!strncmp(message, "Restart by ", 11)) - return 1; - if (!strncmp(message, "Terminated by ", 14)) - return 1; + if (!strncmp(message, "Closing Link: 127.0.0.1 (", 25)) + return 1; + rb_snprintf(prefix2, sizeof prefix2, + "Closing Link: 127.0.0.1 %s (", me.name); + if (!strncmp(message, prefix2, strlen(prefix2))) + return 1; + if (!strncmp(message, "Restart by ", 11)) + return 1; + if (!strncmp(message, "Terminated by ", 14)) + return 1; - if (!ircncmp(message, "Closing Link", 12)) - return 0; - if (strchr(message, '[')) - return 0; - p = strchr(message, '.'); - if (p != NULL && p[1] != '\0') - return 0; - if (strchr(message, ':')) - return 0; + if (!ircncmp(message, "Closing Link", 12)) + return 0; + if (strchr(message, '[')) + return 0; + p = strchr(message, '.'); + if (p != NULL && p[1] != '\0') + return 0; + if (strchr(message, ':')) + return 0; - return 1; + return 1; } /* @@ -89,62 +89,57 @@ is_safe_error(const char *message) int m_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *para; - int hideit = ConfigFileEntry.hide_error_messages; + const char *para; + int hideit = ConfigFileEntry.hide_error_messages; - para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; + para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; - if (IsAnyServer(client_p)) - { - ilog(L_SERVER, "Received ERROR message from %s: %s", - log_client_name(source_p, SHOW_IP), para); - } + if (IsAnyServer(client_p)) { + ilog(L_SERVER, "Received ERROR message from %s: %s", + log_client_name(source_p, SHOW_IP), para); + } - if(is_safe_error(para)) - hideit = 0; - if(IsAnyServer(client_p)) - { - if (hideit < 2) - sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), - "ERROR :from %s -- %s", - client_p->name, para); - if (hideit > 0) - sendto_realops_snomask(SNO_GENERAL, (hideit == 1 ? L_OPER : L_ALL) | (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), - "ERROR :from %s -- ", - client_p->name); - } + if(is_safe_error(para)) + hideit = 0; + if(IsAnyServer(client_p)) { + if (hideit < 2) + sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), + "ERROR :from %s -- %s", + client_p->name, para); + if (hideit > 0) + sendto_realops_snomask(SNO_GENERAL, (hideit == 1 ? L_OPER : L_ALL) | (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), + "ERROR :from %s -- ", + client_p->name); + } - exit_client(client_p, source_p, source_p, "ERROR"); + exit_client(client_p, source_p, source_p, "ERROR"); - return 0; + return 0; } static int ms_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *para; - int hideit = ConfigFileEntry.hide_error_messages; + const char *para; + int hideit = ConfigFileEntry.hide_error_messages; - para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; + para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; - ilog(L_SERVER, "Received ERROR message from %s: %s", - log_client_name(source_p, SHOW_IP), para); + ilog(L_SERVER, "Received ERROR message from %s: %s", + log_client_name(source_p, SHOW_IP), para); - if(is_safe_error(para)) - hideit = 0; - if(hideit == 2) - return 0; + if(is_safe_error(para)) + hideit = 0; + if(hideit == 2) + return 0; - if(client_p == source_p) - { - sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s", - client_p->name, para); - } - else - { - sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s", - source_p->name, client_p->name, para); - } + if(client_p == source_p) { + sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s", + client_p->name, para); + } else { + sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s", + source_p->name, client_p->name, para); + } - return 0; + return 0; } diff --git a/modules/core/m_join.c b/modules/core/m_join.c index 601b362..08710c5 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -47,18 +47,18 @@ static int ms_join(struct Client *, struct Client *, int, const char **); static int ms_sjoin(struct Client *, struct Client *, int, const char **); struct Message join_msgtab = { - "JOIN", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_join, 2}, {ms_join, 2}, mg_ignore, mg_ignore, {m_join, 2}} + "JOIN", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_join, 2}, {ms_join, 2}, mg_ignore, mg_ignore, {m_join, 2}} }; struct Message svsjoin_msgtab = { - "SVSJOIN", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_svsjoin, 3}, mg_ignore} + "SVSJOIN", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_svsjoin, 3}, mg_ignore} }; struct Message sjoin_msgtab = { - "SJOIN", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_ignore, mg_ignore, {ms_sjoin, 4}, mg_ignore, mg_ignore} + "SJOIN", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_ignore, mg_ignore, {ms_sjoin, 4}, mg_ignore, mg_ignore} }; mapi_clist_av1 join_clist[] = { &join_msgtab, &svsjoin_msgtab, &sjoin_msgtab, NULL }; @@ -69,7 +69,7 @@ static void set_final_mode(struct Mode *mode, struct Mode *oldmode); static void remove_our_modes(struct Channel *chptr, struct Client *source_p); static void remove_ban_list(struct Channel *chptr, struct Client *source_p, - rb_dlink_list * list, char c, int mems); + rb_dlink_list * list, char c, int mems); static char modebuf[MODEBUFLEN]; static char omodebuf[MODEBUFLEN]; @@ -86,9 +86,9 @@ static int pargs; static int m_join(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - user_join(client_p, source_p, parv[1], parc > 2 ? parv[2] : NULL); /* channel.c */ + user_join(client_p, source_p, parv[1], parc > 2 ? parv[2] : NULL); /* channel.c */ - return 0; + return 0; } /* @@ -103,19 +103,19 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p static int me_svsjoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if(!(source_p->flags & FLAGS_SERVICE)) - return 0; + if(!(source_p->flags & FLAGS_SERVICE)) + return 0; - if((target_p = find_person(parv[1])) == NULL) - return 0; + if((target_p = find_person(parv[1])) == NULL) + return 0; - if(!MyClient(target_p)) - return 0; + if(!MyClient(target_p)) + return 0; - user_join(&me, target_p, parv[2], NULL); - return 0; + user_join(&me, target_p, parv[2], NULL); + return 0; } /* @@ -128,1401 +128,1248 @@ me_svsjoin(struct Client *client_p, struct Client *source_p, int parc, const cha static int ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; - static struct Mode mode; - time_t oldts; - time_t newts; - int isnew; - int keep_our_modes = YES; - int keep_new_modes = YES; - rb_dlink_node *ptr, *next_ptr; + struct Channel *chptr; + static struct Mode mode; + time_t oldts; + time_t newts; + int isnew; + int keep_our_modes = YES; + int keep_new_modes = YES; + rb_dlink_node *ptr, *next_ptr; - /* special case for join 0 */ - if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) - { - do_join_0(client_p, source_p); - return 0; - } + /* special case for join 0 */ + if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) { + do_join_0(client_p, source_p); + return 0; + } - if(parc < 4) - return 0; + if(parc < 4) + return 0; - if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) - return 0; + if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) + return 0; - /* joins for local channels cant happen. */ - if(parv[2][0] == '&') - return 0; + /* joins for local channels cant happen. */ + if(parv[2][0] == '&') + return 0; - mbuf = modebuf; - ombuf = omodebuf; - mode.key[0] = mode.forward[0] = '\0'; - mode.mode = mode.limit = mode.join_num = mode.join_time = 0; + mbuf = modebuf; + ombuf = omodebuf; + mode.key[0] = mode.forward[0] = '\0'; + mode.mode = mode.limit = mode.join_num = mode.join_time = 0; - if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) - return 0; + if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) + return 0; - newts = atol(parv[1]); - oldts = chptr->channelts; + newts = atol(parv[1]); + oldts = chptr->channelts; #ifdef IGNORE_BOGUS_TS - if(newts < 800000000) - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "*** Bogus TS %ld on %s ignored from %s", - (long) newts, chptr->chname, client_p->name); - newts = (oldts == 0) ? oldts : 800000000; - } + if(newts < 800000000) { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "*** Bogus TS %ld on %s ignored from %s", + (long) newts, chptr->chname, client_p->name); + newts = (oldts == 0) ? oldts : 800000000; + } #else - /* making a channel TS0 */ - if(!isnew && !newts && oldts) - { - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0", - me.name, chptr->chname, chptr->chname, (long) oldts); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Server %s changing TS on %s from %ld to 0", - source_p->name, chptr->chname, (long) oldts); - } + /* making a channel TS0 */ + if(!isnew && !newts && oldts) { + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0", + me.name, chptr->chname, chptr->chname, (long) oldts); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Server %s changing TS on %s from %ld to 0", + source_p->name, chptr->chname, (long) oldts); + } #endif - if(isnew) - chptr->channelts = newts; - else if(newts == 0 || oldts == 0) - chptr->channelts = 0; - else if(newts == oldts) - ; - else if(newts < oldts) - { - keep_our_modes = NO; - chptr->channelts = newts; - } - else - keep_new_modes = NO; + if(isnew) + chptr->channelts = newts; + else if(newts == 0 || oldts == 0) + chptr->channelts = 0; + else if(newts == oldts) + ; + else if(newts < oldts) { + keep_our_modes = NO; + chptr->channelts = newts; + } else + keep_new_modes = NO; - /* Lost the TS, other side wins, so remove modes on this side */ - if(!keep_our_modes) - { - set_final_mode(&mode, &chptr->mode); - chptr->mode = mode; - remove_our_modes(chptr, source_p); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) - { - del_invite(chptr, ptr->data); - } - /* If setting -j, clear join throttle state -- jilles */ - chptr->join_count = chptr->join_delta = 0; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", - me.name, chptr->chname, chptr->chname, - (long) oldts, (long) newts); - /* Update capitalization in channel name, this makes the - * capitalization timestamped like modes are -- jilles */ - strcpy(chptr->chname, parv[2]); - if(*modebuf != '\0') - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s", - source_p->servptr->name, - chptr->chname, modebuf, parabuf); - if(*omodebuf != '\0') - sendto_channel_local(ONLY_OPERS, chptr, - ":%s MODE %s %s %s", - source_p->servptr->name, - chptr->chname, modebuf, parabuf); - *omodebuf = *modebuf = *parabuf = '\0'; + /* Lost the TS, other side wins, so remove modes on this side */ + if(!keep_our_modes) { + set_final_mode(&mode, &chptr->mode); + chptr->mode = mode; + remove_our_modes(chptr, source_p); + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) { + del_invite(chptr, ptr->data); + } + /* If setting -j, clear join throttle state -- jilles */ + chptr->join_count = chptr->join_delta = 0; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", + me.name, chptr->chname, chptr->chname, + (long) oldts, (long) newts); + /* Update capitalization in channel name, this makes the + * capitalization timestamped like modes are -- jilles */ + strcpy(chptr->chname, parv[2]); + if(*modebuf != '\0') + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s", + source_p->servptr->name, + chptr->chname, modebuf, parabuf); + if(*omodebuf != '\0') + sendto_channel_local(ONLY_OPERS, chptr, + ":%s MODE %s %s %s", + source_p->servptr->name, + chptr->chname, modebuf, parabuf); + *omodebuf = *modebuf = *parabuf = '\0'; - /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ - set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); - } + /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ + set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); + } - if(!IsMember(source_p, chptr)) - { - add_user_to_channel(chptr, source_p, CHFL_PEON); - if (chptr->mode.join_num && - rb_current_time() - chptr->join_delta >= chptr->mode.join_time) - { - chptr->join_count = 0; - chptr->join_delta = rb_current_time(); - } - chptr->join_count++; - sendto_channel_local_with_capability(ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s", + if(!IsMember(source_p, chptr)) { + add_user_to_channel(chptr, source_p, CHFL_PEON); + if (chptr->mode.join_num && + rb_current_time() - chptr->join_delta >= chptr->mode.join_time) { + chptr->join_count = 0; + chptr->join_delta = rb_current_time(); + } + chptr->join_count++; + sendto_channel_local_with_capability(ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s", source_p->name, source_p->username, source_p->host, chptr->chname); - sendto_channel_local_with_capability(ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s %ld :%s", + sendto_channel_local_with_capability(ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s %ld :%s", source_p->name, source_p->username, source_p->host, chptr->chname, EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, source_p->tsinfo, source_p->info); - } + } - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s JOIN %ld %s +", - source_p->id, (long) chptr->channelts, chptr->chname); - return 0; + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s JOIN %ld %s +", + source_p->id, (long) chptr->channelts, chptr->chname); + return 0; } static int ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static char buf_uid[BUFSIZE]; - static const char empty_modes[] = "0"; - struct Channel *chptr; - struct Client *target_p, *fakesource_p; - time_t newts; - time_t oldts; - static struct Mode mode, *oldmode; - const char *modes; - int args = 0; - int keep_our_modes = 1; - int keep_new_modes = 1; - int fl; - int isnew; - int mlen_uid; - int len_nick; - int len_uid; - int len; - int joins = 0; - const char *s; - char *ptr_uid; - char *p; - int i, joinc = 0, timeslice = 0; - static char empty[] = ""; - rb_dlink_node *ptr, *next_ptr; + static char buf_uid[BUFSIZE]; + static const char empty_modes[] = "0"; + struct Channel *chptr; + struct Client *target_p, *fakesource_p; + time_t newts; + time_t oldts; + static struct Mode mode, *oldmode; + const char *modes; + int args = 0; + int keep_our_modes = 1; + int keep_new_modes = 1; + int fl; + int isnew; + int mlen_uid; + int len_nick; + int len_uid; + int len; + int joins = 0; + const char *s; + char *ptr_uid; + char *p; + int i, joinc = 0, timeslice = 0; + static char empty[] = ""; + rb_dlink_node *ptr, *next_ptr; - if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) - return 0; + if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) + return 0; - /* SJOIN's for local channels can't happen. */ - if(*parv[2] == '&') - return 0; + /* SJOIN's for local channels can't happen. */ + if(*parv[2] == '&') + return 0; - omodebuf[0] = modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0'; - pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0; + omodebuf[0] = modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0'; + pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0; - /* Hide connecting server on netburst -- jilles */ - if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) - fakesource_p = &me; - else - fakesource_p = source_p; + /* Hide connecting server on netburst -- jilles */ + if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) + fakesource_p = &me; + else + fakesource_p = source_p; - mbuf = modebuf; - ombuf = omodebuf; - newts = atol(parv[1]); + mbuf = modebuf; + ombuf = omodebuf; + newts = atol(parv[1]); - s = parv[3]; - while (*s) - { - switch (*(s++)) - { - case 'f': - rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); - args++; - if(parc < 5 + args) - return 0; - break; - case 'j': - sscanf(parv[4 + args], "%d:%d", &joinc, ×lice); - args++; - mode.join_num = joinc; - mode.join_time = timeslice; - if(parc < 5 + args) - return 0; - break; - case 'k': - rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); - args++; - if(parc < 5 + args) - return 0; - break; - case 'l': - mode.limit = atoi(parv[4 + args]); - args++; - if(parc < 5 + args) - return 0; - break; - default: - if(chmode_flags[(int) *s] != 0) - { - mode.mode |= chmode_flags[(int) *s]; - } - } - } + s = parv[3]; + while (*s) { + switch (*(s++)) { + case 'f': + rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); + args++; + if(parc < 5 + args) + return 0; + break; + case 'j': + sscanf(parv[4 + args], "%d:%d", &joinc, ×lice); + args++; + mode.join_num = joinc; + mode.join_time = timeslice; + if(parc < 5 + args) + return 0; + break; + case 'k': + rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); + args++; + if(parc < 5 + args) + return 0; + break; + case 'l': + mode.limit = atoi(parv[4 + args]); + args++; + if(parc < 5 + args) + return 0; + break; + default: + if(chmode_flags[(int) *s] != 0) { + mode.mode |= chmode_flags[(int) *s]; + } + } + } - if(parv[args + 4]) - { - s = parv[args + 4]; + if(parv[args + 4]) { + s = parv[args + 4]; - /* remove any leading spaces */ - while (*s == ' ') - s++; - } - else - s = ""; + /* remove any leading spaces */ + while (*s == ' ') + s++; + } else + s = ""; - if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) - return 0; /* channel name too long? */ + if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) + return 0; /* channel name too long? */ - oldts = chptr->channelts; - oldmode = &chptr->mode; + oldts = chptr->channelts; + oldmode = &chptr->mode; #ifdef IGNORE_BOGUS_TS - if(newts < 800000000) - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "*** Bogus TS %ld on %s ignored from %s", - (long) newts, chptr->chname, client_p->name); + if(newts < 800000000) { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "*** Bogus TS %ld on %s ignored from %s", + (long) newts, chptr->chname, client_p->name); - newts = (oldts == 0) ? oldts : 800000000; - } + newts = (oldts == 0) ? oldts : 800000000; + } #else - if(!isnew && !newts && oldts) - { - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s NOTICE %s :*** Notice -- TS for %s " - "changed from %ld to 0", - me.name, chptr->chname, chptr->chname, (long) oldts); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Server %s changing TS on %s from %ld to 0", - source_p->name, chptr->chname, (long) oldts); - } + if(!isnew && !newts && oldts) { + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s NOTICE %s :*** Notice -- TS for %s " + "changed from %ld to 0", + me.name, chptr->chname, chptr->chname, (long) oldts); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Server %s changing TS on %s from %ld to 0", + source_p->name, chptr->chname, (long) oldts); + } #endif - if(isnew) - chptr->channelts = newts; - - else if(newts == 0 || oldts == 0) - chptr->channelts = 0; - else if(newts == oldts) - ; - else if(newts < oldts) - { - /* If configured, kick people trying to join +i/+k - * channels by recreating them on split servers. - * If the source has sent EOB, assume this is some - * sort of hack by services. If cmode +i is set, - * services can send kicks if needed; if the key - * differs, services cannot kick in a race-free - * manner so do so here. - * -- jilles */ - if (ConfigChannel.kick_on_split_riding && - ((!HasSentEob(source_p) && - mode.mode & MODE_INVITEONLY) || - (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0))) - { - struct membership *msptr; - struct Client *who; - int l = rb_dlink_list_length(&chptr->members); + if(isnew) + chptr->channelts = newts; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) - { - msptr = ptr->data; - who = msptr->client_p; - sendto_one(who, ":%s KICK %s %s :Net Rider", - me.name, chptr->chname, who->name); + else if(newts == 0 || oldts == 0) + chptr->channelts = 0; + else if(newts == oldts) + ; + else if(newts < oldts) { + /* If configured, kick people trying to join +i/+k + * channels by recreating them on split servers. + * If the source has sent EOB, assume this is some + * sort of hack by services. If cmode +i is set, + * services can send kicks if needed; if the key + * differs, services cannot kick in a race-free + * manner so do so here. + * -- jilles */ + if (ConfigChannel.kick_on_split_riding && + ((!HasSentEob(source_p) && + mode.mode & MODE_INVITEONLY) || + (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0))) { + struct membership *msptr; + struct Client *who; + int l = rb_dlink_list_length(&chptr->members); - sendto_server(NULL, chptr, CAP_TS6, NOCAPS, - ":%s KICK %s %s :Net Rider", - me.id, chptr->chname, - who->id); - remove_user_from_channel(msptr); - if (--l == 0) - break; - } - if (l == 0) - { - /* Channel was emptied, create a new one */ - if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) - return 0; /* oops! */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) { + msptr = ptr->data; + who = msptr->client_p; + sendto_one(who, ":%s KICK %s %s :Net Rider", + me.name, chptr->chname, who->name); - oldmode = &chptr->mode; - } - } - keep_our_modes = NO; - chptr->channelts = newts; - } - else - keep_new_modes = NO; + sendto_server(NULL, chptr, CAP_TS6, NOCAPS, + ":%s KICK %s %s :Net Rider", + me.id, chptr->chname, + who->id); + remove_user_from_channel(msptr); + if (--l == 0) + break; + } + if (l == 0) { + /* Channel was emptied, create a new one */ + if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) + return 0; /* oops! */ - if(!keep_new_modes) - mode = *oldmode; - else if(keep_our_modes) - { - mode.mode |= oldmode->mode; - if(oldmode->limit > mode.limit) - mode.limit = oldmode->limit; - if(strcmp(mode.key, oldmode->key) < 0) - strcpy(mode.key, oldmode->key); - if(oldmode->join_num > mode.join_num || - (oldmode->join_num == mode.join_num && - oldmode->join_time > mode.join_time)) - { - mode.join_num = oldmode->join_num; - mode.join_time = oldmode->join_time; - } - if(irccmp(mode.forward, oldmode->forward) < 0) - strcpy(mode.forward, oldmode->forward); - } - else - { - /* If setting -j, clear join throttle state -- jilles */ - if (!mode.join_num) - chptr->join_count = chptr->join_delta = 0; - } + oldmode = &chptr->mode; + } + } + keep_our_modes = NO; + chptr->channelts = newts; + } else + keep_new_modes = NO; - set_final_mode(&mode, oldmode); - chptr->mode = mode; + if(!keep_new_modes) + mode = *oldmode; + else if(keep_our_modes) { + mode.mode |= oldmode->mode; + if(oldmode->limit > mode.limit) + mode.limit = oldmode->limit; + if(strcmp(mode.key, oldmode->key) < 0) + strcpy(mode.key, oldmode->key); + if(oldmode->join_num > mode.join_num || + (oldmode->join_num == mode.join_num && + oldmode->join_time > mode.join_time)) { + mode.join_num = oldmode->join_num; + mode.join_time = oldmode->join_time; + } + if(irccmp(mode.forward, oldmode->forward) < 0) + strcpy(mode.forward, oldmode->forward); + } else { + /* If setting -j, clear join throttle state -- jilles */ + if (!mode.join_num) + chptr->join_count = chptr->join_delta = 0; + } - /* Lost the TS, other side wins, so remove modes on this side */ - if(!keep_our_modes) - { - remove_our_modes(chptr, fakesource_p); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) - { - del_invite(chptr, ptr->data); - } + set_final_mode(&mode, oldmode); + chptr->mode = mode; - if(rb_dlink_list_length(&chptr->banlist) > 0) - remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS); - if(rb_dlink_list_length(&chptr->exceptlist) > 0) - remove_ban_list(chptr, fakesource_p, &chptr->exceptlist, - 'e', ONLY_CHANOPS); - if(rb_dlink_list_length(&chptr->invexlist) > 0) - remove_ban_list(chptr, fakesource_p, &chptr->invexlist, - 'I', ONLY_CHANOPS); - if(rb_dlink_list_length(&chptr->quietlist) > 0) - remove_ban_list(chptr, fakesource_p, &chptr->quietlist, - 'q', ALL_MEMBERS); - chptr->bants++; + /* Lost the TS, other side wins, so remove modes on this side */ + if(!keep_our_modes) { + remove_our_modes(chptr, fakesource_p); + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) { + del_invite(chptr, ptr->data); + } - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", - me.name, chptr->chname, chptr->chname, - (long) oldts, (long) newts); - /* Update capitalization in channel name, this makes the - * capitalization timestamped like modes are -- jilles */ - strcpy(chptr->chname, parv[2]); + if(rb_dlink_list_length(&chptr->banlist) > 0) + remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS); + if(rb_dlink_list_length(&chptr->exceptlist) > 0) + remove_ban_list(chptr, fakesource_p, &chptr->exceptlist, + 'e', ONLY_CHANOPS); + if(rb_dlink_list_length(&chptr->invexlist) > 0) + remove_ban_list(chptr, fakesource_p, &chptr->invexlist, + 'I', ONLY_CHANOPS); + if(rb_dlink_list_length(&chptr->quietlist) > 0) + remove_ban_list(chptr, fakesource_p, &chptr->quietlist, + 'q', ALL_MEMBERS); + chptr->bants++; - /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ - set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); - } + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", + me.name, chptr->chname, chptr->chname, + (long) oldts, (long) newts); + /* Update capitalization in channel name, this makes the + * capitalization timestamped like modes are -- jilles */ + strcpy(chptr->chname, parv[2]); - if(*modebuf != '\0') - sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s", - fakesource_p->name, chptr->chname, modebuf, parabuf); + /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ + set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); + } - if(*omodebuf != '\0') - sendto_channel_local(ONLY_OPERS, chptr, ":%s MODE %s %s %s", - fakesource_p->name, chptr->chname, omodebuf, parabuf); + if(*modebuf != '\0') + sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s", + fakesource_p->name, chptr->chname, modebuf, parabuf); - *omodebuf = *modebuf = *parabuf = '\0'; + if(*omodebuf != '\0') + sendto_channel_local(ONLY_OPERS, chptr, ":%s MODE %s %s %s", + fakesource_p->name, chptr->chname, omodebuf, parabuf); - if(parv[3][0] != '0' && keep_new_modes) - modes = channel_modes(chptr, source_p); - else - modes = empty_modes; + *omodebuf = *modebuf = *parabuf = '\0'; - mlen_uid = rb_sprintf(buf_uid, ":%s SJOIN %ld %s %s :", - use_id(source_p), (long) chptr->channelts, parv[2], modes); - ptr_uid = buf_uid + mlen_uid; + if(parv[3][0] != '0' && keep_new_modes) + modes = channel_modes(chptr, source_p); + else + modes = empty_modes; - mbuf = modebuf; - ombuf = omodebuf; - para[0] = para[1] = para[2] = para[3] = empty; - pargs = 0; - len_nick = len_uid = 0; + mlen_uid = rb_sprintf(buf_uid, ":%s SJOIN %ld %s %s :", + use_id(source_p), (long) chptr->channelts, parv[2], modes); + ptr_uid = buf_uid + mlen_uid; - /* if theres a space, theres going to be more than one nick, change the - * first space to \0, so s is just the first nick, and point p to the - * second nick - */ - if((p = strchr(s, ' ')) != NULL) - { - *p++ = '\0'; - } + mbuf = modebuf; + ombuf = omodebuf; + para[0] = para[1] = para[2] = para[3] = empty; + pargs = 0; + len_nick = len_uid = 0; - *mbuf++ = '+'; + /* if theres a space, theres going to be more than one nick, change the + * first space to \0, so s is just the first nick, and point p to the + * second nick + */ + if((p = strchr(s, ' ')) != NULL) { + *p++ = '\0'; + } - while (s) - { - fl = 0; + *mbuf++ = '+'; - for (i = 0; i < 4; i++) - { - if(*s == '~') - { - fl |= CHFL_OWNER; - s++; - } - else if(*s == '!') - { - fl |= CHFL_ADMIN; - s++; - } - else if(*s == '@') - { - fl |= CHFL_CHANOP; - s++; - } - else if(*s == '%') - { - fl |= CHFL_HALFOP; - s++; - } - else if(*s == '+') - { - fl |= CHFL_VOICE; - s++; - } - } + while (s) { + fl = 0; - /* if the client doesnt exist or is fake direction, skip. */ - if(!(target_p = find_client(s)) || - (target_p->from != client_p) || !IsPerson(target_p)) - goto nextnick; + for (i = 0; i < 4; i++) { + if(*s == '~') { + fl |= CHFL_OWNER; + s++; + } else if(*s == '!') { + fl |= CHFL_ADMIN; + s++; + } else if(*s == '@') { + fl |= CHFL_CHANOP; + s++; + } else if(*s == '%') { + fl |= CHFL_HALFOP; + s++; + } else if(*s == '+') { + fl |= CHFL_VOICE; + s++; + } + } - /* we assume for these we can fit at least one nick/uid in.. */ + /* if the client doesnt exist or is fake direction, skip. */ + if(!(target_p = find_client(s)) || + (target_p->from != client_p) || !IsPerson(target_p)) + goto nextnick; - /* check we can fit another status+nick+space into a buffer */ - if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) - { - *(ptr_uid - 1) = '\0'; - sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); - ptr_uid = buf_uid + mlen_uid; - len_uid = 0; - } + /* we assume for these we can fit at least one nick/uid in.. */ - if(keep_new_modes) - { - if(fl & CHFL_OWNER) - { - *ptr_uid++ = '~'; - len_nick++; - len_uid++; - } - else if(fl & CHFL_ADMIN) - { - *ptr_uid++ = '!'; - len_nick++; - len_uid++; - } - if(fl & CHFL_CHANOP) - { - *ptr_uid++ = '@'; - len_nick++; - len_uid++; - } - if(fl & CHFL_HALFOP) - { - *ptr_uid++ = '%'; - len_nick++; - len_uid++; - } - if(fl & CHFL_VOICE) - { - *ptr_uid++ = '+'; - len_nick++; - len_uid++; - } - } + /* check we can fit another status+nick+space into a buffer */ + if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) { + *(ptr_uid - 1) = '\0'; + sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); + ptr_uid = buf_uid + mlen_uid; + len_uid = 0; + } - /* copy the nick to the two buffers */ - len = rb_sprintf(ptr_uid, "%s ", use_id(target_p)); - ptr_uid += len; - len_uid += len; + if(keep_new_modes) { + if(fl & CHFL_OWNER) { + *ptr_uid++ = '~'; + len_nick++; + len_uid++; + } else if(fl & CHFL_ADMIN) { + *ptr_uid++ = '!'; + len_nick++; + len_uid++; + } + if(fl & CHFL_CHANOP) { + *ptr_uid++ = '@'; + len_nick++; + len_uid++; + } + if(fl & CHFL_HALFOP) { + *ptr_uid++ = '%'; + len_nick++; + len_uid++; + } + if(fl & CHFL_VOICE) { + *ptr_uid++ = '+'; + len_nick++; + len_uid++; + } + } - if(!keep_new_modes) - fl = 0; + /* copy the nick to the two buffers */ + len = rb_sprintf(ptr_uid, "%s ", use_id(target_p)); + ptr_uid += len; + len_uid += len; - if(!IsMember(target_p, chptr)) - { - add_user_to_channel(chptr, target_p, fl); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", - target_p->name, - target_p->username, target_p->host, parv[2]); - joins++; - } + if(!keep_new_modes) + fl = 0; - /* If anyone can think of a way to do this that doesn't make babies cry - * I would love to hear it - Taros */ + if(!IsMember(target_p, chptr)) { + add_user_to_channel(chptr, target_p, fl); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", + target_p->name, + target_p->username, target_p->host, parv[2]); + joins++; + } - if(fl & CHFL_OWNER) - { - *mbuf++ = 'y'; - para[pargs++] = target_p->name; + /* If anyone can think of a way to do this that doesn't make babies cry + * I would love to hear it - Taros */ - if(fl & CHFL_ADMIN) - { - /* its possible the +y has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + if(fl & CHFL_OWNER) { + *mbuf++ = 'y'; + para[pargs++] = target_p->name; - *mbuf++ = 'a'; - para[pargs++] = target_p->name; - } - if(fl & CHFL_CHANOP) - { - /* its possible the +y has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } - - *mbuf++ = 'o'; - para[pargs++] = target_p->name; - } - if(fl & CHFL_HALFOP) - { - /* its possible the +y has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } - - *mbuf++ = 'h'; - para[pargs++] = target_p->name; - } - if(fl & CHFL_VOICE) - { - /* its possible the +y has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } - - *mbuf++ = 'v'; - para[pargs++] = target_p->name; - } + if(fl & CHFL_ADMIN) { + /* its possible the +y has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; } - else if(fl & CHFL_ADMIN) - { - *mbuf++ = 'a'; - para[pargs++] = target_p->name; - if(fl & CHFL_CHANOP) - { - /* its possible the +a has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + *mbuf++ = 'a'; + para[pargs++] = target_p->name; + } + if(fl & CHFL_CHANOP) { + /* its possible the +y has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - *mbuf++ = 'o'; - para[pargs++] = target_p->name; - } - if(fl & CHFL_HALFOP) - { - /* its possible the +a has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + *mbuf++ = 'o'; + para[pargs++] = target_p->name; + } + if(fl & CHFL_HALFOP) { + /* its possible the +y has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - *mbuf++ = 'h'; - para[pargs++] = target_p->name; - } - if(fl & CHFL_VOICE) - { - /* its possible the +a has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + *mbuf++ = 'h'; + para[pargs++] = target_p->name; + } + if(fl & CHFL_VOICE) { + /* its possible the +y has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - *mbuf++ = 'v'; - para[pargs++] = target_p->name; - } - } - else if(fl & CHFL_CHANOP) - { - *mbuf++ = 'o'; - para[pargs++] = target_p->name; + *mbuf++ = 'v'; + para[pargs++] = target_p->name; + } + } else if(fl & CHFL_ADMIN) { + *mbuf++ = 'a'; + para[pargs++] = target_p->name; - if(fl & CHFL_HALFOP) - { - /* its possible the +o has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + if(fl & CHFL_CHANOP) { + /* its possible the +a has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - *mbuf++ = 'h'; - para[pargs++] = target_p->name; - } - if(fl & CHFL_VOICE) - { - /* its possible the +o has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + *mbuf++ = 'o'; + para[pargs++] = target_p->name; + } + if(fl & CHFL_HALFOP) { + /* its possible the +a has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - *mbuf++ = 'v'; - para[pargs++] = target_p->name; - } - } - else if(fl & CHFL_HALFOP) - { - *mbuf++ = 'h'; - para[pargs++] = target_p->name; + *mbuf++ = 'h'; + para[pargs++] = target_p->name; + } + if(fl & CHFL_VOICE) { + /* its possible the +a has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - if(fl & CHFL_VOICE) - { - /* its possible the +h has filled up MAXMODEPARAMS, if so, start - * a new buffer - */ - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, - modebuf, - para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + *mbuf++ = 'v'; + para[pargs++] = target_p->name; + } + } else if(fl & CHFL_CHANOP) { + *mbuf++ = 'o'; + para[pargs++] = target_p->name; - *mbuf++ = 'v'; - para[pargs++] = target_p->name; - } - } - else if(fl & CHFL_VOICE) - { - *mbuf++ = 'v'; - para[pargs++] = target_p->name; - } + if(fl & CHFL_HALFOP) { + /* its possible the +o has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - if(pargs >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, - chptr->chname, - modebuf, para[0], para[1], para[2], para[3]); - mbuf = modebuf; - *mbuf++ = '+'; - para[0] = para[1] = para[2] = para[3] = NULL; - pargs = 0; - } + *mbuf++ = 'h'; + para[pargs++] = target_p->name; + } + if(fl & CHFL_VOICE) { + /* its possible the +o has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - nextnick: - /* p points to the next nick */ - s = p; + *mbuf++ = 'v'; + para[pargs++] = target_p->name; + } + } else if(fl & CHFL_HALFOP) { + *mbuf++ = 'h'; + para[pargs++] = target_p->name; - /* if there was a trailing space and p was pointing to it, then we - * need to exit.. this has the side effect of breaking double spaces - * in an sjoin.. but that shouldnt happen anyway - */ - if(s && (*s == '\0')) - s = p = NULL; + if(fl & CHFL_VOICE) { + /* its possible the +h has filled up MAXMODEPARAMS, if so, start + * a new buffer + */ + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, + modebuf, + para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - /* if p was NULL due to no spaces, s wont exist due to the above, so - * we cant check it for spaces.. if there are no spaces, then when - * we next get here, s will be NULL - */ - if(s && ((p = strchr(s, ' ')) != NULL)) - { - *p++ = '\0'; - } - } + *mbuf++ = 'v'; + para[pargs++] = target_p->name; + } + } else if(fl & CHFL_VOICE) { + *mbuf++ = 'v'; + para[pargs++] = target_p->name; + } - *mbuf = '\0'; - if(pargs) - { - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - fakesource_p->name, chptr->chname, modebuf, - para[0], CheckEmpty(para[1]), - CheckEmpty(para[2]), CheckEmpty(para[3])); - } + if(pargs >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, + chptr->chname, + modebuf, para[0], para[1], para[2], para[3]); + mbuf = modebuf; + *mbuf++ = '+'; + para[0] = para[1] = para[2] = para[3] = NULL; + pargs = 0; + } - if(!joins && !(chptr->mode.mode & MODE_PERMANENT) && isnew) - { - destroy_channel(chptr); +nextnick: + /* p points to the next nick */ + s = p; - return 0; - } + /* if there was a trailing space and p was pointing to it, then we + * need to exit.. this has the side effect of breaking double spaces + * in an sjoin.. but that shouldnt happen anyway + */ + if(s && (*s == '\0')) + s = p = NULL; - /* Keep the colon if we're sending an SJOIN without nicks -- jilles */ - if (joins) - { - *(ptr_uid - 1) = '\0'; - } + /* if p was NULL due to no spaces, s wont exist due to the above, so + * we cant check it for spaces.. if there are no spaces, then when + * we next get here, s will be NULL + */ + if(s && ((p = strchr(s, ' ')) != NULL)) { + *p++ = '\0'; + } + } - sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); + *mbuf = '\0'; + if(pargs) { + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + fakesource_p->name, chptr->chname, modebuf, + para[0], CheckEmpty(para[1]), + CheckEmpty(para[2]), CheckEmpty(para[3])); + } - return 0; + if(!joins && !(chptr->mode.mode & MODE_PERMANENT) && isnew) { + destroy_channel(chptr); + + return 0; + } + + /* Keep the colon if we're sending an SJOIN without nicks -- jilles */ + if (joins) { + *(ptr_uid - 1) = '\0'; + } + + sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); + + return 0; } static void set_final_mode(struct Mode *mode, struct Mode *oldmode) { - int dir = MODE_QUERY, odir = MODE_QUERY; - char *pbuf = parabuf; - int len; - int i; + int dir = MODE_QUERY, odir = MODE_QUERY; + char *pbuf = parabuf; + int len; + int i; - /* ok, first get a list of modes we need to add */ - for (i = 0; i < 256; i++) - { - if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) - { - if (chmode_table[i].set_func == chm_hidden) - { - if(odir != MODE_ADD) - { - *ombuf++ = '+'; - odir = MODE_ADD; - } - *ombuf++ = i; - } - else - { - if(dir != MODE_ADD) - { - *mbuf++ = '+'; - dir = MODE_ADD; - } - *mbuf++ = i; + /* ok, first get a list of modes we need to add */ + for (i = 0; i < 256; i++) { + if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) { + if (chmode_table[i].set_func == chm_hidden) { + if(odir != MODE_ADD) { + *ombuf++ = '+'; + odir = MODE_ADD; + } + *ombuf++ = i; + } else { + if(dir != MODE_ADD) { + *mbuf++ = '+'; + dir = MODE_ADD; + } + *mbuf++ = i; - } - } - } + } + } + } - /* now the ones we need to remove. */ - for (i = 0; i < 256; i++) - { - if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) - { - if(chmode_table[i].set_func == chm_hidden) - { - if(odir != MODE_DEL) - { - *ombuf++ = '-'; - odir = MODE_DEL; - } - *ombuf++ = i; - } - else - { - if(dir != MODE_DEL) - { - *mbuf++ = '-'; - dir = MODE_DEL; - } - *mbuf++ = i; - } - } - } + /* now the ones we need to remove. */ + for (i = 0; i < 256; i++) { + if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) { + if(chmode_table[i].set_func == chm_hidden) { + if(odir != MODE_DEL) { + *ombuf++ = '-'; + odir = MODE_DEL; + } + *ombuf++ = i; + } else { + if(dir != MODE_DEL) { + *mbuf++ = '-'; + dir = MODE_DEL; + } + *mbuf++ = i; + } + } + } - if(oldmode->limit && !mode->limit) - { - if(dir != MODE_DEL) - { - *mbuf++ = '-'; - dir = MODE_DEL; - } - *mbuf++ = 'l'; - } - if(oldmode->key[0] && !mode->key[0]) - { - if(dir != MODE_DEL) - { - *mbuf++ = '-'; - dir = MODE_DEL; - } - *mbuf++ = 'k'; - len = rb_sprintf(pbuf, "%s ", oldmode->key); - pbuf += len; - } - if(oldmode->join_num && !mode->join_num) - { - if(dir != MODE_DEL) - { - *mbuf++ = '-'; - dir = MODE_DEL; - } - *mbuf++ = 'j'; - } - if(oldmode->forward[0] && !mode->forward[0]) - { - if(dir != MODE_DEL) - { - *mbuf++ = '-'; - dir = MODE_DEL; - } - *mbuf++ = 'f'; - } - if(mode->limit && oldmode->limit != mode->limit) - { - if(dir != MODE_ADD) - { - *mbuf++ = '+'; - dir = MODE_ADD; - } - *mbuf++ = 'l'; - len = rb_sprintf(pbuf, "%d ", mode->limit); - pbuf += len; - } - if(mode->key[0] && strcmp(oldmode->key, mode->key)) - { - if(dir != MODE_ADD) - { - *mbuf++ = '+'; - dir = MODE_ADD; - } - *mbuf++ = 'k'; - len = rb_sprintf(pbuf, "%s ", mode->key); - pbuf += len; - } - if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) - { - if(dir != MODE_ADD) - { - *mbuf++ = '+'; - dir = MODE_ADD; - } - *mbuf++ = 'j'; - len = rb_sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); - pbuf += len; - } - if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && ConfigChannel.use_forward) - { - if(dir != MODE_ADD) - { - *mbuf++ = '+'; - dir = MODE_ADD; - } - *mbuf++ = 'f'; - len = rb_sprintf(pbuf, "%s ", mode->forward); - pbuf += len; - } - *mbuf = '\0'; + if(oldmode->limit && !mode->limit) { + if(dir != MODE_DEL) { + *mbuf++ = '-'; + dir = MODE_DEL; + } + *mbuf++ = 'l'; + } + if(oldmode->key[0] && !mode->key[0]) { + if(dir != MODE_DEL) { + *mbuf++ = '-'; + dir = MODE_DEL; + } + *mbuf++ = 'k'; + len = rb_sprintf(pbuf, "%s ", oldmode->key); + pbuf += len; + } + if(oldmode->join_num && !mode->join_num) { + if(dir != MODE_DEL) { + *mbuf++ = '-'; + dir = MODE_DEL; + } + *mbuf++ = 'j'; + } + if(oldmode->forward[0] && !mode->forward[0]) { + if(dir != MODE_DEL) { + *mbuf++ = '-'; + dir = MODE_DEL; + } + *mbuf++ = 'f'; + } + if(mode->limit && oldmode->limit != mode->limit) { + if(dir != MODE_ADD) { + *mbuf++ = '+'; + dir = MODE_ADD; + } + *mbuf++ = 'l'; + len = rb_sprintf(pbuf, "%d ", mode->limit); + pbuf += len; + } + if(mode->key[0] && strcmp(oldmode->key, mode->key)) { + if(dir != MODE_ADD) { + *mbuf++ = '+'; + dir = MODE_ADD; + } + *mbuf++ = 'k'; + len = rb_sprintf(pbuf, "%s ", mode->key); + pbuf += len; + } + if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) { + if(dir != MODE_ADD) { + *mbuf++ = '+'; + dir = MODE_ADD; + } + *mbuf++ = 'j'; + len = rb_sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); + pbuf += len; + } + if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && ConfigChannel.use_forward) { + if(dir != MODE_ADD) { + *mbuf++ = '+'; + dir = MODE_ADD; + } + *mbuf++ = 'f'; + len = rb_sprintf(pbuf, "%s ", mode->forward); + pbuf += len; + } + *mbuf = '\0'; } /* * remove_our_modes * * inputs - - * output - - * side effects - + * output - + * side effects - */ static void remove_our_modes(struct Channel *chptr, struct Client *source_p) { - struct membership *msptr; - rb_dlink_node *ptr; - char lmodebuf[MODEBUFLEN]; - char *lpara[MAXMODEPARAMS]; - int count = 0; - int i; + struct membership *msptr; + rb_dlink_node *ptr; + char lmodebuf[MODEBUFLEN]; + char *lpara[MAXMODEPARAMS]; + int count = 0; + int i; - mbuf = lmodebuf; - *mbuf++ = '-'; + mbuf = lmodebuf; + *mbuf++ = '-'; - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; - /* If anyone can think of a way to do this that doesn't make babies cry - * I would love to hear it - Taros */ + /* If anyone can think of a way to do this that doesn't make babies cry + * I would love to hear it - Taros */ - if(is_owner(msptr)) - { - msptr->flags &= ~CHFL_ADMIN; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'y'; + if(is_owner(msptr)) { + msptr->flags &= ~CHFL_ADMIN; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'y'; - /* Make sure it fits if +h, +o, or +v are involved */ - if(is_admin(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + /* Make sure it fits if +h, +o, or +v are involved */ + if(is_admin(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_ADMIN; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'a'; - } - if(is_chanop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); - - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_CHANOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'o'; - } - if(is_halfop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); - - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_HALFOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'h'; - } - if(is_voiced(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); - - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_VOICE; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'v'; - } - else if(is_admin(msptr)) - { - msptr->flags &= ~CHFL_ADMIN; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'a'; + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - /* Make sure it fits if +h, +o, or +v are involved */ - if(is_chanop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); - - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_CHANOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'o'; - } - if(is_halfop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); - - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_HALFOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'h'; - } - if(is_voiced(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); - - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; - - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - - msptr->flags &= ~CHFL_VOICE; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'v'; - } - } + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; } - else if(is_admin(msptr)) - { - msptr->flags &= ~CHFL_ADMIN; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'a'; - /* Make sure it fits if +h, +o, or +v are involved */ - if(is_chanop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + msptr->flags &= ~CHFL_ADMIN; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'a'; + } + if(is_chanop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - msptr->flags &= ~CHFL_CHANOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'o'; - } - if(is_halfop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + msptr->flags &= ~CHFL_CHANOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'o'; + } + if(is_halfop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } + msptr->flags &= ~CHFL_HALFOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'h'; + } + if(is_voiced(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - msptr->flags &= ~CHFL_HALFOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'h'; - } - if(is_voiced(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } + msptr->flags &= ~CHFL_VOICE; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'v'; + } else if(is_admin(msptr)) { + msptr->flags &= ~CHFL_ADMIN; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'a'; - msptr->flags &= ~CHFL_VOICE; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'v'; - } - } - else if(is_chanop(msptr)) - { - msptr->flags &= ~CHFL_CHANOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'o'; + /* Make sure it fits if +h, +o, or +v are involved */ + if(is_chanop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - /* Make sure it fits if +h or +v are involved */ - if(is_halfop(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } + msptr->flags &= ~CHFL_CHANOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'o'; + } + if(is_halfop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - msptr->flags &= ~CHFL_HALFOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'h'; - } - if(is_voiced(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } + msptr->flags &= ~CHFL_HALFOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'h'; + } + if(is_voiced(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - msptr->flags &= ~CHFL_VOICE; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'v'; - } - } - else if(is_halfop(msptr)) - { - msptr->flags &= ~CHFL_HALFOP; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'h'; + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - /* +hv, might not fit so check. */ - if(is_voiced(msptr)) - { - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, - lmodebuf, lpara[0], lpara[1], - lpara[2], lpara[3]); + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - /* preserve the initial '-' */ - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + msptr->flags &= ~CHFL_VOICE; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'v'; + } + } + } else if(is_admin(msptr)) { + msptr->flags &= ~CHFL_ADMIN; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'a'; - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } + /* Make sure it fits if +h, +o, or +v are involved */ + if(is_chanop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - msptr->flags &= ~CHFL_VOICE; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'v'; - } - } - else if(is_voiced(msptr)) - { - msptr->flags &= ~CHFL_VOICE; - lpara[count++] = msptr->client_p->name; - *mbuf++ = 'v'; - } - else - continue; + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - if(count >= MAXMODEPARAMS) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, lmodebuf, - lpara[0], lpara[1], lpara[2], lpara[3]); - mbuf = lmodebuf; - *mbuf++ = '-'; - count = 0; + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } - for(i = 0; i < MAXMODEPARAMS; i++) - lpara[i] = NULL; - } - } + msptr->flags &= ~CHFL_CHANOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'o'; + } + if(is_halfop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); - if(count != 0) - { - *mbuf = '\0'; - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s MODE %s %s %s %s %s %s", - source_p->name, chptr->chname, lmodebuf, - EmptyString(lpara[0]) ? "" : lpara[0], - EmptyString(lpara[1]) ? "" : lpara[1], - EmptyString(lpara[2]) ? "" : lpara[2], - EmptyString(lpara[3]) ? "" : lpara[3]); + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; - } + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } + + msptr->flags &= ~CHFL_HALFOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'h'; + } + if(is_voiced(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); + + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; + + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } + + msptr->flags &= ~CHFL_VOICE; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'v'; + } + } else if(is_chanop(msptr)) { + msptr->flags &= ~CHFL_CHANOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'o'; + + /* Make sure it fits if +h or +v are involved */ + if(is_halfop(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); + + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; + + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } + + msptr->flags &= ~CHFL_HALFOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'h'; + } + if(is_voiced(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); + + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; + + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } + + msptr->flags &= ~CHFL_VOICE; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'v'; + } + } else if(is_halfop(msptr)) { + msptr->flags &= ~CHFL_HALFOP; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'h'; + + /* +hv, might not fit so check. */ + if(is_voiced(msptr)) { + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, + lmodebuf, lpara[0], lpara[1], + lpara[2], lpara[3]); + + /* preserve the initial '-' */ + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; + + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } + + msptr->flags &= ~CHFL_VOICE; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'v'; + } + } else if(is_voiced(msptr)) { + msptr->flags &= ~CHFL_VOICE; + lpara[count++] = msptr->client_p->name; + *mbuf++ = 'v'; + } else + continue; + + if(count >= MAXMODEPARAMS) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, lmodebuf, + lpara[0], lpara[1], lpara[2], lpara[3]); + mbuf = lmodebuf; + *mbuf++ = '-'; + count = 0; + + for(i = 0; i < MAXMODEPARAMS; i++) + lpara[i] = NULL; + } + } + + if(count != 0) { + *mbuf = '\0'; + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s MODE %s %s %s %s %s %s", + source_p->name, chptr->chname, lmodebuf, + EmptyString(lpara[0]) ? "" : lpara[0], + EmptyString(lpara[1]) ? "" : lpara[1], + EmptyString(lpara[2]) ? "" : lpara[2], + EmptyString(lpara[3]) ? "" : lpara[3]); + + } } /* remove_ban_list() @@ -1533,55 +1380,53 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p) */ static void remove_ban_list(struct Channel *chptr, struct Client *source_p, - rb_dlink_list * list, char c, int mems) + rb_dlink_list * list, char c, int mems) { - static char lmodebuf[BUFSIZE]; - static char lparabuf[BUFSIZE]; - struct Ban *banptr; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - char *pbuf; - int count = 0; - int cur_len, mlen, plen; + static char lmodebuf[BUFSIZE]; + static char lparabuf[BUFSIZE]; + struct Ban *banptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + char *pbuf; + int count = 0; + int cur_len, mlen, plen; - pbuf = lparabuf; + pbuf = lparabuf; - cur_len = mlen = rb_sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname); - mbuf = lmodebuf + mlen; + cur_len = mlen = rb_sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname); + mbuf = lmodebuf + mlen; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) - { - banptr = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) { + banptr = ptr->data; - /* trailing space, and the mode letter itself */ - plen = strlen(banptr->banstr) + 2; + /* trailing space, and the mode letter itself */ + plen = strlen(banptr->banstr) + 2; - if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) - { - /* remove trailing space */ - *mbuf = '\0'; - *(pbuf - 1) = '\0'; + if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) { + /* remove trailing space */ + *mbuf = '\0'; + *(pbuf - 1) = '\0'; - sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); + sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); - cur_len = mlen; - mbuf = lmodebuf + mlen; - pbuf = lparabuf; - count = 0; - } + cur_len = mlen; + mbuf = lmodebuf + mlen; + pbuf = lparabuf; + count = 0; + } - *mbuf++ = c; - cur_len += plen; - pbuf += rb_sprintf(pbuf, "%s ", banptr->banstr); - count++; + *mbuf++ = c; + cur_len += plen; + pbuf += rb_sprintf(pbuf, "%s ", banptr->banstr); + count++; - free_ban(banptr); - } + free_ban(banptr); + } - *mbuf = '\0'; - *(pbuf - 1) = '\0'; - sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); + *mbuf = '\0'; + *(pbuf - 1) = '\0'; + sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); - list->head = list->tail = NULL; - list->length = 0; + list->head = list->tail = NULL; + list->length = 0; } diff --git a/modules/core/m_kick.c b/modules/core/m_kick.c index eb126b9..21754e3 100644 --- a/modules/core/m_kick.c +++ b/modules/core/m_kick.c @@ -43,8 +43,8 @@ static int m_kick(struct Client *, struct Client *, int, const char **); #define mg_kick { m_kick, 3 } struct Message kick_msgtab = { - "KICK", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_kick, mg_kick, mg_kick, mg_ignore, mg_kick} + "KICK", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_kick, mg_kick, mg_kick, mg_ignore, mg_kick} }; mapi_clist_av1 kick_clist[] = { &kick_msgtab, NULL }; @@ -60,190 +60,175 @@ DECLARE_MODULE_AV1(kick, NULL, NULL, kick_clist, NULL, NULL, "$Revision: 3317 $" static int m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct membership *msptr; - struct Client *who; - struct Channel *chptr; - int chasing = 0; - char *comment; - const char *name; - char *p = NULL; - char text[10]; - const char *user; - static char buf[BUFSIZE]; - int is_override = 0; + struct membership *msptr; + struct Client *who; + struct Channel *chptr; + int chasing = 0; + char *comment; + const char *name; + char *p = NULL; + char text[10]; + const char *user; + static char buf[BUFSIZE]; + int is_override = 0; - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - *buf = '\0'; - if((p = strchr(parv[1], ','))) - *p = '\0'; + *buf = '\0'; + if((p = strchr(parv[1], ','))) + *p = '\0'; - name = parv[1]; + name = parv[1]; - chptr = find_channel(name); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + chptr = find_channel(name); + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - user = parv[2]; /* strtoken(&p2, parv[2], ","); */ + user = parv[2]; /* strtoken(&p2, parv[2], ","); */ - if(!(who = find_chasing(source_p, user, &chasing))) - { - return 0; - } + if(!(who = find_chasing(source_p, user, &chasing))) { + return 0; + } - if(!IsServer(source_p)) - { - msptr = find_channel_membership(chptr, source_p); + if(!IsServer(source_p)) { + msptr = find_channel_membership(chptr, source_p); - if((msptr == NULL) && MyConnect(source_p)) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), name); - return 0; - } + if((msptr == NULL) && MyConnect(source_p)) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), name); + return 0; + } - if(!can_kick_deop(msptr, find_channel_membership(chptr, who))) - { - if(MyConnect(source_p)) - { - if(IsOverride(source_p)) - is_override = 1; - else - { - sendto_one(source_p, ":%s 482 %s %s :You do not have the proper privileges to kick this user", - me.name, source_p->name, name); - return 0; - } - } + if(!can_kick_deop(msptr, find_channel_membership(chptr, who))) { + if(MyConnect(source_p)) { + if(IsOverride(source_p)) + is_override = 1; + else { + sendto_one(source_p, ":%s 482 %s %s :You do not have the proper privileges to kick this user", + me.name, source_p->name, name); + return 0; + } + } - /* If its a TS 0 channel, do it the old way */ - else if(chptr->channelts == 0) - { - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - get_id(&me, source_p), get_id(source_p, source_p), name); - return 0; - } - } + /* If its a TS 0 channel, do it the old way */ + else if(chptr->channelts == 0) { + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + get_id(&me, source_p), get_id(source_p, source_p), name); + return 0; + } + } - /* Its a user doing a kick, but is not showing as chanop locally - * its also not a user ON -my- server, and the channel has a TS. - * There are two cases we can get to this point then... - * - * 1) connect burst is happening, and for some reason a legit - * op has sent a KICK, but the SJOIN hasn't happened yet or - * been seen. (who knows.. due to lag...) - * - * 2) The channel is desynced. That can STILL happen with TS - * - * Now, the old code roger wrote, would allow the KICK to - * go through. Thats quite legit, but lets weird things like - * KICKS by users who appear not to be chanopped happen, - * or even neater, they appear not to be on the channel. - * This fits every definition of a desync, doesn't it? ;-) - * So I will allow the KICK, otherwise, things are MUCH worse. - * But I will warn it as a possible desync. - * - * -Dianora - */ - } + /* Its a user doing a kick, but is not showing as chanop locally + * its also not a user ON -my- server, and the channel has a TS. + * There are two cases we can get to this point then... + * + * 1) connect burst is happening, and for some reason a legit + * op has sent a KICK, but the SJOIN hasn't happened yet or + * been seen. (who knows.. due to lag...) + * + * 2) The channel is desynced. That can STILL happen with TS + * + * Now, the old code roger wrote, would allow the KICK to + * go through. Thats quite legit, but lets weird things like + * KICKS by users who appear not to be chanopped happen, + * or even neater, they appear not to be on the channel. + * This fits every definition of a desync, doesn't it? ;-) + * So I will allow the KICK, otherwise, things are MUCH worse. + * But I will warn it as a possible desync. + * + * -Dianora + */ + } - if((p = strchr(parv[2], ','))) - *p = '\0'; + if((p = strchr(parv[2], ','))) + *p = '\0'; - msptr = find_channel_membership(chptr, who); + msptr = find_channel_membership(chptr, who); - if(msptr != NULL) - { - if(MyClient(source_p) && IsService(who)) - { - sendto_one(source_p, form_str(ERR_ISCHANSERVICE), - me.name, source_p->name, who->name, chptr->chname); - return 0; - } + if(msptr != NULL) { + if(MyClient(source_p) && IsService(who)) { + sendto_one(source_p, form_str(ERR_ISCHANSERVICE), + me.name, source_p->name, who->name, chptr->chname); + return 0; + } - if(MyClient(source_p) && chptr->mode.mode & MODE_NOKICK) - { - sendto_one_numeric(source_p, ERR_NOKICK, - form_str(ERR_NOKICK), - chptr->chname); - return 0; - } + if(MyClient(source_p) && chptr->mode.mode & MODE_NOKICK) { + sendto_one_numeric(source_p, ERR_NOKICK, + form_str(ERR_NOKICK), + chptr->chname); + return 0; + } - //NOTE: Will not stop kicks from services. - if (MyClient(source_p) && chptr->mode.mode & MODE_NOOPERKICK && IsOper(who)) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Overriding KICK from %s on %s in %s (channel is +M)", - source_p->name, who->name, chptr->chname); - sendto_one_numeric(source_p, ERR_ISCHANSERVICE, - "%s %s :Cannot kick IRC operators from that channel.", - who->name, chptr->chname); - return 0; - } + //NOTE: Will not stop kicks from services. + if (MyClient(source_p) && chptr->mode.mode & MODE_NOOPERKICK && IsOper(who)) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Overriding KICK from %s on %s in %s (channel is +M)", + source_p->name, who->name, chptr->chname); + sendto_one_numeric(source_p, ERR_ISCHANSERVICE, + "%s %s :Cannot kick IRC operators from that channel.", + who->name, chptr->chname); + return 0; + } - if(MyClient(source_p)) - { - hook_data_channel_approval hookdata; + if(MyClient(source_p)) { + hook_data_channel_approval hookdata; - hookdata.client = source_p; - hookdata.chptr = chptr; - hookdata.target = who; - hookdata.approved = 1; + hookdata.client = source_p; + hookdata.chptr = chptr; + hookdata.target = who; + hookdata.approved = 1; - call_hook(h_can_kick, &hookdata); + call_hook(h_can_kick, &hookdata); - if (!hookdata.approved) - return 0; - } + if (!hookdata.approved) + return 0; + } - comment = LOCAL_COPY((EmptyString(parv[3])) ? who->name : parv[3]); - if(strlen(comment) > (size_t) REASONLEN) - comment[REASONLEN] = '\0'; + comment = LOCAL_COPY((EmptyString(parv[3])) ? who->name : parv[3]); + if(strlen(comment) > (size_t) REASONLEN) + comment[REASONLEN] = '\0'; - if(is_override) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding KICK [%s] on [%s] [%s]", - get_oper_name(source_p), who->name, chptr->chname, comment); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding KICK [%s] on [%s] [%s]", - me.name, get_oper_name(source_p), who->name, chptr->chname, comment); - } + if(is_override) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding KICK [%s] on [%s] [%s]", + get_oper_name(source_p), who->name, chptr->chname, comment); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding KICK [%s] on [%s] [%s]", + me.name, get_oper_name(source_p), who->name, chptr->chname, comment); + } - /* jdc - * - In the case of a server kicking a user (i.e. CLEARCHAN), - * the kick should show up as coming from the server which did - * the kick. - * - Personally, flame and I believe that server kicks shouldn't - * be sent anyways. Just waiting for some oper to abuse it... - */ - if(IsServer(source_p)) - sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s", - source_p->name, name, who->name, comment); - else - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s!%s@%s KICK %s %s :%s", - source_p->name, source_p->username, - source_p->host, name, who->name, comment); + /* jdc + * - In the case of a server kicking a user (i.e. CLEARCHAN), + * the kick should show up as coming from the server which did + * the kick. + * - Personally, flame and I believe that server kicks shouldn't + * be sent anyways. Just waiting for some oper to abuse it... + */ + if(IsServer(source_p)) + sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s", + source_p->name, name, who->name, comment); + else + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s!%s@%s KICK %s %s :%s", + source_p->name, source_p->username, + source_p->host, name, who->name, comment); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s KICK %s %s :%s", - use_id(source_p), chptr->chname, use_id(who), comment); - remove_user_from_channel(msptr); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s KICK %s %s :%s", + use_id(source_p), chptr->chname, use_id(who), comment); + remove_user_from_channel(msptr); - rb_snprintf(text, sizeof(text), "K%s", who->id); + rb_snprintf(text, sizeof(text), "K%s", who->id); - /* we don't need to track NOREJOIN stuff unless it's our client being kicked */ - if(MyClient(who) && chptr->mode.mode & MODE_NOREJOIN) - channel_metadata_time_add(chptr, text, rb_current_time(), "KICKNOREJOIN"); - } - else if (MyClient(source_p)) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), user, name); + /* we don't need to track NOREJOIN stuff unless it's our client being kicked */ + if(MyClient(who) && chptr->mode.mode & MODE_NOREJOIN) + channel_metadata_time_add(chptr, text, rb_current_time(), "KICKNOREJOIN"); + } else if (MyClient(source_p)) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), user, name); - return 0; + return 0; } diff --git a/modules/core/m_kill.c b/modules/core/m_kill.c index 80df7df..7e8dad9 100644 --- a/modules/core/m_kill.c +++ b/modules/core/m_kill.c @@ -44,11 +44,11 @@ static char buf[BUFSIZE]; static int ms_kill(struct Client *, struct Client *, int, const char **); static int mo_kill(struct Client *, struct Client *, int, const char **); static void relay_kill(struct Client *, struct Client *, struct Client *, - const char *, const char *); + const char *, const char *); struct Message kill_msgtab = { - "KILL", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_kill, 2}, {ms_kill, 2}, mg_ignore, {mo_kill, 2}} + "KILL", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_kill, 2}, {ms_kill, 2}, mg_ignore, {mo_kill, 2}} }; mapi_clist_av1 kill_clist[] = { &kill_msgtab, NULL }; @@ -63,95 +63,88 @@ DECLARE_MODULE_AV1(kill, NULL, NULL, kill_clist, NULL, NULL, "$Revision: 3408 $" static int mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - const char *inpath = client_p->name; - const char *user; - const char *reason; + struct Client *target_p; + const char *inpath = client_p->name; + const char *user; + const char *reason; - user = parv[1]; + user = parv[1]; - if(!IsOperLocalKill(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill"); - return 0; - } + if(!IsOperLocalKill(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill"); + return 0; + } - if(!EmptyString(parv[2])) - { - char *s; - s = LOCAL_COPY(parv[2]); - if(strlen(s) > (size_t) KILLLEN) - s[KILLLEN] = '\0'; - reason = s; - } - else - reason = ""; + if(!EmptyString(parv[2])) { + char *s; + s = LOCAL_COPY(parv[2]); + if(strlen(s) > (size_t) KILLLEN) + s[KILLLEN] = '\0'; + reason = s; + } else + reason = ""; - if((target_p = find_named_person(user)) == NULL) - { - /* - ** If the user has recently changed nick, automatically - ** rewrite the KILL for this new nickname--this keeps - ** servers in synch when nick change and kill collide - */ - if((target_p = get_history(user, (long) KILLCHASETIMELIMIT)) == NULL) - { - if (strchr(user, '.')) - sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); - else - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), user); - return 0; - } - sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); - } + if((target_p = find_named_person(user)) == NULL) { + /* + ** If the user has recently changed nick, automatically + ** rewrite the KILL for this new nickname--this keeps + ** servers in synch when nick change and kill collide + */ + if((target_p = get_history(user, (long) KILLCHASETIMELIMIT)) == NULL) { + if (strchr(user, '.')) + sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); + else + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), user); + return 0; + } + sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); + } - if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p))) - { - sendto_one_notice(source_p, ":Nick %s is not on your server " - "and you do not have the global_kill flag", - target_p->name); - return 0; - } + if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p))) { + sendto_one_notice(source_p, ":Nick %s is not on your server " + "and you do not have the global_kill flag", + target_p->name); + return 0; + } - if(MyConnect(target_p)) - sendto_one(target_p, ":%s!%s@%s KILL %s :%s", - source_p->name, source_p->username, source_p->host, - target_p->name, reason); + if(MyConnect(target_p)) + sendto_one(target_p, ":%s!%s@%s KILL %s :%s", + source_p->name, source_p->username, source_p->host, + target_p->name, reason); - /* Do not change the format of this message. There's no point in changing messages - * that have been around for ever, for no reason.. */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Received KILL message for %s!%s@%s. From %s Path: %s (%s)", - target_p->name, target_p->username, target_p->orighost, - source_p->name, me.name, reason); + /* Do not change the format of this message. There's no point in changing messages + * that have been around for ever, for no reason.. */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Received KILL message for %s!%s@%s. From %s Path: %s (%s)", + target_p->name, target_p->username, target_p->orighost, + source_p->name, me.name, reason); - ilog(L_KILL, "%c %s %s!%s@%s %s %s", - MyConnect(target_p) ? 'L' : 'G', get_oper_name(source_p), - target_p->name, target_p->username, target_p->host, target_p->servptr->name, reason); + ilog(L_KILL, "%c %s %s!%s@%s %s %s", + MyConnect(target_p) ? 'L' : 'G', get_oper_name(source_p), + target_p->name, target_p->username, target_p->host, target_p->servptr->name, reason); - /* - ** And pass on the message to other servers. Note, that if KILL - ** was changed, the message has to be sent to all links, also - ** back. - ** Suicide kills are NOT passed on --SRB - */ - if(!MyConnect(target_p)) - { - relay_kill(client_p, source_p, target_p, inpath, reason); - /* - ** Set FLAGS_KILLED. This prevents exit_one_client from sending - ** the unnecessary QUIT for this. (This flag should never be - ** set in any other place) - */ - target_p->flags |= FLAGS_KILLED; - } + /* + ** And pass on the message to other servers. Note, that if KILL + ** was changed, the message has to be sent to all links, also + ** back. + ** Suicide kills are NOT passed on --SRB + */ + if(!MyConnect(target_p)) { + relay_kill(client_p, source_p, target_p, inpath, reason); + /* + ** Set FLAGS_KILLED. This prevents exit_one_client from sending + ** the unnecessary QUIT for this. (This flag should never be + ** set in any other place) + */ + target_p->flags |= FLAGS_KILLED; + } - rb_sprintf(buf, "Killed (%s (%s))", source_p->name, reason); + rb_sprintf(buf, "Killed (%s (%s))", source_p->name, reason); - exit_client(client_p, target_p, source_p, buf); + exit_client(client_p, target_p, source_p, buf); - return 0; + return 0; } /* @@ -162,142 +155,127 @@ mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - const char *user; - const char *reason; - char default_reason[] = ""; - const char *path; - int chasing = 0; + struct Client *target_p; + const char *user; + const char *reason; + char default_reason[] = ""; + const char *path; + int chasing = 0; - *buf = '\0'; + *buf = '\0'; - user = parv[1]; + user = parv[1]; - if(EmptyString(parv[2])) - { - reason = default_reason; + if(EmptyString(parv[2])) { + reason = default_reason; - /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ - path = source_p->name; - } - else - { - char *s = LOCAL_COPY(parv[2]), *t; - t = strchr(s, ' '); + /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ + path = source_p->name; + } else { + char *s = LOCAL_COPY(parv[2]), *t; + t = strchr(s, ' '); - if(t) - { - *t = '\0'; - t++; - reason = t; - } - else - reason = default_reason; + if(t) { + *t = '\0'; + t++; + reason = t; + } else + reason = default_reason; - path = s; - } + path = s; + } - if((target_p = find_person(user)) == NULL) - { - /* - * If the user has recently changed nick, but only if its - * not an uid, automatically rewrite the KILL for this new nickname. - * --this keeps servers in synch when nick change and kill collide - */ - if(IsDigit(*user) || (!(target_p = get_history(user, (long) KILLCHASETIMELIMIT)))) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user); - return 0; - } - sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); - chasing = 1; - } + if((target_p = find_person(user)) == NULL) { + /* + * If the user has recently changed nick, but only if its + * not an uid, automatically rewrite the KILL for this new nickname. + * --this keeps servers in synch when nick change and kill collide + */ + if(IsDigit(*user) || (!(target_p = get_history(user, (long) KILLCHASETIMELIMIT)))) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user); + return 0; + } + sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); + chasing = 1; + } - if(IsServer(target_p) || IsMe(target_p)) - { - sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); - return 0; - } + if(IsServer(target_p) || IsMe(target_p)) { + sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); + return 0; + } - if(MyConnect(target_p)) - { - if(IsServer(source_p)) - { - sendto_one(target_p, ":%s KILL %s :%s", - source_p->name, target_p->name, reason); - } - else - sendto_one(target_p, ":%s!%s@%s KILL %s :%s", - source_p->name, source_p->username, source_p->host, - target_p->name, reason); - } + if(MyConnect(target_p)) { + if(IsServer(source_p)) { + sendto_one(target_p, ":%s KILL %s :%s", + source_p->name, target_p->name, reason); + } else + sendto_one(target_p, ":%s!%s@%s KILL %s :%s", + source_p->name, source_p->username, source_p->host, + target_p->name, reason); + } - /* Be warned, this message must be From %s, or it confuses clients - * so dont change it to From: or the case or anything! -- fl -- db */ - /* path must contain at least 2 !'s, or bitchx falsely declares it - * local --fl - */ - if(IsOper(source_p)) /* send it normally */ - { - sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL, - "Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s", - target_p->name, target_p->username, target_p->orighost, source_p->name, - source_p->servptr->name, source_p->host, source_p->username, - source_p->name, reason); + /* Be warned, this message must be From %s, or it confuses clients + * so dont change it to From: or the case or anything! -- fl -- db */ + /* path must contain at least 2 !'s, or bitchx falsely declares it + * local --fl + */ + if(IsOper(source_p)) { /* send it normally */ + sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL, + "Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s", + target_p->name, target_p->username, target_p->orighost, source_p->name, + source_p->servptr->name, source_p->host, source_p->username, + source_p->name, reason); - ilog(L_KILL, "%c %s %s!%s@%s %s %s", - MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p), - target_p->name, target_p->username, target_p->host, - target_p->servptr->name, reason); - } - else - { - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Received KILL message for %s!%s@%s. From %s %s", - target_p->name, target_p->username, target_p->orighost, - source_p->name, reason); + ilog(L_KILL, "%c %s %s!%s@%s %s %s", + MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p), + target_p->name, target_p->username, target_p->host, + target_p->servptr->name, reason); + } else { + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Received KILL message for %s!%s@%s. From %s %s", + target_p->name, target_p->username, target_p->orighost, + source_p->name, reason); - ilog(L_KILL, "S %s %s!%s@%s %s %s", - source_p->name, target_p->name, target_p->username, - target_p->host, target_p->servptr->name, reason); - } + ilog(L_KILL, "S %s %s!%s@%s %s %s", + source_p->name, target_p->name, target_p->username, + target_p->host, target_p->servptr->name, reason); + } - relay_kill(client_p, source_p, target_p, path, reason); + relay_kill(client_p, source_p, target_p, path, reason); - /* FLAGS_KILLED prevents a quit being sent out */ - target_p->flags |= FLAGS_KILLED; + /* FLAGS_KILLED prevents a quit being sent out */ + target_p->flags |= FLAGS_KILLED; - rb_sprintf(buf, "Killed (%s %s)", source_p->name, reason); + rb_sprintf(buf, "Killed (%s %s)", source_p->name, reason); - exit_client(client_p, target_p, source_p, buf); + exit_client(client_p, target_p, source_p, buf); - return 0; + return 0; } static void relay_kill(struct Client *one, struct Client *source_p, - struct Client *target_p, const char *inpath, const char *reason) + struct Client *target_p, const char *inpath, const char *reason) { - struct Client *client_p; - rb_dlink_node *ptr; - char buffer[BUFSIZE]; + struct Client *client_p; + rb_dlink_node *ptr; + char buffer[BUFSIZE]; - if(MyClient(source_p)) - rb_snprintf(buffer, sizeof(buffer), - "%s!%s!%s!%s (%s)", - me.name, source_p->host, source_p->username, source_p->name, reason); - else - rb_snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason); + if(MyClient(source_p)) + rb_snprintf(buffer, sizeof(buffer), + "%s!%s!%s!%s (%s)", + me.name, source_p->host, source_p->username, source_p->name, reason); + else + rb_snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason); - RB_DLINK_FOREACH(ptr, serv_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + client_p = ptr->data; - if(!client_p || client_p == one) - continue; + if(!client_p || client_p == one) + continue; - sendto_one(client_p, ":%s KILL %s :%s", - get_id(source_p, client_p), get_id(target_p, client_p), buffer); - } + sendto_one(client_p, ":%s KILL %s :%s", + get_id(source_p, client_p), get_id(target_p, client_p), buffer); + } } diff --git a/modules/core/m_message.c b/modules/core/m_message.c index d108cc9..3baadb0 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -56,40 +56,39 @@ static struct ev_entry *expire_tgchange_event; static int modinit(void) { - expire_tgchange_event = rb_event_addish("expire_tgchange", expire_tgchange, NULL, 300); - expire_tgchange(NULL); - return 0; + expire_tgchange_event = rb_event_addish("expire_tgchange", expire_tgchange, NULL, 300); + expire_tgchange(NULL); + return 0; } static void moddeinit(void) { - rb_event_delete(expire_tgchange_event); + rb_event_delete(expire_tgchange_event); } struct Message privmsg_msgtab = { - "PRIVMSG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {mg_unreg, {m_privmsg, 0}, {m_privmsg, 0}, mg_ignore, mg_ignore, {m_privmsg, 0}} + "PRIVMSG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {mg_unreg, {m_privmsg, 0}, {m_privmsg, 0}, mg_ignore, mg_ignore, {m_privmsg, 0}} }; struct Message notice_msgtab = { - "NOTICE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_notice, 0}, {m_notice, 0}, {m_notice, 0}, mg_ignore, {m_notice, 0}} + "NOTICE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_notice, 0}, {m_notice, 0}, {m_notice, 0}, mg_ignore, {m_notice, 0}} }; mapi_clist_av1 message_clist[] = { &privmsg_msgtab, ¬ice_msgtab, NULL }; DECLARE_MODULE_AV1(message, modinit, moddeinit, message_clist, NULL, NULL, "$Revision: 3173 $"); -struct entity -{ - void *ptr; - int type; - int flags; +struct entity { + void *ptr; + int type; + int flags; }; static int build_target_list(int p_or_n, const char *command, - struct Client *client_p, - struct Client *source_p, const char *nicks_channels, const char *text); + struct Client *client_p, + struct Client *source_p, const char *nicks_channels, const char *text); static int flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p); @@ -108,25 +107,25 @@ static int ntargets = 0; static int duplicate_ptr(void *); static void msg_channel(int p_or_n, const char *command, - struct Client *client_p, - struct Client *source_p, struct Channel *chptr, const char *text); + struct Client *client_p, + struct Client *source_p, struct Channel *chptr, const char *text); static void msg_channel_opmod(int p_or_n, const char *command, - struct Client *client_p, - struct Client *source_p, struct Channel *chptr, - const char *text); + struct Client *client_p, + struct Client *source_p, struct Channel *chptr, + const char *text); static void msg_channel_flags(int p_or_n, const char *command, - struct Client *client_p, - struct Client *source_p, - struct Channel *chptr, int flags, const char *text); + struct Client *client_p, + struct Client *source_p, + struct Channel *chptr, int flags, const char *text); static void msg_client(int p_or_n, const char *command, - struct Client *source_p, struct Client *target_p, const char *text); + struct Client *source_p, struct Client *target_p, const char *text); static void handle_special(int p_or_n, const char *command, - struct Client *client_p, struct Client *source_p, const char *nick, - const char *text); + struct Client *client_p, struct Client *source_p, const char *nick, + const char *text); /* ** m_privmsg @@ -153,13 +152,13 @@ static void handle_special(int p_or_n, const char *command, static int m_privmsg(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - return m_message(PRIVMSG, "PRIVMSG", client_p, source_p, parc, parv); + return m_message(PRIVMSG, "PRIVMSG", client_p, source_p, parc, parv); } static int m_notice(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - return m_message(NOTICE, "NOTICE", client_p, source_p, parc, parv); + return m_message(NOTICE, "NOTICE", client_p, source_p, parc, parv); } /* @@ -171,65 +170,60 @@ m_notice(struct Client *client_p, struct Client *source_p, int parc, const char */ static int m_message(int p_or_n, - const char *command, - struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) + const char *command, + struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int i; + int i; - if(parc < 2 || EmptyString(parv[1])) - { - if(p_or_n != NOTICE) - sendto_one(source_p, form_str(ERR_NORECIPIENT), me.name, - source_p->name, command); - return 0; - } + if(parc < 2 || EmptyString(parv[1])) { + if(p_or_n != NOTICE) + sendto_one(source_p, form_str(ERR_NORECIPIENT), me.name, + source_p->name, command); + return 0; + } - if(parc < 3 || EmptyString(parv[2])) - { - if(p_or_n != NOTICE) - sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); - return 0; - } + if(parc < 3 || EmptyString(parv[2])) { + if(p_or_n != NOTICE) + sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); + return 0; + } - /* Finish the flood grace period if theyre not messaging themselves - * as some clients (ircN) do this as a "lag check" - */ - if(MyClient(source_p) && !IsFloodDone(source_p) && irccmp(source_p->name, parv[1])) - flood_endgrace(source_p); + /* Finish the flood grace period if theyre not messaging themselves + * as some clients (ircN) do this as a "lag check" + */ + if(MyClient(source_p) && !IsFloodDone(source_p) && irccmp(source_p->name, parv[1])) + flood_endgrace(source_p); - if(build_target_list(p_or_n, command, client_p, source_p, parv[1], parv[2]) < 0) - { - return 0; - } + if(build_target_list(p_or_n, command, client_p, source_p, parv[1], parv[2]) < 0) { + return 0; + } - for(i = 0; i < ntargets; i++) - { - switch (targets[i].type) - { - case ENTITY_CHANNEL: - msg_channel(p_or_n, command, client_p, source_p, - (struct Channel *) targets[i].ptr, parv[2]); - break; + for(i = 0; i < ntargets; i++) { + switch (targets[i].type) { + case ENTITY_CHANNEL: + msg_channel(p_or_n, command, client_p, source_p, + (struct Channel *) targets[i].ptr, parv[2]); + break; - case ENTITY_CHANNEL_OPMOD: - msg_channel_opmod(p_or_n, command, client_p, source_p, - (struct Channel *) targets[i].ptr, parv[2]); - break; + case ENTITY_CHANNEL_OPMOD: + msg_channel_opmod(p_or_n, command, client_p, source_p, + (struct Channel *) targets[i].ptr, parv[2]); + break; - case ENTITY_CHANOPS_ON_CHANNEL: - msg_channel_flags(p_or_n, command, client_p, source_p, - (struct Channel *) targets[i].ptr, - targets[i].flags, parv[2]); - break; + case ENTITY_CHANOPS_ON_CHANNEL: + msg_channel_flags(p_or_n, command, client_p, source_p, + (struct Channel *) targets[i].ptr, + targets[i].flags, parv[2]); + break; - case ENTITY_CLIENT: - msg_client(p_or_n, command, source_p, - (struct Client *) targets[i].ptr, parv[2]); - break; - } - } + case ENTITY_CLIENT: + msg_client(p_or_n, command, source_p, + (struct Client *) targets[i].ptr, parv[2]); + break; + } + } - return 0; + return 0; } /* @@ -252,194 +246,171 @@ m_message(int p_or_n, static int build_target_list(int p_or_n, const char *command, struct Client *client_p, - struct Client *source_p, const char *nicks_channels, const char *text) + struct Client *source_p, const char *nicks_channels, const char *text) { - int type; - char *p, *nick, *target_list; - struct Channel *chptr = NULL; - struct Client *target_p; + int type; + char *p, *nick, *target_list; + struct Channel *chptr = NULL; + struct Client *target_p; - target_list = LOCAL_COPY(nicks_channels); /* skip strcpy for non-lazyleafs */ + target_list = LOCAL_COPY(nicks_channels); /* skip strcpy for non-lazyleafs */ - ntargets = 0; + ntargets = 0; - for(nick = rb_strtok_r(target_list, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p)) - { - char *with_prefix; - /* - * channels are privmsg'd a lot more than other clients, moved up - * here plain old channel msg? - */ + for(nick = rb_strtok_r(target_list, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p)) { + char *with_prefix; + /* + * channels are privmsg'd a lot more than other clients, moved up + * here plain old channel msg? + */ - if(IsChanPrefix(*nick)) - { - /* ignore send of local channel to a server (should not happen) */ - if(IsServer(client_p) && *nick == '&') - continue; + if(IsChanPrefix(*nick)) { + /* ignore send of local channel to a server (should not happen) */ + if(IsServer(client_p) && *nick == '&') + continue; - if((chptr = find_channel(nick)) != NULL) - { - if(!duplicate_ptr(chptr)) - { - if(ntargets >= ConfigFileEntry.max_targets) - { - sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), - me.name, source_p->name, nick); - return (1); - } - targets[ntargets].ptr = (void *) chptr; - targets[ntargets++].type = ENTITY_CHANNEL; - } - } + if((chptr = find_channel(nick)) != NULL) { + if(!duplicate_ptr(chptr)) { + if(ntargets >= ConfigFileEntry.max_targets) { + sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), + me.name, source_p->name, nick); + return (1); + } + targets[ntargets].ptr = (void *) chptr; + targets[ntargets++].type = ENTITY_CHANNEL; + } + } - /* non existant channel */ - else if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); + /* non existant channel */ + else if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); - continue; - } + continue; + } - if(MyClient(source_p)) - target_p = find_named_person(nick); - else - target_p = find_person(nick); + if(MyClient(source_p)) + target_p = find_named_person(nick); + else + target_p = find_person(nick); - /* look for a privmsg to another client */ - if(target_p) - { - if(!duplicate_ptr(target_p)) - { - if(ntargets >= ConfigFileEntry.max_targets) - { - sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), - me.name, source_p->name, nick); - return (1); - } - targets[ntargets].ptr = (void *) target_p; - targets[ntargets].type = ENTITY_CLIENT; - targets[ntargets++].flags = 0; - } - continue; - } + /* look for a privmsg to another client */ + if(target_p) { + if(!duplicate_ptr(target_p)) { + if(ntargets >= ConfigFileEntry.max_targets) { + sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), + me.name, source_p->name, nick); + return (1); + } + targets[ntargets].ptr = (void *) target_p; + targets[ntargets].type = ENTITY_CLIENT; + targets[ntargets++].flags = 0; + } + continue; + } - /* @#channel or +#channel message ? */ + /* @#channel or +#channel message ? */ - type = 0; - with_prefix = nick; - /* allow %+@ if someone wants to do that */ - for(;;) - { - if(*nick == '@') - type |= CHFL_CHANOP; - else if(*nick == '+') - type |= CHFL_CHANOP | CHFL_VOICE; - else - break; - nick++; - } + type = 0; + with_prefix = nick; + /* allow %+@ if someone wants to do that */ + for(;;) { + if(*nick == '@') + type |= CHFL_CHANOP; + else if(*nick == '+') + type |= CHFL_CHANOP | CHFL_VOICE; + else + break; + nick++; + } - if(type != 0) - { - /* no recipient.. */ - if(EmptyString(nick)) - { - sendto_one(source_p, form_str(ERR_NORECIPIENT), - me.name, source_p->name, command); - continue; - } + if(type != 0) { + /* no recipient.. */ + if(EmptyString(nick)) { + sendto_one(source_p, form_str(ERR_NORECIPIENT), + me.name, source_p->name, command); + continue; + } - /* At this point, nick+1 should be a channel name i.e. #foo or &foo - * if the channel is found, fine, if not report an error - */ + /* At this point, nick+1 should be a channel name i.e. #foo or &foo + * if the channel is found, fine, if not report an error + */ - if((chptr = find_channel(nick)) != NULL) - { - struct membership *msptr; + if((chptr = find_channel(nick)) != NULL) { + struct membership *msptr; - msptr = find_channel_membership(chptr, source_p); + msptr = find_channel_membership(chptr, source_p); - if(!IsServer(source_p) && !IsService(source_p) && !is_chanop_voiced(msptr)) - { - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - get_id(&me, source_p), - get_id(source_p, source_p), - with_prefix); - return (-1); - } + if(!IsServer(source_p) && !IsService(source_p) && !is_chanop_voiced(msptr)) { + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + get_id(&me, source_p), + get_id(source_p, source_p), + with_prefix); + return (-1); + } - if(!duplicate_ptr(chptr)) - { - if(ntargets >= ConfigFileEntry.max_targets) - { - sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), - me.name, source_p->name, nick); - return (1); - } - targets[ntargets].ptr = (void *) chptr; - targets[ntargets].type = ENTITY_CHANOPS_ON_CHANNEL; - targets[ntargets++].flags = type; - } - } - else if(p_or_n != NOTICE) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); - } + if(!duplicate_ptr(chptr)) { + if(ntargets >= ConfigFileEntry.max_targets) { + sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), + me.name, source_p->name, nick); + return (1); + } + targets[ntargets].ptr = (void *) chptr; + targets[ntargets].type = ENTITY_CHANOPS_ON_CHANNEL; + targets[ntargets++].flags = type; + } + } else if(p_or_n != NOTICE) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); + } - continue; - } + continue; + } - if(IsServer(client_p) && *nick == '=' && nick[1] == '#') - { - nick++; - if((chptr = find_channel(nick)) != NULL) - { - if(!duplicate_ptr(chptr)) - { - if(ntargets >= ConfigFileEntry.max_targets) - { - sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), - me.name, source_p->name, nick); - return (1); - } - targets[ntargets].ptr = (void *) chptr; - targets[ntargets++].type = ENTITY_CHANNEL_OPMOD; - } - } + if(IsServer(client_p) && *nick == '=' && nick[1] == '#') { + nick++; + if((chptr = find_channel(nick)) != NULL) { + if(!duplicate_ptr(chptr)) { + if(ntargets >= ConfigFileEntry.max_targets) { + sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), + me.name, source_p->name, nick); + return (1); + } + targets[ntargets].ptr = (void *) chptr; + targets[ntargets++].type = ENTITY_CHANNEL_OPMOD; + } + } - /* non existant channel */ - else if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); + /* non existant channel */ + else if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); - continue; - } + continue; + } - if(strchr(nick, '@') || (IsOper(source_p) && (*nick == '$'))) - { - handle_special(p_or_n, command, client_p, source_p, nick, text); - continue; - } + if(strchr(nick, '@') || (IsOper(source_p) && (*nick == '$'))) { + handle_special(p_or_n, command, client_p, source_p, nick, text); + continue; + } - /* no matching anything found - error if not NOTICE */ - if(p_or_n != NOTICE) - { - /* dont give this numeric when source is local, - * because its misleading --anfl - */ - if(!MyClient(source_p) && IsDigit(*nick)) - sendto_one(source_p, ":%s %d %s * :Target left IRC. " - "Failed to deliver: [%.20s]", - get_id(&me, source_p), ERR_NOSUCHNICK, - get_id(source_p, source_p), text); - else - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); - } + /* no matching anything found - error if not NOTICE */ + if(p_or_n != NOTICE) { + /* dont give this numeric when source is local, + * because its misleading --anfl + */ + if(!MyClient(source_p) && IsDigit(*nick)) + sendto_one(source_p, ":%s %d %s * :Target left IRC. " + "Failed to deliver: [%.20s]", + get_id(&me, source_p), ERR_NOSUCHNICK, + get_id(source_p, source_p), text); + else + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); + } - } - return (1); + } + return (1); } /* @@ -455,11 +426,11 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p, static int duplicate_ptr(void *ptr) { - int i; - for(i = 0; i < ntargets; i++) - if(targets[i].ptr == ptr) - return YES; - return NO; + int i; + for(i = 0; i < ntargets; i++) + if(targets[i].ptr == ptr) + return YES; + return NO; } /* @@ -477,149 +448,125 @@ duplicate_ptr(void *ptr) */ static void msg_channel(int p_or_n, const char *command, - struct Client *client_p, struct Client *source_p, struct Channel *chptr, - const char *text) + struct Client *client_p, struct Client *source_p, struct Channel *chptr, + const char *text) { - int result; - char text2[BUFSIZE]; - size_t contor; - int caps = 0; - int len = 0; - struct membership *msptr = find_channel_membership(chptr, source_p); - struct Metadata *md; + int result; + char text2[BUFSIZE]; + size_t contor; + int caps = 0; + int len = 0; + struct membership *msptr = find_channel_membership(chptr, source_p); + struct Metadata *md; - if(MyClient(source_p)) - { - /* idle time shouldnt be reset by notices --fl */ - if(p_or_n != NOTICE) - source_p->localClient->last = rb_current_time(); - } + if(MyClient(source_p)) { + /* idle time shouldnt be reset by notices --fl */ + if(p_or_n != NOTICE) + source_p->localClient->last = rb_current_time(); + } - if(chptr->mode.mode & MODE_NOREPEAT) - { - rb_strlcpy(text2, text, BUFSIZE); - strip_unprintable(text2); - md = channel_metadata_find(chptr, "NOREPEAT"); - if(md && (!ConfigChannel.exempt_cmode_K || !is_any_op(msptr))) - { - if(!(strcmp(md->value, text2))) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Message blocked due to repeating (+K set)", chptr->chname); - return; - } - } - channel_metadata_delete(chptr, "NOREPEAT", 0); - channel_metadata_add(chptr, "NOREPEAT", text2, 0); - } + if(chptr->mode.mode & MODE_NOREPEAT) { + rb_strlcpy(text2, text, BUFSIZE); + strip_unprintable(text2); + md = channel_metadata_find(chptr, "NOREPEAT"); + if(md && (!ConfigChannel.exempt_cmode_K || !is_any_op(msptr))) { + if(!(strcmp(md->value, text2))) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Message blocked due to repeating (+K set)", chptr->chname); + return; + } + } + channel_metadata_delete(chptr, "NOREPEAT", 0); + channel_metadata_add(chptr, "NOREPEAT", text2, 0); + } // Must be processed before chmode c --SnoFox - if (strlen(text) > 10 && chptr->mode.mode & MODE_NOCAPS && (!ConfigChannel.exempt_cmode_G || !is_any_op(msptr))) - { + if (strlen(text) > 10 && chptr->mode.mode & MODE_NOCAPS && (!ConfigChannel.exempt_cmode_G || !is_any_op(msptr))) { rb_strlcpy(text2, text, BUFSIZE); strip_unprintable(text2); // Don't count the "ACTION" part of action as part of the message --SnoFox if (p_or_n != NOTICE && *text == '\001' && - !strncasecmp(text + 1, "ACTION ", 7)) - { + !strncasecmp(text + 1, "ACTION ", 7)) { contor = 7; } else { contor = 0; } - for(; contor < strlen(text2); contor++) - { + for(; contor < strlen(text2); contor++) { if(IsUpper(text2[contor]) && !isdigit(text2[contor])) - caps++; + caps++; len++; } /* Added divide by 0 check --alxbl */ - if(len != 0 && ((caps*100)/(len)) >= 50) - { + if(len != 0 && ((caps*100)/(len)) >= 50) { sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Your message contains mostly capital letters (+G set)", chptr->chname); return; } } - if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) - { - rb_strlcpy(text2, text, BUFSIZE); - strip_colour(text2); - text = text2; - if (EmptyString(text)) - { - /* could be empty after colour stripping and - * that would cause problems later */ - if(p_or_n != NOTICE) - sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); - return; - } - } + if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) { + rb_strlcpy(text2, text, BUFSIZE); + strip_colour(text2); + text = text2; + if (EmptyString(text)) { + /* could be empty after colour stripping and + * that would cause problems later */ + if(p_or_n != NOTICE) + sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); + return; + } + } - /* chanops and voiced can flood their own channel with impunity */ - if((result = can_send(chptr, source_p, NULL))) - { - if(result != CAN_SEND_OPV && MyClient(source_p) && - !IsOper(source_p) && - !add_channel_target(source_p, chptr)) - { - sendto_one(source_p, form_str(ERR_TARGCHANGE), - me.name, source_p->name, chptr->chname); - return; - } - if(result == CAN_SEND_OPV || - !flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) - { - if (p_or_n != PRIVMSG && chptr->mode.mode & MODE_NONOTICE && (!ConfigChannel.exempt_cmode_T || !is_any_op(msptr))) - { - sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Notices are disallowed (+T set)", chptr->chname); - return; - } - if (p_or_n != NOTICE && chptr->mode.mode & MODE_NOACTION && - !strncasecmp(text + 1, "ACTION", 6) && - (!ConfigChannel.exempt_cmode_D || !is_any_op(msptr))) - { - sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - ACTIONs are disallowed (+D set)", chptr->chname); - return; - } - if (p_or_n != NOTICE && *text == '\001' && - strncasecmp(text + 1, "ACTION ", 7)) - { - if (chptr->mode.mode & MODE_NOCTCP && (!ConfigChannel.exempt_cmode_C || !is_any_op(msptr))) - { - sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - CTCPs to this channel are disallowed (+C set)", chptr->chname); - return; - } - else if (rb_dlink_list_length(&chptr->locmembers) > (unsigned)(GlobalSetOptions.floodcount / 2)) - source_p->large_ctcp_sent = rb_current_time(); - } - sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr, - "%s %s :%s", command, chptr->chname, text); - } - } - else if(chptr->mode.mode & MODE_OPMODERATE && - (!(chptr->mode.mode & MODE_NOPRIVMSGS) || - IsMember(source_p, chptr))) - { - if(MyClient(source_p) && !IsOper(source_p) && - !add_channel_target(source_p, chptr)) - { - sendto_one(source_p, form_str(ERR_TARGCHANGE), - me.name, source_p->name, chptr->chname); - return; - } - if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) - { - sendto_channel_opmod(client_p, source_p, chptr, - command, text); - } - } - else - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, - form_str(ERR_CANNOTSENDTOCHAN), chptr->chname); - } + /* chanops and voiced can flood their own channel with impunity */ + if((result = can_send(chptr, source_p, NULL))) { + if(result != CAN_SEND_OPV && MyClient(source_p) && + !IsOper(source_p) && + !add_channel_target(source_p, chptr)) { + sendto_one(source_p, form_str(ERR_TARGCHANGE), + me.name, source_p->name, chptr->chname); + return; + } + if(result == CAN_SEND_OPV || + !flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) { + if (p_or_n != PRIVMSG && chptr->mode.mode & MODE_NONOTICE && (!ConfigChannel.exempt_cmode_T || !is_any_op(msptr))) { + sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Notices are disallowed (+T set)", chptr->chname); + return; + } + if (p_or_n != NOTICE && chptr->mode.mode & MODE_NOACTION && + !strncasecmp(text + 1, "ACTION", 6) && + (!ConfigChannel.exempt_cmode_D || !is_any_op(msptr))) { + sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - ACTIONs are disallowed (+D set)", chptr->chname); + return; + } + if (p_or_n != NOTICE && *text == '\001' && + strncasecmp(text + 1, "ACTION ", 7)) { + if (chptr->mode.mode & MODE_NOCTCP && (!ConfigChannel.exempt_cmode_C || !is_any_op(msptr))) { + sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - CTCPs to this channel are disallowed (+C set)", chptr->chname); + return; + } else if (rb_dlink_list_length(&chptr->locmembers) > (unsigned)(GlobalSetOptions.floodcount / 2)) + source_p->large_ctcp_sent = rb_current_time(); + } + sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr, + "%s %s :%s", command, chptr->chname, text); + } + } else if(chptr->mode.mode & MODE_OPMODERATE && + (!(chptr->mode.mode & MODE_NOPRIVMSGS) || + IsMember(source_p, chptr))) { + if(MyClient(source_p) && !IsOper(source_p) && + !add_channel_target(source_p, chptr)) { + sendto_one(source_p, form_str(ERR_TARGCHANGE), + me.name, source_p->name, chptr->chname); + return; + } + if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) { + sendto_channel_opmod(client_p, source_p, chptr, + command, text); + } + } else { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, + form_str(ERR_CANNOTSENDTOCHAN), chptr->chname); + } } /* * msg_channel_opmod @@ -636,48 +583,42 @@ msg_channel(int p_or_n, const char *command, */ static void msg_channel_opmod(int p_or_n, const char *command, - struct Client *client_p, struct Client *source_p, - struct Channel *chptr, const char *text) + struct Client *client_p, struct Client *source_p, + struct Channel *chptr, const char *text) { - char text2[BUFSIZE]; + char text2[BUFSIZE]; - if(chptr->mode.mode & MODE_NOCOLOR) - { - rb_strlcpy(text2, text, BUFSIZE); - strip_colour(text2); - text = text2; - if (EmptyString(text)) - { - /* could be empty after colour stripping and - * that would cause problems later */ - if(p_or_n != NOTICE) - sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); - return; - } - } + if(chptr->mode.mode & MODE_NOCOLOR) { + rb_strlcpy(text2, text, BUFSIZE); + strip_colour(text2); + text = text2; + if (EmptyString(text)) { + /* could be empty after colour stripping and + * that would cause problems later */ + if(p_or_n != NOTICE) + sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); + return; + } + } - if(chptr->mode.mode & MODE_OPMODERATE && - (!(chptr->mode.mode & MODE_NOPRIVMSGS) || - IsMember(source_p, chptr))) - { - if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) - { - sendto_channel_opmod(client_p, source_p, chptr, - command, text); - } - } - else - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, - form_str(ERR_CANNOTSENDTOCHAN), chptr->chname); - } + if(chptr->mode.mode & MODE_OPMODERATE && + (!(chptr->mode.mode & MODE_NOPRIVMSGS) || + IsMember(source_p, chptr))) { + if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) { + sendto_channel_opmod(client_p, source_p, chptr, + command, text); + } + } else { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, + form_str(ERR_CANNOTSENDTOCHAN), chptr->chname); + } } /* * msg_channel_flags * - * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC + * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC * say NOTICE must not auto reply * - pointer to command, "PRIVMSG" or "NOTICE" * - pointer to client_p @@ -690,57 +631,51 @@ msg_channel_opmod(int p_or_n, const char *command, */ static void msg_channel_flags(int p_or_n, const char *command, struct Client *client_p, - struct Client *source_p, struct Channel *chptr, int flags, const char *text) + struct Client *source_p, struct Channel *chptr, int flags, const char *text) { - int type; - char c; + int type; + char c; - if(flags & CHFL_VOICE) - { - type = ONLY_CHANOPSVOICED; - c = '+'; - } - else - { - type = ONLY_CHANOPS; - c = '@'; - } + if(flags & CHFL_VOICE) { + type = ONLY_CHANOPSVOICED; + c = '+'; + } else { + type = ONLY_CHANOPS; + c = '@'; + } - if(MyClient(source_p)) - { - /* idletime shouldnt be reset by notice --fl */ - if(p_or_n != NOTICE) - source_p->localClient->last = rb_current_time(); - } + if(MyClient(source_p)) { + /* idletime shouldnt be reset by notice --fl */ + if(p_or_n != NOTICE) + source_p->localClient->last = rb_current_time(); + } - sendto_channel_flags(client_p, type, source_p, chptr, "%s %c%s :%s", - command, c, chptr->chname, text); + sendto_channel_flags(client_p, type, source_p, chptr, "%s %c%s :%s", + command, c, chptr->chname, text); } static void expire_tgchange(void *unused) { - tgchange *target; - rb_dlink_node *ptr, *next_ptr; + tgchange *target; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, tgchange_list.head) - { - target = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, tgchange_list.head) { + target = ptr->data; - if(target->expiry < rb_current_time()) - { - rb_dlinkDelete(ptr, &tgchange_list); - rb_patricia_remove(tgchange_tree, target->pnode); - rb_free(target->ip); - rb_free(target); - } - } + if(target->expiry < rb_current_time()) { + rb_dlinkDelete(ptr, &tgchange_list); + rb_patricia_remove(tgchange_tree, target->pnode); + rb_free(target->ip); + rb_free(target); + } + } } /* * msg_client * - * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC + * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC * say NOTICE must not auto reply * - pointer to command, "PRIVMSG" or "NOTICE" * - pointer to source_p source (struct Client *) @@ -751,178 +686,151 @@ expire_tgchange(void *unused) */ static void msg_client(int p_or_n, const char *command, - struct Client *source_p, struct Client *target_p, const char *text) + struct Client *source_p, struct Client *target_p, const char *text) { - int do_floodcount = 0; - struct Metadata *md; - struct DictionaryIter iter; - int oaccept = 0; - char text3[10]; + int do_floodcount = 0; + struct Metadata *md; + struct DictionaryIter iter; + int oaccept = 0; + char text3[10]; - if(MyClient(source_p)) - { - /* - * XXX: Controversial? Allow target users to send replies - * through a +g. Rationale is that people can presently use +g - * as a way to taunt users, e.g. harass them and hide behind +g - * as a way of griefing. --nenolod - */ - if(p_or_n != NOTICE && MyClient(source_p) && - IsSetCallerId(source_p) && - IsSetSCallerId(source_p) && - !accept_message(target_p, source_p)) - { - if(rb_dlink_list_length(&source_p->localClient->allow_list) < - ConfigFileEntry.max_accept) - { - rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); - rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); - } - else - { - sendto_one_numeric(source_p, ERR_OWNMODE, - form_str(ERR_OWNMODE), - target_p->name, "+g"); - return; - } - } + if(MyClient(source_p)) { + /* + * XXX: Controversial? Allow target users to send replies + * through a +g. Rationale is that people can presently use +g + * as a way to taunt users, e.g. harass them and hide behind +g + * as a way of griefing. --nenolod + */ + if(p_or_n != NOTICE && MyClient(source_p) && + IsSetCallerId(source_p) && + IsSetSCallerId(source_p) && + !accept_message(target_p, source_p)) { + if(rb_dlink_list_length(&source_p->localClient->allow_list) < + ConfigFileEntry.max_accept) { + rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); + rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); + } else { + sendto_one_numeric(source_p, ERR_OWNMODE, + form_str(ERR_OWNMODE), + target_p->name, "+g"); + return; + } + } - /* reset idle time for message only if its not to self - * and its not a notice */ - if(p_or_n != NOTICE) - source_p->localClient->last = rb_current_time(); + /* reset idle time for message only if its not to self + * and its not a notice */ + if(p_or_n != NOTICE) + source_p->localClient->last = rb_current_time(); - /* auto cprivmsg/cnotice */ - do_floodcount = !IsOper(source_p) && - !find_allowing_channel(source_p, target_p); + /* auto cprivmsg/cnotice */ + do_floodcount = !IsOper(source_p) && + !find_allowing_channel(source_p, target_p); - /* target change stuff, dont limit ctcp replies as that - * would allow people to start filling up random users - * targets just by ctcping them - */ - if((p_or_n != NOTICE || *text != '\001') && - ConfigFileEntry.target_change && do_floodcount) - { - if(!add_target(source_p, target_p)) - { - sendto_one(source_p, form_str(ERR_TARGCHANGE), - me.name, source_p->name, target_p->name); - return; - } - } + /* target change stuff, dont limit ctcp replies as that + * would allow people to start filling up random users + * targets just by ctcping them + */ + if((p_or_n != NOTICE || *text != '\001') && + ConfigFileEntry.target_change && do_floodcount) { + if(!add_target(source_p, target_p)) { + sendto_one(source_p, form_str(ERR_TARGCHANGE), + me.name, source_p->name, target_p->name); + return; + } + } - if (do_floodcount && p_or_n == NOTICE && *text == '\001' && - target_p->large_ctcp_sent + LARGE_CTCP_TIME >= rb_current_time()) - do_floodcount = 0; + if (do_floodcount && p_or_n == NOTICE && *text == '\001' && + target_p->large_ctcp_sent + LARGE_CTCP_TIME >= rb_current_time()) + do_floodcount = 0; - if (do_floodcount && - flood_attack_client(p_or_n, source_p, target_p)) - return; - } - else if(source_p->from == target_p->from) - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Send message to %s[%s] dropped from %s(Fake Dir)", - target_p->name, target_p->from->name, source_p->name); - return; - } + if (do_floodcount && + flood_attack_client(p_or_n, source_p, target_p)) + return; + } else if(source_p->from == target_p->from) { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Send message to %s[%s] dropped from %s(Fake Dir)", + target_p->name, target_p->from->name, source_p->name); + return; + } - if(MyConnect(source_p) && (p_or_n != NOTICE) && target_p->user && target_p->user->away) - sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), - target_p->name, target_p->user->away); + if(MyConnect(source_p) && (p_or_n != NOTICE) && target_p->user && target_p->user->away) + sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), + target_p->name, target_p->user->away); - if(MyClient(target_p)) - { - if (IsSetNoCTCP(target_p) && p_or_n != NOTICE && *text == '\001' && strncasecmp(text + 1, "ACTION", 6)) - { - sendto_one_numeric(source_p, ERR_NOCTCP, - form_str(ERR_NOCTCP), - target_p->name); - } - /* If opers want to go through +g, they should load oaccept.*/ - else if(!IsServer(source_p) && !IsService(source_p) && (IsSetCallerId(target_p) || - (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) || - (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]))) - { - if (IsOper(source_p)) - { - rb_snprintf(text3, sizeof(text3), "O%s", source_p->id); - DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) - { - if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text3)) - { - oaccept = 1; - break; - } - } - } - /* Here is the anti-flood bot/spambot code -db */ - if(accept_message(source_p, target_p) || oaccept) - { - add_reply_target(target_p, source_p); - sendto_one(target_p, ":%s!%s@%s %s %s :%s", - source_p->name, - source_p->username, - source_p->host, command, target_p->name, text); - } - else if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) - { - if (p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NONONREG, - form_str(ERR_NONONREG), - target_p->name); - } - else if (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) - { - if (p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NOCOMMONCHAN, - form_str(ERR_NOCOMMONCHAN), - target_p->name); - } - else - { - /* check for accept, flag recipient incoming message */ - if(p_or_n != NOTICE) - { - sendto_one_numeric(source_p, ERR_TARGUMODEG, - form_str(ERR_TARGUMODEG), - target_p->name); - } + if(MyClient(target_p)) { + if (IsSetNoCTCP(target_p) && p_or_n != NOTICE && *text == '\001' && strncasecmp(text + 1, "ACTION", 6)) { + sendto_one_numeric(source_p, ERR_NOCTCP, + form_str(ERR_NOCTCP), + target_p->name); + } + /* If opers want to go through +g, they should load oaccept.*/ + else if(!IsServer(source_p) && !IsService(source_p) && (IsSetCallerId(target_p) || + (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) || + (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]))) { + if (IsOper(source_p)) { + rb_snprintf(text3, sizeof(text3), "O%s", source_p->id); + DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) { + if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text3)) { + oaccept = 1; + break; + } + } + } + /* Here is the anti-flood bot/spambot code -db */ + if(accept_message(source_p, target_p) || oaccept) { + add_reply_target(target_p, source_p); + sendto_one(target_p, ":%s!%s@%s %s %s :%s", + source_p->name, + source_p->username, + source_p->host, command, target_p->name, text); + } else if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) { + if (p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NONONREG, + form_str(ERR_NONONREG), + target_p->name); + } else if (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) { + if (p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NOCOMMONCHAN, + form_str(ERR_NOCOMMONCHAN), + target_p->name); + } else { + /* check for accept, flag recipient incoming message */ + if(p_or_n != NOTICE) { + sendto_one_numeric(source_p, ERR_TARGUMODEG, + form_str(ERR_TARGUMODEG), + target_p->name); + } - if((target_p->localClient->last_caller_id_time + - ConfigFileEntry.caller_id_wait) < rb_current_time()) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, RPL_TARGNOTIFY, - form_str(RPL_TARGNOTIFY), - target_p->name); + if((target_p->localClient->last_caller_id_time + + ConfigFileEntry.caller_id_wait) < rb_current_time()) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, RPL_TARGNOTIFY, + form_str(RPL_TARGNOTIFY), + target_p->name); - add_reply_target(target_p, source_p); - sendto_one(target_p, form_str(RPL_UMODEGMSG), - me.name, target_p->name, source_p->name, - source_p->username, source_p->host); + add_reply_target(target_p, source_p); + sendto_one(target_p, form_str(RPL_UMODEGMSG), + me.name, target_p->name, source_p->name, + source_p->username, source_p->host); - target_p->localClient->last_caller_id_time = rb_current_time(); - } - } - } - else - { - add_reply_target(target_p, source_p); - sendto_anywhere(target_p, source_p, command, ":%s", text); - } - } - else - sendto_anywhere(target_p, source_p, command, ":%s", text); + target_p->localClient->last_caller_id_time = rb_current_time(); + } + } + } else { + add_reply_target(target_p, source_p); + sendto_anywhere(target_p, source_p, command, ":%s", text); + } + } else + sendto_anywhere(target_p, source_p, command, ":%s", text); - return; + return; } /* * flood_attack_client * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC * say NOTICE must not auto reply - * - pointer to source Client + * - pointer to source Client * - pointer to target Client * output - 1 if target is under flood attack * side effects - check for flood attack on target target_p @@ -930,56 +838,50 @@ msg_client(int p_or_n, const char *command, static int flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p) { - int delta; + int delta; - /* Services could get many messages legitimately and - * can be messaged without rate limiting via aliases - * and msg user@server. - * -- jilles - */ - if(GlobalSetOptions.floodcount && IsClient(source_p) && source_p != target_p && !IsService(target_p) && (!IsOper(source_p) || !ConfigFileEntry.true_no_oper_flood)) - { - if((target_p->first_received_message_time + 1) < rb_current_time()) - { - delta = rb_current_time() - target_p->first_received_message_time; - target_p->received_number_of_privmsgs -= delta; - target_p->first_received_message_time = rb_current_time(); - if(target_p->received_number_of_privmsgs <= 0) - { - target_p->received_number_of_privmsgs = 0; - target_p->flood_noticed = 0; - } - } + /* Services could get many messages legitimately and + * can be messaged without rate limiting via aliases + * and msg user@server. + * -- jilles + */ + if(GlobalSetOptions.floodcount && IsClient(source_p) && source_p != target_p && !IsService(target_p) && (!IsOper(source_p) || !ConfigFileEntry.true_no_oper_flood)) { + if((target_p->first_received_message_time + 1) < rb_current_time()) { + delta = rb_current_time() - target_p->first_received_message_time; + target_p->received_number_of_privmsgs -= delta; + target_p->first_received_message_time = rb_current_time(); + if(target_p->received_number_of_privmsgs <= 0) { + target_p->received_number_of_privmsgs = 0; + target_p->flood_noticed = 0; + } + } - if((target_p->received_number_of_privmsgs >= - GlobalSetOptions.floodcount) || target_p->flood_noticed) - { - if(target_p->flood_noticed == 0) - { - sendto_realops_snomask(SNO_BOTS, L_NETWIDE, - "Possible Flooder %s[%s@%s] on %s target: %s", - source_p->name, source_p->username, - source_p->orighost, - source_p->servptr->name, target_p->name); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s ENCAP * SNOTE b :Possible Flooder %s[%s@%s] on %s target: %s", - me.id, source_p->name, source_p->username, source_p->orighost, - source_p->servptr->name, target_p->name); - target_p->flood_noticed = 1; - /* add a bit of penalty */ - target_p->received_number_of_privmsgs += 2; - } - if(MyClient(source_p) && (p_or_n != NOTICE)) - sendto_one(source_p, - ":%s NOTICE %s :*** Message to %s throttled due to flooding", - me.name, source_p->name, target_p->name); - return 1; - } - else - target_p->received_number_of_privmsgs++; - } + if((target_p->received_number_of_privmsgs >= + GlobalSetOptions.floodcount) || target_p->flood_noticed) { + if(target_p->flood_noticed == 0) { + sendto_realops_snomask(SNO_BOTS, L_NETWIDE, + "Possible Flooder %s[%s@%s] on %s target: %s", + source_p->name, source_p->username, + source_p->orighost, + source_p->servptr->name, target_p->name); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s ENCAP * SNOTE b :Possible Flooder %s[%s@%s] on %s target: %s", + me.id, source_p->name, source_p->username, source_p->orighost, + source_p->servptr->name, target_p->name); + target_p->flood_noticed = 1; + /* add a bit of penalty */ + target_p->received_number_of_privmsgs += 2; + } + if(MyClient(source_p) && (p_or_n != NOTICE)) + sendto_one(source_p, + ":%s NOTICE %s :*** Message to %s throttled due to flooding", + me.name, source_p->name, target_p->name); + return 1; + } else + target_p->received_number_of_privmsgs++; + } - return 0; + return 0; } /* @@ -1000,109 +902,98 @@ flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p */ static void handle_special(int p_or_n, const char *command, struct Client *client_p, - struct Client *source_p, const char *nick, const char *text) + struct Client *source_p, const char *nick, const char *text) { - struct Client *target_p; - char *server; - char *s; + struct Client *target_p; + char *server; + char *s; - /* user[%host]@server addressed? - * NOTE: users can send to user@server, but not user%host@server - * or opers@server - */ - if((server = strchr(nick, '@')) != NULL) - { - if((target_p = find_server(source_p, server + 1)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), server + 1); - return; - } + /* user[%host]@server addressed? + * NOTE: users can send to user@server, but not user%host@server + * or opers@server + */ + if((server = strchr(nick, '@')) != NULL) { + if((target_p = find_server(source_p, server + 1)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), server + 1); + return; + } - if(!IsOper(source_p)) - { - if(strchr(nick, '%') || (strncmp(nick, "opers", 5) == 0)) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); - return; - } - } + if(!IsOper(source_p)) { + if(strchr(nick, '%') || (strncmp(nick, "opers", 5) == 0)) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); + return; + } + } - /* somewhere else.. */ - if(!IsMe(target_p)) - { - sendto_one(target_p, ":%s %s %s :%s", - get_id(source_p, target_p), command, nick, text); - return; - } + /* somewhere else.. */ + if(!IsMe(target_p)) { + sendto_one(target_p, ":%s %s %s :%s", + get_id(source_p, target_p), command, nick, text); + return; + } - /* Check if someones msg'ing opers@our.server */ - if(strncmp(nick, "opers@", 6) == 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "To opers: From: %s: %s", - source_p->name, text); - return; - } + /* Check if someones msg'ing opers@our.server */ + if(strncmp(nick, "opers@", 6) == 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "To opers: From: %s: %s", + source_p->name, text); + return; + } - /* This was not very useful except for bypassing certain - * restrictions. Note that we still allow sending to - * remote servers this way, for messaging pseudoservers - * securely whether they have a service{} block or not. - * -- jilles - */ - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); - return; - } + /* This was not very useful except for bypassing certain + * restrictions. Note that we still allow sending to + * remote servers this way, for messaging pseudoservers + * securely whether they have a service{} block or not. + * -- jilles + */ + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); + return; + } - /* - * the following two cases allow masks in NOTICEs - * (for OPERs only) - * - * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de) - */ - if(IsOper(source_p) && *nick == '$') - { - if((*(nick + 1) == '$' || *(nick + 1) == '#')) - nick++; - else if(MyOper(source_p)) - { - sendto_one(source_p, - ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s", - me.name, source_p->name, command, nick, nick); - return; - } + /* + * the following two cases allow masks in NOTICEs + * (for OPERs only) + * + * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de) + */ + if(IsOper(source_p) && *nick == '$') { + if((*(nick + 1) == '$' || *(nick + 1) == '#')) + nick++; + else if(MyOper(source_p)) { + sendto_one(source_p, + ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s", + me.name, source_p->name, command, nick, nick); + return; + } - if(MyClient(source_p) && !IsOperMassNotice(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "mass_notice"); - return; - } + if(MyClient(source_p) && !IsOperMassNotice(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "mass_notice"); + return; + } - if((s = strrchr(nick, '.')) == NULL) - { - sendto_one_numeric(source_p, ERR_NOTOPLEVEL, - form_str(ERR_NOTOPLEVEL), nick); - return; - } - while(*++s) - if(*s == '.' || *s == '*' || *s == '?') - break; - if(*s == '*' || *s == '?') - { - sendto_one_numeric(source_p, ERR_WILDTOPLEVEL, - form_str(ERR_WILDTOPLEVEL), nick); - return; - } + if((s = strrchr(nick, '.')) == NULL) { + sendto_one_numeric(source_p, ERR_NOTOPLEVEL, + form_str(ERR_NOTOPLEVEL), nick); + return; + } + while(*++s) + if(*s == '.' || *s == '*' || *s == '?') + break; + if(*s == '*' || *s == '?') { + sendto_one_numeric(source_p, ERR_WILDTOPLEVEL, + form_str(ERR_WILDTOPLEVEL), nick); + return; + } - sendto_match_butone(IsServer(client_p) ? client_p : NULL, source_p, - nick + 1, - (*nick == '#') ? MATCH_HOST : MATCH_SERVER, - "%s $%s :%s", command, nick, text); - if (p_or_n != NOTICE && *text == '\001') - source_p->large_ctcp_sent = rb_current_time(); - return; - } + sendto_match_butone(IsServer(client_p) ? client_p : NULL, source_p, + nick + 1, + (*nick == '#') ? MATCH_HOST : MATCH_SERVER, + "%s $%s :%s", command, nick, text); + if (p_or_n != NOTICE && *text == '\001') + source_p->large_ctcp_sent = rb_current_time(); + return; + } } diff --git a/modules/core/m_metadata.c b/modules/core/m_metadata.c index 47925de..8c4274d 100644 --- a/modules/core/m_metadata.c +++ b/modules/core/m_metadata.c @@ -20,12 +20,12 @@ static int me_metadata(struct Client *, struct Client *, int, const char **); struct Message metadata_msgtab = { - "METADATA", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_metadata, 3}, mg_ignore} + "METADATA", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_metadata, 3}, mg_ignore} }; mapi_clist_av1 metadata_clist[] = { - &metadata_msgtab, NULL + &metadata_msgtab, NULL }; DECLARE_MODULE_AV1(metadata, NULL, NULL, metadata_clist, NULL, NULL, "$Revision$"); @@ -38,47 +38,45 @@ DECLARE_MODULE_AV1(metadata, NULL, NULL, metadata_clist, NULL, NULL, "$Revision$ static int me_metadata(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parv[2][0] == '#') - { - struct Channel *chptr; + if(parv[2][0] == '#') { + struct Channel *chptr; - if((chptr = find_channel(parv[2])) == NULL) - return 0; + if((chptr = find_channel(parv[2])) == NULL) + return 0; - //XXX need to support the old, nonstandard verbs for compatability reasons - if(!strcmp(parv[1], "ADD") && parv[4] != NULL) - channel_metadata_add(chptr, parv[3], parv[4], 0); - if(!strcmp(parv[1], "DELETE") && parv[3] != NULL) - channel_metadata_delete(chptr, parv[3], 0); + //XXX need to support the old, nonstandard verbs for compatability reasons + if(!strcmp(parv[1], "ADD") && parv[4] != NULL) + channel_metadata_add(chptr, parv[3], parv[4], 0); + if(!strcmp(parv[1], "DELETE") && parv[3] != NULL) + channel_metadata_delete(chptr, parv[3], 0); - //Now moving on to the standard ones - if(!strcmp(parv[1], "SET") && parv[4] != NULL) - channel_metadata_add(chptr, parv[3], parv[4], 0); - if(!strcmp(parv[1], "CLEAR") && parv[3] != NULL) - channel_metadata_delete(chptr, parv[3], 0); - } + //Now moving on to the standard ones + if(!strcmp(parv[1], "SET") && parv[4] != NULL) + channel_metadata_add(chptr, parv[3], parv[4], 0); + if(!strcmp(parv[1], "CLEAR") && parv[3] != NULL) + channel_metadata_delete(chptr, parv[3], 0); + } - else - { - struct Client *target_p; + else { + struct Client *target_p; - if((target_p = find_id(parv[2])) == NULL) - return 0; + if((target_p = find_id(parv[2])) == NULL) + return 0; - if(!target_p->user) - return 0; + if(!target_p->user) + return 0; - //XXX need to support the old, nonstandard verbs for compatability reasons - if(!strcmp(parv[1], "ADD") && parv[4] != NULL) - user_metadata_add(target_p, parv[3], parv[4], 0); - if(!strcmp(parv[1], "DELETE") && parv[3] != NULL) - user_metadata_delete(target_p, parv[3], 0); + //XXX need to support the old, nonstandard verbs for compatability reasons + if(!strcmp(parv[1], "ADD") && parv[4] != NULL) + user_metadata_add(target_p, parv[3], parv[4], 0); + if(!strcmp(parv[1], "DELETE") && parv[3] != NULL) + user_metadata_delete(target_p, parv[3], 0); - //Now moving on to the standard ones - if(!strcmp(parv[1], "SET") && parv[4] != NULL) - user_metadata_add(target_p, parv[3], parv[4], 0); - if(!strcmp(parv[1], "CLEAR") && parv[3] != NULL) - user_metadata_delete(target_p, parv[3], 0); - } - return 0; + //Now moving on to the standard ones + if(!strcmp(parv[1], "SET") && parv[4] != NULL) + user_metadata_add(target_p, parv[3], parv[4], 0); + if(!strcmp(parv[1], "CLEAR") && parv[3] != NULL) + user_metadata_delete(target_p, parv[3], 0); + } + return 0; } diff --git a/modules/core/m_mode.c b/modules/core/m_mode.c index fd1b183..13beb1c 100644 --- a/modules/core/m_mode.c +++ b/modules/core/m_mode.c @@ -48,20 +48,20 @@ static int ms_mlock(struct Client *, struct Client *, int, const char **); static int ms_bmask(struct Client *, struct Client *, int, const char **); struct Message mode_msgtab = { - "MODE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}} + "MODE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}} }; struct Message tmode_msgtab = { - "TMODE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore} + "TMODE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore} }; struct Message mlock_msgtab = { - "MLOCK", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore} + "MLOCK", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore} }; struct Message bmask_msgtab = { - "BMASK", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore} + "BMASK", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore} }; mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL }; @@ -75,321 +75,296 @@ DECLARE_MODULE_AV1(mode, NULL, NULL, mode_clist, NULL, NULL, "$Revision: 1006 $" static int m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr = NULL; - struct membership *msptr; - int n = 2; - const char *dest; - int operspy = 0; + struct Channel *chptr = NULL; + struct membership *msptr; + int n = 2; + const char *dest; + int operspy = 0; - dest = parv[1]; + dest = parv[1]; - if(IsOperSpy(source_p) && *dest == '!') - { - dest++; - operspy = 1; + if(IsOperSpy(source_p) && *dest == '!') { + dest++; + operspy = 1; - if(EmptyString(dest)) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "MODE"); - return 0; - } - } + if(EmptyString(dest)) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "MODE"); + return 0; + } + } - /* Now, try to find the channel in question */ - if(!IsChanPrefix(*dest)) - { - /* if here, it has to be a non-channel name */ - user_mode(client_p, source_p, parc, parv); - return 0; - } + /* Now, try to find the channel in question */ + if(!IsChanPrefix(*dest)) { + /* if here, it has to be a non-channel name */ + user_mode(client_p, source_p, parc, parv); + return 0; + } - if(!check_channel_name(dest)) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]); - return 0; - } + if(!check_channel_name(dest)) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]); + return 0; + } - chptr = find_channel(dest); + chptr = find_channel(dest); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[1]); - return 0; - } + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[1]); + return 0; + } - /* Now know the channel exists */ - if(parc < n + 1) - { - if(operspy) - report_operspy(source_p, "MODE", chptr->chname); + /* Now know the channel exists */ + if(parc < n + 1) { + if(operspy) + report_operspy(source_p, "MODE", chptr->chname); - sendto_one(source_p, form_str(RPL_CHANNELMODEIS), - me.name, source_p->name, parv[1], - operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p)); + sendto_one(source_p, form_str(RPL_CHANNELMODEIS), + me.name, source_p->name, parv[1], + operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p)); - sendto_one(source_p, form_str(RPL_CREATIONTIME), - me.name, source_p->name, parv[1], chptr->channelts); - } - else - { - msptr = find_channel_membership(chptr, source_p); + sendto_one(source_p, form_str(RPL_CREATIONTIME), + me.name, source_p->name, parv[1], chptr->channelts); + } else { + msptr = find_channel_membership(chptr, source_p); - /* Finish the flood grace period... */ - if(MyClient(source_p) && !IsFloodDone(source_p)) - { - if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0'))) - flood_endgrace(source_p); - } + /* Finish the flood grace period... */ + if(MyClient(source_p) && !IsFloodDone(source_p)) { + if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0'))) + flood_endgrace(source_p); + } - set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n); - } + set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n); + } - return 0; + return 0; } static int ms_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; + struct Channel *chptr; - chptr = find_channel(parv[1]); + chptr = find_channel(parv[1]); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[1]); - return 0; - } + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[1]); + return 0; + } - set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2); + set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2); - return 0; + return 0; } static int ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr = NULL; - struct membership *msptr; + struct Channel *chptr = NULL; + struct membership *msptr; - /* Now, try to find the channel in question */ - if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); - return 0; - } + /* Now, try to find the channel in question */ + if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); + return 0; + } - chptr = find_channel(parv[2]); + chptr = find_channel(parv[2]); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[2]); - return 0; - } + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[2]); + return 0; + } - /* TS is higher, drop it. */ - if(atol(parv[1]) > chptr->channelts) - return 0; + /* TS is higher, drop it. */ + if(atol(parv[1]) > chptr->channelts) + return 0; - if(IsServer(source_p)) - { - set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3); - } - else - { - msptr = find_channel_membership(chptr, source_p); + if(IsServer(source_p)) { + set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3); + } else { + msptr = find_channel_membership(chptr, source_p); - set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3); - } + set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3); + } - return 0; + return 0; } static int ms_mlock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr = NULL; + struct Channel *chptr = NULL; - /* Now, try to find the channel in question */ - if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); - return 0; - } + /* Now, try to find the channel in question */ + if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); + return 0; + } - chptr = find_channel(parv[2]); + chptr = find_channel(parv[2]); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[2]); - return 0; - } + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[2]); + return 0; + } - /* TS is higher, drop it. */ - if(atol(parv[1]) > chptr->channelts) - return 0; + /* TS is higher, drop it. */ + if(atol(parv[1]) > chptr->channelts) + return 0; - if(IsServer(source_p)) - set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE); + if(IsServer(source_p)) + set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE); - return 0; + return 0; } static int ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static char modebuf[BUFSIZE]; - static char parabuf[BUFSIZE]; - struct Channel *chptr; - rb_dlink_list *banlist; - const char *s; - char *t; - char *mbuf; - char *pbuf; - long mode_type; - int mlen; - int plen = 0; - int tlen; - int arglen; - int modecount = 0; - int needcap = NOCAPS; - int mems; - struct Client *fakesource_p; + static char modebuf[BUFSIZE]; + static char parabuf[BUFSIZE]; + struct Channel *chptr; + rb_dlink_list *banlist; + const char *s; + char *t; + char *mbuf; + char *pbuf; + long mode_type; + int mlen; + int plen = 0; + int tlen; + int arglen; + int modecount = 0; + int needcap = NOCAPS; + int mems; + struct Client *fakesource_p; - if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) - return 0; + if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) + return 0; - if((chptr = find_channel(parv[2])) == NULL) - return 0; + if((chptr = find_channel(parv[2])) == NULL) + return 0; - /* TS is higher, drop it. */ - if(atol(parv[1]) > chptr->channelts) - return 0; + /* TS is higher, drop it. */ + if(atol(parv[1]) > chptr->channelts) + return 0; - switch (parv[3][0]) - { - case 'b': - banlist = &chptr->banlist; - mode_type = CHFL_BAN; - mems = ALL_MEMBERS; - break; + switch (parv[3][0]) { + case 'b': + banlist = &chptr->banlist; + mode_type = CHFL_BAN; + mems = ALL_MEMBERS; + break; - case 'e': - banlist = &chptr->exceptlist; - mode_type = CHFL_EXCEPTION; - needcap = CAP_EX; - mems = ONLY_CHANOPS; - break; + case 'e': + banlist = &chptr->exceptlist; + mode_type = CHFL_EXCEPTION; + needcap = CAP_EX; + mems = ONLY_CHANOPS; + break; - case 'I': - banlist = &chptr->invexlist; - mode_type = CHFL_INVEX; - needcap = CAP_IE; - mems = ONLY_CHANOPS; - break; + case 'I': + banlist = &chptr->invexlist; + mode_type = CHFL_INVEX; + needcap = CAP_IE; + mems = ONLY_CHANOPS; + break; - case 'q': - banlist = &chptr->quietlist; - mode_type = CHFL_QUIET; - mems = ALL_MEMBERS; - break; + case 'q': + banlist = &chptr->quietlist; + mode_type = CHFL_QUIET; + mems = ALL_MEMBERS; + break; - /* maybe we should just blindly propagate this? */ - default: - return 0; - } + /* maybe we should just blindly propagate this? */ + default: + return 0; + } - parabuf[0] = '\0'; - s = LOCAL_COPY(parv[4]); + parabuf[0] = '\0'; + s = LOCAL_COPY(parv[4]); - /* Hide connecting server on netburst -- jilles */ - if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) - fakesource_p = &me; - else - fakesource_p = source_p; - mlen = rb_sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname); - mbuf = modebuf + mlen; - pbuf = parabuf; + /* Hide connecting server on netburst -- jilles */ + if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) + fakesource_p = &me; + else + fakesource_p = source_p; + mlen = rb_sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname); + mbuf = modebuf + mlen; + pbuf = parabuf; - while(*s == ' ') - s++; + while(*s == ' ') + s++; - /* next char isnt a space, point t to the next one */ - if((t = strchr(s, ' ')) != NULL) - { - *t++ = '\0'; + /* next char isnt a space, point t to the next one */ + if((t = strchr(s, ' ')) != NULL) { + *t++ = '\0'; - /* double spaces will break the parser */ - while(*t == ' ') - t++; - } + /* double spaces will break the parser */ + while(*t == ' ') + t++; + } - /* couldve skipped spaces and got nothing.. */ - while(!EmptyString(s)) - { - /* ban with a leading ':' -- this will break the protocol */ - if(*s == ':') - goto nextban; + /* couldve skipped spaces and got nothing.. */ + while(!EmptyString(s)) { + /* ban with a leading ':' -- this will break the protocol */ + if(*s == ':') + goto nextban; - tlen = strlen(s); + tlen = strlen(s); - /* I dont even want to begin parsing this.. */ - if(tlen > MODEBUFLEN) - break; + /* I dont even want to begin parsing this.. */ + if(tlen > MODEBUFLEN) + break; - if(add_id(fakesource_p, chptr, s, banlist, mode_type)) - { - /* this new one wont fit.. */ - if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 || - modecount >= MAXMODEPARAMS) - { - *mbuf = '\0'; - *(pbuf - 1) = '\0'; - sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); - sendto_server(client_p, chptr, needcap, CAP_TS6, - "%s %s", modebuf, parabuf); + if(add_id(fakesource_p, chptr, s, banlist, mode_type)) { + /* this new one wont fit.. */ + if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 || + modecount >= MAXMODEPARAMS) { + *mbuf = '\0'; + *(pbuf - 1) = '\0'; + sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); + sendto_server(client_p, chptr, needcap, CAP_TS6, + "%s %s", modebuf, parabuf); - mbuf = modebuf + mlen; - pbuf = parabuf; - plen = modecount = 0; - } + mbuf = modebuf + mlen; + pbuf = parabuf; + plen = modecount = 0; + } - *mbuf++ = parv[3][0]; - arglen = rb_sprintf(pbuf, "%s ", s); - pbuf += arglen; - plen += arglen; - modecount++; - } + *mbuf++ = parv[3][0]; + arglen = rb_sprintf(pbuf, "%s ", s); + pbuf += arglen; + plen += arglen; + modecount++; + } - nextban: - s = t; +nextban: + s = t; - if(s != NULL) - { - if((t = strchr(s, ' ')) != NULL) - { - *t++ = '\0'; + if(s != NULL) { + if((t = strchr(s, ' ')) != NULL) { + *t++ = '\0'; - while(*t == ' ') - t++; - } - } - } + while(*t == ' ') + t++; + } + } + } - if(modecount) - { - *mbuf = '\0'; - *(pbuf - 1) = '\0'; - sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); - sendto_server(client_p, chptr, needcap, CAP_TS6, "%s %s", modebuf, parabuf); - } + if(modecount) { + *mbuf = '\0'; + *(pbuf - 1) = '\0'; + sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); + sendto_server(client_p, chptr, needcap, CAP_TS6, "%s %s", modebuf, parabuf); + } - sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s", - source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]); - return 0; + sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s", + source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]); + return 0; } diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index 87b3c10..561905c 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -66,29 +66,30 @@ static void save_user(struct Client *, struct Client *, struct Client *); static void bad_nickname(struct Client *, const char *); struct Message nick_msgtab = { - "NICK", 0, 0, 0, MFLG_SLOW, - {{mr_nick, 0}, {m_nick, 0}, {mc_nick, 3}, {ms_nick, 0}, mg_ignore, {m_nick, 0}} + "NICK", 0, 0, 0, MFLG_SLOW, + {{mr_nick, 0}, {m_nick, 0}, {mc_nick, 3}, {ms_nick, 0}, mg_ignore, {m_nick, 0}} }; struct Message uid_msgtab = { - "UID", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, {ms_uid, 9}, mg_ignore, mg_ignore} + "UID", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, {ms_uid, 9}, mg_ignore, mg_ignore} }; struct Message euid_msgtab = { - "EUID", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, {ms_euid, 12}, mg_ignore, mg_ignore} + "EUID", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, {ms_euid, 12}, mg_ignore, mg_ignore} }; struct Message save_msgtab = { - "SAVE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, {ms_save, 3}, mg_ignore, mg_ignore} + "SAVE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, {ms_save, 3}, mg_ignore, mg_ignore} }; mapi_clist_av1 nick_clist[] = { &nick_msgtab, &uid_msgtab, &euid_msgtab, - &save_msgtab, NULL }; + &save_msgtab, NULL + }; DECLARE_MODULE_AV1(nick, NULL, NULL, nick_clist, NULL, NULL, "$Revision: 3518 $"); static int change_remote_nick(struct Client *, struct Client *, time_t, - const char *, int); + const char *, int); static int clean_nick(const char *, int loc_client); static int clean_username(const char *); @@ -98,13 +99,13 @@ static int clean_uid(const char *uid); static void set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick); static void change_local_nick(struct Client *client_p, struct Client *source_p, char *nick, int); static int register_client(struct Client *client_p, struct Client *server, - const char *nick, time_t newts, int parc, const char *parv[]); + const char *nick, time_t newts, int parc, const char *parv[]); static int perform_nick_collides(struct Client *, struct Client *, - struct Client *, int, const char **, - time_t, const char *, const char *); + struct Client *, int, const char **, + time_t, const char *, const char *); static int perform_nickchange_collides(struct Client *, struct Client *, - struct Client *, int, const char **, time_t, const char *); + struct Client *, int, const char **, time_t, const char *); /* mr_nick() * parv[1] = nickname @@ -112,56 +113,51 @@ static int perform_nickchange_collides(struct Client *, struct Client *, static int mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - char nick[NICKLEN]; + struct Client *target_p; + char nick[NICKLEN]; - if (strlen(client_p->id) == 3) - { - exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); - return 0; - } + if (strlen(client_p->id) == 3) { + exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); + return 0; + } - if(parc < 2 || EmptyString(parv[1])) - { - sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), - me.name, EmptyString(source_p->name) ? "*" : source_p->name); - return 0; - } + if(parc < 2 || EmptyString(parv[1])) { + sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), + me.name, EmptyString(source_p->name) ? "*" : source_p->name); + return 0; + } - /* copy the nick and terminate it */ - rb_strlcpy(nick, parv[1], sizeof(nick)); + /* copy the nick and terminate it */ + rb_strlcpy(nick, parv[1], sizeof(nick)); - /* check the nickname is ok */ - if(!clean_nick(nick, 1)) - { - sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), - me.name, EmptyString(source_p->name) ? "*" : source_p->name, parv[1]); - return 0; - } + /* check the nickname is ok */ + if(!clean_nick(nick, 1)) { + sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), + me.name, EmptyString(source_p->name) ? "*" : source_p->name, parv[1]); + return 0; + } - /* check if the nick is resv'd */ - if(find_nick_resv(nick)) - { - sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), - me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); - return 0; - } + /* check if the nick is resv'd */ + if(find_nick_resv(nick)) { + sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), + me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); + return 0; + } - if(irc_dictionary_find(nd_dict, nick)) - { - sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), - me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); - return 0; - } + if(irc_dictionary_find(nd_dict, nick)) { + sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), + me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); + return 0; + } - if((target_p = find_named_client(nick)) == NULL) - set_initial_nick(client_p, source_p, nick); - else if(source_p == target_p) - strcpy(source_p->name, nick); - else - sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick); + if((target_p = find_named_client(nick)) == NULL) + set_initial_nick(client_p, source_p, nick); + else if(source_p == target_p) + strcpy(source_p->name, nick); + else + sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick); - return 0; + return 0; } /* m_nick() @@ -170,74 +166,65 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char * static int m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - char nick[NICKLEN]; + struct Client *target_p; + char nick[NICKLEN]; - if(parc < 2 || EmptyString(parv[1])) - { - sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name); - return 0; - } + if(parc < 2 || EmptyString(parv[1])) { + sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name); + return 0; + } - /* mark end of grace period, to prevent nickflooding */ - if(!IsFloodDone(source_p)) - flood_endgrace(source_p); + /* mark end of grace period, to prevent nickflooding */ + if(!IsFloodDone(source_p)) + flood_endgrace(source_p); - /* terminate nick to NICKLEN, we dont want clean_nick() to error! */ - rb_strlcpy(nick, parv[1], sizeof(nick)); + /* terminate nick to NICKLEN, we dont want clean_nick() to error! */ + rb_strlcpy(nick, parv[1], sizeof(nick)); - /* check the nickname is ok */ - if(!clean_nick(nick, 1)) - { - sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); - return 0; - } + /* check the nickname is ok */ + if(!clean_nick(nick, 1)) { + sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); + return 0; + } - if(!IsExemptResv(source_p) && find_nick_resv(nick)) - { - sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); - return 0; - } + if(!IsExemptResv(source_p) && find_nick_resv(nick)) { + sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); + return 0; + } - if(irc_dictionary_find(nd_dict, nick)) - { - sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), - me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); - return 0; - } + if(irc_dictionary_find(nd_dict, nick)) { + sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), + me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); + return 0; + } - if((target_p = find_named_client(nick))) - { - /* If(target_p == source_p) the client is changing nicks between - * equivalent nicknames ie: [nick] -> {nick} - */ - if(target_p == source_p) - { - /* check the nick isnt exactly the same */ - if(strcmp(target_p->name, nick)) - change_local_nick(client_p, source_p, nick, 1); + if((target_p = find_named_client(nick))) { + /* If(target_p == source_p) the client is changing nicks between + * equivalent nicknames ie: [nick] -> {nick} + */ + if(target_p == source_p) { + /* check the nick isnt exactly the same */ + if(strcmp(target_p->name, nick)) + change_local_nick(client_p, source_p, nick, 1); - } + } - /* drop unregged client */ - else if(IsUnknown(target_p)) - { - exit_client(NULL, target_p, &me, "Overridden"); - change_local_nick(client_p, source_p, nick, 1); - } - else - sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, source_p->name, nick); + /* drop unregged client */ + else if(IsUnknown(target_p)) { + exit_client(NULL, target_p, &me, "Overridden"); + change_local_nick(client_p, source_p, nick, 1); + } else + sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, source_p->name, nick); - return 0; - } - else - change_local_nick(client_p, source_p, nick, 1); + return 0; + } else + change_local_nick(client_p, source_p, nick, 1); - return 0; + return 0; } /* mc_nick() - * + * * server -> server nick change * parv[1] = nickname * parv[2] = TS when nick change @@ -245,63 +232,57 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p static int mc_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - time_t newts = 0; + struct Client *target_p; + time_t newts = 0; - /* if nicks erroneous, or too long, kill */ - if(!clean_nick(parv[1], 0)) - { - bad_nickname(client_p, parv[1]); - return 0; - } + /* if nicks erroneous, or too long, kill */ + if(!clean_nick(parv[1], 0)) { + bad_nickname(client_p, parv[1]); + return 0; + } - newts = atol(parv[2]); - target_p = find_named_client(parv[1]); + newts = atol(parv[2]); + target_p = find_named_client(parv[1]); - /* if the nick doesnt exist, allow it and process like normal */ - if(target_p == NULL) - { - change_remote_nick(client_p, source_p, newts, parv[1], 1); - } - else if(IsUnknown(target_p)) - { - exit_client(NULL, target_p, &me, "Overridden"); - change_remote_nick(client_p, source_p, newts, parv[1], 1); - } - else if(target_p == source_p) - { - /* client changing case of nick */ - if(strcmp(target_p->name, parv[1])) - change_remote_nick(client_p, source_p, newts, parv[1], 1); - } - /* we've got a collision! */ - else - perform_nickchange_collides(source_p, client_p, target_p, - parc, parv, newts, parv[1]); + /* if the nick doesnt exist, allow it and process like normal */ + if(target_p == NULL) { + change_remote_nick(client_p, source_p, newts, parv[1], 1); + } else if(IsUnknown(target_p)) { + exit_client(NULL, target_p, &me, "Overridden"); + change_remote_nick(client_p, source_p, newts, parv[1], 1); + } else if(target_p == source_p) { + /* client changing case of nick */ + if(strcmp(target_p->name, parv[1])) + change_remote_nick(client_p, source_p, newts, parv[1], 1); + } + /* we've got a collision! */ + else + perform_nickchange_collides(source_p, client_p, target_p, + parc, parv, newts, parv[1]); - return 0; + return 0; } static int ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *nick, *server; + const char *nick, *server; - nick = parc > 1 ? parv[1] : "?"; - server = parc > 7 ? parv[7] : "?"; + nick = parc > 1 ? parv[1] : "?"; + server = parc > 7 ? parv[7] : "?"; - sendto_wallops_flags(UMODE_WALLOP, &me, - "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", - client_p->name, nick, server); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", - me.id, client_p->name, nick, server); - ilog(L_SERVER, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", - client_p->name, nick, server); + sendto_wallops_flags(UMODE_WALLOP, &me, + "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", + client_p->name, nick, server); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", + me.id, client_p->name, nick, server); + ilog(L_SERVER, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", + client_p->name, nick, server); - exit_client(client_p, client_p, &me, "TS5 nickname introduced"); + exit_client(client_p, client_p, &me, "TS5 nickname introduced"); - return 0; + return 0; } /* ms_uid() @@ -318,79 +299,71 @@ ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - time_t newts = 0; - char squitreason[120]; + struct Client *target_p; + time_t newts = 0; + char squitreason[120]; - newts = atol(parv[3]); + newts = atol(parv[3]); - if(parc != 10) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Dropping server %s due to (invalid) command 'UID' " - "with %d arguments (expecting 10)", client_p->name, parc); - ilog(L_SERVER, "Excess parameters (%d) for command 'UID' from %s.", - parc, client_p->name); - rb_snprintf(squitreason, sizeof squitreason, - "Excess parameters (%d) to %s command, expecting %d", - parc, "UID", 10); - exit_client(client_p, client_p, client_p, squitreason); - return 0; - } + if(parc != 10) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Dropping server %s due to (invalid) command 'UID' " + "with %d arguments (expecting 10)", client_p->name, parc); + ilog(L_SERVER, "Excess parameters (%d) for command 'UID' from %s.", + parc, client_p->name); + rb_snprintf(squitreason, sizeof squitreason, + "Excess parameters (%d) to %s command, expecting %d", + parc, "UID", 10); + exit_client(client_p, client_p, client_p, squitreason); + return 0; + } - /* if nicks erroneous, or too long, kill */ - if(!clean_nick(parv[1], 0)) - { - bad_nickname(client_p, parv[1]); - return 0; - } + /* if nicks erroneous, or too long, kill */ + if(!clean_nick(parv[1], 0)) { + bad_nickname(client_p, parv[1]); + return 0; + } - if(!clean_uid(parv[8])) - { - rb_snprintf(squitreason, sizeof squitreason, - "Invalid UID %s for nick %s on %s", - parv[8], parv[1], source_p->name); - exit_client(client_p, client_p, client_p, squitreason); - return 0; - } + if(!clean_uid(parv[8])) { + rb_snprintf(squitreason, sizeof squitreason, + "Invalid UID %s for nick %s on %s", + parv[8], parv[1], source_p->name); + exit_client(client_p, client_p, client_p, squitreason); + return 0; + } - if(!clean_username(parv[5]) || !clean_host(parv[6])) - { - ServerStats.is_kill++; - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Bad user@host: %s@%s From: %s(via %s)", - parv[5], parv[6], source_p->name, client_p->name); - sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); - return 0; - } + if(!clean_username(parv[5]) || !clean_host(parv[6])) { + ServerStats.is_kill++; + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Bad user@host: %s@%s From: %s(via %s)", + parv[5], parv[6], source_p->name, client_p->name); + sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); + return 0; + } - /* check length of clients gecos */ - if(strlen(parv[9]) > REALLEN) - { - char *s = LOCAL_COPY(parv[9]); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", - source_p->name, parv[1]); - s[REALLEN] = '\0'; - parv[9] = s; - } + /* check length of clients gecos */ + if(strlen(parv[9]) > REALLEN) { + char *s = LOCAL_COPY(parv[9]); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", + source_p->name, parv[1]); + s[REALLEN] = '\0'; + parv[9] = s; + } - target_p = find_named_client(parv[1]); + target_p = find_named_client(parv[1]); - if(target_p == NULL) - { - register_client(client_p, source_p, parv[1], newts, parc, parv); - } - else if(IsUnknown(target_p)) - { - exit_client(NULL, target_p, &me, "Overridden"); - register_client(client_p, source_p, parv[1], newts, parc, parv); - } - /* we've got a collision! */ - else - perform_nick_collides(source_p, client_p, target_p, parc, parv, - newts, parv[1], parv[8]); + if(target_p == NULL) { + register_client(client_p, source_p, parv[1], newts, parc, parv); + } else if(IsUnknown(target_p)) { + exit_client(NULL, target_p, &me, "Overridden"); + register_client(client_p, source_p, parv[1], newts, parc, parv); + } + /* we've got a collision! */ + else + perform_nick_collides(source_p, client_p, target_p, parc, parv, + newts, parv[1], parv[8]); - return 0; + return 0; } /* ms_euid() @@ -409,89 +382,80 @@ ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *p static int ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - time_t newts = 0; - char squitreason[120]; + struct Client *target_p; + time_t newts = 0; + char squitreason[120]; - newts = atol(parv[3]); + newts = atol(parv[3]); - if(parc != 12) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Dropping server %s due to (invalid) command 'EUID' " - "with %d arguments (expecting 12)", client_p->name, parc); - ilog(L_SERVER, "Excess parameters (%d) for command 'EUID' from %s.", - parc, client_p->name); - rb_snprintf(squitreason, sizeof squitreason, - "Excess parameters (%d) to %s command, expecting %d", - parc, "EUID", 12); - exit_client(client_p, client_p, client_p, squitreason); - return 0; - } + if(parc != 12) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Dropping server %s due to (invalid) command 'EUID' " + "with %d arguments (expecting 12)", client_p->name, parc); + ilog(L_SERVER, "Excess parameters (%d) for command 'EUID' from %s.", + parc, client_p->name); + rb_snprintf(squitreason, sizeof squitreason, + "Excess parameters (%d) to %s command, expecting %d", + parc, "EUID", 12); + exit_client(client_p, client_p, client_p, squitreason); + return 0; + } - /* if nicks erroneous, or too long, kill */ - if(!clean_nick(parv[1], 0)) - { - bad_nickname(client_p, parv[1]); - return 0; - } + /* if nicks erroneous, or too long, kill */ + if(!clean_nick(parv[1], 0)) { + bad_nickname(client_p, parv[1]); + return 0; + } - if(!clean_uid(parv[8])) - { - rb_snprintf(squitreason, sizeof squitreason, - "Invalid UID %s for nick %s on %s", - parv[8], parv[1], source_p->name); - exit_client(client_p, client_p, client_p, squitreason); - return 0; - } + if(!clean_uid(parv[8])) { + rb_snprintf(squitreason, sizeof squitreason, + "Invalid UID %s for nick %s on %s", + parv[8], parv[1], source_p->name); + exit_client(client_p, client_p, client_p, squitreason); + return 0; + } - if(!clean_username(parv[5]) || !clean_host(parv[6])) - { - ServerStats.is_kill++; - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Bad user@host: %s@%s From: %s(via %s)", - parv[5], parv[6], source_p->name, client_p->name); - sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); - return 0; - } + if(!clean_username(parv[5]) || !clean_host(parv[6])) { + ServerStats.is_kill++; + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Bad user@host: %s@%s From: %s(via %s)", + parv[5], parv[6], source_p->name, client_p->name); + sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); + return 0; + } - if(strcmp(parv[9], "*") && !clean_host(parv[9])) - { - ServerStats.is_kill++; - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Bad realhost: %s From: %s(via %s)", - parv[9], source_p->name, client_p->name); - sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); - return 0; - } + if(strcmp(parv[9], "*") && !clean_host(parv[9])) { + ServerStats.is_kill++; + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Bad realhost: %s From: %s(via %s)", + parv[9], source_p->name, client_p->name); + sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); + return 0; + } - /* check length of clients gecos */ - if(strlen(parv[11]) > REALLEN) - { - char *s = LOCAL_COPY(parv[11]); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", - source_p->name, parv[1]); - s[REALLEN] = '\0'; - parv[11] = s; - } + /* check length of clients gecos */ + if(strlen(parv[11]) > REALLEN) { + char *s = LOCAL_COPY(parv[11]); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", + source_p->name, parv[1]); + s[REALLEN] = '\0'; + parv[11] = s; + } - target_p = find_named_client(parv[1]); + target_p = find_named_client(parv[1]); - if(target_p == NULL) - { - register_client(client_p, source_p, parv[1], newts, parc, parv); - } - else if(IsUnknown(target_p)) - { - exit_client(NULL, target_p, &me, "Overridden"); - register_client(client_p, source_p, parv[1], newts, parc, parv); - } - /* we've got a collision! */ - else - perform_nick_collides(source_p, client_p, target_p, parc, parv, - newts, parv[1], parv[8]); + if(target_p == NULL) { + register_client(client_p, source_p, parv[1], newts, parc, parv); + } else if(IsUnknown(target_p)) { + exit_client(NULL, target_p, &me, "Overridden"); + register_client(client_p, source_p, parv[1], newts, parc, parv); + } + /* we've got a collision! */ + else + perform_nick_collides(source_p, client_p, target_p, parc, parv, + newts, parv[1], parv[8]); - return 0; + return 0; } /* ms_save() @@ -501,58 +465,57 @@ ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_save(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - target_p = find_id(parv[1]); - if (target_p == NULL) - return 0; - if (!IsPerson(target_p)) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Ignored SAVE message for non-person %s from %s", - target_p->name, source_p->name); - else if (IsDigit(target_p->name[0])) - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Ignored noop SAVE message for %s from %s", - target_p->name, source_p->name); - else if (target_p->tsinfo == atol(parv[2])) - save_user(client_p, source_p, target_p); - else - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Ignored SAVE message for %s from %s", - target_p->name, source_p->name); - return 0; + target_p = find_id(parv[1]); + if (target_p == NULL) + return 0; + if (!IsPerson(target_p)) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Ignored SAVE message for non-person %s from %s", + target_p->name, source_p->name); + else if (IsDigit(target_p->name[0])) + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Ignored noop SAVE message for %s from %s", + target_p->name, source_p->name); + else if (target_p->tsinfo == atol(parv[2])) + save_user(client_p, source_p, target_p); + else + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Ignored SAVE message for %s from %s", + target_p->name, source_p->name); + return 0; } /* clean_nick() * * input - nickname to check * output - 0 if erroneous, else 1 - * side effects - + * side effects - */ static int clean_nick(const char *nick, int loc_client) { - int len = 0; + int len = 0; - /* nicks cant start with a digit or -, and must have a length */ - if(*nick == '-' || *nick == '\0') - return 0; + /* nicks cant start with a digit or -, and must have a length */ + if(*nick == '-' || *nick == '\0') + return 0; - if(loc_client && IsDigit(*nick)) - return 0; + if(loc_client && IsDigit(*nick)) + return 0; - for(; *nick; nick++) - { - len++; - if(!IsNickChar(*nick)) - return 0; - } + for(; *nick; nick++) { + len++; + if(!IsNickChar(*nick)) + return 0; + } - /* nicklen is +1 */ - if(len >= NICKLEN) - return 0; + /* nicklen is +1 */ + if(len >= NICKLEN) + return 0; - return 1; + return 1; } /* clean_username() @@ -564,20 +527,19 @@ clean_nick(const char *nick, int loc_client) static int clean_username(const char *username) { - int len = 0; + int len = 0; - for(; *username; username++) - { - len++; + for(; *username; username++) { + len++; - if(!IsUserChar(*username)) - return 0; - } + if(!IsUserChar(*username)) + return 0; + } - if(len > USERLEN) - return 0; + if(len > USERLEN) + return 0; - return 1; + return 1; } /* clean_host() @@ -589,180 +551,169 @@ clean_username(const char *username) static int clean_host(const char *host) { - int len = 0; + int len = 0; - for(; *host; host++) - { - len++; + for(; *host; host++) { + len++; - if(!IsHostChar(*host)) - return 0; - } + if(!IsHostChar(*host)) + return 0; + } - if(len > HOSTLEN) - return 0; + if(len > HOSTLEN) + return 0; - return 1; + return 1; } static int clean_uid(const char *uid) { - int len = 1; + int len = 1; - if(!IsDigit(*uid++)) - return 0; + if(!IsDigit(*uid++)) + return 0; - for(; *uid; uid++) - { - len++; + for(; *uid; uid++) { + len++; - if(!IsIdChar(*uid)) - return 0; - } + if(!IsIdChar(*uid)) + return 0; + } - if(len != IDLEN - 1) - return 0; + if(len != IDLEN - 1) + return 0; - return 1; + return 1; } static void set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) { - char buf[USERLEN + 1]; - char note[NICKLEN + 10]; + char buf[USERLEN + 1]; + char note[NICKLEN + 10]; - /* This had to be copied here to avoid problems.. */ - source_p->tsinfo = rb_current_time(); - if(source_p->name[0]) - del_from_client_hash(source_p->name, source_p); + /* This had to be copied here to avoid problems.. */ + source_p->tsinfo = rb_current_time(); + if(source_p->name[0]) + del_from_client_hash(source_p->name, source_p); - strcpy(source_p->name, nick); - add_to_client_hash(nick, source_p); + strcpy(source_p->name, nick); + add_to_client_hash(nick, source_p); - rb_snprintf(note, sizeof(note), "Nick: %s", nick); - rb_note(client_p->localClient->F, note); + rb_snprintf(note, sizeof(note), "Nick: %s", nick); + rb_note(client_p->localClient->F, note); - if(source_p->flags & FLAGS_SENTUSER) - { - rb_strlcpy(buf, source_p->username, sizeof(buf)); + if(source_p->flags & FLAGS_SENTUSER) { + rb_strlcpy(buf, source_p->username, sizeof(buf)); - /* got user, heres nick. */ - register_local_user(client_p, source_p, buf); + /* got user, heres nick. */ + register_local_user(client_p, source_p, buf); - } + } } static void change_local_nick(struct Client *client_p, struct Client *source_p, - char *nick, int dosend) + char *nick, int dosend) { - struct Client *target_p; - rb_dlink_node *ptr, *next_ptr; - struct Channel *chptr; - char note[NICKLEN + 10]; - int samenick; + struct Client *target_p; + rb_dlink_node *ptr, *next_ptr; + struct Channel *chptr; + char note[NICKLEN + 10]; + int samenick; - if (dosend) - { - chptr = find_bannickchange_channel(source_p); - if (chptr != NULL) - { - sendto_one_numeric(source_p, ERR_BANNICKCHANGE, - form_str(ERR_BANNICKCHANGE), - nick, chptr->chname); - return; - } + if (dosend) { + chptr = find_bannickchange_channel(source_p); + if (chptr != NULL) { + sendto_one_numeric(source_p, ERR_BANNICKCHANGE, + form_str(ERR_BANNICKCHANGE), + nick, chptr->chname); + return; + } - chptr = find_nonickchange_channel(source_p); - if (chptr != NULL) - { - sendto_one_numeric(source_p, ERR_NONICK, - form_str(ERR_NONICK), - chptr->chname); - return; - } + chptr = find_nonickchange_channel(source_p); + if (chptr != NULL) { + sendto_one_numeric(source_p, ERR_NONICK, + form_str(ERR_NONICK), + chptr->chname); + return; + } - if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < rb_current_time()) - source_p->localClient->number_of_nick_changes = 0; + if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < rb_current_time()) + source_p->localClient->number_of_nick_changes = 0; - source_p->localClient->last_nick_change = rb_current_time(); - source_p->localClient->number_of_nick_changes++; + source_p->localClient->last_nick_change = rb_current_time(); + source_p->localClient->number_of_nick_changes++; - if(ConfigFileEntry.anti_nick_flood && !IsOper(source_p) && - source_p->localClient->number_of_nick_changes > ConfigFileEntry.max_nick_changes) - { - sendto_one(source_p, form_str(ERR_NICKTOOFAST), - me.name, source_p->name, source_p->name, - nick, ConfigFileEntry.max_nick_time); - return; - } - } + if(ConfigFileEntry.anti_nick_flood && !IsOper(source_p) && + source_p->localClient->number_of_nick_changes > ConfigFileEntry.max_nick_changes) { + sendto_one(source_p, form_str(ERR_NICKTOOFAST), + me.name, source_p->name, source_p->name, + nick, ConfigFileEntry.max_nick_time); + return; + } + } - samenick = irccmp(source_p->name, nick) ? 0 : 1; + samenick = irccmp(source_p->name, nick) ? 0 : 1; - /* dont reset TS if theyre just changing case of nick */ - if(!samenick) - { - /* force the TS to increase -- jilles */ - if (source_p->tsinfo >= rb_current_time()) - source_p->tsinfo++; - else - source_p->tsinfo = rb_current_time(); - monitor_signoff(source_p); - /* we only do bancache for local users -- jilles */ - if(source_p->user) - invalidate_bancache_user(source_p); - } + /* dont reset TS if theyre just changing case of nick */ + if(!samenick) { + /* force the TS to increase -- jilles */ + if (source_p->tsinfo >= rb_current_time()) + source_p->tsinfo++; + else + source_p->tsinfo = rb_current_time(); + monitor_signoff(source_p); + /* we only do bancache for local users -- jilles */ + if(source_p->user) + invalidate_bancache_user(source_p); + } - sendto_realops_snomask(SNO_NCHANGE, L_ALL, - "Nick change: From %s to %s [%s@%s]", - source_p->name, nick, source_p->username, source_p->host); + sendto_realops_snomask(SNO_NCHANGE, L_ALL, + "Nick change: From %s to %s [%s@%s]", + source_p->name, nick, source_p->username, source_p->host); - /* send the nick change to the users channels */ - sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s NICK :%s", - source_p->name, source_p->username, source_p->host, nick); + /* send the nick change to the users channels */ + sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s NICK :%s", + source_p->name, source_p->username, source_p->host, nick); - /* send the nick change to servers.. */ - if(source_p->user) - { - add_history(source_p, 1); + /* send the nick change to servers.. */ + if(source_p->user) { + add_history(source_p, 1); - if (dosend) - { - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", - use_id(source_p), nick, (long) source_p->tsinfo); - } - } + if (dosend) { + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", + use_id(source_p), nick, (long) source_p->tsinfo); + } + } - /* Finally, add to hash */ - del_from_client_hash(source_p->name, source_p); - strcpy(source_p->name, nick); - add_to_client_hash(nick, source_p); + /* Finally, add to hash */ + del_from_client_hash(source_p->name, source_p); + strcpy(source_p->name, nick); + add_to_client_hash(nick, source_p); - if(!samenick) - monitor_signon(source_p); + if(!samenick) + monitor_signon(source_p); - /* Make sure everyone that has this client on its accept list - * loses that reference. - */ - /* we used to call del_all_accepts() here, but theres no real reason - * to clear a clients own list of accepted clients. So just remove - * them from everyone elses list --anfl - */ - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) - { - target_p = ptr->data; + /* Make sure everyone that has this client on its accept list + * loses that reference. + */ + /* we used to call del_all_accepts() here, but theres no real reason + * to clear a clients own list of accepted clients. So just remove + * them from everyone elses list --anfl + */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) { + target_p = ptr->data; - rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list); - rb_dlinkDestroy(ptr, &source_p->on_allow_list); - } + rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list); + rb_dlinkDestroy(ptr, &source_p->on_allow_list); + } - rb_snprintf(note, sizeof(note), "Nick: %s", nick); - rb_note(client_p->localClient->F, note); + rb_snprintf(note, sizeof(note), "Nick: %s", nick); + rb_note(client_p->localClient->F, note); - return; + return; } /* @@ -770,416 +721,374 @@ change_local_nick(struct Client *client_p, struct Client *source_p, */ static int change_remote_nick(struct Client *client_p, struct Client *source_p, - time_t newts, const char *nick, int dosend) + time_t newts, const char *nick, int dosend) { - struct nd_entry *nd; - int samenick = irccmp(source_p->name, nick) ? 0 : 1; + struct nd_entry *nd; + int samenick = irccmp(source_p->name, nick) ? 0 : 1; - /* client changing their nick - dont reset ts if its same */ - if(!samenick) - { - source_p->tsinfo = newts ? newts : rb_current_time(); - monitor_signoff(source_p); - } + /* client changing their nick - dont reset ts if its same */ + if(!samenick) { + source_p->tsinfo = newts ? newts : rb_current_time(); + monitor_signoff(source_p); + } - sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s NICK :%s", - source_p->name, source_p->username, source_p->host, nick); + sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s NICK :%s", + source_p->name, source_p->username, source_p->host, nick); - if(source_p->user) - { - add_history(source_p, 1); - if (dosend) - { - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", - use_id(source_p), nick, (long) source_p->tsinfo); - } - } + if(source_p->user) { + add_history(source_p, 1); + if (dosend) { + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", + use_id(source_p), nick, (long) source_p->tsinfo); + } + } - del_from_client_hash(source_p->name, source_p); + del_from_client_hash(source_p->name, source_p); - /* invalidate nick delay when a remote client uses the nick.. */ - if((nd = irc_dictionary_retrieve(nd_dict, nick))) - free_nd_entry(nd); + /* invalidate nick delay when a remote client uses the nick.. */ + if((nd = irc_dictionary_retrieve(nd_dict, nick))) + free_nd_entry(nd); - strcpy(source_p->name, nick); - add_to_client_hash(nick, source_p); + strcpy(source_p->name, nick); + add_to_client_hash(nick, source_p); - if(!samenick) - monitor_signon(source_p); + if(!samenick) + monitor_signon(source_p); - /* remove all accepts pointing to the client */ - del_all_accepts(source_p); + /* remove all accepts pointing to the client */ + del_all_accepts(source_p); - return 0; + return 0; } static int perform_nick_collides(struct Client *source_p, struct Client *client_p, - struct Client *target_p, int parc, const char *parv[], - time_t newts, const char *nick, const char *uid) + struct Client *target_p, int parc, const char *parv[], + time_t newts, const char *nick, const char *uid) { - int sameuser; - int use_save; - const char *action; + int sameuser; + int use_save; + const char *action; - use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && - uid != NULL && can_save(source_p); - action = use_save ? "saved" : "killed"; + use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && + uid != NULL && can_save(source_p); + action = use_save ? "saved" : "killed"; - /* if we dont have a ts, or their TS's are the same, kill both */ - if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo)) - { - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick collision on %s(%s <- %s)(both %s)", - target_p->name, target_p->from->name, client_p->name, action); + /* if we dont have a ts, or their TS's are the same, kill both */ + if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo)) { + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick collision on %s(%s <- %s)(both %s)", + target_p->name, target_p->from->name, client_p->name, action); - if (use_save) - { - save_user(&me, &me, target_p); - ServerStats.is_save++; - sendto_one(client_p, ":%s SAVE %s %ld", me.id, - uid, (long)newts); - register_client(client_p, source_p, - uid, SAVE_NICKTS, parc, parv); - } - else - { - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); + if (use_save) { + save_user(&me, &me, target_p); + ServerStats.is_save++; + sendto_one(client_p, ":%s SAVE %s %ld", me.id, + uid, (long)newts); + register_client(client_p, source_p, + uid, SAVE_NICKTS, parc, parv); + } else { + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); - /* if the new client being introduced has a UID, we need to - * issue a KILL for it.. - */ - if(uid) - sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))", - me.id, uid, me.name); + /* if the new client being introduced has a UID, we need to + * issue a KILL for it.. + */ + if(uid) + sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))", + me.id, uid, me.name); - /* we then need to KILL the old client everywhere */ - kill_client_serv_butone(NULL, target_p, "%s (Nick collision (new))", me.name); - ServerStats.is_kill++; + /* we then need to KILL the old client everywhere */ + kill_client_serv_butone(NULL, target_p, "%s (Nick collision (new))", me.name); + ServerStats.is_kill++; - target_p->flags |= FLAGS_KILLED; - exit_client(client_p, target_p, &me, "Nick collision (new)"); - } - return 0; - } - /* the timestamps are different */ - else - { - sameuser = (target_p->user) && !irccmp(target_p->username, parv[5]) - && !irccmp(target_p->host, parv[6]); + target_p->flags |= FLAGS_KILLED; + exit_client(client_p, target_p, &me, "Nick collision (new)"); + } + return 0; + } + /* the timestamps are different */ + else { + sameuser = (target_p->user) && !irccmp(target_p->username, parv[5]) + && !irccmp(target_p->host, parv[6]); - if((sameuser && newts < target_p->tsinfo) || - (!sameuser && newts > target_p->tsinfo)) - { - /* if we have a UID, then we need to issue a KILL, - * otherwise we do nothing and hope that the other - * client will collide it.. - */ - if (use_save) - { - sendto_one(client_p, ":%s SAVE %s %ld", me.id, - uid, (long)newts); - register_client(client_p, source_p, - uid, SAVE_NICKTS, parc, parv); - } - else if(uid) - sendto_one(client_p, - ":%s KILL %s :%s (Nick collision (new))", - me.id, uid, me.name); - return 0; - } - else - { - if(sameuser) - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick collision on %s(%s <- %s)(older %s)", - target_p->name, target_p->from->name, - client_p->name, action); - else - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick collision on %s(%s <- %s)(newer %s)", - target_p->name, target_p->from->name, - client_p->name, action); + if((sameuser && newts < target_p->tsinfo) || + (!sameuser && newts > target_p->tsinfo)) { + /* if we have a UID, then we need to issue a KILL, + * otherwise we do nothing and hope that the other + * client will collide it.. + */ + if (use_save) { + sendto_one(client_p, ":%s SAVE %s %ld", me.id, + uid, (long)newts); + register_client(client_p, source_p, + uid, SAVE_NICKTS, parc, parv); + } else if(uid) + sendto_one(client_p, + ":%s KILL %s :%s (Nick collision (new))", + me.id, uid, me.name); + return 0; + } else { + if(sameuser) + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick collision on %s(%s <- %s)(older %s)", + target_p->name, target_p->from->name, + client_p->name, action); + else + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick collision on %s(%s <- %s)(newer %s)", + target_p->name, target_p->from->name, + client_p->name, action); - if (use_save) - { - ServerStats.is_save++; - save_user(&me, &me, target_p); - } - else - { - ServerStats.is_kill++; - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); + if (use_save) { + ServerStats.is_save++; + save_user(&me, &me, target_p); + } else { + ServerStats.is_kill++; + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); - /* now we just need to kill the existing client */ - kill_client_serv_butone(client_p, target_p, - "%s (Nick collision (new))", me.name); + /* now we just need to kill the existing client */ + kill_client_serv_butone(client_p, target_p, + "%s (Nick collision (new))", me.name); - target_p->flags |= FLAGS_KILLED; - (void) exit_client(client_p, target_p, &me, "Nick collision"); - } + target_p->flags |= FLAGS_KILLED; + (void) exit_client(client_p, target_p, &me, "Nick collision"); + } - register_client(client_p, source_p, - nick, newts, parc, parv); + register_client(client_p, source_p, + nick, newts, parc, parv); - return 0; - } - } + return 0; + } + } } static int perform_nickchange_collides(struct Client *source_p, struct Client *client_p, - struct Client *target_p, int parc, - const char *parv[], time_t newts, const char *nick) + struct Client *target_p, int parc, + const char *parv[], time_t newts, const char *nick) { - int sameuser; - int use_save; - const char *action; + int sameuser; + int use_save; + const char *action; - use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && - can_save(source_p); - action = use_save ? "saved" : "killed"; + use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && + can_save(source_p); + action = use_save ? "saved" : "killed"; - /* its a client changing nick and causing a collide */ - if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user) - { - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick change collision from %s to %s(%s <- %s)(both %s)", - source_p->name, target_p->name, target_p->from->name, - client_p->name, action); + /* its a client changing nick and causing a collide */ + if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user) { + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick change collision from %s to %s(%s <- %s)(both %s)", + source_p->name, target_p->name, target_p->from->name, + client_p->name, action); - if (use_save) - { - ServerStats.is_save += 2; - save_user(&me, &me, target_p); - sendto_one(client_p, ":%s SAVE %s %ld", me.id, - source_p->id, (long)newts); - /* don't send a redundant nick change */ - if (!IsDigit(source_p->name[0])) - change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); - } - else - { - ServerStats.is_kill++; - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); + if (use_save) { + ServerStats.is_save += 2; + save_user(&me, &me, target_p); + sendto_one(client_p, ":%s SAVE %s %ld", me.id, + source_p->id, (long)newts); + /* don't send a redundant nick change */ + if (!IsDigit(source_p->name[0])) + change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); + } else { + ServerStats.is_kill++; + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); - kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); + kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); - ServerStats.is_kill++; + ServerStats.is_kill++; - kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); + kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); - target_p->flags |= FLAGS_KILLED; - exit_client(NULL, target_p, &me, "Nick collision(new)"); - source_p->flags |= FLAGS_KILLED; - exit_client(client_p, source_p, &me, "Nick collision(old)"); - } - return 0; - } - else - { - sameuser = !irccmp(target_p->username, source_p->username) && - !irccmp(target_p->host, source_p->host); + target_p->flags |= FLAGS_KILLED; + exit_client(NULL, target_p, &me, "Nick collision(new)"); + source_p->flags |= FLAGS_KILLED; + exit_client(client_p, source_p, &me, "Nick collision(old)"); + } + return 0; + } else { + sameuser = !irccmp(target_p->username, source_p->username) && + !irccmp(target_p->host, source_p->host); - if((sameuser && newts < target_p->tsinfo) || - (!sameuser && newts > target_p->tsinfo)) - { - if(sameuser) - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick change collision from %s to %s(%s <- %s)(older %s)", - source_p->name, target_p->name, - target_p->from->name, client_p->name, action); - else - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick change collision from %s to %s(%s <- %s)(newer %s)", - source_p->name, target_p->name, - target_p->from->name, client_p->name, action); + if((sameuser && newts < target_p->tsinfo) || + (!sameuser && newts > target_p->tsinfo)) { + if(sameuser) + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick change collision from %s to %s(%s <- %s)(older %s)", + source_p->name, target_p->name, + target_p->from->name, client_p->name, action); + else + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick change collision from %s to %s(%s <- %s)(newer %s)", + source_p->name, target_p->name, + target_p->from->name, client_p->name, action); - if (use_save) - { - ServerStats.is_save++; - /* can't broadcast a SAVE because the - * nickchange has happened at client_p - * but not in other directions -- jilles */ - sendto_one(client_p, ":%s SAVE %s %ld", me.id, - source_p->id, (long)newts); - /* send a : NICK (!) */ - if (!IsDigit(source_p->name[0])) - change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); - } - else - { - ServerStats.is_kill++; + if (use_save) { + ServerStats.is_save++; + /* can't broadcast a SAVE because the + * nickchange has happened at client_p + * but not in other directions -- jilles */ + sendto_one(client_p, ":%s SAVE %s %ld", me.id, + source_p->id, (long)newts); + /* send a : NICK (!) */ + if (!IsDigit(source_p->name[0])) + change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); + } else { + ServerStats.is_kill++; - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); - /* kill the client issuing the nickchange */ - kill_client_serv_butone(client_p, source_p, - "%s (Nick change collision)", me.name); + /* kill the client issuing the nickchange */ + kill_client_serv_butone(client_p, source_p, + "%s (Nick change collision)", me.name); - source_p->flags |= FLAGS_KILLED; + source_p->flags |= FLAGS_KILLED; - if(sameuser) - exit_client(client_p, source_p, &me, "Nick collision(old)"); - else - exit_client(client_p, source_p, &me, "Nick collision(new)"); - } - return 0; - } - else - { - if(sameuser) - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick collision on %s(%s <- %s)(older %s)", - target_p->name, target_p->from->name, - client_p->name, action); - else - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Nick collision on %s(%s <- %s)(newer %s)", - target_p->name, target_p->from->name, - client_p->name, action); + if(sameuser) + exit_client(client_p, source_p, &me, "Nick collision(old)"); + else + exit_client(client_p, source_p, &me, "Nick collision(new)"); + } + return 0; + } else { + if(sameuser) + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick collision on %s(%s <- %s)(older %s)", + target_p->name, target_p->from->name, + client_p->name, action); + else + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Nick collision on %s(%s <- %s)(newer %s)", + target_p->name, target_p->from->name, + client_p->name, action); - if (use_save) - { - ServerStats.is_save++; - save_user(&me, &me, target_p); - } - else - { - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); + if (use_save) { + ServerStats.is_save++; + save_user(&me, &me, target_p); + } else { + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); - /* kill the client who existed before hand */ - kill_client_serv_butone(client_p, target_p, "%s (Nick collision)", me.name); + /* kill the client who existed before hand */ + kill_client_serv_butone(client_p, target_p, "%s (Nick collision)", me.name); - ServerStats.is_kill++; + ServerStats.is_kill++; - target_p->flags |= FLAGS_KILLED; - (void) exit_client(client_p, target_p, &me, "Nick collision"); - } - } - } + target_p->flags |= FLAGS_KILLED; + (void) exit_client(client_p, target_p, &me, "Nick collision"); + } + } + } - change_remote_nick(client_p, source_p, newts, nick, 1); + change_remote_nick(client_p, source_p, newts, nick, 1); - return 0; + return 0; } static int register_client(struct Client *client_p, struct Client *server, - const char *nick, time_t newts, int parc, const char *parv[]) + const char *nick, time_t newts, int parc, const char *parv[]) { - struct Client *source_p; - struct User *user; - struct nd_entry *nd; - const char *m; - int flag; + struct Client *source_p; + struct User *user; + struct nd_entry *nd; + const char *m; + int flag; - source_p = make_client(client_p); - user = make_user(source_p); - rb_dlinkAddTail(source_p, &source_p->node, &global_client_list); + source_p = make_client(client_p); + user = make_user(source_p); + rb_dlinkAddTail(source_p, &source_p->node, &global_client_list); - source_p->hopcount = atoi(parv[2]); - source_p->tsinfo = newts; + source_p->hopcount = atoi(parv[2]); + source_p->tsinfo = newts; - strcpy(source_p->name, nick); - rb_strlcpy(source_p->username, parv[5], sizeof(source_p->username)); - rb_strlcpy(source_p->host, parv[6], sizeof(source_p->host)); - rb_strlcpy(source_p->orighost, source_p->host, sizeof(source_p->orighost)); + strcpy(source_p->name, nick); + rb_strlcpy(source_p->username, parv[5], sizeof(source_p->username)); + rb_strlcpy(source_p->host, parv[6], sizeof(source_p->host)); + rb_strlcpy(source_p->orighost, source_p->host, sizeof(source_p->orighost)); - if(parc == 12) - { - rb_strlcpy(source_p->info, parv[11], sizeof(source_p->info)); - rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); - rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); - add_to_id_hash(source_p->id, source_p); - if (strcmp(parv[9], "*")) - { - rb_strlcpy(source_p->orighost, parv[9], sizeof(source_p->orighost)); - if (irccmp(source_p->host, source_p->orighost)) - SetDynSpoof(source_p); - } - if (strcmp(parv[10], "*")) - rb_strlcpy(source_p->user->suser, parv[10], sizeof(source_p->user->suser)); - } - else if(parc == 10) - { - rb_strlcpy(source_p->info, parv[9], sizeof(source_p->info)); - rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); - rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); - add_to_id_hash(source_p->id, source_p); - } - else - { - s_assert(0); - } + if(parc == 12) { + rb_strlcpy(source_p->info, parv[11], sizeof(source_p->info)); + rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); + rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); + add_to_id_hash(source_p->id, source_p); + if (strcmp(parv[9], "*")) { + rb_strlcpy(source_p->orighost, parv[9], sizeof(source_p->orighost)); + if (irccmp(source_p->host, source_p->orighost)) + SetDynSpoof(source_p); + } + if (strcmp(parv[10], "*")) + rb_strlcpy(source_p->user->suser, parv[10], sizeof(source_p->user->suser)); + } else if(parc == 10) { + rb_strlcpy(source_p->info, parv[9], sizeof(source_p->info)); + rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); + rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); + add_to_id_hash(source_p->id, source_p); + } else { + s_assert(0); + } - /* remove any nd entries for this nick */ - if((nd = irc_dictionary_retrieve(nd_dict, nick))) - free_nd_entry(nd); + /* remove any nd entries for this nick */ + if((nd = irc_dictionary_retrieve(nd_dict, nick))) + free_nd_entry(nd); - add_to_client_hash(nick, source_p); - add_to_hostname_hash(source_p->orighost, source_p); - monitor_signon(source_p); + add_to_client_hash(nick, source_p); + add_to_hostname_hash(source_p->orighost, source_p); + monitor_signon(source_p); - m = &parv[4][1]; - while(*m) - { - flag = user_modes[(unsigned char) *m]; + m = &parv[4][1]; + while(*m) { + flag = user_modes[(unsigned char) *m]; - if(flag & UMODE_SERVICE) - { - int hit = 0; - rb_dlink_node *ptr; + if(flag & UMODE_SERVICE) { + int hit = 0; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, service_list.head) - { - if(!irccmp((const char *) ptr->data, server->name)) - { - hit++; - break; - } - } + RB_DLINK_FOREACH(ptr, service_list.head) { + if(!irccmp((const char *) ptr->data, server->name)) { + hit++; + break; + } + } - if(!hit) - { - m++; - continue; - } - } + if(!hit) { + m++; + continue; + } + } - /* increment +i count if theyre invis */ - if(!(source_p->umodes & UMODE_INVISIBLE) && (flag & UMODE_INVISIBLE)) - Count.invisi++; + /* increment +i count if theyre invis */ + if(!(source_p->umodes & UMODE_INVISIBLE) && (flag & UMODE_INVISIBLE)) + Count.invisi++; - /* increment opered count if theyre opered */ - if(!(source_p->umodes & UMODE_OPER) && (flag & UMODE_OPER)) - Count.oper++; + /* increment opered count if theyre opered */ + if(!(source_p->umodes & UMODE_OPER) && (flag & UMODE_OPER)) + Count.oper++; - source_p->umodes |= flag; - m++; - } + source_p->umodes |= flag; + m++; + } - if(IsOper(source_p) && !IsService(source_p)) - rb_dlinkAddAlloc(source_p, &oper_list); + if(IsOper(source_p) && !IsService(source_p)) + rb_dlinkAddAlloc(source_p, &oper_list); - SetRemoteClient(source_p); + SetRemoteClient(source_p); - if(++Count.total > Count.max_tot) - Count.max_tot = Count.total; + if(++Count.total > Count.max_tot) + Count.max_tot = Count.total; - source_p->servptr = server; + source_p->servptr = server; - rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); + rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); - call_hook(h_new_remote_user, source_p); + call_hook(h_new_remote_user, source_p); - return (introduce_client(client_p, source_p, user, nick, parc == 12)); + return (introduce_client(client_p, source_p, user, nick, parc == 12)); } /* Check if we can do SAVE. target_p can be a client to save or a @@ -1187,73 +1096,69 @@ register_client(struct Client *client_p, struct Client *server, static int can_save(struct Client *target_p) { - struct Client *serv_p; + struct Client *serv_p; - if (MyClient(target_p)) - return 1; - if (!has_id(target_p)) - return 0; - serv_p = IsServer(target_p) ? target_p : target_p->servptr; - while (serv_p != NULL && serv_p != &me) - { - if (!(serv_p->serv->caps & CAP_SAVE)) - return 0; - serv_p = serv_p->servptr; - } - return serv_p == &me; + if (MyClient(target_p)) + return 1; + if (!has_id(target_p)) + return 0; + serv_p = IsServer(target_p) ? target_p : target_p->servptr; + while (serv_p != NULL && serv_p != &me) { + if (!(serv_p->serv->caps & CAP_SAVE)) + return 0; + serv_p = serv_p->servptr; + } + return serv_p == &me; } static void save_user(struct Client *client_p, struct Client *source_p, - struct Client *target_p) + struct Client *target_p) { - if (!MyConnect(target_p) && (!has_id(target_p) || !IsCapable(target_p->from, CAP_SAVE))) - { - /* This shouldn't happen */ - /* Note we only need SAVE support in this direction */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)", - target_p->name, target_p->username, target_p->host, source_p->name, target_p->from->name); - kill_client_serv_butone(NULL, target_p, "%s (Nick collision (no SAVE support))", me.name); - ServerStats.is_kill++; + if (!MyConnect(target_p) && (!has_id(target_p) || !IsCapable(target_p->from, CAP_SAVE))) { + /* This shouldn't happen */ + /* Note we only need SAVE support in this direction */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)", + target_p->name, target_p->username, target_p->host, source_p->name, target_p->from->name); + kill_client_serv_butone(NULL, target_p, "%s (Nick collision (no SAVE support))", me.name); + ServerStats.is_kill++; - target_p->flags |= FLAGS_KILLED; - (void) exit_client(NULL, target_p, &me, "Nick collision (no SAVE support)"); - return; - } - sendto_server(client_p, NULL, CAP_SAVE|CAP_TS6, NOCAPS, ":%s SAVE %s %ld", - source_p->id, target_p->id, (long)target_p->tsinfo); - sendto_server(client_p, NULL, CAP_TS6, CAP_SAVE, ":%s NICK %s :%ld", - target_p->id, target_p->id, (long)SAVE_NICKTS); - if (!IsMe(client_p)) - sendto_realops_snomask(SNO_SKILL, L_ALL, - "Received SAVE message for %s from %s", - target_p->name, source_p->name); - if (MyClient(target_p)) - { - sendto_one_numeric(target_p, RPL_SAVENICK, - form_str(RPL_SAVENICK), target_p->id); - change_local_nick(target_p, target_p, target_p->id, 0); - target_p->tsinfo = SAVE_NICKTS; - } - else - change_remote_nick(target_p, target_p, SAVE_NICKTS, target_p->id, 0); + target_p->flags |= FLAGS_KILLED; + (void) exit_client(NULL, target_p, &me, "Nick collision (no SAVE support)"); + return; + } + sendto_server(client_p, NULL, CAP_SAVE|CAP_TS6, NOCAPS, ":%s SAVE %s %ld", + source_p->id, target_p->id, (long)target_p->tsinfo); + sendto_server(client_p, NULL, CAP_TS6, CAP_SAVE, ":%s NICK %s :%ld", + target_p->id, target_p->id, (long)SAVE_NICKTS); + if (!IsMe(client_p)) + sendto_realops_snomask(SNO_SKILL, L_ALL, + "Received SAVE message for %s from %s", + target_p->name, source_p->name); + if (MyClient(target_p)) { + sendto_one_numeric(target_p, RPL_SAVENICK, + form_str(RPL_SAVENICK), target_p->id); + change_local_nick(target_p, target_p, target_p->id, 0); + target_p->tsinfo = SAVE_NICKTS; + } else + change_remote_nick(target_p, target_p, SAVE_NICKTS, target_p->id, 0); } static void bad_nickname(struct Client *client_p, const char *nick) { - char squitreason[100]; + char squitreason[100]; - sendto_wallops_flags(UMODE_WALLOP, &me, - "Squitting %s because of bad nickname %s (NICKLEN mismatch?)", - client_p->name, nick); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)", - me.id, client_p->name, nick); - ilog(L_SERVER, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)", - client_p->name, nick); + sendto_wallops_flags(UMODE_WALLOP, &me, + "Squitting %s because of bad nickname %s (NICKLEN mismatch?)", + client_p->name, nick); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)", + me.id, client_p->name, nick); + ilog(L_SERVER, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)", + client_p->name, nick); - rb_snprintf(squitreason, sizeof squitreason, - "Bad nickname introduced [%s]", nick); - exit_client(client_p, client_p, &me, squitreason); + rb_snprintf(squitreason, sizeof squitreason, + "Bad nickname introduced [%s]", nick); + exit_client(client_p, client_p, &me, squitreason); } diff --git a/modules/core/m_part.c b/modules/core/m_part.c index cc32d44..d5ede14 100644 --- a/modules/core/m_part.c +++ b/modules/core/m_part.c @@ -43,8 +43,8 @@ static int m_part(struct Client *, struct Client *, int, const char **); struct Message part_msgtab = { - "PART", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}} + "PART", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}} }; mapi_clist_av1 part_clist[] = { &part_msgtab, NULL }; @@ -52,7 +52,7 @@ mapi_clist_av1 part_clist[] = { &part_msgtab, NULL }; DECLARE_MODULE_AV1(part, NULL, NULL, part_clist, NULL, NULL, "$Revision: 98 $"); static void part_one_client(struct Client *client_p, - struct Client *source_p, char *name, char *reason); + struct Client *source_p, char *name, char *reason); /* @@ -63,27 +63,26 @@ static void part_one_client(struct Client *client_p, static int m_part(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *p, *name; - char reason[REASONLEN + 1]; - char *s = LOCAL_COPY(parv[1]); + char *p, *name; + char reason[REASONLEN + 1]; + char *s = LOCAL_COPY(parv[1]); - reason[0] = '\0'; + reason[0] = '\0'; - if(parc > 2) - rb_strlcpy(reason, parv[2], sizeof(reason)); + if(parc > 2) + rb_strlcpy(reason, parv[2], sizeof(reason)); - name = rb_strtok_r(s, ",", &p); + name = rb_strtok_r(s, ",", &p); - /* Finish the flood grace period... */ - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + /* Finish the flood grace period... */ + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - while(name) - { - part_one_client(client_p, source_p, name, reason); - name = rb_strtok_r(NULL, ",", &p); - } - return 0; + while(name) { + part_one_client(client_p, source_p, name, reason); + name = rb_strtok_r(NULL, ",", &p); + } + return 0; } /* @@ -93,59 +92,53 @@ m_part(struct Client *client_p, struct Client *source_p, int parc, const char *p * - pointer to source client to remove * - char pointer of name of channel to remove from * output - none - * side effects - remove ONE client given the channel name + * side effects - remove ONE client given the channel name */ static void part_one_client(struct Client *client_p, struct Client *source_p, char *name, char *reason) { - struct Channel *chptr; - struct membership *msptr; - char reason2[BUFSIZE]; + struct Channel *chptr; + struct membership *msptr; + char reason2[BUFSIZE]; - if((chptr = find_channel(name)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); - return; - } + if((chptr = find_channel(name)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); + return; + } - msptr = find_channel_membership(chptr, source_p); - if(msptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); - return; - } + msptr = find_channel_membership(chptr, source_p); + if(msptr == NULL) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); + return; + } - if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) - check_spambot_warning(source_p, NULL); + if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) + check_spambot_warning(source_p, NULL); - /* - * Remove user from the old channel (if any) - * only allow /part reasons in -m chans - */ - if(reason[0] && (is_any_op(msptr) || !MyConnect(source_p) || - ((can_send(chptr, source_p, msptr) > 0 && ConfigFileEntry.use_part_messages && - (source_p->localClient->firsttime + - ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) - { - if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) - { - rb_strlcpy(reason2, reason, BUFSIZE); - strip_colour(reason2); - reason = reason2; - } - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :\"%s\"", - source_p->name, source_p->username, - source_p->host, chptr->chname, reason); - } - else - { - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s PART %s", use_id(source_p), chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", - source_p->name, source_p->username, - source_p->host, chptr->chname); - } - remove_user_from_channel(msptr); + /* + * Remove user from the old channel (if any) + * only allow /part reasons in -m chans + */ + if(reason[0] && (is_any_op(msptr) || !MyConnect(source_p) || + ((can_send(chptr, source_p, msptr) > 0 && ConfigFileEntry.use_part_messages && + (source_p->localClient->firsttime + + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) { + if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) { + rb_strlcpy(reason2, reason, BUFSIZE); + strip_colour(reason2); + reason = reason2; + } + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :\"%s\"", + source_p->name, source_p->username, + source_p->host, chptr->chname, reason); + } else { + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s PART %s", use_id(source_p), chptr->chname); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", + source_p->name, source_p->username, + source_p->host, chptr->chname); + } + remove_user_from_channel(msptr); } diff --git a/modules/core/m_quit.c b/modules/core/m_quit.c index 83b8474..a9c2a49 100644 --- a/modules/core/m_quit.c +++ b/modules/core/m_quit.c @@ -39,8 +39,8 @@ static int m_quit(struct Client *, struct Client *, int, const char **); static int ms_quit(struct Client *, struct Client *, int, const char **); struct Message quit_msgtab = { - "QUIT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{m_quit, 0}, {m_quit, 0}, {ms_quit, 0}, mg_ignore, mg_ignore, {m_quit, 0}} + "QUIT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{m_quit, 0}, {m_quit, 0}, {ms_quit, 0}, mg_ignore, mg_ignore, {m_quit, 0}} }; mapi_clist_av1 quit_clist[] = { &quit_msgtab, NULL }; @@ -54,39 +54,36 @@ DECLARE_MODULE_AV1(quit, NULL, NULL, quit_clist, NULL, NULL, "$Revision: 1333 $" static int m_quit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *comment = LOCAL_COPY((parc > 1 && parv[1]) ? parv[1] : client_p->name); - char reason[REASONLEN + 1]; + char *comment = LOCAL_COPY((parc > 1 && parv[1]) ? parv[1] : client_p->name); + char reason[REASONLEN + 1]; - source_p->flags |= FLAGS_NORMALEX; + source_p->flags |= FLAGS_NORMALEX; - if(strlen(comment) > (size_t) REASONLEN) - comment[REASONLEN] = '\0'; + if(strlen(comment) > (size_t) REASONLEN) + comment[REASONLEN] = '\0'; - strip_colour(comment); + strip_colour(comment); - if(ConfigFileEntry.client_exit && comment[0]) - { - rb_snprintf(reason, sizeof(reason), "Quit: %s", comment); - comment = reason; - } + if(ConfigFileEntry.client_exit && comment[0]) { + rb_snprintf(reason, sizeof(reason), "Quit: %s", comment); + comment = reason; + } - if(!IsOper(source_p) && !EmptyString(ConfigFileEntry.static_quit)) - { - exit_client(client_p, source_p, source_p, ConfigFileEntry.static_quit); - return 0; - } + if(!IsOper(source_p) && !EmptyString(ConfigFileEntry.static_quit)) { + exit_client(client_p, source_p, source_p, ConfigFileEntry.static_quit); + return 0; + } - if(!IsOper(source_p) && - (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) > - rb_current_time()) - { - exit_client(client_p, source_p, source_p, "Client Quit"); - return 0; - } + if(!IsOper(source_p) && + (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) > + rb_current_time()) { + exit_client(client_p, source_p, source_p, "Client Quit"); + return 0; + } - exit_client(client_p, source_p, source_p, comment); + exit_client(client_p, source_p, source_p, comment); - return 0; + return 0; } /* @@ -96,13 +93,13 @@ m_quit(struct Client *client_p, struct Client *source_p, int parc, const char *p static int ms_quit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *comment = LOCAL_COPY((parc > 1 && parv[1]) ? parv[1] : client_p->name); + char *comment = LOCAL_COPY((parc > 1 && parv[1]) ? parv[1] : client_p->name); - source_p->flags |= FLAGS_NORMALEX; - if(strlen(comment) > (size_t) REASONLEN) - comment[REASONLEN] = '\0'; + source_p->flags |= FLAGS_NORMALEX; + if(strlen(comment) > (size_t) REASONLEN) + comment[REASONLEN] = '\0'; - exit_client(client_p, source_p, source_p, comment); + exit_client(client_p, source_p, source_p, comment); - return 0; + return 0; } diff --git a/modules/core/m_server.c b/modules/core/m_server.c index 79c1b6c..e63fad1 100644 --- a/modules/core/m_server.c +++ b/modules/core/m_server.c @@ -46,12 +46,12 @@ static int ms_server(struct Client *, struct Client *, int, const char **); static int ms_sid(struct Client *, struct Client *, int, const char **); struct Message server_msgtab = { - "SERVER", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_server, 4}, mg_reg, mg_ignore, {ms_server, 4}, mg_ignore, mg_reg} + "SERVER", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_server, 4}, mg_reg, mg_ignore, {ms_server, 4}, mg_ignore, mg_reg} }; struct Message sid_msgtab = { - "SID", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_reg, mg_ignore, {ms_sid, 5}, mg_ignore, mg_reg} + "SID", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_reg, mg_ignore, {ms_sid, 5}, mg_ignore, mg_reg} }; mapi_clist_av1 server_clist[] = { &server_msgtab, &sid_msgtab, NULL }; @@ -70,209 +70,196 @@ static int set_server_gecos(struct Client *, const char *); static int mr_server(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char info[REALLEN + 1]; - const char *name; - struct Client *target_p; - int hop; - struct Capability *cap; + char info[REALLEN + 1]; + const char *name; + struct Client *target_p; + int hop; + struct Capability *cap; - name = parv[1]; - hop = atoi(parv[2]); - rb_strlcpy(info, parv[3], sizeof(info)); + name = parv[1]; + hop = atoi(parv[2]); + rb_strlcpy(info, parv[3], sizeof(info)); - if (IsHandshake(client_p) && irccmp(client_p->name, name)) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Server %s has unexpected name %s", - client_p->name, name); - ilog(L_SERVER, "Server %s has unexpected name %s", - log_client_name(client_p, SHOW_IP), name); - exit_client(client_p, client_p, client_p, "Server name mismatch"); - return 0; - } + if (IsHandshake(client_p) && irccmp(client_p->name, name)) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Server %s has unexpected name %s", + client_p->name, name); + ilog(L_SERVER, "Server %s has unexpected name %s", + log_client_name(client_p, SHOW_IP), name); + exit_client(client_p, client_p, client_p, "Server name mismatch"); + return 0; + } - /* - * Reject a direct nonTS server connection if we're TS_ONLY -orabidoo - */ - if(!DoesTS(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Link %s dropped, non-TS server", - client_p->name); - exit_client(client_p, client_p, client_p, "Non-TS server"); - return 0; - } + /* + * Reject a direct nonTS server connection if we're TS_ONLY -orabidoo + */ + if(!DoesTS(client_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Link %s dropped, non-TS server", + client_p->name); + exit_client(client_p, client_p, client_p, "Non-TS server"); + return 0; + } - if(bogus_host(name)) - { - exit_client(client_p, client_p, client_p, "Bogus server name"); - return 0; - } + if(bogus_host(name)) { + exit_client(client_p, client_p, client_p, "Bogus server name"); + return 0; + } - /* check to ensure any "required" caps are set. --nenolod */ - for (cap = captab; cap->name; cap++) - { - if (!cap->required) - continue; + /* check to ensure any "required" caps are set. --nenolod */ + for (cap = captab; cap->name; cap++) { + if (!cap->required) + continue; - if (!(client_p->localClient->caps & cap->cap)) - { - char exitbuf[BUFSIZE]; + if (!(client_p->localClient->caps & cap->cap)) { + char exitbuf[BUFSIZE]; - rb_snprintf(exitbuf, BUFSIZE, "Missing required CAPAB [%s]", cap->name); - exit_client(client_p, client_p, client_p, exitbuf); + rb_snprintf(exitbuf, BUFSIZE, "Missing required CAPAB [%s]", cap->name); + exit_client(client_p, client_p, client_p, exitbuf); - return 0; - } - } + return 0; + } + } - /* Now we just have to call check_server and everything should be - * check for us... -A1kmm. */ - switch (check_server(name, client_p)) - { - case -1: - if(ConfigFileEntry.warn_no_nline) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Unauthorised server connection attempt from %s: " - "No entry for servername %s", - log_client_name(client_p, SHOW_IP), name); + /* Now we just have to call check_server and everything should be + * check for us... -A1kmm. */ + switch (check_server(name, client_p)) { + case -1: + if(ConfigFileEntry.warn_no_nline) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Unauthorised server connection attempt from %s: " + "No entry for servername %s", + log_client_name(client_p, SHOW_IP), name); - ilog(L_SERVER, "Access denied, no connect block for server %s%s", - EmptyString(client_p->name) ? name : "", - log_client_name(client_p, SHOW_IP)); - } + ilog(L_SERVER, "Access denied, no connect block for server %s%s", + EmptyString(client_p->name) ? name : "", + log_client_name(client_p, SHOW_IP)); + } - exit_client(client_p, client_p, client_p, "Invalid servername."); - return 0; - /* NOT REACHED */ - break; + exit_client(client_p, client_p, client_p, "Invalid servername."); + return 0; + /* NOT REACHED */ + break; - case -2: - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Unauthorised server connection attempt from %s: " - "Bad credentials for server %s", - log_client_name(client_p, SHOW_IP), name); + case -2: + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Unauthorised server connection attempt from %s: " + "Bad credentials for server %s", + log_client_name(client_p, SHOW_IP), name); - ilog(L_SERVER, "Access denied, invalid credentials for server %s%s", - EmptyString(client_p->name) ? name : "", - log_client_name(client_p, SHOW_IP)); + ilog(L_SERVER, "Access denied, invalid credentials for server %s%s", + EmptyString(client_p->name) ? name : "", + log_client_name(client_p, SHOW_IP)); - exit_client(client_p, client_p, client_p, "Invalid credentials."); - return 0; - /* NOT REACHED */ - break; + exit_client(client_p, client_p, client_p, "Invalid credentials."); + return 0; + /* NOT REACHED */ + break; - case -3: - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Unauthorised server connection attempt from %s: " - "Invalid host for server %s", - log_client_name(client_p, SHOW_IP), name); + case -3: + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Unauthorised server connection attempt from %s: " + "Invalid host for server %s", + log_client_name(client_p, SHOW_IP), name); - ilog(L_SERVER, "Access denied, invalid host for server %s%s", - EmptyString(client_p->name) ? name : "", - log_client_name(client_p, SHOW_IP)); + ilog(L_SERVER, "Access denied, invalid host for server %s%s", + EmptyString(client_p->name) ? name : "", + log_client_name(client_p, SHOW_IP)); - exit_client(client_p, client_p, client_p, "Invalid host."); - return 0; - /* NOT REACHED */ - break; + exit_client(client_p, client_p, client_p, "Invalid host."); + return 0; + /* NOT REACHED */ + break; - /* servername is > HOSTLEN */ - case -4: - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Invalid servername %s from %s", - name, log_client_name(client_p, SHOW_IP)); - ilog(L_SERVER, "Access denied, invalid servername from %s", - log_client_name(client_p, SHOW_IP)); + /* servername is > HOSTLEN */ + case -4: + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Invalid servername %s from %s", + name, log_client_name(client_p, SHOW_IP)); + ilog(L_SERVER, "Access denied, invalid servername from %s", + log_client_name(client_p, SHOW_IP)); - exit_client(client_p, client_p, client_p, "Invalid servername."); - return 0; - /* NOT REACHED */ - break; - case -5: - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Connection from servername %s requires SSL/TLS but is plaintext", - name); - ilog(L_SERVER, "Access denied, requires SSL/TLS but is plaintext from %s", - log_client_name(client_p, SHOW_IP)); + exit_client(client_p, client_p, client_p, "Invalid servername."); + return 0; + /* NOT REACHED */ + break; + case -5: + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Connection from servername %s requires SSL/TLS but is plaintext", + name); + ilog(L_SERVER, "Access denied, requires SSL/TLS but is plaintext from %s", + log_client_name(client_p, SHOW_IP)); - exit_client(client_p, client_p, client_p, "Access denied, requires SSL/TLS but is plaintext"); - return 0; - } + exit_client(client_p, client_p, client_p, "Access denied, requires SSL/TLS but is plaintext"); + return 0; + } - /* require TS6 for direct links */ - if(!IsCapable(client_p, CAP_TS6)) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Link %s dropped, TS6 protocol is required", name); - exit_client(client_p, client_p, client_p, "Incompatible TS version"); - return 0; - } + /* require TS6 for direct links */ + if(!IsCapable(client_p, CAP_TS6)) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Link %s dropped, TS6 protocol is required", name); + exit_client(client_p, client_p, client_p, "Incompatible TS version"); + return 0; + } - if((target_p = find_server(NULL, name))) - { - /* - * This link is trying feed me a server that I already have - * access through another path -- multiple paths not accepted - * currently, kill this link immediately!! - * - * Rather than KILL the link which introduced it, KILL the - * youngest of the two links. -avalon - * - * Definitely don't do that here. This is from an unregistered - * connect - A1kmm. - */ - if (target_p->servptr->flags & FLAGS_SERVICE) - { - /* Assume any servers introduced by services - * are jupes. - * -- jilles - */ - sendto_one(client_p, "ERROR :Server juped."); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Attempt to re-introduce server %s from %s", - name, log_client_name(client_p, SHOW_IP)); - ilog(L_SERVER, "Attempt to re-introduce server %s from %s", - name, log_client_name(client_p, SHOW_IP)); + if((target_p = find_server(NULL, name))) { + /* + * This link is trying feed me a server that I already have + * access through another path -- multiple paths not accepted + * currently, kill this link immediately!! + * + * Rather than KILL the link which introduced it, KILL the + * youngest of the two links. -avalon + * + * Definitely don't do that here. This is from an unregistered + * connect - A1kmm. + */ + if (target_p->servptr->flags & FLAGS_SERVICE) { + /* Assume any servers introduced by services + * are jupes. + * -- jilles + */ + sendto_one(client_p, "ERROR :Server juped."); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Attempt to re-introduce server %s from %s", + name, log_client_name(client_p, SHOW_IP)); + ilog(L_SERVER, "Attempt to re-introduce server %s from %s", + name, log_client_name(client_p, SHOW_IP)); - sendto_one(client_p, "ERROR :Server already exists."); - } - exit_client(client_p, client_p, client_p, "Server Exists"); - return 0; - } + sendto_one(client_p, "ERROR :Server already exists."); + } + exit_client(client_p, client_p, client_p, "Server Exists"); + return 0; + } - if(has_id(client_p) && (target_p = find_id(client_p->id)) != NULL) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Attempt to re-introduce SID %s from %s%s (already in use by %s)", - client_p->id, - EmptyString(client_p->name) ? name : "", - client_p->name, target_p->name); - ilog(L_SERVER, "Attempt to re-introduce SID %s from %s%s (already in use by %s)", - client_p->id, - EmptyString(client_p->name) ? name : "", - log_client_name(client_p, SHOW_IP), - target_p->name); + if(has_id(client_p) && (target_p = find_id(client_p->id)) != NULL) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Attempt to re-introduce SID %s from %s%s (already in use by %s)", + client_p->id, + EmptyString(client_p->name) ? name : "", + client_p->name, target_p->name); + ilog(L_SERVER, "Attempt to re-introduce SID %s from %s%s (already in use by %s)", + client_p->id, + EmptyString(client_p->name) ? name : "", + log_client_name(client_p, SHOW_IP), + target_p->name); - sendto_one(client_p, "ERROR :SID already exists."); - exit_client(client_p, client_p, client_p, "SID Exists"); - return 0; - } + sendto_one(client_p, "ERROR :SID already exists."); + exit_client(client_p, client_p, client_p, "SID Exists"); + return 0; + } - /* - * if we are connecting (Handshake), we already have the name from the - * C:line in client_p->name - */ + /* + * if we are connecting (Handshake), we already have the name from the + * C:line in client_p->name + */ - rb_strlcpy(client_p->name, name, sizeof(client_p->name)); - set_server_gecos(client_p, info); - client_p->hopcount = hop; - server_estab(client_p); + rb_strlcpy(client_p->name, name, sizeof(client_p->name)); + set_server_gecos(client_p, info); + client_p->hopcount = hop; + server_estab(client_p); - return 0; + return 0; } /* @@ -284,365 +271,350 @@ mr_server(struct Client *client_p, struct Client *source_p, int parc, const char static int ms_server(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char info[REALLEN + 1]; - /* same size as in s_misc.c */ - const char *name; - struct Client *target_p; - struct remote_conf *hub_p; - hook_data_client hdata; - int hop; - int hlined = 0; - int llined = 0; - rb_dlink_node *ptr; - char squitreason[160]; + char info[REALLEN + 1]; + /* same size as in s_misc.c */ + const char *name; + struct Client *target_p; + struct remote_conf *hub_p; + hook_data_client hdata; + int hop; + int hlined = 0; + int llined = 0; + rb_dlink_node *ptr; + char squitreason[160]; - name = parv[1]; - hop = atoi(parv[2]); - rb_strlcpy(info, parv[3], sizeof(info)); + name = parv[1]; + hop = atoi(parv[2]); + rb_strlcpy(info, parv[3], sizeof(info)); - if((target_p = find_server(NULL, name))) - { - /* - * This link is trying feed me a server that I already have - * access through another path -- multiple paths not accepted - * currently, kill this link immediately!! - * - * Rather than KILL the link which introduced it, KILL the - * youngest of the two links. -avalon - * - * I think that we should exit the link itself, not the introducer, - * and we should always exit the most recently received(i.e. the - * one we are receiving this SERVER for. -A1kmm - * - * You *cant* do this, if you link somewhere, it bursts you a server - * that already exists, then sends you a client burst, you squit the - * server, but you keep getting the burst of clients on a server that - * doesnt exist, although ircd can handle it, its not a realistic - * solution.. --fl_ - */ - ilog(L_SERVER, "Link %s cancelled, server %s already exists", - client_p->name, name); + if((target_p = find_server(NULL, name))) { + /* + * This link is trying feed me a server that I already have + * access through another path -- multiple paths not accepted + * currently, kill this link immediately!! + * + * Rather than KILL the link which introduced it, KILL the + * youngest of the two links. -avalon + * + * I think that we should exit the link itself, not the introducer, + * and we should always exit the most recently received(i.e. the + * one we are receiving this SERVER for. -A1kmm + * + * You *cant* do this, if you link somewhere, it bursts you a server + * that already exists, then sends you a client burst, you squit the + * server, but you keep getting the burst of clients on a server that + * doesnt exist, although ircd can handle it, its not a realistic + * solution.. --fl_ + */ + ilog(L_SERVER, "Link %s cancelled, server %s already exists", + client_p->name, name); - rb_snprintf(squitreason, sizeof squitreason, - "Server %s already exists", - name); - exit_client(client_p, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "Server %s already exists", + name); + exit_client(client_p, client_p, &me, squitreason); + return 0; + } - /* - * User nicks never have '.' in them and server names - * must always have '.' in them. - */ - if(strchr(name, '.') == NULL) - { - /* - * Server trying to use the same name as a person. Would - * cause a fair bit of confusion. Enough to make it hellish - * for a while and servers to send stuff to the wrong place. - */ - sendto_one(client_p, "ERROR :Nickname %s already exists!", name); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s cancelled: Server/nick collision on %s", - client_p->name, name); - ilog(L_SERVER, "Link %s cancelled: Server/nick collision on %s", - client_p->name, name); + /* + * User nicks never have '.' in them and server names + * must always have '.' in them. + */ + if(strchr(name, '.') == NULL) { + /* + * Server trying to use the same name as a person. Would + * cause a fair bit of confusion. Enough to make it hellish + * for a while and servers to send stuff to the wrong place. + */ + sendto_one(client_p, "ERROR :Nickname %s already exists!", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s cancelled: Server/nick collision on %s", + client_p->name, name); + ilog(L_SERVER, "Link %s cancelled: Server/nick collision on %s", + client_p->name, name); - exit_client(client_p, client_p, client_p, "Nick as Server"); - return 0; - } + exit_client(client_p, client_p, client_p, "Nick as Server"); + return 0; + } - /* - * Server is informing about a new server behind - * this link. Create REMOTE server structure, - * add it to list and propagate word to my other - * server links... - */ + /* + * Server is informing about a new server behind + * this link. Create REMOTE server structure, + * add it to list and propagate word to my other + * server links... + */ - /* - * See if the newly found server is behind a guaranteed - * leaf. If so, close the link. - * - */ - RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) - { - hub_p = ptr->data; + /* + * See if the newly found server is behind a guaranteed + * leaf. If so, close the link. + * + */ + RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) { + hub_p = ptr->data; - if(match(hub_p->server, client_p->name) && match(hub_p->host, name)) - { - if(hub_p->flags & CONF_HUB) - hlined++; - else - llined++; - } - } + if(match(hub_p->server, client_p->name) && match(hub_p->host, name)) { + if(hub_p->flags & CONF_HUB) + hlined++; + else + llined++; + } + } - /* Ok, this way this works is - * - * A server can have a CONF_HUB allowing it to introduce servers - * behind it. - * - * connect { - * name = "irc.bighub.net"; - * hub_mask="*"; - * ... - * - * That would allow "irc.bighub.net" to introduce anything it wanted.. - * - * However - * - * connect { - * name = "irc.somehub.fi"; - * hub_mask="*"; - * leaf_mask="*.edu"; - *... - * Would allow this server in finland to hub anything but - * .edu's - */ + /* Ok, this way this works is + * + * A server can have a CONF_HUB allowing it to introduce servers + * behind it. + * + * connect { + * name = "irc.bighub.net"; + * hub_mask="*"; + * ... + * + * That would allow "irc.bighub.net" to introduce anything it wanted.. + * + * However + * + * connect { + * name = "irc.somehub.fi"; + * hub_mask="*"; + * leaf_mask="*.edu"; + *... + * Would allow this server in finland to hub anything but + * .edu's + */ - /* Ok, check client_p can hub the new server */ - if(!hlined) - { - /* OOOPs nope can't HUB */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Non-Hub link %s introduced %s.", - client_p->name, name); - ilog(L_SERVER, "Non-Hub link %s introduced %s.", - client_p->name, name); + /* Ok, check client_p can hub the new server */ + if(!hlined) { + /* OOOPs nope can't HUB */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Non-Hub link %s introduced %s.", + client_p->name, name); + ilog(L_SERVER, "Non-Hub link %s introduced %s.", + client_p->name, name); - rb_snprintf(squitreason, sizeof squitreason, - "No matching hub_mask for %s", - name); - exit_client(NULL, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "No matching hub_mask for %s", + name); + exit_client(NULL, client_p, &me, squitreason); + return 0; + } - /* Check for the new server being leafed behind this HUB */ - if(llined) - { - /* OOOPs nope can't HUB this leaf */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s introduced leafed server %s.", - client_p->name, name); - ilog(L_SERVER, "Link %s introduced leafed server %s.", - client_p->name, name); + /* Check for the new server being leafed behind this HUB */ + if(llined) { + /* OOOPs nope can't HUB this leaf */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s introduced leafed server %s.", + client_p->name, name); + ilog(L_SERVER, "Link %s introduced leafed server %s.", + client_p->name, name); - rb_snprintf(squitreason, sizeof squitreason, - "Matching leaf_mask for %s", - name); - exit_client(NULL, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "Matching leaf_mask for %s", + name); + exit_client(NULL, client_p, &me, squitreason); + return 0; + } - if(strlen(name) > HOSTLEN) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s introduced server with invalid servername %s", - client_p->name, name); - ilog(L_SERVER, "Link %s introduced server with invalid servername %s", - client_p->name, name); + if(strlen(name) > HOSTLEN) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s introduced server with invalid servername %s", + client_p->name, name); + ilog(L_SERVER, "Link %s introduced server with invalid servername %s", + client_p->name, name); - exit_client(NULL, client_p, &me, "Invalid servername introduced."); - return 0; - } + exit_client(NULL, client_p, &me, "Invalid servername introduced."); + return 0; + } - target_p = make_client(client_p); - make_server(target_p); - target_p->hopcount = hop; + target_p = make_client(client_p); + make_server(target_p); + target_p->hopcount = hop; - rb_strlcpy(target_p->name, name, sizeof(target_p->name)); + rb_strlcpy(target_p->name, name, sizeof(target_p->name)); - set_server_gecos(target_p, info); + set_server_gecos(target_p, info); - target_p->servptr = source_p; + target_p->servptr = source_p; - SetServer(target_p); + SetServer(target_p); - rb_dlinkAddTail(target_p, &target_p->node, &global_client_list); - rb_dlinkAddTailAlloc(target_p, &global_serv_list); - add_to_client_hash(target_p->name, target_p); - rb_dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->servers); + rb_dlinkAddTail(target_p, &target_p->node, &global_client_list); + rb_dlinkAddTailAlloc(target_p, &global_serv_list); + add_to_client_hash(target_p->name, target_p); + rb_dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->servers); - target_p->serv->nameinfo = scache_connect(target_p->name, target_p->info, IsHidden(target_p)); + target_p->serv->nameinfo = scache_connect(target_p->name, target_p->info, IsHidden(target_p)); - sendto_server(client_p, NULL, NOCAPS, NOCAPS, - ":%s SERVER %s %d :%s%s", - source_p->name, target_p->name, target_p->hopcount + 1, - IsHidden(target_p) ? "(H) " : "", target_p->info); + sendto_server(client_p, NULL, NOCAPS, NOCAPS, + ":%s SERVER %s %d :%s%s", + source_p->name, target_p->name, target_p->hopcount + 1, + IsHidden(target_p) ? "(H) " : "", target_p->info); - sendto_realops_snomask(SNO_EXTERNAL, L_ALL, - "Server %s being introduced by %s", target_p->name, source_p->name); + sendto_realops_snomask(SNO_EXTERNAL, L_ALL, + "Server %s being introduced by %s", target_p->name, source_p->name); - /* quick, dirty EOB. you know you love it. */ - sendto_one(target_p, ":%s PING %s %s", get_id(&me, target_p), me.name, target_p->name); + /* quick, dirty EOB. you know you love it. */ + sendto_one(target_p, ":%s PING %s %s", get_id(&me, target_p), me.name, target_p->name); - hdata.client = source_p; - hdata.target = target_p; - call_hook(h_server_introduced, &hdata); + hdata.client = source_p; + hdata.target = target_p; + call_hook(h_server_introduced, &hdata); - return 0; + return 0; } static int ms_sid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - struct remote_conf *hub_p; - hook_data_client hdata; - rb_dlink_node *ptr; - int hop; - int hlined = 0; - int llined = 0; - char squitreason[160]; + struct Client *target_p; + struct remote_conf *hub_p; + hook_data_client hdata; + rb_dlink_node *ptr; + int hop; + int hlined = 0; + int llined = 0; + char squitreason[160]; - hop = atoi(parv[2]); + hop = atoi(parv[2]); - /* collision on the name? */ - if((target_p = find_server(NULL, parv[1])) != NULL) - { - ilog(L_SERVER, "Link %s cancelled, server %s already exists", - client_p->name, parv[1]); + /* collision on the name? */ + if((target_p = find_server(NULL, parv[1])) != NULL) { + ilog(L_SERVER, "Link %s cancelled, server %s already exists", + client_p->name, parv[1]); - rb_snprintf(squitreason, sizeof squitreason, - "Server %s already exists", - parv[1]); - exit_client(NULL, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "Server %s already exists", + parv[1]); + exit_client(NULL, client_p, &me, squitreason); + return 0; + } - /* collision on the SID? */ - if((target_p = find_id(parv[3])) != NULL) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "Link %s cancelled, SID %s for server %s already in use by %s", - client_p->name, parv[3], parv[1], target_p->name); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s WALLOPS :Link %s cancelled, SID %s for server %s already in use by %s", - me.id, client_p->name, parv[3], parv[1], target_p->name); - ilog(L_SERVER, "Link %s cancelled, SID %s for server %s already in use by %s", - client_p->name, parv[3], parv[1], target_p->name); + /* collision on the SID? */ + if((target_p = find_id(parv[3])) != NULL) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "Link %s cancelled, SID %s for server %s already in use by %s", + client_p->name, parv[3], parv[1], target_p->name); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s WALLOPS :Link %s cancelled, SID %s for server %s already in use by %s", + me.id, client_p->name, parv[3], parv[1], target_p->name); + ilog(L_SERVER, "Link %s cancelled, SID %s for server %s already in use by %s", + client_p->name, parv[3], parv[1], target_p->name); - rb_snprintf(squitreason, sizeof squitreason, - "SID %s for %s already in use by %s", - parv[3], parv[1], target_p->name); - exit_client(NULL, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "SID %s for %s already in use by %s", + parv[3], parv[1], target_p->name); + exit_client(NULL, client_p, &me, squitreason); + return 0; + } - if(bogus_host(parv[1]) || strlen(parv[1]) > HOSTLEN) - { - sendto_one(client_p, "ERROR :Invalid servername"); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s cancelled, servername %s invalid", - client_p->name, parv[1]); - ilog(L_SERVER, "Link %s cancelled, servername %s invalid", - client_p->name, parv[1]); + if(bogus_host(parv[1]) || strlen(parv[1]) > HOSTLEN) { + sendto_one(client_p, "ERROR :Invalid servername"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s cancelled, servername %s invalid", + client_p->name, parv[1]); + ilog(L_SERVER, "Link %s cancelled, servername %s invalid", + client_p->name, parv[1]); - exit_client(NULL, client_p, &me, "Bogus server name"); - return 0; - } + exit_client(NULL, client_p, &me, "Bogus server name"); + return 0; + } - if(!IsDigit(parv[3][0]) || !IsIdChar(parv[3][1]) || - !IsIdChar(parv[3][2]) || parv[3][3] != '\0') - { - sendto_one(client_p, "ERROR :Invalid SID"); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s cancelled, SID %s invalid", - client_p->name, parv[3]); - ilog(L_SERVER, "Link %s cancelled, SID %s invalid", - client_p->name, parv[3]); + if(!IsDigit(parv[3][0]) || !IsIdChar(parv[3][1]) || + !IsIdChar(parv[3][2]) || parv[3][3] != '\0') { + sendto_one(client_p, "ERROR :Invalid SID"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s cancelled, SID %s invalid", + client_p->name, parv[3]); + ilog(L_SERVER, "Link %s cancelled, SID %s invalid", + client_p->name, parv[3]); - exit_client(NULL, client_p, &me, "Bogus SID"); - return 0; - } + exit_client(NULL, client_p, &me, "Bogus SID"); + return 0; + } - /* for the directly connected server: - * H: allows it to introduce a server matching that mask - * L: disallows it introducing a server matching that mask - */ - RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) - { - hub_p = ptr->data; + /* for the directly connected server: + * H: allows it to introduce a server matching that mask + * L: disallows it introducing a server matching that mask + */ + RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) { + hub_p = ptr->data; - if(match(hub_p->server, client_p->name) && match(hub_p->host, parv[1])) - { - if(hub_p->flags & CONF_HUB) - hlined++; - else - llined++; - } - } + if(match(hub_p->server, client_p->name) && match(hub_p->host, parv[1])) { + if(hub_p->flags & CONF_HUB) + hlined++; + else + llined++; + } + } - /* no matching hub_mask */ - if(!hlined) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Non-Hub link %s introduced %s.", - client_p->name, parv[1]); - ilog(L_SERVER, "Non-Hub link %s introduced %s.", - client_p->name, parv[1]); + /* no matching hub_mask */ + if(!hlined) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Non-Hub link %s introduced %s.", + client_p->name, parv[1]); + ilog(L_SERVER, "Non-Hub link %s introduced %s.", + client_p->name, parv[1]); - rb_snprintf(squitreason, sizeof squitreason, - "No matching hub_mask for %s", - parv[1]); - exit_client(NULL, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "No matching hub_mask for %s", + parv[1]); + exit_client(NULL, client_p, &me, squitreason); + return 0; + } - /* matching leaf_mask */ - if(llined) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s introduced leafed server %s.", - client_p->name, parv[1]); - ilog(L_SERVER, "Link %s introduced leafed server %s.", - client_p->name, parv[1]); + /* matching leaf_mask */ + if(llined) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s introduced leafed server %s.", + client_p->name, parv[1]); + ilog(L_SERVER, "Link %s introduced leafed server %s.", + client_p->name, parv[1]); - rb_snprintf(squitreason, sizeof squitreason, - "Matching leaf_mask for %s", - parv[1]); - exit_client(NULL, client_p, &me, squitreason); - return 0; - } + rb_snprintf(squitreason, sizeof squitreason, + "Matching leaf_mask for %s", + parv[1]); + exit_client(NULL, client_p, &me, squitreason); + return 0; + } - /* ok, alls good */ - target_p = make_client(client_p); - make_server(target_p); + /* ok, alls good */ + target_p = make_client(client_p); + make_server(target_p); - rb_strlcpy(target_p->name, parv[1], sizeof(target_p->name)); - target_p->hopcount = atoi(parv[2]); - strcpy(target_p->id, parv[3]); - set_server_gecos(target_p, parv[4]); + rb_strlcpy(target_p->name, parv[1], sizeof(target_p->name)); + target_p->hopcount = atoi(parv[2]); + strcpy(target_p->id, parv[3]); + set_server_gecos(target_p, parv[4]); - target_p->servptr = source_p; - SetServer(target_p); + target_p->servptr = source_p; + SetServer(target_p); - rb_dlinkAddTail(target_p, &target_p->node, &global_client_list); - rb_dlinkAddTailAlloc(target_p, &global_serv_list); - add_to_client_hash(target_p->name, target_p); - add_to_id_hash(target_p->id, target_p); - rb_dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->servers); + rb_dlinkAddTail(target_p, &target_p->node, &global_client_list); + rb_dlinkAddTailAlloc(target_p, &global_serv_list); + add_to_client_hash(target_p->name, target_p); + add_to_id_hash(target_p->id, target_p); + rb_dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->servers); - target_p->serv->nameinfo = scache_connect(target_p->name, target_p->info, IsHidden(target_p)); + target_p->serv->nameinfo = scache_connect(target_p->name, target_p->info, IsHidden(target_p)); - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s SID %s %d %s :%s%s", - source_p->id, target_p->name, target_p->hopcount + 1, - target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s SID %s %d %s :%s%s", + source_p->id, target_p->name, target_p->hopcount + 1, + target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info); - sendto_realops_snomask(SNO_EXTERNAL, L_ALL, - "Server %s being introduced by %s", target_p->name, source_p->name); + sendto_realops_snomask(SNO_EXTERNAL, L_ALL, + "Server %s being introduced by %s", target_p->name, source_p->name); - /* quick, dirty EOB. you know you love it. */ - sendto_one(target_p, ":%s PING %s %s", - get_id(&me, target_p), me.name, get_id(target_p, target_p)); + /* quick, dirty EOB. you know you love it. */ + sendto_one(target_p, ":%s PING %s %s", + get_id(&me, target_p), me.name, get_id(target_p, target_p)); - hdata.client = source_p; - hdata.target = target_p; - call_hook(h_server_introduced, &hdata); + hdata.client = source_p; + hdata.target = target_p; + call_hook(h_server_introduced, &hdata); - return 0; + return 0; } /* set_server_gecos() @@ -654,65 +626,59 @@ ms_sid(struct Client *client_p, struct Client *source_p, int parc, const char *p static int set_server_gecos(struct Client *client_p, const char *info) { - /* check the info for [IP] */ - if(info[0]) - { - char *p; - char *s; + /* check the info for [IP] */ + if(info[0]) { + char *p; + char *s; - s = LOCAL_COPY(info); + s = LOCAL_COPY(info); - /* we should only check the first word for an ip */ - if((p = strchr(s, ' '))) - *p = '\0'; + /* we should only check the first word for an ip */ + if((p = strchr(s, ' '))) + *p = '\0'; - /* check for a ] which would symbolise an [IP] */ - if(strchr(s, ']')) - { - /* set s to after the first space */ - if(p) - s = ++p; - else - s = NULL; - } - /* no ], put the space back */ - else if(p) - *p = ' '; + /* check for a ] which would symbolise an [IP] */ + if(strchr(s, ']')) { + /* set s to after the first space */ + if(p) + s = ++p; + else + s = NULL; + } + /* no ], put the space back */ + else if(p) + *p = ' '; - /* p may have been set to a trailing space, so check s exists and that - * it isnt \0 */ - if(s && (*s != '\0')) - { - /* a space? if not (H) could be the last part of info.. */ - if((p = strchr(s, ' '))) - *p = '\0'; + /* p may have been set to a trailing space, so check s exists and that + * it isnt \0 */ + if(s && (*s != '\0')) { + /* a space? if not (H) could be the last part of info.. */ + if((p = strchr(s, ' '))) + *p = '\0'; - /* check for (H) which is a hidden server */ - if(!strcmp(s, "(H)")) - { - SetHidden(client_p); + /* check for (H) which is a hidden server */ + if(!strcmp(s, "(H)")) { + SetHidden(client_p); - /* if there was no space.. theres nothing to set info to */ - if(p) - s = ++p; - else - s = NULL; - } - else if(p) - *p = ' '; + /* if there was no space.. theres nothing to set info to */ + if(p) + s = ++p; + else + s = NULL; + } else if(p) + *p = ' '; - /* if there was a trailing space, s could point to \0, so check */ - if(s && (*s != '\0')) - { - rb_strlcpy(client_p->info, s, sizeof(client_p->info)); - return 1; - } - } - } + /* if there was a trailing space, s could point to \0, so check */ + if(s && (*s != '\0')) { + rb_strlcpy(client_p->info, s, sizeof(client_p->info)); + return 1; + } + } + } - rb_strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); + rb_strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); - return 1; + return 1; } /* @@ -725,23 +691,21 @@ set_server_gecos(struct Client *client_p, const char *info) int bogus_host(const char *host) { - int bogus_server = 0; - const char *s; - int dots = 0; + int bogus_server = 0; + const char *s; + int dots = 0; - for(s = host; *s; s++) - { - if(!IsServChar(*s)) - { - bogus_server = 1; - break; - } - if('.' == *s) - ++dots; - } + for(s = host; *s; s++) { + if(!IsServChar(*s)) { + bogus_server = 1; + break; + } + if('.' == *s) + ++dots; + } - if(!dots || bogus_server) - return 1; + if(!dots || bogus_server) + return 1; - return 0; + return 0; } diff --git a/modules/core/m_squit.c b/modules/core/m_squit.c index f4fa5f2..4bb3267 100644 --- a/modules/core/m_squit.c +++ b/modules/core/m_squit.c @@ -43,22 +43,21 @@ static int ms_squit(struct Client *, struct Client *, int, const char **); static int mo_squit(struct Client *, struct Client *, int, const char **); struct Message squit_msgtab = { - "SQUIT", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_squit, 0}, {ms_squit, 0}, mg_ignore, {mo_squit, 2}} + "SQUIT", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_squit, 0}, {ms_squit, 0}, mg_ignore, {mo_squit, 2}} }; mapi_clist_av1 squit_clist[] = { &squit_msgtab, NULL }; DECLARE_MODULE_AV1(squit, NULL, NULL, squit_clist, NULL, NULL, "$Revision: 3161 $"); -struct squit_parms -{ - const char *server_name; - struct Client *target_p; +struct squit_parms { + const char *server_name; + struct Client *target_p; }; static struct squit_parms *find_squit(struct Client *client_p, - struct Client *source_p, const char *server); + struct Client *source_p, const char *server); /* @@ -69,37 +68,31 @@ static struct squit_parms *find_squit(struct Client *client_p, static int mo_squit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct squit_parms *found_squit; - const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name; + struct squit_parms *found_squit; + const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name; - if((found_squit = find_squit(client_p, source_p, parv[1]))) - { - if(MyConnect(found_squit->target_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Received SQUIT %s from %s (%s)", - found_squit->target_p->name, - get_client_name(source_p, HIDE_IP), comment); - ilog(L_SERVER, "Received SQUIT %s from %s (%s)", - found_squit->target_p->name, log_client_name(source_p, HIDE_IP), - comment); - } - else if(!IsOperRemote(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remote"); - return 0; - } + if((found_squit = find_squit(client_p, source_p, parv[1]))) { + if(MyConnect(found_squit->target_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Received SQUIT %s from %s (%s)", + found_squit->target_p->name, + get_client_name(source_p, HIDE_IP), comment); + ilog(L_SERVER, "Received SQUIT %s from %s (%s)", + found_squit->target_p->name, log_client_name(source_p, HIDE_IP), + comment); + } else if(!IsOperRemote(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remote"); + return 0; + } - exit_client(client_p, found_squit->target_p, source_p, comment); - return 0; - } - else - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[1]); - } + exit_client(client_p, found_squit->target_p, source_p, comment); + return 0; + } else { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[1]); + } - return 0; + return 0; } /* @@ -110,45 +103,42 @@ mo_squit(struct Client *client_p, struct Client *source_p, int parc, const char static int ms_squit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name; + struct Client *target_p; + const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name; - if(parc < 2) - target_p = client_p; - else - { - if((target_p = find_server(NULL, parv[1])) == NULL) - return 0; + if(parc < 2) + target_p = client_p; + else { + if((target_p = find_server(NULL, parv[1])) == NULL) + return 0; - if(IsMe(target_p)) - target_p = client_p; - if(!IsServer(target_p)) - return 0; - } + if(IsMe(target_p)) + target_p = client_p; + if(!IsServer(target_p)) + return 0; + } - /* Server is closing its link */ - if (target_p == client_p) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Server %s closing link (%s)", - target_p->name, comment); - } - /* - ** Notify all opers, if my local link is remotely squitted - */ - else if(MyConnect(target_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "Remote SQUIT %s from %s (%s)", - target_p->name, source_p->name, comment); + /* Server is closing its link */ + if (target_p == client_p) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Server %s closing link (%s)", + target_p->name, comment); + } + /* + ** Notify all opers, if my local link is remotely squitted + */ + else if(MyConnect(target_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "Remote SQUIT %s from %s (%s)", + target_p->name, source_p->name, comment); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s WALLOPS :Remote SQUIT %s from %s (%s)", - me.id, target_p->name, source_p->name, comment); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s WALLOPS :Remote SQUIT %s from %s (%s)", + me.id, target_p->name, source_p->name, comment); - ilog(L_SERVER, "SQUIT From %s : %s (%s)", source_p->name, target_p->name, comment); - } - exit_client(client_p, target_p, source_p, comment); - return 0; + ilog(L_SERVER, "SQUIT From %s : %s (%s)", source_p->name, target_p->name, comment); + } + exit_client(client_p, target_p, source_p, comment); + return 0; } @@ -163,58 +153,51 @@ ms_squit(struct Client *client_p, struct Client *source_p, int parc, const char static struct squit_parms * find_squit(struct Client *client_p, struct Client *source_p, const char *server) { - static struct squit_parms found_squit; - struct Client *target_p = NULL; - struct Client *p; - rb_dlink_node *ptr; + static struct squit_parms found_squit; + struct Client *target_p = NULL; + struct Client *p; + rb_dlink_node *ptr; - /* must ALWAYS be reset */ - found_squit.target_p = NULL; - found_squit.server_name = NULL; + /* must ALWAYS be reset */ + found_squit.target_p = NULL; + found_squit.server_name = NULL; - /* - ** The following allows wild cards in SQUIT. Only useful - ** when the command is issued by an oper. - */ + /* + ** The following allows wild cards in SQUIT. Only useful + ** when the command is issued by an oper. + */ - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - p = ptr->data; - if(IsServer(p) || IsMe(p)) - { - if(match(server, p->name)) - { - target_p = p; - break; - } - } - } + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + p = ptr->data; + if(IsServer(p) || IsMe(p)) { + if(match(server, p->name)) { + target_p = p; + break; + } + } + } - if(target_p == NULL) - return NULL; + if(target_p == NULL) + return NULL; - found_squit.target_p = target_p; - found_squit.server_name = server; + found_squit.target_p = target_p; + found_squit.server_name = server; - if(IsMe(target_p)) - { - if(IsClient(client_p)) - { - if(MyClient(client_p)) - sendto_one_notice(source_p, ":You are trying to squit me."); + if(IsMe(target_p)) { + if(IsClient(client_p)) { + if(MyClient(client_p)) + sendto_one_notice(source_p, ":You are trying to squit me."); - return NULL; - } - else - { - found_squit.target_p = client_p; - found_squit.server_name = client_p->name; - } - } + return NULL; + } else { + found_squit.target_p = client_p; + found_squit.server_name = client_p->name; + } + } - if(found_squit.target_p != NULL) - return &found_squit; - else - return (NULL); + if(found_squit.target_p != NULL) + return &found_squit; + else + return (NULL); } diff --git a/modules/m_accept.c b/modules/m_accept.c index 76a22ab..86d7b39 100644 --- a/modules/m_accept.c +++ b/modules/m_accept.c @@ -42,12 +42,12 @@ static void add_accept(struct Client *, struct Client *); static void list_accepts(struct Client *); struct Message accept_msgtab = { - "ACCEPT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {mg_unreg, {m_accept, 2}, mg_ignore, mg_ignore, mg_ignore, {m_accept, 2}} + "ACCEPT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {mg_unreg, {m_accept, 2}, mg_ignore, mg_ignore, mg_ignore, {m_accept, 2}} }; mapi_clist_av1 accept_clist[] = { - &accept_msgtab, NULL + &accept_msgtab, NULL }; DECLARE_MODULE_AV1(accept, NULL, NULL, accept_clist, NULL, NULL, "$Revision: 254 $"); @@ -58,78 +58,70 @@ DECLARE_MODULE_AV1(accept, NULL, NULL, accept_clist, NULL, NULL, "$Revision: 254 static int m_accept(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *nick; - char *p = NULL; - static char addbuf[BUFSIZE]; - static char delbuf[BUFSIZE]; - struct Client *target_p; - int accept_num; + char *nick; + char *p = NULL; + static char addbuf[BUFSIZE]; + static char delbuf[BUFSIZE]; + struct Client *target_p; + int accept_num; - if(*parv[1] == '*') - { - list_accepts(source_p); - return 0; - } + if(*parv[1] == '*') { + list_accepts(source_p); + return 0; + } - build_nicklist(source_p, addbuf, delbuf, parv[1]); + build_nicklist(source_p, addbuf, delbuf, parv[1]); - /* parse the delete list */ - for (nick = rb_strtok_r(delbuf, ",", &p); nick != NULL; nick = rb_strtok_r(NULL, ",", &p)) - { - /* shouldnt happen, but lets be paranoid */ - if((target_p = find_named_person(nick)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); - continue; - } + /* parse the delete list */ + for (nick = rb_strtok_r(delbuf, ",", &p); nick != NULL; nick = rb_strtok_r(NULL, ",", &p)) { + /* shouldnt happen, but lets be paranoid */ + if((target_p = find_named_person(nick)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); + continue; + } - /* user isnt on clients accept list */ - if(!accept_message(target_p, source_p)) - { - sendto_one(source_p, form_str(ERR_ACCEPTNOT), - me.name, source_p->name, target_p->name); - continue; - } + /* user isnt on clients accept list */ + if(!accept_message(target_p, source_p)) { + sendto_one(source_p, form_str(ERR_ACCEPTNOT), + me.name, source_p->name, target_p->name); + continue; + } - rb_dlinkFindDestroy(target_p, &source_p->localClient->allow_list); - rb_dlinkFindDestroy(source_p, &target_p->on_allow_list); - } + rb_dlinkFindDestroy(target_p, &source_p->localClient->allow_list); + rb_dlinkFindDestroy(source_p, &target_p->on_allow_list); + } - /* get the number of accepts they have */ - accept_num = rb_dlink_list_length(&source_p->localClient->allow_list); + /* get the number of accepts they have */ + accept_num = rb_dlink_list_length(&source_p->localClient->allow_list); - /* parse the add list */ - for (nick = rb_strtok_r(addbuf, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p), accept_num++) - { - /* shouldnt happen, but lets be paranoid */ - if((target_p = find_named_person(nick)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), nick); - continue; - } + /* parse the add list */ + for (nick = rb_strtok_r(addbuf, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p), accept_num++) { + /* shouldnt happen, but lets be paranoid */ + if((target_p = find_named_person(nick)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), nick); + continue; + } - /* user is already on clients accept list */ - if(accept_message(target_p, source_p)) - { - sendto_one(source_p, form_str(ERR_ACCEPTEXIST), - me.name, source_p->name, target_p->name); - continue; - } + /* user is already on clients accept list */ + if(accept_message(target_p, source_p)) { + sendto_one(source_p, form_str(ERR_ACCEPTEXIST), + me.name, source_p->name, target_p->name); + continue; + } - if(accept_num >= ConfigFileEntry.max_accept) - { - sendto_one(source_p, form_str(ERR_ACCEPTFULL), me.name, source_p->name); - return 0; - } + if(accept_num >= ConfigFileEntry.max_accept) { + sendto_one(source_p, form_str(ERR_ACCEPTFULL), me.name, source_p->name); + return 0; + } - /* why is this here? */ - /* del_from accept(target_p, source_p); */ - add_accept(source_p, target_p); - } + /* why is this here? */ + /* del_from accept(target_p, source_p); */ + add_accept(source_p, target_p); + } - return 0; + return 0; } /* @@ -139,57 +131,52 @@ m_accept(struct Client *client_p, struct Client *source_p, int parc, const char * - pointer to addbuffer * - pointer to remove buffer * - pointer to list of nicks - * output - + * output - * side effects - addbuf/delbuf are modified to give valid nicks */ static void build_nicklist(struct Client *source_p, char *addbuf, char *delbuf, const char *nicks) { - char *name; - char *p; - int lenadd; - int lendel; - int del; - char *n = LOCAL_COPY(nicks); + char *name; + char *p; + int lenadd; + int lendel; + int del; + char *n = LOCAL_COPY(nicks); - *addbuf = *delbuf = '\0'; - del = lenadd = lendel = 0; + *addbuf = *delbuf = '\0'; + del = lenadd = lendel = 0; - /* build list of clients to add into addbuf, clients to remove in delbuf */ - for (name = rb_strtok_r(n, ",", &p); name; name = rb_strtok_r(NULL, ",", &p), del = 0) - { - if(*name == '-') - { - del = 1; - name++; - } + /* build list of clients to add into addbuf, clients to remove in delbuf */ + for (name = rb_strtok_r(n, ",", &p); name; name = rb_strtok_r(NULL, ",", &p), del = 0) { + if(*name == '-') { + del = 1; + name++; + } - if(find_named_person(name) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), name); - continue; - } + if(find_named_person(name) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), name); + continue; + } - /* we're deleting a client */ - if(del) - { - if(*delbuf) - (void) strcat(delbuf, ","); + /* we're deleting a client */ + if(del) { + if(*delbuf) + (void) strcat(delbuf, ","); - (void) strncat(delbuf, name, BUFSIZE - lendel - 1); - lendel += strlen(name) + 1; - } - /* adding a client */ - else - { - if(*addbuf) - (void) strcat(addbuf, ","); + (void) strncat(delbuf, name, BUFSIZE - lendel - 1); + lendel += strlen(name) + 1; + } + /* adding a client */ + else { + if(*addbuf) + (void) strcat(addbuf, ","); - (void) strncat(addbuf, name, BUFSIZE - lenadd - 1); - lenadd += strlen(name) + 1; - } - } + (void) strncat(addbuf, name, BUFSIZE - lenadd - 1); + lenadd += strlen(name) + 1; + } + } } /* @@ -203,8 +190,8 @@ build_nicklist(struct Client *source_p, char *addbuf, char *delbuf, const char * static void add_accept(struct Client *source_p, struct Client *target_p) { - rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); - rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); + rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); + rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); } @@ -218,42 +205,39 @@ add_accept(struct Client *source_p, struct Client *target_p) static void list_accepts(struct Client *source_p) { - rb_dlink_node *ptr; - struct Client *target_p; - char nicks[BUFSIZE]; - int len = 0; - int len2 = 0; - int count = 0; + rb_dlink_node *ptr; + struct Client *target_p; + char nicks[BUFSIZE]; + int len = 0; + int len2 = 0; + int count = 0; - *nicks = '\0'; - len2 = strlen(source_p->name) + 10; + *nicks = '\0'; + len2 = strlen(source_p->name) + 10; - RB_DLINK_FOREACH(ptr, source_p->localClient->allow_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, source_p->localClient->allow_list.head) { + target_p = ptr->data; - if(target_p) - { + if(target_p) { - if((len + strlen(target_p->name) + len2 > BUFSIZE) || count > 14) - { - sendto_one(source_p, form_str(RPL_ACCEPTLIST), - me.name, source_p->name, nicks); + if((len + strlen(target_p->name) + len2 > BUFSIZE) || count > 14) { + sendto_one(source_p, form_str(RPL_ACCEPTLIST), + me.name, source_p->name, nicks); - len = count = 0; - *nicks = '\0'; - } + len = count = 0; + *nicks = '\0'; + } - len += rb_snprintf(nicks + len, sizeof(nicks) - len, "%s ", target_p->name); - count++; - } - } + len += rb_snprintf(nicks + len, sizeof(nicks) - len, "%s ", target_p->name); + count++; + } + } - if(*nicks) - sendto_one(source_p, form_str(RPL_ACCEPTLIST), - me.name, source_p->name, nicks); + if(*nicks) + sendto_one(source_p, form_str(RPL_ACCEPTLIST), + me.name, source_p->name, nicks); - sendto_one(source_p, form_str(RPL_ENDOFACCEPT), - me.name, source_p->name); + sendto_one(source_p, form_str(RPL_ENDOFACCEPT), + me.name, source_p->name); } diff --git a/modules/m_admin.c b/modules/m_admin.c index e404a6f..c5fd6c7 100644 --- a/modules/m_admin.c +++ b/modules/m_admin.c @@ -43,43 +43,41 @@ static void do_admin(struct Client *source_p); static void admin_spy(struct Client *); struct Message admin_msgtab = { - "ADMIN", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_admin, 0}, {m_admin, 0}, {ms_admin, 0}, mg_ignore, mg_ignore, {ms_admin, 0}} + "ADMIN", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_admin, 0}, {m_admin, 0}, {ms_admin, 0}, mg_ignore, mg_ignore, {ms_admin, 0}} }; int doing_admin_hook; mapi_clist_av1 admin_clist[] = { &admin_msgtab, NULL }; -mapi_hlist_av1 admin_hlist[] = { - { "doing_admin", &doing_admin_hook }, - { NULL, NULL } +mapi_hlist_av1 admin_hlist[] = { + { "doing_admin", &doing_admin_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(admin, NULL, NULL, admin_clist, admin_hlist, NULL, "$Revision: 3368 $"); /* * mr_admin - ADMIN command handler - * parv[1] = servername + * parv[1] = servername */ static int mr_admin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0L; + static time_t last_used = 0L; - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, - EmptyString(source_p->name) ? "*" : source_p->name, - "ADMIN"); - return 0; - } - else - last_used = rb_current_time(); + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, + EmptyString(source_p->name) ? "*" : source_p->name, + "ADMIN"); + return 0; + } else + last_used = rb_current_time(); - do_admin(source_p); + do_admin(source_p); - return 0; + return 0; } /* @@ -89,26 +87,23 @@ mr_admin(struct Client *client_p, struct Client *source_p, int parc, const char static int m_admin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0L; + static time_t last_used = 0L; - if(parc > 1) - { - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "ADMIN"); - return 0; - } - else - last_used = rb_current_time(); - - if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME) - return 0; - } + if(parc > 1) { + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "ADMIN"); + return 0; + } else + last_used = rb_current_time(); - do_admin(source_p); + if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME) + return 0; + } - return 0; + do_admin(source_p); + + return 0; } @@ -119,12 +114,12 @@ m_admin(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_admin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME) + return 0; - do_admin(source_p); + do_admin(source_p); - return 0; + return 0; } @@ -138,16 +133,16 @@ ms_admin(struct Client *client_p, struct Client *source_p, int parc, const char static void do_admin(struct Client *source_p) { - if(IsPerson(source_p)) - admin_spy(source_p); + if(IsPerson(source_p)) + admin_spy(source_p); - sendto_one_numeric(source_p, RPL_ADMINME, form_str(RPL_ADMINME), me.name); - if(AdminInfo.name != NULL) - sendto_one_numeric(source_p, RPL_ADMINLOC1, form_str(RPL_ADMINLOC1), AdminInfo.name); - if(AdminInfo.description != NULL) - sendto_one_numeric(source_p, RPL_ADMINLOC2, form_str(RPL_ADMINLOC2), AdminInfo.description); - if(AdminInfo.email != NULL) - sendto_one_numeric(source_p, RPL_ADMINEMAIL, form_str(RPL_ADMINEMAIL), AdminInfo.email); + sendto_one_numeric(source_p, RPL_ADMINME, form_str(RPL_ADMINME), me.name); + if(AdminInfo.name != NULL) + sendto_one_numeric(source_p, RPL_ADMINLOC1, form_str(RPL_ADMINLOC1), AdminInfo.name); + if(AdminInfo.description != NULL) + sendto_one_numeric(source_p, RPL_ADMINLOC2, form_str(RPL_ADMINLOC2), AdminInfo.description); + if(AdminInfo.email != NULL) + sendto_one_numeric(source_p, RPL_ADMINEMAIL, form_str(RPL_ADMINEMAIL), AdminInfo.email); } /* admin_spy() @@ -159,10 +154,10 @@ do_admin(struct Client *source_p) static void admin_spy(struct Client *source_p) { - hook_data hd; + hook_data hd; - hd.client = source_p; - hd.arg1 = hd.arg2 = NULL; + hd.client = source_p; + hd.arg1 = hd.arg2 = NULL; - call_hook(doing_admin_hook, &hd); + call_hook(doing_admin_hook, &hd); } diff --git a/modules/m_away.c b/modules/m_away.c index e8e26be..44ebb80 100644 --- a/modules/m_away.c +++ b/modules/m_away.c @@ -40,15 +40,15 @@ static int m_away(struct Client *, struct Client *, int, const char **); struct Message away_msgtab = { - "AWAY", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_away, 0}, {m_away, 0}, mg_ignore, mg_ignore, {m_away, 0}} + "AWAY", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_away, 0}, {m_away, 0}, mg_ignore, mg_ignore, {m_away, 0}} }; mapi_clist_av1 away_clist[] = { &away_msgtab, NULL }; DECLARE_MODULE_AV1(away, NULL, NULL, away_clist, NULL, NULL, "$Revision: 3370 $"); /*********************************************************************** - * m_away() - Added 14 Dec 1988 by jto. + * m_away() - Added 14 Dec 1988 by jto. * Not currently really working, I don't like this * call at all... * @@ -56,7 +56,7 @@ DECLARE_MODULE_AV1(away, NULL, NULL, away_clist, NULL, NULL, "$Revision: 3370 $" * but perhaps it's worth the load it causes to net. * This requires flooding of the whole net like NICK, * USER, MODE, etc messages... --msa - * + * * The above comments have long since irrelvant, but * are kept for historical purposes now ;) ***********************************************************************/ @@ -68,65 +68,60 @@ DECLARE_MODULE_AV1(away, NULL, NULL, away_clist, NULL, NULL, "$Revision: 3370 $" static int m_away(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(MyClient(source_p) && source_p->localClient->next_away && - !IsFloodDone(source_p)) - flood_endgrace(source_p); + if(MyClient(source_p) && source_p->localClient->next_away && + !IsFloodDone(source_p)) + flood_endgrace(source_p); - if(!IsClient(source_p)) - return 0; + if(!IsClient(source_p)) + return 0; - if(parc < 2 || EmptyString(parv[1])) - { - /* Marking as not away */ - if(source_p->user->away != NULL) - { - /* we now send this only if they were away before --is */ - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s AWAY", use_id(source_p)); - free_away(source_p); + if(parc < 2 || EmptyString(parv[1])) { + /* Marking as not away */ + if(source_p->user->away != NULL) { + /* we now send this only if they were away before --is */ + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s AWAY", use_id(source_p)); + free_away(source_p); sendto_common_channels_local_butone(source_p, CLICAP_AWAY_NOTIFY, ":%s!%s@%s AWAY", - source_p->name, source_p->username, source_p->host); - } - if(MyConnect(source_p)) - sendto_one_numeric(source_p, RPL_UNAWAY, form_str(RPL_UNAWAY)); - return 0; - } + source_p->name, source_p->username, source_p->host); + } + if(MyConnect(source_p)) + sendto_one_numeric(source_p, RPL_UNAWAY, form_str(RPL_UNAWAY)); + return 0; + } - /* Rate limit this because it is sent to common channels. */ - if (MyClient(source_p)) - { - if(!IsOper(source_p) && - source_p->localClient->next_away > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "AWAY"); - return; - } - if(source_p->localClient->next_away < rb_current_time() - - ConfigFileEntry.away_interval) - source_p->localClient->next_away = rb_current_time(); - else - source_p->localClient->next_away = rb_current_time() + - ConfigFileEntry.away_interval; - } + /* Rate limit this because it is sent to common channels. */ + if (MyClient(source_p)) { + if(!IsOper(source_p) && + source_p->localClient->next_away > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "AWAY"); + return; + } + if(source_p->localClient->next_away < rb_current_time() - + ConfigFileEntry.away_interval) + source_p->localClient->next_away = rb_current_time(); + else + source_p->localClient->next_away = rb_current_time() + + ConfigFileEntry.away_interval; + } - if(source_p->user->away == NULL) - allocate_away(source_p); - if(strncmp(source_p->user->away, parv[1], AWAYLEN - 1)) - { - rb_strlcpy(source_p->user->away, parv[1], AWAYLEN); - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s AWAY :%s", use_id(source_p), source_p->user->away); - } + if(source_p->user->away == NULL) + allocate_away(source_p); + if(strncmp(source_p->user->away, parv[1], AWAYLEN - 1)) { + rb_strlcpy(source_p->user->away, parv[1], AWAYLEN); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s AWAY :%s", use_id(source_p), source_p->user->away); + } - if(MyConnect(source_p)) - sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY)); + if(MyConnect(source_p)) + sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY)); sendto_common_channels_local_butone(source_p, CLICAP_AWAY_NOTIFY, ":%s!%s@%s AWAY :%s", - source_p->name, source_p->username, source_p->host, - source_p->user->away); + source_p->name, source_p->username, source_p->host, + source_p->user->away); - return 0; + return 0; } diff --git a/modules/m_cap.c b/modules/m_cap.c index 45cb025..545aa81 100644 --- a/modules/m_cap.c +++ b/modules/m_cap.c @@ -1,5 +1,5 @@ /* modules/m_cap.c - * + * * Copyright (C) 2005 Lee Hardy * Copyright (C) 2005 ircd-ratbox development team * @@ -47,8 +47,8 @@ static int m_cap(struct Client *, struct Client *, int, const char **); static int modinit(void); struct Message cap_msgtab = { - "CAP", 0, 0, 0, MFLG_SLOW, - {{m_cap, 2}, {m_cap, 2}, mg_ignore, mg_ignore, mg_ignore, {m_cap, 2}} + "CAP", 0, 0, 0, MFLG_SLOW, + {{m_cap, 2}, {m_cap, 2}, mg_ignore, mg_ignore, mg_ignore, {m_cap, 2}} }; mapi_clist_av1 cap_clist[] = { &cap_msgtab, NULL }; @@ -59,13 +59,12 @@ DECLARE_MODULE_AV1(cap, modinit, NULL, cap_clist, NULL, NULL, "$Revision: 676 $" #define CLICAP_FLAGS_STICKY 0x001 -static struct clicap -{ - const char *name; - int cap_serv; /* for altering s->c */ - int cap_cli; /* for altering c->s */ - int flags; - int namelen; +static struct clicap { + const char *name; + int cap_serv; /* for altering s->c */ + int cap_cli; /* for altering c->s */ + int flags; + int namelen; } clicap_list[] = { _CLICAP("multi-prefix", CLICAP_MULTI_PREFIX, 0, 0), _CLICAP("sasl", CLICAP_SASL, 0, 0), @@ -81,21 +80,21 @@ static int clicap_sort(struct clicap *, struct clicap *); static int modinit(void) { - qsort(clicap_list, CLICAP_LIST_LEN, sizeof(struct clicap), - (bqcmp) clicap_sort); - return 0; + qsort(clicap_list, CLICAP_LIST_LEN, sizeof(struct clicap), + (bqcmp) clicap_sort); + return 0; } static int clicap_sort(struct clicap *one, struct clicap *two) { - return irccmp(one->name, two->name); + return irccmp(one->name, two->name); } static int clicap_compare(const char *name, struct clicap *cap) { - return irccmp(name, cap->name); + return irccmp(name, cap->name); } /* clicap_find() @@ -109,55 +108,51 @@ clicap_compare(const char *name, struct clicap *cap) static struct clicap * clicap_find(const char *data, int *negate, int *finished) { - static char buf[BUFSIZE]; - static char *p; - struct clicap *cap; - char *s; + static char buf[BUFSIZE]; + static char *p; + struct clicap *cap; + char *s; - *negate = 0; + *negate = 0; - if(data) - { - rb_strlcpy(buf, data, sizeof(buf)); - p = buf; - } + if(data) { + rb_strlcpy(buf, data, sizeof(buf)); + p = buf; + } - if(*finished) - return NULL; + if(*finished) + return NULL; - /* skip any whitespace */ - while(*p && IsSpace(*p)) - p++; + /* skip any whitespace */ + while(*p && IsSpace(*p)) + p++; - if(EmptyString(p)) - { - *finished = 1; - return NULL; - } + if(EmptyString(p)) { + *finished = 1; + return NULL; + } - if(*p == '-') - { - *negate = 1; - p++; + if(*p == '-') { + *negate = 1; + p++; - /* someone sent a '-' without a parameter.. */ - if(*p == '\0') - return NULL; - } + /* someone sent a '-' without a parameter.. */ + if(*p == '\0') + return NULL; + } - if((s = strchr(p, ' '))) - *s++ = '\0'; + if((s = strchr(p, ' '))) + *s++ = '\0'; - if((cap = bsearch(p, clicap_list, CLICAP_LIST_LEN, - sizeof(struct clicap), (bqcmp) clicap_compare))) - { - if(s) - p = s; - else - *finished = 1; - } + if((cap = bsearch(p, clicap_list, CLICAP_LIST_LEN, + sizeof(struct clicap), (bqcmp) clicap_compare))) { + if(s) + p = s; + else + *finished = 1; + } - return cap; + return cap; } /* clicap_generate() @@ -171,308 +166,281 @@ clicap_find(const char *data, int *negate, int *finished) static void clicap_generate(struct Client *source_p, const char *subcmd, int flags, int clear) { - char buf[BUFSIZE]; - char capbuf[BUFSIZE]; - char *p; - int buflen = 0; - int curlen, mlen; - size_t i; + char buf[BUFSIZE]; + char capbuf[BUFSIZE]; + char *p; + int buflen = 0; + int curlen, mlen; + size_t i; - mlen = rb_sprintf(buf, ":%s CAP %s %s", - me.name, - EmptyString(source_p->name) ? "*" : source_p->name, - subcmd); + mlen = rb_sprintf(buf, ":%s CAP %s %s", + me.name, + EmptyString(source_p->name) ? "*" : source_p->name, + subcmd); - p = capbuf; - buflen = mlen; + p = capbuf; + buflen = mlen; - /* shortcut, nothing to do */ - if(flags == -1) - { - sendto_one(source_p, "%s :", buf); - return; - } + /* shortcut, nothing to do */ + if(flags == -1) { + sendto_one(source_p, "%s :", buf); + return; + } - for(i = 0; i < CLICAP_LIST_LEN; i++) - { - if(flags) - { - if(!IsCapable(source_p, clicap_list[i].cap_serv)) - continue; - /* they are capable of this, check sticky */ - else if(clear && clicap_list[i].flags & CLICAP_FLAGS_STICKY) - continue; - } + for(i = 0; i < CLICAP_LIST_LEN; i++) { + if(flags) { + if(!IsCapable(source_p, clicap_list[i].cap_serv)) + continue; + /* they are capable of this, check sticky */ + else if(clear && clicap_list[i].flags & CLICAP_FLAGS_STICKY) + continue; + } - /* \r\n\0, possible "-~=", space, " *" */ - if(buflen + clicap_list[i].namelen >= BUFSIZE - 10) - { - /* remove our trailing space -- if buflen == mlen - * here, we didnt even succeed in adding one. - */ - if(buflen != mlen) - *(p - 1) = '\0'; - else - *p = '\0'; + /* \r\n\0, possible "-~=", space, " *" */ + if(buflen + clicap_list[i].namelen >= BUFSIZE - 10) { + /* remove our trailing space -- if buflen == mlen + * here, we didnt even succeed in adding one. + */ + if(buflen != mlen) + *(p - 1) = '\0'; + else + *p = '\0'; - sendto_one(source_p, "%s * :%s", buf, capbuf); - p = capbuf; - buflen = mlen; - } + sendto_one(source_p, "%s * :%s", buf, capbuf); + p = capbuf; + buflen = mlen; + } - if(clear) - { - *p++ = '-'; - buflen++; + if(clear) { + *p++ = '-'; + buflen++; - /* needs a client ack */ - if(clicap_list[i].cap_cli && - IsCapable(source_p, clicap_list[i].cap_cli)) - { - *p++ = '~'; - buflen++; - } - } - else - { - if(clicap_list[i].flags & CLICAP_FLAGS_STICKY) - { - *p++ = '='; - buflen++; - } + /* needs a client ack */ + if(clicap_list[i].cap_cli && + IsCapable(source_p, clicap_list[i].cap_cli)) { + *p++ = '~'; + buflen++; + } + } else { + if(clicap_list[i].flags & CLICAP_FLAGS_STICKY) { + *p++ = '='; + buflen++; + } - /* if we're doing an LS, then we only send this if - * they havent ack'd - */ - if(clicap_list[i].cap_cli && - (!flags || !IsCapable(source_p, clicap_list[i].cap_cli))) - { - *p++ = '~'; - buflen++; - } - } + /* if we're doing an LS, then we only send this if + * they havent ack'd + */ + if(clicap_list[i].cap_cli && + (!flags || !IsCapable(source_p, clicap_list[i].cap_cli))) { + *p++ = '~'; + buflen++; + } + } - curlen = rb_sprintf(p, "%s ", clicap_list[i].name); - p += curlen; - buflen += curlen; - } + curlen = rb_sprintf(p, "%s ", clicap_list[i].name); + p += curlen; + buflen += curlen; + } - /* remove trailing space */ - if(buflen != mlen) - *(p - 1) = '\0'; - else - *p = '\0'; + /* remove trailing space */ + if(buflen != mlen) + *(p - 1) = '\0'; + else + *p = '\0'; - sendto_one(source_p, "%s :%s", buf, capbuf); + sendto_one(source_p, "%s :%s", buf, capbuf); } static void cap_ack(struct Client *source_p, const char *arg) { - struct clicap *cap; - int capadd = 0, capdel = 0; - int finished = 0, negate; + struct clicap *cap; + int capadd = 0, capdel = 0; + int finished = 0, negate; - if(EmptyString(arg)) - return; + if(EmptyString(arg)) + return; - for(cap = clicap_find(arg, &negate, &finished); cap; - cap = clicap_find(NULL, &negate, &finished)) - { - /* sent an ACK for something they havent REQd */ - if(!IsCapable(source_p, cap->cap_serv)) - continue; + for(cap = clicap_find(arg, &negate, &finished); cap; + cap = clicap_find(NULL, &negate, &finished)) { + /* sent an ACK for something they havent REQd */ + if(!IsCapable(source_p, cap->cap_serv)) + continue; - if(negate) - { - /* dont let them ack something sticky off */ - if(cap->flags & CLICAP_FLAGS_STICKY) - continue; + if(negate) { + /* dont let them ack something sticky off */ + if(cap->flags & CLICAP_FLAGS_STICKY) + continue; - capdel |= cap->cap_cli; - } - else - capadd |= cap->cap_cli; - } + capdel |= cap->cap_cli; + } else + capadd |= cap->cap_cli; + } - source_p->localClient->caps |= capadd; - source_p->localClient->caps &= ~capdel; + source_p->localClient->caps |= capadd; + source_p->localClient->caps &= ~capdel; } static void cap_clear(struct Client *source_p, const char *arg) { - clicap_generate(source_p, "ACK", - source_p->localClient->caps ? source_p->localClient->caps : -1, 1); + clicap_generate(source_p, "ACK", + source_p->localClient->caps ? source_p->localClient->caps : -1, 1); - /* XXX - sticky capabs */ + /* XXX - sticky capabs */ #ifdef CLICAP_STICKY - source_p->localClient->caps = source_p->localClient->caps & CLICAP_STICKY; + source_p->localClient->caps = source_p->localClient->caps & CLICAP_STICKY; #else - source_p->localClient->caps = 0; + source_p->localClient->caps = 0; #endif } static void cap_end(struct Client *source_p, const char *arg) { - if(IsRegistered(source_p)) - return; + if(IsRegistered(source_p)) + return; - source_p->flags &= ~FLAGS_CLICAP; + source_p->flags &= ~FLAGS_CLICAP; - if(source_p->name[0] && source_p->flags & FLAGS_SENTUSER) - { - char buf[USERLEN+1]; - rb_strlcpy(buf, source_p->username, sizeof(buf)); - register_local_user(source_p, source_p, buf); - } + if(source_p->name[0] && source_p->flags & FLAGS_SENTUSER) { + char buf[USERLEN+1]; + rb_strlcpy(buf, source_p->username, sizeof(buf)); + register_local_user(source_p, source_p, buf); + } } static void cap_list(struct Client *source_p, const char *arg) { - /* list of what theyre currently using */ - clicap_generate(source_p, "LIST", - source_p->localClient->caps ? source_p->localClient->caps : -1, 0); + /* list of what theyre currently using */ + clicap_generate(source_p, "LIST", + source_p->localClient->caps ? source_p->localClient->caps : -1, 0); } static void cap_ls(struct Client *source_p, const char *arg) { - if(!IsRegistered(source_p)) - source_p->flags |= FLAGS_CLICAP; + if(!IsRegistered(source_p)) + source_p->flags |= FLAGS_CLICAP; - /* list of what we support */ - clicap_generate(source_p, "LS", 0, 0); + /* list of what we support */ + clicap_generate(source_p, "LS", 0, 0); } static void cap_req(struct Client *source_p, const char *arg) { - char buf[BUFSIZE]; - char pbuf[2][BUFSIZE]; - struct clicap *cap; - int buflen, plen; - int i = 0; - int capadd = 0, capdel = 0; - int finished = 0, negate; + char buf[BUFSIZE]; + char pbuf[2][BUFSIZE]; + struct clicap *cap; + int buflen, plen; + int i = 0; + int capadd = 0, capdel = 0; + int finished = 0, negate; - if(!IsRegistered(source_p)) - source_p->flags |= FLAGS_CLICAP; + if(!IsRegistered(source_p)) + source_p->flags |= FLAGS_CLICAP; - if(EmptyString(arg)) - return; + if(EmptyString(arg)) + return; - buflen = rb_snprintf(buf, sizeof(buf), ":%s CAP %s ACK", - me.name, EmptyString(source_p->name) ? "*" : source_p->name); + buflen = rb_snprintf(buf, sizeof(buf), ":%s CAP %s ACK", + me.name, EmptyString(source_p->name) ? "*" : source_p->name); - pbuf[0][0] = '\0'; - plen = 0; + pbuf[0][0] = '\0'; + plen = 0; - for(cap = clicap_find(arg, &negate, &finished); cap; - cap = clicap_find(NULL, &negate, &finished)) - { - /* filled the first array, but cant send it in case the - * request fails. one REQ should never fill more than two - * buffers --fl - */ - if(buflen + plen + cap->namelen + 6 >= BUFSIZE) - { - pbuf[1][0] = '\0'; - plen = 0; - i = 1; - } + for(cap = clicap_find(arg, &negate, &finished); cap; + cap = clicap_find(NULL, &negate, &finished)) { + /* filled the first array, but cant send it in case the + * request fails. one REQ should never fill more than two + * buffers --fl + */ + if(buflen + plen + cap->namelen + 6 >= BUFSIZE) { + pbuf[1][0] = '\0'; + plen = 0; + i = 1; + } - if(negate) - { - if(cap->flags & CLICAP_FLAGS_STICKY) - { - finished = 0; - break; - } + if(negate) { + if(cap->flags & CLICAP_FLAGS_STICKY) { + finished = 0; + break; + } - strcat(pbuf[i], "-"); - plen++; + strcat(pbuf[i], "-"); + plen++; - capdel |= cap->cap_serv; - } - else - { - if(cap->flags & CLICAP_FLAGS_STICKY) - { - strcat(pbuf[i], "="); - plen++; - } + capdel |= cap->cap_serv; + } else { + if(cap->flags & CLICAP_FLAGS_STICKY) { + strcat(pbuf[i], "="); + plen++; + } - capadd |= cap->cap_serv; - } + capadd |= cap->cap_serv; + } - if(cap->cap_cli) - { - strcat(pbuf[i], "~"); - plen++; - } + if(cap->cap_cli) { + strcat(pbuf[i], "~"); + plen++; + } - strcat(pbuf[i], cap->name); - strcat(pbuf[i], " "); - plen += (cap->namelen + 1); - } + strcat(pbuf[i], cap->name); + strcat(pbuf[i], " "); + plen += (cap->namelen + 1); + } - if(!finished) - { - sendto_one(source_p, ":%s CAP %s NAK :%s", - me.name, EmptyString(source_p->name) ? "*" : source_p->name, arg); - return; - } + if(!finished) { + sendto_one(source_p, ":%s CAP %s NAK :%s", + me.name, EmptyString(source_p->name) ? "*" : source_p->name, arg); + return; + } - if(i) - { - sendto_one(source_p, "%s * :%s", buf, pbuf[0]); - sendto_one(source_p, "%s :%s", buf, pbuf[1]); - } - else - sendto_one(source_p, "%s :%s", buf, pbuf[0]); + if(i) { + sendto_one(source_p, "%s * :%s", buf, pbuf[0]); + sendto_one(source_p, "%s :%s", buf, pbuf[1]); + } else + sendto_one(source_p, "%s :%s", buf, pbuf[0]); - source_p->localClient->caps |= capadd; - source_p->localClient->caps &= ~capdel; + source_p->localClient->caps |= capadd; + source_p->localClient->caps &= ~capdel; } -static struct clicap_cmd -{ - const char *cmd; - void (*func)(struct Client *source_p, const char *arg); +static struct clicap_cmd { + const char *cmd; + void (*func)(struct Client *source_p, const char *arg); } clicap_cmdlist[] = { - /* This list *MUST* be in alphabetical order */ - { "ACK", cap_ack }, - { "CLEAR", cap_clear }, - { "END", cap_end }, - { "LIST", cap_list }, - { "LS", cap_ls }, - { "REQ", cap_req }, + /* This list *MUST* be in alphabetical order */ + { "ACK", cap_ack }, + { "CLEAR", cap_clear }, + { "END", cap_end }, + { "LIST", cap_list }, + { "LS", cap_ls }, + { "REQ", cap_req }, }; static int clicap_cmd_search(const char *command, struct clicap_cmd *entry) { - return irccmp(command, entry->cmd); + return irccmp(command, entry->cmd); } static int m_cap(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct clicap_cmd *cmd; + struct clicap_cmd *cmd; - if(!(cmd = bsearch(parv[1], clicap_cmdlist, - sizeof(clicap_cmdlist) / sizeof(struct clicap_cmd), - sizeof(struct clicap_cmd), (bqcmp) clicap_cmd_search))) - { - sendto_one(source_p, form_str(ERR_INVALIDCAPCMD), - me.name, EmptyString(source_p->name) ? "*" : source_p->name, - parv[1]); - return 0; - } + if(!(cmd = bsearch(parv[1], clicap_cmdlist, + sizeof(clicap_cmdlist) / sizeof(struct clicap_cmd), + sizeof(struct clicap_cmd), (bqcmp) clicap_cmd_search))) { + sendto_one(source_p, form_str(ERR_INVALIDCAPCMD), + me.name, EmptyString(source_p->name) ? "*" : source_p->name, + parv[1]); + return 0; + } - (cmd->func)(source_p, parv[2]); - return 0; + (cmd->func)(source_p, parv[2]); + return 0; } diff --git a/modules/m_capab.c b/modules/m_capab.c index 14e2300..a3ff2cd 100644 --- a/modules/m_capab.c +++ b/modules/m_capab.c @@ -36,12 +36,12 @@ static int mr_capab(struct Client *, struct Client *, int, const char **); static int me_gcap(struct Client *, struct Client *, int, const char **); struct Message capab_msgtab = { - "CAPAB", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_capab, 2}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} + "CAPAB", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_capab, 2}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} }; struct Message gcap_msgtab = { - "GCAP", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore} + "GCAP", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_gcap, 2}, mg_ignore} }; mapi_clist_av1 capab_clist[] = { &capab_msgtab, &gcap_msgtab, NULL }; @@ -55,81 +55,71 @@ DECLARE_MODULE_AV1(capab, NULL, NULL, capab_clist, NULL, NULL, "$Revision: 1295 static int mr_capab(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Capability *cap; - int i; - char *p; - char *s; + struct Capability *cap; + int i; + char *p; + char *s; - /* ummm, this shouldn't happen. Could argue this should be logged etc. */ - if(client_p->localClient == NULL) - return 0; + /* ummm, this shouldn't happen. Could argue this should be logged etc. */ + if(client_p->localClient == NULL) + return 0; - if(client_p->user) - return 0; + if(client_p->user) + return 0; - /* CAP_TS6 is set in PASS, so is valid.. */ - if((client_p->localClient->caps & ~CAP_TS6) != 0) - { - exit_client(client_p, client_p, client_p, "CAPAB received twice"); - return 0; - } - else - client_p->localClient->caps |= CAP_CAP; + /* CAP_TS6 is set in PASS, so is valid.. */ + if((client_p->localClient->caps & ~CAP_TS6) != 0) { + exit_client(client_p, client_p, client_p, "CAPAB received twice"); + return 0; + } else + client_p->localClient->caps |= CAP_CAP; - rb_free(client_p->localClient->fullcaps); - client_p->localClient->fullcaps = rb_strdup(parv[1]); + rb_free(client_p->localClient->fullcaps); + client_p->localClient->fullcaps = rb_strdup(parv[1]); - for (i = 1; i < parc; i++) - { - char *t = LOCAL_COPY(parv[i]); - for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p)) - { - for (cap = captab; cap->name; cap++) - { - if(!irccmp(cap->name, s)) - { - client_p->localClient->caps |= cap->cap; - break; - } - } - } - } + for (i = 1; i < parc; i++) { + char *t = LOCAL_COPY(parv[i]); + for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p)) { + for (cap = captab; cap->name; cap++) { + if(!irccmp(cap->name, s)) { + client_p->localClient->caps |= cap->cap; + break; + } + } + } + } - return 0; + return 0; } static int me_gcap(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Capability *cap; - char *t = LOCAL_COPY(parv[1]); - char *s; - char *p; + struct Capability *cap; + char *t = LOCAL_COPY(parv[1]); + char *s; + char *p; - if(!IsServer(source_p)) - return 0; + if(!IsServer(source_p)) + return 0; - /* already had GCAPAB?! */ - if(!EmptyString(source_p->serv->fullcaps)) - { - source_p->serv->caps = 0; - rb_free(source_p->serv->fullcaps); - } + /* already had GCAPAB?! */ + if(!EmptyString(source_p->serv->fullcaps)) { + source_p->serv->caps = 0; + rb_free(source_p->serv->fullcaps); + } - source_p->serv->fullcaps = rb_strdup(parv[1]); + source_p->serv->fullcaps = rb_strdup(parv[1]); - for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p)) - { - for (cap = captab; cap->name; cap++) - { - if(!irccmp(cap->name, s)) - { - source_p->serv->caps |= cap->cap; - break; - } - } - } + for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p)) { + for (cap = captab; cap->name; cap++) { + if(!irccmp(cap->name, s)) { + source_p->serv->caps |= cap->cap; + break; + } + } + } - return 0; + return 0; } diff --git a/modules/m_certfp.c b/modules/m_certfp.c index 6670f88..0d4b152 100644 --- a/modules/m_certfp.c +++ b/modules/m_certfp.c @@ -41,8 +41,8 @@ static int me_certfp(struct Client *, struct Client *, int, const char **); struct Message certfp_msgtab = { - "CERTFP", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_ignore, mg_ignore, mg_ignore, {me_certfp, 0}, mg_ignore} + "CERTFP", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_ignore, mg_ignore, mg_ignore, {me_certfp, 0}, mg_ignore} }; mapi_clist_av1 certfp_clist[] = { &certfp_msgtab, NULL }; @@ -56,14 +56,14 @@ DECLARE_MODULE_AV1(certfp, NULL, NULL, certfp_clist, NULL, NULL, "$Revision$"); static int me_certfp(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if (!IsPerson(source_p)) - return 0; - if (parc != 2) - return 0; + if (!IsPerson(source_p)) + return 0; + if (parc != 2) + return 0; - rb_free(source_p->certfp); - source_p->certfp = NULL; - if (!EmptyString(parv[1])) - source_p->certfp = rb_strdup(parv[1]); - return 0; + rb_free(source_p->certfp); + source_p->certfp = NULL; + if (!EmptyString(parv[1])) + source_p->certfp = rb_strdup(parv[1]); + return 0; } diff --git a/modules/m_challenge.c b/modules/m_challenge.c index 2066095..c5b1999 100644 --- a/modules/m_challenge.c +++ b/modules/m_challenge.c @@ -59,12 +59,12 @@ static int challenge_load(void) { #ifndef STATIC_MODULES - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Challenge module not loaded because OpenSSL is not available."); - ilog(L_MAIN, "Challenge module not loaded because OpenSSL is not available."); - return -1; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Challenge module not loaded because OpenSSL is not available."); + ilog(L_MAIN, "Challenge module not loaded because OpenSSL is not available."); + return -1; #else - return 0; + return 0; #endif } @@ -75,8 +75,8 @@ static int m_challenge(struct Client *, struct Client *, int, const char **); /* We have openssl support, so include /CHALLENGE */ struct Message challenge_msgtab = { - "CHALLENGE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_challenge, 2}, mg_ignore, mg_ignore, mg_ignore, {m_challenge, 2}} + "CHALLENGE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_challenge, 2}, mg_ignore, mg_ignore, mg_ignore, {m_challenge, 2}} }; mapi_clist_av1 challenge_clist[] = { &challenge_msgtab, NULL }; @@ -87,14 +87,14 @@ static int generate_challenge(char **r_challenge, char **r_response, RSA * key); static void cleanup_challenge(struct Client *target_p) { - if(target_p->localClient == NULL) - return; - - rb_free(target_p->localClient->challenge); - rb_free(target_p->localClient->opername); - target_p->localClient->challenge = NULL; - target_p->localClient->opername = NULL; - target_p->localClient->chal_time = 0; + if(target_p->localClient == NULL) + return; + + rb_free(target_p->localClient->challenge); + rb_free(target_p->localClient->opername); + target_p->localClient->challenge = NULL; + target_p->localClient->opername = NULL; + target_p->localClient->chal_time = 0; } /* @@ -105,225 +105,207 @@ cleanup_challenge(struct Client *target_p) static int m_challenge(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct oper_conf *oper_p; - char *challenge = NULL; /* to placate gcc */ - char chal_line[CHALLENGE_WIDTH]; - unsigned char *b_response; - size_t cnt; - int len = 0; + struct oper_conf *oper_p; + char *challenge = NULL; /* to placate gcc */ + char chal_line[CHALLENGE_WIDTH]; + unsigned char *b_response; + size_t cnt; + int len = 0; - /* if theyre an oper, reprint oper motd and ignore */ - if(IsOper(source_p)) - { - sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); - send_oper_motd(source_p); - return 0; - } + /* if theyre an oper, reprint oper motd and ignore */ + if(IsOper(source_p)) { + sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); + send_oper_motd(source_p); + return 0; + } - if(*parv[1] == '+') - { - /* Ignore it if we aren't expecting this... -A1kmm */ - if(!source_p->localClient->challenge) - return 0; + if(*parv[1] == '+') { + /* Ignore it if we aren't expecting this... -A1kmm */ + if(!source_p->localClient->challenge) + return 0; - if((rb_current_time() - source_p->localClient->chal_time) > CHALLENGE_EXPIRES) - { - sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); - ilog(L_FOPER, "EXPIRED CHALLENGE (%s) by (%s!%s@%s) (%s)", - source_p->localClient->opername, source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if((rb_current_time() - source_p->localClient->chal_time) > CHALLENGE_EXPIRES) { + sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); + ilog(L_FOPER, "EXPIRED CHALLENGE (%s) by (%s!%s@%s) (%s)", + source_p->localClient->opername, source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Expired CHALLENGE attempt by %s (%s@%s)", - source_p->name, source_p->username, - source_p->host); - cleanup_challenge(source_p); - return 0; - } + if(ConfigFileEntry.failed_oper_notice) + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Expired CHALLENGE attempt by %s (%s@%s)", + source_p->name, source_p->username, + source_p->host); + cleanup_challenge(source_p); + return 0; + } - parv[1]++; - b_response = rb_base64_decode((const unsigned char *)parv[1], strlen(parv[1]), &len); + parv[1]++; + b_response = rb_base64_decode((const unsigned char *)parv[1], strlen(parv[1]), &len); - if(len != SHA_DIGEST_LENGTH || - memcmp(source_p->localClient->challenge, b_response, SHA_DIGEST_LENGTH)) - { - sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); - ilog(L_FOPER, "FAILED CHALLENGE (%s) by (%s!%s@%s) (%s)", - source_p->localClient->opername, source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if(len != SHA_DIGEST_LENGTH || + memcmp(source_p->localClient->challenge, b_response, SHA_DIGEST_LENGTH)) { + sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); + ilog(L_FOPER, "FAILED CHALLENGE (%s) by (%s!%s@%s) (%s)", + source_p->localClient->opername, source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Failed CHALLENGE attempt by %s (%s@%s)", - source_p->name, source_p->username, - source_p->host); + if(ConfigFileEntry.failed_oper_notice) + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Failed CHALLENGE attempt by %s (%s@%s)", + source_p->name, source_p->username, + source_p->host); - rb_free(b_response); - cleanup_challenge(source_p); - return 0; - } + rb_free(b_response); + cleanup_challenge(source_p); + return 0; + } - rb_free(b_response); + rb_free(b_response); - oper_p = find_oper_conf(source_p->username, source_p->orighost, - source_p->sockhost, - source_p->localClient->opername); + oper_p = find_oper_conf(source_p->username, source_p->orighost, + source_p->sockhost, + source_p->localClient->opername); - if(oper_p == NULL) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", - source_p->localClient->opername, source_p->name, - source_p->username, source_p->host, - source_p->sockhost); + if(oper_p == NULL) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", + source_p->localClient->opername, source_p->name, + source_p->username, source_p->host, + source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Failed CHALLENGE attempt - host mismatch by %s (%s@%s)", - source_p->name, source_p->username, - source_p->host); - return 0; - } + if(ConfigFileEntry.failed_oper_notice) + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Failed CHALLENGE attempt - host mismatch by %s (%s@%s)", + source_p->name, source_p->username, + source_p->host); + return 0; + } - cleanup_challenge(source_p); + cleanup_challenge(source_p); - oper_up(source_p, oper_p); + oper_up(source_p, oper_p); - ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)", - source_p->localClient->opername, source_p->name, - source_p->username, source_p->host, source_p->sockhost); - return 0; - } + ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)", + source_p->localClient->opername, source_p->name, + source_p->username, source_p->host, source_p->sockhost); + return 0; + } - cleanup_challenge(source_p); + cleanup_challenge(source_p); - oper_p = find_oper_conf(source_p->username, source_p->orighost, - source_p->sockhost, parv[1]); + oper_p = find_oper_conf(source_p->username, source_p->orighost, + source_p->sockhost, parv[1]); - if(oper_p == NULL) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", - parv[1], source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if(oper_p == NULL) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", + parv[1], source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Failed CHALLENGE attempt - host mismatch by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - return 0; - } + if(ConfigFileEntry.failed_oper_notice) + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Failed CHALLENGE attempt - host mismatch by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + return 0; + } - if(!oper_p->rsa_pubkey) - { - sendto_one_notice(source_p, ":I'm sorry, PK authentication is not enabled for your oper{} block."); - return 0; - } + if(!oper_p->rsa_pubkey) { + sendto_one_notice(source_p, ":I'm sorry, PK authentication is not enabled for your oper{} block."); + return 0; + } - if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p)) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED CHALLENGE (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS", - parv[1], source_p->name, source_p->username, source_p->host, - source_p->sockhost); + if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p)) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED CHALLENGE (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS", + parv[1], source_p->name, source_p->username, source_p->host, + source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Failed CHALLENGE attempt - missing SSL/TLS by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - } - return 0; - } + if(ConfigFileEntry.failed_oper_notice) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Failed CHALLENGE attempt - missing SSL/TLS by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + } + return 0; + } - if (oper_p->certfp != NULL) - { - if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp)) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch", - parv[1], source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if (oper_p->certfp != NULL) { + if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp)) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch", + parv[1], source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - } - return 0; - } - } + if(ConfigFileEntry.failed_oper_notice) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + } + return 0; + } + } - if(!generate_challenge(&challenge, &(source_p->localClient->challenge), oper_p->rsa_pubkey)) - { - char *chal = challenge; - source_p->localClient->chal_time = rb_current_time(); - for(;;) - { - cnt = rb_strlcpy(chal_line, chal, CHALLENGE_WIDTH); - sendto_one(source_p, form_str(RPL_RSACHALLENGE2), me.name, source_p->name, chal_line); - if(cnt > CHALLENGE_WIDTH) - chal += CHALLENGE_WIDTH - 1; - else - break; - - } - sendto_one(source_p, form_str(RPL_ENDOFRSACHALLENGE2), - me.name, source_p->name); - rb_free(challenge); - source_p->localClient->opername = rb_strdup(oper_p->name); - } - else - sendto_one_notice(source_p, ":Failed to generate challenge."); + if(!generate_challenge(&challenge, &(source_p->localClient->challenge), oper_p->rsa_pubkey)) { + char *chal = challenge; + source_p->localClient->chal_time = rb_current_time(); + for(;;) { + cnt = rb_strlcpy(chal_line, chal, CHALLENGE_WIDTH); + sendto_one(source_p, form_str(RPL_RSACHALLENGE2), me.name, source_p->name, chal_line); + if(cnt > CHALLENGE_WIDTH) + chal += CHALLENGE_WIDTH - 1; + else + break; - return 0; + } + sendto_one(source_p, form_str(RPL_ENDOFRSACHALLENGE2), + me.name, source_p->name); + rb_free(challenge); + source_p->localClient->opername = rb_strdup(oper_p->name); + } else + sendto_one_notice(source_p, ":Failed to generate challenge."); + + return 0; } static int generate_challenge(char **r_challenge, char **r_response, RSA * rsa) { - SHA_CTX ctx; - unsigned char secret[CHALLENGE_SECRET_LENGTH], *tmp; - unsigned long length; - unsigned long e = 0; - unsigned long cnt = 0; - int ret; + SHA_CTX ctx; + unsigned char secret[CHALLENGE_SECRET_LENGTH], *tmp; + unsigned long length; + unsigned long e = 0; + unsigned long cnt = 0; + int ret; - if(!rsa) - return -1; - if(rb_get_random(secret, CHALLENGE_SECRET_LENGTH)) - { - SHA1_Init(&ctx); - SHA1_Update(&ctx, (uint8_t *)secret, CHALLENGE_SECRET_LENGTH); - *r_response = malloc(SHA_DIGEST_LENGTH); - SHA1_Final((uint8_t *)*r_response, &ctx); + if(!rsa) + return -1; + if(rb_get_random(secret, CHALLENGE_SECRET_LENGTH)) { + SHA1_Init(&ctx); + SHA1_Update(&ctx, (uint8_t *)secret, CHALLENGE_SECRET_LENGTH); + *r_response = malloc(SHA_DIGEST_LENGTH); + SHA1_Final((uint8_t *)*r_response, &ctx); - length = RSA_size(rsa); - tmp = rb_malloc(length); - ret = RSA_public_encrypt(CHALLENGE_SECRET_LENGTH, secret, tmp, rsa, RSA_PKCS1_OAEP_PADDING); + length = RSA_size(rsa); + tmp = rb_malloc(length); + ret = RSA_public_encrypt(CHALLENGE_SECRET_LENGTH, secret, tmp, rsa, RSA_PKCS1_OAEP_PADDING); - if(ret >= 0) - { - *r_challenge = (char *)rb_base64_encode(tmp, ret); - rb_free(tmp); - return 0; - } + if(ret >= 0) { + *r_challenge = (char *)rb_base64_encode(tmp, ret); + rb_free(tmp); + return 0; + } - rb_free(tmp); - rb_free(*r_response); - *r_response = NULL; - } + rb_free(tmp); + rb_free(*r_response); + *r_response = NULL; + } - ERR_load_crypto_strings(); - while ((cnt < 100) && (e = ERR_get_error())) - { - ilog(L_MAIN, "SSL error: %s", ERR_error_string(e, 0)); - cnt++; - } + ERR_load_crypto_strings(); + while ((cnt < 100) && (e = ERR_get_error())) { + ilog(L_MAIN, "SSL error: %s", ERR_error_string(e, 0)); + cnt++; + } - return (-1); + return (-1); } #endif /* HAVE_LIBCRYPTO */ diff --git a/modules/m_chghost.c b/modules/m_chghost.c index 647ee68..7290a3c 100644 --- a/modules/m_chghost.c +++ b/modules/m_chghost.c @@ -34,13 +34,13 @@ static int me_chghost(struct Client *, struct Client *, int, const char **); static int mo_chghost(struct Client *, struct Client *, int, const char **); struct Message realhost_msgtab = { - "REALHOST", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_realhost, 2}, mg_ignore} + "REALHOST", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_realhost, 2}, mg_ignore} }; struct Message chghost_msgtab = { - "CHGHOST", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_not_oper, {ms_chghost, 3}, {ms_chghost, 3}, {me_chghost, 3}, {mo_chghost, 3}} + "CHGHOST", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_not_oper, {ms_chghost, 3}, {ms_chghost, 3}, {me_chghost, 3}, {mo_chghost, 3}} }; mapi_clist_av1 chghost_clist[] = { &chghost_msgtab, &realhost_msgtab, NULL }; @@ -56,29 +56,28 @@ DECLARE_MODULE_AV1(chghost, NULL, NULL, chghost_clist, NULL, NULL, "$Revision: 3 static int clean_host(const char *host) { - int len = 0; - const char *last_slash = 0; - - if (*host == '\0' || *host == ':') - return 0; + int len = 0; + const char *last_slash = 0; - for(; *host; host++) - { - len++; + if (*host == '\0' || *host == ':') + return 0; - if(!IsHostChar(*host)) - return 0; - if(*host == '/') - last_slash = host; - } + for(; *host; host++) { + len++; - if(len > HOSTLEN) - return 0; + if(!IsHostChar(*host)) + return 0; + if(*host == '/') + last_slash = host; + } - if(last_slash && IsDigit(last_slash[1])) - return 0; + if(len > HOSTLEN) + return 0; - return 1; + if(last_slash && IsDigit(last_slash[1])) + return 0; + + return 1; } /* @@ -92,55 +91,51 @@ clean_host(const char *host) */ static int me_realhost(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - if (!IsPerson(source_p)) - return 0; + if (!IsPerson(source_p)) + return 0; - del_from_hostname_hash(source_p->orighost, source_p); - rb_strlcpy(source_p->orighost, parv[1], sizeof source_p->orighost); - if (irccmp(source_p->host, source_p->orighost)) - SetDynSpoof(source_p); - else - ClearDynSpoof(source_p); - add_to_hostname_hash(source_p->orighost, source_p); - return 0; + del_from_hostname_hash(source_p->orighost, source_p); + rb_strlcpy(source_p->orighost, parv[1], sizeof source_p->orighost); + if (irccmp(source_p->host, source_p->orighost)) + SetDynSpoof(source_p); + else + ClearDynSpoof(source_p); + add_to_hostname_hash(source_p->orighost, source_p); + return 0; } static int do_chghost(struct Client *source_p, struct Client *target_p, - const char *newhost, int is_encap) + const char *newhost, int is_encap) { - if (!clean_host(newhost)) - { - sendto_realops_snomask(SNO_GENERAL, is_encap ? L_ALL : L_NETWIDE, "%s attempted to change hostname for %s to %s (invalid)", - IsServer(source_p) ? source_p->name : get_oper_name(source_p), - target_p->name, newhost); - /* sending this remotely may disclose important - * routing information -- jilles */ - if (is_encap ? MyClient(target_p) : !ConfigServerHide.flatten_links) - sendto_one_notice(target_p, ":*** Notice -- %s attempted to change your hostname to %s (invalid)", - source_p->name, newhost); - return 0; - } - change_nick_user_host(target_p, target_p->name, target_p->username, newhost, 0, "Changing host"); - if (irccmp(target_p->host, target_p->orighost)) - { - SetDynSpoof(target_p); - if (MyClient(target_p)) - sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", target_p->host, source_p->name); - } - else - { - ClearDynSpoof(target_p); - if (MyClient(target_p)) - sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :hostname reset by %s", target_p->host, source_p->name); - } - if (MyClient(source_p)) - sendto_one_notice(source_p, ":Changed hostname for %s to %s", target_p->name, target_p->host); - if (!IsServer(source_p) && !IsService(source_p)) - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s changed hostname for %s to %s", get_oper_name(source_p), target_p->name, target_p->host); - return 1; + if (!clean_host(newhost)) { + sendto_realops_snomask(SNO_GENERAL, is_encap ? L_ALL : L_NETWIDE, "%s attempted to change hostname for %s to %s (invalid)", + IsServer(source_p) ? source_p->name : get_oper_name(source_p), + target_p->name, newhost); + /* sending this remotely may disclose important + * routing information -- jilles */ + if (is_encap ? MyClient(target_p) : !ConfigServerHide.flatten_links) + sendto_one_notice(target_p, ":*** Notice -- %s attempted to change your hostname to %s (invalid)", + source_p->name, newhost); + return 0; + } + change_nick_user_host(target_p, target_p->name, target_p->username, newhost, 0, "Changing host"); + if (irccmp(target_p->host, target_p->orighost)) { + SetDynSpoof(target_p); + if (MyClient(target_p)) + sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", target_p->host, source_p->name); + } else { + ClearDynSpoof(target_p); + if (MyClient(target_p)) + sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :hostname reset by %s", target_p->host, source_p->name); + } + if (MyClient(source_p)) + sendto_one_notice(source_p, ":Changed hostname for %s to %s", target_p->name, target_p->host); + if (!IsServer(source_p) && !IsService(source_p)) + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s changed hostname for %s to %s", get_oper_name(source_p), target_p->name, target_p->host); + return 1; } /* @@ -150,24 +145,23 @@ do_chghost(struct Client *source_p, struct Client *target_p, */ static int ms_chghost(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if (!(target_p = find_person(parv[1]))) - return -1; + if (!(target_p = find_person(parv[1]))) + return -1; - if (do_chghost(source_p, target_p, parv[2], 0)) - { - sendto_server(client_p, NULL, - CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s", - use_id(source_p), use_id(target_p), parv[2]); - sendto_server(client_p, NULL, - CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", - use_id(source_p), use_id(target_p), parv[2]); - } + if (do_chghost(source_p, target_p, parv[2], 0)) { + sendto_server(client_p, NULL, + CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s", + use_id(source_p), use_id(target_p), parv[2]); + sendto_server(client_p, NULL, + CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", + use_id(source_p), use_id(target_p), parv[2]); + } - return 0; + return 0; } /* @@ -177,16 +171,16 @@ ms_chghost(struct Client *client_p, struct Client *source_p, */ static int me_chghost(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if (!(target_p = find_person(parv[1]))) - return -1; + if (!(target_p = find_person(parv[1]))) + return -1; - do_chghost(source_p, target_p, parv[2], 1); + do_chghost(source_p, target_p, parv[2], 1); - return 0; + return 0; } /* @@ -199,44 +193,41 @@ me_chghost(struct Client *client_p, struct Client *source_p, */ static int mo_chghost(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { #ifdef ENABLE_OPER_CHGHOST - struct Client *target_p; + struct Client *target_p; - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return 0; + } - if (!(target_p = find_named_person(parv[1]))) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), parv[1]); - return 0; - } + if (!(target_p = find_named_person(parv[1]))) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), parv[1]); + return 0; + } - if (!clean_host(parv[2])) - { - sendto_one_notice(source_p, ":Hostname %s is invalid", parv[2]); - return 0; - } + if (!clean_host(parv[2])) { + sendto_one_notice(source_p, ":Hostname %s is invalid", parv[2]); + return 0; + } - do_chghost(source_p, target_p, parv[2], 0); + do_chghost(source_p, target_p, parv[2], 0); - sendto_server(NULL, NULL, - CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s", - use_id(source_p), use_id(target_p), parv[2]); - sendto_server(NULL, NULL, - CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", - use_id(source_p), use_id(target_p), parv[2]); + sendto_server(NULL, NULL, + CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s", + use_id(source_p), use_id(target_p), parv[2]); + sendto_server(NULL, NULL, + CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", + use_id(source_p), use_id(target_p), parv[2]); #else - sendto_one_numeric(source_p, ERR_DISABLED, form_str(ERR_DISABLED), - "CHGHOST"); + sendto_one_numeric(source_p, ERR_DISABLED, form_str(ERR_DISABLED), + "CHGHOST"); #endif - return 0; + return 0; } diff --git a/modules/m_close.c b/modules/m_close.c index 681d6cb..a7bf575 100644 --- a/modules/m_close.c +++ b/modules/m_close.c @@ -35,8 +35,8 @@ static int mo_close(struct Client *, struct Client *, int, const char **); struct Message close_msgtab = { - "CLOSE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_close, 0}} + "CLOSE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_close, 0}} }; mapi_clist_av1 close_clist[] = { &close_msgtab, NULL }; @@ -49,22 +49,21 @@ DECLARE_MODULE_AV1(close, NULL, NULL, close_clist, NULL, NULL, "$Revision: 254 $ static int mo_close(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *ptr_next; - int closed = 0; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *ptr_next; + int closed = 0; - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head) { + target_p = ptr->data; - sendto_one(source_p, form_str(RPL_CLOSING), me.name, source_p->name, - get_client_name(target_p, SHOW_IP), target_p->status); + sendto_one(source_p, form_str(RPL_CLOSING), me.name, source_p->name, + get_client_name(target_p, SHOW_IP), target_p->status); - (void) exit_client(target_p, target_p, target_p, "Oper Closing"); - closed++; - } + (void) exit_client(target_p, target_p, target_p, "Oper Closing"); + closed++; + } - sendto_one(source_p, form_str(RPL_CLOSEEND), me.name, source_p->name, closed); - return 0; + sendto_one(source_p, form_str(RPL_CLOSEEND), me.name, source_p->name, closed); + return 0; } diff --git a/modules/m_cmessage.c b/modules/m_cmessage.c index adcb20b..2dd2f2f 100644 --- a/modules/m_cmessage.c +++ b/modules/m_cmessage.c @@ -47,12 +47,12 @@ static int m_cprivmsg(struct Client *, struct Client *, int, const char **); static int m_cnotice(struct Client *, struct Client *, int, const char **); struct Message cprivmsg_msgtab = { - "CPRIVMSG", 0, 0, 0, MFLG_SLOW, - {mg_ignore, {m_cprivmsg, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cprivmsg, 4}} + "CPRIVMSG", 0, 0, 0, MFLG_SLOW, + {mg_ignore, {m_cprivmsg, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cprivmsg, 4}} }; struct Message cnotice_msgtab = { - "CNOTICE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, {m_cnotice, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cnotice, 4}} + "CNOTICE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, {m_cnotice, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cnotice, 4}} }; mapi_clist_av1 cmessage_clist[] = { &cprivmsg_msgtab, &cnotice_msgtab, NULL }; @@ -64,104 +64,96 @@ DECLARE_MODULE_AV1(cmessage, NULL, NULL, cmessage_clist, NULL, NULL, "$Revision: static int m_cprivmsg(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - return m_cmessage(PRIVMSG, "PRIVMSG", client_p, source_p, parc, parv); + return m_cmessage(PRIVMSG, "PRIVMSG", client_p, source_p, parc, parv); } static int m_cnotice(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - return m_cmessage(NOTICE, "NOTICE", client_p, source_p, parc, parv); + return m_cmessage(NOTICE, "NOTICE", client_p, source_p, parc, parv); } static int m_cmessage(int p_or_n, const char *command, - struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) + struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - struct Channel *chptr; - struct membership *msptr; + struct Client *target_p; + struct Channel *chptr; + struct membership *msptr; - if(!IsFloodDone(source_p)) - flood_endgrace(source_p); + if(!IsFloodDone(source_p)) + flood_endgrace(source_p); - if((target_p = find_named_person(parv[1])) == NULL) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), parv[1]); - return 0; - } + if((target_p = find_named_person(parv[1])) == NULL) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), parv[1]); + return 0; + } - if((chptr = find_channel(parv[2])) == NULL) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[2]); - return 0; - } + if((chptr = find_channel(parv[2])) == NULL) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[2]); + return 0; + } - if((msptr = find_channel_membership(chptr, source_p)) == NULL) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), - chptr->chname); - return 0; - } + if((msptr = find_channel_membership(chptr, source_p)) == NULL) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), + chptr->chname); + return 0; + } - if(!is_chanop_voiced(msptr)) - { - if(p_or_n != NOTICE) - sendto_one(source_p, form_str(ERR_VOICENEEDED), - me.name, source_p->name, chptr->chname); - return 0; - } + if(!is_chanop_voiced(msptr)) { + if(p_or_n != NOTICE) + sendto_one(source_p, form_str(ERR_VOICENEEDED), + me.name, source_p->name, chptr->chname); + return 0; + } - if(!IsMember(target_p, chptr)) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), - target_p->name, chptr->chname); - return 0; - } + if(!IsMember(target_p, chptr)) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), + target_p->name, chptr->chname); + return 0; + } - if(MyClient(target_p) && (IsSetCallerId(target_p) || (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && - !accept_message(source_p, target_p) && !IsOper(source_p)) - { - if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) - { - if (p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_NONONREG, - form_str(ERR_NONONREG), - target_p->name); - return 0; - } - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, ERR_TARGUMODEG, - form_str(ERR_TARGUMODEG), target_p->name); + if(MyClient(target_p) && (IsSetCallerId(target_p) || (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && + !accept_message(source_p, target_p) && !IsOper(source_p)) { + if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) { + if (p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_NONONREG, + form_str(ERR_NONONREG), + target_p->name); + return 0; + } + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, ERR_TARGUMODEG, + form_str(ERR_TARGUMODEG), target_p->name); - if((target_p->localClient->last_caller_id_time + - ConfigFileEntry.caller_id_wait) < rb_current_time()) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, RPL_TARGNOTIFY, - form_str(RPL_TARGNOTIFY), - target_p->name); + if((target_p->localClient->last_caller_id_time + + ConfigFileEntry.caller_id_wait) < rb_current_time()) { + if(p_or_n != NOTICE) + sendto_one_numeric(source_p, RPL_TARGNOTIFY, + form_str(RPL_TARGNOTIFY), + target_p->name); - sendto_one(target_p, form_str(RPL_UMODEGMSG), - me.name, target_p->name, source_p->name, - source_p->username, source_p->host); + sendto_one(target_p, form_str(RPL_UMODEGMSG), + me.name, target_p->name, source_p->name, + source_p->username, source_p->host); - target_p->localClient->last_caller_id_time = rb_current_time(); - } + target_p->localClient->last_caller_id_time = rb_current_time(); + } - return 0; - } + return 0; + } - if(p_or_n != NOTICE) - source_p->localClient->last = rb_current_time(); + if(p_or_n != NOTICE) + source_p->localClient->last = rb_current_time(); - sendto_anywhere(target_p, source_p, command, ":%s", parv[3]); - return 0; + sendto_anywhere(target_p, source_p, command, ":%s", parv[3]); + return 0; } diff --git a/modules/m_connect.c b/modules/m_connect.c index f5a9675..886219e 100644 --- a/modules/m_connect.c +++ b/modules/m_connect.c @@ -43,8 +43,8 @@ static int mo_connect(struct Client *, struct Client *, int, const char **); static int ms_connect(struct Client *, struct Client *, int, const char **); struct Message connect_msgtab = { - "CONNECT", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_connect, 4}, {ms_connect, 4}, mg_ignore, {mo_connect, 2}} + "CONNECT", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_connect, 4}, {ms_connect, 4}, mg_ignore, {mo_connect, 2}} }; mapi_clist_av1 connect_clist[] = { &connect_msgtab, NULL }; @@ -52,7 +52,7 @@ DECLARE_MODULE_AV1(connect, NULL, NULL, connect_clist, NULL, NULL, "$Revision: 3 /* * mo_connect - CONNECT command handler - * + * * Added by Jto 11 Feb 1989 * * m_connect @@ -63,99 +63,88 @@ DECLARE_MODULE_AV1(connect, NULL, NULL, connect_clist, NULL, NULL, "$Revision: 3 static int mo_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int port; - int tmpport; - struct server_conf *server_p; - struct Client *target_p; + int port; + int tmpport; + struct server_conf *server_p; + struct Client *target_p; - /* always privileged with handlers */ + /* always privileged with handlers */ - if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remote"); - return 0; - } + if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remote"); + return 0; + } - if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) + return 0; - if((target_p = find_server(source_p, parv[1]))) - { - sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", parv[1], - target_p->from->name); - return 0; - } + if((target_p = find_server(source_p, parv[1]))) { + sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", parv[1], + target_p->from->name); + return 0; + } - /* - * try to find the name, then host, if both fail notify ops and bail - */ - if((server_p = find_server_conf(parv[1])) == NULL) - { - sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", parv[1]); - return 0; - } + /* + * try to find the name, then host, if both fail notify ops and bail + */ + if((server_p = find_server_conf(parv[1])) == NULL) { + sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", parv[1]); + return 0; + } - if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count())) - { - sendto_one_notice(source_p, - ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.", - parv[1]); - return 0; - } + if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count())) { + sendto_one_notice(source_p, + ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.", + parv[1]); + return 0; + } - /* - * Get port number from user, if given. If not specified, - * use the default form configuration structure. If missing - * from there, then use the precompiled default. - */ - tmpport = port = server_p->port; - if(parc > 2 && !EmptyString(parv[2])) - { - if((port = atoi(parv[2])) <= 0) - { - sendto_one_notice(source_p, ":Connect: Illegal port number"); - return 0; - } - } - else if(port <= 0 && (port = PORTNUM) <= 0) - { - sendto_one_notice(source_p, ":Connect: missing port number"); - return 0; - } - /* - * Notify all operators about remote connect requests - */ + /* + * Get port number from user, if given. If not specified, + * use the default form configuration structure. If missing + * from there, then use the precompiled default. + */ + tmpport = port = server_p->port; + if(parc > 2 && !EmptyString(parv[2])) { + if((port = atoi(parv[2])) <= 0) { + sendto_one_notice(source_p, ":Connect: Illegal port number"); + return 0; + } + } else if(port <= 0 && (port = PORTNUM) <= 0) { + sendto_one_notice(source_p, ":Connect: missing port number"); + return 0; + } + /* + * Notify all operators about remote connect requests + */ - ilog(L_SERVER, "CONNECT From %s : %s %s", source_p->name, parv[1], parc > 2 ? parv[2] : ""); + ilog(L_SERVER, "CONNECT From %s : %s %s", source_p->name, parv[1], parc > 2 ? parv[2] : ""); - server_p->port = port; - /* - * at this point we should be calling connect_server with a valid - * C:line and a valid port in the C:line - */ - if(serv_connect(server_p, source_p)) - { - sendto_one_notice(source_p, ":*** Connecting to %s.%d", - server_p->name, server_p->port); - } - else - { - sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d", - server_p->name, server_p->port); - } + server_p->port = port; + /* + * at this point we should be calling connect_server with a valid + * C:line and a valid port in the C:line + */ + if(serv_connect(server_p, source_p)) { + sendto_one_notice(source_p, ":*** Connecting to %s.%d", + server_p->name, server_p->port); + } else { + sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d", + server_p->name, server_p->port); + } - /* - * client is either connecting with all the data it needs or has been - * destroyed - */ - server_p->port = tmpport; - return 0; + /* + * client is either connecting with all the data it needs or has been + * destroyed + */ + server_p->port = tmpport; + return 0; } /* * ms_connect - CONNECT command handler - * + * * Added by Jto 11 Feb 1989 * * m_connect @@ -166,84 +155,80 @@ mo_connect(struct Client *client_p, struct Client *source_p, int parc, const cha static int ms_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int port; - int tmpport; - struct server_conf *server_p; - struct Client *target_p; + int port; + int tmpport; + struct server_conf *server_p; + struct Client *target_p; - if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) + return 0; - if((target_p = find_server(NULL, parv[1]))) - { - sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", - parv[1], target_p->from->name); - return 0; - } + if((target_p = find_server(NULL, parv[1]))) { + sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", + parv[1], target_p->from->name); + return 0; + } - /* - * try to find the name, then host, if both fail notify ops and bail - */ - if((server_p = find_server_conf(parv[1])) == NULL) - { - sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", - parv[1]); - return 0; - } + /* + * try to find the name, then host, if both fail notify ops and bail + */ + if((server_p = find_server_conf(parv[1])) == NULL) { + sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", + parv[1]); + return 0; + } - if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count())) - { - sendto_one_notice(source_p, - ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.", - parv[1]); - return 0; - } + if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count())) { + sendto_one_notice(source_p, + ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.", + parv[1]); + return 0; + } - /* - * Get port number from user, if given. If not specified, - * use the default form configuration structure. If missing - * from there, then use the precompiled default. - */ - tmpport = server_p->port; + /* + * Get port number from user, if given. If not specified, + * use the default form configuration structure. If missing + * from there, then use the precompiled default. + */ + tmpport = server_p->port; - port = atoi(parv[2]); + port = atoi(parv[2]); - /* if someone sends port 0, and we have a config port.. use it */ - if(port == 0 && server_p->port) - port = server_p->port; - else if(port <= 0) - { - sendto_one_notice(source_p, ":Connect: Illegal port number"); - return 0; - } + /* if someone sends port 0, and we have a config port.. use it */ + if(port == 0 && server_p->port) + port = server_p->port; + else if(port <= 0) { + sendto_one_notice(source_p, ":Connect: Illegal port number"); + return 0; + } - /* - * Notify all operators about remote connect requests - */ - sendto_wallops_flags(UMODE_WALLOP, &me, - "Remote CONNECT %s %d from %s", - parv[1], port, source_p->name); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s WALLOPS :Remote CONNECT %s %d from %s", - me.id, parv[1], port, source_p->name); + /* + * Notify all operators about remote connect requests + */ + sendto_wallops_flags(UMODE_WALLOP, &me, + "Remote CONNECT %s %d from %s", + parv[1], port, source_p->name); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s WALLOPS :Remote CONNECT %s %d from %s", + me.id, parv[1], port, source_p->name); - ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port); + ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port); - server_p->port = port; - /* - * at this point we should be calling connect_server with a valid - * C:line and a valid port in the C:line - */ - if(serv_connect(server_p, source_p)) - sendto_one_notice(source_p, ":*** Connecting to %s.%d", - server_p->name, server_p->port); - else - sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d", - server_p->name, server_p->port); - /* - * client is either connecting with all the data it needs or has been - * destroyed - */ - server_p->port = tmpport; - return 0; + server_p->port = port; + /* + * at this point we should be calling connect_server with a valid + * C:line and a valid port in the C:line + */ + if(serv_connect(server_p, source_p)) + sendto_one_notice(source_p, ":*** Connecting to %s.%d", + server_p->name, server_p->port); + else + sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d", + server_p->name, server_p->port); + /* + * client is either connecting with all the data it needs or has been + * destroyed + */ + server_p->port = tmpport; + return 0; } diff --git a/modules/m_dline.c b/modules/m_dline.c index bb928ac..af60bcf 100644 --- a/modules/m_dline.c +++ b/modules/m_dline.c @@ -51,13 +51,13 @@ static int mo_undline(struct Client *, struct Client *, int, const char **); static int me_undline(struct Client *, struct Client *, int, const char **); struct Message dline_msgtab = { - "DLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_dline, 3}, {mo_dline, 2}} + "DLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_dline, 3}, {mo_dline, 2}} }; struct Message undline_msgtab = { - "UNDLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_undline, 1}, {mo_undline, 2}} + "UNDLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_undline, 1}, {mo_undline, 2}} }; mapi_clist_av1 dline_clist[] = { &dline_msgtab, &undline_msgtab, NULL }; @@ -70,66 +70,62 @@ static int apply_dline(struct Client *, const char *, int, char *); static int apply_undline(struct Client *, const char *); /* mo_dline() - * + * * parv[1] - dline to add * parv[2] - reason */ static int mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char def[] = "No Reason"; - const char *dlhost; - char *reason = def; - char cidr_form_host[HOSTLEN + 1]; - int tdline_time = 0; - const char *target_server = NULL; - int loc = 1; + char def[] = "No Reason"; + const char *dlhost; + char *reason = def; + char cidr_form_host[HOSTLEN + 1]; + int tdline_time = 0; + const char *target_server = NULL; + int loc = 1; - if(!IsOperK(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); - return 0; - } + if(!IsOperK(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); + return 0; + } - if((tdline_time = valid_temp_time(parv[loc])) >= 0) - loc++; + if((tdline_time = valid_temp_time(parv[loc])) >= 0) + loc++; - dlhost = parv[loc]; - rb_strlcpy(cidr_form_host, dlhost, sizeof(cidr_form_host)); + dlhost = parv[loc]; + rb_strlcpy(cidr_form_host, dlhost, sizeof(cidr_form_host)); - loc++; + loc++; - if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - target_server = parv[loc + 1]; - loc += 2; - } + target_server = parv[loc + 1]; + loc += 2; + } - if(parc >= loc + 1 && !EmptyString(parv[loc])) - reason = LOCAL_COPY(parv[loc]); + if(parc >= loc + 1 && !EmptyString(parv[loc])) + reason = LOCAL_COPY(parv[loc]); - if(target_server != NULL) - { - sendto_match_servs(source_p, target_server, - CAP_ENCAP, NOCAPS, - "ENCAP %s DLINE %d %s :%s", - target_server, tdline_time, dlhost, reason); + if(target_server != NULL) { + sendto_match_servs(source_p, target_server, + CAP_ENCAP, NOCAPS, + "ENCAP %s DLINE %d %s :%s", + target_server, tdline_time, dlhost, reason); - if(!match(target_server, me.name)) - return 0; - } + if(!match(target_server, me.name)) + return 0; + } - apply_dline(source_p, dlhost, tdline_time, reason); + apply_dline(source_p, dlhost, tdline_time, reason); - check_dlines(); - return 0; + check_dlines(); + return 0; } /* mo_undline() @@ -139,268 +135,242 @@ mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char static int mo_undline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *cidr; - const char *target_server = NULL; + const char *cidr; + const char *target_server = NULL; - if(!IsOperK(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); - return 0; - } + if(!IsOperK(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); + return 0; + } - cidr = parv[1]; + cidr = parv[1]; - if(parc >= 4 && !irccmp(parv[2], "ON")) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + if(parc >= 4 && !irccmp(parv[2], "ON")) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - target_server = parv[3]; - sendto_match_servs(source_p, target_server, - CAP_ENCAP, NOCAPS, "ENCAP %s UNDLINE %s", target_server, cidr); + target_server = parv[3]; + sendto_match_servs(source_p, target_server, + CAP_ENCAP, NOCAPS, "ENCAP %s UNDLINE %s", target_server, cidr); - if(!match(target_server, me.name)) - return 0; - } + if(!match(target_server, me.name)) + return 0; + } - apply_undline(source_p, cidr); + apply_undline(source_p, cidr); - return 0; + return 0; } static int me_dline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - int tdline_time = atoi(parv[1]); - /* Since this is coming over a server link, assume that the originating - * server did the relevant permission/sanity checks... - */ + int tdline_time = atoi(parv[1]); + /* Since this is coming over a server link, assume that the originating + * server did the relevant permission/sanity checks... + */ - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, - tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE)) - return 0; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, + tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE)) + return 0; - apply_dline(source_p, parv[2], tdline_time, LOCAL_COPY(parv[3])); + apply_dline(source_p, parv[2], tdline_time, LOCAL_COPY(parv[3])); - check_dlines(); - return 0; + check_dlines(); + return 0; } static int me_undline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, SHARED_UNDLINE)) - return 0; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, SHARED_UNDLINE)) + return 0; - apply_undline(source_p, parv[1]); + apply_undline(source_p, parv[1]); - return 0; + return 0; } static int apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *reason) { - struct ConfItem *aconf; - char *oper_reason; - struct rb_sockaddr_storage daddr; - int t = AF_INET, ty, b; - const char *creason; + struct ConfItem *aconf; + char *oper_reason; + struct rb_sockaddr_storage daddr; + int t = AF_INET, ty, b; + const char *creason; - ty = parse_netmask(dlhost, (struct sockaddr *) &daddr, &b); - if(ty == HM_HOST) - { - sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", me.name, source_p->name); - return 0; - } + ty = parse_netmask(dlhost, (struct sockaddr *) &daddr, &b); + if(ty == HM_HOST) { + sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", me.name, source_p->name); + return 0; + } #ifdef RB_IPV6 - if(ty == HM_IPV6) - t = AF_INET6; - else + if(ty == HM_IPV6) + t = AF_INET6; + else #endif - t = AF_INET; + t = AF_INET; - /* This means dlines wider than /16 cannot be set remotely */ - if(IsOperAdmin(source_p)) - { - if(b < 8) - { - sendto_one_notice(source_p, - ":For safety, bitmasks less than 8 require conf access."); - return 0; - } - } - else - { - if(b < 16) - { - sendto_one_notice(source_p, - ":Dline bitmasks less than 16 are for admins only."); - return 0; - } - } + /* This means dlines wider than /16 cannot be set remotely */ + if(IsOperAdmin(source_p)) { + if(b < 8) { + sendto_one_notice(source_p, + ":For safety, bitmasks less than 8 require conf access."); + return 0; + } + } else { + if(b < 16) { + sendto_one_notice(source_p, + ":Dline bitmasks less than 16 are for admins only."); + return 0; + } + } - if(!valid_comment(reason)) - { - sendto_one(source_p, - ":%s NOTICE %s :Invalid character '\"' in comment", - me.name, source_p->name); - return 0; - } + if(!valid_comment(reason)) { + sendto_one(source_p, + ":%s NOTICE %s :Invalid character '\"' in comment", + me.name, source_p->name); + return 0; + } - if(ConfigFileEntry.non_redundant_klines) - { - if((aconf = find_dline((struct sockaddr *) &daddr, t)) != NULL) - { - int bx; - parse_netmask(aconf->host, NULL, &bx); - if(b >= bx) - { - creason = aconf->passwd ? aconf->passwd : ""; - if(IsConfExemptKline(aconf)) - sendto_one(source_p, - ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", - me.name, source_p->name, dlhost, aconf->host, - creason); - else - sendto_one(source_p, - ":%s NOTICE %s :[%s] already D-lined by [%s] - %s", - me.name, source_p->name, dlhost, aconf->host, - creason); - return 0; - } - } - } + if(ConfigFileEntry.non_redundant_klines) { + if((aconf = find_dline((struct sockaddr *) &daddr, t)) != NULL) { + int bx; + parse_netmask(aconf->host, NULL, &bx); + if(b >= bx) { + creason = aconf->passwd ? aconf->passwd : ""; + if(IsConfExemptKline(aconf)) + sendto_one(source_p, + ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", + me.name, source_p->name, dlhost, aconf->host, + creason); + else + sendto_one(source_p, + ":%s NOTICE %s :[%s] already D-lined by [%s] - %s", + me.name, source_p->name, dlhost, aconf->host, + creason); + return 0; + } + } + } - rb_set_time(); + rb_set_time(); - aconf = make_conf(); - aconf->status = CONF_DLINE; - aconf->created = rb_current_time(); - aconf->host = rb_strdup(dlhost); - aconf->passwd = rb_strdup(reason); - aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf = make_conf(); + aconf->status = CONF_DLINE; + aconf->created = rb_current_time(); + aconf->host = rb_strdup(dlhost); + aconf->passwd = rb_strdup(reason); + aconf->info.oper = operhash_add(get_oper_name(source_p)); - /* Look for an oper reason */ - if((oper_reason = strchr(reason, '|')) != NULL) - { - *oper_reason = '\0'; - oper_reason++; + /* Look for an oper reason */ + if((oper_reason = strchr(reason, '|')) != NULL) { + *oper_reason = '\0'; + oper_reason++; - if(!EmptyString(oper_reason)) - aconf->spasswd = rb_strdup(oper_reason); - } + if(!EmptyString(oper_reason)) + aconf->spasswd = rb_strdup(oper_reason); + } - if(tdline_time > 0) - { - aconf->hold = rb_current_time() + tdline_time; - add_temp_dline(aconf); + if(tdline_time > 0) { + aconf->hold = rb_current_time() + tdline_time; + add_temp_dline(aconf); - if(EmptyString(oper_reason)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. D-Line for [%s] [%s]", - get_oper_name(source_p), tdline_time / 60, - aconf->host, reason); - ilog(L_KLINE, "D %s %d %s %s", - get_oper_name(source_p), tdline_time / 60, aconf->host, reason); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. D-Line for [%s] [%s|%s]", - get_oper_name(source_p), tdline_time / 60, - aconf->host, reason, oper_reason); - ilog(L_KLINE, "D %s %d %s %s|%s", - get_oper_name(source_p), tdline_time / 60, - aconf->host, reason, oper_reason); - } + if(EmptyString(oper_reason)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. D-Line for [%s] [%s]", + get_oper_name(source_p), tdline_time / 60, + aconf->host, reason); + ilog(L_KLINE, "D %s %d %s %s", + get_oper_name(source_p), tdline_time / 60, aconf->host, reason); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. D-Line for [%s] [%s|%s]", + get_oper_name(source_p), tdline_time / 60, + aconf->host, reason, oper_reason); + ilog(L_KLINE, "D %s %d %s %s|%s", + get_oper_name(source_p), tdline_time / 60, + aconf->host, reason, oper_reason); + } - sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]", - me.name, source_p->name, tdline_time / 60, aconf->host); - } - else - { - add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); + sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]", + me.name, source_p->name, tdline_time / 60, aconf->host); + } else { + add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); - bandb_add(BANDB_DLINE, source_p, aconf->host, NULL, - reason, EmptyString(aconf->spasswd) ? NULL : aconf->spasswd, 0); + bandb_add(BANDB_DLINE, source_p, aconf->host, NULL, + reason, EmptyString(aconf->spasswd) ? NULL : aconf->spasswd, 0); - if(EmptyString(oper_reason)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added D-Line for [%s] [%s]", - get_oper_name(source_p), aconf->host, reason); - ilog(L_KLINE, "D %s 0 %s %s", - get_oper_name(source_p), aconf->host, reason); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added D-Line for [%s] [%s|%s]", - get_oper_name(source_p), aconf->host, reason, oper_reason); - ilog(L_KLINE, "D %s 0 %s %s|%s", - get_oper_name(source_p), - aconf->host, reason, oper_reason); - } - } + if(EmptyString(oper_reason)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added D-Line for [%s] [%s]", + get_oper_name(source_p), aconf->host, reason); + ilog(L_KLINE, "D %s 0 %s %s", + get_oper_name(source_p), aconf->host, reason); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added D-Line for [%s] [%s|%s]", + get_oper_name(source_p), aconf->host, reason, oper_reason); + ilog(L_KLINE, "D %s 0 %s %s|%s", + get_oper_name(source_p), + aconf->host, reason, oper_reason); + } + } - return 0; + return 0; } static int apply_undline(struct Client *source_p, const char *cidr) { - char buf[BUFSIZE]; - struct ConfItem *aconf; + char buf[BUFSIZE]; + struct ConfItem *aconf; - if(parse_netmask(cidr, NULL, NULL) == HM_HOST) - { - sendto_one_notice(source_p, ":Invalid D-Line"); - return 0; - } + if(parse_netmask(cidr, NULL, NULL) == HM_HOST) { + sendto_one_notice(source_p, ":Invalid D-Line"); + return 0; + } - aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL); - if(aconf == NULL) - { - sendto_one_notice(source_p, ":No D-Line for %s", cidr); - return 0; - } + aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL); + if(aconf == NULL) { + sendto_one_notice(source_p, ":No D-Line for %s", cidr); + return 0; + } - rb_strlcpy(buf, aconf->host, sizeof buf); - if(remove_temp_dline(aconf)) - { - sendto_one(source_p, - ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines", - me.name, source_p->name, buf); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the temporary D-Line for: [%s]", - get_oper_name(source_p), buf); - ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf); - return 0; - } + rb_strlcpy(buf, aconf->host, sizeof buf); + if(remove_temp_dline(aconf)) { + sendto_one(source_p, + ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines", + me.name, source_p->name, buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the temporary D-Line for: [%s]", + get_oper_name(source_p), buf); + ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf); + return 0; + } - bandb_del(BANDB_DLINE, aconf->host, NULL); + bandb_del(BANDB_DLINE, aconf->host, NULL); - sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name, - aconf->host); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the D-Line for: [%s]", - get_oper_name(source_p), aconf->host); - ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), aconf->host); - delete_one_address_conf(aconf->host, aconf); + sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name, + aconf->host); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the D-Line for: [%s]", + get_oper_name(source_p), aconf->host); + ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), aconf->host); + delete_one_address_conf(aconf->host, aconf); - return 0; + return 0; } /* @@ -413,13 +383,13 @@ apply_undline(struct Client *source_p, const char *cidr) static int valid_comment(char *comment) { - if(strchr(comment, '"')) - return 0; + if(strchr(comment, '"')) + return 0; - if(strlen(comment) > BANREASONLEN) - comment[BANREASONLEN] = '\0'; + if(strlen(comment) > BANREASONLEN) + comment[BANREASONLEN] = '\0'; - return 1; + return 1; } /* remove_temp_dline() @@ -431,21 +401,18 @@ valid_comment(char *comment) static int remove_temp_dline(struct ConfItem *aconf) { - rb_dlink_node *ptr; - int i; + rb_dlink_node *ptr; + int i; - for(i = 0; i < LAST_TEMP_TYPE; i++) - { - RB_DLINK_FOREACH(ptr, temp_dlines[i].head) - { - if(aconf == ptr->data) - { - rb_dlinkDestroy(ptr, &temp_dlines[i]); - delete_one_address_conf(aconf->host, aconf); - return YES; - } - } - } + for(i = 0; i < LAST_TEMP_TYPE; i++) { + RB_DLINK_FOREACH(ptr, temp_dlines[i].head) { + if(aconf == ptr->data) { + rb_dlinkDestroy(ptr, &temp_dlines[i]); + delete_one_address_conf(aconf->host, aconf); + return YES; + } + } + } - return NO; + return NO; } diff --git a/modules/m_encap.c b/modules/m_encap.c index 2ee95c8..b2e8c7c 100644 --- a/modules/m_encap.c +++ b/modules/m_encap.c @@ -43,11 +43,11 @@ #include "modules.h" static int ms_encap(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); struct Message encap_msgtab = { - "ENCAP", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, {ms_encap, 3}, {ms_encap, 3}, mg_ignore, mg_ignore} + "ENCAP", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, {ms_encap, 3}, {ms_encap, 3}, mg_ignore, mg_ignore} }; mapi_clist_av1 encap_clist[] = { &encap_msgtab, NULL }; @@ -62,47 +62,46 @@ DECLARE_MODULE_AV1(encap, NULL, NULL, encap_clist, NULL, NULL, "$Revision: 254 $ static int ms_encap(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char buffer[BUFSIZE]; - char *ptr; - int cur_len = 0; - int len; - int i; + char buffer[BUFSIZE]; + char *ptr; + int cur_len = 0; + int len; + int i; - ptr = buffer; - - for(i = 1; i < parc - 1; i++) - { - len = strlen(parv[i]) + 1; + ptr = buffer; - /* ugh, not even at the last parameter, just bail --fl */ - if((size_t)(cur_len + len) >= sizeof(buffer)) - return 0; + for(i = 1; i < parc - 1; i++) { + len = strlen(parv[i]) + 1; - rb_snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]); - cur_len += len; - ptr += len; - } + /* ugh, not even at the last parameter, just bail --fl */ + if((size_t)(cur_len + len) >= sizeof(buffer)) + return 0; - len = strlen(parv[i]); + rb_snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]); + cur_len += len; + ptr += len; + } - /* if its a command without parameters, dont prepend a ':' */ - if(parc == 3) - rb_snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]); - else - rb_snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc-1]); + len = strlen(parv[i]); - /* add a trailing \0 if it was too long */ - if((cur_len + len) >= BUFSIZE) - buffer[BUFSIZE-1] = '\0'; + /* if its a command without parameters, dont prepend a ':' */ + if(parc == 3) + rb_snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]); + else + rb_snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc-1]); - sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS, - "ENCAP %s", buffer); + /* add a trailing \0 if it was too long */ + if((cur_len + len) >= BUFSIZE) + buffer[BUFSIZE-1] = '\0'; - /* if it matches us, find a matching handler and call it */ - if(match(parv[1], me.name)) - handle_encap(client_p, source_p, parv[2], parc - 2, parv + 2); + sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS, + "ENCAP %s", buffer); - return 0; + /* if it matches us, find a matching handler and call it */ + if(match(parv[1], me.name)) + handle_encap(client_p, source_p, parv[2], parc - 2, parv + 2); + + return 0; } diff --git a/modules/m_etrace.c b/modules/m_etrace.c index 6fe1013..98e4441 100644 --- a/modules/m_etrace.c +++ b/modules/m_etrace.c @@ -55,16 +55,16 @@ static int m_chantrace(struct Client *, struct Client *, int, const char **); static int mo_masktrace(struct Client *, struct Client *, int, const char **); struct Message etrace_msgtab = { - "ETRACE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}} + "ETRACE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}} }; struct Message chantrace_msgtab = { - "CHANTRACE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}} + "CHANTRACE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}} }; struct Message masktrace_msgtab = { - "MASKTRACE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}} + "MASKTRACE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}} }; mapi_clist_av1 etrace_clist[] = { &etrace_msgtab, &chantrace_msgtab, &masktrace_msgtab, NULL }; @@ -85,99 +85,92 @@ static const char *spoofed_sockhost = "0"; static int mo_etrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc > 1 && !EmptyString(parv[1])) - { - if(!irccmp(parv[1], "-full")) - do_etrace_full(source_p); + if(parc > 1 && !EmptyString(parv[1])) { + if(!irccmp(parv[1], "-full")) + do_etrace_full(source_p); #ifdef RB_IPV6 - else if(!irccmp(parv[1], "-v6")) - do_etrace(source_p, 0, 1); - else if(!irccmp(parv[1], "-v4")) - do_etrace(source_p, 1, 0); + else if(!irccmp(parv[1], "-v6")) + do_etrace(source_p, 0, 1); + else if(!irccmp(parv[1], "-v4")) + do_etrace(source_p, 1, 0); #endif - else - { - struct Client *target_p = find_named_person(parv[1]); + else { + struct Client *target_p = find_named_person(parv[1]); - if(target_p) - { - if(!MyClient(target_p)) - sendto_one(target_p, ":%s ENCAP %s ETRACE %s", - get_id(source_p, target_p), - target_p->servptr->name, - get_id(target_p, target_p)); - else - do_single_etrace(source_p, target_p); - } - else - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), parv[1]); - } - } - else - do_etrace(source_p, 1, 1); + if(target_p) { + if(!MyClient(target_p)) + sendto_one(target_p, ":%s ENCAP %s ETRACE %s", + get_id(source_p, target_p), + target_p->servptr->name, + get_id(target_p, target_p)); + else + do_single_etrace(source_p, target_p); + } else + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), parv[1]); + } + } else + do_etrace(source_p, 1, 1); - return 0; + return 0; } static int me_etrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) - return 0; + if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) + return 0; - /* we cant etrace remote clients.. we shouldnt even get sent them */ - if((target_p = find_person(parv[1])) && MyClient(target_p)) - do_single_etrace(source_p, target_p); + /* we cant etrace remote clients.. we shouldnt even get sent them */ + if((target_p = find_person(parv[1])) && MyClient(target_p)) + do_single_etrace(source_p, target_p); - sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), - target_p ? target_p->name : parv[1]); + sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), + target_p ? target_p->name : parv[1]); - return 0; + return 0; } static void do_etrace(struct Client *source_p, int ipv4, int ipv6) { - struct Client *target_p; - rb_dlink_node *ptr; + struct Client *target_p; + rb_dlink_node *ptr; - /* report all direct connections */ - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; + /* report all direct connections */ + RB_DLINK_FOREACH(ptr, lclient_list.head) { + target_p = ptr->data; #ifdef RB_IPV6 - if((!ipv4 && target_p->localClient->ip.ss_family == AF_INET) || - (!ipv6 && target_p->localClient->ip.ss_family == AF_INET6)) - continue; + if((!ipv4 && target_p->localClient->ip.ss_family == AF_INET) || + (!ipv6 && target_p->localClient->ip.ss_family == AF_INET6)) + continue; #endif - sendto_one(source_p, form_str(RPL_ETRACE), - me.name, source_p->name, - IsOper(target_p) ? "Oper" : "User", - get_client_class(target_p), - target_p->name, target_p->username, target_p->host, - show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255", - target_p->info); - } + sendto_one(source_p, form_str(RPL_ETRACE), + me.name, source_p->name, + IsOper(target_p) ? "Oper" : "User", + get_client_class(target_p), + target_p->name, target_p->username, target_p->host, + show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255", + target_p->info); + } - sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); + sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); } static void do_etrace_full(struct Client *source_p) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - do_single_etrace(source_p, ptr->data); - } + RB_DLINK_FOREACH(ptr, lclient_list.head) { + do_single_etrace(source_p, ptr->data); + } - sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); + sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); } /* @@ -190,203 +183,190 @@ do_etrace_full(struct Client *source_p) static void do_single_etrace(struct Client *source_p, struct Client *target_p) { - /* note, we hide fullcaps for spoofed users, as mirc can often - * advertise its internal ip address in the field --fl - */ - if(!show_ip(source_p, target_p)) - sendto_one(source_p, form_str(RPL_ETRACEFULL), - me.name, source_p->name, - IsOper(target_p) ? "Oper" : "User", - get_client_class(target_p), - target_p->name, target_p->username, target_p->host, - "255.255.255.255", " ", target_p->info); - else - sendto_one(source_p, form_str(RPL_ETRACEFULL), - me.name, source_p->name, - IsOper(target_p) ? "Oper" : "User", - get_client_class(target_p), - target_p->name, target_p->username, - target_p->host, target_p->sockhost, - target_p->localClient->fullcaps, target_p->info); + /* note, we hide fullcaps for spoofed users, as mirc can often + * advertise its internal ip address in the field --fl + */ + if(!show_ip(source_p, target_p)) + sendto_one(source_p, form_str(RPL_ETRACEFULL), + me.name, source_p->name, + IsOper(target_p) ? "Oper" : "User", + get_client_class(target_p), + target_p->name, target_p->username, target_p->host, + "255.255.255.255", " ", target_p->info); + else + sendto_one(source_p, form_str(RPL_ETRACEFULL), + me.name, source_p->name, + IsOper(target_p) ? "Oper" : "User", + get_client_class(target_p), + target_p->name, target_p->username, + target_p->host, target_p->sockhost, + target_p->localClient->fullcaps, target_p->info); } static int m_chantrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - struct Channel *chptr; - struct membership *msptr; - const char *sockhost; - const char *name; - rb_dlink_node *ptr; - int operspy = 0; + struct Client *target_p; + struct Channel *chptr; + struct membership *msptr; + const char *sockhost; + const char *name; + rb_dlink_node *ptr; + int operspy = 0; - name = parv[1]; + name = parv[1]; - if(IsOperSpy(source_p) && parv[1][0] == '!') - { - name++; - operspy = 1; + if(IsOperSpy(source_p) && parv[1][0] == '!') { + name++; + operspy = 1; - if(EmptyString(name)) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "CHANTRACE"); - return 0; - } - } + if(EmptyString(name)) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "CHANTRACE"); + return 0; + } + } - if((chptr = find_channel(name)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), - name); - return 0; - } + if((chptr = find_channel(name)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), + name); + return 0; + } - /* dont report operspys for nonexistant channels. */ - if(operspy) - report_operspy(source_p, "CHANTRACE", chptr->chname); + /* dont report operspys for nonexistant channels. */ + if(operspy) + report_operspy(source_p, "CHANTRACE", chptr->chname); - if(!operspy && !IsMember(client_p, chptr)) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), - chptr->chname); - return 0; - } + if(!operspy && !IsMember(client_p, chptr)) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), + chptr->chname); + return 0; + } - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(EmptyString(target_p->sockhost)) - sockhost = empty_sockhost; - else if(!show_ip(source_p, target_p)) - sockhost = spoofed_sockhost; - else - sockhost = target_p->sockhost; + if(EmptyString(target_p->sockhost)) + sockhost = empty_sockhost; + else if(!show_ip(source_p, target_p)) + sockhost = spoofed_sockhost; + else + sockhost = target_p->sockhost; - sendto_one(source_p, form_str(RPL_ETRACE), - me.name, source_p->name, - IsOper(target_p) ? "Oper" : "User", - /* class field -- pretend its server.. */ - target_p->servptr->name, - target_p->name, target_p->username, target_p->host, - sockhost, target_p->info); - } + sendto_one(source_p, form_str(RPL_ETRACE), + me.name, source_p->name, + IsOper(target_p) ? "Oper" : "User", + /* class field -- pretend its server.. */ + target_p->servptr->name, + target_p->name, target_p->username, target_p->host, + sockhost, target_p->info); + } - sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); - return 0; + sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); + return 0; } static void match_masktrace(struct Client *source_p, rb_dlink_list *list, - const char *username, const char *hostname, const char *name, - const char *gecos) + const char *username, const char *hostname, const char *name, + const char *gecos) { - struct Client *target_p; - rb_dlink_node *ptr; - const char *sockhost; - - RB_DLINK_FOREACH(ptr, list->head) - { - target_p = ptr->data; - if(!IsPerson(target_p)) - continue; - - if(EmptyString(target_p->sockhost)) - sockhost = empty_sockhost; - else if(!show_ip(source_p, target_p)) - sockhost = spoofed_sockhost; - else - sockhost = target_p->sockhost; + struct Client *target_p; + rb_dlink_node *ptr; + const char *sockhost; - if(match(username, target_p->username) && - (match(hostname, target_p->host) || - match(hostname, target_p->orighost) || - match(hostname, sockhost) || match_ips(hostname, sockhost))) - { - if(name != NULL && !match(name, target_p->name)) - continue; + RB_DLINK_FOREACH(ptr, list->head) { + target_p = ptr->data; + if(!IsPerson(target_p)) + continue; - if(gecos != NULL && !match_esc(gecos, target_p->info)) - continue; - - sendto_one(source_p, form_str(RPL_ETRACE), - me.name, source_p->name, - IsOper(target_p) ? "Oper" : "User", - /* class field -- pretend its server.. */ - target_p->servptr->name, - target_p->name, target_p->username, target_p->host, - sockhost, target_p->info); - } - } + if(EmptyString(target_p->sockhost)) + sockhost = empty_sockhost; + else if(!show_ip(source_p, target_p)) + sockhost = spoofed_sockhost; + else + sockhost = target_p->sockhost; + + if(match(username, target_p->username) && + (match(hostname, target_p->host) || + match(hostname, target_p->orighost) || + match(hostname, sockhost) || match_ips(hostname, sockhost))) { + if(name != NULL && !match(name, target_p->name)) + continue; + + if(gecos != NULL && !match_esc(gecos, target_p->info)) + continue; + + sendto_one(source_p, form_str(RPL_ETRACE), + me.name, source_p->name, + IsOper(target_p) ? "Oper" : "User", + /* class field -- pretend its server.. */ + target_p->servptr->name, + target_p->name, target_p->username, target_p->host, + sockhost, target_p->info); + } + } } static int -mo_masktrace(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]) +mo_masktrace(struct Client *client_p, struct Client *source_p, int parc, + const char *parv[]) { - char *name, *username, *hostname, *gecos; - const char *mask; - int operspy = 0; + char *name, *username, *hostname, *gecos; + const char *mask; + int operspy = 0; - mask = parv[1]; - name = LOCAL_COPY(parv[1]); - collapse(name); + mask = parv[1]; + name = LOCAL_COPY(parv[1]); + collapse(name); - if(IsOperSpy(source_p) && parv[1][0] == '!') - { - name++; - mask++; - operspy = 1; - } - - if(parc > 2 && !EmptyString(parv[2])) - { - gecos = LOCAL_COPY(parv[2]); - collapse_esc(gecos); - } else - gecos = NULL; - + if(IsOperSpy(source_p) && parv[1][0] == '!') { + name++; + mask++; + operspy = 1; + } - if((hostname = strchr(name, '@')) == NULL) - { - sendto_one_notice(source_p, ":Invalid parameters"); - return 0; - } + if(parc > 2 && !EmptyString(parv[2])) { + gecos = LOCAL_COPY(parv[2]); + collapse_esc(gecos); + } else + gecos = NULL; - *hostname++ = '\0'; - - if((username = strchr(name, '!')) == NULL) - { - username = name; - name = NULL; - } else - *username++ = '\0'; - if(EmptyString(username) || EmptyString(hostname)) - { - sendto_one_notice(source_p, ":Invalid parameters"); - return 0; - } - - if(operspy) { - if (!ConfigFileEntry.operspy_dont_care_user_info) - { - char buf[512]; - rb_strlcpy(buf, mask, sizeof(buf)); - if(!EmptyString(gecos)) { - rb_strlcat(buf, " ", sizeof(buf)); - rb_strlcat(buf, gecos, sizeof(buf)); - } + if((hostname = strchr(name, '@')) == NULL) { + sendto_one_notice(source_p, ":Invalid parameters"); + return 0; + } - report_operspy(source_p, "MASKTRACE", buf); - } - match_masktrace(source_p, &global_client_list, username, hostname, name, gecos); - } else - match_masktrace(source_p, &lclient_list, username, hostname, name, gecos); + *hostname++ = '\0'; - sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); - return 0; + if((username = strchr(name, '!')) == NULL) { + username = name; + name = NULL; + } else + *username++ = '\0'; + + if(EmptyString(username) || EmptyString(hostname)) { + sendto_one_notice(source_p, ":Invalid parameters"); + return 0; + } + + if(operspy) { + if (!ConfigFileEntry.operspy_dont_care_user_info) { + char buf[512]; + rb_strlcpy(buf, mask, sizeof(buf)); + if(!EmptyString(gecos)) { + rb_strlcat(buf, " ", sizeof(buf)); + rb_strlcat(buf, gecos, sizeof(buf)); + } + + report_operspy(source_p, "MASKTRACE", buf); + } + match_masktrace(source_p, &global_client_list, username, hostname, name, gecos); + } else + match_masktrace(source_p, &lclient_list, username, hostname, name, gecos); + + sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); + return 0; } diff --git a/modules/m_help.c b/modules/m_help.c index 109e599..6e14ac7 100644 --- a/modules/m_help.c +++ b/modules/m_help.c @@ -43,12 +43,12 @@ static int mo_uhelp(struct Client *, struct Client *, int, const char **); static void dohelp(struct Client *, int, const char *); struct Message help_msgtab = { - "HELP", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}} + "HELP", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}} }; struct Message uhelp_msgtab = { - "UHELP", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}} + "UHELP", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}} }; mapi_clist_av1 help_clist[] = { &help_msgtab, &uhelp_msgtab, NULL }; @@ -60,9 +60,9 @@ DECLARE_MODULE_AV1(help, NULL, NULL, help_clist, NULL, NULL, "$Revision: 254 $") static int m_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); + dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); - return 0; + return 0; } /* @@ -71,8 +71,8 @@ m_help(struct Client *client_p, struct Client *source_p, int parc, const char *p static int mo_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL); - return 0; + dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL); + return 0; } /* @@ -82,55 +82,52 @@ mo_help(struct Client *client_p, struct Client *source_p, int parc, const char * static int mo_uhelp(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); - return 0; + dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); + return 0; } static void dohelp(struct Client *source_p, int flags, const char *topic) { - static const char ntopic[] = "index"; - struct cachefile *hptr; - struct cacheline *lineptr; - rb_dlink_node *ptr; - rb_dlink_node *fptr; + static const char ntopic[] = "index"; + struct cachefile *hptr; + struct cacheline *lineptr; + rb_dlink_node *ptr; + rb_dlink_node *fptr; - if(EmptyString(topic)) - { - topic = ntopic; - if(!EmptyString(ServerInfo.helpchan)) - sendto_one(source_p, ":%s 525 %s :Official Help Channel: %s", - me.name, source_p->name, ServerInfo.helpchan); - if(!EmptyString(ServerInfo.helpurl)) - sendto_one(source_p, ":%s 526 %s :Official Help URL: %s", - me.name, source_p->name, ServerInfo.helpurl); - } + if(EmptyString(topic)) { + topic = ntopic; + if(!EmptyString(ServerInfo.helpchan)) + sendto_one(source_p, ":%s 525 %s :Official Help Channel: %s", + me.name, source_p->name, ServerInfo.helpchan); + if(!EmptyString(ServerInfo.helpurl)) + sendto_one(source_p, ":%s 526 %s :Official Help URL: %s", + me.name, source_p->name, ServerInfo.helpurl); + } - hptr = irc_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic); + hptr = irc_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic); - if(hptr == NULL || !(hptr->flags & flags)) - { - sendto_one(source_p, form_str(ERR_HELPNOTFOUND), - me.name, source_p->name, topic); - return; - } + if(hptr == NULL || !(hptr->flags & flags)) { + sendto_one(source_p, form_str(ERR_HELPNOTFOUND), + me.name, source_p->name, topic); + return; + } - fptr = hptr->contents.head; - lineptr = fptr->data; + fptr = hptr->contents.head; + lineptr = fptr->data; - /* first line cant be empty */ - sendto_one(source_p, form_str(RPL_HELPSTART), - me.name, source_p->name, topic, lineptr->data); + /* first line cant be empty */ + sendto_one(source_p, form_str(RPL_HELPSTART), + me.name, source_p->name, topic, lineptr->data); - RB_DLINK_FOREACH(ptr, fptr->next) - { - lineptr = ptr->data; + RB_DLINK_FOREACH(ptr, fptr->next) { + lineptr = ptr->data; - sendto_one(source_p, form_str(RPL_HELPTXT), - me.name, source_p->name, topic, lineptr->data); - } + sendto_one(source_p, form_str(RPL_HELPTXT), + me.name, source_p->name, topic, lineptr->data); + } - sendto_one(source_p, form_str(RPL_ENDOFHELP), - me.name, source_p->name, topic); - return; + sendto_one(source_p, form_str(RPL_ENDOFHELP), + me.name, source_p->name, topic); + return; } diff --git a/modules/m_info.c b/modules/m_info.c index 40533fc..97ccd07 100644 --- a/modules/m_info.c +++ b/modules/m_info.c @@ -49,16 +49,16 @@ static int m_info(struct Client *, struct Client *, int, const char **); static int mo_info(struct Client *, struct Client *, int, const char **); struct Message info_msgtab = { - "INFO", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_info, 0}, {mo_info, 0}, mg_ignore, mg_ignore, {mo_info, 0}} + "INFO", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_info, 0}, {mo_info, 0}, mg_ignore, mg_ignore, {mo_info, 0}} }; int doing_info_hook; mapi_clist_av1 info_clist[] = { &info_msgtab, NULL }; mapi_hlist_av1 info_hlist[] = { - { "doing_info", &doing_info_hook }, - { NULL, NULL } + { "doing_info", &doing_info_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(info, NULL, NULL, info_clist, info_hlist, NULL, "$Revision: 3396 $"); @@ -66,12 +66,11 @@ DECLARE_MODULE_AV1(info, NULL, NULL, info_clist, info_hlist, NULL, "$Revision: 3 /* * jdc -- Structure for our configuration value table */ -struct InfoStruct -{ - const char *name; /* Displayed variable name */ - unsigned int output_type; /* See below #defines */ - void *option; /* Pointer reference to the value */ - const char *desc; /* ASCII description of the variable */ +struct InfoStruct { + const char *name; /* Displayed variable name */ + unsigned int output_type; /* See below #defines */ + void *option; /* Pointer reference to the value */ + const char *desc; /* ASCII description of the variable */ }; /* Types for output_type in InfoStruct */ #define OUTPUT_STRING 0x0001 /* Output option as %s w/ dereference */ @@ -83,640 +82,640 @@ struct InfoStruct /* *INDENT-OFF* */ static struct InfoStruct info_table[] = { - /* --[ START OF TABLE ]-------------------------------------------- */ - { - "opers_see_all_users", - OUTPUT_BOOLEAN_YN, - &opers_see_all_users, - "Farconnect notices available or operspy accountability limited" - }, - { - "max_connections", - OUTPUT_DECIMAL, - &maxconnections, - "Max number connections" - }, - { - "anti_nick_flood", - OUTPUT_BOOLEAN, - &ConfigFileEntry.anti_nick_flood, - "NICK flood protection" - }, - { - "anti_spam_exit_message_time", - OUTPUT_DECIMAL, - &ConfigFileEntry.anti_spam_exit_message_time, - "Duration a client must be connected for to have an exit message" - }, - { - "use_part_messages", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.use_part_messages, - "Whether or not the server should allow users to show messages on PART" - }, - { - "caller_id_wait", - OUTPUT_DECIMAL, - &ConfigFileEntry.caller_id_wait, - "Minimum delay between notifying UMODE +g users of messages" - }, - { - "client_exit", - OUTPUT_BOOLEAN, - &ConfigFileEntry.client_exit, - "Prepend 'Client Exit:' to user QUIT messages" - }, - { - "client_flood", - OUTPUT_DECIMAL, - &ConfigFileEntry.client_flood, - "Number of lines before a client Excess Flood's", - }, - { - "connect_timeout", - OUTPUT_DECIMAL, - &ConfigFileEntry.connect_timeout, - "Connect timeout for connections to servers" - }, - { - "default_ident_timeout", - OUTPUT_DECIMAL, - &ConfigFileEntry.default_ident_timeout, - "Amount of time the server waits for ident responses from clients", - }, - { - "default_floodcount", - OUTPUT_DECIMAL, - &ConfigFileEntry.default_floodcount, - "Startup value of FLOODCOUNT", - }, - { - "hide_channel_below_users", - OUTPUT_DECIMAL, - &ConfigFileEntry.hide_channel_below_users, - "Hide channels below this many users in standard /LIST output", - }, - { - "default_adminstring", - OUTPUT_STRING, - &ConfigFileEntry.default_adminstring, - "Default adminstring at startup.", - }, - { - "default_operstring", - OUTPUT_STRING, - &ConfigFileEntry.default_operstring, - "Default operstring at startup.", - }, - { - "default_operhost", - OUTPUT_STRING, - &ConfigFileEntry.default_operhost, - "Default vhost for operators to receive upon opering up.", - }, - { - "static_quit", - OUTPUT_STRING, - &ConfigFileEntry.static_quit, - "Quit message to show for all users.", - }, - { - "servicestring", - OUTPUT_STRING, - &ConfigFileEntry.servicestring, - "String shown in whois for opered services.", - }, - { - "disable_auth", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.disable_auth, - "Controls whether auth checking is disabled or not" - }, - { - "disable_fake_channels", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.disable_fake_channels, - "Controls whether bold etc are disabled for JOIN" - }, - { - "dots_in_ident", - OUTPUT_DECIMAL, - &ConfigFileEntry.dots_in_ident, - "Number of permissable dots in an ident" - }, - { - "expire_override_time", - OUTPUT_DECIMAL, - &ConfigFileEntry.expire_override_time, - "Period of time after which to unset user mode +p" - }, - { - "failed_oper_notice", - OUTPUT_BOOLEAN, - &ConfigFileEntry.failed_oper_notice, - "Inform opers if someone /oper's with the wrong password" - }, - { - "fname_userlog", - OUTPUT_STRING, - &ConfigFileEntry.fname_userlog, - "User log file" - }, - { - "fname_fuserlog", - OUTPUT_STRING, - &ConfigFileEntry.fname_fuserlog, - "Failed user log file" - }, + /* --[ START OF TABLE ]-------------------------------------------- */ + { + "opers_see_all_users", + OUTPUT_BOOLEAN_YN, + &opers_see_all_users, + "Farconnect notices available or operspy accountability limited" + }, + { + "max_connections", + OUTPUT_DECIMAL, + &maxconnections, + "Max number connections" + }, + { + "anti_nick_flood", + OUTPUT_BOOLEAN, + &ConfigFileEntry.anti_nick_flood, + "NICK flood protection" + }, + { + "anti_spam_exit_message_time", + OUTPUT_DECIMAL, + &ConfigFileEntry.anti_spam_exit_message_time, + "Duration a client must be connected for to have an exit message" + }, + { + "use_part_messages", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.use_part_messages, + "Whether or not the server should allow users to show messages on PART" + }, + { + "caller_id_wait", + OUTPUT_DECIMAL, + &ConfigFileEntry.caller_id_wait, + "Minimum delay between notifying UMODE +g users of messages" + }, + { + "client_exit", + OUTPUT_BOOLEAN, + &ConfigFileEntry.client_exit, + "Prepend 'Client Exit:' to user QUIT messages" + }, + { + "client_flood", + OUTPUT_DECIMAL, + &ConfigFileEntry.client_flood, + "Number of lines before a client Excess Flood's", + }, + { + "connect_timeout", + OUTPUT_DECIMAL, + &ConfigFileEntry.connect_timeout, + "Connect timeout for connections to servers" + }, + { + "default_ident_timeout", + OUTPUT_DECIMAL, + &ConfigFileEntry.default_ident_timeout, + "Amount of time the server waits for ident responses from clients", + }, + { + "default_floodcount", + OUTPUT_DECIMAL, + &ConfigFileEntry.default_floodcount, + "Startup value of FLOODCOUNT", + }, + { + "hide_channel_below_users", + OUTPUT_DECIMAL, + &ConfigFileEntry.hide_channel_below_users, + "Hide channels below this many users in standard /LIST output", + }, + { + "default_adminstring", + OUTPUT_STRING, + &ConfigFileEntry.default_adminstring, + "Default adminstring at startup.", + }, + { + "default_operstring", + OUTPUT_STRING, + &ConfigFileEntry.default_operstring, + "Default operstring at startup.", + }, + { + "default_operhost", + OUTPUT_STRING, + &ConfigFileEntry.default_operhost, + "Default vhost for operators to receive upon opering up.", + }, + { + "static_quit", + OUTPUT_STRING, + &ConfigFileEntry.static_quit, + "Quit message to show for all users.", + }, + { + "servicestring", + OUTPUT_STRING, + &ConfigFileEntry.servicestring, + "String shown in whois for opered services.", + }, + { + "disable_auth", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.disable_auth, + "Controls whether auth checking is disabled or not" + }, + { + "disable_fake_channels", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.disable_fake_channels, + "Controls whether bold etc are disabled for JOIN" + }, + { + "dots_in_ident", + OUTPUT_DECIMAL, + &ConfigFileEntry.dots_in_ident, + "Number of permissable dots in an ident" + }, + { + "expire_override_time", + OUTPUT_DECIMAL, + &ConfigFileEntry.expire_override_time, + "Period of time after which to unset user mode +p" + }, + { + "failed_oper_notice", + OUTPUT_BOOLEAN, + &ConfigFileEntry.failed_oper_notice, + "Inform opers if someone /oper's with the wrong password" + }, + { + "fname_userlog", + OUTPUT_STRING, + &ConfigFileEntry.fname_userlog, + "User log file" + }, + { + "fname_fuserlog", + OUTPUT_STRING, + &ConfigFileEntry.fname_fuserlog, + "Failed user log file" + }, - { - "fname_operlog", - OUTPUT_STRING, - &ConfigFileEntry.fname_operlog, - "Operator log file" - }, - { - "fname_foperlog", - OUTPUT_STRING, - &ConfigFileEntry.fname_foperlog, - "Failed operator log file" - }, - { - "fname_serverlog", - OUTPUT_STRING, - &ConfigFileEntry.fname_serverlog, - "Server connect/disconnect log file" - }, - { - "fname_klinelog", - OUTPUT_STRING, - &ConfigFileEntry.fname_klinelog, - "KLINE etc log file" - }, - { - "fname_operspylog", - OUTPUT_STRING, - &ConfigFileEntry.fname_operspylog, - "Oper spy log file" - }, - { - "fname_ioerrorlog", - OUTPUT_STRING, - &ConfigFileEntry.fname_ioerrorlog, - "IO error log file" - }, - { - "global_snotices", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.global_snotices, - "Send out certain server notices globally" - }, - { - "hide_error_messages", - OUTPUT_BOOLEAN2, - &ConfigFileEntry.hide_error_messages, - "Hide ERROR messages coming from servers" - }, - { - "hide_spoof_ips", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.hide_spoof_ips, - "Hide IPs of spoofed users" - }, - { - "hub", - OUTPUT_BOOLEAN_YN, - &ServerInfo.hub, - "Server is a hub" - }, - { - "kline_delay", - OUTPUT_DECIMAL, - &ConfigFileEntry.kline_delay, - "Duration of time to delay kline checking" - }, - { - "kline_reason", - OUTPUT_STRING, - &ConfigFileEntry.kline_reason, - "K-lined clients sign off with this reason" - }, - { - "dline_with_reason", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.dline_with_reason, - "Display D-line reason to client on disconnect" - }, - { - "kline_with_reason", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.kline_with_reason, - "Display K-line reason to client on disconnect" - }, - { - "max_accept", - OUTPUT_DECIMAL, - &ConfigFileEntry.max_accept, - "Maximum nicknames on accept list", - }, - { - "max_nick_changes", - OUTPUT_DECIMAL, - &ConfigFileEntry.max_nick_changes, - "NICK change threshhold setting" - }, - { - "max_nick_time", - OUTPUT_DECIMAL, - &ConfigFileEntry.max_nick_time, - "NICK flood protection time interval" - }, - { - "max_targets", - OUTPUT_DECIMAL, - &ConfigFileEntry.max_targets, - "The maximum number of PRIVMSG/NOTICE targets" - }, - { - "min_nonwildcard", - OUTPUT_DECIMAL, - &ConfigFileEntry.min_nonwildcard, - "Minimum non-wildcard chars in K lines", - }, - { - "min_nonwildcard_simple", - OUTPUT_DECIMAL, - &ConfigFileEntry.min_nonwildcard_simple, - "Minimum non-wildcard chars in xlines/resvs", - }, - { - "network_name", - OUTPUT_STRING, - &ServerInfo.network_name, - "Network name" - }, - { - "network_desc", - OUTPUT_STRING, - &ServerInfo.network_desc, - "Network description" - }, - { - "autochanmodes", - OUTPUT_STRING, - &ConfigChannel.autochanmodes, - "Channelmodes set on channel creation" - }, - { - "exemptchanops", - OUTPUT_STRING, - &ConfigChannel.exemptchanops, - "Channelmodes that chanops are exempt from" - }, - { - "nick_delay", - OUTPUT_DECIMAL, - &ConfigFileEntry.nick_delay, - "Delay nicks are locked for on split", - }, - { - "no_oper_flood", - OUTPUT_BOOLEAN, - &ConfigFileEntry.no_oper_flood, - "Disable flood control for operators", - }, - { - "true_no_oper_flood", - OUTPUT_BOOLEAN, - &ConfigFileEntry.true_no_oper_flood, - "Really disable flood control for opers, not just make it very high", - }, - { - "non_redundant_klines", - OUTPUT_BOOLEAN, - &ConfigFileEntry.non_redundant_klines, - "Check for and disallow redundant K-lines" - }, - { - "operspy_admin_only", - OUTPUT_BOOLEAN, - &ConfigFileEntry.operspy_admin_only, - "Send +Z operspy notices to admins only" - }, - { - "operspy_dont_care_user_info", - OUTPUT_BOOLEAN, - &ConfigFileEntry.operspy_dont_care_user_info, - "Remove accountability and some '!' requirement from non-channel operspy" - }, - { - "secret_channels_in_whois", - OUTPUT_BOOLEAN, - &ConfigFileEntry.secret_channels_in_whois, - "Defines whether secret channels are always shown in whois to opers with oper:spy priv." - }, - { - "pace_wait", - OUTPUT_DECIMAL, - &ConfigFileEntry.pace_wait, - "Minimum delay between uses of certain commands" - }, - { - "pace_wait_simple", - OUTPUT_DECIMAL, - &ConfigFileEntry.pace_wait_simple, - "Minimum delay between less intensive commands" - }, - { - "ping_cookie", - OUTPUT_BOOLEAN, - &ConfigFileEntry.ping_cookie, - "Require ping cookies to connect", - }, - { - "reject_after_count", - OUTPUT_DECIMAL, - &ConfigFileEntry.reject_after_count, - "Client rejection threshold setting", - }, - { - "reject_ban_time", - OUTPUT_DECIMAL, - &ConfigFileEntry.reject_ban_time, - "Client rejection time interval", - }, - { - "reject_duration", - OUTPUT_DECIMAL, - &ConfigFileEntry.reject_duration, - "Client rejection cache duration", - }, - { - "short_motd", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.short_motd, - "Do not show MOTD; only tell clients they should read it" - }, - { - "stats_e_disabled", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.stats_e_disabled, - "STATS e output is disabled", - }, - { - "stats_c_oper_only", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.stats_c_oper_only, - "STATS C output is only shown to operators", - }, - { - "stats_h_oper_only", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.stats_h_oper_only, - "STATS H output is only shown to operators", - }, - { - "stats_i_oper_only", - OUTPUT_BOOLEAN2, - &ConfigFileEntry.stats_i_oper_only, - "STATS I output is only shown to operators", - }, - { - "stats_k_oper_only", - OUTPUT_BOOLEAN2, - &ConfigFileEntry.stats_k_oper_only, - "STATS K output is only shown to operators", - }, - { - "stats_o_oper_only", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.stats_o_oper_only, - "STATS O output is only shown to operators", - }, - { - "stats_P_oper_only", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.stats_P_oper_only, - "STATS P is only shown to operators", - }, - { - "stats_y_oper_only", - OUTPUT_BOOLEAN_YN, - &ConfigFileEntry.stats_y_oper_only, - "STATS Y is only shown to operators", - }, - { - "throttle_count", - OUTPUT_DECIMAL, - &ConfigFileEntry.throttle_count, - "Connection throttle threshold", - }, - { - "throttle_duration", - OUTPUT_DECIMAL, - &ConfigFileEntry.throttle_duration, - "Connection throttle duration", - }, - { - "tkline_expire_notices", - OUTPUT_BOOLEAN, - &ConfigFileEntry.tkline_expire_notices, - "Notices given to opers when tklines expire" - }, - { - "ts_max_delta", - OUTPUT_DECIMAL, - &ConfigFileEntry.ts_max_delta, - "Maximum permitted TS delta from another server" - }, - { - "ts_warn_delta", - OUTPUT_DECIMAL, - &ConfigFileEntry.ts_warn_delta, - "Maximum permitted TS delta before displaying a warning" - }, - { - "warn_no_nline", - OUTPUT_BOOLEAN, - &ConfigFileEntry.warn_no_nline, - "Display warning if connecting server lacks N-line" - }, - { - "use_propagated_bans", - OUTPUT_BOOLEAN, - &ConfigFileEntry.use_propagated_bans, - "KLINE sets fully propagated bans" - }, + { + "fname_operlog", + OUTPUT_STRING, + &ConfigFileEntry.fname_operlog, + "Operator log file" + }, + { + "fname_foperlog", + OUTPUT_STRING, + &ConfigFileEntry.fname_foperlog, + "Failed operator log file" + }, + { + "fname_serverlog", + OUTPUT_STRING, + &ConfigFileEntry.fname_serverlog, + "Server connect/disconnect log file" + }, + { + "fname_klinelog", + OUTPUT_STRING, + &ConfigFileEntry.fname_klinelog, + "KLINE etc log file" + }, + { + "fname_operspylog", + OUTPUT_STRING, + &ConfigFileEntry.fname_operspylog, + "Oper spy log file" + }, + { + "fname_ioerrorlog", + OUTPUT_STRING, + &ConfigFileEntry.fname_ioerrorlog, + "IO error log file" + }, + { + "global_snotices", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.global_snotices, + "Send out certain server notices globally" + }, + { + "hide_error_messages", + OUTPUT_BOOLEAN2, + &ConfigFileEntry.hide_error_messages, + "Hide ERROR messages coming from servers" + }, + { + "hide_spoof_ips", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.hide_spoof_ips, + "Hide IPs of spoofed users" + }, + { + "hub", + OUTPUT_BOOLEAN_YN, + &ServerInfo.hub, + "Server is a hub" + }, + { + "kline_delay", + OUTPUT_DECIMAL, + &ConfigFileEntry.kline_delay, + "Duration of time to delay kline checking" + }, + { + "kline_reason", + OUTPUT_STRING, + &ConfigFileEntry.kline_reason, + "K-lined clients sign off with this reason" + }, + { + "dline_with_reason", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.dline_with_reason, + "Display D-line reason to client on disconnect" + }, + { + "kline_with_reason", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.kline_with_reason, + "Display K-line reason to client on disconnect" + }, + { + "max_accept", + OUTPUT_DECIMAL, + &ConfigFileEntry.max_accept, + "Maximum nicknames on accept list", + }, + { + "max_nick_changes", + OUTPUT_DECIMAL, + &ConfigFileEntry.max_nick_changes, + "NICK change threshhold setting" + }, + { + "max_nick_time", + OUTPUT_DECIMAL, + &ConfigFileEntry.max_nick_time, + "NICK flood protection time interval" + }, + { + "max_targets", + OUTPUT_DECIMAL, + &ConfigFileEntry.max_targets, + "The maximum number of PRIVMSG/NOTICE targets" + }, + { + "min_nonwildcard", + OUTPUT_DECIMAL, + &ConfigFileEntry.min_nonwildcard, + "Minimum non-wildcard chars in K lines", + }, + { + "min_nonwildcard_simple", + OUTPUT_DECIMAL, + &ConfigFileEntry.min_nonwildcard_simple, + "Minimum non-wildcard chars in xlines/resvs", + }, + { + "network_name", + OUTPUT_STRING, + &ServerInfo.network_name, + "Network name" + }, + { + "network_desc", + OUTPUT_STRING, + &ServerInfo.network_desc, + "Network description" + }, + { + "autochanmodes", + OUTPUT_STRING, + &ConfigChannel.autochanmodes, + "Channelmodes set on channel creation" + }, + { + "exemptchanops", + OUTPUT_STRING, + &ConfigChannel.exemptchanops, + "Channelmodes that chanops are exempt from" + }, + { + "nick_delay", + OUTPUT_DECIMAL, + &ConfigFileEntry.nick_delay, + "Delay nicks are locked for on split", + }, + { + "no_oper_flood", + OUTPUT_BOOLEAN, + &ConfigFileEntry.no_oper_flood, + "Disable flood control for operators", + }, + { + "true_no_oper_flood", + OUTPUT_BOOLEAN, + &ConfigFileEntry.true_no_oper_flood, + "Really disable flood control for opers, not just make it very high", + }, + { + "non_redundant_klines", + OUTPUT_BOOLEAN, + &ConfigFileEntry.non_redundant_klines, + "Check for and disallow redundant K-lines" + }, + { + "operspy_admin_only", + OUTPUT_BOOLEAN, + &ConfigFileEntry.operspy_admin_only, + "Send +Z operspy notices to admins only" + }, + { + "operspy_dont_care_user_info", + OUTPUT_BOOLEAN, + &ConfigFileEntry.operspy_dont_care_user_info, + "Remove accountability and some '!' requirement from non-channel operspy" + }, + { + "secret_channels_in_whois", + OUTPUT_BOOLEAN, + &ConfigFileEntry.secret_channels_in_whois, + "Defines whether secret channels are always shown in whois to opers with oper:spy priv." + }, + { + "pace_wait", + OUTPUT_DECIMAL, + &ConfigFileEntry.pace_wait, + "Minimum delay between uses of certain commands" + }, + { + "pace_wait_simple", + OUTPUT_DECIMAL, + &ConfigFileEntry.pace_wait_simple, + "Minimum delay between less intensive commands" + }, + { + "ping_cookie", + OUTPUT_BOOLEAN, + &ConfigFileEntry.ping_cookie, + "Require ping cookies to connect", + }, + { + "reject_after_count", + OUTPUT_DECIMAL, + &ConfigFileEntry.reject_after_count, + "Client rejection threshold setting", + }, + { + "reject_ban_time", + OUTPUT_DECIMAL, + &ConfigFileEntry.reject_ban_time, + "Client rejection time interval", + }, + { + "reject_duration", + OUTPUT_DECIMAL, + &ConfigFileEntry.reject_duration, + "Client rejection cache duration", + }, + { + "short_motd", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.short_motd, + "Do not show MOTD; only tell clients they should read it" + }, + { + "stats_e_disabled", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.stats_e_disabled, + "STATS e output is disabled", + }, + { + "stats_c_oper_only", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.stats_c_oper_only, + "STATS C output is only shown to operators", + }, + { + "stats_h_oper_only", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.stats_h_oper_only, + "STATS H output is only shown to operators", + }, + { + "stats_i_oper_only", + OUTPUT_BOOLEAN2, + &ConfigFileEntry.stats_i_oper_only, + "STATS I output is only shown to operators", + }, + { + "stats_k_oper_only", + OUTPUT_BOOLEAN2, + &ConfigFileEntry.stats_k_oper_only, + "STATS K output is only shown to operators", + }, + { + "stats_o_oper_only", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.stats_o_oper_only, + "STATS O output is only shown to operators", + }, + { + "stats_P_oper_only", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.stats_P_oper_only, + "STATS P is only shown to operators", + }, + { + "stats_y_oper_only", + OUTPUT_BOOLEAN_YN, + &ConfigFileEntry.stats_y_oper_only, + "STATS Y is only shown to operators", + }, + { + "throttle_count", + OUTPUT_DECIMAL, + &ConfigFileEntry.throttle_count, + "Connection throttle threshold", + }, + { + "throttle_duration", + OUTPUT_DECIMAL, + &ConfigFileEntry.throttle_duration, + "Connection throttle duration", + }, + { + "tkline_expire_notices", + OUTPUT_BOOLEAN, + &ConfigFileEntry.tkline_expire_notices, + "Notices given to opers when tklines expire" + }, + { + "ts_max_delta", + OUTPUT_DECIMAL, + &ConfigFileEntry.ts_max_delta, + "Maximum permitted TS delta from another server" + }, + { + "ts_warn_delta", + OUTPUT_DECIMAL, + &ConfigFileEntry.ts_warn_delta, + "Maximum permitted TS delta before displaying a warning" + }, + { + "warn_no_nline", + OUTPUT_BOOLEAN, + &ConfigFileEntry.warn_no_nline, + "Display warning if connecting server lacks N-line" + }, + { + "use_propagated_bans", + OUTPUT_BOOLEAN, + &ConfigFileEntry.use_propagated_bans, + "KLINE sets fully propagated bans" + }, { "away_interval", OUTPUT_DECIMAL, &ConfigFileEntry.away_interval, "The minimum time between aways", }, - { - "default_split_server_count", - OUTPUT_DECIMAL, - &ConfigChannel.default_split_server_count, - "Startup value of SPLITNUM", - }, - { - "default_split_user_count", - OUTPUT_DECIMAL, - &ConfigChannel.default_split_user_count, - "Startup value of SPLITUSERS", - }, - { - "knock_delay", - OUTPUT_DECIMAL, - &ConfigChannel.knock_delay, - "Delay between a users KNOCK attempts" - }, - { - "knock_delay_channel", - OUTPUT_DECIMAL, - &ConfigChannel.knock_delay_channel, - "Delay between KNOCK attempts to a channel", - }, - { - "kick_on_split_riding", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.kick_on_split_riding, - "Kick users riding splits to join +i or +k channels" - }, - { - "max_bans", - OUTPUT_DECIMAL, - &ConfigChannel.max_bans, - "Total +b/e/I/q modes allowed in a channel", - }, - { - "max_bans_large", - OUTPUT_DECIMAL, - &ConfigChannel.max_bans_large, - "Total +b/e/I/q modes allowed in a +L channel", - }, - { - "max_chans_per_user", - OUTPUT_DECIMAL, - &ConfigChannel.max_chans_per_user, - "Maximum number of channels a user can join", - }, - { - "no_create_on_split", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.no_create_on_split, - "Disallow creation of channels when split", - }, - { - "no_join_on_split", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.no_join_on_split, - "Disallow joining channels when split", - }, - { - "only_ascii_channels", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.only_ascii_channels, - "Controls whether non-ASCII is disabled for JOIN" - }, - { - "cycle_host_change", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.cycle_host_change, - "Controls if when a users' host changes, they cycle channels", - }, - { - "host_in_topic", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.host_in_topic, - "Defines whether a topicsetters host or just nick is shown on TOPIC", - }, - { - "admin_on_channel_create", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.admin_on_channel_create, - "Give users +ao on channel create", - }, - { - "use_halfop", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_halfop, - "Enable chanmode +h (halfop)", - }, - { - "use_admin", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_admin, - "Enable chanmode +a (admin)", - }, - { - "use_owner", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_owner, - "Enable chanmode +y (owner)", - }, - { - "use_except", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_except, - "Enable chanmode +e (ban exceptions)", - }, - { - "use_invex", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_invex, - "Enable chanmode +I (invite exceptions)", - }, - { - "use_forward", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_forward, - "Enable chanmode +f (channel forwarding)", - }, - { - "use_knock", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.use_knock, - "Enable /KNOCK", - }, + { + "default_split_server_count", + OUTPUT_DECIMAL, + &ConfigChannel.default_split_server_count, + "Startup value of SPLITNUM", + }, + { + "default_split_user_count", + OUTPUT_DECIMAL, + &ConfigChannel.default_split_user_count, + "Startup value of SPLITUSERS", + }, + { + "knock_delay", + OUTPUT_DECIMAL, + &ConfigChannel.knock_delay, + "Delay between a users KNOCK attempts" + }, + { + "knock_delay_channel", + OUTPUT_DECIMAL, + &ConfigChannel.knock_delay_channel, + "Delay between KNOCK attempts to a channel", + }, + { + "kick_on_split_riding", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.kick_on_split_riding, + "Kick users riding splits to join +i or +k channels" + }, + { + "max_bans", + OUTPUT_DECIMAL, + &ConfigChannel.max_bans, + "Total +b/e/I/q modes allowed in a channel", + }, + { + "max_bans_large", + OUTPUT_DECIMAL, + &ConfigChannel.max_bans_large, + "Total +b/e/I/q modes allowed in a +L channel", + }, + { + "max_chans_per_user", + OUTPUT_DECIMAL, + &ConfigChannel.max_chans_per_user, + "Maximum number of channels a user can join", + }, + { + "no_create_on_split", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.no_create_on_split, + "Disallow creation of channels when split", + }, + { + "no_join_on_split", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.no_join_on_split, + "Disallow joining channels when split", + }, + { + "only_ascii_channels", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.only_ascii_channels, + "Controls whether non-ASCII is disabled for JOIN" + }, + { + "cycle_host_change", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.cycle_host_change, + "Controls if when a users' host changes, they cycle channels", + }, + { + "host_in_topic", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.host_in_topic, + "Defines whether a topicsetters host or just nick is shown on TOPIC", + }, + { + "admin_on_channel_create", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.admin_on_channel_create, + "Give users +ao on channel create", + }, + { + "use_halfop", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_halfop, + "Enable chanmode +h (halfop)", + }, + { + "use_admin", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_admin, + "Enable chanmode +a (admin)", + }, + { + "use_owner", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_owner, + "Enable chanmode +y (owner)", + }, + { + "use_except", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_except, + "Enable chanmode +e (ban exceptions)", + }, + { + "use_invex", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_invex, + "Enable chanmode +I (invite exceptions)", + }, + { + "use_forward", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_forward, + "Enable chanmode +f (channel forwarding)", + }, + { + "use_knock", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.use_knock, + "Enable /KNOCK", + }, { "use_local_channels", OUTPUT_BOOLEAN_YN, &ConfigChannel.use_local_channels, "Enable local channels (&channels)" }, - { - "resv_forcepart", - OUTPUT_BOOLEAN_YN, - &ConfigChannel.resv_forcepart, - "Force-part local users on channel RESV" - }, - { - "disable_hidden", - OUTPUT_BOOLEAN_YN, - &ConfigServerHide.disable_hidden, - "Prevent servers from hiding themselves from a flattened /links", - }, - { - "flatten_links", - OUTPUT_BOOLEAN_YN, - &ConfigServerHide.flatten_links, - "Flatten /links list", - }, - { - "hidden", - OUTPUT_BOOLEAN_YN, - &ConfigServerHide.hidden, - "Hide this server from a flattened /links on remote servers", - }, - { - "links_delay", - OUTPUT_DECIMAL, - &ConfigServerHide.links_delay, - "Links rehash delay" - }, - /* --[ END OF TABLE ]---------------------------------------------- */ - { (char *) 0, (unsigned int) 0, (void *) 0, (char *) 0} + { + "resv_forcepart", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.resv_forcepart, + "Force-part local users on channel RESV" + }, + { + "disable_hidden", + OUTPUT_BOOLEAN_YN, + &ConfigServerHide.disable_hidden, + "Prevent servers from hiding themselves from a flattened /links", + }, + { + "flatten_links", + OUTPUT_BOOLEAN_YN, + &ConfigServerHide.flatten_links, + "Flatten /links list", + }, + { + "hidden", + OUTPUT_BOOLEAN_YN, + &ConfigServerHide.hidden, + "Hide this server from a flattened /links on remote servers", + }, + { + "links_delay", + OUTPUT_DECIMAL, + &ConfigServerHide.links_delay, + "Links rehash delay" + }, + /* --[ END OF TABLE ]---------------------------------------------- */ + { (char *) 0, (unsigned int) 0, (void *) 0, (char *) 0} }; /* *INDENT-ON* */ @@ -727,29 +726,27 @@ static struct InfoStruct info_table[] = { static int m_info(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0L; + static time_t last_used = 0L; - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "INFO"); - sendto_one_numeric(source_p, RPL_ENDOFINFO, form_str(RPL_ENDOFINFO)); - return 0; - } - else - last_used = rb_current_time(); + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + /* safe enough to give this on a local connect only */ + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "INFO"); + sendto_one_numeric(source_p, RPL_ENDOFINFO, form_str(RPL_ENDOFINFO)); + return 0; + } else + last_used = rb_current_time(); - if(hunt_server(client_p, source_p, ":%s INFO :%s", 1, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s INFO :%s", 1, parc, parv) != HUNTED_ISME) + return 0; - info_spy(source_p); + info_spy(source_p); - send_info_text(source_p); - send_birthdate_online_time(source_p); + send_info_text(source_p); + send_birthdate_online_time(source_p); - sendto_one_numeric(source_p, RPL_ENDOFINFO, form_str(RPL_ENDOFINFO)); - return 0; + sendto_one_numeric(source_p, RPL_ENDOFINFO, form_str(RPL_ENDOFINFO)); + return 0; } /* @@ -759,24 +756,22 @@ m_info(struct Client *client_p, struct Client *source_p, int parc, const char *p static int mo_info(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(hunt_server(client_p, source_p, ":%s INFO :%s", 1, parc, parv) == HUNTED_ISME) - { - info_spy(source_p); - send_info_text(source_p); + if(hunt_server(client_p, source_p, ":%s INFO :%s", 1, parc, parv) == HUNTED_ISME) { + info_spy(source_p); + send_info_text(source_p); - if(IsOper(source_p)) - { - send_conf_options(source_p); - sendto_one_numeric(source_p, RPL_INFO, ":%s", - rb_lib_version()); - } + if(IsOper(source_p)) { + send_conf_options(source_p); + sendto_one_numeric(source_p, RPL_INFO, ":%s", + rb_lib_version()); + } - send_birthdate_online_time(source_p); + send_birthdate_online_time(source_p); - sendto_one_numeric(source_p, RPL_ENDOFINFO, form_str(RPL_ENDOFINFO)); - } + sendto_one_numeric(source_p, RPL_ENDOFINFO, form_str(RPL_ENDOFINFO)); + } - return 0; + return 0; } /* @@ -789,14 +784,13 @@ mo_info(struct Client *client_p, struct Client *source_p, int parc, const char * static void send_info_text(struct Client *source_p) { - const char **text = infotext; + const char **text = infotext; - while (*text) - { - sendto_one_numeric(source_p, RPL_INFO, form_str(RPL_INFO), *text++); - } + while (*text) { + sendto_one_numeric(source_p, RPL_INFO, form_str(RPL_INFO), *text++); + } - sendto_one_numeric(source_p, RPL_INFO, form_str(RPL_INFO), ""); + sendto_one_numeric(source_p, RPL_INFO, form_str(RPL_INFO), ""); } /* @@ -809,14 +803,14 @@ send_info_text(struct Client *source_p) static void send_birthdate_online_time(struct Client *source_p) { - char tbuf[26]; /* this needs to be 26 - see ctime_r manpage */ - sendto_one(source_p, ":%s %d %s :Birth Date: %s, compile # %s", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), creation, generation); + char tbuf[26]; /* this needs to be 26 - see ctime_r manpage */ + sendto_one(source_p, ":%s %d %s :Birth Date: %s, compile # %s", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), creation, generation); - sendto_one(source_p, ":%s %d %s :On-line since %s", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), rb_ctime(startup_time, tbuf, sizeof(tbuf))); + sendto_one(source_p, ":%s %d %s :On-line since %s", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), rb_ctime(startup_time, tbuf, sizeof(tbuf))); } /* @@ -829,145 +823,133 @@ send_birthdate_online_time(struct Client *source_p) static void send_conf_options(struct Client *source_p) { - Info *infoptr; - int i = 0; + Info *infoptr; + int i = 0; - /* - * Now send them a list of all our configuration options - * (mostly from config.h) - */ - for (infoptr = MyInformation; infoptr->name; infoptr++) - { - if(infoptr->intvalue) - { - sendto_one(source_p, ":%s %d %s :%-30s %-5d [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - infoptr->name, infoptr->intvalue, - infoptr->desc); - } - else - { - sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - infoptr->name, infoptr->strvalue, - infoptr->desc); - } - } + /* + * Now send them a list of all our configuration options + * (mostly from config.h) + */ + for (infoptr = MyInformation; infoptr->name; infoptr++) { + if(infoptr->intvalue) { + sendto_one(source_p, ":%s %d %s :%-30s %-5d [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + infoptr->name, infoptr->intvalue, + infoptr->desc); + } else { + sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + infoptr->name, infoptr->strvalue, + infoptr->desc); + } + } - /* - * Parse the info_table[] and do the magic. - */ - for (i = 0; info_table[i].name; i++) - { - switch (info_table[i].output_type) - { - /* - * For "char *" references - */ - case OUTPUT_STRING: - { - char *option = *((char **) info_table[i].option); + /* + * Parse the info_table[] and do the magic. + */ + for (i = 0; info_table[i].name; i++) { + switch (info_table[i].output_type) { + /* + * For "char *" references + */ + case OUTPUT_STRING: { + char *option = *((char **) info_table[i].option); - sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - info_table[i].name, - option ? option : "NONE", - info_table[i].desc ? info_table[i].desc : ""); + sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + info_table[i].name, + option ? option : "NONE", + info_table[i].desc ? info_table[i].desc : ""); - break; - } - /* - * For "char foo[]" references - */ - case OUTPUT_STRING_PTR: - { - char *option = (char *) info_table[i].option; + break; + } + /* + * For "char foo[]" references + */ + case OUTPUT_STRING_PTR: { + char *option = (char *) info_table[i].option; - sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - info_table[i].name, - EmptyString(option) ? "NONE" : option, - info_table[i].desc ? info_table[i].desc : ""); + sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + info_table[i].name, + EmptyString(option) ? "NONE" : option, + info_table[i].desc ? info_table[i].desc : ""); - break; - } - /* - * Output info_table[i].option as a decimal value. - */ - case OUTPUT_DECIMAL: - { - int option = *((int *) info_table[i].option); + break; + } + /* + * Output info_table[i].option as a decimal value. + */ + case OUTPUT_DECIMAL: { + int option = *((int *) info_table[i].option); - sendto_one(source_p, ":%s %d %s :%-30s %-5d [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - info_table[i].name, - option, - info_table[i].desc ? info_table[i].desc : ""); + sendto_one(source_p, ":%s %d %s :%-30s %-5d [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + info_table[i].name, + option, + info_table[i].desc ? info_table[i].desc : ""); - break; - } + break; + } - /* - * Output info_table[i].option as "ON" or "OFF" - */ - case OUTPUT_BOOLEAN: - { - int option = *((int *) info_table[i].option); + /* + * Output info_table[i].option as "ON" or "OFF" + */ + case OUTPUT_BOOLEAN: { + int option = *((int *) info_table[i].option); - sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - info_table[i].name, - option ? "ON" : "OFF", - info_table[i].desc ? info_table[i].desc : ""); + sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + info_table[i].name, + option ? "ON" : "OFF", + info_table[i].desc ? info_table[i].desc : ""); - break; - } - /* - * Output info_table[i].option as "YES" or "NO" - */ - case OUTPUT_BOOLEAN_YN: - { - int option = *((int *) info_table[i].option); + break; + } + /* + * Output info_table[i].option as "YES" or "NO" + */ + case OUTPUT_BOOLEAN_YN: { + int option = *((int *) info_table[i].option); - sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", - get_id(&me, source_p), RPL_INFO, - get_id(source_p, source_p), - info_table[i].name, - option ? "YES" : "NO", - info_table[i].desc ? info_table[i].desc : ""); + sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", + get_id(&me, source_p), RPL_INFO, + get_id(source_p, source_p), + info_table[i].name, + option ? "YES" : "NO", + info_table[i].desc ? info_table[i].desc : ""); - break; - } + break; + } - case OUTPUT_BOOLEAN2: - { - int option = *((int *) info_table[i].option); + case OUTPUT_BOOLEAN2: { + int option = *((int *) info_table[i].option); - sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", - me.name, RPL_INFO, source_p->name, - info_table[i].name, - option ? ((option == 1) ? "MASK" : "YES") : "NO", - info_table[i].desc ? info_table[i].desc : ""); - } /* switch (info_table[i].output_type) */ - } - } /* forloop */ + sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]", + me.name, RPL_INFO, source_p->name, + info_table[i].name, + option ? ((option == 1) ? "MASK" : "YES") : "NO", + info_table[i].desc ? info_table[i].desc : ""); + } /* switch (info_table[i].output_type) */ + } + } /* forloop */ - /* Don't send oper_only_umodes...it's a bit mask, we will have to decode it - ** in order for it to show up properly to opers who issue INFO - */ + /* Don't send oper_only_umodes...it's a bit mask, we will have to decode it + ** in order for it to show up properly to opers who issue INFO + */ - sendto_one_numeric(source_p, RPL_INFO, form_str(RPL_INFO), ""); + sendto_one_numeric(source_p, RPL_INFO, form_str(RPL_INFO), ""); } /* info_spy() - * + * * input - pointer to client * output - none * side effects - hook doing_info is called @@ -975,10 +957,10 @@ send_conf_options(struct Client *source_p) static void info_spy(struct Client *source_p) { - hook_data hd; + hook_data hd; - hd.client = source_p; - hd.arg1 = hd.arg2 = NULL; + hd.client = source_p; + hd.arg1 = hd.arg2 = NULL; - call_hook(doing_info_hook, &hd); + call_hook(doing_info_hook, &hd); } diff --git a/modules/m_invite.c b/modules/m_invite.c index ed1c53d..7fcb653 100644 --- a/modules/m_invite.c +++ b/modules/m_invite.c @@ -43,8 +43,8 @@ static int m_invite(struct Client *, struct Client *, int, const char **); struct Message invite_msgtab = { - "INVITE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}} + "INVITE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}} }; mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL }; DECLARE_MODULE_AV1(invite, NULL, NULL, invite_clist, NULL, NULL, "$Revision: 3438 $"); @@ -58,197 +58,173 @@ static void add_invite(struct Channel *, struct Client *); static int m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - struct Channel *chptr; - struct membership *msptr; - int store_invite = 0; + struct Client *target_p; + struct Channel *chptr; + struct membership *msptr; + int store_invite = 0; - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - if(MyClient(source_p)) - target_p = find_named_person(parv[1]); - else - target_p = find_person(parv[1]); - if(target_p == NULL) - { - if(!MyClient(source_p) && IsDigit(parv[1][0])) - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - "* :Target left IRC. Failed to invite to %s", - parv[2]); - else - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), - parv[1]); - return 0; - } + if(MyClient(source_p)) + target_p = find_named_person(parv[1]); + else + target_p = find_person(parv[1]); + if(target_p == NULL) { + if(!MyClient(source_p) && IsDigit(parv[1][0])) + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + "* :Target left IRC. Failed to invite to %s", + parv[2]); + else + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), + parv[1]); + return 0; + } - if(check_channel_name(parv[2]) == 0) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), - parv[2]); - return 0; - } + if(check_channel_name(parv[2]) == 0) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), + parv[2]); + return 0; + } - if(!IsChannelName(parv[2])) - { - if(MyClient(source_p)) - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[2]); - return 0; - } + if(!IsChannelName(parv[2])) { + if(MyClient(source_p)) + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[2]); + return 0; + } - /* Do not send local channel invites to users if they are not on the - * same server as the person sending the INVITE message. - */ - if(parv[2][0] == '&' && !MyConnect(target_p)) - { - sendto_one(source_p, form_str(ERR_USERNOTONSERV), - me.name, source_p->name, target_p->name); - return 0; - } + /* Do not send local channel invites to users if they are not on the + * same server as the person sending the INVITE message. + */ + if(parv[2][0] == '&' && !MyConnect(target_p)) { + sendto_one(source_p, form_str(ERR_USERNOTONSERV), + me.name, source_p->name, target_p->name); + return 0; + } - if(((MyConnect(source_p) && !IsExemptResv(source_p)) || - (MyConnect(target_p) && !IsExemptResv(target_p))) && - hash_find_resv(parv[2])) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), - parv[2]); - return 0; - } + if(((MyConnect(source_p) && !IsExemptResv(source_p)) || + (MyConnect(target_p) && !IsExemptResv(target_p))) && + hash_find_resv(parv[2])) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), + parv[2]); + return 0; + } - if((chptr = find_channel(parv[2])) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[2]); - return 0; - } + if((chptr = find_channel(parv[2])) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[2]); + return 0; + } - msptr = find_channel_membership(chptr, source_p); - if(MyClient(source_p) && (msptr == NULL)) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), parv[2]); - return 0; - } + msptr = find_channel_membership(chptr, source_p); + if(MyClient(source_p) && (msptr == NULL)) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), parv[2]); + return 0; + } - if(IsMember(target_p, chptr)) - { - sendto_one_numeric(source_p, ERR_USERONCHANNEL, - form_str(ERR_USERONCHANNEL), - target_p->name, parv[2]); - return 0; - } + if(IsMember(target_p, chptr)) { + sendto_one_numeric(source_p, ERR_USERONCHANNEL, + form_str(ERR_USERONCHANNEL), + target_p->name, parv[2]); + return 0; + } - /* unconditionally require ops, unless the channel is +g */ - /* treat remote clients as chanops */ - if(MyClient(source_p) && !is_any_op(msptr) && - !(chptr->mode.mode & MODE_FREEINVITE)) - { - if(IsOverride(source_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding INVITE [%s] on [%s]", - get_oper_name(source_p), target_p->name, chptr->chname); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding INVITE [%s] on [%s]", - me.name, get_oper_name(source_p), target_p->name, chptr->chname); - } - else - { - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, parv[2]); - return 0; - } - } + /* unconditionally require ops, unless the channel is +g */ + /* treat remote clients as chanops */ + if(MyClient(source_p) && !is_any_op(msptr) && + !(chptr->mode.mode & MODE_FREEINVITE)) { + if(IsOverride(source_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding INVITE [%s] on [%s]", + get_oper_name(source_p), target_p->name, chptr->chname); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding INVITE [%s] on [%s]", + me.name, get_oper_name(source_p), target_p->name, chptr->chname); + } else { + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, parv[2]); + return 0; + } + } - if (IsSetNoInvite(target_p)) - { - sendto_one_numeric(source_p, ERR_NOINVITE, - form_str(ERR_NOINVITE), - target_p->name); - return 0; - } + if (IsSetNoInvite(target_p)) { + sendto_one_numeric(source_p, ERR_NOINVITE, + form_str(ERR_NOINVITE), + target_p->name); + return 0; + } - /* store invites when they could affect the ability to join - * for +l/+j just check if the mode is set, this varies over time - */ - if(chptr->mode.mode & MODE_INVITEONLY || - (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) || - chptr->mode.limit || chptr->mode.join_num) - store_invite = 1; + /* store invites when they could affect the ability to join + * for +l/+j just check if the mode is set, this varies over time + */ + if(chptr->mode.mode & MODE_INVITEONLY || + (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) || + chptr->mode.limit || chptr->mode.join_num) + store_invite = 1; - if(MyConnect(source_p)) - { - if (ConfigFileEntry.target_change && !IsOper(source_p) && - !find_allowing_channel(source_p, target_p) && - !add_target(source_p, target_p)) - { - sendto_one(source_p, form_str(ERR_TARGCHANGE), - me.name, source_p->name, target_p->name); - return 0; - } - sendto_one(source_p, form_str(RPL_INVITING), - me.name, source_p->name, - target_p->name, parv[2]); - if(target_p->user->away) - sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), - target_p->name, target_p->user->away); - } - /* invite timestamp */ - else if(parc > 3 && !EmptyString(parv[3])) - { - /* this should never be less than */ - if(atol(parv[3]) > chptr->channelts) - return 0; - } + if(MyConnect(source_p)) { + if (ConfigFileEntry.target_change && !IsOper(source_p) && + !find_allowing_channel(source_p, target_p) && + !add_target(source_p, target_p)) { + sendto_one(source_p, form_str(ERR_TARGCHANGE), + me.name, source_p->name, target_p->name); + return 0; + } + sendto_one(source_p, form_str(RPL_INVITING), + me.name, source_p->name, + target_p->name, parv[2]); + if(target_p->user->away) + sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), + target_p->name, target_p->user->away); + } + /* invite timestamp */ + else if(parc > 3 && !EmptyString(parv[3])) { + /* this should never be less than */ + if(atol(parv[3]) > chptr->channelts) + return 0; + } - if(MyConnect(target_p)) - { - if(!IsOper(source_p) && (IsSetCallerId(target_p) || - (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && - !accept_message(source_p, target_p)) - { - if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) - { - sendto_one_numeric(source_p, ERR_NONONREG, - form_str(ERR_NONONREG), - target_p->name); - return 0; - } - else - { - /* instead of sending RPL_UMODEGMSG, - * just let the invite through - */ - if((target_p->localClient->last_caller_id_time + - ConfigFileEntry.caller_id_wait) >= rb_current_time()) - { - sendto_one_numeric(source_p, ERR_TARGUMODEG, - form_str(ERR_TARGUMODEG), - target_p->name); - return 0; - } - target_p->localClient->last_caller_id_time = rb_current_time(); - } - } - add_reply_target(target_p, source_p); - sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", - source_p->name, source_p->username, source_p->host, - target_p->name, chptr->chname); + if(MyConnect(target_p)) { + if(!IsOper(source_p) && (IsSetCallerId(target_p) || + (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && + !accept_message(source_p, target_p)) { + if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) { + sendto_one_numeric(source_p, ERR_NONONREG, + form_str(ERR_NONONREG), + target_p->name); + return 0; + } else { + /* instead of sending RPL_UMODEGMSG, + * just let the invite through + */ + if((target_p->localClient->last_caller_id_time + + ConfigFileEntry.caller_id_wait) >= rb_current_time()) { + sendto_one_numeric(source_p, ERR_TARGUMODEG, + form_str(ERR_TARGUMODEG), + target_p->name); + return 0; + } + target_p->localClient->last_caller_id_time = rb_current_time(); + } + } + add_reply_target(target_p, source_p); + sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", + source_p->name, source_p->username, source_p->host, + target_p->name, chptr->chname); - if(store_invite) - add_invite(chptr, target_p); - } - else if(target_p->from != client_p) - { - sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu", - chptr->chname, (unsigned long) chptr->channelts); - } + if(store_invite) + add_invite(chptr, target_p); + } else if(target_p->from != client_p) { + sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu", + chptr->chname, (unsigned long) chptr->channelts); + } - return 0; + return 0; } /* add_invite() @@ -260,28 +236,26 @@ m_invite(struct Client *client_p, struct Client *source_p, int parc, const char static void add_invite(struct Channel *chptr, struct Client *who) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - /* already invited? */ - RB_DLINK_FOREACH(ptr, who->user->invited.head) - { - if(ptr->data == chptr) - return; - } + /* already invited? */ + RB_DLINK_FOREACH(ptr, who->user->invited.head) { + if(ptr->data == chptr) + return; + } - /* ok, if their invite list is too long, remove the tail */ - if((int)rb_dlink_list_length(&who->user->invited) >= - ConfigChannel.max_chans_per_user) - { - ptr = who->user->invited.tail; - del_invite(ptr->data, who); - } + /* ok, if their invite list is too long, remove the tail */ + if((int)rb_dlink_list_length(&who->user->invited) >= + ConfigChannel.max_chans_per_user) { + ptr = who->user->invited.tail; + del_invite(ptr->data, who); + } - /* add user to channel invite list */ - rb_dlinkAddAlloc(who, &chptr->invites); + /* add user to channel invite list */ + rb_dlinkAddAlloc(who, &chptr->invites); - /* add channel to user invite list */ - rb_dlinkAddAlloc(chptr, &who->user->invited); + /* add channel to user invite list */ + rb_dlinkAddAlloc(chptr, &who->user->invited); } diff --git a/modules/m_ison.c b/modules/m_ison.c index 425f99d..5964414 100644 --- a/modules/m_ison.c +++ b/modules/m_ison.c @@ -41,8 +41,8 @@ static int m_ison(struct Client *, struct Client *, int, const char **); struct Message ison_msgtab = { - "ISON", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_ison, 2}, mg_ignore, mg_ignore, mg_ignore, {m_ison, 2}} + "ISON", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_ison, 2}, mg_ignore, mg_ignore, mg_ignore, {m_ison, 2}} }; mapi_clist_av1 ison_clist[] = { &ison_msgtab, NULL }; @@ -64,60 +64,54 @@ static char buf2[BUFSIZE]; static int m_ison(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - char *nick; - char *p; - char *current_insert_point, *current_insert_point2; - int len; - int i; - int done = 0; + struct Client *target_p; + char *nick; + char *p; + char *current_insert_point, *current_insert_point2; + int len; + int i; + int done = 0; - current_insert_point2 = buf2; - *buf2 = '\0'; + current_insert_point2 = buf2; + *buf2 = '\0'; - rb_sprintf(buf, form_str(RPL_ISON), me.name, source_p->name); - len = strlen(buf); - current_insert_point = buf + len; + rb_sprintf(buf, form_str(RPL_ISON), me.name, source_p->name); + len = strlen(buf); + current_insert_point = buf + len; - /* rfc1489 is ambigious about how to handle ISON - * this should handle both interpretations. - */ - for (i = 1; i < parc; i++) - { - char *cs = LOCAL_COPY(parv[i]); - for (nick = rb_strtok_r(cs, " ", &p); nick; nick = rb_strtok_r(NULL, " ", &p)) - { - target_p = find_named_client(nick); + /* rfc1489 is ambigious about how to handle ISON + * this should handle both interpretations. + */ + for (i = 1; i < parc; i++) { + char *cs = LOCAL_COPY(parv[i]); + for (nick = rb_strtok_r(cs, " ", &p); nick; nick = rb_strtok_r(NULL, " ", &p)) { + target_p = find_named_client(nick); - if(target_p != NULL) - { - len = strlen(target_p->name); - if((current_insert_point + (len + 5)) < (buf + sizeof(buf))) - { - memcpy((void *) current_insert_point, - (void *) target_p->name, len); - current_insert_point += len; - *current_insert_point++ = ' '; - } - else - { - done = 1; - break; - } - } - } - if(done) - break; - } + if(target_p != NULL) { + len = strlen(target_p->name); + if((current_insert_point + (len + 5)) < (buf + sizeof(buf))) { + memcpy((void *) current_insert_point, + (void *) target_p->name, len); + current_insert_point += len; + *current_insert_point++ = ' '; + } else { + done = 1; + break; + } + } + } + if(done) + break; + } - /* current_insert_point--; - * Do NOT take out the trailing space, it breaks ircII - * --Rodder */ + /* current_insert_point--; + * Do NOT take out the trailing space, it breaks ircII + * --Rodder */ - *current_insert_point = '\0'; - *current_insert_point2 = '\0'; + *current_insert_point = '\0'; + *current_insert_point2 = '\0'; - sendto_one(source_p, "%s", buf); + sendto_one(source_p, "%s", buf); - return 0; + return 0; } diff --git a/modules/m_kline.c b/modules/m_kline.c index 89ba235..cad06bb 100644 --- a/modules/m_kline.c +++ b/modules/m_kline.c @@ -54,13 +54,13 @@ static int ms_unkline(struct Client *, struct Client *, int, const char **); static int me_unkline(struct Client *, struct Client *, int, const char **); struct Message kline_msgtab = { - "KLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_kline, 5}, {ms_kline, 5}, {me_kline, 5}, {mo_kline, 3}} + "KLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_kline, 5}, {ms_kline, 5}, {me_kline, 5}, {mo_kline, 3}} }; struct Message unkline_msgtab = { - "UNKLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_unkline, 4}, {ms_unkline, 4}, {me_unkline, 3}, {mo_unkline, 2}} + "UNKLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_unkline, 4}, {ms_unkline, 4}, {me_unkline, 3}, {mo_unkline, 2}} }; mapi_clist_av1 kline_clist[] = { &kline_msgtab, &unkline_msgtab, NULL }; @@ -73,13 +73,13 @@ static int valid_comment(struct Client *source_p, char *comment); static int valid_user_host(struct Client *source_p, const char *user, const char *host); static void handle_remote_kline(struct Client *source_p, int tkline_time, - const char *user, const char *host, const char *reason); + const char *user, const char *host, const char *reason); static void apply_kline(struct Client *source_p, struct ConfItem *aconf, - const char *reason, const char *oper_reason); + const char *reason, const char *oper_reason); static void apply_tkline(struct Client *source_p, struct ConfItem *aconf, - const char *, const char *, int); + const char *, const char *, int); static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, - const char *, const char *, int); + const char *, const char *, int); static int already_placed_kline(struct Client *, const char *, const char *, int); static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host); @@ -98,136 +98,125 @@ static void remove_prop_kline(struct Client *, struct ConfItem *); static int mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - char def[] = "No Reason"; - char user[USERLEN + 2]; - char host[HOSTLEN + 2]; - char *reason = def; - char *oper_reason; - const char *target_server = NULL; - struct ConfItem *aconf; - int tkline_time = 0; - int loc = 1; - int propagated = ConfigFileEntry.use_propagated_bans; + char def[] = "No Reason"; + char user[USERLEN + 2]; + char host[HOSTLEN + 2]; + char *reason = def; + char *oper_reason; + const char *target_server = NULL; + struct ConfItem *aconf; + int tkline_time = 0; + int loc = 1; + int propagated = ConfigFileEntry.use_propagated_bans; - if(!IsOperK(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); - return 0; - } + if(!IsOperK(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); + return 0; + } - if((tkline_time = valid_temp_time(parv[loc])) >= 0) - loc++; - /* we just set tkline_time to -1! */ - else - tkline_time = 0; + if((tkline_time = valid_temp_time(parv[loc])) >= 0) + loc++; + /* we just set tkline_time to -1! */ + else + tkline_time = 0; - if(find_user_host(source_p, parv[loc], user, host) == 0) - return 0; + if(find_user_host(source_p, parv[loc], user, host) == 0) + return 0; - loc++; + loc++; - if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - target_server = parv[loc + 1]; - loc += 2; - } + target_server = parv[loc + 1]; + loc += 2; + } - if(parc <= loc || EmptyString(parv[loc])) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "KLINE"); - return 0; - } + if(parc <= loc || EmptyString(parv[loc])) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "KLINE"); + return 0; + } - reason = LOCAL_COPY(parv[loc]); + reason = LOCAL_COPY(parv[loc]); - if(target_server != NULL) - { - propagate_generic(source_p, "KLINE", target_server, CAP_KLN, - "%d %s %s :%s", tkline_time, user, host, reason); + if(target_server != NULL) { + propagate_generic(source_p, "KLINE", target_server, CAP_KLN, + "%d %s %s :%s", tkline_time, user, host, reason); - /* If we are sending it somewhere that doesnt include us, stop */ - if(!match(target_server, me.name)) - return 0; + /* If we are sending it somewhere that doesnt include us, stop */ + if(!match(target_server, me.name)) + return 0; - /* Set as local-only. */ - propagated = 0; - } - /* if we have cluster servers, send it to them.. */ - else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_generic(source_p, "KLINE", - (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN, - "%lu %s %s :%s", tkline_time, user, host, reason); + /* Set as local-only. */ + propagated = 0; + } + /* if we have cluster servers, send it to them.. */ + else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_generic(source_p, "KLINE", + (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN, + "%lu %s %s :%s", tkline_time, user, host, reason); - if(!valid_user_host(source_p, user, host) || - !valid_comment(source_p, reason)) - return 0; + if(!valid_user_host(source_p, user, host) || + !valid_comment(source_p, reason)) + return 0; - if(!valid_wild_card(user, host)) - { - sendto_one_notice(source_p, - ":Please include at least %d non-wildcard " - "characters with the user@host", - ConfigFileEntry.min_nonwildcard); - return 0; - } + if(!valid_wild_card(user, host)) { + sendto_one_notice(source_p, + ":Please include at least %d non-wildcard " + "characters with the user@host", + ConfigFileEntry.min_nonwildcard); + return 0; + } - if(propagated && tkline_time == 0) - { - sendto_one_notice(source_p, ":Cannot set a permanent global ban"); - return 0; - } + if(propagated && tkline_time == 0) { + sendto_one_notice(source_p, ":Cannot set a permanent global ban"); + return 0; + } - if(already_placed_kline(source_p, user, host, tkline_time)) - return 0; + if(already_placed_kline(source_p, user, host, tkline_time)) + return 0; - rb_set_time(); - aconf = make_conf(); - aconf->status = CONF_KILL; - aconf->created = rb_current_time(); - aconf->host = rb_strdup(host); - aconf->user = rb_strdup(user); - aconf->port = 0; - aconf->info.oper = operhash_add(get_oper_name(source_p)); + rb_set_time(); + aconf = make_conf(); + aconf->status = CONF_KILL; + aconf->created = rb_current_time(); + aconf->host = rb_strdup(host); + aconf->user = rb_strdup(user); + aconf->port = 0; + aconf->info.oper = operhash_add(get_oper_name(source_p)); - /* Look for an oper reason */ - if((oper_reason = strchr(reason, '|')) != NULL) - { - *oper_reason = '\0'; - oper_reason++; + /* Look for an oper reason */ + if((oper_reason = strchr(reason, '|')) != NULL) { + *oper_reason = '\0'; + oper_reason++; - if(!EmptyString(oper_reason)) - aconf->spasswd = rb_strdup(oper_reason); - } - aconf->passwd = rb_strdup(reason); + if(!EmptyString(oper_reason)) + aconf->spasswd = rb_strdup(oper_reason); + } + aconf->passwd = rb_strdup(reason); - if(propagated) - apply_prop_kline(source_p, aconf, reason, oper_reason, tkline_time); - else if(tkline_time > 0) - apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); - else - apply_kline(source_p, aconf, reason, oper_reason); + if(propagated) + apply_prop_kline(source_p, aconf, reason, oper_reason, tkline_time); + else if(tkline_time > 0) + apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); + else + apply_kline(source_p, aconf, reason, oper_reason); - if(ConfigFileEntry.kline_delay) - { - if(kline_queued == 0) - { - rb_event_addonce("check_klines", check_klines_event, NULL, - ConfigFileEntry.kline_delay); - kline_queued = 1; - } - } - else - check_klines(); + if(ConfigFileEntry.kline_delay) { + if(kline_queued == 0) { + rb_event_addonce("check_klines", check_klines_event, NULL, + ConfigFileEntry.kline_delay); + kline_queued = 1; + } + } else + check_klines(); - return 0; + return 0; } /* ms_kline() @@ -241,105 +230,100 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char static int ms_kline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int tkline_time = atoi(parv[2]); + int tkline_time = atoi(parv[2]); - /* 1.5-3 and earlier contains a bug that allows remote klines to be - * sent with an empty reason field. This is a protocol violation, - * but its not worth dropping the link over.. --anfl - */ - if(parc < 6 || EmptyString(parv[5])) - return 0; + /* 1.5-3 and earlier contains a bug that allows remote klines to be + * sent with an empty reason field. This is a protocol violation, + * but its not worth dropping the link over.. --anfl + */ + if(parc < 6 || EmptyString(parv[5])) + return 0; - propagate_generic(source_p, "KLINE", parv[1], CAP_KLN, - "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]); + propagate_generic(source_p, "KLINE", parv[1], CAP_KLN, + "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]); - if(!match(parv[1], me.name)) - return 0; + if(!match(parv[1], me.name)) + return 0; - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - handle_remote_kline(source_p, tkline_time, parv[3], parv[4], parv[5]); - return 0; + handle_remote_kline(source_p, tkline_time, parv[3], parv[4], parv[5]); + return 0; } static int me_kline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* : */ - if(!IsPerson(source_p)) - return 0; + /* : */ + if(!IsPerson(source_p)) + return 0; - handle_remote_kline(source_p, atoi(parv[1]), parv[2], parv[3], parv[4]); - return 0; + handle_remote_kline(source_p, atoi(parv[1]), parv[2], parv[3], parv[4]); + return 0; } static void handle_remote_kline(struct Client *source_p, int tkline_time, - const char *user, const char *host, const char *kreason) + const char *user, const char *host, const char *kreason) { - char *reason = LOCAL_COPY(kreason); - struct ConfItem *aconf = NULL; - char *oper_reason; + char *reason = LOCAL_COPY(kreason); + struct ConfItem *aconf = NULL; + char *oper_reason; - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, - (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE)) - return; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, + (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE)) + return; - if(!valid_user_host(source_p, user, host) || - !valid_comment(source_p, reason)) - return; + if(!valid_user_host(source_p, user, host) || + !valid_comment(source_p, reason)) + return; - if(!valid_wild_card(user, host)) - { - sendto_one_notice(source_p, - ":Please include at least %d non-wildcard " - "characters with the user@host", - ConfigFileEntry.min_nonwildcard); - return; - } + if(!valid_wild_card(user, host)) { + sendto_one_notice(source_p, + ":Please include at least %d non-wildcard " + "characters with the user@host", + ConfigFileEntry.min_nonwildcard); + return; + } - if(already_placed_kline(source_p, user, host, tkline_time)) - return; + if(already_placed_kline(source_p, user, host, tkline_time)) + return; - aconf = make_conf(); + aconf = make_conf(); - aconf->status = CONF_KILL; - aconf->created = rb_current_time(); - aconf->user = rb_strdup(user); - aconf->host = rb_strdup(host); - aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf->status = CONF_KILL; + aconf->created = rb_current_time(); + aconf->user = rb_strdup(user); + aconf->host = rb_strdup(host); + aconf->info.oper = operhash_add(get_oper_name(source_p)); - /* Look for an oper reason */ - if((oper_reason = strchr(reason, '|')) != NULL) - { - *oper_reason = '\0'; - oper_reason++; + /* Look for an oper reason */ + if((oper_reason = strchr(reason, '|')) != NULL) { + *oper_reason = '\0'; + oper_reason++; - if(!EmptyString(oper_reason)) - aconf->spasswd = rb_strdup(oper_reason); - } - aconf->passwd = rb_strdup(reason); + if(!EmptyString(oper_reason)) + aconf->spasswd = rb_strdup(oper_reason); + } + aconf->passwd = rb_strdup(reason); - if(tkline_time > 0) - apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); - else - apply_kline(source_p, aconf, reason, oper_reason); + if(tkline_time > 0) + apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); + else + apply_kline(source_p, aconf, reason, oper_reason); - if(ConfigFileEntry.kline_delay) - { - if(kline_queued == 0) - { - rb_event_addonce("check_klines", check_klines_event, NULL, - ConfigFileEntry.kline_delay); - kline_queued = 1; - } - } - else - check_klines(); + if(ConfigFileEntry.kline_delay) { + if(kline_queued == 0) { + rb_event_addonce("check_klines", check_klines_event, NULL, + ConfigFileEntry.kline_delay); + kline_queued = 1; + } + } else + check_klines(); - return; + return; } /* mo_unkline() @@ -351,96 +335,85 @@ handle_remote_kline(struct Client *source_p, int tkline_time, static int mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *user; - char *host; - char splat[] = "*"; - char *h = LOCAL_COPY(parv[1]); - struct ConfItem *aconf; - int propagated = 1; + const char *user; + char *host; + char splat[] = "*"; + char *h = LOCAL_COPY(parv[1]); + struct ConfItem *aconf; + int propagated = 1; - if(!IsOperUnkline(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); - return 0; - } + if(!IsOperUnkline(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); + return 0; + } - if((host = strchr(h, '@')) || *h == '*' || strchr(h, '.') || strchr(h, ':')) - { - /* Explicit user@host mask given */ + if((host = strchr(h, '@')) || *h == '*' || strchr(h, '.') || strchr(h, ':')) { + /* Explicit user@host mask given */ - if(host) /* Found user@host */ - { - *host++ = '\0'; + if(host) { /* Found user@host */ + *host++ = '\0'; - /* check for @host */ - if(*h) - user = h; - else - user = splat; + /* check for @host */ + if(*h) + user = h; + else + user = splat; - /* check for user@ */ - if(!*host) - host = splat; - } - else - { - user = splat; /* no @ found, assume its *@somehost */ - host = h; - } - } - else - { - sendto_one_notice(source_p, ":Invalid parameters"); - return 0; - } + /* check for user@ */ + if(!*host) + host = splat; + } else { + user = splat; /* no @ found, assume its *@somehost */ + host = h; + } + } else { + sendto_one_notice(source_p, ":Invalid parameters"); + return 0; + } - /* possible remote kline.. */ - if((parc > 3) && (irccmp(parv[2], "ON") == 0)) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + /* possible remote kline.. */ + if((parc > 3) && (irccmp(parv[2], "ON") == 0)) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host); + propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host); - if(match(parv[3], me.name) == 0) - return 0; + if(match(parv[3], me.name) == 0) + return 0; - propagated = 0; - } + propagated = 0; + } - aconf = find_exact_conf_by_address(host, CONF_KILL, user); + aconf = find_exact_conf_by_address(host, CONF_KILL, user); - /* No clustering for removing a propagated kline */ - if(propagated && (aconf == NULL || !aconf->lifetime) && - rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_generic(source_p, "UNKLINE", SHARED_UNKLINE, CAP_UNKLN, - "%s %s", user, host); + /* No clustering for removing a propagated kline */ + if(propagated && (aconf == NULL || !aconf->lifetime) && + rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_generic(source_p, "UNKLINE", SHARED_UNKLINE, CAP_UNKLN, + "%s %s", user, host); - if(aconf == NULL) - { - sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); - return 0; - } - - if(aconf->lifetime) - { - if(propagated) - remove_prop_kline(source_p, aconf); - else - sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); - return 0; - } + if(aconf == NULL) { + sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); + return 0; + } - if(remove_temp_kline(source_p, aconf)) - return 0; + if(aconf->lifetime) { + if(propagated) + remove_prop_kline(source_p, aconf); + else + sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); + return 0; + } - remove_permkline_match(source_p, aconf); + if(remove_temp_kline(source_p, aconf)) + return 0; - return 0; + remove_permkline_match(source_p, aconf); + + return 0; } /* ms_unkline() @@ -452,94 +425,89 @@ mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const cha static int ms_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* parv[0] parv[1] parv[2] parv[3] - * oper target server user host */ - propagate_generic(source_p, "UNKLINE", parv[1], CAP_UNKLN, "%s %s", parv[2], parv[3]); + /* parv[0] parv[1] parv[2] parv[3] + * oper target server user host */ + propagate_generic(source_p, "UNKLINE", parv[1], CAP_UNKLN, "%s %s", parv[2], parv[3]); - if(!match(parv[1], me.name)) - return 0; + if(!match(parv[1], me.name)) + return 0; - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - handle_remote_unkline(source_p, parv[2], parv[3]); - return 0; + handle_remote_unkline(source_p, parv[2], parv[3]); + return 0; } static int me_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* user host */ - if(!IsPerson(source_p)) - return 0; + /* user host */ + if(!IsPerson(source_p)) + return 0; - handle_remote_unkline(source_p, parv[1], parv[2]); - return 0; + handle_remote_unkline(source_p, parv[1], parv[2]); + return 0; } static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host) { - struct ConfItem *aconf; + struct ConfItem *aconf; - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, SHARED_UNKLINE)) - return; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, SHARED_UNKLINE)) + return; - aconf = find_exact_conf_by_address(host, CONF_KILL, user); - if(aconf == NULL) - { - sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); - return; - } - if(aconf->lifetime) - { - sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); - return; - } + aconf = find_exact_conf_by_address(host, CONF_KILL, user); + if(aconf == NULL) { + sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); + return; + } + if(aconf->lifetime) { + sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); + return; + } - if(remove_temp_kline(source_p, aconf)) - return; + if(remove_temp_kline(source_p, aconf)) + return; - remove_permkline_match(source_p, aconf); + remove_permkline_match(source_p, aconf); } /* apply_kline() * - * inputs - + * inputs - * output - NONE * side effects - kline as given, is added to the hashtable * and conf file */ static void apply_kline(struct Client *source_p, struct ConfItem *aconf, - const char *reason, const char *oper_reason) + const char *reason, const char *oper_reason) { - add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); - bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, - reason, EmptyString(oper_reason) ? NULL : oper_reason, 0); + add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); + bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, + reason, EmptyString(oper_reason) ? NULL : oper_reason, 0); - /* no oper reason.. */ - if(EmptyString(oper_reason)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added K-Line for [%s@%s] [%s]", - get_oper_name(source_p), aconf->user, aconf->host, reason); - ilog(L_KLINE, "K %s 0 %s %s %s", - get_oper_name(source_p), aconf->user, aconf->host, reason); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added K-Line for [%s@%s] [%s|%s]", - get_oper_name(source_p), aconf->user, aconf->host, - reason, oper_reason); - ilog(L_KLINE, "K %s 0 %s %s %s|%s", - get_oper_name(source_p), aconf->user, aconf->host, reason, oper_reason); - } + /* no oper reason.. */ + if(EmptyString(oper_reason)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added K-Line for [%s@%s] [%s]", + get_oper_name(source_p), aconf->user, aconf->host, reason); + ilog(L_KLINE, "K %s 0 %s %s %s", + get_oper_name(source_p), aconf->user, aconf->host, reason); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added K-Line for [%s@%s] [%s|%s]", + get_oper_name(source_p), aconf->user, aconf->host, + reason, oper_reason); + ilog(L_KLINE, "K %s 0 %s %s %s|%s", + get_oper_name(source_p), aconf->user, aconf->host, reason, oper_reason); + } - sendto_one_notice(source_p, ":Added K-Line [%s@%s]", - aconf->user, aconf->host); + sendto_one_notice(source_p, ":Added K-Line [%s@%s]", + aconf->user, aconf->host); } /* apply_tkline() @@ -550,86 +518,80 @@ apply_kline(struct Client *source_p, struct ConfItem *aconf, */ static void apply_tkline(struct Client *source_p, struct ConfItem *aconf, - const char *reason, const char *oper_reason, int tkline_time) + const char *reason, const char *oper_reason, int tkline_time) { - aconf->hold = rb_current_time() + tkline_time; - add_temp_kline(aconf); + aconf->hold = rb_current_time() + tkline_time; + add_temp_kline(aconf); - /* no oper reason.. */ - if(EmptyString(oper_reason)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. K-Line for [%s@%s] [%s]", - get_oper_name(source_p), tkline_time / 60, - aconf->user, aconf->host, reason); - ilog(L_KLINE, "K %s %d %s %s %s", - get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. K-Line for [%s@%s] [%s|%s]", - get_oper_name(source_p), tkline_time / 60, - aconf->user, aconf->host, reason, oper_reason); - ilog(L_KLINE, "K %s %d %s %s %s|%s", - get_oper_name(source_p), tkline_time / 60, - aconf->user, aconf->host, reason, oper_reason); - } + /* no oper reason.. */ + if(EmptyString(oper_reason)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. K-Line for [%s@%s] [%s]", + get_oper_name(source_p), tkline_time / 60, + aconf->user, aconf->host, reason); + ilog(L_KLINE, "K %s %d %s %s %s", + get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. K-Line for [%s@%s] [%s|%s]", + get_oper_name(source_p), tkline_time / 60, + aconf->user, aconf->host, reason, oper_reason); + ilog(L_KLINE, "K %s %d %s %s %s|%s", + get_oper_name(source_p), tkline_time / 60, + aconf->user, aconf->host, reason, oper_reason); + } - sendto_one_notice(source_p, ":Added temporary %d min. K-Line [%s@%s]", - tkline_time / 60, aconf->user, aconf->host); + sendto_one_notice(source_p, ":Added temporary %d min. K-Line [%s@%s]", + tkline_time / 60, aconf->user, aconf->host); } static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, - const char *reason, const char *oper_reason, int tkline_time) + const char *reason, const char *oper_reason, int tkline_time) { - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - aconf->hold = rb_current_time() + tkline_time; - aconf->lifetime = aconf->hold; + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + aconf->hold = rb_current_time() + tkline_time; + aconf->lifetime = aconf->hold; - replace_old_ban(aconf); + replace_old_ban(aconf); - rb_dlinkAddAlloc(aconf, &prop_bans); - add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); + rb_dlinkAddAlloc(aconf, &prop_bans); + add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); - /* no oper reason.. */ - if(EmptyString(oper_reason)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added global %d min. K-Line for [%s@%s] [%s]", - get_oper_name(source_p), tkline_time / 60, - aconf->user, aconf->host, reason); - ilog(L_KLINE, "K %s %d %s %s %s", - get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added global %d min. K-Line for [%s@%s] [%s|%s]", - get_oper_name(source_p), tkline_time / 60, - aconf->user, aconf->host, reason, oper_reason); - ilog(L_KLINE, "K %s %d %s %s %s|%s", - get_oper_name(source_p), tkline_time / 60, - aconf->user, aconf->host, reason, oper_reason); - } + /* no oper reason.. */ + if(EmptyString(oper_reason)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added global %d min. K-Line for [%s@%s] [%s]", + get_oper_name(source_p), tkline_time / 60, + aconf->user, aconf->host, reason); + ilog(L_KLINE, "K %s %d %s %s %s", + get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added global %d min. K-Line for [%s@%s] [%s|%s]", + get_oper_name(source_p), tkline_time / 60, + aconf->user, aconf->host, reason, oper_reason); + ilog(L_KLINE, "K %s %d %s %s %s|%s", + get_oper_name(source_p), tkline_time / 60, + aconf->user, aconf->host, reason, oper_reason); + } - sendto_one_notice(source_p, ":Added global %d min. K-Line [%s@%s]", - tkline_time / 60, aconf->user, aconf->host); + sendto_one_notice(source_p, ":Added global %d min. K-Line [%s@%s]", + tkline_time / 60, aconf->user, aconf->host); - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN K %s %s %lu %d %d * :%s%s%s", - source_p->id, aconf->user, aconf->host, - (unsigned long)aconf->created, - (int)(aconf->hold - aconf->created), - (int)(aconf->lifetime - aconf->created), - reason, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN K %s %s %lu %d %d * :%s%s%s", + source_p->id, aconf->user, aconf->host, + (unsigned long)aconf->created, + (int)(aconf->hold - aconf->created), + (int)(aconf->lifetime - aconf->created), + reason, + oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); } /* find_user_host() - * + * * inputs - client placing kline, user@host, user buffer, host buffer * output - 0 if not ok to kline, 1 to kline i.e. if valid user host * side effects - @@ -637,39 +599,35 @@ apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, static int find_user_host(struct Client *source_p, const char *userhost, char *luser, char *lhost) { - char *hostp; + char *hostp; - hostp = strchr(userhost, '@'); + hostp = strchr(userhost, '@'); - if(hostp != NULL) /* I'm a little user@host */ - { - *(hostp++) = '\0'; /* short and squat */ - if(*userhost) - rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */ - else - strcpy(luser, "*"); - if(*hostp) - rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ - else - strcpy(lhost, "*"); - } - else - { - /* no '@', no '.', so its not a user@host or host, therefore - * its a nick, which support was removed for. - */ - if(strchr(userhost, '.') == NULL && strchr(userhost, ':') == NULL) - { - sendto_one_notice(source_p, ":K-Line must be a user@host or host"); - return 0; - } + if(hostp != NULL) { /* I'm a little user@host */ + *(hostp++) = '\0'; /* short and squat */ + if(*userhost) + rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */ + else + strcpy(luser, "*"); + if(*hostp) + rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ + else + strcpy(lhost, "*"); + } else { + /* no '@', no '.', so its not a user@host or host, therefore + * its a nick, which support was removed for. + */ + if(strchr(userhost, '.') == NULL && strchr(userhost, ':') == NULL) { + sendto_one_notice(source_p, ":K-Line must be a user@host or host"); + return 0; + } - luser[0] = '*'; /* no @ found, assume its *@somehost */ - luser[1] = '\0'; - rb_strlcpy(lhost, userhost, HOSTLEN + 1); - } + luser[0] = '*'; /* no @ found, assume its *@somehost */ + luser[1] = '\0'; + rb_strlcpy(lhost, userhost, HOSTLEN + 1); + } - return 1; + return 1; } /* valid_user_host() @@ -681,14 +639,13 @@ find_user_host(struct Client *source_p, const char *userhost, char *luser, char static int valid_user_host(struct Client *source_p, const char *luser, const char *lhost) { - /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */ - if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@')) - { - sendto_one_notice(source_p, ":Invalid K-Line"); - return 0; - } + /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */ + if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@')) { + sendto_one_notice(source_p, ":Invalid K-Line"); + return 0; + } - return 1; + return 1; } /* @@ -701,16 +658,15 @@ valid_user_host(struct Client *source_p, const char *luser, const char *lhost) static int valid_comment(struct Client *source_p, char *comment) { - if(strchr(comment, '"')) - { - sendto_one_notice(source_p, ":Invalid character '\"' in comment"); - return 0; - } + if(strchr(comment, '"')) { + sendto_one_notice(source_p, ":Invalid character '\"' in comment"); + return 0; + } - if(strlen(comment) > BANREASONLEN) - comment[BANREASONLEN] = '\0'; + if(strlen(comment) > BANREASONLEN) + comment[BANREASONLEN] = '\0'; - return 1; + return 1; } /* already_placed_kline() @@ -727,58 +683,52 @@ valid_comment(struct Client *source_p, char *comment) static int already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int tkline) { - const char *reason, *p; - struct rb_sockaddr_storage iphost, *piphost; - struct ConfItem *aconf; - int t, bits; + const char *reason, *p; + struct rb_sockaddr_storage iphost, *piphost; + struct ConfItem *aconf; + int t, bits; - aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); - if(aconf == NULL && ConfigFileEntry.non_redundant_klines) - { - bits = 0; - if((t = parse_netmask(lhost, (struct sockaddr *) &iphost, &bits)) != HM_HOST) - { + aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); + if(aconf == NULL && ConfigFileEntry.non_redundant_klines) { + bits = 0; + if((t = parse_netmask(lhost, (struct sockaddr *) &iphost, &bits)) != HM_HOST) { #ifdef RB_IPV6 - if(t == HM_IPV6) - t = AF_INET6; - else + if(t == HM_IPV6) + t = AF_INET6; + else #endif - t = AF_INET; + t = AF_INET; - piphost = &iphost; - } - else - piphost = NULL; + piphost = &iphost; + } else + piphost = NULL; - aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost, - CONF_KILL, t, luser, NULL); - if(aconf != NULL) - { - /* The above was really a lookup of a single IP, - * so check if the new kline is wider than the - * existing one. - * -- jilles - */ - p = strchr(aconf->host, '/'); - if(bits > 0 && (p == NULL || bits < atoi(p + 1))) - aconf = NULL; - } - } - if(aconf != NULL) - { - /* setting a tkline, or existing one is perm */ - if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) - { - reason = aconf->passwd ? aconf->passwd : ""; + aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost, + CONF_KILL, t, luser, NULL); + if(aconf != NULL) { + /* The above was really a lookup of a single IP, + * so check if the new kline is wider than the + * existing one. + * -- jilles + */ + p = strchr(aconf->host, '/'); + if(bits > 0 && (p == NULL || bits < atoi(p + 1))) + aconf = NULL; + } + } + if(aconf != NULL) { + /* setting a tkline, or existing one is perm */ + if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) { + reason = aconf->passwd ? aconf->passwd : ""; - sendto_one_notice(source_p, - ":[%s@%s] already K-Lined by [%s@%s] - %s", - luser, lhost, aconf->user, aconf->host, reason); - return 1; - } - } + sendto_one_notice(source_p, + ":[%s@%s] already K-Lined by [%s@%s] - %s", + luser, lhost, aconf->user, aconf->host, reason); + return 1; + } + } - return 0; + return 0; } /* remove_permkline_match() @@ -788,19 +738,19 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho static void remove_permkline_match(struct Client *source_p, struct ConfItem *aconf) { - sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host); + sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the K-Line for: [%s@%s]", - get_oper_name(source_p), aconf->user, aconf->host); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the K-Line for: [%s@%s]", + get_oper_name(source_p), aconf->user, aconf->host); - ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host); + ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host); - remove_reject_mask(aconf->user, aconf->host); - bandb_del(BANDB_KLINE, aconf->user, aconf->host); - delete_one_address_conf(aconf->host, aconf); + remove_reject_mask(aconf->user, aconf->host); + bandb_del(BANDB_KLINE, aconf->user, aconf->host); + delete_one_address_conf(aconf->host, aconf); - return; + return; } /* remove_temp_kline() @@ -812,68 +762,65 @@ remove_permkline_match(struct Client *source_p, struct ConfItem *aconf) static int remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) { - rb_dlink_node *ptr; - int i; + rb_dlink_node *ptr; + int i; - for(i = 0; i < LAST_TEMP_TYPE; i++) - { - RB_DLINK_FOREACH(ptr, temp_klines[i].head) - { - if(aconf == ptr->data) - { - sendto_one_notice(source_p, - ":Un-klined [%s@%s] from temporary k-lines", - aconf->user, aconf->host); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the temporary K-Line for: [%s@%s]", - get_oper_name(source_p), aconf->user, - aconf->host); + for(i = 0; i < LAST_TEMP_TYPE; i++) { + RB_DLINK_FOREACH(ptr, temp_klines[i].head) { + if(aconf == ptr->data) { + sendto_one_notice(source_p, + ":Un-klined [%s@%s] from temporary k-lines", + aconf->user, aconf->host); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the temporary K-Line for: [%s@%s]", + get_oper_name(source_p), aconf->user, + aconf->host); - ilog(L_KLINE, "UK %s %s %s", - get_oper_name(source_p), aconf->user, aconf->host); - rb_dlinkDestroy(ptr, &temp_klines[i]); - remove_reject_mask(aconf->user, aconf->host); - delete_one_address_conf(aconf->host, aconf); - return YES; - } - } - } + ilog(L_KLINE, "UK %s %s %s", + get_oper_name(source_p), aconf->user, aconf->host); + rb_dlinkDestroy(ptr, &temp_klines[i]); + remove_reject_mask(aconf->user, aconf->host); + delete_one_address_conf(aconf->host, aconf); + return YES; + } + } + } - return NO; + return NO; } static void remove_prop_kline(struct Client *source_p, struct ConfItem *aconf) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - ptr = rb_dlinkFind(aconf, &prop_bans); - if (!ptr) - return; - sendto_one_notice(source_p, - ":Un-klined [%s@%s] from global k-lines", - aconf->user, aconf->host); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the global K-Line for: [%s@%s]", - get_oper_name(source_p), aconf->user, - aconf->host); + ptr = rb_dlinkFind(aconf, &prop_bans); + if (!ptr) + return; + sendto_one_notice(source_p, + ":Un-klined [%s@%s] from global k-lines", + aconf->user, aconf->host); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the global K-Line for: [%s@%s]", + get_oper_name(source_p), aconf->user, + aconf->host); - ilog(L_KLINE, "UK %s %s %s", - get_oper_name(source_p), aconf->user, aconf->host); - if(aconf->created < rb_current_time()) - aconf->created = rb_current_time(); - else - aconf->created++; - aconf->hold = aconf->created; - operhash_delete(aconf->info.oper); - aconf->info.oper = operhash_add(get_oper_name(source_p)); - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN K %s %s %lu %d %d * :*", - source_p->id, aconf->user, aconf->host, - (unsigned long)aconf->created, - 0, - (int)(aconf->lifetime - aconf->created)); - remove_reject_mask(aconf->user, aconf->host); - deactivate_conf(aconf, ptr); + ilog(L_KLINE, "UK %s %s %s", + get_oper_name(source_p), aconf->user, aconf->host); + if(aconf->created < rb_current_time()) + aconf->created = rb_current_time(); + else + aconf->created++; + aconf->hold = aconf->created; + operhash_delete(aconf->info.oper); + aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN K %s %s %lu %d %d * :*", + source_p->id, aconf->user, aconf->host, + (unsigned long)aconf->created, + 0, + (int)(aconf->lifetime - aconf->created)); + remove_reject_mask(aconf->user, aconf->host); + deactivate_conf(aconf, ptr); } diff --git a/modules/m_knock.c b/modules/m_knock.c index 67d56fb..3e11e99 100644 --- a/modules/m_knock.c +++ b/modules/m_knock.c @@ -39,8 +39,8 @@ static int m_knock(struct Client *, struct Client *, int, const char **); struct Message knock_msgtab = { - "KNOCK", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_knock, 2}, {m_knock, 2}, mg_ignore, mg_ignore, {m_knock, 2}} + "KNOCK", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_knock, 2}, {m_knock, 2}, mg_ignore, mg_ignore, {m_knock, 2}} }; mapi_clist_av1 knock_clist[] = { &knock_msgtab, NULL }; @@ -62,110 +62,99 @@ DECLARE_MODULE_AV1(knock, NULL, NULL, knock_clist, NULL, NULL, "$Revision: 3570 static int m_knock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; - char *p, *name; + struct Channel *chptr; + char *p, *name; - if(MyClient(source_p) && ConfigChannel.use_knock == 0) - { - sendto_one(source_p, form_str(ERR_KNOCKDISABLED), - me.name, source_p->name); - return 0; - } + if(MyClient(source_p) && ConfigChannel.use_knock == 0) { + sendto_one(source_p, form_str(ERR_KNOCKDISABLED), + me.name, source_p->name); + return 0; + } - name = LOCAL_COPY(parv[1]); + name = LOCAL_COPY(parv[1]); - /* dont allow one knock to multiple chans */ - if((p = strchr(name, ','))) - *p = '\0'; + /* dont allow one knock to multiple chans */ + if((p = strchr(name, ','))) + *p = '\0'; - if(!IsChannelName(name)) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + if(!IsChannelName(name)) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - if((chptr = find_channel(name)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + if((chptr = find_channel(name)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - if(IsMember(source_p, chptr)) - { - if(MyClient(source_p)) - sendto_one(source_p, form_str(ERR_KNOCKONCHAN), - me.name, source_p->name, name); - return 0; - } + if(IsMember(source_p, chptr)) { + if(MyClient(source_p)) + sendto_one(source_p, form_str(ERR_KNOCKONCHAN), + me.name, source_p->name, name); + return 0; + } - if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || - (chptr->mode.limit && - rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit))) - { - sendto_one_numeric(source_p, ERR_CHANOPEN, - form_str(ERR_CHANOPEN), name); - return 0; - } + if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || + (chptr->mode.limit && + rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit))) { + sendto_one_numeric(source_p, ERR_CHANOPEN, + form_str(ERR_CHANOPEN), name); + return 0; + } - /* cant knock to a +p channel */ - if(HiddenChannel(chptr)) - { - sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, - form_str(ERR_CANNOTSENDTOCHAN), name); - return 0; - } + /* cant knock to a +p channel */ + if(HiddenChannel(chptr)) { + sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, + form_str(ERR_CANNOTSENDTOCHAN), name); + return 0; + } - - if(MyClient(source_p)) - { - /* don't allow a knock if the user is banned */ - if(is_banned(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN || - is_quieted(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN) - { - sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, - form_str(ERR_CANNOTSENDTOCHAN), name); - return 0; - } - /* local flood protection: - * allow one knock per user per knock_delay - * allow one knock per channel per knock_delay_channel - */ - if(!IsOper(source_p) && - (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time()) - { - sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), - me.name, source_p->name, name, "user"); - return 0; - } - else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time()) - { - sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), - me.name, source_p->name, name, "channel"); - return 0; - } + if(MyClient(source_p)) { + /* don't allow a knock if the user is banned */ + if(is_banned(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN || + is_quieted(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN) { + sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, + form_str(ERR_CANNOTSENDTOCHAN), name); + return 0; + } - /* ok, we actually can send the knock, tell client */ - source_p->localClient->last_knock = rb_current_time(); + /* local flood protection: + * allow one knock per user per knock_delay + * allow one knock per channel per knock_delay_channel + */ + if(!IsOper(source_p) && + (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time()) { + sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), + me.name, source_p->name, name, "user"); + return 0; + } else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time()) { + sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), + me.name, source_p->name, name, "channel"); + return 0; + } - sendto_one(source_p, form_str(RPL_KNOCKDLVR), - me.name, source_p->name, name); - } + /* ok, we actually can send the knock, tell client */ + source_p->localClient->last_knock = rb_current_time(); - chptr->last_knock = rb_current_time(); + sendto_one(source_p, form_str(RPL_KNOCKDLVR), + me.name, source_p->name, name); + } - if(ConfigChannel.use_knock) - sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, - chptr, form_str(RPL_KNOCK), - me.name, name, name, source_p->name, - source_p->username, source_p->host); + chptr->last_knock = rb_current_time(); - sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, - ":%s KNOCK %s", use_id(source_p), name); - sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, - ":%s KNOCK %s", source_p->name, name); - return 0; + if(ConfigChannel.use_knock) + sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, + chptr, form_str(RPL_KNOCK), + me.name, name, name, source_p->name, + source_p->username, source_p->host); + + sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, + ":%s KNOCK %s", use_id(source_p), name); + sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, + ":%s KNOCK %s", source_p->name, name); + return 0; } diff --git a/modules/m_links.c b/modules/m_links.c index 4998af2..59e0865 100644 --- a/modules/m_links.c +++ b/modules/m_links.c @@ -42,16 +42,16 @@ static int mo_links(struct Client *, struct Client *, int, const char **); static char * clean_string(char *dest, const unsigned char *src, size_t len); struct Message links_msgtab = { - "LINKS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_links, 0}, {mo_links, 0}, mg_ignore, mg_ignore, {mo_links, 0}} + "LINKS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_links, 0}, {mo_links, 0}, mg_ignore, mg_ignore, {mo_links, 0}} }; int doing_links_hook; mapi_clist_av1 links_clist[] = { &links_msgtab, NULL }; mapi_hlist_av1 links_hlist[] = { - { "doing_links", &doing_links_hook }, - { NULL, NULL } + { "doing_links", &doing_links_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision: 254 $"); @@ -60,107 +60,99 @@ DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision * m_links - LINKS message handler * parv[1] = servername mask * or - * parv[1] = server to query + * parv[1] = server to query * parv[2] = servername mask */ static int m_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(ConfigServerHide.flatten_links && !IsExemptShide(source_p)) - scache_send_flattened_links(source_p); - else - mo_links(client_p, source_p, parc, parv); + if(ConfigServerHide.flatten_links && !IsExemptShide(source_p)) + scache_send_flattened_links(source_p); + else + mo_links(client_p, source_p, parc, parv); - return 0; + return 0; } static int mo_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *mask = ""; - struct Client *target_p; - char clean_mask[2 * HOSTLEN + 4]; - hook_data hd; + const char *mask = ""; + struct Client *target_p; + char clean_mask[2 * HOSTLEN + 4]; + hook_data hd; - rb_dlink_node *ptr; + rb_dlink_node *ptr; - if(parc > 2) - { - if(strlen(parv[2]) > HOSTLEN) - return 0; - if(hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv) - != HUNTED_ISME) - return 0; + if(parc > 2) { + if(strlen(parv[2]) > HOSTLEN) + return 0; + if(hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv) + != HUNTED_ISME) + return 0; - mask = parv[2]; - } - else if(parc == 2) - mask = parv[1]; + mask = parv[2]; + } else if(parc == 2) + mask = parv[1]; - if(*mask) /* only necessary if there is a mask */ - mask = collapse(clean_string - (clean_mask, (const unsigned char *) mask, 2 * HOSTLEN)); + if(*mask) /* only necessary if there is a mask */ + mask = collapse(clean_string + (clean_mask, (const unsigned char *) mask, 2 * HOSTLEN)); - hd.client = source_p; - hd.arg1 = mask; - hd.arg2 = NULL; + hd.client = source_p; + hd.arg1 = mask; + hd.arg2 = NULL; - call_hook(doing_links_hook, &hd); + call_hook(doing_links_hook, &hd); - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + target_p = ptr->data; - if(*mask && !match(mask, target_p->name)) - continue; + if(*mask && !match(mask, target_p->name)) + continue; - /* We just send the reply, as if theyre here theres either no SHIDE, - * or theyre an oper.. - */ - sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), - target_p->name, target_p->servptr->name, - target_p->hopcount, - target_p->info[0] ? target_p->info : "(Unknown Location)"); - } + /* We just send the reply, as if theyre here theres either no SHIDE, + * or theyre an oper.. + */ + sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), + target_p->name, target_p->servptr->name, + target_p->hopcount, + target_p->info[0] ? target_p->info : "(Unknown Location)"); + } - sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS), - EmptyString(mask) ? "*" : mask); + sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS), + EmptyString(mask) ? "*" : mask); - return 0; + return 0; } static char * clean_string(char *dest, const unsigned char *src, size_t len) { - char *d = dest; - s_assert(0 != dest); - s_assert(0 != src); + char *d = dest; + s_assert(0 != dest); + s_assert(0 != src); - if(dest == NULL || src == NULL) - return NULL; + if(dest == NULL || src == NULL) + return NULL; - while (*src && (len > 1)) - { - if(*src & 0x80) /* if high bit is set */ - { - *d++ = '.'; - --len; - if(len <= 1) - break; - } - else if(!IsPrint(*src)) /* if NOT printable */ - { - *d++ = '^'; - --len; - if(len <= 1) - break; - *d++ = 0x40 + *src; /* turn it into a printable */ - } - else - *d++ = *src; - ++src; - --len; - } - *d = '\0'; - return dest; + while (*src && (len > 1)) { + if(*src & 0x80) { /* if high bit is set */ + *d++ = '.'; + --len; + if(len <= 1) + break; + } else if(!IsPrint(*src)) { /* if NOT printable */ + *d++ = '^'; + --len; + if(len <= 1) + break; + *d++ = 0x40 + *src; /* turn it into a printable */ + } else + *d++ = *src; + ++src; + --len; + } + *d = '\0'; + return dest; } diff --git a/modules/m_list.c b/modules/m_list.c index db48d8a..c5851db 100644 --- a/modules/m_list.c +++ b/modules/m_list.c @@ -65,15 +65,15 @@ static void safelist_iterate_clients(void *unused); static void safelist_channel_named(struct Client *source_p, const char *name); struct Message list_msgtab = { - "LIST", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_list, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_list, 0}} + "LIST", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_list, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_list, 0}} }; mapi_clist_av1 list_clist[] = { &list_msgtab, NULL }; mapi_hfn_list_av1 list_hfnlist[] = { - {"client_exit", (hookfn) safelist_check_cliexit}, - {NULL, NULL} + {"client_exit", (hookfn) safelist_check_cliexit}, + {NULL, NULL} }; DECLARE_MODULE_AV1(list, _modinit, _moddeinit, list_clist, NULL, list_hfnlist, "$Revision: 3372 $"); @@ -82,39 +82,38 @@ static struct ev_entry *iterate_clients_ev = NULL; static int _modinit(void) { - iterate_clients_ev = rb_event_add("safelist_iterate_clients", safelist_iterate_clients, NULL, 3); + iterate_clients_ev = rb_event_add("safelist_iterate_clients", safelist_iterate_clients, NULL, 3); - /* ELIST=[tokens]: - * - * M = mask search - * N = !mask search - * U = user count search (< >) - * C = creation time search (C> C<) - * T = topic search (T> T<) - */ - add_isupport("SAFELIST", isupport_string, ""); - add_isupport("ELIST", isupport_string, "CTU"); + /* ELIST=[tokens]: + * + * M = mask search + * N = !mask search + * U = user count search (< >) + * C = creation time search (C> C<) + * T = topic search (T> T<) + */ + add_isupport("SAFELIST", isupport_string, ""); + add_isupport("ELIST", isupport_string, "CTU"); - return 0; + return 0; } static void _moddeinit(void) { - rb_event_delete(iterate_clients_ev); + rb_event_delete(iterate_clients_ev); - delete_isupport("SAFELIST"); - delete_isupport("ELIST"); + delete_isupport("SAFELIST"); + delete_isupport("ELIST"); } static void safelist_check_cliexit(hook_data_client_exit * hdata) { - /* Cancel the safelist request if we are disconnecting - * from the server. That way it doesn't core. :P --nenolod - */ - if (MyClient(hdata->target) && hdata->target->localClient->safelist_data != NULL) - { - safelist_client_release(hdata->target); - } + /* Cancel the safelist request if we are disconnecting + * from the server. That way it doesn't core. :P --nenolod + */ + if (MyClient(hdata->target) && hdata->target->localClient->safelist_data != NULL) { + safelist_client_release(hdata->target); + } } /* m_list() @@ -125,29 +124,25 @@ static void safelist_check_cliexit(hook_data_client_exit * hdata) */ static int m_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0L; + static time_t last_used = 0L; - if (source_p->localClient->safelist_data != NULL) - { - sendto_one_notice(source_p, ":/LIST aborted"); - safelist_client_release(source_p); - return 0; - } + if (source_p->localClient->safelist_data != NULL) { + sendto_one_notice(source_p, ":/LIST aborted"); + safelist_client_release(source_p); + return 0; + } - if (parc < 2 || !IsChannelName(parv[1])) - { - /* pace this due to the sheer traffic involved */ - if (((last_used + ConfigFileEntry.pace_wait) > rb_current_time())) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "LIST"); - sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); - return 0; - } - else - last_used = rb_current_time(); - } + if (parc < 2 || !IsChannelName(parv[1])) { + /* pace this due to the sheer traffic involved */ + if (((last_used + ConfigFileEntry.pace_wait) > rb_current_time())) { + sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "LIST"); + sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); + return 0; + } else + last_used = rb_current_time(); + } - return mo_list(client_p, source_p, parc, parv); + return mo_list(client_p, source_p, parc, parv); } /* mo_list() @@ -155,127 +150,104 @@ static int m_list(struct Client *client_p, struct Client *source_p, int parc, co */ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct ListClient *params; - char *p, *args; - int i; + struct ListClient *params; + char *p, *args; + int i; - if (source_p->localClient->safelist_data != NULL) - { - sendto_one_notice(source_p, ":/LIST aborted"); - safelist_client_release(source_p); - return 0; - } + if (source_p->localClient->safelist_data != NULL) { + sendto_one_notice(source_p, ":/LIST aborted"); + safelist_client_release(source_p); + return 0; + } - /* Single channel. */ - if (parc > 1 && IsChannelName(parv[1])) - { - safelist_channel_named(source_p, parv[1]); - return 0; - } + /* Single channel. */ + if (parc > 1 && IsChannelName(parv[1])) { + safelist_channel_named(source_p, parv[1]); + return 0; + } - /* Multiple channels, possibly with parameters. */ - params = rb_malloc(sizeof(struct ListClient)); + /* Multiple channels, possibly with parameters. */ + params = rb_malloc(sizeof(struct ListClient)); - /* Let the user set it */ - params->users_min = ConfigFileEntry.hide_channel_below_users; - params->users_max = INT_MAX; - params->operspy = 0; - params->created_min = params->topic_min = - params->created_max = params->topic_max = 0; + /* Let the user set it */ + params->users_min = ConfigFileEntry.hide_channel_below_users; + params->users_max = INT_MAX; + params->operspy = 0; + params->created_min = params->topic_min = + params->created_max = params->topic_max = 0; - if (parc > 1 && !EmptyString(parv[1])) - { - args = LOCAL_COPY(parv[1]); + if (parc > 1 && !EmptyString(parv[1])) { + args = LOCAL_COPY(parv[1]); - /* Cancel out default minimum. */ - params->users_min = 0; + /* Cancel out default minimum. */ + params->users_min = 0; - for (i = 0; i < 7; i++) - { - if ((p = strchr(args, ',')) != NULL) - *p++ = '\0'; + for (i = 0; i < 7; i++) { + if ((p = strchr(args, ',')) != NULL) + *p++ = '\0'; - if (*args == '<') - { - args++; - if (IsDigit(*args)) - { - params->users_max = atoi(args); - if (params->users_max == 0) - params->users_max = INT_MAX; - else - params->users_max--; - } - } - else if (*args == '>') - { - args++; - if (IsDigit(*args)) - params->users_min = atoi(args) + 1; - else - params->users_min = 0; - } - else if (*args == 'C' || *args == 'c') - { - args++; - if (*args == '>') - { - /* Creation time earlier than last x minutes. */ - args++; - if (IsDigit(*args)) - { - params->created_max = rb_current_time() - (60 * atoi(args)); - } - } - else if (*args == '<') - { - /* Creation time within last x minutes. */ - args++; - if (IsDigit(*args)) - { - params->created_min = rb_current_time() - (60 * atoi(args)); - } - } - } - else if (*args == 'T' || *args == 't') - { - args++; - if (*args == '>') - { - /* Topic change time earlier than last x minutes. */ - args++; - if (IsDigit(*args)) - { - params->topic_max = rb_current_time() - (60 * atoi(args)); - } - } - else if (*args == '<') - { - /* Topic change time within last x minutes. */ - args++; - if (IsDigit(*args)) - { - params->topic_min = rb_current_time() - (60 * atoi(args)); - } - } - } - /* Only accept operspy as the first option. */ - else if (*args == '!' && IsOperSpy(source_p) && i == 0) - { - params->operspy = 1; - report_operspy(source_p, "LIST", p); - } + if (*args == '<') { + args++; + if (IsDigit(*args)) { + params->users_max = atoi(args); + if (params->users_max == 0) + params->users_max = INT_MAX; + else + params->users_max--; + } + } else if (*args == '>') { + args++; + if (IsDigit(*args)) + params->users_min = atoi(args) + 1; + else + params->users_min = 0; + } else if (*args == 'C' || *args == 'c') { + args++; + if (*args == '>') { + /* Creation time earlier than last x minutes. */ + args++; + if (IsDigit(*args)) { + params->created_max = rb_current_time() - (60 * atoi(args)); + } + } else if (*args == '<') { + /* Creation time within last x minutes. */ + args++; + if (IsDigit(*args)) { + params->created_min = rb_current_time() - (60 * atoi(args)); + } + } + } else if (*args == 'T' || *args == 't') { + args++; + if (*args == '>') { + /* Topic change time earlier than last x minutes. */ + args++; + if (IsDigit(*args)) { + params->topic_max = rb_current_time() - (60 * atoi(args)); + } + } else if (*args == '<') { + /* Topic change time within last x minutes. */ + args++; + if (IsDigit(*args)) { + params->topic_min = rb_current_time() - (60 * atoi(args)); + } + } + } + /* Only accept operspy as the first option. */ + else if (*args == '!' && IsOperSpy(source_p) && i == 0) { + params->operspy = 1; + report_operspy(source_p, "LIST", p); + } - if (EmptyString(p)) - break; - else - args = p; - } - } + if (EmptyString(p)) + break; + else + args = p; + } + } - safelist_client_instantiate(source_p, params); + safelist_client_instantiate(source_p, params); - return 0; + return 0; } /* @@ -291,10 +263,10 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c */ static int safelist_sendq_exceeded(struct Client *client_p) { - if (rb_linebuf_len(&client_p->localClient->buf_sendq) > (get_sendq(client_p) / 2)) - return YES; - else - return NO; + if (rb_linebuf_len(&client_p->localClient->buf_sendq) > (get_sendq(client_p) / 2)) + return YES; + else + return NO; } /* @@ -311,18 +283,18 @@ static int safelist_sendq_exceeded(struct Client *client_p) */ static void safelist_client_instantiate(struct Client *client_p, struct ListClient *params) { - s_assert(MyClient(client_p)); - s_assert(params != NULL); + s_assert(MyClient(client_p)); + s_assert(params != NULL); - client_p->localClient->safelist_data = params; + client_p->localClient->safelist_data = params; - sendto_one(client_p, form_str(RPL_LISTSTART), me.name, client_p->name); + sendto_one(client_p, form_str(RPL_LISTSTART), me.name, client_p->name); - /* pop the client onto the queue for processing */ - rb_dlinkAddAlloc(client_p, &safelisting_clients); + /* pop the client onto the queue for processing */ + rb_dlinkAddAlloc(client_p, &safelisting_clients); - /* give the user some initial data to work with */ - safelist_iterate_client(client_p); + /* give the user some initial data to work with */ + safelist_iterate_client(client_p); } /* @@ -338,15 +310,15 @@ static void safelist_client_instantiate(struct Client *client_p, struct ListClie */ static void safelist_client_release(struct Client *client_p) { - s_assert(MyClient(client_p)); + s_assert(MyClient(client_p)); - rb_dlinkFindDestroy(client_p, &safelisting_clients); + rb_dlinkFindDestroy(client_p, &safelisting_clients); - rb_free(client_p->localClient->safelist_data); + rb_free(client_p->localClient->safelist_data); - client_p->localClient->safelist_data = NULL; + client_p->localClient->safelist_data = NULL; - sendto_one(client_p, form_str(RPL_LISTEND), me.name, client_p->name); + sendto_one(client_p, form_str(RPL_LISTEND), me.name, client_p->name); } /* @@ -358,38 +330,36 @@ static void safelist_client_release(struct Client *client_p) */ static void safelist_channel_named(struct Client *source_p, const char *name) { - struct Channel *chptr; - char *p; - char *n = LOCAL_COPY(name); + struct Channel *chptr; + char *p; + char *n = LOCAL_COPY(name); - sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); + sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); - if ((p = strchr(n, ','))) - *p = '\0'; + if ((p = strchr(n, ','))) + *p = '\0'; - if (*n == '\0') - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name); - sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); - return; - } + if (*n == '\0') { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name); + sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); + return; + } - chptr = find_channel(n); + chptr = find_channel(n); - if (chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), n); - sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); - return; - } + if (chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), n); + sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); + return; + } - if (!SecretChannel(chptr) || IsMember(source_p, chptr)) - sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, "", - chptr->chname, rb_dlink_list_length(&chptr->members), - chptr->topic == NULL ? "" : chptr->topic); + if (!SecretChannel(chptr) || IsMember(source_p, chptr)) + sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, "", + chptr->chname, rb_dlink_list_length(&chptr->members), + chptr->topic == NULL ? "" : chptr->topic); - sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); - return; + sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); + return; } /* @@ -402,33 +372,33 @@ static void safelist_channel_named(struct Client *source_p, const char *name) */ static void safelist_one_channel(struct Client *source_p, struct Channel *chptr) { - struct ListClient *safelist_data = source_p->localClient->safelist_data; + struct ListClient *safelist_data = source_p->localClient->safelist_data; - if (SecretChannel(chptr) && !IsMember(source_p, chptr) && !safelist_data->operspy) - return; + if (SecretChannel(chptr) && !IsMember(source_p, chptr) && !safelist_data->operspy) + return; - if ((unsigned int)chptr->members.length < safelist_data->users_min - || (unsigned int)chptr->members.length > safelist_data->users_max) - return; + if ((unsigned int)chptr->members.length < safelist_data->users_min + || (unsigned int)chptr->members.length > safelist_data->users_max) + return; - if (safelist_data->topic_min && chptr->topic_time < safelist_data->topic_min) - return; + if (safelist_data->topic_min && chptr->topic_time < safelist_data->topic_min) + return; - /* If a topic TS is provided, don't show channels without a topic set. */ - if (safelist_data->topic_max && (chptr->topic_time > safelist_data->topic_max - || chptr->topic_time == 0)) - return; + /* If a topic TS is provided, don't show channels without a topic set. */ + if (safelist_data->topic_max && (chptr->topic_time > safelist_data->topic_max + || chptr->topic_time == 0)) + return; - if (safelist_data->created_min && chptr->channelts < safelist_data->created_min) - return; + if (safelist_data->created_min && chptr->channelts < safelist_data->created_min) + return; - if (safelist_data->created_max && chptr->channelts > safelist_data->created_max) - return; + if (safelist_data->created_max && chptr->channelts > safelist_data->created_max) + return; - sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, - (safelist_data->operspy && SecretChannel(chptr)) ? "!" : "", - chptr->chname, rb_dlink_list_length(&chptr->members), - chptr->topic == NULL ? "" : chptr->topic); + sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, + (safelist_data->operspy && SecretChannel(chptr)) ? "!" : "", + chptr->chname, rb_dlink_list_length(&chptr->members), + chptr->topic == NULL ? "" : chptr->topic); } /* @@ -440,28 +410,26 @@ static void safelist_one_channel(struct Client *source_p, struct Channel *chptr) */ static void safelist_iterate_client(struct Client *source_p) { - rb_dlink_node *ptr; - int iter; + rb_dlink_node *ptr; + int iter; - for (iter = source_p->localClient->safelist_data->hash_indice; iter < CH_MAX; iter++) - { - if (safelist_sendq_exceeded(source_p->from) == YES) - { - source_p->localClient->safelist_data->hash_indice = iter; - return; - } + for (iter = source_p->localClient->safelist_data->hash_indice; iter < CH_MAX; iter++) { + if (safelist_sendq_exceeded(source_p->from) == YES) { + source_p->localClient->safelist_data->hash_indice = iter; + return; + } - RB_DLINK_FOREACH(ptr, channelTable[iter].head) - safelist_one_channel(source_p, (struct Channel *) ptr->data); - } + RB_DLINK_FOREACH(ptr, channelTable[iter].head) + safelist_one_channel(source_p, (struct Channel *) ptr->data); + } - safelist_client_release(source_p); + safelist_client_release(source_p); } static void safelist_iterate_clients(void *unused) { - rb_dlink_node *n, *n2; + rb_dlink_node *n, *n2; - RB_DLINK_FOREACH_SAFE(n, n2, safelisting_clients.head) - safelist_iterate_client((struct Client *)n->data); + RB_DLINK_FOREACH_SAFE(n, n2, safelisting_clients.head) + safelist_iterate_client((struct Client *)n->data); } diff --git a/modules/m_locops.c b/modules/m_locops.c index f774ed8..64d0163 100644 --- a/modules/m_locops.c +++ b/modules/m_locops.c @@ -43,8 +43,8 @@ static int ms_locops(struct Client *, struct Client *, int, const char **); static int me_locops(struct Client *, struct Client *, int, const char **); struct Message locops_msgtab = { - "LOCOPS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_locops, 3}, mg_ignore, {me_locops, 2}, {m_locops, 2}} + "LOCOPS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_locops, 3}, mg_ignore, {me_locops, 2}, {m_locops, 2}} }; mapi_clist_av1 locops_clist[] = { &locops_msgtab, NULL }; @@ -58,43 +58,43 @@ DECLARE_MODULE_AV1(locops, NULL, NULL, locops_clist, NULL, NULL, "$Revision: 254 static int m_locops(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - sendto_wallops_flags(UMODE_LOCOPS, source_p, "LOCOPS - %s", parv[1]); - - if(rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_generic(source_p, "LOCOPS", SHARED_LOCOPS, CAP_CLUSTER, - ":%s", parv[1]); + sendto_wallops_flags(UMODE_LOCOPS, source_p, "LOCOPS - %s", parv[1]); - return 0; + if(rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_generic(source_p, "LOCOPS", SHARED_LOCOPS, CAP_CLUSTER, + ":%s", parv[1]); + + return 0; } static int ms_locops(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* source_p parv[1] parv[2] - * oper target serv message - */ - propagate_generic(source_p, "LOCOPS", parv[1], CAP_CLUSTER, - ":%s", parv[2]); + /* source_p parv[1] parv[2] + * oper target serv message + */ + propagate_generic(source_p, "LOCOPS", parv[1], CAP_CLUSTER, + ":%s", parv[2]); - if(!match(parv[1], me.name)) - return 0; + if(!match(parv[1], me.name)) + return 0; - if(find_shared_conf("*", "*", source_p->servptr->name, SHARED_LOCOPS)) - sendto_wallops_flags(UMODE_LOCOPS, source_p, "SLOCOPS - %s", parv[2]); + if(find_shared_conf("*", "*", source_p->servptr->name, SHARED_LOCOPS)) + sendto_wallops_flags(UMODE_LOCOPS, source_p, "SLOCOPS - %s", parv[2]); - return 0; + return 0; } static int me_locops(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - if(find_shared_conf("*", "*", source_p->servptr->name, SHARED_LOCOPS)) - sendto_wallops_flags(UMODE_LOCOPS, source_p, "SLOCOPS - %s", parv[1]); + if(find_shared_conf("*", "*", source_p->servptr->name, SHARED_LOCOPS)) + sendto_wallops_flags(UMODE_LOCOPS, source_p, "SLOCOPS - %s", parv[1]); - return 0; + return 0; } diff --git a/modules/m_lusers.c b/modules/m_lusers.c index 8e963df..81e5203 100644 --- a/modules/m_lusers.c +++ b/modules/m_lusers.c @@ -39,8 +39,8 @@ static int m_lusers(struct Client *, struct Client *, int, const char **); static int ms_lusers(struct Client *, struct Client *, int, const char **); struct Message lusers_msgtab = { - "LUSERS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_lusers, 0}, {ms_lusers, 0}, mg_ignore, mg_ignore, {ms_lusers, 0}} + "LUSERS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_lusers, 0}, {ms_lusers, 0}, mg_ignore, mg_ignore, {ms_lusers, 0}} }; mapi_clist_av1 lusers_clist[] = { &lusers_msgtab, NULL }; @@ -50,56 +50,52 @@ DECLARE_MODULE_AV1(lusers, NULL, NULL, lusers_clist, NULL, NULL, "$Revision: 254 * m_lusers - LUSERS message handler * parv[1] = host/server mask. * parv[2] = server to query - * + * * 199970918 JRL hacked to ignore parv[1] completely and require parc > 3 * to cause a force */ static int m_lusers(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; + static time_t last_used = 0; - if (parc > 2) - { - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "LUSERS"); - return 0; - } - else - last_used = rb_current_time(); + if (parc > 2) { + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + /* safe enough to give this on a local connect only */ + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "LUSERS"); + return 0; + } else + last_used = rb_current_time(); - if(hunt_server(client_p, source_p, ":%s LUSERS %s :%s", 2, parc, parv) != - HUNTED_ISME) - return 0; - } + if(hunt_server(client_p, source_p, ":%s LUSERS %s :%s", 2, parc, parv) != + HUNTED_ISME) + return 0; + } - show_lusers(source_p); + show_lusers(source_p); - return 0; + return 0; } /* * ms_lusers - LUSERS message handler for servers and opers * parv[1] = host/server mask. * parv[2] = server to query - * + * * 199970918 JRL hacked to ignore parv[1] completely and require parc > 3 * to cause a force */ static int ms_lusers(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc > 2) - { - if(hunt_server(client_p, source_p, ":%s LUSERS %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } + if(parc > 2) { + if(hunt_server(client_p, source_p, ":%s LUSERS %s :%s", 2, parc, parv) + != HUNTED_ISME) + return 0; + } - show_lusers(source_p); + show_lusers(source_p); - return 0; + return 0; } diff --git a/modules/m_map.c b/modules/m_map.c index 7a45140..f3766dd 100644 --- a/modules/m_map.c +++ b/modules/m_map.c @@ -35,8 +35,8 @@ static int m_map(struct Client *client_p, struct Client *source_p, int parc, con static int mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message map_msgtab = { - "MAP", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}} + "MAP", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}} }; mapi_clist_av1 map_clist[] = { &map_msgtab, NULL }; @@ -51,16 +51,15 @@ static char buf[BUFSIZE]; static int m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) || - ConfigFileEntry.map_oper_only) - { - m_not_oper(client_p, source_p, parc, parv); - return 0; - } + if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) || + ConfigFileEntry.map_oper_only) { + m_not_oper(client_p, source_p, parc, parv); + return 0; + } - dump_map(client_p, &me, buf); - sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND)); - return 0; + dump_map(client_p, &me, buf); + sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND)); + return 0; } /* @@ -69,11 +68,11 @@ m_map(struct Client *client_p, struct Client *source_p, int parc, const char *pa static int mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - dump_map(client_p, &me, buf); - scache_send_missing(client_p); - sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND)); + dump_map(client_p, &me, buf); + scache_send_missing(client_p); + sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND)); - return 0; + return 0; } /* @@ -83,64 +82,57 @@ mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *p static void dump_map(struct Client *client_p, struct Client *root_p, char *pbuf) { - int cnt = 0, i = 0, len, frac; - struct Client *server_p; - rb_dlink_node *ptr; - *pbuf = '\0'; + int cnt = 0, i = 0, len, frac; + struct Client *server_p; + rb_dlink_node *ptr; + *pbuf = '\0'; - rb_strlcat(pbuf, root_p->name, BUFSIZE); - if (has_id(root_p)) - { - rb_strlcat(pbuf, "[", BUFSIZE); - rb_strlcat(pbuf, root_p->id, BUFSIZE); - rb_strlcat(pbuf, "]", BUFSIZE); - } - len = strlen(buf); - buf[len] = ' '; + rb_strlcat(pbuf, root_p->name, BUFSIZE); + if (has_id(root_p)) { + rb_strlcat(pbuf, "[", BUFSIZE); + rb_strlcat(pbuf, root_p->id, BUFSIZE); + rb_strlcat(pbuf, "]", BUFSIZE); + } + len = strlen(buf); + buf[len] = ' '; - if(len < USER_COL) - { - for (i = len + 1; i < USER_COL; i++) - { - buf[i] = '-'; - } - } + if(len < USER_COL) { + for (i = len + 1; i < USER_COL; i++) { + buf[i] = '-'; + } + } - frac = (1000 * rb_dlink_list_length(&root_p->serv->users) + Count.total / 2) / Count.total; - rb_snprintf(buf + USER_COL, BUFSIZE - USER_COL, - " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p->serv->users), - frac / 10, frac % 10); + frac = (1000 * rb_dlink_list_length(&root_p->serv->users) + Count.total / 2) / Count.total; + rb_snprintf(buf + USER_COL, BUFSIZE - USER_COL, + " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p->serv->users), + frac / 10, frac % 10); - sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf); + sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf); - if(root_p->serv->servers.head != NULL) - { - cnt += rb_dlink_list_length(&root_p->serv->servers); + if(root_p->serv->servers.head != NULL) { + cnt += rb_dlink_list_length(&root_p->serv->servers); - if(cnt) - { - if(pbuf > buf + 3) - { - pbuf[-2] = ' '; - if(pbuf[-3] == '`') - pbuf[-3] = ' '; - } - } - } - i = 1; - RB_DLINK_FOREACH(ptr, root_p->serv->servers.head) - { - server_p = ptr->data; - *pbuf = ' '; - if(i < cnt) - *(pbuf + 1) = '|'; - else - *(pbuf + 1) = '`'; + if(cnt) { + if(pbuf > buf + 3) { + pbuf[-2] = ' '; + if(pbuf[-3] == '`') + pbuf[-3] = ' '; + } + } + } + i = 1; + RB_DLINK_FOREACH(ptr, root_p->serv->servers.head) { + server_p = ptr->data; + *pbuf = ' '; + if(i < cnt) + *(pbuf + 1) = '|'; + else + *(pbuf + 1) = '`'; - *(pbuf + 2) = '-'; - *(pbuf + 3) = ' '; - dump_map(client_p, server_p, pbuf + 4); + *(pbuf + 2) = '-'; + *(pbuf + 3) = ' '; + dump_map(client_p, server_p, pbuf + 4); - i++; - } + i++; + } } diff --git a/modules/m_monitor.c b/modules/m_monitor.c index 429f9e2..03774ad 100644 --- a/modules/m_monitor.c +++ b/modules/m_monitor.c @@ -1,5 +1,5 @@ /* modules/m_monitor.c - * + * * Copyright (C) 2005 Lee Hardy * Copyright (C) 2005 ircd-ratbox development team * @@ -41,8 +41,8 @@ static int m_monitor(struct Client *, struct Client *, int, const char **); struct Message monitor_msgtab = { - "MONITOR", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_monitor, 2}, mg_ignore, mg_ignore, mg_ignore, {m_monitor, 2}} + "MONITOR", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_monitor, 2}, mg_ignore, mg_ignore, mg_ignore, {m_monitor, 2}} }; mapi_clist_av1 monitor_clist[] = { &monitor_msgtab, NULL }; @@ -51,302 +51,277 @@ DECLARE_MODULE_AV1(monitor, NULL, NULL, monitor_clist, NULL, NULL, "$Revision: 3 static void add_monitor(struct Client *client_p, const char *nicks) { - char onbuf[BUFSIZE], offbuf[BUFSIZE]; - struct Client *target_p; - struct monitor *monptr; - const char *name; - char *tmp; - char *p; - char *onptr, *offptr; - int mlen, arglen; - int cur_onlen, cur_offlen; + char onbuf[BUFSIZE], offbuf[BUFSIZE]; + struct Client *target_p; + struct monitor *monptr; + const char *name; + char *tmp; + char *p; + char *onptr, *offptr; + int mlen, arglen; + int cur_onlen, cur_offlen; - /* these two are same length, just diff numeric */ - cur_offlen = cur_onlen = mlen = sprintf(onbuf, form_str(RPL_MONONLINE), - me.name, client_p->name, ""); - sprintf(offbuf, form_str(RPL_MONOFFLINE), - me.name, client_p->name, ""); + /* these two are same length, just diff numeric */ + cur_offlen = cur_onlen = mlen = sprintf(onbuf, form_str(RPL_MONONLINE), + me.name, client_p->name, ""); + sprintf(offbuf, form_str(RPL_MONOFFLINE), + me.name, client_p->name, ""); - onptr = onbuf + mlen; - offptr = offbuf + mlen; + onptr = onbuf + mlen; + offptr = offbuf + mlen; - tmp = LOCAL_COPY(nicks); + tmp = LOCAL_COPY(nicks); - for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) - { - if(EmptyString(name) || strlen(name) > NICKLEN-1) - continue; + for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { + if(EmptyString(name) || strlen(name) > NICKLEN-1) + continue; - if(rb_dlink_list_length(&client_p->localClient->monitor_list) >= - ConfigFileEntry.max_monitor) - { - char buf[100]; + if(rb_dlink_list_length(&client_p->localClient->monitor_list) >= + ConfigFileEntry.max_monitor) { + char buf[100]; - if(cur_onlen != mlen) - sendto_one(client_p, "%s", onbuf); - if(cur_offlen != mlen) - sendto_one(client_p, "%s", offbuf); + if(cur_onlen != mlen) + sendto_one(client_p, "%s", onbuf); + if(cur_offlen != mlen) + sendto_one(client_p, "%s", offbuf); - if(p) - rb_snprintf(buf, sizeof(buf), "%s,%s", name, p); - else - rb_snprintf(buf, sizeof(buf), "%s", name); + if(p) + rb_snprintf(buf, sizeof(buf), "%s,%s", name, p); + else + rb_snprintf(buf, sizeof(buf), "%s", name); - sendto_one(client_p, form_str(ERR_MONLISTFULL), - me.name, client_p->name, - ConfigFileEntry.max_monitor, buf); - return; - } + sendto_one(client_p, form_str(ERR_MONLISTFULL), + me.name, client_p->name, + ConfigFileEntry.max_monitor, buf); + return; + } - monptr = find_monitor(name, 1); + monptr = find_monitor(name, 1); - /* already monitoring this nick */ - if(rb_dlinkFind(client_p, &monptr->users)) - continue; + /* already monitoring this nick */ + if(rb_dlinkFind(client_p, &monptr->users)) + continue; - rb_dlinkAddAlloc(client_p, &monptr->users); - rb_dlinkAddAlloc(monptr, &client_p->localClient->monitor_list); + rb_dlinkAddAlloc(client_p, &monptr->users); + rb_dlinkAddAlloc(monptr, &client_p->localClient->monitor_list); - if((target_p = find_named_person(name)) != NULL) - { - if(cur_onlen + strlen(target_p->name) + - strlen(target_p->username) + strlen(target_p->host) + 3 >= BUFSIZE-3) - { - sendto_one(client_p, "%s", onbuf); - cur_onlen = mlen; - onptr = onbuf + mlen; - } + if((target_p = find_named_person(name)) != NULL) { + if(cur_onlen + strlen(target_p->name) + + strlen(target_p->username) + strlen(target_p->host) + 3 >= BUFSIZE-3) { + sendto_one(client_p, "%s", onbuf); + cur_onlen = mlen; + onptr = onbuf + mlen; + } - if(cur_onlen != mlen) - { - *onptr++ = ','; - cur_onlen++; - } + if(cur_onlen != mlen) { + *onptr++ = ','; + cur_onlen++; + } - arglen = sprintf(onptr, "%s!%s@%s", - target_p->name, target_p->username, - target_p->host); - onptr += arglen; - cur_onlen += arglen; - } - else - { - if(cur_offlen + strlen(name) + 1 >= BUFSIZE-3) - { - sendto_one(client_p, "%s", offbuf); - cur_offlen = mlen; - offptr = offbuf + mlen; - } + arglen = sprintf(onptr, "%s!%s@%s", + target_p->name, target_p->username, + target_p->host); + onptr += arglen; + cur_onlen += arglen; + } else { + if(cur_offlen + strlen(name) + 1 >= BUFSIZE-3) { + sendto_one(client_p, "%s", offbuf); + cur_offlen = mlen; + offptr = offbuf + mlen; + } - if(cur_offlen != mlen) - { - *offptr++ = ','; - cur_offlen++; - } + if(cur_offlen != mlen) { + *offptr++ = ','; + cur_offlen++; + } - arglen = sprintf(offptr, "%s", name); - offptr += arglen; - cur_offlen += arglen; - } - } + arglen = sprintf(offptr, "%s", name); + offptr += arglen; + cur_offlen += arglen; + } + } - if(cur_onlen != mlen) - sendto_one(client_p, "%s", onbuf); - if(cur_offlen != mlen) - sendto_one(client_p, "%s", offbuf); + if(cur_onlen != mlen) + sendto_one(client_p, "%s", onbuf); + if(cur_offlen != mlen) + sendto_one(client_p, "%s", offbuf); } static void del_monitor(struct Client *client_p, const char *nicks) { - struct monitor *monptr; - const char *name; - char *tmp; - char *p; + struct monitor *monptr; + const char *name; + char *tmp; + char *p; - if(!rb_dlink_list_length(&client_p->localClient->monitor_list)) - return; + if(!rb_dlink_list_length(&client_p->localClient->monitor_list)) + return; - tmp = LOCAL_COPY(nicks); + tmp = LOCAL_COPY(nicks); - for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) - { - if(EmptyString(name)) - continue; + for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { + if(EmptyString(name)) + continue; - /* not monitored */ - if((monptr = find_monitor(name, 0)) == NULL) - continue; + /* not monitored */ + if((monptr = find_monitor(name, 0)) == NULL) + continue; - rb_dlinkFindDestroy(client_p, &monptr->users); - rb_dlinkFindDestroy(monptr, &client_p->localClient->monitor_list); - } + rb_dlinkFindDestroy(client_p, &monptr->users); + rb_dlinkFindDestroy(monptr, &client_p->localClient->monitor_list); + } } static void list_monitor(struct Client *client_p) { - char buf[BUFSIZE]; - struct monitor *monptr; - char *nbuf; - rb_dlink_node *ptr; - int mlen, arglen, cur_len; + char buf[BUFSIZE]; + struct monitor *monptr; + char *nbuf; + rb_dlink_node *ptr; + int mlen, arglen, cur_len; - if(!rb_dlink_list_length(&client_p->localClient->monitor_list)) - { - sendto_one(client_p, form_str(RPL_ENDOFMONLIST), - me.name, client_p->name); - return; - } + if(!rb_dlink_list_length(&client_p->localClient->monitor_list)) { + sendto_one(client_p, form_str(RPL_ENDOFMONLIST), + me.name, client_p->name); + return; + } - cur_len = mlen = sprintf(buf, form_str(RPL_MONLIST), - me.name, client_p->name, ""); - nbuf = buf + mlen; + cur_len = mlen = sprintf(buf, form_str(RPL_MONLIST), + me.name, client_p->name, ""); + nbuf = buf + mlen; - RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) - { - monptr = ptr->data; + RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) { + monptr = ptr->data; - if(cur_len + strlen(monptr->name) + 1 >= BUFSIZE-3) - { - sendto_one(client_p, "%s", buf); - nbuf = buf + mlen; - cur_len = mlen; - } + if(cur_len + strlen(monptr->name) + 1 >= BUFSIZE-3) { + sendto_one(client_p, "%s", buf); + nbuf = buf + mlen; + cur_len = mlen; + } - if(cur_len != mlen) - { - *nbuf++ = ','; - cur_len++; - } + if(cur_len != mlen) { + *nbuf++ = ','; + cur_len++; + } - arglen = sprintf(nbuf, "%s", monptr->name); - cur_len += arglen; - nbuf += arglen; - } + arglen = sprintf(nbuf, "%s", monptr->name); + cur_len += arglen; + nbuf += arglen; + } - sendto_one(client_p, "%s", buf); - sendto_one(client_p, form_str(RPL_ENDOFMONLIST), - me.name, client_p->name); + sendto_one(client_p, "%s", buf); + sendto_one(client_p, form_str(RPL_ENDOFMONLIST), + me.name, client_p->name); } static void show_monitor_status(struct Client *client_p) { - char onbuf[BUFSIZE], offbuf[BUFSIZE]; - struct Client *target_p; - struct monitor *monptr; - char *onptr, *offptr; - int cur_onlen, cur_offlen; - int mlen, arglen; - rb_dlink_node *ptr; + char onbuf[BUFSIZE], offbuf[BUFSIZE]; + struct Client *target_p; + struct monitor *monptr; + char *onptr, *offptr; + int cur_onlen, cur_offlen; + int mlen, arglen; + rb_dlink_node *ptr; - mlen = cur_onlen = sprintf(onbuf, form_str(RPL_MONONLINE), - me.name, client_p->name, ""); - cur_offlen = sprintf(offbuf, form_str(RPL_MONOFFLINE), - me.name, client_p->name, ""); + mlen = cur_onlen = sprintf(onbuf, form_str(RPL_MONONLINE), + me.name, client_p->name, ""); + cur_offlen = sprintf(offbuf, form_str(RPL_MONOFFLINE), + me.name, client_p->name, ""); - onptr = onbuf + mlen; - offptr = offbuf + mlen; + onptr = onbuf + mlen; + offptr = offbuf + mlen; - RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) - { - monptr = ptr->data; + RB_DLINK_FOREACH(ptr, client_p->localClient->monitor_list.head) { + monptr = ptr->data; - if((target_p = find_named_person(monptr->name)) != NULL) - { - if(cur_onlen + strlen(target_p->name) + - strlen(target_p->username) + strlen(target_p->host) + 3 >= BUFSIZE-3) - { - sendto_one(client_p, "%s", onbuf); - cur_onlen = mlen; - onptr = onbuf + mlen; - } + if((target_p = find_named_person(monptr->name)) != NULL) { + if(cur_onlen + strlen(target_p->name) + + strlen(target_p->username) + strlen(target_p->host) + 3 >= BUFSIZE-3) { + sendto_one(client_p, "%s", onbuf); + cur_onlen = mlen; + onptr = onbuf + mlen; + } - if(cur_onlen != mlen) - { - *onptr++ = ','; - cur_onlen++; - } + if(cur_onlen != mlen) { + *onptr++ = ','; + cur_onlen++; + } - arglen = sprintf(onptr, "%s!%s@%s", - target_p->name, target_p->username, - target_p->host); - onptr += arglen; - cur_onlen += arglen; - } - else - { - if(cur_offlen + strlen(monptr->name) + 1 >= BUFSIZE-3) - { - sendto_one(client_p, "%s", offbuf); - cur_offlen = mlen; - offptr = offbuf + mlen; - } + arglen = sprintf(onptr, "%s!%s@%s", + target_p->name, target_p->username, + target_p->host); + onptr += arglen; + cur_onlen += arglen; + } else { + if(cur_offlen + strlen(monptr->name) + 1 >= BUFSIZE-3) { + sendto_one(client_p, "%s", offbuf); + cur_offlen = mlen; + offptr = offbuf + mlen; + } - if(cur_offlen != mlen) - { - *offptr++ = ','; - cur_offlen++; - } + if(cur_offlen != mlen) { + *offptr++ = ','; + cur_offlen++; + } - arglen = sprintf(offptr, "%s", monptr->name); - offptr += arglen; - cur_offlen += arglen; - } - } + arglen = sprintf(offptr, "%s", monptr->name); + offptr += arglen; + cur_offlen += arglen; + } + } - if(cur_onlen != mlen) - sendto_one(client_p, "%s", onbuf); - if(cur_offlen != mlen) - sendto_one(client_p, "%s", offbuf); + if(cur_onlen != mlen) + sendto_one(client_p, "%s", onbuf); + if(cur_offlen != mlen) + sendto_one(client_p, "%s", offbuf); } static int m_monitor(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - switch(parv[1][0]) - { - case '+': - if(parc < 3 || EmptyString(parv[2])) - { - sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "MONITOR"); - return 0; - } + switch(parv[1][0]) { + case '+': + if(parc < 3 || EmptyString(parv[2])) { + sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "MONITOR"); + return 0; + } - add_monitor(source_p, parv[2]); - break; - case '-': - if(parc < 3 || EmptyString(parv[2])) - { - sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "MONITOR"); - return 0; - } + add_monitor(source_p, parv[2]); + break; + case '-': + if(parc < 3 || EmptyString(parv[2])) { + sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "MONITOR"); + return 0; + } - del_monitor(source_p, parv[2]); - break; + del_monitor(source_p, parv[2]); + break; - case 'C': - case 'c': - clear_monitor(source_p); - break; + case 'C': + case 'c': + clear_monitor(source_p); + break; - case 'L': - case 'l': - list_monitor(source_p); - break; + case 'L': + case 'l': + list_monitor(source_p); + break; - case 'S': - case 's': - show_monitor_status(source_p); - break; + case 'S': + case 's': + show_monitor_status(source_p); + break; - default: - break; - } + default: + break; + } - return 0; + return 0; } diff --git a/modules/m_motd.c b/modules/m_motd.c index 48d9a6d..a162a5d 100644 --- a/modules/m_motd.c +++ b/modules/m_motd.c @@ -40,16 +40,16 @@ static int m_motd(struct Client *, struct Client *, int, const char **); static int mo_motd(struct Client *, struct Client *, int, const char **); struct Message motd_msgtab = { - "MOTD", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_motd, 0}, {mo_motd, 0}, mg_ignore, mg_ignore, {mo_motd, 0}} + "MOTD", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_motd, 0}, {mo_motd, 0}, mg_ignore, mg_ignore, {mo_motd, 0}} }; int doing_motd_hook; mapi_clist_av1 motd_clist[] = { &motd_msgtab, NULL }; mapi_hlist_av1 motd_hlist[] = { - { "doing_motd", &doing_motd_hook }, - { NULL, NULL } + { "doing_motd", &doing_motd_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(motd, NULL, NULL, motd_clist, motd_hlist, NULL, "$Revision: 254 $"); @@ -63,27 +63,25 @@ static void motd_spy(struct Client *); static int m_motd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; + static time_t last_used = 0; - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "MOTD"); - sendto_one(source_p, form_str(RPL_ENDOFMOTD), - me.name, source_p->name); - return 0; - } - else - last_used = rb_current_time(); + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + /* safe enough to give this on a local connect only */ + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "MOTD"); + sendto_one(source_p, form_str(RPL_ENDOFMOTD), + me.name, source_p->name); + return 0; + } else + last_used = rb_current_time(); - if(hunt_server(client_p, source_p, ":%s MOTD :%s", 1, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s MOTD :%s", 1, parc, parv) != HUNTED_ISME) + return 0; - motd_spy(source_p); - send_user_motd(source_p); + motd_spy(source_p); + send_user_motd(source_p); - return 0; + return 0; } /* @@ -93,13 +91,13 @@ m_motd(struct Client *client_p, struct Client *source_p, int parc, const char *p static int mo_motd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(hunt_server(client_p, source_p, ":%s MOTD :%s", 1, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s MOTD :%s", 1, parc, parv) != HUNTED_ISME) + return 0; - motd_spy(source_p); - send_user_motd(source_p); + motd_spy(source_p); + send_user_motd(source_p); - return 0; + return 0; } /* motd_spy() @@ -111,10 +109,10 @@ mo_motd(struct Client *client_p, struct Client *source_p, int parc, const char * static void motd_spy(struct Client *source_p) { - hook_data data; + hook_data data; - data.client = source_p; - data.arg1 = data.arg2 = NULL; + data.client = source_p; + data.arg1 = data.arg2 = NULL; - call_hook(doing_motd_hook, &data); + call_hook(doing_motd_hook, &data); } diff --git a/modules/m_names.c b/modules/m_names.c index 298b871..4d2be21 100644 --- a/modules/m_names.c +++ b/modules/m_names.c @@ -41,8 +41,8 @@ static int m_names(struct Client *, struct Client *, int, const char **); struct Message names_msgtab = { - "NAMES", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}} + "NAMES", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}} }; mapi_clist_av1 names_clist[] = { &names_msgtab, NULL }; @@ -61,52 +61,45 @@ static void names_global(struct Client *source_p); static int m_names(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; - struct Channel *chptr = NULL; - char *s; + static time_t last_used = 0; + struct Channel *chptr = NULL; + char *s; - if(parc > 1 && !EmptyString(parv[1])) - { - char *p = LOCAL_COPY(parv[1]); - if((s = strchr(p, ','))) - *s = '\0'; + if(parc > 1 && !EmptyString(parv[1])) { + char *p = LOCAL_COPY(parv[1]); + if((s = strchr(p, ','))) + *s = '\0'; - if(!check_channel_name(p)) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), - (unsigned char *) p); - return 0; - } + if(!check_channel_name(p)) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), + (unsigned char *) p); + return 0; + } - if((chptr = find_channel(p)) != NULL) - channel_member_names(chptr, source_p, 1); - else - sendto_one(source_p, form_str(RPL_ENDOFNAMES), - me.name, source_p->name, p); - } - else - { - if(!IsOper(source_p)) - { - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "NAMES"); - sendto_one(source_p, form_str(RPL_ENDOFNAMES), - me.name, source_p->name, "*"); - return 0; - } - else - last_used = rb_current_time(); - } + if((chptr = find_channel(p)) != NULL) + channel_member_names(chptr, source_p, 1); + else + sendto_one(source_p, form_str(RPL_ENDOFNAMES), + me.name, source_p->name, p); + } else { + if(!IsOper(source_p)) { + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "NAMES"); + sendto_one(source_p, form_str(RPL_ENDOFNAMES), + me.name, source_p->name, "*"); + return 0; + } else + last_used = rb_current_time(); + } - names_global(source_p); - sendto_one(source_p, form_str(RPL_ENDOFNAMES), - me.name, source_p->name, "*"); - } + names_global(source_p); + sendto_one(source_p, form_str(RPL_ENDOFNAMES), + me.name, source_p->name, "*"); + } - return 0; + return 0; } /* @@ -119,71 +112,66 @@ m_names(struct Client *client_p, struct Client *source_p, int parc, const char * static void names_global(struct Client *source_p) { - int mlen; - int tlen; - int cur_len; - int dont_show = NO; - rb_dlink_node *lp, *ptr; - struct Client *target_p; - struct Channel *chptr = NULL; - struct membership *msptr; - char buf[BUFSIZE]; - char *t; + int mlen; + int tlen; + int cur_len; + int dont_show = NO; + rb_dlink_node *lp, *ptr; + struct Client *target_p; + struct Channel *chptr = NULL; + struct membership *msptr; + char buf[BUFSIZE]; + char *t; - /* first do all visible channels */ - RB_DLINK_FOREACH(ptr, global_channel_list.head) - { - chptr = ptr->data; - channel_member_names(chptr, source_p, 0); - } - cur_len = mlen = rb_sprintf(buf, form_str(RPL_NAMREPLY), - me.name, source_p->name, "*", "*"); - t = buf + mlen; + /* first do all visible channels */ + RB_DLINK_FOREACH(ptr, global_channel_list.head) { + chptr = ptr->data; + channel_member_names(chptr, source_p, 0); + } + cur_len = mlen = rb_sprintf(buf, form_str(RPL_NAMREPLY), + me.name, source_p->name, "*", "*"); + t = buf + mlen; - /* Second, do all clients in one big sweep */ - RB_DLINK_FOREACH(ptr, global_client_list.head) - { - target_p = ptr->data; - dont_show = NO; + /* Second, do all clients in one big sweep */ + RB_DLINK_FOREACH(ptr, global_client_list.head) { + target_p = ptr->data; + dont_show = NO; - if(!IsPerson(target_p) || IsInvisible(target_p)) - continue; + if(!IsPerson(target_p) || IsInvisible(target_p)) + continue; - /* we want to show -i clients that are either: - * a) not on any channels - * b) only on +p channels - * - * both were missed out above. if the target is on a - * common channel with source, its already been shown. - */ - RB_DLINK_FOREACH(lp, target_p->user->channel.head) - { - msptr = lp->data; - chptr = msptr->chptr; + /* we want to show -i clients that are either: + * a) not on any channels + * b) only on +p channels + * + * both were missed out above. if the target is on a + * common channel with source, its already been shown. + */ + RB_DLINK_FOREACH(lp, target_p->user->channel.head) { + msptr = lp->data; + chptr = msptr->chptr; - if(PubChannel(chptr) || IsMember(source_p, chptr) || - SecretChannel(chptr)) - { - dont_show = YES; - break; - } - } + if(PubChannel(chptr) || IsMember(source_p, chptr) || + SecretChannel(chptr)) { + dont_show = YES; + break; + } + } - if(dont_show) - continue; + if(dont_show) + continue; - if((cur_len + NICKLEN + 2) > (BUFSIZE - 3)) - { - sendto_one(source_p, "%s", buf); - cur_len = mlen; - t = buf + mlen; - } + if((cur_len + NICKLEN + 2) > (BUFSIZE - 3)) { + sendto_one(source_p, "%s", buf); + cur_len = mlen; + t = buf + mlen; + } - tlen = rb_sprintf(t, "%s ", target_p->name); - cur_len += tlen; - t += tlen; - } + tlen = rb_sprintf(t, "%s ", target_p->name); + cur_len += tlen; + t += tlen; + } - if(cur_len > mlen) - sendto_one(source_p, "%s", buf); + if(cur_len > mlen) + sendto_one(source_p, "%s", buf); } diff --git a/modules/m_oper.c b/modules/m_oper.c index d3f9672..ad8ece2 100644 --- a/modules/m_oper.c +++ b/modules/m_oper.c @@ -43,8 +43,8 @@ static int m_oper(struct Client *, struct Client *, int, const char **); struct Message oper_msgtab = { - "OPER", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}} + "OPER", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}} }; mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL }; @@ -60,142 +60,128 @@ static int match_oper_password(const char *password, struct oper_conf *oper_p); static int m_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct oper_conf *oper_p; - const char *name; - const char *password; + struct oper_conf *oper_p; + const char *name; + const char *password; - name = parv[1]; - password = parv[2]; + name = parv[1]; + password = parv[2]; - if(IsOper(source_p)) - { - sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); - send_oper_motd(source_p); - return 0; - } + if(IsOper(source_p)) { + sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); + send_oper_motd(source_p); + return 0; + } - /* end the grace period */ - if(!IsFloodDone(source_p)) - flood_endgrace(source_p); + /* end the grace period */ + if(!IsFloodDone(source_p)) + flood_endgrace(source_p); - oper_p = find_oper_conf(source_p->username, source_p->orighost, - source_p->sockhost, name); + oper_p = find_oper_conf(source_p->username, source_p->orighost, + source_p->sockhost, name); - if(oper_p == NULL) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", - name, source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if(oper_p == NULL) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", + name, source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Failed OPER attempt - host mismatch by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - } + if(ConfigFileEntry.failed_oper_notice) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Failed OPER attempt - host mismatch by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + } - return 0; - } + return 0; + } - if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p)) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS", - name, source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if(IsOperConfNeedSSL(oper_p) && !IsSSLClient(source_p)) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- requires SSL/TLS", + name, source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Failed OPER attempt - missing SSL/TLS by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - } - return 0; - } + if(ConfigFileEntry.failed_oper_notice) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Failed OPER attempt - missing SSL/TLS by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + } + return 0; + } - if (oper_p->certfp != NULL) - { - if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp)) - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch", - name, source_p->name, - source_p->username, source_p->host, source_p->sockhost); + if (oper_p->certfp != NULL) { + if (source_p->certfp == NULL || strcasecmp(source_p->certfp, oper_p->certfp)) { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s) -- client certificate fingerprint mismatch", + name, source_p->name, + source_p->username, source_p->host, source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - } - return 0; - } - } + if(ConfigFileEntry.failed_oper_notice) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Failed OPER attempt - client certificate fingerprint mismatch by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + } + return 0; + } + } - if(match_oper_password(password, oper_p)) - { - oper_up(source_p, oper_p); + if(match_oper_password(password, oper_p)) { + oper_up(source_p, oper_p); - ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)", - name, source_p->name, source_p->username, source_p->host, - source_p->sockhost); - return 0; - } - else - { - sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); + ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)", + name, source_p->name, source_p->username, source_p->host, + source_p->sockhost); + return 0; + } else { + sendto_one_numeric(source_p, ERR_NOOPERHOST, form_str(ERR_NOOPERHOST)); - ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", - name, source_p->name, source_p->username, source_p->host, - source_p->sockhost); + ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", + name, source_p->name, source_p->username, source_p->host, + source_p->sockhost); - if(ConfigFileEntry.failed_oper_notice) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Failed OPER attempt by %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - } - } + if(ConfigFileEntry.failed_oper_notice) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Failed OPER attempt by %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + } + } - return 0; + return 0; } /* * match_oper_password * * inputs - pointer to given password - * - pointer to Conf + * - pointer to Conf * output - YES or NO if match * side effects - none */ static int match_oper_password(const char *password, struct oper_conf *oper_p) { - const char *encr; + const char *encr; - /* passwd may be NULL pointer. Head it off at the pass... */ - if(EmptyString(oper_p->passwd)) - return NO; + /* passwd may be NULL pointer. Head it off at the pass... */ + if(EmptyString(oper_p->passwd)) + return NO; - if(IsOperConfEncrypted(oper_p)) - { - /* use first two chars of the password they send in as salt */ - /* If the password in the conf is MD5, and ircd is linked - * to scrypt on FreeBSD, or the standard crypt library on - * glibc Linux, then this code will work fine on generating - * the proper encrypted hash for comparison. - */ - if(!EmptyString(password)) - encr = rb_crypt(password, oper_p->passwd); - else - encr = ""; - } - else - encr = password; + if(IsOperConfEncrypted(oper_p)) { + /* use first two chars of the password they send in as salt */ + /* If the password in the conf is MD5, and ircd is linked + * to scrypt on FreeBSD, or the standard crypt library on + * glibc Linux, then this code will work fine on generating + * the proper encrypted hash for comparison. + */ + if(!EmptyString(password)) + encr = rb_crypt(password, oper_p->passwd); + else + encr = ""; + } else + encr = password; - if(strcmp(encr, oper_p->passwd) == 0) - return YES; - else - return NO; + if(strcmp(encr, oper_p->passwd) == 0) + return YES; + else + return NO; } diff --git a/modules/m_operspy.c b/modules/m_operspy.c index b46fa8f..dc33836 100644 --- a/modules/m_operspy.c +++ b/modules/m_operspy.c @@ -43,11 +43,11 @@ #include "modules.h" static int ms_operspy(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); struct Message operspy_msgtab = { - "OPERSPY", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {ms_operspy, 2}, mg_ignore} + "OPERSPY", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {ms_operspy, 2}, mg_ignore} }; mapi_clist_av1 operspy_clist[] = { &operspy_msgtab, NULL }; @@ -60,40 +60,37 @@ DECLARE_MODULE_AV1(operspy, NULL, NULL, operspy_clist, NULL, NULL, "$Revision: 2 */ static int ms_operspy(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - static char buffer[BUFSIZE]; - char *ptr; - int cur_len = 0; - int len, i; + static char buffer[BUFSIZE]; + char *ptr; + int cur_len = 0; + int len, i; - if(parc < 4) - { - report_operspy(source_p, parv[1], - parc < 3 ? NULL : parv[2]); - } - /* buffer all remaining into one param */ - else - { - ptr = buffer; - cur_len = 0; + if(parc < 4) { + report_operspy(source_p, parv[1], + parc < 3 ? NULL : parv[2]); + } + /* buffer all remaining into one param */ + else { + ptr = buffer; + cur_len = 0; - for(i = 2; i < parc; i++) - { - len = strlen(parv[i]) + 1; + for(i = 2; i < parc; i++) { + len = strlen(parv[i]) + 1; - if((size_t)(cur_len + len) >= sizeof(buffer)) - return 0; + if((size_t)(cur_len + len) >= sizeof(buffer)) + return 0; - rb_snprintf(ptr, sizeof(buffer) - cur_len, "%s ", - parv[i]); - ptr += len; - cur_len += len; - } + rb_snprintf(ptr, sizeof(buffer) - cur_len, "%s ", + parv[i]); + ptr += len; + cur_len += len; + } - report_operspy(source_p, parv[1], buffer); - } + report_operspy(source_p, parv[1], buffer); + } - return 0; + return 0; } diff --git a/modules/m_pass.c b/modules/m_pass.c index 443e1dc..dbfa2b3 100644 --- a/modules/m_pass.c +++ b/modules/m_pass.c @@ -39,8 +39,8 @@ static int mr_pass(struct Client *, struct Client *, int, const char **); struct Message pass_msgtab = { - "PASS", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_pass, 2}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} + "PASS", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_pass, 2}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} }; mapi_clist_av1 pass_clist[] = { &pass_msgtab, NULL }; @@ -58,47 +58,43 @@ DECLARE_MODULE_AV1(pass, NULL, NULL, pass_clist, NULL, NULL, "$Revision: 3550 $" static int mr_pass(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - char *pass, *buf; - buf = LOCAL_COPY(parv[1]); - - if(client_p->localClient->passwd) - { - memset(client_p->localClient->passwd, 0, - strlen(client_p->localClient->passwd)); - rb_free(client_p->localClient->passwd); - client_p->localClient->passwd = NULL; - } + char *pass, *buf; + buf = LOCAL_COPY(parv[1]); - pass = buf; - - client_p->localClient->passwd = *pass ? rb_strndup(pass, PASSWDLEN) : NULL; - - /* These are for servers only */ - if(parc > 2 && client_p->user == NULL) - { - /* - * It looks to me as if orabidoo wanted to have more - * than one set of option strings possible here... - * i.e. ":AABBTS" as long as TS was the last two chars - * however, as we are now using CAPAB, I think we can - * safely assume if there is a ":TS" then its a TS server - * -Dianora - */ - if(irccmp(parv[2], "TS") == 0 && client_p->tsinfo == 0) - client_p->tsinfo = TS_DOESTS; + if(client_p->localClient->passwd) { + memset(client_p->localClient->passwd, 0, + strlen(client_p->localClient->passwd)); + rb_free(client_p->localClient->passwd); + client_p->localClient->passwd = NULL; + } - if(parc == 5 && atoi(parv[3]) >= 6) - { - /* only mark as TS6 if the SID is valid.. */ - if(IsDigit(parv[4][0]) && IsIdChar(parv[4][1]) && - IsIdChar(parv[4][2]) && parv[4][3] == '\0' && - EmptyString(client_p->id)) - { - client_p->localClient->caps |= CAP_TS6; - strcpy(client_p->id, parv[4]); - } - } - } + pass = buf; - return 0; + client_p->localClient->passwd = *pass ? rb_strndup(pass, PASSWDLEN) : NULL; + + /* These are for servers only */ + if(parc > 2 && client_p->user == NULL) { + /* + * It looks to me as if orabidoo wanted to have more + * than one set of option strings possible here... + * i.e. ":AABBTS" as long as TS was the last two chars + * however, as we are now using CAPAB, I think we can + * safely assume if there is a ":TS" then its a TS server + * -Dianora + */ + if(irccmp(parv[2], "TS") == 0 && client_p->tsinfo == 0) + client_p->tsinfo = TS_DOESTS; + + if(parc == 5 && atoi(parv[3]) >= 6) { + /* only mark as TS6 if the SID is valid.. */ + if(IsDigit(parv[4][0]) && IsIdChar(parv[4][1]) && + IsIdChar(parv[4][2]) && parv[4][3] == '\0' && + EmptyString(client_p->id)) { + client_p->localClient->caps |= CAP_TS6; + strcpy(client_p->id, parv[4]); + } + } + } + + return 0; } diff --git a/modules/m_ping.c b/modules/m_ping.c index b5e1c83..787a4b2 100644 --- a/modules/m_ping.c +++ b/modules/m_ping.c @@ -40,8 +40,8 @@ static int m_ping(struct Client *, struct Client *, int, const char **); static int ms_ping(struct Client *, struct Client *, int, const char **); struct Message ping_msgtab = { - "PING", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_ping, 2}, {ms_ping, 2}, {ms_ping, 2}, mg_ignore, {m_ping, 2}} + "PING", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_ping, 2}, {ms_ping, 2}, {ms_ping, 2}, mg_ignore, {m_ping, 2}} }; mapi_clist_av1 ping_clist[] = { &ping_msgtab, NULL }; @@ -55,59 +55,52 @@ DECLARE_MODULE_AV1(ping, NULL, NULL, ping_clist, NULL, NULL, "$Revision: 254 $") static int m_ping(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - const char *destination; + struct Client *target_p; + const char *destination; - destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ + destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ - if(!EmptyString(destination) && !match(destination, me.name)) - { - if((target_p = find_server(source_p, destination))) - { - sendto_one(target_p, ":%s PING %s :%s", - get_id(source_p, target_p), - source_p->name, get_id(target_p, target_p)); - } - else - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), - destination); - return 0; - } - } - else - sendto_one(source_p, ":%s PONG %s :%s", me.name, - (destination) ? destination : me.name, parv[1]); + if(!EmptyString(destination) && !match(destination, me.name)) { + if((target_p = find_server(source_p, destination))) { + sendto_one(target_p, ":%s PING %s :%s", + get_id(source_p, target_p), + source_p->name, get_id(target_p, target_p)); + } else { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), + destination); + return 0; + } + } else + sendto_one(source_p, ":%s PONG %s :%s", me.name, + (destination) ? destination : me.name, parv[1]); - return 0; + return 0; } static int ms_ping(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - const char *destination; + struct Client *target_p; + const char *destination; - destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ + destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ - if(!EmptyString(destination) && irccmp(destination, me.name) && - irccmp(destination, me.id)) - { - if((target_p = find_client(destination)) && IsServer(target_p)) - sendto_one(target_p, ":%s PING %s :%s", - get_id(source_p, target_p), source_p->name, - get_id(target_p, target_p)); - /* not directed at an id.. */ - else if(!IsDigit(*destination)) - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), - destination); - } - else - sendto_one(source_p, ":%s PONG %s :%s", - get_id(&me, source_p), me.name, - get_id(source_p, source_p)); + if(!EmptyString(destination) && irccmp(destination, me.name) && + irccmp(destination, me.id)) { + if((target_p = find_client(destination)) && IsServer(target_p)) + sendto_one(target_p, ":%s PING %s :%s", + get_id(source_p, target_p), source_p->name, + get_id(target_p, target_p)); + /* not directed at an id.. */ + else if(!IsDigit(*destination)) + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), + destination); + } else + sendto_one(source_p, ":%s PONG %s :%s", + get_id(&me, source_p), me.name, + get_id(source_p, source_p)); - return 0; + return 0; } diff --git a/modules/m_pong.c b/modules/m_pong.c index fc8245a..abf28fc 100644 --- a/modules/m_pong.c +++ b/modules/m_pong.c @@ -43,8 +43,8 @@ static int mr_pong(struct Client *, struct Client *, int, const char **); static int ms_pong(struct Client *, struct Client *, int, const char **); struct Message pong_msgtab = { - "PONG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_pong, 0}, mg_ignore, mg_ignore, {ms_pong, 2}, mg_ignore, mg_ignore} + "PONG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_pong, 0}, mg_ignore, mg_ignore, {ms_pong, 2}, mg_ignore, mg_ignore} }; mapi_clist_av1 pong_clist[] = { &pong_msgtab, NULL }; @@ -53,82 +53,72 @@ DECLARE_MODULE_AV1(pong, NULL, NULL, pong_clist, NULL, NULL, "$Revision: 3181 $" static int ms_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - const char *destination; + struct Client *target_p; + const char *destination; - destination = parv[2]; - source_p->flags &= ~FLAGS_PINGSENT; + destination = parv[2]; + source_p->flags &= ~FLAGS_PINGSENT; - /* Now attempt to route the PONG, comstud pointed out routable PING - * is used for SPING. routable PING should also probably be left in - * -Dianora - * That being the case, we will route, but only for registered clients (a - * case can be made to allow them only from servers). -Shadowfax - */ - if(!EmptyString(destination) && !match(destination, me.name) && - irccmp(destination, me.id)) - { - if((target_p = find_client(destination))) - sendto_one(target_p, ":%s PONG %s %s", - get_id(source_p, target_p), parv[1], - get_id(target_p, target_p)); - else - { - if(!IsDigit(*destination)) - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), destination); - return 0; - } - } + /* Now attempt to route the PONG, comstud pointed out routable PING + * is used for SPING. routable PING should also probably be left in + * -Dianora + * That being the case, we will route, but only for registered clients (a + * case can be made to allow them only from servers). -Shadowfax + */ + if(!EmptyString(destination) && !match(destination, me.name) && + irccmp(destination, me.id)) { + if((target_p = find_client(destination))) + sendto_one(target_p, ":%s PONG %s %s", + get_id(source_p, target_p), parv[1], + get_id(target_p, target_p)); + else { + if(!IsDigit(*destination)) + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), destination); + return 0; + } + } - /* destination is us, emulate EOB */ - if(IsServer(source_p) && !HasSentEob(source_p)) - { - if(MyConnect(source_p)) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "End of burst (emulated) from %s (%d seconds)", - source_p->name, - (signed int) (rb_current_time() - source_p->localClient->firsttime)); - SetEob(source_p); - eob_count++; - call_hook(h_server_eob, source_p); - } + /* destination is us, emulate EOB */ + if(IsServer(source_p) && !HasSentEob(source_p)) { + if(MyConnect(source_p)) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "End of burst (emulated) from %s (%d seconds)", + source_p->name, + (signed int) (rb_current_time() - source_p->localClient->firsttime)); + SetEob(source_p); + eob_count++; + call_hook(h_server_eob, source_p); + } - return 0; + return 0; } static int mr_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(parc == 2 && !EmptyString(parv[1])) - { - if(ConfigFileEntry.ping_cookie && source_p->flags & FLAGS_SENTUSER && source_p->name[0]) - { - unsigned long incoming_ping = strtoul(parv[1], NULL, 16); - if(incoming_ping) - { - if(source_p->localClient->random_ping == incoming_ping) - { - char buf[USERLEN + 1]; - rb_strlcpy(buf, source_p->username, sizeof(buf)); - source_p->flags |= FLAGS_PING_COOKIE; - register_local_user(client_p, source_p, buf); - } - else - { - sendto_one(source_p, form_str(ERR_WRONGPONG), - me.name, source_p->name, - source_p->localClient->random_ping); - return 0; - } - } - } + if(parc == 2 && !EmptyString(parv[1])) { + if(ConfigFileEntry.ping_cookie && source_p->flags & FLAGS_SENTUSER && source_p->name[0]) { + unsigned long incoming_ping = strtoul(parv[1], NULL, 16); + if(incoming_ping) { + if(source_p->localClient->random_ping == incoming_ping) { + char buf[USERLEN + 1]; + rb_strlcpy(buf, source_p->username, sizeof(buf)); + source_p->flags |= FLAGS_PING_COOKIE; + register_local_user(client_p, source_p, buf); + } else { + sendto_one(source_p, form_str(ERR_WRONGPONG), + me.name, source_p->name, + source_p->localClient->random_ping); + return 0; + } + } + } - } - else - sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, source_p->name); + } else + sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, source_p->name); - source_p->flags &= ~FLAGS_PINGSENT; + source_p->flags &= ~FLAGS_PINGSENT; - return 0; + return 0; } diff --git a/modules/m_post.c b/modules/m_post.c index ddff8ea..937e124 100644 --- a/modules/m_post.c +++ b/modules/m_post.c @@ -37,21 +37,21 @@ static int mr_dumb_proxy(struct Client *, struct Client *, int, const char **); struct Message post_msgtab = { - "POST", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_dumb_proxy, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} + "POST", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_dumb_proxy, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} }; struct Message get_msgtab = { - "GET", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_dumb_proxy, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} + "GET", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_dumb_proxy, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} }; struct Message put_msgtab = { - "PUT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {{mr_dumb_proxy, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} + "PUT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {{mr_dumb_proxy, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore} }; mapi_clist_av1 post_clist[] = { - &post_msgtab, &get_msgtab, &put_msgtab, NULL + &post_msgtab, &get_msgtab, &put_msgtab, NULL }; DECLARE_MODULE_AV1(post, NULL, NULL, post_clist, NULL, NULL, "$Revision: 498 $"); @@ -63,7 +63,7 @@ DECLARE_MODULE_AV1(post, NULL, NULL, post_clist, NULL, NULL, "$Revision: 498 $") static int mr_dumb_proxy(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - exit_client(client_p, source_p, source_p, "Client Exit"); + exit_client(client_p, source_p, source_p, "Client Exit"); - return 0; + return 0; } diff --git a/modules/m_privs.c b/modules/m_privs.c index 1d24aad..29b4dda 100644 --- a/modules/m_privs.c +++ b/modules/m_privs.c @@ -44,110 +44,103 @@ static int me_privs(struct Client *client_p, struct Client *source_p, int parc, static int mo_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message privs_msgtab = { - "PRIVS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}} + "PRIVS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}} }; mapi_clist_av1 privs_clist[] = { - &privs_msgtab, - NULL + &privs_msgtab, + NULL }; /* XXX this is a copy, not so nice */ -struct mode_table -{ - const char *name; - int mode; +struct mode_table { + const char *name; + int mode; }; /* there is no such table like this anywhere else */ static struct mode_table auth_client_table[] = { - {"resv_exempt", FLAGS2_EXEMPTRESV }, - {"kline_exempt", FLAGS2_EXEMPTKLINE }, - {"flood_exempt", FLAGS2_EXEMPTFLOOD }, - {"spambot_exempt", FLAGS2_EXEMPTSPAMBOT }, - {"shide_exempt", FLAGS2_EXEMPTSHIDE }, - {"jupe_exempt", FLAGS2_EXEMPTJUPE }, - {NULL, 0} + {"resv_exempt", FLAGS2_EXEMPTRESV }, + {"kline_exempt", FLAGS2_EXEMPTKLINE }, + {"flood_exempt", FLAGS2_EXEMPTFLOOD }, + {"spambot_exempt", FLAGS2_EXEMPTSPAMBOT }, + {"shide_exempt", FLAGS2_EXEMPTSHIDE }, + {"jupe_exempt", FLAGS2_EXEMPTJUPE }, + {NULL, 0} }; DECLARE_MODULE_AV1(privs, NULL, NULL, privs_clist, NULL, NULL, ""); static void show_privs(struct Client *source_p, struct Client *target_p) { - char buf[512]; - struct mode_table *p; + char buf[512]; + struct mode_table *p; - buf[0] = '\0'; - if (target_p->localClient->privset) - rb_strlcat(buf, target_p->localClient->privset->privs, sizeof buf); - if (IsOper(target_p)) - { - if (buf[0] != '\0') - rb_strlcat(buf, " ", sizeof buf); - rb_strlcat(buf, "operator:", sizeof buf); - rb_strlcat(buf, target_p->localClient->opername, sizeof buf); + buf[0] = '\0'; + if (target_p->localClient->privset) + rb_strlcat(buf, target_p->localClient->privset->privs, sizeof buf); + if (IsOper(target_p)) { + if (buf[0] != '\0') + rb_strlcat(buf, " ", sizeof buf); + rb_strlcat(buf, "operator:", sizeof buf); + rb_strlcat(buf, target_p->localClient->opername, sizeof buf); - if (target_p->localClient->privset) - { - if (buf[0] != '\0') - rb_strlcat(buf, " ", sizeof buf); - rb_strlcat(buf, "privset:", sizeof buf); - rb_strlcat(buf, target_p->localClient->privset->name, sizeof buf); - } - } - p = &auth_client_table[0]; - while (p->name != NULL) - { - if (target_p->flags2 & p->mode) - { - if (buf[0] != '\0') - rb_strlcat(buf, " ", sizeof buf); - rb_strlcat(buf, p->name, sizeof buf); - } - p++; - } - sendto_one_numeric(source_p, RPL_PRIVS, form_str(RPL_PRIVS), - target_p->name, buf); + if (target_p->localClient->privset) { + if (buf[0] != '\0') + rb_strlcat(buf, " ", sizeof buf); + rb_strlcat(buf, "privset:", sizeof buf); + rb_strlcat(buf, target_p->localClient->privset->name, sizeof buf); + } + } + p = &auth_client_table[0]; + while (p->name != NULL) { + if (target_p->flags2 & p->mode) { + if (buf[0] != '\0') + rb_strlcat(buf, " ", sizeof buf); + rb_strlcat(buf, p->name, sizeof buf); + } + p++; + } + sendto_one_numeric(source_p, RPL_PRIVS, form_str(RPL_PRIVS), + target_p->name, buf); } static int me_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) - return 0; + if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) + return 0; - /* we cannot show privs for remote clients */ - if((target_p = find_person(parv[1])) && MyClient(target_p)) - show_privs(source_p, target_p); + /* we cannot show privs for remote clients */ + if((target_p = find_person(parv[1])) && MyClient(target_p)) + show_privs(source_p, target_p); - return 0; + return 0; } static int mo_privs(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if (parc < 2 || EmptyString(parv[1])) - target_p = source_p; - else - { - target_p = find_named_person(parv[1]); - if (target_p == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), parv[1]); - return 0; - } - } + if (parc < 2 || EmptyString(parv[1])) + target_p = source_p; + else { + target_p = find_named_person(parv[1]); + if (target_p == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), parv[1]); + return 0; + } + } - if (MyClient(target_p)) - show_privs(source_p, target_p); - else - sendto_one(target_p, ":%s ENCAP %s PRIVS %s", - get_id(source_p, target_p), - target_p->servptr->name, - use_id(target_p)); - return 0; + if (MyClient(target_p)) + show_privs(source_p, target_p); + else + sendto_one(target_p, ":%s ENCAP %s PRIVS %s", + get_id(source_p, target_p), + target_p->servptr->name, + use_id(target_p)); + return 0; } diff --git a/modules/m_rehash.c b/modules/m_rehash.c index 80333d1..945a60c 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -48,295 +48,279 @@ static int mo_rehash(struct Client *, struct Client *, int, const char **); static int me_rehash(struct Client *, struct Client *, int, const char **); struct Message rehash_msgtab = { - "REHASH", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_rehash, 0}, {mo_rehash, 0}} + "REHASH", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_rehash, 0}, {mo_rehash, 0}} }; mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL }; DECLARE_MODULE_AV1(rehash, NULL, NULL, rehash_clist, NULL, NULL, "$Revision: 3161 $"); -struct hash_commands -{ - const char *cmd; - void (*handler) (struct Client * source_p); +struct hash_commands { + const char *cmd; + void (*handler) (struct Client * source_p); }; static void rehash_bans_loc(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing bans", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing bans", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - rehash_bans(0); + rehash_bans(0); } static void rehash_dns(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - /* reread /etc/resolv.conf and reopen res socket */ - restart_resolver(); + /* reread /etc/resolv.conf and reopen res socket */ + restart_resolver(); } static void rehash_motd(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is forcing re-reading of MOTD file", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is forcing re-reading of MOTD file", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - cache_user_motd(); + cache_user_motd(); } static void rehash_omotd(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is forcing re-reading of OPER MOTD file", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is forcing re-reading of OPER MOTD file", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - free_cachefile(oper_motd); - oper_motd = cache_file(OPATH, "opers.motd", 0); + free_cachefile(oper_motd); + oper_motd = cache_file(OPATH, "opers.motd", 0); } static void rehash_tklines(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr, *next_ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr, *next_ptr; + int i; - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - for(i = 0; i < LAST_TEMP_TYPE; i++) - { - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head) - { - aconf = ptr->data; + for(i = 0; i < LAST_TEMP_TYPE; i++) { + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head) { + aconf = ptr->data; - delete_one_address_conf(aconf->host, aconf); - rb_dlinkDestroy(ptr, &temp_klines[i]); - } - } + delete_one_address_conf(aconf->host, aconf); + rb_dlinkDestroy(ptr, &temp_klines[i]); + } + } } static void rehash_tdlines(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr, *next_ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr, *next_ptr; + int i; - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - for(i = 0; i < LAST_TEMP_TYPE; i++) - { - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head) - { - aconf = ptr->data; + for(i = 0; i < LAST_TEMP_TYPE; i++) { + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head) { + aconf = ptr->data; - delete_one_address_conf(aconf->host, aconf); - rb_dlinkDestroy(ptr, &temp_dlines[i]); - } - } + delete_one_address_conf(aconf->host, aconf); + rb_dlinkDestroy(ptr, &temp_dlines[i]); + } + } } static void rehash_txlines(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) { + aconf = ptr->data; - if(!aconf->hold || aconf->lifetime) - continue; + if(!aconf->hold || aconf->lifetime) + continue; - free_conf(aconf); - rb_dlinkDestroy(ptr, &xline_conf_list); - } + free_conf(aconf); + rb_dlinkDestroy(ptr, &xline_conf_list); + } } static void rehash_tresvs(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + int i; - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) - { - aconf = ptr->data; + HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) { + aconf = ptr->data; - if(!aconf->hold || aconf->lifetime) - continue; + if(!aconf->hold || aconf->lifetime) + continue; - free_conf(aconf); - rb_dlinkDestroy(ptr, &resvTable[i]); - } - HASH_WALK_END + free_conf(aconf); + rb_dlinkDestroy(ptr, &resvTable[i]); + } + HASH_WALK_END - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) { + aconf = ptr->data; - if(!aconf->hold || aconf->lifetime) - continue; + if(!aconf->hold || aconf->lifetime) + continue; - free_conf(aconf); - rb_dlinkDestroy(ptr, &resv_conf_list); - } + free_conf(aconf); + rb_dlinkDestroy(ptr, &resv_conf_list); + } } static void rehash_rejectcache(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing reject cache", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; - flush_reject(); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing reject cache", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; + flush_reject(); } static void rehash_throttles(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing throttles", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; - flush_throttle(); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing throttles", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; + flush_throttle(); } static void rehash_help(struct Client *source_p) { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is forcing re-reading of HELP files", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; - load_help(); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is forcing re-reading of HELP files", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; + load_help(); } static void rehash_nickdelay(struct Client *source_p) { - struct nd_entry *nd; - rb_dlink_node *ptr; - rb_dlink_node *safe_ptr; + struct nd_entry *nd; + rb_dlink_node *ptr; + rb_dlink_node *safe_ptr; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is clearing the nick delay table", - get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is clearing the nick delay table", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; - RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head) - { - nd = ptr->data; - - free_nd_entry(nd); - } + RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head) { + nd = ptr->data; + + free_nd_entry(nd); + } } /* *INDENT-OFF* */ -static struct hash_commands rehash_commands[] = -{ - {"BANS", rehash_bans_loc }, - {"DNS", rehash_dns }, - {"MOTD", rehash_motd }, - {"OMOTD", rehash_omotd }, - {"TKLINES", rehash_tklines }, - {"TDLINES", rehash_tdlines }, - {"TXLINES", rehash_txlines }, - {"TRESVS", rehash_tresvs }, - {"REJECTCACHE", rehash_rejectcache }, - {"THROTTLES", rehash_throttles }, - {"HELP", rehash_help }, - {"NICKDELAY", rehash_nickdelay }, - {NULL, NULL } +static struct hash_commands rehash_commands[] = { + {"BANS", rehash_bans_loc }, + {"DNS", rehash_dns }, + {"MOTD", rehash_motd }, + {"OMOTD", rehash_omotd }, + {"TKLINES", rehash_tklines }, + {"TDLINES", rehash_tdlines }, + {"TXLINES", rehash_txlines }, + {"TRESVS", rehash_tresvs }, + {"REJECTCACHE", rehash_rejectcache }, + {"THROTTLES", rehash_throttles }, + {"HELP", rehash_help }, + {"NICKDELAY", rehash_nickdelay }, + {NULL, NULL } }; /* *INDENT-ON* */ static void do_rehash(struct Client *source_p, const char *type) { - if (type != NULL) - { - int x; - char cmdbuf[100]; + if (type != NULL) { + int x; + char cmdbuf[100]; - for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL; - x++) - { - if(irccmp(type, rehash_commands[x].cmd) == 0) - { - sendto_one(source_p, form_str(RPL_REHASHING), me.name, - source_p->name, rehash_commands[x].cmd); - ilog(L_MAIN, "REHASH %s From %s[%s]", type, - get_oper_name(source_p), source_p->sockhost); - rehash_commands[x].handler(source_p); - remote_rehash_oper_p = NULL; - return; - } - } + for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL; + x++) { + if(irccmp(type, rehash_commands[x].cmd) == 0) { + sendto_one(source_p, form_str(RPL_REHASHING), me.name, + source_p->name, rehash_commands[x].cmd); + ilog(L_MAIN, "REHASH %s From %s[%s]", type, + get_oper_name(source_p), source_p->sockhost); + rehash_commands[x].handler(source_p); + remote_rehash_oper_p = NULL; + return; + } + } - /* We are still here..we didn't match */ - cmdbuf[0] = '\0'; - for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL; - x++) - { - rb_strlcat(cmdbuf, " ", sizeof(cmdbuf)); - rb_strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf)); - } - sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf); - } - else - { - sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name, - ConfigFileEntry.configfile); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is rehashing server config file", get_oper_name(source_p)); - if (!MyConnect(source_p)) - remote_rehash_oper_p = source_p; - ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p), - source_p->sockhost); - rehash(0); - remote_rehash_oper_p = NULL; - } + /* We are still here..we didn't match */ + cmdbuf[0] = '\0'; + for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL; + x++) { + rb_strlcat(cmdbuf, " ", sizeof(cmdbuf)); + rb_strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf)); + } + sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf); + } else { + sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name, + ConfigFileEntry.configfile); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is rehashing server config file", get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; + ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p), + source_p->sockhost); + rehash(0); + remote_rehash_oper_p = NULL; + } } /* @@ -348,57 +332,54 @@ do_rehash(struct Client *source_p, const char *type) static int mo_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *type = NULL, *target_server = NULL; + const char *type = NULL, *target_server = NULL; - if(!IsOperRehash(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "rehash"); - return 0; - } + if(!IsOperRehash(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "rehash"); + return 0; + } - if (parc > 2) - type = parv[1], target_server = parv[2]; - else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*'))) - type = NULL, target_server = parv[1]; - else if (parc > 1) - type = parv[1], target_server = NULL; - else - type = NULL, target_server = NULL; + if (parc > 2) + type = parv[1], target_server = parv[2]; + else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*'))) + type = NULL, target_server = parv[1]; + else if (parc > 1) + type = parv[1], target_server = NULL; + else + type = NULL, target_server = NULL; - if (target_server != NULL) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } - sendto_match_servs(source_p, target_server, - CAP_ENCAP, NOCAPS, - "ENCAP %s REHASH %s", - target_server, type != NULL ? type : ""); - if (match(target_server, me.name) == 0) - return 0; - } + if (target_server != NULL) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } + sendto_match_servs(source_p, target_server, + CAP_ENCAP, NOCAPS, + "ENCAP %s REHASH %s", + target_server, type != NULL ? type : ""); + if (match(target_server, me.name) == 0) + return 0; + } - do_rehash(source_p, type); + do_rehash(source_p, type); - return 0; + return 0; } static int me_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if (!IsPerson(source_p)) - return 0; + if (!IsPerson(source_p)) + return 0; - if (!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, SHARED_REHASH)) - return 0; + if (!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, SHARED_REHASH)) + return 0; - do_rehash(source_p, parc > 1 ? parv[1] : NULL); + do_rehash(source_p, parc > 1 ? parv[1] : NULL); - return 0; + return 0; } diff --git a/modules/m_restart.c b/modules/m_restart.c index 36dbf9c..f9e0567 100644 --- a/modules/m_restart.c +++ b/modules/m_restart.c @@ -44,8 +44,8 @@ static int me_restart(struct Client *, struct Client *, int, const char **); static int do_restart(struct Client *source_p, const char *servername); struct Message restart_msgtab = { - "RESTART", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_restart, 1}, {mo_restart, 0}} + "RESTART", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_restart, 1}, {mo_restart, 0}} }; mapi_clist_av1 restart_clist[] = { &restart_msgtab, NULL }; @@ -58,82 +58,73 @@ DECLARE_MODULE_AV1(restart, NULL, NULL, restart_clist, NULL, NULL, "$Revision: 3 static int mo_restart(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(!IsOperDie(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "die"); - return 0; - } + if(!IsOperDie(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "die"); + return 0; + } - if(parc < 2 || EmptyString(parv[1])) - { - sendto_one_notice(source_p, ":Need server name /restart %s", me.name); - return 0; - } + if(parc < 2 || EmptyString(parv[1])) { + sendto_one_notice(source_p, ":Need server name /restart %s", me.name); + return 0; + } - if(parc > 2) - { - /* Remote restart. Pass it along. */ - struct Client *server_p = find_server(NULL, parv[2]); - if (!server_p) - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]); - return 0; - } - if (!IsMe(server_p)) - { - sendto_one(server_p, ":%s ENCAP %s RESTART %s", source_p->name, parv[2], parv[1]); - return 0; - } + if(parc > 2) { + /* Remote restart. Pass it along. */ + struct Client *server_p = find_server(NULL, parv[2]); + if (!server_p) { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]); + return 0; } + if (!IsMe(server_p)) { + sendto_one(server_p, ":%s ENCAP %s RESTART %s", source_p->name, parv[2], parv[1]); + return 0; + } + } - return do_restart(source_p, parv[1]); + return do_restart(source_p, parv[1]); } static int me_restart(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[]) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_DIE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block to " - "remotely restart this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_DIE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block to " + "remotely restart this server."); + return 0; + } - return do_restart(source_p, parv[1]); + return do_restart(source_p, parv[1]); } static int do_restart(struct Client *source_p, const char *servername) { - char buf[BUFSIZE]; - rb_dlink_node *ptr; - struct Client *target_p; + char buf[BUFSIZE]; + rb_dlink_node *ptr; + struct Client *target_p; - /* this makes sure both servernames match otherwise weirdness will occur */ - if(irccmp(servername, me.name)) - { - sendto_one_notice(source_p, ":Mismatch on /restart %s", me.name); - return 0; - } + /* this makes sure both servernames match otherwise weirdness will occur */ + if(irccmp(servername, me.name)) { + sendto_one_notice(source_p, ":Mismatch on /restart %s", me.name); + return 0; + } - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, lclient_list.head) { + target_p = ptr->data; - sendto_one_notice(target_p, ":Server Restarting. %s", get_client_name(source_p, HIDE_IP)); - } + sendto_one_notice(target_p, ":Server Restarting. %s", get_client_name(source_p, HIDE_IP)); + } - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - sendto_one(target_p, ":%s ERROR :Restart by %s", - me.name, get_client_name(source_p, HIDE_IP)); - } + sendto_one(target_p, ":%s ERROR :Restart by %s", + me.name, get_client_name(source_p, HIDE_IP)); + } - rb_sprintf(buf, "Server RESTART by %s", get_client_name(source_p, HIDE_IP)); - restart(buf); + rb_sprintf(buf, "Server RESTART by %s", get_client_name(source_p, HIDE_IP)); + restart(buf); - return 0; + return 0; } diff --git a/modules/m_resv.c b/modules/m_resv.c index af72747..f755ad5 100644 --- a/modules/m_resv.c +++ b/modules/m_resv.c @@ -48,13 +48,13 @@ static int ms_unresv(struct Client *, struct Client *, int, const char **); static int me_unresv(struct Client *, struct Client *, int, const char **); struct Message resv_msgtab = { - "RESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {mg_ignore, mg_not_oper, {ms_resv, 4}, {ms_resv, 4}, {me_resv, 5}, {mo_resv, 3}} + "RESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {mg_ignore, mg_not_oper, {ms_resv, 4}, {ms_resv, 4}, {me_resv, 5}, {mo_resv, 3}} }; struct Message unresv_msgtab = { - "UNRESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, - {mg_ignore, mg_not_oper, {ms_unresv, 3}, {ms_unresv, 3}, {me_unresv, 2}, {mo_unresv, 2}} + "UNRESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, + {mg_ignore, mg_not_oper, {ms_unresv, 3}, {ms_unresv, 3}, {me_unresv, 2}, {mo_unresv, 2}} }; mapi_clist_av1 resv_clist[] = { &resv_msgtab, &unresv_msgtab, NULL }; @@ -62,11 +62,11 @@ mapi_clist_av1 resv_clist[] = { &resv_msgtab, &unresv_msgtab, NULL }; DECLARE_MODULE_AV1(resv, NULL, NULL, resv_clist, NULL, NULL, "$Revision$"); static void parse_resv(struct Client *source_p, const char *name, - const char *reason, int temp_time, int propagated); + const char *reason, int temp_time, int propagated); static void propagate_resv(struct Client *source_p, const char *target, - int temp_time, const char *name, const char *reason); + int temp_time, const char *name, const char *reason); static void cluster_resv(struct Client *source_p, int temp_time, - const char *name, const char *reason); + const char *name, const char *reason); static void handle_remote_unresv(struct Client *source_p, const char *name); static void remove_resv(struct Client *source_p, const char *name, int propagated); @@ -80,74 +80,67 @@ static void remove_resv(struct Client *source_p, const char *name, int propagate static int mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *name; - const char *reason; - const char *target_server = NULL; - int temp_time; - int loc = 1; - int propagated = ConfigFileEntry.use_propagated_bans; + const char *name; + const char *reason; + const char *target_server = NULL; + int temp_time; + int loc = 1; + int propagated = ConfigFileEntry.use_propagated_bans; - if(!IsOperResv(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv"); - return 0; - } + if(!IsOperResv(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv"); + return 0; + } - /* RESV [time] [ON ] : */ + /* RESV [time] [ON ] : */ - if((temp_time = valid_temp_time(parv[loc])) >= 0) - loc++; - /* we just set temp_time to -1! */ - else - temp_time = 0; + if((temp_time = valid_temp_time(parv[loc])) >= 0) + loc++; + /* we just set temp_time to -1! */ + else + temp_time = 0; - name = parv[loc]; - loc++; + name = parv[loc]; + loc++; - if((parc >= loc + 2) && (irccmp(parv[loc], "ON") == 0)) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + if((parc >= loc + 2) && (irccmp(parv[loc], "ON") == 0)) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - target_server = parv[loc + 1]; - loc += 2; + target_server = parv[loc + 1]; + loc += 2; - /* Set as local-only. */ - propagated = 0; - } + /* Set as local-only. */ + propagated = 0; + } - if(parc <= loc || EmptyString(parv[loc])) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "RESV"); - return 0; - } + if(parc <= loc || EmptyString(parv[loc])) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "RESV"); + return 0; + } - reason = parv[loc]; + reason = parv[loc]; - /* remote resv.. */ - if(target_server) - { - propagate_resv(source_p, target_server, temp_time, name, reason); + /* remote resv.. */ + if(target_server) { + propagate_resv(source_p, target_server, temp_time, name, reason); - if(match(target_server, me.name) == 0) - return 0; - } - else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_resv(source_p, temp_time, name, reason); + if(match(target_server, me.name) == 0) + return 0; + } else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_resv(source_p, temp_time, name, reason); - if(propagated && temp_time == 0) - { - sendto_one_notice(source_p, ":Cannot set a permanent global ban"); - return 0; - } + if(propagated && temp_time == 0) { + sendto_one_notice(source_p, ":Cannot set a permanent global ban"); + return 0; + } - parse_resv(source_p, name, reason, temp_time, propagated); + parse_resv(source_p, name, reason, temp_time, propagated); - return 0; + return 0; } /* ms_resv() @@ -159,30 +152,30 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* parv[0] parv[1] parv[2] parv[3] - * oper target server resv reason - */ - propagate_resv(source_p, parv[1], 0, parv[2], parv[3]); + /* parv[0] parv[1] parv[2] parv[3] + * oper target server resv reason + */ + propagate_resv(source_p, parv[1], 0, parv[2], parv[3]); - if(!match(parv[1], me.name)) - return 0; + if(!match(parv[1], me.name)) + return 0; - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - parse_resv(source_p, parv[2], parv[3], 0, 0); - return 0; + parse_resv(source_p, parv[2], parv[3], 0, 0); + return 0; } static int me_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* time name 0 :reason */ - if(!IsPerson(source_p)) - return 0; + /* time name 0 :reason */ + if(!IsPerson(source_p)) + return 0; - parse_resv(source_p, parv[2], parv[4], atoi(parv[1]), 0); - return 0; + parse_resv(source_p, parv[2], parv[4], atoi(parv[1]), 0); + return 0; } /* parse_resv() @@ -196,238 +189,212 @@ me_resv(struct Client *client_p, struct Client *source_p, int parc, const char * static void parse_resv(struct Client *source_p, const char *name, const char *reason, int temp_time, int propagated) { - struct ConfItem *aconf; + struct ConfItem *aconf; - if(!MyClient(source_p) && - !find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, - (temp_time > 0) ? SHARED_TRESV : SHARED_PRESV)) - return; + if(!MyClient(source_p) && + !find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, + (temp_time > 0) ? SHARED_TRESV : SHARED_PRESV)) + return; - if(IsChannelName(name)) - { - if(hash_find_resv(name)) - { - sendto_one_notice(source_p, - ":A RESV has already been placed on channel: %s", name); - return; - } + if(IsChannelName(name)) { + if(hash_find_resv(name)) { + sendto_one_notice(source_p, + ":A RESV has already been placed on channel: %s", name); + return; + } - if(strlen(name) > CHANNELLEN) - { - sendto_one_notice(source_p, ":Invalid RESV length: %s", name); - return; - } + if(strlen(name) > CHANNELLEN) { + sendto_one_notice(source_p, ":Invalid RESV length: %s", name); + return; + } - if(strchr(reason, '"')) - { - sendto_one_notice(source_p, ":Invalid character '\"' in comment"); - return; - } + if(strchr(reason, '"')) { + sendto_one_notice(source_p, ":Invalid character '\"' in comment"); + return; + } - aconf = make_conf(); - aconf->status = CONF_RESV_CHANNEL; - aconf->port = 0; - aconf->created = rb_current_time(); - aconf->host = rb_strdup(name); - aconf->passwd = rb_strdup(reason); - aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf = make_conf(); + aconf->status = CONF_RESV_CHANNEL; + aconf->port = 0; + aconf->created = rb_current_time(); + aconf->host = rb_strdup(name); + aconf->passwd = rb_strdup(reason); + aconf->info.oper = operhash_add(get_oper_name(source_p)); - if(propagated) - { - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - aconf->hold = rb_current_time() + temp_time; - aconf->lifetime = aconf->hold; - replace_old_ban(aconf); - rb_dlinkAddAlloc(aconf, &prop_bans); + if(propagated) { + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + aconf->hold = rb_current_time() + temp_time; + aconf->lifetime = aconf->hold; + replace_old_ban(aconf); + rb_dlinkAddAlloc(aconf, &prop_bans); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added global %d min. RESV for [%s] [%s]", - get_oper_name(source_p), temp_time / 60, - name, reason); - ilog(L_KLINE, "R %s %d %s %s", - get_oper_name(source_p), temp_time / 60, name, reason); - sendto_one_notice(source_p, ":Added global %d min. RESV [%s]", - temp_time / 60, name); - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN R * %s %lu %d %d * :%s", - source_p->id, aconf->host, - (unsigned long)aconf->created, - (int)(aconf->hold - aconf->created), - (int)(aconf->lifetime - aconf->created), - reason); - } - else if(temp_time > 0) - { - aconf->hold = rb_current_time() + temp_time; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added global %d min. RESV for [%s] [%s]", + get_oper_name(source_p), temp_time / 60, + name, reason); + ilog(L_KLINE, "R %s %d %s %s", + get_oper_name(source_p), temp_time / 60, name, reason); + sendto_one_notice(source_p, ":Added global %d min. RESV [%s]", + temp_time / 60, name); + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN R * %s %lu %d %d * :%s", + source_p->id, aconf->host, + (unsigned long)aconf->created, + (int)(aconf->hold - aconf->created), + (int)(aconf->lifetime - aconf->created), + reason); + } else if(temp_time > 0) { + aconf->hold = rb_current_time() + temp_time; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. RESV for [%s] [%s]", - get_oper_name(source_p), temp_time / 60, - name, reason); - ilog(L_KLINE, "R %s %d %s %s", - get_oper_name(source_p), temp_time / 60, name, reason); - sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]", - temp_time / 60, name); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added RESV for [%s] [%s]", - get_oper_name(source_p), name, reason); - ilog(L_KLINE, "R %s 0 %s %s", - get_oper_name(source_p), name, reason); - sendto_one_notice(source_p, ":Added RESV [%s]", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. RESV for [%s] [%s]", + get_oper_name(source_p), temp_time / 60, + name, reason); + ilog(L_KLINE, "R %s %d %s %s", + get_oper_name(source_p), temp_time / 60, name, reason); + sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]", + temp_time / 60, name); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added RESV for [%s] [%s]", + get_oper_name(source_p), name, reason); + ilog(L_KLINE, "R %s 0 %s %s", + get_oper_name(source_p), name, reason); + sendto_one_notice(source_p, ":Added RESV [%s]", name); - bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); - } + bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); + } - add_to_resv_hash(aconf->host, aconf); - resv_chan_forcepart(aconf->host, aconf->passwd, temp_time); - } - else if(clean_resv_nick(name)) - { - if(strlen(name) > NICKLEN * 2) - { - sendto_one_notice(source_p, ":Invalid RESV length: %s", name); - return; - } + add_to_resv_hash(aconf->host, aconf); + resv_chan_forcepart(aconf->host, aconf->passwd, temp_time); + } else if(clean_resv_nick(name)) { + if(strlen(name) > NICKLEN * 2) { + sendto_one_notice(source_p, ":Invalid RESV length: %s", name); + return; + } - if(strchr(reason, '"')) - { - sendto_one_notice(source_p, ":Invalid character '\"' in comment"); - return; - } + if(strchr(reason, '"')) { + sendto_one_notice(source_p, ":Invalid character '\"' in comment"); + return; + } - if(!valid_wild_card_simple(name)) - { - sendto_one_notice(source_p, - ":Please include at least %d non-wildcard " - "characters with the resv", - ConfigFileEntry.min_nonwildcard_simple); - return; - } + if(!valid_wild_card_simple(name)) { + sendto_one_notice(source_p, + ":Please include at least %d non-wildcard " + "characters with the resv", + ConfigFileEntry.min_nonwildcard_simple); + return; + } - if(find_nick_resv_mask(name)) - { - sendto_one_notice(source_p, - ":A RESV has already been placed on nick: %s", name); - return; - } + if(find_nick_resv_mask(name)) { + sendto_one_notice(source_p, + ":A RESV has already been placed on nick: %s", name); + return; + } - aconf = make_conf(); - aconf->status = CONF_RESV_NICK; - aconf->port = 0; - aconf->created = rb_current_time(); - aconf->host = rb_strdup(name); - aconf->passwd = rb_strdup(reason); - aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf = make_conf(); + aconf->status = CONF_RESV_NICK; + aconf->port = 0; + aconf->created = rb_current_time(); + aconf->host = rb_strdup(name); + aconf->passwd = rb_strdup(reason); + aconf->info.oper = operhash_add(get_oper_name(source_p)); - if(propagated) - { - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - aconf->hold = rb_current_time() + temp_time; - aconf->lifetime = aconf->hold; - replace_old_ban(aconf); - rb_dlinkAddAlloc(aconf, &prop_bans); + if(propagated) { + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + aconf->hold = rb_current_time() + temp_time; + aconf->lifetime = aconf->hold; + replace_old_ban(aconf); + rb_dlinkAddAlloc(aconf, &prop_bans); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added global %d min. RESV for [%s] [%s]", - get_oper_name(source_p), temp_time / 60, - name, reason); - ilog(L_KLINE, "R %s %d %s %s", - get_oper_name(source_p), temp_time / 60, name, reason); - sendto_one_notice(source_p, ":Added global %d min. RESV [%s]", - temp_time / 60, name); - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN R * %s %lu %d %d * :%s", - source_p->id, aconf->host, - (unsigned long)aconf->created, - (int)(aconf->hold - aconf->created), - (int)(aconf->lifetime - aconf->created), - reason); - } - else if(temp_time > 0) - { - aconf->hold = rb_current_time() + temp_time; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added global %d min. RESV for [%s] [%s]", + get_oper_name(source_p), temp_time / 60, + name, reason); + ilog(L_KLINE, "R %s %d %s %s", + get_oper_name(source_p), temp_time / 60, name, reason); + sendto_one_notice(source_p, ":Added global %d min. RESV [%s]", + temp_time / 60, name); + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN R * %s %lu %d %d * :%s", + source_p->id, aconf->host, + (unsigned long)aconf->created, + (int)(aconf->hold - aconf->created), + (int)(aconf->lifetime - aconf->created), + reason); + } else if(temp_time > 0) { + aconf->hold = rb_current_time() + temp_time; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. RESV for [%s] [%s]", - get_oper_name(source_p), temp_time / 60, - name, reason); - ilog(L_KLINE, "R %s %d %s %s", - get_oper_name(source_p), temp_time / 60, name, reason); - sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]", - temp_time / 60, name); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added RESV for [%s] [%s]", - get_oper_name(source_p), name, reason); - ilog(L_KLINE, "R %s 0 %s %s", - get_oper_name(source_p), name, reason); - sendto_one_notice(source_p, ":Added RESV [%s]", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. RESV for [%s] [%s]", + get_oper_name(source_p), temp_time / 60, + name, reason); + ilog(L_KLINE, "R %s %d %s %s", + get_oper_name(source_p), temp_time / 60, name, reason); + sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]", + temp_time / 60, name); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added RESV for [%s] [%s]", + get_oper_name(source_p), name, reason); + ilog(L_KLINE, "R %s 0 %s %s", + get_oper_name(source_p), name, reason); + sendto_one_notice(source_p, ":Added RESV [%s]", name); - bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); - } + bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); + } - rb_dlinkAddAlloc(aconf, &resv_conf_list); - } - else - sendto_one_notice(source_p, ":You have specified an invalid resv: [%s]", name); + rb_dlinkAddAlloc(aconf, &resv_conf_list); + } else + sendto_one_notice(source_p, ":You have specified an invalid resv: [%s]", name); } static void propagate_resv(struct Client *source_p, const char *target, - int temp_time, const char *name, const char *reason) + int temp_time, const char *name, const char *reason) { - if(!temp_time) - { - sendto_match_servs(source_p, target, - CAP_CLUSTER, NOCAPS, "RESV %s %s :%s", target, name, reason); - sendto_match_servs(source_p, target, - CAP_ENCAP, CAP_CLUSTER, - "ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason); - } - else - sendto_match_servs(source_p, target, - CAP_ENCAP, NOCAPS, - "ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason); + if(!temp_time) { + sendto_match_servs(source_p, target, + CAP_CLUSTER, NOCAPS, "RESV %s %s :%s", target, name, reason); + sendto_match_servs(source_p, target, + CAP_ENCAP, CAP_CLUSTER, + "ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason); + } else + sendto_match_servs(source_p, target, + CAP_ENCAP, NOCAPS, + "ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason); } static void cluster_resv(struct Client *source_p, int temp_time, const char *name, const char *reason) { - struct remote_conf *shared_p; - rb_dlink_node *ptr; + struct remote_conf *shared_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, cluster_conf_list.head) - { - shared_p = ptr->data; + RB_DLINK_FOREACH(ptr, cluster_conf_list.head) { + shared_p = ptr->data; - /* old protocol cant handle temps, and we dont really want - * to convert them to perm.. --fl - */ - if(!temp_time) - { - if(!(shared_p->flags & SHARED_PRESV)) - continue; + /* old protocol cant handle temps, and we dont really want + * to convert them to perm.. --fl + */ + if(!temp_time) { + if(!(shared_p->flags & SHARED_PRESV)) + continue; - sendto_match_servs(source_p, shared_p->server, - CAP_CLUSTER, NOCAPS, - "RESV %s %s :%s", shared_p->server, name, reason); - sendto_match_servs(source_p, shared_p->server, - CAP_ENCAP, CAP_CLUSTER, - "ENCAP %s RESV 0 %s 0 :%s", - shared_p->server, name, reason); - } - else if(shared_p->flags & SHARED_TRESV) - sendto_match_servs(source_p, shared_p->server, - CAP_ENCAP, NOCAPS, - "ENCAP %s RESV %d %s 0 :%s", - shared_p->server, temp_time, name, reason); - } + sendto_match_servs(source_p, shared_p->server, + CAP_CLUSTER, NOCAPS, + "RESV %s %s :%s", shared_p->server, name, reason); + sendto_match_servs(source_p, shared_p->server, + CAP_ENCAP, CAP_CLUSTER, + "ENCAP %s RESV 0 %s 0 :%s", + shared_p->server, name, reason); + } else if(shared_p->flags & SHARED_TRESV) + sendto_match_servs(source_p, shared_p->server, + CAP_ENCAP, NOCAPS, + "ENCAP %s RESV %d %s 0 :%s", + shared_p->server, temp_time, name, reason); + } } @@ -439,38 +406,35 @@ cluster_resv(struct Client *source_p, int temp_time, const char *name, const cha static int mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int propagated = 1; + int propagated = 1; - if(!IsOperResv(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv"); - return 0; - } + if(!IsOperResv(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv"); + return 0; + } - if((parc == 4) && (irccmp(parv[2], "ON") == 0)) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + if((parc == 4) && (irccmp(parv[2], "ON") == 0)) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - propagate_generic(source_p, "UNRESV", parv[3], CAP_CLUSTER, "%s", parv[1]); + propagate_generic(source_p, "UNRESV", parv[3], CAP_CLUSTER, "%s", parv[1]); - if(match(parv[3], me.name) == 0) - return 0; + if(match(parv[3], me.name) == 0) + return 0; - propagated = 0; - } + propagated = 0; + } #if 0 - else if(rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", parv[1]); + else if(rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", parv[1]); #endif - /* cluster{} moved to remove_resv */ + /* cluster{} moved to remove_resv */ - remove_resv(source_p, parv[1], propagated); - return 0; + remove_resv(source_p, parv[1], propagated); + return 0; } /* ms_unresv() @@ -481,188 +445,170 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char static int ms_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* parv[0] parv[1] parv[2] - * oper target server resv to remove - */ - propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER, "%s", parv[2]); + /* parv[0] parv[1] parv[2] + * oper target server resv to remove + */ + propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER, "%s", parv[2]); - if(!match(parv[1], me.name)) - return 0; + if(!match(parv[1], me.name)) + return 0; - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - handle_remote_unresv(source_p, parv[2]); - return 0; + handle_remote_unresv(source_p, parv[2]); + return 0; } static int me_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* name */ - if(!IsPerson(source_p)) - return 0; + /* name */ + if(!IsPerson(source_p)) + return 0; - handle_remote_unresv(source_p, parv[1]); - return 0; + handle_remote_unresv(source_p, parv[1]); + return 0; } static void handle_remote_unresv(struct Client *source_p, const char *name) { - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, SHARED_UNRESV)) - return; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, SHARED_UNRESV)) + return; - remove_resv(source_p, name, 0); + remove_resv(source_p, name, 0); - return; + return; } static void remove_resv(struct Client *source_p, const char *name, int propagated) { - struct ConfItem *aconf = NULL; - rb_dlink_node *ptr; + struct ConfItem *aconf = NULL; + rb_dlink_node *ptr; - if(IsChannelName(name)) - { - if((aconf = hash_find_resv(name)) == NULL) - { - if(propagated && rb_dlink_list_length(&cluster_conf_list)) - cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); + if(IsChannelName(name)) { + if((aconf = hash_find_resv(name)) == NULL) { + if(propagated && rb_dlink_list_length(&cluster_conf_list)) + cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); - sendto_one_notice(source_p, ":No RESV for %s", name); - return; - } + sendto_one_notice(source_p, ":No RESV for %s", name); + return; + } - if(aconf->lifetime) - { - if(!propagated) - { - sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name); - return; - } - ptr = rb_dlinkFind(aconf, &prop_bans); - if(ptr == NULL) - return; - sendto_one_notice(source_p, ":RESV for [%s] is removed", name); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the global RESV for: [%s]", - get_oper_name(source_p), name); - ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); - if(aconf->created < rb_current_time()) - aconf->created = rb_current_time(); - else - aconf->created++; - aconf->hold = aconf->created; - operhash_delete(aconf->info.oper); - aconf->info.oper = operhash_add(get_oper_name(source_p)); - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN R * %s %lu %d %d * :*", - source_p->id, aconf->host, - (unsigned long)aconf->created, - 0, - (int)(aconf->lifetime - aconf->created)); - deactivate_conf(aconf, ptr); - return; - } - else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); + if(aconf->lifetime) { + if(!propagated) { + sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name); + return; + } + ptr = rb_dlinkFind(aconf, &prop_bans); + if(ptr == NULL) + return; + sendto_one_notice(source_p, ":RESV for [%s] is removed", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the global RESV for: [%s]", + get_oper_name(source_p), name); + ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); + if(aconf->created < rb_current_time()) + aconf->created = rb_current_time(); + else + aconf->created++; + aconf->hold = aconf->created; + operhash_delete(aconf->info.oper); + aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN R * %s %lu %d %d * :*", + source_p->id, aconf->host, + (unsigned long)aconf->created, + 0, + (int)(aconf->lifetime - aconf->created)); + deactivate_conf(aconf, ptr); + return; + } else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); - sendto_one_notice(source_p, ":RESV for [%s] is removed", name); - ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); - if(!aconf->hold) - { - bandb_del(BANDB_RESV, aconf->host, NULL); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the RESV for: [%s]", - get_oper_name(source_p), name); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the temporary RESV for: [%s]", - get_oper_name(source_p), name); - } - del_from_resv_hash(name, aconf); - } - else - { - RB_DLINK_FOREACH(ptr, resv_conf_list.head) - { - aconf = ptr->data; + sendto_one_notice(source_p, ":RESV for [%s] is removed", name); + ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); + if(!aconf->hold) { + bandb_del(BANDB_RESV, aconf->host, NULL); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the RESV for: [%s]", + get_oper_name(source_p), name); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the temporary RESV for: [%s]", + get_oper_name(source_p), name); + } + del_from_resv_hash(name, aconf); + } else { + RB_DLINK_FOREACH(ptr, resv_conf_list.head) { + aconf = ptr->data; - if(irccmp(aconf->host, name)) - aconf = NULL; - else - break; - } + if(irccmp(aconf->host, name)) + aconf = NULL; + else + break; + } - if(aconf == NULL) - { - if(propagated && rb_dlink_list_length(&cluster_conf_list)) - cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); + if(aconf == NULL) { + if(propagated && rb_dlink_list_length(&cluster_conf_list)) + cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); - sendto_one_notice(source_p, ":No RESV for %s", name); - return; - } + sendto_one_notice(source_p, ":No RESV for %s", name); + return; + } - if(aconf->lifetime) - { - if(!propagated) - { - sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name); - return; - } - ptr = rb_dlinkFind(aconf, &prop_bans); - if(ptr == NULL) - return; - sendto_one_notice(source_p, ":RESV for [%s] is removed", name); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the global RESV for: [%s]", - get_oper_name(source_p), name); - ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); - if(aconf->created < rb_current_time()) - aconf->created = rb_current_time(); - else - aconf->created++; - aconf->hold = aconf->created; - operhash_delete(aconf->info.oper); - aconf->info.oper = operhash_add(get_oper_name(source_p)); - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN R * %s %lu %d %d * :*", - source_p->id, aconf->host, - (unsigned long)aconf->created, - 0, - (int)(aconf->lifetime - aconf->created)); - deactivate_conf(aconf, ptr); - return; - } - else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); + if(aconf->lifetime) { + if(!propagated) { + sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name); + return; + } + ptr = rb_dlinkFind(aconf, &prop_bans); + if(ptr == NULL) + return; + sendto_one_notice(source_p, ":RESV for [%s] is removed", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the global RESV for: [%s]", + get_oper_name(source_p), name); + ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); + if(aconf->created < rb_current_time()) + aconf->created = rb_current_time(); + else + aconf->created++; + aconf->hold = aconf->created; + operhash_delete(aconf->info.oper); + aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN R * %s %lu %d %d * :*", + source_p->id, aconf->host, + (unsigned long)aconf->created, + 0, + (int)(aconf->lifetime - aconf->created)); + deactivate_conf(aconf, ptr); + return; + } else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", name); - sendto_one_notice(source_p, ":RESV for [%s] is removed", name); - ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); - if(!aconf->hold) - { - bandb_del(BANDB_RESV, aconf->host, NULL); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the RESV for: [%s]", - get_oper_name(source_p), name); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the temporary RESV for: [%s]", - get_oper_name(source_p), name); - } - /* already have ptr from the loop above.. */ - rb_dlinkDestroy(ptr, &resv_conf_list); - } - free_conf(aconf); + sendto_one_notice(source_p, ":RESV for [%s] is removed", name); + ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); + if(!aconf->hold) { + bandb_del(BANDB_RESV, aconf->host, NULL); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the RESV for: [%s]", + get_oper_name(source_p), name); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the temporary RESV for: [%s]", + get_oper_name(source_p), name); + } + /* already have ptr from the loop above.. */ + rb_dlinkDestroy(ptr, &resv_conf_list); + } + free_conf(aconf); - return; + return; } diff --git a/modules/m_sasl.c b/modules/m_sasl.c index 5f8f443..3188301 100644 --- a/modules/m_sasl.c +++ b/modules/m_sasl.c @@ -48,147 +48,141 @@ static void abort_sasl(struct Client *); static void abort_sasl_exit(hook_data_client_exit *); struct Message authenticate_msgtab = { - "AUTHENTICATE", 0, 0, 0, MFLG_SLOW, - {{mr_authenticate, 2}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} + "AUTHENTICATE", 0, 0, 0, MFLG_SLOW, + {{mr_authenticate, 2}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} }; struct Message sasl_msgtab = { - "SASL", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_sasl, 5}, mg_ignore} + "SASL", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_sasl, 5}, mg_ignore} }; -mapi_clist_av1 sasl_clist[] = { - &authenticate_msgtab, &sasl_msgtab, NULL +mapi_clist_av1 sasl_clist[] = { + &authenticate_msgtab, &sasl_msgtab, NULL }; mapi_hfn_list_av1 sasl_hfnlist[] = { - { "new_local_user", (hookfn) abort_sasl }, - { "client_exit", (hookfn) abort_sasl_exit }, - { NULL, NULL } + { "new_local_user", (hookfn) abort_sasl }, + { "client_exit", (hookfn) abort_sasl_exit }, + { NULL, NULL } }; DECLARE_MODULE_AV1(sasl, NULL, NULL, sasl_clist, NULL, sasl_hfnlist, "$Revision: 1409 $"); static int mr_authenticate(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *agent_p = NULL; + struct Client *agent_p = NULL; - /* They really should use CAP for their own sake. */ - if(!IsCapable(source_p, CLICAP_SASL)) - return 0; + /* They really should use CAP for their own sake. */ + if(!IsCapable(source_p, CLICAP_SASL)) + return 0; - if (strlen(client_p->id) == 3) - { - exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); - return 0; - } + if (strlen(client_p->id) == 3) { + exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); + return 0; + } - if(source_p->preClient->sasl_complete) - { - sendto_one(source_p, form_str(ERR_SASLALREADY), me.name, EmptyString(source_p->name) ? "*" : source_p->name); - return 0; - } + if(source_p->preClient->sasl_complete) { + sendto_one(source_p, form_str(ERR_SASLALREADY), me.name, EmptyString(source_p->name) ? "*" : source_p->name); + return 0; + } - if(strlen(parv[1]) > 400) - { - sendto_one(source_p, form_str(ERR_SASLTOOLONG), me.name, EmptyString(source_p->name) ? "*" : source_p->name); - return 0; - } + if(strlen(parv[1]) > 400) { + sendto_one(source_p, form_str(ERR_SASLTOOLONG), me.name, EmptyString(source_p->name) ? "*" : source_p->name); + return 0; + } - if(!*source_p->id) - { - /* Allocate a UID. */ - strcpy(source_p->id, generate_uid()); - add_to_id_hash(source_p->id, source_p); - } + if(!*source_p->id) { + /* Allocate a UID. */ + strcpy(source_p->id, generate_uid()); + add_to_id_hash(source_p->id, source_p); + } - if(*source_p->preClient->sasl_agent) - agent_p = find_id(source_p->preClient->sasl_agent); + if(*source_p->preClient->sasl_agent) + agent_p = find_id(source_p->preClient->sasl_agent); - if(agent_p == NULL) - sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * S %s", me.id, - source_p->id, parv[1]); - else - sendto_one(agent_p, ":%s ENCAP %s SASL %s %s C %s", me.id, agent_p->servptr->name, - source_p->id, agent_p->id, parv[1]); - source_p->preClient->sasl_out++; + if(agent_p == NULL) + sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * S %s", me.id, + source_p->id, parv[1]); + else + sendto_one(agent_p, ":%s ENCAP %s SASL %s %s C %s", me.id, agent_p->servptr->name, + source_p->id, agent_p->id, parv[1]); + source_p->preClient->sasl_out++; - return 0; + return 0; } static int me_sasl(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p, *agent_p; + struct Client *target_p, *agent_p; - /* Let propagate if not addressed to us, or if broadcast. - * Only SASL agents can answer global requests. - */ - if(strncmp(parv[2], me.id, 3)) - return 0; + /* Let propagate if not addressed to us, or if broadcast. + * Only SASL agents can answer global requests. + */ + if(strncmp(parv[2], me.id, 3)) + return 0; - if((target_p = find_id(parv[2])) == NULL) - return 0; + if((target_p = find_id(parv[2])) == NULL) + return 0; - if(target_p->preClient == NULL) - return 0; + if(target_p->preClient == NULL) + return 0; - if((agent_p = find_id(parv[1])) == NULL) - return 0; + if((agent_p = find_id(parv[1])) == NULL) + return 0; - if(source_p != agent_p->servptr) /* WTF?! */ - return 0; + if(source_p != agent_p->servptr) /* WTF?! */ + return 0; - /* We only accept messages from SASL agents; these must have umode +S - * (so the server must be listed in a service{} block). - */ - if(!IsService(agent_p)) - return 0; + /* We only accept messages from SASL agents; these must have umode +S + * (so the server must be listed in a service{} block). + */ + if(!IsService(agent_p)) + return 0; - /* Reject if someone has already answered. */ - if(*target_p->preClient->sasl_agent && strncmp(parv[1], target_p->preClient->sasl_agent, IDLEN)) - return 0; - else if(!*target_p->preClient->sasl_agent) - rb_strlcpy(target_p->preClient->sasl_agent, parv[1], IDLEN); + /* Reject if someone has already answered. */ + if(*target_p->preClient->sasl_agent && strncmp(parv[1], target_p->preClient->sasl_agent, IDLEN)) + return 0; + else if(!*target_p->preClient->sasl_agent) + rb_strlcpy(target_p->preClient->sasl_agent, parv[1], IDLEN); - if(*parv[3] == 'C') - sendto_one(target_p, "AUTHENTICATE %s", parv[4]); - else if(*parv[3] == 'D') - { - if(*parv[4] == 'F') - sendto_one(target_p, form_str(ERR_SASLFAIL), me.name, EmptyString(target_p->name) ? "*" : target_p->name); - else if(*parv[4] == 'S') { - sendto_one(target_p, form_str(RPL_SASLSUCCESS), me.name, EmptyString(target_p->name) ? "*" : target_p->name); - target_p->preClient->sasl_complete = 1; - ServerStats.is_ssuc++; - //server_auth_sasl(target_p); - } - *target_p->preClient->sasl_agent = '\0'; /* Blank the stored agent so someone else can answer */ - } - - return 0; + if(*parv[3] == 'C') + sendto_one(target_p, "AUTHENTICATE %s", parv[4]); + else if(*parv[3] == 'D') { + if(*parv[4] == 'F') + sendto_one(target_p, form_str(ERR_SASLFAIL), me.name, EmptyString(target_p->name) ? "*" : target_p->name); + else if(*parv[4] == 'S') { + sendto_one(target_p, form_str(RPL_SASLSUCCESS), me.name, EmptyString(target_p->name) ? "*" : target_p->name); + target_p->preClient->sasl_complete = 1; + ServerStats.is_ssuc++; + //server_auth_sasl(target_p); + } + *target_p->preClient->sasl_agent = '\0'; /* Blank the stored agent so someone else can answer */ + } + + return 0; } static int server_auth_sasl(struct Client *client_p) { - char *auth_user = NULL; + char *auth_user = NULL; - if (client_p->localClient->auth_user != NULL) - { - memset(client_p->localClient->auth_user, 0, - strlen(client_p->localClient->auth_user)); - rb_free(client_p->localClient->auth_user); - client_p->localClient->auth_user = NULL; - } + if (client_p->localClient->auth_user != NULL) { + memset(client_p->localClient->auth_user, 0, + strlen(client_p->localClient->auth_user)); + rb_free(client_p->localClient->auth_user); + client_p->localClient->auth_user = NULL; + } - if (client_p->user != NULL && client_p->user->suser != NULL) - auth_user = rb_strndup(client_p->user->suser, PASSWDLEN); + if (client_p->user != NULL && client_p->user->suser != NULL) + auth_user = rb_strndup(client_p->user->suser, PASSWDLEN); - if (auth_user != NULL) - client_p->localClient->auth_user = rb_strndup(auth_user, PASSWDLEN); + if (auth_user != NULL) + client_p->localClient->auth_user = rb_strndup(auth_user, PASSWDLEN); - return 0; + return 0; } /* If the client never finished authenticating but is @@ -197,34 +191,32 @@ static int server_auth_sasl(struct Client *client_p) static void abort_sasl(struct Client *data) { - if(data->preClient->sasl_out == 0 || data->preClient->sasl_complete) - return; + if(data->preClient->sasl_out == 0 || data->preClient->sasl_complete) + return; - data->preClient->sasl_out = data->preClient->sasl_complete = 0; - ServerStats.is_sbad++; + data->preClient->sasl_out = data->preClient->sasl_complete = 0; + ServerStats.is_sbad++; - if(!IsClosing(data)) - sendto_one(data, form_str(ERR_SASLABORTED), me.name, EmptyString(data->name) ? "*" : data->name); + if(!IsClosing(data)) + sendto_one(data, form_str(ERR_SASLABORTED), me.name, EmptyString(data->name) ? "*" : data->name); - if(*data->preClient->sasl_agent) - { - struct Client *agent_p = find_id(data->preClient->sasl_agent); - if(agent_p) - { - sendto_one(agent_p, ":%s ENCAP %s SASL %s %s D A", me.id, agent_p->servptr->name, - data->id, agent_p->id); - return; - } - } + if(*data->preClient->sasl_agent) { + struct Client *agent_p = find_id(data->preClient->sasl_agent); + if(agent_p) { + sendto_one(agent_p, ":%s ENCAP %s SASL %s %s D A", me.id, agent_p->servptr->name, + data->id, agent_p->id); + return; + } + } - sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * D A", me.id, - data->id); + sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * D A", me.id, + data->id); } static void abort_sasl_exit(hook_data_client_exit *data) { - if (data->target->preClient) - abort_sasl(data->target); + if (data->target->preClient) + abort_sasl(data->target); } diff --git a/modules/m_scan.c b/modules/m_scan.c index 28154d8..30bbce5 100644 --- a/modules/m_scan.c +++ b/modules/m_scan.c @@ -54,23 +54,23 @@ static int scan_umodes(struct Client *, struct Client *, int, const char **); /*static int scan_cmodes(struct Client *, struct Client *, int, const char **);*/ struct Message scan_msgtab = { - "SCAN", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_scan, 2}} + "SCAN", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_scan, 2}} }; mapi_clist_av1 scan_clist[] = { &scan_msgtab, NULL }; DECLARE_MODULE_AV1(scan, NULL, NULL, scan_clist, NULL, NULL, "$Revision: 1853 $"); -typedef int (*scan_handler)(struct Client *, struct Client *, int, - const char **); +typedef int (*scan_handler)(struct Client *, struct Client *, int, + const char **); struct scan_cmd { - const char *name; - int operlevel; - scan_handler handler; + const char *name; + int operlevel; + scan_handler handler; } scan_cmds[] = { - {"UMODES", L_OPER, scan_umodes}, - {NULL, 0, NULL} + {"UMODES", L_OPER, scan_umodes}, + {NULL, 0, NULL} }; static const char *empty_sockhost = "255.255.255.255"; @@ -82,198 +82,176 @@ static const char *spoofed_sockhost = "0"; * parv[2] = [target] */ static int -mo_scan(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]) +mo_scan(struct Client *client_p, struct Client *source_p, int parc, + const char *parv[]) { - struct scan_cmd *sptr; + struct scan_cmd *sptr; - for (sptr = scan_cmds; sptr->name != NULL; sptr++) - { - if (!irccmp(sptr->name, parv[1])) - { - if (sptr->operlevel == L_ADMIN && - !IsOperAdmin(source_p)) - return -1; - else - return sptr->handler(client_p, source_p, parc, parv); - } - } + for (sptr = scan_cmds; sptr->name != NULL; sptr++) { + if (!irccmp(sptr->name, parv[1])) { + if (sptr->operlevel == L_ADMIN && + !IsOperAdmin(source_p)) + return -1; + else + return sptr->handler(client_p, source_p, parc, parv); + } + } - sendto_one_notice(source_p, ":*** %s is not an implemented SCAN target", - parv[1]); + sendto_one_notice(source_p, ":*** %s is not an implemented SCAN target", + parv[1]); - return 0; + return 0; } static int scan_umodes(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]) + const char *parv[]) { - unsigned int allowed_umodes = 0, disallowed_umodes = 0; - int what = MODE_ADD; - int mode; - int list_users = YES; - int list_max = 500; - int list_count = 0, count = 0; - const char *mask = NULL; - const char *c; - struct Client *target_p; - rb_dlink_list *target_list = &lclient_list; /* local clients only by default */ - rb_dlink_node *tn; - int i; - const char *sockhost; - char buf[512]; + unsigned int allowed_umodes = 0, disallowed_umodes = 0; + int what = MODE_ADD; + int mode; + int list_users = YES; + int list_max = 500; + int list_count = 0, count = 0; + const char *mask = NULL; + const char *c; + struct Client *target_p; + rb_dlink_list *target_list = &lclient_list; /* local clients only by default */ + rb_dlink_node *tn; + int i; + const char *sockhost; + char buf[512]; - if (parc < 3) - { - if (MyClient(source_p)) - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "SCAN UMODES"); + if (parc < 3) { + if (MyClient(source_p)) + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "SCAN UMODES"); - return -1; - } + return -1; + } - if (parv[2][0] != '+' && parv[2][0] != '-') - { - sendto_one_notice(source_p, ":SCAN UMODES: umodes parameter must start with '+' or '-'"); - return -1; - } + if (parv[2][0] != '+' && parv[2][0] != '-') { + sendto_one_notice(source_p, ":SCAN UMODES: umodes parameter must start with '+' or '-'"); + return -1; + } - for (c = parv[2]; *c; c++) - { - switch(*c) - { - case '+': - what = MODE_ADD; - break; - case '-': - what = MODE_DEL; - break; - default: - if ((mode = user_modes[(unsigned char) *c]) != 0) - { - if (what == MODE_ADD) - allowed_umodes |= mode; - else - disallowed_umodes |= mode; - } - } - } + for (c = parv[2]; *c; c++) { + switch(*c) { + case '+': + what = MODE_ADD; + break; + case '-': + what = MODE_DEL; + break; + default: + if ((mode = user_modes[(unsigned char) *c]) != 0) { + if (what == MODE_ADD) + allowed_umodes |= mode; + else + disallowed_umodes |= mode; + } + } + } - for (i = 3; i < parc; i++) - { - if (!irccmp(parv[i], "no-list")) - list_users = NO; - else if (!irccmp(parv[i], "list")) - list_users = YES; - else if (!irccmp(parv[i], "global")) - target_list = &global_client_list; - else if (i < (parc - 1)) - { - if (!irccmp(parv[i], "list-max")) - list_max = atoi(parv[++i]); - else if (!irccmp(parv[i], "mask")) - mask = parv[++i]; - else - { - sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters"); - return -1; - } - } - else - { - sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters"); - return -1; - } - } - if (target_list == &global_client_list && list_users) - { - if (IsOperSpy(source_p)) - { - if (!ConfigFileEntry.operspy_dont_care_user_info) - { - rb_strlcpy(buf, "UMODES", sizeof buf); - for (i = 2; i < parc; i++) - { - rb_strlcat(buf, " ", sizeof buf); - rb_strlcat(buf, parv[i], sizeof buf); - } - report_operspy(source_p, "SCAN", buf); - } - } - else - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "oper_spy"); - return -1; - } - } + for (i = 3; i < parc; i++) { + if (!irccmp(parv[i], "no-list")) + list_users = NO; + else if (!irccmp(parv[i], "list")) + list_users = YES; + else if (!irccmp(parv[i], "global")) + target_list = &global_client_list; + else if (i < (parc - 1)) { + if (!irccmp(parv[i], "list-max")) + list_max = atoi(parv[++i]); + else if (!irccmp(parv[i], "mask")) + mask = parv[++i]; + else { + sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters"); + return -1; + } + } else { + sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters"); + return -1; + } + } + if (target_list == &global_client_list && list_users) { + if (IsOperSpy(source_p)) { + if (!ConfigFileEntry.operspy_dont_care_user_info) { + rb_strlcpy(buf, "UMODES", sizeof buf); + for (i = 2; i < parc; i++) { + rb_strlcat(buf, " ", sizeof buf); + rb_strlcat(buf, parv[i], sizeof buf); + } + report_operspy(source_p, "SCAN", buf); + } + } else { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "oper_spy"); + return -1; + } + } - RB_DLINK_FOREACH(tn, target_list->head) - { - unsigned int working_umodes = 0; - char maskbuf[BUFSIZE]; + RB_DLINK_FOREACH(tn, target_list->head) { + unsigned int working_umodes = 0; + char maskbuf[BUFSIZE]; - target_p = tn->data; + target_p = tn->data; - if (!IsClient(target_p)) - continue; + if (!IsClient(target_p)) + continue; - if(EmptyString(target_p->sockhost)) - sockhost = empty_sockhost; - else if(!show_ip(source_p, target_p)) - sockhost = spoofed_sockhost; - else - sockhost = target_p->sockhost; + if(EmptyString(target_p->sockhost)) + sockhost = empty_sockhost; + else if(!show_ip(source_p, target_p)) + sockhost = spoofed_sockhost; + else + sockhost = target_p->sockhost; - working_umodes = target_p->umodes; + working_umodes = target_p->umodes; - /* require that we have the allowed umodes... */ - if ((working_umodes & allowed_umodes) != allowed_umodes) - continue; + /* require that we have the allowed umodes... */ + if ((working_umodes & allowed_umodes) != allowed_umodes) + continue; - /* require that we have NONE of the disallowed ones */ - if ((working_umodes & disallowed_umodes) != 0) - continue; + /* require that we have NONE of the disallowed ones */ + if ((working_umodes & disallowed_umodes) != 0) + continue; - if (mask != NULL) - { - rb_snprintf(maskbuf, BUFSIZE, "%s!%s@%s", - target_p->name, target_p->username, target_p->host); + if (mask != NULL) { + rb_snprintf(maskbuf, BUFSIZE, "%s!%s@%s", + target_p->name, target_p->username, target_p->host); - if (!match(mask, maskbuf)) - continue; - } + if (!match(mask, maskbuf)) + continue; + } - if (list_users && (!list_max || (list_count < list_max))) - { - char modebuf[BUFSIZE]; - char *m = modebuf; + if (list_users && (!list_max || (list_count < list_max))) { + char modebuf[BUFSIZE]; + char *m = modebuf; - *m++ = '+'; + *m++ = '+'; - for (i = 0; i < 128; i++) - { - if (target_p->umodes & user_modes[i]) - *m++ = (char) i; - } + for (i = 0; i < 128; i++) { + if (target_p->umodes & user_modes[i]) + *m++ = (char) i; + } - *m++ = '\0'; + *m++ = '\0'; - list_count++; + list_count++; - sendto_one_numeric(source_p, RPL_SCANUMODES, - form_str(RPL_SCANUMODES), - target_p->name, target_p->username, - target_p->host, sockhost, - target_p->servptr->name, modebuf, - target_p->info); - } - count++; - } + sendto_one_numeric(source_p, RPL_SCANUMODES, + form_str(RPL_SCANUMODES), + target_p->name, target_p->username, + target_p->host, sockhost, + target_p->servptr->name, modebuf, + target_p->info); + } + count++; + } - sendto_one_numeric(source_p, RPL_SCANMATCHED, - form_str(RPL_SCANMATCHED), count); + sendto_one_numeric(source_p, RPL_SCANMATCHED, + form_str(RPL_SCANMATCHED), count); - return 0; + return 0; } diff --git a/modules/m_services.c b/modules/m_services.c index ecee113..94c7df1 100644 --- a/modules/m_services.c +++ b/modules/m_services.c @@ -57,188 +57,186 @@ static void h_svc_whois(hook_data_client *); static void h_svc_stats(hook_data_int *); struct Message su_msgtab = { - "SU", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_su, 2}, mg_ignore} + "SU", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_su, 2}, mg_ignore} }; struct Message login_msgtab = { - "LOGIN", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_login, 2}, mg_ignore} + "LOGIN", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_login, 2}, mg_ignore} }; struct Message rsfnc_msgtab = { - "RSFNC", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_rsfnc, 4}, mg_ignore} + "RSFNC", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_rsfnc, 4}, mg_ignore} }; struct Message nickdelay_msgtab = { - "NICKDELAY", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_ignore, mg_ignore, mg_ignore, {me_nickdelay, 3}, mg_ignore} + "NICKDELAY", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_ignore, mg_ignore, mg_ignore, {me_nickdelay, 3}, mg_ignore} }; -mapi_clist_av1 services_clist[] = { - &su_msgtab, &login_msgtab, &rsfnc_msgtab, &nickdelay_msgtab, NULL +mapi_clist_av1 services_clist[] = { + &su_msgtab, &login_msgtab, &rsfnc_msgtab, &nickdelay_msgtab, NULL }; mapi_hfn_list_av1 services_hfnlist[] = { - { "doing_stats", (hookfn) h_svc_stats }, - { "doing_whois", (hookfn) h_svc_whois }, - { "doing_whois_global", (hookfn) h_svc_whois }, - { "server_introduced", (hookfn) h_svc_server_introduced }, - { NULL, NULL } + { "doing_stats", (hookfn) h_svc_stats }, + { "doing_whois", (hookfn) h_svc_whois }, + { "doing_whois_global", (hookfn) h_svc_whois }, + { "server_introduced", (hookfn) h_svc_server_introduced }, + { NULL, NULL } }; DECLARE_MODULE_AV1(services, NULL, NULL, services_clist, NULL, services_hfnlist, "$Revision: 1907 $"); static int me_su(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - if(!(source_p->flags & FLAGS_SERVICE)) - return 0; + if(!(source_p->flags & FLAGS_SERVICE)) + return 0; - if((target_p = find_client(parv[1])) == NULL) - return 0; + if((target_p = find_client(parv[1])) == NULL) + return 0; - if(!target_p->user) - return 0; + if(!target_p->user) + return 0; - if(EmptyString(parv[2])) - target_p->user->suser[0] = '\0'; - else - rb_strlcpy(target_p->user->suser, parv[2], sizeof(target_p->user->suser)); + if(EmptyString(parv[2])) + target_p->user->suser[0] = '\0'; + else + rb_strlcpy(target_p->user->suser, parv[2], sizeof(target_p->user->suser)); sendto_common_channels_local_butone(target_p, CLICAP_ACCOUNT_NOTIFY, ":%s!%s@%s ACCOUNT :%s", target_p->name, target_p->username, target_p->host, EmptyString(target_p->user->suser) ? "*" : target_p->user->suser); - - invalidate_bancache_user(target_p); - return 0; + invalidate_bancache_user(target_p); + + return 0; } static int me_login(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - rb_strlcpy(source_p->user->suser, parv[1], sizeof(source_p->user->suser)); - return 0; + rb_strlcpy(source_p->user->suser, parv[1], sizeof(source_p->user->suser)); + return 0; } static int clean_nick(const char *nick) { - int len = 0; + int len = 0; - if(EmptyString(nick) || *nick == '-' || IsDigit(*nick)) - return 0; + if(EmptyString(nick) || *nick == '-' || IsDigit(*nick)) + return 0; - for(; *nick; nick++) - { - len++; - if(!IsNickChar(*nick)) - return 0; - } + for(; *nick; nick++) { + len++; + if(!IsNickChar(*nick)) + return 0; + } - if(len >= NICKLEN) - return 0; + if(len >= NICKLEN) + return 0; - return 1; + return 1; } static int me_rsfnc(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p; - struct Client *exist_p; - time_t newts, curts; - char note[NICKLEN + 10]; + struct Client *target_p; + struct Client *exist_p; + time_t newts, curts; + char note[NICKLEN + 10]; - if(!(source_p->flags & FLAGS_SERVICE)) - return 0; + if(!(source_p->flags & FLAGS_SERVICE)) + return 0; - if((target_p = find_person(parv[1])) == NULL) - return 0; + if((target_p = find_person(parv[1])) == NULL) + return 0; - if(!MyClient(target_p)) - return 0; + if(!MyClient(target_p)) + return 0; - if(!clean_nick(parv[2])) - return 0; + if(!clean_nick(parv[2])) + return 0; - curts = atol(parv[4]); + curts = atol(parv[4]); - /* if tsinfo is different from what it was when services issued the - * RSFNC, then we ignore it. This can happen when a client changes - * nicknames before the RSFNC arrives.. --anfl - */ - if(target_p->tsinfo != curts) - return 0; + /* if tsinfo is different from what it was when services issued the + * RSFNC, then we ignore it. This can happen when a client changes + * nicknames before the RSFNC arrives.. --anfl + */ + if(target_p->tsinfo != curts) + return 0; - if((exist_p = find_named_client(parv[2]))) - { - char buf[BUFSIZE]; + if((exist_p = find_named_client(parv[2]))) { + char buf[BUFSIZE]; - /* this would be one hell of a race condition to trigger - * this one given the tsinfo check above, but its here for - * safety --anfl - */ - if(target_p == exist_p) - return 0; + /* this would be one hell of a race condition to trigger + * this one given the tsinfo check above, but its here for + * safety --anfl + */ + if(target_p == exist_p) + return 0; - if(MyClient(exist_p)) - sendto_one(exist_p, ":%s KILL %s :(Nickname regained by services)", - me.name, exist_p->name); + if(MyClient(exist_p)) + sendto_one(exist_p, ":%s KILL %s :(Nickname regained by services)", + me.name, exist_p->name); - exist_p->flags |= FLAGS_KILLED; - /* Do not send kills to servers for unknowns -- jilles */ - if(IsClient(exist_p)) - kill_client_serv_butone(NULL, exist_p, "%s (Nickname regained by services)", - me.name); + exist_p->flags |= FLAGS_KILLED; + /* Do not send kills to servers for unknowns -- jilles */ + if(IsClient(exist_p)) + kill_client_serv_butone(NULL, exist_p, "%s (Nickname regained by services)", + me.name); - rb_snprintf(buf, sizeof(buf), "Killed (%s (Nickname regained by services))", - me.name); - exit_client(NULL, exist_p, &me, buf); - } + rb_snprintf(buf, sizeof(buf), "Killed (%s (Nickname regained by services))", + me.name); + exit_client(NULL, exist_p, &me, buf); + } - newts = atol(parv[3]); + newts = atol(parv[3]); - /* timestamp is older than 15mins, ignore it */ - if(newts < (rb_current_time() - 900)) - newts = rb_current_time() - 900; + /* timestamp is older than 15mins, ignore it */ + if(newts < (rb_current_time() - 900)) + newts = rb_current_time() - 900; - target_p->tsinfo = newts; + target_p->tsinfo = newts; - monitor_signoff(target_p); + monitor_signoff(target_p); - invalidate_bancache_user(target_p); + invalidate_bancache_user(target_p); - sendto_realops_snomask(SNO_NCHANGE, L_ALL, - "Nick change: From %s to %s [%s@%s]", - target_p->name, parv[2], target_p->username, - target_p->host); + sendto_realops_snomask(SNO_NCHANGE, L_ALL, + "Nick change: From %s to %s [%s@%s]", + target_p->name, parv[2], target_p->username, + target_p->host); - sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s", - target_p->name, target_p->username, - target_p->host, parv[2]); + sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s", + target_p->name, target_p->username, + target_p->host, parv[2]); - add_history(target_p, 1); - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", - use_id(target_p), parv[2], (long) target_p->tsinfo); + add_history(target_p, 1); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", + use_id(target_p), parv[2], (long) target_p->tsinfo); - del_from_client_hash(target_p->name, target_p); - strcpy(target_p->name, parv[2]); - add_to_client_hash(target_p->name, target_p); + del_from_client_hash(target_p->name, target_p); + strcpy(target_p->name, parv[2]); + add_to_client_hash(target_p->name, target_p); - monitor_signon(target_p); + monitor_signon(target_p); - del_all_accepts(target_p); + del_all_accepts(target_p); - rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); - rb_note(target_p->localClient->F, note); - return 0; + rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); + rb_note(target_p->localClient->F, note); + return 0; } /* @@ -249,81 +247,73 @@ me_rsfnc(struct Client *client_p, struct Client *source_p, static int me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int duration; - struct nd_entry *nd; + int duration; + struct nd_entry *nd; - if(!(source_p->flags & FLAGS_SERVICE)) - return 0; + if(!(source_p->flags & FLAGS_SERVICE)) + return 0; - duration = atoi(parv[1]); - if (duration <= 0) - { - nd = irc_dictionary_retrieve(nd_dict, parv[2]); - if (nd != NULL) - free_nd_entry(nd); - } - else - { - if (duration > 86400) - duration = 86400; - add_nd_entry(parv[2]); - nd = irc_dictionary_retrieve(nd_dict, parv[2]); - if (nd != NULL) - nd->expire = rb_current_time() + duration; - } + duration = atoi(parv[1]); + if (duration <= 0) { + nd = irc_dictionary_retrieve(nd_dict, parv[2]); + if (nd != NULL) + free_nd_entry(nd); + } else { + if (duration > 86400) + duration = 86400; + add_nd_entry(parv[2]); + nd = irc_dictionary_retrieve(nd_dict, parv[2]); + if (nd != NULL) + nd->expire = rb_current_time() + duration; + } - return 0; + return 0; } static void h_svc_server_introduced(hook_data_client *hdata) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, service_list.head) - { - if(!irccmp((const char *) ptr->data, hdata->target->name)) - { - hdata->target->flags |= FLAGS_SERVICE; - return; - } - } + RB_DLINK_FOREACH(ptr, service_list.head) { + if(!irccmp((const char *) ptr->data, hdata->target->name)) { + hdata->target->flags |= FLAGS_SERVICE; + return; + } + } } static void h_svc_whois(hook_data_client *data) { - char *p = data->target->user->suser; - if(!EmptyString(p)) - { - /* Try to strip off any leading digits as this may be used to - * store both an ID number and an account name in one field. - * If only digits are present, leave as is. - */ - while(IsDigit(*p)) - p++; - if(*p == '\0') - p = data->target->user->suser; + char *p = data->target->user->suser; + if(!EmptyString(p)) { + /* Try to strip off any leading digits as this may be used to + * store both an ID number and an account name in one field. + * If only digits are present, leave as is. + */ + while(IsDigit(*p)) + p++; + if(*p == '\0') + p = data->target->user->suser; - sendto_one_numeric(data->client, RPL_WHOISLOGGEDIN, - form_str(RPL_WHOISLOGGEDIN), - data->target->name, p); - } + sendto_one_numeric(data->client, RPL_WHOISLOGGEDIN, + form_str(RPL_WHOISLOGGEDIN), + data->target->name, p); + } } static void h_svc_stats(hook_data_int *data) { - char statchar = (char) data->arg2; - rb_dlink_node *ptr; + char statchar = (char) data->arg2; + rb_dlink_node *ptr; - if (statchar == 'U' && IsOper(data->client)) - { - RB_DLINK_FOREACH(ptr, service_list.head) - { - sendto_one_numeric(data->client, RPL_STATSULINE, - form_str(RPL_STATSULINE), - ptr->data, "*", "*", "s"); - } - } + if (statchar == 'U' && IsOper(data->client)) { + RB_DLINK_FOREACH(ptr, service_list.head) { + sendto_one_numeric(data->client, RPL_STATSULINE, + form_str(RPL_STATSULINE), + ptr->data, "*", "*", "s"); + } + } } diff --git a/modules/m_set.c b/modules/m_set.c index f803f72..68247fe 100644 --- a/modules/m_set.c +++ b/modules/m_set.c @@ -44,23 +44,22 @@ static int mo_set(struct Client *, struct Client *, int, const char **); struct Message set_msgtab = { - "SET", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_set, 0}} + "SET", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_set, 0}} }; mapi_clist_av1 set_clist[] = { &set_msgtab, NULL }; DECLARE_MODULE_AV1(set, NULL, NULL, set_clist, NULL, NULL, "$Revision: 3406 $"); /* Structure used for the SET table itself */ -struct SetStruct -{ - const char *name; - void (*handler)(struct Client *source_p, const char *chararg, int intarg); - int wants_char; /* 1 if it expects (char *, [int]) */ - int wants_int; /* 1 if it expects ([char *], int) */ +struct SetStruct { + const char *name; + void (*handler)(struct Client *source_p, const char *chararg, int intarg); + int wants_char; /* 1 if it expects (char *, [int]) */ + int wants_int; /* 1 if it expects ([char *], int) */ - /* eg: 0, 1 == only an int arg - * eg: 1, 1 == char and int args */ + /* eg: 0, 1 == only an int arg + * eg: 1, 1 == char and int args */ }; @@ -81,7 +80,7 @@ static void quote_splitusers(struct Client *, const char *, int); static void list_quote_commands(struct Client *); -/* +/* * If this ever needs to be expanded to more than one arg of each * type, want_char/want_int could be the count of the arguments, * instead of just a boolean flag... @@ -90,24 +89,24 @@ static void list_quote_commands(struct Client *); */ static struct SetStruct set_cmd_table[] = { - /* name function string arg int arg */ - /* -------------------------------------------------------- */ - {"ADMINSTRING", quote_adminstring, 1, 0 }, - {"AUTOCONN", quote_autoconn, 1, 1 }, - {"AUTOCONNALL", quote_autoconnall, 0, 1 }, - {"FLOODCOUNT", quote_floodcount, 0, 1 }, - {"IDENTTIMEOUT", quote_identtimeout, 0, 1 }, - {"MAX", quote_max, 0, 1 }, - {"MAXCLIENTS", quote_max, 0, 1 }, - {"OPERHOST", quote_operhost, 1, 0 }, - {"OPERSTRING", quote_operstring, 1, 0 }, - {"SPAMNUM", quote_spamnum, 0, 1 }, - {"SPAMTIME", quote_spamtime, 0, 1 }, - {"SPLITMODE", quote_splitmode, 1, 0 }, - {"SPLITNUM", quote_splitnum, 0, 1 }, - {"SPLITUSERS", quote_splitusers, 0, 1 }, - /* -------------------------------------------------------- */ - {(char *) 0, (void (*)(struct Client *, const char *, int)) 0, 0, 0} + /* name function string arg int arg */ + /* -------------------------------------------------------- */ + {"ADMINSTRING", quote_adminstring, 1, 0 }, + {"AUTOCONN", quote_autoconn, 1, 1 }, + {"AUTOCONNALL", quote_autoconnall, 0, 1 }, + {"FLOODCOUNT", quote_floodcount, 0, 1 }, + {"IDENTTIMEOUT", quote_identtimeout, 0, 1 }, + {"MAX", quote_max, 0, 1 }, + {"MAXCLIENTS", quote_max, 0, 1 }, + {"OPERHOST", quote_operhost, 1, 0 }, + {"OPERSTRING", quote_operstring, 1, 0 }, + {"SPAMNUM", quote_spamnum, 0, 1 }, + {"SPAMTIME", quote_spamtime, 0, 1 }, + {"SPLITMODE", quote_splitmode, 1, 0 }, + {"SPLITNUM", quote_splitnum, 0, 1 }, + {"SPLITUSERS", quote_splitusers, 0, 1 }, + /* -------------------------------------------------------- */ + {(char *) 0, (void (*)(struct Client *, const char *, int)) 0, 0, 0} }; @@ -118,55 +117,50 @@ static struct SetStruct set_cmd_table[] = { static void list_quote_commands(struct Client *source_p) { - int i; - int j = 0; - const char *names[4]; + int i; + int j = 0; + const char *names[4]; - sendto_one_notice(source_p, ":Available QUOTE SET commands:"); + sendto_one_notice(source_p, ":Available QUOTE SET commands:"); - names[0] = names[1] = names[2] = names[3] = ""; + names[0] = names[1] = names[2] = names[3] = ""; - for (i = 0; set_cmd_table[i].handler; i++) - { - names[j++] = set_cmd_table[i].name; + for (i = 0; set_cmd_table[i].handler; i++) { + names[j++] = set_cmd_table[i].name; - if(j > 3) - { - sendto_one_notice(source_p, ":%s %s %s %s", - names[0], names[1], names[2], names[3]); - j = 0; - names[0] = names[1] = names[2] = names[3] = ""; - } + if(j > 3) { + sendto_one_notice(source_p, ":%s %s %s %s", + names[0], names[1], names[2], names[3]); + j = 0; + names[0] = names[1] = names[2] = names[3] = ""; + } - } - if(j) - sendto_one_notice(source_p, ":%s %s %s %s", - names[0], names[1], names[2], names[3]); + } + if(j) + sendto_one_notice(source_p, ":%s %s %s %s", + names[0], names[1], names[2], names[3]); } /* SET AUTOCONN */ static void quote_autoconn(struct Client *source_p, const char *arg, int newval) { - set_server_conf_autoconn(source_p, arg, newval); + set_server_conf_autoconn(source_p, arg, newval); } /* SET AUTOCONNALL */ static void quote_autoconnall(struct Client *source_p, const char *arg, int newval) { - if(newval >= 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed AUTOCONNALL to %i", - source_p->name, newval); + if(newval >= 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed AUTOCONNALL to %i", + source_p->name, newval); - GlobalSetOptions.autoconn = newval; - } - else - { - sendto_one_notice(source_p, ":AUTOCONNALL is currently %i", - GlobalSetOptions.autoconn); - } + GlobalSetOptions.autoconn = newval; + } else { + sendto_one_notice(source_p, ":AUTOCONNALL is currently %i", + GlobalSetOptions.autoconn); + } } @@ -174,304 +168,259 @@ quote_autoconnall(struct Client *source_p, const char *arg, int newval) static void quote_floodcount(struct Client *source_p, const char *arg, int newval) { - if(newval >= 0) - { - GlobalSetOptions.floodcount = newval; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed FLOODCOUNT to %i", source_p->name, - GlobalSetOptions.floodcount); - } - else - { - sendto_one_notice(source_p, ":FLOODCOUNT is currently %i", - GlobalSetOptions.floodcount); - } + if(newval >= 0) { + GlobalSetOptions.floodcount = newval; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed FLOODCOUNT to %i", source_p->name, + GlobalSetOptions.floodcount); + } else { + sendto_one_notice(source_p, ":FLOODCOUNT is currently %i", + GlobalSetOptions.floodcount); + } } /* SET IDENTTIMEOUT */ static void quote_identtimeout(struct Client *source_p, const char *arg, int newval) { - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return; + } - if(newval > 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed IDENTTIMEOUT to %d", - get_oper_name(source_p), newval); - GlobalSetOptions.ident_timeout = newval; - } - else - sendto_one_notice(source_p, ":IDENTTIMEOUT is currently %d", - GlobalSetOptions.ident_timeout); + if(newval > 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed IDENTTIMEOUT to %d", + get_oper_name(source_p), newval); + GlobalSetOptions.ident_timeout = newval; + } else + sendto_one_notice(source_p, ":IDENTTIMEOUT is currently %d", + GlobalSetOptions.ident_timeout); } /* SET MAX */ static void quote_max(struct Client *source_p, const char *arg, int newval) { - if(newval > 0) - { - if(newval > maxconnections - MAX_BUFFER) - { - sendto_one_notice(source_p, - ":You cannot set MAXCLIENTS to > %d", - maxconnections - MAX_BUFFER); - return; - } + if(newval > 0) { + if(newval > maxconnections - MAX_BUFFER) { + sendto_one_notice(source_p, + ":You cannot set MAXCLIENTS to > %d", + maxconnections - MAX_BUFFER); + return; + } - if(newval < 32) - { - sendto_one_notice(source_p, ":You cannot set MAXCLIENTS to < 32 (%d:%d)", - GlobalSetOptions.maxclients, rb_getmaxconnect()); - return; - } + if(newval < 32) { + sendto_one_notice(source_p, ":You cannot set MAXCLIENTS to < 32 (%d:%d)", + GlobalSetOptions.maxclients, rb_getmaxconnect()); + return; + } - GlobalSetOptions.maxclients = newval; + GlobalSetOptions.maxclients = newval; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s!%s@%s set new MAXCLIENTS to %d (%lu current)", - source_p->name, source_p->username, source_p->host, - GlobalSetOptions.maxclients, - rb_dlink_list_length(&lclient_list)); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s!%s@%s set new MAXCLIENTS to %d (%lu current)", + source_p->name, source_p->username, source_p->host, + GlobalSetOptions.maxclients, + rb_dlink_list_length(&lclient_list)); - return; - } - else - { - sendto_one_notice(source_p, ":Current Maxclients = %d (%lu)", - GlobalSetOptions.maxclients, rb_dlink_list_length(&lclient_list)); - } + return; + } else { + sendto_one_notice(source_p, ":Current Maxclients = %d (%lu)", + GlobalSetOptions.maxclients, rb_dlink_list_length(&lclient_list)); + } } /* SET OPERHOST */ static void quote_operhost(struct Client *source_p, const char *arg, int newval) { - if(EmptyString(arg)) - { - sendto_one_notice(source_p, ":OPERHOST is currently '%s'", GlobalSetOptions.operhost); - } - else if(!valid_hostname(arg)) - { - sendto_one_notice(source_p, "Invalid hostmask."); - } - else - { - rb_strlcpy(GlobalSetOptions.operhost, arg, - sizeof(GlobalSetOptions.operhost)); - - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed OPERHOST to '%s'", - get_oper_name(source_p), arg); - } + if(EmptyString(arg)) { + sendto_one_notice(source_p, ":OPERHOST is currently '%s'", GlobalSetOptions.operhost); + } else if(!valid_hostname(arg)) { + sendto_one_notice(source_p, "Invalid hostmask."); + } else { + rb_strlcpy(GlobalSetOptions.operhost, arg, + sizeof(GlobalSetOptions.operhost)); + + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed OPERHOST to '%s'", + get_oper_name(source_p), arg); + } } /* SET OPERSTRING */ static void quote_operstring(struct Client *source_p, const char *arg, int newval) { - if(EmptyString(arg)) - { - sendto_one_notice(source_p, ":OPERSTRING is currently '%s'", GlobalSetOptions.operstring); - } - else - { - rb_strlcpy(GlobalSetOptions.operstring, arg, - sizeof(GlobalSetOptions.operstring)); - - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed OPERSTRING to '%s'", - get_oper_name(source_p), arg); - } + if(EmptyString(arg)) { + sendto_one_notice(source_p, ":OPERSTRING is currently '%s'", GlobalSetOptions.operstring); + } else { + rb_strlcpy(GlobalSetOptions.operstring, arg, + sizeof(GlobalSetOptions.operstring)); + + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed OPERSTRING to '%s'", + get_oper_name(source_p), arg); + } } /* SET ADMINSTRING */ static void quote_adminstring(struct Client *source_p, const char *arg, int newval) { - if(EmptyString(arg)) - { - sendto_one_notice(source_p, ":ADMINSTRING is currently '%s'", GlobalSetOptions.adminstring); - } - else - { - rb_strlcpy(GlobalSetOptions.adminstring, arg, - sizeof(GlobalSetOptions.adminstring)); - - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed ADMINSTRING to '%s'", - get_oper_name(source_p), arg); - } + if(EmptyString(arg)) { + sendto_one_notice(source_p, ":ADMINSTRING is currently '%s'", GlobalSetOptions.adminstring); + } else { + rb_strlcpy(GlobalSetOptions.adminstring, arg, + sizeof(GlobalSetOptions.adminstring)); + + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed ADMINSTRING to '%s'", + get_oper_name(source_p), arg); + } } /* SET SPAMNUM */ static void quote_spamnum(struct Client *source_p, const char *arg, int newval) { - if(newval > 0) - { - if(newval == 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has disabled ANTI_SPAMBOT", source_p->name); - GlobalSetOptions.spam_num = newval; - return; - } - if(newval < MIN_SPAM_NUM) - { - GlobalSetOptions.spam_num = MIN_SPAM_NUM; - } - else /* if (newval < MIN_SPAM_NUM) */ - { - GlobalSetOptions.spam_num = newval; - } - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed SPAMNUM to %i", - source_p->name, GlobalSetOptions.spam_num); - } - else - { - sendto_one_notice(source_p, ":SPAMNUM is currently %i", GlobalSetOptions.spam_num); - } + if(newval > 0) { + if(newval == 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has disabled ANTI_SPAMBOT", source_p->name); + GlobalSetOptions.spam_num = newval; + return; + } + if(newval < MIN_SPAM_NUM) { + GlobalSetOptions.spam_num = MIN_SPAM_NUM; + } else { /* if (newval < MIN_SPAM_NUM) */ + GlobalSetOptions.spam_num = newval; + } + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed SPAMNUM to %i", + source_p->name, GlobalSetOptions.spam_num); + } else { + sendto_one_notice(source_p, ":SPAMNUM is currently %i", GlobalSetOptions.spam_num); + } } /* SET SPAMTIME */ static void quote_spamtime(struct Client *source_p, const char *arg, int newval) { - if(newval > 0) - { - if(newval < MIN_SPAM_TIME) - { - GlobalSetOptions.spam_time = MIN_SPAM_TIME; - } - else /* if (newval < MIN_SPAM_TIME) */ - { - GlobalSetOptions.spam_time = newval; - } - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed SPAMTIME to %i", - source_p->name, GlobalSetOptions.spam_time); - } - else - { - sendto_one_notice(source_p, ":SPAMTIME is currently %i", GlobalSetOptions.spam_time); - } + if(newval > 0) { + if(newval < MIN_SPAM_TIME) { + GlobalSetOptions.spam_time = MIN_SPAM_TIME; + } else { /* if (newval < MIN_SPAM_TIME) */ + GlobalSetOptions.spam_time = newval; + } + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed SPAMTIME to %i", + source_p->name, GlobalSetOptions.spam_time); + } else { + sendto_one_notice(source_p, ":SPAMTIME is currently %i", GlobalSetOptions.spam_time); + } } /* this table is what splitmode may be set to */ static const char *splitmode_values[] = { - "OFF", - "ON", - "AUTO", - NULL + "OFF", + "ON", + "AUTO", + NULL }; /* this table is what splitmode may be */ static const char *splitmode_status[] = { - "OFF", - "AUTO (OFF)", - "ON", - "AUTO (ON)", - NULL + "OFF", + "AUTO (OFF)", + "ON", + "AUTO (ON)", + NULL }; /* SET SPLITMODE */ static void quote_splitmode(struct Client *source_p, const char *charval, int intval) { - if(charval) - { - int newval; + if(charval) { + int newval; - for (newval = 0; splitmode_values[newval]; newval++) - { - if(!irccmp(splitmode_values[newval], charval)) - break; - } + for (newval = 0; splitmode_values[newval]; newval++) { + if(!irccmp(splitmode_values[newval], charval)) + break; + } - /* OFF */ - if(newval == 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is disabling splitmode", get_oper_name(source_p)); + /* OFF */ + if(newval == 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is disabling splitmode", get_oper_name(source_p)); - splitmode = 0; - splitchecking = 0; + splitmode = 0; + splitchecking = 0; - rb_event_delete(check_splitmode_ev); - check_splitmode_ev = NULL; - } - /* ON */ - else if(newval == 1) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is enabling and activating splitmode", - get_oper_name(source_p)); + rb_event_delete(check_splitmode_ev); + check_splitmode_ev = NULL; + } + /* ON */ + else if(newval == 1) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is enabling and activating splitmode", + get_oper_name(source_p)); - splitmode = 1; - splitchecking = 0; + splitmode = 1; + splitchecking = 0; - /* we might be deactivating an automatic splitmode, so pull the event */ - rb_event_delete(check_splitmode_ev); - check_splitmode_ev = NULL; - } - /* AUTO */ - else if(newval == 2) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s is enabling automatic splitmode", - get_oper_name(source_p)); + /* we might be deactivating an automatic splitmode, so pull the event */ + rb_event_delete(check_splitmode_ev); + check_splitmode_ev = NULL; + } + /* AUTO */ + else if(newval == 2) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s is enabling automatic splitmode", + get_oper_name(source_p)); - splitchecking = 1; - check_splitmode(NULL); - } - } - else - /* if we add splitchecking to splitmode*2 we get a unique table to - * pull values back out of, splitmode can be four states - but you can - * only set to three, which means we cant use the same table --fl_ - */ - sendto_one_notice(source_p, ":SPLITMODE is currently %s", - splitmode_status[(splitchecking + (splitmode * 2))]); + splitchecking = 1; + check_splitmode(NULL); + } + } else + /* if we add splitchecking to splitmode*2 we get a unique table to + * pull values back out of, splitmode can be four states - but you can + * only set to three, which means we cant use the same table --fl_ + */ + sendto_one_notice(source_p, ":SPLITMODE is currently %s", + splitmode_status[(splitchecking + (splitmode * 2))]); } /* SET SPLITNUM */ static void quote_splitnum(struct Client *source_p, const char *arg, int newval) { - if(newval >= 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed SPLITNUM to %i", source_p->name, newval); - split_servers = newval; + if(newval >= 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed SPLITNUM to %i", source_p->name, newval); + split_servers = newval; - if(splitchecking) - check_splitmode(NULL); - } - else - sendto_one_notice(source_p, ":SPLITNUM is currently %i", split_servers); + if(splitchecking) + check_splitmode(NULL); + } else + sendto_one_notice(source_p, ":SPLITNUM is currently %i", split_servers); } /* SET SPLITUSERS */ static void quote_splitusers(struct Client *source_p, const char *arg, int newval) { - if(newval >= 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed SPLITUSERS to %i", source_p->name, newval); - split_users = newval; + if(newval >= 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed SPLITUSERS to %i", source_p->name, newval); + split_users = newval; - if(splitchecking) - check_splitmode(NULL); - } - else - sendto_one_notice(source_p, ":SPLITUSERS is currently %i", split_users); + if(splitchecking) + check_splitmode(NULL); + } else + sendto_one_notice(source_p, ":SPLITUSERS is currently %i", split_users); } /* @@ -481,99 +430,86 @@ quote_splitusers(struct Client *source_p, const char *arg, int newval) static int mo_set(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int newval; - int i, n; - const char *arg = NULL; - const char *intarg = NULL; + int newval; + int i, n; + const char *arg = NULL; + const char *intarg = NULL; - if(parc > 1) - { - /* - * Go through all the commands in set_cmd_table, until one is - * matched. I realize strcmp() is more intensive than a numeric - * lookup, but at least it's better than a big-ass switch/case - * statement. - */ - for (i = 0; set_cmd_table[i].handler; i++) - { - if(!irccmp(set_cmd_table[i].name, parv[1])) - { - /* - * Command found; now execute the code - */ - n = 2; + if(parc > 1) { + /* + * Go through all the commands in set_cmd_table, until one is + * matched. I realize strcmp() is more intensive than a numeric + * lookup, but at least it's better than a big-ass switch/case + * statement. + */ + for (i = 0; set_cmd_table[i].handler; i++) { + if(!irccmp(set_cmd_table[i].name, parv[1])) { + /* + * Command found; now execute the code + */ + n = 2; - if(set_cmd_table[i].wants_char) - { - arg = parv[n++]; - } + if(set_cmd_table[i].wants_char) { + arg = parv[n++]; + } - if(set_cmd_table[i].wants_int) - { - intarg = parv[n++]; - } + if(set_cmd_table[i].wants_int) { + intarg = parv[n++]; + } - if((n - 1) > parc) - { - sendto_one_notice(source_p, - ":SET %s expects (\"%s%s\") args", - set_cmd_table[i].name, - (set_cmd_table[i]. - wants_char ? "string, " : ""), - (set_cmd_table[i]. - wants_char ? "int" : "")); - return 0; - } + if((n - 1) > parc) { + sendto_one_notice(source_p, + ":SET %s expects (\"%s%s\") args", + set_cmd_table[i].name, + (set_cmd_table[i]. + wants_char ? "string, " : ""), + (set_cmd_table[i]. + wants_char ? "int" : "")); + return 0; + } - if(parc <= 2) - { - arg = NULL; - intarg = NULL; - } + if(parc <= 2) { + arg = NULL; + intarg = NULL; + } - if(set_cmd_table[i].wants_int && (parc > 2)) - { - if(intarg) - { - if(!irccmp(intarg, "yes") || !irccmp(intarg, "on")) - newval = 1; - else if(!irccmp(intarg, "no") - || !irccmp(intarg, "off")) - newval = 0; - else - newval = atoi(intarg); - } - else - { - newval = -1; - } + if(set_cmd_table[i].wants_int && (parc > 2)) { + if(intarg) { + if(!irccmp(intarg, "yes") || !irccmp(intarg, "on")) + newval = 1; + else if(!irccmp(intarg, "no") + || !irccmp(intarg, "off")) + newval = 0; + else + newval = atoi(intarg); + } else { + newval = -1; + } - if(newval < 0) - { - sendto_one_notice(source_p, - ":Value less than 0 illegal for %s", - set_cmd_table[i].name); + if(newval < 0) { + sendto_one_notice(source_p, + ":Value less than 0 illegal for %s", + set_cmd_table[i].name); - return 0; - } - } - else - newval = -1; + return 0; + } + } else + newval = -1; - set_cmd_table[i].handler(source_p, arg, newval); - return 0; - } - } + set_cmd_table[i].handler(source_p, arg, newval); + return 0; + } + } - /* - * Code here will be executed when a /QUOTE SET command is not - * found within set_cmd_table. - */ - sendto_one_notice(source_p, ":Variable not found."); - return 0; - } + /* + * Code here will be executed when a /QUOTE SET command is not + * found within set_cmd_table. + */ + sendto_one_notice(source_p, ":Variable not found."); + return 0; + } - list_quote_commands(source_p); + list_quote_commands(source_p); - return 0; + return 0; } diff --git a/modules/m_signon.c b/modules/m_signon.c index efcb84d..2990115 100644 --- a/modules/m_signon.c +++ b/modules/m_signon.c @@ -56,16 +56,16 @@ static int ms_signon(struct Client *, struct Client *, int, const char **); static void send_signon(struct Client *, struct Client *, const char *, const char *, const char *, unsigned int, const char *); struct Message svslogin_msgtab = { - "SVSLOGIN", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_svslogin, 6}, mg_ignore} + "SVSLOGIN", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_svslogin, 6}, mg_ignore} }; struct Message signon_msgtab = { - "SIGNON", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_ignore, {ms_signon, 6}, mg_ignore, mg_ignore, mg_ignore} + "SIGNON", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_ignore, {ms_signon, 6}, mg_ignore, mg_ignore, mg_ignore} }; -mapi_clist_av1 signon_clist[] = { - &svslogin_msgtab, &signon_msgtab, NULL +mapi_clist_av1 signon_clist[] = { + &svslogin_msgtab, &signon_msgtab, NULL }; DECLARE_MODULE_AV1(signon, NULL, NULL, signon_clist, NULL, NULL, "$Revision: 1192 $"); @@ -77,362 +77,334 @@ DECLARE_MODULE_AV1(signon, NULL, NULL, signon_clist, NULL, NULL, "$Revision: 119 static int clean_nick(const char *nick) { - int len = 0; + int len = 0; - if(*nick == '-') - return 0; + if(*nick == '-') + return 0; - /* This is used to check logins, which are often - * numeric. Don't check for leading digits, if - * services wants to set someone's nick to something - * starting with a number, let it try. - * --gxti - */ + /* This is used to check logins, which are often + * numeric. Don't check for leading digits, if + * services wants to set someone's nick to something + * starting with a number, let it try. + * --gxti + */ - for (; *nick; nick++) - { - len++; - if(!IsNickChar(*nick)) - return 0; - } + for (; *nick; nick++) { + len++; + if(!IsNickChar(*nick)) + return 0; + } - /* nicklen is +1 */ - if(len >= NICKLEN) - return 0; + /* nicklen is +1 */ + if(len >= NICKLEN) + return 0; - return 1; + return 1; } static int clean_username(const char *username) { - int len = 0; + int len = 0; - for (; *username; username++) - { - len++; + for (; *username; username++) { + len++; - if(!IsUserChar(*username)) - return 0; - } + if(!IsUserChar(*username)) + return 0; + } - if(len > USERLEN) - return 0; + if(len > USERLEN) + return 0; - return 1; + return 1; } static int clean_host(const char *host) { - int len = 0; + int len = 0; - for (; *host; host++) - { - len++; + for (; *host; host++) { + len++; - if(!IsHostChar(*host)) - return 0; - } + if(!IsHostChar(*host)) + return 0; + } - if(len > HOSTLEN) - return 0; + if(len > HOSTLEN) + return 0; - return 1; + return 1; } static int me_svslogin(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p, *exist_p; - char nick[NICKLEN+1], login[NICKLEN+1]; - char user[USERLEN+1], host[HOSTLEN+1]; - int valid = 0; + struct Client *target_p, *exist_p; + char nick[NICKLEN+1], login[NICKLEN+1]; + char user[USERLEN+1], host[HOSTLEN+1]; + int valid = 0; - if(!(source_p->flags & FLAGS_SERVICE)) - return 0; + if(!(source_p->flags & FLAGS_SERVICE)) + return 0; - if((target_p = find_client(parv[1])) == NULL) - return 0; + if((target_p = find_client(parv[1])) == NULL) + return 0; - if(!MyClient(target_p) && !IsUnknown(target_p)) - return 0; + if(!MyClient(target_p) && !IsUnknown(target_p)) + return 0; - if(clean_nick(parv[2])) - { - rb_strlcpy(nick, parv[2], NICKLEN + 1); - valid |= NICK_VALID; - } - else if(*target_p->name) - rb_strlcpy(nick, target_p->name, NICKLEN + 1); - else - strcpy(nick, "*"); + if(clean_nick(parv[2])) { + rb_strlcpy(nick, parv[2], NICKLEN + 1); + valid |= NICK_VALID; + } else if(*target_p->name) + rb_strlcpy(nick, target_p->name, NICKLEN + 1); + else + strcpy(nick, "*"); - if(clean_username(parv[3])) - { - rb_strlcpy(user, parv[3], USERLEN + 1); - valid |= USER_VALID; - } - else - rb_strlcpy(user, target_p->username, USERLEN + 1); + if(clean_username(parv[3])) { + rb_strlcpy(user, parv[3], USERLEN + 1); + valid |= USER_VALID; + } else + rb_strlcpy(user, target_p->username, USERLEN + 1); - if(clean_host(parv[4])) - { - rb_strlcpy(host, parv[4], HOSTLEN + 1); - valid |= HOST_VALID; - } - else - rb_strlcpy(host, target_p->host, HOSTLEN + 1); + if(clean_host(parv[4])) { + rb_strlcpy(host, parv[4], HOSTLEN + 1); + valid |= HOST_VALID; + } else + rb_strlcpy(host, target_p->host, HOSTLEN + 1); - if(*parv[5] == '*') - { - if(target_p->user) - rb_strlcpy(login, target_p->user->suser, NICKLEN + 1); - else - login[0] = '\0'; - } - else if(!strcmp(parv[5], "0")) - login[0] = '\0'; - else - rb_strlcpy(login, parv[5], NICKLEN + 1); + if(*parv[5] == '*') { + if(target_p->user) + rb_strlcpy(login, target_p->user->suser, NICKLEN + 1); + else + login[0] = '\0'; + } else if(!strcmp(parv[5], "0")) + login[0] = '\0'; + else + rb_strlcpy(login, parv[5], NICKLEN + 1); - /* Login (mostly) follows nick rules. */ - if(*login && !clean_nick(login)) - return 0; + /* Login (mostly) follows nick rules. */ + if(*login && !clean_nick(login)) + return 0; - if((exist_p = find_person(nick)) && target_p != exist_p) - { - char buf[BUFSIZE]; + if((exist_p = find_person(nick)) && target_p != exist_p) { + char buf[BUFSIZE]; - if(MyClient(exist_p)) - sendto_one(exist_p, ":%s KILL %s :(Nickname regained by services)", - me.name, exist_p->name); + if(MyClient(exist_p)) + sendto_one(exist_p, ":%s KILL %s :(Nickname regained by services)", + me.name, exist_p->name); - exist_p->flags |= FLAGS_KILLED; - kill_client_serv_butone(NULL, exist_p, "%s (Nickname regained by services)", - me.name); + exist_p->flags |= FLAGS_KILLED; + kill_client_serv_butone(NULL, exist_p, "%s (Nickname regained by services)", + me.name); - rb_snprintf(buf, sizeof(buf), "Killed (%s (Nickname regained by services))", - me.name); - exit_client(NULL, exist_p, &me, buf); - }else if((exist_p = find_client(nick)) && IsUnknown(exist_p) && exist_p != target_p) { - exit_client(NULL, exist_p, &me, "Overridden"); - } + rb_snprintf(buf, sizeof(buf), "Killed (%s (Nickname regained by services))", + me.name); + exit_client(NULL, exist_p, &me, buf); + } else if((exist_p = find_client(nick)) && IsUnknown(exist_p) && exist_p != target_p) { + exit_client(NULL, exist_p, &me, "Overridden"); + } - if(*login) - { - /* Strip leading digits, unless it's purely numeric. */ - const char *p = login; - while(IsDigit(*p)) - p++; - if(!*p) - p = login; + if(*login) { + /* Strip leading digits, unless it's purely numeric. */ + const char *p = login; + while(IsDigit(*p)) + p++; + if(!*p) + p = login; - sendto_one(target_p, form_str(RPL_LOGGEDIN), me.name, EmptyString(target_p->name) ? "*" : target_p->name, - nick, user, host, p, p); - } - else - sendto_one(target_p, form_str(RPL_LOGGEDOUT), me.name, EmptyString(target_p->name) ? "*" : target_p->name, - nick, user, host); + sendto_one(target_p, form_str(RPL_LOGGEDIN), me.name, EmptyString(target_p->name) ? "*" : target_p->name, + nick, user, host, p, p); + } else + sendto_one(target_p, form_str(RPL_LOGGEDOUT), me.name, EmptyString(target_p->name) ? "*" : target_p->name, + nick, user, host); - if(IsUnknown(target_p)) - { - struct User *user_p = make_user(target_p); + if(IsUnknown(target_p)) { + struct User *user_p = make_user(target_p); - if(valid & NICK_VALID) - strcpy(target_p->preClient->spoofnick, nick); + if(valid & NICK_VALID) + strcpy(target_p->preClient->spoofnick, nick); - if(valid & USER_VALID) - strcpy(target_p->preClient->spoofuser, user); + if(valid & USER_VALID) + strcpy(target_p->preClient->spoofuser, user); - if(valid & HOST_VALID) - strcpy(target_p->preClient->spoofhost, host); + if(valid & HOST_VALID) + strcpy(target_p->preClient->spoofhost, host); - rb_strlcpy(user_p->suser, login, NICKLEN + 1); - } - else - { - char note[NICKLEN + 10]; + rb_strlcpy(user_p->suser, login, NICKLEN + 1); + } else { + char note[NICKLEN + 10]; - send_signon(NULL, target_p, nick, user, host, rb_current_time(), login); + send_signon(NULL, target_p, nick, user, host, rb_current_time(), login); - rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); - rb_note(target_p->localClient->F, note); - } + rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); + rb_note(target_p->localClient->F, note); + } - return 0; + return 0; } static int ms_signon(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p; - int newts, sameuser; - char login[NICKLEN+1]; + struct Client *target_p; + int newts, sameuser; + char login[NICKLEN+1]; - if(!clean_nick(parv[1])) - { - ServerStats.is_kill++; - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Bad Nick from SIGNON: %s From: %s(via %s)", - parv[1], source_p->servptr->name, client_p->name); - /* if source_p has an id, kill_client_serv_butone() will - * send a kill to client_p, otherwise do it here */ - if (!has_id(source_p)) - sendto_one(client_p, ":%s KILL %s :%s (Bad nickname from SIGNON)", - get_id(&me, client_p), parv[1], me.name); - kill_client_serv_butone(client_p, source_p, "%s (Bad nickname from SIGNON)", - me.name); - source_p->flags |= FLAGS_KILLED; - exit_client(NULL, source_p, &me, "Bad nickname from SIGNON"); - return 0; - } + if(!clean_nick(parv[1])) { + ServerStats.is_kill++; + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Bad Nick from SIGNON: %s From: %s(via %s)", + parv[1], source_p->servptr->name, client_p->name); + /* if source_p has an id, kill_client_serv_butone() will + * send a kill to client_p, otherwise do it here */ + if (!has_id(source_p)) + sendto_one(client_p, ":%s KILL %s :%s (Bad nickname from SIGNON)", + get_id(&me, client_p), parv[1], me.name); + kill_client_serv_butone(client_p, source_p, "%s (Bad nickname from SIGNON)", + me.name); + source_p->flags |= FLAGS_KILLED; + exit_client(NULL, source_p, &me, "Bad nickname from SIGNON"); + return 0; + } - if(!clean_username(parv[2]) || !clean_host(parv[3])) - { - ServerStats.is_kill++; - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Bad user@host from SIGNON: %s@%s From: %s(via %s)", - parv[2], parv[3], source_p->servptr->name, client_p->name); - /* if source_p has an id, kill_client_serv_butone() will - * send a kill to client_p, otherwise do it here */ - if (!has_id(source_p)) - sendto_one(client_p, ":%s KILL %s :%s (Bad user@host from SIGNON)", - get_id(&me, client_p), parv[1], me.name); - kill_client_serv_butone(client_p, source_p, "%s (Bad user@host from SIGNON)", - me.name); - source_p->flags |= FLAGS_KILLED; - exit_client(NULL, source_p, &me, "Bad user@host from SIGNON"); - return 0; - } + if(!clean_username(parv[2]) || !clean_host(parv[3])) { + ServerStats.is_kill++; + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Bad user@host from SIGNON: %s@%s From: %s(via %s)", + parv[2], parv[3], source_p->servptr->name, client_p->name); + /* if source_p has an id, kill_client_serv_butone() will + * send a kill to client_p, otherwise do it here */ + if (!has_id(source_p)) + sendto_one(client_p, ":%s KILL %s :%s (Bad user@host from SIGNON)", + get_id(&me, client_p), parv[1], me.name); + kill_client_serv_butone(client_p, source_p, "%s (Bad user@host from SIGNON)", + me.name); + source_p->flags |= FLAGS_KILLED; + exit_client(NULL, source_p, &me, "Bad user@host from SIGNON"); + return 0; + } - newts = atol(parv[4]); + newts = atol(parv[4]); - if(!strcmp(parv[5], "0")) - login[0] = '\0'; - else if(*parv[5] != '*') - { - if (clean_nick(parv[5])) - rb_strlcpy(login, parv[5], NICKLEN + 1); - else - return 0; - } + if(!strcmp(parv[5], "0")) + login[0] = '\0'; + else if(*parv[5] != '*') { + if (clean_nick(parv[5])) + rb_strlcpy(login, parv[5], NICKLEN + 1); + else + return 0; + } - target_p = find_named_client(parv[1]); - if(target_p != NULL && target_p != source_p) - { - /* In case of collision, follow NICK rules. */ - /* XXX this is duplicated code and does not do SAVE */ - if(IsUnknown(target_p)) - exit_client(NULL, target_p, &me, "Overridden"); - else - { - if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Nick change collision from SIGNON from %s to %s(%s <- %s)(both killed)", - source_p->name, target_p->name, target_p->from->name, - client_p->name); - - ServerStats.is_kill++; - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); - - kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); - - ServerStats.is_kill++; - - kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); - - target_p->flags |= FLAGS_KILLED; - exit_client(NULL, target_p, &me, "Nick collision(new)"); - source_p->flags |= FLAGS_KILLED; - exit_client(client_p, source_p, &me, "Nick collision(old)"); - return 0; - } - else - { - sameuser = !irccmp(target_p->username, source_p->username) && - !irccmp(target_p->host, source_p->host); - - if((sameuser && newts < target_p->tsinfo) || - (!sameuser && newts > target_p->tsinfo)) - { - if(sameuser) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Nick change collision from SIGNON from %s to %s(%s <- %s)(older killed)", - source_p->name, target_p->name, - target_p->from->name, client_p->name); - else - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Nick change collision from SIGNON from %s to %s(%s <- %s)(newer killed)", - source_p->name, target_p->name, - target_p->from->name, client_p->name); - - ServerStats.is_kill++; - - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); - - /* kill the client issuing the nickchange */ - kill_client_serv_butone(client_p, source_p, - "%s (Nick change collision)", me.name); - - source_p->flags |= FLAGS_KILLED; - - if(sameuser) - exit_client(client_p, source_p, &me, "Nick collision(old)"); - else - exit_client(client_p, source_p, &me, "Nick collision(new)"); - return 0; - } - else - { - if(sameuser) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Nick collision from SIGNON on %s(%s <- %s)(older killed)", - target_p->name, target_p->from->name, - client_p->name); - else - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Nick collision from SIGNON on %s(%s <- %s)(newer killed)", - target_p->name, target_p->from->name, - client_p->name); - - sendto_one_numeric(target_p, ERR_NICKCOLLISION, - form_str(ERR_NICKCOLLISION), target_p->name); - - /* kill the client who existed before hand */ - kill_client_serv_butone(client_p, target_p, - "%s (Nick collision)", me.name); - - ServerStats.is_kill++; - - target_p->flags |= FLAGS_KILLED; - (void) exit_client(client_p, target_p, &me, "Nick collision"); - } - } - - } - } + target_p = find_named_client(parv[1]); + if(target_p != NULL && target_p != source_p) { + /* In case of collision, follow NICK rules. */ + /* XXX this is duplicated code and does not do SAVE */ + if(IsUnknown(target_p)) + exit_client(NULL, target_p, &me, "Overridden"); + else { + if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Nick change collision from SIGNON from %s to %s(%s <- %s)(both killed)", + source_p->name, target_p->name, target_p->from->name, + client_p->name); - send_signon(client_p, source_p, parv[1], parv[2], parv[3], newts, login); - return 0; + ServerStats.is_kill++; + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); + + kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); + + ServerStats.is_kill++; + + kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); + + target_p->flags |= FLAGS_KILLED; + exit_client(NULL, target_p, &me, "Nick collision(new)"); + source_p->flags |= FLAGS_KILLED; + exit_client(client_p, source_p, &me, "Nick collision(old)"); + return 0; + } else { + sameuser = !irccmp(target_p->username, source_p->username) && + !irccmp(target_p->host, source_p->host); + + if((sameuser && newts < target_p->tsinfo) || + (!sameuser && newts > target_p->tsinfo)) { + if(sameuser) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Nick change collision from SIGNON from %s to %s(%s <- %s)(older killed)", + source_p->name, target_p->name, + target_p->from->name, client_p->name); + else + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Nick change collision from SIGNON from %s to %s(%s <- %s)(newer killed)", + source_p->name, target_p->name, + target_p->from->name, client_p->name); + + ServerStats.is_kill++; + + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); + + /* kill the client issuing the nickchange */ + kill_client_serv_butone(client_p, source_p, + "%s (Nick change collision)", me.name); + + source_p->flags |= FLAGS_KILLED; + + if(sameuser) + exit_client(client_p, source_p, &me, "Nick collision(old)"); + else + exit_client(client_p, source_p, &me, "Nick collision(new)"); + return 0; + } else { + if(sameuser) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Nick collision from SIGNON on %s(%s <- %s)(older killed)", + target_p->name, target_p->from->name, + client_p->name); + else + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Nick collision from SIGNON on %s(%s <- %s)(newer killed)", + target_p->name, target_p->from->name, + client_p->name); + + sendto_one_numeric(target_p, ERR_NICKCOLLISION, + form_str(ERR_NICKCOLLISION), target_p->name); + + /* kill the client who existed before hand */ + kill_client_serv_butone(client_p, target_p, + "%s (Nick collision)", me.name); + + ServerStats.is_kill++; + + target_p->flags |= FLAGS_KILLED; + (void) exit_client(client_p, target_p, &me, "Nick collision"); + } + } + + } + } + + send_signon(client_p, source_p, parv[1], parv[2], parv[3], newts, login); + return 0; } static void send_signon(struct Client *client_p, struct Client *target_p, - const char *nick, const char *user, const char *host, - unsigned int newts, const char *login) + const char *nick, const char *user, const char *host, + unsigned int newts, const char *login) { - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s SIGNON %s %s %s %ld %s", - use_id(target_p), nick, user, host, - (long) target_p->tsinfo, *login ? login : "0"); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s SIGNON %s %s %s %ld %s", + use_id(target_p), nick, user, host, + (long) target_p->tsinfo, *login ? login : "0"); - strcpy(target_p->user->suser, login); + strcpy(target_p->user->suser, login); - change_nick_user_host(target_p, nick, user, host, newts, "Signing %s (%s)", *login ? "in" : "out", nick); + change_nick_user_host(target_p, nick, user, host, newts, "Signing %s (%s)", *login ? "in" : "out", nick); } diff --git a/modules/m_snote.c b/modules/m_snote.c index c3785be..ce8fe82 100644 --- a/modules/m_snote.c +++ b/modules/m_snote.c @@ -52,8 +52,8 @@ static int me_snote(struct Client *, struct Client *, int, const char **); struct Message snote_msgtab = { - "SNOTE", 0, 0, 0, MFLG_SLOW, - {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_snote, 3}, mg_ignore} + "SNOTE", 0, 0, 0, MFLG_SLOW, + {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_snote, 3}, mg_ignore} }; mapi_clist_av1 snote_clist[] = { &snote_msgtab, NULL }; @@ -65,20 +65,20 @@ DECLARE_MODULE_AV1(snote, NULL, NULL, snote_clist, NULL, NULL, "$Revision: 623 $ * parv[2] = message */ static int -me_snote(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]) +me_snote(struct Client *client_p, struct Client *source_p, int parc, + const char *parv[]) { - /* if there's more than just two params, this is a protocol - * violation, but it seems stupid to drop servers over it, - * shit happens afterall -nenolod - */ - if (parc > 3) - return 0; - if (!IsServer(source_p)) - return 0; + /* if there's more than just two params, this is a protocol + * violation, but it seems stupid to drop servers over it, + * shit happens afterall -nenolod + */ + if (parc > 3) + return 0; + if (!IsServer(source_p)) + return 0; - sendto_realops_snomask_from(snomask_modes[(unsigned char) *parv[1]], - L_ALL, source_p, "%s", parv[2]); + sendto_realops_snomask_from(snomask_modes[(unsigned char) *parv[1]], + L_ALL, source_p, "%s", parv[2]); - return 0; + return 0; } diff --git a/modules/m_stats.c b/modules/m_stats.c index dc826bc..b8d22c5 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -51,8 +51,8 @@ static int m_stats (struct Client *, struct Client *, int, const char **); struct Message stats_msgtab = { - "STATS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_stats, 2}, {m_stats, 3}, mg_ignore, mg_ignore, {m_stats, 2}} + "STATS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_stats, 2}, {m_stats, 3}, mg_ignore, mg_ignore, {m_stats, 2}} }; int doing_stats_hook; @@ -60,9 +60,9 @@ int doing_stats_p_hook; mapi_clist_av1 stats_clist[] = { &stats_msgtab, NULL }; mapi_hlist_av1 stats_hlist[] = { - { "doing_stats", &doing_stats_hook }, - { "doing_stats_p", &doing_stats_p_hook }, - { NULL, NULL } + { "doing_stats", &doing_stats_hook }, + { "doing_stats_p", &doing_stats_p_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(stats, NULL, NULL, stats_clist, stats_hlist, NULL, "$Revision: 1608 $"); @@ -71,18 +71,17 @@ const char *Lformat = "%s %u %u %u %u %u :%u %u %s"; static void stats_l_list(struct Client *s, const char *, int, int, rb_dlink_list *, char); static void stats_l_client(struct Client *source_p, struct Client *target_p, - char statchar); + char statchar); static void stats_spy(struct Client *, char, const char *); static void stats_p_spy(struct Client *); /* Heres our struct for the stats table */ -struct StatsStruct -{ - char letter; - void (*handler) (struct Client *source_p); - int need_oper; - int need_admin; +struct StatsStruct { + char letter; + void (*handler) (struct Client *source_p); + int need_oper; + int need_admin; }; static void stats_dns_servers(struct Client *); @@ -125,52 +124,52 @@ static void stats_comm(struct Client *); */ static struct StatsStruct stats_cmd_table[] = { /* letter function need_oper need_admin */ - {'a', stats_dns_servers, 1, 1, }, - {'A', stats_dns_servers, 1, 1, }, - {'b', stats_delay, 1, 1, }, - {'B', stats_hash, 1, 1, }, - {'c', stats_connect, 0, 0, }, - {'C', stats_connect, 0, 0, }, - {'d', stats_tdeny, 1, 0, }, - {'D', stats_deny, 1, 0, }, - {'e', stats_exempt, 1, 0, }, - {'E', stats_events, 1, 1, }, - {'f', stats_comm, 1, 1, }, - {'F', stats_comm, 1, 1, }, - {'g', stats_prop_klines, 1, 0, }, - {'h', stats_hubleaf, 0, 0, }, - {'H', stats_hubleaf, 0, 0, }, - {'i', stats_auth, 0, 0, }, - {'I', stats_auth, 0, 0, }, - {'k', stats_tklines, 0, 0, }, - {'K', stats_klines, 0, 0, }, - {'l', NULL /* special */, 0, 0, }, - {'L', NULL /* special */, 0, 0, }, - {'m', stats_messages, 0, 0, }, - {'M', stats_messages, 0, 0, }, - {'n', stats_dnsbl, 0, 0, }, - {'o', stats_oper, 0, 0, }, - {'O', stats_privset, 1, 0, }, - {'p', stats_operedup, 0, 0, }, - {'P', stats_ports, 0, 0, }, - {'q', stats_tresv, 1, 0, }, - {'Q', stats_resv, 1, 0, }, - {'r', stats_usage, 1, 0, }, - {'R', stats_usage, 1, 0, }, - {'t', stats_tstats, 1, 0, }, - {'T', stats_tstats, 1, 0, }, - {'u', stats_uptime, 0, 0, }, - {'U', stats_shared, 1, 0, }, - {'v', stats_servers, 0, 0, }, - {'V', stats_servers, 0, 0, }, - {'x', stats_tgecos, 1, 0, }, - {'X', stats_gecos, 1, 0, }, - {'y', stats_class, 0, 0, }, - {'Y', stats_class, 0, 0, }, - {'z', stats_memory, 1, 0, }, - {'Z', stats_ziplinks, 1, 0, }, - {'?', stats_servlinks, 0, 0, }, - {(char) 0, (void (*)()) 0, 0, 0, } + {'a', stats_dns_servers, 1, 1, }, + {'A', stats_dns_servers, 1, 1, }, + {'b', stats_delay, 1, 1, }, + {'B', stats_hash, 1, 1, }, + {'c', stats_connect, 0, 0, }, + {'C', stats_connect, 0, 0, }, + {'d', stats_tdeny, 1, 0, }, + {'D', stats_deny, 1, 0, }, + {'e', stats_exempt, 1, 0, }, + {'E', stats_events, 1, 1, }, + {'f', stats_comm, 1, 1, }, + {'F', stats_comm, 1, 1, }, + {'g', stats_prop_klines, 1, 0, }, + {'h', stats_hubleaf, 0, 0, }, + {'H', stats_hubleaf, 0, 0, }, + {'i', stats_auth, 0, 0, }, + {'I', stats_auth, 0, 0, }, + {'k', stats_tklines, 0, 0, }, + {'K', stats_klines, 0, 0, }, + {'l', NULL /* special */, 0, 0, }, + {'L', NULL /* special */, 0, 0, }, + {'m', stats_messages, 0, 0, }, + {'M', stats_messages, 0, 0, }, + {'n', stats_dnsbl, 0, 0, }, + {'o', stats_oper, 0, 0, }, + {'O', stats_privset, 1, 0, }, + {'p', stats_operedup, 0, 0, }, + {'P', stats_ports, 0, 0, }, + {'q', stats_tresv, 1, 0, }, + {'Q', stats_resv, 1, 0, }, + {'r', stats_usage, 1, 0, }, + {'R', stats_usage, 1, 0, }, + {'t', stats_tstats, 1, 0, }, + {'T', stats_tstats, 1, 0, }, + {'u', stats_uptime, 0, 0, }, + {'U', stats_shared, 1, 0, }, + {'v', stats_servers, 0, 0, }, + {'V', stats_servers, 0, 0, }, + {'x', stats_tgecos, 1, 0, }, + {'X', stats_gecos, 1, 0, }, + {'y', stats_class, 0, 0, }, + {'Y', stats_class, 0, 0, }, + {'z', stats_memory, 1, 0, }, + {'Z', stats_ziplinks, 1, 0, }, + {'?', stats_servlinks, 0, 0, }, + {(char) 0, (void (*)()) 0, 0, 0, } }; /* @@ -179,150 +178,139 @@ static struct StatsStruct stats_cmd_table[] = { * parv[2] = (if present) server/mask in stats L, or target * * This will search the tables for the appropriate stats letter, - * if found execute it. + * if found execute it. */ static int m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; - int i; - char statchar; + static time_t last_used = 0; + int i; + char statchar; - statchar = parv[1][0]; + statchar = parv[1][0]; - if(MyClient(source_p) && !IsOper(source_p)) - { - /* Check the user is actually allowed to do /stats, and isnt flooding */ - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "STATS"); - sendto_one_numeric(source_p, RPL_ENDOFSTATS, - form_str(RPL_ENDOFSTATS), statchar); - return 0; - } - else - last_used = rb_current_time(); - } + if(MyClient(source_p) && !IsOper(source_p)) { + /* Check the user is actually allowed to do /stats, and isnt flooding */ + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + /* safe enough to give this on a local connect only */ + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "STATS"); + sendto_one_numeric(source_p, RPL_ENDOFSTATS, + form_str(RPL_ENDOFSTATS), statchar); + return 0; + } else + last_used = rb_current_time(); + } - if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME) - return 0; + if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME) + return 0; - if((statchar != 'L') && (statchar != 'l')) - stats_spy(source_p, statchar, NULL); + if((statchar != 'L') && (statchar != 'l')) + stats_spy(source_p, statchar, NULL); - for (i = 0; stats_cmd_table[i].letter; i++) - { - if(stats_cmd_table[i].letter == statchar) - { - /* The stats table says what privs are needed, so check --fl_ */ - /* Called for remote clients and for local opers, so check need_admin - * and need_oper - */ - if(stats_cmd_table[i].need_oper && !IsOper(source_p)) - { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - break; - } - if(stats_cmd_table[i].need_admin && !IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - break; - } + for (i = 0; stats_cmd_table[i].letter; i++) { + if(stats_cmd_table[i].letter == statchar) { + /* The stats table says what privs are needed, so check --fl_ */ + /* Called for remote clients and for local opers, so check need_admin + * and need_oper + */ + if(stats_cmd_table[i].need_oper && !IsOper(source_p)) { + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + break; + } + if(stats_cmd_table[i].need_admin && !IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + break; + } - /* Blah, stats L needs the parameters, none of the others do.. */ - if(statchar == 'L' || statchar == 'l') - stats_ltrace (source_p, parc, parv); - else - stats_cmd_table[i].handler (source_p); - } - } + /* Blah, stats L needs the parameters, none of the others do.. */ + if(statchar == 'L' || statchar == 'l') + stats_ltrace (source_p, parc, parv); + else + stats_cmd_table[i].handler (source_p); + } + } - /* Send the end of stats notice, and the stats_spy */ - sendto_one_numeric(source_p, RPL_ENDOFSTATS, - form_str(RPL_ENDOFSTATS), statchar); + /* Send the end of stats notice, and the stats_spy */ + sendto_one_numeric(source_p, RPL_ENDOFSTATS, + form_str(RPL_ENDOFSTATS), statchar); - return 0; + return 0; } static void stats_dns_servers (struct Client *source_p) { - report_dns_servers (source_p); + report_dns_servers (source_p); } static void stats_delay(struct Client *source_p) { - struct nd_entry *nd; - struct DictionaryIter iter; + struct nd_entry *nd; + struct DictionaryIter iter; - DICTIONARY_FOREACH(nd, &iter, nd_dict) - { - sendto_one_notice(source_p, ":Delaying: %s for %ld", - nd->name, (long) nd->expire); - } + DICTIONARY_FOREACH(nd, &iter, nd_dict) { + sendto_one_notice(source_p, ":Delaying: %s for %ld", + nd->name, (long) nd->expire); + } } static void stats_hash(struct Client *source_p) { - hash_stats(source_p); + hash_stats(source_p); } static void stats_connect(struct Client *source_p) { - static char buf[5]; - struct server_conf *server_p; - char *s; - rb_dlink_node *ptr; + static char buf[5]; + struct server_conf *server_p; + char *s; + rb_dlink_node *ptr; - if((ConfigFileEntry.stats_c_oper_only || - (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && - !IsOper(source_p)) - { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str(ERR_NOPRIVILEGES)); - return; - } + if((ConfigFileEntry.stats_c_oper_only || + (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && + !IsOper(source_p)) { + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str(ERR_NOPRIVILEGES)); + return; + } - RB_DLINK_FOREACH(ptr, server_conf_list.head) - { - server_p = ptr->data; + RB_DLINK_FOREACH(ptr, server_conf_list.head) { + server_p = ptr->data; - if(ServerConfIllegal(server_p)) - continue; + if(ServerConfIllegal(server_p)) + continue; - buf[0] = '\0'; - s = buf; + buf[0] = '\0'; + s = buf; - if(IsOper(source_p)) - { - if(ServerConfAutoconn(server_p)) - *s++ = 'A'; - if(ServerConfSSL(server_p)) - *s++ = 'S'; - if(ServerConfTb(server_p)) - *s++ = 'T'; - if(ServerConfCompressed(server_p)) - *s++ = 'Z'; - } + if(IsOper(source_p)) { + if(ServerConfAutoconn(server_p)) + *s++ = 'A'; + if(ServerConfSSL(server_p)) + *s++ = 'S'; + if(ServerConfTb(server_p)) + *s++ = 'T'; + if(ServerConfCompressed(server_p)) + *s++ = 'Z'; + } - if(!buf[0]) - *s++ = '*'; + if(!buf[0]) + *s++ = '*'; - *s = '\0'; + *s = '\0'; - sendto_one_numeric(source_p, RPL_STATSCLINE, - form_str(RPL_STATSCLINE), - "*@127.0.0.1", - buf, server_p->name, - server_p->port, server_p->class_name); - } + sendto_one_numeric(source_p, RPL_STATSCLINE, + form_str(RPL_STATSCLINE), + "*@127.0.0.1", + buf, server_p->name, + server_p->port, server_p->class_name); + } } /* stats_tdeny() @@ -334,32 +322,29 @@ stats_connect(struct Client *source_p) static void stats_tdeny (struct Client *source_p) { - char *host, *pass, *user, *oper_reason; - struct AddressRec *arec; - struct ConfItem *aconf; - int i; + char *host, *pass, *user, *oper_reason; + struct AddressRec *arec; + struct ConfItem *aconf; + int i; - for (i = 0; i < ATABLE_SIZE; i++) - { - for (arec = atable[i]; arec; arec = arec->next) - { - if(arec->type == CONF_DLINE) - { - aconf = arec->aconf; + for (i = 0; i < ATABLE_SIZE; i++) { + for (arec = atable[i]; arec; arec = arec->next) { + if(arec->type == CONF_DLINE) { + aconf = arec->aconf; - if(!(aconf->flags & CONF_FLAGS_TEMPORARY)) - continue; + if(!(aconf->flags & CONF_FLAGS_TEMPORARY)) + continue; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); + get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSDLINE, - form_str (RPL_STATSDLINE), - 'd', host, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - } - } + sendto_one_numeric(source_p, RPL_STATSDLINE, + form_str (RPL_STATSDLINE), + 'd', host, pass, + oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } + } + } } /* stats_deny() @@ -371,32 +356,29 @@ stats_tdeny (struct Client *source_p) static void stats_deny (struct Client *source_p) { - char *host, *pass, *user, *oper_reason; - struct AddressRec *arec; - struct ConfItem *aconf; - int i; + char *host, *pass, *user, *oper_reason; + struct AddressRec *arec; + struct ConfItem *aconf; + int i; - for (i = 0; i < ATABLE_SIZE; i++) - { - for (arec = atable[i]; arec; arec = arec->next) - { - if(arec->type == CONF_DLINE) - { - aconf = arec->aconf; + for (i = 0; i < ATABLE_SIZE; i++) { + for (arec = atable[i]; arec; arec = arec->next) { + if(arec->type == CONF_DLINE) { + aconf = arec->aconf; - if(aconf->flags & CONF_FLAGS_TEMPORARY) - continue; + if(aconf->flags & CONF_FLAGS_TEMPORARY) + continue; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); + get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSDLINE, - form_str (RPL_STATSDLINE), - 'D', host, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - } - } + sendto_one_numeric(source_p, RPL_STATSDLINE, + form_str (RPL_STATSDLINE), + 'D', host, pass, + oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } + } + } } @@ -409,306 +391,291 @@ stats_deny (struct Client *source_p) static void stats_exempt(struct Client *source_p) { - char *name, *host, *pass, *user, *classname; - struct AddressRec *arec; - struct ConfItem *aconf; - int i, port; + char *name, *host, *pass, *user, *classname; + struct AddressRec *arec; + struct ConfItem *aconf; + int i, port; - if(ConfigFileEntry.stats_e_disabled) - { - sendto_one_numeric(source_p, ERR_DISABLED, - form_str(ERR_DISABLED), "STATS e"); - return; - } + if(ConfigFileEntry.stats_e_disabled) { + sendto_one_numeric(source_p, ERR_DISABLED, + form_str(ERR_DISABLED), "STATS e"); + return; + } - for (i = 0; i < ATABLE_SIZE; i++) - { - for (arec = atable[i]; arec; arec = arec->next) - { - if(arec->type == CONF_EXEMPTDLINE) - { - aconf = arec->aconf; - get_printable_conf (aconf, &name, &host, &pass, - &user, &port, &classname); + for (i = 0; i < ATABLE_SIZE; i++) { + for (arec = atable[i]; arec; arec = arec->next) { + if(arec->type == CONF_EXEMPTDLINE) { + aconf = arec->aconf; + get_printable_conf (aconf, &name, &host, &pass, + &user, &port, &classname); - sendto_one_numeric(source_p, RPL_STATSDLINE, - form_str(RPL_STATSDLINE), - 'e', host, pass, "", ""); - } - } - }} + sendto_one_numeric(source_p, RPL_STATSDLINE, + form_str(RPL_STATSDLINE), + 'e', host, pass, "", ""); + } + } + } +} static void stats_events_cb(char *str, void *ptr) { - sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str); + sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str); } static void stats_events (struct Client *source_p) { - rb_dump_events(stats_events_cb, source_p); + rb_dump_events(stats_events_cb, source_p); } static void stats_prop_klines(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - char *user, *host, *pass, *oper_reason; + struct ConfItem *aconf; + rb_dlink_node *ptr; + char *user, *host, *pass, *oper_reason; - RB_DLINK_FOREACH(ptr, prop_bans.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, prop_bans.head) { + aconf = ptr->data; - /* Skip non-klines and deactivated klines. */ - if(aconf->status != CONF_KILL) - continue; + /* Skip non-klines and deactivated klines. */ + if(aconf->status != CONF_KILL) + continue; - get_printable_kline(source_p, aconf, &host, &pass, - &user, &oper_reason); + get_printable_kline(source_p, aconf, &host, &pass, + &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), - 'g', host, user, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), + 'g', host, user, pass, + oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } } static void stats_hubleaf(struct Client *source_p) { - struct remote_conf *hub_p; - rb_dlink_node *ptr; + struct remote_conf *hub_p; + rb_dlink_node *ptr; - if((ConfigFileEntry.stats_h_oper_only || - (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && - !IsOper(source_p)) - { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - return; - } + if((ConfigFileEntry.stats_h_oper_only || + (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && + !IsOper(source_p)) { + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + return; + } - RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) - { - hub_p = ptr->data; + RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) { + hub_p = ptr->data; - if(hub_p->flags & CONF_HUB) - sendto_one_numeric(source_p, RPL_STATSHLINE, - form_str(RPL_STATSHLINE), - hub_p->host, hub_p->server); - else - sendto_one_numeric(source_p, RPL_STATSLLINE, - form_str(RPL_STATSLLINE), - hub_p->host, hub_p->server); - } + if(hub_p->flags & CONF_HUB) + sendto_one_numeric(source_p, RPL_STATSHLINE, + form_str(RPL_STATSHLINE), + hub_p->host, hub_p->server); + else + sendto_one_numeric(source_p, RPL_STATSLLINE, + form_str(RPL_STATSLLINE), + hub_p->host, hub_p->server); + } } static void stats_auth (struct Client *source_p) { - /* Oper only, if unopered, return ERR_NOPRIVS */ - if((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper (source_p)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); + /* Oper only, if unopered, return ERR_NOPRIVS */ + if((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper (source_p)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); - /* If unopered, Only return matching auth blocks */ - else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper (source_p)) - { - struct ConfItem *aconf; - char *name, *host, *pass = "*", *user, *classname; - int port; + /* If unopered, Only return matching auth blocks */ + else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper (source_p)) { + struct ConfItem *aconf; + char *name, *host, *pass = "*", *user, *classname; + int port; - if(MyConnect (source_p)) - aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, - (struct sockaddr *)&source_p->localClient->ip, - CONF_CLIENT, - source_p->localClient->ip.ss_family, - source_p->username, NULL); - else - aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_CLIENT, - 0, source_p->username, NULL); + if(MyConnect (source_p)) + aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, + (struct sockaddr *)&source_p->localClient->ip, + CONF_CLIENT, + source_p->localClient->ip.ss_family, + source_p->username, NULL); + else + aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_CLIENT, + 0, source_p->username, NULL); - if(aconf == NULL) - return; + if(aconf == NULL) + return; - get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname); - if(!EmptyString(aconf->spasswd)) - pass = aconf->spasswd; + get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname); + if(!EmptyString(aconf->spasswd)) + pass = aconf->spasswd; - sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), - name, pass, show_iline_prefix(source_p, aconf, user), - host, port, classname); - } + sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), + name, pass, show_iline_prefix(source_p, aconf, user), + host, port, classname); + } - /* Theyre opered, or allowed to see all auth blocks */ - else - report_auth (source_p); + /* Theyre opered, or allowed to see all auth blocks */ + else + report_auth (source_p); } static void stats_tklines(struct Client *source_p) { - /* Oper only, if unopered, return ERR_NOPRIVS */ - if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); + /* Oper only, if unopered, return ERR_NOPRIVS */ + if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); - /* If unopered, Only return matching klines */ - else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) - { - struct ConfItem *aconf; - char *host, *pass, *user, *oper_reason; + /* If unopered, Only return matching klines */ + else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) { + struct ConfItem *aconf; + char *host, *pass, *user, *oper_reason; - if(MyConnect (source_p)) - aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, - (struct sockaddr *)&source_p->localClient->ip, - CONF_KILL, - source_p->localClient->ip.ss_family, - source_p->username, NULL); - else - aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, - 0, source_p->username, NULL); + if(MyConnect (source_p)) + aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, + (struct sockaddr *)&source_p->localClient->ip, + CONF_KILL, + source_p->localClient->ip.ss_family, + source_p->username, NULL); + else + aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, + 0, source_p->username, NULL); - if(aconf == NULL) - return; + if(aconf == NULL) + return; - /* dont report a permanent kline as a tkline */ - if((aconf->flags & CONF_FLAGS_TEMPORARY) == 0) - return; + /* dont report a permanent kline as a tkline */ + if((aconf->flags & CONF_FLAGS_TEMPORARY) == 0) + return; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); + get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K', - host, user, pass, oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - /* Theyre opered, or allowed to see all klines */ - else - { - struct ConfItem *aconf; - rb_dlink_node *ptr; - int i; - char *user, *host, *pass, *oper_reason; + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K', + host, user, pass, oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } + /* Theyre opered, or allowed to see all klines */ + else { + struct ConfItem *aconf; + rb_dlink_node *ptr; + int i; + char *user, *host, *pass, *oper_reason; - for(i = 0; i < LAST_TEMP_TYPE; i++) - { - RB_DLINK_FOREACH(ptr, temp_klines[i].head) - { - aconf = ptr->data; + for(i = 0; i < LAST_TEMP_TYPE; i++) { + RB_DLINK_FOREACH(ptr, temp_klines[i].head) { + aconf = ptr->data; - get_printable_kline(source_p, aconf, &host, &pass, - &user, &oper_reason); + get_printable_kline(source_p, aconf, &host, &pass, + &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), - 'k', host, user, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - } - } + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), + 'k', host, user, pass, + oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } + } + } } static void stats_klines(struct Client *source_p) { - /* Oper only, if unopered, return ERR_NOPRIVS */ - if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); + /* Oper only, if unopered, return ERR_NOPRIVS */ + if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); - /* If unopered, Only return matching klines */ - else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) - { - struct ConfItem *aconf; - char *host, *pass, *user, *oper_reason; + /* If unopered, Only return matching klines */ + else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) { + struct ConfItem *aconf; + char *host, *pass, *user, *oper_reason; - /* search for a kline */ - if(MyConnect (source_p)) - aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, - (struct sockaddr *)&source_p->localClient->ip, - CONF_KILL, - source_p->localClient->ip.ss_family, - source_p->username, NULL); - else - aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, - 0, source_p->username, NULL); + /* search for a kline */ + if(MyConnect (source_p)) + aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, + (struct sockaddr *)&source_p->localClient->ip, + CONF_KILL, + source_p->localClient->ip.ss_family, + source_p->username, NULL); + else + aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, + 0, source_p->username, NULL); - if(aconf == NULL) - return; + if(aconf == NULL) + return; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); + get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE), - aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K', - host, user, pass, oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - /* Theyre opered, or allowed to see all klines */ - else - report_Klines (source_p); + sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE), + aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K', + host, user, pass, oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } + /* Theyre opered, or allowed to see all klines */ + else + report_Klines (source_p); } static void stats_messages(struct Client *source_p) { - report_messages(source_p); + report_messages(source_p); } static void stats_dnsbl(struct Client *source_p) { - rb_dlink_node *ptr; - struct Blacklist *blptr; + rb_dlink_node *ptr; + struct Blacklist *blptr; - RB_DLINK_FOREACH(ptr, blacklist_list.head) - { - blptr = ptr->data; + RB_DLINK_FOREACH(ptr, blacklist_list.head) { + blptr = ptr->data; - /* use RPL_STATSDEBUG for now -- jilles */ - sendto_one_numeric(source_p, RPL_STATSDEBUG, "n :%d %s %s (%d)", - blptr->hits, - blptr->host, - blptr->status & CONF_ILLEGAL ? "disabled" : "active", - blptr->refcount); - } + /* use RPL_STATSDEBUG for now -- jilles */ + sendto_one_numeric(source_p, RPL_STATSDEBUG, "n :%d %s %s (%d)", + blptr->hits, + blptr->host, + blptr->status & CONF_ILLEGAL ? "disabled" : "active", + blptr->refcount); + } } static void stats_oper(struct Client *source_p) { - struct oper_conf *oper_p; - rb_dlink_node *ptr; + struct oper_conf *oper_p; + rb_dlink_node *ptr; - if(!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only) - { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - return; - } + if(!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only) { + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + return; + } - RB_DLINK_FOREACH(ptr, oper_conf_list.head) - { - oper_p = ptr->data; - - sendto_one_numeric(source_p, RPL_STATSOLINE, - form_str(RPL_STATSOLINE), - oper_p->username, oper_p->host, oper_p->name, - IsOper(source_p) ? oper_p->privset->name : "0", "-1"); - } + RB_DLINK_FOREACH(ptr, oper_conf_list.head) { + oper_p = ptr->data; + + sendto_one_numeric(source_p, RPL_STATSOLINE, + form_str(RPL_STATSOLINE), + oper_p->username, oper_p->host, oper_p->name, + IsOper(source_p) ? oper_p->privset->name : "0", "-1"); + } } static void stats_privset(struct Client *source_p) { - privilegeset_report(source_p); + privilegeset_report(source_p); } /* stats_operedup() @@ -720,329 +687,314 @@ stats_privset(struct Client *source_p) static void stats_operedup (struct Client *source_p) { - struct Client *target_p; - rb_dlink_node *oper_ptr; - unsigned int count = 0; + struct Client *target_p; + rb_dlink_node *oper_ptr; + unsigned int count = 0; - RB_DLINK_FOREACH (oper_ptr, oper_list.head) - { - target_p = oper_ptr->data; + RB_DLINK_FOREACH (oper_ptr, oper_list.head) { + target_p = oper_ptr->data; - if(IsOperInvis(target_p) && !IsOper(source_p)) - continue; + if(IsOperInvis(target_p) && !IsOper(source_p)) + continue; - if(target_p->user->away) - continue; + if(target_p->user->away) + continue; - count++; + count++; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "p :%s (%s@%s)", - target_p->name, target_p->username, - target_p->host); - } + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "p :%s (%s@%s)", + target_p->name, target_p->username, + target_p->host); + } - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "p :%u staff members", count); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "p :%u staff members", count); - stats_p_spy (source_p); + stats_p_spy (source_p); } static void stats_ports (struct Client *source_p) { - if(!IsOper (source_p) && ConfigFileEntry.stats_P_oper_only) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - else - show_ports (source_p); + if(!IsOper (source_p) && ConfigFileEntry.stats_P_oper_only) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + else + show_ports (source_p); } static void stats_tresv(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr; + int i; - RB_DLINK_FOREACH(ptr, resv_conf_list.head) - { - aconf = ptr->data; - if(aconf->hold) - sendto_one_numeric(source_p, RPL_STATSQLINE, - form_str(RPL_STATSQLINE), - 'q', aconf->port, aconf->host, aconf->passwd); - } + RB_DLINK_FOREACH(ptr, resv_conf_list.head) { + aconf = ptr->data; + if(aconf->hold) + sendto_one_numeric(source_p, RPL_STATSQLINE, + form_str(RPL_STATSQLINE), + 'q', aconf->port, aconf->host, aconf->passwd); + } - HASH_WALK(i, R_MAX, ptr, resvTable) - { - aconf = ptr->data; - if(aconf->hold) - sendto_one_numeric(source_p, RPL_STATSQLINE, - form_str(RPL_STATSQLINE), - 'q', aconf->port, aconf->host, aconf->passwd); - } - HASH_WALK_END + HASH_WALK(i, R_MAX, ptr, resvTable) { + aconf = ptr->data; + if(aconf->hold) + sendto_one_numeric(source_p, RPL_STATSQLINE, + form_str(RPL_STATSQLINE), + 'q', aconf->port, aconf->host, aconf->passwd); + } + HASH_WALK_END } static void stats_resv(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr; + int i; - RB_DLINK_FOREACH(ptr, resv_conf_list.head) - { - aconf = ptr->data; - if(!aconf->hold) - sendto_one_numeric(source_p, RPL_STATSQLINE, - form_str(RPL_STATSQLINE), - 'Q', aconf->port, aconf->host, aconf->passwd); - } + RB_DLINK_FOREACH(ptr, resv_conf_list.head) { + aconf = ptr->data; + if(!aconf->hold) + sendto_one_numeric(source_p, RPL_STATSQLINE, + form_str(RPL_STATSQLINE), + 'Q', aconf->port, aconf->host, aconf->passwd); + } - HASH_WALK(i, R_MAX, ptr, resvTable) - { - aconf = ptr->data; - if(!aconf->hold) - sendto_one_numeric(source_p, RPL_STATSQLINE, - form_str(RPL_STATSQLINE), - 'Q', aconf->port, aconf->host, aconf->passwd); - } - HASH_WALK_END + HASH_WALK(i, R_MAX, ptr, resvTable) { + aconf = ptr->data; + if(!aconf->hold) + sendto_one_numeric(source_p, RPL_STATSQLINE, + form_str(RPL_STATSQLINE), + 'Q', aconf->port, aconf->host, aconf->passwd); + } + HASH_WALK_END } static void stats_usage (struct Client *source_p) { - struct rusage rus; - time_t secs; - time_t rup; + struct rusage rus; + time_t secs; + time_t rup; #ifdef hz # define hzz hz #else # ifdef HZ # define hzz HZ # else - int hzz = 1; + int hzz = 1; # endif #endif - if(getrusage(RUSAGE_SELF, &rus) == -1) - { - sendto_one_notice(source_p, ":Getruseage error: %s.", - strerror(errno)); - return; - } - secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; - if(0 == secs) - secs = 1; + if(getrusage(RUSAGE_SELF, &rus) == -1) { + sendto_one_notice(source_p, ":Getruseage error: %s.", + strerror(errno)); + return; + } + secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; + if(0 == secs) + secs = 1; - rup = (rb_current_time() - startup_time) * hzz; - if(0 == rup) - rup = 1; - - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "R :CPU Secs %d:%d User %d:%d System %d:%d", - (int) (secs / 60), (int) (secs % 60), - (int) (rus.ru_utime.tv_sec / 60), - (int) (rus.ru_utime.tv_sec % 60), - (int) (rus.ru_stime.tv_sec / 60), - (int) (rus.ru_stime.tv_sec % 60)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "R :RSS %ld ShMem %ld Data %ld Stack %ld", - rus.ru_maxrss, (rus.ru_ixrss / rup), - (rus.ru_idrss / rup), (rus.ru_isrss / rup)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "R :Swaps %d Reclaims %d Faults %d", - (int) rus.ru_nswap, (int) rus.ru_minflt, (int) rus.ru_majflt); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "R :Block in %d out %d", - (int) rus.ru_inblock, (int) rus.ru_oublock); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "R :Msg Rcv %d Send %d", - (int) rus.ru_msgrcv, (int) rus.ru_msgsnd); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "R :Signals %d Context Vol. %d Invol %d", - (int) rus.ru_nsignals, (int) rus.ru_nvcsw, - (int) rus.ru_nivcsw); + rup = (rb_current_time() - startup_time) * hzz; + if(0 == rup) + rup = 1; + + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "R :CPU Secs %d:%d User %d:%d System %d:%d", + (int) (secs / 60), (int) (secs % 60), + (int) (rus.ru_utime.tv_sec / 60), + (int) (rus.ru_utime.tv_sec % 60), + (int) (rus.ru_stime.tv_sec / 60), + (int) (rus.ru_stime.tv_sec % 60)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "R :RSS %ld ShMem %ld Data %ld Stack %ld", + rus.ru_maxrss, (rus.ru_ixrss / rup), + (rus.ru_idrss / rup), (rus.ru_isrss / rup)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "R :Swaps %d Reclaims %d Faults %d", + (int) rus.ru_nswap, (int) rus.ru_minflt, (int) rus.ru_majflt); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "R :Block in %d out %d", + (int) rus.ru_inblock, (int) rus.ru_oublock); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "R :Msg Rcv %d Send %d", + (int) rus.ru_msgrcv, (int) rus.ru_msgsnd); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "R :Signals %d Context Vol. %d Invol %d", + (int) rus.ru_nsignals, (int) rus.ru_nvcsw, + (int) rus.ru_nivcsw); } static void stats_tstats (struct Client *source_p) { - struct Client *target_p; - struct ServerStatistics sp; - rb_dlink_node *ptr; + struct Client *target_p; + struct ServerStatistics sp; + rb_dlink_node *ptr; - memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics)); + memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics)); - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - sp.is_sbs += target_p->localClient->sendB; - sp.is_sbr += target_p->localClient->receiveB; - sp.is_sti += (unsigned long long)(rb_current_time() - target_p->localClient->firsttime); - sp.is_sv++; - } + sp.is_sbs += target_p->localClient->sendB; + sp.is_sbr += target_p->localClient->receiveB; + sp.is_sti += (unsigned long long)(rb_current_time() - target_p->localClient->firsttime); + sp.is_sv++; + } - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, lclient_list.head) { + target_p = ptr->data; - sp.is_cbs += target_p->localClient->sendB; - sp.is_cbr += target_p->localClient->receiveB; - sp.is_cti += (unsigned long long)(rb_current_time() - target_p->localClient->firsttime); - sp.is_cl++; - } + sp.is_cbs += target_p->localClient->sendB; + sp.is_cbr += target_p->localClient->receiveB; + sp.is_cti += (unsigned long long)(rb_current_time() - target_p->localClient->firsttime); + sp.is_cl++; + } - RB_DLINK_FOREACH(ptr, unknown_list.head) - { - sp.is_ni++; - } + RB_DLINK_FOREACH(ptr, unknown_list.head) { + sp.is_ni++; + } - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :accepts %u refused %u", sp.is_ac, sp.is_ref); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :rejected %u delaying %lu", - sp.is_rej, delay_exit_length()); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :throttled refused %u throttle list size %lu", sp.is_thr, throttle_size()); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :nicks being delayed %lu", - get_nd_count()); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :unknown commands %u prefixes %u", - sp.is_unco, sp.is_unpf); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :nick collisions %u saves %u unknown closes %u", - sp.is_kill, sp.is_save, sp.is_ni); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :wrong direction %u empty %u", - sp.is_wrdi, sp.is_empt); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :numerics seen %u", sp.is_num); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :tgchange blocked msgs %u restricted addrs %lu", - sp.is_tgch, rb_dlink_list_length(&tgchange_list)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :auth successes %u fails %u", - sp.is_asuc, sp.is_abad); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :sasl successes %u fails %u", - sp.is_ssuc, sp.is_sbad); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server"); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :connected %u %u", sp.is_cl, sp.is_sv); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :bytes sent %lluK %lluK", - sp.is_cbs / 1024, - sp.is_sbs / 1024); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :bytes recv %lluK %lluK", - sp.is_cbr / 1024, - sp.is_sbr / 1024); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :time connected %llu %llu", - sp.is_cti, sp.is_sti); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :accepts %u refused %u", sp.is_ac, sp.is_ref); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :rejected %u delaying %lu", + sp.is_rej, delay_exit_length()); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :throttled refused %u throttle list size %lu", sp.is_thr, throttle_size()); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :nicks being delayed %lu", + get_nd_count()); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :unknown commands %u prefixes %u", + sp.is_unco, sp.is_unpf); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :nick collisions %u saves %u unknown closes %u", + sp.is_kill, sp.is_save, sp.is_ni); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :wrong direction %u empty %u", + sp.is_wrdi, sp.is_empt); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :numerics seen %u", sp.is_num); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :tgchange blocked msgs %u restricted addrs %lu", + sp.is_tgch, rb_dlink_list_length(&tgchange_list)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :auth successes %u fails %u", + sp.is_asuc, sp.is_abad); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :sasl successes %u fails %u", + sp.is_ssuc, sp.is_sbad); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server"); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :connected %u %u", sp.is_cl, sp.is_sv); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :bytes sent %lluK %lluK", + sp.is_cbs / 1024, + sp.is_sbs / 1024); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :bytes recv %lluK %lluK", + sp.is_cbr / 1024, + sp.is_sbr / 1024); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :time connected %llu %llu", + sp.is_cti, sp.is_sti); } static void stats_uptime (struct Client *source_p) { - time_t now; + time_t now; - now = rb_current_time() - startup_time; - sendto_one_numeric(source_p, RPL_STATSUPTIME, - form_str (RPL_STATSUPTIME), - now / 86400, (now / 3600) % 24, - (now / 60) % 60, now % 60); - sendto_one_numeric(source_p, RPL_STATSCONN, - form_str (RPL_STATSCONN), - MaxConnectionCount, MaxClientCount, - Count.totalrestartcount); + now = rb_current_time() - startup_time; + sendto_one_numeric(source_p, RPL_STATSUPTIME, + form_str (RPL_STATSUPTIME), + now / 86400, (now / 3600) % 24, + (now / 60) % 60, now % 60); + sendto_one_numeric(source_p, RPL_STATSCONN, + form_str (RPL_STATSCONN), + MaxConnectionCount, MaxClientCount, + Count.totalrestartcount); } -struct shared_flags -{ - int flag; - char letter; +struct shared_flags { + int flag; + char letter; }; -static struct shared_flags shared_flagtable[] = -{ - { SHARED_PKLINE, 'K' }, - { SHARED_TKLINE, 'k' }, - { SHARED_UNKLINE, 'U' }, - { SHARED_PXLINE, 'X' }, - { SHARED_TXLINE, 'x' }, - { SHARED_UNXLINE, 'Y' }, - { SHARED_PRESV, 'Q' }, - { SHARED_TRESV, 'q' }, - { SHARED_UNRESV, 'R' }, - { SHARED_LOCOPS, 'L' }, - { SHARED_REHASH, 'H' }, - { SHARED_TDLINE, 'd' }, - { SHARED_PDLINE, 'D' }, - { SHARED_UNDLINE, 'E' }, - { SHARED_DIE, 'I' }, - { SHARED_MODULE, 'M' }, - { 0, '\0'} +static struct shared_flags shared_flagtable[] = { + { SHARED_PKLINE, 'K' }, + { SHARED_TKLINE, 'k' }, + { SHARED_UNKLINE, 'U' }, + { SHARED_PXLINE, 'X' }, + { SHARED_TXLINE, 'x' }, + { SHARED_UNXLINE, 'Y' }, + { SHARED_PRESV, 'Q' }, + { SHARED_TRESV, 'q' }, + { SHARED_UNRESV, 'R' }, + { SHARED_LOCOPS, 'L' }, + { SHARED_REHASH, 'H' }, + { SHARED_TDLINE, 'd' }, + { SHARED_PDLINE, 'D' }, + { SHARED_UNDLINE, 'E' }, + { SHARED_DIE, 'I' }, + { SHARED_MODULE, 'M' }, + { 0, '\0'} }; static void stats_shared (struct Client *source_p) { - struct remote_conf *shared_p; - rb_dlink_node *ptr; - char buf[sizeof(shared_flagtable)/sizeof(shared_flagtable[0])]; - char *p; - int i; + struct remote_conf *shared_p; + rb_dlink_node *ptr; + char buf[sizeof(shared_flagtable)/sizeof(shared_flagtable[0])]; + char *p; + int i; - RB_DLINK_FOREACH(ptr, shared_conf_list.head) - { - shared_p = ptr->data; + RB_DLINK_FOREACH(ptr, shared_conf_list.head) { + shared_p = ptr->data; - p = buf; + p = buf; - *p++ = 'c'; + *p++ = 'c'; - for(i = 0; shared_flagtable[i].flag != 0; i++) - { - if(shared_p->flags & shared_flagtable[i].flag) - *p++ = shared_flagtable[i].letter; - } + for(i = 0; shared_flagtable[i].flag != 0; i++) { + if(shared_p->flags & shared_flagtable[i].flag) + *p++ = shared_flagtable[i].letter; + } - *p = '\0'; + *p = '\0'; - sendto_one_numeric(source_p, RPL_STATSULINE, - form_str(RPL_STATSULINE), - shared_p->server, shared_p->username, - shared_p->host, buf); - } + sendto_one_numeric(source_p, RPL_STATSULINE, + form_str(RPL_STATSULINE), + shared_p->server, shared_p->username, + shared_p->host, buf); + } - RB_DLINK_FOREACH(ptr, cluster_conf_list.head) - { - shared_p = ptr->data; + RB_DLINK_FOREACH(ptr, cluster_conf_list.head) { + shared_p = ptr->data; - p = buf; + p = buf; - *p++ = 'C'; + *p++ = 'C'; - for(i = 0; shared_flagtable[i].flag != 0; i++) - { - if(shared_p->flags & shared_flagtable[i].flag) - *p++ = shared_flagtable[i].letter; - } + for(i = 0; shared_flagtable[i].flag != 0; i++) { + if(shared_p->flags & shared_flagtable[i].flag) + *p++ = shared_flagtable[i].letter; + } - *p = '\0'; + *p = '\0'; - sendto_one_numeric(source_p, RPL_STATSULINE, - form_str(RPL_STATSULINE), - shared_p->server, "*", "*", buf); - } + sendto_one_numeric(source_p, RPL_STATSULINE, + form_str(RPL_STATSULINE), + shared_p->server, "*", "*", buf); + } } /* stats_servers() @@ -1054,577 +1006,544 @@ stats_shared (struct Client *source_p) static void stats_servers (struct Client *source_p) { - struct Client *target_p; - rb_dlink_node *ptr; - time_t seconds; - int days, hours, minutes; - int j = 0; + struct Client *target_p; + rb_dlink_node *ptr; + time_t seconds; + int days, hours, minutes; + int j = 0; - if(ConfigServerHide.flatten_links && !IsOper(source_p) && - !IsExemptShide(source_p)) - { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - return; - } + if(ConfigServerHide.flatten_links && !IsOper(source_p) && + !IsExemptShide(source_p)) { + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + return; + } - RB_DLINK_FOREACH (ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH (ptr, serv_list.head) { + target_p = ptr->data; - j++; - seconds = rb_current_time() - target_p->localClient->firsttime; + j++; + seconds = rb_current_time() - target_p->localClient->firsttime; - days = (int) (seconds / 86400); - seconds %= 86400; - hours = (int) (seconds / 3600); - seconds %= 3600; - minutes = (int) (seconds / 60); - seconds %= 60; + days = (int) (seconds / 86400); + seconds %= 86400; + hours = (int) (seconds / 3600); + seconds %= 3600; + minutes = (int) (seconds / 60); + seconds %= 60; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "V :%s (%s!*@*) Idle: %d SendQ: %d " - "Connected: %d day%s, %d:%02d:%02d", - target_p->name, - (target_p->serv->by[0] ? target_p->serv->by : "Remote."), - (int) (rb_current_time() - target_p->localClient->lasttime), - (int) rb_linebuf_len (&target_p->localClient->buf_sendq), - days, (days == 1) ? "" : "s", hours, minutes, - (int) seconds); - } + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "V :%s (%s!*@*) Idle: %d SendQ: %d " + "Connected: %d day%s, %d:%02d:%02d", + target_p->name, + (target_p->serv->by[0] ? target_p->serv->by : "Remote."), + (int) (rb_current_time() - target_p->localClient->lasttime), + (int) rb_linebuf_len (&target_p->localClient->buf_sendq), + days, (days == 1) ? "" : "s", hours, minutes, + (int) seconds); + } - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "V :%d Server(s)", j); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "V :%d Server(s)", j); } static void stats_tgecos(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, xline_conf_list.head) { + aconf = ptr->data; - if(aconf->hold) - sendto_one_numeric(source_p, RPL_STATSXLINE, - form_str(RPL_STATSXLINE), - 'x', aconf->port, aconf->host, - aconf->passwd); - } + if(aconf->hold) + sendto_one_numeric(source_p, RPL_STATSXLINE, + form_str(RPL_STATSXLINE), + 'x', aconf->port, aconf->host, + aconf->passwd); + } } static void stats_gecos(struct Client *source_p) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, xline_conf_list.head) { + aconf = ptr->data; - if(!aconf->hold) - sendto_one_numeric(source_p, RPL_STATSXLINE, - form_str(RPL_STATSXLINE), - 'X', aconf->port, aconf->host, - aconf->passwd); - } + if(!aconf->hold) + sendto_one_numeric(source_p, RPL_STATSXLINE, + form_str(RPL_STATSXLINE), + 'X', aconf->port, aconf->host, + aconf->passwd); + } } static void stats_class(struct Client *source_p) { - if(ConfigFileEntry.stats_y_oper_only && !IsOper(source_p)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - else - report_classes(source_p); + if(ConfigFileEntry.stats_y_oper_only && !IsOper(source_p)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + else + report_classes(source_p); } static void stats_memory (struct Client *source_p) { - struct Client *target_p; - struct Channel *chptr; - struct Ban *actualBan; - rb_dlink_node *rb_dlink; - rb_dlink_node *ptr; - int channel_count = 0; - int local_client_conf_count = 0; /* local client conf links */ - int users_counted = 0; /* user structs */ + struct Client *target_p; + struct Channel *chptr; + struct Ban *actualBan; + rb_dlink_node *rb_dlink; + rb_dlink_node *ptr; + int channel_count = 0; + int local_client_conf_count = 0; /* local client conf links */ + int users_counted = 0; /* user structs */ - int channel_users = 0; - int channel_invites = 0; - int channel_bans = 0; - int channel_except = 0; - int channel_invex = 0; - int channel_quiets = 0; + int channel_users = 0; + int channel_invites = 0; + int channel_bans = 0; + int channel_except = 0; + int channel_invex = 0; + int channel_quiets = 0; - int class_count = 0; /* classes */ - int conf_count = 0; /* conf lines */ - int users_invited_count = 0; /* users invited */ - int user_channels = 0; /* users in channels */ - int aways_counted = 0; - size_t number_servers_cached; /* number of servers cached by scache */ + int class_count = 0; /* classes */ + int conf_count = 0; /* conf lines */ + int users_invited_count = 0; /* users invited */ + int user_channels = 0; /* users in channels */ + int aways_counted = 0; + size_t number_servers_cached; /* number of servers cached by scache */ - size_t channel_memory = 0; - size_t channel_ban_memory = 0; - size_t channel_except_memory = 0; - size_t channel_invex_memory = 0; - size_t channel_quiet_memory = 0; + size_t channel_memory = 0; + size_t channel_ban_memory = 0; + size_t channel_except_memory = 0; + size_t channel_invex_memory = 0; + size_t channel_quiet_memory = 0; - size_t away_memory = 0; /* memory used by aways */ - size_t ww = 0; /* whowas array count */ - size_t wwm = 0; /* whowas array memory used */ - size_t conf_memory = 0; /* memory used by conf lines */ - size_t mem_servers_cached; /* memory used by scache */ + size_t away_memory = 0; /* memory used by aways */ + size_t ww = 0; /* whowas array count */ + size_t wwm = 0; /* whowas array memory used */ + size_t conf_memory = 0; /* memory used by conf lines */ + size_t mem_servers_cached; /* memory used by scache */ - size_t linebuf_count = 0; - size_t linebuf_memory_used = 0; + size_t linebuf_count = 0; + size_t linebuf_memory_used = 0; - size_t total_channel_memory = 0; - size_t totww = 0; + size_t total_channel_memory = 0; + size_t totww = 0; - size_t local_client_count = 0; - size_t local_client_memory_used = 0; + size_t local_client_count = 0; + size_t local_client_memory_used = 0; - size_t remote_client_count = 0; - size_t remote_client_memory_used = 0; + size_t remote_client_count = 0; + size_t remote_client_memory_used = 0; - size_t total_memory = 0; + size_t total_memory = 0; - count_whowas_memory(&ww, &wwm); + count_whowas_memory(&ww, &wwm); - RB_DLINK_FOREACH(ptr, global_client_list.head) - { - target_p = ptr->data; - if(MyConnect(target_p)) - { - local_client_conf_count++; - } + RB_DLINK_FOREACH(ptr, global_client_list.head) { + target_p = ptr->data; + if(MyConnect(target_p)) { + local_client_conf_count++; + } - if(target_p->user) - { - users_counted++; - users_invited_count += rb_dlink_list_length(&target_p->user->invited); - user_channels += rb_dlink_list_length(&target_p->user->channel); - if(target_p->user->away) - { - aways_counted++; - away_memory += (strlen(target_p->user->away) + 1); - } - } - } + if(target_p->user) { + users_counted++; + users_invited_count += rb_dlink_list_length(&target_p->user->invited); + user_channels += rb_dlink_list_length(&target_p->user->channel); + if(target_p->user->away) { + aways_counted++; + away_memory += (strlen(target_p->user->away) + 1); + } + } + } - /* Count up all channels, ban lists, except lists, Invex lists */ - RB_DLINK_FOREACH(ptr, global_channel_list.head) - { - chptr = ptr->data; - channel_count++; - channel_memory += (strlen(chptr->chname) + sizeof(struct Channel)); + /* Count up all channels, ban lists, except lists, Invex lists */ + RB_DLINK_FOREACH(ptr, global_channel_list.head) { + chptr = ptr->data; + channel_count++; + channel_memory += (strlen(chptr->chname) + sizeof(struct Channel)); - channel_users += rb_dlink_list_length(&chptr->members); - channel_invites += rb_dlink_list_length(&chptr->invites); + channel_users += rb_dlink_list_length(&chptr->members); + channel_invites += rb_dlink_list_length(&chptr->invites); - RB_DLINK_FOREACH(rb_dlink, chptr->banlist.head) - { - actualBan = rb_dlink->data; - channel_bans++; + RB_DLINK_FOREACH(rb_dlink, chptr->banlist.head) { + actualBan = rb_dlink->data; + channel_bans++; - channel_ban_memory += sizeof(rb_dlink_node) + sizeof(struct Ban); - } + channel_ban_memory += sizeof(rb_dlink_node) + sizeof(struct Ban); + } - RB_DLINK_FOREACH(rb_dlink, chptr->exceptlist.head) - { - actualBan = rb_dlink->data; - channel_except++; + RB_DLINK_FOREACH(rb_dlink, chptr->exceptlist.head) { + actualBan = rb_dlink->data; + channel_except++; - channel_except_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); - } + channel_except_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); + } - RB_DLINK_FOREACH(rb_dlink, chptr->invexlist.head) - { - actualBan = rb_dlink->data; - channel_invex++; + RB_DLINK_FOREACH(rb_dlink, chptr->invexlist.head) { + actualBan = rb_dlink->data; + channel_invex++; - channel_invex_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); - } + channel_invex_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); + } - RB_DLINK_FOREACH(rb_dlink, chptr->quietlist.head) - { - actualBan = rb_dlink->data; - channel_quiets++; + RB_DLINK_FOREACH(rb_dlink, chptr->quietlist.head) { + actualBan = rb_dlink->data; + channel_quiets++; - channel_quiet_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); - } - } + channel_quiet_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); + } + } - /* count up all classes */ + /* count up all classes */ - class_count = rb_dlink_list_length(&class_list) + 1; + class_count = rb_dlink_list_length(&class_list) + 1; - rb_count_rb_linebuf_memory(&linebuf_count, &linebuf_memory_used); + rb_count_rb_linebuf_memory(&linebuf_count, &linebuf_memory_used); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Users %u(%lu) Invites %u(%lu)", - users_counted, - (unsigned long) users_counted * sizeof(struct User), - users_invited_count, - (unsigned long) users_invited_count * sizeof(rb_dlink_node)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Users %u(%lu) Invites %u(%lu)", + users_counted, + (unsigned long) users_counted * sizeof(struct User), + users_invited_count, + (unsigned long) users_invited_count * sizeof(rb_dlink_node)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :User channels %u(%lu) Aways %u(%d)", - user_channels, - (unsigned long) user_channels * sizeof(rb_dlink_node), - aways_counted, (int) away_memory); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :User channels %u(%lu) Aways %u(%d)", + user_channels, + (unsigned long) user_channels * sizeof(rb_dlink_node), + aways_counted, (int) away_memory); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Attached confs %u(%lu)", - local_client_conf_count, - (unsigned long) local_client_conf_count * sizeof(rb_dlink_node)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Attached confs %u(%lu)", + local_client_conf_count, + (unsigned long) local_client_conf_count * sizeof(rb_dlink_node)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Conflines %u(%d)", conf_count, (int) conf_memory); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Conflines %u(%d)", conf_count, (int) conf_memory); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Classes %u(%lu)", - class_count, - (unsigned long) class_count * sizeof(struct Class)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Classes %u(%lu)", + class_count, + (unsigned long) class_count * sizeof(struct Class)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Channels %u(%d)", - channel_count, (int) channel_memory); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Channels %u(%d)", + channel_count, (int) channel_memory); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)", - channel_bans, (int) channel_ban_memory, - channel_except, (int) channel_except_memory, - channel_invex, (int) channel_invex_memory, - channel_quiets, (int) channel_quiet_memory); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)", + channel_bans, (int) channel_ban_memory, + channel_except, (int) channel_except_memory, + channel_invex, (int) channel_invex_memory, + channel_quiets, (int) channel_quiet_memory); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Channel members %u(%lu) invite %u(%lu)", - channel_users, - (unsigned long) channel_users * sizeof(rb_dlink_node), - channel_invites, - (unsigned long) channel_invites * sizeof(rb_dlink_node)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Channel members %u(%lu) invite %u(%lu)", + channel_users, + (unsigned long) channel_users * sizeof(rb_dlink_node), + channel_invites, + (unsigned long) channel_invites * sizeof(rb_dlink_node)); - total_channel_memory = channel_memory + - channel_ban_memory + - channel_users * sizeof(rb_dlink_node) + channel_invites * sizeof(rb_dlink_node); + total_channel_memory = channel_memory + + channel_ban_memory + + channel_users * sizeof(rb_dlink_node) + channel_invites * sizeof(rb_dlink_node); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Whowas array %ld(%ld)", - (long)ww, (long)wwm); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Whowas array %ld(%ld)", + (long)ww, (long)wwm); - totww = wwm; + totww = wwm; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Hash: client %u(%ld) chan %u(%ld)", - U_MAX, (long)(U_MAX * sizeof(rb_dlink_list)), - CH_MAX, (long)(CH_MAX * sizeof(rb_dlink_list))); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Hash: client %u(%ld) chan %u(%ld)", + U_MAX, (long)(U_MAX * sizeof(rb_dlink_list)), + CH_MAX, (long)(CH_MAX * sizeof(rb_dlink_list))); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :linebuf %ld(%ld)", - (long)linebuf_count, (long)linebuf_memory_used); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :linebuf %ld(%ld)", + (long)linebuf_count, (long)linebuf_memory_used); - count_scache(&number_servers_cached, &mem_servers_cached); + count_scache(&number_servers_cached, &mem_servers_cached); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :scache %ld(%ld)", - (long)number_servers_cached, (long)mem_servers_cached); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :scache %ld(%ld)", + (long)number_servers_cached, (long)mem_servers_cached); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :hostname hash %d(%ld)", - HOST_MAX, (long)HOST_MAX * sizeof(rb_dlink_list)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :hostname hash %d(%ld)", + HOST_MAX, (long)HOST_MAX * sizeof(rb_dlink_list)); - total_memory = totww + total_channel_memory + conf_memory + - class_count * sizeof(struct Class); + total_memory = totww + total_channel_memory + conf_memory + + class_count * sizeof(struct Class); - total_memory += mem_servers_cached; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Total: whowas %d channel %d conf %d", - (int) totww, (int) total_channel_memory, - (int) conf_memory); + total_memory += mem_servers_cached; + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Total: whowas %d channel %d conf %d", + (int) totww, (int) total_channel_memory, + (int) conf_memory); - count_local_client_memory(&local_client_count, &local_client_memory_used); - total_memory += local_client_memory_used; + count_local_client_memory(&local_client_count, &local_client_memory_used); + total_memory += local_client_memory_used; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Local client Memory in use: %ld(%ld)", - (long)local_client_count, (long)local_client_memory_used); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Local client Memory in use: %ld(%ld)", + (long)local_client_count, (long)local_client_memory_used); - count_remote_client_memory(&remote_client_count, &remote_client_memory_used); - total_memory += remote_client_memory_used; + count_remote_client_memory(&remote_client_count, &remote_client_memory_used); + total_memory += remote_client_memory_used; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "z :Remote client Memory in use: %ld(%ld)", - (long)remote_client_count, - (long)remote_client_memory_used); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "z :Remote client Memory in use: %ld(%ld)", + (long)remote_client_count, + (long)remote_client_memory_used); } static void stats_ziplinks (struct Client *source_p) { - rb_dlink_node *ptr; - struct Client *target_p; - struct ZipStats *zipstats; - int sent_data = 0; - char buf[128], buf1[128]; - RB_DLINK_FOREACH (ptr, serv_list.head) - { - target_p = ptr->data; - if(IsCapable (target_p, CAP_ZIP)) - { - zipstats = target_p->localClient->zipstats; - sprintf(buf, "%.2f%%", zipstats->out_ratio); - sprintf(buf1, "%.2f%%", zipstats->in_ratio); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "Z :ZipLinks stats for %s send[%s compression " - "(%llu kB data/%llu kB wire)] recv[%s compression " - "(%llu kB data/%llu kB wire)]", - target_p->name, - buf, zipstats->out >> 10, - zipstats->out_wire >> 10, buf1, - zipstats->in >> 10, zipstats->in_wire >> 10); - sent_data++; - } - } + rb_dlink_node *ptr; + struct Client *target_p; + struct ZipStats *zipstats; + int sent_data = 0; + char buf[128], buf1[128]; + RB_DLINK_FOREACH (ptr, serv_list.head) { + target_p = ptr->data; + if(IsCapable (target_p, CAP_ZIP)) { + zipstats = target_p->localClient->zipstats; + sprintf(buf, "%.2f%%", zipstats->out_ratio); + sprintf(buf1, "%.2f%%", zipstats->in_ratio); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "Z :ZipLinks stats for %s send[%s compression " + "(%llu kB data/%llu kB wire)] recv[%s compression " + "(%llu kB data/%llu kB wire)]", + target_p->name, + buf, zipstats->out >> 10, + zipstats->out_wire >> 10, buf1, + zipstats->in >> 10, zipstats->in_wire >> 10); + sent_data++; + } + } - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "Z :%u ziplink(s)", sent_data); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "Z :%u ziplink(s)", sent_data); } static void stats_servlinks (struct Client *source_p) { - static char Sformat[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s"; - long uptime, sendK, receiveK; - struct Client *target_p; - rb_dlink_node *ptr; - int j = 0; - char buf[128]; + static char Sformat[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s"; + long uptime, sendK, receiveK; + struct Client *target_p; + rb_dlink_node *ptr; + int j = 0; + char buf[128]; - if(ConfigServerHide.flatten_links && !IsOper (source_p) && - !IsExemptShide(source_p)) - { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, - form_str (ERR_NOPRIVILEGES)); - return; - } + if(ConfigServerHide.flatten_links && !IsOper (source_p) && + !IsExemptShide(source_p)) { + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, + form_str (ERR_NOPRIVILEGES)); + return; + } - sendK = receiveK = 0; + sendK = receiveK = 0; - RB_DLINK_FOREACH (ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH (ptr, serv_list.head) { + target_p = ptr->data; - j++; - sendK += target_p->localClient->sendK; - receiveK += target_p->localClient->receiveK; + j++; + sendK += target_p->localClient->sendK; + receiveK += target_p->localClient->receiveK; - sendto_one(source_p, Sformat, - get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p), - target_p->name, - (int) rb_linebuf_len (&target_p->localClient->buf_sendq), - (int) target_p->localClient->sendM, - (int) target_p->localClient->sendK, - (int) target_p->localClient->receiveM, - (int) target_p->localClient->receiveK, - rb_current_time() - target_p->localClient->firsttime, - (rb_current_time() > target_p->localClient->lasttime) ? - (rb_current_time() - target_p->localClient->lasttime) : 0, - IsOper (source_p) ? show_capabilities (target_p) : "TS"); - } + sendto_one(source_p, Sformat, + get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p), + target_p->name, + (int) rb_linebuf_len (&target_p->localClient->buf_sendq), + (int) target_p->localClient->sendM, + (int) target_p->localClient->sendK, + (int) target_p->localClient->receiveM, + (int) target_p->localClient->receiveK, + rb_current_time() - target_p->localClient->firsttime, + (rb_current_time() > target_p->localClient->lasttime) ? + (rb_current_time() - target_p->localClient->lasttime) : 0, + IsOper (source_p) ? show_capabilities (target_p) : "TS"); + } - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "? :%u total server(s)", j); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "? :%u total server(s)", j); - snprintf(buf, sizeof buf, "%7.2f", _GMKv ((sendK))); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "? :Sent total : %s %s", - buf, _GMKs (sendK)); - snprintf(buf, sizeof buf, "%7.2f", _GMKv ((receiveK))); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "? :Recv total : %s %s", - buf, _GMKs (receiveK)); + snprintf(buf, sizeof buf, "%7.2f", _GMKv ((sendK))); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "? :Sent total : %s %s", + buf, _GMKs (sendK)); + snprintf(buf, sizeof buf, "%7.2f", _GMKv ((receiveK))); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "? :Recv total : %s %s", + buf, _GMKs (receiveK)); - uptime = (rb_current_time() - startup_time); - snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)", - _GMKv (me.localClient->sendK), - _GMKs (me.localClient->sendK), - (float) ((float) me.localClient->sendK / (float) uptime)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server send: %s", buf); - snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)", - _GMKv (me.localClient->receiveK), - _GMKs (me.localClient->receiveK), - (float) ((float) me.localClient->receiveK / (float) uptime)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server recv: %s", buf); + uptime = (rb_current_time() - startup_time); + snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)", + _GMKv (me.localClient->sendK), + _GMKs (me.localClient->sendK), + (float) ((float) me.localClient->sendK / (float) uptime)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server send: %s", buf); + snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)", + _GMKv (me.localClient->receiveK), + _GMKs (me.localClient->receiveK), + (float) ((float) me.localClient->receiveK / (float) uptime)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server recv: %s", buf); } static void stats_ltrace(struct Client *source_p, int parc, const char *parv[]) { - int doall = 0; - int wilds = 0; - const char *name; - char statchar = parv[1][0]; + int doall = 0; + int wilds = 0; + const char *name; + char statchar = parv[1][0]; - /* this is def targeted at us somehow.. */ - if(parc > 2 && !EmptyString(parv[2])) - { - /* directed at us generically? */ - if(match(parv[2], me.name) || - (!MyClient(source_p) && !irccmp(parv[2], me.id))) - { - name = me.name; - doall = 1; - } - else - { - name = parv[2]; - wilds = strchr(name, '*') || strchr(name, '?'); - } + /* this is def targeted at us somehow.. */ + if(parc > 2 && !EmptyString(parv[2])) { + /* directed at us generically? */ + if(match(parv[2], me.name) || + (!MyClient(source_p) && !irccmp(parv[2], me.id))) { + name = me.name; + doall = 1; + } else { + name = parv[2]; + wilds = strchr(name, '*') || strchr(name, '?'); + } - /* must be directed at a specific person thats not us */ - if(!doall && !wilds) - { - struct Client *target_p; + /* must be directed at a specific person thats not us */ + if(!doall && !wilds) { + struct Client *target_p; - if(MyClient(source_p)) - target_p = find_named_person(name); - else - target_p = find_person(name); + if(MyClient(source_p)) + target_p = find_named_person(name); + else + target_p = find_person(name); - if(target_p != NULL) - { - stats_spy(source_p, statchar, target_p->name); - stats_l_client(source_p, target_p, statchar); - } - else - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), - name); + if(target_p != NULL) { + stats_spy(source_p, statchar, target_p->name); + stats_l_client(source_p, target_p, statchar); + } else + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), + name); - return; - } - } - else - { - name = me.name; - doall = 1; - } + return; + } + } else { + name = me.name; + doall = 1; + } - stats_spy(source_p, statchar, name); + stats_spy(source_p, statchar, name); - if(doall) - { - /* local opers get everyone */ - if(MyOper(source_p)) - { - stats_l_list(source_p, name, doall, wilds, &unknown_list, statchar); - stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar); - } - else - { - /* they still need themselves if theyre local.. */ - if(MyClient(source_p)) - stats_l_client(source_p, source_p, statchar); + if(doall) { + /* local opers get everyone */ + if(MyOper(source_p)) { + stats_l_list(source_p, name, doall, wilds, &unknown_list, statchar); + stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar); + } else { + /* they still need themselves if theyre local.. */ + if(MyClient(source_p)) + stats_l_client(source_p, source_p, statchar); - stats_l_list(source_p, name, doall, wilds, &local_oper_list, statchar); - } + stats_l_list(source_p, name, doall, wilds, &local_oper_list, statchar); + } - if (!ConfigServerHide.flatten_links || IsOper(source_p) || - IsExemptShide(source_p)) - stats_l_list(source_p, name, doall, wilds, &serv_list, statchar); + if (!ConfigServerHide.flatten_links || IsOper(source_p) || + IsExemptShide(source_p)) + stats_l_list(source_p, name, doall, wilds, &serv_list, statchar); - return; - } + return; + } - /* ok, at this point theyre looking for a specific client whos on - * our server.. but it contains a wildcard. --fl - */ - stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar); + /* ok, at this point theyre looking for a specific client whos on + * our server.. but it contains a wildcard. --fl + */ + stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar); - return; + return; } static void stats_l_list(struct Client *source_p, const char *name, int doall, int wilds, - rb_dlink_list * list, char statchar) + rb_dlink_list * list, char statchar) { - rb_dlink_node *ptr; - struct Client *target_p; + rb_dlink_node *ptr; + struct Client *target_p; - /* send information about connections which match. note, we - * dont need tests for IsInvisible(), because non-opers will - * never get here for normal clients --fl - */ - RB_DLINK_FOREACH(ptr, list->head) - { - target_p = ptr->data; + /* send information about connections which match. note, we + * dont need tests for IsInvisible(), because non-opers will + * never get here for normal clients --fl + */ + RB_DLINK_FOREACH(ptr, list->head) { + target_p = ptr->data; - if(!doall && wilds && !match(name, target_p->name)) - continue; + if(!doall && wilds && !match(name, target_p->name)) + continue; - stats_l_client(source_p, target_p, statchar); - } + stats_l_client(source_p, target_p, statchar); + } } void stats_l_client(struct Client *source_p, struct Client *target_p, - char statchar) + char statchar) { - if(IsAnyServer(target_p)) - { - sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, - target_p->name, - (int) rb_linebuf_len(&target_p->localClient->buf_sendq), - (int) target_p->localClient->sendM, - (int) target_p->localClient->sendK, - (int) target_p->localClient->receiveM, - (int) target_p->localClient->receiveK, - rb_current_time() - target_p->localClient->firsttime, - (rb_current_time() > target_p->localClient->lasttime) ? - (rb_current_time() - target_p->localClient->lasttime) : 0, - IsOper(source_p) ? show_capabilities(target_p) : "-"); - } + if(IsAnyServer(target_p)) { + sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, + target_p->name, + (int) rb_linebuf_len(&target_p->localClient->buf_sendq), + (int) target_p->localClient->sendM, + (int) target_p->localClient->sendK, + (int) target_p->localClient->receiveM, + (int) target_p->localClient->receiveK, + rb_current_time() - target_p->localClient->firsttime, + (rb_current_time() > target_p->localClient->lasttime) ? + (rb_current_time() - target_p->localClient->lasttime) : 0, + IsOper(source_p) ? show_capabilities(target_p) : "-"); + } - else - { - sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, - show_ip(source_p, target_p) ? - (IsUpper(statchar) ? - get_client_name(target_p, SHOW_IP) : - get_client_name(target_p, HIDE_IP)) : - get_client_name(target_p, MASK_IP), - (int) rb_linebuf_len(&target_p->localClient->buf_sendq), - (int) target_p->localClient->sendM, - (int) target_p->localClient->sendK, - (int) target_p->localClient->receiveM, - (int) target_p->localClient->receiveK, - rb_current_time() - target_p->localClient->firsttime, - (rb_current_time() > target_p->localClient->lasttime) ? - (rb_current_time() - target_p->localClient->lasttime) : 0, - "-"); - } + else { + sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, + show_ip(source_p, target_p) ? + (IsUpper(statchar) ? + get_client_name(target_p, SHOW_IP) : + get_client_name(target_p, HIDE_IP)) : + get_client_name(target_p, MASK_IP), + (int) rb_linebuf_len(&target_p->localClient->buf_sendq), + (int) target_p->localClient->sendM, + (int) target_p->localClient->sendK, + (int) target_p->localClient->receiveM, + (int) target_p->localClient->receiveK, + rb_current_time() - target_p->localClient->firsttime, + (rb_current_time() > target_p->localClient->lasttime) ? + (rb_current_time() - target_p->localClient->lasttime) : 0, + "-"); + } } static void rb_dump_fd_callback(int fd, const char *desc, void *data) { - struct Client *source_p = data; - sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc); + struct Client *source_p = data; + sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc); } static void stats_comm(struct Client *source_p) { - rb_dump_fd(rb_dump_fd_callback, source_p); + rb_dump_fd(rb_dump_fd_callback, source_p); } /* @@ -1643,13 +1562,13 @@ stats_comm(struct Client *source_p) static void stats_spy(struct Client *source_p, char statchar, const char *name) { - hook_data_int data; + hook_data_int data; - data.client = source_p; - data.arg1 = name; - data.arg2 = (int) statchar; + data.client = source_p; + data.arg1 = name; + data.arg2 = (int) statchar; - call_hook(doing_stats_hook, &data); + call_hook(doing_stats_hook, &data); } /* stats_p_spy() @@ -1661,11 +1580,11 @@ stats_spy(struct Client *source_p, char statchar, const char *name) static void stats_p_spy (struct Client *source_p) { - hook_data data; + hook_data data; - data.client = source_p; - data.arg1 = data.arg2 = NULL; + data.client = source_p; + data.arg1 = data.arg2 = NULL; - call_hook(doing_stats_p_hook, &data); + call_hook(doing_stats_p_hook, &data); } diff --git a/modules/m_svinfo.c b/modules/m_svinfo.c index 99047f5..22b8ecd 100644 --- a/modules/m_svinfo.c +++ b/modules/m_svinfo.c @@ -39,8 +39,8 @@ static int ms_svinfo(struct Client *, struct Client *, int, const char **); struct Message svinfo_msgtab = { - "SVINFO", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_ignore, mg_ignore, {ms_svinfo, 5}, mg_ignore, mg_ignore} + "SVINFO", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_ignore, mg_ignore, {ms_svinfo, 5}, mg_ignore, mg_ignore} }; mapi_clist_av1 svinfo_clist[] = { &svinfo_msgtab, NULL }; @@ -56,59 +56,56 @@ DECLARE_MODULE_AV1(svinfo, NULL, NULL, svinfo_clist, NULL, NULL, "$Revision: 494 static int ms_svinfo(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - signed int deltat; - time_t theirtime; - char squitreason[120]; + signed int deltat; + time_t theirtime; + char squitreason[120]; - /* SVINFO isnt remote. */ - if(source_p != client_p) - return 0; + /* SVINFO isnt remote. */ + if(source_p != client_p) + return 0; - if(TS_CURRENT < atoi(parv[2]) || atoi(parv[1]) < TS_MIN) - { - /* TS version is too low on one of the sides, drop the link */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s dropped, wrong TS protocol version (%s,%s)", - source_p->name, parv[1], parv[2]); - rb_snprintf(squitreason, sizeof squitreason, "Incompatible TS version (%s,%s)", - parv[1], parv[2]); - exit_client(source_p, source_p, source_p, squitreason); - return 0; - } + if(TS_CURRENT < atoi(parv[2]) || atoi(parv[1]) < TS_MIN) { + /* TS version is too low on one of the sides, drop the link */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s dropped, wrong TS protocol version (%s,%s)", + source_p->name, parv[1], parv[2]); + rb_snprintf(squitreason, sizeof squitreason, "Incompatible TS version (%s,%s)", + parv[1], parv[2]); + exit_client(source_p, source_p, source_p, squitreason); + return 0; + } - /* - * since we're here, might as well set rb_current_time() while we're at it - */ - rb_set_time(); - theirtime = atol(parv[4]); - deltat = abs(theirtime - rb_current_time()); + /* + * since we're here, might as well set rb_current_time() while we're at it + */ + rb_set_time(); + theirtime = atol(parv[4]); + deltat = abs(theirtime - rb_current_time()); - if(deltat > ConfigFileEntry.ts_max_delta) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link %s dropped, excessive TS delta" - " (my TS=%ld, their TS=%ld, delta=%d)", - source_p->name, - (long) rb_current_time(), (long) theirtime, deltat); - ilog(L_SERVER, - "Link %s dropped, excessive TS delta" - " (my TS=%ld, their TS=%ld, delta=%d)", - log_client_name(source_p, SHOW_IP), (long) rb_current_time(), (long) theirtime, deltat); - rb_snprintf(squitreason, sizeof squitreason, "Excessive TS delta (my TS=%ld, their TS=%ld, delta=%d)", - (long) rb_current_time(), (long) theirtime, deltat); - disable_server_conf_autoconn(source_p->name); - exit_client(source_p, source_p, source_p, squitreason); - return 0; - } + if(deltat > ConfigFileEntry.ts_max_delta) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link %s dropped, excessive TS delta" + " (my TS=%ld, their TS=%ld, delta=%d)", + source_p->name, + (long) rb_current_time(), (long) theirtime, deltat); + ilog(L_SERVER, + "Link %s dropped, excessive TS delta" + " (my TS=%ld, their TS=%ld, delta=%d)", + log_client_name(source_p, SHOW_IP), (long) rb_current_time(), (long) theirtime, deltat); + rb_snprintf(squitreason, sizeof squitreason, "Excessive TS delta (my TS=%ld, their TS=%ld, delta=%d)", + (long) rb_current_time(), (long) theirtime, deltat); + disable_server_conf_autoconn(source_p->name); + exit_client(source_p, source_p, source_p, squitreason); + return 0; + } - if(deltat > ConfigFileEntry.ts_warn_delta) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Link %s notable TS delta" - " (my TS=%ld, their TS=%ld, delta=%d)", - source_p->name, (long) rb_current_time(), (long) theirtime, deltat); - } + if(deltat > ConfigFileEntry.ts_warn_delta) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Link %s notable TS delta" + " (my TS=%ld, their TS=%ld, delta=%d)", + source_p->name, (long) rb_current_time(), (long) theirtime, deltat); + } - return 0; + return 0; } diff --git a/modules/m_tb.c b/modules/m_tb.c index 6b979c5..7399f7c 100644 --- a/modules/m_tb.c +++ b/modules/m_tb.c @@ -1,5 +1,5 @@ /* modules/m_tb.c - * + * * Copyright (C) 2003 Lee Hardy * Copyright (C) 2003-2005 ircd-ratbox development team * @@ -47,13 +47,13 @@ static int ms_tb(struct Client *client_p, struct Client *source_p, int parc, con static int ms_etb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message tb_msgtab = { - "TB", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_ignore, mg_ignore, {ms_tb, 4}, mg_ignore, mg_ignore} + "TB", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_ignore, mg_ignore, {ms_tb, 4}, mg_ignore, mg_ignore} }; struct Message etb_msgtab = { - "ETB", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_ignore, {ms_etb, 5}, {ms_etb, 5}, mg_ignore, mg_ignore} + "ETB", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_ignore, {ms_etb, 5}, {ms_etb, 5}, mg_ignore, mg_ignore} }; mapi_clist_av1 tb_clist[] = { &tb_msgtab, &etb_msgtab, NULL }; @@ -69,59 +69,55 @@ DECLARE_MODULE_AV1(tb, NULL, NULL, tb_clist, NULL, NULL, "$Revision: 1349 $"); static int ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; - const char *newtopic; - const char *newtopicwho; - time_t newtopicts; - struct Client *fakesource_p; + struct Channel *chptr; + const char *newtopic; + const char *newtopicwho; + time_t newtopicts; + struct Client *fakesource_p; - chptr = find_channel(parv[1]); + chptr = find_channel(parv[1]); - if(chptr == NULL) - return 0; + if(chptr == NULL) + return 0; - newtopicts = atol(parv[2]); + newtopicts = atol(parv[2]); - /* Hide connecting server on netburst -- jilles */ - if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) - fakesource_p = &me; - else - fakesource_p = source_p; + /* Hide connecting server on netburst -- jilles */ + if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) + fakesource_p = &me; + else + fakesource_p = source_p; - if(parc == 5) - { - newtopic = parv[4]; - newtopicwho = parv[3]; - } - else - { - newtopic = parv[3]; - newtopicwho = fakesource_p->name; - } + if(parc == 5) { + newtopic = parv[4]; + newtopicwho = parv[3]; + } else { + newtopic = parv[3]; + newtopicwho = fakesource_p->name; + } - if (EmptyString(newtopic)) - return 0; + if (EmptyString(newtopic)) + return 0; - if(chptr->topic == NULL || chptr->topic_time > newtopicts) - { - /* its possible the topicts is a few seconds out on some - * servers, due to lag when propagating it, so if theyre the - * same topic just drop the message --fl - */ - if(chptr->topic != NULL && strcmp(chptr->topic, newtopic) == 0) - return 0; + if(chptr->topic == NULL || chptr->topic_time > newtopicts) { + /* its possible the topicts is a few seconds out on some + * servers, due to lag when propagating it, so if theyre the + * same topic just drop the message --fl + */ + if(chptr->topic != NULL && strcmp(chptr->topic, newtopic) == 0) + return 0; - set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", - fakesource_p->name, chptr->chname, newtopic); - sendto_server(client_p, chptr, CAP_TB|CAP_TS6, NOCAPS, - ":%s TB %s %ld %s%s:%s", - use_id(source_p), chptr->chname, (long) chptr->topic_time, - ConfigChannel.burst_topicwho ? chptr->topic_info : "", - ConfigChannel.burst_topicwho ? " " : "", chptr->topic); - } + set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", + fakesource_p->name, chptr->chname, newtopic); + sendto_server(client_p, chptr, CAP_TB|CAP_TS6, NOCAPS, + ":%s TB %s %ld %s%s:%s", + use_id(source_p), chptr->chname, (long) chptr->topic_time, + ConfigChannel.burst_topicwho ? chptr->topic_info : "", + ConfigChannel.burst_topicwho ? " " : "", chptr->topic); + } - return 0; + return 0; } /* ms_etb() @@ -135,119 +131,113 @@ ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *pa static int ms_etb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr; - const char *newtopic; - const char *newtopicwho; - time_t channelts, newtopicts; - struct Client *fakesource_p, *source_server_p; - int textchange, can_use_tb, member; + struct Channel *chptr; + const char *newtopic; + const char *newtopicwho; + time_t channelts, newtopicts; + struct Client *fakesource_p, *source_server_p; + int textchange, can_use_tb, member; - channelts = atol(parv[1]); - chptr = find_channel(parv[2]); + channelts = atol(parv[1]); + chptr = find_channel(parv[2]); - if(chptr == NULL) - return 0; + if(chptr == NULL) + return 0; - newtopicts = atol(parv[3]); + newtopicts = atol(parv[3]); - /* Hide connecting server on netburst -- jilles */ - if (IsServer(source_p) && ConfigServerHide.flatten_links && - !HasSentEob(source_p)) - fakesource_p = &me; - else - fakesource_p = source_p; + /* Hide connecting server on netburst -- jilles */ + if (IsServer(source_p) && ConfigServerHide.flatten_links && + !HasSentEob(source_p)) + fakesource_p = &me; + else + fakesource_p = source_p; - newtopicwho = parv[4]; - newtopic = parv[parc - 1]; + newtopicwho = parv[4]; + newtopic = parv[parc - 1]; - if(chptr->topic == NULL || chptr->channelts > channelts || - (chptr->channelts == channelts && chptr->topic_time < newtopicts)) - { - textchange = chptr->topic == NULL || strcmp(chptr->topic, newtopic); - can_use_tb = textchange && !EmptyString(newtopic) && - (chptr->topic == NULL || chptr->topic_time > newtopicts); + if(chptr->topic == NULL || chptr->channelts > channelts || + (chptr->channelts == channelts && chptr->topic_time < newtopicts)) { + textchange = chptr->topic == NULL || strcmp(chptr->topic, newtopic); + can_use_tb = textchange && !EmptyString(newtopic) && + (chptr->topic == NULL || chptr->topic_time > newtopicts); - set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); - newtopic = chptr->topic ? chptr->topic : ""; - if (chptr->topic_info) - newtopicwho = chptr->topic_info; + set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); + newtopic = chptr->topic ? chptr->topic : ""; + if (chptr->topic_info) + newtopicwho = chptr->topic_info; - /* Do not send a textually identical topic to clients, - * but do propagate the new topicts/topicwho to servers. - */ - if(textchange) - { - if (IsPerson(fakesource_p)) - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s!%s@%s TOPIC %s :%s", - fakesource_p->name, - fakesource_p->username, - fakesource_p->host, - chptr->chname, - newtopic); - else - sendto_channel_local(ALL_MEMBERS, chptr, - ":%s TOPIC %s :%s", - fakesource_p->name, - chptr->chname, newtopic); - } - /* Propagate channelts as given, because an older channelts - * forces any change. - */ - sendto_server(client_p, chptr, CAP_EOPMOD|CAP_TS6, NOCAPS, - ":%s ETB %ld %s %ld %s :%s", - use_id(source_p), (long)channelts, chptr->chname, - (long)newtopicts, newtopicwho, newtopic); - source_server_p = IsServer(source_p) ? source_p : source_p->servptr; - if (can_use_tb) - sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, - ":%s TB %s %ld %s :%s", - use_id(source_server_p), - chptr->chname, (long)newtopicts, - newtopicwho, newtopic); - else if (IsPerson(source_p) && textchange) - { - member = IsMember(source_p, chptr); - if (!member) - sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, - ":%s SJOIN %ld %s + :@%s", - use_id(source_server_p), - (long)chptr->channelts, - chptr->chname, use_id(source_p)); - if (EmptyString(newtopic) || - newtopicts >= rb_current_time() - 60) - sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, - ":%s TOPIC %s :%s", - use_id(source_p), - chptr->chname, newtopic); - else - { - sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, - ":%s TOPIC %s :%s", - use_id(source_p), - chptr->chname, ""); - sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, - ":%s TB %s %ld %s :%s", - use_id(source_server_p), - chptr->chname, (long)newtopicts, - newtopicwho, newtopic); - } - if (!member) - sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, - ":%s PART %s :Topic set for %s", - use_id(source_p), - chptr->chname, newtopicwho); - } - else if (textchange) - { - /* Should not send :server ETB if not all servers - * support EOPMOD. - */ - sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, - ":%s NOTICE %s :*** Notice -- Dropping topic change for %s", - me.id, chptr->chname, chptr->chname); - } - } + /* Do not send a textually identical topic to clients, + * but do propagate the new topicts/topicwho to servers. + */ + if(textchange) { + if (IsPerson(fakesource_p)) + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s!%s@%s TOPIC %s :%s", + fakesource_p->name, + fakesource_p->username, + fakesource_p->host, + chptr->chname, + newtopic); + else + sendto_channel_local(ALL_MEMBERS, chptr, + ":%s TOPIC %s :%s", + fakesource_p->name, + chptr->chname, newtopic); + } + /* Propagate channelts as given, because an older channelts + * forces any change. + */ + sendto_server(client_p, chptr, CAP_EOPMOD|CAP_TS6, NOCAPS, + ":%s ETB %ld %s %ld %s :%s", + use_id(source_p), (long)channelts, chptr->chname, + (long)newtopicts, newtopicwho, newtopic); + source_server_p = IsServer(source_p) ? source_p : source_p->servptr; + if (can_use_tb) + sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, + ":%s TB %s %ld %s :%s", + use_id(source_server_p), + chptr->chname, (long)newtopicts, + newtopicwho, newtopic); + else if (IsPerson(source_p) && textchange) { + member = IsMember(source_p, chptr); + if (!member) + sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, + ":%s SJOIN %ld %s + :@%s", + use_id(source_server_p), + (long)chptr->channelts, + chptr->chname, use_id(source_p)); + if (EmptyString(newtopic) || + newtopicts >= rb_current_time() - 60) + sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, + ":%s TOPIC %s :%s", + use_id(source_p), + chptr->chname, newtopic); + else { + sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, + ":%s TOPIC %s :%s", + use_id(source_p), + chptr->chname, ""); + sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, + ":%s TB %s %ld %s :%s", + use_id(source_server_p), + chptr->chname, (long)newtopicts, + newtopicwho, newtopic); + } + if (!member) + sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, + ":%s PART %s :Topic set for %s", + use_id(source_p), + chptr->chname, newtopicwho); + } else if (textchange) { + /* Should not send :server ETB if not all servers + * support EOPMOD. + */ + sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, + ":%s NOTICE %s :*** Notice -- Dropping topic change for %s", + me.id, chptr->chname, chptr->chname); + } + } - return 0; + return 0; } diff --git a/modules/m_testline.c b/modules/m_testline.c index b96f878..f3e728f 100644 --- a/modules/m_testline.c +++ b/modules/m_testline.c @@ -1,5 +1,5 @@ /* modules/m_testline.c - * + * * Copyright (C) 2004 Lee Hardy * Copyright (C) 2004-2005 ircd-ratbox development team * @@ -44,12 +44,12 @@ static int mo_testline(struct Client *, struct Client *, int, const char **); static int mo_testgecos(struct Client *, struct Client *, int, const char **); struct Message testline_msgtab = { - "TESTLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}} + "TESTLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testline, 2}} }; struct Message testgecos_msgtab = { - "TESTGECOS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}} + "TESTGECOS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testgecos, 2}} }; mapi_clist_av1 testline_clist[] = { &testline_msgtab, &testgecos_msgtab, NULL }; @@ -58,193 +58,177 @@ DECLARE_MODULE_AV1(testline, NULL, NULL, testline_clist, NULL, NULL, "$Revision: static int mo_testline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct ConfItem *aconf; - struct ConfItem *resv_p; - struct rb_sockaddr_storage ip; - char user_trunc[USERLEN + 1], notildeuser_trunc[USERLEN + 1]; - const char *name = NULL; - const char *username = NULL; - const char *host = NULL; - char *mask; - char *p; - int host_mask; - int type; - int duration; - char *puser, *phost, *reason, *operreason; - char reasonbuf[BUFSIZE]; + struct ConfItem *aconf; + struct ConfItem *resv_p; + struct rb_sockaddr_storage ip; + char user_trunc[USERLEN + 1], notildeuser_trunc[USERLEN + 1]; + const char *name = NULL; + const char *username = NULL; + const char *host = NULL; + char *mask; + char *p; + int host_mask; + int type; + int duration; + char *puser, *phost, *reason, *operreason; + char reasonbuf[BUFSIZE]; - mask = LOCAL_COPY(parv[1]); + mask = LOCAL_COPY(parv[1]); - if (IsChannelName(mask)) - { - resv_p = hash_find_resv(mask); - if (resv_p != NULL) - { - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - resv_p->hold ? 'q' : 'Q', - resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, - resv_p->host, resv_p->passwd); - /* this is a false positive, so make sure it isn't counted in stats q - * --nenolod - */ - resv_p->port--; - } - else - sendto_one(source_p, form_str(RPL_NOTESTLINE), - me.name, source_p->name, parv[1]); - return 0; - } + if (IsChannelName(mask)) { + resv_p = hash_find_resv(mask); + if (resv_p != NULL) { + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + resv_p->hold ? 'q' : 'Q', + resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, + resv_p->host, resv_p->passwd); + /* this is a false positive, so make sure it isn't counted in stats q + * --nenolod + */ + resv_p->port--; + } else + sendto_one(source_p, form_str(RPL_NOTESTLINE), + me.name, source_p->name, parv[1]); + return 0; + } - if((p = strchr(mask, '!'))) - { - *p++ = '\0'; - name = mask; - mask = p; + if((p = strchr(mask, '!'))) { + *p++ = '\0'; + name = mask; + mask = p; - if(EmptyString(mask)) - return 0; - } + if(EmptyString(mask)) + return 0; + } - if((p = strchr(mask, '@'))) - { - *p++ = '\0'; - username = mask; - host = p; + if((p = strchr(mask, '@'))) { + *p++ = '\0'; + username = mask; + host = p; - if(EmptyString(host)) - return 0; - } - else - host = mask; + if(EmptyString(host)) + return 0; + } else + host = mask; - /* parses as an IP, check for a dline */ - if((type = parse_netmask(host, (struct sockaddr *)&ip, &host_mask)) != HM_HOST) - { + /* parses as an IP, check for a dline */ + if((type = parse_netmask(host, (struct sockaddr *)&ip, &host_mask)) != HM_HOST) { #ifdef RB_IPV6 - if(type == HM_IPV6) - aconf = find_dline((struct sockaddr *)&ip, AF_INET6); - else + if(type == HM_IPV6) + aconf = find_dline((struct sockaddr *)&ip, AF_INET6); + else #endif - aconf = find_dline((struct sockaddr *)&ip, AF_INET); + aconf = find_dline((struct sockaddr *)&ip, AF_INET); - if(aconf && aconf->status & CONF_DLINE) - { - get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); - rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, - operreason ? "|" : "", operreason ? operreason : ""); - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', - (aconf->flags & CONF_FLAGS_TEMPORARY) ? - (long) ((aconf->hold - rb_current_time()) / 60) : 0L, - phost, reasonbuf); + if(aconf && aconf->status & CONF_DLINE) { + get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); + rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, + operreason ? "|" : "", operreason ? operreason : ""); + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', + (aconf->flags & CONF_FLAGS_TEMPORARY) ? + (long) ((aconf->hold - rb_current_time()) / 60) : 0L, + phost, reasonbuf); - return 0; - } - /* Otherwise, aconf is an exempt{} */ - if(aconf == NULL && - (duration = is_reject_ip((struct sockaddr *)&ip))) - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - '!', - duration / 60, - host, "Reject cache"); - if(aconf == NULL && - (duration = is_throttle_ip((struct sockaddr *)&ip))) - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - '!', - duration / 60, - host, "Throttled"); - } + return 0; + } + /* Otherwise, aconf is an exempt{} */ + if(aconf == NULL && + (duration = is_reject_ip((struct sockaddr *)&ip))) + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + '!', + duration / 60, + host, "Reject cache"); + if(aconf == NULL && + (duration = is_throttle_ip((struct sockaddr *)&ip))) + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + '!', + duration / 60, + host, "Throttled"); + } - if (username != NULL) - { - rb_strlcpy(user_trunc, username, sizeof user_trunc); - rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc); - } - else - { - rb_strlcpy(user_trunc, "dummy", sizeof user_trunc); - rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc); - } - /* now look for a matching I/K/G */ - if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc, - (type != HM_HOST) ? (struct sockaddr *)&ip : NULL, - (type != HM_HOST) ? ( + if (username != NULL) { + rb_strlcpy(user_trunc, username, sizeof user_trunc); + rb_strlcpy(notildeuser_trunc, *username == '~' ? username + 1 : username, sizeof notildeuser_trunc); + } else { + rb_strlcpy(user_trunc, "dummy", sizeof user_trunc); + rb_strlcpy(notildeuser_trunc, "dummy", sizeof notildeuser_trunc); + } + /* now look for a matching I/K/G */ + if((aconf = find_address_conf(host, NULL, user_trunc, notildeuser_trunc, + (type != HM_HOST) ? (struct sockaddr *)&ip : NULL, + (type != HM_HOST) ? ( #ifdef RB_IPV6 - (type == HM_IPV6) ? AF_INET6 : + (type == HM_IPV6) ? AF_INET6 : #endif - AF_INET) : 0, NULL))) - { - static char buf[HOSTLEN+USERLEN+2]; + AF_INET) : 0, NULL))) { + static char buf[HOSTLEN+USERLEN+2]; - if(aconf->status & CONF_KILL) - { - get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); - rb_snprintf(buf, sizeof(buf), "%s@%s", - puser, phost); - rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, - operreason ? "|" : "", operreason ? operreason : ""); - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', - (aconf->flags & CONF_FLAGS_TEMPORARY) ? - (long) ((aconf->hold - rb_current_time()) / 60) : 0L, - buf, reasonbuf); - return 0; - } - } + if(aconf->status & CONF_KILL) { + get_printable_kline(source_p, aconf, &phost, &reason, &puser, &operreason); + rb_snprintf(buf, sizeof(buf), "%s@%s", + puser, phost); + rb_snprintf(reasonbuf, sizeof(reasonbuf), "%s%s%s", reason, + operreason ? "|" : "", operreason ? operreason : ""); + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', + (aconf->flags & CONF_FLAGS_TEMPORARY) ? + (long) ((aconf->hold - rb_current_time()) / 60) : 0L, + buf, reasonbuf); + return 0; + } + } - /* they asked us to check a nick, so hunt for resvs.. */ - if(name && (resv_p = find_nick_resv(name))) - { - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - resv_p->hold ? 'q' : 'Q', - resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, - resv_p->host, resv_p->passwd); + /* they asked us to check a nick, so hunt for resvs.. */ + if(name && (resv_p = find_nick_resv(name))) { + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + resv_p->hold ? 'q' : 'Q', + resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, + resv_p->host, resv_p->passwd); - /* this is a false positive, so make sure it isn't counted in stats q - * --nenolod - */ - resv_p->port--; - return 0; - } + /* this is a false positive, so make sure it isn't counted in stats q + * --nenolod + */ + resv_p->port--; + return 0; + } - /* no matching resv, we can print the I: if it exists */ - if(aconf && aconf->status & CONF_CLIENT) - { - sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), - aconf->info.name, EmptyString(aconf->spasswd) ? "" : aconf->spasswd, - show_iline_prefix(source_p, aconf, aconf->user), - aconf->host, aconf->port, aconf->className); - return 0; - } + /* no matching resv, we can print the I: if it exists */ + if(aconf && aconf->status & CONF_CLIENT) { + sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), + aconf->info.name, EmptyString(aconf->spasswd) ? "" : aconf->spasswd, + show_iline_prefix(source_p, aconf, aconf->user), + aconf->host, aconf->port, aconf->className); + return 0; + } - /* nothing matches.. */ - sendto_one(source_p, form_str(RPL_NOTESTLINE), - me.name, source_p->name, parv[1]); - return 0; + /* nothing matches.. */ + sendto_one(source_p, form_str(RPL_NOTESTLINE), + me.name, source_p->name, parv[1]); + return 0; } static int mo_testgecos(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct ConfItem *aconf; + struct ConfItem *aconf; - if(!(aconf = find_xline(parv[1], 0))) - { - sendto_one(source_p, form_str(RPL_NOTESTLINE), - me.name, source_p->name, parv[1]); - return 0; - } + if(!(aconf = find_xline(parv[1], 0))) { + sendto_one(source_p, form_str(RPL_NOTESTLINE), + me.name, source_p->name, parv[1]); + return 0; + } - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - aconf->hold ? 'x' : 'X', - aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, - aconf->host, aconf->passwd); - return 0; + sendto_one(source_p, form_str(RPL_TESTLINE), + me.name, source_p->name, + aconf->hold ? 'x' : 'X', + aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, + aconf->host, aconf->passwd); + return 0; } diff --git a/modules/m_testmask.c b/modules/m_testmask.c index 5a19773..b51163e 100644 --- a/modules/m_testmask.c +++ b/modules/m_testmask.c @@ -10,12 +10,12 @@ * met: * * 1.Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + * this list of conditions and the following disclaimer. * 2.Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * documentation and/or other materials provided with the distribution. * 3.The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -48,11 +48,11 @@ #include "modules.h" static int mo_testmask(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]); + int parc, const char *parv[]); struct Message testmask_msgtab = { - "TESTMASK", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testmask, 2}} + "TESTMASK", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testmask, 2}} }; mapi_clist_av1 testmask_clist[] = { &testmask_msgtab, NULL }; @@ -63,84 +63,77 @@ static const char *spoofed_sockhost = "0"; static int mo_testmask(struct Client *client_p, struct Client *source_p, - int parc, const char *parv[]) + int parc, const char *parv[]) { - struct Client *target_p; - int lcount = 0; - int gcount = 0; - char *name, *username, *hostname; - const char *sockhost; - char *gecos = NULL; - rb_dlink_node *ptr; + struct Client *target_p; + int lcount = 0; + int gcount = 0; + char *name, *username, *hostname; + const char *sockhost; + char *gecos = NULL; + rb_dlink_node *ptr; - name = LOCAL_COPY(parv[1]); - collapse(name); + name = LOCAL_COPY(parv[1]); + collapse(name); - /* username is required */ - if((hostname = strchr(name, '@')) == NULL) - { - sendto_one_notice(source_p, ":Invalid parameters"); - return 0; - } + /* username is required */ + if((hostname = strchr(name, '@')) == NULL) { + sendto_one_notice(source_p, ":Invalid parameters"); + return 0; + } - *hostname++ = '\0'; + *hostname++ = '\0'; - /* nickname is optional */ - if((username = strchr(name, '!')) == NULL) - { - username = name; - name = NULL; - } - else - *username++ = '\0'; + /* nickname is optional */ + if((username = strchr(name, '!')) == NULL) { + username = name; + name = NULL; + } else + *username++ = '\0'; - if(EmptyString(username) || EmptyString(hostname)) - { - sendto_one_notice(source_p, ":Invalid parameters"); - return 0; - } + if(EmptyString(username) || EmptyString(hostname)) { + sendto_one_notice(source_p, ":Invalid parameters"); + return 0; + } - if(parc > 2 && !EmptyString(parv[2])) - { - gecos = LOCAL_COPY(parv[2]); - collapse_esc(gecos); - } + if(parc > 2 && !EmptyString(parv[2])) { + gecos = LOCAL_COPY(parv[2]); + collapse_esc(gecos); + } - RB_DLINK_FOREACH(ptr, global_client_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, global_client_list.head) { + target_p = ptr->data; - if(!IsPerson(target_p)) - continue; + if(!IsPerson(target_p)) + continue; - if(EmptyString(target_p->sockhost)) - sockhost = empty_sockhost; - else if(!show_ip(source_p, target_p)) - sockhost = spoofed_sockhost; - else - sockhost = target_p->sockhost; + if(EmptyString(target_p->sockhost)) + sockhost = empty_sockhost; + else if(!show_ip(source_p, target_p)) + sockhost = spoofed_sockhost; + else + sockhost = target_p->sockhost; - if(match(username, target_p->username) && - (match(hostname, target_p->host) || - match(hostname, target_p->orighost) || - match(hostname, sockhost) || match_ips(hostname, sockhost))) - { - if(name && !match(name, target_p->name)) - continue; + if(match(username, target_p->username) && + (match(hostname, target_p->host) || + match(hostname, target_p->orighost) || + match(hostname, sockhost) || match_ips(hostname, sockhost))) { + if(name && !match(name, target_p->name)) + continue; - if(gecos && !match_esc(gecos, target_p->info)) - continue; + if(gecos && !match_esc(gecos, target_p->info)) + continue; - if(MyClient(target_p)) - lcount++; - else - gcount++; - } - } + if(MyClient(target_p)) + lcount++; + else + gcount++; + } + } - sendto_one(source_p, form_str(RPL_TESTMASKGECOS), - me.name, source_p->name, - lcount, gcount, name ? name : "*", - username, hostname, gecos ? gecos : "*"); - return 0; + sendto_one(source_p, form_str(RPL_TESTMASKGECOS), + me.name, source_p->name, + lcount, gcount, name ? name : "*", + username, hostname, gecos ? gecos : "*"); + return 0; } diff --git a/modules/m_time.c b/modules/m_time.c index 944b846..68908a5 100644 --- a/modules/m_time.c +++ b/modules/m_time.c @@ -39,22 +39,22 @@ static int m_time(struct Client *, struct Client *, int, const char **); static char *date(void); struct Message time_msgtab = { - "TIME", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_time, 0}, {m_time, 2}, mg_ignore, mg_ignore, {m_time, 0}} + "TIME", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_time, 0}, {m_time, 2}, mg_ignore, mg_ignore, {m_time, 0}} }; mapi_clist_av1 time_clist[] = { &time_msgtab, NULL }; DECLARE_MODULE_AV1(time, NULL, NULL, time_clist, NULL, NULL, "$Revision: 254 $"); static const char *months[] = { - "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December" + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" }; static const char *weekdays[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" }; /* @@ -64,15 +64,15 @@ static const char *weekdays[] = { static int m_time(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* this is not rate limited, so end the grace period */ - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + /* this is not rate limited, so end the grace period */ + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - if(hunt_server(client_p, source_p, ":%s TIME :%s", 1, parc, parv) == HUNTED_ISME) - sendto_one_numeric(source_p, RPL_TIME, form_str(RPL_TIME), - me.name, date()); + if(hunt_server(client_p, source_p, ":%s TIME :%s", 1, parc, parv) == HUNTED_ISME) + sendto_one_numeric(source_p, RPL_TIME, form_str(RPL_TIME), + me.name, date()); - return 0; + return 0; } /* date() @@ -82,36 +82,36 @@ m_time(struct Client *client_p, struct Client *source_p, int parc, const char *p static char * date(void) { - static char buf[80]; - char plus; - struct tm *lt; - struct tm *gm; - struct tm gmbuf; - time_t lclock; - int minswest; + static char buf[80]; + char plus; + struct tm *lt; + struct tm *gm; + struct tm gmbuf; + time_t lclock; + int minswest; - lclock = rb_current_time(); - gm = gmtime(&lclock); - memcpy((void *) &gmbuf, (void *) gm, sizeof(gmbuf)); - gm = &gmbuf; - lt = localtime(&lclock); + lclock = rb_current_time(); + gm = gmtime(&lclock); + memcpy((void *) &gmbuf, (void *) gm, sizeof(gmbuf)); + gm = &gmbuf; + lt = localtime(&lclock); - if(lt->tm_yday == gm->tm_yday) - minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min); - else if(lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) - minswest = (gm->tm_hour - (lt->tm_hour + 24)) * 60; - else - minswest = ((gm->tm_hour + 24) - lt->tm_hour) * 60; + if(lt->tm_yday == gm->tm_yday) + minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min); + else if(lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) + minswest = (gm->tm_hour - (lt->tm_hour + 24)) * 60; + else + minswest = ((gm->tm_hour + 24) - lt->tm_hour) * 60; - plus = (minswest > 0) ? '-' : '+'; + plus = (minswest > 0) ? '-' : '+'; - if(minswest < 0) - minswest = -minswest; + if(minswest < 0) + minswest = -minswest; - rb_sprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u", - weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday, - lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec, - plus, minswest / 60, minswest % 60); + rb_sprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u", + weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday, + lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec, + plus, minswest / 60, minswest % 60); - return buf; + return buf; } diff --git a/modules/m_topic.c b/modules/m_topic.c index 2fd2072..bbffb79 100644 --- a/modules/m_topic.c +++ b/modules/m_topic.c @@ -44,8 +44,8 @@ static int m_topic(struct Client *, struct Client *, int, const char **); static int ms_topic(struct Client *, struct Client *, int, const char **); struct Message topic_msgtab = { - "TOPIC", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_topic, 2}, {m_topic, 2}, {ms_topic, 5}, mg_ignore, {m_topic, 2}} + "TOPIC", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_topic, 2}, {m_topic, 2}, {ms_topic, 5}, mg_ignore, {m_topic, 2}} }; mapi_clist_av1 topic_clist[] = { &topic_msgtab, NULL }; @@ -59,137 +59,122 @@ DECLARE_MODULE_AV1(topic, NULL, NULL, topic_clist, NULL, NULL, "$Revision: 254 $ static int m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr = NULL; - struct membership *msptr; - char *p = NULL; - const char *name; - int operspy = 0; + struct Channel *chptr = NULL; + struct membership *msptr; + char *p = NULL; + const char *name; + int operspy = 0; - if((p = strchr(parv[1], ','))) - *p = '\0'; + if((p = strchr(parv[1], ','))) + *p = '\0'; - name = parv[1]; + name = parv[1]; - if(IsOperSpy(source_p) && parv[1][0] == '!') - { - name++; - operspy = 1; + if(IsOperSpy(source_p) && parv[1][0] == '!') { + name++; + operspy = 1; - if(EmptyString(name)) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "TOPIC"); - return 0; - } - } + if(EmptyString(name)) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "TOPIC"); + return 0; + } + } - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - if(!IsChannelName(name)) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + if(!IsChannelName(name)) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - chptr = find_channel(name); + chptr = find_channel(name); - if(chptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), name); - return 0; - } + if(chptr == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), name); + return 0; + } - /* setting topic */ - if(parc > 2) - { - char topic_info[USERHOST_REPLYLEN]; + /* setting topic */ + if(parc > 2) { + char topic_info[USERHOST_REPLYLEN]; - msptr = find_channel_membership(chptr, source_p); + msptr = find_channel_membership(chptr, source_p); - if(msptr == NULL) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), name); - return 0; - } + if(msptr == NULL) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), name); + return 0; + } - if(MyClient(source_p) && !is_chanop_voiced(msptr) && - !IsOper(source_p) && - !add_channel_target(source_p, chptr)) - { - sendto_one(source_p, form_str(ERR_TARGCHANGE), - me.name, source_p->name, chptr->chname); - return 0; - } + if(MyClient(source_p) && !is_chanop_voiced(msptr) && + !IsOper(source_p) && + !add_channel_target(source_p, chptr)) { + sendto_one(source_p, form_str(ERR_TARGCHANGE), + me.name, source_p->name, chptr->chname); + return 0; + } - if(MyClient(source_p) && (chptr->mode.mode & MODE_TOPICLIMIT) && !is_any_op(msptr)) - { - if(IsOverride(source_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding TOPIC on [%s]", - get_oper_name(source_p), chptr->chname); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding TOPIC on [%s]", - me.name, get_oper_name(source_p), chptr->chname); - } - else - { - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, parv[1]); - return 0; - } + if(MyClient(source_p) && (chptr->mode.mode & MODE_TOPICLIMIT) && !is_any_op(msptr)) { + if(IsOverride(source_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding TOPIC on [%s]", + get_oper_name(source_p), chptr->chname); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding TOPIC on [%s]", + me.name, get_oper_name(source_p), chptr->chname); + } else { + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, parv[1]); + return 0; + } - } + } - if(ConfigChannel.host_in_topic) - rb_sprintf(topic_info, "%s!%s@%s", - source_p->name, source_p->username, source_p->host); - else - rb_strlcpy(topic_info, source_p->name, sizeof(topic_info)); + if(ConfigChannel.host_in_topic) + rb_sprintf(topic_info, "%s!%s@%s", + source_p->name, source_p->username, source_p->host); + else + rb_strlcpy(topic_info, source_p->name, sizeof(topic_info)); - set_channel_topic(chptr, parv[2], topic_info, rb_current_time()); + set_channel_topic(chptr, parv[2], topic_info, rb_current_time()); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s TOPIC %s :%s", - use_id(source_p), chptr->chname, - chptr->topic == NULL ? "" : chptr->topic); - sendto_channel_local(ALL_MEMBERS, - chptr, ":%s!%s@%s TOPIC %s :%s", - source_p->name, source_p->username, - source_p->host, chptr->chname, - chptr->topic == NULL ? "" : chptr->topic); + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s TOPIC %s :%s", + use_id(source_p), chptr->chname, + chptr->topic == NULL ? "" : chptr->topic); + sendto_channel_local(ALL_MEMBERS, + chptr, ":%s!%s@%s TOPIC %s :%s", + source_p->name, source_p->username, + source_p->host, chptr->chname, + chptr->topic == NULL ? "" : chptr->topic); - } - else if(MyClient(source_p)) - { - if(operspy) - report_operspy(source_p, "TOPIC", chptr->chname); - if(!IsMember(source_p, chptr) && SecretChannel(chptr) && - !operspy) - { - sendto_one_numeric(source_p, ERR_NOTONCHANNEL, - form_str(ERR_NOTONCHANNEL), name); - return 0; - } - if(chptr->topic == NULL) - sendto_one(source_p, form_str(RPL_NOTOPIC), - me.name, source_p->name, name); - else - { - sendto_one(source_p, form_str(RPL_TOPIC), - me.name, source_p->name, chptr->chname, chptr->topic); + } else if(MyClient(source_p)) { + if(operspy) + report_operspy(source_p, "TOPIC", chptr->chname); + if(!IsMember(source_p, chptr) && SecretChannel(chptr) && + !operspy) { + sendto_one_numeric(source_p, ERR_NOTONCHANNEL, + form_str(ERR_NOTONCHANNEL), name); + return 0; + } + if(chptr->topic == NULL) + sendto_one(source_p, form_str(RPL_NOTOPIC), + me.name, source_p->name, name); + else { + sendto_one(source_p, form_str(RPL_TOPIC), + me.name, source_p->name, chptr->chname, chptr->topic); - sendto_one(source_p, form_str(RPL_TOPICWHOTIME), - me.name, source_p->name, chptr->chname, - chptr->topic_info, chptr->topic_time); - } - } + sendto_one(source_p, form_str(RPL_TOPICWHOTIME), + me.name, source_p->name, chptr->chname, + chptr->topic_info, chptr->topic_time); + } + } - return 0; + return 0; } /* @@ -204,19 +189,18 @@ m_topic(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Channel *chptr = NULL; + struct Channel *chptr = NULL; - if(IsChannelName(parv[1])) - { - if((chptr = find_channel(parv[1])) == NULL) - return 0; + if(IsChannelName(parv[1])) { + if((chptr = find_channel(parv[1])) == NULL) + return 0; - set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); + set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", - source_p->name, parv[1], - chptr->topic == NULL ? "" : chptr->topic); - } + sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", + source_p->name, parv[1], + chptr->topic == NULL ? "" : chptr->topic); + } - return 0; + return 0; } diff --git a/modules/m_trace.c b/modules/m_trace.c index 0482c1d..ea8c5d0 100644 --- a/modules/m_trace.c +++ b/modules/m_trace.c @@ -46,16 +46,16 @@ static int m_trace(struct Client *, struct Client *, int, const char **); static void trace_spy(struct Client *, struct Client *); struct Message trace_msgtab = { - "TRACE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_trace, 0}, {m_trace, 0}, mg_ignore, mg_ignore, {m_trace, 0}} + "TRACE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_trace, 0}, {m_trace, 0}, mg_ignore, mg_ignore, {m_trace, 0}} }; int doing_trace_hook; mapi_clist_av1 trace_clist[] = { &trace_msgtab, NULL }; mapi_hlist_av1 trace_hlist[] = { - { "doing_trace", &doing_trace_hook }, - { NULL, NULL } + { "doing_trace", &doing_trace_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(trace, NULL, NULL, trace_clist, trace_hlist, NULL, "$Revision: 3183 $"); @@ -71,233 +71,209 @@ static const char *empty_sockhost = "255.255.255.255"; static int m_trace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p = NULL; - struct Class *cltmp; - const char *tname; - int doall = 0; - int cnt = 0, wilds, dow; - rb_dlink_node *ptr; + struct Client *target_p = NULL; + struct Class *cltmp; + const char *tname; + int doall = 0; + int cnt = 0, wilds, dow; + rb_dlink_node *ptr; - if(parc > 1) - { - tname = parv[1]; + if(parc > 1) { + tname = parv[1]; - if(parc > 2) - { - if(hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv) != - HUNTED_ISME) - return 0; - } - } - else - tname = me.name; + if(parc > 2) { + if(hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv) != + HUNTED_ISME) + return 0; + } + } else + tname = me.name; - /* if we have 3 parameters, then the command is directed at us. So - * we shouldnt be forwarding it anywhere. - */ - if(parc < 3) - { - switch (hunt_server(client_p, source_p, ":%s TRACE :%s", 1, parc, parv)) - { - case HUNTED_PASS: /* note: gets here only if parv[1] exists */ - { - struct Client *ac2ptr; + /* if we have 3 parameters, then the command is directed at us. So + * we shouldnt be forwarding it anywhere. + */ + if(parc < 3) { + switch (hunt_server(client_p, source_p, ":%s TRACE :%s", 1, parc, parv)) { + case HUNTED_PASS: { /* note: gets here only if parv[1] exists */ + struct Client *ac2ptr; - if(MyClient(source_p)) - ac2ptr = find_named_client(tname); - else - ac2ptr = find_client(tname); + if(MyClient(source_p)) + ac2ptr = find_named_client(tname); + else + ac2ptr = find_client(tname); - if(ac2ptr == NULL) - { - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - ac2ptr = ptr->data; + if(ac2ptr == NULL) { + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + ac2ptr = ptr->data; - if(match(tname, ac2ptr->name)) - break; - else - ac2ptr = NULL; - } - } + if(match(tname, ac2ptr->name)) + break; + else + ac2ptr = NULL; + } + } - /* giving this out with flattened links defeats the - * object --fl - */ - if(IsOper(source_p) || IsExemptShide(source_p) || - !ConfigServerHide.flatten_links) - sendto_one_numeric(source_p, RPL_TRACELINK, - form_str(RPL_TRACELINK), - ircd_version, - ac2ptr ? ac2ptr->name : tname, - ac2ptr ? ac2ptr->from->name : "EEK!"); + /* giving this out with flattened links defeats the + * object --fl + */ + if(IsOper(source_p) || IsExemptShide(source_p) || + !ConfigServerHide.flatten_links) + sendto_one_numeric(source_p, RPL_TRACELINK, + form_str(RPL_TRACELINK), + ircd_version, + ac2ptr ? ac2ptr->name : tname, + ac2ptr ? ac2ptr->from->name : "EEK!"); - return 0; - } + return 0; + } - case HUNTED_ISME: - break; + case HUNTED_ISME: + break; - default: - return 0; - } - } + default: + return 0; + } + } - if(match(tname, me.name)) - { - doall = 1; - } - /* if theyre tracing our SID, we need to move tname to our name so - * we dont give the sid in ENDOFTRACE - */ - else if(!MyClient(source_p) && !strcmp(tname, me.id)) - { - doall = 1; - tname = me.name; - } + if(match(tname, me.name)) { + doall = 1; + } + /* if theyre tracing our SID, we need to move tname to our name so + * we dont give the sid in ENDOFTRACE + */ + else if(!MyClient(source_p) && !strcmp(tname, me.id)) { + doall = 1; + tname = me.name; + } - wilds = strchr(tname, '*') || strchr(tname, '?'); - dow = wilds || doall; + wilds = strchr(tname, '*') || strchr(tname, '?'); + dow = wilds || doall; - /* specific trace */ - if(dow == 0) - { - if(MyClient(source_p) || parc > 2) - target_p = find_named_person(tname); - else - target_p = find_person(tname); + /* specific trace */ + if(dow == 0) { + if(MyClient(source_p) || parc > 2) + target_p = find_named_person(tname); + else + target_p = find_person(tname); - /* tname could be pointing to an ID at this point, so reset - * it to target_p->name if we have a target --fl - */ - if(target_p != NULL) - { - report_this_status(source_p, target_p); - tname = target_p->name; - } + /* tname could be pointing to an ID at this point, so reset + * it to target_p->name if we have a target --fl + */ + if(target_p != NULL) { + report_this_status(source_p, target_p); + tname = target_p->name; + } - trace_spy(source_p, target_p); + trace_spy(source_p, target_p); - sendto_one_numeric(source_p, RPL_ENDOFTRACE, - form_str(RPL_ENDOFTRACE), tname); - return 0; - } + sendto_one_numeric(source_p, RPL_ENDOFTRACE, + form_str(RPL_ENDOFTRACE), tname); + return 0; + } - trace_spy(source_p, NULL); + trace_spy(source_p, NULL); - /* give non-opers a limited trace output of themselves (if local), - * opers and servers (if no shide) --fl - */ - if(!IsOper(source_p)) - { - if(MyClient(source_p)) - { - if(doall || (wilds && match(tname, source_p->name))) - report_this_status(source_p, source_p); - } + /* give non-opers a limited trace output of themselves (if local), + * opers and servers (if no shide) --fl + */ + if(!IsOper(source_p)) { + if(MyClient(source_p)) { + if(doall || (wilds && match(tname, source_p->name))) + report_this_status(source_p, source_p); + } - RB_DLINK_FOREACH(ptr, local_oper_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, local_oper_list.head) { + target_p = ptr->data; - if(!doall && wilds && (match(tname, target_p->name) == 0)) - continue; + if(!doall && wilds && (match(tname, target_p->name) == 0)) + continue; - report_this_status(source_p, target_p); - } + report_this_status(source_p, target_p); + } - if (IsExemptShide(source_p) || !ConfigServerHide.flatten_links) - { - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + if (IsExemptShide(source_p) || !ConfigServerHide.flatten_links) { + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - if(!doall && wilds && !match(tname, target_p->name)) - continue; + if(!doall && wilds && !match(tname, target_p->name)) + continue; - report_this_status(source_p, target_p); - } - } + report_this_status(source_p, target_p); + } + } - sendto_one_numeric(source_p, RPL_ENDOFTRACE, - form_str(RPL_ENDOFTRACE), tname); - return 0; - } + sendto_one_numeric(source_p, RPL_ENDOFTRACE, + form_str(RPL_ENDOFTRACE), tname); + return 0; + } - /* source_p is opered */ + /* source_p is opered */ - /* report all direct connections */ - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; + /* report all direct connections */ + RB_DLINK_FOREACH(ptr, lclient_list.head) { + target_p = ptr->data; - /* dont show invisible users to remote opers */ - if(IsInvisible(target_p) && dow && !MyConnect(source_p) && !IsOper(target_p)) - continue; + /* dont show invisible users to remote opers */ + if(IsInvisible(target_p) && dow && !MyConnect(source_p) && !IsOper(target_p)) + continue; - if(!doall && wilds && !match(tname, target_p->name)) - continue; + if(!doall && wilds && !match(tname, target_p->name)) + continue; - /* remote opers may not see invisible normal users */ - if(dow && !MyConnect(source_p) && !IsOper(target_p) && - IsInvisible(target_p)) - continue; + /* remote opers may not see invisible normal users */ + if(dow && !MyConnect(source_p) && !IsOper(target_p) && + IsInvisible(target_p)) + continue; - cnt = report_this_status(source_p, target_p); - } + cnt = report_this_status(source_p, target_p); + } - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - if(!doall && wilds && !match(tname, target_p->name)) - continue; + if(!doall && wilds && !match(tname, target_p->name)) + continue; - cnt = report_this_status(source_p, target_p); - } + cnt = report_this_status(source_p, target_p); + } - if(MyConnect(source_p)) - { - RB_DLINK_FOREACH(ptr, unknown_list.head) - { - target_p = ptr->data; + if(MyConnect(source_p)) { + RB_DLINK_FOREACH(ptr, unknown_list.head) { + target_p = ptr->data; - if(!doall && wilds && !match(tname, target_p->name)) - continue; + if(!doall && wilds && !match(tname, target_p->name)) + continue; - cnt = report_this_status(source_p, target_p); - } - } + cnt = report_this_status(source_p, target_p); + } + } - if(!cnt) - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), - tname); + if(!cnt) { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), + tname); - /* let the user have some idea that its at the end of the - * trace - */ - sendto_one_numeric(source_p, RPL_ENDOFTRACE, - form_str(RPL_ENDOFTRACE), tname); - return 0; - } + /* let the user have some idea that its at the end of the + * trace + */ + sendto_one_numeric(source_p, RPL_ENDOFTRACE, + form_str(RPL_ENDOFTRACE), tname); + return 0; + } - if(doall) - { - RB_DLINK_FOREACH(ptr, class_list.head) - { - cltmp = ptr->data; + if(doall) { + RB_DLINK_FOREACH(ptr, class_list.head) { + cltmp = ptr->data; - if(CurrUsers(cltmp) > 0) - sendto_one_numeric(source_p, RPL_TRACECLASS, - form_str(RPL_TRACECLASS), - ClassName(cltmp), CurrUsers(cltmp)); - } - } + if(CurrUsers(cltmp) > 0) + sendto_one_numeric(source_p, RPL_TRACECLASS, + form_str(RPL_TRACECLASS), + ClassName(cltmp), CurrUsers(cltmp)); + } + } - sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), tname); + sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), tname); - return 0; + return 0; } /* @@ -311,14 +287,13 @@ m_trace(struct Client *client_p, struct Client *source_p, int parc, const char * static void count_downlinks(struct Client *server_p, int *pservcount, int *pusercount) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - (*pservcount)++; - *pusercount += rb_dlink_list_length(&server_p->serv->users); - RB_DLINK_FOREACH(ptr, server_p->serv->servers.head) - { - count_downlinks(ptr->data, pservcount, pusercount); - } + (*pservcount)++; + *pusercount += rb_dlink_list_length(&server_p->serv->users); + RB_DLINK_FOREACH(ptr, server_p->serv->servers.head) { + count_downlinks(ptr->data, pservcount, pusercount); + } } /* @@ -332,91 +307,88 @@ count_downlinks(struct Client *server_p, int *pservcount, int *pusercount) static int report_this_status(struct Client *source_p, struct Client *target_p) { - const char *name; - const char *class_name; - char ip[HOSTIPLEN]; - int cnt = 0; + const char *name; + const char *class_name; + char ip[HOSTIPLEN]; + int cnt = 0; - /* sanity check - should never happen */ - if(!MyConnect(target_p)) - return 0; + /* sanity check - should never happen */ + if(!MyConnect(target_p)) + return 0; - rb_inet_ntop_sock((struct sockaddr *)&target_p->localClient->ip, ip, sizeof(ip)); - class_name = get_client_class(target_p); + rb_inet_ntop_sock((struct sockaddr *)&target_p->localClient->ip, ip, sizeof(ip)); + class_name = get_client_class(target_p); - if(IsAnyServer(target_p)) - name = target_p->name; - else - name = get_client_name(target_p, HIDE_IP); + if(IsAnyServer(target_p)) + name = target_p->name; + else + name = get_client_name(target_p, HIDE_IP); - switch (target_p->status) - { - case STAT_CONNECTING: - sendto_one_numeric(source_p, RPL_TRACECONNECTING, - form_str(RPL_TRACECONNECTING), - class_name, name); - cnt++; - break; + switch (target_p->status) { + case STAT_CONNECTING: + sendto_one_numeric(source_p, RPL_TRACECONNECTING, + form_str(RPL_TRACECONNECTING), + class_name, name); + cnt++; + break; - case STAT_HANDSHAKE: - sendto_one_numeric(source_p, RPL_TRACEHANDSHAKE, - form_str(RPL_TRACEHANDSHAKE), - class_name, name); - cnt++; - break; + case STAT_HANDSHAKE: + sendto_one_numeric(source_p, RPL_TRACEHANDSHAKE, + form_str(RPL_TRACEHANDSHAKE), + class_name, name); + cnt++; + break; - case STAT_ME: - break; + case STAT_ME: + break; - case STAT_UNKNOWN: - /* added time -Taner */ - sendto_one_numeric(source_p, RPL_TRACEUNKNOWN, - form_str(RPL_TRACEUNKNOWN), - class_name, name, ip, - rb_current_time() - target_p->localClient->firsttime); - cnt++; - break; + case STAT_UNKNOWN: + /* added time -Taner */ + sendto_one_numeric(source_p, RPL_TRACEUNKNOWN, + form_str(RPL_TRACEUNKNOWN), + class_name, name, ip, + rb_current_time() - target_p->localClient->firsttime); + cnt++; + break; - case STAT_CLIENT: - { - int tnumeric; + case STAT_CLIENT: { + int tnumeric; - tnumeric = IsOper(target_p) ? RPL_TRACEOPERATOR : RPL_TRACEUSER; - sendto_one_numeric(source_p, tnumeric, form_str(tnumeric), - class_name, name, - show_ip(source_p, target_p) ? ip : empty_sockhost, - rb_current_time() - target_p->localClient->lasttime, - rb_current_time() - target_p->localClient->last); + tnumeric = IsOper(target_p) ? RPL_TRACEOPERATOR : RPL_TRACEUSER; + sendto_one_numeric(source_p, tnumeric, form_str(tnumeric), + class_name, name, + show_ip(source_p, target_p) ? ip : empty_sockhost, + rb_current_time() - target_p->localClient->lasttime, + rb_current_time() - target_p->localClient->last); - cnt++; - } - break; + cnt++; + } + break; - case STAT_SERVER: - { - int usercount = 0; - int servcount = 0; + case STAT_SERVER: { + int usercount = 0; + int servcount = 0; - count_downlinks(target_p, &servcount, &usercount); + count_downlinks(target_p, &servcount, &usercount); - sendto_one_numeric(source_p, RPL_TRACESERVER, form_str(RPL_TRACESERVER), - class_name, servcount, usercount, name, - *(target_p->serv->by) ? target_p->serv->by : "*", "*", - me.name, rb_current_time() - target_p->localClient->lasttime); - cnt++; + sendto_one_numeric(source_p, RPL_TRACESERVER, form_str(RPL_TRACESERVER), + class_name, servcount, usercount, name, + *(target_p->serv->by) ? target_p->serv->by : "*", "*", + me.name, rb_current_time() - target_p->localClient->lasttime); + cnt++; - } - break; + } + break; - default: /* ...we actually shouldn't come here... --msa */ - sendto_one_numeric(source_p, RPL_TRACENEWTYPE, - form_str(RPL_TRACENEWTYPE), - me.name, source_p->name, name); - cnt++; - break; - } + default: /* ...we actually shouldn't come here... --msa */ + sendto_one_numeric(source_p, RPL_TRACENEWTYPE, + form_str(RPL_TRACENEWTYPE), + me.name, source_p->name, name); + cnt++; + break; + } - return (cnt); + return (cnt); } /* trace_spy() @@ -428,10 +400,10 @@ report_this_status(struct Client *source_p, struct Client *target_p) static void trace_spy(struct Client *source_p, struct Client *target_p) { - hook_data_client hdata; + hook_data_client hdata; - hdata.client = source_p; - hdata.target = target_p; + hdata.client = source_p; + hdata.target = target_p; - call_hook(doing_trace_hook, &hdata); + call_hook(doing_trace_hook, &hdata); } diff --git a/modules/m_unreject.c b/modules/m_unreject.c index a6cc126..64656d5 100644 --- a/modules/m_unreject.c +++ b/modules/m_unreject.c @@ -34,8 +34,8 @@ static int mo_unreject(struct Client *, struct Client *, int, const char **); struct Message unreject_msgtab = { - "UNREJECT", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_unreject, 2}} + "UNREJECT", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_unreject, 2}} }; mapi_clist_av1 unreject_clist[] = { &unreject_msgtab, NULL }; @@ -48,23 +48,21 @@ DECLARE_MODULE_AV1(unreject, NULL, NULL, unreject_clist, NULL, NULL, "$Revision: static int mo_unreject(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0 || - ConfigFileEntry.reject_duration == 0) - { - sendto_one_notice(source_p, ":Reject cache is disabled"); - return 0; - } + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0 || + ConfigFileEntry.reject_duration == 0) { + sendto_one_notice(source_p, ":Reject cache is disabled"); + return 0; + } - if(!parse_netmask(parv[1], NULL, NULL)) - { - sendto_one_notice(source_p, ":Unable to parse netmask %s", parv[1]); - return 0; - } - - if(remove_reject_ip(parv[1])) - sendto_one_notice(source_p, ":Removed reject for %s", parv[1]); - else - sendto_one_notice(source_p, ":Unable to remove reject for %s", parv[1]); + if(!parse_netmask(parv[1], NULL, NULL)) { + sendto_one_notice(source_p, ":Unable to parse netmask %s", parv[1]); + return 0; + } - return 0; + if(remove_reject_ip(parv[1])) + sendto_one_notice(source_p, ":Removed reject for %s", parv[1]); + else + sendto_one_notice(source_p, ":Unable to remove reject for %s", parv[1]); + + return 0; } diff --git a/modules/m_user.c b/modules/m_user.c index cf8416e..724d6f5 100644 --- a/modules/m_user.c +++ b/modules/m_user.c @@ -39,15 +39,15 @@ static int mr_user(struct Client *, struct Client *, int, const char **); struct Message user_msgtab = { - "USER", 0, 0, 0, MFLG_SLOW, - {{mr_user, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} + "USER", 0, 0, 0, MFLG_SLOW, + {{mr_user, 5}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg} }; mapi_clist_av1 user_clist[] = { &user_msgtab, NULL }; DECLARE_MODULE_AV1(user, NULL, NULL, user_clist, NULL, NULL, "$Revision: 3416 $"); static int do_local_user(struct Client *client_p, struct Client *source_p, - const char *username, const char *realname); + const char *username, const char *realname); /* mr_user() * parv[1] = username (login name, account) @@ -58,58 +58,54 @@ static int do_local_user(struct Client *client_p, struct Client *source_p, static int mr_user(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static char buf[BUFSIZE]; - char *p; + static char buf[BUFSIZE]; + char *p; - if (strlen(client_p->id) == 3) - { - exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); - return 0; - } + if (strlen(client_p->id) == 3) { + exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); + return 0; + } - if((p = strchr(parv[1], '@'))) - *p = '\0'; + if((p = strchr(parv[1], '@'))) + *p = '\0'; - rb_snprintf(buf, sizeof(buf), "%s %s", parv[2], parv[3]); - rb_free(source_p->localClient->fullcaps); - source_p->localClient->fullcaps = rb_strdup(buf); + rb_snprintf(buf, sizeof(buf), "%s %s", parv[2], parv[3]); + rb_free(source_p->localClient->fullcaps); + source_p->localClient->fullcaps = rb_strdup(buf); - do_local_user(client_p, source_p, parv[1], parv[4]); - return 0; + do_local_user(client_p, source_p, parv[1], parv[4]); + return 0; } static int do_local_user(struct Client *client_p, struct Client *source_p, - const char *username, const char *realname) + const char *username, const char *realname) { - struct User *user; + struct User *user; - s_assert(NULL != source_p); - s_assert(source_p->username != username); + s_assert(NULL != source_p); + s_assert(source_p->username != username); - user = make_user(source_p); + user = make_user(source_p); - if (!(source_p->flags & FLAGS_SENTUSER)) - { - lookup_blacklists(source_p); - source_p->flags |= FLAGS_SENTUSER; - } + if (!(source_p->flags & FLAGS_SENTUSER)) { + lookup_blacklists(source_p); + source_p->flags |= FLAGS_SENTUSER; + } - rb_strlcpy(source_p->info, realname, sizeof(source_p->info)); + rb_strlcpy(source_p->info, realname, sizeof(source_p->info)); - if(!IsGotId(source_p)) - { - /* This is in this location for a reason..If there is no identd - * and ping cookies are enabled..we need to have a copy of this - */ - rb_strlcpy(source_p->username, username, sizeof(source_p->username)); - } + if(!IsGotId(source_p)) { + /* This is in this location for a reason..If there is no identd + * and ping cookies are enabled..we need to have a copy of this + */ + rb_strlcpy(source_p->username, username, sizeof(source_p->username)); + } - if(source_p->name[0]) - { - /* NICK already received, now I have USER... */ - return register_local_user(client_p, source_p, username); - } + if(source_p->name[0]) { + /* NICK already received, now I have USER... */ + return register_local_user(client_p, source_p, username); + } - return 0; + return 0; } diff --git a/modules/m_userhost.c b/modules/m_userhost.c index 8cae493..ff3b777 100644 --- a/modules/m_userhost.c +++ b/modules/m_userhost.c @@ -40,8 +40,8 @@ static char buf[BUFSIZE]; static int m_userhost(struct Client *, struct Client *, int, const char **); struct Message userhost_msgtab = { - "USERHOST", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_userhost, 2}, mg_ignore, mg_ignore, mg_ignore, {m_userhost, 2}} + "USERHOST", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_userhost, 2}, mg_ignore, mg_ignore, mg_ignore, {m_userhost, 2}} }; mapi_clist_av1 userhost_clist[] = { &userhost_msgtab, NULL }; @@ -55,59 +55,52 @@ DECLARE_MODULE_AV1(userhost, NULL, NULL, userhost_clist, NULL, NULL, "$Revision: static int m_userhost(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - char response[NICKLEN * 2 + USERLEN + HOSTLEN + 30]; - char *t; - int i; /* loop counter */ - int cur_len; - int rl; + struct Client *target_p; + char response[NICKLEN * 2 + USERLEN + HOSTLEN + 30]; + char *t; + int i; /* loop counter */ + int cur_len; + int rl; - cur_len = rb_sprintf(buf, form_str(RPL_USERHOST), me.name, source_p->name, ""); - t = buf + cur_len; + cur_len = rb_sprintf(buf, form_str(RPL_USERHOST), me.name, source_p->name, ""); + t = buf + cur_len; - for (i = 1; i <= 5; i++) - { - if(parc < i + 1) - break; + for (i = 1; i <= 5; i++) { + if(parc < i + 1) + break; - if((target_p = find_person(parv[i])) != NULL) - { - /* - * Show real IP for USERHOST on yourself. - * This is needed for things like mIRC, which do a server-based - * lookup (USERHOST) to figure out what the clients' local IP - * is. Useful for things like NAT, and dynamic dial-up users. - */ - if(MyClient(target_p) && (target_p == source_p)) - { - rl = rb_sprintf(response, "%s%s=%c%s@%s ", - target_p->name, - IsOper(target_p) ? "*" : "", - (target_p->user->away) ? '-' : '+', - target_p->username, - target_p->sockhost); - } - else - { - rl = rb_sprintf(response, "%s%s=%c%s@%s ", - target_p->name, - IsOper(target_p) ? "*" : "", - (target_p->user->away) ? '-' : '+', - target_p->username, target_p->host); - } + if((target_p = find_person(parv[i])) != NULL) { + /* + * Show real IP for USERHOST on yourself. + * This is needed for things like mIRC, which do a server-based + * lookup (USERHOST) to figure out what the clients' local IP + * is. Useful for things like NAT, and dynamic dial-up users. + */ + if(MyClient(target_p) && (target_p == source_p)) { + rl = rb_sprintf(response, "%s%s=%c%s@%s ", + target_p->name, + IsOper(target_p) ? "*" : "", + (target_p->user->away) ? '-' : '+', + target_p->username, + target_p->sockhost); + } else { + rl = rb_sprintf(response, "%s%s=%c%s@%s ", + target_p->name, + IsOper(target_p) ? "*" : "", + (target_p->user->away) ? '-' : '+', + target_p->username, target_p->host); + } - if((rl + cur_len) < (BUFSIZE - 10)) - { - rb_sprintf(t, "%s", response); - t += rl; - cur_len += rl; - } - else - break; - } - } + if((rl + cur_len) < (BUFSIZE - 10)) { + rb_sprintf(t, "%s", response); + t += rl; + cur_len += rl; + } else + break; + } + } - sendto_one(source_p, "%s", buf); + sendto_one(source_p, "%s", buf); - return 0; + return 0; } diff --git a/modules/m_users.c b/modules/m_users.c index fc9a087..8ba6e0f 100644 --- a/modules/m_users.c +++ b/modules/m_users.c @@ -37,8 +37,8 @@ static int m_users(struct Client *, struct Client *, int, const char **); struct Message users_msgtab = { - "USERS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_users, 0}, {m_users, 0}, mg_ignore, mg_ignore, {m_users, 0}} + "USERS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_users, 0}, {m_users, 0}, mg_ignore, mg_ignore, {m_users, 0}} }; mapi_clist_av1 users_clist[] = { &users_msgtab, NULL }; @@ -51,20 +51,19 @@ DECLARE_MODULE_AV1(users, NULL, NULL, users_clist, NULL, NULL, "$Revision: 254 $ static int m_users(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(hunt_server(client_p, source_p, ":%s USERS :%s", 1, parc, parv) == HUNTED_ISME) - { - sendto_one_numeric(source_p, RPL_LOCALUSERS, - form_str(RPL_LOCALUSERS), - rb_dlink_list_length(&lclient_list), - Count.max_loc, - rb_dlink_list_length(&lclient_list), - Count.max_loc); + if(hunt_server(client_p, source_p, ":%s USERS :%s", 1, parc, parv) == HUNTED_ISME) { + sendto_one_numeric(source_p, RPL_LOCALUSERS, + form_str(RPL_LOCALUSERS), + rb_dlink_list_length(&lclient_list), + Count.max_loc, + rb_dlink_list_length(&lclient_list), + Count.max_loc); - sendto_one_numeric(source_p, RPL_GLOBALUSERS, - form_str(RPL_GLOBALUSERS), - Count.total, Count.max_tot, - Count.total, Count.max_tot); - } + sendto_one_numeric(source_p, RPL_GLOBALUSERS, + form_str(RPL_GLOBALUSERS), + Count.total, Count.max_tot, + Count.total, Count.max_tot); + } - return 0; + return 0; } diff --git a/modules/m_version.c b/modules/m_version.c index f27633a..2d1805c 100644 --- a/modules/m_version.c +++ b/modules/m_version.c @@ -41,8 +41,8 @@ static int m_version(struct Client *, struct Client *, int, const char **); static int mo_version(struct Client *, struct Client *, int, const char **); struct Message version_msgtab = { - "VERSION", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_version, 0}, {mo_version, 0}, {mo_version, 0}, mg_ignore, {mo_version, 0}} + "VERSION", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_version, 0}, {mo_version, 0}, {mo_version, 0}, mg_ignore, {mo_version, 0}} }; mapi_clist_av1 version_clist[] = { &version_msgtab, NULL }; @@ -55,32 +55,29 @@ DECLARE_MODULE_AV1(version, NULL, NULL, version_clist, NULL, NULL, "$Revision: 1 static int m_version(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0L; + static time_t last_used = 0L; - if(parc > 1) - { - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "VERSION"); - return 0; - } - else - last_used = rb_current_time(); + if(parc > 1) { + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + /* safe enough to give this on a local connect only */ + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "VERSION"); + return 0; + } else + last_used = rb_current_time(); - if(hunt_server(client_p, source_p, ":%s VERSION :%s", 1, parc, parv) != HUNTED_ISME) - return 0; - } + if(hunt_server(client_p, source_p, ":%s VERSION :%s", 1, parc, parv) != HUNTED_ISME) + return 0; + } - sendto_one_numeric(source_p, RPL_VERSION, form_str(RPL_VERSION), - ircd_version, serno, - me.name, confopts(source_p), TS_CURRENT, - ServerInfo.sid); + sendto_one_numeric(source_p, RPL_VERSION, form_str(RPL_VERSION), + ircd_version, serno, + me.name, confopts(source_p), TS_CURRENT, + ServerInfo.sid); - show_isupport(source_p); + show_isupport(source_p); - return 0; + return 0; } /* @@ -90,16 +87,15 @@ m_version(struct Client *client_p, struct Client *source_p, int parc, const char static int mo_version(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(hunt_server(client_p, source_p, ":%s VERSION :%s", 1, parc, parv) == HUNTED_ISME) - { - sendto_one_numeric(source_p, RPL_VERSION, form_str(RPL_VERSION), - ircd_version, serno, - me.name, confopts(source_p), TS_CURRENT, - ServerInfo.sid); - show_isupport(source_p); - } + if(hunt_server(client_p, source_p, ":%s VERSION :%s", 1, parc, parv) == HUNTED_ISME) { + sendto_one_numeric(source_p, RPL_VERSION, form_str(RPL_VERSION), + ircd_version, serno, + me.name, confopts(source_p), TS_CURRENT, + ServerInfo.sid); + show_isupport(source_p); + } - return 0; + return 0; } /* confopts() @@ -110,43 +106,43 @@ mo_version(struct Client *client_p, struct Client *source_p, int parc, const cha static char * confopts(struct Client *source_p) { - static char result[15]; - char *p; + static char result[15]; + char *p; - result[0] = '\0'; - p = result; + result[0] = '\0'; + p = result; - if(ConfigChannel.use_except) - *p++ = 'e'; + if(ConfigChannel.use_except) + *p++ = 'e'; - /* might wanna hide this :P */ - if(ServerInfo.hub) - *p++ = 'H'; + /* might wanna hide this :P */ + if(ServerInfo.hub) + *p++ = 'H'; - if(ConfigChannel.use_invex) - *p++ = 'I'; + if(ConfigChannel.use_invex) + *p++ = 'I'; - if(ConfigChannel.use_knock) - *p++ = 'K'; + if(ConfigChannel.use_knock) + *p++ = 'K'; - *p++ = 'M'; - *p++ = 'p'; + *p++ = 'M'; + *p++ = 'p'; - if(opers_see_all_users || ConfigFileEntry.operspy_dont_care_user_info) - *p++ = 'S'; + if(opers_see_all_users || ConfigFileEntry.operspy_dont_care_user_info) + *p++ = 'S'; #ifdef IGNORE_BOGUS_TS - *p++ = 'T'; + *p++ = 'T'; #endif #ifdef HAVE_LIBZ - *p++ = 'Z'; + *p++ = 'Z'; #endif #ifdef RB_IPV6 - *p++ = '6'; + *p++ = '6'; #endif - *p = '\0'; + *p = '\0'; - return result; + return result; } diff --git a/modules/m_wallops.c b/modules/m_wallops.c index 58a83d8..e07fc4e 100644 --- a/modules/m_wallops.c +++ b/modules/m_wallops.c @@ -42,12 +42,12 @@ static int ms_operwall(struct Client *, struct Client *, int, const char **); static int ms_wallops(struct Client *, struct Client *, int, const char **); struct Message wallops_msgtab = { - "WALLOPS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_wallops, 2}, {ms_wallops, 2}, mg_ignore, {ms_wallops, 2}} + "WALLOPS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_wallops, 2}, {ms_wallops, 2}, mg_ignore, {ms_wallops, 2}} }; struct Message operwall_msgtab = { - "OPERWALL", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_operwall, 2}, mg_ignore, mg_ignore, {mo_operwall, 2}} + "OPERWALL", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_operwall, 2}, mg_ignore, mg_ignore, {mo_operwall, 2}} }; mapi_clist_av1 wallops_clist[] = { &wallops_msgtab, &operwall_msgtab, NULL }; @@ -60,18 +60,17 @@ DECLARE_MODULE_AV1(wallops, NULL, NULL, wallops_clist, NULL, NULL, "$Revision: 1 static int mo_operwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - if(!IsOperOperwall(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "operwall"); - return 0; - } + if(!IsOperOperwall(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "operwall"); + return 0; + } - sendto_wallops_flags(UMODE_OPERWALL, source_p, "OPERWALL - %s", parv[1]); - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s OPERWALL :%s", - use_id(source_p), parv[1]); + sendto_wallops_flags(UMODE_OPERWALL, source_p, "OPERWALL - %s", parv[1]); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s OPERWALL :%s", + use_id(source_p), parv[1]); - return 0; + return 0; } /* @@ -82,11 +81,11 @@ mo_operwall(struct Client *client_p, struct Client *source_p, int parc, const ch static int ms_operwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s OPERWALL :%s", - use_id(source_p), parv[1]); - sendto_wallops_flags(UMODE_OPERWALL, source_p, "OPERWALL - %s", parv[1]); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s OPERWALL :%s", + use_id(source_p), parv[1]); + sendto_wallops_flags(UMODE_OPERWALL, source_p, "OPERWALL - %s", parv[1]); - return 0; + return 0; } /* @@ -96,29 +95,27 @@ ms_operwall(struct Client *client_p, struct Client *source_p, int parc, const ch static int ms_wallops(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - const char *prefix = ""; + const char *prefix = ""; - if (MyClient(source_p) && !IsOperMassNotice(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "mass_notice"); - return 0; - } + if (MyClient(source_p) && !IsOperMassNotice(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "mass_notice"); + return 0; + } - if (IsPerson(source_p)) - { - if (!strncmp(parv[1], "OPERWALL - ", 11) || - !strncmp(parv[1], "LOCOPS - ", 9) || - !strncmp(parv[1], "SLOCOPS - ", 10) || - !strncmp(parv[1], "ADMINWALL - ", 12)) - prefix = "WALLOPS - "; - } + if (IsPerson(source_p)) { + if (!strncmp(parv[1], "OPERWALL - ", 11) || + !strncmp(parv[1], "LOCOPS - ", 9) || + !strncmp(parv[1], "SLOCOPS - ", 10) || + !strncmp(parv[1], "ADMINWALL - ", 12)) + prefix = "WALLOPS - "; + } - sendto_wallops_flags(UMODE_WALLOP, source_p, "%s%s", prefix, parv[1]); + sendto_wallops_flags(UMODE_WALLOP, source_p, "%s%s", prefix, parv[1]); - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s WALLOPS :%s", - use_id(source_p), parv[1]); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s WALLOPS :%s", + use_id(source_p), parv[1]); - return 0; + return 0; } diff --git a/modules/m_who.c b/modules/m_who.c index 769beea..1a1b007 100644 --- a/modules/m_who.c +++ b/modules/m_who.c @@ -54,31 +54,30 @@ #define FIELD_ACCOUNT 0x0800 #define FIELD_OPLEVEL 0x1000 /* meaningless and stupid, but whatever */ -struct who_format -{ - int fields; - const char *querytype; +struct who_format { + int fields; + const char *querytype; }; static int m_who(struct Client *, struct Client *, int, const char **); struct Message who_msgtab = { - "WHO", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_who, 2}, mg_ignore, mg_ignore, mg_ignore, {m_who, 2}} + "WHO", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_who, 2}, mg_ignore, mg_ignore, mg_ignore, {m_who, 2}} }; mapi_clist_av1 who_clist[] = { &who_msgtab, NULL }; DECLARE_MODULE_AV1(who, NULL, NULL, who_clist, NULL, NULL, "$Revision: 3350 $"); static void do_who_on_channel(struct Client *source_p, struct Channel *chptr, - int server_oper, int member, - struct who_format *fmt); + int server_oper, int member, + struct who_format *fmt); static void who_global(struct Client *source_p, const char *mask, int server_oper, int operspy, struct who_format *fmt); static void do_who(struct Client *source_p, - struct Client *target_p, struct membership *msptr, - struct who_format *fmt); + struct Client *target_p, struct membership *msptr, + struct who_format *fmt); /* @@ -89,179 +88,191 @@ static void do_who(struct Client *source_p, static int m_who(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; - struct Client *target_p; - struct membership *msptr; - char *mask; - rb_dlink_node *lp; - struct Channel *chptr = NULL; - int server_oper = parc > 2 ? (*parv[2] == 'o') : 0; /* Show OPERS only */ - int member; - int operspy = 0; - struct who_format fmt; - const char *s; - char maskcopy[512]; + static time_t last_used = 0; + struct Client *target_p; + struct membership *msptr; + char *mask; + rb_dlink_node *lp; + struct Channel *chptr = NULL; + int server_oper = parc > 2 ? (*parv[2] == 'o') : 0; /* Show OPERS only */ + int member; + int operspy = 0; + struct who_format fmt; + const char *s; + char maskcopy[512]; - fmt.fields = 0; - fmt.querytype = NULL; - if (parc > 2 && (s = strchr(parv[2], '%')) != NULL) - { - s++; - for (; *s != '\0'; s++) - { - switch (*s) - { - case 'c': fmt.fields |= FIELD_CHANNEL; break; - case 'd': fmt.fields |= FIELD_HOP; break; - case 'f': fmt.fields |= FIELD_FLAGS; break; - case 'h': fmt.fields |= FIELD_HOST; break; - case 'i': fmt.fields |= FIELD_IP; break; - case 'l': fmt.fields |= FIELD_IDLE; break; - case 'n': fmt.fields |= FIELD_NICK; break; - case 'r': fmt.fields |= FIELD_INFO; break; - case 's': fmt.fields |= FIELD_SERVER; break; - case 't': fmt.fields |= FIELD_QUERYTYPE; break; - case 'u': fmt.fields |= FIELD_USER; break; - case 'a': fmt.fields |= FIELD_ACCOUNT; break; - case 'o': fmt.fields |= FIELD_OPLEVEL; break; - case ',': - s++; - fmt.querytype = s; - s += strlen(s); - s--; - break; - } - } - if (EmptyString(fmt.querytype) || strlen(fmt.querytype) > 3) - fmt.querytype = "0"; - } + fmt.fields = 0; + fmt.querytype = NULL; + if (parc > 2 && (s = strchr(parv[2], '%')) != NULL) { + s++; + for (; *s != '\0'; s++) { + switch (*s) { + case 'c': + fmt.fields |= FIELD_CHANNEL; + break; + case 'd': + fmt.fields |= FIELD_HOP; + break; + case 'f': + fmt.fields |= FIELD_FLAGS; + break; + case 'h': + fmt.fields |= FIELD_HOST; + break; + case 'i': + fmt.fields |= FIELD_IP; + break; + case 'l': + fmt.fields |= FIELD_IDLE; + break; + case 'n': + fmt.fields |= FIELD_NICK; + break; + case 'r': + fmt.fields |= FIELD_INFO; + break; + case 's': + fmt.fields |= FIELD_SERVER; + break; + case 't': + fmt.fields |= FIELD_QUERYTYPE; + break; + case 'u': + fmt.fields |= FIELD_USER; + break; + case 'a': + fmt.fields |= FIELD_ACCOUNT; + break; + case 'o': + fmt.fields |= FIELD_OPLEVEL; + break; + case ',': + s++; + fmt.querytype = s; + s += strlen(s); + s--; + break; + } + } + if (EmptyString(fmt.querytype) || strlen(fmt.querytype) > 3) + fmt.querytype = "0"; + } - rb_strlcpy(maskcopy, parv[1], sizeof maskcopy); - mask = maskcopy; + rb_strlcpy(maskcopy, parv[1], sizeof maskcopy); + mask = maskcopy; - collapse(mask); + collapse(mask); - /* '/who *' */ - if((*(mask + 1) == '\0') && (*mask == '*')) - { - if(source_p->user == NULL) - return 0; + /* '/who *' */ + if((*(mask + 1) == '\0') && (*mask == '*')) { + if(source_p->user == NULL) + return 0; - if((lp = source_p->user->channel.head) != NULL) - { - msptr = lp->data; - do_who_on_channel(source_p, msptr->chptr, server_oper, YES, &fmt); - } + if((lp = source_p->user->channel.head) != NULL) { + msptr = lp->data; + do_who_on_channel(source_p, msptr->chptr, server_oper, YES, &fmt); + } - sendto_one(source_p, form_str(RPL_ENDOFWHO), - me.name, source_p->name, "*"); - return 0; - } + sendto_one(source_p, form_str(RPL_ENDOFWHO), + me.name, source_p->name, "*"); + return 0; + } - if(IsOperSpy(source_p) && *mask == '!') - { - mask++; - operspy = 1; + if(IsOperSpy(source_p) && *mask == '!') { + mask++; + operspy = 1; - if(EmptyString(mask)) - { - sendto_one(source_p, form_str(RPL_ENDOFWHO), - me.name, source_p->name, parv[1]); - return 0; - } - } + if(EmptyString(mask)) { + sendto_one(source_p, form_str(RPL_ENDOFWHO), + me.name, source_p->name, parv[1]); + return 0; + } + } - /* '/who #some_channel' */ - if(IsChannelName(mask)) - { - /* List all users on a given channel */ - chptr = find_channel(parv[1] + operspy); - if(chptr != NULL) - { - if(operspy) - report_operspy(source_p, "WHO", chptr->chname); + /* '/who #some_channel' */ + if(IsChannelName(mask)) { + /* List all users on a given channel */ + chptr = find_channel(parv[1] + operspy); + if(chptr != NULL) { + if(operspy) + report_operspy(source_p, "WHO", chptr->chname); - if(IsMember(source_p, chptr) || operspy) - do_who_on_channel(source_p, chptr, server_oper, YES, &fmt); - else if(!SecretChannel(chptr)) - do_who_on_channel(source_p, chptr, server_oper, NO, &fmt); - } - sendto_one(source_p, form_str(RPL_ENDOFWHO), - me.name, source_p->name, parv[1] + operspy); - return 0; - } + if(IsMember(source_p, chptr) || operspy) + do_who_on_channel(source_p, chptr, server_oper, YES, &fmt); + else if(!SecretChannel(chptr)) + do_who_on_channel(source_p, chptr, server_oper, NO, &fmt); + } + sendto_one(source_p, form_str(RPL_ENDOFWHO), + me.name, source_p->name, parv[1] + operspy); + return 0; + } - /* '/who nick' */ + /* '/who nick' */ - if(((target_p = find_named_person(mask)) != NULL) && - (!server_oper || IsOper(target_p))) - { - int isinvis = 0; + if(((target_p = find_named_person(mask)) != NULL) && + (!server_oper || IsOper(target_p))) { + int isinvis = 0; - isinvis = IsInvisible(target_p); - RB_DLINK_FOREACH(lp, target_p->user->channel.head) - { - msptr = lp->data; - chptr = msptr->chptr; + isinvis = IsInvisible(target_p); + RB_DLINK_FOREACH(lp, target_p->user->channel.head) { + msptr = lp->data; + chptr = msptr->chptr; - member = IsMember(source_p, chptr); + member = IsMember(source_p, chptr); - if(isinvis && !member) - continue; + if(isinvis && !member) + continue; - if(member || (!isinvis && PubChannel(chptr))) - break; - } + if(member || (!isinvis && PubChannel(chptr))) + break; + } - /* if we stopped midlist, lp->data is the membership for - * target_p of chptr - */ - if(lp != NULL) - do_who(source_p, target_p, lp->data, &fmt); - else - do_who(source_p, target_p, NULL, &fmt); + /* if we stopped midlist, lp->data is the membership for + * target_p of chptr + */ + if(lp != NULL) + do_who(source_p, target_p, lp->data, &fmt); + else + do_who(source_p, target_p, NULL, &fmt); - sendto_one(source_p, form_str(RPL_ENDOFWHO), - me.name, source_p->name, mask); - return 0; - } + sendto_one(source_p, form_str(RPL_ENDOFWHO), + me.name, source_p->name, mask); + return 0; + } - if(!IsFloodDone(source_p)) - flood_endgrace(source_p); + if(!IsFloodDone(source_p)) + flood_endgrace(source_p); - /* it has to be a global who at this point, limit it */ - if(!IsOper(source_p)) - { - if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "WHO"); - sendto_one(source_p, form_str(RPL_ENDOFWHO), - me.name, source_p->name, "*"); - return 0; - } - else - last_used = rb_current_time(); - } + /* it has to be a global who at this point, limit it */ + if(!IsOper(source_p)) { + if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "WHO"); + sendto_one(source_p, form_str(RPL_ENDOFWHO), + me.name, source_p->name, "*"); + return 0; + } else + last_used = rb_current_time(); + } - /* Note: operspy_dont_care_user_info does not apply to - * who on channels */ - if(IsOperSpy(source_p) && ConfigFileEntry.operspy_dont_care_user_info) - operspy = 1; + /* Note: operspy_dont_care_user_info does not apply to + * who on channels */ + if(IsOperSpy(source_p) && ConfigFileEntry.operspy_dont_care_user_info) + operspy = 1; - /* '/who 0' for a global list. this forces clients to actually - * request a full list. I presume its because of too many typos - * with "/who" ;) --fl - */ - if((*(mask + 1) == '\0') && (*mask == '0')) - who_global(source_p, NULL, server_oper, 0, &fmt); - else - who_global(source_p, mask, server_oper, operspy, &fmt); + /* '/who 0' for a global list. this forces clients to actually + * request a full list. I presume its because of too many typos + * with "/who" ;) --fl + */ + if((*(mask + 1) == '\0') && (*mask == '0')) + who_global(source_p, NULL, server_oper, 0, &fmt); + else + who_global(source_p, mask, server_oper, operspy, &fmt); - sendto_one(source_p, form_str(RPL_ENDOFWHO), - me.name, source_p->name, mask); + sendto_one(source_p, form_str(RPL_ENDOFWHO), + me.name, source_p->name, mask); - return 0; + return 0; } /* who_common_channel @@ -277,39 +288,36 @@ m_who(struct Client *client_p, struct Client *source_p, int parc, const char *pa */ static void who_common_channel(struct Client *source_p, struct Channel *chptr, - const char *mask, int server_oper, int *maxmatches, - struct who_format *fmt) + const char *mask, int server_oper, int *maxmatches, + struct who_format *fmt) { - struct membership *msptr; - struct Client *target_p; - rb_dlink_node *ptr; + struct membership *msptr; + struct Client *target_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(!IsInvisible(target_p) || IsMarked(target_p)) - continue; + if(!IsInvisible(target_p) || IsMarked(target_p)) + continue; - if(server_oper && !IsOper(target_p)) - continue; + if(server_oper && !IsOper(target_p)) + continue; - SetMark(target_p); + SetMark(target_p); - if(*maxmatches > 0) - { - if((mask == NULL) || - match(mask, target_p->name) || match(mask, target_p->username) || - match(mask, target_p->host) || match(mask, target_p->servptr->name) || - (IsOper(source_p) && match(mask, target_p->orighost)) || - match(mask, target_p->info)) - { - do_who(source_p, target_p, NULL, fmt); - --(*maxmatches); - } - } - } + if(*maxmatches > 0) { + if((mask == NULL) || + match(mask, target_p->name) || match(mask, target_p->username) || + match(mask, target_p->host) || match(mask, target_p->servptr->name) || + (IsOper(source_p) && match(mask, target_p->orighost)) || + match(mask, target_p->info)) { + do_who(source_p, target_p, NULL, fmt); + --(*maxmatches); + } + } + } } /* @@ -329,63 +337,56 @@ who_common_channel(struct Client *source_p, struct Channel *chptr, static void who_global(struct Client *source_p, const char *mask, int server_oper, int operspy, struct who_format *fmt) { - struct membership *msptr; - struct Client *target_p; - rb_dlink_node *lp, *ptr; - int maxmatches = 500; + struct membership *msptr; + struct Client *target_p; + rb_dlink_node *lp, *ptr; + int maxmatches = 500; - /* first, list all matching INvisible clients on common channels - * if this is not an operspy who - */ - if(!operspy) - { - RB_DLINK_FOREACH(lp, source_p->user->channel.head) - { - msptr = lp->data; - who_common_channel(source_p, msptr->chptr, mask, server_oper, &maxmatches, fmt); - } - } - else if (!ConfigFileEntry.operspy_dont_care_user_info) - report_operspy(source_p, "WHO", mask); + /* first, list all matching INvisible clients on common channels + * if this is not an operspy who + */ + if(!operspy) { + RB_DLINK_FOREACH(lp, source_p->user->channel.head) { + msptr = lp->data; + who_common_channel(source_p, msptr->chptr, mask, server_oper, &maxmatches, fmt); + } + } else if (!ConfigFileEntry.operspy_dont_care_user_info) + report_operspy(source_p, "WHO", mask); - /* second, list all matching visible clients and clear all marks - * on invisible clients - * if this is an operspy who, list all matching clients, no need - * to clear marks - */ - RB_DLINK_FOREACH(ptr, global_client_list.head) - { - target_p = ptr->data; - if(!IsPerson(target_p)) - continue; + /* second, list all matching visible clients and clear all marks + * on invisible clients + * if this is an operspy who, list all matching clients, no need + * to clear marks + */ + RB_DLINK_FOREACH(ptr, global_client_list.head) { + target_p = ptr->data; + if(!IsPerson(target_p)) + continue; - if(IsInvisible(target_p) && !operspy) - { - ClearMark(target_p); - continue; - } + if(IsInvisible(target_p) && !operspy) { + ClearMark(target_p); + continue; + } - if(server_oper && !IsOper(target_p)) - continue; + if(server_oper && !IsOper(target_p)) + continue; - if(maxmatches > 0) - { - if(!mask || - match(mask, target_p->name) || match(mask, target_p->username) || - match(mask, target_p->host) || match(mask, target_p->servptr->name) || - (IsOper(source_p) && match(mask, target_p->orighost)) || - match(mask, target_p->info)) - { - do_who(source_p, target_p, NULL, fmt); - --maxmatches; - } - } - } + if(maxmatches > 0) { + if(!mask || + match(mask, target_p->name) || match(mask, target_p->username) || + match(mask, target_p->host) || match(mask, target_p->servptr->name) || + (IsOper(source_p) && match(mask, target_p->orighost)) || + match(mask, target_p->info)) { + do_who(source_p, target_p, NULL, fmt); + --maxmatches; + } + } + } - if (maxmatches <= 0) - sendto_one(source_p, - form_str(ERR_TOOMANYMATCHES), - me.name, source_p->name, "WHO"); + if (maxmatches <= 0) + sendto_one(source_p, + form_str(ERR_TOOMANYMATCHES), + me.name, source_p->name, "WHO"); } /* @@ -402,23 +403,22 @@ who_global(struct Client *source_p, const char *mask, int server_oper, int opers */ static void do_who_on_channel(struct Client *source_p, struct Channel *chptr, - int server_oper, int member, struct who_format *fmt) + int server_oper, int member, struct who_format *fmt) { - struct Client *target_p; - struct membership *msptr; - rb_dlink_node *ptr; + struct Client *target_p; + struct membership *msptr; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(server_oper && !IsOper(target_p)) - continue; + if(server_oper && !IsOper(target_p)) + continue; - if(member || !IsInvisible(target_p)) - do_who(source_p, target_p, msptr, fmt); - } + if(member || !IsInvisible(target_p)) + do_who(source_p, target_p, msptr, fmt); + } } /* @@ -436,14 +436,14 @@ do_who_on_channel(struct Client *source_p, struct Channel *chptr, static void append_format(char *buf, size_t bufsize, size_t *pos, const char *fmt, ...) { - size_t max, result; - va_list ap; + size_t max, result; + va_list ap; - max = *pos >= bufsize ? 0 : bufsize - *pos; - va_start(ap, fmt); - result = rb_vsnprintf(buf + *pos, max, fmt, ap); - va_end(ap); - *pos += result; + max = *pos >= bufsize ? 0 : bufsize - *pos; + va_start(ap, fmt); + result = rb_vsnprintf(buf + *pos, max, fmt, ap); + va_end(ap); + *pos += result; } /* @@ -460,81 +460,75 @@ append_format(char *buf, size_t bufsize, size_t *pos, const char *fmt, ...) static void do_who(struct Client *source_p, struct Client *target_p, struct membership *msptr, struct who_format *fmt) { - char status[16]; - char str[510 + 1]; /* linebuf.c will add \r\n */ - size_t pos; - const char *q; + char status[16]; + char str[510 + 1]; /* linebuf.c will add \r\n */ + size_t pos; + const char *q; - rb_sprintf(status, "%c%s%s", - target_p->user->away ? 'G' : 'H', IsOper(target_p) ? "*" : "", msptr ? find_channel_status(msptr, fmt->fields || IsCapable(source_p, CLICAP_MULTI_PREFIX)) : ""); + rb_sprintf(status, "%c%s%s", + target_p->user->away ? 'G' : 'H', IsOper(target_p) ? "*" : "", msptr ? find_channel_status(msptr, fmt->fields || IsCapable(source_p, CLICAP_MULTI_PREFIX)) : ""); - if (fmt->fields == 0) - sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, - source_p->name, msptr ? msptr->chptr->chname : "*", - target_p->username, target_p->host, - target_p->servptr->name, target_p->name, status, - ConfigServerHide.flatten_links && !IsOper(source_p) && !IsExemptShide(source_p) ? 0 : target_p->hopcount, - target_p->info); - else - { - str[0] = '\0'; - pos = 0; - append_format(str, sizeof str, &pos, ":%s %d %s", - me.name, RPL_WHOSPCRPL, source_p->name); - if (fmt->fields & FIELD_QUERYTYPE) - append_format(str, sizeof str, &pos, " %s", fmt->querytype); - if (fmt->fields & FIELD_CHANNEL) - append_format(str, sizeof str, &pos, " %s", msptr ? msptr->chptr->chname : "*"); - if (fmt->fields & FIELD_USER) - append_format(str, sizeof str, &pos, " %s", target_p->username); - if (fmt->fields & FIELD_IP) - { - if (show_ip(source_p, target_p) && !EmptyString(target_p->sockhost) && strcmp(target_p->sockhost, "0")) - append_format(str, sizeof str, &pos, " %s", target_p->sockhost); - else - append_format(str, sizeof str, &pos, " %s", "255.255.255.255"); - } - if (fmt->fields & FIELD_HOST) - append_format(str, sizeof str, &pos, " %s", target_p->host); - if (fmt->fields & FIELD_SERVER) - append_format(str, sizeof str, &pos, " %s", target_p->servptr->name); - if (fmt->fields & FIELD_NICK) - append_format(str, sizeof str, &pos, " %s", target_p->name); - if (fmt->fields & FIELD_FLAGS) - append_format(str, sizeof str, &pos, " %s", status); - if (fmt->fields & FIELD_HOP) - append_format(str, sizeof str, &pos, " %d", ConfigServerHide.flatten_links && !IsOper(source_p) && !IsExemptShide(source_p) ? 0 : target_p->hopcount); - if (fmt->fields & FIELD_IDLE) - append_format(str, sizeof str, &pos, " %d", (int)(MyClient(target_p) ? rb_current_time() - target_p->localClient->last : 0)); - if (fmt->fields & FIELD_ACCOUNT) - { - /* display as in whois */ - q = target_p->user->suser; - if (!EmptyString(q)) - { - while(IsDigit(*q)) - q++; - if(*q == '\0') - q = target_p->user->suser; - } - else - q = "0"; - append_format(str, sizeof str, &pos, " %s", q); - } - if (fmt->fields & FIELD_OPLEVEL) - append_format(str, sizeof str, &pos, " %s", is_chanop(msptr) ? "999" : "n/a"); - if (fmt->fields & FIELD_INFO) - append_format(str, sizeof str, &pos, " :%s", target_p->info); + if (fmt->fields == 0) + sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, + source_p->name, msptr ? msptr->chptr->chname : "*", + target_p->username, target_p->host, + target_p->servptr->name, target_p->name, status, + ConfigServerHide.flatten_links && !IsOper(source_p) && !IsExemptShide(source_p) ? 0 : target_p->hopcount, + target_p->info); + else { + str[0] = '\0'; + pos = 0; + append_format(str, sizeof str, &pos, ":%s %d %s", + me.name, RPL_WHOSPCRPL, source_p->name); + if (fmt->fields & FIELD_QUERYTYPE) + append_format(str, sizeof str, &pos, " %s", fmt->querytype); + if (fmt->fields & FIELD_CHANNEL) + append_format(str, sizeof str, &pos, " %s", msptr ? msptr->chptr->chname : "*"); + if (fmt->fields & FIELD_USER) + append_format(str, sizeof str, &pos, " %s", target_p->username); + if (fmt->fields & FIELD_IP) { + if (show_ip(source_p, target_p) && !EmptyString(target_p->sockhost) && strcmp(target_p->sockhost, "0")) + append_format(str, sizeof str, &pos, " %s", target_p->sockhost); + else + append_format(str, sizeof str, &pos, " %s", "255.255.255.255"); + } + if (fmt->fields & FIELD_HOST) + append_format(str, sizeof str, &pos, " %s", target_p->host); + if (fmt->fields & FIELD_SERVER) + append_format(str, sizeof str, &pos, " %s", target_p->servptr->name); + if (fmt->fields & FIELD_NICK) + append_format(str, sizeof str, &pos, " %s", target_p->name); + if (fmt->fields & FIELD_FLAGS) + append_format(str, sizeof str, &pos, " %s", status); + if (fmt->fields & FIELD_HOP) + append_format(str, sizeof str, &pos, " %d", ConfigServerHide.flatten_links && !IsOper(source_p) && !IsExemptShide(source_p) ? 0 : target_p->hopcount); + if (fmt->fields & FIELD_IDLE) + append_format(str, sizeof str, &pos, " %d", (int)(MyClient(target_p) ? rb_current_time() - target_p->localClient->last : 0)); + if (fmt->fields & FIELD_ACCOUNT) { + /* display as in whois */ + q = target_p->user->suser; + if (!EmptyString(q)) { + while(IsDigit(*q)) + q++; + if(*q == '\0') + q = target_p->user->suser; + } else + q = "0"; + append_format(str, sizeof str, &pos, " %s", q); + } + if (fmt->fields & FIELD_OPLEVEL) + append_format(str, sizeof str, &pos, " %s", is_chanop(msptr) ? "999" : "n/a"); + if (fmt->fields & FIELD_INFO) + append_format(str, sizeof str, &pos, " :%s", target_p->info); - if (pos >= sizeof str) - { - static int warned = 0; - if (!warned) - sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, - "WHOX overflow while sending information about %s to %s", - target_p->name, source_p->name); - warned = 1; - } - sendto_one(source_p, "%s", str); - } + if (pos >= sizeof str) { + static int warned = 0; + if (!warned) + sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, + "WHOX overflow while sending information about %s to %s", + target_p->name, source_p->name); + warned = 1; + } + sendto_one(source_p, "%s", str); + } } diff --git a/modules/m_whois.c b/modules/m_whois.c index 1daedce..eef1d4b 100644 --- a/modules/m_whois.c +++ b/modules/m_whois.c @@ -51,8 +51,8 @@ static int m_whois(struct Client *, struct Client *, int, const char **); static int ms_whois(struct Client *, struct Client *, int, const char **); struct Message whois_msgtab = { - "WHOIS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_whois, 2}, {ms_whois, 2}, mg_ignore, mg_ignore, {m_whois, 2}} + "WHOIS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_whois, 2}, {ms_whois, 2}, mg_ignore, mg_ignore, {m_whois, 2}} }; int doing_whois_hook; @@ -60,9 +60,9 @@ int doing_whois_global_hook; mapi_clist_av1 whois_clist[] = { &whois_msgtab, NULL }; mapi_hlist_av1 whois_hlist[] = { - { "doing_whois", &doing_whois_hook }, - { "doing_whois_global", &doing_whois_global_hook }, - { NULL, NULL } + { "doing_whois", &doing_whois_hook }, + { "doing_whois_global", &doing_whois_global_hook }, + { NULL, NULL } }; DECLARE_MODULE_AV1(whois, NULL, NULL, whois_clist, whois_hlist, NULL, "$Revision: 3536 $"); @@ -74,42 +74,37 @@ DECLARE_MODULE_AV1(whois, NULL, NULL, whois_clist, whois_hlist, NULL, "$Revision static int m_whois(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; + static time_t last_used = 0; - if(parc > 2) - { - if(EmptyString(parv[2])) - { - sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), - me.name, source_p->name); - return 0; - } + if(parc > 2) { + if(EmptyString(parv[2])) { + sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), + me.name, source_p->name); + return 0; + } - if(!IsOper(source_p)) - { - /* seeing as this is going across servers, we should limit it */ - if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "WHOIS"); - sendto_one_numeric(source_p, RPL_ENDOFWHOIS, - form_str(RPL_ENDOFWHOIS), parv[2]); - return 0; - } - else - last_used = rb_current_time(); - } + if(!IsOper(source_p)) { + /* seeing as this is going across servers, we should limit it */ + if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "WHOIS"); + sendto_one_numeric(source_p, RPL_ENDOFWHOIS, + form_str(RPL_ENDOFWHOIS), parv[2]); + return 0; + } else + last_used = rb_current_time(); + } - if(hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1, parc, parv) != - HUNTED_ISME) - return 0; + if(hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1, parc, parv) != + HUNTED_ISME) + return 0; - parv[1] = parv[2]; + parv[1] = parv[2]; - } - do_whois(client_p, source_p, parc, parv); + } + do_whois(client_p, source_p, parc, parv); - return 0; + return 0; } /* @@ -120,100 +115,93 @@ m_whois(struct Client *client_p, struct Client *source_p, int parc, const char * static int ms_whois(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; + struct Client *target_p; - /* note: early versions of ratbox allowed users to issue a remote - * whois with a blank parv[2], so we cannot treat it as a protocol - * violation. --anfl - */ - if(parc < 3 || EmptyString(parv[2])) - { - sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), - me.name, source_p->name); - return 0; - } + /* note: early versions of ratbox allowed users to issue a remote + * whois with a blank parv[2], so we cannot treat it as a protocol + * violation. --anfl + */ + if(parc < 3 || EmptyString(parv[2])) { + sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), + me.name, source_p->name); + return 0; + } - /* check if parv[1] exists */ - if((target_p = find_client(parv[1])) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), - IsDigit(parv[1][0]) ? "*" : parv[1]); - return 0; - } + /* check if parv[1] exists */ + if((target_p = find_client(parv[1])) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), + IsDigit(parv[1][0]) ? "*" : parv[1]); + return 0; + } - /* if parv[1] isnt my client, or me, someone else is supposed - * to be handling the request.. so send it to them - */ - if(!MyClient(target_p) && !IsMe(target_p)) - { - sendto_one(target_p, ":%s WHOIS %s :%s", - get_id(source_p, target_p), - get_id(target_p, target_p), parv[2]); - return 0; - } + /* if parv[1] isnt my client, or me, someone else is supposed + * to be handling the request.. so send it to them + */ + if(!MyClient(target_p) && !IsMe(target_p)) { + sendto_one(target_p, ":%s WHOIS %s :%s", + get_id(source_p, target_p), + get_id(target_p, target_p), parv[2]); + return 0; + } - /* ok, the target is either us, or a client on our server, so perform the whois - * but first, parv[1] == server to perform the whois on, parv[2] == person - * to whois, so make parv[1] = parv[2] so do_whois is ok -- fl_ - */ - parv[1] = parv[2]; - do_whois(client_p, source_p, parc, parv); + /* ok, the target is either us, or a client on our server, so perform the whois + * but first, parv[1] == server to perform the whois on, parv[2] == person + * to whois, so make parv[1] = parv[2] so do_whois is ok -- fl_ + */ + parv[1] = parv[2]; + do_whois(client_p, source_p, parc, parv); - return 0; + return 0; } /* do_whois * - * inputs - pointer to - * output - + * inputs - pointer to + * output - * side effects - */ static void do_whois(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct Client *target_p; - char *nick; - char *p = NULL; - int operspy = 0; + struct Client *target_p; + char *nick; + char *p = NULL; + int operspy = 0; - nick = LOCAL_COPY(parv[1]); - if((p = strchr(nick, ','))) - *p = '\0'; + nick = LOCAL_COPY(parv[1]); + if((p = strchr(nick, ','))) + *p = '\0'; - if(IsOperSpy(source_p) && *nick == '!') - { - operspy = 1; - nick++; - } + if(IsOperSpy(source_p) && *nick == '!') { + operspy = 1; + nick++; + } - if(MyClient(source_p)) - target_p = find_named_person(nick); - else - target_p = find_person(nick); + if(MyClient(source_p)) + target_p = find_named_person(nick); + else + target_p = find_person(nick); - if(target_p != NULL) - { - if(operspy) - { - char buffer[BUFSIZE]; + if(target_p != NULL) { + if(operspy) { + char buffer[BUFSIZE]; - rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s %s", - target_p->name, target_p->username, - target_p->host, target_p->servptr->name); - report_operspy(source_p, "WHOIS", buffer); - } + rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s %s", + target_p->name, target_p->username, + target_p->host, target_p->servptr->name); + report_operspy(source_p, "WHOIS", buffer); + } - single_whois(source_p, target_p, operspy); - } - else - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), - nick); + single_whois(source_p, target_p, operspy); + } else + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), + nick); - sendto_one_numeric(source_p, RPL_ENDOFWHOIS, - form_str(RPL_ENDOFWHOIS), parv[1]); - return; + sendto_one_numeric(source_p, RPL_ENDOFWHOIS, + form_str(RPL_ENDOFWHOIS), parv[1]); + return; } /* @@ -228,194 +216,178 @@ do_whois(struct Client *client_p, struct Client *source_p, int parc, const char static void single_whois(struct Client *source_p, struct Client *target_p, int operspy) { - char buf[BUFSIZE]; - rb_dlink_node *ptr; - struct membership *msptr; - struct Channel *chptr; - int cur_len = 0; - int mlen; - char *t; - int tlen; - hook_data_client hdata; - int visible; - int extra_space = 0; - int i; - char *m; - int showsecret = 0; - struct Metadata *md; + char buf[BUFSIZE]; + rb_dlink_node *ptr; + struct membership *msptr; + struct Channel *chptr; + int cur_len = 0; + int mlen; + char *t; + int tlen; + hook_data_client hdata; + int visible; + int extra_space = 0; + int i; + char *m; + int showsecret = 0; + struct Metadata *md; - if(ConfigFileEntry.secret_channels_in_whois && IsOperSpy(source_p)) - showsecret = 1; + if(ConfigFileEntry.secret_channels_in_whois && IsOperSpy(source_p)) + showsecret = 1; - if(target_p->user == NULL) - { - s_assert(0); - return; - } + if(target_p->user == NULL) { + s_assert(0); + return; + } - sendto_one_numeric(source_p, RPL_WHOISUSER, form_str(RPL_WHOISUSER), - target_p->name, target_p->username, - target_p->host, target_p->info); + sendto_one_numeric(source_p, RPL_WHOISUSER, form_str(RPL_WHOISUSER), + target_p->name, target_p->username, + target_p->host, target_p->info); - cur_len = mlen = rb_sprintf(buf, form_str(RPL_WHOISCHANNELS), - get_id(&me, source_p), get_id(source_p, source_p), - target_p->name); + cur_len = mlen = rb_sprintf(buf, form_str(RPL_WHOISCHANNELS), + get_id(&me, source_p), get_id(source_p, source_p), + target_p->name); - /* Make sure it won't overflow when sending it to the client - * in full names; note that serverhiding may require more space - * for a different server name (not done here) -- jilles - */ - if (!MyConnect(source_p)) - { - extra_space = strlen(source_p->name) - 9; - if (extra_space < 0) - extra_space = 0; - extra_space += strlen(me.name) - 2; /* make sure >= 0 */ - cur_len += extra_space; - } + /* Make sure it won't overflow when sending it to the client + * in full names; note that serverhiding may require more space + * for a different server name (not done here) -- jilles + */ + if (!MyConnect(source_p)) { + extra_space = strlen(source_p->name) - 9; + if (extra_space < 0) + extra_space = 0; + extra_space += strlen(me.name) - 2; /* make sure >= 0 */ + cur_len += extra_space; + } - t = buf + mlen; + t = buf + mlen; - if (!IsService(target_p) && (!(target_p->umodes & UMODE_HIDECHANS) || IsOper(source_p))) - { - RB_DLINK_FOREACH(ptr, target_p->user->channel.head) - { - msptr = ptr->data; - chptr = msptr->chptr; + if (!IsService(target_p) && (!(target_p->umodes & UMODE_HIDECHANS) || IsOper(source_p))) { + RB_DLINK_FOREACH(ptr, target_p->user->channel.head) { + msptr = ptr->data; + chptr = msptr->chptr; - visible = ShowChannel(source_p, chptr); + visible = ShowChannel(source_p, chptr); - if(visible || operspy || showsecret) - { - if((cur_len + strlen(chptr->chname) + 3) > (BUFSIZE - 5)) - { - sendto_one(source_p, "%s", buf); - cur_len = mlen + extra_space; - t = buf + mlen; - } + if(visible || operspy || showsecret) { + if((cur_len + strlen(chptr->chname) + 3) > (BUFSIZE - 5)) { + sendto_one(source_p, "%s", buf); + cur_len = mlen + extra_space; + t = buf + mlen; + } - tlen = rb_sprintf(t, "%s%s%s ", - visible ? "" : "*", - find_channel_status(msptr, 1), - chptr->chname); - t += tlen; - cur_len += tlen; - } - } - } + tlen = rb_sprintf(t, "%s%s%s ", + visible ? "" : "*", + find_channel_status(msptr, 1), + chptr->chname); + t += tlen; + cur_len += tlen; + } + } + } - if(cur_len > mlen + extra_space) - sendto_one(source_p, "%s", buf); + if(cur_len > mlen + extra_space) + sendto_one(source_p, "%s", buf); - sendto_one_numeric(source_p, RPL_WHOISSERVER, form_str(RPL_WHOISSERVER), - target_p->name, target_p->servptr->name, - target_p->servptr->info); + sendto_one_numeric(source_p, RPL_WHOISSERVER, form_str(RPL_WHOISSERVER), + target_p->name, target_p->servptr->name, + target_p->servptr->info); - if(target_p->user->away) - sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), - target_p->name, target_p->user->away); + if(target_p->user->away) + sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), + target_p->name, target_p->user->away); - if(IsOper(target_p)) - { - if((md = user_metadata_find(target_p, "OPERSTRING")) != NULL) - sendto_one_numeric(source_p, 313, "%s :%s", target_p->name, md->value); - else - sendto_one_numeric(source_p, RPL_WHOISOPERATOR, form_str(RPL_WHOISOPERATOR), - target_p->name, - IsService(target_p) ? ConfigFileEntry.servicestring : - (IsAdmin(target_p) ? GlobalSetOptions.adminstring : - GlobalSetOptions.operstring)); - if((md = user_metadata_find(target_p, "SWHOIS")) != NULL) - sendto_one_numeric(source_p, 320, "%s :%s", target_p->name, md->value); - } + if(IsOper(target_p)) { + if((md = user_metadata_find(target_p, "OPERSTRING")) != NULL) + sendto_one_numeric(source_p, 313, "%s :%s", target_p->name, md->value); + else + sendto_one_numeric(source_p, RPL_WHOISOPERATOR, form_str(RPL_WHOISOPERATOR), + target_p->name, + IsService(target_p) ? ConfigFileEntry.servicestring : + (IsAdmin(target_p) ? GlobalSetOptions.adminstring : + GlobalSetOptions.operstring)); + if((md = user_metadata_find(target_p, "SWHOIS")) != NULL) + sendto_one_numeric(source_p, 320, "%s :%s", target_p->name, md->value); + } - if(IsSSLClient(target_p)) - sendto_one_numeric(source_p, RPL_WHOISSECURE, form_str(RPL_WHOISSECURE), - target_p->name); - if((source_p == target_p || IsOper(source_p)) && - target_p->certfp != NULL) - sendto_one_numeric(source_p, RPL_WHOISCERTFP, - form_str(RPL_WHOISCERTFP), - target_p->name, target_p->certfp); + if(IsSSLClient(target_p)) + sendto_one_numeric(source_p, RPL_WHOISSECURE, form_str(RPL_WHOISSECURE), + target_p->name); + if((source_p == target_p || IsOper(source_p)) && + target_p->certfp != NULL) + sendto_one_numeric(source_p, RPL_WHOISCERTFP, + form_str(RPL_WHOISCERTFP), + target_p->name, target_p->certfp); - if(IsSetBot(target_p)) - sendto_one_numeric(source_p, RPL_WHOISBOT, - form_str(RPL_WHOISBOT), - target_p->name); - if(IsOper(source_p) || source_p == target_p) - { - m = buf; - *m++ = '+'; + if(IsSetBot(target_p)) + sendto_one_numeric(source_p, RPL_WHOISBOT, + form_str(RPL_WHOISBOT), + target_p->name); + if(IsOper(source_p) || source_p == target_p) { + m = buf; + *m++ = '+'; - for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ - if (target_p->umodes & user_modes[i]) - *m++ = (char) i; - *m = '\0'; + for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ + if (target_p->umodes & user_modes[i]) + *m++ = (char) i; + *m = '\0'; - sendto_one_numeric(source_p, RPL_WHOISMODES, - form_str(RPL_WHOISMODES), - target_p->name, buf); - } + sendto_one_numeric(source_p, RPL_WHOISMODES, + form_str(RPL_WHOISMODES), + target_p->name, buf); + } - if(MyClient(target_p)) - { - if (IsDynSpoof(target_p) && (IsOper(source_p) || source_p == target_p)) - { - /* trick here: show a nonoper their own IP if - * dynamic spoofed but not if auth{} spoofed - * -- jilles */ - ClearDynSpoof(target_p); - sendto_one_numeric(source_p, RPL_WHOISHOST, - form_str(RPL_WHOISHOST), - target_p->name, target_p->orighost, - show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255"); - SetDynSpoof(target_p); - } - else if(ConfigFileEntry.use_whois_actually && show_ip(source_p, target_p)) - sendto_one_numeric(source_p, RPL_WHOISACTUALLY, - form_str(RPL_WHOISACTUALLY), - target_p->name, target_p->sockhost); + if(MyClient(target_p)) { + if (IsDynSpoof(target_p) && (IsOper(source_p) || source_p == target_p)) { + /* trick here: show a nonoper their own IP if + * dynamic spoofed but not if auth{} spoofed + * -- jilles */ + ClearDynSpoof(target_p); + sendto_one_numeric(source_p, RPL_WHOISHOST, + form_str(RPL_WHOISHOST), + target_p->name, target_p->orighost, + show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255"); + SetDynSpoof(target_p); + } else if(ConfigFileEntry.use_whois_actually && show_ip(source_p, target_p)) + sendto_one_numeric(source_p, RPL_WHOISACTUALLY, + form_str(RPL_WHOISACTUALLY), + target_p->name, target_p->sockhost); - sendto_one_numeric(source_p, RPL_WHOISIDLE, form_str(RPL_WHOISIDLE), - target_p->name, - rb_current_time() - target_p->localClient->last, - target_p->localClient->firsttime); - } - else - { - if (IsDynSpoof(target_p) && (IsOper(source_p) || source_p == target_p)) - { - ClearDynSpoof(target_p); - sendto_one_numeric(source_p, RPL_WHOISHOST, - form_str(RPL_WHOISHOST), - target_p->name, target_p->orighost, - show_ip(source_p, target_p) && !EmptyString(target_p->sockhost) && strcmp(target_p->sockhost, "0")? target_p->sockhost : "255.255.255.255"); - SetDynSpoof(target_p); - } - else if(ConfigFileEntry.use_whois_actually && show_ip(source_p, target_p) && - !EmptyString(target_p->sockhost) && strcmp(target_p->sockhost, "0")) - { - sendto_one_numeric(source_p, RPL_WHOISACTUALLY, - form_str(RPL_WHOISACTUALLY), - target_p->name, target_p->sockhost); - - } - } + sendto_one_numeric(source_p, RPL_WHOISIDLE, form_str(RPL_WHOISIDLE), + target_p->name, + rb_current_time() - target_p->localClient->last, + target_p->localClient->firsttime); + } else { + if (IsDynSpoof(target_p) && (IsOper(source_p) || source_p == target_p)) { + ClearDynSpoof(target_p); + sendto_one_numeric(source_p, RPL_WHOISHOST, + form_str(RPL_WHOISHOST), + target_p->name, target_p->orighost, + show_ip(source_p, target_p) && !EmptyString(target_p->sockhost) && strcmp(target_p->sockhost, "0")? target_p->sockhost : "255.255.255.255"); + SetDynSpoof(target_p); + } else if(ConfigFileEntry.use_whois_actually && show_ip(source_p, target_p) && + !EmptyString(target_p->sockhost) && strcmp(target_p->sockhost, "0")) { + sendto_one_numeric(source_p, RPL_WHOISACTUALLY, + form_str(RPL_WHOISACTUALLY), + target_p->name, target_p->sockhost); - hdata.client = source_p; - hdata.target = target_p; + } + } - /* doing_whois_hook must only be called for local clients, - * doing_whois_global_hook must only be called for local targets - */ - /* it is important that these are called *before* RPL_ENDOFWHOIS is - * sent, services compatibility code depends on it. --anfl - */ - if(MyClient(source_p)) - call_hook(doing_whois_hook, &hdata); - else - call_hook(doing_whois_global_hook, &hdata); + hdata.client = source_p; + hdata.target = target_p; - return; + /* doing_whois_hook must only be called for local clients, + * doing_whois_global_hook must only be called for local targets + */ + /* it is important that these are called *before* RPL_ENDOFWHOIS is + * sent, services compatibility code depends on it. --anfl + */ + if(MyClient(source_p)) + call_hook(doing_whois_hook, &hdata); + else + call_hook(doing_whois_global_hook, &hdata); + + return; } diff --git a/modules/m_whowas.c b/modules/m_whowas.c index 272c12b..e04637b 100644 --- a/modules/m_whowas.c +++ b/modules/m_whowas.c @@ -43,8 +43,8 @@ static int m_whowas(struct Client *, struct Client *, int, const char **); struct Message whowas_msgtab = { - "WHOWAS", 0, 0, 0, MFLG_SLOW, - {mg_unreg, {m_whowas, 2}, mg_ignore, mg_ignore, mg_ignore, {m_whowas, 2}} + "WHOWAS", 0, 0, 0, MFLG_SLOW, + {mg_unreg, {m_whowas, 2}, mg_ignore, mg_ignore, mg_ignore, {m_whowas, 2}} }; mapi_clist_av1 whowas_clist[] = { &whowas_msgtab, NULL }; @@ -56,84 +56,79 @@ DECLARE_MODULE_AV1(whowas, NULL, NULL, whowas_clist, NULL, NULL, "$Revision: 171 */ static int m_whowas(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) -{ - struct Whowas *temp; - int cur = 0; - int max = -1, found = 0; - char *p; - const char *nick; - char tbuf[26]; +{ + struct Whowas *temp; + int cur = 0; + int max = -1, found = 0; + char *p; + const char *nick; + char tbuf[26]; - static time_t last_used = 0L; + static time_t last_used = 0L; - if(!IsOper(source_p)) - { - if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "WHOWAS"); - sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), - me.name, source_p->name, parv[1]); - return 0; - } - else - last_used = rb_current_time(); - } + if(!IsOper(source_p)) { + if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) { + sendto_one(source_p, form_str(RPL_LOAD2HI), + me.name, source_p->name, "WHOWAS"); + sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), + me.name, source_p->name, parv[1]); + return 0; + } else + last_used = rb_current_time(); + } - if(parc > 2) - max = atoi(parv[2]); + if(parc > 2) + max = atoi(parv[2]); #if 0 - if(parc > 3) - if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)) - return 0; + if(parc > 3) + if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)) + return 0; #endif - if((p = strchr(parv[1], ','))) - *p = '\0'; + if((p = strchr(parv[1], ','))) + *p = '\0'; - nick = parv[1]; + nick = parv[1]; - temp = WHOWASHASH[hash_whowas_name(nick)]; - found = 0; - for (; temp; temp = temp->next) - { - if(!irccmp(nick, temp->name)) - { - sendto_one(source_p, form_str(RPL_WHOWASUSER), - me.name, source_p->name, temp->name, - temp->username, temp->hostname, temp->realname); - if (MyOper(source_p) && !EmptyString(temp->sockhost)) + temp = WHOWASHASH[hash_whowas_name(nick)]; + found = 0; + for (; temp; temp = temp->next) { + if(!irccmp(nick, temp->name)) { + sendto_one(source_p, form_str(RPL_WHOWASUSER), + me.name, source_p->name, temp->name, + temp->username, temp->hostname, temp->realname); + if (MyOper(source_p) && !EmptyString(temp->sockhost)) #if 0 - sendto_one(source_p, form_str(RPL_WHOWASREAL), - me.name, source_p->name, temp->name, - "", temp->sockhost); + sendto_one(source_p, form_str(RPL_WHOWASREAL), + me.name, source_p->name, temp->name, + "", temp->sockhost); #else - sendto_one_numeric(source_p, RPL_WHOISACTUALLY, - form_str(RPL_WHOISACTUALLY), - temp->name, temp->sockhost); + sendto_one_numeric(source_p, RPL_WHOISACTUALLY, + form_str(RPL_WHOISACTUALLY), + temp->name, temp->sockhost); #endif - if (!EmptyString(temp->suser)) - sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN, - "%s %s :was logged in as", - temp->name, temp->suser); - sendto_one_numeric(source_p, RPL_WHOISSERVER, - form_str(RPL_WHOISSERVER), - temp->name, temp->servername, - rb_ctime(temp->logoff, tbuf, sizeof(tbuf))); - cur++; - found++; - } - if(max > 0 && cur >= max) - break; - } + if (!EmptyString(temp->suser)) + sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN, + "%s %s :was logged in as", + temp->name, temp->suser); + sendto_one_numeric(source_p, RPL_WHOISSERVER, + form_str(RPL_WHOISSERVER), + temp->name, temp->servername, + rb_ctime(temp->logoff, tbuf, sizeof(tbuf))); + cur++; + found++; + } + if(max > 0 && cur >= max) + break; + } - if(!found) - sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), - me.name, source_p->name, nick); + if(!found) + sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), + me.name, source_p->name, nick); - sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), - me.name, source_p->name, parv[1]); - return 0; + sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), + me.name, source_p->name, parv[1]); + return 0; } diff --git a/modules/m_xline.c b/modules/m_xline.c index d1975ec..7d39310 100644 --- a/modules/m_xline.c +++ b/modules/m_xline.c @@ -1,5 +1,5 @@ /* modules/m_xline.c - * + * * Copyright (C) 2002-2003 Lee Hardy * Copyright (C) 2002-2005 ircd-ratbox development team * @@ -57,20 +57,20 @@ static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]); + const char *parv[]); static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]); + const char *parv[]); static int me_unxline(struct Client *client_p, struct Client *source_p, int parc, - const char *parv[]); + const char *parv[]); struct Message xline_msgtab = { - "XLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}} + "XLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}} }; struct Message unxline_msgtab = { - "UNXLINE", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}} + "UNXLINE", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}} }; mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL }; @@ -79,18 +79,18 @@ DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision$"); static int valid_xline(struct Client *, const char *, const char *); static void apply_xline(struct Client *client_p, const char *name, - const char *reason, int temp_time, int propagated); + const char *reason, int temp_time, int propagated); static void propagate_xline(struct Client *source_p, const char *target, - int temp_time, const char *name, const char *type, const char *reason); + int temp_time, const char *name, const char *type, const char *reason); static void cluster_xline(struct Client *source_p, int temp_time, - const char *name, const char *reason); + const char *name, const char *reason); static void handle_remote_xline(struct Client *source_p, int temp_time, - const char *name, const char *reason); + const char *name, const char *reason); static void handle_remote_unxline(struct Client *source_p, const char *name); static void remove_xline(struct Client *source_p, const char *name, - int propagated); + int propagated); /* m_xline() @@ -102,84 +102,76 @@ static void remove_xline(struct Client *source_p, const char *name, static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - struct ConfItem *aconf; - const char *name; - const char *reason; - const char *target_server = NULL; - int temp_time; - int loc = 1; - int propagated = ConfigFileEntry.use_propagated_bans; + struct ConfItem *aconf; + const char *name; + const char *reason; + const char *target_server = NULL; + int temp_time; + int loc = 1; + int propagated = ConfigFileEntry.use_propagated_bans; - if(!IsOperXline(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); - return 0; - } + if(!IsOperXline(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); + return 0; + } - if((temp_time = valid_temp_time(parv[loc])) >= 0) - loc++; - /* we just set temp_time to -1! */ - else - temp_time = 0; + if((temp_time = valid_temp_time(parv[loc])) >= 0) + loc++; + /* we just set temp_time to -1! */ + else + temp_time = 0; - name = parv[loc]; - loc++; + name = parv[loc]; + loc++; - /* XLINE ON : */ - if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + /* XLINE ON : */ + if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - target_server = parv[loc + 1]; - loc += 2; - } + target_server = parv[loc + 1]; + loc += 2; + } - if(parc <= loc || EmptyString(parv[loc])) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - me.name, source_p->name, "XLINE"); - return 0; - } + if(parc <= loc || EmptyString(parv[loc])) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + me.name, source_p->name, "XLINE"); + return 0; + } - reason = parv[loc]; + reason = parv[loc]; - if(target_server != NULL) - { - propagate_xline(source_p, target_server, temp_time, name, "2", reason); + if(target_server != NULL) { + propagate_xline(source_p, target_server, temp_time, name, "2", reason); - if(!match(target_server, me.name)) - return 0; + if(!match(target_server, me.name)) + return 0; - /* Set as local-only. */ - propagated = 0; - } - else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) - cluster_xline(source_p, temp_time, name, reason); + /* Set as local-only. */ + propagated = 0; + } else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) + cluster_xline(source_p, temp_time, name, reason); - if((aconf = find_xline_mask(name)) != NULL) - { - sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", - me.name, source_p->name, name, aconf->host, aconf->passwd); - return 0; - } + if((aconf = find_xline_mask(name)) != NULL) { + sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", + me.name, source_p->name, name, aconf->host, aconf->passwd); + return 0; + } - if(!valid_xline(source_p, name, reason)) - return 0; + if(!valid_xline(source_p, name, reason)) + return 0; - if(propagated && temp_time == 0) - { - sendto_one_notice(source_p, ":Cannot set a permanent global ban"); - return 0; - } + if(propagated && temp_time == 0) { + sendto_one_notice(source_p, ":Cannot set a permanent global ban"); + return 0; + } - apply_xline(source_p, name, reason, temp_time, propagated); + apply_xline(source_p, name, reason, temp_time, propagated); - return 0; + return 0; } /* ms_xline() @@ -189,55 +181,54 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* parv[0] parv[1] parv[2] parv[3] parv[4] - * oper target serv xline type reason - */ - propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]); + /* parv[0] parv[1] parv[2] parv[3] parv[4] + * oper target serv xline type reason + */ + propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]); - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - /* destined for me? */ - if(!match(parv[1], me.name)) - return 0; + /* destined for me? */ + if(!match(parv[1], me.name)) + return 0; - handle_remote_xline(source_p, 0, parv[2], parv[4]); - return 0; + handle_remote_xline(source_p, 0, parv[2], parv[4]); + return 0; } static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* time name type :reason */ - if(!IsPerson(source_p)) - return 0; + /* time name type :reason */ + if(!IsPerson(source_p)) + return 0; - handle_remote_xline(source_p, atoi(parv[1]), parv[2], parv[4]); - return 0; + handle_remote_xline(source_p, atoi(parv[1]), parv[2], parv[4]); + return 0; } static void handle_remote_xline(struct Client *source_p, int temp_time, const char *name, const char *reason) { - struct ConfItem *aconf; + struct ConfItem *aconf; - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, - (temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE)) - return; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, + (temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE)) + return; - if(!valid_xline(source_p, name, reason)) - return; + if(!valid_xline(source_p, name, reason)) + return; - /* already xlined */ - if((aconf = find_xline_mask(name)) != NULL) - { - sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->host, - aconf->passwd); - return; - } + /* already xlined */ + if((aconf = find_xline_mask(name)) != NULL) { + sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->host, + aconf->passwd); + return; + } - apply_xline(source_p, name, reason, temp_time, 0); + apply_xline(source_p, name, reason, temp_time, 0); } /* valid_xline() @@ -249,150 +240,136 @@ handle_remote_xline(struct Client *source_p, int temp_time, const char *name, co static int valid_xline(struct Client *source_p, const char *gecos, const char *reason) { - if(EmptyString(reason)) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), - get_id(&me, source_p), get_id(source_p, source_p), "XLINE"); - return 0; - } + if(EmptyString(reason)) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), + get_id(&me, source_p), get_id(source_p, source_p), "XLINE"); + return 0; + } - if(strchr(reason, ':') != NULL) - { - sendto_one_notice(source_p, ":Invalid character ':' in comment"); - return 0; - } + if(strchr(reason, ':') != NULL) { + sendto_one_notice(source_p, ":Invalid character ':' in comment"); + return 0; + } - if(strchr(reason, '"')) - { - sendto_one_notice(source_p, ":Invalid character '\"' in comment"); - return 0; - } + if(strchr(reason, '"')) { + sendto_one_notice(source_p, ":Invalid character '\"' in comment"); + return 0; + } - if(!valid_wild_card_simple(gecos)) - { - sendto_one_notice(source_p, - ":Please include at least %d non-wildcard " - "characters with the xline", - ConfigFileEntry.min_nonwildcard_simple); - return 0; - } + if(!valid_wild_card_simple(gecos)) { + sendto_one_notice(source_p, + ":Please include at least %d non-wildcard " + "characters with the xline", + ConfigFileEntry.min_nonwildcard_simple); + return 0; + } - return 1; + return 1; } void apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time, int propagated) { - struct ConfItem *aconf; + struct ConfItem *aconf; - aconf = make_conf(); - aconf->status = CONF_XLINE; - aconf->created = rb_current_time(); - aconf->host = rb_strdup(name); - aconf->passwd = rb_strdup(reason); - collapse(aconf->host); + aconf = make_conf(); + aconf->status = CONF_XLINE; + aconf->created = rb_current_time(); + aconf->host = rb_strdup(name); + aconf->passwd = rb_strdup(reason); + collapse(aconf->host); - aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf->info.oper = operhash_add(get_oper_name(source_p)); - if(propagated) - { - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - aconf->hold = rb_current_time() + temp_time; - aconf->lifetime = aconf->hold; + if(propagated) { + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + aconf->hold = rb_current_time() + temp_time; + aconf->lifetime = aconf->hold; - replace_old_ban(aconf); - rb_dlinkAddAlloc(aconf, &prop_bans); + replace_old_ban(aconf); + rb_dlinkAddAlloc(aconf, &prop_bans); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added global %d min. X-Line for [%s] [%s]", - get_oper_name(source_p), temp_time / 60, - aconf->host, reason); - ilog(L_KLINE, "X %s %d %s %s", - get_oper_name(source_p), temp_time / 60, name, reason); - sendto_one_notice(source_p, ":Added global %d min. X-Line [%s]", - temp_time / 60, aconf->host); - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN X * %s %lu %d %d * :%s", - source_p->id, aconf->host, - (unsigned long)aconf->created, - (int)(aconf->hold - aconf->created), - (int)(aconf->lifetime - aconf->created), - reason); - } - else if(temp_time > 0) - { - aconf->hold = rb_current_time() + temp_time; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added global %d min. X-Line for [%s] [%s]", + get_oper_name(source_p), temp_time / 60, + aconf->host, reason); + ilog(L_KLINE, "X %s %d %s %s", + get_oper_name(source_p), temp_time / 60, name, reason); + sendto_one_notice(source_p, ":Added global %d min. X-Line [%s]", + temp_time / 60, aconf->host); + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN X * %s %lu %d %d * :%s", + source_p->id, aconf->host, + (unsigned long)aconf->created, + (int)(aconf->hold - aconf->created), + (int)(aconf->lifetime - aconf->created), + reason); + } else if(temp_time > 0) { + aconf->hold = rb_current_time() + temp_time; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. X-Line for [%s] [%s]", - get_oper_name(source_p), temp_time / 60, - aconf->host, reason); - ilog(L_KLINE, "X %s %d %s %s", - get_oper_name(source_p), temp_time / 60, name, reason); - sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]", - temp_time / 60, aconf->host); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]", - get_oper_name(source_p), aconf->host, aconf->passwd); - sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]", - aconf->host, aconf->passwd); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added temporary %d min. X-Line for [%s] [%s]", + get_oper_name(source_p), temp_time / 60, + aconf->host, reason); + ilog(L_KLINE, "X %s %d %s %s", + get_oper_name(source_p), temp_time / 60, name, reason); + sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]", + temp_time / 60, aconf->host); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]", + get_oper_name(source_p), aconf->host, aconf->passwd); + sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]", + aconf->host, aconf->passwd); - bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); - ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, aconf->passwd); - } + bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); + ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, aconf->passwd); + } - rb_dlinkAddAlloc(aconf, &xline_conf_list); - check_xlines(); + rb_dlinkAddAlloc(aconf, &xline_conf_list); + check_xlines(); } static void propagate_xline(struct Client *source_p, const char *target, - int temp_time, const char *name, const char *type, const char *reason) + int temp_time, const char *name, const char *type, const char *reason) { - if(!temp_time) - { - sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS, - "XLINE %s %s %s :%s", target, name, type, reason); - sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER, - "ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason); - } - else - sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS, - "ENCAP %s XLINE %d %s %s :%s", - target, temp_time, name, type, reason); + if(!temp_time) { + sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS, + "XLINE %s %s %s :%s", target, name, type, reason); + sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER, + "ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason); + } else + sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS, + "ENCAP %s XLINE %d %s %s :%s", + target, temp_time, name, type, reason); } static void cluster_xline(struct Client *source_p, int temp_time, const char *name, const char *reason) { - struct remote_conf *shared_p; - rb_dlink_node *ptr; + struct remote_conf *shared_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, cluster_conf_list.head) - { - shared_p = ptr->data; + RB_DLINK_FOREACH(ptr, cluster_conf_list.head) { + shared_p = ptr->data; - /* old protocol cant handle temps, and we dont really want - * to convert them to perm.. --fl - */ - if(!temp_time) - { - if(!(shared_p->flags & SHARED_PXLINE)) - continue; + /* old protocol cant handle temps, and we dont really want + * to convert them to perm.. --fl + */ + if(!temp_time) { + if(!(shared_p->flags & SHARED_PXLINE)) + continue; - sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS, - "XLINE %s %s 2 :%s", shared_p->server, name, reason); - sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER, - "ENCAP %s XLINE 0 %s 2 :%s", - shared_p->server, name, reason); - } - else if(shared_p->flags & SHARED_TXLINE) - sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS, - "ENCAP %s XLINE %d %s 2 :%s", - shared_p->server, temp_time, name, reason); - } + sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS, + "XLINE %s %s 2 :%s", shared_p->server, name, reason); + sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER, + "ENCAP %s XLINE 0 %s 2 :%s", + shared_p->server, name, reason); + } else if(shared_p->flags & SHARED_TXLINE) + sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS, + "ENCAP %s XLINE %d %s 2 :%s", + shared_p->server, temp_time, name, reason); + } } /* mo_unxline() @@ -402,35 +379,32 @@ cluster_xline(struct Client *source_p, int temp_time, const char *name, const ch static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int propagated = 1; + int propagated = 1; - if(!IsOperXline(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); - return 0; - } + if(!IsOperXline(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); + return 0; + } - if(parc == 4 && !(irccmp(parv[2], "ON"))) - { - if(!IsOperRemoteBan(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "remoteban"); - return 0; - } + if(parc == 4 && !(irccmp(parv[2], "ON"))) { + if(!IsOperRemoteBan(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "remoteban"); + return 0; + } - propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]); + propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]); - if(match(parv[3], me.name) == 0) - return 0; + if(match(parv[3], me.name) == 0) + return 0; - propagated = 0; - } - /* cluster{} moved to remove_xline */ + propagated = 0; + } + /* cluster{} moved to remove_xline */ - remove_xline(source_p, parv[1], propagated); + remove_xline(source_p, parv[1], propagated); - return 0; + return 0; } /* ms_unxline() @@ -440,121 +414,113 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* parv[0] parv[1] parv[2] - * oper target server gecos - */ - propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]); + /* parv[0] parv[1] parv[2] + * oper target server gecos + */ + propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]); - if(!match(parv[1], me.name)) - return 0; + if(!match(parv[1], me.name)) + return 0; - if(!IsPerson(source_p)) - return 0; + if(!IsPerson(source_p)) + return 0; - handle_remote_unxline(source_p, parv[2]); - return 0; + handle_remote_unxline(source_p, parv[2]); + return 0; } static int me_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* name */ - if(!IsPerson(source_p)) - return 0; + /* name */ + if(!IsPerson(source_p)) + return 0; - handle_remote_unxline(source_p, parv[1]); - return 0; + handle_remote_unxline(source_p, parv[1]); + return 0; } static void handle_remote_unxline(struct Client *source_p, const char *name) { - if(!find_shared_conf(source_p->username, source_p->host, - source_p->servptr->name, SHARED_UNXLINE)) - return; + if(!find_shared_conf(source_p->username, source_p->host, + source_p->servptr->name, SHARED_UNXLINE)) + return; - remove_xline(source_p, name, 0); + remove_xline(source_p, name, 0); - return; + return; } static void remove_xline(struct Client *source_p, const char *name, int propagated) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, xline_conf_list.head) { + aconf = ptr->data; - if(!irccmp(aconf->host, name)) - { - if(aconf->lifetime) - { - if(!propagated) - { - sendto_one_notice(source_p, ":Cannot remove global X-Line %s on specific servers", name); - return; - } - ptr = rb_dlinkFind(aconf, &prop_bans); - if(ptr == NULL) - return; - sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the global X-Line for: [%s]", - get_oper_name(source_p), name); - ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); - if(aconf->created < rb_current_time()) - aconf->created = rb_current_time(); - else - aconf->created++; - aconf->hold = aconf->created; - operhash_delete(aconf->info.oper); - aconf->info.oper = operhash_add(get_oper_name(source_p)); - aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; - sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, - ":%s BAN X * %s %lu %d %d * :*", - source_p->id, aconf->host, - (unsigned long)aconf->created, - 0, - (int)(aconf->lifetime - aconf->created)); - remove_reject_mask(aconf->host, NULL); - deactivate_conf(aconf, ptr); - return; - } - else if(propagated && rb_dlink_list_length(&cluster_conf_list)) - cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); - if(!aconf->hold) - { - bandb_del(BANDB_XLINE, aconf->host, NULL); + if(!irccmp(aconf->host, name)) { + if(aconf->lifetime) { + if(!propagated) { + sendto_one_notice(source_p, ":Cannot remove global X-Line %s on specific servers", name); + return; + } + ptr = rb_dlinkFind(aconf, &prop_bans); + if(ptr == NULL) + return; + sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the global X-Line for: [%s]", + get_oper_name(source_p), name); + ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); + if(aconf->created < rb_current_time()) + aconf->created = rb_current_time(); + else + aconf->created++; + aconf->hold = aconf->created; + operhash_delete(aconf->info.oper); + aconf->info.oper = operhash_add(get_oper_name(source_p)); + aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; + sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, + ":%s BAN X * %s %lu %d %d * :*", + source_p->id, aconf->host, + (unsigned long)aconf->created, + 0, + (int)(aconf->lifetime - aconf->created)); + remove_reject_mask(aconf->host, NULL); + deactivate_conf(aconf, ptr); + return; + } else if(propagated && rb_dlink_list_length(&cluster_conf_list)) + cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); + if(!aconf->hold) { + bandb_del(BANDB_XLINE, aconf->host, NULL); - sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the X-Line for: [%s]", - get_oper_name(source_p), aconf->host); - ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host); - } - else - { - sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the temporary X-Line for: [%s]", - get_oper_name(source_p), name); - ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); - } + sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the X-Line for: [%s]", + get_oper_name(source_p), aconf->host); + ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host); + } else { + sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has removed the temporary X-Line for: [%s]", + get_oper_name(source_p), name); + ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); + } - remove_reject_mask(aconf->host, NULL); - free_conf(aconf); - rb_dlinkDestroy(ptr, &xline_conf_list); - return; - } - } + remove_reject_mask(aconf->host, NULL); + free_conf(aconf); + rb_dlinkDestroy(ptr, &xline_conf_list); + return; + } + } - if(propagated && rb_dlink_list_length(&cluster_conf_list)) - cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); + if(propagated && rb_dlink_list_length(&cluster_conf_list)) + cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); - sendto_one_notice(source_p, ":No X-Line for %s", name); + sendto_one_notice(source_p, ":No X-Line for %s", name); - return; + return; } diff --git a/modules/sno_routing.c b/modules/sno_routing.c index 0698395..49c1398 100644 --- a/modules/sno_routing.c +++ b/modules/sno_routing.c @@ -41,9 +41,9 @@ static void h_nn_server_eob(struct Client *); static void h_nn_client_exit(hook_data_client_exit *); mapi_hfn_list_av1 nn_hfnlist[] = { - { "server_eob", (hookfn) h_nn_server_eob }, - { "client_exit", (hookfn) h_nn_client_exit }, - { NULL, NULL } + { "server_eob", (hookfn) h_nn_server_eob }, + { "client_exit", (hookfn) h_nn_client_exit }, + { NULL, NULL } }; DECLARE_MODULE_AV1(networknotice, NULL, NULL, NULL, NULL, nn_hfnlist, "$Revision: 1172 $"); @@ -60,59 +60,56 @@ DECLARE_MODULE_AV1(networknotice, NULL, NULL, NULL, NULL, nn_hfnlist, "$Revision static void count_mark_downlinks(struct Client *server_p, int *pservcount, int *pusercount) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - SetFloodDone(server_p); - (*pservcount)++; - *pusercount += rb_dlink_list_length(&server_p->serv->users); - RB_DLINK_FOREACH(ptr, server_p->serv->servers.head) - { - count_mark_downlinks(ptr->data, pservcount, pusercount); - } + SetFloodDone(server_p); + (*pservcount)++; + *pusercount += rb_dlink_list_length(&server_p->serv->users); + RB_DLINK_FOREACH(ptr, server_p->serv->servers.head) { + count_mark_downlinks(ptr->data, pservcount, pusercount); + } } static void h_nn_server_eob(struct Client *source_p) { - int s = 0, u = 0; + int s = 0, u = 0; - if (IsFloodDone(source_p)) - return; - count_mark_downlinks(source_p, &s, &u); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Netjoin %s <-> %s (%dS %dC)", - source_p->servptr ? source_p->servptr->name : "?", - source_p->name, s, u); + if (IsFloodDone(source_p)) + return; + count_mark_downlinks(source_p, &s, &u); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Netjoin %s <-> %s (%dS %dC)", + source_p->servptr ? source_p->servptr->name : "?", + source_p->name, s, u); } static void h_nn_client_exit(hook_data_client_exit *hdata) { - struct Client *source_p; - int s = 0, u = 0; - char *fromnick; + struct Client *source_p; + int s = 0, u = 0; + char *fromnick; - source_p = hdata->target; - fromnick = IsClient(hdata->from) ? hdata->from->name : NULL; + source_p = hdata->target; + fromnick = IsClient(hdata->from) ? hdata->from->name : NULL; - if (!IsServer(source_p)) - return; - if (HasSentEob(source_p)) - { - count_mark_downlinks(source_p, &s, &u); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Netsplit %s <-> %s (%dS %dC) (%s%s%s%s)", - source_p->servptr ? source_p->servptr->name : "?", - source_p->name, s, u, - fromnick ? "by " : "", - fromnick ? fromnick : "", - fromnick ? ": " : "", - hdata->comment); - } - else - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Netsplit %s <-> %s (during burst) (%s%s%s%s)", - source_p->servptr ? source_p->servptr->name : "?", - source_p->name, - fromnick ? "by " : "", - fromnick ? fromnick : "", - fromnick ? ": " : "", - hdata->comment); + if (!IsServer(source_p)) + return; + if (HasSentEob(source_p)) { + count_mark_downlinks(source_p, &s, &u); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Netsplit %s <-> %s (%dS %dC) (%s%s%s%s)", + source_p->servptr ? source_p->servptr->name : "?", + source_p->name, s, u, + fromnick ? "by " : "", + fromnick ? fromnick : "", + fromnick ? ": " : "", + hdata->comment); + } else + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Netsplit %s <-> %s (during burst) (%s%s%s%s)", + source_p->servptr ? source_p->servptr->name : "?", + source_p->name, + fromnick ? "by " : "", + fromnick ? fromnick : "", + fromnick ? ": " : "", + hdata->comment); } diff --git a/src/bandbi.c b/src/bandbi.c index e1e3917..077a477 100644 --- a/src/bandbi.c +++ b/src/bandbi.c @@ -49,7 +49,7 @@ #include "operhash.h" static char bandb_add_letter[LAST_BANDB_TYPE] = { - 'K', 'D', 'X', 'R' + 'K', 'D', 'X', 'R' }; rb_dlink_list bandb_pending; @@ -64,391 +64,373 @@ static char *bandb_path; void init_bandb(void) { - if(start_bandb()) - { - ilog(L_MAIN, "Unable to start bandb helper: %s", strerror(errno)); - exit(0); - } + if(start_bandb()) { + ilog(L_MAIN, "Unable to start bandb helper: %s", strerror(errno)); + exit(0); + } } static int start_bandb(void) { - char fullpath[PATH_MAX + 1]; + char fullpath[PATH_MAX + 1]; #ifdef _WIN32 - const char *suffix = ".exe"; + const char *suffix = ".exe"; #else - const char *suffix = ""; + const char *suffix = ""; #endif - rb_setenv("BANDB_DBPATH", PKGLOCALSTATEDIR "/ban.db", 1); - if(bandb_path == NULL) - { - rb_snprintf(fullpath, sizeof(fullpath), "%s/bandb%s", PKGLIBEXECDIR, suffix); + rb_setenv("BANDB_DBPATH", PKGLOCALSTATEDIR "/ban.db", 1); + if(bandb_path == NULL) { + rb_snprintf(fullpath, sizeof(fullpath), "%s/bandb%s", PKGLIBEXECDIR, suffix); - if(access(fullpath, X_OK) == -1) - { - rb_snprintf(fullpath, sizeof(fullpath), "%s/bin/bandb%s", - ConfigFileEntry.dpath, suffix); + if(access(fullpath, X_OK) == -1) { + rb_snprintf(fullpath, sizeof(fullpath), "%s/bin/bandb%s", + ConfigFileEntry.dpath, suffix); - if(access(fullpath, X_OK) == -1) - { - ilog(L_MAIN, - "Unable to execute bandb%s in %s or %s/bin", - suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath); - return 0; - } - } - bandb_path = rb_strdup(fullpath); - } + if(access(fullpath, X_OK) == -1) { + ilog(L_MAIN, + "Unable to execute bandb%s in %s or %s/bin", + suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath); + return 0; + } + } + bandb_path = rb_strdup(fullpath); + } - bandb_helper = rb_helper_start("bandb", bandb_path, bandb_parse, bandb_restart_cb); + bandb_helper = rb_helper_start("bandb", bandb_path, bandb_parse, bandb_restart_cb); - if(bandb_helper == NULL) - { - ilog(L_MAIN, "Unable to start bandb: %s", strerror(errno)); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Unable to start bandb: %s", - strerror(errno)); - return 1; - } + if(bandb_helper == NULL) { + ilog(L_MAIN, "Unable to start bandb: %s", strerror(errno)); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Unable to start bandb: %s", + strerror(errno)); + return 1; + } - rb_helper_run(bandb_helper); - return 0; + rb_helper_run(bandb_helper); + return 0; } void bandb_add(bandb_type type, struct Client *source_p, const char *mask1, - const char *mask2, const char *reason, const char *oper_reason, int perm) + const char *mask2, const char *reason, const char *oper_reason, int perm) { - if(bandb_helper == NULL) - return; + if(bandb_helper == NULL) + return; - static char buf[BUFSIZE]; + static char buf[BUFSIZE]; - rb_snprintf(buf, sizeof(buf), "%c %s ", bandb_add_letter[type], mask1); + rb_snprintf(buf, sizeof(buf), "%c %s ", bandb_add_letter[type], mask1); - if(!EmptyString(mask2)) - rb_snprintf_append(buf, sizeof(buf), "%s ", mask2); + if(!EmptyString(mask2)) + rb_snprintf_append(buf, sizeof(buf), "%s ", mask2); - rb_snprintf_append(buf, sizeof(buf), "%s %ld %d :%s", - get_oper_name(source_p), (long int)rb_current_time(), perm, reason); + rb_snprintf_append(buf, sizeof(buf), "%s %ld %d :%s", + get_oper_name(source_p), (long int)rb_current_time(), perm, reason); - if(!EmptyString(oper_reason)) - rb_snprintf_append(buf, sizeof(buf), "|%s", oper_reason); + if(!EmptyString(oper_reason)) + rb_snprintf_append(buf, sizeof(buf), "|%s", oper_reason); - rb_helper_write(bandb_helper, "%s", buf); + rb_helper_write(bandb_helper, "%s", buf); } static char bandb_del_letter[LAST_BANDB_TYPE] = { - 'k', 'd', 'x', 'r' + 'k', 'd', 'x', 'r' }; void bandb_del(bandb_type type, const char *mask1, const char *mask2) { - if(bandb_helper == NULL) - return; + if(bandb_helper == NULL) + return; - static char buf[BUFSIZE]; + static char buf[BUFSIZE]; - buf[0] = '\0'; + buf[0] = '\0'; - rb_snprintf_append(buf, sizeof(buf), "%c %s", bandb_del_letter[type], mask1); + rb_snprintf_append(buf, sizeof(buf), "%c %s", bandb_del_letter[type], mask1); - if(!EmptyString(mask2)) - rb_snprintf_append(buf, sizeof(buf), " %s", mask2); + if(!EmptyString(mask2)) + rb_snprintf_append(buf, sizeof(buf), " %s", mask2); - rb_helper_write(bandb_helper, "%s", buf); + rb_helper_write(bandb_helper, "%s", buf); } static void bandb_handle_ban(char *parv[], int parc) { - struct ConfItem *aconf; - char *p; - int para = 1; + struct ConfItem *aconf; + char *p; + int para = 1; - aconf = make_conf(); - aconf->port = 0; + aconf = make_conf(); + aconf->port = 0; - if(parv[0][0] == 'K') - aconf->user = rb_strdup(parv[para++]); + if(parv[0][0] == 'K') + aconf->user = rb_strdup(parv[para++]); - aconf->host = rb_strdup(parv[para++]); - aconf->info.oper = operhash_add(parv[para++]); + aconf->host = rb_strdup(parv[para++]); + aconf->info.oper = operhash_add(parv[para++]); - switch (parv[0][0]) - { - case 'K': - aconf->status = CONF_KILL; - break; + switch (parv[0][0]) { + case 'K': + aconf->status = CONF_KILL; + break; - case 'D': - aconf->status = CONF_DLINE; - break; + case 'D': + aconf->status = CONF_DLINE; + break; - case 'X': - aconf->status = CONF_XLINE; - break; + case 'X': + aconf->status = CONF_XLINE; + break; - case 'R': - if(IsChannelName(aconf->host)) - aconf->status = CONF_RESV_CHANNEL; - else - aconf->status = CONF_RESV_NICK; + case 'R': + if(IsChannelName(aconf->host)) + aconf->status = CONF_RESV_CHANNEL; + else + aconf->status = CONF_RESV_NICK; - break; - } + break; + } - if((p = strchr(parv[para], '|'))) - { - *p++ = '\0'; - aconf->spasswd = rb_strdup(p); - } + if((p = strchr(parv[para], '|'))) { + *p++ = '\0'; + aconf->spasswd = rb_strdup(p); + } - aconf->passwd = rb_strdup(parv[para]); + aconf->passwd = rb_strdup(parv[para]); - rb_dlinkAddAlloc(aconf, &bandb_pending); + rb_dlinkAddAlloc(aconf, &bandb_pending); } static int bandb_check_kline(struct ConfItem *aconf) { - struct rb_sockaddr_storage daddr; - struct ConfItem *kconf = NULL; - int aftype; - const char *p; + struct rb_sockaddr_storage daddr; + struct ConfItem *kconf = NULL; + int aftype; + const char *p; - aftype = parse_netmask(aconf->host, (struct sockaddr *)&daddr, NULL); + aftype = parse_netmask(aconf->host, (struct sockaddr *)&daddr, NULL); - if(aftype != HM_HOST) - { + if(aftype != HM_HOST) { #ifdef RB_IPV6 - if(aftype == HM_IPV6) - aftype = AF_INET6; - else + if(aftype == HM_IPV6) + aftype = AF_INET6; + else #endif - aftype = AF_INET; + aftype = AF_INET; - kconf = find_conf_by_address(aconf->host, NULL, NULL, (struct sockaddr *)&daddr, - CONF_KILL, aftype, aconf->user, NULL); - } - else - kconf = find_conf_by_address(aconf->host, NULL, NULL, NULL, CONF_KILL, 0, aconf->user, NULL); + kconf = find_conf_by_address(aconf->host, NULL, NULL, (struct sockaddr *)&daddr, + CONF_KILL, aftype, aconf->user, NULL); + } else + kconf = find_conf_by_address(aconf->host, NULL, NULL, NULL, CONF_KILL, 0, aconf->user, NULL); - if(kconf && ((kconf->flags & CONF_FLAGS_TEMPORARY) == 0)) - return 0; + if(kconf && ((kconf->flags & CONF_FLAGS_TEMPORARY) == 0)) + return 0; - for(p = aconf->user; *p; p++) - { - if(!IsUserChar(*p) && !IsKWildChar(*p)) - return 0; - } + for(p = aconf->user; *p; p++) { + if(!IsUserChar(*p) && !IsKWildChar(*p)) + return 0; + } - for(p = aconf->host; *p; p++) - { - if(!IsHostChar(*p) && !IsKWildChar(*p)) - return 0; - } + for(p = aconf->host; *p; p++) { + if(!IsHostChar(*p) && !IsKWildChar(*p)) + return 0; + } - return 1; + return 1; } static int bandb_check_dline(struct ConfItem *aconf) { - struct rb_sockaddr_storage daddr; -/* struct ConfItem *dconf; */ - int bits; + struct rb_sockaddr_storage daddr; + /* struct ConfItem *dconf; */ + int bits; - if(!parse_netmask(aconf->host, (struct sockaddr *)&daddr, &bits)) - return 0; + if(!parse_netmask(aconf->host, (struct sockaddr *)&daddr, &bits)) + return 0; - return 1; + return 1; } static int bandb_check_xline(struct ConfItem *aconf) { - struct ConfItem *xconf; - /* XXX perhaps convert spaces to \s? -- jilles */ + struct ConfItem *xconf; + /* XXX perhaps convert spaces to \s? -- jilles */ - xconf = find_xline_mask(aconf->host); - if(xconf != NULL && !(xconf->flags & CONF_FLAGS_TEMPORARY)) - return 0; + xconf = find_xline_mask(aconf->host); + if(xconf != NULL && !(xconf->flags & CONF_FLAGS_TEMPORARY)) + return 0; - return 1; + return 1; } static int bandb_check_resv_channel(struct ConfItem *aconf) { - const char *p; + const char *p; - if(hash_find_resv(aconf->host) || strlen(aconf->host) > CHANNELLEN) - return 0; + if(hash_find_resv(aconf->host) || strlen(aconf->host) > CHANNELLEN) + return 0; - for(p = aconf->host; *p; p++) - { - if(!IsChanChar(*p)) - return 0; - } + for(p = aconf->host; *p; p++) { + if(!IsChanChar(*p)) + return 0; + } - return 1; + return 1; } static int bandb_check_resv_nick(struct ConfItem *aconf) { - if(!clean_resv_nick(aconf->host)) - return 0; + if(!clean_resv_nick(aconf->host)) + return 0; - if(find_nick_resv(aconf->host)) - return 0; + if(find_nick_resv(aconf->host)) + return 0; - return 1; + return 1; } static void bandb_handle_clear(void) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, bandb_pending.head) - { - free_conf(ptr->data); - rb_dlinkDestroy(ptr, &bandb_pending); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, bandb_pending.head) { + free_conf(ptr->data); + rb_dlinkDestroy(ptr, &bandb_pending); + } } static void bandb_handle_finish(void) { - struct ConfItem *aconf; - rb_dlink_node *ptr, *next_ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr, *next_ptr; - clear_out_address_conf_bans(); - clear_s_newconf_bans(); + clear_out_address_conf_bans(); + clear_s_newconf_bans(); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, bandb_pending.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, bandb_pending.head) { + aconf = ptr->data; - rb_dlinkDestroy(ptr, &bandb_pending); + rb_dlinkDestroy(ptr, &bandb_pending); - switch (aconf->status) - { - case CONF_KILL: - if(bandb_check_kline(aconf)) - add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); - else - free_conf(aconf); + switch (aconf->status) { + case CONF_KILL: + if(bandb_check_kline(aconf)) + add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); + else + free_conf(aconf); - break; + break; - case CONF_DLINE: - if(bandb_check_dline(aconf)) - add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); - else - free_conf(aconf); + case CONF_DLINE: + if(bandb_check_dline(aconf)) + add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); + else + free_conf(aconf); - break; + break; - case CONF_XLINE: - if(bandb_check_xline(aconf)) - rb_dlinkAddAlloc(aconf, &xline_conf_list); - else - free_conf(aconf); + case CONF_XLINE: + if(bandb_check_xline(aconf)) + rb_dlinkAddAlloc(aconf, &xline_conf_list); + else + free_conf(aconf); - break; + break; - case CONF_RESV_CHANNEL: - if(bandb_check_resv_channel(aconf)) - add_to_resv_hash(aconf->host, aconf); - else - free_conf(aconf); + case CONF_RESV_CHANNEL: + if(bandb_check_resv_channel(aconf)) + add_to_resv_hash(aconf->host, aconf); + else + free_conf(aconf); - break; + break; - case CONF_RESV_NICK: - if(bandb_check_resv_nick(aconf)) - rb_dlinkAddAlloc(aconf, &resv_conf_list); - else - free_conf(aconf); + case CONF_RESV_NICK: + if(bandb_check_resv_nick(aconf)) + rb_dlinkAddAlloc(aconf, &resv_conf_list); + else + free_conf(aconf); - break; - } - } + break; + } + } - check_banned_lines(); + check_banned_lines(); } static void bandb_handle_failure(rb_helper *helper, char **parv, int parc) { - if(server_state_foreground) - fprintf(stderr, "bandb - bandb failure: %s\n", parv[1]); - - ilog(L_MAIN, "bandb - bandb failure: %s", parv[1]); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "bandb - bandb failure: %s", parv[1]); - exit(1); + if(server_state_foreground) + fprintf(stderr, "bandb - bandb failure: %s\n", parv[1]); + + ilog(L_MAIN, "bandb - bandb failure: %s", parv[1]); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "bandb - bandb failure: %s", parv[1]); + exit(1); } static void bandb_parse(rb_helper *helper) { - static char buf[READBUF_SIZE]; - char *parv[MAXPARA + 1]; - int len, parc; + static char buf[READBUF_SIZE]; + char *parv[MAXPARA + 1]; + int len, parc; - while((len = rb_helper_read(helper, buf, sizeof(buf)))) - { - parc = rb_string_to_array(buf, parv, MAXPARA); + while((len = rb_helper_read(helper, buf, sizeof(buf)))) { + parc = rb_string_to_array(buf, parv, MAXPARA); - if(parc < 1) - continue; + if(parc < 1) + continue; - switch (parv[0][0]) - { - case '!': - bandb_handle_failure(helper, parv, parc); - break; - case 'K': - case 'D': - case 'X': - case 'R': - bandb_handle_ban(parv, parc); - break; + switch (parv[0][0]) { + case '!': + bandb_handle_failure(helper, parv, parc); + break; + case 'K': + case 'D': + case 'X': + case 'R': + bandb_handle_ban(parv, parc); + break; - case 'C': - bandb_handle_clear(); - case 'F': - bandb_handle_finish(); - break; - } - } + case 'C': + bandb_handle_clear(); + case 'F': + bandb_handle_finish(); + break; + } + } } void bandb_rehash_bans(void) { - if(bandb_helper != NULL) - rb_helper_write(bandb_helper, "L"); + if(bandb_helper != NULL) + rb_helper_write(bandb_helper, "L"); } static void bandb_restart_cb(rb_helper *helper) { - ilog(L_MAIN, "bandb - bandb_restart_cb called, bandb helper died?"); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "bandb - bandb_restart_cb called, bandb helper died?"); - if(helper != NULL) - { - rb_helper_close(helper); - bandb_helper = NULL; - } - start_bandb(); - return; + ilog(L_MAIN, "bandb - bandb_restart_cb called, bandb helper died?"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "bandb - bandb_restart_cb called, bandb helper died?"); + if(helper != NULL) { + rb_helper_close(helper); + bandb_helper = NULL; + } + start_bandb(); + return; } diff --git a/src/blacklist.c b/src/blacklist.c index c165d4d..0052ec3 100644 --- a/src/blacklist.c +++ b/src/blacklist.c @@ -46,219 +46,202 @@ rb_dlink_list blacklist_list = { NULL, NULL, 0 }; /* private interfaces */ static struct Blacklist *find_blacklist(char *name) { - rb_dlink_node *nptr; + rb_dlink_node *nptr; - RB_DLINK_FOREACH(nptr, blacklist_list.head) - { - struct Blacklist *blptr = (struct Blacklist *) nptr->data; + RB_DLINK_FOREACH(nptr, blacklist_list.head) { + struct Blacklist *blptr = (struct Blacklist *) nptr->data; - if (!irccmp(blptr->host, name)) - return blptr; - } + if (!irccmp(blptr->host, name)) + return blptr; + } - return NULL; + return NULL; } static void blacklist_dns_callback(void *vptr, struct DNSReply *reply) { - struct BlacklistClient *blcptr = (struct BlacklistClient *) vptr; - int listed = 0; + struct BlacklistClient *blcptr = (struct BlacklistClient *) vptr; + int listed = 0; - if (blcptr == NULL || blcptr->client_p == NULL) - return; + if (blcptr == NULL || blcptr->client_p == NULL) + return; - if (blcptr->client_p->preClient == NULL) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "blacklist_dns_callback(): blcptr->client_p->preClient (%s) is NULL", get_client_name(blcptr->client_p, HIDE_IP)); - rb_free(blcptr); - return; - } + if (blcptr->client_p->preClient == NULL) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "blacklist_dns_callback(): blcptr->client_p->preClient (%s) is NULL", get_client_name(blcptr->client_p, HIDE_IP)); + rb_free(blcptr); + return; + } - if (reply != NULL) - { - /* only accept 127.x.y.z as a listing */ - if (reply->addr.ss_family == AF_INET && - !memcmp(&((struct sockaddr_in *)&reply->addr)->sin_addr, "\177", 1)) - listed = TRUE; - else if (blcptr->blacklist->lastwarning + 3600 < rb_current_time()) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Garbage reply from blacklist %s", - blcptr->blacklist->host); - blcptr->blacklist->lastwarning = rb_current_time(); - } - } + if (reply != NULL) { + /* only accept 127.x.y.z as a listing */ + if (reply->addr.ss_family == AF_INET && + !memcmp(&((struct sockaddr_in *)&reply->addr)->sin_addr, "\177", 1)) + listed = TRUE; + else if (blcptr->blacklist->lastwarning + 3600 < rb_current_time()) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Garbage reply from blacklist %s", + blcptr->blacklist->host); + blcptr->blacklist->lastwarning = rb_current_time(); + } + } - /* they have a blacklist entry for this client */ - if (listed && blcptr->client_p->preClient->dnsbl_listed == NULL) - { - blcptr->client_p->preClient->dnsbl_listed = blcptr->blacklist; - /* reference to blacklist moves from blcptr to client_p->preClient... */ - } - else - unref_blacklist(blcptr->blacklist); + /* they have a blacklist entry for this client */ + if (listed && blcptr->client_p->preClient->dnsbl_listed == NULL) { + blcptr->client_p->preClient->dnsbl_listed = blcptr->blacklist; + /* reference to blacklist moves from blcptr to client_p->preClient... */ + } else + unref_blacklist(blcptr->blacklist); - rb_dlinkDelete(&blcptr->node, &blcptr->client_p->preClient->dnsbl_queries); + rb_dlinkDelete(&blcptr->node, &blcptr->client_p->preClient->dnsbl_queries); - /* yes, it can probably happen... */ - if (rb_dlink_list_length(&blcptr->client_p->preClient->dnsbl_queries) == 0 && blcptr->client_p->flags & FLAGS_SENTUSER && !EmptyString(blcptr->client_p->name)) - { - char buf[USERLEN + 1]; - rb_strlcpy(buf, blcptr->client_p->username, sizeof buf); - register_local_user(blcptr->client_p, blcptr->client_p, buf); - } + /* yes, it can probably happen... */ + if (rb_dlink_list_length(&blcptr->client_p->preClient->dnsbl_queries) == 0 && blcptr->client_p->flags & FLAGS_SENTUSER && !EmptyString(blcptr->client_p->name)) { + char buf[USERLEN + 1]; + rb_strlcpy(buf, blcptr->client_p->username, sizeof buf); + register_local_user(blcptr->client_p, blcptr->client_p, buf); + } - rb_free(blcptr); + rb_free(blcptr); } static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *client_p) { - struct BlacklistClient *blcptr = rb_malloc(sizeof(struct BlacklistClient)); - char buf[IRCD_RES_HOSTLEN + 1]; - uint8_t *ip; + struct BlacklistClient *blcptr = rb_malloc(sizeof(struct BlacklistClient)); + char buf[IRCD_RES_HOSTLEN + 1]; + uint8_t *ip; - blcptr->blacklist = blptr; - blcptr->client_p = client_p; + blcptr->blacklist = blptr; + blcptr->client_p = client_p; - blcptr->dns_query.ptr = blcptr; - blcptr->dns_query.callback = blacklist_dns_callback; + blcptr->dns_query.ptr = blcptr; + blcptr->dns_query.callback = blacklist_dns_callback; - if ((client_p->localClient->ip.ss_family == AF_INET) && blptr->ipv4) - { - ip = (uint8_t *)&((struct sockaddr_in *)&client_p->localClient->ip)->sin_addr.s_addr; + if ((client_p->localClient->ip.ss_family == AF_INET) && blptr->ipv4) { + ip = (uint8_t *)&((struct sockaddr_in *)&client_p->localClient->ip)->sin_addr.s_addr; - /* becomes 2.0.0.127.torbl.ahbl.org or whatever */ - rb_snprintf(buf, sizeof buf, "%d.%d.%d.%d.%s", - (unsigned int) ip[3], - (unsigned int) ip[2], - (unsigned int) ip[1], - (unsigned int) ip[0], - blptr->host); - } - /* IPv6 is supported now. --Elizabeth */ - else if ((client_p->localClient->ip.ss_family == AF_INET6) && blptr->ipv6) - { - /* Breaks it into ip[0] = 0x00, ip[1] = 0x00... ip[16] = 0x01 for localhost - * I wish there was a uint4_t for C, this would make the below cleaner, but... */ - ip = (uint8_t *)&((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_addr.s6_addr; - char *bufptr = buf; - int i; + /* becomes 2.0.0.127.torbl.ahbl.org or whatever */ + rb_snprintf(buf, sizeof buf, "%d.%d.%d.%d.%s", + (unsigned int) ip[3], + (unsigned int) ip[2], + (unsigned int) ip[1], + (unsigned int) ip[0], + blptr->host); + } + /* IPv6 is supported now. --Elizabeth */ + else if ((client_p->localClient->ip.ss_family == AF_INET6) && blptr->ipv6) { + /* Breaks it into ip[0] = 0x00, ip[1] = 0x00... ip[16] = 0x01 for localhost + * I wish there was a uint4_t for C, this would make the below cleaner, but... */ + ip = (uint8_t *)&((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_addr.s6_addr; + char *bufptr = buf; + int i; - /* The below will give us something like - * 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.foobl.invalid - */ + /* The below will give us something like + * 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.foobl.invalid + */ - /* Going backwards */ - for (i = 15; i >= 0; i--) - { - /* Get upper and lower nibbles (yes this works fine on - * both big and little endian) */ - uint8_t hi = (ip[i] >> 4) & 0x0F; - uint8_t lo = ip[i] & 0x0F; + /* Going backwards */ + for (i = 15; i >= 0; i--) { + /* Get upper and lower nibbles (yes this works fine on + * both big and little endian) */ + uint8_t hi = (ip[i] >> 4) & 0x0F; + uint8_t lo = ip[i] & 0x0F; - /* One part... (why 5? rb_snprintf adds \0) */ - rb_snprintf(bufptr, 5, "%1x.%1x.", - (unsigned int) lo, /* Remember, backwards */ - (unsigned int) hi); + /* One part... (why 5? rb_snprintf adds \0) */ + rb_snprintf(bufptr, 5, "%1x.%1x.", + (unsigned int) lo, /* Remember, backwards */ + (unsigned int) hi); - /* Lurch forward to next position */ - bufptr += 4; - } + /* Lurch forward to next position */ + bufptr += 4; + } - /* Tack host on */ - strcpy(bufptr, blptr->host); - } - /* This shouldn't happen... */ - else - return; + /* Tack host on */ + strcpy(bufptr, blptr->host); + } + /* This shouldn't happen... */ + else + return; - gethost_byname_type(buf, &blcptr->dns_query, T_A); + gethost_byname_type(buf, &blcptr->dns_query, T_A); - rb_dlinkAdd(blcptr, &blcptr->node, &client_p->preClient->dnsbl_queries); - blptr->refcount++; + rb_dlinkAdd(blcptr, &blcptr->node, &client_p->preClient->dnsbl_queries); + blptr->refcount++; } /* public interfaces */ struct Blacklist *new_blacklist(char *name, char *reject_reason, int ipv4, int ipv6) { - struct Blacklist *blptr; + struct Blacklist *blptr; - if (name == NULL || reject_reason == NULL) - return NULL; + if (name == NULL || reject_reason == NULL) + return NULL; - blptr = find_blacklist(name); - if (blptr == NULL) - { - blptr = rb_malloc(sizeof(struct Blacklist)); - rb_dlinkAddAlloc(blptr, &blacklist_list); - } - else - blptr->status &= ~CONF_ILLEGAL; - rb_strlcpy(blptr->host, name, IRCD_RES_HOSTLEN + 1); - rb_strlcpy(blptr->reject_reason, reject_reason, IRCD_BUFSIZE); - blptr->ipv4 = ipv4; - blptr->ipv6 = ipv6; - blptr->lastwarning = 0; + blptr = find_blacklist(name); + if (blptr == NULL) { + blptr = rb_malloc(sizeof(struct Blacklist)); + rb_dlinkAddAlloc(blptr, &blacklist_list); + } else + blptr->status &= ~CONF_ILLEGAL; + rb_strlcpy(blptr->host, name, IRCD_RES_HOSTLEN + 1); + rb_strlcpy(blptr->reject_reason, reject_reason, IRCD_BUFSIZE); + blptr->ipv4 = ipv4; + blptr->ipv6 = ipv6; + blptr->lastwarning = 0; - return blptr; + return blptr; } void unref_blacklist(struct Blacklist *blptr) { - blptr->refcount--; - if (blptr->status & CONF_ILLEGAL && blptr->refcount <= 0) - { - rb_dlinkFindDestroy(blptr, &blacklist_list); - rb_free(blptr); - } + blptr->refcount--; + if (blptr->status & CONF_ILLEGAL && blptr->refcount <= 0) { + rb_dlinkFindDestroy(blptr, &blacklist_list); + rb_free(blptr); + } } void lookup_blacklists(struct Client *client_p) { - rb_dlink_node *nptr; + rb_dlink_node *nptr; - RB_DLINK_FOREACH(nptr, blacklist_list.head) - { - struct Blacklist *blptr = (struct Blacklist *) nptr->data; + RB_DLINK_FOREACH(nptr, blacklist_list.head) { + struct Blacklist *blptr = (struct Blacklist *) nptr->data; - if (!(blptr->status & CONF_ILLEGAL)) - initiate_blacklist_dnsquery(blptr, client_p); - } + if (!(blptr->status & CONF_ILLEGAL)) + initiate_blacklist_dnsquery(blptr, client_p); + } } void abort_blacklist_queries(struct Client *client_p) { - rb_dlink_node *ptr, *next_ptr; - struct BlacklistClient *blcptr; + rb_dlink_node *ptr, *next_ptr; + struct BlacklistClient *blcptr; - if (client_p->preClient == NULL) - return; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->preClient->dnsbl_queries.head) - { - blcptr = ptr->data; - rb_dlinkDelete(&blcptr->node, &client_p->preClient->dnsbl_queries); - unref_blacklist(blcptr->blacklist); - delete_resolver_queries(&blcptr->dns_query); - rb_free(blcptr); - } + if (client_p->preClient == NULL) + return; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->preClient->dnsbl_queries.head) { + blcptr = ptr->data; + rb_dlinkDelete(&blcptr->node, &client_p->preClient->dnsbl_queries); + unref_blacklist(blcptr->blacklist); + delete_resolver_queries(&blcptr->dns_query); + rb_free(blcptr); + } } void destroy_blacklists(void) { - rb_dlink_node *ptr, *next_ptr; - struct Blacklist *blptr; + rb_dlink_node *ptr, *next_ptr; + struct Blacklist *blptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, blacklist_list.head) - { - blptr = ptr->data; - blptr->hits = 0; /* keep it simple and consistent */ - if (blptr->refcount > 0) - blptr->status |= CONF_ILLEGAL; - else - { - rb_free(ptr->data); - rb_dlinkDestroy(ptr, &blacklist_list); - } - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, blacklist_list.head) { + blptr = ptr->data; + blptr->hits = 0; /* keep it simple and consistent */ + if (blptr->refcount > 0) + blptr->status |= CONF_ILLEGAL; + else { + rb_free(ptr->data); + rb_dlinkDestroy(ptr, &blacklist_list); + } + } } diff --git a/src/cache.c b/src/cache.c index 04766b7..6b937af 100644 --- a/src/cache.c +++ b/src/cache.c @@ -59,21 +59,21 @@ struct Dictionary *help_dict_user = NULL; void init_cache(void) { - /* allocate the emptyline */ - emptyline = rb_malloc(sizeof(struct cacheline)); - emptyline->data[0] = ' '; - emptyline->data[1] = '\0'; - user_motd_changed[0] = '\0'; + /* allocate the emptyline */ + emptyline = rb_malloc(sizeof(struct cacheline)); + emptyline->data[0] = ' '; + emptyline->data[1] = '\0'; + user_motd_changed[0] = '\0'; - user_motd = cache_file(MPATH, "ircd.motd", 0); - oper_motd = cache_file(OPATH, "opers.motd", 0); - memset(&links_cache_list, 0, sizeof(links_cache_list)); + user_motd = cache_file(MPATH, "ircd.motd", 0); + oper_motd = cache_file(OPATH, "opers.motd", 0); + memset(&links_cache_list, 0, sizeof(links_cache_list)); - help_dict_oper = irc_dictionary_create(strcasecmp); - help_dict_user = irc_dictionary_create(strcasecmp); + help_dict_oper = irc_dictionary_create(strcasecmp); + help_dict_user = irc_dictionary_create(strcasecmp); } -/* +/* * removes tabs from src, replaces with 8 spaces, and returns the length * of the new string. if the new string would be greater than destlen, * it is truncated to destlen - 1 @@ -81,25 +81,22 @@ init_cache(void) static size_t untabify(char *dest, const char *src, size_t destlen) { - size_t x = 0, i; - const char *s = src; - char *d = dest; + size_t x = 0, i; + const char *s = src; + char *d = dest; - while(*s != '\0' && x < destlen - 1) - { - if(*s == '\t') - { - for(i = 0; i < 8 && x < destlen - 1; i++, x++, d++) - *d = ' '; - s++; - } else - { - *d++ = *s++; - x++; - } - } - *d = '\0'; - return x; + while(*s != '\0' && x < destlen - 1) { + if(*s == '\t') { + for(i = 0; i < 8 && x < destlen - 1; i++, x++, d++) + *d = ' '; + s++; + } else { + *d++ = *s++; + x++; + } + } + *d = '\0'; + return x; } /* cache_file() @@ -111,83 +108,77 @@ untabify(char *dest, const char *src, size_t destlen) struct cachefile * cache_file(const char *filename, const char *shortname, int flags) { - FILE *in; - struct cachefile *cacheptr; - struct cacheline *lineptr; - char line[BUFSIZE]; - char *p; + FILE *in; + struct cachefile *cacheptr; + struct cacheline *lineptr; + char line[BUFSIZE]; + char *p; - if((in = fopen(filename, "r")) == NULL) - return NULL; + if((in = fopen(filename, "r")) == NULL) + return NULL; - cacheptr = rb_malloc(sizeof(struct cachefile)); + cacheptr = rb_malloc(sizeof(struct cachefile)); - rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name)); - cacheptr->flags = flags; + rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name)); + cacheptr->flags = flags; - /* cache the file... */ - while(fgets(line, sizeof(line), in) != NULL) - { - if((p = strpbrk(line, "\r\n")) != NULL) - *p = '\0'; + /* cache the file... */ + while(fgets(line, sizeof(line), in) != NULL) { + if((p = strpbrk(line, "\r\n")) != NULL) + *p = '\0'; - if(!EmptyString(line)) - { - lineptr = rb_malloc(sizeof(struct cacheline)); - untabify(lineptr->data, line, sizeof(lineptr->data)); - rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents); - } - else - rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents); - } + if(!EmptyString(line)) { + lineptr = rb_malloc(sizeof(struct cacheline)); + untabify(lineptr->data, line, sizeof(lineptr->data)); + rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents); + } else + rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents); + } - if (0 == rb_dlink_list_length(&cacheptr->contents)) - { - /* No contents. Don't cache it after all. */ - rb_free(cacheptr); - cacheptr = NULL; - } + if (0 == rb_dlink_list_length(&cacheptr->contents)) { + /* No contents. Don't cache it after all. */ + rb_free(cacheptr); + cacheptr = NULL; + } - fclose(in); - return cacheptr; + fclose(in); + return cacheptr; } void cache_links(void *unused) { - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - char *links_line; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + char *links_line; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head) - { - rb_free(ptr->data); - rb_free_rb_dlink_node(ptr); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head) { + rb_free(ptr->data); + rb_free_rb_dlink_node(ptr); + } - links_cache_list.head = links_cache_list.tail = NULL; - links_cache_list.length = 0; + links_cache_list.head = links_cache_list.tail = NULL; + links_cache_list.length = 0; - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + target_p = ptr->data; - /* skip ourselves (done in /links) and hidden servers */ - if(IsMe(target_p) || - (IsHidden(target_p) && !ConfigServerHide.disable_hidden)) - continue; + /* skip ourselves (done in /links) and hidden servers */ + if(IsMe(target_p) || + (IsHidden(target_p) && !ConfigServerHide.disable_hidden)) + continue; - /* if the below is ever modified, change LINKSLINELEN */ - links_line = rb_malloc(LINKSLINELEN); - rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s", - target_p->name, me.name, - target_p->info[0] ? target_p->info : - "(Unknown Location)"); + /* if the below is ever modified, change LINKSLINELEN */ + links_line = rb_malloc(LINKSLINELEN); + rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s", + target_p->name, me.name, + target_p->info[0] ? target_p->info : + "(Unknown Location)"); - rb_dlinkAddTailAlloc(links_line, &links_cache_list); - } + rb_dlinkAddTailAlloc(links_line, &links_cache_list); + } } /* free_cachefile() @@ -199,19 +190,18 @@ cache_links(void *unused) void free_cachefile(struct cachefile *cacheptr) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - if(cacheptr == NULL) - return; + if(cacheptr == NULL) + return; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head) - { - if(ptr->data != emptyline) - rb_free(ptr->data); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head) { + if(ptr->data != emptyline) + rb_free(ptr->data); + } - rb_free(cacheptr); + rb_free(cacheptr); } /* load_help() @@ -224,77 +214,71 @@ free_cachefile(struct cachefile *cacheptr) void load_help(void) { - DIR *helpfile_dir = NULL; - struct dirent *ldirent= NULL; - char filename[MAXPATHLEN]; - struct cachefile *cacheptr; - struct DictionaryIter iter; + DIR *helpfile_dir = NULL; + struct dirent *ldirent= NULL; + char filename[MAXPATHLEN]; + struct cachefile *cacheptr; + struct DictionaryIter iter; #if defined(S_ISLNK) && defined(HAVE_LSTAT) - struct stat sb; + struct stat sb; #endif - DICTIONARY_FOREACH(cacheptr, &iter, help_dict_oper) - { - irc_dictionary_delete(help_dict_oper, cacheptr->name); - free_cachefile(cacheptr); - } - DICTIONARY_FOREACH(cacheptr, &iter, help_dict_user) - { - irc_dictionary_delete(help_dict_user, cacheptr->name); - free_cachefile(cacheptr); - } + DICTIONARY_FOREACH(cacheptr, &iter, help_dict_oper) { + irc_dictionary_delete(help_dict_oper, cacheptr->name); + free_cachefile(cacheptr); + } + DICTIONARY_FOREACH(cacheptr, &iter, help_dict_user) { + irc_dictionary_delete(help_dict_user, cacheptr->name); + free_cachefile(cacheptr); + } - helpfile_dir = opendir(HPATH); + helpfile_dir = opendir(HPATH); - if(helpfile_dir == NULL) - return; + if(helpfile_dir == NULL) + return; - while((ldirent = readdir(helpfile_dir)) != NULL) - { - if(ldirent->d_name[0] == '.') - continue; - rb_snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name); - cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER); - irc_dictionary_add(help_dict_oper, cacheptr->name, cacheptr); - } + while((ldirent = readdir(helpfile_dir)) != NULL) { + if(ldirent->d_name[0] == '.') + continue; + rb_snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name); + cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER); + irc_dictionary_add(help_dict_oper, cacheptr->name, cacheptr); + } - closedir(helpfile_dir); - helpfile_dir = opendir(UHPATH); + closedir(helpfile_dir); + helpfile_dir = opendir(UHPATH); - if(helpfile_dir == NULL) - return; + if(helpfile_dir == NULL) + return; - while((ldirent = readdir(helpfile_dir)) != NULL) - { - if(ldirent->d_name[0] == '.') - continue; - rb_snprintf(filename, sizeof(filename), "%s/%s", UHPATH, ldirent->d_name); + while((ldirent = readdir(helpfile_dir)) != NULL) { + if(ldirent->d_name[0] == '.') + continue; + rb_snprintf(filename, sizeof(filename), "%s/%s", UHPATH, ldirent->d_name); #if defined(S_ISLNK) && defined(HAVE_LSTAT) - if(lstat(filename, &sb) < 0) - continue; + if(lstat(filename, &sb) < 0) + continue; - /* ok, if its a symlink, we work on the presumption if an - * oper help exists of that name, its a symlink to that --fl - */ - if(S_ISLNK(sb.st_mode)) - { - cacheptr = irc_dictionary_retrieve(help_dict_oper, ldirent->d_name); + /* ok, if its a symlink, we work on the presumption if an + * oper help exists of that name, its a symlink to that --fl + */ + if(S_ISLNK(sb.st_mode)) { + cacheptr = irc_dictionary_retrieve(help_dict_oper, ldirent->d_name); - if(cacheptr != NULL) - { - cacheptr->flags |= HELP_USER; - continue; - } - } + if(cacheptr != NULL) { + cacheptr->flags |= HELP_USER; + continue; + } + } #endif - cacheptr = cache_file(filename, ldirent->d_name, HELP_USER); - irc_dictionary_add(help_dict_user, cacheptr->name, cacheptr); - } + cacheptr = cache_file(filename, ldirent->d_name, HELP_USER); + irc_dictionary_add(help_dict_user, cacheptr->name, cacheptr); + } - closedir(helpfile_dir); + closedir(helpfile_dir); } /* send_user_motd() @@ -306,48 +290,44 @@ load_help(void) void send_user_motd(struct Client *source_p) { - struct cacheline *lineptr; - rb_dlink_node *ptr; - const char *myname = get_id(&me, source_p); - const char *nick = get_id(source_p, source_p); - if(user_motd == NULL || rb_dlink_list_length(&user_motd->contents) == 0) - { - sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick); - return; - } + struct cacheline *lineptr; + rb_dlink_node *ptr; + const char *myname = get_id(&me, source_p); + const char *nick = get_id(source_p, source_p); + if(user_motd == NULL || rb_dlink_list_length(&user_motd->contents) == 0) { + sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick); + return; + } - sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name); + sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name); - RB_DLINK_FOREACH(ptr, user_motd->contents.head) - { - lineptr = ptr->data; - sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data); - } + RB_DLINK_FOREACH(ptr, user_motd->contents.head) { + lineptr = ptr->data; + sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data); + } - sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick); + sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick); } void cache_user_motd(void) { - struct stat sb; - struct tm *local_tm; - - if(stat(MPATH, &sb) == 0) - { - local_tm = localtime(&sb.st_mtime); + struct stat sb; + struct tm *local_tm; - if(local_tm != NULL) - { - rb_snprintf(user_motd_changed, sizeof(user_motd_changed), - "%d/%d/%d %d:%d", - local_tm->tm_mday, local_tm->tm_mon + 1, - 1900 + local_tm->tm_year, local_tm->tm_hour, - local_tm->tm_min); - } - } - free_cachefile(user_motd); - user_motd = cache_file(MPATH, "ircd.motd", 0); + if(stat(MPATH, &sb) == 0) { + local_tm = localtime(&sb.st_mtime); + + if(local_tm != NULL) { + rb_snprintf(user_motd_changed, sizeof(user_motd_changed), + "%d/%d/%d %d:%d", + local_tm->tm_mday, local_tm->tm_mon + 1, + 1900 + local_tm->tm_year, local_tm->tm_hour, + local_tm->tm_min); + } + } + free_cachefile(user_motd); + user_motd = cache_file(MPATH, "ircd.motd", 0); } @@ -360,22 +340,21 @@ cache_user_motd(void) void send_oper_motd(struct Client *source_p) { - struct cacheline *lineptr; - rb_dlink_node *ptr; + struct cacheline *lineptr; + rb_dlink_node *ptr; - if(oper_motd == NULL || rb_dlink_list_length(&oper_motd->contents) == 0) - return; + if(oper_motd == NULL || rb_dlink_list_length(&oper_motd->contents) == 0) + return; - sendto_one(source_p, form_str(RPL_OMOTDSTART), - me.name, source_p->name); + sendto_one(source_p, form_str(RPL_OMOTDSTART), + me.name, source_p->name); - RB_DLINK_FOREACH(ptr, oper_motd->contents.head) - { - lineptr = ptr->data; - sendto_one(source_p, form_str(RPL_OMOTD), - me.name, source_p->name, lineptr->data); - } + RB_DLINK_FOREACH(ptr, oper_motd->contents.head) { + lineptr = ptr->data; + sendto_one(source_p, form_str(RPL_OMOTD), + me.name, source_p->name, lineptr->data); + } - sendto_one(source_p, form_str(RPL_ENDOFOMOTD), - me.name, source_p->name); + sendto_one(source_p, form_str(RPL_ENDOFOMOTD), + me.name, source_p->name); } diff --git a/src/channel.c b/src/channel.c index 378b7c4..b0da262 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2,9 +2,9 @@ * ircd-ratbox: A slightly useful ircd. * channel.c: Controls channels. * - * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center - * Copyright (C) 1996-2002 Hybrid Development Team - * Copyright (C) 2002-2005 ircd-ratbox development team + * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center + * Copyright (C) 1996-2002 Hybrid Development Team + * Copyright (C) 2002-2005 ircd-ratbox development team * * 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 @@ -51,9 +51,9 @@ static rb_bh *topic_heap; static rb_bh *member_heap; static int channel_capabs[] = { CAP_EX, CAP_IE, - CAP_SERVICE, - CAP_TS6 -}; + CAP_SERVICE, + CAP_TS6 + }; #define NCHCAPS (sizeof(channel_capabs)/sizeof(int)) #define NCHCAP_COMBOS (1 << NCHCAPS) @@ -75,14 +75,14 @@ static int h_channel_join; void init_channels(void) { - channel_heap = rb_bh_create(sizeof(struct Channel), CHANNEL_HEAP_SIZE, "channel_heap"); - ban_heap = rb_bh_create(sizeof(struct Ban), BAN_HEAP_SIZE, "ban_heap"); - topic_heap = rb_bh_create(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE, "topic_heap"); - member_heap = rb_bh_create(sizeof(struct membership), MEMBER_HEAP_SIZE, "member_heap"); + channel_heap = rb_bh_create(sizeof(struct Channel), CHANNEL_HEAP_SIZE, "channel_heap"); + ban_heap = rb_bh_create(sizeof(struct Ban), BAN_HEAP_SIZE, "ban_heap"); + topic_heap = rb_bh_create(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE, "topic_heap"); + member_heap = rb_bh_create(sizeof(struct membership), MEMBER_HEAP_SIZE, "member_heap"); - h_can_join = register_hook("can_join"); - h_channel_join = register_hook("channel_join"); - h_can_create_channel = register_hook("can_create_channel"); + h_can_join = register_hook("can_join"); + h_channel_join = register_hook("channel_join"); + h_can_create_channel = register_hook("can_create_channel"); } /* @@ -91,42 +91,42 @@ init_channels(void) struct Channel * allocate_channel(const char *chname) { - struct Channel *chptr; - struct Dictionary *metadata; - chptr = rb_bh_alloc(channel_heap); - chptr->chname = rb_strdup(chname); - - metadata = irc_dictionary_create(irccmp); - chptr->metadata = metadata; - return (chptr); + struct Channel *chptr; + struct Dictionary *metadata; + chptr = rb_bh_alloc(channel_heap); + chptr->chname = rb_strdup(chname); + + metadata = irc_dictionary_create(irccmp); + chptr->metadata = metadata; + return (chptr); } void free_channel(struct Channel *chptr) { - channel_metadata_clear(chptr); - rb_free(chptr->chname); - rb_free(chptr->mode_lock); - rb_bh_free(channel_heap, chptr); + channel_metadata_clear(chptr); + rb_free(chptr->chname); + rb_free(chptr->mode_lock); + rb_bh_free(channel_heap, chptr); } struct Ban * allocate_ban(const char *banstr, const char *who) { - struct Ban *bptr; - bptr = rb_bh_alloc(ban_heap); - bptr->banstr = rb_strdup(banstr); - bptr->who = rb_strdup(who); + struct Ban *bptr; + bptr = rb_bh_alloc(ban_heap); + bptr->banstr = rb_strdup(banstr); + bptr->who = rb_strdup(who); - return (bptr); + return (bptr); } void free_ban(struct Ban *bptr) { - rb_free(bptr->banstr); - rb_free(bptr->who); - rb_bh_free(ban_heap, bptr); + rb_free(bptr->banstr); + rb_free(bptr->who); + rb_bh_free(ban_heap, bptr); } @@ -139,37 +139,32 @@ free_ban(struct Ban *bptr) struct membership * find_channel_membership(struct Channel *chptr, struct Client *client_p) { - struct membership *msptr; - rb_dlink_node *ptr; + struct membership *msptr; + rb_dlink_node *ptr; - if(!IsClient(client_p)) - return NULL; + if(!IsClient(client_p)) + return NULL; - /* Pick the most efficient list to use to be nice to things like - * CHANSERV which could be in a large number of channels - */ - if(rb_dlink_list_length(&chptr->members) < rb_dlink_list_length(&client_p->user->channel)) - { - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; + /* Pick the most efficient list to use to be nice to things like + * CHANSERV which could be in a large number of channels + */ + if(rb_dlink_list_length(&chptr->members) < rb_dlink_list_length(&client_p->user->channel)) { + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; - if(msptr->client_p == client_p) - return msptr; - } - } - else - { - RB_DLINK_FOREACH(ptr, client_p->user->channel.head) - { - msptr = ptr->data; + if(msptr->client_p == client_p) + return msptr; + } + } else { + RB_DLINK_FOREACH(ptr, client_p->user->channel.head) { + msptr = ptr->data; - if(msptr->chptr == chptr) - return msptr; - } - } + if(msptr->chptr == chptr) + return msptr; + } + } - return NULL; + return NULL; } /* find_channel_status() @@ -181,114 +176,110 @@ find_channel_membership(struct Channel *chptr, struct Client *client_p) const char * find_channel_status(struct membership *msptr, int combine) { - static char buffer[5]; - char *p; + static char buffer[5]; + char *p; - p = buffer; + p = buffer; - if(is_owner(msptr)) - { - if(!combine) - return "~"; - *p++ = '~'; - } - if(is_admin(msptr)) - { - if(!combine) - return "!"; - *p++ = '!'; - } + if(is_owner(msptr)) { + if(!combine) + return "~"; + *p++ = '~'; + } + if(is_admin(msptr)) { + if(!combine) + return "!"; + *p++ = '!'; + } - if(is_chanop(msptr)) - { - if(!combine) - return "@"; - *p++ = '@'; - } + if(is_chanop(msptr)) { + if(!combine) + return "@"; + *p++ = '@'; + } - if(is_halfop(msptr)) - { - if(!combine) - return "%"; - *p++ = '%'; - } + if(is_halfop(msptr)) { + if(!combine) + return "%"; + *p++ = '%'; + } - if(is_voiced(msptr)) - *p++ = '+'; + if(is_voiced(msptr)) + *p++ = '+'; - *p = '\0'; - return buffer; + *p = '\0'; + return buffer; } /* is_halfop() * * input - membership to check for halfops - * output - 1 if the user is halfopped, 0 if the user is not or halfop + * output - 1 if the user is halfopped, 0 if the user is not or halfop * is disabled. - * side effects - + * side effects - * */ int is_halfop(struct membership *msptr) { - if(!ConfigChannel.use_halfop) - return 0; - if(is_chmode_h(msptr)) - return 1; - else - return 0; + if(!ConfigChannel.use_halfop) + return 0; + if(is_chmode_h(msptr)) + return 1; + else + return 0; } /* is_admin() * * input - membership to check for admin - * output - 1 if the user is an admin, 0 if the user is not or admin + * output - 1 if the user is an admin, 0 if the user is not or admin * is disabled. - * side effects - + * side effects - * */ int is_admin(struct membership *msptr) { - if(!ConfigChannel.use_admin) - return 0; - if(is_chmode_a(msptr)) - return 1; - else - return 0; + if(!ConfigChannel.use_admin) + return 0; + if(is_chmode_a(msptr)) + return 1; + else + return 0; } /* is_owner() * input - membership to check for owner * output - 1 if the user is an admin, 0 if the user is not or owner * is disabled - * side effects - + * side effects - * */ int is_owner(struct membership *msptr) { - if(!ConfigChannel.use_owner) - return 0; - if(is_chmode_y(msptr)) - return 1; - else - return 0; + if(!ConfigChannel.use_owner) + return 0; + if(is_chmode_y(msptr)) + return 1; + else + return 0; } /* is_any_op() * * input - membership to check for ops * output - 1 if the user is op, halfop, or admin, 0 elsewise - * side effects - + * side effects - */ int is_any_op(struct membership *msptr) { - if(is_chanop(msptr) || is_halfop(msptr) || is_admin(msptr) || is_owner(msptr)) - return 1; - else - return 0; + if(is_chanop(msptr) || is_halfop(msptr) || is_admin(msptr) || is_owner(msptr)) + return 1; + else + return 0; } /* is_chanop_voiced() @@ -300,10 +291,10 @@ is_any_op(struct membership *msptr) int is_chanop_voiced(struct membership *msptr) { - if(is_chanop(msptr) || is_voiced(msptr) || is_halfop(msptr) || is_admin(msptr) || is_owner(msptr)) - return 1; - else - return 0; + if(is_chanop(msptr) || is_voiced(msptr) || is_halfop(msptr) || is_admin(msptr) || is_owner(msptr)) + return 1; + else + return 0; } /* can_kick_deop() @@ -315,61 +306,61 @@ is_chanop_voiced(struct membership *msptr) int can_kick_deop(struct membership *source, struct membership *target) { - /* - * Reworked the logic to match this: - * - owners can do what they want - * - admins cannot kick or deop owners - * - admins can kick or deop admins - * - ops cannot kick or deop admins - * - halfops cannot kick or deop anyone that has halfop or up - * -- Niichan - */ + /* + * Reworked the logic to match this: + * - owners can do what they want + * - admins cannot kick or deop owners + * - admins can kick or deop admins + * - ops cannot kick or deop admins + * - halfops cannot kick or deop anyone that has halfop or up + * -- Niichan + */ - if(is_owner(source)) - return 1; - if(is_admin(source) && is_owner(target)) - return 0; - if(is_admin(source) && is_admin(target)) - return 1; - if(is_chanop(source) && is_owner(target)) - return 0; - if(is_chanop(source) && is_admin(target)) - return 0; - if(is_halfop(source) && is_any_op(target)) - return 0; - if(!is_any_op(source)) - return 0; + if(is_owner(source)) + return 1; + if(is_admin(source) && is_owner(target)) + return 0; + if(is_admin(source) && is_admin(target)) + return 1; + if(is_chanop(source) && is_owner(target)) + return 0; + if(is_chanop(source) && is_admin(target)) + return 0; + if(is_halfop(source) && is_any_op(target)) + return 0; + if(!is_any_op(source)) + return 0; - return 1; + return 1; } /* add_user_to_channel() * * input - channel to add client to, client to add, channel flags - * output - + * output - * side effects - user is added to channel */ void add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) { - struct membership *msptr; + struct membership *msptr; - s_assert(client_p->user != NULL); - if(client_p->user == NULL) - return; + s_assert(client_p->user != NULL); + if(client_p->user == NULL) + return; - msptr = rb_bh_alloc(member_heap); + msptr = rb_bh_alloc(member_heap); - msptr->chptr = chptr; - msptr->client_p = client_p; - msptr->flags = flags; + msptr->chptr = chptr; + msptr->client_p = client_p; + msptr->flags = flags; - rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel); - rb_dlinkAdd(msptr, &msptr->channode, &chptr->members); + rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel); + rb_dlinkAdd(msptr, &msptr->channode, &chptr->members); - if(MyClient(client_p)) - rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers); + if(MyClient(client_p)) + rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers); } /* remove_user_from_channel() @@ -381,27 +372,27 @@ add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) void remove_user_from_channel(struct membership *msptr) { - struct Client *client_p; - struct Channel *chptr; - s_assert(msptr != NULL); - if(msptr == NULL) - return; + struct Client *client_p; + struct Channel *chptr; + s_assert(msptr != NULL); + if(msptr == NULL) + return; - client_p = msptr->client_p; - chptr = msptr->chptr; + client_p = msptr->client_p; + chptr = msptr->chptr; - rb_dlinkDelete(&msptr->usernode, &client_p->user->channel); - rb_dlinkDelete(&msptr->channode, &chptr->members); + rb_dlinkDelete(&msptr->usernode, &client_p->user->channel); + rb_dlinkDelete(&msptr->channode, &chptr->members); - if(client_p->servptr == &me) - rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); + if(client_p->servptr == &me) + rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); - if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) - destroy_channel(chptr); + if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) + destroy_channel(chptr); - rb_bh_free(member_heap, msptr); + rb_bh_free(member_heap, msptr); - return; + return; } /* remove_user_from_channels() @@ -413,32 +404,31 @@ remove_user_from_channel(struct membership *msptr) void remove_user_from_channels(struct Client *client_p) { - struct Channel *chptr; - struct membership *msptr; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct Channel *chptr; + struct membership *msptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - if(client_p == NULL) - return; + if(client_p == NULL) + return; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head) - { - msptr = ptr->data; - chptr = msptr->chptr; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head) { + msptr = ptr->data; + chptr = msptr->chptr; - rb_dlinkDelete(&msptr->channode, &chptr->members); + rb_dlinkDelete(&msptr->channode, &chptr->members); - if(client_p->servptr == &me) - rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); + if(client_p->servptr == &me) + rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); - if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) - destroy_channel(chptr); + if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) + destroy_channel(chptr); - rb_bh_free(member_heap, msptr); - } + rb_bh_free(member_heap, msptr); + } - client_p->user->channel.head = client_p->user->channel.tail = NULL; - client_p->user->channel.length = 0; + client_p->user->channel.head = client_p->user->channel.tail = NULL; + client_p->user->channel.length = 0; } /* invalidate_bancache_user() @@ -451,18 +441,17 @@ remove_user_from_channels(struct Client *client_p) void invalidate_bancache_user(struct Client *client_p) { - struct membership *msptr; - rb_dlink_node *ptr; + struct membership *msptr; + rb_dlink_node *ptr; - if(client_p == NULL) - return; + if(client_p == NULL) + return; - RB_DLINK_FOREACH(ptr, client_p->user->channel.head) - { - msptr = ptr->data; - msptr->bants = 0; - msptr->flags &= ~CHFL_BANNED; - } + RB_DLINK_FOREACH(ptr, client_p->user->channel.head) { + msptr = ptr->data; + msptr->bants = 0; + msptr->flags &= ~CHFL_BANNED; + } } /* check_channel_name() @@ -474,17 +463,16 @@ invalidate_bancache_user(struct Client *client_p) int check_channel_name(const char *name) { - s_assert(name != NULL); - if(name == NULL) - return 0; + s_assert(name != NULL); + if(name == NULL) + return 0; - for (; *name; ++name) - { - if(!IsChanChar(*name)) - return 0; - } + for (; *name; ++name) { + if(!IsChanChar(*name)) + return 0; + } - return 1; + return 1; } /* free_channel_list() @@ -496,18 +484,17 @@ check_channel_name(const char *name) void free_channel_list(rb_dlink_list * list) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct Ban *actualBan; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct Ban *actualBan; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) - { - actualBan = ptr->data; - free_ban(actualBan); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) { + actualBan = ptr->data; + free_ban(actualBan); + } - list->head = list->tail = NULL; - list->length = 0; + list->head = list->tail = NULL; + list->length = 0; } /* destroy_channel() @@ -519,25 +506,24 @@ free_channel_list(rb_dlink_list * list) void destroy_channel(struct Channel *chptr) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) - { - del_invite(chptr, ptr->data); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) { + del_invite(chptr, ptr->data); + } - /* free all bans/exceptions/denies */ - free_channel_list(&chptr->banlist); - free_channel_list(&chptr->exceptlist); - free_channel_list(&chptr->invexlist); - free_channel_list(&chptr->quietlist); + /* free all bans/exceptions/denies */ + free_channel_list(&chptr->banlist); + free_channel_list(&chptr->exceptlist); + free_channel_list(&chptr->invexlist); + free_channel_list(&chptr->quietlist); - /* Free the topic */ - free_topic(chptr); + /* Free the topic */ + free_topic(chptr); - rb_dlinkDelete(&chptr->node, &global_channel_list); - del_from_channel_hash(chptr->chname, chptr); - free_channel(chptr); + rb_dlinkDelete(&chptr->node, &global_channel_list); + del_from_channel_hash(chptr->chname, chptr); + free_channel(chptr); } /* channel_pub_or_secret() @@ -549,11 +535,11 @@ destroy_channel(struct Channel *chptr) static const char * channel_pub_or_secret(struct Channel *chptr) { - if(PubChannel(chptr)) - return ("="); - else if(SecretChannel(chptr)) - return ("@"); - return ("*"); + if(PubChannel(chptr)) + return ("="); + else if(SecretChannel(chptr)) + return ("@"); + return ("*"); } /* channel_member_names() @@ -565,68 +551,64 @@ channel_pub_or_secret(struct Channel *chptr) void channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eon) { - struct membership *msptr; - struct Client *target_p; - rb_dlink_node *ptr; - char lbuf[BUFSIZE]; - char *t; - int mlen; - int tlen; - int cur_len; - int is_member; - int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX); + struct membership *msptr; + struct Client *target_p; + rb_dlink_node *ptr; + char lbuf[BUFSIZE]; + char *t; + int mlen; + int tlen; + int cur_len; + int is_member; + int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX); - if(ShowChannel(client_p, chptr)) - { - is_member = IsMember(client_p, chptr); + if(ShowChannel(client_p, chptr)) { + is_member = IsMember(client_p, chptr); - cur_len = mlen = rb_sprintf(lbuf, form_str(RPL_NAMREPLY), - me.name, client_p->name, - channel_pub_or_secret(chptr), chptr->chname); + cur_len = mlen = rb_sprintf(lbuf, form_str(RPL_NAMREPLY), + me.name, client_p->name, + channel_pub_or_secret(chptr), chptr->chname); - t = lbuf + cur_len; + t = lbuf + cur_len; - RB_DLINK_FOREACH(ptr, chptr->members.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH(ptr, chptr->members.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(IsInvisible(target_p) && !is_member) - continue; + if(IsInvisible(target_p) && !is_member) + continue; - /* space, possible "@+" prefix */ - if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3) - { - *(t - 1) = '\0'; - sendto_one(client_p, "%s", lbuf); - cur_len = mlen; - t = lbuf + mlen; - } + /* space, possible "@+" prefix */ + if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3) { + *(t - 1) = '\0'; + sendto_one(client_p, "%s", lbuf); + cur_len = mlen; + t = lbuf + mlen; + } - tlen = rb_sprintf(t, "%s%s ", find_channel_status(msptr, stack), - target_p->name); + tlen = rb_sprintf(t, "%s%s ", find_channel_status(msptr, stack), + target_p->name); - cur_len += tlen; - t += tlen; - } + cur_len += tlen; + t += tlen; + } - /* The old behaviour here was to always output our buffer, - * even if there are no clients we can show. This happens - * when a client does "NAMES" with no parameters, and all - * the clients on a -sp channel are +i. I dont see a good - * reason for keeping that behaviour, as it just wastes - * bandwidth. --anfl - */ - if(cur_len != mlen) - { - *(t - 1) = '\0'; - sendto_one(client_p, "%s", lbuf); - } - } + /* The old behaviour here was to always output our buffer, + * even if there are no clients we can show. This happens + * when a client does "NAMES" with no parameters, and all + * the clients on a -sp channel are +i. I dont see a good + * reason for keeping that behaviour, as it just wastes + * bandwidth. --anfl + */ + if(cur_len != mlen) { + *(t - 1) = '\0'; + sendto_one(client_p, "%s", lbuf); + } + } - if(show_eon) - sendto_one(client_p, form_str(RPL_ENDOFNAMES), - me.name, client_p->name, chptr->chname); + if(show_eon) + sendto_one(client_p, form_str(RPL_ENDOFNAMES), + me.name, client_p->name, chptr->chname); } /* del_invite() @@ -638,8 +620,8 @@ channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eo void del_invite(struct Channel *chptr, struct Client *who) { - rb_dlinkFindDestroy(who, &chptr->invites); - rb_dlinkFindDestroy(chptr, &who->user->invited); + rb_dlinkFindDestroy(who, &chptr->invites); + rb_dlinkFindDestroy(chptr, &who->user->invited); } /* is_banned() @@ -651,101 +633,88 @@ del_invite(struct Channel *chptr, struct Client *who) */ int is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr, - const char *s, const char *s2) + const char *s, const char *s2) { - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; - char *s3 = NULL; - rb_dlink_node *ptr; - struct Ban *actualBan = NULL; - struct Ban *actualExcept = NULL; + char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; + char *s3 = NULL; + rb_dlink_node *ptr; + struct Ban *actualBan = NULL; + struct Ban *actualExcept = NULL; - if(!MyClient(who)) - return 0; + if(!MyClient(who)) + return 0; - /* if the buffers havent been built, do it here */ - if(s == NULL) - { - rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); - rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); + /* if the buffers havent been built, do it here */ + if(s == NULL) { + rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); + rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); - s = src_host; - s2 = src_iphost; - } - if(who->localClient->mangledhost != NULL) - { - /* if host mangling mode enabled, also check their real host */ - if(!strcmp(who->host, who->localClient->mangledhost)) - { - rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); - s3 = src_althost; - } - /* if host mangling mode not enabled and no other spoof, - * also check the mangled form of their host */ - else if (!IsDynSpoof(who)) - { - rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); - s3 = src_althost; - } - } + s = src_host; + s2 = src_iphost; + } + if(who->localClient->mangledhost != NULL) { + /* if host mangling mode enabled, also check their real host */ + if(!strcmp(who->host, who->localClient->mangledhost)) { + rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); + s3 = src_althost; + } + /* if host mangling mode not enabled and no other spoof, + * also check the mangled form of their host */ + else if (!IsDynSpoof(who)) { + rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); + s3 = src_althost; + } + } - RB_DLINK_FOREACH(ptr, chptr->banlist.head) - { - actualBan = ptr->data; - if(match(actualBan->banstr, s) || - match(actualBan->banstr, s2) || - match_cidr(actualBan->banstr, s2) || - match_extban(actualBan->banstr, who, chptr, CHFL_BAN) || - (s3 != NULL && match(actualBan->banstr, s3))) - break; - else - actualBan = NULL; - } + RB_DLINK_FOREACH(ptr, chptr->banlist.head) { + actualBan = ptr->data; + if(match(actualBan->banstr, s) || + match(actualBan->banstr, s2) || + match_cidr(actualBan->banstr, s2) || + match_extban(actualBan->banstr, who, chptr, CHFL_BAN) || + (s3 != NULL && match(actualBan->banstr, s3))) + break; + else + actualBan = NULL; + } - if((actualBan != NULL) && ConfigChannel.use_except) - { - RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) - { - actualExcept = ptr->data; + if((actualBan != NULL) && ConfigChannel.use_except) { + RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) { + actualExcept = ptr->data; - /* theyre exempted.. */ - if(match(actualExcept->banstr, s) || - match(actualExcept->banstr, s2) || - match_cidr(actualExcept->banstr, s2) || - match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || - (s3 != NULL && match(actualExcept->banstr, s3))) - { - /* cache the fact theyre not banned */ - if(msptr != NULL) - { - msptr->bants = chptr->bants; - msptr->flags &= ~CHFL_BANNED; - } + /* theyre exempted.. */ + if(match(actualExcept->banstr, s) || + match(actualExcept->banstr, s2) || + match_cidr(actualExcept->banstr, s2) || + match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || + (s3 != NULL && match(actualExcept->banstr, s3))) { + /* cache the fact theyre not banned */ + if(msptr != NULL) { + msptr->bants = chptr->bants; + msptr->flags &= ~CHFL_BANNED; + } - return CHFL_EXCEPTION; - } - } - } + return CHFL_EXCEPTION; + } + } + } - /* cache the banned/not banned status */ - if(msptr != NULL) - { - msptr->bants = chptr->bants; + /* cache the banned/not banned status */ + if(msptr != NULL) { + msptr->bants = chptr->bants; - if(actualBan != NULL) - { - msptr->flags |= CHFL_BANNED; - return CHFL_BAN; - } - else - { - msptr->flags &= ~CHFL_BANNED; - return 0; - } - } + if(actualBan != NULL) { + msptr->flags |= CHFL_BANNED; + return CHFL_BAN; + } else { + msptr->flags &= ~CHFL_BANNED; + return 0; + } + } - return ((actualBan ? CHFL_BAN : 0)); + return ((actualBan ? CHFL_BAN : 0)); } /* is_quieted() @@ -757,101 +726,88 @@ is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr, */ int is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr, - const char *s, const char *s2) + const char *s, const char *s2) { - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; - char *s3 = NULL; - rb_dlink_node *ptr; - struct Ban *actualBan = NULL; - struct Ban *actualExcept = NULL; + char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; + char *s3 = NULL; + rb_dlink_node *ptr; + struct Ban *actualBan = NULL; + struct Ban *actualExcept = NULL; - if(!MyClient(who)) - return 0; + if(!MyClient(who)) + return 0; - /* if the buffers havent been built, do it here */ - if(s == NULL) - { - rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); - rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); + /* if the buffers havent been built, do it here */ + if(s == NULL) { + rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); + rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); - s = src_host; - s2 = src_iphost; - } - if(who->localClient->mangledhost != NULL) - { - /* if host mangling mode enabled, also check their real host */ - if(!strcmp(who->host, who->localClient->mangledhost)) - { - rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); - s3 = src_althost; - } - /* if host mangling mode not enabled and no other spoof, - * also check the mangled form of their host */ - else if (!IsDynSpoof(who)) - { - rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); - s3 = src_althost; - } - } + s = src_host; + s2 = src_iphost; + } + if(who->localClient->mangledhost != NULL) { + /* if host mangling mode enabled, also check their real host */ + if(!strcmp(who->host, who->localClient->mangledhost)) { + rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); + s3 = src_althost; + } + /* if host mangling mode not enabled and no other spoof, + * also check the mangled form of their host */ + else if (!IsDynSpoof(who)) { + rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); + s3 = src_althost; + } + } - RB_DLINK_FOREACH(ptr, chptr->quietlist.head) - { - actualBan = ptr->data; - if(match(actualBan->banstr, s) || - match(actualBan->banstr, s2) || - match_cidr(actualBan->banstr, s2) || - match_extban(actualBan->banstr, who, chptr, CHFL_QUIET) || - (s3 != NULL && match(actualBan->banstr, s3))) - break; - else - actualBan = NULL; - } + RB_DLINK_FOREACH(ptr, chptr->quietlist.head) { + actualBan = ptr->data; + if(match(actualBan->banstr, s) || + match(actualBan->banstr, s2) || + match_cidr(actualBan->banstr, s2) || + match_extban(actualBan->banstr, who, chptr, CHFL_QUIET) || + (s3 != NULL && match(actualBan->banstr, s3))) + break; + else + actualBan = NULL; + } - if((actualBan != NULL) && ConfigChannel.use_except) - { - RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) - { - actualExcept = ptr->data; + if((actualBan != NULL) && ConfigChannel.use_except) { + RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) { + actualExcept = ptr->data; - /* theyre exempted.. */ - if(match(actualExcept->banstr, s) || - match(actualExcept->banstr, s2) || - match_cidr(actualExcept->banstr, s2) || - match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || - (s3 != NULL && match(actualExcept->banstr, s3))) - { - /* cache the fact theyre not banned */ - if(msptr != NULL) - { - msptr->bants = chptr->bants; - msptr->flags &= ~CHFL_BANNED; - } + /* theyre exempted.. */ + if(match(actualExcept->banstr, s) || + match(actualExcept->banstr, s2) || + match_cidr(actualExcept->banstr, s2) || + match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || + (s3 != NULL && match(actualExcept->banstr, s3))) { + /* cache the fact theyre not banned */ + if(msptr != NULL) { + msptr->bants = chptr->bants; + msptr->flags &= ~CHFL_BANNED; + } - return CHFL_EXCEPTION; - } - } - } + return CHFL_EXCEPTION; + } + } + } - /* cache the banned/not banned status */ - if(msptr != NULL) - { - msptr->bants = chptr->bants; + /* cache the banned/not banned status */ + if(msptr != NULL) { + msptr->bants = chptr->bants; - if(actualBan != NULL) - { - msptr->flags |= CHFL_BANNED; - return CHFL_BAN; - } - else - { - msptr->flags &= ~CHFL_BANNED; - return 0; - } - } + if(actualBan != NULL) { + msptr->flags |= CHFL_BANNED; + return CHFL_BAN; + } else { + msptr->flags &= ~CHFL_BANNED; + return 0; + } + } - return ((actualBan ? CHFL_BAN : 0)); + return ((actualBan ? CHFL_BAN : 0)); } /* can_join() @@ -863,116 +819,105 @@ is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr, int can_join(struct Client *source_p, struct Channel *chptr, char *key) { - rb_dlink_node *invite = NULL; - rb_dlink_node *ptr; - struct Ban *invex = NULL; - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; - char text[10]; - int use_althost = 0; - int i = 0; - hook_data_channel moduledata; - struct Metadata *md; - struct DictionaryIter iter; + rb_dlink_node *invite = NULL; + rb_dlink_node *ptr; + struct Ban *invex = NULL; + char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; + char text[10]; + int use_althost = 0; + int i = 0; + hook_data_channel moduledata; + struct Metadata *md; + struct DictionaryIter iter; - s_assert(source_p->localClient != NULL); + s_assert(source_p->localClient != NULL); - rb_sprintf(src_host, "%s!%s@%s", source_p->name, source_p->username, source_p->host); - rb_sprintf(src_iphost, "%s!%s@%s", source_p->name, source_p->username, source_p->sockhost); - if(source_p->localClient->mangledhost != NULL) - { - /* if host mangling mode enabled, also check their real host */ - if(!strcmp(source_p->host, source_p->localClient->mangledhost)) - { - rb_sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->orighost); - use_althost = 1; - } - /* if host mangling mode not enabled and no other spoof, - * also check the mangled form of their host */ - else if (!IsDynSpoof(source_p)) - { - rb_sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->localClient->mangledhost); - use_althost = 1; - } - } + rb_sprintf(src_host, "%s!%s@%s", source_p->name, source_p->username, source_p->host); + rb_sprintf(src_iphost, "%s!%s@%s", source_p->name, source_p->username, source_p->sockhost); + if(source_p->localClient->mangledhost != NULL) { + /* if host mangling mode enabled, also check their real host */ + if(!strcmp(source_p->host, source_p->localClient->mangledhost)) { + rb_sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->orighost); + use_althost = 1; + } + /* if host mangling mode not enabled and no other spoof, + * also check the mangled form of their host */ + else if (!IsDynSpoof(source_p)) { + rb_sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->localClient->mangledhost); + use_althost = 1; + } + } - if((is_banned(chptr, source_p, NULL, src_host, src_iphost)) == CHFL_BAN) - return (ERR_BANNEDFROMCHAN); + if((is_banned(chptr, source_p, NULL, src_host, src_iphost)) == CHFL_BAN) + return (ERR_BANNEDFROMCHAN); - rb_snprintf(text, sizeof(text), "K%s", source_p->id); + rb_snprintf(text, sizeof(text), "K%s", source_p->id); - DICTIONARY_FOREACH(md, &iter, chptr->metadata) - { - if(!strcmp(md->value, "KICKNOREJOIN") && !strcmp(md->name, text) && (md->timevalue + 2 > rb_current_time())) - return ERR_KICKNOREJOIN; - /* cleanup any stale KICKNOREJOIN metadata we find while we're at it */ - if(!strcmp(md->value, "KICKNOREJOIN") && !(md->timevalue + 2 > rb_current_time())) - channel_metadata_delete(chptr, md->name, 0); - } + DICTIONARY_FOREACH(md, &iter, chptr->metadata) { + if(!strcmp(md->value, "KICKNOREJOIN") && !strcmp(md->name, text) && (md->timevalue + 2 > rb_current_time())) + return ERR_KICKNOREJOIN; + /* cleanup any stale KICKNOREJOIN metadata we find while we're at it */ + if(!strcmp(md->value, "KICKNOREJOIN") && !(md->timevalue + 2 > rb_current_time())) + channel_metadata_delete(chptr, md->name, 0); + } - if(chptr->mode.mode & MODE_INVITEONLY) - { - RB_DLINK_FOREACH(invite, source_p->user->invited.head) - { - if(invite->data == chptr) - break; - } - if(invite == NULL) - { - if(!ConfigChannel.use_invex) - return (ERR_INVITEONLYCHAN); - RB_DLINK_FOREACH(ptr, chptr->invexlist.head) - { - invex = ptr->data; - if(match(invex->banstr, src_host) - || match(invex->banstr, src_iphost) - || match_cidr(invex->banstr, src_iphost) - || match_extban(invex->banstr, source_p, chptr, CHFL_INVEX) - || (use_althost && match(invex->banstr, src_althost))) - break; - } - if(ptr == NULL) - return (ERR_INVITEONLYCHAN); - } - } + if(chptr->mode.mode & MODE_INVITEONLY) { + RB_DLINK_FOREACH(invite, source_p->user->invited.head) { + if(invite->data == chptr) + break; + } + if(invite == NULL) { + if(!ConfigChannel.use_invex) + return (ERR_INVITEONLYCHAN); + RB_DLINK_FOREACH(ptr, chptr->invexlist.head) { + invex = ptr->data; + if(match(invex->banstr, src_host) + || match(invex->banstr, src_iphost) + || match_cidr(invex->banstr, src_iphost) + || match_extban(invex->banstr, source_p, chptr, CHFL_INVEX) + || (use_althost && match(invex->banstr, src_althost))) + break; + } + if(ptr == NULL) + return (ERR_INVITEONLYCHAN); + } + } - if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key))) - return (ERR_BADCHANNELKEY); + if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key))) + return (ERR_BADCHANNELKEY); - if(chptr->mode.limit && - rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit) - i = ERR_CHANNELISFULL; - if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser)) - i = ERR_NEEDREGGEDNICK; - /* join throttling stuff --nenolod */ - else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) - { - if ((rb_current_time() - chptr->join_delta <= - chptr->mode.join_time) && (chptr->join_count >= - chptr->mode.join_num)) - i = ERR_THROTTLE; - } + if(chptr->mode.limit && + rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit) + i = ERR_CHANNELISFULL; + if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser)) + i = ERR_NEEDREGGEDNICK; + /* join throttling stuff --nenolod */ + else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) { + if ((rb_current_time() - chptr->join_delta <= + chptr->mode.join_time) && (chptr->join_count >= + chptr->mode.join_num)) + i = ERR_THROTTLE; + } - /* allow /invite to override +l/+r/+j also -- jilles */ - if (i != 0 && invite == NULL) - { - RB_DLINK_FOREACH(invite, source_p->user->invited.head) - { - if(invite->data == chptr) - break; - } - if (invite == NULL) - return i; - } + /* allow /invite to override +l/+r/+j also -- jilles */ + if (i != 0 && invite == NULL) { + RB_DLINK_FOREACH(invite, source_p->user->invited.head) { + if(invite->data == chptr) + break; + } + if (invite == NULL) + return i; + } - moduledata.client = source_p; - moduledata.chptr = chptr; - moduledata.approved = 0; + moduledata.client = source_p; + moduledata.chptr = chptr; + moduledata.approved = 0; - call_hook(h_can_join, &moduledata); + call_hook(h_can_join, &moduledata); - return moduledata.approved; + return moduledata.approved; } /* can_send() @@ -984,57 +929,52 @@ can_join(struct Client *source_p, struct Channel *chptr, char *key) int can_send(struct Channel *chptr, struct Client *source_p, struct membership *msptr) { - if(IsServer(source_p) || IsService(source_p)) - return CAN_SEND_OPV; + if(IsServer(source_p) || IsService(source_p)) + return CAN_SEND_OPV; - if(MyClient(source_p) && hash_find_resv(chptr->chname) && - !IsOper(source_p) && !IsExemptResv(source_p)) - return CAN_SEND_NO; + if(MyClient(source_p) && hash_find_resv(chptr->chname) && + !IsOper(source_p) && !IsExemptResv(source_p)) + return CAN_SEND_NO; - if(msptr == NULL) - { - msptr = find_channel_membership(chptr, source_p); + if(msptr == NULL) { + msptr = find_channel_membership(chptr, source_p); - if(msptr == NULL) - { - /* if its +m or +n and theyre not in the channel, - * they cant send. we dont check bans here because - * theres no possibility of caching them --fl - */ - if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED) - return CAN_SEND_NO; - else - return CAN_SEND_NONOP; - } - } + if(msptr == NULL) { + /* if its +m or +n and theyre not in the channel, + * they cant send. we dont check bans here because + * theres no possibility of caching them --fl + */ + if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED) + return CAN_SEND_NO; + else + return CAN_SEND_NONOP; + } + } - if(is_chanop_voiced(msptr)) - return CAN_SEND_OPV; + if(is_chanop_voiced(msptr)) + return CAN_SEND_OPV; - if(chptr->mode.mode & MODE_MODERATED) - return CAN_SEND_NO; + if(chptr->mode.mode & MODE_MODERATED) + return CAN_SEND_NO; - if(MyClient(source_p)) - { - /* cached can_send */ - if(msptr->bants == chptr->bants) - { - if(can_send_banned(msptr)) - return CAN_SEND_NO; - } - else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN - || is_quieted(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN) - return CAN_SEND_NO; - } + if(MyClient(source_p)) { + /* cached can_send */ + if(msptr->bants == chptr->bants) { + if(can_send_banned(msptr)) + return CAN_SEND_NO; + } else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN + || is_quieted(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN) + return CAN_SEND_NO; + } - return CAN_SEND_NONOP; + return CAN_SEND_NONOP; } /* * flood_attack_channel * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC * says NOTICE must not auto reply - * - pointer to source Client + * - pointer to source Client * - pointer to target channel * output - 1 if target is under flood attack * side effects - check for flood attack on target chptr @@ -1042,48 +982,42 @@ can_send(struct Channel *chptr, struct Client *source_p, struct membership *mspt int flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, char *chname) { - int delta; + int delta; - if(GlobalSetOptions.floodcount && MyClient(source_p) && (!IsOper(source_p) || !ConfigFileEntry.true_no_oper_flood)) - { - if((chptr->first_received_message_time + 1) < rb_current_time()) - { - delta = rb_current_time() - chptr->first_received_message_time; - chptr->received_number_of_privmsgs -= delta; - chptr->first_received_message_time = rb_current_time(); - if(chptr->received_number_of_privmsgs <= 0) - { - chptr->received_number_of_privmsgs = 0; - chptr->flood_noticed = 0; - } - } + if(GlobalSetOptions.floodcount && MyClient(source_p) && (!IsOper(source_p) || !ConfigFileEntry.true_no_oper_flood)) { + if((chptr->first_received_message_time + 1) < rb_current_time()) { + delta = rb_current_time() - chptr->first_received_message_time; + chptr->received_number_of_privmsgs -= delta; + chptr->first_received_message_time = rb_current_time(); + if(chptr->received_number_of_privmsgs <= 0) { + chptr->received_number_of_privmsgs = 0; + chptr->flood_noticed = 0; + } + } - if((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount) - || chptr->flood_noticed) - { - if(chptr->flood_noticed == 0) - { - sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE, - "Possible Flooder %s[%s@%s] on %s target: %s", - source_p->name, source_p->username, - source_p->orighost, - source_p->servptr->name, chptr->chname); - chptr->flood_noticed = 1; + if((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount) + || chptr->flood_noticed) { + if(chptr->flood_noticed == 0) { + sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE, + "Possible Flooder %s[%s@%s] on %s target: %s", + source_p->name, source_p->username, + source_p->orighost, + source_p->servptr->name, chptr->chname); + chptr->flood_noticed = 1; - /* Add a bit of penalty */ - chptr->received_number_of_privmsgs += 2; - } - if(MyClient(source_p) && (p_or_n != 1)) - sendto_one(source_p, - ":%s NOTICE %s :*** Message to %s throttled due to flooding", - me.name, source_p->name, chptr->chname); - return 1; - } - else - chptr->received_number_of_privmsgs++; - } + /* Add a bit of penalty */ + chptr->received_number_of_privmsgs += 2; + } + if(MyClient(source_p) && (p_or_n != 1)) + sendto_one(source_p, + ":%s NOTICE %s :*** Message to %s throttled due to flooding", + me.name, source_p->name, chptr->chname); + return 1; + } else + chptr->received_number_of_privmsgs++; + } - return 0; + return 0; } /* find_bannickchange_channel() @@ -1093,35 +1027,32 @@ flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, struct Channel * find_bannickchange_channel(struct Client *client_p) { - struct Channel *chptr; - struct membership *msptr; - rb_dlink_node *ptr; - char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; - char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; + struct Channel *chptr; + struct membership *msptr; + rb_dlink_node *ptr; + char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; + char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; - if (!MyClient(client_p) || IsOverride(client_p)) - return NULL; + if (!MyClient(client_p) || IsOverride(client_p)) + return NULL; - rb_sprintf(src_host, "%s!%s@%s", client_p->name, client_p->username, client_p->host); - rb_sprintf(src_iphost, "%s!%s@%s", client_p->name, client_p->username, client_p->sockhost); + rb_sprintf(src_host, "%s!%s@%s", client_p->name, client_p->username, client_p->host); + rb_sprintf(src_iphost, "%s!%s@%s", client_p->name, client_p->username, client_p->sockhost); - RB_DLINK_FOREACH(ptr, client_p->user->channel.head) - { - msptr = ptr->data; - chptr = msptr->chptr; - if (is_chanop_voiced(msptr)) - continue; - /* cached can_send */ - if (msptr->bants == chptr->bants) - { - if (can_send_banned(msptr)) - return chptr; - } - else if (is_banned(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN - || is_quieted(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN) - return chptr; - } - return NULL; + RB_DLINK_FOREACH(ptr, client_p->user->channel.head) { + msptr = ptr->data; + chptr = msptr->chptr; + if (is_chanop_voiced(msptr)) + continue; + /* cached can_send */ + if (msptr->bants == chptr->bants) { + if (can_send_banned(msptr)) + return chptr; + } else if (is_banned(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN + || is_quieted(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN) + return chptr; + } + return NULL; } /* find_nonickchange_channel() @@ -1131,21 +1062,20 @@ find_bannickchange_channel(struct Client *client_p) struct Channel * find_nonickchange_channel(struct Client *client_p) { - struct Channel *chptr; - struct membership *msptr; - rb_dlink_node *ptr; + struct Channel *chptr; + struct membership *msptr; + rb_dlink_node *ptr; - if (!MyClient(client_p)) - return NULL; + if (!MyClient(client_p)) + return NULL; - RB_DLINK_FOREACH(ptr, client_p->user->channel.head) - { - msptr = ptr->data; - chptr = msptr->chptr; - if (chptr->mode.mode & MODE_NONICK && (!ConfigChannel.exempt_cmode_N || !is_any_op(msptr))) - return chptr; - } - return NULL; + RB_DLINK_FOREACH(ptr, client_p->user->channel.head) { + msptr = ptr->data; + chptr = msptr->chptr; + if (chptr->mode.mode & MODE_NONICK && (!ConfigChannel.exempt_cmode_N || !is_any_op(msptr))) + return chptr; + } + return NULL; } /* void check_spambot_warning(struct Client *source_p) @@ -1158,54 +1088,46 @@ find_nonickchange_channel(struct Client *client_p) void check_spambot_warning(struct Client *source_p, const char *name) { - int t_delta; - int decrement_count; - if((GlobalSetOptions.spam_num && - (source_p->localClient->join_leave_count >= GlobalSetOptions.spam_num))) - { - if(source_p->localClient->oper_warn_count_down > 0) - source_p->localClient->oper_warn_count_down--; - else - source_p->localClient->oper_warn_count_down = 0; - if(source_p->localClient->oper_warn_count_down == 0 && - name != NULL) - { - /* Its already known as a possible spambot */ - sendto_realops_snomask(SNO_BOTS, L_NETWIDE, - "User %s (%s@%s) trying to join %s is a possible spambot", - source_p->name, - source_p->username, source_p->orighost, name); - source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; - } - } - else - { - if((t_delta = - (rb_current_time() - source_p->localClient->last_leave_time)) > - JOIN_LEAVE_COUNT_EXPIRE_TIME) - { - decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); - if(name != NULL) - ; - else if(decrement_count > source_p->localClient->join_leave_count) - source_p->localClient->join_leave_count = 0; - else - source_p->localClient->join_leave_count -= decrement_count; - } - else - { - if((rb_current_time() - - (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time) - { - /* oh, its a possible spambot */ - source_p->localClient->join_leave_count++; - } - } - if(name != NULL) - source_p->localClient->last_join_time = rb_current_time(); - else - source_p->localClient->last_leave_time = rb_current_time(); - } + int t_delta; + int decrement_count; + if((GlobalSetOptions.spam_num && + (source_p->localClient->join_leave_count >= GlobalSetOptions.spam_num))) { + if(source_p->localClient->oper_warn_count_down > 0) + source_p->localClient->oper_warn_count_down--; + else + source_p->localClient->oper_warn_count_down = 0; + if(source_p->localClient->oper_warn_count_down == 0 && + name != NULL) { + /* Its already known as a possible spambot */ + sendto_realops_snomask(SNO_BOTS, L_NETWIDE, + "User %s (%s@%s) trying to join %s is a possible spambot", + source_p->name, + source_p->username, source_p->orighost, name); + source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; + } + } else { + if((t_delta = + (rb_current_time() - source_p->localClient->last_leave_time)) > + JOIN_LEAVE_COUNT_EXPIRE_TIME) { + decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); + if(name != NULL) + ; + else if(decrement_count > source_p->localClient->join_leave_count) + source_p->localClient->join_leave_count = 0; + else + source_p->localClient->join_leave_count -= decrement_count; + } else { + if((rb_current_time() - + (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time) { + /* oh, its a possible spambot */ + source_p->localClient->join_leave_count++; + } + } + if(name != NULL) + source_p->localClient->last_join_time = rb_current_time(); + else + source_p->localClient->last_leave_time = rb_current_time(); + } } /* check_splitmode() @@ -1218,33 +1140,29 @@ check_spambot_warning(struct Client *source_p, const char *name) void check_splitmode(void *unused) { - if(splitchecking && (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split)) - { - /* not split, we're being asked to check now because someone - * has left - */ - if(!splitmode) - { - if(eob_count < split_servers || Count.total < split_users) - { - splitmode = 1; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Network split, activating splitmode"); - check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2); - } - } - /* in splitmode, check whether its finished */ - else if(eob_count >= split_servers && Count.total >= split_users) - { - splitmode = 0; + if(splitchecking && (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split)) { + /* not split, we're being asked to check now because someone + * has left + */ + if(!splitmode) { + if(eob_count < split_servers || Count.total < split_users) { + splitmode = 1; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Network split, activating splitmode"); + check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2); + } + } + /* in splitmode, check whether its finished */ + else if(eob_count >= split_servers && Count.total >= split_users) { + splitmode = 0; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Network rejoined, deactivating splitmode"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Network rejoined, deactivating splitmode"); - rb_event_delete(check_splitmode_ev); - check_splitmode_ev = NULL; - } - } + rb_event_delete(check_splitmode_ev); + check_splitmode_ev = NULL; + } + } } @@ -1257,21 +1175,21 @@ check_splitmode(void *unused) static void allocate_topic(struct Channel *chptr) { - void *ptr; + void *ptr; - if(chptr == NULL) - return; + if(chptr == NULL) + return; - ptr = rb_bh_alloc(topic_heap); + ptr = rb_bh_alloc(topic_heap); - /* Basically we allocate one large block for the topic and - * the topic info. We then split it up into two and shove it - * in the chptr - */ - chptr->topic = ptr; - chptr->topic_info = (char *) ptr + TOPICLEN + 1; - *chptr->topic = '\0'; - *chptr->topic_info = '\0'; + /* Basically we allocate one large block for the topic and + * the topic info. We then split it up into two and shove it + * in the chptr + */ + chptr->topic = ptr; + chptr->topic_info = (char *) ptr + TOPICLEN + 1; + *chptr->topic = '\0'; + *chptr->topic_info = '\0'; } /* free_topic() @@ -1283,18 +1201,18 @@ allocate_topic(struct Channel *chptr) static void free_topic(struct Channel *chptr) { - void *ptr; + void *ptr; - if(chptr == NULL || chptr->topic == NULL) - return; + if(chptr == NULL || chptr->topic == NULL) + return; - /* This is safe for now - If you change allocate_topic you - * MUST change this as well - */ - ptr = chptr->topic; - rb_bh_free(topic_heap, ptr); - chptr->topic = NULL; - chptr->topic_info = NULL; + /* This is safe for now - If you change allocate_topic you + * MUST change this as well + */ + ptr = chptr->topic; + rb_bh_free(topic_heap, ptr); + chptr->topic = NULL; + chptr->topic_info = NULL; } /* set_channel_topic() @@ -1306,24 +1224,21 @@ free_topic(struct Channel *chptr) void set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_info, time_t topicts) { - if(strlen(topic) > 0) - { - if(chptr->topic == NULL) - allocate_topic(chptr); - rb_strlcpy(chptr->topic, topic, TOPICLEN + 1); - rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); - chptr->topic_time = topicts; - } - else - { - if(chptr->topic != NULL) - free_topic(chptr); - chptr->topic_time = 0; - } + if(strlen(topic) > 0) { + if(chptr->topic == NULL) + allocate_topic(chptr); + rb_strlcpy(chptr->topic, topic, TOPICLEN + 1); + rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); + chptr->topic_time = topicts; + } else { + if(chptr->topic != NULL) + free_topic(chptr); + chptr->topic_time = 0; + } } /* has_common_channel() - * + * * input - pointer to client * - pointer to another client * output - 1 if the two have a channel in common, 0 elsewise @@ -1332,14 +1247,13 @@ set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_in int has_common_channel(struct Client *client1, struct Client *client2) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, client1->user->channel.head) - { - if(IsMember(client2, ((struct membership *)ptr->data)->chptr)) - return 1; - } - return 0; + RB_DLINK_FOREACH(ptr, client1->user->channel.head) { + if(IsMember(client2, ((struct membership *)ptr->data)->chptr)) + return 1; + } + return 0; } /* channel_modes() @@ -1354,62 +1268,57 @@ has_common_channel(struct Client *client1, struct Client *client2) const char * channel_modes(struct Channel *chptr, struct Client *client_p) { - int i; - char buf1[BUFSIZE]; - char buf2[BUFSIZE]; - static char final[BUFSIZE]; - char *mbuf = buf1; - char *pbuf = buf2; + int i; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + static char final[BUFSIZE]; + char *mbuf = buf1; + char *pbuf = buf2; - *mbuf++ = '+'; - *pbuf = '\0'; + *mbuf++ = '+'; + *pbuf = '\0'; - for (i = 0; i < 256; i++) - { - if(chmode_table[i].set_func == chm_hidden && !IsOper(client_p) && IsClient(client_p)) - continue; - if(chptr->mode.mode & chmode_flags[i]) - *mbuf++ = i; - } + for (i = 0; i < 256; i++) { + if(chmode_table[i].set_func == chm_hidden && !IsOper(client_p) && IsClient(client_p)) + continue; + if(chptr->mode.mode & chmode_flags[i]) + *mbuf++ = i; + } - if(chptr->mode.limit) - { - *mbuf++ = 'l'; + if(chptr->mode.limit) { + *mbuf++ = 'l'; - if(!IsClient(client_p) || IsMember(client_p, chptr)) - pbuf += rb_sprintf(pbuf, " %d", chptr->mode.limit); - } + if(!IsClient(client_p) || IsMember(client_p, chptr)) + pbuf += rb_sprintf(pbuf, " %d", chptr->mode.limit); + } - if(*chptr->mode.key) - { - *mbuf++ = 'k'; + if(*chptr->mode.key) { + *mbuf++ = 'k'; - if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) - pbuf += rb_sprintf(pbuf, " %s", chptr->mode.key); - } + if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) + pbuf += rb_sprintf(pbuf, " %s", chptr->mode.key); + } - if(chptr->mode.join_num) - { - *mbuf++ = 'j'; + if(chptr->mode.join_num) { + *mbuf++ = 'j'; - if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) - pbuf += rb_sprintf(pbuf, " %d:%d", chptr->mode.join_num, - chptr->mode.join_time); - } + if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) + pbuf += rb_sprintf(pbuf, " %d:%d", chptr->mode.join_num, + chptr->mode.join_time); + } - if(*chptr->mode.forward && (ConfigChannel.use_forward || !IsClient(client_p))) - { - *mbuf++ = 'f'; + if(*chptr->mode.forward && (ConfigChannel.use_forward || !IsClient(client_p))) { + *mbuf++ = 'f'; - if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) - pbuf += rb_sprintf(pbuf, " %s", chptr->mode.forward); - } + if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) + pbuf += rb_sprintf(pbuf, " %s", chptr->mode.forward); + } - *mbuf = '\0'; + *mbuf = '\0'; - rb_strlcpy(final, buf1, sizeof final); - rb_strlcat(final, buf2, sizeof final); - return final; + rb_strlcpy(final, buf1, sizeof final); + rb_strlcat(final, buf2, sizeof final); + return final; } /* Now lets do some stuff to keep track of what combinations of @@ -1433,24 +1342,22 @@ channel_modes(struct Channel *chptr, struct Client *client_p) void init_chcap_usage_counts(void) { - unsigned long m, c, y, n; + unsigned long m, c, y, n; - memset(chcap_combos, 0, sizeof(chcap_combos)); + memset(chcap_combos, 0, sizeof(chcap_combos)); - /* For every possible combination */ - for (m = 0; m < NCHCAP_COMBOS; m++) - { - /* Check each capab */ - for (c = y = n = 0; c < NCHCAPS; c++) - { - if((m & (1 << c)) == 0) - n |= channel_capabs[c]; - else - y |= channel_capabs[c]; - } - chcap_combos[m].cap_yes = y; - chcap_combos[m].cap_no = n; - } + /* For every possible combination */ + for (m = 0; m < NCHCAP_COMBOS; m++) { + /* Check each capab */ + for (c = y = n = 0; c < NCHCAPS; c++) { + if((m & (1 << c)) == 0) + n |= channel_capabs[c]; + else + y |= channel_capabs[c]; + } + chcap_combos[m].cap_yes = y; + chcap_combos[m].cap_no = n; + } } /* void set_chcap_usage_counts(struct Client *serv_p) @@ -1462,20 +1369,18 @@ init_chcap_usage_counts(void) void set_chcap_usage_counts(struct Client *serv_p) { - int n; + int n; - for (n = 0; n < NCHCAP_COMBOS; n++) - { - if(IsCapable(serv_p, chcap_combos[n].cap_yes) && - NotCapable(serv_p, chcap_combos[n].cap_no)) - { - chcap_combos[n].count++; - return; - } - } + for (n = 0; n < NCHCAP_COMBOS; n++) { + if(IsCapable(serv_p, chcap_combos[n].cap_yes) && + NotCapable(serv_p, chcap_combos[n].cap_no)) { + chcap_combos[n].count++; + return; + } + } - /* This should be impossible -A1kmm. */ - s_assert(0); + /* This should be impossible -A1kmm. */ + s_assert(0); } /* void set_chcap_usage_counts(struct Client *serv_p) @@ -1488,24 +1393,22 @@ set_chcap_usage_counts(struct Client *serv_p) void unset_chcap_usage_counts(struct Client *serv_p) { - int n; + int n; - for (n = 0; n < NCHCAP_COMBOS; n++) - { - if(IsCapable(serv_p, chcap_combos[n].cap_yes) && - NotCapable(serv_p, chcap_combos[n].cap_no)) - { - /* Hopefully capabs can't change dynamically or anything... */ - s_assert(chcap_combos[n].count > 0); + for (n = 0; n < NCHCAP_COMBOS; n++) { + if(IsCapable(serv_p, chcap_combos[n].cap_yes) && + NotCapable(serv_p, chcap_combos[n].cap_no)) { + /* Hopefully capabs can't change dynamically or anything... */ + s_assert(chcap_combos[n].count > 0); - if(chcap_combos[n].count > 0) - chcap_combos[n].count--; - return; - } - } + if(chcap_combos[n].count > 0) + chcap_combos[n].count--; + return; + } + } - /* This should be impossible -A1kmm. */ - s_assert(0); + /* This should be impossible -A1kmm. */ + s_assert(0); } /* void send_cap_mode_changes(struct Client *client_p, @@ -1522,164 +1425,156 @@ unset_chcap_usage_counts(struct Client *serv_p) */ void send_cap_mode_changes(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count) + struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count) { - static char modebuf[BUFSIZE]; - static char parabuf[BUFSIZE]; - int i, mbl, pbl, nc, mc, preflen, len; - char *pbuf; - const char *arg; - int dir; - int j; - int cap; - int nocap; - int arglen; + static char modebuf[BUFSIZE]; + static char parabuf[BUFSIZE]; + int i, mbl, pbl, nc, mc, preflen, len; + char *pbuf; + const char *arg; + int dir; + int j; + int cap; + int nocap; + int arglen; - /* Now send to servers... */ - for (j = 0; j < NCHCAP_COMBOS; j++) - { - if(chcap_combos[j].count == 0) - continue; + /* Now send to servers... */ + for (j = 0; j < NCHCAP_COMBOS; j++) { + if(chcap_combos[j].count == 0) + continue; - mc = 0; - nc = 0; - pbl = 0; - parabuf[0] = 0; - pbuf = parabuf; - dir = MODE_QUERY; + mc = 0; + nc = 0; + pbl = 0; + parabuf[0] = 0; + pbuf = parabuf; + dir = MODE_QUERY; - cap = chcap_combos[j].cap_yes; - nocap = chcap_combos[j].cap_no; + cap = chcap_combos[j].cap_yes; + nocap = chcap_combos[j].cap_no; - mbl = preflen = rb_sprintf(modebuf, ":%s TMODE %ld %s ", - use_id(source_p), (long) chptr->channelts, - chptr->chname); + mbl = preflen = rb_sprintf(modebuf, ":%s TMODE %ld %s ", + use_id(source_p), (long) chptr->channelts, + chptr->chname); - /* loop the list of - modes we have */ - for (i = 0; i < mode_count; i++) - { - /* if they dont support the cap we need, or they do support a cap they - * cant have, then dont add it to the modebuf.. that way they wont see - * the mode - */ - if((mode_changes[i].letter == 0) || - ((cap & mode_changes[i].caps) != mode_changes[i].caps) - || ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps)) - continue; + /* loop the list of - modes we have */ + for (i = 0; i < mode_count; i++) { + /* if they dont support the cap we need, or they do support a cap they + * cant have, then dont add it to the modebuf.. that way they wont see + * the mode + */ + if((mode_changes[i].letter == 0) || + ((cap & mode_changes[i].caps) != mode_changes[i].caps) + || ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps)) + continue; - if(!EmptyString(mode_changes[i].id)) - arg = mode_changes[i].id; - else - arg = mode_changes[i].arg; + if(!EmptyString(mode_changes[i].id)) + arg = mode_changes[i].id; + else + arg = mode_changes[i].arg; - if(arg) - { - arglen = strlen(arg); + if(arg) { + arglen = strlen(arg); - /* dont even think about it! --fl */ - if(arglen > MODEBUFLEN - 5) - continue; - } + /* dont even think about it! --fl */ + if(arglen > MODEBUFLEN - 5) + continue; + } - /* if we're creeping past the buf size, we need to send it and make - * another line for the other modes - * XXX - this could give away server topology with uids being - * different lengths, but not much we can do, except possibly break - * them as if they were the longest of the nick or uid at all times, - * which even then won't work as we don't always know the uid -A1kmm. - */ - if(arg && ((mc == MAXMODEPARAMSSERV) || - ((mbl + pbl + arglen + 4) > (BUFSIZE - 3)))) - { - if(nc != 0) - sendto_server(client_p, chptr, cap, nocap, - "%s %s", modebuf, parabuf); - nc = 0; - mc = 0; + /* if we're creeping past the buf size, we need to send it and make + * another line for the other modes + * XXX - this could give away server topology with uids being + * different lengths, but not much we can do, except possibly break + * them as if they were the longest of the nick or uid at all times, + * which even then won't work as we don't always know the uid -A1kmm. + */ + if(arg && ((mc == MAXMODEPARAMSSERV) || + ((mbl + pbl + arglen + 4) > (BUFSIZE - 3)))) { + if(nc != 0) + sendto_server(client_p, chptr, cap, nocap, + "%s %s", modebuf, parabuf); + nc = 0; + mc = 0; - mbl = preflen; - pbl = 0; - pbuf = parabuf; - parabuf[0] = 0; - dir = MODE_QUERY; - } + mbl = preflen; + pbl = 0; + pbuf = parabuf; + parabuf[0] = 0; + dir = MODE_QUERY; + } - if(dir != mode_changes[i].dir) - { - modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; - dir = mode_changes[i].dir; - } + if(dir != mode_changes[i].dir) { + modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; + dir = mode_changes[i].dir; + } - modebuf[mbl++] = mode_changes[i].letter; - modebuf[mbl] = 0; - nc++; + modebuf[mbl++] = mode_changes[i].letter; + modebuf[mbl] = 0; + nc++; - if(arg != NULL) - { - len = rb_sprintf(pbuf, "%s ", arg); - pbuf += len; - pbl += len; - mc++; - } - } + if(arg != NULL) { + len = rb_sprintf(pbuf, "%s ", arg); + pbuf += len; + pbl += len; + mc++; + } + } - if(pbl && parabuf[pbl - 1] == ' ') - parabuf[pbl - 1] = 0; + if(pbl && parabuf[pbl - 1] == ' ') + parabuf[pbl - 1] = 0; - if(nc != 0) - sendto_server(client_p, chptr, cap, nocap, "%s %s", modebuf, parabuf); - } + if(nc != 0) + sendto_server(client_p, chptr, cap, nocap, "%s %s", modebuf, parabuf); + } } -void +void resv_chan_forcepart(const char *name, const char *reason, int temp_time) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct Channel *chptr; - struct membership *msptr; - struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct Channel *chptr; + struct membership *msptr; + struct Client *target_p; - if(!ConfigChannel.resv_forcepart) - return; + if(!ConfigChannel.resv_forcepart) + return; - /* for each user on our server in the channel list - * send them a PART, and notify opers. - */ - chptr = find_channel(name); - if(chptr != NULL) - { - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + /* for each user on our server in the channel list + * send them a PART, and notify opers. + */ + chptr = find_channel(name); + if(chptr != NULL) { + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(IsExemptResv(target_p)) - continue; + if(IsExemptResv(target_p)) + continue; - sendto_server(target_p, chptr, CAP_TS6, NOCAPS, - ":%s PART %s", target_p->id, chptr->chname); + sendto_server(target_p, chptr, CAP_TS6, NOCAPS, + ":%s PART %s", target_p->id, chptr->chname); - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", - target_p->name, target_p->username, - target_p->host, chptr->chname, target_p->name); + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", + target_p->name, target_p->username, + target_p->host, chptr->chname, target_p->name); - remove_user_from_channel(msptr); + remove_user_from_channel(msptr); - /* notify opers & user they were removed from the channel */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Forced PART for %s!%s@%s from %s (%s)", - target_p->name, target_p->username, - target_p->host, name, reason); + /* notify opers & user they were removed from the channel */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Forced PART for %s!%s@%s from %s (%s)", + target_p->name, target_p->username, + target_p->host, name, reason); - if(temp_time > 0) - sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.", - name); - else - sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.", - name); - } - } + if(temp_time > 0) + sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.", + name); + else + sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.", + name); + } + } } /* Check what we will forward to, without sending any notices to the user @@ -1687,38 +1582,37 @@ resv_chan_forcepart(const char *name, const char *reason, int temp_time) */ struct Channel * check_forward(struct Client *source_p, struct Channel *chptr, - char *key) + char *key) { - int depth = 0, i; + int depth = 0, i; - /* User is +Q */ - if (IsNoForward(source_p)) - return NULL; + /* User is +Q */ + if (IsNoForward(source_p)) + return NULL; - while (depth < 16) - { - chptr = find_channel(chptr->mode.forward); - /* Can only forward to existing channels */ - if (chptr == NULL) - return NULL; - /* Already on there, show original error message */ - if (IsMember(source_p, chptr)) - return NULL; - /* Juped. Sending a warning notice would be unfair */ - if (hash_find_resv(chptr->chname)) - return NULL; - /* Don't forward to +Q channel */ - if (chptr->mode.mode & MODE_DISFORWARD) - return NULL; - i = can_join(source_p, chptr, key); - if (i == 0) - return chptr; - if (i != ERR_INVITEONLYCHAN && i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_CHANNELISFULL) - return NULL; - depth++; - } + while (depth < 16) { + chptr = find_channel(chptr->mode.forward); + /* Can only forward to existing channels */ + if (chptr == NULL) + return NULL; + /* Already on there, show original error message */ + if (IsMember(source_p, chptr)) + return NULL; + /* Juped. Sending a warning notice would be unfair */ + if (hash_find_resv(chptr->chname)) + return NULL; + /* Don't forward to +Q channel */ + if (chptr->mode.mode & MODE_DISFORWARD) + return NULL; + i = can_join(source_p, chptr, key); + if (i == 0) + return chptr; + if (i != ERR_INVITEONLYCHAN && i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_CHANNELISFULL) + return NULL; + depth++; + } - return NULL; + return NULL; } /* @@ -1732,355 +1626,317 @@ check_forward(struct Client *source_p, struct Channel *chptr, void do_join_0(struct Client *client_p, struct Client *source_p) { - struct membership *msptr; - struct Channel *chptr = NULL; - rb_dlink_node *ptr; + struct membership *msptr; + struct Channel *chptr = NULL; + rb_dlink_node *ptr; - /* Finish the flood grace period... */ - if(MyClient(source_p) && !IsFloodDone(source_p)) - flood_endgrace(source_p); + /* Finish the flood grace period... */ + if(MyClient(source_p) && !IsFloodDone(source_p)) + flood_endgrace(source_p); - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p)); + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p)); - while((ptr = source_p->user->channel.head)) - { - if(source_p->user->channel.head && MyConnect(source_p) && - !IsOper(source_p) && !IsExemptSpambot(source_p)) - check_spambot_warning(source_p, NULL); + while((ptr = source_p->user->channel.head)) { + if(source_p->user->channel.head && MyConnect(source_p) && + !IsOper(source_p) && !IsExemptSpambot(source_p)) + check_spambot_warning(source_p, NULL); - msptr = ptr->data; - chptr = msptr->chptr; - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", - source_p->name, - source_p->username, source_p->host, chptr->chname); - remove_user_from_channel(msptr); - } + msptr = ptr->data; + chptr = msptr->chptr; + sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", + source_p->name, + source_p->username, source_p->host, chptr->chname); + remove_user_from_channel(msptr); + } } int check_channel_name_loc(struct Client *source_p, const char *name) { - const char *p; + const char *p; - s_assert(name != NULL); - if(EmptyString(name)) - return 0; + s_assert(name != NULL); + if(EmptyString(name)) + return 0; - if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p)) - { - for(p = name; *p; ++p) - { - if(!IsChanChar(*p) || IsFakeChanChar(*p)) - return 0; - } - } - else - { - for(p = name; *p; ++p) - { - if(!IsChanChar(*p)) - return 0; - } - } + if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p)) { + for(p = name; *p; ++p) { + if(!IsChanChar(*p) || IsFakeChanChar(*p)) + return 0; + } + } else { + for(p = name; *p; ++p) { + if(!IsChanChar(*p)) + return 0; + } + } - if(ConfigChannel.only_ascii_channels) - { - for(p = name; *p; ++p) - if(*p < 33 || *p > 126) - return 0; + if(ConfigChannel.only_ascii_channels) { + for(p = name; *p; ++p) + if(*p < 33 || *p > 126) + return 0; } - return 1; + return 1; } void user_join(struct Client * client_p, struct Client * source_p, const char * channels, const char * keys) { - static char jbuf[BUFSIZE]; - struct Channel *chptr = NULL; - struct ConfItem *aconf; - char *name; - char *key = NULL; - const char *modes; - int i, flags = 0; - char *p = NULL, *p2 = NULL; - char *chanlist; - char *mykey; + static char jbuf[BUFSIZE]; + struct Channel *chptr = NULL; + struct ConfItem *aconf; + char *name; + char *key = NULL; + const char *modes; + int i, flags = 0; + char *p = NULL, *p2 = NULL; + char *chanlist; + char *mykey; - jbuf[0] = '\0'; + jbuf[0] = '\0'; - if(channels == NULL) - return; + if(channels == NULL) + return; - /* rebuild the list of channels theyre supposed to be joining. - * this code has a side effect of losing keys, but.. - */ - chanlist = LOCAL_COPY(channels); - for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) - { - /* check the length and name of channel is ok */ - if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN)) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), (unsigned char *) name); - continue; - } + /* rebuild the list of channels theyre supposed to be joining. + * this code has a side effect of losing keys, but.. + */ + chanlist = LOCAL_COPY(channels); + for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) { + /* check the length and name of channel is ok */ + if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN)) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), (unsigned char *) name); + continue; + } - /* join 0 parts all channels */ - if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) - { - (void) strcpy(jbuf, "0"); - continue; - } + /* join 0 parts all channels */ + if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) { + (void) strcpy(jbuf, "0"); + continue; + } - /* check it begins with # or &, and local chans are disabled */ - else if(!IsChannelName(name) || - ( !ConfigChannel.use_local_channels && name[0] == '&')) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), name); - continue; - } + /* check it begins with # or &, and local chans are disabled */ + else if(!IsChannelName(name) || + ( !ConfigChannel.use_local_channels && name[0] == '&')) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), name); + continue; + } - /* see if its resv'd */ - if(!IsExemptResv(source_p) && (aconf = hash_find_resv(name))) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), name); + /* see if its resv'd */ + if(!IsExemptResv(source_p) && (aconf = hash_find_resv(name))) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), name); - /* dont warn for opers */ - if(!IsExemptJupe(source_p) && !IsOper(source_p)) - sendto_realops_snomask(SNO_SPY, L_NETWIDE, - "User %s (%s@%s) is attempting to join locally juped channel %s (%s)", - source_p->name, source_p->username, - source_p->orighost, name, aconf->passwd); - /* dont update tracking for jupe exempt users, these - * are likely to be spamtrap leaves - */ - else if(IsExemptJupe(source_p)) - aconf->port--; + /* dont warn for opers */ + if(!IsExemptJupe(source_p) && !IsOper(source_p)) + sendto_realops_snomask(SNO_SPY, L_NETWIDE, + "User %s (%s@%s) is attempting to join locally juped channel %s (%s)", + source_p->name, source_p->username, + source_p->orighost, name, aconf->passwd); + /* dont update tracking for jupe exempt users, these + * are likely to be spamtrap leaves + */ + else if(IsExemptJupe(source_p)) + aconf->port--; - continue; - } + continue; + } - if(splitmode && !IsOper(source_p) && (*name != '&') && - ConfigChannel.no_join_on_split) - { - sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), - me.name, source_p->name, name); - continue; - } + if(splitmode && !IsOper(source_p) && (*name != '&') && + ConfigChannel.no_join_on_split) { + sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), + me.name, source_p->name, name); + continue; + } - if(*jbuf) - (void) strcat(jbuf, ","); - (void) rb_strlcat(jbuf, name, sizeof(jbuf)); - } + if(*jbuf) + (void) strcat(jbuf, ","); + (void) rb_strlcat(jbuf, name, sizeof(jbuf)); + } - if(keys != NULL) - { - mykey = LOCAL_COPY(keys); - key = rb_strtok_r(mykey, ",", &p2); - } + if(keys != NULL) { + mykey = LOCAL_COPY(keys); + key = rb_strtok_r(mykey, ",", &p2); + } - for(name = rb_strtok_r(jbuf, ",", &p); name; - key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p)) - { - hook_data_channel_activity hook_info; + for(name = rb_strtok_r(jbuf, ",", &p); name; + key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p)) { + hook_data_channel_activity hook_info; - /* JOIN 0 simply parts all channels the user is in */ - if(*name == '0' && !atoi(name)) - { - if(source_p->user->channel.head == NULL) - continue; + /* JOIN 0 simply parts all channels the user is in */ + if(*name == '0' && !atoi(name)) { + if(source_p->user->channel.head == NULL) + continue; - do_join_0(&me, source_p); - continue; - } + do_join_0(&me, source_p); + continue; + } - /* look for the channel */ - if((chptr = find_channel(name)) != NULL) - { - if(IsMember(source_p, chptr)) - continue; + /* look for the channel */ + if((chptr = find_channel(name)) != NULL) { + if(IsMember(source_p, chptr)) + continue; - flags = 0; - } - else - { - hook_data_client_approval moduledata; + flags = 0; + } else { + hook_data_client_approval moduledata; - moduledata.client = source_p; - moduledata.approved = 0; + moduledata.client = source_p; + moduledata.approved = 0; - call_hook(h_can_create_channel, &moduledata); + call_hook(h_can_create_channel, &moduledata); - if(moduledata.approved != 0) - { - sendto_one(source_p, form_str(moduledata.approved), - me.name, source_p->name, name); - continue; - } + if(moduledata.approved != 0) { + sendto_one(source_p, form_str(moduledata.approved), + me.name, source_p->name, name); + continue; + } - if(splitmode && !IsOper(source_p) && (*name != '&') && - ConfigChannel.no_create_on_split) - { - sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), - me.name, source_p->name, name); - continue; - } + if(splitmode && !IsOper(source_p) && (*name != '&') && + ConfigChannel.no_create_on_split) { + sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), + me.name, source_p->name, name); + continue; + } - if(ConfigChannel.admin_on_channel_create && ConfigChannel.use_admin) - flags = CHFL_ADMIN | CHFL_CHANOP; - else - flags = CHFL_CHANOP; - } + if(ConfigChannel.admin_on_channel_create && ConfigChannel.use_admin) + flags = CHFL_ADMIN | CHFL_CHANOP; + else + flags = CHFL_CHANOP; + } - if((rb_dlink_list_length(&source_p->user->channel) >= - (unsigned long) ConfigChannel.max_chans_per_user) && - (!IsOper(source_p) || - (rb_dlink_list_length(&source_p->user->channel) >= - (unsigned long) ConfigChannel.max_chans_per_user * 3))) - { - sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), - me.name, source_p->name, name); - continue; - } + if((rb_dlink_list_length(&source_p->user->channel) >= + (unsigned long) ConfigChannel.max_chans_per_user) && + (!IsOper(source_p) || + (rb_dlink_list_length(&source_p->user->channel) >= + (unsigned long) ConfigChannel.max_chans_per_user * 3))) { + sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), + me.name, source_p->name, name); + continue; + } - if(chptr == NULL) /* If I already have a chptr, no point doing this */ - { - chptr = get_or_create_channel(source_p, name, NULL); + if(chptr == NULL) { /* If I already have a chptr, no point doing this */ + chptr = get_or_create_channel(source_p, name, NULL); - if(chptr == NULL) - { - sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), - me.name, source_p->name, name); - continue; - } - } + if(chptr == NULL) { + sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), + me.name, source_p->name, name); + continue; + } + } - /* can_join checks for +i key, bans etc */ - if((i = can_join(source_p, chptr, key))) - { - if(IsOverride(source_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding JOIN to [%s]", - get_oper_name(source_p), chptr->chname); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding JOIN to [%s]", - me.name, get_oper_name(source_p), chptr->chname); - } - else if ((i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_INVITEONLYCHAN && i != ERR_CHANNELISFULL) || - (!ConfigChannel.use_forward || (chptr = check_forward(source_p, chptr, key)) == NULL)) - { - /* might be wrong, but is there any other better location for such? - * see extensions/chm_operonly.c for other comments on this - * -- dwr - */ - if(i != ERR_CUSTOM) - sendto_one(source_p, form_str(i), me.name, source_p->name, name); + /* can_join checks for +i key, bans etc */ + if((i = can_join(source_p, chptr, key))) { + if(IsOverride(source_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding JOIN to [%s]", + get_oper_name(source_p), chptr->chname); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding JOIN to [%s]", + me.name, get_oper_name(source_p), chptr->chname); + } else if ((i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_INVITEONLYCHAN && i != ERR_CHANNELISFULL) || + (!ConfigChannel.use_forward || (chptr = check_forward(source_p, chptr, key)) == NULL)) { + /* might be wrong, but is there any other better location for such? + * see extensions/chm_operonly.c for other comments on this + * -- dwr + */ + if(i != ERR_CUSTOM) + sendto_one(source_p, form_str(i), me.name, source_p->name, name); - continue; - } - else - sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr->chname); - } - - if(flags == 0 && - !IsOper(source_p) && !IsExemptSpambot(source_p)) - check_spambot_warning(source_p, name); + continue; + } else + sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr->chname); + } - /* add the user to the channel */ - add_user_to_channel(chptr, source_p, flags); - if (chptr->mode.join_num && - rb_current_time() - chptr->join_delta >= chptr->mode.join_time) - { - chptr->join_count = 0; - chptr->join_delta = rb_current_time(); - } - chptr->join_count++; + if(flags == 0 && + !IsOper(source_p) && !IsExemptSpambot(source_p)) + check_spambot_warning(source_p, name); - /* we send the user their join here, because we could have to - * send a mode out next. - */ - sendto_channel_local_with_capability(ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s", + /* add the user to the channel */ + add_user_to_channel(chptr, source_p, flags); + if (chptr->mode.join_num && + rb_current_time() - chptr->join_delta >= chptr->mode.join_time) { + chptr->join_count = 0; + chptr->join_delta = rb_current_time(); + } + chptr->join_count++; + + /* we send the user their join here, because we could have to + * send a mode out next. + */ + sendto_channel_local_with_capability(ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s", source_p->name, source_p->username, source_p->host, chptr->chname); - sendto_channel_local_with_capability(ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s %ld :%s", + sendto_channel_local_with_capability(ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s %ld :%s", source_p->name, source_p->username, source_p->host, chptr->chname, EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, source_p->tsinfo, source_p->info); - /* Send away message to away-notify enabled clients. */ -/* if (client_p->user && client_p->user->away) - sendto_channel_local_with_capability_butone(client_p, ALL_MEMBERS, CLICAP_AWAY_NOTIFY, NOCAPS, chptr, - ":%s!%s@%s AWAY :%s", client_p->name, client_p->username, - client_p->host, client_p->user->away);*/ + /* Send away message to away-notify enabled clients. */ + /* if (client_p->user && client_p->user->away) + sendto_channel_local_with_capability_butone(client_p, ALL_MEMBERS, CLICAP_AWAY_NOTIFY, NOCAPS, chptr, + ":%s!%s@%s AWAY :%s", client_p->name, client_p->username, + client_p->host, client_p->user->away);*/ - /* its a new channel, set +nt and burst. */ - if(flags & CHFL_CHANOP) - { - chptr->channelts = rb_current_time(); + /* its a new channel, set +nt and burst. */ + if(flags & CHFL_CHANOP) { + chptr->channelts = rb_current_time(); - /* autochanmodes stuff */ - if(ConfigChannel.autochanmodes) - { - char * ch; - for(ch = ConfigChannel.autochanmodes; *ch; *ch++) - { - chptr->mode.mode |= chmode_table[*ch].mode_type; - } - } - else - { - chptr->mode.mode |= MODE_TOPICLIMIT; - chptr->mode.mode |= MODE_NOPRIVMSGS; - } + /* autochanmodes stuff */ + if(ConfigChannel.autochanmodes) { + char * ch; + for(ch = ConfigChannel.autochanmodes; *ch; *ch++) { + chptr->mode.mode |= chmode_table[*ch].mode_type; + } + } else { + chptr->mode.mode |= MODE_TOPICLIMIT; + chptr->mode.mode |= MODE_NOPRIVMSGS; + } - modes = channel_modes(chptr, &me); + modes = channel_modes(chptr, &me); - sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s", - me.name, chptr->chname, modes); + sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s", + me.name, chptr->chname, modes); - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s SJOIN %ld %s %s :@%s", - me.id, (long) chptr->channelts, - chptr->chname, modes, source_p->id); - } - else - { - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s JOIN %ld %s +", - use_id(source_p), (long) chptr->channelts, - chptr->chname); - } + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s SJOIN %ld %s %s :@%s", + me.id, (long) chptr->channelts, + chptr->chname, modes, source_p->id); + } else { + sendto_server(client_p, chptr, CAP_TS6, NOCAPS, + ":%s JOIN %ld %s +", + use_id(source_p), (long) chptr->channelts, + chptr->chname); + } - del_invite(chptr, source_p); + del_invite(chptr, source_p); - if(chptr->topic != NULL) - { - sendto_one(source_p, form_str(RPL_TOPIC), me.name, - source_p->name, chptr->chname, chptr->topic); + if(chptr->topic != NULL) { + sendto_one(source_p, form_str(RPL_TOPIC), me.name, + source_p->name, chptr->chname, chptr->topic); - sendto_one(source_p, form_str(RPL_TOPICWHOTIME), - me.name, source_p->name, chptr->chname, - chptr->topic_info, chptr->topic_time); - } + sendto_one(source_p, form_str(RPL_TOPICWHOTIME), + me.name, source_p->name, chptr->chname, + chptr->topic_info, chptr->topic_time); + } - channel_member_names(chptr, source_p, 1); + channel_member_names(chptr, source_p, 1); - hook_info.client = source_p; - hook_info.chptr = chptr; - hook_info.key = key; - call_hook(h_channel_join, &hook_info); - } + hook_info.client = source_p; + hook_info.chptr = chptr; + hook_info.key = key; + call_hook(h_channel_join, &hook_info); + } - return; + return; } /* * channel_metadata_add - * + * * inputs - pointer to channel struct * - name of metadata item you wish to add * - value of metadata item @@ -2092,24 +1948,24 @@ void user_join(struct Client * client_p, struct Client * source_p, const char * struct Metadata * channel_metadata_add(struct Channel *target, const char *name, const char *value, int propagate) { - struct Metadata *md; + struct Metadata *md; - md = rb_malloc(sizeof(struct Metadata)); - md->name = rb_strdup(name); - md->value = rb_strdup(value); + md = rb_malloc(sizeof(struct Metadata)); + md->name = rb_strdup(name); + md->value = rb_strdup(value); - irc_dictionary_add(target->metadata, md->name, md); - - if(propagate) - sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA SET %s %s :%s", - target->chname, name, value); + irc_dictionary_add(target->metadata, md->name, md); - return md; + if(propagate) + sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA SET %s %s :%s", + target->chname, name, value); + + return md; } /* * channel_metadata_time_add - * + * * inputs - pointer to channel struct * - name of metadata item you wish to add * - time_t you wish to add @@ -2120,21 +1976,21 @@ channel_metadata_add(struct Channel *target, const char *name, const char *value struct Metadata * channel_metadata_time_add(struct Channel *target, const char *name, time_t timevalue, const char *value) { - struct Metadata *md; + struct Metadata *md; - md = rb_malloc(sizeof(struct Metadata)); - md->name = rb_strdup(name); - md->value = rb_strdup(value); - md->timevalue = timevalue; + md = rb_malloc(sizeof(struct Metadata)); + md->name = rb_strdup(name); + md->value = rb_strdup(value); + md->timevalue = timevalue; - irc_dictionary_add(target->metadata, md->name, md); + irc_dictionary_add(target->metadata, md->name, md); - return md; + return md; } /* * channel_metadata_delete - * + * * inputs - pointer to channel struct * - name of metadata item you wish to delete * output - none @@ -2144,43 +2000,43 @@ channel_metadata_time_add(struct Channel *target, const char *name, time_t timev void channel_metadata_delete(struct Channel *target, const char *name, int propagate) { - struct Metadata *md = channel_metadata_find(target, name); + struct Metadata *md = channel_metadata_find(target, name); - if(!md) - return; + if(!md) + return; - irc_dictionary_delete(target->metadata, md->name); + irc_dictionary_delete(target->metadata, md->name); - rb_free(md); + rb_free(md); - if(propagate) - sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA CLEAR %s %s", - target->chname, name); + if(propagate) + sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA CLEAR %s %s", + target->chname, name); } /* * channel_metadata_find - * + * * inputs - pointer to channel struct * - name of metadata item you wish to read * output - the requested metadata, if it exists, elsewise null. - * side effects - + * side effects - */ struct Metadata * channel_metadata_find(struct Channel *target, const char *name) { - if(!target) - return NULL; + if(!target) + return NULL; - if(!target->metadata) - return NULL; + if(!target->metadata) + return NULL; - return irc_dictionary_retrieve(target->metadata, name); + return irc_dictionary_retrieve(target->metadata, name); } /* * channel_metadata_clear - * + * * inputs - pointer to channel struct * output - none * side effects - metadata is cleared from the channel in question @@ -2188,11 +2044,10 @@ channel_metadata_find(struct Channel *target, const char *name) void channel_metadata_clear(struct Channel *chptr) { - struct Metadata *md; - struct DictionaryIter iter; - - DICTIONARY_FOREACH(md, &iter, chptr->metadata) - { - channel_metadata_delete(chptr, md->name, 0); - } + struct Metadata *md; + struct DictionaryIter iter; + + DICTIONARY_FOREACH(md, &iter, chptr->metadata) { + channel_metadata_delete(chptr, md->name, 0); + } } diff --git a/src/chmode.c b/src/chmode.c index d7318c3..0539f55 100644 --- a/src/chmode.c +++ b/src/chmode.c @@ -2,9 +2,9 @@ * charybdis: A slightly useful ircd. * chmode.c: channel mode management * - * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center - * Copyright (C) 1996-2002 Hybrid Development Team - * Copyright (C) 2002-2005 ircd-ratbox development team + * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center + * Copyright (C) 1996-2002 Hybrid Development Team + * Copyright (C) 2002-2005 ircd-ratbox development team * Copyright (C) 2005-2006 charybdis development team * * This program is free software; you can redistribute it and/or modify @@ -78,86 +78,77 @@ int chmode_flags[256]; void construct_cflags_strings(void) { - int i; - char *ptr = cflagsbuf; - char *ptr2 = cflagsmyinfo; - - *ptr = '\0'; - *ptr2 = '\0'; + int i; + char *ptr = cflagsbuf; + char *ptr2 = cflagsmyinfo; - for(i = 0; i < 256; i++) - { - if( !(chmode_table[i].set_func == chm_ban) && - !(chmode_table[i].set_func == chm_forward) && - !(chmode_table[i].set_func == chm_throttle) && - !(chmode_table[i].set_func == chm_key) && - !(chmode_table[i].set_func == chm_limit) && - !(chmode_table[i].set_func == chm_owner) && - !(chmode_table[i].set_func == chm_admin) && - !(chmode_table[i].set_func == chm_op) && - !(chmode_table[i].set_func == chm_halfop) && - !(chmode_table[i].set_func == chm_voice)) - { - chmode_flags[i] = chmode_table[i].mode_type; - } - else - { - chmode_flags[i] = 0; - } - - switch (chmode_flags[i]) - { - case MODE_EXLIMIT: - case MODE_DISFORWARD: - if(ConfigChannel.use_forward) - { - *ptr++ = (char) i; - } - - break; - case MODE_REGONLY: - if(rb_dlink_list_length(&service_list)) - { - *ptr++ = (char) i; - } + *ptr = '\0'; + *ptr2 = '\0'; - break; - default: - if(chmode_flags[i] != 0 && !(chmode_table[i].set_func == chm_orphaned)) - { - *ptr++ = (char) i; - } - } - - /* Should we leave orphaned check here? -- dwr */ - if( !(chmode_table[i].set_func == chm_nosuch) && - !(chmode_table[i].set_func == chm_orphaned) && - !(chmode_table[i].set_func == chm_owner && !ConfigChannel.use_owner) && - !(chmode_table[i].set_func == chm_admin && !ConfigChannel.use_admin) && - !(chmode_table[i].set_func == chm_halfop && !ConfigChannel.use_halfop)) - { - *ptr2++ = (char) i; - } - } - - *ptr++ = '\0'; - *ptr2++ = '\0'; + for(i = 0; i < 256; i++) { + if( !(chmode_table[i].set_func == chm_ban) && + !(chmode_table[i].set_func == chm_forward) && + !(chmode_table[i].set_func == chm_throttle) && + !(chmode_table[i].set_func == chm_key) && + !(chmode_table[i].set_func == chm_limit) && + !(chmode_table[i].set_func == chm_owner) && + !(chmode_table[i].set_func == chm_admin) && + !(chmode_table[i].set_func == chm_op) && + !(chmode_table[i].set_func == chm_halfop) && + !(chmode_table[i].set_func == chm_voice)) { + chmode_flags[i] = chmode_table[i].mode_type; + } else { + chmode_flags[i] = 0; + } + + switch (chmode_flags[i]) { + case MODE_EXLIMIT: + case MODE_DISFORWARD: + if(ConfigChannel.use_forward) { + *ptr++ = (char) i; + } + + break; + case MODE_REGONLY: + if(rb_dlink_list_length(&service_list)) { + *ptr++ = (char) i; + } + + break; + default: + if(chmode_flags[i] != 0 && !(chmode_table[i].set_func == chm_orphaned)) { + *ptr++ = (char) i; + } + } + + /* Should we leave orphaned check here? -- dwr */ + if( !(chmode_table[i].set_func == chm_nosuch) && + !(chmode_table[i].set_func == chm_orphaned) && + !(chmode_table[i].set_func == chm_owner && !ConfigChannel.use_owner) && + !(chmode_table[i].set_func == chm_admin && !ConfigChannel.use_admin) && + !(chmode_table[i].set_func == chm_halfop && !ConfigChannel.use_halfop)) { + *ptr2++ = (char) i; + } + } + + *ptr++ = '\0'; + *ptr2++ = '\0'; } void construct_cflag_param_string(void) { - *cflagsparaminfo = '\0'; - rb_snprintf(cflagsparaminfo, sizeof cflagsparaminfo, "%s%sb%s%s%s%sklov%s%s", - ConfigChannel.use_owner ? "y" : "", - ConfigChannel.use_admin ? "a" : "", - ConfigChannel.use_except ? "e" : "", - ConfigChannel.use_forward ? "f" : "", - ConfigChannel.use_halfop ? "h" : "", - strchr(ConfigChannel.disabledmodes, 'j') ? "" : "j", - strchr(ConfigChannel.disabledmodes, 'q') ? "" : "q", - ConfigChannel.use_invex ? "I" : ""); + *cflagsparaminfo = '\0'; + rb_snprintf(cflagsparaminfo, sizeof cflagsparaminfo, "%s%sb%s%s%s%sklov%s%s", + ConfigChannel.use_owner ? "y" : "", + ConfigChannel.use_admin ? "a" : "", + ConfigChannel.use_except ? "e" : "", + ConfigChannel.use_forward ? "f" : "", + ConfigChannel.use_halfop ? "h" : "", + strchr(ConfigChannel.disabledmodes, 'j') ? "" : "j", + strchr(ConfigChannel.disabledmodes, 'q') ? "" : "q", + ConfigChannel.use_invex ? "I" : ""); } /* @@ -171,58 +162,58 @@ construct_cflag_param_string(void) static unsigned int find_cflag_slot(void) { - unsigned int all_cflags = 0, my_cflag = 0, i; + unsigned int all_cflags = 0, my_cflag = 0, i; - for (i = 0; i < 256; i++) - all_cflags |= chmode_flags[i]; + for (i = 0; i < 256; i++) + all_cflags |= chmode_flags[i]; - for (my_cflag = 1; my_cflag && (all_cflags & my_cflag); - my_cflag <<= 1); + for (my_cflag = 1; my_cflag && (all_cflags & my_cflag); + my_cflag <<= 1); - return my_cflag; + return my_cflag; } unsigned int cflag_add(char c_, ChannelModeFunc function) { - int c = (unsigned char)c_; + int c = (unsigned char)c_; - if (chmode_table[c].set_func != chm_nosuch && - chmode_table[c].set_func != chm_orphaned) - return 0; + if (chmode_table[c].set_func != chm_nosuch && + chmode_table[c].set_func != chm_orphaned) + return 0; - if (chmode_table[c].set_func == chm_nosuch) - chmode_table[c].mode_type = find_cflag_slot(); - if (chmode_table[c].mode_type == 0) - return 0; - chmode_table[c].set_func = function; - construct_cflags_strings(); - return chmode_table[c].mode_type; + if (chmode_table[c].set_func == chm_nosuch) + chmode_table[c].mode_type = find_cflag_slot(); + if (chmode_table[c].mode_type == 0) + return 0; + chmode_table[c].set_func = function; + construct_cflags_strings(); + return chmode_table[c].mode_type; } void cflag_orphan(char c_) { - int c = (unsigned char)c_; + int c = (unsigned char)c_; - s_assert(chmode_flags[c] != 0); - chmode_table[c].set_func = chm_orphaned; - construct_cflags_strings(); + s_assert(chmode_flags[c] != 0); + chmode_table[c].set_func = chm_orphaned; + construct_cflags_strings(); } static int get_channel_access(struct Client *source_p, struct membership *msptr) { - if(!MyClient(source_p) || is_owner(msptr)) - return CHFL_OWNER; - else if(is_admin(msptr)) - return CHFL_ADMIN; - else if(is_chanop(msptr)) - return CHFL_CHANOP; - else if(is_halfop(msptr)) - return CHFL_HALFOP; + if(!MyClient(source_p) || is_owner(msptr)) + return CHFL_OWNER; + else if(is_admin(msptr)) + return CHFL_ADMIN; + else if(is_chanop(msptr)) + return CHFL_CHANOP; + else if(is_halfop(msptr)) + return CHFL_HALFOP; - return CHFL_PEON; + return CHFL_PEON; } /* add_id() @@ -235,57 +226,52 @@ int add_id(struct Client *source_p, struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type) { - struct Ban *actualBan; - static char who[USERHOST_REPLYLEN]; - char *realban = LOCAL_COPY(banid); - rb_dlink_node *ptr; + struct Ban *actualBan; + static char who[USERHOST_REPLYLEN]; + char *realban = LOCAL_COPY(banid); + rb_dlink_node *ptr; - /* dont let local clients overflow the banlist, or set redundant - * bans - */ - if(MyClient(source_p)) - { - if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans)) - { - sendto_one(source_p, form_str(ERR_BANLISTFULL), - me.name, source_p->name, chptr->chname, realban); - return 0; - } + /* dont let local clients overflow the banlist, or set redundant + * bans + */ + if(MyClient(source_p)) { + if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans)) { + sendto_one(source_p, form_str(ERR_BANLISTFULL), + me.name, source_p->name, chptr->chname, realban); + return 0; + } - RB_DLINK_FOREACH(ptr, list->head) - { - actualBan = ptr->data; - if(mask_match(actualBan->banstr, realban)) - return 0; - } - } - /* dont let remotes set duplicates */ - else - { - RB_DLINK_FOREACH(ptr, list->head) - { - actualBan = ptr->data; - if(!irccmp(actualBan->banstr, realban)) - return 0; - } - } + RB_DLINK_FOREACH(ptr, list->head) { + actualBan = ptr->data; + if(mask_match(actualBan->banstr, realban)) + return 0; + } + } + /* dont let remotes set duplicates */ + else { + RB_DLINK_FOREACH(ptr, list->head) { + actualBan = ptr->data; + if(!irccmp(actualBan->banstr, realban)) + return 0; + } + } - if(IsPerson(source_p)) - rb_sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host); - else - rb_strlcpy(who, source_p->name, sizeof(who)); + if(IsPerson(source_p)) + rb_sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host); + else + rb_strlcpy(who, source_p->name, sizeof(who)); - actualBan = allocate_ban(realban, who); - actualBan->when = rb_current_time(); + actualBan = allocate_ban(realban, who); + actualBan->when = rb_current_time(); - rb_dlinkAdd(actualBan, &actualBan->node, list); + rb_dlinkAdd(actualBan, &actualBan->node, list); - /* invalidate the can_send() cache */ - if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) - chptr->bants++; + /* invalidate the can_send() cache */ + if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) + chptr->bants++; - return 1; + return 1; } /* del_id() @@ -297,30 +283,28 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, int del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type) { - rb_dlink_node *ptr; - struct Ban *banptr; + rb_dlink_node *ptr; + struct Ban *banptr; - if(EmptyString(banid)) - return 0; + if(EmptyString(banid)) + return 0; - RB_DLINK_FOREACH(ptr, list->head) - { - banptr = ptr->data; + RB_DLINK_FOREACH(ptr, list->head) { + banptr = ptr->data; - if(irccmp(banid, banptr->banstr) == 0) - { - rb_dlinkDelete(&banptr->node, list); - free_ban(banptr); + if(irccmp(banid, banptr->banstr) == 0) { + rb_dlinkDelete(&banptr->node, list); + free_ban(banptr); - /* invalidate the can_send() cache */ - if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) - chptr->bants++; + /* invalidate the can_send() cache */ + if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) + chptr->bants++; - return 1; - } - } + return 1; + } + } - return 0; + return 0; } /* check_string() @@ -332,20 +316,18 @@ del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode static char * check_string(char *s) { - char *str = s; - static char splat[] = "*"; - if(!(s && *s)) - return splat; + char *str = s; + static char splat[] = "*"; + if(!(s && *s)) + return splat; - for(; *s; ++s) - { - if(IsSpace(*s)) - { - *s = '\0'; - break; - } - } - return str; + for(; *s; ++s) { + if(IsSpace(*s)) { + *s = '\0'; + break; + } + } + return str; } /* pretty_mask() @@ -362,112 +344,98 @@ check_string(char *s) static char * pretty_mask(const char *idmask) { - static char mask_buf[BUFSIZE]; - int old_mask_pos; - char *nick, *user, *host; - char splat[] = "*"; - char *t, *at, *ex; - char ne = 0, ue = 0, he = 0; /* save values at nick[NICKLEN], et all */ - char *mask; + static char mask_buf[BUFSIZE]; + int old_mask_pos; + char *nick, *user, *host; + char splat[] = "*"; + char *t, *at, *ex; + char ne = 0, ue = 0, he = 0; /* save values at nick[NICKLEN], et all */ + char *mask; - mask = LOCAL_COPY(idmask); - mask = check_string(mask); - collapse(mask); + mask = LOCAL_COPY(idmask); + mask = check_string(mask); + collapse(mask); - nick = user = host = splat; + nick = user = host = splat; - if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5) - return NULL; + if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5) + return NULL; - old_mask_pos = mask_pos; + old_mask_pos = mask_pos; - if (*mask == '$') - { - mask_pos += rb_sprintf(mask_buf + mask_pos, "%s", mask) + 1; - t = mask_buf + old_mask_pos + 1; - if (*t == '!') - *t = '~'; - if (*t == '~') - t++; - *t = ToLower(*t); - return mask_buf + old_mask_pos; - } + if (*mask == '$') { + mask_pos += rb_sprintf(mask_buf + mask_pos, "%s", mask) + 1; + t = mask_buf + old_mask_pos + 1; + if (*t == '!') + *t = '~'; + if (*t == '~') + t++; + *t = ToLower(*t); + return mask_buf + old_mask_pos; + } - at = ex = NULL; - if((t = strchr(mask, '@')) != NULL) - { - at = t; - *t++ = '\0'; - if(*t != '\0') - host = t; + at = ex = NULL; + if((t = strchr(mask, '@')) != NULL) { + at = t; + *t++ = '\0'; + if(*t != '\0') + host = t; - if((t = strchr(mask, '!')) != NULL) - { - ex = t; - *t++ = '\0'; - if(*t != '\0') - user = t; - if(*mask != '\0') - nick = mask; - } - else - { - if(*mask != '\0') - user = mask; - } - } - else if((t = strchr(mask, '!')) != NULL) - { - ex = t; - *t++ = '\0'; - if(*mask != '\0') - nick = mask; - if(*t != '\0') - user = t; - } - else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL || strchr(mask, '/') != NULL) - { - if(*mask != '\0') - host = mask; - } - else - { - if(*mask != '\0') - nick = mask; - } + if((t = strchr(mask, '!')) != NULL) { + ex = t; + *t++ = '\0'; + if(*t != '\0') + user = t; + if(*mask != '\0') + nick = mask; + } else { + if(*mask != '\0') + user = mask; + } + } else if((t = strchr(mask, '!')) != NULL) { + ex = t; + *t++ = '\0'; + if(*mask != '\0') + nick = mask; + if(*t != '\0') + user = t; + } else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL || strchr(mask, '/') != NULL) { + if(*mask != '\0') + host = mask; + } else { + if(*mask != '\0') + nick = mask; + } - /* truncate values to max lengths */ - if(strlen(nick) > NICKLEN - 1) - { - ne = nick[NICKLEN - 1]; - nick[NICKLEN - 1] = '\0'; - } - if(strlen(user) > USERLEN) - { - ue = user[USERLEN]; - user[USERLEN] = '\0'; - } - if(strlen(host) > HOSTLEN) - { - he = host[HOSTLEN]; - host[HOSTLEN] = '\0'; - } + /* truncate values to max lengths */ + if(strlen(nick) > NICKLEN - 1) { + ne = nick[NICKLEN - 1]; + nick[NICKLEN - 1] = '\0'; + } + if(strlen(user) > USERLEN) { + ue = user[USERLEN]; + user[USERLEN] = '\0'; + } + if(strlen(host) > HOSTLEN) { + he = host[HOSTLEN]; + host[HOSTLEN] = '\0'; + } - mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1; + mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1; - /* restore mask, since we may need to use it again later */ - if(at) - *at = '@'; - if(ex) - *ex = '!'; - if(ne) - nick[NICKLEN - 1] = ne; - if(ue) - user[USERLEN] = ue; - if(he) - host[HOSTLEN] = he; + /* restore mask, since we may need to use it again later */ + if(at) + *at = '@'; + if(ex) + *ex = '!'; + if(ne) + nick[NICKLEN - 1] = ne; + if(ue) + user[USERLEN] = ue; + if(he) + host[HOSTLEN] = he; - return mask_buf + old_mask_pos; + return mask_buf + old_mask_pos; } /* fix_key() @@ -480,17 +448,16 @@ pretty_mask(const char *idmask) static char * fix_key(char *arg) { - u_char *s, *t, c; + u_char *s, *t, c; - for(s = t = (u_char *) arg; (c = *s); s++) - { - c &= 0x7f; - if(c != ':' && c != ',' && c > ' ') - *t++ = c; - } + for(s = t = (u_char *) arg; (c = *s); s++) { + c &= 0x7f; + if(c != ':' && c != ',' && c > ' ') + *t++ = c; + } - *t = '\0'; - return arg; + *t = '\0'; + return arg; } /* fix_key_remote() @@ -503,17 +470,16 @@ fix_key(char *arg) static char * fix_key_remote(char *arg) { - u_char *s, *t, c; + u_char *s, *t, c; - for(s = t = (u_char *) arg; (c = *s); s++) - { - c &= 0x7f; - if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' ')) - *t++ = c; - } + for(s = t = (u_char *) arg; (c = *s); s++) { + c &= 0x7f; + if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' ')) + *t++ = c; + } - *t = '\0'; - return arg; + *t = '\0'; + return arg; } /* chm_*() @@ -522,490 +488,449 @@ fix_key_remote(char *arg) */ void chm_nosuch(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - if(*errors & SM_ERR_UNKNOWN) - return; - *errors |= SM_ERR_UNKNOWN; - sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); + if(*errors & SM_ERR_UNKNOWN) + return; + *errors |= SM_ERR_UNKNOWN; + sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); } void chm_simple(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - int override = 0; - struct Metadata *md; - struct DictionaryIter iter; - - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if (IsOverride(source_p)) - override = 1; - else - { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + int override = 0; + struct Metadata *md; + struct DictionaryIter iter; - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if (IsOverride(source_p)) + override = 1; + else { + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - /* setting + */ - if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) - { - /* if +f is disabled, ignore an attempt to set +QF locally */ - if(!ConfigChannel.use_forward && MyClient(source_p) && - (c == 'Q' || c == 'F')) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - chptr->mode.mode |= mode_type; + /* setting + */ + if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { + /* if +f is disabled, ignore an attempt to set +QF locally */ + if(!ConfigChannel.use_forward && MyClient(source_p) && + (c == 'Q' || c == 'F')) + return; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = NULL; - } - else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) - { - /* cleanup metadata when the related mode is removed */ - if(c == 'J') - { - DICTIONARY_FOREACH(md, &iter, chptr->metadata) - { - if(!strcmp(md->value, "KICKNOREJOIN")) - channel_metadata_delete(chptr, md->name, 0); - } - } - if(c == 'K') - channel_metadata_delete(chptr, "NOREPEAT", 0); + chptr->mode.mode |= mode_type; - chptr->mode.mode &= ~mode_type; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = NULL; + } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { + /* cleanup metadata when the related mode is removed */ + if(c == 'J') { + DICTIONARY_FOREACH(md, &iter, chptr->metadata) { + if(!strcmp(md->value, "KICKNOREJOIN")) + channel_metadata_delete(chptr, md->name, 0); + } + } + if(c == 'K') + channel_metadata_delete(chptr, "NOREPEAT", 0); - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = NULL; - } + chptr->mode.mode &= ~mode_type; + + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = NULL; + } } void chm_orphaned(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - if(MyClient(source_p)) - { - sendto_one_numeric(source_p, 469, "Mode %c is disabled.", c); - return; - } - - if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) - { - chptr->mode.mode |= mode_type; + if(MyClient(source_p)) { + sendto_one_numeric(source_p, 469, "Mode %c is disabled.", c); + return; + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count++].arg = NULL; - } - else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) - { - chptr->mode.mode &= ~mode_type; + if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { + chptr->mode.mode |= mode_type; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count++].arg = NULL; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count++].arg = NULL; + } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { + chptr->mode.mode &= ~mode_type; + + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count++].arg = NULL; + } } void chm_hidden(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - if(!IsOper(source_p) && !IsServer(source_p)) - { - if(!(*errors & SM_ERR_NOPRIVS)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); - *errors |= SM_ERR_NOPRIVS; - return; - } - if(MyClient(source_p) && !IsOperAdmin(source_p)) - { - if(!(*errors & SM_ERR_NOPRIVS)) - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, - source_p->name, "cmodes"); - *errors |= SM_ERR_NOPRIVS; - return; - } + if(!IsOper(source_p) && !IsServer(source_p)) { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); + *errors |= SM_ERR_NOPRIVS; + return; + } + if(MyClient(source_p) && !IsOperAdmin(source_p)) { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, + source_p->name, "cmodes"); + *errors |= SM_ERR_NOPRIVS; + return; + } - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - /* setting + */ - if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) - { - chptr->mode.mode |= mode_type; + /* setting + */ + if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { + chptr->mode.mode |= mode_type; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].mems = ONLY_OPERS; - mode_changes[mode_count].override = 0; - mode_changes[mode_count++].arg = NULL; - - ilog(L_MAIN, "+%c set on [%s] by %s", - c, chptr->chname, get_oper_name(source_p)); - - /* A little ugly */ - if (MyClient(source_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "+%c set on [%s] by %s!%s@%s", - c, chptr->chname, source_p->name, source_p->username, source_p->host); + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].mems = ONLY_OPERS; + mode_changes[mode_count].override = 0; + mode_changes[mode_count++].arg = NULL; - if(*chptr->chname != '&') - sendto_server(NULL, NULL, NOCAPS, NOCAPS, - ":%s WALLOPS :+%c set on [%s] by %s!%s@%s", - me.name, c, chptr->chname, source_p->name, source_p->username, - source_p->host); - } - } - else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) - { - chptr->mode.mode &= ~mode_type; + ilog(L_MAIN, "+%c set on [%s] by %s", + c, chptr->chname, get_oper_name(source_p)); - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ONLY_OPERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = 0; - mode_changes[mode_count++].arg = NULL; - - ilog(L_MAIN, "+%c unset from [%s] by %s", - c, chptr->chname, get_oper_name(source_p)); - - /* A little ugly */ - if (MyClient(source_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "+%c unset from [%s] by %s!%s@%s", - c, chptr->chname, source_p->name, source_p->username, source_p->host); + /* A little ugly */ + if (MyClient(source_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "+%c set on [%s] by %s!%s@%s", + c, chptr->chname, source_p->name, source_p->username, source_p->host); - if(*chptr->chname != '&') - sendto_server(NULL, NULL, NOCAPS, NOCAPS, - ":%s WALLOPS :+%c unset from [%s] by %s!%s@%s", - me.name, c, chptr->chname, source_p->name, source_p->username, - source_p->host); - } - } + if(*chptr->chname != '&') + sendto_server(NULL, NULL, NOCAPS, NOCAPS, + ":%s WALLOPS :+%c set on [%s] by %s!%s@%s", + me.name, c, chptr->chname, source_p->name, source_p->username, + source_p->host); + } + } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { + chptr->mode.mode &= ~mode_type; + + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ONLY_OPERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = 0; + mode_changes[mode_count++].arg = NULL; + + ilog(L_MAIN, "+%c unset from [%s] by %s", + c, chptr->chname, get_oper_name(source_p)); + + /* A little ugly */ + if (MyClient(source_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "+%c unset from [%s] by %s!%s@%s", + c, chptr->chname, source_p->name, source_p->username, source_p->host); + + if(*chptr->chname != '&') + sendto_server(NULL, NULL, NOCAPS, NOCAPS, + ":%s WALLOPS :+%c unset from [%s] by %s!%s@%s", + me.name, c, chptr->chname, source_p->name, source_p->username, + source_p->host); + } + } } void chm_staff(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - int override = 0; + int override = 0; - if(!IsOper(source_p) && !IsServer(source_p)) - { - if(!(*errors & SM_ERR_NOPRIVS)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); - *errors |= SM_ERR_NOPRIVS; - return; - } - if(MyClient(source_p) && !IsOperResv(source_p)) - { - if(!(*errors & SM_ERR_NOPRIVS)) - sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, - source_p->name, "resv"); - *errors |= SM_ERR_NOPRIVS; - return; - } + if(!IsOper(source_p) && !IsServer(source_p)) { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); + *errors |= SM_ERR_NOPRIVS; + return; + } + if(MyClient(source_p) && !IsOperResv(source_p)) { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, + source_p->name, "resv"); + *errors |= SM_ERR_NOPRIVS; + return; + } - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if (IsOverride(source_p)) - override = 1; - else - { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if (IsOverride(source_p)) + override = 1; + else { + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - /* setting + */ - if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) - { - chptr->mode.mode |= mode_type; + /* setting + */ + if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { + chptr->mode.mode |= mode_type; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = NULL; - } - else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) - { - chptr->mode.mode &= ~mode_type; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = NULL; + } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { + chptr->mode.mode &= ~mode_type; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].override = override; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count++].arg = NULL; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].override = override; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count++].arg = NULL; + } } void chm_ban(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - const char *mask; - const char *raw_mask; - rb_dlink_list *list; - rb_dlink_node *ptr; - struct Ban *banptr; - int errorval; - int rpl_list; - int rpl_endlist; - int caps; - int mems; - int override = 0; + const char *mask; + const char *raw_mask; + rb_dlink_list *list; + rb_dlink_node *ptr; + struct Ban *banptr; + int errorval; + int rpl_list; + int rpl_endlist; + int caps; + int mems; + int override = 0; - switch (mode_type) - { - case CHFL_BAN: - list = &chptr->banlist; - errorval = SM_ERR_RPL_B; - rpl_list = RPL_BANLIST; - rpl_endlist = RPL_ENDOFBANLIST; - mems = ALL_MEMBERS; - caps = 0; - break; + switch (mode_type) { + case CHFL_BAN: + list = &chptr->banlist; + errorval = SM_ERR_RPL_B; + rpl_list = RPL_BANLIST; + rpl_endlist = RPL_ENDOFBANLIST; + mems = ALL_MEMBERS; + caps = 0; + break; - case CHFL_EXCEPTION: - /* if +e is disabled, allow all but +e locally */ - if(!ConfigChannel.use_except && MyClient(source_p) && - ((dir == MODE_ADD) && (parc > *parn))) - return; + case CHFL_EXCEPTION: + /* if +e is disabled, allow all but +e locally */ + if(!ConfigChannel.use_except && MyClient(source_p) && + ((dir == MODE_ADD) && (parc > *parn))) + return; - list = &chptr->exceptlist; - errorval = SM_ERR_RPL_E; - rpl_list = RPL_EXCEPTLIST; - rpl_endlist = RPL_ENDOFEXCEPTLIST; - caps = CAP_EX; + list = &chptr->exceptlist; + errorval = SM_ERR_RPL_E; + rpl_list = RPL_EXCEPTLIST; + rpl_endlist = RPL_ENDOFEXCEPTLIST; + caps = CAP_EX; - if(ConfigChannel.use_except || (dir == MODE_DEL)) - mems = ONLY_CHANOPS; - else - mems = ONLY_SERVERS; - break; + if(ConfigChannel.use_except || (dir == MODE_DEL)) + mems = ONLY_CHANOPS; + else + mems = ONLY_SERVERS; + break; - case CHFL_INVEX: - /* if +I is disabled, allow all but +I locally */ - if(!ConfigChannel.use_invex && MyClient(source_p) && - (dir == MODE_ADD) && (parc > *parn)) - return; + case CHFL_INVEX: + /* if +I is disabled, allow all but +I locally */ + if(!ConfigChannel.use_invex && MyClient(source_p) && + (dir == MODE_ADD) && (parc > *parn)) + return; - list = &chptr->invexlist; - errorval = SM_ERR_RPL_I; - rpl_list = RPL_INVITELIST; - rpl_endlist = RPL_ENDOFINVITELIST; - caps = CAP_IE; + list = &chptr->invexlist; + errorval = SM_ERR_RPL_I; + rpl_list = RPL_INVITELIST; + rpl_endlist = RPL_ENDOFINVITELIST; + caps = CAP_IE; - if(ConfigChannel.use_invex || (dir == MODE_DEL)) - mems = ONLY_CHANOPS; - else - mems = ONLY_SERVERS; - break; + if(ConfigChannel.use_invex || (dir == MODE_DEL)) + mems = ONLY_CHANOPS; + else + mems = ONLY_SERVERS; + break; - case CHFL_QUIET: - list = &chptr->quietlist; - errorval = SM_ERR_RPL_Q; - rpl_list = RPL_QUIETLIST; - rpl_endlist = RPL_ENDOFQUIETLIST; - mems = ALL_MEMBERS; - caps = 0; - break; + case CHFL_QUIET: + list = &chptr->quietlist; + errorval = SM_ERR_RPL_Q; + rpl_list = RPL_QUIETLIST; + rpl_endlist = RPL_ENDOFQUIETLIST; + mems = ALL_MEMBERS; + caps = 0; + break; - default: - sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!"); - return; - break; - } + default: + sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!"); + return; + break; + } - if(dir == 0 || parc <= *parn) - { - if((*errors & errorval) != 0) - return; - *errors |= errorval; + if(dir == 0 || parc <= *parn) { + if((*errors & errorval) != 0) + return; + *errors |= errorval; - /* non-ops cant see +eI lists.. */ - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER && - mode_type != CHFL_BAN && mode_type != CHFL_QUIET) - { - if(IsOverride(source_p)) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding modes on %s: (%s list)", - get_oper_name(source_p), chptr->chname, mode_type == CHFL_INVEX ? "invex" : "exempt"); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding modes on %s: (%s list)", - me.name, get_oper_name(source_p), chptr->chname, mode_type == CHFL_INVEX ? "invex" : "exempt"); - } - else - { + /* non-ops cant see +eI lists.. */ + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER && + mode_type != CHFL_BAN && mode_type != CHFL_QUIET) { + if(IsOverride(source_p)) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding modes on %s: (%s list)", + get_oper_name(source_p), chptr->chname, mode_type == CHFL_INVEX ? "invex" : "exempt"); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding modes on %s: (%s list)", + me.name, get_oper_name(source_p), chptr->chname, mode_type == CHFL_INVEX ? "invex" : "exempt"); + } else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if(!(chptr->mode.mode & MODE_HIDEBANS) || alevel & ONLY_CHANOPS) { - RB_DLINK_FOREACH(ptr, list->head) - { - banptr = ptr->data; - sendto_one(source_p, form_str(rpl_list), - me.name, source_p->name, chptr->chname, - banptr->banstr, banptr->who, banptr->when); - } - } + if(!(chptr->mode.mode & MODE_HIDEBANS) || alevel & ONLY_CHANOPS) { + RB_DLINK_FOREACH(ptr, list->head) { + banptr = ptr->data; + sendto_one(source_p, form_str(rpl_list), + me.name, source_p->name, chptr->chname, + banptr->banstr, banptr->who, banptr->when); + } + } - sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname); - return; - } + sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname); + return; + } - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) - return; + if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) + return; - raw_mask = parv[(*parn)]; - (*parn)++; + raw_mask = parv[(*parn)]; + (*parn)++; - /* empty ban, or starts with ':' which messes up s2s, ignore it */ - if(EmptyString(raw_mask) || *raw_mask == ':') - return; + /* empty ban, or starts with ':' which messes up s2s, ignore it */ + if(EmptyString(raw_mask) || *raw_mask == ':') + return; - if(!MyClient(source_p)) - { - if(strchr(raw_mask, ' ')) - return; + if(!MyClient(source_p)) { + if(strchr(raw_mask, ' ')) + return; - mask = raw_mask; - } - else - mask = pretty_mask(raw_mask); + mask = raw_mask; + } else + mask = pretty_mask(raw_mask); - /* we'd have problems parsing this, hyb6 does it too - * also make sure it will always fit on a line with channel - * name etc. - */ - if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5)) - return; + /* we'd have problems parsing this, hyb6 does it too + * also make sure it will always fit on a line with channel + * name etc. + */ + if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5)) + return; - /* if we're adding a NEW id */ - if(dir == MODE_ADD) - { - if (*mask == '$' && MyClient(source_p)) - { - if (!valid_extban(mask, source_p, chptr, mode_type)) - /* XXX perhaps return an error message here */ - return; - } + /* if we're adding a NEW id */ + if(dir == MODE_ADD) { + if (*mask == '$' && MyClient(source_p)) { + if (!valid_extban(mask, source_p, chptr, mode_type)) + /* XXX perhaps return an error message here */ + return; + } - /* dont allow local clients to overflow the banlist, dont - * let remote servers set duplicate bans - */ - if(!add_id(source_p, chptr, mask, list, mode_type)) - return; + /* dont allow local clients to overflow the banlist, dont + * let remote servers set duplicate bans + */ + if(!add_id(source_p, chptr, mask, list, mode_type)) + return; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = caps; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = mems; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = mask; - } - else if(dir == MODE_DEL) - { - if(del_id(chptr, mask, list, mode_type) == 0) - { - /* mask isn't a valid ban, check raw_mask */ - if(del_id(chptr, raw_mask, list, mode_type)) - mask = raw_mask; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = caps; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = mems; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = mask; + } else if(dir == MODE_DEL) { + if(del_id(chptr, mask, list, mode_type) == 0) { + /* mask isn't a valid ban, check raw_mask */ + if(del_id(chptr, raw_mask, list, mode_type)) + mask = raw_mask; + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = caps; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = mems; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = mask; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = caps; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = mems; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = mask; + } } void @@ -1013,220 +938,199 @@ chm_owner(struct Client *source_p, struct Channel *chptr, int alevel, int parc, int *parn, const char **parv, int *errors, int dir, char c, long mode_type) { - struct membership *mstptr; - const char *ownernick; - struct Client *targ_p; - int override = 0; + struct membership *mstptr; + const char *ownernick; + struct Client *targ_p; + int override = 0; - if(!ConfigChannel.use_owner) - { - if(*errors & SM_ERR_UNKNOWN) - return; - *errors |= SM_ERR_UNKNOWN; - sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); - return; + if(!ConfigChannel.use_owner) { + if(*errors & SM_ERR_UNKNOWN) + return; + *errors |= SM_ERR_UNKNOWN; + sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); + return; + } + + if(alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, ":%s 482 %s %s :You're not a channel owner", me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } + + if((dir == MODE_QUERY) || (parc <= *parn)) + return; + + ownernick = parv[(*parn)]; + (*parn)++; + + /* empty nick */ + if(EmptyString(ownernick)) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); + return; + } + + if((targ_p = find_chasing(source_p, ownernick, NULL)) == NULL) + return; + + mstptr = find_channel_membership(chptr, targ_p); + + if(mstptr == NULL) { + if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), ownernick, chptr->chname); + *errors |= SM_ERR_NOTONCHANNEL; + return; + } + + if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) + return; + + if(dir == MODE_ADD) { + if(targ_p == source_p) { + no_override_deop = 1; + /* Don't reject modes from remote. It desyncs, and this is perfectly + * legitimate from a remote override oper. + if(!override) + return; + */ } - if(alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, ":%s 482 %s %s :You're not a channel owner", me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; + + mstptr->flags |= CHFL_OWNER; + } else { + if(MyClient(source_p) && IsService(targ_p)) { + sendto_one(source_p, form_str(ERR_ISCHANSERVICE), + me.name, source_p->name, targ_p->name, chptr->chname); + return; } - if((dir == MODE_QUERY) || (parc <= *parn)) - return; - - ownernick = parv[(*parn)]; - (*parn)++; - - /* empty nick */ - if(EmptyString(ownernick)) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); - return; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - if((targ_p = find_chasing(source_p, ownernick, NULL)) == NULL) - return; - - mstptr = find_channel_membership(chptr, targ_p); - - if(mstptr == NULL) - { - if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), ownernick, chptr->chname); - *errors |= SM_ERR_NOTONCHANNEL; - return; - } - - if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) - return; - - if(dir == MODE_ADD) - { - if(targ_p == source_p) - { - no_override_deop = 1; - /* Don't reject modes from remote. It desyncs, and this is perfectly - * legitimate from a remote override oper. - if(!override) - return; - */ - } - - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; - - mstptr->flags |= CHFL_OWNER; - } - else - { - if(MyClient(source_p) && IsService(targ_p)) - { - sendto_one(source_p, form_str(ERR_ISCHANSERVICE), - me.name, source_p->name, targ_p->name, chptr->chname); - return; - } - - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; - - mstptr->flags &= ~CHFL_OWNER; - } + mstptr->flags &= ~CHFL_OWNER; + } } void chm_admin(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - struct membership *mstptr; - const char *adminnick; - struct Client *targ_p; - int override = 0; + struct membership *mstptr; + const char *adminnick; + struct Client *targ_p; + int override = 0; - if(!ConfigChannel.use_admin) - { - if(*errors & SM_ERR_UNKNOWN) - return; - *errors |= SM_ERR_UNKNOWN; - sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); - return; - } + if(!ConfigChannel.use_admin) { + if(*errors & SM_ERR_UNKNOWN) + return; + *errors |= SM_ERR_UNKNOWN; + sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); + return; + } - if(alevel != CHFL_ADMIN && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { + if(alevel != CHFL_ADMIN && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, ":%s 482 %s %s :You're not a channel administrator", me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, ":%s 482 %s %s :You're not a channel administrator", me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if((dir == MODE_QUERY) || (parc <= *parn)) - return; + if((dir == MODE_QUERY) || (parc <= *parn)) + return; - adminnick = parv[(*parn)]; - (*parn)++; + adminnick = parv[(*parn)]; + (*parn)++; - /* empty nick */ - if(EmptyString(adminnick)) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); - return; - } + /* empty nick */ + if(EmptyString(adminnick)) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); + return; + } - if((targ_p = find_chasing(source_p, adminnick, NULL)) == NULL) - { - return; - } + if((targ_p = find_chasing(source_p, adminnick, NULL)) == NULL) { + return; + } - mstptr = find_channel_membership(chptr, targ_p); + mstptr = find_channel_membership(chptr, targ_p); - if(mstptr == NULL) - { - if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), adminnick, chptr->chname); - *errors |= SM_ERR_NOTONCHANNEL; - return; - } + if(mstptr == NULL) { + if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), adminnick, chptr->chname); + *errors |= SM_ERR_NOTONCHANNEL; + return; + } - if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) - return; + if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) + return; - if(dir == MODE_ADD) - { - if(targ_p == source_p) - { - no_override_deop = 1; - /* Don't reject modes from remote. It desyncs, and this is perfectly - * legitimate from a remote override oper. - if(!override) - return; - */ - } + if(dir == MODE_ADD) { + if(targ_p == source_p) { + no_override_deop = 1; + /* Don't reject modes from remote. It desyncs, and this is perfectly + * legitimate from a remote override oper. + if(!override) + return; + */ + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags |= CHFL_ADMIN; - } - else - { - if(MyClient(source_p) && IsService(targ_p)) - { - sendto_one(source_p, form_str(ERR_ISCHANSERVICE), - me.name, source_p->name, targ_p->name, chptr->chname); - return; - } + mstptr->flags |= CHFL_ADMIN; + } else { + if(MyClient(source_p) && IsService(targ_p)) { + sendto_one(source_p, form_str(ERR_ISCHANSERVICE), + me.name, source_p->name, targ_p->name, chptr->chname); + return; + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags &= ~CHFL_ADMIN; - } + mstptr->flags &= ~CHFL_ADMIN; + } } void @@ -1234,927 +1138,867 @@ chm_op(struct Client *source_p, struct Channel *chptr, int alevel, int parc, int *parn, const char **parv, int *errors, int dir, char c, long mode_type) { - struct membership *mstptr; - const char *opnick; - struct Client *targ_p; - int override = 0; + struct membership *mstptr; + const char *opnick; + struct Client *targ_p; + int override = 0; - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if((dir == MODE_QUERY) || (parc <= *parn)) - return; + if((dir == MODE_QUERY) || (parc <= *parn)) + return; - opnick = parv[(*parn)]; - (*parn)++; + opnick = parv[(*parn)]; + (*parn)++; - /* empty nick */ - if(EmptyString(opnick)) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); - return; - } + /* empty nick */ + if(EmptyString(opnick)) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); + return; + } - if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) - { - return; - } + if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) { + return; + } - mstptr = find_channel_membership(chptr, targ_p); + mstptr = find_channel_membership(chptr, targ_p); - if(mstptr == NULL) - { - if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); - *errors |= SM_ERR_NOTONCHANNEL; - return; - } + if(mstptr == NULL) { + if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); + *errors |= SM_ERR_NOTONCHANNEL; + return; + } - if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) - return; + if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) + return; - if(dir == MODE_ADD) - { - if(targ_p == source_p) - { - no_override_deop = 1; - /* Don't reject modes from remote. It desyncs, and this is perfectly - * legitimate from a remote override oper. - if(!override) - return; - */ - } + if(dir == MODE_ADD) { + if(targ_p == source_p) { + no_override_deop = 1; + /* Don't reject modes from remote. It desyncs, and this is perfectly + * legitimate from a remote override oper. + if(!override) + return; + */ + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags |= CHFL_CHANOP; - } - else - { - if(MyClient(source_p) && IsService(targ_p)) - { - sendto_one(source_p, form_str(ERR_ISCHANSERVICE), - me.name, source_p->name, targ_p->name, chptr->chname); - return; - } + mstptr->flags |= CHFL_CHANOP; + } else { + if(MyClient(source_p) && IsService(targ_p)) { + sendto_one(source_p, form_str(ERR_ISCHANSERVICE), + me.name, source_p->name, targ_p->name, chptr->chname); + return; + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags &= ~CHFL_CHANOP; - } + mstptr->flags &= ~CHFL_CHANOP; + } } void chm_halfop(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - struct membership *mstptr; - const char *halfopnick; - struct Client *targ_p; - int override = 0; + struct membership *mstptr; + const char *halfopnick; + struct Client *targ_p; + int override = 0; - if(!ConfigChannel.use_halfop) - { - if(*errors & SM_ERR_UNKNOWN) - return; - *errors |= SM_ERR_UNKNOWN; - sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); - return; - } + if(!ConfigChannel.use_halfop) { + if(*errors & SM_ERR_UNKNOWN) + return; + *errors |= SM_ERR_UNKNOWN; + sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); + return; + } - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if((dir == MODE_QUERY) || (parc <= *parn)) - return; + if((dir == MODE_QUERY) || (parc <= *parn)) + return; - halfopnick = parv[(*parn)]; - (*parn)++; + halfopnick = parv[(*parn)]; + (*parn)++; - /* empty nick */ - if(EmptyString(halfopnick)) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); - return; - } + /* empty nick */ + if(EmptyString(halfopnick)) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); + return; + } - if((targ_p = find_chasing(source_p, halfopnick, NULL)) == NULL) - { - return; - } + if((targ_p = find_chasing(source_p, halfopnick, NULL)) == NULL) { + return; + } - mstptr = find_channel_membership(chptr, targ_p); + mstptr = find_channel_membership(chptr, targ_p); - if(mstptr == NULL) - { - if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), halfopnick, chptr->chname); - *errors |= SM_ERR_NOTONCHANNEL; - return; - } + if(mstptr == NULL) { + if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), halfopnick, chptr->chname); + *errors |= SM_ERR_NOTONCHANNEL; + return; + } - if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) - return; + if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) + return; - if(dir == MODE_ADD) - { - if(targ_p == source_p) - { - no_override_deop = 1; - /* Don't reject modes from remote. It desyncs, and this is perfectly - * legitimate from a remote override oper. - if(!override) - return; - */ - } + if(dir == MODE_ADD) { + if(targ_p == source_p) { + no_override_deop = 1; + /* Don't reject modes from remote. It desyncs, and this is perfectly + * legitimate from a remote override oper. + if(!override) + return; + */ + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags |= CHFL_HALFOP; - } - else - { - if(MyClient(source_p) && IsService(targ_p)) - { - sendto_one(source_p, form_str(ERR_ISCHANSERVICE), - me.name, source_p->name, targ_p->name, chptr->chname); - return; - } + mstptr->flags |= CHFL_HALFOP; + } else { + if(MyClient(source_p) && IsService(targ_p)) { + sendto_one(source_p, form_str(ERR_ISCHANSERVICE), + me.name, source_p->name, targ_p->name, chptr->chname); + return; + } - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags &= ~CHFL_HALFOP; - } + mstptr->flags &= ~CHFL_HALFOP; + } } void chm_voice(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - struct membership *mstptr; - const char *opnick; - struct Client *targ_p; - int override = 0; + struct membership *mstptr; + const char *opnick; + struct Client *targ_p; + int override = 0; - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if((dir == MODE_QUERY) || parc <= *parn) - return; + if((dir == MODE_QUERY) || parc <= *parn) + return; - opnick = parv[(*parn)]; - (*parn)++; + opnick = parv[(*parn)]; + (*parn)++; - /* empty nick */ - if(EmptyString(opnick)) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); - return; - } + /* empty nick */ + if(EmptyString(opnick)) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); + return; + } - if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) - { - return; - } + if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) { + return; + } - mstptr = find_channel_membership(chptr, targ_p); + mstptr = find_channel_membership(chptr, targ_p); - if(mstptr == NULL) - { - if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) - sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, - form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); - *errors |= SM_ERR_NOTONCHANNEL; - return; - } + if(mstptr == NULL) { + if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) + sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, + form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); + *errors |= SM_ERR_NOTONCHANNEL; + return; + } - if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) - return; + if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) + return; - if(dir == MODE_ADD) - { - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + if(dir == MODE_ADD) { + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags |= CHFL_VOICE; - } - else - { - mode_changes[mode_count].letter = 'v'; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = targ_p->id; - mode_changes[mode_count].arg = targ_p->name; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].client = targ_p; + mstptr->flags |= CHFL_VOICE; + } else { + mode_changes[mode_count].letter = 'v'; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = targ_p->id; + mode_changes[mode_count].arg = targ_p->name; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].client = targ_p; - mstptr->flags &= ~CHFL_VOICE; - } + mstptr->flags &= ~CHFL_VOICE; + } } void chm_limit(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - const char *lstr; - static char limitstr[30]; - int limit; - int override = 0; + const char *lstr; + static char limitstr[30]; + int limit; + int override = 0; - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if(dir == MODE_QUERY) - return; + if(dir == MODE_QUERY) + return; - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - if((dir == MODE_ADD) && parc > *parn) - { - lstr = parv[(*parn)]; - (*parn)++; + if((dir == MODE_ADD) && parc > *parn) { + lstr = parv[(*parn)]; + (*parn)++; - if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0) - return; + if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0) + return; - rb_sprintf(limitstr, "%d", limit); + rb_sprintf(limitstr, "%d", limit); - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = limitstr; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = limitstr; - chptr->mode.limit = limit; - } - else if(dir == MODE_DEL) - { - if(!chptr->mode.limit) - return; + chptr->mode.limit = limit; + } else if(dir == MODE_DEL) { + if(!chptr->mode.limit) + return; - chptr->mode.limit = 0; + chptr->mode.limit = 0; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = NULL; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = NULL; + } } void chm_throttle(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - int joins = 0, timeslice = 0; - int override = 0; + int joins = 0, timeslice = 0; + int override = 0; - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if(dir == MODE_QUERY) - return; + if(dir == MODE_QUERY) + return; - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - if((dir == MODE_ADD) && parc > *parn) - { - sscanf(parv[(*parn)], "%d:%d", &joins, ×lice); + if((dir == MODE_ADD) && parc > *parn) { + sscanf(parv[(*parn)], "%d:%d", &joins, ×lice); - if(!joins || !timeslice) - return; + if(!joins || !timeslice) + return; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = parv[(*parn)]; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = parv[(*parn)]; - (*parn)++; + (*parn)++; - chptr->mode.join_num = joins; - chptr->mode.join_time = timeslice; - } - else if(dir == MODE_DEL) - { - if(!chptr->mode.join_num) - return; + chptr->mode.join_num = joins; + chptr->mode.join_time = timeslice; + } else if(dir == MODE_DEL) { + if(!chptr->mode.join_num) + return; - chptr->mode.join_num = 0; - chptr->mode.join_time = 0; - chptr->join_count = 0; - chptr->join_delta = 0; + chptr->mode.join_num = 0; + chptr->mode.join_time = 0; + chptr->join_count = 0; + chptr->join_delta = 0; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = NULL; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = NULL; + } } void chm_forward(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - struct Channel *targptr = NULL; - struct membership *msptr; - const char *forward; - int override = 0; + struct Channel *targptr = NULL; + struct membership *msptr; + const char *forward; + int override = 0; - /* if +f is disabled, ignore local attempts to set it */ - if(!ConfigChannel.use_forward && MyClient(source_p) && - (dir == MODE_ADD) && (parc > *parn)) - return; + /* if +f is disabled, ignore local attempts to set it */ + if(!ConfigChannel.use_forward && MyClient(source_p) && + (dir == MODE_ADD) && (parc > *parn)) + return; - if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn)) - { - if (!(*errors & SM_ERR_RPL_F)) - { - if (*chptr->mode.forward == '\0') - sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); - else - sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); - *errors |= SM_ERR_RPL_F; - } - return; - } + if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn)) { + if (!(*errors & SM_ERR_RPL_F)) { + if (*chptr->mode.forward == '\0') + sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); + else + sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); + *errors |= SM_ERR_RPL_F; + } + return; + } #ifndef FORWARD_OPERONLY - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } #else - if(!IsOper(source_p) && !IsServer(source_p)) - { - if(!(*errors & SM_ERR_NOPRIVS)) - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); - *errors |= SM_ERR_NOPRIVS; - return; - } + if(!IsOper(source_p) && !IsServer(source_p)) { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); + *errors |= SM_ERR_NOPRIVS; + return; + } #endif - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - if(dir == MODE_ADD && parc > *parn) - { - forward = parv[(*parn)]; - (*parn)++; + if(dir == MODE_ADD && parc > *parn) { + forward = parv[(*parn)]; + (*parn)++; - if(EmptyString(forward)) - return; - if(!check_channel_name(forward) || - (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward)))) - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); - return; - } - /* don't forward to inconsistent target -- jilles */ - if(chptr->chname[0] == '#' && forward[0] == '&') - { - sendto_one_numeric(source_p, ERR_BADCHANNAME, - form_str(ERR_BADCHANNAME), forward); - return; - } - if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL) - { - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), forward); - return; - } - if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) - { - if((msptr = find_channel_membership(targptr, source_p)) == NULL || - !is_any_op(msptr)) - { - if(IsOverride(source_p)) - override = 1; - else - { - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, targptr->chname); - return; - } - } - } + if(EmptyString(forward)) + return; + if(!check_channel_name(forward) || + (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward)))) { + sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); + return; + } + /* don't forward to inconsistent target -- jilles */ + if(chptr->chname[0] == '#' && forward[0] == '&') { + sendto_one_numeric(source_p, ERR_BADCHANNAME, + form_str(ERR_BADCHANNAME), forward); + return; + } + if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL) { + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), forward); + return; + } + if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) { + if((msptr = find_channel_membership(targptr, source_p)) == NULL || + !is_any_op(msptr)) { + if(IsOverride(source_p)) + override = 1; + else { + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, targptr->chname); + return; + } + } + } - rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward)); + rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward)); - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = forward; - } - else if(dir == MODE_DEL) - { - if(!(*chptr->mode.forward)) - return; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = forward; + } else if(dir == MODE_DEL) { + if(!(*chptr->mode.forward)) + return; - *chptr->mode.forward = '\0'; + *chptr->mode.forward = '\0'; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = NULL; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = NULL; + } } void chm_key(struct Client *source_p, struct Channel *chptr, - int alevel, int parc, int *parn, - const char **parv, int *errors, int dir, char c, long mode_type) + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) { - char *key; - int override = 0; + char *key; + int override = 0; - if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) - { - if(IsOverride(source_p)) - override = 1; - else - { - if(!(*errors & SM_ERR_NOOPS)) - sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), - me.name, source_p->name, chptr->chname); - *errors |= SM_ERR_NOOPS; - return; - } - } + if(alevel != CHFL_CHANOP && alevel != CHFL_ADMIN && alevel != CHFL_HALFOP && alevel != CHFL_OWNER) { + if(IsOverride(source_p)) + override = 1; + else { + if(!(*errors & SM_ERR_NOOPS)) + sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), + me.name, source_p->name, chptr->chname); + *errors |= SM_ERR_NOOPS; + return; + } + } - if(dir == MODE_QUERY) - return; + if(dir == MODE_QUERY) + return; - if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) - return; + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; - if((dir == MODE_ADD) && parc > *parn) - { - key = LOCAL_COPY(parv[(*parn)]); - (*parn)++; + if((dir == MODE_ADD) && parc > *parn) { + key = LOCAL_COPY(parv[(*parn)]); + (*parn)++; - if(MyClient(source_p)) - fix_key(key); - else - fix_key_remote(key); + if(MyClient(source_p)) + fix_key(key); + else + fix_key_remote(key); - if(EmptyString(key)) - return; + if(EmptyString(key)) + return; - s_assert(key[0] != ' '); - rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); + s_assert(key[0] != ' '); + rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_ADD; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = chptr->mode.key; - } - else if(dir == MODE_DEL) - { - static char splat[] = "*"; - int i; + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = chptr->mode.key; + } else if(dir == MODE_DEL) { + static char splat[] = "*"; + int i; - if(parc > *parn) - (*parn)++; + if(parc > *parn) + (*parn)++; - if(!(*chptr->mode.key)) - return; + if(!(*chptr->mode.key)) + return; - /* hack time. when we get a +k-k mode, the +k arg is - * chptr->mode.key, which the -k sets to \0, so hunt for a - * +k when we get a -k, and set the arg to splat. --anfl - */ - for(i = 0; i < mode_count; i++) - { - if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) - mode_changes[i].arg = splat; - } + /* hack time. when we get a +k-k mode, the +k arg is + * chptr->mode.key, which the -k sets to \0, so hunt for a + * +k when we get a -k, and set the arg to splat. --anfl + */ + for(i = 0; i < mode_count; i++) { + if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) + mode_changes[i].arg = splat; + } - *chptr->mode.key = 0; + *chptr->mode.key = 0; - mode_changes[mode_count].letter = c; - mode_changes[mode_count].dir = MODE_DEL; - mode_changes[mode_count].caps = 0; - mode_changes[mode_count].nocaps = 0; - mode_changes[mode_count].mems = ALL_MEMBERS; - mode_changes[mode_count].id = NULL; - mode_changes[mode_count].override = override; - mode_changes[mode_count++].arg = "*"; - } + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ALL_MEMBERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = override; + mode_changes[mode_count++].arg = "*"; + } } /* *INDENT-OFF* */ -struct ChannelMode chmode_table[256] = -{ - {chm_nosuch, 0 }, /* 0x00 */ - {chm_nosuch, 0 }, /* 0x01 */ - {chm_nosuch, 0 }, /* 0x02 */ - {chm_nosuch, 0 }, /* 0x03 */ - {chm_nosuch, 0 }, /* 0x04 */ - {chm_nosuch, 0 }, /* 0x05 */ - {chm_nosuch, 0 }, /* 0x06 */ - {chm_nosuch, 0 }, /* 0x07 */ - {chm_nosuch, 0 }, /* 0x08 */ - {chm_nosuch, 0 }, /* 0x09 */ - {chm_nosuch, 0 }, /* 0x0a */ - {chm_nosuch, 0 }, /* 0x0b */ - {chm_nosuch, 0 }, /* 0x0c */ - {chm_nosuch, 0 }, /* 0x0d */ - {chm_nosuch, 0 }, /* 0x0e */ - {chm_nosuch, 0 }, /* 0x0f */ - {chm_nosuch, 0 }, /* 0x10 */ - {chm_nosuch, 0 }, /* 0x11 */ - {chm_nosuch, 0 }, /* 0x12 */ - {chm_nosuch, 0 }, /* 0x13 */ - {chm_nosuch, 0 }, /* 0x14 */ - {chm_nosuch, 0 }, /* 0x15 */ - {chm_nosuch, 0 }, /* 0x16 */ - {chm_nosuch, 0 }, /* 0x17 */ - {chm_nosuch, 0 }, /* 0x18 */ - {chm_nosuch, 0 }, /* 0x19 */ - {chm_nosuch, 0 }, /* 0x1a */ - {chm_nosuch, 0 }, /* 0x1b */ - {chm_nosuch, 0 }, /* 0x1c */ - {chm_nosuch, 0 }, /* 0x1d */ - {chm_nosuch, 0 }, /* 0x1e */ - {chm_nosuch, 0 }, /* 0x1f */ - {chm_nosuch, 0 }, /* 0x20 */ - {chm_nosuch, 0 }, /* 0x21 */ - {chm_nosuch, 0 }, /* 0x22 */ - {chm_nosuch, 0 }, /* 0x23 */ - {chm_nosuch, 0 }, /* 0x24 */ - {chm_nosuch, 0 }, /* 0x25 */ - {chm_nosuch, 0 }, /* 0x26 */ - {chm_nosuch, 0 }, /* 0x27 */ - {chm_nosuch, 0 }, /* 0x28 */ - {chm_nosuch, 0 }, /* 0x29 */ - {chm_nosuch, 0 }, /* 0x2a */ - {chm_nosuch, 0 }, /* 0x2b */ - {chm_nosuch, 0 }, /* 0x2c */ - {chm_nosuch, 0 }, /* 0x2d */ - {chm_nosuch, 0 }, /* 0x2e */ - {chm_nosuch, 0 }, /* 0x2f */ - {chm_nosuch, 0 }, /* 0x30 */ - {chm_nosuch, 0 }, /* 0x31 */ - {chm_nosuch, 0 }, /* 0x32 */ - {chm_nosuch, 0 }, /* 0x33 */ - {chm_nosuch, 0 }, /* 0x34 */ - {chm_nosuch, 0 }, /* 0x35 */ - {chm_nosuch, 0 }, /* 0x36 */ - {chm_nosuch, 0 }, /* 0x37 */ - {chm_nosuch, 0 }, /* 0x38 */ - {chm_nosuch, 0 }, /* 0x39 */ - {chm_nosuch, 0 }, /* 0x3a */ - {chm_nosuch, 0 }, /* 0x3b */ - {chm_nosuch, 0 }, /* 0x3c */ - {chm_nosuch, 0 }, /* 0x3d */ - {chm_nosuch, 0 }, /* 0x3e */ - {chm_nosuch, 0 }, /* 0x3f */ +struct ChannelMode chmode_table[256] = { + {chm_nosuch, 0 }, /* 0x00 */ + {chm_nosuch, 0 }, /* 0x01 */ + {chm_nosuch, 0 }, /* 0x02 */ + {chm_nosuch, 0 }, /* 0x03 */ + {chm_nosuch, 0 }, /* 0x04 */ + {chm_nosuch, 0 }, /* 0x05 */ + {chm_nosuch, 0 }, /* 0x06 */ + {chm_nosuch, 0 }, /* 0x07 */ + {chm_nosuch, 0 }, /* 0x08 */ + {chm_nosuch, 0 }, /* 0x09 */ + {chm_nosuch, 0 }, /* 0x0a */ + {chm_nosuch, 0 }, /* 0x0b */ + {chm_nosuch, 0 }, /* 0x0c */ + {chm_nosuch, 0 }, /* 0x0d */ + {chm_nosuch, 0 }, /* 0x0e */ + {chm_nosuch, 0 }, /* 0x0f */ + {chm_nosuch, 0 }, /* 0x10 */ + {chm_nosuch, 0 }, /* 0x11 */ + {chm_nosuch, 0 }, /* 0x12 */ + {chm_nosuch, 0 }, /* 0x13 */ + {chm_nosuch, 0 }, /* 0x14 */ + {chm_nosuch, 0 }, /* 0x15 */ + {chm_nosuch, 0 }, /* 0x16 */ + {chm_nosuch, 0 }, /* 0x17 */ + {chm_nosuch, 0 }, /* 0x18 */ + {chm_nosuch, 0 }, /* 0x19 */ + {chm_nosuch, 0 }, /* 0x1a */ + {chm_nosuch, 0 }, /* 0x1b */ + {chm_nosuch, 0 }, /* 0x1c */ + {chm_nosuch, 0 }, /* 0x1d */ + {chm_nosuch, 0 }, /* 0x1e */ + {chm_nosuch, 0 }, /* 0x1f */ + {chm_nosuch, 0 }, /* 0x20 */ + {chm_nosuch, 0 }, /* 0x21 */ + {chm_nosuch, 0 }, /* 0x22 */ + {chm_nosuch, 0 }, /* 0x23 */ + {chm_nosuch, 0 }, /* 0x24 */ + {chm_nosuch, 0 }, /* 0x25 */ + {chm_nosuch, 0 }, /* 0x26 */ + {chm_nosuch, 0 }, /* 0x27 */ + {chm_nosuch, 0 }, /* 0x28 */ + {chm_nosuch, 0 }, /* 0x29 */ + {chm_nosuch, 0 }, /* 0x2a */ + {chm_nosuch, 0 }, /* 0x2b */ + {chm_nosuch, 0 }, /* 0x2c */ + {chm_nosuch, 0 }, /* 0x2d */ + {chm_nosuch, 0 }, /* 0x2e */ + {chm_nosuch, 0 }, /* 0x2f */ + {chm_nosuch, 0 }, /* 0x30 */ + {chm_nosuch, 0 }, /* 0x31 */ + {chm_nosuch, 0 }, /* 0x32 */ + {chm_nosuch, 0 }, /* 0x33 */ + {chm_nosuch, 0 }, /* 0x34 */ + {chm_nosuch, 0 }, /* 0x35 */ + {chm_nosuch, 0 }, /* 0x36 */ + {chm_nosuch, 0 }, /* 0x37 */ + {chm_nosuch, 0 }, /* 0x38 */ + {chm_nosuch, 0 }, /* 0x39 */ + {chm_nosuch, 0 }, /* 0x3a */ + {chm_nosuch, 0 }, /* 0x3b */ + {chm_nosuch, 0 }, /* 0x3c */ + {chm_nosuch, 0 }, /* 0x3d */ + {chm_nosuch, 0 }, /* 0x3e */ + {chm_nosuch, 0 }, /* 0x3f */ - {chm_nosuch, 0 }, /* @ */ - {chm_nosuch, 0 }, /* A */ - {chm_nosuch, 0 }, /* B */ - {chm_simple, MODE_NOCTCP }, /* C */ - {chm_simple, MODE_NOACTION }, /* D */ - {chm_simple, MODE_NOKICK }, /* E */ - {chm_simple, MODE_FREETARGET }, /* F */ - {chm_simple, MODE_NOCAPS }, /* G */ - {chm_nosuch, 0 }, /* H */ - {chm_ban, CHFL_INVEX }, /* I */ - {chm_simple, MODE_NOREJOIN }, /* J */ - {chm_simple, MODE_NOREPEAT }, /* K */ - {chm_staff, MODE_EXLIMIT }, /* L */ - {chm_hidden, MODE_NOOPERKICK }, /* M */ - {chm_nosuch, 0 }, /* N */ - {chm_nosuch, 0 }, /* O */ - {chm_staff, MODE_PERMANENT }, /* P */ - {chm_simple, MODE_DISFORWARD }, /* Q */ - {chm_nosuch, 0 }, /* R */ - {chm_nosuch, 0 }, /* S */ - {chm_simple, MODE_NONOTICE }, /* T */ - {chm_nosuch, 0 }, /* U */ - {chm_nosuch, 0 }, /* V */ - {chm_nosuch, 0 }, /* W */ - {chm_nosuch, 0 }, /* X */ - {chm_nosuch, 0 }, /* Y */ - {chm_nosuch, 0 }, /* Z */ - {chm_nosuch, 0 }, - {chm_nosuch, 0 }, - {chm_nosuch, 0 }, - {chm_nosuch, 0 }, - {chm_nosuch, 0 }, - {chm_nosuch, 0 }, - {chm_admin, 0 }, /* a */ - {chm_ban, CHFL_BAN }, /* b */ - {chm_simple, MODE_NOCOLOR }, /* c */ - {chm_simple, MODE_NONICK }, /* d */ - {chm_ban, CHFL_EXCEPTION }, /* e */ - {chm_forward, 0 }, /* f */ - {chm_simple, MODE_FREEINVITE }, /* g */ - {chm_halfop, 0 }, /* h */ - {chm_simple, MODE_INVITEONLY }, /* i */ - {chm_throttle, 0 }, /* j */ - {chm_key, 0 }, /* k */ - {chm_limit, 0 }, /* l */ - {chm_simple, MODE_MODERATED }, /* m */ - {chm_simple, MODE_NOPRIVMSGS }, /* n */ - {chm_op, 0 }, /* o */ - {chm_simple, MODE_PRIVATE }, /* p */ - {chm_ban, CHFL_QUIET }, /* q */ - {chm_simple, MODE_REGONLY }, /* r */ - {chm_simple, MODE_SECRET }, /* s */ - {chm_simple, MODE_TOPICLIMIT }, /* t */ - {chm_simple, MODE_HIDEBANS }, /* u */ - {chm_voice, 0 }, /* v */ - {chm_nosuch, 0 }, /* w */ - {chm_nosuch, 0 }, /* x */ - {chm_owner, 0 }, /* y */ - {chm_simple, MODE_OPMODERATE }, /* z */ + {chm_nosuch, 0 }, /* @ */ + {chm_nosuch, 0 }, /* A */ + {chm_nosuch, 0 }, /* B */ + {chm_simple, MODE_NOCTCP }, /* C */ + {chm_simple, MODE_NOACTION }, /* D */ + {chm_simple, MODE_NOKICK }, /* E */ + {chm_simple, MODE_FREETARGET }, /* F */ + {chm_simple, MODE_NOCAPS }, /* G */ + {chm_nosuch, 0 }, /* H */ + {chm_ban, CHFL_INVEX }, /* I */ + {chm_simple, MODE_NOREJOIN }, /* J */ + {chm_simple, MODE_NOREPEAT }, /* K */ + {chm_staff, MODE_EXLIMIT }, /* L */ + {chm_hidden, MODE_NOOPERKICK }, /* M */ + {chm_nosuch, 0 }, /* N */ + {chm_nosuch, 0 }, /* O */ + {chm_staff, MODE_PERMANENT }, /* P */ + {chm_simple, MODE_DISFORWARD }, /* Q */ + {chm_nosuch, 0 }, /* R */ + {chm_nosuch, 0 }, /* S */ + {chm_simple, MODE_NONOTICE }, /* T */ + {chm_nosuch, 0 }, /* U */ + {chm_nosuch, 0 }, /* V */ + {chm_nosuch, 0 }, /* W */ + {chm_nosuch, 0 }, /* X */ + {chm_nosuch, 0 }, /* Y */ + {chm_nosuch, 0 }, /* Z */ + {chm_nosuch, 0 }, + {chm_nosuch, 0 }, + {chm_nosuch, 0 }, + {chm_nosuch, 0 }, + {chm_nosuch, 0 }, + {chm_nosuch, 0 }, + {chm_admin, 0 }, /* a */ + {chm_ban, CHFL_BAN }, /* b */ + {chm_simple, MODE_NOCOLOR }, /* c */ + {chm_simple, MODE_NONICK }, /* d */ + {chm_ban, CHFL_EXCEPTION }, /* e */ + {chm_forward, 0 }, /* f */ + {chm_simple, MODE_FREEINVITE }, /* g */ + {chm_halfop, 0 }, /* h */ + {chm_simple, MODE_INVITEONLY }, /* i */ + {chm_throttle, 0 }, /* j */ + {chm_key, 0 }, /* k */ + {chm_limit, 0 }, /* l */ + {chm_simple, MODE_MODERATED }, /* m */ + {chm_simple, MODE_NOPRIVMSGS }, /* n */ + {chm_op, 0 }, /* o */ + {chm_simple, MODE_PRIVATE }, /* p */ + {chm_ban, CHFL_QUIET }, /* q */ + {chm_simple, MODE_REGONLY }, /* r */ + {chm_simple, MODE_SECRET }, /* s */ + {chm_simple, MODE_TOPICLIMIT }, /* t */ + {chm_simple, MODE_HIDEBANS }, /* u */ + {chm_voice, 0 }, /* v */ + {chm_nosuch, 0 }, /* w */ + {chm_nosuch, 0 }, /* x */ + {chm_owner, 0 }, /* y */ + {chm_simple, MODE_OPMODERATE }, /* z */ - {chm_nosuch, 0 }, /* 0x7b */ - {chm_nosuch, 0 }, /* 0x7c */ - {chm_nosuch, 0 }, /* 0x7d */ - {chm_nosuch, 0 }, /* 0x7e */ - {chm_nosuch, 0 }, /* 0x7f */ + {chm_nosuch, 0 }, /* 0x7b */ + {chm_nosuch, 0 }, /* 0x7c */ + {chm_nosuch, 0 }, /* 0x7d */ + {chm_nosuch, 0 }, /* 0x7e */ + {chm_nosuch, 0 }, /* 0x7f */ - {chm_nosuch, 0 }, /* 0x80 */ - {chm_nosuch, 0 }, /* 0x81 */ - {chm_nosuch, 0 }, /* 0x82 */ - {chm_nosuch, 0 }, /* 0x83 */ - {chm_nosuch, 0 }, /* 0x84 */ - {chm_nosuch, 0 }, /* 0x85 */ - {chm_nosuch, 0 }, /* 0x86 */ - {chm_nosuch, 0 }, /* 0x87 */ - {chm_nosuch, 0 }, /* 0x88 */ - {chm_nosuch, 0 }, /* 0x89 */ - {chm_nosuch, 0 }, /* 0x8a */ - {chm_nosuch, 0 }, /* 0x8b */ - {chm_nosuch, 0 }, /* 0x8c */ - {chm_nosuch, 0 }, /* 0x8d */ - {chm_nosuch, 0 }, /* 0x8e */ - {chm_nosuch, 0 }, /* 0x8f */ + {chm_nosuch, 0 }, /* 0x80 */ + {chm_nosuch, 0 }, /* 0x81 */ + {chm_nosuch, 0 }, /* 0x82 */ + {chm_nosuch, 0 }, /* 0x83 */ + {chm_nosuch, 0 }, /* 0x84 */ + {chm_nosuch, 0 }, /* 0x85 */ + {chm_nosuch, 0 }, /* 0x86 */ + {chm_nosuch, 0 }, /* 0x87 */ + {chm_nosuch, 0 }, /* 0x88 */ + {chm_nosuch, 0 }, /* 0x89 */ + {chm_nosuch, 0 }, /* 0x8a */ + {chm_nosuch, 0 }, /* 0x8b */ + {chm_nosuch, 0 }, /* 0x8c */ + {chm_nosuch, 0 }, /* 0x8d */ + {chm_nosuch, 0 }, /* 0x8e */ + {chm_nosuch, 0 }, /* 0x8f */ - {chm_nosuch, 0 }, /* 0x90 */ - {chm_nosuch, 0 }, /* 0x91 */ - {chm_nosuch, 0 }, /* 0x92 */ - {chm_nosuch, 0 }, /* 0x93 */ - {chm_nosuch, 0 }, /* 0x94 */ - {chm_nosuch, 0 }, /* 0x95 */ - {chm_nosuch, 0 }, /* 0x96 */ - {chm_nosuch, 0 }, /* 0x97 */ - {chm_nosuch, 0 }, /* 0x98 */ - {chm_nosuch, 0 }, /* 0x99 */ - {chm_nosuch, 0 }, /* 0x9a */ - {chm_nosuch, 0 }, /* 0x9b */ - {chm_nosuch, 0 }, /* 0x9c */ - {chm_nosuch, 0 }, /* 0x9d */ - {chm_nosuch, 0 }, /* 0x9e */ - {chm_nosuch, 0 }, /* 0x9f */ + {chm_nosuch, 0 }, /* 0x90 */ + {chm_nosuch, 0 }, /* 0x91 */ + {chm_nosuch, 0 }, /* 0x92 */ + {chm_nosuch, 0 }, /* 0x93 */ + {chm_nosuch, 0 }, /* 0x94 */ + {chm_nosuch, 0 }, /* 0x95 */ + {chm_nosuch, 0 }, /* 0x96 */ + {chm_nosuch, 0 }, /* 0x97 */ + {chm_nosuch, 0 }, /* 0x98 */ + {chm_nosuch, 0 }, /* 0x99 */ + {chm_nosuch, 0 }, /* 0x9a */ + {chm_nosuch, 0 }, /* 0x9b */ + {chm_nosuch, 0 }, /* 0x9c */ + {chm_nosuch, 0 }, /* 0x9d */ + {chm_nosuch, 0 }, /* 0x9e */ + {chm_nosuch, 0 }, /* 0x9f */ - {chm_nosuch, 0 }, /* 0xa0 */ - {chm_nosuch, 0 }, /* 0xa1 */ - {chm_nosuch, 0 }, /* 0xa2 */ - {chm_nosuch, 0 }, /* 0xa3 */ - {chm_nosuch, 0 }, /* 0xa4 */ - {chm_nosuch, 0 }, /* 0xa5 */ - {chm_nosuch, 0 }, /* 0xa6 */ - {chm_nosuch, 0 }, /* 0xa7 */ - {chm_nosuch, 0 }, /* 0xa8 */ - {chm_nosuch, 0 }, /* 0xa9 */ - {chm_nosuch, 0 }, /* 0xaa */ - {chm_nosuch, 0 }, /* 0xab */ - {chm_nosuch, 0 }, /* 0xac */ - {chm_nosuch, 0 }, /* 0xad */ - {chm_nosuch, 0 }, /* 0xae */ - {chm_nosuch, 0 }, /* 0xaf */ + {chm_nosuch, 0 }, /* 0xa0 */ + {chm_nosuch, 0 }, /* 0xa1 */ + {chm_nosuch, 0 }, /* 0xa2 */ + {chm_nosuch, 0 }, /* 0xa3 */ + {chm_nosuch, 0 }, /* 0xa4 */ + {chm_nosuch, 0 }, /* 0xa5 */ + {chm_nosuch, 0 }, /* 0xa6 */ + {chm_nosuch, 0 }, /* 0xa7 */ + {chm_nosuch, 0 }, /* 0xa8 */ + {chm_nosuch, 0 }, /* 0xa9 */ + {chm_nosuch, 0 }, /* 0xaa */ + {chm_nosuch, 0 }, /* 0xab */ + {chm_nosuch, 0 }, /* 0xac */ + {chm_nosuch, 0 }, /* 0xad */ + {chm_nosuch, 0 }, /* 0xae */ + {chm_nosuch, 0 }, /* 0xaf */ - {chm_nosuch, 0 }, /* 0xb0 */ - {chm_nosuch, 0 }, /* 0xb1 */ - {chm_nosuch, 0 }, /* 0xb2 */ - {chm_nosuch, 0 }, /* 0xb3 */ - {chm_nosuch, 0 }, /* 0xb4 */ - {chm_nosuch, 0 }, /* 0xb5 */ - {chm_nosuch, 0 }, /* 0xb6 */ - {chm_nosuch, 0 }, /* 0xb7 */ - {chm_nosuch, 0 }, /* 0xb8 */ - {chm_nosuch, 0 }, /* 0xb9 */ - {chm_nosuch, 0 }, /* 0xba */ - {chm_nosuch, 0 }, /* 0xbb */ - {chm_nosuch, 0 }, /* 0xbc */ - {chm_nosuch, 0 }, /* 0xbd */ - {chm_nosuch, 0 }, /* 0xbe */ - {chm_nosuch, 0 }, /* 0xbf */ + {chm_nosuch, 0 }, /* 0xb0 */ + {chm_nosuch, 0 }, /* 0xb1 */ + {chm_nosuch, 0 }, /* 0xb2 */ + {chm_nosuch, 0 }, /* 0xb3 */ + {chm_nosuch, 0 }, /* 0xb4 */ + {chm_nosuch, 0 }, /* 0xb5 */ + {chm_nosuch, 0 }, /* 0xb6 */ + {chm_nosuch, 0 }, /* 0xb7 */ + {chm_nosuch, 0 }, /* 0xb8 */ + {chm_nosuch, 0 }, /* 0xb9 */ + {chm_nosuch, 0 }, /* 0xba */ + {chm_nosuch, 0 }, /* 0xbb */ + {chm_nosuch, 0 }, /* 0xbc */ + {chm_nosuch, 0 }, /* 0xbd */ + {chm_nosuch, 0 }, /* 0xbe */ + {chm_nosuch, 0 }, /* 0xbf */ - {chm_nosuch, 0 }, /* 0xc0 */ - {chm_nosuch, 0 }, /* 0xc1 */ - {chm_nosuch, 0 }, /* 0xc2 */ - {chm_nosuch, 0 }, /* 0xc3 */ - {chm_nosuch, 0 }, /* 0xc4 */ - {chm_nosuch, 0 }, /* 0xc5 */ - {chm_nosuch, 0 }, /* 0xc6 */ - {chm_nosuch, 0 }, /* 0xc7 */ - {chm_nosuch, 0 }, /* 0xc8 */ - {chm_nosuch, 0 }, /* 0xc9 */ - {chm_nosuch, 0 }, /* 0xca */ - {chm_nosuch, 0 }, /* 0xcb */ - {chm_nosuch, 0 }, /* 0xcc */ - {chm_nosuch, 0 }, /* 0xcd */ - {chm_nosuch, 0 }, /* 0xce */ - {chm_nosuch, 0 }, /* 0xcf */ + {chm_nosuch, 0 }, /* 0xc0 */ + {chm_nosuch, 0 }, /* 0xc1 */ + {chm_nosuch, 0 }, /* 0xc2 */ + {chm_nosuch, 0 }, /* 0xc3 */ + {chm_nosuch, 0 }, /* 0xc4 */ + {chm_nosuch, 0 }, /* 0xc5 */ + {chm_nosuch, 0 }, /* 0xc6 */ + {chm_nosuch, 0 }, /* 0xc7 */ + {chm_nosuch, 0 }, /* 0xc8 */ + {chm_nosuch, 0 }, /* 0xc9 */ + {chm_nosuch, 0 }, /* 0xca */ + {chm_nosuch, 0 }, /* 0xcb */ + {chm_nosuch, 0 }, /* 0xcc */ + {chm_nosuch, 0 }, /* 0xcd */ + {chm_nosuch, 0 }, /* 0xce */ + {chm_nosuch, 0 }, /* 0xcf */ - {chm_nosuch, 0 }, /* 0xd0 */ - {chm_nosuch, 0 }, /* 0xd1 */ - {chm_nosuch, 0 }, /* 0xd2 */ - {chm_nosuch, 0 }, /* 0xd3 */ - {chm_nosuch, 0 }, /* 0xd4 */ - {chm_nosuch, 0 }, /* 0xd5 */ - {chm_nosuch, 0 }, /* 0xd6 */ - {chm_nosuch, 0 }, /* 0xd7 */ - {chm_nosuch, 0 }, /* 0xd8 */ - {chm_nosuch, 0 }, /* 0xd9 */ - {chm_nosuch, 0 }, /* 0xda */ - {chm_nosuch, 0 }, /* 0xdb */ - {chm_nosuch, 0 }, /* 0xdc */ - {chm_nosuch, 0 }, /* 0xdd */ - {chm_nosuch, 0 }, /* 0xde */ - {chm_nosuch, 0 }, /* 0xdf */ + {chm_nosuch, 0 }, /* 0xd0 */ + {chm_nosuch, 0 }, /* 0xd1 */ + {chm_nosuch, 0 }, /* 0xd2 */ + {chm_nosuch, 0 }, /* 0xd3 */ + {chm_nosuch, 0 }, /* 0xd4 */ + {chm_nosuch, 0 }, /* 0xd5 */ + {chm_nosuch, 0 }, /* 0xd6 */ + {chm_nosuch, 0 }, /* 0xd7 */ + {chm_nosuch, 0 }, /* 0xd8 */ + {chm_nosuch, 0 }, /* 0xd9 */ + {chm_nosuch, 0 }, /* 0xda */ + {chm_nosuch, 0 }, /* 0xdb */ + {chm_nosuch, 0 }, /* 0xdc */ + {chm_nosuch, 0 }, /* 0xdd */ + {chm_nosuch, 0 }, /* 0xde */ + {chm_nosuch, 0 }, /* 0xdf */ - {chm_nosuch, 0 }, /* 0xe0 */ - {chm_nosuch, 0 }, /* 0xe1 */ - {chm_nosuch, 0 }, /* 0xe2 */ - {chm_nosuch, 0 }, /* 0xe3 */ - {chm_nosuch, 0 }, /* 0xe4 */ - {chm_nosuch, 0 }, /* 0xe5 */ - {chm_nosuch, 0 }, /* 0xe6 */ - {chm_nosuch, 0 }, /* 0xe7 */ - {chm_nosuch, 0 }, /* 0xe8 */ - {chm_nosuch, 0 }, /* 0xe9 */ - {chm_nosuch, 0 }, /* 0xea */ - {chm_nosuch, 0 }, /* 0xeb */ - {chm_nosuch, 0 }, /* 0xec */ - {chm_nosuch, 0 }, /* 0xed */ - {chm_nosuch, 0 }, /* 0xee */ - {chm_nosuch, 0 }, /* 0xef */ + {chm_nosuch, 0 }, /* 0xe0 */ + {chm_nosuch, 0 }, /* 0xe1 */ + {chm_nosuch, 0 }, /* 0xe2 */ + {chm_nosuch, 0 }, /* 0xe3 */ + {chm_nosuch, 0 }, /* 0xe4 */ + {chm_nosuch, 0 }, /* 0xe5 */ + {chm_nosuch, 0 }, /* 0xe6 */ + {chm_nosuch, 0 }, /* 0xe7 */ + {chm_nosuch, 0 }, /* 0xe8 */ + {chm_nosuch, 0 }, /* 0xe9 */ + {chm_nosuch, 0 }, /* 0xea */ + {chm_nosuch, 0 }, /* 0xeb */ + {chm_nosuch, 0 }, /* 0xec */ + {chm_nosuch, 0 }, /* 0xed */ + {chm_nosuch, 0 }, /* 0xee */ + {chm_nosuch, 0 }, /* 0xef */ - {chm_nosuch, 0 }, /* 0xf0 */ - {chm_nosuch, 0 }, /* 0xf1 */ - {chm_nosuch, 0 }, /* 0xf2 */ - {chm_nosuch, 0 }, /* 0xf3 */ - {chm_nosuch, 0 }, /* 0xf4 */ - {chm_nosuch, 0 }, /* 0xf5 */ - {chm_nosuch, 0 }, /* 0xf6 */ - {chm_nosuch, 0 }, /* 0xf7 */ - {chm_nosuch, 0 }, /* 0xf8 */ - {chm_nosuch, 0 }, /* 0xf9 */ - {chm_nosuch, 0 }, /* 0xfa */ - {chm_nosuch, 0 }, /* 0xfb */ - {chm_nosuch, 0 }, /* 0xfc */ - {chm_nosuch, 0 }, /* 0xfd */ - {chm_nosuch, 0 }, /* 0xfe */ - {chm_nosuch, 0 }, /* 0xff */ + {chm_nosuch, 0 }, /* 0xf0 */ + {chm_nosuch, 0 }, /* 0xf1 */ + {chm_nosuch, 0 }, /* 0xf2 */ + {chm_nosuch, 0 }, /* 0xf3 */ + {chm_nosuch, 0 }, /* 0xf4 */ + {chm_nosuch, 0 }, /* 0xf5 */ + {chm_nosuch, 0 }, /* 0xf6 */ + {chm_nosuch, 0 }, /* 0xf7 */ + {chm_nosuch, 0 }, /* 0xf8 */ + {chm_nosuch, 0 }, /* 0xf9 */ + {chm_nosuch, 0 }, /* 0xfa */ + {chm_nosuch, 0 }, /* 0xfb */ + {chm_nosuch, 0 }, /* 0xfc */ + {chm_nosuch, 0 }, /* 0xfd */ + {chm_nosuch, 0 }, /* 0xfe */ + {chm_nosuch, 0 }, /* 0xff */ }; /* *INDENT-ON* */ @@ -2162,239 +2006,218 @@ struct ChannelMode chmode_table[256] = /* set_channel_mode() * * inputs - client, source, channel, membership pointer, params - * output - + * output - * side effects - channel modes/memberships are changed, MODE is issued * * Extensively modified to be hotpluggable, 03/09/06 -- nenolod */ void set_channel_mode(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) + struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) { - static char cmdbuf[BUFSIZE]; - static char modebuf[BUFSIZE]; - static char parabuf[BUFSIZE]; - char *mbuf; - char *pbuf; - int cur_len, mlen, paralen, paracount, arglen, len; - int i, j, flags, override; - int dir = MODE_ADD; - int parn = 1; - int errors = 0; - int alevel; - const char *ml = parv[0]; - char c; - struct Client *fakesource_p; - int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; + static char cmdbuf[BUFSIZE]; + static char modebuf[BUFSIZE]; + static char parabuf[BUFSIZE]; + char *mbuf; + char *pbuf; + int cur_len, mlen, paralen, paracount, arglen, len; + int i, j, flags, override; + int dir = MODE_ADD; + int parn = 1; + int errors = 0; + int alevel; + const char *ml = parv[0]; + char c; + struct Client *fakesource_p; + int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; - mask_pos = 0; - mode_count = 0; - mode_limit = 0; - mode_limit_simple = 0; + mask_pos = 0; + mode_count = 0; + mode_limit = 0; + mode_limit_simple = 0; - alevel = get_channel_access(source_p, msptr); + alevel = get_channel_access(source_p, msptr); - no_override_deop = 0; + no_override_deop = 0; - /* Hide connecting server on netburst -- jilles */ - if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) - fakesource_p = &me; - else - fakesource_p = source_p; + /* Hide connecting server on netburst -- jilles */ + if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) + fakesource_p = &me; + else + fakesource_p = source_p; - for(; (c = *ml) != 0; ml++) - { - switch (c) - { - case '+': - dir = MODE_ADD; - break; - case '-': - dir = MODE_DEL; - break; - case '=': - dir = MODE_QUERY; - break; - default: - /* If this mode char is locked, don't allow local users to change it. */ - if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c)) - { - if (!(errors & SM_ERR_MLOCK)) - sendto_one_numeric(source_p, - ERR_MLOCKRESTRICTED, - form_str(ERR_MLOCKRESTRICTED), - chptr->chname, - c, - chptr->mode_lock); - errors |= SM_ERR_MLOCK; - continue; - } - chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel, - parc, &parn, parv, - &errors, dir, c, - chmode_table[(unsigned char) c].mode_type); - break; - } - } + for(; (c = *ml) != 0; ml++) { + switch (c) { + case '+': + dir = MODE_ADD; + break; + case '-': + dir = MODE_DEL; + break; + case '=': + dir = MODE_QUERY; + break; + default: + /* If this mode char is locked, don't allow local users to change it. */ + if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c)) { + if (!(errors & SM_ERR_MLOCK)) + sendto_one_numeric(source_p, + ERR_MLOCKRESTRICTED, + form_str(ERR_MLOCKRESTRICTED), + chptr->chname, + c, + chptr->mode_lock); + errors |= SM_ERR_MLOCK; + continue; + } + chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel, + parc, &parn, parv, + &errors, dir, c, + chmode_table[(unsigned char) c].mode_type); + break; + } + } - /* bail out if we have nothing to do... */ - if(!mode_count) - return; + /* bail out if we have nothing to do... */ + if(!mode_count) + return; - if(IsServer(source_p)) - rb_sprintf(cmdbuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); - else - rb_sprintf(cmdbuf, ":%s!%s@%s MODE %s ", - source_p->name, source_p->username, - source_p->host, chptr->chname); + if(IsServer(source_p)) + rb_sprintf(cmdbuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); + else + rb_sprintf(cmdbuf, ":%s!%s@%s MODE %s ", + source_p->name, source_p->username, + source_p->host, chptr->chname); - mlen = 0; + mlen = 0; - for (override = 0; override < (IsOverride(source_p) && alevel != CHFL_CHANOP ? 2 : 1); ++override) - { - int was_on_chan = 0; + for (override = 0; override < (IsOverride(source_p) && alevel != CHFL_CHANOP ? 2 : 1); ++override) { + int was_on_chan = 0; - if(override) - { - if(msptr) - { - was_on_chan = 1; - msptr->flags |= CHFL_CHANOP; - } - else - add_user_to_channel(chptr, source_p, CHFL_CHANOP); - } + if(override) { + if(msptr) { + was_on_chan = 1; + msptr->flags |= CHFL_CHANOP; + } else + add_user_to_channel(chptr, source_p, CHFL_CHANOP); + } - for(j = 0; j < 3; j++) - { - flags = flags_list[j]; - cur_len = mlen; - mbuf = modebuf + mlen; - pbuf = parabuf; - parabuf[0] = '\0'; - paracount = paralen = 0; - dir = MODE_QUERY; + for(j = 0; j < 3; j++) { + flags = flags_list[j]; + cur_len = mlen; + mbuf = modebuf + mlen; + pbuf = parabuf; + parabuf[0] = '\0'; + paracount = paralen = 0; + dir = MODE_QUERY; - for(i = 0; i < mode_count; i++) - { - if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) - continue; + for(i = 0; i < mode_count; i++) { + if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) + continue; - if(mode_changes[i].override != override) - continue; + if(mode_changes[i].override != override) + continue; - if(mode_changes[i].arg != NULL) - { - arglen = strlen(mode_changes[i].arg); + if(mode_changes[i].arg != NULL) { + arglen = strlen(mode_changes[i].arg); - if(arglen > MODEBUFLEN - 5) - continue; - } - else - arglen = 0; + if(arglen > MODEBUFLEN - 5) + continue; + } else + arglen = 0; - /* if we're creeping over MAXMODEPARAMSSERV, or over - * bufsize (4 == +/-,modechar,two spaces) send now. - */ - if(mode_changes[i].arg != NULL && - ((paracount == MAXMODEPARAMSSERV) || - ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) - { - *mbuf = '\0'; + /* if we're creeping over MAXMODEPARAMSSERV, or over + * bufsize (4 == +/-,modechar,two spaces) send now. + */ + if(mode_changes[i].arg != NULL && + ((paracount == MAXMODEPARAMSSERV) || + ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) { + *mbuf = '\0'; - if(cur_len > mlen) - { - sendto_channel_local(flags, chptr, "%s%s %s", - cmdbuf, modebuf, parabuf); - if(override) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding modes on %s: %s %s", - get_oper_name(source_p), chptr->chname, modebuf, parabuf); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding modes on %s: %s %s", - me.name, get_oper_name(source_p), chptr->chname, modebuf, parabuf); - } - } - else - continue; + if(cur_len > mlen) { + sendto_channel_local(flags, chptr, "%s%s %s", + cmdbuf, modebuf, parabuf); + if(override) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding modes on %s: %s %s", + get_oper_name(source_p), chptr->chname, modebuf, parabuf); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding modes on %s: %s %s", + me.name, get_oper_name(source_p), chptr->chname, modebuf, parabuf); + } + } else + continue; - paracount = paralen = 0; - cur_len = mlen; - mbuf = modebuf + mlen; - pbuf = parabuf; - parabuf[0] = '\0'; - dir = MODE_QUERY; - } + paracount = paralen = 0; + cur_len = mlen; + mbuf = modebuf + mlen; + pbuf = parabuf; + parabuf[0] = '\0'; + dir = MODE_QUERY; + } - if(dir != mode_changes[i].dir) - { - *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; - cur_len++; - dir = mode_changes[i].dir; - } + if(dir != mode_changes[i].dir) { + *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; + cur_len++; + dir = mode_changes[i].dir; + } - *mbuf++ = mode_changes[i].letter; - cur_len++; + *mbuf++ = mode_changes[i].letter; + cur_len++; - if(mode_changes[i].arg != NULL) - { - paracount++; - len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg); - pbuf += len; - paralen += len; - } - } + if(mode_changes[i].arg != NULL) { + paracount++; + len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg); + pbuf += len; + paralen += len; + } + } - if(paralen && parabuf[paralen - 1] == ' ') - parabuf[paralen - 1] = '\0'; + if(paralen && parabuf[paralen - 1] == ' ') + parabuf[paralen - 1] = '\0'; - *mbuf = '\0'; - if(cur_len > mlen) - { - sendto_channel_local(flags, chptr, "%s%s %s", cmdbuf, modebuf, parabuf); - if(override) - { - sendto_wallops_flags(UMODE_WALLOP, &me, - "%s is overriding modes on %s: %s %s", - get_oper_name(source_p), chptr->chname, modebuf, parabuf); - sendto_server(NULL, chptr, NOCAPS, NOCAPS, - ":%s WALLOPS :%s is overriding modes on %s: %s %s", - me.name, get_oper_name(source_p), chptr->chname, modebuf, parabuf); - } - } - } - if(override) - { - if(!was_on_chan) - remove_user_from_channel(find_channel_membership(chptr, source_p)); - else if (!no_override_deop) - msptr->flags &= ~CHFL_CHANOP; - } - } + *mbuf = '\0'; + if(cur_len > mlen) { + sendto_channel_local(flags, chptr, "%s%s %s", cmdbuf, modebuf, parabuf); + if(override) { + sendto_wallops_flags(UMODE_WALLOP, &me, + "%s is overriding modes on %s: %s %s", + get_oper_name(source_p), chptr->chname, modebuf, parabuf); + sendto_server(NULL, chptr, NOCAPS, NOCAPS, + ":%s WALLOPS :%s is overriding modes on %s: %s %s", + me.name, get_oper_name(source_p), chptr->chname, modebuf, parabuf); + } + } + } + if(override) { + if(!was_on_chan) + remove_user_from_channel(find_channel_membership(chptr, source_p)); + else if (!no_override_deop) + msptr->flags &= ~CHFL_CHANOP; + } + } - /* only propagate modes originating locally, or if we're hubbing */ - if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) - send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count); + /* only propagate modes originating locally, or if we're hubbing */ + if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) + send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count); } /* set_channel_mlock() * * inputs - client, source, channel, params - * output - + * output - * side effects - channel mlock is changed / MLOCK is propagated */ void set_channel_mlock(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, const char *newmlock, int propagate) + struct Channel *chptr, const char *newmlock, int propagate) { - rb_free(chptr->mode_lock); - chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL; + rb_free(chptr->mode_lock); + chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL; - if (propagate) - { - sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s", - source_p->id, (long) chptr->channelts, chptr->chname, - chptr->mode_lock ? chptr->mode_lock : ""); - } + if (propagate) { + sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s", + source_p->id, (long) chptr->channelts, chptr->chname, + chptr->mode_lock ? chptr->mode_lock : ""); + } } diff --git a/src/class.c b/src/class.c index 5998158..33abf3d 100644 --- a/src/class.c +++ b/src/class.c @@ -46,27 +46,27 @@ struct Class *default_class; struct Class * make_class(void) { - struct Class *tmp; + struct Class *tmp; - tmp = rb_malloc(sizeof(struct Class)); + tmp = rb_malloc(sizeof(struct Class)); - ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY; - PingFreq(tmp) = DEFAULT_PINGFREQUENCY; - MaxUsers(tmp) = 1; - MaxSendq(tmp) = DEFAULT_SENDQ; + ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY; + PingFreq(tmp) = DEFAULT_PINGFREQUENCY; + MaxUsers(tmp) = 1; + MaxSendq(tmp) = DEFAULT_SENDQ; - tmp->ip_limits = rb_new_patricia(PATRICIA_BITS); - return tmp; + tmp->ip_limits = rb_new_patricia(PATRICIA_BITS); + return tmp; } void free_class(struct Class *tmp) { - if(tmp->ip_limits) - rb_destroy_patricia(tmp->ip_limits, NULL); + if(tmp->ip_limits) + rb_destroy_patricia(tmp->ip_limits, NULL); - rb_free(tmp->class_name); - rb_free(tmp); + rb_free(tmp->class_name); + rb_free(tmp); } @@ -80,10 +80,10 @@ free_class(struct Class *tmp) static int get_conf_ping(struct ConfItem *aconf) { - if((aconf) && ClassPtr(aconf)) - return (ConfPingFreq(aconf)); + if((aconf) && ClassPtr(aconf)) + return (ConfPingFreq(aconf)); - return (BAD_PING); + return (BAD_PING); } /* @@ -96,28 +96,25 @@ get_conf_ping(struct ConfItem *aconf) const char * get_client_class(struct Client *target_p) { - const char *retc = "unknown"; + const char *retc = "unknown"; - if(target_p == NULL || IsMe(target_p)) - return retc; + if(target_p == NULL || IsMe(target_p)) + return retc; - if(IsServer(target_p)) - { - struct server_conf *server_p = target_p->localClient->att_sconf; - return server_p->class_name; - } - else - { - struct ConfItem *aconf; - aconf = target_p->localClient->att_conf; + if(IsServer(target_p)) { + struct server_conf *server_p = target_p->localClient->att_sconf; + return server_p->class_name; + } else { + struct ConfItem *aconf; + aconf = target_p->localClient->att_conf; - if((aconf == NULL) || (aconf->className == NULL)) - retc = "default"; - else - retc = aconf->className; - } + if((aconf == NULL) || (aconf->className == NULL)) + retc = "default"; + else + retc = aconf->className; + } - return (retc); + return (retc); } /* @@ -130,29 +127,26 @@ get_client_class(struct Client *target_p) int get_client_ping(struct Client *target_p) { - int ping = 0; + int ping = 0; - if(IsServer(target_p)) - { - struct server_conf *server_p = target_p->localClient->att_sconf; - ping = PingFreq(server_p->class); - } - else - { - struct ConfItem *aconf; + if(IsServer(target_p)) { + struct server_conf *server_p = target_p->localClient->att_sconf; + ping = PingFreq(server_p->class); + } else { + struct ConfItem *aconf; - aconf = target_p->localClient->att_conf; + aconf = target_p->localClient->att_conf; - if(aconf != NULL) - ping = get_conf_ping(aconf); - else - ping = DEFAULT_PINGFREQUENCY; - } + if(aconf != NULL) + ping = get_conf_ping(aconf); + else + ping = DEFAULT_PINGFREQUENCY; + } - if(ping <= 0) - ping = DEFAULT_PINGFREQUENCY; + if(ping <= 0) + ping = DEFAULT_PINGFREQUENCY; - return ping; + return ping; } /* @@ -165,9 +159,9 @@ get_client_ping(struct Client *target_p) int get_con_freq(struct Class *clptr) { - if(clptr) - return (ConFreq(clptr)); - return (DEFAULT_CONNECTFREQUENCY); + if(clptr) + return (ConFreq(clptr)); + return (DEFAULT_CONNECTFREQUENCY); } /* add_class() @@ -180,30 +174,27 @@ get_con_freq(struct Class *clptr) void add_class(struct Class *classptr) { - struct Class *tmpptr; + struct Class *tmpptr; - tmpptr = find_class(classptr->class_name); + tmpptr = find_class(classptr->class_name); - if(tmpptr == default_class) - { - rb_dlinkAddAlloc(classptr, &class_list); - CurrUsers(classptr) = 0; - } - else - { - MaxUsers(tmpptr) = MaxUsers(classptr); - MaxLocal(tmpptr) = MaxLocal(classptr); - MaxGlobal(tmpptr) = MaxGlobal(classptr); - MaxIdent(tmpptr) = MaxIdent(classptr); - PingFreq(tmpptr) = PingFreq(classptr); - MaxSendq(tmpptr) = MaxSendq(classptr); - ConFreq(tmpptr) = ConFreq(classptr); - CidrIpv4Bitlen(tmpptr) = CidrIpv4Bitlen(classptr); - CidrIpv6Bitlen(tmpptr) = CidrIpv6Bitlen(classptr); - CidrAmount(tmpptr) = CidrAmount(classptr); + if(tmpptr == default_class) { + rb_dlinkAddAlloc(classptr, &class_list); + CurrUsers(classptr) = 0; + } else { + MaxUsers(tmpptr) = MaxUsers(classptr); + MaxLocal(tmpptr) = MaxLocal(classptr); + MaxGlobal(tmpptr) = MaxGlobal(classptr); + MaxIdent(tmpptr) = MaxIdent(classptr); + PingFreq(tmpptr) = PingFreq(classptr); + MaxSendq(tmpptr) = MaxSendq(classptr); + ConFreq(tmpptr) = ConFreq(classptr); + CidrIpv4Bitlen(tmpptr) = CidrIpv4Bitlen(classptr); + CidrIpv6Bitlen(tmpptr) = CidrIpv6Bitlen(classptr); + CidrAmount(tmpptr) = CidrAmount(classptr); - free_class(classptr); - } + free_class(classptr); + } } @@ -217,21 +208,20 @@ add_class(struct Class *classptr) struct Class * find_class(const char *classname) { - struct Class *cltmp; - rb_dlink_node *ptr; + struct Class *cltmp; + rb_dlink_node *ptr; - if(classname == NULL) - return default_class; + if(classname == NULL) + return default_class; - RB_DLINK_FOREACH(ptr, class_list.head) - { - cltmp = ptr->data; + RB_DLINK_FOREACH(ptr, class_list.head) { + cltmp = ptr->data; - if(!strcmp(ClassName(cltmp), classname)) - return cltmp; - } + if(!strcmp(ClassName(cltmp), classname)) + return cltmp; + } - return default_class; + return default_class; } /* @@ -239,26 +229,24 @@ find_class(const char *classname) * * inputs - NONE * output - NONE - * side effects - + * side effects - */ void check_class() { - struct Class *cltmp; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct Class *cltmp; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, class_list.head) - { - cltmp = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, class_list.head) { + cltmp = ptr->data; - if(MaxUsers(cltmp) < 0) - { - rb_dlinkDestroy(ptr, &class_list); - if(CurrUsers(cltmp) <= 0) - free_class(cltmp); - } - } + if(MaxUsers(cltmp) < 0) { + rb_dlinkDestroy(ptr, &class_list); + if(CurrUsers(cltmp) <= 0) + free_class(cltmp); + } + } } /* @@ -266,13 +254,13 @@ check_class() * * inputs - NONE * output - NONE - * side effects - + * side effects - */ void initclass() { - default_class = make_class(); - ClassName(default_class) = rb_strdup("default"); + default_class = make_class(); + ClassName(default_class) = rb_strdup("default"); } /* @@ -285,31 +273,30 @@ initclass() void report_classes(struct Client *source_p) { - struct Class *cltmp; - rb_dlink_node *ptr; + struct Class *cltmp; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, class_list.head) - { - cltmp = ptr->data; + RB_DLINK_FOREACH(ptr, class_list.head) { + cltmp = ptr->data; - sendto_one_numeric(source_p, RPL_STATSYLINE, - form_str(RPL_STATSYLINE), - ClassName(cltmp), PingFreq(cltmp), - ConFreq(cltmp), MaxUsers(cltmp), - MaxSendq(cltmp), - MaxLocal(cltmp), MaxIdent(cltmp), - MaxGlobal(cltmp), MaxIdent(cltmp), - CurrUsers(cltmp)); - } + sendto_one_numeric(source_p, RPL_STATSYLINE, + form_str(RPL_STATSYLINE), + ClassName(cltmp), PingFreq(cltmp), + ConFreq(cltmp), MaxUsers(cltmp), + MaxSendq(cltmp), + MaxLocal(cltmp), MaxIdent(cltmp), + MaxGlobal(cltmp), MaxIdent(cltmp), + CurrUsers(cltmp)); + } - /* also output the default class */ - sendto_one_numeric(source_p, RPL_STATSYLINE, form_str(RPL_STATSYLINE), - ClassName(default_class), PingFreq(default_class), - ConFreq(default_class), MaxUsers(default_class), - MaxSendq(default_class), - MaxLocal(default_class), MaxIdent(default_class), - MaxGlobal(default_class), MaxIdent(default_class), - CurrUsers(default_class)); + /* also output the default class */ + sendto_one_numeric(source_p, RPL_STATSYLINE, form_str(RPL_STATSYLINE), + ClassName(default_class), PingFreq(default_class), + ConFreq(default_class), MaxUsers(default_class), + MaxSendq(default_class), + MaxLocal(default_class), MaxIdent(default_class), + MaxGlobal(default_class), MaxIdent(default_class), + CurrUsers(default_class)); } /* @@ -322,22 +309,19 @@ report_classes(struct Client *source_p) long get_sendq(struct Client *client_p) { - if(client_p == NULL || IsMe(client_p)) - return DEFAULT_SENDQ; + if(client_p == NULL || IsMe(client_p)) + return DEFAULT_SENDQ; - if(IsServer(client_p)) - { - struct server_conf *server_p; - server_p = client_p->localClient->att_sconf; - return MaxSendq(server_p->class); - } - else - { - struct ConfItem *aconf = client_p->localClient->att_conf; + if(IsServer(client_p)) { + struct server_conf *server_p; + server_p = client_p->localClient->att_sconf; + return MaxSendq(server_p->class); + } else { + struct ConfItem *aconf = client_p->localClient->att_conf; - if(aconf != NULL && aconf->status & CONF_CLIENT) - return ConfMaxSendq(aconf); - } + if(aconf != NULL && aconf->status & CONF_CLIENT) + return ConfMaxSendq(aconf); + } - return DEFAULT_SENDQ; + return DEFAULT_SENDQ; } diff --git a/src/client.c b/src/client.c index 107a21e..4315786 100644 --- a/src/client.c +++ b/src/client.c @@ -80,10 +80,9 @@ static char current_uid[IDLEN]; struct Dictionary *nd_dict = NULL; -enum -{ - D_LINED, - K_LINED +enum { + D_LINED, + K_LINED }; rb_dlink_list dead_list; @@ -91,11 +90,10 @@ rb_dlink_list dead_list; static rb_dlink_list dead_remote_list; #endif -struct abort_client -{ - rb_dlink_node node; - struct Client *client; - char notice[REASONLEN]; +struct abort_client { + rb_dlink_node node; + struct Client *client; + char notice[REASONLEN]; }; static rb_dlink_list abort_list; @@ -111,22 +109,22 @@ static rb_dlink_list abort_list; void init_client(void) { - /* - * start off the check ping event .. -- adrian - * Every 30 seconds is plenty -- db - */ - client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap"); - lclient_heap = rb_bh_create(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE, "lclient_heap"); - pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap"); - user_heap = rb_bh_create(sizeof(struct User), USER_HEAP_SIZE, "user_heap"); - away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap"); + /* + * start off the check ping event .. -- adrian + * Every 30 seconds is plenty -- db + */ + client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap"); + lclient_heap = rb_bh_create(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE, "lclient_heap"); + pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap"); + user_heap = rb_bh_create(sizeof(struct User), USER_HEAP_SIZE, "user_heap"); + away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap"); - rb_event_addish("check_pings", check_pings, NULL, 30); - rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4); - rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1); - rb_event_add("flood_recalc", flood_recalc, NULL, 1); + rb_event_addish("check_pings", check_pings, NULL, 30); + rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4); + rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1); + rb_event_add("flood_recalc", flood_recalc, NULL, 1); - nd_dict = irc_dictionary_create(irccmp); + nd_dict = irc_dictionary_create(irccmp); } @@ -143,126 +141,120 @@ init_client(void) struct Client * make_client(struct Client *from) { - struct Client *client_p = NULL; - struct LocalUser *localClient; + struct Client *client_p = NULL; + struct LocalUser *localClient; - client_p = rb_bh_alloc(client_heap); + client_p = rb_bh_alloc(client_heap); - if(from == NULL) - { - client_p->from = client_p; /* 'from' of local client is self! */ + if(from == NULL) { + client_p->from = client_p; /* 'from' of local client is self! */ - localClient = rb_bh_alloc(lclient_heap); - SetMyConnect(client_p); - client_p->localClient = localClient; + localClient = rb_bh_alloc(lclient_heap); + SetMyConnect(client_p); + client_p->localClient = localClient; - client_p->localClient->lasttime = client_p->localClient->firsttime = rb_current_time(); + client_p->localClient->lasttime = client_p->localClient->firsttime = rb_current_time(); - client_p->localClient->F = NULL; + client_p->localClient->F = NULL; - client_p->preClient = rb_bh_alloc(pclient_heap);; + client_p->preClient = rb_bh_alloc(pclient_heap);; - /* as good a place as any... */ - rb_dlinkAdd(client_p, &client_p->localClient->tnode, &unknown_list); - } - else - { /* from is not NULL */ - client_p->localClient = NULL; - client_p->preClient = NULL; - client_p->from = from; /* 'from' of local client is self! */ - } - - SetUnknown(client_p); - strcpy(client_p->username, "unknown"); + /* as good a place as any... */ + rb_dlinkAdd(client_p, &client_p->localClient->tnode, &unknown_list); + } else { + /* from is not NULL */ + client_p->localClient = NULL; + client_p->preClient = NULL; + client_p->from = from; /* 'from' of local client is self! */ + } - return client_p; + SetUnknown(client_p); + strcpy(client_p->username, "unknown"); + + return client_p; } void free_pre_client(struct Client *client_p) { - struct Blacklist *blptr; + struct Blacklist *blptr; - s_assert(NULL != client_p); + s_assert(NULL != client_p); - if(client_p->preClient == NULL) - return; + if(client_p->preClient == NULL) + return; - blptr = client_p->preClient->dnsbl_listed; - if (blptr != NULL) - unref_blacklist(blptr); - abort_blacklist_queries(client_p); - rb_bh_free(pclient_heap, client_p->preClient); - client_p->preClient = NULL; + blptr = client_p->preClient->dnsbl_listed; + if (blptr != NULL) + unref_blacklist(blptr); + abort_blacklist_queries(client_p); + rb_bh_free(pclient_heap, client_p->preClient); + client_p->preClient = NULL; } static void free_local_client(struct Client *client_p) { - s_assert(NULL != client_p); - s_assert(&me != client_p); + s_assert(NULL != client_p); + s_assert(&me != client_p); - if(client_p->localClient == NULL) - return; + if(client_p->localClient == NULL) + return; - /* - * clean up extra sockets from P-lines which have been discarded. - */ - if(client_p->localClient->listener) - { - s_assert(0 < client_p->localClient->listener->ref_count); - if(0 == --client_p->localClient->listener->ref_count - && !client_p->localClient->listener->active) - free_listener(client_p->localClient->listener); - client_p->localClient->listener = 0; - } + /* + * clean up extra sockets from P-lines which have been discarded. + */ + if(client_p->localClient->listener) { + s_assert(0 < client_p->localClient->listener->ref_count); + if(0 == --client_p->localClient->listener->ref_count + && !client_p->localClient->listener->active) + free_listener(client_p->localClient->listener); + client_p->localClient->listener = 0; + } - if(client_p->localClient->F != NULL) - { - del_from_cli_fd_hash(client_p); - rb_close(client_p->localClient->F); - } + if(client_p->localClient->F != NULL) { + del_from_cli_fd_hash(client_p); + rb_close(client_p->localClient->F); + } - if(client_p->localClient->passwd) - { - memset(client_p->localClient->passwd, 0, - strlen(client_p->localClient->passwd)); - rb_free(client_p->localClient->passwd); - } + if(client_p->localClient->passwd) { + memset(client_p->localClient->passwd, 0, + strlen(client_p->localClient->passwd)); + rb_free(client_p->localClient->passwd); + } - rb_free(client_p->localClient->auth_user); + rb_free(client_p->localClient->auth_user); - if(client_p->localClient->override_timeout_event) - { - rb_event_delete(client_p->localClient->override_timeout_event); - } + if(client_p->localClient->override_timeout_event) { + rb_event_delete(client_p->localClient->override_timeout_event); + } - rb_free(client_p->localClient->challenge); - rb_free(client_p->localClient->fullcaps); - rb_free(client_p->localClient->opername); - rb_free(client_p->localClient->mangledhost); - if (client_p->localClient->privset) - privilegeset_unref(client_p->localClient->privset); + rb_free(client_p->localClient->challenge); + rb_free(client_p->localClient->fullcaps); + rb_free(client_p->localClient->opername); + rb_free(client_p->localClient->mangledhost); + if (client_p->localClient->privset) + privilegeset_unref(client_p->localClient->privset); - if(IsSSL(client_p)) - ssld_decrement_clicount(client_p->localClient->ssl_ctl); - - if(IsCapable(client_p, CAP_ZIP)) - ssld_decrement_clicount(client_p->localClient->z_ctl); + if(IsSSL(client_p)) + ssld_decrement_clicount(client_p->localClient->ssl_ctl); - rb_bh_free(lclient_heap, client_p->localClient); - client_p->localClient = NULL; + if(IsCapable(client_p, CAP_ZIP)) + ssld_decrement_clicount(client_p->localClient->z_ctl); + + rb_bh_free(lclient_heap, client_p->localClient); + client_p->localClient = NULL; } void free_client(struct Client *client_p) { - s_assert(NULL != client_p); - s_assert(&me != client_p); - free_local_client(client_p); - free_pre_client(client_p); - rb_free(client_p->certfp); - rb_bh_free(client_heap, client_p); + s_assert(NULL != client_p); + s_assert(&me != client_p); + free_local_client(client_p); + free_pre_client(client_p); + rb_free(client_p->certfp); + rb_bh_free(client_heap, client_p); } /* @@ -271,7 +263,7 @@ free_client(struct Client *client_p) * * inputs - NOT USED (from event) * output - next time_t when check_pings() should be called again - * side effects - + * side effects - * * * A PING can be sent to clients as necessary. @@ -294,9 +286,9 @@ free_client(struct Client *client_p) static void check_pings(void *notused) { - check_pings_list(&lclient_list); - check_pings_list(&serv_list); - check_unknowns_list(&unknown_list); + check_pings_list(&lclient_list); + check_pings_list(&serv_list); + check_unknowns_list(&unknown_list); } /* @@ -304,66 +296,60 @@ check_pings(void *notused) * * inputs - pointer to list to check * output - NONE - * side effects - + * side effects - */ static void check_pings_list(rb_dlink_list * list) { - char scratch[32]; /* way too generous but... */ - struct Client *client_p; /* current local client_p being examined */ - int ping = 0; /* ping time value from client */ - rb_dlink_node *ptr, *next_ptr; + char scratch[32]; /* way too generous but... */ + struct Client *client_p; /* current local client_p being examined */ + int ping = 0; /* ping time value from client */ + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) { + client_p = ptr->data; - if(!MyConnect(client_p) || IsDead(client_p)) - continue; + if(!MyConnect(client_p) || IsDead(client_p)) + continue; - ping = get_client_ping(client_p); + ping = get_client_ping(client_p); - if(ping < (rb_current_time() - client_p->localClient->lasttime)) - { - /* - * If the client/server hasnt talked to us in 2*ping seconds - * and it has a ping time, then close its connection. - */ - if(((rb_current_time() - client_p->localClient->lasttime) >= (2 * ping) - && (client_p->flags & FLAGS_PINGSENT))) - { - if(IsServer(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "No response from %s, closing link", - client_p->name); - ilog(L_SERVER, - "No response from %s, closing link", - log_client_name(client_p, HIDE_IP)); - } - (void) rb_snprintf(scratch, sizeof(scratch), - "Ping timeout: %d seconds", - (int) (rb_current_time() - client_p->localClient->lasttime)); + if(ping < (rb_current_time() - client_p->localClient->lasttime)) { + /* + * If the client/server hasnt talked to us in 2*ping seconds + * and it has a ping time, then close its connection. + */ + if(((rb_current_time() - client_p->localClient->lasttime) >= (2 * ping) + && (client_p->flags & FLAGS_PINGSENT))) { + if(IsServer(client_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "No response from %s, closing link", + client_p->name); + ilog(L_SERVER, + "No response from %s, closing link", + log_client_name(client_p, HIDE_IP)); + } + (void) rb_snprintf(scratch, sizeof(scratch), + "Ping timeout: %d seconds", + (int) (rb_current_time() - client_p->localClient->lasttime)); - exit_client(client_p, client_p, &me, scratch); - continue; - } - else if((client_p->flags & FLAGS_PINGSENT) == 0) - { - /* - * if we havent PINGed the connection and we havent - * heard from it in a while, PING it to make sure - * it is still alive. - */ - client_p->flags |= FLAGS_PINGSENT; - /* not nice but does the job */ - client_p->localClient->lasttime = rb_current_time() - ping; - sendto_one(client_p, "PING :%s", me.name); - } - } - /* ping_timeout: */ + exit_client(client_p, client_p, &me, scratch); + continue; + } else if((client_p->flags & FLAGS_PINGSENT) == 0) { + /* + * if we havent PINGed the connection and we havent + * heard from it in a while, PING it to make sure + * it is still alive. + */ + client_p->flags |= FLAGS_PINGSENT; + /* not nice but does the job */ + client_p->localClient->lasttime = rb_current_time() - ping; + sendto_one(client_p, "PING :%s", me.name); + } + } + /* ping_timeout: */ - } + } } /* @@ -376,72 +362,66 @@ check_pings_list(rb_dlink_list * list) static void check_unknowns_list(rb_dlink_list * list) { - rb_dlink_node *ptr, *next_ptr; - struct Client *client_p; - int timeout; + rb_dlink_node *ptr, *next_ptr; + struct Client *client_p; + int timeout; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) { + client_p = ptr->data; - if(IsDead(client_p) || IsClosing(client_p)) - continue; + if(IsDead(client_p) || IsClosing(client_p)) + continue; - /* still has DNSbls to validate against */ - if(client_p->preClient != NULL && - rb_dlink_list_length(&client_p->preClient->dnsbl_queries) > 0) - continue; + /* still has DNSbls to validate against */ + if(client_p->preClient != NULL && + rb_dlink_list_length(&client_p->preClient->dnsbl_queries) > 0) + continue; - /* - * Check UNKNOWN connections - if they have been in this state - * for > 30s, close them. - */ + /* + * Check UNKNOWN connections - if they have been in this state + * for > 30s, close them. + */ - timeout = IsAnyServer(client_p) ? ConfigFileEntry.connect_timeout : 30; - if((rb_current_time() - client_p->localClient->firsttime) > timeout) - { - if(IsAnyServer(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "No response from %s, closing link", - client_p->name); - ilog(L_SERVER, - "No response from %s, closing link", - log_client_name(client_p, HIDE_IP)); - } - exit_client(client_p, client_p, &me, "Connection timed out"); - } - } + timeout = IsAnyServer(client_p) ? ConfigFileEntry.connect_timeout : 30; + if((rb_current_time() - client_p->localClient->firsttime) > timeout) { + if(IsAnyServer(client_p)) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "No response from %s, closing link", + client_p->name); + ilog(L_SERVER, + "No response from %s, closing link", + log_client_name(client_p, HIDE_IP)); + } + exit_client(client_p, client_p, &me, "Connection timed out"); + } + } } static void notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban) { - static const char conn_closed[] = "Connection closed"; - static const char d_lined[] = "D-lined"; - static const char k_lined[] = "K-lined"; - const char *reason = NULL; - const char *exit_reason = conn_closed; + static const char conn_closed[] = "Connection closed"; + static const char d_lined[] = "D-lined"; + static const char k_lined[] = "K-lined"; + const char *reason = NULL; + const char *exit_reason = conn_closed; - if(ConfigFileEntry.kline_with_reason) - { - reason = get_user_ban_reason(aconf); - exit_reason = reason; - } - else - { - reason = aconf->status == D_LINED ? d_lined : k_lined; - } + if(ConfigFileEntry.kline_with_reason) { + reason = get_user_ban_reason(aconf); + exit_reason = reason; + } else { + reason = aconf->status == D_LINED ? d_lined : k_lined; + } - if(ban == D_LINED && !IsPerson(client_p)) - sendto_one(client_p, "NOTICE DLINE :*** You have been D-lined"); - else - sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP), - me.name, client_p->name, reason); - - exit_client(client_p, client_p, &me, - EmptyString(ConfigFileEntry.kline_reason) ? exit_reason : - ConfigFileEntry.kline_reason); + if(ban == D_LINED && !IsPerson(client_p)) + sendto_one(client_p, "NOTICE DLINE :*** You have been D-lined"); + else + sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP), + me.name, client_p->name, reason); + + exit_client(client_p, client_p, &me, + EmptyString(ConfigFileEntry.kline_reason) ? exit_reason : + ConfigFileEntry.kline_reason); } /* @@ -454,9 +434,9 @@ notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban) void check_banned_lines(void) { - check_dlines(); - check_klines(); - check_xlines(); + check_dlines(); + check_klines(); + check_xlines(); } /* check_klines_event() @@ -468,8 +448,8 @@ check_banned_lines(void) void check_klines_event(void *unused) { - kline_queued = 0; - check_klines(); + kline_queued = 0; + check_klines(); } /* check_klines @@ -481,37 +461,34 @@ check_klines_event(void *unused) void check_klines(void) { - struct Client *client_p; - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct Client *client_p; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { + client_p = ptr->data; - if(IsMe(client_p) || !IsPerson(client_p)) - continue; + if(IsMe(client_p) || !IsPerson(client_p)) + continue; - if((aconf = find_kline(client_p)) != NULL) - { - if(IsExemptKline(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "KLINE over-ruled for %s, client is kline_exempt [%s@%s]", - get_client_name(client_p, HIDE_IP), - aconf->user, aconf->host); - continue; - } + if((aconf = find_kline(client_p)) != NULL) { + if(IsExemptKline(client_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "KLINE over-ruled for %s, client is kline_exempt [%s@%s]", + get_client_name(client_p, HIDE_IP), + aconf->user, aconf->host); + continue; + } - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "KLINE active for %s", - get_client_name(client_p, HIDE_IP)); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "KLINE active for %s", + get_client_name(client_p, HIDE_IP)); - notify_banned_client(client_p, aconf, K_LINED); - continue; - } - } + notify_banned_client(client_p, aconf, K_LINED); + continue; + } + } } /* check_dlines() @@ -523,45 +500,41 @@ check_klines(void) void check_dlines(void) { - struct Client *client_p; - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct Client *client_p; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { + client_p = ptr->data; - if(IsMe(client_p)) - continue; + if(IsMe(client_p)) + continue; - if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL) - { - if(aconf->status & CONF_EXEMPTDLINE) - continue; + if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL) { + if(aconf->status & CONF_EXEMPTDLINE) + continue; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "DLINE active for %s", - get_client_name(client_p, HIDE_IP)); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "DLINE active for %s", + get_client_name(client_p, HIDE_IP)); - notify_banned_client(client_p, aconf, D_LINED); - continue; - } - } + notify_banned_client(client_p, aconf, D_LINED); + continue; + } + } - /* dlines need to be checked against unknowns too */ - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) - { - client_p = ptr->data; + /* dlines need to be checked against unknowns too */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) { + client_p = ptr->data; - if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL) - { - if(aconf->status & CONF_EXEMPTDLINE) - continue; + if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL) { + if(aconf->status & CONF_EXEMPTDLINE) + continue; - notify_banned_client(client_p, aconf, D_LINED); - } - } + notify_banned_client(client_p, aconf, D_LINED); + } + } } /* check_xlines @@ -573,36 +546,33 @@ check_dlines(void) void check_xlines(void) { - struct Client *client_p; - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct Client *client_p; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { + client_p = ptr->data; - if(IsMe(client_p) || !IsPerson(client_p)) - continue; + if(IsMe(client_p) || !IsPerson(client_p)) + continue; - if((aconf = find_xline(client_p->info, 1)) != NULL) - { - if(IsExemptKline(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "XLINE over-ruled for %s, client is kline_exempt [%s]", - get_client_name(client_p, HIDE_IP), - aconf->host); - continue; - } + if((aconf = find_xline(client_p->info, 1)) != NULL) { + if(IsExemptKline(client_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "XLINE over-ruled for %s, client is kline_exempt [%s]", + get_client_name(client_p, HIDE_IP), + aconf->host); + continue; + } - sendto_realops_snomask(SNO_GENERAL, L_ALL, "XLINE active for %s", - get_client_name(client_p, HIDE_IP)); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "XLINE active for %s", + get_client_name(client_p, HIDE_IP)); - (void) exit_client(client_p, client_p, &me, "Bad user info"); - continue; - } - } + (void) exit_client(client_p, client_p, &me, "Bad user info"); + continue; + } + } } /* @@ -610,30 +580,27 @@ check_xlines(void) * * input - pointer to client * output - NONE - * side effects - + * side effects - */ static void update_client_exit_stats(struct Client *client_p) { - if(IsServer(client_p)) - { - sendto_realops_snomask(SNO_EXTERNAL, L_ALL, - "Server %s split from %s", - client_p->name, client_p->servptr->name); - if(HasSentEob(client_p)) - eob_count--; - } - else if(IsClient(client_p)) - { - --Count.total; - if(IsOper(client_p)) - --Count.oper; - if(IsInvisible(client_p)) - --Count.invisi; - } + if(IsServer(client_p)) { + sendto_realops_snomask(SNO_EXTERNAL, L_ALL, + "Server %s split from %s", + client_p->name, client_p->servptr->name); + if(HasSentEob(client_p)) + eob_count--; + } else if(IsClient(client_p)) { + --Count.total; + if(IsOper(client_p)) + --Count.oper; + if(IsInvisible(client_p)) + --Count.invisi; + } - if(splitchecking && !splitmode) - check_splitmode(NULL); + if(splitchecking && !splitmode) + check_splitmode(NULL); } /* @@ -641,23 +608,21 @@ update_client_exit_stats(struct Client *client_p) * * input - pointer to client to release * output - NONE - * side effects - + * side effects - */ static void release_client_state(struct Client *client_p) { - if(client_p->user != NULL) - { - free_user(client_p->user, client_p); /* try this here */ - } - if(client_p->serv) - { - if(client_p->serv->user != NULL) - free_user(client_p->serv->user, client_p); - if(client_p->serv->fullcaps) - rb_free(client_p->serv->fullcaps); - rb_free(client_p->serv); - } + if(client_p->user != NULL) { + free_user(client_p->user, client_p); /* try this here */ + } + if(client_p->serv) { + if(client_p->serv->user != NULL) + free_user(client_p->serv->user, client_p); + if(client_p->serv->fullcaps) + rb_free(client_p->serv->fullcaps); + rb_free(client_p->serv); + } } /* @@ -670,23 +635,23 @@ release_client_state(struct Client *client_p) static void remove_client_from_list(struct Client *client_p) { - s_assert(NULL != client_p); + s_assert(NULL != client_p); - if(client_p == NULL) - return; + if(client_p == NULL) + return; - /* A client made with make_client() - * is on the unknown_list until removed. - * If it =does= happen to exit before its removed from that list - * and its =not= on the global_client_list, it will core here. - * short circuit that case now -db - */ - if(client_p->node.prev == NULL && client_p->node.next == NULL) - return; + /* A client made with make_client() + * is on the unknown_list until removed. + * If it =does= happen to exit before its removed from that list + * and its =not= on the global_client_list, it will core here. + * short circuit that case now -db + */ + if(client_p->node.prev == NULL && client_p->node.next == NULL) + return; - rb_dlinkDelete(&client_p->node, &global_client_list); + rb_dlinkDelete(&client_p->node, &global_client_list); - update_client_exit_stats(client_p); + update_client_exit_stats(client_p); } @@ -699,59 +664,58 @@ remove_client_from_list(struct Client *client_p) struct Client * find_person(const char *name) { - struct Client *c2ptr; + struct Client *c2ptr; - c2ptr = find_client(name); + c2ptr = find_client(name); - if(c2ptr && IsPerson(c2ptr)) - return (c2ptr); - return (NULL); + if(c2ptr && IsPerson(c2ptr)) + return (c2ptr); + return (NULL); } struct Client * find_named_person(const char *name) { - struct Client *c2ptr; + struct Client *c2ptr; - c2ptr = find_named_client(name); + c2ptr = find_named_client(name); - if(c2ptr && IsPerson(c2ptr)) - return (c2ptr); - return (NULL); + if(c2ptr && IsPerson(c2ptr)) + return (c2ptr); + return (NULL); } /* - * find_chasing - find the client structure for a nick name (user) - * using history mechanism if necessary. If the client is not found, + * find_chasing - find the client structure for a nick name (user) + * using history mechanism if necessary. If the client is not found, * an error message (NO SUCH NICK) is generated. If the client was found * through the history, chasing will be 1 and otherwise 0. */ struct Client * find_chasing(struct Client *source_p, const char *user, int *chasing) { - struct Client *who; + struct Client *who; - if(MyClient(source_p)) - who = find_named_person(user); - else - who = find_person(user); + if(MyClient(source_p)) + who = find_named_person(user); + else + who = find_person(user); - if(chasing) - *chasing = 0; + if(chasing) + *chasing = 0; - if(who || IsDigit(*user)) - return who; + if(who || IsDigit(*user)) + return who; - if(!(who = get_history(user, (long) KILLCHASETIMELIMIT))) - { - sendto_one_numeric(source_p, ERR_NOSUCHNICK, - form_str(ERR_NOSUCHNICK), user); - return (NULL); - } - if(chasing) - *chasing = 1; - return who; + if(!(who = get_history(user, (long) KILLCHASETIMELIMIT))) { + sendto_one_numeric(source_p, ERR_NOSUCHNICK, + form_str(ERR_NOSUCHNICK), user); + return (NULL); + } + if(chasing) + *chasing = 1; + return who; } /* @@ -776,48 +740,46 @@ find_chasing(struct Client *source_p, const char *user, int *chasing) const char * get_client_name(struct Client *client, int showip) { - static char nbuf[HOSTLEN * 2 + USERLEN + 5]; + static char nbuf[HOSTLEN * 2 + USERLEN + 5]; - s_assert(NULL != client); - if(client == NULL) - return NULL; + s_assert(NULL != client); + if(client == NULL) + return NULL; - if(MyConnect(client)) - { - if(!irccmp(client->name, client->host)) - return client->name; + if(MyConnect(client)) { + if(!irccmp(client->name, client->host)) + return client->name; - if(ConfigFileEntry.hide_spoof_ips && - showip == SHOW_IP && IsIPSpoof(client)) - showip = MASK_IP; - if(IsAnyServer(client)) - showip = MASK_IP; + if(ConfigFileEntry.hide_spoof_ips && + showip == SHOW_IP && IsIPSpoof(client)) + showip = MASK_IP; + if(IsAnyServer(client)) + showip = MASK_IP; - /* And finally, let's get the host information, ip or name */ - switch (showip) - { - case SHOW_IP: - rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", - client->name, client->username, - client->sockhost); - break; - case MASK_IP: - rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", - client->name, client->username); - break; - default: - rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", - client->name, client->username, client->host); - } - return nbuf; - } + /* And finally, let's get the host information, ip or name */ + switch (showip) { + case SHOW_IP: + rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", + client->name, client->username, + client->sockhost); + break; + case MASK_IP: + rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", + client->name, client->username); + break; + default: + rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", + client->name, client->username, client->host); + } + return nbuf; + } - /* As pointed out by Adel Mezibra - * Neph|l|m@EFnet. Was missing a return here. - */ - return client->name; + /* As pointed out by Adel Mezibra + * Neph|l|m@EFnet. Was missing a return here. + */ + return client->name; } - + /* log_client_name() * * This version is the same as get_client_name, but doesnt contain the @@ -826,36 +788,34 @@ get_client_name(struct Client *client, int showip) const char * log_client_name(struct Client *target_p, int showip) { - static char nbuf[HOSTLEN * 2 + USERLEN + 5]; + static char nbuf[HOSTLEN * 2 + USERLEN + 5]; - if(target_p == NULL) - return NULL; + if(target_p == NULL) + return NULL; - if(MyConnect(target_p)) - { - if(irccmp(target_p->name, target_p->host) == 0) - return target_p->name; + if(MyConnect(target_p)) { + if(irccmp(target_p->name, target_p->host) == 0) + return target_p->name; - switch (showip) - { - case SHOW_IP: - rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", target_p->name, - target_p->username, target_p->sockhost); - break; + switch (showip) { + case SHOW_IP: + rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", target_p->name, + target_p->username, target_p->sockhost); + break; - case MASK_IP: - rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", - target_p->name, target_p->username); + case MASK_IP: + rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", + target_p->name, target_p->username); - default: - rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", target_p->name, - target_p->username, target_p->host); - } + default: + rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", target_p->name, + target_p->username, target_p->host); + } - return nbuf; - } + return nbuf; + } - return target_p->name; + return target_p->name; } /* is_remote_connect - Returns whether a server was /connect'ed by a remote @@ -863,84 +823,77 @@ log_client_name(struct Client *target_p, int showip) int is_remote_connect(struct Client *client_p) { - struct Client *oper; + struct Client *oper; - if (client_p->serv == NULL) - return FALSE; - oper = find_named_person(client_p->serv->by); - return oper != NULL && IsOper(oper) && !MyConnect(oper); + if (client_p->serv == NULL) + return FALSE; + oper = find_named_person(client_p->serv->by); + return oper != NULL && IsOper(oper) && !MyConnect(oper); } static void free_exited_clients(void *unused) { - rb_dlink_node *ptr, *next; - struct Client *target_p; + rb_dlink_node *ptr, *next; + struct Client *target_p; - RB_DLINK_FOREACH_SAFE(ptr, next, dead_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next, dead_list.head) { + target_p = ptr->data; #ifdef DEBUG_EXITED_CLIENTS - { - struct abort_client *abt; - rb_dlink_node *aptr; - int found = 0; + { + struct abort_client *abt; + rb_dlink_node *aptr; + int found = 0; - RB_DLINK_FOREACH(aptr, abort_list.head) - { - abt = aptr->data; - if(abt->client == target_p) - { - s_assert(0); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "On abort_list: %s stat: %u flags: %u/%u handler: %c", - target_p->name, (unsigned int) target_p->status, - target_p->flags, target_p->flags2, target_p->handler); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Please report this to the charybdis developers!"); - found++; - } - } + RB_DLINK_FOREACH(aptr, abort_list.head) { + abt = aptr->data; + if(abt->client == target_p) { + s_assert(0); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "On abort_list: %s stat: %u flags: %u/%u handler: %c", + target_p->name, (unsigned int) target_p->status, + target_p->flags, target_p->flags2, target_p->handler); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Please report this to the charybdis developers!"); + found++; + } + } - if(found) - { - rb_dlinkDestroy(ptr, &dead_list); - continue; - } - } + if(found) { + rb_dlinkDestroy(ptr, &dead_list); + continue; + } + } #endif - if(ptr->data == NULL) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Warning: null client on dead_list!"); - rb_dlinkDestroy(ptr, &dead_list); - continue; - } - release_client_state(target_p); - free_client(target_p); - rb_dlinkDestroy(ptr, &dead_list); - } + if(ptr->data == NULL) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Warning: null client on dead_list!"); + rb_dlinkDestroy(ptr, &dead_list); + continue; + } + release_client_state(target_p); + free_client(target_p); + rb_dlinkDestroy(ptr, &dead_list); + } #ifdef DEBUG_EXITED_CLIENTS - RB_DLINK_FOREACH_SAFE(ptr, next, dead_remote_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next, dead_remote_list.head) { + target_p = ptr->data; - if(ptr->data == NULL) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Warning: null client on dead_list!"); - rb_dlinkDestroy(ptr, &dead_list); - continue; - } - release_client_state(target_p); - free_client(target_p); - rb_dlinkDestroy(ptr, &dead_remote_list); - } + if(ptr->data == NULL) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Warning: null client on dead_list!"); + rb_dlinkDestroy(ptr, &dead_list); + continue; + } + release_client_state(target_p); + free_client(target_p); + rb_dlinkDestroy(ptr, &dead_remote_list); + } #endif - + } /* @@ -952,41 +905,36 @@ free_exited_clients(void *unused) ** on that one -orabidoo */ static void -recurse_send_quits(struct Client *client_p, struct Client *source_p, - struct Client *to, const char *comment1, - const char *comment) +recurse_send_quits(struct Client *client_p, struct Client *source_p, + struct Client *to, const char *comment1, + const char *comment) { - struct Client *target_p; - rb_dlink_node *ptr, *ptr_next; - /* If this server can handle quit storm (QS) removal - * of dependents, just send the SQUIT - */ + struct Client *target_p; + rb_dlink_node *ptr, *ptr_next; + /* If this server can handle quit storm (QS) removal + * of dependents, just send the SQUIT + */ - if(IsCapable(to, CAP_QS)) - { - sendto_one(to, "SQUIT %s :%s", - get_id(source_p, to), comment); - } - else - { - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head) - { - target_p = ptr->data; - sendto_one(to, ":%s QUIT :%s", target_p->id, comment1); - } - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->servers.head) - { - target_p = ptr->data; - recurse_send_quits(client_p, target_p, to, comment1, comment); - } - sendto_one(to, "SQUIT %s :%s", source_p->id, comment); - } + if(IsCapable(to, CAP_QS)) { + sendto_one(to, "SQUIT %s :%s", + get_id(source_p, to), comment); + } else { + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head) { + target_p = ptr->data; + sendto_one(to, ":%s QUIT :%s", target_p->id, comment1); + } + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->servers.head) { + target_p = ptr->data; + recurse_send_quits(client_p, target_p, to, comment1, comment); + } + sendto_one(to, "SQUIT %s :%s", source_p->id, comment); + } } -/* +/* ** Remove all clients that depend on source_p; assumes all (S)QUITs have -** already been sent. we make sure to exit a server's dependent clients -** and servers before the server itself; exit_one_client takes care of +** already been sent. we make sure to exit a server's dependent clients +** and servers before the server itself; exit_one_client takes care of ** actually removing things off llists. tweaked from +CSr31 -orabidoo */ /* @@ -995,46 +943,40 @@ recurse_send_quits(struct Client *client_p, struct Client *source_p, static void recurse_remove_clients(struct Client *source_p, const char *comment) { - struct Client *target_p; - rb_dlink_node *ptr, *ptr_next; + struct Client *target_p; + rb_dlink_node *ptr, *ptr_next; - if(IsMe(source_p)) - return; + if(IsMe(source_p)) + return; - if(source_p->serv == NULL) /* oooops. uh this is actually a major bug */ - return; + if(source_p->serv == NULL) /* oooops. uh this is actually a major bug */ + return; - /* this is very ugly, but it saves cpu :P */ - if(ConfigFileEntry.nick_delay > 0) - { - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head) - { - target_p = ptr->data; - target_p->flags |= FLAGS_KILLED; - add_nd_entry(target_p->name); + /* this is very ugly, but it saves cpu :P */ + if(ConfigFileEntry.nick_delay > 0) { + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head) { + target_p = ptr->data; + target_p->flags |= FLAGS_KILLED; + add_nd_entry(target_p->name); - if(!IsDead(target_p) && !IsClosing(target_p)) - exit_remote_client(NULL, target_p, &me, comment); - } - } - else - { - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head) - { - target_p = ptr->data; - target_p->flags |= FLAGS_KILLED; + if(!IsDead(target_p) && !IsClosing(target_p)) + exit_remote_client(NULL, target_p, &me, comment); + } + } else { + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head) { + target_p = ptr->data; + target_p->flags |= FLAGS_KILLED; - if(!IsDead(target_p) && !IsClosing(target_p)) - exit_remote_client(NULL, target_p, &me, comment); - } - } + if(!IsDead(target_p) && !IsClosing(target_p)) + exit_remote_client(NULL, target_p, &me, comment); + } + } - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->servers.head) - { - target_p = ptr->data; - recurse_remove_clients(target_p, comment); - qs_server(NULL, target_p, &me, comment); - } + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->servers.head) { + target_p = ptr->data; + recurse_remove_clients(target_p, comment); + qs_server(NULL, target_p, &me, comment); + } } /* @@ -1044,66 +986,63 @@ recurse_remove_clients(struct Client *source_p, const char *comment) */ static void remove_dependents(struct Client *client_p, - struct Client *source_p, - struct Client *from, const char *comment, const char *comment1) + struct Client *source_p, + struct Client *from, const char *comment, const char *comment1) { - struct Client *to; - rb_dlink_node *ptr, *next; + struct Client *to; + rb_dlink_node *ptr, *next; - RB_DLINK_FOREACH_SAFE(ptr, next, serv_list.head) - { - to = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next, serv_list.head) { + to = ptr->data; - if(IsMe(to) || to == source_p->from || - (to == client_p && IsCapable(to, CAP_QS))) - continue; + if(IsMe(to) || to == source_p->from || + (to == client_p && IsCapable(to, CAP_QS))) + continue; - recurse_send_quits(client_p, source_p, to, comment1, comment); - } + recurse_send_quits(client_p, source_p, to, comment1, comment); + } - recurse_remove_clients(source_p, comment1); + recurse_remove_clients(source_p, comment1); } void exit_aborted_clients(void *unused) { - struct abort_client *abt; - rb_dlink_node *ptr, *next; - RB_DLINK_FOREACH_SAFE(ptr, next, abort_list.head) - { - abt = ptr->data; + struct abort_client *abt; + rb_dlink_node *ptr, *next; + RB_DLINK_FOREACH_SAFE(ptr, next, abort_list.head) { + abt = ptr->data; #ifdef DEBUG_EXITED_CLIENTS - { - if(rb_dlinkFind(abt->client, &dead_list)) - { - s_assert(0); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "On dead_list: %s stat: %u flags: %u/%u handler: %c", - abt->client->name, (unsigned int) abt->client->status, - abt->client->flags, abt->client->flags2, abt->client->handler); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Please report this to the charybdis developers!"); - continue; - } - } + { + if(rb_dlinkFind(abt->client, &dead_list)) { + s_assert(0); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "On dead_list: %s stat: %u flags: %u/%u handler: %c", + abt->client->name, (unsigned int) abt->client->status, + abt->client->flags, abt->client->flags2, abt->client->handler); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Please report this to the charybdis developers!"); + continue; + } + } #endif - s_assert(*((unsigned long*)abt->client) != 0xdeadbeef); /* This is lame but its a debug thing */ - rb_dlinkDelete(ptr, &abort_list); + s_assert(*((unsigned long*)abt->client) != 0xdeadbeef); /* This is lame but its a debug thing */ + rb_dlinkDelete(ptr, &abort_list); - if(IsAnyServer(abt->client)) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Closing link to %s: %s", - abt->client->name, abt->notice); + if(IsAnyServer(abt->client)) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Closing link to %s: %s", + abt->client->name, abt->notice); - /* its no longer on abort list - we *must* remove - * FLAGS_CLOSING otherwise exit_client() will not run --fl - */ - abt->client->flags &= ~FLAGS_CLOSING; - exit_client(abt->client, abt->client, &me, abt->notice); - rb_free(abt); - } + /* its no longer on abort list - we *must* remove + * FLAGS_CLOSING otherwise exit_client() will not run --fl + */ + abt->client->flags &= ~FLAGS_CLOSING; + exit_client(abt->client, abt->client, &me, abt->notice); + rb_free(abt); + } } @@ -1114,99 +1053,96 @@ exit_aborted_clients(void *unused) void dead_link(struct Client *client_p, int sendqex) { - struct abort_client *abt; + struct abort_client *abt; - s_assert(!IsMe(client_p)); - if(IsDead(client_p) || IsClosing(client_p) || IsMe(client_p)) - return; + s_assert(!IsMe(client_p)); + if(IsDead(client_p) || IsClosing(client_p) || IsMe(client_p)) + return; - abt = (struct abort_client *) rb_malloc(sizeof(struct abort_client)); + abt = (struct abort_client *) rb_malloc(sizeof(struct abort_client)); - if(sendqex) - rb_strlcpy(abt->notice, "Max SendQ exceeded", sizeof(abt->notice)); - else - rb_snprintf(abt->notice, sizeof(abt->notice), "Write error: %s", strerror(errno)); + if(sendqex) + rb_strlcpy(abt->notice, "Max SendQ exceeded", sizeof(abt->notice)); + else + rb_snprintf(abt->notice, sizeof(abt->notice), "Write error: %s", strerror(errno)); - abt->client = client_p; - SetIOError(client_p); - SetDead(client_p); - SetClosing(client_p); - rb_dlinkAdd(abt, &abt->node, &abort_list); + abt->client = client_p; + SetIOError(client_p); + SetDead(client_p); + SetClosing(client_p); + rb_dlinkAdd(abt, &abt->node, &abort_list); } /* This does the remove of the user from channels..local or remote */ static inline void exit_generic_client(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) + const char *comment) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - if(IsOper(source_p)) - rb_dlinkFindDestroy(source_p, &oper_list); + if(IsOper(source_p)) + rb_dlinkFindDestroy(source_p, &oper_list); - /* get rid of any metadata the user may have */ - user_metadata_clear(source_p); + /* get rid of any metadata the user may have */ + user_metadata_clear(source_p); - sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s QUIT :%s", - source_p->name, - source_p->username, source_p->host, comment); + sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s QUIT :%s", + source_p->name, + source_p->username, source_p->host, comment); - remove_user_from_channels(source_p); + remove_user_from_channels(source_p); - /* Should not be in any channels now */ - s_assert(source_p->user->channel.head == NULL); + /* Should not be in any channels now */ + s_assert(source_p->user->channel.head == NULL); - /* Clean up invitefield */ - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->user->invited.head) - { - del_invite(ptr->data, source_p); - } + /* Clean up invitefield */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->user->invited.head) { + del_invite(ptr->data, source_p); + } - /* Clean up allow lists */ - del_all_accepts(source_p); + /* Clean up allow lists */ + del_all_accepts(source_p); - add_history(source_p, 0); - off_history(source_p); + add_history(source_p, 0); + off_history(source_p); - monitor_signoff(source_p); + monitor_signoff(source_p); - if(has_id(source_p)) - del_from_id_hash(source_p->id, source_p); + if(has_id(source_p)) + del_from_id_hash(source_p->id, source_p); - del_from_hostname_hash(source_p->orighost, source_p); - del_from_client_hash(source_p->name, source_p); - remove_client_from_list(source_p); + del_from_hostname_hash(source_p->orighost, source_p); + del_from_client_hash(source_p->name, source_p); + remove_client_from_list(source_p); } -/* +/* * Assumes IsPerson(source_p) && !MyConnect(source_p) */ static int exit_remote_client(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) + const char *comment) { - exit_generic_client(client_p, source_p, from, comment); - - if(source_p->servptr && source_p->servptr->serv) - { - rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users); - } + exit_generic_client(client_p, source_p, from, comment); - if((source_p->flags & FLAGS_KILLED) == 0) - { - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s QUIT :%s", use_id(source_p), comment); - } + if(source_p->servptr && source_p->servptr->serv) { + rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users); + } - SetDead(source_p); + if((source_p->flags & FLAGS_KILLED) == 0) { + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s QUIT :%s", use_id(source_p), comment); + } + + SetDead(source_p); #ifdef DEBUG_EXITED_CLIENTS - rb_dlinkAddAlloc(source_p, &dead_remote_list); + rb_dlinkAddAlloc(source_p, &dead_remote_list); #else - rb_dlinkAddAlloc(source_p, &dead_list); + rb_dlinkAddAlloc(source_p, &dead_list); #endif - return(CLIENT_EXITED); + return(CLIENT_EXITED); } /* @@ -1215,237 +1151,231 @@ exit_remote_client(struct Client *client_p, struct Client *source_p, struct Clie static int exit_unknown_client(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) + const char *comment) { - delete_auth_queries(source_p); - if (source_p->localClient->dnsquery) - { - delete_resolver_queries(source_p->localClient->dnsquery); - rb_free(source_p->localClient->dnsquery); - } - rb_dlinkDelete(&source_p->localClient->tnode, &unknown_list); + delete_auth_queries(source_p); + if (source_p->localClient->dnsquery) { + delete_resolver_queries(source_p->localClient->dnsquery); + rb_free(source_p->localClient->dnsquery); + } + rb_dlinkDelete(&source_p->localClient->tnode, &unknown_list); - if(!IsIOError(source_p)) - sendto_one(source_p, "ERROR :Closing Link: %s (%s)", - source_p->user != NULL ? source_p->host : "127.0.0.1", - comment); + if(!IsIOError(source_p)) + sendto_one(source_p, "ERROR :Closing Link: %s (%s)", + source_p->user != NULL ? source_p->host : "127.0.0.1", + comment); - close_connection(source_p); + close_connection(source_p); - if(has_id(source_p)) - del_from_id_hash(source_p->id, source_p); + if(has_id(source_p)) + del_from_id_hash(source_p->id, source_p); - del_from_hostname_hash(source_p->host, source_p); - del_from_client_hash(source_p->name, source_p); - remove_client_from_list(source_p); - SetDead(source_p); - rb_dlinkAddAlloc(source_p, &dead_list); + del_from_hostname_hash(source_p->host, source_p); + del_from_client_hash(source_p->name, source_p); + remove_client_from_list(source_p); + SetDead(source_p); + rb_dlinkAddAlloc(source_p, &dead_list); - /* Note that we don't need to add unknowns to the dead_list */ - return(CLIENT_EXITED); + /* Note that we don't need to add unknowns to the dead_list */ + return(CLIENT_EXITED); } static int -exit_remote_server(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) +exit_remote_server(struct Client *client_p, struct Client *source_p, struct Client *from, + const char *comment) { - static char comment1[(HOSTLEN*2)+2]; - static char newcomment[BUFSIZE]; - struct Client *target_p; - - if(ConfigServerHide.flatten_links) - strcpy(comment1, "*.net *.split"); - else - { - strcpy(comment1, source_p->servptr->name); - strcat(comment1, " "); - strcat(comment1, source_p->name); - } - if (IsPerson(from)) - rb_snprintf(newcomment, sizeof(newcomment), "by %s: %s", - from->name, comment); + static char comment1[(HOSTLEN*2)+2]; + static char newcomment[BUFSIZE]; + struct Client *target_p; - if(source_p->serv != NULL) - remove_dependents(client_p, source_p, from, IsPerson(from) ? newcomment : comment, comment1); + if(ConfigServerHide.flatten_links) + strcpy(comment1, "*.net *.split"); + else { + strcpy(comment1, source_p->servptr->name); + strcat(comment1, " "); + strcat(comment1, source_p->name); + } + if (IsPerson(from)) + rb_snprintf(newcomment, sizeof(newcomment), "by %s: %s", + from->name, comment); - if(source_p->servptr && source_p->servptr->serv) - rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); - else - s_assert(0); + if(source_p->serv != NULL) + remove_dependents(client_p, source_p, from, IsPerson(from) ? newcomment : comment, comment1); - rb_dlinkFindDestroy(source_p, &global_serv_list); - target_p = source_p->from; - - if(target_p != NULL && IsServer(target_p) && target_p != client_p && - !IsMe(target_p) && (source_p->flags & FLAGS_KILLED) == 0) - { - sendto_one(target_p, ":%s SQUIT %s :%s", - get_id(from, target_p), get_id(source_p, target_p), - comment); - } + if(source_p->servptr && source_p->servptr->serv) + rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); + else + s_assert(0); - if(has_id(source_p)) - del_from_id_hash(source_p->id, source_p); + rb_dlinkFindDestroy(source_p, &global_serv_list); + target_p = source_p->from; - del_from_client_hash(source_p->name, source_p); - remove_client_from_list(source_p); - scache_split(source_p->serv->nameinfo); - - SetDead(source_p); + if(target_p != NULL && IsServer(target_p) && target_p != client_p && + !IsMe(target_p) && (source_p->flags & FLAGS_KILLED) == 0) { + sendto_one(target_p, ":%s SQUIT %s :%s", + get_id(from, target_p), get_id(source_p, target_p), + comment); + } + + if(has_id(source_p)) + del_from_id_hash(source_p->id, source_p); + + del_from_client_hash(source_p->name, source_p); + remove_client_from_list(source_p); + scache_split(source_p->serv->nameinfo); + + SetDead(source_p); #ifdef DEBUG_EXITED_CLIENTS - rb_dlinkAddAlloc(source_p, &dead_remote_list); + rb_dlinkAddAlloc(source_p, &dead_remote_list); #else - rb_dlinkAddAlloc(source_p, &dead_list); + rb_dlinkAddAlloc(source_p, &dead_list); #endif - return 0; + return 0; } static int -qs_server(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) +qs_server(struct Client *client_p, struct Client *source_p, struct Client *from, + const char *comment) { - if(source_p->servptr && source_p->servptr->serv) - rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); - else - s_assert(0); + if(source_p->servptr && source_p->servptr->serv) + rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); + else + s_assert(0); - rb_dlinkFindDestroy(source_p, &global_serv_list); - - if(has_id(source_p)) - del_from_id_hash(source_p->id, source_p); + rb_dlinkFindDestroy(source_p, &global_serv_list); - del_from_client_hash(source_p->name, source_p); - remove_client_from_list(source_p); - scache_split(source_p->serv->nameinfo); - - SetDead(source_p); - rb_dlinkAddAlloc(source_p, &dead_list); - return 0; + if(has_id(source_p)) + del_from_id_hash(source_p->id, source_p); + + del_from_client_hash(source_p->name, source_p); + remove_client_from_list(source_p); + scache_split(source_p->serv->nameinfo); + + SetDead(source_p); + rb_dlinkAddAlloc(source_p, &dead_list); + return 0; } static int -exit_local_server(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) +exit_local_server(struct Client *client_p, struct Client *source_p, struct Client *from, + const char *comment) { - static char comment1[(HOSTLEN*2)+2]; - static char newcomment[BUFSIZE]; - unsigned int sendk, recvk; - - rb_dlinkDelete(&source_p->localClient->tnode, &serv_list); - rb_dlinkFindDestroy(source_p, &global_serv_list); - - unset_chcap_usage_counts(source_p); - sendk = source_p->localClient->sendK; - recvk = source_p->localClient->receiveK; + static char comment1[(HOSTLEN*2)+2]; + static char newcomment[BUFSIZE]; + unsigned int sendk, recvk; - /* Always show source here, so the server notices show - * which side initiated the split -- jilles - */ - rb_snprintf(newcomment, sizeof(newcomment), "by %s: %s", - from == source_p ? me.name : from->name, comment); - if (!IsIOError(source_p)) - sendto_one(source_p, "SQUIT %s :%s", use_id(source_p), - newcomment); - if(client_p != NULL && source_p != client_p && !IsIOError(source_p)) - { - sendto_one(source_p, "ERROR :Closing Link: 127.0.0.1 %s (%s)", - source_p->name, comment); - } - - if(source_p->servptr && source_p->servptr->serv) - rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); - else - s_assert(0); + rb_dlinkDelete(&source_p->localClient->tnode, &serv_list); + rb_dlinkFindDestroy(source_p, &global_serv_list); + + unset_chcap_usage_counts(source_p); + sendk = source_p->localClient->sendK; + recvk = source_p->localClient->receiveK; + + /* Always show source here, so the server notices show + * which side initiated the split -- jilles + */ + rb_snprintf(newcomment, sizeof(newcomment), "by %s: %s", + from == source_p ? me.name : from->name, comment); + if (!IsIOError(source_p)) + sendto_one(source_p, "SQUIT %s :%s", use_id(source_p), + newcomment); + if(client_p != NULL && source_p != client_p && !IsIOError(source_p)) { + sendto_one(source_p, "ERROR :Closing Link: 127.0.0.1 %s (%s)", + source_p->name, comment); + } + + if(source_p->servptr && source_p->servptr->serv) + rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); + else + s_assert(0); - close_connection(source_p); - - if(ConfigServerHide.flatten_links) - strcpy(comment1, "*.net *.split"); - else - { - strcpy(comment1, source_p->servptr->name); - strcat(comment1, " "); - strcat(comment1, source_p->name); - } + close_connection(source_p); - if(source_p->serv != NULL) - remove_dependents(client_p, source_p, from, IsPerson(from) ? newcomment : comment, comment1); + if(ConfigServerHide.flatten_links) + strcpy(comment1, "*.net *.split"); + else { + strcpy(comment1, source_p->servptr->name); + strcat(comment1, " "); + strcat(comment1, source_p->name); + } - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s was connected" - " for %ld seconds. %d/%d sendK/recvK.", - source_p->name, (long) rb_current_time() - source_p->localClient->firsttime, sendk, recvk); + if(source_p->serv != NULL) + remove_dependents(client_p, source_p, from, IsPerson(from) ? newcomment : comment, comment1); - ilog(L_SERVER, "%s was connected for %ld seconds. %d/%d sendK/recvK.", - source_p->name, (long) rb_current_time() - source_p->localClient->firsttime, sendk, recvk); - - if(has_id(source_p)) - del_from_id_hash(source_p->id, source_p); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s was connected" + " for %ld seconds. %d/%d sendK/recvK.", + source_p->name, (long) rb_current_time() - source_p->localClient->firsttime, sendk, recvk); - del_from_client_hash(source_p->name, source_p); - remove_client_from_list(source_p); - scache_split(source_p->serv->nameinfo); - - SetDead(source_p); - rb_dlinkAddAlloc(source_p, &dead_list); - return 0; + ilog(L_SERVER, "%s was connected for %ld seconds. %d/%d sendK/recvK.", + source_p->name, (long) rb_current_time() - source_p->localClient->firsttime, sendk, recvk); + + if(has_id(source_p)) + del_from_id_hash(source_p->id, source_p); + + del_from_client_hash(source_p->name, source_p); + remove_client_from_list(source_p); + scache_split(source_p->serv->nameinfo); + + SetDead(source_p); + rb_dlinkAddAlloc(source_p, &dead_list); + return 0; } -/* +/* * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE */ static int exit_local_client(struct Client *client_p, struct Client *source_p, struct Client *from, - const char *comment) + const char *comment) { - unsigned long on_for; - char tbuf[26]; + unsigned long on_for; + char tbuf[26]; - exit_generic_client(client_p, source_p, from, comment); - clear_monitor(source_p); + exit_generic_client(client_p, source_p, from, comment); + clear_monitor(source_p); - s_assert(IsPerson(source_p)); - rb_dlinkDelete(&source_p->localClient->tnode, &lclient_list); - rb_dlinkDelete(&source_p->lnode, &me.serv->users); + s_assert(IsPerson(source_p)); + rb_dlinkDelete(&source_p->localClient->tnode, &lclient_list); + rb_dlinkDelete(&source_p->lnode, &me.serv->users); - if(IsOper(source_p)) - rb_dlinkFindDestroy(source_p, &local_oper_list); + if(IsOper(source_p)) + rb_dlinkFindDestroy(source_p, &local_oper_list); - sendto_realops_snomask(SNO_CCONN, L_ALL, - "Client exiting: %s (%s@%s) [%s] [%s]", - source_p->name, - source_p->username, source_p->host, comment, - show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255"); + sendto_realops_snomask(SNO_CCONN, L_ALL, + "Client exiting: %s (%s@%s) [%s] [%s]", + source_p->name, + source_p->username, source_p->host, comment, + show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255"); - sendto_realops_snomask(SNO_CCONNEXT, L_ALL, - "CLIEXIT %s %s %s %s 0 %s", - source_p->name, source_p->username, source_p->host, - show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255", - comment); + sendto_realops_snomask(SNO_CCONNEXT, L_ALL, + "CLIEXIT %s %s %s %s 0 %s", + source_p->name, source_p->username, source_p->host, + show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255", + comment); - on_for = rb_current_time() - source_p->localClient->firsttime; + on_for = rb_current_time() - source_p->localClient->firsttime; - ilog(L_USER, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d", - rb_ctime(rb_current_time(), tbuf, sizeof(tbuf)), on_for / 3600, - (on_for % 3600) / 60, on_for % 60, - source_p->name, source_p->username, source_p->host, - source_p->sockhost, - source_p->localClient->sendK, source_p->localClient->receiveK); + ilog(L_USER, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d", + rb_ctime(rb_current_time(), tbuf, sizeof(tbuf)), on_for / 3600, + (on_for % 3600) / 60, on_for % 60, + source_p->name, source_p->username, source_p->host, + source_p->sockhost, + source_p->localClient->sendK, source_p->localClient->receiveK); - sendto_one(source_p, "ERROR :Closing Link: %s (%s)", source_p->host, comment); - close_connection(source_p); + sendto_one(source_p, "ERROR :Closing Link: %s (%s)", source_p->host, comment); + close_connection(source_p); - if((source_p->flags & FLAGS_KILLED) == 0) - { - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s QUIT :%s", use_id(source_p), comment); - } + if((source_p->flags & FLAGS_KILLED) == 0) { + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s QUIT :%s", use_id(source_p), comment); + } - SetDead(source_p); - rb_dlinkAddAlloc(source_p, &dead_list); - return(CLIENT_EXITED); + SetDead(source_p); + rb_dlinkAddAlloc(source_p, &dead_list); + return(CLIENT_EXITED); } @@ -1476,49 +1406,46 @@ exit_client(struct Client *client_p, /* The local client originating the * internal reasons. * This will not get any of the * generated messages. */ - struct Client *source_p, /* Client exiting */ - struct Client *from, /* Client firing off this Exit, + struct Client *source_p, /* Client exiting */ + struct Client *from, /* Client firing off this Exit, * never NULL! */ - const char *comment /* Reason for the exit */ - ) + const char *comment /* Reason for the exit */ + ) { - hook_data_client_exit hdata; - if(IsClosing(source_p)) - return -1; + hook_data_client_exit hdata; + if(IsClosing(source_p)) + return -1; - /* note, this HAS to be here, when we exit a client we attempt to - * send them data, if this generates a write error we must *not* add - * them to the abort list --fl - */ - SetClosing(source_p); + /* note, this HAS to be here, when we exit a client we attempt to + * send them data, if this generates a write error we must *not* add + * them to the abort list --fl + */ + SetClosing(source_p); - hdata.local_link = client_p; - hdata.target = source_p; - hdata.from = from; - hdata.comment = comment; - call_hook(h_client_exit, &hdata); + hdata.local_link = client_p; + hdata.target = source_p; + hdata.from = from; + hdata.comment = comment; + call_hook(h_client_exit, &hdata); - if(MyConnect(source_p)) - { - /* Local clients of various types */ - if(IsPerson(source_p)) - return exit_local_client(client_p, source_p, from, comment); - else if(IsServer(source_p)) - return exit_local_server(client_p, source_p, from, comment); - /* IsUnknown || IsConnecting || IsHandShake */ - else if(!IsReject(source_p)) - return exit_unknown_client(client_p, source_p, from, comment); - } - else - { - /* Remotes */ - if(IsPerson(source_p)) - return exit_remote_client(client_p, source_p, from, comment); - else if(IsServer(source_p)) - return exit_remote_server(client_p, source_p, from, comment); - } + if(MyConnect(source_p)) { + /* Local clients of various types */ + if(IsPerson(source_p)) + return exit_local_client(client_p, source_p, from, comment); + else if(IsServer(source_p)) + return exit_local_server(client_p, source_p, from, comment); + /* IsUnknown || IsConnecting || IsHandShake */ + else if(!IsReject(source_p)) + return exit_unknown_client(client_p, source_p, from, comment); + } else { + /* Remotes */ + if(IsPerson(source_p)) + return exit_remote_client(client_p, source_p, from, comment); + else if(IsServer(source_p)) + return exit_remote_server(client_p, source_p, from, comment); + } - return -1; + return -1; } /* @@ -1529,9 +1456,9 @@ exit_client(struct Client *client_p, /* The local client originating the void count_local_client_memory(size_t * count, size_t * local_client_memory_used) { - size_t lusage; - rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL); - *local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client))); + size_t lusage; + rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL); + *local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client))); } /* @@ -1540,19 +1467,19 @@ count_local_client_memory(size_t * count, size_t * local_client_memory_used) void count_remote_client_memory(size_t * count, size_t * remote_client_memory_used) { - size_t lcount, rcount; - rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL); - rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL); - *count = rcount - lcount; - *remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client)); + size_t lcount, rcount; + rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL); + rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL); + *count = rcount - lcount; + *remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client)); } /* * accept processing, this adds a form of "caller ID" to ircd - * + * * If a client puts themselves into "caller ID only" mode, - * only clients that match a client pointer they have put on + * only clients that match a client pointer they have put on * the accept list will be allowed to message them. * * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ] @@ -1563,7 +1490,7 @@ count_remote_client_memory(size_t * count, size_t * remote_client_memory_used) * each source client then has a back pointer pointing back * to the client that has it on its accept list. * This allows for exit_one_client to remove these now bogus entries - * from any client having an accept on them. + * from any client having an accept on them. */ /* * del_all_accepts @@ -1576,35 +1503,32 @@ count_remote_client_memory(size_t * count, size_t * remote_client_memory_used) void del_all_accepts(struct Client *client_p) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct Client *target_p; - if(MyClient(client_p) && client_p->localClient->allow_list.head) - { - /* clear this clients accept list, and remove them from - * everyones on_accept_list - */ - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->allow_list.head) - { - target_p = ptr->data; - rb_dlinkFindDestroy(client_p, &target_p->on_allow_list); - rb_dlinkDestroy(ptr, &client_p->localClient->allow_list); - } - } + if(MyClient(client_p) && client_p->localClient->allow_list.head) { + /* clear this clients accept list, and remove them from + * everyones on_accept_list + */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->allow_list.head) { + target_p = ptr->data; + rb_dlinkFindDestroy(client_p, &target_p->on_allow_list); + rb_dlinkDestroy(ptr, &client_p->localClient->allow_list); + } + } - /* remove this client from everyones accept list */ - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head) - { - target_p = ptr->data; - rb_dlinkFindDestroy(client_p, &target_p->localClient->allow_list); - rb_dlinkDestroy(ptr, &client_p->on_allow_list); - } + /* remove this client from everyones accept list */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head) { + target_p = ptr->data; + rb_dlinkFindDestroy(client_p, &target_p->localClient->allow_list); + rb_dlinkDestroy(ptr, &client_p->on_allow_list); + } } /* * show_ip() - asks if the true IP shoudl be shown when source is - * askin for info about target + * askin for info about target * * Inputs - source_p who is asking * - target_p who do we want the info on @@ -1615,38 +1539,32 @@ del_all_accepts(struct Client *client_p) int show_ip(struct Client *source_p, struct Client *target_p) { - if(IsAnyServer(target_p)) - { - return 0; - } - else if(IsIPSpoof(target_p)) - { - /* source == NULL indicates message is being sent - * to local opers. - */ - if(!ConfigFileEntry.hide_spoof_ips && - (source_p == NULL || MyOper(source_p))) - return 1; - return 0; - } - else if(IsDynSpoof(target_p) && (source_p != NULL && !IsOper(source_p))) - return 0; - else - return 1; + if(IsAnyServer(target_p)) { + return 0; + } else if(IsIPSpoof(target_p)) { + /* source == NULL indicates message is being sent + * to local opers. + */ + if(!ConfigFileEntry.hide_spoof_ips && + (source_p == NULL || MyOper(source_p))) + return 1; + return 0; + } else if(IsDynSpoof(target_p) && (source_p != NULL && !IsOper(source_p))) + return 0; + else + return 1; } int show_ip_conf(struct ConfItem *aconf, struct Client *source_p) { - if(IsConfDoSpoofIp(aconf)) - { - if(!ConfigFileEntry.hide_spoof_ips && MyOper(source_p)) - return 1; + if(IsConfDoSpoofIp(aconf)) { + if(!ConfigFileEntry.hide_spoof_ips && MyOper(source_p)) + return 1; - return 0; - } - else - return 1; + return 0; + } else + return 1; } /* @@ -1660,20 +1578,19 @@ show_ip_conf(struct ConfItem *aconf, struct Client *source_p) struct User * make_user(struct Client *client_p) { - struct User *user; - struct Dictionary *metadata; + struct User *user; + struct Dictionary *metadata; - user = client_p->user; - if(!user) - { - user = (struct User *) rb_bh_alloc(user_heap); - user->refcnt = 1; - client_p->user = user; + user = client_p->user; + if(!user) { + user = (struct User *) rb_bh_alloc(user_heap); + user->refcnt = 1; + client_p->user = user; - metadata = irc_dictionary_create(irccmp); - client_p->user->metadata = metadata; - } - return user; + metadata = irc_dictionary_create(irccmp); + client_p->user->metadata = metadata; + } + return user; } /* @@ -1687,19 +1604,18 @@ make_user(struct Client *client_p) struct Server * make_server(struct Client *client_p) { - struct Server *serv = client_p->serv; + struct Server *serv = client_p->serv; - if(!serv) - { - serv = (struct Server *) rb_malloc(sizeof(struct Server)); - client_p->serv = serv; - } - return client_p->serv; + if(!serv) { + serv = (struct Server *) rb_malloc(sizeof(struct Server)); + client_p->serv = serv; + } + return client_p->serv; } /* * free_user - * + * * inputs - pointer to user struct * - pointer to client struct * output - none @@ -1709,102 +1625,93 @@ make_server(struct Client *client_p) void free_user(struct User *user, struct Client *client_p) { - free_away(client_p); + free_away(client_p); - if(--user->refcnt <= 0) - { - if(user->away) - rb_free((char *) user->away); - - /* - * sanity check - */ - if(user->refcnt < 0 || user->invited.head || user->channel.head) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *", - (unsigned long) client_p, - client_p ? client_p-> - name : "", - client_p->username, - client_p->host, - (unsigned long) user, - (unsigned long) user->invited.head, - (unsigned long) user->channel.head, - rb_dlink_list_length(&user->channel), - user->refcnt); - s_assert(!user->refcnt); - s_assert(!user->invited.head); - s_assert(!user->channel.head); - } + if(--user->refcnt <= 0) { + if(user->away) + rb_free((char *) user->away); - rb_bh_free(user_heap, user); - } + /* + * sanity check + */ + if(user->refcnt < 0 || user->invited.head || user->channel.head) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *", + (unsigned long) client_p, + client_p ? client_p-> + name : "", + client_p->username, + client_p->host, + (unsigned long) user, + (unsigned long) user->invited.head, + (unsigned long) user->channel.head, + rb_dlink_list_length(&user->channel), + user->refcnt); + s_assert(!user->refcnt); + s_assert(!user->invited.head); + s_assert(!user->channel.head); + } + + rb_bh_free(user_heap, user); + } } void allocate_away(struct Client *client_p) { - if(client_p->user->away == NULL) - client_p->user->away = rb_bh_alloc(away_heap); + if(client_p->user->away == NULL) + client_p->user->away = rb_bh_alloc(away_heap); } void free_away(struct Client *client_p) { - if(client_p->user != NULL && client_p->user->away != NULL) { - rb_bh_free(away_heap, client_p->user->away); - client_p->user->away = NULL; - } + if(client_p->user != NULL && client_p->user->away != NULL) { + rb_bh_free(away_heap, client_p->user->away); + client_p->user->away = NULL; + } } void init_uid(void) { - int i; + int i; - for(i = 0; i < 3; i++) - current_uid[i] = me.id[i]; + for(i = 0; i < 3; i++) + current_uid[i] = me.id[i]; - for(i = 3; i < 9; i++) - current_uid[i] = 'A'; + for(i = 3; i < 9; i++) + current_uid[i] = 'A'; - current_uid[9] = '\0'; + current_uid[9] = '\0'; } char * generate_uid(void) { - int i; + int i; - for(i = 8; i > 3; i--) - { - if(current_uid[i] == 'Z') - { - current_uid[i] = '0'; - return current_uid; - } - else if(current_uid[i] != '9') - { - current_uid[i]++; - return current_uid; - } - else - current_uid[i] = 'A'; - } + for(i = 8; i > 3; i--) { + if(current_uid[i] == 'Z') { + current_uid[i] = '0'; + return current_uid; + } else if(current_uid[i] != '9') { + current_uid[i]++; + return current_uid; + } else + current_uid[i] = 'A'; + } - /* if this next if() triggers, we're fucked. */ - if(current_uid[3] == 'Z') - { - current_uid[i] = 'A'; - s_assert(0); - } - else - current_uid[i]++; + /* if this next if() triggers, we're fucked. */ + if(current_uid[3] == 'Z') { + current_uid[i] = 'A'; + s_assert(0); + } else + current_uid[i]++; - return current_uid; + return current_uid; } /* @@ -1815,73 +1722,67 @@ generate_uid(void) void close_connection(struct Client *client_p) { - s_assert(client_p != NULL); - if(client_p == NULL) - return; + s_assert(client_p != NULL); + if(client_p == NULL) + return; - s_assert(MyConnect(client_p)); - if(!MyConnect(client_p)) - return; - - if(IsServer(client_p)) - { - struct server_conf *server_p; + s_assert(MyConnect(client_p)); + if(!MyConnect(client_p)) + return; - ServerStats.is_sv++; - ServerStats.is_sbs += client_p->localClient->sendB; - ServerStats.is_sbr += client_p->localClient->receiveB; - ServerStats.is_sti += (unsigned long long)(rb_current_time() - client_p->localClient->firsttime); + if(IsServer(client_p)) { + struct server_conf *server_p; - /* - * If the connection has been up for a long amount of time, schedule - * a 'quick' reconnect, else reset the next-connect cycle. - */ - if((server_p = find_server_conf(client_p->name)) != NULL) - { - /* - * Reschedule a faster reconnect, if this was a automatically - * connected configuration entry. (Note that if we have had - * a rehash in between, the status has been changed to - * CONF_ILLEGAL). But only do this if it was a "good" link. - */ - server_p->hold = time(NULL); - server_p->hold += - (server_p->hold - client_p->localClient->lasttime > - HANGONGOODLINK) ? HANGONRETRYDELAY : ConFreq(server_p->class); - } + ServerStats.is_sv++; + ServerStats.is_sbs += client_p->localClient->sendB; + ServerStats.is_sbr += client_p->localClient->receiveB; + ServerStats.is_sti += (unsigned long long)(rb_current_time() - client_p->localClient->firsttime); - } - else if(IsClient(client_p)) - { - ServerStats.is_cl++; - ServerStats.is_cbs += client_p->localClient->sendB; - ServerStats.is_cbr += client_p->localClient->receiveB; - ServerStats.is_cti += (unsigned long long)(rb_current_time() - client_p->localClient->firsttime); - } - else - ServerStats.is_ni++; + /* + * If the connection has been up for a long amount of time, schedule + * a 'quick' reconnect, else reset the next-connect cycle. + */ + if((server_p = find_server_conf(client_p->name)) != NULL) { + /* + * Reschedule a faster reconnect, if this was a automatically + * connected configuration entry. (Note that if we have had + * a rehash in between, the status has been changed to + * CONF_ILLEGAL). But only do this if it was a "good" link. + */ + server_p->hold = time(NULL); + server_p->hold += + (server_p->hold - client_p->localClient->lasttime > + HANGONGOODLINK) ? HANGONRETRYDELAY : ConFreq(server_p->class); + } - if(client_p->localClient->F != NULL) - { - /* attempt to flush any pending dbufs. Evil, but .. -- adrian */ - if(!IsIOError(client_p)) - send_queued(client_p); + } else if(IsClient(client_p)) { + ServerStats.is_cl++; + ServerStats.is_cbs += client_p->localClient->sendB; + ServerStats.is_cbr += client_p->localClient->receiveB; + ServerStats.is_cti += (unsigned long long)(rb_current_time() - client_p->localClient->firsttime); + } else + ServerStats.is_ni++; - del_from_cli_fd_hash(client_p); - rb_close(client_p->localClient->F); - client_p->localClient->F = NULL; - } + if(client_p->localClient->F != NULL) { + /* attempt to flush any pending dbufs. Evil, but .. -- adrian */ + if(!IsIOError(client_p)) + send_queued(client_p); - rb_linebuf_donebuf(&client_p->localClient->buf_sendq); - rb_linebuf_donebuf(&client_p->localClient->buf_recvq); - detach_conf(client_p); + del_from_cli_fd_hash(client_p); + rb_close(client_p->localClient->F); + client_p->localClient->F = NULL; + } - /* XXX shouldnt really be done here. */ - detach_server_conf(client_p); + rb_linebuf_donebuf(&client_p->localClient->buf_sendq); + rb_linebuf_donebuf(&client_p->localClient->buf_recvq); + detach_conf(client_p); - client_p->from = NULL; /* ...this should catch them! >:) --msa */ - ClearMyConnect(client_p); - SetIOError(client_p); + /* XXX shouldnt really be done here. */ + detach_server_conf(client_p); + + client_p->from = NULL; /* ...this should catch them! >:) --msa */ + ClearMyConnect(client_p); + SetIOError(client_p); } @@ -1889,52 +1790,48 @@ close_connection(struct Client *client_p) void error_exit_client(struct Client *client_p, int error) { - /* - * ...hmm, with non-blocking sockets we might get - * here from quite valid reasons, although.. why - * would select report "data available" when there - * wasn't... so, this must be an error anyway... --msa - * actually, EOF occurs when read() returns 0 and - * in due course, select() returns that fd as ready - * for reading even though it ends up being an EOF. -avalon - */ - char errmsg[255]; - int current_error = rb_get_sockerr(client_p->localClient->F); + /* + * ...hmm, with non-blocking sockets we might get + * here from quite valid reasons, although.. why + * would select report "data available" when there + * wasn't... so, this must be an error anyway... --msa + * actually, EOF occurs when read() returns 0 and + * in due course, select() returns that fd as ready + * for reading even though it ends up being an EOF. -avalon + */ + char errmsg[255]; + int current_error = rb_get_sockerr(client_p->localClient->F); - SetIOError(client_p); + SetIOError(client_p); - if(IsServer(client_p) || IsHandshake(client_p)) - { - if(error == 0) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, - "Server %s closed the connection", - client_p->name); + if(IsServer(client_p) || IsHandshake(client_p)) { + if(error == 0) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, + "Server %s closed the connection", + client_p->name); - ilog(L_SERVER, "Server %s closed the connection", - log_client_name(client_p, SHOW_IP)); - } - else - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, - "Lost connection to %s: %s", - client_p->name, strerror(current_error)); - ilog(L_SERVER, "Lost connection to %s: %s", - log_client_name(client_p, SHOW_IP), strerror(current_error)); - } - } + ilog(L_SERVER, "Server %s closed the connection", + log_client_name(client_p, SHOW_IP)); + } else { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, + "Lost connection to %s: %s", + client_p->name, strerror(current_error)); + ilog(L_SERVER, "Lost connection to %s: %s", + log_client_name(client_p, SHOW_IP), strerror(current_error)); + } + } - if(error == 0) - rb_strlcpy(errmsg, "Remote host closed the connection", sizeof(errmsg)); - else - rb_snprintf(errmsg, sizeof(errmsg), "Read error: %s", strerror(current_error)); + if(error == 0) + rb_strlcpy(errmsg, "Remote host closed the connection", sizeof(errmsg)); + else + rb_snprintf(errmsg, sizeof(errmsg), "Read error: %s", strerror(current_error)); - exit_client(client_p, client_p, &me, errmsg); + exit_client(client_p, client_p, &me, errmsg); } /* * user_metadata_add - * + * * inputs - pointer to client struct * - name of metadata item you wish to add * - value of metadata item @@ -1946,24 +1843,24 @@ error_exit_client(struct Client *client_p, int error) struct Metadata * user_metadata_add(struct Client *target, const char *name, const char *value, int propagate) { - struct Metadata *md; + struct Metadata *md; - md = rb_malloc(sizeof(struct Metadata)); - md->name = rb_strdup(name); - md->value = rb_strdup(value); + md = rb_malloc(sizeof(struct Metadata)); + md->name = rb_strdup(name); + md->value = rb_strdup(value); - irc_dictionary_add(target->user->metadata, md->name, md); - - if(propagate) - sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA SET %s %s :%s", - target->id, name, value); + irc_dictionary_add(target->user->metadata, md->name, md); - return md; + if(propagate) + sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA SET %s %s :%s", + target->id, name, value); + + return md; } /* * user_metadata_delete - * + * * inputs - pointer to client struct * - name of metadata item you wish to delete * output - none @@ -1973,42 +1870,42 @@ user_metadata_add(struct Client *target, const char *name, const char *value, in void user_metadata_delete(struct Client *target, const char *name, int propagate) { - struct Metadata *md = user_metadata_find(target, name); + struct Metadata *md = user_metadata_find(target, name); - if(!md) - return; + if(!md) + return; - irc_dictionary_delete(target->user->metadata, md->name); + irc_dictionary_delete(target->user->metadata, md->name); - rb_free(md); + rb_free(md); - if(propagate) - sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA CLEAR %s %s", - target->id, name); + if(propagate) + sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA CLEAR %s %s", + target->id, name); } /* * user_metadata_find - * + * * inputs - pointer to client struct * - name of metadata item you wish to read * output - the requested metadata, if it exists, elsewise null. - * side effects - + * side effects - */ struct Metadata * user_metadata_find(struct Client *target, const char *name) { - if(!target->user) - return NULL; + if(!target->user) + return NULL; - if(!target->user->metadata) - return NULL; + if(!target->user->metadata) + return NULL; - return irc_dictionary_retrieve(target->user->metadata, name); + return irc_dictionary_retrieve(target->user->metadata, name); } /* * user_metadata_clear - * + * * inputs - pointer to user struct * output - none * side effects - metadata is cleared from the user in question @@ -2016,11 +1913,10 @@ user_metadata_find(struct Client *target, const char *name) void user_metadata_clear(struct Client *target) { - struct Metadata *md; - struct DictionaryIter iter; - - DICTIONARY_FOREACH(md, &iter, target->user->metadata) - { - user_metadata_delete(target, md->name, 0); - } + struct Metadata *md; + struct DictionaryIter iter; + + DICTIONARY_FOREACH(md, &iter, target->user->metadata) { + user_metadata_delete(target, md->name, 0); + } } diff --git a/src/extban.c b/src/extban.c index ca32f08..d4eff4b 100644 --- a/src/extban.c +++ b/src/extban.c @@ -31,77 +31,74 @@ ExtbanFunc extban_table[256] = { NULL }; int match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) { - const char *p; - int invert = 0, result = EXTBAN_INVALID; - ExtbanFunc f; + const char *p; + int invert = 0, result = EXTBAN_INVALID; + ExtbanFunc f; - if (*banstr != '$') - return 0; - p = banstr + 1; - if (*p == '~') - { - invert = 1; - p++; - } - f = extban_table[(unsigned char) ToLower(*p)]; - if (*p != '\0') - { - p++; - if (*p == ':') - p++; - else - p = NULL; - } - if (f != NULL) - result = f(p, client_p, chptr, mode_type); - else - result = EXTBAN_INVALID; + if (*banstr != '$') + return 0; + p = banstr + 1; + if (*p == '~') { + invert = 1; + p++; + } + f = extban_table[(unsigned char) ToLower(*p)]; + if (*p != '\0') { + p++; + if (*p == ':') + p++; + else + p = NULL; + } + if (f != NULL) + result = f(p, client_p, chptr, mode_type); + else + result = EXTBAN_INVALID; - if (invert) - return result == EXTBAN_NOMATCH; - else - return result == EXTBAN_MATCH; + if (invert) + return result == EXTBAN_NOMATCH; + else + return result == EXTBAN_MATCH; } int valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) { - const char *p; - int result = EXTBAN_INVALID; - ExtbanFunc f; + const char *p; + int result = EXTBAN_INVALID; + ExtbanFunc f; - if (*banstr != '$') - return 0; - p = banstr + 1; - if (*p == '~') - p++; - f = extban_table[(unsigned char) ToLower(*p)]; - if (*p != '\0') - { - p++; - if (*p == ':') - p++; - else - p = NULL; - } - if (f != NULL) - result = f(p, client_p, chptr, mode_type); - else - result = EXTBAN_INVALID; + if (*banstr != '$') + return 0; + p = banstr + 1; + if (*p == '~') + p++; + f = extban_table[(unsigned char) ToLower(*p)]; + if (*p != '\0') { + p++; + if (*p == ':') + p++; + else + p = NULL; + } + if (f != NULL) + result = f(p, client_p, chptr, mode_type); + else + result = EXTBAN_INVALID; - return result != EXTBAN_INVALID; + return result != EXTBAN_INVALID; } const char * get_extban_string(void) { - static char e[256]; - int i, j; + static char e[256]; + int i, j; - j = 0; - for (i = 1; i < 256; i++) - if (i == ToLower(i) && extban_table[i]) - e[j++] = i; - e[j] = 0; - return e; + j = 0; + for (i = 1; i < 256; i++) + if (i == ToLower(i) && extban_table[i]) + e[j++] = i; + e[j] = 0; + return e; } diff --git a/src/getopt.c b/src/getopt.c index eb457bd..71b2f92 100644 --- a/src/getopt.c +++ b/src/getopt.c @@ -32,108 +32,98 @@ void parseargs(int *argc, char ***argv, struct lgetopt *opts) { - int i; - char *progname = (*argv)[0]; + int i; + char *progname = (*argv)[0]; - /* loop through each argument */ - for (;;) - { - int found = 0; + /* loop through each argument */ + for (;;) { + int found = 0; - (*argc)--; - (*argv)++; + (*argc)--; + (*argv)++; - if(*argc < 1) - { - return; - } + if(*argc < 1) { + return; + } - /* check if it *is* an arg.. */ - if((*argv)[0][0] != OPTCHAR) - { - return; - } + /* check if it *is* an arg.. */ + if((*argv)[0][0] != OPTCHAR) { + return; + } - (*argv)[0]++; + (*argv)[0]++; - /* search through our argument list, and see if it matches */ - for (i = 0; opts[i].opt; i++) - { - if(!strcmp(opts[i].opt, (*argv)[0])) - { - /* found our argument */ - found = 1; + /* search through our argument list, and see if it matches */ + for (i = 0; opts[i].opt; i++) { + if(!strcmp(opts[i].opt, (*argv)[0])) { + /* found our argument */ + found = 1; - switch (opts[i].argtype) - { - case YESNO: - *((int *) opts[i].argloc) = 1; - break; - case INTEGER: - if(*argc < 2) - { - fprintf(stderr, - "Error: option '%c%s' requires an argument\n", - OPTCHAR, opts[i].opt); - usage((*argv)[0]); - } + switch (opts[i].argtype) { + case YESNO: + *((int *) opts[i].argloc) = 1; + break; + case INTEGER: + if(*argc < 2) { + fprintf(stderr, + "Error: option '%c%s' requires an argument\n", + OPTCHAR, opts[i].opt); + usage((*argv)[0]); + } - *((int *) opts[i].argloc) = atoi((*argv)[1]); + *((int *) opts[i].argloc) = atoi((*argv)[1]); - (*argc)--; - (*argv)++; - break; - case STRING: - if(*argc < 2) - { - fprintf(stderr, - "error: option '%c%s' requires an argument\n", - OPTCHAR, opts[i].opt); - usage(progname); - } + (*argc)--; + (*argv)++; + break; + case STRING: + if(*argc < 2) { + fprintf(stderr, + "error: option '%c%s' requires an argument\n", + OPTCHAR, opts[i].opt); + usage(progname); + } - *((char **) opts[i].argloc) = - malloc(strlen((*argv)[1]) + 1); - strcpy(*((char **) opts[i].argloc), (*argv)[1]); + *((char **) opts[i].argloc) = + malloc(strlen((*argv)[1]) + 1); + strcpy(*((char **) opts[i].argloc), (*argv)[1]); - (*argc)--; - (*argv)++; - break; + (*argc)--; + (*argv)++; + break; - case USAGE: - usage(progname); - /*NOTREACHED*/ default: - fprintf(stderr, - "Error: internal error in parseargs() at %s:%d\n", - __FILE__, __LINE__); - exit(EXIT_FAILURE); - } - } - } - if(!found) - { - fprintf(stderr, "error: unknown argument '%c%s'\n", OPTCHAR, (*argv)[0]); - usage(progname); - } - } + case USAGE: + usage(progname); + /*NOTREACHED*/ default: + fprintf(stderr, + "Error: internal error in parseargs() at %s:%d\n", + __FILE__, __LINE__); + exit(EXIT_FAILURE); + } + } + } + if(!found) { + fprintf(stderr, "error: unknown argument '%c%s'\n", OPTCHAR, (*argv)[0]); + usage(progname); + } + } } void usage(char *name) { - int i = 0; + int i = 0; - fprintf(stderr, "Usage: %s [options]\n", name); - fprintf(stderr, "Where valid options are:\n"); + fprintf(stderr, "Usage: %s [options]\n", name); + fprintf(stderr, "Where valid options are:\n"); - for (i = 0; myopts[i].opt; i++) - { - fprintf(stderr, "\t%c%-10s %-20s%s\n", OPTCHAR, - myopts[i].opt, (myopts[i].argtype == YESNO - || myopts[i].argtype == - USAGE) ? "" : myopts[i].argtype == - INTEGER ? "" : "", myopts[i].desc); - } + for (i = 0; myopts[i].opt; i++) { + fprintf(stderr, "\t%c%-10s %-20s%s\n", OPTCHAR, + myopts[i].opt, (myopts[i].argtype == YESNO + || myopts[i].argtype == + USAGE) ? "" : myopts[i].argtype == + INTEGER ? "" : "", myopts[i].desc); + } - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } diff --git a/src/hash.c b/src/hash.c index 9cac5bc..b9ffd63 100644 --- a/src/hash.c +++ b/src/hash.c @@ -46,7 +46,7 @@ rb_dlink_list *clientTable; rb_dlink_list *channelTable; rb_dlink_list *idTable; rb_dlink_list *resvTable; -rb_dlink_list *hostTable; +rb_dlink_list *hostTable; /* * look in whowas.c for the missing ...[WW_MAX]; entry @@ -75,14 +75,14 @@ rb_dlink_list *hostTable; * * A - GOPbot, B - chang, C - hanuaway, D - *.mu.OZ.AU * - * The order shown above is just one instant of the server. + * The order shown above is just one instant of the server. * * * The hash functions currently used are based Fowler/Noll/Vo hashes * which work amazingly well and have a extremely low collision rate * For more info see http://www.isthe.com/chongo/tech/comp/fnv/index.html * - * + * */ /* init_hash() @@ -92,72 +92,68 @@ rb_dlink_list *hostTable; void init_hash(void) { - clientTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); - idTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); - channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX); - hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX); - resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX); + clientTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); + idTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); + channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX); + hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX); + resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX); } #ifndef RICER_HASHING u_int32_t fnv_hash_upper(const unsigned char *s, int bits) { - u_int32_t h = FNV1_32_INIT; + u_int32_t h = FNV1_32_INIT; - while (*s) - { - h ^= ToUpper(*s++); - h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24); - } - if (bits < 32) - h = ((h >> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<data; + RB_DLINK_FOREACH(ptr, idTable[hashv].head) { + target_p = ptr->data; - if(strcmp(name, target_p->id) == 0) - return target_p; - } + if(strcmp(name, target_p->id) == 0) + return target_p; + } - return NULL; + return NULL; } /* find_client() @@ -408,29 +403,28 @@ find_id(const char *name) struct Client * find_client(const char *name) { - struct Client *target_p; - rb_dlink_node *ptr; - unsigned int hashv; + struct Client *target_p; + rb_dlink_node *ptr; + unsigned int hashv; - s_assert(name != NULL); - if(EmptyString(name)) - return NULL; + s_assert(name != NULL); + if(EmptyString(name)) + return NULL; - /* hunting for an id, not a nick */ - if(IsDigit(*name)) - return (find_id(name)); + /* hunting for an id, not a nick */ + if(IsDigit(*name)) + return (find_id(name)); - hashv = hash_nick(name); + hashv = hash_nick(name); - RB_DLINK_FOREACH(ptr, clientTable[hashv].head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { + target_p = ptr->data; - if(irccmp(name, target_p->name) == 0) - return target_p; - } + if(irccmp(name, target_p->name) == 0) + return target_p; + } - return NULL; + return NULL; } /* find_named_client() @@ -440,25 +434,24 @@ find_client(const char *name) struct Client * find_named_client(const char *name) { - struct Client *target_p; - rb_dlink_node *ptr; - unsigned int hashv; + struct Client *target_p; + rb_dlink_node *ptr; + unsigned int hashv; - s_assert(name != NULL); - if(EmptyString(name)) - return NULL; + s_assert(name != NULL); + if(EmptyString(name)) + return NULL; - hashv = hash_nick(name); + hashv = hash_nick(name); - RB_DLINK_FOREACH(ptr, clientTable[hashv].head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { + target_p = ptr->data; - if(irccmp(name, target_p->name) == 0) - return target_p; - } + if(irccmp(name, target_p->name) == 0) + return target_p; + } - return NULL; + return NULL; } /* find_server() @@ -468,32 +461,30 @@ find_named_client(const char *name) struct Client * find_server(struct Client *source_p, const char *name) { - struct Client *target_p; - rb_dlink_node *ptr; - unsigned int hashv; - - if(EmptyString(name)) - return NULL; + struct Client *target_p; + rb_dlink_node *ptr; + unsigned int hashv; - if((source_p == NULL || !MyClient(source_p)) && - IsDigit(*name) && strlen(name) == 3) - { - target_p = find_id(name); - return(target_p); - } + if(EmptyString(name)) + return NULL; - hashv = hash_nick(name); + if((source_p == NULL || !MyClient(source_p)) && + IsDigit(*name) && strlen(name) == 3) { + target_p = find_id(name); + return(target_p); + } - RB_DLINK_FOREACH(ptr, clientTable[hashv].head) - { - target_p = ptr->data; + hashv = hash_nick(name); - if((IsServer(target_p) || IsMe(target_p)) && - irccmp(name, target_p->name) == 0) - return target_p; - } + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { + target_p = ptr->data; - return NULL; + if((IsServer(target_p) || IsMe(target_p)) && + irccmp(name, target_p->name) == 0) + return target_p; + } + + return NULL; } /* find_hostname() @@ -505,14 +496,14 @@ find_server(struct Client *source_p, const char *name) rb_dlink_node * find_hostname(const char *hostname) { - unsigned int hashv; + unsigned int hashv; - if(EmptyString(hostname)) - return NULL; + if(EmptyString(hostname)) + return NULL; - hashv = hash_hostname(hostname); + hashv = hash_hostname(hostname); - return hostTable[hashv].head; + return hostTable[hashv].head; } /* find_channel() @@ -522,25 +513,24 @@ find_hostname(const char *hostname) struct Channel * find_channel(const char *name) { - struct Channel *chptr; - rb_dlink_node *ptr; - unsigned int hashv; + struct Channel *chptr; + rb_dlink_node *ptr; + unsigned int hashv; - s_assert(name != NULL); - if(EmptyString(name)) - return NULL; + s_assert(name != NULL); + if(EmptyString(name)) + return NULL; - hashv = hash_channel(name); + hashv = hash_channel(name); - RB_DLINK_FOREACH(ptr, channelTable[hashv].head) - { - chptr = ptr->data; + RB_DLINK_FOREACH(ptr, channelTable[hashv].head) { + chptr = ptr->data; - if(irccmp(name, chptr->chname) == 0) - return chptr; - } + if(irccmp(name, chptr->chname) == 0) + return chptr; + } - return NULL; + return NULL; } /* @@ -557,57 +547,53 @@ find_channel(const char *name) struct Channel * get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) { - struct Channel *chptr; - rb_dlink_node *ptr; - unsigned int hashv; - int len; - const char *s = chname; + struct Channel *chptr; + rb_dlink_node *ptr; + unsigned int hashv; + int len; + const char *s = chname; - if(EmptyString(s)) - return NULL; + if(EmptyString(s)) + return NULL; - len = strlen(s); - if(len > CHANNELLEN) - { - char *t; - if(IsServer(client_p)) - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "*** Long channel name from %s (%d > %d): %s", - client_p->name, len, CHANNELLEN, s); - } - len = CHANNELLEN; - t = LOCAL_COPY(s); - *(t + CHANNELLEN) = '\0'; - s = t; - } + len = strlen(s); + if(len > CHANNELLEN) { + char *t; + if(IsServer(client_p)) { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "*** Long channel name from %s (%d > %d): %s", + client_p->name, len, CHANNELLEN, s); + } + len = CHANNELLEN; + t = LOCAL_COPY(s); + *(t + CHANNELLEN) = '\0'; + s = t; + } - hashv = hash_channel(s); + hashv = hash_channel(s); - RB_DLINK_FOREACH(ptr, channelTable[hashv].head) - { - chptr = ptr->data; + RB_DLINK_FOREACH(ptr, channelTable[hashv].head) { + chptr = ptr->data; - if(irccmp(s, chptr->chname) == 0) - { - if(isnew != NULL) - *isnew = 0; - return chptr; - } - } + if(irccmp(s, chptr->chname) == 0) { + if(isnew != NULL) + *isnew = 0; + return chptr; + } + } - if(isnew != NULL) - *isnew = 1; + if(isnew != NULL) + *isnew = 1; - chptr = allocate_channel(s); + chptr = allocate_channel(s); - rb_dlinkAdd(chptr, &chptr->node, &global_channel_list); + rb_dlinkAdd(chptr, &chptr->node, &global_channel_list); - chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */ + chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */ - rb_dlinkAddAlloc(chptr, &channelTable[hashv]); + rb_dlinkAddAlloc(chptr, &channelTable[hashv]); - return chptr; + return chptr; } /* hash_find_resv() @@ -617,155 +603,147 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) struct ConfItem * hash_find_resv(const char *name) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - unsigned int hashv; + struct ConfItem *aconf; + rb_dlink_node *ptr; + unsigned int hashv; - s_assert(name != NULL); - if(EmptyString(name)) - return NULL; + s_assert(name != NULL); + if(EmptyString(name)) + return NULL; - hashv = hash_resv(name); + hashv = hash_resv(name); - RB_DLINK_FOREACH(ptr, resvTable[hashv].head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, resvTable[hashv].head) { + aconf = ptr->data; - if(!irccmp(name, aconf->host)) - { - aconf->port++; - return aconf; - } - } + if(!irccmp(name, aconf->host)) { + aconf->port++; + return aconf; + } + } - return NULL; + return NULL; } void clear_resv_hash(void) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + int i; - HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) - { - aconf = ptr->data; + HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) { + aconf = ptr->data; - /* skip temp resvs */ - if(aconf->hold) - continue; + /* skip temp resvs */ + if(aconf->hold) + continue; - free_conf(ptr->data); - rb_dlinkDestroy(ptr, &resvTable[i]); - } - HASH_WALK_END + free_conf(ptr->data); + rb_dlinkDestroy(ptr, &resvTable[i]); + } + HASH_WALK_END } void add_to_cli_fd_hash(struct Client *client_p) { - rb_dlinkAddAlloc(client_p, &clientbyfdTable[hash_cli_fd(rb_get_fd(client_p->localClient->F))]); + rb_dlinkAddAlloc(client_p, &clientbyfdTable[hash_cli_fd(rb_get_fd(client_p->localClient->F))]); } void del_from_cli_fd_hash(struct Client *client_p) { - unsigned int hashv; - hashv = hash_cli_fd(rb_get_fd(client_p->localClient->F)); - rb_dlinkFindDestroy(client_p, &clientbyfdTable[hashv]); + unsigned int hashv; + hashv = hash_cli_fd(rb_get_fd(client_p->localClient->F)); + rb_dlinkFindDestroy(client_p, &clientbyfdTable[hashv]); } struct Client * find_cli_fd_hash(int fd) { - struct Client *target_p; - rb_dlink_node *ptr; - unsigned int hashv; - hashv = hash_cli_fd(fd); - RB_DLINK_FOREACH(ptr, clientbyfdTable[hashv].head) - { - target_p = ptr->data; - if(rb_get_fd(target_p->localClient->F) == fd) - return target_p; - } - return NULL; + struct Client *target_p; + rb_dlink_node *ptr; + unsigned int hashv; + hashv = hash_cli_fd(fd); + RB_DLINK_FOREACH(ptr, clientbyfdTable[hashv].head) { + target_p = ptr->data; + if(rb_get_fd(target_p->localClient->F) == fd) + return target_p; + } + return NULL; } static void output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest) { - unsigned long total = 0; - int i; - char buf[128]; + unsigned long total = 0; + int i; + char buf[128]; - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :%s Hash Statistics", name); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :%s Hash Statistics", name); - snprintf(buf, sizeof buf, "%.3f%%", - (float) ((counts[0]*100) / (float) length)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Size: %d Empty: %d (%s)", - length, counts[0], buf); + snprintf(buf, sizeof buf, "%.3f%%", + (float) ((counts[0]*100) / (float) length)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Size: %d Empty: %d (%s)", + length, counts[0], buf); - for(i = 1; i < 11; i++) - { - total += (counts[i] * i); - } + for(i = 1; i < 11; i++) { + total += (counts[i] * i); + } - /* dont want to divide by 0! --fl */ - if(counts[0] != length) - { - snprintf(buf, sizeof buf, "%.3f/%.3f", - (float) (total / (length - counts[0])), - (float) (total / length)); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Average depth: %s Highest depth: %d", - buf, deepest); - } + /* dont want to divide by 0! --fl */ + if(counts[0] != length) { + snprintf(buf, sizeof buf, "%.3f/%.3f", + (float) (total / (length - counts[0])), + (float) (total / length)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Average depth: %s Highest depth: %d", + buf, deepest); + } - for(i = 0; i < 11; i++) - { - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Nodes with %d entries: %d", - i, counts[i]); - } + for(i = 0; i < 11; i++) { + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Nodes with %d entries: %d", + i, counts[i]); + } } - + static void count_hash(struct Client *source_p, rb_dlink_list *table, int length, const char *name) { - int counts[11]; - int deepest = 0; - int i; + int counts[11]; + int deepest = 0; + int i; - memset(counts, 0, sizeof(counts)); - - for(i = 0; i < length; i++) - { - if(rb_dlink_list_length(&table[i]) >= 10) - counts[10]++; - else - counts[rb_dlink_list_length(&table[i])]++; + memset(counts, 0, sizeof(counts)); - if(rb_dlink_list_length(&table[i]) > deepest) - deepest = rb_dlink_list_length(&table[i]); - } + for(i = 0; i < length; i++) { + if(rb_dlink_list_length(&table[i]) >= 10) + counts[10]++; + else + counts[rb_dlink_list_length(&table[i])]++; - output_hash(source_p, name, length, counts, deepest); + if(rb_dlink_list_length(&table[i]) > deepest) + deepest = rb_dlink_list_length(&table[i]); + } + + output_hash(source_p, name, length, counts, deepest); } void hash_stats(struct Client *source_p) { - count_hash(source_p, channelTable, CH_MAX, "Channel"); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); - count_hash(source_p, clientTable, U_MAX, "Client"); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); - count_hash(source_p, idTable, U_MAX, "ID"); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); - count_hash(source_p, hostTable, HOST_MAX, "Hostname"); -} + count_hash(source_p, channelTable, CH_MAX, "Channel"); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); + count_hash(source_p, clientTable, U_MAX, "Client"); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); + count_hash(source_p, idTable, U_MAX, "ID"); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); + count_hash(source_p, hostTable, HOST_MAX, "Hostname"); +} diff --git a/src/hook.c b/src/hook.c index 4f5c6ec..00c57a6 100644 --- a/src/hook.c +++ b/src/hook.c @@ -67,25 +67,25 @@ int h_can_kick; void init_hook(void) { - hooks = rb_malloc(sizeof(hook) * HOOK_INCREMENT); + hooks = rb_malloc(sizeof(hook) * HOOK_INCREMENT); #ifdef USE_IODEBUG_HOOKS - h_iosend_id = register_hook("iosend"); - h_iorecv_id = register_hook("iorecv"); - h_iorecvctrl_id = register_hook("iorecvctrl"); + h_iosend_id = register_hook("iosend"); + h_iorecv_id = register_hook("iorecv"); + h_iorecvctrl_id = register_hook("iorecvctrl"); #endif - h_burst_client = register_hook("burst_client"); - h_burst_channel = register_hook("burst_channel"); - h_burst_finished = register_hook("burst_finished"); - h_server_introduced = register_hook("server_introduced"); - h_server_eob = register_hook("server_eob"); - h_client_exit = register_hook("client_exit"); - h_umode_changed = register_hook("umode_changed"); - h_new_local_user = register_hook("new_local_user"); - h_new_remote_user = register_hook("new_remote_user"); - h_introduce_client = register_hook("introduce_client"); - h_can_kick = register_hook("can_kick"); + h_burst_client = register_hook("burst_client"); + h_burst_channel = register_hook("burst_channel"); + h_burst_finished = register_hook("burst_finished"); + h_server_introduced = register_hook("server_introduced"); + h_server_eob = register_hook("server_eob"); + h_client_exit = register_hook("client_exit"); + h_umode_changed = register_hook("umode_changed"); + h_new_local_user = register_hook("new_local_user"); + h_new_remote_user = register_hook("new_remote_user"); + h_introduce_client = register_hook("introduce_client"); + h_can_kick = register_hook("can_kick"); } /* grow_hooktable() @@ -94,14 +94,14 @@ init_hook(void) static void grow_hooktable(void) { - hook *newhooks; + hook *newhooks; - newhooks = rb_malloc(sizeof(hook) * (max_hooks + HOOK_INCREMENT)); - memcpy(newhooks, hooks, sizeof(hook) * num_hooks); + newhooks = rb_malloc(sizeof(hook) * (max_hooks + HOOK_INCREMENT)); + memcpy(newhooks, hooks, sizeof(hook) * num_hooks); - rb_free(hooks); - hooks = newhooks; - max_hooks += HOOK_INCREMENT; + rb_free(hooks); + hooks = newhooks; + max_hooks += HOOK_INCREMENT; } /* find_freehookslot() @@ -111,19 +111,18 @@ grow_hooktable(void) static int find_freehookslot(void) { - int i; + int i; - if((num_hooks + 1) > max_hooks) - grow_hooktable(); + if((num_hooks + 1) > max_hooks) + grow_hooktable(); - for(i = 0; i < max_hooks; i++) - { - if(!hooks[i].name) - return i; - } + for(i = 0; i < max_hooks; i++) { + if(!hooks[i].name) + return i; + } - /* shouldnt ever get here */ - return(max_hooks - 1); + /* shouldnt ever get here */ + return(max_hooks - 1); } /* find_hook() @@ -132,18 +131,17 @@ find_freehookslot(void) static int find_hook(const char *name) { - int i; + int i; - for(i = 0; i < max_hooks; i++) - { - if(!hooks[i].name) - continue; + for(i = 0; i < max_hooks; i++) { + if(!hooks[i].name) + continue; - if(!irccmp(hooks[i].name, name)) - return i; - } + if(!irccmp(hooks[i].name, name)) + return i; + } - return -1; + return -1; } /* register_hook() @@ -153,16 +151,15 @@ find_hook(const char *name) int register_hook(const char *name) { - int i; + int i; - if((i = find_hook(name)) < 0) - { - i = find_freehookslot(); - hooks[i].name = rb_strdup(name); - num_hooks++; - } + if((i = find_hook(name)) < 0) { + i = find_freehookslot(); + hooks[i].name = rb_strdup(name); + num_hooks++; + } - return i; + return i; } /* add_hook() @@ -172,11 +169,11 @@ register_hook(const char *name) void add_hook(const char *name, hookfn fn) { - int i; + int i; - i = register_hook(name); + i = register_hook(name); - rb_dlinkAddAlloc(fn, &hooks[i].hooks); + rb_dlinkAddAlloc(fn, &hooks[i].hooks); } /* remove_hook() @@ -185,12 +182,12 @@ add_hook(const char *name, hookfn fn) void remove_hook(const char *name, hookfn fn) { - int i; + int i; - if((i = find_hook(name)) < 0) - return; + if((i = find_hook(name)) < 0) + return; - rb_dlinkFindDestroy(fn, &hooks[i].hooks); + rb_dlinkFindDestroy(fn, &hooks[i].hooks); } /* call_hook() @@ -199,16 +196,15 @@ remove_hook(const char *name, hookfn fn) void call_hook(int id, void *arg) { - hookfn fn; - rb_dlink_node *ptr; + hookfn fn; + rb_dlink_node *ptr; - /* The ID we were passed is the position in the hook table of this - * hook - */ - RB_DLINK_FOREACH(ptr, hooks[id].hooks.head) - { - fn = ptr->data; - fn(arg); - } + /* The ID we were passed is the position in the hook table of this + * hook + */ + RB_DLINK_FOREACH(ptr, hooks[id].hooks.head) { + fn = ptr->data; + fn(arg); + } } diff --git a/src/hostmask.c b/src/hostmask.c index 7792993..7cf3e7e 100644 --- a/src/hostmask.c +++ b/src/hostmask.c @@ -48,59 +48,54 @@ static unsigned long hash_ipv4(struct sockaddr *, int); int parse_netmask(const char *text, struct sockaddr *naddr, int *nb) { - char *ip = LOCAL_COPY(text); - char *ptr; - struct rb_sockaddr_storage *addr, xaddr; - int *b, xb; - if(nb == NULL) - b = &xb; - else - b = nb; - - if(naddr == NULL) - addr = (struct rb_sockaddr_storage *)&xaddr; - else - addr = (struct rb_sockaddr_storage *)naddr; + char *ip = LOCAL_COPY(text); + char *ptr; + struct rb_sockaddr_storage *addr, xaddr; + int *b, xb; + if(nb == NULL) + b = &xb; + else + b = nb; - if(strpbrk(ip, "*?") != NULL) - { - return HM_HOST; - } + if(naddr == NULL) + addr = (struct rb_sockaddr_storage *)&xaddr; + else + addr = (struct rb_sockaddr_storage *)naddr; + + if(strpbrk(ip, "*?") != NULL) { + return HM_HOST; + } #ifdef RB_IPV6 - if(strchr(ip, ':')) - { - if((ptr = strchr(ip, '/'))) - { - *ptr = '\0'; - ptr++; - *b = atoi(ptr); - if(*b > 128) - *b = 128; - } else - *b = 128; - if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0) - return HM_IPV6; - else - return HM_HOST; - } else + if(strchr(ip, ':')) { + if((ptr = strchr(ip, '/'))) { + *ptr = '\0'; + ptr++; + *b = atoi(ptr); + if(*b > 128) + *b = 128; + } else + *b = 128; + if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0) + return HM_IPV6; + else + return HM_HOST; + } else #endif - if(strchr(text, '.')) - { - if((ptr = strchr(ip, '/'))) - { - *ptr = '\0'; - ptr++; - *b = atoi(ptr); - if(*b > 32) - *b = 32; - } else - *b = 32; - if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0) - return HM_IPV4; - else - return HM_HOST; - } - return HM_HOST; + if(strchr(text, '.')) { + if((ptr = strchr(ip, '/'))) { + *ptr = '\0'; + ptr++; + *b = atoi(ptr); + if(*b > 32) + *b = 32; + } else + *b = 32; + if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0) + return HM_IPV4; + else + return HM_HOST; + } + return HM_HOST; } /* Hashtable stuff...now external as its used in m_stats.c */ @@ -109,7 +104,7 @@ struct AddressRec *atable[ATABLE_SIZE]; void init_host_hash(void) { - memset(&atable, 0, sizeof(atable)); + memset(&atable, 0, sizeof(atable)); } /* unsigned long hash_ipv4(struct rb_sockaddr_storage*) @@ -120,15 +115,14 @@ init_host_hash(void) static unsigned long hash_ipv4(struct sockaddr *saddr, int bits) { - struct sockaddr_in *addr = (struct sockaddr_in *) saddr; - - if(bits != 0) - { - unsigned long av = ntohl(addr->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1); - return (av ^ (av >> 12) ^ (av >> 24)) & (ATABLE_SIZE - 1); - } + struct sockaddr_in *addr = (struct sockaddr_in *) saddr; - return 0; + if(bits != 0) { + unsigned long av = ntohl(addr->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1); + return (av ^ (av >> 12) ^ (av >> 24)) & (ATABLE_SIZE - 1); + } + + return 0; } /* unsigned long hash_ipv6(struct rb_sockaddr_storage*) @@ -140,24 +134,19 @@ hash_ipv4(struct sockaddr *saddr, int bits) static unsigned long hash_ipv6(struct sockaddr *saddr, int bits) { - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr; - unsigned long v = 0, n; - for (n = 0; n < 16; n++) - { - if(bits >= 8) - { - v ^= addr->sin6_addr.s6_addr[n]; - bits -= 8; - } - else if(bits) - { - v ^= addr->sin6_addr.s6_addr[n] & ~((1 << (8 - bits)) - 1); - return v & (ATABLE_SIZE - 1); - } - else - return v & (ATABLE_SIZE - 1); - } - return v & (ATABLE_SIZE - 1); + struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr; + unsigned long v = 0, n; + for (n = 0; n < 16; n++) { + if(bits >= 8) { + v ^= addr->sin6_addr.s6_addr[n]; + bits -= 8; + } else if(bits) { + v ^= addr->sin6_addr.s6_addr[n] & ~((1 << (8 - bits)) - 1); + return v & (ATABLE_SIZE - 1); + } else + return v & (ATABLE_SIZE - 1); + } + return v & (ATABLE_SIZE - 1); } #endif @@ -169,15 +158,14 @@ hash_ipv6(struct sockaddr *saddr, int bits) static int hash_text(const char *start) { - const char *p = start; - unsigned long h = 0; + const char *p = start; + unsigned long h = 0; - while(*p) - { - h = (h << 4) - (h + (unsigned char) ToLower(*p++)); - } + while(*p) { + h = (h << 4) - (h + (unsigned char) ToLower(*p++)); + } - return (h & (ATABLE_SIZE - 1)); + return (h & (ATABLE_SIZE - 1)); } /* unsigned long get_hash_mask(const char *) @@ -189,14 +177,14 @@ hash_text(const char *start) static unsigned long get_mask_hash(const char *text) { - const char *hp = "", *p; + const char *hp = "", *p; - for (p = text + strlen(text) - 1; p >= text; p--) - if(*p == '*' || *p == '?') - return hash_text(hp); - else if(*p == '.') - hp = p + 1; - return hash_text(text); + for (p = text + strlen(text) - 1; p >= text; p--) + if(*p == '*' || *p == '?') + return hash_text(hp); + else if(*p == '.') + hp = p + 1; + return hash_text(text); } /* struct ConfItem* find_conf_by_address(const char*, struct rb_sockaddr_storage*, @@ -209,149 +197,131 @@ get_mask_hash(const char *text) */ struct ConfItem * find_conf_by_address(const char *name, const char *sockhost, - const char *orighost, - struct sockaddr *addr, int type, int fam, - const char *username, const char *auth_user) + const char *orighost, + struct sockaddr *addr, int type, int fam, + const char *username, const char *auth_user) { - unsigned long hprecv = 0; - struct ConfItem *hprec = NULL; - struct AddressRec *arec; - int b; + unsigned long hprecv = 0; + struct ConfItem *hprec = NULL; + struct AddressRec *arec; + int b; - if(username == NULL) - username = ""; + if(username == NULL) + username = ""; - if(addr) - { - /* Check for IPV6 matches... */ + if(addr) { + /* Check for IPV6 matches... */ #ifdef RB_IPV6 - if(fam == AF_INET6) - { + if(fam == AF_INET6) { - for (b = 128; b >= 0; b -= 16) - { - for (arec = atable[hash_ipv6(addr, b)]; arec; arec = arec->next) - if(arec->type == (type & ~0x1) && - arec->masktype == HM_IPV6 && - comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr, - arec->Mask.ipa.bits) && - (type & 0x1 || match(arec-> username, username)) && - (type != CONF_CLIENT || !arec->auth_user || - (auth_user && match(arec->auth_user, auth_user))) && - arec->precedence > hprecv) - { - hprecv = arec->precedence; - hprec = arec->aconf; - } - } - } - else + for (b = 128; b >= 0; b -= 16) { + for (arec = atable[hash_ipv6(addr, b)]; arec; arec = arec->next) + if(arec->type == (type & ~0x1) && + arec->masktype == HM_IPV6 && + comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr, + arec->Mask.ipa.bits) && + (type & 0x1 || match(arec-> username, username)) && + (type != CONF_CLIENT || !arec->auth_user || + (auth_user && match(arec->auth_user, auth_user))) && + arec->precedence > hprecv) { + hprecv = arec->precedence; + hprec = arec->aconf; + } + } + } else #endif - if(fam == AF_INET) - { - for (b = 32; b >= 0; b -= 8) - { - for (arec = atable[hash_ipv4(addr, b)]; arec; arec = arec->next) - if(arec->type == (type & ~0x1) && - arec->masktype == HM_IPV4 && - comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr, - arec->Mask.ipa.bits) && - (type & 0x1 || match(arec->username, username)) && - (type != CONF_CLIENT || !arec->auth_user || - (auth_user && match(arec->auth_user, auth_user))) && - arec->precedence > hprecv) - { - hprecv = arec->precedence; - hprec = arec->aconf; - } - } - } - } + if(fam == AF_INET) { + for (b = 32; b >= 0; b -= 8) { + for (arec = atable[hash_ipv4(addr, b)]; arec; arec = arec->next) + if(arec->type == (type & ~0x1) && + arec->masktype == HM_IPV4 && + comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr, + arec->Mask.ipa.bits) && + (type & 0x1 || match(arec->username, username)) && + (type != CONF_CLIENT || !arec->auth_user || + (auth_user && match(arec->auth_user, auth_user))) && + arec->precedence > hprecv) { + hprecv = arec->precedence; + hprec = arec->aconf; + } + } + } + } - if(orighost != NULL) - { - const char *p; + if(orighost != NULL) { + const char *p; - for (p = orighost; p != NULL;) - { - for (arec = atable[hash_text(p)]; arec; arec = arec->next) - - if((arec->type == (type & ~0x1)) && - (arec->masktype == HM_HOST) && - arec->precedence > hprecv && - match(arec->Mask.hostname, orighost) && - (type != CONF_CLIENT || !arec->auth_user || - (auth_user && match(arec->auth_user, auth_user))) && - (type & 0x1 || match(arec->username, username))) - { - hprecv = arec->precedence; - hprec = arec->aconf; - } - p = strchr(p, '.'); - if(p != NULL) - p++; - else - break; - } - for (arec = atable[0]; arec; arec = arec->next) - { - if(arec->type == (type & ~0x1) && - arec->masktype == HM_HOST && - arec->precedence > hprecv && - (match(arec->Mask.hostname, orighost) || - (sockhost && match(arec->Mask.hostname, sockhost))) && - (type != CONF_CLIENT || !arec->auth_user || - (auth_user && match(arec->auth_user, auth_user))) && - (type & 0x1 || match(arec->username, username))) - { - hprecv = arec->precedence; - hprec = arec->aconf; - } - } - } + for (p = orighost; p != NULL;) { + for (arec = atable[hash_text(p)]; arec; arec = arec->next) - if(name != NULL) - { - const char *p; - /* And yes - we have to check p after strchr and p after increment for - * NULL -kre */ - for (p = name; p != NULL;) - { - for (arec = atable[hash_text(p)]; arec; arec = arec->next) - if((arec->type == (type & ~0x1)) && - (arec->masktype == HM_HOST) && - arec->precedence > hprecv && - match(arec->Mask.hostname, name) && - (type != CONF_CLIENT || !arec->auth_user || - (auth_user && match(arec->auth_user, auth_user))) && - (type & 0x1 || match(arec->username, username))) - { - hprecv = arec->precedence; - hprec = arec->aconf; - } - p = strchr(p, '.'); - if(p != NULL) - p++; - else - break; - } - for (arec = atable[0]; arec; arec = arec->next) - { - if(arec->type == (type & ~0x1) && - arec->masktype == HM_HOST && - arec->precedence > hprecv && - (match(arec->Mask.hostname, name) || - (sockhost && match(arec->Mask.hostname, sockhost))) && - (type != CONF_CLIENT || !arec->auth_user || - (auth_user && match(arec->auth_user, auth_user))) && - (type & 0x1 || match(arec->username, username))) - { - hprecv = arec->precedence; - hprec = arec->aconf; - } - } - } - return hprec; + if((arec->type == (type & ~0x1)) && + (arec->masktype == HM_HOST) && + arec->precedence > hprecv && + match(arec->Mask.hostname, orighost) && + (type != CONF_CLIENT || !arec->auth_user || + (auth_user && match(arec->auth_user, auth_user))) && + (type & 0x1 || match(arec->username, username))) { + hprecv = arec->precedence; + hprec = arec->aconf; + } + p = strchr(p, '.'); + if(p != NULL) + p++; + else + break; + } + for (arec = atable[0]; arec; arec = arec->next) { + if(arec->type == (type & ~0x1) && + arec->masktype == HM_HOST && + arec->precedence > hprecv && + (match(arec->Mask.hostname, orighost) || + (sockhost && match(arec->Mask.hostname, sockhost))) && + (type != CONF_CLIENT || !arec->auth_user || + (auth_user && match(arec->auth_user, auth_user))) && + (type & 0x1 || match(arec->username, username))) { + hprecv = arec->precedence; + hprec = arec->aconf; + } + } + } + + if(name != NULL) { + const char *p; + /* And yes - we have to check p after strchr and p after increment for + * NULL -kre */ + for (p = name; p != NULL;) { + for (arec = atable[hash_text(p)]; arec; arec = arec->next) + if((arec->type == (type & ~0x1)) && + (arec->masktype == HM_HOST) && + arec->precedence > hprecv && + match(arec->Mask.hostname, name) && + (type != CONF_CLIENT || !arec->auth_user || + (auth_user && match(arec->auth_user, auth_user))) && + (type & 0x1 || match(arec->username, username))) { + hprecv = arec->precedence; + hprec = arec->aconf; + } + p = strchr(p, '.'); + if(p != NULL) + p++; + else + break; + } + for (arec = atable[0]; arec; arec = arec->next) { + if(arec->type == (type & ~0x1) && + arec->masktype == HM_HOST && + arec->precedence > hprecv && + (match(arec->Mask.hostname, name) || + (sockhost && match(arec->Mask.hostname, sockhost))) && + (type != CONF_CLIENT || !arec->auth_user || + (auth_user && match(arec->auth_user, auth_user))) && + (type & 0x1 || match(arec->username, username))) { + hprecv = arec->precedence; + hprec = arec->aconf; + } + } + } + return hprec; } /* struct ConfItem* find_address_conf(const char*, const char*, @@ -361,62 +331,58 @@ find_conf_by_address(const char *name, const char *sockhost, * Side-effects: None */ struct ConfItem * -find_address_conf(const char *host, const char *sockhost, const char *user, - const char *notildeuser, struct sockaddr *ip, int aftype, char *auth_user) +find_address_conf(const char *host, const char *sockhost, const char *user, + const char *notildeuser, struct sockaddr *ip, int aftype, char *auth_user) { - struct ConfItem *iconf, *kconf; - const char *vuser; + struct ConfItem *iconf, *kconf; + const char *vuser; - /* Find the best I-line... If none, return NULL -A1kmm */ - if(!(iconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_CLIENT, aftype, user, auth_user))) - return NULL; - /* Find what their visible username will be. - * Note that the username without tilde may contain one char more. - * -- jilles */ - vuser = IsNoTilde(iconf) ? notildeuser : user; + /* Find the best I-line... If none, return NULL -A1kmm */ + if(!(iconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_CLIENT, aftype, user, auth_user))) + return NULL; + /* Find what their visible username will be. + * Note that the username without tilde may contain one char more. + * -- jilles */ + vuser = IsNoTilde(iconf) ? notildeuser : user; - /* If they are exempt from K-lines, return the best I-line. -A1kmm */ - if(IsConfExemptKline(iconf)) - return iconf; + /* If they are exempt from K-lines, return the best I-line. -A1kmm */ + if(IsConfExemptKline(iconf)) + return iconf; - /* Find the best K-line... -A1kmm */ - kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, user, NULL); + /* Find the best K-line... -A1kmm */ + kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, user, NULL); - /* If they are K-lined, return the K-line */ - if(kconf) - return kconf; + /* If they are K-lined, return the K-line */ + if(kconf) + return kconf; - /* if theres a spoof, check it against klines.. */ - if(IsConfDoSpoofIp(iconf)) - { - char *p = strchr(iconf->info.name, '@'); + /* if theres a spoof, check it against klines.. */ + if(IsConfDoSpoofIp(iconf)) { + char *p = strchr(iconf->info.name, '@'); - /* note, we dont need to pass sockhost here, as its - * guaranteed to not match by whats above.. --anfl - */ - if(p) - { - *p = '\0'; - kconf = find_conf_by_address(p+1, NULL, NULL, ip, CONF_KILL, aftype, iconf->info.name, NULL); - *p = '@'; - } - else - kconf = find_conf_by_address(iconf->info.name, NULL, NULL, ip, CONF_KILL, aftype, vuser, NULL); + /* note, we dont need to pass sockhost here, as its + * guaranteed to not match by whats above.. --anfl + */ + if(p) { + *p = '\0'; + kconf = find_conf_by_address(p+1, NULL, NULL, ip, CONF_KILL, aftype, iconf->info.name, NULL); + *p = '@'; + } else + kconf = find_conf_by_address(iconf->info.name, NULL, NULL, ip, CONF_KILL, aftype, vuser, NULL); - if(kconf) - return kconf; - } + if(kconf) + return kconf; + } - /* if no_tilde, check the username without tilde against klines too - * -- jilles */ - if(user != vuser) - { - kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, vuser, NULL); - if(kconf) - return kconf; - } + /* if no_tilde, check the username without tilde against klines too + * -- jilles */ + if(user != vuser) { + kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, vuser, NULL); + if(kconf) + return kconf; + } - return iconf; + return iconf; } /* struct ConfItem* find_dline(struct rb_sockaddr_storage*, int) @@ -427,116 +393,101 @@ find_address_conf(const char *host, const char *sockhost, const char *user, struct ConfItem * find_dline(struct sockaddr *addr, int aftype) { - struct ConfItem *eline; - eline = find_conf_by_address(NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, aftype, NULL, NULL); - if(eline) - return eline; - return find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL, NULL); + struct ConfItem *eline; + eline = find_conf_by_address(NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, aftype, NULL, NULL); + if(eline) + return eline; + return find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL, NULL); } /* void find_exact_conf_by_address(const char*, int, const char *) - * Input: + * Input: * Output: ConfItem if found * Side-effects: None */ struct ConfItem * find_exact_conf_by_address(const char *address, int type, const char *username) { - int masktype, bits; - unsigned long hv; - struct AddressRec *arec; - struct rb_sockaddr_storage addr; + int masktype, bits; + unsigned long hv; + struct AddressRec *arec; + struct rb_sockaddr_storage addr; - if(address == NULL) - address = "/NOMATCH!/"; - masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); + if(address == NULL) + address = "/NOMATCH!/"; + masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); #ifdef RB_IPV6 - if(masktype == HM_IPV6) - { - /* We have to do this, since we do not re-hash for every bit -A1kmm. */ - hv = hash_ipv6((struct sockaddr *)&addr, bits - bits % 16); - } - else + if(masktype == HM_IPV6) { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + hv = hash_ipv6((struct sockaddr *)&addr, bits - bits % 16); + } else #endif - if(masktype == HM_IPV4) - { - /* We have to do this, since we do not re-hash for every bit -A1kmm. */ - hv = hash_ipv4((struct sockaddr *)&addr, bits - bits % 8); - } - else - { - hv = get_mask_hash(address); - } - for (arec = atable[hv]; arec; arec = arec->next) - { - if (arec->type == type && - arec->masktype == masktype && - (arec->username == NULL || username == NULL ? arec->username == username : !irccmp(arec->username, username))) - { - if (masktype == HM_HOST) - { - if (!irccmp(arec->Mask.hostname, address)) - return arec->aconf; - } - else - { - if (arec->Mask.ipa.bits == bits && - comp_with_mask_sock((struct sockaddr *)&arec->Mask.ipa.addr, (struct sockaddr *)&addr, bits)) - return arec->aconf; - } - } - } - return NULL; + if(masktype == HM_IPV4) { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + hv = hash_ipv4((struct sockaddr *)&addr, bits - bits % 8); + } else { + hv = get_mask_hash(address); + } + for (arec = atable[hv]; arec; arec = arec->next) { + if (arec->type == type && + arec->masktype == masktype && + (arec->username == NULL || username == NULL ? arec->username == username : !irccmp(arec->username, username))) { + if (masktype == HM_HOST) { + if (!irccmp(arec->Mask.hostname, address)) + return arec->aconf; + } else { + if (arec->Mask.ipa.bits == bits && + comp_with_mask_sock((struct sockaddr *)&arec->Mask.ipa.addr, (struct sockaddr *)&addr, bits)) + return arec->aconf; + } + } + } + return NULL; } /* void add_conf_by_address(const char*, int, const char *, * struct ConfItem *aconf) - * Input: + * Input: * Output: None * Side-effects: Adds this entry to the hash table. */ void add_conf_by_address(const char *address, int type, const char *username, const char *auth_user, struct ConfItem *aconf) { - static unsigned long prec_value = 0xFFFFFFFF; - int masktype, bits; - unsigned long hv; - struct AddressRec *arec; + static unsigned long prec_value = 0xFFFFFFFF; + int masktype, bits; + unsigned long hv; + struct AddressRec *arec; - if(address == NULL) - address = "/NOMATCH!/"; - arec = rb_malloc(sizeof(struct AddressRec)); - masktype = parse_netmask(address, (struct sockaddr *)&arec->Mask.ipa.addr, &bits); - arec->Mask.ipa.bits = bits; - arec->masktype = masktype; + if(address == NULL) + address = "/NOMATCH!/"; + arec = rb_malloc(sizeof(struct AddressRec)); + masktype = parse_netmask(address, (struct sockaddr *)&arec->Mask.ipa.addr, &bits); + arec->Mask.ipa.bits = bits; + arec->masktype = masktype; #ifdef RB_IPV6 - if(masktype == HM_IPV6) - { - /* We have to do this, since we do not re-hash for every bit -A1kmm. */ - bits -= bits % 16; - arec->next = atable[(hv = hash_ipv6((struct sockaddr *)&arec->Mask.ipa.addr, bits))]; - atable[hv] = arec; - } - else + if(masktype == HM_IPV6) { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + bits -= bits % 16; + arec->next = atable[(hv = hash_ipv6((struct sockaddr *)&arec->Mask.ipa.addr, bits))]; + atable[hv] = arec; + } else #endif - if(masktype == HM_IPV4) - { - /* We have to do this, since we do not re-hash for every bit -A1kmm. */ - bits -= bits % 8; - arec->next = atable[(hv = hash_ipv4((struct sockaddr *)&arec->Mask.ipa.addr, bits))]; - atable[hv] = arec; - } - else - { - arec->Mask.hostname = address; - arec->next = atable[(hv = get_mask_hash(address))]; - atable[hv] = arec; - } - arec->username = username; - arec->auth_user = auth_user; - arec->aconf = aconf; - arec->precedence = prec_value--; - arec->type = type; + if(masktype == HM_IPV4) { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + bits -= bits % 8; + arec->next = atable[(hv = hash_ipv4((struct sockaddr *)&arec->Mask.ipa.addr, bits))]; + atable[hv] = arec; + } else { + arec->Mask.hostname = address; + arec->next = atable[(hv = get_mask_hash(address))]; + atable[hv] = arec; + } + arec->username = username; + arec->auth_user = auth_user; + arec->aconf = aconf; + arec->precedence = prec_value--; + arec->type = type; } /* void delete_one_address(const char*, struct ConfItem*) @@ -548,44 +499,38 @@ add_conf_by_address(const char *address, int type, const char *username, const c void delete_one_address_conf(const char *address, struct ConfItem *aconf) { - int masktype, bits; - unsigned long hv; - struct AddressRec *arec, *arecl = NULL; - struct rb_sockaddr_storage addr; - masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); + int masktype, bits; + unsigned long hv; + struct AddressRec *arec, *arecl = NULL; + struct rb_sockaddr_storage addr; + masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); #ifdef RB_IPV6 - if(masktype == HM_IPV6) - { - /* We have to do this, since we do not re-hash for every bit -A1kmm. */ - bits -= bits % 16; - hv = hash_ipv6((struct sockaddr *)&addr, bits); - } - else + if(masktype == HM_IPV6) { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + bits -= bits % 16; + hv = hash_ipv6((struct sockaddr *)&addr, bits); + } else #endif - if(masktype == HM_IPV4) - { - /* We have to do this, since we do not re-hash for every bit -A1kmm. */ - bits -= bits % 8; - hv = hash_ipv4((struct sockaddr *)&addr, bits); - } - else - hv = get_mask_hash(address); - for (arec = atable[hv]; arec; arec = arec->next) - { - if(arec->aconf == aconf) - { - if(arecl) - arecl->next = arec->next; - else - atable[hv] = arec->next; - aconf->status |= CONF_ILLEGAL; - if(!aconf->clients) - free_conf(aconf); - rb_free(arec); - return; - } - arecl = arec; - } + if(masktype == HM_IPV4) { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + bits -= bits % 8; + hv = hash_ipv4((struct sockaddr *)&addr, bits); + } else + hv = get_mask_hash(address); + for (arec = atable[hv]; arec; arec = arec->next) { + if(arec->aconf == aconf) { + if(arecl) + arecl->next = arec->next; + else + atable[hv] = arec->next; + aconf->status |= CONF_ILLEGAL; + if(!aconf->clients) + free_conf(aconf); + rb_free(arec); + return; + } + arecl = arec; + } } /* void clear_out_address_conf(void) @@ -598,67 +543,57 @@ delete_one_address_conf(const char *address, struct ConfItem *aconf) void clear_out_address_conf(void) { - int i; - struct AddressRec **store_next; - struct AddressRec *arec, *arecn; + int i; + struct AddressRec **store_next; + struct AddressRec *arec, *arecn; - for (i = 0; i < ATABLE_SIZE; i++) - { - store_next = &atable[i]; - for (arec = atable[i]; arec; arec = arecn) - { - arecn = arec->next; - /* We keep the temporary K-lines and destroy the - * permanent ones, just to be confusing :) -A1kmm */ - if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || - (arec->type != CONF_CLIENT && arec->type != CONF_EXEMPTDLINE)) - { - *store_next = arec; - store_next = &arec->next; - } - else - { - arec->aconf->status |= CONF_ILLEGAL; - if(!arec->aconf->clients) - free_conf(arec->aconf); - rb_free(arec); - } - } - *store_next = NULL; - } + for (i = 0; i < ATABLE_SIZE; i++) { + store_next = &atable[i]; + for (arec = atable[i]; arec; arec = arecn) { + arecn = arec->next; + /* We keep the temporary K-lines and destroy the + * permanent ones, just to be confusing :) -A1kmm */ + if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || + (arec->type != CONF_CLIENT && arec->type != CONF_EXEMPTDLINE)) { + *store_next = arec; + store_next = &arec->next; + } else { + arec->aconf->status |= CONF_ILLEGAL; + if(!arec->aconf->clients) + free_conf(arec->aconf); + rb_free(arec); + } + } + *store_next = NULL; + } } void clear_out_address_conf_bans(void) { - int i; - struct AddressRec **store_next; - struct AddressRec *arec, *arecn; + int i; + struct AddressRec **store_next; + struct AddressRec *arec, *arecn; - for (i = 0; i < ATABLE_SIZE; i++) - { - store_next = &atable[i]; - for (arec = atable[i]; arec; arec = arecn) - { - arecn = arec->next; - /* We keep the temporary K-lines and destroy the - * permanent ones, just to be confusing :) -A1kmm */ - if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || - (arec->type == CONF_CLIENT || arec->type == CONF_EXEMPTDLINE)) - { - *store_next = arec; - store_next = &arec->next; - } - else - { - arec->aconf->status |= CONF_ILLEGAL; - if(!arec->aconf->clients) - free_conf(arec->aconf); - rb_free(arec); - } - } - *store_next = NULL; - } + for (i = 0; i < ATABLE_SIZE; i++) { + store_next = &atable[i]; + for (arec = atable[i]; arec; arec = arecn) { + arecn = arec->next; + /* We keep the temporary K-lines and destroy the + * permanent ones, just to be confusing :) -A1kmm */ + if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || + (arec->type == CONF_CLIENT || arec->type == CONF_EXEMPTDLINE)) { + *store_next = arec; + store_next = &arec->next; + } else { + arec->aconf->status |= CONF_ILLEGAL; + if(!arec->aconf->clients) + free_conf(arec->aconf); + rb_free(arec); + } + } + *store_next = NULL; + } } @@ -666,7 +601,7 @@ clear_out_address_conf_bans(void) * show_iline_prefix() * * inputs - pointer to struct Client requesting output - * - pointer to struct ConfItem + * - pointer to struct ConfItem * - name to which iline prefix will be prefixed to * output - pointer to static string with prefixes listed in ascii form * side effects - NONE @@ -674,27 +609,27 @@ clear_out_address_conf_bans(void) char * show_iline_prefix(struct Client *sptr, struct ConfItem *aconf, char *name) { - static char prefix_of_host[USERLEN + 15]; - char *prefix_ptr; + static char prefix_of_host[USERLEN + 15]; + char *prefix_ptr; - prefix_ptr = prefix_of_host; - if(IsNoTilde(aconf)) - *prefix_ptr++ = '-'; - if(IsNeedIdentd(aconf)) - *prefix_ptr++ = '+'; - if(IsConfDoSpoofIp(aconf)) - *prefix_ptr++ = '='; - if(IsOper(sptr) && IsConfExemptFlood(aconf)) - *prefix_ptr++ = '|'; - if(IsOper(sptr) && IsConfExemptDNSBL(aconf) && !IsConfExemptKline(aconf)) - *prefix_ptr++ = '$'; - if(IsOper(sptr) && IsConfExemptKline(aconf)) - *prefix_ptr++ = '^'; - if(IsOper(sptr) && IsConfExemptLimits(aconf)) - *prefix_ptr++ = '>'; - *prefix_ptr = '\0'; - strncpy(prefix_ptr, name, USERLEN); - return (prefix_of_host); + prefix_ptr = prefix_of_host; + if(IsNoTilde(aconf)) + *prefix_ptr++ = '-'; + if(IsNeedIdentd(aconf)) + *prefix_ptr++ = '+'; + if(IsConfDoSpoofIp(aconf)) + *prefix_ptr++ = '='; + if(IsOper(sptr) && IsConfExemptFlood(aconf)) + *prefix_ptr++ = '|'; + if(IsOper(sptr) && IsConfExemptDNSBL(aconf) && !IsConfExemptKline(aconf)) + *prefix_ptr++ = '$'; + if(IsOper(sptr) && IsConfExemptKline(aconf)) + *prefix_ptr++ = '^'; + if(IsOper(sptr) && IsConfExemptLimits(aconf)) + *prefix_ptr++ = '>'; + *prefix_ptr = '\0'; + strncpy(prefix_ptr, name, USERLEN); + return (prefix_of_host); } /* report_auth() @@ -706,67 +641,63 @@ show_iline_prefix(struct Client *sptr, struct ConfItem *aconf, char *name) void report_auth(struct Client *client_p) { - char *name, *host, *pass, *user, *classname; - struct AddressRec *arec; - struct ConfItem *aconf; - int i, port; + char *name, *host, *pass, *user, *classname; + struct AddressRec *arec; + struct ConfItem *aconf; + int i, port; - for (i = 0; i < ATABLE_SIZE; i++) - for (arec = atable[i]; arec; arec = arec->next) - if(arec->type == CONF_CLIENT) - { - aconf = arec->aconf; + for (i = 0; i < ATABLE_SIZE; i++) + for (arec = atable[i]; arec; arec = arec->next) + if(arec->type == CONF_CLIENT) { + aconf = arec->aconf; - if(!IsOper(client_p) && IsConfDoSpoofIp(aconf)) - continue; + if(!IsOper(client_p) && IsConfDoSpoofIp(aconf)) + continue; - get_printable_conf(aconf, &name, &host, &pass, &user, &port, - &classname); - - if(!EmptyString(aconf->spasswd)) - pass = aconf->spasswd; + get_printable_conf(aconf, &name, &host, &pass, &user, &port, + &classname); - sendto_one_numeric(client_p, RPL_STATSILINE, - form_str(RPL_STATSILINE), - name, pass, show_iline_prefix(client_p, aconf, user), - show_ip_conf(aconf, client_p) ? host : "255.255.255.255", - port, classname); - } + if(!EmptyString(aconf->spasswd)) + pass = aconf->spasswd; + + sendto_one_numeric(client_p, RPL_STATSILINE, + form_str(RPL_STATSILINE), + name, pass, show_iline_prefix(client_p, aconf, user), + show_ip_conf(aconf, client_p) ? host : "255.255.255.255", + port, classname); + } } /* report_Klines() - * - * inputs - Client to report to, mask + * + * inputs - Client to report to, mask * outputs - * side effects - Reports configured K-lines to client_p. */ void report_Klines(struct Client *source_p) { - char *host, *pass, *user, *oper_reason; - struct AddressRec *arec; - struct ConfItem *aconf = NULL; - int i; + char *host, *pass, *user, *oper_reason; + struct AddressRec *arec; + struct ConfItem *aconf = NULL; + int i; - for (i = 0; i < ATABLE_SIZE; i++) - { - for (arec = atable[i]; arec; arec = arec->next) - { - if(arec->type == CONF_KILL) - { - aconf = arec->aconf; + for (i = 0; i < ATABLE_SIZE; i++) { + for (arec = atable[i]; arec; arec = arec->next) { + if(arec->type == CONF_KILL) { + aconf = arec->aconf; - /* its a tempkline, theyre reported elsewhere */ - if(aconf->flags & CONF_FLAGS_TEMPORARY) - continue; + /* its a tempkline, theyre reported elsewhere */ + if(aconf->flags & CONF_FLAGS_TEMPORARY) + continue; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSKLINE, - form_str(RPL_STATSKLINE), - 'K', host, user, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - } - } + get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); + sendto_one_numeric(source_p, RPL_STATSKLINE, + form_str(RPL_STATSKLINE), + 'K', host, user, pass, + oper_reason ? "|" : "", + oper_reason ? oper_reason : ""); + } + } + } } diff --git a/src/irc_dictionary.c b/src/irc_dictionary.c index 89a0a7b..f131a5f 100644 --- a/src/irc_dictionary.c +++ b/src/irc_dictionary.c @@ -30,13 +30,12 @@ static rb_bh *elem_heap = NULL; -struct Dictionary -{ - DCF compare_cb; - struct DictionaryElement *root, *head, *tail; - unsigned int count; - char *id; - unsigned int dirty:1; +struct Dictionary { + DCF compare_cb; + struct DictionaryElement *root, *head, *tail; + unsigned int count; + char *id; + unsigned int dirty:1; }; /* @@ -56,18 +55,18 @@ struct Dictionary */ struct Dictionary *irc_dictionary_create(DCF compare_cb) { - struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); + struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); - dtree->compare_cb = compare_cb; + dtree->compare_cb = compare_cb; - if (!elem_heap) - elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); + if (!elem_heap) + elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); - return dtree; + return dtree; } /* - * irc_dictionary_create_named(const char *name, + * irc_dictionary_create_named(const char *name, * DCF compare_cb) * * Dictionary object factory. @@ -84,17 +83,17 @@ struct Dictionary *irc_dictionary_create(DCF compare_cb) * the program will abort. */ struct Dictionary *irc_dictionary_create_named(const char *name, - DCF compare_cb) + DCF compare_cb) { - struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); + struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); - dtree->compare_cb = compare_cb; - dtree->id = rb_strdup(name); + dtree->compare_cb = compare_cb; + dtree->id = rb_strdup(name); - if (!elem_heap) - elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); + if (!elem_heap) + elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); - return dtree; + return dtree; } /* @@ -115,12 +114,12 @@ struct Dictionary *irc_dictionary_create_named(const char *name, * - the dictionary comparator function is reset. */ void irc_dictionary_set_comparator_func(struct Dictionary *dict, - DCF compare_cb) + DCF compare_cb) { - s_assert(dict != NULL); - s_assert(compare_cb != NULL); + s_assert(dict != NULL); + s_assert(compare_cb != NULL); - dict->compare_cb = compare_cb; + dict->compare_cb = compare_cb; } /* @@ -140,9 +139,9 @@ void irc_dictionary_set_comparator_func(struct Dictionary *dict, DCF irc_dictionary_get_comparator_func(struct Dictionary *dict) { - s_assert(dict != NULL); + s_assert(dict != NULL); - return dict->compare_cb; + return dict->compare_cb; } /* @@ -164,29 +163,28 @@ irc_dictionary_get_comparator_func(struct Dictionary *dict) int irc_dictionary_get_linear_index(struct Dictionary *dict, const char *key) { - struct DictionaryElement *elem; + struct DictionaryElement *elem; - s_assert(dict != NULL); - s_assert(key != NULL); + s_assert(dict != NULL); + s_assert(key != NULL); - elem = irc_dictionary_find(dict, key); - if (elem == NULL) - return -1; + elem = irc_dictionary_find(dict, key); + if (elem == NULL) + return -1; - if (!dict->dirty) - return elem->position; - else - { - struct DictionaryElement *delem; - int i; + if (!dict->dirty) + return elem->position; + else { + struct DictionaryElement *delem; + int i; - for (delem = dict->head, i = 0; delem != NULL; delem = delem->next, i++) - delem->position = i; + for (delem = dict->head, i = 0; delem != NULL; delem = delem->next, i++) + delem->position = i; - dict->dirty = FALSE; - } + dict->dirty = FALSE; + } - return elem->position; + return elem->position; } /* @@ -206,79 +204,73 @@ irc_dictionary_get_linear_index(struct Dictionary *dict, const char *key) static void irc_dictionary_retune(struct Dictionary *dict, const char *key) { - struct DictionaryElement n, *tn, *left, *right, *node; - int ret; + struct DictionaryElement n, *tn, *left, *right, *node; + int ret; - s_assert(dict != NULL); + s_assert(dict != NULL); - if (dict->root == NULL) - return; + if (dict->root == NULL) + return; - /* - * we initialize n with known values, since it's on stack - * memory. otherwise the dict would become corrupted. - * - * n is used for temporary storage while the tree is retuned. - * -nenolod - */ - n.left = n.right = NULL; - left = right = &n; + /* + * we initialize n with known values, since it's on stack + * memory. otherwise the dict would become corrupted. + * + * n is used for temporary storage while the tree is retuned. + * -nenolod + */ + n.left = n.right = NULL; + left = right = &n; - /* this for(;;) loop is the main workhorse of the rebalancing */ - for (node = dict->root; ; ) - { - if ((ret = dict->compare_cb(key, node->key)) == 0) - break; + /* this for(;;) loop is the main workhorse of the rebalancing */ + for (node = dict->root; ; ) { + if ((ret = dict->compare_cb(key, node->key)) == 0) + break; - if (ret < 0) - { - if (node->left == NULL) - break; + if (ret < 0) { + if (node->left == NULL) + break; - if ((ret = dict->compare_cb(key, node->left->key)) < 0) - { - tn = node->left; - node->left = tn->right; - tn->right = node; - node = tn; + if ((ret = dict->compare_cb(key, node->left->key)) < 0) { + tn = node->left; + node->left = tn->right; + tn->right = node; + node = tn; - if (node->left == NULL) - break; - } + if (node->left == NULL) + break; + } - right->left = node; - right = node; - node = node->left; - } - else - { - if (node->right == NULL) - break; + right->left = node; + right = node; + node = node->left; + } else { + if (node->right == NULL) + break; - if ((ret = dict->compare_cb(key, node->right->key)) > 0) - { - tn = node->right; - node->right = tn->left; - tn->left = node; - node = tn; + if ((ret = dict->compare_cb(key, node->right->key)) > 0) { + tn = node->right; + node->right = tn->left; + tn->left = node; + node = tn; - if (node->right == NULL) - break; - } + if (node->right == NULL) + break; + } - left->right = node; - left = node; - node = node->right; - } - } + left->right = node; + left = node; + node = node->right; + } + } - left->right = node->left; - right->left = node->right; + left->right = node->left; + right->left = node->right; - node->left = n.right; - node->right = n.left; + node->left = n.right; + node->right = n.left; - dict->root = node; + dict->root = node; } /* @@ -304,68 +296,60 @@ irc_dictionary_retune(struct Dictionary *dict, const char *key) */ static void irc_dictionary_link(struct Dictionary *dict, - struct DictionaryElement *delem) + struct DictionaryElement *delem) { - s_assert(dict != NULL); - s_assert(delem != NULL); + s_assert(dict != NULL); + s_assert(delem != NULL); - dict->dirty = TRUE; + dict->dirty = TRUE; - dict->count++; + dict->count++; - if (dict->root == NULL) - { - delem->left = delem->right = NULL; - delem->next = delem->prev = NULL; - dict->head = dict->tail = dict->root = delem; - } - else - { - int ret; + if (dict->root == NULL) { + delem->left = delem->right = NULL; + delem->next = delem->prev = NULL; + dict->head = dict->tail = dict->root = delem; + } else { + int ret; - irc_dictionary_retune(dict, delem->key); + irc_dictionary_retune(dict, delem->key); - if ((ret = dict->compare_cb(delem->key, dict->root->key)) < 0) - { - delem->left = dict->root->left; - delem->right = dict->root; - dict->root->left = NULL; + if ((ret = dict->compare_cb(delem->key, dict->root->key)) < 0) { + delem->left = dict->root->left; + delem->right = dict->root; + dict->root->left = NULL; - if (dict->root->prev) - dict->root->prev->next = delem; - else - dict->head = delem; + if (dict->root->prev) + dict->root->prev->next = delem; + else + dict->head = delem; - delem->prev = dict->root->prev; - delem->next = dict->root; - dict->root->prev = delem; - dict->root = delem; - } - else if (ret > 0) - { - delem->right = dict->root->right; - delem->left = dict->root; - dict->root->right = NULL; + delem->prev = dict->root->prev; + delem->next = dict->root; + dict->root->prev = delem; + dict->root = delem; + } else if (ret > 0) { + delem->right = dict->root->right; + delem->left = dict->root; + dict->root->right = NULL; - if (dict->root->next) - dict->root->next->prev = delem; - else - dict->tail = delem; + if (dict->root->next) + dict->root->next->prev = delem; + else + dict->tail = delem; - delem->next = dict->root->next; - delem->prev = dict->root; - dict->root->next = delem; - dict->root = delem; - } - else - { - dict->root->key = delem->key; - dict->root->data = delem->data; - dict->count--; + delem->next = dict->root->next; + delem->prev = dict->root; + dict->root->next = delem; + dict->root = delem; + } else { + dict->root->key = delem->key; + dict->root->data = delem->data; + dict->count--; - rb_bh_free(elem_heap, delem); - } - } + rb_bh_free(elem_heap, delem); + } + } } /* @@ -385,56 +369,52 @@ irc_dictionary_link(struct Dictionary *dict, static void irc_dictionary_unlink_root(struct Dictionary *dict) { - struct DictionaryElement *delem, *nextnode, *parentofnext; + struct DictionaryElement *delem, *nextnode, *parentofnext; - dict->dirty = TRUE; + dict->dirty = TRUE; - delem = dict->root; - if (delem == NULL) - return; + delem = dict->root; + if (delem == NULL) + return; - if (dict->root->left == NULL) - dict->root = dict->root->right; - else if (dict->root->right == NULL) - dict->root = dict->root->left; - else - { - /* Make the node with the next highest key the new root. - * This node has a NULL left pointer. */ - nextnode = delem->next; - s_assert(nextnode->left == NULL); - if (nextnode == delem->right) - { - dict->root = nextnode; - dict->root->left = delem->left; - } - else - { - parentofnext = delem->right; - while (parentofnext->left != NULL && parentofnext->left != nextnode) - parentofnext = parentofnext->left; - s_assert(parentofnext->left == nextnode); - parentofnext->left = nextnode->right; - dict->root = nextnode; - dict->root->left = delem->left; - dict->root->right = delem->right; - } - } + if (dict->root->left == NULL) + dict->root = dict->root->right; + else if (dict->root->right == NULL) + dict->root = dict->root->left; + else { + /* Make the node with the next highest key the new root. + * This node has a NULL left pointer. */ + nextnode = delem->next; + s_assert(nextnode->left == NULL); + if (nextnode == delem->right) { + dict->root = nextnode; + dict->root->left = delem->left; + } else { + parentofnext = delem->right; + while (parentofnext->left != NULL && parentofnext->left != nextnode) + parentofnext = parentofnext->left; + s_assert(parentofnext->left == nextnode); + parentofnext->left = nextnode->right; + dict->root = nextnode; + dict->root->left = delem->left; + dict->root->right = delem->right; + } + } - /* linked list */ - if (delem->prev != NULL) - delem->prev->next = delem->next; + /* linked list */ + if (delem->prev != NULL) + delem->prev->next = delem->next; - if (dict->head == delem) - dict->head = delem->next; + if (dict->head == delem) + dict->head = delem->next; - if (delem->next) - delem->next->prev = delem->prev; + if (delem->next) + delem->next->prev = delem->prev; - if (dict->tail == delem) - dict->tail = delem->prev; + if (dict->tail == delem) + dict->tail = delem->prev; - dict->count--; + dict->count--; } /* @@ -460,22 +440,21 @@ irc_dictionary_unlink_root(struct Dictionary *dict) * DTree will not be destroyed. */ void irc_dictionary_destroy(struct Dictionary *dtree, - void (*destroy_cb)(struct DictionaryElement *delem, void *privdata), - void *privdata) + void (*destroy_cb)(struct DictionaryElement *delem, void *privdata), + void *privdata) { - struct DictionaryElement *n, *tn; + struct DictionaryElement *n, *tn; - s_assert(dtree != NULL); + s_assert(dtree != NULL); - RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) - { - if (destroy_cb != NULL) - (*destroy_cb)(n, privdata); + RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) { + if (destroy_cb != NULL) + (*destroy_cb)(n, privdata); - rb_bh_free(elem_heap, n); - } + rb_bh_free(elem_heap, n); + } - rb_free(dtree); + rb_free(dtree); } /* @@ -497,21 +476,20 @@ void irc_dictionary_destroy(struct Dictionary *dtree, * - on success, a dtree is iterated */ void irc_dictionary_foreach(struct Dictionary *dtree, - int (*foreach_cb)(struct DictionaryElement *delem, void *privdata), - void *privdata) + int (*foreach_cb)(struct DictionaryElement *delem, void *privdata), + void *privdata) { - struct DictionaryElement *n, *tn; + struct DictionaryElement *n, *tn; - s_assert(dtree != NULL); + s_assert(dtree != NULL); - RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) - { - /* delem_t is a subclass of node_t. */ - struct DictionaryElement *delem = (struct DictionaryElement *) n; + RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) { + /* delem_t is a subclass of node_t. */ + struct DictionaryElement *delem = (struct DictionaryElement *) n; - if (foreach_cb != NULL) - (*foreach_cb)(delem, privdata); - } + if (foreach_cb != NULL) + (*foreach_cb)(delem, privdata); + } } /* @@ -534,27 +512,26 @@ void irc_dictionary_foreach(struct Dictionary *dtree, * - a dtree is iterated until the requested conditions are met */ void *irc_dictionary_search(struct Dictionary *dtree, - void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata), - void *privdata) + void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata), + void *privdata) { - struct DictionaryElement *n, *tn; - void *ret = NULL; + struct DictionaryElement *n, *tn; + void *ret = NULL; - s_assert(dtree != NULL); + s_assert(dtree != NULL); - RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) - { - /* delem_t is a subclass of node_t. */ - struct DictionaryElement *delem = (struct DictionaryElement *) n; + RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) { + /* delem_t is a subclass of node_t. */ + struct DictionaryElement *delem = (struct DictionaryElement *) n; - if (foreach_cb != NULL) - ret = (*foreach_cb)(delem, privdata); + if (foreach_cb != NULL) + ret = (*foreach_cb)(delem, privdata); - if (ret) - break; - } + if (ret) + break; + } - return ret; + return ret; } /* @@ -574,24 +551,24 @@ void *irc_dictionary_search(struct Dictionary *dtree, * - the static iterator, &state, is initialized. */ void irc_dictionary_foreach_start(struct Dictionary *dtree, - struct DictionaryIter *state) + struct DictionaryIter *state) { - s_assert(dtree != NULL); - s_assert(state != NULL); + s_assert(dtree != NULL); + s_assert(state != NULL); - state->cur = NULL; - state->next = NULL; + state->cur = NULL; + state->next = NULL; - /* find first item */ - state->cur = dtree->head; + /* find first item */ + state->cur = dtree->head; - if (state->cur == NULL) - return; + if (state->cur == NULL) + return; - /* make state->cur point to first item and state->next point to - * second item */ - state->next = state->cur; - irc_dictionary_foreach_next(dtree, state); + /* make state->cur point to first item and state->next point to + * second item */ + state->next = state->cur; + irc_dictionary_foreach_next(dtree, state); } /* @@ -612,12 +589,12 @@ void irc_dictionary_foreach_start(struct Dictionary *dtree, * - none */ void *irc_dictionary_foreach_cur(struct Dictionary *dtree, - struct DictionaryIter *state) + struct DictionaryIter *state) { - s_assert(dtree != NULL); - s_assert(state != NULL); + s_assert(dtree != NULL); + s_assert(state != NULL); - return state->cur != NULL ? state->cur->data : NULL; + return state->cur != NULL ? state->cur->data : NULL; } /* @@ -637,23 +614,22 @@ void *irc_dictionary_foreach_cur(struct Dictionary *dtree, * - the static iterator, &state, is advanced to a new DTree node. */ void irc_dictionary_foreach_next(struct Dictionary *dtree, - struct DictionaryIter *state) + struct DictionaryIter *state) { - s_assert(dtree != NULL); - s_assert(state != NULL); + s_assert(dtree != NULL); + s_assert(state != NULL); - if (state->cur == NULL) - { - ilog(L_MAIN, "irc_dictionary_foreach_next(): called again after iteration finished on dtree<%p>", (void *)dtree); - return; - } + if (state->cur == NULL) { + ilog(L_MAIN, "irc_dictionary_foreach_next(): called again after iteration finished on dtree<%p>", (void *)dtree); + return; + } - state->cur = state->next; + state->cur = state->next; - if (state->next == NULL) - return; + if (state->next == NULL) + return; - state->next = state->next->next; + state->next = state->next->next; } /* @@ -674,16 +650,16 @@ void irc_dictionary_foreach_next(struct Dictionary *dtree, */ struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const char *key) { - s_assert(dict != NULL); - s_assert(key != NULL); + s_assert(dict != NULL); + s_assert(key != NULL); - /* retune for key, key will be the tree's root if it's available */ - irc_dictionary_retune(dict, key); + /* retune for key, key will be the tree's root if it's available */ + irc_dictionary_retune(dict, key); - if (dict->root && !dict->compare_cb(key, dict->root->key)) - return dict->root; + if (dict->root && !dict->compare_cb(key, dict->root->key)) + return dict->root; - return NULL; + return NULL; } /* @@ -705,27 +681,26 @@ struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const cha */ struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const char *key, void *data) { - struct DictionaryElement *delem; + struct DictionaryElement *delem; - s_assert(dict != NULL); - s_assert(key != NULL); - s_assert(data != NULL); - s_assert(irc_dictionary_find(dict, key) == NULL); + s_assert(dict != NULL); + s_assert(key != NULL); + s_assert(data != NULL); + s_assert(irc_dictionary_find(dict, key) == NULL); - delem = rb_bh_alloc(elem_heap); - delem->key = key; - delem->data = data; + delem = rb_bh_alloc(elem_heap); + delem->key = key; + delem->data = data; - /* TBD: is this needed? --nenolod */ - if (delem->key == NULL) - { - rb_bh_free(elem_heap, delem); - return NULL; - } + /* TBD: is this needed? --nenolod */ + if (delem->key == NULL) { + rb_bh_free(elem_heap, delem); + return NULL; + } - irc_dictionary_link(dict, delem); + irc_dictionary_link(dict, delem); - return delem; + return delem; } /* @@ -749,18 +724,18 @@ struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const char */ void *irc_dictionary_delete(struct Dictionary *dtree, const char *key) { - struct DictionaryElement *delem = irc_dictionary_find(dtree, key); - void *data; + struct DictionaryElement *delem = irc_dictionary_find(dtree, key); + void *data; - if (delem == NULL) - return NULL; + if (delem == NULL) + return NULL; - data = delem->data; + data = delem->data; - irc_dictionary_unlink_root(dtree); - rb_bh_free(elem_heap, delem); + irc_dictionary_unlink_root(dtree); + rb_bh_free(elem_heap, delem); - return data; + return data; } /* @@ -781,12 +756,12 @@ void *irc_dictionary_delete(struct Dictionary *dtree, const char *key) */ void *irc_dictionary_retrieve(struct Dictionary *dtree, const char *key) { - struct DictionaryElement *delem = irc_dictionary_find(dtree, key); + struct DictionaryElement *delem = irc_dictionary_find(dtree, key); - if (delem != NULL) - return delem->data; + if (delem != NULL) + return delem->data; - return NULL; + return NULL; } /* @@ -805,25 +780,25 @@ void *irc_dictionary_retrieve(struct Dictionary *dtree, const char *key) */ unsigned int irc_dictionary_size(struct Dictionary *dict) { - s_assert(dict != NULL); + s_assert(dict != NULL); - return dict->count; + return dict->count; } /* returns the sum of the depths of the subtree rooted in delem at depth depth */ static int stats_recurse(struct DictionaryElement *delem, int depth, int *pmaxdepth) { - int result; + int result; - if (depth > *pmaxdepth) - *pmaxdepth = depth; - result = depth; - if (delem->left) - result += stats_recurse(delem->left, depth + 1, pmaxdepth); - if (delem->right) - result += stats_recurse(delem->right, depth + 1, pmaxdepth); - return result; + if (depth > *pmaxdepth) + *pmaxdepth = depth; + result = depth; + if (delem->left) + result += stats_recurse(delem->left, depth + 1, pmaxdepth); + if (delem->right) + result += stats_recurse(delem->right, depth + 1, pmaxdepth); + return result; } /* @@ -844,21 +819,21 @@ stats_recurse(struct DictionaryElement *delem, int depth, int *pmaxdepth) */ void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata) { - char str[256]; - int sum, maxdepth; + char str[256]; + int sum, maxdepth; - s_assert(dict != NULL); + s_assert(dict != NULL); - if (dict->id != NULL) - rb_snprintf(str, sizeof str, "Dictionary stats for %s (%d)", - dict->id, dict->count); - else - rb_snprintf(str, sizeof str, "Dictionary stats for <%p> (%d)", - (void *)dict, dict->count); - cb(str, privdata); - maxdepth = 0; - sum = stats_recurse(dict->root, 0, &maxdepth); - rb_snprintf(str, sizeof str, "Depth sum %d Avg depth %d Max depth %d", sum, sum / dict->count, maxdepth); - cb(str, privdata); - return; + if (dict->id != NULL) + rb_snprintf(str, sizeof str, "Dictionary stats for %s (%d)", + dict->id, dict->count); + else + rb_snprintf(str, sizeof str, "Dictionary stats for <%p> (%d)", + (void *)dict, dict->count); + cb(str, privdata); + maxdepth = 0; + sum = stats_recurse(dict->root, 0, &maxdepth); + rb_snprintf(str, sizeof str, "Depth sum %d Avg depth %d Max depth %d", sum, sum / dict->count, maxdepth); + cb(str, privdata); + return; } diff --git a/src/ircd.c b/src/ircd.c index 8716b3e..0b0695a 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -123,30 +123,28 @@ int eob_count; void ircd_shutdown(const char *reason) { - struct Client *target_p; - rb_dlink_node *ptr; + struct Client *target_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, lclient_list.head) { + target_p = ptr->data; - sendto_one(target_p, ":%s NOTICE %s :Server Terminating. %s", - me.name, target_p->name, reason); - } + sendto_one(target_p, ":%s NOTICE %s :Server Terminating. %s", + me.name, target_p->name, reason); + } - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - sendto_one(target_p, ":%s ERROR :Terminated by %s", - me.name, reason); - } + sendto_one(target_p, ":%s ERROR :Terminated by %s", + me.name, reason); + } - ilog(L_MAIN, "Server Terminating. %s", reason); - close_logfiles(); + ilog(L_MAIN, "Server Terminating. %s", reason); + close_logfiles(); - unlink(pidFileName); - exit(0); + unlink(pidFileName); + exit(0); } /* @@ -155,20 +153,20 @@ ircd_shutdown(const char *reason) static void print_startup(int pid) { - inotice("now running in %s mode from %s as pid %d ...", - !server_state_foreground ? "background" : "foreground", - ConfigFileEntry.dpath, pid); + inotice("now running in %s mode from %s as pid %d ...", + !server_state_foreground ? "background" : "foreground", + ConfigFileEntry.dpath, pid); - /* let the parent process know the initialization was successful - * -- jilles */ - if (!server_state_foreground) - write(0, ".", 1); - fclose(stdin); - fclose(stdout); - fclose(stderr); - open("/dev/null", O_RDWR); - dup2(0, 1); - dup2(0, 2); + /* let the parent process know the initialization was successful + * -- jilles */ + if (!server_state_foreground) + write(0, ".", 1); + fclose(stdin); + fclose(stdout); + fclose(stderr); + open("/dev/null", O_RDWR); + dup2(0, 1); + dup2(0, 2); } /* @@ -182,108 +180,111 @@ static void init_sys(void) { #if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) - struct rlimit limit; + struct rlimit limit; - if(!getrlimit(RLIMIT_NOFILE, &limit)) - { - maxconnections = limit.rlim_cur; - if(maxconnections <= MAX_BUFFER) - { - fprintf(stderr, "ERROR: Shell FD limits are too low.\n"); - fprintf(stderr, "ERROR: charybdis reserves %d FDs, shell limits must be above this\n", MAX_BUFFER); - exit(EXIT_FAILURE); - } - return; - } + if(!getrlimit(RLIMIT_NOFILE, &limit)) { + maxconnections = limit.rlim_cur; + if(maxconnections <= MAX_BUFFER) { + fprintf(stderr, "ERROR: Shell FD limits are too low.\n"); + fprintf(stderr, "ERROR: charybdis reserves %d FDs, shell limits must be above this\n", MAX_BUFFER); + exit(EXIT_FAILURE); + } + return; + } #endif /* RLIMIT_FD_MAX */ - maxconnections = MAXCONNECTIONS; + maxconnections = MAXCONNECTIONS; } static int make_daemon(void) { - int pid; - int pip[2]; - char c; + int pid; + int pip[2]; + char c; - if (pipe(pip) < 0) - { - perror("pipe"); - exit(EXIT_FAILURE); - } - dup2(pip[1], 0); - close(pip[1]); - if((pid = fork()) < 0) - { - perror("fork"); - exit(EXIT_FAILURE); - } - else if(pid > 0) - { - close(0); - /* Wait for initialization to finish, successfully or - * unsuccessfully. Until this point the child may still - * write to stdout/stderr. - * -- jilles */ - if (read(pip[0], &c, 1) > 0) - exit(EXIT_SUCCESS); - else - exit(EXIT_FAILURE); - } + if (pipe(pip) < 0) { + perror("pipe"); + exit(EXIT_FAILURE); + } + dup2(pip[1], 0); + close(pip[1]); + if((pid = fork()) < 0) { + perror("fork"); + exit(EXIT_FAILURE); + } else if(pid > 0) { + close(0); + /* Wait for initialization to finish, successfully or + * unsuccessfully. Until this point the child may still + * write to stdout/stderr. + * -- jilles */ + if (read(pip[0], &c, 1) > 0) + exit(EXIT_SUCCESS); + else + exit(EXIT_FAILURE); + } - close(pip[0]); - setsid(); -/* fclose(stdin); - fclose(stdout); - fclose(stderr); */ + close(pip[0]); + setsid(); + /* fclose(stdin); + fclose(stdout); + fclose(stderr); */ - return 0; + return 0; } static int printVersion = 0; struct lgetopt myopts[] = { - {"configfile", &ConfigFileEntry.configfile, - STRING, "File to use for ircd.conf"}, - {"logfile", &logFileName, - STRING, "File to use for ircd.log"}, - {"pidfile", &pidFileName, - STRING, "File to use for process ID"}, - {"foreground", &server_state_foreground, - YESNO, "Run in foreground (don't detach)"}, - {"version", &printVersion, - YESNO, "Print version and exit"}, - {"conftest", &testing_conf, - YESNO, "Test the configuration files and exit"}, - {"help", NULL, USAGE, "Print this text"}, - {NULL, NULL, STRING, NULL}, + { + "configfile", &ConfigFileEntry.configfile, + STRING, "File to use for ircd.conf" + }, + { + "logfile", &logFileName, + STRING, "File to use for ircd.log" + }, + { + "pidfile", &pidFileName, + STRING, "File to use for process ID" + }, + { + "foreground", &server_state_foreground, + YESNO, "Run in foreground (don't detach)" + }, + { + "version", &printVersion, + YESNO, "Print version and exit" + }, + { + "conftest", &testing_conf, + YESNO, "Test the configuration files and exit" + }, + {"help", NULL, USAGE, "Print this text"}, + {NULL, NULL, STRING, NULL}, }; static void check_rehash(void *unused) { - /* - * Check to see whether we have to rehash the configuration .. - */ - if(dorehash) - { - rehash(1); - dorehash = 0; - } + /* + * Check to see whether we have to rehash the configuration .. + */ + if(dorehash) { + rehash(1); + dorehash = 0; + } - if(dorehashbans) - { - rehash_bans(1); - dorehashbans = 0; - } + if(dorehashbans) { + rehash_bans(1); + dorehashbans = 0; + } - if(doremotd) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Got signal SIGUSR1, reloading ircd motd file"); - cache_user_motd(); - doremotd = 0; - } + if(doremotd) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Got signal SIGUSR1, reloading ircd motd file"); + cache_user_motd(); + doremotd = 0; + } } /* @@ -291,61 +292,60 @@ check_rehash(void *unused) * * inputs - none * output - none - * side effects - This sets all global set options needed + * side effects - This sets all global set options needed */ static void initialize_global_set_options(void) { - memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); - /* memset( &ConfigFileEntry, 0, sizeof(ConfigFileEntry)); */ + memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); + /* memset( &ConfigFileEntry, 0, sizeof(ConfigFileEntry)); */ - GlobalSetOptions.maxclients = ServerInfo.default_max_clients; + GlobalSetOptions.maxclients = ServerInfo.default_max_clients; - if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER) || (GlobalSetOptions.maxclients <= 0)) - GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER; + if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER) || (GlobalSetOptions.maxclients <= 0)) + GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER; - GlobalSetOptions.autoconn = 1; + GlobalSetOptions.autoconn = 1; - GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; - GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; + GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; + GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; - if(ConfigFileEntry.default_floodcount) - GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; - else - GlobalSetOptions.floodcount = 10; + if(ConfigFileEntry.default_floodcount) + GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount; + else + GlobalSetOptions.floodcount = 10; - split_servers = ConfigChannel.default_split_server_count; - split_users = ConfigChannel.default_split_user_count; + split_servers = ConfigChannel.default_split_server_count; + split_users = ConfigChannel.default_split_user_count; - if(split_users && split_servers - && (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split)) - { - splitmode = 1; - splitchecking = 1; - } + if(split_users && split_servers + && (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split)) { + splitmode = 1; + splitchecking = 1; + } - if(ConfigFileEntry.default_ident_timeout) - GlobalSetOptions.ident_timeout = ConfigFileEntry.default_ident_timeout; - else - GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; + if(ConfigFileEntry.default_ident_timeout) + GlobalSetOptions.ident_timeout = ConfigFileEntry.default_ident_timeout; + else + GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; - if(ConfigFileEntry.default_operhost) - rb_strlcpy(GlobalSetOptions.operhost, - ConfigFileEntry.default_operhost, - sizeof(GlobalSetOptions.operhost)); - else - rb_strlcpy(GlobalSetOptions.operhost, "", sizeof(GlobalSetOptions.operhost)); + if(ConfigFileEntry.default_operhost) + rb_strlcpy(GlobalSetOptions.operhost, + ConfigFileEntry.default_operhost, + sizeof(GlobalSetOptions.operhost)); + else + rb_strlcpy(GlobalSetOptions.operhost, "", sizeof(GlobalSetOptions.operhost)); - rb_strlcpy(GlobalSetOptions.operstring, - ConfigFileEntry.default_operstring, - sizeof(GlobalSetOptions.operstring)); - rb_strlcpy(GlobalSetOptions.adminstring, - ConfigFileEntry.default_adminstring, - sizeof(GlobalSetOptions.adminstring)); + rb_strlcpy(GlobalSetOptions.operstring, + ConfigFileEntry.default_operstring, + sizeof(GlobalSetOptions.operstring)); + rb_strlcpy(GlobalSetOptions.adminstring, + ConfigFileEntry.default_adminstring, + sizeof(GlobalSetOptions.adminstring)); - /* memset( &ConfigChannel, 0, sizeof(ConfigChannel)); */ + /* memset( &ConfigChannel, 0, sizeof(ConfigChannel)); */ - /* End of global set options */ + /* End of global set options */ } @@ -358,7 +358,7 @@ initialize_global_set_options(void) static void initialize_server_capabs(void) { - default_server_capabs &= ~CAP_ZIP; + default_server_capabs &= ~CAP_ZIP; } @@ -372,25 +372,21 @@ initialize_server_capabs(void) static void write_pidfile(const char *filename) { - FILE *fb; - char buff[32]; - if((fb = fopen(filename, "w"))) - { - unsigned int pid = (unsigned int) getpid(); + FILE *fb; + char buff[32]; + if((fb = fopen(filename, "w"))) { + unsigned int pid = (unsigned int) getpid(); - rb_snprintf(buff, sizeof(buff), "%u\n", pid); - if((fputs(buff, fb) == -1)) - { - ilog(L_MAIN, "Error writing %u to pid file %s (%s)", - pid, filename, strerror(errno)); - } - fclose(fb); - return; - } - else - { - ilog(L_MAIN, "Error opening pid file %s", filename); - } + rb_snprintf(buff, sizeof(buff), "%u\n", pid); + if((fputs(buff, fb) == -1)) { + ilog(L_MAIN, "Error writing %u to pid file %s (%s)", + pid, filename, strerror(errno)); + } + fclose(fb); + return; + } else { + ilog(L_MAIN, "Error opening pid file %s", filename); + } } /* @@ -405,24 +401,21 @@ write_pidfile(const char *filename) static void check_pidfile(const char *filename) { - FILE *fb; - char buff[32]; - pid_t pidfromfile; + FILE *fb; + char buff[32]; + pid_t pidfromfile; - /* Don't do logging here, since we don't have log() initialised */ - if((fb = fopen(filename, "r"))) - { - if(fgets(buff, 20, fb) != NULL) - { - pidfromfile = atoi(buff); - if(!kill(pidfromfile, 0)) - { - printf("ircd: daemon is already running\n"); - exit(-1); - } - } - fclose(fb); - } + /* Don't do logging here, since we don't have log() initialised */ + if((fb = fopen(filename, "r"))) { + if(fgets(buff, 20, fb) != NULL) { + pidfromfile = atoi(buff); + if(!kill(pidfromfile, 0)) { + printf("ircd: daemon is already running\n"); + exit(-1); + } + } + fclose(fb); + } } /* @@ -437,28 +430,27 @@ static void setup_corefile(void) { #ifdef HAVE_SYS_RESOURCE_H - struct rlimit rlim; /* resource limits */ + struct rlimit rlim; /* resource limits */ - /* Set corefilesize to maximum */ - if(!getrlimit(RLIMIT_CORE, &rlim)) - { - rlim.rlim_cur = rlim.rlim_max; - setrlimit(RLIMIT_CORE, &rlim); - } + /* Set corefilesize to maximum */ + if(!getrlimit(RLIMIT_CORE, &rlim)) { + rlim.rlim_cur = rlim.rlim_max; + setrlimit(RLIMIT_CORE, &rlim); + } #endif } static void ircd_log_cb(const char *str) { - ilog(L_MAIN, "libratbox reports: %s", str); + ilog(L_MAIN, "libratbox reports: %s", str); } static void ircd_restart_cb(const char *str) { - inotice("libratbox has called the restart callback: %s", str); - restart(str); + inotice("libratbox has called the restart callback: %s", str); + restart(str); } /* @@ -471,17 +463,15 @@ ircd_restart_cb(const char *str) static void ircd_die_cb(const char *str) { - if(str != NULL) - { - /* Try to get the message out to currently logged in operators. */ - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "libratbox has called the die callback..aborting: %s", str); - inotice("libratbox has called the die callback..aborting: %s", str); - } - else - inotice("libratbox has called the die callback..aborting"); + if(str != NULL) { + /* Try to get the message out to currently logged in operators. */ + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "libratbox has called the die callback..aborting: %s", str); + inotice("libratbox has called the die callback..aborting: %s", str); + } else + inotice("libratbox has called the die callback..aborting"); - unlink(pidFileName); - exit(EXIT_FAILURE); + unlink(pidFileName); + exit(EXIT_FAILURE); } struct ev_entry *check_splitmode_ev = NULL; @@ -489,42 +479,39 @@ struct ev_entry *check_splitmode_ev = NULL; static int seed_with_urandom(void) { - unsigned int seed; - int fd; + unsigned int seed; + int fd; - fd = open("/dev/urandom", O_RDONLY); - if(fd >= 0) - { - if(read(fd, &seed, sizeof(seed)) == sizeof(seed)) - { - close(fd); - srand(seed); - return 1; - } - } - return 0; + fd = open("/dev/urandom", O_RDONLY); + if(fd >= 0) { + if(read(fd, &seed, sizeof(seed)) == sizeof(seed)) { + close(fd); + srand(seed); + return 1; + } + } + return 0; } static void seed_with_clock(void) { - const struct timeval *tv; - rb_set_time(); - tv = rb_current_time_tv(); - srand(tv->tv_sec ^ (tv->tv_usec | (getpid() << 20))); + const struct timeval *tv; + rb_set_time(); + tv = rb_current_time_tv(); + srand(tv->tv_sec ^ (tv->tv_usec | (getpid() << 20))); } static void seed_random(void *unused) { - unsigned int seed; - if(rb_get_random(&seed, sizeof(seed)) == -1) - { - if(!seed_with_urandom()) - seed_with_clock(); - return; - } - srand(seed); + unsigned int seed; + if(rb_get_random(&seed, sizeof(seed)) == -1) { + if(!seed_with_urandom()) + seed_with_clock(); + return; + } + srand(seed); } /* @@ -539,231 +526,218 @@ seed_random(void *unused) int main(int argc, char *argv[]) { - int fd; + int fd; - /* Check to see if the user is running us as root, which is a nono */ - if(geteuid() == 0) - { - fprintf(stderr, "Don't run ircd as root!!!\n"); - return -1; - } + /* Check to see if the user is running us as root, which is a nono */ + if(geteuid() == 0) { + fprintf(stderr, "Don't run ircd as root!!!\n"); + return -1; + } - init_sys(); + init_sys(); - ConfigFileEntry.dpath = DPATH; - ConfigFileEntry.configfile = CPATH; /* Server configuration file */ - ConfigFileEntry.connect_timeout = 30; /* Default to 30 */ - - umask(077); /* better safe than sorry --SRB */ + ConfigFileEntry.dpath = DPATH; + ConfigFileEntry.configfile = CPATH; /* Server configuration file */ + ConfigFileEntry.connect_timeout = 30; /* Default to 30 */ - myargv = argv; - parseargs(&argc, &argv, myopts); + umask(077); /* better safe than sorry --SRB */ - if(chdir(ConfigFileEntry.dpath)) - { - fprintf(stderr, "Unable to chdir to %s: %s\n", ConfigFileEntry.dpath, strerror(errno)); - exit(EXIT_FAILURE); - } + myargv = argv; + parseargs(&argc, &argv, myopts); - rb_set_time(); + if(chdir(ConfigFileEntry.dpath)) { + fprintf(stderr, "Unable to chdir to %s: %s\n", ConfigFileEntry.dpath, strerror(errno)); + exit(EXIT_FAILURE); + } - /* - * Setup corefile size immediately after boot -kre - */ - setup_corefile(); + rb_set_time(); - memset(&me, 0, sizeof(me)); - memset(&meLocalUser, 0, sizeof(meLocalUser)); - me.localClient = &meLocalUser; + /* + * Setup corefile size immediately after boot -kre + */ + setup_corefile(); - /* Make sure all lists are zeroed */ - memset(&unknown_list, 0, sizeof(unknown_list)); - memset(&lclient_list, 0, sizeof(lclient_list)); - memset(&serv_list, 0, sizeof(serv_list)); - memset(&global_serv_list, 0, sizeof(global_serv_list)); - memset(&local_oper_list, 0, sizeof(local_oper_list)); - memset(&oper_list, 0, sizeof(oper_list)); + memset(&me, 0, sizeof(me)); + memset(&meLocalUser, 0, sizeof(meLocalUser)); + me.localClient = &meLocalUser; - rb_dlinkAddTail(&me, &me.node, &global_client_list); + /* Make sure all lists are zeroed */ + memset(&unknown_list, 0, sizeof(unknown_list)); + memset(&lclient_list, 0, sizeof(lclient_list)); + memset(&serv_list, 0, sizeof(serv_list)); + memset(&global_serv_list, 0, sizeof(global_serv_list)); + memset(&local_oper_list, 0, sizeof(local_oper_list)); + memset(&oper_list, 0, sizeof(oper_list)); - memset(&Count, 0, sizeof(Count)); - memset(&ServerInfo, 0, sizeof(ServerInfo)); - memset(&AdminInfo, 0, sizeof(AdminInfo)); - memset(&ServerStats, 0, sizeof(struct ServerStatistics)); + rb_dlinkAddTail(&me, &me.node, &global_client_list); - /* Initialise the channel capability usage counts... */ - init_chcap_usage_counts(); + memset(&Count, 0, sizeof(Count)); + memset(&ServerInfo, 0, sizeof(ServerInfo)); + memset(&AdminInfo, 0, sizeof(AdminInfo)); + memset(&ServerStats, 0, sizeof(struct ServerStatistics)); - if(printVersion) - { - printf("ircd: version %s(%s)\n", ircd_version, serno); - printf("ircd: %s\n", rb_lib_version()); - exit(EXIT_SUCCESS); - } + /* Initialise the channel capability usage counts... */ + init_chcap_usage_counts(); + + if(printVersion) { + printf("ircd: version %s(%s)\n", ircd_version, serno); + printf("ircd: %s\n", rb_lib_version()); + exit(EXIT_SUCCESS); + } - setup_signals(); + setup_signals(); - if (testing_conf) - server_state_foreground = 1; + if (testing_conf) + server_state_foreground = 1; - /* Make sure fd 0, 1 and 2 are in use -- jilles */ - do - { - fd = open("/dev/null", O_RDWR); - } while (fd < 2 && fd != -1); - if (fd > 2) - close(fd); - else if (fd == -1) - exit(1); + /* Make sure fd 0, 1 and 2 are in use -- jilles */ + do { + fd = open("/dev/null", O_RDWR); + } while (fd < 2 && fd != -1); + if (fd > 2) + close(fd); + else if (fd == -1) + exit(1); - /* Check if there is pidfile and daemon already running */ - if(!testing_conf) - { - check_pidfile(pidFileName); + /* Check if there is pidfile and daemon already running */ + if(!testing_conf) { + check_pidfile(pidFileName); - if(!server_state_foreground) - make_daemon(); - inotice("starting %s ...", ircd_version); - inotice("%s", rb_lib_version()); - } + if(!server_state_foreground) + make_daemon(); + inotice("starting %s ...", ircd_version); + inotice("%s", rb_lib_version()); + } - /* Init the event subsystem */ - rb_lib_init(ircd_log_cb, ircd_restart_cb, ircd_die_cb, !server_state_foreground, maxconnections, DNODE_HEAP_SIZE, FD_HEAP_SIZE); - rb_linebuf_init(LINEBUF_HEAP_SIZE); + /* Init the event subsystem */ + rb_lib_init(ircd_log_cb, ircd_restart_cb, ircd_die_cb, !server_state_foreground, maxconnections, DNODE_HEAP_SIZE, FD_HEAP_SIZE); + rb_linebuf_init(LINEBUF_HEAP_SIZE); - if(ConfigFileEntry.use_egd && (ConfigFileEntry.egdpool_path != NULL)) - { - rb_init_prng(ConfigFileEntry.egdpool_path, RB_PRNG_EGD); - } else - rb_init_prng(NULL, RB_PRNG_DEFAULT); + if(ConfigFileEntry.use_egd && (ConfigFileEntry.egdpool_path != NULL)) { + rb_init_prng(ConfigFileEntry.egdpool_path, RB_PRNG_EGD); + } else + rb_init_prng(NULL, RB_PRNG_DEFAULT); - seed_random(NULL); + seed_random(NULL); - init_main_logfile(); - newconf_init(); - init_s_conf(); - init_s_newconf(); - init_hash(); - clear_scache_hash_table(); /* server cache name table */ - init_host_hash(); - clear_hash_parse(); - init_client(); - init_hook(); - init_channels(); - initclass(); - initwhowas(); - init_reject(); - init_cache(); - init_monitor(); - init_isupport(); + init_main_logfile(); + newconf_init(); + init_s_conf(); + init_s_newconf(); + init_hash(); + clear_scache_hash_table(); /* server cache name table */ + init_host_hash(); + clear_hash_parse(); + init_client(); + init_hook(); + init_channels(); + initclass(); + initwhowas(); + init_reject(); + init_cache(); + init_monitor(); + init_isupport(); - construct_cflags_strings(); + construct_cflags_strings(); - load_all_modules(1); + load_all_modules(1); #ifndef STATIC_MODULES - load_core_modules(1); + load_core_modules(1); #endif - init_auth(); /* Initialise the auth code */ - init_resolver(); /* Needs to be setup before the io loop */ - privilegeset_set_new("default", "", 0); + init_auth(); /* Initialise the auth code */ + init_resolver(); /* Needs to be setup before the io loop */ + privilegeset_set_new("default", "", 0); - if (testing_conf) - fprintf(stderr, "\nBeginning config test\n"); - read_conf_files(YES); /* cold start init conf files */ + if (testing_conf) + fprintf(stderr, "\nBeginning config test\n"); + read_conf_files(YES); /* cold start init conf files */ #ifndef STATIC_MODULES - mod_add_path(MODULE_DIR); - mod_add_path(MODULE_DIR "/autoload"); + mod_add_path(MODULE_DIR); + mod_add_path(MODULE_DIR "/autoload"); #endif - init_bandb(); - init_ssld(); + init_bandb(); + init_ssld(); - rehash_bans(0); + rehash_bans(0); - initialize_server_capabs(); /* Set up default_server_capabs */ - initialize_global_set_options(); + initialize_server_capabs(); /* Set up default_server_capabs */ + initialize_global_set_options(); - if(ServerInfo.name == NULL) - { - ierror("no server name specified in serverinfo block."); - return -1; - } - rb_strlcpy(me.name, ServerInfo.name, sizeof(me.name)); + if(ServerInfo.name == NULL) { + ierror("no server name specified in serverinfo block."); + return -1; + } + rb_strlcpy(me.name, ServerInfo.name, sizeof(me.name)); - if(ServerInfo.sid[0] == '\0') - { - ierror("no server sid specified in serverinfo block."); - return -2; - } - strcpy(me.id, ServerInfo.sid); - init_uid(); + if(ServerInfo.sid[0] == '\0') { + ierror("no server sid specified in serverinfo block."); + return -2; + } + strcpy(me.id, ServerInfo.sid); + init_uid(); - /* serverinfo{} description must exist. If not, error out. */ - if(ServerInfo.description == NULL) - { - ierror("no server description specified in serverinfo block."); - return -3; - } - rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); + /* serverinfo{} description must exist. If not, error out. */ + if(ServerInfo.description == NULL) { + ierror("no server description specified in serverinfo block."); + return -3; + } + rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); - if(ServerInfo.ssl_cert != NULL && ServerInfo.ssl_private_key != NULL) - { - /* just do the rb_setup_ssl_server to validate the config */ - if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params)) - { - ilog(L_MAIN, "WARNING: Unable to setup SSL."); - ssl_ok = 0; - } - else - ssl_ok = 1; - } + if(ServerInfo.ssl_cert != NULL && ServerInfo.ssl_private_key != NULL) { + /* just do the rb_setup_ssl_server to validate the config */ + if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params)) { + ilog(L_MAIN, "WARNING: Unable to setup SSL."); + ssl_ok = 0; + } else + ssl_ok = 1; + } - if (testing_conf) - { - fprintf(stderr, "\nConfig testing complete.\n"); - fflush(stderr); - return 0; /* Why? We want the launcher to exit out. */ - } + if (testing_conf) { + fprintf(stderr, "\nConfig testing complete.\n"); + fflush(stderr); + return 0; /* Why? We want the launcher to exit out. */ + } - me.from = &me; - me.servptr = &me; - SetMe(&me); - make_server(&me); - startup_time = rb_current_time(); - add_to_client_hash(me.name, &me); - add_to_id_hash(me.id, &me); - me.serv->nameinfo = scache_connect(me.name, me.info, 0); + me.from = &me; + me.servptr = &me; + SetMe(&me); + make_server(&me); + startup_time = rb_current_time(); + add_to_client_hash(me.name, &me); + add_to_id_hash(me.id, &me); + me.serv->nameinfo = scache_connect(me.name, me.info, 0); - rb_dlinkAddAlloc(&me, &global_serv_list); + rb_dlinkAddAlloc(&me, &global_serv_list); - construct_umodebuf(); + construct_umodebuf(); - check_class(); - write_pidfile(pidFileName); - load_help(); - open_logfiles(); + check_class(); + write_pidfile(pidFileName); + load_help(); + open_logfiles(); - ilog(L_MAIN, "Server Ready"); + ilog(L_MAIN, "Server Ready"); - /* We want try_connections to be called as soon as possible now! -- adrian */ - /* No, 'cause after a restart it would cause all sorts of nick collides */ - /* um. by waiting even longer, that just means we have even *more* - * nick collisions. what a stupid idea. set an event for the IO loop --fl - */ - rb_event_addish("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); - rb_event_addonce("try_connections_startup", try_connections, NULL, 2); - rb_event_add("check_rehash", check_rehash, NULL, 3); - rb_event_addish("reseed_srand", seed_random, NULL, 300); /* reseed every 10 minutes */ + /* We want try_connections to be called as soon as possible now! -- adrian */ + /* No, 'cause after a restart it would cause all sorts of nick collides */ + /* um. by waiting even longer, that just means we have even *more* + * nick collisions. what a stupid idea. set an event for the IO loop --fl + */ + rb_event_addish("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); + rb_event_addonce("try_connections_startup", try_connections, NULL, 2); + rb_event_add("check_rehash", check_rehash, NULL, 3); + rb_event_addish("reseed_srand", seed_random, NULL, 300); /* reseed every 10 minutes */ - if(splitmode) - check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 5); + if(splitmode) + check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 5); - print_startup(getpid()); + print_startup(getpid()); - rb_lib_loop(0); + rb_lib_loop(0); - return 0; + return 0; } diff --git a/src/ircd_signal.c b/src/ircd_signal.c index f861a38..9169723 100644 --- a/src/ircd_signal.c +++ b/src/ircd_signal.c @@ -35,19 +35,19 @@ static void dummy_handler(int sig) { - /* Empty */ + /* Empty */ } static void sigchld_handler(int sig) { - int status, olderrno; + int status, olderrno; - olderrno = errno; - while (waitpid(-1, &status, WNOHANG) > 0) - ; - errno = olderrno; + olderrno = errno; + while (waitpid(-1, &status, WNOHANG) > 0) + ; + errno = olderrno; } /* @@ -56,16 +56,16 @@ sigchld_handler(int sig) static void sigterm_handler(int sig) { - ircd_shutdown("Received SIGTERM"); + ircd_shutdown("Received SIGTERM"); } -/* +/* * sighup_handler - reread the server configuration */ static void sighup_handler(int sig) { - dorehash = 1; + dorehash = 1; } /* @@ -74,13 +74,13 @@ sighup_handler(int sig) static void sigusr1_handler(int sig) { - doremotd = 1; + doremotd = 1; } static void sigusr2_handler(int sig) { - dorehashbans = 1; + dorehashbans = 1; } /* @@ -89,22 +89,18 @@ sigusr2_handler(int sig) static void sigint_handler(int sig) { - static int restarting = 0; + static int restarting = 0; - if(server_state_foreground) - { - ilog(L_MAIN, "Server exiting on SIGINT"); - exit(0); - } - else - { - ilog(L_MAIN, "Server Restarting on SIGINT"); - if(restarting == 0) - { - restarting = 1; - server_reboot(); - } - } + if(server_state_foreground) { + ilog(L_MAIN, "Server exiting on SIGINT"); + exit(0); + } else { + ilog(L_MAIN, "Server Restarting on SIGINT"); + if(restarting == 0) { + restarting = 1; + server_reboot(); + } + } } /* @@ -113,52 +109,52 @@ sigint_handler(int sig) void setup_signals() { - struct sigaction act; + struct sigaction act; - act.sa_flags = 0; - act.sa_handler = SIG_IGN; - sigemptyset(&act.sa_mask); - sigaddset(&act.sa_mask, SIGPIPE); - sigaddset(&act.sa_mask, SIGALRM); + act.sa_flags = 0; + act.sa_handler = SIG_IGN; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGPIPE); + sigaddset(&act.sa_mask, SIGALRM); #ifdef SIGTRAP - sigaddset(&act.sa_mask, SIGTRAP); + sigaddset(&act.sa_mask, SIGTRAP); #endif # ifdef SIGWINCH - sigaddset(&act.sa_mask, SIGWINCH); - sigaction(SIGWINCH, &act, 0); + sigaddset(&act.sa_mask, SIGWINCH); + sigaction(SIGWINCH, &act, 0); # endif - sigaction(SIGPIPE, &act, 0); + sigaction(SIGPIPE, &act, 0); #ifdef SIGTRAP - sigaction(SIGTRAP, &act, 0); + sigaction(SIGTRAP, &act, 0); #endif - act.sa_handler = dummy_handler; - sigaction(SIGALRM, &act, 0); + act.sa_handler = dummy_handler; + sigaction(SIGALRM, &act, 0); - act.sa_handler = sighup_handler; - sigemptyset(&act.sa_mask); - sigaddset(&act.sa_mask, SIGHUP); - sigaction(SIGHUP, &act, 0); + act.sa_handler = sighup_handler; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGHUP); + sigaction(SIGHUP, &act, 0); - act.sa_handler = sigint_handler; - sigaddset(&act.sa_mask, SIGINT); - sigaction(SIGINT, &act, 0); + act.sa_handler = sigint_handler; + sigaddset(&act.sa_mask, SIGINT); + sigaction(SIGINT, &act, 0); - act.sa_handler = sigterm_handler; - sigaddset(&act.sa_mask, SIGTERM); - sigaction(SIGTERM, &act, 0); + act.sa_handler = sigterm_handler; + sigaddset(&act.sa_mask, SIGTERM); + sigaction(SIGTERM, &act, 0); - act.sa_handler = sigusr1_handler; - sigaddset(&act.sa_mask, SIGUSR1); - sigaction(SIGUSR1, &act, 0); + act.sa_handler = sigusr1_handler; + sigaddset(&act.sa_mask, SIGUSR1); + sigaction(SIGUSR1, &act, 0); - act.sa_handler = sigusr2_handler; - sigaddset(&act.sa_mask, SIGUSR2); - sigaction(SIGUSR2, &act, 0); + act.sa_handler = sigusr2_handler; + sigaddset(&act.sa_mask, SIGUSR2); + sigaction(SIGUSR2, &act, 0); - act.sa_handler = sigchld_handler; - sigaddset(&act.sa_mask, SIGCHLD); - sigaction(SIGCHLD, &act, 0); + act.sa_handler = sigchld_handler; + sigaddset(&act.sa_mask, SIGCHLD); + sigaction(SIGCHLD, &act, 0); } diff --git a/src/listener.c b/src/listener.c index a781f60..901e9ea 100644 --- a/src/listener.c +++ b/src/listener.c @@ -49,7 +49,7 @@ #if defined(NO_IN6ADDR_ANY) && defined(RB_IPV6) static const struct in6_addr in6addr_any = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; -#endif +#endif static struct Listener *ListenerPollList = NULL; static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data); @@ -58,42 +58,39 @@ static void accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_s static struct Listener * make_listener(struct rb_sockaddr_storage *addr) { - struct Listener *listener = (struct Listener *) rb_malloc(sizeof(struct Listener)); - s_assert(0 != listener); - listener->name = me.name; - listener->F = NULL; + struct Listener *listener = (struct Listener *) rb_malloc(sizeof(struct Listener)); + s_assert(0 != listener); + listener->name = me.name; + listener->F = NULL; - memcpy(&listener->addr, addr, sizeof(struct rb_sockaddr_storage)); - listener->next = NULL; - return listener; + memcpy(&listener->addr, addr, sizeof(struct rb_sockaddr_storage)); + listener->next = NULL; + return listener; } void free_listener(struct Listener *listener) { - s_assert(NULL != listener); - if(listener == NULL) - return; - /* - * remove from listener list - */ - if(listener == ListenerPollList) - ListenerPollList = listener->next; - else - { - struct Listener *prev = ListenerPollList; - for (; prev; prev = prev->next) - { - if(listener == prev->next) - { - prev->next = listener->next; - break; - } - } - } + s_assert(NULL != listener); + if(listener == NULL) + return; + /* + * remove from listener list + */ + if(listener == ListenerPollList) + ListenerPollList = listener->next; + else { + struct Listener *prev = ListenerPollList; + for (; prev; prev = prev->next) { + if(listener == prev->next) { + prev->next = listener->next; + break; + } + } + } - /* free */ - rb_free(listener); + /* free */ + rb_free(listener); } #define PORTNAMELEN 6 /* ":31337" */ @@ -105,22 +102,22 @@ free_listener(struct Listener *listener) const char * get_listener_name(const struct Listener *listener) { - static char buf[HOSTLEN + HOSTLEN + PORTNAMELEN + 4]; - int port = 0; + static char buf[HOSTLEN + HOSTLEN + PORTNAMELEN + 4]; + int port = 0; - s_assert(NULL != listener); - if(listener == NULL) - return NULL; + s_assert(NULL != listener); + if(listener == NULL) + return NULL; #ifdef RB_IPV6 - if(listener->addr.ss_family == AF_INET6) - port = ntohs(((const struct sockaddr_in6 *)&listener->addr)->sin6_port); - else + if(listener->addr.ss_family == AF_INET6) + port = ntohs(((const struct sockaddr_in6 *)&listener->addr)->sin6_port); + else #endif - port = ntohs(((const struct sockaddr_in *)&listener->addr)->sin_port); + port = ntohs(((const struct sockaddr_in *)&listener->addr)->sin_port); - rb_snprintf(buf, sizeof(buf), "%s[%s/%u]", me.name, listener->name, port); - return buf; + rb_snprintf(buf, sizeof(buf), "%s[%s/%u]", me.name, listener->name, port); + return buf; } /* @@ -132,22 +129,21 @@ get_listener_name(const struct Listener *listener) void show_ports(struct Client *source_p) { - struct Listener *listener = 0; + struct Listener *listener = 0; - for (listener = ListenerPollList; listener; listener = listener->next) - { - sendto_one_numeric(source_p, RPL_STATSPLINE, - form_str(RPL_STATSPLINE), 'P', + for (listener = ListenerPollList; listener; listener = listener->next) { + sendto_one_numeric(source_p, RPL_STATSPLINE, + form_str(RPL_STATSPLINE), 'P', #ifdef RB_IPV6 - ntohs(listener->addr.ss_family == AF_INET ? ((struct sockaddr_in *)&listener->addr)->sin_port : - ((struct sockaddr_in6 *)&listener->addr)->sin6_port), + ntohs(listener->addr.ss_family == AF_INET ? ((struct sockaddr_in *)&listener->addr)->sin_port : + ((struct sockaddr_in6 *)&listener->addr)->sin6_port), #else - ntohs(((struct sockaddr_in *)&listener->addr)->sin_port), + ntohs(((struct sockaddr_in *)&listener->addr)->sin_port), #endif - IsOperAdmin(source_p) ? listener->name : me.name, - listener->ref_count, (listener->active) ? "active" : "disabled", - listener->ssl ? " ssl" : ""); - } + IsOperAdmin(source_p) ? listener->name : me.name, + listener->ref_count, (listener->active) ? "active" : "disabled", + listener->ssl ? " ssl" : ""); + } } /* @@ -166,133 +162,118 @@ show_ports(struct Client *source_p) static int inetport(struct Listener *listener) { - rb_fde_t *F; - int opt = 1; + rb_fde_t *F; + int opt = 1; - /* - * At first, open a new socket - */ - - F = rb_socket(GET_SS_FAMILY(&listener->addr), SOCK_STREAM, 0, "Listener socket"); + /* + * At first, open a new socket + */ + + F = rb_socket(GET_SS_FAMILY(&listener->addr), SOCK_STREAM, 0, "Listener socket"); #ifdef RB_IPV6 - if(listener->addr.ss_family == AF_INET6) - { - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&listener->addr; - if(!IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &in6addr_any)) - { - rb_inet_ntop(AF_INET6, &in6->sin6_addr, listener->vhost, sizeof(listener->vhost)); - listener->name = listener->vhost; - } - } else + if(listener->addr.ss_family == AF_INET6) { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&listener->addr; + if(!IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &in6addr_any)) { + rb_inet_ntop(AF_INET6, &in6->sin6_addr, listener->vhost, sizeof(listener->vhost)); + listener->name = listener->vhost; + } + } else #endif - { - struct sockaddr_in *in = (struct sockaddr_in *)&listener->addr; - if(in->sin_addr.s_addr != INADDR_ANY) - { - rb_inet_ntop(AF_INET, &in->sin_addr, listener->vhost, sizeof(listener->vhost)); - listener->name = listener->vhost; - } - } + { + struct sockaddr_in *in = (struct sockaddr_in *)&listener->addr; + if(in->sin_addr.s_addr != INADDR_ANY) { + rb_inet_ntop(AF_INET, &in->sin_addr, listener->vhost, sizeof(listener->vhost)); + listener->name = listener->vhost; + } + } - if(F == NULL) - { - ilog_error("opening listener socket"); - return 0; - } - else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/ - { - ilog_error("no more connections left for listener"); - rb_close(F); - return 0; - } + if(F == NULL) { + ilog_error("opening listener socket"); + return 0; + } else if((maxconnections - 10) < rb_get_fd(F)) { /* XXX this is kinda bogus*/ + ilog_error("no more connections left for listener"); + rb_close(F); + return 0; + } - /* - * XXX - we don't want to do all this crap for a listener - * set_sock_opts(listener); - */ - if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt))) - { - ilog_error("setting SO_REUSEADDR for listener"); - rb_close(F); - return 0; - } + /* + * XXX - we don't want to do all this crap for a listener + * set_sock_opts(listener); + */ + if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt))) { + ilog_error("setting SO_REUSEADDR for listener"); + rb_close(F); + return 0; + } - /* - * Bind a port to listen for new connections if port is non-null, - * else assume it is already open and try get something from it. - */ + /* + * Bind a port to listen for new connections if port is non-null, + * else assume it is already open and try get something from it. + */ - if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr))) - { - ilog_error("binding listener socket"); - rb_close(F); - return 0; - } + if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr))) { + ilog_error("binding listener socket"); + rb_close(F); + return 0; + } - if(rb_listen(F, RATBOX_SOMAXCONN, listener->defer_accept)) - { - ilog_error("listen()"); - rb_close(F); - return 0; - } + if(rb_listen(F, RATBOX_SOMAXCONN, listener->defer_accept)) { + ilog_error("listen()"); + rb_close(F); + return 0; + } - listener->F = F; + listener->F = F; - rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener); - return 1; + rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener); + return 1; } static struct Listener * find_listener(struct rb_sockaddr_storage *addr) { - struct Listener *listener = NULL; - struct Listener *last_closed = NULL; + struct Listener *listener = NULL; + struct Listener *last_closed = NULL; - for (listener = ListenerPollList; listener; listener = listener->next) - { - if(addr->ss_family != listener->addr.ss_family) - continue; - - switch(addr->ss_family) - { - case AF_INET: - { - struct sockaddr_in *in4 = (struct sockaddr_in *)addr; - struct sockaddr_in *lin4 = (struct sockaddr_in *)&listener->addr; - if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr && - in4->sin_port == lin4->sin_port ) - { - if(listener->F == NULL) - last_closed = listener; - else - return(listener); - } - break; - } + for (listener = ListenerPollList; listener; listener = listener->next) { + if(addr->ss_family != listener->addr.ss_family) + continue; + + switch(addr->ss_family) { + case AF_INET: { + struct sockaddr_in *in4 = (struct sockaddr_in *)addr; + struct sockaddr_in *lin4 = (struct sockaddr_in *)&listener->addr; + if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr && + in4->sin_port == lin4->sin_port ) { + if(listener->F == NULL) + last_closed = listener; + else + return(listener); + } + break; + } #ifdef RB_IPV6 - case AF_INET6: - { - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; - struct sockaddr_in6 *lin6 =(struct sockaddr_in6 *)&listener->addr; - if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) && - in6->sin6_port == lin6->sin6_port) - { - if(listener->F == NULL) - last_closed = listener; - else - return(listener); - } - break; - - } + case AF_INET6: { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; + struct sockaddr_in6 *lin6 =(struct sockaddr_in6 *)&listener->addr; + if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) && + in6->sin6_port == lin6->sin6_port) { + if(listener->F == NULL) + last_closed = listener; + else + return(listener); + } + break; + + } #endif - default: - break; - } - } - return last_closed; + default: + break; + } + } + return last_closed; } @@ -305,83 +286,74 @@ find_listener(struct rb_sockaddr_storage *addr) void add_listener(int port, const char *vhost_ip, int family, int ssl, int defer_accept) { - struct Listener *listener; - struct rb_sockaddr_storage vaddr; + struct Listener *listener; + struct rb_sockaddr_storage vaddr; - /* - * if no port in conf line, don't bother - */ - if(port == 0) - return; - memset(&vaddr, 0, sizeof(vaddr)); - vaddr.ss_family = family; + /* + * if no port in conf line, don't bother + */ + if(port == 0) + return; + memset(&vaddr, 0, sizeof(vaddr)); + vaddr.ss_family = family; - if(vhost_ip != NULL) - { - if(family == AF_INET) - { - if(rb_inet_pton(family, vhost_ip, &((struct sockaddr_in *)&vaddr)->sin_addr) <= 0) - return; - } + if(vhost_ip != NULL) { + if(family == AF_INET) { + if(rb_inet_pton(family, vhost_ip, &((struct sockaddr_in *)&vaddr)->sin_addr) <= 0) + return; + } #ifdef RB_IPV6 - else - { - if(rb_inet_pton(family, vhost_ip, &((struct sockaddr_in6 *)&vaddr)->sin6_addr) <= 0) - return; - - } -#endif - } else - { - switch(family) - { - case AF_INET: - ((struct sockaddr_in *)&vaddr)->sin_addr.s_addr = INADDR_ANY; - break; -#ifdef RB_IPV6 - case AF_INET6: - memcpy(&((struct sockaddr_in6 *)&vaddr)->sin6_addr, &in6addr_any, sizeof(struct in6_addr)); - break; - default: - return; -#endif - } - } - switch(family) - { - case AF_INET: - SET_SS_LEN(&vaddr, sizeof(struct sockaddr_in)); - ((struct sockaddr_in *)&vaddr)->sin_port = htons(port); - break; -#ifdef RB_IPV6 - case AF_INET6: - SET_SS_LEN(&vaddr, sizeof(struct sockaddr_in6)); - ((struct sockaddr_in6 *)&vaddr)->sin6_port = htons(port); - break; -#endif - default: - break; - } - if((listener = find_listener(&vaddr))) - { - if(listener->F != NULL) - return; - } - else - { - listener = make_listener(&vaddr); - listener->next = ListenerPollList; - ListenerPollList = listener; - } + else { + if(rb_inet_pton(family, vhost_ip, &((struct sockaddr_in6 *)&vaddr)->sin6_addr) <= 0) + return; - listener->F = NULL; - listener->ssl = ssl; - listener->defer_accept = defer_accept; + } +#endif + } else { + switch(family) { + case AF_INET: + ((struct sockaddr_in *)&vaddr)->sin_addr.s_addr = INADDR_ANY; + break; +#ifdef RB_IPV6 + case AF_INET6: + memcpy(&((struct sockaddr_in6 *)&vaddr)->sin6_addr, &in6addr_any, sizeof(struct in6_addr)); + break; + default: + return; +#endif + } + } + switch(family) { + case AF_INET: + SET_SS_LEN(&vaddr, sizeof(struct sockaddr_in)); + ((struct sockaddr_in *)&vaddr)->sin_port = htons(port); + break; +#ifdef RB_IPV6 + case AF_INET6: + SET_SS_LEN(&vaddr, sizeof(struct sockaddr_in6)); + ((struct sockaddr_in6 *)&vaddr)->sin6_port = htons(port); + break; +#endif + default: + break; + } + if((listener = find_listener(&vaddr))) { + if(listener->F != NULL) + return; + } else { + listener = make_listener(&vaddr); + listener->next = ListenerPollList; + ListenerPollList = listener; + } - if(inetport(listener)) - listener->active = 1; - else - close_listener(listener); + listener->F = NULL; + listener->ssl = ssl; + listener->defer_accept = defer_accept; + + if(inetport(listener)) + listener->active = 1; + else + close_listener(listener); } /* @@ -390,21 +362,20 @@ add_listener(int port, const char *vhost_ip, int family, int ssl, int defer_acce void close_listener(struct Listener *listener) { - s_assert(listener != NULL); - if(listener == NULL) - return; - if(listener->F != NULL) - { - rb_close(listener->F); - listener->F = NULL; - } + s_assert(listener != NULL); + if(listener == NULL) + return; + if(listener->F != NULL) { + rb_close(listener->F); + listener->F = NULL; + } - listener->active = 0; + listener->active = 0; - if(listener->ref_count) - return; + if(listener->ref_count) + return; - free_listener(listener); + free_listener(listener); } /* @@ -413,22 +384,21 @@ close_listener(struct Listener *listener) void close_listeners() { - struct Listener *listener; - struct Listener *listener_next = 0; - /* - * close all 'extra' listening ports we have - */ - for (listener = ListenerPollList; listener; listener = listener_next) - { - listener_next = listener->next; - close_listener(listener); - } + struct Listener *listener; + struct Listener *listener_next = 0; + /* + * close all 'extra' listening ports we have + */ + for (listener = ListenerPollList; listener; listener = listener_next) { + listener_next = listener->next; + close_listener(listener); + } } #define DLINE_WARNING "ERROR :You have been D-lined.\r\n" /* - * add_connection - creates a client which has just connected to us on + * add_connection - creates a client which has just connected to us on * the given fd. The sockhost field is initialized with the ip# of the host. * The client is sent to the auth module for verification, and not put in * any client list yet. @@ -436,38 +406,38 @@ close_listeners() static void add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, struct sockaddr *lai, void *ssl_ctl) { - struct Client *new_client; - s_assert(NULL != listener); + struct Client *new_client; + s_assert(NULL != listener); - /* - * get the client socket name from the socket - * the client has already been checked out in accept_connection - */ - new_client = make_client(NULL); + /* + * get the client socket name from the socket + * the client has already been checked out in accept_connection + */ + new_client = make_client(NULL); - memcpy(&new_client->localClient->ip, sai, sizeof(struct rb_sockaddr_storage)); - memcpy(&new_client->preClient->lip, lai, sizeof(struct rb_sockaddr_storage)); + memcpy(&new_client->localClient->ip, sai, sizeof(struct rb_sockaddr_storage)); + memcpy(&new_client->preClient->lip, lai, sizeof(struct rb_sockaddr_storage)); - /* - * copy address to 'sockhost' as a string, copy it to host too - * so we have something valid to put into error messages... - */ - rb_inet_ntop_sock((struct sockaddr *)&new_client->localClient->ip, new_client->sockhost, - sizeof(new_client->sockhost)); + /* + * copy address to 'sockhost' as a string, copy it to host too + * so we have something valid to put into error messages... + */ + rb_inet_ntop_sock((struct sockaddr *)&new_client->localClient->ip, new_client->sockhost, + sizeof(new_client->sockhost)); - rb_strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host)); + rb_strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host)); - new_client->localClient->F = F; - add_to_cli_fd_hash(new_client); - new_client->localClient->listener = listener; - new_client->localClient->ssl_ctl = ssl_ctl; - if(ssl_ctl != NULL || rb_fd_ssl(F)) - SetSSL(new_client); + new_client->localClient->F = F; + add_to_cli_fd_hash(new_client); + new_client->localClient->listener = listener; + new_client->localClient->ssl_ctl = ssl_ctl; + if(ssl_ctl != NULL || rb_fd_ssl(F)) + SetSSL(new_client); - ++listener->ref_count; + ++listener->ref_count; - start_auth(new_client); + start_auth(new_client); } static const char *toofast = "ERROR :Reconnecting too fast, throttled.\r\n"; @@ -475,112 +445,102 @@ static const char *toofast = "ERROR :Reconnecting too fast, throttled.\r\n"; static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data) { - struct Listener *listener = (struct Listener *)data; - char buf[BUFSIZE]; - struct ConfItem *aconf; - static time_t last_oper_notice = 0; - int len; + struct Listener *listener = (struct Listener *)data; + char buf[BUFSIZE]; + struct ConfItem *aconf; + static time_t last_oper_notice = 0; + int len; - if(listener->ssl && (!ssl_ok || !get_ssld_count())) - { - rb_close(F); - return 0; - } + if(listener->ssl && (!ssl_ok || !get_ssld_count())) { + rb_close(F); + return 0; + } - if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */ - { - ++ServerStats.is_ref; - /* - * slow down the whining to opers bit - */ - if((last_oper_notice + 20) <= rb_current_time()) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "All connections in use. (%s)", - get_listener_name(listener)); - last_oper_notice = rb_current_time(); - } - - rb_write(F, "ERROR :All connections in use\r\n", 32); - rb_close(F); - /* Re-register a new IO request for the next accept .. */ - return 0; - } + if((maxconnections - 10) < rb_get_fd(F)) { /* XXX this is kinda bogus */ + ++ServerStats.is_ref; + /* + * slow down the whining to opers bit + */ + if((last_oper_notice + 20) <= rb_current_time()) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "All connections in use. (%s)", + get_listener_name(listener)); + last_oper_notice = rb_current_time(); + } - aconf = find_dline(addr, addr->sa_family); - if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE)) - return 1; - - /* Do an initial check we aren't connecting too fast or with too many - * from this IP... */ - if(aconf != NULL) - { - ServerStats.is_ref++; - - if(ConfigFileEntry.dline_with_reason) - { - len = rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", get_user_ban_reason(aconf)); - if (len >= (int)(sizeof(buf)-1)) - { - buf[sizeof(buf) - 3] = '\r'; - buf[sizeof(buf) - 2] = '\n'; - buf[sizeof(buf) - 1] = '\0'; - } - } - else - strcpy(buf, "ERROR :You have been D-lined.\r\n"); - - rb_write(F, buf, strlen(buf)); - rb_close(F); - return 0; - } + rb_write(F, "ERROR :All connections in use\r\n", 32); + rb_close(F); + /* Re-register a new IO request for the next accept .. */ + return 0; + } - if(check_reject(F, addr)) - return 0; - - if(throttle_add(addr)) - { - rb_write(F, toofast, strlen(toofast)); - rb_close(F); - return 0; - } + aconf = find_dline(addr, addr->sa_family); + if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE)) + return 1; - return 1; + /* Do an initial check we aren't connecting too fast or with too many + * from this IP... */ + if(aconf != NULL) { + ServerStats.is_ref++; + + if(ConfigFileEntry.dline_with_reason) { + len = rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", get_user_ban_reason(aconf)); + if (len >= (int)(sizeof(buf)-1)) { + buf[sizeof(buf) - 3] = '\r'; + buf[sizeof(buf) - 2] = '\n'; + buf[sizeof(buf) - 1] = '\0'; + } + } else + strcpy(buf, "ERROR :You have been D-lined.\r\n"); + + rb_write(F, buf, strlen(buf)); + rb_close(F); + return 0; + } + + if(check_reject(F, addr)) + return 0; + + if(throttle_add(addr)) { + rb_write(F, toofast, strlen(toofast)); + rb_close(F); + return 0; + } + + return 1; } static void accept_ssld(rb_fde_t *F, struct sockaddr *addr, struct sockaddr *laddr, struct Listener *listener) { - ssl_ctl_t *ctl; - rb_fde_t *xF[2]; - if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF[0], &xF[1], "Incoming ssld Connection") == -1) - { - ilog_error("creating SSL/TLS socket pairs"); - rb_close(F); - return; - } - ctl = start_ssld_accept(F, xF[1], rb_get_fd(xF[0])); /* this will close F for us */ - add_connection(listener, xF[0], addr, laddr, ctl); + ssl_ctl_t *ctl; + rb_fde_t *xF[2]; + if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF[0], &xF[1], "Incoming ssld Connection") == -1) { + ilog_error("creating SSL/TLS socket pairs"); + rb_close(F); + return; + } + ctl = start_ssld_accept(F, xF[1], rb_get_fd(xF[0])); /* this will close F for us */ + add_connection(listener, xF[0], addr, laddr, ctl); } static void accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data) { - struct Listener *listener = data; - struct rb_sockaddr_storage lip; - unsigned int locallen = sizeof(struct rb_sockaddr_storage); - - ServerStats.is_ac++; + struct Listener *listener = data; + struct rb_sockaddr_storage lip; + unsigned int locallen = sizeof(struct rb_sockaddr_storage); - if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0) - { - /* this can fail if the connection disappeared in the meantime */ - rb_close(F); - return; - } - - if(listener->ssl) - accept_ssld(F, addr, (struct sockaddr *)&lip, listener); - else - add_connection(listener, F, addr, (struct sockaddr *)&lip, NULL); + ServerStats.is_ac++; + + if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0) { + /* this can fail if the connection disappeared in the meantime */ + rb_close(F); + return; + } + + if(listener->ssl) + accept_ssld(F, addr, (struct sockaddr *)&lip, listener); + else + add_connection(listener, F, addr, (struct sockaddr *)&lip, NULL); } diff --git a/src/logger.c b/src/logger.c index b6d3dcc..2bfeed8 100644 --- a/src/logger.c +++ b/src/logger.c @@ -52,238 +52,226 @@ static FILE *log_kline; static FILE *log_operspy; static FILE *log_ioerror; -struct log_struct -{ - char **name; - FILE **logfile; +struct log_struct { + char **name; + FILE **logfile; }; -static struct log_struct log_table[LAST_LOGFILE] = -{ - { NULL, &log_main }, - { &ConfigFileEntry.fname_userlog, &log_user }, - { &ConfigFileEntry.fname_fuserlog, &log_fuser }, - { &ConfigFileEntry.fname_operlog, &log_oper }, - { &ConfigFileEntry.fname_foperlog, &log_foper }, - { &ConfigFileEntry.fname_serverlog, &log_server }, - { &ConfigFileEntry.fname_killlog, &log_kill }, - { &ConfigFileEntry.fname_klinelog, &log_kline }, - { &ConfigFileEntry.fname_operspylog, &log_operspy }, - { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror } +static struct log_struct log_table[LAST_LOGFILE] = { + { NULL, &log_main }, + { &ConfigFileEntry.fname_userlog, &log_user }, + { &ConfigFileEntry.fname_fuserlog, &log_fuser }, + { &ConfigFileEntry.fname_operlog, &log_oper }, + { &ConfigFileEntry.fname_foperlog, &log_foper }, + { &ConfigFileEntry.fname_serverlog, &log_server }, + { &ConfigFileEntry.fname_killlog, &log_kill }, + { &ConfigFileEntry.fname_klinelog, &log_kline }, + { &ConfigFileEntry.fname_operspylog, &log_operspy }, + { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror } }; static void verify_logfile_access(const char *filename) { - char *dirname, *d; - char buf[512]; - d = rb_dirname(filename); - dirname = LOCAL_COPY(d); - rb_free(d); - - if(access(dirname, F_OK) == -1) - { - rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - parent directory %s does not exist", filename, dirname); - if(testing_conf || server_state_foreground) - fprintf(stderr, "%s\n", buf); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); - return; - } + char *dirname, *d; + char buf[512]; + d = rb_dirname(filename); + dirname = LOCAL_COPY(d); + rb_free(d); - if(access(filename, F_OK) == -1) - { - if(access(dirname, W_OK) == -1) - { - rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - access to parent directory %s failed: %s", - filename, dirname, strerror(errno)); - if(testing_conf || server_state_foreground) - fprintf(stderr, "%s\n", buf); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); - } - return; - } - - if(access(filename, W_OK) == -1) - { - rb_snprintf(buf, sizeof(buf), "WARNING: Access denied for logfile %s: %s", filename, strerror(errno)); - if(testing_conf || server_state_foreground) - fprintf(stderr, "%s\n", buf); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); - return; - } - return; + if(access(dirname, F_OK) == -1) { + rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - parent directory %s does not exist", filename, dirname); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + return; + } + + if(access(filename, F_OK) == -1) { + if(access(dirname, W_OK) == -1) { + rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - access to parent directory %s failed: %s", + filename, dirname, strerror(errno)); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + } + return; + } + + if(access(filename, W_OK) == -1) { + rb_snprintf(buf, sizeof(buf), "WARNING: Access denied for logfile %s: %s", filename, strerror(errno)); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + return; + } + return; } void init_main_logfile(void) { - verify_logfile_access(logFileName); - if(log_main == NULL) - { - log_main = fopen(logFileName, "a"); - } + verify_logfile_access(logFileName); + if(log_main == NULL) { + log_main = fopen(logFileName, "a"); + } } void open_logfiles(void) { - int i; + int i; - close_logfiles(); + close_logfiles(); - log_main = fopen(logFileName, "a"); + log_main = fopen(logFileName, "a"); - /* log_main is handled above, so just do the rest */ - for(i = 1; i < LAST_LOGFILE; i++) - { - /* reopen those with paths */ - if(!EmptyString(*log_table[i].name)) - { - verify_logfile_access(*log_table[i].name); - *log_table[i].logfile = fopen(*log_table[i].name, "a"); - } - } -} + /* log_main is handled above, so just do the rest */ + for(i = 1; i < LAST_LOGFILE; i++) { + /* reopen those with paths */ + if(!EmptyString(*log_table[i].name)) { + verify_logfile_access(*log_table[i].name); + *log_table[i].logfile = fopen(*log_table[i].name, "a"); + } + } +} void close_logfiles(void) { - int i; + int i; - if(log_main != NULL) - fclose(log_main); + if(log_main != NULL) + fclose(log_main); - /* log_main is handled above, so just do the rest */ - for(i = 1; i < LAST_LOGFILE; i++) - { - if(*log_table[i].logfile != NULL) - { - fclose(*log_table[i].logfile); - *log_table[i].logfile = NULL; - } - } + /* log_main is handled above, so just do the rest */ + for(i = 1; i < LAST_LOGFILE; i++) { + if(*log_table[i].logfile != NULL) { + fclose(*log_table[i].logfile); + *log_table[i].logfile = NULL; + } + } } void ilog(ilogfile dest, const char *format, ...) { - FILE *logfile = *log_table[dest].logfile; - char buf[BUFSIZE]; - char buf2[BUFSIZE]; - va_list args; + FILE *logfile = *log_table[dest].logfile; + char buf[BUFSIZE]; + char buf2[BUFSIZE]; + va_list args; - if(logfile == NULL) - return; + if(logfile == NULL) + return; - va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); - va_end(args); + va_start(args, format); + rb_vsnprintf(buf, sizeof(buf), format, args); + va_end(args); - rb_snprintf(buf2, sizeof(buf2), "%s %s\n", - smalldate(rb_current_time()), buf); + rb_snprintf(buf2, sizeof(buf2), "%s %s\n", + smalldate(rb_current_time()), buf); - if(fputs(buf2, logfile) < 0) - { - fclose(logfile); - *log_table[dest].logfile = NULL; - return; - } + if(fputs(buf2, logfile) < 0) { + fclose(logfile); + *log_table[dest].logfile = NULL; + return; + } - fflush(logfile); + fflush(logfile); } static void _iprint(const char *domain, const char *buf) { - if (domain == NULL || buf == NULL) - return; + if (domain == NULL || buf == NULL) + return; - fprintf(stderr, "%8s: %s\n", domain, buf); + fprintf(stderr, "%8s: %s\n", domain, buf); } void inotice(const char *format, ...) { - char buf[BUFSIZE]; - va_list args; + char buf[BUFSIZE]; + va_list args; - va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); - va_end(args); + va_start(args, format); + rb_vsnprintf(buf, sizeof(buf), format, args); + va_end(args); - _iprint("notice", buf); + _iprint("notice", buf); - ilog(L_MAIN, "%s", buf); + ilog(L_MAIN, "%s", buf); } void iwarn(const char *format, ...) { - char buf[BUFSIZE]; - va_list args; + char buf[BUFSIZE]; + va_list args; - va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); - va_end(args); + va_start(args, format); + rb_vsnprintf(buf, sizeof(buf), format, args); + va_end(args); - _iprint("warning", buf); + _iprint("warning", buf); - ilog(L_MAIN, "%s", buf); + ilog(L_MAIN, "%s", buf); } void ierror(const char *format, ...) { - char buf[BUFSIZE]; - va_list args; + char buf[BUFSIZE]; + va_list args; - va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); - va_end(args); + va_start(args, format); + rb_vsnprintf(buf, sizeof(buf), format, args); + va_end(args); - _iprint("error", buf); + _iprint("error", buf); - ilog(L_MAIN, "%s", buf); + ilog(L_MAIN, "%s", buf); } void report_operspy(struct Client *source_p, const char *token, const char *arg) { - /* if its not my client its already propagated */ - if(MyClient(source_p)) - sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, - "ENCAP * OPERSPY %s %s", - token, arg ? arg : ""); + /* if its not my client its already propagated */ + if(MyClient(source_p)) + sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, + "ENCAP * OPERSPY %s %s", + token, arg ? arg : ""); - sendto_realops_snomask(SNO_OPERSPY, - ConfigFileEntry.operspy_admin_only ? L_ADMIN : L_ALL, - "OPERSPY %s %s %s", - get_oper_name(source_p), token, - arg ? arg : ""); + sendto_realops_snomask(SNO_OPERSPY, + ConfigFileEntry.operspy_admin_only ? L_ADMIN : L_ALL, + "OPERSPY %s %s %s", + get_oper_name(source_p), token, + arg ? arg : ""); - ilog(L_OPERSPY, "OPERSPY %s %s %s", - get_oper_name(source_p), token, arg ? arg : ""); + ilog(L_OPERSPY, "OPERSPY %s %s %s", + get_oper_name(source_p), token, arg ? arg : ""); } const char * smalldate(time_t ltime) { - static char buf[MAX_DATE_STRING]; - struct tm *lt; + static char buf[MAX_DATE_STRING]; + struct tm *lt; - lt = localtime(<ime); + lt = localtime(<ime); - rb_snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", - lt->tm_year + 1900, lt->tm_mon + 1, - lt->tm_mday, lt->tm_hour, lt->tm_min); + rb_snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", + lt->tm_year + 1900, lt->tm_mon + 1, + lt->tm_mday, lt->tm_hour, lt->tm_min); - return buf; + return buf; } void ilog_error(const char *error) { - ilog(L_IOERROR, "%s: %d (%s)", error, errno, strerror(errno)); + ilog(L_IOERROR, "%s: %d (%s)", error, errno, strerror(errno)); - sendto_realops_snomask(SNO_DEBUG, L_ALL, "%s: %d (%s)", error, errno, strerror(errno)); + sendto_realops_snomask(SNO_DEBUG, L_ALL, "%s: %d (%s)", error, errno, strerror(errno)); } diff --git a/src/match.c b/src/match.c index 2d7dae6..85a3498 100644 --- a/src/match.c +++ b/src/match.c @@ -47,61 +47,54 @@ */ int match(const char *mask, const char *name) { - const char *m = mask, *n = name; - const char *m_tmp = mask, *n_tmp = name; - int star_p; + const char *m = mask, *n = name; + const char *m_tmp = mask, *n_tmp = name; + int star_p; - s_assert(mask != NULL); - s_assert(name != NULL); + s_assert(mask != NULL); + s_assert(name != NULL); - for (;;) - { - switch (*m) - { - case '\0': - if (!*n) - return 1; - backtrack: - if (m_tmp == mask) - return 0; - m = m_tmp; - n = ++n_tmp; - break; - case '*': - case '?': - for (star_p = 0;; m++) - { - if (*m == '*') - star_p = 1; - else if (*m == '?') - { - if (!*n++) - goto backtrack; - } - else - break; - } - if (star_p) - { - if (!*m) - return 1; - else - { - m_tmp = m; - for (n_tmp = n; *n && ToLower(*n) != ToLower(*m); n++); - } - } - /* and fall through */ - default: - if (!*n) - return (*m != '\0' ? 0 : 1); - if (ToLower(*m) != ToLower(*n)) - goto backtrack; - m++; - n++; - break; - } - } + for (;;) { + switch (*m) { + case '\0': + if (!*n) + return 1; +backtrack: + if (m_tmp == mask) + return 0; + m = m_tmp; + n = ++n_tmp; + break; + case '*': + case '?': + for (star_p = 0;; m++) { + if (*m == '*') + star_p = 1; + else if (*m == '?') { + if (!*n++) + goto backtrack; + } else + break; + } + if (star_p) { + if (!*m) + return 1; + else { + m_tmp = m; + for (n_tmp = n; *n && ToLower(*n) != ToLower(*m); n++); + } + } + /* and fall through */ + default: + if (!*n) + return (*m != '\0' ? 0 : 1); + if (ToLower(*m) != ToLower(*n)) + goto backtrack; + m++; + n++; + break; + } + } } /** Check a mask against a mask. @@ -117,63 +110,56 @@ int match(const char *mask, const char *name) */ int mask_match(const char *mask, const char *name) { - const char *m = mask, *n = name; - const char *m_tmp = mask, *n_tmp = name; - int star_p; + const char *m = mask, *n = name; + const char *m_tmp = mask, *n_tmp = name; + int star_p; - s_assert(mask != NULL); - s_assert(name != NULL); + s_assert(mask != NULL); + s_assert(name != NULL); - for (;;) - { - switch (*m) - { - case '\0': - if (!*n) - return 1; - backtrack: - if (m_tmp == mask) - return 0; - m = m_tmp; - n = ++n_tmp; - break; - case '*': - case '?': - for (star_p = 0;; m++) - { - if (*m == '*') - star_p = 1; - else if (*m == '?') - { - /* changed for mask_match() */ - if (*n == '*' || !*n) - goto backtrack; - n++; - } - else - break; - } - if (star_p) - { - if (!*m) - return 1; - else - { - m_tmp = m; - for (n_tmp = n; *n && ToLower(*n) != ToLower(*m); n++); - } - } - /* and fall through */ - default: - if (!*n) - return (*m != '\0' ? 0 : 1); - if (ToLower(*m) != ToLower(*n)) - goto backtrack; - m++; - n++; - break; - } - } + for (;;) { + switch (*m) { + case '\0': + if (!*n) + return 1; +backtrack: + if (m_tmp == mask) + return 0; + m = m_tmp; + n = ++n_tmp; + break; + case '*': + case '?': + for (star_p = 0;; m++) { + if (*m == '*') + star_p = 1; + else if (*m == '?') { + /* changed for mask_match() */ + if (*n == '*' || !*n) + goto backtrack; + n++; + } else + break; + } + if (star_p) { + if (!*m) + return 1; + else { + m_tmp = m; + for (n_tmp = n; *n && ToLower(*n) != ToLower(*m); n++); + } + } + /* and fall through */ + default: + if (!*n) + return (*m != '\0' ? 0 : 1); + if (ToLower(*m) != ToLower(*n)) + goto backtrack; + m++; + n++; + break; + } + } } @@ -186,7 +172,7 @@ int mask_match(const char *mask, const char *name) * is a number; '@' means match exactly one character that is a * letter; '\s' means match a space. * - * This function supports escaping, so that a wildcard may be matched + * This function supports escaping, so that a wildcard may be matched * exactly. * * @param[in] mask Wildcard-containing mask. @@ -196,151 +182,137 @@ int mask_match(const char *mask, const char *name) int match_esc(const char *mask, const char *name) { - const unsigned char *m = (const unsigned char *)mask; - const unsigned char *n = (const unsigned char *)name; - const unsigned char *ma = (const unsigned char *)mask; - const unsigned char *na = (const unsigned char *)name; - int wild = 0; - int calls = 0; - int quote = 0; - int match1 = 0; + const unsigned char *m = (const unsigned char *)mask; + const unsigned char *n = (const unsigned char *)name; + const unsigned char *ma = (const unsigned char *)mask; + const unsigned char *na = (const unsigned char *)name; + int wild = 0; + int calls = 0; + int quote = 0; + int match1 = 0; - s_assert(mask != NULL); - s_assert(name != NULL); + s_assert(mask != NULL); + s_assert(name != NULL); - if(!mask || !name) - return 0; + if(!mask || !name) + return 0; - /* if the mask is "*", it matches everything */ - if((*m == '*') && (*(m + 1) == '\0')) - return 1; + /* if the mask is "*", it matches everything */ + if((*m == '*') && (*(m + 1) == '\0')) + return 1; - while(calls++ < MATCH_MAX_CALLS) - { - if(quote) - quote++; - if(quote == 3) - quote = 0; - if(*m == '\\' && !quote) - { - m++; - quote = 1; - continue; - } - if(!quote && *m == '*') - { - /* - * XXX - shouldn't need to spin here, the mask should have been - * collapsed before match is called - */ - while(*m == '*') - m++; + while(calls++ < MATCH_MAX_CALLS) { + if(quote) + quote++; + if(quote == 3) + quote = 0; + if(*m == '\\' && !quote) { + m++; + quote = 1; + continue; + } + if(!quote && *m == '*') { + /* + * XXX - shouldn't need to spin here, the mask should have been + * collapsed before match is called + */ + while(*m == '*') + m++; - wild = 1; - ma = m; - na = n; + wild = 1; + ma = m; + na = n; - if(*m == '\\') - { - m++; - /* This means it is an invalid mask -A1kmm. */ - if(!*m) - return 0; - quote++; - continue; - } - } + if(*m == '\\') { + m++; + /* This means it is an invalid mask -A1kmm. */ + if(!*m) + return 0; + quote++; + continue; + } + } - if(!*m) - { - if(!*n) - return 1; - if(quote) - return 0; - for(m--; (m > (const unsigned char *)mask) && (*m == '?'); m--);; + if(!*m) { + if(!*n) + return 1; + if(quote) + return 0; + for(m--; (m > (const unsigned char *)mask) && (*m == '?'); m--);; - if(*m == '*' && (m > (const unsigned char *)mask)) - return 1; - if(!wild) - return 0; - m = ma; - n = ++na; - } - else if(!*n) - { - /* - * XXX - shouldn't need to spin here, the mask should have been - * collapsed before match is called - */ - if(quote) - return 0; - while(*m == '*') - m++; - return (*m == 0); - } + if(*m == '*' && (m > (const unsigned char *)mask)) + return 1; + if(!wild) + return 0; + m = ma; + n = ++na; + } else if(!*n) { + /* + * XXX - shouldn't need to spin here, the mask should have been + * collapsed before match is called + */ + if(quote) + return 0; + while(*m == '*') + m++; + return (*m == 0); + } - if(quote) - match1 = *m == 's' ? *n == ' ' : ToLower(*m) == ToLower(*n); - else if(*m == '?') - match1 = 1; - else if(*m == '@') - match1 = IsLetter(*n); - else if(*m == '#') - match1 = IsDigit(*n); - else - match1 = ToLower(*m) == ToLower(*n); - if(match1) - { - if(*m) - m++; - if(*n) - n++; - } - else - { - if(!wild) - return 0; - m = ma; - n = ++na; - } - } - return 0; + if(quote) + match1 = *m == 's' ? *n == ' ' : ToLower(*m) == ToLower(*n); + else if(*m == '?') + match1 = 1; + else if(*m == '@') + match1 = IsLetter(*n); + else if(*m == '#') + match1 = IsDigit(*n); + else + match1 = ToLower(*m) == ToLower(*n); + if(match1) { + if(*m) + m++; + if(*n) + n++; + } else { + if(!wild) + return 0; + m = ma; + n = ++na; + } + } + return 0; } int comp_with_mask(void *addr, void *dest, u_int mask) { - if (memcmp(addr, dest, mask / 8) == 0) - { - int n = mask / 8; - int m = ((-1) << (8 - (mask % 8))); - if (mask % 8 == 0 || (((u_char *) addr)[n] & m) == (((u_char *) dest)[n] & m)) - { - return (1); - } - } - return (0); + if (memcmp(addr, dest, mask / 8) == 0) { + int n = mask / 8; + int m = ((-1) << (8 - (mask % 8))); + if (mask % 8 == 0 || (((u_char *) addr)[n] & m) == (((u_char *) dest)[n] & m)) { + return (1); + } + } + return (0); } int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, u_int mask) { - void *iaddr = NULL; - void *idest = NULL; + void *iaddr = NULL; + void *idest = NULL; - if (addr->sa_family == AF_INET) - { - iaddr = &((struct sockaddr_in *)addr)->sin_addr; - idest = &((struct sockaddr_in *)dest)->sin_addr; - } + if (addr->sa_family == AF_INET) { + iaddr = &((struct sockaddr_in *)addr)->sin_addr; + idest = &((struct sockaddr_in *)dest)->sin_addr; + } #ifdef RB_IPV6 - else - { - iaddr = &((struct sockaddr_in6 *)addr)->sin6_addr; - idest = &((struct sockaddr_in6 *)dest)->sin6_addr; + else { + iaddr = &((struct sockaddr_in6 *)addr)->sin6_addr; + idest = &((struct sockaddr_in6 *)dest)->sin6_addr; - } + } #endif - return (comp_with_mask(iaddr, idest, mask)); + return (comp_with_mask(iaddr, idest, mask)); } /* @@ -350,50 +322,46 @@ int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, u_int mask */ int match_ips(const char *s1, const char *s2) { - struct rb_sockaddr_storage ipaddr, maskaddr; - char mask[BUFSIZE]; - char address[HOSTLEN + 1]; - char *len; - void *ipptr, *maskptr; - int cidrlen, aftype; + struct rb_sockaddr_storage ipaddr, maskaddr; + char mask[BUFSIZE]; + char address[HOSTLEN + 1]; + char *len; + void *ipptr, *maskptr; + int cidrlen, aftype; - strcpy(mask, s1); - strcpy(address, s2); + strcpy(mask, s1); + strcpy(address, s2); - len = strrchr(mask, '/'); - if (len == NULL) - return 0; + len = strrchr(mask, '/'); + if (len == NULL) + return 0; - *len++ = '\0'; + *len++ = '\0'; - cidrlen = atoi(len); - if (cidrlen == 0) - return 0; + cidrlen = atoi(len); + if (cidrlen == 0) + return 0; #ifdef RB_IPV6 - if (strchr(mask, ':') && strchr(address, ':')) - { - aftype = AF_INET6; - ipptr = &((struct sockaddr_in6 *)&ipaddr)->sin6_addr; - maskptr = &((struct sockaddr_in6 *)&maskaddr)->sin6_addr; - } - else + if (strchr(mask, ':') && strchr(address, ':')) { + aftype = AF_INET6; + ipptr = &((struct sockaddr_in6 *)&ipaddr)->sin6_addr; + maskptr = &((struct sockaddr_in6 *)&maskaddr)->sin6_addr; + } else #endif - if (!strchr(mask, ':') && !strchr(address, ':')) - { - aftype = AF_INET; - ipptr = &((struct sockaddr_in *)&ipaddr)->sin_addr; - maskptr = &((struct sockaddr_in *)&maskaddr)->sin_addr; - } - else - return 0; + if (!strchr(mask, ':') && !strchr(address, ':')) { + aftype = AF_INET; + ipptr = &((struct sockaddr_in *)&ipaddr)->sin_addr; + maskptr = &((struct sockaddr_in *)&maskaddr)->sin_addr; + } else + return 0; - rb_inet_pton(aftype, address, ipptr); - rb_inet_pton(aftype, mask, maskptr); - if (comp_with_mask(ipptr, maskptr, cidrlen)) - return 1; - else - return 0; + rb_inet_pton(aftype, address, ipptr); + rb_inet_pton(aftype, mask, maskptr); + if (comp_with_mask(ipptr, maskptr, cidrlen)) + return 1; + else + return 0; } /* match_cidr() @@ -404,64 +372,60 @@ int match_ips(const char *s1, const char *s2) int match_cidr(const char *s1, const char *s2) { - struct rb_sockaddr_storage ipaddr, maskaddr; - char mask[BUFSIZE]; - char address[NICKLEN + USERLEN + HOSTLEN + 6]; - char *ipmask; - char *ip; - char *len; - void *ipptr, *maskptr; - int cidrlen, aftype; + struct rb_sockaddr_storage ipaddr, maskaddr; + char mask[BUFSIZE]; + char address[NICKLEN + USERLEN + HOSTLEN + 6]; + char *ipmask; + char *ip; + char *len; + void *ipptr, *maskptr; + int cidrlen, aftype; - strcpy(mask, s1); - strcpy(address, s2); + strcpy(mask, s1); + strcpy(address, s2); - ipmask = strrchr(mask, '@'); - if (ipmask == NULL) - return 0; + ipmask = strrchr(mask, '@'); + if (ipmask == NULL) + return 0; - *ipmask++ = '\0'; + *ipmask++ = '\0'; - ip = strrchr(address, '@'); - if (ip == NULL) - return 0; - *ip++ = '\0'; + ip = strrchr(address, '@'); + if (ip == NULL) + return 0; + *ip++ = '\0'; - len = strrchr(ipmask, '/'); - if (len == NULL) - return 0; + len = strrchr(ipmask, '/'); + if (len == NULL) + return 0; - *len++ = '\0'; + *len++ = '\0'; - cidrlen = atoi(len); - if (cidrlen == 0) - return 0; + cidrlen = atoi(len); + if (cidrlen == 0) + return 0; #ifdef RB_IPV6 - if (strchr(ip, ':') && strchr(ipmask, ':')) - { - aftype = AF_INET6; - ipptr = &((struct sockaddr_in6 *)&ipaddr)->sin6_addr; - maskptr = &((struct sockaddr_in6 *)&maskaddr)->sin6_addr; - } - else + if (strchr(ip, ':') && strchr(ipmask, ':')) { + aftype = AF_INET6; + ipptr = &((struct sockaddr_in6 *)&ipaddr)->sin6_addr; + maskptr = &((struct sockaddr_in6 *)&maskaddr)->sin6_addr; + } else #endif - if (!strchr(ip, ':') && !strchr(ipmask, ':')) - { - aftype = AF_INET; - ipptr = &((struct sockaddr_in *)&ipaddr)->sin_addr; - maskptr = &((struct sockaddr_in *)&maskaddr)->sin_addr; - } - else - return 0; + if (!strchr(ip, ':') && !strchr(ipmask, ':')) { + aftype = AF_INET; + ipptr = &((struct sockaddr_in *)&ipaddr)->sin_addr; + maskptr = &((struct sockaddr_in *)&maskaddr)->sin_addr; + } else + return 0; - rb_inet_pton(aftype, ip, ipptr); - rb_inet_pton(aftype, ipmask, maskptr); - if (comp_with_mask(ipptr, maskptr, cidrlen) && match(mask, address)) - return 1; - else - return 0; + rb_inet_pton(aftype, ip, ipptr); + rb_inet_pton(aftype, ipmask, maskptr); + if (comp_with_mask(ipptr, maskptr, cidrlen) && match(mask, address)) + return 1; + else + return 0; } /* collapse() @@ -470,30 +434,26 @@ int match_cidr(const char *s1, const char *s2) */ char *collapse(char *pattern) { - char *p = pattern, *po = pattern; - char c; - int f = 0; + char *p = pattern, *po = pattern; + char c; + int f = 0; - if (p == NULL) - return NULL; + if (p == NULL) + return NULL; - while ((c = *p++)) - { - if (c == '*') - { - if (!(f & 1)) - *po++ = '*'; - f |= 1; - } - else - { - *po++ = c; - f &= ~1; - } - } - *po++ = 0; + while ((c = *p++)) { + if (c == '*') { + if (!(f & 1)) + *po++ = '*'; + f |= 1; + } else { + *po++ = c; + f &= ~1; + } + } + *po++ = 0; - return pattern; + return pattern; } /* collapse_esc() @@ -502,34 +462,28 @@ char *collapse(char *pattern) */ char *collapse_esc(char *pattern) { - char *p = pattern, *po = pattern; - char c; - int f = 0; + char *p = pattern, *po = pattern; + char c; + int f = 0; - if (p == NULL) - return NULL; + if (p == NULL) + return NULL; - while ((c = *p++)) - { - if (!(f & 2) && c == '*') - { - if (!(f & 1)) - *po++ = '*'; - f |= 1; - } - else if (!(f & 2) && c == '\\') - { - *po++ = '\\'; - f |= 2; - } - else - { - *po++ = c; - f &= ~3; - } - } - *po++ = 0; - return pattern; + while ((c = *p++)) { + if (!(f & 2) && c == '*') { + if (!(f & 1)) + *po++ = '*'; + f |= 1; + } else if (!(f & 2) && c == '\\') { + *po++ = '\\'; + f |= 2; + } else { + *po++ = c; + f &= ~3; + } + } + *po++ = 0; + return pattern; } /* @@ -541,110 +495,108 @@ char *collapse_esc(char *pattern) */ int irccmp(const char *s1, const char *s2) { - const unsigned char *str1 = (const unsigned char *)s1; - const unsigned char *str2 = (const unsigned char *)s2; - int res; + const unsigned char *str1 = (const unsigned char *)s1; + const unsigned char *str2 = (const unsigned char *)s2; + int res; - s_assert(s1 != NULL); - s_assert(s2 != NULL); + s_assert(s1 != NULL); + s_assert(s2 != NULL); - while ((res = ToUpper(*str1) - ToUpper(*str2)) == 0) - { - if (*str1 == '\0') - return 0; - str1++; - str2++; - } - return (res); + while ((res = ToUpper(*str1) - ToUpper(*str2)) == 0) { + if (*str1 == '\0') + return 0; + str1++; + str2++; + } + return (res); } int ircncmp(const char *s1, const char *s2, int n) { - const unsigned char *str1 = (const unsigned char *)s1; - const unsigned char *str2 = (const unsigned char *)s2; - int res; - s_assert(s1 != NULL); - s_assert(s2 != NULL); + const unsigned char *str1 = (const unsigned char *)s1; + const unsigned char *str2 = (const unsigned char *)s2; + int res; + s_assert(s1 != NULL); + s_assert(s2 != NULL); - while ((res = ToUpper(*str1) - ToUpper(*str2)) == 0) - { - str1++; - str2++; - n--; - if (n == 0 || (*str1 == '\0' && *str2 == '\0')) - return 0; - } - return (res); + while ((res = ToUpper(*str1) - ToUpper(*str2)) == 0) { + str1++; + str2++; + n--; + if (n == 0 || (*str1 == '\0' && *str2 == '\0')) + return 0; + } + return (res); } const unsigned char ToLowerTab[] = { - 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, - 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, - 0x1e, 0x1f, - ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')', - '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - ':', ';', '<', '=', '>', '?', - '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', - 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', - 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', - '_', - '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', - 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', - 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', - 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, - 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, - 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, - 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, - 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, - 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, - 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff + 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, + 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, + 0x1e, 0x1f, + ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')', + '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + ':', ';', '<', '=', '>', '?', + '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', + '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', + 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, + 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, + 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, + 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, + 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, + 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; const unsigned char ToUpperTab[] = { - 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, - 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, - 0x1e, 0x1f, - ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')', - '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - ':', ';', '<', '=', '>', '?', - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', - 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', - 0x5f, - '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', - 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', - 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, - 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, - 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, - 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, - 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, - 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, - 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff + 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, + 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, + 0x1e, 0x1f, + ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')', + '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + ':', ';', '<', '=', '>', '?', + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', + 0x5f, + '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', + 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, + 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, + 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, + 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, + 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, + 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; /* @@ -654,260 +606,260 @@ const unsigned char ToUpperTab[] = { * for channel names */ const unsigned int CharAttrs[] = { -/* 0 */ CNTRL_C, -/* 1 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 2 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, -/* 3 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, -/* 4 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 5 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 6 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 7 BEL */ CNTRL_C | NONEOS_C, -/* 8 \b */ CNTRL_C | CHAN_C | NONEOS_C, -/* 9 \t */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C, -/* 10 \n */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C | EOL_C, -/* 11 \v */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C, -/* 12 \f */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C, -/* 13 \r */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C | EOL_C, -/* 14 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 15 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 16 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 17 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 18 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 19 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 20 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 21 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 22 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, -/* 23 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 24 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 25 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 26 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 27 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 28 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 29 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, -/* 30 */ CNTRL_C | CHAN_C | NONEOS_C, -/* 31 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, -/* SP */ PRINT_C | SPACE_C, -/* ! */ PRINT_C | KWILD_C | CHAN_C | NONEOS_C, -/* " */ PRINT_C | CHAN_C | NONEOS_C, -/* # */ PRINT_C | MWILD_C | CHANPFX_C | CHAN_C | NONEOS_C, -/* $ */ PRINT_C | CHAN_C | NONEOS_C | USER_C, -/* % */ PRINT_C | CHAN_C | NONEOS_C, -/* & */ PRINT_C | CHANPFX_C | CHAN_C | NONEOS_C, -/* ' */ PRINT_C | CHAN_C | NONEOS_C, -/* ( */ PRINT_C | CHAN_C | NONEOS_C, -/* ) */ PRINT_C | CHAN_C | NONEOS_C, -/* * */ PRINT_C | KWILD_C | MWILD_C | CHAN_C | NONEOS_C, -/* + */ PRINT_C | CHAN_C | NONEOS_C, -/* , */ PRINT_C | NONEOS_C, -/* - */ PRINT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* . */ PRINT_C | KWILD_C | CHAN_C | NONEOS_C | USER_C | HOST_C | SERV_C, -/* / */ PRINT_C | CHAN_C | NONEOS_C | HOST_C, -/* 0 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 1 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 2 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 3 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 4 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 5 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 6 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 7 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 8 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* 9 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* : */ PRINT_C | CHAN_C | NONEOS_C | HOST_C, -/* ; */ PRINT_C | CHAN_C | NONEOS_C, -/* < */ PRINT_C | CHAN_C | NONEOS_C, -/* = */ PRINT_C | CHAN_C | NONEOS_C, -/* > */ PRINT_C | CHAN_C | NONEOS_C, -/* ? */ PRINT_C | KWILD_C | MWILD_C | CHAN_C | NONEOS_C, -/* @ */ PRINT_C | KWILD_C | MWILD_C | CHAN_C | NONEOS_C, -/* A */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* B */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* C */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* D */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* E */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* F */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* G */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* H */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* I */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* J */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* K */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* L */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* M */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* N */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* O */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* P */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* Q */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* R */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* S */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* T */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* U */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* V */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* W */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* X */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* Y */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* Z */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* [ */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* \ */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* ] */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* ^ */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* _ */ PRINT_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* ` */ PRINT_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* a */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* b */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* c */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* d */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* e */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* f */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* g */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* h */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* i */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* j */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* k */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* l */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* m */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* n */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* o */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* p */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* q */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* r */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* s */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* t */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* u */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* v */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* w */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* x */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* y */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* z */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, -/* { */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* | */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* } */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, -/* ~ */ PRINT_C | ALPHA_C | CHAN_C | NONEOS_C | USER_C, -/* del */ CHAN_C | NONEOS_C, -/* 0x80 */ CHAN_C | NONEOS_C, -/* 0x81 */ CHAN_C | NONEOS_C, -/* 0x82 */ CHAN_C | NONEOS_C, -/* 0x83 */ CHAN_C | NONEOS_C, -/* 0x84 */ CHAN_C | NONEOS_C, -/* 0x85 */ CHAN_C | NONEOS_C, -/* 0x86 */ CHAN_C | NONEOS_C, -/* 0x87 */ CHAN_C | NONEOS_C, -/* 0x88 */ CHAN_C | NONEOS_C, -/* 0x89 */ CHAN_C | NONEOS_C, -/* 0x8A */ CHAN_C | NONEOS_C, -/* 0x8B */ CHAN_C | NONEOS_C, -/* 0x8C */ CHAN_C | NONEOS_C, -/* 0x8D */ CHAN_C | NONEOS_C, -/* 0x8E */ CHAN_C | NONEOS_C, -/* 0x8F */ CHAN_C | NONEOS_C, -/* 0x90 */ CHAN_C | NONEOS_C, -/* 0x91 */ CHAN_C | NONEOS_C, -/* 0x92 */ CHAN_C | NONEOS_C, -/* 0x93 */ CHAN_C | NONEOS_C, -/* 0x94 */ CHAN_C | NONEOS_C, -/* 0x95 */ CHAN_C | NONEOS_C, -/* 0x96 */ CHAN_C | NONEOS_C, -/* 0x97 */ CHAN_C | NONEOS_C, -/* 0x98 */ CHAN_C | NONEOS_C, -/* 0x99 */ CHAN_C | NONEOS_C, -/* 0x9A */ CHAN_C | NONEOS_C, -/* 0x9B */ CHAN_C | NONEOS_C, -/* 0x9C */ CHAN_C | NONEOS_C, -/* 0x9D */ CHAN_C | NONEOS_C, -/* 0x9E */ CHAN_C | NONEOS_C, -/* 0x9F */ CHAN_C | NONEOS_C, -/* 0xA0 */ CHAN_C | FCHAN_C | NONEOS_C, -/* 0xA1 */ CHAN_C | NONEOS_C, -/* 0xA2 */ CHAN_C | NONEOS_C, -/* 0xA3 */ CHAN_C | NONEOS_C, -/* 0xA4 */ CHAN_C | NONEOS_C, -/* 0xA5 */ CHAN_C | NONEOS_C, -/* 0xA6 */ CHAN_C | NONEOS_C, -/* 0xA7 */ CHAN_C | NONEOS_C, -/* 0xA8 */ CHAN_C | NONEOS_C, -/* 0xA9 */ CHAN_C | NONEOS_C, -/* 0xAA */ CHAN_C | NONEOS_C, -/* 0xAB */ CHAN_C | NONEOS_C, -/* 0xAC */ CHAN_C | NONEOS_C, -/* 0xAD */ CHAN_C | NONEOS_C, -/* 0xAE */ CHAN_C | NONEOS_C, -/* 0xAF */ CHAN_C | NONEOS_C, -/* 0xB0 */ CHAN_C | NONEOS_C, -/* 0xB1 */ CHAN_C | NONEOS_C, -/* 0xB2 */ CHAN_C | NONEOS_C, -/* 0xB3 */ CHAN_C | NONEOS_C, -/* 0xB4 */ CHAN_C | NONEOS_C, -/* 0xB5 */ CHAN_C | NONEOS_C, -/* 0xB6 */ CHAN_C | NONEOS_C, -/* 0xB7 */ CHAN_C | NONEOS_C, -/* 0xB8 */ CHAN_C | NONEOS_C, -/* 0xB9 */ CHAN_C | NONEOS_C, -/* 0xBA */ CHAN_C | NONEOS_C, -/* 0xBB */ CHAN_C | NONEOS_C, -/* 0xBC */ CHAN_C | NONEOS_C, -/* 0xBD */ CHAN_C | NONEOS_C, -/* 0xBE */ CHAN_C | NONEOS_C, -/* 0xBF */ CHAN_C | NONEOS_C, -/* 0xC0 */ CHAN_C | NONEOS_C, -/* 0xC1 */ CHAN_C | NONEOS_C, -/* 0xC2 */ CHAN_C | NONEOS_C, -/* 0xC3 */ CHAN_C | NONEOS_C, -/* 0xC4 */ CHAN_C | NONEOS_C, -/* 0xC5 */ CHAN_C | NONEOS_C, -/* 0xC6 */ CHAN_C | NONEOS_C, -/* 0xC7 */ CHAN_C | NONEOS_C, -/* 0xC8 */ CHAN_C | NONEOS_C, -/* 0xC9 */ CHAN_C | NONEOS_C, -/* 0xCA */ CHAN_C | NONEOS_C, -/* 0xCB */ CHAN_C | NONEOS_C, -/* 0xCC */ CHAN_C | NONEOS_C, -/* 0xCD */ CHAN_C | NONEOS_C, -/* 0xCE */ CHAN_C | NONEOS_C, -/* 0xCF */ CHAN_C | NONEOS_C, -/* 0xD0 */ CHAN_C | NONEOS_C, -/* 0xD1 */ CHAN_C | NONEOS_C, -/* 0xD2 */ CHAN_C | NONEOS_C, -/* 0xD3 */ CHAN_C | NONEOS_C, -/* 0xD4 */ CHAN_C | NONEOS_C, -/* 0xD5 */ CHAN_C | NONEOS_C, -/* 0xD6 */ CHAN_C | NONEOS_C, -/* 0xD7 */ CHAN_C | NONEOS_C, -/* 0xD8 */ CHAN_C | NONEOS_C, -/* 0xD9 */ CHAN_C | NONEOS_C, -/* 0xDA */ CHAN_C | NONEOS_C, -/* 0xDB */ CHAN_C | NONEOS_C, -/* 0xDC */ CHAN_C | NONEOS_C, -/* 0xDD */ CHAN_C | NONEOS_C, -/* 0xDE */ CHAN_C | NONEOS_C, -/* 0xDF */ CHAN_C | NONEOS_C, -/* 0xE0 */ CHAN_C | NONEOS_C, -/* 0xE1 */ CHAN_C | NONEOS_C, -/* 0xE2 */ CHAN_C | NONEOS_C, -/* 0xE3 */ CHAN_C | NONEOS_C, -/* 0xE4 */ CHAN_C | NONEOS_C, -/* 0xE5 */ CHAN_C | NONEOS_C, -/* 0xE6 */ CHAN_C | NONEOS_C, -/* 0xE7 */ CHAN_C | NONEOS_C, -/* 0xE8 */ CHAN_C | NONEOS_C, -/* 0xE9 */ CHAN_C | NONEOS_C, -/* 0xEA */ CHAN_C | NONEOS_C, -/* 0xEB */ CHAN_C | NONEOS_C, -/* 0xEC */ CHAN_C | NONEOS_C, -/* 0xED */ CHAN_C | NONEOS_C, -/* 0xEE */ CHAN_C | NONEOS_C, -/* 0xEF */ CHAN_C | NONEOS_C, -/* 0xF0 */ CHAN_C | NONEOS_C, -/* 0xF1 */ CHAN_C | NONEOS_C, -/* 0xF2 */ CHAN_C | NONEOS_C, -/* 0xF3 */ CHAN_C | NONEOS_C, -/* 0xF4 */ CHAN_C | NONEOS_C, -/* 0xF5 */ CHAN_C | NONEOS_C, -/* 0xF6 */ CHAN_C | NONEOS_C, -/* 0xF7 */ CHAN_C | NONEOS_C, -/* 0xF8 */ CHAN_C | NONEOS_C, -/* 0xF9 */ CHAN_C | NONEOS_C, -/* 0xFA */ CHAN_C | NONEOS_C, -/* 0xFB */ CHAN_C | NONEOS_C, -/* 0xFC */ CHAN_C | NONEOS_C, -/* 0xFD */ CHAN_C | NONEOS_C, -/* 0xFE */ CHAN_C | NONEOS_C, -/* 0xFF */ CHAN_C | NONEOS_C + /* 0 */ CNTRL_C, + /* 1 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 2 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, + /* 3 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, + /* 4 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 5 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 6 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 7 BEL */ CNTRL_C | NONEOS_C, + /* 8 \b */ CNTRL_C | CHAN_C | NONEOS_C, + /* 9 \t */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C, + /* 10 \n */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C | EOL_C, + /* 11 \v */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C, + /* 12 \f */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C, + /* 13 \r */ CNTRL_C | SPACE_C | CHAN_C | NONEOS_C | EOL_C, + /* 14 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 15 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 16 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 17 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 18 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 19 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 20 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 21 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 22 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, + /* 23 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 24 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 25 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 26 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 27 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 28 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 29 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, + /* 30 */ CNTRL_C | CHAN_C | NONEOS_C, + /* 31 */ CNTRL_C | CHAN_C | FCHAN_C | NONEOS_C, + /* SP */ PRINT_C | SPACE_C, + /* ! */ PRINT_C | KWILD_C | CHAN_C | NONEOS_C, + /* " */ PRINT_C | CHAN_C | NONEOS_C, + /* # */ PRINT_C | MWILD_C | CHANPFX_C | CHAN_C | NONEOS_C, + /* $ */ PRINT_C | CHAN_C | NONEOS_C | USER_C, + /* % */ PRINT_C | CHAN_C | NONEOS_C, + /* & */ PRINT_C | CHANPFX_C | CHAN_C | NONEOS_C, + /* ' */ PRINT_C | CHAN_C | NONEOS_C, + /* ( */ PRINT_C | CHAN_C | NONEOS_C, + /* ) */ PRINT_C | CHAN_C | NONEOS_C, + /* * */ PRINT_C | KWILD_C | MWILD_C | CHAN_C | NONEOS_C, + /* + */ PRINT_C | CHAN_C | NONEOS_C, + /* , */ PRINT_C | NONEOS_C, + /* - */ PRINT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* . */ PRINT_C | KWILD_C | CHAN_C | NONEOS_C | USER_C | HOST_C | SERV_C, + /* / */ PRINT_C | CHAN_C | NONEOS_C | HOST_C, + /* 0 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 1 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 2 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 3 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 4 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 5 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 6 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 7 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 8 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* 9 */ PRINT_C | DIGIT_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* : */ PRINT_C | CHAN_C | NONEOS_C | HOST_C, + /* ; */ PRINT_C | CHAN_C | NONEOS_C, + /* < */ PRINT_C | CHAN_C | NONEOS_C, + /* = */ PRINT_C | CHAN_C | NONEOS_C, + /* > */ PRINT_C | CHAN_C | NONEOS_C, + /* ? */ PRINT_C | KWILD_C | MWILD_C | CHAN_C | NONEOS_C, + /* @ */ PRINT_C | KWILD_C | MWILD_C | CHAN_C | NONEOS_C, + /* A */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* B */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* C */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* D */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* E */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* F */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* G */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* H */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* I */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* J */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* K */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* L */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* M */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* N */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* O */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* P */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* Q */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* R */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* S */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* T */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* U */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* V */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* W */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* X */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* Y */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* Z */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* [ */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* \ */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* ] */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* ^ */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* _ */ PRINT_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* ` */ PRINT_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* a */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* b */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* c */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* d */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* e */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* f */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* g */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* h */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* i */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* j */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* k */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* l */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* m */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* n */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* o */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* p */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* q */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* r */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* s */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* t */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* u */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* v */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* w */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* x */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* y */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* z */ PRINT_C | ALPHA_C | LET_C | NICK_C | CHAN_C | NONEOS_C | USER_C | HOST_C, + /* { */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* | */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* } */ PRINT_C | ALPHA_C | NICK_C | CHAN_C | NONEOS_C | USER_C, + /* ~ */ PRINT_C | ALPHA_C | CHAN_C | NONEOS_C | USER_C, + /* del */ CHAN_C | NONEOS_C, + /* 0x80 */ CHAN_C | NONEOS_C, + /* 0x81 */ CHAN_C | NONEOS_C, + /* 0x82 */ CHAN_C | NONEOS_C, + /* 0x83 */ CHAN_C | NONEOS_C, + /* 0x84 */ CHAN_C | NONEOS_C, + /* 0x85 */ CHAN_C | NONEOS_C, + /* 0x86 */ CHAN_C | NONEOS_C, + /* 0x87 */ CHAN_C | NONEOS_C, + /* 0x88 */ CHAN_C | NONEOS_C, + /* 0x89 */ CHAN_C | NONEOS_C, + /* 0x8A */ CHAN_C | NONEOS_C, + /* 0x8B */ CHAN_C | NONEOS_C, + /* 0x8C */ CHAN_C | NONEOS_C, + /* 0x8D */ CHAN_C | NONEOS_C, + /* 0x8E */ CHAN_C | NONEOS_C, + /* 0x8F */ CHAN_C | NONEOS_C, + /* 0x90 */ CHAN_C | NONEOS_C, + /* 0x91 */ CHAN_C | NONEOS_C, + /* 0x92 */ CHAN_C | NONEOS_C, + /* 0x93 */ CHAN_C | NONEOS_C, + /* 0x94 */ CHAN_C | NONEOS_C, + /* 0x95 */ CHAN_C | NONEOS_C, + /* 0x96 */ CHAN_C | NONEOS_C, + /* 0x97 */ CHAN_C | NONEOS_C, + /* 0x98 */ CHAN_C | NONEOS_C, + /* 0x99 */ CHAN_C | NONEOS_C, + /* 0x9A */ CHAN_C | NONEOS_C, + /* 0x9B */ CHAN_C | NONEOS_C, + /* 0x9C */ CHAN_C | NONEOS_C, + /* 0x9D */ CHAN_C | NONEOS_C, + /* 0x9E */ CHAN_C | NONEOS_C, + /* 0x9F */ CHAN_C | NONEOS_C, + /* 0xA0 */ CHAN_C | FCHAN_C | NONEOS_C, + /* 0xA1 */ CHAN_C | NONEOS_C, + /* 0xA2 */ CHAN_C | NONEOS_C, + /* 0xA3 */ CHAN_C | NONEOS_C, + /* 0xA4 */ CHAN_C | NONEOS_C, + /* 0xA5 */ CHAN_C | NONEOS_C, + /* 0xA6 */ CHAN_C | NONEOS_C, + /* 0xA7 */ CHAN_C | NONEOS_C, + /* 0xA8 */ CHAN_C | NONEOS_C, + /* 0xA9 */ CHAN_C | NONEOS_C, + /* 0xAA */ CHAN_C | NONEOS_C, + /* 0xAB */ CHAN_C | NONEOS_C, + /* 0xAC */ CHAN_C | NONEOS_C, + /* 0xAD */ CHAN_C | NONEOS_C, + /* 0xAE */ CHAN_C | NONEOS_C, + /* 0xAF */ CHAN_C | NONEOS_C, + /* 0xB0 */ CHAN_C | NONEOS_C, + /* 0xB1 */ CHAN_C | NONEOS_C, + /* 0xB2 */ CHAN_C | NONEOS_C, + /* 0xB3 */ CHAN_C | NONEOS_C, + /* 0xB4 */ CHAN_C | NONEOS_C, + /* 0xB5 */ CHAN_C | NONEOS_C, + /* 0xB6 */ CHAN_C | NONEOS_C, + /* 0xB7 */ CHAN_C | NONEOS_C, + /* 0xB8 */ CHAN_C | NONEOS_C, + /* 0xB9 */ CHAN_C | NONEOS_C, + /* 0xBA */ CHAN_C | NONEOS_C, + /* 0xBB */ CHAN_C | NONEOS_C, + /* 0xBC */ CHAN_C | NONEOS_C, + /* 0xBD */ CHAN_C | NONEOS_C, + /* 0xBE */ CHAN_C | NONEOS_C, + /* 0xBF */ CHAN_C | NONEOS_C, + /* 0xC0 */ CHAN_C | NONEOS_C, + /* 0xC1 */ CHAN_C | NONEOS_C, + /* 0xC2 */ CHAN_C | NONEOS_C, + /* 0xC3 */ CHAN_C | NONEOS_C, + /* 0xC4 */ CHAN_C | NONEOS_C, + /* 0xC5 */ CHAN_C | NONEOS_C, + /* 0xC6 */ CHAN_C | NONEOS_C, + /* 0xC7 */ CHAN_C | NONEOS_C, + /* 0xC8 */ CHAN_C | NONEOS_C, + /* 0xC9 */ CHAN_C | NONEOS_C, + /* 0xCA */ CHAN_C | NONEOS_C, + /* 0xCB */ CHAN_C | NONEOS_C, + /* 0xCC */ CHAN_C | NONEOS_C, + /* 0xCD */ CHAN_C | NONEOS_C, + /* 0xCE */ CHAN_C | NONEOS_C, + /* 0xCF */ CHAN_C | NONEOS_C, + /* 0xD0 */ CHAN_C | NONEOS_C, + /* 0xD1 */ CHAN_C | NONEOS_C, + /* 0xD2 */ CHAN_C | NONEOS_C, + /* 0xD3 */ CHAN_C | NONEOS_C, + /* 0xD4 */ CHAN_C | NONEOS_C, + /* 0xD5 */ CHAN_C | NONEOS_C, + /* 0xD6 */ CHAN_C | NONEOS_C, + /* 0xD7 */ CHAN_C | NONEOS_C, + /* 0xD8 */ CHAN_C | NONEOS_C, + /* 0xD9 */ CHAN_C | NONEOS_C, + /* 0xDA */ CHAN_C | NONEOS_C, + /* 0xDB */ CHAN_C | NONEOS_C, + /* 0xDC */ CHAN_C | NONEOS_C, + /* 0xDD */ CHAN_C | NONEOS_C, + /* 0xDE */ CHAN_C | NONEOS_C, + /* 0xDF */ CHAN_C | NONEOS_C, + /* 0xE0 */ CHAN_C | NONEOS_C, + /* 0xE1 */ CHAN_C | NONEOS_C, + /* 0xE2 */ CHAN_C | NONEOS_C, + /* 0xE3 */ CHAN_C | NONEOS_C, + /* 0xE4 */ CHAN_C | NONEOS_C, + /* 0xE5 */ CHAN_C | NONEOS_C, + /* 0xE6 */ CHAN_C | NONEOS_C, + /* 0xE7 */ CHAN_C | NONEOS_C, + /* 0xE8 */ CHAN_C | NONEOS_C, + /* 0xE9 */ CHAN_C | NONEOS_C, + /* 0xEA */ CHAN_C | NONEOS_C, + /* 0xEB */ CHAN_C | NONEOS_C, + /* 0xEC */ CHAN_C | NONEOS_C, + /* 0xED */ CHAN_C | NONEOS_C, + /* 0xEE */ CHAN_C | NONEOS_C, + /* 0xEF */ CHAN_C | NONEOS_C, + /* 0xF0 */ CHAN_C | NONEOS_C, + /* 0xF1 */ CHAN_C | NONEOS_C, + /* 0xF2 */ CHAN_C | NONEOS_C, + /* 0xF3 */ CHAN_C | NONEOS_C, + /* 0xF4 */ CHAN_C | NONEOS_C, + /* 0xF5 */ CHAN_C | NONEOS_C, + /* 0xF6 */ CHAN_C | NONEOS_C, + /* 0xF7 */ CHAN_C | NONEOS_C, + /* 0xF8 */ CHAN_C | NONEOS_C, + /* 0xF9 */ CHAN_C | NONEOS_C, + /* 0xFA */ CHAN_C | NONEOS_C, + /* 0xFB */ CHAN_C | NONEOS_C, + /* 0xFC */ CHAN_C | NONEOS_C, + /* 0xFD */ CHAN_C | NONEOS_C, + /* 0xFE */ CHAN_C | NONEOS_C, + /* 0xFF */ CHAN_C | NONEOS_C }; diff --git a/src/modules.c b/src/modules.c index 44db3fb..21d1f6a 100644 --- a/src/modules.c +++ b/src/modules.c @@ -44,10 +44,10 @@ /* -TimeMr14C: * I have moved the dl* function definitions and * the two functions (load_a_module / unload_a_module) to the - * file dynlink.c + * file dynlink.c * And also made the necessary changes to those functions * to comply with shl_load and friends. - * In this file, to keep consistency with the makefile, + * In this file, to keep consistency with the makefile, * I added the ability to load *.sl files, too. * 27/02/2002 */ @@ -57,21 +57,21 @@ struct module **modlist = NULL; static const char *core_module_table[] = { - "m_ban", - "m_die", - "m_error", - "m_join", - "m_kick", - "m_kill", - "m_message", - "m_metadata", - "m_mode", - "m_nick", - "m_part", - "m_quit", - "m_server", - "m_squit", - NULL + "m_ban", + "m_die", + "m_error", + "m_join", + "m_kick", + "m_kill", + "m_message", + "m_metadata", + "m_mode", + "m_nick", + "m_part", + "m_quit", + "m_server", + "m_squit", + NULL }; #define MODS_INCREMENT 10 @@ -86,7 +86,7 @@ static int mo_modreload(struct Client *, struct Client *, int, const char **); static int mo_modunload(struct Client *, struct Client *, int, const char **); static int mo_modrestart(struct Client *, struct Client *, int, const char **); -static int me_modload(struct Client *, struct Client *, int, const char **); +static int me_modload(struct Client *, struct Client *, int, const char **); static int me_modlist(struct Client *, struct Client *, int, const char **); static int me_modreload(struct Client *, struct Client *, int, const char **); static int me_modunload(struct Client *, struct Client *, int, const char **); @@ -96,45 +96,45 @@ static int do_modload(struct Client *, const char *); static int do_modunload(struct Client *, const char *); static int do_modreload(struct Client *, const char *); static int do_modlist(struct Client *, const char *); -static int do_modrestart(struct Client *); +static int do_modrestart(struct Client *); struct Message modload_msgtab = { - "MODLOAD", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modload, 2}, {mo_modload, 2}} + "MODLOAD", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modload, 2}, {mo_modload, 2}} }; struct Message modunload_msgtab = { - "MODUNLOAD", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modunload, 2}, {mo_modunload, 2}} + "MODUNLOAD", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modunload, 2}, {mo_modunload, 2}} }; struct Message modreload_msgtab = { - "MODRELOAD", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modreload, 2}, {mo_modreload, 2}} + "MODRELOAD", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modreload, 2}, {mo_modreload, 2}} }; struct Message modlist_msgtab = { - "MODLIST", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modlist, 0}, {mo_modlist, 0}} + "MODLIST", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modlist, 0}, {mo_modlist, 0}} }; struct Message modrestart_msgtab = { - "MODRESTART", 0, 0, 0, MFLG_SLOW, - {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modrestart, 0}, {mo_modrestart, 0}} + "MODRESTART", 0, 0, 0, MFLG_SLOW, + {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modrestart, 0}, {mo_modrestart, 0}} }; void modules_init(void) { - mod_add_cmd(&modload_msgtab); - mod_add_cmd(&modunload_msgtab); - mod_add_cmd(&modreload_msgtab); - mod_add_cmd(&modlist_msgtab); - mod_add_cmd(&modrestart_msgtab); + mod_add_cmd(&modload_msgtab); + mod_add_cmd(&modunload_msgtab); + mod_add_cmd(&modreload_msgtab); + mod_add_cmd(&modlist_msgtab); + mod_add_cmd(&modrestart_msgtab); - /* Add the default paths we look in to the module system --nenolod */ - mod_add_path(MODPATH); - mod_add_path(AUTOMODPATH); + /* Add the default paths we look in to the module system --nenolod */ + mod_add_path(MODPATH); + mod_add_path(AUTOMODPATH); } /* mod_find_path() @@ -146,38 +146,37 @@ modules_init(void) static struct module_path * mod_find_path(const char *path) { - rb_dlink_node *ptr; - struct module_path *mpath; + rb_dlink_node *ptr; + struct module_path *mpath; - RB_DLINK_FOREACH(ptr, mod_paths.head) - { - mpath = ptr->data; + RB_DLINK_FOREACH(ptr, mod_paths.head) { + mpath = ptr->data; - if(!strcmp(path, mpath->path)) - return mpath; - } + if(!strcmp(path, mpath->path)) + return mpath; + } - return NULL; + return NULL; } /* mod_add_path * * input - path - * ouput - + * ouput - * side effects - adds path to list */ void mod_add_path(const char *path) { - struct module_path *pathst; + struct module_path *pathst; - if(mod_find_path(path)) - return; + if(mod_find_path(path)) + return; - pathst = rb_malloc(sizeof(struct module_path)); + pathst = rb_malloc(sizeof(struct module_path)); - strcpy(pathst->path, path); - rb_dlinkAddAlloc(pathst, &mod_paths); + strcpy(pathst->path, path); + rb_dlinkAddAlloc(pathst, &mod_paths); } /* mod_clear_paths() @@ -189,16 +188,15 @@ mod_add_path(const char *path) void mod_clear_paths(void) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) - { - rb_free(ptr->data); - rb_free_rb_dlink_node(ptr); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) { + rb_free(ptr->data); + rb_free_rb_dlink_node(ptr); + } - mod_paths.head = mod_paths.tail = NULL; - mod_paths.length = 0; + mod_paths.head = mod_paths.tail = NULL; + mod_paths.length = 0; } /* findmodule_byname @@ -211,14 +209,13 @@ mod_clear_paths(void) int findmodule_byname(const char *name) { - int i; + int i; - for (i = 0; i < num_mods; i++) - { - if(!irccmp(modlist[i]->name, name)) - return i; - } - return -1; + for (i = 0; i < num_mods; i++) { + if(!irccmp(modlist[i]->name, name)) + return i; + } + return -1; } /* load_all_modules() @@ -230,36 +227,33 @@ findmodule_byname(const char *name) void load_all_modules(int warn) { - DIR *system_module_dir = NULL; - struct dirent *ldirent = NULL; - char module_fq_name[PATH_MAX + 1]; - int len; + DIR *system_module_dir = NULL; + struct dirent *ldirent = NULL; + char module_fq_name[PATH_MAX + 1]; + int len; - modules_init(); + modules_init(); - modlist = (struct module **) rb_malloc(sizeof(struct module) * (MODS_INCREMENT)); + modlist = (struct module **) rb_malloc(sizeof(struct module) * (MODS_INCREMENT)); - max_mods = MODS_INCREMENT; + max_mods = MODS_INCREMENT; - system_module_dir = opendir(AUTOMODPATH); + system_module_dir = opendir(AUTOMODPATH); - if(system_module_dir == NULL) - { - ilog(L_MAIN, "Could not load modules from %s: %s", AUTOMODPATH, strerror(errno)); - return; - } + if(system_module_dir == NULL) { + ilog(L_MAIN, "Could not load modules from %s: %s", AUTOMODPATH, strerror(errno)); + return; + } - while ((ldirent = readdir(system_module_dir)) != NULL) - { - len = strlen(ldirent->d_name); - if((len > 3) && !strcmp(ldirent->d_name+len-3, SHARED_SUFFIX)) - { - (void) rb_snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name); - (void) load_a_module(module_fq_name, warn, 0); - } + while ((ldirent = readdir(system_module_dir)) != NULL) { + len = strlen(ldirent->d_name); + if((len > 3) && !strcmp(ldirent->d_name+len-3, SHARED_SUFFIX)) { + (void) rb_snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name); + (void) load_a_module(module_fq_name, warn, 0); + } - } - (void) closedir(system_module_dir); + } + (void) closedir(system_module_dir); } /* load_core_modules() @@ -271,23 +265,21 @@ load_all_modules(int warn) void load_core_modules(int warn) { - char module_name[MAXPATHLEN]; - int i; + char module_name[MAXPATHLEN]; + int i; - for (i = 0; core_module_table[i]; i++) - { - rb_snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH, - core_module_table[i], SHARED_SUFFIX); + for (i = 0; core_module_table[i]; i++) { + rb_snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH, + core_module_table[i], SHARED_SUFFIX); - if(load_a_module(module_name, warn, 1) == -1) - { - ilog(L_MAIN, - "Error loading core module %s%s: terminating ircd", - core_module_table[i], SHARED_SUFFIX); - exit(0); - } - } + if(load_a_module(module_name, warn, 1) == -1) { + ilog(L_MAIN, + "Error loading core module %s%s: terminating ircd", + core_module_table[i], SHARED_SUFFIX); + exit(0); + } + } } /* load_one_module() @@ -299,39 +291,35 @@ load_core_modules(int warn) int load_one_module(const char *path, int coremodule) { - char modpath[MAXPATHLEN]; - rb_dlink_node *pathst; - struct module_path *mpath; + char modpath[MAXPATHLEN]; + rb_dlink_node *pathst; + struct module_path *mpath; - struct stat statbuf; + struct stat statbuf; - if (server_state_foreground == 1) - inotice("loading module %s ...", path); + if (server_state_foreground == 1) + inotice("loading module %s ...", path); - RB_DLINK_FOREACH(pathst, mod_paths.head) - { - mpath = pathst->data; + RB_DLINK_FOREACH(pathst, mod_paths.head) { + mpath = pathst->data; - rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path); - if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL)) - { - if(stat(modpath, &statbuf) == 0) - { - if(S_ISREG(statbuf.st_mode)) - { - /* Regular files only please */ - if(coremodule) - return load_a_module(modpath, 1, 1); - else - return load_a_module(modpath, 1, 0); - } - } + rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path); + if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL)) { + if(stat(modpath, &statbuf) == 0) { + if(S_ISREG(statbuf.st_mode)) { + /* Regular files only please */ + if(coremodule) + return load_a_module(modpath, 1, 1); + else + return load_a_module(modpath, 1, 0); + } + } - } - } + } + } - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Cannot locate module %s", path); - return -1; + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Cannot locate module %s", path); + return -1; } @@ -339,54 +327,50 @@ load_one_module(const char *path, int coremodule) static int mo_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return 0; + } - if(parc > 2) - { - sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, - "ENCAP %s MODLOAD %s", parv[2], parv[1]); - if (match(parv[2], me.name) == 0) - return 0; - } + if(parc > 2) { + sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, + "ENCAP %s MODLOAD %s", parv[2], parv[1]); + if (match(parv[2], me.name) == 0) + return 0; + } - return do_modload(source_p, parv[1]); + return do_modload(source_p, parv[1]); } static int me_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " - "to load modules on this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " + "to load modules on this server."); + return 0; + } - return do_modload(source_p, parv[1]); + return do_modload(source_p, parv[1]); } static int do_modload(struct Client *source_p, const char *module) { - char *m_bn = rb_basename(module); + char *m_bn = rb_basename(module); - if(findmodule_byname(m_bn) != -1) - { - sendto_one_notice(source_p, ":Module %s is already loaded", m_bn); - rb_free(m_bn); - return 0; - } + if(findmodule_byname(m_bn) != -1) { + sendto_one_notice(source_p, ":Module %s is already loaded", m_bn); + rb_free(m_bn); + return 0; + } - load_one_module(module, 0); + load_one_module(module, 0); - rb_free(m_bn); + rb_free(m_bn); - return 0; + return 0; } @@ -394,257 +378,234 @@ do_modload(struct Client *source_p, const char *module) static int mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return 0; + } - if(parc > 2) - { - sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, - "ENCAP %s MODUNLOAD %s", parv[2], parv[1]); - if (match(parv[2], me.name) == 0) - return 0; - } + if(parc > 2) { + sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, + "ENCAP %s MODUNLOAD %s", parv[2], parv[1]); + if (match(parv[2], me.name) == 0) + return 0; + } - return do_modunload(source_p, parv[1]); + return do_modunload(source_p, parv[1]); } static int me_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " - "to load modules on this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " + "to load modules on this server."); + return 0; + } - return do_modunload(source_p, parv[1]); + return do_modunload(source_p, parv[1]); } static int do_modunload(struct Client *source_p, const char *module) { - int modindex; - char *m_bn = rb_basename(module); + int modindex; + char *m_bn = rb_basename(module); - if((modindex = findmodule_byname(m_bn)) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); - rb_free(m_bn); - return 0; - } + if((modindex = findmodule_byname(m_bn)) == -1) { + sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); + rb_free(m_bn); + return 0; + } - if(modlist[modindex]->core == 1) - { - sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn); - rb_free(m_bn); - return 0; - } + if(modlist[modindex]->core == 1) { + sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn); + rb_free(m_bn); + return 0; + } - if(unload_one_module(m_bn, 1) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); - } + if(unload_one_module(m_bn, 1) == -1) { + sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); + } - rb_free(m_bn); - return 0; + rb_free(m_bn); + return 0; } /* unload and load in one! */ static int mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return 0; + } - if(parc > 2) - { - sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, - "ENCAP %s MODRELOAD %s", parv[2], parv[1]); - if (match(parv[2], me.name) == 0) - return 0; - } + if(parc > 2) { + sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, + "ENCAP %s MODRELOAD %s", parv[2], parv[1]); + if (match(parv[2], me.name) == 0) + return 0; + } - return do_modreload(source_p, parv[1]); + return do_modreload(source_p, parv[1]); } static int me_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " - "to load modules on this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " + "to load modules on this server."); + return 0; + } - return do_modreload(source_p, parv[1]); + return do_modreload(source_p, parv[1]); } static int do_modreload(struct Client *source_p, const char *module) { - int modindex; - int check_core; - char *m_bn = rb_basename(module); + int modindex; + int check_core; + char *m_bn = rb_basename(module); - if((modindex = findmodule_byname(m_bn)) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); - rb_free(m_bn); - return 0; - } + if((modindex = findmodule_byname(m_bn)) == -1) { + sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); + rb_free(m_bn); + return 0; + } - check_core = modlist[modindex]->core; + check_core = modlist[modindex]->core; - if(unload_one_module(m_bn, 1) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); - rb_free(m_bn); - return 0; - } + if(unload_one_module(m_bn, 1) == -1) { + sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); + rb_free(m_bn); + return 0; + } - if((load_one_module(m_bn, check_core) == -1) && check_core) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Error reloading core module: %s: terminating ircd", m_bn); - ilog(L_MAIN, "Error loading core module %s: terminating ircd", m_bn); - exit(0); - } + if((load_one_module(m_bn, check_core) == -1) && check_core) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Error reloading core module: %s: terminating ircd", m_bn); + ilog(L_MAIN, "Error loading core module %s: terminating ircd", m_bn); + exit(0); + } - rb_free(m_bn); - return 0; + rb_free(m_bn); + return 0; } /* list modules .. */ static int mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return 0; + } - if(parc > 2) - { - sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, - "ENCAP %s MODLIST %s", parv[2], parv[1]); - if (match(parv[2], me.name) == 0) - return 0; - } + if(parc > 2) { + sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS, + "ENCAP %s MODLIST %s", parv[2], parv[1]); + if (match(parv[2], me.name) == 0) + return 0; + } - return do_modlist(source_p, parc > 1 ? parv[1] : 0); + return do_modlist(source_p, parc > 1 ? parv[1] : 0); } static int me_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " - "to load modules on this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " + "to load modules on this server."); + return 0; + } - return do_modlist(source_p, parv[1]); + return do_modlist(source_p, parv[1]); } static int do_modlist(struct Client *source_p, const char *pattern) { - int i; + int i; - for (i = 0; i < num_mods; i++) - { - if(pattern) - { - if(match(pattern, modlist[i]->name)) - { - sendto_one(source_p, form_str(RPL_MODLIST), - me.name, source_p->name, - modlist[i]->name, - modlist[i]->address, - modlist[i]->version, modlist[i]->core ? "(core)" : ""); - } - } - else - { - sendto_one(source_p, form_str(RPL_MODLIST), - me.name, source_p->name, modlist[i]->name, - modlist[i]->address, modlist[i]->version, - modlist[i]->core ? "(core)" : ""); - } - } + for (i = 0; i < num_mods; i++) { + if(pattern) { + if(match(pattern, modlist[i]->name)) { + sendto_one(source_p, form_str(RPL_MODLIST), + me.name, source_p->name, + modlist[i]->name, + modlist[i]->address, + modlist[i]->version, modlist[i]->core ? "(core)" : ""); + } + } else { + sendto_one(source_p, form_str(RPL_MODLIST), + me.name, source_p->name, modlist[i]->name, + modlist[i]->address, modlist[i]->version, + modlist[i]->core ? "(core)" : ""); + } + } - sendto_one(source_p, form_str(RPL_ENDOFMODLIST), me.name, source_p->name); - return 0; + sendto_one(source_p, form_str(RPL_ENDOFMODLIST), me.name, source_p->name); + return 0; } /* unload and reload all modules */ static int mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!IsOperAdmin(source_p)) - { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return 0; - } + if(!IsOperAdmin(source_p)) { + sendto_one(source_p, form_str(ERR_NOPRIVS), + me.name, source_p->name, "admin"); + return 0; + } - if(parc > 1) - { - sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS, - "ENCAP %s MODRESTART", parv[1]); - if (match(parv[1], me.name) == 0) - return 0; - } + if(parc > 1) { + sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS, + "ENCAP %s MODRESTART", parv[1]); + if (match(parv[1], me.name) == 0) + return 0; + } - return do_modrestart(source_p); + return do_modrestart(source_p); } static int me_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv) { - if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) - { - sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " - "to load modules on this server."); - return 0; - } + if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE)) { + sendto_one_notice(source_p, ":*** You do not have an appropriate shared block " + "to load modules on this server."); + return 0; + } - return do_modrestart(source_p); + return do_modrestart(source_p); } static int do_modrestart(struct Client *source_p) { - int modnum; + int modnum; - sendto_one_notice(source_p, ":Reloading all modules"); + sendto_one_notice(source_p, ":Reloading all modules"); - modnum = num_mods; - while (num_mods) - unload_one_module(modlist[0]->name, 0); + modnum = num_mods; + while (num_mods) + unload_one_module(modlist[0]->name, 0); - load_all_modules(0); - load_core_modules(0); - rehash(0); + load_all_modules(0); + load_core_modules(0); + rehash(0); - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Module Restart: %d modules unloaded, %d modules loaded", - modnum, num_mods); - ilog(L_MAIN, "Module Restart: %d modules unloaded, %d modules loaded", modnum, num_mods); - return 0; + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Module Restart: %d modules unloaded, %d modules loaded", + modnum, num_mods); + ilog(L_MAIN, "Module Restart: %d modules unloaded, %d modules loaded", modnum, num_mods); + return 0; } @@ -697,98 +658,96 @@ void *dlsym(void *, char *); static int firstLoad = TRUE; static int myDlError; static char *myErrorTable[] = { "Loading file as object failed\n", - "Loading file as object succeeded\n", - "Not a valid shared object\n", - "Architecture of object invalid on this architecture\n", - "Invalid or corrupt image\n", - "Could not access object\n", - "NSCreateObjectFileImageFromFile failed\n", - NULL -}; + "Loading file as object succeeded\n", + "Not a valid shared object\n", + "Architecture of object invalid on this architecture\n", + "Invalid or corrupt image\n", + "Could not access object\n", + "NSCreateObjectFileImageFromFile failed\n", + NULL + }; void undefinedErrorHandler(const char *symbolName) { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Undefined symbol: %s", symbolName); - ilog(L_MAIN, "Undefined symbol: %s", symbolName); - return; + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Undefined symbol: %s", symbolName); + ilog(L_MAIN, "Undefined symbol: %s", symbolName); + return; } NSModule multipleErrorHandler(NSSymbol s, NSModule old, NSModule new) { - /* XXX - ** This results in substantial leaking of memory... Should free one - ** module, maybe? - */ - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Symbol `%s' found in `%s' and `%s'", - NSNameOfSymbol(s), NSNameOfModule(old), NSNameOfModule(new)); - ilog(L_MAIN, "Symbol `%s' found in `%s' and `%s'", - NSNameOfSymbol(s), NSNameOfModule(old), NSNameOfModule(new)); - /* We return which module should be considered valid, I believe */ - return new; + /* XXX + ** This results in substantial leaking of memory... Should free one + ** module, maybe? + */ + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Symbol `%s' found in `%s' and `%s'", + NSNameOfSymbol(s), NSNameOfModule(old), NSNameOfModule(new)); + ilog(L_MAIN, "Symbol `%s' found in `%s' and `%s'", + NSNameOfSymbol(s), NSNameOfModule(old), NSNameOfModule(new)); + /* We return which module should be considered valid, I believe */ + return new; } void linkEditErrorHandler(NSLinkEditErrors errorClass, int errnum, - const char *fileName, const char *errorString) + const char *fileName, const char *errorString) { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Link editor error: %s for %s", errorString, fileName); - ilog(L_MAIN, "Link editor error: %s for %s", errorString, fileName); - return; + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Link editor error: %s for %s", errorString, fileName); + ilog(L_MAIN, "Link editor error: %s for %s", errorString, fileName); + return; } char * dlerror(void) { - return myDlError == NSObjectFileImageSuccess ? NULL : myErrorTable[myDlError % 7]; + return myDlError == NSObjectFileImageSuccess ? NULL : myErrorTable[myDlError % 7]; } void * dlopen(char *filename, int unused) { - NSObjectFileImage myImage; - NSModule myModule; + NSObjectFileImage myImage; + NSModule myModule; - if(firstLoad) - { - /* - ** If we are loading our first symbol (huzzah!) we should go ahead - ** and install link editor error handling! - */ - NSLinkEditErrorHandlers linkEditorErrorHandlers; + if(firstLoad) { + /* + ** If we are loading our first symbol (huzzah!) we should go ahead + ** and install link editor error handling! + */ + NSLinkEditErrorHandlers linkEditorErrorHandlers; - linkEditorErrorHandlers.undefined = undefinedErrorHandler; - linkEditorErrorHandlers.multiple = multipleErrorHandler; - linkEditorErrorHandlers.linkEdit = linkEditErrorHandler; - NSInstallLinkEditErrorHandlers(&linkEditorErrorHandlers); - firstLoad = FALSE; - } - myDlError = NSCreateObjectFileImageFromFile(filename, &myImage); - if(myDlError != NSObjectFileImageSuccess) - { - return NULL; - } - myModule = NSLinkModule(myImage, filename, NSLINKMODULE_OPTION_PRIVATE); - return (void *) myModule; + linkEditorErrorHandlers.undefined = undefinedErrorHandler; + linkEditorErrorHandlers.multiple = multipleErrorHandler; + linkEditorErrorHandlers.linkEdit = linkEditErrorHandler; + NSInstallLinkEditErrorHandlers(&linkEditorErrorHandlers); + firstLoad = FALSE; + } + myDlError = NSCreateObjectFileImageFromFile(filename, &myImage); + if(myDlError != NSObjectFileImageSuccess) { + return NULL; + } + myModule = NSLinkModule(myImage, filename, NSLINKMODULE_OPTION_PRIVATE); + return (void *) myModule; } int dlclose(void *myModule) { - NSUnLinkModule(myModule, FALSE); - return 0; + NSUnLinkModule(myModule, FALSE); + return 0; } void * dlsym(void *myModule, char *mySymbolName) { - NSSymbol mySymbol; + NSSymbol mySymbol; - mySymbol = NSLookupSymbolInModule((NSModule) myModule, mySymbolName); - return NSAddressOfSymbol(mySymbol); + mySymbol = NSLookupSymbolInModule((NSModule) myModule, mySymbolName); + return NSAddressOfSymbol(mySymbol); } #endif #endif @@ -808,10 +767,10 @@ dlsym(void *myModule, char *mySymbolName) static void * hpux_dlsym(void *handle, char *name) { - void *sym_addr; - if(!shl_findsym((shl_t *) & handle, name, TYPE_UNDEFINED, &sym_addr)) - return sym_addr; - return NULL; + void *sym_addr; + if(!shl_findsym((shl_t *) & handle, name, TYPE_UNDEFINED, &sym_addr)) + return sym_addr; + return NULL; } #endif @@ -826,73 +785,68 @@ hpux_dlsym(void *handle, char *name) int unload_one_module(const char *name, int warn) { - int modindex; + int modindex; - if((modindex = findmodule_byname(name)) == -1) - return -1; + if((modindex = findmodule_byname(name)) == -1) + return -1; - /* - ** XXX - The type system in C does not allow direct conversion between - ** data and function pointers, but as it happens, most C compilers will - ** safely do this, however it is a theoretical overlow to cast as we - ** must do here. I have library functions to take care of this, but - ** despite being more "correct" for the C language, this is more - ** practical. Removing the abuse of the ability to cast ANY pointer - ** to and from an integer value here will break some compilers. - ** -jmallett - */ - /* Left the comment in but the code isn't here any more -larne */ - switch (modlist[modindex]->mapi_version) - { - case 1: - { - struct mapi_mheader_av1 *mheader = modlist[modindex]->mapi_header; - if(mheader->mapi_command_list) - { - struct Message **m; - for (m = mheader->mapi_command_list; *m; ++m) - mod_del_cmd(*m); - } + /* + ** XXX - The type system in C does not allow direct conversion between + ** data and function pointers, but as it happens, most C compilers will + ** safely do this, however it is a theoretical overlow to cast as we + ** must do here. I have library functions to take care of this, but + ** despite being more "correct" for the C language, this is more + ** practical. Removing the abuse of the ability to cast ANY pointer + ** to and from an integer value here will break some compilers. + ** -jmallett + */ + /* Left the comment in but the code isn't here any more -larne */ + switch (modlist[modindex]->mapi_version) { + case 1: { + struct mapi_mheader_av1 *mheader = modlist[modindex]->mapi_header; + if(mheader->mapi_command_list) { + struct Message **m; + for (m = mheader->mapi_command_list; *m; ++m) + mod_del_cmd(*m); + } - /* hook events are never removed, we simply lose the - * ability to call them --fl - */ - if(mheader->mapi_hfn_list) - { - mapi_hfn_list_av1 *m; - for (m = mheader->mapi_hfn_list; m->hapi_name; ++m) - remove_hook(m->hapi_name, m->fn); - } + /* hook events are never removed, we simply lose the + * ability to call them --fl + */ + if(mheader->mapi_hfn_list) { + mapi_hfn_list_av1 *m; + for (m = mheader->mapi_hfn_list; m->hapi_name; ++m) + remove_hook(m->hapi_name, m->fn); + } - if(mheader->mapi_unregister) - mheader->mapi_unregister(); - break; - } - default: - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Unknown/unsupported MAPI version %d when unloading %s!", - modlist[modindex]->mapi_version, modlist[modindex]->name); - ilog(L_MAIN, "Unknown/unsupported MAPI version %d when unloading %s!", - modlist[modindex]->mapi_version, modlist[modindex]->name); - break; - } + if(mheader->mapi_unregister) + mheader->mapi_unregister(); + break; + } + default: + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Unknown/unsupported MAPI version %d when unloading %s!", + modlist[modindex]->mapi_version, modlist[modindex]->name); + ilog(L_MAIN, "Unknown/unsupported MAPI version %d when unloading %s!", + modlist[modindex]->mapi_version, modlist[modindex]->name); + break; + } - dlclose(modlist[modindex]->address); + dlclose(modlist[modindex]->address); - rb_free(modlist[modindex]->name); - memmove(&modlist[modindex], &modlist[modindex + 1], - sizeof(struct module) * ((num_mods - 1) - modindex)); + rb_free(modlist[modindex]->name); + memmove(&modlist[modindex], &modlist[modindex + 1], + sizeof(struct module) * ((num_mods - 1) - modindex)); - if(num_mods != 0) - num_mods--; + if(num_mods != 0) + num_mods--; - if(warn == 1) - { - ilog(L_MAIN, "Module %s unloaded", name); - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Module %s unloaded", name); - } + if(warn == 1) { + ilog(L_MAIN, "Module %s unloaded", name); + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Module %s unloaded", name); + } - return 0; + return 0; } @@ -906,130 +860,121 @@ unload_one_module(const char *name, int warn) int load_a_module(const char *path, int warn, int core) { - void *tmpptr = NULL; + void *tmpptr = NULL; - char *mod_basename; - const char *ver; + char *mod_basename; + const char *ver; - int *mapi_version; + int *mapi_version; - mod_basename = rb_basename(path); + mod_basename = rb_basename(path); #ifdef CHARYBDIS_PROFILE - tmpptr = dlopen(path, RTLD_NOW | RTLD_LOCAL | RTLD_PROFILE); + tmpptr = dlopen(path, RTLD_NOW | RTLD_LOCAL | RTLD_PROFILE); #else - tmpptr = dlopen(path, RTLD_NOW | RTLD_LOCAL); + tmpptr = dlopen(path, RTLD_NOW | RTLD_LOCAL); #endif - if(tmpptr == NULL) - { - const char *err = dlerror(); + if(tmpptr == NULL) { + const char *err = dlerror(); - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Error loading module %s: %s", mod_basename, err); - ilog(L_MAIN, "Error loading module %s: %s", mod_basename, err); - rb_free(mod_basename); - return -1; - } + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Error loading module %s: %s", mod_basename, err); + ilog(L_MAIN, "Error loading module %s: %s", mod_basename, err); + rb_free(mod_basename); + return -1; + } - /* - * _mheader is actually a struct mapi_mheader_*, but mapi_version - * is always the first member of this structure, so we treate it - * as a single int in order to determine the API version. - * -larne. - */ - mapi_version = (int *) (uintptr_t) dlsym(tmpptr, "_mheader"); - if((mapi_version == NULL - && (mapi_version = (int *) (uintptr_t) dlsym(tmpptr, "__mheader")) == NULL) - || MAPI_MAGIC(*mapi_version) != MAPI_MAGIC_HDR) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Data format error: module %s has no MAPI header.", - mod_basename); - ilog(L_MAIN, "Data format error: module %s has no MAPI header.", mod_basename); - (void) dlclose(tmpptr); - rb_free(mod_basename); - return -1; - } + /* + * _mheader is actually a struct mapi_mheader_*, but mapi_version + * is always the first member of this structure, so we treate it + * as a single int in order to determine the API version. + * -larne. + */ + mapi_version = (int *) (uintptr_t) dlsym(tmpptr, "_mheader"); + if((mapi_version == NULL + && (mapi_version = (int *) (uintptr_t) dlsym(tmpptr, "__mheader")) == NULL) + || MAPI_MAGIC(*mapi_version) != MAPI_MAGIC_HDR) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Data format error: module %s has no MAPI header.", + mod_basename); + ilog(L_MAIN, "Data format error: module %s has no MAPI header.", mod_basename); + (void) dlclose(tmpptr); + rb_free(mod_basename); + return -1; + } - switch (MAPI_VERSION(*mapi_version)) - { - case 1: - { - struct mapi_mheader_av1 *mheader = (struct mapi_mheader_av1 *) mapi_version; /* see above */ - if(mheader->mapi_register && (mheader->mapi_register() == -1)) - { - ilog(L_MAIN, "Module %s indicated failure during load.", - mod_basename); - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Module %s indicated failure during load.", - mod_basename); - dlclose(tmpptr); - rb_free(mod_basename); - return -1; - } - if(mheader->mapi_command_list) - { - struct Message **m; - for (m = mheader->mapi_command_list; *m; ++m) - mod_add_cmd(*m); - } + switch (MAPI_VERSION(*mapi_version)) { + case 1: { + struct mapi_mheader_av1 *mheader = (struct mapi_mheader_av1 *) mapi_version; /* see above */ + if(mheader->mapi_register && (mheader->mapi_register() == -1)) { + ilog(L_MAIN, "Module %s indicated failure during load.", + mod_basename); + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Module %s indicated failure during load.", + mod_basename); + dlclose(tmpptr); + rb_free(mod_basename); + return -1; + } + if(mheader->mapi_command_list) { + struct Message **m; + for (m = mheader->mapi_command_list; *m; ++m) + mod_add_cmd(*m); + } - if(mheader->mapi_hook_list) - { - mapi_hlist_av1 *m; - for (m = mheader->mapi_hook_list; m->hapi_name; ++m) - *m->hapi_id = register_hook(m->hapi_name); - } + if(mheader->mapi_hook_list) { + mapi_hlist_av1 *m; + for (m = mheader->mapi_hook_list; m->hapi_name; ++m) + *m->hapi_id = register_hook(m->hapi_name); + } - if(mheader->mapi_hfn_list) - { - mapi_hfn_list_av1 *m; - for (m = mheader->mapi_hfn_list; m->hapi_name; ++m) - add_hook(m->hapi_name, m->fn); - } + if(mheader->mapi_hfn_list) { + mapi_hfn_list_av1 *m; + for (m = mheader->mapi_hfn_list; m->hapi_name; ++m) + add_hook(m->hapi_name, m->fn); + } - ver = mheader->mapi_module_version; - break; - } + ver = mheader->mapi_module_version; + break; + } - default: - ilog(L_MAIN, "Module %s has unknown/unsupported MAPI version %d.", - mod_basename, MAPI_VERSION(*mapi_version)); - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Module %s has unknown/unsupported MAPI version %d.", - mod_basename, *mapi_version); - dlclose(tmpptr); - rb_free(mod_basename); - return -1; - } + default: + ilog(L_MAIN, "Module %s has unknown/unsupported MAPI version %d.", + mod_basename, MAPI_VERSION(*mapi_version)); + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Module %s has unknown/unsupported MAPI version %d.", + mod_basename, *mapi_version); + dlclose(tmpptr); + rb_free(mod_basename); + return -1; + } - if(ver == NULL) - ver = unknown_ver; + if(ver == NULL) + ver = unknown_ver; - increase_modlist(); + increase_modlist(); - modlist[num_mods] = rb_malloc(sizeof(struct module)); - modlist[num_mods]->address = tmpptr; - modlist[num_mods]->version = ver; - modlist[num_mods]->core = core; - modlist[num_mods]->name = rb_strdup(mod_basename); - modlist[num_mods]->mapi_header = mapi_version; - modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version); - num_mods++; + modlist[num_mods] = rb_malloc(sizeof(struct module)); + modlist[num_mods]->address = tmpptr; + modlist[num_mods]->version = ver; + modlist[num_mods]->core = core; + modlist[num_mods]->name = rb_strdup(mod_basename); + modlist[num_mods]->mapi_header = mapi_version; + modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version); + num_mods++; - if(warn == 1) - { - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx", - mod_basename, ver, MAPI_VERSION(*mapi_version), - (unsigned long) tmpptr); - ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx", - mod_basename, ver, MAPI_VERSION(*mapi_version), (unsigned long) tmpptr); - } - rb_free(mod_basename); - return 0; + if(warn == 1) { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx", + mod_basename, ver, MAPI_VERSION(*mapi_version), + (unsigned long) tmpptr); + ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx", + mod_basename, ver, MAPI_VERSION(*mapi_version), (unsigned long) tmpptr); + } + rb_free(mod_basename); + return 0; } /* @@ -1042,18 +987,18 @@ load_a_module(const char *path, int warn, int core) static void increase_modlist(void) { - struct module **new_modlist = NULL; + struct module **new_modlist = NULL; - if((num_mods + 1) < max_mods) - return; + if((num_mods + 1) < max_mods) + return; - new_modlist = (struct module **) rb_malloc(sizeof(struct module) * - (max_mods + MODS_INCREMENT)); - memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module) * num_mods); + new_modlist = (struct module **) rb_malloc(sizeof(struct module) * + (max_mods + MODS_INCREMENT)); + memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module) * num_mods); - rb_free(modlist); - modlist = new_modlist; - max_mods += MODS_INCREMENT; + rb_free(modlist); + modlist = new_modlist; + max_mods += MODS_INCREMENT; } #else /* STATIC_MODULES */ @@ -1067,7 +1012,7 @@ increase_modlist(void) void load_all_modules(int warn) { - load_static_modules(); + load_static_modules(); } #endif /* STATIC_MODULES */ diff --git a/src/monitor.c b/src/monitor.c index 62bf06d..8d4e3cc 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -42,46 +42,44 @@ static rb_bh *monitor_heap; void init_monitor(void) { - monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap"); + monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap"); } static inline unsigned int hash_monitor_nick(const char *name) { - return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS); + return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS); } struct monitor * find_monitor(const char *name, int add) { - struct monitor *monptr; + struct monitor *monptr; - unsigned int hashv = hash_monitor_nick(name); + unsigned int hashv = hash_monitor_nick(name); - for(monptr = monitorTable[hashv]; monptr; monptr = monptr->hnext) - { - if(!irccmp(monptr->name, name)) - return monptr; - } + for(monptr = monitorTable[hashv]; monptr; monptr = monptr->hnext) { + if(!irccmp(monptr->name, name)) + return monptr; + } - if(add) - { - monptr = rb_bh_alloc(monitor_heap); - rb_strlcpy(monptr->name, name, sizeof(monptr->name)); + if(add) { + monptr = rb_bh_alloc(monitor_heap); + rb_strlcpy(monptr->name, name, sizeof(monptr->name)); - monptr->hnext = monitorTable[hashv]; - monitorTable[hashv] = monptr; + monptr->hnext = monitorTable[hashv]; + monitorTable[hashv] = monptr; - return monptr; - } + return monptr; + } - return NULL; + return NULL; } void free_monitor(struct monitor *monptr) { - rb_bh_free(monitor_heap, monptr); + rb_bh_free(monitor_heap, monptr); } /* monitor_signon() @@ -94,16 +92,16 @@ free_monitor(struct monitor *monptr) void monitor_signon(struct Client *client_p) { - char buf[USERHOST_REPLYLEN]; - struct monitor *monptr = find_monitor(client_p->name, 0); + char buf[USERHOST_REPLYLEN]; + struct monitor *monptr = find_monitor(client_p->name, 0); - /* noones watching this nick */ - if(monptr == NULL) - return; + /* noones watching this nick */ + if(monptr == NULL) + return; - rb_snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host); + rb_snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host); - sendto_monitor(monptr, form_str(RPL_MONONLINE), me.name, "*", buf); + sendto_monitor(monptr, form_str(RPL_MONONLINE), me.name, "*", buf); } /* monitor_signoff() @@ -116,30 +114,29 @@ monitor_signon(struct Client *client_p) void monitor_signoff(struct Client *client_p) { - struct monitor *monptr = find_monitor(client_p->name, 0); + struct monitor *monptr = find_monitor(client_p->name, 0); - /* noones watching this nick */ - if(monptr == NULL) - return; + /* noones watching this nick */ + if(monptr == NULL) + return; - sendto_monitor(monptr, form_str(RPL_MONOFFLINE), me.name, "*", - client_p->name); + sendto_monitor(monptr, form_str(RPL_MONOFFLINE), me.name, "*", + client_p->name); } void clear_monitor(struct Client *client_p) { - struct monitor *monptr; - rb_dlink_node *ptr, *next_ptr; + struct monitor *monptr; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->monitor_list.head) - { - monptr = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->monitor_list.head) { + monptr = ptr->data; - rb_dlinkFindDestroy(client_p, &monptr->users); - rb_free_rb_dlink_node(ptr); - } + rb_dlinkFindDestroy(client_p, &monptr->users); + rb_free_rb_dlink_node(ptr); + } - client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL; - client_p->localClient->monitor_list.length = 0; + client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL; + client_p->localClient->monitor_list.length = 0; } diff --git a/src/newconf.c b/src/newconf.c index cf31f7a..b8f2578 100644 --- a/src/newconf.c +++ b/src/newconf.c @@ -56,208 +56,193 @@ static struct alias_entry *yy_alias = NULL; static char *yy_blacklist_host = NULL; static char *yy_blacklist_reason = NULL; static int yy_blacklist_ipv4 = 1; -static int yy_blacklist_ipv6 = 0; +static int yy_blacklist_ipv6 = 0; static char *yy_privset_extends = NULL; static const char * conf_strtype(int type) { - switch (type & CF_MTYPE) - { - case CF_INT: - return "integer value"; - case CF_STRING: - return "unquoted string"; - case CF_YESNO: - return "yes/no value"; - case CF_QSTRING: - return "quoted string"; - case CF_TIME: - return "time/size value"; - default: - return "unknown type"; - } + switch (type & CF_MTYPE) { + case CF_INT: + return "integer value"; + case CF_STRING: + return "unquoted string"; + case CF_YESNO: + return "yes/no value"; + case CF_QSTRING: + return "quoted string"; + case CF_TIME: + return "time/size value"; + default: + return "unknown type"; + } } int -add_top_conf(const char *name, int (*sfunc) (struct TopConf *), - int (*efunc) (struct TopConf *), struct ConfEntry *items) +add_top_conf(const char *name, int (*sfunc) (struct TopConf *), + int (*efunc) (struct TopConf *), struct ConfEntry *items) { - struct TopConf *tc; + struct TopConf *tc; - tc = rb_malloc(sizeof(struct TopConf)); + tc = rb_malloc(sizeof(struct TopConf)); - tc->tc_name = name; - tc->tc_sfunc = sfunc; - tc->tc_efunc = efunc; - tc->tc_entries = items; + tc->tc_name = name; + tc->tc_sfunc = sfunc; + tc->tc_efunc = efunc; + tc->tc_entries = items; - rb_dlinkAddAlloc(tc, &conf_items); - return 0; + rb_dlinkAddAlloc(tc, &conf_items); + return 0; } struct TopConf * find_top_conf(const char *name) { - rb_dlink_node *d; - struct TopConf *tc; + rb_dlink_node *d; + struct TopConf *tc; - RB_DLINK_FOREACH(d, conf_items.head) - { - tc = d->data; - if(strcasecmp(tc->tc_name, name) == 0) - return tc; - } + RB_DLINK_FOREACH(d, conf_items.head) { + tc = d->data; + if(strcasecmp(tc->tc_name, name) == 0) + return tc; + } - return NULL; + return NULL; } struct ConfEntry * find_conf_item(const struct TopConf *top, const char *name) { - struct ConfEntry *cf; - rb_dlink_node *d; + struct ConfEntry *cf; + rb_dlink_node *d; - if(top->tc_entries) - { - int i; + if(top->tc_entries) { + int i; - for(i = 0; top->tc_entries[i].cf_type; i++) - { - cf = &top->tc_entries[i]; + for(i = 0; top->tc_entries[i].cf_type; i++) { + cf = &top->tc_entries[i]; - if(!strcasecmp(cf->cf_name, name)) - return cf; - } - } + if(!strcasecmp(cf->cf_name, name)) + return cf; + } + } - RB_DLINK_FOREACH(d, top->tc_items.head) - { - cf = d->data; - if(strcasecmp(cf->cf_name, name) == 0) - return cf; - } + RB_DLINK_FOREACH(d, top->tc_items.head) { + cf = d->data; + if(strcasecmp(cf->cf_name, name) == 0) + return cf; + } - return NULL; + return NULL; } int remove_top_conf(char *name) { - struct TopConf *tc; - rb_dlink_node *ptr; + struct TopConf *tc; + rb_dlink_node *ptr; - if((tc = find_top_conf(name)) == NULL) - return -1; + if((tc = find_top_conf(name)) == NULL) + return -1; - if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL) - return -1; + if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL) + return -1; - rb_dlinkDestroy(ptr, &conf_items); - rb_free(tc); + rb_dlinkDestroy(ptr, &conf_items); + rb_free(tc); - return 0; + return 0; } static void conf_set_serverinfo_name(void *data) { - if(ServerInfo.name == NULL) - { - const char *s; - int dots = 0; + if(ServerInfo.name == NULL) { + const char *s; + int dots = 0; - for(s = data; *s != '\0'; s++) - { - if(!IsServChar(*s)) - { - conf_report_error("Ignoring serverinfo::name " - "-- bogus servername."); - return; - } - else if(*s == '.') - ++dots; - } + for(s = data; *s != '\0'; s++) { + if(!IsServChar(*s)) { + conf_report_error("Ignoring serverinfo::name " + "-- bogus servername."); + return; + } else if(*s == '.') + ++dots; + } - if(!dots) - { - conf_report_error("Ignoring serverinfo::name -- must contain '.'"); - return; - } + if(!dots) { + conf_report_error("Ignoring serverinfo::name -- must contain '.'"); + return; + } - s = data; + s = data; - if(IsDigit(*s)) - { - conf_report_error("Ignoring serverinfo::name -- cannot begin with digit."); - return; - } + if(IsDigit(*s)) { + conf_report_error("Ignoring serverinfo::name -- cannot begin with digit."); + return; + } - /* the ircd will exit() in main() if we dont set one */ - if(strlen(s) <= HOSTLEN) - ServerInfo.name = rb_strdup((char *) data); - } + /* the ircd will exit() in main() if we dont set one */ + if(strlen(s) <= HOSTLEN) + ServerInfo.name = rb_strdup((char *) data); + } } static void conf_set_serverinfo_sid(void *data) { - char *sid = data; + char *sid = data; - if(ServerInfo.sid[0] == '\0') - { - if(!IsDigit(sid[0]) || !IsIdChar(sid[1]) || - !IsIdChar(sid[2]) || sid[3] != '\0') - { - conf_report_error("Ignoring serverinfo::sid " - "-- bogus sid."); - return; - } + if(ServerInfo.sid[0] == '\0') { + if(!IsDigit(sid[0]) || !IsIdChar(sid[1]) || + !IsIdChar(sid[2]) || sid[3] != '\0') { + conf_report_error("Ignoring serverinfo::sid " + "-- bogus sid."); + return; + } - strcpy(ServerInfo.sid, sid); - } + strcpy(ServerInfo.sid, sid); + } } static void conf_set_serverinfo_network_name(void *data) { - char *p; + char *p; - if((p = strchr((char *) data, ' '))) - *p = '\0'; + if((p = strchr((char *) data, ' '))) + *p = '\0'; - rb_free(ServerInfo.network_name); - ServerInfo.network_name = rb_strdup((char *) data); + rb_free(ServerInfo.network_name); + ServerInfo.network_name = rb_strdup((char *) data); } static void conf_set_serverinfo_vhost(void *data) { - if(rb_inet_pton(AF_INET, (char *) data, &ServerInfo.ip.sin_addr) <= 0) - { - conf_report_error("Invalid netmask for server IPv4 vhost (%s)", (char *) data); - return; - } - ServerInfo.ip.sin_family = AF_INET; - ServerInfo.specific_ipv4_vhost = 1; + if(rb_inet_pton(AF_INET, (char *) data, &ServerInfo.ip.sin_addr) <= 0) { + conf_report_error("Invalid netmask for server IPv4 vhost (%s)", (char *) data); + return; + } + ServerInfo.ip.sin_family = AF_INET; + ServerInfo.specific_ipv4_vhost = 1; } static void conf_set_serverinfo_vhost6(void *data) { #ifdef RB_IPV6 - if(rb_inet_pton(AF_INET6, (char *) data, &ServerInfo.ip6.sin6_addr) <= 0) - { - conf_report_error("Invalid netmask for server IPv6 vhost (%s)", (char *) data); - return; - } + if(rb_inet_pton(AF_INET6, (char *) data, &ServerInfo.ip6.sin6_addr) <= 0) { + conf_report_error("Invalid netmask for server IPv6 vhost (%s)", (char *) data); + return; + } - ServerInfo.specific_ipv6_vhost = 1; - ServerInfo.ip6.sin6_family = AF_INET6; + ServerInfo.specific_ipv6_vhost = 1; + ServerInfo.ip6.sin6_family = AF_INET6; #else - conf_report_error("Warning -- ignoring serverinfo::vhost6 -- IPv6 support not available."); + conf_report_error("Warning -- ignoring serverinfo::vhost6 -- IPv6 support not available."); #endif } @@ -265,18 +250,18 @@ static void conf_set_modules_module(void *data) { #ifndef STATIC_MODULES - char *m_bn; + char *m_bn; - m_bn = rb_basename((char *) data); + m_bn = rb_basename((char *) data); - if(findmodule_byname(m_bn) != -1) - return; + if(findmodule_byname(m_bn) != -1) + return; - load_one_module((char *) data, 0); + load_one_module((char *) data, 0); - rb_free(m_bn); + rb_free(m_bn); #else - conf_report_error("Ignoring modules::module -- loadable module support not present."); + conf_report_error("Ignoring modules::module -- loadable module support not present."); #endif } @@ -284,519 +269,487 @@ static void conf_set_modules_path(void *data) { #ifndef STATIC_MODULES - mod_add_path((char *) data); + mod_add_path((char *) data); #else - conf_report_error("Ignoring modules::path -- loadable module support not present."); + conf_report_error("Ignoring modules::path -- loadable module support not present."); #endif } -struct mode_table -{ - const char *name; - int mode; +struct mode_table { + const char *name; + int mode; }; /* *INDENT-OFF* */ static struct mode_table umode_table[] = { - {"callerid", UMODE_CALLERID }, - {"softcallerid", UMODE_SCALLERID }, - {"deaf", UMODE_DEAF }, - {"invisible", UMODE_INVISIBLE }, - {"locops", UMODE_LOCOPS }, - {"noforward", UMODE_NOFORWARD }, - {"regonlymsg", UMODE_REGONLYMSG}, - {"servnotice", UMODE_SERVNOTICE}, - {"wallop", UMODE_WALLOP }, - {"operwall", UMODE_OPERWALL }, - {"noctcp", UMODE_NOCTCP }, - {"noinvite", UMODE_NOINVITE }, - {"bot", UMODE_BOT }, - {"override", UMODE_OVERRIDE }, - {NULL, 0} + {"callerid", UMODE_CALLERID }, + {"softcallerid", UMODE_SCALLERID }, + {"deaf", UMODE_DEAF }, + {"invisible", UMODE_INVISIBLE }, + {"locops", UMODE_LOCOPS }, + {"noforward", UMODE_NOFORWARD }, + {"regonlymsg", UMODE_REGONLYMSG}, + {"servnotice", UMODE_SERVNOTICE}, + {"wallop", UMODE_WALLOP }, + {"operwall", UMODE_OPERWALL }, + {"noctcp", UMODE_NOCTCP }, + {"noinvite", UMODE_NOINVITE }, + {"bot", UMODE_BOT }, + {"override", UMODE_OVERRIDE }, + {NULL, 0} }; static struct mode_table oper_table[] = { - {"encrypted", OPER_ENCRYPTED }, - {"need_ssl", OPER_NEEDSSL }, - {NULL, 0} + {"encrypted", OPER_ENCRYPTED }, + {"need_ssl", OPER_NEEDSSL }, + {NULL, 0} }; static struct mode_table auth_table[] = { - {"encrypted", CONF_FLAGS_ENCRYPTED }, - {"spoof_notice", CONF_FLAGS_SPOOF_NOTICE }, - {"exceed_limit", CONF_FLAGS_NOLIMIT }, - {"dnsbl_exempt", CONF_FLAGS_EXEMPTDNSBL }, - {"kline_exempt", CONF_FLAGS_EXEMPTKLINE }, - {"flood_exempt", CONF_FLAGS_EXEMPTFLOOD }, - {"spambot_exempt", CONF_FLAGS_EXEMPTSPAMBOT }, - {"shide_exempt", CONF_FLAGS_EXEMPTSHIDE }, - {"jupe_exempt", CONF_FLAGS_EXEMPTJUPE }, - {"resv_exempt", CONF_FLAGS_EXEMPTRESV }, - {"no_tilde", CONF_FLAGS_NO_TILDE }, - {"need_ident", CONF_FLAGS_NEED_IDENTD }, - {"have_ident", CONF_FLAGS_NEED_IDENTD }, - {"need_ssl", CONF_FLAGS_NEED_SSL }, - {"need_sasl", CONF_FLAGS_NEED_SASL }, - {NULL, 0} + {"encrypted", CONF_FLAGS_ENCRYPTED }, + {"spoof_notice", CONF_FLAGS_SPOOF_NOTICE }, + {"exceed_limit", CONF_FLAGS_NOLIMIT }, + {"dnsbl_exempt", CONF_FLAGS_EXEMPTDNSBL }, + {"kline_exempt", CONF_FLAGS_EXEMPTKLINE }, + {"flood_exempt", CONF_FLAGS_EXEMPTFLOOD }, + {"spambot_exempt", CONF_FLAGS_EXEMPTSPAMBOT }, + {"shide_exempt", CONF_FLAGS_EXEMPTSHIDE }, + {"jupe_exempt", CONF_FLAGS_EXEMPTJUPE }, + {"resv_exempt", CONF_FLAGS_EXEMPTRESV }, + {"no_tilde", CONF_FLAGS_NO_TILDE }, + {"need_ident", CONF_FLAGS_NEED_IDENTD }, + {"have_ident", CONF_FLAGS_NEED_IDENTD }, + {"need_ssl", CONF_FLAGS_NEED_SSL }, + {"need_sasl", CONF_FLAGS_NEED_SASL }, + {NULL, 0} }; static struct mode_table connect_table[] = { - { "autoconn", SERVER_AUTOCONN }, - { "compressed", SERVER_COMPRESSED }, - { "encrypted", SERVER_ENCRYPTED }, - { "topicburst", SERVER_TB }, - { "ssl", SERVER_SSL }, - { NULL, 0 }, + { "autoconn", SERVER_AUTOCONN }, + { "compressed", SERVER_COMPRESSED }, + { "encrypted", SERVER_ENCRYPTED }, + { "topicburst", SERVER_TB }, + { "ssl", SERVER_SSL }, + { NULL, 0 }, }; static struct mode_table cluster_table[] = { - { "kline", SHARED_PKLINE }, - { "tkline", SHARED_TKLINE }, - { "unkline", SHARED_UNKLINE }, - { "locops", SHARED_LOCOPS }, - { "xline", SHARED_PXLINE }, - { "txline", SHARED_TXLINE }, - { "unxline", SHARED_UNXLINE }, - { "resv", SHARED_PRESV }, - { "tresv", SHARED_TRESV }, - { "unresv", SHARED_UNRESV }, - { "all", CLUSTER_ALL }, - {NULL, 0} + { "kline", SHARED_PKLINE }, + { "tkline", SHARED_TKLINE }, + { "unkline", SHARED_UNKLINE }, + { "locops", SHARED_LOCOPS }, + { "xline", SHARED_PXLINE }, + { "txline", SHARED_TXLINE }, + { "unxline", SHARED_UNXLINE }, + { "resv", SHARED_PRESV }, + { "tresv", SHARED_TRESV }, + { "unresv", SHARED_UNRESV }, + { "all", CLUSTER_ALL }, + {NULL, 0} }; -static struct mode_table shared_table[] = -{ - { "kline", SHARED_PKLINE|SHARED_TKLINE }, - { "xline", SHARED_PXLINE|SHARED_TXLINE }, - { "resv", SHARED_PRESV|SHARED_TRESV }, - { "dline", SHARED_PDLINE|SHARED_TDLINE }, - { "tdline", SHARED_TDLINE }, - { "pdline", SHARED_PDLINE }, - { "undline", SHARED_UNDLINE }, - { "tkline", SHARED_TKLINE }, - { "unkline", SHARED_UNKLINE }, - { "txline", SHARED_TXLINE }, - { "unxline", SHARED_UNXLINE }, - { "tresv", SHARED_TRESV }, - { "unresv", SHARED_UNRESV }, - { "locops", SHARED_LOCOPS }, - { "rehash", SHARED_REHASH }, - { "die", SHARED_DIE }, - { "modules", SHARED_MODULE }, - { "all", SHARED_ALL }, - { "none", 0 }, - {NULL, 0} +static struct mode_table shared_table[] = { + { "kline", SHARED_PKLINE|SHARED_TKLINE }, + { "xline", SHARED_PXLINE|SHARED_TXLINE }, + { "resv", SHARED_PRESV|SHARED_TRESV }, + { "dline", SHARED_PDLINE|SHARED_TDLINE }, + { "tdline", SHARED_TDLINE }, + { "pdline", SHARED_PDLINE }, + { "undline", SHARED_UNDLINE }, + { "tkline", SHARED_TKLINE }, + { "unkline", SHARED_UNKLINE }, + { "txline", SHARED_TXLINE }, + { "unxline", SHARED_UNXLINE }, + { "tresv", SHARED_TRESV }, + { "unresv", SHARED_UNRESV }, + { "locops", SHARED_LOCOPS }, + { "rehash", SHARED_REHASH }, + { "die", SHARED_DIE }, + { "modules", SHARED_MODULE }, + { "all", SHARED_ALL }, + { "none", 0 }, + {NULL, 0} }; /* *INDENT-ON* */ static int find_umode(struct mode_table *tab, const char *name) { - int i; + int i; - for (i = 0; tab[i].name; i++) - { - if(strcmp(tab[i].name, name) == 0) - return tab[i].mode; - } + for (i = 0; tab[i].name; i++) { + if(strcmp(tab[i].name, name) == 0) + return tab[i].mode; + } - return -1; + return -1; } static void set_modes_from_table(int *modes, const char *whatis, struct mode_table *tab, conf_parm_t * args) { - for (; args; args = args->next) - { - const char *umode; - int dir = 1; - int mode; + for (; args; args = args->next) { + const char *umode; + int dir = 1; + int mode; - if((args->type & CF_MTYPE) != CF_STRING) - { - conf_report_error("Warning -- %s is not a string; ignoring.", whatis); - continue; - } + if((args->type & CF_MTYPE) != CF_STRING) { + conf_report_error("Warning -- %s is not a string; ignoring.", whatis); + continue; + } - umode = args->v.string; + umode = args->v.string; - if(*umode == '~') - { - dir = 0; - umode++; - } + if(*umode == '~') { + dir = 0; + umode++; + } - mode = find_umode(tab, umode); + mode = find_umode(tab, umode); - if(mode == -1) - { - conf_report_error("Warning -- unknown %s %s.", whatis, args->v.string); - continue; - } + if(mode == -1) { + conf_report_error("Warning -- unknown %s %s.", whatis, args->v.string); + continue; + } - if(mode) - { - if(dir) - *modes |= mode; - else - *modes &= ~mode; - } - else - *modes = 0; - } + if(mode) { + if(dir) + *modes |= mode; + else + *modes &= ~mode; + } else + *modes = 0; + } } static void conf_set_privset_extends(void *data) { - yy_privset_extends = rb_strdup((char *) data); + yy_privset_extends = rb_strdup((char *) data); } static void conf_set_privset_privs(void *data) { - char *privs = NULL; - conf_parm_t *args = data; + char *privs = NULL; + conf_parm_t *args = data; - for (; args; args = args->next) - { - if (privs == NULL) - privs = rb_strdup(args->v.string); - else - { - char *privs_old = privs; + for (; args; args = args->next) { + if (privs == NULL) + privs = rb_strdup(args->v.string); + else { + char *privs_old = privs; - privs = rb_malloc(strlen(privs_old) + 1 + strlen(args->v.string) + 1); - strcpy(privs, privs_old); - strcat(privs, " "); - strcat(privs, args->v.string); + privs = rb_malloc(strlen(privs_old) + 1 + strlen(args->v.string) + 1); + strcpy(privs, privs_old); + strcat(privs, " "); + strcat(privs, args->v.string); - rb_free(privs_old); - } - } + rb_free(privs_old); + } + } - if (privs) - { - if (yy_privset_extends) - { - struct PrivilegeSet *set = privilegeset_get(yy_privset_extends); + if (privs) { + if (yy_privset_extends) { + struct PrivilegeSet *set = privilegeset_get(yy_privset_extends); - if (!set) - { - conf_report_error("Warning -- unknown parent privilege set %s for %s; assuming defaults", yy_privset_extends, conf_cur_block_name); + if (!set) { + conf_report_error("Warning -- unknown parent privilege set %s for %s; assuming defaults", yy_privset_extends, conf_cur_block_name); - set = privilegeset_get("default"); - } + set = privilegeset_get("default"); + } - privilegeset_extend(set, conf_cur_block_name != NULL ? conf_cur_block_name : "", privs, 0); + privilegeset_extend(set, conf_cur_block_name != NULL ? conf_cur_block_name : "", privs, 0); - rb_free(yy_privset_extends); - yy_privset_extends = NULL; - } - else - privilegeset_set_new(conf_cur_block_name != NULL ? conf_cur_block_name : "", privs, 0); + rb_free(yy_privset_extends); + yy_privset_extends = NULL; + } else + privilegeset_set_new(conf_cur_block_name != NULL ? conf_cur_block_name : "", privs, 0); - rb_free(privs); - } + rb_free(privs); + } } static int conf_begin_oper(struct TopConf *tc) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - if(yy_oper != NULL) - { - free_oper_conf(yy_oper); - yy_oper = NULL; - } + if(yy_oper != NULL) { + free_oper_conf(yy_oper); + yy_oper = NULL; + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head) - { - free_oper_conf(ptr->data); - rb_dlinkDestroy(ptr, &yy_oper_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head) { + free_oper_conf(ptr->data); + rb_dlinkDestroy(ptr, &yy_oper_list); + } - yy_oper = make_oper_conf(); - yy_oper->flags |= OPER_ENCRYPTED; + yy_oper = make_oper_conf(); + yy_oper->flags |= OPER_ENCRYPTED; - return 0; + return 0; } static int conf_end_oper(struct TopConf *tc) { - struct oper_conf *yy_tmpoper; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct oper_conf *yy_tmpoper; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - if(conf_cur_block_name != NULL) - { - if(strlen(conf_cur_block_name) > OPERNICKLEN) - conf_cur_block_name[OPERNICKLEN] = '\0'; + if(conf_cur_block_name != NULL) { + if(strlen(conf_cur_block_name) > OPERNICKLEN) + conf_cur_block_name[OPERNICKLEN] = '\0'; - yy_oper->name = rb_strdup(conf_cur_block_name); - } + yy_oper->name = rb_strdup(conf_cur_block_name); + } - if(EmptyString(yy_oper->name)) - { - conf_report_error("Ignoring operator block -- missing name."); - return 0; - } + if(EmptyString(yy_oper->name)) { + conf_report_error("Ignoring operator block -- missing name."); + return 0; + } #ifdef HAVE_LIBCRYPTO - if(EmptyString(yy_oper->passwd) && EmptyString(yy_oper->rsa_pubkey_file)) + if(EmptyString(yy_oper->passwd) && EmptyString(yy_oper->rsa_pubkey_file)) #else - if(EmptyString(yy_oper->passwd)) + if(EmptyString(yy_oper->passwd)) #endif - { - conf_report_error("Ignoring operator block for %s -- missing password", - yy_oper->name); - return 0; - } + { + conf_report_error("Ignoring operator block for %s -- missing password", + yy_oper->name); + return 0; + } - if (!yy_oper->privset) - yy_oper->privset = privilegeset_get("default"); + if (!yy_oper->privset) + yy_oper->privset = privilegeset_get("default"); - /* now, yy_oper_list contains a stack of oper_conf's with just user - * and host in, yy_oper contains the rest of the information which - * we need to copy into each element in yy_oper_list - */ - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head) - { - yy_tmpoper = ptr->data; + /* now, yy_oper_list contains a stack of oper_conf's with just user + * and host in, yy_oper contains the rest of the information which + * we need to copy into each element in yy_oper_list + */ + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head) { + yy_tmpoper = ptr->data; - yy_tmpoper->name = rb_strdup(yy_oper->name); + yy_tmpoper->name = rb_strdup(yy_oper->name); - /* could be an rsa key instead.. */ - if(!EmptyString(yy_oper->passwd)) - yy_tmpoper->passwd = rb_strdup(yy_oper->passwd); + /* could be an rsa key instead.. */ + if(!EmptyString(yy_oper->passwd)) + yy_tmpoper->passwd = rb_strdup(yy_oper->passwd); - yy_tmpoper->flags = yy_oper->flags; - yy_tmpoper->umodes = yy_oper->umodes; - yy_tmpoper->snomask = yy_oper->snomask; + yy_tmpoper->flags = yy_oper->flags; + yy_tmpoper->umodes = yy_oper->umodes; + yy_tmpoper->snomask = yy_oper->snomask; - if(!EmptyString(yy_oper->vhost)) - { - if(valid_hostname(yy_oper->vhost)) - yy_tmpoper->vhost = rb_strdup(yy_oper->vhost); - else if(!EmptyString(yy_oper->vhost)) - conf_report_error("Ignoring vhost setting for oper %s -- invalid hostmask.", yy_oper->name); - } + if(!EmptyString(yy_oper->vhost)) { + if(valid_hostname(yy_oper->vhost)) + yy_tmpoper->vhost = rb_strdup(yy_oper->vhost); + else if(!EmptyString(yy_oper->vhost)) + conf_report_error("Ignoring vhost setting for oper %s -- invalid hostmask.", yy_oper->name); + } - if(!EmptyString(yy_oper->swhois)) - { - if(strlen(yy_oper->swhois) < 400) - yy_tmpoper->swhois = rb_strdup(yy_oper->swhois); - else - conf_report_error("Ignoring swhois setting for oper %s -- swhois too long.", yy_oper->name); - } + if(!EmptyString(yy_oper->swhois)) { + if(strlen(yy_oper->swhois) < 400) + yy_tmpoper->swhois = rb_strdup(yy_oper->swhois); + else + conf_report_error("Ignoring swhois setting for oper %s -- swhois too long.", yy_oper->name); + } - if(!EmptyString(yy_oper->operstring)) - { - if(strlen(yy_oper->operstring) < 400) - yy_tmpoper->operstring = rb_strdup(yy_oper->operstring); - else - conf_report_error("Ignoring operstring setting for oper %s -- operstring too long.", yy_oper->name); - } + if(!EmptyString(yy_oper->operstring)) { + if(strlen(yy_oper->operstring) < 400) + yy_tmpoper->operstring = rb_strdup(yy_oper->operstring); + else + conf_report_error("Ignoring operstring setting for oper %s -- operstring too long.", yy_oper->name); + } - yy_tmpoper->privset = yy_oper->privset; + yy_tmpoper->privset = yy_oper->privset; #ifdef HAVE_LIBCRYPTO - if(yy_oper->rsa_pubkey_file) - { - BIO *file; + if(yy_oper->rsa_pubkey_file) { + BIO *file; - if((file = BIO_new_file(yy_oper->rsa_pubkey_file, "r")) == NULL) - { - conf_report_error("Ignoring operator block for %s -- " - "rsa_public_key_file cant be opened", - yy_tmpoper->name); - return 0; - } - - yy_tmpoper->rsa_pubkey = - (RSA *) PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); + if((file = BIO_new_file(yy_oper->rsa_pubkey_file, "r")) == NULL) { + conf_report_error("Ignoring operator block for %s -- " + "rsa_public_key_file cant be opened", + yy_tmpoper->name); + return 0; + } - (void)BIO_set_close(file, BIO_CLOSE); - BIO_free(file); + yy_tmpoper->rsa_pubkey = + (RSA *) PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); - if(yy_tmpoper->rsa_pubkey == NULL) - { - conf_report_error("Ignoring operator block for %s -- " - "rsa_public_key_file key invalid; check syntax", - yy_tmpoper->name); - return 0; - } - } + (void)BIO_set_close(file, BIO_CLOSE); + BIO_free(file); - if(!EmptyString(yy_oper->certfp)) - yy_tmpoper->certfp = rb_strdup(yy_oper->certfp); + if(yy_tmpoper->rsa_pubkey == NULL) { + conf_report_error("Ignoring operator block for %s -- " + "rsa_public_key_file key invalid; check syntax", + yy_tmpoper->name); + return 0; + } + } + + if(!EmptyString(yy_oper->certfp)) + yy_tmpoper->certfp = rb_strdup(yy_oper->certfp); #endif - /* all is ok, put it on oper_conf_list */ - rb_dlinkMoveNode(ptr, &yy_oper_list, &oper_conf_list); - } + /* all is ok, put it on oper_conf_list */ + rb_dlinkMoveNode(ptr, &yy_oper_list, &oper_conf_list); + } - free_oper_conf(yy_oper); - yy_oper = NULL; + free_oper_conf(yy_oper); + yy_oper = NULL; - return 0; + return 0; } static void conf_set_oper_flags(void *data) { - conf_parm_t *args = data; + conf_parm_t *args = data; - set_modes_from_table(&yy_oper->flags, "flag", oper_table, args); + set_modes_from_table(&yy_oper->flags, "flag", oper_table, args); } static void conf_set_oper_fingerprint(void *data) { - if (yy_oper->certfp) - rb_free(yy_oper->certfp); - yy_oper->certfp = rb_strdup((char *) data); + if (yy_oper->certfp) + rb_free(yy_oper->certfp); + yy_oper->certfp = rb_strdup((char *) data); } static void conf_set_oper_privset(void *data) { - yy_oper->privset = privilegeset_get((char *) data); + yy_oper->privset = privilegeset_get((char *) data); } static void conf_set_oper_user(void *data) { - struct oper_conf *yy_tmpoper; - char *p; - char *host = (char *) data; + struct oper_conf *yy_tmpoper; + char *p; + char *host = (char *) data; - yy_tmpoper = make_oper_conf(); + yy_tmpoper = make_oper_conf(); - if((p = strchr(host, '@'))) - { - *p++ = '\0'; + if((p = strchr(host, '@'))) { + *p++ = '\0'; - yy_tmpoper->username = rb_strdup(host); - yy_tmpoper->host = rb_strdup(p); - } - else - { + yy_tmpoper->username = rb_strdup(host); + yy_tmpoper->host = rb_strdup(p); + } else { - yy_tmpoper->username = rb_strdup("*"); - yy_tmpoper->host = rb_strdup(host); - } + yy_tmpoper->username = rb_strdup("*"); + yy_tmpoper->host = rb_strdup(host); + } - if(EmptyString(yy_tmpoper->username) || EmptyString(yy_tmpoper->host)) - { - conf_report_error("Ignoring user -- missing username/host"); - free_oper_conf(yy_tmpoper); - return; - } + if(EmptyString(yy_tmpoper->username) || EmptyString(yy_tmpoper->host)) { + conf_report_error("Ignoring user -- missing username/host"); + free_oper_conf(yy_tmpoper); + return; + } - rb_dlinkAddAlloc(yy_tmpoper, &yy_oper_list); + rb_dlinkAddAlloc(yy_tmpoper, &yy_oper_list); } static void conf_set_oper_password(void *data) { - if(yy_oper->passwd) - { - memset(yy_oper->passwd, 0, strlen(yy_oper->passwd)); - rb_free(yy_oper->passwd); - } + if(yy_oper->passwd) { + memset(yy_oper->passwd, 0, strlen(yy_oper->passwd)); + rb_free(yy_oper->passwd); + } - yy_oper->passwd = rb_strdup((char *) data); + yy_oper->passwd = rb_strdup((char *) data); } static void conf_set_oper_rsa_public_key_file(void *data) { #ifdef HAVE_LIBCRYPTO - rb_free(yy_oper->rsa_pubkey_file); - yy_oper->rsa_pubkey_file = rb_strdup((char *) data); + rb_free(yy_oper->rsa_pubkey_file); + yy_oper->rsa_pubkey_file = rb_strdup((char *) data); #else - conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available"); + conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available"); #endif } static void conf_set_oper_umodes(void *data) { - set_modes_from_table(&yy_oper->umodes, "umode", umode_table, data); + set_modes_from_table(&yy_oper->umodes, "umode", umode_table, data); } static void conf_set_oper_snomask(void *data) { - yy_oper->snomask = parse_snobuf_to_mask(0, (const char *) data); + yy_oper->snomask = parse_snobuf_to_mask(0, (const char *) data); } static void conf_set_oper_vhost(void *data) { - yy_oper->vhost = rb_strdup((char *) data); + yy_oper->vhost = rb_strdup((char *) data); } static void conf_set_oper_swhois(void *data) { - yy_oper->swhois = rb_strdup((char *) data); + yy_oper->swhois = rb_strdup((char *) data); } static void conf_set_oper_operstring(void *data) { - yy_oper->operstring = rb_strdup((char *) data); + yy_oper->operstring = rb_strdup((char *) data); } static int conf_begin_class(struct TopConf *tc) { - if(yy_class) - free_class(yy_class); + if(yy_class) + free_class(yy_class); - yy_class = make_class(); - return 0; + yy_class = make_class(); + return 0; } static int conf_end_class(struct TopConf *tc) { - if(conf_cur_block_name != NULL) - yy_class->class_name = rb_strdup(conf_cur_block_name); + if(conf_cur_block_name != NULL) + yy_class->class_name = rb_strdup(conf_cur_block_name); - if(EmptyString(yy_class->class_name)) - { - conf_report_error("Ignoring connect block -- missing name."); - return 0; - } + if(EmptyString(yy_class->class_name)) { + conf_report_error("Ignoring connect block -- missing name."); + return 0; + } - add_class(yy_class); - yy_class = NULL; - return 0; + add_class(yy_class); + yy_class = NULL; + return 0; } static void conf_set_class_ping_time(void *data) { - yy_class->ping_freq = *(unsigned int *) data; + yy_class->ping_freq = *(unsigned int *) data; } static void conf_set_class_cidr_ipv4_bitlen(void *data) { - unsigned int maxsize = 32; - if(*(unsigned int *) data > maxsize) - conf_report_error - ("class::cidr_ipv4_bitlen argument exceeds maxsize (%d > %d) - ignoring.", - *(unsigned int *) data, maxsize); - else - yy_class->cidr_ipv4_bitlen = *(unsigned int *) data; + unsigned int maxsize = 32; + if(*(unsigned int *) data > maxsize) + conf_report_error + ("class::cidr_ipv4_bitlen argument exceeds maxsize (%d > %d) - ignoring.", + *(unsigned int *) data, maxsize); + else + yy_class->cidr_ipv4_bitlen = *(unsigned int *) data; } @@ -804,13 +757,13 @@ conf_set_class_cidr_ipv4_bitlen(void *data) static void conf_set_class_cidr_ipv6_bitlen(void *data) { - unsigned int maxsize = 128; - if(*(unsigned int *) data > maxsize) - conf_report_error - ("class::cidr_ipv6_bitlen argument exceeds maxsize (%d > %d) - ignoring.", - *(unsigned int *) data, maxsize); - else - yy_class->cidr_ipv6_bitlen = *(unsigned int *) data; + unsigned int maxsize = 128; + if(*(unsigned int *) data > maxsize) + conf_report_error + ("class::cidr_ipv6_bitlen argument exceeds maxsize (%d > %d) - ignoring.", + *(unsigned int *) data, maxsize); + else + yy_class->cidr_ipv6_bitlen = *(unsigned int *) data; } #endif @@ -818,44 +771,44 @@ conf_set_class_cidr_ipv6_bitlen(void *data) static void conf_set_class_number_per_cidr(void *data) { - yy_class->cidr_amount = *(unsigned int *) data; + yy_class->cidr_amount = *(unsigned int *) data; } static void conf_set_class_number_per_ip(void *data) { - yy_class->max_local = *(unsigned int *) data; + yy_class->max_local = *(unsigned int *) data; } static void conf_set_class_number_per_ip_global(void *data) { - yy_class->max_global = *(unsigned int *) data; + yy_class->max_global = *(unsigned int *) data; } static void conf_set_class_number_per_ident(void *data) { - yy_class->max_ident = *(unsigned int *) data; + yy_class->max_ident = *(unsigned int *) data; } static void conf_set_class_connectfreq(void *data) { - yy_class->con_freq = *(unsigned int *) data; + yy_class->con_freq = *(unsigned int *) data; } static void conf_set_class_max_number(void *data) { - yy_class->max_total = *(unsigned int *) data; + yy_class->max_total = *(unsigned int *) data; } static void conf_set_class_sendq(void *data) { - yy_class->max_sendq = *(unsigned int *) data; + yy_class->max_sendq = *(unsigned int *) data; } static char *listener_address; @@ -863,320 +816,300 @@ static char *listener_address; static int conf_begin_listen(struct TopConf *tc) { - rb_free(listener_address); - listener_address = NULL; - return 0; + rb_free(listener_address); + listener_address = NULL; + return 0; } static int conf_end_listen(struct TopConf *tc) { - rb_free(listener_address); - listener_address = NULL; - return 0; + rb_free(listener_address); + listener_address = NULL; + return 0; } static void conf_set_listen_defer_accept(void *data) { - yy_defer_accept = *(unsigned int *) data; + yy_defer_accept = *(unsigned int *) data; } static void conf_set_listen_port_both(void *data, int ssl) { - conf_parm_t *args = data; - for (; args; args = args->next) - { - if((args->type & CF_MTYPE) != CF_INT) - { - conf_report_error - ("listener::port argument is not an integer " "-- ignoring."); - continue; - } - if(listener_address == NULL) - { - add_listener(args->v.number, listener_address, AF_INET, ssl, yy_defer_accept); + conf_parm_t *args = data; + for (; args; args = args->next) { + if((args->type & CF_MTYPE) != CF_INT) { + conf_report_error + ("listener::port argument is not an integer " "-- ignoring."); + continue; + } + if(listener_address == NULL) { + add_listener(args->v.number, listener_address, AF_INET, ssl, yy_defer_accept); #ifdef RB_IPV6 - add_listener(args->v.number, listener_address, AF_INET6, ssl, yy_defer_accept); + add_listener(args->v.number, listener_address, AF_INET6, ssl, yy_defer_accept); #endif - } - else - { - int family; + } else { + int family; #ifdef RB_IPV6 - if(strchr(listener_address, ':') != NULL) - family = AF_INET6; - else + if(strchr(listener_address, ':') != NULL) + family = AF_INET6; + else #endif - family = AF_INET; - - add_listener(args->v.number, listener_address, family, ssl, yy_defer_accept); - - } + family = AF_INET; - } + add_listener(args->v.number, listener_address, family, ssl, yy_defer_accept); + + } + + } } static void conf_set_listen_port(void *data) { - conf_set_listen_port_both(data, 0); + conf_set_listen_port_both(data, 0); } static void conf_set_listen_sslport(void *data) { - conf_set_listen_port_both(data, 1); + conf_set_listen_port_both(data, 1); } static void conf_set_listen_address(void *data) { - rb_free(listener_address); - listener_address = rb_strdup(data); + rb_free(listener_address); + listener_address = rb_strdup(data); } static int conf_begin_auth(struct TopConf *tc) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - if(yy_aconf) - free_conf(yy_aconf); + if(yy_aconf) + free_conf(yy_aconf); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head) - { - free_conf(ptr->data); - rb_dlinkDestroy(ptr, &yy_aconf_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head) { + free_conf(ptr->data); + rb_dlinkDestroy(ptr, &yy_aconf_list); + } - yy_aconf = make_conf(); - yy_aconf->status = CONF_CLIENT; + yy_aconf = make_conf(); + yy_aconf->status = CONF_CLIENT; - return 0; + return 0; } static int conf_end_auth(struct TopConf *tc) { - struct ConfItem *yy_tmp, *found_conf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct ConfItem *yy_tmp, *found_conf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - if(EmptyString(yy_aconf->info.name)) - yy_aconf->info.name = rb_strdup("NOMATCH"); + if(EmptyString(yy_aconf->info.name)) + yy_aconf->info.name = rb_strdup("NOMATCH"); - /* didnt even get one ->host? */ - if(EmptyString(yy_aconf->host)) - { - conf_report_error("Ignoring auth block -- missing user@host"); - return 0; - } + /* didnt even get one ->host? */ + if(EmptyString(yy_aconf->host)) { + conf_report_error("Ignoring auth block -- missing user@host"); + return 0; + } - /* so the stacking works in order.. */ - collapse(yy_aconf->user); - collapse(yy_aconf->host); - conf_add_class_to_conf(yy_aconf); - if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL) - conf_report_error("Ignoring redundant auth block (after *@*)"); - else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) && - (!found_conf->spasswd || (yy_aconf->spasswd && - 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd)))) - conf_report_error("Ignoring duplicate auth block for %s@%s", - yy_aconf->user, yy_aconf->host); - else - add_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user, yy_aconf->spasswd, yy_aconf); + /* so the stacking works in order.. */ + collapse(yy_aconf->user); + collapse(yy_aconf->host); + conf_add_class_to_conf(yy_aconf); + if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL) + conf_report_error("Ignoring redundant auth block (after *@*)"); + else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) && + (!found_conf->spasswd || (yy_aconf->spasswd && + 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd)))) + conf_report_error("Ignoring duplicate auth block for %s@%s", + yy_aconf->user, yy_aconf->host); + else + add_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user, yy_aconf->spasswd, yy_aconf); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head) - { - yy_tmp = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head) { + yy_tmp = ptr->data; - if(yy_aconf->passwd) - yy_tmp->passwd = rb_strdup(yy_aconf->passwd); + if(yy_aconf->passwd) + yy_tmp->passwd = rb_strdup(yy_aconf->passwd); - if(yy_aconf->spasswd) - yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd); - - /* this will always exist.. */ - yy_tmp->info.name = rb_strdup(yy_aconf->info.name); + if(yy_aconf->spasswd) + yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd); - if(yy_aconf->className) - yy_tmp->className = rb_strdup(yy_aconf->className); + /* this will always exist.. */ + yy_tmp->info.name = rb_strdup(yy_aconf->info.name); - yy_tmp->flags = yy_aconf->flags; - yy_tmp->port = yy_aconf->port; + if(yy_aconf->className) + yy_tmp->className = rb_strdup(yy_aconf->className); - collapse(yy_tmp->user); - collapse(yy_tmp->host); + yy_tmp->flags = yy_aconf->flags; + yy_tmp->port = yy_aconf->port; - conf_add_class_to_conf(yy_tmp); + collapse(yy_tmp->user); + collapse(yy_tmp->host); - if (find_exact_conf_by_address("*", CONF_CLIENT, "*")) - conf_report_error("Ignoring redundant auth block (after *@*)"); - else if (find_exact_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user)) - conf_report_error("Ignoring duplicate auth block for %s@%s", - yy_tmp->user, yy_tmp->host); - else - add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp); - rb_dlinkDestroy(ptr, &yy_aconf_list); - } + conf_add_class_to_conf(yy_tmp); - yy_aconf = NULL; - return 0; + if (find_exact_conf_by_address("*", CONF_CLIENT, "*")) + conf_report_error("Ignoring redundant auth block (after *@*)"); + else if (find_exact_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user)) + conf_report_error("Ignoring duplicate auth block for %s@%s", + yy_tmp->user, yy_tmp->host); + else + add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp); + rb_dlinkDestroy(ptr, &yy_aconf_list); + } + + yy_aconf = NULL; + return 0; } static void conf_set_auth_user(void *data) { - struct ConfItem *yy_tmp; - char *p; + struct ConfItem *yy_tmp; + char *p; - /* The first user= line doesn't allocate a new conf */ - if(!EmptyString(yy_aconf->host)) - { - yy_tmp = make_conf(); - yy_tmp->status = CONF_CLIENT; - } - else - yy_tmp = yy_aconf; + /* The first user= line doesn't allocate a new conf */ + if(!EmptyString(yy_aconf->host)) { + yy_tmp = make_conf(); + yy_tmp->status = CONF_CLIENT; + } else + yy_tmp = yy_aconf; - if((p = strchr(data, '@'))) - { - *p++ = '\0'; + if((p = strchr(data, '@'))) { + *p++ = '\0'; - yy_tmp->user = rb_strdup(data); - yy_tmp->host = rb_strdup(p); - } - else - { - yy_tmp->user = rb_strdup("*"); - yy_tmp->host = rb_strdup(data); - } + yy_tmp->user = rb_strdup(data); + yy_tmp->host = rb_strdup(p); + } else { + yy_tmp->user = rb_strdup("*"); + yy_tmp->host = rb_strdup(data); + } - if(yy_aconf != yy_tmp) - rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list); + if(yy_aconf != yy_tmp) + rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list); } static void conf_set_auth_auth_user(void *data) { - if(yy_aconf->spasswd) - memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd)); - rb_free(yy_aconf->spasswd); - yy_aconf->spasswd = rb_strdup(data); + if(yy_aconf->spasswd) + memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd)); + rb_free(yy_aconf->spasswd); + yy_aconf->spasswd = rb_strdup(data); } static void conf_set_auth_passwd(void *data) { - if(yy_aconf->passwd) - memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd)); - rb_free(yy_aconf->passwd); - yy_aconf->passwd = rb_strdup(data); + if(yy_aconf->passwd) + memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd)); + rb_free(yy_aconf->passwd); + yy_aconf->passwd = rb_strdup(data); } static void conf_set_auth_autojoin(void *data) { - if(yy_aconf->autojoin) - memset(yy_aconf->autojoin, 0, strlen(yy_aconf->autojoin)); - rb_free(yy_aconf->autojoin); - yy_aconf->autojoin = rb_strdup(data); + if(yy_aconf->autojoin) + memset(yy_aconf->autojoin, 0, strlen(yy_aconf->autojoin)); + rb_free(yy_aconf->autojoin); + yy_aconf->autojoin = rb_strdup(data); } static void conf_set_auth_spoof(void *data) { - char *p; - char *user = NULL; - char *host = NULL; + char *p; + char *user = NULL; + char *host = NULL; - host = data; + host = data; - /* user@host spoof */ - if((p = strchr(host, '@')) != NULL) - { - *p = '\0'; - user = data; - host = p+1; + /* user@host spoof */ + if((p = strchr(host, '@')) != NULL) { + *p = '\0'; + user = data; + host = p+1; - if(EmptyString(user)) - { - conf_report_error("Warning -- spoof ident empty."); - return; - } + if(EmptyString(user)) { + conf_report_error("Warning -- spoof ident empty."); + return; + } - if(strlen(user) > USERLEN) - { - conf_report_error("Warning -- spoof ident length invalid."); - return; - } + if(strlen(user) > USERLEN) { + conf_report_error("Warning -- spoof ident length invalid."); + return; + } - if(!valid_username(user)) - { - conf_report_error("Warning -- invalid spoof (ident)."); - return; - } + if(!valid_username(user)) { + conf_report_error("Warning -- invalid spoof (ident)."); + return; + } - /* this must be restored! */ - *p = '@'; - } + /* this must be restored! */ + *p = '@'; + } - if(EmptyString(host)) - { - conf_report_error("Warning -- spoof host empty."); - return; - } + if(EmptyString(host)) { + conf_report_error("Warning -- spoof host empty."); + return; + } - if(strlen(host) > HOSTLEN) - { - conf_report_error("Warning -- spoof host length invalid."); - return; - } + if(strlen(host) > HOSTLEN) { + conf_report_error("Warning -- spoof host length invalid."); + return; + } - if(!valid_hostname(host)) - { - conf_report_error("Warning -- invalid spoof (host)."); - return; - } + if(!valid_hostname(host)) { + conf_report_error("Warning -- invalid spoof (host)."); + return; + } - rb_free(yy_aconf->info.name); - yy_aconf->info.name = rb_strdup(data); - yy_aconf->flags |= CONF_FLAGS_SPOOF_IP; + rb_free(yy_aconf->info.name); + yy_aconf->info.name = rb_strdup(data); + yy_aconf->flags |= CONF_FLAGS_SPOOF_IP; } static void conf_set_auth_flags(void *data) { - conf_parm_t *args = data; + conf_parm_t *args = data; - set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args); + set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args); } static void conf_set_auth_redir_serv(void *data) { - yy_aconf->flags |= CONF_FLAGS_REDIR; - rb_free(yy_aconf->info.name); - yy_aconf->info.name = rb_strdup(data); + yy_aconf->flags |= CONF_FLAGS_REDIR; + rb_free(yy_aconf->info.name); + yy_aconf->info.name = rb_strdup(data); } static void conf_set_auth_redir_port(void *data) { - int port = *(unsigned int *) data; + int port = *(unsigned int *) data; - yy_aconf->flags |= CONF_FLAGS_REDIR; - yy_aconf->port = port; + yy_aconf->flags |= CONF_FLAGS_REDIR; + yy_aconf->port = port; } static void conf_set_auth_class(void *data) { - rb_free(yy_aconf->className); - yy_aconf->className = rb_strdup(data); + rb_free(yy_aconf->className); + yy_aconf->className = rb_strdup(data); } /* ok, shared_oper handles the stacking, shared_flags handles adding @@ -1186,730 +1119,688 @@ conf_set_auth_class(void *data) static int conf_cleanup_shared(struct TopConf *tc) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head) - { - free_remote_conf(ptr->data); - rb_dlinkDestroy(ptr, &yy_shared_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head) { + free_remote_conf(ptr->data); + rb_dlinkDestroy(ptr, &yy_shared_list); + } - if(yy_shared != NULL) - { - free_remote_conf(yy_shared); - yy_shared = NULL; - } + if(yy_shared != NULL) { + free_remote_conf(yy_shared); + yy_shared = NULL; + } - return 0; + return 0; } static void conf_set_shared_oper(void *data) { - conf_parm_t *args = data; - const char *username; - char *p; + conf_parm_t *args = data; + const char *username; + char *p; - if(yy_shared != NULL) - free_remote_conf(yy_shared); + if(yy_shared != NULL) + free_remote_conf(yy_shared); - yy_shared = make_remote_conf(); + yy_shared = make_remote_conf(); - if(args->next != NULL) - { - if((args->type & CF_MTYPE) != CF_QSTRING) - { - conf_report_error("Ignoring shared::oper -- server is not a qstring"); - return; - } + if(args->next != NULL) { + if((args->type & CF_MTYPE) != CF_QSTRING) { + conf_report_error("Ignoring shared::oper -- server is not a qstring"); + return; + } - yy_shared->server = rb_strdup(args->v.string); - args = args->next; - } - else - yy_shared->server = rb_strdup("*"); + yy_shared->server = rb_strdup(args->v.string); + args = args->next; + } else + yy_shared->server = rb_strdup("*"); - if((args->type & CF_MTYPE) != CF_QSTRING) - { - conf_report_error("Ignoring shared::oper -- oper is not a qstring"); - return; - } + if((args->type & CF_MTYPE) != CF_QSTRING) { + conf_report_error("Ignoring shared::oper -- oper is not a qstring"); + return; + } - if((p = strchr(args->v.string, '@')) == NULL) - { - conf_report_error("Ignoring shared::oper -- oper is not a user@host"); - return; - } + if((p = strchr(args->v.string, '@')) == NULL) { + conf_report_error("Ignoring shared::oper -- oper is not a user@host"); + return; + } - username = args->v.string; - *p++ = '\0'; + username = args->v.string; + *p++ = '\0'; - if(EmptyString(p)) - yy_shared->host = rb_strdup("*"); - else - yy_shared->host = rb_strdup(p); + if(EmptyString(p)) + yy_shared->host = rb_strdup("*"); + else + yy_shared->host = rb_strdup(p); - if(EmptyString(username)) - yy_shared->username = rb_strdup("*"); - else - yy_shared->username = rb_strdup(username); + if(EmptyString(username)) + yy_shared->username = rb_strdup("*"); + else + yy_shared->username = rb_strdup(username); - rb_dlinkAddAlloc(yy_shared, &yy_shared_list); - yy_shared = NULL; + rb_dlinkAddAlloc(yy_shared, &yy_shared_list); + yy_shared = NULL; } static void conf_set_shared_flags(void *data) { - conf_parm_t *args = data; - int flags = 0; - rb_dlink_node *ptr, *next_ptr; + conf_parm_t *args = data; + int flags = 0; + rb_dlink_node *ptr, *next_ptr; - if(yy_shared != NULL) - free_remote_conf(yy_shared); + if(yy_shared != NULL) + free_remote_conf(yy_shared); - set_modes_from_table(&flags, "flag", shared_table, args); + set_modes_from_table(&flags, "flag", shared_table, args); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head) - { - yy_shared = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head) { + yy_shared = ptr->data; - yy_shared->flags = flags; - rb_dlinkDestroy(ptr, &yy_shared_list); - rb_dlinkAddTail(yy_shared, &yy_shared->node, &shared_conf_list); - } + yy_shared->flags = flags; + rb_dlinkDestroy(ptr, &yy_shared_list); + rb_dlinkAddTail(yy_shared, &yy_shared->node, &shared_conf_list); + } - yy_shared = NULL; + yy_shared = NULL; } static int conf_begin_connect(struct TopConf *tc) { - if(yy_server) - free_server_conf(yy_server); + if(yy_server) + free_server_conf(yy_server); - yy_server = make_server_conf(); - yy_server->port = PORTNUM; - yy_server->flags |= SERVER_TB; + yy_server = make_server_conf(); + yy_server->port = PORTNUM; + yy_server->flags |= SERVER_TB; - if(conf_cur_block_name != NULL) - yy_server->name = rb_strdup(conf_cur_block_name); + if(conf_cur_block_name != NULL) + yy_server->name = rb_strdup(conf_cur_block_name); - return 0; + return 0; } static int conf_end_connect(struct TopConf *tc) { - if(EmptyString(yy_server->name)) - { - conf_report_error("Ignoring connect block -- missing name."); - return 0; - } + if(EmptyString(yy_server->name)) { + conf_report_error("Ignoring connect block -- missing name."); + return 0; + } - if(ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name)) - { - conf_report_error("Ignoring connect block for %s -- name is equal to my own name.", - yy_server->name); - return 0; - } + if(ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name)) { + conf_report_error("Ignoring connect block for %s -- name is equal to my own name.", + yy_server->name); + return 0; + } - if((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd)) && EmptyString(yy_server->certfp)) - { - conf_report_error("Ignoring connect block for %s -- no fingerprint or password credentials provided.", - yy_server->name); - return 0; - } + if((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd)) && EmptyString(yy_server->certfp)) { + conf_report_error("Ignoring connect block for %s -- no fingerprint or password credentials provided.", + yy_server->name); + return 0; + } - if(EmptyString(yy_server->host)) - { - conf_report_error("Ignoring connect block for %s -- missing host.", - yy_server->name); - return 0; - } + if(EmptyString(yy_server->host)) { + conf_report_error("Ignoring connect block for %s -- missing host.", + yy_server->name); + return 0; + } #ifndef HAVE_LIBZ - if(ServerConfCompressed(yy_server)) - { - conf_report_error("Ignoring connect::flags::compressed -- zlib not available."); - yy_server->flags &= ~SERVER_COMPRESSED; - } + if(ServerConfCompressed(yy_server)) { + conf_report_error("Ignoring connect::flags::compressed -- zlib not available."); + yy_server->flags &= ~SERVER_COMPRESSED; + } #endif - add_server_conf(yy_server); - rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list); + add_server_conf(yy_server); + rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list); - yy_server = NULL; - return 0; + yy_server = NULL; + return 0; } static void conf_set_connect_host(void *data) { - rb_free(yy_server->host); - yy_server->host = rb_strdup(data); - if (strchr(yy_server->host, ':')) - yy_server->aftype = AF_INET6; + rb_free(yy_server->host); + yy_server->host = rb_strdup(data); + if (strchr(yy_server->host, ':')) + yy_server->aftype = AF_INET6; } static void conf_set_connect_vhost(void *data) { - if(rb_inet_pton_sock(data, (struct sockaddr *)&yy_server->my_ipnum) <= 0) - { - conf_report_error("Invalid netmask for server vhost (%s)", - (char *) data); - return; - } + if(rb_inet_pton_sock(data, (struct sockaddr *)&yy_server->my_ipnum) <= 0) { + conf_report_error("Invalid netmask for server vhost (%s)", + (char *) data); + return; + } - yy_server->flags |= SERVER_VHOSTED; + yy_server->flags |= SERVER_VHOSTED; } static void conf_set_connect_send_password(void *data) { - if(yy_server->spasswd) - { - memset(yy_server->spasswd, 0, strlen(yy_server->spasswd)); - rb_free(yy_server->spasswd); - } + if(yy_server->spasswd) { + memset(yy_server->spasswd, 0, strlen(yy_server->spasswd)); + rb_free(yy_server->spasswd); + } - yy_server->spasswd = rb_strdup(data); + yy_server->spasswd = rb_strdup(data); } static void conf_set_connect_accept_password(void *data) { - if(yy_server->passwd) - { - memset(yy_server->passwd, 0, strlen(yy_server->passwd)); - rb_free(yy_server->passwd); - } - yy_server->passwd = rb_strdup(data); + if(yy_server->passwd) { + memset(yy_server->passwd, 0, strlen(yy_server->passwd)); + rb_free(yy_server->passwd); + } + yy_server->passwd = rb_strdup(data); } static void conf_set_connect_fingerprint(void *data) { - if (yy_server->certfp) - rb_free(yy_server->certfp); - yy_server->certfp = rb_strdup((char *) data); + if (yy_server->certfp) + rb_free(yy_server->certfp); + yy_server->certfp = rb_strdup((char *) data); - /* force SSL to be enabled if fingerprint is enabled. */ - yy_server->flags |= SERVER_SSL; + /* force SSL to be enabled if fingerprint is enabled. */ + yy_server->flags |= SERVER_SSL; } static void conf_set_connect_port(void *data) { - int port = *(unsigned int *) data; + int port = *(unsigned int *) data; - if(port < 1) - port = PORTNUM; + if(port < 1) + port = PORTNUM; - yy_server->port = port; + yy_server->port = port; } static void conf_set_connect_aftype(void *data) { - char *aft = data; + char *aft = data; - if(strcasecmp(aft, "ipv4") == 0) - yy_server->aftype = AF_INET; + if(strcasecmp(aft, "ipv4") == 0) + yy_server->aftype = AF_INET; #ifdef RB_IPV6 - else if(strcasecmp(aft, "ipv6") == 0) - yy_server->aftype = AF_INET6; + else if(strcasecmp(aft, "ipv6") == 0) + yy_server->aftype = AF_INET6; #endif - else - conf_report_error("connect::aftype '%s' is unknown.", aft); + else + conf_report_error("connect::aftype '%s' is unknown.", aft); } static void conf_set_connect_flags(void *data) { - conf_parm_t *args = data; + conf_parm_t *args = data; - /* note, we allow them to set compressed, then remove it later if - * they do and LIBZ isnt available - */ - set_modes_from_table(&yy_server->flags, "flag", connect_table, args); + /* note, we allow them to set compressed, then remove it later if + * they do and LIBZ isnt available + */ + set_modes_from_table(&yy_server->flags, "flag", connect_table, args); } static void conf_set_connect_hub_mask(void *data) { - struct remote_conf *yy_hub; + struct remote_conf *yy_hub; - if(EmptyString(yy_server->name)) - return; + if(EmptyString(yy_server->name)) + return; - yy_hub = make_remote_conf(); - yy_hub->flags = CONF_HUB; + yy_hub = make_remote_conf(); + yy_hub->flags = CONF_HUB; - yy_hub->host = rb_strdup(data); - yy_hub->server = rb_strdup(yy_server->name); - rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list); + yy_hub->host = rb_strdup(data); + yy_hub->server = rb_strdup(yy_server->name); + rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list); } static void conf_set_connect_leaf_mask(void *data) { - struct remote_conf *yy_leaf; + struct remote_conf *yy_leaf; - if(EmptyString(yy_server->name)) - return; + if(EmptyString(yy_server->name)) + return; - yy_leaf = make_remote_conf(); - yy_leaf->flags = CONF_LEAF; + yy_leaf = make_remote_conf(); + yy_leaf->flags = CONF_LEAF; - yy_leaf->host = rb_strdup(data); - yy_leaf->server = rb_strdup(yy_server->name); - rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list); + yy_leaf->host = rb_strdup(data); + yy_leaf->server = rb_strdup(yy_server->name); + rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list); } static void conf_set_connect_class(void *data) { - rb_free(yy_server->class_name); - yy_server->class_name = rb_strdup(data); + rb_free(yy_server->class_name); + yy_server->class_name = rb_strdup(data); } static void conf_set_exempt_ip(void *data) { - struct ConfItem *yy_tmp; + struct ConfItem *yy_tmp; - if(parse_netmask(data, NULL, NULL) == HM_HOST) - { - conf_report_error("Ignoring exempt -- invalid exempt::ip."); - return; - } + if(parse_netmask(data, NULL, NULL) == HM_HOST) { + conf_report_error("Ignoring exempt -- invalid exempt::ip."); + return; + } - yy_tmp = make_conf(); - yy_tmp->passwd = rb_strdup("*"); - yy_tmp->host = rb_strdup(data); - yy_tmp->status = CONF_EXEMPTDLINE; - add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp); + yy_tmp = make_conf(); + yy_tmp->passwd = rb_strdup("*"); + yy_tmp->host = rb_strdup(data); + yy_tmp->status = CONF_EXEMPTDLINE; + add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp); } static int conf_cleanup_cluster(struct TopConf *tc) { - rb_dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head) - { - free_remote_conf(ptr->data); - rb_dlinkDestroy(ptr, &yy_cluster_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head) { + free_remote_conf(ptr->data); + rb_dlinkDestroy(ptr, &yy_cluster_list); + } - if(yy_shared != NULL) - { - free_remote_conf(yy_shared); - yy_shared = NULL; - } + if(yy_shared != NULL) { + free_remote_conf(yy_shared); + yy_shared = NULL; + } - return 0; + return 0; } static void conf_set_cluster_name(void *data) { - if(yy_shared != NULL) - free_remote_conf(yy_shared); + if(yy_shared != NULL) + free_remote_conf(yy_shared); - yy_shared = make_remote_conf(); - yy_shared->server = rb_strdup(data); - rb_dlinkAddAlloc(yy_shared, &yy_cluster_list); + yy_shared = make_remote_conf(); + yy_shared->server = rb_strdup(data); + rb_dlinkAddAlloc(yy_shared, &yy_cluster_list); - yy_shared = NULL; + yy_shared = NULL; } static void conf_set_cluster_flags(void *data) { - conf_parm_t *args = data; - int flags = 0; - rb_dlink_node *ptr, *next_ptr; + conf_parm_t *args = data; + int flags = 0; + rb_dlink_node *ptr, *next_ptr; - if(yy_shared != NULL) - free_remote_conf(yy_shared); + if(yy_shared != NULL) + free_remote_conf(yy_shared); - set_modes_from_table(&flags, "flag", cluster_table, args); + set_modes_from_table(&flags, "flag", cluster_table, args); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head) - { - yy_shared = ptr->data; - yy_shared->flags = flags; - rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list); - rb_dlinkDestroy(ptr, &yy_cluster_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head) { + yy_shared = ptr->data; + yy_shared->flags = flags; + rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list); + rb_dlinkDestroy(ptr, &yy_cluster_list); + } - yy_shared = NULL; + yy_shared = NULL; } static void conf_set_general_havent_read_conf(void *data) { - if(*(unsigned int *) data) - { - conf_report_error("You haven't read your config file properly."); - conf_report_error - ("There is a line in the example conf that will kill your server if not removed."); - conf_report_error - ("Consider actually reading/editing the conf file, and removing this line."); - if (!testing_conf) - exit(0); - } + if(*(unsigned int *) data) { + conf_report_error("You haven't read your config file properly."); + conf_report_error + ("There is a line in the example conf that will kill your server if not removed."); + conf_report_error + ("Consider actually reading/editing the conf file, and removing this line."); + if (!testing_conf) + exit(0); + } } static void conf_set_general_hide_error_messages(void *data) { - char *val = data; + char *val = data; - if(strcasecmp(val, "yes") == 0) - ConfigFileEntry.hide_error_messages = 2; - else if(strcasecmp(val, "opers") == 0) - ConfigFileEntry.hide_error_messages = 1; - else if(strcasecmp(val, "no") == 0) - ConfigFileEntry.hide_error_messages = 0; - else - conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val); + if(strcasecmp(val, "yes") == 0) + ConfigFileEntry.hide_error_messages = 2; + else if(strcasecmp(val, "opers") == 0) + ConfigFileEntry.hide_error_messages = 1; + else if(strcasecmp(val, "no") == 0) + ConfigFileEntry.hide_error_messages = 0; + else + conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val); } static void conf_set_general_kline_delay(void *data) { - ConfigFileEntry.kline_delay = *(unsigned int *) data; + ConfigFileEntry.kline_delay = *(unsigned int *) data; - /* THIS MUST BE HERE to stop us being unable to check klines */ - kline_queued = 0; + /* THIS MUST BE HERE to stop us being unable to check klines */ + kline_queued = 0; } static void conf_set_general_stats_k_oper_only(void *data) { - char *val = data; + char *val = data; - if(strcasecmp(val, "yes") == 0) - ConfigFileEntry.stats_k_oper_only = 2; - else if(strcasecmp(val, "masked") == 0) - ConfigFileEntry.stats_k_oper_only = 1; - else if(strcasecmp(val, "no") == 0) - ConfigFileEntry.stats_k_oper_only = 0; - else - conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val); + if(strcasecmp(val, "yes") == 0) + ConfigFileEntry.stats_k_oper_only = 2; + else if(strcasecmp(val, "masked") == 0) + ConfigFileEntry.stats_k_oper_only = 1; + else if(strcasecmp(val, "no") == 0) + ConfigFileEntry.stats_k_oper_only = 0; + else + conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val); } static void conf_set_general_stats_i_oper_only(void *data) { - char *val = data; + char *val = data; - if(strcasecmp(val, "yes") == 0) - ConfigFileEntry.stats_i_oper_only = 2; - else if(strcasecmp(val, "masked") == 0) - ConfigFileEntry.stats_i_oper_only = 1; - else if(strcasecmp(val, "no") == 0) - ConfigFileEntry.stats_i_oper_only = 0; - else - conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val); + if(strcasecmp(val, "yes") == 0) + ConfigFileEntry.stats_i_oper_only = 2; + else if(strcasecmp(val, "masked") == 0) + ConfigFileEntry.stats_i_oper_only = 1; + else if(strcasecmp(val, "no") == 0) + ConfigFileEntry.stats_i_oper_only = 0; + else + conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val); } static void conf_set_general_compression_level(void *data) { #ifdef HAVE_LIBZ - ConfigFileEntry.compression_level = *(unsigned int *) data; + ConfigFileEntry.compression_level = *(unsigned int *) data; - if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9)) - { - conf_report_error - ("Invalid general::compression_level %d -- using default.", - ConfigFileEntry.compression_level); - ConfigFileEntry.compression_level = 0; - } + if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9)) { + conf_report_error + ("Invalid general::compression_level %d -- using default.", + ConfigFileEntry.compression_level); + ConfigFileEntry.compression_level = 0; + } #else - conf_report_error("Ignoring general::compression_level -- zlib not available."); + conf_report_error("Ignoring general::compression_level -- zlib not available."); #endif } static void conf_set_general_default_umodes(void *data) { - char *pm; - int what = MODE_ADD, flag; + char *pm; + int what = MODE_ADD, flag; - ConfigFileEntry.default_umodes = 0; - for (pm = (char *) data; *pm; pm++) - { - switch (*pm) - { - case '+': - what = MODE_ADD; - break; - case '-': - what = MODE_DEL; - break; + ConfigFileEntry.default_umodes = 0; + for (pm = (char *) data; *pm; pm++) { + switch (*pm) { + case '+': + what = MODE_ADD; + break; + case '-': + what = MODE_DEL; + break; - /* don't allow +o */ - case 'o': - case 'S': - case 'Z': - case ' ': - break; + /* don't allow +o */ + case 'o': + case 'S': + case 'Z': + case ' ': + break; - default: - if ((flag = user_modes[(unsigned char) *pm])) - { - /* Proper value has probably not yet been set - * so don't check oper_only_umodes -- jilles */ - if (what == MODE_ADD) - ConfigFileEntry.default_umodes |= flag; - else - ConfigFileEntry.default_umodes &= ~flag; - } - break; - } - } + default: + if ((flag = user_modes[(unsigned char) *pm])) { + /* Proper value has probably not yet been set + * so don't check oper_only_umodes -- jilles */ + if (what == MODE_ADD) + ConfigFileEntry.default_umodes |= flag; + else + ConfigFileEntry.default_umodes &= ~flag; + } + break; + } + } } static void conf_set_general_oper_umodes(void *data) { - set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data); + set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data); } static void conf_set_general_oper_only_umodes(void *data) { - set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data); + set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data); } static void conf_set_general_oper_snomask(void *data) { - char *pm; - int what = MODE_ADD, flag; + char *pm; + int what = MODE_ADD, flag; - ConfigFileEntry.oper_snomask = 0; - for (pm = (char *) data; *pm; pm++) - { - switch (*pm) - { - case '+': - what = MODE_ADD; - break; - case '-': - what = MODE_DEL; - break; + ConfigFileEntry.oper_snomask = 0; + for (pm = (char *) data; *pm; pm++) { + switch (*pm) { + case '+': + what = MODE_ADD; + break; + case '-': + what = MODE_DEL; + break; - default: - if ((flag = snomask_modes[(unsigned char) *pm])) - { - if (what == MODE_ADD) - ConfigFileEntry.oper_snomask |= flag; - else - ConfigFileEntry.oper_snomask &= ~flag; - } - break; - } - } + default: + if ((flag = snomask_modes[(unsigned char) *pm])) { + if (what == MODE_ADD) + ConfigFileEntry.oper_snomask |= flag; + else + ConfigFileEntry.oper_snomask &= ~flag; + } + break; + } + } } static void conf_set_serverhide_links_delay(void *data) { - int val = *(unsigned int *) data; + int val = *(unsigned int *) data; - ConfigServerHide.links_delay = val; + ConfigServerHide.links_delay = val; } static int conf_begin_service(struct TopConf *tc) { - struct Client *target_p; - rb_dlink_node *ptr; + struct Client *target_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + target_p = ptr->data; - target_p->flags &= ~FLAGS_SERVICE; - } + target_p->flags &= ~FLAGS_SERVICE; + } - return 0; + return 0; } static void conf_set_service_name(void *data) { - struct Client *target_p; - const char *s; - char *tmp; - int dots = 0; + struct Client *target_p; + const char *s; + char *tmp; + int dots = 0; - for(s = data; *s != '\0'; s++) - { - if(!IsServChar(*s)) - { - conf_report_error("Ignoring service::name " - "-- bogus servername."); - return; - } - else if(*s == '.') - dots++; - } + for(s = data; *s != '\0'; s++) { + if(!IsServChar(*s)) { + conf_report_error("Ignoring service::name " + "-- bogus servername."); + return; + } else if(*s == '.') + dots++; + } - if(!dots) - { - conf_report_error("Ignoring service::name -- must contain '.'"); - return; - } + if(!dots) { + conf_report_error("Ignoring service::name -- must contain '.'"); + return; + } - tmp = rb_strdup(data); - rb_dlinkAddAlloc(tmp, &service_list); + tmp = rb_strdup(data); + rb_dlinkAddAlloc(tmp, &service_list); - if((target_p = find_server(NULL, tmp))) - target_p->flags |= FLAGS_SERVICE; + if((target_p = find_server(NULL, tmp))) + target_p->flags |= FLAGS_SERVICE; } static int conf_begin_alias(struct TopConf *tc) { - yy_alias = rb_malloc(sizeof(struct alias_entry)); + yy_alias = rb_malloc(sizeof(struct alias_entry)); - if (conf_cur_block_name != NULL) - yy_alias->name = rb_strdup(conf_cur_block_name); + if (conf_cur_block_name != NULL) + yy_alias->name = rb_strdup(conf_cur_block_name); - yy_alias->flags = 0; - yy_alias->hits = 0; + yy_alias->flags = 0; + yy_alias->hits = 0; - return 0; + return 0; } static int conf_end_alias(struct TopConf *tc) { - if (yy_alias == NULL) - return -1; + if (yy_alias == NULL) + return -1; - if (yy_alias->name == NULL) - { - conf_report_error("Ignoring alias -- must have a name."); + if (yy_alias->name == NULL) { + conf_report_error("Ignoring alias -- must have a name."); - rb_free(yy_alias); + rb_free(yy_alias); - return -1; - } + return -1; + } - if (yy_alias->target == NULL) - { - conf_report_error("Ignoring alias -- must have a target."); + if (yy_alias->target == NULL) { + conf_report_error("Ignoring alias -- must have a target."); - rb_free(yy_alias); + rb_free(yy_alias); - return -1; - } + return -1; + } - irc_dictionary_add(alias_dict, yy_alias->name, yy_alias); + irc_dictionary_add(alias_dict, yy_alias->name, yy_alias); - return 0; + return 0; } static void conf_set_alias_name(void *data) { - if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */ - return; + if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */ + return; - yy_alias->name = rb_strdup(data); + yy_alias->name = rb_strdup(data); } static void conf_set_alias_target(void *data) { - if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */ - return; + if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */ + return; - yy_alias->target = rb_strdup(data); + yy_alias->target = rb_strdup(data); } static void conf_set_blacklist_host(void *data) { - yy_blacklist_host = rb_strdup(data); + yy_blacklist_host = rb_strdup(data); } static void conf_set_blacklist_type(void *data) { - conf_parm_t *args = data; + conf_parm_t *args = data; - /* Don't assume we have either if we got here */ - yy_blacklist_ipv4 = 0; - yy_blacklist_ipv6 = 0; + /* Don't assume we have either if we got here */ + yy_blacklist_ipv4 = 0; + yy_blacklist_ipv6 = 0; - for (; args; args = args->next) - { - if (!strcasecmp(args->v.string, "ipv4")) - yy_blacklist_ipv4 = 1; - else if (!strcasecmp(args->v.string, "ipv6")) - yy_blacklist_ipv6 = 1; - else - conf_report_error("blacklist::type has unknown address family %s", - args->v.string); - } + for (; args; args = args->next) { + if (!strcasecmp(args->v.string, "ipv4")) + yy_blacklist_ipv4 = 1; + else if (!strcasecmp(args->v.string, "ipv6")) + yy_blacklist_ipv6 = 1; + else + conf_report_error("blacklist::type has unknown address family %s", + args->v.string); + } - /* If we have neither, just default to IPv4 */ - if (!yy_blacklist_ipv4 && !yy_blacklist_ipv6) - { - conf_report_error("blacklist::type has neither IPv4 nor IPv6 (defaulting to IPv4)"); - yy_blacklist_ipv4 = 1; - } -} + /* If we have neither, just default to IPv4 */ + if (!yy_blacklist_ipv4 && !yy_blacklist_ipv6) { + conf_report_error("blacklist::type has neither IPv4 nor IPv6 (defaulting to IPv4)"); + yy_blacklist_ipv4 = 1; + } +} static void conf_set_blacklist_reason(void *data) { - yy_blacklist_reason = rb_strdup(data); + yy_blacklist_reason = rb_strdup(data); - if (yy_blacklist_host && yy_blacklist_reason) - { - if (yy_blacklist_ipv6) - { - /* Make sure things fit (64 = alnum count + dots) */ - if ((64 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN) - { - conf_report_error("blacklist::host %s results in IPv6 queries that are too long", - yy_blacklist_host); - goto cleanup_bl; - } - } - /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */ - if (yy_blacklist_ipv4 && !yy_blacklist_ipv6) - { - /* Make sure things fit (16 = number of nums + dots) */ - if ((16 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN) - { - conf_report_error("blacklist::host %s results in IPv4 queries that are too long", - yy_blacklist_host); - goto cleanup_bl; - } - } + if (yy_blacklist_host && yy_blacklist_reason) { + if (yy_blacklist_ipv6) { + /* Make sure things fit (64 = alnum count + dots) */ + if ((64 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN) { + conf_report_error("blacklist::host %s results in IPv6 queries that are too long", + yy_blacklist_host); + goto cleanup_bl; + } + } + /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */ + if (yy_blacklist_ipv4 && !yy_blacklist_ipv6) { + /* Make sure things fit (16 = number of nums + dots) */ + if ((16 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN) { + conf_report_error("blacklist::host %s results in IPv4 queries that are too long", + yy_blacklist_host); + goto cleanup_bl; + } + } - new_blacklist(yy_blacklist_host, yy_blacklist_reason, yy_blacklist_ipv4, yy_blacklist_ipv6); + new_blacklist(yy_blacklist_host, yy_blacklist_reason, yy_blacklist_ipv4, yy_blacklist_ipv6); cleanup_bl: - rb_free(yy_blacklist_host); - rb_free(yy_blacklist_reason); - yy_blacklist_host = NULL; - yy_blacklist_reason = NULL; - yy_blacklist_ipv4 = 1; - yy_blacklist_ipv6 = 0; - } + rb_free(yy_blacklist_host); + rb_free(yy_blacklist_reason); + yy_blacklist_host = NULL; + yy_blacklist_reason = NULL; + yy_blacklist_ipv4 = 1; + yy_blacklist_ipv6 = 0; + } } /* public functions */ @@ -1918,520 +1809,498 @@ cleanup_bl: void conf_report_error(const char *fmt, ...) { - va_list ap; - char msg[IRCD_BUFSIZE + 1] = { 0 }; + va_list ap; + char msg[IRCD_BUFSIZE + 1] = { 0 }; - va_start(ap, fmt); - rb_vsnprintf(msg, IRCD_BUFSIZE, fmt, ap); - va_end(ap); + va_start(ap, fmt); + rb_vsnprintf(msg, IRCD_BUFSIZE, fmt, ap); + va_end(ap); - if (testing_conf) - { - fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg); - return; - } + if (testing_conf) { + fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg); + return; + } - ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s", current_file, lineno + 1, msg); + ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s", current_file, lineno + 1, msg); } int conf_start_block(char *block, char *name) { - if((conf_cur_block = find_top_conf(block)) == NULL) - { - conf_report_error("Configuration block '%s' is not defined.", block); - return -1; - } + if((conf_cur_block = find_top_conf(block)) == NULL) { + conf_report_error("Configuration block '%s' is not defined.", block); + return -1; + } - if(name) - conf_cur_block_name = rb_strdup(name); - else - conf_cur_block_name = NULL; + if(name) + conf_cur_block_name = rb_strdup(name); + else + conf_cur_block_name = NULL; - if(conf_cur_block->tc_sfunc) - if(conf_cur_block->tc_sfunc(conf_cur_block) < 0) - return -1; + if(conf_cur_block->tc_sfunc) + if(conf_cur_block->tc_sfunc(conf_cur_block) < 0) + return -1; - return 0; + return 0; } int conf_end_block(struct TopConf *tc) { - if(tc->tc_efunc) - return tc->tc_efunc(tc); + if(tc->tc_efunc) + return tc->tc_efunc(tc); - rb_free(conf_cur_block_name); - return 0; + rb_free(conf_cur_block_name); + return 0; } static void conf_set_generic_int(void *data, void *location) { - *((int *) location) = *((unsigned int *) data); + *((int *) location) = *((unsigned int *) data); } static void conf_set_generic_string(void *data, int len, void *location) { - char **loc = location; - char *input = data; + char **loc = location; + char *input = data; - if(len && strlen(input) > (unsigned int)len) - input[len] = '\0'; + if(len && strlen(input) > (unsigned int)len) + input[len] = '\0'; - rb_free(*loc); - *loc = rb_strdup(input); + rb_free(*loc); + *loc = rb_strdup(input); } int conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value, int type) { - struct ConfEntry *cf; - conf_parm_t *cp; + struct ConfEntry *cf; + conf_parm_t *cp; - if(!tc) - return -1; + if(!tc) + return -1; - if((cf = find_conf_item(tc, item)) == NULL) - { - conf_report_error - ("Non-existant configuration setting %s::%s.", tc->tc_name, (char *) item); - return -1; - } + if((cf = find_conf_item(tc, item)) == NULL) { + conf_report_error + ("Non-existant configuration setting %s::%s.", tc->tc_name, (char *) item); + return -1; + } - /* if it takes one thing, make sure they only passed one thing, - and handle as needed. */ - if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST)) - { - conf_report_error - ("Option %s::%s does not take a list of values.", tc->tc_name, item); - return -1; - } + /* if it takes one thing, make sure they only passed one thing, + and handle as needed. */ + if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST)) { + conf_report_error + ("Option %s::%s does not take a list of values.", tc->tc_name, item); + return -1; + } - cp = value->v.list; + cp = value->v.list; - if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type)) - { - /* if it expects a string value, but we got a yesno, - * convert it back - */ - if((CF_TYPE(value->v.list->type) == CF_YESNO) && - (CF_TYPE(cf->cf_type) == CF_STRING)) - { - value->v.list->type = CF_STRING; + if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type)) { + /* if it expects a string value, but we got a yesno, + * convert it back + */ + if((CF_TYPE(value->v.list->type) == CF_YESNO) && + (CF_TYPE(cf->cf_type) == CF_STRING)) { + value->v.list->type = CF_STRING; - if(cp->v.number == 1) - cp->v.string = rb_strdup("yes"); - else - cp->v.string = rb_strdup("no"); - } + if(cp->v.number == 1) + cp->v.string = rb_strdup("yes"); + else + cp->v.string = rb_strdup("no"); + } - /* maybe it's a CF_TIME and they passed CF_INT -- - should still be valid */ - else if(!((CF_TYPE(value->v.list->type) == CF_INT) && - (CF_TYPE(cf->cf_type) == CF_TIME))) - { - conf_report_error - ("Wrong type for %s::%s (expected %s, got %s)", - tc->tc_name, (char *) item, - conf_strtype(cf->cf_type), conf_strtype(value->v.list->type)); - return -1; - } - } + /* maybe it's a CF_TIME and they passed CF_INT -- + should still be valid */ + else if(!((CF_TYPE(value->v.list->type) == CF_INT) && + (CF_TYPE(cf->cf_type) == CF_TIME))) { + conf_report_error + ("Wrong type for %s::%s (expected %s, got %s)", + tc->tc_name, (char *) item, + conf_strtype(cf->cf_type), conf_strtype(value->v.list->type)); + return -1; + } + } - if(cf->cf_type & CF_FLIST) - { + if(cf->cf_type & CF_FLIST) { #if 0 - if(cf->cf_arg) - conf_set_generic_list(value->v.list, cf->cf_arg); - else + if(cf->cf_arg) + conf_set_generic_list(value->v.list, cf->cf_arg); + else #endif - /* just pass it the extended argument list */ - cf->cf_func(value->v.list); - } - else - { - /* it's old-style, needs only one arg */ - switch (cf->cf_type) - { - case CF_INT: - case CF_TIME: - case CF_YESNO: - if(cf->cf_arg) - conf_set_generic_int(&cp->v.number, cf->cf_arg); - else - cf->cf_func(&cp->v.number); - break; - case CF_STRING: - case CF_QSTRING: - if(EmptyString(cp->v.string)) - conf_report_error("Ignoring %s::%s -- empty field", - tc->tc_name, item); - else if(cf->cf_arg) - conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg); - else - cf->cf_func(cp->v.string); - break; - } - } + /* just pass it the extended argument list */ + cf->cf_func(value->v.list); + } else { + /* it's old-style, needs only one arg */ + switch (cf->cf_type) { + case CF_INT: + case CF_TIME: + case CF_YESNO: + if(cf->cf_arg) + conf_set_generic_int(&cp->v.number, cf->cf_arg); + else + cf->cf_func(&cp->v.number); + break; + case CF_STRING: + case CF_QSTRING: + if(EmptyString(cp->v.string)) + conf_report_error("Ignoring %s::%s -- empty field", + tc->tc_name, item); + else if(cf->cf_arg) + conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg); + else + cf->cf_func(cp->v.string); + break; + } + } - return 0; + return 0; } int add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *)) { - struct TopConf *tc; - struct ConfEntry *cf; + struct TopConf *tc; + struct ConfEntry *cf; - if((tc = find_top_conf(topconf)) == NULL) - return -1; + if((tc = find_top_conf(topconf)) == NULL) + return -1; - if(find_conf_item(tc, name)) - return -1; + if(find_conf_item(tc, name)) + return -1; - cf = rb_malloc(sizeof(struct ConfEntry)); + cf = rb_malloc(sizeof(struct ConfEntry)); - cf->cf_name = name; - cf->cf_type = type; - cf->cf_func = func; - cf->cf_arg = NULL; + cf->cf_name = name; + cf->cf_type = type; + cf->cf_func = func; + cf->cf_arg = NULL; - rb_dlinkAddAlloc(cf, &tc->tc_items); + rb_dlinkAddAlloc(cf, &tc->tc_items); - return 0; + return 0; } int remove_conf_item(const char *topconf, const char *name) { - struct TopConf *tc; - struct ConfEntry *cf; - rb_dlink_node *ptr; + struct TopConf *tc; + struct ConfEntry *cf; + rb_dlink_node *ptr; - if((tc = find_top_conf(topconf)) == NULL) - return -1; + if((tc = find_top_conf(topconf)) == NULL) + return -1; - if((cf = find_conf_item(tc, name)) == NULL) - return -1; + if((cf = find_conf_item(tc, name)) == NULL) + return -1; - if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL) - return -1; + if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL) + return -1; - rb_dlinkDestroy(ptr, &tc->tc_items); - rb_free(cf); + rb_dlinkDestroy(ptr, &tc->tc_items); + rb_free(cf); - return 0; + return 0; } /* *INDENT-OFF* */ -static struct ConfEntry conf_serverinfo_table[] = -{ - { "description", CF_QSTRING, NULL, 0, &ServerInfo.description }, - { "network_desc", CF_QSTRING, NULL, 0, &ServerInfo.network_desc }, - { "helpchan", CF_QSTRING, NULL, 0, &ServerInfo.helpchan }, - { "helpurl", CF_QSTRING, NULL, 0, &ServerInfo.helpurl }, - { "hub", CF_YESNO, NULL, 0, &ServerInfo.hub }, +static struct ConfEntry conf_serverinfo_table[] = { + { "description", CF_QSTRING, NULL, 0, &ServerInfo.description }, + { "network_desc", CF_QSTRING, NULL, 0, &ServerInfo.network_desc }, + { "helpchan", CF_QSTRING, NULL, 0, &ServerInfo.helpchan }, + { "helpurl", CF_QSTRING, NULL, 0, &ServerInfo.helpurl }, + { "hub", CF_YESNO, NULL, 0, &ServerInfo.hub }, - { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL }, - { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL }, - { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL }, - { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL }, - { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL }, + { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL }, + { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL }, + { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL }, + { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL }, + { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL }, - { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key }, - { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert }, - { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert }, - { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params }, - { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count }, + { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key }, + { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert }, + { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert }, + { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params }, + { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count }, - { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients }, + { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients }, - { "\0", 0, NULL, 0, NULL } + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_admin_table[] = -{ - { "name", CF_QSTRING, NULL, 200, &AdminInfo.name }, - { "description",CF_QSTRING, NULL, 200, &AdminInfo.description }, - { "email", CF_QSTRING, NULL, 200, &AdminInfo.email }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_admin_table[] = { + { "name", CF_QSTRING, NULL, 200, &AdminInfo.name }, + { "description",CF_QSTRING, NULL, 200, &AdminInfo.description }, + { "email", CF_QSTRING, NULL, 200, &AdminInfo.email }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_log_table[] = -{ - { "fname_userlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_userlog }, - { "fname_fuserlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_fuserlog }, - { "fname_operlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_operlog }, - { "fname_foperlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_foperlog }, - { "fname_serverlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_serverlog }, - { "fname_killlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_killlog }, - { "fname_klinelog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_klinelog }, - { "fname_operspylog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_operspylog }, - { "fname_ioerrorlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_ioerrorlog }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_log_table[] = { + { "fname_userlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_userlog }, + { "fname_fuserlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_fuserlog }, + { "fname_operlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_operlog }, + { "fname_foperlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_foperlog }, + { "fname_serverlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_serverlog }, + { "fname_killlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_killlog }, + { "fname_klinelog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_klinelog }, + { "fname_operspylog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_operspylog }, + { "fname_ioerrorlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_ioerrorlog }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_operator_table[] = -{ - { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL }, - { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL }, - { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL }, - { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL }, - { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL }, - { "vhost", CF_QSTRING, conf_set_oper_vhost, 0, NULL }, - { "swhois", CF_QSTRING, conf_set_oper_swhois, 0, NULL }, - { "operstring", CF_QSTRING, conf_set_oper_operstring, 0, NULL }, - { "user", CF_QSTRING, conf_set_oper_user, 0, NULL }, - { "password", CF_QSTRING, conf_set_oper_password, 0, NULL }, - { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_operator_table[] = { + { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL }, + { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL }, + { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL }, + { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL }, + { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL }, + { "vhost", CF_QSTRING, conf_set_oper_vhost, 0, NULL }, + { "swhois", CF_QSTRING, conf_set_oper_swhois, 0, NULL }, + { "operstring", CF_QSTRING, conf_set_oper_operstring, 0, NULL }, + { "user", CF_QSTRING, conf_set_oper_user, 0, NULL }, + { "password", CF_QSTRING, conf_set_oper_password, 0, NULL }, + { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_privset_table[] = -{ - { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL }, - { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_privset_table[] = { + { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL }, + { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_class_table[] = -{ - { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL }, - { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL }, +static struct ConfEntry conf_class_table[] = { + { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL }, + { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL }, #ifdef RB_IPV6 - { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL }, + { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL }, #endif - { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL }, - { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL }, - { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL }, - { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL }, - { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL }, - { "max_number", CF_INT, conf_set_class_max_number, 0, NULL }, - { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL }, - { "\0", 0, NULL, 0, NULL } + { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL }, + { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL }, + { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL }, + { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL }, + { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL }, + { "max_number", CF_INT, conf_set_class_max_number, 0, NULL }, + { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_auth_table[] = -{ - { "user", CF_QSTRING, conf_set_auth_user, 0, NULL }, - { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL }, - { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL }, - { "class", CF_QSTRING, conf_set_auth_class, 0, NULL }, - { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL }, - { "autojoin", CF_QSTRING, conf_set_auth_autojoin, 0, NULL }, - { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL }, - { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL }, - { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_auth_table[] = { + { "user", CF_QSTRING, conf_set_auth_user, 0, NULL }, + { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL }, + { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL }, + { "class", CF_QSTRING, conf_set_auth_class, 0, NULL }, + { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL }, + { "autojoin", CF_QSTRING, conf_set_auth_autojoin, 0, NULL }, + { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL }, + { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL }, + { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_connect_table[] = -{ - { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL }, - { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL }, - { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL }, - { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL }, - { "host", CF_QSTRING, conf_set_connect_host, 0, NULL }, - { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL }, - { "port", CF_INT, conf_set_connect_port, 0, NULL }, - { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL }, - { "hub_mask", CF_QSTRING, conf_set_connect_hub_mask, 0, NULL }, - { "leaf_mask", CF_QSTRING, conf_set_connect_leaf_mask, 0, NULL }, - { "class", CF_QSTRING, conf_set_connect_class, 0, NULL }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_connect_table[] = { + { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL }, + { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL }, + { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL }, + { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL }, + { "host", CF_QSTRING, conf_set_connect_host, 0, NULL }, + { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL }, + { "port", CF_INT, conf_set_connect_port, 0, NULL }, + { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL }, + { "hub_mask", CF_QSTRING, conf_set_connect_hub_mask, 0, NULL }, + { "leaf_mask", CF_QSTRING, conf_set_connect_leaf_mask, 0, NULL }, + { "class", CF_QSTRING, conf_set_connect_class, 0, NULL }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_general_table[] = -{ - { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL }, - { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL }, - { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL }, - { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL }, - { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL }, - { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL }, - { "kline_delay", CF_TIME, conf_set_general_kline_delay, 0, NULL }, - { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL }, - { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL }, - { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL }, +static struct ConfEntry conf_general_table[] = { + { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL }, + { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL }, + { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL }, + { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL }, + { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL }, + { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL }, + { "kline_delay", CF_TIME, conf_set_general_kline_delay, 0, NULL }, + { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL }, + { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL }, + { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL }, - { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring }, - { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring }, - { "default_operhost", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operhost }, - { "static_quit", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.static_quit }, - { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring }, - { "egdpool_path", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.egdpool_path }, - { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason }, - { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice }, - { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand }, + { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring }, + { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring }, + { "default_operhost", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operhost }, + { "static_quit", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.static_quit }, + { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring }, + { "egdpool_path", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.egdpool_path }, + { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason }, + { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice }, + { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand }, - { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time }, - { "use_part_messages", CF_YESNO, NULL, 0, &ConfigFileEntry.use_part_messages }, - { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels }, - { "hide_channel_below_users", CF_INT, NULL, 0, &ConfigFileEntry.hide_channel_below_users }, - { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple }, - { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines }, - { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices }, + { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time }, + { "use_part_messages", CF_YESNO, NULL, 0, &ConfigFileEntry.use_part_messages }, + { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels }, + { "hide_channel_below_users", CF_INT, NULL, 0, &ConfigFileEntry.hide_channel_below_users }, + { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple }, + { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines }, + { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices }, - { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood }, - { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away }, - { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait }, - { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit }, - { "client_flood", CF_INT, NULL, 0, &ConfigFileEntry.client_flood }, - { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc }, - { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout }, - { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount }, - { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout }, - { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth }, - { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident }, - { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice }, - { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices }, - { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips }, - { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason }, - { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason }, - { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only }, - { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept }, - { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor }, - { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time }, - { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes }, - { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets }, - { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard }, - { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay }, - { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood }, - { "true_no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.true_no_oper_flood }, - { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only }, - { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info }, - { "secret_channels_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.secret_channels_in_whois }, - { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait }, - { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple }, - { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie }, - { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count }, - { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time }, - { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration }, - { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count }, - { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration }, - { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd }, - { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only }, - { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled }, - { "stats_h_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_h_oper_only }, - { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only }, - { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only }, - { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only }, - { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change }, - { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta }, - { "use_egd", CF_YESNO, NULL, 0, &ConfigFileEntry.use_egd }, - { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta }, - { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually }, - { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline }, - { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans }, - { "expire_override_time", CF_TIME, NULL, 0, &ConfigFileEntry.expire_override_time}, + { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood }, + { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away }, + { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait }, + { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit }, + { "client_flood", CF_INT, NULL, 0, &ConfigFileEntry.client_flood }, + { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc }, + { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout }, + { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount }, + { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout }, + { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth }, + { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident }, + { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice }, + { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices }, + { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips }, + { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason }, + { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason }, + { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only }, + { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept }, + { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor }, + { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time }, + { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes }, + { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets }, + { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard }, + { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay }, + { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood }, + { "true_no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.true_no_oper_flood }, + { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only }, + { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info }, + { "secret_channels_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.secret_channels_in_whois }, + { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait }, + { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple }, + { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie }, + { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count }, + { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time }, + { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration }, + { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count }, + { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration }, + { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd }, + { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only }, + { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled }, + { "stats_h_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_h_oper_only }, + { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only }, + { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only }, + { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only }, + { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change }, + { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta }, + { "use_egd", CF_YESNO, NULL, 0, &ConfigFileEntry.use_egd }, + { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta }, + { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually }, + { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline }, + { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans }, + { "expire_override_time", CF_TIME, NULL, 0, &ConfigFileEntry.expire_override_time}, { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval }, - { "\0", 0, NULL, 0, NULL } + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_channel_table[] = -{ - { "autochanmodes", CF_QSTRING, NULL, 0, &ConfigChannel.autochanmodes }, - { "exemptchanops", CF_QSTRING, NULL, 0, &ConfigChannel.exemptchanops }, - { "disabledmodes", CF_QSTRING, NULL, 0, &ConfigChannel.disabledmodes }, - { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count }, - { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count }, - { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho }, - { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding }, - { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay }, - { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel }, - { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans }, - { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large }, - { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user }, - { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split }, - { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split }, - { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels }, - { "cycle_host_change", CF_YESNO, NULL, 0, &ConfigChannel.cycle_host_change }, - { "host_in_topic", CF_YESNO, NULL, 0, &ConfigChannel.host_in_topic }, - { "admin_on_channel_create", CF_YESNO, NULL, 0, &ConfigChannel.admin_on_channel_create }, - { "use_halfop", CF_YESNO, NULL, 0, &ConfigChannel.use_halfop }, - { "use_admin", CF_YESNO, NULL, 0, &ConfigChannel.use_admin }, - { "use_owner", CF_YESNO, NULL, 0, &ConfigChannel.use_owner }, - { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except }, - { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex }, - { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock }, - { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward }, - { "use_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.use_local_channels }, - { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart }, - { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change }, - { "exempt_cmode_c", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_c }, - { "exempt_cmode_C", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_C }, - { "exempt_cmode_D", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_D }, - { "exempt_cmode_T", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_T }, - { "exempt_cmode_N", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_N }, - { "exempt_cmode_G", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_G }, - { "exempt_cmode_K", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_K }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_channel_table[] = { + { "autochanmodes", CF_QSTRING, NULL, 0, &ConfigChannel.autochanmodes }, + { "exemptchanops", CF_QSTRING, NULL, 0, &ConfigChannel.exemptchanops }, + { "disabledmodes", CF_QSTRING, NULL, 0, &ConfigChannel.disabledmodes }, + { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count }, + { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count }, + { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho }, + { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding }, + { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay }, + { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel }, + { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans }, + { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large }, + { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user }, + { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split }, + { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split }, + { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels }, + { "cycle_host_change", CF_YESNO, NULL, 0, &ConfigChannel.cycle_host_change }, + { "host_in_topic", CF_YESNO, NULL, 0, &ConfigChannel.host_in_topic }, + { "admin_on_channel_create", CF_YESNO, NULL, 0, &ConfigChannel.admin_on_channel_create }, + { "use_halfop", CF_YESNO, NULL, 0, &ConfigChannel.use_halfop }, + { "use_admin", CF_YESNO, NULL, 0, &ConfigChannel.use_admin }, + { "use_owner", CF_YESNO, NULL, 0, &ConfigChannel.use_owner }, + { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except }, + { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex }, + { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock }, + { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward }, + { "use_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.use_local_channels }, + { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart }, + { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change }, + { "exempt_cmode_c", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_c }, + { "exempt_cmode_C", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_C }, + { "exempt_cmode_D", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_D }, + { "exempt_cmode_T", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_T }, + { "exempt_cmode_N", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_N }, + { "exempt_cmode_G", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_G }, + { "exempt_cmode_K", CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_K }, + { "\0", 0, NULL, 0, NULL } }; -static struct ConfEntry conf_serverhide_table[] = -{ - { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden }, - { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links }, - { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden }, - { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL }, - { "\0", 0, NULL, 0, NULL } +static struct ConfEntry conf_serverhide_table[] = { + { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden }, + { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links }, + { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden }, + { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL }, + { "\0", 0, NULL, 0, NULL } }; /* *INDENT-ON* */ void newconf_init() { - add_top_conf("modules", NULL, NULL, NULL); - add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path); - add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module); + add_top_conf("modules", NULL, NULL, NULL); + add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path); + add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module); - add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table); - add_top_conf("admin", NULL, NULL, conf_admin_table); - add_top_conf("log", NULL, NULL, conf_log_table); - add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table); - add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table); - add_top_conf("privset", NULL, NULL, conf_privset_table); + add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table); + add_top_conf("admin", NULL, NULL, conf_admin_table); + add_top_conf("log", NULL, NULL, conf_log_table); + add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table); + add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table); + add_top_conf("privset", NULL, NULL, conf_privset_table); - add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL); - add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept); - add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port); - add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport); - add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address); - add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address); + add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL); + add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept); + add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port); + add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport); + add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address); + add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address); - add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table); + add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table); - add_top_conf("shared", conf_cleanup_shared, conf_cleanup_shared, NULL); - add_conf_item("shared", "oper", CF_QSTRING|CF_FLIST, conf_set_shared_oper); - add_conf_item("shared", "flags", CF_STRING | CF_FLIST, conf_set_shared_flags); + add_top_conf("shared", conf_cleanup_shared, conf_cleanup_shared, NULL); + add_conf_item("shared", "oper", CF_QSTRING|CF_FLIST, conf_set_shared_oper); + add_conf_item("shared", "flags", CF_STRING | CF_FLIST, conf_set_shared_flags); - add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table); + add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table); - add_top_conf("exempt", NULL, NULL, NULL); - add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip); + add_top_conf("exempt", NULL, NULL, NULL); + add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip); - add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL); - add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name); - add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags); + add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL); + add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name); + add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags); - add_top_conf("general", NULL, NULL, conf_general_table); - add_top_conf("channel", NULL, NULL, conf_channel_table); - add_top_conf("serverhide", NULL, NULL, conf_serverhide_table); + add_top_conf("general", NULL, NULL, conf_general_table); + add_top_conf("channel", NULL, NULL, conf_channel_table); + add_top_conf("serverhide", NULL, NULL, conf_serverhide_table); - add_top_conf("service", conf_begin_service, NULL, NULL); - add_conf_item("service", "name", CF_QSTRING, conf_set_service_name); + add_top_conf("service", conf_begin_service, NULL, NULL); + add_conf_item("service", "name", CF_QSTRING, conf_set_service_name); - add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL); - add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name); - add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target); + add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL); + add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name); + add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target); - add_top_conf("blacklist", NULL, NULL, NULL); - add_conf_item("blacklist", "host", CF_QSTRING, conf_set_blacklist_host); - add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_blacklist_type); - add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_blacklist_reason); + add_top_conf("blacklist", NULL, NULL, NULL); + add_conf_item("blacklist", "host", CF_QSTRING, conf_set_blacklist_host); + add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_blacklist_type); + add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_blacklist_reason); } diff --git a/src/numeric.c b/src/numeric.c index 3da23ff..97ff6ec 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -43,20 +43,20 @@ const char * form_str(int numeric) { - const char *num_ptr; + const char *num_ptr; - s_assert(-1 < numeric); - s_assert(numeric < ERR_LAST_ERR_MSG); - s_assert(0 != replies[numeric]); + s_assert(-1 < numeric); + s_assert(numeric < ERR_LAST_ERR_MSG); + s_assert(0 != replies[numeric]); - if(numeric > ERR_LAST_ERR_MSG) - numeric = ERR_LAST_ERR_MSG; - if(numeric < 0) - numeric = ERR_LAST_ERR_MSG; + if(numeric > ERR_LAST_ERR_MSG) + numeric = ERR_LAST_ERR_MSG; + if(numeric < 0) + numeric = ERR_LAST_ERR_MSG; - num_ptr = replies[numeric]; - if(num_ptr == NULL) - num_ptr = replies[ERR_LAST_ERR_MSG]; + num_ptr = replies[numeric]; + if(num_ptr == NULL) + num_ptr = replies[ERR_LAST_ERR_MSG]; - return (num_ptr); + return (num_ptr); } diff --git a/src/operhash.c b/src/operhash.c index f151cf4..0fda22c 100644 --- a/src/operhash.c +++ b/src/operhash.c @@ -40,10 +40,9 @@ #define hash_opername(x) fnv_hash_upper((const unsigned char *)(x), OPERHASH_MAX_BITS) -struct operhash_entry -{ - char *name; - int refcount; +struct operhash_entry { + char *name; + int refcount; }; static rb_dlink_list operhash_table[OPERHASH_MAX]; @@ -51,85 +50,80 @@ static rb_dlink_list operhash_table[OPERHASH_MAX]; const char * operhash_add(const char *name) { - struct operhash_entry *ohash; - unsigned int hashv; - rb_dlink_node *ptr; + struct operhash_entry *ohash; + unsigned int hashv; + rb_dlink_node *ptr; - if(EmptyString(name)) - return NULL; + if(EmptyString(name)) + return NULL; - hashv = hash_opername(name); + hashv = hash_opername(name); - RB_DLINK_FOREACH(ptr, operhash_table[hashv].head) - { - ohash = ptr->data; + RB_DLINK_FOREACH(ptr, operhash_table[hashv].head) { + ohash = ptr->data; - if(!irccmp(ohash->name, name)) - { - ohash->refcount++; - return ohash->name; - } - } + if(!irccmp(ohash->name, name)) { + ohash->refcount++; + return ohash->name; + } + } - ohash = rb_malloc(sizeof(struct operhash_entry)); - ohash->refcount = 1; - ohash->name = rb_strdup(name); + ohash = rb_malloc(sizeof(struct operhash_entry)); + ohash->refcount = 1; + ohash->name = rb_strdup(name); - rb_dlinkAddAlloc(ohash, &operhash_table[hashv]); + rb_dlinkAddAlloc(ohash, &operhash_table[hashv]); - return ohash->name; + return ohash->name; } const char * operhash_find(const char *name) { - struct operhash_entry *ohash; - unsigned int hashv; - rb_dlink_node *ptr; + struct operhash_entry *ohash; + unsigned int hashv; + rb_dlink_node *ptr; - if(EmptyString(name)) - return NULL; + if(EmptyString(name)) + return NULL; - hashv = hash_opername(name); + hashv = hash_opername(name); - RB_DLINK_FOREACH(ptr, operhash_table[hashv].head) - { - ohash = ptr->data; + RB_DLINK_FOREACH(ptr, operhash_table[hashv].head) { + ohash = ptr->data; - if(!irccmp(ohash->name, name)) - return ohash->name; - } + if(!irccmp(ohash->name, name)) + return ohash->name; + } - return NULL; + return NULL; } void operhash_delete(const char *name) { - struct operhash_entry *ohash; - unsigned int hashv; - rb_dlink_node *ptr; + struct operhash_entry *ohash; + unsigned int hashv; + rb_dlink_node *ptr; - if(EmptyString(name)) - return; + if(EmptyString(name)) + return; - hashv = hash_opername(name); + hashv = hash_opername(name); - RB_DLINK_FOREACH(ptr, operhash_table[hashv].head) - { - ohash = ptr->data; + RB_DLINK_FOREACH(ptr, operhash_table[hashv].head) { + ohash = ptr->data; - if(irccmp(ohash->name, name)) - continue; + if(irccmp(ohash->name, name)) + continue; - ohash->refcount--; + ohash->refcount--; - if(ohash->refcount == 0) - { - rb_free(ohash->name); - rb_free(ohash); - rb_dlinkDestroy(ptr, &operhash_table[hashv]); - return; - } - } + if(ohash->refcount == 0) { + rb_free(ohash->name); + rb_free(ohash); + rb_dlinkDestroy(ptr, &operhash_table[hashv]); + return; + } + } } diff --git a/src/packet.c b/src/packet.c index 707ddbb..746d820 100644 --- a/src/packet.c +++ b/src/packet.c @@ -44,111 +44,101 @@ static void client_dopacket(struct Client *client_p, char *buffer, size_t length static void parse_client_queued(struct Client *client_p) { - int dolen = 0; - int checkflood = 1; + int dolen = 0; + int checkflood = 1; - if(IsAnyDead(client_p)) - return; + if(IsAnyDead(client_p)) + return; - if(IsUnknown(client_p)) - { - for (;;) - { - if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) - break; + if(IsUnknown(client_p)) { + for (;;) { + if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) + break; - dolen = rb_linebuf_get(&client_p->localClient-> - buf_recvq, readBuf, READBUF_SIZE, - LINEBUF_COMPLETE, LINEBUF_PARSED); + dolen = rb_linebuf_get(&client_p->localClient-> + buf_recvq, readBuf, READBUF_SIZE, + LINEBUF_COMPLETE, LINEBUF_PARSED); - if(dolen <= 0 || IsDead(client_p)) - break; + if(dolen <= 0 || IsDead(client_p)) + break; - client_dopacket(client_p, readBuf, dolen); - client_p->localClient->sent_parsed++; + client_dopacket(client_p, readBuf, dolen); + client_p->localClient->sent_parsed++; - /* He's dead cap'n */ - if(IsAnyDead(client_p)) - return; - /* if theyve dropped out of the unknown state, break and move - * to the parsing for their appropriate status. --fl - */ - if(!IsUnknown(client_p)) - { - /* reset their flood limits, they're now - * graced to flood - */ - client_p->localClient->sent_parsed = 0; - break; - } + /* He's dead cap'n */ + if(IsAnyDead(client_p)) + return; + /* if theyve dropped out of the unknown state, break and move + * to the parsing for their appropriate status. --fl + */ + if(!IsUnknown(client_p)) { + /* reset their flood limits, they're now + * graced to flood + */ + client_p->localClient->sent_parsed = 0; + break; + } - } - } + } + } - if(IsAnyServer(client_p) || IsExemptFlood(client_p)) - { - while (!IsAnyDead(client_p) && (dolen = rb_linebuf_get(&client_p->localClient->buf_recvq, - readBuf, READBUF_SIZE, LINEBUF_COMPLETE, - LINEBUF_PARSED)) > 0) - { - client_dopacket(client_p, readBuf, dolen); - } - } - else if(IsClient(client_p)) - { + if(IsAnyServer(client_p) || IsExemptFlood(client_p)) { + while (!IsAnyDead(client_p) && (dolen = rb_linebuf_get(&client_p->localClient->buf_recvq, + readBuf, READBUF_SIZE, LINEBUF_COMPLETE, + LINEBUF_PARSED)) > 0) { + client_dopacket(client_p, readBuf, dolen); + } + } else if(IsClient(client_p)) { - if(IsOper(client_p) && ConfigFileEntry.no_oper_flood) - { - if (ConfigFileEntry.true_no_oper_flood) - checkflood = -1; - else - checkflood = 0; - } - /* - * Handle flood protection here - if we exceed our flood limit on - * messages in this loop, we simply drop out of the loop prematurely. - * -- adrian - */ - for (;;) - { - /* This flood protection works as follows: - * - * A client is given allow_read lines to send to the server. Every - * time a line is parsed, sent_parsed is increased. sent_parsed - * is decreased by 1 every time flood_recalc is called. - * - * Thus a client can 'burst' allow_read lines to the server, any - * excess lines will be parsed one per flood_recalc() call. - * - * Therefore a client will be penalised more if they keep flooding, - * as sent_parsed will always hover around the allow_read limit - * and no 'bursts' will be permitted. - */ - if(checkflood) - { - if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) - break; - } + if(IsOper(client_p) && ConfigFileEntry.no_oper_flood) { + if (ConfigFileEntry.true_no_oper_flood) + checkflood = -1; + else + checkflood = 0; + } + /* + * Handle flood protection here - if we exceed our flood limit on + * messages in this loop, we simply drop out of the loop prematurely. + * -- adrian + */ + for (;;) { + /* This flood protection works as follows: + * + * A client is given allow_read lines to send to the server. Every + * time a line is parsed, sent_parsed is increased. sent_parsed + * is decreased by 1 every time flood_recalc is called. + * + * Thus a client can 'burst' allow_read lines to the server, any + * excess lines will be parsed one per flood_recalc() call. + * + * Therefore a client will be penalised more if they keep flooding, + * as sent_parsed will always hover around the allow_read limit + * and no 'bursts' will be permitted. + */ + if(checkflood) { + if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) + break; + } - /* allow opers 4 times the amount of messages as users. why 4? - * why not. :) --fl_ - */ - else if(client_p->localClient->sent_parsed >= (4 * client_p->localClient->allow_read) && checkflood != -1) - break; + /* allow opers 4 times the amount of messages as users. why 4? + * why not. :) --fl_ + */ + else if(client_p->localClient->sent_parsed >= (4 * client_p->localClient->allow_read) && checkflood != -1) + break; - dolen = rb_linebuf_get(&client_p->localClient-> - buf_recvq, readBuf, READBUF_SIZE, - LINEBUF_COMPLETE, LINEBUF_PARSED); + dolen = rb_linebuf_get(&client_p->localClient-> + buf_recvq, readBuf, READBUF_SIZE, + LINEBUF_COMPLETE, LINEBUF_PARSED); - if(!dolen) - break; + if(!dolen) + break; - client_dopacket(client_p, readBuf, dolen); - if(IsAnyDead(client_p)) - return; - client_p->localClient->sent_parsed++; - } - } + client_dopacket(client_p, readBuf, dolen); + if(IsAnyDead(client_p)) + return; + client_p->localClient->sent_parsed++; + } + } } /* flood_endgrace() @@ -158,15 +148,15 @@ parse_client_queued(struct Client *client_p) void flood_endgrace(struct Client *client_p) { - SetFloodDone(client_p); + SetFloodDone(client_p); - /* Drop their flood limit back down */ - client_p->localClient->allow_read = MAX_FLOOD; + /* Drop their flood limit back down */ + client_p->localClient->allow_read = MAX_FLOOD; - /* sent_parsed could be way over MAX_FLOOD but under MAX_FLOOD_BURST, - * so reset it. - */ - client_p->localClient->sent_parsed = 0; + /* sent_parsed could be way over MAX_FLOOD but under MAX_FLOOD_BURST, + * so reset it. + */ + client_p->localClient->sent_parsed = 0; } /* @@ -178,54 +168,52 @@ flood_endgrace(struct Client *client_p) void flood_recalc(void *unused) { - rb_dlink_node *ptr, *next; - struct Client *client_p; + rb_dlink_node *ptr, *next; + struct Client *client_p; - RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head) { + client_p = ptr->data; - if(rb_unlikely(IsMe(client_p))) - continue; - - if(rb_unlikely(client_p->localClient == NULL)) - continue; - - if(IsFloodDone(client_p)) - client_p->localClient->sent_parsed -= 2; - else - client_p->localClient->sent_parsed = 0; - - if(client_p->localClient->sent_parsed < 0) - client_p->localClient->sent_parsed = 0; + if(rb_unlikely(IsMe(client_p))) + continue; - if(--client_p->localClient->actually_read < 0) - client_p->localClient->actually_read = 0; + if(rb_unlikely(client_p->localClient == NULL)) + continue; - parse_client_queued(client_p); - - if(rb_unlikely(IsAnyDead(client_p))) - continue; + if(IsFloodDone(client_p)) + client_p->localClient->sent_parsed -= 2; + else + client_p->localClient->sent_parsed = 0; - } + if(client_p->localClient->sent_parsed < 0) + client_p->localClient->sent_parsed = 0; - RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head) - { - client_p = ptr->data; + if(--client_p->localClient->actually_read < 0) + client_p->localClient->actually_read = 0; - if(client_p->localClient == NULL) - continue; + parse_client_queued(client_p); - client_p->localClient->sent_parsed--; + if(rb_unlikely(IsAnyDead(client_p))) + continue; - if(client_p->localClient->sent_parsed < 0) - client_p->localClient->sent_parsed = 0; + } - if(--client_p->localClient->actually_read < 0) - client_p->localClient->actually_read = 0; + RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head) { + client_p = ptr->data; - parse_client_queued(client_p); - } + if(client_p->localClient == NULL) + continue; + + client_p->localClient->sent_parsed--; + + if(client_p->localClient->sent_parsed < 0) + client_p->localClient->sent_parsed = 0; + + if(--client_p->localClient->actually_read < 0) + client_p->localClient->actually_read = 0; + + parse_client_queued(client_p); + } } /* @@ -234,93 +222,86 @@ flood_recalc(void *unused) void read_packet(rb_fde_t * F, void *data) { - struct Client *client_p = data; - struct LocalUser *lclient_p = client_p->localClient; - int length = 0; - int lbuf_len; + struct Client *client_p = data; + struct LocalUser *lclient_p = client_p->localClient; + int length = 0; + int lbuf_len; - int binary = 0; + int binary = 0; #ifdef USE_IODEBUG_HOOKS - hook_data_int hdata; + hook_data_int hdata; #endif - while(1) - { - if(IsAnyDead(client_p)) - return; + while(1) { + if(IsAnyDead(client_p)) + return; - /* - * Read some data. We *used to* do anti-flood protection here, but - * I personally think it makes the code too hairy to make sane. - * -- adrian - */ - length = rb_read(client_p->localClient->F, readBuf, READBUF_SIZE); + /* + * Read some data. We *used to* do anti-flood protection here, but + * I personally think it makes the code too hairy to make sane. + * -- adrian + */ + length = rb_read(client_p->localClient->F, readBuf, READBUF_SIZE); - if(length < 0) - { - if(rb_ignore_errno(errno)) - rb_setselect(client_p->localClient->F, - RB_SELECT_READ, read_packet, client_p); - else - error_exit_client(client_p, length); - return; - } - else if(length == 0) - { - error_exit_client(client_p, length); - return; - } + if(length < 0) { + if(rb_ignore_errno(errno)) + rb_setselect(client_p->localClient->F, + RB_SELECT_READ, read_packet, client_p); + else + error_exit_client(client_p, length); + return; + } else if(length == 0) { + error_exit_client(client_p, length); + return; + } #ifdef USE_IODEBUG_HOOKS - hdata.client = client_p; - hdata.arg1 = readBuf; - hdata.arg2 = length; - call_hook(h_iorecv_id, &hdata); + hdata.client = client_p; + hdata.arg1 = readBuf; + hdata.arg2 = length; + call_hook(h_iorecv_id, &hdata); #endif - if(client_p->localClient->lasttime < rb_current_time()) - client_p->localClient->lasttime = rb_current_time(); - client_p->flags &= ~FLAGS_PINGSENT; + if(client_p->localClient->lasttime < rb_current_time()) + client_p->localClient->lasttime = rb_current_time(); + client_p->flags &= ~FLAGS_PINGSENT; - /* - * Before we even think of parsing what we just read, stick - * it on the end of the receive queue and do it when its - * turn comes around. - */ - if(IsHandshake(client_p) || IsUnknown(client_p)) - binary = 1; + /* + * Before we even think of parsing what we just read, stick + * it on the end of the receive queue and do it when its + * turn comes around. + */ + if(IsHandshake(client_p) || IsUnknown(client_p)) + binary = 1; - lbuf_len = rb_linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary); + lbuf_len = rb_linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary); - lclient_p->actually_read += lbuf_len; + lclient_p->actually_read += lbuf_len; - if(IsAnyDead(client_p)) - return; - - /* Attempt to parse what we have */ - parse_client_queued(client_p); + if(IsAnyDead(client_p)) + return; - if(IsAnyDead(client_p)) - return; - - /* Check to make sure we're not flooding */ - if(!IsAnyServer(client_p) && - (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood)) - { - if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p))) - { - exit_client(client_p, client_p, client_p, "Excess Flood"); - return; - } - } + /* Attempt to parse what we have */ + parse_client_queued(client_p); - /* bail if short read */ - if(length < READBUF_SIZE) - { - rb_setselect(client_p->localClient->F, RB_SELECT_READ, read_packet, client_p); - return; - } - } + if(IsAnyDead(client_p)) + return; + + /* Check to make sure we're not flooding */ + if(!IsAnyServer(client_p) && + (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood)) { + if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p))) { + exit_client(client_p, client_p, client_p, "Excess Flood"); + return; + } + } + + /* bail if short read */ + if(length < READBUF_SIZE) { + rb_setselect(client_p->localClient->F, RB_SELECT_READ, read_packet, client_p); + return; + } + } } /* @@ -338,37 +319,35 @@ read_packet(rb_fde_t * F, void *data) void client_dopacket(struct Client *client_p, char *buffer, size_t length) { - s_assert(client_p != NULL); - s_assert(buffer != NULL); + s_assert(client_p != NULL); + s_assert(buffer != NULL); - if(client_p == NULL || buffer == NULL) - return; - if(IsAnyDead(client_p)) - return; - /* - * Update messages received - */ - ++me.localClient->receiveM; - ++client_p->localClient->receiveM; + if(client_p == NULL || buffer == NULL) + return; + if(IsAnyDead(client_p)) + return; + /* + * Update messages received + */ + ++me.localClient->receiveM; + ++client_p->localClient->receiveM; - /* - * Update bytes received - */ - client_p->localClient->receiveB += length; + /* + * Update bytes received + */ + client_p->localClient->receiveB += length; - if(client_p->localClient->receiveB > 1023) - { - client_p->localClient->receiveK += (client_p->localClient->receiveB >> 10); - client_p->localClient->receiveB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ - } + if(client_p->localClient->receiveB > 1023) { + client_p->localClient->receiveK += (client_p->localClient->receiveB >> 10); + client_p->localClient->receiveB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ + } - me.localClient->receiveB += length; + me.localClient->receiveB += length; - if(me.localClient->receiveB > 1023) - { - me.localClient->receiveK += (me.localClient->receiveB >> 10); - me.localClient->receiveB &= 0x03ff; - } + if(me.localClient->receiveB > 1023) { + me.localClient->receiveK += (me.localClient->receiveB >> 10); + me.localClient->receiveB &= 0x03ff; + } - parse(client_p, buffer, buffer + length); + parse(client_p, buffer, buffer + length); } diff --git a/src/parse.c b/src/parse.c index a8ce091..51d5076 100644 --- a/src/parse.c +++ b/src/parse.c @@ -63,50 +63,44 @@ static char buffer[1024]; static inline int string_to_array(char *string, char **parv) { - char *p, *buf = string; - int x = 1; + char *p, *buf = string; + int x = 1; - parv[x] = NULL; - while (*buf == ' ') /* skip leading spaces */ - buf++; - if(*buf == '\0') /* ignore all-space args */ - return x; + parv[x] = NULL; + while (*buf == ' ') /* skip leading spaces */ + buf++; + if(*buf == '\0') /* ignore all-space args */ + return x; - do - { - if(*buf == ':') /* Last parameter */ - { - buf++; - parv[x++] = buf; - parv[x] = NULL; - return x; - } - else - { - parv[x++] = buf; - parv[x] = NULL; - if((p = strchr(buf, ' ')) != NULL) - { - *p++ = '\0'; - buf = p; - } - else - return x; - } - while (*buf == ' ') - buf++; - if(*buf == '\0') - return x; - } - /* we can go upto parv[MAXPARA], as parv[0] is skipped */ - while (x < MAXPARA); + do { + if(*buf == ':') { /* Last parameter */ + buf++; + parv[x++] = buf; + parv[x] = NULL; + return x; + } else { + parv[x++] = buf; + parv[x] = NULL; + if((p = strchr(buf, ' ')) != NULL) { + *p++ = '\0'; + buf = p; + } else + return x; + } + while (*buf == ' ') + buf++; + if(*buf == '\0') + return x; + } + /* we can go upto parv[MAXPARA], as parv[0] is skipped */ + while (x < MAXPARA); - if(*p == ':') - p++; + if(*p == ':') + p++; - parv[x++] = p; - parv[x] = NULL; - return x; + parv[x++] = p; + parv[x] = NULL; + return x; } /* parse() @@ -116,180 +110,160 @@ string_to_array(char *string, char **parv) void parse(struct Client *client_p, char *pbuffer, char *bufend) { - struct Client *from = client_p; - char *sender; - char *ch; - char *s; - char *end; - int i = 1; - char *numeric = 0; - struct Message *mptr; + struct Client *from = client_p; + char *sender; + char *ch; + char *s; + char *end; + int i = 1; + char *numeric = 0; + struct Message *mptr; - s_assert(MyConnect(client_p)); - s_assert(client_p->localClient->F != NULL); - if(IsAnyDead(client_p)) - return; + s_assert(MyConnect(client_p)); + s_assert(client_p->localClient->F != NULL); + if(IsAnyDead(client_p)) + return; - for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */ - /* null statement */ ; + for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */ + /* null statement */ ; - para[0] = from->name; + para[0] = from->name; - if(*ch == ':') - { - ch++; + if(*ch == ':') { + ch++; - /* point sender to the sender param */ - sender = ch; + /* point sender to the sender param */ + sender = ch; - if((s = strchr(ch, ' '))) - { - *s = '\0'; - s++; - ch = s; - } + if((s = strchr(ch, ' '))) { + *s = '\0'; + s++; + ch = s; + } - if(*sender && IsServer(client_p)) - { - from = find_client(sender); + if(*sender && IsServer(client_p)) { + from = find_client(sender); - /* didnt find any matching client, issue a kill */ - if(from == NULL) - { - ServerStats.is_unpf++; - remove_unknown(client_p, sender, pbuffer); - return; - } + /* didnt find any matching client, issue a kill */ + if(from == NULL) { + ServerStats.is_unpf++; + remove_unknown(client_p, sender, pbuffer); + return; + } - para[0] = from->name; + para[0] = from->name; - /* fake direction, hmm. */ - if(from->from != client_p) - { - ServerStats.is_wrdi++; - cancel_clients(client_p, from, pbuffer); - return; - } - } - while (*ch == ' ') - ch++; - } + /* fake direction, hmm. */ + if(from->from != client_p) { + ServerStats.is_wrdi++; + cancel_clients(client_p, from, pbuffer); + return; + } + } + while (*ch == ' ') + ch++; + } - if(*ch == '\0') - { - ServerStats.is_empt++; - return; - } + if(*ch == '\0') { + ServerStats.is_empt++; + return; + } - /* at this point there must be some sort of command parameter */ + /* at this point there must be some sort of command parameter */ - /* - * Extract the command code from the packet. Point s to the end - * of the command code and calculate the length using pointer - * arithmetic. Note: only need length for numerics and *all* - * numerics must have parameters and thus a space after the command - * code. -avalon - */ + /* + * Extract the command code from the packet. Point s to the end + * of the command code and calculate the length using pointer + * arithmetic. Note: only need length for numerics and *all* + * numerics must have parameters and thus a space after the command + * code. -avalon + */ - /* EOB is 3 chars long but is not a numeric */ + /* EOB is 3 chars long but is not a numeric */ - if(*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */ - IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2))) - { - mptr = NULL; - numeric = ch; - ServerStats.is_num++; - s = ch + 3; /* I know this is ' ' from above if */ - *s++ = '\0'; /* blow away the ' ', and point s to next part */ - } - else - { - int ii = 0; + if(*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */ + IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2))) { + mptr = NULL; + numeric = ch; + ServerStats.is_num++; + s = ch + 3; /* I know this is ' ' from above if */ + *s++ = '\0'; /* blow away the ' ', and point s to next part */ + } else { + int ii = 0; - if((s = strchr(ch, ' '))) - *s++ = '\0'; + if((s = strchr(ch, ' '))) + *s++ = '\0'; - mptr = irc_dictionary_retrieve(cmd_dict, ch); + mptr = irc_dictionary_retrieve(cmd_dict, ch); - /* no command or its encap only, error */ - if(!mptr || !mptr->cmd) - { - /* - * Note: Give error message *only* to recognized - * persons. It's a nightmare situation to have - * two programs sending "Unknown command"'s or - * equivalent to each other at full blast.... - * If it has got to person state, it at least - * seems to be well behaving. Perhaps this message - * should never be generated, though... --msa - * Hm, when is the buffer empty -- if a command - * code has been found ?? -Armin - */ - if(pbuffer[0] != '\0') - { - if (IsPerson(client_p)) - { - struct alias_entry *aptr = irc_dictionary_retrieve(alias_dict, ch); - if (aptr != NULL) - { - do_alias(aptr, client_p, s); - return; - } - } - if(IsPerson(from)) - { - sendto_one(from, form_str(ERR_UNKNOWNCOMMAND), - me.name, from->name, ch); - } - } - ServerStats.is_unco++; - return; - } + /* no command or its encap only, error */ + if(!mptr || !mptr->cmd) { + /* + * Note: Give error message *only* to recognized + * persons. It's a nightmare situation to have + * two programs sending "Unknown command"'s or + * equivalent to each other at full blast.... + * If it has got to person state, it at least + * seems to be well behaving. Perhaps this message + * should never be generated, though... --msa + * Hm, when is the buffer empty -- if a command + * code has been found ?? -Armin + */ + if(pbuffer[0] != '\0') { + if (IsPerson(client_p)) { + struct alias_entry *aptr = irc_dictionary_retrieve(alias_dict, ch); + if (aptr != NULL) { + do_alias(aptr, client_p, s); + return; + } + } + if(IsPerson(from)) { + sendto_one(from, form_str(ERR_UNKNOWNCOMMAND), + me.name, from->name, ch); + } + } + ServerStats.is_unco++; + return; + } - ii = bufend - ((s) ? s : ch); - mptr->bytes += ii; - } + ii = bufend - ((s) ? s : ch); + mptr->bytes += ii; + } - end = bufend - 1; + end = bufend - 1; - /* XXX this should be done before parse() is called */ - if(*end == '\n') - *end-- = '\0'; - if(*end == '\r') - *end = '\0'; + /* XXX this should be done before parse() is called */ + if(*end == '\n') + *end-- = '\0'; + if(*end == '\r') + *end = '\0'; - if(s != NULL) - i = string_to_array(s, para); + if(s != NULL) + i = string_to_array(s, para); - if(mptr == NULL) - { - do_numeric(numeric, client_p, from, i, para); - return; - } + if(mptr == NULL) { + do_numeric(numeric, client_p, from, i, para); + return; + } - if(handle_command(mptr, client_p, from, i, /* XXX discards const!!! */ (const char **)para) < -1) - { - char *p; - for (p = pbuffer; p <= end; p += 8) - { - /* HACK HACK */ - /* Its expected this nasty code can be removed - * or rewritten later if still needed. - */ - if((unsigned long) (p + 8) > (unsigned long) end) - { - for (; p <= end; p++) - { - ilog(L_MAIN, "%02x |%c", p[0], p[0]); - } - } - else - ilog(L_MAIN, - "%02x %02x %02x %02x %02x %02x %02x %02x |%c%c%c%c%c%c%c%c", - p[0], p[1], p[2], p[3], p[4], p[5], - p[6], p[7], p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - } - } + if(handle_command(mptr, client_p, from, i, /* XXX discards const!!! */ (const char **)para) < -1) { + char *p; + for (p = pbuffer; p <= end; p += 8) { + /* HACK HACK */ + /* Its expected this nasty code can be removed + * or rewritten later if still needed. + */ + if((unsigned long) (p + 8) > (unsigned long) end) { + for (; p <= end; p++) { + ilog(L_MAIN, "%02x |%c", p[0], p[0]); + } + } else + ilog(L_MAIN, + "%02x %02x %02x %02x %02x %02x %02x %02x |%c%c%c%c%c%c%c%c", + p[0], p[1], p[2], p[3], p[4], p[5], + p[6], p[7], p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); + } + } } @@ -306,93 +280,90 @@ parse(struct Client *client_p, char *pbuffer, char *bufend) */ static int handle_command(struct Message *mptr, struct Client *client_p, - struct Client *from, int i, const char** hpara) + struct Client *from, int i, const char** hpara) { - struct MessageEntry ehandler; - MessageHandler handler = 0; - char squitreason[80]; + struct MessageEntry ehandler; + MessageHandler handler = 0; + char squitreason[80]; - if(IsAnyDead(client_p)) - return -1; + if(IsAnyDead(client_p)) + return -1; - if(IsServer(client_p)) - mptr->rcount++; + if(IsServer(client_p)) + mptr->rcount++; - mptr->count++; + mptr->count++; - /* New patch to avoid server flooding from unregistered connects - - Pie-Man 07/27/2000 */ + /* New patch to avoid server flooding from unregistered connects + - Pie-Man 07/27/2000 */ - if(!IsRegistered(client_p)) - { - /* if its from a possible server connection - * ignore it.. more than likely its a header thats sneaked through - */ + if(!IsRegistered(client_p)) { + /* if its from a possible server connection + * ignore it.. more than likely its a header thats sneaked through + */ - if(IsAnyServer(client_p) && !(mptr->flags & MFLG_UNREG)) - return (1); - } + if(IsAnyServer(client_p) && !(mptr->flags & MFLG_UNREG)) + return (1); + } - ehandler = mptr->handlers[from->handler]; - handler = ehandler.handler; + ehandler = mptr->handlers[from->handler]; + handler = ehandler.handler; - /* check right amount of params is passed... --is */ - if(i < ehandler.min_para || - (ehandler.min_para && EmptyString(hpara[ehandler.min_para - 1]))) - { - if(!IsServer(client_p)) - { - sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), - me.name, - EmptyString(client_p->name) ? "*" : client_p->name, - mptr->cmd); - if(MyClient(client_p)) - return (1); - else - return (-1); - } + /* check right amount of params is passed... --is */ + if(i < ehandler.min_para || + (ehandler.min_para && EmptyString(hpara[ehandler.min_para - 1]))) { + if(!IsServer(client_p)) { + sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), + me.name, + EmptyString(client_p->name) ? "*" : client_p->name, + mptr->cmd); + if(MyClient(client_p)) + return (1); + else + return (-1); + } - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Dropping server %s due to (invalid) command '%s'" - " with only %d arguments (expecting %d).", - client_p->name, mptr->cmd, i, ehandler.min_para); - ilog(L_SERVER, - "Insufficient parameters (%d < %d) for command '%s' from %s.", - i, ehandler.min_para, mptr->cmd, client_p->name); - rb_snprintf(squitreason, sizeof squitreason, - "Insufficient parameters (%d < %d) for command '%s'", - i, ehandler.min_para, mptr->cmd); - exit_client(client_p, client_p, client_p, squitreason); - return (-1); - } + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Dropping server %s due to (invalid) command '%s'" + " with only %d arguments (expecting %d).", + client_p->name, mptr->cmd, i, ehandler.min_para); + ilog(L_SERVER, + "Insufficient parameters (%d < %d) for command '%s' from %s.", + i, ehandler.min_para, mptr->cmd, client_p->name); + rb_snprintf(squitreason, sizeof squitreason, + "Insufficient parameters (%d < %d) for command '%s'", + i, ehandler.min_para, mptr->cmd); + exit_client(client_p, client_p, client_p, squitreason); + return (-1); + } - (*handler) (client_p, from, i, hpara); - return (1); + (*handler) (client_p, from, i, hpara); + return (1); } void handle_encap(struct Client *client_p, struct Client *source_p, - const char *command, int parc, const char *parv[]) + const char *command, int parc, const char *parv[]) { - struct Message *mptr; - struct MessageEntry ehandler; - MessageHandler handler = 0; + struct Message *mptr; + struct MessageEntry ehandler; + MessageHandler handler = 0; - parv[0] = source_p->name; + parv[0] = source_p->name; - mptr = irc_dictionary_retrieve(cmd_dict, command); + mptr = irc_dictionary_retrieve(cmd_dict, command); - if(mptr == NULL || mptr->cmd == NULL) - return; + if(mptr == NULL || mptr->cmd == NULL) + return; - ehandler = mptr->handlers[ENCAP_HANDLER]; - handler = ehandler.handler; + ehandler = mptr->handlers[ENCAP_HANDLER]; + handler = ehandler.handler; - if(parc < ehandler.min_para || - (ehandler.min_para && EmptyString(parv[ehandler.min_para - 1]))) - return; + if(parc < ehandler.min_para || + (ehandler.min_para && EmptyString(parv[ehandler.min_para - 1]))) + return; - (*handler) (client_p, source_p, parc, parv); + (*handler) (client_p, source_p, parc, parv); } /* @@ -407,7 +378,7 @@ handle_encap(struct Client *client_p, struct Client *source_p, void clear_hash_parse() { - cmd_dict = irc_dictionary_create(strcasecmp); + cmd_dict = irc_dictionary_create(strcasecmp); } /* mod_add_cmd @@ -422,18 +393,18 @@ clear_hash_parse() void mod_add_cmd(struct Message *msg) { - s_assert(msg != NULL); - if(msg == NULL) - return; + s_assert(msg != NULL); + if(msg == NULL) + return; - if (irc_dictionary_find(cmd_dict, msg->cmd) != NULL) - return; + if (irc_dictionary_find(cmd_dict, msg->cmd) != NULL) + return; - msg->count = 0; - msg->rcount = 0; - msg->bytes = 0; + msg->count = 0; + msg->rcount = 0; + msg->bytes = 0; - irc_dictionary_add(cmd_dict, msg->cmd, msg); + irc_dictionary_add(cmd_dict, msg->cmd, msg); } /* mod_del_cmd @@ -445,11 +416,11 @@ mod_add_cmd(struct Message *msg) void mod_del_cmd(struct Message *msg) { - s_assert(msg != NULL); - if(msg == NULL) - return; + s_assert(msg != NULL); + if(msg == NULL) + return; - irc_dictionary_delete(cmd_dict, msg->cmd); + irc_dictionary_delete(cmd_dict, msg->cmd); } /* @@ -462,26 +433,24 @@ mod_del_cmd(struct Message *msg) void report_messages(struct Client *source_p) { - struct DictionaryIter iter; - struct Message *msg; - struct alias_entry *amsg; + struct DictionaryIter iter; + struct Message *msg; + struct alias_entry *amsg; - DICTIONARY_FOREACH(msg, &iter, cmd_dict) - { - s_assert(msg->cmd != NULL); - sendto_one_numeric(source_p, RPL_STATSCOMMANDS, - form_str(RPL_STATSCOMMANDS), - msg->cmd, msg->count, - msg->bytes, msg->rcount); - } + DICTIONARY_FOREACH(msg, &iter, cmd_dict) { + s_assert(msg->cmd != NULL); + sendto_one_numeric(source_p, RPL_STATSCOMMANDS, + form_str(RPL_STATSCOMMANDS), + msg->cmd, msg->count, + msg->bytes, msg->rcount); + } - DICTIONARY_FOREACH(amsg, &iter, alias_dict) - { - s_assert(amsg->name != NULL); - sendto_one_numeric(source_p, RPL_STATSCOMMANDS, - form_str(RPL_STATSCOMMANDS), - amsg->name, amsg->hits, 0, 0); - } + DICTIONARY_FOREACH(amsg, &iter, alias_dict) { + s_assert(amsg->name != NULL); + sendto_one_numeric(source_p, RPL_STATSCOMMANDS, + form_str(RPL_STATSCOMMANDS), + amsg->name, amsg->hits, 0, 0); + } } /* cancel_clients() @@ -494,74 +463,68 @@ report_messages(struct Client *source_p) static void cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd) { - /* ok, fake prefix happens naturally during a burst on a nick - * collision with TS5, we cant kill them because one client has to - * survive, so we just send an error. - */ - if(IsServer(source_p) || IsMe(source_p)) - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Message for %s[%s] from %s", - source_p->name, source_p->from->name, - client_p->name); - } - else - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Message for %s[%s@%s!%s] from %s (TS, ignored)", - source_p->name, - source_p->username, - source_p->host, - source_p->from->name, - client_p->name); - } + /* ok, fake prefix happens naturally during a burst on a nick + * collision with TS5, we cant kill them because one client has to + * survive, so we just send an error. + */ + if(IsServer(source_p) || IsMe(source_p)) { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Message for %s[%s] from %s", + source_p->name, source_p->from->name, + client_p->name); + } else { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Message for %s[%s@%s!%s] from %s (TS, ignored)", + source_p->name, + source_p->username, + source_p->host, + source_p->from->name, + client_p->name); + } } /* remove_unknown() * * inputs - client who gave us message, supposed sender, buffer - * output - + * output - * side effects - kills issued for clients, squits for servers */ static void remove_unknown(struct Client *client_p, char *lsender, char *lbuffer) { - int slen = strlen(lsender); - char sid[4]; - struct Client *server; + int slen = strlen(lsender); + char sid[4]; + struct Client *server; - /* meepfoo is a nickname (ignore) - * #XXXXXXXX is a UID (KILL) - * #XX is a SID (SQUIT) - * meep.foo is a server (SQUIT) - */ - if((IsDigit(lsender[0]) && slen == 3) || - (strchr(lsender, '.') != NULL)) - { - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Unknown prefix (%s) from %s, Squitting %s", - lbuffer, client_p->name, lsender); + /* meepfoo is a nickname (ignore) + * #XXXXXXXX is a UID (KILL) + * #XX is a SID (SQUIT) + * meep.foo is a server (SQUIT) + */ + if((IsDigit(lsender[0]) && slen == 3) || + (strchr(lsender, '.') != NULL)) { + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Unknown prefix (%s) from %s, Squitting %s", + lbuffer, client_p->name, lsender); - sendto_one(client_p, - ":%s SQUIT %s :(Unknown prefix (%s) from %s)", - get_id(&me, client_p), lsender, - lbuffer, client_p->name); - } - else if(!IsDigit(lsender[0])) - ; - else if(slen != 9) - sendto_realops_snomask(SNO_DEBUG, L_ALL, - "Invalid prefix (%s) from %s", - lbuffer, client_p->name); - else - { - memcpy(sid, lsender, 3); - sid[3] = '\0'; - server = find_server(NULL, sid); - if (server != NULL && server->from == client_p) - sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", - get_id(&me, client_p), lsender, me.name); - } + sendto_one(client_p, + ":%s SQUIT %s :(Unknown prefix (%s) from %s)", + get_id(&me, client_p), lsender, + lbuffer, client_p->name); + } else if(!IsDigit(lsender[0])) + ; + else if(slen != 9) + sendto_realops_snomask(SNO_DEBUG, L_ALL, + "Invalid prefix (%s) from %s", + lbuffer, client_p->name); + else { + memcpy(sid, lsender, 3); + sid[3] = '\0'; + server = find_server(NULL, sid); + if (server != NULL && server->from == client_p) + sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", + get_id(&me, client_p), lsender, me.name); + } } @@ -582,173 +545,160 @@ remove_unknown(struct Client *client_p, char *lsender, char *lbuffer) static void do_numeric(char numeric[], struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { - struct Client *target_p; - struct Channel *chptr; + struct Client *target_p; + struct Channel *chptr; - if(parc < 2 || !IsServer(source_p)) - return; + if(parc < 2 || !IsServer(source_p)) + return; - /* Remap low number numerics. */ - if(numeric[0] == '0') - numeric[0] = '1'; + /* Remap low number numerics. */ + if(numeric[0] == '0') + numeric[0] = '1'; - /* - * Prepare the parameter portion of the message into 'buffer'. - * (Because the buffer is twice as large as the message buffer - * for the socket, no overflow can occur here... ...on current - * assumptions--bets are off, if these are changed --msa) - * Note: if buffer is non-empty, it will begin with SPACE. - */ - if(parc > 1) - { - char *t = buffer; /* Current position within the buffer */ - int i; - int tl; /* current length of presently being built string in t */ - for (i = 2; i < (parc - 1); i++) - { - tl = rb_sprintf(t, " %s", parv[i]); - t += tl; - } - rb_sprintf(t, " :%s", parv[parc - 1]); - } + /* + * Prepare the parameter portion of the message into 'buffer'. + * (Because the buffer is twice as large as the message buffer + * for the socket, no overflow can occur here... ...on current + * assumptions--bets are off, if these are changed --msa) + * Note: if buffer is non-empty, it will begin with SPACE. + */ + if(parc > 1) { + char *t = buffer; /* Current position within the buffer */ + int i; + int tl; /* current length of presently being built string in t */ + for (i = 2; i < (parc - 1); i++) { + tl = rb_sprintf(t, " %s", parv[i]); + t += tl; + } + rb_sprintf(t, " :%s", parv[parc - 1]); + } - if((target_p = find_client(parv[1])) != NULL) - { - if(IsMe(target_p)) - { - /* - * We shouldn't get numerics sent to us, - * any numerics we do get indicate a bug somewhere.. - */ - /* ugh. this is here because of nick collisions. when two servers - * relink, they burst each other their nicks, then perform collides. - * if there is a nick collision, BOTH servers will kill their own - * nicks, and BOTH will kill the other servers nick, which wont exist, - * because it will have been already killed by the local server. - * - * unfortunately, as we cant guarantee other servers will do the - * "right thing" on a nick collision, we have to keep both kills. - * ergo we need to ignore ERR_NOSUCHNICK. --fl_ - */ - /* quick comment. This _was_ tried. i.e. assume the other servers - * will do the "right thing" and kill a nick that is colliding. - * unfortunately, it did not work. --Dianora - */ - /* note, now we send PING on server connect, we can - * also get ERR_NOSUCHSERVER.. - */ - if(atoi(numeric) != ERR_NOSUCHNICK && - atoi(numeric) != ERR_NOSUCHSERVER) - sendto_realops_snomask(SNO_GENERAL, L_ADMIN, - "*** %s(via %s) sent a %s numeric to me: %s", - source_p->name, - client_p->name, numeric, buffer); - return; - } - else if(target_p->from == client_p) - { - /* This message changed direction (nick collision?) - * ignore it. - */ - return; - } + if((target_p = find_client(parv[1])) != NULL) { + if(IsMe(target_p)) { + /* + * We shouldn't get numerics sent to us, + * any numerics we do get indicate a bug somewhere.. + */ + /* ugh. this is here because of nick collisions. when two servers + * relink, they burst each other their nicks, then perform collides. + * if there is a nick collision, BOTH servers will kill their own + * nicks, and BOTH will kill the other servers nick, which wont exist, + * because it will have been already killed by the local server. + * + * unfortunately, as we cant guarantee other servers will do the + * "right thing" on a nick collision, we have to keep both kills. + * ergo we need to ignore ERR_NOSUCHNICK. --fl_ + */ + /* quick comment. This _was_ tried. i.e. assume the other servers + * will do the "right thing" and kill a nick that is colliding. + * unfortunately, it did not work. --Dianora + */ + /* note, now we send PING on server connect, we can + * also get ERR_NOSUCHSERVER.. + */ + if(atoi(numeric) != ERR_NOSUCHNICK && + atoi(numeric) != ERR_NOSUCHSERVER) + sendto_realops_snomask(SNO_GENERAL, L_ADMIN, + "*** %s(via %s) sent a %s numeric to me: %s", + source_p->name, + client_p->name, numeric, buffer); + return; + } else if(target_p->from == client_p) { + /* This message changed direction (nick collision?) + * ignore it. + */ + return; + } - /* csircd will send out unknown umode flag for +a (admin), drop it here. */ - if((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p)) - return; + /* csircd will send out unknown umode flag for +a (admin), drop it here. */ + if((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p)) + return; - /* Fake it for server hiding, if its our client */ - sendto_one(target_p, ":%s %s %s%s", - get_id(source_p, target_p), numeric, - get_id(target_p, target_p), buffer); - return; - } - else if((chptr = find_channel(parv[1])) != NULL) - sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr, - "%s %s%s", - numeric, chptr->chname, buffer); + /* Fake it for server hiding, if its our client */ + sendto_one(target_p, ":%s %s %s%s", + get_id(source_p, target_p), numeric, + get_id(target_p, target_p), buffer); + return; + } else if((chptr = find_channel(parv[1])) != NULL) + sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr, + "%s %s%s", + numeric, chptr->chname, buffer); } static void do_alias(struct alias_entry *aptr, struct Client *source_p, char *text) { - char *p; - struct Client *target_p; + char *p; + struct Client *target_p; - if (!IsFloodDone(source_p) && source_p->localClient->receiveM > 20) - flood_endgrace(source_p); + if (!IsFloodDone(source_p) && source_p->localClient->receiveM > 20) + flood_endgrace(source_p); - p = strchr(aptr->target, '@'); - if (p != NULL) - { - /* user@server */ - target_p = find_server(NULL, p + 1); - if (target_p != NULL && IsMe(target_p)) - target_p = NULL; - } - else - { - /* nick, must be +S */ - target_p = find_named_person(aptr->target); - if (target_p != NULL && !IsService(target_p)) - target_p = NULL; - } + p = strchr(aptr->target, '@'); + if (p != NULL) { + /* user@server */ + target_p = find_server(NULL, p + 1); + if (target_p != NULL && IsMe(target_p)) + target_p = NULL; + } else { + /* nick, must be +S */ + target_p = find_named_person(aptr->target); + if (target_p != NULL && !IsService(target_p)) + target_p = NULL; + } - if (target_p == NULL) - { - sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), aptr->target); - return; - } + if (target_p == NULL) { + sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), aptr->target); + return; + } - if (text != NULL && *text == ':') - text++; - if (text == NULL || *text == '\0') - { - sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); - return; - } + if (text != NULL && *text == ':') + text++; + if (text == NULL || *text == '\0') { + sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); + return; + } - /* increment the hitcounter on this alias */ - aptr->hits++; + /* increment the hitcounter on this alias */ + aptr->hits++; - sendto_one(target_p, ":%s PRIVMSG %s :%s", - get_id(source_p, target_p), - p != NULL ? aptr->target : get_id(target_p, target_p), - text); + sendto_one(target_p, ":%s PRIVMSG %s :%s", + get_id(source_p, target_p), + p != NULL ? aptr->target : get_id(target_p, target_p), + text); } int m_not_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); - return 0; + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); + return 0; } int m_unregistered(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - /* bit of a hack. - * I don't =really= want to waste a bit in a flag - * number_of_nick_changes is only really valid after the client - * is fully registered.. - */ - if(client_p->localClient->number_of_nick_changes == 0) - { - sendto_one(client_p, form_str(ERR_NOTREGISTERED), me.name); - client_p->localClient->number_of_nick_changes++; - } + /* bit of a hack. + * I don't =really= want to waste a bit in a flag + * number_of_nick_changes is only really valid after the client + * is fully registered.. + */ + if(client_p->localClient->number_of_nick_changes == 0) { + sendto_one(client_p, form_str(ERR_NOTREGISTERED), me.name); + client_p->localClient->number_of_nick_changes++; + } - return 0; + return 0; } int m_registered(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - sendto_one(client_p, form_str(ERR_ALREADYREGISTRED), me.name, source_p->name); - return 0; + sendto_one(client_p, form_str(ERR_ALREADYREGISTRED), me.name, source_p->name); + return 0; } int m_ignore(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - return 0; + return 0; } diff --git a/src/privilege.c b/src/privilege.c index 6b2c8b7..6d91073 100644 --- a/src/privilege.c +++ b/src/privilege.c @@ -31,181 +31,170 @@ static rb_dlink_list privilegeset_list = {}; int privilegeset_in_set(struct PrivilegeSet *set, const char *priv) { - s_assert(set != NULL); - s_assert(priv != NULL); + s_assert(set != NULL); + s_assert(priv != NULL); - return strstr(set->privs, priv) != NULL; + return strstr(set->privs, priv) != NULL; } static struct PrivilegeSet * privilegeset_get_any(const char *name) { - rb_dlink_node *iter; + rb_dlink_node *iter; - s_assert(name != NULL); + s_assert(name != NULL); - RB_DLINK_FOREACH(iter, privilegeset_list.head) - { - struct PrivilegeSet *set = (struct PrivilegeSet *) iter->data; + RB_DLINK_FOREACH(iter, privilegeset_list.head) { + struct PrivilegeSet *set = (struct PrivilegeSet *) iter->data; - if (!strcasecmp(set->name, name)) - return set; - } + if (!strcasecmp(set->name, name)) + return set; + } - return NULL; + return NULL; } struct PrivilegeSet * privilegeset_set_new(const char *name, const char *privs, PrivilegeFlags flags) { - struct PrivilegeSet *set; + struct PrivilegeSet *set; - set = privilegeset_get_any(name); - if (set != NULL) - { - if (!(set->status & CONF_ILLEGAL)) - ilog(L_MAIN, "Duplicate privset %s", name); - set->status &= ~CONF_ILLEGAL; - rb_free(set->privs); - } - else - { - set = rb_malloc(sizeof(struct PrivilegeSet)); - set->status = 0; - set->refs = 0; - set->name = rb_strdup(name); + set = privilegeset_get_any(name); + if (set != NULL) { + if (!(set->status & CONF_ILLEGAL)) + ilog(L_MAIN, "Duplicate privset %s", name); + set->status &= ~CONF_ILLEGAL; + rb_free(set->privs); + } else { + set = rb_malloc(sizeof(struct PrivilegeSet)); + set->status = 0; + set->refs = 0; + set->name = rb_strdup(name); - rb_dlinkAdd(set, &set->node, &privilegeset_list); - } - set->privs = rb_strdup(privs); - set->flags = flags; + rb_dlinkAdd(set, &set->node, &privilegeset_list); + } + set->privs = rb_strdup(privs); + set->flags = flags; - return set; + return set; } struct PrivilegeSet * privilegeset_extend(struct PrivilegeSet *parent, const char *name, const char *privs, PrivilegeFlags flags) { - struct PrivilegeSet *set; + struct PrivilegeSet *set; - s_assert(parent != NULL); - s_assert(name != NULL); - s_assert(privs != NULL); + s_assert(parent != NULL); + s_assert(name != NULL); + s_assert(privs != NULL); - set = privilegeset_get_any(name); - if (set != NULL) - { - if (!(set->status & CONF_ILLEGAL)) - ilog(L_MAIN, "Duplicate privset %s", name); - set->status &= ~CONF_ILLEGAL; - rb_free(set->privs); - } - else - { - set = rb_malloc(sizeof(struct PrivilegeSet)); - set->status = 0; - set->refs = 0; - set->name = rb_strdup(name); + set = privilegeset_get_any(name); + if (set != NULL) { + if (!(set->status & CONF_ILLEGAL)) + ilog(L_MAIN, "Duplicate privset %s", name); + set->status &= ~CONF_ILLEGAL; + rb_free(set->privs); + } else { + set = rb_malloc(sizeof(struct PrivilegeSet)); + set->status = 0; + set->refs = 0; + set->name = rb_strdup(name); - rb_dlinkAdd(set, &set->node, &privilegeset_list); - } - set->flags = flags; - set->privs = rb_malloc(strlen(parent->privs) + 1 + strlen(privs) + 1); - strcpy(set->privs, parent->privs); - strcat(set->privs, " "); - strcat(set->privs, privs); + rb_dlinkAdd(set, &set->node, &privilegeset_list); + } + set->flags = flags; + set->privs = rb_malloc(strlen(parent->privs) + 1 + strlen(privs) + 1); + strcpy(set->privs, parent->privs); + strcat(set->privs, " "); + strcat(set->privs, privs); - return set; + return set; } struct PrivilegeSet * privilegeset_get(const char *name) { - struct PrivilegeSet *set; + struct PrivilegeSet *set; - set = privilegeset_get_any(name); - if (set != NULL && set->status & CONF_ILLEGAL) - set = NULL; - return set; + set = privilegeset_get_any(name); + if (set != NULL && set->status & CONF_ILLEGAL) + set = NULL; + return set; } struct PrivilegeSet * privilegeset_ref(struct PrivilegeSet *set) { - s_assert(set != NULL); + s_assert(set != NULL); - set->refs++; + set->refs++; - return set; + return set; } void privilegeset_unref(struct PrivilegeSet *set) { - s_assert(set != NULL); + s_assert(set != NULL); - if (set->refs > 0) - set->refs--; - else - ilog(L_MAIN, "refs on privset %s is already 0", - set->name); - if (set->refs == 0 && set->status & CONF_ILLEGAL) - { - rb_dlinkDelete(&set->node, &privilegeset_list); + if (set->refs > 0) + set->refs--; + else + ilog(L_MAIN, "refs on privset %s is already 0", + set->name); + if (set->refs == 0 && set->status & CONF_ILLEGAL) { + rb_dlinkDelete(&set->node, &privilegeset_list); - rb_free(set->name); - rb_free(set->privs); - rb_free(set); - } + rb_free(set->name); + rb_free(set->privs); + rb_free(set); + } } void privilegeset_mark_all_illegal(void) { - rb_dlink_node *iter; + rb_dlink_node *iter; - RB_DLINK_FOREACH(iter, privilegeset_list.head) - { - struct PrivilegeSet *set = (struct PrivilegeSet *) iter->data; + RB_DLINK_FOREACH(iter, privilegeset_list.head) { + struct PrivilegeSet *set = (struct PrivilegeSet *) iter->data; - /* the "default" privset is special and must remain available */ - if (!strcmp(set->name, "default")) - continue; + /* the "default" privset is special and must remain available */ + if (!strcmp(set->name, "default")) + continue; - set->status |= CONF_ILLEGAL; - rb_free(set->privs); - set->privs = rb_strdup(""); - /* but do not free it yet */ - } + set->status |= CONF_ILLEGAL; + rb_free(set->privs); + set->privs = rb_strdup(""); + /* but do not free it yet */ + } } void privilegeset_delete_all_illegal(void) { - rb_dlink_node *iter, *next; + rb_dlink_node *iter, *next; - RB_DLINK_FOREACH_SAFE(iter, next, privilegeset_list.head) - { - struct PrivilegeSet *set = (struct PrivilegeSet *) iter->data; + RB_DLINK_FOREACH_SAFE(iter, next, privilegeset_list.head) { + struct PrivilegeSet *set = (struct PrivilegeSet *) iter->data; - privilegeset_ref(set); - privilegeset_unref(set); - } + privilegeset_ref(set); + privilegeset_unref(set); + } } void privilegeset_report(struct Client *source_p) { - rb_dlink_node *ptr; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, privilegeset_list.head) - { - struct PrivilegeSet *set = ptr->data; + RB_DLINK_FOREACH(ptr, privilegeset_list.head) { + struct PrivilegeSet *set = ptr->data; - /* use RPL_STATSDEBUG for now -- jilles */ - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "O :%s %s", - set->name, - set->privs); - } + /* use RPL_STATSDEBUG for now -- jilles */ + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "O :%s %s", + set->name, + set->privs); + } } diff --git a/src/reject.c b/src/reject.c index ab9163b..79e2bff 100644 --- a/src/reject.c +++ b/src/reject.c @@ -43,354 +43,331 @@ static rb_patricia_tree_t *throttle_tree; static void throttle_expires(void *unused); -typedef struct _reject_data -{ - rb_dlink_node rnode; - time_t time; - unsigned int count; - uint32_t mask_hashv; +typedef struct _reject_data { + rb_dlink_node rnode; + time_t time; + unsigned int count; + uint32_t mask_hashv; } reject_t; -typedef struct _delay_data -{ - rb_dlink_node node; - rb_fde_t *F; +typedef struct _delay_data { + rb_dlink_node node; + rb_fde_t *F; } delay_t; -typedef struct _throttle -{ - rb_dlink_node node; - time_t last; - int count; +typedef struct _throttle { + rb_dlink_node node; + time_t last; + int count; } throttle_t; unsigned long delay_exit_length(void) { - return rb_dlink_list_length(&delay_exit); + return rb_dlink_list_length(&delay_exit); } static void reject_exit(void *unused) { - rb_dlink_node *ptr, *ptr_next; - delay_t *ddata; - static const char *errbuf = "ERROR :Closing Link: (*** Banned (cache))\r\n"; - - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, delay_exit.head) - { - ddata = ptr->data; + rb_dlink_node *ptr, *ptr_next; + delay_t *ddata; + static const char *errbuf = "ERROR :Closing Link: (*** Banned (cache))\r\n"; - rb_write(ddata->F, errbuf, strlen(errbuf)); - rb_close(ddata->F); - rb_free(ddata); - } + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, delay_exit.head) { + ddata = ptr->data; - delay_exit.head = delay_exit.tail = NULL; - delay_exit.length = 0; + rb_write(ddata->F, errbuf, strlen(errbuf)); + rb_close(ddata->F); + rb_free(ddata); + } + + delay_exit.head = delay_exit.tail = NULL; + delay_exit.length = 0; } static void reject_expires(void *unused) { - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - reject_t *rdata; - - RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) - { - pnode = ptr->data; - rdata = pnode->data; + rb_dlink_node *ptr, *next; + rb_patricia_node_t *pnode; + reject_t *rdata; - if(rdata->time + ConfigFileEntry.reject_duration > rb_current_time()) - continue; + RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) { + pnode = ptr->data; + rdata = pnode->data; - rb_dlinkDelete(ptr, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - } + if(rdata->time + ConfigFileEntry.reject_duration > rb_current_time()) + continue; + + rb_dlinkDelete(ptr, &reject_list); + rb_free(rdata); + rb_patricia_remove(reject_tree, pnode); + } } void init_reject(void) { - reject_tree = rb_new_patricia(PATRICIA_BITS); - throttle_tree = rb_new_patricia(PATRICIA_BITS); - rb_event_add("reject_exit", reject_exit, NULL, DELAYED_EXIT_TIME); - rb_event_add("reject_expires", reject_expires, NULL, 60); - rb_event_add("throttle_expires", throttle_expires, NULL, 10); + reject_tree = rb_new_patricia(PATRICIA_BITS); + throttle_tree = rb_new_patricia(PATRICIA_BITS); + rb_event_add("reject_exit", reject_exit, NULL, DELAYED_EXIT_TIME); + rb_event_add("reject_expires", reject_expires, NULL, 60); + rb_event_add("throttle_expires", throttle_expires, NULL, 10); } unsigned long throttle_size(void) { - unsigned long count; - rb_dlink_node *ptr; - rb_patricia_node_t *pnode; - throttle_t *t; + unsigned long count; + rb_dlink_node *ptr; + rb_patricia_node_t *pnode; + throttle_t *t; - count = 0; - RB_DLINK_FOREACH(ptr, throttle_list.head) - { - pnode = ptr->data; - t = pnode->data; - if (t->count > ConfigFileEntry.throttle_count) - count++; - } + count = 0; + RB_DLINK_FOREACH(ptr, throttle_list.head) { + pnode = ptr->data; + t = pnode->data; + if (t->count > ConfigFileEntry.throttle_count) + count++; + } - return count; + return count; } void add_reject(struct Client *client_p, const char *mask1, const char *mask2) { - rb_patricia_node_t *pnode; - reject_t *rdata; - uint32_t hashv; + rb_patricia_node_t *pnode; + reject_t *rdata; + uint32_t hashv; - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return; + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) + return; - hashv = 0; - if (mask1 != NULL) - hashv ^= fnv_hash_upper((const unsigned char *)mask1, 32); - if (mask2 != NULL) - hashv ^= fnv_hash_upper((const unsigned char *)mask2, 32); + hashv = 0; + if (mask1 != NULL) + hashv ^= fnv_hash_upper((const unsigned char *)mask1, 32); + if (mask2 != NULL) + hashv ^= fnv_hash_upper((const unsigned char *)mask2, 32); - if((pnode = rb_match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) - { - rdata = pnode->data; - rdata->time = rb_current_time(); - rdata->count++; - } - else - { - int bitlen = 32; + if((pnode = rb_match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) { + rdata = pnode->data; + rdata->time = rb_current_time(); + rdata->count++; + } else { + int bitlen = 32; #ifdef RB_IPV6 - if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET6) - bitlen = 128; + if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET6) + bitlen = 128; #endif - pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); - pnode->data = rdata = rb_malloc(sizeof(reject_t)); - rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list); - rdata->time = rb_current_time(); - rdata->count = 1; - } - rdata->mask_hashv = hashv; + pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); + pnode->data = rdata = rb_malloc(sizeof(reject_t)); + rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list); + rdata->time = rb_current_time(); + rdata->count = 1; + } + rdata->mask_hashv = hashv; } int check_reject(rb_fde_t *F, struct sockaddr *addr) { - rb_patricia_node_t *pnode; - reject_t *rdata; - delay_t *ddata; - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return 0; - - pnode = rb_match_ip(reject_tree, addr); - if(pnode != NULL) - { - rdata = pnode->data; + rb_patricia_node_t *pnode; + reject_t *rdata; + delay_t *ddata; + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) + return 0; - rdata->time = rb_current_time(); - if(rdata->count > (unsigned long)ConfigFileEntry.reject_after_count) - { - ddata = rb_malloc(sizeof(delay_t)); - ServerStats.is_rej++; - rb_setselect(F, RB_SELECT_WRITE | RB_SELECT_READ, NULL, NULL); - ddata->F = F; - rb_dlinkAdd(ddata, &ddata->node, &delay_exit); - return 1; - } - } - /* Caller does what it wants */ - return 0; + pnode = rb_match_ip(reject_tree, addr); + if(pnode != NULL) { + rdata = pnode->data; + + rdata->time = rb_current_time(); + if(rdata->count > (unsigned long)ConfigFileEntry.reject_after_count) { + ddata = rb_malloc(sizeof(delay_t)); + ServerStats.is_rej++; + rb_setselect(F, RB_SELECT_WRITE | RB_SELECT_READ, NULL, NULL); + ddata->F = F; + rb_dlinkAdd(ddata, &ddata->node, &delay_exit); + return 1; + } + } + /* Caller does what it wants */ + return 0; } int is_reject_ip(struct sockaddr *addr) { - rb_patricia_node_t *pnode; - reject_t *rdata; - int duration; + rb_patricia_node_t *pnode; + reject_t *rdata; + int duration; - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return 0; - - pnode = rb_match_ip(reject_tree, addr); - if(pnode != NULL) - { - rdata = pnode->data; + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) + return 0; - if(rdata->count > (unsigned long)ConfigFileEntry.reject_after_count) - { - duration = rdata->time + ConfigFileEntry.reject_duration - rb_current_time(); - return duration > 0 ? duration : 1; - } - } - return 0; + pnode = rb_match_ip(reject_tree, addr); + if(pnode != NULL) { + rdata = pnode->data; + + if(rdata->count > (unsigned long)ConfigFileEntry.reject_after_count) { + duration = rdata->time + ConfigFileEntry.reject_duration - rb_current_time(); + return duration > 0 ? duration : 1; + } + } + return 0; } -void +void flush_reject(void) { - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - reject_t *rdata; - - RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) - { - pnode = ptr->data; - rdata = pnode->data; - rb_dlinkDelete(ptr, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - } + rb_dlink_node *ptr, *next; + rb_patricia_node_t *pnode; + reject_t *rdata; + + RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) { + pnode = ptr->data; + rdata = pnode->data; + rb_dlinkDelete(ptr, &reject_list); + rb_free(rdata); + rb_patricia_remove(reject_tree, pnode); + } } -int +int remove_reject_ip(const char *ip) { - rb_patricia_node_t *pnode; - - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return -1; + rb_patricia_node_t *pnode; - if((pnode = rb_match_string(reject_tree, ip)) != NULL) - { - reject_t *rdata = pnode->data; - rb_dlinkDelete(&rdata->rnode, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - return 1; - } - return 0; + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) + return -1; + + if((pnode = rb_match_string(reject_tree, ip)) != NULL) { + reject_t *rdata = pnode->data; + rb_dlinkDelete(&rdata->rnode, &reject_list); + rb_free(rdata); + rb_patricia_remove(reject_tree, pnode); + return 1; + } + return 0; } int remove_reject_mask(const char *mask1, const char *mask2) { - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - reject_t *rdata; - uint32_t hashv; - int n = 0; - - hashv = 0; - if (mask1 != NULL) - hashv ^= fnv_hash_upper((const unsigned char *)mask1, 32); - if (mask2 != NULL) - hashv ^= fnv_hash_upper((const unsigned char *)mask2, 32); - RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) - { - pnode = ptr->data; - rdata = pnode->data; - if (rdata->mask_hashv == hashv) - { - rb_dlinkDelete(ptr, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - n++; - } - } - return n; + rb_dlink_node *ptr, *next; + rb_patricia_node_t *pnode; + reject_t *rdata; + uint32_t hashv; + int n = 0; + + hashv = 0; + if (mask1 != NULL) + hashv ^= fnv_hash_upper((const unsigned char *)mask1, 32); + if (mask2 != NULL) + hashv ^= fnv_hash_upper((const unsigned char *)mask2, 32); + RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) { + pnode = ptr->data; + rdata = pnode->data; + if (rdata->mask_hashv == hashv) { + rb_dlinkDelete(ptr, &reject_list); + rb_free(rdata); + rb_patricia_remove(reject_tree, pnode); + n++; + } + } + return n; } int throttle_add(struct sockaddr *addr) { - throttle_t *t; - rb_patricia_node_t *pnode; + throttle_t *t; + rb_patricia_node_t *pnode; - if((pnode = rb_match_ip(throttle_tree, addr)) != NULL) - { - t = pnode->data; + if((pnode = rb_match_ip(throttle_tree, addr)) != NULL) { + t = pnode->data; - if(t->count > ConfigFileEntry.throttle_count) - { - ServerStats.is_thr++; - return 1; - } - /* Stop penalizing them after they've been throttled */ - t->last = rb_current_time(); - t->count++; + if(t->count > ConfigFileEntry.throttle_count) { + ServerStats.is_thr++; + return 1; + } + /* Stop penalizing them after they've been throttled */ + t->last = rb_current_time(); + t->count++; - } else { - int bitlen = 32; + } else { + int bitlen = 32; #ifdef RB_IPV6 - if(GET_SS_FAMILY(addr) == AF_INET6) - bitlen = 128; + if(GET_SS_FAMILY(addr) == AF_INET6) + bitlen = 128; #endif - t = rb_malloc(sizeof(throttle_t)); - t->last = rb_current_time(); - t->count = 1; - pnode = make_and_lookup_ip(throttle_tree, addr, bitlen); - pnode->data = t; - rb_dlinkAdd(pnode, &t->node, &throttle_list); - } - return 0; + t = rb_malloc(sizeof(throttle_t)); + t->last = rb_current_time(); + t->count = 1; + pnode = make_and_lookup_ip(throttle_tree, addr, bitlen); + pnode->data = t; + rb_dlinkAdd(pnode, &t->node, &throttle_list); + } + return 0; } int is_throttle_ip(struct sockaddr *addr) { - throttle_t *t; - rb_patricia_node_t *pnode; - int duration; + throttle_t *t; + rb_patricia_node_t *pnode; + int duration; - if((pnode = rb_match_ip(throttle_tree, addr)) != NULL) - { - t = pnode->data; - if(t->count > ConfigFileEntry.throttle_count) - { - duration = t->last + ConfigFileEntry.throttle_duration - rb_current_time(); - return duration > 0 ? duration : 1; - } - } - return 0; + if((pnode = rb_match_ip(throttle_tree, addr)) != NULL) { + t = pnode->data; + if(t->count > ConfigFileEntry.throttle_count) { + duration = t->last + ConfigFileEntry.throttle_duration - rb_current_time(); + return duration > 0 ? duration : 1; + } + } + return 0; } -void +void flush_throttle(void) { - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - throttle_t *t; - - RB_DLINK_FOREACH_SAFE(ptr, next, throttle_list.head) - { - pnode = ptr->data; - t = pnode->data; + rb_dlink_node *ptr, *next; + rb_patricia_node_t *pnode; + throttle_t *t; - rb_dlinkDelete(ptr, &throttle_list); - rb_free(t); - rb_patricia_remove(throttle_tree, pnode); - } + RB_DLINK_FOREACH_SAFE(ptr, next, throttle_list.head) { + pnode = ptr->data; + t = pnode->data; + + rb_dlinkDelete(ptr, &throttle_list); + rb_free(t); + rb_patricia_remove(throttle_tree, pnode); + } } static void throttle_expires(void *unused) { - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - throttle_t *t; - - RB_DLINK_FOREACH_SAFE(ptr, next, throttle_list.head) - { - pnode = ptr->data; - t = pnode->data; + rb_dlink_node *ptr, *next; + rb_patricia_node_t *pnode; + throttle_t *t; - if(t->last + ConfigFileEntry.throttle_duration > rb_current_time()) - continue; + RB_DLINK_FOREACH_SAFE(ptr, next, throttle_list.head) { + pnode = ptr->data; + t = pnode->data; - rb_dlinkDelete(ptr, &throttle_list); - rb_free(t); - rb_patricia_remove(throttle_tree, pnode); - } + if(t->last + ConfigFileEntry.throttle_duration > rb_current_time()) + continue; + + rb_dlinkDelete(ptr, &throttle_list); + rb_free(t); + rb_patricia_remove(throttle_tree, pnode); + } } diff --git a/src/res.c b/src/res.c index 2dac47f..7dea349 100644 --- a/src/res.c +++ b/src/res.c @@ -13,7 +13,7 @@ * --Bleep (Thomas Helvey ) * * This was all needlessly complicated for irc. Simplified. No more hostent - * All we really care about is the IP -> hostname mappings. Thats all. + * All we really care about is the IP -> hostname mappings. Thats all. * * Apr 28, 2003 --cryogen and Dianora * @@ -54,21 +54,20 @@ static PF res_readreply; #define RDLENGTH_SIZE (size_t)2 #define ANSWER_FIXED_SIZE (TYPE_SIZE + CLASS_SIZE + TTL_SIZE + RDLENGTH_SIZE) -struct reslist -{ - rb_dlink_node node; - int id; - time_t ttl; - char type; - char queryname[IRCD_RES_HOSTLEN + 1]; /* name currently being queried */ - char retries; /* retry counter */ - char sends; /* number of sends (>1 means resent) */ - time_t sentat; - time_t timeout; - unsigned int lastns; /* index of last server sent to */ - struct rb_sockaddr_storage addr; - char *name; - struct DNSQuery *query; /* query callback for this request */ +struct reslist { + rb_dlink_node node; + int id; + time_t ttl; + char type; + char queryname[IRCD_RES_HOSTLEN + 1]; /* name currently being queried */ + char retries; /* retry counter */ + char sends; /* number of sends (>1 means resent) */ + time_t sentat; + time_t timeout; + unsigned int lastns; /* index of last server sent to */ + struct rb_sockaddr_storage addr; + char *name; + struct DNSQuery *query; /* query callback for this request */ }; static rb_fde_t *res_fd; @@ -79,7 +78,7 @@ static void rem_request(struct reslist *request); static struct reslist *make_request(struct DNSQuery *query); static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, int); static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *, - struct reslist *request); + struct reslist *request); static void query_name(struct reslist *request); static int send_res_msg(const char *buf, int len, int count); static void resend_query(struct reslist *request); @@ -102,99 +101,89 @@ static struct DNSReply *make_dnsreply(struct reslist *request); static int res_ourserver(const struct rb_sockaddr_storage *inp) { #ifdef RB_IPV6 - const struct sockaddr_in6 *v6; - const struct sockaddr_in6 *v6in = (const struct sockaddr_in6 *)inp; + const struct sockaddr_in6 *v6; + const struct sockaddr_in6 *v6in = (const struct sockaddr_in6 *)inp; #endif - const struct sockaddr_in *v4; - const struct sockaddr_in *v4in = (const struct sockaddr_in *)inp; - int ns; + const struct sockaddr_in *v4; + const struct sockaddr_in *v4in = (const struct sockaddr_in *)inp; + int ns; - for (ns = 0; ns < irc_nscount; ns++) - { - const struct rb_sockaddr_storage *srv = &irc_nsaddr_list[ns]; + for (ns = 0; ns < irc_nscount; ns++) { + const struct rb_sockaddr_storage *srv = &irc_nsaddr_list[ns]; #ifdef RB_IPV6 - v6 = (const struct sockaddr_in6 *)srv; + v6 = (const struct sockaddr_in6 *)srv; #endif - v4 = (const struct sockaddr_in *)srv; + v4 = (const struct sockaddr_in *)srv; - /* could probably just memcmp(srv, inp, srv.ss_len) here - * but we'll air on the side of caution - stu - */ - switch (srv->ss_family) - { + /* could probably just memcmp(srv, inp, srv.ss_len) here + * but we'll air on the side of caution - stu + */ + switch (srv->ss_family) { #ifdef RB_IPV6 - case AF_INET6: - if (srv->ss_family == inp->ss_family) - if (v6->sin6_port == v6in->sin6_port) - if ((memcmp(&v6->sin6_addr.s6_addr, &v6in->sin6_addr.s6_addr, - sizeof(struct in6_addr)) == 0) || - (memcmp(&v6->sin6_addr.s6_addr, &in6addr_any, - sizeof(struct in6_addr)) == 0)) - { - ns_timeout_count[ns] = 0; - return 1; - } - break; + case AF_INET6: + if (srv->ss_family == inp->ss_family) + if (v6->sin6_port == v6in->sin6_port) + if ((memcmp(&v6->sin6_addr.s6_addr, &v6in->sin6_addr.s6_addr, + sizeof(struct in6_addr)) == 0) || + (memcmp(&v6->sin6_addr.s6_addr, &in6addr_any, + sizeof(struct in6_addr)) == 0)) { + ns_timeout_count[ns] = 0; + return 1; + } + break; #endif - case AF_INET: - if (srv->ss_family == inp->ss_family) - if (v4->sin_port == v4in->sin_port) - if ((v4->sin_addr.s_addr == INADDR_ANY) - || (v4->sin_addr.s_addr == v4in->sin_addr.s_addr)) - { - ns_timeout_count[ns] = 0; - return 1; - } - break; - default: - break; - } - } + case AF_INET: + if (srv->ss_family == inp->ss_family) + if (v4->sin_port == v4in->sin_port) + if ((v4->sin_addr.s_addr == INADDR_ANY) + || (v4->sin_addr.s_addr == v4in->sin_addr.s_addr)) { + ns_timeout_count[ns] = 0; + return 1; + } + break; + default: + break; + } + } - return 0; + return 0; } /* - * timeout_query_list - Remove queries from the list which have been + * timeout_query_list - Remove queries from the list which have been * there too long without being resolved. */ static time_t timeout_query_list(time_t now) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct reslist *request; - time_t next_time = 0; - time_t timeout = 0; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct reslist *request; + time_t next_time = 0; + time_t timeout = 0; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head) - { - request = ptr->data; - timeout = request->sentat + request->timeout; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head) { + request = ptr->data; + timeout = request->sentat + request->timeout; - if (now >= timeout) - { - if (--request->retries <= 0) - { - (*request->query->callback) (request->query->ptr, NULL); - rem_request(request); - continue; - } - else - { - ns_timeout_count[request->lastns]++; - request->sentat = now; - request->timeout += request->timeout; - resend_query(request); - } - } + if (now >= timeout) { + if (--request->retries <= 0) { + (*request->query->callback) (request->query->ptr, NULL); + rem_request(request); + continue; + } else { + ns_timeout_count[request->lastns]++; + request->sentat = now; + request->timeout += request->timeout; + resend_query(request); + } + } - if ((next_time == 0) || timeout < next_time) - { - next_time = timeout; - } - } + if ((next_time == 0) || timeout < next_time) { + next_time = timeout; + } + } - return (next_time > now) ? next_time : (now + AR_TTL); + return (next_time > now) ? next_time : (now + AR_TTL); } /* @@ -202,7 +191,7 @@ static time_t timeout_query_list(time_t now) */ static void timeout_resolver(void *notused) { - timeout_query_list(rb_current_time()); + timeout_query_list(rb_current_time()); } static struct ev_entry *timeout_resolver_ev = NULL; @@ -213,22 +202,21 @@ static struct ev_entry *timeout_resolver_ev = NULL; */ static void start_resolver(void) { - int i; + int i; - irc_res_init(); - for (i = 0; i < irc_nscount; i++) - ns_timeout_count[i] = 0; + irc_res_init(); + for (i = 0; i < irc_nscount; i++) + ns_timeout_count[i] = 0; - if (res_fd == NULL) - { - if ((res_fd = rb_socket(irc_nsaddr_list[0].ss_family, SOCK_DGRAM, 0, - "UDP resolver socket")) == NULL) - return; + if (res_fd == NULL) { + if ((res_fd = rb_socket(irc_nsaddr_list[0].ss_family, SOCK_DGRAM, 0, + "UDP resolver socket")) == NULL) + return; - /* At the moment, the resolver FD data is global .. */ - rb_setselect(res_fd, RB_SELECT_READ, res_readreply, NULL); - timeout_resolver_ev = rb_event_add("timeout_resolver", timeout_resolver, NULL, 1); - } + /* At the moment, the resolver FD data is global .. */ + rb_setselect(res_fd, RB_SELECT_READ, res_readreply, NULL); + timeout_resolver_ev = rb_event_add("timeout_resolver", timeout_resolver, NULL, 1); + } } /* @@ -237,9 +225,9 @@ static void start_resolver(void) void init_resolver(void) { #ifdef HAVE_SRAND48 - srand48(rb_current_time()); + srand48(rb_current_time()); #endif - start_resolver(); + start_resolver(); } /* @@ -247,10 +235,10 @@ void init_resolver(void) */ void restart_resolver(void) { - rb_close(res_fd); - res_fd = NULL; - rb_event_delete(timeout_resolver_ev); /* -ddosen */ - start_resolver(); + rb_close(res_fd); + res_fd = NULL; + rb_event_delete(timeout_resolver_ev); /* -ddosen */ + start_resolver(); } /* @@ -259,32 +247,29 @@ void restart_resolver(void) */ void add_local_domain(char *hname, size_t size) { - /* try to fix up unqualified names */ - if (strchr(hname, '.') == NULL) - { - if (irc_domain[0]) - { - size_t len = strlen(hname); + /* try to fix up unqualified names */ + if (strchr(hname, '.') == NULL) { + if (irc_domain[0]) { + size_t len = strlen(hname); - if ((strlen(irc_domain) + len + 2) < size) - { - hname[len++] = '.'; - strcpy(hname + len, irc_domain); - } - } - } + if ((strlen(irc_domain) + len + 2) < size) { + hname[len++] = '.'; + strcpy(hname + len, irc_domain); + } + } + } } /* - * rem_request - remove a request from the list. - * This must also free any memory that has been allocated for + * rem_request - remove a request from the list. + * This must also free any memory that has been allocated for * temporary storage of DNS results. */ static void rem_request(struct reslist *request) { - rb_dlinkDelete(&request->node, &request_list); - rb_free(request->name); - rb_free(request); + rb_dlinkDelete(&request->node, &request_list); + rb_free(request->name); + rb_free(request); } /* @@ -292,36 +277,34 @@ static void rem_request(struct reslist *request) */ static struct reslist *make_request(struct DNSQuery *query) { - struct reslist *request = rb_malloc(sizeof(struct reslist)); + struct reslist *request = rb_malloc(sizeof(struct reslist)); - request->sentat = rb_current_time(); - request->retries = 3; - request->timeout = 4; /* start at 4 and exponential inc. */ - request->query = query; + request->sentat = rb_current_time(); + request->retries = 3; + request->timeout = 4; /* start at 4 and exponential inc. */ + request->query = query; - rb_dlinkAdd(request, &request->node, &request_list); + rb_dlinkAdd(request, &request->node, &request_list); - return request; + return request; } /* - * delete_resolver_queries - cleanup outstanding queries + * delete_resolver_queries - cleanup outstanding queries * for which there no longer exist clients or conf lines. */ void delete_resolver_queries(const struct DNSQuery *query) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct reslist *request; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct reslist *request; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head) - { - if ((request = ptr->data) != NULL) - { - if (query == request->query) - rem_request(request); - } - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head) { + if ((request = ptr->data) != NULL) { + if (query == request->query) + rem_request(request); + } + } } /* @@ -330,62 +313,59 @@ void delete_resolver_queries(const struct DNSQuery *query) */ static int retryfreq(int timeouts) { - switch (timeouts) - { - case 1: - return 3; - case 2: - return 9; - case 3: - return 27; - case 4: - return 81; - default: - return 243; - } + switch (timeouts) { + case 1: + return 3; + case 2: + return 9; + case 3: + return 27; + case 4: + return 81; + default: + return 243; + } } /* * send_res_msg - sends msg to a nameserver. * This should reflect /etc/resolv.conf. - * Returns number of nameserver successfully sent to + * Returns number of nameserver successfully sent to * or -1 if no successful sends. */ static int send_res_msg(const char *msg, int len, int rcount) { - int i; - int ns; - static int retrycnt; + int i; + int ns; + static int retrycnt; - retrycnt++; - /* First try a nameserver that seems to work. - * Every once in a while, try a possibly broken one to check - * if it is working again. - */ - for (i = 0; i < irc_nscount; i++) - { - ns = (i + rcount - 1) % irc_nscount; - if (ns_timeout_count[ns] && retrycnt % retryfreq(ns_timeout_count[ns])) - continue; - if (sendto(rb_get_fd(res_fd), msg, len, 0, - (struct sockaddr *)&(irc_nsaddr_list[ns]), - GET_SS_LEN(&irc_nsaddr_list[ns])) == len) - return ns; - } + retrycnt++; + /* First try a nameserver that seems to work. + * Every once in a while, try a possibly broken one to check + * if it is working again. + */ + for (i = 0; i < irc_nscount; i++) { + ns = (i + rcount - 1) % irc_nscount; + if (ns_timeout_count[ns] && retrycnt % retryfreq(ns_timeout_count[ns])) + continue; + if (sendto(rb_get_fd(res_fd), msg, len, 0, + (struct sockaddr *)&(irc_nsaddr_list[ns]), + GET_SS_LEN(&irc_nsaddr_list[ns])) == len) + return ns; + } - /* No known working nameservers, try some broken one. */ - for (i = 0; i < irc_nscount; i++) - { - ns = (i + rcount - 1) % irc_nscount; - if (!ns_timeout_count[ns]) - continue; - if (sendto(rb_get_fd(res_fd), msg, len, 0, - (struct sockaddr *)&(irc_nsaddr_list[ns]), - GET_SS_LEN(&irc_nsaddr_list[ns])) == len) - return ns; - } + /* No known working nameservers, try some broken one. */ + for (i = 0; i < irc_nscount; i++) { + ns = (i + rcount - 1) % irc_nscount; + if (!ns_timeout_count[ns]) + continue; + if (sendto(rb_get_fd(res_fd), msg, len, 0, + (struct sockaddr *)&(irc_nsaddr_list[ns]), + GET_SS_LEN(&irc_nsaddr_list[ns])) == len) + return ns; + } - return -1; + return -1; } /* @@ -393,28 +373,27 @@ static int send_res_msg(const char *msg, int len, int rcount) */ static struct reslist *find_id(int id) { - rb_dlink_node *ptr; - struct reslist *request; + rb_dlink_node *ptr; + struct reslist *request; - RB_DLINK_FOREACH(ptr, request_list.head) - { - request = ptr->data; + RB_DLINK_FOREACH(ptr, request_list.head) { + request = ptr->data; - if (request->id == id) - return (request); - } + if (request->id == id) + return (request); + } - return (NULL); + return (NULL); } -/* +/* * gethost_byname_type - get host address from name * */ void gethost_byname_type(const char *name, struct DNSQuery *query, int type) { - assert(name != 0); - do_query_name(query, name, NULL, type); + assert(name != 0); + do_query_name(query, name, NULL, type); } /* @@ -422,84 +401,80 @@ void gethost_byname_type(const char *name, struct DNSQuery *query, int type) */ void gethost_byaddr(const struct rb_sockaddr_storage *addr, struct DNSQuery *query) { - do_query_number(query, addr, NULL); + do_query_number(query, addr, NULL); } /* * do_query_name - nameserver lookup name */ static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, - int type) + int type) { - char host_name[IRCD_RES_HOSTLEN + 1]; + char host_name[IRCD_RES_HOSTLEN + 1]; - rb_strlcpy(host_name, name, IRCD_RES_HOSTLEN + 1); - add_local_domain(host_name, IRCD_RES_HOSTLEN); + rb_strlcpy(host_name, name, IRCD_RES_HOSTLEN + 1); + add_local_domain(host_name, IRCD_RES_HOSTLEN); - if (request == NULL) - { - request = make_request(query); - request->name = (char *)rb_malloc(strlen(host_name) + 1); - strcpy(request->name, host_name); - } + if (request == NULL) { + request = make_request(query); + request->name = (char *)rb_malloc(strlen(host_name) + 1); + strcpy(request->name, host_name); + } - rb_strlcpy(request->queryname, host_name, sizeof(request->queryname)); - request->type = type; - query_name(request); + rb_strlcpy(request->queryname, host_name, sizeof(request->queryname)); + request->type = type; + query_name(request); } /* * do_query_number - Use this to do reverse IP# lookups. */ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *addr, - struct reslist *request) + struct reslist *request) { - const unsigned char *cp; + const unsigned char *cp; - if (request == NULL) - { - request = make_request(query); - memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage)); - request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1); - } + if (request == NULL) { + request = make_request(query); + memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage)); + request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1); + } - if (addr->ss_family == AF_INET) - { - const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr; - cp = (const unsigned char *)&v4->sin_addr.s_addr; + if (addr->ss_family == AF_INET) { + const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr; + cp = (const unsigned char *)&v4->sin_addr.s_addr; - rb_sprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]), - (unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0])); - } + rb_sprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]), + (unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0])); + } #ifdef RB_IPV6 - else if (addr->ss_family == AF_INET6) - { - const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr; - cp = (const unsigned char *)&v6->sin6_addr.s6_addr; + else if (addr->ss_family == AF_INET6) { + const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr; + cp = (const unsigned char *)&v6->sin6_addr.s6_addr; - (void)sprintf(request->queryname, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." - "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa", - (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4), - (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4), - (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4), - (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4), - (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4), - (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4), - (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4), - (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4), - (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4), - (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4), - (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4), - (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4), - (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4), - (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4), - (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4), - (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4)); - } + (void)sprintf(request->queryname, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." + "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa", + (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4), + (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4), + (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4), + (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4), + (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4), + (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4), + (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4), + (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4), + (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4), + (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4), + (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4), + (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4), + (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4), + (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4), + (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4), + (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4)); + } #endif - request->type = T_PTR; - query_name(request); + request->type = T_PTR; + query_name(request); } /* @@ -507,64 +482,60 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto */ static void query_name(struct reslist *request) { - char buf[MAXPACKET]; - int request_len = 0; - int ns; + char buf[MAXPACKET]; + int request_len = 0; + int ns; - memset(buf, 0, sizeof(buf)); + memset(buf, 0, sizeof(buf)); - if ((request_len = - irc_res_mkquery(request->queryname, C_IN, request->type, (unsigned char *)buf, sizeof(buf))) > 0) - { - HEADER *header = (HEADER *) buf; + if ((request_len = + irc_res_mkquery(request->queryname, C_IN, request->type, (unsigned char *)buf, sizeof(buf))) > 0) { + HEADER *header = (HEADER *) buf; #ifndef HAVE_LRAND48 - int k = 0; - struct timeval tv; + int k = 0; + struct timeval tv; #endif - /* - * generate an unique id - * NOTE: we don't have to worry about converting this to and from - * network byte order, the nameserver does not interpret this value - * and returns it unchanged - */ + /* + * generate an unique id + * NOTE: we don't have to worry about converting this to and from + * network byte order, the nameserver does not interpret this value + * and returns it unchanged + */ #ifdef HAVE_LRAND48 - do - { - header->id = (header->id + lrand48()) & 0xffff; - } while (find_id(header->id)); + do { + header->id = (header->id + lrand48()) & 0xffff; + } while (find_id(header->id)); #else - gettimeofday(&tv, NULL); - do - { - header->id = (header->id + k + tv.tv_usec) & 0xffff; - k++; - } while (find_id(header->id)); + gettimeofday(&tv, NULL); + do { + header->id = (header->id + k + tv.tv_usec) & 0xffff; + k++; + } while (find_id(header->id)); #endif /* HAVE_LRAND48 */ - request->id = header->id; - ++request->sends; + request->id = header->id; + ++request->sends; - ns = send_res_msg(buf, request_len, request->sends); - if (ns != -1) - request->lastns = ns; - } + ns = send_res_msg(buf, request_len, request->sends); + if (ns != -1) + request->lastns = ns; + } } static void resend_query(struct reslist *request) { - switch (request->type) - { - case T_PTR: - do_query_number(NULL, &request->addr, request); - break; - case T_A: + switch (request->type) { + case T_PTR: + do_query_number(NULL, &request->addr, request); + break; + case T_A: #ifdef RB_IPV6 - case T_AAAA: + case T_AAAA: #endif - do_query_name(NULL, request->name, request, request->type); - break; - default: - break; - } + do_query_name(NULL, request->name, request, request->type); + break; + default: + break; + } } /* @@ -574,20 +545,20 @@ static void resend_query(struct reslist *request) */ static int check_question(struct reslist *request, HEADER * header, char *buf, char *eob) { - char hostbuf[IRCD_RES_HOSTLEN + 1]; /* working buffer */ - unsigned char *current; /* current position in buf */ - int n; /* temp count */ + char hostbuf[IRCD_RES_HOSTLEN + 1]; /* working buffer */ + unsigned char *current; /* current position in buf */ + int n; /* temp count */ - current = (unsigned char *)buf + sizeof(HEADER); - if (header->qdcount != 1) - return 0; - n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current, hostbuf, - sizeof(hostbuf)); - if (n <= 0) - return 0; - if (strcasecmp(hostbuf, request->queryname)) - return 0; - return 1; + current = (unsigned char *)buf + sizeof(HEADER); + if (header->qdcount != 1) + return 0; + n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current, hostbuf, + sizeof(hostbuf)); + if (n <= 0) + return 0; + if (strcasecmp(hostbuf, request->queryname)) + return 0; + return 1; } /* @@ -595,137 +566,131 @@ static int check_question(struct reslist *request, HEADER * header, char *buf, c */ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char *eob) { - char hostbuf[IRCD_RES_HOSTLEN + 100]; /* working buffer */ - unsigned char *current; /* current position in buf */ - int query_class; /* answer class */ - int type; /* answer type */ - int n; /* temp count */ - int rd_length; - struct sockaddr_in *v4; /* conversion */ + char hostbuf[IRCD_RES_HOSTLEN + 100]; /* working buffer */ + unsigned char *current; /* current position in buf */ + int query_class; /* answer class */ + int type; /* answer type */ + int n; /* temp count */ + int rd_length; + struct sockaddr_in *v4; /* conversion */ #ifdef RB_IPV6 - struct sockaddr_in6 *v6; + struct sockaddr_in6 *v6; #endif - current = (unsigned char *)buf + sizeof(HEADER); + current = (unsigned char *)buf + sizeof(HEADER); - for (; header->qdcount > 0; --header->qdcount) - { - if ((n = irc_dn_skipname(current, (unsigned char *)eob)) < 0) - return 0; + for (; header->qdcount > 0; --header->qdcount) { + if ((n = irc_dn_skipname(current, (unsigned char *)eob)) < 0) + return 0; - current += (size_t) n + QFIXEDSZ; - } + current += (size_t) n + QFIXEDSZ; + } - /* - * process each answer sent to us blech. - */ - while (header->ancount > 0 && (char *)current < eob) - { - header->ancount--; + /* + * process each answer sent to us blech. + */ + while (header->ancount > 0 && (char *)current < eob) { + header->ancount--; - n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current, hostbuf, - sizeof(hostbuf)); + n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current, hostbuf, + sizeof(hostbuf)); - if (n < 0) - { - /* - * broken message - */ - return (0); - } - else if (n == 0) - { - /* - * no more answers left - */ - return (0); - } + if (n < 0) { + /* + * broken message + */ + return (0); + } else if (n == 0) { + /* + * no more answers left + */ + return (0); + } - hostbuf[IRCD_RES_HOSTLEN] = '\0'; + hostbuf[IRCD_RES_HOSTLEN] = '\0'; - /* With Address arithmetic you have to be very anal - * this code was not working on alpha due to that - * (spotted by rodder/jailbird/dianora) - */ - current += (size_t) n; + /* With Address arithmetic you have to be very anal + * this code was not working on alpha due to that + * (spotted by rodder/jailbird/dianora) + */ + current += (size_t) n; - if (!(((char *)current + ANSWER_FIXED_SIZE) < eob)) - break; + if (!(((char *)current + ANSWER_FIXED_SIZE) < eob)) + break; - type = irc_ns_get16(current); - current += TYPE_SIZE; + type = irc_ns_get16(current); + current += TYPE_SIZE; - query_class = irc_ns_get16(current); - current += CLASS_SIZE; + query_class = irc_ns_get16(current); + current += CLASS_SIZE; - request->ttl = irc_ns_get32(current); - current += TTL_SIZE; + request->ttl = irc_ns_get32(current); + current += TTL_SIZE; - rd_length = irc_ns_get16(current); - current += RDLENGTH_SIZE; + rd_length = irc_ns_get16(current); + current += RDLENGTH_SIZE; - /* - * Wait to set request->type until we verify this structure - */ - switch (type) - { - case T_A: - if (request->type != T_A) - return (0); + /* + * Wait to set request->type until we verify this structure + */ + switch (type) { + case T_A: + if (request->type != T_A) + return (0); - /* - * check for invalid rd_length or too many addresses - */ - if (rd_length != sizeof(struct in_addr)) - return (0); - v4 = (struct sockaddr_in *)&request->addr; - SET_SS_LEN(&request->addr, sizeof(struct sockaddr_in)); - v4->sin_family = AF_INET; - memcpy(&v4->sin_addr, current, sizeof(struct in_addr)); - return (1); - break; + /* + * check for invalid rd_length or too many addresses + */ + if (rd_length != sizeof(struct in_addr)) + return (0); + v4 = (struct sockaddr_in *)&request->addr; + SET_SS_LEN(&request->addr, sizeof(struct sockaddr_in)); + v4->sin_family = AF_INET; + memcpy(&v4->sin_addr, current, sizeof(struct in_addr)); + return (1); + break; #ifdef RB_IPV6 - case T_AAAA: - if (request->type != T_AAAA) - return (0); - if (rd_length != sizeof(struct in6_addr)) - return (0); - SET_SS_LEN(&request->addr, sizeof(struct sockaddr_in6)); - v6 = (struct sockaddr_in6 *)&request->addr; - v6->sin6_family = AF_INET6; - memcpy(&v6->sin6_addr, current, sizeof(struct in6_addr)); - return (1); - break; + case T_AAAA: + if (request->type != T_AAAA) + return (0); + if (rd_length != sizeof(struct in6_addr)) + return (0); + SET_SS_LEN(&request->addr, sizeof(struct sockaddr_in6)); + v6 = (struct sockaddr_in6 *)&request->addr; + v6->sin6_family = AF_INET6; + memcpy(&v6->sin6_addr, current, sizeof(struct in6_addr)); + return (1); + break; #endif - case T_PTR: - if (request->type != T_PTR) - return (0); - n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current, - hostbuf, sizeof(hostbuf)); - if (n < 0) - return (0); /* broken message */ - else if (n == 0) - return (0); /* no more answers left */ + case T_PTR: + if (request->type != T_PTR) + return (0); + n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current, + hostbuf, sizeof(hostbuf)); + if (n < 0) + return (0); /* broken message */ + else if (n == 0) + return (0); /* no more answers left */ - rb_strlcpy(request->name, hostbuf, IRCD_RES_HOSTLEN + 1); + rb_strlcpy(request->name, hostbuf, IRCD_RES_HOSTLEN + 1); - return (1); - break; - case T_CNAME: - /* real answer will follow */ - current += rd_length; - break; + return (1); + break; + case T_CNAME: + /* real answer will follow */ + current += rd_length; + break; - default: - /* XXX I'd rather just throw away the entire bogus thing - * but its possible its just a broken nameserver with still - * valid answers. But lets do some rudimentary logging for now... - */ - ilog(L_MAIN, "irc_res.c bogus type %d", type); - break; - } - } + default: + /* XXX I'd rather just throw away the entire bogus thing + * but its possible its just a broken nameserver with still + * valid answers. But lets do some rudimentary logging for now... + */ + ilog(L_MAIN, "irc_res.c bogus type %d", type); + break; + } + } - return (1); + return (1); } /* @@ -734,160 +699,148 @@ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char */ static int res_read_single_reply(rb_fde_t *F, void *data) { - char buf[sizeof(HEADER) + MAXPACKET] - /* Sparc and alpha need 16bit-alignment for accessing header->id - * (which is uint16_t). Because of the header = (HEADER*) buf; - * lateron, this is neeeded. --FaUl - */ + char buf[sizeof(HEADER) + MAXPACKET] + /* Sparc and alpha need 16bit-alignment for accessing header->id + * (which is uint16_t). Because of the header = (HEADER*) buf; + * lateron, this is neeeded. --FaUl + */ #if defined(__sparc__) || defined(__alpha__) - __attribute__ ((aligned(16))) + __attribute__ ((aligned(16))) #endif - ; - HEADER *header; - struct reslist *request = NULL; - struct DNSReply *reply = NULL; - int rc; - int answer_count; - socklen_t len = sizeof(struct rb_sockaddr_storage); - struct rb_sockaddr_storage lsin; + ; + HEADER *header; + struct reslist *request = NULL; + struct DNSReply *reply = NULL; + int rc; + int answer_count; + socklen_t len = sizeof(struct rb_sockaddr_storage); + struct rb_sockaddr_storage lsin; - rc = recvfrom(rb_get_fd(F), buf, sizeof(buf), 0, (struct sockaddr *)&lsin, &len); + rc = recvfrom(rb_get_fd(F), buf, sizeof(buf), 0, (struct sockaddr *)&lsin, &len); - /* No packet */ - if (rc == 0 || rc == -1) - return 0; + /* No packet */ + if (rc == 0 || rc == -1) + return 0; - /* Too small */ - if (rc <= (int)(sizeof(HEADER))) - return 1; + /* Too small */ + if (rc <= (int)(sizeof(HEADER))) + return 1; - /* - * convert DNS reply reader from Network byte order to CPU byte order. - */ - header = (HEADER *) buf; - header->ancount = ntohs(header->ancount); - header->qdcount = ntohs(header->qdcount); - header->nscount = ntohs(header->nscount); - header->arcount = ntohs(header->arcount); + /* + * convert DNS reply reader from Network byte order to CPU byte order. + */ + header = (HEADER *) buf; + header->ancount = ntohs(header->ancount); + header->qdcount = ntohs(header->qdcount); + header->nscount = ntohs(header->nscount); + header->arcount = ntohs(header->arcount); - /* - * response for an id which we have already received an answer for - * just ignore this response. - */ - if (0 == (request = find_id(header->id))) - return 1; + /* + * response for an id which we have already received an answer for + * just ignore this response. + */ + if (0 == (request = find_id(header->id))) + return 1; - /* - * check against possibly fake replies - */ - if (!res_ourserver(&lsin)) - return 1; + /* + * check against possibly fake replies + */ + if (!res_ourserver(&lsin)) + return 1; - if (!check_question(request, header, buf, buf + rc)) - return 1; + if (!check_question(request, header, buf, buf + rc)) + return 1; - if ((header->rcode != NO_ERRORS) || (header->ancount == 0)) - { - if (NXDOMAIN == header->rcode) - { - (*request->query->callback) (request->query->ptr, NULL); - rem_request(request); - } - else - { - /* - * If a bad error was returned, we stop here and dont send - * send any more (no retries granted). - */ - (*request->query->callback) (request->query->ptr, NULL); - rem_request(request); - } - return 1; - } - /* - * If this fails there was an error decoding the received packet, - * give up. -- jilles - */ - answer_count = proc_answer(request, header, buf, buf + rc); + if ((header->rcode != NO_ERRORS) || (header->ancount == 0)) { + if (NXDOMAIN == header->rcode) { + (*request->query->callback) (request->query->ptr, NULL); + rem_request(request); + } else { + /* + * If a bad error was returned, we stop here and dont send + * send any more (no retries granted). + */ + (*request->query->callback) (request->query->ptr, NULL); + rem_request(request); + } + return 1; + } + /* + * If this fails there was an error decoding the received packet, + * give up. -- jilles + */ + answer_count = proc_answer(request, header, buf, buf + rc); - if (answer_count) - { - if (request->type == T_PTR) - { - if (request->name == NULL) - { - /* - * got a PTR response with no name, something bogus is happening - * don't bother trying again, the client address doesn't resolve - */ - (*request->query->callback) (request->query->ptr, reply); - rem_request(request); - return 1; - } + if (answer_count) { + if (request->type == T_PTR) { + if (request->name == NULL) { + /* + * got a PTR response with no name, something bogus is happening + * don't bother trying again, the client address doesn't resolve + */ + (*request->query->callback) (request->query->ptr, reply); + rem_request(request); + return 1; + } - /* - * Lookup the 'authoritative' name that we were given for the - * ip#. - * - */ + /* + * Lookup the 'authoritative' name that we were given for the + * ip#. + * + */ #ifdef RB_IPV6 - if (request->addr.ss_family == AF_INET6) - gethost_byname_type(request->name, request->query, T_AAAA); - else + if (request->addr.ss_family == AF_INET6) + gethost_byname_type(request->name, request->query, T_AAAA); + else #endif - gethost_byname_type(request->name, request->query, T_A); - rem_request(request); - } - else - { - /* - * got a name and address response, client resolved - */ - reply = make_dnsreply(request); - (*request->query->callback) (request->query->ptr, reply); - rb_free(reply); - rem_request(request); - } - } - else - { - /* couldn't decode, give up -- jilles */ - (*request->query->callback) (request->query->ptr, NULL); - rem_request(request); - } - return 1; + gethost_byname_type(request->name, request->query, T_A); + rem_request(request); + } else { + /* + * got a name and address response, client resolved + */ + reply = make_dnsreply(request); + (*request->query->callback) (request->query->ptr, reply); + rb_free(reply); + rem_request(request); + } + } else { + /* couldn't decode, give up -- jilles */ + (*request->query->callback) (request->query->ptr, NULL); + rem_request(request); + } + return 1; } static void res_readreply(rb_fde_t *F, void *data) { - while (res_read_single_reply(F, data)) - ; - rb_setselect(F, RB_SELECT_READ, res_readreply, NULL); + while (res_read_single_reply(F, data)) + ; + rb_setselect(F, RB_SELECT_READ, res_readreply, NULL); } static struct DNSReply *make_dnsreply(struct reslist *request) { - struct DNSReply *cp; - s_assert(request != 0); + struct DNSReply *cp; + s_assert(request != 0); - cp = (struct DNSReply *)rb_malloc(sizeof(struct DNSReply)); + cp = (struct DNSReply *)rb_malloc(sizeof(struct DNSReply)); - cp->h_name = request->name; - memcpy(&cp->addr, &request->addr, sizeof(cp->addr)); - return (cp); + cp->h_name = request->name; + memcpy(&cp->addr, &request->addr, sizeof(cp->addr)); + return (cp); } void report_dns_servers(struct Client *source_p) { - int i; - char ipaddr[128]; + int i; + char ipaddr[128]; - for (i = 0; i < irc_nscount; i++) - { - if (!rb_inet_ntop_sock((struct sockaddr *)&(irc_nsaddr_list[i]), - ipaddr, sizeof ipaddr)) - rb_strlcpy(ipaddr, "?", sizeof ipaddr); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "A %s %d", ipaddr, ns_timeout_count[i]); - } + for (i = 0; i < irc_nscount; i++) { + if (!rb_inet_ntop_sock((struct sockaddr *)&(irc_nsaddr_list[i]), + ipaddr, sizeof ipaddr)) + rb_strlcpy(ipaddr, "?", sizeof ipaddr); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "A %s %d", ipaddr, ns_timeout_count[i]); + } } diff --git a/src/reslib.c b/src/reslib.c index 25cabe4..43e48b1 100644 --- a/src/reslib.c +++ b/src/reslib.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -17,7 +17,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -33,14 +33,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -68,7 +68,7 @@ * SOFTWARE. */ -/* Original copyright ISC as above. +/* Original copyright ISC as above. * Code modified specifically for ircd use from the following orginal files * in bind ... * @@ -76,7 +76,7 @@ * ns_name.c * ns_netint.c * res_init.c - * + * * - Dianora */ @@ -98,22 +98,22 @@ int irc_nscount = 0; char irc_domain[IRCD_RES_HOSTLEN + 1]; static const char digitvalue[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/ - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/ }; static int parse_resvconf(void); @@ -125,10 +125,10 @@ static int special(int ch); static int printable(int ch); static int irc_decode_bitstring(const char **cpp, char *dn, const char *eom); static int irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz, - const unsigned char **dnptrs, const unsigned char **lastdnptr); + const unsigned char **dnptrs, const unsigned char **lastdnptr); static int irc_dn_find(const unsigned char *, const unsigned char *, const unsigned char * const *, const unsigned char * const *); -static int irc_encode_bitsring(const char **, const char *, unsigned char **, unsigned char **, +static int irc_encode_bitsring(const char **, const char *, unsigned char **, unsigned char **, const char *); static int irc_ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t); @@ -138,15 +138,15 @@ static int irc_ns_name_unpack(const unsigned char *, const unsigned char *, static int irc_ns_name_ntop(const char *, char *, size_t); static int irc_ns_name_skip(const unsigned char **, const unsigned char *); static int mklower(int ch); - + int irc_res_init(void) { - irc_nscount = 0; - parse_resvconf(); - if (irc_nscount == 0) - add_nameserver("127.0.0.1"); - return 0; + irc_nscount = 0; + parse_resvconf(); + if (irc_nscount == 0) + add_nameserver("127.0.0.1"); + return 0; } /* parse_resvconf() @@ -158,61 +158,60 @@ irc_res_init(void) static int parse_resvconf(void) { - char *p; - char *opt; - char *arg; - char input[DNS_MAXLINE]; - FILE *file; + char *p; + char *opt; + char *arg; + char input[DNS_MAXLINE]; + FILE *file; - /* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps - * for cygwin support etc. this hardcodes it to unix for now -db - */ - if ((file = fopen("/etc/resolv.conf", "r")) == NULL) - return -1; + /* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps + * for cygwin support etc. this hardcodes it to unix for now -db + */ + if ((file = fopen("/etc/resolv.conf", "r")) == NULL) + return -1; - while (fgets(input, sizeof(input), file) != NULL) - { - /* blow away any newline */ - if ((p = strpbrk(input, "\r\n")) != NULL) - *p = '\0'; + while (fgets(input, sizeof(input), file) != NULL) { + /* blow away any newline */ + if ((p = strpbrk(input, "\r\n")) != NULL) + *p = '\0'; - p = input; - /* skip until something thats not a space is seen */ - while (IsSpace(*p)) - p++; - /* if at this point, have a '\0' then continue */ - if (*p == '\0') - continue; + p = input; + /* skip until something thats not a space is seen */ + while (IsSpace(*p)) + p++; + /* if at this point, have a '\0' then continue */ + if (*p == '\0') + continue; - /* Ignore comment lines immediately */ - if (*p == '#' || *p == ';') - continue; + /* Ignore comment lines immediately */ + if (*p == '#' || *p == ';') + continue; - /* skip until a space is found */ - opt = p; - while (!IsSpace(*p) && *p != '\0') - p++; - if (*p == '\0') - continue; /* no arguments?.. ignore this line */ - /* blow away the space character */ - *p++ = '\0'; + /* skip until a space is found */ + opt = p; + while (!IsSpace(*p) && *p != '\0') + p++; + if (*p == '\0') + continue; /* no arguments?.. ignore this line */ + /* blow away the space character */ + *p++ = '\0'; - /* skip these spaces that are before the argument */ - while (IsSpace(*p)) - p++; - /* Now arg should be right where p is pointing */ - arg = p; - if ((p = strpbrk(arg, " \t")) != NULL) - *p = '\0'; /* take the first word */ + /* skip these spaces that are before the argument */ + while (IsSpace(*p)) + p++; + /* Now arg should be right where p is pointing */ + arg = p; + if ((p = strpbrk(arg, " \t")) != NULL) + *p = '\0'; /* take the first word */ - if (irccmp(opt, "domain") == 0) - rb_strlcpy(irc_domain, arg, sizeof(irc_domain)); - else if (irccmp(opt, "nameserver") == 0) - add_nameserver(arg); - } + if (irccmp(opt, "domain") == 0) + rb_strlcpy(irc_domain, arg, sizeof(irc_domain)); + else if (irccmp(opt, "nameserver") == 0) + add_nameserver(arg); + } - fclose(file); - return 0; + fclose(file); + return 0; } /* add_nameserver() @@ -225,30 +224,29 @@ parse_resvconf(void) static void add_nameserver(const char *arg) { - struct addrinfo hints, *res; + struct addrinfo hints, *res; - /* Done max number of nameservers? */ - if (irc_nscount >= IRCD_MAXNS) - { - ilog (L_MAIN, "Too many nameservers, ignoring %s", arg); - return; - } + /* Done max number of nameservers? */ + if (irc_nscount >= IRCD_MAXNS) { + ilog (L_MAIN, "Too many nameservers, ignoring %s", arg); + return; + } - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - if (getaddrinfo(arg, "domain", &hints, &res)) - return; + if (getaddrinfo(arg, "domain", &hints, &res)) + return; - if (res == NULL) - return; + if (res == NULL) + return; - memcpy(&irc_nsaddr_list[irc_nscount], res->ai_addr, res->ai_addrlen); - SET_SS_LEN(&irc_nsaddr_list[irc_nscount], res->ai_addrlen); - irc_nscount++; - freeaddrinfo(res); + memcpy(&irc_nsaddr_list[irc_nscount], res->ai_addr, res->ai_addrlen); + SET_SS_LEN(&irc_nsaddr_list[irc_nscount], res->ai_addrlen); + irc_nscount++; + freeaddrinfo(res); } /* @@ -262,11 +260,11 @@ int irc_dn_expand(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, char *dst, int dstsiz) { - int n = irc_ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz); + int n = irc_ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz); - if (n > 0 && dst[0] == '.') - dst[0] = '\0'; - return(n); + if (n > 0 && dst[0] == '.') + dst[0] = '\0'; + return(n); } /* @@ -281,14 +279,14 @@ static int irc_ns_name_uncompress(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, char *dst, size_t dstsiz) { - unsigned char tmp[NS_MAXCDNAME]; - int n; + unsigned char tmp[NS_MAXCDNAME]; + int n; - if ((n = irc_ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1) - return(-1); - if (irc_ns_name_ntop((char*)tmp, dst, dstsiz) == -1) - return(-1); - return(n); + if ((n = irc_ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1) + return(-1); + if (irc_ns_name_ntop((char*)tmp, dst, dstsiz) == -1) + return(-1); + return(n); } /* * irc_ns_name_unpack(msg, eom, src, dst, dstsiz) @@ -301,74 +299,74 @@ irc_ns_name_unpack(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, unsigned char *dst, size_t dstsiz) { - const unsigned char *srcp, *dstlim; - unsigned char *dstp; - int n, len, checked, l; + const unsigned char *srcp, *dstlim; + unsigned char *dstp; + int n, len, checked, l; - len = -1; - checked = 0; - dstp = dst; - srcp = src; - dstlim = dst + dstsiz; - if (srcp < msg || srcp >= eom) { - errno = EMSGSIZE; - return (-1); - } - /* Fetch next label in domain name. */ - while ((n = *srcp++) != 0) { - /* Check for indirection. */ - switch (n & NS_CMPRSFLGS) { - case 0: - case NS_TYPE_ELT: - /* Limit checks. */ - if ((l = labellen(srcp - 1)) < 0) { - errno = EMSGSIZE; - return(-1); - } - if (dstp + l + 1 >= dstlim || srcp + l >= eom) { - errno = EMSGSIZE; - return (-1); - } - checked += l + 1; - *dstp++ = n; - memcpy(dstp, srcp, l); - dstp += l; - srcp += l; - break; + len = -1; + checked = 0; + dstp = dst; + srcp = src; + dstlim = dst + dstsiz; + if (srcp < msg || srcp >= eom) { + errno = EMSGSIZE; + return (-1); + } + /* Fetch next label in domain name. */ + while ((n = *srcp++) != 0) { + /* Check for indirection. */ + switch (n & NS_CMPRSFLGS) { + case 0: + case NS_TYPE_ELT: + /* Limit checks. */ + if ((l = labellen(srcp - 1)) < 0) { + errno = EMSGSIZE; + return(-1); + } + if (dstp + l + 1 >= dstlim || srcp + l >= eom) { + errno = EMSGSIZE; + return (-1); + } + checked += l + 1; + *dstp++ = n; + memcpy(dstp, srcp, l); + dstp += l; + srcp += l; + break; - case NS_CMPRSFLGS: - if (srcp >= eom) { - errno = EMSGSIZE; - return (-1); - } - if (len < 0) - len = srcp - src + 1; - srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); - if (srcp < msg || srcp >= eom) { /* Out of range. */ - errno = EMSGSIZE; - return (-1); - } - checked += 2; - /* - * Check for loops in the compressed name; - * if we've looked at the whole message, - * there must be a loop. - */ - if (checked >= eom - msg) { - errno = EMSGSIZE; - return (-1); - } - break; + case NS_CMPRSFLGS: + if (srcp >= eom) { + errno = EMSGSIZE; + return (-1); + } + if (len < 0) + len = srcp - src + 1; + srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); + if (srcp < msg || srcp >= eom) { /* Out of range. */ + errno = EMSGSIZE; + return (-1); + } + checked += 2; + /* + * Check for loops in the compressed name; + * if we've looked at the whole message, + * there must be a loop. + */ + if (checked >= eom - msg) { + errno = EMSGSIZE; + return (-1); + } + break; - default: - errno = EMSGSIZE; - return (-1); /* flag error */ - } - } - *dstp = '\0'; - if (len < 0) - len = srcp - src; - return (len); + default: + errno = EMSGSIZE; + return (-1); /* flag error */ + } + } + *dstp = '\0'; + if (len < 0) + len = srcp - src; + return (len); } /* @@ -383,93 +381,92 @@ irc_ns_name_unpack(const unsigned char *msg, const unsigned char *eom, static int irc_ns_name_ntop(const char *src, char *dst, size_t dstsiz) { - const char *cp; - char *dn, *eom; - unsigned char c; - unsigned int n; - int l; + const char *cp; + char *dn, *eom; + unsigned char c; + unsigned int n; + int l; - cp = src; - dn = dst; - eom = dst + dstsiz; + cp = src; + dn = dst; + eom = dst + dstsiz; - while ((n = *cp++) != 0) { - if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { - /* Some kind of compression pointer. */ - errno = EMSGSIZE; - return (-1); - } - if (dn != dst) { - if (dn >= eom) { - errno = EMSGSIZE; - return (-1); - } - *dn++ = '.'; - } - if ((l = labellen((const unsigned char*)(cp - 1))) < 0) { - errno = EMSGSIZE; /* XXX */ - return(-1); - } - if (dn + l >= eom) { - errno = EMSGSIZE; - return (-1); - } - if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) { - int m; + while ((n = *cp++) != 0) { + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + /* Some kind of compression pointer. */ + errno = EMSGSIZE; + return (-1); + } + if (dn != dst) { + if (dn >= eom) { + errno = EMSGSIZE; + return (-1); + } + *dn++ = '.'; + } + if ((l = labellen((const unsigned char*)(cp - 1))) < 0) { + errno = EMSGSIZE; /* XXX */ + return(-1); + } + if (dn + l >= eom) { + errno = EMSGSIZE; + return (-1); + } + if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) { + int m; - if (n != DNS_LABELTYPE_BITSTRING) { - /* XXX: labellen should reject this case */ - errno = EINVAL; - return(-1); - } - if ((m = irc_decode_bitstring(&cp, dn, eom)) < 0) - { - errno = EMSGSIZE; - return(-1); - } - dn += m; - continue; - } - for ((void)NULL; l > 0; l--) { - c = *cp++; - if (special(c)) { - if (dn + 1 >= eom) { - errno = EMSGSIZE; - return (-1); - } - *dn++ = '\\'; - *dn++ = (char)c; - } else if (!printable(c)) { - if (dn + 3 >= eom) { - errno = EMSGSIZE; - return (-1); - } - *dn++ = '\\'; - *dn++ = digits[c / 100]; - *dn++ = digits[(c % 100) / 10]; - *dn++ = digits[c % 10]; - } else { - if (dn >= eom) { - errno = EMSGSIZE; - return (-1); - } - *dn++ = (char)c; - } - } - } - if (dn == dst) { - if (dn >= eom) { - errno = EMSGSIZE; - return (-1); - } - *dn++ = '.'; - } - if (dn >= eom) { - errno = EMSGSIZE; - return (-1); - } - *dn++ = '\0'; - return (dn - dst); + if (n != DNS_LABELTYPE_BITSTRING) { + /* XXX: labellen should reject this case */ + errno = EINVAL; + return(-1); + } + if ((m = irc_decode_bitstring(&cp, dn, eom)) < 0) { + errno = EMSGSIZE; + return(-1); + } + dn += m; + continue; + } + for ((void)NULL; l > 0; l--) { + c = *cp++; + if (special(c)) { + if (dn + 1 >= eom) { + errno = EMSGSIZE; + return (-1); + } + *dn++ = '\\'; + *dn++ = (char)c; + } else if (!printable(c)) { + if (dn + 3 >= eom) { + errno = EMSGSIZE; + return (-1); + } + *dn++ = '\\'; + *dn++ = digits[c / 100]; + *dn++ = digits[(c % 100) / 10]; + *dn++ = digits[c % 10]; + } else { + if (dn >= eom) { + errno = EMSGSIZE; + return (-1); + } + *dn++ = (char)c; + } + } + } + if (dn == dst) { + if (dn >= eom) { + errno = EMSGSIZE; + return (-1); + } + *dn++ = '.'; + } + if (dn >= eom) { + errno = EMSGSIZE; + return (-1); + } + *dn++ = '\0'; + return (dn - dst); } /* @@ -481,21 +478,22 @@ static int irc_dn_comp(const char *src, unsigned char *dst, int dstsiz, unsigned char **dnptrs, unsigned char **lastdnptr) { - return(irc_ns_name_compress(src, dst, (size_t)dstsiz, - (const unsigned char **)dnptrs, - (const unsigned char **)lastdnptr)); + return(irc_ns_name_compress(src, dst, (size_t)dstsiz, + (const unsigned char **)dnptrs, + (const unsigned char **)lastdnptr)); } /* * Skip over a compressed domain name. Return the size or -1. */ int -irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom) { - const unsigned char *saveptr = ptr; +irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom) +{ + const unsigned char *saveptr = ptr; - if (irc_ns_name_skip(&ptr, eom) == -1) - return(-1); - return(ptr - saveptr); + if (irc_ns_name_skip(&ptr, eom) == -1) + return(-1); + return(ptr - saveptr); } /* @@ -507,78 +505,74 @@ irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom) { static int irc_ns_name_skip(const unsigned char **ptrptr, const unsigned char *eom) { - const unsigned char *cp; - unsigned int n; - int l; + const unsigned char *cp; + unsigned int n; + int l; - cp = *ptrptr; + cp = *ptrptr; - while (cp < eom && (n = *cp++) != 0) - { - /* Check for indirection. */ - switch (n & NS_CMPRSFLGS) - { - case 0: /* normal case, n == len */ - cp += n; - continue; - case NS_TYPE_ELT: /* EDNS0 extended label */ - if ((l = labellen(cp - 1)) < 0) - { - errno = EMSGSIZE; /* XXX */ - return(-1); + while (cp < eom && (n = *cp++) != 0) { + /* Check for indirection. */ + switch (n & NS_CMPRSFLGS) { + case 0: /* normal case, n == len */ + cp += n; + continue; + case NS_TYPE_ELT: /* EDNS0 extended label */ + if ((l = labellen(cp - 1)) < 0) { + errno = EMSGSIZE; /* XXX */ + return(-1); + } + + cp += l; + continue; + case NS_CMPRSFLGS: /* indirection */ + cp++; + break; + default: /* illegal type */ + errno = EMSGSIZE; + return(-1); } - cp += l; - continue; - case NS_CMPRSFLGS: /* indirection */ - cp++; break; - default: /* illegal type */ - errno = EMSGSIZE; - return(-1); } - break; - } + if (cp > eom) { + errno = EMSGSIZE; + return (-1); + } - if (cp > eom) - { - errno = EMSGSIZE; - return (-1); - } - - *ptrptr = cp; - return(0); + *ptrptr = cp; + return(0); } unsigned int irc_ns_get16(const unsigned char *src) { - unsigned int dst; + unsigned int dst; - IRC_NS_GET16(dst, src); - return(dst); + IRC_NS_GET16(dst, src); + return(dst); } unsigned long irc_ns_get32(const unsigned char *src) { - unsigned long dst; + unsigned long dst; - IRC_NS_GET32(dst, src); - return(dst); + IRC_NS_GET32(dst, src); + return(dst); } void irc_ns_put16(unsigned int src, unsigned char *dst) { - IRC_NS_PUT16(src, dst); + IRC_NS_PUT16(src, dst); } void irc_ns_put32(unsigned long src, unsigned char *dst) { - IRC_NS_PUT32(src, dst); + IRC_NS_PUT32(src, dst); } /* From ns_name.c */ @@ -593,48 +587,44 @@ irc_ns_put32(unsigned long src, unsigned char *dst) static int special(int ch) { - switch (ch) - { + switch (ch) { case 0x22: /* '"' */ case 0x2E: /* '.' */ case 0x3B: /* ';' */ case 0x5C: /* '\\' */ case 0x28: /* '(' */ case 0x29: /* ')' */ - /* Special modifiers in zone files. */ + /* Special modifiers in zone files. */ case 0x40: /* '@' */ case 0x24: /* '$' */ - return(1); + return(1); default: - return(0); - } + return(0); + } } static int labellen(const unsigned char *lp) -{ - int bitlen; - unsigned char l = *lp; +{ + int bitlen; + unsigned char l = *lp; - if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) - { - /* should be avoided by the caller */ - return(-1); - } - - if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) - { - if (l == DNS_LABELTYPE_BITSTRING) - { - if ((bitlen = *(lp + 1)) == 0) - bitlen = 256; - return((bitlen + 7 ) / 8 + 1); + if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + /* should be avoided by the caller */ + return(-1); } - return(-1); /* unknwon ELT */ - } + if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) { + if (l == DNS_LABELTYPE_BITSTRING) { + if ((bitlen = *(lp + 1)) == 0) + bitlen = 256; + return((bitlen + 7 ) / 8 + 1); + } - return(l); + return(-1); /* unknwon ELT */ + } + + return(l); } @@ -648,39 +638,39 @@ labellen(const unsigned char *lp) static int printable(int ch) { - return(ch > 0x20 && ch < 0x7f); + return(ch > 0x20 && ch < 0x7f); } static int irc_decode_bitstring(const char **cpp, char *dn, const char *eom) { - const char *cp = *cpp; - char *beg = dn, tc; - int b, blen, plen; + const char *cp = *cpp; + char *beg = dn, tc; + int b, blen, plen; - if ((blen = (*cp & 0xff)) == 0) - blen = 256; - plen = (blen + 3) / 4; - plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); - if (dn + plen >= eom) - return(-1); + if ((blen = (*cp & 0xff)) == 0) + blen = 256; + plen = (blen + 3) / 4; + plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); + if (dn + plen >= eom) + return(-1); - cp++; - dn += sprintf(dn, "\\[x"); - for (b = blen; b > 7; b -= 8, cp++) - dn += sprintf(dn, "%02x", *cp & 0xff); - if (b > 4) { - tc = *cp++; - dn += sprintf(dn, "%02x", tc & (0xff << (8 - b))); - } else if (b > 0) { - tc = *cp++; - dn += sprintf(dn, "%1x", - ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); - } - dn += sprintf(dn, "/%d]", blen); + cp++; + dn += sprintf(dn, "\\[x"); + for (b = blen; b > 7; b -= 8, cp++) + dn += sprintf(dn, "%02x", *cp & 0xff); + if (b > 4) { + tc = *cp++; + dn += sprintf(dn, "%02x", tc & (0xff << (8 - b))); + } else if (b > 0) { + tc = *cp++; + dn += sprintf(dn, "%1x", + ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); + } + dn += sprintf(dn, "/%d]", blen); - *cpp = cp; - return(dn - beg); + *cpp = cp; + return(dn - beg); } /* @@ -696,131 +686,130 @@ irc_decode_bitstring(const char **cpp, char *dn, const char *eom) static int irc_ns_name_pton(const char *src, unsigned char *dst, size_t dstsiz) { - unsigned char *label, *bp, *eom; - char *cp; - int c, n, escaped, e = 0; + unsigned char *label, *bp, *eom; + char *cp; + int c, n, escaped, e = 0; - escaped = 0; - bp = dst; - eom = dst + dstsiz; - label = bp++; + escaped = 0; + bp = dst; + eom = dst + dstsiz; + label = bp++; - while ((c = *src++) != 0) { - if (escaped) { - if (c == '[') { /* start a bit string label */ - if ((cp = strchr(src, ']')) == NULL) { - errno = EINVAL; /* ??? */ - return(-1); + while ((c = *src++) != 0) { + if (escaped) { + if (c == '[') { /* start a bit string label */ + if ((cp = strchr(src, ']')) == NULL) { + errno = EINVAL; /* ??? */ + return(-1); + } + if ((e = irc_encode_bitsring(&src, + cp + 2, + &label, + &bp, + (const char *)eom)) + != 0) { + errno = e; + return(-1); + } + escaped = 0; + label = bp++; + if ((c = *src++) == 0) + goto done; + else if (c != '.') { + errno = EINVAL; + return(-1); + } + continue; + } else if ((cp = strchr(digits, c)) != NULL) { + n = (cp - digits) * 100; + if ((c = *src++) == 0 || + (cp = strchr(digits, c)) == NULL) { + errno = EMSGSIZE; + return (-1); + } + n += (cp - digits) * 10; + if ((c = *src++) == 0 || + (cp = strchr(digits, c)) == NULL) { + errno = EMSGSIZE; + return (-1); + } + n += (cp - digits); + if (n > 255) { + errno = EMSGSIZE; + return (-1); + } + c = n; + } + escaped = 0; + } else if (c == '\\') { + escaped = 1; + continue; + } else if (c == '.') { + c = (bp - label - 1); + if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ + errno = EMSGSIZE; + return (-1); + } + if (label >= eom) { + errno = EMSGSIZE; + return (-1); + } + *label = c; + /* Fully qualified ? */ + if (*src == '\0') { + if (c != 0) { + if (bp >= eom) { + errno = EMSGSIZE; + return (-1); + } + *bp++ = '\0'; + } + if ((bp - dst) > NS_MAXCDNAME) { + errno = EMSGSIZE; + return (-1); + } + return (1); + } + if (c == 0 || *src == '.') { + errno = EMSGSIZE; + return (-1); + } + label = bp++; + continue; } - if ((e = irc_encode_bitsring(&src, - cp + 2, - &label, - &bp, - (const char *)eom)) - != 0) { - errno = e; - return(-1); - } - escaped = 0; - label = bp++; - if ((c = *src++) == 0) - goto done; - else if (c != '.') { - errno = EINVAL; - return(-1); - } - continue; - } - else if ((cp = strchr(digits, c)) != NULL) { - n = (cp - digits) * 100; - if ((c = *src++) == 0 || - (cp = strchr(digits, c)) == NULL) { - errno = EMSGSIZE; - return (-1); - } - n += (cp - digits) * 10; - if ((c = *src++) == 0 || - (cp = strchr(digits, c)) == NULL) { - errno = EMSGSIZE; - return (-1); - } - n += (cp - digits); - if (n > 255) { - errno = EMSGSIZE; - return (-1); - } - c = n; - } - escaped = 0; - } else if (c == '\\') { - escaped = 1; - continue; - } else if (c == '.') { - c = (bp - label - 1); - if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ - errno = EMSGSIZE; - return (-1); - } - if (label >= eom) { - errno = EMSGSIZE; - return (-1); - } - *label = c; - /* Fully qualified ? */ - if (*src == '\0') { - if (c != 0) { - if (bp >= eom) { + if (bp >= eom) { errno = EMSGSIZE; return (-1); - } - *bp++ = '\0'; } - if ((bp - dst) > NS_MAXCDNAME) { - errno = EMSGSIZE; - return (-1); - } - return (1); - } - if (c == 0 || *src == '.') { + *bp++ = (unsigned char)c; + } + c = (bp - label - 1); + if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ errno = EMSGSIZE; return (-1); - } - label = bp++; - continue; } - if (bp >= eom) { - errno = EMSGSIZE; - return (-1); +done: + if (label >= eom) { + errno = EMSGSIZE; + return (-1); } - *bp++ = (unsigned char)c; - } - c = (bp - label - 1); - if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ - errno = EMSGSIZE; - return (-1); - } - done: - if (label >= eom) { - errno = EMSGSIZE; - return (-1); - } - *label = c; - if (c != 0) { - if (bp >= eom) { - errno = EMSGSIZE; - return (-1); + *label = c; + if (c != 0) { + if (bp >= eom) { + errno = EMSGSIZE; + return (-1); + } + *bp++ = 0; } - *bp++ = 0; - } - if ((bp - dst) > NS_MAXCDNAME) - { /* src too big */ - errno = EMSGSIZE; - return (-1); - } + if ((bp - dst) > NS_MAXCDNAME) { + /* src too big */ + errno = EMSGSIZE; + return (-1); + } - return (0); + return (0); } /* @@ -844,208 +833,207 @@ static int irc_ns_name_pack(const unsigned char *src, unsigned char *dst, int dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr) { - unsigned char *dstp; - const unsigned char **cpp, **lpp, *eob, *msg; - const unsigned char *srcp; - int n, l, first = 1; + unsigned char *dstp; + const unsigned char **cpp, **lpp, *eob, *msg; + const unsigned char *srcp; + int n, l, first = 1; - srcp = src; - dstp = dst; - eob = dstp + dstsiz; - lpp = cpp = NULL; - if (dnptrs != NULL) { - if ((msg = *dnptrs++) != NULL) { - for (cpp = dnptrs; *cpp != NULL; cpp++) - (void)NULL; - lpp = cpp; /* end of list to search */ - } - } else - msg = NULL; - - /* make sure the domain we are about to add is legal */ - l = 0; - do { - int l0; - - n = *srcp; - if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { - errno = EMSGSIZE; - return (-1); - } - if ((l0 = labellen(srcp)) < 0) { - errno = EINVAL; - return(-1); - } - l += l0 + 1; - if (l > NS_MAXCDNAME) { - errno = EMSGSIZE; - return (-1); - } - srcp += l0 + 1; - } while (n != 0); - - /* from here on we need to reset compression pointer array on error */ - srcp = src; - do { - /* Look to see if we can use pointers. */ - n = *srcp; - if (n != 0 && msg != NULL) { - l = irc_dn_find(srcp, msg, (const unsigned char * const *)dnptrs, - (const unsigned char * const *)lpp); - if (l >= 0) { - if (dstp + 1 >= eob) { - goto cleanup; + srcp = src; + dstp = dst; + eob = dstp + dstsiz; + lpp = cpp = NULL; + if (dnptrs != NULL) { + if ((msg = *dnptrs++) != NULL) { + for (cpp = dnptrs; *cpp != NULL; cpp++) + (void)NULL; + lpp = cpp; /* end of list to search */ } - *dstp++ = (l >> 8) | NS_CMPRSFLGS; - *dstp++ = l % 256; - return (dstp - dst); - } - /* Not found, save it. */ - if (lastdnptr != NULL && cpp < lastdnptr - 1 && - (dstp - msg) < 0x4000 && first) { - *cpp++ = dstp; - *cpp = NULL; - first = 0; - } - } - /* copy label to buffer */ - if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { - /* Should not happen. */ - goto cleanup; - } - n = labellen(srcp); - if (dstp + 1 + n >= eob) { - goto cleanup; - } - memcpy(dstp, srcp, n + 1); - srcp += n + 1; - dstp += n + 1; - } while (n != 0); + } else + msg = NULL; - if (dstp > eob) { + /* make sure the domain we are about to add is legal */ + l = 0; + do { + int l0; + + n = *srcp; + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + errno = EMSGSIZE; + return (-1); + } + if ((l0 = labellen(srcp)) < 0) { + errno = EINVAL; + return(-1); + } + l += l0 + 1; + if (l > NS_MAXCDNAME) { + errno = EMSGSIZE; + return (-1); + } + srcp += l0 + 1; + } while (n != 0); + + /* from here on we need to reset compression pointer array on error */ + srcp = src; + do { + /* Look to see if we can use pointers. */ + n = *srcp; + if (n != 0 && msg != NULL) { + l = irc_dn_find(srcp, msg, (const unsigned char * const *)dnptrs, + (const unsigned char * const *)lpp); + if (l >= 0) { + if (dstp + 1 >= eob) { + goto cleanup; + } + *dstp++ = (l >> 8) | NS_CMPRSFLGS; + *dstp++ = l % 256; + return (dstp - dst); + } + /* Not found, save it. */ + if (lastdnptr != NULL && cpp < lastdnptr - 1 && + (dstp - msg) < 0x4000 && first) { + *cpp++ = dstp; + *cpp = NULL; + first = 0; + } + } + /* copy label to buffer */ + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + /* Should not happen. */ + goto cleanup; + } + n = labellen(srcp); + if (dstp + 1 + n >= eob) { + goto cleanup; + } + memcpy(dstp, srcp, n + 1); + srcp += n + 1; + dstp += n + 1; + } while (n != 0); + + if (dstp > eob) { cleanup: - if (msg != NULL) - *lpp = NULL; - errno = EMSGSIZE; - return (-1); - } - return(dstp - dst); + if (msg != NULL) + *lpp = NULL; + errno = EMSGSIZE; + return (-1); + } + return(dstp - dst); } static int irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr) { - unsigned char tmp[NS_MAXCDNAME]; + unsigned char tmp[NS_MAXCDNAME]; - if (irc_ns_name_pton(src, tmp, sizeof tmp) == -1) - return(-1); - return(irc_ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr)); + if (irc_ns_name_pton(src, tmp, sizeof tmp) == -1) + return(-1); + return(irc_ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr)); } static int irc_encode_bitsring(const char **bp, const char *end, unsigned char **labelp, unsigned char **dst, const char *eom) { - int afterslash = 0; - const char *cp = *bp; - char *tp, c; - const char *beg_blen; - char *end_blen = NULL; - int value = 0, count = 0, tbcount = 0, blen = 0; + int afterslash = 0; + const char *cp = *bp; + char *tp, c; + const char *beg_blen; + char *end_blen = NULL; + int value = 0, count = 0, tbcount = 0, blen = 0; - beg_blen = end_blen = NULL; + beg_blen = end_blen = NULL; - /* a bitstring must contain at least 2 characters */ - if (end - cp < 2) - return(EINVAL); + /* a bitstring must contain at least 2 characters */ + if (end - cp < 2) + return(EINVAL); - /* XXX: currently, only hex strings are supported */ - if (*cp++ != 'x') - return(EINVAL); - if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */ - return(EINVAL); + /* XXX: currently, only hex strings are supported */ + if (*cp++ != 'x') + return(EINVAL); + if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */ + return(EINVAL); - for (tp = (char*)(dst + 1); cp < end && tp < eom; cp++) { - switch((c = *cp)) { - case ']': /* end of the bitstring */ - if (afterslash) { - if (beg_blen == NULL) - return(EINVAL); - blen = (int)strtol(beg_blen, &end_blen, 10); - if (*end_blen != ']') - return(EINVAL); - } - if (count) - *tp++ = ((value << 4) & 0xff); - cp++; /* skip ']' */ - goto done; - case '/': - afterslash = 1; - break; - default: - if (afterslash) { - if (!isdigit(c&0xff)) - return(EINVAL); - if (beg_blen == NULL) { + for (tp = (char*)(dst + 1); cp < end && tp < eom; cp++) { + switch((c = *cp)) { + case ']': /* end of the bitstring */ + if (afterslash) { + if (beg_blen == NULL) + return(EINVAL); + blen = (int)strtol(beg_blen, &end_blen, 10); + if (*end_blen != ']') + return(EINVAL); + } + if (count) + *tp++ = ((value << 4) & 0xff); + cp++; /* skip ']' */ + goto done; + case '/': + afterslash = 1; + break; + default: + if (afterslash) { + if (!isdigit(c&0xff)) + return(EINVAL); + if (beg_blen == NULL) { - if (c == '0') { - /* blen never begings with 0 */ - return(EINVAL); - } - beg_blen = cp; + if (c == '0') { + /* blen never begings with 0 */ + return(EINVAL); + } + beg_blen = cp; + } + } else { + if (!isxdigit(c&0xff)) + return(EINVAL); + value <<= 4; + value += digitvalue[(int)c]; + count += 4; + tbcount += 4; + if (tbcount > 256) + return(EINVAL); + if (count == 8) { + *tp++ = value; + count = 0; + } + } + break; } - } else { - if (!isxdigit(c&0xff)) - return(EINVAL); - value <<= 4; - value += digitvalue[(int)c]; - count += 4; - tbcount += 4; - if (tbcount > 256) - return(EINVAL); - if (count == 8) { - *tp++ = value; - count = 0; - } - } - break; } - } - done: - if (cp >= end || tp >= eom) - return(EMSGSIZE); +done: + if (cp >= end || tp >= eom) + return(EMSGSIZE); - /* - * bit length validation: - * If a is present, the number of digits in the - * MUST be just sufficient to contain the number of bits specified - * by the . If there are insignificant bits in a final - * hexadecimal or octal digit, they MUST be zero. - * RFC 2673, Section 3.2. - */ - if (blen > 0) { - int traillen; + /* + * bit length validation: + * If a is present, the number of digits in the + * MUST be just sufficient to contain the number of bits specified + * by the . If there are insignificant bits in a final + * hexadecimal or octal digit, they MUST be zero. + * RFC 2673, Section 3.2. + */ + if (blen > 0) { + int traillen; - if (((blen + 3) & ~3) != tbcount) - return(EINVAL); - traillen = tbcount - blen; /* between 0 and 3 */ - if (((value << (8 - traillen)) & 0xff) != 0) - return(EINVAL); - } - else - blen = tbcount; - if (blen == 256) - blen = 0; + if (((blen + 3) & ~3) != tbcount) + return(EINVAL); + traillen = tbcount - blen; /* between 0 and 3 */ + if (((value << (8 - traillen)) & 0xff) != 0) + return(EINVAL); + } else + blen = tbcount; + if (blen == 256) + blen = 0; - /* encode the type and the significant bit fields */ - **labelp = DNS_LABELTYPE_BITSTRING; - **dst = blen; + /* encode the type and the significant bit fields */ + **labelp = DNS_LABELTYPE_BITSTRING; + **dst = blen; - *bp = cp; - *dst = (unsigned char*)tp; + *bp = cp; + *dst = (unsigned char*)tp; - return(0); + return(0); } /* @@ -1062,59 +1050,59 @@ irc_dn_find(const unsigned char *domain, const unsigned char *msg, const unsigned char * const *dnptrs, const unsigned char * const *lastdnptr) { - const unsigned char *dn, *cp, *sp; - const unsigned char * const *cpp; - unsigned int n; + const unsigned char *dn, *cp, *sp; + const unsigned char * const *cpp; + unsigned int n; - for (cpp = dnptrs; cpp < lastdnptr; cpp++) - { - sp = *cpp; - /* - * terminate search on: - * root label - * compression pointer - * unusable offset - */ - while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 && - (sp - msg) < 0x4000) { - dn = domain; - cp = sp; - while ((n = *cp++) != 0) { + for (cpp = dnptrs; cpp < lastdnptr; cpp++) { + sp = *cpp; /* - * check for indirection + * terminate search on: + * root label + * compression pointer + * unusable offset */ - switch (n & NS_CMPRSFLGS) { - case 0: /* normal case, n == len */ - n = labellen(cp - 1); /* XXX */ + while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 && + (sp - msg) < 0x4000) { + dn = domain; + cp = sp; + while ((n = *cp++) != 0) { + /* + * check for indirection + */ + switch (n & NS_CMPRSFLGS) { + case 0: /* normal case, n == len */ + n = labellen(cp - 1); /* XXX */ - if (n != *dn++) - goto next; + if (n != *dn++) + goto next; - for ((void)NULL; n > 0; n--) - if (mklower(*dn++) != - mklower(*cp++)) - goto next; - /* Is next root for both ? */ - if (*dn == '\0' && *cp == '\0') - return (sp - msg); - if (*dn) - continue; - goto next; - case NS_CMPRSFLGS: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; + for ((void)NULL; n > 0; n--) + if (mklower(*dn++) != + mklower(*cp++)) + goto next; + /* Is next root for both ? */ + if (*dn == '\0' && *cp == '\0') + return (sp - msg); + if (*dn) + continue; + goto next; + case NS_CMPRSFLGS: /* indirection */ + cp = msg + (((n & 0x3f) << 8) | *cp); + break; - default: /* illegal type */ - errno = EMSGSIZE; - return (-1); + default: /* illegal type */ + errno = EMSGSIZE; + return (-1); + } + } +next: + ; + sp += *sp + 1; } - } - next: ; - sp += *sp + 1; } - } - errno = ENOENT; - return (-1); + errno = ENOENT; + return (-1); } /* @@ -1122,12 +1110,12 @@ irc_dn_find(const unsigned char *domain, const unsigned char *msg, * * convert this character to lower case if it's upper case. * */ static int -mklower(int ch) +mklower(int ch) { - if (ch >= 0x41 && ch <= 0x5A) - return(ch + 0x20); + if (ch >= 0x41 && ch <= 0x5A) + return(ch + 0x20); - return(ch); + return(ch); } /* From resolv/mkquery.c */ @@ -1138,45 +1126,45 @@ mklower(int ch) */ int irc_res_mkquery( - const char *dname, /* domain name */ - int class, int type, /* class and type of query */ - unsigned char *buf, /* buffer to put query */ - int buflen) /* size of buffer */ + const char *dname, /* domain name */ + int class, int type, /* class and type of query */ + unsigned char *buf, /* buffer to put query */ + int buflen) /* size of buffer */ { - HEADER *hp; - unsigned char *cp; - int n; - unsigned char *dnptrs[20], **dpp, **lastdnptr; + HEADER *hp; + unsigned char *cp; + int n; + unsigned char *dnptrs[20], **dpp, **lastdnptr; - /* - * Initialize header fields. - */ - if ((buf == NULL) || (buflen < HFIXEDSZ)) - return (-1); - memset(buf, 0, HFIXEDSZ); - hp = (HEADER *) buf; + /* + * Initialize header fields. + */ + if ((buf == NULL) || (buflen < HFIXEDSZ)) + return (-1); + memset(buf, 0, HFIXEDSZ); + hp = (HEADER *) buf; - hp->id = 0; - hp->opcode = QUERY; - hp->rd = 1; /* recurse */ - hp->rcode = NO_ERRORS; - cp = buf + HFIXEDSZ; - buflen -= HFIXEDSZ; - dpp = dnptrs; - *dpp++ = buf; - *dpp++ = NULL; - lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; + hp->id = 0; + hp->opcode = QUERY; + hp->rd = 1; /* recurse */ + hp->rcode = NO_ERRORS; + cp = buf + HFIXEDSZ; + buflen -= HFIXEDSZ; + dpp = dnptrs; + *dpp++ = buf; + *dpp++ = NULL; + lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; - if ((buflen -= QFIXEDSZ) < 0) - return (-1); - if ((n = irc_dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) - return (-1); + if ((buflen -= QFIXEDSZ) < 0) + return (-1); + if ((n = irc_dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) + return (-1); - cp += n; - buflen -= n; - IRC_NS_PUT16(type, cp); - IRC_NS_PUT16(class, cp); - hp->qdcount = htons(1); + cp += n; + buflen -= n; + IRC_NS_PUT16(type, cp); + IRC_NS_PUT16(class, cp); + hp->qdcount = htons(1); - return (cp - buf); + return (cp - buf); } diff --git a/src/restart.c b/src/restart.c index d3e3a58..d726f38 100644 --- a/src/restart.c +++ b/src/restart.c @@ -29,7 +29,7 @@ #include "send.h" #include "logger.h" #include "s_conf.h" -#include "client.h" +#include "client.h" #include "ircd_signal.h" /* external var */ @@ -38,46 +38,46 @@ extern char **myargv; void restart(const char *mesg) { - static int was_here = NO; /* redundant due to restarting flag below */ + static int was_here = NO; /* redundant due to restarting flag below */ - if(was_here) - abort(); - was_here = YES; + if(was_here) + abort(); + was_here = YES; - ilog(L_MAIN, "Restarting Server because: %s", mesg); + ilog(L_MAIN, "Restarting Server because: %s", mesg); - server_reboot(); + server_reboot(); } void server_reboot(void) { - int i; - char path[PATH_MAX+1]; + int i; + char path[PATH_MAX+1]; - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Restarting server..."); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Restarting server..."); - ilog(L_MAIN, "Restarting server..."); - - /* - * XXX we used to call flush_connections() here. But since this routine - * doesn't exist anymore, we won't be flushing. This is ok, since - * when close handlers come into existance, rb_close() will be called - * below, and the data flushing will be implicit. - * -- adrian - * - * bah, for now, the program ain't coming back to here, so forcibly - * close everything the "wrong" way for now, and just LEAVE... - */ - for (i = 0; i < maxconnections; ++i) - close(i); + ilog(L_MAIN, "Restarting server..."); - unlink(pidFileName); - execv(SPATH, (void *)myargv); + /* + * XXX we used to call flush_connections() here. But since this routine + * doesn't exist anymore, we won't be flushing. This is ok, since + * when close handlers come into existance, rb_close() will be called + * below, and the data flushing will be implicit. + * -- adrian + * + * bah, for now, the program ain't coming back to here, so forcibly + * close everything the "wrong" way for now, and just LEAVE... + */ + for (i = 0; i < maxconnections; ++i) + close(i); - /* use this if execv of SPATH fails */ - rb_snprintf(path, sizeof(path), "%s/bin/ircd", ConfigFileEntry.dpath); + unlink(pidFileName); + execv(SPATH, (void *)myargv); - execv(path, (void *)myargv); - exit(-1); + /* use this if execv of SPATH fails */ + rb_snprintf(path, sizeof(path), "%s/bin/ircd", ConfigFileEntry.dpath); + + execv(path, (void *)myargv); + exit(-1); } diff --git a/src/s_auth.c b/src/s_auth.c index 2644ff1..adec9e2 100644 --- a/src/s_auth.c +++ b/src/s_auth.c @@ -49,16 +49,15 @@ #include "hook.h" #include "blacklist.h" -struct AuthRequest -{ - rb_dlink_node node; - struct Client *client; /* pointer to client struct for request */ - struct DNSQuery dns_query; /* DNS Query */ - unsigned int flags; /* current state of request */ - rb_fde_t *F; /* file descriptor for auth queries */ - time_t timeout; /* time when query expires */ - uint16_t lport; - uint16_t rport; +struct AuthRequest { + rb_dlink_node node; + struct Client *client; /* pointer to client struct for request */ + struct DNSQuery dns_query; /* DNS Query */ + unsigned int flags; /* current state of request */ + rb_fde_t *F; /* file descriptor for auth queries */ + time_t timeout; /* time when query expires */ + uint16_t lport; + uint16_t rport; }; /* @@ -89,34 +88,32 @@ struct AuthRequest * this replaces the original sendheader macros */ -static const char *HeaderMessages[] = -{ - ":*** Looking up your hostname...", - ":*** Found your hostname", - ":*** Couldn't look up your hostname", - ":*** Checking Ident", - ":*** Got Ident response", - ":*** No Ident response", - ":*** Your hostname is too long, ignoring hostname", - ":*** Your forward and reverse DNS do not match, ignoring hostname", - ":*** Cannot verify hostname validity, ignoring hostname", +static const char *HeaderMessages[] = { + ":*** Looking up your hostname...", + ":*** Found your hostname", + ":*** Couldn't look up your hostname", + ":*** Checking Ident", + ":*** Got Ident response", + ":*** No Ident response", + ":*** Your hostname is too long, ignoring hostname", + ":*** Your forward and reverse DNS do not match, ignoring hostname", + ":*** Cannot verify hostname validity, ignoring hostname", }; -typedef enum -{ - REPORT_DO_DNS, - REPORT_FIN_DNS, - REPORT_FAIL_DNS, - REPORT_DO_ID, - REPORT_FIN_ID, - REPORT_FAIL_ID, - REPORT_HOST_TOOLONG, - REPORT_HOST_MISMATCH, - REPORT_HOST_UNKNOWN +typedef enum { + REPORT_DO_DNS, + REPORT_FIN_DNS, + REPORT_FAIL_DNS, + REPORT_DO_ID, + REPORT_FIN_ID, + REPORT_FAIL_ID, + REPORT_HOST_TOOLONG, + REPORT_HOST_MISMATCH, + REPORT_HOST_UNKNOWN } ReportType; -#define sendheader(c, r) sendto_one_notice(c, HeaderMessages[(r)]) +#define sendheader(c, r) sendto_one_notice(c, HeaderMessages[(r)]) static rb_dlink_list auth_poll_list; static rb_bh *auth_heap; @@ -133,10 +130,10 @@ static CNCB auth_connect_callback; void init_auth(void) { - /* This hook takes a struct Client for its argument */ - memset(&auth_poll_list, 0, sizeof(auth_poll_list)); - rb_event_addish("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1); - auth_heap = rb_bh_create(sizeof(struct AuthRequest), LCLIENT_HEAP_SIZE, "auth_heap"); + /* This hook takes a struct Client for its argument */ + memset(&auth_poll_list, 0, sizeof(auth_poll_list)); + rb_event_addish("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1); + auth_heap = rb_bh_create(sizeof(struct AuthRequest), LCLIENT_HEAP_SIZE, "auth_heap"); } /* @@ -145,12 +142,12 @@ init_auth(void) static struct AuthRequest * make_auth_request(struct Client *client) { - struct AuthRequest *request = rb_bh_alloc(auth_heap); - client->localClient->auth_request = request; - request->F = NULL; - request->client = client; - request->timeout = rb_current_time() + ConfigFileEntry.connect_timeout; - return request; + struct AuthRequest *request = rb_bh_alloc(auth_heap); + client->localClient->auth_request = request; + request->F = NULL; + request->client = client; + request->timeout = rb_current_time() + ConfigFileEntry.connect_timeout; + return request; } /* @@ -159,7 +156,7 @@ make_auth_request(struct Client *client) static void free_auth_request(struct AuthRequest *request) { - rb_bh_free(auth_heap, request); + rb_bh_free(auth_heap, request); } /* @@ -170,23 +167,23 @@ free_auth_request(struct AuthRequest *request) static void release_auth_client(struct AuthRequest *auth) { - struct Client *client = auth->client; - - if(IsDNSPending(auth) || IsDoingAuth(auth)) - return; + struct Client *client = auth->client; - client->localClient->auth_request = NULL; - rb_dlinkDelete(&auth->node, &auth_poll_list); - free_auth_request(auth); + if(IsDNSPending(auth) || IsDoingAuth(auth)) + return; - /* - * When a client has auth'ed, we want to start reading what it sends - * us. This is what read_packet() does. - * -- adrian - */ - client->localClient->allow_read = MAX_FLOOD; - rb_dlinkAddTail(client, &client->node, &global_client_list); - read_packet(client->localClient->F, client); + client->localClient->auth_request = NULL; + rb_dlinkDelete(&auth->node, &auth_poll_list); + free_auth_request(auth); + + /* + * When a client has auth'ed, we want to start reading what it sends + * us. This is what read_packet() does. + * -- adrian + */ + client->localClient->allow_read = MAX_FLOOD; + rb_dlinkAddTail(client, &client->node, &global_client_list); + read_packet(client->localClient->F, client); } /* @@ -199,72 +196,62 @@ release_auth_client(struct AuthRequest *auth) static void auth_dns_callback(void *vptr, struct DNSReply *reply) { - struct AuthRequest *auth = (struct AuthRequest *) vptr; - ClearDNSPending(auth); + struct AuthRequest *auth = (struct AuthRequest *) vptr; + ClearDNSPending(auth); - /* XXX: this shouldn't happen, but it does. -nenolod */ - if(auth->client->localClient == NULL) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "auth_dns_callback(): auth->client->localClient (%s) is NULL", get_client_name(auth->client, HIDE_IP)); + /* XXX: this shouldn't happen, but it does. -nenolod */ + if(auth->client->localClient == NULL) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "auth_dns_callback(): auth->client->localClient (%s) is NULL", get_client_name(auth->client, HIDE_IP)); - rb_dlinkDelete(&auth->node, &auth_poll_list); - free_auth_request(auth); + rb_dlinkDelete(&auth->node, &auth_poll_list); + free_auth_request(auth); - /* and they will silently drop through and all will hopefully be ok... -nenolod */ - return; - } + /* and they will silently drop through and all will hopefully be ok... -nenolod */ + return; + } - if(reply) - { - int good = 1; + if(reply) { + int good = 1; - if(auth->client->localClient->ip.ss_family == AF_INET) - { - struct sockaddr_in *ip, *ip_fwd; + if(auth->client->localClient->ip.ss_family == AF_INET) { + struct sockaddr_in *ip, *ip_fwd; - ip = (struct sockaddr_in *) &auth->client->localClient->ip; - ip_fwd = (struct sockaddr_in *) &reply->addr; + ip = (struct sockaddr_in *) &auth->client->localClient->ip; + ip_fwd = (struct sockaddr_in *) &reply->addr; - if(ip->sin_addr.s_addr != ip_fwd->sin_addr.s_addr) - { - sendheader(auth->client, REPORT_HOST_MISMATCH); - good = 0; - } - } -#ifdef RB_IPV6 - else if(auth->client->localClient->ip.ss_family == AF_INET6) - { - struct sockaddr_in6 *ip, *ip_fwd; - - ip = (struct sockaddr_in6 *) &auth->client->localClient->ip; - ip_fwd = (struct sockaddr_in6 *) &reply->addr; - - if(memcmp(&ip->sin6_addr, &ip_fwd->sin6_addr, sizeof(struct in6_addr)) != 0) - { - sendheader(auth->client, REPORT_HOST_MISMATCH); - good = 0; - } - } -#endif - else /* can't verify it, don't know how. reject it. */ - { - sendheader(auth->client, REPORT_HOST_UNKNOWN); - good = 0; - } - - if(good && strlen(reply->h_name) <= HOSTLEN) - { - rb_strlcpy(auth->client->host, reply->h_name, sizeof(auth->client->host)); - sendheader(auth->client, REPORT_FIN_DNS); - } - else if (strlen(reply->h_name) > HOSTLEN) - sendheader(auth->client, REPORT_HOST_TOOLONG); + if(ip->sin_addr.s_addr != ip_fwd->sin_addr.s_addr) { + sendheader(auth->client, REPORT_HOST_MISMATCH); + good = 0; + } } - else - sendheader(auth->client, REPORT_FAIL_DNS); +#ifdef RB_IPV6 + else if(auth->client->localClient->ip.ss_family == AF_INET6) { + struct sockaddr_in6 *ip, *ip_fwd; - release_auth_client(auth); + ip = (struct sockaddr_in6 *) &auth->client->localClient->ip; + ip_fwd = (struct sockaddr_in6 *) &reply->addr; + + if(memcmp(&ip->sin6_addr, &ip_fwd->sin6_addr, sizeof(struct in6_addr)) != 0) { + sendheader(auth->client, REPORT_HOST_MISMATCH); + good = 0; + } + } +#endif + else { /* can't verify it, don't know how. reject it. */ + sendheader(auth->client, REPORT_HOST_UNKNOWN); + good = 0; + } + + if(good && strlen(reply->h_name) <= HOSTLEN) { + rb_strlcpy(auth->client->host, reply->h_name, sizeof(auth->client->host)); + sendheader(auth->client, REPORT_FIN_DNS); + } else if (strlen(reply->h_name) > HOSTLEN) + sendheader(auth->client, REPORT_HOST_TOOLONG); + } else + sendheader(auth->client, REPORT_FAIL_DNS); + + release_auth_client(auth); } /* @@ -273,19 +260,19 @@ auth_dns_callback(void *vptr, struct DNSReply *reply) static void auth_error(struct AuthRequest *auth) { - ++ServerStats.is_abad; + ++ServerStats.is_abad; - rb_close(auth->F); - auth->F = NULL; + rb_close(auth->F); + auth->F = NULL; - ClearAuth(auth); - sendheader(auth->client, REPORT_FAIL_ID); - - release_auth_client(auth); + ClearAuth(auth); + sendheader(auth->client, REPORT_FAIL_ID); + + release_auth_client(auth); } /* - * start_auth_query - Flag the client to show that an attempt to + * start_auth_query - Flag the client to show that an attempt to * contact the ident server on * the client's host. The connect and subsequently the socket are all put * into 'non-blocking' mode. Should the connect or any later phase of the @@ -295,85 +282,79 @@ auth_error(struct AuthRequest *auth) static int start_auth_query(struct AuthRequest *auth) { - struct rb_sockaddr_storage localaddr, destaddr; - rb_fde_t *F; - int family; - - if(IsAnyDead(auth->client)) - return 0; - - family = auth->client->localClient->ip.ss_family; - if((F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL) - { - ilog_error("creating auth stream socket"); - ++ServerStats.is_abad; - return 0; - } + struct rb_sockaddr_storage localaddr, destaddr; + rb_fde_t *F; + int family; - /* - * TBD: this is a pointless arbitrary limit .. we either have a socket or not. -nenolod - */ - if((maxconnections - 10) < rb_get_fd(F)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Can't allocate fd for auth on %s", - get_client_name(auth->client, SHOW_IP)); - rb_close(F); - return 0; - } + if(IsAnyDead(auth->client)) + return 0; - sendheader(auth->client, REPORT_DO_ID); + family = auth->client->localClient->ip.ss_family; + if((F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL) { + ilog_error("creating auth stream socket"); + ++ServerStats.is_abad; + return 0; + } - /* - * get the local address of the client and bind to that to - * make the auth request. This used to be done only for - * ifdef VIRTUAL_HOST, but needs to be done for all clients - * since the ident request must originate from that same address-- - * and machines with multiple IP addresses are common now - */ - localaddr = auth->client->preClient->lip; - - /* XXX mangle_mapped_sockaddr((struct sockaddr *)&localaddr); */ + /* + * TBD: this is a pointless arbitrary limit .. we either have a socket or not. -nenolod + */ + if((maxconnections - 10) < rb_get_fd(F)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Can't allocate fd for auth on %s", + get_client_name(auth->client, SHOW_IP)); + rb_close(F); + return 0; + } + + sendheader(auth->client, REPORT_DO_ID); + + /* + * get the local address of the client and bind to that to + * make the auth request. This used to be done only for + * ifdef VIRTUAL_HOST, but needs to be done for all clients + * since the ident request must originate from that same address-- + * and machines with multiple IP addresses are common now + */ + localaddr = auth->client->preClient->lip; + + /* XXX mangle_mapped_sockaddr((struct sockaddr *)&localaddr); */ #ifdef RB_IPV6 - if(localaddr.ss_family == AF_INET6) - { - auth->lport = ntohs(((struct sockaddr_in6 *)&localaddr)->sin6_port); - ((struct sockaddr_in6 *)&localaddr)->sin6_port = 0; - } - else + if(localaddr.ss_family == AF_INET6) { + auth->lport = ntohs(((struct sockaddr_in6 *)&localaddr)->sin6_port); + ((struct sockaddr_in6 *)&localaddr)->sin6_port = 0; + } else #endif - { - auth->lport = ntohs(((struct sockaddr_in *)&localaddr)->sin_port); - ((struct sockaddr_in *)&localaddr)->sin_port = 0; - } + { + auth->lport = ntohs(((struct sockaddr_in *)&localaddr)->sin_port); + ((struct sockaddr_in *)&localaddr)->sin_port = 0; + } - destaddr = auth->client->localClient->ip; + destaddr = auth->client->localClient->ip; #ifdef RB_IPV6 - if(localaddr.ss_family == AF_INET6) - { - auth->rport = ntohs(((struct sockaddr_in6 *)&destaddr)->sin6_port); - ((struct sockaddr_in6 *)&destaddr)->sin6_port = htons(113); - } - else + if(localaddr.ss_family == AF_INET6) { + auth->rport = ntohs(((struct sockaddr_in6 *)&destaddr)->sin6_port); + ((struct sockaddr_in6 *)&destaddr)->sin6_port = htons(113); + } else #endif - { - auth->rport = ntohs(((struct sockaddr_in *)&destaddr)->sin_port); - ((struct sockaddr_in *)&destaddr)->sin_port = htons(113); - } - - auth->F = F; - SetAuthConnect(auth); + { + auth->rport = ntohs(((struct sockaddr_in *)&destaddr)->sin_port); + ((struct sockaddr_in *)&destaddr)->sin_port = htons(113); + } - rb_connect_tcp(F, (struct sockaddr *)&destaddr, - (struct sockaddr *) &localaddr, GET_SS_LEN(&localaddr), - auth_connect_callback, auth, - GlobalSetOptions.ident_timeout); - return 1; /* We suceed here for now */ + auth->F = F; + SetAuthConnect(auth); + + rb_connect_tcp(F, (struct sockaddr *)&destaddr, + (struct sockaddr *) &localaddr, GET_SS_LEN(&localaddr), + auth_connect_callback, auth, + GlobalSetOptions.ident_timeout); + return 1; /* We suceed here for now */ } /* * GetValidIdent - parse ident query reply from identd server - * + * * Inputs - pointer to ident buf * Output - NULL if no valid ident found, otherwise pointer to name * Side effects - @@ -381,56 +362,56 @@ start_auth_query(struct AuthRequest *auth) static char * GetValidIdent(char *buf) { - int remp = 0; - int locp = 0; - char *colon1Ptr; - char *colon2Ptr; - char *colon3Ptr; - char *commaPtr; - char *remotePortString; + int remp = 0; + int locp = 0; + char *colon1Ptr; + char *colon2Ptr; + char *colon3Ptr; + char *commaPtr; + char *remotePortString; - /* All this to get rid of a sscanf() fun. */ - remotePortString = buf; + /* All this to get rid of a sscanf() fun. */ + remotePortString = buf; - colon1Ptr = strchr(remotePortString, ':'); - if(!colon1Ptr) - return 0; + colon1Ptr = strchr(remotePortString, ':'); + if(!colon1Ptr) + return 0; - *colon1Ptr = '\0'; - colon1Ptr++; - colon2Ptr = strchr(colon1Ptr, ':'); - if(!colon2Ptr) - return 0; + *colon1Ptr = '\0'; + colon1Ptr++; + colon2Ptr = strchr(colon1Ptr, ':'); + if(!colon2Ptr) + return 0; - *colon2Ptr = '\0'; - colon2Ptr++; - commaPtr = strchr(remotePortString, ','); + *colon2Ptr = '\0'; + colon2Ptr++; + commaPtr = strchr(remotePortString, ','); - if(!commaPtr) - return 0; + if(!commaPtr) + return 0; - *commaPtr = '\0'; - commaPtr++; + *commaPtr = '\0'; + commaPtr++; - remp = atoi(remotePortString); - if(!remp) - return 0; + remp = atoi(remotePortString); + if(!remp) + return 0; - locp = atoi(commaPtr); - if(!locp) - return 0; + locp = atoi(commaPtr); + if(!locp) + return 0; - /* look for USERID bordered by first pair of colons */ - if(!strstr(colon1Ptr, "USERID")) - return 0; + /* look for USERID bordered by first pair of colons */ + if(!strstr(colon1Ptr, "USERID")) + return 0; - colon3Ptr = strchr(colon2Ptr, ':'); - if(!colon3Ptr) - return 0; + colon3Ptr = strchr(colon2Ptr, ':'); + if(!colon3Ptr) + return 0; - *colon3Ptr = '\0'; - colon3Ptr++; - return (colon3Ptr); + *colon3Ptr = '\0'; + colon3Ptr++; + return (colon3Ptr); } /* @@ -439,27 +420,27 @@ GetValidIdent(char *buf) void start_auth(struct Client *client) { - struct AuthRequest *auth = 0; - s_assert(0 != client); - if(client == NULL) - return; + struct AuthRequest *auth = 0; + s_assert(0 != client); + if(client == NULL) + return; - auth = make_auth_request(client); + auth = make_auth_request(client); - auth->dns_query.ptr = auth; - auth->dns_query.callback = auth_dns_callback; + auth->dns_query.ptr = auth; + auth->dns_query.callback = auth_dns_callback; - sendheader(client, REPORT_DO_DNS); + sendheader(client, REPORT_DO_DNS); - /* No DNS cache now, remember? -- adrian */ - gethost_byaddr(&client->localClient->ip, &auth->dns_query); + /* No DNS cache now, remember? -- adrian */ + gethost_byaddr(&client->localClient->ip, &auth->dns_query); - SetDNSPending(auth); + SetDNSPending(auth); - if(ConfigFileEntry.disable_auth == 0) - start_auth_query(auth); + if(ConfigFileEntry.disable_auth == 0) + start_auth_query(auth); - rb_dlinkAdd(auth, &auth->node, &auth_poll_list); + rb_dlinkAdd(auth, &auth->node, &auth_poll_list); } /* @@ -469,37 +450,33 @@ start_auth(struct Client *client) static void timeout_auth_queries_event(void *notused) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct AuthRequest *auth; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct AuthRequest *auth; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, auth_poll_list.head) - { - auth = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, auth_poll_list.head) { + auth = ptr->data; - if(auth->timeout < rb_current_time()) - { - if(auth->F != NULL) - rb_close(auth->F); + if(auth->timeout < rb_current_time()) { + if(auth->F != NULL) + rb_close(auth->F); - if(IsDoingAuth(auth)) - { - ClearAuth(auth); - ++ServerStats.is_abad; - sendheader(auth->client, REPORT_FAIL_ID); - auth->client->localClient->auth_request = NULL; - } - if(IsDNSPending(auth)) - { - ClearDNSPending(auth); - delete_resolver_queries(&auth->dns_query); - sendheader(auth->client, REPORT_FAIL_DNS); - } + if(IsDoingAuth(auth)) { + ClearAuth(auth); + ++ServerStats.is_abad; + sendheader(auth->client, REPORT_FAIL_ID); + auth->client->localClient->auth_request = NULL; + } + if(IsDNSPending(auth)) { + ClearDNSPending(auth); + delete_resolver_queries(&auth->dns_query); + sendheader(auth->client, REPORT_FAIL_DNS); + } - auth->client->localClient->lasttime = rb_current_time(); - release_auth_client(auth); - } - } + auth->client->localClient->lasttime = rb_current_time(); + release_auth_client(auth); + } + } } /* @@ -516,33 +493,31 @@ timeout_auth_queries_event(void *notused) static void auth_connect_callback(rb_fde_t *F, int error, void *data) { - struct AuthRequest *auth = data; - char authbuf[32]; + struct AuthRequest *auth = data; + char authbuf[32]; - /* Check the error */ - if(error != RB_OK) - { - /* We had an error during connection :( */ - auth_error(auth); - return; - } + /* Check the error */ + if(error != RB_OK) { + /* We had an error during connection :( */ + auth_error(auth); + return; + } - rb_snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n", - auth->rport, auth->lport); + rb_snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n", + auth->rport, auth->lport); - if(rb_write(auth->F, authbuf, strlen(authbuf)) != strlen(authbuf)) - { - auth_error(auth); - return; - } - ClearAuthConnect(auth); - SetAuthPending(auth); - read_auth_reply(auth->F, auth); + if(rb_write(auth->F, authbuf, strlen(authbuf)) != strlen(authbuf)) { + auth_error(auth); + return; + } + ClearAuthConnect(auth); + SetAuthPending(auth); + read_auth_reply(auth->F, auth); } /* - * read_auth_reply - read the reply (if any) from the ident server + * read_auth_reply - read the reply (if any) from the ident server * we connected to. * We only give it one shot, if the reply isn't good the first time * fail the authentication entirely. --Bleep @@ -552,66 +527,57 @@ auth_connect_callback(rb_fde_t *F, int error, void *data) static void read_auth_reply(rb_fde_t *F, void *data) { - struct AuthRequest *auth = data; - char *s = NULL; - char *t = NULL; - int len; - int count; - char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */ + struct AuthRequest *auth = data; + char *s = NULL; + char *t = NULL; + int len; + int count; + char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */ - len = rb_read(F, buf, AUTH_BUFSIZ); + len = rb_read(F, buf, AUTH_BUFSIZ); - if(len < 0 && rb_ignore_errno(errno)) - { - rb_setselect(F, RB_SELECT_READ, read_auth_reply, auth); - return; - } + if(len < 0 && rb_ignore_errno(errno)) { + rb_setselect(F, RB_SELECT_READ, read_auth_reply, auth); + return; + } - if(len > 0) - { - buf[len] = '\0'; + if(len > 0) { + buf[len] = '\0'; - if((s = GetValidIdent(buf))) - { - t = auth->client->username; + if((s = GetValidIdent(buf))) { + t = auth->client->username; - while (*s == '~' || *s == '^') - s++; + while (*s == '~' || *s == '^') + s++; - for (count = USERLEN; *s && count; s++) - { - if(*s == '@') - { - break; - } - if(!IsSpace(*s) && *s != ':' && *s != '[') - { - *t++ = *s; - count--; - } - } - *t = '\0'; - } - } + for (count = USERLEN; *s && count; s++) { + if(*s == '@') { + break; + } + if(!IsSpace(*s) && *s != ':' && *s != '[') { + *t++ = *s; + count--; + } + } + *t = '\0'; + } + } - rb_close(auth->F); - auth->F = NULL; - ClearAuth(auth); + rb_close(auth->F); + auth->F = NULL; + ClearAuth(auth); - if(s == NULL) - { - ++ServerStats.is_abad; - strcpy(auth->client->username, "unknown"); - sendheader(auth->client, REPORT_FAIL_ID); - } - else - { - sendheader(auth->client, REPORT_FIN_ID); - ++ServerStats.is_asuc; - SetGotId(auth->client); - } + if(s == NULL) { + ++ServerStats.is_abad; + strcpy(auth->client->username, "unknown"); + sendheader(auth->client, REPORT_FAIL_ID); + } else { + sendheader(auth->client, REPORT_FIN_ID); + ++ServerStats.is_asuc; + SetGotId(auth->client); + } - release_auth_client(auth); + release_auth_client(auth); } @@ -623,21 +589,21 @@ read_auth_reply(rb_fde_t *F, void *data) void delete_auth_queries(struct Client *target_p) { - struct AuthRequest *auth; + struct AuthRequest *auth; - if(target_p == NULL || target_p->localClient == NULL || - target_p->localClient->auth_request == NULL) - return; - - auth = target_p->localClient->auth_request; - target_p->localClient->auth_request = NULL; + if(target_p == NULL || target_p->localClient == NULL || + target_p->localClient->auth_request == NULL) + return; - if(IsDNSPending(auth)) - delete_resolver_queries(&auth->dns_query); + auth = target_p->localClient->auth_request; + target_p->localClient->auth_request = NULL; - if(auth->F != NULL) - rb_close(auth->F); - - rb_dlinkDelete(&auth->node, &auth_poll_list); - free_auth_request(auth); + if(IsDNSPending(auth)) + delete_resolver_queries(&auth->dns_query); + + if(auth->F != NULL) + rb_close(auth->F); + + rb_dlinkDelete(&auth->node, &auth_poll_list); + free_auth_request(auth); } diff --git a/src/s_conf.c b/src/s_conf.c index 8ac6977..6735d0f 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -91,25 +91,25 @@ int startup = 1; void init_s_conf(void) { - confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap"); + confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap"); - rb_event_addish("expire_prop_bans", expire_prop_bans, &prop_bans, 60); + rb_event_addish("expire_prop_bans", expire_prop_bans, &prop_bans, 60); - rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); - rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); + rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); + rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); - rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd, - &temp_klines[TEMP_HOUR], 3600); - rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd, - &temp_dlines[TEMP_HOUR], 3600); - rb_event_addish("expire_temp_klines_day", reorganise_temp_kd, - &temp_klines[TEMP_DAY], 86400); - rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd, - &temp_dlines[TEMP_DAY], 86400); - rb_event_addish("expire_temp_klines_week", reorganise_temp_kd, - &temp_klines[TEMP_WEEK], 604800); - rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd, - &temp_dlines[TEMP_WEEK], 604800); + rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd, + &temp_klines[TEMP_HOUR], 3600); + rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd, + &temp_dlines[TEMP_HOUR], 3600); + rb_event_addish("expire_temp_klines_day", reorganise_temp_kd, + &temp_klines[TEMP_DAY], 86400); + rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd, + &temp_dlines[TEMP_DAY], 86400); + rb_event_addish("expire_temp_klines_week", reorganise_temp_kd, + &temp_klines[TEMP_WEEK], 604800); + rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd, + &temp_dlines[TEMP_WEEK], 604800); } /* @@ -122,11 +122,11 @@ init_s_conf(void) struct ConfItem * make_conf() { - struct ConfItem *aconf; + struct ConfItem *aconf; - aconf = rb_bh_alloc(confitem_heap); - aconf->status = CONF_ILLEGAL; - return (aconf); + aconf = rb_bh_alloc(confitem_heap); + aconf->status = CONF_ILLEGAL; + return (aconf); } /* @@ -139,28 +139,28 @@ make_conf() void free_conf(struct ConfItem *aconf) { - s_assert(aconf != NULL); - if(aconf == NULL) - return; + s_assert(aconf != NULL); + if(aconf == NULL) + return; - /* security.. */ - if(aconf->passwd) - memset(aconf->passwd, 0, strlen(aconf->passwd)); - if(aconf->spasswd) - memset(aconf->spasswd, 0, strlen(aconf->spasswd)); + /* security.. */ + if(aconf->passwd) + memset(aconf->passwd, 0, strlen(aconf->passwd)); + if(aconf->spasswd) + memset(aconf->spasswd, 0, strlen(aconf->spasswd)); - rb_free(aconf->passwd); - rb_free(aconf->spasswd); - rb_free(aconf->className); - rb_free(aconf->user); - rb_free(aconf->host); + rb_free(aconf->passwd); + rb_free(aconf->spasswd); + rb_free(aconf->className); + rb_free(aconf->user); + rb_free(aconf->host); - if(IsConfBan(aconf)) - operhash_delete(aconf->info.oper); - else - rb_free(aconf->info.name); + if(IsConfBan(aconf)) + operhash_delete(aconf->info.oper); + else + rb_free(aconf->info.name); - rb_bh_free(confitem_heap, aconf); + rb_bh_free(confitem_heap, aconf); } /* @@ -180,129 +180,126 @@ free_conf(struct ConfItem *aconf) int check_client(struct Client *client_p, struct Client *source_p, const char *username) { - int i; + int i; - if((i = verify_access(source_p, username))) - { - ilog(L_FUSER, "Access denied: %s[%s]", - source_p->name, source_p->sockhost); - } - - switch (i) - { - case SOCKET_ERROR: - exit_client(client_p, source_p, &me, "Socket Error"); - break; + if((i = verify_access(source_p, username))) { + ilog(L_FUSER, "Access denied: %s[%s]", + source_p->name, source_p->sockhost); + } - case TOO_MANY_LOCAL: - /* Note that these notices are sent to opers on other - * servers also, so even if local opers are allowed to - * see the IP, we still cannot send it. - */ - sendto_realops_snomask(SNO_FULL, L_NETWIDE, - "Too many local connections for %s!%s%s@%s", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, - show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); + switch (i) { + case SOCKET_ERROR: + exit_client(client_p, source_p, &me, "Socket Error"); + break; - ilog(L_FUSER, "Too many local connections from %s!%s%s@%s", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->sockhost); + case TOO_MANY_LOCAL: + /* Note that these notices are sent to opers on other + * servers also, so even if local opers are allowed to + * see the IP, we still cannot send it. + */ + sendto_realops_snomask(SNO_FULL, L_NETWIDE, + "Too many local connections for %s!%s%s@%s", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, + show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); - ServerStats.is_ref++; - exit_client(client_p, source_p, &me, "Too many host connections (local)"); - break; + ilog(L_FUSER, "Too many local connections from %s!%s%s@%s", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->sockhost); - case TOO_MANY_GLOBAL: - sendto_realops_snomask(SNO_FULL, L_NETWIDE, - "Too many global connections for %s!%s%s@%s", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, - show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); - ilog(L_FUSER, "Too many global connections from %s!%s%s@%s", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->sockhost); + ServerStats.is_ref++; + exit_client(client_p, source_p, &me, "Too many host connections (local)"); + break; - ServerStats.is_ref++; - exit_client(client_p, source_p, &me, "Too many host connections (global)"); - break; + case TOO_MANY_GLOBAL: + sendto_realops_snomask(SNO_FULL, L_NETWIDE, + "Too many global connections for %s!%s%s@%s", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, + show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); + ilog(L_FUSER, "Too many global connections from %s!%s%s@%s", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->sockhost); - case TOO_MANY_IDENT: - sendto_realops_snomask(SNO_FULL, L_NETWIDE, - "Too many user connections for %s!%s%s@%s", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, - show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); - ilog(L_FUSER, "Too many user connections from %s!%s%s@%s", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->sockhost); + ServerStats.is_ref++; + exit_client(client_p, source_p, &me, "Too many host connections (global)"); + break; - ServerStats.is_ref++; - exit_client(client_p, source_p, &me, "Too many user connections (global)"); - break; + case TOO_MANY_IDENT: + sendto_realops_snomask(SNO_FULL, L_NETWIDE, + "Too many user connections for %s!%s%s@%s", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, + show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); + ilog(L_FUSER, "Too many user connections from %s!%s%s@%s", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->sockhost); - case I_LINE_FULL: - sendto_realops_snomask(SNO_FULL, L_NETWIDE, - "I-line is full for %s!%s%s@%s (%s).", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->host, - show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255"); + ServerStats.is_ref++; + exit_client(client_p, source_p, &me, "Too many user connections (global)"); + break; - ilog(L_FUSER, "Too many connections from %s!%s%s@%s.", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->sockhost); + case I_LINE_FULL: + sendto_realops_snomask(SNO_FULL, L_NETWIDE, + "I-line is full for %s!%s%s@%s (%s).", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->host, + show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255"); - ServerStats.is_ref++; - exit_client(client_p, source_p, &me, - "No more connections allowed in your connection class"); - break; + ilog(L_FUSER, "Too many connections from %s!%s%s@%s.", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->sockhost); - case NOT_AUTHORISED: - { - int port = -1; + ServerStats.is_ref++; + exit_client(client_p, source_p, &me, + "No more connections allowed in your connection class"); + break; + + case NOT_AUTHORISED: { + int port = -1; #ifdef RB_IPV6 - if(source_p->localClient->ip.ss_family == AF_INET6) - port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port); - else + if(source_p->localClient->ip.ss_family == AF_INET6) + port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port); + else #endif - port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port); - - ServerStats.is_ref++; - /* jdc - lists server name & port connections are on */ - /* a purely cosmetical change */ - /* why ipaddr, and not just source_p->sockhost? --fl */ + port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port); + + ServerStats.is_ref++; + /* jdc - lists server name & port connections are on */ + /* a purely cosmetical change */ + /* why ipaddr, and not just source_p->sockhost? --fl */ #if 0 - static char ipaddr[HOSTIPLEN]; - rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); + static char ipaddr[HOSTIPLEN]; + rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); #endif - sendto_realops_snomask(SNO_UNAUTH, L_ALL, - "Unauthorised client connection from " - "%s!%s%s@%s [%s] on [%s/%u].", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->host, - source_p->sockhost, - source_p->localClient->listener->name, port); + sendto_realops_snomask(SNO_UNAUTH, L_ALL, + "Unauthorised client connection from " + "%s!%s%s@%s [%s] on [%s/%u].", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->host, + source_p->sockhost, + source_p->localClient->listener->name, port); - ilog(L_FUSER, - "Unauthorised client connection from %s!%s%s@%s on [%s/%u].", - source_p->name, IsGotId(source_p) ? "" : "~", - source_p->username, source_p->sockhost, - source_p->localClient->listener->name, port); - add_reject(client_p, NULL, NULL); - exit_client(client_p, source_p, &me, - "You are not authorised to use this server"); - break; - } - case BANNED_CLIENT: - exit_client(client_p, client_p, &me, "*** Banned "); - ServerStats.is_ref++; - break; + ilog(L_FUSER, + "Unauthorised client connection from %s!%s%s@%s on [%s/%u].", + source_p->name, IsGotId(source_p) ? "" : "~", + source_p->username, source_p->sockhost, + source_p->localClient->listener->name, port); + add_reject(client_p, NULL, NULL); + exit_client(client_p, source_p, &me, + "You are not authorised to use this server"); + break; + } + case BANNED_CLIENT: + exit_client(client_p, client_p, &me, "*** Banned "); + ServerStats.is_ref++; + break; - case 0: - default: - break; - } - return (i); + case 0: + default: + break; + } + return (i); } /* @@ -316,92 +313,81 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern static int verify_access(struct Client *client_p, const char *username) { - struct ConfItem *aconf; - char non_ident[USERLEN + 1]; + struct ConfItem *aconf; + char non_ident[USERLEN + 1]; - if(IsGotId(client_p)) - { - aconf = find_address_conf(client_p->host, client_p->sockhost, - client_p->username, client_p->username, - (struct sockaddr *) &client_p->localClient->ip, - client_p->localClient->ip.ss_family, - client_p->localClient->auth_user); - } - else - { - rb_strlcpy(non_ident, "~", sizeof(non_ident)); - rb_strlcat(non_ident, username, sizeof(non_ident)); - aconf = find_address_conf(client_p->host, client_p->sockhost, - non_ident, client_p->username, - (struct sockaddr *) &client_p->localClient->ip, - client_p->localClient->ip.ss_family, - client_p->localClient->auth_user); - } + if(IsGotId(client_p)) { + aconf = find_address_conf(client_p->host, client_p->sockhost, + client_p->username, client_p->username, + (struct sockaddr *) &client_p->localClient->ip, + client_p->localClient->ip.ss_family, + client_p->localClient->auth_user); + } else { + rb_strlcpy(non_ident, "~", sizeof(non_ident)); + rb_strlcat(non_ident, username, sizeof(non_ident)); + aconf = find_address_conf(client_p->host, client_p->sockhost, + non_ident, client_p->username, + (struct sockaddr *) &client_p->localClient->ip, + client_p->localClient->ip.ss_family, + client_p->localClient->auth_user); + } - if(aconf == NULL) - return NOT_AUTHORISED; + if(aconf == NULL) + return NOT_AUTHORISED; - if(aconf->status & CONF_CLIENT) - { - if(aconf->flags & CONF_FLAGS_REDIR) - { - sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR), - aconf->info.name ? aconf->info.name : "", aconf->port); - return (NOT_AUTHORISED); - } + if(aconf->status & CONF_CLIENT) { + if(aconf->flags & CONF_FLAGS_REDIR) { + sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR), + aconf->info.name ? aconf->info.name : "", aconf->port); + return (NOT_AUTHORISED); + } - /* Thanks for spoof idea amm */ - if(IsConfDoSpoofIp(aconf)) - { - char *p; + /* Thanks for spoof idea amm */ + if(IsConfDoSpoofIp(aconf)) { + char *p; - /* show_ip() depends on this --fl */ - SetIPSpoof(client_p); + /* show_ip() depends on this --fl */ + SetIPSpoof(client_p); - if(IsConfSpoofNotice(aconf)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s spoofing: %s as %s", - client_p->name, - show_ip(NULL, client_p) ? client_p->host : aconf->info.name, - aconf->info.name); - } + if(IsConfSpoofNotice(aconf)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s spoofing: %s as %s", + client_p->name, + show_ip(NULL, client_p) ? client_p->host : aconf->info.name, + aconf->info.name); + } - /* user@host spoof */ - if((p = strchr(aconf->info.name, '@')) != NULL) - { - char *host = p+1; - *p = '\0'; + /* user@host spoof */ + if((p = strchr(aconf->info.name, '@')) != NULL) { + char *host = p+1; + *p = '\0'; - rb_strlcpy(client_p->username, aconf->info.name, - sizeof(client_p->username)); - rb_strlcpy(client_p->host, host, - sizeof(client_p->host)); - *p = '@'; - } - else - rb_strlcpy(client_p->host, aconf->info.name, sizeof(client_p->host)); - } - return (attach_iline(client_p, aconf)); - } - else if(aconf->status & CONF_KILL) - { - if(ConfigFileEntry.kline_with_reason) - sendto_one(client_p, - form_str(ERR_YOUREBANNEDCREEP), - me.name, client_p->name, - get_user_ban_reason(aconf)); - add_reject(client_p, aconf->user, aconf->host); - return (BANNED_CLIENT); - } + rb_strlcpy(client_p->username, aconf->info.name, + sizeof(client_p->username)); + rb_strlcpy(client_p->host, host, + sizeof(client_p->host)); + *p = '@'; + } else + rb_strlcpy(client_p->host, aconf->info.name, sizeof(client_p->host)); + } + return (attach_iline(client_p, aconf)); + } else if(aconf->status & CONF_KILL) { + if(ConfigFileEntry.kline_with_reason) + sendto_one(client_p, + form_str(ERR_YOUREBANNEDCREEP), + me.name, client_p->name, + get_user_ban_reason(aconf)); + add_reject(client_p, aconf->user, aconf->host); + return (BANNED_CLIENT); + } - return NOT_AUTHORISED; + return NOT_AUTHORISED; } /* * add_ip_limit - * + * * Returns 1 if successful 0 if not * * This checks if the user has exceed the limits for their class @@ -411,62 +397,58 @@ verify_access(struct Client *client_p, const char *username) static int add_ip_limit(struct Client *client_p, struct ConfItem *aconf) { - rb_patricia_node_t *pnode; - int bitlen; + rb_patricia_node_t *pnode; + int bitlen; - /* If the limits are 0 don't do anything.. */ - if(ConfCidrAmount(aconf) == 0 - || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) - return -1; + /* If the limits are 0 don't do anything.. */ + if(ConfCidrAmount(aconf) == 0 + || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) + return -1; - pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); + pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); - if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET) - bitlen = ConfCidrIpv4Bitlen(aconf); - else - bitlen = ConfCidrIpv6Bitlen(aconf); + if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET) + bitlen = ConfCidrIpv4Bitlen(aconf); + else + bitlen = ConfCidrIpv6Bitlen(aconf); - if(pnode == NULL) - pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, bitlen); + if(pnode == NULL) + pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, bitlen); - s_assert(pnode != NULL); + s_assert(pnode != NULL); - if(pnode != NULL) - { - if(((intptr_t)pnode->data) >= ConfCidrAmount(aconf) && !IsConfExemptLimits(aconf)) - { - /* This should only happen if the limits are set to 0 */ - if((intptr_t)pnode->data == 0) - { - rb_patricia_remove(ConfIpLimits(aconf), pnode); - } - return (0); - } + if(pnode != NULL) { + if(((intptr_t)pnode->data) >= ConfCidrAmount(aconf) && !IsConfExemptLimits(aconf)) { + /* This should only happen if the limits are set to 0 */ + if((intptr_t)pnode->data == 0) { + rb_patricia_remove(ConfIpLimits(aconf), pnode); + } + return (0); + } - pnode->data = (void *)(((intptr_t)pnode->data) + 1); - } - return 1; + pnode->data = (void *)(((intptr_t)pnode->data) + 1); + } + return 1; } static void remove_ip_limit(struct Client *client_p, struct ConfItem *aconf) { - rb_patricia_node_t *pnode; + rb_patricia_node_t *pnode; - /* If the limits are 0 don't do anything.. */ - if(ConfCidrAmount(aconf) == 0 - || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) - return; + /* If the limits are 0 don't do anything.. */ + if(ConfCidrAmount(aconf) == 0 + || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) + return; - pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); - if(pnode == NULL) - return; + pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); + if(pnode == NULL) + return; - pnode->data = (void *)(((intptr_t)pnode->data) - 1); - if(((intptr_t)pnode->data) == 0) - { - rb_patricia_remove(ConfIpLimits(aconf), pnode); - } + pnode->data = (void *)(((intptr_t)pnode->data) - 1); + if(((intptr_t)pnode->data) == 0) { + rb_patricia_remove(ConfIpLimits(aconf), pnode); + } } @@ -481,50 +463,47 @@ remove_ip_limit(struct Client *client_p, struct ConfItem *aconf) static int attach_iline(struct Client *client_p, struct ConfItem *aconf) { - struct Client *target_p; - rb_dlink_node *ptr; - int local_count = 0; - int global_count = 0; - int ident_count = 0; - int unidented; + struct Client *target_p; + rb_dlink_node *ptr; + int local_count = 0; + int global_count = 0; + int ident_count = 0; + int unidented; - if(IsConfExemptLimits(aconf)) - return (attach_conf(client_p, aconf)); + if(IsConfExemptLimits(aconf)) + return (attach_conf(client_p, aconf)); - unidented = !IsGotId(client_p) && !IsNoTilde(aconf) && - (!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')); + unidented = !IsGotId(client_p) && !IsNoTilde(aconf) && + (!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')); - /* find_hostname() returns the head of the list to search */ - RB_DLINK_FOREACH(ptr, find_hostname(client_p->host)) - { - target_p = ptr->data; + /* find_hostname() returns the head of the list to search */ + RB_DLINK_FOREACH(ptr, find_hostname(client_p->host)) { + target_p = ptr->data; - if(irccmp(client_p->host, target_p->orighost) != 0) - continue; + if(irccmp(client_p->host, target_p->orighost) != 0) + continue; - if(MyConnect(target_p)) - local_count++; + if(MyConnect(target_p)) + local_count++; - global_count++; + global_count++; - if(unidented) - { - if(*target_p->username == '~') - ident_count++; - } - else if(irccmp(target_p->username, client_p->username) == 0) - ident_count++; + if(unidented) { + if(*target_p->username == '~') + ident_count++; + } else if(irccmp(target_p->username, client_p->username) == 0) + ident_count++; - if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf)) - return (TOO_MANY_LOCAL); - else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf)) - return (TOO_MANY_GLOBAL); - else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf)) - return (TOO_MANY_IDENT); - } + if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf)) + return (TOO_MANY_LOCAL); + else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf)) + return (TOO_MANY_GLOBAL); + else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf)) + return (TOO_MANY_IDENT); + } - return (attach_conf(client_p, aconf)); + return (attach_conf(client_p, aconf)); } /* @@ -538,41 +517,38 @@ attach_iline(struct Client *client_p, struct ConfItem *aconf) int detach_conf(struct Client *client_p) { - struct ConfItem *aconf; + struct ConfItem *aconf; - aconf = client_p->localClient->att_conf; + aconf = client_p->localClient->att_conf; - if(aconf != NULL) - { - if(ClassPtr(aconf)) - { - remove_ip_limit(client_p, aconf); + if(aconf != NULL) { + if(ClassPtr(aconf)) { + remove_ip_limit(client_p, aconf); - if(ConfCurrUsers(aconf) > 0) - --ConfCurrUsers(aconf); + if(ConfCurrUsers(aconf) > 0) + --ConfCurrUsers(aconf); - if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0) - { - free_class(ClassPtr(aconf)); - ClassPtr(aconf) = NULL; - } + if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0) { + free_class(ClassPtr(aconf)); + ClassPtr(aconf) = NULL; + } - } + } - aconf->clients--; - if(!aconf->clients && IsIllegal(aconf)) - free_conf(aconf); + aconf->clients--; + if(!aconf->clients && IsIllegal(aconf)) + free_conf(aconf); - client_p->localClient->att_conf = NULL; - return 0; - } + client_p->localClient->att_conf = NULL; + return 0; + } - return -1; + return -1; } /* * attach_conf - * + * * inputs - client pointer * - conf pointer * output - @@ -584,37 +560,32 @@ detach_conf(struct Client *client_p) int attach_conf(struct Client *client_p, struct ConfItem *aconf) { - if(IsIllegal(aconf)) - return (NOT_AUTHORISED); + if(IsIllegal(aconf)) + return (NOT_AUTHORISED); - if(ClassPtr(aconf)) - { - if(!add_ip_limit(client_p, aconf)) - return (TOO_MANY_LOCAL); - } + if(ClassPtr(aconf)) { + if(!add_ip_limit(client_p, aconf)) + return (TOO_MANY_LOCAL); + } - if((aconf->status & CONF_CLIENT) && - ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0) - { - if(!IsConfExemptLimits(aconf)) - { - return (I_LINE_FULL); - } - else - { - sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!"); - } + if((aconf->status & CONF_CLIENT) && + ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0) { + if(!IsConfExemptLimits(aconf)) { + return (I_LINE_FULL); + } else { + sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!"); + } - } + } - if(client_p->localClient->att_conf != NULL) - detach_conf(client_p); + if(client_p->localClient->att_conf != NULL) + detach_conf(client_p); - client_p->localClient->att_conf = aconf; + client_p->localClient->att_conf = aconf; - aconf->clients++; - ConfCurrUsers(aconf)++; - return (0); + aconf->clients++; + ConfCurrUsers(aconf)++; + return (0); } /* @@ -627,29 +598,28 @@ attach_conf(struct Client *client_p, struct ConfItem *aconf) int rehash(int sig) { - if(sig != 0) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Got signal SIGHUP, reloading ircd conf. file"); - } + if(sig != 0) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Got signal SIGHUP, reloading ircd conf. file"); + } - restart_resolver(); - /* don't close listeners until we know we can go ahead with the rehash */ - read_conf_files(NO); + restart_resolver(); + /* don't close listeners until we know we can go ahead with the rehash */ + read_conf_files(NO); - if(ServerInfo.description != NULL) - rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); - else - rb_strlcpy(me.info, "unknown", sizeof(me.info)); + if(ServerInfo.description != NULL) + rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); + else + rb_strlcpy(me.info, "unknown", sizeof(me.info)); - open_logfiles(); - return (0); + open_logfiles(); + return (0); } void rehash_bans(int sig) { - bandb_rehash_bans(); + bandb_rehash_bans(); } /* @@ -670,170 +640,170 @@ rehash_bans(int sig) static void set_default_conf(void) { - /* ServerInfo.name is not rehashable */ - /* ServerInfo.name = ServerInfo.name; */ - ServerInfo.description = NULL; - ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); - ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); - ServerInfo.helpchan = rb_strdup(""); - ServerInfo.helpurl = rb_strdup(""); + /* ServerInfo.name is not rehashable */ + /* ServerInfo.name = ServerInfo.name; */ + ServerInfo.description = NULL; + ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); + ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); + ServerInfo.helpchan = rb_strdup(""); + ServerInfo.helpurl = rb_strdup(""); - memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); - ServerInfo.specific_ipv4_vhost = 0; + memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); + ServerInfo.specific_ipv4_vhost = 0; #ifdef RB_IPV6 - memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); - ServerInfo.specific_ipv6_vhost = 0; + memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); + ServerInfo.specific_ipv6_vhost = 0; #endif - /* Don't reset hub, as that will break lazylinks */ - /* ServerInfo.hub = NO; */ - AdminInfo.name = NULL; - AdminInfo.email = NULL; - AdminInfo.description = NULL; + /* Don't reset hub, as that will break lazylinks */ + /* ServerInfo.hub = NO; */ + AdminInfo.name = NULL; + AdminInfo.email = NULL; + AdminInfo.description = NULL; - ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); - ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); - ConfigFileEntry.default_operhost = rb_strdup(""); - ConfigFileEntry.static_quit = rb_strdup(""); - ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); + ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); + ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); + ConfigFileEntry.default_operhost = rb_strdup(""); + ConfigFileEntry.static_quit = rb_strdup(""); + ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); - ConfigFileEntry.default_umodes = UMODE_INVISIBLE; - ConfigFileEntry.failed_oper_notice = YES; - ConfigFileEntry.anti_nick_flood = NO; - ConfigFileEntry.disable_fake_channels = NO; - ConfigFileEntry.hide_channel_below_users = 3; - ConfigFileEntry.max_nick_time = 20; - ConfigFileEntry.max_nick_changes = 5; - ConfigFileEntry.max_accept = 20; - ConfigFileEntry.max_monitor = 60; - ConfigFileEntry.nick_delay = 900; /* 15 minutes */ - ConfigFileEntry.target_change = YES; - ConfigFileEntry.anti_spam_exit_message_time = 0; - ConfigFileEntry.use_part_messages = YES; - ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; - ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; - ConfigFileEntry.client_exit = YES; - ConfigFileEntry.dline_with_reason = YES; - ConfigFileEntry.kline_with_reason = YES; - ConfigFileEntry.kline_delay = 0; - ConfigFileEntry.warn_no_nline = YES; - ConfigFileEntry.non_redundant_klines = YES; - ConfigFileEntry.stats_e_disabled = NO; - ConfigFileEntry.stats_o_oper_only = NO; - ConfigFileEntry.stats_k_oper_only = 1; /* masked */ - ConfigFileEntry.stats_i_oper_only = 1; /* masked */ - ConfigFileEntry.stats_P_oper_only = NO; - ConfigFileEntry.stats_c_oper_only = NO; - ConfigFileEntry.stats_y_oper_only = NO; - ConfigFileEntry.stats_h_oper_only = NO; - ConfigFileEntry.map_oper_only = YES; - ConfigFileEntry.operspy_admin_only = NO; - ConfigFileEntry.pace_wait = 10; - ConfigFileEntry.caller_id_wait = 60; - ConfigFileEntry.pace_wait_simple = 1; - ConfigFileEntry.short_motd = NO; - ConfigFileEntry.no_oper_flood = NO; - ConfigFileEntry.true_no_oper_flood = NO; - ConfigFileEntry.fname_userlog = NULL; - ConfigFileEntry.fname_fuserlog = NULL; - ConfigFileEntry.fname_operlog = NULL; - ConfigFileEntry.fname_foperlog = NULL; - ConfigFileEntry.fname_serverlog = NULL; - ConfigFileEntry.fname_klinelog = NULL; - ConfigFileEntry.fname_operspylog = NULL; - ConfigFileEntry.fname_ioerrorlog = NULL; - ConfigFileEntry.use_egd = NO; - ConfigFileEntry.hide_spoof_ips = YES; - ConfigFileEntry.hide_error_messages = 1; - ConfigFileEntry.dots_in_ident = 0; - ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; - ConfigFileEntry.egdpool_path = NULL; - ConfigFileEntry.use_whois_actually = YES; - ConfigFileEntry.burst_away = NO; - ConfigFileEntry.collision_fnc = YES; - ConfigFileEntry.global_snotices = YES; - ConfigFileEntry.operspy_dont_care_user_info = NO; - ConfigFileEntry.use_propagated_bans = YES; - ConfigFileEntry.secret_channels_in_whois = NO; + ConfigFileEntry.default_umodes = UMODE_INVISIBLE; + ConfigFileEntry.failed_oper_notice = YES; + ConfigFileEntry.anti_nick_flood = NO; + ConfigFileEntry.disable_fake_channels = NO; + ConfigFileEntry.hide_channel_below_users = 3; + ConfigFileEntry.max_nick_time = 20; + ConfigFileEntry.max_nick_changes = 5; + ConfigFileEntry.max_accept = 20; + ConfigFileEntry.max_monitor = 60; + ConfigFileEntry.nick_delay = 900; /* 15 minutes */ + ConfigFileEntry.target_change = YES; + ConfigFileEntry.anti_spam_exit_message_time = 0; + ConfigFileEntry.use_part_messages = YES; + ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; + ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; + ConfigFileEntry.client_exit = YES; + ConfigFileEntry.dline_with_reason = YES; + ConfigFileEntry.kline_with_reason = YES; + ConfigFileEntry.kline_delay = 0; + ConfigFileEntry.warn_no_nline = YES; + ConfigFileEntry.non_redundant_klines = YES; + ConfigFileEntry.stats_e_disabled = NO; + ConfigFileEntry.stats_o_oper_only = NO; + ConfigFileEntry.stats_k_oper_only = 1; /* masked */ + ConfigFileEntry.stats_i_oper_only = 1; /* masked */ + ConfigFileEntry.stats_P_oper_only = NO; + ConfigFileEntry.stats_c_oper_only = NO; + ConfigFileEntry.stats_y_oper_only = NO; + ConfigFileEntry.stats_h_oper_only = NO; + ConfigFileEntry.map_oper_only = YES; + ConfigFileEntry.operspy_admin_only = NO; + ConfigFileEntry.pace_wait = 10; + ConfigFileEntry.caller_id_wait = 60; + ConfigFileEntry.pace_wait_simple = 1; + ConfigFileEntry.short_motd = NO; + ConfigFileEntry.no_oper_flood = NO; + ConfigFileEntry.true_no_oper_flood = NO; + ConfigFileEntry.fname_userlog = NULL; + ConfigFileEntry.fname_fuserlog = NULL; + ConfigFileEntry.fname_operlog = NULL; + ConfigFileEntry.fname_foperlog = NULL; + ConfigFileEntry.fname_serverlog = NULL; + ConfigFileEntry.fname_klinelog = NULL; + ConfigFileEntry.fname_operspylog = NULL; + ConfigFileEntry.fname_ioerrorlog = NULL; + ConfigFileEntry.use_egd = NO; + ConfigFileEntry.hide_spoof_ips = YES; + ConfigFileEntry.hide_error_messages = 1; + ConfigFileEntry.dots_in_ident = 0; + ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; + ConfigFileEntry.egdpool_path = NULL; + ConfigFileEntry.use_whois_actually = YES; + ConfigFileEntry.burst_away = NO; + ConfigFileEntry.collision_fnc = YES; + ConfigFileEntry.global_snotices = YES; + ConfigFileEntry.operspy_dont_care_user_info = NO; + ConfigFileEntry.use_propagated_bans = YES; + ConfigFileEntry.secret_channels_in_whois = NO; ConfigFileEntry.away_interval = 30; #ifdef HAVE_LIBZ - ConfigFileEntry.compression_level = 4; + ConfigFileEntry.compression_level = 4; #endif - ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE | - UMODE_OPERWALL | UMODE_WALLOP; - ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE; - ConfigFileEntry.oper_snomask = SNO_GENERAL; + ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE | + UMODE_OPERWALL | UMODE_WALLOP; + ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE; + ConfigFileEntry.oper_snomask = SNO_GENERAL; - ConfigChannel.autochanmodes = rb_strdup("nt"); - ConfigChannel.exemptchanops = rb_strdup(""); - ConfigChannel.disabledmodes = rb_strdup(""); - ConfigChannel.admin_on_channel_create = NO; - ConfigChannel.use_halfop = YES; - ConfigChannel.use_admin = YES; - ConfigChannel.use_owner = YES; - ConfigChannel.use_except = YES; - ConfigChannel.use_invex = YES; - ConfigChannel.use_knock = YES; - ConfigChannel.use_forward = YES; - ConfigChannel.use_local_channels = YES; - ConfigChannel.knock_delay = 300; - ConfigChannel.knock_delay_channel = 60; - ConfigChannel.max_chans_per_user = 15; - ConfigChannel.max_bans = 25; - ConfigChannel.max_bans_large = 500; - ConfigChannel.only_ascii_channels = NO; - ConfigChannel.cycle_host_change = YES; - ConfigChannel.host_in_topic = YES; - ConfigChannel.burst_topicwho = NO; - ConfigChannel.kick_on_split_riding = NO; + ConfigChannel.autochanmodes = rb_strdup("nt"); + ConfigChannel.exemptchanops = rb_strdup(""); + ConfigChannel.disabledmodes = rb_strdup(""); + ConfigChannel.admin_on_channel_create = NO; + ConfigChannel.use_halfop = YES; + ConfigChannel.use_admin = YES; + ConfigChannel.use_owner = YES; + ConfigChannel.use_except = YES; + ConfigChannel.use_invex = YES; + ConfigChannel.use_knock = YES; + ConfigChannel.use_forward = YES; + ConfigChannel.use_local_channels = YES; + ConfigChannel.knock_delay = 300; + ConfigChannel.knock_delay_channel = 60; + ConfigChannel.max_chans_per_user = 15; + ConfigChannel.max_bans = 25; + ConfigChannel.max_bans_large = 500; + ConfigChannel.only_ascii_channels = NO; + ConfigChannel.cycle_host_change = YES; + ConfigChannel.host_in_topic = YES; + ConfigChannel.burst_topicwho = NO; + ConfigChannel.kick_on_split_riding = NO; - ConfigChannel.default_split_user_count = 15000; - ConfigChannel.default_split_server_count = 10; - ConfigChannel.no_join_on_split = NO; - ConfigChannel.no_create_on_split = YES; - ConfigChannel.resv_forcepart = YES; - ConfigChannel.channel_target_change = YES; + ConfigChannel.default_split_user_count = 15000; + ConfigChannel.default_split_server_count = 10; + ConfigChannel.no_join_on_split = NO; + ConfigChannel.no_create_on_split = YES; + ConfigChannel.resv_forcepart = YES; + ConfigChannel.channel_target_change = YES; - ConfigChannel.exempt_cmode_c = NO; - ConfigChannel.exempt_cmode_C = NO; - ConfigChannel.exempt_cmode_D = NO; - ConfigChannel.exempt_cmode_T = NO; - ConfigChannel.exempt_cmode_N = NO; - ConfigChannel.exempt_cmode_G = NO; - ConfigChannel.exempt_cmode_K = NO; + ConfigChannel.exempt_cmode_c = NO; + ConfigChannel.exempt_cmode_C = NO; + ConfigChannel.exempt_cmode_D = NO; + ConfigChannel.exempt_cmode_T = NO; + ConfigChannel.exempt_cmode_N = NO; + ConfigChannel.exempt_cmode_G = NO; + ConfigChannel.exempt_cmode_K = NO; - ConfigServerHide.flatten_links = 0; - ConfigServerHide.links_delay = 300; - ConfigServerHide.hidden = 0; - ConfigServerHide.disable_hidden = 0; + ConfigServerHide.flatten_links = 0; + ConfigServerHide.links_delay = 300; + ConfigServerHide.hidden = 0; + ConfigServerHide.disable_hidden = 0; - ConfigFileEntry.min_nonwildcard = 4; - ConfigFileEntry.min_nonwildcard_simple = 3; - ConfigFileEntry.default_floodcount = 8; - ConfigFileEntry.default_ident_timeout = 5; - ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT; - ConfigFileEntry.tkline_expire_notices = 0; + ConfigFileEntry.min_nonwildcard = 4; + ConfigFileEntry.min_nonwildcard_simple = 3; + ConfigFileEntry.default_floodcount = 8; + ConfigFileEntry.default_ident_timeout = 5; + ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT; + ConfigFileEntry.tkline_expire_notices = 0; - ConfigFileEntry.reject_after_count = 5; - ConfigFileEntry.reject_ban_time = 300; - ConfigFileEntry.reject_duration = 120; - ConfigFileEntry.throttle_count = 4; - ConfigFileEntry.throttle_duration = 60; - ConfigFileEntry.expire_override_time = 300; + ConfigFileEntry.reject_after_count = 5; + ConfigFileEntry.reject_ban_time = 300; + ConfigFileEntry.reject_duration = 120; + ConfigFileEntry.throttle_count = 4; + ConfigFileEntry.throttle_duration = 60; + ConfigFileEntry.expire_override_time = 300; - ServerInfo.default_max_clients = MAXCONNECTIONS; + ServerInfo.default_max_clients = MAXCONNECTIONS; - if (!alias_dict) - alias_dict = irc_dictionary_create(strcasecmp); + if (!alias_dict) + alias_dict = irc_dictionary_create(strcasecmp); } #undef YES #undef NO /* - * read_conf() + * read_conf() * * * inputs - file descriptor pointing to config file to use @@ -843,269 +813,227 @@ set_default_conf(void) static void read_conf(FILE * file) { - lineno = 0; + lineno = 0; - set_default_conf(); /* Set default values prior to conf parsing */ - yyparse(); /* Load the values from the conf */ - validate_conf(); /* Check to make sure some values are still okay. */ - /* Some global values are also loaded here. */ - check_class(); /* Make sure classes are valid */ - privilegeset_delete_all_illegal(); + set_default_conf(); /* Set default values prior to conf parsing */ + yyparse(); /* Load the values from the conf */ + validate_conf(); /* Check to make sure some values are still okay. */ + /* Some global values are also loaded here. */ + check_class(); /* Make sure classes are valid */ + privilegeset_delete_all_illegal(); } static void validate_conf(void) { - if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) - ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; + if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) + ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; - if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) - ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; + if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) + ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; - if(ServerInfo.network_name == NULL) - ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); + if(ServerInfo.network_name == NULL) + ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); - if(ServerInfo.network_desc == NULL) - ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); + if(ServerInfo.network_desc == NULL) + ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); - if(ServerInfo.ssld_count < 1) - ServerInfo.ssld_count = 1; + if(ServerInfo.ssld_count < 1) + ServerInfo.ssld_count = 1; - if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params)) - { - ilog(L_MAIN, "WARNING: Unable to setup SSL."); - ssl_ok = 0; - } else { - ssl_ok = 1; - send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); - } + if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params)) { + ilog(L_MAIN, "WARNING: Unable to setup SSL."); + ssl_ok = 0; + } else { + ssl_ok = 1; + send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); + } - if(ServerInfo.ssld_count > get_ssld_count()) - { - int start = ServerInfo.ssld_count - get_ssld_count(); - /* start up additional ssld if needed */ - start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); - - } + if(ServerInfo.ssld_count > get_ssld_count()) { + int start = ServerInfo.ssld_count - get_ssld_count(); + /* start up additional ssld if needed */ + start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); - if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) || - (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX)) - ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX; + } - if(!split_users || !split_servers || - (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split)) - { - rb_event_delete(check_splitmode_ev); - check_splitmode_ev = NULL; - splitmode = 0; - splitchecking = 0; - } + if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) || + (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX)) + ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX; - if(!valid_hostname(ConfigFileEntry.default_operhost) && !EmptyString(ConfigFileEntry.default_operhost)) - { - conf_report_error("Warning -- invalid default_operhost specified, ignoring."); - ConfigFileEntry.default_operhost = rb_strdup(""); - } + if(!split_users || !split_servers || + (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split)) { + rb_event_delete(check_splitmode_ev); + check_splitmode_ev = NULL; + splitmode = 0; + splitchecking = 0; + } - /* Parse the exemptchanops option and set the internal variables - * that we will use. */ - char * ech; + if(!valid_hostname(ConfigFileEntry.default_operhost) && !EmptyString(ConfigFileEntry.default_operhost)) { + conf_report_error("Warning -- invalid default_operhost specified, ignoring."); + ConfigFileEntry.default_operhost = rb_strdup(""); + } - for(ech = ConfigChannel.exemptchanops; *ech; ech++) - { - if(*ech == 'c') - { - ConfigChannel.exempt_cmode_c = 1; - continue; - } - if(*ech == 'C') - { - ConfigChannel.exempt_cmode_C = 1; - continue; - } - if(*ech == 'D') - { - ConfigChannel.exempt_cmode_D = 1; - continue; - } - if(*ech == 'T') - { - ConfigChannel.exempt_cmode_T = 1; - continue; - } - if(*ech == 'N') - { - ConfigChannel.exempt_cmode_N = 1; - continue; - } - if(*ech == 'G') - { - ConfigChannel.exempt_cmode_G = 1; - continue; - } - if(*ech == 'K') - ConfigChannel.exempt_cmode_K = 1; - } + /* Parse the exemptchanops option and set the internal variables + * that we will use. */ + char * ech; - /* orphan any modes specified in channel::disabledmodes */ - char * dm; + for(ech = ConfigChannel.exemptchanops; *ech; ech++) { + if(*ech == 'c') { + ConfigChannel.exempt_cmode_c = 1; + continue; + } + if(*ech == 'C') { + ConfigChannel.exempt_cmode_C = 1; + continue; + } + if(*ech == 'D') { + ConfigChannel.exempt_cmode_D = 1; + continue; + } + if(*ech == 'T') { + ConfigChannel.exempt_cmode_T = 1; + continue; + } + if(*ech == 'N') { + ConfigChannel.exempt_cmode_N = 1; + continue; + } + if(*ech == 'G') { + ConfigChannel.exempt_cmode_G = 1; + continue; + } + if(*ech == 'K') + ConfigChannel.exempt_cmode_K = 1; + } - if(startup && !EmptyString(ConfigChannel.disabledmodes)) - { - for(dm = ConfigChannel.disabledmodes; *dm; dm++) - { - if(*dm == 'C') - { - cflag_orphan('C'); - continue; - } - if(*dm == 'r') - { - cflag_orphan('r'); - continue; - } - if(*dm == 'c') - { - cflag_orphan('c'); - continue; - } - if(*dm == 'L') - { - cflag_orphan('L'); - continue; - } - if(*dm == 'P') - { - cflag_orphan('P'); - continue; - } - if(*dm == 'z') - { - cflag_orphan('z'); - continue; - } - if(*dm == 'g') - { - cflag_orphan('g'); - continue; - } - if(*dm == 'F') - { - cflag_orphan('F'); - continue; - } - if(*dm == 'Q') - { - cflag_orphan('Q'); - continue; - } - if(*dm == 'q') - { - cflag_orphan('q'); - continue; - } - if(*dm == 'I') - { - cflag_orphan('I'); - ConfigChannel.use_invex = 0; - continue; - } - if(*dm == 'e') - { - cflag_orphan('e'); - ConfigChannel.use_except = 0; - continue; - } - if(*dm == 'f') - { - cflag_orphan('f'); - ConfigChannel.use_forward = 0; - continue; - } - if(*dm == 'j') - { - cflag_orphan('j'); - continue; - } - if(*dm == 'T') - { - cflag_orphan('T'); - continue; - } - if(*dm == 'D') - { - cflag_orphan('D'); - continue; - } - if(*dm == 'E') - { - cflag_orphan('E'); - continue; - } - if(*dm == 'N') - { - cflag_orphan('N'); - continue; - } - if(*dm == 'G') - { - cflag_orphan('G'); - continue; - } - if(*dm == 'J') - { - cflag_orphan('J'); - continue; - } - if(*dm == 'K') - { - cflag_orphan('K'); - continue; - } - if(*dm == 'M') - { - cflag_orphan('M'); - continue; - } - } - } - construct_cflag_param_string(); - startup = 0; + /* orphan any modes specified in channel::disabledmodes */ + char * dm; + + if(startup && !EmptyString(ConfigChannel.disabledmodes)) { + for(dm = ConfigChannel.disabledmodes; *dm; dm++) { + if(*dm == 'C') { + cflag_orphan('C'); + continue; + } + if(*dm == 'r') { + cflag_orphan('r'); + continue; + } + if(*dm == 'c') { + cflag_orphan('c'); + continue; + } + if(*dm == 'L') { + cflag_orphan('L'); + continue; + } + if(*dm == 'P') { + cflag_orphan('P'); + continue; + } + if(*dm == 'z') { + cflag_orphan('z'); + continue; + } + if(*dm == 'g') { + cflag_orphan('g'); + continue; + } + if(*dm == 'F') { + cflag_orphan('F'); + continue; + } + if(*dm == 'Q') { + cflag_orphan('Q'); + continue; + } + if(*dm == 'q') { + cflag_orphan('q'); + continue; + } + if(*dm == 'I') { + cflag_orphan('I'); + ConfigChannel.use_invex = 0; + continue; + } + if(*dm == 'e') { + cflag_orphan('e'); + ConfigChannel.use_except = 0; + continue; + } + if(*dm == 'f') { + cflag_orphan('f'); + ConfigChannel.use_forward = 0; + continue; + } + if(*dm == 'j') { + cflag_orphan('j'); + continue; + } + if(*dm == 'T') { + cflag_orphan('T'); + continue; + } + if(*dm == 'D') { + cflag_orphan('D'); + continue; + } + if(*dm == 'E') { + cflag_orphan('E'); + continue; + } + if(*dm == 'N') { + cflag_orphan('N'); + continue; + } + if(*dm == 'G') { + cflag_orphan('G'); + continue; + } + if(*dm == 'J') { + cflag_orphan('J'); + continue; + } + if(*dm == 'K') { + cflag_orphan('K'); + continue; + } + if(*dm == 'M') { + cflag_orphan('M'); + continue; + } + } + } + construct_cflag_param_string(); + startup = 0; } /* add_temp_kline() * * inputs - pointer to struct ConfItem * output - none - * Side effects - links in given struct ConfItem into + * Side effects - links in given struct ConfItem into * temporary kline link list */ void add_temp_kline(struct ConfItem *aconf) { - if(aconf->hold >= rb_current_time() + (10080 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); - aconf->port = TEMP_WEEK; - } - else if(aconf->hold >= rb_current_time() + (1440 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); - aconf->port = TEMP_DAY; - } - else if(aconf->hold >= rb_current_time() + (60 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); - aconf->port = TEMP_HOUR; - } - else - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]); - aconf->port = TEMP_MIN; - } + if(aconf->hold >= rb_current_time() + (10080 * 60)) { + rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); + aconf->port = TEMP_WEEK; + } else if(aconf->hold >= rb_current_time() + (1440 * 60)) { + rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); + aconf->port = TEMP_DAY; + } else if(aconf->hold >= rb_current_time() + (60 * 60)) { + rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); + aconf->port = TEMP_HOUR; + } else { + rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]); + aconf->port = TEMP_MIN; + } - aconf->flags |= CONF_FLAGS_TEMPORARY; - add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); + aconf->flags |= CONF_FLAGS_TEMPORARY; + add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); } /* add_temp_dline() @@ -1117,33 +1045,26 @@ add_temp_kline(struct ConfItem *aconf) void add_temp_dline(struct ConfItem *aconf) { - if(aconf->hold >= rb_current_time() + (10080 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); - aconf->port = TEMP_WEEK; - } - else if(aconf->hold >= rb_current_time() + (1440 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); - aconf->port = TEMP_DAY; - } - else if(aconf->hold >= rb_current_time() + (60 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); - aconf->port = TEMP_HOUR; - } - else - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]); - aconf->port = TEMP_MIN; - } + if(aconf->hold >= rb_current_time() + (10080 * 60)) { + rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); + aconf->port = TEMP_WEEK; + } else if(aconf->hold >= rb_current_time() + (1440 * 60)) { + rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); + aconf->port = TEMP_DAY; + } else if(aconf->hold >= rb_current_time() + (60 * 60)) { + rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); + aconf->port = TEMP_HOUR; + } else { + rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]); + aconf->port = TEMP_MIN; + } - aconf->flags |= CONF_FLAGS_TEMPORARY; - add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); + aconf->flags |= CONF_FLAGS_TEMPORARY; + add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); } /* valid_wild_card() - * + * * input - user buffer, host buffer * output - 0 if invalid, 1 if valid * side effects - @@ -1151,120 +1072,111 @@ add_temp_dline(struct ConfItem *aconf) int valid_wild_card(const char *luser, const char *lhost) { - const char *p; - char tmpch; - int nonwild = 0; - int bitlen; + const char *p; + char tmpch; + int nonwild = 0; + int bitlen; - /* user has no wildcards, always accept -- jilles */ - if(!strchr(luser, '?') && !strchr(luser, '*')) - return 1; + /* user has no wildcards, always accept -- jilles */ + if(!strchr(luser, '?') && !strchr(luser, '*')) + return 1; - /* check there are enough non wildcard chars */ - p = luser; - while((tmpch = *p++)) - { - if(!IsKWildChar(tmpch)) - { - /* found enough chars, return */ - if(++nonwild >= ConfigFileEntry.min_nonwildcard) - return 1; - } - } + /* check there are enough non wildcard chars */ + p = luser; + while((tmpch = *p++)) { + if(!IsKWildChar(tmpch)) { + /* found enough chars, return */ + if(++nonwild >= ConfigFileEntry.min_nonwildcard) + return 1; + } + } - /* try host, as user didnt contain enough */ - /* special case for cidr masks -- jilles */ - if((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1])) - { - bitlen = atoi(p + 1); - /* much like non-cidr for ipv6, rather arbitrary for ipv4 */ - if(bitlen > 0 - && bitlen >= - (strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 - - 2 * nonwild)) - return 1; - } - else - { - p = lhost; - while((tmpch = *p++)) - { - if(!IsKWildChar(tmpch)) - if(++nonwild >= ConfigFileEntry.min_nonwildcard) - return 1; - } - } + /* try host, as user didnt contain enough */ + /* special case for cidr masks -- jilles */ + if((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1])) { + bitlen = atoi(p + 1); + /* much like non-cidr for ipv6, rather arbitrary for ipv4 */ + if(bitlen > 0 + && bitlen >= + (strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 - + 2 * nonwild)) + return 1; + } else { + p = lhost; + while((tmpch = *p++)) { + if(!IsKWildChar(tmpch)) + if(++nonwild >= ConfigFileEntry.min_nonwildcard) + return 1; + } + } - return 0; + return 0; } rb_dlink_node * find_prop_ban(unsigned int status, const char *user, const char *host) { - rb_dlink_node *ptr; - struct ConfItem *aconf; + rb_dlink_node *ptr; + struct ConfItem *aconf; - RB_DLINK_FOREACH(ptr, prop_bans.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, prop_bans.head) { + aconf = ptr->data; - if((aconf->status & ~CONF_ILLEGAL) == status && - (!user || !aconf->user || - !irccmp(aconf->user, user)) && - !irccmp(aconf->host, host)) - return ptr; - } - return NULL; + if((aconf->status & ~CONF_ILLEGAL) == status && + (!user || !aconf->user || + !irccmp(aconf->user, user)) && + !irccmp(aconf->host, host)) + return ptr; + } + return NULL; } void deactivate_conf(struct ConfItem *aconf, rb_dlink_node *ptr) { - int i; + int i; - s_assert(ptr->data == aconf); + s_assert(ptr->data == aconf); - switch (aconf->status) - { - case CONF_KILL: - if (aconf->lifetime == 0 && - aconf->flags & CONF_FLAGS_TEMPORARY) - for (i = 0; i < LAST_TEMP_TYPE; i++) - rb_dlinkFindDestroy(aconf, &temp_klines[i]); - /* Make sure delete_one_address_conf() does not - * free the aconf. - */ - aconf->clients++; - delete_one_address_conf(aconf->host, aconf); - aconf->clients--; - break; - case CONF_DLINE: - if (aconf->lifetime == 0 && - aconf->flags & CONF_FLAGS_TEMPORARY) - for (i = 0; i < LAST_TEMP_TYPE; i++) - rb_dlinkFindDestroy(aconf, &temp_dlines[i]); - aconf->clients++; - delete_one_address_conf(aconf->host, aconf); - aconf->clients--; - break; - case CONF_XLINE: - rb_dlinkFindDestroy(aconf, &xline_conf_list); - break; - case CONF_RESV_NICK: - rb_dlinkFindDestroy(aconf, &resv_conf_list); - break; - case CONF_RESV_CHANNEL: - del_from_resv_hash(aconf->host, aconf); - break; - } - if (aconf->lifetime != 0 && rb_current_time() < aconf->lifetime) - aconf->status |= CONF_ILLEGAL; - else - { - if (aconf->lifetime != 0) - rb_dlinkDestroy(ptr, &prop_bans); - free_conf(aconf); - } + switch (aconf->status) { + case CONF_KILL: + if (aconf->lifetime == 0 && + aconf->flags & CONF_FLAGS_TEMPORARY) + for (i = 0; i < LAST_TEMP_TYPE; i++) + rb_dlinkFindDestroy(aconf, &temp_klines[i]); + /* Make sure delete_one_address_conf() does not + * free the aconf. + */ + aconf->clients++; + delete_one_address_conf(aconf->host, aconf); + aconf->clients--; + break; + case CONF_DLINE: + if (aconf->lifetime == 0 && + aconf->flags & CONF_FLAGS_TEMPORARY) + for (i = 0; i < LAST_TEMP_TYPE; i++) + rb_dlinkFindDestroy(aconf, &temp_dlines[i]); + aconf->clients++; + delete_one_address_conf(aconf->host, aconf); + aconf->clients--; + break; + case CONF_XLINE: + rb_dlinkFindDestroy(aconf, &xline_conf_list); + break; + case CONF_RESV_NICK: + rb_dlinkFindDestroy(aconf, &resv_conf_list); + break; + case CONF_RESV_CHANNEL: + del_from_resv_hash(aconf->host, aconf); + break; + } + if (aconf->lifetime != 0 && rb_current_time() < aconf->lifetime) + aconf->status |= CONF_ILLEGAL; + else { + if (aconf->lifetime != 0) + rb_dlinkDestroy(ptr, &prop_bans); + free_conf(aconf); + } } /* Given a new ban ConfItem, look for any matching ban, update the lifetime @@ -1273,59 +1185,56 @@ deactivate_conf(struct ConfItem *aconf, rb_dlink_node *ptr) void replace_old_ban(struct ConfItem *aconf) { - rb_dlink_node *ptr; - struct ConfItem *oldconf; + rb_dlink_node *ptr; + struct ConfItem *oldconf; - ptr = find_prop_ban(aconf->status, aconf->user, aconf->host); - if(ptr != NULL) - { - oldconf = ptr->data; - /* Remember at least as long as the old one. */ - if(oldconf->lifetime > aconf->lifetime) - aconf->lifetime = oldconf->lifetime; - /* Force creation time to increase. */ - if(oldconf->created >= aconf->created) - aconf->created = oldconf->created + 1; - /* Leave at least one second of validity. */ - if(aconf->hold <= aconf->created) - aconf->hold = aconf->created + 1; - if(aconf->lifetime < aconf->hold) - aconf->lifetime = aconf->hold; - /* Tell deactivate_conf() to destroy it. */ - oldconf->lifetime = rb_current_time(); - deactivate_conf(oldconf, ptr); - } + ptr = find_prop_ban(aconf->status, aconf->user, aconf->host); + if(ptr != NULL) { + oldconf = ptr->data; + /* Remember at least as long as the old one. */ + if(oldconf->lifetime > aconf->lifetime) + aconf->lifetime = oldconf->lifetime; + /* Force creation time to increase. */ + if(oldconf->created >= aconf->created) + aconf->created = oldconf->created + 1; + /* Leave at least one second of validity. */ + if(aconf->hold <= aconf->created) + aconf->hold = aconf->created + 1; + if(aconf->lifetime < aconf->hold) + aconf->lifetime = aconf->hold; + /* Tell deactivate_conf() to destroy it. */ + oldconf->lifetime = rb_current_time(); + deactivate_conf(oldconf, ptr); + } } static void expire_prop_bans(void *list) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct ConfItem *aconf; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) { + aconf = ptr->data; - if(aconf->lifetime <= rb_current_time() || - (aconf->hold <= rb_current_time() && - !(aconf->status & CONF_ILLEGAL))) - { - /* Alert opers that a TKline expired - Hwy */ - /* XXX show what type of ban it is */ - if(ConfigFileEntry.tkline_expire_notices && - !(aconf->status & CONF_ILLEGAL)) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Propagated ban for [%s%s%s] expired", - aconf->user ? aconf->user : "", - aconf->user ? "@" : "", - aconf->host ? aconf->host : "*"); + if(aconf->lifetime <= rb_current_time() || + (aconf->hold <= rb_current_time() && + !(aconf->status & CONF_ILLEGAL))) { + /* Alert opers that a TKline expired - Hwy */ + /* XXX show what type of ban it is */ + if(ConfigFileEntry.tkline_expire_notices && + !(aconf->status & CONF_ILLEGAL)) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Propagated ban for [%s%s%s] expired", + aconf->user ? aconf->user : "", + aconf->user ? "@" : "", + aconf->host ? aconf->host : "*"); - /* will destroy or mark illegal */ - deactivate_conf(aconf, ptr); - } - } + /* will destroy or mark illegal */ + deactivate_conf(aconf, ptr); + } + } } /* expire_tkline() @@ -1338,62 +1247,53 @@ expire_prop_bans(void *list) static void expire_temp_kd(void *list) { - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + struct ConfItem *aconf; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) { + aconf = ptr->data; - if(aconf->hold <= rb_current_time()) - { - /* Alert opers that a TKline expired - Hwy */ - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Temporary K-line for [%s@%s] expired", - (aconf->user) ? aconf-> - user : "*", (aconf->host) ? aconf->host : "*"); + if(aconf->hold <= rb_current_time()) { + /* Alert opers that a TKline expired - Hwy */ + if(ConfigFileEntry.tkline_expire_notices) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Temporary K-line for [%s@%s] expired", + (aconf->user) ? aconf-> + user : "*", (aconf->host) ? aconf->host : "*"); - delete_one_address_conf(aconf->host, aconf); - rb_dlinkDestroy(ptr, list); - } - } + delete_one_address_conf(aconf->host, aconf); + rb_dlinkDestroy(ptr, list); + } + } } static void reorganise_temp_kd(void *list) { - struct ConfItem *aconf; - rb_dlink_node *ptr, *next_ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) { + aconf = ptr->data; - if(aconf->hold < (rb_current_time() + (60 * 60))) - { - rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? - &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]); - aconf->port = TEMP_MIN; - } - else if(aconf->port > TEMP_HOUR) - { - if(aconf->hold < (rb_current_time() + (1440 * 60))) - { - rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? - &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]); - aconf->port = TEMP_HOUR; - } - else if(aconf->port > TEMP_DAY && - (aconf->hold < (rb_current_time() + (10080 * 60)))) - { - rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? - &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]); - aconf->port = TEMP_DAY; - } - } - } + if(aconf->hold < (rb_current_time() + (60 * 60))) { + rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? + &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]); + aconf->port = TEMP_MIN; + } else if(aconf->port > TEMP_HOUR) { + if(aconf->hold < (rb_current_time() + (1440 * 60))) { + rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? + &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]); + aconf->port = TEMP_HOUR; + } else if(aconf->port > TEMP_DAY && + (aconf->hold < (rb_current_time() + (10080 * 60)))) { + rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? + &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]); + aconf->port = TEMP_DAY; + } + } + } } @@ -1406,21 +1306,20 @@ reorganise_temp_kd(void *list) char * get_oper_name(struct Client *client_p) { - /* +5 for !,@,{,} and null */ - static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; + /* +5 for !,@,{,} and null */ + static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; - if(MyOper(client_p)) - { - rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", - client_p->name, client_p->username, - client_p->host, client_p->localClient->opername); - return buffer; - } + if(MyOper(client_p)) { + rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", + client_p->name, client_p->username, + client_p->host, client_p->localClient->opername); + return buffer; + } - rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", - client_p->name, client_p->username, - client_p->host, client_p->servptr->name); - return buffer; + rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", + client_p->name, client_p->username, + client_p->host, client_p->servptr->name); + return buffer; } /* @@ -1428,7 +1327,7 @@ get_oper_name(struct Client *client_p) * * inputs - struct ConfItem * - * output - name + * output - name * - host * - pass * - user @@ -1441,68 +1340,66 @@ get_oper_name(struct Client *client_p) */ void get_printable_conf(struct ConfItem *aconf, char **name, char **host, - char **pass, char **user, int *port, char **classname) + char **pass, char **user, int *port, char **classname) { - static char null[] = ""; - static char zero[] = "default"; + static char null[] = ""; + static char zero[] = "default"; - *name = EmptyString(aconf->info.name) ? null : aconf->info.name; - *host = EmptyString(aconf->host) ? null : aconf->host; - *pass = EmptyString(aconf->passwd) ? null : aconf->passwd; - *user = EmptyString(aconf->user) ? null : aconf->user; - *classname = EmptyString(aconf->className) ? zero : aconf->className; - *port = (int) aconf->port; + *name = EmptyString(aconf->info.name) ? null : aconf->info.name; + *host = EmptyString(aconf->host) ? null : aconf->host; + *pass = EmptyString(aconf->passwd) ? null : aconf->passwd; + *user = EmptyString(aconf->user) ? null : aconf->user; + *classname = EmptyString(aconf->className) ? zero : aconf->className; + *port = (int) aconf->port; } char * get_user_ban_reason(struct ConfItem *aconf) { - static char reasonbuf[BUFSIZE]; + static char reasonbuf[BUFSIZE]; - if (aconf->flags & CONF_FLAGS_TEMPORARY && - (aconf->status == CONF_KILL || aconf->status == CONF_DLINE)) - rb_snprintf(reasonbuf, sizeof reasonbuf, - "Temporary %c-line %d min. - ", - aconf->status == CONF_DLINE ? 'D' : 'K', - (int)((aconf->hold - aconf->created) / 60)); - else - reasonbuf[0] = '\0'; - if (aconf->passwd) - rb_strlcat(reasonbuf, aconf->passwd, sizeof reasonbuf); - else - rb_strlcat(reasonbuf, "No Reason", sizeof reasonbuf); - if (aconf->created) - { - rb_strlcat(reasonbuf, " (", sizeof reasonbuf); - rb_strlcat(reasonbuf, smalldate(aconf->created), - sizeof reasonbuf); - rb_strlcat(reasonbuf, ")", sizeof reasonbuf); - } - return reasonbuf; + if (aconf->flags & CONF_FLAGS_TEMPORARY && + (aconf->status == CONF_KILL || aconf->status == CONF_DLINE)) + rb_snprintf(reasonbuf, sizeof reasonbuf, + "Temporary %c-line %d min. - ", + aconf->status == CONF_DLINE ? 'D' : 'K', + (int)((aconf->hold - aconf->created) / 60)); + else + reasonbuf[0] = '\0'; + if (aconf->passwd) + rb_strlcat(reasonbuf, aconf->passwd, sizeof reasonbuf); + else + rb_strlcat(reasonbuf, "No Reason", sizeof reasonbuf); + if (aconf->created) { + rb_strlcat(reasonbuf, " (", sizeof reasonbuf); + rb_strlcat(reasonbuf, smalldate(aconf->created), + sizeof reasonbuf); + rb_strlcat(reasonbuf, ")", sizeof reasonbuf); + } + return reasonbuf; } void -get_printable_kline(struct Client *source_p, struct ConfItem *aconf, - char **host, char **reason, - char **user, char **oper_reason) +get_printable_kline(struct Client *source_p, struct ConfItem *aconf, + char **host, char **reason, + char **user, char **oper_reason) { - static char null[] = ""; - static char operreasonbuf[BUFSIZE]; + static char null[] = ""; + static char operreasonbuf[BUFSIZE]; - *host = EmptyString(aconf->host) ? null : aconf->host; - *user = EmptyString(aconf->user) ? null : aconf->user; - *reason = get_user_ban_reason(aconf); + *host = EmptyString(aconf->host) ? null : aconf->host; + *user = EmptyString(aconf->user) ? null : aconf->user; + *reason = get_user_ban_reason(aconf); - if(!IsOper(source_p)) - *oper_reason = NULL; - else - { - rb_snprintf(operreasonbuf, sizeof operreasonbuf, "%s%s(%s)", - EmptyString(aconf->spasswd) ? "" : aconf->spasswd, - EmptyString(aconf->spasswd) ? "" : " ", - aconf->info.oper); - *oper_reason = operreasonbuf; - } + if(!IsOper(source_p)) + *oper_reason = NULL; + else { + rb_snprintf(operreasonbuf, sizeof operreasonbuf, "%s%s(%s)", + EmptyString(aconf->spasswd) ? "" : aconf->spasswd, + EmptyString(aconf->spasswd) ? "" : " ", + aconf->info.oper); + *oper_reason = operreasonbuf; + } } /* @@ -1515,26 +1412,24 @@ get_printable_kline(struct Client *source_p, struct ConfItem *aconf, void read_conf_files(int cold) { - const char *filename; + const char *filename; - conf_fbfile_in = NULL; + conf_fbfile_in = NULL; - filename = ConfigFileEntry.configfile; + filename = ConfigFileEntry.configfile; - /* We need to know the initial filename for the yyerror() to report - FIXME: The full path is in conffilenamebuf first time since we - dont know anything else + /* We need to know the initial filename for the yyerror() to report + FIXME: The full path is in conffilenamebuf first time since we + dont know anything else - - Gozem 2002-07-21 - */ - rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf)); + - Gozem 2002-07-21 + */ + rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf)); - if((conf_fbfile_in = fopen(filename, "r")) == NULL) - { - if(cold) - { + if((conf_fbfile_in = fopen(filename, "r")) == NULL) { + if(cold) { inotice("Failed in reading configuration file %s, aborting", filename); - ilog(L_MAIN, "Failed in reading configuration file %s", filename); + ilog(L_MAIN, "Failed in reading configuration file %s", filename); int e; e = errno; @@ -1542,23 +1437,20 @@ read_conf_files(int cold) inotice("FATAL: %s %s", strerror(e), filename); ilog(L_MAIN, "FATAL: %s %s", strerror(e), filename); - exit(-1); - } - else - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Can't open file '%s' - aborting rehash!", filename); - return; - } - } + exit(-1); + } else { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Can't open file '%s' - aborting rehash!", filename); + return; + } + } - if(!cold) - { - clear_out_old_conf(); - } + if(!cold) { + clear_out_old_conf(); + } - read_conf(conf_fbfile_in); - fclose(conf_fbfile_in); + read_conf(conf_fbfile_in); + fclose(conf_fbfile_in); } /* @@ -1567,11 +1459,11 @@ read_conf_files(int cold) static void free_alias_cb(struct DictionaryElement *ptr, void *unused) { - struct alias_entry *aptr = ptr->data; + struct alias_entry *aptr = ptr->data; - rb_free(aptr->name); - rb_free(aptr->target); - rb_free(aptr); + rb_free(aptr->name); + rb_free(aptr->target); + rb_free(aptr); } /* @@ -1584,82 +1476,79 @@ free_alias_cb(struct DictionaryElement *ptr, void *unused) static void clear_out_old_conf(void) { - struct Class *cltmp; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct Class *cltmp; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - /* - * don't delete the class table, rather mark all entries - * for deletion. The table is cleaned up by check_class. - avalon - */ - RB_DLINK_FOREACH(ptr, class_list.head) - { - cltmp = ptr->data; - MaxUsers(cltmp) = -1; - } + /* + * don't delete the class table, rather mark all entries + * for deletion. The table is cleaned up by check_class. - avalon + */ + RB_DLINK_FOREACH(ptr, class_list.head) { + cltmp = ptr->data; + MaxUsers(cltmp) = -1; + } - clear_out_address_conf(); - clear_s_newconf(); + clear_out_address_conf(); + clear_s_newconf(); - /* clean out module paths */ + /* clean out module paths */ #ifndef STATIC_MODULES - mod_clear_paths(); - mod_add_path(MODULE_DIR); - mod_add_path(MODULE_DIR "/autoload"); + mod_clear_paths(); + mod_add_path(MODULE_DIR); + mod_add_path(MODULE_DIR "/autoload"); #endif - /* clean out ServerInfo */ - rb_free(ServerInfo.description); - ServerInfo.description = NULL; - rb_free(ServerInfo.network_name); - ServerInfo.network_name = NULL; - rb_free(ServerInfo.network_desc); - ServerInfo.network_desc = NULL; - rb_free(ServerInfo.helpchan); - ServerInfo.helpchan = NULL; - rb_free(ServerInfo.helpurl); - ServerInfo.helpurl = NULL; + /* clean out ServerInfo */ + rb_free(ServerInfo.description); + ServerInfo.description = NULL; + rb_free(ServerInfo.network_name); + ServerInfo.network_name = NULL; + rb_free(ServerInfo.network_desc); + ServerInfo.network_desc = NULL; + rb_free(ServerInfo.helpchan); + ServerInfo.helpchan = NULL; + rb_free(ServerInfo.helpurl); + ServerInfo.helpurl = NULL; - ServerInfo.ssld_count = 1; + ServerInfo.ssld_count = 1; - /* clean out AdminInfo */ - rb_free(AdminInfo.name); - AdminInfo.name = NULL; - rb_free(AdminInfo.email); - AdminInfo.email = NULL; - rb_free(AdminInfo.description); - AdminInfo.description = NULL; + /* clean out AdminInfo */ + rb_free(AdminInfo.name); + AdminInfo.name = NULL; + rb_free(AdminInfo.email); + AdminInfo.email = NULL; + rb_free(AdminInfo.description); + AdminInfo.description = NULL; - /* operator{} and class{} blocks are freed above */ - /* clean out listeners */ - close_listeners(); + /* operator{} and class{} blocks are freed above */ + /* clean out listeners */ + close_listeners(); - /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{} - * and gecos{} blocks are freed above too - */ + /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{} + * and gecos{} blocks are freed above too + */ - /* clean out general */ - rb_free(ConfigFileEntry.kline_reason); - ConfigFileEntry.kline_reason = NULL; + /* clean out general */ + rb_free(ConfigFileEntry.kline_reason); + ConfigFileEntry.kline_reason = NULL; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) - { - rb_free(ptr->data); - rb_dlinkDestroy(ptr, &service_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) { + rb_free(ptr->data); + rb_dlinkDestroy(ptr, &service_list); + } - /* remove any aliases... -- nenolod */ - if (alias_dict != NULL) - { - irc_dictionary_destroy(alias_dict, free_alias_cb, NULL); - alias_dict = NULL; - } + /* remove any aliases... -- nenolod */ + if (alias_dict != NULL) { + irc_dictionary_destroy(alias_dict, free_alias_cb, NULL); + alias_dict = NULL; + } - destroy_blacklists(); + destroy_blacklists(); - privilegeset_mark_all_illegal(); + privilegeset_mark_all_illegal(); - /* OK, that should be everything... */ + /* OK, that should be everything... */ } @@ -1667,42 +1556,38 @@ clear_out_old_conf(void) * conf_add_class_to_conf * inputs - pointer to config item * output - NONE - * side effects - Add a class pointer to a conf + * side effects - Add a class pointer to a conf */ void conf_add_class_to_conf(struct ConfItem *aconf) { - if(aconf->className == NULL) - { - aconf->className = rb_strdup("default"); - ClassPtr(aconf) = default_class; - return; - } + if(aconf->className == NULL) { + aconf->className = rb_strdup("default"); + ClassPtr(aconf) = default_class; + return; + } - ClassPtr(aconf) = find_class(aconf->className); + ClassPtr(aconf) = find_class(aconf->className); - if(ClassPtr(aconf) == default_class) - { - if(aconf->status == CONF_CLIENT) - { - conf_report_error( - "Using default class for missing class \"%s\" in auth{} for %s@%s", - aconf->className, aconf->user, aconf->host); - } + if(ClassPtr(aconf) == default_class) { + if(aconf->status == CONF_CLIENT) { + conf_report_error( + "Using default class for missing class \"%s\" in auth{} for %s@%s", + aconf->className, aconf->user, aconf->host); + } - rb_free(aconf->className); - aconf->className = rb_strdup("default"); - return; - } + rb_free(aconf->className); + aconf->className = rb_strdup("default"); + return; + } - if(ConfMaxUsers(aconf) < 0) - { - ClassPtr(aconf) = default_class; - rb_free(aconf->className); - aconf->className = rb_strdup("default"); - return; - } + if(ConfMaxUsers(aconf) < 0) { + ClassPtr(aconf) = default_class; + rb_free(aconf->className); + aconf->className = rb_strdup("default"); + return; + } } /* @@ -1714,43 +1599,39 @@ conf_add_class_to_conf(struct ConfItem *aconf) void conf_add_d_conf(struct ConfItem *aconf) { - if(aconf->host == NULL) - return; + if(aconf->host == NULL) + return; - aconf->user = NULL; + aconf->user = NULL; - /* XXX - Should 'd' ever be in the old conf? For new conf we don't - * need this anyway, so I will disable it for now... -A1kmm - */ + /* XXX - Should 'd' ever be in the old conf? For new conf we don't + * need this anyway, so I will disable it for now... -A1kmm + */ - if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST) - { - ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host); - free_conf(aconf); - } - else - { - add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); - } + if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST) { + ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host); + free_conf(aconf); + } else { + add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); + } } static char * strip_tabs(char *dest, const char *src, size_t len) { - char *d = dest; + char *d = dest; - if(dest == NULL || src == NULL) - return NULL; + if(dest == NULL || src == NULL) + return NULL; - rb_strlcpy(dest, src, len); + rb_strlcpy(dest, src, len); - while(*d) - { - if(*d == '\t') - *d = ' '; - d++; - } - return dest; + while(*d) { + if(*d == '\t') + *d = ' '; + d++; + } + return dest; } /* @@ -1763,27 +1644,27 @@ strip_tabs(char *dest, const char *src, size_t len) void yyerror(const char *msg) { - char newlinebuf[BUFSIZE]; + char newlinebuf[BUFSIZE]; - strip_tabs(newlinebuf, linebuf, strlen(linebuf)); + strip_tabs(newlinebuf, linebuf, strlen(linebuf)); - ierror("\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'", - conffilebuf, lineno + 1, msg, newlinebuf); + ierror("\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'", + conffilebuf, lineno + 1, msg, newlinebuf); } int conf_fgets(char *lbuf, int max_size, FILE * fb) { - if(fgets(lbuf, max_size, fb) == NULL) - return (0); + if(fgets(lbuf, max_size, fb) == NULL) + return (0); - return (strlen(lbuf)); + return (strlen(lbuf)); } int conf_yy_fatal_error(const char *msg) { - return (0); + return (0); } diff --git a/src/s_newconf.c b/src/s_newconf.c index d35cef2..c65cace 100644 --- a/src/s_newconf.c +++ b/src/s_newconf.c @@ -67,488 +67,457 @@ struct ev_entry *expire_temp_rxlines_ev = NULL; void init_s_newconf(void) { - tgchange_tree = rb_new_patricia(PATRICIA_BITS); - nd_heap = rb_bh_create(sizeof(struct nd_entry), ND_HEAP_SIZE, "nd_heap"); - expire_nd_entries_ev = rb_event_addish("expire_nd_entries", expire_nd_entries, NULL, 30); - expire_temp_rxlines_ev = rb_event_addish("expire_temp_rxlines", expire_temp_rxlines, NULL, 60); + tgchange_tree = rb_new_patricia(PATRICIA_BITS); + nd_heap = rb_bh_create(sizeof(struct nd_entry), ND_HEAP_SIZE, "nd_heap"); + expire_nd_entries_ev = rb_event_addish("expire_nd_entries", expire_nd_entries, NULL, 30); + expire_temp_rxlines_ev = rb_event_addish("expire_temp_rxlines", expire_temp_rxlines, NULL, 60); } void clear_s_newconf(void) { - struct server_conf *server_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct server_conf *server_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head) - { - /* ptr here is ptr->data->node */ - rb_dlinkDelete(ptr, &shared_conf_list); - free_remote_conf(ptr->data); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head) { + /* ptr here is ptr->data->node */ + rb_dlinkDelete(ptr, &shared_conf_list); + free_remote_conf(ptr->data); + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head) - { - rb_dlinkDelete(ptr, &cluster_conf_list); - free_remote_conf(ptr->data); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head) { + rb_dlinkDelete(ptr, &cluster_conf_list); + free_remote_conf(ptr->data); + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head) - { - rb_dlinkDelete(ptr, &hubleaf_conf_list); - free_remote_conf(ptr->data); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head) { + rb_dlinkDelete(ptr, &hubleaf_conf_list); + free_remote_conf(ptr->data); + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head) - { - free_oper_conf(ptr->data); - rb_dlinkDestroy(ptr, &oper_conf_list); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head) { + free_oper_conf(ptr->data); + rb_dlinkDestroy(ptr, &oper_conf_list); + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, server_conf_list.head) - { - server_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, server_conf_list.head) { + server_p = ptr->data; - if(!server_p->servers) - { - rb_dlinkDelete(ptr, &server_conf_list); - free_server_conf(ptr->data); - } - else - server_p->flags |= SERVER_ILLEGAL; - } + if(!server_p->servers) { + rb_dlinkDelete(ptr, &server_conf_list); + free_server_conf(ptr->data); + } else + server_p->flags |= SERVER_ILLEGAL; + } } void clear_s_newconf_bans(void) { - struct ConfItem *aconf; - rb_dlink_node *ptr, *next_ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr, *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) { + aconf = ptr->data; - if(aconf->hold) - continue; + if(aconf->hold) + continue; - free_conf(aconf); - rb_dlinkDestroy(ptr, &xline_conf_list); - } + free_conf(aconf); + rb_dlinkDestroy(ptr, &xline_conf_list); + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) { + aconf = ptr->data; - /* temporary resv */ - if(aconf->hold) - continue; + /* temporary resv */ + if(aconf->hold) + continue; - free_conf(aconf); - rb_dlinkDestroy(ptr, &resv_conf_list); - } + free_conf(aconf); + rb_dlinkDestroy(ptr, &resv_conf_list); + } - clear_resv_hash(); + clear_resv_hash(); } struct remote_conf * make_remote_conf(void) { - struct remote_conf *remote_p = rb_malloc(sizeof(struct remote_conf)); - return remote_p; + struct remote_conf *remote_p = rb_malloc(sizeof(struct remote_conf)); + return remote_p; } void free_remote_conf(struct remote_conf *remote_p) { - s_assert(remote_p != NULL); - if(remote_p == NULL) - return; + s_assert(remote_p != NULL); + if(remote_p == NULL) + return; - rb_free(remote_p->username); - rb_free(remote_p->host); - rb_free(remote_p->server); - rb_free(remote_p); + rb_free(remote_p->username); + rb_free(remote_p->host); + rb_free(remote_p->server); + rb_free(remote_p); } int -find_shared_conf(const char *username, const char *host, - const char *server, int flags) +find_shared_conf(const char *username, const char *host, + const char *server, int flags) { - struct remote_conf *shared_p; - rb_dlink_node *ptr; + struct remote_conf *shared_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, shared_conf_list.head) - { - shared_p = ptr->data; + RB_DLINK_FOREACH(ptr, shared_conf_list.head) { + shared_p = ptr->data; - if(match(shared_p->username, username) && - match(shared_p->host, host) && - match(shared_p->server, server)) - { - if(shared_p->flags & flags) - return YES; - else - return NO; - } - } + if(match(shared_p->username, username) && + match(shared_p->host, host) && + match(shared_p->server, server)) { + if(shared_p->flags & flags) + return YES; + else + return NO; + } + } - return NO; + return NO; } void propagate_generic(struct Client *source_p, const char *command, - const char *target, int cap, const char *format, ...) + const char *target, int cap, const char *format, ...) { - char buffer[BUFSIZE]; - va_list args; + char buffer[BUFSIZE]; + va_list args; - va_start(args, format); - rb_vsnprintf(buffer, sizeof(buffer), format, args); - va_end(args); + va_start(args, format); + rb_vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); - sendto_match_servs(source_p, target, cap, NOCAPS, - "%s %s %s", - command, target, buffer); - sendto_match_servs(source_p, target, CAP_ENCAP, cap, - "ENCAP %s %s %s", - target, command, buffer); + sendto_match_servs(source_p, target, cap, NOCAPS, + "%s %s %s", + command, target, buffer); + sendto_match_servs(source_p, target, CAP_ENCAP, cap, + "ENCAP %s %s %s", + target, command, buffer); } - + void cluster_generic(struct Client *source_p, const char *command, - int cltype, int cap, const char *format, ...) + int cltype, int cap, const char *format, ...) { - char buffer[BUFSIZE]; - struct remote_conf *shared_p; - va_list args; - rb_dlink_node *ptr; + char buffer[BUFSIZE]; + struct remote_conf *shared_p; + va_list args; + rb_dlink_node *ptr; - va_start(args, format); - rb_vsnprintf(buffer, sizeof(buffer), format, args); - va_end(args); + va_start(args, format); + rb_vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); - RB_DLINK_FOREACH(ptr, cluster_conf_list.head) - { - shared_p = ptr->data; + RB_DLINK_FOREACH(ptr, cluster_conf_list.head) { + shared_p = ptr->data; - if(!(shared_p->flags & cltype)) - continue; + if(!(shared_p->flags & cltype)) + continue; - sendto_match_servs(source_p, shared_p->server, cap, NOCAPS, - "%s %s %s", - command, shared_p->server, buffer); - sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, cap, - "ENCAP %s %s %s", - shared_p->server, command, buffer); - } + sendto_match_servs(source_p, shared_p->server, cap, NOCAPS, + "%s %s %s", + command, shared_p->server, buffer); + sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, cap, + "ENCAP %s %s %s", + shared_p->server, command, buffer); + } } struct oper_conf * make_oper_conf(void) { - struct oper_conf *oper_p = rb_malloc(sizeof(struct oper_conf)); - return oper_p; + struct oper_conf *oper_p = rb_malloc(sizeof(struct oper_conf)); + return oper_p; } void free_oper_conf(struct oper_conf *oper_p) { - s_assert(oper_p != NULL); - if(oper_p == NULL) - return; + s_assert(oper_p != NULL); + if(oper_p == NULL) + return; - rb_free(oper_p->username); - rb_free(oper_p->host); - rb_free(oper_p->name); - rb_free(oper_p->certfp); + rb_free(oper_p->username); + rb_free(oper_p->host); + rb_free(oper_p->name); + rb_free(oper_p->certfp); - if(oper_p->passwd) - { - memset(oper_p->passwd, 0, strlen(oper_p->passwd)); - rb_free(oper_p->passwd); - } + if(oper_p->passwd) { + memset(oper_p->passwd, 0, strlen(oper_p->passwd)); + rb_free(oper_p->passwd); + } #ifdef HAVE_LIBCRYPTO - rb_free(oper_p->rsa_pubkey_file); + rb_free(oper_p->rsa_pubkey_file); - if(oper_p->rsa_pubkey) - RSA_free(oper_p->rsa_pubkey); + if(oper_p->rsa_pubkey) + RSA_free(oper_p->rsa_pubkey); #endif - rb_free(oper_p); + rb_free(oper_p); } struct oper_conf * find_oper_conf(const char *username, const char *host, const char *locip, const char *name) { - struct oper_conf *oper_p; - struct rb_sockaddr_storage ip, cip; - char addr[HOSTLEN+1]; - int bits, cbits; - rb_dlink_node *ptr; + struct oper_conf *oper_p; + struct rb_sockaddr_storage ip, cip; + char addr[HOSTLEN+1]; + int bits, cbits; + rb_dlink_node *ptr; - parse_netmask(locip, (struct sockaddr *)&cip, &cbits); + parse_netmask(locip, (struct sockaddr *)&cip, &cbits); - RB_DLINK_FOREACH(ptr, oper_conf_list.head) - { - oper_p = ptr->data; + RB_DLINK_FOREACH(ptr, oper_conf_list.head) { + oper_p = ptr->data; - /* name/username doesnt match.. */ - if(irccmp(oper_p->name, name) || !match(oper_p->username, username)) - continue; + /* name/username doesnt match.. */ + if(irccmp(oper_p->name, name) || !match(oper_p->username, username)) + continue; - rb_strlcpy(addr, oper_p->host, sizeof(addr)); + rb_strlcpy(addr, oper_p->host, sizeof(addr)); - if(parse_netmask(addr, (struct sockaddr *)&ip, &bits) != HM_HOST) - { - if(ip.ss_family == cip.ss_family && - comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits)) - return oper_p; - } + if(parse_netmask(addr, (struct sockaddr *)&ip, &bits) != HM_HOST) { + if(ip.ss_family == cip.ss_family && + comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits)) + return oper_p; + } - /* we have to compare against the host as well, because its - * valid to set a spoof to an IP, which if we only compare - * in ip form to sockhost will not necessarily match --anfl - */ - if(match(oper_p->host, host)) - return oper_p; - } + /* we have to compare against the host as well, because its + * valid to set a spoof to an IP, which if we only compare + * in ip form to sockhost will not necessarily match --anfl + */ + if(match(oper_p->host, host)) + return oper_p; + } - return NULL; + return NULL; } struct server_conf * make_server_conf(void) { - struct server_conf *server_p = rb_malloc(sizeof(struct server_conf)); - server_p->aftype = AF_INET; - return server_p; + struct server_conf *server_p = rb_malloc(sizeof(struct server_conf)); + server_p->aftype = AF_INET; + return server_p; } void free_server_conf(struct server_conf *server_p) { - s_assert(server_p != NULL); - if(server_p == NULL) - return; + s_assert(server_p != NULL); + if(server_p == NULL) + return; - if(!EmptyString(server_p->passwd)) - { - memset(server_p->passwd, 0, strlen(server_p->passwd)); - rb_free(server_p->passwd); - } + if(!EmptyString(server_p->passwd)) { + memset(server_p->passwd, 0, strlen(server_p->passwd)); + rb_free(server_p->passwd); + } - if(!EmptyString(server_p->spasswd)) - { - memset(server_p->spasswd, 0, strlen(server_p->spasswd)); - rb_free(server_p->spasswd); - } + if(!EmptyString(server_p->spasswd)) { + memset(server_p->spasswd, 0, strlen(server_p->spasswd)); + rb_free(server_p->spasswd); + } - rb_free(server_p->name); - rb_free(server_p->host); - rb_free(server_p->class_name); - rb_free(server_p); + rb_free(server_p->name); + rb_free(server_p->host); + rb_free(server_p->class_name); + rb_free(server_p); } void add_server_conf(struct server_conf *server_p) { - if(EmptyString(server_p->class_name)) - { - server_p->class_name = rb_strdup("default"); - server_p->class = default_class; - return; - } + if(EmptyString(server_p->class_name)) { + server_p->class_name = rb_strdup("default"); + server_p->class = default_class; + return; + } - server_p->class = find_class(server_p->class_name); + server_p->class = find_class(server_p->class_name); - if(server_p->class == default_class) - { - conf_report_error("Warning connect::class invalid for %s", - server_p->name); + if(server_p->class == default_class) { + conf_report_error("Warning connect::class invalid for %s", + server_p->name); - rb_free(server_p->class_name); - server_p->class_name = rb_strdup("default"); - } + rb_free(server_p->class_name); + server_p->class_name = rb_strdup("default"); + } - if(strchr(server_p->host, '*') || strchr(server_p->host, '?')) - return; + if(strchr(server_p->host, '*') || strchr(server_p->host, '?')) + return; } struct server_conf * find_server_conf(const char *name) { - struct server_conf *server_p; - rb_dlink_node *ptr; + struct server_conf *server_p; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, server_conf_list.head) - { - server_p = ptr->data; + RB_DLINK_FOREACH(ptr, server_conf_list.head) { + server_p = ptr->data; - if(ServerConfIllegal(server_p)) - continue; + if(ServerConfIllegal(server_p)) + continue; - if(match(name, server_p->name)) - return server_p; - } + if(match(name, server_p->name)) + return server_p; + } - return NULL; + return NULL; } void attach_server_conf(struct Client *client_p, struct server_conf *server_p) { - /* already have an attached conf */ - if(client_p->localClient->att_sconf) - { - /* short circuit this special case :) */ - if(client_p->localClient->att_sconf == server_p) - return; + /* already have an attached conf */ + if(client_p->localClient->att_sconf) { + /* short circuit this special case :) */ + if(client_p->localClient->att_sconf == server_p) + return; - detach_server_conf(client_p); - } + detach_server_conf(client_p); + } - CurrUsers(server_p->class)++; + CurrUsers(server_p->class)++; - client_p->localClient->att_sconf = server_p; - server_p->servers++; + client_p->localClient->att_sconf = server_p; + server_p->servers++; } void detach_server_conf(struct Client *client_p) { - struct server_conf *server_p = client_p->localClient->att_sconf; + struct server_conf *server_p = client_p->localClient->att_sconf; - if(server_p == NULL) - return; + if(server_p == NULL) + return; - client_p->localClient->att_sconf = NULL; - server_p->servers--; - CurrUsers(server_p->class)--; + client_p->localClient->att_sconf = NULL; + server_p->servers--; + CurrUsers(server_p->class)--; - if(ServerConfIllegal(server_p) && !server_p->servers) - { - /* the class this one is using may need destroying too */ - if(MaxUsers(server_p->class) < 0 && CurrUsers(server_p->class) <= 0) - free_class(server_p->class); + if(ServerConfIllegal(server_p) && !server_p->servers) { + /* the class this one is using may need destroying too */ + if(MaxUsers(server_p->class) < 0 && CurrUsers(server_p->class) <= 0) + free_class(server_p->class); - rb_dlinkDelete(&server_p->node, &server_conf_list); - free_server_conf(server_p); - } + rb_dlinkDelete(&server_p->node, &server_conf_list); + free_server_conf(server_p); + } } void set_server_conf_autoconn(struct Client *source_p, const char *name, int newval) { - struct server_conf *server_p; + struct server_conf *server_p; - if((server_p = find_server_conf(name)) != NULL) - { - if(newval) - server_p->flags |= SERVER_AUTOCONN; - else - server_p->flags &= ~SERVER_AUTOCONN; + if((server_p = find_server_conf(name)) != NULL) { + if(newval) + server_p->flags |= SERVER_AUTOCONN; + else + server_p->flags &= ~SERVER_AUTOCONN; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has changed AUTOCONN for %s to %i", - get_oper_name(source_p), name, newval); - } - else - sendto_one_notice(source_p, ":Can't find %s", name); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s has changed AUTOCONN for %s to %i", + get_oper_name(source_p), name, newval); + } else + sendto_one_notice(source_p, ":Can't find %s", name); } void disable_server_conf_autoconn(const char *name) { - struct server_conf *server_p; + struct server_conf *server_p; - server_p = find_server_conf(name); - if(server_p != NULL && server_p->flags & SERVER_AUTOCONN) - { - server_p->flags &= ~SERVER_AUTOCONN; + server_p = find_server_conf(name); + if(server_p != NULL && server_p->flags & SERVER_AUTOCONN) { + server_p->flags &= ~SERVER_AUTOCONN; - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Disabling AUTOCONN for %s because of error", - name); - ilog(L_SERVER, "Disabling AUTOCONN for %s because of error", - name); - } + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Disabling AUTOCONN for %s because of error", + name); + ilog(L_SERVER, "Disabling AUTOCONN for %s because of error", + name); + } } struct ConfItem * find_xline(const char *gecos, int counter) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, xline_conf_list.head) { + aconf = ptr->data; - if(match_esc(aconf->host, gecos)) - { - if(counter) - aconf->port++; - return aconf; - } - } + if(match_esc(aconf->host, gecos)) { + if(counter) + aconf->port++; + return aconf; + } + } - return NULL; + return NULL; } struct ConfItem * find_xline_mask(const char *gecos) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, xline_conf_list.head) { + aconf = ptr->data; - if(!irccmp(aconf->host, gecos)) - return aconf; - } + if(!irccmp(aconf->host, gecos)) + return aconf; + } - return NULL; + return NULL; } struct ConfItem * find_nick_resv(const char *name) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, resv_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, resv_conf_list.head) { + aconf = ptr->data; - if(match_esc(aconf->host, name)) - { - aconf->port++; - return aconf; - } - } + if(match_esc(aconf->host, name)) { + aconf->port++; + return aconf; + } + } - return NULL; + return NULL; } struct ConfItem * find_nick_resv_mask(const char *name) { - struct ConfItem *aconf; - rb_dlink_node *ptr; + struct ConfItem *aconf; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, resv_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH(ptr, resv_conf_list.head) { + aconf = ptr->data; - if(!irccmp(aconf->host, name)) - return aconf; - } + if(!irccmp(aconf->host, name)) + return aconf; + } - return NULL; + return NULL; } /* clean_resv_nick() @@ -560,30 +529,29 @@ find_nick_resv_mask(const char *name) int clean_resv_nick(const char *nick) { - char tmpch; - int as = 0; - int q = 0; - int ch = 0; + char tmpch; + int as = 0; + int q = 0; + int ch = 0; - if(*nick == '-' || IsDigit(*nick)) - return 0; + if(*nick == '-' || IsDigit(*nick)) + return 0; - while ((tmpch = *nick++)) - { - if(tmpch == '?' || tmpch == '@' || tmpch == '#') - q++; - else if(tmpch == '*') - as++; - else if(IsNickChar(tmpch)) - ch++; - else - return 0; - } + while ((tmpch = *nick++)) { + if(tmpch == '?' || tmpch == '@' || tmpch == '#') + q++; + else if(tmpch == '*') + as++; + else if(IsNickChar(tmpch)) + ch++; + else + return 0; + } - if(!ch && as) - return 0; + if(!ch && as) + return 0; - return 1; + return 1; } /* valid_wild_card_simple() @@ -595,209 +563,194 @@ clean_resv_nick(const char *nick) int valid_wild_card_simple(const char *data) { - const char *p; - char tmpch; - int nonwild = 0; - int wild = 0; + const char *p; + char tmpch; + int nonwild = 0; + int wild = 0; - /* check the string for minimum number of nonwildcard chars */ - p = data; + /* check the string for minimum number of nonwildcard chars */ + p = data; - while((tmpch = *p++)) - { - /* found an escape, p points to the char after it, so skip - * that and move on. - */ - if(tmpch == '\\' && *p) - { - p++; - if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) - return 1; - } - else if(!IsMWildChar(tmpch)) - { - /* if we have enough nonwildchars, return */ - if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) - return 1; - } - else - wild++; - } + while((tmpch = *p++)) { + /* found an escape, p points to the char after it, so skip + * that and move on. + */ + if(tmpch == '\\' && *p) { + p++; + if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) + return 1; + } else if(!IsMWildChar(tmpch)) { + /* if we have enough nonwildchars, return */ + if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) + return 1; + } else + wild++; + } - /* strings without wilds are also ok */ - return wild == 0; + /* strings without wilds are also ok */ + return wild == 0; } time_t valid_temp_time(const char *p) { - time_t result = 0; + time_t result = 0; - while(*p) - { - if(IsDigit(*p)) - { - result *= 10; - result += ((*p) & 0xF); - p++; - } - else - return -1; - } + while(*p) { + if(IsDigit(*p)) { + result *= 10; + result += ((*p) & 0xF); + p++; + } else + return -1; + } - if(result > (60 * 24 * 7 * 52)) - result = (60 * 24 * 7 * 52); + if(result > (60 * 24 * 7 * 52)) + result = (60 * 24 * 7 * 52); - return(result * 60); + return(result * 60); } /* Propagated bans are expired elsewhere. */ static void expire_temp_rxlines(void *unused) { - struct ConfItem *aconf; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - int i; + struct ConfItem *aconf; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + int i; - HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) - { - aconf = ptr->data; + HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) { + aconf = ptr->data; - if(aconf->lifetime != 0) - continue; - if(aconf->hold && aconf->hold <= rb_current_time()) - { - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Temporary RESV for [%s] expired", - aconf->host); + if(aconf->lifetime != 0) + continue; + if(aconf->hold && aconf->hold <= rb_current_time()) { + if(ConfigFileEntry.tkline_expire_notices) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Temporary RESV for [%s] expired", + aconf->host); - free_conf(aconf); - rb_dlinkDestroy(ptr, &resvTable[i]); - } - } - HASH_WALK_END + free_conf(aconf); + rb_dlinkDestroy(ptr, &resvTable[i]); + } + } + HASH_WALK_END - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) { + aconf = ptr->data; - if(aconf->lifetime != 0) - continue; - if(aconf->hold && aconf->hold <= rb_current_time()) - { - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Temporary RESV for [%s] expired", - aconf->host); - free_conf(aconf); - rb_dlinkDestroy(ptr, &resv_conf_list); - } - } + if(aconf->lifetime != 0) + continue; + if(aconf->hold && aconf->hold <= rb_current_time()) { + if(ConfigFileEntry.tkline_expire_notices) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Temporary RESV for [%s] expired", + aconf->host); + free_conf(aconf); + rb_dlinkDestroy(ptr, &resv_conf_list); + } + } - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) - { - aconf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) { + aconf = ptr->data; - if(aconf->lifetime != 0) - continue; - if(aconf->hold && aconf->hold <= rb_current_time()) - { - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Temporary X-line for [%s] expired", - aconf->host); - free_conf(aconf); - rb_dlinkDestroy(ptr, &xline_conf_list); - } - } + if(aconf->lifetime != 0) + continue; + if(aconf->hold && aconf->hold <= rb_current_time()) { + if(ConfigFileEntry.tkline_expire_notices) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Temporary X-line for [%s] expired", + aconf->host); + free_conf(aconf); + rb_dlinkDestroy(ptr, &xline_conf_list); + } + } } unsigned long get_nd_count(void) { - return(rb_dlink_list_length(&nd_list)); + return(rb_dlink_list_length(&nd_list)); } void add_nd_entry(const char *name) { - struct nd_entry *nd; + struct nd_entry *nd; - if(irc_dictionary_find(nd_dict, name) != NULL) - return; + if(irc_dictionary_find(nd_dict, name) != NULL) + return; - nd = rb_bh_alloc(nd_heap); - - rb_strlcpy(nd->name, name, sizeof(nd->name)); - nd->expire = rb_current_time() + ConfigFileEntry.nick_delay; + nd = rb_bh_alloc(nd_heap); - /* this list is ordered */ - rb_dlinkAddTail(nd, &nd->lnode, &nd_list); + rb_strlcpy(nd->name, name, sizeof(nd->name)); + nd->expire = rb_current_time() + ConfigFileEntry.nick_delay; - irc_dictionary_add(nd_dict, nd->name, nd); + /* this list is ordered */ + rb_dlinkAddTail(nd, &nd->lnode, &nd_list); + + irc_dictionary_add(nd_dict, nd->name, nd); } void free_nd_entry(struct nd_entry *nd) { - irc_dictionary_delete(nd_dict, nd->name); + irc_dictionary_delete(nd_dict, nd->name); - rb_dlinkDelete(&nd->lnode, &nd_list); - rb_bh_free(nd_heap, nd); + rb_dlinkDelete(&nd->lnode, &nd_list); + rb_bh_free(nd_heap, nd); } void expire_nd_entries(void *unused) { - struct nd_entry *nd; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + struct nd_entry *nd; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, nd_list.head) - { - nd = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, nd_list.head) { + nd = ptr->data; - /* this list is ordered - we can stop when we hit the first - * entry that doesnt expire.. - */ - if(nd->expire > rb_current_time()) - return; + /* this list is ordered - we can stop when we hit the first + * entry that doesnt expire.. + */ + if(nd->expire > rb_current_time()) + return; - free_nd_entry(nd); - } + free_nd_entry(nd); + } } void add_tgchange(const char *host) { - tgchange *target; - rb_patricia_node_t *pnode; + tgchange *target; + rb_patricia_node_t *pnode; - if(find_tgchange(host)) - return; + if(find_tgchange(host)) + return; - target = rb_malloc(sizeof(tgchange)); - pnode = make_and_lookup(tgchange_tree, host); + target = rb_malloc(sizeof(tgchange)); + pnode = make_and_lookup(tgchange_tree, host); - pnode->data = target; - target->pnode = pnode; + pnode->data = target; + target->pnode = pnode; - target->ip = rb_strdup(host); - target->expiry = rb_current_time() + (60*60*12); + target->ip = rb_strdup(host); + target->expiry = rb_current_time() + (60*60*12); - rb_dlinkAdd(target, &target->node, &tgchange_list); + rb_dlinkAdd(target, &target->node, &tgchange_list); } tgchange * find_tgchange(const char *host) { - rb_patricia_node_t *pnode; + rb_patricia_node_t *pnode; - if((pnode = rb_match_exact_string(tgchange_tree, host))) - return pnode->data; + if((pnode = rb_match_exact_string(tgchange_tree, host))) + return pnode->data; - return NULL; + return NULL; } diff --git a/src/s_serv.c b/src/s_serv.c index c4db56c..8d44855 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -71,26 +71,26 @@ static char buf[BUFSIZE]; * extra argument to "PASS" takes care of checking that. -orabidoo */ struct Capability captab[] = { -/* name cap */ - { "QS", CAP_QS }, - { "EX", CAP_EX }, - { "CHW", CAP_CHW}, - { "IE", CAP_IE}, - { "KLN", CAP_KLN}, - { "KNOCK", CAP_KNOCK}, - { "ZIP", CAP_ZIP}, - { "TB", CAP_TB}, - { "UNKLN", CAP_UNKLN}, - { "CLUSTER", CAP_CLUSTER}, - { "ENCAP", CAP_ENCAP }, - { "SERVICES", CAP_SERVICE }, - { "RSFNC", CAP_RSFNC }, - { "SAVE", CAP_SAVE }, - { "EUID", CAP_EUID }, - { "EOPMOD", CAP_EOPMOD }, - { "BAN", CAP_BAN }, - { "MLOCK", CAP_MLOCK }, - {0, 0} + /* name cap */ + { "QS", CAP_QS }, + { "EX", CAP_EX }, + { "CHW", CAP_CHW}, + { "IE", CAP_IE}, + { "KLN", CAP_KLN}, + { "KNOCK", CAP_KNOCK}, + { "ZIP", CAP_ZIP}, + { "TB", CAP_TB}, + { "UNKLN", CAP_UNKLN}, + { "CLUSTER", CAP_CLUSTER}, + { "ENCAP", CAP_ENCAP }, + { "SERVICES", CAP_SERVICE }, + { "RSFNC", CAP_RSFNC }, + { "SAVE", CAP_SAVE }, + { "EUID", CAP_EUID }, + { "EOPMOD", CAP_EOPMOD }, + { "BAN", CAP_BAN }, + { "MLOCK", CAP_MLOCK }, + {0, 0} }; static CNCB serv_connect_callback; @@ -117,77 +117,73 @@ static CNCB serv_connect_ssl_callback; */ int hunt_server(struct Client *client_p, struct Client *source_p, - const char *command, int server, int parc, const char *parv[]) + const char *command, int server, int parc, const char *parv[]) { - struct Client *target_p; - int wilds; - rb_dlink_node *ptr; - const char *old; - char *new; + struct Client *target_p; + int wilds; + rb_dlink_node *ptr; + const char *old; + char *new; - /* - * Assume it's me, if no server - */ - if(parc <= server || EmptyString(parv[server]) || - match(parv[server], me.name) || (strcmp(parv[server], me.id) == 0)) - return (HUNTED_ISME); - - new = LOCAL_COPY(parv[server]); + /* + * Assume it's me, if no server + */ + if(parc <= server || EmptyString(parv[server]) || + match(parv[server], me.name) || (strcmp(parv[server], me.id) == 0)) + return (HUNTED_ISME); - /* - * These are to pickup matches that would cause the following - * message to go in the wrong direction while doing quick fast - * non-matching lookups. - */ - if(MyClient(source_p)) - target_p = find_named_client(new); - else - target_p = find_client(new); + new = LOCAL_COPY(parv[server]); - if(target_p) - if(target_p->from == source_p->from && !MyConnect(target_p)) - target_p = NULL; + /* + * These are to pickup matches that would cause the following + * message to go in the wrong direction while doing quick fast + * non-matching lookups. + */ + if(MyClient(source_p)) + target_p = find_named_client(new); + else + target_p = find_client(new); - collapse(new); - wilds = (strchr(new, '?') || strchr(new, '*')); + if(target_p) + if(target_p->from == source_p->from && !MyConnect(target_p)) + target_p = NULL; - /* - * Again, if there are no wild cards involved in the server - * name, use the hash lookup - */ - if(!target_p && wilds) - { - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - if(match(new, ((struct Client *) (ptr->data))->name)) - { - target_p = ptr->data; - break; - } - } - } + collapse(new); + wilds = (strchr(new, '?') || strchr(new, '*')); - if(target_p && !IsRegistered(target_p)) - target_p = NULL; + /* + * Again, if there are no wild cards involved in the server + * name, use the hash lookup + */ + if(!target_p && wilds) { + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + if(match(new, ((struct Client *) (ptr->data))->name)) { + target_p = ptr->data; + break; + } + } + } - if(target_p) - { - if(IsMe(target_p) || MyClient(target_p)) - return HUNTED_ISME; + if(target_p && !IsRegistered(target_p)) + target_p = NULL; - old = parv[server]; - parv[server] = get_id(target_p, target_p); + if(target_p) { + if(IsMe(target_p) || MyClient(target_p)) + return HUNTED_ISME; - sendto_one(target_p, command, get_id(source_p, target_p), - parv[1], parv[2], parv[3], parv[4], parv[5], parv[6], parv[7], parv[8]); - parv[server] = old; - return (HUNTED_PASS); - } + old = parv[server]; + parv[server] = get_id(target_p, target_p); - if(MyClient(source_p) || !IsDigit(parv[server][0])) - sendto_one_numeric(source_p, ERR_NOSUCHSERVER, - form_str(ERR_NOSUCHSERVER), parv[server]); - return (HUNTED_NOSUCH); + sendto_one(target_p, command, get_id(source_p, target_p), + parv[1], parv[2], parv[3], parv[4], parv[5], parv[6], parv[7], parv[8]); + parv[server] = old; + return (HUNTED_PASS); + } + + if(MyClient(source_p) || !IsDigit(parv[server][0])) + sendto_one_numeric(source_p, ERR_NOSUCHSERVER, + form_str(ERR_NOSUCHSERVER), parv[server]); + return (HUNTED_NOSUCH); } /* @@ -199,175 +195,163 @@ hunt_server(struct Client *client_p, struct Client *source_p, void try_connections(void *unused) { - struct Client *client_p; - struct server_conf *server_p = NULL; - struct server_conf *tmp_p; - struct Class *cltmp; - rb_dlink_node *ptr; - int connecting = FALSE; - int confrq = 0; - time_t next = 0; + struct Client *client_p; + struct server_conf *server_p = NULL; + struct server_conf *tmp_p; + struct Class *cltmp; + rb_dlink_node *ptr; + int connecting = FALSE; + int confrq = 0; + time_t next = 0; - RB_DLINK_FOREACH(ptr, server_conf_list.head) - { - tmp_p = ptr->data; + RB_DLINK_FOREACH(ptr, server_conf_list.head) { + tmp_p = ptr->data; - if(ServerConfIllegal(tmp_p) || !ServerConfAutoconn(tmp_p)) - continue; + if(ServerConfIllegal(tmp_p) || !ServerConfAutoconn(tmp_p)) + continue; - /* don't allow ssl connections if ssl isn't setup */ - if(ServerConfSSL(tmp_p) && (!ssl_ok || !get_ssld_count())) - continue; + /* don't allow ssl connections if ssl isn't setup */ + if(ServerConfSSL(tmp_p) && (!ssl_ok || !get_ssld_count())) + continue; - cltmp = tmp_p->class; + cltmp = tmp_p->class; - /* - * Skip this entry if the use of it is still on hold until - * future. Otherwise handle this entry (and set it on hold - * until next time). Will reset only hold times, if already - * made one successfull connection... [this algorithm is - * a bit fuzzy... -- msa >;) ] - */ - if(tmp_p->hold > rb_current_time()) - { - if(next > tmp_p->hold || next == 0) - next = tmp_p->hold; - continue; - } + /* + * Skip this entry if the use of it is still on hold until + * future. Otherwise handle this entry (and set it on hold + * until next time). Will reset only hold times, if already + * made one successfull connection... [this algorithm is + * a bit fuzzy... -- msa >;) ] + */ + if(tmp_p->hold > rb_current_time()) { + if(next > tmp_p->hold || next == 0) + next = tmp_p->hold; + continue; + } - confrq = get_con_freq(cltmp); - tmp_p->hold = rb_current_time() + confrq; + confrq = get_con_freq(cltmp); + tmp_p->hold = rb_current_time() + confrq; - /* - * Found a CONNECT config with port specified, scan clients - * and see if this server is already connected? - */ - client_p = find_server(NULL, tmp_p->name); + /* + * Found a CONNECT config with port specified, scan clients + * and see if this server is already connected? + */ + client_p = find_server(NULL, tmp_p->name); - if(!client_p && (CurrUsers(cltmp) < MaxUsers(cltmp)) && !connecting) - { - server_p = tmp_p; + if(!client_p && (CurrUsers(cltmp) < MaxUsers(cltmp)) && !connecting) { + server_p = tmp_p; - /* We connect only one at time... */ - connecting = TRUE; - } + /* We connect only one at time... */ + connecting = TRUE; + } - if((next > tmp_p->hold) || (next == 0)) - next = tmp_p->hold; - } + if((next > tmp_p->hold) || (next == 0)) + next = tmp_p->hold; + } - /* TODO: change this to set active flag to 0 when added to event! --Habeeb */ - if(GlobalSetOptions.autoconn == 0) - return; + /* TODO: change this to set active flag to 0 when added to event! --Habeeb */ + if(GlobalSetOptions.autoconn == 0) + return; - if(!connecting) - return; + if(!connecting) + return; - /* move this connect entry to end.. */ - rb_dlinkDelete(&server_p->node, &server_conf_list); - rb_dlinkAddTail(server_p, &server_p->node, &server_conf_list); + /* move this connect entry to end.. */ + rb_dlinkDelete(&server_p->node, &server_conf_list); + rb_dlinkAddTail(server_p, &server_p->node, &server_conf_list); - /* - * We used to only print this if serv_connect() actually - * suceeded, but since rb_tcp_connect() can call the callback - * immediately if there is an error, we were getting error messages - * in the wrong order. SO, we just print out the activated line, - * and let serv_connect() / serv_connect_callback() print an - * error afterwards if it fails. - * -- adrian - */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Connection to %s activated", - server_p->name); + /* + * We used to only print this if serv_connect() actually + * suceeded, but since rb_tcp_connect() can call the callback + * immediately if there is an error, we were getting error messages + * in the wrong order. SO, we just print out the activated line, + * and let serv_connect() / serv_connect_callback() print an + * error afterwards if it fails. + * -- adrian + */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Connection to %s activated", + server_p->name); - serv_connect(server_p, 0); + serv_connect(server_p, 0); } int check_server(const char *name, struct Client *client_p) { - struct server_conf *server_p = NULL; - struct server_conf *tmp_p; - rb_dlink_node *ptr; - int error = -1; + struct server_conf *server_p = NULL; + struct server_conf *tmp_p; + rb_dlink_node *ptr; + int error = -1; - s_assert(NULL != client_p); - if(client_p == NULL) - return error; + s_assert(NULL != client_p); + if(client_p == NULL) + return error; - if(!(client_p->localClient->passwd)) - return -2; + if(!(client_p->localClient->passwd)) + return -2; - if(strlen(name) > HOSTLEN) - return -4; + if(strlen(name) > HOSTLEN) + return -4; - RB_DLINK_FOREACH(ptr, server_conf_list.head) - { - tmp_p = ptr->data; + RB_DLINK_FOREACH(ptr, server_conf_list.head) { + tmp_p = ptr->data; - if(ServerConfIllegal(tmp_p)) - continue; + if(ServerConfIllegal(tmp_p)) + continue; - if(!match(tmp_p->name, name)) - continue; + if(!match(tmp_p->name, name)) + continue; - error = -3; + error = -3; - /* XXX: Fix me for IPv6 */ - /* XXX sockhost is the IPv4 ip as a string */ - if(match(tmp_p->host, client_p->host) || - match(tmp_p->host, client_p->sockhost)) - { - error = -2; + /* XXX: Fix me for IPv6 */ + /* XXX sockhost is the IPv4 ip as a string */ + if(match(tmp_p->host, client_p->host) || + match(tmp_p->host, client_p->sockhost)) { + error = -2; - if(tmp_p->passwd) - { - if(ServerConfEncrypted(tmp_p)) - { - if(!strcmp(tmp_p->passwd, rb_crypt(client_p->localClient->passwd, - tmp_p->passwd))) - { - server_p = tmp_p; - break; - } - else - continue; - } - else if(strcmp(tmp_p->passwd, client_p->localClient->passwd)) - continue; - } + if(tmp_p->passwd) { + if(ServerConfEncrypted(tmp_p)) { + if(!strcmp(tmp_p->passwd, rb_crypt(client_p->localClient->passwd, + tmp_p->passwd))) { + server_p = tmp_p; + break; + } else + continue; + } else if(strcmp(tmp_p->passwd, client_p->localClient->passwd)) + continue; + } - if(tmp_p->certfp) - { - if(!client_p->certfp || strcasecmp(tmp_p->certfp, client_p->certfp) != 0) - continue; - } + if(tmp_p->certfp) { + if(!client_p->certfp || strcasecmp(tmp_p->certfp, client_p->certfp) != 0) + continue; + } - server_p = tmp_p; - break; - } - } + server_p = tmp_p; + break; + } + } - if(server_p == NULL) - return error; + if(server_p == NULL) + return error; - if(ServerConfSSL(server_p) && client_p->localClient->ssl_ctl == NULL) - { - return -5; - } + if(ServerConfSSL(server_p) && client_p->localClient->ssl_ctl == NULL) { + return -5; + } - attach_server_conf(client_p, server_p); + attach_server_conf(client_p, server_p); - /* clear ZIP/TB if they support but we dont want them */ + /* clear ZIP/TB if they support but we dont want them */ #ifdef HAVE_LIBZ - if(!ServerConfCompressed(server_p)) + if(!ServerConfCompressed(server_p)) #endif - ClearCap(client_p, CAP_ZIP); + ClearCap(client_p, CAP_ZIP); - if(!ServerConfTb(server_p)) - ClearCap(client_p, CAP_TB); + if(!ServerConfTb(server_p)) + ClearCap(client_p, CAP_TB); - return 0; + return 0; } /* @@ -382,87 +366,91 @@ check_server(const char *name, struct Client *client_p) void send_capabilities(struct Client *client_p, int cap_can_send) { - struct Capability *cap; - char msgbuf[BUFSIZE]; - char *t; - int tl; + struct Capability *cap; + char msgbuf[BUFSIZE]; + char *t; + int tl; - t = msgbuf; + t = msgbuf; - for (cap = captab; cap->name; ++cap) - { - if(cap->cap & cap_can_send) - { - tl = rb_sprintf(t, "%s ", cap->name); - t += tl; - } - } + for (cap = captab; cap->name; ++cap) { + if(cap->cap & cap_can_send) { + tl = rb_sprintf(t, "%s ", cap->name); + t += tl; + } + } - t--; - *t = '\0'; + t--; + *t = '\0'; - sendto_one(client_p, "CAPAB :%s", msgbuf); + sendto_one(client_p, "CAPAB :%s", msgbuf); } static void burst_ban(struct Client *client_p) { - rb_dlink_node *ptr; - struct ConfItem *aconf; - const char *type, *oper; - /* +5 for !,@,{,} and null */ - char operbuf[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; - char *p; - size_t melen; + rb_dlink_node *ptr; + struct ConfItem *aconf; + const char *type, *oper; + /* +5 for !,@,{,} and null */ + char operbuf[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; + char *p; + size_t melen; - melen = strlen(me.name); - RB_DLINK_FOREACH(ptr, prop_bans.head) - { - aconf = ptr->data; + melen = strlen(me.name); + RB_DLINK_FOREACH(ptr, prop_bans.head) { + aconf = ptr->data; - /* Skip expired stuff. */ - if(aconf->lifetime < rb_current_time()) - continue; - switch(aconf->status & ~CONF_ILLEGAL) - { - case CONF_KILL: type = "K"; break; - case CONF_DLINE: type = "D"; break; - case CONF_XLINE: type = "X"; break; - case CONF_RESV_NICK: type = "R"; break; - case CONF_RESV_CHANNEL: type = "R"; break; - default: - continue; - } - oper = aconf->info.oper; - if(aconf->flags & CONF_FLAGS_MYOPER) - { - /* Our operator{} names may not be meaningful - * to other servers, so rewrite to our server - * name. - */ - rb_strlcpy(operbuf, aconf->info.oper, sizeof buf); - p = strrchr(operbuf, '{'); - if (p != NULL && - operbuf + sizeof operbuf - p > (ptrdiff_t)(melen + 2)) - { - memcpy(p + 1, me.name, melen); - p[melen + 1] = '}'; - p[melen + 2] = '\0'; - oper = operbuf; - } - } - sendto_one(client_p, ":%s BAN %s %s %s %lu %d %d %s :%s%s%s", - me.id, - type, - aconf->user ? aconf->user : "*", aconf->host, - (unsigned long)aconf->created, - (int)(aconf->hold - aconf->created), - (int)(aconf->lifetime - aconf->created), - oper, - aconf->passwd, - aconf->spasswd ? "|" : "", - aconf->spasswd ? aconf->spasswd : ""); - } + /* Skip expired stuff. */ + if(aconf->lifetime < rb_current_time()) + continue; + switch(aconf->status & ~CONF_ILLEGAL) { + case CONF_KILL: + type = "K"; + break; + case CONF_DLINE: + type = "D"; + break; + case CONF_XLINE: + type = "X"; + break; + case CONF_RESV_NICK: + type = "R"; + break; + case CONF_RESV_CHANNEL: + type = "R"; + break; + default: + continue; + } + oper = aconf->info.oper; + if(aconf->flags & CONF_FLAGS_MYOPER) { + /* Our operator{} names may not be meaningful + * to other servers, so rewrite to our server + * name. + */ + rb_strlcpy(operbuf, aconf->info.oper, sizeof buf); + p = strrchr(operbuf, '{'); + if (p != NULL && + operbuf + sizeof operbuf - p > (ptrdiff_t)(melen + 2)) { + memcpy(p + 1, me.name, melen); + p[melen + 1] = '}'; + p[melen + 2] = '\0'; + oper = operbuf; + } + } + sendto_one(client_p, ":%s BAN %s %s %s %lu %d %d %s :%s%s%s", + me.id, + type, + aconf->user ? aconf->user : "*", aconf->host, + (unsigned long)aconf->created, + (int)(aconf->hold - aconf->created), + (int)(aconf->lifetime - aconf->created), + oper, + aconf->passwd, + aconf->spasswd ? "|" : "", + aconf->spasswd ? aconf->spasswd : ""); + } } /* burst_modes_TS6() @@ -472,58 +460,55 @@ burst_ban(struct Client *client_p) * side effects - client is sent a list of +b, +e, or +I modes */ static void -burst_modes_TS6(struct Client *client_p, struct Channel *chptr, - rb_dlink_list *list, char flag) +burst_modes_TS6(struct Client *client_p, struct Channel *chptr, + rb_dlink_list *list, char flag) { - rb_dlink_node *ptr; - struct Ban *banptr; - char *t; - int tlen; - int mlen; - int cur_len; + rb_dlink_node *ptr; + struct Ban *banptr; + char *t; + int tlen; + int mlen; + int cur_len; - cur_len = mlen = rb_sprintf(buf, ":%s BMASK %ld %s %c :", - me.id, (long) chptr->channelts, chptr->chname, flag); - t = buf + mlen; + cur_len = mlen = rb_sprintf(buf, ":%s BMASK %ld %s %c :", + me.id, (long) chptr->channelts, chptr->chname, flag); + t = buf + mlen; - RB_DLINK_FOREACH(ptr, list->head) - { - banptr = ptr->data; + RB_DLINK_FOREACH(ptr, list->head) { + banptr = ptr->data; - tlen = strlen(banptr->banstr) + 1; + tlen = strlen(banptr->banstr) + 1; - /* uh oh */ - if(cur_len + tlen > BUFSIZE - 3) - { - /* the one we're trying to send doesnt fit at all! */ - if(cur_len == mlen) - { - s_assert(0); - continue; - } + /* uh oh */ + if(cur_len + tlen > BUFSIZE - 3) { + /* the one we're trying to send doesnt fit at all! */ + if(cur_len == mlen) { + s_assert(0); + continue; + } - /* chop off trailing space and send.. */ - *(t-1) = '\0'; - sendto_one(client_p, "%s", buf); - cur_len = mlen; - t = buf + mlen; - } + /* chop off trailing space and send.. */ + *(t-1) = '\0'; + sendto_one(client_p, "%s", buf); + cur_len = mlen; + t = buf + mlen; + } - rb_sprintf(t, "%s ", banptr->banstr); - t += tlen; - cur_len += tlen; - } + rb_sprintf(t, "%s ", banptr->banstr); + t += tlen; + cur_len += tlen; + } - /* cant ever exit the loop above without having modified buf, - * chop off trailing space and send. - */ - *(t-1) = '\0'; - sendto_one(client_p, "%s", buf); + /* cant ever exit the loop above without having modified buf, + * chop off trailing space and send. + */ + *(t-1) = '\0'; + sendto_one(client_p, "%s", buf); } /* * burst_TS6 - * + * * inputs - client (server) to send nick towards * - client to send nick for * output - NONE @@ -532,176 +517,167 @@ burst_modes_TS6(struct Client *client_p, struct Channel *chptr, static void burst_TS6(struct Client *client_p) { - static char ubuf[BUFSIZE]; - struct Client *target_p; - struct Channel *chptr; - struct membership *msptr; - hook_data_client hclientinfo; - hook_data_channel hchaninfo; - rb_dlink_node *ptr; - rb_dlink_node *uptr; - char *t; - int tlen, mlen; - int cur_len = 0; - struct Metadata *md; - struct DictionaryIter iter; + static char ubuf[BUFSIZE]; + struct Client *target_p; + struct Channel *chptr; + struct membership *msptr; + hook_data_client hclientinfo; + hook_data_channel hchaninfo; + rb_dlink_node *ptr; + rb_dlink_node *uptr; + char *t; + int tlen, mlen; + int cur_len = 0; + struct Metadata *md; + struct DictionaryIter iter; - hclientinfo.client = hchaninfo.client = client_p; + hclientinfo.client = hchaninfo.client = client_p; - RB_DLINK_FOREACH(ptr, global_client_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, global_client_list.head) { + target_p = ptr->data; - if(!IsPerson(target_p)) - continue; + if(!IsPerson(target_p)) + continue; - send_umode(NULL, target_p, 0, 0, ubuf); - if(!*ubuf) - { - ubuf[0] = '+'; - ubuf[1] = '\0'; - } + send_umode(NULL, target_p, 0, 0, ubuf); + if(!*ubuf) { + ubuf[0] = '+'; + ubuf[1] = '\0'; + } - if(IsCapable(client_p, CAP_EUID)) - sendto_one(client_p, ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", - target_p->servptr->id, target_p->name, - target_p->hopcount + 1, - (long) target_p->tsinfo, ubuf, - target_p->username, target_p->host, - IsIPSpoof(target_p) ? "0" : target_p->sockhost, - target_p->id, - IsDynSpoof(target_p) ? target_p->orighost : "*", - EmptyString(target_p->user->suser) ? "*" : target_p->user->suser, - target_p->info); - else - sendto_one(client_p, ":%s UID %s %d %ld %s %s %s %s %s :%s", - target_p->servptr->id, target_p->name, - target_p->hopcount + 1, - (long) target_p->tsinfo, ubuf, - target_p->username, target_p->host, - IsIPSpoof(target_p) ? "0" : target_p->sockhost, - target_p->id, target_p->info); + if(IsCapable(client_p, CAP_EUID)) + sendto_one(client_p, ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", + target_p->servptr->id, target_p->name, + target_p->hopcount + 1, + (long) target_p->tsinfo, ubuf, + target_p->username, target_p->host, + IsIPSpoof(target_p) ? "0" : target_p->sockhost, + target_p->id, + IsDynSpoof(target_p) ? target_p->orighost : "*", + EmptyString(target_p->user->suser) ? "*" : target_p->user->suser, + target_p->info); + else + sendto_one(client_p, ":%s UID %s %d %ld %s %s %s %s %s :%s", + target_p->servptr->id, target_p->name, + target_p->hopcount + 1, + (long) target_p->tsinfo, ubuf, + target_p->username, target_p->host, + IsIPSpoof(target_p) ? "0" : target_p->sockhost, + target_p->id, target_p->info); - if(!EmptyString(target_p->certfp)) - sendto_one(client_p, ":%s ENCAP * CERTFP :%s", - use_id(target_p), target_p->certfp); + if(!EmptyString(target_p->certfp)) + sendto_one(client_p, ":%s ENCAP * CERTFP :%s", + use_id(target_p), target_p->certfp); - if(!IsCapable(client_p, CAP_EUID)) - { - if(IsDynSpoof(target_p)) - sendto_one(client_p, ":%s ENCAP * REALHOST %s", - use_id(target_p), target_p->orighost); - if(!EmptyString(target_p->user->suser)) - sendto_one(client_p, ":%s ENCAP * LOGIN %s", - use_id(target_p), target_p->user->suser); - } + if(!IsCapable(client_p, CAP_EUID)) { + if(IsDynSpoof(target_p)) + sendto_one(client_p, ":%s ENCAP * REALHOST %s", + use_id(target_p), target_p->orighost); + if(!EmptyString(target_p->user->suser)) + sendto_one(client_p, ":%s ENCAP * LOGIN %s", + use_id(target_p), target_p->user->suser); + } - DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) - { - sendto_one(client_p, ":%s ENCAP * METADATA SET %s %s :%s", - use_id(&me), use_id(target_p), md->name, md->value); - } + DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) { + sendto_one(client_p, ":%s ENCAP * METADATA SET %s %s :%s", + use_id(&me), use_id(target_p), md->name, md->value); + } - if(ConfigFileEntry.burst_away && !EmptyString(target_p->user->away)) - sendto_one(client_p, ":%s AWAY :%s", - use_id(target_p), - target_p->user->away); + if(ConfigFileEntry.burst_away && !EmptyString(target_p->user->away)) + sendto_one(client_p, ":%s AWAY :%s", + use_id(target_p), + target_p->user->away); - hclientinfo.target = target_p; - call_hook(h_burst_client, &hclientinfo); - } + hclientinfo.target = target_p; + call_hook(h_burst_client, &hclientinfo); + } - RB_DLINK_FOREACH(ptr, global_channel_list.head) - { - chptr = ptr->data; + RB_DLINK_FOREACH(ptr, global_channel_list.head) { + chptr = ptr->data; - if(*chptr->chname != '#') - continue; + if(*chptr->chname != '#') + continue; - cur_len = mlen = rb_sprintf(buf, ":%s SJOIN %ld %s %s :", me.id, - (long) chptr->channelts, chptr->chname, - channel_modes(chptr, client_p)); + cur_len = mlen = rb_sprintf(buf, ":%s SJOIN %ld %s %s :", me.id, + (long) chptr->channelts, chptr->chname, + channel_modes(chptr, client_p)); - t = buf + mlen; + t = buf + mlen; - RB_DLINK_FOREACH(uptr, chptr->members.head) - { - msptr = uptr->data; + RB_DLINK_FOREACH(uptr, chptr->members.head) { + msptr = uptr->data; - tlen = strlen(use_id(msptr->client_p)) + 1; - if(is_owner(msptr)) - tlen++; - if(is_admin(msptr)) - tlen++; - if(is_chanop(msptr)) - tlen++; - if(is_halfop(msptr)) - tlen++; - if(is_voiced(msptr)) - tlen++; + tlen = strlen(use_id(msptr->client_p)) + 1; + if(is_owner(msptr)) + tlen++; + if(is_admin(msptr)) + tlen++; + if(is_chanop(msptr)) + tlen++; + if(is_halfop(msptr)) + tlen++; + if(is_voiced(msptr)) + tlen++; - if(cur_len + tlen >= BUFSIZE - 3) - { - *(t-1) = '\0'; - sendto_one(client_p, "%s", buf); - cur_len = mlen; - t = buf + mlen; - } + if(cur_len + tlen >= BUFSIZE - 3) { + *(t-1) = '\0'; + sendto_one(client_p, "%s", buf); + cur_len = mlen; + t = buf + mlen; + } - rb_sprintf(t, "%s%s ", find_channel_status(msptr, 1), - use_id(msptr->client_p)); + rb_sprintf(t, "%s%s ", find_channel_status(msptr, 1), + use_id(msptr->client_p)); - cur_len += tlen; - t += tlen; - } + cur_len += tlen; + t += tlen; + } - if (rb_dlink_list_length(&chptr->members) > 0) - { - /* remove trailing space */ - *(t-1) = '\0'; - } - sendto_one(client_p, "%s", buf); + if (rb_dlink_list_length(&chptr->members) > 0) { + /* remove trailing space */ + *(t-1) = '\0'; + } + sendto_one(client_p, "%s", buf); - DICTIONARY_FOREACH(md, &iter, chptr->metadata) - { - /* don't bother bursting +J metadata */ - if(!(md->name[0] == 'K')) - sendto_one(client_p, ":%s ENCAP * METADATA SET %s %s :%s", - use_id(&me), chptr->chname, md->name, md->value); - } + DICTIONARY_FOREACH(md, &iter, chptr->metadata) { + /* don't bother bursting +J metadata */ + if(!(md->name[0] == 'K')) + sendto_one(client_p, ":%s ENCAP * METADATA SET %s %s :%s", + use_id(&me), chptr->chname, md->name, md->value); + } - if(rb_dlink_list_length(&chptr->banlist) > 0) - burst_modes_TS6(client_p, chptr, &chptr->banlist, 'b'); + if(rb_dlink_list_length(&chptr->banlist) > 0) + burst_modes_TS6(client_p, chptr, &chptr->banlist, 'b'); - if(IsCapable(client_p, CAP_EX) && - rb_dlink_list_length(&chptr->exceptlist) > 0) - burst_modes_TS6(client_p, chptr, &chptr->exceptlist, 'e'); + if(IsCapable(client_p, CAP_EX) && + rb_dlink_list_length(&chptr->exceptlist) > 0) + burst_modes_TS6(client_p, chptr, &chptr->exceptlist, 'e'); - if(IsCapable(client_p, CAP_IE) && - rb_dlink_list_length(&chptr->invexlist) > 0) - burst_modes_TS6(client_p, chptr, &chptr->invexlist, 'I'); + if(IsCapable(client_p, CAP_IE) && + rb_dlink_list_length(&chptr->invexlist) > 0) + burst_modes_TS6(client_p, chptr, &chptr->invexlist, 'I'); - if(rb_dlink_list_length(&chptr->quietlist) > 0) - burst_modes_TS6(client_p, chptr, &chptr->quietlist, 'q'); + if(rb_dlink_list_length(&chptr->quietlist) > 0) + burst_modes_TS6(client_p, chptr, &chptr->quietlist, 'q'); - if(IsCapable(client_p, CAP_TB) && chptr->topic != NULL) - sendto_one(client_p, ":%s TB %s %ld %s%s:%s", - me.id, chptr->chname, (long) chptr->topic_time, - ConfigChannel.burst_topicwho ? chptr->topic_info : "", - ConfigChannel.burst_topicwho ? " " : "", - chptr->topic); + if(IsCapable(client_p, CAP_TB) && chptr->topic != NULL) + sendto_one(client_p, ":%s TB %s %ld %s%s:%s", + me.id, chptr->chname, (long) chptr->topic_time, + ConfigChannel.burst_topicwho ? chptr->topic_info : "", + ConfigChannel.burst_topicwho ? " " : "", + chptr->topic); - if(IsCapable(client_p, CAP_MLOCK)) - sendto_one(client_p, ":%s MLOCK %ld %s :%s", - me.id, (long) chptr->channelts, chptr->chname, - EmptyString(chptr->mode_lock) ? "" : chptr->mode_lock); + if(IsCapable(client_p, CAP_MLOCK)) + sendto_one(client_p, ":%s MLOCK %ld %s :%s", + me.id, (long) chptr->channelts, chptr->chname, + EmptyString(chptr->mode_lock) ? "" : chptr->mode_lock); - hchaninfo.chptr = chptr; - call_hook(h_burst_channel, &hchaninfo); - } + hchaninfo.chptr = chptr; + call_hook(h_burst_channel, &hchaninfo); + } - hclientinfo.target = NULL; - call_hook(h_burst_finished, &hclientinfo); + hclientinfo.target = NULL; + call_hook(h_burst_finished, &hclientinfo); } /* @@ -714,25 +690,24 @@ burst_TS6(struct Client *client_p) const char * show_capabilities(struct Client *target_p) { - static char msgbuf[BUFSIZE]; - struct Capability *cap; + static char msgbuf[BUFSIZE]; + struct Capability *cap; - if(has_id(target_p)) - rb_strlcpy(msgbuf, " TS6", sizeof(msgbuf)); + if(has_id(target_p)) + rb_strlcpy(msgbuf, " TS6", sizeof(msgbuf)); - if(IsSSL(target_p)) - rb_strlcat(msgbuf, " SSL", sizeof(msgbuf)); + if(IsSSL(target_p)) + rb_strlcat(msgbuf, " SSL", sizeof(msgbuf)); - if(!IsServer(target_p) || !target_p->serv->caps) /* short circuit if no caps */ - return msgbuf + 1; + if(!IsServer(target_p) || !target_p->serv->caps) /* short circuit if no caps */ + return msgbuf + 1; - for (cap = captab; cap->cap; ++cap) - { - if(cap->cap & target_p->serv->caps) - rb_snprintf_append(msgbuf, sizeof(msgbuf), " %s", cap->name); - } + for (cap = captab; cap->cap; ++cap) { + if(cap->cap & target_p->serv->caps) + rb_snprintf_append(msgbuf, sizeof(msgbuf), " %s", cap->name); + } - return msgbuf + 1; + return msgbuf + 1; } /* @@ -745,229 +720,217 @@ show_capabilities(struct Client *target_p) int server_estab(struct Client *client_p) { - struct Client *target_p; - struct server_conf *server_p; - hook_data_client hdata; - char *host; - rb_dlink_node *ptr; - char note[HOSTLEN + 15]; + struct Client *target_p; + struct server_conf *server_p; + hook_data_client hdata; + char *host; + rb_dlink_node *ptr; + char note[HOSTLEN + 15]; - s_assert(NULL != client_p); - if(client_p == NULL) - return -1; + s_assert(NULL != client_p); + if(client_p == NULL) + return -1; - host = client_p->name; + host = client_p->name; - if((server_p = client_p->localClient->att_sconf) == NULL) - { - /* This shouldn't happen, better tell the ops... -A1kmm */ - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Warning: Lost connect{} block for server %s!", host); - return exit_client(client_p, client_p, client_p, "Lost connect{} block!"); - } + if((server_p = client_p->localClient->att_sconf) == NULL) { + /* This shouldn't happen, better tell the ops... -A1kmm */ + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Warning: Lost connect{} block for server %s!", host); + return exit_client(client_p, client_p, client_p, "Lost connect{} block!"); + } - /* We shouldn't have to check this, it should already done before - * server_estab is called. -A1kmm - */ - if(client_p->localClient->passwd) - { - memset(client_p->localClient->passwd, 0, strlen(client_p->localClient->passwd)); - rb_free(client_p->localClient->passwd); - client_p->localClient->passwd = NULL; - } + /* We shouldn't have to check this, it should already done before + * server_estab is called. -A1kmm + */ + if(client_p->localClient->passwd) { + memset(client_p->localClient->passwd, 0, strlen(client_p->localClient->passwd)); + rb_free(client_p->localClient->passwd); + client_p->localClient->passwd = NULL; + } - /* Its got identd , since its a server */ - SetGotId(client_p); + /* Its got identd , since its a server */ + SetGotId(client_p); - /* If there is something in the serv_list, it might be this - * connecting server.. - */ - if(!ServerInfo.hub && serv_list.head) - { - if(client_p != serv_list.head->data || serv_list.head->next) - { - ServerStats.is_ref++; - sendto_one(client_p, "ERROR :I'm a leaf not a hub"); - return exit_client(client_p, client_p, client_p, "I'm a leaf"); - } - } + /* If there is something in the serv_list, it might be this + * connecting server.. + */ + if(!ServerInfo.hub && serv_list.head) { + if(client_p != serv_list.head->data || serv_list.head->next) { + ServerStats.is_ref++; + sendto_one(client_p, "ERROR :I'm a leaf not a hub"); + return exit_client(client_p, client_p, client_p, "I'm a leaf"); + } + } - if(IsUnknown(client_p)) - { - /* the server may be linking based on certificate fingerprint now. --nenolod */ - sendto_one(client_p, "PASS %s TS %d :%s", - EmptyString(server_p->spasswd) ? "*" : server_p->spasswd, TS_CURRENT, me.id); + if(IsUnknown(client_p)) { + /* the server may be linking based on certificate fingerprint now. --nenolod */ + sendto_one(client_p, "PASS %s TS %d :%s", + EmptyString(server_p->spasswd) ? "*" : server_p->spasswd, TS_CURRENT, me.id); - /* pass info to new server */ - send_capabilities(client_p, default_server_capabs - | (ServerConfCompressed(server_p) ? CAP_ZIP_SUPPORTED : 0) - | (ServerConfTb(server_p) ? CAP_TB : 0)); + /* pass info to new server */ + send_capabilities(client_p, default_server_capabs + | (ServerConfCompressed(server_p) ? CAP_ZIP_SUPPORTED : 0) + | (ServerConfTb(server_p) ? CAP_TB : 0)); - sendto_one(client_p, "SERVER %s 1 :%s%s", - me.name, - ConfigServerHide.hidden ? "(H) " : "", - (me.info[0]) ? (me.info) : "IRCers United"); - } + sendto_one(client_p, "SERVER %s 1 :%s%s", + me.name, + ConfigServerHide.hidden ? "(H) " : "", + (me.info[0]) ? (me.info) : "IRCers United"); + } - if(!rb_set_buffers(client_p->localClient->F, READBUF_SIZE)) - ilog_error("rb_set_buffers failed for server"); + if(!rb_set_buffers(client_p->localClient->F, READBUF_SIZE)) + ilog_error("rb_set_buffers failed for server"); - /* Enable compression now */ - if(IsCapable(client_p, CAP_ZIP)) - { - start_zlib_session(client_p); - } - sendto_one(client_p, "SVINFO %d %d 0 :%ld", TS_CURRENT, TS_MIN, (long int)rb_current_time()); + /* Enable compression now */ + if(IsCapable(client_p, CAP_ZIP)) { + start_zlib_session(client_p); + } + sendto_one(client_p, "SVINFO %d %d 0 :%ld", TS_CURRENT, TS_MIN, (long int)rb_current_time()); - client_p->servptr = &me; + client_p->servptr = &me; - if(IsAnyDead(client_p)) - return CLIENT_EXITED; + if(IsAnyDead(client_p)) + return CLIENT_EXITED; - SetServer(client_p); + SetServer(client_p); - /* Update the capability combination usage counts */ - set_chcap_usage_counts(client_p); + /* Update the capability combination usage counts */ + set_chcap_usage_counts(client_p); - rb_dlinkAdd(client_p, &client_p->lnode, &me.serv->servers); - rb_dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &serv_list); - rb_dlinkAddTailAlloc(client_p, &global_serv_list); + rb_dlinkAdd(client_p, &client_p->lnode, &me.serv->servers); + rb_dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &serv_list); + rb_dlinkAddTailAlloc(client_p, &global_serv_list); - if(has_id(client_p)) - add_to_id_hash(client_p->id, client_p); + if(has_id(client_p)) + add_to_id_hash(client_p->id, client_p); - add_to_client_hash(client_p->name, client_p); - /* doesnt duplicate client_p->serv if allocated this struct already */ - make_server(client_p); + add_to_client_hash(client_p->name, client_p); + /* doesnt duplicate client_p->serv if allocated this struct already */ + make_server(client_p); - client_p->serv->caps = client_p->localClient->caps; + client_p->serv->caps = client_p->localClient->caps; - if(client_p->localClient->fullcaps) - { - client_p->serv->fullcaps = rb_strdup(client_p->localClient->fullcaps); - rb_free(client_p->localClient->fullcaps); - client_p->localClient->fullcaps = NULL; - } + if(client_p->localClient->fullcaps) { + client_p->serv->fullcaps = rb_strdup(client_p->localClient->fullcaps); + rb_free(client_p->localClient->fullcaps); + client_p->localClient->fullcaps = NULL; + } - client_p->serv->nameinfo = scache_connect(client_p->name, client_p->info, IsHidden(client_p)); - client_p->localClient->firsttime = rb_current_time(); - /* fixing eob timings.. -gnp */ + client_p->serv->nameinfo = scache_connect(client_p->name, client_p->info, IsHidden(client_p)); + client_p->localClient->firsttime = rb_current_time(); + /* fixing eob timings.. -gnp */ - if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > - (unsigned long)MaxConnectionCount) - MaxConnectionCount = rb_dlink_list_length(&lclient_list) + - rb_dlink_list_length(&serv_list); + if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > + (unsigned long)MaxConnectionCount) + MaxConnectionCount = rb_dlink_list_length(&lclient_list) + + rb_dlink_list_length(&serv_list); - /* Show the real host/IP to admins */ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Link with %s established: (%s) link", - client_p->name, - show_capabilities(client_p)); + /* Show the real host/IP to admins */ + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Link with %s established: (%s) link", + client_p->name, + show_capabilities(client_p)); - ilog(L_SERVER, "Link with %s established: (%s) link", - log_client_name(client_p, SHOW_IP), show_capabilities(client_p)); + ilog(L_SERVER, "Link with %s established: (%s) link", + log_client_name(client_p, SHOW_IP), show_capabilities(client_p)); - hdata.client = &me; - hdata.target = client_p; - call_hook(h_server_introduced, &hdata); + hdata.client = &me; + hdata.target = client_p; + call_hook(h_server_introduced, &hdata); - rb_snprintf(note, sizeof(note), "Server: %s", client_p->name); - rb_note(client_p->localClient->F, note); + rb_snprintf(note, sizeof(note), "Server: %s", client_p->name); + rb_note(client_p->localClient->F, note); - /* - ** Old sendto_serv_but_one() call removed because we now - ** need to send different names to different servers - ** (domain name matching) Send new server to other servers. - */ - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + /* + ** Old sendto_serv_but_one() call removed because we now + ** need to send different names to different servers + ** (domain name matching) Send new server to other servers. + */ + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - if(target_p == client_p) - continue; + if(target_p == client_p) + continue; - if(has_id(target_p) && has_id(client_p)) - { - sendto_one(target_p, ":%s SID %s 2 %s :%s%s", - me.id, client_p->name, client_p->id, - IsHidden(client_p) ? "(H) " : "", client_p->info); + if(has_id(target_p) && has_id(client_p)) { + sendto_one(target_p, ":%s SID %s 2 %s :%s%s", + me.id, client_p->name, client_p->id, + IsHidden(client_p) ? "(H) " : "", client_p->info); - if(IsCapable(target_p, CAP_ENCAP) && - !EmptyString(client_p->serv->fullcaps)) - sendto_one(target_p, ":%s ENCAP * GCAP :%s", - client_p->id, client_p->serv->fullcaps); - } - else - { - sendto_one(target_p, ":%s SERVER %s 2 :%s%s", - me.name, client_p->name, - IsHidden(client_p) ? "(H) " : "", client_p->info); + if(IsCapable(target_p, CAP_ENCAP) && + !EmptyString(client_p->serv->fullcaps)) + sendto_one(target_p, ":%s ENCAP * GCAP :%s", + client_p->id, client_p->serv->fullcaps); + } else { + sendto_one(target_p, ":%s SERVER %s 2 :%s%s", + me.name, client_p->name, + IsHidden(client_p) ? "(H) " : "", client_p->info); - if(IsCapable(target_p, CAP_ENCAP) && - !EmptyString(client_p->serv->fullcaps)) - sendto_one(target_p, ":%s ENCAP * GCAP :%s", - client_p->name, client_p->serv->fullcaps); - } - } + if(IsCapable(target_p, CAP_ENCAP) && + !EmptyString(client_p->serv->fullcaps)) + sendto_one(target_p, ":%s ENCAP * GCAP :%s", + client_p->name, client_p->serv->fullcaps); + } + } - /* - ** Pass on my client information to the new server - ** - ** First, pass only servers (idea is that if the link gets - ** cancelled beacause the server was already there, - ** there are no NICK's to be cancelled...). Of course, - ** if cancellation occurs, all this info is sent anyway, - ** and I guess the link dies when a read is attempted...? --msa - ** - ** Note: Link cancellation to occur at this point means - ** that at least two servers from my fragment are building - ** up connection this other fragment at the same time, it's - ** a race condition, not the normal way of operation... - ** - ** ALSO NOTE: using the get_client_name for server names-- - ** see previous *WARNING*!!! (Also, original inpath - ** is destroyed...) - */ - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - target_p = ptr->data; + /* + ** Pass on my client information to the new server + ** + ** First, pass only servers (idea is that if the link gets + ** cancelled beacause the server was already there, + ** there are no NICK's to be cancelled...). Of course, + ** if cancellation occurs, all this info is sent anyway, + ** and I guess the link dies when a read is attempted...? --msa + ** + ** Note: Link cancellation to occur at this point means + ** that at least two servers from my fragment are building + ** up connection this other fragment at the same time, it's + ** a race condition, not the normal way of operation... + ** + ** ALSO NOTE: using the get_client_name for server names-- + ** see previous *WARNING*!!! (Also, original inpath + ** is destroyed...) + */ + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + target_p = ptr->data; - /* target_p->from == target_p for target_p == client_p */ - if(IsMe(target_p) || target_p->from == client_p) - continue; + /* target_p->from == target_p for target_p == client_p */ + if(IsMe(target_p) || target_p->from == client_p) + continue; - /* presumption, if target has an id, so does its uplink */ - if(has_id(client_p) && has_id(target_p)) - sendto_one(client_p, ":%s SID %s %d %s :%s%s", - target_p->servptr->id, target_p->name, - target_p->hopcount + 1, target_p->id, - IsHidden(target_p) ? "(H) " : "", target_p->info); - else - sendto_one(client_p, ":%s SERVER %s %d :%s%s", - target_p->servptr->name, - target_p->name, target_p->hopcount + 1, - IsHidden(target_p) ? "(H) " : "", target_p->info); + /* presumption, if target has an id, so does its uplink */ + if(has_id(client_p) && has_id(target_p)) + sendto_one(client_p, ":%s SID %s %d %s :%s%s", + target_p->servptr->id, target_p->name, + target_p->hopcount + 1, target_p->id, + IsHidden(target_p) ? "(H) " : "", target_p->info); + else + sendto_one(client_p, ":%s SERVER %s %d :%s%s", + target_p->servptr->name, + target_p->name, target_p->hopcount + 1, + IsHidden(target_p) ? "(H) " : "", target_p->info); - if(IsCapable(client_p, CAP_ENCAP) && - !EmptyString(target_p->serv->fullcaps)) - sendto_one(client_p, ":%s ENCAP * GCAP :%s", - get_id(target_p, client_p), - target_p->serv->fullcaps); - } + if(IsCapable(client_p, CAP_ENCAP) && + !EmptyString(target_p->serv->fullcaps)) + sendto_one(client_p, ":%s ENCAP * GCAP :%s", + get_id(target_p, client_p), + target_p->serv->fullcaps); + } - if(IsCapable(client_p, CAP_BAN)) - burst_ban(client_p); + if(IsCapable(client_p, CAP_BAN)) + burst_ban(client_p); - burst_TS6(client_p); + burst_TS6(client_p); - /* Always send a PING after connect burst is done */ - sendto_one(client_p, "PING :%s", get_id(&me, client_p)); + /* Always send a PING after connect burst is done */ + sendto_one(client_p, "PING :%s", get_id(&me, client_p)); - free_pre_client(client_p); + free_pre_client(client_p); - send_pop_queue(client_p); + send_pop_queue(client_p); - return 0; + return 0; } /* @@ -979,136 +942,127 @@ server_estab(struct Client *client_p) static int serv_connect_resolved(struct Client *client_p) { - struct rb_sockaddr_storage myipnum; - char vhoststr[HOSTIPLEN]; - struct server_conf *server_p; - uint16_t port; + struct rb_sockaddr_storage myipnum; + char vhoststr[HOSTIPLEN]; + struct server_conf *server_p; + uint16_t port; - if((server_p = client_p->localClient->att_sconf) == NULL) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Lost connect{} block for %s", - client_p->name); - exit_client(client_p, client_p, &me, "Lost connect{} block"); - return 0; - } + if((server_p = client_p->localClient->att_sconf) == NULL) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Lost connect{} block for %s", + client_p->name); + exit_client(client_p, client_p, &me, "Lost connect{} block"); + return 0; + } #ifdef RB_IPV6 - if(client_p->localClient->ip.ss_family == AF_INET6) - port = ntohs(((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port); - else + if(client_p->localClient->ip.ss_family == AF_INET6) + port = ntohs(((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port); + else #endif - port = ntohs(((struct sockaddr_in *)&client_p->localClient->ip)->sin_port); + port = ntohs(((struct sockaddr_in *)&client_p->localClient->ip)->sin_port); + + if(ServerConfVhosted(server_p)) { + memcpy(&myipnum, &server_p->my_ipnum, sizeof(myipnum)); + ((struct sockaddr_in *)&myipnum)->sin_port = 0; + myipnum.ss_family = server_p->aftype; + + } else if(server_p->aftype == AF_INET && ServerInfo.specific_ipv4_vhost) { + memcpy(&myipnum, &ServerInfo.ip, sizeof(myipnum)); + ((struct sockaddr_in *)&myipnum)->sin_port = 0; + myipnum.ss_family = AF_INET; + SET_SS_LEN(&myipnum, sizeof(struct sockaddr_in)); + } - if(ServerConfVhosted(server_p)) - { - memcpy(&myipnum, &server_p->my_ipnum, sizeof(myipnum)); - ((struct sockaddr_in *)&myipnum)->sin_port = 0; - myipnum.ss_family = server_p->aftype; - - } - else if(server_p->aftype == AF_INET && ServerInfo.specific_ipv4_vhost) - { - memcpy(&myipnum, &ServerInfo.ip, sizeof(myipnum)); - ((struct sockaddr_in *)&myipnum)->sin_port = 0; - myipnum.ss_family = AF_INET; - SET_SS_LEN(&myipnum, sizeof(struct sockaddr_in)); - } - #ifdef RB_IPV6 - else if((server_p->aftype == AF_INET6) && ServerInfo.specific_ipv6_vhost) - { - memcpy(&myipnum, &ServerInfo.ip6, sizeof(myipnum)); - ((struct sockaddr_in6 *)&myipnum)->sin6_port = 0; - myipnum.ss_family = AF_INET6; - SET_SS_LEN(&myipnum, sizeof(struct sockaddr_in6)); - } + else if((server_p->aftype == AF_INET6) && ServerInfo.specific_ipv6_vhost) { + memcpy(&myipnum, &ServerInfo.ip6, sizeof(myipnum)); + ((struct sockaddr_in6 *)&myipnum)->sin6_port = 0; + myipnum.ss_family = AF_INET6; + SET_SS_LEN(&myipnum, sizeof(struct sockaddr_in6)); + } #endif - else - { - /* log */ - ilog(L_SERVER, "Connecting to %s[%s] port %d (%s)", client_p->name, client_p->sockhost, port, + else { + /* log */ + ilog(L_SERVER, "Connecting to %s[%s] port %d (%s)", client_p->name, client_p->sockhost, port, #ifdef RB_IPV6 - server_p->aftype == AF_INET6 ? "IPv6" : + server_p->aftype == AF_INET6 ? "IPv6" : #endif - (server_p->aftype == AF_INET ? "IPv4" : "?")); + (server_p->aftype == AF_INET ? "IPv4" : "?")); - if(ServerConfSSL(server_p)) - { - rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, - NULL, 0, serv_connect_ssl_callback, - client_p, ConfigFileEntry.connect_timeout); - } - else - rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, - NULL, 0, serv_connect_callback, - client_p, ConfigFileEntry.connect_timeout); - return 1; - } + if(ServerConfSSL(server_p)) { + rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, + NULL, 0, serv_connect_ssl_callback, + client_p, ConfigFileEntry.connect_timeout); + } else + rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, + NULL, 0, serv_connect_callback, + client_p, ConfigFileEntry.connect_timeout); + return 1; + } - /* log */ - rb_inet_ntop_sock((struct sockaddr *)&myipnum, vhoststr, sizeof vhoststr); - ilog(L_SERVER, "Connecting to %s[%s] port %d (%s) (vhost %s)", client_p->name, client_p->sockhost, port, + /* log */ + rb_inet_ntop_sock((struct sockaddr *)&myipnum, vhoststr, sizeof vhoststr); + ilog(L_SERVER, "Connecting to %s[%s] port %d (%s) (vhost %s)", client_p->name, client_p->sockhost, port, #ifdef RB_IPV6 - server_p->aftype == AF_INET6 ? "IPv6" : + server_p->aftype == AF_INET6 ? "IPv6" : #endif - (server_p->aftype == AF_INET ? "IPv4" : "?"), vhoststr); + (server_p->aftype == AF_INET ? "IPv4" : "?"), vhoststr); - if(ServerConfSSL(server_p)) - rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, - (struct sockaddr *) &myipnum, - GET_SS_LEN(&myipnum), serv_connect_ssl_callback, client_p, - ConfigFileEntry.connect_timeout); - else - rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, - (struct sockaddr *) &myipnum, - GET_SS_LEN(&myipnum), serv_connect_callback, client_p, - ConfigFileEntry.connect_timeout); + if(ServerConfSSL(server_p)) + rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, + (struct sockaddr *) &myipnum, + GET_SS_LEN(&myipnum), serv_connect_ssl_callback, client_p, + ConfigFileEntry.connect_timeout); + else + rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&client_p->localClient->ip, + (struct sockaddr *) &myipnum, + GET_SS_LEN(&myipnum), serv_connect_callback, client_p, + ConfigFileEntry.connect_timeout); - return 1; + return 1; } static void serv_connect_dns_callback(void *vptr, struct DNSReply *reply) { - struct Client *client_p = vptr; - uint16_t port; + struct Client *client_p = vptr; + uint16_t port; - rb_free(client_p->localClient->dnsquery); - client_p->localClient->dnsquery = NULL; + rb_free(client_p->localClient->dnsquery); + client_p->localClient->dnsquery = NULL; - if (reply == NULL) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Cannot resolve hostname for %s", - client_p->name); - ilog(L_SERVER, "Cannot resolve hostname for %s", - log_client_name(client_p, HIDE_IP)); - exit_client(client_p, client_p, &me, "Cannot resolve hostname"); - return; - } + if (reply == NULL) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Cannot resolve hostname for %s", + client_p->name); + ilog(L_SERVER, "Cannot resolve hostname for %s", + log_client_name(client_p, HIDE_IP)); + exit_client(client_p, client_p, &me, "Cannot resolve hostname"); + return; + } #ifdef RB_IPV6 - if(reply->addr.ss_family == AF_INET6) - port = ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port; - else + if(reply->addr.ss_family == AF_INET6) + port = ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port; + else #endif - port = ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port; - memcpy(&client_p->localClient->ip, &reply->addr, sizeof(client_p->localClient->ip)); + port = ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port; + memcpy(&client_p->localClient->ip, &reply->addr, sizeof(client_p->localClient->ip)); #ifdef RB_IPV6 - if(reply->addr.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port = port; - else + if(reply->addr.ss_family == AF_INET6) + ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port = port; + else #endif - ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = port; - /* Set sockhost properly now -- jilles */ - rb_inet_ntop_sock((struct sockaddr *)&client_p->localClient->ip, - client_p->sockhost, sizeof client_p->sockhost); - serv_connect_resolved(client_p); + ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = port; + /* Set sockhost properly now -- jilles */ + rb_inet_ntop_sock((struct sockaddr *)&client_p->localClient->ip, + client_p->sockhost, sizeof client_p->sockhost); + serv_connect_resolved(client_p); } /* * serv_connect() - initiate a server connection * - * inputs - pointer to conf + * inputs - pointer to conf * - pointer to client doing the connet * output - * side effects - @@ -1125,159 +1079,148 @@ serv_connect_dns_callback(void *vptr, struct DNSReply *reply) int serv_connect(struct server_conf *server_p, struct Client *by) { - struct Client *client_p; - struct rb_sockaddr_storage theiripnum; - rb_fde_t *F; - char note[HOSTLEN + 10]; + struct Client *client_p; + struct rb_sockaddr_storage theiripnum; + rb_fde_t *F; + char note[HOSTLEN + 10]; - s_assert(server_p != NULL); - if(server_p == NULL) - return 0; + s_assert(server_p != NULL); + if(server_p == NULL) + return 0; - /* - * Make sure this server isn't already connected - */ - if((client_p = find_server(NULL, server_p->name))) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Server %s already present from %s", - server_p->name, client_p->name); - if(by && IsPerson(by) && !MyClient(by)) - sendto_one_notice(by, ":Server %s already present from %s", - server_p->name, client_p->name); - return 0; - } + /* + * Make sure this server isn't already connected + */ + if((client_p = find_server(NULL, server_p->name))) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Server %s already present from %s", + server_p->name, client_p->name); + if(by && IsPerson(by) && !MyClient(by)) + sendto_one_notice(by, ":Server %s already present from %s", + server_p->name, client_p->name); + return 0; + } - /* create a socket for the server connection */ - if((F = rb_socket(server_p->aftype, SOCK_STREAM, 0, NULL)) == NULL) - { - ilog_error("opening a stream socket"); - return 0; - } + /* create a socket for the server connection */ + if((F = rb_socket(server_p->aftype, SOCK_STREAM, 0, NULL)) == NULL) { + ilog_error("opening a stream socket"); + return 0; + } - rb_snprintf(note, sizeof note, "Server: %s", server_p->name); - rb_note(F, note); + rb_snprintf(note, sizeof note, "Server: %s", server_p->name); + rb_note(F, note); - /* Create a local client */ - client_p = make_client(NULL); + /* Create a local client */ + client_p = make_client(NULL); - /* Copy in the server, hostname, fd - * The sockhost may be a hostname, this will be corrected later - * -- jilles - */ - rb_strlcpy(client_p->name, server_p->name, sizeof(client_p->name)); - rb_strlcpy(client_p->host, server_p->host, sizeof(client_p->host)); - rb_strlcpy(client_p->sockhost, server_p->host, sizeof(client_p->sockhost)); - client_p->localClient->F = F; - add_to_cli_fd_hash(client_p); + /* Copy in the server, hostname, fd + * The sockhost may be a hostname, this will be corrected later + * -- jilles + */ + rb_strlcpy(client_p->name, server_p->name, sizeof(client_p->name)); + rb_strlcpy(client_p->host, server_p->host, sizeof(client_p->host)); + rb_strlcpy(client_p->sockhost, server_p->host, sizeof(client_p->sockhost)); + client_p->localClient->F = F; + add_to_cli_fd_hash(client_p); - /* - * Set up the initial server evilness, ripped straight from - * connect_server(), so don't blame me for it being evil. - * -- adrian - */ + /* + * Set up the initial server evilness, ripped straight from + * connect_server(), so don't blame me for it being evil. + * -- adrian + */ - if(!rb_set_buffers(client_p->localClient->F, READBUF_SIZE)) - { - ilog_error("setting the buffer size for a server connection"); - } + if(!rb_set_buffers(client_p->localClient->F, READBUF_SIZE)) { + ilog_error("setting the buffer size for a server connection"); + } - /* - * Attach config entries to client here rather than in - * serv_connect_callback(). This to avoid null pointer references. - */ - attach_server_conf(client_p, server_p); + /* + * Attach config entries to client here rather than in + * serv_connect_callback(). This to avoid null pointer references. + */ + attach_server_conf(client_p, server_p); - /* - * at this point we have a connection in progress and C/N lines - * attached to the client, the socket info should be saved in the - * client and it should either be resolved or have a valid address. - * - * The socket has been connected or connect is in progress. - */ - make_server(client_p); - if(by && IsPerson(by)) - { - strcpy(client_p->serv->by, by->name); - if(client_p->serv->user) - free_user(client_p->serv->user, NULL); - client_p->serv->user = by->user; - by->user->refcnt++; - } - else - { - strcpy(client_p->serv->by, "AutoConn."); - if(client_p->serv->user) - free_user(client_p->serv->user, NULL); - client_p->serv->user = NULL; - } - SetConnecting(client_p); - rb_dlinkAddTail(client_p, &client_p->node, &global_client_list); + /* + * at this point we have a connection in progress and C/N lines + * attached to the client, the socket info should be saved in the + * client and it should either be resolved or have a valid address. + * + * The socket has been connected or connect is in progress. + */ + make_server(client_p); + if(by && IsPerson(by)) { + strcpy(client_p->serv->by, by->name); + if(client_p->serv->user) + free_user(client_p->serv->user, NULL); + client_p->serv->user = by->user; + by->user->refcnt++; + } else { + strcpy(client_p->serv->by, "AutoConn."); + if(client_p->serv->user) + free_user(client_p->serv->user, NULL); + client_p->serv->user = NULL; + } + SetConnecting(client_p); + rb_dlinkAddTail(client_p, &client_p->node, &global_client_list); - if (rb_inet_pton_sock(server_p->host, (struct sockaddr *)&theiripnum) > 0) - { - memcpy(&client_p->localClient->ip, &theiripnum, sizeof(client_p->localClient->ip)); + if (rb_inet_pton_sock(server_p->host, (struct sockaddr *)&theiripnum) > 0) { + memcpy(&client_p->localClient->ip, &theiripnum, sizeof(client_p->localClient->ip)); #ifdef RB_IPV6 - if(theiripnum.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port = htons(server_p->port); - else + if(theiripnum.ss_family == AF_INET6) + ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port = htons(server_p->port); + else #endif - ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = htons(server_p->port); + ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = htons(server_p->port); - return serv_connect_resolved(client_p); - } - else - { + return serv_connect_resolved(client_p); + } else { #ifdef RB_IPV6 - if(theiripnum.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port = htons(server_p->port); - else + if(theiripnum.ss_family == AF_INET6) + ((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port = htons(server_p->port); + else #endif - ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = htons(server_p->port); + ((struct sockaddr_in *)&client_p->localClient->ip)->sin_port = htons(server_p->port); - client_p->localClient->dnsquery = rb_malloc(sizeof(struct DNSQuery)); - client_p->localClient->dnsquery->ptr = client_p; - client_p->localClient->dnsquery->callback = serv_connect_dns_callback; - gethost_byname_type(server_p->host, client_p->localClient->dnsquery, + client_p->localClient->dnsquery = rb_malloc(sizeof(struct DNSQuery)); + client_p->localClient->dnsquery->ptr = client_p; + client_p->localClient->dnsquery->callback = serv_connect_dns_callback; + gethost_byname_type(server_p->host, client_p->localClient->dnsquery, #ifdef RB_IPV6 - server_p->aftype == AF_INET6 ? T_AAAA : + server_p->aftype == AF_INET6 ? T_AAAA : #endif - T_A); - return 1; - } + T_A); + return 1; + } } static void serv_connect_ssl_callback(rb_fde_t *F, int status, void *data) { - struct Client *client_p = data; - rb_fde_t *xF[2]; - rb_connect_sockaddr(F, (struct sockaddr *)&client_p->localClient->ip, sizeof(client_p->localClient->ip)); - if(status != RB_OK) - { - /* Print error message, just like non-SSL. */ - serv_connect_callback(F, status, data); - return; - } - if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF[0], &xF[1], "Outgoing ssld connection") == -1) - { - ilog_error("rb_socketpair failed for server"); - serv_connect_callback(F, RB_ERROR, data); - return; - - } - del_from_cli_fd_hash(client_p); - client_p->localClient->F = xF[0]; - add_to_cli_fd_hash(client_p); + struct Client *client_p = data; + rb_fde_t *xF[2]; + rb_connect_sockaddr(F, (struct sockaddr *)&client_p->localClient->ip, sizeof(client_p->localClient->ip)); + if(status != RB_OK) { + /* Print error message, just like non-SSL. */ + serv_connect_callback(F, status, data); + return; + } + if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF[0], &xF[1], "Outgoing ssld connection") == -1) { + ilog_error("rb_socketpair failed for server"); + serv_connect_callback(F, RB_ERROR, data); + return; - client_p->localClient->ssl_ctl = start_ssld_connect(F, xF[1], rb_get_fd(xF[0])); - SetSSL(client_p); - serv_connect_callback(client_p->localClient->F, RB_OK, client_p); + } + del_from_cli_fd_hash(client_p); + client_p->localClient->F = xF[0]; + add_to_cli_fd_hash(client_p); + + client_p->localClient->ssl_ctl = start_ssld_connect(F, xF[1], rb_get_fd(xF[0])); + SetSSL(client_p); + serv_connect_callback(client_p->localClient->F, RB_OK, client_p); } /* * serv_connect_callback() - complete a server connection. - * + * * This routine is called after the server connection attempt has * completed. If unsucessful, an error is sent to ops and the client * is closed. If sucessful, it goes through the initialisation/check @@ -1287,103 +1230,96 @@ serv_connect_ssl_callback(rb_fde_t *F, int status, void *data) static void serv_connect_callback(rb_fde_t *F, int status, void *data) { - struct Client *client_p = data; - struct server_conf *server_p; - char *errstr; + struct Client *client_p = data; + struct server_conf *server_p; + char *errstr; - /* First, make sure its a real client! */ - s_assert(client_p != NULL); - s_assert(client_p->localClient->F == F); + /* First, make sure its a real client! */ + s_assert(client_p != NULL); + s_assert(client_p->localClient->F == F); - if(client_p == NULL) - return; + if(client_p == NULL) + return; - /* while we were waiting for the callback, its possible this already - * linked in.. --fl - */ - if(find_server(NULL, client_p->name) != NULL) - { - exit_client(client_p, client_p, &me, "Server Exists"); - return; - } + /* while we were waiting for the callback, its possible this already + * linked in.. --fl + */ + if(find_server(NULL, client_p->name) != NULL) { + exit_client(client_p, client_p, &me, "Server Exists"); + return; + } - if(client_p->localClient->ssl_ctl == NULL) - rb_connect_sockaddr(F, (struct sockaddr *)&client_p->localClient->ip, sizeof(client_p->localClient->ip)); + if(client_p->localClient->ssl_ctl == NULL) + rb_connect_sockaddr(F, (struct sockaddr *)&client_p->localClient->ip, sizeof(client_p->localClient->ip)); - /* Check the status */ - if(status != RB_OK) - { - /* COMM_ERR_TIMEOUT wont have an errno associated with it, - * the others will.. --fl - */ - if(status == RB_ERR_TIMEOUT) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Error connecting to %s[%s]: %s", - client_p->name, - client_p->sockhost, - rb_errstr(status)); - ilog(L_SERVER, "Error connecting to %s[%s]: %s", - client_p->name, client_p->sockhost, - rb_errstr(status)); - } - else - { - errstr = strerror(rb_get_sockerr(F)); - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "Error connecting to %s[%s]: %s (%s)", - client_p->name, - "255.255.255.255", - rb_errstr(status), errstr); - ilog(L_SERVER, "Error connecting to %s[%s]: %s (%s)", - client_p->name, client_p->sockhost, - rb_errstr(status), errstr); - } + /* Check the status */ + if(status != RB_OK) { + /* COMM_ERR_TIMEOUT wont have an errno associated with it, + * the others will.. --fl + */ + if(status == RB_ERR_TIMEOUT) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Error connecting to %s[%s]: %s", + client_p->name, + client_p->sockhost, + rb_errstr(status)); + ilog(L_SERVER, "Error connecting to %s[%s]: %s", + client_p->name, client_p->sockhost, + rb_errstr(status)); + } else { + errstr = strerror(rb_get_sockerr(F)); + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "Error connecting to %s[%s]: %s (%s)", + client_p->name, + "255.255.255.255", + rb_errstr(status), errstr); + ilog(L_SERVER, "Error connecting to %s[%s]: %s (%s)", + client_p->name, client_p->sockhost, + rb_errstr(status), errstr); + } - exit_client(client_p, client_p, &me, rb_errstr(status)); - return; - } + exit_client(client_p, client_p, &me, rb_errstr(status)); + return; + } - /* COMM_OK, so continue the connection procedure */ - /* Get the C/N lines */ - if((server_p = client_p->localClient->att_sconf) == NULL) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Lost connect{} block for %s", - client_p->name); - exit_client(client_p, client_p, &me, "Lost connect{} block"); - return; - } + /* COMM_OK, so continue the connection procedure */ + /* Get the C/N lines */ + if((server_p = client_p->localClient->att_sconf) == NULL) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Lost connect{} block for %s", + client_p->name); + exit_client(client_p, client_p, &me, "Lost connect{} block"); + return; + } - /* Next, send the initial handshake */ - SetHandshake(client_p); + /* Next, send the initial handshake */ + SetHandshake(client_p); - /* the server may be linking based on certificate fingerprint now. --nenolod */ - sendto_one(client_p, "PASS %s TS %d :%s", - EmptyString(server_p->spasswd) ? "*" : server_p->spasswd, TS_CURRENT, me.id); + /* the server may be linking based on certificate fingerprint now. --nenolod */ + sendto_one(client_p, "PASS %s TS %d :%s", + EmptyString(server_p->spasswd) ? "*" : server_p->spasswd, TS_CURRENT, me.id); - /* pass my info to the new server */ - send_capabilities(client_p, default_server_capabs - | (ServerConfCompressed(server_p) ? CAP_ZIP_SUPPORTED : 0) - | (ServerConfTb(server_p) ? CAP_TB : 0)); + /* pass my info to the new server */ + send_capabilities(client_p, default_server_capabs + | (ServerConfCompressed(server_p) ? CAP_ZIP_SUPPORTED : 0) + | (ServerConfTb(server_p) ? CAP_TB : 0)); - sendto_one(client_p, "SERVER %s 1 :%s%s", - me.name, - ConfigServerHide.hidden ? "(H) " : "", me.info); + sendto_one(client_p, "SERVER %s 1 :%s%s", + me.name, + ConfigServerHide.hidden ? "(H) " : "", me.info); - /* - * If we've been marked dead because a send failed, just exit - * here now and save everyone the trouble of us ever existing. - */ - if(IsAnyDead(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, - "%s went dead during handshake", client_p->name); - exit_client(client_p, client_p, &me, "Went dead during handshake"); - return; - } + /* + * If we've been marked dead because a send failed, just exit + * here now and save everyone the trouble of us ever existing. + */ + if(IsAnyDead(client_p)) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, + "%s went dead during handshake", client_p->name); + exit_client(client_p, client_p, &me, "Went dead during handshake"); + return; + } - /* don't move to serv_list yet -- we haven't sent a burst! */ + /* don't move to serv_list yet -- we haven't sent a burst! */ - /* If we get here, we're ok, so lets start reading some data */ - read_packet(F, client_p); + /* If we get here, we're ok, so lets start reading some data */ + read_packet(F, client_p); } diff --git a/src/s_user.c b/src/s_user.c index 63ed445..5bcca92 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -61,73 +61,73 @@ char umodebuf[128]; static int orphaned_umodes = 0; int user_modes[256] = { - /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */ - /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */ - /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */ - /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */ - 0, /* @ */ - 0, /* A */ - UMODE_BOT, /* B */ - UMODE_NOCTCP, /* C */ - UMODE_DEAF, /* D */ - 0, /* E */ - 0, /* F */ - UMODE_SCALLERID, /* G */ - 0, /* H */ - UMODE_HIDECHANS, /* I */ - 0, /* J */ - 0, /* K */ - 0, /* L */ - 0, /* M */ - 0, /* N */ - 0, /* O */ - 0, /* P */ - UMODE_NOFORWARD, /* Q */ - UMODE_REGONLYMSG, /* R */ - UMODE_SERVICE, /* S */ - 0, /* T */ - 0, /* U */ - UMODE_NOINVITE, /* V */ - 0, /* W */ - 0, /* X */ - 0, /* Y */ - UMODE_SSLCLIENT, /* Z */ - /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */ - UMODE_ADMIN, /* a */ - 0, /* b */ - 0, /* c */ - 0, /* d */ - 0, /* e */ - 0, /* f */ - UMODE_CALLERID, /* g */ - 0, /* h */ - UMODE_INVISIBLE, /* i */ - 0, /* j */ - 0, /* k */ - UMODE_LOCOPS, /* l */ - 0, /* m */ - 0, /* n */ - UMODE_OPER, /* o */ - UMODE_OVERRIDE, /* p */ - 0, /* q */ - 0, /* r */ - UMODE_SERVNOTICE, /* s */ - 0, /* t */ - 0, /* u */ - 0, /* v */ - UMODE_WALLOP, /* w */ - 0, /* x */ - 0, /* y */ - UMODE_OPERWALL, /* z */ - /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */ - /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ - /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ - /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */ - /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */ - /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */ - /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */ - /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */ - /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */ + /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */ + /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */ + /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */ + /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */ + 0, /* @ */ + 0, /* A */ + UMODE_BOT, /* B */ + UMODE_NOCTCP, /* C */ + UMODE_DEAF, /* D */ + 0, /* E */ + 0, /* F */ + UMODE_SCALLERID, /* G */ + 0, /* H */ + UMODE_HIDECHANS, /* I */ + 0, /* J */ + 0, /* K */ + 0, /* L */ + 0, /* M */ + 0, /* N */ + 0, /* O */ + 0, /* P */ + UMODE_NOFORWARD, /* Q */ + UMODE_REGONLYMSG, /* R */ + UMODE_SERVICE, /* S */ + 0, /* T */ + 0, /* U */ + UMODE_NOINVITE, /* V */ + 0, /* W */ + 0, /* X */ + 0, /* Y */ + UMODE_SSLCLIENT, /* Z */ + /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */ + UMODE_ADMIN, /* a */ + 0, /* b */ + 0, /* c */ + 0, /* d */ + 0, /* e */ + 0, /* f */ + UMODE_CALLERID, /* g */ + 0, /* h */ + UMODE_INVISIBLE, /* i */ + 0, /* j */ + 0, /* k */ + UMODE_LOCOPS, /* l */ + 0, /* m */ + 0, /* n */ + UMODE_OPER, /* o */ + UMODE_OVERRIDE, /* p */ + 0, /* q */ + 0, /* r */ + UMODE_SERVNOTICE, /* s */ + 0, /* t */ + 0, /* u */ + 0, /* v */ + UMODE_WALLOP, /* w */ + 0, /* x */ + 0, /* y */ + UMODE_OPERWALL, /* z */ + /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */ + /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ + /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ + /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */ + /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */ + /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */ + /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */ + /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */ + /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */ }; /* *INDENT-ON* */ @@ -141,53 +141,53 @@ int user_modes[256] = { int show_lusers(struct Client *source_p) { - if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount) - MaxClientCount = rb_dlink_list_length(&lclient_list); + if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount) + MaxClientCount = rb_dlink_list_length(&lclient_list); - if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > - (unsigned long)MaxConnectionCount) - MaxConnectionCount = rb_dlink_list_length(&lclient_list) + - rb_dlink_list_length(&serv_list); + if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > + (unsigned long)MaxConnectionCount) + MaxConnectionCount = rb_dlink_list_length(&lclient_list) + + rb_dlink_list_length(&serv_list); - sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT), - (Count.total - Count.invisi), - Count.invisi, rb_dlink_list_length(&global_serv_list)); + sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT), + (Count.total - Count.invisi), + Count.invisi, rb_dlink_list_length(&global_serv_list)); - if(rb_dlink_list_length(&oper_list) > 0) - sendto_one_numeric(source_p, RPL_LUSEROP, - form_str(RPL_LUSEROP), rb_dlink_list_length(&oper_list)); + if(rb_dlink_list_length(&oper_list) > 0) + sendto_one_numeric(source_p, RPL_LUSEROP, + form_str(RPL_LUSEROP), rb_dlink_list_length(&oper_list)); - if(rb_dlink_list_length(&unknown_list) > 0) - sendto_one_numeric(source_p, RPL_LUSERUNKNOWN, - form_str(RPL_LUSERUNKNOWN), - rb_dlink_list_length(&unknown_list)); + if(rb_dlink_list_length(&unknown_list) > 0) + sendto_one_numeric(source_p, RPL_LUSERUNKNOWN, + form_str(RPL_LUSERUNKNOWN), + rb_dlink_list_length(&unknown_list)); - if(rb_dlink_list_length(&global_channel_list) > 0) - sendto_one_numeric(source_p, RPL_LUSERCHANNELS, - form_str(RPL_LUSERCHANNELS), - rb_dlink_list_length(&global_channel_list)); + if(rb_dlink_list_length(&global_channel_list) > 0) + sendto_one_numeric(source_p, RPL_LUSERCHANNELS, + form_str(RPL_LUSERCHANNELS), + rb_dlink_list_length(&global_channel_list)); - sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME), - rb_dlink_list_length(&lclient_list), - rb_dlink_list_length(&serv_list)); + sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME), + rb_dlink_list_length(&lclient_list), + rb_dlink_list_length(&serv_list)); - sendto_one_numeric(source_p, RPL_LOCALUSERS, - form_str(RPL_LOCALUSERS), - rb_dlink_list_length(&lclient_list), - Count.max_loc, - rb_dlink_list_length(&lclient_list), - Count.max_loc); + sendto_one_numeric(source_p, RPL_LOCALUSERS, + form_str(RPL_LOCALUSERS), + rb_dlink_list_length(&lclient_list), + Count.max_loc, + rb_dlink_list_length(&lclient_list), + Count.max_loc); - sendto_one_numeric(source_p, RPL_GLOBALUSERS, form_str(RPL_GLOBALUSERS), - Count.total, Count.max_tot, - Count.total, Count.max_tot); + sendto_one_numeric(source_p, RPL_GLOBALUSERS, form_str(RPL_GLOBALUSERS), + Count.total, Count.max_tot, + Count.total, Count.max_tot); - sendto_one_numeric(source_p, RPL_STATSCONN, - form_str(RPL_STATSCONN), - MaxConnectionCount, MaxClientCount, - Count.totalrestartcount); + sendto_one_numeric(source_p, RPL_STATSCONN, + form_str(RPL_STATSCONN), + MaxConnectionCount, MaxClientCount, + Count.totalrestartcount); - return 0; + return 0; } /* @@ -217,375 +217,350 @@ show_lusers(struct Client *source_p) int register_local_user(struct Client *client_p, struct Client *source_p, const char *username) { - struct ConfItem *aconf, *xconf; - struct User *user = source_p->user; - char tmpstr2[IRCD_BUFSIZE]; - char ipaddr[HOSTIPLEN]; - char myusername[USERLEN+1]; - int status; + struct ConfItem *aconf, *xconf; + struct User *user = source_p->user; + char tmpstr2[IRCD_BUFSIZE]; + char ipaddr[HOSTIPLEN]; + char myusername[USERLEN+1]; + int status; - s_assert(NULL != source_p); - s_assert(MyConnect(source_p)); - s_assert(source_p->username != username); + s_assert(NULL != source_p); + s_assert(MyConnect(source_p)); + s_assert(source_p->username != username); - if(source_p == NULL) - return -1; + if(source_p == NULL) + return -1; - if(IsAnyDead(source_p)) - return -1; + if(IsAnyDead(source_p)) + return -1; - /* Allocate a UID if it was not previously allocated. - * If this already occured, it was probably during SASL auth... - */ - if(!*source_p->id) - { - strcpy(source_p->id, generate_uid()); - add_to_id_hash(source_p->id, source_p); - } + /* Allocate a UID if it was not previously allocated. + * If this already occured, it was probably during SASL auth... + */ + if(!*source_p->id) { + strcpy(source_p->id, generate_uid()); + add_to_id_hash(source_p->id, source_p); + } - if(ConfigFileEntry.ping_cookie) - { - if(!(source_p->flags & FLAGS_PINGSENT) && source_p->localClient->random_ping == 0) - { - source_p->localClient->random_ping = (unsigned long) (rand() * rand()) << 1; - sendto_one(source_p, "PING :%08lX", - (unsigned long) source_p->localClient->random_ping); - source_p->flags |= FLAGS_PINGSENT; - return -1; - } - if(!(source_p->flags & FLAGS_PING_COOKIE)) - { - return -1; - } - } + if(ConfigFileEntry.ping_cookie) { + if(!(source_p->flags & FLAGS_PINGSENT) && source_p->localClient->random_ping == 0) { + source_p->localClient->random_ping = (unsigned long) (rand() * rand()) << 1; + sendto_one(source_p, "PING :%08lX", + (unsigned long) source_p->localClient->random_ping); + source_p->flags |= FLAGS_PINGSENT; + return -1; + } + if(!(source_p->flags & FLAGS_PING_COOKIE)) { + return -1; + } + } - /* hasnt finished client cap negotiation */ - if(source_p->flags & FLAGS_CLICAP) - return -1; + /* hasnt finished client cap negotiation */ + if(source_p->flags & FLAGS_CLICAP) + return -1; - /* still has DNSbls to validate against */ - if(rb_dlink_list_length(&source_p->preClient->dnsbl_queries) > 0) - return -1; + /* still has DNSbls to validate against */ + if(rb_dlink_list_length(&source_p->preClient->dnsbl_queries) > 0) + return -1; - client_p->localClient->last = rb_current_time(); - /* Straight up the maximum rate of flooding... */ - source_p->localClient->allow_read = MAX_FLOOD_BURST; + client_p->localClient->last = rb_current_time(); + /* Straight up the maximum rate of flooding... */ + source_p->localClient->allow_read = MAX_FLOOD_BURST; - /* XXX - fixme. we shouldnt have to build a users buffer twice.. */ - if(!IsGotId(source_p) && (strchr(username, '[') != NULL)) - { - const char *p; - int i = 0; + /* XXX - fixme. we shouldnt have to build a users buffer twice.. */ + if(!IsGotId(source_p) && (strchr(username, '[') != NULL)) { + const char *p; + int i = 0; - p = username; + p = username; - while(*p && i < USERLEN) - { - if(*p != '[') - myusername[i++] = *p; - p++; - } + while(*p && i < USERLEN) { + if(*p != '[') + myusername[i++] = *p; + p++; + } - myusername[i] = '\0'; - username = myusername; - } + myusername[i] = '\0'; + username = myusername; + } - if((status = check_client(client_p, source_p, username)) < 0) - return (CLIENT_EXITED); + if((status = check_client(client_p, source_p, username)) < 0) + return (CLIENT_EXITED); - /* Apply nick override */ - if(*source_p->preClient->spoofnick) - { - char note[NICKLEN + 10]; + /* Apply nick override */ + if(*source_p->preClient->spoofnick) { + char note[NICKLEN + 10]; - del_from_client_hash(source_p->name, source_p); - rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1); - add_to_client_hash(source_p->name, source_p); + del_from_client_hash(source_p->name, source_p); + rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1); + add_to_client_hash(source_p->name, source_p); - rb_snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name); - rb_note(source_p->localClient->F, note); - } + rb_snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name); + rb_note(source_p->localClient->F, note); + } - if(!valid_hostname(source_p->host)) - { - sendto_one_notice(source_p, ":*** Notice -- You have an illegal character in your hostname"); + if(!valid_hostname(source_p->host)) { + sendto_one_notice(source_p, ":*** Notice -- You have an illegal character in your hostname"); - rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); - } - + rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); + } - aconf = source_p->localClient->att_conf; - if(aconf == NULL) - { - exit_client(client_p, source_p, &me, "*** Not Authorised"); - return (CLIENT_EXITED); - } + aconf = source_p->localClient->att_conf; - if(IsConfSSLNeeded(aconf) && !IsSSL(source_p)) - { - ServerStats.is_ref++; - sendto_one_notice(source_p, ":*** Notice -- You need to use SSL/TLS to use this server"); - exit_client(client_p, source_p, &me, "Use SSL/TLS"); - return (CLIENT_EXITED); - } + if(aconf == NULL) { + exit_client(client_p, source_p, &me, "*** Not Authorised"); + return (CLIENT_EXITED); + } - if(!IsGotId(source_p)) - { - const char *p; - int i = 0; + if(IsConfSSLNeeded(aconf) && !IsSSL(source_p)) { + ServerStats.is_ref++; + sendto_one_notice(source_p, ":*** Notice -- You need to use SSL/TLS to use this server"); + exit_client(client_p, source_p, &me, "Use SSL/TLS"); + return (CLIENT_EXITED); + } - if(IsNeedIdentd(aconf)) - { - ServerStats.is_ref++; - sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server"); - exit_client(client_p, source_p, &me, "Install identd"); - return (CLIENT_EXITED); - } + if(!IsGotId(source_p)) { + const char *p; + int i = 0; - /* dont replace username if its supposed to be spoofed --fl */ - if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')) - { - p = username; + if(IsNeedIdentd(aconf)) { + ServerStats.is_ref++; + sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server"); + exit_client(client_p, source_p, &me, "Install identd"); + return (CLIENT_EXITED); + } - if(!IsNoTilde(aconf)) - source_p->username[i++] = '~'; + /* dont replace username if its supposed to be spoofed --fl */ + if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')) { + p = username; - while (*p && i < USERLEN) - { - if(*p != '[') - source_p->username[i++] = *p; - p++; - } + if(!IsNoTilde(aconf)) + source_p->username[i++] = '~'; - source_p->username[i] = '\0'; - } - } + while (*p && i < USERLEN) { + if(*p != '[') + source_p->username[i++] = *p; + p++; + } - if(IsNeedSasl(aconf) && !*user->suser) - { - sendto_realops_snomask(SNO_SASLFAIL, L_ALL, - "SASL authentication failed, rejecting %s[%s].", source_p->name, source_p->host); + source_p->username[i] = '\0'; + } + } + + if(IsNeedSasl(aconf) && !*user->suser) { + sendto_realops_snomask(SNO_SASLFAIL, L_ALL, + "SASL authentication failed, rejecting %s[%s].", source_p->name, source_p->host); //Broadcast snote sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s ENCAP * SNOTE S :%s SASL authentication failed, rejecting %s[%s].", - me.id, me.name, source_p->name, source_p->host); + ":%s ENCAP * SNOTE S :%s SASL authentication failed, rejecting %s[%s].", + me.id, me.name, source_p->name, source_p->host); - ServerStats.is_ref++; - sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server"); - exit_client(client_p, source_p, &me, "SASL access only"); - return (CLIENT_EXITED); - } + ServerStats.is_ref++; + sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server"); + exit_client(client_p, source_p, &me, "SASL access only"); + return (CLIENT_EXITED); + } - /* password check */ - if(!EmptyString(aconf->passwd)) - { - const char *encr; + /* password check */ + if(!EmptyString(aconf->passwd)) { + const char *encr; - if(EmptyString(source_p->localClient->passwd)) - encr = ""; - else if(IsConfEncrypted(aconf)) - encr = rb_crypt(source_p->localClient->passwd, aconf->passwd); - else - encr = source_p->localClient->passwd; + if(EmptyString(source_p->localClient->passwd)) + encr = ""; + else if(IsConfEncrypted(aconf)) + encr = rb_crypt(source_p->localClient->passwd, aconf->passwd); + else + encr = source_p->localClient->passwd; - if(strcmp(encr, aconf->passwd)) - { - ServerStats.is_ref++; - sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); - exit_client(client_p, source_p, &me, "Bad Password"); - return (CLIENT_EXITED); - } + if(strcmp(encr, aconf->passwd)) { + ServerStats.is_ref++; + sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); + exit_client(client_p, source_p, &me, "Bad Password"); + return (CLIENT_EXITED); + } - /* clear password only if used now, otherwise send it - * to services -- jilles */ - if(source_p->localClient->passwd) - { - memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); - rb_free(source_p->localClient->passwd); - source_p->localClient->passwd = NULL; - } - } + /* clear password only if used now, otherwise send it + * to services -- jilles */ + if(source_p->localClient->passwd) { + memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); + rb_free(source_p->localClient->passwd); + source_p->localClient->passwd = NULL; + } + } - /* report if user has &^>= etc. and set flags as needed in source_p */ - report_and_set_user_flags(source_p, aconf); + /* report if user has &^>= etc. and set flags as needed in source_p */ + report_and_set_user_flags(source_p, aconf); - /* Limit clients */ - /* - * We want to be able to have servers and F-line clients - * connect, so save room for "buffer" connections. - * Smaller servers may want to decrease this, and it should - * probably be just a percentage of the MAXCLIENTS... - * -Taner - */ - /* Except "F:" clients */ - if(rb_dlink_list_length(&lclient_list) >= - (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf)) - { - sendto_realops_snomask(SNO_FULL, L_ALL, - "Too many clients, rejecting %s[%s].", source_p->name, source_p->host); + /* Limit clients */ + /* + * We want to be able to have servers and F-line clients + * connect, so save room for "buffer" connections. + * Smaller servers may want to decrease this, and it should + * probably be just a percentage of the MAXCLIENTS... + * -Taner + */ + /* Except "F:" clients */ + if(rb_dlink_list_length(&lclient_list) >= + (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf)) { + sendto_realops_snomask(SNO_FULL, L_ALL, + "Too many clients, rejecting %s[%s].", source_p->name, source_p->host); - ServerStats.is_ref++; - exit_client(client_p, source_p, &me, "Sorry, server is full - try later"); - return (CLIENT_EXITED); - } + ServerStats.is_ref++; + exit_client(client_p, source_p, &me, "Sorry, server is full - try later"); + return (CLIENT_EXITED); + } - /* kline exemption extends to xline too */ - if(!IsExemptKline(source_p) && - (xconf = find_xline(source_p->info, 1)) != NULL) - { - ServerStats.is_ref++; - add_reject(source_p, xconf->host, NULL); - exit_client(client_p, source_p, &me, "Bad user info"); - return CLIENT_EXITED; - } + /* kline exemption extends to xline too */ + if(!IsExemptKline(source_p) && + (xconf = find_xline(source_p->info, 1)) != NULL) { + ServerStats.is_ref++; + add_reject(source_p, xconf->host, NULL); + exit_client(client_p, source_p, &me, "Bad user info"); + return CLIENT_EXITED; + } - /* dnsbl check */ - if (source_p->preClient->dnsbl_listed != NULL) - { - if (IsExemptKline(source_p) || IsConfExemptDNSBL(aconf)) - sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s, but you are exempt", - source_p->sockhost, source_p->preClient->dnsbl_listed->host); - else - { - rb_dlink_list varlist = { NULL, NULL, 0 }; + /* dnsbl check */ + if (source_p->preClient->dnsbl_listed != NULL) { + if (IsExemptKline(source_p) || IsConfExemptDNSBL(aconf)) + sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s, but you are exempt", + source_p->sockhost, source_p->preClient->dnsbl_listed->host); + else { + rb_dlink_list varlist = { NULL, NULL, 0 }; - substitution_append_var(&varlist, "nick", source_p->name); - substitution_append_var(&varlist, "ip", source_p->sockhost); - substitution_append_var(&varlist, "host", source_p->host); - substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->dnsbl_listed->host); - substitution_append_var(&varlist, "network-name", ServerInfo.network_name); + substitution_append_var(&varlist, "nick", source_p->name); + substitution_append_var(&varlist, "ip", source_p->sockhost); + substitution_append_var(&varlist, "host", source_p->host); + substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->dnsbl_listed->host); + substitution_append_var(&varlist, "network-name", ServerInfo.network_name); - ServerStats.is_ref++; + ServerStats.is_ref++; - sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP), - me.name, source_p->name, - substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist)); + sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP), + me.name, source_p->name, + substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist)); - substitution_free(&varlist); + substitution_free(&varlist); - sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s", - source_p->sockhost, source_p->preClient->dnsbl_listed->host); - source_p->preClient->dnsbl_listed->hits++; + sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s", + source_p->sockhost, source_p->preClient->dnsbl_listed->host); + source_p->preClient->dnsbl_listed->hits++; - sendto_server(NULL, NULL, CAP_TS6, NOCAPS, - ":%s ENCAP * SNOTE r :%s (%s@%s) is being disconnected due to being listed in DNS Blacklist %s", - me.id, source_p->name, source_p->username, source_p->sockhost, source_p->preClient->dnsbl_listed->host); + sendto_server(NULL, NULL, CAP_TS6, NOCAPS, + ":%s ENCAP * SNOTE r :%s (%s@%s) is being disconnected due to being listed in DNS Blacklist %s", + me.id, source_p->name, source_p->username, source_p->sockhost, source_p->preClient->dnsbl_listed->host); - sendto_realops_snomask(SNO_REJ, L_ALL, - "%s (%s@%s) is being disconnected due to being listed in DNS Blacklist %s", - source_p->name, source_p->username, source_p->sockhost, source_p->preClient->dnsbl_listed->host); + sendto_realops_snomask(SNO_REJ, L_ALL, + "%s (%s@%s) is being disconnected due to being listed in DNS Blacklist %s", + source_p->name, source_p->username, source_p->sockhost, source_p->preClient->dnsbl_listed->host); - add_reject(source_p, NULL, NULL); - exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)"); - return CLIENT_EXITED; - } - } + add_reject(source_p, NULL, NULL); + exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)"); + return CLIENT_EXITED; + } + } - /* valid user name check */ + /* valid user name check */ - if(!valid_username(source_p->username)) - { - sendto_realops_snomask(SNO_REJ, L_ALL, - "Invalid username: %s (%s@%s)", - source_p->name, source_p->username, source_p->host); - ServerStats.is_ref++; - sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains " - "only alphanumeric characters."); - rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username); - exit_client(client_p, source_p, &me, tmpstr2); - return (CLIENT_EXITED); - } + if(!valid_username(source_p->username)) { + sendto_realops_snomask(SNO_REJ, L_ALL, + "Invalid username: %s (%s@%s)", + source_p->name, source_p->username, source_p->host); + ServerStats.is_ref++; + sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains " + "only alphanumeric characters."); + rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username); + exit_client(client_p, source_p, &me, tmpstr2); + return (CLIENT_EXITED); + } - /* end of valid user name check */ + /* end of valid user name check */ - /* Store original hostname -- jilles */ - rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1); + /* Store original hostname -- jilles */ + rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1); - /* Spoof user@host */ - if(*source_p->preClient->spoofuser) - rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1); - if(*source_p->preClient->spoofhost) - { - rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1); - if (irccmp(source_p->host, source_p->orighost)) - SetDynSpoof(source_p); - } + /* Spoof user@host */ + if(*source_p->preClient->spoofuser) + rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1); + if(*source_p->preClient->spoofhost) { + rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1); + if (irccmp(source_p->host, source_p->orighost)) + SetDynSpoof(source_p); + } - source_p->umodes |= ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes & ~orphaned_umodes; + source_p->umodes |= ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes & ~orphaned_umodes; - call_hook(h_new_local_user, source_p); + call_hook(h_new_local_user, source_p); - /* If they have died in send_* or were thrown out by the - * new_local_user hook don't do anything. */ - if(IsAnyDead(source_p)) - return CLIENT_EXITED; + /* If they have died in send_* or were thrown out by the + * new_local_user hook don't do anything. */ + if(IsAnyDead(source_p)) + return CLIENT_EXITED; - /* To avoid inconsistencies, do not abort the registration - * starting from this point -- jilles - */ - rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); + /* To avoid inconsistencies, do not abort the registration + * starting from this point -- jilles + */ + rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); - sendto_realops_snomask(SNO_CCONN, L_ALL, - "Client connecting: %s (%s@%s) [%s] {%s} [%s]", - source_p->name, source_p->username, source_p->orighost, - show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", - get_client_class(source_p), source_p->info); + sendto_realops_snomask(SNO_CCONN, L_ALL, + "Client connecting: %s (%s@%s) [%s] {%s} [%s]", + source_p->name, source_p->username, source_p->orighost, + show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", + get_client_class(source_p), source_p->info); - sendto_realops_snomask(SNO_CCONNEXT, L_ALL, - "CLICONN %s %s %s %s %s %s 0 %s", - source_p->name, source_p->username, source_p->orighost, - show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", - get_client_class(source_p), - /* mirc can sometimes send ips here */ - show_ip(NULL, source_p) ? source_p->localClient->fullcaps : " ", - source_p->info); + sendto_realops_snomask(SNO_CCONNEXT, L_ALL, + "CLICONN %s %s %s %s %s %s 0 %s", + source_p->name, source_p->username, source_p->orighost, + show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", + get_client_class(source_p), + /* mirc can sometimes send ips here */ + show_ip(NULL, source_p) ? source_p->localClient->fullcaps : " ", + source_p->info); - add_to_hostname_hash(source_p->orighost, source_p); + add_to_hostname_hash(source_p->orighost, source_p); - if (IsSSL(source_p)) - source_p->umodes |= UMODE_SSLCLIENT; + if (IsSSL(source_p)) + source_p->umodes |= UMODE_SSLCLIENT; - if (source_p->umodes & UMODE_INVISIBLE) - Count.invisi++; + if (source_p->umodes & UMODE_INVISIBLE) + Count.invisi++; - s_assert(!IsClient(source_p)); - rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list); - SetClient(source_p); + s_assert(!IsClient(source_p)); + rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list); + SetClient(source_p); - source_p->servptr = &me; - rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); + source_p->servptr = &me; + rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); - /* Increment our total user count here */ - if(++Count.total > Count.max_tot) - Count.max_tot = Count.total; + /* Increment our total user count here */ + if(++Count.total > Count.max_tot) + Count.max_tot = Count.total; - source_p->localClient->allow_read = MAX_FLOOD_BURST; + source_p->localClient->allow_read = MAX_FLOOD_BURST; - Count.totalrestartcount++; + Count.totalrestartcount++; - s_assert(source_p->localClient != NULL); + s_assert(source_p->localClient != NULL); - if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc) - { - Count.max_loc = rb_dlink_list_length(&lclient_list); - if(!(Count.max_loc % 10)) - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "New Max Local Clients: %d", Count.max_loc); - } + if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc) { + Count.max_loc = rb_dlink_list_length(&lclient_list); + if(!(Count.max_loc % 10)) + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "New Max Local Clients: %d", Count.max_loc); + } - /* they get a reduced limit */ - if(find_tgchange(source_p->sockhost)) - source_p->localClient->targets_free = TGCHANGE_INITIAL_LOW; - else - source_p->localClient->targets_free = TGCHANGE_INITIAL; + /* they get a reduced limit */ + if(find_tgchange(source_p->sockhost)) + source_p->localClient->targets_free = TGCHANGE_INITIAL_LOW; + else + source_p->localClient->targets_free = TGCHANGE_INITIAL; - monitor_signon(source_p); - user_welcome(source_p); + monitor_signon(source_p); + user_welcome(source_p); - free_pre_client(source_p); + free_pre_client(source_p); - return (introduce_client(client_p, source_p, user, source_p->name, 1)); + return (introduce_client(client_p, source_p, user, source_p->name, 1)); } /* @@ -600,141 +575,132 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char int introduce_client(struct Client *client_p, struct Client *source_p, struct User *user, const char *nick, int use_euid) { - static char ubuf[BUFSIZE]; - struct Client *identifyservice_p; - char *p; - hook_data_umode_changed hdata; - hook_data_client hdata2; - char sockhost[HOSTLEN]; - struct ConfItem *aconf; + static char ubuf[BUFSIZE]; + struct Client *identifyservice_p; + char *p; + hook_data_umode_changed hdata; + hook_data_client hdata2; + char sockhost[HOSTLEN]; + struct ConfItem *aconf; - if(MyClient(source_p)) - send_umode(source_p, source_p, 0, 0, ubuf); - else - send_umode(NULL, source_p, 0, 0, ubuf); + if(MyClient(source_p)) + send_umode(source_p, source_p, 0, 0, ubuf); + else + send_umode(NULL, source_p, 0, 0, ubuf); - if(!*ubuf) - { - ubuf[0] = '+'; - ubuf[1] = '\0'; - } + if(!*ubuf) { + ubuf[0] = '+'; + ubuf[1] = '\0'; + } - s_assert(has_id(source_p)); + s_assert(has_id(source_p)); - if(source_p->sockhost[0] == ':') - { - sockhost[0] = '0'; - sockhost[1] = '\0'; - rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost)); - } else - strcpy(sockhost, source_p->sockhost); - - if (use_euid) - sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS, - ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", - source_p->servptr->id, nick, - source_p->hopcount + 1, - (long) source_p->tsinfo, ubuf, - source_p->username, source_p->host, - IsIPSpoof(source_p) ? "0" : sockhost, - source_p->id, - IsDynSpoof(source_p) ? source_p->orighost : "*", - EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, - source_p->info); + if(source_p->sockhost[0] == ':') { + sockhost[0] = '0'; + sockhost[1] = '\0'; + rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost)); + } else + strcpy(sockhost, source_p->sockhost); - sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, - ":%s UID %s %d %ld %s %s %s %s %s :%s", - source_p->servptr->id, nick, - source_p->hopcount + 1, - (long) source_p->tsinfo, ubuf, - source_p->username, source_p->host, - IsIPSpoof(source_p) ? "0" : sockhost, - source_p->id, source_p->info); + if (use_euid) + sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS, + ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", + source_p->servptr->id, nick, + source_p->hopcount + 1, + (long) source_p->tsinfo, ubuf, + source_p->username, source_p->host, + IsIPSpoof(source_p) ? "0" : sockhost, + source_p->id, + IsDynSpoof(source_p) ? source_p->orighost : "*", + EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, + source_p->info); - if(!EmptyString(source_p->certfp)) - sendto_server(client_p, NULL, CAP_TS6, NOCAPS, - ":%s ENCAP * CERTFP :%s", - use_id(source_p), source_p->certfp); + sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, + ":%s UID %s %d %ld %s %s %s %s %s :%s", + source_p->servptr->id, nick, + source_p->hopcount + 1, + (long) source_p->tsinfo, ubuf, + source_p->username, source_p->host, + IsIPSpoof(source_p) ? "0" : sockhost, + source_p->id, source_p->info); - if (IsDynSpoof(source_p)) - { - sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s", - use_id(source_p), source_p->orighost); - user_metadata_add(source_p, "CLOAKEDHOST", source_p->host, 1); - } + if(!EmptyString(source_p->certfp)) + sendto_server(client_p, NULL, CAP_TS6, NOCAPS, + ":%s ENCAP * CERTFP :%s", + use_id(source_p), source_p->certfp); - if (!EmptyString(source_p->user->suser)) - { - sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s", - use_id(source_p), source_p->user->suser); - } + if (IsDynSpoof(source_p)) { + sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s", + use_id(source_p), source_p->orighost); + user_metadata_add(source_p, "CLOAKEDHOST", source_p->host, 1); + } - if(MyConnect(source_p) && source_p->localClient->passwd) - { - if (!EmptyString(ConfigFileEntry.identifyservice) && - !EmptyString(ConfigFileEntry.identifycommand)) - { - /* use user@server */ - p = strchr(ConfigFileEntry.identifyservice, '@'); - if (p != NULL) - identifyservice_p = find_named_client(p + 1); - else - identifyservice_p = NULL; - if (identifyservice_p != NULL) - { - if (!EmptyString(source_p->localClient->auth_user)) - sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s", - get_id(source_p, identifyservice_p), - ConfigFileEntry.identifyservice, - ConfigFileEntry.identifycommand, - source_p->localClient->auth_user, - source_p->localClient->passwd); - else - sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s", - get_id(source_p, identifyservice_p), - ConfigFileEntry.identifyservice, - ConfigFileEntry.identifycommand, - source_p->localClient->passwd); - } - } - memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); - rb_free(source_p->localClient->passwd); - source_p->localClient->passwd = NULL; - } + if (!EmptyString(source_p->user->suser)) { + sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s", + use_id(source_p), source_p->user->suser); + } - /* let modules providing usermodes know that we've got a new user, - * why is this here? -- well, some modules need to be able to send out new - * information about a client, so this was the best place to do it - * --nenolod - */ - hdata.client = source_p; - hdata.oldumodes = 0; - hdata.oldsnomask = 0; - call_hook(h_umode_changed, &hdata); + if(MyConnect(source_p) && source_p->localClient->passwd) { + if (!EmptyString(ConfigFileEntry.identifyservice) && + !EmptyString(ConfigFileEntry.identifycommand)) { + /* use user@server */ + p = strchr(ConfigFileEntry.identifyservice, '@'); + if (p != NULL) + identifyservice_p = find_named_client(p + 1); + else + identifyservice_p = NULL; + if (identifyservice_p != NULL) { + if (!EmptyString(source_p->localClient->auth_user)) + sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s", + get_id(source_p, identifyservice_p), + ConfigFileEntry.identifyservice, + ConfigFileEntry.identifycommand, + source_p->localClient->auth_user, + source_p->localClient->passwd); + else + sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s", + get_id(source_p, identifyservice_p), + ConfigFileEntry.identifyservice, + ConfigFileEntry.identifycommand, + source_p->localClient->passwd); + } + } + memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); + rb_free(source_p->localClient->passwd); + source_p->localClient->passwd = NULL; + } - /* On the other hand, some modules need to know when a client is - * being introduced, period. - * --gxti - */ - hdata2.client = client_p; - hdata2.target = source_p; - call_hook(h_introduce_client, &hdata2); + /* let modules providing usermodes know that we've got a new user, + * why is this here? -- well, some modules need to be able to send out new + * information about a client, so this was the best place to do it + * --nenolod + */ + hdata.client = source_p; + hdata.oldumodes = 0; + hdata.oldsnomask = 0; + call_hook(h_umode_changed, &hdata); - /* Do all the auth::autojoin wizardry once we're connected */ - if(MyConnect(source_p)) - { - aconf = source_p->localClient->att_conf; + /* On the other hand, some modules need to know when a client is + * being introduced, period. + * --gxti + */ + hdata2.client = client_p; + hdata2.target = source_p; + call_hook(h_introduce_client, &hdata2); - if(aconf->autojoin != NULL) - { - user_join(client_p, source_p, aconf->autojoin, NULL); - } - } + /* Do all the auth::autojoin wizardry once we're connected */ + if(MyConnect(source_p)) { + aconf = source_p->localClient->att_conf; - return 0; + if(aconf->autojoin != NULL) { + user_join(client_p, source_p, aconf->autojoin, NULL); + } + } + + return 0; } -/* +/* * valid_hostname - check hostname for validity * * Inputs - pointer to user @@ -747,47 +713,45 @@ introduce_client(struct Client *client_p, struct Client *source_p, struct User * int valid_hostname(const char *hostname) { - const char *p = hostname, *last_slash = 0; - int found_sep = 0; + const char *p = hostname, *last_slash = 0; + int found_sep = 0; - s_assert(NULL != p); + s_assert(NULL != p); - if(hostname == NULL) - return NO; + if(hostname == NULL) + return NO; - if('.' == *p || ':' == *p || '/' == *p) - return NO; + if('.' == *p || ':' == *p || '/' == *p) + return NO; - while (*p) - { - if(!IsHostChar(*p)) - return NO; - if(*p == '.' || *p == ':') - found_sep++; - else if(*p == '/') - { - found_sep++; - last_slash = p; - } - p++; - } + while (*p) { + if(!IsHostChar(*p)) + return NO; + if(*p == '.' || *p == ':') + found_sep++; + else if(*p == '/') { + found_sep++; + last_slash = p; + } + p++; + } - if(found_sep == 0) - return NO; + if(found_sep == 0) + return NO; - if(last_slash && IsDigit(last_slash[1])) - return NO; + if(last_slash && IsDigit(last_slash[1])) + return NO; - return YES; + return YES; } -/* +/* * valid_username - check username for validity * * Inputs - pointer to user * Output - YES if valid, NO if not * Side effects - NONE - * + * * Absolutely always reject any '*' '!' '?' '@' in an user name * reject any odd control characters names. * Allow '.' in username to allow for "first.last" @@ -796,38 +760,35 @@ valid_hostname(const char *hostname) int valid_username(const char *username) { - int dots = 0; - const char *p = username; + int dots = 0; + const char *p = username; - s_assert(NULL != p); + s_assert(NULL != p); - if(username == NULL) - return NO; + if(username == NULL) + return NO; - if('~' == *p) - ++p; + if('~' == *p) + ++p; - /* reject usernames that don't start with an alphanum - * i.e. reject jokers who have '-@somehost' or '.@somehost' - * or "-hi-@somehost", "h-----@somehost" would still be accepted. - */ - if(!IsAlNum(*p)) - return NO; + /* reject usernames that don't start with an alphanum + * i.e. reject jokers who have '-@somehost' or '.@somehost' + * or "-hi-@somehost", "h-----@somehost" would still be accepted. + */ + if(!IsAlNum(*p)) + return NO; - while (*++p) - { - if((*p == '.') && ConfigFileEntry.dots_in_ident) - { - dots++; - if(dots > ConfigFileEntry.dots_in_ident) - return NO; - if(!IsUserChar(p[1])) - return NO; - } - else if(!IsUserChar(*p)) - return NO; - } - return YES; + while (*++p) { + if((*p == '.') && ConfigFileEntry.dots_in_ident) { + dots++; + if(dots > ConfigFileEntry.dots_in_ident) + return NO; + if(!IsUserChar(p[1])) + return NO; + } else if(!IsUserChar(*p)) + return NO; + } + return YES; } /* report_and_set_user_flags @@ -842,92 +803,84 @@ valid_username(const char *username) static void report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf) { - /* If this user is being spoofed, tell them so */ - if(IsConfDoSpoofIp(aconf)) - { - sendto_one_notice(source_p, ":*** Spoofing your IP"); - } + /* If this user is being spoofed, tell them so */ + if(IsConfDoSpoofIp(aconf)) { + sendto_one_notice(source_p, ":*** Spoofing your IP"); + } - /* If this user is in the exception class, Set it "E lined" */ - if(IsConfExemptKline(aconf)) - { - SetExemptKline(source_p); - sendto_one_notice(source_p, ":*** You are exempt from K/X lines"); - } + /* If this user is in the exception class, Set it "E lined" */ + if(IsConfExemptKline(aconf)) { + SetExemptKline(source_p); + sendto_one_notice(source_p, ":*** You are exempt from K/X lines"); + } - if(IsConfExemptDNSBL(aconf)) - /* kline exempt implies this, don't send both */ - if(!IsConfExemptKline(aconf)) - sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists"); + if(IsConfExemptDNSBL(aconf)) + /* kline exempt implies this, don't send both */ + if(!IsConfExemptKline(aconf)) + sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists"); - /* If this user is exempt from user limits set it F lined" */ - if(IsConfExemptLimits(aconf)) - { - sendto_one_notice(source_p, ":*** You are exempt from user limits"); - } + /* If this user is exempt from user limits set it F lined" */ + if(IsConfExemptLimits(aconf)) { + sendto_one_notice(source_p, ":*** You are exempt from user limits"); + } - if(IsConfExemptFlood(aconf)) - { - SetExemptFlood(source_p); - sendto_one_notice(source_p, ":*** You are exempt from flood limits"); - } + if(IsConfExemptFlood(aconf)) { + SetExemptFlood(source_p); + sendto_one_notice(source_p, ":*** You are exempt from flood limits"); + } - if(IsConfExemptSpambot(aconf)) - { - SetExemptSpambot(source_p); - sendto_one_notice(source_p, ":*** You are exempt from spambot checks"); - } + if(IsConfExemptSpambot(aconf)) { + SetExemptSpambot(source_p); + sendto_one_notice(source_p, ":*** You are exempt from spambot checks"); + } - if(IsConfExemptJupe(aconf)) - { - SetExemptJupe(source_p); - sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings"); - } + if(IsConfExemptJupe(aconf)) { + SetExemptJupe(source_p); + sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings"); + } - if(IsConfExemptResv(aconf)) - { - SetExemptResv(source_p); - sendto_one_notice(source_p, ":*** You are exempt from resvs"); - } + if(IsConfExemptResv(aconf)) { + SetExemptResv(source_p); + sendto_one_notice(source_p, ":*** You are exempt from resvs"); + } - if(IsConfExemptShide(aconf)) - { - SetExemptShide(source_p); - sendto_one_notice(source_p, ":*** You are exempt from serverhiding"); - } + if(IsConfExemptShide(aconf)) { + SetExemptShide(source_p); + sendto_one_notice(source_p, ":*** You are exempt from serverhiding"); + } } static void show_other_user_mode(struct Client *source_p, struct Client *target_p) { - int i; - char buf[BUFSIZE]; - char *m; + int i; + char buf[BUFSIZE]; + char *m; - m = buf; - *m++ = '+'; + m = buf; + *m++ = '+'; - for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ - if (target_p->umodes & user_modes[i]) - *m++ = (char) i; - *m = '\0'; + for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ + if (target_p->umodes & user_modes[i]) + *m++ = (char) i; + *m = '\0'; - if (MyConnect(target_p) && target_p->snomask != 0) - sendto_one_notice(source_p, ":Modes for %s are %s %s", - target_p->name, buf, - construct_snobuf(target_p->snomask)); - else - sendto_one_notice(source_p, ":Modes for %s are %s", - target_p->name, buf); + if (MyConnect(target_p) && target_p->snomask != 0) + sendto_one_notice(source_p, ":Modes for %s are %s %s", + target_p->name, buf, + construct_snobuf(target_p->snomask)); + else + sendto_one_notice(source_p, ":Modes for %s are %s", + target_p->name, buf); } static void expire_umode_p(void *data) { - struct Client *source_p = data; - const char *parv[4] = {source_p->name, source_p->name, "-p", NULL}; - source_p->localClient->override_timeout_event = NULL; - user_mode(source_p, source_p, 3, parv); + struct Client *source_p = data; + const char *parv[4] = {source_p->name, source_p->name, "-p", NULL}; + source_p->localClient->override_timeout_event = NULL; + user_mode(source_p, source_p, 3, parv); } /* @@ -940,271 +893,242 @@ expire_umode_p(void *data) int user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - int flag; - int i; - char *m; - const char *pm; - struct Client *target_p; - int what, setflags; - int badflag = NO; /* Only send one bad flag notice */ - int showsnomask = NO; - unsigned int setsnomask; - char buf[BUFSIZE]; - hook_data_umode_changed hdata; + int flag; + int i; + char *m; + const char *pm; + struct Client *target_p; + int what, setflags; + int badflag = NO; /* Only send one bad flag notice */ + int showsnomask = NO; + unsigned int setsnomask; + char buf[BUFSIZE]; + hook_data_umode_changed hdata; - what = MODE_ADD; + what = MODE_ADD; - if(parc < 2) - { - sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); - return 0; - } + if(parc < 2) { + sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); + return 0; + } - if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL) - { - if(MyConnect(source_p)) - sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, - form_str(ERR_NOSUCHCHANNEL), parv[1]); - return 0; - } + if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL) { + if(MyConnect(source_p)) + sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, + form_str(ERR_NOSUCHCHANNEL), parv[1]); + return 0; + } - /* Dont know why these were commented out.. - * put them back using new sendto() funcs - */ + /* Dont know why these were commented out.. + * put them back using new sendto() funcs + */ - if(IsServer(source_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ADMIN, - "*** Mode for User %s from %s", parv[1], source_p->name); - return 0; - } + if(IsServer(source_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ADMIN, + "*** Mode for User %s from %s", parv[1], source_p->name); + return 0; + } - if(source_p != target_p) - { - if (MyOper(source_p) && parc < 3) - show_other_user_mode(source_p, target_p); - else - sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name); - return 0; - } + if(source_p != target_p) { + if (MyOper(source_p) && parc < 3) + show_other_user_mode(source_p, target_p); + else + sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name); + return 0; + } - if(parc < 3) - { - m = buf; - *m++ = '+'; + if(parc < 3) { + m = buf; + *m++ = '+'; - for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ - if (source_p->umodes & user_modes[i]) - *m++ = (char) i; + for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ + if (source_p->umodes & user_modes[i]) + *m++ = (char) i; - *m = '\0'; - sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf); + *m = '\0'; + sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf); - if (source_p->snomask != 0) - sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), - construct_snobuf(source_p->snomask)); + if (source_p->snomask != 0) + sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), + construct_snobuf(source_p->snomask)); - return 0; - } + return 0; + } - /* find flags already set for user */ - setflags = source_p->umodes; - setsnomask = source_p->snomask; + /* find flags already set for user */ + setflags = source_p->umodes; + setsnomask = source_p->snomask; - /* - * parse mode change string(s) - */ - for (pm = parv[2]; *pm; pm++) - switch (*pm) - { - case '+': - what = MODE_ADD; - break; - case '-': - what = MODE_DEL; - break; + /* + * parse mode change string(s) + */ + for (pm = parv[2]; *pm; pm++) + switch (*pm) { + case '+': + what = MODE_ADD; + break; + case '-': + what = MODE_DEL; + break; - case 'o': - if(what == MODE_ADD) - { - if(IsServer(client_p) && !IsOper(source_p)) - { - ++Count.oper; - SetOper(source_p); - rb_dlinkAddAlloc(source_p, &oper_list); - } - } - else - { - /* Only decrement the oper counts if an oper to begin with - * found by Pat Szuta, Perly , perly@xnet.com - */ + case 'o': + if(what == MODE_ADD) { + if(IsServer(client_p) && !IsOper(source_p)) { + ++Count.oper; + SetOper(source_p); + rb_dlinkAddAlloc(source_p, &oper_list); + } + } else { + /* Only decrement the oper counts if an oper to begin with + * found by Pat Szuta, Perly , perly@xnet.com + */ - if(!IsOper(source_p)) - break; + if(!IsOper(source_p)) + break; - ClearOper(source_p); + ClearOper(source_p); - Count.oper--; + Count.oper--; - user_metadata_delete(source_p, "OPERSTRING", 1); - user_metadata_delete(source_p, "SWHOIS", 1); + user_metadata_delete(source_p, "OPERSTRING", 1); + user_metadata_delete(source_p, "SWHOIS", 1); - if(MyConnect(source_p)) - { - source_p->umodes &= ~ConfigFileEntry.oper_only_umodes; - if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0) - { - source_p->snomask = 0; - showsnomask = YES; - } - source_p->flags2 &= ~OPER_FLAGS; + if(MyConnect(source_p)) { + source_p->umodes &= ~ConfigFileEntry.oper_only_umodes; + if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0) { + source_p->snomask = 0; + showsnomask = YES; + } + source_p->flags2 &= ~OPER_FLAGS; - rb_free(source_p->localClient->opername); - source_p->localClient->opername = NULL; + rb_free(source_p->localClient->opername); + source_p->localClient->opername = NULL; - rb_dlinkFindDestroy(source_p, &local_oper_list); - privilegeset_unref(source_p->localClient->privset); - source_p->localClient->privset = NULL; - } + rb_dlinkFindDestroy(source_p, &local_oper_list); + privilegeset_unref(source_p->localClient->privset); + source_p->localClient->privset = NULL; + } - rb_dlinkFindDestroy(source_p, &oper_list); - } - break; + rb_dlinkFindDestroy(source_p, &oper_list); + } + break; - /* we may not get these, - * but they shouldnt be in default - */ + /* we may not get these, + * but they shouldnt be in default + */ - /* can only be set on burst */ - case 'S': - case 'Z': - case ' ': - case '\n': - case '\r': - case '\t': - break; + /* can only be set on burst */ + case 'S': + case 'Z': + case ' ': + case '\n': + case '\r': + case '\t': + break; - case 's': - if (MyConnect(source_p)) - { - if(!IsOper(source_p) - && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE)) - { - if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE) - badflag = YES; - continue; - } - showsnomask = YES; - if(what == MODE_ADD) - { - if (parc > 3) - source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]); - else - source_p->snomask |= SNO_GENERAL; - } - else - source_p->snomask = 0; - if (source_p->snomask != 0) - source_p->umodes |= UMODE_SERVNOTICE; - else - source_p->umodes &= ~UMODE_SERVNOTICE; - break; - } - /* FALLTHROUGH */ - default: - if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) { - badflag = YES; - break; - } + case 's': + if (MyConnect(source_p)) { + if(!IsOper(source_p) + && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE)) { + if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE) + badflag = YES; + continue; + } + showsnomask = YES; + if(what == MODE_ADD) { + if (parc > 3) + source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]); + else + source_p->snomask |= SNO_GENERAL; + } else + source_p->snomask = 0; + if (source_p->snomask != 0) + source_p->umodes |= UMODE_SERVNOTICE; + else + source_p->umodes &= ~UMODE_SERVNOTICE; + break; + } + /* FALLTHROUGH */ + default: + if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) { + badflag = YES; + break; + } - if((flag = user_modes[(unsigned char) *pm])) - { - if(MyConnect(source_p) - && ((!IsOper(source_p) - && (ConfigFileEntry.oper_only_umodes & flag)) - || (orphaned_umodes & flag))) - { - if (what == MODE_ADD || source_p->umodes & flag) - badflag = YES; - } - else - { - if(what == MODE_ADD) - source_p->umodes |= flag; - else - source_p->umodes &= ~flag; - } - } - else - { - if(MyConnect(source_p)) - badflag = YES; - } - break; - } + if((flag = user_modes[(unsigned char) *pm])) { + if(MyConnect(source_p) + && ((!IsOper(source_p) + && (ConfigFileEntry.oper_only_umodes & flag)) + || (orphaned_umodes & flag))) { + if (what == MODE_ADD || source_p->umodes & flag) + badflag = YES; + } else { + if(what == MODE_ADD) + source_p->umodes |= flag; + else + source_p->umodes &= ~flag; + } + } else { + if(MyConnect(source_p)) + badflag = YES; + } + break; + } - if(badflag) - sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name); + if(badflag) + sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name); - if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p)) - { - sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n"); - source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */ - } + if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p)) { + sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n"); + source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */ + } - if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p)) - { - sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z"); - source_p->umodes &= ~UMODE_OPERWALL; - } + if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p)) { + sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z"); + source_p->umodes &= ~UMODE_OPERWALL; + } - if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) && - (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))) - { - sendto_one_notice(source_p, ":*** You need oper and admin flag for +a"); - source_p->umodes &= ~UMODE_ADMIN; - } + if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) && + (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))) { + sendto_one_notice(source_p, ":*** You need oper and admin flag for +a"); + source_p->umodes &= ~UMODE_ADMIN; + } - if(MyConnect(source_p) && (source_p->umodes & UMODE_OVERRIDE) && (!IsOperOverride(source_p))) - { - sendto_one_notice(source_p, ":*** You need oper and the override flag for +p"); - source_p->umodes &= ~UMODE_OVERRIDE; - } + if(MyConnect(source_p) && (source_p->umodes & UMODE_OVERRIDE) && (!IsOperOverride(source_p))) { + sendto_one_notice(source_p, ":*** You need oper and the override flag for +p"); + source_p->umodes &= ~UMODE_OVERRIDE; + } - /* let modules providing usermodes know that we've changed our usermode --nenolod */ - hdata.client = source_p; - hdata.oldumodes = setflags; - hdata.oldsnomask = setsnomask; - call_hook(h_umode_changed, &hdata); + /* let modules providing usermodes know that we've changed our usermode --nenolod */ + hdata.client = source_p; + hdata.oldumodes = setflags; + hdata.oldsnomask = setsnomask; + call_hook(h_umode_changed, &hdata); - if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p)) - ++Count.invisi; - if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p)) - --Count.invisi; - /* - * compare new flags with old flags and send string which - * will cause servers to update correctly. - */ - send_umode_out(client_p, source_p, setflags); - if (showsnomask && MyConnect(source_p)) - sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), - construct_snobuf(source_p->snomask)); + if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p)) + ++Count.invisi; + if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p)) + --Count.invisi; + /* + * compare new flags with old flags and send string which + * will cause servers to update correctly. + */ + send_umode_out(client_p, source_p, setflags); + if (showsnomask && MyConnect(source_p)) + sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), + construct_snobuf(source_p->snomask)); - /* If we're setting +p, expire it, but only from local clients */ - if(ConfigFileEntry.expire_override_time && MyClient(source_p) && (source_p->umodes & ~setflags) & UMODE_OVERRIDE) - { - source_p->localClient->override_timeout_event = - rb_event_addonce("expire_override", expire_umode_p, source_p, ConfigFileEntry.expire_override_time); - } - else if(MyClient(source_p) && source_p->localClient->override_timeout_event && (setflags & ~source_p->umodes) & UMODE_OVERRIDE) - { - rb_event_delete(source_p->localClient->override_timeout_event); - source_p->localClient->override_timeout_event = NULL; - } + /* If we're setting +p, expire it, but only from local clients */ + if(ConfigFileEntry.expire_override_time && MyClient(source_p) && (source_p->umodes & ~setflags) & UMODE_OVERRIDE) { + source_p->localClient->override_timeout_event = + rb_event_addonce("expire_override", expire_umode_p, source_p, ConfigFileEntry.expire_override_time); + } else if(MyClient(source_p) && source_p->localClient->override_timeout_event && (setflags & ~source_p->umodes) & UMODE_OVERRIDE) { + rb_event_delete(source_p->localClient->override_timeout_event); + source_p->localClient->override_timeout_event = NULL; + } - return (0); + return (0); } /* @@ -1214,49 +1138,43 @@ user_mode(struct Client *client_p, struct Client *source_p, int parc, const char void send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf) { - int i; - int flag; - char *m; - int what = 0; + int i; + int flag; + char *m; + int what = 0; - /* - * build a string in umode_buf to represent the change in the user's - * mode between the new (source_p->flag) and 'old'. - */ - m = umode_buf; - *m = '\0'; + /* + * build a string in umode_buf to represent the change in the user's + * mode between the new (source_p->flag) and 'old'. + */ + m = umode_buf; + *m = '\0'; - for (i = 0; i < 128; i++) - { - flag = user_modes[i]; + for (i = 0; i < 128; i++) { + flag = user_modes[i]; - if((flag & old) && !(source_p->umodes & flag)) - { - if(what == MODE_DEL) - *m++ = (char) i; - else - { - what = MODE_DEL; - *m++ = '-'; - *m++ = (char) i; - } - } - else if(!(flag & old) && (source_p->umodes & flag)) - { - if(what == MODE_ADD) - *m++ = (char) i; - else - { - what = MODE_ADD; - *m++ = '+'; - *m++ = (char) i; - } - } - } - *m = '\0'; + if((flag & old) && !(source_p->umodes & flag)) { + if(what == MODE_DEL) + *m++ = (char) i; + else { + what = MODE_DEL; + *m++ = '-'; + *m++ = (char) i; + } + } else if(!(flag & old) && (source_p->umodes & flag)) { + if(what == MODE_ADD) + *m++ = (char) i; + else { + what = MODE_ADD; + *m++ = '+'; + *m++ = (char) i; + } + } + } + *m = '\0'; - if(*umode_buf && client_p) - sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf); + if(*umode_buf && client_p) + sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf); } /* @@ -1264,34 +1182,32 @@ send_umode(struct Client *client_p, struct Client *source_p, int old, int sendma * * inputs - * output - NONE - * side effects - + * side effects - */ void send_umode_out(struct Client *client_p, struct Client *source_p, int old) { - struct Client *target_p; - char buf[BUFSIZE]; - rb_dlink_node *ptr; + struct Client *target_p; + char buf[BUFSIZE]; + rb_dlink_node *ptr; - send_umode(NULL, source_p, old, 0, buf); + send_umode(NULL, source_p, old, 0, buf); - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - if((target_p != client_p) && (target_p != source_p) && (*buf)) - { - sendto_one(target_p, ":%s MODE %s :%s", - get_id(source_p, target_p), - get_id(source_p, target_p), buf); - } - } + if((target_p != client_p) && (target_p != source_p) && (*buf)) { + sendto_one(target_p, ":%s MODE %s :%s", + get_id(source_p, target_p), + get_id(source_p, target_p), buf); + } + } - if(client_p && MyClient(client_p)) - send_umode(client_p, source_p, old, 0, buf); + if(client_p && MyClient(client_p)) + send_umode(client_p, source_p, old, 0, buf); } -/* +/* * user_welcome * * inputs - client pointer to client to welcome @@ -1301,31 +1217,29 @@ send_umode_out(struct Client *client_p, struct Client *source_p, int old) void user_welcome(struct Client *source_p) { - sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name); - sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST), - get_listener_name(source_p->localClient->listener), ircd_version); - sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation); - sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo, cflagsparaminfo); + sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name); + sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST), + get_listener_name(source_p->localClient->listener), ircd_version); + sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation); + sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo, cflagsparaminfo); - show_isupport(source_p); + show_isupport(source_p); - show_lusers(source_p); + show_lusers(source_p); - if(ConfigFileEntry.short_motd) - { - sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed); - sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it"); + if(ConfigFileEntry.short_motd) { + sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed); + sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it"); - sendto_one(source_p, form_str(RPL_MOTDSTART), - me.name, source_p->name, me.name); + sendto_one(source_p, form_str(RPL_MOTDSTART), + me.name, source_p->name, me.name); - sendto_one(source_p, form_str(RPL_MOTD), - me.name, source_p->name, "*** This is the short motd ***"); + sendto_one(source_p, form_str(RPL_MOTD), + me.name, source_p->name, "*** This is the short motd ***"); - sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name); - } - else - send_user_motd(source_p); + sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name); + } else + send_user_motd(source_p); } /* oper_up() @@ -1338,108 +1252,103 @@ user_welcome(struct Client *source_p) int oper_up(struct Client *source_p, struct oper_conf *oper_p) { - unsigned int old = source_p->umodes, oldsnomask = source_p->snomask; - hook_data_umode_changed hdata; - struct ConfItem *aconf; + unsigned int old = source_p->umodes, oldsnomask = source_p->snomask; + hook_data_umode_changed hdata; + struct ConfItem *aconf; - SetOper(source_p); + SetOper(source_p); - if(oper_p->umodes) - source_p->umodes |= oper_p->umodes; - else if(ConfigFileEntry.oper_umodes) - source_p->umodes |= ConfigFileEntry.oper_umodes; - else - source_p->umodes |= DEFAULT_OPER_UMODES; + if(oper_p->umodes) + source_p->umodes |= oper_p->umodes; + else if(ConfigFileEntry.oper_umodes) + source_p->umodes |= ConfigFileEntry.oper_umodes; + else + source_p->umodes |= DEFAULT_OPER_UMODES; - if(oper_p->swhois) - user_metadata_add(source_p, "SWHOIS", oper_p->swhois, 1); + if(oper_p->swhois) + user_metadata_add(source_p, "SWHOIS", oper_p->swhois, 1); - if(oper_p->operstring) - user_metadata_add(source_p, "OPERSTRING", oper_p->operstring, 1); + if(oper_p->operstring) + user_metadata_add(source_p, "OPERSTRING", oper_p->operstring, 1); - if(oper_p->vhost || !EmptyString(GlobalSetOptions.operhost)) - { - if(oper_p->vhost) - change_nick_user_host(source_p, source_p->name, source_p->username, oper_p->vhost, 0, "Changing host"); - else - change_nick_user_host(source_p, source_p->name, source_p->username, GlobalSetOptions.operhost, 0, "Changing host"); - - sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", source_p->host, source_p->servptr->name); + if(oper_p->vhost || !EmptyString(GlobalSetOptions.operhost)) { + if(oper_p->vhost) + change_nick_user_host(source_p, source_p->name, source_p->username, oper_p->vhost, 0, "Changing host"); + else + change_nick_user_host(source_p, source_p->name, source_p->username, GlobalSetOptions.operhost, 0, "Changing host"); - sendto_server(NULL, NULL, - CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", - use_id(&me), use_id(source_p), source_p->host); - sendto_server(NULL, NULL, - CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", - use_id(&me), use_id(source_p), source_p->host); + sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", source_p->host, source_p->servptr->name); - if (!IsDynSpoof(source_p)) - SetDynSpoof(source_p); - } + sendto_server(NULL, NULL, + CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s", + use_id(&me), use_id(source_p), source_p->host); + sendto_server(NULL, NULL, + CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s", + use_id(&me), use_id(source_p), source_p->host); - if (oper_p->snomask) - { - source_p->snomask |= oper_p->snomask; - source_p->umodes |= UMODE_SERVNOTICE; - } - else if (source_p->umodes & UMODE_SERVNOTICE) - { - /* Only apply these if +s is already set -- jilles */ - if (ConfigFileEntry.oper_snomask) - source_p->snomask |= ConfigFileEntry.oper_snomask; - else - source_p->snomask |= DEFAULT_OPER_SNOMASK; - } + if (!IsDynSpoof(source_p)) + SetDynSpoof(source_p); + } - Count.oper++; + if (oper_p->snomask) { + source_p->snomask |= oper_p->snomask; + source_p->umodes |= UMODE_SERVNOTICE; + } else if (source_p->umodes & UMODE_SERVNOTICE) { + /* Only apply these if +s is already set -- jilles */ + if (ConfigFileEntry.oper_snomask) + source_p->snomask |= ConfigFileEntry.oper_snomask; + else + source_p->snomask |= DEFAULT_OPER_SNOMASK; + } - SetExemptKline(source_p); + Count.oper++; - source_p->flags2 |= oper_p->flags; - source_p->localClient->opername = rb_strdup(oper_p->name); - source_p->localClient->privset = privilegeset_ref(oper_p->privset); + SetExemptKline(source_p); - rb_dlinkAddAlloc(source_p, &local_oper_list); - rb_dlinkAddAlloc(source_p, &oper_list); + source_p->flags2 |= oper_p->flags; + source_p->localClient->opername = rb_strdup(oper_p->name); + source_p->localClient->privset = privilegeset_ref(oper_p->privset); - if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p)) - source_p->umodes |= UMODE_ADMIN; - if(!IsOperN(source_p)) - source_p->snomask &= ~SNO_NCHANGE; - if(!IsOperOperwall(source_p)) - source_p->umodes &= ~UMODE_OPERWALL; - if (!IsOperOverride(source_p)) - source_p->umodes &= ~UMODE_OVERRIDE; - hdata.client = source_p; - hdata.oldumodes = old; - hdata.oldsnomask = oldsnomask; - call_hook(h_umode_changed, &hdata); + rb_dlinkAddAlloc(source_p, &local_oper_list); + rb_dlinkAddAlloc(source_p, &oper_list); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name, - source_p->username, source_p->host); - if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p)) - ++Count.invisi; - if((old & UMODE_INVISIBLE) && !IsInvisible(source_p)) - --Count.invisi; - send_umode_out(source_p, source_p, old); - sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), - construct_snobuf(source_p->snomask)); - sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); - sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name); - sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs); - send_oper_motd(source_p); + if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p)) + source_p->umodes |= UMODE_ADMIN; + if(!IsOperN(source_p)) + source_p->snomask &= ~SNO_NCHANGE; + if(!IsOperOperwall(source_p)) + source_p->umodes &= ~UMODE_OPERWALL; + if (!IsOperOverride(source_p)) + source_p->umodes &= ~UMODE_OVERRIDE; + hdata.client = source_p; + hdata.oldumodes = old; + hdata.oldsnomask = oldsnomask; + call_hook(h_umode_changed, &hdata); - aconf = source_p->localClient->att_conf; + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name, + source_p->username, source_p->host); + if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p)) + ++Count.invisi; + if((old & UMODE_INVISIBLE) && !IsInvisible(source_p)) + --Count.invisi; + send_umode_out(source_p, source_p, old); + sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), + construct_snobuf(source_p->snomask)); + sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); + sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name); + sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs); + send_oper_motd(source_p); - /* If we're setting +p, expire it */ - if(ConfigFileEntry.expire_override_time && MyClient(source_p) && source_p->umodes & UMODE_OVERRIDE) - { - source_p->localClient->override_timeout_event = - rb_event_addonce("expire_override", expire_umode_p, source_p, ConfigFileEntry.expire_override_time); - } + aconf = source_p->localClient->att_conf; - return (1); + /* If we're setting +p, expire it */ + if(ConfigFileEntry.expire_override_time && MyClient(source_p) && source_p->umodes & UMODE_OVERRIDE) { + source_p->localClient->override_timeout_event = + rb_event_addonce("expire_override", expire_umode_p, source_p, ConfigFileEntry.expire_override_time); + } + + return (1); } /* @@ -1453,168 +1362,150 @@ oper_up(struct Client *source_p, struct oper_conf *oper_p) unsigned int find_umode_slot(void) { - unsigned int all_umodes = 0, my_umode = 0, i; + unsigned int all_umodes = 0, my_umode = 0, i; - for (i = 0; i < 128; i++) - all_umodes |= user_modes[i]; + for (i = 0; i < 128; i++) + all_umodes |= user_modes[i]; - for (my_umode = 1; my_umode && (all_umodes & my_umode); - my_umode <<= 1); + for (my_umode = 1; my_umode && (all_umodes & my_umode); + my_umode <<= 1); - return my_umode; + return my_umode; } void construct_umodebuf(void) { - int i; - char *ptr = umodebuf; - static int prev_user_modes[128]; + int i; + char *ptr = umodebuf; + static int prev_user_modes[128]; - *ptr = '\0'; + *ptr = '\0'; - for (i = 0; i < 128; i++) - { - if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i]) - { - if (user_modes[i] == 0) - { - orphaned_umodes |= prev_user_modes[i]; - sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i); - } - else - { - orphaned_umodes &= ~prev_user_modes[i]; - sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i); - } - user_modes[i] = prev_user_modes[i]; - } - else - prev_user_modes[i] = user_modes[i]; - if (user_modes[i]) - *ptr++ = (char) i; - } + for (i = 0; i < 128; i++) { + if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i]) { + if (user_modes[i] == 0) { + orphaned_umodes |= prev_user_modes[i]; + sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i); + } else { + orphaned_umodes &= ~prev_user_modes[i]; + sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i); + } + user_modes[i] = prev_user_modes[i]; + } else + prev_user_modes[i] = user_modes[i]; + if (user_modes[i]) + *ptr++ = (char) i; + } - *ptr++ = '\0'; + *ptr++ = '\0'; } void change_nick_user_host(struct Client *target_p, const char *nick, const char *user, - const char *host, int newts, const char *format, ...) + const char *host, int newts, const char *format, ...) { - rb_dlink_node *ptr; - struct Channel *chptr; - struct membership *mscptr; - int changed = irccmp(target_p->name, nick); - int changed_case = strcmp(target_p->name, nick); - int do_qjm = irccmp(target_p->username, user) || (irccmp(target_p->host, host) && ConfigChannel.cycle_host_change); - char mode[10], modeval[NICKLEN * 4 + 4], reason[256], *mptr; - va_list ap; + rb_dlink_node *ptr; + struct Channel *chptr; + struct membership *mscptr; + int changed = irccmp(target_p->name, nick); + int changed_case = strcmp(target_p->name, nick); + int do_qjm = irccmp(target_p->username, user) || (irccmp(target_p->host, host) && ConfigChannel.cycle_host_change); + char mode[10], modeval[NICKLEN * 4 + 4], reason[256], *mptr; + va_list ap; - modeval[0] = '\0'; - - if(changed) - { - target_p->tsinfo = newts; - monitor_signoff(target_p); - } - invalidate_bancache_user(target_p); + modeval[0] = '\0'; - if(do_qjm) - { - va_start(ap, format); - vsnprintf(reason, 255, format, ap); - va_end(ap); + if(changed) { + target_p->tsinfo = newts; + monitor_signoff(target_p); + } + invalidate_bancache_user(target_p); - sendto_common_channels_local_butone(target_p, NOCAPS, ":%s!%s@%s QUIT :%s", - target_p->name, target_p->username, target_p->host, - reason); + if(do_qjm) { + va_start(ap, format); + vsnprintf(reason, 255, format, ap); + va_end(ap); - RB_DLINK_FOREACH(ptr, target_p->user->channel.head) - { - mscptr = ptr->data; - chptr = mscptr->chptr; - mptr = mode; + sendto_common_channels_local_butone(target_p, NOCAPS, ":%s!%s@%s QUIT :%s", + target_p->name, target_p->username, target_p->host, + reason); - if(is_owner(mscptr)) - { + RB_DLINK_FOREACH(ptr, target_p->user->channel.head) { + mscptr = ptr->data; + chptr = mscptr->chptr; + mptr = mode; + + if(is_owner(mscptr)) { *mptr++ = 'y'; strcat(modeval, nick); strcat(modeval, " "); } - if(is_admin(mscptr)) - { - *mptr++ = 'a'; - strcat(modeval, nick); - strcat(modeval, " "); - } + if(is_admin(mscptr)) { + *mptr++ = 'a'; + strcat(modeval, nick); + strcat(modeval, " "); + } - if(is_chanop(mscptr)) - { - *mptr++ = 'o'; - strcat(modeval, nick); - strcat(modeval, " "); - } + if(is_chanop(mscptr)) { + *mptr++ = 'o'; + strcat(modeval, nick); + strcat(modeval, " "); + } - if(is_halfop(mscptr)) - { - *mptr++ = 'h'; - strcat(modeval, nick); - strcat(modeval, " "); - } + if(is_halfop(mscptr)) { + *mptr++ = 'h'; + strcat(modeval, nick); + strcat(modeval, " "); + } - if(is_voiced(mscptr)) - { - *mptr++ = 'v'; - strcat(modeval, nick); - } + if(is_voiced(mscptr)) { + *mptr++ = 'v'; + strcat(modeval, nick); + } - *mptr = '\0'; + *mptr = '\0'; - sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", - nick, user, host, chptr->chname); + sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", + nick, user, host, chptr->chname); - if(*mode) - sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, - ":%s MODE %s +%s %s", - target_p->servptr->name, - chptr->chname, mode, modeval); + if(*mode) + sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, + ":%s MODE %s +%s %s", + target_p->servptr->name, + chptr->chname, mode, modeval); - *modeval = '\0'; - } + *modeval = '\0'; + } - if(MyClient(target_p) && changed_case) - sendto_one(target_p, ":%s!%s@%s NICK %s", - target_p->name, target_p->username, target_p->host, nick); - } - else if(changed_case) - { - sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s", - target_p->name, target_p->username, - target_p->host, nick); - } - - //Needed check for away-notify - if(target_p->user->away != NULL) - { - sendto_common_channels_local_butone(target_p, CLICAP_AWAY_NOTIFY, ":%s!%s@%s AWAY :%s", - target_p->name, target_p->username, host, target_p->user->away); + if(MyClient(target_p) && changed_case) + sendto_one(target_p, ":%s!%s@%s NICK %s", + target_p->name, target_p->username, target_p->host, nick); + } else if(changed_case) { + sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s", + target_p->name, target_p->username, + target_p->host, nick); } - rb_strlcpy(target_p->username, user, sizeof target_p->username); - rb_strlcpy(target_p->host, host, sizeof target_p->host); + //Needed check for away-notify + if(target_p->user->away != NULL) { + sendto_common_channels_local_butone(target_p, CLICAP_AWAY_NOTIFY, ":%s!%s@%s AWAY :%s", + target_p->name, target_p->username, host, target_p->user->away); + } - if (changed) - add_history(target_p, 1); + rb_strlcpy(target_p->username, user, sizeof target_p->username); + rb_strlcpy(target_p->host, host, sizeof target_p->host); - del_from_client_hash(target_p->name, target_p); - rb_strlcpy(target_p->name, nick, NICKLEN); - add_to_client_hash(target_p->name, target_p); + if (changed) + add_history(target_p, 1); - if(changed) - { - monitor_signon(target_p); - del_all_accepts(target_p); - } + del_from_client_hash(target_p->name, target_p); + rb_strlcpy(target_p->name, nick, NICKLEN); + add_to_client_hash(target_p->name, target_p); + + if(changed) { + monitor_signon(target_p); + del_all_accepts(target_p); + } } diff --git a/src/scache.c b/src/scache.c index a186ba1..8281718 100644 --- a/src/scache.c +++ b/src/scache.c @@ -35,11 +35,11 @@ /* - * ircd used to store full servernames in anUser as well as in the + * ircd used to store full servernames in anUser as well as in the * whowas info. there can be some 40k such structures alive at any * given time, while the number of unique server names a server sees * in its lifetime is at most a few hundred. by tokenizing server - * names internally, the server can easily save 2 or 3 megs of RAM. + * names internally, the server can easily save 2 or 3 megs of RAM. * -orabidoo * * reworked to serve for flattening/delaying /links also @@ -52,15 +52,14 @@ #define SC_ONLINE 1 #define SC_HIDDEN 2 -struct scache_entry -{ - char name[HOSTLEN + 1]; - char info[REALLEN + 1]; - int flags; - time_t known_since; - time_t last_connect; - time_t last_split; - struct scache_entry *next; +struct scache_entry { + char name[HOSTLEN + 1]; + char info[REALLEN + 1]; + int flags; + time_t known_since; + time_t last_connect; + time_t last_split; + struct scache_entry *next; }; static struct scache_entry *scache_hash[SCACHE_HASH_SIZE]; @@ -68,79 +67,77 @@ static struct scache_entry *scache_hash[SCACHE_HASH_SIZE]; void clear_scache_hash_table(void) { - memset(scache_hash, 0, sizeof(scache_hash)); + memset(scache_hash, 0, sizeof(scache_hash)); } static int sc_hash(const char *string) { - int hash_value; + int hash_value; - hash_value = 0; - while (*string) - { - hash_value += ToLower(*string++); - } + hash_value = 0; + while (*string) { + hash_value += ToLower(*string++); + } - return hash_value % SCACHE_HASH_SIZE; + return hash_value % SCACHE_HASH_SIZE; } static struct scache_entry * find_or_add(const char *name) { - int hash_index; - struct scache_entry *ptr; + int hash_index; + struct scache_entry *ptr; - ptr = scache_hash[hash_index = sc_hash(name)]; - for (; ptr; ptr = ptr->next) - { - if(!irccmp(ptr->name, name)) - return ptr; - } + ptr = scache_hash[hash_index = sc_hash(name)]; + for (; ptr; ptr = ptr->next) { + if(!irccmp(ptr->name, name)) + return ptr; + } - ptr = (struct scache_entry *) rb_malloc(sizeof(struct scache_entry)); - s_assert(0 != ptr); + ptr = (struct scache_entry *) rb_malloc(sizeof(struct scache_entry)); + s_assert(0 != ptr); - rb_strlcpy(ptr->name, name, sizeof(ptr->name)); - ptr->info[0] = '\0'; - ptr->flags = 0; - ptr->known_since = rb_current_time(); - ptr->last_connect = 0; - ptr->last_split = 0; + rb_strlcpy(ptr->name, name, sizeof(ptr->name)); + ptr->info[0] = '\0'; + ptr->flags = 0; + ptr->known_since = rb_current_time(); + ptr->last_connect = 0; + ptr->last_split = 0; - ptr->next = scache_hash[hash_index]; - scache_hash[hash_index] = ptr; - return ptr; + ptr->next = scache_hash[hash_index]; + scache_hash[hash_index] = ptr; + return ptr; } struct scache_entry * scache_connect(const char *name, const char *info, int hidden) { - struct scache_entry *ptr; + struct scache_entry *ptr; - ptr = find_or_add(name); - rb_strlcpy(ptr->info, info, sizeof(ptr->info)); - ptr->flags |= SC_ONLINE; - if (hidden) - ptr->flags |= SC_HIDDEN; - else - ptr->flags &= ~SC_HIDDEN; - ptr->last_connect = rb_current_time(); - return ptr; + ptr = find_or_add(name); + rb_strlcpy(ptr->info, info, sizeof(ptr->info)); + ptr->flags |= SC_ONLINE; + if (hidden) + ptr->flags |= SC_HIDDEN; + else + ptr->flags &= ~SC_HIDDEN; + ptr->last_connect = rb_current_time(); + return ptr; } void scache_split(struct scache_entry *ptr) { - if (ptr == NULL) - return; - ptr->flags &= ~SC_ONLINE; - ptr->last_split = rb_current_time(); + if (ptr == NULL) + return; + ptr->flags &= ~SC_ONLINE; + ptr->last_split = rb_current_time(); } const char *scache_get_name(struct scache_entry *ptr) { - return ptr->name; + return ptr->name; } /* scache_send_flattened_links() @@ -152,35 +149,33 @@ const char *scache_get_name(struct scache_entry *ptr) void scache_send_flattened_links(struct Client *source_p) { - struct scache_entry *scache_ptr; - int i; - int show; + struct scache_entry *scache_ptr; + int i; + int show; - for (i = 0; i < SCACHE_HASH_SIZE; i++) - { - scache_ptr = scache_hash[i]; - while (scache_ptr) - { - if (!irccmp(scache_ptr->name, me.name)) - show = FALSE; - else if (scache_ptr->flags & SC_HIDDEN && - !ConfigServerHide.disable_hidden) - show = FALSE; - else if (scache_ptr->flags & SC_ONLINE) - show = scache_ptr->known_since < rb_current_time() - ConfigServerHide.links_delay; - else - show = scache_ptr->last_split > rb_current_time() - ConfigServerHide.links_delay && scache_ptr->last_split - scache_ptr->known_since > ConfigServerHide.links_delay; - if (show) - sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), - scache_ptr->name, me.name, 1, scache_ptr->info); + for (i = 0; i < SCACHE_HASH_SIZE; i++) { + scache_ptr = scache_hash[i]; + while (scache_ptr) { + if (!irccmp(scache_ptr->name, me.name)) + show = FALSE; + else if (scache_ptr->flags & SC_HIDDEN && + !ConfigServerHide.disable_hidden) + show = FALSE; + else if (scache_ptr->flags & SC_ONLINE) + show = scache_ptr->known_since < rb_current_time() - ConfigServerHide.links_delay; + else + show = scache_ptr->last_split > rb_current_time() - ConfigServerHide.links_delay && scache_ptr->last_split - scache_ptr->known_since > ConfigServerHide.links_delay; + if (show) + sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), + scache_ptr->name, me.name, 1, scache_ptr->info); - scache_ptr = scache_ptr->next; - } - } - sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), - me.name, me.name, 0, me.info); + scache_ptr = scache_ptr->next; + } + } + sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), + me.name, me.name, 0, me.info); - sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS), "*"); + sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS), "*"); } #define MISSING_TIMEOUT 86400 @@ -194,21 +189,19 @@ scache_send_flattened_links(struct Client *source_p) void scache_send_missing(struct Client *source_p) { - struct scache_entry *scache_ptr; - int i; + struct scache_entry *scache_ptr; + int i; - for (i = 0; i < SCACHE_HASH_SIZE; i++) - { - scache_ptr = scache_hash[i]; - while (scache_ptr) - { - if (!(scache_ptr->flags & SC_ONLINE) && scache_ptr->last_split > rb_current_time() - MISSING_TIMEOUT) - sendto_one_numeric(source_p, RPL_MAP, "** %s (recently split)", - scache_ptr->name); + for (i = 0; i < SCACHE_HASH_SIZE; i++) { + scache_ptr = scache_hash[i]; + while (scache_ptr) { + if (!(scache_ptr->flags & SC_ONLINE) && scache_ptr->last_split > rb_current_time() - MISSING_TIMEOUT) + sendto_one_numeric(source_p, RPL_MAP, "** %s (recently split)", + scache_ptr->name); - scache_ptr = scache_ptr->next; - } - } + scache_ptr = scache_ptr->next; + } + } } /* * count_scache @@ -220,22 +213,20 @@ scache_send_missing(struct Client *source_p) void count_scache(size_t * number_servers_cached, size_t * mem_servers_cached) { - struct scache_entry *scache_ptr; - int i; + struct scache_entry *scache_ptr; + int i; - *number_servers_cached = 0; - *mem_servers_cached = 0; + *number_servers_cached = 0; + *mem_servers_cached = 0; - for (i = 0; i < SCACHE_HASH_SIZE; i++) - { - scache_ptr = scache_hash[i]; - while (scache_ptr) - { - *number_servers_cached = *number_servers_cached + 1; - *mem_servers_cached = *mem_servers_cached + - sizeof(struct scache_entry ); + for (i = 0; i < SCACHE_HASH_SIZE; i++) { + scache_ptr = scache_hash[i]; + while (scache_ptr) { + *number_servers_cached = *number_servers_cached + 1; + *mem_servers_cached = *mem_servers_cached + + sizeof(struct scache_entry ); - scache_ptr = scache_ptr->next; - } - } + scache_ptr = scache_ptr->next; + } + } } diff --git a/src/send.c b/src/send.c index 3b62f11..41a2b84 100644 --- a/src/send.c +++ b/src/send.c @@ -59,52 +59,47 @@ struct Client *remote_rehash_oper_p; static int _send_linebuf(struct Client *to, buf_head_t *linebuf) { - if(IsMe(to)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!"); - return 0; - } + if(IsMe(to)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!"); + return 0; + } - if(!MyConnect(to) || IsIOError(to)) - return 0; + if(!MyConnect(to) || IsIOError(to)) + return 0; - if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to)) - { - if(IsServer(to)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Max SendQ limit exceeded for %s: %u > %lu", - to->name, - rb_linebuf_len(&to->localClient->buf_sendq), - get_sendq(to)); + if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to)) { + if(IsServer(to)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Max SendQ limit exceeded for %s: %u > %lu", + to->name, + rb_linebuf_len(&to->localClient->buf_sendq), + get_sendq(to)); - ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu", - log_client_name(to, SHOW_IP), - rb_linebuf_len(&to->localClient->buf_sendq), - get_sendq(to)); - } + ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu", + log_client_name(to, SHOW_IP), + rb_linebuf_len(&to->localClient->buf_sendq), + get_sendq(to)); + } - dead_link(to, 1); - return -1; - } - else - { - /* just attach the linebuf to the sendq instead of - * generating a new one - */ - rb_linebuf_attach(&to->localClient->buf_sendq, linebuf); - } + dead_link(to, 1); + return -1; + } else { + /* just attach the linebuf to the sendq instead of + * generating a new one + */ + rb_linebuf_attach(&to->localClient->buf_sendq, linebuf); + } - /* - ** Update statistics. The following is slightly incorrect - ** because it counts messages even if queued, but bytes - ** only really sent. Queued bytes get updated in SendQueued. - */ - to->localClient->sendM += 1; - me.localClient->sendM += 1; - if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) - send_queued(to); - return 0; + /* + ** Update statistics. The following is slightly incorrect + ** because it counts messages even if queued, but bytes + ** only really sent. Queued bytes get updated in SendQueued. + */ + to->localClient->sendM += 1; + me.localClient->sendM += 1; + if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) + send_queued(to); + return 0; } /* send_linebuf_remote() @@ -116,13 +111,13 @@ _send_linebuf(struct Client *to, buf_head_t *linebuf) static void send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf) { - if(to->from) - to = to->from; + if(to->from) + to = to->from; - /* we assume the caller has already tested for fake direction */ + /* we assume the caller has already tested for fake direction */ - _send_linebuf(to, linebuf); - return; + _send_linebuf(to, linebuf); + return; } /* send_queued_write() @@ -134,92 +129,84 @@ send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf) void send_queued(struct Client *to) { - int retlen; + int retlen; #ifdef USE_IODEBUG_HOOKS - hook_data_int hd; + hook_data_int hd; #endif - rb_fde_t *F = to->localClient->F; - if (!F) - return; + rb_fde_t *F = to->localClient->F; + if (!F) + return; - /* cant write anything to a dead socket. */ - if(IsIOError(to)) - return; + /* cant write anything to a dead socket. */ + if(IsIOError(to)) + return; - /* Something wants us to not send anything currently */ - /* if(IsCork(to)) - return; */ + /* Something wants us to not send anything currently */ + /* if(IsCork(to)) + return; */ - /* try to flush later when the write event resets this */ - if(IsFlush(to)) - return; + /* try to flush later when the write event resets this */ + if(IsFlush(to)) + return; #ifdef USE_IODEBUG_HOOKS - hd.client = to; - if(to->localClient->buf_sendq.list.head) - hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head->data)->buf + - to->localClient->buf_sendq.writeofs; + hd.client = to; + if(to->localClient->buf_sendq.list.head) + hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head->data)->buf + + to->localClient->buf_sendq.writeofs; #endif - if(rb_linebuf_len(&to->localClient->buf_sendq)) - { - while ((retlen = - rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0) - { - /* We have some data written .. update counters */ + if(rb_linebuf_len(&to->localClient->buf_sendq)) { + while ((retlen = + rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0) { + /* We have some data written .. update counters */ #ifdef USE_IODEBUG_HOOKS - hd.arg2 = retlen; - call_hook(h_iosend_id, &hd); + hd.arg2 = retlen; + call_hook(h_iosend_id, &hd); - if(to->localClient->buf_sendq.list.head) - hd.arg1 = - ((buf_line_t *) to->localClient->buf_sendq.list.head-> - data)->buf + to->localClient->buf_sendq.writeofs; + if(to->localClient->buf_sendq.list.head) + hd.arg1 = + ((buf_line_t *) to->localClient->buf_sendq.list.head-> + data)->buf + to->localClient->buf_sendq.writeofs; #endif - - ClearFlush(to); - to->localClient->sendB += retlen; - me.localClient->sendB += retlen; - if(to->localClient->sendB > 1023) - { - to->localClient->sendK += (to->localClient->sendB >> 10); - to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ - } - else if(me.localClient->sendB > 1023) - { - me.localClient->sendK += (me.localClient->sendB >> 10); - me.localClient->sendB &= 0x03ff; - } - } + ClearFlush(to); - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - dead_link(to, 0); - return; - } - } + to->localClient->sendB += retlen; + me.localClient->sendB += retlen; + if(to->localClient->sendB > 1023) { + to->localClient->sendK += (to->localClient->sendB >> 10); + to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ + } else if(me.localClient->sendB > 1023) { + me.localClient->sendK += (me.localClient->sendB >> 10); + me.localClient->sendB &= 0x03ff; + } + } - if(rb_linebuf_len(&to->localClient->buf_sendq)) - { - SetFlush(to); - rb_setselect(to->localClient->F, RB_SELECT_WRITE, - send_queued_write, to); - } - else - ClearFlush(to); + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + dead_link(to, 0); + return; + } + } + + if(rb_linebuf_len(&to->localClient->buf_sendq)) { + SetFlush(to); + rb_setselect(to->localClient->F, RB_SELECT_WRITE, + send_queued_write, to); + } else + ClearFlush(to); } void send_pop_queue(struct Client *to) { - if(to->from != NULL) - to = to->from; - if(!MyConnect(to) || IsIOError(to)) - return; - if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) - send_queued(to); + if(to->from != NULL) + to = to->from; + if(!MyConnect(to) || IsIOError(to)) + return; + if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) + send_queued(to); } /* send_queued_write() @@ -231,39 +218,39 @@ send_pop_queue(struct Client *to) static void send_queued_write(rb_fde_t *F, void *data) { - struct Client *to = data; - ClearFlush(to); - send_queued(to); + struct Client *to = data; + ClearFlush(to); + send_queued(to); } /* sendto_one() * * inputs - client to send to, va_args * outputs - client has message put into its queue - * side effects - + * side effects - */ void sendto_one(struct Client *target_p, const char *pattern, ...) { - va_list args; - buf_head_t linebuf; + va_list args; + buf_head_t linebuf; - /* send remote if to->from non NULL */ - if(target_p->from != NULL) - target_p = target_p->from; + /* send remote if to->from non NULL */ + if(target_p->from != NULL) + target_p = target_p->from; - if(IsIOError(target_p)) - return; + if(IsIOError(target_p)) + return; - rb_linebuf_newbuf(&linebuf); + rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); - va_end(args); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); - _send_linebuf(target_p, &linebuf); + _send_linebuf(target_p, &linebuf); - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } @@ -275,37 +262,36 @@ sendto_one(struct Client *target_p, const char *pattern, ...) */ void sendto_one_prefix(struct Client *target_p, struct Client *source_p, - const char *command, const char *pattern, ...) + const char *command, const char *pattern, ...) { - struct Client *dest_p; - va_list args; - buf_head_t linebuf; + struct Client *dest_p; + va_list args; + buf_head_t linebuf; - /* send remote if to->from non NULL */ - if(target_p->from != NULL) - dest_p = target_p->from; - else - dest_p = target_p; + /* send remote if to->from non NULL */ + if(target_p->from != NULL) + dest_p = target_p->from; + else + dest_p = target_p; - if(IsIOError(dest_p)) - return; + if(IsIOError(dest_p)) + return; - if(IsMe(dest_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); - return; - } + if(IsMe(dest_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); + return; + } - rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s %s %s ", - get_id(source_p, target_p), - command, get_id(target_p, target_p)); - va_end(args); + rb_linebuf_newbuf(&linebuf); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s %s %s ", + get_id(source_p, target_p), + command, get_id(target_p, target_p)); + va_end(args); - _send_linebuf(dest_p, &linebuf); - rb_linebuf_donebuf(&linebuf); + _send_linebuf(dest_p, &linebuf); + rb_linebuf_donebuf(&linebuf); } /* sendto_one_notice() @@ -317,35 +303,34 @@ sendto_one_prefix(struct Client *target_p, struct Client *source_p, void sendto_one_notice(struct Client *target_p, const char *pattern, ...) { - struct Client *dest_p; - va_list args; - buf_head_t linebuf; - char *to; + struct Client *dest_p; + va_list args; + buf_head_t linebuf; + char *to; - /* send remote if to->from non NULL */ - if(target_p->from != NULL) - dest_p = target_p->from; - else - dest_p = target_p; + /* send remote if to->from non NULL */ + if(target_p->from != NULL) + dest_p = target_p->from; + else + dest_p = target_p; - if(IsIOError(dest_p)) - return; + if(IsIOError(dest_p)) + return; - if(IsMe(dest_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); - return; - } + if(IsMe(dest_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); + return; + } - rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s NOTICE %s ", - get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); - va_end(args); + rb_linebuf_newbuf(&linebuf); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s NOTICE %s ", + get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); + va_end(args); - _send_linebuf(dest_p, &linebuf); - rb_linebuf_donebuf(&linebuf); + _send_linebuf(dest_p, &linebuf); + rb_linebuf_donebuf(&linebuf); } @@ -358,41 +343,40 @@ sendto_one_notice(struct Client *target_p, const char *pattern, ...) void sendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, ...) { - struct Client *dest_p; - va_list args; - buf_head_t linebuf; - char *to; + struct Client *dest_p; + va_list args; + buf_head_t linebuf; + char *to; - /* send remote if to->from non NULL */ - if(target_p->from != NULL) - dest_p = target_p->from; - else - dest_p = target_p; + /* send remote if to->from non NULL */ + if(target_p->from != NULL) + dest_p = target_p->from; + else + dest_p = target_p; - if(IsIOError(dest_p)) - return; + if(IsIOError(dest_p)) + return; - if(IsMe(dest_p)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); - return; - } + if(IsMe(dest_p)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); + return; + } - rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s %03d %s ", - get_id(&me, target_p), - numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); - va_end(args); + rb_linebuf_newbuf(&linebuf); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s %03d %s ", + get_id(&me, target_p), + numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); + va_end(args); - _send_linebuf(dest_p, &linebuf); - rb_linebuf_donebuf(&linebuf); + _send_linebuf(dest_p, &linebuf); + rb_linebuf_donebuf(&linebuf); } /* * sendto_server - * + * * inputs - pointer to client to NOT send to * - caps or'd together which must ALL be present * - caps or'd together which must ALL NOT be present @@ -402,53 +386,52 @@ sendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, .. * side effects - Send a message to all connected servers, except the * client 'one' (if non-NULL), as long as the servers * support ALL capabs in 'caps', and NO capabs in 'nocaps'. - * + * * This function was written in an attempt to merge together the other * billion sendto_*serv*() functions, which sprung up with capabs, uids etc * -davidt */ void sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps, - unsigned long nocaps, const char *format, ...) + unsigned long nocaps, const char *format, ...) { - va_list args; - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - buf_head_t linebuf; + va_list args; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + buf_head_t linebuf; - /* noone to send to.. */ - if(rb_dlink_list_length(&serv_list) == 0) - return; + /* noone to send to.. */ + if(rb_dlink_list_length(&serv_list) == 0) + return; - if(chptr != NULL && *chptr->chname != '#') - return; + if(chptr != NULL && *chptr->chname != '#') + return; - rb_linebuf_newbuf(&linebuf); - va_start(args, format); - rb_linebuf_putmsg(&linebuf, format, &args, NULL); - va_end(args); + rb_linebuf_newbuf(&linebuf); + va_start(args, format); + rb_linebuf_putmsg(&linebuf, format, &args, NULL); + va_end(args); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) { + target_p = ptr->data; - /* check against 'one' */ - if(one != NULL && (target_p == one->from)) - continue; + /* check against 'one' */ + if(one != NULL && (target_p == one->from)) + continue; - /* check we have required capabs */ - if(!IsCapable(target_p, caps)) - continue; + /* check we have required capabs */ + if(!IsCapable(target_p, caps)) + continue; - /* check we don't have any forbidden capabs */ - if(!NotCapable(target_p, nocaps)) - continue; + /* check we don't have any forbidden capabs */ + if(!NotCapable(target_p, nocaps)) + continue; - _send_linebuf(target_p, &linebuf); - } + _send_linebuf(target_p, &linebuf); + } - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } @@ -460,71 +443,67 @@ sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps, */ void sendto_channel_flags(struct Client *one, int type, struct Client *source_p, - struct Channel *chptr, const char *pattern, ...) + struct Channel *chptr, const char *pattern, ...) { - static char buf[BUFSIZE]; - va_list args; - buf_head_t rb_linebuf_local; - buf_head_t rb_linebuf_id; - struct Client *target_p; - struct membership *msptr; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + static char buf[BUFSIZE]; + va_list args; + buf_head_t rb_linebuf_local; + buf_head_t rb_linebuf_id; + struct Client *target_p; + struct membership *msptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - rb_linebuf_newbuf(&rb_linebuf_local); - rb_linebuf_newbuf(&rb_linebuf_id); + rb_linebuf_newbuf(&rb_linebuf_local); + rb_linebuf_newbuf(&rb_linebuf_id); - current_serial++; + current_serial++; - va_start(args, pattern); - rb_vsnprintf(buf, sizeof(buf), pattern, args); - va_end(args); + va_start(args, pattern); + rb_vsnprintf(buf, sizeof(buf), pattern, args); + va_end(args); - if(IsServer(source_p)) - rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, - ":%s %s", source_p->name, buf); - else - rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, - ":%s!%s@%s %s", - source_p->name, source_p->username, - source_p->host, buf); + if(IsServer(source_p)) + rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, + ":%s %s", source_p->name, buf); + else + rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, + ":%s!%s@%s %s", + source_p->name, source_p->username, + source_p->host, buf); - rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); + rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(IsIOError(target_p->from) || target_p->from == one) - continue; + if(IsIOError(target_p->from) || target_p->from == one) + continue; - if(type && ((msptr->flags & type) == 0)) - continue; + if(type && ((msptr->flags & type) == 0)) + continue; - if(IsDeaf(target_p)) - continue; + if(IsDeaf(target_p)) + continue; - if(!MyClient(target_p)) - { - /* if we've got a specific type, target must support - * CHW.. --fl - */ - if(type && NotCapable(target_p->from, CAP_CHW)) - continue; + if(!MyClient(target_p)) { + /* if we've got a specific type, target must support + * CHW.. --fl + */ + if(type && NotCapable(target_p->from, CAP_CHW)) + continue; - if(target_p->from->serial != current_serial) - { - send_linebuf_remote(target_p, source_p, &rb_linebuf_id); - target_p->from->serial = current_serial; - } - } - else - _send_linebuf(target_p, &rb_linebuf_local); - } + if(target_p->from->serial != current_serial) { + send_linebuf_remote(target_p, source_p, &rb_linebuf_id); + target_p->from->serial = current_serial; + } + } else + _send_linebuf(target_p, &rb_linebuf_local); + } - rb_linebuf_donebuf(&rb_linebuf_local); - rb_linebuf_donebuf(&rb_linebuf_id); + rb_linebuf_donebuf(&rb_linebuf_local); + rb_linebuf_donebuf(&rb_linebuf_id); } /* sendto_channel_flags() @@ -535,84 +514,80 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p, */ void sendto_channel_opmod(struct Client *one, struct Client *source_p, - struct Channel *chptr, const char *command, - const char *text) + struct Channel *chptr, const char *command, + const char *text) { - buf_head_t rb_linebuf_local; - buf_head_t rb_linebuf_old; - buf_head_t rb_linebuf_new; - struct Client *target_p; - struct membership *msptr; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; + buf_head_t rb_linebuf_local; + buf_head_t rb_linebuf_old; + buf_head_t rb_linebuf_new; + struct Client *target_p; + struct membership *msptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - rb_linebuf_newbuf(&rb_linebuf_local); - rb_linebuf_newbuf(&rb_linebuf_old); - rb_linebuf_newbuf(&rb_linebuf_new); + rb_linebuf_newbuf(&rb_linebuf_local); + rb_linebuf_newbuf(&rb_linebuf_old); + rb_linebuf_newbuf(&rb_linebuf_new); - current_serial++; + current_serial++; - if(IsServer(source_p)) - rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, - ":%s %s %s :%s", - source_p->name, command, chptr->chname, text); - else - rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, - ":%s!%s@%s %s %s :%s", - source_p->name, source_p->username, - source_p->host, command, chptr->chname, text); + if(IsServer(source_p)) + rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, + ":%s %s %s :%s", + source_p->name, command, chptr->chname, text); + else + rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, + ":%s!%s@%s %s %s :%s", + source_p->name, source_p->username, + source_p->host, command, chptr->chname, text); - if (chptr->mode.mode & MODE_MODERATED) - rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, - ":%s %s %s :%s", - use_id(source_p), command, chptr->chname, text); - else - rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, - ":%s NOTICE @%s :<%s:%s> %s", - use_id(source_p->servptr), chptr->chname, - source_p->name, chptr->chname, text); - rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL, - ":%s %s =%s :%s", - use_id(source_p), command, chptr->chname, text); + if (chptr->mode.mode & MODE_MODERATED) + rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, + ":%s %s %s :%s", + use_id(source_p), command, chptr->chname, text); + else + rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, + ":%s NOTICE @%s :<%s:%s> %s", + use_id(source_p->servptr), chptr->chname, + source_p->name, chptr->chname, text); + rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL, + ":%s %s =%s :%s", + use_id(source_p), command, chptr->chname, text); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(IsIOError(target_p->from) || target_p->from == one) - continue; + if(IsIOError(target_p->from) || target_p->from == one) + continue; - if(!is_any_op(msptr)) - continue; + if(!is_any_op(msptr)) + continue; - if(IsDeaf(target_p)) - continue; + if(IsDeaf(target_p)) + continue; - if(!MyClient(target_p)) - { - /* if we've got a specific type, target must support - * CHW.. --fl - */ - if(NotCapable(target_p->from, CAP_CHW)) - continue; + if(!MyClient(target_p)) { + /* if we've got a specific type, target must support + * CHW.. --fl + */ + if(NotCapable(target_p->from, CAP_CHW)) + continue; - if(target_p->from->serial != current_serial) - { - if (IsCapable(target_p->from, CAP_EOPMOD)) - send_linebuf_remote(target_p, source_p, &rb_linebuf_new); - else - send_linebuf_remote(target_p, source_p, &rb_linebuf_old); - target_p->from->serial = current_serial; - } - } - else - _send_linebuf(target_p, &rb_linebuf_local); - } + if(target_p->from->serial != current_serial) { + if (IsCapable(target_p->from, CAP_EOPMOD)) + send_linebuf_remote(target_p, source_p, &rb_linebuf_new); + else + send_linebuf_remote(target_p, source_p, &rb_linebuf_old); + target_p->from->serial = current_serial; + } + } else + _send_linebuf(target_p, &rb_linebuf_local); + } - rb_linebuf_donebuf(&rb_linebuf_local); - rb_linebuf_donebuf(&rb_linebuf_old); - rb_linebuf_donebuf(&rb_linebuf_new); + rb_linebuf_donebuf(&rb_linebuf_local); + rb_linebuf_donebuf(&rb_linebuf_old); + rb_linebuf_donebuf(&rb_linebuf_new); } /* sendto_channel_local() @@ -624,39 +599,36 @@ sendto_channel_opmod(struct Client *one, struct Client *source_p, void sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...) { - va_list args; - buf_head_t linebuf; - struct membership *msptr; - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - - rb_linebuf_newbuf(&linebuf); - - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); - va_end(args); + va_list args; + buf_head_t linebuf; + struct membership *msptr; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + rb_linebuf_newbuf(&linebuf); - if(IsIOError(target_p)) - continue; + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); - if(type == ONLY_OPERS) - { - if(!IsOper(target_p)) - continue; - } - else if(type && ((msptr->flags & type) == 0)) - continue; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) { + msptr = ptr->data; + target_p = msptr->client_p; - _send_linebuf(target_p, &linebuf); - } + if(IsIOError(target_p)) + continue; - rb_linebuf_donebuf(&linebuf); + if(type == ONLY_OPERS) { + if(!IsOper(target_p)) + continue; + } else if(type && ((msptr->flags & type) == 0)) + continue; + + _send_linebuf(target_p, &linebuf); + } + + rb_linebuf_donebuf(&linebuf); } /* sendto_channel_local_butone() @@ -669,37 +641,36 @@ sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...) void sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...) { - va_list args; - buf_head_t linebuf; - struct membership *msptr; - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - - rb_linebuf_newbuf(&linebuf); - - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); - va_end(args); + va_list args; + buf_head_t linebuf; + struct membership *msptr; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) - { - msptr = ptr->data; - target_p = msptr->client_p; + rb_linebuf_newbuf(&linebuf); - if(target_p == one) - continue; + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); - if(IsIOError(target_p)) - continue; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) { + msptr = ptr->data; + target_p = msptr->client_p; - if(type && ((msptr->flags & type) == 0)) - continue; + if(target_p == one) + continue; - _send_linebuf(target_p, &linebuf); - } + if(IsIOError(target_p)) + continue; - rb_linebuf_donebuf(&linebuf); + if(type && ((msptr->flags & type) == 0)) + continue; + + _send_linebuf(target_p, &linebuf); + } + + rb_linebuf_donebuf(&linebuf); } /* @@ -709,37 +680,36 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, */ static void _sendto_channel_local_with_capability_butone(struct Client *one, int type, int caps, int negcaps, struct Channel *chptr, - const char *pattern, va_list * args) + const char *pattern, va_list * args) { - buf_head_t linebuf; - struct membership *msptr; - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - - rb_linebuf_newbuf(&linebuf); - rb_linebuf_putmsg(&linebuf, pattern, args, NULL); - - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) - { - msptr = ptr->data; - target_p = msptr->client_p; - - if (target_p == one) - continue; - - if(IsIOError(target_p) || - !IsCapable(target_p, caps) || - !NotCapable(target_p, negcaps)) - continue; - - if(type && ((msptr->flags & type) == 0)) - continue; - - _send_linebuf(target_p, &linebuf); - } - - rb_linebuf_donebuf(&linebuf); + buf_head_t linebuf; + struct membership *msptr; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + + rb_linebuf_newbuf(&linebuf); + rb_linebuf_putmsg(&linebuf, pattern, args, NULL); + + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) { + msptr = ptr->data; + target_p = msptr->client_p; + + if (target_p == one) + continue; + + if(IsIOError(target_p) || + !IsCapable(target_p, caps) || + !NotCapable(target_p, negcaps)) + continue; + + if(type && ((msptr->flags & type) == 0)) + continue; + + _send_linebuf(target_p, &linebuf); + } + + rb_linebuf_donebuf(&linebuf); } /* sendto_channel_local_with_capability() @@ -751,11 +721,11 @@ _sendto_channel_local_with_capability_butone(struct Client *one, int type, int c void sendto_channel_local_with_capability(int type, int caps, int negcaps, struct Channel *chptr, const char *pattern, ...) { - va_list args; - - va_start(args, pattern); - _sendto_channel_local_with_capability_butone(NULL, type, caps, negcaps, chptr, pattern, &args); - va_end(args); + va_list args; + + va_start(args, pattern); + _sendto_channel_local_with_capability_butone(NULL, type, caps, negcaps, chptr, pattern, &args); + va_end(args); } @@ -767,13 +737,13 @@ sendto_channel_local_with_capability(int type, int caps, int negcaps, struct Cha */ void sendto_channel_local_with_capability_butone(struct Client *one, int type, int caps, int negcaps, struct Channel *chptr, - const char *pattern, ...) + const char *pattern, ...) { - va_list args; - - va_start(args, pattern); - _sendto_channel_local_with_capability_butone(one, type, caps, negcaps, chptr, pattern, &args); - va_end(args); + va_list args; + + va_start(args, pattern); + _sendto_channel_local_with_capability_butone(one, type, caps, negcaps, chptr, pattern, &args); + va_end(args); } /* @@ -784,57 +754,55 @@ sendto_channel_local_with_capability_butone(struct Client *one, int type, int ca * - capability mask * output - NONE * side effects - Sends a message to all people on local server who are - * in same channel with user. + * in same channel with user. * used by m_nick.c and exit_one_client. */ void sendto_common_channels_local(struct Client *user, int cap, const char *pattern, ...) { - va_list args; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - rb_dlink_node *uptr; - rb_dlink_node *next_uptr; - struct Channel *chptr; - struct Client *target_p; - struct membership *msptr; - struct membership *mscptr; - buf_head_t linebuf; + va_list args; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + rb_dlink_node *uptr; + rb_dlink_node *next_uptr; + struct Channel *chptr; + struct Client *target_p; + struct membership *msptr; + struct membership *mscptr; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); - va_end(args); + rb_linebuf_newbuf(&linebuf); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); - ++current_serial; + ++current_serial; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) - { - mscptr = ptr->data; - chptr = mscptr->chptr; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) { + mscptr = ptr->data; + chptr = mscptr->chptr; - RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) - { - msptr = uptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) { + msptr = uptr->data; + target_p = msptr->client_p; - if(IsIOError(target_p) || - target_p->serial == current_serial || + if(IsIOError(target_p) || + target_p->serial == current_serial || !IsCapable(target_p, cap)) - continue; + continue; - target_p->serial = current_serial; - send_linebuf(target_p, &linebuf); - } - } + target_p->serial = current_serial; + send_linebuf(target_p, &linebuf); + } + } - /* this can happen when the user isnt in any channels, but we still - * need to send them the data, ie a nick change - */ - if(MyConnect(user) && (user->serial != current_serial)) - send_linebuf(user, &linebuf); + /* this can happen when the user isnt in any channels, but we still + * need to send them the data, ie a nick change + */ + if(MyConnect(user) && (user->serial != current_serial)) + send_linebuf(user, &linebuf); - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } /* @@ -850,47 +818,45 @@ sendto_common_channels_local(struct Client *user, int cap, const char *pattern, void sendto_common_channels_local_butone(struct Client *user, int cap, const char *pattern, ...) { - va_list args; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - rb_dlink_node *uptr; - rb_dlink_node *next_uptr; - struct Channel *chptr; - struct Client *target_p; - struct membership *msptr; - struct membership *mscptr; - buf_head_t linebuf; + va_list args; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + rb_dlink_node *uptr; + rb_dlink_node *next_uptr; + struct Channel *chptr; + struct Client *target_p; + struct membership *msptr; + struct membership *mscptr; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); - va_end(args); + rb_linebuf_newbuf(&linebuf); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); - ++current_serial; - /* Skip them -- jilles */ - user->serial = current_serial; + ++current_serial; + /* Skip them -- jilles */ + user->serial = current_serial; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) - { - mscptr = ptr->data; - chptr = mscptr->chptr; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) { + mscptr = ptr->data; + chptr = mscptr->chptr; - RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) - { - msptr = uptr->data; - target_p = msptr->client_p; + RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) { + msptr = uptr->data; + target_p = msptr->client_p; - if(IsIOError(target_p) || - target_p->serial == current_serial || + if(IsIOError(target_p) || + target_p->serial == current_serial || !IsCapable(target_p, cap)) - continue; + continue; - target_p->serial = current_serial; - send_linebuf(target_p, &linebuf); - } - } + target_p->serial = current_serial; + send_linebuf(target_p, &linebuf); + } + } - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } /* sendto_match_butone() @@ -901,127 +867,120 @@ sendto_common_channels_local_butone(struct Client *user, int cap, const char *pa */ void sendto_match_butone(struct Client *one, struct Client *source_p, - const char *mask, int what, const char *pattern, ...) + const char *mask, int what, const char *pattern, ...) { - static char buf[BUFSIZE]; - va_list args; - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - buf_head_t rb_linebuf_local; - buf_head_t rb_linebuf_id; + static char buf[BUFSIZE]; + va_list args; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + buf_head_t rb_linebuf_local; + buf_head_t rb_linebuf_id; - rb_linebuf_newbuf(&rb_linebuf_local); - rb_linebuf_newbuf(&rb_linebuf_id); + rb_linebuf_newbuf(&rb_linebuf_local); + rb_linebuf_newbuf(&rb_linebuf_id); - va_start(args, pattern); - rb_vsnprintf(buf, sizeof(buf), pattern, args); - va_end(args); + va_start(args, pattern); + rb_vsnprintf(buf, sizeof(buf), pattern, args); + va_end(args); - if(IsServer(source_p)) - rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, - ":%s %s", source_p->name, buf); - else - rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, - ":%s!%s@%s %s", - source_p->name, source_p->username, - source_p->host, buf); + if(IsServer(source_p)) + rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, + ":%s %s", source_p->name, buf); + else + rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, + ":%s!%s@%s %s", + source_p->name, source_p->username, + source_p->host, buf); - rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); + rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); - if(what == MATCH_HOST) - { - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) - { - target_p = ptr->data; + if(what == MATCH_HOST) { + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { + target_p = ptr->data; - if(match(mask, target_p->host)) - _send_linebuf(target_p, &rb_linebuf_local); - } - } - /* what = MATCH_SERVER, if it doesnt match us, just send remote */ - else if(match(mask, me.name)) - { - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) - { - target_p = ptr->data; - _send_linebuf(target_p, &rb_linebuf_local); - } - } + if(match(mask, target_p->host)) + _send_linebuf(target_p, &rb_linebuf_local); + } + } + /* what = MATCH_SERVER, if it doesnt match us, just send remote */ + else if(match(mask, me.name)) { + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { + target_p = ptr->data; + _send_linebuf(target_p, &rb_linebuf_local); + } + } - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; - if(target_p == one) - continue; + if(target_p == one) + continue; - send_linebuf_remote(target_p, source_p, &rb_linebuf_id); - } + send_linebuf_remote(target_p, source_p, &rb_linebuf_id); + } - rb_linebuf_donebuf(&rb_linebuf_local); - rb_linebuf_donebuf(&rb_linebuf_id); + rb_linebuf_donebuf(&rb_linebuf_local); + rb_linebuf_donebuf(&rb_linebuf_id); } /* sendto_match_servs() * * inputs - source, mask to send to, caps needed, va_args - * outputs - + * outputs - * side effects - message is sent to matching servers with caps. */ void -sendto_match_servs(struct Client *source_p, const char *mask, int cap, - int nocap, const char *pattern, ...) +sendto_match_servs(struct Client *source_p, const char *mask, int cap, + int nocap, const char *pattern, ...) { - static char buf[BUFSIZE]; - va_list args; - rb_dlink_node *ptr; - struct Client *target_p; - buf_head_t rb_linebuf_id; + static char buf[BUFSIZE]; + va_list args; + rb_dlink_node *ptr; + struct Client *target_p; + buf_head_t rb_linebuf_id; - if(EmptyString(mask)) - return; + if(EmptyString(mask)) + return; - rb_linebuf_newbuf(&rb_linebuf_id); + rb_linebuf_newbuf(&rb_linebuf_id); - va_start(args, pattern); - rb_vsnprintf(buf, sizeof(buf), pattern, args); - va_end(args); + va_start(args, pattern); + rb_vsnprintf(buf, sizeof(buf), pattern, args); + va_end(args); - rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, - ":%s %s", use_id(source_p), buf); + rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, + ":%s %s", use_id(source_p), buf); - current_serial++; + current_serial++; - RB_DLINK_FOREACH(ptr, global_serv_list.head) - { - target_p = ptr->data; + RB_DLINK_FOREACH(ptr, global_serv_list.head) { + target_p = ptr->data; - /* dont send to ourselves, or back to where it came from.. */ - if(IsMe(target_p) || target_p->from == source_p->from) - continue; + /* dont send to ourselves, or back to where it came from.. */ + if(IsMe(target_p) || target_p->from == source_p->from) + continue; - if(target_p->from->serial == current_serial) - continue; + if(target_p->from->serial == current_serial) + continue; - if(match(mask, target_p->name)) - { - /* if we set the serial here, then we'll never do - * a match() again if !IsCapable() - */ - target_p->from->serial = current_serial; + if(match(mask, target_p->name)) { + /* if we set the serial here, then we'll never do + * a match() again if !IsCapable() + */ + target_p->from->serial = current_serial; - if(cap && !IsCapable(target_p->from, cap)) - continue; + if(cap && !IsCapable(target_p->from, cap)) + continue; - if(nocap && !NotCapable(target_p->from, nocap)) - continue; + if(nocap && !NotCapable(target_p->from, nocap)) + continue; - _send_linebuf(target_p->from, &rb_linebuf_id); - } - } + _send_linebuf(target_p->from, &rb_linebuf_id); + } + } - rb_linebuf_donebuf(&rb_linebuf_id); + rb_linebuf_donebuf(&rb_linebuf_id); } /* sendto_monitor() @@ -1033,29 +992,28 @@ sendto_match_servs(struct Client *source_p, const char *mask, int cap, void sendto_monitor(struct monitor *monptr, const char *pattern, ...) { - va_list args; - buf_head_t linebuf; - struct Client *target_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - - rb_linebuf_newbuf(&linebuf); - - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); - va_end(args); + va_list args; + buf_head_t linebuf; + struct Client *target_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head) - { - target_p = ptr->data; + rb_linebuf_newbuf(&linebuf); - if(IsIOError(target_p)) - continue; + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); + va_end(args); - _send_linebuf(target_p, &linebuf); - } + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head) { + target_p = ptr->data; - rb_linebuf_donebuf(&linebuf); + if(IsIOError(target_p)) + continue; + + _send_linebuf(target_p, &linebuf); + } + + rb_linebuf_donebuf(&linebuf); } /* sendto_anywhere() @@ -1065,41 +1023,39 @@ sendto_monitor(struct monitor *monptr, const char *pattern, ...) * side effects - client is sent message with correct prefix. */ void -sendto_anywhere(struct Client *target_p, struct Client *source_p, - const char *command, const char *pattern, ...) +sendto_anywhere(struct Client *target_p, struct Client *source_p, + const char *command, const char *pattern, ...) { - va_list args; - buf_head_t linebuf; + va_list args; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); + rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); + va_start(args, pattern); - if(MyClient(target_p)) - { - if(IsServer(source_p)) - rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", - source_p->name, command, - target_p->name); - else - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s!%s@%s %s %s ", - source_p->name, source_p->username, - source_p->host, command, - target_p->name); - } - else - rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", - get_id(source_p, target_p), command, - get_id(target_p, target_p)); - va_end(args); + if(MyClient(target_p)) { + if(IsServer(source_p)) + rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", + source_p->name, command, + target_p->name); + else + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s!%s@%s %s %s ", + source_p->name, source_p->username, + source_p->host, command, + target_p->name); + } else + rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", + get_id(source_p, target_p), command, + get_id(target_p, target_p)); + va_end(args); - if(MyClient(target_p)) - _send_linebuf(target_p, &linebuf); - else - send_linebuf_remote(target_p, source_p, &linebuf); + if(MyClient(target_p)) + _send_linebuf(target_p, &linebuf); + else + send_linebuf_remote(target_p, source_p, &linebuf); - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } /* sendto_realops_snomask() @@ -1111,67 +1067,61 @@ sendto_anywhere(struct Client *target_p, struct Client *source_p, void sendto_realops_snomask(int flags, int level, const char *pattern, ...) { - static char buf[BUFSIZE]; - char *snobuf; - struct Client *client_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - va_list args; - buf_head_t linebuf; + static char buf[BUFSIZE]; + char *snobuf; + struct Client *client_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + va_list args; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); + rb_linebuf_newbuf(&linebuf); - /* Be very sure not to do things like "Trying to send to myself" - * L_NETWIDE, otherwise infinite recursion may result! -- jilles */ - if (level & L_NETWIDE && ConfigFileEntry.global_snotices) - { - /* rather a lot of copying around, oh well -- jilles */ - va_start(args, pattern); - rb_vsnprintf(buf, sizeof(buf), pattern, args); - va_end(args); - rb_linebuf_putmsg(&linebuf, pattern, NULL, - ":%s NOTICE * :*** Notice -- %s", me.name, buf); - snobuf = construct_snobuf(flags); - if (snobuf[1] != '\0') - sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS, - ":%s ENCAP * SNOTE %c :%s", - me.id, snobuf[1], buf); - } - else if (remote_rehash_oper_p != NULL) - { - /* rather a lot of copying around, oh well -- jilles */ - va_start(args, pattern); - rb_vsnprintf(buf, sizeof(buf), pattern, args); - va_end(args); - rb_linebuf_putmsg(&linebuf, pattern, NULL, - ":%s NOTICE * :*** Notice -- %s", me.name, buf); - sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf); - } - else - { - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s NOTICE * :*** Notice -- ", me.name); - va_end(args); - } - level &= ~L_NETWIDE; + /* Be very sure not to do things like "Trying to send to myself" + * L_NETWIDE, otherwise infinite recursion may result! -- jilles */ + if (level & L_NETWIDE && ConfigFileEntry.global_snotices) { + /* rather a lot of copying around, oh well -- jilles */ + va_start(args, pattern); + rb_vsnprintf(buf, sizeof(buf), pattern, args); + va_end(args); + rb_linebuf_putmsg(&linebuf, pattern, NULL, + ":%s NOTICE * :*** Notice -- %s", me.name, buf); + snobuf = construct_snobuf(flags); + if (snobuf[1] != '\0') + sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS, + ":%s ENCAP * SNOTE %c :%s", + me.id, snobuf[1], buf); + } else if (remote_rehash_oper_p != NULL) { + /* rather a lot of copying around, oh well -- jilles */ + va_start(args, pattern); + rb_vsnprintf(buf, sizeof(buf), pattern, args); + va_end(args); + rb_linebuf_putmsg(&linebuf, pattern, NULL, + ":%s NOTICE * :*** Notice -- %s", me.name, buf); + sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf); + } else { + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s NOTICE * :*** Notice -- ", me.name); + va_end(args); + } + level &= ~L_NETWIDE; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) { + client_p = ptr->data; - /* If we're sending it to opers and theyre an admin, skip. - * If we're sending it to admins, and theyre not, skip. - */ - if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || - ((level == L_OPER) && IsOperAdmin(client_p))) - continue; + /* If we're sending it to opers and theyre an admin, skip. + * If we're sending it to admins, and theyre not, skip. + */ + if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || + ((level == L_OPER) && IsOperAdmin(client_p))) + continue; - if(client_p->snomask & flags) - _send_linebuf(client_p, &linebuf); - } + if(client_p->snomask & flags) + _send_linebuf(client_p, &linebuf); + } - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } /* sendto_realops_snomask_from() * @@ -1181,37 +1131,36 @@ sendto_realops_snomask(int flags, int level, const char *pattern, ...) */ void sendto_realops_snomask_from(int flags, int level, struct Client *source_p, - const char *pattern, ...) + const char *pattern, ...) { - struct Client *client_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - va_list args; - buf_head_t linebuf; + struct Client *client_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + va_list args; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); + rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s NOTICE * :*** Notice -- ", source_p->name); - va_end(args); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s NOTICE * :*** Notice -- ", source_p->name); + va_end(args); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) { + client_p = ptr->data; - /* If we're sending it to opers and theyre an admin, skip. - * If we're sending it to admins, and theyre not, skip. - */ - if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || - ((level == L_OPER) && IsOperAdmin(client_p))) - continue; + /* If we're sending it to opers and theyre an admin, skip. + * If we're sending it to admins, and theyre not, skip. + */ + if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || + ((level == L_OPER) && IsOperAdmin(client_p))) + continue; - if(client_p->snomask & flags) - _send_linebuf(client_p, &linebuf); - } + if(client_p->snomask & flags) + _send_linebuf(client_p, &linebuf); + } - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } /* @@ -1226,34 +1175,33 @@ sendto_realops_snomask_from(int flags, int level, struct Client *source_p, void sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...) { - struct Client *client_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - va_list args; - buf_head_t linebuf; + struct Client *client_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + va_list args; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); + rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); + va_start(args, pattern); - if(IsPerson(source_p)) - rb_linebuf_putmsg(&linebuf, pattern, &args, - ":%s!%s@%s WALLOPS :", source_p->name, - source_p->username, source_p->host); - else - rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name); + if(IsPerson(source_p)) + rb_linebuf_putmsg(&linebuf, pattern, &args, + ":%s!%s@%s WALLOPS :", source_p->name, + source_p->username, source_p->host); + else + rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name); - va_end(args); + va_end(args); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head) - { - client_p = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head) { + client_p = ptr->data; - if(client_p->umodes & flags) - _send_linebuf(client_p, &linebuf); - } + if(client_p->umodes & flags) + _send_linebuf(client_p, &linebuf); + } - rb_linebuf_donebuf(&linebuf); + rb_linebuf_donebuf(&linebuf); } /* kill_client() @@ -1265,18 +1213,18 @@ sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, .. void kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...) { - va_list args; - buf_head_t linebuf; + va_list args; + buf_head_t linebuf; - rb_linebuf_newbuf(&linebuf); + rb_linebuf_newbuf(&linebuf); - va_start(args, pattern); - rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :", - get_id(&me, target_p), get_id(diedie, target_p)); - va_end(args); + va_start(args, pattern); + rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :", + get_id(&me, target_p), get_id(diedie, target_p)); + va_end(args); - send_linebuf(target_p, &linebuf); - rb_linebuf_donebuf(&linebuf); + send_linebuf(target_p, &linebuf); + rb_linebuf_donebuf(&linebuf); } @@ -1294,35 +1242,34 @@ kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, void kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...) { - static char buf[BUFSIZE]; - va_list args; - struct Client *client_p; - rb_dlink_node *ptr; - rb_dlink_node *next_ptr; - buf_head_t rb_linebuf_id; + static char buf[BUFSIZE]; + va_list args; + struct Client *client_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + buf_head_t rb_linebuf_id; - rb_linebuf_newbuf(&rb_linebuf_id); - - va_start(args, pattern); - rb_vsnprintf(buf, sizeof(buf), pattern, args); - va_end(args); + rb_linebuf_newbuf(&rb_linebuf_id); - rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s", - use_id(&me), use_id(target_p), buf); + va_start(args, pattern); + rb_vsnprintf(buf, sizeof(buf), pattern, args); + va_end(args); - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) - { - client_p = ptr->data; + rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s", + use_id(&me), use_id(target_p), buf); - /* ok, if the client we're supposed to not send to has an - * ID, then we still want to issue the kill there.. - */ - if(one != NULL && (client_p == one->from) && - (!has_id(client_p) || !has_id(target_p))) - continue; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) { + client_p = ptr->data; - _send_linebuf(client_p, &rb_linebuf_id); - } + /* ok, if the client we're supposed to not send to has an + * ID, then we still want to issue the kill there.. + */ + if(one != NULL && (client_p == one->from) && + (!has_id(client_p) || !has_id(target_p))) + continue; - rb_linebuf_donebuf(&rb_linebuf_id); + _send_linebuf(client_p, &rb_linebuf_id); + } + + rb_linebuf_donebuf(&rb_linebuf_id); } diff --git a/src/snomask.c b/src/snomask.c index f010f83..af4e37b 100644 --- a/src/snomask.c +++ b/src/snomask.c @@ -39,73 +39,73 @@ /* *INDENT-OFF* */ int snomask_modes[256] = { - /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */ - /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */ - /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */ - /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */ - 0, /* @ */ - 0, /* A */ - 0, /* B */ - SNO_CCONNEXT, /* C */ - 0, /* D */ - 0, /* E */ - 0, /* F */ - 0, /* G */ - 0, /* H */ - 0, /* I */ - 0, /* J */ - 0, /* K */ - 0, /* L */ - 0, /* M */ - 0, /* N */ - 0, /* O */ - 0, /* P */ - 0, /* Q */ - 0, /* R */ - SNO_SASLFAIL, /* S */ - 0, /* T */ - 0, /* U */ - 0, /* V */ - 0, /* W */ - 0, /* X */ - 0, /* Y */ - SNO_OPERSPY, /* Z */ - /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */ - 0, /* a */ - SNO_BOTS, /* b */ - SNO_CCONN, /* c */ - SNO_DEBUG, /* d */ - 0, /* e */ - SNO_FULL, /* f */ - 0, /* g */ - 0, /* h */ - 0, /* i */ - 0, /* j */ - SNO_SKILL, /* k */ - 0, /* l */ - 0, /* m */ - SNO_NCHANGE, /* n */ - 0, /* o */ - 0, /* p */ - 0, /* q */ - SNO_REJ, /* r */ - SNO_GENERAL, /* s */ - 0, /* t */ - SNO_UNAUTH, /* u */ - 0, /* v */ - 0, /* w */ - SNO_EXTERNAL, /* x */ - SNO_SPY, /* y */ - 0, /* z */ - /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */ - /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ - /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ - /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */ - /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */ - /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */ - /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */ - /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */ - /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */ + /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */ + /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */ + /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */ + /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */ + 0, /* @ */ + 0, /* A */ + 0, /* B */ + SNO_CCONNEXT, /* C */ + 0, /* D */ + 0, /* E */ + 0, /* F */ + 0, /* G */ + 0, /* H */ + 0, /* I */ + 0, /* J */ + 0, /* K */ + 0, /* L */ + 0, /* M */ + 0, /* N */ + 0, /* O */ + 0, /* P */ + 0, /* Q */ + 0, /* R */ + SNO_SASLFAIL, /* S */ + 0, /* T */ + 0, /* U */ + 0, /* V */ + 0, /* W */ + 0, /* X */ + 0, /* Y */ + SNO_OPERSPY, /* Z */ + /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */ + 0, /* a */ + SNO_BOTS, /* b */ + SNO_CCONN, /* c */ + SNO_DEBUG, /* d */ + 0, /* e */ + SNO_FULL, /* f */ + 0, /* g */ + 0, /* h */ + 0, /* i */ + 0, /* j */ + SNO_SKILL, /* k */ + 0, /* l */ + 0, /* m */ + SNO_NCHANGE, /* n */ + 0, /* o */ + 0, /* p */ + 0, /* q */ + SNO_REJ, /* r */ + SNO_GENERAL, /* s */ + 0, /* t */ + SNO_UNAUTH, /* u */ + 0, /* v */ + 0, /* w */ + SNO_EXTERNAL, /* x */ + SNO_SPY, /* y */ + 0, /* z */ + /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */ + /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ + /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */ + /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */ + /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */ + /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */ + /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */ + /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */ + /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */ }; /* *INDENT-ON* */ @@ -121,19 +121,19 @@ static char snobuf[BUFSIZE]; char * construct_snobuf(unsigned int val) { - int i; - char *ptr = snobuf; + int i; + char *ptr = snobuf; - *ptr = '\0'; - *ptr++ = '+'; + *ptr = '\0'; + *ptr++ = '+'; - for (i = 0; i < 128; i++) - if (snomask_modes[i] && (val & snomask_modes[i])) - *ptr++ = (char) i; + for (i = 0; i < 128; i++) + if (snomask_modes[i] && (val & snomask_modes[i])) + *ptr++ = (char) i; - *ptr++ = '\0'; + *ptr++ = '\0'; - return snobuf; + return snobuf; } /* @@ -146,33 +146,31 @@ construct_snobuf(unsigned int val) unsigned int parse_snobuf_to_mask(unsigned int val, const char *sno) { - const char *p; - int what = SNO_ADD; + const char *p; + int what = SNO_ADD; - if (sno == NULL) - return val; + if (sno == NULL) + return val; - for (p = sno; *p != '\0'; p++) - { - switch(*p) - { - case '+': - what = SNO_ADD; - break; - case '-': - what = SNO_DEL; - break; - default: - if (what == SNO_ADD) - val |= snomask_modes[(unsigned char) *p]; - else if (what == SNO_DEL) - val &= ~snomask_modes[(unsigned char) *p]; + for (p = sno; *p != '\0'; p++) { + switch(*p) { + case '+': + what = SNO_ADD; + break; + case '-': + what = SNO_DEL; + break; + default: + if (what == SNO_ADD) + val |= snomask_modes[(unsigned char) *p]; + else if (what == SNO_DEL) + val &= ~snomask_modes[(unsigned char) *p]; - break; - } - } + break; + } + } - return val; + return val; } /* @@ -186,14 +184,14 @@ parse_snobuf_to_mask(unsigned int val, const char *sno) unsigned int find_snomask_slot(void) { - unsigned int all_umodes = 0, my_umode = 0, i; + unsigned int all_umodes = 0, my_umode = 0, i; - for (i = 0; i < 128; i++) - all_umodes |= snomask_modes[i]; + for (i = 0; i < 128; i++) + all_umodes |= snomask_modes[i]; - for (my_umode = 1; my_umode && (all_umodes & my_umode); - my_umode <<= 1); + for (my_umode = 1; my_umode && (all_umodes & my_umode); + my_umode <<= 1); - return my_umode; + return my_umode; } diff --git a/src/sslproc.c b/src/sslproc.c index 11fadbb..527681e 100644 --- a/src/sslproc.c +++ b/src/sslproc.c @@ -47,30 +47,28 @@ static char nul = '\0'; #define MAXPASSFD 4 #define READSIZE 1024 -typedef struct _ssl_ctl_buf -{ - rb_dlink_node node; - char *buf; - size_t buflen; - rb_fde_t *F[MAXPASSFD]; - int nfds; +typedef struct _ssl_ctl_buf { + rb_dlink_node node; + char *buf; + size_t buflen; + rb_fde_t *F[MAXPASSFD]; + int nfds; } ssl_ctl_buf_t; -struct _ssl_ctl -{ - rb_dlink_node node; - int cli_count; - rb_fde_t *F; - rb_fde_t *P; - pid_t pid; - rb_dlink_list readq; - rb_dlink_list writeq; - uint8_t dead; +struct _ssl_ctl { + rb_dlink_node node; + int cli_count; + rb_fde_t *F; + rb_fde_t *P; + pid_t pid; + rb_dlink_list readq; + rb_dlink_list writeq; + uint8_t dead; }; static void send_new_ssl_certs_one(ssl_ctl_t * ctl, const char *ssl_cert, - const char *ssl_private_key, const char *ssl_dh_params); + const char *ssl_private_key, const char *ssl_dh_params); static void send_init_prng(ssl_ctl_t * ctl, prng_seed_t seedtype, const char *path); @@ -79,83 +77,81 @@ static rb_dlink_list ssl_daemons; static inline int32_t buf_to_int32(char *buf) { - int32_t x; - memcpy(&x, buf, sizeof(x)); - return x; + int32_t x; + memcpy(&x, buf, sizeof(x)); + return x; } static inline void int32_to_buf(char *buf, int32_t x) { - memcpy(buf, &x, sizeof(x)); - return; + memcpy(buf, &x, sizeof(x)); + return; } static inline uint16_t buf_to_uint16(char *buf) { - uint16_t x; - memcpy(&x, buf, sizeof(x)); - return x; + uint16_t x; + memcpy(&x, buf, sizeof(x)); + return x; } static inline void uint16_to_buf(char *buf, uint16_t x) { - memcpy(buf, &x, sizeof(x)); - return; + memcpy(buf, &x, sizeof(x)); + return; } static ssl_ctl_t * allocate_ssl_daemon(rb_fde_t * F, rb_fde_t * P, int pid) { - ssl_ctl_t *ctl; + ssl_ctl_t *ctl; - if(F == NULL || pid < 0) - return NULL; - ctl = rb_malloc(sizeof(ssl_ctl_t)); - ctl->F = F; - ctl->P = P; - ctl->pid = pid; - ssld_count++; - rb_dlinkAdd(ctl, &ctl->node, &ssl_daemons); - return ctl; + if(F == NULL || pid < 0) + return NULL; + ctl = rb_malloc(sizeof(ssl_ctl_t)); + ctl->F = F; + ctl->P = P; + ctl->pid = pid; + ssld_count++; + rb_dlinkAdd(ctl, &ctl->node, &ssl_daemons); + return ctl; } static void free_ssl_daemon(ssl_ctl_t * ctl) { - rb_dlink_node *ptr; - ssl_ctl_buf_t *ctl_buf; - int x; - if(ctl->cli_count) - return; + rb_dlink_node *ptr; + ssl_ctl_buf_t *ctl_buf; + int x; + if(ctl->cli_count) + return; - RB_DLINK_FOREACH(ptr, ctl->readq.head) - { - ctl_buf = ptr->data; - for(x = 0; x < ctl_buf->nfds; x++) - rb_close(ctl_buf->F[x]); + RB_DLINK_FOREACH(ptr, ctl->readq.head) { + ctl_buf = ptr->data; + for(x = 0; x < ctl_buf->nfds; x++) + rb_close(ctl_buf->F[x]); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + } - RB_DLINK_FOREACH(ptr, ctl->writeq.head) - { - ctl_buf = ptr->data; - for(x = 0; x < ctl_buf->nfds; x++) - rb_close(ctl_buf->F[x]); + RB_DLINK_FOREACH(ptr, ctl->writeq.head) { + ctl_buf = ptr->data; + for(x = 0; x < ctl_buf->nfds; x++) + rb_close(ctl_buf->F[x]); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } - rb_close(ctl->F); - rb_close(ctl->P); - rb_dlinkDelete(&ctl->node, &ssl_daemons); - rb_free(ctl); + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + } + rb_close(ctl->F); + rb_close(ctl->P); + rb_dlinkDelete(&ctl->node, &ssl_daemons); + rb_free(ctl); } static char *ssld_path; @@ -168,314 +164,298 @@ static int ssld_wait = 0; static void ssl_killall(void) { - rb_dlink_node *ptr, *next; - ssl_ctl_t *ctl; - RB_DLINK_FOREACH_SAFE(ptr, next, ssl_daemons.head) - { - ctl = ptr->data; - if(ctl->dead) - continue; - ctl->dead = 1; - ssld_count--; - rb_kill(ctl->pid, SIGKILL); - } + rb_dlink_node *ptr, *next; + ssl_ctl_t *ctl; + RB_DLINK_FOREACH_SAFE(ptr, next, ssl_daemons.head) { + ctl = ptr->data; + if(ctl->dead) + continue; + ctl->dead = 1; + ssld_count--; + rb_kill(ctl->pid, SIGKILL); + } } static void ssl_dead(ssl_ctl_t * ctl) { - if(ctl->dead) - return; + if(ctl->dead) + return; - ctl->dead = 1; - ssld_count--; - rb_kill(ctl->pid, SIGKILL); /* make sure the process is really gone */ - ilog(L_MAIN, "ssld helper died - attempting to restart"); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld helper died - attempting to restart"); - start_ssldaemon(1, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); + ctl->dead = 1; + ssld_count--; + rb_kill(ctl->pid, SIGKILL); /* make sure the process is really gone */ + ilog(L_MAIN, "ssld helper died - attempting to restart"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld helper died - attempting to restart"); + start_ssldaemon(1, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); } static void ssl_do_pipe(rb_fde_t * F, void *data) { - int retlen; - ssl_ctl_t *ctl = data; - retlen = rb_write(F, "0", 1); - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - ssl_dead(ctl); - return; - } - rb_setselect(F, RB_SELECT_READ, ssl_do_pipe, data); + int retlen; + ssl_ctl_t *ctl = data; + retlen = rb_write(F, "0", 1); + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + ssl_dead(ctl); + return; + } + rb_setselect(F, RB_SELECT_READ, ssl_do_pipe, data); } static void restart_ssld_event(void *unused) { - ssld_spin_count = 0; - last_spin = 0; - ssld_wait = 0; - if(ServerInfo.ssld_count > get_ssld_count()) - { - int start = ServerInfo.ssld_count - get_ssld_count(); - ilog(L_MAIN, "Attempting to restart ssld processes"); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Attempt to restart ssld processes"); - start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); - } + ssld_spin_count = 0; + last_spin = 0; + ssld_wait = 0; + if(ServerInfo.ssld_count > get_ssld_count()) { + int start = ServerInfo.ssld_count - get_ssld_count(); + ilog(L_MAIN, "Attempting to restart ssld processes"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Attempt to restart ssld processes"); + start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); + } } int start_ssldaemon(int count, const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params) { - rb_fde_t *F1, *F2; - rb_fde_t *P1, *P2; + rb_fde_t *F1, *F2; + rb_fde_t *P1, *P2; #ifdef _WIN32 - const char *suffix = ".exe"; + const char *suffix = ".exe"; #else - const char *suffix = ""; + const char *suffix = ""; #endif - char fullpath[PATH_MAX + 1]; - char fdarg[6]; - const char *parv[2]; - char buf[128]; - char s_pid[10]; - pid_t pid; - int started = 0, i; + char fullpath[PATH_MAX + 1]; + char fdarg[6]; + const char *parv[2]; + char buf[128]; + char s_pid[10]; + pid_t pid; + int started = 0, i; - if(ssld_wait) - return 0; + if(ssld_wait) + return 0; - if(ssld_spin_count > 20 && (rb_current_time() - last_spin < 5)) - { - ilog(L_MAIN, "ssld helper is spinning - will attempt to restart in 1 minute"); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "ssld helper is spinning - will attempt to restart in 1 minute"); - rb_event_add("restart_ssld_event", restart_ssld_event, NULL, 60); - ssld_wait = 1; - return 0; - } + if(ssld_spin_count > 20 && (rb_current_time() - last_spin < 5)) { + ilog(L_MAIN, "ssld helper is spinning - will attempt to restart in 1 minute"); + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "ssld helper is spinning - will attempt to restart in 1 minute"); + rb_event_add("restart_ssld_event", restart_ssld_event, NULL, 60); + ssld_wait = 1; + return 0; + } - ssld_spin_count++; - last_spin = rb_current_time(); + ssld_spin_count++; + last_spin = rb_current_time(); - if(ssld_path == NULL) - { - rb_snprintf(fullpath, sizeof(fullpath), "%s/ssld%s", PKGLIBEXECDIR, suffix); + if(ssld_path == NULL) { + rb_snprintf(fullpath, sizeof(fullpath), "%s/ssld%s", PKGLIBEXECDIR, suffix); - if(access(fullpath, X_OK) == -1) - { - rb_snprintf(fullpath, sizeof(fullpath), "%s/bin/ssld%s", - ConfigFileEntry.dpath, suffix); - if(access(fullpath, X_OK) == -1) - { - ilog(L_MAIN, - "Unable to execute ssld%s in %s or %s/bin", - suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath); - return 0; - } - } - ssld_path = rb_strdup(fullpath); - } - rb_strlcpy(buf, "-ircd ssld daemon helper", sizeof(buf)); - parv[0] = buf; - parv[1] = NULL; + if(access(fullpath, X_OK) == -1) { + rb_snprintf(fullpath, sizeof(fullpath), "%s/bin/ssld%s", + ConfigFileEntry.dpath, suffix); + if(access(fullpath, X_OK) == -1) { + ilog(L_MAIN, + "Unable to execute ssld%s in %s or %s/bin", + suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath); + return 0; + } + } + ssld_path = rb_strdup(fullpath); + } + rb_strlcpy(buf, "-ircd ssld daemon helper", sizeof(buf)); + parv[0] = buf; + parv[1] = NULL; - for(i = 0; i < count; i++) - { - ssl_ctl_t *ctl; - if(rb_socketpair(AF_UNIX, SOCK_DGRAM, 0, &F1, &F2, "SSL/TLS handle passing socket") == -1) - { - ilog(L_MAIN, "Unable to create ssld - rb_socketpair failed: %s", strerror(errno)); - return started; - } - - rb_set_buffers(F1, READBUF_SIZE); - rb_set_buffers(F2, READBUF_SIZE); - rb_snprintf(fdarg, sizeof(fdarg), "%d", rb_get_fd(F2)); - rb_setenv("CTL_FD", fdarg, 1); - if(rb_pipe(&P1, &P2, "SSL/TLS pipe") == -1) - { - ilog(L_MAIN, "Unable to create ssld - rb_pipe failed: %s", strerror(errno)); - return started; - } - rb_snprintf(fdarg, sizeof(fdarg), "%d", rb_get_fd(P1)); - rb_setenv("CTL_PIPE", fdarg, 1); - rb_snprintf(s_pid, sizeof(s_pid), "%d", (int)getpid()); - rb_setenv("CTL_PPID", s_pid, 1); + for(i = 0; i < count; i++) { + ssl_ctl_t *ctl; + if(rb_socketpair(AF_UNIX, SOCK_DGRAM, 0, &F1, &F2, "SSL/TLS handle passing socket") == -1) { + ilog(L_MAIN, "Unable to create ssld - rb_socketpair failed: %s", strerror(errno)); + return started; + } + + rb_set_buffers(F1, READBUF_SIZE); + rb_set_buffers(F2, READBUF_SIZE); + rb_snprintf(fdarg, sizeof(fdarg), "%d", rb_get_fd(F2)); + rb_setenv("CTL_FD", fdarg, 1); + if(rb_pipe(&P1, &P2, "SSL/TLS pipe") == -1) { + ilog(L_MAIN, "Unable to create ssld - rb_pipe failed: %s", strerror(errno)); + return started; + } + rb_snprintf(fdarg, sizeof(fdarg), "%d", rb_get_fd(P1)); + rb_setenv("CTL_PIPE", fdarg, 1); + rb_snprintf(s_pid, sizeof(s_pid), "%d", (int)getpid()); + rb_setenv("CTL_PPID", s_pid, 1); #ifdef _WIN32 - SetHandleInformation((HANDLE) rb_get_fd(F2), HANDLE_FLAG_INHERIT, 1); - SetHandleInformation((HANDLE) rb_get_fd(P1), HANDLE_FLAG_INHERIT, 1); + SetHandleInformation((HANDLE) rb_get_fd(F2), HANDLE_FLAG_INHERIT, 1); + SetHandleInformation((HANDLE) rb_get_fd(P1), HANDLE_FLAG_INHERIT, 1); #endif - pid = rb_spawn_process(ssld_path, (const char **) parv); - if(pid == -1) - { - ilog(L_MAIN, "Unable to create ssld: %s\n", strerror(errno)); - rb_close(F1); - rb_close(F2); - rb_close(P1); - rb_close(P2); - return started; - } - started++; - rb_close(F2); - rb_close(P1); - ctl = allocate_ssl_daemon(F1, P2, pid); - if(ssl_ok) - { - if(ConfigFileEntry.use_egd && (ConfigFileEntry.egdpool_path != NULL)) - send_init_prng(ctl, RB_PRNG_EGD, ConfigFileEntry.egdpool_path); - else - send_init_prng(ctl, RB_PRNG_DEFAULT, NULL); - } - if(ssl_ok && ssl_cert != NULL && ssl_private_key != NULL) - send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, - ssl_dh_params != NULL ? ssl_dh_params : ""); - ssl_read_ctl(ctl->F, ctl); - ssl_do_pipe(P2, ctl); + pid = rb_spawn_process(ssld_path, (const char **) parv); + if(pid == -1) { + ilog(L_MAIN, "Unable to create ssld: %s\n", strerror(errno)); + rb_close(F1); + rb_close(F2); + rb_close(P1); + rb_close(P2); + return started; + } + started++; + rb_close(F2); + rb_close(P1); + ctl = allocate_ssl_daemon(F1, P2, pid); + if(ssl_ok) { + if(ConfigFileEntry.use_egd && (ConfigFileEntry.egdpool_path != NULL)) + send_init_prng(ctl, RB_PRNG_EGD, ConfigFileEntry.egdpool_path); + else + send_init_prng(ctl, RB_PRNG_DEFAULT, NULL); + } + if(ssl_ok && ssl_cert != NULL && ssl_private_key != NULL) + send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, + ssl_dh_params != NULL ? ssl_dh_params : ""); + ssl_read_ctl(ctl->F, ctl); + ssl_do_pipe(P2, ctl); - } - return started; + } + return started; } static void ssl_process_zipstats(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf) { - struct Client *server; - struct ZipStats *zips; - int parc; - char *parv[7]; - parc = rb_string_to_array(ctl_buf->buf, parv, 6); - server = find_server(NULL, parv[1]); - if(server == NULL || server->localClient == NULL || !IsCapable(server, CAP_ZIP)) - return; - if(server->localClient->zipstats == NULL) - server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats)); + struct Client *server; + struct ZipStats *zips; + int parc; + char *parv[7]; + parc = rb_string_to_array(ctl_buf->buf, parv, 6); + server = find_server(NULL, parv[1]); + if(server == NULL || server->localClient == NULL || !IsCapable(server, CAP_ZIP)) + return; + if(server->localClient->zipstats == NULL) + server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats)); - zips = server->localClient->zipstats; + zips = server->localClient->zipstats; - zips->in += strtoull(parv[2], NULL, 10); - zips->in_wire += strtoull(parv[3], NULL, 10); - zips->out += strtoull(parv[4], NULL, 10); - zips->out_wire += strtoull(parv[5], NULL, 10); + zips->in += strtoull(parv[2], NULL, 10); + zips->in_wire += strtoull(parv[3], NULL, 10); + zips->out += strtoull(parv[4], NULL, 10); + zips->out_wire += strtoull(parv[5], NULL, 10); - if(zips->in > 0) - zips->in_ratio = ((double) (zips->in - zips->in_wire) / (double) zips->in) * 100.00; - else - zips->in_ratio = 0; + if(zips->in > 0) + zips->in_ratio = ((double) (zips->in - zips->in_wire) / (double) zips->in) * 100.00; + else + zips->in_ratio = 0; - if(zips->out > 0) - zips->out_ratio = ((double) (zips->out - zips->out_wire) / (double) zips->out) * 100.00; - else - zips->out_ratio = 0; + if(zips->out > 0) + zips->out_ratio = ((double) (zips->out - zips->out_wire) / (double) zips->out) * 100.00; + else + zips->out_ratio = 0; } static void ssl_process_dead_fd(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf) { - struct Client *client_p; - char reason[256]; - int32_t fd; + struct Client *client_p; + char reason[256]; + int32_t fd; - if(ctl_buf->buflen < 6) - return; /* bogus message..drop it.. XXX should warn here */ + if(ctl_buf->buflen < 6) + return; /* bogus message..drop it.. XXX should warn here */ - fd = buf_to_int32(&ctl_buf->buf[1]); - rb_strlcpy(reason, &ctl_buf->buf[5], sizeof(reason)); - client_p = find_cli_fd_hash(fd); - if(client_p == NULL) - return; - if(IsAnyServer(client_p) || IsRegistered(client_p)) - { - /* read any last moment ERROR, QUIT or the like -- jilles */ - if (!strcmp(reason, "Remote host closed the connection")) - read_packet(client_p->localClient->F, client_p); - if (IsAnyDead(client_p)) - return; - } - if(IsAnyServer(client_p)) - { - sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, "ssld error for %s: %s", client_p->name, reason); - ilog(L_SERVER, "ssld error for %s: %s", log_client_name(client_p, SHOW_IP), reason); - } - exit_client(client_p, client_p, &me, reason); + fd = buf_to_int32(&ctl_buf->buf[1]); + rb_strlcpy(reason, &ctl_buf->buf[5], sizeof(reason)); + client_p = find_cli_fd_hash(fd); + if(client_p == NULL) + return; + if(IsAnyServer(client_p) || IsRegistered(client_p)) { + /* read any last moment ERROR, QUIT or the like -- jilles */ + if (!strcmp(reason, "Remote host closed the connection")) + read_packet(client_p->localClient->F, client_p); + if (IsAnyDead(client_p)) + return; + } + if(IsAnyServer(client_p)) { + sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, "ssld error for %s: %s", client_p->name, reason); + ilog(L_SERVER, "ssld error for %s: %s", log_client_name(client_p, SHOW_IP), reason); + } + exit_client(client_p, client_p, &me, reason); } static void ssl_process_certfp(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf) { - struct Client *client_p; - int32_t fd; - uint8_t *certfp; - char *certfp_string; - int i; + struct Client *client_p; + int32_t fd; + uint8_t *certfp; + char *certfp_string; + int i; - if(ctl_buf->buflen != 5 + RB_SSL_CERTFP_LEN) - return; /* bogus message..drop it.. XXX should warn here */ + if(ctl_buf->buflen != 5 + RB_SSL_CERTFP_LEN) + return; /* bogus message..drop it.. XXX should warn here */ - fd = buf_to_int32(&ctl_buf->buf[1]); - certfp = (uint8_t *)&ctl_buf->buf[5]; - client_p = find_cli_fd_hash(fd); - if(client_p == NULL) - return; - rb_free(client_p->certfp); - certfp_string = rb_malloc(RB_SSL_CERTFP_LEN * 2 + 1); - for(i = 0; i < RB_SSL_CERTFP_LEN; i++) - rb_snprintf(certfp_string + 2 * i, 3, "%02x", - certfp[i]); - client_p->certfp = certfp_string; + fd = buf_to_int32(&ctl_buf->buf[1]); + certfp = (uint8_t *)&ctl_buf->buf[5]; + client_p = find_cli_fd_hash(fd); + if(client_p == NULL) + return; + rb_free(client_p->certfp); + certfp_string = rb_malloc(RB_SSL_CERTFP_LEN * 2 + 1); + for(i = 0; i < RB_SSL_CERTFP_LEN; i++) + rb_snprintf(certfp_string + 2 * i, 3, "%02x", + certfp[i]); + client_p->certfp = certfp_string; } static void ssl_process_cmd_recv(ssl_ctl_t * ctl) { - static const char *cannot_setup_ssl = "ssld cannot setup ssl, check your certificates and private key"; - static const char *no_ssl_or_zlib = "ssld has neither SSL/TLS or zlib support killing all sslds"; - rb_dlink_node *ptr, *next; - ssl_ctl_buf_t *ctl_buf; - if(ctl->dead) - return; - RB_DLINK_FOREACH_SAFE(ptr, next, ctl->readq.head) - { - ctl_buf = ptr->data; - switch (*ctl_buf->buf) - { - case 'N': - ssl_ok = 0; /* ssld says it can't do ssl/tls */ - break; - case 'D': - ssl_process_dead_fd(ctl, ctl_buf); - break; - case 'F': - ssl_process_certfp(ctl, ctl_buf); - break; - case 'S': - ssl_process_zipstats(ctl, ctl_buf); - break; - case 'I': - ssl_ok = 0; - ilog(L_MAIN, cannot_setup_ssl); - sendto_realops_snomask(SNO_GENERAL, L_ALL, cannot_setup_ssl); - case 'U': - zlib_ok = 0; - ssl_ok = 0; - ilog(L_MAIN, no_ssl_or_zlib); - sendto_realops_snomask(SNO_GENERAL, L_ALL, no_ssl_or_zlib); - ssl_killall(); - break; - case 'z': - zlib_ok = 0; - break; - default: - ilog(L_MAIN, "Received invalid command from ssld: %s", ctl_buf->buf); - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Received invalid command from ssld"); - break; - } - rb_dlinkDelete(ptr, &ctl->readq); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } + static const char *cannot_setup_ssl = "ssld cannot setup ssl, check your certificates and private key"; + static const char *no_ssl_or_zlib = "ssld has neither SSL/TLS or zlib support killing all sslds"; + rb_dlink_node *ptr, *next; + ssl_ctl_buf_t *ctl_buf; + if(ctl->dead) + return; + RB_DLINK_FOREACH_SAFE(ptr, next, ctl->readq.head) { + ctl_buf = ptr->data; + switch (*ctl_buf->buf) { + case 'N': + ssl_ok = 0; /* ssld says it can't do ssl/tls */ + break; + case 'D': + ssl_process_dead_fd(ctl, ctl_buf); + break; + case 'F': + ssl_process_certfp(ctl, ctl_buf); + break; + case 'S': + ssl_process_zipstats(ctl, ctl_buf); + break; + case 'I': + ssl_ok = 0; + ilog(L_MAIN, cannot_setup_ssl); + sendto_realops_snomask(SNO_GENERAL, L_ALL, cannot_setup_ssl); + case 'U': + zlib_ok = 0; + ssl_ok = 0; + ilog(L_MAIN, no_ssl_or_zlib); + sendto_realops_snomask(SNO_GENERAL, L_ALL, no_ssl_or_zlib); + ssl_killall(); + break; + case 'z': + zlib_ok = 0; + break; + default: + ilog(L_MAIN, "Received invalid command from ssld: %s", ctl_buf->buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Received invalid command from ssld"); + break; + } + rb_dlinkDelete(ptr, &ctl->readq); + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + } } @@ -483,239 +463,221 @@ ssl_process_cmd_recv(ssl_ctl_t * ctl) static void ssl_read_ctl(rb_fde_t * F, void *data) { - ssl_ctl_buf_t *ctl_buf; - ssl_ctl_t *ctl = data; - int retlen; + ssl_ctl_buf_t *ctl_buf; + ssl_ctl_t *ctl = data; + int retlen; - if(ctl->dead) - return; - do - { - ctl_buf = rb_malloc(sizeof(ssl_ctl_buf_t)); - ctl_buf->buf = rb_malloc(READSIZE); - retlen = rb_recv_fd_buf(ctl->F, ctl_buf->buf, READSIZE, ctl_buf->F, 4); - ctl_buf->buflen = retlen; - if(retlen <= 0) - { - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } - else - rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq); - } - while(retlen > 0); + if(ctl->dead) + return; + do { + ctl_buf = rb_malloc(sizeof(ssl_ctl_buf_t)); + ctl_buf->buf = rb_malloc(READSIZE); + retlen = rb_recv_fd_buf(ctl->F, ctl_buf->buf, READSIZE, ctl_buf->F, 4); + ctl_buf->buflen = retlen; + if(retlen <= 0) { + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + } else + rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq); + } while(retlen > 0); - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - ssl_dead(ctl); - return; - } - ssl_process_cmd_recv(ctl); - rb_setselect(ctl->F, RB_SELECT_READ, ssl_read_ctl, ctl); + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + ssl_dead(ctl); + return; + } + ssl_process_cmd_recv(ctl); + rb_setselect(ctl->F, RB_SELECT_READ, ssl_read_ctl, ctl); } static ssl_ctl_t * which_ssld(void) { - ssl_ctl_t *ctl, *lowest = NULL; - rb_dlink_node *ptr; + ssl_ctl_t *ctl, *lowest = NULL; + rb_dlink_node *ptr; - RB_DLINK_FOREACH(ptr, ssl_daemons.head) - { - ctl = ptr->data; - if(ctl->dead) - continue; - if(lowest == NULL) - { - lowest = ctl; - continue; - } - if(ctl->cli_count < lowest->cli_count) - lowest = ctl; - } - return (lowest); + RB_DLINK_FOREACH(ptr, ssl_daemons.head) { + ctl = ptr->data; + if(ctl->dead) + continue; + if(lowest == NULL) { + lowest = ctl; + continue; + } + if(ctl->cli_count < lowest->cli_count) + lowest = ctl; + } + return (lowest); } static void ssl_write_ctl(rb_fde_t * F, void *data) { - ssl_ctl_t *ctl = data; - ssl_ctl_buf_t *ctl_buf; - rb_dlink_node *ptr, *next; - int retlen, x; + ssl_ctl_t *ctl = data; + ssl_ctl_buf_t *ctl_buf; + rb_dlink_node *ptr, *next; + int retlen, x; - if(ctl->dead) - return; + if(ctl->dead) + return; - RB_DLINK_FOREACH_SAFE(ptr, next, ctl->writeq.head) - { - ctl_buf = ptr->data; - /* in theory unix sock_dgram shouldn't ever short write this.. */ - retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, ctl_buf->buflen, ctl->pid); - 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); + RB_DLINK_FOREACH_SAFE(ptr, next, ctl->writeq.head) { + ctl_buf = ptr->data; + /* in theory unix sock_dgram shouldn't ever short write this.. */ + retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, ctl_buf->buflen, ctl->pid); + 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))) - { - ssl_dead(ctl); - return; - } - else - { - rb_setselect(ctl->F, RB_SELECT_WRITE, ssl_write_ctl, ctl); - } - } + } + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + ssl_dead(ctl); + return; + } else { + rb_setselect(ctl->F, RB_SELECT_WRITE, ssl_write_ctl, ctl); + } + } } static void ssl_cmd_write_queue(ssl_ctl_t * ctl, rb_fde_t ** F, int count, const void *buf, size_t buflen) { - ssl_ctl_buf_t *ctl_buf; - int x; + ssl_ctl_buf_t *ctl_buf; + int x; - /* don't bother */ - if(ctl->dead) - return; + /* don't bother */ + if(ctl->dead) + return; - ctl_buf = rb_malloc(sizeof(ssl_ctl_buf_t)); - ctl_buf->buf = rb_malloc(buflen); - memcpy(ctl_buf->buf, buf, buflen); - ctl_buf->buflen = buflen; + ctl_buf = rb_malloc(sizeof(ssl_ctl_buf_t)); + ctl_buf->buf = rb_malloc(buflen); + memcpy(ctl_buf->buf, buf, buflen); + ctl_buf->buflen = buflen; - for(x = 0; x < count && x < MAXPASSFD; x++) - { - ctl_buf->F[x] = F[x]; - } - ctl_buf->nfds = count; - rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->writeq); - ssl_write_ctl(ctl->F, ctl); + for(x = 0; x < count && x < MAXPASSFD; x++) { + ctl_buf->F[x] = F[x]; + } + ctl_buf->nfds = count; + rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->writeq); + ssl_write_ctl(ctl->F, ctl); } static void send_new_ssl_certs_one(ssl_ctl_t * ctl, const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params) { - size_t len; + size_t len; - len = strlen(ssl_cert) + strlen(ssl_private_key) + strlen(ssl_dh_params) + 5; - if(len > sizeof(tmpbuf)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...", - len, sizeof(tmpbuf)); - ilog(L_MAIN, - "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...", - len, sizeof(tmpbuf)); - return; - } - len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "K%c%s%c%s%c%s%c", nul, ssl_cert, nul, - ssl_private_key, nul, ssl_dh_params, nul); - ssl_cmd_write_queue(ctl, NULL, 0, tmpbuf, len); + len = strlen(ssl_cert) + strlen(ssl_private_key) + strlen(ssl_dh_params) + 5; + if(len > sizeof(tmpbuf)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...", + len, sizeof(tmpbuf)); + ilog(L_MAIN, + "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...", + len, sizeof(tmpbuf)); + return; + } + len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "K%c%s%c%s%c%s%c", nul, ssl_cert, nul, + ssl_private_key, nul, ssl_dh_params, nul); + ssl_cmd_write_queue(ctl, NULL, 0, tmpbuf, len); } static void send_init_prng(ssl_ctl_t * ctl, prng_seed_t seedtype, const char *path) { - size_t len; - const char *s; - uint8_t seed = (uint8_t) seedtype; + size_t len; + const char *s; + uint8_t seed = (uint8_t) seedtype; - if(path == NULL) - s = ""; - else - s = path; + if(path == NULL) + s = ""; + else + s = path; - len = strlen(s) + 3; - if(len > sizeof(tmpbuf)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...", - len, sizeof(tmpbuf)); - ilog(L_MAIN, - "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...", - len, sizeof(tmpbuf)); - return; + len = strlen(s) + 3; + if(len > sizeof(tmpbuf)) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...", + len, sizeof(tmpbuf)); + ilog(L_MAIN, + "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...", + len, sizeof(tmpbuf)); + return; - } - len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "I%c%s%c", seed, s, nul); - ssl_cmd_write_queue(ctl, NULL, 0, tmpbuf, len); + } + len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "I%c%s%c", seed, s, nul); + ssl_cmd_write_queue(ctl, NULL, 0, tmpbuf, len); } void send_new_ssl_certs(const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params) { - rb_dlink_node *ptr; - if(ssl_cert == NULL || ssl_private_key == NULL || ssl_dh_params == NULL) - { - ssl_ok = 0; - return; - } - RB_DLINK_FOREACH(ptr, ssl_daemons.head) - { - ssl_ctl_t *ctl = ptr->data; - send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, ssl_dh_params); - } + rb_dlink_node *ptr; + if(ssl_cert == NULL || ssl_private_key == NULL || ssl_dh_params == NULL) { + ssl_ok = 0; + return; + } + RB_DLINK_FOREACH(ptr, ssl_daemons.head) { + ssl_ctl_t *ctl = ptr->data; + send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, ssl_dh_params); + } } ssl_ctl_t * start_ssld_accept(rb_fde_t * sslF, rb_fde_t * plainF, int32_t id) { - rb_fde_t *F[2]; - ssl_ctl_t *ctl; - char buf[5]; - F[0] = sslF; - F[1] = plainF; + rb_fde_t *F[2]; + ssl_ctl_t *ctl; + char buf[5]; + F[0] = sslF; + F[1] = plainF; - buf[0] = 'A'; - int32_to_buf(&buf[1], id); - ctl = which_ssld(); - ctl->cli_count++; - ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf)); - return ctl; + buf[0] = 'A'; + int32_to_buf(&buf[1], id); + ctl = which_ssld(); + ctl->cli_count++; + ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf)); + return ctl; } ssl_ctl_t * start_ssld_connect(rb_fde_t * sslF, rb_fde_t * plainF, int32_t id) { - rb_fde_t *F[2]; - ssl_ctl_t *ctl; - char buf[5]; - F[0] = sslF; - F[1] = plainF; + rb_fde_t *F[2]; + ssl_ctl_t *ctl; + char buf[5]; + F[0] = sslF; + F[1] = plainF; - buf[0] = 'C'; - int32_to_buf(&buf[1], id); + buf[0] = 'C'; + int32_to_buf(&buf[1], id); - ctl = which_ssld(); - ctl->cli_count++; - ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf)); - return ctl; + ctl = which_ssld(); + ctl->cli_count++; + ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf)); + return ctl; } void ssld_decrement_clicount(ssl_ctl_t * ctl) { - if(ctl == NULL) - return; + if(ctl == NULL) + return; - ctl->cli_count--; - if(ctl->dead && !ctl->cli_count) - { - free_ssl_daemon(ctl); - } + ctl->cli_count--; + if(ctl->dead && !ctl->cli_count) { + free_ssl_daemon(ctl); + } } -/* +/* * what we end up sending to the ssld process for ziplinks is the following - * Z[ourfd][level][RECVQ] - * Z = ziplinks command = buf[0] + * Z[ourfd][level][RECVQ] + * Z = ziplinks command = buf[0] * ourfd = Our end of the socketpair = buf[1..4] * level = zip level buf[5] * recvqlen = our recvq len = buf[6-7] @@ -724,144 +686,135 @@ ssld_decrement_clicount(ssl_ctl_t * ctl) void start_zlib_session(void *data) { - struct Client *server = (struct Client *) data; - uint16_t recvqlen; - uint8_t level; - void *xbuf; + struct Client *server = (struct Client *) data; + uint16_t recvqlen; + uint8_t level; + void *xbuf; - rb_fde_t *F[2]; - rb_fde_t *xF1, *xF2; - char *buf; - char buf2[9]; - void *recvq_start; + 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(int32_t); - size_t len; - int cpylen, left; + size_t hdr = (sizeof(uint8_t) * 2) + sizeof(int32_t); + size_t len; + int cpylen, left; - server->localClient->event = NULL; + server->localClient->event = NULL; - recvqlen = rb_linebuf_len(&server->localClient->buf_recvq); + recvqlen = rb_linebuf_len(&server->localClient->buf_recvq); - len = recvqlen + hdr; + len = recvqlen + hdr; - if(len > READBUF_SIZE) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "ssld - attempted to pass message of %zd len, max len %d, giving up", - len, READBUF_SIZE); - ilog(L_MAIN, "ssld - attempted to pass message of %zd len, max len %d, giving up", len, READBUF_SIZE); - exit_client(server, server, server, "ssld readbuf exceeded"); - return; - } + if(len > READBUF_SIZE) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "ssld - attempted to pass message of %zd len, max len %d, giving up", + len, READBUF_SIZE); + ilog(L_MAIN, "ssld - attempted to pass message of %zd len, max len %d, giving up", len, READBUF_SIZE); + exit_client(server, server, server, "ssld readbuf exceeded"); + return; + } - buf = rb_malloc(len); - level = ConfigFileEntry.compression_level; + buf = rb_malloc(len); + level = ConfigFileEntry.compression_level; - int32_to_buf(&buf[1], rb_get_fd(server->localClient->F)); - buf[5] = (char) level; + int32_to_buf(&buf[1], rb_get_fd(server->localClient->F)); + buf[5] = (char) level; - recvq_start = &buf[6]; - server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats)); + recvq_start = &buf[6]; + server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats)); - xbuf = recvq_start; - left = recvqlen; + xbuf = recvq_start; + left = recvqlen; - do - { - cpylen = rb_linebuf_get(&server->localClient->buf_recvq, xbuf, left, LINEBUF_PARTIAL, LINEBUF_RAW); - left -= cpylen; - xbuf = (void *) (((uintptr_t) xbuf) + cpylen); - } - while(cpylen > 0); + do { + cpylen = rb_linebuf_get(&server->localClient->buf_recvq, xbuf, left, LINEBUF_PARTIAL, LINEBUF_RAW); + left -= cpylen; + xbuf = (void *) (((uintptr_t) xbuf) + cpylen); + } while(cpylen > 0); - /* Pass the socket to ssld. */ - *buf = 'Z'; - if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF1, &xF2, "Initial zlib socketpairs") == -1) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "Error creating zlib socketpair - %s", strerror(errno)); - ilog(L_MAIN, "Error creating zlib socketpairs - %s", strerror(errno)); - exit_client(server, server, server, "Error creating zlib socketpair"); - return; - } - - if(IsSSL(server)) - { - /* tell ssld the new connid for the ssl part*/ - buf2[0] = 'Y'; - int32_to_buf(&buf2[1], rb_get_fd(server->localClient->F)); - int32_to_buf(&buf2[5], rb_get_fd(xF2)); - ssl_cmd_write_queue(server->localClient->ssl_ctl, NULL, 0, buf2, sizeof(buf2)); - } + /* Pass the socket to ssld. */ + *buf = 'Z'; + if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF1, &xF2, "Initial zlib socketpairs") == -1) { + sendto_realops_snomask(SNO_GENERAL, L_ALL, "Error creating zlib socketpair - %s", strerror(errno)); + ilog(L_MAIN, "Error creating zlib socketpairs - %s", strerror(errno)); + exit_client(server, server, server, "Error creating zlib socketpair"); + return; + } + + if(IsSSL(server)) { + /* tell ssld the new connid for the ssl part*/ + buf2[0] = 'Y'; + int32_to_buf(&buf2[1], rb_get_fd(server->localClient->F)); + int32_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_cli_fd_hash(server); - server->localClient->F = xF2; - /* need to redo as what we did before isn't valid now */ - int32_to_buf(&buf[1], rb_get_fd(server->localClient->F)); - add_to_cli_fd_hash(server); + F[0] = server->localClient->F; + F[1] = xF1; + del_from_cli_fd_hash(server); + server->localClient->F = xF2; + /* need to redo as what we did before isn't valid now */ + int32_to_buf(&buf[1], rb_get_fd(server->localClient->F)); + add_to_cli_fd_hash(server); - server->localClient->z_ctl = which_ssld(); - server->localClient->z_ctl->cli_count++; - ssl_cmd_write_queue(server->localClient->z_ctl, F, 2, buf, len); - rb_free(buf); + server->localClient->z_ctl = which_ssld(); + server->localClient->z_ctl->cli_count++; + ssl_cmd_write_queue(server->localClient->z_ctl, F, 2, buf, len); + rb_free(buf); } static void collect_zipstats(void *unused) { - rb_dlink_node *ptr; - struct Client *target_p; - char buf[sizeof(uint8_t) + sizeof(int32_t) + HOSTLEN]; - void *odata; - size_t len; - int32_t id; + rb_dlink_node *ptr; + struct Client *target_p; + char buf[sizeof(uint8_t) + sizeof(int32_t) + HOSTLEN]; + void *odata; + size_t len; + int32_t id; - buf[0] = 'S'; - odata = buf + sizeof(uint8_t) + sizeof(int32_t); + buf[0] = 'S'; + odata = buf + sizeof(uint8_t) + sizeof(int32_t); - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; - if(IsCapable(target_p, CAP_ZIP)) - { - len = sizeof(uint8_t) + sizeof(uint32_t); + RB_DLINK_FOREACH(ptr, serv_list.head) { + target_p = ptr->data; + if(IsCapable(target_p, CAP_ZIP)) { + len = sizeof(uint8_t) + sizeof(uint32_t); - id = rb_get_fd(target_p->localClient->F); - int32_to_buf(&buf[1], rb_get_fd(target_p->localClient->F)); - rb_strlcpy(odata, target_p->name, (sizeof(buf) - len)); - len += strlen(odata) + 1; /* Get the \0 as well */ - ssl_cmd_write_queue(target_p->localClient->z_ctl, NULL, 0, buf, len); - } - } + id = rb_get_fd(target_p->localClient->F); + int32_to_buf(&buf[1], rb_get_fd(target_p->localClient->F)); + rb_strlcpy(odata, target_p->name, (sizeof(buf) - len)); + len += strlen(odata) + 1; /* Get the \0 as well */ + ssl_cmd_write_queue(target_p->localClient->z_ctl, NULL, 0, buf, len); + } + } } static void cleanup_dead_ssl(void *unused) { - rb_dlink_node *ptr, *next; - ssl_ctl_t *ctl; - RB_DLINK_FOREACH_SAFE(ptr, next, ssl_daemons.head) - { - ctl = ptr->data; - if(ctl->dead && !ctl->cli_count) - { - free_ssl_daemon(ctl); - } - } + rb_dlink_node *ptr, *next; + ssl_ctl_t *ctl; + RB_DLINK_FOREACH_SAFE(ptr, next, ssl_daemons.head) { + ctl = ptr->data; + if(ctl->dead && !ctl->cli_count) { + free_ssl_daemon(ctl); + } + } } int get_ssld_count(void) { - return ssld_count; + return ssld_count; } void init_ssld(void) { - rb_event_addish("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); - rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl, NULL, 1200); + rb_event_addish("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); + rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl, NULL, 1200); } diff --git a/src/substitution.c b/src/substitution.c index 708dce2..223d71c 100644 --- a/src/substitution.c +++ b/src/substitution.c @@ -44,10 +44,9 @@ * Everything is a string, so typing doesn't really matter too * horribly much right now. */ -struct substitution_variable -{ - char *name; - char *value; +struct substitution_variable { + char *name; + char *value; }; /* @@ -59,12 +58,12 @@ struct substitution_variable */ void substitution_append_var(rb_dlink_list *varlist, const char *name, const char *value) { - struct substitution_variable *tmp = rb_malloc(sizeof(struct substitution_variable)); + struct substitution_variable *tmp = rb_malloc(sizeof(struct substitution_variable)); - tmp->name = rb_strdup(name); - tmp->value = rb_strdup(value); + tmp->name = rb_strdup(name); + tmp->value = rb_strdup(value); - rb_dlinkAddAlloc(tmp, varlist); + rb_dlinkAddAlloc(tmp, varlist); } /* @@ -76,17 +75,16 @@ void substitution_append_var(rb_dlink_list *varlist, const char *name, const cha */ void substitution_free(rb_dlink_list *varlist) { - rb_dlink_node *nptr, *nptr2; + rb_dlink_node *nptr, *nptr2; - RB_DLINK_FOREACH_SAFE(nptr, nptr2, varlist->head) - { - struct substitution_variable *tmp = (struct substitution_variable *) nptr->data; + RB_DLINK_FOREACH_SAFE(nptr, nptr2, varlist->head) { + struct substitution_variable *tmp = (struct substitution_variable *) nptr->data; - rb_dlinkDelete(nptr, varlist); - rb_free(tmp->name); - rb_free(tmp->value); - rb_free(tmp); - } + rb_dlinkDelete(nptr, varlist); + rb_free(tmp->name); + rb_free(tmp->value); + rb_free(tmp); + } } /* @@ -98,53 +96,48 @@ void substitution_free(rb_dlink_list *varlist) */ char *substitution_parse(const char *fmt, rb_dlink_list *varlist) { - static char buf[BUFSIZE]; - const char *ptr; - char *bptr = buf; + static char buf[BUFSIZE]; + const char *ptr; + char *bptr = buf; - for (ptr = fmt; *ptr != '\0' && bptr - buf < BUFSIZE; ptr++) - if (*ptr != '$') - *bptr++ = *ptr; - else if (*(ptr + 1) == '{') - { - static char varname[BUFSIZE]; - char *vptr = varname; - const char *pptr; - rb_dlink_node *nptr; + for (ptr = fmt; *ptr != '\0' && bptr - buf < BUFSIZE; ptr++) + if (*ptr != '$') + *bptr++ = *ptr; + else if (*(ptr + 1) == '{') { + static char varname[BUFSIZE]; + char *vptr = varname; + const char *pptr; + rb_dlink_node *nptr; - *vptr = '\0'; + *vptr = '\0'; - /* break out ${var} */ - for (pptr = ptr + 2; *pptr != '\0'; pptr++) - { - if (*pptr != '}') - *vptr++ = *pptr; - else - { - *vptr++ = '\0'; - break; - } - } + /* break out ${var} */ + for (pptr = ptr + 2; *pptr != '\0'; pptr++) { + if (*pptr != '}') + *vptr++ = *pptr; + else { + *vptr++ = '\0'; + break; + } + } - s_assert(*varname != '\0'); - s_assert(*pptr != '\0'); + s_assert(*varname != '\0'); + s_assert(*pptr != '\0'); - /* advance ptr by length of variable */ - ptr += (pptr - ptr); + /* advance ptr by length of variable */ + ptr += (pptr - ptr); - RB_DLINK_FOREACH(nptr, varlist->head) - { - struct substitution_variable *val = (struct substitution_variable *) nptr->data; + RB_DLINK_FOREACH(nptr, varlist->head) { + struct substitution_variable *val = (struct substitution_variable *) nptr->data; - if (!strcasecmp(varname, val->name)) - { - rb_strlcpy(bptr, val->value, BUFSIZE - (bptr - buf)); - bptr += strlen(val->value); - break; - } - } - } + if (!strcasecmp(varname, val->name)) { + rb_strlcpy(bptr, val->value, BUFSIZE - (bptr - buf)); + bptr += strlen(val->value); + break; + } + } + } - *bptr = '\0'; - return buf; + *bptr = '\0'; + return buf; } diff --git a/src/supported.c b/src/supported.c index 7036fe8..270786c 100644 --- a/src/supported.c +++ b/src/supported.c @@ -82,275 +82,267 @@ rb_dlink_list isupportlist; -struct isupportitem -{ - const char *name; - const char *(*func)(const void *); - const void *param; - rb_dlink_node node; +struct isupportitem { + const char *name; + const char *(*func)(const void *); + const void *param; + rb_dlink_node node; }; void add_isupport(const char *name, const char *(*func)(const void *), const void *param) { - struct isupportitem *item; + struct isupportitem *item; - item = rb_malloc(sizeof(struct isupportitem)); - item->name = name; - item->func = func; - item->param = param; - rb_dlinkAddTail(item, &item->node, &isupportlist); + item = rb_malloc(sizeof(struct isupportitem)); + item->name = name; + item->func = func; + item->param = param; + rb_dlinkAddTail(item, &item->node, &isupportlist); } const void * change_isupport(const char *name, const char *(*func)(const void *), const void *param) { - rb_dlink_node *ptr; - struct isupportitem *item; - const void *oldvalue = NULL; + rb_dlink_node *ptr; + struct isupportitem *item; + const void *oldvalue = NULL; - RB_DLINK_FOREACH(ptr, isupportlist.head) - { - item = ptr->data; + RB_DLINK_FOREACH(ptr, isupportlist.head) { + item = ptr->data; - if (!strcmp(item->name, name)) - { - oldvalue = item->param; + if (!strcmp(item->name, name)) { + oldvalue = item->param; - // item->name = name; - item->func = func; - item->param = param; + // item->name = name; + item->func = func; + item->param = param; - break; - } - } + break; + } + } - return oldvalue; + return oldvalue; } void delete_isupport(const char *name) { - rb_dlink_node *ptr, *next_ptr; - struct isupportitem *item; + rb_dlink_node *ptr, *next_ptr; + struct isupportitem *item; - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head) - { - item = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head) { + item = ptr->data; - if (!strcmp(item->name, name)) - { - rb_dlinkDelete(ptr, &isupportlist); - rb_free(item); - } - } + if (!strcmp(item->name, name)) { + rb_dlinkDelete(ptr, &isupportlist); + rb_free(item); + } + } } /* XXX caching? */ void show_isupport(struct Client *client_p) { - rb_dlink_node *ptr; - struct isupportitem *item; - const char *value; - char buf[512]; - int extra_space; - unsigned int nchars, nparams; - int l; + rb_dlink_node *ptr; + struct isupportitem *item; + const char *value; + char buf[512]; + int extra_space; + unsigned int nchars, nparams; + int l; - extra_space = strlen(client_p->name); - /* UID */ - if (!MyClient(client_p) && extra_space < 9) - extra_space = 9; - /* : 005 :are supported by this server */ - /* form_str(RPL_ISUPPORT) is %s :are supported by this server */ - extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT)); + extra_space = strlen(client_p->name); + /* UID */ + if (!MyClient(client_p) && extra_space < 9) + extra_space = 9; + /* : 005 :are supported by this server */ + /* form_str(RPL_ISUPPORT) is %s :are supported by this server */ + extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT)); - nchars = extra_space, nparams = 0, buf[0] = '\0'; - RB_DLINK_FOREACH(ptr, isupportlist.head) - { - item = ptr->data; - value = (*item->func)(item->param); - if (value == NULL) - continue; - l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value)); - if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12) - { - sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); - nchars = extra_space, nparams = 0, buf[0] = '\0'; - } - if (nparams > 0) - rb_strlcat(buf, " ", sizeof buf), nchars++; - rb_strlcat(buf, item->name, sizeof buf); - if (!EmptyString(value)) - { - rb_strlcat(buf, "=", sizeof buf); - rb_strlcat(buf, value, sizeof buf); - } - nchars += l; - nparams++; - } - if (nparams > 0) - sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); + nchars = extra_space, nparams = 0, buf[0] = '\0'; + RB_DLINK_FOREACH(ptr, isupportlist.head) { + item = ptr->data; + value = (*item->func)(item->param); + if (value == NULL) + continue; + l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value)); + if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12) { + sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); + nchars = extra_space, nparams = 0, buf[0] = '\0'; + } + if (nparams > 0) + rb_strlcat(buf, " ", sizeof buf), nchars++; + rb_strlcat(buf, item->name, sizeof buf); + if (!EmptyString(value)) { + rb_strlcat(buf, "=", sizeof buf); + rb_strlcat(buf, value, sizeof buf); + } + nchars += l; + nparams++; + } + if (nparams > 0) + sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); } const char * isupport_intptr(const void *ptr) { - static char buf[15]; - rb_snprintf(buf, sizeof buf, "%d", *(const int *)ptr); - return buf; + static char buf[15]; + rb_snprintf(buf, sizeof buf, "%d", *(const int *)ptr); + return buf; } const char * isupport_boolean(const void *ptr) { - return *(const int *)ptr ? "" : NULL; + return *(const int *)ptr ? "" : NULL; } const char * isupport_string(const void *ptr) { - return (const char *)ptr; + return (const char *)ptr; } const char * isupport_stringptr(const void *ptr) { - return *(char * const *)ptr; + return *(char * const *)ptr; } static const char * isupport_chanmodes(const void *ptr) { - static char result[80]; + static char result[80]; - rb_snprintf(result, sizeof result, "%s%sb%s,k,%sl%s,%s", - ConfigChannel.use_except ? "e" : "", - ConfigChannel.use_invex ? "I" : "", - strchr(ConfigChannel.disabledmodes, 'q') ? "" : "q", - ConfigChannel.use_forward ? "f" : "", - strchr(ConfigChannel.disabledmodes, 'j') ? "" : "j", - cflagsbuf); - return result; + rb_snprintf(result, sizeof result, "%s%sb%s,k,%sl%s,%s", + ConfigChannel.use_except ? "e" : "", + ConfigChannel.use_invex ? "I" : "", + strchr(ConfigChannel.disabledmodes, 'q') ? "" : "q", + ConfigChannel.use_forward ? "f" : "", + strchr(ConfigChannel.disabledmodes, 'j') ? "" : "j", + cflagsbuf); + return result; } static const char * isupport_chantypes(const void *ptr) { - return ConfigChannel.use_local_channels ? "&#" : "#"; + return ConfigChannel.use_local_channels ? "&#" : "#"; } static const char * isupport_chanlimit(const void *ptr) { - static char result[30]; + static char result[30]; - rb_snprintf(result, sizeof result, "%s:%i", - ConfigChannel.use_local_channels ? "&#" : "#", - ConfigChannel.max_chans_per_user); - return result; + rb_snprintf(result, sizeof result, "%s:%i", + ConfigChannel.use_local_channels ? "&#" : "#", + ConfigChannel.max_chans_per_user); + return result; } static const char* isupport_prefix(const void *ptr) { - static char result[13]; + static char result[13]; - rb_snprintf(result, sizeof result, "(%s%so%sv)%s%s@%s+", - ConfigChannel.use_owner ? "y" : "", - ConfigChannel.use_admin ? "a" : "", - ConfigChannel.use_halfop ? "h" : "", - ConfigChannel.use_owner ? "~" : "", - ConfigChannel.use_admin ? "!" : "", - ConfigChannel.use_halfop ? "%" : ""); - return result; + rb_snprintf(result, sizeof result, "(%s%so%sv)%s%s@%s+", + ConfigChannel.use_owner ? "y" : "", + ConfigChannel.use_admin ? "a" : "", + ConfigChannel.use_halfop ? "h" : "", + ConfigChannel.use_owner ? "~" : "", + ConfigChannel.use_admin ? "!" : "", + ConfigChannel.use_halfop ? "%" : ""); + return result; } static const char * isupport_maxlist(const void *ptr) { - static char result[30]; + static char result[30]; - rb_snprintf(result, sizeof result, "bq%s%s:%i", - ConfigChannel.use_except ? "e" : "", - ConfigChannel.use_invex ? "I" : "", - ConfigChannel.max_bans); - return result; + rb_snprintf(result, sizeof result, "bq%s%s:%i", + ConfigChannel.use_except ? "e" : "", + ConfigChannel.use_invex ? "I" : "", + ConfigChannel.max_bans); + return result; } static const char * isupport_targmax(const void *ptr) { - static char result[200]; + static char result[200]; - rb_snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:", - ConfigFileEntry.max_targets, - ConfigFileEntry.max_targets); - return result; + rb_snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:", + ConfigFileEntry.max_targets, + ConfigFileEntry.max_targets); + return result; } static const char * isupport_extban(const void *ptr) { - const char *p; - static char result[200]; + const char *p; + static char result[200]; - p = get_extban_string(); - if (EmptyString(p)) - return NULL; - rb_snprintf(result, sizeof result, "$,%s", p); - return result; + p = get_extban_string(); + if (EmptyString(p)) + return NULL; + rb_snprintf(result, sizeof result, "$,%s", p); + return result; } static const char * isupport_ownermode(const void *ptr) { - static char result[200]; + static char result[200]; - if(!ConfigChannel.use_owner) - return NULL; + if(!ConfigChannel.use_owner) + return NULL; - rb_snprintf(result, sizeof result, "y"); + rb_snprintf(result, sizeof result, "y"); - return result; + return result; } void init_isupport(void) { - static int maxmodes = MAXMODEPARAMS; - static int nicklen = NICKLEN-1; - static int channellen = LOC_CHANNELLEN; - static int topiclen = TOPICLEN; + static int maxmodes = MAXMODEPARAMS; + static int nicklen = NICKLEN-1; + static int channellen = LOC_CHANNELLEN; + static int topiclen = TOPICLEN; - add_isupport("CHANTYPES", isupport_chantypes, NULL); - add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except); - add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex); - add_isupport("CHANMODES", isupport_chanmodes, NULL); - add_isupport("CHANLIMIT", isupport_chanlimit, NULL); - add_isupport("PREFIX", isupport_prefix, NULL); - add_isupport("OWNER", isupport_ownermode, NULL); - add_isupport("MAXLIST", isupport_maxlist, NULL); - add_isupport("MODES", isupport_intptr, &maxmodes); - add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name); - add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock); - add_isupport("STATUSMSG", isupport_string, "@+"); - add_isupport("CALLERID", isupport_string, "g"); - add_isupport("CASEMAPPING", isupport_string, "rfc1459"); - add_isupport("NICKLEN", isupport_intptr, &nicklen); - add_isupport("CHANNELLEN", isupport_intptr, &channellen); - add_isupport("TOPICLEN", isupport_intptr, &topiclen); - add_isupport("ETRACE", isupport_string, ""); - add_isupport("CPRIVMSG", isupport_string, ""); - add_isupport("CNOTICE", isupport_string, ""); - add_isupport("DEAF", isupport_string, "D"); - add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor); - add_isupport("FNC", isupport_string, ""); - add_isupport("TARGMAX", isupport_targmax, NULL); - add_isupport("EXTBAN", isupport_extban, NULL); - add_isupport("WHOX", isupport_string, ""); - add_isupport("CLIENTVER", isupport_string, "3.0"); + add_isupport("CHANTYPES", isupport_chantypes, NULL); + add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except); + add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex); + add_isupport("CHANMODES", isupport_chanmodes, NULL); + add_isupport("CHANLIMIT", isupport_chanlimit, NULL); + add_isupport("PREFIX", isupport_prefix, NULL); + add_isupport("OWNER", isupport_ownermode, NULL); + add_isupport("MAXLIST", isupport_maxlist, NULL); + add_isupport("MODES", isupport_intptr, &maxmodes); + add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name); + add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock); + add_isupport("STATUSMSG", isupport_string, "@+"); + add_isupport("CALLERID", isupport_string, "g"); + add_isupport("CASEMAPPING", isupport_string, "rfc1459"); + add_isupport("NICKLEN", isupport_intptr, &nicklen); + add_isupport("CHANNELLEN", isupport_intptr, &channellen); + add_isupport("TOPICLEN", isupport_intptr, &topiclen); + add_isupport("ETRACE", isupport_string, ""); + add_isupport("CPRIVMSG", isupport_string, ""); + add_isupport("CNOTICE", isupport_string, ""); + add_isupport("DEAF", isupport_string, "D"); + add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor); + add_isupport("FNC", isupport_string, ""); + add_isupport("TARGMAX", isupport_targmax, NULL); + add_isupport("EXTBAN", isupport_extban, NULL); + add_isupport("WHOX", isupport_string, ""); + add_isupport("CLIENTVER", isupport_string, "3.0"); } diff --git a/src/tgchange.c b/src/tgchange.c index d06ad41..f4a461d 100644 --- a/src/tgchange.c +++ b/src/tgchange.c @@ -35,143 +35,132 @@ static int add_hashed_target(struct Client *source_p, uint32_t hashv); struct Channel * find_allowing_channel(struct Client *source_p, struct Client *target_p) { - rb_dlink_node *ptr; - struct membership *msptr; + rb_dlink_node *ptr; + struct membership *msptr; - RB_DLINK_FOREACH(ptr, source_p->user->channel.head) - { - msptr = ptr->data; - if (is_chanop_voiced(msptr) && IsMember(target_p, msptr->chptr)) - return msptr->chptr; - } - return NULL; + RB_DLINK_FOREACH(ptr, source_p->user->channel.head) { + msptr = ptr->data; + if (is_chanop_voiced(msptr) && IsMember(target_p, msptr->chptr)) + return msptr->chptr; + } + return NULL; } int add_target(struct Client *source_p, struct Client *target_p) { - uint32_t hashv; + uint32_t hashv; - /* can msg themselves or services without using any target slots */ - if(source_p == target_p || IsService(target_p)) - return 1; + /* can msg themselves or services without using any target slots */ + if(source_p == target_p || IsService(target_p)) + return 1; - /* special condition for those who have had PRIVMSG crippled to allow them - * to talk to IRCops still. - * - * XXX: is this controversial? - */ - if(source_p->localClient->target_last > rb_current_time() && IsOper(target_p)) - return 1; + /* special condition for those who have had PRIVMSG crippled to allow them + * to talk to IRCops still. + * + * XXX: is this controversial? + */ + if(source_p->localClient->target_last > rb_current_time() && IsOper(target_p)) + return 1; - hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32); - return add_hashed_target(source_p, hashv); + hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32); + return add_hashed_target(source_p, hashv); } int add_channel_target(struct Client *source_p, struct Channel *chptr) { - uint32_t hashv; + uint32_t hashv; - hashv = fnv_hash_upper((const unsigned char *)chptr->chname, 32); - return add_hashed_target(source_p, hashv); + hashv = fnv_hash_upper((const unsigned char *)chptr->chname, 32); + return add_hashed_target(source_p, hashv); } static int add_hashed_target(struct Client *source_p, uint32_t hashv) { - int i, j; - uint32_t *targets; + int i, j; + uint32_t *targets; - targets = source_p->localClient->targets; + targets = source_p->localClient->targets; - /* check for existing target, and move it to the head */ - for(i = 0; i < TGCHANGE_NUM + TGCHANGE_REPLY; i++) - { - if(targets[i] == hashv) - { - for(j = i; j > 0; j--) - targets[j] = targets[j - 1]; - targets[0] = hashv; - return 1; - } - } + /* check for existing target, and move it to the head */ + for(i = 0; i < TGCHANGE_NUM + TGCHANGE_REPLY; i++) { + if(targets[i] == hashv) { + for(j = i; j > 0; j--) + targets[j] = targets[j - 1]; + targets[0] = hashv; + return 1; + } + } - if(source_p->localClient->targets_free < TGCHANGE_NUM) - { - /* first message after connect, we may only start clearing - * slots after this message --anfl - */ - if(!IsTGChange(source_p)) - { - SetTGChange(source_p); - source_p->localClient->target_last = rb_current_time(); - } - /* clear as many targets as we can */ - else if((i = (rb_current_time() - source_p->localClient->target_last) / 60)) - { - if(i + source_p->localClient->targets_free > TGCHANGE_NUM) - source_p->localClient->targets_free = TGCHANGE_NUM; - else - source_p->localClient->targets_free += i; + if(source_p->localClient->targets_free < TGCHANGE_NUM) { + /* first message after connect, we may only start clearing + * slots after this message --anfl + */ + if(!IsTGChange(source_p)) { + SetTGChange(source_p); + source_p->localClient->target_last = rb_current_time(); + } + /* clear as many targets as we can */ + else if((i = (rb_current_time() - source_p->localClient->target_last) / 60)) { + if(i + source_p->localClient->targets_free > TGCHANGE_NUM) + source_p->localClient->targets_free = TGCHANGE_NUM; + else + source_p->localClient->targets_free += i; - source_p->localClient->target_last = rb_current_time(); - } - /* cant clear any, full target list */ - else if(source_p->localClient->targets_free == 0) - { - ServerStats.is_tgch++; - add_tgchange(source_p->sockhost); - return 0; - } - } - /* no targets in use, reset their target_last so that they cant - * abuse a long idle to get targets back more quickly - */ - else - { - source_p->localClient->target_last = rb_current_time(); - SetTGChange(source_p); - } + source_p->localClient->target_last = rb_current_time(); + } + /* cant clear any, full target list */ + else if(source_p->localClient->targets_free == 0) { + ServerStats.is_tgch++; + add_tgchange(source_p->sockhost); + return 0; + } + } + /* no targets in use, reset their target_last so that they cant + * abuse a long idle to get targets back more quickly + */ + else { + source_p->localClient->target_last = rb_current_time(); + SetTGChange(source_p); + } - for(i = TGCHANGE_NUM + TGCHANGE_REPLY - 1; i > 0; i--) - targets[i] = targets[i - 1]; - targets[0] = hashv; - source_p->localClient->targets_free--; - return 1; + for(i = TGCHANGE_NUM + TGCHANGE_REPLY - 1; i > 0; i--) + targets[i] = targets[i - 1]; + targets[0] = hashv; + source_p->localClient->targets_free--; + return 1; } void add_reply_target(struct Client *source_p, struct Client *target_p) { - int i, j; - uint32_t hashv; - uint32_t *targets; + int i, j; + uint32_t hashv; + uint32_t *targets; - /* can msg themselves or services without using any target slots */ - if(source_p == target_p || IsService(target_p)) - return; + /* can msg themselves or services without using any target slots */ + if(source_p == target_p || IsService(target_p)) + return; - hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32); - targets = source_p->localClient->targets; + hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32); + targets = source_p->localClient->targets; - /* check for existing target, and move it to the first reply slot - * if it is in a reply slot - */ - for(i = 0; i < TGCHANGE_NUM + TGCHANGE_REPLY; i++) - { - if(targets[i] == hashv) - { - if(i > TGCHANGE_NUM) - { - for(j = i; j > TGCHANGE_NUM; j--) - targets[j] = targets[j - 1]; - targets[TGCHANGE_NUM] = hashv; - } - return; - } - } - for(i = TGCHANGE_NUM + TGCHANGE_REPLY - 1; i > TGCHANGE_NUM; i--) - targets[i] = targets[i - 1]; - targets[TGCHANGE_NUM] = hashv; + /* check for existing target, and move it to the first reply slot + * if it is in a reply slot + */ + for(i = 0; i < TGCHANGE_NUM + TGCHANGE_REPLY; i++) { + if(targets[i] == hashv) { + if(i > TGCHANGE_NUM) { + for(j = i; j > TGCHANGE_NUM; j--) + targets[j] = targets[j - 1]; + targets[TGCHANGE_NUM] = hashv; + } + return; + } + } + for(i = TGCHANGE_NUM + TGCHANGE_REPLY - 1; i > TGCHANGE_NUM; i--) + targets[i] = targets[i - 1]; + targets[TGCHANGE_NUM] = hashv; } diff --git a/src/whowas.c b/src/whowas.c index 8fc37d0..017c111 100644 --- a/src/whowas.c +++ b/src/whowas.c @@ -52,143 +52,137 @@ static int whowas_next = 0; unsigned int hash_whowas_name(const char *name) { - return fnv_hash_upper((const unsigned char *) name, WW_MAX_BITS); + return fnv_hash_upper((const unsigned char *) name, WW_MAX_BITS); } void add_history(struct Client *client_p, int online) { - struct Whowas *who = &WHOWAS[whowas_next]; + struct Whowas *who = &WHOWAS[whowas_next]; - s_assert(NULL != client_p); + s_assert(NULL != client_p); - if(client_p == NULL) - return; + if(client_p == NULL) + return; - if(who->hashv != -1) - { - if(who->online) - del_whowas_from_clist(&(who->online->whowas), who); - del_whowas_from_list(&WHOWASHASH[who->hashv], who); - } - who->hashv = hash_whowas_name(client_p->name); - who->logoff = rb_current_time(); - /* - * NOTE: strcpy ok here, the sizes in the client struct MUST - * match the sizes in the whowas struct - */ - rb_strlcpy(who->name, client_p->name, sizeof(who->name)); - strcpy(who->username, client_p->username); - strcpy(who->hostname, client_p->host); - strcpy(who->realname, client_p->info); - strcpy(who->suser, client_p->user->suser); - if (!EmptyString(client_p->sockhost) && strcmp(client_p->sockhost, "0") && show_ip(NULL, client_p)) - strcpy(who->sockhost, client_p->sockhost); - else - who->sockhost[0] = '\0'; + if(who->hashv != -1) { + if(who->online) + del_whowas_from_clist(&(who->online->whowas), who); + del_whowas_from_list(&WHOWASHASH[who->hashv], who); + } + who->hashv = hash_whowas_name(client_p->name); + who->logoff = rb_current_time(); + /* + * NOTE: strcpy ok here, the sizes in the client struct MUST + * match the sizes in the whowas struct + */ + rb_strlcpy(who->name, client_p->name, sizeof(who->name)); + strcpy(who->username, client_p->username); + strcpy(who->hostname, client_p->host); + strcpy(who->realname, client_p->info); + strcpy(who->suser, client_p->user->suser); + if (!EmptyString(client_p->sockhost) && strcmp(client_p->sockhost, "0") && show_ip(NULL, client_p)) + strcpy(who->sockhost, client_p->sockhost); + else + who->sockhost[0] = '\0'; - who->servername = scache_get_name(client_p->servptr->serv->nameinfo); + who->servername = scache_get_name(client_p->servptr->serv->nameinfo); - if(online) - { - who->online = client_p; - add_whowas_to_clist(&(client_p->whowas), who); - } - else - who->online = NULL; - add_whowas_to_list(&WHOWASHASH[who->hashv], who); - whowas_next++; - if(whowas_next == NICKNAMEHISTORYLENGTH) - whowas_next = 0; + if(online) { + who->online = client_p; + add_whowas_to_clist(&(client_p->whowas), who); + } else + who->online = NULL; + add_whowas_to_list(&WHOWASHASH[who->hashv], who); + whowas_next++; + if(whowas_next == NICKNAMEHISTORYLENGTH) + whowas_next = 0; } void off_history(struct Client *client_p) { - struct Whowas *temp, *next; + struct Whowas *temp, *next; - for (temp = client_p->whowas; temp; temp = next) - { - next = temp->cnext; - temp->online = NULL; - del_whowas_from_clist(&(client_p->whowas), temp); - } + for (temp = client_p->whowas; temp; temp = next) { + next = temp->cnext; + temp->online = NULL; + del_whowas_from_clist(&(client_p->whowas), temp); + } } struct Client *get_history(const char *nick, time_t timelimit) { - struct Whowas *temp; - int blah; + struct Whowas *temp; + int blah; - timelimit = rb_current_time() - timelimit; - blah = hash_whowas_name(nick); - temp = WHOWASHASH[blah]; - for (; temp; temp = temp->next) - { - if(irccmp(nick, temp->name)) - continue; - if(temp->logoff < timelimit) - continue; - return temp->online; - } - return NULL; + timelimit = rb_current_time() - timelimit; + blah = hash_whowas_name(nick); + temp = WHOWASHASH[blah]; + for (; temp; temp = temp->next) { + if(irccmp(nick, temp->name)) + continue; + if(temp->logoff < timelimit) + continue; + return temp->online; + } + return NULL; } void count_whowas_memory(size_t * wwu, size_t * wwum) { - *wwu = NICKNAMEHISTORYLENGTH; - *wwum = NICKNAMEHISTORYLENGTH * sizeof(struct Whowas); + *wwu = NICKNAMEHISTORYLENGTH; + *wwum = NICKNAMEHISTORYLENGTH * sizeof(struct Whowas); } void initwhowas() { - int i; + int i; - for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) - { - memset((void *) &WHOWAS[i], 0, sizeof(struct Whowas)); - WHOWAS[i].hashv = -1; - } - for (i = 0; i < WW_MAX; i++) - WHOWASHASH[i] = NULL; + for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) { + memset((void *) &WHOWAS[i], 0, sizeof(struct Whowas)); + WHOWAS[i].hashv = -1; + } + for (i = 0; i < WW_MAX; i++) + WHOWASHASH[i] = NULL; } static void add_whowas_to_clist(struct Whowas **bucket, struct Whowas *whowas) { - whowas->cprev = NULL; - if((whowas->cnext = *bucket) != NULL) - whowas->cnext->cprev = whowas; - *bucket = whowas; + whowas->cprev = NULL; + if((whowas->cnext = *bucket) != NULL) + whowas->cnext->cprev = whowas; + *bucket = whowas; } static void del_whowas_from_clist(struct Whowas **bucket, struct Whowas *whowas) { - if(whowas->cprev) - whowas->cprev->cnext = whowas->cnext; - else - *bucket = whowas->cnext; - if(whowas->cnext) - whowas->cnext->cprev = whowas->cprev; + if(whowas->cprev) + whowas->cprev->cnext = whowas->cnext; + else + *bucket = whowas->cnext; + if(whowas->cnext) + whowas->cnext->cprev = whowas->cprev; } static void add_whowas_to_list(struct Whowas **bucket, struct Whowas *whowas) { - whowas->prev = NULL; - if((whowas->next = *bucket) != NULL) - whowas->next->prev = whowas; - *bucket = whowas; + whowas->prev = NULL; + if((whowas->next = *bucket) != NULL) + whowas->next->prev = whowas; + *bucket = whowas; } static void del_whowas_from_list(struct Whowas **bucket, struct Whowas *whowas) { - if(whowas->prev) - whowas->prev->next = whowas->next; - else - *bucket = whowas->next; - if(whowas->next) - whowas->next->prev = whowas->prev; + if(whowas->prev) + whowas->prev->next = whowas->next; + else + *bucket = whowas->next; + if(whowas->next) + whowas->next->prev = whowas->prev; } diff --git a/ssld/ssld.c b/ssld/ssld.c index da01c1f..3dad780 100644 --- a/ssld/ssld.c +++ b/ssld/ssld.c @@ -39,31 +39,31 @@ static pid_t ppid; static inline int32_t buf_to_int32(char *buf) { - int32_t x; - memcpy(&x, buf, sizeof(x)); - return x; + int32_t x; + memcpy(&x, buf, sizeof(x)); + return x; } static inline void int32_to_buf(char *buf, int32_t x) { - memcpy(buf, &x, sizeof(x)); - return; + memcpy(buf, &x, sizeof(x)); + return; } static inline uint16_t buf_to_uint16(char *buf) { - uint16_t x; - memcpy(&x, buf, sizeof(x)); - return x; + uint16_t x; + memcpy(&x, buf, sizeof(x)); + return x; } static inline void uint16_to_buf(char *buf, uint16_t x) { - memcpy(buf, &x, sizeof(x)); - return; + memcpy(buf, &x, sizeof(x)); + return; } @@ -72,53 +72,49 @@ static char inbuf[READBUF_SIZE]; static char outbuf[READBUF_SIZE]; #endif -typedef struct _mod_ctl_buf -{ - rb_dlink_node node; - char *buf; - size_t buflen; - rb_fde_t *F[MAXPASSFD]; - int nfds; +typedef struct _mod_ctl_buf { + rb_dlink_node node; + char *buf; + size_t buflen; + rb_fde_t *F[MAXPASSFD]; + int nfds; } mod_ctl_buf_t; -typedef struct _mod_ctl -{ - rb_dlink_node node; - int cli_count; - rb_fde_t *F; - rb_fde_t *F_pipe; - rb_dlink_list readq; - rb_dlink_list writeq; +typedef struct _mod_ctl { + rb_dlink_node node; + int cli_count; + rb_fde_t *F; + rb_fde_t *F_pipe; + rb_dlink_list readq; + rb_dlink_list writeq; } mod_ctl_t; static mod_ctl_t *mod_ctl; #ifdef HAVE_LIBZ -typedef struct _zlib_stream -{ - z_stream instream; - z_stream outstream; +typedef struct _zlib_stream { + z_stream instream; + z_stream outstream; } zlib_stream_t; #endif -typedef struct _conn -{ - rb_dlink_node node; - mod_ctl_t *ctl; - rawbuf_head_t *modbuf_out; - rawbuf_head_t *plainbuf_out; +typedef struct _conn { + rb_dlink_node node; + mod_ctl_t *ctl; + rawbuf_head_t *modbuf_out; + rawbuf_head_t *plainbuf_out; - int32_t id; + int32_t id; - 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; - uint8_t flags; - void *stream; + 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; + uint8_t flags; + void *stream; } conn_t; #define FLAG_SSL 0x01 @@ -186,697 +182,658 @@ static int zlib_ok = 0; static void * ssld_alloc(void *unused, size_t count, size_t size) { - return rb_malloc(count * size); + return rb_malloc(count * size); } static void ssld_free(void *unused, void *ptr) { - rb_free(ptr); + rb_free(ptr); } #endif static conn_t * conn_find_by_id(int32_t id) { - rb_dlink_node *ptr; - conn_t *conn; + rb_dlink_node *ptr; + conn_t *conn; - RB_DLINK_FOREACH(ptr, (connid_hash(id))->head) - { - conn = ptr->data; - if(conn->id == id && !IsDead(conn)) - return conn; - } - return NULL; + RB_DLINK_FOREACH(ptr, (connid_hash(id))->head) { + conn = ptr->data; + if(conn->id == id && !IsDead(conn)) + return conn; + } + return NULL; } static void conn_add_id_hash(conn_t * conn, int32_t id) { - conn->id = id; - rb_dlinkAdd(conn, &conn->node, connid_hash(id)); + conn->id = id; + rb_dlinkAdd(conn, &conn->node, connid_hash(id)); } static void free_conn(conn_t * conn) { - rb_free_rawbuffer(conn->modbuf_out); - rb_free_rawbuffer(conn->plainbuf_out); + rb_free_rawbuffer(conn->modbuf_out); + rb_free_rawbuffer(conn->plainbuf_out); #ifdef HAVE_LIBZ - if(IsZip(conn)) - { - zlib_stream_t *stream = conn->stream; - inflateEnd(&stream->instream); - deflateEnd(&stream->outstream); - } + if(IsZip(conn)) { + zlib_stream_t *stream = conn->stream; + inflateEnd(&stream->instream); + deflateEnd(&stream->outstream); + } #endif - rb_free(conn); + rb_free(conn); } static void clean_dead_conns(void *unused) { - conn_t *conn; - rb_dlink_node *ptr, *next; - RB_DLINK_FOREACH_SAFE(ptr, next, dead_list.head) - { - conn = ptr->data; - free_conn(conn); - } - dead_list.tail = dead_list.head = NULL; + conn_t *conn; + rb_dlink_node *ptr, *next; + RB_DLINK_FOREACH_SAFE(ptr, next, dead_list.head) { + conn = ptr->data; + free_conn(conn); + } + dead_list.tail = dead_list.head = NULL; } 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 */ - char buf[256]; - int len; - if(IsDead(conn)) - return; + va_list ap; + char reason[128]; /* must always be under 250 bytes */ + char 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_rawbuf_flush(conn->modbuf_out, conn->mod_fd); + rb_rawbuf_flush(conn->plainbuf_out, conn->plain_fd); + rb_close(conn->mod_fd); + SetDead(conn); - if(conn->id >= 0 && !IsZipSSL(conn)) - rb_dlinkDelete(&conn->node, connid_hash(conn->id)); + if(conn->id >= 0 && !IsZipSSL(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); - rb_vsnprintf(reason, sizeof(reason), fmt, ap); - va_end(ap); + 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); + rb_vsnprintf(reason, sizeof(reason), fmt, ap); + va_end(ap); - buf[0] = 'D'; - int32_to_buf(&buf[1], conn->id); - strcpy(&buf[5], reason); - len = (strlen(reason) + 1) + 5; - mod_cmd_write_queue(conn->ctl, buf, len); + buf[0] = 'D'; + int32_to_buf(&buf[1], conn->id); + strcpy(&buf[5], reason); + 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) { - conn_t *conn = rb_malloc(sizeof(conn_t)); - conn->ctl = ctl; - conn->modbuf_out = rb_new_rawbuffer(); - conn->plainbuf_out = rb_new_rawbuffer(); - 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; + conn_t *conn = rb_malloc(sizeof(conn_t)); + conn->ctl = ctl; + conn->modbuf_out = rb_new_rawbuffer(); + conn->plainbuf_out = rb_new_rawbuffer(); + 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; } static void check_handshake_flood(void *unused) { - conn_t *conn; - rb_dlink_node *ptr, *next; - unsigned int count; - int i; - HASH_WALK_SAFE(i, CONN_HASH_SIZE, ptr, next, connid_hash_table) - { - conn = ptr->data; - if(!IsSSL(conn)) - continue; + conn_t *conn; + rb_dlink_node *ptr, *next; + unsigned int count; + int i; + HASH_WALK_SAFE(i, CONN_HASH_SIZE, ptr, next, connid_hash_table) { + conn = ptr->data; + if(!IsSSL(conn)) + continue; - count = rb_ssl_handshake_count(conn->mod_fd); - /* nothing needs to do this more than twice in ten seconds i don't think */ - if(count > 2) - close_conn(conn, WAIT_PLAIN, "Handshake flooding"); - else - rb_ssl_clear_handshake_count(conn->mod_fd); - } -HASH_WALK_END} + count = rb_ssl_handshake_count(conn->mod_fd); + /* nothing needs to do this more than twice in ten seconds i don't think */ + if(count > 2) + close_conn(conn, WAIT_PLAIN, "Handshake flooding"); + else + rb_ssl_clear_handshake_count(conn->mod_fd); + } + HASH_WALK_END +} static void conn_mod_write_sendq(rb_fde_t *fd, void *data) { - conn_t *conn = data; - const char *err; - int retlen; - if(IsDead(conn)) - return; + conn_t *conn = data; + const char *err; + int retlen; + if(IsDead(conn)) + return; - if(IsSSLWWantsR(conn)) - { - ClearSSLWWantsR(conn); - conn_mod_read_cb(conn->mod_fd, conn); - if(IsDead(conn)) - return; - } + if(IsSSLWWantsR(conn)) { + ClearSSLWWantsR(conn); + conn_mod_read_cb(conn->mod_fd, conn); + if(IsDead(conn)) + return; + } - while((retlen = rb_rawbuf_flush(conn->modbuf_out, fd)) > 0) - conn->mod_out += retlen; + while((retlen = rb_rawbuf_flush(conn->modbuf_out, fd)) > 0) + conn->mod_out += retlen; - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - if(retlen == 0) - close_conn(conn, WAIT_PLAIN, "%s", remote_closed); - if(IsSSL(conn) && retlen == RB_RW_SSL_ERROR) - err = rb_get_ssl_strerror(conn->mod_fd); - else - err = strerror(errno); - close_conn(conn, WAIT_PLAIN, "Write error: %s", err); - return; - } - if(rb_rawbuf_length(conn->modbuf_out) > 0) - { - if(retlen != RB_RW_SSL_NEED_READ) - rb_setselect(conn->mod_fd, RB_SELECT_WRITE, conn_mod_write_sendq, conn); - else - { - rb_setselect(conn->mod_fd, RB_SELECT_READ, conn_mod_write_sendq, conn); - rb_setselect(conn->mod_fd, RB_SELECT_WRITE, NULL, NULL); - SetSSLWWantsR(conn); - } - } - else - rb_setselect(conn->mod_fd, RB_SELECT_WRITE, NULL, NULL); + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + if(retlen == 0) + close_conn(conn, WAIT_PLAIN, "%s", remote_closed); + if(IsSSL(conn) && retlen == RB_RW_SSL_ERROR) + err = rb_get_ssl_strerror(conn->mod_fd); + else + err = strerror(errno); + close_conn(conn, WAIT_PLAIN, "Write error: %s", err); + return; + } + if(rb_rawbuf_length(conn->modbuf_out) > 0) { + if(retlen != RB_RW_SSL_NEED_READ) + rb_setselect(conn->mod_fd, RB_SELECT_WRITE, conn_mod_write_sendq, conn); + else { + rb_setselect(conn->mod_fd, RB_SELECT_READ, conn_mod_write_sendq, conn); + rb_setselect(conn->mod_fd, RB_SELECT_WRITE, NULL, NULL); + SetSSLWWantsR(conn); + } + } else + rb_setselect(conn->mod_fd, RB_SELECT_WRITE, NULL, NULL); - if(IsCork(conn) && rb_rawbuf_length(conn->modbuf_out) == 0) - { - ClearCork(conn); - conn_plain_read_cb(conn->plain_fd, conn); - } + if(IsCork(conn) && rb_rawbuf_length(conn->modbuf_out) == 0) { + ClearCork(conn); + conn_plain_read_cb(conn->plain_fd, conn); + } } static void conn_mod_write(conn_t * conn, void *data, size_t len) { - if(IsDead(conn)) /* no point in queueing to a dead man */ - return; - rb_rawbuf_append(conn->modbuf_out, data, len); + if(IsDead(conn)) /* no point in queueing to a dead man */ + return; + rb_rawbuf_append(conn->modbuf_out, data, len); } static void conn_plain_write(conn_t * conn, void *data, size_t len) { - if(IsDead(conn)) /* again no point in queueing to dead men */ - return; - rb_rawbuf_append(conn->plainbuf_out, data, len); + if(IsDead(conn)) /* again no point in queueing to dead men */ + return; + rb_rawbuf_append(conn->plainbuf_out, data, len); } 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); + 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); } #ifdef HAVE_LIBZ static void common_zlib_deflate(conn_t * conn, void *buf, size_t len) { - int ret, have; - z_stream *outstream = &((zlib_stream_t *) conn->stream)->outstream; - outstream->next_in = buf; - outstream->avail_in = len; - outstream->next_out = (Bytef *) outbuf; - outstream->avail_out = sizeof(outbuf); + int ret, have; + z_stream *outstream = &((zlib_stream_t *) conn->stream)->outstream; + outstream->next_in = buf; + outstream->avail_in = len; + outstream->next_out = (Bytef *) outbuf; + outstream->avail_out = sizeof(outbuf); - ret = deflate(outstream, Z_SYNC_FLUSH); - if(ret != Z_OK) - { - /* deflate error */ - close_conn(conn, WAIT_PLAIN, "Deflate failed: %s", zError(ret)); - return; - } - if(outstream->avail_out == 0) - { - /* avail_out empty */ - close_conn(conn, WAIT_PLAIN, "error compressing data, avail_out == 0"); - return; - } - if(outstream->avail_in != 0) - { - /* avail_in isn't empty... */ - close_conn(conn, WAIT_PLAIN, "error compressing data, avail_in != 0"); - return; - } - have = sizeof(outbuf) - outstream->avail_out; - conn_mod_write(conn, outbuf, have); + ret = deflate(outstream, Z_SYNC_FLUSH); + if(ret != Z_OK) { + /* deflate error */ + close_conn(conn, WAIT_PLAIN, "Deflate failed: %s", zError(ret)); + return; + } + if(outstream->avail_out == 0) { + /* avail_out empty */ + close_conn(conn, WAIT_PLAIN, "error compressing data, avail_out == 0"); + return; + } + if(outstream->avail_in != 0) { + /* avail_in isn't empty... */ + close_conn(conn, WAIT_PLAIN, "error compressing data, avail_in != 0"); + return; + } + have = sizeof(outbuf) - outstream->avail_out; + conn_mod_write(conn, outbuf, have); } static void common_zlib_inflate(conn_t * conn, void *buf, size_t len) { - int ret, have = 0; - ((zlib_stream_t *) conn->stream)->instream.next_in = buf; - ((zlib_stream_t *) conn->stream)->instream.avail_in = len; - ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf; - ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf); + int ret, have = 0; + ((zlib_stream_t *) conn->stream)->instream.next_in = buf; + ((zlib_stream_t *) conn->stream)->instream.avail_in = len; + ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf; + ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf); - while(((zlib_stream_t *) conn->stream)->instream.avail_in) - { - ret = inflate(&((zlib_stream_t *) conn->stream)->instream, Z_NO_FLUSH); - if(ret != Z_OK) - { - if(!strncmp("ERROR ", buf, 6)) - { - close_conn(conn, WAIT_PLAIN, "Received uncompressed ERROR"); - return; - } - close_conn(conn, WAIT_PLAIN, "Inflate failed: %s", zError(ret)); - return; - } - have = sizeof(outbuf) - ((zlib_stream_t *) conn->stream)->instream.avail_out; + while(((zlib_stream_t *) conn->stream)->instream.avail_in) { + ret = inflate(&((zlib_stream_t *) conn->stream)->instream, Z_NO_FLUSH); + if(ret != Z_OK) { + if(!strncmp("ERROR ", buf, 6)) { + close_conn(conn, WAIT_PLAIN, "Received uncompressed ERROR"); + return; + } + close_conn(conn, WAIT_PLAIN, "Inflate failed: %s", zError(ret)); + return; + } + have = sizeof(outbuf) - ((zlib_stream_t *) conn->stream)->instream.avail_out; - if(((zlib_stream_t *) conn->stream)->instream.avail_in) - { - conn_plain_write(conn, outbuf, have); - have = 0; - ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf; - ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf); - } - } - if(have == 0) - return; + if(((zlib_stream_t *) conn->stream)->instream.avail_in) { + conn_plain_write(conn, outbuf, have); + have = 0; + ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf; + ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf); + } + } + if(have == 0) + return; - conn_plain_write(conn, outbuf, have); + conn_plain_write(conn, outbuf, have); } #endif static int plain_check_cork(conn_t * conn) { - if(rb_rawbuf_length(conn->modbuf_out) >= 4096) - { - /* if we have over 4k pending outbound, don't read until - * we've cleared the queue */ - SetCork(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 0; + if(rb_rawbuf_length(conn->modbuf_out) >= 4096) { + /* if we have over 4k pending outbound, don't read until + * we've cleared the queue */ + SetCork(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 0; } static void conn_plain_read_cb(rb_fde_t *fd, void *data) { - conn_t *conn = data; - int length = 0; - if(conn == NULL) - return; + conn_t *conn = data; + int length = 0; + if(conn == NULL) + return; - if(IsDead(conn)) - return; + if(IsDead(conn)) + return; - if(plain_check_cork(conn)) - return; + if(plain_check_cork(conn)) + return; - while(1) - { - if(IsDead(conn)) - return; + while(1) { + if(IsDead(conn)) + return; - length = rb_read(conn->plain_fd, inbuf, sizeof(inbuf)); + length = rb_read(conn->plain_fd, inbuf, sizeof(inbuf)); - if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) - { - close_conn(conn, NO_WAIT, NULL); - return; - } + if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) { + close_conn(conn, NO_WAIT, NULL); + return; + } - if(length < 0) - { - rb_setselect(conn->plain_fd, RB_SELECT_READ, conn_plain_read_cb, conn); - conn_mod_write_sendq(conn->mod_fd, conn); - return; - } - conn->plain_in += length; + if(length < 0) { + rb_setselect(conn->plain_fd, RB_SELECT_READ, conn_plain_read_cb, conn); + conn_mod_write_sendq(conn->mod_fd, conn); + return; + } + conn->plain_in += length; #ifdef HAVE_LIBZ - if(IsZip(conn)) - common_zlib_deflate(conn, inbuf, length); - else + if(IsZip(conn)) + common_zlib_deflate(conn, inbuf, length); + else #endif - conn_mod_write(conn, inbuf, length); - if(IsDead(conn)) - return; - if(plain_check_cork(conn)) - return; - } + conn_mod_write(conn, inbuf, length); + if(IsDead(conn)) + return; + if(plain_check_cork(conn)) + return; + } } static void conn_plain_read_shutdown_cb(rb_fde_t *fd, void *data) { - conn_t *conn = data; - int length = 0; + conn_t *conn = data; + int length = 0; - if(conn == NULL) - return; + if(conn == NULL) + return; - while(1) - { - length = rb_read(conn->plain_fd, inbuf, sizeof(inbuf)); + 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 || (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; - } - } + if(length < 0) { + rb_setselect(conn->plain_fd, RB_SELECT_READ, conn_plain_read_shutdown_cb, conn); + return; + } + } } static void conn_mod_read_cb(rb_fde_t *fd, void *data) { - conn_t *conn = data; - const char *err; - int length; - if(conn == NULL) - return; - if(IsDead(conn)) - return; + conn_t *conn = data; + const char *err; + int length; + if(conn == NULL) + return; + if(IsDead(conn)) + return; - if(IsSSLRWantsW(conn)) - { - ClearSSLRWantsW(conn); - conn_mod_write_sendq(conn->mod_fd, conn); - if(IsDead(conn)) - return; - } + if(IsSSLRWantsW(conn)) { + ClearSSLRWantsW(conn); + conn_mod_write_sendq(conn->mod_fd, conn); + if(IsDead(conn)) + return; + } - while(1) - { - if(IsDead(conn)) - return; + while(1) { + if(IsDead(conn)) + return; - length = rb_read(conn->mod_fd, inbuf, sizeof(inbuf)); + length = rb_read(conn->mod_fd, inbuf, sizeof(inbuf)); - if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) - { - if(length == 0) - { - close_conn(conn, WAIT_PLAIN, "%s", remote_closed); - return; - } + if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) { + if(length == 0) { + close_conn(conn, WAIT_PLAIN, "%s", remote_closed); + return; + } - if(IsSSL(conn) && length == RB_RW_SSL_ERROR) - err = rb_get_ssl_strerror(conn->mod_fd); - else - err = strerror(errno); - close_conn(conn, WAIT_PLAIN, "Read error: %s", err); - return; - } - if(length < 0) - { - if(length != RB_RW_SSL_NEED_WRITE) - rb_setselect(conn->mod_fd, RB_SELECT_READ, conn_mod_read_cb, conn); - else - { - rb_setselect(conn->mod_fd, RB_SELECT_READ, NULL, NULL); - rb_setselect(conn->mod_fd, RB_SELECT_WRITE, conn_mod_read_cb, conn); - SetSSLRWantsW(conn); - } - conn_plain_write_sendq(conn->plain_fd, conn); - return; - } - conn->mod_in += length; + if(IsSSL(conn) && length == RB_RW_SSL_ERROR) + err = rb_get_ssl_strerror(conn->mod_fd); + else + err = strerror(errno); + close_conn(conn, WAIT_PLAIN, "Read error: %s", err); + return; + } + if(length < 0) { + if(length != RB_RW_SSL_NEED_WRITE) + rb_setselect(conn->mod_fd, RB_SELECT_READ, conn_mod_read_cb, conn); + else { + rb_setselect(conn->mod_fd, RB_SELECT_READ, NULL, NULL); + rb_setselect(conn->mod_fd, RB_SELECT_WRITE, conn_mod_read_cb, conn); + SetSSLRWantsW(conn); + } + conn_plain_write_sendq(conn->plain_fd, conn); + return; + } + conn->mod_in += length; #ifdef HAVE_LIBZ - if(IsZip(conn)) - common_zlib_inflate(conn, inbuf, length); - else + if(IsZip(conn)) + common_zlib_inflate(conn, inbuf, length); + else #endif - conn_plain_write(conn, inbuf, length); - } + conn_plain_write(conn, inbuf, length); + } } static void conn_plain_write_sendq(rb_fde_t *fd, void *data) { - conn_t *conn = data; - int retlen; + conn_t *conn = data; + int retlen; - if(IsDead(conn)) - return; + if(IsDead(conn)) + return; - while((retlen = rb_rawbuf_flush(conn->plainbuf_out, fd)) > 0) - { - conn->plain_out += retlen; - } - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - close_conn(data, NO_WAIT, NULL); - return; - } + while((retlen = rb_rawbuf_flush(conn->plainbuf_out, fd)) > 0) { + conn->plain_out += retlen; + } + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { + close_conn(data, NO_WAIT, NULL); + return; + } - if(rb_rawbuf_length(conn->plainbuf_out) > 0) - rb_setselect(conn->plain_fd, RB_SELECT_WRITE, conn_plain_write_sendq, conn); - else - rb_setselect(conn->plain_fd, RB_SELECT_WRITE, NULL, NULL); + if(rb_rawbuf_length(conn->plainbuf_out) > 0) + rb_setselect(conn->plain_fd, RB_SELECT_WRITE, conn_plain_write_sendq, conn); + else + rb_setselect(conn->plain_fd, RB_SELECT_WRITE, NULL, NULL); } static int maxconn(void) { #if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) - struct rlimit limit; + struct rlimit limit; - if(!getrlimit(RLIMIT_NOFILE, &limit)) - { - return limit.rlim_cur; - } + if(!getrlimit(RLIMIT_NOFILE, &limit)) { + return limit.rlim_cur; + } #endif /* RLIMIT_FD_MAX */ - return MAXCONNECTIONS; + return MAXCONNECTIONS; } static void ssl_process_accept_cb(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t len, void *data) { - conn_t *conn = data; - char buf[5 + RB_SSL_CERTFP_LEN]; + conn_t *conn = data; + char buf[5 + RB_SSL_CERTFP_LEN]; - if(status == RB_OK) - { - if(rb_get_ssl_certfp(F, &buf[5])) - { - buf[0] = 'F'; - int32_to_buf(&buf[1], conn->id); - mod_cmd_write_queue(conn->ctl, buf, sizeof buf); - } - conn_mod_read_cb(conn->mod_fd, conn); - conn_plain_read_cb(conn->plain_fd, conn); - return; - } - /* ircd doesn't care about the reason for this */ - close_conn(conn, NO_WAIT, 0); - return; + if(status == RB_OK) { + if(rb_get_ssl_certfp(F, &buf[5])) { + buf[0] = 'F'; + int32_to_buf(&buf[1], conn->id); + mod_cmd_write_queue(conn->ctl, buf, sizeof buf); + } + conn_mod_read_cb(conn->mod_fd, conn); + conn_plain_read_cb(conn->plain_fd, conn); + return; + } + /* ircd doesn't care about the reason for this */ + close_conn(conn, NO_WAIT, 0); + return; } static void ssl_process_connect_cb(rb_fde_t *F, int status, void *data) { - conn_t *conn = data; - char buf[5 + RB_SSL_CERTFP_LEN]; + conn_t *conn = data; + char buf[5 + RB_SSL_CERTFP_LEN]; - if(status == RB_OK) - { - if(rb_get_ssl_certfp(F, &buf[5])) - { - buf[0] = 'F'; - int32_to_buf(&buf[1], conn->id); - mod_cmd_write_queue(conn->ctl, buf, sizeof buf); - } - conn_mod_read_cb(conn->mod_fd, conn); - conn_plain_read_cb(conn->plain_fd, conn); - } - else if(status == RB_ERR_TIMEOUT) - close_conn(conn, WAIT_PLAIN, "SSL handshake timed out"); - else if(status == RB_ERROR_SSL) - close_conn(conn, WAIT_PLAIN, "%s", rb_get_ssl_strerror(conn->mod_fd)); - else - close_conn(conn, WAIT_PLAIN, "SSL handshake failed"); + if(status == RB_OK) { + if(rb_get_ssl_certfp(F, &buf[5])) { + buf[0] = 'F'; + int32_to_buf(&buf[1], conn->id); + mod_cmd_write_queue(conn->ctl, buf, sizeof buf); + } + conn_mod_read_cb(conn->mod_fd, conn); + conn_plain_read_cb(conn->plain_fd, conn); + } else if(status == RB_ERR_TIMEOUT) + close_conn(conn, WAIT_PLAIN, "SSL handshake timed out"); + else if(status == RB_ERROR_SSL) + close_conn(conn, WAIT_PLAIN, "%s", rb_get_ssl_strerror(conn->mod_fd)); + else + close_conn(conn, WAIT_PLAIN, "SSL handshake failed"); } static void cleanup_bad_message(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { - int i; + int i; - /* XXX should log this somehow */ - for (i = 0; i < ctlb->nfds; i++) - rb_close(ctlb->F[i]); + /* XXX should log this somehow */ + for (i = 0; i < ctlb->nfds; i++) + rb_close(ctlb->F[i]); } static void ssl_process_accept(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { - conn_t *conn; - int32_t id; + conn_t *conn; + int32_t id; - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); + conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - id = buf_to_int32(&ctlb->buf[1]); + id = buf_to_int32(&ctlb->buf[1]); - if(id >= 0) - conn_add_id_hash(conn, id); - SetSSL(conn); + if(id >= 0) + conn_add_id_hash(conn, id); + SetSSL(conn); - if(rb_get_type(conn->mod_fd) & RB_FD_UNKNOWN) - { + 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) - rb_set_type(conn->plain_fd, RB_FD_SOCKET); + rb_set_type(conn->mod_fd, RB_FD_SOCKET); + } + if(rb_get_type(conn->mod_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); + rb_ssl_start_accepted(ctlb->F[0], ssl_process_accept_cb, conn, 10); } static void ssl_process_connect(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { - conn_t *conn; - int32_t id; - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); + conn_t *conn; + int32_t id; + conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - id = buf_to_int32(&ctlb->buf[1]); + id = buf_to_int32(&ctlb->buf[1]); - if(id >= 0) - conn_add_id_hash(conn, id); - SetSSL(conn); + if(id >= 0) + conn_add_id_hash(conn, id); + 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) + rb_set_type(conn->mod_fd, RB_FD_SOCKET); - if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->plain_fd, RB_FD_SOCKET); + if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) + rb_set_type(conn->plain_fd, RB_FD_SOCKET); - rb_ssl_start_connected(ctlb->F[0], ssl_process_connect_cb, conn, 10); + rb_ssl_start_connected(ctlb->F[0], ssl_process_connect_cb, conn, 10); } static void process_stats(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { - char outstat[512]; - conn_t *conn; - const char *odata; - int32_t id; + char outstat[512]; + conn_t *conn; + const char *odata; + int32_t id; - id = buf_to_int32(&ctlb->buf[1]); + id = buf_to_int32(&ctlb->buf[1]); - if(id < 0) - return; + if(id < 0) + return; - odata = &ctlb->buf[5]; - conn = conn_find_by_id(id); + odata = &ctlb->buf[5]; + conn = conn_find_by_id(id); - if(conn == NULL) - return; + 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); - conn->plain_out = 0; - conn->plain_in = 0; - conn->mod_in = 0; - conn->mod_out = 0; - mod_cmd_write_queue(ctl, outstat, strlen(outstat) + 1); /* +1 is so we send the \0 as well */ + rb_snprintf(outstat, sizeof(outstat), "S %s %llu %llu %llu %llu", odata, + conn->plain_out, conn->mod_in, conn->plain_in, conn->mod_out); + conn->plain_out = 0; + conn->plain_in = 0; + conn->mod_in = 0; + conn->mod_out = 0; + 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) { - int32_t id = buf_to_int32(&ctlb->buf[1]); - int32_t newid = buf_to_int32(&ctlb->buf[5]); - conn_t *conn = conn_find_by_id(id); - if(conn->id >= 0) - rb_dlinkDelete(&conn->node, connid_hash(conn->id)); - SetZipSSL(conn); - conn->id = newid; + int32_t id = buf_to_int32(&ctlb->buf[1]); + int32_t newid = buf_to_int32(&ctlb->buf[5]); + conn_t *conn = conn_find_by_id(id); + if(conn->id >= 0) + 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) { - uint8_t level; - size_t recvqlen; - size_t hdr = (sizeof(uint8_t) * 2) + sizeof(int32_t); - void *recvq_start; - z_stream *instream, *outstream; - conn_t *conn; - int32_t id; + uint8_t level; + size_t recvqlen; + size_t hdr = (sizeof(uint8_t) * 2) + sizeof(int32_t); + void *recvq_start; + z_stream *instream, *outstream; + conn_t *conn; + int32_t id; - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->mod_fd, RB_FD_SOCKET); + conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); + if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) + rb_set_type(conn->mod_fd, RB_FD_SOCKET); - if(rb_get_type(conn->plain_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->plain_fd, RB_FD_SOCKET); + if(rb_get_type(conn->plain_fd) == RB_FD_UNKNOWN) + rb_set_type(conn->plain_fd, RB_FD_SOCKET); - id = buf_to_int32(&ctlb->buf[1]); - conn_add_id_hash(conn, id); + id = buf_to_int32(&ctlb->buf[1]); + conn_add_id_hash(conn, id); - level = (uint8_t)ctlb->buf[5]; + level = (uint8_t)ctlb->buf[5]; - recvqlen = ctlb->buflen - hdr; - recvq_start = &ctlb->buf[6]; + recvqlen = ctlb->buflen - hdr; + recvq_start = &ctlb->buf[6]; - SetZip(conn); - conn->stream = rb_malloc(sizeof(zlib_stream_t)); - instream = &((zlib_stream_t *) conn->stream)->instream; - outstream = &((zlib_stream_t *) conn->stream)->outstream; + SetZip(conn); + conn->stream = rb_malloc(sizeof(zlib_stream_t)); + instream = &((zlib_stream_t *) conn->stream)->instream; + outstream = &((zlib_stream_t *) conn->stream)->outstream; - instream->total_in = 0; - instream->total_out = 0; - instream->zalloc = (alloc_func) ssld_alloc; - instream->zfree = (free_func) ssld_free; - instream->data_type = Z_ASCII; - inflateInit(&((zlib_stream_t *) conn->stream)->instream); + instream->total_in = 0; + instream->total_out = 0; + instream->zalloc = (alloc_func) ssld_alloc; + instream->zfree = (free_func) ssld_free; + instream->data_type = Z_ASCII; + inflateInit(&((zlib_stream_t *) conn->stream)->instream); - outstream->total_in = 0; - outstream->total_out = 0; - outstream->zalloc = (alloc_func) ssld_alloc; - outstream->zfree = (free_func) ssld_free; - outstream->data_type = Z_ASCII; + outstream->total_in = 0; + outstream->total_out = 0; + outstream->zalloc = (alloc_func) ssld_alloc; + outstream->zfree = (free_func) ssld_free; + outstream->data_type = Z_ASCII; - if(level > 9) - level = Z_DEFAULT_COMPRESSION; + if(level > 9) + level = Z_DEFAULT_COMPRESSION; - deflateInit(&((zlib_stream_t *) conn->stream)->outstream, level); - if(recvqlen > 0) - common_zlib_inflate(conn, recvq_start, recvqlen); + deflateInit(&((zlib_stream_t *) conn->stream)->outstream, level); + if(recvqlen > 0) + common_zlib_inflate(conn, recvq_start, recvqlen); - conn_mod_read_cb(conn->mod_fd, conn); - conn_plain_read_cb(conn->plain_fd, conn); - return; + conn_mod_read_cb(conn->mod_fd, conn); + conn_plain_read_cb(conn->plain_fd, conn); + return; } #endif @@ -884,179 +841,162 @@ zlib_process(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) static void init_prng(mod_ctl_t * ctl, mod_ctl_buf_t * ctl_buf) { - char *path; - prng_seed_t seed_type; + char *path; + prng_seed_t seed_type; - seed_type = (prng_seed_t) ctl_buf->buf[1]; - path = &ctl_buf->buf[2]; - rb_init_prng(path, seed_type); + seed_type = (prng_seed_t) ctl_buf->buf[1]; + path = &ctl_buf->buf[2]; + rb_init_prng(path, seed_type); } static void ssl_new_keys(mod_ctl_t * ctl, mod_ctl_buf_t * ctl_buf) { - char *buf; - char *cert, *key, *dhparam; + char *buf; + char *cert, *key, *dhparam; - buf = &ctl_buf->buf[2]; - cert = buf; - buf += strlen(cert) + 1; - key = buf; - buf += strlen(key) + 1; - dhparam = buf; - if(strlen(dhparam) == 0) - dhparam = NULL; + buf = &ctl_buf->buf[2]; + cert = buf; + buf += strlen(cert) + 1; + key = buf; + buf += strlen(key) + 1; + dhparam = buf; + if(strlen(dhparam) == 0) + dhparam = NULL; - if(!rb_setup_ssl_server(cert, key, dhparam)) - { - const char *invalid = "I"; - mod_cmd_write_queue(ctl, invalid, strlen(invalid)); - return; - } + if(!rb_setup_ssl_server(cert, key, dhparam)) { + const char *invalid = "I"; + mod_cmd_write_queue(ctl, invalid, strlen(invalid)); + return; + } } static void send_nossl_support(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { - static const char *nossl_cmd = "N"; - conn_t *conn; - int32_t id; + static const char *nossl_cmd = "N"; + conn_t *conn; + int32_t id; - if(ctlb != NULL) - { - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - id = buf_to_int32(&ctlb->buf[1]); + if(ctlb != NULL) { + conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); + id = buf_to_int32(&ctlb->buf[1]); - if(id >= 0) - conn_add_id_hash(conn, id); - close_conn(conn, WAIT_PLAIN, "libratbox reports no SSL/TLS support"); - } - mod_cmd_write_queue(ctl, nossl_cmd, strlen(nossl_cmd)); + if(id >= 0) + conn_add_id_hash(conn, id); + close_conn(conn, WAIT_PLAIN, "libratbox reports no SSL/TLS support"); + } + mod_cmd_write_queue(ctl, nossl_cmd, strlen(nossl_cmd)); } static void send_i_am_useless(mod_ctl_t * ctl) { - static const char *useless = "U"; - mod_cmd_write_queue(ctl, useless, strlen(useless)); + static const char *useless = "U"; + mod_cmd_write_queue(ctl, useless, strlen(useless)); } static void send_nozlib_support(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) { - static const char *nozlib_cmd = "z"; - conn_t *conn; - int32_t id; - if(ctlb != NULL) - { - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - id = buf_to_int32(&ctlb->buf[1]); + static const char *nozlib_cmd = "z"; + conn_t *conn; + int32_t id; + if(ctlb != NULL) { + conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); + id = buf_to_int32(&ctlb->buf[1]); - if(id >= 0) - conn_add_id_hash(conn, id); - close_conn(conn, WAIT_PLAIN, "libratbox reports no zlib support"); - } - mod_cmd_write_queue(ctl, nozlib_cmd, strlen(nozlib_cmd)); + if(id >= 0) + conn_add_id_hash(conn, id); + close_conn(conn, WAIT_PLAIN, "libratbox reports no zlib support"); + } + mod_cmd_write_queue(ctl, nozlib_cmd, strlen(nozlib_cmd)); } static void mod_process_cmd_recv(mod_ctl_t * ctl) { - rb_dlink_node *ptr, *next; - mod_ctl_buf_t *ctl_buf; + rb_dlink_node *ptr, *next; + mod_ctl_buf_t *ctl_buf; - RB_DLINK_FOREACH_SAFE(ptr, next, ctl->readq.head) - { - ctl_buf = ptr->data; + RB_DLINK_FOREACH_SAFE(ptr, next, ctl->readq.head) { + ctl_buf = ptr->data; - switch (*ctl_buf->buf) - { - case 'A': - { - if (ctl_buf->nfds != 2 || ctl_buf->buflen != 5) - { - cleanup_bad_message(ctl, ctl_buf); - break; - } + switch (*ctl_buf->buf) { + case 'A': { + if (ctl_buf->nfds != 2 || ctl_buf->buflen != 5) { + cleanup_bad_message(ctl, ctl_buf); + break; + } - if(!ssl_ok) - { - send_nossl_support(ctl, ctl_buf); - break; - } - ssl_process_accept(ctl, ctl_buf); - break; - } - case 'C': - { - if (ctl_buf->nfds != 2 || ctl_buf->buflen != 5) - { - cleanup_bad_message(ctl, ctl_buf); - break; - } + if(!ssl_ok) { + send_nossl_support(ctl, ctl_buf); + break; + } + ssl_process_accept(ctl, ctl_buf); + break; + } + case 'C': { + if (ctl_buf->nfds != 2 || ctl_buf->buflen != 5) { + cleanup_bad_message(ctl, ctl_buf); + break; + } - if(!ssl_ok) - { - send_nossl_support(ctl, ctl_buf); - break; - } - ssl_process_connect(ctl, ctl_buf); - break; - } + if(!ssl_ok) { + send_nossl_support(ctl, ctl_buf); + break; + } + ssl_process_connect(ctl, ctl_buf); + break; + } - case 'K': - { - if(!ssl_ok) - { - send_nossl_support(ctl, ctl_buf); - break; - } - ssl_new_keys(ctl, ctl_buf); - break; - } - case 'I': - init_prng(ctl, ctl_buf); - break; - case 'S': - { - process_stats(ctl, ctl_buf); - break; - } - case 'Y': - { - change_connid(ctl, ctl_buf); - break; - } + case 'K': { + if(!ssl_ok) { + send_nossl_support(ctl, ctl_buf); + break; + } + ssl_new_keys(ctl, ctl_buf); + break; + } + case 'I': + init_prng(ctl, ctl_buf); + break; + case 'S': { + process_stats(ctl, ctl_buf); + break; + } + case 'Y': { + change_connid(ctl, ctl_buf); + break; + } #ifdef HAVE_LIBZ - case 'Z': - { - if (ctl_buf->nfds != 2 || ctl_buf->buflen < 6) - { - cleanup_bad_message(ctl, ctl_buf); - break; - } + case 'Z': { + if (ctl_buf->nfds != 2 || ctl_buf->buflen < 6) { + cleanup_bad_message(ctl, ctl_buf); + break; + } - /* just zlib only */ - zlib_process(ctl, ctl_buf); - break; - } + /* just zlib only */ + zlib_process(ctl, ctl_buf); + break; + } #else - - case 'Z': - send_nozlib_support(ctl, ctl_buf); - break; + + case 'Z': + send_nozlib_support(ctl, ctl_buf); + break; #endif - default: - break; - /* Log unknown commands */ - } - rb_dlinkDelete(ptr, &ctl->readq); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } + default: + break; + /* Log unknown commands */ + } + rb_dlinkDelete(ptr, &ctl->readq); + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + } } @@ -1065,159 +1005,147 @@ mod_process_cmd_recv(mod_ctl_t * ctl) static void mod_read_ctl(rb_fde_t *F, void *data) { - mod_ctl_buf_t *ctl_buf; - mod_ctl_t *ctl = data; - int retlen; - int i; + mod_ctl_buf_t *ctl_buf; + mod_ctl_t *ctl = data; + int retlen; + int i; - do - { - ctl_buf = rb_malloc(sizeof(mod_ctl_buf_t)); - ctl_buf->buf = rb_malloc(READBUF_SIZE); - ctl_buf->buflen = READBUF_SIZE; - retlen = rb_recv_fd_buf(ctl->F, ctl_buf->buf, ctl_buf->buflen, ctl_buf->F, - MAXPASSFD); - if(retlen <= 0) - { - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } - else - { - ctl_buf->buflen = retlen; - rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq); - for (i = 0; i < MAXPASSFD && ctl_buf->F[i] != NULL; i++) - ; - ctl_buf->nfds = i; - } - } - while(retlen > 0); + do { + ctl_buf = rb_malloc(sizeof(mod_ctl_buf_t)); + ctl_buf->buf = rb_malloc(READBUF_SIZE); + ctl_buf->buflen = READBUF_SIZE; + retlen = rb_recv_fd_buf(ctl->F, ctl_buf->buf, ctl_buf->buflen, ctl_buf->F, + MAXPASSFD); + if(retlen <= 0) { + rb_free(ctl_buf->buf); + rb_free(ctl_buf); + } else { + ctl_buf->buflen = retlen; + rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq); + for (i = 0; i < MAXPASSFD && ctl_buf->F[i] != NULL; i++) + ; + ctl_buf->nfds = i; + } + } while(retlen > 0); - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - exit(0); + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) + exit(0); - mod_process_cmd_recv(ctl); - rb_setselect(ctl->F, RB_SELECT_READ, mod_read_ctl, ctl); + mod_process_cmd_recv(ctl); + 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; + 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); + 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(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); + } + 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) { - int retlen; - while((retlen = rb_read(F, inbuf, sizeof(inbuf))) > 0) - { - ;; /* we don't do anything with the pipe really, just care if the other process dies.. */ - } - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - exit(0); - rb_setselect(F, RB_SELECT_READ, read_pipe_ctl, NULL); + int retlen; + while((retlen = rb_read(F, inbuf, sizeof(inbuf))) > 0) { + ;; /* we don't do anything with the pipe really, just care if the other process dies.. */ + } + if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) + exit(0); + rb_setselect(F, RB_SELECT_READ, read_pipe_ctl, NULL); } int main(int argc, char **argv) { - const char *s_ctlfd, *s_pipe, *s_pid; - int ctlfd, pipefd, x, maxfd; - maxfd = maxconn(); + const char *s_ctlfd, *s_pipe, *s_pid; + int ctlfd, pipefd, x, maxfd; + maxfd = maxconn(); - s_ctlfd = getenv("CTL_FD"); - s_pipe = getenv("CTL_PIPE"); - s_pid = getenv("CTL_PPID"); + s_ctlfd = getenv("CTL_FD"); + s_pipe = getenv("CTL_PIPE"); + s_pid = getenv("CTL_PPID"); - 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"); - fprintf(stderr, - "You get an Id tag for this: $Id$\n"); - fprintf(stderr, "Have a nice life\n"); - exit(1); - } + 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"); + fprintf(stderr, + "You get an Id tag for this: $Id$\n"); + fprintf(stderr, "Have a nice life\n"); + exit(1); + } - ctlfd = atoi(s_ctlfd); - pipefd = atoi(s_pipe); - ppid = atoi(s_pid); - x = 0; + ctlfd = atoi(s_ctlfd); + pipefd = atoi(s_pipe); + ppid = atoi(s_pid); + x = 0; #ifndef _WIN32 - for(x = 0; x < maxfd; x++) - { - if(x != ctlfd && x != pipefd && x > 2) - close(x); - } - x = open("/dev/null", O_RDWR); + for(x = 0; x < maxfd; x++) { + if(x != ctlfd && x != pipefd && x > 2) + close(x); + } + x = open("/dev/null", O_RDWR); - if(x >= 0) - { - if(ctlfd != 0 && pipefd != 0) - dup2(x, 0); - if(ctlfd != 1 && pipefd != 1) - dup2(x, 1); - if(ctlfd != 2 && pipefd != 2) - dup2(x, 2); - if(x > 2) - close(x); - } + if(x >= 0) { + if(ctlfd != 0 && pipefd != 0) + dup2(x, 0); + if(ctlfd != 1 && pipefd != 1) + dup2(x, 1); + if(ctlfd != 2 && pipefd != 2) + dup2(x, 2); + if(x > 2) + close(x); + } #endif - setup_signals(); - rb_lib_init(NULL, NULL, NULL, 0, maxfd, 1024, 4096); - rb_init_rawbuffers(1024); - 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"); - rb_set_nb(mod_ctl->F); - rb_set_nb(mod_ctl->F_pipe); - rb_event_addish("clean_dead_conns", clean_dead_conns, NULL, 10); - 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) - { - /* this is really useless... */ - send_i_am_useless(mod_ctl); - /* sleep until the ircd kills us */ - rb_sleep(2 << 30, 0); - exit(1); - } + setup_signals(); + rb_lib_init(NULL, NULL, NULL, 0, maxfd, 1024, 4096); + rb_init_rawbuffers(1024); + 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"); + rb_set_nb(mod_ctl->F); + rb_set_nb(mod_ctl->F_pipe); + rb_event_addish("clean_dead_conns", clean_dead_conns, NULL, 10); + 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) { + /* this is really useless... */ + send_i_am_useless(mod_ctl); + /* sleep until the ircd kills us */ + rb_sleep(2 << 30, 0); + exit(1); + } - if(!zlib_ok) - send_nozlib_support(mod_ctl, NULL); - if(!ssl_ok) - send_nossl_support(mod_ctl, NULL); - rb_lib_loop(0); - return 0; + if(!zlib_ok) + send_nozlib_support(mod_ctl, NULL); + if(!ssl_ok) + send_nossl_support(mod_ctl, NULL); + rb_lib_loop(0); + return 0; } @@ -1225,7 +1153,7 @@ main(int argc, char **argv) static void dummy_handler(int sig) { - return; + return; } #endif @@ -1233,27 +1161,27 @@ static void setup_signals() { #ifndef _WIN32 - struct sigaction act; + struct sigaction act; - act.sa_flags = 0; - act.sa_handler = SIG_IGN; - sigemptyset(&act.sa_mask); - sigaddset(&act.sa_mask, SIGPIPE); - sigaddset(&act.sa_mask, SIGALRM); + act.sa_flags = 0; + act.sa_handler = SIG_IGN; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGPIPE); + sigaddset(&act.sa_mask, SIGALRM); #ifdef SIGTRAP - sigaddset(&act.sa_mask, SIGTRAP); + sigaddset(&act.sa_mask, SIGTRAP); #endif #ifdef SIGWINCH - sigaddset(&act.sa_mask, SIGWINCH); - sigaction(SIGWINCH, &act, 0); + sigaddset(&act.sa_mask, SIGWINCH); + sigaction(SIGWINCH, &act, 0); #endif - sigaction(SIGPIPE, &act, 0); + sigaction(SIGPIPE, &act, 0); #ifdef SIGTRAP - sigaction(SIGTRAP, &act, 0); + sigaction(SIGTRAP, &act, 0); #endif - act.sa_handler = dummy_handler; - sigaction(SIGALRM, &act, 0); + act.sa_handler = dummy_handler; + sigaction(SIGALRM, &act, 0); #endif }