int main(int argc, char *argv[]) { char *System = NULL; int c, i; char *p; const char *q; char sbuf[12]; int cmdlineBR; int fcarg; setprogname(argv[0]); gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); if (strcmp(getprogname(), "cu") == 0) { cumode = 1; cumain(argc, argv); goto cucommon; } if (argc > 4) tipusage(); if (!isatty(0)) errx(EXIT_FAILURE, "must be interactive"); cmdlineBR = 0; while((c = getopt(argc, argv, "v0123456789")) != -1) { switch(c) { case 'v': vflag++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': cmdlineBR = cmdlineBR * 10 + (c - '0'); BR = cmdlineBR; break; default: warnx("%s, unknown option", argv[1]); break; } } argc -= optind; argv += optind; if (argc != 1) tipusage(); else System = argv[0]; if (System == NULL) goto notnumber; if (isalpha((unsigned char)*System)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(System) > sizeof PNbuf - 1) { errx(1, "phone number too long (max = %d bytes)", (int)sizeof(PNbuf) - 1); } (void)strlcpy(PNbuf, System, sizeof(PNbuf)); for (p = System; *p; p++) *p = '\0'; PN = PNbuf; (void)snprintf(sbuf, sizeof sbuf, "tip%d", (int)BR); System = sbuf; notnumber: (void)signal(SIGINT, cleanup); (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); if ((i = hunt(System)) == 0) { errx(3, "all ports busy"); } if (i == -1) { errx(3, "link down"); } setbuf(stdout, NULL); /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NULL) PH = path_phones; vinit(); /* init variables */ setparity("none"); /* set the parity table */ /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) { if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) { errx(3, "bad baud rate %d", (int)number(value(BAUDRATE))); } } if ((q = tip_connect()) != NULL) { errx(1, "\07%s\n[EOT]", q); } if (!HW) { if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) { errx(3, "bad baud rate %d", (int)number(value(BAUDRATE))); } } cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ /* * Direct connections with no carrier require using O_NONBLOCK on * open, but we don't want to keep O_NONBLOCK after open because it * will cause busy waits. */ if (DC && ((fcarg = fcntl(FD, F_GETFL, 0)) < 0 || fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) { err(1, "can't clear O_NONBLOCK"); } (void)tcgetattr(0, &defterm); term = defterm; term.c_lflag &= ~(ICANON|IEXTEN|ECHO); term.c_iflag &= ~(INPCK|ICRNL); term.c_oflag &= ~OPOST; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; defchars = term; term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = term.c_cc[VLNEXT] = _POSIX_VDISABLE; raw(); (void)pipe(attndes); (void)pipe(fildes); (void)pipe(repdes); (void)signal(SIGALRM, alrmtimeout); /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ (void)printf("%s", cumode ? "Connected\r\n" : "\07connected\r\n"); switch (pid = fork()) { default: tipin(); break; case 0: tipout(); break; case -1: err(1, "can't fork"); } /*NOTREACHED*/ exit(0); /* XXX: pacify gcc */ }
int main(int argc, char *argv[]) { char *sys = NOSTR, sbuf[12], *p; int i; /* XXX preserve previous braindamaged behavior */ setboolean(value(DC), TRUE); gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); if (equal(__progname, "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } if (argc > 4) { fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); exit(1); } if (!isatty(0)) { fprintf(stderr, "%s: must be interactive\n", __progname); exit(1); } for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') sys = argv[1]; else switch (argv[1][1]) { case 'v': vflag++; break; case 'n': noesc++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: fprintf(stderr, "%s: %s, unknown option\n", __progname, argv[1]); break; } } if (sys == NOSTR) goto notnumber; if (isalpha(*sys)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(sys) > sizeof PNbuf - 1) { fprintf(stderr, "%s: phone number too long (max = %d bytes)\n", __progname, (int)sizeof(PNbuf) - 1); exit(1); } strlcpy(PNbuf, sys, sizeof PNbuf - 1); for (p = sys; *p; p++) *p = '\0'; PN = PNbuf; (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); sys = sbuf; notnumber: (void)signal(SIGINT, cleanup); (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); (void)signal(SIGCHLD, SIG_DFL); if ((i = hunt(sys)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { printf("link down\n"); (void)uu_unlock(uucplock); exit(3); } setbuf(stdout, NULL); loginit(); /* * Now that we have the logfile and the ACU open * return to the real uid and gid. These things will * be closed on exit. Swap real and effective uid's * so we can get the original permissions back * for removing the uucp lock. */ user_uid(); /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NOSTR) PH = _PATH_PHONES; vinit(); /* init variables */ setparity("none"); /* set the parity table */ /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW && ttysetup(number(value(BAUDRATE)))) { fprintf(stderr, "%s: bad baud rate %ld\n", __progname, number(value(BAUDRATE))); daemon_uid(); (void)uu_unlock(uucplock); exit(3); } if ((p = con())) { printf("\07%s\n[EOT]\n", p); daemon_uid(); (void)uu_unlock(uucplock); exit(1); } if (!HW && ttysetup(number(value(BAUDRATE)))) { fprintf(stderr, "%s: bad baud rate %ld\n", __progname, number(value(BAUDRATE))); daemon_uid(); (void)uu_unlock(uucplock); exit(3); } cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ i = fcntl(FD, F_GETFL); if (i == -1) { perror("fcntl"); cleanup(0); } i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK); if (i == -1) { perror("fcntl"); cleanup(0); } tcgetattr(0, &defterm); gotdefterm = 1; term = defterm; term.c_lflag &= ~(ICANON|IEXTEN|ECHO); term.c_iflag &= ~(INPCK|ICRNL); term.c_oflag &= ~OPOST; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; defchars = term; term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = term.c_cc[VLNEXT] = _POSIX_VDISABLE; raw(); pipe(fildes); pipe(repdes); (void)signal(SIGALRM, timeout); if (value(LINEDISC) != TTYDISC) { int ld = (int)(intptr_t)value(LINEDISC); ioctl(FD, TIOCSETD, &ld); } /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ printf(cumode ? "Connected\r\n" : "\07connected\r\n"); tipin_pid = getpid(); if ((tipout_pid = fork())) tipin(); else tipout(); /*NOTREACHED*/ exit(0); }
int main(int argc, char *argv[]) { char *system = NOSTR; int i; char *p; char sbuf[15]; gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); if (equal(sname(argv[0]), "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } if (argc > 4) { (void) fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); return (1); } if (!isatty(0)) { (void) fprintf(stderr, "tip: must be interactive\n"); return (1); } for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') system = argv[1]; else switch (argv[1][1]) { case 'v': vflag++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: (void) fprintf(stderr, "tip: %s, unknown option\n", argv[1]); break; } } (void) setlocale(LC_CTYPE, ""); if (system == NOSTR) goto notnumber; for (p = system; *p; p++) if (isalpha(*p)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(system) > sizeof (PNbuf) - 1) { (void) fprintf(stderr, "tip: phone number too long (max = %d bytes)\n", sizeof (PNbuf) - 1); return (1); } (void) strncpy(PNbuf, system, sizeof (PNbuf) - 1); for (p = system; *p; p++) *p = '\0'; PN = PNbuf; (void) snprintf(sbuf, sizeof (sbuf), "tip%d", BR); system = sbuf; notnumber: (void) signal(SIGINT, (sig_handler_t)cleanup); (void) signal(SIGQUIT, (sig_handler_t)cleanup); (void) signal(SIGHUP, (sig_handler_t)cleanup); (void) signal(SIGTERM, (sig_handler_t)cleanup); if ((i = hunt(system)) == 0) { (void) printf("all ports busy\n"); return (3); } if (i == -1) { (void) printf("link down\n"); delock(uucplock); return (3); } setbuf(stdout, NULL); loginit(); /* * Now that we have the logfile and the ACU open * return to the real uid and gid. These things will * be closed on exit. The saved-setuid uid and gid * allows us to get the original setuid permissions back * for removing the uucp lock. */ userperm(); /* * Kludge, there's no easy way to get the initialization * in the right order, so force it here. * Do the open here, before we change back to real uid. * We will check whether the open succeeded later, when * (and if) we actually go to use the file. */ if ((PH = getenv("PHONES")) == NOSTR) { myperm(); PH = "/etc/phones"; } phfd = fopen(PH, "r"); userperm(); vinit(); /* init variables */ setparity("none"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == NULL) { (void) printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); myperm(); delock(uucplock); return (3); } /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) ttysetup(i); if (p = connect()) { (void) printf("\07%s\n[EOT]\n", p); myperm(); delock(uucplock); return (1); } /* * Always setup the tty again here in case hardware flow * control was selected, which can only be set after the * connection is made, or in case this is not a hardwired * modem (rare these days) that likewise can only be setup * after the connection is made. */ ttysetup(i); cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ (void) ioctl(0, TCGETS, (char *)&defarg); arg = defarg; /* turn off input processing */ arg.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN); arg.c_cc[VMIN] = 1; arg.c_cc[VTIME] = 0; arg.c_iflag &= ~(INPCK|IXON|IXOFF|ICRNL); arg.c_oflag = 0; /* turn off all output processing */ /* handle tandem mode in case was set in remote file */ if (boolean(value(TAND))) tandem("on"); else tandem("off"); raw(); (void) pipe(fildes); (void) pipe(repdes); (void) signal(SIGALRM, (sig_handler_t)timeout); /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ if (CM != NOSTR) { (void) sleep(2); /* let line settle */ parwrite(FD, (unsigned char *)CM, strlen(CM)); } (void) printf(cumode ? "Connected\r\n" : "\07connected\r\n"); (void) signal(SIGCHLD, (sig_handler_t)deadkid); if (pid = fork()) tipin(); else tipout(); /*NOTREACHED*/ }
int main(int argc, char *argv[]) { char *system = NULL; int i; char *p; char sbuf[12]; gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); #if INCLUDE_CU_INTERFACE if (equal(sname(argv[0]), "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } #endif /* INCLUDE_CU_INTERFACE */ if (argc > 4) usage(); if (!isatty(0)) errx(1, "must be interactive"); for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') system = argv[1]; else switch (argv[1][1]) { case 'v': vflag++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: warnx("%s, unknown option", argv[1]); break; } } if (system == NULL) goto notnumber; if (isalpha(*system)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(system) > sizeof(PNbuf) - 1) errx(1, "phone number too long (max = %zd bytes)", sizeof PNbuf - 1); strncpy(PNbuf, system, sizeof(PNbuf) - 1); for (p = system; *p; p++) *p = '\0'; PN = PNbuf; (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); system = sbuf; notnumber: (void)signal(SIGINT, cleanup); (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); (void)signal(SIGUSR1, tipdone); if ((i = hunt(system)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { printf("link down\n"); (void)uu_unlock(uucplock); exit(3); } setbuf(stdout, NULL); loginit(); /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NULL) PH = _PATH_PHONES; vinit(); /* init variables */ setparity("even"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == 0) { printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); (void)uu_unlock(uucplock); exit(3); } /* * Now that we have the logfile and the ACU open * return to the real uid and gid. These things will * be closed on exit. Swap real and effective uid's * so we can get the original permissions back * for removing the uucp lock. */ user_uid(); /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) ttysetup(i); if ((p = connect())) { printf("\07%s\n[EOT]\n", p); daemon_uid(); (void)uu_unlock(uucplock); exit(1); } if (!HW) ttysetup(i); cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ #if HAVE_TERMIOS tcgetattr (0, &otermios); ctermios = otermios; #ifndef _POSIX_SOURCE ctermios.c_iflag = (IMAXBEL|IXANY|ISTRIP|IXON|BRKINT); ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOCTL|ECHOE|ECHOKE); #else ctermios.c_iflag = (ISTRIP|IXON|BRKINT); ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOE); #endif ctermios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); ctermios.c_cc[VINTR] = ctermios.c_cc[VQUIT] = -1; ctermios.c_cc[VSUSP] = ctermios.c_cc[VDSUSP] = ctermios.c_cc[VDISCARD] = ctermios.c_cc[VLNEXT] = -1; #else /* HAVE_TERMIOS */ ioctl(0, TIOCGETP, (char *)&defarg); ioctl(0, TIOCGETC, (char *)&defchars); ioctl(0, TIOCGLTC, (char *)&deflchars); ioctl(0, TIOCGETD, (char *)&odisc); arg = defarg; arg.sg_flags = ANYP | CBREAK; tchars = defchars; tchars.t_intrc = tchars.t_quitc = -1; ltchars = deflchars; ltchars.t_suspc = ltchars.t_dsuspc = ltchars.t_flushc = ltchars.t_lnextc = -1; #endif /* HAVE_TERMIOS */ raw(); pipe(fildes); pipe(repdes); (void)signal(SIGALRM, timeoutfunc); /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ printf(cumode ? "Connected\r\n" : "\07connected\r\n"); if (LI != NULL && tiplink (LI, 0) != 0) { tipabort ("login failed"); } if ((pid = fork())) tipin(); else tipout(); /*NOTREACHED*/ }