]>
jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_handler.c
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 */
84 flags
|= GLINE_DESTROY
;
90 flags
|= GLINE_ACTIVATE
;
94 flags
|= GLINE_DEACTIVATE
;
99 Error("gline", ERR_WARNING
, "Received local modification from %s - do they realise we're a service?", sender
);
102 Error("gline", ERR_WARNING
, "Received 'forced gline' token from %s", sender
);
106 if (flags
& GLINE_ACTIVATE
) {
108 expire
= abs_expire(atoi(cargv
[2]));
111 /* asuka U:d, no lastmod */
118 lastmod
= atoi(cargv
[3]);
119 lifetime
= gline_max(lastmod
, expire
); /* set lifetime = lastmod */
124 lastmod
= atoi(cargv
[3]);
125 lifetime
= atoi(cargv
[4]);
129 Error("gline", ERR_WARNING
, "Gline Activate with invalid number (%d) of arguments", cargc
);
133 Error("debuggline", ERR_WARNING
, "GL Received: Creator %s, Mask %s, Reason %s, Expire %lu, Lastmod %lu, Lifetime %lu", creator
, mask
, reason
, expire
, lastmod
, lifetime
);
135 agline
= findgline(mask
);
138 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
);
140 agline
->flags
|= GLINE_ACTIVE
;
142 /* check lastmod then assume the new gline is authoritive */
143 if (lastmod
> agline
->lastmod
) {
144 agline
->lastmod
= lastmod
;
145 agline
->expire
= expire
;
146 agline
->lifetime
= lifetime
;
147 freesstring(agline
->creator
);
148 agline
->creator
= getsstring(creator
, 255);
149 freesstring(agline
->reason
);
150 agline
->reason
= getsstring(reason
, 255);
152 Error("debuggline", ERR_WARNING
, "received a gline with a lower lastmod");
153 /* Don't send our gline as that might cause loops in case we don't understand the gline properly. */
158 glinebufinit(&gbuf
, 0);
159 glinebufadd(&gbuf
, mask
, creator
, reason
, expire
, lastmod
, lifetime
);
160 glinebufcommit(&gbuf
, 0);
162 } else if (flags
& GLINE_DEACTIVATE
) {
163 /* deactivate gline */
164 agline
= findgline(mask
);
169 /* asuka U:d, no last mod */
174 lastmod
= atoi(cargv
[3]);
176 if (flags
& GLINE_DESTROY
)
177 gline_destroy(agline
, lastmod
, 0);
179 gline_deactivate(agline
, lastmod
, 0);
184 lastmod
= atoi(cargv
[3]);
186 if (flags
& GLINE_DESTROY
)
187 gline_destroy(agline
, lastmod
, 0);
189 gline_deactivate(agline
, lastmod
, 0);
193 Error("gline", ERR_WARNING
, "Gline Deactivate with invalid number (%d) of arguments", cargc
);
199 Error("gline", ERR_WARNING
, "Gline addition - adding deactivated gline - mask not found (%s)", mask
);
200 expire
= abs_expire(atoi(cargv
[2]));
203 /* asuka U:d, no lastmod */
208 lastmod
= atoi(cargv
[3]);
209 lifetime
= gline_max(lastmod
, expire
); /* set lifetime = lastmod */
214 lastmod
= atoi(cargv
[3]);
215 lifetime
= atoi(cargv
[4]);
219 Error("gline", ERR_WARNING
, "Gline DeActivate with invalid number (%d) of arguments", cargc
);
223 glinebufinit(&gbuf
, 0);
224 agline
= glinebufadd(&gbuf
, mask
, creator
, reason
, expire
, lastmod
, lifetime
);
227 glinebufabort(&gbuf
);
228 Error("gline", ERR_WARNING
, "gline_add failed");
232 gline_deactivate(agline
, lastmod
, 0);
233 glinebufcommit(&gbuf
, 0);
238 /* modification - only snircd 1.4.x */
239 agline
= findgline(mask
);
242 expire
= abs_expire(atoi(cargv
[2]));
243 lastmod
= atoi(cargv
[3]);
244 lifetime
= atoi(cargv
[4]);
247 if (lastmod
> agline
->lastmod
) {
248 agline
->lastmod
= lastmod
;
249 agline
->expire
= expire
;
250 agline
->lifetime
= lifetime
;
251 agline
->creator
= getsstring(creator
, 255);
252 freesstring(agline
->reason
);
253 agline
->reason
= getsstring(reason
, 255);
255 Error("debuggline", ERR_WARNING
, "received a gline modification with a lower lastmod");
260 Error("gline", ERR_WARNING
, "Received modification for G-Line that does not exist for mask %s", mask
);
268 void handleglinestats(int hooknum
, void *arg
) {
269 if ((long)arg
> 10) {
274 for(gl
= glinelist
; gl
; gl
= gl
->next
)
277 snprintf(message
, sizeof(message
), "G-Lines :%7d glines", glcount
);
278 triggerhook(HOOK_CORE_STATSREPLY
, message
);