Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_who.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_who.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 #if 0
83 /*
84  * No need to include handlers.h here the signatures must match
85  * and we don't need to force a rebuild of all the handlers everytime
86  * we add a new one to the list. --Bleep
87  */
88 #include "handlers.h"
89 #endif /* 0 */
90 #include "channel.h"
91 #include "client.h"
92 #include "hash.h"
93 #include "ircd.h"
94 #include "ircd_chattr.h"
95 #include "ircd_log.h"
96 #include "ircd_reply.h"
97 #include "ircd_string.h"
98 #include "match.h"
99 #include "numeric.h"
100 #include "numnicks.h"
101 #include "send.h"
102 #include "support.h"
103 #include "whocmds.h"
104
105
106 #include <assert.h>
107 #include <string.h>
108
109
110 /*
111  * A little spin-marking utility to tell us wich clients we have already
112  * processed and wich not
113  */
114 static int who_marker = 0;
115 static void move_marker(void)
116 {
117   if (!++who_marker)
118   {
119     struct Client *cptr = GlobalClientList;
120     while (cptr)
121     {
122       cptr->marker = 0;
123       cptr = cptr->next;
124     }
125     who_marker++;
126   }
127 }
128
129 #define CheckMark(x, y) ((x == y) ? 0 : (x = y))
130 #define Process(cptr) CheckMark(cptr->marker, who_marker)
131
132 /*
133  * m_who - generic message handler
134  *
135  *  parv[0] = sender prefix
136  *  parv[1] = nickname mask list
137  *  parv[2] = additional selection flag, only 'o' for now.
138  *            and %flags to specify what fields to output
139  *            plus a ,querytype if the t flag is specified
140  *            so the final thing will be like o%tnchu,777
141  *  parv[3] = _optional_ parameter that overrides parv[1]
142  *            This can be used as "/quote who foo % :The Black Hacker
143  *            to find me, parv[3] _can_ contain spaces !.
144  */
145 int m_who(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
146 {
147   char *mask;           /* The mask we are looking for              */
148   char ch;                      /* Scratch char register                    */
149   struct Channel *chptr;                /* Channel to show                          */
150   struct Client *acptr;         /* Client to show                           */
151
152   int bitsel;                   /* Mask of selectors to apply               */
153   int matchsel;                 /* Wich fields the match should apply on    */
154   int counter;                  /* Query size counter,
155                                    initially used to count fields           */
156   int commas;                   /* Does our mask contain any comma ?
157                                    If so is a list..                        */
158   int fields;                   /* Mask of fields to show                   */
159   int isthere = 0;              /* When this set the user is member of chptr */
160   char *nick;                   /* Single element extracted from
161                                    the mask list                            */
162   char *p;                      /* Scratch char pointer                     */
163   char *qrt;                    /* Pointer to the query type                */
164   static char mymask[512];      /* To save the mask before corrupting it    */
165
166   /* Let's find where is our mask, and if actually contains something */
167   mask = ((parc > 1) ? parv[1] : 0);
168   if (parc > 3 && parv[3])
169     mask = parv[3];
170   if (mask && ((mask[0] == '\0') ||
171       (mask[1] == '\0' && ((mask[0] == '0') || (mask[0] == '*')))))
172     mask = 0;
173
174   /* Evaluate the flags now, we consider the second parameter 
175      as "matchFlags%fieldsToInclude,querytype"           */
176   bitsel = fields = counter = matchsel = 0;
177   qrt = 0;
178   if (parc > 2 && parv[2] && *parv[2])
179   {
180     p = parv[2];
181     while (((ch = *(p++))) && (ch != '%') && (ch != ','))
182       switch (ch)
183       {
184         case 'o':
185         case 'O':
186           bitsel |= WHOSELECT_OPER;
187           continue;
188         case 'x':
189         case 'X':
190           bitsel |= WHOSELECT_EXTRA;
191 #ifdef WPATH
192           if (IsAnOper(sptr))
193             write_log(WPATH, "# " TIME_T_FMT " %#C WHO %s %s\n",
194                       CurrentTime, sptr, (BadPtr(parv[3]) ? parv[1] : parv[3]),
195                       parv[2]);
196 #endif /* WPATH */
197           continue;
198         case 'n':
199         case 'N':
200           matchsel |= WHO_FIELD_NIC;
201           continue;
202         case 'u':
203         case 'U':
204           matchsel |= WHO_FIELD_UID;
205           continue;
206         case 'h':
207         case 'H':
208           matchsel |= WHO_FIELD_HOS;
209           continue;
210         case 'i':
211         case 'I':
212           matchsel |= WHO_FIELD_NIP;
213           continue;
214         case 's':
215         case 'S':
216           matchsel |= WHO_FIELD_SER;
217           continue;
218         case 'r':
219         case 'R':
220           matchsel |= WHO_FIELD_REN;
221           continue;
222       }
223     if (ch == '%')
224       while ((ch = *p++) && (ch != ','))
225       {
226         counter++;
227         switch (ch)
228         {
229           case 'c':
230           case 'C':
231             fields |= WHO_FIELD_CHA;
232             break;
233           case 'd':
234           case 'D':
235             fields |= WHO_FIELD_DIS;
236             break;
237           case 'f':
238           case 'F':
239             fields |= WHO_FIELD_FLA;
240             break;
241           case 'h':
242           case 'H':
243             fields |= WHO_FIELD_HOS;
244             break;
245           case 'i':
246           case 'I':
247             fields |= WHO_FIELD_NIP;
248             break;
249           case 'l':
250           case 'L':
251             fields |= WHO_FIELD_IDL;
252           case 'n':
253           case 'N':
254             fields |= WHO_FIELD_NIC;
255             break;
256           case 'r':
257           case 'R':
258             fields |= WHO_FIELD_REN;
259             break;
260           case 's':
261           case 'S':
262             fields |= WHO_FIELD_SER;
263             break;
264           case 't':
265           case 'T':
266             fields |= WHO_FIELD_QTY;
267             break;
268           case 'u':
269           case 'U':
270             fields |= WHO_FIELD_UID;
271             break;
272           default:
273             break;
274         }
275       };
276     if (ch)
277       qrt = p;
278   }
279
280   if (!matchsel)
281     matchsel = WHO_FIELD_DEF;
282   if (!fields)
283     counter = 7;
284
285   if (qrt && (fields & WHO_FIELD_QTY))
286   {
287     p = qrt;
288     if (!((*p > '9') || (*p < '0')))
289       p++;
290     if (!((*p > '9') || (*p < '0')))
291       p++;
292     if (!((*p > '9') || (*p < '0')))
293       p++;
294     *p = '\0';
295   }
296   else
297     qrt = 0;
298
299   /* I'd love to add also a check on the number of matches fields per time */
300   counter = (2048 / (counter + 4));
301   if (mask && (strlen(mask) > 510))
302     mask[510] = '\0';
303   move_marker();
304   commas = (mask && strchr(mask, ','));
305
306   /* First treat mask as a list of plain nicks/channels */
307   if (mask)
308   {
309     strcpy(mymask, mask);
310     for (p = 0, nick = ircd_strtok(&p, mymask, ","); nick;
311         nick = ircd_strtok(&p, 0, ","))
312     {
313       if (IsChannelName(nick) && (chptr = FindChannel(nick)))
314       {
315         isthere = (find_channel_member(sptr, chptr) != 0);
316         if (isthere || SEE_CHANNEL(sptr, chptr, bitsel))
317         {
318           struct Membership* member;
319           for (member = chptr->members; member; member = member->next_member)
320           {
321             acptr = member->user;
322             if ((bitsel & WHOSELECT_OPER) && !(IsAnOper(acptr)))
323               continue;
324             if ((acptr != sptr) && (member->status & CHFL_ZOMBIE))
325               continue;
326             if (!(isthere || (SEE_USER(sptr, acptr, bitsel))))
327               continue;
328             if (!Process(acptr))        /* This can't be moved before other checks */
329               continue;
330             if (!(isthere || (SHOW_MORE(sptr, counter))))
331               break;
332             do_who(sptr, acptr, chptr, fields, qrt);
333           }
334         }
335       }
336       else
337       {
338         if ((acptr = FindUser(nick)) &&
339             ((!(bitsel & WHOSELECT_OPER)) || IsAnOper(acptr)) &&
340             Process(acptr) && SHOW_MORE(sptr, counter))
341         {
342           do_who(sptr, acptr, 0, fields, qrt);
343         }
344       }
345     }
346   }
347
348   /* If we didn't have any comma in the mask treat it as a
349      real mask and try to match all relevant fields */
350   if (!(commas || (counter < 1)))
351   {
352     int minlen, cset;
353     static struct in_mask imask;
354     if (mask)
355     {
356       matchcomp(mymask, &minlen, &cset, mask);
357       if (matchcompIP(&imask, mask))
358         matchsel &= ~WHO_FIELD_NIP;
359       if ((minlen > NICKLEN) || !(cset & NTL_IRCNK))
360         matchsel &= ~WHO_FIELD_NIC;
361       if ((matchsel & WHO_FIELD_SER) &&
362           ((minlen > HOSTLEN) || (!(cset & NTL_IRCHN))
363           || (!markMatchexServer(mymask, minlen))))
364         matchsel &= ~WHO_FIELD_SER;
365       if ((minlen > USERLEN) || !(cset & NTL_IRCUI))
366         matchsel &= ~WHO_FIELD_UID;
367       if ((minlen > HOSTLEN) || !(cset & NTL_IRCHN))
368         matchsel &= ~WHO_FIELD_HOS;
369     }
370
371     /* First of all loop through the clients in common channels */
372     if ((!(counter < 1)) && matchsel) {
373       struct Membership* member;
374       struct Membership* chan;
375       for (chan = sptr->user->channel; chan; chan = chan->next_channel) {
376         chptr = chan->channel;
377         for (member = chptr->members; member; member = member->next_member)
378         {
379           acptr = member->user;
380           if (!(IsUser(acptr) && Process(acptr)))
381             continue;           /* Now Process() is at the beginning, if we fail
382                                    we'll never have to show this acptr in this query */
383           if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
384             continue;
385           if ((mask) &&
386               ((!(matchsel & WHO_FIELD_NIC))
387               || matchexec(acptr->name, mymask, minlen))
388               && ((!(matchsel & WHO_FIELD_UID))
389               || matchexec(acptr->user->username, mymask, minlen))
390               && ((!(matchsel & WHO_FIELD_SER))
391               || (!(acptr->user->server->flags & FLAGS_MAP)))
392               && ((!(matchsel & WHO_FIELD_HOS))
393               || matchexec(acptr->user->host, mymask, minlen))
394               && ((!(matchsel & WHO_FIELD_REN))
395               || matchexec(acptr->info, mymask, minlen))
396               && ((!(matchsel & WHO_FIELD_NIP))
397               || ((((acptr->ip.s_addr & imask.mask.s_addr) !=
398               imask.bits.s_addr)) || (imask.fall
399               && matchexec(ircd_ntoa((const char*) &acptr->ip), mymask, minlen)))))
400             continue;
401           if (!SHOW_MORE(sptr, counter))
402             break;
403           do_who(sptr, acptr, chptr, fields, qrt);
404         }
405       }
406     }
407     /* Loop through all clients :-\, if we still have something to match to 
408        and we can show more clients */
409     if ((!(counter < 1)) && matchsel)
410       for (acptr = me.prev; acptr; acptr = acptr->prev)
411       {
412         if (!(IsUser(acptr) && Process(acptr)))
413           continue;
414         if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
415           continue;
416         if (!(SEE_USER(sptr, acptr, bitsel)))
417           continue;
418         if ((mask) &&
419             ((!(matchsel & WHO_FIELD_NIC))
420             || matchexec(acptr->name, mymask, minlen))
421             && ((!(matchsel & WHO_FIELD_UID))
422             || matchexec(acptr->user->username, mymask, minlen))
423             && ((!(matchsel & WHO_FIELD_SER))
424             || (!(acptr->user->server->flags & FLAGS_MAP)))
425             && ((!(matchsel & WHO_FIELD_HOS))
426             || matchexec(acptr->user->host, mymask, minlen))
427             && ((!(matchsel & WHO_FIELD_REN))
428             || matchexec(acptr->info, mymask, minlen))
429             && ((!(matchsel & WHO_FIELD_NIP))
430             || ((((acptr->ip.s_addr & imask.mask.s_addr) != imask.bits.s_addr))
431             || (imask.fall
432             && matchexec(ircd_ntoa((const char*) &acptr->ip), mymask, minlen)))))
433           continue;
434         if (!SHOW_MORE(sptr, counter))
435           break;
436         do_who(sptr, acptr, 0, fields, qrt);
437       }
438   }
439
440   /* Make a clean mask suitable to be sent in the "end of" */
441   if (mask && (p = strchr(mask, ' ')))
442     *p = '\0';
443   send_reply(sptr, RPL_ENDOFWHO, BadPtr(mask) ? "*" : mask);
444
445   /* Notify the user if we decided that his query was too long */
446   if (counter < 0)
447     send_reply(sptr, ERR_QUERYTOOLONG, "WHO");
448
449   return 0;
450 }
451
452
453 #if 0
454 /*
455  *  m_who
456  *
457  *  parv[0] = sender prefix
458  *  parv[1] = nickname mask list
459  *  parv[2] = additional selection flag, only 'o' for now.
460  *            and %flags to specify what fields to output
461  *            plus a ,querytype if the t flag is specified
462  *            so the final thing will be like o%tnchu,777
463  *  parv[3] = _optional_ parameter that overrides parv[1]
464  *            This can be used as "/quote who foo % :The Black Hacker
465  *            to find me, parv[3] _can_ contain spaces !.
466  */
467
468 int m_who(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
469 {
470   char *mask;           /* The mask we are looking for              */
471   char ch;                      /* Scratch char register                    */
472   struct Channel *chptr;                /* Channel to show                          */
473   struct Client *acptr;         /* Client to show                           */
474
475   int bitsel;                   /* Mask of selectors to apply               */
476   int matchsel;                 /* Wich fields the match should apply on    */
477   int counter;                  /* Query size counter,
478                                    initially used to count fields           */
479   int commas;                   /* Does our mask contain any comma ?
480                                    If so is a list..                        */
481   int fields;                   /* Mask of fields to show                   */
482   int isthere = 0;              /* When this set the user is member of chptr */
483   char *nick;                   /* Single element extracted from
484                                    the mask list                            */
485   char *p;                      /* Scratch char pointer                     */
486   char *qrt;                    /* Pointer to the query type                */
487   static char mymask[512];      /* To save the mask before corrupting it    */
488
489   /* Let's find where is our mask, and if actually contains something */
490   mask = ((parc > 1) ? parv[1] : 0);
491   if (parc > 3 && parv[3])
492     mask = parv[3];
493   if (mask && ((mask[0] == '\0') ||
494       (mask[1] == '\0' && ((mask[0] == '0') || (mask[0] == '*')))))
495     mask = 0;
496
497   /* Evaluate the flags now, we consider the second parameter 
498      as "matchFlags%fieldsToInclude,querytype"           */
499   bitsel = fields = counter = matchsel = 0;
500   qrt = 0;
501   if (parc > 2 && parv[2] && *parv[2])
502   {
503     p = parv[2];
504     while (((ch = *(p++))) && (ch != '%') && (ch != ','))
505       switch (ch)
506       {
507         case 'o':
508         case 'O':
509           bitsel |= WHOSELECT_OPER;
510           continue;
511         case 'x':
512         case 'X':
513           bitsel |= WHOSELECT_EXTRA;
514 #ifdef WPATH
515           if (IsAnOper(sptr))
516             write_log(WPATH, "# " TIME_T_FMT " %s!%s@%s WHO %s %s\n",
517                 CurrentTime, sptr->name, sptr->user->username, sptr->user->host,
518                 (BadPtr(parv[3]) ? parv[1] : parv[3]), parv[2]);
519 #endif /* WPATH */
520           continue;
521         case 'n':
522         case 'N':
523           matchsel |= WHO_FIELD_NIC;
524           continue;
525         case 'u':
526         case 'U':
527           matchsel |= WHO_FIELD_UID;
528           continue;
529         case 'h':
530         case 'H':
531           matchsel |= WHO_FIELD_HOS;
532           continue;
533         case 'i':
534         case 'I':
535           matchsel |= WHO_FIELD_NIP;
536           continue;
537         case 's':
538         case 'S':
539           matchsel |= WHO_FIELD_SER;
540           continue;
541         case 'r':
542         case 'R':
543           matchsel |= WHO_FIELD_REN;
544           continue;
545       }
546     if (ch == '%')
547       while ((ch = *p++) && (ch != ','))
548       {
549         counter++;
550         switch (ch)
551         {
552           case 'c':
553           case 'C':
554             fields |= WHO_FIELD_CHA;
555             break;
556           case 'd':
557           case 'D':
558             fields |= WHO_FIELD_DIS;
559             break;
560           case 'f':
561           case 'F':
562             fields |= WHO_FIELD_FLA;
563             break;
564           case 'h':
565           case 'H':
566             fields |= WHO_FIELD_HOS;
567             break;
568           case 'i':
569           case 'I':
570             fields |= WHO_FIELD_NIP;
571             break;
572           case 'n':
573           case 'N':
574             fields |= WHO_FIELD_NIC;
575             break;
576           case 'r':
577           case 'R':
578             fields |= WHO_FIELD_REN;
579             break;
580           case 's':
581           case 'S':
582             fields |= WHO_FIELD_SER;
583             break;
584           case 't':
585           case 'T':
586             fields |= WHO_FIELD_QTY;
587             break;
588           case 'u':
589           case 'U':
590             fields |= WHO_FIELD_UID;
591             break;
592           default:
593             break;
594         }
595       };
596     if (ch)
597       qrt = p;
598   }
599
600   if (!matchsel)
601     matchsel = WHO_FIELD_DEF;
602   if (!fields)
603     counter = 7;
604
605   if (qrt && (fields & WHO_FIELD_QTY))
606   {
607     p = qrt;
608     if (!((*p > '9') || (*p < '0')))
609       p++;
610     if (!((*p > '9') || (*p < '0')))
611       p++;
612     if (!((*p > '9') || (*p < '0')))
613       p++;
614     *p = '\0';
615   }
616   else
617     qrt = 0;
618
619   /* I'd love to add also a check on the number of matches fields per time */
620   counter = (2048 / (counter + 4));
621   if (mask && (strlen(mask) > 510))
622     mask[510] = '\0';
623   move_marker();
624   commas = (mask && strchr(mask, ','));
625
626   /* First treat mask as a list of plain nicks/channels */
627   if (mask)
628   {
629     strcpy(mymask, mask);
630     for (p = 0, nick = ircd_strtok(&p, mymask, ","); nick;
631         nick = ircd_strtok(&p, 0, ","))
632     {
633       if (IsChannelName(nick) && (chptr = FindChannel(nick)))
634       {
635         isthere = (find_channel_member(sptr, chptr) != 0);
636         if (isthere || SEE_CHANNEL(sptr, chptr, bitsel))
637         {
638           struct Membership* member;
639           for (member = chptr->members; member; member = member->next_member)
640           {
641             acptr = member->user;
642             if ((bitsel & WHOSELECT_OPER) && !(IsAnOper(acptr)))
643               continue;
644             if ((acptr != sptr) && (member->status & CHFL_ZOMBIE))
645               continue;
646             if (!(isthere || (SEE_USER(sptr, acptr, bitsel))))
647               continue;
648             if (!Process(acptr))        /* This can't be moved before other checks */
649               continue;
650             if (!(isthere || (SHOW_MORE(sptr, counter))))
651               break;
652             do_who(sptr, acptr, chptr, fields, qrt);
653           }
654         }
655       }
656       else
657       {
658         if ((acptr = FindUser(nick)) &&
659             ((!(bitsel & WHOSELECT_OPER)) || IsAnOper(acptr)) &&
660             Process(acptr) && SHOW_MORE(sptr, counter))
661         {
662           do_who(sptr, acptr, 0, fields, qrt);
663         }
664       }
665     }
666   }
667
668   /* If we didn't have any comma in the mask treat it as a
669      real mask and try to match all relevant fields */
670   if (!(commas || (counter < 1)))
671   {
672     int minlen, cset;
673     static struct in_mask imask;
674     if (mask)
675     {
676       matchcomp(mymask, &minlen, &cset, mask);
677       if (matchcompIP(&imask, mask))
678         matchsel &= ~WHO_FIELD_NIP;
679       if ((minlen > NICKLEN) || !(cset & NTL_IRCNK))
680         matchsel &= ~WHO_FIELD_NIC;
681       if ((matchsel & WHO_FIELD_SER) &&
682           ((minlen > HOSTLEN) || (!(cset & NTL_IRCHN))
683           || (!markMatchexServer(mymask, minlen))))
684         matchsel &= ~WHO_FIELD_SER;
685       if ((minlen > USERLEN) || !(cset & NTL_IRCUI))
686         matchsel &= ~WHO_FIELD_UID;
687       if ((minlen > HOSTLEN) || !(cset & NTL_IRCHN))
688         matchsel &= ~WHO_FIELD_HOS;
689     }
690
691     /* First of all loop through the clients in common channels */
692     if ((!(counter < 1)) && matchsel) {
693       struct Membership* member;
694       struct Membership* chan;
695       for (chan = sptr->user->channel; chan; chan = chan->next_channel) {
696         chptr = chan->channel;
697         for (member = chptr->members; member; member = member->next_member)
698         {
699           acptr = member->user;
700           if (!(IsUser(acptr) && Process(acptr)))
701             continue;           /* Now Process() is at the beginning, if we fail
702                                    we'll never have to show this acptr in this query */
703           if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
704             continue;
705           if ((mask) &&
706               ((!(matchsel & WHO_FIELD_NIC))
707               || matchexec(acptr->name, mymask, minlen))
708               && ((!(matchsel & WHO_FIELD_UID))
709               || matchexec(acptr->user->username, mymask, minlen))
710               && ((!(matchsel & WHO_FIELD_SER))
711               || (!(acptr->user->server->flags & FLAGS_MAP)))
712               && ((!(matchsel & WHO_FIELD_HOS))
713               || matchexec(acptr->user->host, mymask, minlen))
714               && ((!(matchsel & WHO_FIELD_REN))
715               || matchexec(acptr->info, mymask, minlen))
716               && ((!(matchsel & WHO_FIELD_NIP))
717               || ((((acptr->ip.s_addr & imask.mask.s_addr) !=
718               imask.bits.s_addr)) || (imask.fall
719               && matchexec(inet_ntoa(acptr->ip), mymask, minlen)))))
720             continue;
721           if (!SHOW_MORE(sptr, counter))
722             break;
723           do_who(sptr, acptr, chptr, fields, qrt);
724         }
725       }
726     }
727     /* Loop through all clients :-\, if we still have something to match to 
728        and we can show more clients */
729     if ((!(counter < 1)) && matchsel)
730       for (acptr = me.prev; acptr; acptr = acptr->prev)
731       {
732         if (!(IsUser(acptr) && Process(acptr)))
733           continue;
734         if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
735           continue;
736         if (!(SEE_USER(sptr, acptr, bitsel)))
737           continue;
738         if ((mask) &&
739             ((!(matchsel & WHO_FIELD_NIC))
740             || matchexec(acptr->name, mymask, minlen))
741             && ((!(matchsel & WHO_FIELD_UID))
742             || matchexec(acptr->user->username, mymask, minlen))
743             && ((!(matchsel & WHO_FIELD_SER))
744             || (!(acptr->user->server->flags & FLAGS_MAP)))
745             && ((!(matchsel & WHO_FIELD_HOS))
746             || matchexec(acptr->user->host, mymask, minlen))
747             && ((!(matchsel & WHO_FIELD_REN))
748             || matchexec(acptr->info, mymask, minlen))
749             && ((!(matchsel & WHO_FIELD_NIP))
750             || ((((acptr->ip.s_addr & imask.mask.s_addr) != imask.bits.s_addr))
751             || (imask.fall
752             && matchexec(inet_ntoa(acptr->ip), mymask, minlen)))))
753           continue;
754         if (!SHOW_MORE(sptr, counter))
755           break;
756         do_who(sptr, acptr, 0, fields, qrt);
757       }
758   }
759
760   /* Make a clean mask suitable to be sent in the "end of" */
761   if (mask && (p = strchr(mask, ' ')))
762     *p = '\0';
763   sendto_one(sptr, rpl_str(RPL_ENDOFWHO), /* XXX DEAD */
764       me.name, parv[0], BadPtr(mask) ? "*" : mask);
765
766   /* Notify the user if we decided that his query was too long */
767   if (counter < 0)
768     sendto_one(sptr, err_str(ERR_QUERYTOOLONG), me.name, parv[0], "WHO"); /* XXX DEAD */
769
770   return 0;
771 }
772 #endif /* 0 */
773