* Removed the completely redunant function get_mm()
[citadel.git] / citadel / control.c
index 7e01f13b1b5b983ce4342a1389fc6b93eee22286..5ef54287aee0154d3710c1543d70c5c940f606f3 100644 (file)
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <sys/types.h>
+#include <sys/file.h>
 #include "citadel.h"
 #include "server.h"
 #include "control.h"
@@ -48,11 +49,34 @@ struct CitControl CitControl;
 extern struct config config;
 FILE *control_fp = NULL;
 
+
+
+/*
+ * lock_control  -  acquire a lock on the control record file.
+ *                  This keeps multiple citservers from running concurrently.
+ */
+void lock_control(void)
+{
+       if (flock(fileno(control_fp), (LOCK_EX | LOCK_NB))) {
+               lprintf(CTDL_EMERG, "citserver: unable to lock %s.\n", file_citadel_control);
+               lprintf(CTDL_EMERG, "Is another citserver already running?\n");
+               exit(CTDLEXIT_CONTROL);
+       }
+}
+
+
 /*
  * get_control  -  read the control record into memory.
  */
 void get_control(void)
 {
+       static int already_have_control = 0;
+
+       /*
+        * If we already have the control record in memory, there's no point
+        * in reading it from disk again.
+        */
+       if (already_have_control) return;
 
        /* Zero it out.  If the control record on disk is missing or short,
         * the system functions with all control record fields initialized
@@ -62,12 +86,14 @@ void get_control(void)
        if (control_fp == NULL) {
                control_fp = fopen(file_citadel_control, "rb+");
                if (control_fp != NULL) {
+                       lock_control();
                        fchown(fileno(control_fp), config.c_ctdluid, -1);
                }
        }
        if (control_fp == NULL) {
                control_fp = fopen(file_citadel_control, "wb+");
                if (control_fp != NULL) {
+                       lock_control();
                        fchown(fileno(control_fp), config.c_ctdluid, -1);
                        memset(&CitControl, 0, sizeof(struct CitControl));
                        fwrite(&CitControl, sizeof(struct CitControl),
@@ -84,6 +110,7 @@ void get_control(void)
 
        rewind(control_fp);
        fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
+       already_have_control = 1;
 }
 
 /*
@@ -100,6 +127,15 @@ void put_control(void)
        }
 }
 
+/**
+ * release_control - close our fd on exit
+ */
+void release_control(void)
+{
+       if (control_fp != NULL)
+               fclose(control_fp);
+       control_fp = NULL;
+}
 
 /*
  * get_new_message_number()  -  Obtain a new, unique ID to be used for a message.
@@ -224,6 +260,12 @@ void cmd_conf(char *argbuf)
                cprintf("%s\n", config.c_default_cal_zone);
                cprintf("%d\n", config.c_pftcpdict_port);
                cprintf("%d\n", config.c_managesieve_port);
+               cprintf("%d\n", config.c_auth_mode);
+               cprintf("%s\n", config.c_funambol_host);
+               cprintf("%d\n", config.c_funambol_port);
+               cprintf("%s\n", config.c_funambol_source);
+               cprintf("%s\n", config.c_funambol_auth);
+               cprintf("%d\n", config.c_rbl_at_greeting);
                cprintf("000\n");
        }
 
@@ -429,6 +471,28 @@ void cmd_conf(char *argbuf)
                        case 51:
                                config.c_managesieve_port = atoi(buf);
                                break;
+                       case 52:
+                               config.c_auth_mode = atoi(buf);
+                       case 53:
+                               safestrncpy(config.c_funambol_host, buf,
+                                       sizeof config.c_funambol_host);
+                               break;
+                       case 54:
+                               config.c_funambol_port = atoi(buf);
+                               break;
+                       case 55:
+                               safestrncpy(config.c_funambol_source,
+                                       buf, 
+                                       sizeof config.c_funambol_source);
+                               break;
+                       case 56:
+                               safestrncpy(config.c_funambol_auth,
+                                       buf,
+                                       sizeof config.c_funambol_auth);
+                               break;
+                       case 57:
+                               config.c_rbl_at_greeting = atoi(buf);
+                               break;
                        }
                        ++a;
                }
@@ -436,7 +500,7 @@ void cmd_conf(char *argbuf)
                snprintf(buf, sizeof buf,
                         "The global system configuration has been edited by %s.\n",
                         CC->curr_user);
-               aide_message(buf);
+               aide_message(buf,"Citadel Configuration Manager Message");
 
                if (strlen(config.c_logpages) > 0)
                        create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);