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