2 * Main source module for the Citadel server
4 * Copyright (c) 1987-2011 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sys/types.h>
30 #if TIME_WITH_SYS_TIME
31 # include <sys/time.h>
35 # include <sys/time.h>
51 #include <sys/types.h>
52 #include <sys/socket.h>
53 #include <netinet/in.h>
54 #include <arpa/inet.h>
55 #include <libcitadel.h>
58 #include "sysdep_decls.h"
60 #include "citserver.h"
63 #include "housekeeping.h"
67 #include "locate_host.h"
71 #include "euidindex.h"
73 #include "svn_revision.h"
79 #include "ctdl_module.h"
81 char *unique_session_numbers;
82 int ScheduledShutdown = 0;
83 time_t server_startup_time;
85 int openid_level_supported = 0;
88 * print the actual stack frame.
90 void cit_backtrace(void)
93 void *stack_frames[50];
98 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
99 strings = backtrace_symbols(stack_frames, size);
100 for (i = 0; i < size; i++) {
102 syslog(LOG_ALERT, "%s\n", strings[i]);
104 syslog(LOG_ALERT, "%p\n", stack_frames[i]);
111 * print the actual stack frame.
113 void cit_panic_backtrace(int SigNum)
115 #ifdef HAVE_BACKTRACE
116 void *stack_frames[10];
120 printf("caught signal 11\n");
121 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
122 strings = backtrace_symbols(stack_frames, size);
123 for (i = 0; i < size; i++) {
125 syslog(LOG_ALERT, "%s\n", strings[i]);
127 syslog(LOG_ALERT, "%p\n", stack_frames[i]);
135 * Various things that need to be initialized at startup
137 void master_startup(void) {
141 struct ctdlroom qrbuf;
144 syslog(LOG_DEBUG, "master_startup() started\n");
145 time(&server_startup_time);
147 syslog(LOG_INFO, "Opening databases\n");
151 syslog(LOG_INFO, "Creating base rooms (if necessary)\n");
152 CtdlCreateRoom(config.c_baseroom, 0, "", 0, 1, 0, VIEW_BBS);
153 CtdlCreateRoom(AIDEROOM, 3, "", 0, 1, 0, VIEW_BBS);
154 CtdlCreateRoom(SYSCONFIGROOM, 3, "", 0, 1, 0, VIEW_BBS);
155 CtdlCreateRoom(config.c_twitroom, 0, "", 0, 1, 0, VIEW_BBS);
157 /* The "Local System Configuration" room doesn't need to be visible */
158 if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) {
159 qrbuf.QRflags2 |= QR2_SYSTEM;
160 CtdlPutRoomLock(&qrbuf);
163 /* Aide needs to be public postable, else we're not RFC conformant. */
164 if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) {
165 qrbuf.QRflags2 |= QR2_SMTP_PUBLIC;
166 CtdlPutRoomLock(&qrbuf);
169 syslog(LOG_INFO, "Seeding the pseudo-random number generator...\n");
170 urandom = fopen("/dev/urandom", "r");
171 if (urandom != NULL) {
172 rv = fread(&seed, sizeof seed, 1, urandom);
174 syslog(LOG_EMERG, "failed to read random seed: %s\n",
179 gettimeofday(&tv, NULL);
185 syslog(LOG_INFO, "Initializing ipgm secret\n");
187 config.c_ipgm_secret = rand();
190 syslog(LOG_DEBUG, "master_startup() finished\n");
195 * Cleanup routine to be called when the server is shutting down.
197 void master_cleanup(int exitcode) {
198 struct CleanupFunctionHook *fcn;
199 static int already_cleaning_up = 0;
201 if (already_cleaning_up) while(1) sleep(1);
202 already_cleaning_up = 1;
204 /* Run any cleanup routines registered by loadable modules */
205 for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) {
206 (*fcn->h_function_pointer)();
209 /* Close the AdjRefCount queue file */
212 /* Do system-dependent stuff */
213 sysdep_master_cleanup();
215 /* Close databases */
216 syslog(LOG_INFO, "Closing databases\n");
219 /* If the operator requested a halt but not an exit, halt here. */
220 if (shutdown_and_halt) {
221 syslog(LOG_NOTICE, "citserver: Halting server without exiting.\n");
222 fflush(stdout); fflush(stderr);
231 syslog(LOG_NOTICE, "citserver: Exiting with status %d\n", exitcode);
232 fflush(stdout); fflush(stderr);
234 if (restart_server != 0)
236 if ((running_as_daemon != 0) && ((exitcode == 0) ))
237 exitcode = CTDLEXIT_SHUTDOWN;
244 * cmd_info() - tell the client about this server
246 void cmd_info(char *cmdbuf) {
247 cprintf("%d Server info:\n", LISTING_FOLLOWS);
248 cprintf("%d\n", CC->cs_pid);
249 cprintf("%s\n", config.c_nodename);
250 cprintf("%s\n", config.c_humannode);
251 cprintf("%s\n", config.c_fqdn);
252 cprintf("%s\n", CITADEL);
253 cprintf("%d\n", REV_LEVEL);
254 cprintf("%s\n", config.c_site_location);
255 cprintf("%s\n", config.c_sysadm);
256 cprintf("%d\n", SERVER_TYPE);
257 cprintf("%s\n", config.c_moreprompt);
258 cprintf("1\n"); /* 1 = yes, this system supports floors */
259 cprintf("1\n"); /* 1 = we support the extended paging options */
260 cprintf("\n"); /* nonce no longer supported */
261 cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
264 cprintf("1\n"); /* 1 = yes, this server is LDAP-enabled */
266 cprintf("0\n"); /* 1 = no, this server is not LDAP-enabled */
269 if (config.c_auth_mode == AUTHMODE_NATIVE) {
270 cprintf("%d\n", config.c_disable_newu);
273 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
276 cprintf("%s\n", config.c_default_cal_zone);
278 /* thread load averages -- temporarily disabled during refactoring of this code */
279 cprintf("0\n"); /* load average */
280 cprintf("0\n"); /* worker average */
281 cprintf("0\n"); /* thread count */
283 cprintf("1\n"); /* yes, Sieve mail filtering is supported */
284 cprintf("%d\n", config.c_enable_fulltext);
285 cprintf("%s\n", svn_revision());
287 if (config.c_auth_mode == AUTHMODE_NATIVE) {
288 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
291 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
294 cprintf("%d\n", config.c_guest_logins);
301 * returns an asterisk if there are any instant messages waiting,
304 char CtdlCheckExpress(void) {
305 if (CC->FirstExpressMessage == NULL) {
313 void cmd_time(char *argbuf)
319 localtime_r(&tv, &tmp);
321 /* timezone and daylight global variables are not portable. */
322 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
323 cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst);
325 cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst);
331 * Check originating host against the public_clients file. This determines
332 * whether the client is allowed to change the hostname for this session
333 * (for example, to show the location of the user rather than the location
336 int is_public_client(void)
342 char *public_clientspos;
343 char *public_clientsend;
346 static time_t pc_timestamp = 0;
347 static char public_clients[SIZ];
348 static char public_clients_file[SIZ];
350 #define LOCALHOSTSTR "127.0.0.1"
352 snprintf(public_clients_file, sizeof public_clients_file, "%s/public_clients", ctdl_etc_dir);
355 * Check the time stamp on the public_clients file. If it's been
356 * updated since the last time we were here (or if this is the first
357 * time we've been through the loop), read its contents and learn
358 * the IP addresses of the listed hosts.
360 if (stat(public_clients_file, &statbuf) != 0) {
361 /* No public_clients file exists, so bail out */
362 syslog(LOG_WARNING, "Warning: '%s' does not exist\n",
363 public_clients_file);
367 if (statbuf.st_mtime > pc_timestamp) {
368 begin_critical_section(S_PUBLIC_CLIENTS);
369 syslog(LOG_INFO, "Loading %s\n", public_clients_file);
371 public_clientspos = &public_clients[0];
372 public_clientsend = public_clientspos + SIZ;
373 safestrncpy(public_clientspos, LOCALHOSTSTR, sizeof public_clients);
374 public_clientspos += sizeof(LOCALHOSTSTR) - 1;
376 if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
377 *(public_clientspos++) = '|';
379 while (!IsEmptyStr (paddr) &&
380 (public_clientspos < public_clientsend))
381 *(public_clientspos++) = *(paddr++);
384 fp = fopen(public_clients_file, "r");
386 while ((fgets(buf, sizeof buf, fp)!=NULL) &&
387 (public_clientspos < public_clientsend)){
390 while (!IsEmptyStr(ptr)) {
398 while (ptr>buf && isspace(*ptr)) {
401 if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
402 *(public_clientspos++) = '|';
404 while (!IsEmptyStr(paddr) &&
405 (public_clientspos < public_clientsend)){
406 *(public_clientspos++) = *(paddr++);
411 pc_timestamp = time(NULL);
412 end_critical_section(S_PUBLIC_CLIENTS);
415 syslog(LOG_DEBUG, "Checking whether %s is a local or public client\n",
417 for (i=0; i<num_parms(public_clients); ++i) {
418 extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
419 if (!strcasecmp(CC->cs_addr, addrbuf)) {
420 syslog(LOG_DEBUG, "... yes its local.\n");
425 /* No hits. This is not a public client. */
426 syslog(LOG_DEBUG, "... no it isn't.\n");
432 * the client is identifying itself to the server
434 void cmd_iden(char *argbuf)
442 if (num_parms(argbuf)<4) {
443 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
447 dev_code = extract_int(argbuf,0);
448 cli_code = extract_int(argbuf,1);
449 rev_level = extract_int(argbuf,2);
450 extract_token(desc, argbuf, 3, '|', sizeof desc);
452 safestrncpy(from_host, config.c_fqdn, sizeof from_host);
453 from_host[sizeof from_host - 1] = 0;
454 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
456 CC->cs_clientdev = dev_code;
457 CC->cs_clienttyp = cli_code;
458 CC->cs_clientver = rev_level;
459 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
460 CC->cs_clientname[31] = 0;
462 /* For local sockets and public clients, trust the hostname supplied by the client */
463 if ( (CC->is_local_socket) || (is_public_client()) ) {
464 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
465 CC->cs_host[sizeof CC->cs_host - 1] = 0;
469 syslog(LOG_NOTICE, "Client %d/%d/%01d.%02d (%s) from %s\n",
477 cprintf("%d Ok\n",CIT_OK);
482 * display system messages or help
484 void cmd_mesg(char *mname)
494 extract_token(buf, mname, 0, '|', sizeof buf);
496 dirs[0] = strdup(ctdl_message_dir);
497 dirs[1] = strdup(ctdl_hlp_dir);
499 snprintf(buf2, sizeof buf2, "%s.%d.%d",
500 buf, CC->cs_clientdev, CC->cs_clienttyp);
502 /* If the client requested "?" then produce a listing */
503 if (!strcmp(buf, "?")) {
504 cprintf("%d %s\n", LISTING_FOLLOWS, buf);
505 dp = opendir(dirs[1]);
507 while (d = readdir(dp), d != NULL) {
508 if (d->d_name[0] != '.') {
509 cprintf(" %s\n", d->d_name);
520 /* Otherwise, look for the requested file by name. */
522 mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
523 if (IsEmptyStr(targ)) {
524 snprintf(buf2, sizeof buf2, "%s.%d",
525 buf, CC->cs_clientdev);
526 mesg_locate(targ, sizeof targ, buf2, 2,
527 (const char **)dirs);
528 if (IsEmptyStr(targ)) {
529 mesg_locate(targ, sizeof targ, buf, 2,
530 (const char **)dirs);
538 if (IsEmptyStr(targ)) {
539 cprintf("%d '%s' not found. (Searching in %s and %s)\n",
540 ERROR + FILE_NOT_FOUND,
548 mfp = fopen(targ, "r");
550 cprintf("%d Cannot open '%s': %s\n",
551 ERROR + INTERNAL_ERROR, targ, strerror(errno));
554 cprintf("%d %s\n", LISTING_FOLLOWS,buf);
556 while (fgets(buf, (sizeof buf - 1), mfp) != NULL) {
557 buf[strlen(buf)-1] = 0;
568 * enter system messages or help
570 void cmd_emsg(char *mname)
580 if (CtdlAccessCheck(ac_aide)) return;
582 extract_token(buf, mname, 0, '|', sizeof buf);
583 for (a=0; !IsEmptyStr(&buf[a]); ++a) { /* security measure */
584 if (buf[a] == '/') buf[a] = '.';
587 dirs[0] = strdup(ctdl_message_dir);
588 dirs[1] = strdup(ctdl_hlp_dir);
590 mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
594 if (IsEmptyStr(targ)) {
595 snprintf(targ, sizeof targ,
600 mfp = fopen(targ,"w");
602 cprintf("%d Cannot open '%s': %s\n",
603 ERROR + INTERNAL_ERROR, targ, strerror(errno));
606 cprintf("%d %s\n", SEND_LISTING, targ);
608 while (client_getln(buf, sizeof buf) >=0 && strcmp(buf, "000")) {
609 fprintf(mfp, "%s\n", buf);
616 /* Don't show the names of private rooms unless the viewing
617 * user also knows the rooms.
619 void GenerateRoomDisplay(char *real_room,
621 CitContext *viewer) {
625 strcpy(real_room, viewed->room.QRname);
626 if (viewed->room.QRflags & QR_MAILBOX) {
627 strcpy(real_room, &real_room[11]);
629 if (viewed->room.QRflags & QR_PRIVATE) {
630 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
631 if ( (ra & UA_KNOWN) == 0) {
632 strcpy(real_room, " ");
636 if (viewed->cs_flags & CS_CHAT) {
637 while (strlen(real_room) < 14) {
638 strcat(real_room, " ");
640 strcpy(&real_room[14], "<chat>");
646 * Convenience function.
648 int CtdlAccessCheck(int required_level) {
650 if (CC->internal_pgm) return(0);
651 if (required_level >= ac_internal) {
652 cprintf("%d This is not a user-level command.\n",
653 ERROR + HIGHER_ACCESS_REQUIRED);
657 if ((required_level >= ac_logged_in_or_guest) && (CC->logged_in == 0) && (!config.c_guest_logins)) {
658 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
662 if ((required_level >= ac_logged_in) && (CC->logged_in == 0)) {
663 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
667 if (CC->user.axlevel >= AxAideU) return(0);
668 if (required_level >= ac_aide) {
669 cprintf("%d This command requires Aide access.\n",
670 ERROR + HIGHER_ACCESS_REQUIRED);
674 if (is_room_aide()) return(0);
675 if (required_level >= ac_room_aide) {
676 cprintf("%d This command requires Aide or Room Aide access.\n",
677 ERROR + HIGHER_ACCESS_REQUIRED);
681 /* shhh ... succeed quietly */
688 * Terminate another running session
690 void cmd_term(char *cmdbuf)
695 session_num = extract_int(cmdbuf, 0);
697 terminated = CtdlTerminateOtherSession(session_num);
699 if (terminated < 0) {
700 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
704 if (terminated & TERM_FOUND) {
705 if (terminated == TERM_KILLED) {
706 cprintf("%d Session terminated.\n", CIT_OK);
709 cprintf("%d You are not allowed to do that.\n",
710 ERROR + HIGHER_ACCESS_REQUIRED);
714 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
720 * get the paginator prompt
722 void cmd_more(char *argbuf) {
723 cprintf("%d %s\n", CIT_OK, config.c_moreprompt);
730 void cmd_echo(char *etext)
732 cprintf("%d %s\n", CIT_OK, etext);
737 * Perform privilege escalation for an internal program
739 void cmd_ipgm(char *argbuf)
743 secret = extract_int(argbuf, 0);
745 /* For security reasons, we do NOT allow this command to run
746 * over the network. Local sockets only.
748 if (!CC->is_local_socket) {
750 cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED);
752 else if (secret == config.c_ipgm_secret) {
753 CC->internal_pgm = 1;
754 strcpy(CC->curr_user, "<internal program>");
755 CC->cs_flags = CC->cs_flags|CS_STEALTH;
756 cprintf("%d Authenticated as an internal program.\n", CIT_OK);
760 cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED);
761 syslog(LOG_ERR, "Warning: ipgm authentication failed.\n");
762 CC->kill_me = KILLME_AUTHFAILED;
768 * Shut down the server
770 void cmd_down(char *argbuf) {
771 char *Reply ="%d Shutting down server. Goodbye.\n";
773 if (CtdlAccessCheck(ac_aide)) return;
775 if (!IsEmptyStr(argbuf))
778 restart_server = extract_int(argbuf, 0);
780 if (restart_server > 0)
782 Reply = "%d citserver will now shut down and automatically restart.\n";
784 if ((restart_server > 0) && !running_as_daemon)
786 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
787 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
790 cprintf(Reply, state);
794 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
796 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
797 server_shutting_down = 1;
802 * Halt the server without exiting the server process.
804 void cmd_halt(char *argbuf) {
806 if (CtdlAccessCheck(ac_aide)) return;
808 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
809 server_shutting_down = 1;
810 shutdown_and_halt = 1;
815 * Schedule or cancel a server shutdown
817 void cmd_scdn(char *argbuf)
821 char *Reply = "%d %d\n";
823 if (CtdlAccessCheck(ac_aide)) return;
825 new_state = extract_int(argbuf, 0);
826 if ((new_state == 2) || (new_state == 3))
829 if (!running_as_daemon)
831 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
832 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
836 restart_server = extract_int(argbuf, 0);
839 if ((new_state == 0) || (new_state == 1)) {
840 ScheduledShutdown = new_state;
842 cprintf(Reply, state, ScheduledShutdown);
847 * Set or unset asynchronous protocol mode
849 void cmd_asyn(char *argbuf)
853 new_state = extract_int(argbuf, 0);
854 if ((new_state == 0) || (new_state == 1)) {
855 CC->is_async = new_state;
857 cprintf("%d %d\n", CIT_OK, CC->is_async);
863 * Back-end function for starting a session
865 void begin_session(CitContext *con)
868 * Initialize some variables specific to our context.
871 con->internal_pgm = 0;
872 con->download_fp = NULL;
873 con->upload_fp = NULL;
874 con->cached_msglist = NULL;
875 con->cached_num_msgs = 0;
876 con->FirstExpressMessage = NULL;
878 time(&con->lastidle);
879 strcpy(con->lastcmdname, " ");
880 strcpy(con->cs_clientname, "(unknown)");
881 strcpy(con->curr_user, NLI);
882 *con->net_node = '\0';
883 *con->fake_username = '\0';
884 *con->fake_hostname = '\0';
885 *con->fake_roomname = '\0';
886 *con->cs_clientinfo = '\0';
887 safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
888 safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
889 con->cs_UDSclientUID = -1;
890 con->cs_host[sizeof con->cs_host - 1] = 0;
891 if (!CC->is_local_socket) {
892 locate_host(con->cs_host, sizeof con->cs_host,
893 con->cs_addr, sizeof con->cs_addr,
900 #ifdef HAVE_STRUCT_UCRED
902 /* as http://www.wsinnovations.com/softeng/articles/uds.html told us... */
903 struct ucred credentials;
904 socklen_t ucred_length = sizeof(struct ucred);
906 /*fill in the user data structure */
907 if(getsockopt(con->client_socket, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) {
908 syslog(LOG_NOTICE, "could obtain credentials from unix domain socket");
912 /* the process ID of the process on the other side of the socket */
913 /* credentials.pid; */
915 /* the effective UID of the process on the other side of the socket */
916 con->cs_UDSclientUID = credentials.uid;
918 /* the effective primary GID of the process on the other side of the socket */
919 /* credentials.gid; */
921 /* To get supplemental groups, we will have to look them up in our account
922 database, after a reverse lookup on the UID to get the account name.
923 We can take this opportunity to check to see if this is a legit account.
925 snprintf(con->cs_clientinfo, sizeof(con->cs_clientinfo),
926 "PID: "F_PID_T"; UID: "F_UID_T"; GID: "F_XPID_T" ",
935 con->upload_type = UPL_FILE;
939 if (((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions)) || CtdlWantSingleUser()) {
943 if (!CC->is_local_socket) {
944 syslog(LOG_NOTICE, "Session (%s) started from %s (%s).\n", con->ServiceName, con->cs_host, con->cs_addr);
947 syslog(LOG_NOTICE, "Session (%s) started via local socket UID:%d.\n", con->ServiceName, con->cs_UDSclientUID);
950 /* Run any session startup routines registered by loadable modules */
951 PerformSessionHooks(EVT_START);
955 void citproto_begin_session() {
956 if (CC->nologin==1) {
957 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
958 ERROR + MAX_SESSIONS_EXCEEDED,
959 config.c_nodename, config.c_maxsessions
961 CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
964 cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
965 CC->can_receive_im = 1;
970 void cmd_noop(char *argbuf)
972 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
976 void cmd_qnop(char *argbuf)
978 /* do nothing, this command returns no response */
982 void cmd_quit(char *argbuf)
984 cprintf("%d Goodbye.\n", CIT_OK);
985 CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
989 void cmd_lout(char *argbuf)
993 cprintf("%d logged out.\n", CIT_OK);
998 * This loop recognizes all server commands.
1000 void do_command_loop(void) {
1004 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
1005 if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
1006 syslog(LOG_ERR, "Citadel client disconnected: ending session.\n");
1007 CC->kill_me = KILLME_CLIENT_DISCONNECTED;
1011 /* Log the server command, but don't show passwords... */
1012 if ( (strncasecmp(cmdbuf, "PASS", 4)) && (strncasecmp(cmdbuf, "SETP", 4)) ) {
1013 syslog(LOG_INFO, "[%d][%s(%ld)] %s",
1014 CC->cs_pid, CC->curr_user, CC->user.usernum, cmdbuf
1018 syslog(LOG_INFO, "[%d][%s(%ld)] <password command hidden from log>",
1019 CC->cs_pid, CC->curr_user, CC->user.usernum
1026 * Let other clients see the last command we executed, and
1027 * update the idle time, but not NOOP, QNOP, PEXP, GEXP, RWHO, or TIME.
1029 if ( (strncasecmp(cmdbuf, "NOOP", 4))
1030 && (strncasecmp(cmdbuf, "QNOP", 4))
1031 && (strncasecmp(cmdbuf, "PEXP", 4))
1032 && (strncasecmp(cmdbuf, "GEXP", 4))
1033 && (strncasecmp(cmdbuf, "RWHO", 4))
1034 && (strncasecmp(cmdbuf, "TIME", 4)) ) {
1035 strcpy(CC->lastcmdname, " ");
1036 safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
1037 time(&CC->lastidle);
1040 if ((strncasecmp(cmdbuf, "ENT0", 4))
1041 && (strncasecmp(cmdbuf, "MESG", 4))
1042 && (strncasecmp(cmdbuf, "MSGS", 4)))
1044 CC->cs_flags &= ~CS_POSTING;
1047 if (!DLoader_Exec_Cmd(cmdbuf)) {
1048 cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
1053 /* Run any after-each-command routines registered by modules */
1054 PerformSessionHooks(EVT_CMD);
1059 * This loop performs all asynchronous functions.
1061 void do_async_loop(void) {
1062 PerformSessionHooks(EVT_ASYNC);
1066 /*****************************************************************************/
1067 /* MODULE INITIALIZATION STUFF */
1068 /*****************************************************************************/
1070 CTDL_MODULE_INIT(citserver)
1073 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
1074 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
1075 CtdlRegisterProtoHook(cmd_quit, "QUIT", "log out and disconnect from server");
1076 CtdlRegisterProtoHook(cmd_lout, "LOUT", "log out but do not disconnect from server");
1077 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
1078 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
1079 CtdlRegisterProtoHook(cmd_mesg, "MESG", "fetch system banners");
1080 CtdlRegisterProtoHook(cmd_emsg, "EMSG", "submit system banners");
1081 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
1082 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
1083 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
1084 CtdlRegisterProtoHook(cmd_ipgm, "IPGM", "perform privilege escalation for internal programs");
1085 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
1086 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
1087 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
1088 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
1089 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
1091 /* return our id for the Log */