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