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