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