]>
jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_handler.c
45d2476fb8b0369092442eb7037649f1959a24f0
3 #include "../localuser/localuserchannel.h"
7 <prefix> GL <target> [!][+|-|>|<]<mask> [<expiration>] [<lastmod>] [<lifetime>] [:<reason>]
10 int handleglinemsg(void *source
, int cargc
, char **cargv
) {
11 char *sender
= (char *)source
;
15 time_t lifetime
= 0, expire
= 0, lastmod
= 0;
16 unsigned int flags
= 0;
23 * Valid GL tokens have X params:
24 * 2: Local modification to a local gline - ignored by services
27 * 6: 1.4.x GL Token - adds lifetime parameter
31 /* local modification which we reject later */
40 /* 1.4.0 and above GL token */
43 Error("gline", ERR_WARNING
, "Invalid number of arguments in GL token (%d)", cargc
);
48 * Gline creator can be either a nick or a server
49 * 2 long numeric = server
50 * 5 long number = client
52 switch (strlen(source
)) {
54 creatornum
= numerictolong(sender
, 2);
56 Error("gline", ERR_WARNING
, "Failed to resolve numeric (%s) to server when adding G-Line from network!", sender
);
59 if (serverlist
[(int)creatornum
].name
== NULL
) {
60 Error("gline", ERR_WARNING
, "Received gline from non-existant server");
63 creator
= serverlist
[(int)creatornum
].name
->content
, HOSTLEN
;
67 creatornum
= numerictolong(sender
, 5);
68 np
= getnickbynumeric(creatornum
);
70 Error("gline", ERR_WARNING
, "Failed to resolve numeric (%s) to nick when adding G-Line from network!", sender
);
76 Error("gline", ERR_WARNING
, "Invalid numeric '%s' in G-Line message.", sender
);
80 /* 2nd param is mask */
83 /* snircd 1.3.5 can destroy glines, no #if here */
85 flags
|= GLINE_DESTROY
;
91 flags
|= GLINE_ACTIVATE
;
95 flags
|= GLINE_DEACTIVATE
;
100 Error("gline", ERR_WARNING
, "Received local modification from %s - do they realise we're a service?", sender
);
103 Error("gline", ERR_WARNING
, "Received 'forced gline' token from %s", sender
);
107 if (flags
& GLINE_ACTIVATE
) {
109 expire
= abs_expire(atoi(cargv
[2]));
112 /* asuka U:d, no lastmod */
119 lastmod
= atoi(cargv
[3]);
120 lifetime
= gline_max(lastmod
, expire
); /* set lifetime = lastmod */
125 lastmod
= atoi(cargv
[3]);
126 lifetime
= atoi(cargv
[4]);
130 Error("gline", ERR_WARNING
, "Gline Activate with invalid number (%d) of arguments", cargc
);
134 Error("debuggline", ERR_WARNING
, "GL Received: Creator %s, Mask %s, Reason %s, Expire %lu, Lastmod %lu, Lifetime %lu", creator
, mask
, reason
, expire
, lastmod
, lifetime
);
136 agline
= findgline(mask
);
139 Error("debuggline", ERR_WARNING
, "Update for existing gline received for %s - old lastmod %lu, expire %lu, lifetime %lu, reason %s, creator %s", mask
, agline
->lastmod
, agline
->expire
, agline
->lifetime
, agline
->reason
->content
, agline
->creator
->content
);
141 agline
->flags
|= GLINE_ACTIVE
;
143 /* check lastmod then assume the new gline is authoritive */
144 if (lastmod
> agline
->lastmod
) {
145 agline
->lastmod
= lastmod
;
146 agline
->expire
= expire
;
147 agline
->lifetime
= lifetime
;
148 freesstring(agline
->creator
);
149 agline
->creator
= getsstring(creator
, 255);
150 freesstring(agline
->reason
);
151 agline
->reason
= getsstring(reason
, 255);
153 Error("debuggline", ERR_WARNING
, "received a gline with a lower lastmod");
154 /* Don't send our gline as that might cause loops in case we don't understand the gline properly. */
159 glinebufinit(&gbuf
, 0);
160 glinebufadd(&gbuf
, mask
, creator
, reason
, expire
, lastmod
, lifetime
);
161 glinebufflush(&gbuf
, 0);
163 } else if (flags
& GLINE_DEACTIVATE
) {
164 /* deactivate gline */
165 agline
= findgline(mask
);
170 /* asuka U:d, no last mod */
175 lastmod
= atoi(cargv
[3]);
177 if (flags
& GLINE_DESTROY
)
178 gline_destroy(agline
, lastmod
, 0);
180 gline_deactivate(agline
, lastmod
, 0);
185 lastmod
= atoi(cargv
[3]);
187 if (flags
& GLINE_DESTROY
)
188 gline_destroy(agline
, lastmod
, 0);
190 gline_deactivate(agline
, lastmod
, 0);
194 Error("gline", ERR_WARNING
, "Gline Deactivate with invalid number (%d) of arguments", cargc
);
200 Error("gline", ERR_WARNING
, "Gline addition - adding deactivated gline - mask not found (%s)", mask
);
201 expire
= abs_expire(atoi(cargv
[2]));
204 /* asuka U:d, no lastmod */
209 lastmod
= atoi(cargv
[3]);
210 lifetime
= gline_max(lastmod
, expire
); /* set lifetime = lastmod */
215 lastmod
= atoi(cargv
[3]);
216 lifetime
= atoi(cargv
[4]);
220 Error("gline", ERR_WARNING
, "Gline DeActivate with invalid number (%d) of arguments", cargc
);
224 glinebufinit(&gbuf
, 0);
225 agline
= glinebufadd(&gbuf
, mask
, creator
, reason
, expire
, lastmod
, lifetime
);
228 glinebufabandon(&gbuf
);
229 Error("gline", ERR_WARNING
, "gline_add failed");
233 gline_deactivate(agline
, lastmod
, 0);
234 glinebufflush(&gbuf
, 0);
239 /* modification - only snircd 1.4.x */
240 agline
= findgline(mask
);
243 expire
= abs_expire(atoi(cargv
[2]));
244 lastmod
= atoi(cargv
[3]);
245 lifetime
= atoi(cargv
[4]);
248 if (lastmod
> agline
->lastmod
) {
249 agline
->lastmod
= lastmod
;
250 agline
->expire
= expire
;
251 agline
->lifetime
= lifetime
;
252 agline
->creator
= getsstring(creator
, 255);
253 freesstring(agline
->reason
);
254 agline
->reason
= getsstring(reason
, 255);
256 Error("debuggline", ERR_WARNING
, "received a gline modification with a lower lastmod");
261 Error("gline", ERR_WARNING
, "Received modification for G-Line that does not exist for mask %s", mask
);
269 void handleglinestats(int hooknum
, void *arg
) {
270 if ((long)arg
> 10) {
275 for(gl
= glinelist
; gl
; gl
= gl
->next
)
278 snprintf(message
, sizeof(message
), "G-Lines :%7d glines", glcount
);
279 triggerhook(HOOK_CORE_STATSREPLY
, message
);