2 # Parent 1ce0d004b836adf870a8c93691bf89c67369ba0f
4 diff -r 1ce0d004b836 include/gline.h
5 --- a/include/gline.h Tue Jul 16 22:24:30 2013 +0100
6 +++ b/include/gline.h Tue Jul 16 22:31:38 2013 +0100
9 struct Gline *gl_next; /**< Next G-line in linked list. */
10 struct Gline**gl_prev_p; /**< Previous pointer to this G-line. */
11 + char *gl_nick; /**< Nickname mask. */
12 char *gl_user; /**< Username mask (or channel/realname mask). */
13 char *gl_host; /**< Host portion of mask. */
14 char *gl_reason; /**< Reason for G-line. */
16 /** Test whether \a g is local to this server. */
17 #define GlineIsLocal(g) ((g)->gl_flags & GLINE_LOCAL)
19 +/** Return nick mask of a G-line. */
20 +#define GlineNick(g) ((g)->gl_nick)
21 /** Return user mask of a G-line. */
22 #define GlineUser(g) ((g)->gl_user)
23 /** Return host mask of a G-line. */
25 extern void gline_stats(struct Client *sptr, const struct StatDesc *sd,
27 extern int gline_memory_count(size_t *gl_size);
28 +extern struct Gline *IsNickGlined(struct Client *cptr, char *nick);
30 #endif /* INCLUDED_gline_h */
31 diff -r 1ce0d004b836 ircd/gline.c
32 --- a/ircd/gline.c Tue Jul 16 22:24:30 2013 +0100
33 +++ b/ircd/gline.c Tue Jul 16 22:31:38 2013 +0100
40 #include "ircd_alloc.h"
41 #include "ircd_features.h"
48 /* #include <assert.h> -- Now using assert in ircd_log.h */
51 * Otherwise, assign \a def_user to *user_p and \a userhost to *host_p.
53 * @param[in] userhost Input string from user.
54 + * @param[out] nick_p Gets pointer to nick part of hostmask.
55 * @param[out] user_p Gets pointer to user (or channel/realname) part of hostmask.
56 * @param[out] host_p Gets point to host part of hostmask (may be assigned NULL).
57 * @param[in] def_user Default value for user part.
60 -canon_userhost(char *userhost, char **user_p, char **host_p, char *def_user)
61 +canon_userhost(char *userhost, char **nick_p, char **user_p, char **host_p, char *def_user)
66 if (*userhost == '$') {
73 - if (!(tmp = strchr(userhost, '@'))) {
74 + if ((tmp = strchr(userhost, '!'))) {
82 + if (!(s = strchr(tmp, '@'))) {
96 /** Create a Gline structure.
97 + * @param[in] nick Nick part of mask.
98 * @param[in] user User part of mask.
99 * @param[in] host Host part of mask (NULL if not applicable).
100 * @param[in] reason Reason for G-line.
102 * @return Newly allocated G-line.
104 static struct Gline *
105 -make_gline(char *user, char *host, char *reason, time_t expire, time_t lastmod,
106 +make_gline(char *nick, char *user, char *host, char *reason, time_t expire, time_t lastmod,
107 time_t lifetime, unsigned int flags)
111 BadChanGlineList->gl_prev_p = &gline->gl_next;
112 BadChanGlineList = gline;
114 - DupString(gline->gl_user, user); /* remember them... */
116 + DupString(gline->gl_nick, nick); /* remember them... */
118 + gline->gl_nick = 0;
119 + DupString(gline->gl_user, user);
121 DupString(gline->gl_host, host);
125 Debug((DEBUG_DEBUG,"Matched!"));
126 } else { /* Host/IP gline */
127 + if (cli_name(acptr) &&
128 + match(gline->gl_nick, cli_name(acptr)) !=0)
131 if (cli_user(acptr)->username &&
132 match(gline->gl_user, (cli_user(acptr))->realusername) != 0)
136 assert(gline->gl_lastmod);
138 - sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu %Tu :%s",
139 - GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
140 + sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s%s%s %Tu %Tu %Tu :%s",
141 + GlineIsRemActive(gline) ? '+' : '-',
142 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
143 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
145 gline->gl_host ? "@" : "",
146 gline->gl_host ? gline->gl_host : "",
147 gline->gl_expire - TStime(), gline->gl_lastmod,
151 struct Gline *agline;
152 - char uhmask[USERLEN + HOSTLEN + 2];
154 + char uhmask[NICKLEN + USERLEN + HOSTLEN + 3];
155 + char *nick, *user, *host;
158 assert(0 != userhost);
160 return send_reply(sptr, ERR_TOOMANYUSERS, tmp);
163 - canon_userhost(userhost, &user, &host, "*");
164 + canon_userhost(userhost, &nick, &user, &host, "*");
166 ircd_snprintf(0, uhmask, sizeof(uhmask), "%s@%s", user, host))
167 return send_reply(sptr, ERR_LONGMASK);
168 @@ -537,29 +559,35 @@
171 sendto_opmask_butone(0, ircd_strncmp(reason, "AUTO", 4) ? SNO_GLINE :
172 - SNO_AUTO, "%s adding %s%s %s for %s%s%s, expiring at "
173 + SNO_AUTO, "%s adding %s%s %s for %s%s%s%s%s, expiring at "
175 (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
177 cli_name((cli_user(sptr))->server),
178 (flags & GLINE_ACTIVE) ? "" : "deactivated ",
179 (flags & GLINE_LOCAL) ? "local" : "global",
180 - (flags & GLINE_BADCHAN) ? "BADCHAN" : "GLINE", user,
181 + (flags & GLINE_BADCHAN) ? "BADCHAN" : "GLINE",
182 + (flags & (GLINE_BADCHAN|GLINE_REALNAME)) ? "" : nick,
183 + (flags & (GLINE_BADCHAN|GLINE_REALNAME)) ? "" : "!",
185 (flags & (GLINE_BADCHAN|GLINE_REALNAME)) ? "" : "@",
186 (flags & (GLINE_BADCHAN|GLINE_REALNAME)) ? "" : host,
190 log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
191 - "%#C adding %s %s for %s%s%s, expiring at %Tu: %s", sptr,
192 + "%#C adding %s %s for %s%s%s%s%s, expiring at %Tu: %s", sptr,
193 flags & GLINE_LOCAL ? "local" : "global",
194 - flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", user,
195 + flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE",
196 + flags & (GLINE_BADCHAN|GLINE_REALNAME) ? "" : nick,
197 + flags & (GLINE_BADCHAN|GLINE_REALNAME) ? "" : "!",
199 flags & (GLINE_BADCHAN|GLINE_REALNAME) ? "" : "@",
200 flags & (GLINE_BADCHAN|GLINE_REALNAME) ? "" : host,
204 - agline = make_gline(user, host, reason, expire, lastmod, lifetime, flags);
205 + agline = make_gline(nick, user, host, reason, expire, lastmod, lifetime, flags);
207 /* since we've disabled overlapped G-line checking, agline should
209 @@ -606,19 +634,24 @@
210 return 0; /* was active to begin with */
212 /* Inform ops and log it */
213 - sendto_opmask_butone(0, SNO_GLINE, "%s activating global %s for %s%s%s, "
214 + sendto_opmask_butone(0, SNO_GLINE, "%s activating global %s for %s%s%s%s%s, "
215 "expiring at %Tu: %s",
216 (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
218 cli_name((cli_user(sptr))->server),
219 GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
220 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
221 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
222 gline->gl_user, gline->gl_host ? "@" : "",
223 gline->gl_host ? gline->gl_host : "",
224 gline->gl_expire, gline->gl_reason);
226 log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
227 - "%#C activating global %s for %s%s%s, expiring at %Tu: %s", sptr,
228 - GlineIsBadChan(gline) ? "BADCHAN" : "GLINE", gline->gl_user,
229 + "%#C activating global %s for %s%s%s%s%s, expiring at %Tu: %s", sptr,
230 + GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
231 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
232 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
234 gline->gl_host ? "@" : "",
235 gline->gl_host ? gline->gl_host : "",
236 gline->gl_expire, gline->gl_reason);
237 @@ -674,19 +707,24 @@
240 /* Inform ops and log it */
241 - sendto_opmask_butone(0, SNO_GLINE, "%s %s %s for %s%s%s, expiring at %Tu: "
242 + sendto_opmask_butone(0, SNO_GLINE, "%s %s %s for %s%s%s%s%s, expiring at %Tu: "
244 (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
246 cli_name((cli_user(sptr))->server),
247 msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
248 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
249 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
250 gline->gl_user, gline->gl_host ? "@" : "",
251 gline->gl_host ? gline->gl_host : "",
252 gline->gl_expire, gline->gl_reason);
254 log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
255 - "%#C %s %s for %s%s%s, expiring at %Tu: %s", sptr, msg,
256 - GlineIsBadChan(gline) ? "BADCHAN" : "GLINE", gline->gl_user,
257 + "%#C %s %s for %s%s%s%s%s, expiring at %Tu: %s", sptr, msg,
258 + GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
259 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
260 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
262 gline->gl_host ? "@" : "",
263 gline->gl_host ? gline->gl_host : "",
264 gline->gl_expire, gline->gl_reason);
267 assert(!GlineIsLocal(gline));
269 - Debug((DEBUG_DEBUG, "gline_modify(\"%s\", \"%s\", \"%s%s%s\", %s, \"%s\", "
270 + Debug((DEBUG_DEBUG, "gline_modify(\"%s\", \"%s\", \"%s%s%s%s%s\", %s, \"%s\", "
271 "%Tu, %Tu, %Tu, 0x%04x)", cli_name(cptr), cli_name(sptr),
272 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
273 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
274 gline->gl_user, gline->gl_host ? "@" : "",
275 gline->gl_host ? gline->gl_host : "",
276 action == GLINE_ACTIVATE ? "GLINE_ACTIVATE" :
277 @@ -872,10 +912,12 @@
280 /* All right, inform ops... */
281 - sendto_opmask_butone(0, SNO_GLINE, "%s modifying global %s for %s%s%s:%s",
282 + sendto_opmask_butone(0, SNO_GLINE, "%s modifying global %s for %s%s%s%s%s:%s",
283 (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
284 cli_name(sptr) : cli_name((cli_user(sptr))->server),
285 GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
286 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
287 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
288 gline->gl_user, gline->gl_host ? "@" : "",
289 gline->gl_host ? gline->gl_host : "", buf);
293 if (action != GLINE_LOCAL_ACTIVATE && action != GLINE_LOCAL_DEACTIVATE)
294 sendcmdto_serv_butone(sptr, CMD_GLINE, cptr,
295 - "* %s%s%s%s%s %Tu %Tu %Tu :%s",
296 + "* %s%s%s%s%s%s%s %Tu %Tu %Tu :%s",
297 flags & GLINE_OPERFORCE ? "!" : "", op,
298 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
299 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
300 gline->gl_user, gline->gl_host ? "@" : "",
301 gline->gl_host ? gline->gl_host : "",
302 gline->gl_expire - TStime(), gline->gl_lastmod,
303 @@ -915,15 +959,20 @@
304 assert(GlineIsLocal(gline));
306 /* Inform ops and log it */
307 - sendto_opmask_butone(0, SNO_GLINE, "%s removing local %s for %s%s%s",
308 + sendto_opmask_butone(0, SNO_GLINE, "%s removing local %s for %s%s%s%s%s",
309 (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
310 cli_name(sptr) : cli_name((cli_user(sptr))->server),
311 GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
312 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
313 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
314 gline->gl_user, gline->gl_host ? "@" : "",
315 gline->gl_host ? gline->gl_host : "");
316 log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
317 - "%#C removing local %s for %s%s%s", sptr,
318 - GlineIsBadChan(gline) ? "BADCHAN" : "GLINE", gline->gl_user,
319 + "%#C removing local %s for %s%s%s%s%s", sptr,
320 + GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
321 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
322 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
324 gline->gl_host ? "@" : "", gline->gl_host ? gline->gl_host : "");
326 gline_free(gline); /* get rid of the G-line */
329 struct Gline *gline = 0;
330 struct Gline *sgline;
331 - char *user, *host, *t_uh;
332 + char *nick, *user, *host, *t_uh;
334 if (flags & (GLINE_BADCHAN | GLINE_ANY)) {
335 gliter(BadChanGlineList, gline, sgline) {
339 DupString(t_uh, userhost);
340 - canon_userhost(t_uh, &user, &host, "*");
341 + canon_userhost(t_uh, &nick, &user, &host, "*");
343 gliter(GlobalGlineList, gline, sgline) {
344 if ((flags & (GlineIsLocal(gline) ? GLINE_GLOBAL : GLINE_LOCAL)) ||
345 @@ -978,12 +1027,18 @@
346 else if (flags & GLINE_EXACT) {
347 if (((gline->gl_host && host && ircd_strcmp(gline->gl_host, host) == 0)
348 || (!gline->gl_host && !host)) &&
349 - (ircd_strcmp(gline->gl_user, user) == 0))
350 + ((!user && ircd_strcmp(gline->gl_user, "*") == 0) ||
351 + (user && ircd_strcmp(gline->gl_user, user) == 0)) &&
352 + ((!nick && gline->gl_nick && ircd_strcmp(gline->gl_nick, "*") == 0) ||
353 + (nick && gline->gl_nick && ircd_strcmp(gline->gl_nick, nick) == 0) || (!gline->gl_nick && !nick)))
356 if (((gline->gl_host && host && match(gline->gl_host, host) == 0)
357 || (!gline->gl_host && !host)) &&
358 - (match(gline->gl_user, user) == 0))
359 + ((!user && ircd_strcmp(gline->gl_user, "*") == 0) ||
360 + (user && match(gline->gl_user, user) == 0)) &&
361 + ((!nick && gline->gl_nick && ircd_strcmp(gline->gl_nick, "*") == 0) ||
362 + (nick && gline->gl_nick && (match(gline->gl_nick, nick) == 0)) || (!gline->gl_nick && !nick)))
366 @@ -1039,7 +1094,9 @@
370 - if (match(gline->gl_user, (cli_user(cptr))->username) != 0)
371 + if (match(gline->gl_nick, cli_name(cptr)) != 0)
373 + if (match(gline->gl_user, (cli_user(cptr))->realusername) != 0)
376 if (GlineIsIpMask(gline)) {
377 @@ -1090,8 +1147,11 @@
379 gliter(GlobalGlineList, gline, sgline) {
380 if (!GlineIsLocal(gline) && gline->gl_lastmod)
381 - sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu %Tu :%s",
382 - GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
383 + sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s%s%s %Tu %Tu %Tu :%s",
384 + GlineIsRemActive(gline) ? '+' : '-',
385 + gline->gl_nick ? gline->gl_nick : "",
386 + gline->gl_nick ? "!" : "",
388 gline->gl_host ? "@" : "",
389 gline->gl_host ? gline->gl_host : "",
390 gline->gl_expire - TStime(), gline->gl_lastmod,
391 @@ -1118,8 +1178,11 @@
392 if (GlineIsLocal(gline) || !gline->gl_lastmod)
395 - sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu %Tu :%s",
396 - GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
397 + sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s%s%s %Tu %Tu %Tu :%s",
398 + GlineIsRemActive(gline) ? '+' : '-',
399 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : gline->gl_nick,
400 + GlineIsBadChan(gline)|GlineIsRealName(gline) ? "" : "!",
402 gline->gl_host ? "@" : "",
403 gline->gl_host ? gline->gl_host : "",
404 gline->gl_expire - TStime(), gline->gl_lastmod,
405 @@ -1146,8 +1209,10 @@
406 return send_reply(sptr, ERR_NOSUCHGLINE, userhost);
408 /* send gline information along */
409 - send_reply(sptr, RPL_GLIST, gline->gl_user,
410 - gline->gl_host ? "@" : "",
411 + send_reply(sptr, RPL_GLIST,
412 + GlineIsBadChan(gline) | GlineIsRealName(gline) ? "" : gline->gl_nick,
413 + GlineIsBadChan(gline) | GlineIsRealName(gline) ? "" : "!",
414 + gline->gl_user, GlineIsBadChan(gline) || GlineIsRealName(gline) ? "" : "@",
415 gline->gl_host ? gline->gl_host : "",
416 gline->gl_expire, gline->gl_lastmod,
418 @@ -1157,7 +1222,10 @@
419 GlineIsRemActive(gline) ? '+' : '-', gline->gl_reason);
421 gliter(GlobalGlineList, gline, sgline) {
422 - send_reply(sptr, RPL_GLIST, gline->gl_user,
423 + send_reply(sptr, RPL_GLIST,
424 + gline->gl_nick ? gline->gl_nick : "",
425 + gline->gl_nick ? "!" : "",
427 gline->gl_host ? "@" : "",
428 gline->gl_host ? gline->gl_host : "",
429 gline->gl_expire, gline->gl_lastmod,
430 @@ -1169,7 +1237,7 @@
433 gliter(BadChanGlineList, gline, sgline) {
434 - send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
435 + send_reply(sptr, RPL_GLIST, gline->gl_user, "", "", "", "",
436 gline->gl_expire, gline->gl_lastmod,
438 GlineIsLocal(gline) ? cli_name(&me) : "*",
439 @@ -1196,7 +1264,10 @@
440 struct Gline *sgline;
442 gliter(GlobalGlineList, gline, sgline) {
443 - send_reply(sptr, RPL_STATSGLINE, 'G', gline->gl_user,
444 + send_reply(sptr, RPL_STATSGLINE, 'G',
445 + gline->gl_nick ? gline->gl_nick : "",
446 + gline->gl_nick ? "!" : "",
448 gline->gl_host ? "@" : "",
449 gline->gl_host ? gline->gl_host : "",
450 gline->gl_expire, gline->gl_lastmod,
451 @@ -1231,6 +1302,7 @@
452 for (gline = GlobalGlineList; gline; gline = gline->gl_next) {
454 *gl_size += sizeof(struct Gline);
455 + *gl_size += gline->gl_nick ? (strlen(gline->gl_nick) +1) : 0;
456 *gl_size += gline->gl_user ? (strlen(gline->gl_user) + 1) : 0;
457 *gl_size += gline->gl_host ? (strlen(gline->gl_host) + 1) : 0;
458 *gl_size += gline->gl_reason ? (strlen(gline->gl_reason) + 1) : 0;
459 @@ -1246,3 +1318,46 @@
465 +IsNickGlined(struct Client *cptr, char *nick)
467 + struct Gline *gline;
468 + struct Gline *sgline;
470 + for (gline = GlobalGlineList; gline; gline = sgline) {
471 + sgline = gline->gl_next;
473 + if (gline->gl_expire <= CurrentTime) {
478 + if (GlineIsRealName(gline)) /* skip realname glines */
481 + if (!ircd_strcmp(gline->gl_nick, "*")) /* skip glines w. wildcarded nick */
484 + if (match(gline->gl_nick, nick) != 0)
487 + if (match(gline->gl_user, (cli_user(cptr))->username) != 0)
490 + if (GlineIsIpMask(gline)) {
491 + if (!ipmask_check(&(cli_ip(cptr)), &gline->gl_addr, gline->gl_bits))
495 + if (match(gline->gl_host, (cli_user(cptr))->realhost) != 0)
501 + * No Glines matched
506 diff -r 1ce0d004b836 ircd/m_nick.c
507 --- a/ircd/m_nick.c Tue Jul 16 22:24:30 2013 +0100
508 +++ b/ircd/m_nick.c Tue Jul 16 22:31:38 2013 +0100
515 /* #include <assert.h> -- Now using assert in ircd_log.h */
521 + if (IsRegistered(sptr) && !IsAnOper(sptr) && IsNickGlined(sptr, nick)) {
522 + send_reply(sptr, ERR_ERRONEUSNICKNAME, nick);
527 * Check if this is a LOCAL user trying to use a reserved (Juped)
528 * nick, if so tell him that it's a nick in use...
529 diff -r 1ce0d004b836 ircd/s_err.c
530 --- a/ircd/s_err.c Tue Jul 16 22:24:30 2013 +0100
531 +++ b/ircd/s_err.c Tue Jul 16 22:31:38 2013 +0100
534 { RPL_STATSTLINE, "%c %s %s", "246" },
536 - { RPL_STATSGLINE, "%c %s%s%s %Tu %Tu %Tu %s%c :%s", "247" },
537 + { RPL_STATSGLINE, "%c %s%s%s%s%s %Tu %Tu %Tu %s%c :%s", "247" },
539 { RPL_STATSULINE, "U %s", "248" },
545 - { RPL_GLIST, "%s%s%s %Tu %Tu %Tu %s %s%c :%s", "280" },
546 + { RPL_GLIST, "%s%s%s%s%s %Tu %Tu %Tu %s %s%c :%s", "280" },
548 { RPL_ENDOFGLIST, ":End of G-line List", "281" },