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