file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / uucp / uucico / conn.c
index 7a2f4b5..9fdc307 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)conn.c     5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)conn.c     5.15    (Berkeley) %G%";
 #endif
 
 #include <signal.h>
 #endif
 
 #include <signal.h>
@@ -61,31 +61,43 @@ alarmtr()
  */
 #define PCP_BAUD       3
 #define PCP_PHONE      4
  */
 #define PCP_BAUD       3
 #define PCP_PHONE      4
-#define PCP_CALLBACK   8
-#define PCP_CITY       10
-#define PCP_RPHONE     12
-#define NPCFIELDS      15
+#define PCP_CITY       14
+#define PCP_PASSWORD   16
+#define PCP_RPHONE     20
+#define NPCFIELDS      23
 
 static char *PCFlds[] = {
        "PC-PURSUIT",
        "Any",
        "ACU",
        "1200",
 
 static char *PCFlds[] = {
        "PC-PURSUIT",
        "Any",
        "ACU",
        "1200",
-       CNULL,  /* <--- **** Welcome to Telenet PC Pursuit ***** */
+       CNULL,
+       CNULL,
+       "P_ZERO",       /* Telenet insists on zero parity */
        "ABORT",
        "ABORT",
-       "Good", /* Abort of Good bye! */
-       ")",    /* <--- Enter your 7-digit phone number (xxx-xxxx) */
-       CNULL,  /* ---> 528-1234 */
-       "call?",        /* <--- Which city do you wish to call? */
-       CNULL,  /* ---> CHICAGO */
-       ")",    /* <--- Enter the phone number you wish to call (xxx-xxxx) */
-       CNULL,  /* ---> 690-7171 */
-       "R)?",  /* <--- You are #1 in the queue. Do you want to wait, or Restart (Y/N/R)? */
-       "Y",
-       CNULL   /* <--- .....Good Bye! */
+       "BUSY",         /* Abort on Busy Signal */
+       CNULL,
+       "\\d\\d\\r\\d\\r",      /* Get telenet's attention */
+       "TERMINAL=~3-\r-TERM~3-\r-TERM~5",      /* Terminal type ? */
+       "\\r",
+       "@",            /* telenet's prompt */
+       "D/DCWAS/21,telenetloginstring", /* overwritten later */
+       "PASSWORD",
+       CNULL,          /* telenet password */
+       "CONNECTED",    /* We're now talking to a Hayes in the remote city */
+       "ATZ",          /* Reset it */
+       "OK",
+       "ATDT6907171", /* overwritten */
+       "CONNECT",      
+       "\\d\\r",               /* We're in !*/
+       CNULL,
 };
 
 };
 
-static char PCP_brand[20];
+static char PCP_brand[25];
+int Dcf = -1;
+char *Flds[MAXC/10];
+char LineType[10];
+extern int LocalOnly;
 
 /*
  *     place a telephone call to system and login, etc.
 
 /*
  *     place a telephone call to system and login, etc.
@@ -99,11 +111,6 @@ static char PCP_brand[20];
  *
  *             >0  - file no.  -  connect ok
  */
  *
  *             >0  - file no.  -  connect ok
  */
