*
* $Id$
*/
+#include "config.h"
+
#include "s_misc.h"
#include "IPcheck.h"
#include "channel.h"
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_log.h"
+#include "ircd_policy.h"
+#include "ircd_reply.h"
#include "ircd_string.h"
#include "list.h"
#include "match.h"
#include "struct.h"
#include "support.h"
#include "sys.h"
+#include "uping.h"
#include "userload.h"
#include <assert.h>
#include <sys/stat.h>
#include <unistd.h>
-static void exit_one_client(struct Client *, char *);
static char *months[] = {
"January", "February", "March", "April",
*
* Returns:
* "name[user@ip#.port]" if 'showip' is true;
- * "name[sockethost]", if name and sockhost are different and
- * showip is false; else
- * "name".
+ * "name" if 'showip' is false.
*
* NOTE 1:
* Watch out the allocation of "nbuf", if either sptr->name
if (MyConnect(sptr)) {
if (showip)
- sprintf_irc(nbuf, "%s[%s@%s]", sptr->name,
- (IsIdented(sptr)) ? sptr->username : "", sptr->sock_ip);
- else {
- if (0 != ircd_strcmp(sptr->name, sptr->sockhost))
- sprintf_irc(nbuf, "%s[%s]", sptr->name, sptr->sockhost);
- else
- return sptr->name;
- }
+ sprintf_irc(nbuf, "%s[%s@%s]", cli_name(sptr),
+ (IsIdented(sptr)) ? cli_username(sptr) : "", cli_sock_ip(sptr));
+ else
+ return cli_name(sptr);
return nbuf;
}
- return sptr->name;
+ return cli_name(sptr);
}
const char *get_client_host(const struct Client *cptr)
s++;
else
s = host;
- ircd_strncpy(cptr->sockhost, s, HOSTLEN);
+ ircd_strncpy(cli_sockhost(cptr), s, HOSTLEN);
+}
+
+/*
+ * Exit one client, local or remote. Assuming for local client that
+ * all dependants already have been removed, and socket is closed.
+ *
+ * Rewritten by Run - 24 sept 94
+ *
+ * bcptr : client being (s)quitted
+ * sptr : The source (prefix) of the QUIT or SQUIT
+ *
+ * --Run
+ */
+static void exit_one_client(struct Client* bcptr, const char* comment)
+{
+ struct SLink *lp;
+
+ if (cli_serv(bcptr) && cli_serv(bcptr)->client_list) /* Was SetServerYXX called ? */
+ ClearServerYXX(bcptr); /* Removes server from server_list[] */
+ if (IsUser(bcptr)) {
+ /*
+ * clear out uping requests
+ */
+ if (IsUPing(bcptr))
+ uping_cancel(bcptr, 0);
+ /*
+ * Stop a running /LIST clean
+ */
+ if (MyUser(bcptr) && cli_listing(bcptr)) {
+ cli_listing(bcptr)->chptr->mode.mode &= ~MODE_LISTED;
+ MyFree(cli_listing(bcptr));
+ cli_listing(bcptr) = NULL;
+ }
+ /*
+ * If a person is on a channel, send a QUIT notice
+ * to every client (person) on the same channel (so
+ * that the client can show the "**signoff" message).
+ * (Note: The notice is to the local clients *only*)
+ */
+ sendcmdto_common_channels(bcptr, CMD_QUIT, ":%s", comment);
+
+ remove_user_from_all_channels(bcptr);
+
+ /* Clean up invitefield */
+ while ((lp = cli_user(bcptr)->invited))
+ del_invite(bcptr, lp->value.chptr);
+
+ /* Clean up silencefield */
+ while ((lp = cli_user(bcptr)->silence))
+ del_silence(bcptr, lp->value.cp);
+
+ if (IsInvisible(bcptr))
+ --UserStats.inv_clients;
+ if (IsOper(bcptr))
+ --UserStats.opers;
+ if (MyConnect(bcptr))
+ Count_clientdisconnects(bcptr, UserStats);
+ else {
+ Count_remoteclientquits(UserStats, bcptr);
+ }
+ }
+ else if (IsServer(bcptr))
+ {
+ /* Remove downlink list node of uplink */
+ remove_dlink(&(cli_serv(cli_serv(bcptr)->up))->down, cli_serv(bcptr)->updown);
+ cli_serv(bcptr)->updown = 0;
+
+ if (MyConnect(bcptr))
+ Count_serverdisconnects(UserStats);
+ else
+ Count_remoteserverquits(UserStats);
+ }
+ else if (IsMe(bcptr))
+ {
+ sendto_opmask_butone(0, SNO_OLDSNO, "ERROR: tried to exit me! : %s",
+ comment);
+ return; /* ...must *never* exit self! */
+ }
+ else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr))
+ Count_unknowndisconnects(UserStats);
+
+ /*
+ * Update IPregistry
+ */
+ if (IsIPChecked(bcptr))
+ IPcheck_disconnect(bcptr);
+
+ /*
+ * Remove from serv->client_list
+ * NOTE: user is *always* NULL if this is a server
+ */
+ if (cli_user(bcptr)) {
+ assert(!IsServer(bcptr));
+ /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */
+ RemoveYXXClient(cli_user(bcptr)->server, cli_yxx(bcptr));
+ }
+
+ /* Remove bcptr from the client list */
+#ifdef DEBUGMODE
+ if (hRemClient(bcptr) != 0)
+ Debug((DEBUG_ERROR, "%p !in tab %s[%s] %p %p %p %d %d %p",
+ bcptr, cli_name(bcptr), cli_from(bcptr) ? cli_sockhost(cli_from(bcptr)) : "??host",
+ cli_from(bcptr), cli_next(bcptr), cli_prev(bcptr), cli_fd(bcptr),
+ cli_status(bcptr), cli_user(bcptr)));
+#else
+ hRemClient(bcptr);
+#endif
+ remove_client_from_list(bcptr);
}
/*
int i;
/* Run over all its downlinks */
- for (lp = cptr->serv->down; lp; lp = next)
+ for (lp = cli_serv(cptr)->down; lp; lp = next)
{
next = lp->next;
acptr = lp->value.cptr;
/* Remove the downlinks and client of the downlink */
exit_downlinks(acptr, sptr, comment);
/* Remove the downlink itself */
- exit_one_client(acptr, me.name);
+ exit_one_client(acptr, cli_name(&me));
}
/* Remove all clients of this server */
- acptrp = cptr->serv->client_list;
- for (i = 0; i <= cptr->serv->nn_mask; ++acptrp, ++i) {
+ acptrp = cli_serv(cptr)->client_list;
+ for (i = 0; i <= cli_serv(cptr)->nn_mask; ++acptrp, ++i) {
if (*acptrp)
exit_one_client(*acptrp, comment);
}
struct Client* victim, /* Client being killed */
struct Client* killer, /* The client that made the decision
to remove this one, never NULL */
- char *comment) /* Reason for the exit */
+ const char* comment) /* Reason for the exit */
{
struct Client* acptr = 0;
struct DLink *dlp;
-#ifdef FNAME_USERLOG
time_t on_for;
-#endif
- char comment1[HOSTLEN + HOSTLEN + 2];
+ char comment1[HOSTLEN + HOSTLEN + 2];
+ assert(killer);
if (MyConnect(victim)) {
- victim->flags |= FLAGS_CLOSING;
-#ifdef ALLOW_SNO_CONNEXIT
-#ifdef SNO_CONNEXIT_IP
- if (IsUser(victim)) {
- sprintf_irc(sendbuf,
- ":%s NOTICE * :*** Notice -- Client exiting: %s (%s@%s) [%s] [%s]",
- me.name, victim->name, victim->user->username, victim->user->host,
- comment, ircd_ntoa((const char*) &victim->ip));
- sendbufto_op_mask(SNO_CONNEXIT);
- }
-#else /* SNO_CONNEXIT_IP */
- if (IsUser(victim)) {
- sprintf_irc(sendbuf,
- ":%s NOTICE * :*** Notice -- Client exiting: %s (%s@%s) [%s]",
- me.name, victim->name, victim->user->username, victim->user->host,
- comment);
- sendbufto_op_mask(SNO_CONNEXIT);
- }
-#endif /* SNO_CONNEXIT_IP */
-#endif /* ALLOW_SNO_CONNEXIT */
+ cli_flags(victim) |= FLAGS_CLOSING;
update_load();
-#ifdef FNAME_USERLOG
- on_for = CurrentTime - victim->firsttime;
-#if defined(USE_SYSLOG) && defined(SYSLOG_USERS)
- if (IsUser(victim))
- ircd_log(L_TRACE, "%s (%3d:%02d:%02d): %s@%s (%s)\n",
- myctime(victim->firsttime), on_for / 3600, (on_for % 3600) / 60,
- on_for % 60, victim->user->username, victim->sockhost, victim->name);
-#else
+
+ on_for = CurrentTime - cli_firsttime(victim);
+
if (IsUser(victim))
- write_log(FNAME_USERLOG,
- "%s (%3d:%02d:%02d): %s@%s [%s]\n",
- myctime(victim->firsttime),
- on_for / 3600, (on_for % 3600) / 60,
- on_for % 60,
- victim->user->username, victim->user->host, victim->username);
-#endif
-#endif
- if (victim != killer->from /* The source knows already */
+ log_write(LS_USER, L_TRACE, 0, "%s (%3d:%02d:%02d): %s@%s (%s)",
+ myctime(cli_firsttime(victim)), on_for / 3600,
+ (on_for % 3600) / 60, on_for % 60, cli_user(victim)->username,
+ cli_sockhost(victim), cli_name(victim));
+
+ if (victim != cli_from(killer) /* The source knows already */
&& IsClient(victim)) /* Not a Ping struct or Log file */
{
if (IsServer(victim) || IsHandshake(victim))
- sendto_one(victim, ":%s SQUIT %s 0 :%s", killer->name, me.name, comment);
+ sendcmdto_one(killer, CMD_SQUIT, victim, "%s 0 :%s", cli_name(&me), comment);
else if (!IsConnecting(victim)) {
if (!IsDead(victim))
- sendto_one(victim, "ERROR :Closing Link: %s by %s (%s)",
- victim->name, killer->name, comment);
+ sendrawto_one(victim, MSG_ERROR " :Closing Link: %s by %s (%s)",
+ cli_name(victim), cli_name(killer), comment);
}
if ((IsServer(victim) || IsHandshake(victim) || IsConnecting(victim)) &&
(killer == &me || (IsServer(killer) &&
* Note: check user == user needed to make sure we have the same
* client
*/
- if (victim->serv->user && *victim->serv->by &&
- (acptr = findNUser(victim->serv->by))) {
- if (acptr->user == victim->serv->user) {
- if (MyUser(acptr) || Protocol(acptr->from) < 10)
- sendto_one(acptr,
- ":%s NOTICE %s :Link with %s cancelled: %s",
- me.name, acptr->name, victim->name, comment);
- else
- sendto_one(acptr,
- "%s NOTICE %s%s :Link with %s cancelled: %s",
- NumServ(&me), NumNick(acptr), victim->name, comment);
+ if (cli_serv(victim)->user && *(cli_serv(victim))->by &&
+ (acptr = findNUser(cli_serv(victim)->by))) {
+ if (cli_user(acptr) == cli_serv(victim)->user) {
+ sendcmdto_one(&me, CMD_NOTICE, acptr,
+ "%C :Link with %s cancelled: %s", acptr,
+ cli_name(victim), comment);
}
else {
/*
* not right client, set by to empty string
*/
acptr = 0;
- *victim->serv->by = '\0';
+ *(cli_serv(victim))->by = '\0';
}
}
if (killer == &me)
- sendto_lops_butone(acptr, "Link with %s cancelled: %s",
- victim->name, comment);
+ sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s cancelled: %s",
+ cli_name(victim), comment);
}
}
/*
if (IsServer(victim))
{
- strcpy(comment1, victim->serv->up->name);
+#ifdef HEAD_IN_SAND_NETSPLIT
+ strcpy(comment1, "*.net *.split");
+#else
+ strcpy(comment1, cli_name(cli_serv(victim)->up));
strcat(comment1, " ");
- strcat(comment1, victim->name);
+ strcat(comment1, cli_name(victim));
+#endif
if (IsUser(killer))
- sendto_lops_butone(killer, "%s SQUIT by %s [%s]:",
- (killer->user->server == victim ||
- killer->user->server == victim->serv->up) ? "Local" : "Remote",
- get_client_name(killer, HIDE_IP), killer->user->server->name);
- else if (killer != &me && victim->serv->up != killer)
- sendto_ops("Received SQUIT %s from %s :", victim->name,
- IsServer(killer) ? killer->name : get_client_name(killer, HIDE_IP));
- sendto_op_mask(SNO_NETWORK, "Net break: %s (%s)", comment1, comment);
+ sendto_opmask_butone(killer, SNO_OLDSNO, "%s SQUIT by %s [%s]:",
+ (cli_user(killer)->server == victim ||
+ cli_user(killer)->server == cli_serv(victim)->up) ?
+ "Local" : "Remote",
+ get_client_name(killer, HIDE_IP),
+ cli_name(cli_user(killer)->server));
+ else if (killer != &me && cli_serv(victim)->up != killer)
+ sendto_opmask_butone(0, SNO_OLDSNO, "Received SQUIT %s from %s :",
+ cli_name(victim), IsServer(killer) ? cli_name(killer) :
+ get_client_name(killer, HIDE_IP));
+ sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)",
+ cli_serv(victim)->up, victim, comment);
}
/*
* First generate the needed protocol for the other server links
* except the source:
*/
- for (dlp = me.serv->down; dlp; dlp = dlp->next) {
- if (dlp->value.cptr != killer->from && dlp->value.cptr != victim) {
+ for (dlp = cli_serv(&me)->down; dlp; dlp = dlp->next) {
+ if (dlp->value.cptr != cli_from(killer) && dlp->value.cptr != victim) {
if (IsServer(victim))
- sendto_one(dlp->value.cptr, ":%s SQUIT %s " TIME_T_FMT " :%s",
- killer->name, victim->name, victim->serv->timestamp, comment);
- else if (IsUser(victim) && 0 == (victim->flags & FLAGS_KILLED))
- sendto_one(dlp->value.cptr, "%s%s " TOK_QUIT " :%s", NumNick(victim), comment);
+ sendcmdto_one(killer, CMD_SQUIT, dlp->value.cptr, "%s %Tu :%s",
+ cli_name(victim), cli_serv(victim)->timestamp, comment);
+ else if (IsUser(victim) && 0 == (cli_flags(victim) & FLAGS_KILLED))
+ sendcmdto_one(victim, CMD_QUIT, dlp->value.cptr, ":%s", comment);
}
}
/* Then remove the client structures */
* Exit client with formatted message, added 25-9-94 by Run
*/
int vexit_client_msg(struct Client *cptr, struct Client *bcptr, struct Client *sptr,
- char *pattern, va_list vl)
+ const char *pattern, va_list vl)
{
char msgbuf[1024];
vsprintf_irc(msgbuf, pattern, vl);
}
int exit_client_msg(struct Client *cptr, struct Client *bcptr,
- struct Client *sptr, char *pattern, ...)
+ struct Client *sptr, const char *pattern, ...)
{
va_list vl;
char msgbuf[1024];
return exit_client(cptr, bcptr, sptr, msgbuf);
}
-/*
- * Exit one client, local or remote. Assuming for local client that
- * all dependants already have been removed, and socket is closed.
- *
- * Rewritten by Run - 24 sept 94
- *
- * bcptr : client being (s)quitted
- * sptr : The source (prefix) of the QUIT or SQUIT
- *
- * --Run
- */
-static void exit_one_client(struct Client *bcptr, char *comment)
-{
- struct SLink *lp;
-
- if (bcptr->serv && bcptr->serv->client_list) /* Was SetServerYXX called ? */
- ClearServerYXX(bcptr); /* Removes server from server_list[] */
- if (IsUser(bcptr)) {
- /*
- * Stop a running /LIST clean
- */
- if (MyUser(bcptr) && bcptr->listing) {
- bcptr->listing->chptr->mode.mode &= ~MODE_LISTED;
- MyFree(bcptr->listing);
- bcptr->listing = NULL;
- }
- /*
- * If a person is on a channel, send a QUIT notice
- * to every client (person) on the same channel (so
- * that the client can show the "**signoff" message).
- * (Note: The notice is to the local clients *only*)
- */
- sendto_common_channels(bcptr, ":%s QUIT :%s", bcptr->name, comment);
-
- remove_user_from_all_channels(bcptr);
-
- /* Clean up invitefield */
- while ((lp = bcptr->user->invited))
- del_invite(bcptr, lp->value.chptr);
-
- /* Clean up silencefield */
- while ((lp = bcptr->user->silence))
- del_silence(bcptr, lp->value.cp);
-
- if (IsInvisible(bcptr))
- --UserStats.inv_clients;
- if (IsOper(bcptr))
- --UserStats.opers;
- if (MyConnect(bcptr))
- Count_clientdisconnects(bcptr, UserStats);
- else
- Count_remoteclientquits(UserStats, bcptr);
- }
- else if (IsServer(bcptr))
- {
- /* Remove downlink list node of uplink */
- remove_dlink(&bcptr->serv->up->serv->down, bcptr->serv->updown);
- bcptr->serv->updown = 0;
-
- if (MyConnect(bcptr))
- Count_serverdisconnects(UserStats);
- else
- Count_remoteserverquits(UserStats);
- }
- else if (IsMe(bcptr))
- {
- sendto_ops("ERROR: tried to exit me! : %s", comment);
- return; /* ...must *never* exit self! */
- }
- else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr))
- Count_unknowndisconnects(UserStats);
-
- /*
- * Update IPregistry
- */
- if (IsIPChecked(bcptr))
- IPcheck_disconnect(bcptr);
-
- /*
- * Remove from serv->client_list
- * NOTE: user is *always* NULL if this is a server
- */
- if (bcptr->user) {
- assert(!IsServer(bcptr));
- /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */
- RemoveYXXClient(bcptr->user->server, bcptr->yxx);
- }
-
- /* Remove bcptr from the client list */
-#ifdef DEBUGMODE
- if (hRemClient(bcptr) != 0)
- Debug((DEBUG_ERROR, "%p !in tab %s[%s] %p %p %p %d %d %p",
- bcptr, bcptr->name, bcptr->from ? bcptr->from->sockhost : "??host",
- bcptr->from, bcptr->next, bcptr->prev, bcptr->fd,
- bcptr->status, bcptr->user));
-#else
- hRemClient(bcptr);
-#endif
- remove_client_from_list(bcptr);
-}
-
-
void initstats(void)
{
memset(&ircst, 0, sizeof(ircst));
continue;
if (IsServer(acptr))
{
- sp->is_sbs += acptr->sendB;
- sp->is_sbr += acptr->receiveB;
- sp->is_sks += acptr->sendK;
- sp->is_skr += acptr->receiveK;
- sp->is_sti += CurrentTime - acptr->firsttime;
+ sp->is_sbs += cli_sendB(acptr);
+ sp->is_sbr += cli_receiveB(acptr);
+ sp->is_sks += cli_sendK(acptr);
+ sp->is_skr += cli_receiveK(acptr);
+ sp->is_sti += CurrentTime - cli_firsttime(acptr);
sp->is_sv++;
if (sp->is_sbs > 1023)
{
}
else if (IsUser(acptr))
{
- sp->is_cbs += acptr->sendB;
- sp->is_cbr += acptr->receiveB;
- sp->is_cks += acptr->sendK;
- sp->is_ckr += acptr->receiveK;
- sp->is_cti += CurrentTime - acptr->firsttime;
+ sp->is_cbs += cli_sendB(acptr);
+ sp->is_cbr += cli_receiveB(acptr);
+ sp->is_cks += cli_sendK(acptr);
+ sp->is_ckr += cli_receiveK(acptr);
+ sp->is_cti += CurrentTime - cli_firsttime(acptr);
sp->is_cl++;
if (sp->is_cbs > 1023)
{
sp->is_ni++;
}
- sendto_one(cptr, ":%s %d %s :accepts %u refused %u",
- me.name, RPL_STATSDEBUG, name, sp->is_ac, sp->is_ref);
- sendto_one(cptr, ":%s %d %s :unknown commands %u prefixes %u",
- me.name, RPL_STATSDEBUG, name, sp->is_unco, sp->is_unpf);
- sendto_one(cptr, ":%s %d %s :nick collisions %u unknown closes %u",
- me.name, RPL_STATSDEBUG, name, sp->is_kill, sp->is_ni);
- sendto_one(cptr, ":%s %d %s :wrong direction %u empty %u",
- me.name, RPL_STATSDEBUG, name, sp->is_wrdi, sp->is_empt);
- sendto_one(cptr, ":%s %d %s :numerics seen %u mode fakes %u",
- me.name, RPL_STATSDEBUG, name, sp->is_num, sp->is_fake);
- sendto_one(cptr, ":%s %d %s :auth successes %u fails %u",
- me.name, RPL_STATSDEBUG, name, sp->is_asuc, sp->is_abad);
- sendto_one(cptr, ":%s %d %s :local connections %u",
- me.name, RPL_STATSDEBUG, name, sp->is_loc);
- sendto_one(cptr, ":%s %d %s :Client Server", me.name, RPL_STATSDEBUG, name);
- sendto_one(cptr, ":%s %d %s :connected %u %u",
- me.name, RPL_STATSDEBUG, name, sp->is_cl, sp->is_sv);
- sendto_one(cptr, ":%s %d %s :bytes sent %u.%uK %u.%uK",
- me.name, RPL_STATSDEBUG, name,
- sp->is_cks, sp->is_cbs, sp->is_sks, sp->is_sbs);
- sendto_one(cptr, ":%s %d %s :bytes recv %u.%uK %u.%uK",
- me.name, RPL_STATSDEBUG, name,
- sp->is_ckr, sp->is_cbr, sp->is_skr, sp->is_sbr);
- sendto_one(cptr, ":%s %d %s :time connected " TIME_T_FMT " " TIME_T_FMT,
- me.name, RPL_STATSDEBUG, name, sp->is_cti, sp->is_sti);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":accepts %u refused %u",
+ sp->is_ac, sp->is_ref);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":unknown commands %u prefixes %u", sp->is_unco, sp->is_unpf);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":nick collisions %u unknown closes %u", sp->is_kill, sp->is_ni);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":wrong direction %u empty %u", sp->is_wrdi, sp->is_empt);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":numerics seen %u mode fakes %u", sp->is_num, sp->is_fake);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":auth successes %u fails %u", sp->is_asuc, sp->is_abad);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":local connections %u",
+ sp->is_loc);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Client server");
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":connected %u %u",
+ sp->is_cl, sp->is_sv);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %u.%uK %u.%uK",
+ sp->is_cks, sp->is_cbs, sp->is_sks, sp->is_sbs);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %u.%uK %u.%uK",
+ sp->is_ckr, sp->is_cbr, sp->is_skr, sp->is_sbr);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Tu %Tu",
+ sp->is_cti, sp->is_sti);
}