Format the whole code using clang-format

This commit is contained in:
Pierre-Louis Bonicoli 2022-03-10 13:52:03 +01:00
parent 8d9658ca43
commit f2fd1824ca
Signed by: pilou
GPG Key ID: 06914C4A5EDAA6DD
17 changed files with 1683 additions and 1467 deletions

446
src/bip.c
View File

@ -201,8 +201,7 @@ try_again:
unlink(longpath);
free(longpath);
return fd;
pid_is_there:
{
pid_is_there : {
pid_t pid;
size_t p;
if (fd != -1)
@ -212,7 +211,8 @@ pid_is_there:
fclose(f);
pid = (pid_t)p;
if (c != 1 || p == 0) {
mylog(LOG_INFO, "pid file found but invalid "
mylog(LOG_INFO,
"pid file found but invalid "
"data inside. Continuing...\n");
if (unlink(conf_pid_file)) {
fatal("Cannot delete pid file '%s', "
@ -235,10 +235,11 @@ pid_is_there:
}
if (pid)
mylog(LOG_INFO, "pid file found (pid %ld).", pid);
mylog(LOG_FATAL, "Another instance of bip is certainly running.");
mylog(LOG_FATAL,
"Another instance of bip is certainly running.");
mylog(LOG_FATAL, "If you are sure this is not the case remove"
" %s.", conf_pid_file);
"If you are sure this is not the case remove"
" %s.",
conf_pid_file);
exit(2);
}
free(longpath);
@ -255,14 +256,16 @@ void reload_config(int i)
void rlimit_cpu_reached(int i)
{
(void)i;
mylog(LOG_WARN, "This process has reached the CPU time usage limit. "
mylog(LOG_WARN,
"This process has reached the CPU time usage limit. "
"It means bip will be killed by the Operating System soon.");
}
void rlimit_bigfile_reached(int i)
{
(void)i;
mylog(LOG_WARN, "A file has reached the max size this process is "
mylog(LOG_WARN,
"A file has reached the max size this process is "
"allowed to create. The file will not be written correctly, "
"an error message should follow. This is not fatal.");
}
@ -275,7 +278,8 @@ void bad_quit(int i)
struct link *l = list_it_item(&it);
struct link_server *ls = l->l_server;
if (ls && l->s_state == IRCS_CONNECTED) {
write_line_fast(CONN(ls), "QUIT :Coyote finally "
write_line_fast(CONN(ls),
"QUIT :Coyote finally "
"caught me\r\n");
}
}
@ -323,12 +327,14 @@ static int add_network(bip_t *bip, list_t *data)
#endif
case LEX_SERVER:
if (n->serverc < 0) {
conf_die(bip, "internal error in network statement");
conf_die(bip,
"internal error in network statement");
return 0;
}
n->serverv = bip_realloc(n->serverv,
(unsigned int)(n->serverc + 1) * sizeof(struct server));
n->serverv = bip_realloc(
n->serverv, (unsigned int)(n->serverc + 1)
* sizeof(struct server));
n->serverc++;
memset(&n->serverv[n->serverc - 1], 0,
sizeof(struct server));
@ -414,7 +420,8 @@ void adm_bip_addconn(bip_t *bip, struct link_client *ic, const char *conn_name,
#endif
#define SCOPY(member) l->member = (LINK(ic)->member ? bip_strdup(LINK(ic)->member) : NULL)
#define SCOPY(member) \
l->member = (LINK(ic)->member ? bip_strdup(LINK(ic)->member) : NULL)
#define ICOPY(member) l->member = LINK(ic)->member
SCOPY(connect_nick);
@ -503,7 +510,8 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data)
} else if (strcmp(t->pdata, "EXTERNAL") == 0) {
l->sasl_mechanism = SASL_AUTH_EXTERNAL;
} else {
conf_die(bip, "Unsupported SASL mechanism %s.", t->pdata);
conf_die(bip, "Unsupported SASL mechanism %s.",
t->pdata);
return 0;
}
break;
@ -538,7 +546,9 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data)
ci->backlog = t2->ndata;
break;
default:
conf_die(bip, "Unknown keyword in channel block (%d)",
conf_die(
bip,
"Unknown keyword in channel block (%d)",
t2->type);
return 0;
}
@ -584,12 +594,14 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data)
break;
#else
case LEX_SSL_CHECK_MODE:
mylog(LOG_WARN, "Found SSL option whereas bip is "
mylog(LOG_WARN,
"Found SSL option whereas bip is "
"not built with SSL support.");
break;
#endif
default:
conf_die(bip, "Unknown keyword in connection "
conf_die(bip,
"Unknown keyword in connection "
"statement");
return 0;
}
@ -611,7 +623,8 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data)
}
if (!l->username) {
if (!user->default_username) {
conf_die(bip, "No username set and no default "
conf_die(bip,
"No username set and no default "
"username.");
return 0;
}
@ -619,7 +632,8 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data)
}
if (!l->realname) {
if (!user->default_realname) {
conf_die(bip, "No realname set and no default "
conf_die(bip,
"No realname set and no default "
"realname.");
return 0;
}
@ -636,8 +650,11 @@ static int add_connection(bip_t *bip, struct bipuser *user, list_t *data)
return 0;
}
if (l->sasl_mechanism == SASL_AUTH_PLAIN && (!l->sasl_username || !l->sasl_password)) {
conf_die(bip, "SASL mechanism PLAIN requires username and password.");
if (l->sasl_mechanism == SASL_AUTH_PLAIN
&& (!l->sasl_username || !l->sasl_password)) {
conf_die(
bip,
"SASL mechanism PLAIN requires username and password.");
return 0;
}
if (l->sasl_username && !l->sasl_mechanism)
@ -673,7 +690,8 @@ static int get_tuple_nvalue(list_t *tuple_l, int lex)
return -1;
}
enum BLTimestamp lex_backlog_timestamp(char * tdata) {
enum BLTimestamp lex_backlog_timestamp(char *tdata)
{
if (strcmp(tdata, "time") == 0) {
return BLTSTime;
} else if (strcmp(tdata, "datetime") == 0) {
@ -803,7 +821,8 @@ static int add_user(bip_t *bip, list_t *data, struct historical_directives *hds)
case LEX_SSL_CLIENT_CERTFILE:
case LEX_SSL_CHECK_MODE:
case LEX_SSL_CHECK_STORE:
mylog(LOG_WARN, "Found SSL option whereas bip is "
mylog(LOG_WARN,
"Found SSL option whereas bip is "
"not built with SSL support.");
break;
#endif
@ -843,17 +862,16 @@ static int validate_config(bip_t *bip)
for (hash_it_init(&bip->users, &it); (user = hash_it_item(&it));
hash_it_next(&it)) {
for (hash_it_init(&user->connections, &sit);
(link = hash_it_item(&sit));
hash_it_next(&sit)) {
if (!user->default_nick || !user->default_username ||
!user->default_realname) {
if ((!link->username &&
!user->default_username) ||
(!link->connect_nick &&
!user->default_nick) ||
(!link->realname &&
!user->default_realname)) {
conf_die(bip, "user %s, "
(link = hash_it_item(&sit)); hash_it_next(&sit)) {
if (!user->default_nick || !user->default_username
|| !user->default_realname) {
if ((!link->username && !user->default_username)
|| (!link->connect_nick
&& !user->default_nick)
|| (!link->realname
&& !user->default_realname)) {
conf_die(bip,
"user %s, "
"connection %s: you must defin"
"e nick, user and realname.",
user->name, link->name);
@ -864,14 +882,14 @@ static int validate_config(bip_t *bip)
}
for (hash_it_init(&link->chan_infos, &cit);
(ci = hash_it_item(&cit));
hash_it_next(&cit)) {
(ci = hash_it_item(&cit)); hash_it_next(&cit)) {
if (!ci->name) {
conf_die(bip, "user %s, "
conf_die(bip,
"user %s, "
"connection "
"%s: channel must have"
"a name.", user->name,
link->name);
"a name.",
user->name, link->name);
r = 0;
continue;
}
@ -879,7 +897,8 @@ static int validate_config(bip_t *bip)
}
if (user->backlog && !conf_log && user->backlog_lines == 0) {
conf_die(bip, "If conf_log = false, you must set "
conf_die(bip,
"If conf_log = false, you must set "
"backlog_"
"lines to a non-nul value for each user with"
"backlog = true. Faulty user is %s",
@ -896,7 +915,8 @@ static int validate_config(bip_t *bip)
hash_it_next(&it);
if (hash_it_item(&it)) {
// hash contains at least two elements
mylog(LOG_WARN, "log_format does not contain %%u, all users'"
mylog(LOG_WARN,
"log_format does not contain %%u, all users'"
" logs will be mixed !");
}
}
@ -979,7 +999,8 @@ int fireup(bip_t *bip, FILE *conf)
return 0;
}
#define SET_HV(d, n) do {\
#define SET_HV(d, n) \
do { \
int __gtv = get_tuple_nvalue(root_list, LEX_##n); \
if (__gtv != -1) \
d = __gtv; \
@ -1045,7 +1066,8 @@ int fireup(bip_t *bip, FILE *conf)
case LEX_CSS_CIPHERS:
case LEX_CSS_PEM:
case LEX_DH_PARAM:
mylog(LOG_WARN, "Found SSL option whereas bip is "
mylog(LOG_WARN,
"Found SSL option whereas bip is "
"not built with SSL support.");
break;
#endif
@ -1129,7 +1151,8 @@ void check_rlimits(void)
strerror(errno));
} else {
if (lt.rlim_max != RLIM_INFINITY) {
mylog(LOG_WARN, "virtual memory rlimit active, "
mylog(LOG_WARN,
"virtual memory rlimit active, "
"bip may be KILLED by the system");
cklim = 1;
}
@ -1142,7 +1165,8 @@ void check_rlimits(void)
strerror(errno));
} else {
if (lt.rlim_max != RLIM_INFINITY) {
mylog(LOG_WARN, "CPU rlimit active, bip may "
mylog(LOG_WARN,
"CPU rlimit active, bip may "
"be OFTEN KILLED by the system");
cklim = 1;
}
@ -1154,9 +1178,11 @@ void check_rlimits(void)
strerror(errno));
} else {
if (lt.rlim_max != RLIM_INFINITY) {
mylog(LOG_WARN, "FSIZE rlimit active, bip will "
mylog(LOG_WARN,
"FSIZE rlimit active, bip will "
"fail to create files of size greater than "
"%d bytes.", (int)lt.rlim_max);
"%d bytes.",
(int)lt.rlim_max);
cklim = 1;
}
}
@ -1167,9 +1193,11 @@ void check_rlimits(void)
strerror(errno));
} else {
if (lt.rlim_max != RLIM_INFINITY && lt.rlim_max < 256) {
mylog(LOG_WARN, "opened files count rlimit "
mylog(LOG_WARN,
"opened files count rlimit "
"active, bip will not be allowed to open more "
"than %d files at a time", (int)lt.rlim_max);
"than %d files at a time",
(int)lt.rlim_max);
cklim = 1;
}
}
@ -1180,7 +1208,8 @@ void check_rlimits(void)
strerror(errno));
} else {
if (lt.rlim_max != RLIM_INFINITY) {
mylog(LOG_WARN, "stack rlimit active, "
mylog(LOG_WARN,
"stack rlimit active, "
"bip may be KILLED by the system");
cklim = 1;
}
@ -1221,62 +1250,77 @@ void adm_print_connection(struct link_client *ic, struct link *lnk,
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcat_fit(&remaining, bufpos, " follow_nick");
bufpos = bip_strcat_fit(&remaining, bufpos,
" follow_nick");
if (!bufpos)
goto limittoolow;
}
}
if (lnk->ignore_first_nick) {
bufpos = bip_strcat_fit(&remaining, bufpos, " ignore_first_nick");
bufpos = bip_strcat_fit(&remaining, bufpos,
" ignore_first_nick");
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcat_fit(&remaining, bufpos, " ignore_first_nick");
bufpos = bip_strcat_fit(&remaining, bufpos,
" ignore_first_nick");
if (!bufpos)
goto limittoolow;
}
}
if (lnk->away_nick) {
bufpos = bip_strcatf_fit(&remaining, bufpos, " away_nick=%s", lnk->away_nick);
bufpos = bip_strcatf_fit(&remaining, bufpos, " away_nick=%s",
lnk->away_nick);
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcatf_fit(&remaining, bufpos, " away_nick=%s", lnk->away_nick);
bufpos = bip_strcatf_fit(&remaining, bufpos,
" away_nick=%s",
lnk->away_nick);
if (!bufpos)
goto limittoolow;
}
}
if (lnk->no_client_away_msg) {
bufpos = bip_strcatf_fit(&remaining, bufpos, " no_client_away_msg=%s", lnk->no_client_away_msg);
bufpos = bip_strcatf_fit(&remaining, bufpos,
" no_client_away_msg=%s",
lnk->no_client_away_msg);
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcatf_fit(&remaining, bufpos, " no_client_away_msg=%s", lnk->no_client_away_msg);
bufpos = bip_strcatf_fit(&remaining, bufpos,
" no_client_away_msg=%s",
lnk->no_client_away_msg);
if (!bufpos)
goto limittoolow;
}
}
if (lnk->vhost) {
bufpos = bip_strcatf_fit(&remaining, bufpos, " vhost=%s", lnk->vhost);
bufpos = bip_strcatf_fit(&remaining, bufpos, " vhost=%s",
lnk->vhost);
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcatf_fit(&remaining, bufpos, " vhost=%s", lnk->vhost);
bufpos = bip_strcatf_fit(&remaining, bufpos,
" vhost=%s", lnk->vhost);
if (!bufpos)
goto limittoolow;
}
}
if (lnk->bind_port) {
bufpos = bip_strcatf_fit(&remaining, bufpos, " bind_port=%s", lnk->bind_port);
bufpos = bip_strcatf_fit(&remaining, bufpos, " bind_port=%s",
lnk->bind_port);
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcatf_fit(&remaining, bufpos, " bind_port=%s", lnk->bind_port);
bufpos = bip_strcatf_fit(&remaining, bufpos,
" bind_port=%s",
lnk->bind_port);
if (!bufpos)
goto limittoolow;
}
@ -1311,7 +1355,8 @@ void adm_print_connection(struct link_client *ic, struct link *lnk,
// TODO : check channels struct
bufpos = bip_strcat_fit(&remaining, bufpos, " Channels (* with key, ` no backlog)");
bufpos = bip_strcat_fit(&remaining, bufpos,
" Channels (* with key, ` no backlog)");
if (!bufpos)
goto limittoolow;
@ -1319,8 +1364,8 @@ void adm_print_connection(struct link_client *ic, struct link *lnk,
hash_it_next(&lit)) {
struct chan_info *ch = hash_it_item(&lit);
bufpos = bip_strcatf_fit(&remaining, bufpos, "%s%s%s",
ch->name, (ch->key ? "*" : ""),
bufpos = bip_strcatf_fit(&remaining, bufpos, "%s%s%s", ch->name,
(ch->key ? "*" : ""),
(ch->backlog ? "" : "`"));
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
@ -1366,7 +1411,8 @@ void adm_print_connection(struct link_client *ic, struct link *lnk,
goto noroomstatus;
break;
case IRCS_RECONNECTING:
bufpos = bip_strcatf_fit(&remaining, bufpos,
bufpos = bip_strcatf_fit(
&remaining, bufpos,
"reconnecting... attempts: %d, last: %s",
lnk->s_conn_attempt,
hrtime(lnk->last_connection_attempt));
@ -1374,7 +1420,8 @@ void adm_print_connection(struct link_client *ic, struct link *lnk,
goto noroomstatus;
break;
case IRCS_TIMER_WAIT:
bufpos = bip_strcatf_fit(&remaining, bufpos,
bufpos = bip_strcatf_fit(
&remaining, bufpos,
"waiting to reconnect, attempts: %d, last: %s",
lnk->s_conn_attempt,
hrtime(lnk->last_connection_attempt));
@ -1396,8 +1443,10 @@ noroomstatus:
bip_notify(ic, "%stoo long to print", buf);
return;
limittoolow:
bip_notify(ic, "cannot print connection, LINE_SIZE_LIM(%d) "
"is too low (please recompile)", LINE_SIZE_LIM);
bip_notify(ic,
"cannot print connection, LINE_SIZE_LIM(%d) "
"is too low (please recompile)",
LINE_SIZE_LIM);
return;
}
@ -1442,16 +1491,18 @@ void adm_info_user(struct link_client *ic, const char *name)
return;
}
bip_notify(ic, "user: %s%s", u->name, (u->admin ? ", is bip admin" : ""));
bip_notify(ic, "user: %s%s", u->name,
(u->admin ? ", is bip admin" : ""));
#ifdef HAVE_LIBSSL
if (u->ssl_check_store) {
bip_notify(ic, "SSL check mode '%s', stored into '%s'",
checkmode2text(u->ssl_check_mode),
u->ssl_check_store);
}
else {
bip_notify(ic, "SSL check mode '%s', default or no certificate store",
} else {
bip_notify(
ic,
"SSL check mode '%s', default or no certificate store",
checkmode2text(u->ssl_check_mode));
}
if (u->ssl_client_certfile)
@ -1462,10 +1513,15 @@ void adm_info_user(struct link_client *ic, const char *name)
STRORNULL(u->default_nick), STRORNULL(u->default_username),
STRORNULL(u->default_realname));
if (u->backlog) {
bip_notify(ic, "Backlog enabled, lines: %d, timestamp: %s,"
" messages only: %s", u->backlog_lines,
u->backlog_timestamp == BLTSNone ? "none" :
(u->backlog_timestamp == BLTSTime ? "time" : "datetime"),
bip_notify(ic,
"Backlog enabled, lines: %d, timestamp: %s,"
" messages only: %s",
u->backlog_lines,
u->backlog_timestamp == BLTSNone
? "none"
: (u->backlog_timestamp == BLTSTime
? "time"
: "datetime"),
bool2text(u->bl_msg_only));
bip_notify(ic, "always backlog: %s, reset on talk: %s",
bool2text(u->always_backlog),
@ -1501,27 +1557,36 @@ void adm_list_users(struct link_client *ic)
if (first) {
first = 0;
} else {
bufpos = bip_strcat_fit(&remaining, bufpos, ",");
// if this is too long for a comma, print and prefix with spaces
bufpos =
bip_strcat_fit(&remaining, bufpos, ",");
// if this is too long for a comma, print and
// prefix with spaces
if (!bufpos) {
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcat_fit(&remaining, buf, " ");;
// this should not happen or LINE_SIZE_LIM is really low...
bufpos = bip_strcat_fit(&remaining, buf,
" ");
;
// this should not happen or
// LINE_SIZE_LIM is really low...
if (!bufpos)
goto limittoolow;
}
}
bufpos = bip_strcatf_fit(&remaining, bufpos, " %s", lnk->name);
bufpos = bip_strcatf_fit(&remaining, bufpos, " %s",
lnk->name);
if (!bufpos) {
// if this is too long, print and reset
buf[LINE_SIZE_LIM] = 0;
bip_notify(ic, "%s", buf);
remaining = LINE_SIZE_LIM;
bufpos = bip_strcat_fit(&remaining, buf, " ");;
// this should not happen or LINE_SIZE_LIM is really low...
bufpos = bip_strcat_fit(&remaining, buf,
" ");
;
// this should not happen or LINE_SIZE_LIM is
// really low...
if (!bufpos)
goto limittoolow;
} else {
@ -1537,8 +1602,10 @@ void adm_list_users(struct link_client *ic)
bip_notify(ic, "-- End of User list");
return;
limittoolow:
bip_notify(ic, "cannot print users, LINE_SIZE_LIM(%d) "
"is too low (please recompile)", LINE_SIZE_LIM);
bip_notify(ic,
"cannot print users, LINE_SIZE_LIM(%d) "
"is too low (please recompile)",
LINE_SIZE_LIM);
}
void adm_list_networks(struct link_client *ic)
@ -1556,17 +1623,18 @@ void adm_list_networks(struct link_client *ic)
#ifdef HAVE_LIBSSL
if (n->ssl) {
bufpos = bip_strcatf_fit(&remaining, bufpos, "- %s*:",
n->name);
bufpos = bip_strcatf_fit(&remaining, bufpos,
"- %s*:", n->name);
} else {
#endif
bufpos = bip_strcatf_fit(&remaining, bufpos, "- %s:",
n->name);
bufpos = bip_strcatf_fit(&remaining, bufpos,
"- %s:", n->name);
#ifdef HAVE_LIBSSL
}
#endif
// if we've reached max length, print name and reset
// honestly, this should not happen, but for the sake of cleanliness...
// honestly, this should not happen, but for the sake of
// cleanliness...
if (!bufpos) {
#ifdef HAVE_LIBSSL
if (n->ssl) {
@ -1647,8 +1715,8 @@ int ssl_check_trust(struct link_client *ic)
unsigned int fplen;
int i;
if(!LINK(ic)->untrusted_certs ||
sk_X509_num(LINK(ic)->untrusted_certs) <= 0) {
if (!LINK(ic)->untrusted_certs
|| sk_X509_num(LINK(ic)->untrusted_certs) <= 0) {
ic->allow_trust = 0;
return 0;
}
@ -1662,8 +1730,8 @@ int ssl_check_trust(struct link_client *ic)
X509_digest(trustcert, EVP_md5(), fp, &fplen);
for (i = 0; i < (int)fplen; i++)
sprintf(fpstr + 17 + (i * 3), "%02X%c",
fp[i], (i == (int)fplen - 1) ? '\0' : ':');
sprintf(fpstr + 17 + (i * 3), "%02X%c", fp[i],
(i == (int)fplen - 1) ? '\0' : ':');
WRITE_LINE2(CONN(ic), P_SERV, "NOTICE", "TrustEm",
"This server SSL certificate was not "
@ -1725,19 +1793,22 @@ int adm_trust(struct link_client *ic, struct line *line)
BIO *bio = BIO_new_file(LINK(ic)->user->ssl_check_store, "a+");
X509 *trustcert = sk_X509_shift(LINK(ic)->untrusted_certs);
if(!bio || !trustcert ||
PEM_write_bio_X509(bio, trustcert) <= 0)
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
if (!bio || !trustcert
|| PEM_write_bio_X509(bio, trustcert) <= 0)
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":==== Error while trusting test!\r\n");
else
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":==== Certificate now trusted.\r\n");
BIO_free_all(bio);
X509_free(trustcert);
} else if (irc_line_elem_case_equals(line, 2, "NO")) {
/* NO, discard the cert! */
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":==== Certificate discarded.\r\n");
X509_free(sk_X509_shift(LINK(ic)->untrusted_certs));
@ -1745,10 +1816,12 @@ int adm_trust(struct link_client *ic, struct line *line)
return ERR_PROTOCOL;
if (!ssl_check_trust(ic)) {
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":No more certificates waiting awaiting "
"user trust, thanks!\r\n");
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":If the certificate is trusted, bip should "
"be able to connect to the server on the "
"next retry. Please wait a while and try "
@ -1773,8 +1846,9 @@ void _bip_notify(struct link_client *ic, char *fmt, va_list ap)
vsnprintf(str, (size_t)4095, fmt, ap);
str[4095] = 0;
WRITE_LINE2(CONN(ic), P_IRCMASK, (LINK(ic)->user->bip_use_notice ?
"NOTICE" : "PRIVMSG"), nick, str);
WRITE_LINE2(CONN(ic), P_IRCMASK,
(LINK(ic)->user->bip_use_notice ? "NOTICE" : "PRIVMSG"),
nick, str);
}
void bip_notify(struct link_client *ic, char *fmt, ...)
@ -1839,8 +1913,7 @@ void set_on_connect_send(struct link_client *ic, char *val)
}
#define ON_CONNECT_MAX_STRSIZE 1024
void adm_on_connect_send(struct link_client *ic, struct line *line,
int privmsg)
void adm_on_connect_send(struct link_client *ic, struct line *line, int privmsg)
{
size_t remaining = ON_CONNECT_MAX_STRSIZE;
char buf[ON_CONNECT_MAX_STRSIZE];
@ -1853,7 +1926,8 @@ void adm_on_connect_send(struct link_client *ic, struct line *line,
}
if (!irc_line_includes(line, 2)) {
mylog(LOG_DEBUG, "[%s] not enough parameters on /BIP on_connect_send",
mylog(LOG_DEBUG,
"[%s] not enough parameters on /BIP on_connect_send",
LINK(ic)->user->name);
return;
}
@ -1870,7 +1944,9 @@ void adm_on_connect_send(struct link_client *ic, struct line *line,
mylog(LOG_DEBUG, "[%s] processed item %d, remaining %ld, %s",
LINK(ic)->user->name, i, remaining, buf);
if (!bufpos) {
bip_notify(ic, "on connect send string too big, not changing.");
bip_notify(
ic,
"on connect send string too big, not changing.");
return;
}
}
@ -1899,58 +1975,75 @@ void adm_bip_help(struct link_client *ic, int admin, const char *subhelp)
{
if (subhelp == NULL) {
if (admin) {
bip_notify(ic, "/BIP RELOAD # Re-read bip "
bip_notify(ic,
"/BIP RELOAD # Re-read bip "
"configuration and apply changes.");
bip_notify(ic, "/BIP INFO user <username> "
bip_notify(ic,
"/BIP INFO user <username> "
"# show a user's configuration");
bip_notify(ic, "/BIP LIST networks|users|connections|"
bip_notify(ic,
"/BIP LIST networks|users|connections|"
"all_links|all_connections");
bip_notify(ic, "/BIP ADD_CONN <connection name> "
bip_notify(ic,
"/BIP ADD_CONN <connection name> "
"<network>");
bip_notify(ic, "/BIP DEL_CONN <connection name>");
} else {
bip_notify(ic, "/BIP LIST networks|connections");
}
bip_notify(ic, "/BIP JUMP # jump to next server (in same "
bip_notify(ic,
"/BIP JUMP # jump to next server (in same "
"network)");
bip_notify(ic, "/BIP BLRESET [channel|query]# reset backlog "
bip_notify(ic,
"/BIP BLRESET [channel|query]# reset backlog "
"(this connection only). Add -q flag and the "
"operation is quiet. You can specify a channel "
"or a nick to reset only this channel/query.");
bip_notify(ic, "/BIP HELP [subhelp] # show this help...");
bip_notify(ic, "## Temporary changes for this connection:");
bip_notify(ic, "/BIP FOLLOW_NICK|IGNORE_FIRST_NICK TRUE|FALSE");
bip_notify(ic, "/BIP ON_CONNECT_SEND <str> # Adds a string to "
bip_notify(ic,
"/BIP ON_CONNECT_SEND <str> # Adds a string to "
"send on connect");
bip_notify(ic, "/BIP ON_CONNECT_SEND # Clears on_connect_send");
bip_notify(ic, "/BIP AWAY_NICK <nick> # Set away nick");
bip_notify(ic, "/BIP AWAY_NICK # clear away nick");
bip_notify(ic, "/BIP BACKLOG [n] # backlog text of the n last "
bip_notify(ic,
"/BIP BACKLOG [n] # backlog text of the n last "
"hours");
} else if (admin && strcasecmp(subhelp, "RELOAD") == 0) {
bip_notify(ic, "/BIP RELOAD (admin only) :");
bip_notify(ic, " Reloads bip configuration file and apply "
bip_notify(ic,
" Reloads bip configuration file and apply "
"changes.");
bip_notify(ic, " Please note that changes to 'user' or "
bip_notify(ic,
" Please note that changes to 'user' or "
"'realname' will not be applied without a JUMP.");
} else if (admin && strcasecmp(subhelp, "INFO") == 0) {
bip_notify(ic, "/BIP INFO USER <user> (admin only) :");
bip_notify(ic, " Show <user>'s current configuration.");
bip_notify(ic, " That means it may be different from the "
bip_notify(ic,
" That means it may be different from the "
"configuration stored in bip.conf");
} else if (admin && strcasecmp(subhelp, "ADD_CONN") == 0) {
bip_notify(ic, "/BIP ADD_CONN <connection name> <network> "
bip_notify(ic,
"/BIP ADD_CONN <connection name> <network> "
"(admin only) :");
bip_notify(ic, " Add a connection named <connection name> to "
bip_notify(ic,
" Add a connection named <connection name> to "
"the network <network> to your connection list");
bip_notify(ic, " <network> should already exist in bip's "
bip_notify(ic,
" <network> should already exist in bip's "
"configuration.");
} else if (admin && strcasecmp(subhelp, "DEL_CONN") == 0) {
bip_notify(ic, "/BIP DEL_CONN <connection name> (admin only) "
bip_notify(ic,
"/BIP DEL_CONN <connection name> (admin only) "
":");
bip_notify(ic, " Remove the connection named <connection "
bip_notify(ic,
" Remove the connection named <connection "
"name> from your connection list.");
bip_notify(ic, " Removing a connection will cause "
bip_notify(ic,
" Removing a connection will cause "
"its disconnection.");
} else if (strcasecmp(subhelp, "JUMP") == 0) {
bip_notify(ic, "/BIP JUMP :");
@ -1960,46 +2053,61 @@ void adm_bip_help(struct link_client *ic, int admin, const char *subhelp)
bip_notify(ic, " Reset backlog on this network.");
} else if (strcasecmp(subhelp, "FOLLOW_NICK") == 0) {
bip_notify(ic, "/BIP FOLLOW_NICK TRUE|FALSE :");
bip_notify(ic, " Change the value of the follow_nick option "
bip_notify(ic,
" Change the value of the follow_nick option "
"for this connection.");
bip_notify(ic, " If set to true, when you change nick, "
bip_notify(ic,
" If set to true, when you change nick, "
"BIP stores the new nickname as the new default "
"nickname value.");
bip_notify(ic, " Thus, if you are disconnected from the "
bip_notify(ic,
" Thus, if you are disconnected from the "
"server, BIP will restore the correct nickname.");
} else if (strcasecmp(subhelp, "IGNORE_FIRST_NICK") == 0) {
bip_notify(ic, "/BIP IGNORE_FIRST_NICK TRUE|FALSE :");
bip_notify(ic, " Change the value of the ignore_first_nick "
bip_notify(ic,
" Change the value of the ignore_first_nick "
"option for this connection.");
bip_notify(ic, " If set to TRUE, BIP will ignore the nickname"
bip_notify(ic,
" If set to TRUE, BIP will ignore the nickname"
"sent by the client upon connect.");
bip_notify(ic, " Further nickname changes will be processed "
bip_notify(ic,
" Further nickname changes will be processed "
"as usual.");
} else if (strcasecmp(subhelp, "ON_CONNECT_SEND") == 0) {
bip_notify(ic, "/BIP ON_CONNECT_SEND [some text] :");
bip_notify(ic, " BIP will send the text as is to the server "
bip_notify(ic,
" BIP will send the text as is to the server "
"upon connection.");
bip_notify(ic, " You can call this command more than once.");
bip_notify(ic, " If [some text] is empty, this command will "
bip_notify(
ic,
" If [some text] is empty, this command will "
"remove any on_connect_send defined for this connection.");
} else if (strcasecmp(subhelp, "AWAY_NICK") == 0) {
bip_notify(ic, "/BIP AWAY_NICK [some_nick] :");
bip_notify(ic, " If [some_nick] is set, BIP will change "
bip_notify(
ic,
" If [some_nick] is set, BIP will change "
"nickname to [some_nick] if there are no more client "
"attached");
bip_notify(ic, " If [some_nick] is empty, this command will "
bip_notify(ic,
" If [some_nick] is empty, this command will "
"unset current connection's away_nick.");
} else if (strcasecmp(subhelp, "LIST") == 0) {
bip_notify(ic, "/BIP LIST <section> :");
bip_notify(ic, " List information from a these sections :");
bip_notify(ic, " - networks: list all available networks");
bip_notify(ic, " - connections: list all your configured "
bip_notify(ic,
" - connections: list all your configured "
"connections and their state.");
if (admin) {
bip_notify(ic, " - users: list all users (admin)");
bip_notify(ic, " - all_links: list all connected "
bip_notify(ic,
" - all_links: list all connected "
"sockets from and to BIP (admin)");
bip_notify(ic, " - all_connections: list all users' "
bip_notify(ic,
" - all_connections: list all users' "
"configured connections (admin)");
}
} else {
@ -2069,37 +2177,47 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
return OK_FORGET;
}
if (admin && strcasecmp(irc_line_elem(line, privmsg + 2),
"users") == 0) {
if (admin
&& strcasecmp(irc_line_elem(line, privmsg + 2), "users")
== 0) {
adm_list_users(ic);
} else if (strcasecmp(irc_line_elem(line, privmsg + 2),
"networks") == 0) {
"networks")
== 0) {
adm_list_networks(ic);
} else if (strcasecmp(irc_line_elem(line, privmsg + 2),
"connections") == 0) {
"connections")
== 0) {
adm_list_connections(ic, NULL);
} else if (admin && strcasecmp(irc_line_elem(line, privmsg + 2),
"all_connections") == 0) {
} else if (admin
&& strcasecmp(irc_line_elem(line, privmsg + 2),
"all_connections")
== 0) {
adm_list_all_connections(ic);
} else if (admin && strcasecmp(irc_line_elem(line, privmsg + 2),
"all_links") == 0) {
} else if (admin
&& strcasecmp(irc_line_elem(line, privmsg + 2),
"all_links")
== 0) {
adm_list_all_links(ic);
} else {
bip_notify(ic, "-- Invalid LIST request");
}
} else if (irc_line_elem_case_equals(line, privmsg + 1, "INFO")) {
if (!irc_line_includes(line, privmsg + 3)) {
bip_notify(ic, "-- INFO command needs at least two "
bip_notify(ic,
"-- INFO command needs at least two "
"arguments");
return OK_FORGET;
}
if (admin && irc_line_elem_case_equals(line, privmsg + 2, "user")) {
if (admin
&& irc_line_elem_case_equals(line, privmsg + 2, "user")) {
if (irc_line_count(line) == (privmsg + 4)) {
adm_info_user(ic,
irc_line_elem(line, privmsg + 3));
} else {
bip_notify(ic, "-- INFO USER command needs one"
bip_notify(ic,
"-- INFO USER command needs one"
" argument");
}
#if 0
@ -2119,15 +2237,16 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
if (irc_line_includes(line, privmsg + 2)) {
if (irc_line_elem_equals(line, privmsg + 2, "-q")) {
if (irc_line_includes(line, privmsg + 3)) {
log_reset_store(LINK(ic)->log,
log_reset_store(
LINK(ic)->log,
irc_line_elem(line,
privmsg + 3));
} else {
log_reset_all(LINK(ic)->log);
}
} else {
adm_blreset_store(ic, irc_line_elem(line,
privmsg + 2));
adm_blreset_store(
ic, irc_line_elem(line, privmsg + 2));
}
} else {
adm_blreset(ic);
@ -2139,9 +2258,11 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
adm_bip_help(ic, admin,
irc_line_elem(line, privmsg + 2));
else
bip_notify(ic,
bip_notify(
ic,
"-- HELP command needs at most one argument");
} else if (irc_line_elem_case_equals(line, privmsg + 1, "FOLLOW_NICK")) {
} else if (irc_line_elem_case_equals(line, privmsg + 1,
"FOLLOW_NICK")) {
if (irc_line_count(line) != privmsg + 3) {
bip_notify(ic,
"-- FOLLOW_NICK command needs one argument");
@ -2151,7 +2272,8 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
} else if (irc_line_elem_case_equals(line, privmsg + 1,
"IGNORE_FIRST_NICK")) {
if (irc_line_count(line) != privmsg + 3) {
bip_notify(ic, "-- IGNORE_FIRST_NICK "
bip_notify(ic,
"-- IGNORE_FIRST_NICK "
"command needs one argument");
return OK_FORGET;
}
@ -2163,7 +2285,8 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
} else if (irc_line_includes(line, privmsg + 2)) {
adm_on_connect_send(ic, line, privmsg);
} else {
bip_notify(ic, "-- ON_CONNECT_SEND command needs at "
bip_notify(ic,
"-- ON_CONNECT_SEND command needs at "
"least one argument");
}
} else if (irc_line_elem_case_equals(line, privmsg + 1, "AWAY_NICK")) {
@ -2172,7 +2295,8 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
} else if (irc_line_count(line) == privmsg + 3) {
adm_away_nick(ic, irc_line_elem(line, privmsg + 2));
} else {
bip_notify(ic, "-- AWAY_NICK command needs zero or one"
bip_notify(ic,
"-- AWAY_NICK command needs zero or one"
" argument");
}
} else if (irc_line_elem_case_equals(line, privmsg + 1, "BACKLOG")) {
@ -2184,17 +2308,20 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
} else {
bip_notify(ic, "-- BACKLOG takes 0 or one argument");
}
} else if (admin && irc_line_elem_case_equals(line, privmsg + 1,
} else if (admin
&& irc_line_elem_case_equals(line, privmsg + 1,
"ADD_CONN")) {
if (irc_line_count(line) != privmsg + 4) {
bip_notify(ic, "/BIP ADD_CONN <connection name> "
bip_notify(ic,
"/BIP ADD_CONN <connection name> "
"<network name>");
} else {
adm_bip_addconn(bip, ic,
irc_line_elem(line, privmsg + 2),
irc_line_elem(line, privmsg + 3));
}
} else if (admin && irc_line_elem_case_equals(line, privmsg + 1,
} else if (admin
&& irc_line_elem_case_equals(line, privmsg + 1,
"DEL_CONN")) {
if (irc_line_count(line) != privmsg + 3) {
bip_notify(ic, "/BIP DEL_CONN <connection name>");
@ -2235,4 +2362,3 @@ void free_conf(list_t *l)
}
free(l);
}

View File

@ -72,22 +72,23 @@ int do_pid_stuff(void);
static void usage(char *name)
{
printf(
"Usage: %s [-f config_file] [-h] [-n]\n"
printf("Usage: %s [-f config_file] [-h] [-n]\n"
" -f config_file: Use config_file as the configuration file\n"
" If no config file is given %s will try to open ~/.bip/" S_CONF "\n"
" If no config file is given %s will try to open ~/.bip/" S_CONF
"\n"
" -n: Don't daemonize, log in stderr\n"
" -s: Bip HOME, default parent directory for client certificate,\n"
" configuration, logs, pid, oidentd\n"
" -v: Print version and exit\n"
" -h: This help\n", name, name);
" -h: This help\n",
name, name);
exit(1);
}
static void version(void)
{
printf(
"Bip IRC Proxy - " PACKAGE_VERSION "\n"
printf("Bip IRC Proxy - " PACKAGE_VERSION
"\n"
"Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n"
"Distributed under the GNU General Public License Version 2\n");
}
@ -208,7 +209,8 @@ int main(int argc, char **argv)
char *home = NULL; /* oidentd path searching ignores conf_biphome */
home = getenv("HOME");
if (!home && !conf_biphome) {
conf_die(&bip, "no value for environment variable $HOME,"
conf_die(&bip,
"no value for environment variable $HOME,"
"use '-s' parameter");
return 0;
}
@ -220,16 +222,16 @@ int main(int argc, char **argv)
}
if (!bip.oidentdpath) {
bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1 +
strlen(OIDENTD_FILENAME) + 1);
bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1
+ strlen(OIDENTD_FILENAME) + 1);
strcpy(bip.oidentdpath, conf_biphome);
strcat(bip.oidentdpath, "/");
strcat(bip.oidentdpath, OIDENTD_FILENAME);
}
if (!confpath) {
confpath = bip_malloc(strlen(conf_biphome) + 1 +
strlen(S_CONF) + 1);
confpath = bip_malloc(strlen(conf_biphome) + 1 + strlen(S_CONF)
+ 1);
strcpy(confpath, conf_biphome);
strcat(confpath, "/");
strcat(confpath, S_CONF);
@ -245,16 +247,16 @@ int main(int argc, char **argv)
if (!conf_log_root) {
char *ap = "/logs";
conf_log_root = bip_malloc(strlen(conf_biphome) +
strlen(ap) + 1);
conf_log_root =
bip_malloc(strlen(conf_biphome) + strlen(ap) + 1);
strcpy(conf_log_root, conf_biphome);
strcat(conf_log_root, ap);
mylog(LOG_INFO, "Default log root: %s", conf_log_root);
}
if (!conf_pid_file) {
char *pid = "/bip.pid";
conf_pid_file = bip_malloc(strlen(conf_biphome) +
strlen(pid) + 1);
conf_pid_file =
bip_malloc(strlen(conf_biphome) + strlen(pid) + 1);
strcpy(conf_pid_file, conf_biphome);
strcat(conf_pid_file, pid);
mylog(LOG_INFO, "Default pid file: %s", conf_pid_file);
@ -266,17 +268,20 @@ int main(int argc, char **argv)
struct stat fs;
if (!conf_ssl_certfile) {
conf_ssl_certfile = default_path(conf_biphome, "bip.pem",
"SSL certificate");
conf_ssl_certfile = default_path(
conf_biphome, "bip.pem", "SSL certificate");
}
assert_path_exists(conf_ssl_certfile);
e = stat(conf_ssl_certfile, &fs);
if (e)
mylog(LOG_WARN, "Unable to check PEM file, stat(%s): "
"%s", conf_ssl_certfile, strerror(errno));
mylog(LOG_WARN,
"Unable to check PEM file, stat(%s): "
"%s",
conf_ssl_certfile, strerror(errno));
else if ((fs.st_mode & S_IROTH) | (fs.st_mode & S_IWOTH))
mylog(LOG_ERROR, "PEM file %s should not be world "
mylog(LOG_ERROR,
"PEM file %s should not be world "
"readable / writable. Please fix the modes.",
conf_ssl_certfile);

View File

@ -45,7 +45,8 @@ void readpass(char *buffer, int buflen)
bipmkpw_fatal("tcgetattr failed", strerror(errno));
memcpy(&tt, &ttback, sizeof(ttback));
// unsigned conversion from int to tcflag_t {aka unsigned int} changes value from -11 to 4294967285
// unsigned conversion from int to tcflag_t {aka unsigned int} changes
// value from -11 to 4294967285
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
tt.c_lflag &= ~(ICANON | ECHO);
@ -94,9 +95,9 @@ int main(void)
readpass(str, 256);
str[255] = 0;
// passing argument 1 of srand with different width due to prototype [-Werror=traditional-conversion]
// conversion from time_t {aka long int} to unsigned int may change value [-Werror=conversion]
// We don't care.
// passing argument 1 of srand with different width due to prototype
// [-Werror=traditional-conversion] conversion from time_t {aka long int} to
// unsigned int may change value [-Werror=conversion] We don't care.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtraditional-conversion"
#pragma GCC diagnostic ignored "-Wconversion"

View File

@ -43,8 +43,7 @@ static int connection_timedout(connection_t *cn);
static int socket_set_nonblock(int s);
static void connection_connected(connection_t *c);
struct connecting_data
{
struct connecting_data {
struct addrinfo *dst;
struct addrinfo *src;
struct addrinfo *cur;
@ -129,7 +128,8 @@ static void connect_trynext(connection_t *cn)
for (cur = cn->connecting_data->cur; cur; cur = cur->ai_next) {
if ((cn->handle = socket(cur->ai_family, cur->ai_socktype,
cur->ai_protocol)) < 0) {
cur->ai_protocol))
< 0) {
mylog(LOG_WARN, "socket() : %s", strerror(errno));
continue;
}
@ -203,7 +203,8 @@ static X509 *mySSL_get_cert(SSL *ssl)
}
cert = SSL_get_peer_certificate(ssl);
if (cert == NULL)
mylog(LOG_WARN, "mySSL_get_cert() SSL server supplied no "
mylog(LOG_WARN,
"mySSL_get_cert() SSL server supplied no "
"certificate !");
return cert;
}
@ -241,8 +242,7 @@ static int _write_socket_SSL(connection_t *cn, char* message)
|| err == SSL_ERROR_WANT_ACCEPT)
return WRITE_KEEP;
if (cn_is_connected(cn)) {
mylog(LOG_ERROR, "fd %d: Connection error",
cn->handle);
mylog(LOG_ERROR, "fd %d: Connection error", cn->handle);
cn->connected = CONN_ERROR;
}
return WRITE_ERROR;
@ -250,7 +250,8 @@ static int _write_socket_SSL(connection_t *cn, char* message)
if (count != (int)size) {
/* abnormal : openssl keeps writing until message is not fully
* sent */
mylog(LOG_ERROR, "SSL_write wrote only %d while message length is %d",
mylog(LOG_ERROR,
"SSL_write wrote only %d while message length is %d",
count, size);
}
@ -260,7 +261,8 @@ static int _write_socket_SSL(connection_t *cn, char* message)
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define X509_OBJECT_get0_X509(o) ((o)->data.x509)
#define X509_STORE_CTX_get_by_subject(vs, type, name, ret) X509_STORE_get_by_subject(vs, type, name, ret)
#define X509_STORE_CTX_get_by_subject(vs, type, name, ret) \
X509_STORE_get_by_subject(vs, type, name, ret)
int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
{
@ -362,7 +364,6 @@ static int write_socket(connection_t *cn, char *line)
else
#endif
return _write_socket(cn, line);
}
/* returns 1 if connection must be notified */
@ -521,20 +522,19 @@ static int read_socket_SSL(connection_t *cn)
|| err == SSL_ERROR_WANT_ACCEPT)
return 0;
if (cn_is_connected(cn)) {
mylog(LOG_ERROR, "fd %d: Connection error",
cn->handle);
mylog(LOG_ERROR, "fd %d: Connection error", cn->handle);
cn->connected = CONN_ERROR;
}
return 1;
} else if (count == 0) {
/* int err = SSL_get_error(cn->ssl_h,count);
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE
if (err == SSL_ERROR_WANT_READ || err ==
SSL_ERROR_WANT_WRITE
|| err == SSL_ERROR_WANT_CONNECT
|| err == SSL_ERROR_WANT_ACCEPT)
return 0;*/
if (cn_is_connected(cn)) {
mylog(LOG_ERROR, "fd %d: Connection lost",
cn->handle);
mylog(LOG_ERROR, "fd %d: Connection lost", cn->handle);
connection_close(cn);
}
return 1;
@ -688,8 +688,8 @@ static int check_event_read(fd_set *fds, connection_t *cn)
int ret;
if (cn_is_in_error(cn)) {
mylog(LOG_ERROR, "Error on fd %d (read, state %d)",
cn->handle, cn->connected);
mylog(LOG_ERROR, "Error on fd %d (read, state %d)", cn->handle,
cn->connected);
return 1;
}
@ -711,8 +711,7 @@ static int check_event_read(fd_set *fds, connection_t *cn)
ret = read_socket(cn);
if (ret) {
mylog(LOG_ERROR, "Error while reading on fd %d",
cn->handle);
mylog(LOG_ERROR, "Error while reading on fd %d", cn->handle);
return 1;
}
@ -742,8 +741,8 @@ static void connection_connected(connection_t *c)
static int check_event_write(fd_set *fds, connection_t *cn, int *nc)
{
if (cn_is_in_error(cn)) {
mylog(LOG_ERROR, "Error on fd %d (write, state %d)",
cn->handle, cn->connected);
mylog(LOG_ERROR, "Error on fd %d (write, state %d)", cn->handle,
cn->connected);
return 1;
}
@ -775,8 +774,10 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc)
cn->handle = -1;
connect_trynext(cn);
}
return (cn_is_new(cn) || cn->connected ==
CONN_NEED_SSLIZE) ? 0 : 1;
return (cn_is_new(cn)
|| cn->connected == CONN_NEED_SSLIZE)
? 0
: 1;
} else if (err == EINPROGRESS || err == EALREADY) {
mylog(LOG_DEBUG, "fd:%d Connection in progress...",
@ -803,8 +804,10 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc)
cn->handle = -1;
connect_trynext(cn);
}
return (cn_is_new(cn) || cn->connected ==
CONN_NEED_SSLIZE) ? 0 : 1;
return (cn_is_new(cn)
|| cn->connected == CONN_NEED_SSLIZE)
? 0
: 1;
}
}
@ -842,7 +845,8 @@ static int cn_want_write(connection_t *cn)
if (!clock_gettime(CLOCK_MONOTONIC, &tv)) {
if (tv.tv_sec < 0 || tv.tv_nsec < 0)
fatal("clock_gettime returned negative time");
now = (unsigned long)(tv.tv_sec * 1000 + tv.tv_nsec / 1000000);
now = (unsigned long)(tv.tv_sec * 1000
+ tv.tv_nsec / 1000000);
/* round now to TOKEN_INTERVAL multiple */
now -= now % TOKEN_INTERVAL;
if (now < cn->lasttoken) {
@ -850,8 +854,8 @@ static int cn_want_write(connection_t *cn)
cn->token = 1;
cn->lasttoken = now;
} else if (now > cn->lasttoken + TOKEN_INTERVAL) {
cn->token += (unsigned)((now - cn->lasttoken) /
TOKEN_INTERVAL);
cn->token += (unsigned)((now - cn->lasttoken)
/ TOKEN_INTERVAL);
if (cn->token > TOKEN_MAX)
cn->token = TOKEN_MAX;
if (!cn->token)
@ -917,8 +921,7 @@ list_t *wait_event(list_t *cn_list, time_t *msec, int *nc)
if (cn_is_connected(cn)) {
FD_SET(cn->handle, &fds_read);
mylog(LOG_DEBUGTOOMUCH, "Test read on fd %d %d:%d",
cn->handle, cn->connected,
cn_is_connected(cn));
cn->handle, cn->connected, cn_is_connected(cn));
}
/* we NEVER want to check write on a listening socket */
@ -928,8 +931,7 @@ list_t *wait_event(list_t *cn_list, time_t *msec, int *nc)
if (!cn_is_connected(cn) || cn_want_write(cn)) {
FD_SET(cn->handle, &fds_write);
mylog(LOG_DEBUGTOOMUCH, "Test write on fd %d %d:%d",
cn->handle, cn->connected,
cn_is_connected(cn));
cn->handle, cn->connected, cn_is_connected(cn));
}
}
@ -1018,8 +1020,8 @@ static void create_socket(char *dsthostname, char *dstport, char *srchostname,
hint.ai_protocol = 0;
cn->connected = CONN_ERROR;
cdata = (struct connecting_data *)
bip_malloc(sizeof(struct connecting_data));
cdata = (struct connecting_data *)bip_malloc(
sizeof(struct connecting_data));
cdata->dst = cdata->src = cdata->cur = NULL;
err = getaddrinfo(dsthostname, dstport, &hint, &cdata->dst);
@ -1054,8 +1056,7 @@ static void create_listening_socket(char *hostname, char *port,
int multi_client = 1;
int err;
struct addrinfo *res, *cur;
struct addrinfo hint = {
.ai_flags = AI_PASSIVE,
struct addrinfo hint = {.ai_flags = AI_PASSIVE,
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
.ai_protocol = 0,
@ -1063,8 +1064,7 @@ static void create_listening_socket(char *hostname, char *port,
.ai_addrlen = 0,
.ai_addr = 0,
.ai_canonname = 0,
.ai_next = 0
};
.ai_next = 0};
cn->connected = CONN_ERROR;
@ -1076,13 +1076,15 @@ static void create_listening_socket(char *hostname, char *port,
for (cur = res; cur; cur = cur->ai_next) {
if ((cn->handle = socket(cur->ai_family, cur->ai_socktype,
cur->ai_protocol)) < 0) {
cur->ai_protocol))
< 0) {
mylog(LOG_WARN, "socket : %s", strerror(errno));
continue;
}
if (cn->handle >= FD_SETSIZE) {
mylog(LOG_WARN, "too many fd used, close listening socket %d",
mylog(LOG_WARN,
"too many fd used, close listening socket %d",
cn->handle);
if (close(cn->handle) == -1)
@ -1095,7 +1097,8 @@ static void create_listening_socket(char *hostname, char *port,
if (setsockopt(cn->handle, SOL_SOCKET, SO_REUSEADDR,
(char *)&multi_client,
(socklen_t)sizeof(multi_client)) < 0) {
(socklen_t)sizeof(multi_client))
< 0) {
mylog(LOG_WARN, "setsockopt() : %s", strerror(errno));
close(cn->handle);
cn->handle = -1;
@ -1187,7 +1190,8 @@ static int ctx_set_dh(SSL_CTX *ctx)
return 0;
}
// SSL crap: passing argument 3 of SSL_CTX_ctrl with different width due to prototype
// SSL crap: passing argument 3 of SSL_CTX_ctrl with different width due to
// prototype
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtraditional-conversion"
ret = SSL_CTX_set_tmp_dh(ctx, dh);
@ -1238,19 +1242,23 @@ connection_t *accept_new(connection_t *cn)
#ifdef HAVE_LIBSSL
if (cn->ssl) {
if (!sslctx) {
mylog(LOG_DEBUG, "No SSL context available for "
mylog(LOG_DEBUG,
"No SSL context available for "
"accepted connections. "
"Initializing...");
if (!(sslctx = SSL_init_context(conf_client_ciphers))) {
mylog(LOG_ERROR, "SSL context initialization "
mylog(LOG_ERROR,
"SSL context initialization "
"failed");
connection_free(conn);
return NULL;
}
if (!conf_client_dh_file) {
// try with a default path but don't fail if it doesn't exist
conf_client_dh_file = default_path(conf_biphome, "dh.pem",
// try with a default path but don't fail if it
// doesn't exist
conf_client_dh_file =
default_path(conf_biphome, "dh.pem",
"DH parameters");
struct stat st_buf;
@ -1262,16 +1270,18 @@ connection_t *accept_new(connection_t *cn)
if (conf_client_dh_file) {
if (!ctx_set_dh(sslctx)) {
mylog(LOG_ERROR, "SSL Unable to load DH "
mylog(LOG_ERROR,
"SSL Unable to load DH "
"parameters");
connection_free(conn);
return NULL;
}
}
if (!SSL_CTX_use_certificate_chain_file(sslctx,
conf_ssl_certfile))
mylog(LOG_WARN, "SSL: Unable to load "
if (!SSL_CTX_use_certificate_chain_file(
sslctx, conf_ssl_certfile))
mylog(LOG_WARN,
"SSL: Unable to load "
"certificate file");
if (!SSL_CTX_use_PrivateKey_file(sslctx,
conf_ssl_certfile,
@ -1312,7 +1322,8 @@ connection_t *listen_new(char *hostname, int port, int ssl)
}
static connection_t *_connection_new(char *dsthostname, char *dstport,
char *srchostname, char *srcport, time_t timeout)
char *srchostname, char *srcport,
time_t timeout)
{
connection_t *conn;
@ -1331,7 +1342,8 @@ static SSL_CTX *SSL_init_context(char *ciphers)
SSL_CTX *ctx;
if (!ssl_initialized) {
// SSL crap: passing argument 1 of OPENSSL_init_ssl with different width due to prototype
// SSL crap: passing argument 1 of OPENSSL_init_ssl with different width due
// to prototype
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtraditional-conversion"
SSL_library_init();
@ -1346,7 +1358,8 @@ static SSL_CTX *SSL_init_context(char *ciphers)
flags |= O_NONBLOCK;
fd = open("/dev/random", flags);
if (fd < 0) {
mylog(LOG_WARN, "SSL: /dev/random not ready, unable "
mylog(LOG_WARN,
"SSL: /dev/random not ready, unable "
"to manually seed PRNG.");
goto prng_end;
}
@ -1358,8 +1371,10 @@ static SSL_CTX *SSL_init_context(char *ciphers)
strerror(errno));
goto prng_end;
}
mylog(LOG_DEBUG, "PRNG seeded with %d /dev/random "
"bytes", ret);
mylog(LOG_DEBUG,
"PRNG seeded with %d /dev/random "
"bytes",
ret);
RAND_seed(buf, (int)ret);
} while (!(rng = RAND_status()));
@ -1371,7 +1386,8 @@ prng_end:
mylog(LOG_DEBUG, "SSL: PRNG is seeded !");
} else {
mylog(LOG_WARN, "SSL: PRNG is not seeded enough");
mylog(LOG_WARN, " OpenSSL will use /dev/urandom if "
mylog(LOG_WARN,
" OpenSSL will use /dev/urandom if "
"available.");
}
@ -1385,10 +1401,12 @@ prng_end:
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtraditional-conversion"
// SSL crap: passing argument 3 of SSL_CTX_ctrl with different width due to prototype
// SSL crap: passing argument 3 of SSL_CTX_ctrl with different width
// due to prototype
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_BOTH);
SSL_CTX_set_timeout(ctx, (long)60);
// SSL crap: passing argument 2 of SSL_CTX_set_options with different width due to prototype
// SSL crap: passing argument 2 of SSL_CTX_set_options with different
// width due to prototype
SSL_CTX_set_options(ctx, SSL_OP_ALL);
#pragma GCC diagnostic pop
if (ciphers && !SSL_CTX_set_cipher_list(ctx, ciphers)) {
@ -1429,38 +1447,45 @@ static int bip_ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
/* in basic mode (mode 1), accept a leaf certificate if we can find it
* in the store */
if (c->ssl_check_mode == SSL_CHECK_BASIC && result == 0 &&
(err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY ||
err == X509_V_ERR_CERT_UNTRUSTED ||
err == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT ||
err == X509_V_ERR_CERT_HAS_EXPIRED ||
err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN)) {
if (c->ssl_check_mode == SSL_CHECK_BASIC && result == 0
&& (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
|| err == X509_V_ERR_CERT_UNTRUSTED
|| err == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE
|| err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT
|| err == X509_V_ERR_CERT_HAS_EXPIRED
|| err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN)) {
if (!(xobj = X509_OBJECT_new())) {
result = 0;
} else {
if (X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509,
X509_get_subject_name(err_cert), xobj) > 0 &&
!X509_cmp(X509_OBJECT_get0_X509(xobj), err_cert)) {
if (X509_STORE_CTX_get_by_subject(
ctx, X509_LU_X509,
X509_get_subject_name(err_cert), xobj)
> 0
&& !X509_cmp(X509_OBJECT_get0_X509(xobj),
err_cert)) {
if (err == X509_V_ERR_CERT_HAS_EXPIRED)
mylog(LOG_INFO, "Basic mode; Accepting "
mylog(LOG_INFO,
"Basic mode; Accepting "
"*expired* peer certificate "
"found in store.");
else
mylog(LOG_INFO, "Basic mode; Accepting peer "
mylog(LOG_INFO,
"Basic mode; Accepting peer "
"certificate found in store.");
result = 1;
err = X509_V_OK;
X509_STORE_CTX_set_error(ctx, err);
} else {
mylog(LOG_INFO, "Basic mode; peer certificate NOT "
mylog(LOG_INFO,
"Basic mode; peer certificate NOT "
"in store, rejecting it!");
err = X509_V_ERR_CERT_REJECTED;
X509_STORE_CTX_set_error(ctx, err);
link_add_untrusted(c->user_data, X509_dup(err_cert));
link_add_untrusted(c->user_data,
X509_dup(err_cert));
}
X509_OBJECT_free(xobj);
}
@ -1540,7 +1565,8 @@ static int SSLize(connection_t *cn, int *nc)
}
break;
default:
mylog(LOG_ERROR, "Unknown ssl_check_mode (%d)!", cn->ssl_check_mode);
mylog(LOG_ERROR, "Unknown ssl_check_mode (%d)!",
cn->ssl_check_mode);
return 1;
}
@ -1563,8 +1589,11 @@ static int SSLize(connection_t *cn, int *nc)
}
static connection_t *_connection_new_SSL(char *dsthostname, char *dstport,
char *srchostname, char *srcport, char *ciphers, int check_mode,
char *check_store, char *ssl_client_certfile, time_t timeout)
char *srchostname, char *srcport,
char *ciphers, int check_mode,
char *check_store,
char *ssl_client_certfile,
time_t timeout)
{
connection_t *conn;
@ -1584,18 +1613,21 @@ static connection_t *_connection_new_SSL(char *dsthostname, char *dstport,
case SSL_CHECK_BASIC:
if (!SSL_CTX_load_verify_locations(conn->ssl_ctx_h, check_store,
NULL)) {
mylog(LOG_ERROR, "Can't assign check store to "
mylog(LOG_ERROR,
"Can't assign check store to "
"SSL connection! Proceeding without!");
}
break;
case SSL_CHECK_CA:
if (!check_store) {
if (SSL_CTX_set_default_verify_paths(conn->ssl_ctx_h)) {
mylog(LOG_INFO, "No SSL certificate check store configured. "
mylog(LOG_INFO,
"No SSL certificate check store configured. "
"Default store will be used.");
break;
} else {
mylog(LOG_ERROR, "No SSL certificate check store configured "
mylog(LOG_ERROR,
"No SSL certificate check store configured "
"and cannot use default store!");
return conn;
}
@ -1603,28 +1635,34 @@ static connection_t *_connection_new_SSL(char *dsthostname, char *dstport,
// Check if check_store is a file or directory
if (stat(check_store, &st_buf) == 0) {
if (st_buf.st_mode & S_IFDIR) {
if (!SSL_CTX_load_verify_locations(conn->ssl_ctx_h, NULL,
if (!SSL_CTX_load_verify_locations(
conn->ssl_ctx_h, NULL,
check_store)) {
mylog(LOG_ERROR, "Can't assign check store to "
mylog(LOG_ERROR,
"Can't assign check store to "
"SSL connection!");
return conn;
}
break;
}
if (st_buf.st_mode & S_IFREG) {
if (!SSL_CTX_load_verify_locations(conn->ssl_ctx_h, check_store,
if (!SSL_CTX_load_verify_locations(
conn->ssl_ctx_h, check_store,
NULL)) {
mylog(LOG_ERROR, "Can't assign check store to "
mylog(LOG_ERROR,
"Can't assign check store to "
"SSL connection!");
return conn;
}
break;
}
mylog(LOG_ERROR, "Specified SSL certificate check store is neither "
mylog(LOG_ERROR,
"Specified SSL certificate check store is neither "
"a file nor a directory.");
return conn;
}
mylog(LOG_ERROR, "Can't open SSL certificate check store! Check path "
mylog(LOG_ERROR,
"Can't open SSL certificate check store! Check path "
"and permissions.");
return conn;
default:
@ -1653,11 +1691,14 @@ static connection_t *_connection_new_SSL(char *dsthostname, char *dstport,
ssl_client_certfile))
mylog(LOG_WARN, "SSL: Unable to load certificate file");
else if (!SSL_CTX_use_PrivateKey_file(conn->ssl_ctx_h,
ssl_client_certfile, SSL_FILETYPE_PEM))
ssl_client_certfile,
SSL_FILETYPE_PEM))
mylog(LOG_WARN, "SSL: Unable to load key file");
else
mylog(LOG_INFO, "SSL: using %s pem file as client SSL "
"certificate", ssl_client_certfile);
mylog(LOG_INFO,
"SSL: using %s pem file as client SSL "
"certificate",
ssl_client_certfile);
}
conn->ssl_h = SSL_new(conn->ssl_ctx_h);
@ -1683,8 +1724,9 @@ static connection_t *_connection_new_SSL(char *dsthostname, char *dstport,
#endif
connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
int srcport, int ssl, char *ssl_ciphers, int ssl_check_mode,
char *ssl_check_store, char *ssl_client_certfile, time_t timeout)
int srcport, int ssl, char *ssl_ciphers,
int ssl_check_mode, char *ssl_check_store,
char *ssl_client_certfile, time_t timeout)
{
char dstportbuf[20], srcportbuf[20], *tmp;
#ifndef HAVE_LIBSSL
@ -1706,8 +1748,9 @@ connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
#ifdef HAVE_LIBSSL
if (ssl)
return _connection_new_SSL(dsthostname, dstportbuf, srchostname,
tmp, ssl_ciphers, ssl_check_mode, ssl_check_store,
ssl_client_certfile, timeout);
tmp, ssl_ciphers, ssl_check_mode,
ssl_check_store, ssl_client_certfile,
timeout);
else
#endif
return _connection_new(dsthostname, dstportbuf, srchostname,
@ -1747,14 +1790,14 @@ static int socket_set_nonblock(int s)
int flags;
if ((flags = fcntl(s, F_GETFL, 0)) < 0) {
mylog(LOG_ERROR, "Cannot set socket %d to non blocking : %s",
s, strerror(errno));
mylog(LOG_ERROR, "Cannot set socket %d to non blocking : %s", s,
strerror(errno));
return 0;
}
if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) {
mylog(LOG_ERROR, "Cannot set socket %d to non blocking : %s",
s, strerror(errno));
mylog(LOG_ERROR, "Cannot set socket %d to non blocking : %s", s,
strerror(errno));
return 0;
}
return 1;
@ -1866,8 +1909,7 @@ static char *socket_ip(int fd, int remote)
/* getsockname every time to get IP version */
err = getsockname(fd, (struct sockaddr *)&addr, &addrlen);
if (err != 0) {
mylog(LOG_ERROR, "in getsockname(%d): %s", fd,
strerror(errno));
mylog(LOG_ERROR, "in getsockname(%d): %s", fd, strerror(errno));
return NULL;
}

View File

@ -92,8 +92,9 @@ typedef struct connection {
} connection_t;
connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
int srcport, int ssl, char *ssl_ciphers, int ssl_check_mode,
char *ssl_check_store, char *ssl_client_certfile, time_t timeout);
int srcport, int ssl, char *ssl_ciphers,
int ssl_check_mode, char *ssl_check_store,
char *ssl_client_certfile, time_t timeout);
connection_t *listen_new(char *hostname, int port, int ssl);
connection_t *accept_new(connection_t *cn);
void connection_free(connection_t *cn);

375
src/irc.c
View File

@ -24,7 +24,8 @@
#include "md5.h"
#include "utils/base64.h"
// TODO resolve assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1
// TODO resolve assuming signed overflow does not occur when changing X +- C1
// cmp C2 to X cmp C2 -+ C1
#pragma GCC diagnostic ignored "-Wstrict-overflow"
#define S_CONN_DELAY (10)
@ -36,7 +37,8 @@ static int irc_join(struct link_server *server, struct line *line);
static int irc_part(struct link_server *server, struct line *line);
static int irc_mode(struct link_server *server, struct line *line);
static int irc_mode_channel(struct link_server *s, struct channel *channel,
struct line *line, const char* mode, int add, int cur_arg);
struct line *line, const char *mode, int add,
int cur_arg);
static int irc_kick(struct link_server *server, struct line *line);
static int irc_privmsg(struct link_server *server, struct line *line);
static int irc_notice(struct link_server *server, struct line *line);
@ -238,8 +240,8 @@ static void irc_server_connected(struct link_server *server)
LINK(server)->s_state = IRCS_CONNECTED;
LINK(server)->s_conn_attempt = 0;
mylog(LOG_INFO, "[%s] Connected for user %s",
LINK(server)->name, LINK(server)->user->name);
mylog(LOG_INFO, "[%s] Connected for user %s", LINK(server)->name,
LINK(server)->user->name);
irc_server_join(server);
log_connected(LINK(server)->log);
@ -401,54 +403,74 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
}
} else if (irc_line_elem_equals(line, 0, "CAP")) {
if (LINK(server)->sasl_mechanism) {
if (irc_line_elem_equals(line, 2, "ACK") && irc_line_elem_equals(line, 3, "sasl")) {
// Server is answering our CAP REQ :sasl and is SASL capable
char *sasl_mech = sasl_mechanism_to_text(LINK(server)->sasl_mechanism);
mylog(LOG_INFO, "[%s] Server is SASL capable, starting %s authentication.",
if (irc_line_elem_equals(line, 2, "ACK")
&& irc_line_elem_equals(line, 3, "sasl")) {
// Server is answering our CAP REQ :sasl and is
// SASL capable
char *sasl_mech = sasl_mechanism_to_text(
LINK(server)->sasl_mechanism);
mylog(LOG_INFO,
"[%s] Server is SASL capable, starting %s authentication.",
LINK(server)->name, sasl_mech);
WRITE_LINE1(CONN(server), NULL, "AUTHENTICATE", sasl_mech);
WRITE_LINE1(CONN(server), NULL, "AUTHENTICATE",
sasl_mech);
ret = OK_FORGET;
} else if (irc_line_elem_equals(line, 2, "NAK") && irc_line_elem_equals(line, 3, "sasl")) {
// Server is answering our CAP REQ :sasl and isn't SASL capable
mylog(LOG_INFO, "[%s] Server is not SASL capable.", LINK(server)->name);
} else if (irc_line_elem_equals(line, 2, "NAK")
&& irc_line_elem_equals(line, 3, "sasl")) {
// Server is answering our CAP REQ :sasl and
// isn't SASL capable
mylog(LOG_INFO,
"[%s] Server is not SASL capable.",
LINK(server)->name);
ret = ERR_PROTOCOL;
} else {
// Unhandled CAP message
mylog(LOG_ERROR,
"[%s] Unhandled CAP message: %s",
LINK(server)->name,
irc_line_to_string(line));
ret = OK_FORGET;
}
} else {
// Unhandled CAP message
mylog(LOG_ERROR, "[%s] Unhandled CAP message: %s",
LINK(server)->name, irc_line_to_string(line));
ret = OK_FORGET;
}
} else {
// Unhandled CAP message
mylog(LOG_ERROR, "[%s] Unhandled CAP message: %s", LINK(server)->name,
irc_line_to_string(line));
ret = OK_FORGET;
}
} else if (irc_line_elem_equals(line, 0, "AUTHENTICATE")) {
if (LINK(server)->sasl_mechanism) {
if (irc_line_count(line) == 2 && irc_line_elem_equals(line, 1, "+")) {
// Server is waiting for us to authenticate, let's do it
mylog(LOG_INFO, "[%s] Server accepted our authentication mechanism.",
if (irc_line_count(line) == 2
&& irc_line_elem_equals(line, 1, "+")) {
// Server is waiting for us to authenticate,
// let's do it
mylog(LOG_INFO,
"[%s] Server accepted our authentication mechanism.",
LINK(server)->name);
ret = irc_server_sasl_authenticate(server);
} else {
// Anything else than "AUTHENTICATE +" is unknown to us
mylog(LOG_ERROR, "[%s] Server sent gibberish: %s",
LINK(server)->name, irc_line_to_string(line));
// Anything else than "AUTHENTICATE +" is
// unknown to us
mylog(LOG_ERROR,
"[%s] Server sent gibberish: %s",
LINK(server)->name,
irc_line_to_string(line));
ret = ERR_PROTOCOL;
}
} else {
// Unhandled AUTHENTICATE message
mylog(LOG_ERROR, "[%s] Unhandled AUTHENTICATE message: %s",
mylog(LOG_ERROR,
"[%s] Unhandled AUTHENTICATE message: %s",
LINK(server)->name, irc_line_to_string(line));
ret = OK_FORGET;
}
} else if (irc_line_elem_equals(line, 0, "900")) {
if (irc_line_count(line) >= 5) {
mylog(LOG_INFO, "[%s] Logged in as %s(%s): %s", LINK(server)->name,
irc_line_elem(line, 3), irc_line_elem(line, 2), irc_line_elem(line, 4));
mylog(LOG_INFO, "[%s] Logged in as %s(%s): %s",
LINK(server)->name, irc_line_elem(line, 3),
irc_line_elem(line, 2), irc_line_elem(line, 4));
} else {
mylog(LOG_INFO, "[%s] Logged in: %s", LINK(server)->name, irc_line_to_string(line));
mylog(LOG_INFO, "[%s] Logged in: %s",
LINK(server)->name, irc_line_to_string(line));
}
ret = OK_FORGET;
} else if (irc_line_elem_equals(line, 0, "901")) {
@ -456,7 +478,8 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
mylog(LOG_INFO, "[%s] Logged out: %s",
LINK(server)->name, irc_line_elem(line, 3));
} else {
mylog(LOG_INFO, "[%s] Logged out: %s", LINK(server)->name, irc_line_to_string(line));
mylog(LOG_INFO, "[%s] Logged out: %s",
LINK(server)->name, irc_line_to_string(line));
}
ret = OK_FORGET;
} else if (irc_line_elem_equals(line, 0, "902")) {
@ -464,25 +487,30 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
LINK(server)->name, irc_line_to_string(line));
ret = OK_FORGET;
} else if (irc_line_elem_equals(line, 0, "903")) {
mylog(LOG_INFO, "[%s] SASL authentication successful", LINK(server)->name);
mylog(LOG_INFO, "[%s] SASL authentication successful",
LINK(server)->name);
WRITE_LINE1(CONN(server), NULL, "CAP", "END");
ret = OK_FORGET;
} else if (irc_line_elem_equals(line, 0, "904")) {
mylog(LOG_ERROR, "[%s] SASL authentication failed", LINK(server)->name);
mylog(LOG_ERROR, "[%s] SASL authentication failed",
LINK(server)->name);
ret = ERR_AUTH;
} else if (irc_line_elem_equals(line, 0, "905")) {
mylog(LOG_ERROR, "[%s] SASL message too long", LINK(server)->name);
mylog(LOG_ERROR, "[%s] SASL message too long",
LINK(server)->name);
ret = ERR_AUTH;
} else if (irc_line_elem_equals(line, 0, "906")) {
mylog(LOG_ERROR, "[%s] SASL authentication aborted by client",
LINK(server)->name);
ret = ERR_AUTH;
} else if (irc_line_elem_equals(line, 0, "907")) {
mylog(LOG_ERROR, "[%s] SASL authentication has already been completed",
mylog(LOG_ERROR,
"[%s] SASL authentication has already been completed",
LINK(server)->name);
ret = OK_FORGET;
} else if (irc_line_elem_equals(line, 0, "908")) {
mylog(LOG_ERROR, "[%s] Server only accepts following authentication mechanisms: %s",
mylog(LOG_ERROR,
"[%s] Server only accepts following authentication mechanisms: %s",
LINK(server)->name, irc_line_elem(line, 2));
ret = ERR_AUTH;
} else if (irc_line_elem_equals(line, 0, "433")) {
@ -501,8 +529,10 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
newnick[7] = '`';
}
} else {
newnick[8] = (char)('a' + ('z' - 'a') *
rand() / RAND_MAX);
newnick[8] =
(char)('a'
+ ('z' - 'a') * rand()
/ RAND_MAX);
}
newnick[9] = 0;
}
@ -523,13 +553,19 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
if (irc_line_elem_equals(line, 0, "005")) {
int i;
for (i = irc_line_count(line) - 1; i > 0; i--) {
if (LINK(server)->ignore_server_capab &&
irc_line_elem_equals(line, i, "CAPAB"))
if (LINK(server)->ignore_server_capab
&& irc_line_elem_equals(line, i, "CAPAB"))
irc_line_drop(line, i);
else if (!strncmp(irc_line_elem(line, i), "CHANMODES=", (size_t)10))
server_set_chanmodes(server, irc_line_elem(line, i) + 10);
else if (!strncmp(irc_line_elem(line, i), "PREFIX=(", (size_t)8))
server_set_prefix(server, irc_line_elem(line, i) + 7);
else if (!strncmp(irc_line_elem(line, i),
"CHANMODES=", (size_t)10))
server_set_chanmodes(
server,
irc_line_elem(line, i) + 10);
else if (!strncmp(irc_line_elem(line, i),
"PREFIX=(", (size_t)8))
server_set_prefix(server,
irc_line_elem(line, i)
+ 7);
}
}
if (irc_line_elem_equals(line, 0, "NOTICE")) {
@ -594,8 +630,8 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
if (ret == OK_COPY) {
unsigned int i;
for (i = 0; i < LINK(server)->l_clientc; i++) {
if (TYPE(LINK(server)->l_clientv[i]) ==
IRC_TYPE_CLIENT) {
if (TYPE(LINK(server)->l_clientv[i])
== IRC_TYPE_CLIENT) {
char *s = irc_line_to_string(line);
write_line(CONN(LINK(server)->l_clientv[i]), s);
free(s);
@ -609,8 +645,8 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server,
write_line(CONN(LINK(server)->who_client), s);
free(s);
}
if (LINK(server)->who_client &&
LINK(server)->who_client->who_count == 0) {
if (LINK(server)->who_client
&& LINK(server)->who_client->who_count == 0) {
mylog(LOG_DEBUG, "OK_COPY_WHO: who_count for %p is nul",
LINK(server)->who_client);
rotate_who_client(LINK(server));
@ -628,8 +664,8 @@ static void irc_send_join(struct link_client *ic, struct channel *chan)
assert(user);
/* user ircmask here for rbot */
ircmask = bip_malloc(strlen(LINK(ic)->l_server->nick) +
strlen(BIP_FAKEMASK) + 1);
ircmask = bip_malloc(strlen(LINK(ic)->l_server->nick)
+ strlen(BIP_FAKEMASK) + 1);
strcpy(ircmask, LINK(ic)->l_server->nick);
strcat(ircmask, BIP_FAKEMASK);
WRITE_LINE1(CONN(ic), ircmask, "JOIN", chan->name);
@ -673,8 +709,8 @@ static void bind_to_link(struct link *l, struct link_client *ic)
LINK(ic) = l;
l->l_clientc++;
l->l_clientv = bip_realloc(l->l_clientv, l->l_clientc *
sizeof(struct link_client *));
l->l_clientv = bip_realloc(l->l_clientv,
l->l_clientc * sizeof(struct link_client *));
l->l_clientv[i] = ic;
}
@ -701,8 +737,8 @@ void unbind_from_link(struct link_client *ic)
if (l->l_clientc == 0)
fatal("unbind_from_link: negative client count");
l->l_clientc--;
l->l_clientv = bip_realloc(l->l_clientv, l->l_clientc *
sizeof(struct link_client *));
l->l_clientv = bip_realloc(l->l_clientv,
l->l_clientc * sizeof(struct link_client *));
if (l->l_clientc == 0) { /* bip_realloc was equiv to free() */
l->l_clientv = NULL;
return;
@ -759,8 +795,8 @@ static void irc_cli_make_join(struct link_client *ic)
list_iterator_t li;
for (list_it_init(&LINK(ic)->chan_infos_order, &li);
list_it_item(&li); list_it_next(&li)) {
struct chan_info *ci = (struct chan_info *)
list_it_item(&li);
struct chan_info *ci =
(struct chan_info *)list_it_item(&li);
struct channel *chan;
if ((chan = hash_get(&LINK(ic)->l_server->channels,
ci->name)))
@ -771,8 +807,8 @@ static void irc_cli_make_join(struct link_client *ic)
hash_iterator_t hi;
for (hash_it_init(&LINK(ic)->l_server->channels, &hi);
hash_it_item(&hi); hash_it_next(&hi)) {
struct channel *chan = (struct channel *)
hash_it_item(&hi);
struct channel *chan =
(struct channel *)hash_it_item(&hi);
if (!hash_get(&LINK(ic)->chan_infos, chan->name))
irc_send_join(ic, chan);
}
@ -848,10 +884,10 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic,
for (list_it_init(&bip->link_list, &it); list_it_item(&it);
list_it_next(&it)) {
struct link *l = list_it_item(&it);
if (strcmp(user, l->user->name) == 0 &&
strcmp(connname, l->name) == 0) {
if (chash_cmp(pass, l->user->password,
l->user->seed) == 0) {
if (strcmp(user, l->user->name) == 0
&& strcmp(connname, l->name) == 0) {
if (chash_cmp(pass, l->user->password, l->user->seed)
== 0) {
bind_to_link(l, ic);
break;
}
@ -887,7 +923,8 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic,
if (LINK(ic)->s_state == IRCS_NONE) {
/* drop it if corresponding server hasn't connected at all. */
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":ERROR Proxy not yet connected, try again "
"later\r\n");
unbind_from_link(ic);
@ -898,8 +935,8 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic,
list_remove(&bip->connecting_client_list, ic);
TYPE(ic) = IRC_TYPE_CLIENT;
for (list_it_init(&LINK(ic)->init_strings, &it);
list_it_item(&it); list_it_next(&it))
for (list_it_init(&LINK(ic)->init_strings, &it); list_it_item(&it);
list_it_next(&it))
write_init_string(CONN(ic), list_it_item(&it), init_nick);
/* we change nick on server */
@ -909,8 +946,8 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic,
if (!LINK(ic)->ignore_first_nick)
WRITE_LINE1(CONN(server), NULL, "NICK", init_nick);
else if (LINK(ic)->away_nick &&
strcmp(LINK(ic)->away_nick, server->nick) == 0)
else if (LINK(ic)->away_nick
&& strcmp(LINK(ic)->away_nick, server->nick) == 0)
WRITE_LINE1(CONN(server), NULL, "NICK",
LINK(server)->connect_nick);
@ -1038,8 +1075,8 @@ static int irc_cli_who(struct link_client *ic, struct line *line)
++ic->who_count;
if (ic->who_count == 1)
ic->whoc_tstamp = time(NULL);
mylog(LOG_DEBUG, "cli_who: Incrementing who count for %p: %d",
ic, ic->who_count);
mylog(LOG_DEBUG, "cli_who: Incrementing who count for %p: %d", ic,
ic->who_count);
if (l->who_client && l->who_client != ic) {
list_add_first(&ic->who_queue, irc_line_to_string(line));
@ -1060,8 +1097,8 @@ static int irc_cli_mode(struct link_client *ic, struct line *line)
return OK_COPY;
/* This is a wild guess and that sucks. */
if (!irc_line_elem_equals(line, 0, "MODE") ||
strchr(irc_line_elem(line, 2), 'b') == NULL)
if (!irc_line_elem_equals(line, 0, "MODE")
|| strchr(irc_line_elem(line, 2), 'b') == NULL)
return OK_COPY;
++ic->who_count;
@ -1093,8 +1130,8 @@ static void irc_notify_disconnection(struct link_server *is)
for (hash_it_init(&is->channels, &hi); hash_it_item(&hi);
hash_it_next(&hi)) {
struct channel *c = (struct channel *)hash_it_item(&hi);
WRITE_LINE3(CONN(ic), P_IRCMASK, "KICK",
c->name, is->nick,
WRITE_LINE3(CONN(ic), P_IRCMASK, "KICK", c->name,
is->nick,
"Server disconnected, reconnecting");
}
bip_notify(ic, "Server disconnected, reconnecting");
@ -1191,8 +1228,8 @@ static int irc_cli_part(struct link_client *irc, struct line *line)
cname = irc_line_elem(line, 1);
if ((ci = hash_remove_if_exists(&LINK(irc)->chan_infos,
cname)) != NULL) {
if ((ci = hash_remove_if_exists(&LINK(irc)->chan_infos, cname))
!= NULL) {
list_remove(&LINK(irc)->chan_infos_order, ci);
free(ci->name);
if (ci->key)
@ -1209,8 +1246,8 @@ static int irc_dispatch_trust_client(struct link_client *ic, struct line *line)
if (!irc_line_includes(line, 1))
return ERR_PROTOCOL;
if (strcasecmp(irc_line_elem(line, 0), "BIP") == 0 &&
strcasecmp(irc_line_elem(line, 1), "TRUST") == 0)
if (strcasecmp(irc_line_elem(line, 0), "BIP") == 0
&& strcasecmp(irc_line_elem(line, 1), "TRUST") == 0)
r = adm_trust(ic, line);
return r;
@ -1231,7 +1268,8 @@ static int irc_dispatch_client(bip_t *bip, struct link_client *ic,
irc_line_elem(line, 1));
r = OK_FORGET;
} else if (LINK(ic)->s_state != IRCS_CONNECTED) {
write_line_fast(CONN(ic), ":irc.bip.net NOTICE pouet "
write_line_fast(CONN(ic),
":irc.bip.net NOTICE pouet "
":ERROR Proxy not connected, please wait "
"before sending commands\r\n");
r = OK_FORGET;
@ -1257,13 +1295,14 @@ static int irc_dispatch_client(bip_t *bip, struct link_client *ic,
if (r == OK_COPY || r == OK_COPY_CLI) {
char *str = irc_line_to_string(line);
if (LINK(ic)->s_state == IRCS_CONNECTED &&
LINK(ic)->l_server->nick)
if (LINK(ic)->s_state == IRCS_CONNECTED
&& LINK(ic)->l_server->nick)
write_line(CONN(LINK(ic)->l_server), str);
else if (LINK(ic)->l_server->nick)
WRITE_LINE2(CONN(ic), P_IRCMASK,
(LINK(ic)->user->bip_use_notice ?
"NOTICE" : "PRIVMSG"),
(LINK(ic)->user->bip_use_notice
? "NOTICE"
: "PRIVMSG"),
LINK(ic)->l_server->nick,
":Not connected please try again "
"later...\r\n");
@ -1288,8 +1327,8 @@ static void irc_copy_cli(struct link_client *src, struct link_client *dest,
if (src == dest)
return;
if (!irc_line_includes(line, 1) ||
!irc_line_elem_equals(line, 0, "PRIVMSG")) {
if (!irc_line_includes(line, 1)
|| !irc_line_elem_equals(line, 0, "PRIVMSG")) {
str = irc_line_to_string(line);
write_line(CONN(dest), str);
free(str);
@ -1314,7 +1353,8 @@ static void irc_copy_cli(struct link_client *src, struct link_client *dest,
/* LINK(src) == LINK(dest) */
size_t len = strlen(irc_line_elem(line, 2)) + 6;
// snprintf fix ^
// __builtin___snprintf_chk output may be truncated before the last format character
// __builtin___snprintf_chk output may be truncated before the last
// format character
char *tmp;
if (len == 0)
@ -1630,8 +1670,8 @@ static int irc_part(struct link_server *server, struct line *line)
if (origin_is_me(line, server)) {
log_part(LINK(server)->log, line->origin, s_chan,
irc_line_count(line) == 3 ? irc_line_elem(line, 2) :
NULL);
irc_line_count(line) == 3 ? irc_line_elem(line, 2)
: NULL);
log_reset_store(LINK(server)->log, s_chan);
log_drop(LINK(server)->log, s_chan);
@ -1654,8 +1694,7 @@ static int irc_part(struct link_server *server, struct line *line)
free(s_nick);
log_part(LINK(server)->log, line->origin, s_chan,
irc_line_count(line) == 3 ?
irc_line_elem(line, 2) : NULL);
irc_line_count(line) == 3 ? irc_line_elem(line, 2) : NULL);
return OK_COPY;
}
@ -1679,8 +1718,8 @@ static void mode_remove_letter(struct link_server *s, char c)
for (; i < s->user_mode_len - 1; i++)
s->user_mode[i] = s->user_mode[i + 1];
s->user_mode_len--;
s->user_mode = bip_realloc(s->user_mode,
s->user_mode_len);
s->user_mode =
bip_realloc(s->user_mode, s->user_mode_len);
return;
}
}
@ -1775,25 +1814,30 @@ static int irc_mode(struct link_server *server, struct line *line)
// Check if mode is known: first user modes then
// server modes
if (!(str = strchr(server->usermodes, *mode))) {
array_each(&server->chanmodes, i, str) {
array_each(&server->chanmodes, i, str)
{
if ((str = strchr(str, *mode)))
break;
}
}
if (str) {
// Usermodes, types A & B always take a parameter
// Type C take a parameter only when set
// Usermodes, types A & B always take a
// parameter Type C take a parameter only when
// set
if (i <= 1 || (i == 2 && add)) {
if (!irc_line_includes(line, cur_arg + 3)) {
if (!irc_line_includes(line,
cur_arg + 3)) {
return ERR_PROTOCOL;
} else {
ret = irc_mode_channel(server, channel, line, mode,
add, cur_arg);
ret = irc_mode_channel(
server, channel, line,
mode, add, cur_arg);
cur_arg++;
}
} else {
ret = irc_mode_channel(server, channel, line, mode, add,
ret = irc_mode_channel(server, channel,
line, mode, add,
cur_arg);
}
}
@ -1805,7 +1849,8 @@ static int irc_mode(struct link_server *server, struct line *line)
}
static int irc_mode_channel(struct link_server *s, struct channel *channel,
struct line *line, const char* mode, int add, int cur_arg)
struct line *line, const char *mode, int add,
int cur_arg)
{
const char *nick;
long int ovmask;
@ -1817,8 +1862,8 @@ static int irc_mode_channel(struct link_server *s, struct channel *channel,
#pragma GCC diagnostic ignored "-Wtraditional-conversion"
if (*mode == 'k') {
if (add) {
channel->key = bip_strdup(
irc_line_elem(line, cur_arg + 3));
channel->key =
bip_strdup(irc_line_elem(line, cur_arg + 3));
} else {
if (channel->key) {
free(channel->key);
@ -1905,8 +1950,8 @@ static int irc_kick(struct link_server *server, struct line *line)
/* we get kicked !! */
log_kick(LINK(server)->log, line->origin, channel->name,
irc_line_elem(line, 2),
irc_line_count(line) == 4 ?
irc_line_elem(line, 3) : NULL);
irc_line_count(line) == 4 ? irc_line_elem(line, 3)
: NULL);
log_reset_store(LINK(server)->log, channel->name);
log_drop(LINK(server)->log, channel->name);
@ -2011,9 +2056,9 @@ static int irc_nick(struct link_server *server, struct line *line)
if (origin_is_me(line, server)) {
free(server->nick);
server->nick = bip_strdup(dst_nick);
if (LINK(server)->follow_nick &&
(LINK(server)->away_nick == NULL ||
strcmp(server->nick, LINK(server)->away_nick))
if (LINK(server)->follow_nick
&& (LINK(server)->away_nick == NULL
|| strcmp(server->nick, LINK(server)->away_nick))
!= 0) {
free(LINK(server)->connect_nick);
LINK(server)->connect_nick = bip_strdup(server->nick);
@ -2046,8 +2091,8 @@ static int irc_generic_quit(struct link_server *server, struct line *line)
continue;
hash_remove(&channel->ovmasks, s_nick);
log_quit(LINK(server)->log, line->origin, channel->name,
irc_line_includes(line, 1) ?
irc_line_elem(line, 1) : NULL);
irc_line_includes(line, 1) ? irc_line_elem(line, 1)
: NULL);
}
free(s_nick);
return OK_COPY;
@ -2106,7 +2151,8 @@ static int irc_server_sasl_authenticate(struct link_server *ircs)
// Should not happen, but we never know right ?
if (!sasl_username || !sasl_password) {
mylog(LOG_ERROR, "[%s] Missing SASL username or password.", LINK(ircs)->name);
mylog(LOG_ERROR, "[%s] Missing SASL username or password.",
LINK(ircs)->name);
return ERR_AUTH;
}
@ -2129,7 +2175,8 @@ static int irc_server_sasl_authenticate(struct link_server *ircs)
raw_str[u_len * 2 + 1] = '\0';
memcpy(raw_str + u_len * 2 + 2, sasl_password, p_len);
enc_str = base64_encode(raw_str, raw_len, &enc_len);
mylog(LOG_DEBUG, "[%s] Base64 encoded SASL auth token (len %d): %s", LINK(ircs)->name, enc_len, enc_str);
mylog(LOG_DEBUG, "[%s] Base64 encoded SASL auth token (len %d): %s",
LINK(ircs)->name, enc_len, enc_str);
for (size_t i = 0; i < enc_len; i += chunk_chars) {
size_t remaining = enc_len - i;
@ -2144,9 +2191,11 @@ static int irc_server_sasl_authenticate(struct link_server *ircs)
LINK(ircs)->name, i / chunk_chars, strlen(chunk), chunk);
WRITE_LINE1(CONN(ircs), NULL, "AUTHENTICATE", chunk);
// Send a closing AUTHENTICATE line if last chunk size was exactly 400
// Send a closing AUTHENTICATE line if last chunk size was
// exactly 400
if (remaining == chunk_chars) {
mylog(LOG_DEBUG, "[%s] Last SASL chunk was exactly 400, sending +",
mylog(LOG_DEBUG,
"[%s] Last SASL chunk was exactly 400, sending +",
LINK(ircs)->name);
WRITE_LINE1(CONN(ircs), NULL, "AUTHENTICATE", "+");
break;
@ -2275,15 +2324,13 @@ static void server_setup_reconnect_timer(struct link *link)
{
int timer = 0;
if (link->last_connection_attempt &&
time(NULL) - link->last_connection_attempt
< CONN_INTERVAL) {
if (link->last_connection_attempt
&& time(NULL) - link->last_connection_attempt < CONN_INTERVAL) {
timer = conf_reconn_timer * (link->s_conn_attempt);
if (timer > RECONN_TIMER_MAX)
timer = RECONN_TIMER_MAX;
}
mylog(LOG_ERROR, "[%s] reconnecting in %d seconds", link->name,
timer);
mylog(LOG_ERROR, "[%s] reconnecting in %d seconds", link->name, timer);
link->recon_timer = timer;
}
@ -2371,8 +2418,7 @@ void irc_server_free(struct link_server *s)
int i;
char *ptr;
array_each(&s->chanmodes, i, ptr)
free(ptr);
array_each(&s->chanmodes, i, ptr) free(ptr);
MAYFREE(s->prefixes);
MAYFREE(s->usermodes);
@ -2395,18 +2441,18 @@ connection_t *irc_server_connect(struct link *link)
link->s_conn_attempt++;
mylog(LOG_INFO, "[%s] Connecting user '%s' using server "
"%s:%d", link->name, link->user->name,
mylog(LOG_INFO,
"[%s] Connecting user '%s' using server "
"%s:%d",
link->name, link->user->name,
link->network->serverv[link->cur_server].host,
link->network->serverv[link->cur_server].port);
conn = connection_new(link->network->serverv[link->cur_server].host,
link->network->serverv[link->cur_server].port,
link->vhost, link->bind_port,
#ifdef HAVE_LIBSSL
link->network->ssl,
link->network->ciphers,
link->ssl_check_mode,
link->user->ssl_check_store,
link->network->ssl, link->network->ciphers,
link->ssl_check_mode, link->user->ssl_check_store,
link->user->ssl_client_certfile,
#else
0, NULL, 0, NULL, NULL,
@ -2458,8 +2504,7 @@ void irc_server_shutdown(struct link_server *s)
{
int i;
char *cur;
array_each(&s->chanmodes, i, cur)
free(cur);
array_each(&s->chanmodes, i, cur) free(cur);
array_deinit(&s->chanmodes);
server_init_modes(s);
@ -2510,9 +2555,10 @@ void oidentd_dump(bip_t *bip)
content = (char *)bip_malloc((size_t)(stats.st_size + 1));
// validate that content is of stats.st_size size
if (fread(content, (size_t)1, (size_t)stats.st_size, f) !=
(size_t)stats.st_size) {
mylog(LOG_WARN, "Can't read %s fully", bip->oidentdpath);
if (fread(content, (size_t)1, (size_t)stats.st_size, f)
!= (size_t)stats.st_size) {
mylog(LOG_WARN, "Can't read %s fully",
bip->oidentdpath);
free(content);
goto clean_oidentd;
}
@ -2532,32 +2578,37 @@ void oidentd_dump(bip_t *bip)
}
// data preceeding the tag, bipstart >= content (strstr)
fwrite(content, (size_t)1, (size_t)(bipstart - content), f);
fwrite(content, (size_t)1, (size_t)(bipstart - content),
f);
bipend = strstr(bipstart, BIP_OIDENTD_END);
if (bipend == NULL) {
mylog(LOG_WARN, "No %s mark found in %s",
BIP_OIDENTD_END,
bip->oidentdpath);
BIP_OIDENTD_END, bip->oidentdpath);
} else {
/* data following the tag
* ...........BIP_OIDENTD_START...BIP_OIDENTD_END..............
* ^content...^bipstart...........^bipend........^remaining data
* ^content...^bipstart...........^bipend........^remaining
* data
*/
char *remaining = bipend + BIP_OIDENTD_END_LENGTH;
off_t remaining_len = stats.st_size -
(bipend - content) - (off_t)BIP_OIDENTD_END_LENGTH;
char *remaining =
bipend + BIP_OIDENTD_END_LENGTH;
off_t remaining_len =
stats.st_size - (bipend - content)
- (off_t)BIP_OIDENTD_END_LENGTH;
if (remaining_len < 0) {
mylog(LOG_ERROR, "oidentd_dump: error parsing %s",
mylog(LOG_ERROR,
"oidentd_dump: error parsing %s",
bip->oidentdpath);
goto clean_oidentd;
}
fwrite(remaining, (size_t)1, (size_t)remaining_len, f);
fwrite(remaining, (size_t)1,
(size_t)remaining_len, f);
}
} else {
/* No previous conf */
if (stats.st_size != 0 &&
content[stats.st_size - 1] != '\n')
if (stats.st_size != 0
&& content[stats.st_size - 1] != '\n')
fprintf(f, "\n");
}
free(content);
@ -2567,10 +2618,10 @@ void oidentd_dump(bip_t *bip)
list_it_next(&it)) {
connection_t *c = list_it_item(&it);
struct link_any *la = c->user_data;
if (la && TYPE(la) == IRC_TYPE_SERVER && (
c->connected == CONN_OK ||
c->connected == CONN_NEED_SSLIZE ||
c->connected == CONN_UNTRUSTED)) {
if (la && TYPE(la) == IRC_TYPE_SERVER
&& (c->connected == CONN_OK
|| c->connected == CONN_NEED_SSLIZE
|| c->connected == CONN_UNTRUSTED)) {
struct link_server *ls;
struct link *l;
@ -2607,7 +2658,8 @@ void timeout_clean_who_counts(list_t *conns)
time_t now;
now = time(NULL);
if (now - client->whoc_tstamp > 10) {
mylog(LOG_DEBUG, "Yawn, "
mylog(LOG_DEBUG,
"Yawn, "
"forgetting one who reply");
if (client->who_count > 0)
--client->who_count;
@ -2725,8 +2777,10 @@ void bip_on_event(bip_t *bip, connection_t *conn)
line = irc_line_new_from_string(line_s);
if (!line) {
mylog(LOG_ERROR, "[%s] Can not parse line. Link type: %d. "
"closing...", link_name(lc), TYPE(lc));
mylog(LOG_ERROR,
"[%s] Can not parse line. Link type: %d. "
"closing...",
link_name(lc), TYPE(lc));
free(line_s);
goto prot_err_lines;
}
@ -2735,7 +2789,8 @@ void bip_on_event(bip_t *bip, connection_t *conn)
irc_line_free(line);
free(line_s);
if (r == ERR_PROTOCOL) {
mylog(LOG_ERROR, "[%s] Error in protocol. Link type: %d closing...",
mylog(LOG_ERROR,
"[%s] Error in protocol. Link type: %d closing...",
link_name(lc), TYPE(lc));
goto prot_err_lines;
}
@ -2744,7 +2799,6 @@ void bip_on_event(bip_t *bip, connection_t *conn)
/* XXX: not real error */
if (r == OK_CLOSE)
goto prot_err_lines;
}
list_free(linel);
return;
@ -2756,8 +2810,8 @@ prot_err:
if (linel)
list_free(linel);
if (lc) {
if (TYPE(lc) == IRC_TYPE_LOGGING_CLIENT || TYPE(lc) ==
IRC_TYPE_TRUST_CLIENT)
if (TYPE(lc) == IRC_TYPE_LOGGING_CLIENT
|| TYPE(lc) == IRC_TYPE_TRUST_CLIENT)
list_remove(&bip->connecting_client_list, lc);
irc_close(lc);
}
@ -2897,8 +2951,7 @@ static void server_set_chanmodes(struct link_server *l, const char *modes)
mylog(LOG_DEBUG, "[%s] Set chanmodes", LINK(l)->name);
array_each(&l->chanmodes, i, cur)
free(cur);
array_each(&l->chanmodes, i, cur) free(cur);
array_deinit(&l->chanmodes);
// handle four categories, ignore all others
@ -2936,27 +2989,33 @@ static void server_set_prefix(struct link_server *s, const char *modes)
end_mode = strchr(modes + 1, ')'); // skip '('
if (*modes != '(' || !end_mode) {
mylog(LOG_WARN, "[%s] Unable to parse PREFIX parameter", LINK(s)->name);
mylog(LOG_WARN, "[%s] Unable to parse PREFIX parameter",
LINK(s)->name);
return;
}
// end_mode can't be lower than (modes + 1)
len = (size_t)(end_mode - modes - 1); // len of mode without '('
if (len * 2 + 2 != strlen(modes)) {
mylog(LOG_WARN, "[%s] Unable to parse PREFIX parameter", LINK(s)->name);
mylog(LOG_WARN, "[%s] Unable to parse PREFIX parameter",
LINK(s)->name);
return;
}
s->prefixes = bip_realloc(s->prefixes, sizeof(*s->prefixes) * (len + 1));
s->usermodes = bip_realloc(s->usermodes, sizeof(s->usermodes) * (len + 1));
s->prefixes =
bip_realloc(s->prefixes, sizeof(*s->prefixes) * (len + 1));
s->usermodes =
bip_realloc(s->usermodes, sizeof(s->usermodes) * (len + 1));
memcpy(s->usermodes, modes + 1, len);
s->usermodes[len] = 0;
memcpy(s->prefixes, end_mode + 1, len);
s->prefixes[len] = 0;
mylog(LOG_DEBUGVERB, "[%s] user prefix: '%s'", LINK(s)->name, s->prefixes);
mylog(LOG_DEBUGVERB, "[%s] user modes: '%s'", LINK(s)->name, s->usermodes);
mylog(LOG_DEBUGVERB, "[%s] user prefix: '%s'", LINK(s)->name,
s->prefixes);
mylog(LOG_DEBUGVERB, "[%s] user modes: '%s'", LINK(s)->name,
s->usermodes);
}
// Return the position (*1 based*) of car in str, else -1

View File

@ -96,8 +96,7 @@ struct bipuser {
char in_use; /* for mark and sweep on reload */
};
struct network
{
struct network {
char *name;
#ifdef HAVE_LIBSSL
int ssl;
@ -284,4 +283,3 @@ void irc_cli_backlog(struct link_client *ic, int hours);
#define BIP_FAKEMASK "!bip@bip.bip.bip"
#endif

View File

@ -16,7 +16,8 @@
#include "line.h"
#include "util.h"
// TODO resolve assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1
// TODO resolve assuming signed overflow does not occur when changing X +- C1
// cmp C2 to X cmp C2 -+ C1
#pragma GCC diagnostic ignored "-Wstrict-overflow"
void irc_line_init(struct line *l)

133
src/log.c
View File

@ -61,8 +61,7 @@ int check_dir(char *filename, int is_fatal)
} else if (err) {
if (is_fatal)
fatal("stat(%s) %s", filename, strerror(errno));
mylog(LOG_ERROR, "stat(%s) %s", filename,
strerror(errno));
mylog(LOG_ERROR, "stat(%s) %s", filename, strerror(errno));
return 1;
} else if (!(statbuf.st_mode & S_IFDIR)) {
if (is_fatal)
@ -114,7 +113,8 @@ void strtolower(char *str)
char *c;
for (c = str; *c != '\0'; c++)
*c = (char)tolower(*c); // tolower()->int but should be safe to cast
*c = (char)tolower(
*c); // tolower()->int but should be safe to cast
}
/*
@ -201,8 +201,8 @@ static void log_reset(logstore_t *store)
return;
}
while ((olf = list_get_first(&store->file_group)) &&
olf != list_get_last(&store->file_group)) {
while ((olf = list_get_first(&store->file_group))
&& olf != list_get_last(&store->file_group)) {
logfile_free(olf);
list_remove_first(&store->file_group);
}
@ -413,8 +413,8 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
time(&t);
ltime = localtime(&t);
if (ltime->tm_year != lf->last_log.tm_year ||
ltime->tm_yday != lf->last_log.tm_yday) {
if (ltime->tm_year != lf->last_log.tm_year
|| ltime->tm_yday != lf->last_log.tm_yday) {
logfile_t *oldlf;
/* day changed, we might want to rotate logfile */
@ -443,8 +443,8 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
/* remove oldlf from file_group */
assert(list_remove_first(&store->file_group) == oldlf);
logfile_free(oldlf);
assert(list_get_first(&store->file_group) ==
list_get_last(&store->file_group));
assert(list_get_first(&store->file_group)
== list_get_last(&store->file_group));
} else {
fclose(oldlf->file);
oldlf->file = NULL;
@ -456,8 +456,7 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
void log_join(log_t *logdata, const char *ircmask, const char *channel)
{
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has joined %s", timestamp(), ircmask,
channel);
"%s -!- %s has joined %s", timestamp(), ircmask, channel);
log_write(logdata, channel, logdata->buffer);
}
@ -479,8 +478,8 @@ void log_kick(log_t *logdata, const char *ircmask, const char *channel,
const char *who, const char *message)
{
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has been kicked by %s [%s]", timestamp(),
who, ircmask, message);
"%s -!- %s has been kicked by %s [%s]", timestamp(), who,
ircmask, message);
log_write(logdata, channel, logdata->buffer);
}
@ -488,8 +487,7 @@ void log_quit(log_t *logdata, const char *ircmask, const char *channel,
const char *message)
{
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has quit [%s]", timestamp(), ircmask,
message);
"%s -!- %s has quit [%s]", timestamp(), ircmask, message);
log_write(logdata, channel, logdata->buffer);
}
@ -510,8 +508,7 @@ void log_nick(log_t *logdata, const char *ircmask, const char *channel,
free(oldnick);
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s is now known as %s",
timestamp(), ircmask, newnick);
"%s -!- %s is now known as %s", timestamp(), ircmask, newnick);
log_write(logdata, channel, logdata->buffer);
}
@ -525,10 +522,11 @@ static void do_log_privmsg(log_t *logdata, const char *storage, int src,
if (src)
dir = '>';
if (strlen(message) > 8 && ((*message == '\001' ||
((*message == '+' || *message == '-') &&
(*(message + 1) == '\001'))) &&
(*(message + strlen(message) - 1) == '\001'))) {
if (strlen(message) > 8
&& ((*message == '\001'
|| ((*message == '+' || *message == '-')
&& (*(message + 1) == '\001')))
&& (*(message + strlen(message) - 1) == '\001'))) {
char *msg;
/* hack for freenode and the like */
const char *real_message = message;
@ -541,13 +539,11 @@ static void do_log_privmsg(log_t *logdata, const char *storage, int src,
msg = bip_strdup(real_message);
*(msg + strlen(msg) - 1) = '\0';
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s %c * %s %s", timestamp(), dir,
from, msg + 8);
"%s %c * %s %s", timestamp(), dir, from, msg + 8);
free(msg);
} else {
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s %c %s: %s", timestamp(), dir,
from, message);
"%s %c %s: %s", timestamp(), dir, from, message);
}
log_write(logdata, storage, logdata->buffer);
}
@ -604,16 +600,15 @@ void log_topic(log_t *logdata, const char *ircmask, const char *channel,
const char *message)
{
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s changed topic of %s to: %s", timestamp(),
ircmask, channel, message);
"%s -!- %s changed topic of %s to: %s", timestamp(), ircmask,
channel, message);
log_write(logdata, channel, logdata->buffer);
}
void log_init_topic(log_t *logdata, const char *channel, const char *message)
{
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Topic for %s: %s", timestamp(), channel,
message);
"%s -!- Topic for %s: %s", timestamp(), channel, message);
log_write(logdata, channel, logdata->buffer);
}
@ -633,8 +628,7 @@ void log_init_topic_time(log_t *logdata, const char *channel, const char *who,
timestr[50] = '\0';
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Topic set by %s [%s]", timestamp(), who,
timestr);
"%s -!- Topic set by %s [%s]", timestamp(), who, timestr);
free(timestr);
log_write(logdata, channel, logdata->buffer);
}
@ -647,20 +641,20 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel,
char *tmpbuf2 = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
char *tmp;
snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN,
"%s -!- mode/%s [%s", timestamp(), channel, modes);
snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN, "%s -!- mode/%s [%s",
timestamp(), channel, modes);
if (mode_args) {
for (i = 0; i < array_count(mode_args); i++) {
snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s", tmpbuf,
(const char*)array_get(mode_args, i));
snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s",
tmpbuf, (const char *)array_get(mode_args, i));
tmp = tmpbuf;
tmpbuf = tmpbuf2;
tmpbuf2 = tmp;
}
}
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s",
tmpbuf, ircmask);
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s", tmpbuf,
ircmask);
log_write(logdata, channel, logdata->buffer);
free(tmpbuf);
@ -670,8 +664,10 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel,
void log_disconnected(log_t *logdata)
{
hash_iterator_t hi;
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Disconnected"
" from server...", timestamp());
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Disconnected"
" from server...",
timestamp());
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
hash_it_next(&hi))
log_write(logdata, hash_it_key(&hi), logdata->buffer);
@ -696,8 +692,10 @@ void log_connected(log_t *logdata)
{
hash_iterator_t hi;
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Connected to"
" server...", timestamp());
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Connected to"
" server...",
timestamp());
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
hash_it_next(&hi)) {
log_write(logdata, hash_it_key(&hi), logdata->buffer);
@ -811,7 +809,8 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
logfile_t *lf;
while ((lf = list_it_item(&store->file_it))) {
//mylog(LOG_ERROR, "LOG: %s %d", lf->filename, store->file_offset);
// mylog(LOG_ERROR, "LOG: %s %d", lf->filename,
// store->file_offset);
if (!lf->file) {
lf->file = fopen(lf->filename, "r");
if (!lf->file) {
@ -822,7 +821,8 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
}
}
if (fseek(lf->file, store->file_offset, SEEK_SET)) {
//mylog(LOG_ERROR, "LOG: fseek FAIL %s %d", lf->filename, store->file_offset);
// mylog(LOG_ERROR, "LOG: fseek FAIL %s %d",
// lf->filename, store->file_offset);
log_reinit(store);
return;
}
@ -830,16 +830,20 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
while ((c = fgetc(lf->file)) != EOF) {
store->file_offset++;
if (c == '\n') {
//mylog(LOG_ERROR, "LOG: %s advanced at %d", lf->filename, store->file_offset);
// mylog(LOG_ERROR, "LOG: %s advanced at %d",
// lf->filename, store->file_offset);
return;
}
}
//mylog(LOG_ERROR, "LOG: %s advanced at %d", lf->filename, store->file_offset);
// mylog(LOG_ERROR, "LOG: %s advanced at %d", lf->filename,
// store->file_offset);
if (lf == list_get_last(&store->file_group)) {
//mylog(LOG_ERROR, "LOG: %s is last of file_group", lf->filename, store->file_offset);
// mylog(LOG_ERROR, "LOG: %s is last of file_group",
// lf->filename, store->file_offset);
return;
}
//mylog(LOG_ERROR, "LOG: next file %s %d", lf->filename, store->file_offset);
// mylog(LOG_ERROR, "LOG: next file %s %d", lf->filename,
// store->file_offset);
fclose(lf->file);
lf->file = NULL;
list_it_next(&store->file_it);
@ -962,10 +966,10 @@ char *log_beautify(log_t *logdata, const char *buf, const char *storename,
return _log_wrap(dest, buf);
// action and out are 0 or 1, safe to cast
p = ret = (char *)bip_malloc(
1 + lon + strlen(LAMESTRING) + strlen(dest) + 2 + lots + 2 +
lom + 3 + (size_t)action * (2 + strlen("ACTION ")) +
(size_t)out * strlen(PMSG_ARROW));
p = ret = (char *)bip_malloc(1 + lon + strlen(LAMESTRING) + strlen(dest)
+ 2 + lots + 2 + lom + 3
+ (size_t)action * (2 + strlen("ACTION "))
+ (size_t)out * strlen(PMSG_ARROW));
*p++ = ':';
@ -1059,7 +1063,8 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
*/
if (fseek(lf->file, store->file_offset, SEEK_SET)) {
mylog(LOG_ERROR, "Can't seek in %s", lf->filename);
list_add_last(res, _log_wrap(store->name,
list_add_last(res,
_log_wrap(store->name,
"Error seeking in logfile"));
return 0;
}
@ -1067,7 +1072,8 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
// mylog(LOG_ERROR, "bread Seeking %s to %d", lf->filename, 0);
if (fseek(lf->file, (long)0, SEEK_SET)) {
mylog(LOG_ERROR, "Can't seek in %s", lf->filename);
list_add_last(res, _log_wrap(store->name,
list_add_last(res,
_log_wrap(store->name,
"Error seeking in logfile"));
return 0;
}
@ -1078,7 +1084,8 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
if (!fgets(buf, LOGLINE_MAXLEN, lf->file)) {
if (ferror(lf->file)) {
list_add_last(res, _log_wrap("Error reading "
"logfile", store->name));
"logfile",
store->name));
}
/* error or oef */
break;
@ -1109,7 +1116,6 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
logbr = log_beautify(log, buf, store->name, dest);
if (logbr)
list_add_last(res, logbr);
}
if (close) {
fclose(lf->file);
@ -1153,8 +1159,7 @@ static list_t *log_backread(log_t *log, const char *storename, const char *dest)
logfile_t *logf;
ret = list_new(NULL);
for (file_it = store->file_it;
(logf = list_it_item(&file_it));
for (file_it = store->file_it; (logf = list_it_item(&file_it));
list_it_next(&file_it)) {
if (!log_backread_file(log, store, logf, ret, dest,
(time_t)0)) {
@ -1201,8 +1206,8 @@ static size_t _log_write(log_t *logdata, logstore_t *store,
tmpstr[LOGLINE_MAXLEN] = 0;
if (store->memlog) {
char *r = log_beautify(logdata, tmpstr, store->name,
destination);
char *r =
log_beautify(logdata, tmpstr, store->name, destination);
if (r != NULL) {
list_add_last(store->memlog, r);
if (store->memc == logdata->user->backlog_lines)
@ -1320,7 +1325,8 @@ array_t *str_split(const char *str, const char *splt)
const char *start = str;
size_t len;
char *extracted;
array_t *array = array_new();;
array_t *array = array_new();
;
do {
if (!*p || strchr(splt, *p)) {
@ -1358,8 +1364,7 @@ int log_parse_date(char *strdate, int *year, int *month, int *mday, int *hour,
ret = 1;
}
int i;
array_each(fields, i, sptr)
free(sptr);
array_each(fields, i, sptr) free(sptr);
array_free(fields);
return ret;
@ -1397,8 +1402,7 @@ static list_t *log_backread_hours(log_t *log, const char *storename,
ret = list_new(NULL);
for (logstore_get_file_at(store, blstarttime, &file_it);
(logf = list_it_item(&file_it));
list_it_next(&file_it)) {
(logf = list_it_item(&file_it)); list_it_next(&file_it)) {
if (!log_backread_file(log, store, logf, ret, dest,
blstarttime)) {
log_reinit(store);
@ -1454,4 +1458,3 @@ list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
}
return ret;
}

View File

@ -29,8 +29,7 @@
struct list;
typedef struct logfile
{
typedef struct logfile {
FILE *file;
char *filename;
char *canonical_filename;
@ -38,8 +37,7 @@ typedef struct logfile
size_t len;
} logfile_t;
typedef struct logstore
{
typedef struct logstore {
char *name;
list_t file_group;
int skip_advance;
@ -51,8 +49,7 @@ typedef struct logstore
long file_offset;
} logstore_t;
typedef struct log
{
typedef struct log {
hash_t logfgs;
char *network;
char *buffer;

View File

@ -27,8 +27,7 @@
#define GET_UINT32(n, b, i) \
{ \
(n) = ( (uint32) (b)[(i) ] ) \
| ( (uint32) (b)[(i) + 1] << 8 ) \
(n) = ((uint32)(b)[(i)]) | ((uint32)(b)[(i) + 1] << 8) \
| ((uint32)(b)[(i) + 2] << 16) \
| ((uint32)(b)[(i) + 3] << 24); \
}
@ -77,7 +76,8 @@ void md5_process( md5_context *ctx, uint8 data[64] )
#define P(a, b, c, d, k, s, t) \
{ \
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
a += F(b, c, d) + X[k] + t; \
a = S(a, s) + b; \
}
A = ctx->state[0];
@ -179,7 +179,8 @@ void md5_update( md5_context *ctx, uint8 *input, uint32 length )
{
uint32 left, fill;
if( ! length ) return;
if (!length)
return;
left = ctx->total[0] & 0x3F;
fill = 64 - left;
@ -190,37 +191,29 @@ void md5_update( md5_context *ctx, uint8 *input, uint32 length )
if (ctx->total[0] < length)
ctx->total[1]++;
if( left && length >= fill )
{
memcpy( (void *) (ctx->buffer + left),
(void *) input, fill );
if (left && length >= fill) {
memcpy((void *)(ctx->buffer + left), (void *)input, fill);
md5_process(ctx, ctx->buffer);
length -= fill;
input += fill;
left = 0;
}
while( length >= 64 )
{
while (length >= 64) {
md5_process(ctx, input);
length -= 64;
input += 64;
}
if( length )
{
memcpy( (void *) (ctx->buffer + left),
(void *) input, length );
if (length) {
memcpy((void *)(ctx->buffer + left), (void *)input, length);
}
}
static uint8 md5_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
};
static uint8 md5_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};
void md5_finish(md5_context *ctx, uint8 digest[16])
{
@ -228,8 +221,7 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
uint32 high, low;
uint8 msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32(low, msglen, 0);
@ -256,28 +248,21 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
* those are the standard RFC 1321 test vectors
*/
static char *msg[] =
{
static char *msg[] = {
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012" \
"345678901234567890"
};
"12345678901234567890123456789012345678901234567890123456789012"
"345678901234567890"};
static char *val[] =
{
"d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a"
};
static char *val[] = {
"d41d8cd98f00b204e9800998ecf8427e", "0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72", "f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b", "d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a"};
int main(int argc, char *argv[])
{
@ -288,25 +273,21 @@ int main( int argc, char *argv[] )
unsigned char buf[1000];
unsigned char md5sum[16];
if( argc < 2 )
{
if (argc < 2) {
printf("\n MD5 Validation Tests:\n\n");
for( i = 0; i < 7; i++ )
{
for (i = 0; i < 7; i++) {
printf(" Test %d ", i + 1);
md5_starts(&ctx);
md5_update(&ctx, (uint8 *)msg[i], strlen(msg[i]));
md5_finish(&ctx, md5sum);
for( j = 0; j < 16; j++ )
{
for (j = 0; j < 16; j++) {
sprintf(output + j * 2, "%02x", md5sum[j]);
}
if( memcmp( output, val[i], 32 ) )
{
if (memcmp(output, val[i], 32)) {
printf("failed!\n");
return (1);
}
@ -315,26 +296,21 @@ int main( int argc, char *argv[] )
}
printf("\n");
}
else
{
if( ! ( f = fopen( argv[1], "rb" ) ) )
{
} else {
if (!(f = fopen(argv[1], "rb"))) {
perror("fopen");
return (1);
}
md5_starts(&ctx);
while( ( i = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
{
while ((i = fread(buf, 1, sizeof(buf), f)) > 0) {
md5_update(&ctx, buf, i);
}
md5_finish(&ctx, md5sum);
for( j = 0; j < 16; j++ )
{
for (j = 0; j < 16; j++) {
printf("%02x", md5sum[j]);
}
@ -360,7 +336,8 @@ unsigned char *chash_double(char *str, unsigned int seed)
length = strlen(str);
length += 4;
ptr = bip_malloc(length);
// conversion from unsigned int to unsigned char may change value [-Werror=conversion]
// conversion from unsigned int to unsigned char may change value
// [-Werror=conversion]
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
ptr[0] = seed >> 24 & 0xff;
@ -399,4 +376,3 @@ int chash_cmp(char *try, unsigned char *pass, unsigned int seed)
free(try_hash);
return 0;
}

View File

@ -9,15 +9,12 @@
#define uint32 unsigned long int
#endif
typedef struct
{
typedef struct {
uint32 total[2];
uint32 state[4];
uint8 buffer[64];
}
md5_context;
} md5_context;
int chash_cmp(char *try, unsigned char *pass,
unsigned int seed);
int chash_cmp(char *try, unsigned char *pass, unsigned int seed);
unsigned char *chash_double(char *str, unsigned int seed);
#endif /* md5.h */

View File

@ -107,7 +107,8 @@ char *bip_strcat_fit(size_t *remaining, char *str, const char *str2)
res = memccpy(str, str2, '\0', *remaining);
if (!res) {
mylog(LOG_DEBUGTOOMUCH, "bip_strcat_fit: memccpy() failed, remaining %lu",
mylog(LOG_DEBUGTOOMUCH,
"bip_strcat_fit: memccpy() failed, remaining %lu",
*remaining);
return NULL;
}
@ -135,7 +136,8 @@ char *bip_strcatf_fit(size_t *remaining, char *str, const char *fmt, ...)
}
if (*remaining > STRCATF_BUF_MAXLEN) {
mylog(LOG_ERROR, "bip_strcatf_fit: remaining "
mylog(LOG_ERROR,
"bip_strcatf_fit: remaining "
"is over STRCATF_BUF_MAXLEN");
}
@ -149,14 +151,17 @@ char *bip_strcatf_fit(size_t *remaining, char *str, const char *fmt, ...)
}
if ((unsigned)written >= *remaining) {
mylog(LOG_DEBUGVERB, "bip_strcatf_fit,vsnprintf: no space left");
mylog(LOG_DEBUGVERB,
"bip_strcatf_fit,vsnprintf: no space left");
goto end;
}
res = memccpy(str, str2, '\0', *remaining);
if (!res) {
mylog(LOG_DEBUGTOOMUCH, "bip_strcatf_fit: memccpy() failed, "
"remaining %lu", *remaining);
mylog(LOG_DEBUGTOOMUCH,
"bip_strcatf_fit: memccpy() failed, "
"remaining %lu",
*remaining);
goto end;
}
@ -194,10 +199,10 @@ int is_valid_nick(char *str)
return 0;
tmp = str;
while (*tmp != '\0' && (isalnum(*tmp) || *tmp == '-' || *tmp == '[' ||
*tmp == ']' || *tmp == '\\' || *tmp == '`' ||
*tmp == '^' || *tmp == '{' || *tmp == '}' ||
*tmp == '|' || *tmp == '_' ))
while (*tmp != '\0'
&& (isalnum(*tmp) || *tmp == '-' || *tmp == '[' || *tmp == ']'
|| *tmp == '\\' || *tmp == '`' || *tmp == '^' || *tmp == '{'
|| *tmp == '}' || *tmp == '|' || *tmp == '_'))
tmp++;
return (*tmp == '\0');
}
@ -209,8 +214,8 @@ int is_valid_username(char *str)
return 0;
tmp = str;
while (*tmp != '\0' && *tmp != ' ' && *tmp != '\0' && *tmp != '\r' &&
*tmp != '\n')
while (*tmp != '\0' && *tmp != ' ' && *tmp != '\0' && *tmp != '\r'
&& *tmp != '\n')
tmp++;
return (*tmp == '\0');
}
@ -606,13 +611,13 @@ void hash_init(hash_t *h, int options)
switch (options) {
case HASH_NOCASE:
list_init(&h->lists[i],
(int (*)(const void*, const void*))
hash_item_nocase_cmp);
(int (*)(const void *,
const void *))hash_item_nocase_cmp);
break;
case HASH_DEFAULT:
list_init(&h->lists[i],
(int (*)(const void*,const void*))
hash_item_cmp);
(int (*)(const void *,
const void *))hash_item_cmp);
break;
default:
fatal("wrong hash option %d", options);

View File

@ -74,16 +74,20 @@ typedef struct array {
const void **elemv;
} array_t;
#define MOVE_STRING(dest, src) do {\
#define MOVE_STRING(dest, src) \
do { \
if (dest) \
free(dest); \
(dest) = (src); \
(src) = NULL; \
} while (0)
#define FREE(a) free(a); (a) = NULL;
#define FREE(a) \
free(a); \
(a) = NULL;
#define MAYFREE(a) do { \
#define MAYFREE(a) \
do { \
if (a) { \
free(a); \
(a) = NULL; \
@ -93,15 +97,16 @@ typedef struct array {
#define assert(condition) \
do { \
if (!(condition)) \
fatal("Failed assertion in " __FILE__ "(%d): " \
#condition, __LINE__); \
fatal("Failed assertion in " __FILE__ \
"(%d): " #condition, \
__LINE__); \
} while (0)
#define assert_msg(condition, msg) \
do { \
if (!(condition)) \
fatal("%s in " __FILE__ "(%d): " \
#condition, (msg), __LINE__); \
fatal("%s in " __FILE__ "(%d): " #condition, (msg), \
__LINE__); \
} while (0)
void list_init(list_t *list, int (*cmp)(const void *, const void *));
@ -183,8 +188,9 @@ char *bip_strdup(const char *str);
char *bip_strcat_fit(size_t *remaining, char *str, const char *str2);
char *bip_strcatf_fit(size_t *remaining, char *str, const char *str2, ...);
void bip_clock_gettime(clockid_t clockid, struct timespec *tp);
#define array_each(a, idx, ptr) for ((idx) = 0; \
(idx) < (a)->elemc && (((ptr) = bip_strdup(array_get((a), (idx)))) || 1); \
#define array_each(a, idx, ptr) \
for ((idx) = 0; (idx) < (a)->elemc \
&& (((ptr) = bip_strdup(array_get((a), (idx)))) || 1); \
(idx)++)
void array_init(array_t *a);

View File

@ -72,8 +72,8 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
*pos++ = base64_table[(in[0] & 0x03) << 4];
*pos++ = '=';
} else {
*pos++ = base64_table[((in[0] & 0x03) << 4) |
(in[1] >> 4)];
*pos++ = base64_table[((in[0] & 0x03) << 4)
| (in[1] >> 4)];
*pos++ = base64_table[(in[1] & 0x0f) << 2];
}
*pos++ = '=';
@ -91,4 +91,3 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
*out_len = (size_t)(pos - out);
return out;
}