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