Patches from Matt with slight mod from me to do without strlen. Also modified lprintf...
authorDave West <davew@uncensored.citadel.org>
Thu, 23 Aug 2007 19:43:29 +0000 (19:43 +0000)
committerDave West <davew@uncensored.citadel.org>
Thu, 23 Aug 2007 19:43:29 +0000 (19:43 +0000)
15 files changed:
citadel/citadel.c
citadel/citadel_ipc.c
citadel/citserver.c
citadel/client_chat.c
citadel/messages.c
citadel/modules/network/serv_network.c
citadel/room_ops.c
citadel/routines.c
citadel/routines2.c
citadel/screen.c
citadel/server.h
citadel/server_main.c
citadel/setup.c
citadel/sysdep.c
citadel/sysdep_decls.h

index 920f06cc402b1ce1537991109cdfb85f2cf71d39..e9c979adbc91489e818998f93994dd4db53acbfc 100644 (file)
@@ -517,6 +517,8 @@ void gotonext(CtdlIPC *ipc)
  */
                mptr = (struct march *) malloc(sizeof(struct march));
                mptr->next = NULL;
+               mptr->march_order = 0;
+               mptr->march_floor = 0;
                strcpy(mptr->march_name, "_BASEROOM_");
                if (march == NULL) {
                        march = mptr;
@@ -747,8 +749,18 @@ void  gotoroomstep(CtdlIPC *ipc, int direction, int mode)
        struct ctdlroomlisting *rs;
        int list_it;
        char rmname[ROOMNAMELEN];
-       int rmslot;
+       int rmslot = 0;
        int rmtotal;
+       struct ctdlroom *attr = NULL;
+
+       /* Fetch the existing room config */
+       r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
+       if (r / 100 != 2) {
+               scr_printf("%s\n", buf);
+               return;
+       }
+       strcpy (room_name , attr->QRname); 
+       free(attr);
 
        /* Ask the server for a room list */
        r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
index df52ea719473c0e96f6a81f997b8086a78a1646e..54d076e84a852e0a91c4254044fea32c08d4070d 100644 (file)
@@ -121,7 +121,7 @@ int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret)
 int CtdlIPCQuit(CtdlIPC *ipc)
 {
        register int ret = 221;         /* Default to successful quit */
-       char aaa[128];
+       char aaa[SIZ]; 
 
        CtdlIPC_lock(ipc);
        if (ipc->sock > -1) {
@@ -149,7 +149,7 @@ int CtdlIPCQuit(CtdlIPC *ipc)
 int CtdlIPCLogout(CtdlIPC *ipc)
 {
        register int ret;
-       char aaa[128];
+       char aaa[SIZ];
 
        CtdlIPC_lock(ipc);
        CtdlIPC_putline(ipc, "LOUT");
@@ -2335,6 +2335,7 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
        char aaa[SIZ];
        char buf[4096];
        FILE *fd;
+       int ferr;
 
        if (!cret) return -1;
        if (!path) return -1;
@@ -2379,7 +2380,9 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
        }
        if (progress_gauge_callback)
                progress_gauge_callback(ipc, 1, 1);
-       return (!ferror(fd) ? ret : -2);
+       ferr = ferror(fd);
+       fclose(fd);
+       return (!ferr ? ret : -2);
 }
 
 
@@ -2870,8 +2873,8 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
                        serv_read(ipc, &buf[i], 1);
 
        /* Strip the trailing newline (and carriage return, if present) */
-       if (buf[i] == 10) buf[i--] = 0;
-       if (buf[i] == 13) buf[i--] = 0;
+       if (i>=0 && buf[i] == 10) buf[i--] = 0;
+       if (i>=0 && buf[i] == 13) buf[i--] = 0;
 }
 
 void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf)
index 87f4f6f827d4c65be909a214d6e092a56f77152d..43c0567bf94e1341275adc37dd43e355acf6e159 100644 (file)
@@ -175,9 +175,6 @@ void master_cleanup(int exitcode) {
        lprintf(CTDL_INFO, "Closing databases\n");
        close_databases();
 
-       /* flush the networker stuff */
-/*     destroy_network_queue_room();*/
-
        /* Do system-dependent stuff */
        sysdep_master_cleanup();
        
@@ -369,8 +366,9 @@ int is_public_client(void)
                                }
                                else ptr++;
                        }
