]> code.citadel.org Git - citadel.git/blobdiff - citadel/routines2.c
* Sysconfig commands for specifying where the LDAP server lives
[citadel.git] / citadel / routines2.c
index 9e5e420e60925fef161b71fbfa66adcd86c53c9c..640a16e68f53ffe49dbe5cd20bd974b676e232e8 100644 (file)
 #endif
 #include "screen.h"
 
+/* work around solaris include files */
+#ifdef reg
+#undef reg
+#endif
+
 extern char temp[];
 extern char tempdir[];
 extern char *axdefs[7];
@@ -189,13 +194,18 @@ void updatels(CtdlIPC *ipc)
        int r;                          /* IPC response code */
 
        if (rc_alt_semantics) {
-               if (maxmsgnum == highest_msg_read == 0) {
+               if (maxmsgnum == 0 && highest_msg_read == 0) {
                        return;
                }
                r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ?
                                 maxmsgnum : highest_msg_read, buf);
        } else {
-               r = CtdlIPCSetLastRead(ipc, 0, buf);
+               r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ?
+                                maxmsgnum : highest_msg_read, buf);
+/*             r = CtdlIPCSetLastRead(ipc, maxmsgnum, buf); */
+/* This is a quick-and-dirty fix to all msgs becoming new in Mail>.
+ * It will need to be rethought when messages.c is rewritten.
+ */
        }
        if (r / 100 != 2)
                scr_printf("%s\n", buf);
@@ -247,10 +257,13 @@ void cli_upload(CtdlIPC *ipc)
                /* basename of filename */
                strcpy(tbuf, flnm);
                if (haschar(tbuf, '/'))
-                       strcpy(tbuf, strrchr(tbuf, '/'));
+                       extract_token(tbuf, flnm,
+                               num_tokens(tbuf, '/') - 1,
+                               '/'
+                       );
                /* filename.1, filename.2, etc */
                if (a > 0) {
-                       sprintf(buf + strlen(buf), ".%d", a);
+                       sprintf(&tbuf[strlen(tbuf)], ".%d", a);
                }
                /* Try upload */
                r = CtdlIPCFileUpload(ipc, tbuf, desc, flnm, progress, buf);
@@ -259,7 +272,8 @@ void cli_upload(CtdlIPC *ipc)
                else
                        break;
                ++a;
-       };
+       }
+       if (a > 0) scr_printf("Saved as '%s'\n", tbuf);
 }
 
 
@@ -394,17 +408,19 @@ void upload(CtdlIPC *ipc, int c)
 }
 
 /* 
- * validate a user
+ * validate a user (returns 0 for successful validation, nonzero if quitting)
  */
-void val_user(CtdlIPC *ipc, char *user, int do_validate)
+int val_user(CtdlIPC *ipc, char *user, int do_validate)
 {
        int a;
        char cmd[SIZ];
        char buf[SIZ];
        char *resp = NULL;
        int ax = 0;
+       char answer[2];
        int r;                          /* IPC response code */
 
+       scr_printf("\n");
        r = CtdlIPCGetUserRegistration(ipc, user, &resp, cmd);
        if (r / 100 == 1) {
                a = 0;
@@ -443,12 +459,31 @@ void val_user(CtdlIPC *ipc, char *user, int do_validate)
 
        if (do_validate) {
                /* now set the access level */
-               ax = intprompt("Access level", ax, 0, 6);
-               r = CtdlIPCValidateUser(ipc, user, ax, cmd);
-               if (r / 100 != 2)
-                       scr_printf("%s\n", cmd);
+               while(1) {
+                       sprintf(answer, "%d", ax);
+                       strprompt("New access level (? for help, q to quit)",
+                               answer, 1);
+                       if ((answer[0] >= '0') && (answer[0] <= '6')) {
+                               ax = atoi(answer);
+                               r = CtdlIPCValidateUser(ipc, user, ax, cmd);
+                               if (r / 100 != 2)
+                               scr_printf("%s\n\n", cmd);
+                               return(0);
+                       }
+                       if (tolower(answer[0]) == 'q') {
+                               scr_printf("*** Aborted.\n\n");
+                               return(1);
+                       }
+                       if (answer[0] == '?') {
+                               scr_printf("Available access levels:\n");
+                               for (a=0; a<7; ++a) {
+                                       scr_printf("%d - %s\n",
+                                               a, axdefs[a]);
+                               }
+                       }
+               }
        }
-       scr_printf("\n");
+       return(0);
 }
 
 
@@ -467,7 +502,7 @@ void validate(CtdlIPC *ipc)
                        scr_printf("%s\n", cmd);
                if (r / 100 == 3) {
                        extract(buf, cmd, 0);
-                       val_user(ipc, buf, 1);
+                       if (val_user(ipc, buf, 1) != 0) finished = 1;
                }
        } while (finished == 0);
 }
