]>
jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_buf.c
1a867d3d5db138589e265e6e13e4f5fc9e8b2576
3 #include "../lib/irc_string.h"
4 #include "../irc/irc.h"
5 #include "../control/control.h"
6 #include "../trusts/trusts.h"
9 void glinebufinit(glinebuf
*gbuf
, int merge
) {
14 gline
*glinebufadd(glinebuf
*gbuf
, const char *mask
, const char *creator
, const char *reason
, time_t expire
, time_t lastmod
, time_t lifetime
) {
15 gline
*gl
, *sgl
, **pnext
;
17 gl
= makegline(mask
); /* sets up nick,user,host,node and flags */
20 /* couldn't process gline mask */
21 Error("gline", ERR_WARNING
, "Tried to add malformed G-Line %s!", mask
);
26 /* Check if an existing gline supercedes this mask */
27 for (sgl
= gbuf
->head
; sgl
; sgl
= sgl
->next
) {
28 if (gline_match_mask(sgl
, gl
)) {
34 /* Remove older glines this gline matches */
35 for (pnext
= &gbuf
->head
; *pnext
; pnext
= &((*pnext
)->next
)) {
38 if (gline_match_mask(gl
, sgl
)) {
48 gl
->creator
= getsstring(creator
, 255);
50 /* it's not unreasonable to assume gline is active, if we're adding a deactivated gline, we can remove this later */
51 gl
->flags
|= GLINE_ACTIVE
;
53 gl
->reason
= getsstring(reason
, 255);
55 gl
->lastmod
= lastmod
;
56 gl
->lifetime
= lifetime
;
58 gl
->next
= gbuf
->head
;
64 void glinebufaddbyip(glinebuf
*gbuf
, const char *user
, struct irc_in_addr
*ip
, unsigned char bits
, int flags
, const char *creator
, const char *reason
, time_t expire
, time_t lastmod
, time_t lifetime
) {
67 unsigned char nodebits
;
69 nodebits
= getnodebits(ip
);
71 if (!(flags
& GLINE_IGNORE_TRUST
)) {
72 th
= th_getbyhost(ip
);
74 if (th
&& (th
->group
->flags
& TRUST_RELIABLE_USERNAME
)) { /* Trust with reliable usernames */
75 for (oth
= th
->group
->hosts
; oth
; oth
= oth
->next
)
76 glinebufaddbyip(gbuf
, user
, &oth
->ip
, oth
->bits
, flags
| GLINE_ALWAYS_USER
| GLINE_IGNORE_TRUST
, creator
, reason
, expire
, lastmod
, lifetime
);
82 if (!(flags
& GLINE_ALWAYS_USER
))
85 /* Widen gline to match the node mask. */
89 snprintf(mask
, sizeof(mask
), "%s@%s", user
, trusts_cidr2str(ip
, bits
));
91 glinebufadd(gbuf
, mask
, creator
, reason
, expire
, lastmod
, lifetime
);
94 void glinebufaddbynick(glinebuf
*gbuf
, nick
*np
, int flags
, const char *creator
, const char *reason
, time_t expire
, time_t lastmod
, time_t lifetime
) {
95 if (flags
& GLINE_ALWAYS_NICK
) {
97 snprintf(mask
, sizeof(mask
), "%s!*@*", np
->nick
);
98 glinebufadd(gbuf
, mask
, creator
, reason
, expire
, lastmod
, lifetime
);
100 glinebufaddbyip(gbuf
, np
->ident
, &np
->p_ipaddr
, 128, flags
, creator
, reason
, expire
, lastmod
, lifetime
);
104 void glinebufcounthits(glinebuf
*gbuf
, int *users
, int *channels
) {
118 for (i
= 0; i
<CHANNELHASHSIZE
; i
++) {
119 for (cip
= chantable
[i
]; cip
; cip
= cip
->next
) {
127 for (gl
= gbuf
->head
; gl
; gl
= gl
->next
) {
128 if (gline_match_channel(gl
, cp
)) {
141 for (i
= 0; i
< NICKHASHSIZE
; i
++) {
142 for (np
= nicktable
[i
]; np
; np
= np
->next
) {
145 for (gl
= gbuf
->head
; gl
; gl
= gl
->next
) {
146 if (gline_match_nick(gl
, np
)) {
159 int glinebufsanitize(glinebuf
*gbuf
) {
166 /* Remove glines that fail the sanity check */
167 for (pnext
= &gbuf
->head
; *pnext
; pnext
= &((*pnext
)->next
)) {
170 if (!isglinesane(gl
, &hint
)) {
171 controlwall(NO_OPER
, NL_GLINES
, "Sanity check failed for G-Line on '%s' lasting %s created by %s with reason '%s' - Skipping: %s",
172 glinetostring(gl
), longtoduration(gl
->expire
-getnettime(), 0),
173 gl
->reason
->content
, gl
->creator
->content
, hint
);
188 void glinebufspew(glinebuf
*gbuf
, nick
*np
) {
191 for (gl
= gbuf
->head
; gl
; gl
= gl
->next
)
192 controlreply(np
, "mask: %s", glinetostring(gl
));
195 void glinebufflush(glinebuf
*gbuf
, int propagate
) {
196 gline
*gl
, *next
, *sgl
;
200 glinebufcounthits(gbuf
, &users
, &channels
);
202 if (propagate
&& (users
> MAXGLINEUSERHITS
|| channels
> MAXGLINECHANNELHITS
)) {
203 controlwall(NO_OPER
, NL_GLINES
, "G-Line buffer would hit %d users/%d channels. Not setting G-Lines.");
204 glinebufabandon(gbuf
);
208 for (gl
= gbuf
->head
; gl
; gl
= next
) {
211 sgl
= findgline(glinetostring(gl
));
215 * in 1.4, can update expire, reason etc
216 * in 1.3 can only activate/deactivate an existing gline */
218 if (gl
->flags
& GLINE_ACTIVE
&& !(sgl
->flags
& GLINE_ACTIVE
))
219 gline_activate(sgl
, 0, 0);
220 else if (!(gl
->flags
& GLINE_ACTIVE
) && sgl
->flags
& GLINE_ACTIVE
)
221 gline_deactivate(sgl
, 0, 0);
226 gl
->next
= glinelist
;
235 void glinebufabandon(glinebuf
*gbuf
) {
238 for (gl
= gbuf
->head
; gl
; gl
= next
) {