]> code.citadel.org Git - citadel.git/blobdiff - citadel/routines2.c
* Reorg header stuff to make it more compatible with leak checkers
[citadel.git] / citadel / routines2.c
index 640a16e68f53ffe49dbe5cd20bd974b676e232e8..66ff6d090fa2f468a88caafb55a1713b54c79f27 100644 (file)
@@ -5,7 +5,6 @@
  *
  */
 
-#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -31,6 +30,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
+#include "sysdep.h"
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_decls.h"
@@ -161,7 +161,7 @@ void entregis(CtdlIPC *ipc)
                        striplt(diruser);
                        striplt(dirnode);
                        if ((strcasecmp(diruser, fullname))
-                          || (strcasecmp(dirnode, serv_info.serv_nodename))) {
+                          || (strcasecmp(dirnode, ipc->ServInfo.nodename))) {
                                scr_printf(
                                        "\nYou can't use %s as your address.\n",
                                        tmpemail);
@@ -510,10 +510,11 @@ void validate(CtdlIPC *ipc)
 void subshell(void)
 {
        int a, b;
+
+       screen_reset();
+       sttybbs(SB_RESTORE);
        a = fork();
        if (a == 0) {
-               screen_reset();
-               sttybbs(SB_RESTORE);
                signal(SIGINT, SIG_DFL);
                signal(SIGQUIT, SIG_DFL);
                execlp(getenv("SHELL"), getenv("SHELL"), NULL);
@@ -643,7 +644,7 @@ void read_bio(CtdlIPC *ipc)
 void do_system_configuration(CtdlIPC *ipc)
 {
 
-#define NUM_CONFIGS 34
+#define NUM_CONFIGS 37
 
        char buf[SIZ];
        char sc[NUM_CONFIGS][SIZ];
@@ -751,7 +752,7 @@ void do_system_configuration(CtdlIPC *ipc)
        snprintf(sc[25], sizeof sc[25], "%d", a);
 
        /* LDAP settings */
-       if (serv_info.serv_supports_qnop) {
+       if (ipc->ServInfo.supports_ldap) {
                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);
@@ -760,6 +761,9 @@ void do_system_configuration(CtdlIPC *ipc)
                                &sc[32][0], 127);
                        strprompt("Port number of LDAP service",
                                &sc[33][0], 5);
+                       strprompt("Base DN", &sc[34][0], 255);
+                       strprompt("Bind DN", &sc[35][0], 255);
+                       strprompt("Password for bind DN", &sc[36][0], 255);
                }
                else {
                        strcpy(&sc[32][0], "");
@@ -904,6 +908,7 @@ void do_internet_configuration(CtdlIPC *ipc)
        int badkey;
        int i, j;
        int quitting = 0;
+       int modified = 0;
        int r;
        
        r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
@@ -955,6 +960,7 @@ void do_internet_configuration(CtdlIPC *ipc)
                                                        &buf[strlen(buf)]);
                                        recs[num_recs-1] = strdup(buf);
                                }
+                               modified = 1;
                                break;
                        case 'd':
                                i = intprompt("Delete which one",
@@ -963,6 +969,7 @@ void do_internet_configuration(CtdlIPC *ipc)
                                --num_recs;
                                for (j=i; j<num_recs; ++j)
                                        recs[j] = recs[j+1];
+                               modified = 1;
                                break;
                        case 's':
                                r = 1;
@@ -980,17 +987,19 @@ void do_internet_configuration(CtdlIPC *ipc)
                                r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
                                if (r / 100 != 4) {
                                        err_printf("%s\n", buf);
+                               } else {
+                                       scr_printf("Wrote %d records.\n", num_recs);
+                                       modified = 0;
                                }
-                               quitting = 1;
                                break;
                        case 'q':
-                               quitting = boolprompt(
+                               quitting = !modified || boolprompt(
                                        "Quit without saving", 0);
                                break;
                        default:
                                badkey = 1;
                }
-       } while (quitting == 0);
+       } while (!quitting);
 
        if (recs != NULL) {
                for (i=0; i<num_recs; ++i) free(recs[i]);
@@ -1016,6 +1025,8 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
        char addr[SIZ];
        FILE *tempfp;
        FILE *changefp;
+       char *listing = NULL;
+       int r;
 
        if (strlen(editor_paths[0]) == 0) {
                scr_printf("You must have an external editor configured in"
@@ -1037,10 +1048,11 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
        fprintf(tempfp, "# Specify one per line.\n"
                        "\n\n");
 
-       CtdlIPC_putline(ipc, "GNET");
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] == '1') {
-               while(CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
+       r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
+       if (r / 100 == 1) {
+               while(listing && strlen(listing)) {
+                       extract_token(buf, listing, 0, '\n');
+                       remove_token(listing, 0, '\n');
                        extract(instr, buf, 0);
                        if (!strcasecmp(instr, entrytype)) {
                                extract(addr, buf, 1);
@@ -1048,6 +1060,10 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
                        }
                }
        }
+       if (listing) {
+               free(listing);
+               listing = NULL;
+       }
        fclose(tempfp);
 
        e_ex_code = 1;  /* start with a failed exit code */
@@ -1078,16 +1094,21 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
 
        if (e_ex_code == 0) {           /* Save changes */
                changefp = fopen(changefile, "w");
-               CtdlIPC_putline(ipc, "GNET");
-               CtdlIPC_getline(ipc, buf);
-               if (buf[0] == '1') {
-                       while(CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
+               r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
+               if (r / 100 == 1) {
+                       while(listing && strlen(listing)) {
+                               extract_token(buf, listing, 0, '\n');
+                               remove_token(listing, 0, '\n');
                                extract(instr, buf, 0);
                                if (strcasecmp(instr, entrytype)) {
                                        fprintf(changefp, "%s\n", buf);
                                }
                        }
                }
+               if (listing) {
+                       free(listing);
+                       listing = NULL;
+               }
                tempfp = fopen(filename, "r");
                while (fgets(buf, sizeof buf, tempfp) != NULL) {
                        for (i=0; i<strlen(buf); ++i) {
@@ -1102,19 +1123,15 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
                fclose(changefp);
 
                /* now write it to the server... */
-               CtdlIPC_putline(ipc, "SNET");
-               CtdlIPC_getline(ipc, buf);
-               if (buf[0] == '4') {
-                       changefp = fopen(changefile, "r");
-                       if (changefp != NULL) {
-                               while (fgets(buf, sizeof buf,
-                                      changefp) != NULL) {
-                                       buf[strlen(buf) - 1] = 0;
-                                       CtdlIPC_putline(ipc, buf);
-                               }
-                               fclose(changefp);
+               changefp = fopen(changefile, "r");
+               if (changefp != NULL) {
+                       listing = load_message_from_file(changefp);
+                       if (listing) {
+                               r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
+                               free(listing);
+                               listing = NULL;
                        }
-                       CtdlIPC_putline(ipc, "000");
+                       fclose(changefp);
                }
        }
 
@@ -1134,18 +1151,22 @@ void do_ignet_configuration(CtdlIPC *ipc) {
        int badkey;
        int i, j;
        int quitting = 0;
-       
+       int modified = 0;
+       char *listing = NULL;
+       int r;
+
+       r = CtdlIPCGetSystemConfigByType(ipc, IGNETCFG, &listing, buf);
+       if (r / 100 == 1) while (*listing && strlen(listing)) {
+               extract_token(buf, listing, 0, '\n');
+               remove_token(listing, 0, '\n');
 
-       snprintf(buf, sizeof buf, "CONF getsys|%s", IGNETCFG);
-       CtdlIPC_putline(ipc, buf);
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] == '1') while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
                ++num_recs;
                if (num_recs == 1) recs = malloc(sizeof(char *));
                else recs = realloc(recs, (sizeof(char *)) * num_recs);
                recs[num_recs-1] = malloc(SIZ);
                strcpy(recs[num_recs-1], buf);
        }
+       if (listing) free(listing);
 
        do {
                scr_printf("\n");
@@ -1178,6 +1199,7 @@ void do_ignet_configuration(CtdlIPC *ipc) {
                scr_printf("%-3s\n", buf);
                color(DIM_WHITE);
                }
+               scr_printf("\n");
 
                ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
                switch(ch) {
@@ -1198,6 +1220,7 @@ void do_ignet_configuration(CtdlIPC *ipc) {
                                strprompt("Enter port number  : ",
                                        &buf[strlen(buf)-3], 5);
                                recs[num_recs-1] = strdup(buf);
+                               modified = 1;
                                break;
                        case 'd':
                                i = intprompt("Delete which one",
@@ -1206,30 +1229,37 @@ void do_ignet_configuration(CtdlIPC *ipc) {
                                --num_recs;
                                for (j=i; j<num_recs; ++j)
                                        recs[j] = recs[j+1];
+                               modified = 1;
                                break;
                        case 's':
-                               snprintf(buf, sizeof buf, "CONF putsys|%s", IGNETCFG);
-                               CtdlIPC_putline(ipc, buf);
-                               CtdlIPC_getline(ipc, buf);
-                               if (buf[0] == '4') {
-                                       for (i=0; i<num_recs; ++i) {
-                                               CtdlIPC_putline(ipc, recs[i]);
-                                       }
-                                       CtdlIPC_putline(ipc, "000");
+                               r = 1;
+                               for (i = 0; i < num_recs; ++i)
+                                       r += 1 + strlen(recs[i]);
+                               listing = (char*) calloc(1, r);
+                               if (!listing) {
+                                       err_printf("Can't save config - out of memory!\n");
+                                       logoff(ipc, 1);
                                }
-                               else {
-                                       scr_printf("%s\n", &buf[4]);
+                               if (num_recs) for (i = 0; i < num_recs; ++i) {
+                                       strcat(listing, recs[i]);
+                                       strcat(listing, "\n");
+                               }
+                               r = CtdlIPCSetSystemConfigByType(ipc, IGNETCFG, listing, buf);
+                               if (r / 100 != 4) {
+                                       scr_printf("%s\n", buf);
+                               } else {
+                                       scr_printf("Wrote %d records.\n", num_recs);
+                                       modified = 0;
                                }
-                               quitting = 1;
                                break;
                        case 'q':
-                               quitting = boolprompt(
+                               quitting = !modified || boolprompt(
                                        "Quit without saving", 0);
                                break;
                        default:
                                badkey = 1;
                }
-       } while (quitting == 0);
+       } while (!quitting);
 
        if (recs != NULL) {
                for (i=0; i<num_recs; ++i) free(recs[i]);
@@ -1249,18 +1279,22 @@ void do_filterlist_configuration(CtdlIPC *ipc)
        int badkey;
        int i, j;
        int quitting = 0;
-       
+       int modified = 0;
+       char *listing = NULL;
+       int r;
+
+       r = CtdlIPCGetSystemConfigByType(ipc, FILTERLIST, &listing, buf);
+       if (r / 100 == 1) while (*listing && strlen(listing)) {
+               extract_token(buf, listing, 0, '\n');
+               remove_token(listing, 0, '\n');
 
-       snprintf(buf, sizeof buf, "CONF getsys|%s", FILTERLIST);
-       CtdlIPC_putline(ipc, buf);
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] == '1') while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
                ++num_recs;
                if (num_recs == 1) recs = malloc(sizeof(char *));
                else recs = realloc(recs, (sizeof(char *)) * num_recs);
                recs[num_recs-1] = malloc(SIZ);
                strcpy(recs[num_recs-1], buf);
        }
+       if (listing) free(listing);
 
        do {
                scr_printf("\n");
@@ -1309,6 +1343,7 @@ void do_filterlist_configuration(CtdlIPC *ipc)
                                        &buf[strlen(buf)], 16);
                                strcat(buf, "|");
                                recs[num_recs-1] = strdup(buf);
+                               modified = 1;
                                break;
                        case 'd':
                                i = intprompt("Delete which one",
@@ -1317,30 +1352,37 @@ void do_filterlist_configuration(CtdlIPC *ipc)
                                --num_recs;
                                for (j=i; j<num_recs; ++j)
                                        recs[j] = recs[j+1];
+                               modified = 1;
                                break;
                        case 's':
-                               snprintf(buf, sizeof buf, "CONF putsys|%s", FILTERLIST);
-                               CtdlIPC_putline(ipc, buf);
-                               CtdlIPC_getline(ipc, buf);
-                               if (buf[0] == '4') {
-                                       for (i=0; i<num_recs; ++i) {
-                                               CtdlIPC_putline(ipc, recs[i]);
-                                       }
-                                       CtdlIPC_putline(ipc, "000");
+                               r = 1;
+                               for (i = 0; i < num_recs; ++i)
+                                       r += 1 + strlen(recs[i]);
+                               listing = (char*) calloc(1, r);
+                               if (!listing) {
+                                       err_printf("Can't save config - out of memory!\n");
+                                       logoff(ipc, 1);
+                               }
+                               if (num_recs) for (i = 0; i < num_recs; ++i) {
+                                       strcat(listing, recs[i]);
+                                       strcat(listing, "\n");
                                }
-                               else {
-                                       scr_printf("%s\n", &buf[4]);
+                               r = CtdlIPCSetSystemConfigByType(ipc, FILTERLIST, listing, buf);
+                               if (r / 100 != 4) {
+                                       scr_printf("%s\n", buf);
+                               } else {
+                                       scr_printf("Wrote %d records.\n", num_recs);
+                                       modified = 0;
                                }
-                               quitting = 1;
                                break;
                        case 'q':
-                               quitting = boolprompt(
+                               quitting = !modified || boolprompt(
                                        "Quit without saving", 0);
                                break;
                        default:
                                badkey = 1;
                }
-       } while (quitting == 0);
+       } while (!quitting);
 
        if (recs != NULL) {
                for (i=0; i<num_recs; ++i) free(recs[i]);