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