-
-int Dcf = -1;
-char *Flds[MAXC/10];
-extern int LocalOnly;
-
 conn(system)
 char *system;
 {
 conn(system)
 char *system;
 {
@@ -115,15 +122,19 @@ char *system;
        nf = 0;
 
        fsys = fopen(SYSFILE, "r");
        nf = 0;
 
        fsys = fopen(SYSFILE, "r");
-       ASSERT(fsys != NULL, "CAN'T OPEN", SYSFILE, 0);
+       if (fsys == NULL) {
+               syslog(LOG_ERR, "fopen(%s) failed: %m", SYSFILE);
+               cleanup(FAIL);
+       }
 
        DEBUG(4, "finds (%s) called\n", system);
 keeplooking:
        while((nf = finds(fsys, system, info, Flds)) > 0) {
 
        DEBUG(4, "finds (%s) called\n", system);
 keeplooking:
        while((nf = finds(fsys, system, info, Flds)) > 0) {
+               strncpy(LineType, Flds[F_LINE], 10);
                if (LocalOnly) {
                if (LocalOnly) {
-                       if (strcmp("TCP", Flds[F_LINE])
-                               && strcmp("DIR", Flds[F_LINE])
-                               && strcmp("LOCAL", Flds[F_LINE]) ) {
+                       if (strcmp("TCP", LineType)
+                               && strcmp("DIR", LineType)
+                               && strcmp("LOCAL", LineType) ) {
                                        fcode = CF_TIME;
                                        continue;
                        }
                                        fcode = CF_TIME;
                                        continue;
                        }
@@ -135,12 +146,17 @@ keeplooking:
                                continue;
                }
                /* For GTE's PC Pursuit */
                                continue;
                }
                /* For GTE's PC Pursuit */
-               if (snccmp(Flds[F_LINE], PCP) == SAME) {
+               if (snccmp(LineType, PCP) == SAME) {
                        FILE *dfp;
                        int status;
                        static struct Devices dev;
                        FILE *dfp;
                        int status;
                        static struct Devices dev;
+
                        dfp = fopen(DEVFILE, "r");
                        dfp = fopen(DEVFILE, "r");
-                       ASSERT(dfp != NULL, "Can't open", DEVFILE, 0);
+                       if (dfp == NULL) {
+                               syslog(LOG_ERR, "fopen(%s) failed: %m",
+                                       DEVFILE);
+                               cleanup(FAIL);
+                       }
                        while ((status=rddev(dfp, &dev)) != FAIL
                                && strcmp(PCP, dev.D_type) != SAME)
                                        ;
                        while ((status=rddev(dfp, &dev)) != FAIL
                                && strcmp(PCP, dev.D_type) != SAME)
                                        ;
@@ -154,25 +170,28 @@ keeplooking:
                        }
                        PCFlds[PCP_BAUD] = dev.D_class;
                        PCFlds[PCP_PHONE] = dev.D_calldev;
                        }
                        PCFlds[PCP_BAUD] = dev.D_class;
                        PCFlds[PCP_PHONE] = dev.D_calldev;
-                       PCFlds[PCP_CALLBACK] = dev.D_arg[D_CHAT];
-                       PCFlds[PCP_CITY] = Flds[F_CLASS];
-                       PCFlds[PCP_RPHONE] = Flds[F_PHONE];
+                       sprintf(PCFlds[PCP_CITY], "c d/%s%s,%s",
+                               Flds[F_CLASS],
+                               index(Flds[F_CLASS], '/') == NULL ? "/12" : "",
+                               dev.D_arg[D_CHAT]);
+                       PCFlds[PCP_PASSWORD] = dev.D_line;
+                       strncpy(&PCFlds[PCP_RPHONE][4], Flds[F_PHONE], 7);
                        strncpy(PCP_brand, dev.D_brand, sizeof(PCP_brand));
                        strncpy(PCP_brand, dev.D_brand, sizeof(PCP_brand));
-                       if ((fcode = getto(PCFlds)) < 0)
+                       if ((fcode = getto(PCFlds)) < 0) {
+                               rmlock(PCP);
                                continue;
                                continue;
+                       }
                        Dcf = fcode;
                        fcode = login(NPCFIELDS, PCFlds, Dcf);
                        Dcf = fcode;
                        fcode = login(NPCFIELDS, PCFlds, Dcf);
-                       clsacu(); /* Hang up, they'll call back */
-                       if (fcode != SUCCESS) {
-                               fcode = CF_DIAL;
-                               continue;
-                       }
-                       Flds[F_CLASS] = dev.D_class;
-                       Flds[F_PHONE] = dev.D_line;
-                       
-               } /* end PC Pursuit */
-               if ((fcode = getto(Flds)) > 0) 
+                       if (fcode == SUCCESS)
+                               break;
+                       fcode = CF_DIAL;
+                       rmlock(PCP);
+                       /* end PC Pursuit */
+               } else if ((fcode = getto(Flds)) > 0)  {
+                       Dcf = fcode;
                        break;
                        break;
+               }
        }
 
        if (nf <= 0) {
        }
 
        if (nf <= 0) {
@@ -180,20 +199,11 @@ keeplooking:
                return fcode ? fcode : nf;
        }
 
                return fcode ? fcode : nf;
        }
 