@@ -607,10 +642,14 @@ void read_bio(CtdlIPC *ipc)
  */
 void do_system_configuration(CtdlIPC *ipc)
 {
+
+#define NUM_CONFIGS 34
+
        char buf[SIZ];
-       char sc[31][SIZ];
+       char sc[NUM_CONFIGS][SIZ];
        char *resp = NULL;
-       struct ExpirePolicy *expirepolicy = NULL;
+       struct ExpirePolicy *site_expirepolicy = NULL;
+       struct ExpirePolicy *mbx_expirepolicy = NULL;
        int a;
        int logpages = 0;
        int r;                  /* IPC response code */
@@ -625,7 +664,7 @@ void do_system_configuration(CtdlIPC *ipc)
                while (strlen(resp)) {
                        extract_token(buf, resp, 0, '\n');
                        remove_token(resp, 0, '\n');
-                       if (a < 31) {
+                       if (a < NUM_CONFIGS) {
                                strcpy(&sc[a][0], buf);
                        }
                        ++a;
@@ -636,7 +675,8 @@ void do_system_configuration(CtdlIPC *ipc)
        /* Fetch the expire policy (this will silently fail on old servers,
         * resulting in "default" policy)
         */
-       r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &expirepolicy, buf);
+       r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
+       r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
 
        /* Identification parameters */
 
@@ -673,7 +713,7 @@ void do_system_configuration(CtdlIPC *ipc)
        snprintf(sc[26], sizeof sc[26], "%d", (boolprompt(
              "Allow Aides to Zap (forget) rooms",
                                                     atoi(&sc[26][0]))));
-       snprintf(sc[30], sizeof sc[29], "%d", (boolprompt(
+       snprintf(sc[30], sizeof sc[30], "%d", (boolprompt(
              "Allow system Aides access to user mailboxes",
                                                     atoi(&sc[30][0]))));
 
@@ -696,14 +736,35 @@ void do_system_configuration(CtdlIPC *ipc)
        strprompt("Minimum number of worker threads", &sc[21][0], 3);
        strprompt("Maximum number of worker threads", &sc[22][0], 3);
 
-       /* no longer applicable ... deprecated
-       strprompt("Server-to-server networking password", &sc[15][0], 19);
-       */
-
-       strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
-       strprompt("SMTP server port (-1 to disable)", &sc[24][0], 5);
        strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
        strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
+       strprompt("SMTP server port (-1 to disable)", &sc[24][0], 5);
+
+       /* This logic flips the question around, because it's one of those
+        * situations where 0=yes and 1=no
+        */
+       a = atoi(sc[25]);
+       a = (a ? 0 : 1);
+       a = boolprompt("Correct forged From: lines during authenticated SMTP",
+               a);
+       a = (a ? 0 : 1);
+       snprintf(sc[25], sizeof sc[25], "%d", a);
+
+       /* LDAP settings */
+       if (serv_info.serv_supports_qnop) {
+               a = strlen(&sc[32][0]);
+               a = (a ? 1 : 0);        /* Set only to 1 or 0 */
+               a = boolprompt("Connect this Citadel to an LDAP directory", a);
+               if (a) {
+                       strprompt("Host name of LDAP server",
+                               &sc[32][0], 127);
+                       strprompt("Port number of LDAP service",
+                               &sc[33][0], 5);
+               }
+               else {
+                       strcpy(&sc[32][0], "");
+               }
+       }
 
        /* Expiry settings */
        strprompt("Default user purge time (days)", &sc[16][0], 5);
@@ -711,7 +772,7 @@ void do_system_configuration(CtdlIPC *ipc)
 
        /* Angels and demons dancing in my head... */
        do {
-               snprintf(buf, sizeof buf, "%d", expirepolicy->expire_mode);
+               snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
                strprompt("System default message expire policy (? for list)",
                          buf, 1);
                if (buf[0] == '?') {
@@ -721,31 +782,62 @@ void do_system_configuration(CtdlIPC *ipc)
                                "3. Expire by message age\n");
                }
        } while ((buf[0] < '1') || (buf[0] > '3'));
-       expirepolicy->expire_mode = buf[0] - '0';
+       site_expirepolicy->expire_mode = buf[0] - '0';
 
        /* ...lunatics and monsters underneath my bed */
-       if (expirepolicy->expire_mode == 2) {
-               snprintf(buf, sizeof buf, "%d", expirepolicy->expire_value);
+       if (site_expirepolicy->expire_mode == 2) {
+               snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
+               strprompt("Keep how many messages online?", buf, 10);
+               site_expirepolicy->expire_value = atol(buf);
+       }
+       if (site_expirepolicy->expire_mode == 3) {
+               snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
+               strprompt("Keep messages for how many days?", buf, 10);
+               site_expirepolicy->expire_value = atol(buf);
+       }
+
+       /* Media messiahs preying on my fears... */
+       do {
+               snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
+               strprompt("Mailbox default message expire policy (? for list)",
+                         buf, 1);
+               if (buf[0] == '?') {
+                       scr_printf("\n"
+                               "0. Go with the system default\n"
+                               "1. Never automatically expire messages\n"
+                               "2. Expire by message count\n"
+                               "3. Expire by message age\n");
+               }
+       } while ((buf[0] < '0') || (buf[0] > '3'));
+       mbx_expirepolicy->expire_mode = buf[0] - '0';
+
+       /* ...Pop culture prophets playing in my ears */
+       if (mbx_expirepolicy->expire_mode == 2) {
+               snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
                strprompt("Keep how many messages online?", buf, 10);
-               expirepolicy->expire_value = atol(buf);
+               mbx_expirepolicy->expire_value = atol(buf);
        }
-       if (expirepolicy->expire_mode == 3) {
-               snprintf(buf, sizeof buf, "%d", expirepolicy->expire_value);
+       if (mbx_expirepolicy->expire_mode == 3) {
+               snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
                strprompt("Keep messages for how many days?", buf, 10);
-               expirepolicy->expire_value = atol(buf);
+               mbx_expirepolicy->expire_value = atol(buf);
        }
+
+       strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
+       strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
+
        /* Save it */
        scr_printf("Save this configuration? ");
        if (yesno()) {
                r = 1;
-               for (a = 0; a < 31; a++)
+               for (a = 0; a < NUM_CONFIGS; a++)
                        r += 1 + strlen(sc[a]);
                resp = (char *)calloc(1, r);
                if (!resp) {
                        err_printf("Can't save config - out of memory!\n");
                        logoff(ipc, 1);
                }
-               for (a = 0; a < 31; a++) {
+               for (a = 0; a < NUM_CONFIGS; a++) {
                        strcat(resp, sc[a]);
                        strcat(resp, "\n");
                }
@@ -754,10 +846,17 @@ void do_system_configuration(CtdlIPC *ipc)
                        err_printf("%s\n", buf);
                }
                free(resp);
-               r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, expirepolicy, buf);
+
+               r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
+               if (r / 100 != 2) {
+                       err_printf("%s\n", buf);
+               }
+
+               r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
                if (r / 100 != 2) {
                        err_printf("%s\n", buf);
                }
+
        }
 }
 
@@ -874,7 +973,7 @@ void do_internet_configuration(CtdlIPC *ipc)
                                        err_printf("Can't save config - out of memory!\n");
                                        logoff(ipc, 1);
                                }
-                               for (i = 0; i < num_recs; i++) {
+                               if (num_recs) for (i = 0; i < num_recs; i++) {
                                        strcat(resp, recs[i]);
                                        strcat(resp, "\n");
                                }