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