]> code.citadel.org Git - citadel.git/blobdiff - citadel/migratenet.c
removed all references to sprintf from several files (not all files yet)
[citadel.git] / citadel / migratenet.c
index 8a979e43c2b66c5e92aa95697ec268a24bd18f9f..1ecf2c1e705f0d0b9ffa19b3aa16b823322e692e 100644 (file)
 #include <sys/types.h>
 #include <dirent.h>
 #include <errno.h>
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
 #include "citadel.h"
 #include "ipc.h"
 #include "tools.h"
 #include "config.h"
 
+struct mn_roomlist {
+       struct mn_roomlist *next;
+       char roomname[SIZ];
+};
 
 void logoff(int code)
 {
@@ -31,10 +38,16 @@ int main(int argc, char **argv)
        DIR *dp;
        struct dirent *d;
        long highest = 0L;
+       char node[SIZ];
        char room[SIZ];
        long thighest;
        FILE *fp;
-       FILE *tempfp;
+       FILE *roomfp;
+       char roomfilename[SIZ];
+       FILE *nodefp;
+       char nodefilename[SIZ];
+       struct mn_roomlist *mn = NULL;
+       struct mn_roomlist *mnptr = NULL;
 
        printf("\n\n\n\n\n"
 "This utility migrates your network settings (room sharing with other\n"
@@ -56,7 +69,7 @@ int main(int argc, char **argv)
                logoff(atoi(buf));
        }
 
-       sprintf(buf, "IPGM %d", config.c_ipgm_secret);
+       snprintf(buf, sizeof buf, "IPGM %d", config.c_ipgm_secret);
        serv_puts(buf);
        serv_gets(buf);
        fprintf(stderr, "%s\n", &buf[4]);
@@ -69,8 +82,16 @@ int main(int argc, char **argv)
                exit(errno);
        }
 
-       tempfp = tmpfile();
-       if (tempfp == NULL) {
+       strcpy(roomfilename, tmpnam(NULL));
+       roomfp = fopen(roomfilename, "w");
+       if (roomfp == NULL) {
+               perror("cannot open temp file");
+               exit(errno);
+       }
+
+       strcpy(nodefilename, tmpnam(NULL));
+       nodefp = fopen(nodefilename, "w");
+       if (roomfp == NULL) {
                perror("cannot open temp file");
                exit(errno);
        }
@@ -87,25 +108,144 @@ int main(int argc, char **argv)
                        fp = fopen(d->d_name, "r");
                }
                if (fp != NULL) {
-                       printf("*** Processing '%s'\n", d->d_name);
+                       printf("\n*** Processing '%s'\n", d->d_name);
+
+                       fprintf(nodefp, "%s|", d->d_name);
+                       printf("Enter shared secret: ");
+                       gets(buf);
+                       if (buf[0] == 0) strcpy(buf, config.c_net_password);
+                       fprintf(nodefp, "%s|", buf);
+                       printf("Enter host name/IP : ");
+                       gets(buf);
+                       if (buf[0] == 0) snprintf(buf, sizeof buf, "%s.citadel.org",
+                               d->d_name);
+                       fprintf(nodefp, "%s|", buf);
+                       printf("Enter port number  : ");
+                       gets(buf);
+                       if (buf[0] == 0) strcpy(buf, "504");
+                       fprintf(nodefp, "%s\n", buf);
+
+                       fgets(buf, sizeof buf, fp);
+                       printf("skipping: %s", buf);
                        while (fgets(room, sizeof room, fp),
-                               fscanf(fp, "%ld\n", &thighest),
-                               !feof(fp) ) {
-                                       room[strlen(room) - 1] = 0;
-                                       fprintf(tempfp, "%s|%s\n",
-                                               room, d->d_name);
-                                       if (thighest > highest) {
-                                               highest = thighest;
-                                       }
+                             (fgets(buf, sizeof buf, fp) != NULL) ) {
+                               thighest = atol(buf),
+                               room[strlen(room) - 1] = 0;
+                               fprintf(roomfp, "%s|%s\n",
+                                       d->d_name, room);
+                               if (thighest > highest) {
+                                       highest = thighest;
+                               }
                        }
                        fclose(fp);
                }
        }
 
        closedir(dp);
-       fclose(tempfp);
-       return(0);
-}
+       fclose(roomfp);
+       fclose(nodefp);
+
+       /* Point of no return */
+
+       /* Set up the node table */
+       printf("Creating neighbor node table\n");
+       snprintf(buf, sizeof buf, "CONF putsys|%s", IGNETCFG);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0] == '4') {
+               nodefp = fopen(nodefilename, "r");
+               if (nodefp != NULL) {
+                       while (fgets(buf, sizeof buf, nodefp) != NULL) {
+                               buf[strlen(buf)-1] = 0;
+                               serv_puts(buf);
+                       }
+                       fclose(nodefp);
+               }
+               serv_puts("000");
+       }
+       else {
+               printf("%s\n", &buf[4]);
+       }
+
+
+       /* Now go through the table looking for node names to enter */
+
+       snprintf(buf, sizeof buf, "cat %s |awk -F \"|\" '{ print $2 }' |sort -f |uniq -i",
+               roomfilename);
+       roomfp = popen(buf, "r");
+       if (roomfp == NULL) {
+               perror("cannot open pipe");
+               unlink(roomfilename);
+       }
+
+       while (fgets(room, sizeof room, roomfp) != NULL) {
+               room[strlen(room)-1] = 0;
+               if (strlen(room) > 0) {
+                       mnptr = (struct mn_roomlist *)
+                               malloc(sizeof (struct mn_roomlist));
+                       strcpy(mnptr->roomname, room);
+                       mnptr->next = mn;
+                       mn = mnptr;
+               }
+       }
+
+       pclose(roomfp);
+
+       /* Enter configurations for each room... */
+       while (mn != NULL) {
+               printf("Room <%s>\n", mn->roomname);
+
+               snprintf(buf, sizeof buf, "GOTO %s", mn->roomname);
+               serv_puts(buf);
+               serv_gets(buf);
+               printf("%s\n", &buf[4]);
+               if (buf[0] != '2') goto roomerror;
+
+               serv_puts("SNET");
+               serv_gets(buf);
+               if (buf[0] != '4') goto roomerror;
+
+               snprintf(buf, sizeof buf, "lastsent|%ld", highest);
+               serv_puts(buf);
+
+               roomfp = fopen(roomfilename, "r");
+               if (roomfp != NULL) {
+                       while (fgets(buf, sizeof buf, roomfp) != NULL) {
+                               buf[strlen(buf)-1] = 0;
+                               extract(node, buf, 0);
+                               extract(room, buf, 1);
+                               if (!strcasecmp(room, mn->roomname)) {
+                                       snprintf(buf, sizeof buf,
+                                               "ignet_push_share|%s", node);
+                                       serv_puts(buf);
+                               }
+                       }
+                       fclose(roomfp);
+               }
+
+               serv_puts("000");
 
+roomerror:     /* free this record */
+               mnptr = mn->next;
+               free(mn);
+               mn = mnptr;
+       }
+
+       unlink(roomfilename);
+       unlink(nodefilename);
+
+       printf("\n\n"
+               "If this conversion was successful, you do not need your\n"
+               "old network configuration files.  Delete them now? "
+       );
+
+       gets(buf);
+       if (tolower(buf[0]) != 'y') exit(0);
 
+       get_config();
+       system("rm -fr ./network/systems");
+       system("rm -f ./network/mail.sysinfo");
+       system("rm -f ./network/internetmail.config");
 
+       exit(0);
+}