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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
|
/* HostServ functions
*
* (C) 2003 Anope Team
* Contact us at info@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
* $Id$
*
*/
/*************************************************************************/
#include "services.h"
#include "pseudo.h"
#define HOST_VERSION 3
#define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31))
void load_hs_dbase_v1(dbFILE * f);
void load_hs_dbase_v2(dbFILE * f);
void load_hs_dbase_v3(dbFILE * f);
HostCore *head = NULL; /* head of the HostCore list */
HostCore *createHostCorelist(HostCore * next, char *nick, char *vIdent,
char *vHost, char *creator, int32 tmp_time);
HostCore *findHostCore(HostCore * head, char *nick, boolean * found);
HostCore *insertHostCore(HostCore * head, HostCore * prev, char *nick,
char *vIdent, char *vHost, char *creator,
int32 tmp_time);
HostCore *deleteHostCore(HostCore * head, HostCore * prev);
void delHostCore(char *nick);
int is_host_setter(User * u);
int is_host_remover(User * u);
static int do_help(User * u);
static int do_set(User * u);
static int do_on(User * u);
int do_on_id(User * u);
static void set_lastmask(User * u);
static int do_off(User * u);
static int do_del(User * u);
static int do_group(User * u);
static int listOut(User * u);
int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, char *creator,
time_t time);
int do_setall(User * u);
int do_delall(User * u);
void moduleAddHostServCmds(void);
/*************************************************************************/
void moduleAddHostServCmds(void)
{
Command *c;
c = createCommand("HELP", do_help, NULL, -1, -1, -1, -1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("SET", do_set, is_host_setter, HOST_HELP_SET, -1, -1,
-1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("GROUP", do_group, NULL, HOST_HELP_GROUP, -1, -1, -1,
-1);
addCoreCommand(HOSTSERV, c);
c = createCommand("SETALL", do_setall, is_host_setter,
HOST_HELP_SETALL, -1, -1, -1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("DELALL", do_delall, is_host_remover,
HOST_HELP_DELALL, -1, -1, -1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("ON", do_on, NULL, HOST_HELP_ON, -1, -1, -1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("OFF", do_off, NULL, HOST_HELP_OFF, -1, -1, -1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("DEL", do_del, is_host_remover, HOST_HELP_DEL, -1,
-1, -1, -1);
addCoreCommand(HOSTSERV, c);
c = createCommand("LIST", listOut, is_services_oper, HOST_HELP_LIST,
-1, -1, -1, -1);
addCoreCommand(HOSTSERV, c);
}
/*************************************************************************/
/*************************************************************************/
/* HostServ initialization. */
void hostserv_init(void)
{
moduleAddHostServCmds();
}
/*************************************************************************/
/* Main HostServ routine. */
void hostserv(User * u, char *buf)
{
char *cmd, *s;
cmd = strtok(buf, " ");
if (!cmd) {
return;
} else if (stricmp(cmd, "\1PING") == 0) {
if (!(s = strtok(NULL, "")))
s = "\1";
notice(s_HostServ, u->nick, "\1PING %s", s);
} else if (skeleton) {
notice_lang(s_HostServ, u, SERVICE_OFFLINE, s_HostServ);
} else {
if (ircd->vhost) {
mod_run_cmd(s_HostServ, u, HOSTSERV, cmd);
} else {
notice_lang(s_HostServ, u, SERVICE_OFFLINE, s_HostServ);
}
}
}
/*************************************************************************/
/* Start of Linked List routines */
/*************************************************************************/
HostCore *createHostCorelist(HostCore * next, char *nick, char *vIdent,
char *vHost, char *creator, int32 tmp_time)
{
next = malloc(sizeof(HostCore));
if (next == NULL) {
anope_cmd_global(s_HostServ,
"Unable to allocate memory to create the vHost LL, problems i sense..");
} else {
next->nick = malloc(sizeof(char) * strlen(nick) + 1);
next->vHost = malloc(sizeof(char) * strlen(vHost) + 1);
next->creator = malloc(sizeof(char) * strlen(creator) + 1);
if (vIdent)
next->vIdent = malloc(sizeof(char) * strlen(vIdent) + 1);
if ((next->nick == NULL) || (next->vHost == NULL)
|| (next->creator == NULL)) {
anope_cmd_global(s_HostServ,
"Unable to allocate memory to create the vHost LL, problems i sense..");
return NULL;
}
strcpy(next->nick, nick);
strcpy(next->vHost, vHost);
strcpy(next->creator, creator);
if (vIdent) {
if ((next->vIdent == NULL)) {
anope_cmd_global(s_HostServ,
"Unable to allocate memory to create the vHost LL, problems i sense..");
return NULL;
}
strcpy(next->vIdent, vIdent);
} else {
next->vIdent = NULL;
}
next->time = tmp_time;
next->next = NULL;
return next;
}
return NULL;
}
/*************************************************************************/
/**
* Returns either NULL for the head, or the location of the *PREVIOUS*
* record, this is where we need to insert etc..
*
* -rob
**/
HostCore *findHostCore(HostCore * head, char *nick, boolean * found)
{
HostCore *previous, *current;
*found = false;
current = head;
previous = current;
if (!nick) {
return NULL;
}
while (current != NULL) {
if (stricmp(nick, current->nick) == 0) {
*found = true;
break;
} else if (stricmp(nick, current->nick) < 0) {
/* we know were not gonna find it now.... */
break;
} else {
previous = current;
current = current->next;
}
}
if (current == head) {
return NULL;
} else {
return previous;
}
}
/*************************************************************************/
HostCore *insertHostCore(HostCore * head, HostCore * prev, char *nick,
char *vIdent, char *vHost, char *creator,
int32 tmp_time)
{
HostCore *newCore, *tmp;
if (!nick || !vHost || !creator) {
return NULL;
}
newCore = malloc(sizeof(HostCore));
if (newCore == NULL) {
anope_cmd_global(s_HostServ,
"Unable to allocate memory to insert into the vHost LL, problems i sense..");
return NULL;
} else {
newCore->nick = malloc(sizeof(char) * strlen(nick) + 1);
newCore->vHost = malloc(sizeof(char) * strlen(vHost) + 1);
newCore->creator = malloc(sizeof(char) * strlen(creator) + 1);
if (vIdent)
newCore->vIdent = malloc(sizeof(char) * strlen(vIdent) + 1);
if ((newCore->nick == NULL) || (newCore->vHost == NULL)
|| (newCore->creator == NULL)) {
anope_cmd_global(s_HostServ,
"Unable to allocate memory to create the vHost LL, problems i sense..");
return NULL;
}
strcpy(newCore->nick, nick);
strcpy(newCore->vHost, vHost);
strcpy(newCore->creator, creator);
if (vIdent) {
if ((newCore->vIdent == NULL)) {
anope_cmd_global(s_HostServ,
"Unable to allocate memory to create the vHost LL, problems i sense..");
return NULL;
}
strcpy(newCore->vIdent, vIdent);
} else {
newCore->vIdent = NULL;
}
newCore->time = tmp_time;
if (prev == NULL) {
tmp = head;
head = newCore;
newCore->next = tmp;
} else {
tmp = prev->next;
prev->next = newCore;
newCore->next = tmp;
}
}
return head;
}
/*************************************************************************/
HostCore *deleteHostCore(HostCore * head, HostCore * prev)
{
HostCore *tmp;
if (prev == NULL) {
tmp = head;
head = head->next;
} else {
tmp = prev->next;
prev->next = tmp->next;
}
free(tmp->vHost);
free(tmp->nick);
free(tmp->creator);
if (tmp->vIdent) {
free(tmp->vIdent);
}
free(tmp);
return head;
}
/*************************************************************************/
void addHostCore(char *nick, char *vIdent, char *vhost, char *creator,
int32 tmp_time)
{
HostCore *tmp;
boolean found = false;
if (head == NULL) {
head =
createHostCorelist(head, nick, vIdent, vhost, creator,
tmp_time);
} else {
tmp = findHostCore(head, nick, &found);
if (!found) {
head =
insertHostCore(head, tmp, nick, vIdent, vhost, creator,
tmp_time);
} else {
head = deleteHostCore(head, tmp); /* delete the old entry */
addHostCore(nick, vIdent, vhost, creator, tmp_time); /* recursive call to add new entry */
}
}
}
/*************************************************************************/
char *getvHost(char *nick)
{
HostCore *tmp;
boolean found = false;
tmp = findHostCore(head, nick, &found);
if (found) {
if (tmp == NULL)
return head->vHost;
else
return tmp->next->vHost;
}
return NULL;
}
/*************************************************************************/
char *getvIdent(char *nick)
{
HostCore *tmp;
boolean found = false;
tmp = findHostCore(head, nick, &found);
if (found) {
if (tmp == NULL)
return head->vIdent;
else
return tmp->next->vIdent;
}
return NULL;
}
/*************************************************************************/
int listOut(User * u)
{
char *key = strtok(NULL, "");
struct tm *tm;
char buf[BUFSIZE];
int counter = 1;
int from = 0, to = 0;
char *tmp = NULL;
char *s = NULL;
int display_counter = 0;
HostCore *current;
current = head;
if (current == NULL)
notice_lang(s_HostServ, u, HOST_EMPTY);
else {
/**
* Do a check for a range here, then in the next loop
* we'll only display what has been requested..
**/
if (key) {
if (key[0] == '#') {
tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */
if (!tmp) {
return MOD_CONT;
}
for (s = tmp; *s; s++) {
if (!isdigit(*s)) {
return MOD_CONT;
}
}
from = atoi(tmp);
tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */
if (!tmp) {
return MOD_CONT;
}
for (s = tmp; *s; s++) {
if (!isdigit(*s)) {
return MOD_CONT;
}
}
to = atoi(tmp);
key = NULL;
}
}
while (current != NULL) {
if (key) {
if (((match_wild_nocase(key, current->nick))
|| (match_wild_nocase(key, current->vHost)))
&& (display_counter < NSListMax)) {
display_counter++;
tm = localtime(¤t->time);
strftime_lang(buf, sizeof(buf), u,
STRFTIME_DATE_TIME_FORMAT, tm);
if (current->vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
counter, current->nick,
current->vIdent, current->vHost,
current->creator, buf);
} else {
notice_lang(s_HostServ, u, HOST_ENTRY, counter,
current->nick, current->vHost,
current->creator, buf);
}
}
} else {
/**
* List the host if its in the display range, and not more
* than NSListMax records have been displayed...
**/
if ((((counter >= from) && (counter <= to))
|| ((from == 0) && (to == 0)))
&& (display_counter < NSListMax)) {
display_counter++;
tm = localtime(¤t->time);
strftime_lang(buf, sizeof(buf), u,
STRFTIME_DATE_TIME_FORMAT, tm);
if (current->vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
counter, current->nick,
current->vIdent, current->vHost,
current->creator, buf);
} else {
notice_lang(s_HostServ, u, HOST_ENTRY, counter,
current->nick, current->vHost,
current->creator, buf);
}
}
}
counter++;
current = current->next;
}
if (key) {
notice_lang(s_HostServ, u, HOST_LIST_KEY_FOOTER, key,
display_counter);
} else {
if (from != 0) {
notice_lang(s_HostServ, u, HOST_LIST_RANGE_FOOTER, from,
to);
} else {
notice_lang(s_HostServ, u, HOST_LIST_FOOTER,
display_counter);
}
}
}
return MOD_CONT;
}
/*************************************************************************/
void delHostCore(char *nick)
{
#ifdef USE_RDB
static char clause[128];
#endif
HostCore *tmp;
boolean found = false;
tmp = findHostCore(head, nick, &found);
if (found) {
head = deleteHostCore(head, tmp);
#ifdef USE_RDB
/* Reflect this change in the database right away. */
if (rdb_open()) {
snprintf(clause, sizeof(clause), "nick='%s'", nick);
rdb_scrub_table("anope_hs_core", clause);
rdb_close();
}
#endif
}
}
/*************************************************************************/
/* End of Linked List routines */
/*************************************************************************/
/*************************************************************************/
/* Start of Load/Save routines */
/*************************************************************************/
#define SAFE(x) do { \
if ((x) < 0) { \
if (!forceload) \
fatal("Read error on %s", HostDBName); \
failed = 1; \
break; \
} \
} while (0)
void load_hs_dbase(void)
{
dbFILE *f;
int ver;
if (!(f = open_db(s_HostServ, HostDBName, "r", HOST_VERSION))) {
return;
}
ver = get_file_version(f);
if (ver == 1) {
load_hs_dbase_v1(f);
} else if (ver == 2) {
load_hs_dbase_v2(f);
} else if (ver == 3) {
load_hs_dbase_v3(f);
}
close_db(f);
}
void load_hs_dbase_v1(dbFILE * f)
{
int c;
int failed = 0;
int32 tmp;
char *nick;
char *vHost;
tmp = time(NULL);
while (!failed && (c = getc_db(f)) == 1) {
if (c == 1) {
SAFE(read_string(&nick, f));
SAFE(read_string(&vHost, f));
addHostCore(nick, NULL, vHost, "Unknown", tmp); /* could get a speed increase by not searching the list */
free(nick); /* as we know the db is in alphabetical order... */
free(vHost);
} else {
fatal("Invalid format in %s %d", HostDBName, c);
}
}
}
void load_hs_dbase_v2(dbFILE * f)
{
int c;
int failed = 0;
char *nick;
char *vHost;
char *creator;
int32 time;
while (!failed && (c = getc_db(f)) == 1) {
if (c == 1) {
SAFE(read_string(&nick, f));
SAFE(read_string(&vHost, f));
SAFE(read_string(&creator, f));
SAFE(read_int32(&time, f));
addHostCore(nick, NULL, vHost, creator, time); /* could get a speed increase by not searching the list */
free(nick); /* as we know the db is in alphabetical order... */
free(vHost);
free(creator);
} else {
fatal("Invalid format in %s %d", HostDBName, c);
}
}
}
void load_hs_dbase_v3(dbFILE * f)
{
int c;
int failed = 0;
char *nick;
char *vHost;
char *creator;
char *vIdent;
int32 time;
while (!failed && (c = getc_db(f)) == 1) {
if (c == 1) {
SAFE(read_string(&nick, f));
SAFE(read_string(&vIdent, f));
SAFE(read_string(&vHost, f));
SAFE(read_string(&creator, f));
SAFE(read_int32(&time, f));
addHostCore(nick, vIdent, vHost, creator, time); /* could get a speed increase by not searching the list */
free(nick); /* as we know the db is in alphabetical order... */
free(vHost);
free(creator);
free(vIdent);
} else {
fatal("Invalid format in %s %d", HostDBName, c);
}
}
}
#undef SAFE
/*************************************************************************/
#define SAFE(x) do { \
if ((x) < 0) { \
restore_db(f); \
log_perror("Write error on %s", HostDBName); \
if (time(NULL) - lastwarn > WarningTimeout) { \
anope_cmd_global(NULL, "Write error on %s: %s", HostDBName, \
strerror(errno)); \
lastwarn = time(NULL); \
} \
return; \
} \
} while (0)
void save_hs_dbase(void)
{
dbFILE *f;
static time_t lastwarn = 0;
HostCore *current;
if (!(f = open_db(s_HostServ, HostDBName, "w", HOST_VERSION)))
return;
current = head;
while (current != NULL) {
SAFE(write_int8(1, f));
SAFE(write_string(current->nick, f));
SAFE(write_string(current->vIdent, f));
SAFE(write_string(current->vHost, f));
SAFE(write_string(current->creator, f));
SAFE(write_int32(current->time, f));
current = current->next;
}
SAFE(write_int8(0, f));
close_db(f);
}
#undef SAFE
void save_hs_rdb_dbase(void)
{
#ifdef USE_RDB
HostCore *current;
if (!rdb_open())
return;
rdb_clear_table("anope_hs_core");
current = head;
while (current != NULL) {
rdb_save_hs_core(current);
current = current->next;
}
rdb_close();
#endif
}
/*************************************************************************/
/* End of Load/Save Functions */
/*************************************************************************/
/*************************************************************************/
/* Start of Generic Functions */
/*************************************************************************/
int do_setall(User * u)
{
char *nick = strtok(NULL, " ");
char *rawhostmask = strtok(NULL, " ");
char *hostmask = smalloc(HOSTMAX);
NickAlias *na;
int32 tmp_time;
char *s;
char *vIdent = NULL;
if (!nick || !rawhostmask) {
notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ);
return MOD_CONT;
}
vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */
if (vIdent) {
rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */
if (!rawhostmask) {
notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ);
return MOD_CONT;
}
if (strlen(vIdent) > USERMAX - 1) {
notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
return MOD_CONT;
} else {
for (s = vIdent; *s; s++) {
if (!isvalidchar(*s)) {
notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
return MOD_CONT;
}
}
}
if (!ircd->vident) {
notice_lang(s_HostServ, u, HOST_NO_VIDENT);
return MOD_CONT;
}
}
if (strlen(rawhostmask) < HOSTMAX - 1)
snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask);
else {
notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
return MOD_CONT;
}
if (!isValidHost(hostmask, 3)) {
notice_lang(s_HostServ, u, HOST_SET_ERROR);
return MOD_CONT;
}
tmp_time = time(NULL);
if ((na = findnick(nick))) {
if (na->status & NS_VERBOTEN) {
notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
return MOD_CONT;
}
if (vIdent && ircd->vident) {
alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
} else {
alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
}
do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time);
if (vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent,
hostmask);
} else {
notice_lang(s_HostServ, u, HOST_SETALL, nick, hostmask);
}
} else {
notice_lang(s_HostServ, u, HOST_NOREG, nick);
}
free(hostmask);
return MOD_CONT;
}
int do_delall(User * u)
{
int i;
char *nick = strtok(NULL, " ");
NickAlias *na;
NickCore *nc;
if (!nick) {
notice_lang(s_HostServ, u, HOST_DELALL_SYNTAX, s_HostServ);
return MOD_CONT;
}
if ((na = findnick(nick))) {
if (na->status & NS_VERBOTEN) {
notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
return MOD_CONT;
}
nc = na->nc;
for (i = 0; i < nc->aliases.count; i++) {
na = nc->aliases.list[i];
delHostCore(na->nick);
}
alog("vHosts for all nicks in group \002%s\002 deleted by oper \002%s\002", nc->display, u->nick);
notice_lang(s_HostServ, u, HOST_DELALL, nc->display);
} else {
notice_lang(s_HostServ, u, HOST_NOREG, nick);
}
return MOD_CONT;
}
int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, char *creator,
time_t time)
{
int i;
NickAlias *na;
for (i = 0; i < nc->aliases.count; i++) {
na = nc->aliases.list[i];
addHostCore(na->nick, vIdent, hostmask, creator, time);
}
return MOD_CONT;
}
static int do_group(User * u)
{
NickAlias *na;
HostCore *tmp;
char *vHost = NULL;
char *vIdent = NULL;
char *creator = NULL;
time_t time;
boolean found = false;
if ((na = findnick(u->nick))) {
if (na->status & NS_IDENTIFIED) {
tmp = findHostCore(head, u->nick, &found);
if (found) {
if (tmp == NULL) {
tmp = head; /* incase first in list */
} else if (tmp->next) { /* we dont want the previous entry were not inserting! */
tmp = tmp->next; /* jump to the next */
}
vHost = sstrdup(tmp->vHost);
if (tmp->vIdent)
vIdent = sstrdup(tmp->vIdent);
creator = sstrdup(tmp->creator);
time = tmp->time;
do_hs_sync(na->nc, vIdent, vHost, creator, time);
if (tmp->vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_GROUP,
na->nc->display, vIdent, vHost);
} else {
notice_lang(s_HostServ, u, HOST_GROUP, na->nc->display,
vHost);
}
free(vHost);
if (vIdent)
free(vIdent);
free(creator);
} else {
notice_lang(s_HostServ, u, HOST_NOT_ASSIGNED);
}
} else {
notice_lang(s_HostServ, u, HOST_ID);
}
} else {
notice_lang(s_HostServ, u, HOST_NOT_REGED);
}
return MOD_CONT;
}
static int do_help(User * u)
{
char *cmd = strtok(NULL, "");
if (!cmd) {
notice_help(s_HostServ, u, HOST_HELP, s_HostServ);
if ((is_services_oper(u)) || (is_host_setter(u)))
notice_help(s_HostServ, u, HOST_OPER_HELP);
/* Removed as atm, there is no admin only help */
/* if (is_services_admin(u))
notice_help(s_HostServ, u, HOST_ADMIN_HELP);*/
moduleDisplayHelp(6, u);
} else {
mod_help_cmd(s_HostServ, u, HOSTSERV, cmd);
}
return MOD_CONT;
}
/*************************************************************************/
int do_set(User * u)
{
char *nick = strtok(NULL, " ");
char *rawhostmask = strtok(NULL, " ");
char *hostmask = smalloc(HOSTMAX);
NickAlias *na;
int32 tmp_time;
char *s;
char *vIdent = NULL;
if (!nick || !rawhostmask) {
notice_lang(s_HostServ, u, HOST_SET_SYNTAX, s_HostServ);
return MOD_CONT;
}
vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */
if (vIdent) {
rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */
if (!rawhostmask) {
notice_lang(s_HostServ, u, HOST_SET_SYNTAX, s_HostServ);
return MOD_CONT;
}
if (strlen(vIdent) > USERMAX - 1) {
notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
return MOD_CONT;
} else {
for (s = vIdent; *s; s++) {
if (!isvalidchar(*s)) {
notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
return MOD_CONT;
}
}
}
if (!ircd->vident) {
notice_lang(s_HostServ, u, HOST_NO_VIDENT);
return MOD_CONT;
}
}
if (strlen(rawhostmask) < HOSTMAX - 1)
snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask);
else {
notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
return MOD_CONT;
}
if (!isValidHost(hostmask, 3)) {
notice_lang(s_HostServ, u, HOST_SET_ERROR);
return MOD_CONT;
}
tmp_time = time(NULL);
if ((na = findnick(nick))) {
if (na->status & NS_VERBOTEN) {
notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
return MOD_CONT;
}
if (vIdent && ircd->vident) {
alog("vHost for user \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
} else {
alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
}
addHostCore(nick, vIdent, hostmask, u->nick, tmp_time);
if (vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_SET, nick, vIdent,
hostmask);
} else {
notice_lang(s_HostServ, u, HOST_SET, nick, hostmask);
}
} else {
notice_lang(s_HostServ, u, HOST_NOREG, nick);
}
free(hostmask);
return MOD_CONT;
}
/*************************************************************************/
int do_on(User * u)
{
NickAlias *na;
char *vHost;
char *vIdent = NULL;
if ((na = findnick(u->nick))) {
if (na->status & NS_IDENTIFIED) {
vHost = getvHost(u->nick);
vIdent = getvIdent(u->nick);
if (vHost == NULL) {
notice_lang(s_HostServ, u, HOST_NOT_ASSIGNED);
} else {
if (vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_ACTIVATED,
vIdent, vHost);
} else {
notice_lang(s_HostServ, u, HOST_ACTIVATED, vHost);
}
anope_cmd_vhost_on(u->nick, vIdent, vHost);
if (ircd->vhost) {
u->vhost = sstrdup(vHost);
}
if (ircd->vident) {
if (vIdent)
u->vident = sstrdup(vIdent);
}
set_lastmask(u);
}
} else {
notice_lang(s_HostServ, u, HOST_ID);
}
} else {
notice_lang(s_HostServ, u, HOST_NOT_REGED);
}
return MOD_CONT;
}
/*************************************************************************/
int do_on_id(User * u)
{ /* we've assumed that the user exists etc.. */
char *vHost; /* as were only gonna call this from nsid routine */
char *vIdent;
vHost = getvHost(u->nick);
vIdent = getvIdent(u->nick);
if (vHost != NULL) {
if (vIdent) {
notice_lang(s_HostServ, u, HOST_IDENT_ACTIVATED, vIdent,
vHost);
} else {
notice_lang(s_HostServ, u, HOST_ACTIVATED, vHost);
}
anope_cmd_vhost_on(u->nick, vIdent, vHost);
if (ircd->vhost) {
u->vhost = sstrdup(vHost);
}
if (ircd->vident) {
if (vIdent)
u->vident = sstrdup(vIdent);
}
set_lastmask(u);
}
return MOD_CONT;
}
/*************************************************************************/
int do_del(User * u)
{
NickAlias *na;
char *nick = strtok(NULL, " ");
if (nick) {
if ((na = findnick(nick))) {
if (na->status & NS_VERBOTEN) {
notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
return MOD_CONT;
}
alog("vHost for user \002%s\002 deleted by oper \002%s\002",
nick, u->nick);
delHostCore(nick);
notice_lang(s_HostServ, u, HOST_DEL, nick);
} else {
notice_lang(s_HostServ, u, HOST_NOREG, nick);
}
} else {
notice_lang(s_HostServ, u, HOST_DEL_SYNTAX, s_HostServ);
}
return MOD_CONT;
}
/*************************************************************************/
int do_off(User * u)
{
/* put any generic code here... :) */
anope_cmd_vhost_off(u);
return MOD_CONT;
}
int is_host_setter(User * u)
{
int i, j;
NickAlias *na;
if (is_services_oper(u)) {
return 1;
}
if (!nick_identified(u)) {
return 0;
}
/* Look through all user's aliases (0000412) */
for (i = 0; i < u->na->nc->aliases.count; i++) {
na = u->na->nc->aliases.list[i];
for (j = 0; j < HostNumber; j++) {
if (stricmp(HostSetters[j], na->nick) == 0) {
return 1;
}
}
}
return 0;
}
int is_host_remover(User * u)
{
return is_host_setter(u); /* only here incase we want to split them up later */
}
/*
* Sets the last_usermak properly. Using virtual ident and/or host
*/
void set_lastmask(User * u)
{
if (u->na->last_usermask)
free(u->na->last_usermask);
u->na->last_usermask =
smalloc(strlen(common_get_vident(u)) +
strlen(common_get_vhost(u)) + 2);
sprintf(u->na->last_usermask, "%s@%s", common_get_vident(u),
common_get_vhost(u));
}
/*************************************************************************/
/* End of Generic Functions */
/*************************************************************************/
/*************************************************************************/
/* End of Server Functions */
/*************************************************************************/
|