Fixes for kyo's merge.
A few rare snprintf bugs. Mostly cosmetic and cleanness stuff.
This commit is contained in:
parent
dd49be1755
commit
dbe633ec59
@ -136,7 +136,7 @@ user {
|
|||||||
name = "iiens"; # used by bip only
|
name = "iiens"; # used by bip only
|
||||||
network = "iiens"; # which ircnet to connect to
|
network = "iiens"; # which ircnet to connect to
|
||||||
|
|
||||||
# You can precise ssl_check_mode here, if you want a different
|
# You can define ssl_check_mode here, if you want a different
|
||||||
# behavior than the one defined in the parent user {}.
|
# behavior than the one defined in the parent user {}.
|
||||||
#ssl_check_mode = "none";
|
#ssl_check_mode = "none";
|
||||||
|
|
||||||
|
349
src/bip.c
349
src/bip.c
@ -450,9 +450,9 @@ static int add_connection(bip_t *bip, struct user *user, list_t *data)
|
|||||||
break;
|
break;
|
||||||
#ifdef HAVE_LIBSSL
|
#ifdef HAVE_LIBSSL
|
||||||
case LEX_SSL_CHECK_MODE:
|
case LEX_SSL_CHECK_MODE:
|
||||||
if (!strncmp(t->pdata, "basic", 5))
|
if (strcmp(t->pdata, "basic") == 0)
|
||||||
l->ssl_check_mode = SSL_CHECK_BASIC;
|
l->ssl_check_mode = SSL_CHECK_BASIC;
|
||||||
if (!strncmp(t->pdata, "ca", 2))
|
if (strcmp(t->pdata, "ca") == 0)
|
||||||
l->ssl_check_mode = SSL_CHECK_CA;
|
l->ssl_check_mode = SSL_CHECK_CA;
|
||||||
free(t->pdata);
|
free(t->pdata);
|
||||||
break;
|
break;
|
||||||
@ -469,12 +469,21 @@ static int add_connection(bip_t *bip, struct user *user, list_t *data)
|
|||||||
/* checks that can only be here, or must */
|
/* checks that can only be here, or must */
|
||||||
if (!l->network)
|
if (!l->network)
|
||||||
conf_die("Missing network in connection block");
|
conf_die("Missing network in connection block");
|
||||||
if (!l->connect_nick)
|
if (!l->connect_nick) {
|
||||||
|
if (!user->default_nick)
|
||||||
|
conf_die("No nick set and no default nick.");
|
||||||
l->connect_nick = strdup(user->default_nick);
|
l->connect_nick = strdup(user->default_nick);
|
||||||
if (!l->username)
|
}
|
||||||
|
if (!l->username) {
|
||||||
|
if (!user->username)
|
||||||
|
conf_die("No username set and no default username.");
|
||||||
l->username = strdup(user->default_username);
|
l->username = strdup(user->default_username);
|
||||||
if (!l->realname)
|
}
|
||||||
|
if (!l->realname) {
|
||||||
|
if (!user->realname)
|
||||||
|
conf_die("No realname set and no default realname.");
|
||||||
l->realname = strdup(user->default_realname);
|
l->realname = strdup(user->default_realname);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,16 +663,6 @@ static int validate_config(bip_t *bip)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning CODE ME -> DONE BY KYOSHIRO ?
|
|
||||||
#if 0
|
|
||||||
if (conf_backlog && !conf_log) {
|
|
||||||
if (conf_backlog_lines == 0) {
|
|
||||||
conf_die("You must set conf_backlog_lines if "
|
|
||||||
"conf_log = false and "
|
|
||||||
"conf_backlog = true");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,6 +717,32 @@ int fireup(bip_t *bip, FILE *conf)
|
|||||||
add_user(bip, t->pdata);
|
add_user(bip, t->pdata);
|
||||||
list_free(t->pdata);
|
list_free(t->pdata);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#warning deprecated but we still need to support these
|
||||||
|
#if 0
|
||||||
|
case LEX_ALWAYS_BACKLOG:
|
||||||
|
conf_always_backlog = t->ndata;
|
||||||
|
break;
|
||||||
|
case LEX_BACKLOG:
|
||||||
|
conf_backlog = t->ndata;
|
||||||
|
break;
|
||||||
|
case LEX_BL_MSG_ONLY:
|
||||||
|
conf_bl_msg_only = t->ndata;
|
||||||
|
break;
|
||||||
|
case LEX_BACKLOG_LINES:
|
||||||
|
conf_backlog_lines = t->ndata;
|
||||||
|
break;
|
||||||
|
case LEX_BACKLOG_NO_TIMESTAMP:
|
||||||
|
conf_backlog_no_timestamp = t->ndata;
|
||||||
|
break;
|
||||||
|
case LEX_BLRESET_ON_TALK:
|
||||||
|
conf_blreset_on_talk = t->ndata;
|
||||||
|
break;
|
||||||
|
/* end of deprectated */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
conf_die("Config error in base config (%d)", t->type);
|
conf_die("Config error in base config (%d)", t->type);
|
||||||
}
|
}
|
||||||
@ -758,18 +783,20 @@ void check_rlimits()
|
|||||||
|
|
||||||
r = getrlimit(RLIMIT_AS, <);
|
r = getrlimit(RLIMIT_AS, <);
|
||||||
if (r) {
|
if (r) {
|
||||||
mylog(LOG_ERROR, "getrlimit(): failed with %s", strerror(errno));
|
mylog(LOG_ERROR, "getrlimit(): failed with %s",
|
||||||
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (lt.rlim_max != RLIM_INFINITY) {
|
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");
|
"bip may be KILLED by the system");
|
||||||
cklim = 1;
|
cklim = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = getrlimit(RLIMIT_CPU, <);
|
r = getrlimit(RLIMIT_CPU, <);
|
||||||
if (r) {
|
if (r) {
|
||||||
mylog(LOG_ERROR, "getrlimit(): failed with %s", strerror(errno));
|
mylog(LOG_ERROR, "getrlimit(): failed with %s",
|
||||||
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (lt.rlim_max != RLIM_INFINITY) {
|
if (lt.rlim_max != RLIM_INFINITY) {
|
||||||
mylog(LOG_WARN, "CPU rlimit active, bip may "
|
mylog(LOG_WARN, "CPU rlimit active, bip may "
|
||||||
@ -780,10 +807,11 @@ void check_rlimits()
|
|||||||
|
|
||||||
r = getrlimit(RLIMIT_FSIZE, <);
|
r = getrlimit(RLIMIT_FSIZE, <);
|
||||||
if (r) {
|
if (r) {
|
||||||
mylog(LOG_ERROR, "getrlimit(): failed with %s", strerror(errno));
|
mylog(LOG_ERROR, "getrlimit(): failed with %s",
|
||||||
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (lt.rlim_max != RLIM_INFINITY) {
|
if (lt.rlim_max != RLIM_INFINITY) {
|
||||||
mylog(LOG_WARN, "FSIZE rlimit active, bip'll"
|
mylog(LOG_WARN, "FSIZE rlimit active, bip will "
|
||||||
"fail to create files of size greater than "
|
"fail to create files of size greater than "
|
||||||
"%d bytes.", (int)lt.rlim_max);
|
"%d bytes.", (int)lt.rlim_max);
|
||||||
cklim = 1;
|
cklim = 1;
|
||||||
@ -792,11 +820,12 @@ void check_rlimits()
|
|||||||
|
|
||||||
r = getrlimit(RLIMIT_NOFILE, <);
|
r = getrlimit(RLIMIT_NOFILE, <);
|
||||||
if (r) {
|
if (r) {
|
||||||
mylog(LOG_ERROR, "getrlimit(): failed with %s", strerror(errno));
|
mylog(LOG_ERROR, "getrlimit(): failed with %s",
|
||||||
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (lt.rlim_max != RLIM_INFINITY) {
|
if (lt.rlim_max != RLIM_INFINITY) {
|
||||||
mylog(LOG_WARN, "opened files count rlimit "
|
mylog(LOG_WARN, "opened files count rlimit "
|
||||||
"active, bip'll not be allowed to open more"
|
"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;
|
cklim = 1;
|
||||||
}
|
}
|
||||||
@ -804,11 +833,12 @@ void check_rlimits()
|
|||||||
|
|
||||||
r = getrlimit(RLIMIT_STACK, <);
|
r = getrlimit(RLIMIT_STACK, <);
|
||||||
if (r) {
|
if (r) {
|
||||||
mylog(LOG_ERROR, "getrlimit(): failed with %s", strerror(errno));
|
mylog(LOG_ERROR, "getrlimit(): failed with %s",
|
||||||
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (lt.rlim_max != RLIM_INFINITY) {
|
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");
|
"bip may be KILLED by the system");
|
||||||
cklim = 1;
|
cklim = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -981,120 +1011,168 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adm_print_connection(struct link_client *ic, struct link *lnk, struct user *bu)
|
#define RET_STR_LEN 256
|
||||||
|
#define LINE_SIZE_LIM 70
|
||||||
|
void adm_print_connection(struct link_client *ic, struct link *lnk,
|
||||||
|
struct user *bu)
|
||||||
{
|
{
|
||||||
hash_iterator_t lit;
|
hash_iterator_t lit;
|
||||||
char buf[4096];
|
char buf[RET_STR_LEN + 1];
|
||||||
int t_wrote = 0;
|
int t_wrote = 0;
|
||||||
int t_max_len = 70;
|
|
||||||
|
|
||||||
if (!bu) {
|
if (!bu) {
|
||||||
bu = lnk->user;
|
bu = lnk->user;
|
||||||
snprintf(buf, 4095, "%s's links:", bu->name);
|
snprintf(buf, RET_STR_LEN, "%s's links:", bu->name);
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, 4095, "* %s to %s as \"%s\" (%s!%s) :",
|
snprintf(buf, RET_STR_LEN, "* %s to %s as \"%s\" (%s!%s) :",
|
||||||
lnk->name, lnk->network->name,
|
lnk->name, lnk->network->name,
|
||||||
(lnk->realname ? lnk->realname : bu->default_realname),
|
(lnk->realname ? lnk->realname : bu->default_realname),
|
||||||
(lnk->connect_nick ? lnk->connect_nick : bu->default_nick),
|
(lnk->connect_nick ? lnk->connect_nick : bu->default_nick),
|
||||||
(lnk->username ? lnk->username : bu->default_username)
|
(lnk->username ? lnk->username : bu->default_username)
|
||||||
);
|
);
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
|
|
||||||
t_wrote += snprintf(buf, 4095, " Options:");
|
t_wrote = snprintf(buf, RET_STR_LEN, " Options:");
|
||||||
if (lnk->follow_nick)
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
if (lnk->follow_nick) {
|
||||||
t_wrote += snprintf(buf + t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
4095 - t_wrote, " follow_nick");
|
RET_STR_LEN - t_wrote, " follow_nick");
|
||||||
if (lnk->ignore_first_nick)
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
if (lnk->ignore_first_nick) {
|
||||||
t_wrote += snprintf(buf + t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
4095 - t_wrote, " ignore_first_nick");
|
RET_STR_LEN - t_wrote, " ignore_first_nick");
|
||||||
if (lnk->away_nick)
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
if (lnk->away_nick) {
|
||||||
t_wrote += snprintf(buf + t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
4095 - t_wrote, " away_nick=%s",
|
RET_STR_LEN - t_wrote, " away_nick=%s",
|
||||||
lnk->away_nick);
|
lnk->away_nick);
|
||||||
if (lnk->no_client_away_msg)
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
if (lnk->no_client_away_msg) {
|
||||||
t_wrote += snprintf(buf + t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
4095 - t_wrote, " no_client_away_msg=%s",
|
RET_STR_LEN - t_wrote, " no_client_away_msg=%s",
|
||||||
lnk->no_client_away_msg);
|
lnk->no_client_away_msg);
|
||||||
if (lnk->vhost)
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
if (lnk->vhost) {
|
||||||
t_wrote += snprintf(buf + t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
4095 - t_wrote, " vhost=%s",
|
RET_STR_LEN - t_wrote, " vhost=%s",
|
||||||
lnk->vhost);
|
lnk->vhost);
|
||||||
if (lnk->bind_port)
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
if (lnk->bind_port) {
|
||||||
t_wrote += snprintf(buf + t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
4095 - t_wrote, " bind_port=%u",
|
RET_STR_LEN - t_wrote, " bind_port=%u",
|
||||||
lnk->bind_port);
|
lnk->bind_port);
|
||||||
buf[4095] = 0;
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
noroom: /* that means the line is larger that RET_STR_LEN. We're not likely to
|
||||||
|
even read such a long line */
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
|
|
||||||
// TODO: on_connect_send
|
// TODO: on_connect_send
|
||||||
|
|
||||||
// TODO : check channels struct
|
// TODO : check channels struct
|
||||||
t_wrote = snprintf(buf, 4095, " Channels:");
|
t_wrote = snprintf(buf, RET_STR_LEN, " Channels:");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomchan;
|
||||||
for (hash_it_init(&lnk->chan_infos, &lit); hash_it_item(&lit);
|
for (hash_it_init(&lnk->chan_infos, &lit); hash_it_item(&lit);
|
||||||
hash_it_next(&lit)) {
|
hash_it_next(&lit)) {
|
||||||
struct channel *ch = hash_it_item(&lit);
|
struct channel *ch = hash_it_item(&lit);
|
||||||
|
|
||||||
if (ch->key) {
|
if (ch->key) {
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN
|
||||||
- t_wrote, " *%s", ch->name);
|
- t_wrote, " *%s", ch->name);
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomchan;
|
||||||
} else {
|
} else {
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN
|
||||||
- t_wrote, " %s", ch->name);
|
- t_wrote, " %s", ch->name);
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomchan;
|
||||||
}
|
}
|
||||||
if (t_wrote > t_max_len) {
|
if (t_wrote > LINE_SIZE_LIM) {
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
t_wrote = 0;
|
t_wrote = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf[4095] = 0;
|
noroomchan:
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
|
|
||||||
t_wrote = snprintf(buf, 4095, " Status: ");
|
t_wrote = snprintf(buf, RET_STR_LEN, " Status: ");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
switch (lnk->s_state) {
|
switch (lnk->s_state) {
|
||||||
case IRCS_NONE:
|
case IRCS_NONE:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"not started");
|
"not started");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
case IRCS_CONNECTING:
|
case IRCS_CONNECTING:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"connecting... attempts: %d, last: %s",
|
"connecting... attempts: %d, last: %s",
|
||||||
lnk->s_conn_attempt,
|
lnk->s_conn_attempt,
|
||||||
hrtime(lnk->last_connection_attempt));
|
hrtime(lnk->last_connection_attempt));
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
case IRCS_CONNECTED:
|
case IRCS_CONNECTED:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"connected !");
|
"connected !");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
case IRCS_WAS_CONNECTED:
|
case IRCS_WAS_CONNECTED:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"disconnected, attempts: %d, last: %s",
|
"disconnected, attempts: %d, last: %s",
|
||||||
lnk->s_conn_attempt,
|
lnk->s_conn_attempt,
|
||||||
hrtime(lnk->last_connection_attempt));
|
hrtime(lnk->last_connection_attempt));
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
case IRCS_RECONNECTING:
|
case IRCS_RECONNECTING:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"reconnecting... attempts: %d, last: %s",
|
"reconnecting... attempts: %d, last: %s",
|
||||||
lnk->s_conn_attempt,
|
lnk->s_conn_attempt,
|
||||||
hrtime(lnk->last_connection_attempt));
|
hrtime(lnk->last_connection_attempt));
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
case IRCS_TIMER_WAIT:
|
case IRCS_TIMER_WAIT:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"waiting to reconnect, attempts: %d, last: %s",
|
"waiting to reconnect, attempts: %d, last: %s",
|
||||||
lnk->s_conn_attempt,
|
lnk->s_conn_attempt,
|
||||||
hrtime(lnk->last_connection_attempt));
|
hrtime(lnk->last_connection_attempt));
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
"unknown");
|
"unknown");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroomstatus;
|
||||||
break;
|
break;
|
||||||
// s_conn_attempt recon_timer last_connection_attempt
|
// s_conn_attempt recon_timer last_connection_attempt
|
||||||
}
|
}
|
||||||
buf[4095] = 0;
|
noroomstatus:
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1123,7 +1201,7 @@ void adm_list_all_connections(struct link_client *ic)
|
|||||||
void adm_info_user(struct link_client *ic, char *name)
|
void adm_info_user(struct link_client *ic, char *name)
|
||||||
{
|
{
|
||||||
struct user *u;
|
struct user *u;
|
||||||
char buf[4096];
|
char buf[RET_STR_LEN + 1];
|
||||||
int t_wrote = 0;
|
int t_wrote = 0;
|
||||||
|
|
||||||
u = hash_get(&_bip->users, name);
|
u = hash_get(&_bip->users, name);
|
||||||
@ -1132,40 +1210,50 @@ void adm_info_user(struct link_client *ic, char *name)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote, "");
|
//t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote, "");
|
||||||
//buf[4095] = 0;
|
//buf[RET_STR_LEN] = 0;
|
||||||
//adm_reply(ic, buf);
|
//adm_reply(ic, buf);
|
||||||
//t_wrote = 0;
|
//t_wrote = 0;
|
||||||
|
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote, "user: %s", u->name);
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote, "user: %s",
|
||||||
if (u->admin)
|
u->name);
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote, ", is bip admin");
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
if (u->admin) {
|
||||||
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN - t_wrote,
|
||||||
|
", is bip admin");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
|
||||||
buf[4095] = 0;
|
noroom:
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
t_wrote = 0;
|
t_wrote = 0;
|
||||||
|
|
||||||
#ifdef HAVE_LIBSSL
|
#ifdef HAVE_LIBSSL
|
||||||
snprintf(buf, 4095, "SSL check mode '%s', stored into '%s'",
|
snprintf(buf, RET_STR_LEN, "SSL check mode '%s', stored into '%s'",
|
||||||
checkmode2text(u->ssl_check_mode), u->ssl_check_store);
|
checkmode2text(u->ssl_check_mode), u->ssl_check_store);
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
#endif
|
#endif
|
||||||
snprintf(buf, 4095, "Defaults nick: %s, user: %s, realname: %s",
|
snprintf(buf, RET_STR_LEN, "Defaults nick: %s, user: %s, realname: %s",
|
||||||
u->default_nick, u->default_username, u->default_realname);
|
u->default_nick, u->default_username, u->default_realname);
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
if (u->backlog) {
|
if (u->backlog) {
|
||||||
snprintf(buf, 4095, "Backlog enabled, lines: %d, no timestamp: "
|
snprintf(buf, RET_STR_LEN, "Backlog enabled, lines: %d, "
|
||||||
"%s, messages only: %s", u->backlog_lines,
|
"no timestamp: %s, messages only: %s",
|
||||||
|
u->backlog_lines,
|
||||||
bool2text(u->backlog_no_timestamp),
|
bool2text(u->backlog_no_timestamp),
|
||||||
bool2text(u->bl_msg_only));
|
bool2text(u->bl_msg_only));
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
snprintf(buf, 4095, "always backlog: %s, reset on talk: %s",
|
snprintf(buf, RET_STR_LEN, "always backlog: %s, "
|
||||||
|
"reset on talk: %s",
|
||||||
bool2text(u->always_backlog),
|
bool2text(u->always_backlog),
|
||||||
bool2text(u->blreset_on_talk));
|
bool2text(u->blreset_on_talk));
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
} else {
|
} else {
|
||||||
adm_reply(ic, "Backlog disabled");
|
adm_reply(ic, "Backlog disabled");
|
||||||
@ -1177,7 +1265,7 @@ void adm_list_users(struct link_client *ic)
|
|||||||
{
|
{
|
||||||
hash_iterator_t it;
|
hash_iterator_t it;
|
||||||
hash_iterator_t lit;
|
hash_iterator_t lit;
|
||||||
char buf[4096];
|
char buf[RET_STR_LEN + 1];
|
||||||
connection_t *c;
|
connection_t *c;
|
||||||
|
|
||||||
c = CONN(ic);
|
c = CONN(ic);
|
||||||
@ -1186,31 +1274,39 @@ void adm_list_users(struct link_client *ic)
|
|||||||
for (hash_it_init(&_bip->users, &it); hash_it_item(&it);
|
for (hash_it_init(&_bip->users, &it); hash_it_item(&it);
|
||||||
hash_it_next(&it)) {
|
hash_it_next(&it)) {
|
||||||
struct user *u = hash_it_item(&it);
|
struct user *u = hash_it_item(&it);
|
||||||
int t_max_len = 60;
|
|
||||||
int first = 1;
|
int first = 1;
|
||||||
int t_wrote = 0;
|
int t_wrote = 0;
|
||||||
|
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
t_wrote += snprintf(buf, 4095, "* %s%s:", u->name, (u->admin ?
|
t_wrote += snprintf(buf, RET_STR_LEN, "* %s%s:", u->name,
|
||||||
"": "(admin)"));
|
(u->admin ? "": "(admin)"));
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
for (hash_it_init(&u->connections, &lit); hash_it_item(&lit);
|
for (hash_it_init(&u->connections, &lit); hash_it_item(&lit);
|
||||||
hash_it_next(&lit)) {
|
hash_it_next(&lit)) {
|
||||||
struct link *lnk = hash_it_item(&lit);
|
struct link *lnk = hash_it_item(&lit);
|
||||||
if (first)
|
if (first) {
|
||||||
first = 0;
|
first = 0;
|
||||||
else
|
}else {
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN
|
||||||
- t_wrote, ",");
|
- t_wrote, ",");
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
|
}
|
||||||
|
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095 - t_wrote,
|
t_wrote += snprintf(buf + t_wrote,
|
||||||
|
RET_STR_LEN - t_wrote,
|
||||||
" %s", lnk->name);
|
" %s", lnk->name);
|
||||||
if (t_wrote > t_max_len) {
|
if (t_wrote >= RET_STR_LEN)
|
||||||
buf[4095] = 0;
|
goto noroom;
|
||||||
|
if (t_wrote > LINE_SIZE_LIM) {
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
t_wrote = 0;
|
t_wrote = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf[4095] = 0;
|
noroom:
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
}
|
}
|
||||||
adm_reply(ic, "End of bip user list");
|
adm_reply(ic, "End of bip user list");
|
||||||
@ -1219,7 +1315,7 @@ void adm_list_users(struct link_client *ic)
|
|||||||
void adm_list_networks(struct link_client *ic)
|
void adm_list_networks(struct link_client *ic)
|
||||||
{
|
{
|
||||||
hash_iterator_t it;
|
hash_iterator_t it;
|
||||||
char buf[4096];
|
char buf[RET_STR_LEN + 1];
|
||||||
connection_t *c;
|
connection_t *c;
|
||||||
|
|
||||||
c = CONN(ic);
|
c = CONN(ic);
|
||||||
@ -1228,28 +1324,35 @@ void adm_list_networks(struct link_client *ic)
|
|||||||
for (hash_it_init(&_bip->networks, &it); hash_it_item(&it);
|
for (hash_it_init(&_bip->networks, &it); hash_it_item(&it);
|
||||||
hash_it_next(&it)) {
|
hash_it_next(&it)) {
|
||||||
struct network *n = hash_it_item(&it);
|
struct network *n = hash_it_item(&it);
|
||||||
int t_max_len = 60;
|
|
||||||
int t_wrote = 0;
|
int t_wrote = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
if (n->ssl) {
|
if (n->ssl) {
|
||||||
t_wrote += snprintf(buf, 4095, "- %s*:", n->name);
|
t_wrote += snprintf(buf, RET_STR_LEN, "- %s*:",
|
||||||
|
n->name);
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
} else {
|
} else {
|
||||||
t_wrote += snprintf(buf, 4095, "- %s:", n->name);
|
t_wrote += snprintf(buf, RET_STR_LEN, "- %s:", n->name);
|
||||||
|
if (t_wrote >= RET_STR_LEN)
|
||||||
|
goto noroom;
|
||||||
}
|
}
|
||||||
for (i = 0; i < n->serverc; i++) {
|
for (i = 0; i < n->serverc; i++) {
|
||||||
struct server *serv = i+n->serverv;
|
struct server *serv = i+n->serverv;
|
||||||
t_wrote += snprintf(buf + t_wrote, 4095
|
t_wrote += snprintf(buf + t_wrote, RET_STR_LEN
|
||||||
- t_wrote, " %s:%d", serv->host,
|
- t_wrote, " %s:%d", serv->host,
|
||||||
serv->port);
|
serv->port);
|
||||||
if (t_wrote > t_max_len) {
|
if (t_wrote >= RET_STR_LEN)
|
||||||
buf[4095] = 0;
|
goto noroom;
|
||||||
|
if (t_wrote > LINE_SIZE_LIM) {
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
t_wrote = 0;
|
t_wrote = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf[4095] = 0;
|
noroom:
|
||||||
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
}
|
}
|
||||||
adm_reply(ic, "End of bip network list");
|
adm_reply(ic, "End of bip network list");
|
||||||
@ -1258,7 +1361,7 @@ void adm_list_networks(struct link_client *ic)
|
|||||||
void adm_list_connections(struct link_client *ic, struct user *bu)
|
void adm_list_connections(struct link_client *ic, struct user *bu)
|
||||||
{
|
{
|
||||||
hash_iterator_t it;
|
hash_iterator_t it;
|
||||||
char buf[4096];
|
char buf[RET_STR_LEN + 1];
|
||||||
connection_t *c;
|
connection_t *c;
|
||||||
|
|
||||||
c = CONN(ic);
|
c = CONN(ic);
|
||||||
@ -1266,8 +1369,8 @@ void adm_list_connections(struct link_client *ic, struct user *bu)
|
|||||||
adm_reply(ic, "Your connections:");
|
adm_reply(ic, "Your connections:");
|
||||||
bu = LINK(ic)->user;
|
bu = LINK(ic)->user;
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf, 4095, "%s's connections:", bu->name);
|
snprintf(buf, RET_STR_LEN, "%s's connections:", bu->name);
|
||||||
buf[4095] = 0;
|
buf[RET_STR_LEN] = 0;
|
||||||
adm_reply(ic, buf);
|
adm_reply(ic, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1537,7 +1640,7 @@ int adm_bip(struct link_client *ic, struct line *line, unsigned int privmsg)
|
|||||||
adm_reply(ic, "You're not allowed to reload bip");
|
adm_reply(ic, "You're not allowed to reload bip");
|
||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
adm_reply(ic, "Bip has been set to reload shortly");
|
adm_reply(ic, "Reloading...");
|
||||||
reloading_client = ic;
|
reloading_client = ic;
|
||||||
sighup = 1;
|
sighup = 1;
|
||||||
} else if (strcasecmp(line->elemv[privmsg + 1], "LIST") == 0) {
|
} else if (strcasecmp(line->elemv[privmsg + 1], "LIST") == 0) {
|
||||||
@ -1546,27 +1649,28 @@ int adm_bip(struct link_client *ic, struct line *line, unsigned int privmsg)
|
|||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (admin && strncasecmp(line->elemv[privmsg + 2],
|
if (admin && strcasecmp(line->elemv[privmsg + 2],
|
||||||
"users", 5) == 0) {
|
"users") == 0) {
|
||||||
adm_list_users(ic);
|
adm_list_users(ic);
|
||||||
} else if (strncasecmp(line->elemv[privmsg + 2],
|
} else if (strcasecmp(line->elemv[privmsg + 2],
|
||||||
"networks", 8) == 0) {
|
"networks") == 0) {
|
||||||
adm_list_networks(ic);
|
adm_list_networks(ic);
|
||||||
} else if (strncasecmp(line->elemv[privmsg + 2],
|
} else if (strcasecmp(line->elemv[privmsg + 2],
|
||||||
"connections", 11) == 0) {
|
"connections") == 0) {
|
||||||
adm_list_connections(ic, NULL);
|
adm_list_connections(ic, NULL);
|
||||||
} else if (admin && strncasecmp(line->elemv[privmsg + 2],
|
} else if (admin && strcasecmp(line->elemv[privmsg + 2],
|
||||||
"all_connections", 15) == 0) {
|
"all_connections") == 0) {
|
||||||
adm_list_all_connections(ic);
|
adm_list_all_connections(ic);
|
||||||
} else if (admin && strncasecmp(line->elemv[privmsg + 2],
|
} else if (admin && strcasecmp(line->elemv[privmsg + 2],
|
||||||
"all_links", 9) == 0) {
|
"all_links") == 0) {
|
||||||
adm_list_all_links(ic);
|
adm_list_all_links(ic);
|
||||||
} else {
|
} else {
|
||||||
adm_reply(ic, "Invalid LIST request");
|
adm_reply(ic, "Invalid LIST request");
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(line->elemv[privmsg + 1], "INFO") == 0) {
|
} else if (strcasecmp(line->elemv[privmsg + 1], "INFO") == 0) {
|
||||||
if (line->elemc < privmsg + 3) {
|
if (line->elemc < privmsg + 3) {
|
||||||
adm_reply(ic, "INFO command needs at least one argument");
|
adm_reply(ic, "INFO command needs at least one "
|
||||||
|
"argument");
|
||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1578,14 +1682,17 @@ int adm_bip(struct link_client *ic, struct line *line, unsigned int privmsg)
|
|||||||
adm_reply(ic, "/BIP INFO user needs one "
|
adm_reply(ic, "/BIP INFO user needs one "
|
||||||
"argument");
|
"argument");
|
||||||
}
|
}
|
||||||
/*TODO } else if (strncasecmp(line->elemv[privmsg + 2],
|
#if 0
|
||||||
|
TODO
|
||||||
|
} else if (strncasecmp(line->elemv[privmsg + 2],
|
||||||
"network", 8) == 0) {
|
"network", 8) == 0) {
|
||||||
if (line->elemc == privmsg + 4) {
|
if (line->elemc == privmsg + 4) {
|
||||||
adm_info_network(ic, line->elemv[privmsg + 3]);
|
adm_info_network(ic, line->elemv[privmsg + 3]);
|
||||||
} else {
|
} else {
|
||||||
adm_reply(ic, "/BIP INFO network needs one "
|
adm_reply(ic, "/BIP INFO network needs one "
|
||||||
"argument");
|
"argument");
|
||||||
}*/
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
adm_reply(ic, "Invalid INFO request");
|
adm_reply(ic, "Invalid INFO request");
|
||||||
}
|
}
|
||||||
@ -1609,7 +1716,8 @@ int adm_bip(struct link_client *ic, struct line *line, unsigned int privmsg)
|
|||||||
} else if (strcasecmp(line->elemv[privmsg + 1],
|
} else if (strcasecmp(line->elemv[privmsg + 1],
|
||||||
"IGNORE_FIRST_NICK") == 0) {
|
"IGNORE_FIRST_NICK") == 0) {
|
||||||
if (line->elemc != privmsg + 3) {
|
if (line->elemc != privmsg + 3) {
|
||||||
adm_reply(ic, "IGNORE_FIRST_NICK command needs one argument");
|
adm_reply(ic, "IGNORE_FIRST_NICK command needs one "
|
||||||
|
"argument");
|
||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
adm_ignore_first_nick(ic, line->elemv[privmsg + 2]);
|
adm_ignore_first_nick(ic, line->elemv[privmsg + 2]);
|
||||||
@ -1639,12 +1747,7 @@ int adm_bip(struct link_client *ic, struct line *line, unsigned int privmsg)
|
|||||||
return adm_trust(ic, line);
|
return adm_trust(ic, line);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
char buf[4096];
|
adm_reply(ic, "Unknown command.");
|
||||||
|
|
||||||
buf[4095] = 0;
|
|
||||||
snprintf(buf, 4095, "Unknown command %s",
|
|
||||||
line->elemv[privmsg + 1]);
|
|
||||||
adm_reply(ic, buf);
|
|
||||||
}
|
}
|
||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user