Added the OPNA command for downloading attachments
[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
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         if (CC->ExpressMessages != NULL) phree(CC->ExpressMessages);
111         end_critical_section(S_SESSION_TABLE);
112
113         /* Deallocate any message list we might have in memory */
114         if (CC->msglist != NULL) phree(CC->msglist);
115
116         /* Now get rid of the session and context */
117         lprintf(7, "cleanup_stuff() calling RemoveContext(%d)\n", CC->cs_pid);
118         RemoveContext(CC);
119
120         /* While we still have an extra thread with no user attached to it,
121          * take the opportunity to do some housekeeping before exiting.
122          */
123         do_housekeeping();
124         }
125
126
127 /*
128  * set_wtmpsupp()  -  alter the session listing
129  */
130 void set_wtmpsupp(char *newtext)
131 {
132         strncpy(CC->cs_room,newtext,sizeof CC->cs_room);
133         CC->cs_room[sizeof CC->cs_room - 1] = 0;
134         time(&CC->cs_lastupdt);
135
136         /* Run any routines registered by loadable modules */
137         PerformSessionHooks(EVT_NEWROOM);
138         }
139
140
141 /*
142  * call set_wtmpsupp() with the name of the current room, modified a bit...
143  */
144 void set_wtmpsupp_to_current_room() {
145         if (CC->quickroom.QRflags & QR_PRIVATE) {
146                 set_wtmpsupp("<private room>");
147                 }
148         else if (CC->quickroom.QRflags & QR_MAILBOX) {
149                 set_wtmpsupp(&CC->quickroom.QRname[11]);
150                 }
151         else {
152                 set_wtmpsupp(CC->quickroom.QRname);
153                 }
154         }
155
156
157
158 /*
159  * cmd_info()  -  tell the client about this server
160  */
161 void cmd_info(void) {
162         cprintf("%d Server info:\n",LISTING_FOLLOWS);
163         cprintf("%d\n",CC->cs_pid);
164         cprintf("%s\n",config.c_nodename);
165         cprintf("%s\n",config.c_humannode);
166         cprintf("%s\n",config.c_fqdn);
167         cprintf("%s\n",CITADEL);
168         cprintf("%d\n",REV_LEVEL);
169         cprintf("%s\n",config.c_bbs_city);
170         cprintf("%s\n",config.c_sysadm);
171         cprintf("%d\n",SERVER_TYPE);
172         cprintf("%s\n",config.c_moreprompt);
173         cprintf("1\n"); /* 1 = yes, this system supports floors */
174         cprintf("1\n"); /* 1 = we support the extended paging options */
175         cprintf("000\n");
176         }
177
178 void cmd_rchg(char *argbuf)
179 {
180         char newroomname[256]; /* set to 256 to prevent buffer overruns <dme>*/
181
182         extract(newroomname, argbuf, 0);
183         newroomname[ROOMNAMELEN] = 0;
184         if (strlen(newroomname) > 0) {
185                 strncpy(CC->fake_roomname, newroomname, ROOMNAMELEN);
186                 CC->fake_roomname[ROOMNAMELEN - 1] = 0;
187                 }
188         else {
189                 strcpy(CC->fake_roomname, "");
190                 }
191         cprintf("%d OK\n", OK);
192 }
193
194 void cmd_hchg(char *newhostname)
195 {
196    if ((newhostname) && (newhostname[0]))
197    {
198       memset(CC->fake_hostname, 0, 25);
199       strncpy(CC->fake_hostname, newhostname, 24);
200    }
201    else
202       strcpy(CC->fake_hostname, "");
203    cprintf("%d OK\n",OK);
204 }
205
206 void cmd_uchg(char *newusername)
207 {
208    if (CC->usersupp.axlevel < 6) 
209    {
210       cprintf("%d You must be an Aide to use UCHG.\n",
211                 ERROR+HIGHER_ACCESS_REQUIRED);
212       return;
213    }
214    if ((newusername) && (newusername[0]))
215    {
216       CC->cs_flags &= ~CS_STEALTH;
217       memset(CC->fake_username, 0, 32);
218       if (strncasecmp(newusername, CC->curr_user, strlen(CC->curr_user)))
219          strncpy(CC->fake_username, newusername, 31);
220    }
221    else
222    {
223       CC->fake_username[0] = '\0';
224       CC->cs_flags |= CS_STEALTH;
225    }
226    cprintf("%d\n",OK);
227 }
228
229 /*
230  * returns an asterisk if there are any express messages waiting,
231  * space otherwise.
232  */
233 char check_express(void) {
234         if (CC->ExpressMessages == NULL) {
235                 return(' ');
236                 }
237         else {
238                 return('*');
239                 }
240         }
241
242 void cmd_time(void)
243 {
244    time_t tv;
245    
246    tv = time(NULL);
247    
248    cprintf("%d %ld\n", OK, tv);
249 }
250
251 /*
252  * check a hostname against the public_clients file
253  */
254 int is_public_client(char *where)
255 {
256         char buf[256];
257         FILE *fp;
258
259         if (!strcasecmp(where,"localhost")) return(1);
260         if (!strcasecmp(where,config.c_fqdn)) return(1);
261
262         fp = fopen("public_clients","r");
263         if (fp == NULL) return(0);
264
265         while (fgets(buf,256,fp)!=NULL) {
266                 while (isspace((buf[strlen(buf)-1]))) 
267                         buf[strlen(buf)-1] = 0;
268                 if (!strcasecmp(buf,where)) {
269                         fclose(fp);
270                         return(1);
271                         }
272                 }
273
274         fclose(fp);
275         return(0);
276         }
277
278
279 /*
280  * the client is identifying itself to the server
281  */
282 void cmd_iden(char *argbuf)
283 {
284         int dev_code;
285         int cli_code;
286         int rev_level;
287         char desc[256];
288         char from_host[256];
289
290         if (num_parms(argbuf)<4) {
291                 cprintf("%d usage error\n",ERROR);
292                 return;
293                 }
294
295         dev_code = extract_int(argbuf,0);
296         cli_code = extract_int(argbuf,1);
297         rev_level = extract_int(argbuf,2);
298         extract(desc,argbuf,3);
299
300         strncpy(from_host,config.c_fqdn,sizeof from_host);
301         from_host[sizeof from_host - 1] = 0;
302         if (num_parms(argbuf)>=5) extract(from_host,argbuf,4);
303
304         CC->cs_clientdev = dev_code;
305         CC->cs_clienttyp = cli_code;
306         CC->cs_clientver = rev_level;
307         strncpy(CC->cs_clientname,desc,31);
308         CC->cs_clientname[31] = 0;
309
310         if ((strlen(from_host)>0) && 
311            (is_public_client(CC->cs_host))) {
312                 strncpy(CC->cs_host,from_host,24);
313                 CC->cs_host[24] = 0;
314                 }
315         set_wtmpsupp_to_current_room();
316
317         syslog(LOG_NOTICE,"client %d/%d/%01d.%02d (%s)\n",
318                 dev_code,
319                 cli_code,
320                 (rev_level / 100),
321                 (rev_level % 100),
322                 desc);
323                 cprintf("%d Ok\n",OK);
324         }
325
326
327 /*
328  * enter or exit "stealth mode"
329  */
330 void cmd_stel(char *cmdbuf)
331 {
332         int requested_mode;
333
334         requested_mode = extract_int(cmdbuf,0);
335         if (requested_mode !=0) requested_mode = 1;
336
337         if (!CC->logged_in) {
338                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
339                 return;
340                 }
341
342         if (CC->usersupp.axlevel < 6) {
343                 cprintf("%d You must be an Aide to use stealth mode.\n",
344                         ERROR+HIGHER_ACCESS_REQUIRED);
345                 return;
346                 }
347
348         if (CC->cs_flags & CS_STEALTH) {
349                 if (requested_mode == 0)
350                         CC->cs_flags = CC->cs_flags-CS_STEALTH;
351                 }
352         else {
353                 if (requested_mode == 1)
354                         CC->cs_flags = CC->cs_flags|CS_STEALTH;
355                 }
356
357         set_wtmpsupp_to_current_room();
358         cprintf("%d Ok\n",OK);
359         }
360
361
362
363
364 /*
365  * display system messages or help
366  */
367 void cmd_mesg(char *mname)
368 {
369         FILE *mfp;
370         char targ[256];
371         char buf[256];
372         char *dirs[2];
373
374         extract(buf,mname,0);
375
376
377         dirs[0]=mallok(64);
378         dirs[1]=mallok(64);
379         strcpy(dirs[0],"messages");
380         strcpy(dirs[1],"help");
381         mesg_locate(targ,buf,2,dirs);
382         phree(dirs[0]);
383         phree(dirs[1]);
384
385
386         if (strlen(targ)==0) {
387                 cprintf("%d '%s' not found.\n",ERROR,mname);
388                 return;
389                 }
390
391         mfp = fopen(targ,"r");
392         if (mfp==NULL) {
393                 cprintf("%d Cannot open '%s': %s\n",
394                         ERROR,targ,strerror(errno));
395                 return;
396                 }
397         cprintf("%d %s\n",LISTING_FOLLOWS,buf);
398
399         while (fgets(buf,255,mfp)!=NULL) {
400                 buf[strlen(buf)-1] = 0;
401                 do_help_subst(buf);
402                 cprintf("%s\n",buf);
403                 }
404
405         fclose(mfp);
406         cprintf("000\n");
407         }
408
409
410 /*
411  * enter system messages or help
412  */
413 void cmd_emsg(char *mname)
414 {
415         FILE *mfp;
416         char targ[256];
417         char buf[256];
418         char *dirs[2];
419         int a;
420
421         if (CC->usersupp.axlevel < 6) {
422                 cprintf("%d You must be an Aide to edit system messages.\n",
423                         ERROR+HIGHER_ACCESS_REQUIRED);
424                 return;
425                 }
426
427         extract(buf,mname,0);
428         for (a=0; a<strlen(buf); ++a) {         /* security measure */
429                 if (buf[a] == '/') buf[a] = '.';
430                 }
431
432         dirs[0]=mallok(64);
433         dirs[1]=mallok(64);
434         strcpy(dirs[0],"messages");
435         strcpy(dirs[1],"help");
436         mesg_locate(targ,buf,2,dirs);
437         phree(dirs[0]);
438         phree(dirs[1]);
439
440         if (strlen(targ)==0) {
441                 snprintf(targ, sizeof targ, "./help/%s", buf);
442                 }
443
444         mfp = fopen(targ,"w");
445         if (mfp==NULL) {
446                 cprintf("%d Cannot open '%s': %s\n",
447                         ERROR,targ,strerror(errno));
448                 return;
449                 }
450         cprintf("%d %s\n", SEND_LISTING, targ);
451
452         while (client_gets(buf), strcmp(buf, "000")) {
453                 fprintf(mfp, "%s\n", buf);
454                 }
455
456         fclose(mfp);
457         }
458
459
460 /*
461  * who's online
462  */
463 void cmd_rwho(void) {
464         struct CitContext *cptr;
465         int spoofed = 0;
466         int aide;
467         char un[40], room[40], host[40], flags[5];
468         
469         aide = CC->usersupp.axlevel >= 6;
470         cprintf("%d\n",LISTING_FOLLOWS);
471         
472         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) 
473         {
474                 flags[0] = '\0';
475                 spoofed = 0;
476                 
477                 if (cptr->cs_flags & CS_POSTING)
478                    strcat(flags, "*");
479                 else
480                    strcat(flags, ".");
481                    
482                 if (cptr->fake_username[0])
483                 {
484                    strcpy(un, cptr->fake_username);
485                    spoofed = 1;
486                 }
487                 else
488                    strcpy(un, cptr->curr_user);
489                    
490                 if (cptr->fake_hostname[0])
491                 {
492                    strcpy(host, cptr->fake_hostname);
493                    spoofed = 1;
494                 }
495                 else
496                    strcpy(host, cptr->cs_host);
497
498                 if (cptr->fake_roomname[0])
499                 {
500                    strcpy(room, cptr->fake_roomname);
501                    spoofed = 1;
502                 }
503                 else
504                    strcpy(room, cptr->cs_room);
505                    
506                 
507                 if ((aide) && (spoofed))
508                    strcat(flags, "+");
509                 
510                 if ((cptr->cs_flags & CS_STEALTH) && (aide))
511                    strcat(flags, "-");
512                 
513                 if (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
514                 {
515                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s\n",
516                                 cptr->cs_pid, un, room,
517                                 host, cptr->cs_clientname,
518                                 (long)(cptr->lastidle),
519                                 cptr->lastcmdname, flags);
520                 }
521                 if ((spoofed) && (aide))
522                 {
523                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s\n",
524                                 cptr->cs_pid, cptr->curr_user, cptr->cs_room,
525                                 cptr->cs_host, cptr->cs_clientname,
526                                 (long)(cptr->lastidle),
527                                 cptr->lastcmdname, flags);
528                 
529                 }
530         }
531         cprintf("000\n");
532         }
533
534
535 /*
536  * Terminate another running session
537  */
538 void cmd_term(char *cmdbuf)
539 {
540         int session_num;
541         struct CitContext *ccptr;
542         int session_to_kill = 0;
543
544         if (!CC->logged_in) {
545                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
546                 return;
547                 }
548
549         if (CC->usersupp.axlevel < 6) {
550                 cprintf("%d You must be an Aide to terminate sessions.\n",
551                         ERROR+HIGHER_ACCESS_REQUIRED);
552                 return;
553                 }
554
555         session_num = extract_int(cmdbuf, 0);
556         if (session_num == CC->cs_pid) {
557                 cprintf("%d You can't kill your own session.\n", ERROR);
558                 return;
559                 }
560
561         lprintf(9, "Locating session to kill\n");
562         begin_critical_section(S_SESSION_TABLE);
563         for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
564                 if (session_num == ccptr->cs_pid) {
565                         session_to_kill = ccptr->cs_pid;
566                         }
567                 }
568         end_critical_section(S_SESSION_TABLE);
569         lprintf(9, "session_to_kill == %d\n", session_to_kill);
570
571         if (session_to_kill > 0) {
572                 lprintf(9, "calling kill_session()\n");
573                 kill_session(session_to_kill);
574                 cprintf("%d Session terminated.\n", OK);
575                 }
576         else {
577                 cprintf("%d No such session.\n", ERROR);
578                 }
579         }
580
581
582
583
584
585 /* 
586  * get the paginator prompt
587  */
588 void cmd_more(void) {
589         cprintf("%d %s\n",OK,config.c_moreprompt);
590         }
591
592 /*
593  * echo 
594  */
595 void cmd_echo(char *etext)
596 {
597         cprintf("%d %s\n",OK,etext);
598         }
599
600
601
602 /* 
603  * identify as internal program
604  */
605 void cmd_ipgm(char *argbuf)
606 {
607         int secret;
608
609         secret = extract_int(argbuf, 0);
610         if (secret == config.c_ipgm_secret) {
611                 CC->internal_pgm = 1;
612                 strcpy(CC->curr_user, "<internal program>");
613                 CC->cs_flags = CC->cs_flags|CS_STEALTH;
614                 cprintf("%d Authenticated as an internal program.\n",OK);
615                 }
616         else {
617                 cprintf("%d Authentication failed.\n",ERROR);
618                 }
619         }
620
621
622 /*
623  * Shut down the server
624  */
625 void cmd_down(void) {
626         if (!CC->logged_in) {
627                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
628                 return;
629                 }
630
631         if (CC->usersupp.axlevel < 6) {
632                 cprintf("%d You must be an Aide to shut down the server.\n",
633                         ERROR+HIGHER_ACCESS_REQUIRED);
634                 return;
635                 }
636
637         cprintf("%d Shutting down server.  Goodbye.\n", OK);
638         master_cleanup();
639         }
640
641 /*
642  * Schedule or cancel a server shutdown
643  */
644 void cmd_scdn(char *argbuf)
645 {
646         int new_state;
647
648         if (!CC->logged_in) {
649                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
650                 return;
651                 }
652
653         if (CC->usersupp.axlevel < 6) {
654                 cprintf("%d You must be an Aide to schedule a shutdown.\n",
655                         ERROR+HIGHER_ACCESS_REQUIRED);
656                 return;
657                 }
658
659         new_state = extract_int(argbuf, 0);
660         if ((new_state == 0) || (new_state == 1)) {
661                 ScheduledShutdown = new_state;
662                 }
663         cprintf("%d %d\n", OK, ScheduledShutdown);
664         }
665
666
667 /*
668  * main context loop
669  */
670 void *context_loop(struct CitContext *con)
671 {
672         char cmdbuf[256];
673         int num_sessions;
674
675         /*
676          * Wedge our way into the context table.
677          */
678         InitMyContext(con);
679
680         /* 
681          * Initialize some variables specific to our context.
682          */
683         CC->logged_in = 0;
684         CC->internal_pgm = 0;
685         CC->download_fp = NULL;
686         CC->upload_fp = NULL;
687         CC->cs_pid = con->client_socket;        /* not necessarily portable */
688         CC->ExpressMessages = NULL;
689         CC->msglist = NULL;
690         CC->num_msgs = 0;
691         time(&CC->lastcmd);
692         time(&CC->lastidle);
693         strcpy(CC->lastcmdname, "    ");
694         strcpy(CC->cs_clientname, "(unknown)");
695         strcpy(CC->curr_user,"");
696         strcpy(CC->net_node,"");
697         snprintf(CC->temp, sizeof CC->temp, "/tmp/CitServer.%d.%d", getpid(), CC->cs_pid);
698         strcpy(CC->cs_room, "");
699         strncpy(CC->cs_host, config.c_fqdn, sizeof CC->cs_host);
700         CC->cs_host[sizeof CC->cs_host - 1] = 0;
701         locate_host(CC->cs_host);
702         CC->cs_flags = 0;
703         CC->upload_type = UPL_FILE;
704         CC->dl_is_net = 0;
705
706         num_sessions = session_count();
707         CC->nologin = 0;
708         if ((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions))
709                 CC->nologin = 1;
710
711         if (CC->nologin==1) {
712            cprintf("%d %s: Too many users are already online (maximum is %d)\n",
713                 ERROR+MAX_SESSIONS_EXCEEDED,
714                 config.c_nodename,config.c_maxsessions);
715                 }
716         else {
717            cprintf("%d %s Citadel/UX server ready.\n",OK,config.c_nodename);
718                 }
719
720         lprintf(3, "citserver[%3d]: started.\n", CC->cs_pid);
721
722         /* Run any session startup routines registered by loadable modules */
723         PerformSessionHooks(EVT_START);
724
725         rec_log(CL_CONNECT, "");
726
727         do {
728                 time(&CC->lastcmd);
729                 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
730                 if (client_gets(cmdbuf) < 1) cleanup(EXIT_NULL);
731                 lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf);
732
733                 /*
734                  * Let other clients see the last command we executed, but
735                  * exclude NOOP because that would be boring.
736                  */
737                 if (strncasecmp(cmdbuf, "NOOP", 4)) {
738                         strcpy(CC->lastcmdname, "    ");
739                         strncpy(CC->lastcmdname, cmdbuf, 4);
740                         time(&CC->lastidle);
741                         }
742                         
743                 if ((strncasecmp(cmdbuf, "ENT0", 4)) && (strncasecmp(cmdbuf, "MESG", 4)) && (strncasecmp(cmdbuf, "MSGS", 4)))
744                 {
745                    CC->cs_flags &= ~CS_POSTING;
746                 }
747                    
748 /*
749  * This loop recognizes all server commands.
750  */
751
752                 if (!strncasecmp(cmdbuf,"NOOP",4)) {
753                         cprintf("%d%cok\n",OK,check_express());
754                         }
755
756                 else if (!strncasecmp(cmdbuf,"QUIT",4)) {
757                         cprintf("%d Goodbye.\n",OK);
758                         }
759
760                 else if (!strncasecmp(cmdbuf,"LOUT",4)) {
761                         if (CC->logged_in) logout(CC);
762                         cprintf("%d logged out.\n",OK);
763                         }
764
765                 else if (!strncasecmp(cmdbuf,"USER",4)) {
766                         cmd_user(&cmdbuf[5]);
767                         }
768
769                 else if (!strncasecmp(cmdbuf,"PASS",4)) {
770                         cmd_pass(&cmdbuf[5]);
771                         }
772
773                 else if (!strncasecmp(cmdbuf,"NEWU",4)) {
774                         cmd_newu(&cmdbuf[5]);
775                         }
776
777                 else if (!strncasecmp(cmdbuf,"SETP",4)) {
778                         cmd_setp(&cmdbuf[5]);
779                         }
780
781                 else if (!strncasecmp(cmdbuf,"LRMS",4)) {
782                         cmd_lrms(&cmdbuf[5]);
783                         }
784
785                 else if (!strncasecmp(cmdbuf,"LKRA",4)) {
786                         cmd_lkra(&cmdbuf[5]);
787                         }
788
789                 else if (!strncasecmp(cmdbuf,"LKRN",4)) {
790                         cmd_lkrn(&cmdbuf[5]);
791                         }
792
793                 else if (!strncasecmp(cmdbuf,"LKRO",4)) {
794                         cmd_lkro(&cmdbuf[5]);
795                         }
796
797                 else if (!strncasecmp(cmdbuf,"LZRM",4)) {
798                         cmd_lzrm(&cmdbuf[5]);
799                         }
800
801                 else if (!strncasecmp(cmdbuf,"GETU",4)) {
802                         cmd_getu();
803                         }
804
805                 else if (!strncasecmp(cmdbuf,"SETU",4)) {
806                         cmd_setu(&cmdbuf[5]);
807                         }
808
809                 else if (!strncasecmp(cmdbuf,"GOTO",4)) {
810                         cmd_goto(&cmdbuf[5]);
811                         }
812
813                 else if (!strncasecmp(cmdbuf,"MSGS",4)) {
814                         cmd_msgs(&cmdbuf[5]);
815                         }
816
817                 else if (!strncasecmp(cmdbuf,"WHOK",4)) {
818                         cmd_whok();
819                         }
820
821                 else if (!strncasecmp(cmdbuf,"RDIR",4)) {
822                         cmd_rdir();
823                         }
824
825                 else if (!strncasecmp(cmdbuf,"MSG0",4)) {
826                         cmd_msg0(&cmdbuf[5]);
827                         }
828
829                 else if (!strncasecmp(cmdbuf,"MSG2",4)) {
830                         cmd_msg2(&cmdbuf[5]);
831                         }
832
833                 else if (!strncasecmp(cmdbuf,"MSG3",4)) {
834                         cmd_msg3(&cmdbuf[5]);
835                         }
836
837                 else if (!strncasecmp(cmdbuf,"MSG4",4)) {
838                         cmd_msg4(&cmdbuf[5]);
839                         }
840
841                 else if (!strncasecmp(cmdbuf,"OPNA",4)) {
842                         cmd_opna(&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         }