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