-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnuts333.c
7956 lines (7223 loc) · 206 KB
/
nuts333.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
/*****************************************************************************
NUTS version 3.3.3 (Triple Three :) - Copyright (C) Neil Robertson 1996
Last update: 18th November 1996
This software is provided as is. It is not intended as any sort of bullet
proof system for commercial operation (though you may use it to set up a
pay-to-use system, just don't attempt to sell the code itself) and I accept
no liability for any problems that may arise from you using it. Since this is
freeware (NOT public domain , I have not relinquished the copyright) you may
distribute it as you see fit and you may alter the code to suit your needs.
Read the COPYRIGHT file for further information.
Neil Robertson.
Email : [email protected]
Home page: http://www.wso.co.uk/neil.html (need JavaScript enabled browser)
NUTS page: http://www.wso.co.uk/nuts.html
Newsgroup: alt.talkers.nuts
NB: This program listing looks best when the tab length is 5 chars which is
"set ts=5" in vi.
*****************************************************************************/
#include <stdio.h>
#ifdef _AIX
#include <sys/select.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <unistd.h>
#include <setjmp.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <ctype.h>
#include "nuts333.h"
#define VERSION "3.3.3"
/*** This function calls all the setup routines and also contains the
main program loop ***/
int main(argc,argv)
int argc;
char *argv[];
{
fd_set readmask;
int i,len;
char inpstr[ARR_SIZE];
UR_OBJECT user,next;
NL_OBJECT nl;
strcpy(progname,argv[0]);
if (argc<2) strcpy(confile,CONFIGFILE);
else strcpy(confile,argv[1]);
/* Startup */
printf("\n*** NUTS %s server booting ***\n\n",VERSION);
init_globals();
write_syslog("\n*** SERVER BOOTING ***\n",0);
set_date_time();
init_signals();
load_and_parse_config();
init_sockets();
if (auto_connect) init_connections();
else printf("Skipping connect stage.\n");
check_messages(NULL,1);
/* Run in background automatically. */
switch(fork()) {
case -1: boot_exit(11); /* fork failure */
case 0: break; /* child continues */
default: sleep(1); exit(0); /* parent dies */
}
reset_alarm();
printf("\n*** Booted with PID %d ***\n\n",getpid());
sprintf(text,"*** Booted successfully with PID %d %s ***\n\n",getpid(),long_date(1));
write_syslog(text,0);
/**** Main program loop. *****/
setjmp(jmpvar); /* jump to here if we crash and crash_action = IGNORE */
while(1) {
/* set up mask then wait */
setup_readmask(&readmask);
if (select(FD_SETSIZE,&readmask,0,0,0)==-1) continue;
/* check for connection to listen sockets */
for(i=0;i<3;++i) {
if (FD_ISSET(listen_sock[i],&readmask))
accept_connection(listen_sock[i],i);
}
/* Cycle through client-server connections to other talkers */
for(nl=nl_first;nl!=NULL;nl=nl->next) {
no_prompt=0;
if (nl->type==UNCONNECTED || !FD_ISSET(nl->socket,&readmask))
continue;
/* See if remote site has disconnected */
if (!(len=read(nl->socket,inpstr,sizeof(inpstr)-3))) {
if (nl->stage==UP)
sprintf(text,"NETLINK: Remote disconnect by %s.\n",nl->service);
else sprintf(text,"NETLINK: Remote disconnect by site %s.\n",nl->site);
write_syslog(text,1);
sprintf(text,"~OLSYSTEM:~RS Lost link to %s in the %s.\n",nl->service,nl->connect_room->name);
write_room(NULL,text);
shutdown_netlink(nl);
continue;
}
inpstr[len]='\0';
exec_netcom(nl,inpstr);
}
/* Cycle through users. Use a while loop instead of a for because
user structure may be destructed during loop in which case we
may lose the user->next link. */
user=user_first;
while(user!=NULL) {
next=user->next; /* store in case user object is destructed */
/* If remote user or clone ignore */
if (user->type!=USER_TYPE) { user=next; continue; }
/* see if any data on socket else continue */
if (!FD_ISSET(user->socket,&readmask)) { user=next; continue; }
/* see if client (eg telnet) has closed socket */
inpstr[0]='\0';
if (!(len=read(user->socket,inpstr,sizeof(inpstr)))) {
disconnect_user(user); user=next;
continue;
}
/* ignore control code replies */
if ((unsigned char)inpstr[0]==255) { user=next; continue; }
/* Deal with input chars. If the following if test succeeds we
are dealing with a character mode client so call function. */
if (inpstr[len-1]>=32 || user->buffpos) {
if (get_charclient_line(user,inpstr,len)) goto GOT_LINE;
user=next; continue;
}
else terminate(inpstr);
GOT_LINE:
no_prompt=0;
com_num=-1;
force_listen=0;
destructed=0;
user->buff[0]='\0';
user->buffpos=0;
user->last_input=time(0);
if (user->login) {
login(user,inpstr); user=next; continue;
}
/* If a dot on its own then execute last inpstr unless its a misc
op or the user is on a remote site */
if (!user->misc_op) {
if (!strcmp(inpstr,".") && user->inpstr_old[0]) {
strcpy(inpstr,user->inpstr_old);
sprintf(text,"%s\n",inpstr);
write_user(user,text);
}
/* else save current one for next time */
else {
if (inpstr[0]) strncpy(user->inpstr_old,inpstr,REVIEW_LEN);
}
}
/* Main input check */
clear_words();
word_count=wordfind(inpstr);
if (user->afk) {
if (user->afk==2) {
if (!word_count) {
if (user->command_mode) prompt(user);
user=next; continue;
}
if (strcmp((char *)crypt(word[0],"NU"),user->pass)) {
write_user(user,"Incorrect password.\n");
prompt(user); user=next; continue;
}
cls(user);
write_user(user,"Session unlocked, you are no longer AFK.\n");
}
else write_user(user,"You are no longer AFK.\n");
user->afk_mesg[0]='\0';
if (user->vis) {
sprintf(text,"%s comes back from being AFK.\n",user->name);
write_room_except(user->room,text,user);
}
if (user->afk==2) {
user->afk=0; prompt(user); user=next; continue;
}
user->afk=0;
}
if (!word_count) {
if (misc_ops(user,inpstr)) { user=next; continue; }
if (user->room==NULL) {
sprintf(text,"ACT %s NL\n",user->name);
write_sock(user->netlink->socket,text);
}
if (user->command_mode) prompt(user);
user=next; continue;
}
if (misc_ops(user,inpstr)) { user=next; continue; }
com_num=-1;
if (user->command_mode || strchr(".;!<>-#",inpstr[0]))
exec_com(user,inpstr);
else say(user,inpstr);
if (!destructed) {
if (user->room!=NULL) prompt(user);
else {
switch((int)com_num) {
case -1 : /* Unknown command */
case HOME:
case QUIT:
case MODE:
case PROMPT:
case SUICIDE:
case REBOOT:
case SHUTDOWN: prompt(user); break;
default: break;
}
}
}
user=next;
}
} /* end while */
}
/************ MAIN LOOP FUNCTIONS ************/
/*** Set up readmask for select ***/
void setup_readmask(mask)
fd_set *mask;
{
UR_OBJECT user;
NL_OBJECT nl;
int i;
FD_ZERO(mask);
for(i=0;i<3;++i) FD_SET(listen_sock[i],mask);
/* Do users */
for (user=user_first;user!=NULL;user=user->next)
if (user->type==USER_TYPE) FD_SET(user->socket,mask);
/* Do client-server stuff */
for(nl=nl_first;nl!=NULL;nl=nl->next)
if (nl->type!=UNCONNECTED) FD_SET(nl->socket,mask);
}
/*** Accept incoming connections on listen sockets ***/
void accept_connection(lsock,num)
int lsock,num;
{
UR_OBJECT user,create_user();
NL_OBJECT create_netlink();
char site[80];
struct sockaddr_in acc_addr;
int accept_sock;
unsigned int size;
size=sizeof(struct sockaddr_in);
accept_sock=accept(lsock,(struct sockaddr *)&acc_addr,&size);
if (num==2) {
accept_server_connection(accept_sock,acc_addr); return;
}
strcpy(site,get_ip_address(acc_addr));
if (site_banned(site)) {
write_sock(accept_sock,"\n\rLogins from your site/domain are banned.\n\n\r");
close(accept_sock);
sprintf(text,"Attempted login from banned site %s.\n",site);
write_syslog(text,1);
return;
}
more(NULL,accept_sock,MOTD1); /* send pre-login message */
if (num_of_users+num_of_logins>=max_users && !num) {
write_sock(accept_sock,"\n\rSorry, the talker is full at the moment.\n\n\r");
close(accept_sock);
return;
}
if ((user=create_user())==NULL) {
sprintf(text,"\n\r%s: unable to create session.\n\n\r",syserror);
write_sock(accept_sock,text);
close(accept_sock);
return;
}
user->socket=accept_sock;
user->login=3;
user->last_input=time(0);
if (!num) user->port=port[0];
else {
user->port=port[1];
write_user(user,"** Wizport login **\n\n");
}
strcpy(user->site,site);
user->site_port=(int)ntohs(acc_addr.sin_port);
echo_on(user);
write_user(user,"Give me a name: ");
num_of_logins++;
}
/*** Get net address of accepted connection ***/
char *get_ip_address(acc_addr)
struct sockaddr_in acc_addr;
{
static char site[80];
struct hostent *host;
strcpy(site,(char *)inet_ntoa(acc_addr.sin_addr)); /* get number addr */
if ((host=gethostbyaddr((char *)&acc_addr.sin_addr,4,AF_INET))!=NULL)
strcpy(site,host->h_name); /* copy name addr. */
strtolower(site);
return site;
}
/*** See if users site is banned ***/
int site_banned(site)
char *site;
{
FILE *fp;
char line[82],filename[80];
sprintf(filename,"%s/%s",DATAFILES,SITEBAN);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",line);
while(!feof(fp)) {
if (strstr(site,line)) { fclose(fp); return 1; }
fscanf(fp,"%s",line);
}
fclose(fp);
return 0;
}
/*** See if user is banned ***/
int user_banned(name)
char *name;
{
FILE *fp;
char line[82],filename[80];
sprintf(filename,"%s/%s",DATAFILES,USERBAN);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",line);
while(!feof(fp)) {
if (!strcmp(line,name)) { fclose(fp); return 1; }
fscanf(fp,"%s",line);
}
fclose(fp);
return 0;
}
/*** Attempt to get '\n' terminated line of input from a character
mode client else store data read so far in user buffer. ***/
int get_charclient_line(user,inpstr,len)
UR_OBJECT user;
char *inpstr;
int len;
{
int l;
for(l=0;l<len;++l) {
/* see if delete entered */
if (inpstr[l]==8 || inpstr[l]==127) {
if (user->buffpos) {
user->buffpos--;
if (user->charmode_echo) write_user(user,"\b \b");
}
continue;
}
user->buff[user->buffpos]=inpstr[l];
/* See if end of line */
if (inpstr[l]<32 || user->buffpos+2==ARR_SIZE) {
terminate(user->buff);
strcpy(inpstr,user->buff);
if (user->charmode_echo) write_user(user,"\n");
return 1;
}
user->buffpos++;
}
if (user->charmode_echo
&& ((user->login!=2 && user->login!=1) || password_echo))
write(user->socket,inpstr,len);
return 0;
}
/*** Put string terminate char. at first char < 32 ***/
void terminate(str)
char *str;
{
int i;
for (i=0;i<ARR_SIZE;++i) {
if (*(str+i)<32) { *(str+i)=0; return; }
}
str[i-1]=0;
}
/*** Get words from sentence. This function prevents the words in the
sentence from writing off the end of a word array element. This is
difficult to do with sscanf() hence I use this function instead. ***/
int wordfind(inpstr)
char *inpstr;
{
int wn,wpos;
wn=0; wpos=0;
do {
while(*inpstr<33) if (!*inpstr++) return wn;
while(*inpstr>32 && wpos<WORD_LEN-1) {
word[wn][wpos]=*inpstr++; wpos++;
}
word[wn][wpos]='\0';
wn++; wpos=0;
} while (wn<MAX_WORDS);
return wn-1;
}
/*** clear word array etc. ***/
void clear_words()
{
int w;
for(w=0;w<MAX_WORDS;++w) word[w][0]='\0';
word_count=0;
}
/************ PARSE CONFIG FILE **************/
void load_and_parse_config()
{
FILE *fp;
char line[81]; /* Should be long enough */
char c,filename[80];
int i,section_in,got_init,got_rooms;
RM_OBJECT rm1,rm2;
NL_OBJECT nl;
section_in=0;
got_init=0;
got_rooms=0;
sprintf(filename,"%s/%s",DATAFILES,confile);
printf("Parsing config file \"%s\"...\n",filename);
if (!(fp=fopen(filename,"r"))) {
perror("NUTS: Can't open config file"); boot_exit(1);
}
/* Main reading loop */
config_line=0;
fgets(line,81,fp);
while(!feof(fp)) {
config_line++;
for(i=0;i<8;++i) wrd[i][0]='\0';
sscanf(line,"%s %s %s %s %s %s %s %s",wrd[0],wrd[1],wrd[2],wrd[3],wrd[4],wrd[5],wrd[6],wrd[7]);
if (wrd[0][0]=='#' || wrd[0][0]=='\0') {
fgets(line,81,fp); continue;
}
/* See if new section */
if (wrd[0][strlen(wrd[0])-1]==':') {
if (!strcmp(wrd[0],"INIT:")) section_in=1;
else if (!strcmp(wrd[0],"ROOMS:")) section_in=2;
else if (!strcmp(wrd[0],"SITES:")) section_in=3;
else {
fprintf(stderr,"NUTS: Unknown section header on line %d.\n",config_line);
fclose(fp); boot_exit(1);
}
}
switch(section_in) {
case 1: parse_init_section(); got_init=1; break;
case 2: parse_rooms_section(); got_rooms=1; break;
case 3: parse_sites_section(); break;
default:
fprintf(stderr,"NUTS: Section header expected on line %d.\n",config_line);
boot_exit(1);
}
fgets(line,81,fp);
}
fclose(fp);
/* See if required sections were present (SITES is optional) and if
required parameters were set. */
if (!got_init) {
fprintf(stderr,"NUTS: INIT section missing from config file.\n");
boot_exit(1);
}
if (!got_rooms) {
fprintf(stderr,"NUTS: ROOMS section missing from config file.\n");
boot_exit(1);
}
if (!verification[0]) {
fprintf(stderr,"NUTS: Verification not set in config file.\n");
boot_exit(1);
}
if (!port[0]) {
fprintf(stderr,"NUTS: Main port number not set in config file.\n");
boot_exit(1);
}
if (!port[1]) {
fprintf(stderr,"NUTS: Wiz port number not set in config file.\n");
boot_exit(1);
}
if (!port[2]) {
fprintf(stderr,"NUTS: Link port number not set in config file.\n");
boot_exit(1);
}
if (port[0]==port[1] || port[1]==port[2] || port[0]==port[2]) {
fprintf(stderr,"NUTS: Port numbers must be unique.\n");
boot_exit(1);
}
if (room_first==NULL) {
fprintf(stderr,"NUTS: No rooms configured in config file.\n");
boot_exit(1);
}
/* Parsing done, now check data is valid. Check room stuff first. */
for(rm1=room_first;rm1!=NULL;rm1=rm1->next) {
for(i=0;i<MAX_LINKS;++i) {
if (!rm1->link_label[i][0]) break;
for(rm2=room_first;rm2!=NULL;rm2=rm2->next) {
if (rm1==rm2) continue;
if (!strcmp(rm1->link_label[i],rm2->label)) {
rm1->link[i]=rm2; break;
}
}
if (rm1->link[i]==NULL) {
fprintf(stderr,"NUTS: Room %s has undefined link label '%s'.\n",rm1->name,rm1->link_label[i]);
boot_exit(1);
}
}
}
/* Check external links */
for(rm1=room_first;rm1!=NULL;rm1=rm1->next) {
for(nl=nl_first;nl!=NULL;nl=nl->next) {
if (!strcmp(nl->service,rm1->name)) {
fprintf(stderr,"NUTS: Service name %s is also the name of a room.\n",nl->service);
boot_exit(1);
}
if (rm1->netlink_name[0]
&& !strcmp(rm1->netlink_name,nl->service)) {
rm1->netlink=nl; break;
}
}
if (rm1->netlink_name[0] && rm1->netlink==NULL) {
fprintf(stderr,"NUTS: Service name %s not defined for room %s.\n",rm1->netlink_name,rm1->name);
boot_exit(1);
}
}
/* Load room descriptions */
for(rm1=room_first;rm1!=NULL;rm1=rm1->next) {
sprintf(filename,"%s/%s.R",DATAFILES,rm1->name);
if (!(fp=fopen(filename,"r"))) {
fprintf(stderr,"NUTS: Can't open description file for room %s.\n",rm1->name);
sprintf(text,"ERROR: Couldn't open description file for room %s.\n",rm1->name);
write_syslog(text,0);
continue;
}
i=0;
c=getc(fp);
while(!feof(fp)) {
if (i==ROOM_DESC_LEN) {
fprintf(stderr,"NUTS: Description too long for room %s.\n",rm1->name);
sprintf(text,"ERROR: Description too long for room %s.\n",rm1->name);
write_syslog(text,0);
break;
}
rm1->desc[i]=c;
c=getc(fp); ++i;
}
rm1->desc[i]='\0';
fclose(fp);
}
}
/*** Parse init section ***/
void parse_init_section()
{
static int in_section=0;
int op,val;
char *options[]={
"mainport","wizport","linkport","system_logging","minlogin_level","mesg_life",
"wizport_level","prompt_def","gatecrash_level","min_private","ignore_mp_level",
"rem_user_maxlevel","rem_user_deflevel","verification","mesg_check_time",
"max_users","heartbeat","login_idle_time","user_idle_time","password_echo",
"ignore_sigterm","auto_connect","max_clones","ban_swearing","crash_action",
"colour_def","time_out_afks","allow_caps_in_name","charecho_def",
"time_out_maxlevel","*"
};
if (!strcmp(wrd[0],"INIT:")) {
if (++in_section>1) {
fprintf(stderr,"NUTS: Unexpected INIT section header on line %d.\n",config_line);
boot_exit(1);
}
return;
}
op=0;
while(strcmp(options[op],wrd[0])) {
if (options[op][0]=='*') {
fprintf(stderr,"NUTS: Unknown INIT option on line %d.\n",config_line);
boot_exit(1);
}
++op;
}
if (!wrd[1][0]) {
fprintf(stderr,"NUTS: Required parameter missing on line %d.\n",config_line);
boot_exit(1);
}
if (wrd[2][0] && wrd[2][0]!='#') {
fprintf(stderr,"NUTS: Unexpected word following init parameter on line %d.\n",config_line);
boot_exit(1);
}
val=atoi(wrd[1]);
switch(op) {
case 0: /* main port */
case 1:
case 2:
if ((port[op]=val)<1 || val>65535) {
fprintf(stderr,"NUTS: Illegal port number on line %d.\n",config_line);
boot_exit(1);
}
return;
case 3:
if ((system_logging=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: System_logging must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 4:
if ((minlogin_level=get_level(wrd[1]))==-1) {
if (strcmp(wrd[1],"NONE")) {
fprintf(stderr,"NUTS: Unknown level specifier for minlogin_level on line %d.\n",config_line);
boot_exit(1);
}
minlogin_level=-1;
}
return;
case 5: /* message lifetime */
if ((mesg_life=val)<1) {
fprintf(stderr,"NUTS: Illegal message lifetime on line %d.\n",config_line);
boot_exit(1);
}
return;
case 6: /* wizport_level */
if ((wizport_level=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier for wizport_level on line %d.\n",config_line);
boot_exit(1);
}
return;
case 7: /* prompt defaults */
if ((prompt_def=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Prompt_def must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 8: /* gatecrash level */
if ((gatecrash_level=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier for gatecrash_level on line %d.\n",config_line);
boot_exit(1);
}
return;
case 9:
if (val<1) {
fprintf(stderr,"NUTS: Number too low for min_private_users on line %d.\n",config_line);
boot_exit(1);
}
min_private_users=val;
return;
case 10:
if ((ignore_mp_level=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier for ignore_mp_level on line %d.\n",config_line);
boot_exit(1);
}
return;
case 11:
/* Max level a remote user can remotely log in if he doesn't have a local
account. ie if level set to WIZ a GOD can only be a WIZ if logging in
from another server unless he has a local account of level GOD */
if ((rem_user_maxlevel=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier for rem_user_maxlevel on line %d.\n",config_line);
boot_exit(1);
}
return;
case 12:
/* Default level of remote user who does not have an account on site and
connection is from a server of version 3.3.0 or lower. */
if ((rem_user_deflevel=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier for rem_user_deflevel on line %d.\n",config_line);
boot_exit(1);
}
return;
case 13:
if (strlen(wrd[1])>VERIFY_LEN) {
fprintf(stderr,"NUTS: Verification too long on line %d.\n",config_line);
boot_exit(1);
}
strcpy(verification,wrd[1]);
return;
case 14: /* mesg_check_time */
if (wrd[1][2]!=':'
|| strlen(wrd[1])>5
|| !isdigit(wrd[1][0])
|| !isdigit(wrd[1][1])
|| !isdigit(wrd[1][3])
|| !isdigit(wrd[1][4])) {
fprintf(stderr,"NUTS: Invalid message check time on line %d.\n",config_line);
boot_exit(1);
}
sscanf(wrd[1],"%d:%d",&mesg_check_hour,&mesg_check_min);
if (mesg_check_hour>23 || mesg_check_min>59) {
fprintf(stderr,"NUTS: Invalid message check time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 15:
if ((max_users=val)<1) {
fprintf(stderr,"NUTS: Invalid value for max_users on line %d.\n",config_line);
boot_exit(1);
}
return;
case 16:
if ((heartbeat=val)<1) {
fprintf(stderr,"NUTS: Invalid value for heartbeat on line %d.\n",config_line);
boot_exit(1);
}
return;
case 17:
if ((login_idle_time=val)<10) {
fprintf(stderr,"NUTS: Invalid value for login_idle_time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 18:
if ((user_idle_time=val)<10) {
fprintf(stderr,"NUTS: Invalid value for user_idle_time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 19:
if ((password_echo=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Password_echo must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 20:
if ((ignore_sigterm=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Ignore_sigterm must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 21:
if ((auto_connect=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Auto_connect must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 22:
if ((max_clones=val)<0) {
fprintf(stderr,"NUTS: Invalid value for max_clones on line %d.\n",config_line);
boot_exit(1);
}
return;
case 23:
if ((ban_swearing=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Ban_swearing must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 24:
if (!strcmp(wrd[1],"NONE")) crash_action=0;
else if (!strcmp(wrd[1],"IGNORE")) crash_action=1;
else if (!strcmp(wrd[1],"REBOOT")) crash_action=2;
else {
fprintf(stderr,"NUTS: Crash_action must be NONE, IGNORE or REBOOT on line %d.\n",config_line);
boot_exit(1);
}
return;
case 25:
if ((colour_def=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Colour_def must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 26:
if ((time_out_afks=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Time_out_afks must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 27:
if ((allow_caps_in_name=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Allow_caps_in_name must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 28:
if ((charecho_def=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Charecho_def must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 29:
if ((time_out_maxlevel=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier for time_out_maxlevel on line %d.\n",config_line);
boot_exit(1);
}
return;
}
}
/*** Parse rooms section ***/
void parse_rooms_section()
{
static int in_section=0;
int i;
char *ptr1,*ptr2,c;
RM_OBJECT room;
if (!strcmp(wrd[0],"ROOMS:")) {
if (++in_section>1) {
fprintf(stderr,"NUTS: Unexpected ROOMS section header on line %d.\n",config_line);
boot_exit(1);
}
return;
}
if (!wrd[2][0]) {
fprintf(stderr,"NUTS: Required parameter(s) missing on line %d.\n",config_line);
boot_exit(1);
}
if (strlen(wrd[0])>ROOM_LABEL_LEN) {
fprintf(stderr,"NUTS: Room label too long on line %d.\n",config_line);
boot_exit(1);
}
if (strlen(wrd[1])>ROOM_NAME_LEN) {
fprintf(stderr,"NUTS: Room name too long on line %d.\n",config_line);
boot_exit(1);
}
/* Check for duplicate label or name */
for(room=room_first;room!=NULL;room=room->next) {
if (!strcmp(room->label,wrd[0])) {
fprintf(stderr,"NUTS: Duplicate room label on line %d.\n",config_line);
boot_exit(1);
}
if (!strcmp(room->name,wrd[1])) {
fprintf(stderr,"NUTS: Duplicate room name on line %d.\n",config_line);
boot_exit(1);
}
}
room=create_room();
strcpy(room->label,wrd[0]);
strcpy(room->name,wrd[1]);
/* Parse internal links bit ie hl,gd,of etc. MUST NOT be any spaces between
the commas */
i=0;
ptr1=wrd[2];
ptr2=wrd[2];
while(1) {
while(*ptr2!=',' && *ptr2!='\0') ++ptr2;
if (*ptr2==',' && *(ptr2+1)=='\0') {
fprintf(stderr,"NUTS: Missing link label on line %d.\n",config_line);
boot_exit(1);
}
c=*ptr2; *ptr2='\0';
if (!strcmp(ptr1,room->label)) {
fprintf(stderr,"NUTS: Room has a link to itself on line %d.\n",config_line);
boot_exit(1);
}
strcpy(room->link_label[i],ptr1);
if (c=='\0') break;
if (++i>=MAX_LINKS) {
fprintf(stderr,"NUTS: Too many links on line %d.\n",config_line);
boot_exit(1);
}
*ptr2=c;
ptr1=++ptr2;
}
/* Parse access privs */
if (wrd[3][0]=='#') { room->access=PUBLIC; return; }
if (!wrd[3][0] || !strcmp(wrd[3],"BOTH")) room->access=PUBLIC;
else if (!strcmp(wrd[3],"PUB")) room->access=FIXED_PUBLIC;
else if (!strcmp(wrd[3],"PRIV")) room->access=FIXED_PRIVATE;
else {
fprintf(stderr,"NUTS: Unknown room access type on line %d.\n",config_line);
boot_exit(1);
}
/* Parse external link stuff */
if (!wrd[4][0] || wrd[4][0]=='#') return;
if (!strcmp(wrd[4],"ACCEPT")) {
if (wrd[5][0] && wrd[5][0]!='#') {
fprintf(stderr,"NUTS: Unexpected word following ACCEPT keyword on line %d.\n",config_line);
boot_exit(1);
}
room->inlink=1;
return;
}
if (!strcmp(wrd[4],"CONNECT")) {
if (!wrd[5][0]) {
fprintf(stderr,"NUTS: External link name missing on line %d.\n",config_line);
boot_exit(1);
}
if (wrd[6][0] && wrd[6][0]!='#') {
fprintf(stderr,"NUTS: Unexpected word following external link name on line %d.\n",config_line);
boot_exit(1);
}
strcpy(room->netlink_name,wrd[5]);
return;
}
fprintf(stderr,"NUTS: Unknown connection option on line %d.\n",config_line);
boot_exit(1);
}
/*** Parse sites section ***/
void parse_sites_section()
{
NL_OBJECT nl;
static int in_section=0;
if (!strcmp(wrd[0],"SITES:")) {
if (++in_section>1) {
fprintf(stderr,"NUTS: Unexpected SITES section header on line %d.\n",config_line);
boot_exit(1);
}
return;
}
if (!wrd[3][0]) {
fprintf(stderr,"NUTS: Required parameter(s) missing on line %d.\n",config_line);
boot_exit(1);
}
if (strlen(wrd[0])>SERV_NAME_LEN) {
fprintf(stderr,"NUTS: Link name length too long on line %d.\n",config_line);
boot_exit(1);
}
if (strlen(wrd[3])>VERIFY_LEN) {
fprintf(stderr,"NUTS: Verification too long on line %d.\n",config_line);
boot_exit(1);
}
if ((nl=create_netlink())==NULL) {
fprintf(stderr,"NUTS: Memory allocation failure creating netlink on line %d.\n",config_line);
boot_exit(1);
}
if (!wrd[4][0] || wrd[4][0]=='#' || !strcmp(wrd[4],"ALL")) nl->allow=ALL;
else if (!strcmp(wrd[4],"IN")) nl->allow=IN;
else if (!strcmp(wrd[4],"OUT")) nl->allow=OUT;
else {
fprintf(stderr,"NUTS: Unknown netlink access type on line %d.\n",config_line);
boot_exit(1);
}
if ((nl->port=atoi(wrd[2]))<1 || nl->port>65535) {