-
Notifications
You must be signed in to change notification settings - Fork 0
/
chanserv.c
5322 lines (4783 loc) · 165 KB
/
chanserv.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
/* ChanServ functions.
*
* Services is copyright (c) 1996-1999 Andy Church.
* E-mail: <[email protected]>
* This program is free but copyrighted software; see the file COPYING for
* details.
*/
/*************************************************************************/
#include "services.h"
#include "pseudo.h"
/*************************************************************************/
static ChannelInfo *chanlists[256];
static int def_levels[][2] = {
{ CA_AUTOOP, 300 },
{ CA_AUTOVOICE, 100 },
{ CA_AUTODEOP, -1 },
{ CA_NOJOIN, -1 },
{ CA_INVITE, 300 },
{ CA_AKICK, 450 },
{ CA_SET, ACCESS_INVALID },
{ CA_CLEAR, ACCESS_INVALID },
{ CA_UNBAN, 300 },
{ CA_OPDEOP, 200 },
{ CA_ACCESS_LIST, 0 },
{ CA_ACCESS_CHANGE, 450 },
{ CA_MEMO, 100 },
{ CA_RESET, 450 },
{ CA_AUTODEVOICE -1 },
{ CA_VOICEDEVOICE, 50 },
{ CA_KICK, 400 },
{ CA_BAN, 400 },
{ -1 }
};
typedef struct {
int what;
char *name;
int desc;
} LevelInfo;
static LevelInfo levelinfo[] = {
{ CA_AUTOOP, "AUTOOP", CHAN_LEVEL_AUTOOP },
{ CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE },
{ CA_AUTODEOP, "AUTODEOP", CHAN_LEVEL_AUTODEOP },
/* { CA_AUTODEVOICE, "AUTODEVOICE", CHAN_LEVEL_AUTODEVOICE }, */
{ CA_NOJOIN, "NOJOIN", CHAN_LEVEL_NOJOIN },
{ CA_INVITE, "INVITE", CHAN_LEVEL_INVITE },
{ CA_OPDEOP, "OPDEOP", CHAN_LEVEL_OPDEOP },
{ CA_VOICEDEVOICE, "VOICEDEVOICE", CHAN_LEVEL_VOICEDEVOICE },
{ CA_KICK, "KICK", CHAN_LEVEL_KICK },
/* { CA_BAN, "BAN", CHAN_LEVEL_BAN } */
{ CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN },
{ CA_AKICK, "AKICK", CHAN_LEVEL_AKICK },
{ CA_SET, "SET", CHAN_LEVEL_SET },
{ CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR },
{ CA_RESET, "RESET", CHAN_LEVEL_RESET },
{ CA_ACCESS_LIST, "ACC-LIST", CHAN_LEVEL_ACCESS_LIST },
{ CA_ACCESS_CHANGE, "ACC-CHANGE", CHAN_LEVEL_ACCESS_CHANGE },
{ CA_MEMO, "MEMO", CHAN_LEVEL_MEMO },
{ -1 }
};
static int levelinfo_maxwidth = 0;
/*************************************************************************/
static void alpha_insert_chan(ChannelInfo *ci);
static ChannelInfo *makechan(const char *chan);
static int delchan(ChannelInfo *ci);
static void reset_levels(ChannelInfo *ci);
static int is_founder(User *user, ChannelInfo *ci);
static int is_identified(User *user, ChannelInfo *ci);
static int get_access(User *user, ChannelInfo *ci);
static void do_credits(User *u);
static void do_help(User *u);
static void do_register(User *u);
static void do_identify(User *u);
static void do_drop(User *u);
static void do_set(User *u);
static void do_set_founder(User *u, ChannelInfo *ci, char *param);
static void do_set_successor(User *u, ChannelInfo *ci, char *param);
static void do_set_password(User *u, ChannelInfo *ci, char *param);
static void do_set_desc(User *u, ChannelInfo *ci, char *param);
static void do_set_url(User *u, ChannelInfo *ci, char *param);
static void do_set_email(User *u, ChannelInfo *ci, char *param);
static void do_set_entrymsg(User *u, ChannelInfo *ci, char *param);
static void do_set_topic(User *u, ChannelInfo *ci, char *param);
static void do_set_mlock(User *u, ChannelInfo *ci, char *param);
static void do_set_keeptopic(User *u, ChannelInfo *ci, char *param);
static void do_set_topiclock(User *u, ChannelInfo *ci, char *param);
static void do_set_private(User *u, ChannelInfo *ci, char *param);
static void do_set_securevoices(User *u, ChannelInfo *ci, char *param);
static void do_set_secureops(User *u, ChannelInfo *ci, char *param);
static void do_set_leaveops(User *u, ChannelInfo *ci, char *param);
static void do_set_restricted(User *u, ChannelInfo *ci, char *param);
static void do_set_secure(User *u, ChannelInfo *ci, char *param);
static void do_set_opnotice(User *u, ChannelInfo *ci, char *param);
static void do_set_stay(User *u, ChannelInfo *ci, char *param);
static void do_set_noexpire(User *u, ChannelInfo *ci, char *param);
static void do_access(User *u);
static void do_akick(User *u);
static void do_info(User *u);
static void do_list(User *u);
static void do_invite(User *u);
static void do_levels(User *u);
static void do_op(User *u);
static void do_deop(User *u);
static void do_voice(User *u);
static void do_devoice(User *u);
static void do_ckick(User *u);
// static void do_ban(User *u);
static void do_unban(User *u);
static void do_clear(User *u);
static void do_reset(User *u);
static void do_verify(User *u);
static void do_ircops(User *u);
static void do_getpass(User *u);
static void do_suspend(User *u);
static void do_unsuspend(User *u);
static void do_forbid(User *u);
static void do_unforbid(User *u);
static void do_status(User *u);
static void do_say(User *u);
static void do_delaccess(User *u);
/*************************************************************************/
static Command cmds[] = {
{ "CREDITS", do_credits, NULL, -1, -1,-1,-1,-1 },
{ "CREDITOS", do_credits, NULL, -1, -1,-1,-1,-1 },
{ "HELP", do_help, NULL, -1, -1,-1,-1,-1 },
{ "AYUDA", do_help, NULL, -1, -1,-1,-1,-1 },
{ "DELACCESS", do_delaccess, NULL, CHAN_HELP_DELACCESS, -1,-1,-1,-1 },
{ "SHOWCOMMANDS", do_help, NULL, -1, -1,-1,-1,-1 },
{ ":?", do_help, NULL, -1, -1,-1,-1,-1 },
{ "?", do_help, NULL, -1, -1,-1,-1,-1 },
{ "REGISTER", do_register, NULL, CHAN_HELP_REGISTER, -1,-1,-1,-1 },
{ "IDENTIFY", do_identify, NULL, CHAN_HELP_IDENTIFY, -1,-1,-1,-1 },
{ "AUTH", do_identify, NULL, CHAN_HELP_IDENTIFY, -1,-1,-1,-1 },
{ "DROP", do_drop, is_services_oper, -1,
CHAN_HELP_DROP, CHAN_SERVADMIN_HELP_DROP,
CHAN_SERVADMIN_HELP_DROP, CHAN_SERVADMIN_HELP_DROP },
{ "SET", do_set, NULL, CHAN_HELP_SET,
-1, CHAN_SERVADMIN_HELP_SET,
CHAN_SERVADMIN_HELP_SET, CHAN_SERVADMIN_HELP_SET },
{ "SET FOUNDER", NULL, NULL, CHAN_HELP_SET_FOUNDER, -1,-1,-1,-1 },
{ "SET SUCCESSOR", NULL, NULL, CHAN_HELP_SET_SUCCESSOR, -1,-1,-1,-1 },
{ "SET PASSWORD", NULL, NULL, CHAN_HELP_SET_PASSWORD, -1,-1,-1,-1 },
{ "SET PASS", NULL, NULL, CHAN_HELP_SET_PASSWORD, -1,-1,-1,-1 },
{ "SET DESC", NULL, NULL, CHAN_HELP_SET_DESC, -1,-1,-1,-1 },
{ "SET URL", NULL, NULL, CHAN_HELP_SET_URL, -1,-1,-1,-1 },
{ "SET EMAIL", NULL, NULL, CHAN_HELP_SET_EMAIL, -1,-1,-1,-1 },
{ "SET ENTRYMSG", NULL, NULL, CHAN_HELP_SET_ENTRYMSG, -1,-1,-1,-1 },
{ "SET TOPIC", NULL, NULL, CHAN_HELP_SET_TOPIC, -1,-1,-1,-1 },
{ "SET KEEPTOPIC", NULL, NULL, CHAN_HELP_SET_KEEPTOPIC, -1,-1,-1,-1 },
{ "SET TOPICLOCK", NULL, NULL, CHAN_HELP_SET_TOPICLOCK, -1,-1,-1,-1 },
{ "SET MLOCK", NULL, NULL, CHAN_HELP_SET_MLOCK, -1,-1,-1,-1 },
{ "SET RESTRICTED", NULL, NULL, CHAN_HELP_SET_RESTRICTED, -1,-1,-1,-1 },
{ "SET SECURE", NULL, NULL, CHAN_HELP_SET_SECURE, -1,-1,-1,-1 },
{ "SET SECUREVOICES", NULL, NULL, CHAN_HELP_SET_SECUREOPS, -1,-1,-1,-1 },
{ "SET SECUREOPS", NULL, NULL, CHAN_HELP_SET_SECUREOPS, -1,-1,-1,-1 },
{ "SET LEAVEOPS", NULL, NULL, CHAN_HELP_SET_LEAVEOPS, -1,-1,-1,-1 },
{ "SET ISSUED", NULL, NULL, CHAN_HELP_SET_OPNOTICE, -1,-1,-1,-1 },
{ "SET DEBUG", NULL, NULL, CHAN_HELP_SET_OPNOTICE, -1,-1,-1,-1 },
{ "SET OPNOTICE", NULL, NULL, CHAN_HELP_SET_OPNOTICE, -1,-1,-1,-1 },
{ "SET STAY", NULL, NULL, CHAN_HELP_SET_OPNOTICE, -1,-1,-1,-1 },
{ "SET NOEXPIRE", NULL, NULL, -1, -1,
CHAN_SERVADMIN_HELP_SET_NOEXPIRE,
CHAN_SERVADMIN_HELP_SET_NOEXPIRE,
CHAN_SERVADMIN_HELP_SET_NOEXPIRE },
{ "ACCESS", do_access, NULL, CHAN_HELP_ACCESS, -1,-1,-1,-1 },
{ "ACCESS LEVELS", NULL, NULL, CHAN_HELP_ACCESS_LEVELS, -1,-1,-1,-1 },
{ "AKICK", do_akick, NULL, CHAN_HELP_AKICK, -1,-1,-1,-1 },
{ "LEVELS", do_levels, NULL, CHAN_HELP_LEVELS, -1,-1,-1,-1 },
{ "INFO", do_info, NULL, CHAN_HELP_INFO,
-1, CHAN_SERVADMIN_HELP_INFO, CHAN_SERVADMIN_HELP_INFO,
CHAN_SERVADMIN_HELP_INFO },
{ "LIST", do_list, NULL, -1,
CHAN_HELP_LIST, CHAN_SERVADMIN_HELP_LIST,
CHAN_SERVADMIN_HELP_LIST, CHAN_SERVADMIN_HELP_LIST },
{ "VOICE", do_voice, NULL, CHAN_HELP_VOICE, -1,-1,-1,-1 },
{ "DEVOICE", do_devoice, NULL, CHAN_HELP_DEVOICE, -1,-1,-1,-1 },
{ "OP", do_op, NULL, CHAN_HELP_OP, -1,-1,-1,-1 },
{ "DEOP", do_deop, NULL, CHAN_HELP_DEOP, -1,-1,-1,-1 },
{ "INVITE", do_invite, NULL, CHAN_HELP_INVITE, -1,-1,-1,-1 },
{ "KICK", do_ckick, NULL, CHAN_HELP_KICK, -1,-1,-1,-1 },
// { "BAN", do_ban, NULL, CHAN_HELP_BAN, -1,-1,-1,-1 },
{ "UNBAN", do_unban, NULL, CHAN_HELP_UNBAN, -1,-1,-1,-1 },
{ "CLEAR", do_clear, NULL, CHAN_HELP_CLEAR, -1,-1,-1,-1 },
{ "RESET", do_reset, NULL, CHAN_HELP_RESET, -1,-1,-1,-1 },
{ "VERIFY", do_verify, is_services_oper, CHAN_HELP_VERIFY, -1,-1,-1,-1 },
{ "IRCOPS", do_ircops, is_services_oper, CHAN_HELP_IRCOPS, -1,-1,-1,-1 },
{ "GETPASS", do_getpass, is_services_oper, -1,
-1, CHAN_SERVADMIN_HELP_GETPASS,
CHAN_SERVADMIN_HELP_GETPASS, CHAN_SERVADMIN_HELP_GETPASS },
{ "SUSPEND", do_suspend, is_services_oper, -1,
-1, CHAN_SERVADMIN_HELP_SUSPEND,
CHAN_SERVADMIN_HELP_SUSPEND, CHAN_SERVADMIN_HELP_SUSPEND },
{ "UNSUSPEND", do_unsuspend, is_services_oper, -1,
-1, CHAN_SERVADMIN_HELP_UNSUSPEND,
CHAN_SERVADMIN_HELP_UNSUSPEND, CHAN_SERVADMIN_HELP_UNSUSPEND },
{ "FORBID", do_forbid, is_services_admin, -1,
-1, CHAN_SERVADMIN_HELP_FORBID,
CHAN_SERVADMIN_HELP_FORBID, CHAN_SERVADMIN_HELP_FORBID },
{ "UNFORBID", do_unforbid, is_services_admin, -1,
-1, CHAN_SERVADMIN_HELP_UNFORBID,
CHAN_SERVADMIN_HELP_UNFORBID, CHAN_SERVADMIN_HELP_UNFORBID },
{ "STATUS", do_status, is_services_oper, -1,
-1, CHAN_SERVADMIN_HELP_STATUS,
CHAN_SERVADMIN_HELP_STATUS, CHAN_SERVADMIN_HELP_STATUS },
{ "SAY", do_say, is_services_oper, -1, -1, -1, -1, -1 },
{ NULL }
};
/*************************************************************************/
/*************************************************************************/
/* Display total number of registered channels and info about each; or, if
* a specific channel is given, display information about that channel
* (like /msg ChanServ INFO <channel>). If count_only != 0, then only
* display the number of registered channels (the channel parameter is
* ignored).
*/
void listchans(int count_only, const char *chan)
{
int count = 0;
ChannelInfo *ci;
int i;
if (count_only) {
for (i = 0; i < 256; i++) {
for (ci = chanlists[i]; ci; ci = ci->next)
count++;
}
printf("%d canales registrados.\n", count);
} else if (chan) {
struct tm *tm;
char *s, buf[BUFSIZE];
if (!(ci = cs_findchan(chan))) {
printf("El canal %s no esta registrado.\n", chan);
return;
}
if (ci->flags & CI_VERBOTEN) {
printf("El canal %s esta FORBIDeado.\n", ci->name);
} else {
printf("Informacion del canal %s:\n", ci->name);
if (ci->flags & CI_SUSPEND)
printf("Estado: SUSPENDIDO");
else
printf("Estado: ACTIVO");
s = ci->founder->last_usermask;
printf("Fundador: %s%s%s%s\n",
ci->founder->nick,
s ? " (" : "", s ? s : "", s ? ")" : "");
printf("Descripcion: %s\n", ci->desc);
tm = localtime(&ci->time_registered);
strftime(buf, sizeof(buf), getstring(NULL,STRFTIME_DATE_TIME_FORMAT), tm);
printf("Registrado: %s\n", buf);
tm = localtime(&ci->last_used);
strftime(buf, sizeof(buf), getstring(NULL,STRFTIME_DATE_TIME_FORMAT), tm);
printf("Ultimo uso: %s\n", buf);
if (ci->last_topic) {
printf("Ultimo topic: %s\n", ci->last_topic);
printf("Topic ajustado por: %s\n", ci->last_topic_setter);
}
if (ci->url)
printf("URL: %s\n", ci->url);
if (ci->email)
printf("E-mail: %s\n", ci->email);
printf("Opciones: ");
if (!ci->flags) {
printf("Ninguna\n");
} else {
int need_comma = 0;
static const char commastr[] = ", ";
if (ci->flags & CI_PRIVATE) {
printf("Privado");
need_comma = 1;
}
if (ci->flags & CI_KEEPTOPIC) {
printf("%sRetencion de topic", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_TOPICLOCK) {
printf("%sCandado de topic", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_SECUREVOICES) {
printf("%sSecure Voices", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_SECUREOPS) {
printf("%sSecure Ops", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_LEAVEOPS) {
printf("%sLeave Ops", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_RESTRICTED) {
printf("%sAcceso Restringido", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_SECURE) {
printf("%sSeguro", need_comma ? commastr : "");
need_comma = 1;
}
if (ci->flags & CI_NO_EXPIRE) {
printf("%sNo Expira", need_comma ? commastr : "");
need_comma = 1;
}
printf("\n");
}
printf("Candado de modos: ");
if (ci->mlock_on || ci->mlock_key || ci->mlock_limit) {
printf("+%s%s%s%s%s%s%s%s%s%s%s%s",
(ci->mlock_on & CMODE_I) ? "i" : "",
(ci->mlock_key ) ? "k" : "",
(ci->mlock_limit ) ? "l" : "",
(ci->mlock_on & CMODE_M) ? "m" : "",
(ci->mlock_on & CMODE_N) ? "n" : "",
(ci->mlock_on & CMODE_P) ? "p" : "",
(ci->mlock_on & CMODE_s) ? "s" : "",
(ci->mlock_on & CMODE_T) ? "t" : "",
//#if defined (IRC_HISPANO) || defined (IRC_TERRA)
(ci->mlock_on & CMODE_R) ? "R" : "",
(ci->mlock_on & CMODE_m) ? "M" : ""
//#else
// ""
//#endif
/* #ifdef IRC_HISPANO
,(ci->mlock_on & CMODE_A) ? "A" : "",
(ci->mlock_on & CMODE_S) ? "S" : ""
#else */
,"",
""
//#endif
);
}
if (ci->mlock_off)
printf("-%s%s%s%s%s%s%s%s%s%s%s%s",
(ci->mlock_off & CMODE_I) ? "i" : "",
(ci->mlock_off & CMODE_K) ? "k" : "",
(ci->mlock_off & CMODE_L) ? "l" : "",
(ci->mlock_off & CMODE_M) ? "m" : "",
(ci->mlock_off & CMODE_N) ? "n" : "",
(ci->mlock_off & CMODE_P) ? "p" : "",
(ci->mlock_off & CMODE_s) ? "s" : "",
(ci->mlock_off & CMODE_T) ? "t" : "",
//#if defined (IRC_HISPANO) || defined (IRC_TERRA)
(ci->mlock_off & CMODE_R) ? "R" : "",
(ci->mlock_off & CMODE_m) ? "M" : ""
//#else
// ""
//#endif
/* #ifdef IRC_HISPANO
,
(ci->mlock_off & CMODE_A) ? "A" : "",
(ci->mlock_off & CMODE_S) ? "S" : ""
#else */
,
"",
""
/* #endif */
);
if (ci->mlock_key)
printf(" %s", ci->mlock_key);
if (ci->mlock_limit)
printf(" %d", ci->mlock_limit);
printf("\n");
}
} else {
for (i = 0; i < 256; i++) {
for (ci = chanlists[i]; ci; ci = ci->next) {
printf(" %s %-20s %s\n", ci->flags & CI_NO_EXPIRE ? "!" : " ",
ci->name,
ci->flags & CI_VERBOTEN ?
"Inactivo (FORBID)" : ci->desc);
count++;
}
}
printf("%d Canales registrados.\n", count);
}
}
/*************************************************************************/
/* Return information on memory use. Assumes pointers are valid. */
void get_chanserv_stats(long *nrec, long *memuse)
{
long count = 0, mem = 0;
int i, j;
ChannelInfo *ci;
for (i = 0; i < 256; i++) {
for (ci = chanlists[i]; ci; ci = ci->next) {
count++;
mem += sizeof(*ci);
if (ci->desc)
mem += strlen(ci->desc)+1;
if (ci->url)
mem += strlen(ci->url)+1;
if (ci->email)
mem += strlen(ci->email)+1;
mem += ci->accesscount * sizeof(ChanAccess);
mem += ci->akickcount * sizeof(AutoKick);
for (j = 0; j < ci->akickcount; j++) {
if (!ci->akick[j].is_nick && ci->akick[j].u.mask)
mem += strlen(ci->akick[j].u.mask)+1;
if (ci->akick[j].reason)
mem += strlen(ci->akick[j].reason)+1;
}
if (ci->mlock_key)
mem += strlen(ci->mlock_key)+1;
if (ci->last_topic)
mem += strlen(ci->last_topic)+1;
if (ci->entry_message)
mem += strlen(ci->entry_message)+1;
if (ci->suspendby)
mem += strlen(ci->suspendby)+1;
if (ci->suspendreason)
mem += strlen(ci->suspendreason)+1;
if (ci->forbidby)
mem += strlen(ci->forbidby)+1;
if (ci->forbidreason)
mem += strlen(ci->forbidreason)+1;
if (ci->levels)
mem += sizeof(*ci->levels) * CA_SIZE;
mem += ci->memos.memocount * sizeof(Memo);
for (j = 0; j < ci->memos.memocount; j++) {
if (ci->memos.memos[j].text)
mem += strlen(ci->memos.memos[j].text)+1;
}
}
}
*nrec = count;
*memuse = mem;
}
/*************************************************************************/
/*************************************************************************/
/* ChanServ initialization. */
void cs_init(void)
{
Command *cmd;
cmd = lookup_cmd(cmds, "REGISTER");
if (cmd)
cmd->help_param1 = s_NickServ;
cmd = lookup_cmd(cmds, "SET SECURE");
if (cmd)
cmd->help_param1 = s_NickServ;
cmd = lookup_cmd(cmds, "SET SUCCESSOR");
if (cmd)
cmd->help_param1 = (char *)(long)CSMaxReg;
}
/*************************************************************************/
/* Main ChanServ routine. */
void chanserv(const char *source, char *buf)
{
char *cmd, *s;
User *u = finduser(source);
if (!u) {
log("%s: registro de usuario para %s no encontrado", s_ChanServ, source);
#ifndef IRC_UNDERNET_P10
/* En undernet P10, no sabremos el trio, y por lo tanto innecesario */
privmsg(s_NickServ, source,
getstring((NickInfo *)NULL, USER_RECORD_NOT_FOUND));
#endif
return;
}
cmd = strtok(buf, " ");
if (!cmd) {
return;
} else if (stricmp(cmd, "\1PING") == 0) {
if (!(s = strtok(NULL, "")))
s = "\1";
#ifdef IRC_UNDERNET_P10
notice(s_ChanServ, u->numerico, "\1PING %s", s);
#else
notice(s_ChanServ, source, "\1PING %s", s);
#endif
} else if (stricmp(cmd, "\1VERSION\1") == 0) {
notice(s_ChanServ, source, "\1VERSION %s %s -- %s\1",
PNAME, s_ChanServ, version_build);
} else if (skeleton) {
notice_lang(s_ChanServ, u, SERVICE_OFFLINE, s_ChanServ);
} else if (stricmp(cmd, "AOP") == 0 || stricmp(cmd, "SOP") == 0) {
notice_lang(s_ChanServ, u, CHAN_NO_AOP_SOP, s_ChanServ);
} else {
run_cmd(s_ChanServ, u, cmds, cmd);
}
}
/*************************************************************************/
/* Load/save data files. */
#define SAFE(x) do { \
if ((x) < 0) { \
if (!forceload) \
fatal("Error de lectura en %s", ChanDBName); \
failed = 1; \
break; \
} \
} while (0)
/* Load v1-v4 files. */
static void load_old_cs_dbase(dbFILE *f, int ver)
{
int i, j, c;
ChannelInfo *ci, **last, *prev;
NickInfo *ni;
int failed = 0;
struct {
short level;
#ifdef COMPATIBILITY_V2
short is_nick;
#else
short in_use;
#endif
char *name;
} old_chanaccess;
struct {
short is_nick;
short pad;
char *name;
char *reason;
} old_autokick;
struct {
ChannelInfo *next, *prev;
char name[CHANMAX];
char founder[NICKMAX];
char founderpass[PASSMAX];
char *desc;
time_t time_registered;
time_t last_used;
long accesscount;
ChanAccess *access;
long akickcount;
AutoKick *akick;
short mlock_on, mlock_off;
long mlock_limit;
char *mlock_key;
char *last_topic;
char last_topic_setter[NICKMAX];
time_t last_topic_time;
long flags;
short *levels;
char *url;
char *email;
struct channel_ *c;
} old_channelinfo;
for (i = 33; i < 256 && !failed; i++) {
last = &chanlists[i];
prev = NULL;
while ((c = getc_db(f)) != 0) {
if (c != 1)
fatal("Invalid format in %s", ChanDBName);
SAFE(read_variable(old_channelinfo, f));
if (debug >= 3)
log("debug: load_old_cs_dbase: leyendo canal %s",
old_channelinfo.name);
ci = scalloc(1, sizeof(ChannelInfo));
strscpy(ci->name, old_channelinfo.name, CHANMAX);
ci->founder = findnick(old_channelinfo.founder);
strscpy(ci->founderpass, old_channelinfo.founderpass, PASSMAX);
ci->time_registered = old_channelinfo.time_registered;
ci->last_used = old_channelinfo.last_used;
ci->accesscount = old_channelinfo.accesscount;
ci->akickcount = old_channelinfo.akickcount;
ci->mlock_on = old_channelinfo.mlock_on;
ci->mlock_off = old_channelinfo.mlock_off;
ci->mlock_limit = old_channelinfo.mlock_limit;
strscpy(ci->last_topic_setter,
old_channelinfo.last_topic_setter, NICKMAX);
ci->last_topic_time = old_channelinfo.last_topic_time;
ci->flags = old_channelinfo.flags;
#ifdef USE_ENCRYPTION
if (!(ci->flags & (CI_ENCRYPTEDPW | CI_VERBOTEN))) {
if (debug)
log("debug: %s: password encriptada para %s on load",
s_ChanServ, ci->name);
if (encrypt_in_place(ci->founderpass, PASSMAX) < 0)
fatal("%s: load database: No está encriptada la password de %s!",
s_ChanServ, ci->name);
ci->flags |= CI_ENCRYPTEDPW;
}
#else
if (ci->flags & CI_ENCRYPTEDPW) {
/* Bail: it makes no sense to continue with encrypted
* passwords, since we won't be able to verify them */
fatal("%s: load database: password para %s encriptada "
"pero la encriptacion está desactivada, abortando",
s_ChanServ, ci->name);
}
#endif
ni = ci->founder;
if (ni) {
if (ni->channelcount+1 > ni->channelcount)
ni->channelcount++;
ni = getlink(ni);
if (ni != ci->founder && ni->channelcount+1 > ni->channelcount)
ni->channelcount++;
}
SAFE(read_string(&ci->desc, f));
if (!ci->desc)
ci->desc = sstrdup("");
if (old_channelinfo.url)
SAFE(read_string(&ci->url, f));
if (old_channelinfo.email)
SAFE(read_string(&ci->email, f));
if (old_channelinfo.mlock_key)
SAFE(read_string(&ci->mlock_key, f));
if (old_channelinfo.last_topic)
SAFE(read_string(&ci->last_topic, f));
if (ci->accesscount) {
ChanAccess *access;
char *s;
access = smalloc(sizeof(ChanAccess) * ci->accesscount);
ci->access = access;
for (j = 0; j < ci->accesscount; j++, access++) {
SAFE(read_variable(old_chanaccess, f));
#ifdef COMPATIBILITY_V2
if (old_chanaccess.is_nick < 0)
access->in_use = 0;
else
access->in_use = old_chanaccess.is_nick;
#else
access->in_use = old_chanaccess.in_use;
#endif
access->level = old_chanaccess.level;
}
access = ci->access;
for (j = 0; j < ci->accesscount; j++, access++) {
SAFE(read_string(&s, f));
if (s && access->in_use)
access->ni = findnick(s);
else
access->ni = NULL;
if (s)
free(s);
if (access->ni == NULL)
access->in_use = 0;
}
} else {
ci->access = NULL;
} /* if (ci->accesscount) */
if (ci->akickcount) {
AutoKick *akick;
char *s;
akick = smalloc(sizeof(AutoKick) * ci->akickcount);
ci->akick = akick;
for (j = 0; j < ci->akickcount; j++, akick++) {
SAFE(read_variable(old_autokick, f));
if (old_autokick.is_nick < 0) {
akick->in_use = 0;
akick->is_nick = 0;
} else {
akick->in_use = 1;
akick->is_nick = old_autokick.is_nick;
}
akick->reason = old_autokick.reason;
}
akick = ci->akick;
for (j = 0; j < ci->akickcount; j++, akick++) {
SAFE(read_string(&s, f));
if (akick->is_nick) {
if (!(akick->u.ni = findnick(s)))
akick->in_use = akick->is_nick = 0;
free(s);
} else {
if (!(akick->u.mask = s))
akick->in_use = 0;
}
if (akick->reason)
SAFE(read_string(&akick->reason, f));
if (!akick->in_use) {
if (akick->is_nick) {
akick->u.ni = NULL;
} else {
free(akick->u.mask);
akick->u.mask = NULL;
}
if (akick->reason) {
free(akick->reason);
akick->reason = NULL;
}
}
}
} else {
ci->akick = NULL;
} /* if (ci->akickcount) */
if (old_channelinfo.levels) {
int16 n_entries;
ci->levels = NULL;
reset_levels(ci);
SAFE(read_int16(&n_entries, f));
#ifdef COMPATIBILITY_V2
/* Ignore earlier, incompatible levels list */
if (n_entries == 6) {
fseek(f, sizeof(short) * n_entries, SEEK_CUR);
} else
#endif
for (j = 0; j < n_entries; j++) {
short lev;
SAFE(read_variable(lev, f));
if (j < CA_SIZE)
ci->levels[j] = lev;
}
} else {
reset_levels(ci);
}
ci->memos.memomax = MSMaxMemos;
*last = ci;
last = &ci->next;
ci->prev = prev;
prev = ci;
} /* while (getc_db(f) != 0) */
*last = NULL;
} /* for (i) */
}
void load_cs_dbase(void)
{
dbFILE *f;
int ver, i, j, c;
ChannelInfo *ci, **last, *prev;
int failed = 0;
if (!(f = open_db(s_ChanServ, ChanDBName, "r")))
return;
switch (ver = get_file_version(f)) {
case 8:
case 7:
case 6:
case 5:
for (i = 0; i < 256 && !failed; i++) {
int16 tmp16;
int32 tmp32;
int n_levels;
char *s;
last = &chanlists[i];
prev = NULL;
while ((c = getc_db(f)) != 0) {
if (c != 1)
fatal("Formato invalido en %s", ChanDBName);
ci = smalloc(sizeof(ChannelInfo));
*last = ci;
last = &ci->next;
ci->prev = prev;
prev = ci;
SAFE(read_buffer(ci->name, f));
SAFE(read_string(&s, f));
if (s)
ci->founder = findnick(s);
else
ci->founder = NULL;
if (ver >= 7) {
SAFE(read_string(&s, f));
if (s)
ci->successor = findnick(s);
else
ci->successor = NULL;
} else {
ci->successor = NULL;
}
if (ver == 5 && ci->founder != NULL) {
/* Channel count incorrect in version 5 files */
ci->founder->channelcount++;
}
SAFE(read_buffer(ci->founderpass, f));
SAFE(read_string(&ci->desc, f));
if (!ci->desc)
ci->desc = sstrdup("");
SAFE(read_string(&ci->url, f));
SAFE(read_string(&ci->email, f));
SAFE(read_int32(&tmp32, f));
ci->time_registered = tmp32;
SAFE(read_int32(&tmp32, f));
ci->last_used = tmp32;
SAFE(read_string(&ci->last_topic, f));
SAFE(read_buffer(ci->last_topic_setter, f));
SAFE(read_int32(&tmp32, f));
ci->last_topic_time = tmp32;
SAFE(read_int32(&ci->flags, f));
#ifdef USE_ENCRYPTION
if (!(ci->flags & (CI_ENCRYPTEDPW | CI_VERBOTEN))) {
if (debug)
log("debug: %s: encrypting password for %s on load",
s_ChanServ, ci->name);
if (encrypt_in_place(ci->founderpass, PASSMAX) < 0)
fatal("%s: load database: Can't encrypt %s password!",
s_ChanServ, ci->name);
ci->flags |= CI_ENCRYPTEDPW;
}
#else
if (ci->flags & CI_ENCRYPTEDPW) {
/* Bail: it makes no sense to continue with encrypted
* passwords, since we won't be able to verify them */
fatal("%s: load database: password for %s encrypted "
"but encryption disabled, aborting",
s_ChanServ, ci->name);
}
#endif
if (ver >= 8) {
SAFE(read_string(&ci->suspendby, f));
SAFE(read_string(&ci->suspendreason, f));
SAFE(read_int32(&tmp32, f));
ci->time_suspend = tmp32;
SAFE(read_int32(&tmp32, f));
ci->time_expiresuspend = tmp32;
SAFE(read_string(&ci->forbidby, f));
SAFE(read_string(&ci->forbidreason, f));
} else {
ci->suspendby = NULL;
ci->suspendreason = NULL;
ci->time_suspend = 0;
ci->time_expiresuspend = 0;
ci->forbidby = NULL;
ci->forbidreason = NULL;
}
SAFE(read_int16(&tmp16, f));
n_levels = tmp16;
ci->levels = smalloc(2*CA_SIZE);
reset_levels(ci);
for (j = 0; j < n_levels; j++) {
if (j < CA_SIZE)
SAFE(read_int16(&ci->levels[j], f));
else
SAFE(read_int16(&tmp16, f));
}
SAFE(read_int16(&ci->accesscount, f));
if (ci->accesscount) {
ci->access = scalloc(ci->accesscount, sizeof(ChanAccess));
for (j = 0; j < ci->accesscount; j++) {
SAFE(read_int16(&ci->access[j].in_use, f));
if (ci->access[j].in_use) {
SAFE(read_int16(&ci->access[j].level, f));
SAFE(read_string(&s, f));
if (s) {
ci->access[j].ni = findnick(s);
free(s);
}
if (ci->access[j].ni == NULL)
ci->access[j].in_use = 0;
}
}
} else {
ci->access = NULL;
}
SAFE(read_int16(&ci->akickcount, f));
if (ci->akickcount) {
ci->akick = scalloc(ci->akickcount, sizeof(AutoKick));
for (j = 0; j < ci->akickcount; j++) {
SAFE(read_int16(&ci->akick[j].in_use, f));
if (ci->akick[j].in_use) {
SAFE(read_int16(&ci->akick[j].is_nick, f));
SAFE(read_string(&s, f));
if (ci->akick[j].is_nick) {
ci->akick[j].u.ni = findnick(s);
if (!ci->akick[j].u.ni)
ci->akick[j].in_use = 0;
free(s);
} else {
ci->akick[j].u.mask = s;
}
SAFE(read_string(&s, f));
if (ci->akick[j].in_use)
ci->akick[j].reason = s;
else if (s)
free(s);
if (ver >= 8)
SAFE(read_buffer(ci->akick[j].who, f));
else
ci->akick[j].who[0] = '\0';
}
}
} else {
ci->akick = NULL;
}
SAFE(read_int16(&ci->mlock_on, f));
SAFE(read_int16(&ci->mlock_off, f));
SAFE(read_int32(&ci->mlock_limit, f));
SAFE(read_string(&ci->mlock_key, f));
SAFE(read_int16(&ci->memos.memocount, f));
SAFE(read_int16(&ci->memos.memomax, f));
if (ci->memos.memocount) {
Memo *memos;
memos = smalloc(sizeof(Memo) * ci->memos.memocount);
ci->memos.memos = memos;
for (j = 0; j < ci->memos.memocount; j++, memos++) {
SAFE(read_int32(&memos->number, f));
SAFE(read_int16(&memos->flags, f));
SAFE(read_int32(&tmp32, f));
memos->time = tmp32;
SAFE(read_buffer(memos->sender, f));
SAFE(read_string(&memos->text, f));
}
}
SAFE(read_string(&ci->entry_message, f));
ci->c = NULL;
} /* while (getc_db(f) != 0) */
*last = NULL;
} /* for (i) */
break; /* case 5 and up */
case 4:
case 3:
case 2:
case 1:
load_old_cs_dbase(f, ver);
break;
default:
fatal("Version no soportada (%d) en %s", ver, ChanDBName);
} /* switch (version) */
close_db(f);
/* Check for non-forbidden channels with no founder */
for (i = 0; i < 256; i++) {
ChannelInfo *next;
for (ci = chanlists[i]; ci; ci = next) {
next = ci->next;
if (!(ci->flags & CI_VERBOTEN) && !ci->founder) {
// canalopers(s_ChanServ, "El canal 12%s no tiene founder. Borrando..", ci->name);
log("%s: Carga DB: Borrando canal %s por no tener founder",
s_ChanServ, ci->name);
delchan(ci);
}
}
}
}
#undef SAFE
/*************************************************************************/
#define SAFE(x) do { \
if ((x) < 0) { \
restore_db(f); \
log_perror("Error de escritura en %s", ChanDBName); \
if (time(NULL) - lastwarn > WarningTimeout) { \