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