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