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"
73 #include "ctdl_module.h"
75 char *unique_session_numbers;
76 int ScheduledShutdown = 0;
77 time_t server_startup_time;
79 int openid_level_supported = 0;
82 * print the actual stack frame.
84 void cit_backtrace(void)
87 void *stack_frames[50];
92 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
93 strings = backtrace_symbols(stack_frames, size);
94 for (i = 0; i < size; i++) {
96 syslog(LOG_ALERT, "%s\n", strings[i]);
98 syslog(LOG_ALERT, "%p\n", stack_frames[i]);
104 void cit_oneline_backtrace(void)
106 #ifdef HAVE_BACKTRACE
107 void *stack_frames[50];
112 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
113 strings = backtrace_symbols(stack_frames, size);
117 for (i = 1; i < size; i++) {
119 StrBufAppendPrintf(Buf, "%s : ", strings[i]);
121 StrBufAppendPrintf(Buf, "%p : ", stack_frames[i]);
124 syslog(LOG_ALERT, "%s\n", ChrPtr(Buf));
131 * print the actual stack frame.
133 void cit_panic_backtrace(int SigNum)
135 #ifdef HAVE_BACKTRACE
136 void *stack_frames[10];
140 printf("caught signal 11\n");
141 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
142 strings = backtrace_symbols(stack_frames, size);
143 for (i = 0; i < size; i++) {
145 syslog(LOG_ALERT, "%s\n", strings[i]);
147 syslog(LOG_ALERT, "%p\n", stack_frames[i]);
155 * Various things that need to be initialized at startup
157 void master_startup(void) {
161 struct ctdlroom qrbuf;
164 syslog(LOG_DEBUG, "master_startup() started\n");
165 time(&server_startup_time);
168 syslog(LOG_INFO, "Opening databases\n");
172 syslog(LOG_INFO, "Creating base rooms (if necessary)\n");
173 CtdlCreateRoom(config.c_baseroom, 0, "", 0, 1, 0, VIEW_BBS);
174 CtdlCreateRoom(AIDEROOM, 3, "", 0, 1, 0, VIEW_BBS);
175 CtdlCreateRoom(SYSCONFIGROOM, 3, "", 0, 1, 0, VIEW_BBS);
176 CtdlCreateRoom(config.c_twitroom, 0, "", 0, 1, 0, VIEW_BBS);
178 /* The "Local System Configuration" room doesn't need to be visible */
179 if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) {
180 qrbuf.QRflags2 |= QR2_SYSTEM;
181 CtdlPutRoomLock(&qrbuf);
184 /* Aide needs to be public postable, else we're not RFC conformant. */
185 if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) {
186 qrbuf.QRflags2 |= QR2_SMTP_PUBLIC;
187 CtdlPutRoomLock(&qrbuf);
190 syslog(LOG_INFO, "Seeding the pseudo-random number generator...\n");
191 urandom = fopen("/dev/urandom", "r");
192 if (urandom != NULL) {
193 rv = fread(&seed, sizeof seed, 1, urandom);
195 syslog(LOG_EMERG, "failed to read random seed: %s\n",
200 gettimeofday(&tv, NULL);
208 syslog(LOG_DEBUG, "master_startup() finished\n");
213 * Cleanup routine to be called when the server is shutting down.
215 void master_cleanup(int exitcode) {
216 struct CleanupFunctionHook *fcn;
217 static int already_cleaning_up = 0;
219 if (already_cleaning_up) while(1) usleep(1000);
220 already_cleaning_up = 1;
222 /* Run any cleanup routines registered by loadable modules */
223 for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) {
224 (*fcn->h_function_pointer)();
227 /* Close the AdjRefCount queue file */
230 /* Do system-dependent stuff */
231 sysdep_master_cleanup();
233 /* Close databases */
234 syslog(LOG_INFO, "Closing databases\n");
237 /* If the operator requested a halt but not an exit, halt here. */
238 if (shutdown_and_halt) {
239 syslog(LOG_NOTICE, "citserver: Halting server without exiting.\n");
240 fflush(stdout); fflush(stderr);
249 syslog(LOG_NOTICE, "citserver: Exiting with status %d\n", exitcode);
250 fflush(stdout); fflush(stderr);
252 if (restart_server != 0)
254 if ((running_as_daemon != 0) && ((exitcode == 0) ))
255 exitcode = CTDLEXIT_SHUTDOWN;
262 * cmd_info() - tell the client about this server
264 void cmd_info(char *cmdbuf) {
265 cprintf("%d Server info:\n", LISTING_FOLLOWS);
266 cprintf("%d\n", CC->cs_pid);
267 cprintf("%s\n", config.c_nodename);
268 cprintf("%s\n", config.c_humannode);
269 cprintf("%s\n", config.c_fqdn);
270 cprintf("%s\n", CITADEL);
271 cprintf("%d\n", REV_LEVEL);
272 cprintf("%s\n", config.c_site_location);
273 cprintf("%s\n", config.c_sysadm);
274 cprintf("%d\n", SERVER_TYPE);
275 cprintf("%s\n", config.c_moreprompt);
276 cprintf("1\n"); /* 1 = yes, this system supports floors */
277 cprintf("1\n"); /* 1 = we support the extended paging options */
278 cprintf("\n"); /* nonce no longer supported */
279 cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
282 cprintf("1\n"); /* 1 = yes, this server is LDAP-enabled */
284 cprintf("0\n"); /* 1 = no, this server is not LDAP-enabled */
287 if (config.c_auth_mode == AUTHMODE_NATIVE) {
288 cprintf("%d\n", config.c_disable_newu);
291 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
294 cprintf("%s\n", config.c_default_cal_zone);
296 /* thread load averages -- temporarily disabled during refactoring of this code */
297 cprintf("0\n"); /* load average */
298 cprintf("0\n"); /* worker average */
299 cprintf("0\n"); /* thread count */
301 cprintf("1\n"); /* yes, Sieve mail filtering is supported */
302 cprintf("%d\n", config.c_enable_fulltext);
303 cprintf("%s\n", svn_revision());
305 if (config.c_auth_mode == AUTHMODE_NATIVE) {
306 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
309 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
312 cprintf("%d\n", config.c_guest_logins);
319 * returns an asterisk if there are any instant messages waiting,
322 char CtdlCheckExpress(void) {
323 if (CC->FirstExpressMessage == NULL) {
331 void cmd_time(char *argbuf)
337 localtime_r(&tv, &tmp);
339 /* timezone and daylight global variables are not portable. */
340 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
341 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
343 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
349 * Check originating host against the public_clients file. This determines
350 * whether the client is allowed to change the hostname for this session
351 * (for example, to show the location of the user rather than the location
354 int is_public_client(void)
360 char *public_clientspos;
361 char *public_clientsend;
364 static time_t pc_timestamp = 0;
365 static char public_clients[SIZ];
366 static char public_clients_file[SIZ];
368 #define LOCALHOSTSTR "127.0.0.1"
370 snprintf(public_clients_file, sizeof public_clients_file, "%s/public_clients", ctdl_etc_dir);
373 * Check the time stamp on the public_clients file. If it's been
374 * updated since the last time we were here (or if this is the first
375 * time we've been through the loop), read its contents and learn
376 * the IP addresses of the listed hosts.
378 if (stat(public_clients_file, &statbuf) != 0) {
379 /* No public_clients file exists, so bail out */
380 syslog(LOG_WARNING, "Warning: '%s' does not exist\n",
381 public_clients_file);
385 if (statbuf.st_mtime > pc_timestamp) {
386 begin_critical_section(S_PUBLIC_CLIENTS);
387 syslog(LOG_INFO, "Loading %s\n", public_clients_file);
389 public_clientspos = &public_clients[0];
390 public_clientsend = public_clientspos + SIZ;
391 safestrncpy(public_clientspos, LOCALHOSTSTR, sizeof public_clients);
392 public_clientspos += sizeof(LOCALHOSTSTR) - 1;
394 if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
395 *(public_clientspos++) = '|';
397 while (!IsEmptyStr (paddr) &&
398 (public_clientspos < public_clientsend))
399 *(public_clientspos++) = *(paddr++);
402 fp = fopen(public_clients_file, "r");
404 while ((fgets(buf, sizeof buf, fp)!=NULL) &&
405 (public_clientspos < public_clientsend)){
408 while (!IsEmptyStr(ptr)) {
416 while (ptr>buf && isspace(*ptr)) {
419 if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
420 *(public_clientspos++) = '|';
422 while (!IsEmptyStr(paddr) &&
423 (public_clientspos < public_clientsend)){
424 *(public_clientspos++) = *(paddr++);
428 if (fp != NULL) fclose(fp);
429 pc_timestamp = time(NULL);
430 end_critical_section(S_PUBLIC_CLIENTS);
433 syslog(LOG_DEBUG, "Checking whether %s is a local or public client\n",
435 for (i=0; i<num_parms(public_clients); ++i) {
436 extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
437 if (!strcasecmp(CC->cs_addr, addrbuf)) {
438 syslog(LOG_DEBUG, "... yes its local.\n");
443 /* No hits. This is not a public client. */
444 syslog(LOG_DEBUG, "... no it isn't.\n");
450 * the client is identifying itself to the server
452 void cmd_iden(char *argbuf)
460 if (num_parms(argbuf)<4) {
461 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
465 dev_code = extract_int(argbuf,0);
466 cli_code = extract_int(argbuf,1);
467 rev_level = extract_int(argbuf,2);
468 extract_token(desc, argbuf, 3, '|', sizeof desc);
470 safestrncpy(from_host, config.c_fqdn, sizeof from_host);
471 from_host[sizeof from_host - 1] = 0;
472 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
474 CC->cs_clientdev = dev_code;
475 CC->cs_clienttyp = cli_code;
476 CC->cs_clientver = rev_level;
477 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
478 CC->cs_clientname[31] = 0;
480 /* For local sockets and public clients, trust the hostname supplied by the client */
481 if ( (CC->is_local_socket) || (is_public_client()) ) {
482 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
483 CC->cs_host[sizeof CC->cs_host - 1] = 0;
487 syslog(LOG_NOTICE, "Client %d/%d/%01d.%02d (%s) from %s\n",
495 cprintf("%d Ok\n",CIT_OK);
498 typedef const char *ccharp;
500 * display system messages or help
502 void cmd_mesg(char *mname)
512 extract_token(buf, mname, 0, '|', sizeof buf);
514 dirs[0] = strdup(ctdl_message_dir);
515 dirs[1] = strdup(ctdl_hlp_dir);
517 snprintf(buf2, sizeof buf2, "%s.%d.%d",
518 buf, CC->cs_clientdev, CC->cs_clienttyp);
520 /* If the client requested "?" then produce a listing */
521 if (!strcmp(buf, "?")) {
522 cprintf("%d %s\n", LISTING_FOLLOWS, buf);
523 dp = opendir(dirs[1]);
525 while (d = readdir(dp), d != NULL) {
526 if (d->d_name[0] != '.') {
527 cprintf(" %s\n", d->d_name);
538 /* Otherwise, look for the requested file by name. */
540 mesg_locate(targ, sizeof targ, buf2, 2, (const ccharp*)dirs);
541 if (IsEmptyStr(targ)) {
542 snprintf(buf2, sizeof buf2, "%s.%d",
543 buf, CC->cs_clientdev);
544 mesg_locate(targ, sizeof targ, buf2, 2,
545 (const ccharp*)dirs);
546 if (IsEmptyStr(targ)) {
547 mesg_locate(targ, sizeof targ, buf, 2,
548 (const ccharp*)dirs);
556 if (IsEmptyStr(targ)) {
557 cprintf("%d '%s' not found. (Searching in %s and %s)\n",
558 ERROR + FILE_NOT_FOUND,
566 mfp = fopen(targ, "r");
568 cprintf("%d Cannot open '%s': %s\n",
569 ERROR + INTERNAL_ERROR, targ, strerror(errno));
572 cprintf("%d %s\n", LISTING_FOLLOWS,buf);
574 while (fgets(buf, (sizeof buf - 1), mfp) != NULL) {
575 buf[strlen(buf)-1] = 0;
586 * enter system messages or help
588 void cmd_emsg(char *mname)
598 if (CtdlAccessCheck(ac_aide)) return;
600 extract_token(buf, mname, 0, '|', sizeof buf);
601 for (a=0; !IsEmptyStr(&buf[a]); ++a) { /* security measure */
602 if (buf[a] == '/') buf[a] = '.';
605 dirs[0] = strdup(ctdl_message_dir);
606 dirs[1] = strdup(ctdl_hlp_dir);
608 mesg_locate(targ, sizeof targ, buf, 2, (const ccharp*)dirs);
612 if (IsEmptyStr(targ)) {
613 snprintf(targ, sizeof targ,
618 mfp = fopen(targ,"w");
620 cprintf("%d Cannot open '%s': %s\n",
621 ERROR + INTERNAL_ERROR, targ, strerror(errno));
624 cprintf("%d %s\n", SEND_LISTING, targ);
626 while (client_getln(buf, sizeof buf) >=0 && strcmp(buf, "000")) {
627 fprintf(mfp, "%s\n", buf);
634 /* Don't show the names of private rooms unless the viewing
635 * user also knows the rooms.
637 void GenerateRoomDisplay(char *real_room,
639 CitContext *viewer) {
643 strcpy(real_room, viewed->room.QRname);
644 if (viewed->room.QRflags & QR_MAILBOX) {
645 strcpy(real_room, &real_room[11]);
647 if (viewed->room.QRflags & QR_PRIVATE) {
648 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
649 if ( (ra & UA_KNOWN) == 0) {
650 strcpy(real_room, " ");
654 if (viewed->cs_flags & CS_CHAT) {
655 while (strlen(real_room) < 14) {
656 strcat(real_room, " ");
658 strcpy(&real_room[14], "<chat>");
664 * Convenience function.
666 int CtdlAccessCheck(int required_level) {
668 if (CC->internal_pgm) return(0);
669 if (required_level >= ac_internal) {
670 cprintf("%d This is not a user-level command.\n",
671 ERROR + HIGHER_ACCESS_REQUIRED);
675 if ((required_level >= ac_logged_in_or_guest) && (CC->logged_in == 0) && (!config.c_guest_logins)) {
676 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
680 if ((required_level >= ac_logged_in) && (CC->logged_in == 0)) {
681 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
685 if (CC->user.axlevel >= AxAideU) return(0);
686 if (required_level >= ac_aide) {
687 cprintf("%d This command requires Admin access.\n",
688 ERROR + HIGHER_ACCESS_REQUIRED);
692 if (is_room_aide()) return(0);
693 if (required_level >= ac_room_aide) {
694 cprintf("%d This command requires Admin or Room Admin access.\n",
695 ERROR + HIGHER_ACCESS_REQUIRED);
699 /* shhh ... succeed quietly */
706 * Terminate another running session
708 void cmd_term(char *cmdbuf)
713 session_num = extract_int(cmdbuf, 0);
715 terminated = CtdlTerminateOtherSession(session_num);
717 if (terminated < 0) {
718 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
722 if (terminated & TERM_FOUND) {
723 if (terminated == TERM_KILLED) {
724 cprintf("%d Session terminated.\n", CIT_OK);
727 cprintf("%d You are not allowed to do that.\n",
728 ERROR + HIGHER_ACCESS_REQUIRED);
732 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
738 * get the paginator prompt
740 void cmd_more(char *argbuf) {
741 cprintf("%d %s\n", CIT_OK, config.c_moreprompt);
748 void cmd_echo(char *etext)
750 cprintf("%d %s\n", CIT_OK, etext);
756 * Shut down the server
758 void cmd_down(char *argbuf) {
759 char *Reply ="%d Shutting down server. Goodbye.\n";
761 if (CtdlAccessCheck(ac_aide)) return;
763 if (!IsEmptyStr(argbuf))
766 restart_server = extract_int(argbuf, 0);
768 if (restart_server > 0)
770 Reply = "%d citserver will now shut down and automatically restart.\n";
772 if ((restart_server > 0) && !running_as_daemon)
774 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
775 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
778 cprintf(Reply, state);
782 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
784 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
785 server_shutting_down = 1;
790 * Halt the server without exiting the server process.
792 void cmd_halt(char *argbuf) {
794 if (CtdlAccessCheck(ac_aide)) return;
796 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
797 server_shutting_down = 1;
798 shutdown_and_halt = 1;
803 * Schedule or cancel a server shutdown
805 void cmd_scdn(char *argbuf)
809 char *Reply = "%d %d\n";
811 if (CtdlAccessCheck(ac_aide)) return;
813 new_state = extract_int(argbuf, 0);
814 if ((new_state == 2) || (new_state == 3))
817 if (!running_as_daemon)
819 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
820 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
824 restart_server = extract_int(argbuf, 0);
827 if ((new_state == 0) || (new_state == 1)) {
828 ScheduledShutdown = new_state;
830 cprintf(Reply, state, ScheduledShutdown);
835 * Set or unset asynchronous protocol mode
837 void cmd_asyn(char *argbuf)
841 new_state = extract_int(argbuf, 0);
842 if ((new_state == 0) || (new_state == 1)) {
843 CC->is_async = new_state;
845 cprintf("%d %d\n", CIT_OK, CC->is_async);
851 * Back-end function for starting a session
853 void begin_session(CitContext *con)
856 * Initialize some variables specific to our context.
859 con->internal_pgm = 0;
860 con->download_fp = NULL;
861 con->upload_fp = NULL;
862 con->cached_msglist = NULL;
863 con->cached_num_msgs = 0;
864 con->FirstExpressMessage = NULL;
866 time(&con->lastidle);
867 strcpy(con->lastcmdname, " ");
868 strcpy(con->cs_clientname, "(unknown)");
869 strcpy(con->curr_user, NLI);
870 *con->net_node = '\0';
871 *con->fake_username = '\0';
872 *con->fake_hostname = '\0';
873 *con->fake_roomname = '\0';
874 *con->cs_clientinfo = '\0';
875 safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
876 safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
877 con->cs_UDSclientUID = -1;
878 con->cs_host[sizeof con->cs_host - 1] = 0;
879 if (!CC->is_local_socket) {
880 locate_host(con->cs_host, sizeof con->cs_host,
881 con->cs_addr, sizeof con->cs_addr,
888 #ifdef HAVE_STRUCT_UCRED
890 /* as http://www.wsinnovations.com/softeng/articles/uds.html told us... */
891 struct ucred credentials;
892 socklen_t ucred_length = sizeof(struct ucred);
894 /*fill in the user data structure */
895 if(getsockopt(con->client_socket, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) {
896 syslog(LOG_NOTICE, "could obtain credentials from unix domain socket");
900 /* the process ID of the process on the other side of the socket */
901 /* credentials.pid; */
903 /* the effective UID of the process on the other side of the socket */
904 con->cs_UDSclientUID = credentials.uid;
906 /* the effective primary GID of the process on the other side of the socket */
907 /* credentials.gid; */
909 /* To get supplemental groups, we will have to look them up in our account
910 database, after a reverse lookup on the UID to get the account name.
911 We can take this opportunity to check to see if this is a legit account.
913 snprintf(con->cs_clientinfo, sizeof(con->cs_clientinfo),
914 "PID: "F_PID_T"; UID: "F_UID_T"; GID: "F_XPID_T" ",
923 con->upload_type = UPL_FILE;
927 if (((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions)) || CtdlWantSingleUser()) {
931 if (!CC->is_local_socket) {
932 syslog(LOG_NOTICE, "Session (%s) started from %s (%s).\n", con->ServiceName, con->cs_host, con->cs_addr);
935 syslog(LOG_NOTICE, "Session (%s) started via local socket UID:%d.\n", con->ServiceName, con->cs_UDSclientUID);
938 /* Run any session startup routines registered by loadable modules */
939 PerformSessionHooks(EVT_START);
943 void citproto_begin_session() {
944 if (CC->nologin==1) {
945 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
946 ERROR + MAX_SESSIONS_EXCEEDED,
947 config.c_nodename, config.c_maxsessions
949 CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
952 cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
953 CC->can_receive_im = 1;
958 void citproto_begin_admin_session() {
959 CC->internal_pgm = 1;
960 cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, config.c_nodename);
964 void cmd_noop(char *argbuf)
966 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
970 void cmd_qnop(char *argbuf)
972 /* do nothing, this command returns no response */
976 void cmd_quit(char *argbuf)
978 cprintf("%d Goodbye.\n", CIT_OK);
979 CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
983 void cmd_lout(char *argbuf)
987 cprintf("%d logged out.\n", CIT_OK);
992 * This loop recognizes all server commands.
994 void do_command_loop(void) {
998 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
999 if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
1000 syslog(LOG_ERR, "Citadel client disconnected: ending session.\n");
1001 CC->kill_me = KILLME_CLIENT_DISCONNECTED;
1005 /* Log the server command, but don't show passwords... */
1006 if ( (strncasecmp(cmdbuf, "PASS", 4)) && (strncasecmp(cmdbuf, "SETP", 4)) ) {
1007 syslog(LOG_INFO, "[%d][%s(%ld)] %s",
1008 CC->cs_pid, CC->curr_user, CC->user.usernum, cmdbuf
1012 syslog(LOG_INFO, "[%d][%s(%ld)] <password command hidden from log>",
1013 CC->cs_pid, CC->curr_user, CC->user.usernum
1020 * Let other clients see the last command we executed, and
1021 * update the idle time, but not NOOP, QNOP, PEXP, GEXP, RWHO, or TIME.
1023 if ( (strncasecmp(cmdbuf, "NOOP", 4))
1024 && (strncasecmp(cmdbuf, "QNOP", 4))
1025 && (strncasecmp(cmdbuf, "PEXP", 4))
1026 && (strncasecmp(cmdbuf, "GEXP", 4))
1027 && (strncasecmp(cmdbuf, "RWHO", 4))
1028 && (strncasecmp(cmdbuf, "TIME", 4)) ) {
1029 strcpy(CC->lastcmdname, " ");
1030 safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
1031 time(&CC->lastidle);
1034 if ((strncasecmp(cmdbuf, "ENT0", 4))
1035 && (strncasecmp(cmdbuf, "MESG", 4))
1036 && (strncasecmp(cmdbuf, "MSGS", 4)))
1038 CC->cs_flags &= ~CS_POSTING;
1041 if (!DLoader_Exec_Cmd(cmdbuf)) {
1042 cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
1047 /* Run any after-each-command routines registered by modules */
1048 PerformSessionHooks(EVT_CMD);
1053 * This loop performs all asynchronous functions.
1055 void do_async_loop(void) {
1056 PerformSessionHooks(EVT_ASYNC);
1060 /*****************************************************************************/
1061 /* MODULE INITIALIZATION STUFF */
1062 /*****************************************************************************/
1064 CTDL_MODULE_INIT(citserver)
1067 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
1068 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
1069 CtdlRegisterProtoHook(cmd_quit, "QUIT", "log out and disconnect from server");
1070 CtdlRegisterProtoHook(cmd_lout, "LOUT", "log out but do not disconnect from server");
1071 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
1072 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
1073 CtdlRegisterProtoHook(cmd_mesg, "MESG", "fetch system banners");
1074 CtdlRegisterProtoHook(cmd_emsg, "EMSG", "submit system banners");
1075 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
1076 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
1077 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
1078 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
1079 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
1080 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
1081 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
1082 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
1084 /* return our id for the Log */