* Renamed "struct user" to "struct ctdluser"
[citadel.git] / citadel / citserver.c
index 5aea06c2baef5bc0f72f6747ab1c4e9ecc7b39a2..8ea2441fafb9b1a1f5833518937dcfa3485226f8 100644 (file)
 #include <arpa/inet.h>
 #include "citadel.h"
 #include "server.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "config.h"
 #include "database.h"
 #include "housekeeping.h"
 #include "user_ops.h"
-#include "logging.h"
 #include "msgbase.h"
 #include "support.h"
 #include "locate_host.h"
@@ -65,14 +64,18 @@ struct CitContext *ContextList = NULL;
 char *unique_session_numbers;
 int ScheduledShutdown = 0;
 int do_defrag = 0;
+time_t server_startup_time;
 
 /*
  * Various things that need to be initialized at startup
  */
 void master_startup(void) {
        struct timeval tv;
+       struct ctdlroom qrbuf;
        
        lprintf(9, "master_startup() started\n");
+       time(&server_startup_time);
+
        lprintf(7, "Opening databases\n");
        open_databases();
 
@@ -88,6 +91,13 @@ void master_startup(void) {
        create_room(SYSCONFIGROOM,      3, "", 0, 1, 0);
        create_room(config.c_twitroom,  0, "", 0, 1, 0);
 
+       /* The "Local System Configuration" room doesn't need to be visible */
+        if (lgetroom(&qrbuf, SYSCONFIGROOM) == 0) {
+                qrbuf.QRflags2 |= QR2_SYSTEM;
+                lputroom(&qrbuf);
+        }
+
+
        lprintf(7, "Seeding the pseudo-random number generator...\n");
        gettimeofday(&tv, NULL);
        srand(tv.tv_usec);
@@ -201,13 +211,10 @@ void RemoveContext (struct CitContext *con)
        lprintf(7, "Calling logout(%d)\n", con->cs_pid);
        logout(con);
 
-       rec_log(CL_TERMINATE, con->curr_user);
        unlink(con->temp);
        lprintf(3, "[%3d] Session ended.\n", con->cs_pid);
-       
-
        syslog(LOG_NOTICE,"session %d: ended", con->cs_pid);
-       
+
        /* Deallocate any user-data attached to this session */
        deallocate_user_data(con);
 
@@ -397,25 +404,28 @@ static int hostnames_match(const char *realname, const char *testname) {
 }
 
 /*
- * check a hostname against the public_clients file
+ * Check a hostname against the public_clients file.  This determines
+ * whether the client is allowed to change the hostname for this session
+ * (for example, to show the location of the user rather than the location
+ * of the client).
  */
 int is_public_client(char *where)
 {
        char buf[SIZ];
        FILE *fp;
 
-       lprintf(9, "Checking whether %s is a public client\n", where);
-
+       lprintf(9, "Checking whether %s is a local client\n", where);
        if (hostnames_match(where, "localhost")) return(1);
        if (hostnames_match(where, config.c_fqdn)) return(1);
 
-       fp = fopen("public_clients","r");
+       lprintf(9, "Checking whether %s is a public client\n", where);
+       fp = fopen("public_clients", "r");
        if (fp == NULL) return(0);
 
        while (fgets(buf, sizeof buf, fp)!=NULL) {
                while (isspace((buf[strlen(buf)-1]))) 
                        buf[strlen(buf)-1] = 0;
-               if (hostnames_match(where,buf)) {
+               if (hostnames_match(where, buf)) {
                        fclose(fp);
                        return(1);
                }
@@ -502,20 +512,27 @@ void cmd_mesg(char *mname)
        FILE *mfp;
        char targ[SIZ];
        char buf[SIZ];
+       char buf2[SIZ];
        char *dirs[2];
 
        extract(buf,mname,0);
 
-
        dirs[0]=mallok(64);
        dirs[1]=mallok(64);
        strcpy(dirs[0],"messages");
        strcpy(dirs[1],"help");
-       mesg_locate(targ,sizeof targ,buf,2,(const char **)dirs);
+       snprintf(buf2, sizeof buf2, "%s.%d.%d", buf, CC->cs_clientdev, CC->cs_clienttyp);
+       mesg_locate(targ,sizeof targ,buf2,2,(const char **)dirs);
+       if (strlen(targ) == 0) {
+               snprintf(buf2, sizeof buf2, "%s.%d", buf, CC->cs_clientdev);
+               mesg_locate(targ,sizeof targ,buf2,2,(const char **)dirs);
+               if (strlen(targ) == 0) {
+                       mesg_locate(targ,sizeof targ,buf,2,(const char **)dirs);
+               }       
+       }
        phree(dirs[0]);
        phree(dirs[1]);
 
-
        if (strlen(targ)==0) {
                cprintf("%d '%s' not found.\n",ERROR,mname);
                return;
@@ -593,12 +610,12 @@ void GenerateRoomDisplay(char *real_room,
                        struct CitContext *viewed,
                        struct CitContext *viewer) {
 
-       strcpy(real_room, viewed->quickroom.QRname);
-       if (viewed->quickroom.QRflags & QR_MAILBOX) {
+       strcpy(real_room, viewed->room.QRname);
+       if (viewed->room.QRflags & QR_MAILBOX) {
                strcpy(real_room, &real_room[11]);
        }
-       if (viewed->quickroom.QRflags & QR_PRIVATE) {
-               if ( (CtdlRoomAccess(&viewed->quickroom, &viewer->usersupp)
+       if (viewed->room.QRflags & QR_PRIVATE) {
+               if ( (CtdlRoomAccess(&viewed->room, &viewer->user)
                   & UA_KNOWN) == 0) {
                        strcpy(real_room, "<private room>");
                }
@@ -625,7 +642,7 @@ int CtdlAccessCheck(int required_level) {
                return(-1);
        }
 
-       if (CC->usersupp.axlevel >= 6) return(0);
+       if (CC->user.axlevel >= 6) return(0);
        if (required_level >= ac_aide) {
                cprintf("%d This command requires Aide access.\n",
                        ERROR+HIGHER_ACCESS_REQUIRED);
@@ -672,8 +689,8 @@ void cmd_term(char *cmdbuf)
        for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
                if (session_num == ccptr->cs_pid) {
                        found_it = 1;
-                       if ((ccptr->usersupp.usernum == CC->usersupp.usernum)
-                          || (CC->usersupp.axlevel >= 6)) {
+                       if ((ccptr->user.usernum == CC->user.usernum)
+                          || (CC->user.axlevel >= 6)) {
                                allowed = 1;
                                ccptr->kill_me = 1;
                        }
@@ -807,7 +824,7 @@ void generate_nonce(struct CitContext *con) {
  */
 void begin_session(struct CitContext *con)
 {
-       int len;
+       int len;        /* should be socklen_t but doesn't work on Macintosh */
        struct sockaddr_in sin;
 
        /* 
@@ -851,11 +868,10 @@ void begin_session(struct CitContext *con)
                con->nologin = 1;
 
        lprintf(3, "Session started.\n");
+       syslog(LOG_NOTICE,"session %d: ended", con->cs_pid);
 
        /* Run any session startup routines registered by loadable modules */
        PerformSessionHooks(EVT_START);
-
-       rec_log(CL_CONNECT, "");
 }
 
 
@@ -973,6 +989,10 @@ void do_command_loop(void) {
                cmd_lzrm(&cmdbuf[5]);
        }
 
+       else if (!strncasecmp(cmdbuf,"LPRM",4)) {
+               cmd_lprm(&cmdbuf[5]);
+       }
+
        else if (!strncasecmp(cmdbuf,"GETU",4)) {
                cmd_getu();
        }
@@ -1013,6 +1033,10 @@ void do_command_loop(void) {
                cmd_msg4(&cmdbuf[5]);
        }
 
+       else if (!strncasecmp(cmdbuf,"MSGP",4)) {
+               cmd_msgp(&cmdbuf[5]);
+       }
+
        else if (!strncasecmp(cmdbuf,"OPNA",4)) {
                cmd_opna(&cmdbuf[5]);
        }
@@ -1241,6 +1265,10 @@ void do_command_loop(void) {
                cmd_view(&cmdbuf[5]);
        }
 
+       else if (!strncasecmp(cmdbuf, "ISME", 4)) {
+               cmd_isme(&cmdbuf[5]);
+       }
+
 #ifdef DEBUG_MEMORY_LEAKS
        else if (!strncasecmp(cmdbuf, "LEAK", 4)) {
                dump_tracked();