Committer : entrope
CVSROOT : /cvsroot/undernet-ircu
Module : ircu2.10
Branch tags: u2_10_12_branch
Commit time: 2007-10-30 01:53:44 UTC
Modified files:
Tag: u2_10_12_branch
ircd/whocmds.c ircd/gline.c include/whocmds.h include/gline.h
ChangeLog
Log message:
Require force for many-victim realname G-lines; clean up gline.c.
---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.710.2.208 ircu2.10/ChangeLog:1.710.2.209
--- ircu2.10/ChangeLog:1.710.2.208 Mon Oct 29 18:19:52 2007
+++ ircu2.10/ChangeLog Mon Oct 29 18:53:33 2007
@@ -1,3 +1,22 @@
+2007-10-29 Michael Poole <[EMAIL PROTECTED]>
+
+ * include/gline.h: Delete declaration of gline_propagate().
+
+ * include/whocmds.h: Delete declaration of count_users().
+
+ * ircd/whocmds.c (count_users): Move to gline.c as a static.
+
+ * ircd/gline.c (whocmds.h): Remove #include.
+ (gliter): Document boolean trickiness. Add missing trickiness
+ when gl_flags has bits set besides GLINE_ACTIVE.
+ (make_gline): Get rid of now-unused "after" variable and the
+ comments related to overlapping G-lines.
+ (gline_propagate): Make static.
+ (count_users): Move from whocmds.c as a static function.
+ (count_realnames): New function.
+ (gline_add): Require a force to hit lots of users with a realname
+ G-line.
+
2007-09-05 Michael Poole <[EMAIL PROTECTED]>
* ircd/m_gline.c (ms_gline): Remove dead branch when 4 < parc < 5.
Index: ircu2.10/include/gline.h
diff -u ircu2.10/include/gline.h:1.17.2.2 ircu2.10/include/gline.h:1.17.2.3
--- ircu2.10/include/gline.h:1.17.2.2 Sat Mar 17 15:45:35 2007
+++ ircu2.10/include/gline.h Mon Oct 29 18:53:33 2007
@@ -22,7 +22,7 @@
*/
/** @file
* @brief Structures and APIs for G-line manipulation.
- * @version $Id: gline.h,v 1.17.2.2 2007/03/17 22:45:35 klmitch Exp $
+ * @version $Id: gline.h,v 1.17.2.3 2007/10/30 01:53:33 entrope Exp $
*/
#ifndef INCLUDED_sys_types_h
#include <sys/types.h>
@@ -119,8 +119,6 @@
/** Return last modification time of a G-line. */
#define GlineLastMod(g) ((g)->gl_lastmod)
-extern int gline_propagate(struct Client *cptr, struct Client *sptr,
- struct Gline *gline);
extern int gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
char *reason, time_t expire, time_t lastmod,
time_t lifetime, unsigned int flags);
Index: ircu2.10/include/whocmds.h
diff -u ircu2.10/include/whocmds.h:1.10.2.1 ircu2.10/include/whocmds.h:1.10.2.2
--- ircu2.10/include/whocmds.h:1.10.2.1 Sat Nov 4 13:35:28 2006
+++ ircu2.10/include/whocmds.h Mon Oct 29 18:53:33 2007
@@ -1,6 +1,6 @@
/** @file whocmds.h
* @brief Support functions for /WHO-like commands.
- * @version $Id: whocmds.h,v 1.10.2.1 2006/11/04 21:35:28 entrope Exp $
+ * @version $Id: whocmds.h,v 1.10.2.2 2007/10/30 01:53:33 entrope Exp $
*/
#ifndef INCLUDED_whocmds_h
#define INCLUDED_whocmds_h
@@ -88,6 +88,5 @@
*/
extern void do_who(struct Client* sptr, struct Client* acptr, struct Channel*
repchan,
int fields, char* qrt);
-extern int count_users(char* mask);
#endif /* INCLUDED_whocmds_h */
Index: ircu2.10/ircd/gline.c
diff -u ircu2.10/ircd/gline.c:1.61.2.4 ircu2.10/ircd/gline.c:1.61.2.5
--- ircu2.10/ircd/gline.c:1.61.2.4 Fri Jul 20 16:32:19 2007
+++ ircu2.10/ircd/gline.c Mon Oct 29 18:53:33 2007
@@ -19,7 +19,7 @@
*/
/** @file
* @brief Implementation of Gline manipulation functions.
- * @version $Id: gline.c,v 1.61.2.4 2007/07/20 23:32:19 klmitch Exp $
+ * @version $Id: gline.c,v 1.61.2.5 2007/10/30 01:53:33 entrope Exp $
*/
#include "config.h"
@@ -44,7 +44,6 @@
#include "msg.h"
#include "numnicks.h"
#include "numeric.h"
-#include "whocmds.h"
/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <string.h>
@@ -77,6 +76,10 @@
* @param[in] gl Name of a struct Gline pointer variable that will be made to
point to the G-lines in sequence.
* @param[in] next Name of a scratch struct Gline pointer variable.
*/
+/* There is some subtlety here with the boolean operators:
+ * (x || 1) is used to continue in a logical-and series even when !x.
+ * (x && 0) is used to continue in a logical-or series even when x.
+ */
#define gliter(list, gl, next) \
/* Iterate through the G-lines in the list */ \
for ((gl) = (list); (gl); (gl) = (next)) \
@@ -87,8 +90,8 @@
/* Record has expired, so free the G-line */ \
gline_free((gl)); \
/* See if we need to expire the G-line */ \
- else if (((gl)->gl_expire > CurrentTime || \
- ((gl)->gl_flags &= ~GLINE_ACTIVE) || \
+ else if ((((gl)->gl_expire > CurrentTime) || \
+ (((gl)->gl_flags &= ~GLINE_ACTIVE) && 0) || \
((gl)->gl_state = GLOCAL_GLOBAL)) && 0) \
; /* empty statement */ \
else
@@ -137,37 +140,7 @@
make_gline(char *user, char *host, char *reason, time_t expire, time_t lastmod,
time_t lifetime, unsigned int flags)
{
- struct Gline *gline, *after = 0;
-
- /* Disable checking for overlapping G-lines. The problem is that we
- * may have a wide-mask, long lifetime G-line that we've
- * deactivated--maybe it was a mistake?--and someone comes along and
- * wants to set a narrower overlapping G-line with a shorter
- * lifetime. If we were to leave this logic enabled, there would be
- * no way to set that narrower G-line.
- */
-/* if (!(flags & GLINE_BADCHAN)) { /\* search for overlapping glines first
*\/ */
-
-/* for (gline = GlobalGlineList; gline; gline = sgline) { */
-/* sgline = gline->gl_next; */
-
-/* if (gline->gl_expire <= CurrentTime) */
-/* gline_free(gline); */
-/* else if (((gline->gl_flags & GLINE_LOCAL) != (flags & GLINE_LOCAL))
|| */
-/* (gline->gl_host && !host) || (!gline->gl_host && host)) */
-/* continue; */
-/* else if (!mmatch(gline->gl_user, user) /\* gline contains new mask
*\/ */
-/* && (gline->gl_host == NULL || !mmatch(gline->gl_host, host))) {
*/
-/* if (expire <= gline->gl_expire) /\* will expire before wider gline *\/
*/
-/* return 0; */
-/* else */
-/* after = gline; /\* stick new gline after this one *\/ */
-/* } else if (!mmatch(user, gline->gl_user) /\* new mask contains gline
*\/ */
-/* && (gline->gl_host==NULL || !mmatch(host, gline->gl_host)) */
-/* && gline->gl_expire <= expire) /\* old expires before new *\/
*/
-/* gline_free(gline); /\* save some memory *\/ */
-/* } */
-/* } */
+ struct Gline *gline;
gline = (struct Gline *)MyMalloc(sizeof(struct Gline)); /* alloc memory */
assert(0 != gline);
@@ -181,7 +154,7 @@
if (flags & GLINE_BADCHAN) { /* set a BADCHAN gline */
DupString(gline->gl_user, user); /* first, remember channel */
- gline->gl_host = 0;
+ gline->gl_host = NULL;
gline->gl_next = BadChanGlineList; /* then link it into list */
gline->gl_prev_p = &BadChanGlineList;
@@ -198,19 +171,11 @@
if (*user != '$' && ipmask_parse(host, &gline->gl_addr, &gline->gl_bits))
gline->gl_flags |= GLINE_IPMASK;
- if (after) {
- gline->gl_next = after->gl_next;
- gline->gl_prev_p = &after->gl_next;
- if (after->gl_next)
- after->gl_next->gl_prev_p = &gline->gl_next;
- after->gl_next = gline;
- } else {
- gline->gl_next = GlobalGlineList; /* then link it into list */
- gline->gl_prev_p = &GlobalGlineList;
- if (GlobalGlineList)
- GlobalGlineList->gl_prev_p = &gline->gl_next;
- GlobalGlineList = gline;
- }
+ gline->gl_next = GlobalGlineList; /* then link it into list */
+ gline->gl_prev_p = &GlobalGlineList;
+ if (GlobalGlineList)
+ GlobalGlineList->gl_prev_p = &gline->gl_next;
+ GlobalGlineList = gline;
}
return gline;
@@ -362,7 +327,7 @@
* @param[in] gline G-line to forward.
* @return Zero.
*/
-int
+static int
gline_propagate(struct Client *cptr, struct Client *sptr, struct Gline *gline)
{
if (GlineIsLocal(gline))
@@ -380,6 +345,59 @@
return 0;
}
+/** Count number of users who match \a mask.
+ * @param[in] mask [EMAIL PROTECTED] or [EMAIL PROTECTED] mask to check.
+ * @return Count of matching users.
+ */
+static int
+count_users(char *mask)
+{
+ struct Client *acptr;
+ int count = 0;
+ char namebuf[USERLEN + HOSTLEN + 2];
+ char ipbuf[USERLEN + SOCKIPLEN + 2];
+
+ for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
+ if (!IsUser(acptr))
+ continue;
+
+ ircd_snprintf(0, namebuf, sizeof(namebuf), "[EMAIL PROTECTED]",
+ cli_user(acptr)->username, cli_user(acptr)->host);
+ ircd_snprintf(0, ipbuf, sizeof(ipbuf), "[EMAIL PROTECTED]",
cli_user(acptr)->username,
+ ircd_ntoa(&cli_ip(acptr)));
+
+ if (!match(mask, namebuf) || !match(mask, ipbuf))
+ count++;
+ }
+
+ return count;
+}
+
+/** Count number of users with a realname matching \a mask.
+ * @param[in] mask Wildcard mask to match against realnames.
+ * @return Count of matching users.
+ */
+static int
+count_realnames(const char *mask)
+{
+ struct Client *acptr;
+ int minlen;
+ int count;
+ char cmask[BUFSIZE];
+
+ count = 0;
+ matchcomp(cmask, &minlen, NULL, mask);
+ for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
+ if (!IsUser(acptr))
+ continue;
+ if (strlen(cli_info(acptr)) < minlen)
+ continue;
+ if (!matchexec(cli_info(acptr), cmask, minlen))
+ count++;
+ }
+ return count;
+}
+
/** Create a new G-line and add it to global lists.
* \a userhost may be in one of four forms:
* \li A channel name, to add a BadChan.
@@ -420,7 +438,7 @@
flags |= GLINE_BADCHAN;
user = userhost;
- host = 0;
+ host = NULL;
} else if (*userhost == '$') {
switch (userhost[1]) {
case 'R': flags |= GLINE_REALNAME; break;
@@ -430,14 +448,15 @@
-- hikari */
if (IsServer(cptr))
return protocol_violation(sptr,"%s has been smoking the sweet leaf
and sent me a whacky gline",cli_name(sptr));
- else {
- sendto_opmask_butone(NULL, SNO_GLINE, "%s has been smoking the sweet
leaf and sent me a whacky gline", cli_name(sptr));
- return 0;
- }
- break;
+ sendto_opmask_butone(NULL, SNO_GLINE, "%s has been smoking the sweet
leaf and sent me a whacky gline", cli_name(sptr));
+ return 0;
}
- user = userhost;
- host = 0;
+ user = userhost;
+ host = NULL;
+ tmp = count_realnames(userhost + 2);
+ if ((tmp >= feature_int(FEAT_GLINEMAXUSERCOUNT))
+ && !(flags & GLINE_OPERFORCE))
+ return send_reply(sptr, ERR_TOOMANYUSERS, tmp);
} else {
canon_userhost(userhost, &user, &host, "*");
if (sizeof(uhmask) <
@@ -505,8 +524,6 @@
* never be NULL...
*/
assert(agline);
-/* if (!agline) /\* if it overlapped, silently return *\/ */
-/* return 0; */
gline_propagate(cptr, sptr, agline);
Index: ircu2.10/ircd/whocmds.c
diff -u ircu2.10/ircd/whocmds.c:1.25.2.2 ircu2.10/ircd/whocmds.c:1.25.2.3
--- ircu2.10/ircd/whocmds.c:1.25.2.2 Sun Mar 4 06:55:31 2007
+++ ircu2.10/ircd/whocmds.c Mon Oct 29 18:53:33 2007
@@ -22,7 +22,7 @@
*/
/** @file
* @brief Support functions for /WHO-like commands.
- * @version $Id: whocmds.c,v 1.25.2.2 2007/03/04 14:55:31 entrope Exp $
+ * @version $Id: whocmds.c,v 1.25.2.3 2007/10/30 01:53:33 entrope Exp $
*/
#include "config.h"
@@ -276,31 +276,3 @@
p1 = buf1;
send_reply(sptr, fields ? RPL_WHOSPCRPL : RPL_WHOREPLY, ++p1);
}
-
-/** Count number of users who match \a mask.
- * @param[in] mask [EMAIL PROTECTED] or [EMAIL PROTECTED] mask to check.
- * @return Count of matching users.
- */
-int
-count_users(char *mask)
-{
- struct Client *acptr;
- int count = 0;
- char namebuf[USERLEN + HOSTLEN + 2];
- char ipbuf[USERLEN + SOCKIPLEN + 2];
-
- for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
- if (!IsUser(acptr))
- continue;
-
- ircd_snprintf(0, namebuf, sizeof(namebuf), "[EMAIL PROTECTED]",
- cli_user(acptr)->username, cli_user(acptr)->host);
- ircd_snprintf(0, ipbuf, sizeof(ipbuf), "[EMAIL PROTECTED]",
cli_user(acptr)->username,
- ircd_ntoa(&cli_ip(acptr)));
-
- if (!match(mask, namebuf) || !match(mask, ipbuf))
- count++;
- }
-
- return count;
-}
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches