-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy paths_serv.c
3250 lines (2925 loc) · 97.9 KB
/
s_serv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************
* IRC - Internet Relay Chat, src/s_serv.c
* Copyright (C) 1990 Jarkko Oikarinen and
* University of Oulu, Computing Center
*
* See file AUTHORS in IRC package for additional names of
* the programmers.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include "nameser.h"
#include "resolv.h"
#include "dh.h"
#include "zlink.h"
#include "userban.h"
#if defined(AIX) || defined(SVR3)
#include <time.h>
#endif
#include <sys/stat.h>
#include <sys/utsname.h>
#include <fcntl.h>
#include "h.h"
#if defined( HAVE_STRING_H )
#include <string.h>
#else
/* older unices don't have strchr/strrchr .. help them out */
#include <strings.h>
#undef strchr
#define strchr index
#endif
#include "fdlist.h"
#include "throttle.h"
#include "clones.h"
#include "memcount.h"
#include <zlib.h>
static char buf[BUFSIZE];
extern int rehashed;
extern int forked;
extern int uhm_type;
extern int uhm_umodeh;
/* external variables */
/* external functions */
extern char *smalldate(time_t); /* defined in s_misc.c */
extern void outofmemory(void); /* defined in list.c */
extern void s_die(void);
extern int match(char *, char *); /* defined in match.c */
extern char *engine_name(); /* defined in socketengine_*.c */
extern struct FlagList xflags_list[]; /* for m_check() */
/* Local function prototypes */
int send_motd(aClient *, aClient *, int, char **);
void read_motd(char *);
void read_shortmotd(char *);
char motd_last_changed_date[MAX_DATE_STRING]; /* enough room for date */
void fakeserver_list(aClient *);
int fakelinkscontrol(int, char **);
void fakelinkserver_update(char *, char *);
void fakeserver_sendserver(aClient *);
int is_luserslocked();
void send_fake_users(aClient *);
void send_fake_lusers(aClient *);
void fakelusers_sendlock(aClient *);
int local_rehash(aClient *, aClient *, char *, char *);
/*
* m_functions execute protocol messages on this server: *
*
* cptr:
** always NON-NULL, pointing to a *LOCAL* client
** structure (with an open socket connected!). This
** is the physical socket where the message originated (or
** which caused the m_function to be executed--some
** m_functions may call others...).
*
* sptr:
** the source of the message, defined by the
** prefix part of the message if present. If not or
** prefix not found, then sptr==cptr.
*
* *Always* true (if 'parse' and others are working correct):
*
* 1) sptr->from == cptr (note: cptr->from == cptr)
*
* 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
* cannot be a local connection, unless it's actually cptr!).
*
* MyConnect(x) should probably be defined as (x == x->from) --msa
*
* parc:
** number of variable parameter strings (if zero,
** parv is allowed to be NULL)
*
* parv:
** a NULL terminated list of parameter pointers,
*** parv[0], sender (prefix string), if not present his points to
*** an empty string.
*
** [parc-1]:
*** pointers to additional parameters
*** parv[parc] == NULL, *always*
*
* note: it is guaranteed that parv[0]..parv[parc-1] are all
* non-NULL pointers.
*/
/*
* * m_version
* parv[0] = sender prefix
* parv[1] = remote server
*/
int
m_version(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
if (hunt_server(cptr, sptr, ":%s VERSION :%s", 1, parc, parv) ==
HUNTED_ISME)
send_rplversion(sptr);
return 0;
}
/*
* m_squit
* there are two types of squits: those going downstream (to the target server)
* and those going back upstream (from the target server).
* previously, it wasn't necessary to distinguish between these two types of
* squits because they neatly echoed back all of the QUIT messages during
* an squit. This, however, is no longer practical.
*
* To clarify here, DOWNSTREAM signifies an SQUIT heading towards the target
* server UPSTREAM signifies an SQUIT which has successfully completed,
* heading out everywhere.
*
* acptr is the server being squitted.
* a DOWNSTREAM squit is where the notice did not come from acptr->from.
* an UPSTREAM squit is where the notice DID come from acptr->from.
*
* parv[0] = sender prefix
* parv[1] = server name
* parv[2] = comment
*/
int
m_squit(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
aConnect *aconn;
char *server;
aClient *acptr;
char *comment = (parc > 2) ? parv[2] : sptr->name;
if (!IsPrivileged(sptr))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
return 0;
}
if (parc > 1)
{
server = parv[1];
/* To accomodate host masking, a squit for a masked server
* name is expanded if the incoming mask is the same as the
* server name for that link to the name of link.
*/
while ((*server == '*') && IsServer(cptr))
{
aconn = cptr->serv->aconn;
if (!aconn)
break;
if (!mycmp(server, my_name_for_link(me.name, aconn)))
server = cptr->name;
break; /* WARNING is normal here */
/* NOTREACHED */
}
/*
* The following allows wild cards in SQUIT. Only useful when
* the command is issued by an oper.
*/
for (acptr = client; (acptr = next_client(acptr, server));
acptr = acptr->next)
if (IsServer(acptr) || IsMe(acptr))
break;
if (acptr && IsMe(acptr))
{
acptr = cptr;
server = cptr->name;
}
}
else
{
/* This is actually protocol error. But, well, closing the
* link is very proper answer to that...
*/
server = cptr->name;
acptr = cptr;
}
if (!acptr)
{
sendto_one(sptr, err_str(ERR_NOSUCHSERVER),
me.name, parv[0], server);
return 0;
}
if (MyClient(sptr) && ((!OPCanGRoute(sptr) && !MyConnect(acptr)) ||
(!OPCanLRoute(sptr) && MyConnect(acptr))))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
return 0;
}
/* If the server is mine, we don't care about upstream or downstream,
just kill it and do the notice. */
if (MyConnect(acptr))
{
sendto_gnotice("from %s: Received SQUIT %s from %s (%s)",
me.name, acptr->name, get_client_name(sptr, HIDEME),
comment);
sendto_serv_butone(NULL, ":%s GNOTICE :Received SQUIT %s from %s (%s)",
me.name, server, get_client_name(sptr, HIDEME),
comment);
#if defined(USE_SYSLOG) && defined(SYSLOG_SQUIT)
syslog(LOG_DEBUG, "SQUIT From %s : %s (%s)",
parv[0], server, comment);
#endif
/* I am originating this squit! Not cptr! */
/* ack, but if cptr is squitting itself.. */
if(cptr == sptr)
{
exit_client(&me, acptr, sptr, comment);
return FLUSH_BUFFER; /* kludge */
}
return exit_client(&me, acptr, sptr, comment);
}
/* the server is not connected to me. Determine whether this is an upstream
or downstream squit */
if(sptr->from == acptr->from) /* upstream */
{
sendto_realops_lev(DEBUG_LEV,
"Exiting server %s due to upstream squit by %s [%s]",
acptr->name, sptr->name, comment);
return exit_client(cptr, acptr, sptr, comment);
}
/* fallthrough: downstream */
if(!(IsUnconnect(acptr->from))) /* downstream not unconnect capable */
{
sendto_realops_lev(DEBUG_LEV,
"Exiting server %s due to non-unconnect server %s [%s]",
acptr->name, acptr->from->name, comment);
return exit_client(&me, acptr, sptr, comment);
}
sendto_realops_lev(DEBUG_LEV, "Passing along SQUIT for %s by %s [%s]",
acptr->name, sptr->name, comment);
sendto_one(acptr->from, ":%s SQUIT %s :%s", parv[0], acptr->name, comment);
return 0;
}
/*
* m_svinfo
* parv[0] = sender prefix
* parv[1] = TS_CURRENT for the server
* parv[2] = TS_MIN for the server
* parv[3] = server is standalone or connected to non-TS only
* parv[4] = server's idea of UTC time
*/
int m_svinfo(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
time_t deltat, tmptime, theirtime;
if (!IsServer(sptr) || !MyConnect(sptr))
return 0;
if(parc == 2 && mycmp(parv[1], "ZIP") == 0)
{
SetZipIn(sptr);
sptr->serv->zip_in = zip_create_input_session();
sendto_gnotice("from %s: Input from %s is now compressed",
me.name, get_client_name(sptr, HIDEME));
sendto_serv_butone(sptr,
":%s GNOTICE :Input from %s is now compressed",
me.name, get_client_name(sptr, HIDEME));
return ZIP_NEXT_BUFFER;
}
if(parc < 5 || !DoesTS(sptr))
return 0;
if (TS_CURRENT < atoi(parv[2]) || atoi(parv[1]) < TS_MIN)
{
/* a server with the wrong TS version connected; since we're
* TS_ONLY we can't fall back to the non-TS protocol so we drop
* the link -orabidoo
*/
sendto_ops("Link %s dropped, wrong TS protocol version (%s,%s)",
get_client_name(sptr, HIDEME), parv[1], parv[2]);
return exit_client(sptr, sptr, sptr, "Incompatible TS version");
}
tmptime = time(NULL);
theirtime = atol(parv[4]);
deltat = abs(theirtime - tmptime);
if (deltat > tsmaxdelta)
{
sendto_gnotice("from %s: Link %s dropped, excessive TS delta (my "
"TS=%ld, their TS=%ld, delta=%ld)",
me.name, get_client_name(sptr, HIDEME),
(long)tmptime, (long)theirtime, (long)deltat);
sendto_serv_butone(sptr, ":%s GNOTICE :Link %s dropped, excessive "
"TS delta (delta=%ld)",
me.name, get_client_name(sptr, HIDEME),
(long)deltat);
return exit_client(sptr, sptr, sptr, "Excessive TS delta");
}
if (deltat > tswarndelta)
{
sendto_realops("Link %s notable TS delta (my TS=%ld, their TS=%ld, "
"delta=%ld)", get_client_name(sptr, HIDEME),
(long)tmptime, (long)theirtime, (long)deltat);
}
return 0;
}
/*
* m_burst
* parv[0] = sender prefix
* parv[1] = SendQ if an EOB
*/
int
m_burst(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
if (!IsServer(sptr) || sptr != cptr || parc > 2 || !IsBurst(sptr))
return 0;
if (parc == 2) { /* This is an EOB */
sptr->flags &= ~(FLAGS_EOBRECV);
if (sptr->flags & (FLAGS_SOBSENT|FLAGS_BURST)) return 0;
/* we've already sent our EOB.. we synched first
* no need to check IsBurst because we shouldn't receive a BURST if
* they're not BURST capab
*/
sendto_gnotice("from %s: synch to %s in %ld %s at %s sendq", me.name,
*parv, (long)(timeofday-sptr->firsttime),
(timeofday-sptr->firsttime)==1?"sec":"secs", parv[1]);
sendto_serv_butone(NULL,
":%s GNOTICE :synch to %s in %ld %s at %s sendq",
me.name, sptr->name, (long)(timeofday-sptr->firsttime),
(timeofday-sptr->firsttime)==1?"sec":"secs",
parv[1]);
}
else
{
sptr->flags |= FLAGS_EOBRECV;
}
return 0;
}
/*
* * m_info
* parv[0] = sender prefix
* parv[1] = servername
*/
int
m_info(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
char **text = infotext;
static time_t last_used = 0L;
struct utsname uninfo;
if (hunt_server(cptr,sptr,":%s INFO :%s",1,parc,parv) == HUNTED_ISME)
{
if(!IsULine(sptr) && !IsServer(sptr))
{
sendto_realops_lev(SPY_LEV, "INFO requested by %s (%s@%s) [%s]",
sptr->name, sptr->user->username, sptr->user->host,
sptr->user->server);
if (!IsAnOper(sptr))
{
if (IsSquelch(sptr)) {
sendto_one(sptr, rpl_str(RPL_ENDOFINFO), me.name, parv[0]);
return 0;
}
if (!MyConnect(sptr))
return 0;
if ((last_used + MOTD_WAIT) > NOW)
return 0;
else
last_used = NOW;
}
}
while (*text)
sendto_one(sptr, rpl_str(RPL_INFO),
me.name, parv[0], *text++);
if(IsAdmin(sptr) || IsULine(sptr))
{
uname(&uninfo);
sendto_one(sptr, ":%s %d %s :OS: %s %s %s %s",
me.name, RPL_INFO, parv[0], uninfo.sysname,
uninfo.release, uninfo.machine, uninfo.version);
sendto_one(sptr, ":%s %d %s :Socket Engine Type: %s", me.name,
RPL_INFO, parv[0], engine_name());
#ifdef USE_SSL
sendto_one(sptr, ":%s %d %s :OpenSSL Version: %s", me.name,
RPL_INFO, parv[0], SSLeay_version(SSLEAY_VERSION));
#endif
sendto_one(sptr, ":%s %d %s :zlib version: %s", me.name,
RPL_INFO, parv[0], ZLIB_VERSION);
sendto_one(sptr, ":%s %d %s :FD_SETSIZE=%d WRITEV_IOV=%d "
"MAXCONNECTIONS=%d MAX_BUFFER=%d MAXCLIENTS=%d uhm_type=%d uhm_umodeh=%d",
me.name, RPL_INFO, parv[0], FD_SETSIZE,
#ifdef WRITEV_IOV
WRITEV_IOV,
#else
0,
#endif
MAXCONNECTIONS, MAX_BUFFER, MAXCLIENTS, uhm_type, uhm_umodeh);
}
sendto_one(sptr, rpl_str(RPL_INFO), me.name, parv[0], "");
/* I am -definately- going to come up with a replacement for this! */
/* you didnt, so i removed it.. kinda stupid anyway. -epi */
sendto_one(sptr,
":%s %d %s :Birth Date: %s, compile #%s",
me.name, RPL_INFO, parv[0], creation, generation);
sendto_one(sptr, ":%s %d %s :On-line since %s",
me.name, RPL_INFO, parv[0],
myctime(me.firsttime));
sendto_one(sptr, rpl_str(RPL_ENDOFINFO), me.name, parv[0]);
}
return 0;
}
/*
* * m_links
* parv[0] = sender prefix
* parv[1] = servername mask
* or
* parv[0] = sender prefix
* parv[1] = server to query
* parv[2] = servername mask
*/
int
m_links(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
char *mask;
aClient *acptr;
char clean_mask[(2 * HOSTLEN) + 1];
char *s;
char *d;
int n;
/* reject non-local requests */
if (IsServer(sptr) || (!IsAnOper(sptr) && !MyConnect(sptr)))
return 0;
mask = (parc < 2) ? NULL : parv[1];
/*
* * sigh* Before the kiddies find this new and exciting way of
* * annoying opers, lets clean up what is sent to all opers
* * -Dianora
*/
if (mask)
{ /* only necessary if there is a mask */
s = mask;
d = clean_mask;
n = (2 * HOSTLEN) - 2;
while (*s && n > 0)
{
/* Is it a control character? */
if ((unsigned char) *s < (unsigned char) ' ')
{
*d++ = '^';
/* turn it into a printable */
*d++ = (char) ((unsigned char)*s + 0x40);
s++;
n -= 2;
}
else if ((unsigned char) *s > (unsigned char) '~')
{
*d++ = '.';
s++;
n--;
}
else
{
*d++ = *s++;
n--;
}
}
*d = '\0';
}
if (MyConnect(sptr))
sendto_realops_lev(SPY_LEV,
"LINKS %s requested by %s (%s@%s) [%s]",
mask ? clean_mask : "all",
sptr->name, sptr->user->username,
sptr->user->host, sptr->user->server);
if(!(confopts & FLAGS_SHOWLINKS) && !IsAnOper(sptr))
fakeserver_list(sptr);
else
for (acptr = client, (void) collapse(mask); acptr; acptr = acptr->next)
{
if (!IsServer(acptr) && !IsMe(acptr))
continue;
if (!BadPtr(mask) && match(mask, acptr->name))
continue;
#ifdef HIDEULINEDSERVS
if (!IsOper(sptr) && IsULine(acptr))
continue;
#endif
sendto_one(sptr, rpl_str(RPL_LINKS),
me.name, parv[0], acptr->name, acptr->serv->up,
acptr->hopcount, (acptr->info[0] ? acptr->info :
"(Unknown Location)"));
}
sendto_one(sptr, rpl_str(RPL_ENDOFLINKS), me.name, parv[0],
BadPtr(mask) ? "*" : clean_mask);
return 0;
}
/*
* * m_users
* parv[0] = sender prefix
* parv[1] = servername
*/
int
m_users(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
if (hunt_server(cptr, sptr, ":%s USERS :%s", 1, parc, parv) == HUNTED_ISME)
{
if(is_luserslocked())
{
send_fake_users(sptr);
return 0;
}
/* No one uses this any more... so lets remap it.. -Taner */
sendto_one(sptr, rpl_str(RPL_LOCALUSERS), me.name, parv[0],
Count.local, Count.max_loc);
sendto_one(sptr, rpl_str(RPL_GLOBALUSERS), me.name, parv[0],
Count.total, Count.max_tot);
}
return 0;
}
/*
* * Note: At least at protocol level ERROR has only one parameter,
* although this is called internally from other functions --msa
*
* parv[0] = sender prefix
* parv[*] = parameters
*/
int
m_error(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
char *para;
para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
Debug((DEBUG_ERROR, "Received ERROR message from %s: %s",
sptr->name, para));
/*
* * Ignore error messages generated by normal user clients
* (because ill-behaving user clients would flood opers screen
* otherwise). Pass ERROR's from other sources to the local
* operator...
*/
if (IsPerson(cptr) || IsUnknown(cptr))
return 0;
sendto_serv_butone_super(cptr, 0, ":%s GNOTICE :Error -- %s", parv[0], para);
sendto_gnotice("from %s: Error -- %s", parv[0], para);
return 0;
}
/*
* m_help
* parv[0] = sender prefix
*
* Forward help requests to HelpServ if defined, and is invoked
* by non-opers, otherwise sends opers.txt to opers (if present),
* or sends a big list of commands to non-opers (and opers if
* opers.txt is not present). -srd
*/
int
m_help(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
int i;
aMotd *helpfile_ptr;
static time_t last_used = 0L;
#ifdef HELP_FORWARD_HS
if (!IsAnOper(sptr))
{
if (parc < 2 || *parv[1] == '\0')
{
sendto_one(sptr, ":%s NOTICE %s :For a list of help topics, type "
"/%s %s", me.name, sptr->name, HELPSERV, DEF_HELP_CMD);
return -1;
}
return m_aliased(cptr, sptr, parc, parv, &aliastab[AII_HS]);
return 0;
}
#endif
if (!IsAnOper(sptr))
{
/* reject non local requests */
if ((last_used + MOTD_WAIT) > NOW)
return 0;
else
last_used = NOW;
}
if (!IsAnOper(sptr) || (helpfile == (aMotd *) NULL))
{
for (i = 0; msgtab[i].cmd; i++)
sendto_one(sptr, ":%s NOTICE %s :%s",
me.name, parv[0], msgtab[i].cmd);
return 0;
}
helpfile_ptr = helpfile;
while (helpfile_ptr)
{
sendto_one(sptr,
":%s NOTICE %s :%s",
me.name, parv[0], helpfile_ptr->line);
helpfile_ptr = helpfile_ptr->next;
}
return 0;
}
/*
* parv[0] = sender parv[1] = host/server mask.
* parv[2] = server to query
*
* 199970918 JRL hacked to ignore parv[1] completely and require parc > 3
* to cause a force
*
* Now if parv[1] is anything other than *, it forces a recount.
* -Quension [May 2005]
*/
int
m_lusers(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
int send_lusers(aClient *, aClient *, int, char **);
if (parc > 2)
{
if (hunt_server(cptr, sptr, ":%s LUSERS %s :%s", 2, parc, parv) !=
HUNTED_ISME)
return 0;
}
if(!IsAnOper(sptr) && is_luserslocked())
{
send_fake_lusers(sptr);
return 0;
}
return send_lusers(cptr,sptr,parc,parv);
}
/*
* send_lusers
* parv[0] = sender
* parv[1] = anything but "*" to force a recount
* parv[2] = server to query
*/
int send_lusers(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
/* forced recount */
if (IsAnOper(sptr) && (parc > 1) && (*parv[1] != '*'))
{
int s_count = 0;
int c_count = 0;
int u_count = 0;
int i_count = 0;
int o_count = 0;
int m_client = 0;
int m_server = 0;
int m_ulined = 0;
aClient *acptr;
for (acptr = client; acptr; acptr = acptr->next)
{
switch (acptr->status)
{
case STAT_SERVER:
if (MyConnect(acptr))
{
m_server++;
if(IsULine(acptr))
m_ulined++;
}
case STAT_ME:
s_count++;
break;
case STAT_CLIENT:
if (IsAnOper(acptr))
o_count++;
#ifdef SHOW_INVISIBLE_LUSERS
if (MyConnect(acptr))
m_client++;
if (!IsInvisible(acptr))
c_count++;
else
i_count++;
#else
if (MyConnect(acptr))
{
if (IsInvisible(acptr))
{
if (IsAnOper(sptr))
m_client++;
}
else
m_client++;
}
if (!IsInvisible(acptr))
c_count++;
else
i_count++;
#endif
break;
default:
u_count++;
break;
}
}
/* sanity check */
if (m_server != Count.myserver)
{
sendto_realops_lev(DEBUG_LEV, "Local server count off by %d",
Count.myserver - m_server);
Count.myserver = m_server;
}
if (m_ulined != Count.myulined)
{
sendto_realops_lev(DEBUG_LEV, "Local superserver count off by %d",
Count.myulined - m_ulined);
Count.myulined = m_ulined;
}
if (s_count != Count.server)
{
sendto_realops_lev(DEBUG_LEV, "Server count off by %d",
Count.server - s_count);
Count.server = s_count;
}
if (i_count != Count.invisi)
{
sendto_realops_lev(DEBUG_LEV, "Invisible client count off by %d",
Count.invisi - i_count);
Count.invisi = i_count;
}
if ((c_count + i_count) != Count.total)
{
sendto_realops_lev(DEBUG_LEV, "Total client count off by %d",
Count.total - (c_count + i_count));
Count.total = c_count + i_count;
}
if (m_client != Count.local)
{
sendto_realops_lev(DEBUG_LEV, "Local client count off by %d",
Count.local - m_client);
Count.local = m_client;
}
if (o_count != Count.oper)
{
sendto_realops_lev(DEBUG_LEV, "Oper count off by %d",
Count.oper - o_count);
Count.oper = o_count;
}
if (u_count != Count.unknown)
{
sendto_realops_lev(DEBUG_LEV, "Unknown connection count off by %d",
Count.unknown - u_count);
Count.unknown = u_count;
}
} /* Recount loop */
/* save stats */
if ((timeofday - last_stat_save) > 3600)
{
FILE *fp;
char tmp[PATH_MAX];
last_stat_save = timeofday;
ircsprintf(tmp, "%s/.maxclients", dpath);
fp = fopen(tmp, "w");
if (fp != NULL)
{
fprintf(fp, "%d %d %li %li %li %ld %ld %ld %ld", Count.max_loc,
Count.max_tot, Count.weekly, Count.monthly,
Count.yearly, Count.start, Count.week, Count.month,
Count.year);
fclose(fp);
sendto_realops_lev(DEBUG_LEV, "Saved maxclient statistics");
}
}
#ifndef SHOW_INVISIBLE_LUSERS
if (IsAnOper(sptr) && Count.invisi)
#endif
sendto_one(sptr, rpl_str(RPL_LUSERCLIENT), me.name, parv[0],
Count.total - Count.invisi, Count.invisi, Count.server);
#ifndef SHOW_INVISIBLE_LUSERS
else
sendto_one(sptr,
":%s %d %s :There are %d users on %d servers", me.name,
RPL_LUSERCLIENT, parv[0], Count.total - Count.invisi,
Count.server);
#endif
if (Count.oper)
sendto_one(sptr, rpl_str(RPL_LUSEROP), me.name, parv[0], Count.oper);
if (IsAnOper(sptr) && Count.unknown)
sendto_one(sptr, rpl_str(RPL_LUSERUNKNOWN), me.name, parv[0],
Count.unknown);
/* This should be ok */
if (Count.chan > 0)
sendto_one(sptr, rpl_str(RPL_LUSERCHANNELS),
me.name, parv[0], Count.chan);
sendto_one(sptr, rpl_str(RPL_LUSERME),
#ifdef HIDEULINEDSERVS
me.name, parv[0], Count.local,
IsOper(sptr) ? Count.myserver : Count.myserver - Count.myulined);
#else
me.name, parv[0], Count.local, Count.myserver);
#endif
sendto_one(sptr, rpl_str(RPL_LOCALUSERS), me.name, parv[0],
Count.local, Count.max_loc);
sendto_one(sptr, rpl_str(RPL_GLOBALUSERS), me.name, parv[0],
Count.total, Count.max_tot);
return 0;
}
/***********************************************************************
* m_connect() - Added by Jto 11 Feb 1989
***********************************************************************/
/*
* * m_connect
* parv[0] = sender prefix
* parv[1] = servername
* parv[2] = port number
* parv[3] = remote server
*/
int
m_connect(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
int port, tmpport, retval;
aConnect *aconn;
aClient *acptr;
if (!IsPrivileged(sptr))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
return -1;
}
if ((MyClient(sptr) && !OPCanGRoute(sptr) && parc > 3) ||
(MyClient(sptr) && !OPCanLRoute(sptr) && parc <= 3))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
return 0;
}
if (hunt_server(cptr, sptr, ":%s CONNECT %s %s :%s",
3, parc, parv) != HUNTED_ISME)
return 0;
if (parc < 2 || *parv[1] == '\0')
{
sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS),
me.name, parv[0], "CONNECT");
return -1;
}
if ((acptr = find_server(parv[1], NULL)))
{
sendto_one(sptr, ":%s NOTICE %s :Connect: Server %s %s %s.",
me.name, parv[0], parv[1], "already exists from",
acptr->from->name);
return 0;
}
if (!(aconn = find_aConnect(parv[1])))
{
sendto_one(sptr, ":%s NOTICE %s :Connect: No Connect block found for %s.",
me.name, parv[0], parv[1]);
return 0;
}
/*
* * Get port number from user, if given. If not specified, use
* the default form configuration structure. If missing from
* there, then use the precompiled default.
*/
tmpport = port = aconn->port;
if (parc > 2 && !BadPtr(parv[2]))
{
if ((port = atoi(parv[2])) <= 0)
{
sendto_one(sptr,
"NOTICE %s :Connect: Illegal port number",
parv[0]);
return 0;
}
}
else if (port <= 0 && (port = PORTNUM) <= 0)
{
sendto_one(sptr, ":%s NOTICE %s :Connect: missing port number",
me.name, parv[0]);
return 0;
}
/*
* * Notify all operators about remote connect requests
* Let's notify about local connects, too. - lucas
* sendto_ops_butone -> sendto_serv_butone(), like in df. -mjs
*/
sendto_gnotice("from %s: %s CONNECT %s %s from %s",
me.name, IsAnOper(cptr) ? "Local" : "Remote",
parv[1], parv[2] ? parv[2] : "",
sptr->name);
sendto_serv_butone(NULL, ":%s GNOTICE :%s CONNECT %s %s from %s",
me.name, IsAnOper(cptr) ? "Local" : "Remote",
parv[1], parv[2] ? parv[2] : "",
sptr->name);
#if defined(USE_SYSLOG) && defined(SYSLOG_CONNECT)
syslog(LOG_DEBUG, "CONNECT From %s : %s %s", parv[0], parv[1],
parv[2] ? parv[2] : "");
#endif
aconn->port = port;
switch (retval = connect_server(aconn, sptr, NULL))
{
case 0:
sendto_one(sptr, ":%s NOTICE %s :*** Connecting to %s.",
me.name, parv[0], aconn->name);
break;