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, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
21 #include <sys/types.h>
24 #if TIME_WITH_SYS_TIME
25 # include <sys/time.h>
29 # include <sys/time.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #include <libcitadel.h>
52 #include "sysdep_decls.h"
54 #include "citserver.h"
57 #include "housekeeping.h"
61 #include "locate_host.h"
65 #include "euidindex.h"
67 #include "svn_revision.h"
68 #include "ctdl_module.h"
70 char *unique_session_numbers;
71 int ScheduledShutdown = 0;
72 time_t server_startup_time;
74 int openid_level_supported = 0;
77 * print the actual stack frame.
79 void cit_backtrace(void)
82 void *stack_frames[50];
87 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
88 strings = backtrace_symbols(stack_frames, size);
89 for (i = 0; i < size; i++) {
91 syslog(LOG_ALERT, "%s\n", strings[i]);
93 syslog(LOG_ALERT, "%p\n", stack_frames[i]);
99 void cit_oneline_backtrace(void)
101 #ifdef HAVE_BACKTRACE
102 void *stack_frames[50];
107 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
108 strings = backtrace_symbols(stack_frames, size);
112 for (i = 1; i < size; i++) {
114 StrBufAppendPrintf(Buf, "%s : ", strings[i]);
116 StrBufAppendPrintf(Buf, "%p : ", stack_frames[i]);
119 syslog(LOG_ALERT, "%s\n", ChrPtr(Buf));
126 * print the actual stack frame.
128 void cit_panic_backtrace(int SigNum)
130 #ifdef HAVE_BACKTRACE
131 void *stack_frames[10];
135 printf("caught signal 11\n");
136 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
137 strings = backtrace_symbols(stack_frames, size);
138 for (i = 0; i < size; i++) {
140 syslog(LOG_ALERT, "%s\n", strings[i]);
142 syslog(LOG_ALERT, "%p\n", stack_frames[i]);
150 * Various things that need to be initialized at startup
152 void master_startup(void) {
156 struct ctdlroom qrbuf;
159 syslog(LOG_DEBUG, "master_startup() started\n");
160 time(&server_startup_time);
163 syslog(LOG_INFO, "Opening databases\n");
167 syslog(LOG_INFO, "Creating base rooms (if necessary)\n");
168 CtdlCreateRoom(config.c_baseroom, 0, "", 0, 1, 0, VIEW_BBS);
169 CtdlCreateRoom(AIDEROOM, 3, "", 0, 1, 0, VIEW_BBS);
170 CtdlCreateRoom(SYSCONFIGROOM, 3, "", 0, 1, 0, VIEW_BBS);
171 CtdlCreateRoom(config.c_twitroom, 0, "", 0, 1, 0, VIEW_BBS);
173 /* The "Local System Configuration" room doesn't need to be visible */
174 if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) {
175 qrbuf.QRflags2 |= QR2_SYSTEM;
176 CtdlPutRoomLock(&qrbuf);
179 /* Aide needs to be public postable, else we're not RFC conformant. */
180 if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) {
181 qrbuf.QRflags2 |= QR2_SMTP_PUBLIC;
182 CtdlPutRoomLock(&qrbuf);
185 syslog(LOG_INFO, "Seeding the pseudo-random number generator...\n");
186 urandom = fopen("/dev/urandom", "r");
187 if (urandom != NULL) {
188 rv = fread(&seed, sizeof seed, 1, urandom);
190 syslog(LOG_EMERG, "failed to read random seed: %s\n",
195 gettimeofday(&tv, NULL);
203 syslog(LOG_DEBUG, "master_startup() finished\n");
208 * Cleanup routine to be called when the server is shutting down.
210 void master_cleanup(int exitcode) {
211 struct CleanupFunctionHook *fcn;
212 static int already_cleaning_up = 0;
214 if (already_cleaning_up) while(1) usleep(1000000);
215 already_cleaning_up = 1;
217 /* Run any cleanup routines registered by loadable modules */
218 for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) {
219 (*fcn->h_function_pointer)();
222 /* Close the AdjRefCount queue file */
225 /* Do system-dependent stuff */
226 sysdep_master_cleanup();
228 /* Close databases */
229 syslog(LOG_INFO, "Closing databases\n");
232 /* If the operator requested a halt but not an exit, halt here. */
233 if (shutdown_and_halt) {
234 syslog(LOG_NOTICE, "citserver: Halting server without exiting.\n");
235 fflush(stdout); fflush(stderr);
244 syslog(LOG_NOTICE, "citserver: Exiting with status %d\n", exitcode);
245 fflush(stdout); fflush(stderr);
247 if (restart_server != 0)
249 if ((running_as_daemon != 0) && ((exitcode == 0) ))
250 exitcode = CTDLEXIT_SHUTDOWN;
257 * cmd_info() - tell the client about this server
259 void cmd_info(char *cmdbuf) {
260 cprintf("%d Server info:\n", LISTING_FOLLOWS);
261 cprintf("%d\n", CC->cs_pid);
262 cprintf("%s\n", config.c_nodename);
263 cprintf("%s\n", config.c_humannode);
264 cprintf("%s\n", config.c_fqdn);
265 cprintf("%s\n", CITADEL);
266 cprintf("%d\n", REV_LEVEL);
267 cprintf("%s\n", config.c_site_location);
268 cprintf("%s\n", config.c_sysadm);
269 cprintf("%d\n", SERVER_TYPE);
270 cprintf("%s\n", config.c_moreprompt);
271 cprintf("1\n"); /* 1 = yes, this system supports floors */
272 cprintf("1\n"); /* 1 = we support the extended paging options */
273 cprintf("\n"); /* nonce no longer supported */
274 cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
277 cprintf("1\n"); /* 1 = yes, this server is LDAP-enabled */
279 cprintf("0\n"); /* 1 = no, this server is not LDAP-enabled */
282 if ((config.c_auth_mode == AUTHMODE_NATIVE) &&
283 (config.c_disable_newu == 0))
285 cprintf("%d\n", config.c_disable_newu);
288 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
291 cprintf("%s\n", config.c_default_cal_zone);
293 /* thread load averages -- temporarily disabled during refactoring of this code */
294 cprintf("0\n"); /* load average */
295 cprintf("0\n"); /* worker average */
296 cprintf("0\n"); /* thread count */
298 cprintf("1\n"); /* yes, Sieve mail filtering is supported */
299 cprintf("%d\n", config.c_enable_fulltext);
300 cprintf("%s\n", svn_revision());
302 if (config.c_auth_mode == AUTHMODE_NATIVE) {
303 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
306 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
309 cprintf("%d\n", config.c_guest_logins);
316 * returns an asterisk if there are any instant messages waiting,
319 char CtdlCheckExpress(void) {
320 if (CC->FirstExpressMessage == NULL) {
328 void cmd_time(char *argbuf)
334 localtime_r(&tv, &tmp);
336 /* timezone and daylight global variables are not portable. */
337 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
338 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
340 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
346 * Check originating host against the public_clients file. This determines
347 * whether the client is allowed to change the hostname for this session
348 * (for example, to show the location of the user rather than the location
351 int is_public_client(void)
357 char *public_clientspos;
358 char *public_clientsend;
361 static time_t pc_timestamp = 0;
362 static char public_clients[SIZ];
363 static char public_clients_file[SIZ];
365 #define LOCALHOSTSTR "127.0.0.1"
367 snprintf(public_clients_file, sizeof public_clients_file, "%s/public_clients", ctdl_etc_dir);
370 * Check the time stamp on the public_clients file. If it's been
371 * updated since the last time we were here (or if this is the first
372 * time we've been through the loop), read its contents and learn
373 * the IP addresses of the listed hosts.
375 if (stat(public_clients_file, &statbuf) != 0) {
376 /* No public_clients file exists, so bail out */
377 syslog(LOG_WARNING, "Warning: '%s' does not exist\n",
378 public_clients_file);
382 if (statbuf.st_mtime > pc_timestamp) {
383 begin_critical_section(S_PUBLIC_CLIENTS);
384 syslog(LOG_INFO, "Loading %s\n", public_clients_file);
386 public_clientspos = &public_clients[0];
387 public_clientsend = public_clientspos + SIZ;
388 safestrncpy(public_clientspos, LOCALHOSTSTR, sizeof public_clients);
389 public_clientspos += sizeof(LOCALHOSTSTR) - 1;
391 if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
392 *(public_clientspos++) = '|';
394 while (!IsEmptyStr (paddr) &&
395 (public_clientspos < public_clientsend))
396 *(public_clientspos++) = *(paddr++);
399 fp = fopen(public_clients_file, "r");
401 while ((fgets(buf, sizeof buf, fp)!=NULL) &&
402 (public_clientspos < public_clientsend)){
405 while (!IsEmptyStr(ptr)) {
413 while (ptr>buf && isspace(*ptr)) {
416 if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
417 *(public_clientspos++) = '|';
419 while (!IsEmptyStr(paddr) &&
420 (public_clientspos < public_clientsend)){
421 *(public_clientspos++) = *(paddr++);
425 if (fp != NULL) fclose(fp);
426 pc_timestamp = time(NULL);
427 end_critical_section(S_PUBLIC_CLIENTS);
430 syslog(LOG_DEBUG, "Checking whether %s is a local or public client\n",
432 for (i=0; i<num_parms(public_clients); ++i) {
433 extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
434 if (!strcasecmp(CC->cs_addr, addrbuf)) {
435 syslog(LOG_DEBUG, "... yes its local.\n");
440 /* No hits. This is not a public client. */
441 syslog(LOG_DEBUG, "... no it isn't.\n");
447 * the client is identifying itself to the server
449 void cmd_iden(char *argbuf)
457 if (num_parms(argbuf)<4) {
458 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
462 dev_code = extract_int(argbuf,0);
463 cli_code = extract_int(argbuf,1);
464 rev_level = extract_int(argbuf,2);
465 extract_token(desc, argbuf, 3, '|', sizeof desc);
467 safestrncpy(from_host, config.c_fqdn, sizeof from_host);
468 from_host[sizeof from_host - 1] = 0;
469 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
471 CC->cs_clientdev = dev_code;
472 CC->cs_clienttyp = cli_code;
473 CC->cs_clientver = rev_level;
474 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
475 CC->cs_clientname[31] = 0;
477 /* For local sockets and public clients, trust the hostname supplied by the client */
478 if ( (CC->is_local_socket) || (is_public_client()) ) {
479 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
480 CC->cs_host[sizeof CC->cs_host - 1] = 0;
484 syslog(LOG_NOTICE, "Client %d/%d/%01d.%02d (%s) from %s\n",
492 cprintf("%d Ok\n",CIT_OK);
495 typedef const char *ccharp;
497 * display system messages or help
499 void cmd_mesg(char *mname)
509 extract_token(buf, mname, 0, '|', sizeof buf);
511 dirs[0] = strdup(ctdl_message_dir);
512 dirs[1] = strdup(ctdl_hlp_dir);
514 snprintf(buf2, sizeof buf2, "%s.%d.%d",
515 buf, CC->cs_clientdev, CC->cs_clienttyp);
517 /* If the client requested "?" then produce a listing */
518 if (!strcmp(buf, "?")) {
519 cprintf("%d %s\n", LISTING_FOLLOWS, buf);
520 dp = opendir(dirs[1]);
522 while (d = readdir(dp), d != NULL) {
523 if (d->d_name[0] != '.') {
524 cprintf(" %s\n", d->d_name);
535 /* Otherwise, look for the requested file by name. */
537 mesg_locate(targ, sizeof targ, buf2, 2, (const ccharp*)dirs);
538 if (IsEmptyStr(targ)) {
539 snprintf(buf2, sizeof buf2, "%s.%d",
540 buf, CC->cs_clientdev);
541 mesg_locate(targ, sizeof targ, buf2, 2,
542 (const ccharp*)dirs);
543 if (IsEmptyStr(targ)) {
544 mesg_locate(targ, sizeof targ, buf, 2,
545 (const ccharp*)dirs);
553 if (IsEmptyStr(targ)) {
554 cprintf("%d '%s' not found. (Searching in %s and %s)\n",
555 ERROR + FILE_NOT_FOUND,
563 mfp = fopen(targ, "r");
565 cprintf("%d Cannot open '%s': %s\n",
566 ERROR + INTERNAL_ERROR, targ, strerror(errno));
569 cprintf("%d %s\n", LISTING_FOLLOWS,buf);
571 while (fgets(buf, (sizeof buf - 1), mfp) != NULL) {
572 buf[strlen(buf)-1] = 0;
583 * enter system messages or help
585 void cmd_emsg(char *mname)
595 if (CtdlAccessCheck(ac_aide)) return;
597 extract_token(buf, mname, 0, '|', sizeof buf);
598 for (a=0; !IsEmptyStr(&buf[a]); ++a) { /* security measure */
599 if (buf[a] == '/') buf[a] = '.';
602 dirs[0] = strdup(ctdl_message_dir);
603 dirs[1] = strdup(ctdl_hlp_dir);
605 mesg_locate(targ, sizeof targ, buf, 2, (const ccharp*)dirs);
609 if (IsEmptyStr(targ)) {
610 snprintf(targ, sizeof targ,
615 mfp = fopen(targ,"w");
617 cprintf("%d Cannot open '%s': %s\n",
618 ERROR + INTERNAL_ERROR, targ, strerror(errno));
621 cprintf("%d %s\n", SEND_LISTING, targ);
623 while (client_getln(buf, sizeof buf) >=0 && strcmp(buf, "000")) {
624 fprintf(mfp, "%s\n", buf);
631 /* Don't show the names of private rooms unless the viewing
632 * user also knows the rooms.
634 void GenerateRoomDisplay(char *real_room,
636 CitContext *viewer) {
640 strcpy(real_room, viewed->room.QRname);
641 if (viewed->room.QRflags & QR_MAILBOX) {
642 strcpy(real_room, &real_room[11]);
644 if (viewed->room.QRflags & QR_PRIVATE) {
645 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
646 if ( (ra & UA_KNOWN) == 0) {
647 strcpy(real_room, " ");
651 if (viewed->cs_flags & CS_CHAT) {
652 while (strlen(real_room) < 14) {
653 strcat(real_room, " ");
655 strcpy(&real_room[14], "<chat>");
661 * Convenience function.
663 int CtdlAccessCheck(int required_level) {
665 if (CC->internal_pgm) return(0);
666 if (required_level >= ac_internal) {
667 cprintf("%d This is not a user-level command.\n",
668 ERROR + HIGHER_ACCESS_REQUIRED);
672 if ((required_level >= ac_logged_in_or_guest) && (CC->logged_in == 0) && (!config.c_guest_logins)) {
673 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
677 if ((required_level >= ac_logged_in) && (CC->logged_in == 0)) {
678 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
682 if (CC->user.axlevel >= AxAideU) return(0);
683 if (required_level >= ac_aide) {
684 cprintf("%d This command requires Admin access.\n",
685 ERROR + HIGHER_ACCESS_REQUIRED);
689 if (is_room_aide()) return(0);
690 if (required_level >= ac_room_aide) {
691 cprintf("%d This command requires Admin or Room Admin access.\n",
692 ERROR + HIGHER_ACCESS_REQUIRED);
696 /* shhh ... succeed quietly */
703 * Terminate another running session
705 void cmd_term(char *cmdbuf)
710 session_num = extract_int(cmdbuf, 0);
712 terminated = CtdlTerminateOtherSession(session_num);
714 if (terminated < 0) {
715 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
719 if (terminated & TERM_FOUND) {
720 if (terminated == TERM_KILLED) {
721 cprintf("%d Session terminated.\n", CIT_OK);
724 cprintf("%d You are not allowed to do that.\n",
725 ERROR + HIGHER_ACCESS_REQUIRED);
729 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
735 * get the paginator prompt
737 void cmd_more(char *argbuf) {
738 cprintf("%d %s\n", CIT_OK, config.c_moreprompt);
745 void cmd_echo(char *etext)
747 cprintf("%d %s\n", CIT_OK, etext);
753 * Shut down the server
755 void cmd_down(char *argbuf) {
756 char *Reply ="%d Shutting down server. Goodbye.\n";
758 if (CtdlAccessCheck(ac_aide)) return;
760 if (!IsEmptyStr(argbuf))
763 restart_server = extract_int(argbuf, 0);
765 if (restart_server > 0)
767 Reply = "%d citserver will now shut down and automatically restart.\n";
769 if ((restart_server > 0) && !running_as_daemon)
771 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
772 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
775 cprintf(Reply, state);
779 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
781 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
782 server_shutting_down = 1;
787 * Halt the server without exiting the server process.
789 void cmd_halt(char *argbuf) {
791 if (CtdlAccessCheck(ac_aide)) return;
793 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
794 server_shutting_down = 1;
795 shutdown_and_halt = 1;
800 * Schedule or cancel a server shutdown
802 void cmd_scdn(char *argbuf)
806 char *Reply = "%d %d\n";
808 if (CtdlAccessCheck(ac_aide)) return;
810 new_state = extract_int(argbuf, 0);
811 if ((new_state == 2) || (new_state == 3))
814 if (!running_as_daemon)
816 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
817 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
821 restart_server = extract_int(argbuf, 0);
824 if ((new_state == 0) || (new_state == 1)) {
825 ScheduledShutdown = new_state;
827 cprintf(Reply, state, ScheduledShutdown);
832 * Set or unset asynchronous protocol mode
834 void cmd_asyn(char *argbuf)
838 new_state = extract_int(argbuf, 0);
839 if ((new_state == 0) || (new_state == 1)) {
840 CC->is_async = new_state;
842 cprintf("%d %d\n", CIT_OK, CC->is_async);
848 * Back-end function for starting a session
850 void begin_session(CitContext *con)
853 * Initialize some variables specific to our context.
856 con->internal_pgm = 0;
857 con->download_fp = NULL;
858 con->upload_fp = NULL;
859 con->cached_msglist = NULL;
860 con->cached_num_msgs = 0;
861 con->FirstExpressMessage = NULL;
863 time(&con->lastidle);
864 strcpy(con->lastcmdname, " ");
865 strcpy(con->cs_clientname, "(unknown)");
866 strcpy(con->curr_user, NLI);
867 *con->net_node = '\0';
868 *con->fake_username = '\0';
869 *con->fake_hostname = '\0';
870 *con->fake_roomname = '\0';
871 *con->cs_clientinfo = '\0';
872 safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
873 safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
874 con->cs_UDSclientUID = -1;
875 con->cs_host[sizeof con->cs_host - 1] = 0;
876 if (!CC->is_local_socket) {
877 locate_host(con->cs_host, sizeof con->cs_host,
878 con->cs_addr, sizeof con->cs_addr,
885 #ifdef HAVE_STRUCT_UCRED
887 /* as http://www.wsinnovations.com/softeng/articles/uds.html told us... */
888 struct ucred credentials;
889 socklen_t ucred_length = sizeof(struct ucred);
891 /*fill in the user data structure */
892 if(getsockopt(con->client_socket, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) {
893 syslog(LOG_NOTICE, "could obtain credentials from unix domain socket");
897 /* the process ID of the process on the other side of the socket */
898 /* credentials.pid; */
900 /* the effective UID of the process on the other side of the socket */
901 con->cs_UDSclientUID = credentials.uid;
903 /* the effective primary GID of the process on the other side of the socket */
904 /* credentials.gid; */
906 /* To get supplemental groups, we will have to look them up in our account
907 database, after a reverse lookup on the UID to get the account name.
908 We can take this opportunity to check to see if this is a legit account.
910 snprintf(con->cs_clientinfo, sizeof(con->cs_clientinfo),
911 "PID: "F_PID_T"; UID: "F_UID_T"; GID: "F_XPID_T" ",
920 con->upload_type = UPL_FILE;
924 if (((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions)) || CtdlWantSingleUser()) {
928 if (!CC->is_local_socket) {
929 syslog(LOG_NOTICE, "Session (%s) started from %s (%s).\n", con->ServiceName, con->cs_host, con->cs_addr);
932 syslog(LOG_NOTICE, "Session (%s) started via local socket UID:%d.\n", con->ServiceName, con->cs_UDSclientUID);
935 /* Run any session startup routines registered by loadable modules */
936 PerformSessionHooks(EVT_START);
940 void citproto_begin_session() {
941 if (CC->nologin==1) {
942 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
943 ERROR + MAX_SESSIONS_EXCEEDED,
944 config.c_nodename, config.c_maxsessions
946 CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
949 cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
950 CC->can_receive_im = 1;
955 void citproto_begin_admin_session() {
956 CC->internal_pgm = 1;
957 cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, config.c_nodename);
961 void cmd_noop(char *argbuf)
963 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
967 void cmd_qnop(char *argbuf)
969 /* do nothing, this command returns no response */
973 void cmd_quit(char *argbuf)
975 cprintf("%d Goodbye.\n", CIT_OK);
976 CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
980 void cmd_lout(char *argbuf)
984 cprintf("%d logged out.\n", CIT_OK);
989 * This loop recognizes all server commands.
991 void do_command_loop(void) {
995 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
996 if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
997 syslog(LOG_ERR, "Citadel client disconnected: ending session.\n");
998 CC->kill_me = KILLME_CLIENT_DISCONNECTED;
1002 /* Log the server command, but don't show passwords... */
1003 if ( (strncasecmp(cmdbuf, "PASS", 4)) && (strncasecmp(cmdbuf, "SETP", 4)) ) {
1004 syslog(LOG_INFO, "[%d][%s(%ld)] %s",
1005 CC->cs_pid, CC->curr_user, CC->user.usernum, cmdbuf
1009 syslog(LOG_INFO, "[%d][%s(%ld)] <password command hidden from log>",
1010 CC->cs_pid, CC->curr_user, CC->user.usernum
1017 * Let other clients see the last command we executed, and
1018 * update the idle time, but not NOOP, QNOP, PEXP, GEXP, RWHO, or TIME.
1020 if ( (strncasecmp(cmdbuf, "NOOP", 4))
1021 && (strncasecmp(cmdbuf, "QNOP", 4))
1022 && (strncasecmp(cmdbuf, "PEXP", 4))
1023 && (strncasecmp(cmdbuf, "GEXP", 4))
1024 && (strncasecmp(cmdbuf, "RWHO", 4))
1025 && (strncasecmp(cmdbuf, "TIME", 4)) ) {
1026 strcpy(CC->lastcmdname, " ");
1027 safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
1028 time(&CC->lastidle);
1031 if ((strncasecmp(cmdbuf, "ENT0", 4))
1032 && (strncasecmp(cmdbuf, "MESG", 4))
1033 && (strncasecmp(cmdbuf, "MSGS", 4)))
1035 CC->cs_flags &= ~CS_POSTING;
1038 if (!DLoader_Exec_Cmd(cmdbuf)) {
1039 cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
1044 /* Run any after-each-command routines registered by modules */
1045 PerformSessionHooks(EVT_CMD);
1050 * This loop performs all asynchronous functions.
1052 void do_async_loop(void) {
1053 PerformSessionHooks(EVT_ASYNC);
1057 /*****************************************************************************/
1058 /* MODULE INITIALIZATION STUFF */
1059 /*****************************************************************************/
1061 CTDL_MODULE_INIT(citserver)
1064 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
1065 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
1066 CtdlRegisterProtoHook(cmd_quit, "QUIT", "log out and disconnect from server");
1067 CtdlRegisterProtoHook(cmd_lout, "LOUT", "log out but do not disconnect from server");
1068 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
1069 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
1070 CtdlRegisterProtoHook(cmd_mesg, "MESG", "fetch system banners");
1071 CtdlRegisterProtoHook(cmd_emsg, "EMSG", "submit system banners");
1072 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
1073 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
1074 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
1075 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
1076 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
1077 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
1078 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
1079 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
1081 /* return our id for the Log */