-       Dcf = fcode;
 
 
-       if (fcode >= 0 && snccmp(Flds[F_LINE], PCP) == SAME) {
-               AbortOn = "Good";       /* .... Good Bye */
-               fcode = expect("****~300", Dcf);
-               if (fcode != SUCCESS) {
-                       DEBUG(4, "\nexpect timed out\n", CNULL);
-                       fcode = CF_DIAL;
-               }
-       }
        if (fcode >= 0) {
                DEBUG(4, "login %s\n", "called");
        if (fcode >= 0) {
                DEBUG(4, "login %s\n", "called");
-               fcode = login(nf, Flds, Dcf);
-       }
+               setproctitle("login");
+               fcode = login(nf, Flds, Dcf); }
        if (fcode < 0) {
                clsacu();
                if (fcode == ABORT) {
        if (fcode < 0) {
                clsacu();
                if (fcode == ABORT) {
@@ -209,6 +219,9 @@ keeplooking:
        return Dcf;
 }
 
        return Dcf;
 }
 
+int nulldev();
+int (*CU_end)() = nulldev;
+
 /*
  *     connect to remote machine
  *
 /*
  *     connect to remote machine
  *
@@ -216,12 +229,11 @@ keeplooking:
  *             >0  -  file number - ok
  *             FAIL  -  failed
  */
  *             >0  -  file number - ok
  *             FAIL  -  failed
  */
-
 getto(flds)
 register char *flds[];
 {
        register struct condev *cd;
 getto(flds)
 register char *flds[];
 {
        register struct condev *cd;
-       int nulldev(), diropn();
+       int diropn();
        char *line;
 
        DEBUG(4, "getto: call no. %s ", flds[F_PHONE]);
        char *line;
 
        DEBUG(4, "getto: call no. %s ", flds[F_PHONE]);
@@ -261,8 +273,6 @@ register char *flds[];
  *
  *     return codes:  none
  */
  *
  *     return codes:  none
  */
-
-int (*CU_end)() = nulldev;
 clsacu()
 {
        /* make *sure* Dcf is no longer exclusive.
 clsacu()
 {
        /* make *sure* Dcf is no longer exclusive.
@@ -294,7 +304,6 @@ clsacu()
 /*
  *     expand phone number for given prefix and number
  */
 /*
  *     expand phone number for given prefix and number
  */
-
 exphone(in, out)
 register char *in, *out;
 {
 exphone(in, out)
 register char *in, *out;
 {
@@ -342,7 +351,6 @@ register char *in, *out;
  *
  *     return code - FAIL at end-of file; 0 otherwise
  */
  *
  *     return code - FAIL at end-of file; 0 otherwise
  */
-
 rddev(fp, dev)
 register struct Devices *dev;
 FILE *fp;
 rddev(fp, dev)
 register struct Devices *dev;
 FILE *fp;
@@ -352,7 +360,10 @@ FILE *fp;
        if (!cfgets(dev->D_argbfr, sizeof(dev->D_argbfr), fp))
                return FAIL;
        na = getargs(dev->D_argbfr, dev->D_arg, 20);
        if (!cfgets(dev->D_argbfr, sizeof(dev->D_argbfr), fp))
                return FAIL;
        na = getargs(dev->D_argbfr, dev->D_arg, 20);
-       ASSERT(na >= 4, "BAD DEVICE ENTRY", dev->D_argbfr, 0);
+       if (na < 4) {
+               syslog(LOG_ERR, "%s: invalid device entry", dev->D_argbfr);
+               cleanup(FAIL);
+       }
        if (na == 4) {
                dev->D_brand = "";
                na++;
        if (na == 4) {
                dev->D_brand = "";
                na++;
@@ -370,7 +381,6 @@ FILE *fp;
  *             CF_SYSTEM  -  system name not found
  *             CF_TIME  -  wrong time to call
  */
  *             CF_SYSTEM  -  system name not found
  *             CF_TIME  -  wrong time to call
  */
-
 finds(fsys, sysnam, info, flds)
 char *sysnam, info[], *flds[];
 FILE *fsys;
 finds(fsys, sysnam, info, flds)
 char *sysnam, info[], *flds[];
 FILE *fsys;
@@ -403,7 +413,6 @@ FILE *fsys;
  *
  *     return codes:  SUCCESS  |  FAIL
  */
  *
  *     return codes:  SUCCESS  |  FAIL
  */
-
 login(nf, flds, fn)
 register char *flds[];
 int nf, fn;
 login(nf, flds, fn)
 register char *flds[];
 int nf, fn;
@@ -411,12 +420,17 @@ int nf, fn;
        register char *want, *altern;
        int k, ok;
 
        register char *want, *altern;
        int k, ok;
 
-       ASSERT(nf > 4, "TOO FEW LOG FIELDS", CNULL, nf);
+       if (nf < 4) {
+               syslog(LOG_ERR, "Too few log fields: %d", nf);
+               cleanup(FAIL);
+       }
        if (setjmp(Cjbuf))
                return FAIL;
        AbortOn = NULL;
        for (k = F_LOGIN; k < nf; k += 2) {
                want = flds[k];
        if (setjmp(Cjbuf))
                return FAIL;
        AbortOn = NULL;
        for (k = F_LOGIN; k < nf; k += 2) {
                want = flds[k];
+               if (want == NULL)
+                       want = "";
                ok = FAIL;
                while (ok != SUCCESS) {
                        altern = index(want, '-');
                ok = FAIL;
                while (ok != SUCCESS) {
                        altern = index(want, '-');
@@ -441,7 +455,9 @@ int nf, fn;
                                sendthem(altern, fn);
                        } else
                                if (ok == ABORT) {
                                sendthem(altern, fn);
                        } else
                                if (ok == ABORT) {
-                                       logent("LOGIN ABORTED", _FAILED);
+                                       char sbuf[MAXFULLNAME];
+                                       sprintf(sbuf, "LOGIN ABORTED on \"%s\"",                                                AbortOn);
+                                       logent(sbuf, _FAILED);
                                        return ABORT;
                                }
                }
                                        return ABORT;
                                }
                }
@@ -515,7 +531,6 @@ struct sg_spds {int sp_val, sp_name;} spds[] = {
  *
  *     return codes:  none
  */
  *
  *     return codes:  none
  */
-
 fixline(tty, spwant)
 int tty, spwant;
 {
 fixline(tty, spwant)
 int tty, spwant;
 {
@@ -530,7 +545,10 @@ int tty, spwant;
        for (ps = spds; ps->sp_val; ps++)
                if (ps->sp_val == spwant)
                        speed = ps->sp_name;
        for (ps = spds; ps->sp_val; ps++)
                if (ps->sp_val == spwant)
                        speed = ps->sp_name;
-       ASSERT(speed >= 0, "BAD SPEED", CNULL, speed);
+       if (speed < 0) {
+               syslog(LOG_ERR, "unrecognized speed: %d", speed);
+               cleanup(FAIL);
+       }
 #ifdef USG
        if (ioctl(tty, TCGETA, &ttbuf) < 0)
                return FAIL;
 #ifdef USG
        if (ioctl(tty, TCGETA, &ttbuf) < 0)
                return FAIL;
@@ -562,39 +580,6 @@ int tty, spwant;
        return SUCCESS;
 }
 
        return SUCCESS;
 }
 
-/*
- *     getbaud(tty)    set linebaudrate variable
- *
- *     return codes:  none
- */
-
-getbaud(tty)
-int tty;
-{
-#ifdef USG
-       struct termio ttbuf;
-#else
-       struct sgttyb ttbuf;
-#endif
-       register struct sg_spds *ps;
-       register int name;
-
-       if (IsTcpIp)
-               return;
-#ifdef USG
-       ioctl(tty, TCGETA, &ttbuf);
-       name = ttbuf.c_cflag & CBAUD;
-#else
-       ioctl(tty, TIOCGETP, &ttbuf);
-       name = ttbuf.sg_ispeed;
-#endif
-       for (ps = spds; ps->sp_val; ps++)
-               if (ps->sp_name == name) {
-                       linebaudrate = ps->sp_val;
-                       break;
-               }
-}
-
 #define MR 100
 
 /*
 #define MR 100
 
 /*
@@ -605,7 +590,6 @@ int tty;
  *             FAIL  -  lost line or too many characters read
  *             some character  -  timed out
  */
  *             FAIL  -  lost line or too many characters read
  *             some character  -  timed out
  */
-
 expect(str, fn)
 register char *str;
 int fn;
 expect(str, fn)
 register char *str;
 int fn;
@@ -624,7 +608,9 @@ int fn;
                        switch(*++strptr) {
                        case 's':
                                DEBUG(5, "BLANK\n", CNULL);
                        switch(*++strptr) {
                        case 's':
                                DEBUG(5, "BLANK\n", CNULL);
+                               strptr--;
                                *strptr = ' ';
                                *strptr = ' ';
+                               strcpy(&strptr[1], &strptr[4]);
                                break;
                        default:
                                strptr--;  /* back up to backslash */
                                break;
                        default:
                                strptr--;  /* back up to backslash */
@@ -709,7 +695,7 @@ int fn;
 
        if (!p_init) {
                p_init++;
 
        if (!p_init) {
                p_init++;
-               bld_partab(P_EVEN);
+               bld_partab(P_ZERO);
        }
 
        if (prefix("BREAK", str)) {
        }
 
        if (prefix("BREAK", str)) {
@@ -1003,16 +989,10 @@ char *string;
        if (th < tl) {          /* crosses midnight */
                if (tl <= tn || tn < th)
                        return MGrade;
        if (th < tl) {          /* crosses midnight */
                if (tl <= tn || tn < th)
                        return MGrade;
-       } else
-
-       if (i < 2)
-               return MGrade;
-       if (th < tl) {  /* crosses midnight */
-               if (tl <= tn || tn < th)
-                       return MGrade;
-       } else
+       } else {
                if (tl <= tn && tn < th)
                        return MGrade;
                if (tl <= tn && tn < th)
                        return MGrade;
+       }
        return FAIL;
 }
 
        return FAIL;
 }
 
@@ -1179,6 +1159,8 @@ register int tty;
                        DEBUG(9,"Incoming baudrate is %d\n", linebaudrate);
                        return;
                }
                        DEBUG(9,"Incoming baudrate is %d\n", linebaudrate);
                        return;
                }
-       ASSERT(linebaudrate >= 0, "BAD SPEED", CNULL, speed);
+       if (linebaudrate < 0) {
+               syslog(LOG_ERR, "unrecognized speed: %d", linebaudrate);
+               cleanup(FAIL);
+       }
 }
 }
-