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