-
Notifications
You must be signed in to change notification settings - Fork 0
/
operserv.c
2323 lines (2125 loc) · 58.1 KB
/
operserv.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
/* OperServ functions.
*
* Magick IRC Services are copyright (c) 1996-1998 Preston A. Elder.
* E-mail: <prez@magick.tm> IRC: PreZ@RelicNet
* Originally based on EsperNet services (c) 1996-1998 Andy Church
* This program is free but copyrighted software; see the file COPYING for
* details.
*/
#include "services.h"
typedef struct
{
int what;
char *name;
}
MessageName;
static MessageName messagename[] =
{
{M_LOGON, "Logon"},
{M_OPER, "Oper"},
{-1}
};
char *override_level[] =
{
"Disabled",
"All IRC Operator",
"\"low\" Levelled",
"All Services Operator",
"\"high\" Levelled",
"All Services Admin",
NULL
};
#include "os-help.c"
/* Nick for OperServ */
char s_OperServ[NICKMAX];
char akill_db[512];
char clone_db[512];
char sop_db[512];
char message_db[512];
/* Nick for sending global notices */
char s_GlobalNoticer[NICKMAX];
/* Perm nick for OperServ clone */
char s_Outlet[NICKMAX];
int akill_expire;
int clones_allowed;
char def_clone_reason[512];
int nsop = 0;
int sop_size = 0;
Sop *sops = NULL;
int nmessage = 0;
int message_size = 0;
Message *messages = NULL;
int nakill = 0;
int akill_size = 0;
Akill *akills = NULL;
int nclone = 0;
int clone_size = 0;
Allow *clones = NULL;
Clone *clonelist = NULL;
static void do_sop (const char *source);
static void do_sop_add (const char *source);
static void do_sop_del (const char *source);
static void do_sop_list (const char *source);
static void do_logonmsg (const char *source);
static void do_opermsg (const char *source);
static void do_logonmsg_add (const char *source);
static void do_opermsg_add (const char *source);
static void do_message_add (const char *source, short type);
static void do_logonmsg_del (const char *source);
static void do_opermsg_del (const char *source);
static void do_message_del (const char *source, short type);
static void do_logonmsg_list (const char *source);
static void do_opermsg_list (const char *source);
static void do_message_list (const char *source, short type);
static int add_message (const char *source, const char *text, short type);
static int del_message (int num, short type);
static void do_akill (const char *source);
static void do_pakill (const char *source);
static void do_akill_add (const char *source);
static void do_pakill_add (const char *source);
static void do_akill_addfunc (const char *source, int call);
static void do_akill_del (const char *source);
static void do_pakill_del (const char *source);
static void do_akill_delfunc (const char *source, int call);
static void do_akill_list (const char *source);
static int add_akill (const char *mask, const char *reason, const char *who, int call);
static int is_on_akill (const char *mask);
static void do_clone (const char *source);
static void do_clone_add (const char *source);
static void do_clone_del (const char *source);
static void do_clone_list (const char *source);
static void add_clone (const char *host, int amount, const char *reason, const char *who);
static Clone *findclone (const char *host);
static int is_on_clone (char *host);
static void do_mode (const char *source);
static void do_os_kick (const char *source);
static void do_help (const char *source);
static void do_global (const char *source);
static void do_settings (const char *source);
static void do_breakdown (const char *source);
static void do_sendpings (const char *source);
static void do_stats (const char *source);
#ifdef DAL_SERV
static void do_qline (const char *source);
static void do_unqline (const char *source);
static void do_noop (const char *source);
static void do_os_kill (const char *source);
#endif
static void do_ignore (const char *source);
static void do_update (const char *source);
static void do_os_quit (const char *source);
static void do_shutdown (const char *source);
static void do_reload (const char *source);
static void do_jupe (const char *source);
static void do_off (const char *source);
static void do_on (const char *source);
static void do_raw (const char *source);
static char *getmsgname (short type);
static void
do_identify (const char *source)
{
do_real_identify (s_OperServ, source);
}
/*************************************************************************/
/* Main OperServ routine. */
void
operserv (const char *source, char *buf)
{
char *cmd;
char *s;
write_log ("%s: %s: %s", s_OperServ, source, buf);
cmd = strtok (buf, " ");
if (!(runflags & RUN_MODE) && stricmp (cmd, "ON") != 0 && !match_wild_nocase ("ID*", cmd))
{
if (offreason)
notice (s_OperServ, source, SERVICES_OFF_REASON, offreason);
else
notice (s_OperServ, source, SERVICES_OFF);
return;
}
if (!cmd)
return;
if (stricmp (cmd, "\1PING") == 0)
{
if (!(s = strtok (NULL, "")))
s = "\1";
notice (s_OperServ, source, "\1PING %s", s);
}
else if (match_wild_nocase ("USER*LIST", cmd))
{
s = strtok (NULL, " ");
send_user_list (s_OperServ, source, s);
}
else if (match_wild_nocase ("*MASK*LIST", cmd))
{
s = strtok (NULL, " ");
send_usermask_list (s_OperServ, source, s);
}
else if (match_wild_nocase ("U*MODE*LIST", cmd))
{
s = strtok (NULL, " ");
send_usermode_list (s_OperServ, source, s);
}
else if (match_wild_nocase ("CHAN*LIST", cmd))
{
s = strtok (NULL, " ");
send_channel_list (s_OperServ, source, s);
}
else if (match_wild_nocase ("C*MODE*LIST", cmd))
{
s = strtok (NULL, " ");
send_chanmode_list (s_OperServ, source, s);
}
else
{
Hash *command, hash_table[] =
{
{"HELP", H_OPER, do_help},
{"*MODE", H_OPER, do_mode},
{"KICK*", H_OPER, do_os_kick},
{"STAT*", H_OPER, do_stats},
{"SET*", H_OPER, do_settings},
{"BREAKDOWN", H_OPER, do_breakdown},
{"COUNT*", H_OPER, do_breakdown},
{"ID*", H_OPER, do_identify},
{"GLOB*", H_OPER, do_global},
{"A*KILL", H_OPER, do_akill},
{"P*A*KILL", H_SOP, do_pakill},
{"IGN*", H_SOP, do_ignore},
{"JUPE*", H_SOP, do_jupe},
{"FAKE*", H_SOP, do_jupe},
{"UPDATE*", H_SOP, do_update},
{"WRITE*", H_SOP, do_update},
{"SAVE*", H_SOP, do_update},
{"CLONE*", H_SOP, do_clone},
{"LOG*MESS*", H_SOP, do_logonmsg},
{"LOG*MSG*", H_SOP, do_logonmsg},
/* { "*PING*", H_SOP, do_sendpings }, */
{"OP*MESS*", H_ADMIN, do_opermsg},
{"OP*MSG*", H_ADMIN, do_opermsg},
{"OFF", H_ADMIN, do_off},
{"ON", H_ADMIN, do_on},
{"RAW", H_ADMIN, do_raw},
{"QUOTE", H_ADMIN, do_raw},
{"SHUTDOWN", H_ADMIN, do_shutdown},
{"DIE", H_ADMIN, do_shutdown},
{"END", H_ADMIN, do_shutdown},
{"RELOAD", H_ADMIN, do_reload},
{"*HUP", H_ADMIN, do_reload},
{"RESTART", H_ADMIN, do_reload},
{"QUIT", H_ADMIN, do_os_quit},
{"*MURDER", H_ADMIN, do_os_quit},
{"S*OP", H_ADMIN, do_sop},
{"OPER*", H_ADMIN, do_sop},
#ifdef DAL_SERV
{"QLINE", H_OPER, do_qline},
{"UNQLINE", H_OPER, do_unqline},
{"KILL*", H_SOP, do_os_kill},
{"N*OP*", H_ADMIN, do_noop},
#endif
{NULL}
};
if (command = get_hash (source, cmd, hash_table))
{
if((nickserv_on==FALSE&&command->process==do_identify)
||(devnull_on==FALSE&&command->process==do_ignore)
||(globalnoticer_on==FALSE&&(command->process==do_global||command->process==do_logonmsg||command->process==do_opermsg))
||(akill_on==FALSE&&(command->process==do_akill||command->process==do_pakill))
||(clones_on==FALSE&&command->process==do_clone)
)
notice (s_OperServ, source, ERR_UNKNOWN_COMMAND, cmd, s_OperServ);
else
(*command->process) (source);
}
else
notice (s_OperServ, source, ERR_UNKNOWN_COMMAND, cmd, s_OperServ);
}
}
static void
do_mode (const char *source)
{
Channel *c;
User *u;
char l[16];
char *chan = strtok (NULL, " ");
char *serv = strtok (NULL, " ");
char *s = strtok (NULL, "");
if (!chan)
return;
if (validchan(chan))
{
if (!(c = findchan (chan)))
return;
else if (!serv)
{
snprintf (l, sizeof (l), " %d", c->limit);
notice (s_OperServ, source, "%s +%s%s%s%s%s", c->name, c->mode,
(c->limit) ? " " : "",
(c->limit) ? l : "",
(c->key) ? " " : "",
(c->key) ? c->key : "");
}
else if (s)
change_cmode (s_OperServ, c->name, serv, s);
else
change_cmode (s_OperServ, c->name, serv, "");
}
else if (!(u = finduser (chan)))
{
return;
}
else if (!serv)
notice (s_OperServ, source, "%s +%s", u->nick, u->mode);
#ifdef DAL_SERV
else if (is_services_op (source))
{
char *av[2];
av[0] = sstrdup (u->nick);
av[1] = sstrdup (serv);
send_cmd (s_OperServ, "SVSMODE %s %s", u->nick, serv);
do_svumode (source, 2, av);
free (av[0]);
free (av[1]);
}
#endif
}
static void
do_os_kick (const char *source)
{
char *chan = strtok (NULL, " ");
char *nick = strtok (NULL, " ");
char *s = strtok (NULL, "");
if (!s || !findchan (chan) || !finduser (nick))
return;
else
{
char *st;
st=smalloc(strlen (s) + strlen (source) + 4);
snprintf (st, strlen (s) + strlen (source) + 4, "%s (%s)", source, s);
kick_user (s_OperServ, chan, finduser (nick)->nick, st);
free(st);
}
}
static void
do_help (const char *source)
{
char *cmd = strtok (NULL, " ");
if (!cmd)
{
notice_list (s_OperServ, source, os_help);
if (is_services_op (source))
notice_list (s_OperServ, source, os_sop_help);
if (is_services_admin (source))
notice_list (s_OperServ, source, os_admin_help);
notice_list (s_OperServ, source, os_end_help);
}
else if (match_wild_nocase ("GLOB*", cmd) && globalnoticer_on==TRUE)
{
/* Information varies, so we need to do it manually. */
notice (s_OperServ, source, "Syntax: GLOBAL \37message\37");
notice (s_OperServ, source, "");
notice (s_OperServ, source,
"Allows IRCops to send messages to all users on the");
notice (s_OperServ, source,
"network. The message will be sent from the nick");
notice (s_OperServ, source, "\2%s\2.", s_GlobalNoticer);
}
else
{
Hash_HELP *command, hash_table[] =
{
{"*MODE", H_OPER, mode_help},
{"USER*LIST", H_OPER, userlist_help},
{"*MASK*LIST", H_OPER, masklist_help},
{"CHAN*LIST", H_OPER, chanlist_help},
{"KICK", H_OPER, kick_help},
{"STAT*", H_OPER, stats_help},
{"SET*", H_OPER, settings_help},
{"BREAKDOWN", H_OPER, breakdown_help},
{"COUNT*", H_OPER, breakdown_help},
{"NICKS?RV", H_OPER, nickserv_help},
{"CHANS?RV", H_OPER, chanserv_help},
{"MEMOS?RV", H_OPER, memoserv_help},
{"JUPE*", H_SOP, jupe_help},
{"FAKE*", H_SOP, jupe_help},
{"IGNORE", H_SOP, ignore_help},
{"UPDATE*", H_SOP, update_help},
{"WRITE*", H_SOP, update_help},
{"SAVE*", H_SOP, update_help},
{"LOG*MESS*", H_SOP, logonmsg_help},
{"LOG*MSG*", H_SOP, logonmsg_help},
/* { "*PING*", H_SOP, sendpings_help }, */
{"OP*MESS*", H_ADMIN, opermsg_help},
{"OP*MSG*", H_ADMIN, opermsg_help},
{"ON", H_ADMIN, offon_help},
{"OFF", H_ADMIN, offon_help},
{"SHUTDOWN", H_ADMIN, shutdown_help},
{"DIE", H_ADMIN, shutdown_help},
{"END", H_ADMIN, shutdown_help},
{"RELOAD", H_ADMIN, reload_help},
{"*HUP", H_ADMIN, reload_help},
{"RESTART", H_ADMIN, reload_help},
{"QUIT", H_ADMIN, quit_help},
{"*MURDER", H_ADMIN, quit_help},
{"S*OP", H_ADMIN, sop_help},
{"OPER*", H_ADMIN, sop_help},
{"A*KILL", H_OPER, akill_help},
{"P*A*KILL", H_SOP, pakill_help},
#ifdef DAL_SERV
{"QLINE", H_OPER, qline_help},
{"UNQLINE", H_OPER, unqline_help},
{"KILL*", H_SOP, kill_help},
{"N*OP*", H_ADMIN, noop_help},
#endif
{"CLONE*", H_SOP, clone_help},
{NULL}
};
if (command = get_help_hash (source, cmd, hash_table))
{
if((globalnoticer_on==FALSE&&(command->process==logonmsg_help||command->process==opermsg_help))
||(akill_on==FALSE&&(command->process==akill_help||command->process==pakill_help))
||(clones_on==FALSE&&command->process==clone_help)
)
notice (s_OperServ, source, ERR_NOHELP, cmd);
else
notice_list (s_OperServ, source, command->process);
}
else
notice (s_OperServ, source, ERR_NOHELP, cmd);
}
}
static void
do_global (const char *source)
{
char *msg = strtok (NULL, "");
if (!msg)
{
notice (s_OperServ, source, "Syntax: \2GLOBAL \37msg\37\2");
notice (s_OperServ, source,
"\2/msg %s HELP GLOBAL for more information.",
s_OperServ);
}
noticeall (s_GlobalNoticer, "%s", msg);
wallops (s_OperServ, OS_GLOBAL_WALLOP, source);
}
static void
do_settings (const char *source)
{
notice (s_OperServ, source, OS_SET_EXP);
if(chanserv_on==TRUE)
notice (s_OperServ, source, OS_SET_EXP_CHAN, channel_expire);
if(nickserv_on==TRUE)
notice (s_OperServ, source, OS_SET_EXP_NICK, nick_expire);
if(news_on==TRUE)
notice (s_OperServ, source, OS_SET_EXP_NEWS, news_expire);
if(akill_on==TRUE)
notice (s_OperServ, source, OS_SET_EXP_AKILL, akill_expire);
if(clones_on==TRUE)
notice (s_OperServ, source, OS_SET_CLONES, clones_allowed);
if(nickserv_on==TRUE&&release_timeout>0)
notice (s_OperServ, source, OS_SET_RELEASE, release_timeout);
if(chanserv_on==TRUE&&akick_max>0)
notice (s_OperServ, source, OS_SET_AKICKS, akick_max);
if(devnull_on==TRUE)
{
notice (s_OperServ, source, OS_SET_FLOOD, flood_messages, flood_time);
notice (s_OperServ, source, OS_SET_IGNORE, ignore_time, ignore_offences);
}
if(server_relink>0)
notice (s_OperServ, source, OS_SET_RELINK, server_relink);
notice (s_OperServ, source, OS_SET_OVERRIDE, override_level[override_level_val]);
notice (s_OperServ, source, OS_SET_UPDATE, update_timeout);
if(show_sync_on==TRUE)
notice(s_OperServ, source, INFO_SYNC_TIME,
disect_time((last_update+update_timeout)-time(NULL), 0));
notice (s_OperServ, source, OS_SET_ADMINS, services_admin);
}
static void
do_breakdown (const char *source)
{
User *u;
int i, cnt, totcnt = 0;
/* notice(s_OperServ, source, "\2Servers Users Lag Percent\2");
*/ notice (s_OperServ, source, "\2Servers Users Percent\2");
for (i = 0; i < servcnt; ++i)
{
cnt = 0;
for (u = userlist; u; u = u->next)
if (stricmp (servlist[i].server, u->server) == 0)
{
cnt++;
totcnt++;
}
/* notice(s_OperServ, source, "%-32s %4d %3ds %3.2f%%",
servlist[i].server, cnt, servlist[i].lag, (float)(cnt*100)/usercnt);
*/ notice (s_OperServ, source, "%-32s %4d %3.2f%%",
servlist[i].server, cnt, (float) (cnt * 100) / usercnt);
}
if (totcnt != usercnt)
notice (s_OperServ, source,
"WARNING: I counted %d users, but have %d on status record.",
totcnt, usercnt);
}
static void
do_sendpings (const char *source)
{
notice (s_OperServ, source, "Sending Pings.");
runflags |= RUN_SEND_PINGS;
}
static void
do_stats (const char *source)
{
char *extra = strtok (NULL, "");
notice (s_OperServ, source, "Current users : \2%d\2 (%d ops)", usercnt, opcnt);
if(clones_on==TRUE)
{
Clone *clone;
int cnt = 0, hosts = 0;
for (clone = clonelist; clone; clone = clone->next)
if (clone->amount > 1)
{
cnt += clone->amount - 1;
hosts++;
}
if (cnt)
notice (s_OperServ, source, "Current clones: \2%d\2 (%d hosts)", cnt, hosts);
}
notice (s_OperServ, source, "Maximum users : \2%d\2", maxusercnt);
notice (s_OperServ, source, "Services up \2%s\2.", time_ago (start_time, 0));
if (start_time != reset_time)
notice (s_OperServ, source, "Services last reset \2%s\2.", time_ago (reset_time, 0));
if (extra && is_services_op (source))
if (stricmp (extra, "ALL") == 0)
{
long count, mem;
get_user_stats (&count, &mem);
notice (s_OperServ, source,
"User : \2%6d\2 records, \2%5d\2 kB",
count, (mem + 1023) / 1024);
get_channel_stats (&count, &mem);
notice (s_OperServ, source,
"Channel : \2%6d\2 records, \2%5d\2 kB",
count, (mem + 1023) / 1024);
if(nickserv_on==TRUE)
{
get_nickserv_stats (&count, &mem);
notice (s_OperServ, source, "NickServ: \2%6d\2 records, \2%5d\2 kB", count, (mem + 1023) / 1024);
}
if(chanserv_on==TRUE)
{
get_chanserv_stats (&count, &mem);
notice (s_OperServ, source, "ChanServ: \2%6d\2 records, \2%5d\2 kB", count, (mem + 1023) / 1024);
}
if (services_level == 1)
{
if(memos_on==TRUE)
{
get_memoserv_stats (&count, &mem);
notice (s_OperServ, source, "MemoServ: \2%6d\2 records, \2%5d\2 kB", count, (mem + 1023) / 1024);
}
if(news_on==TRUE)
{
get_newsserv_stats (&count, &mem);
notice (s_OperServ, source, "NewsServ: \2%6d\2 records, \2%5d\2 kB", count, (mem + 1023) / 1024);
}
}
if(akill_on==TRUE)
{
if(clones_on==TRUE)
notice (s_OperServ, source, "OperServ: \2%6d\2 records, \2%5d\2 kB",nakill + nclone, ((akill_size * sizeof (*akills) + 1023) + (clone_size * sizeof (*clones) + 1023)) / 1024);
else
notice (s_OperServ, source, "OperServ: \2%6d\2 records, \2%5d\2 kB",nakill, (akill_size * sizeof (*akills) + 1023) / 1024);
}
else
notice (s_OperServ, source, "OperServ: \2%6d\2 records, \2%5d\2 kB",nclone, (clone_size * sizeof (*clones) + 1023) / 1024);
}
else if (stricmp (extra, "NICK") == 0)
{
NickInfo *ni;
int i, links = 0, regs = 0, forbid = 0, suspend = 0;
for (i=33; i<256; i++)
for (ni = nicklists[i]; ni; ni = ni->next)
if (ni->flags & NI_VERBOTEN)
forbid++;
else if (host(ni)->flags & NI_SUSPENDED)
suspend++;
else if (ni->flags & NI_SLAVE)
links++;
else
regs++;
notice (s_OperServ, source, "Registered / Linked : \37\2%d\2\37 / \37\2%d\2\37", regs, links);
notice (s_OperServ, source, "Forbidden / Suspended : \37\2%d\2\37 / \37\2%d\2\37", forbid, suspend);
notice (s_OperServ, source, "Registers / Links : \2%d\2 / \2%d\2", S_nick_reg, S_nick_link);
notice (s_OperServ, source, "Identifies / Drops : \2%d\2 / \2%d\2", S_nick_ident, S_nick_drop);
notice (s_OperServ, source, "Recovers / Releases : \2%d\2 / \2%d\2", S_nick_recover, S_nick_release);
notice (s_OperServ, source, "Ghosts / Kills : \2%d\2 / \2%d\2", S_nick_ghost, S_nick_kill);
notice (s_OperServ, source, "Getpasses / Forbids : \2%d\2 / \2%d\2", S_nick_getpass, S_nick_forbid);
notice (s_OperServ, source, "Suspends / Unsuspends: \2%d\2 / \2%d\2", S_nick_suspend, S_nick_unsuspend);
}
}
#ifdef DAL_SERV
static void
do_qline (const char *source)
{
char *nick = strtok (NULL, " ");
char *s = strtok (NULL, "");
if (!nick)
return;
if (!s)
send_cmd (NULL, "SQLINE %s", nick);
else
send_cmd (NULL, "SQLINE %s :%s", nick, s);
wallops (s_OperServ, OS_QLINE, source, nick);
}
static void
do_unqline (const char *source)
{
char *nick = strtok (NULL, " ");
if (!nick)
return;
send_cmd (NULL, "UNSQLINE %s", nick);
wallops (s_OperServ, OS_UNQLINE, source, nick);
}
static void
do_noop (const char *source)
{
char *serv = strtok (NULL, " ");
char *s = strtok (NULL, "");
if (!s || (s[0] != '+' && s[0] != '-'))
return;
send_cmd (s_OperServ, "SVSNOOP 1 :%s", serv, s);
if (s[0] == '+')
wallops (s_OperServ, OS_SVSNOOP_ON, source, serv);
else
wallops (s_OperServ, OS_SVSNOOP_OFF, source, serv);
}
static void
do_os_kill (const char *source)
{
char *nick = strtok (NULL, " ");
char *s = strtok (NULL, "");
if (!s || !finduser (nick))
return;
send_cmd (s_OperServ, "SVSKILL %s :%s", finduser (nick)->nick, s);
}
#endif
static void
do_ignore (const char *source)
{
char *option = strtok (NULL, " ");
char *param = strtok (NULL, "");
int i;
if (!option || (stricmp (option, "LIST") != 0 && !param))
notice (s_OperServ, source,
"Syntax: \2IGNORE\2 \37{ADD|DEL|LIST}\37 [\37nick\37]");
else if (stricmp (option, "ADD") == 0)
{
if (ignorecnt >= ignore_size)
{
if (ignore_size < 8)
ignore_size = 8;
else
ignore_size *= 2;
ignore = srealloc (ignore, sizeof (*ignore) * ignore_size);
}
strscpy (ignore[ignorecnt].nick, param, NICKMAX);
ignore[ignorecnt].start = 0;
ignorecnt++;
notice (s_OperServ, source, LIST_ADDED, param, "services", "IGNORE");
}
else if (stricmp (option, "DEL") == 0)
{
int cnt = 0;
if (strspn (param, "1234567890") == strlen (param) &&
(i = atoi (param)) > 0 && i <= ignorecnt)
strscpy (param, ignore[i - 1].nick, NICKMAX);
for (i = 0; i < ignorecnt; ++i)
if (match_wild_nocase (param, ignore[i].nick))
{
--ignorecnt;
if (i < ignorecnt)
bcopy (ignore + i + 1, ignore + i, sizeof (*ignore) * (ignorecnt - i));
i--;
cnt++;
}
notice (s_OperServ, source, LIST_REMOVED_MASK,
cnt, cnt == 1 ? "y" : "ies", param, "services", "IGNORE");
}
else if (stricmp (option, "LIST") == 0)
{
notice (s_OperServ, source, "Services ignorance list:");
for (i = 0; i < ignorecnt; i++)
if (!ignore[i].start && (!param ||
match_wild_nocase (param, ignore[i].nick)))
notice (s_OperServ, source, "%d %s%s", i + 1, ignore[i].nick,
finduser (ignore[i].nick) ? " (online)" : "");
}
else
notice (s_OperServ, source, ERR_UNKNOWN_OPTION, option, s_OperServ,
"IGNORE");
}
static void
do_jupe (const char *source)
{
char *serv = strtok (NULL, " ");
char *reason = strtok (NULL, "");
if (!serv)
notice (s_OperServ, source, "Syntax: \2JUPE \37servername\37 [\37reason\37]\2");
else
{
wallops (s_OperServ, OS_JUPE, serv, source);
if (reason)
send_cmd (NULL, "SERVER %s 2 :JUPE: %s", serv, reason);
else
send_cmd (NULL, "SERVER %s 2 :Jupitered server", serv);
}
}
static void
do_off (const char *source)
{
char *s = strtok (NULL, "");
if (runflags & RUN_MODE)
{
runflags &= ~RUN_MODE;
write_log ("Log closed with OFF command from %s", source);
close_log ();
wallops (s_OperServ, ONOFF_NOTIFY, "OFF", source);
if (s)
{
if (offreason = malloc (strlen (s) + 1))
snprintf (offreason, strlen (s) + 1, "%s", s);
else
offreason = s;
}
if(globalnoticer_on==TRUE)
{
if (offreason)
noticeall (s_GlobalNoticer, SERVICES_OFF_REASON, offreason);
else
noticeall (s_GlobalNoticer, SERVICES_OFF);
}
else
{
if (offreason)
notice (s_OperServ, source, SERVICES_OFF_REASON, offreason);
else
notice (s_OperServ, source, SERVICES_OFF);
}
}
}
static void
do_on (const char *source)
{
if (!(runflags & RUN_MODE))
{
runflags |= RUN_MODE;
open_log ();
write_log ("Log opened with ON command from %s", source);
wallops (s_OperServ, ONOFF_NOTIFY, "ON", source);
if (offreason)
free(offreason);
offreason = NULL;
if(globalnoticer_on==TRUE)
noticeall (s_GlobalNoticer, SERVICES_ON);
else
notice (s_OperServ, source, SERVICES_ON);
}
}
static void
do_update (const char *source)
{
notice (s_OperServ, source, OS_UPDATE);
runflags |= RUN_SAVE_DATA;
}
static void
do_reload (const char *source)
{
quitmsg = malloc (BUFSIZE);
if (!quitmsg)
quitmsg = "RELOAD command recieved, but out of memory!";
else
snprintf (quitmsg, BUFSIZE, "RELOAD command received from %s", source);
runflags |= RUN_QUITTING;
runflags |= RUN_NOSLEEP;
}
static void
do_os_quit (const char *source)
{
quitmsg = malloc (BUFSIZE);
if (!quitmsg)
quitmsg = "QUIT command received, but out of memory!";
else
snprintf (quitmsg, BUFSIZE, "QUIT command received from %s", source);
runflags |= RUN_QUITTING;
runflags |= RUN_TERMINATING;
}
static void
do_shutdown (const char *source)
{
do_update (source);
do_os_quit (source);
}
static void
do_raw (const char *source)
{
char *text = strtok (NULL, "");
if (!text)
notice (s_OperServ, source, "Syntax: \2RAW \37command\37\2");
else
send_cmd (NULL, text);
}
/*************************************************************************/
/************************** Services Operators ***************************/
/*************************************************************************/
void
load_sop ()
{
FILE *f = fopen (sop_db, "r");
int i;
if (!f)
{
log_perror ("Can't read SOP database %s", sop_db);
return;
}
switch (i = get_file_version (f, sop_db))
{
case 5:
case 4:
case 3:
case 2:
case 1:
nsop = fgetc (f) * 256 + fgetc (f);
if (nsop < 8)
sop_size = 16;
else
sop_size = 2 * nsop;
sops = srealloc (sops, sizeof (Sop) * sop_size);
if (!nsop)
{
fclose (f);
return;
}
if (nsop != fread (sops, sizeof (Sop), nsop, f))
fatal_perror ("Read error on %s", sop_db);
break;
default:
fatal ("Unsupported version (%d) on %s", i, sop_db);
} /* switch (version) */
fclose (f);
}
/*************************************************************************/
void
save_sop ()
{
FILE *f;
char sop_dbsave[2048];
strcpy (sop_dbsave, sop_db);
strcat (sop_dbsave, ".save");
remove (sop_dbsave);
if (rename (sop_db, sop_dbsave) < 0)
log_perror ("Can't back up %s", sop_db);
f = fopen (sop_db, "w");
if (!f)
{
log_perror ("Can't write to SOP database %s", sop_db);
if (rename (sop_dbsave, sop_db) < 0)
fatal_perror ("Can't restore backup copy of %s", sop_db);
return;
}
#ifndef WIN32
if (fchown (fileno (f), -1, file_gid) < 0)
log_perror ("Can't change group of %s to %d", sop_db, file_gid);
#endif
write_file_version (f, sop_db);
fputc (nsop / 256, f);
fputc (nsop & 255, f);
if (fwrite (sops, sizeof (Sop), nsop, f) != nsop)
fatal_perror ("Write error on %s", sop_db);
fclose (f);
remove (sop_dbsave);
}
/*************************************************************************/
/* Handle an SOP command. */
static void
do_sop (const char *source)
{
char *cmd = strtok (NULL, " ");
if (!cmd)
{
notice (s_OperServ, source,
"Syntax: \2SOP {ADD|DEL|LIST} \2[\37user\37]");
notice (s_OperServ, source, ERR_MORE_INFO,
s_OperServ, "SOP");
}
else
{
Hash *command, hash_table[] =
{
{"ADD", H_ADMIN, do_sop_add},
{"ALLOW", H_ADMIN, do_sop_add},
{"GRANT", H_ADMIN, do_sop_add},
{"DEL*", H_ADMIN, do_sop_del},
{"ERASE", H_ADMIN, do_sop_del},
{"TRASH", H_ADMIN, do_sop_del},
{"LIST*", H_ADMIN, do_sop_list},
{"VIEW", H_ADMIN, do_sop_list},
{"DISP*", H_ADMIN, do_sop_list},
{"SHOW*", H_ADMIN, do_sop_list},
{NULL}
};
if (command = get_hash (source, cmd, hash_table))
(*command->process) (source);
else
{
notice (s_OperServ, source,
"Syntax: \2SOP {ADD|DEL|LIST} [\37user\37]\2");
notice (s_OperServ, source, ERR_UNKNOWN_OPTION,
cmd, s_OperServ, "SOP");
}
}
}
void
do_sop_add (const char *source)
{
char *nick;
if (nick = strtok (NULL, " "))
{
if (is_justservices_op (nick))
notice (s_OperServ, source, LIST_THERE, nick, "services", "SOP");
else
{
if(nickserv_on==TRUE)
{
NickInfo *ni = host (findnick (nick));
if (!ni)
notice (s_OperServ, source, NS_NOT_REGISTERED, nick);
else if (ni->flags & NI_IRCOP)
{
strscpy (nick, ni->nick, NICKMAX);
if (nsop >= sop_size)
{
if (sop_size < 8)
sop_size = 8;
else
sop_size *= 2;
sops = srealloc (sops, sizeof (*sops) * sop_size);
}
strscpy (sops[nsop].nick, nick, NICKMAX);
notice (s_OperServ, source, LIST_ADDED, nick, "services", "SOP");
++nsop;
if (services_level != 1)
notice (s_OperServ, source, ERR_READ_ONLY);
}
else
notice (s_OperServ, source, ERR_ONLY_ON_IRCOP, "SOP ADD");
}
else