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