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 (config.c_disable_newu == 0))
290 cprintf("%d\n", config.c_disable_newu);
293 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
296 cprintf("%s\n", config.c_default_cal_zone);
298 /* thread load averages -- temporarily disabled during refactoring of this code */
299 cprintf("0\n"); /* load average */
300 cprintf("0\n"); /* worker average */
301 cprintf("0\n"); /* thread count */
303 cprintf("1\n"); /* yes, Sieve mail filtering is supported */
304 cprintf("%d\n", config.c_enable_fulltext);
305 cprintf("%s\n", svn_revision());
307 if (config.c_auth_mode == AUTHMODE_NATIVE) {
308 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
311 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
314 cprintf("%d\n", config.c_guest_logins);
321 * returns an asterisk if there are any instant messages waiting,
324 char CtdlCheckExpress(void) {
325 if (CC->FirstExpressMessage == NULL) {
333 void cmd_time(char *argbuf)
339 localtime_r(&tv, &tmp);
341 /* timezone and daylight global variables are not portable. */
342 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
343 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
345 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
351 * Check originating host against the public_clients file. This determines
352 * whether the client is allowed to change the hostname for this session
353 * (for example, to show the location of the user rather than the location
356 int is_public_client(void)
362 char *public_clientspos;
363 char *public_clientsend;
366 static time_t pc_timestamp = 0;
367 static char public_clients[SIZ];
368 static char public_clients_file[SIZ];
370 #define LOCALHOSTSTR "127.0.0.1"
372 snprintf(public_clients_file, sizeof public_clients_file, "%s/public_clients", ctdl_etc_dir);
375 * Check the time stamp on the public_clients file. If it's been
376 * updated since the last time we were here (or if this is the first
377 * time we've been through the loop), read its contents and learn
378 * the IP addresses of the listed hosts.
380 if (stat(public_clients_file, &statbuf) != 0) {
381 /* No public_clients file exists, so bail out */
382 syslog(LOG_WARNING, "Warning: '%s' does not exist\n",
383 public_clients_file);
387 if (statbuf.st_mtime > pc_timestamp) {
388 begin_critical_section(S_PUBLIC_CLIENTS);
389 syslog(LOG_INFO, "Loading %s\n", public_clients_file);
391 public_clientspos = &public_clients[0];
392 public_clientsend = public_clientspos + SIZ;
393 safestrncpy(public_clientspos, LOCALHOSTSTR, sizeof public_clients);
394 public_clientspos += sizeof(LOCALHOSTSTR) - 1;
396 if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
397 *(public_clientspos++) = '|';
399 while (!IsEmptyStr (paddr) &&
400 (public_clientspos < public_clientsend))
401 *(public_clientspos++) = *(paddr++);
404 fp = fopen(public_clients_file, "r");
406 while ((fgets(buf, sizeof buf, fp)!=NULL) &&
407 (public_clientspos < public_clientsend)){
410 while (!IsEmptyStr(ptr)) {
418 while (ptr>buf && isspace(*ptr)) {
421 if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
422 *(public_clientspos++) = '|';
424 while (!IsEmptyStr(paddr) &&
425 (public_clientspos < public_clientsend)){
426 *(public_clientspos++) = *(paddr++);
431 pc_timestamp = time(NULL);
432 end_critical_section(S_PUBLIC_CLIENTS);
435 syslog(LOG_DEBUG, "Checking whether %s is a local or public client\n",
437 for (i=0; i<num_parms(public_clients); ++i) {
438 extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
439 if (!strcasecmp(CC->cs_addr, addrbuf)) {
440 syslog(LOG_DEBUG, "... yes its local.\n");
445 /* No hits. This is not a public client. */
446 syslog(LOG_DEBUG, "... no it isn't.\n");
452 * the client is identifying itself to the server
454 void cmd_iden(char *argbuf)
462 if (num_parms(argbuf)<4) {
463 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
467 dev_code = extract_int(argbuf,0);
468 cli_code = extract_int(argbuf,1);
469 rev_level = extract_int(argbuf,2);
470 extract_token(desc, argbuf, 3, '|', sizeof desc);
472 safestrncpy(from_host, config.c_fqdn, sizeof from_host);
473 from_host[sizeof from_host - 1] = 0;
474 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
476 CC->cs_clientdev = dev_code;
477 CC->cs_clienttyp = cli_code;
478 CC->cs_clientver = rev_level;
479 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
480 CC->cs_clientname[31] = 0;
482 /* For local sockets and public clients, trust the hostname supplied by the client */
483 if ( (CC->is_local_socket) || (is_public_client()) ) {
484 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
485 CC->cs_host[sizeof CC->cs_host - 1] = 0;
489 syslog(LOG_NOTICE, "Client %d/%d/%01d.%02d (%s) from %s\n",
497 cprintf("%d Ok\n",CIT_OK);
500 typedef const char *ccharp;
502 * display system messages or help
504 void cmd_mesg(char *mname)
514 extract_token(buf, mname, 0, '|', sizeof buf);
516 dirs[0] = strdup(ctdl_message_dir);
517 dirs[1] = strdup(ctdl_hlp_dir);
519 snprintf(buf2, sizeof buf2, "%s.%d.%d",
520 buf, CC->cs_clientdev, CC->cs_clienttyp);
522 /* If the client requested "?" then produce a listing */
523 if (!strcmp(buf, "?")) {
524 cprintf("%d %s\n", LISTING_FOLLOWS, buf);
525 dp = opendir(dirs[1]);
527 while (d = readdir(dp), d != NULL) {
528 if (d->d_name[0] != '.') {
529 cprintf(" %s\n", d->d_name);
540 /* Otherwise, look for the requested file by name. */
542 mesg_locate(targ, sizeof targ, buf2, 2, (const ccharp*)dirs);
543 if (IsEmptyStr(targ)) {
544 snprintf(buf2, sizeof buf2, "%s.%d",
545 buf, CC->cs_clientdev);
546 mesg_locate(targ, sizeof targ, buf2, 2,
547 (const ccharp*)dirs);
548 if (IsEmptyStr(targ)) {
549 mesg_locate(targ, sizeof targ, buf, 2,
550 (const ccharp*)dirs);
558 if (IsEmptyStr(targ)) {
559 cprintf("%d '%s' not found. (Searching in %s and %s)\n",
560 ERROR + FILE_NOT_FOUND,
568 mfp = fopen(targ, "r");
570 cprintf("%d Cannot open '%s': %s\n",
571 ERROR + INTERNAL_ERROR, targ, strerror(errno));
574 cprintf("%d %s\n", LISTING_FOLLOWS,buf);
576 while (fgets(buf, (sizeof buf - 1), mfp) != NULL) {
577 buf[strlen(buf)-1] = 0;
588 * enter system messages or help
590 void cmd_emsg(char *mname)
600 if (CtdlAccessCheck(ac_aide)) return;
602 extract_token(buf, mname, 0, '|', sizeof buf);
603 for (a=0; !IsEmptyStr(&buf[a]); ++a) { /* security measure */
604 if (buf[a] == '/') buf[a] = '.';
607 dirs[0] = strdup(ctdl_message_dir);
608 dirs[1] = strdup(ctdl_hlp_dir);
610 mesg_locate(targ, sizeof targ, buf, 2, (const ccharp*)dirs);
614 if (IsEmptyStr(targ)) {
615 snprintf(targ, sizeof targ,
620 mfp = fopen(targ,"w");
622 cprintf("%d Cannot open '%s': %s\n",
623 ERROR + INTERNAL_ERROR, targ, strerror(errno));
626 cprintf("%d %s\n", SEND_LISTING, targ);
628 while (client_getln(buf, sizeof buf) >=0 && strcmp(buf, "000")) {
629 fprintf(mfp, "%s\n", buf);
636 /* Don't show the names of private rooms unless the viewing
637 * user also knows the rooms.
639 void GenerateRoomDisplay(char *real_room,
641 CitContext *viewer) {
645 strcpy(real_room, viewed->room.QRname);
646 if (viewed->room.QRflags & QR_MAILBOX) {
647 strcpy(real_room, &real_room[11]);
649 if (viewed->room.QRflags & QR_PRIVATE) {
650 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
651 if ( (ra & UA_KNOWN) == 0) {
652 strcpy(real_room, " ");
656 if (viewed->cs_flags & CS_CHAT) {
657 while (strlen(real_room) < 14) {
658 strcat(real_room, " ");
660 strcpy(&real_room[14], "<chat>");
666 * Convenience function.
668 int CtdlAccessCheck(int required_level) {
670 if (CC->internal_pgm) return(0);
671 if (required_level >= ac_internal) {
672 cprintf("%d This is not a user-level command.\n",
673 ERROR + HIGHER_ACCESS_REQUIRED);
677 if ((required_level >= ac_logged_in_or_guest) && (CC->logged_in == 0) && (!config.c_guest_logins)) {
678 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
682 if ((required_level >= ac_logged_in) && (CC->logged_in == 0)) {
683 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
687 if (CC->user.axlevel >= AxAideU) return(0);
688 if (required_level >= ac_aide) {
689 cprintf("%d This command requires Aide access.\n",
690 ERROR + HIGHER_ACCESS_REQUIRED);
694 if (is_room_aide()) return(0);
695 if (required_level >= ac_room_aide) {
696 cprintf("%d This command requires Aide or Room Aide access.\n",
697 ERROR + HIGHER_ACCESS_REQUIRED);
701 /* shhh ... succeed quietly */
708 * Terminate another running session
710 void cmd_term(char *cmdbuf)
715 session_num = extract_int(cmdbuf, 0);
717 terminated = CtdlTerminateOtherSession(session_num);
719 if (terminated < 0) {
720 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
724 if (terminated & TERM_FOUND) {
725 if (terminated == TERM_KILLED) {
726 cprintf("%d Session terminated.\n", CIT_OK);
729 cprintf("%d You are not allowed to do that.\n",
730 ERROR + HIGHER_ACCESS_REQUIRED);
734 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
740 * get the paginator prompt
742 void cmd_more(char *argbuf) {
743 cprintf("%d %s\n", CIT_OK, config.c_moreprompt);
750 void cmd_echo(char *etext)
752 cprintf("%d %s\n", CIT_OK, etext);
758 * Shut down the server
760 void cmd_down(char *argbuf) {
761 char *Reply ="%d Shutting down server. Goodbye.\n";
763 if (CtdlAccessCheck(ac_aide)) return;
765 if (!IsEmptyStr(argbuf))
768 restart_server = extract_int(argbuf, 0);
770 if (restart_server > 0)
772 Reply = "%d citserver will now shut down and automatically restart.\n";
774 if ((restart_server > 0) && !running_as_daemon)
776 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
777 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
780 cprintf(Reply, state);
784 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
786 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
787 server_shutting_down = 1;
792 * Halt the server without exiting the server process.
794 void cmd_halt(char *argbuf) {
796 if (CtdlAccessCheck(ac_aide)) return;
798 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
799 server_shutting_down = 1;
800 shutdown_and_halt = 1;
805 * Schedule or cancel a server shutdown
807 void cmd_scdn(char *argbuf)
811 char *Reply = "%d %d\n";
813 if (CtdlAccessCheck(ac_aide)) return;
815 new_state = extract_int(argbuf, 0);
816 if ((new_state == 2) || (new_state == 3))
819 if (!running_as_daemon)
821 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
822 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
826 restart_server = extract_int(argbuf, 0);
829 if ((new_state == 0) || (new_state == 1)) {
830 ScheduledShutdown = new_state;
832 cprintf(Reply, state, ScheduledShutdown);
837 * Set or unset asynchronous protocol mode
839 void cmd_asyn(char *argbuf)
843 new_state = extract_int(argbuf, 0);
844 if ((new_state == 0) || (new_state == 1)) {
845 CC->is_async = new_state;
847 cprintf("%d %d\n", CIT_OK, CC->is_async);
853 * Back-end function for starting a session
855 void begin_session(CitContext *con)
858 * Initialize some variables specific to our context.
861 con->internal_pgm = 0;
862 con->download_fp = NULL;
863 con->upload_fp = NULL;
864 con->cached_msglist = NULL;
865 con->cached_num_msgs = 0;
866 con->FirstExpressMessage = NULL;
868 time(&con->lastidle);
869 strcpy(con->lastcmdname, " ");
870 strcpy(con->cs_clientname, "(unknown)");
871 strcpy(con->curr_user, NLI);
872 *con->net_node = '\0';
873 *con->fake_username = '\0';
874 *con->fake_hostname = '\0';
875 *con->fake_roomname = '\0';
876 *con->cs_clientinfo = '\0';
877 safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
878 safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
879 con->cs_UDSclientUID = -1;
880 con->cs_host[sizeof con->cs_host - 1] = 0;
881 if (!CC->is_local_socket) {
882 locate_host(con->cs_host, sizeof con->cs_host,
883 con->cs_addr, sizeof con->cs_addr,
890 #ifdef HAVE_STRUCT_UCRED
892 /* as http://www.wsinnovations.com/softeng/articles/uds.html told us... */
893 struct ucred credentials;
894 socklen_t ucred_length = sizeof(struct ucred);
896 /*fill in the user data structure */
897 if(getsockopt(con->client_socket, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) {
898 syslog(LOG_NOTICE, "could obtain credentials from unix domain socket");
902 /* the process ID of the process on the other side of the socket */
903 /* credentials.pid; */
905 /* the effective UID of the process on the other side of the socket */
906 con->cs_UDSclientUID = credentials.uid;
908 /* the effective primary GID of the process on the other side of the socket */
909 /* credentials.gid; */
911 /* To get supplemental groups, we will have to look them up in our account
912 database, after a reverse lookup on the UID to get the account name.
913 We can take this opportunity to check to see if this is a legit account.
915 snprintf(con->cs_clientinfo, sizeof(con->cs_clientinfo),
916 "PID: "F_PID_T"; UID: "F_UID_T"; GID: "F_XPID_T" ",
925 con->upload_type = UPL_FILE;
929 if (((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions)) || CtdlWantSingleUser()) {
933 if (!CC->is_local_socket) {
934 syslog(LOG_NOTICE, "Session (%s) started from %s (%s).\n", con->ServiceName, con->cs_host, con->cs_addr);
937 syslog(LOG_NOTICE, "Session (%s) started via local socket UID:%d.\n", con->ServiceName, con->cs_UDSclientUID);
940 /* Run any session startup routines registered by loadable modules */
941 PerformSessionHooks(EVT_START);
945 void citproto_begin_session() {
946 if (CC->nologin==1) {
947 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
948 ERROR + MAX_SESSIONS_EXCEEDED,
949 config.c_nodename, config.c_maxsessions
951 CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
954 cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
955 CC->can_receive_im = 1;
960 void citproto_begin_admin_session() {
961 CC->internal_pgm = 1;
962 cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, config.c_nodename);
966 void cmd_noop(char *argbuf)
968 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
972 void cmd_qnop(char *argbuf)
974 /* do nothing, this command returns no response */
978 void cmd_quit(char *argbuf)
980 cprintf("%d Goodbye.\n", CIT_OK);
981 CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
985 void cmd_lout(char *argbuf)
989 cprintf("%d logged out.\n", CIT_OK);
994 * This loop recognizes all server commands.
996 void do_command_loop(void) {
1000 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
1001 if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
1002 syslog(LOG_ERR, "Citadel client disconnected: ending session.\n");
1003 CC->kill_me = KILLME_CLIENT_DISCONNECTED;
1007 /* Log the server command, but don't show passwords... */
1008 if ( (strncasecmp(cmdbuf, "PASS", 4)) && (strncasecmp(cmdbuf, "SETP", 4)) ) {
1009 syslog(LOG_INFO, "[%d][%s(%ld)] %s",
1010 CC->cs_pid, CC->curr_user, CC->user.usernum, cmdbuf
1014 syslog(LOG_INFO, "[%d][%s(%ld)] <password command hidden from log>",
1015 CC->cs_pid, CC->curr_user, CC->user.usernum
1022 * Let other clients see the last command we executed, and
1023 * update the idle time, but not NOOP, QNOP, PEXP, GEXP, RWHO, or TIME.
1025 if ( (strncasecmp(cmdbuf, "NOOP", 4))
1026 && (strncasecmp(cmdbuf, "QNOP", 4))
1027 && (strncasecmp(cmdbuf, "PEXP", 4))
1028 && (strncasecmp(cmdbuf, "GEXP", 4))
1029 && (strncasecmp(cmdbuf, "RWHO", 4))
1030 && (strncasecmp(cmdbuf, "TIME", 4)) ) {
1031 strcpy(CC->lastcmdname, " ");
1032 safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
1033 time(&CC->lastidle);
1036 if ((strncasecmp(cmdbuf, "ENT0", 4))
1037 && (strncasecmp(cmdbuf, "MESG", 4))
1038 && (strncasecmp(cmdbuf, "MSGS", 4)))
1040 CC->cs_flags &= ~CS_POSTING;
1043 if (!DLoader_Exec_Cmd(cmdbuf)) {
1044 cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
1049 /* Run any after-each-command routines registered by modules */
1050 PerformSessionHooks(EVT_CMD);
1055 * This loop performs all asynchronous functions.
1057 void do_async_loop(void) {
1058 PerformSessionHooks(EVT_ASYNC);
1062 /*****************************************************************************/
1063 /* MODULE INITIALIZATION STUFF */
1064 /*****************************************************************************/
1066 CTDL_MODULE_INIT(citserver)
1069 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
1070 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
1071 CtdlRegisterProtoHook(cmd_quit, "QUIT", "log out and disconnect from server");
1072 CtdlRegisterProtoHook(cmd_lout, "LOUT", "log out but do not disconnect from server");
1073 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
1074 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
1075 CtdlRegisterProtoHook(cmd_mesg, "MESG", "fetch system banners");
1076 CtdlRegisterProtoHook(cmd_emsg, "EMSG", "submit system banners");
1077 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
1078 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
1079 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
1080 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
1081 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
1082 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
1083 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
1084 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
1086 /* return our id for the Log */