From 09c56a03b159d9a0c05a100c1379bf489ba45c4e Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Thu, 13 Apr 2000 15:58:22 +0000 Subject: [PATCH] Author: Kev Log message: Ok, with the exception of m_stats, being worked on by GW, this should complete the actual coding of the gline patch; server still won't compile until GW commits his changes, though, and I haven't compile- checked the rest (GW promised to do that ;) git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@160 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 23 ++++- include/handlers.h | 1 + ircd/gline.c | 42 +++++---- ircd/m_gline.c | 207 +++++++++++++++++++++++++++++++++++++++++++++ ircd/parse.c | 2 +- ircd/s_serv.c | 2 + ircd/s_user.c | 4 + 7 files changed, 261 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5dbfba8..4dc058b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2000-04-13 Kevin L. Mitchell + + * include/handlers.h: declare m_gline() + + * ircd/parse.c: gline can be called by users, but it only lists + the glines. + + * ircd/s_user.c (set_nick_name): resend gline if a remote server + introduces a glined client + + * ircd/s_serv.c (server_estab): burst glines, too + + * ircd/gline.c: fix up all the expire times to be offsets; + simplify gline_resend() + + * ircd/m_gline.c: begin coding replacements for ms_gline(), + mo_gline(), and m_gline() + + * ircd/gline.c (gline_add): allow *@#channel to work correctly; + also, prohibit local BADCHANs if LOCAL_BADCHAN not defined + 2000-04-13 Greg Sikorski * tools/Bouncer/*: Add comments/documentation/tags. @@ -401,7 +422,7 @@ # # ChangeLog for ircu2.10.11 # -# $Id: ChangeLog,v 1.77 2000-04-13 05:53:48 gte Exp $ +# $Id: ChangeLog,v 1.78 2000-04-13 15:58:22 kev Exp $ # # Insert new changes at beginning of the change list. # diff --git a/include/handlers.h b/include/handlers.h index 7a4c4d0..3889074 100644 --- a/include/handlers.h +++ b/include/handlers.h @@ -88,6 +88,7 @@ extern int m_admin(struct Client*, struct Client*, int, char*[]); extern int m_away(struct Client*, struct Client*, int, char*[]); extern int m_cnotice(struct Client*, struct Client*, int, char*[]); extern int m_cprivmsg(struct Client*, struct Client*, int, char*[]); +extern int m_gline(struct Client*, struct Client*, int, char*[]); extern int m_help(struct Client*, struct Client*, int, char*[]); extern int m_ignore(struct Client*, struct Client*, int, char*[]); extern int m_info(struct Client*, struct Client*, int, char*[]); diff --git a/ircd/gline.c b/ircd/gline.c index 911fa26..33e72a3 100644 --- a/ircd/gline.c +++ b/ircd/gline.c @@ -147,7 +147,8 @@ propagate_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline) GlineIsActive(gline) ? '+' : '-', gline->gl_user, GlineIsBadChan(gline) ? "" : "@", GlineIsBadChan(gline) ? "" : gline->gl_host, - gline->gl_expire, gline->gl_lastmod, gline->gl_reason); + gline->gl_expire - TStime(), gline->gl_lastmod, + gline->gl_reason); } else { if (gline->gl_lastmod) sendto_serv_butone(cptr, "%s " TOK_GLINE " * %c%s%s%s " TIME_T_FMT " " @@ -155,7 +156,7 @@ propagate_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline) GlineIsActive(gline) ? '+' : '-', gline->gl_user, GlineIsBadChan(gline) ? "" : "@", GlineIsBadChan(gline) ? "" : gline->gl_host, - gline->gl_expire, gline->gl_lastmod, + gline->gl_expire - TStime(), gline->gl_lastmod, gline->gl_reason); else sendto_serv_butone(cptr, "%s " TOK_GLINE " * %c%s%s%s " TIME_T_FMT @@ -163,7 +164,7 @@ propagate_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline) GlineIsActive(gline) ? '+' : '-', gline->gl_user, GlineIsBadChan(gline) ? "" : "@", GlineIsBadChan(gline) ? "" : gline->gl_host, - gline->gl_expire, gline->gl_reason); + gline->gl_expire - TStime(), gline->gl_reason); } } @@ -188,10 +189,20 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost, expire += TStime(); /* convert from lifetime to timestamp */ + /* NO_OLD_GLINE allows *@#channel to work correctly */ #ifdef BADCHAN - if (*userhost == '#' || *userhost == '&' || *userhost == '+') + if (*userhost == '#' || *userhost == '&' || *userhost == '+' +# ifndef NO_OLD_GLINE + || userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+' +# endif /* OLD_GLINE */ + ) { +# ifndef LOCAL_BADCHAN + if (flags & GLINE_LOCAL) + return 0; +# endif flags |= GLINE_BADCHAN; -#endif + } +#endif /* BADCHAN */ /* Inform ops... */ sendto_op_mask(SNO_GLINE, "%s adding %s %s for %s, expiring at " @@ -414,7 +425,7 @@ gline_burst(struct Client *cptr) else if (!GlineIsLocal(gline) && gline->gl_lastmod) sendto_one(cptr, "%s " TOK_GLINE " * %c%s@%s " TIME_T_FMT " " TIME_T_FMT " :%s", NumServ(&me), GlineIsActive(gline) ? '+' : '-', - gline->gl_user, gline->gl_host, gline->gl_expire, + gline->gl_user, gline->gl_host, gline->gl_expire - TStime(), gline->gl_lastmod, gline->gl_reason); } @@ -426,8 +437,8 @@ gline_burst(struct Client *cptr) else if (!GlineIsLocal(gline) && gline->gl_lastmod) sendto_one(cptr, "%s " TOK_GLINE " * %c%s " TIME_T_FMT " " TIME_T_FMT " :%s", NumServ(&me), GlineIsActive(gline) ? '+' : '-', - gline->gl_user, gline->gl_expire, gline->gl_lastmod, - gline->gl_reason); + gline->gl_user, gline->gl_expire - TStime(), + gline->gl_lastmod, gline->gl_reason); } } @@ -437,16 +448,11 @@ gline_resend(struct Client *cptr, struct Gline *gline) if (GlineIsLocal(gline) || !gline->gl_lastmod) return 0; - if (GlineIsBadChan(gline)) - sendto_one(cptr, "%s " TOK_GLINE " * %c%s " TIME_T_FMT " " TIME_T_FMT - " :%s", NumServ(&me), GlineIsActive(gline) ? '+' : '-', - gline->gl_user, gline->gl_expire, gline->gl_lastmod, - gline->gl_reason); - else - sendto_one(cptr, "%s " TOK_GLINE " * %c%s@%s " TIME_T_FMT " " TIME_T_FMT - " :%s", NumServ(&me), GlineIsActive(gline) ? '+' : '-', - gline->gl_user, gline->gl_host, gline->gl_expire, - gline->gl_lastmod, gline->gl_reason); + sendto_one(cptr, "%s " TOK_GLINE " * %c%s%s%s " TIME_T_FMT " " TIME_T_FMT + " :%s", NumServ(&me), GlineIsActive(gline) ? '+' : '-', + gline->gl_user, GlineIsBadChan(gline) ? "" : "@", + GlineIsBadChan(gline) ? "" : gline->gl_host, + gline->gl_expire - TStime(), gline->gl_lastmod, gline->gl_reason); return 0; } diff --git a/ircd/m_gline.c b/ircd/m_gline.c index aad3d0a..c2980c1 100644 --- a/ircd/m_gline.c +++ b/ircd/m_gline.c @@ -106,6 +106,212 @@ #include #include +/* + * ms_gline - server message handler + * + * parv[0] = Sender prefix + * parv[1] = Target: server numeric + * parv[2] = (+|-) + * parv[3] = G-line lifetime + * + * From Uworld: + * + * parv[4] = Comment + * + * From somewhere else: + * + * parv[4] = Last modification time + * parv[5] = Comment + * + */ +int +ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) +{ + struct Client *acptr = 0; + struct Gline *agline; + unsigned int flags = 0; + time_t expire_off, lastmod = 0; + char *mask = parv[2], *target = parv[1], *reason; + + if (parc == 4) { + if (!find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) + return need_more_params(sptr, "GLINE"); + + reason = parv[4]; + flags |= GLINE_FORCE; + } else if (parc >= 5) { + lastmod = atoi(parv[4]); + reason = parv[5]; + } else + return need_more_params(sptr, "GLINE"); + + if (!(target[0] == '*' && target[1] == '\0')) { + if (!(acptr = FindNServer(target))) + return 0; /* no such server */ + + if (!IsMe(acptr)) { /* manually propagate */ + if (IsServer(sptr)) { + if (!lastmod) + sendto_one(acptr, "%s " TOK_GLINE " %s %s %s :%s", NumServ(sptr), + target, mask, parv[3], reason); + else + sendto_one(acptr, "%s " TOK_GLINE " %s %s %s %s :%s", NumServ(sptr), + target, mask, parv[3], parv[4], reason); + } else + sendto_one(acptr, "%s%s " TOK_GLINE " %s %s %s %s :%s", NumNick(sptr), + target, mask, parv[3], parv[4], reason); + + return 0; + } + + flags |= GLINE_LOCAL; + } + + if (*server == '-') + server++; + else if (*server == '+') { + flags |= GLINE_ACTIVE; + server++; + } else + flags |= GLINE_ACTIVE; + + expire_off = atoi(parv[3]); + + agline = gline_find(mask, GLINE_ANY); + + if (agline) { + if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */ + gline_free(agline); + else if (!lastmod || GlineLastMod(agline) < lastmod) { /* new mod */ + if (flags & GLINE_ACTIVE) + return gline_activate(cptr, sptr, agline, lastmod); + else + return gline_deactivate(cptr, sptr, agline, lastmod); + } else if (GlineLastMod(agline) == lastmod) + return 0; + else + return gline_resend(cptr, agline); /* other server desynched WRT gline */ + } + + return gline_add(cptr, sptr, mask, reason, expire_off, lastmod, flags); +} + +/* + * mo_gline - oper message handler + * + * parv[0] = Sender prefix + * parv[1] = [[+|-]] + * + * Old style: + * + * parv[2] = [Expiration offset] + * parv[3] = [Comment] + * + * New style: + * + * parv[2] = [target] + * parv[3] = [Expiration offset] + * parv[4] = [Comment] + * + */ +int +mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) +{ + struct Client *acptr = 0; + struct Gline *agline; + unsigned int flags = 0; + time_t expire_off; + char *mask = parv[1], *target = 0, *reason; + + if (parc < 2) + return gline_list(sptr, 0); + + if (*mask == '+') { + flags |= GLINE_ACTIVE; + mask++; + } else if (*mask == '-') + mask++; + else + return gline_list(sptr, mask); + +#ifndef LOCOP_LGLINE + if (!IsOper(sptr)) { + send_error_to_client(sptr, ERR_NOPRIVILEGES); + return 0; + } +#endif + + if (parc == 3) { + expire_off = atoi(parv[2]); + reason = parv[3]; + flags |= GLINE_LOCAL; + } else if (parc >= 4) { + target = parv[2]; + expire_off = atoi(parv[3]); + reason = parv[4]; + } else + return need_more_params(sptr, "GLINE"); + + if (target) { + if (!(target[0] == '*' && target[1] == '\0')) { + if (!(acptr = find_match_server(target))) { + send_error_to_client(sptr, ERR_NOSUCHSERVER, target); + return 0; + } + + if (!IsMe(acptr)) { /* manually propagate, since we don't set it */ + if (!IsOper(sptr)) { + send_error_to_client(sptr, ERR_NOPRIVILEGES); + return 0; + } + + sendto_one(acptr, "%s%s " TOK_GLINE " %s %c%s %s " TIME_T_FMT " :%s", + NumNick(sptr), NumServ(acptr), + flags & GLINE_ACTIVE ? '?' : '-', mask, parv[3], TStime(), + reason); + return 0; + } + + flags |= GLINE_LOCAL; + } else if (!IsOper(sptr)) { + send_error_to_client(sptr, ERR_NOPRIVILEGES); + return 0; + } + } + + agline = gline_find(mask, GLINE_ANY); + + if (agline) { + if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */ + gline_free(agline); + else { + if (flags & GLINE_ACTIVE) + return gline_activate(cptr, sptr, agline, TStime()); + else + return gline_deactivate(cptr, sptr, agline, TStime()); + } + } + + return gline_add(cptr, sptr, mask, reason, expire_off, TStime(), flags); +} + +/* + * m_gline - user message handler + * + * parv[0] = Sender prefix + * parv[1] = [] + * + */ +int +m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) +{ + if (parc < 2) + return gline_list(sptr, 0); + + return gline_list(sptr, parv[1]); +} + +#if 0 /* * ms_gline - server message handler * @@ -1130,3 +1336,4 @@ int m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) #endif /* 0 */ +#endif /* 0 */ diff --git a/ircd/parse.c b/ircd/parse.c index c5d562a..64e9d0f 100644 --- a/ircd/parse.c +++ b/ircd/parse.c @@ -437,7 +437,7 @@ struct Message msgtab[] = { TOK_GLINE, 0, MAXPARA, MFLG_SLOW, 0, /* UNREG, CLIENT, SERVER, OPER, SERVICE */ - { m_unregistered, m_not_oper, ms_gline, mo_gline, m_ignore } + { m_unregistered, m_gline, ms_gline, mo_gline, m_ignore } }, { MSG_JUPE, diff --git a/ircd/s_serv.c b/ircd/s_serv.c index c74be25..a2912b5 100644 --- a/ircd/s_serv.c +++ b/ircd/s_serv.c @@ -27,6 +27,7 @@ #include "channel.h" #include "client.h" #include "crule.h" +#include "gline.h" #include "hash.h" #include "ircd.h" #include "ircd_alloc.h" @@ -272,6 +273,7 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf) send_channel_modes(cptr, chptr); } jupe_burst(cptr); + gline_burst(cptr); sendto_one(cptr, "%s EB", NumServ(&me)); return 0; } diff --git a/ircd/s_user.c b/ircd/s_user.c index a09321b..b2f3cd4 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -27,6 +27,7 @@ #include "channel.h" #include "class.h" #include "client.h" +#include "gline.h" #include "hash.h" #include "ircd.h" #include "ircd_alloc.h" @@ -687,6 +688,7 @@ int set_nick_name(struct Client* cptr, struct Client* sptr, if (IsServer(sptr)) { int i; const char* p; + struct Gline *gline; /* * A server introducing a new client, change source @@ -725,6 +727,8 @@ int set_nick_name(struct Client* cptr, struct Client* sptr, ircd_strncpy(new_client->username, parv[4], USERLEN); ircd_strncpy(new_client->user->host, parv[5], HOSTLEN); ircd_strncpy(new_client->info, parv[parc - 1], REALLEN); + if ((gline = gline_lookup(new_client)) && GlineIsActive(gline)) + gline_resend(cptr, gline); return register_user(cptr, new_client, new_client->name, parv[4]); } else if (sptr->name[0]) { -- 2.20.1