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