Finished all of the code relating to the "global server info" stuff defined
[citadel.git] / citadel / citserver.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <fcntl.h>
5 #include <signal.h>
6 #include <time.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <pthread.h>
11 #include <syslog.h>
12 #include "citadel.h"
13 #include "server.h"
14 #include "proto.h"
15
16 struct config config;
17
18 struct CitContext *ContextList = NULL;
19 int ScheduledShutdown = 0;
20
21         
22 /*
23  * record an entry in the call log
24  */
25 void rec_log(unsigned int lrtype, char *name)
26 {
27         struct calllog record;
28         int file,file2,a,b;
29
30
31         time(&record.CLtime);
32         record.CLflags = lrtype;
33         strncpy(record.CLfullname,name,29);
34
35         begin_critical_section(S_CALLLOG);
36         file=open("calllog.pos",O_RDWR);
37
38         read(file,&a,sizeof(int));
39         b=a; ++a; if (a>=CALLLOG) a=0;
40         lseek(file,0L,0);
41         write(file,&a,sizeof(int));
42
43         file2=open("calllog",O_RDWR);
44         lseek(file2,(long)(b*sizeof(struct calllog)),0);
45         write(file2,(char *)&record,sizeof(struct calllog));
46         close(file2);
47
48         close(file);
49         end_critical_section(S_CALLLOG);
50         }
51
52
53 /*
54  * Various things that need to be initialized at startup
55  */
56 void master_startup() {
57         lprintf(7, "Opening databases\n");
58         open_databases();
59
60         lprintf(7, "Checking floor reference counts\n");
61         check_ref_counts();
62         }
63
64 /*
65  * Cleanup routine to be called when the server is shutting down.
66  */
67 void master_cleanup() {
68
69         /* Cancel all running sessions */
70         lprintf(7, "Cancelling running sessions...\n");
71         while (ContextList != NULL) {
72                 kill_session(ContextList->cs_pid);
73                 }
74
75         /* Close databases */
76         lprintf(7, "Closing databases\n");
77         close_databases();
78
79         /* Do system-dependent stuff */
80         sysdep_master_cleanup();
81
82         /* Now go away. */
83         hook_cleanup();
84         lprintf(3, "citserver: exiting.\n");
85         exit(0);
86         }
87
88
89 /*
90  * Gracefully terminate the session and thread.
91  * (This is called as a cleanup handler by the thread library.)
92  */
93 void cleanup_stuff()
94 {
95         struct ExpressMessage *emptr;
96
97         lprintf(9, "cleanup_stuff() called\n");
98
99         lprintf(7, "Calling logout(%d)\n", CC->cs_pid);
100         logout(CC);
101
102         rec_log(CL_TERMINATE,CC->curr_user);
103         unlink(CC->temp);
104         lprintf(3, "citserver[%3d]: ended.\n",CC->cs_pid);
105         hook_end_session(CC->cs_pid);
106         syslog(LOG_NOTICE,"session %d ended", CC->cs_pid);
107         
108         /* Deallocate any unsent express messages */
109         begin_critical_section(S_SESSION_TABLE);
110         while (CC->FirstExpressMessage != NULL) {
111                 emptr = CC->FirstExpressMessage;
112                 CC->FirstExpressMessage = CC->FirstExpressMessage->next;
113                 free(emptr);
114                 }
115         end_critical_section(S_SESSION_TABLE);
116
117         /* Now get rid of the session and context */
118         lprintf(7, "cleanup_stuff() is calling RemoveContext(%d)\n", CC->cs_pid);
119         RemoveContext(CC);
120
121         /* While we still have an extra thread with no user attached to it,
122          * take the opportunity to do some housekeeping before exiting.
123          */
124         do_housekeeping();
125         }
126
127
128 /*
129  * set_wtmpsupp()  -  alter the session listing
130  */
131 void set_wtmpsupp(char *newtext)
132 {
133         strncpy(CC->cs_room,newtext,19);
134         CC->cs_room[19] = 0;
135         time(&CC->cs_lastupdt);
136         hook_room_name(CC->cs_pid, CC->cs_room);
137         }
138
139
140 /*
141  * cmd_info()  -  tell the client about this server
142  */
143 void cmd_info(void) {
144         cprintf("%d Server info:\n",LISTING_FOLLOWS);
145         cprintf("%d\n",CC->cs_pid);
146         cprintf("%s\n",config.c_nodename);
147         cprintf("%s\n",config.c_humannode);
148         cprintf("%s\n",config.c_fqdn);
149         cprintf("%s\n",CITADEL);
150         cprintf("%d\n",REV_LEVEL);
151         cprintf("%s\n",config.c_bbs_city);
152         cprintf("%s\n",config.c_sysadm);
153         cprintf("%d\n",SERVER_TYPE);
154         cprintf("%s\n",config.c_moreprompt);
155         cprintf("1\n"); /* 1 = yes, this system supports floors */
156         cprintf("000\n");
157         }
158
159 void cmd_rchg(char *newroomname)
160 {
161    if ((newroomname) && (newroomname[0]))
162    {
163       bzero(CC->fake_roomname, 20);
164       strncpy(CC->fake_roomname, newroomname, 19);
165    }
166    else
167       CC->fake_roomname[0] = '\0';
168    cprintf("%d\n",OK);
169 }
170
171 void cmd_hchg(char *newhostname)
172 {
173    if ((newhostname) && (newhostname[0]))
174    {
175       bzero(CC->fake_hostname, 25);
176       strncpy(CC->fake_hostname, newhostname, 24);
177    }
178    else
179       CC->fake_hostname[0] = '\0';
180    cprintf("%d\n",OK);
181 }
182
183 void cmd_uchg(char *newusername)
184 {
185    if (CC->usersupp.axlevel < 6) 
186    {
187       cprintf("%d You must be an Aide to use UCHG.\n",
188                 ERROR+HIGHER_ACCESS_REQUIRED);
189       return;
190    }
191    if ((newusername) && (newusername[0]))
192    {
193       CC->cs_flags &= ~CS_STEALTH;
194       bzero(CC->fake_username, 32);
195       if (struncmp(newusername, CC->curr_user, strlen(CC->curr_user)))
196          strncpy(CC->fake_username, newusername, 31);
197    }
198    else
199    {
200       CC->fake_username[0] = '\0';
201       CC->cs_flags |= CS_STEALTH;
202    }
203    cprintf("%d\n",OK);
204 }
205
206 void cmd_time()
207 {
208    time_t tv;
209    
210    tv = time(NULL);
211    
212    cprintf("%d|%ld\n", OK, tv);
213 }
214
215 /*
216  * check a hostname against the public_clients file
217  */
218 int is_public_client(char *where)
219 {
220         char buf[256];
221         FILE *fp;
222
223         if (!strucmp(where,"localhost")) return(1);
224         if (!strucmp(where,config.c_fqdn)) return(1);
225
226         fp = fopen("public_clients","r");
227         if (fp == NULL) return(0);
228
229         while (fgets(buf,256,fp)!=NULL) {
230                 while (isspace((buf[strlen(buf)-1]))) 
231                         buf[strlen(buf)-1] = 0;
232                 if (!strucmp(buf,where)) {
233                         fclose(fp);
234                         return(1);
235                         }
236                 }
237
238         fclose(fp);
239         return(0);
240         }
241
242
243 /*
244  * the client is identifying itself to the server
245  */
246 void cmd_iden(char *argbuf)
247 {
248         int dev_code;
249         int cli_code;
250         int rev_level;
251         char desc[256];
252         char from_host[256];
253
254         if (num_parms(argbuf)<4) {
255                 cprintf("%d usage error\n",ERROR);
256                 return;
257                 }
258
259         dev_code = extract_int(argbuf,0);
260         cli_code = extract_int(argbuf,1);
261         rev_level = extract_int(argbuf,2);
262         extract(desc,argbuf,3);
263
264         strcpy(from_host,config.c_fqdn);
265         if (num_parms(argbuf)>=5) extract(from_host,argbuf,4);
266
267         CC->cs_clientdev = dev_code;
268         CC->cs_clienttyp = cli_code;
269         CC->cs_clientver = rev_level;
270         strncpy(CC->cs_clientname,desc,31);
271         CC->cs_clientname[31] = 0;
272
273         if ((strlen(from_host)>0) && 
274            (is_public_client(CC->cs_host))) {
275                 strncpy(CC->cs_host,from_host,24);
276                 CC->cs_host[24] = 0;
277                 }
278         set_wtmpsupp(CC->quickroom.QRname);
279
280         syslog(LOG_NOTICE,"client %d/%d/%01d.%02d (%s)\n",
281                 dev_code,
282                 cli_code,
283                 (rev_level / 100),
284                 (rev_level % 100),
285                 desc);
286                 cprintf("%d Ok\n",OK);
287         }
288
289
290 /*
291  * enter or exit "stealth mode"
292  */
293 void cmd_stel(char *cmdbuf)
294 {
295         int requested_mode;
296
297         requested_mode = extract_int(cmdbuf,0);
298         if (requested_mode !=0) requested_mode = 1;
299
300         if (!CC->logged_in) {
301                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
302                 return;
303                 }
304
305         if (CC->usersupp.axlevel < 6) {
306                 cprintf("%d You must be an Aide to use stealth mode.\n",
307                         ERROR+HIGHER_ACCESS_REQUIRED);
308                 return;
309                 }
310
311         if (CC->cs_flags & CS_STEALTH) {
312                 if (requested_mode == 0)
313                         CC->cs_flags = CC->cs_flags-CS_STEALTH;
314                 }
315         else {
316                 if (requested_mode == 1)
317                         CC->cs_flags = CC->cs_flags|CS_STEALTH;
318                 }
319
320         set_wtmpsupp(CC->quickroom.QRname);
321         cprintf("%d Ok\n",OK);
322         }
323
324
325
326
327 /*
328  * display system messages or help
329  */
330 void cmd_mesg(char *mname)
331 {
332         FILE *mfp;
333         char targ[256];
334         char buf[256];
335         char *dirs[2];
336
337         extract(buf,mname,0);
338
339
340         dirs[0]=malloc(64);
341         dirs[1]=malloc(64);
342         strcpy(dirs[0],"messages");
343         strcpy(dirs[1],"help");
344         mesg_locate(targ,buf,2,dirs);
345         free(dirs[0]);
346         free(dirs[1]);
347
348
349         if (strlen(targ)==0) {
350                 cprintf("%d '%s' not found.\n",ERROR,mname);
351                 return;
352                 }
353
354         mfp = fopen(targ,"r");
355         if (mfp==NULL) {
356                 cprintf("%d Cannot open '%s': %s\n",
357                         ERROR,targ,strerror(errno));
358                 return;
359                 }
360         cprintf("%d %s\n",LISTING_FOLLOWS,buf);
361
362         while (fgets(buf,255,mfp)!=NULL) {
363                 buf[strlen(buf)-1] = 0;
364                 do_help_subst(buf);
365                 cprintf("%s\n",buf);
366                 }
367
368         fclose(mfp);
369         cprintf("000\n");
370         }
371
372
373 /*
374  * enter system messages or help
375  */
376 void cmd_emsg(char *mname)
377 {
378         FILE *mfp;
379         char targ[256];
380         char buf[256];
381         char *dirs[2];
382         int a;
383
384         if (CC->usersupp.axlevel < 6) {
385                 cprintf("%d You must be an Aide to edit system messages.\n",
386                         ERROR+HIGHER_ACCESS_REQUIRED);
387                 return;
388                 }
389
390         extract(buf,mname,0);
391         for (a=0; a<strlen(buf); ++a) {         /* security measure */
392                 if (buf[a] == '/') buf[a] = '.';
393                 }
394
395         dirs[0]=malloc(64);
396         dirs[1]=malloc(64);
397         strcpy(dirs[0],"messages");
398         strcpy(dirs[1],"help");
399         mesg_locate(targ,buf,2,dirs);
400         free(dirs[0]);
401         free(dirs[1]);
402
403         if (strlen(targ)==0) {
404                 sprintf(targ, "./help/%s", buf);
405                 }
406
407         mfp = fopen(targ,"w");
408         if (mfp==NULL) {
409                 cprintf("%d Cannot open '%s': %s\n",
410                         ERROR,targ,strerror(errno));
411                 return;
412                 }
413         cprintf("%d %s\n", SEND_LISTING, targ);
414
415         while (client_gets(buf), strcmp(buf, "000")) {
416                 fprintf(mfp, "%s\n", buf);
417                 }
418
419         fclose(mfp);
420         }
421
422
423 /*
424  * who's online
425  */
426 void cmd_rwho(void) {
427         struct CitContext *cptr;
428         int spoofed = 0;
429         int aide;
430         char un[40], room[40], host[40], flags[5];
431         
432         aide = CC->usersupp.axlevel >= 6;
433         cprintf("%d\n",LISTING_FOLLOWS);
434         
435         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) 
436         {
437                 flags[0] = '\0';
438                 spoofed = 0;
439                 
440                 if (cptr->cs_flags & CS_POSTING)
441                    strcat(flags, "*");
442                 else
443                    strcat(flags, ".");
444                    
445                 if (cptr->fake_username[0])
446                 {
447                    strcpy(un, cptr->fake_username);
448                    spoofed = 1;
449                 }
450                 else
451                    strcpy(un, cptr->curr_user);
452                    
453                 if (cptr->fake_hostname[0])
454                 {
455                    strcpy(host, cptr->fake_hostname);
456                    spoofed = 1;
457                 }
458                 else
459                    strcpy(host, cptr->cs_host);
460
461                 if (cptr->fake_roomname[0])
462                 {
463                    strcpy(room, cptr->fake_roomname);
464                    spoofed = 1;
465                 }
466                 else
467                    strcpy(room, cptr->cs_room);
468                    
469                 
470                 if ((aide) && (spoofed))
471                    strcat(flags, "+");
472                 
473                 if ((cptr->cs_flags & CS_STEALTH) && (aide))
474                    strcat(flags, "-");
475                 
476                 if (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
477                 {
478                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s\n",
479                                 cptr->cs_pid, un, room,
480                                 host, cptr->cs_clientname,
481                                 (long)(cptr->lastidle),
482                                 cptr->lastcmdname, flags);
483                 }
484                 if ((spoofed) && (aide))
485                 {
486                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s\n",
487                                 cptr->cs_pid, cptr->curr_user, cptr->cs_room,
488                                 cptr->cs_host, cptr->cs_clientname,
489                                 (long)(cptr->lastidle),
490                                 cptr->lastcmdname, flags);
491                 
492                 }
493         }
494         cprintf("000\n");
495         }
496
497
498 /*
499  * Terminate another running session
500  */
501 void cmd_term(char *cmdbuf)
502 {
503         int session_num;
504         struct CitContext *ccptr;
505
506         if (!CC->logged_in) {
507                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
508                 return;
509                 }
510
511         if (CC->usersupp.axlevel < 6) {
512                 cprintf("%d You must be an Aide to terminate sessions.\n",
513                         ERROR+HIGHER_ACCESS_REQUIRED);
514                 return;
515                 }
516
517         session_num = extract_int(cmdbuf, 0);
518         if (session_num == CC->cs_pid) {
519                 cprintf("%d You can't kill your own session.\n", ERROR);
520                 return;
521                 }
522
523         for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
524                 if (session_num == ccptr->cs_pid) {
525                         kill_session(ccptr->cs_pid);
526                         cprintf("%d Session terminated.\n", OK);
527                         return;
528                         }
529                 }
530
531         cprintf("%d No such session.\n", ERROR);
532         }
533
534
535
536
537
538 /* 
539  * get the paginator prompt
540  */
541 void cmd_more(void) {
542         cprintf("%d %s\n",OK,config.c_moreprompt);
543         }
544
545 /*
546  * echo 
547  */
548 void cmd_echo(char *etext)
549 {
550         cprintf("%d %s\n",OK,etext);
551         }
552
553
554
555 /* 
556  * identify as internal program
557  */
558 void cmd_ipgm(char *argbuf)
559 {
560         int secret;
561
562         secret = extract_int(argbuf, 0);
563         if (secret == config.c_ipgm_secret) {
564                 CC->internal_pgm = 1;
565                 strcpy(CC->curr_user, "<internal program>");
566                 CC->cs_flags = CC->cs_flags|CS_STEALTH;
567                 cprintf("%d Authenticated as an internal program.\n",OK);
568                 }
569         else {
570                 cprintf("%d Authentication failed.\n",ERROR);
571                 }
572         }
573
574
575 /*
576  * Shut down the server
577  */
578 void cmd_down(void) {
579         if (!CC->logged_in) {
580                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
581                 return;
582                 }
583
584         if (CC->usersupp.axlevel < 6) {
585                 cprintf("%d You must be an Aide to shut down the server.\n",
586                         ERROR+HIGHER_ACCESS_REQUIRED);
587                 return;
588                 }
589
590         cprintf("%d Shutting down server.  Goodbye.\n", OK);
591         master_cleanup();
592         }
593
594 /*
595  * Shut down the server
596  */
597 void cmd_scdn(char *argbuf)
598 {
599         int new_state;
600
601         if (!CC->logged_in) {
602                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
603                 return;
604                 }
605
606         if (CC->usersupp.axlevel < 6) {
607                 cprintf("%d You must be an Aide to schedule a shutdown.\n",
608                         ERROR+HIGHER_ACCESS_REQUIRED);
609                 return;
610                 }
611
612         new_state = extract_int(argbuf, 0);
613         if ((new_state == 0) || (new_state == 1)) {
614                 ScheduledShutdown = new_state;
615                 }
616         cprintf("%d %d\n", OK, ScheduledShutdown);
617         }
618
619 /*
620  * main context loop
621  */
622 void *context_loop(struct CitContext *con)
623 {
624         char cmdbuf[256];
625         int session_num;
626
627         /*
628          * Wedge our way into the context table.
629          */
630         InitMyContext(con);
631
632         /* 
633          * Initialize some variables specific to our context.
634          */
635         CC->curr_rm = (-1);
636         CC->logged_in = 0;
637         CC->internal_pgm = 0;
638         CC->download_fp = NULL;
639         CC->upload_fp = NULL;
640         CC->cs_pid = con->client_socket;        /* not necessarily portable */
641         CC->FirstExpressMessage = NULL;
642         time(&CC->lastcmd);
643         time(&CC->lastidle);
644         strcpy(CC->lastcmdname, "    ");
645         strcpy(CC->cs_clientname, "(unknown)");
646         strcpy(CC->curr_user,"");
647         strcpy(CC->net_node,"");
648         sprintf(CC->temp,"/tmp/CitServer.%d.%d", getpid(), CC->cs_pid);
649         strcpy(CC->cs_room, "");
650         strcpy(CC->cs_host, config.c_fqdn);
651         locate_host(CC->cs_host);
652         CC->cs_flags = 0;
653         CC->upload_type = UPL_FILE;
654         CC->dl_is_net = 0;
655
656         session_num = session_count();
657         CC->nologin = 0;
658         if ((config.c_maxsessions > 0)&&(session_num >= config.c_maxsessions))
659                 CC->nologin = 1;
660
661         if (CC->nologin==1) {
662            cprintf("%d %s: Too many users are already online (maximum is %d)\n",
663                 ERROR+MAX_SESSIONS_EXCEEDED,
664                 config.c_nodename,config.c_maxsessions);
665                 }
666         else {
667            cprintf("%d %s Citadel/UX server ready.\n",OK,config.c_nodename);
668                 }
669
670         lprintf(3, "citserver[%3d]: started.\n", CC->cs_pid);
671         hook_start_session(CC->cs_pid);
672
673         do {
674                 time(&CC->lastcmd);
675                 if (client_gets(cmdbuf) < 1) cleanup(EXIT_NULL);
676                 lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf);
677                 hook_command_received(CC->cs_pid, cmdbuf);
678
679                 /*
680                  * Let other clients see the last command we executed, but
681                  * exclude NOOP because that would be boring.
682                  */
683                 if (struncmp(cmdbuf, "NOOP", 4)) {
684                         strcpy(CC->lastcmdname, "    ");
685                         strncpy(CC->lastcmdname, cmdbuf, 4);
686                         time(&CC->lastidle);
687                         }
688                         
689                 if ((struncmp(cmdbuf, "ENT0", 4)) && (struncmp(cmdbuf, "MESG", 4)) && (struncmp(cmdbuf, "MSGS", 4)))
690                 {
691                    CC->cs_flags &= ~CS_POSTING;
692                 }
693                    
694 /*
695  * This loop recognizes all server commands.
696  */
697
698                 if (!struncmp(cmdbuf,"NOOP",4)) {
699                         cprintf("%d%cok\n",OK,check_express());
700                         }
701
702                 else if (!struncmp(cmdbuf,"QUIT",4)) {
703                         cprintf("%d Goodbye.\n",OK);
704                         }
705
706                 else if (!struncmp(cmdbuf,"LOUT",4)) {
707                         if (CC->logged_in) logout(CC);
708                         cprintf("%d logged out.\n",OK);
709                         }
710
711                 else if (!struncmp(cmdbuf,"USER",4)) {
712                         cmd_user(&cmdbuf[5]);
713                         }
714
715                 else if (!struncmp(cmdbuf,"PASS",4)) {
716                         cmd_pass(&cmdbuf[5]);
717                         }
718
719                 else if (!struncmp(cmdbuf,"NEWU",4)) {
720                         cmd_newu(&cmdbuf[5]);
721                         }
722
723                 else if (!struncmp(cmdbuf,"SETP",4)) {
724                         cmd_setp(&cmdbuf[5]);
725                         }
726
727                 else if (!struncmp(cmdbuf,"LRMS",4)) {
728                         cmd_lrms(&cmdbuf[5]);
729                         }
730
731                 else if (!struncmp(cmdbuf,"LKRA",4)) {
732                         cmd_lkra(&cmdbuf[5]);
733                         }
734
735                 else if (!struncmp(cmdbuf,"LKRN",4)) {
736                         cmd_lkrn(&cmdbuf[5]);
737                         }
738
739                 else if (!struncmp(cmdbuf,"LKRO",4)) {
740                         cmd_lkro(&cmdbuf[5]);
741                         }
742
743                 else if (!struncmp(cmdbuf,"LZRM",4)) {
744                         cmd_lzrm(&cmdbuf[5]);
745                         }
746
747                 else if (!struncmp(cmdbuf,"GETU",4)) {
748                         cmd_getu();
749                         }
750
751                 else if (!struncmp(cmdbuf,"SETU",4)) {
752                         cmd_setu(&cmdbuf[5]);
753                         }
754
755                 else if (!struncmp(cmdbuf,"GOTO",4)) {
756                         cmd_goto(&cmdbuf[5]);
757                         }
758
759                 else if (!struncmp(cmdbuf,"MSGS",4)) {
760                         cmd_msgs(&cmdbuf[5]);
761                         }
762
763                 else if (!struncmp(cmdbuf,"WHOK",4)) {
764                         cmd_whok();
765                         }
766
767                 else if (!struncmp(cmdbuf,"RDIR",4)) {
768                         cmd_rdir();
769                         }
770
771                 else if (!struncmp(cmdbuf,"MSG0",4)) {
772                         cmd_msg0(&cmdbuf[5]);
773                         }
774
775                 else if (!struncmp(cmdbuf,"MSG2",4)) {
776                         cmd_msg2(&cmdbuf[5]);
777                         }
778
779                 else if (!struncmp(cmdbuf,"MSG3",4)) {
780                         cmd_msg3(&cmdbuf[5]);
781                         }
782
783                 else if (!struncmp(cmdbuf,"INFO",4)) {
784                         cmd_info();
785                         }
786
787                 else if (!struncmp(cmdbuf,"SLRP",4)) {
788                         cmd_slrp(&cmdbuf[5]);
789                         }
790
791                 else if (!struncmp(cmdbuf,"INVT",4)) {
792                         cmd_invt_kick(&cmdbuf[5],1);
793                         }
794
795                 else if (!struncmp(cmdbuf,"KICK",4)) {
796                         cmd_invt_kick(&cmdbuf[5],0);
797                         }
798
799                 else if (!struncmp(cmdbuf,"GETR",4)) {
800                         cmd_getr();
801                         }
802
803                 else if (!struncmp(cmdbuf,"SETR",4)) {
804                         cmd_setr(&cmdbuf[5]);
805                         }
806
807                 else if (!struncmp(cmdbuf,"GETA",4)) {
808                         cmd_geta();
809                         }
810
811                 else if (!struncmp(cmdbuf,"SETA",4)) {
812                         cmd_seta(&cmdbuf[5]);
813                         }
814
815                 else if (!struncmp(cmdbuf,"ENT0",4)) {
816                         cmd_ent0(&cmdbuf[5]);
817                         }
818
819                 else if (!struncmp(cmdbuf,"ENT3",4)) {
820                         cmd_ent3(&cmdbuf[5]);
821                         }
822
823                 else if (!struncmp(cmdbuf,"RINF",4)) {
824                         cmd_rinf();
825                         }
826
827                 else if (!struncmp(cmdbuf,"DELE",4)) {
828                         cmd_dele(&cmdbuf[5]);
829                         }
830
831                 else if (!struncmp(cmdbuf,"KILL",4)) {
832                         cmd_kill(&cmdbuf[5]);
833                         }
834
835                 else if (!struncmp(cmdbuf,"CRE8",4)) {
836                         cmd_cre8(&cmdbuf[5]);
837                         }
838
839                 else if (!struncmp(cmdbuf,"MOVE",4)) {
840                         cmd_move(&cmdbuf[5]);
841                         }
842
843                 else if (!struncmp(cmdbuf,"FORG",4)) {
844                         cmd_forg();
845                         }
846
847                 else if (!struncmp(cmdbuf,"MESG",4)) {
848                         cmd_mesg(&cmdbuf[5]);
849                         }
850
851                 else if (!struncmp(cmdbuf,"EMSG",4)) {
852                         cmd_emsg(&cmdbuf[5]);
853                         }
854
855                 else if (!struncmp(cmdbuf,"GNUR",4)) {
856                         cmd_gnur();
857                         }
858
859                 else if (!struncmp(cmdbuf,"GREG",4)) {
860                         cmd_greg(&cmdbuf[5]);
861                         }
862
863                 else if (!struncmp(cmdbuf,"VALI",4)) {
864                         cmd_vali(&cmdbuf[5]);
865                         }
866
867                 else if (!struncmp(cmdbuf,"EINF",4)) {
868                         cmd_einf(&cmdbuf[5]);
869                         }
870
871                 else if (!struncmp(cmdbuf,"LIST",4)) {
872                         cmd_list();
873                         }
874
875                 else if (!struncmp(cmdbuf,"REGI",4)) {
876                         cmd_regi();
877                         }
878
879                 else if (!struncmp(cmdbuf,"CHEK",4)) {
880                         cmd_chek();
881                         }
882
883                 else if (!struncmp(cmdbuf,"DELF",4)) {
884                         cmd_delf(&cmdbuf[5]);
885                         }
886
887                 else if (!struncmp(cmdbuf,"MOVF",4)) {
888                         cmd_movf(&cmdbuf[5]);
889                         }
890
891                 else if (!struncmp(cmdbuf,"NETF",4)) {
892                         cmd_netf(&cmdbuf[5]);
893                         }
894
895                 else if (!struncmp(cmdbuf,"RWHO",4)) {
896                         cmd_rwho();
897                         }
898
899                 else if (!struncmp(cmdbuf,"OPEN",4)) {
900                         cmd_open(&cmdbuf[5]);
901                         }
902
903                 else if (!struncmp(cmdbuf,"CLOS",4)) {
904                         cmd_clos();
905                         }
906
907                 else if (!struncmp(cmdbuf,"UOPN",4)) {
908                         cmd_uopn(&cmdbuf[5]);
909                         }
910
911                 else if (!struncmp(cmdbuf,"UCLS",4)) {
912                         cmd_ucls(&cmdbuf[5]);
913                         }
914
915                 else if (!struncmp(cmdbuf,"READ",4)) {
916                         cmd_read(&cmdbuf[5]);
917                         }
918
919                 else if (!struncmp(cmdbuf,"WRIT",4)) {
920                         cmd_writ(&cmdbuf[5]);
921                         }
922
923                 else if (!struncmp(cmdbuf,"QUSR",4)) {
924                         cmd_qusr(&cmdbuf[5]);
925                         }
926
927                 else if (!struncmp(cmdbuf,"ECHO",4)) {
928                         cmd_echo(&cmdbuf[5]);
929                         }
930
931                 else if (!struncmp(cmdbuf,"OIMG",4)) {
932                         cmd_oimg(&cmdbuf[5]);
933                         }
934
935                 else if (!struncmp(cmdbuf,"MORE",4)) {
936                         cmd_more();
937                         }
938
939                 else if (!struncmp(cmdbuf,"NETP",4)) {
940                         cmd_netp(&cmdbuf[5]);
941                         }
942
943                 else if (!struncmp(cmdbuf,"NDOP",4)) {
944                         cmd_ndop(&cmdbuf[5]);
945                         }
946
947                 else if (!struncmp(cmdbuf,"NUOP",4)) {
948                         cmd_nuop(&cmdbuf[5]);
949                         }
950
951                 else if (!struncmp(cmdbuf,"LFLR",4)) {
952                         cmd_lflr();
953                         }
954
955                 else if (!struncmp(cmdbuf,"CFLR",4)) {
956                         cmd_cflr(&cmdbuf[5]);
957                         }
958
959                 else if (!struncmp(cmdbuf,"KFLR",4)) {
960                         cmd_kflr(&cmdbuf[5]);
961                         }
962
963                 else if (!struncmp(cmdbuf,"EFLR",4)) {
964                         cmd_eflr(&cmdbuf[5]);
965                         }
966
967                 else if (!struncmp(cmdbuf,"IDEN",4)) {
968                         cmd_iden(&cmdbuf[5]);
969                         }
970
971                 else if (!struncmp(cmdbuf,"IPGM",4)) {
972                         cmd_ipgm(&cmdbuf[5]);
973                         }
974
975                 else if (!struncmp(cmdbuf,"CHAT",4)) {
976                         cmd_chat(&cmdbuf[5]);
977                         }
978
979                 else if (!struncmp(cmdbuf,"PEXP",4)) {
980                         cmd_pexp();
981                         }
982
983                 else if (!struncmp(cmdbuf,"SEXP",4)) {
984                         cmd_sexp(&cmdbuf[5]);
985                         }
986
987                 else if (!struncmp(cmdbuf,"EBIO",4)) {
988                         cmd_ebio();
989                         }
990
991                 else if (!struncmp(cmdbuf,"RBIO",4)) {
992                         cmd_rbio(&cmdbuf[5]);
993                         }
994
995                 else if (!struncmp(cmdbuf,"LBIO",4)) {
996                         cmd_lbio();
997                         }
998
999                 else if (!struncmp(cmdbuf,"STEL",4)) {
1000                         cmd_stel(&cmdbuf[5]);
1001                         }
1002
1003                 else if (!struncmp(cmdbuf,"TERM",4)) {
1004                         cmd_term(&cmdbuf[5]);
1005                         }
1006
1007                 else if (!struncmp(cmdbuf,"DOWN",4)) {
1008                         cmd_down();
1009                         }
1010
1011                 else if (!struncmp(cmdbuf,"SCDN",4)) {
1012                         cmd_scdn(&cmdbuf[5]);
1013                         }
1014
1015                 else if (!struncmp(cmdbuf, "NSET", 4)) {
1016                         cmd_nset(&cmdbuf[5]);
1017                         }
1018
1019                 else if (!struncmp(cmdbuf, "UIMG", 4)) {
1020                         cmd_uimg(&cmdbuf[5]);
1021                         }
1022                 else if (!struncmp(cmdbuf, "UCHG", 4)) {
1023                         cmd_uchg(&cmdbuf[5]);
1024                         }
1025                 else if (!struncmp(cmdbuf, "TIME", 4)) {
1026                         cmd_time(&cmdbuf[5]);
1027                         }
1028                 else if (!struncmp(cmdbuf, "HCHG", 4)) {
1029                         cmd_hchg(&cmdbuf[5]);
1030                         }
1031                 else if (!struncmp(cmdbuf, "RCHG", 4)) {
1032                         cmd_rchg(&cmdbuf[5]);
1033                         }
1034                 else {
1035                         cprintf("%d Unrecognized or unsupported command.\n",
1036                                 ERROR);
1037                         }
1038
1039                 } while(struncmp(cmdbuf,"QUIT",4));
1040
1041         cleanup(EXIT_NORMAL);
1042         return(NULL);
1043         }