885c8a15acec1b9bdb71c3c2b3c01f27d659c2dc
[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
33 struct CitContext *ContextList = NULL;
34 int ScheduledShutdown = 0;
35
36 /*
37  * Various things that need to be initialized at startup
38  */
39 void master_startup(void) {
40         lprintf(7, "Opening databases\n");
41         open_databases();
42
43         lprintf(7, "Checking floor reference counts\n");
44         check_ref_counts();
45
46         lprintf(7, "Creating base rooms (if necessary)\n");
47         create_room(BASEROOM, 0, "", 0);
48         create_room(AIDEROOM, 4, "", 0);
49         create_room(config.c_twitroom, 0, "", 0);
50         }
51
52 /*
53  * Cleanup routine to be called when the server is shutting down.
54  */
55 void master_cleanup(void) {
56         struct CleanupFunctionHook *fcn;
57
58         /* Cancel all running sessions */
59         lprintf(7, "Cancelling running sessions...\n");
60         while (ContextList != NULL) {
61                 kill_session(ContextList->cs_pid);
62                 }
63
64         /* Run any cleanup routines registered by loadable modules */
65         for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) {
66                 (*fcn->h_function_pointer)();
67                 }
68
69         /* Close databases */
70         lprintf(7, "Closing databases\n");
71         close_databases();
72
73         /* Do system-dependent stuff */
74         sysdep_master_cleanup();
75
76         /* Now go away. */
77         lprintf(3, "citserver: exiting.\n");
78         fflush(stdout); fflush(stderr);
79         exit(0);
80         }
81
82
83 /*
84  * Gracefully terminate the session and thread.
85  * (This is called as a cleanup handler by the thread library.)
86  *
87  * All NON-system-dependent stuff is done in this function.
88  * System-dependent session/thread cleanup is in cleanup() in sysdep.c
89  */
90 void cleanup_stuff(void *arg)
91 {
92         struct ExpressMessage *emptr;
93
94         lprintf(9, "cleanup_stuff() called\n");
95
96         lprintf(7, "Calling logout(%d)\n", CC->cs_pid);
97         logout(CC);
98
99         rec_log(CL_TERMINATE,CC->curr_user);
100         unlink(CC->temp);
101         lprintf(3, "citserver[%3d]: ended.\n",CC->cs_pid);
102         
103         /* Run any cleanup routines registered by loadable modules */
104         PerformSessionHooks(EVT_STOP);
105
106         syslog(LOG_NOTICE,"session %d ended", CC->cs_pid);
107         
108         /* Deallocate any unsent express messages */
109         begin_critical_section(S_SESSION_TABLE);
110         while (CC->FirstExpressMessage != NULL) {
111                 emptr = CC->FirstExpressMessage;
112                 CC->FirstExpressMessage = CC->FirstExpressMessage->next;
113                 free(emptr);
114                 }
115         end_critical_section(S_SESSION_TABLE);
116
117         /* Deallocate any message list we might have in memory */
118         if (CC->msglist != NULL) free(CC->msglist);
119
120         /* Purge any stale user/room relationships */
121         PurgeStaleRelationships();
122
123         /* Now get rid of the session and context */
124         lprintf(7, "cleanup_stuff() calling RemoveContext(%d)\n", CC->cs_pid);
125         RemoveContext(CC);
126
127         /* While we still have an extra thread with no user attached to it,
128          * take the opportunity to do some housekeeping before exiting.
129          */
130         do_housekeeping();
131         }
132
133
134 /*
135  * set_wtmpsupp()  -  alter the session listing
136  */
137 void set_wtmpsupp(char *newtext)
138 {
139         strncpy(CC->cs_room,newtext,sizeof CC->cs_room);
140         CC->cs_room[sizeof CC->cs_room - 1] = 0;
141         time(&CC->cs_lastupdt);
142
143         /* Run any routines registered by loadable modules */
144         PerformSessionHooks(EVT_NEWROOM);
145         }
146
147
148 /*
149  * call set_wtmpsupp() with the name of the current room, modified a bit...
150  */
151 void set_wtmpsupp_to_current_room() {
152         if (CC->quickroom.QRflags & QR_PRIVATE) {
153                 set_wtmpsupp("<private room>");
154                 }
155         else if (CC->quickroom.QRflags & QR_MAILBOX) {
156                 set_wtmpsupp(&CC->quickroom.QRname[11]);
157                 }
158         else {
159                 set_wtmpsupp(CC->quickroom.QRname);
160                 }
161         }
162
163
164
165 /*
166  * cmd_info()  -  tell the client about this server
167  */
168 void cmd_info(void) {
169         cprintf("%d Server info:\n",LISTING_FOLLOWS);
170         cprintf("%d\n",CC->cs_pid);
171         cprintf("%s\n",config.c_nodename);
172         cprintf("%s\n",config.c_humannode);
173         cprintf("%s\n",config.c_fqdn);
174         cprintf("%s\n",CITADEL);
175         cprintf("%d\n",REV_LEVEL);
176         cprintf("%s\n",config.c_bbs_city);
177         cprintf("%s\n",config.c_sysadm);
178         cprintf("%d\n",SERVER_TYPE);
179         cprintf("%s\n",config.c_moreprompt);
180         cprintf("1\n"); /* 1 = yes, this system supports floors */
181         cprintf("000\n");
182         }
183
184 void cmd_rchg(char *argbuf)
185 {
186         char newroomname[ROOMNAMELEN];
187
188         extract(newroomname, argbuf, 0);
189         if (strlen(newroomname) > 0) {
190                 strncpy(CC->fake_roomname, newroomname, ROOMNAMELEN);
191                 CC->fake_roomname[ROOMNAMELEN - 1] = 0;
192                 }
193         else {
194                 strcpy(CC->fake_roomname, "");
195                 }
196         cprintf("%d OK\n", OK);
197 }
198
199 void cmd_hchg(char *newhostname)
200 {
201    if ((newhostname) && (newhostname[0]))
202    {
203       bzero(CC->fake_hostname, 25);
204       strncpy(CC->fake_hostname, newhostname, 24);
205    }
206    else
207       strcpy(CC->fake_hostname, "");
208    cprintf("%d OK\n",OK);
209 }
210
211 void cmd_uchg(char *newusername)
212 {
213    if (CC->usersupp.axlevel < 6) 
214    {
215       cprintf("%d You must be an Aide to use UCHG.\n",
216                 ERROR+HIGHER_ACCESS_REQUIRED);
217       return;
218    }
219    if ((newusername) && (newusername[0]))
220    {
221       CC->cs_flags &= ~CS_STEALTH;
222       bzero(CC->fake_username, 32);
223       if (strncasecmp(newusername, CC->curr_user, strlen(CC->curr_user)))
224          strncpy(CC->fake_username, newusername, 31);
225    }
226    else
227    {
228       CC->fake_username[0] = '\0';
229       CC->cs_flags |= CS_STEALTH;
230    }
231    cprintf("%d\n",OK);
232 }
233
234 /*
235  * returns an asterisk if there are any express messages waiting,
236  * space otherwise.
237  */
238 char check_express(void) {
239         if (CC->FirstExpressMessage == NULL) {
240                 return(' ');
241                 }
242         else {
243                 return('*');
244                 }
245         }
246
247 void cmd_time(void)
248 {
249    time_t tv;
250    
251    tv = time(NULL);
252    
253    cprintf("%d %ld\n", OK, tv);
254 }
255
256 /*
257  * check a hostname against the public_clients file
258  */
259 int is_public_client(char *where)
260 {
261         char buf[256];
262         FILE *fp;
263
264         if (!strcasecmp(where,"localhost")) return(1);
265         if (!strcasecmp(where,config.c_fqdn)) return(1);
266
267         fp = fopen("public_clients","r");
268         if (fp == NULL) return(0);
269
270         while (fgets(buf,256,fp)!=NULL) {
271                 while (isspace((buf[strlen(buf)-1]))) 
272                         buf[strlen(buf)-1] = 0;
273                 if (!strcasecmp(buf,where)) {
274                         fclose(fp);
275                         return(1);
276                         }
277                 }
278
279         fclose(fp);
280         return(0);
281         }
282
283
284 /*
285  * the client is identifying itself to the server
286  */
287 void cmd_iden(char *argbuf)
288 {
289         int dev_code;
290         int cli_code;
291         int rev_level;
292         char desc[256];
293         char from_host[256];
294
295         if (num_parms(argbuf)<4) {
296                 cprintf("%d usage error\n",ERROR);
297                 return;
298                 }
299
300         dev_code = extract_int(argbuf,0);
301         cli_code = extract_int(argbuf,1);
302         rev_level = extract_int(argbuf,2);
303         extract(desc,argbuf,3);
304
305         strncpy(from_host,config.c_fqdn,sizeof from_host);
306         from_host[sizeof from_host - 1] = 0;
307         if (num_parms(argbuf)>=5) extract(from_host,argbuf,4);
308
309         CC->cs_clientdev = dev_code;
310         CC->cs_clienttyp = cli_code;
311         CC->cs_clientver = rev_level;
312         strncpy(CC->cs_clientname,desc,31);
313         CC->cs_clientname[31] = 0;
314
315         if ((strlen(from_host)>0) && 
316            (is_public_client(CC->cs_host))) {
317                 strncpy(CC->cs_host,from_host,24);
318                 CC->cs_host[24] = 0;
319                 }
320         set_wtmpsupp_to_current_room();
321
322         syslog(LOG_NOTICE,"client %d/%d/%01d.%02d (%s)\n",
323                 dev_code,
324                 cli_code,
325                 (rev_level / 100),
326                 (rev_level % 100),
327                 desc);
328                 cprintf("%d Ok\n",OK);
329         }
330
331
332 /*
333  * enter or exit "stealth mode"
334  */
335 void cmd_stel(char *cmdbuf)
336 {
337         int requested_mode;
338
339         requested_mode = extract_int(cmdbuf,0);
340         if (requested_mode !=0) requested_mode = 1;
341
342         if (!CC->logged_in) {
343                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
344                 return;
345                 }
346
347         if (CC->usersupp.axlevel < 6) {
348                 cprintf("%d You must be an Aide to use stealth mode.\n",
349                         ERROR+HIGHER_ACCESS_REQUIRED);
350                 return;
351                 }
352
353         if (CC->cs_flags & CS_STEALTH) {
354                 if (requested_mode == 0)
355                         CC->cs_flags = CC->cs_flags-CS_STEALTH;
356                 }
357         else {
358                 if (requested_mode == 1)
359                         CC->cs_flags = CC->cs_flags|CS_STEALTH;
360                 }
361
362         set_wtmpsupp_to_current_room();
363         cprintf("%d Ok\n",OK);
364         }
365
366
367
368
369 /*
370  * display system messages or help
371  */
372 void cmd_mesg(char *mname)
373 {
374         FILE *mfp;
375         char targ[256];
376         char buf[256];
377         char *dirs[2];
378
379         extract(buf,mname,0);
380
381
382         dirs[0]=malloc(64);
383         dirs[1]=malloc(64);
384         strcpy(dirs[0],"messages");
385         strcpy(dirs[1],"help");
386         mesg_locate(targ,buf,2,dirs);
387         free(dirs[0]);
388         free(dirs[1]);
389
390
391         if (strlen(targ)==0) {
392                 cprintf("%d '%s' not found.\n",ERROR,mname);
393                 return;
394                 }
395
396         mfp = fopen(targ,"r");
397         if (mfp==NULL) {
398                 cprintf("%d Cannot open '%s': %s\n",
399                         ERROR,targ,strerror(errno));
400                 return;
401                 }
402         cprintf("%d %s\n",LISTING_FOLLOWS,buf);
403
404         while (fgets(buf,255,mfp)!=NULL) {
405                 buf[strlen(buf)-1] = 0;
406                 do_help_subst(buf);
407                 cprintf("%s\n",buf);
408                 }
409
410         fclose(mfp);
411         cprintf("000\n");
412         }
413
414
415 /*
416  * enter system messages or help
417  */
418 void cmd_emsg(char *mname)
419 {
420         FILE *mfp;
421         char targ[256];
422         char buf[256];
423         char *dirs[2];
424         int a;
425
426         if (CC->usersupp.axlevel < 6) {
427                 cprintf("%d You must be an Aide to edit system messages.\n",
428                         ERROR+HIGHER_ACCESS_REQUIRED);
429                 return;
430                 }
431
432         extract(buf,mname,0);
433         for (a=0; a<strlen(buf); ++a) {         /* security measure */
434                 if (buf[a] == '/') buf[a] = '.';
435                 }
436
437         dirs[0]=malloc(64);
438         dirs[1]=malloc(64);
439         strcpy(dirs[0],"messages");
440         strcpy(dirs[1],"help");
441         mesg_locate(targ,buf,2,dirs);
442         free(dirs[0]);
443         free(dirs[1]);
444
445         if (strlen(targ)==0) {
446                 snprintf(targ, sizeof targ, "./help/%s", buf);
447                 }
448
449         mfp = fopen(targ,"w");
450         if (mfp==NULL) {
451                 cprintf("%d Cannot open '%s': %s\n",
452                         ERROR,targ,strerror(errno));
453                 return;
454                 }
455         cprintf("%d %s\n", SEND_LISTING, targ);
456
457         while (client_gets(buf), strcmp(buf, "000")) {
458                 fprintf(mfp, "%s\n", buf);
459                 }
460
461         fclose(mfp);
462         }
463
464
465 /*
466  * who's online
467  */
468 void cmd_rwho(void) {
469         struct CitContext *cptr;
470         int spoofed = 0;
471         int aide;
472         char un[40], room[40], host[40], flags[5];
473         
474         aide = CC->usersupp.axlevel >= 6;
475         cprintf("%d\n",LISTING_FOLLOWS);
476         
477         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) 
478         {
479                 flags[0] = '\0';
480                 spoofed = 0;
481                 
482                 if (cptr->cs_flags & CS_POSTING)
483                    strcat(flags, "*");
484                 else
485                    strcat(flags, ".");
486                    
487                 if (cptr->fake_username[0])
488                 {
489                    strcpy(un, cptr->fake_username);
490                    spoofed = 1;
491                 }
492                 else
493                    strcpy(un, cptr->curr_user);
494                    
495                 if (cptr->fake_hostname[0])
496                 {
497                    strcpy(host, cptr->fake_hostname);
498                    spoofed = 1;
499                 }
500                 else
501                    strcpy(host, cptr->cs_host);
502
503                 if (cptr->fake_roomname[0])
504                 {
505                    strcpy(room, cptr->fake_roomname);
506                    spoofed = 1;
507                 }
508                 else
509                    strcpy(room, cptr->cs_room);
510                    
511                 
512                 if ((aide) && (spoofed))
513                    strcat(flags, "+");
514                 
515                 if ((cptr->cs_flags & CS_STEALTH) && (aide))
516                    strcat(flags, "-");
517                 
518                 if (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
519                 {
520                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s\n",
521                                 cptr->cs_pid, un, room,
522                                 host, cptr->cs_clientname,
523                                 (long)(cptr->lastidle),
524                                 cptr->lastcmdname, flags);
525                 }
526                 if ((spoofed) && (aide))
527                 {
528                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s\n",
529                                 cptr->cs_pid, cptr->curr_user, cptr->cs_room,
530                                 cptr->cs_host, cptr->cs_clientname,
531                                 (long)(cptr->lastidle),
532                                 cptr->lastcmdname, flags);
533                 
534                 }
535         }
536         cprintf("000\n");
537         }
538
539
540 /*
541  * Terminate another running session
542  */
543 void cmd_term(char *cmdbuf)
544 {
545         int session_num;
546         struct CitContext *ccptr;
547
548         if (!CC->logged_in) {
549                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
550                 return;
551                 }
552
553         if (CC->usersupp.axlevel < 6) {
554                 cprintf("%d You must be an Aide to terminate sessions.\n",
555                         ERROR+HIGHER_ACCESS_REQUIRED);
556                 return;
557                 }
558
559         session_num = extract_int(cmdbuf, 0);
560         if (session_num == CC->cs_pid) {
561                 cprintf("%d You can't kill your own session.\n", ERROR);
562                 return;
563                 }
564
565         for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
566                 if (session_num == ccptr->cs_pid) {
567                         kill_session(ccptr->cs_pid);
568                         cprintf("%d Session terminated.\n", OK);
569                         return;
570                         }
571                 }
572
573         cprintf("%d No such session.\n", ERROR);
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 session_num;
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         session_num = session_count();
702         CC->nologin = 0;
703         if ((config.c_maxsessions > 0)&&(session_num >= 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                 bzero(cmdbuf, 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,"INFO",4)) {
833                         cmd_info();
834                         }
835
836                 else if (!strncasecmp(cmdbuf,"SLRP",4)) {
837                         cmd_slrp(&cmdbuf[5]);
838                         }
839
840                 else if (!strncasecmp(cmdbuf,"INVT",4)) {
841                         cmd_invt_kick(&cmdbuf[5],1);
842                         }
843
844                 else if (!strncasecmp(cmdbuf,"KICK",4)) {
845                         cmd_invt_kick(&cmdbuf[5],0);
846                         }
847
848                 else if (!strncasecmp(cmdbuf,"GETR",4)) {
849                         cmd_getr();
850                         }
851
852                 else if (!strncasecmp(cmdbuf,"SETR",4)) {
853                         cmd_setr(&cmdbuf[5]);
854                         }
855
856                 else if (!strncasecmp(cmdbuf,"GETA",4)) {
857                         cmd_geta();
858                         }
859
860                 else if (!strncasecmp(cmdbuf,"SETA",4)) {
861                         cmd_seta(&cmdbuf[5]);
862                         }
863
864                 else if (!strncasecmp(cmdbuf,"ENT0",4)) {
865                         cmd_ent0(&cmdbuf[5]);
866                         }
867
868                 else if (!strncasecmp(cmdbuf,"ENT3",4)) {
869                         cmd_ent3(&cmdbuf[5]);
870                         }
871
872                 else if (!strncasecmp(cmdbuf,"RINF",4)) {
873                         cmd_rinf();
874                         }
875
876                 else if (!strncasecmp(cmdbuf,"DELE",4)) {
877                         cmd_dele(&cmdbuf[5]);
878                         }
879
880                 else if (!strncasecmp(cmdbuf,"KILL",4)) {
881                         cmd_kill(&cmdbuf[5]);
882                         }
883
884                 else if (!strncasecmp(cmdbuf,"CRE8",4)) {
885                         cmd_cre8(&cmdbuf[5]);
886                         }
887
888                 else if (!strncasecmp(cmdbuf,"MOVE",4)) {
889                         cmd_move(&cmdbuf[5]);
890                         }
891
892                 else if (!strncasecmp(cmdbuf,"FORG",4)) {
893                         cmd_forg();
894                         }
895
896                 else if (!strncasecmp(cmdbuf,"MESG",4)) {
897                         cmd_mesg(&cmdbuf[5]);
898                         }
899
900                 else if (!strncasecmp(cmdbuf,"EMSG",4)) {
901                         cmd_emsg(&cmdbuf[5]);
902                         }
903
904                 else if (!strncasecmp(cmdbuf,"GNUR",4)) {
905                         cmd_gnur();
906                         }
907
908                 else if (!strncasecmp(cmdbuf,"GREG",4)) {
909                         cmd_greg(&cmdbuf[5]);
910                         }
911
912                 else if (!strncasecmp(cmdbuf,"VALI",4)) {
913                         cmd_vali(&cmdbuf[5]);
914                         }
915
916                 else if (!strncasecmp(cmdbuf,"EINF",4)) {
917                         cmd_einf(&cmdbuf[5]);
918                         }
919
920                 else if (!strncasecmp(cmdbuf,"LIST",4)) {
921                         cmd_list();
922                         }
923
924                 else if (!strncasecmp(cmdbuf,"REGI",4)) {
925                         cmd_regi();
926                         }
927
928                 else if (!strncasecmp(cmdbuf,"CHEK",4)) {
929                         cmd_chek();
930                         }
931
932                 else if (!strncasecmp(cmdbuf,"DELF",4)) {
933                         cmd_delf(&cmdbuf[5]);
934                         }
935
936                 else if (!strncasecmp(cmdbuf,"MOVF",4)) {
937                         cmd_movf(&cmdbuf[5]);
938                         }
939
940                 else if (!strncasecmp(cmdbuf,"NETF",4)) {
941                         cmd_netf(&cmdbuf[5]);
942                         }
943
944                 else if (!strncasecmp(cmdbuf,"RWHO",4)) {
945                         cmd_rwho();
946                         }
947
948                 else if (!strncasecmp(cmdbuf,"OPEN",4)) {
949                         cmd_open(&cmdbuf[5]);
950                         }
951
952                 else if (!strncasecmp(cmdbuf,"CLOS",4)) {
953                         cmd_clos();
954                         }
955
956                 else if (!strncasecmp(cmdbuf,"UOPN",4)) {
957                         cmd_uopn(&cmdbuf[5]);
958                         }
959
960                 else if (!strncasecmp(cmdbuf,"UCLS",4)) {
961                         cmd_ucls(&cmdbuf[5]);
962                         }
963
964                 else if (!strncasecmp(cmdbuf,"READ",4)) {
965                         cmd_read(&cmdbuf[5]);
966                         }
967
968                 else if (!strncasecmp(cmdbuf,"WRIT",4)) {
969                         cmd_writ(&cmdbuf[5]);
970                         }
971
972                 else if (!strncasecmp(cmdbuf,"QUSR",4)) {
973                         cmd_qusr(&cmdbuf[5]);
974                         }
975
976                 else if (!strncasecmp(cmdbuf,"ECHO",4)) {
977                         cmd_echo(&cmdbuf[5]);
978                         }
979
980                 else if (!strncasecmp(cmdbuf,"OIMG",4)) {
981                         cmd_oimg(&cmdbuf[5]);
982                         }
983
984                 else if (!strncasecmp(cmdbuf,"MORE",4)) {
985                         cmd_more();
986                         }
987
988                 else if (!strncasecmp(cmdbuf,"NETP",4)) {
989                         cmd_netp(&cmdbuf[5]);
990                         }
991
992                 else if (!strncasecmp(cmdbuf,"NDOP",4)) {
993                         cmd_ndop(&cmdbuf[5]);
994                         }
995
996                 else if (!strncasecmp(cmdbuf,"NUOP",4)) {
997                         cmd_nuop(&cmdbuf[5]);
998                         }
999
1000                 else if (!strncasecmp(cmdbuf,"LFLR",4)) {
1001                         cmd_lflr();
1002                         }
1003
1004                 else if (!strncasecmp(cmdbuf,"CFLR",4)) {
1005                         cmd_cflr(&cmdbuf[5]);
1006                         }
1007
1008                 else if (!strncasecmp(cmdbuf,"KFLR",4)) {
1009                         cmd_kflr(&cmdbuf[5]);
1010                         }
1011
1012                 else if (!strncasecmp(cmdbuf,"EFLR",4)) {
1013                         cmd_eflr(&cmdbuf[5]);
1014                         }
1015
1016                 else if (!strncasecmp(cmdbuf,"IDEN",4)) {
1017                         cmd_iden(&cmdbuf[5]);
1018                         }
1019
1020                 else if (!strncasecmp(cmdbuf,"IPGM",4)) {
1021                         cmd_ipgm(&cmdbuf[5]);
1022                         }
1023
1024                 else if (!strncasecmp(cmdbuf,"EBIO",4)) {
1025                         cmd_ebio();
1026                         }
1027
1028                 else if (!strncasecmp(cmdbuf,"RBIO",4)) {
1029                         cmd_rbio(&cmdbuf[5]);
1030                         }
1031
1032                 else if (!strncasecmp(cmdbuf,"LBIO",4)) {
1033                         cmd_lbio();
1034                         }
1035
1036                 else if (!strncasecmp(cmdbuf,"STEL",4)) {
1037                         cmd_stel(&cmdbuf[5]);
1038                         }
1039
1040                 else if (!strncasecmp(cmdbuf,"TERM",4)) {
1041                         cmd_term(&cmdbuf[5]);
1042                         }
1043
1044                 else if (!strncasecmp(cmdbuf,"DOWN",4)) {
1045                         cmd_down();
1046                         }
1047
1048                 else if (!strncasecmp(cmdbuf,"SCDN",4)) {
1049                         cmd_scdn(&cmdbuf[5]);
1050                         }
1051
1052                 else if (!strncasecmp(cmdbuf, "NSET", 4)) {
1053                         cmd_nset(&cmdbuf[5]);
1054                         }
1055
1056                 else if (!strncasecmp(cmdbuf, "UIMG", 4)) {
1057                         cmd_uimg(&cmdbuf[5]);
1058                         }
1059
1060                 else if (!strncasecmp(cmdbuf, "UCHG", 4)) {
1061                         cmd_uchg(&cmdbuf[5]);
1062                         }
1063
1064                 else if (!strncasecmp(cmdbuf, "TIME", 4)) {
1065                         cmd_time();
1066                         }
1067
1068                 else if (!strncasecmp(cmdbuf, "HCHG", 4)) {
1069                         cmd_hchg(&cmdbuf[5]);
1070                         }
1071
1072                 else if (!strncasecmp(cmdbuf, "RCHG", 4)) {
1073                         cmd_rchg(&cmdbuf[5]);
1074                         }
1075
1076                 else if (!strncasecmp(cmdbuf, "AGUP", 4)) {
1077                         cmd_agup(&cmdbuf[5]);
1078                         }
1079
1080                 else if (!strncasecmp(cmdbuf, "ASUP", 4)) {
1081                         cmd_asup(&cmdbuf[5]);
1082                         }
1083
1084                 else if (!strncasecmp(cmdbuf, "GPEX", 4)) {
1085                         cmd_gpex(&cmdbuf[5]);
1086                         }
1087
1088                 else if (!strncasecmp(cmdbuf, "SPEX", 4)) {
1089                         cmd_spex(&cmdbuf[5]);
1090                         }
1091
1092                 else if (!strncasecmp(cmdbuf, "CONF", 4)) {
1093                         cmd_conf(&cmdbuf[5]);
1094                         }
1095
1096                 else if (!DLoader_Exec_Cmd(cmdbuf))
1097                         {
1098                            cprintf("%d Unrecognized or unsupported command.\n",
1099                                     ERROR);
1100                         }
1101
1102                 } while(strncasecmp(cmdbuf, "QUIT", 4));
1103
1104         cleanup(EXIT_NORMAL);
1105         return(NULL);
1106         }