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