[BACK]Return to cu.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tip

Annotation of src/usr.bin/tip/cu.c, Revision 1.16

1.16    ! otto        1: /*     $OpenBSD: cu.c,v 1.15 2004/05/26 18:17:59 deraadt Exp $ */
1.3       millert     2: /*     $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $       */
1.1       deraadt     3:
                      4: /*
                      5:  * Copyright (c) 1983, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.14      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #ifndef lint
                     34: #if 0
                     35: static char sccsid[] = "@(#)cu.c       8.1 (Berkeley) 6/6/93";
                     36: #endif
1.16    ! otto       37: static const char rcsid[] = "$OpenBSD: cu.c,v 1.15 2004/05/26 18:17:59 deraadt Exp $";
1.1       deraadt    38: #endif /* not lint */
                     39:
                     40: #include "tip.h"
                     41:
                     42: void   cleanup();
1.6       millert    43: void   cuusage();
1.1       deraadt    44:
                     45: /*
                     46:  * Botch the interface to look like cu's
                     47:  */
1.4       deraadt    48: void
1.1       deraadt    49: cumain(argc, argv)
1.4       deraadt    50:        int argc;
1.1       deraadt    51:        char *argv[];
                     52: {
1.11      miod       53:        int ch, i, parity;
1.6       millert    54:        long l;
                     55:        char *cp;
1.1       deraadt    56:        static char sbuf[12];
                     57:
1.6       millert    58:        if (argc < 2)
                     59:                cuusage();
1.1       deraadt    60:        CU = DV = NOSTR;
                     61:        BR = DEFBR;
1.11      miod       62:        parity = 0;     /* none */
1.6       millert    63:        while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
                     64:                switch(ch) {
1.1       deraadt    65:                case 'a':
1.6       millert    66:                        CU = optarg;
                     67:                        break;
                     68:                case 'l':
1.8       deraadt    69:                        if (DV != NULL) {
                     70:                                fprintf(stderr,
                     71:                                    "%s: cannot specificy multiple -l options\n",
                     72:                                    __progname);
                     73:                                exit(3);
                     74:                        }
                     75:                        if (strchr(optarg, '/'))
                     76:                                DV = optarg;
                     77:                        else
                     78:                                asprintf(&DV, "/dev/%s", optarg);
1.1       deraadt    79:                        break;
                     80:                case 's':
1.6       millert    81:                        l = strtol(optarg, &cp, 10);
1.13      millert    82:                        if (*cp != '\0' || l < 0 || l >= INT_MAX) {
1.6       millert    83:                                fprintf(stderr, "%s: unsupported speed %s\n",
                     84:                                    __progname, optarg);
1.1       deraadt    85:                                exit(3);
                     86:                        }
1.6       millert    87:                        BR = (int)l;
                     88:                        break;
                     89:                case 'h':
1.9       millert    90:                        setboolean(value(LECHO), TRUE);
1.6       millert    91:                        HD = TRUE;
                     92:                        break;
                     93:                case 't':
                     94:                        HW = 1, DU = -1;
1.1       deraadt    95:                        break;
1.6       millert    96:                case 'o':
1.11      miod       97:                        if (parity != 0)
                     98:                                parity = 0;     /* -e -o */
                     99:                        else
                    100:                                parity = 1;     /* odd */
1.6       millert   101:                        break;
                    102:                case 'e':
1.11      miod      103:                        if (parity != 0)
                    104:                                parity = 0;     /* -o -e */
                    105:                        else
                    106:                                parity = -1;    /* even */
1.1       deraadt   107:                        break;
                    108:                case '0': case '1': case '2': case '3': case '4':
                    109:                case '5': case '6': case '7': case '8': case '9':
                    110:                        if (CU)
1.6       millert   111:                                CU[strlen(CU)-1] = ch;
1.1       deraadt   112:                        if (DV)
1.6       millert   113:                                DV[strlen(DV)-1] = ch;
1.1       deraadt   114:                        break;
                    115:                default:
1.10      pvalchev  116:                        cuusage();
1.1       deraadt   117:                        break;
                    118:                }
                    119:        }
1.6       millert   120:        argc -= optind;
                    121:        argv += optind;
                    122:
                    123:        switch (argc) {
                    124:        case 1:
                    125:                PN = argv[0];
                    126:                break;
                    127:        case 0:
                    128:                break;
                    129:        default:
                    130:                cuusage();
                    131:                break;
                    132:        }
                    133:
1.1       deraadt   134:        signal(SIGINT, cleanup);
                    135:        signal(SIGQUIT, cleanup);
                    136:        signal(SIGHUP, cleanup);
                    137:        signal(SIGTERM, cleanup);
1.16    ! otto      138:        signal(SIGCHLD, SIG_DFL);
1.1       deraadt   139:
                    140:        /*
                    141:         * The "cu" host name is used to define the
                    142:         * attributes of the generic dialer.
                    143:         */
1.4       deraadt   144:        (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
1.1       deraadt   145:        if ((i = hunt(sbuf)) == 0) {
                    146:                printf("all ports busy\n");
                    147:                exit(3);
                    148:        }
                    149:        if (i == -1) {
                    150:                printf("link down\n");
                    151:                (void)uu_unlock(uucplock);
                    152:                exit(3);
                    153:        }
                    154:        setbuf(stdout, NULL);
                    155:        loginit();
                    156:        user_uid();
                    157:        vinit();
1.11      miod      158:        switch (parity) {
                    159:        case -1:
                    160:                setparity("even");
                    161:                break;
                    162:        case 1:
                    163:                setparity("odd");
                    164:                break;
                    165:        default:
                    166:                setparity("none");
                    167:                break;
                    168:        }
1.9       millert   169:        setboolean(value(VERBOSE), FALSE);
1.13      millert   170:        if (HW && ttysetup(BR)) {
                    171:                fprintf(stderr, "%s: unsupported speed %ld\n",
                    172:                    __progname, BR);
                    173:                daemon_uid();
                    174:                (void)uu_unlock(uucplock);
                    175:                exit(3);
                    176:        }
1.1       deraadt   177:        if (connect()) {
                    178:                printf("Connect failed\n");
                    179:                daemon_uid();
                    180:                (void)uu_unlock(uucplock);
                    181:                exit(1);
                    182:        }
1.13      millert   183:        if (!HW && ttysetup(BR)) {
                    184:                fprintf(stderr, "%s: unsupported speed %ld\n",
                    185:                    __progname, BR);
                    186:                daemon_uid();
                    187:                (void)uu_unlock(uucplock);
                    188:                exit(3);
                    189:        }
1.6       millert   190: }
                    191:
                    192: void
                    193: cuusage()
                    194: {
                    195:        fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] "
                    196:            "[phone-number]\n");
                    197:        exit(8);
1.1       deraadt   198: }