10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 5*549Smuffin 60Sstevel@tonic-gate /* 70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 90Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 100Sstevel@tonic-gate */ 110Sstevel@tonic-gate 12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 130Sstevel@tonic-gate 140Sstevel@tonic-gate #include "tip.h" 150Sstevel@tonic-gate 16*549Smuffin void cleanup(void); 17*549Smuffin void timeout(void); 180Sstevel@tonic-gate 190Sstevel@tonic-gate /* 200Sstevel@tonic-gate * Botch the interface to look like cu's 210Sstevel@tonic-gate */ 22*549Smuffin void 23*549Smuffin cumain(int argc, char *argv[]) 240Sstevel@tonic-gate { 25*549Smuffin int i; 260Sstevel@tonic-gate static char sbuf[12]; 270Sstevel@tonic-gate 280Sstevel@tonic-gate if (argc < 2) { 290Sstevel@tonic-gate usage: 30*549Smuffin (void) fprintf(stderr, 31*549Smuffin "usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n"); 320Sstevel@tonic-gate exit(8); 330Sstevel@tonic-gate } 340Sstevel@tonic-gate CU = DV = NOSTR; 350Sstevel@tonic-gate for (; argc > 1; argv++, argc--) { 360Sstevel@tonic-gate if (argv[1][0] != '-') 370Sstevel@tonic-gate PN = argv[1]; 380Sstevel@tonic-gate else if (argv[1][1] != '\0' && argv[1][2] != '\0') { 39*549Smuffin (void) fprintf(stderr, 40*549Smuffin "cu: extra characters after flag: %s\n", 41*549Smuffin argv[1]); 420Sstevel@tonic-gate goto usage; 430Sstevel@tonic-gate } else switch (argv[1][1]) { 440Sstevel@tonic-gate 450Sstevel@tonic-gate case 't': 460Sstevel@tonic-gate HW = 1, DU = -1; 470Sstevel@tonic-gate --argc; 480Sstevel@tonic-gate continue; 490Sstevel@tonic-gate 500Sstevel@tonic-gate case 'a': 510Sstevel@tonic-gate CU = argv[2]; ++argv; --argc; 520Sstevel@tonic-gate break; 530Sstevel@tonic-gate 540Sstevel@tonic-gate case 's': 550Sstevel@tonic-gate if (argc < 3) 560Sstevel@tonic-gate goto usage; 570Sstevel@tonic-gate if (speed(atoi(argv[2])) == 0) { 58*549Smuffin (void) fprintf(stderr, 59*549Smuffin "cu: unsupported speed %s\n", 60*549Smuffin argv[2]); 610Sstevel@tonic-gate exit(3); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate BR = atoi(argv[2]); ++argv; --argc; 640Sstevel@tonic-gate break; 650Sstevel@tonic-gate 660Sstevel@tonic-gate case 'l': 670Sstevel@tonic-gate DV = argv[2]; ++argv; --argc; 680Sstevel@tonic-gate break; 690Sstevel@tonic-gate 700Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4': 710Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9': 720Sstevel@tonic-gate if (CU) 730Sstevel@tonic-gate CU[strlen(CU)-1] = argv[1][1]; 740Sstevel@tonic-gate if (DV) 750Sstevel@tonic-gate DV[strlen(DV)-1] = argv[1][1]; 760Sstevel@tonic-gate break; 770Sstevel@tonic-gate 780Sstevel@tonic-gate default: 79*549Smuffin (void) fprintf(stderr, "cu: bad flag %s\n", argv[1]); 800Sstevel@tonic-gate goto usage; 810Sstevel@tonic-gate } 820Sstevel@tonic-gate } 83*549Smuffin (void) signal(SIGINT, (sig_handler_t)cleanup); 84*549Smuffin (void) signal(SIGQUIT, (sig_handler_t)cleanup); 85*549Smuffin (void) signal(SIGHUP, (sig_handler_t)cleanup); 86*549Smuffin (void) signal(SIGTERM, (sig_handler_t)cleanup); 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * The "cu" host name is used to define the 900Sstevel@tonic-gate * attributes of the generic dialer. 910Sstevel@tonic-gate */ 92*549Smuffin (void) sprintf(sbuf, "cu%d", BR); 930Sstevel@tonic-gate if ((i = hunt(sbuf)) == 0) { 94*549Smuffin (void) printf("all ports busy\n"); 950Sstevel@tonic-gate exit(3); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate if (i == -1) { 98*549Smuffin (void) printf("link down\n"); 990Sstevel@tonic-gate delock(uucplock); 1000Sstevel@tonic-gate exit(3); 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate setbuf(stdout, NULL); 1030Sstevel@tonic-gate loginit(); 1040Sstevel@tonic-gate gid = getgid(); 1050Sstevel@tonic-gate egid = getegid(); 1060Sstevel@tonic-gate uid = getuid(); 1070Sstevel@tonic-gate euid = geteuid(); 1080Sstevel@tonic-gate userperm(); 1090Sstevel@tonic-gate vinit(); 1100Sstevel@tonic-gate setparity("none"); 1110Sstevel@tonic-gate boolean(value(VERBOSE)) = 0; 1120Sstevel@tonic-gate if (HW) 1130Sstevel@tonic-gate ttysetup(speed(BR)); 1140Sstevel@tonic-gate if (connect()) { 115*549Smuffin (void) printf("Connect failed\n"); 1160Sstevel@tonic-gate myperm(); 1170Sstevel@tonic-gate delock(uucplock); 1180Sstevel@tonic-gate exit(1); 1190Sstevel@tonic-gate } 1200Sstevel@tonic-gate if (!HW) 1210Sstevel@tonic-gate ttysetup(speed(BR)); 1220Sstevel@tonic-gate } 123