-                       while (isspace((buf[strlen(buf)-1]))) {
-                               buf[strlen(buf)-1] = 0;
+                       ptr--;
+                       while (ptr>buf && isspace(*ptr)) {
+                               *(ptr--) = 0;
                        }
                        if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
                                if ((strlen(public_clients) +
index 535055fc9d40f7e8add4c2d70d57e1fcf3da4711..a1ad06ce101ea34b9094d062055431bb221adf98 100644 (file)
@@ -84,6 +84,7 @@ void chatmode(CtdlIPC *ipc)
 
        strcpy(buf, "");
        strcpy(wbuf, "");
+       strcpy(last_user, ""); 
        color(BRIGHT_YELLOW);
        sln_printf_if("\n");
        sln_printf("> ");
index 79e03b1b4d32e931a62b89e52e988ee24fe0f787..7de1c23299f45b5a5bb8fcdb06ba842c08b35b32 100644 (file)
@@ -411,9 +411,11 @@ int read_message(CtdlIPC *ipc,
        if (r / 100 != 1) {
                err_printf("*** msg #%ld: %d %s\n", num, r, buf);
                ++lines_printed;
-               lines_printed =
-                   checkpagin(lines_printed, pagin, screenheight);
+               lines_printed = checkpagin(lines_printed, pagin, screenheight);
                stty_ctdl(0);
+               free(message->text);
+               free_parts(message->attachments);
+               free(message);
                return (0);
        }
 
@@ -461,6 +463,9 @@ int read_message(CtdlIPC *ipc,
                }
                pprintf("\n");
                stty_ctdl(0);
+               free(message->text);
+               free_parts(message->attachments);
+               free(message);
                return (0);
        }
 
@@ -669,7 +674,7 @@ int read_message(CtdlIPC *ipc,
 
                        if (sigcaught == 0) {
                                linelen = strlen(lineptr);
-                               if (lineptr[linelen-1] == '\r') {
+                               if (linelen && (lineptr[linelen-1] == '\r')) {
                                        lineptr[--linelen] = 0;
                                }
                                if (dest) {
@@ -697,6 +702,7 @@ int read_message(CtdlIPC *ipc,
                        scr_printf("\n");
                        ++lines_printed;
                        lines_printed = checkpagin(lines_printed, pagin, screenheight);
+                       fr = sigcaught;         
                }
        }
 
@@ -1630,10 +1636,10 @@ RMSGREAD:       scr_flush();
 
                        r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf);
                }
-               if (e == 3)
+               if (e == SIGQUIT)
                        return;
-               if (((userflags & US_NOPROMPT) || (e == 2))
-                   && (((room_flags & QR_MAILBOX) == 0)
+               if (((userflags & US_NOPROMPT) || (e == SIGINT))
+                       && (((room_flags & QR_MAILBOX) == 0)
                        || (rc_force_mail_prompts == 0))) {
                        e = 'n';
                } else {
index 71dc40a26bf215b0816e5225558ebef3ba72bb3e..29ad8379bdf78ef1045f23b98f7e08bebb78e189 100644 (file)
@@ -1435,6 +1435,7 @@ void network_process_buffer(char *buffer, long size) {
         * connected that it's inevitable.)
         */
        if (network_usetable(msg) != 0) {
+               CtdlFreeMessage(msg);
                return;
        }
 
@@ -1706,9 +1707,9 @@ void receive_spool(int sock, char *remote_nodename) {
                return;
        }
        if (download_len > 0)
-               lprintf(CTDL_NOTICE, "Received %ld octets from <%s>",
+               lprintf(CTDL_NOTICE, "Received %ld octets from <%s>\n",
                                download_len, remote_nodename);
-       lprintf(CTDL_DEBUG, "%s", buf);
+       lprintf(CTDL_DEBUG, "%s\n", buf);
        /* TODO: make move inline. forking is verry expensive. */
        snprintf(buf, 
                         sizeof buf, 
index 3cfd2af32b32ef44a7a6a480afc1c20cb559574f..caed7a3054684917e6f1be2f1af594446a542ee5 100644 (file)
@@ -520,7 +520,7 @@ int sort_msglist(long listptrs[], int oldcount)
 
        /* and yank any nulls */
        while ((numitems > 0) && (listptrs[0] == 0L)) {
-               memcpy(&listptrs[0], &listptrs[1],
+               memmove(&listptrs[0], &listptrs[1],
                       (sizeof(long) * (numitems - 1)));
                --numitems;
        }
@@ -1882,7 +1882,7 @@ void cmd_cre8(char *args)
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       if (CC->user.axlevel < config.c_createax || CC->internal_pgm) {
+       if (CC->user.axlevel < config.c_createax && !CC->internal_pgm) {
                cprintf("%d You need higher access to create rooms.\n",
                        ERROR + HIGHER_ACCESS_REQUIRED);
                return;
index 41d971e8ae1aed7cc67678abe2928bc42692e225..30db9a5ce161671d2e6bc7cb987d78d1c8d531ce 100644 (file)
@@ -59,7 +59,7 @@ struct utmp *getutline(struct utmp *ut);
 #define IFNAIDE if (axlevel<6)
 
 extern unsigned userflags;
-extern char *axdefs[7];
+//extern char *axdefs[8];
 extern char sigcaught;
 extern char rc_floor_mode;
 extern int rc_ansi_color;
@@ -159,7 +159,10 @@ void edituser(CtdlIPC *ipc, int cmd)
 
        if (cmd == 96) {
                scr_printf("Do you want to delete this user? ");
-               if (!yesno()) return;
+               if (!yesno()) {
+                       free(user);
+                       return;
+               }
                user->axlevel = 0;
        }
        
index 3687f06eafbd9419b862e0cd484eea56d11a9d23..93c1814e51d7003a445a72f3b41e577704c77379 100644 (file)
@@ -51,7 +51,7 @@
 
 extern char temp[];
 extern char tempdir[];
-extern char *axdefs[7];
+extern char *axdefs[8];
 extern long highest_msg_read;
 extern long maxmsgnum;
 extern unsigned room_flags;
@@ -451,6 +451,11 @@ int val_user(CtdlIPC *ipc, char *user, int do_validate)
                        if (a == 11)
                                scr_printf("%s\n", buf);
                } while (!IsEmptyStr(resp));
+
+/* TODODRW: discrepancy here. Parts of the code refer to axdefs[7] as the highest
+ * but most of it limits it to axdefs[6].
+ * Webcit limits to 6 as does the code here but there are 7 in axdefs.h
+ */
                scr_printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
        } else {
                scr_printf("%s\n%s\n", user, &cmd[4]);
index 398f945ce8ce570cb9327f9420cf9c09a7828e5f..a1d8abd7546f0c477d62725f061458e36fc40684 100644 (file)
@@ -86,7 +86,7 @@ void status_line(const char *humannode, const char *site_location,
 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
 void wait_indicator(int state) {
 
-       if (!isendwin() && statuswindow) {
+       if (statuswindow && !isendwin()) {
 
                mvwinch(statuswindow, 0, screenwidth - 2);
                switch (state) {
index 927abb6e867ace165e62846b6ab8f6c253cd146d..3d1c9c487a721d151a8dd3769c528f2eb4dc36c4 100644 (file)
@@ -237,6 +237,7 @@ enum {
        S_RPLIST,
        S_SIEVELIST,
        S_CHKPWD,
+       S_LOG,
        MAX_SEMAPHORES
 };
 
index 318f72e2b5f149041b5bb42ae125f23d8a98f5b0..4c69e608342f9c9c3af4aa9cdc653f77f279b3fa 100644 (file)
@@ -87,6 +87,11 @@ int main(int argc, char **argv)
 #ifdef HAVE_RUN_DIR
        struct stat filestats;
 #endif
+
+       /* initialise semaphores here. Patch by Matt and davew
+        * its called here as they are needed by lprintf for thread safety
+        */
+       InitialiseSemaphores();
        
        /* initialize the master context */
        InitializeMasterCC();
index 1e741f002e333108de525312c87fdb07d85ecd72..bf1374d5a018e3be3ee3d41e85150c1fea856311 100644 (file)
@@ -752,8 +752,8 @@ void edit_value(int curr)
                                        config.c_ctdluid = atoi(ctdluidname);
                                }
                        }
-               }
 #endif
+               }
                break;
 
        case 3:
index cd7f12107a5a15da0f3841d489cf7fda72b93cfe..94029bc68fead4090dc82b1199eaea7990d52945 100644 (file)
@@ -103,6 +103,7 @@ void DestroyWorkerList(void);
  * lprintf()  ...   Write logging information
  */
 void lprintf(enum LogLevel loglevel, const char *format, ...) {   
+       char *buf;
        va_list arg_ptr;
 
        if (enable_syslog) {
@@ -112,7 +113,9 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
        }
 
        /* stderr output code */
-       if (enable_syslog || running_as_daemon) return;
+       if (enable_syslog || running_as_daemon) {
+               return;
+       }
 
        /* if we run in forground and syslog is disabled, log to terminal */
        if (loglevel <= verbosity) { 
@@ -124,24 +127,30 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
                /* Promote to time_t; types differ on some OSes (like darwin) */
                unixtime = tv.tv_sec;
                localtime_r(&unixtime, &tim);
+//     begin_critical_section(S_LOG);
+
+               buf = malloc(SIZ+strlen(format));
+
                if (CC->cs_pid != 0) {
-                       fprintf(stderr,
+                       sprintf(buf,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] ",
                                tim.tm_year + 1900, tim.tm_mon + 1,
                                tim.tm_mday, tim.tm_hour, tim.tm_min,
                                tim.tm_sec, (long)tv.tv_usec,
                                CC->cs_pid);
                } else {
-                       fprintf(stderr,
+                       sprintf(buf,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld ",
                                tim.tm_year + 1900, tim.tm_mon + 1,
                                tim.tm_mday, tim.tm_hour, tim.tm_min,
                                tim.tm_sec, (long)tv.tv_usec);
                }
-               va_start(arg_ptr, format);   
-                       vfprintf(stderr, format, arg_ptr);   
+               strcat(buf, format);
+               va_start(arg_ptr, buf);   
+               vfprintf(stderr, buf, arg_ptr);   
                va_end(arg_ptr);   
                fflush(stderr);
+//     end_critical_section(S_LOG);
        }
 }   
 
@@ -162,11 +171,25 @@ static RETSIGTYPE signal_cleanup(int signum) {
        master_cleanup(signum);
 }
 
+
+
+
+void InitialiseSemaphores(void)
+{
+       int i;
+
+       /* Set up a bunch of semaphores to be used for critical sections */
+       for (i=0; i<MAX_SEMAPHORES; ++i) {
+               pthread_mutex_init(&Critters[i], NULL);
+       }
+}
+
+
+
 /*
  * Some initialization stuff...
  */
 void init_sysdep(void) {
-       int i;
        sigset_t set;
 
        /* Avoid vulnerabilities related to FD_SETSIZE if we can. */
@@ -185,11 +208,6 @@ void init_sysdep(void) {
        init_ssl();
 #endif
 
-       /* Set up a bunch of semaphores to be used for critical sections */
-       for (i=0; i<MAX_SEMAPHORES; ++i) {
-               pthread_mutex_init(&Critters[i], NULL);
-       }
-
        /*
         * Set up a place to put thread-specific data.
         * We only need a single pointer per thread - it points to the
index 54d889384be131e951fee142a9c94ab0c27a1bf8..99a29e68e52d0f5910807c0c02ba2d9483d10ef6 100644 (file)
@@ -74,6 +74,7 @@ void become_session(struct CitContext *which_con);
 void InitializeMasterCC(void);
 void init_master_fdset(void);
 void create_worker(void);
+void InitialiseSemaphores(void);
 
 extern int num_sessions;
 extern volatile int time_to_die;