Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_gline.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_gline.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 1, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id$
24  */
25
26 /*
27  * m_functions execute protocol messages on this server:
28  *
29  *    cptr    is always NON-NULL, pointing to a *LOCAL* client
30  *            structure (with an open socket connected!). This
31  *            identifies the physical socket where the message
32  *            originated (or which caused the m_function to be
33  *            executed--some m_functions may call others...).
34  *
35  *    sptr    is the source of the message, defined by the
36  *            prefix part of the message if present. If not
37  *            or prefix not found, then sptr==cptr.
38  *
39  *            (!IsServer(cptr)) => (cptr == sptr), because
40  *            prefixes are taken *only* from servers...
41  *
42  *            (IsServer(cptr))
43  *                    (sptr == cptr) => the message didn't
44  *                    have the prefix.
45  *
46  *                    (sptr != cptr && IsServer(sptr) means
47  *                    the prefix specified servername. (?)
48  *
49  *                    (sptr != cptr && !IsServer(sptr) means
50  *                    that message originated from a remote
51  *                    user (not local).
52  *
53  *            combining
54  *
55  *            (!IsServer(sptr)) means that, sptr can safely
56  *            taken as defining the target structure of the
57  *            message in this server.
58  *
59  *    *Always* true (if 'parse' and others are working correct):
60  *
61  *    1)      sptr->from == cptr  (note: cptr->from == cptr)
62  *
63  *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64  *            *cannot* be a local connection, unless it's
65  *            actually cptr!). [MyConnect(x) should probably
66  *            be defined as (x == x->from) --msa ]
67  *
68  *    parc    number of variable parameter strings (if zero,
69  *            parv is allowed to be NULL)
70  *
71  *    parv    a NULL terminated list of parameter pointers,
72  *
73  *                    parv[0], sender (prefix string), if not present
74  *                            this points to an empty string.
75  *                    parv[1]...parv[parc-1]
76  *                            pointers to additional parameters
77  *                    parv[parc] == NULL, *always*
78  *
79  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
80  *                    non-NULL pointers.
81  */
82 #include "config.h"
83
84 #include "client.h"
85 #include "gline.h"
86 #include "hash.h"
87 #include "ircd.h"
88 #include "ircd_features.h"
89 #include "ircd_log.h"
90 #include "ircd_reply.h"
91 #include "ircd_string.h"
92 #include "match.h"
93 #include "msg.h"
94 #include "numeric.h"
95 #include "numnicks.h"
96 #include "s_conf.h"
97 #include "s_debug.h"
98 #include "s_misc.h"
99 #include "send.h"
100
101 /* #include <assert.h> -- Now using assert in ircd_log.h */
102 #include <stdlib.h>
103 #include <string.h>
104
105 #define PASTWATCH       157680000       /* number of seconds in 5 years */
106
107 /*
108  * If the expiration value, interpreted as an absolute timestamp, is
109  * more recent than 5 years in the past, we interpret it as an
110  * absolute timestamp; otherwise, we assume it's relative and convert
111  * it to an absolute timestamp.  Either way, the output of this macro
112  * is an absolute timestamp--not guaranteed to be a *valid* timestamp,
113  * but you can't have everything in a macro ;)
114  */
115 #define abs_expire(exp)                                                 \
116   ((exp) >= CurrentTime - PASTWATCH ? (exp) : (exp) + CurrentTime)
117
118 /*
119  * ms_gline - server message handler
120  *
121  * parv[0] = Sender prefix
122  * parv[1] = Target: server numeric
123  * parv[2] = (+|-)<G-line mask>
124  *
125  * For other parameters, see doc/readme.gline.
126  */
127 int
128 ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
129 {
130   struct Client *acptr = 0;
131   struct Gline *agline = 0;
132   unsigned int flags = 0;
133   enum GlineAction action = GLINE_MODIFY;
134   time_t expire = 0, lastmod = 0, lifetime = 0;
135   char *mask = parv[2], *target = parv[1], *reason = "No reason", *tmp = 0;
136
137   if (parc < 3)
138     return need_more_params(sptr, "GLINE");
139
140   if (IsServer(sptr))
141     flags |= GLINE_FORCE;
142
143   if (*mask == '!') {
144     mask++;
145     flags |= GLINE_OPERFORCE; /* assume oper had WIDE_GLINE */
146   }
147
148   switch (*mask) { /* handle +, -, <, and > */
149   case '+': /* activate the G-line */
150     action = GLINE_ACTIVATE;
151     mask++;
152     break;
153
154   case '-': /* deactivate the G-line */
155     action = GLINE_DEACTIVATE;
156     mask++;
157     break;
158
159   case '>': /* locally activate the G-line */
160     action = GLINE_LOCAL_ACTIVATE;
161     mask++;
162     break;
163
164   case '<': /* locally deactivate the G-line */
165     action = GLINE_LOCAL_DEACTIVATE;
166     mask++;
167     break;
168   }
169
170   /* Now, let's figure out if it's a local or global G-line */
171   if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE ||
172       (target[0] == '*' && target[1] == '\0'))
173     flags |= GLINE_GLOBAL;
174   else
175     flags |= GLINE_LOCAL;
176
177   /* now figure out if we need to resolve a server */
178   if ((action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE ||
179        (flags & GLINE_LOCAL)) && !(acptr = FindNServer(target)))
180     return 0; /* no such server, jump out */
181
182   /* If it's a local activate/deactivate and server isn't me, propagate it */
183   if ((action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE) &&
184       !IsMe(acptr)) {
185     Debug((DEBUG_DEBUG, "I am forwarding a local change to a global gline "
186            "to a remote server; target %s, mask %s, operforce %s, action %c",
187            target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
188            action == GLINE_LOCAL_ACTIVATE ? '>' : '<'));
189
190     sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s", acptr,
191                   flags & GLINE_OPERFORCE ? "!" : "",
192                   action == GLINE_LOCAL_ACTIVATE ? '>' : '<', mask);
193
194     return 0; /* all done */
195   }
196
197   /* Next, try to find the G-line... */
198   if ((flags & GLINE_GLOBAL) || IsMe(acptr)) /* don't bother if it's not me! */
199     agline = gline_find(mask, flags | GLINE_ANY | GLINE_EXACT);
200
201   /* We now have all the pieces to tell us what we've got; let's put
202    * it all together and convert the rest of the arguments.
203    */
204
205   /* Handle the local G-lines first... */
206   if (flags & GLINE_LOCAL) {
207     assert(acptr);
208
209     /* normalize the action, first */
210     if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_MODIFY)
211       action = GLINE_ACTIVATE;
212     else if (action == GLINE_LOCAL_DEACTIVATE)
213       action = GLINE_DEACTIVATE;
214
215     if (action == GLINE_ACTIVATE) { /* get expiration and reason */
216       if (parc < 5) /* check parameter count... */
217         return need_more_params(sptr, "GLINE");
218
219       expire = atoi(parv[3]); /* get expiration... */
220       expire = abs_expire(expire); /* convert to absolute... */
221       reason = parv[parc - 1]; /* and reason */
222
223       if (IsMe(acptr)) {
224         if (agline) /* G-line already exists, so let's ignore it... */
225           return 0;
226
227         /* OK, create the local G-line */
228         Debug((DEBUG_DEBUG, "I am creating a local G-line here; target %s, "
229                "mask %s, operforce %s, action %s, expire %Tu, reason: %s",
230                target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
231                action == GLINE_ACTIVATE ? "+" : "-", expire, reason));
232
233         return gline_add(cptr, sptr, mask, reason, expire, lastmod,
234                          lifetime, flags | GLINE_ACTIVE);
235       }
236     } else if (IsMe(acptr)) { /* destroying a local G-line */
237       if (!agline) /* G-line doesn't exist, so let's complain... */
238         return send_reply(sptr, ERR_NOSUCHGLINE, mask);
239
240       /* Let's now destroy the G-line */;
241       Debug((DEBUG_DEBUG, "I am destroying a local G-line here; target %s, "
242              "mask %s, operforce %s, action %s", target, mask,
243              flags & GLINE_OPERFORCE ? "YES" : "NO",
244              action == GLINE_ACTIVATE ? "+" : "-"));
245
246       return gline_destroy(cptr, sptr, agline);
247     }
248
249     /* OK, we've converted arguments; if it's not for us, forward */
250     /* UPDATE NOTE: Once all servers are updated to u2.10.12.11, the
251      * format string in this sendcmdto_one() may be updated to omit
252      * <lastmod> for GLINE_ACTIVATE and to omit <expire>, <lastmod>,
253      * and <reason> for GLINE_DEACTIVATE.
254      */
255     assert(!IsMe(acptr));
256
257     Debug((DEBUG_DEBUG, "I am forwarding a local G-line to a remote server; "
258            "target %s, mask %s, operforce %s, action %c, expire %Tu, "
259            "lastmod %Tu, reason: %s", target, mask,
260            flags & GLINE_OPERFORCE ? "YES" : "NO",
261            action == GLINE_ACTIVATE ? '+' :  '-', expire, CurrentTime,
262            reason));
263
264     sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s %Tu %Tu :%s",
265                   acptr, flags & GLINE_OPERFORCE ? "!" : "",
266                   action == GLINE_ACTIVATE ? '+' : '-', mask,
267                   expire - CurrentTime, CurrentTime, reason);
268
269     return 0; /* all done */
270   }
271
272   /* can't modify a G-line that doesn't exist, so remap to activate */
273   if (!agline && action == GLINE_MODIFY)
274     action = GLINE_ACTIVATE;
275
276   /* OK, let's figure out what other parameters we may have... */
277   switch (action) {
278   case GLINE_LOCAL_ACTIVATE: /* locally activating a G-line */
279   case GLINE_LOCAL_DEACTIVATE: /* locally deactivating a G-line */
280     if (!agline) /* no G-line to locally activate or deactivate? */
281       return send_reply(sptr, ERR_NOSUCHGLINE, mask);
282     break; /* no additional parameters to manipulate */
283
284   case GLINE_ACTIVATE: /* activating a G-line */
285   case GLINE_DEACTIVATE: /* deactivating a G-line */
286     /* in either of these cases, we have at least a lastmod parameter */
287     if (parc < 4)
288       return need_more_params(sptr, "GLINE");
289     else if (parc == 4) /* lastmod only form... */
290       lastmod = atoi(parv[3]);
291     /*FALLTHROUGH*/
292   case GLINE_MODIFY: /* modifying a G-line */
293     /* convert expire and lastmod, look for lifetime and reason */
294     if (parc > 4) { /* protect against fall-through from 4-param form */
295       if (parc < 5)
296         return need_more_params(sptr, "GLINE");
297
298       expire = atoi(parv[3]); /* convert expiration and lastmod */
299       expire = abs_expire(expire);
300       lastmod = atoi(parv[4]);
301
302       flags |= GLINE_EXPIRE; /* we have an expiration time update */
303
304       if (parc > 6) { /* no question, have a lifetime and reason */
305         lifetime = atoi(parv[5]);
306         reason = parv[parc - 1];
307
308         flags |= GLINE_LIFETIME | GLINE_REASON;
309       } else if (parc == 6) { /* either a lifetime or a reason */
310         if (!agline || /* gline creation, has to be the reason */
311             /* trial-convert as lifetime, and if it doesn't fully convert,
312              * it must be the reason */
313             ((lifetime = strtoul(parv[5], &tmp, 10)) && !*tmp)) {
314           lifetime = 0;
315           reason = parv[5];
316
317           flags |= GLINE_REASON; /* have a reason update */
318         } else if (lifetime)
319           flags |= GLINE_LIFETIME; /* have a lifetime update */
320       }
321     }
322   }
323
324   if (!lastmod) /* must have a lastmod parameter by now */
325     return need_more_params(sptr, "GLINE");
326
327   Debug((DEBUG_DEBUG, "I have a global G-line I am acting upon now; "
328          "target %s, mask %s, operforce %s, action %s, expire %Tu, "
329          "lastmod %Tu, lifetime %Tu, reason: %s; gline %s!  (fields "
330          "present: %s %s %s)", target, mask,
331          flags & GLINE_OPERFORCE ? "YES" : "NO",
332          action == GLINE_ACTIVATE ? "+" :
333          (action == GLINE_DEACTIVATE ? "-" :
334           (action == GLINE_LOCAL_ACTIVATE ? ">" :
335            (action == GLINE_LOCAL_DEACTIVATE ? "<" : "(MODIFY)"))),
336          expire, lastmod, lifetime, reason,
337          agline ? "EXISTS" : "does not exist",
338          flags & GLINE_EXPIRE ? "expire" : "",
339          flags & GLINE_LIFETIME ? "lifetime" : "",
340          flags & GLINE_REASON ? "reason" : ""));
341
342   /* OK, at this point, we have converted all available parameters.
343    * Let's actually do the action!
344    */
345   if (agline)
346     return gline_modify(cptr, sptr, agline, action, reason, expire,
347                         lastmod, lifetime, flags);
348
349   assert(action != GLINE_LOCAL_ACTIVATE);
350   assert(action != GLINE_LOCAL_DEACTIVATE);
351   assert(action != GLINE_MODIFY);
352
353   return gline_add(cptr, sptr, mask, reason, expire, lastmod, lifetime,
354                    flags | ((action == GLINE_ACTIVATE) ? GLINE_ACTIVE : 0));
355 }
356
357 /*
358  * mo_gline - oper message handler
359  *
360  * parv[0] = Sender prefix
361  * parv[1] = [[+|-]<G-line mask>]
362  *
363  * For other parameters, see doc/readme.gline.
364  */
365 int
366 mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
367 {
368   struct Client *acptr = 0;
369   struct Gline *agline = 0;
370   unsigned int flags = 0;
371   enum GlineAction action = GLINE_MODIFY;
372   time_t expire = 0;
373   char *mask = parv[1], *target = 0, *reason = 0;
374
375   if (parc < 2)
376     return gline_list(sptr, 0);
377
378   if (*mask == '!') {
379     mask++;
380
381     if (HasPriv(sptr, PRIV_WIDE_GLINE))
382       flags |= GLINE_OPERFORCE;
383   }
384
385   switch (*mask) { /* handle +, -, <, and > */
386   case '+': /* activate the G-line */
387     action = GLINE_ACTIVATE;
388     mask++;
389     break;
390
391   case '-': /* deactivate the G-line */
392     action = GLINE_DEACTIVATE;
393     mask++;
394     break;
395
396   case '>': /* locally activate the G-line */
397     action = GLINE_LOCAL_ACTIVATE;
398     mask++;
399     break;
400
401   case '<': /* locally deactivate the G-line */
402     action = GLINE_LOCAL_DEACTIVATE;
403     mask++;
404     break;
405   }
406
407   /* OK, let's figure out the parameters... */
408   switch (action) {
409   case GLINE_MODIFY: /* no specific action on the G-line... */
410     if (parc == 2) /* user wants a listing of a specific G-line */
411       return gline_list(sptr, mask);
412     else if (parc < 4) /* must have target and expire, minimum */
413       return need_more_params(sptr, "GLINE");
414
415     target = parv[2]; /* get the target... */
416     expire = atoi(parv[3]) + CurrentTime; /* and the expiration */
417
418     flags |= GLINE_EXPIRE; /* remember that we got an expire time */
419
420     if (parc > 4) { /* also got a reason... */
421       reason = parv[4];
422       flags |= GLINE_REASON;
423     }
424
425     /* target is not global, interpolate action and require reason */
426     if (target[0] != '*' || target[1] != '\0') {
427       if (!reason) /* have to have a reason for this */
428         return need_more_params(sptr, "GLINE");
429
430       action = GLINE_ACTIVATE;
431     }
432     break;
433
434   case GLINE_LOCAL_ACTIVATE: /* locally activate a G-line */
435   case GLINE_LOCAL_DEACTIVATE: /* locally deactivate a G-line */
436     if (parc > 2) /* if target is available, pick it */
437       target = parv[2];
438     break;
439
440   case GLINE_ACTIVATE: /* activating/adding a G-line */
441   case GLINE_DEACTIVATE: /* deactivating/removing a G-line */
442     if (parc < 3)
443       return need_more_params(sptr, "GLINE");
444
445     if (parc > 3) {
446       /* get expiration and target */
447       expire = atoi(parv[parc - 2]) + CurrentTime;
448       reason = parv[parc - 1];
449
450       flags |= GLINE_EXPIRE | GLINE_REASON; /* remember that we got 'em */
451
452       if (parc > 4) /* also have a target! */
453         target = parv[2];
454     } else {
455       target = parv[2]; /* target has to be present, and has to be '*' */
456
457       if (target[0] != '*' || target[1] != '\0')
458         return need_more_params(sptr, "GLINE");
459     }
460     break;
461   }
462
463   /* Now let's figure out which is the target server */
464   if (!target) /* no target, has to be me... */
465     acptr = &me;
466   /* if it's not '*', look up the server */
467   else if ((target[0] != '*' || target[1] != '\0') &&
468            !(acptr = find_match_server(target)))
469     return send_reply(sptr, ERR_NOSUCHSERVER, target);
470
471   /* Now, is the G-line local or global? */
472   if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE ||
473       !acptr)
474     flags |= GLINE_GLOBAL;
475   else /* it's some form of local G-line */
476     flags |= GLINE_LOCAL;
477
478   /* If it's a local activate/deactivate and server isn't me, propagate it */
479   if ((action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE) &&
480       !IsMe(acptr)) {
481     /* check for permissions... */
482     if (!feature_bool(FEAT_CONFIG_OPERCMDS))
483       return send_reply(sptr, ERR_DISABLED, "GLINE");
484     else if (!HasPriv(sptr, PRIV_GLINE))
485       return send_reply(sptr, ERR_NOPRIVILEGES);
486
487     Debug((DEBUG_DEBUG, "I am forwarding a local change to a global gline "
488            "to a remote server; target %s, mask %s, operforce %s, action %c",
489            cli_name(acptr), mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
490            action == GLINE_LOCAL_ACTIVATE ? '>' : '<'));
491
492     sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s", acptr,
493                   flags & GLINE_OPERFORCE ? "!" : "",
494                   action == GLINE_LOCAL_ACTIVATE ? '>' : '<', mask);
495
496     return 0; /* all done */
497   }
498
499   /* Next, try to find the G-line... */
500   if ((flags & GLINE_GLOBAL) || IsMe(acptr)) /* don't bother if it's not me! */
501     agline = gline_find(mask, flags | GLINE_ANY | GLINE_EXACT);
502
503   /* We now have all the pieces to tell us what we've got; let's put
504    * it all together and convert the rest of the arguments.
505    */
506
507   /* Handle the local G-lines first... */
508   if (flags & GLINE_LOCAL) {
509     assert(acptr);
510
511     /* normalize the action, first */
512     if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_MODIFY)
513       action = GLINE_ACTIVATE;
514     else if (action == GLINE_LOCAL_DEACTIVATE)
515       action = GLINE_DEACTIVATE;
516
517     /* If it's not for us, forward */
518     /* UPDATE NOTE: Once all servers are updated to u2.10.12.11, the
519      * format string in this sendcmdto_one() may be updated to omit
520      * <lastmod> for GLINE_ACTIVATE and to omit <expire>, <lastmod>,
521      * and <reason> for GLINE_DEACTIVATE.
522      */
523
524     if (!IsMe(acptr)) {
525       /* check for permissions... */
526       if (!feature_bool(FEAT_CONFIG_OPERCMDS))
527         return send_reply(sptr, ERR_DISABLED, "GLINE");
528       else if (!HasPriv(sptr, PRIV_GLINE))
529         return send_reply(sptr, ERR_NOPRIVILEGES);
530
531       Debug((DEBUG_DEBUG, "I am forwarding a local G-line to a remote "
532              "server; target %s, mask %s, operforce %s, action %c, "
533              "expire %Tu, reason %s", target, mask,
534              flags & GLINE_OPERFORCE ? "YES" : "NO",
535              action == GLINE_ACTIVATE ? '+' : '-', expire, reason));
536
537       sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s %Tu %Tu :%s",
538                     acptr, flags & GLINE_OPERFORCE ? "!" : "",
539                     action == GLINE_ACTIVATE ? '+' : '-', mask,
540                     expire - CurrentTime, CurrentTime, reason);
541
542       return 0; /* all done */
543     }
544
545     /* check local G-line permissions... */
546     if (!HasPriv(sptr, PRIV_LOCAL_GLINE))
547       return send_reply(sptr, ERR_NOPRIVILEGES);
548
549     /* let's handle activation... */
550     if (action == GLINE_ACTIVATE) {
551       if (agline) /* G-line already exists, so let's ignore it... */
552         return 0;
553
554       /* OK, create the local G-line */
555       Debug((DEBUG_DEBUG, "I am creating a local G-line here; target %s, "
556              "mask %s, operforce %s, action  %s, expire %Tu, reason: %s",
557              target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
558              action == GLINE_ACTIVATE ? "+" : "-", expire, reason));
559
560       return gline_add(cptr, sptr, mask, reason, expire, 0, 0,
561                        flags | GLINE_ACTIVE);
562     } else { /* OK, it's a deactivation/destruction */
563       if (!agline) /* G-line doesn't exist, so let's complain... */
564         return send_reply(sptr, ERR_NOSUCHGLINE, mask);
565
566       /* Let's now destroy the G-line */
567       Debug((DEBUG_DEBUG, "I am destroying a local G-line here; target %s, "
568              "mask %s, operforce %s, action %s", target, mask,
569              flags & GLINE_OPERFORCE ? "YES" : "NO",
570              action == GLINE_ACTIVATE ? "+" : "-"));
571
572       return gline_destroy(cptr, sptr, agline);
573     }
574   }
575
576   /* can't modify a G-line that doesn't exist... */
577   if (!agline &&
578       (action == GLINE_MODIFY || action == GLINE_LOCAL_ACTIVATE ||
579        action == GLINE_LOCAL_DEACTIVATE))
580     return send_reply(sptr, ERR_NOSUCHGLINE, mask);
581
582   /* check for G-line permissions... */
583   if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE) {
584     /* only need local privileges for locally-limited status changes */
585     if (!HasPriv(sptr, PRIV_LOCAL_GLINE))
586       return send_reply(sptr, ERR_NOPRIVILEGES);
587   } else { /* global privileges required */
588     if (!feature_bool(FEAT_CONFIG_OPERCMDS))
589       return send_reply(sptr, ERR_DISABLED, "GLINE");
590     else if (!HasPriv(sptr, PRIV_GLINE))
591       return send_reply(sptr, ERR_NOPRIVILEGES);
592   }
593
594   Debug((DEBUG_DEBUG, "I have a global G-line I am acting upon now; "
595          "target %s, mask %s, operforce %s, action %s, expire %Tu, "
596          "reason: %s; gline %s!  (fields present: %s %s)", target, 
597          mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
598          action == GLINE_ACTIVATE ? "+" :
599          (action == GLINE_DEACTIVATE ? "-" :
600           (action == GLINE_LOCAL_ACTIVATE ? ">" :
601            (action == GLINE_LOCAL_DEACTIVATE ? "<" : "(MODIFY)"))),
602          expire, reason, agline ? "EXISTS" : "does not exist",
603          flags & GLINE_EXPIRE ? "expire" : "",
604          flags & GLINE_REASON ? "reason" : ""));
605
606   if (agline) /* modifying an existing G-line */
607     return gline_modify(cptr, sptr, agline, action, reason, expire,
608                         CurrentTime, 0, flags);
609
610   assert(action != GLINE_LOCAL_ACTIVATE);
611   assert(action != GLINE_LOCAL_DEACTIVATE);
612   assert(action != GLINE_MODIFY);
613
614   /* create a new G-line */
615   return gline_add(cptr, sptr, mask, reason, expire, CurrentTime, 0,
616                    flags | ((action == GLINE_ACTIVATE) ? GLINE_ACTIVE : 0));
617 }
618
619 /*
620  * m_gline - user message handler
621  *
622  * parv[0] = Sender prefix
623  * parv[1] = [<server name>]
624  *
625  */
626 int
627 m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
628 {
629   if (parc < 2)
630     return send_reply(sptr, ERR_NOSUCHGLINE, "");
631
632   return gline_list(sptr, parv[1]);
633 }