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