From: Gabriel B. <sh...@us...> - 2005-12-04 07:14:17
|
Update of /cvsroot/solidircd/solidircd-stable/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30793/src Modified Files: Makefile.in s_conf.c s_serv.c s_user.c userban.c Added Files: glines.c Log Message: minor updates, currently working on gline implementation. Index: Makefile.in =================================================================== RCS file: /cvsroot/solidircd/solidircd-stable/src/Makefile.in,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.in 4 Sep 2005 18:57:33 -0000 1.6 --- Makefile.in 4 Dec 2005 07:14:07 -0000 1.7 *************** *** 20,24 **** SOURCES = blalloc.c bsd.c channel.c clientlist.c clones.c confparse.c \ ! fdlist.c fds.c hash.c hide.c inet_addr.c ircd.c ircsprintf.c klines.c list.c \ m_shun.c m_nick.c m_rwho.c m_server.c m_services.c m_stats.c m_who.c match.c \ memcount.c modules.c packet.c parse.c pcre.c probability.c res.c \ --- 20,24 ---- SOURCES = blalloc.c bsd.c channel.c clientlist.c clones.c confparse.c \ ! fdlist.c fds.c hash.c hide.c inet_addr.c ircd.c ircsprintf.c klines.c glines.c list.c \ m_shun.c m_nick.c m_rwho.c m_server.c m_services.c m_stats.c m_who.c match.c \ memcount.c modules.c packet.c parse.c pcre.c probability.c res.c \ *************** *** 141,144 **** --- 141,149 ---- ../include/fdlist.h ../include/ircsprintf.h ../include/find.h \ ../include/userban.h ../include/numeric.h + glines.o: glines.c ../include/struct.h ../include/config.h \ + ../include/setup.h ../include/defs.h ../include/sys.h ../include/hash.h \ + ../include/sbuf.h ../include/common.h ../include/h.h ../include/send.h \ + ../include/fdlist.h ../include/ircsprintf.h ../include/find.h \ + ../include/userban.h ../include/numeric.h list.o: list.c ../include/struct.h ../include/config.h ../include/setup.h \ ../include/defs.h ../include/sys.h ../include/hash.h ../include/sbuf.h \ Index: s_conf.c =================================================================== RCS file: /cvsroot/solidircd/solidircd-stable/src/s_conf.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** s_conf.c 4 Sep 2005 05:24:13 -0000 1.9 --- s_conf.c 4 Dec 2005 07:14:07 -0000 1.10 *************** *** 1539,1564 **** return lnum; /* this isnt a parser problem - dont pull out */ ! ban->flags |= (UBAN_LOCAL|UBAN_CONF); DupString(ban->reason, ub_r); ban->timeset = NOW; add_hostbased_userban(ban); - /* Check local users against it */ - for (i = 0; i <= highest_fd; i++) - { - if (!(ub_acptr = local[i]) || IsMe(ub_acptr) || - IsLog(ub_acptr)) - continue; - - if (IsPerson(ub_acptr) && user_match_ban(ub_acptr, ban)) - { - sendto_ops(LOCAL_BAN_NAME " active for %s", - get_client_name(ub_acptr, FALSE)); - ircsprintf(fbuf, LOCAL_BANNED_NAME ": %s", ub_r); - exit_client(ub_acptr, ub_acptr, &me, fbuf); - i--; - } - } return lnum; } --- 1539,1549 ---- return lnum; /* this isnt a parser problem - dont pull out */ ! ban->flags |= (UBAN_LOCAL|UBAN_CONF); DupString(ban->reason, ub_r); ban->timeset = NOW; add_hostbased_userban(ban); + userban_sweep(ban); return lnum; } Index: s_user.c =================================================================== RCS file: /cvsroot/solidircd/solidircd-stable/src/s_user.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** s_user.c 4 Sep 2005 05:24:13 -0000 1.13 --- s_user.c 4 Dec 2005 07:14:07 -0000 1.14 *************** *** 938,941 **** --- 938,942 ---- get_client_name(sptr, FALSE)); } + else { *************** *** 943,946 **** --- 944,955 ---- char *reason, *ktype; int local; + /* + char *gtype; + int global; + + global = (ban->flags & UBAN_GLINE) ? 1 : 0; + gtype = global ? NETWORK_GLINE_NAME : NETWORK_GLINNED_NAME; + reason = ban->reason ? ban->reason : gtype; + */ local = (ban->flags & UBAN_LOCAL) ? 1 : 0; *************** *** 948,951 **** --- 957,962 ---- reason = ban->reason ? ban->reason : ktype; + + sendto_one(sptr, err_str(ERR_YOUREBANNEDCREEP), me.name, sptr->name, ktype); *************** *** 971,974 **** --- 982,987 ---- return exit_client(cptr, sptr, &me, reason); } + + } --- NEW FILE: glines.c --- /* * glines.c - gline interface and storage * Copyright (C) 2005 Trevor Talbot and * the DALnet coding team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* $Id: glines.c,v 1.1 2005/12/04 07:14:07 sheik Exp $ */ /* * This is a simple K-Line journal implementation. When a K-Line with a * duration greater than gline_MIN_STORE_TIME is added, it is written to the * journal file (.glines): * + expireTS usermask hostmask reason * * When a K-Line is manually removed, it also results in a journal entry: * - usermask hostmask * * This allows K-Lines to be saved across restarts and rehashes. * * To keep the journal from getting larger than it needs to be, it is * periodically compacted: all active K-Lines are dumped into a new file, which * then replaces the active journal. This is done on startup as well as every * gline_STORE_COMPACT_THRESH journal entries. */ #include "struct.h" #include "common.h" #include "sys.h" #include "h.h" #include <fcntl.h> #include "userban.h" #include "numeric.h" static int journal = -1; static char journalfilename[512]; static int journalcount; void glinestore_add(struct userBan *); void glinestore_remove(struct userBan *); /* ircd.c */ extern int forked; /* s_misc.c */ extern char *smalldate(time_t); /* * m_gline * Add a local user@host ban. * * parv[0] = sender * parv[1] = duration (optional) * parv[2] = nick or user@host mask * parv[3] = reason (optional) */ int m_gline(aClient *cptr, aClient *sptr, int parc, char *parv[]) { char rbuf[512]; char *target; char *user; char *host; char *reason = "<no reason>"; int tgminutes = DEFAULT_GLINE_TIME; int tgseconds; long lval; struct userBan *ban; struct userBan *existing; if (!OPCanGline(sptr)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (parc < 2) { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "gline"); return 0; } lval = strtol(parv[1], &target, 10); if (*target != 0) { target = parv[1]; if (parc > 2) reason = parv[2]; } else { /* valid expiration time */ tgminutes = lval; if (parc < 3) { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "Gline"); return 0; } target = parv[2]; if (parc > 3) reason = parv[3]; } /* negative times, or times greater than a year, are permanent */ if (tgminutes < 0 || tgminutes > (365 * 24 * 60)) tgminutes = 0; tgseconds = tgminutes * 60; if ((host = strchr(target, '@'))) { *host++ = 0; user = target; } else { user = "*"; host = target; } if (!match(user, "akjhfkahfasfjd") && !match(host, "ldksjfl.kss...kdjfd.jfklsjf")) { sendto_one(sptr, ":%s NOTICE %s :gline: %s@%s mask is too wide", me.name, parv[0], user, host); return 0; } /* * XXX: nick target support to be re-added */ if (!(ban = make_hostbased_ban(user, host))) { sendto_one(sptr, ":%s NOTICE %s :gline: invalid ban mask %s@%s", me.name, parv[0], user, host); return 0; } ban->flags |= UBAN_GLINE; /* only looks for duplicate glines, not akills */ if ((existing = find_userban_exact(ban, UBAN_GLINE))) { sendto_one(sptr, ":%s NOTICE %s :gline: %s@%s is already %s: %s", me.name, parv[0], user, host, NETWORK_GLINE_NAME, existing->reason ? existing->reason : "<no reason>"); userban_free(ban); return 0; } if (user_match_ban(sptr, ban)) { sendto_one(sptr, ":%s NOTICE %s :gline: %s@%s matches you, rejected", me.name, parv[0], user, host); userban_free(ban); return 0; } ircsnprintf(rbuf, sizeof(rbuf), "%s (%s)", reason, smalldate(0)); ban->reason = MyMalloc(strlen(rbuf) + 1); strcpy(ban->reason, rbuf); if (tgseconds) { ban->flags |= UBAN_TEMPORARY; ban->timeset = NOW; ban->duration = tgseconds; } add_hostbased_userban(ban); if (!tgminutes || tgminutes >= GLINE_MIN_STORE_TIME) glinestore_add(ban); userban_sweep(ban); host = get_userban_host(ban, rbuf, sizeof(rbuf)); if (tgminutes) sendto_realops("%s added temporary %d min. "NETWORK_GLINE_NAME" for" " [%s@%s] [%s]", parv[0], tgminutes, user, host, reason); else sendto_realops("%s added "NETWORK_GLINE_NAME" for [%s@%s] [%s]", parv[0], user, host, reason); return 0; } /* * m_ungline * Remove a local user@host ban. * * parv[0] = sender * parv[1] = user@host mask */ int m_ungline(aClient *cptr, aClient *sptr, int parc, char *parv[]) { char hbuf[512]; char *user; char *host; struct userBan *ban; struct userBan *existing; if (!OPCanUNGline(sptr)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (parc < 2) { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "UNGline"); return 0; } if ((host = strchr(parv[1], '@'))) { *host++ = 0; user = parv[1]; } else { user = "*"; host = parv[1]; } if (!(ban = make_hostbased_ban(user, host))) { sendto_one(sptr, ":%s NOTICE %s :UNGline: No such ban %s@%s", me.name, parv[0], user, host); return 0; } ban->flags |= UBAN_GLINE; existing = find_userban_exact(ban, UBAN_GLINE); host = get_userban_host(ban, hbuf, sizeof(hbuf)); userban_free(ban); if (!existing) { sendto_one(sptr, ":%s NOTICE %s :UNGLINE: No such ban %s@%s", me.name, parv[0], user, host); return 0; } if (existing->flags & UBAN_CONF) { sendto_one(sptr, ":%s NOTICE %s :UNGline: %s@%s is specified in the" " configuration file and cannot be removed online", me.name, parv[0], user, host); return 0; } remove_userban(existing); glinestore_remove(existing); userban_free(existing); sendto_ops("%s has removed the G-Line for: [%s@%s]", parv[0], user, host); return 0; } static void gs_error(char *msg) { if (!forked) puts(msg); else sendto_ops("%s", msg); } /* * Writes a G-Line to the appropriate file. */ void gs_write(int f, char type, struct userBan *ub) { char outbuf[1024]; char cidr[4] = ""; time_t expiretime = 0; char *user = "*"; char *reason = ""; char *host = ub->h; int len; /* userban.c */ unsigned int netmask_to_cidr(unsigned int); if (ub->flags & UBAN_TEMPORARY) expiretime = ub->timeset + ub->duration; if (ub->u) user = ub->u; if (ub->reason) reason = ub->reason; if (ub->flags & (UBAN_CIDR4|UBAN_CIDR4BIG)) { host = inetntoa((char *)&ub->cidr4ip); ircsprintf(cidr, "/%d", netmask_to_cidr(ntohl(ub->cidr4mask))); } if (type == '+') len = ircsprintf(outbuf, "%c %d %s %s%s %s\n", type, (int)expiretime, user, host, cidr, reason); else len = ircsprintf(outbuf, "%c %s %s%s\n", type, user, host, cidr); write(f, outbuf, len); } /* * Parses a G-Line entry from a storage journal line. * Returns 0 on invalid input, 1 otherwise. */ static int gs_read(char *s) { char type; time_t duration = 0; char *user; char *host; char *reason = ""; struct userBan *ban; struct userBan *existing; type = *s++; /* bad type */ if (type != '+' && type != '-') return 0; /* malformed */ if (*s++ != ' ') return 0; if (type == '+') { duration = strtol(s, &s, 0); if (duration) { /* already expired */ if (NOW >= duration) return 1; duration -= NOW; } /* malformed */ if (*s++ != ' ') return 0; } /* usermask */ user = s; while (*s && *s != ' ') s++; /* malformed */ if (*s != ' ') return 0; /* mark end of user mask */ *s++ = 0; /* hostmask */ host = s; while (*s && *s != ' ') s++; if (type == '+') { /* malformed */ if (*s != ' ') return 0; /* mark end of host mask */ *s++ = 0; /* reason is the only thing left */ reason = s; } ban = make_hostbased_ban(user, host); if (!ban) return 0; ban->flags |= UBAN_GLINE; if (type == '+') { if (duration) { ban->flags |= UBAN_TEMPORARY; ban->timeset = NOW; ban->duration = duration; } if (*reason) DupString(ban->reason, reason); add_hostbased_userban(ban); } else { existing = find_userban_exact(ban, UBAN_GLINE|UBAN_CONF); userban_free(ban); /* add may have been skipped due to being expired, so not an error */ if (!existing) return 1; remove_userban(existing); userban_free(existing); } return 1; } /* * Compact G-Line store: dump active glines to a new file and remove the * current journal. * Returns 1 on success, 0 on failure. */ int glinestore_compact(void) { char buf1[512]; int newfile; /* userban.c */ extern void gs_dumpglines(int); if (forked) sendto_ops_lev(DEBUG_LEV, "Compacting G-Line store..."); journalcount = 0; /* open a compaction file to dump all active glines to */ ircsnprintf(buf1, sizeof(buf1), "%s/.glines_c", dpath); newfile = open(buf1, O_WRONLY|O_CREAT|O_TRUNC, 0700); if (newfile < 0) { ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to create G-Line" " compaction file .glines_c: %s", strerror(errno)); gs_error(buf1); return 0; } /* do the dump */ gs_dumpglines(newfile); close(newfile); /* close active storage file, rename compaction file, and reopen */ if (journal >= 0) { close(journal); journal = -1; } if (rename(buf1, journalfilename) < 0) { ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to rename G-Line" " compaction file .glines_c to .glines: %s", strerror(errno)); gs_error(buf1); return 0; } journal = open(journalfilename, O_WRONLY|O_APPEND, 0700); if (journal < 0) { ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to reopen G-Line" " storage file .glines: %s", strerror(errno)); gs_error(buf1); return 0; } return 1; } /* * Add a G-Line to the active store. */ void glinestore_add(struct userBan *ban) { if (journal >= 0) gs_write(journal, '+', ban); if (++journalcount > GLINE_STORE_COMPACT_THRESH) glinestore_compact(); } /* * Remove a G-Line from the active store. */ void glinestore_remove(struct userBan *ban) { if (journal >= 0) gs_write(journal, '-', ban); if (++journalcount > GLINE_STORE_COMPACT_THRESH) glinestore_compact(); } /* * Initialize G-Line storage. Pass 1 when glines don't need to be reloaded. * Returns 0 on failure, 1 otherwise. */ int glinestore_init(int noreload) { char buf1[1024]; FILE *jf; ircsnprintf(journalfilename, sizeof(journalfilename), "%s/.glines", dpath); if (journal >= 0) { if (noreload) return 1; close(journal); journal = -1; } /* "a+" to create if it doesn't exist */ jf = fopen(journalfilename, "a+"); if (!jf) { ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to open G-Line storage" " file .glines: %s", strerror(errno)); gs_error(buf1); return 0; } rewind(jf); /* replay journal */ while (fgets(buf1, sizeof(buf1), jf)) { char *s = strchr(buf1, '\n'); /* no newline, consider it malformed and stop here */ if (!s) break; *s = 0; if (!gs_read(buf1)) break; } fclose(jf); /* this will reopen the journal for appending */ return glinestore_compact(); } Index: s_serv.c =================================================================== RCS file: /cvsroot/solidircd/solidircd-stable/src/s_serv.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** s_serv.c 4 Sep 2005 18:57:33 -0000 1.8 --- s_serv.c 4 Dec 2005 07:14:07 -0000 1.9 *************** *** 2224,2241 **** /* Check local users against it */ ! for (i = 0; i <= highest_fd; i++) ! { ! if (!(acptr = local[i]) || IsMe(acptr) || IsLog(acptr)) ! continue; ! ! if (IsPerson(acptr) && user_match_ban(acptr, ban)) ! { ! sendto_ops(LOCAL_BAN_NAME" active for %s", ! get_client_name(acptr, FALSE)); ! ircsprintf(fbuf, LOCAL_BANNED_NAME": %s", reason); ! exit_client(acptr, acptr, &me, fbuf); ! i--; ! } ! } host = get_userban_host(ban, fbuf, 512); --- 2224,2229 ---- /* Check local users against it */ ! ! userban_sweep(ban); host = get_userban_host(ban, fbuf, 512); *************** *** 2486,2504 **** #endif /* UNKLINE */ ! ! /* ! * m_gline ! * ----- client parameters ----- ! * parv[0] = ! * parv[1] = ! * parv[2] = ! * parv[3] = ! */ ! ! int m_gline(aClient *cptr, aClient *sptr, int parc, char *parv[]) { struct userBan *ban, *oban; char buffer[1024]; char *user, *host; char *reason; --- 2474,2490 ---- #endif /* UNKLINE */ ! #if 0 int m_gline(aClient *cptr, aClient *sptr, int parc, char *parv[]) { struct userBan *ban, *oban; + #if defined (LOCKFILE) + struct pkl *k; + #else + int out; + #endif + char buffer[1024]; + + char *filename; /* filename to use for kline */ char *user, *host; char *reason; *************** *** 2507,2511 **** char tempuser[USERLEN + 2]; char temphost[HOSTLEN + 1]; ! int temporary_gline_time = 0; /* -Dianora */ time_t temporary_gline_time_seconds = 0; int time_specified = 0; --- 2493,2497 ---- char tempuser[USERLEN + 2]; char temphost[HOSTLEN + 1]; ! int temporary_gline_time = 0; /* -Dianora */ time_t temporary_gline_time_seconds = 0; int time_specified = 0; *************** *** 2514,2531 **** char fbuf[512]; ! ! ! ! if (!IsAnOper(sptr) && !IsServer(sptr)) { ! sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); ! return 0; } if (parc < 2) { ! sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), ! me.name, parv[0], "GLINE"); ! return 0; } --- 2500,2514 ---- char fbuf[512]; ! if (!MyClient(sptr) || !IsAnOper(sptr) || !OPCanGline(sptr)) { ! sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); ! return 0; } if (parc < 2) { ! sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), ! me.name, parv[0], "GLINE"); ! return 0; } *************** *** 2534,2565 **** if ((temporary_gline_time = isnumber(argv)) >= 0) { ! if (parc < 3) ! { ! sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), ! me.name, parv[0], "GLINE"); ! return 0; ! } ! if (temporary_gline_time > 1080000) ! temporary_gline_time = 1080000; ! ! temporary_gline_time_seconds = (time_t) temporary_gline_time; ! argv = parv[2]; ! parc--; ! time_specified = 1; } else { ! temporary_gline_time = 0; } if(strchr(argv, ' ')) { ! sendto_one(sptr, ! ":%s NOTICE %s :Poorly formatted hostname " ! "(contains spaces). Be sure you are using the form: " ! "/quote GLINE [time] <user@host/nick> :<reason>", ! me.name, parv[0]); ! return 0; } --- 2517,2549 ---- if ((temporary_gline_time = isnumber(argv)) >= 0) { ! if (parc < 3) ! { ! sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), ! me.name, parv[0], "GLINE"); ! return 0; ! } ! if (temporary_gline_time > (24 * 60 * 7)) ! temporary_gline_time = (24 * 60 * 7); /* Max it at 1 week */ ! temporary_gline_time_seconds = ! (time_t) temporary_gline_time *(time_t) 60; ! ! /* turn it into minutes */ ! argv = parv[2]; ! parc--; ! time_specified = 1; } else { ! temporary_gline_time = 0; /* -1 minute klines are bad... :) - lucas */ } if(strchr(argv, ' ')) { ! sendto_one(sptr, ":%s NOTICE %s :Poorly formatted hostname " ! "(contains spaces). Be sure you are using the form: " ! "/quote GLINE [time] <user@host/nick> :<reason>", ! me.name, parv[0]); ! return 0; } *************** *** 2567,2659 **** if ((host = strchr(argv, '@')) || *argv == '*') { ! if (host) ! { ! user = argv; ! *(host++) = '\0'; ! } ! else ! { ! user = "*"; ! host = argv; ! } ! ! if (!*host) ! host = "*"; ! ! strncpyzt(tempuser, user, USERLEN + 2); ! strncpyzt(temphost, host, HOSTLEN); ! user = tempuser; ! host = temphost; } else { ! ! if (!(acptr = find_chasing(sptr, argv, NULL))) ! return 0; ! if (!acptr->user) ! return 0; ! if (IsServer(acptr)) ! { ! sendto_one(sptr, ":%s NOTICE %s :Can't GLINE a server, use @'s " ! "where appropriate", me.name, parv[0]); ! return 0; ! } ! tempuser[0] = '*'; ! if (*acptr->user->username == '~') ! strcpy(tempuser + 1, (char *) acptr->user->username + 1); ! ! else ! strcpy(tempuser + 1, acptr->user->username); ! user = tempuser; ! host = cluster(acptr->user->host); } if (time_specified) ! argv = parv[3]; else ! argv = parv[2]; - /* FIXME: Shouldnt we use our hown DEFAULT_GLINE_TIME? - Tux`*/ #ifdef DEFAULT_KLINE_TIME ! if (time_specified <= 0) { ! temporary_gline_time = 30; ! temporary_gline_time_seconds = (time_t) temporary_gline_time *(time_t) 60; } #endif if (parc > 2) { ! if (*argv) ! reason = argv; ! else ! reason = "No reason"; } else ! reason = "No reason"; if (!match(user, "akjhfkahfasfjd") && ! !match(host, "ldksjfl.kss...kdjfd.jfklsjf")) { ! sendto_one(sptr, ":%s NOTICE %s :Can't G-Line *@*", me.name, ! parv[0]); ! return 0; } if (temporary_gline_time == 0 && strchr(reason, ':')) { ! sendto_one(sptr, ! ":%s NOTICE %s :Invalid character ':' in comment", ! me.name, parv[0]); ! return 0; } if (temporary_gline_time == 0 && strchr(reason, '#')) { ! sendto_one(sptr,":%s NOTICE %s :Invalid character '#' in comment", ! me.name, parv[0]); ! return 0; } --- 2551,2651 ---- if ((host = strchr(argv, '@')) || *argv == '*') { + /* Explicit user@host mask given */ ! if (host) /* Found user@host */ ! { ! user = argv; /* here is user part */ ! *(host++) = '\0'; /* and now here is host */ ! } ! else ! { ! user = "*"; /* no @ found, assume its *@somehost */ ! host = argv; ! } ! ! if (!*host) /* duh. no host found, assume its '*' host */ ! host = "*"; ! strncpyzt(tempuser, user, USERLEN + 2); /* allow for '*' in front */ ! strncpyzt(temphost, host, HOSTLEN); ! user = tempuser; ! host = temphost; } else { ! /* Try to find user@host mask from nick */ ! ! if (!(acptr = find_chasing(sptr, argv, NULL))) ! return 0; ! if (!acptr->user) ! return 0; ! if (IsServer(acptr)) ! { ! sendto_one(sptr, ":%s NOTICE %s :Can't GLINE a server, use @'s " ! "where appropriate", me.name, parv[0]); ! return 0; ! } ! /* ! * turn the "user" bit into "*user", blow away '~' if found in ! * original user name (non-idented) ! */ ! ! tempuser[0] = '*'; ! if (*acptr->user->username == '~') ! strcpy(tempuser + 1, (char *) acptr->user->username + 1); ! else ! strcpy(tempuser + 1, acptr->user->username); ! user = tempuser; ! host = cluster(acptr->user->host); } if (time_specified) ! argv = parv[3]; else ! argv = parv[2]; #ifdef DEFAULT_KLINE_TIME ! if (time_specified == 0) { ! temporary_gline_time = DEFAULT_KLINE_TIME; ! temporary_gline_time_seconds = ! (time_t) temporary_gline_time *(time_t) 60; } #endif + if (parc > 2) { ! if (*argv) ! reason = argv; ! else ! reason = "No reason"; } else ! reason = "No reason"; if (!match(user, "akjhfkahfasfjd") && ! !match(host, "ldksjfl.kss...kdjfd.jfklsjf")) { ! sendto_one(sptr, ":%s NOTICE %s :Can't K-Line *@*", me.name, ! parv[0]); ! return 0; } + /* we can put whatever we want in temp K: lines */ if (temporary_gline_time == 0 && strchr(reason, ':')) { ! sendto_one(sptr, ! ":%s NOTICE %s :Invalid character ':' in comment", ! me.name, parv[0]); ! return 0; } if (temporary_gline_time == 0 && strchr(reason, '#')) { ! sendto_one(sptr, ! ":%s NOTICE %s :Invalid character '#' in comment", ! me.name, parv[0]); ! return 0; } *************** *** 2661,2715 **** if(!ban) { ! sendto_one(sptr, ":%s NOTICE %s :Malformed ban %s@%s", me.name, parv[0], ! user, host); ! return 0; } - - if ((oban = find_userban_exact(ban, 0))) { ! if (oban->flags & UBAN_GLINE) ! { ! if (MyClient(sptr)) ! { ! sendto_one(sptr, ":%s NOTICE %s :[%s@%s] already %s for %s", ! me.name, parv[0], user, host, NETWORK_GLINNED_NAME, ! oban->reason ? oban->reason : "<No Reason>"); ! } ! else ! { ! /* The G-Line does not exist, and sptr is not our client. ! * However, we should still send it... - Tux` */ ! host = get_userban_host(ban, fbuf, 512); ! sendto_serv_butone(sptr, ":%s GLINE %d %s@%s :%s", ! parv[0], temporary_gline_time_seconds, user, host, reason); ! ! } ! userban_free(ban); ! return 0; ! } } current_date = smalldate((time_t) 0); ! ban->flags |= temporary_gline_time ? (UBAN_GLINE|UBAN_TEMPORARY) : (UBAN_GLINE); ! if (IsServer(sptr)) ! ircsprintf(buffer, "%s", reason); ! ircsprintf(buffer, "%s (%s)", reason, current_date); ban->reason = (char *) MyMalloc(strlen(buffer) + 1); strcpy(ban->reason, buffer); ! ban->timeset = timeofday; ! ban->duration = temporary_gline_time_seconds; ! ! if(user_match_ban(sptr, ban)) { ! sendto_one(sptr, ":%s NOTICE %s :You attempted to add a gline [%s@%s] " ! "which would affect yourself. Aborted.", ! me.name, parv[0], user, host); ! userban_free(ban); ! return 0; } --- 2653,2695 ---- if(!ban) { ! sendto_one(sptr, ":%s NOTICE %s :Malformed ban %s@%s", me.name, parv[0], ! user, host); ! return 0; } if ((oban = find_userban_exact(ban, 0))) { ! char *gtype = (oban->flags & UBAN_GLINE) ? ! NETWORK_GLINE_NAME : NETWORK_GLINNE_NAME; ! ! sendto_one(sptr, ":%s NOTICE %s :[%s@%s] already %s for %s", ! me.name, parv[0], user, host, gtype, ! oban->reason ? oban->reason : "<No Reason>"); ! ! userban_free(ban); ! return 0; } current_date = smalldate((time_t) 0); ! ircsprintf(buffer, "%s (%s)", reason, current_date); ! ! ban->flags |= UBAN_GLINE; ban->reason = (char *) MyMalloc(strlen(buffer) + 1); strcpy(ban->reason, buffer); ! if (temporary_gline_time) ! { ! ban->flags |= UBAN_TEMPORARY; ! ban->timeset = timeofday; ! ban->duration = temporary_gline_time_seconds; ! } if(user_match_ban(sptr, ban)) { ! sendto_one(sptr, ":%s NOTICE %s :You attempted to add a ban [%s@%s]" ! " which would affect yourself. Aborted.", ! me.name, parv[0], user, host); ! userban_free(ban); ! return 0; } *************** *** 2717,2823 **** /* Check local users against it */ ! for (i = 0; i <= highest_fd; i++) { ! if (!(acptr = local[i]) || IsMe(acptr) || IsLog(acptr)) ! continue; ! if (IsPerson(acptr) && user_match_ban(acptr, ban)) ! { ! sendto_ops(NETWORK_GLINE_NAME" active for %s", ! get_client_name(acptr, FALSE)); ! sendto_serv_butone(sptr, ":%s GLOBOPS :%s active for %s", ! NETWORK_GLINE_NAME, me.name, get_client_name(acptr, FALSE)); ! ircsprintf(fbuf, NETWORK_GLINNED_NAME": %s", reason); ! exit_client(acptr, acptr, &me, fbuf); ! i--; ! } } ! host = get_userban_host(ban, fbuf, 512); ! if(temporary_gline_time) ! { ! sendto_realops("%s added a temporary %d sec(s) "NETWORK_GLINE_NAME" for [%s@%s] [%s]", ! parv[0], temporary_gline_time, user, host, reason); ! sendto_serv_butone(sptr, ":%s GLINE %d %s@%s :%s", ! parv[0], temporary_gline_time_seconds, user, host, reason); ! return 0; } ! sendto_realops("%s added a permanent gline for [%s@%s] [%s]", ! parv[0], user, host, reason); ! sendto_serv_butone(sptr, ":%s GLINE %d %s@%s :%s", ! parv[0], temporary_gline_time_seconds, user, host, reason); return 0; } ! int m_ungline(aClient *cptr, aClient *sptr, int parc, char *parv[]) { struct userBan *ban; ! char *user, *host; ! ! if (!IsAnOper(sptr)) { ! sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); ! return 0; } ! ! if(parc<2) { ! sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0],"UNGLINE"); ! return 0; } ! if ((host = strchr(parv[1], '@')) || *parv[1] == '*') { ! if (host) { ! user = parv[1]; ! *(host++) = '\0'; ! } else { ! user = "*"; ! host = parv[1]; ! } ! } else { ! sendto_one(sptr, ":%s NOTICE %s :Invalid parameters",me.name, parv[0]); ! return 0; } ! if ((user[0] == '*') && (user[1] == '\0') && ! (host[0] == '*') && (host[1] == '\0')) { ! sendto_one(sptr, ":%s NOTICE %s :Cannot ungline everyone",me.name, parv[0]); ! return 0; } ban = make_hostbased_ban(user, host); ! if(ban) { ! struct userBan *oban; ! ban->flags |= (UBAN_GLINE|UBAN_TEMPORARY); ! if((oban = find_userban_exact(ban, UBAN_GLINE))) { ! char tmp[512]; ! host = get_userban_host(oban, tmp, 512); ! remove_userban(oban); ! userban_free(oban); ! userban_free(ban); ! ! if (MyClient(sptr)) ! sendto_one(sptr, ":%s NOTICE %s :G-line for [%s@%s] is removed", ! me.name, parv[0], user, host); ! sendto_ops("%s has removed the G-line for: [%s@%s] (%d matches)", ! parv[0], user, host, 1); ! sendto_serv_butone(cptr, ":%s UNGLINE %s@%s", sptr->name, user, host); ! return 0; ! } ! userban_free(ban); ! } ! if (MyClient(sptr)) ! sendto_one(sptr, ":%s NOTICE %s :No g-line for %s@%s was found", ! me.name, parv[0], user, host); ! return 0; ! } /* m_rehash */ --- 2697,2905 ---- /* Check local users against it */ ! ! userban_sweep(ban); ! ! host = get_userban_host(ban, fbuf, 512); ! ! if(temporary_gline_time) ! { ! sendto_realops("%s added temporary %d min. "NETWORK_GLINE_NAME" for" ! " [%s@%s] [%s]", parv[0], temporary_gline_time, user, ! host, reason); ! return 0; ! } ! ! /* from here on, we're dealing with a perm kline */ ! ! filename = configfile; ! ! sendto_one(sptr, ":%s NOTICE %s :Added G-Line [%s@%s] to server " ! "configfile", me.name, parv[0], user, host); ! ! sendto_realops("%s added G-Line for [%s@%s] [%s]", ! parv[0], user, host, reason); ! ! #if defined(LOCKFILE) ! if ((k = (struct pkl *) malloc(sizeof(struct pkl))) == NULL) { ! sendto_one(sptr, ":%s NOTICE %s :Problem allocating memory", ! me.name, parv[0]); ! return (0); ! } ! ircsprintf(buffer, "/* %s!%s@%s Added kill for: %s@%s\n" ! " * at %s */\n", ! sptr->name, sptr->user->username, ! sptr->user->host, user, host, current_date); ! if ((k->comment = strdup(buffer)) == NULL) ! { ! free(k); ! sendto_one(sptr, ":%s NOTICE %s :Problem allocating memory", ! me.name, parv[0]); ! return (0); } ! ircsprintf(buffer, "kill {\n" ! " mask \"%s@%s\";\n" ! " reason \"%s\";\n" ! "};\n\n", ! user, host, reason); ! if ((k->kline = strdup(buffer)) == NULL) ! { ! free(k->comment); ! free(k); ! sendto_one(sptr, ":%s NOTICE %s :Problem allocating memory", ! me.name, parv[0]); ! return (0); } + k->next = pending_glines; + pending_glines = k; ! do_pending_glines(); ! return (0); ! ! #else /* LOCKFILE - MDP */ ! ! if ((out = open(filename, O_RDWR | O_APPEND | O_CREAT)) == -1) ! { ! sendto_one(sptr, ":%s NOTICE %s :Problem opening %s ", ! me.name, parv[0], filename); ! return 0; ! } ! ! ircsprintf(buffer, "/* %s!%s@%s Added kill for: %s@%s\n" ! " * at %s */\n", ! sptr->name, sptr->user->username, ! sptr->user->host, user, host, current_date); ! ! if (write(out, buffer, strlen(buffer)) <= 0) ! { ! sendto_one(sptr, ":%s NOTICE %s :Problem writing to %s", ! me.name, parv[0], filename); ! close(out); ! return 0; ! } ! ! ircsprintf(buffer, "kill {\n" ! " mask \"%s@%s\";\n" ! " reason \"%s\";\n" ! "};\n\n", ! user, host, reason); ! ! if (write(out, buffer, strlen(buffer)) <= 0) ! { ! sendto_one(sptr, ":%s NOTICE %s :Problem writing to %s", ! me.name, parv[0], filename); ! close(out); ! return 0; ! } ! ! close(out); ! ! #ifdef USE_SYSLOG ! syslog(LOG_NOTICE, "%s added G-Line for [%s@%s] [%s]", parv[0], ! user, host, reason); ! #endif return 0; + #endif /* LOCKFILE */ } + #endif ! ! #if 0 ! /* ! * * m_ungline ! * Added Aug 31, 1997 ! * common (Keith Fralick) fr...@ga... ! * ! * parv[0] = sender ! * parv[1] = address to remove ! * ! * re-worked and cleanedup for use in hybrid-5 -Dianora ! * ! */ ! int m_ungline(aClient *cptr, aClient *sptr, int parc, char *parv[]) { struct userBan *ban; ! char *user, *host; ! ! if (!IsAnOper(sptr) || !OPCanUnGline(sptr)) { ! sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); ! return 0; } ! ! if (parc < 2) { ! sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), ! me.name, parv[0], "UNGLINE"); ! return 0; } ! if ((host = strchr(parv[1], '@')) || *parv[1] == '*') ! { ! /* Explicit user@host mask given */ ! ! if (host) /* Found user@host */ ! { ! user = parv[1]; /* here is user part */ ! *(host++) = '\0'; /* and now here is host */ ! } ! else ! { ! user = "*"; /* no @ found, assume its *@somehost */ ! host = parv[1]; ! } } ! else ! { ! sendto_one(sptr, ":%s NOTICE %s :Invalid parameters", ! me.name, parv[0]); ! return 0; ! } ! ! if ((user[0] == '*') && (user[1] == '\0') && (host[0] == '*') && ! (host[1] == '\0')) ! { ! sendto_one(sptr, ":%s NOTICE %s :Cannot UNG-Line everyone", ! me.name, parv[0]); ! return 0; } ban = make_hostbased_ban(user, host); ! if(ban) ! { ! struct userBan *oban; ! ban->flags |= (UBAN_GLINE|UBAN_TEMPORARY); ! if((oban = find_userban_exact(ban, UBAN_GLINE|UBAN_TEMPORARY))) ! { ! char tmp[512]; ! host = get_userban_host(oban, tmp, 512); + remove_userban(oban); + glinestore_remove(oban); + userban_free(oban); + userban_free(ban); + + sendto_one(sptr, ":%s NOTICE %s :G-Line for [%s@%s] is removed", + me.name, parv[0], user, host); + sendto_ops("%s has removed the G-Line for: [%s@%s] (%d matches)", + parv[0], user, host, 1); + return 0; + } + userban_free(ban); + } + sendto_one(sptr, ":%s NOTICE %s :No Gline matches [%s@%s]", + me.name, parv[0], user, host); + return 0; + } + #endif /* UNGLINE */ /* m_rehash */ Index: userban.c =================================================================== RCS file: /cvsroot/solidircd/solidircd-stable/src/userban.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** userban.c 4 Sep 2005 05:24:13 -0000 1.5 --- userban.c 4 Dec 2005 07:14:07 -0000 1.6 *************** *** 1619,1630 **** char *reason; char *btext; int clientonly = 1; int i; ! if (ban->flags & UBAN_NETWORK) ! btext = NETWORK_BANNED_NAME; ! else ! btext = LOCAL_BANNED_NAME; ! if (!(reason = ban->reason)) reason = "<no reason>"; --- 1619,1637 ---- char *reason; char *btext; + char *ntext; int clientonly = 1; int i; ! if (ban->flags & UBAN_NETWORK) ! { ! btext = NETWORK_BANNED_NAME; ! ntext = NETWORK_BAN_NAME; ! } ! else ! { ! btext = LOCAL_BANNED_NAME; ! ntext = LOCAL_BAN_NAME; ! } ! if (!(reason = ban->reason)) reason = "<no reason>"; *************** *** 1707,1710 **** --- 1714,1772 ---- } + /* gline.c */ + + + + /* + * gs_dumpklines() helper + */ + static void + gs_dumplist(int f, uBanEnt *be) + { + struct userBan *ub; + + /* glines.c */ + extern void gs_write(int, char, struct userBan *); + + for (; be; be = LIST_NEXT(be, lp)) + { + ub = be->ban; + + /* must be local and not from conf */ + if ((ub->flags & (UBAN_GLINE|UBAN_CONF)) != UBAN_GLINE) + continue; + + /* must be over the storage threshold duration */ + if ((ub->flags & UBAN_TEMPORARY) + && ub->duration < (GLINE_MIN_STORE_TIME * 60)) + continue; + + gs_write(f, '+', ub); + } + } + + /* + * Called from glines.c during a storage GC. + */ + void + gs_dumpglines(int f) + { + int i, j; + + for (i = 0; i < 256; i++) + for (j = 0; j < 256; j++) + gs_dumplist(f, LIST_FIRST(&CIDR4_bans[i][j])); + + gs_dumplist(f, LIST_FIRST(&CIDR4BIG_bans)); + gs_dumplist(f, LIST_FIRST(&host_bans.wild_list)); + gs_dumplist(f, LIST_FIRST(&ip_bans.wild_list)); + + for (i = 0; i < HASH_SIZE; i++) + { + gs_dumplist(f, LIST_FIRST(&host_bans.hash_list[i])); + gs_dumplist(f, LIST_FIRST(&ip_bans.hash_list[i])); + } + } + static void |