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