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