1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1995 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /* 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate * uucp file transfer program: 36*7c478bd9Sstevel@tonic-gate * to place a call to a remote machine, login, and 37*7c478bd9Sstevel@tonic-gate * copy files between the two machines. 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * Added check to limit the total number of uucicos as defined 42*7c478bd9Sstevel@tonic-gate * in the Limits file. 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * Added -f flag to "force execution", ignoring the limit on the 45*7c478bd9Sstevel@tonic-gate * number of uucicos. This will be used when invoking uucico from 46*7c478bd9Sstevel@tonic-gate * Uutry. 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #include "uucp.h" 50*7c478bd9Sstevel@tonic-gate #include "log.h" 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #ifndef V7 53*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 54*7c478bd9Sstevel@tonic-gate #endif /* V7 */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #ifdef TLI 57*7c478bd9Sstevel@tonic-gate #include <sys/tiuser.h> 58*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate jmp_buf Sjbuf; 61*7c478bd9Sstevel@tonic-gate extern unsigned msgtime; 62*7c478bd9Sstevel@tonic-gate char uuxqtarg[MAXBASENAME] = {'\0'}; 63*7c478bd9Sstevel@tonic-gate int uuxqtflag = 0; 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate extern int (*Setup)(), (*Teardown)(); /* defined in interface.c */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate #define USAGE "Usage: %s [-x NUM] [-r [0|1]] -s SYSTEM -u USERID -d SPOOL -i INTERFACE [-f]\n" 68*7c478bd9Sstevel@tonic-gate extern void closedem(); 69*7c478bd9Sstevel@tonic-gate void cleanup(), cleanTM(); 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate extern int sysaccess(), guinfo(), eaccess(), countProcs(), interface(), 72*7c478bd9Sstevel@tonic-gate savline(), omsg(), restline(), imsg(), callok(), gnxseq(), 73*7c478bd9Sstevel@tonic-gate cmtseq(), conn(), startup(), cntrl(); 74*7c478bd9Sstevel@tonic-gate extern void setuucp(), fixline(), gename(), ulkseq(), pfEndfile(); 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS 77*7c478bd9Sstevel@tonic-gate static void checkrmt(); /* See if we want to talk to remote. */ 78*7c478bd9Sstevel@tonic-gate #endif /* NOSTRANGERS */ 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate extern char *Mytype; 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate main(argc, argv, envp) 83*7c478bd9Sstevel@tonic-gate char *argv[]; 84*7c478bd9Sstevel@tonic-gate char **envp; 85*7c478bd9Sstevel@tonic-gate { 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate extern void intrEXIT(), onintr(), timeout(); 88*7c478bd9Sstevel@tonic-gate static char *pskip(); 89*7c478bd9Sstevel@tonic-gate extern void setservice(); 90*7c478bd9Sstevel@tonic-gate #ifndef ATTSVR3 91*7c478bd9Sstevel@tonic-gate void setTZ(); 92*7c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */ 93*7c478bd9Sstevel@tonic-gate int ret, seq, exitcode; 94*7c478bd9Sstevel@tonic-gate char file[NAMESIZE]; 95*7c478bd9Sstevel@tonic-gate char msg[BUFSIZ], *p, *q; 96*7c478bd9Sstevel@tonic-gate char xflag[6]; /* -xN N is single digit */ 97*7c478bd9Sstevel@tonic-gate char *ttyn; 98*7c478bd9Sstevel@tonic-gate char *iface; /* interface name */ 99*7c478bd9Sstevel@tonic-gate char cb[128]; 100*7c478bd9Sstevel@tonic-gate time_t ts, tconv; 101*7c478bd9Sstevel@tonic-gate char lockname[MAXFULLNAME]; 102*7c478bd9Sstevel@tonic-gate struct limits limitval; 103*7c478bd9Sstevel@tonic-gate int maxnumb; 104*7c478bd9Sstevel@tonic-gate int force = 0; /* set to force execution, ignoring uucico limit */ 105*7c478bd9Sstevel@tonic-gate char gradedir[2*NAMESIZE]; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate /* Set locale environment variables local definitions */ 108*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 109*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 110*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 111*7c478bd9Sstevel@tonic-gate #endif 112*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate Ulimit = ulimit(1,0L); 115*7c478bd9Sstevel@tonic-gate Uid = getuid(); 116*7c478bd9Sstevel@tonic-gate Euid = geteuid(); /* this should be UUCPUID */ 117*7c478bd9Sstevel@tonic-gate if (Uid == 0) 118*7c478bd9Sstevel@tonic-gate setuid(UUCPUID); 119*7c478bd9Sstevel@tonic-gate Env = envp; 120*7c478bd9Sstevel@tonic-gate Role = SLAVE; 121*7c478bd9Sstevel@tonic-gate strcpy(Logfile, LOGCICO); 122*7c478bd9Sstevel@tonic-gate *Rmtname = NULLCHAR; 123*7c478bd9Sstevel@tonic-gate Ifn = Ofn = -1; /* must be set before signal handlers */ 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate closedem(); 126*7c478bd9Sstevel@tonic-gate time(&Nstat.t_qtime); 127*7c478bd9Sstevel@tonic-gate tconv = Nstat.t_start = Nstat.t_qtime; 128*7c478bd9Sstevel@tonic-gate strcpy(Progname, "uucico"); 129*7c478bd9Sstevel@tonic-gate setservice(Progname); 130*7c478bd9Sstevel@tonic-gate ret = sysaccess(EACCESS_SYSTEMS); 131*7c478bd9Sstevel@tonic-gate ASSERT(ret == 0, Ct_OPEN, "Systems", ret); 132*7c478bd9Sstevel@tonic-gate ret = sysaccess(EACCESS_DEVICES); 133*7c478bd9Sstevel@tonic-gate ASSERT(ret == 0, Ct_OPEN, "Devices", ret); 134*7c478bd9Sstevel@tonic-gate ret = sysaccess(EACCESS_DIALERS); 135*7c478bd9Sstevel@tonic-gate ASSERT(ret == 0, Ct_OPEN, "Dialers", ret); 136*7c478bd9Sstevel@tonic-gate Pchar = 'C'; 137*7c478bd9Sstevel@tonic-gate (void) signal(SIGILL, intrEXIT); 138*7c478bd9Sstevel@tonic-gate (void) signal(SIGTRAP, intrEXIT); 139*7c478bd9Sstevel@tonic-gate (void) signal(SIGIOT, intrEXIT); 140*7c478bd9Sstevel@tonic-gate (void) signal(SIGEMT, intrEXIT); 141*7c478bd9Sstevel@tonic-gate (void) signal(SIGFPE, intrEXIT); 142*7c478bd9Sstevel@tonic-gate (void) signal(SIGBUS, intrEXIT); 143*7c478bd9Sstevel@tonic-gate (void) signal(SIGSEGV, intrEXIT); 144*7c478bd9Sstevel@tonic-gate (void) signal(SIGSYS, intrEXIT); 145*7c478bd9Sstevel@tonic-gate if (signal(SIGPIPE, SIG_IGN) != SIG_IGN) /* This for sockets */ 146*7c478bd9Sstevel@tonic-gate (void) signal(SIGPIPE, intrEXIT); 147*7c478bd9Sstevel@tonic-gate (void) signal(SIGINT, onintr); 148*7c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, onintr); 149*7c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, onintr); 150*7c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, onintr); 151*7c478bd9Sstevel@tonic-gate #ifdef SIGUSR1 152*7c478bd9Sstevel@tonic-gate (void) signal(SIGUSR1, SIG_IGN); 153*7c478bd9Sstevel@tonic-gate #endif 154*7c478bd9Sstevel@tonic-gate #ifdef SIGUSR2 155*7c478bd9Sstevel@tonic-gate (void) signal(SIGUSR2, SIG_IGN); 156*7c478bd9Sstevel@tonic-gate #endif 157*7c478bd9Sstevel@tonic-gate #ifdef BSD4_2 158*7c478bd9Sstevel@tonic-gate (void) sigsetmask(sigblock(0) & ~(1 << (SIGALRM - 1))); 159*7c478bd9Sstevel@tonic-gate #endif /*BSD4_2*/ 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate pfInit(); 162*7c478bd9Sstevel@tonic-gate scInit("xfer"); 163*7c478bd9Sstevel@tonic-gate ret = guinfo(Euid, User); 164*7c478bd9Sstevel@tonic-gate ASSERT(ret == 0, "BAD UID ", "", ret); 165*7c478bd9Sstevel@tonic-gate strncpy(Uucp, User, NAMESIZE); 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate setuucp(User); 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate *xflag = NULLCHAR; 170*7c478bd9Sstevel@tonic-gate iface = "UNIX"; 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate while ((ret = getopt(argc, argv, "fd:c:r:s:x:u:i:")) != EOF) { 173*7c478bd9Sstevel@tonic-gate switch (ret) { 174*7c478bd9Sstevel@tonic-gate case 'd': 175*7c478bd9Sstevel@tonic-gate if ( eaccess(optarg, 01) != 0 ) { 176*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot" 177*7c478bd9Sstevel@tonic-gate " access spool directory %s\n"), 178*7c478bd9Sstevel@tonic-gate Progname, optarg); 179*7c478bd9Sstevel@tonic-gate exit(1); 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate Spool = optarg; 182*7c478bd9Sstevel@tonic-gate break; 183*7c478bd9Sstevel@tonic-gate case 'c': 184*7c478bd9Sstevel@tonic-gate Mytype = optarg; 185*7c478bd9Sstevel@tonic-gate break; 186*7c478bd9Sstevel@tonic-gate case 'f': 187*7c478bd9Sstevel@tonic-gate ++force; 188*7c478bd9Sstevel@tonic-gate break; 189*7c478bd9Sstevel@tonic-gate case 'r': 190*7c478bd9Sstevel@tonic-gate if ( (Role = atoi(optarg)) != MASTER && Role != SLAVE ) { 191*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: bad value" 192*7c478bd9Sstevel@tonic-gate " '%s' for -r argument\n" USAGE), 193*7c478bd9Sstevel@tonic-gate Progname, optarg, Progname); 194*7c478bd9Sstevel@tonic-gate exit(1); 195*7c478bd9Sstevel@tonic-gate } 196*7c478bd9Sstevel@tonic-gate break; 197*7c478bd9Sstevel@tonic-gate case 's': 198*7c478bd9Sstevel@tonic-gate strncpy(Rmtname, optarg, MAXFULLNAME-1); 199*7c478bd9Sstevel@tonic-gate if (versys(Rmtname)) { 200*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 201*7c478bd9Sstevel@tonic-gate gettext("%s: %s not in Systems file\n"), 202*7c478bd9Sstevel@tonic-gate Progname, optarg); 203*7c478bd9Sstevel@tonic-gate cleanup(101); 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate /* set args for possible xuuxqt call */ 206*7c478bd9Sstevel@tonic-gate strcpy(uuxqtarg, Rmtname); 207*7c478bd9Sstevel@tonic-gate /* if versys put a longer name in, truncate it again */ 208*7c478bd9Sstevel@tonic-gate Rmtname[MAXBASENAME] = '\0'; 209*7c478bd9Sstevel@tonic-gate break; 210*7c478bd9Sstevel@tonic-gate case 'x': 211*7c478bd9Sstevel@tonic-gate Debug = atoi(optarg); 212*7c478bd9Sstevel@tonic-gate if (Debug <= 0) 213*7c478bd9Sstevel@tonic-gate Debug = 1; 214*7c478bd9Sstevel@tonic-gate if (Debug > 9) 215*7c478bd9Sstevel@tonic-gate Debug = 9; 216*7c478bd9Sstevel@tonic-gate (void) sprintf(xflag, "-x%d", Debug); 217*7c478bd9Sstevel@tonic-gate break; 218*7c478bd9Sstevel@tonic-gate case 'u': 219*7c478bd9Sstevel@tonic-gate DEBUG(4, "Loginuser %s specified\n", optarg); 220*7c478bd9Sstevel@tonic-gate strncpy(Loginuser, optarg, NAMESIZE); 221*7c478bd9Sstevel@tonic-gate Loginuser[NAMESIZE - 1] = NULLCHAR; 222*7c478bd9Sstevel@tonic-gate break; 223*7c478bd9Sstevel@tonic-gate case 'i': 224*7c478bd9Sstevel@tonic-gate /* interface type */ 225*7c478bd9Sstevel@tonic-gate iface = optarg; 226*7c478bd9Sstevel@tonic-gate break; 227*7c478bd9Sstevel@tonic-gate default: 228*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(USAGE), Progname); 229*7c478bd9Sstevel@tonic-gate exit(1); 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate if (Role == MASTER || *Loginuser == NULLCHAR) { 234*7c478bd9Sstevel@tonic-gate ret = guinfo(Uid, Loginuser); 235*7c478bd9Sstevel@tonic-gate ASSERT(ret == 0, "BAD LOGIN_UID ", "", ret); 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate /* limit the total number of uucicos */ 239*7c478bd9Sstevel@tonic-gate if (force) { 240*7c478bd9Sstevel@tonic-gate DEBUG(4, "force flag set (ignoring uucico limit)\n%s", ""); 241*7c478bd9Sstevel@tonic-gate } else if (scanlimit("uucico", &limitval) == FAIL) { 242*7c478bd9Sstevel@tonic-gate DEBUG(1, "No limits for uucico in %s\n", LIMITS); 243*7c478bd9Sstevel@tonic-gate } else { 244*7c478bd9Sstevel@tonic-gate maxnumb = limitval.totalmax; 245*7c478bd9Sstevel@tonic-gate if (maxnumb < 0) { 246*7c478bd9Sstevel@tonic-gate DEBUG(4, "Non-positive limit for uucico in %s\n", LIMITS); 247*7c478bd9Sstevel@tonic-gate DEBUG(1, "No limits for uucico\n%s", ""); 248*7c478bd9Sstevel@tonic-gate } else { 249*7c478bd9Sstevel@tonic-gate DEBUG(4, "Uucico limit %d -- ", maxnumb); 250*7c478bd9Sstevel@tonic-gate (void) sprintf(lockname, "%s.", LOCKPRE); 251*7c478bd9Sstevel@tonic-gate if (countProcs(lockname, (maxnumb-1)) == FALSE) { 252*7c478bd9Sstevel@tonic-gate DEBUG(4, "exiting\n%s", ""); 253*7c478bd9Sstevel@tonic-gate cleanup(101); 254*7c478bd9Sstevel@tonic-gate } 255*7c478bd9Sstevel@tonic-gate DEBUG(4, "continuing\n%s", ""); 256*7c478bd9Sstevel@tonic-gate } 257*7c478bd9Sstevel@tonic-gate } 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate pfStrtConn((Role == MASTER) ? 'M' : 'S'); 260*7c478bd9Sstevel@tonic-gate if (Role == MASTER) { 261*7c478bd9Sstevel@tonic-gate if (*Rmtname == NULLCHAR) { 262*7c478bd9Sstevel@tonic-gate DEBUG(5, "No -s specified\n%s" , ""); 263*7c478bd9Sstevel@tonic-gate cleanup(101); 264*7c478bd9Sstevel@tonic-gate } 265*7c478bd9Sstevel@tonic-gate /* get Myname - it depends on who I'm calling--Rmtname */ 266*7c478bd9Sstevel@tonic-gate (void) mchFind(Rmtname); 267*7c478bd9Sstevel@tonic-gate myName(Myname); 268*7c478bd9Sstevel@tonic-gate if (EQUALSN(Rmtname, Myname, MAXBASENAME)) { 269*7c478bd9Sstevel@tonic-gate DEBUG(5, "This system specified: -sMyname: %s, ", Myname); 270*7c478bd9Sstevel@tonic-gate cleanup(101); 271*7c478bd9Sstevel@tonic-gate } 272*7c478bd9Sstevel@tonic-gate acInit("xfer"); 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate ASSERT(chdir(Spool) == 0, Ct_CHDIR, Spool, errno); 276*7c478bd9Sstevel@tonic-gate strcpy(Wrkdir, Spool); 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate scReqsys((Role == MASTER) ? Myname : Rmtname); /* log requestor system */ 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate if (Role == SLAVE) { 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate #ifndef ATTSVR3 283*7c478bd9Sstevel@tonic-gate setTZ(); 284*7c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */ 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate if (freopen(RMTDEBUG, "a", stderr) == 0) { 287*7c478bd9Sstevel@tonic-gate errent(Ct_OPEN, RMTDEBUG, errno, __FILE__, __LINE__); 288*7c478bd9Sstevel@tonic-gate freopen("/dev/null", "w", stderr); 289*7c478bd9Sstevel@tonic-gate } 290*7c478bd9Sstevel@tonic-gate if ( interface(iface) ) { 291*7c478bd9Sstevel@tonic-gate (void)fprintf(stderr, 292*7c478bd9Sstevel@tonic-gate "%s: invalid interface %s\n", Progname, iface); 293*7c478bd9Sstevel@tonic-gate cleanup(101); 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate /*master setup will be called from processdev()*/ 296*7c478bd9Sstevel@tonic-gate if ( (*Setup)( Role, &Ifn, &Ofn ) ) { 297*7c478bd9Sstevel@tonic-gate DEBUG(5, "SLAVE Setup failed%s", ""); 298*7c478bd9Sstevel@tonic-gate cleanup(101); 299*7c478bd9Sstevel@tonic-gate } 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate /* 302*7c478bd9Sstevel@tonic-gate * initial handshake 303*7c478bd9Sstevel@tonic-gate */ 304*7c478bd9Sstevel@tonic-gate (void) savline(); 305*7c478bd9Sstevel@tonic-gate fixline(Ifn, 0, D_ACU); 306*7c478bd9Sstevel@tonic-gate /* get MyName - use logFind to check PERMISSIONS file */ 307*7c478bd9Sstevel@tonic-gate (void) logFind(Loginuser, ""); 308*7c478bd9Sstevel@tonic-gate myName(Myname); 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate DEBUG(4,"cico.c: Myname - %s\n",Myname); 311*7c478bd9Sstevel@tonic-gate DEBUG(4,"cico.c: Loginuser - %s\n",Loginuser); 312*7c478bd9Sstevel@tonic-gate fflush(stderr); 313*7c478bd9Sstevel@tonic-gate Nstat.t_scall = times(&Nstat.t_tga); 314*7c478bd9Sstevel@tonic-gate (void) sprintf(msg, "here=%s", Myname); 315*7c478bd9Sstevel@tonic-gate omsg('S', msg, Ofn); 316*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, timeout); 317*7c478bd9Sstevel@tonic-gate (void) alarm(msgtime); /* give slow machines a second chance */ 318*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate /* 321*7c478bd9Sstevel@tonic-gate * timed out 322*7c478bd9Sstevel@tonic-gate */ 323*7c478bd9Sstevel@tonic-gate (void) restline(); 324*7c478bd9Sstevel@tonic-gate rmlock(CNULL); 325*7c478bd9Sstevel@tonic-gate exit(0); 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate for (;;) { 328*7c478bd9Sstevel@tonic-gate ret = imsg(msg, Ifn); 329*7c478bd9Sstevel@tonic-gate if (ret != 0) { 330*7c478bd9Sstevel@tonic-gate (void) alarm(0); 331*7c478bd9Sstevel@tonic-gate (void) restline(); 332*7c478bd9Sstevel@tonic-gate rmlock(CNULL); 333*7c478bd9Sstevel@tonic-gate exit(0); 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate if (msg[0] == 'S') 336*7c478bd9Sstevel@tonic-gate break; 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate Nstat.t_ecall = times(&Nstat.t_tga); 339*7c478bd9Sstevel@tonic-gate (void) alarm(0); 340*7c478bd9Sstevel@tonic-gate q = &msg[1]; 341*7c478bd9Sstevel@tonic-gate p = pskip(q); 342*7c478bd9Sstevel@tonic-gate strncpy(Rmtname, q, MAXBASENAME); 343*7c478bd9Sstevel@tonic-gate Rmtname[MAXBASENAME] = '\0'; 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate seq = 0; 346*7c478bd9Sstevel@tonic-gate while (p && *p == '-') { 347*7c478bd9Sstevel@tonic-gate q = pskip(p); 348*7c478bd9Sstevel@tonic-gate switch(*(++p)) { 349*7c478bd9Sstevel@tonic-gate case 'x': 350*7c478bd9Sstevel@tonic-gate Debug = atoi(++p); 351*7c478bd9Sstevel@tonic-gate if (Debug <= 0) 352*7c478bd9Sstevel@tonic-gate Debug = 1; 353*7c478bd9Sstevel@tonic-gate (void) sprintf(xflag, "-x%d", Debug); 354*7c478bd9Sstevel@tonic-gate break; 355*7c478bd9Sstevel@tonic-gate case 'Q': 356*7c478bd9Sstevel@tonic-gate seq = atoi(++p); 357*7c478bd9Sstevel@tonic-gate if (seq < 0) 358*7c478bd9Sstevel@tonic-gate seq = 0; 359*7c478bd9Sstevel@tonic-gate break; 360*7c478bd9Sstevel@tonic-gate #ifdef MAXGRADE 361*7c478bd9Sstevel@tonic-gate case 'v': /* version -- -vname=val or -vname */ 362*7c478bd9Sstevel@tonic-gate if (strncmp(++p, "grade=", 6) == 0 && 363*7c478bd9Sstevel@tonic-gate isalnum(p[6])) 364*7c478bd9Sstevel@tonic-gate MaxGrade = p[6]; 365*7c478bd9Sstevel@tonic-gate break; 366*7c478bd9Sstevel@tonic-gate #endif /* MAXGRADE */ 367*7c478bd9Sstevel@tonic-gate case 'R': 368*7c478bd9Sstevel@tonic-gate Restart++; 369*7c478bd9Sstevel@tonic-gate p++; 370*7c478bd9Sstevel@tonic-gate break; 371*7c478bd9Sstevel@tonic-gate case 'U': 372*7c478bd9Sstevel@tonic-gate SizeCheck++; 373*7c478bd9Sstevel@tonic-gate RemUlimit = strtol(++p, (char **) NULL,0); 374*7c478bd9Sstevel@tonic-gate break; 375*7c478bd9Sstevel@tonic-gate default: 376*7c478bd9Sstevel@tonic-gate break; 377*7c478bd9Sstevel@tonic-gate } 378*7c478bd9Sstevel@tonic-gate p = q; 379*7c478bd9Sstevel@tonic-gate } 380*7c478bd9Sstevel@tonic-gate DEBUG(4, "sys-%s\n", Rmtname); 381*7c478bd9Sstevel@tonic-gate if (strpbrk(Rmtname, Shchar) != NULL) { 382*7c478bd9Sstevel@tonic-gate DEBUG(4, "Bad remote system name '%s'\n", Rmtname); 383*7c478bd9Sstevel@tonic-gate logent(Rmtname, "BAD REMOTE SYSTEM NAME"); 384*7c478bd9Sstevel@tonic-gate omsg('R', "Bad remote system name", Ofn); 385*7c478bd9Sstevel@tonic-gate cleanup(101); 386*7c478bd9Sstevel@tonic-gate } 387*7c478bd9Sstevel@tonic-gate if (Restart) 388*7c478bd9Sstevel@tonic-gate CDEBUG(1,"Checkpoint Restart enabled\n%s", ""); 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS 391*7c478bd9Sstevel@tonic-gate checkrmt(); /* Do we know the remote system. */ 392*7c478bd9Sstevel@tonic-gate #else 393*7c478bd9Sstevel@tonic-gate (void) versys(Rmtname); /* in case the real name is longer */ 394*7c478bd9Sstevel@tonic-gate #endif /* NOSTRANGERS */ 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate (void) sprintf(lockname, "%ld", (long) getpid()); 397*7c478bd9Sstevel@tonic-gate if (umlock(LOCKPRE, lockname)) { 398*7c478bd9Sstevel@tonic-gate omsg('R', "LCK", Ofn); 399*7c478bd9Sstevel@tonic-gate cleanup(101); 400*7c478bd9Sstevel@tonic-gate } 401*7c478bd9Sstevel@tonic-gate 402*7c478bd9Sstevel@tonic-gate /* validate login using PERMISSIONS file */ 403*7c478bd9Sstevel@tonic-gate if (logFind(Loginuser, Rmtname) == FAIL) { 404*7c478bd9Sstevel@tonic-gate scWrite(); /* log security violation */ 405*7c478bd9Sstevel@tonic-gate Uerror = SS_BAD_LOG_MCH; 406*7c478bd9Sstevel@tonic-gate logent(UERRORTEXT, "FAILED"); 407*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_BAD_LOG_MCH, UERRORTEXT, 408*7c478bd9Sstevel@tonic-gate Retrytime); 409*7c478bd9Sstevel@tonic-gate omsg('R', "LOGIN", Ofn); 410*7c478bd9Sstevel@tonic-gate cleanup(101); 411*7c478bd9Sstevel@tonic-gate } 412*7c478bd9Sstevel@tonic-gate 413*7c478bd9Sstevel@tonic-gate ret = callBack(); 414*7c478bd9Sstevel@tonic-gate DEBUG(4,"return from callcheck: %s",ret ? "TRUE" : "FALSE"); 415*7c478bd9Sstevel@tonic-gate if (ret==TRUE) { 416*7c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); 417*7c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN); 418*7c478bd9Sstevel@tonic-gate omsg('R', "CB", Ofn); 419*7c478bd9Sstevel@tonic-gate logent("CALLBACK", "REQUIRED"); 420*7c478bd9Sstevel@tonic-gate /* 421*7c478bd9Sstevel@tonic-gate * set up for call back 422*7c478bd9Sstevel@tonic-gate */ 423*7c478bd9Sstevel@tonic-gate chremdir(Rmtname); 424*7c478bd9Sstevel@tonic-gate (void) sprintf(file, "%s/%c", Rmtname, D_QUEUE); 425*7c478bd9Sstevel@tonic-gate chremdir(file); 426*7c478bd9Sstevel@tonic-gate gename(CMDPRE, Rmtname, 'C', file); 427*7c478bd9Sstevel@tonic-gate (void) close(creat(file, CFILEMODE)); 428*7c478bd9Sstevel@tonic-gate if (callok(Rmtname) == SS_CALLBACK_LOOP) { 429*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_CALLBACK_LOOP, "CALL BACK - LOOP", Retrytime); 430*7c478bd9Sstevel@tonic-gate } else { 431*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_CALLBACK, "CALL BACK", Retrytime); 432*7c478bd9Sstevel@tonic-gate xuucico(Rmtname); 433*7c478bd9Sstevel@tonic-gate } 434*7c478bd9Sstevel@tonic-gate cleanup(101); 435*7c478bd9Sstevel@tonic-gate } 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate if (callok(Rmtname) == SS_SEQBAD) { 438*7c478bd9Sstevel@tonic-gate Uerror = SS_SEQBAD; 439*7c478bd9Sstevel@tonic-gate logent(UERRORTEXT, "PREVIOUS"); 440*7c478bd9Sstevel@tonic-gate omsg('R', "BADSEQ", Ofn); 441*7c478bd9Sstevel@tonic-gate cleanup(101); 442*7c478bd9Sstevel@tonic-gate } 443*7c478bd9Sstevel@tonic-gate 444*7c478bd9Sstevel@tonic-gate if (gnxseq(Rmtname) == seq) { 445*7c478bd9Sstevel@tonic-gate if (Restart) { 446*7c478bd9Sstevel@tonic-gate if (SizeCheck) 447*7c478bd9Sstevel@tonic-gate (void) sprintf (msg, "OK -R -U0x%lx %s", 448*7c478bd9Sstevel@tonic-gate Ulimit, xflag); 449*7c478bd9Sstevel@tonic-gate else 450*7c478bd9Sstevel@tonic-gate (void) sprintf (msg, "OK -R %s", xflag); 451*7c478bd9Sstevel@tonic-gate omsg('R', msg, Ofn); 452*7c478bd9Sstevel@tonic-gate } else 453*7c478bd9Sstevel@tonic-gate omsg('R', "OK", Ofn); 454*7c478bd9Sstevel@tonic-gate (void) cmtseq(); 455*7c478bd9Sstevel@tonic-gate } else { 456*7c478bd9Sstevel@tonic-gate Uerror = SS_SEQBAD; 457*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_SEQBAD, UERRORTEXT, Retrytime); 458*7c478bd9Sstevel@tonic-gate logent(UERRORTEXT, "HANDSHAKE FAILED"); 459*7c478bd9Sstevel@tonic-gate ulkseq(); 460*7c478bd9Sstevel@tonic-gate omsg('R', "BADSEQ", Ofn); 461*7c478bd9Sstevel@tonic-gate cleanup(101); 462*7c478bd9Sstevel@tonic-gate } 463*7c478bd9Sstevel@tonic-gate ttyn = ttyname(Ifn); 464*7c478bd9Sstevel@tonic-gate if (ttyn != CNULL && *ttyn != NULLCHAR) { 465*7c478bd9Sstevel@tonic-gate struct stat ttysbuf; 466*7c478bd9Sstevel@tonic-gate if ( fstat(Ifn,&ttysbuf) == 0 ) 467*7c478bd9Sstevel@tonic-gate Dev_mode = ttysbuf.st_mode; 468*7c478bd9Sstevel@tonic-gate else 469*7c478bd9Sstevel@tonic-gate Dev_mode = R_DEVICEMODE; 470*7c478bd9Sstevel@tonic-gate if ( EQUALSN(ttyn,"/dev/",5) ) 471*7c478bd9Sstevel@tonic-gate strcpy(Dc, ttyn+5); 472*7c478bd9Sstevel@tonic-gate else 473*7c478bd9Sstevel@tonic-gate strcpy(Dc, ttyn); 474*7c478bd9Sstevel@tonic-gate chmod(ttyn, S_DEVICEMODE); 475*7c478bd9Sstevel@tonic-gate } else 476*7c478bd9Sstevel@tonic-gate strcpy(Dc, "notty"); 477*7c478bd9Sstevel@tonic-gate /* set args for possible xuuxqt call */ 478*7c478bd9Sstevel@tonic-gate strcpy(uuxqtarg, Rmtname); 479*7c478bd9Sstevel@tonic-gate } 480*7c478bd9Sstevel@tonic-gate 481*7c478bd9Sstevel@tonic-gate strcpy(User, Uucp); 482*7c478bd9Sstevel@tonic-gate /* 483*7c478bd9Sstevel@tonic-gate * Ensure reasonable ulimit (MINULIMIT) 484*7c478bd9Sstevel@tonic-gate */ 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate #ifndef V7 487*7c478bd9Sstevel@tonic-gate { 488*7c478bd9Sstevel@tonic-gate long minulimit; 489*7c478bd9Sstevel@tonic-gate minulimit = ulimit(1, (long) 0); 490*7c478bd9Sstevel@tonic-gate ASSERT(minulimit >= MINULIMIT, "ULIMIT TOO SMALL", 491*7c478bd9Sstevel@tonic-gate Loginuser, (int) minulimit); 492*7c478bd9Sstevel@tonic-gate } 493*7c478bd9Sstevel@tonic-gate #endif 494*7c478bd9Sstevel@tonic-gate if (Role == MASTER && callok(Rmtname) != 0) { 495*7c478bd9Sstevel@tonic-gate logent("SYSTEM STATUS", "CAN NOT CALL"); 496*7c478bd9Sstevel@tonic-gate cleanup(101); 497*7c478bd9Sstevel@tonic-gate } 498*7c478bd9Sstevel@tonic-gate 499*7c478bd9Sstevel@tonic-gate chremdir(Rmtname); 500*7c478bd9Sstevel@tonic-gate 501*7c478bd9Sstevel@tonic-gate (void) strcpy(Wrkdir, RemSpool); 502*7c478bd9Sstevel@tonic-gate if (Role == MASTER) { 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate /* 505*7c478bd9Sstevel@tonic-gate * master part 506*7c478bd9Sstevel@tonic-gate */ 507*7c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); 508*7c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN); 509*7c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_IGN); 510*7c478bd9Sstevel@tonic-gate if (Ifn != -1 && Role == MASTER) { 511*7c478bd9Sstevel@tonic-gate (void) (*Write)(Ofn, EOTMSG, strlen(EOTMSG)); 512*7c478bd9Sstevel@tonic-gate (void) close(Ofn); 513*7c478bd9Sstevel@tonic-gate (void) close(Ifn); 514*7c478bd9Sstevel@tonic-gate Ifn = Ofn = -1; 515*7c478bd9Sstevel@tonic-gate rmlock(CNULL); 516*7c478bd9Sstevel@tonic-gate sleep(3); 517*7c478bd9Sstevel@tonic-gate } 518*7c478bd9Sstevel@tonic-gate 519*7c478bd9Sstevel@tonic-gate /* 520*7c478bd9Sstevel@tonic-gate * Find the highest priority job grade that has 521*7c478bd9Sstevel@tonic-gate * jobs to do. This is needed to form the lock name. 522*7c478bd9Sstevel@tonic-gate */ 523*7c478bd9Sstevel@tonic-gate 524*7c478bd9Sstevel@tonic-gate findgrade(RemSpool, JobGrade); 525*7c478bd9Sstevel@tonic-gate DEBUG(4, "Job grade to process - %s\n", JobGrade); 526*7c478bd9Sstevel@tonic-gate 527*7c478bd9Sstevel@tonic-gate /* 528*7c478bd9Sstevel@tonic-gate * Lock the job grade if there is one to process. 529*7c478bd9Sstevel@tonic-gate */ 530*7c478bd9Sstevel@tonic-gate 531*7c478bd9Sstevel@tonic-gate if (*JobGrade != NULLCHAR) { 532*7c478bd9Sstevel@tonic-gate (void) sprintf(gradedir, "%s/%s", Rmtname, JobGrade); 533*7c478bd9Sstevel@tonic-gate chremdir(gradedir); 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate (void) sprintf(lockname, "%.*s.%s", SYSNSIZE, Rmtname, JobGrade); 536*7c478bd9Sstevel@tonic-gate (void) sprintf(msg, "call to %s - process job grade %s ", 537*7c478bd9Sstevel@tonic-gate Rmtname, JobGrade); 538*7c478bd9Sstevel@tonic-gate if (umlock(LOCKPRE, lockname) != 0) { 539*7c478bd9Sstevel@tonic-gate logent(msg, "LOCKED"); 540*7c478bd9Sstevel@tonic-gate CDEBUG(1, "Currently Talking With %s\n", 541*7c478bd9Sstevel@tonic-gate Rmtname); 542*7c478bd9Sstevel@tonic-gate cleanup(100); 543*7c478bd9Sstevel@tonic-gate } 544*7c478bd9Sstevel@tonic-gate } else { 545*7c478bd9Sstevel@tonic-gate (void) sprintf(msg, "call to %s - no work", Rmtname); 546*7c478bd9Sstevel@tonic-gate } 547*7c478bd9Sstevel@tonic-gate 548*7c478bd9Sstevel@tonic-gate Nstat.t_scall = times(&Nstat.t_tga); 549*7c478bd9Sstevel@tonic-gate Ofn = Ifn = conn(Rmtname); 550*7c478bd9Sstevel@tonic-gate Nstat.t_ecall = times(&Nstat.t_tga); 551*7c478bd9Sstevel@tonic-gate if (Ofn < 0) { 552*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 553*7c478bd9Sstevel@tonic-gate logent(UERRORTEXT, "CONN FAILED"); 554*7c478bd9Sstevel@tonic-gate systat(Rmtname, Uerror, UERRORTEXT, Retrytime); 555*7c478bd9Sstevel@tonic-gate cleanup(101); 556*7c478bd9Sstevel@tonic-gate } else { 557*7c478bd9Sstevel@tonic-gate logent(msg, "SUCCEEDED"); 558*7c478bd9Sstevel@tonic-gate ttyn = ttyname(Ifn); 559*7c478bd9Sstevel@tonic-gate if (ttyn != CNULL && *ttyn != NULLCHAR) { 560*7c478bd9Sstevel@tonic-gate struct stat ttysbuf; 561*7c478bd9Sstevel@tonic-gate if ( fstat(Ifn,&ttysbuf) == 0 ) 562*7c478bd9Sstevel@tonic-gate Dev_mode = ttysbuf.st_mode; 563*7c478bd9Sstevel@tonic-gate else 564*7c478bd9Sstevel@tonic-gate Dev_mode = R_DEVICEMODE; 565*7c478bd9Sstevel@tonic-gate chmod(ttyn, M_DEVICEMODE); 566*7c478bd9Sstevel@tonic-gate } 567*7c478bd9Sstevel@tonic-gate } 568*7c478bd9Sstevel@tonic-gate 569*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 570*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 571*7c478bd9Sstevel@tonic-gate Uerror = SS_LOGIN_FAILED; 572*7c478bd9Sstevel@tonic-gate logent(Rmtname, UERRORTEXT); 573*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_LOGIN_FAILED, 574*7c478bd9Sstevel@tonic-gate UERRORTEXT, Retrytime); 575*7c478bd9Sstevel@tonic-gate DEBUG(4, "%s - failed\n", UERRORTEXT); 576*7c478bd9Sstevel@tonic-gate cleanup(101); 577*7c478bd9Sstevel@tonic-gate } 578*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, timeout); 579*7c478bd9Sstevel@tonic-gate /* give slow guys lots of time to thrash */ 580*7c478bd9Sstevel@tonic-gate (void) alarm(2 * msgtime); 581*7c478bd9Sstevel@tonic-gate for (;;) { 582*7c478bd9Sstevel@tonic-gate ret = imsg(msg, Ifn); 583*7c478bd9Sstevel@tonic-gate if (ret != 0) { 584*7c478bd9Sstevel@tonic-gate continue; /* try again */ 585*7c478bd9Sstevel@tonic-gate } 586*7c478bd9Sstevel@tonic-gate if (msg[0] == 'S') 587*7c478bd9Sstevel@tonic-gate break; 588*7c478bd9Sstevel@tonic-gate } 589*7c478bd9Sstevel@tonic-gate (void) alarm(0); 590*7c478bd9Sstevel@tonic-gate if(EQUALSN("here=", &msg[1], 5)){ 591*7c478bd9Sstevel@tonic-gate /* This may be a problem, we check up to MAXBASENAME 592*7c478bd9Sstevel@tonic-gate * characters now. The old comment was: 593*7c478bd9Sstevel@tonic-gate * this is a problem. We'd like to compare with an 594*7c478bd9Sstevel@tonic-gate * untruncated Rmtname but we fear incompatability. 595*7c478bd9Sstevel@tonic-gate * So we'll look at most 6 chars (at most). 596*7c478bd9Sstevel@tonic-gate */ 597*7c478bd9Sstevel@tonic-gate (void) pskip(&msg[6]); 598*7c478bd9Sstevel@tonic-gate if (!EQUALSN(&msg[6], Rmtname, MAXBASENAME)) { 599*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 600*7c478bd9Sstevel@tonic-gate Uerror = SS_WRONG_MCH; 601*7c478bd9Sstevel@tonic-gate logent(&msg[6], UERRORTEXT); 602*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_WRONG_MCH, UERRORTEXT, 603*7c478bd9Sstevel@tonic-gate Retrytime); 604*7c478bd9Sstevel@tonic-gate DEBUG(4, "%s - failed\n", UERRORTEXT); 605*7c478bd9Sstevel@tonic-gate cleanup(101); 606*7c478bd9Sstevel@tonic-gate } 607*7c478bd9Sstevel@tonic-gate } 608*7c478bd9Sstevel@tonic-gate CDEBUG(1,"Login Successful: System=%s\n",&msg[6]); 609*7c478bd9Sstevel@tonic-gate seq = gnxseq(Rmtname); 610*7c478bd9Sstevel@tonic-gate (void) sprintf(msg, "%s -Q%d -R -U0x%lx %s", 611*7c478bd9Sstevel@tonic-gate Myname, seq, Ulimit, xflag); 612*7c478bd9Sstevel@tonic-gate #ifdef MAXGRADE 613*7c478bd9Sstevel@tonic-gate if (MaxGrade != NULLCHAR) { 614*7c478bd9Sstevel@tonic-gate p = strchr(msg, NULLCHAR); 615*7c478bd9Sstevel@tonic-gate sprintf(p, " -vgrade=%c", MaxGrade); 616*7c478bd9Sstevel@tonic-gate } 617*7c478bd9Sstevel@tonic-gate #endif /* MAXGRADE */ 618*7c478bd9Sstevel@tonic-gate omsg('S', msg, Ofn); 619*7c478bd9Sstevel@tonic-gate (void) alarm(msgtime); /* give slow guys some thrash time */ 620*7c478bd9Sstevel@tonic-gate for (;;) { 621*7c478bd9Sstevel@tonic-gate ret = imsg(msg, Ifn); 622*7c478bd9Sstevel@tonic-gate DEBUG(4, "msg-%s\n", msg); 623*7c478bd9Sstevel@tonic-gate if (ret != 0) { 624*7c478bd9Sstevel@tonic-gate (void) alarm(0); 625*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 626*7c478bd9Sstevel@tonic-gate ulkseq(); 627*7c478bd9Sstevel@tonic-gate cleanup(101); 628*7c478bd9Sstevel@tonic-gate } 629*7c478bd9Sstevel@tonic-gate if (msg[0] == 'R') 630*7c478bd9Sstevel@tonic-gate break; 631*7c478bd9Sstevel@tonic-gate } 632*7c478bd9Sstevel@tonic-gate (void) alarm(0); 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate /* check for rejects from remote */ 635*7c478bd9Sstevel@tonic-gate Uerror = 0; 636*7c478bd9Sstevel@tonic-gate if (EQUALS(&msg[1], "LCK")) 637*7c478bd9Sstevel@tonic-gate Uerror = SS_RLOCKED; 638*7c478bd9Sstevel@tonic-gate else if (EQUALS(&msg[1], "LOGIN")) 639*7c478bd9Sstevel@tonic-gate Uerror = SS_RLOGIN; 640*7c478bd9Sstevel@tonic-gate else if (EQUALS(&msg[1], "CB")) 641*7c478bd9Sstevel@tonic-gate Uerror = (callBack() ? SS_CALLBACK_LOOP : SS_CALLBACK); 642*7c478bd9Sstevel@tonic-gate else if (EQUALS(&msg[1], "You are unknown to me")) 643*7c478bd9Sstevel@tonic-gate Uerror = SS_RUNKNOWN; 644*7c478bd9Sstevel@tonic-gate else if (EQUALS(&msg[1], "BADSEQ")) 645*7c478bd9Sstevel@tonic-gate Uerror = SS_SEQBAD; 646*7c478bd9Sstevel@tonic-gate else if (!EQUALSN(&msg[1], "OK", 2)) 647*7c478bd9Sstevel@tonic-gate Uerror = SS_UNKNOWN_RESPONSE; 648*7c478bd9Sstevel@tonic-gate if (Uerror) { 649*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 650*7c478bd9Sstevel@tonic-gate systat(Rmtname, Uerror, UERRORTEXT, Retrytime); 651*7c478bd9Sstevel@tonic-gate logent(UERRORTEXT, "HANDSHAKE FAILED"); 652*7c478bd9Sstevel@tonic-gate CDEBUG(1, "HANDSHAKE FAILED: %s\n", UERRORTEXT); 653*7c478bd9Sstevel@tonic-gate ulkseq(); 654*7c478bd9Sstevel@tonic-gate cleanup(101); 655*7c478bd9Sstevel@tonic-gate } 656*7c478bd9Sstevel@tonic-gate (void) cmtseq(); 657*7c478bd9Sstevel@tonic-gate 658*7c478bd9Sstevel@tonic-gate /* 659*7c478bd9Sstevel@tonic-gate * See if we have any additional parameters on the OK 660*7c478bd9Sstevel@tonic-gate */ 661*7c478bd9Sstevel@tonic-gate 662*7c478bd9Sstevel@tonic-gate if (strlen(&msg[3])) { 663*7c478bd9Sstevel@tonic-gate p = pskip(&msg[3]); 664*7c478bd9Sstevel@tonic-gate while (p && *p == '-') { 665*7c478bd9Sstevel@tonic-gate q = pskip(p); 666*7c478bd9Sstevel@tonic-gate switch(*(++p)) { 667*7c478bd9Sstevel@tonic-gate case 'R': 668*7c478bd9Sstevel@tonic-gate Restart++; 669*7c478bd9Sstevel@tonic-gate p++; 670*7c478bd9Sstevel@tonic-gate break; 671*7c478bd9Sstevel@tonic-gate case 'U': 672*7c478bd9Sstevel@tonic-gate SizeCheck++; 673*7c478bd9Sstevel@tonic-gate RemUlimit = strtol(++p, (char **) NULL, 0); 674*7c478bd9Sstevel@tonic-gate break; 675*7c478bd9Sstevel@tonic-gate case 'x': 676*7c478bd9Sstevel@tonic-gate if (!Debug) { 677*7c478bd9Sstevel@tonic-gate Debug = atoi(++p); 678*7c478bd9Sstevel@tonic-gate if (Debug <= 0) 679*7c478bd9Sstevel@tonic-gate Debug = 1; 680*7c478bd9Sstevel@tonic-gate } 681*7c478bd9Sstevel@tonic-gate break; 682*7c478bd9Sstevel@tonic-gate default: 683*7c478bd9Sstevel@tonic-gate break; 684*7c478bd9Sstevel@tonic-gate } 685*7c478bd9Sstevel@tonic-gate p = q; 686*7c478bd9Sstevel@tonic-gate } 687*7c478bd9Sstevel@tonic-gate } 688*7c478bd9Sstevel@tonic-gate 689*7c478bd9Sstevel@tonic-gate } 690*7c478bd9Sstevel@tonic-gate DEBUG(4, " Rmtname %s, ", Rmtname); 691*7c478bd9Sstevel@tonic-gate DEBUG(4, " Restart %s, ", (Restart ? "YES" : "NO")); 692*7c478bd9Sstevel@tonic-gate DEBUG(4, "Role %s, ", Role ? "MASTER" : "SLAVE"); 693*7c478bd9Sstevel@tonic-gate DEBUG(4, "Ifn - %d, ", Ifn); 694*7c478bd9Sstevel@tonic-gate DEBUG(4, "Loginuser - %s\n", Loginuser); 695*7c478bd9Sstevel@tonic-gate 696*7c478bd9Sstevel@tonic-gate /* alarm/setjmp added here due to experience with uucico 697*7c478bd9Sstevel@tonic-gate * hanging for hours in imsg(). 698*7c478bd9Sstevel@tonic-gate */ 699*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 700*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 701*7c478bd9Sstevel@tonic-gate logent("startup", "TIMEOUT"); 702*7c478bd9Sstevel@tonic-gate DEBUG(4, "%s - timeout\n", "startup"); 703*7c478bd9Sstevel@tonic-gate cleanup(101); 704*7c478bd9Sstevel@tonic-gate } 705*7c478bd9Sstevel@tonic-gate (void) alarm(MAXSTART); 706*7c478bd9Sstevel@tonic-gate ret = startup(); 707*7c478bd9Sstevel@tonic-gate (void) alarm(0); 708*7c478bd9Sstevel@tonic-gate 709*7c478bd9Sstevel@tonic-gate if (ret != SUCCESS) { 710*7c478bd9Sstevel@tonic-gate delock(LOCKPRE, lockname); 711*7c478bd9Sstevel@tonic-gate logent("startup", "FAILED"); 712*7c478bd9Sstevel@tonic-gate Uerror = SS_STARTUP; 713*7c478bd9Sstevel@tonic-gate CDEBUG(1, "%s\n", UERRORTEXT); 714*7c478bd9Sstevel@tonic-gate systat(Rmtname, Uerror, UERRORTEXT, Retrytime); 715*7c478bd9Sstevel@tonic-gate exitcode = 101; 716*7c478bd9Sstevel@tonic-gate } else { 717*7c478bd9Sstevel@tonic-gate pfConnected(Rmtname, Dc); 718*7c478bd9Sstevel@tonic-gate acConnected(Rmtname, Dc); 719*7c478bd9Sstevel@tonic-gate logent("startup", "OK"); 720*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_INPROGRESS, UTEXT(SS_INPROGRESS),Retrytime); 721*7c478bd9Sstevel@tonic-gate Nstat.t_sftp = times(&Nstat.t_tga); 722*7c478bd9Sstevel@tonic-gate 723*7c478bd9Sstevel@tonic-gate exitcode = cntrl(); 724*7c478bd9Sstevel@tonic-gate Nstat.t_eftp = times(&Nstat.t_tga); 725*7c478bd9Sstevel@tonic-gate DEBUG(4, "cntrl - %d\n", exitcode); 726*7c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); 727*7c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN); 728*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, timeout); 729*7c478bd9Sstevel@tonic-gate 730*7c478bd9Sstevel@tonic-gate if (exitcode == 0) { 731*7c478bd9Sstevel@tonic-gate (void) time(&ts); 732*7c478bd9Sstevel@tonic-gate (void) sprintf(cb, "conversation complete %s %ld", 733*7c478bd9Sstevel@tonic-gate Dc, ts - tconv); 734*7c478bd9Sstevel@tonic-gate logent(cb, "OK"); 735*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_OK, UTEXT(SS_OK), Retrytime); 736*7c478bd9Sstevel@tonic-gate 737*7c478bd9Sstevel@tonic-gate } else { 738*7c478bd9Sstevel@tonic-gate logent("conversation complete", "FAILED"); 739*7c478bd9Sstevel@tonic-gate systat(Rmtname, SS_CONVERSATION, 740*7c478bd9Sstevel@tonic-gate UTEXT(SS_CONVERSATION), Retrytime); 741*7c478bd9Sstevel@tonic-gate } 742*7c478bd9Sstevel@tonic-gate (void) alarm(msgtime); /* give slow guys some thrash time */ 743*7c478bd9Sstevel@tonic-gate omsg('O', "OOOOO", Ofn); 744*7c478bd9Sstevel@tonic-gate CDEBUG(4, "send OO %d,", ret); 745*7c478bd9Sstevel@tonic-gate if (!setjmp(Sjbuf)) { 746*7c478bd9Sstevel@tonic-gate for (;;) { 747*7c478bd9Sstevel@tonic-gate omsg('O', "OOOOO", Ofn); 748*7c478bd9Sstevel@tonic-gate ret = imsg(msg, Ifn); 749*7c478bd9Sstevel@tonic-gate if (ret != 0) 750*7c478bd9Sstevel@tonic-gate break; 751*7c478bd9Sstevel@tonic-gate if (msg[0] == 'O') 752*7c478bd9Sstevel@tonic-gate break; 753*7c478bd9Sstevel@tonic-gate } 754*7c478bd9Sstevel@tonic-gate } 755*7c478bd9Sstevel@tonic-gate (void) alarm(0); 756*7c478bd9Sstevel@tonic-gate } 757*7c478bd9Sstevel@tonic-gate cleanup(exitcode); 758*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 759*7c478bd9Sstevel@tonic-gate } 760*7c478bd9Sstevel@tonic-gate 761*7c478bd9Sstevel@tonic-gate /* 762*7c478bd9Sstevel@tonic-gate * clean and exit with "code" status 763*7c478bd9Sstevel@tonic-gate */ 764*7c478bd9Sstevel@tonic-gate void 765*7c478bd9Sstevel@tonic-gate cleanup(code) 766*7c478bd9Sstevel@tonic-gate register int code; 767*7c478bd9Sstevel@tonic-gate { 768*7c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); 769*7c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN); 770*7c478bd9Sstevel@tonic-gate rmlock(CNULL); 771*7c478bd9Sstevel@tonic-gate closedem(); 772*7c478bd9Sstevel@tonic-gate alarm(msgtime); /* Start timer in case closes hang. */ 773*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf) == 0) 774*7c478bd9Sstevel@tonic-gate (*Teardown)( Role, Ifn, Ofn ); 775*7c478bd9Sstevel@tonic-gate alarm(0); /* Turn off timer. */ 776*7c478bd9Sstevel@tonic-gate DEBUG(4, "exit code %d\n", code); 777*7c478bd9Sstevel@tonic-gate CDEBUG(1, "Conversation Complete: Status %s\n\n", 778*7c478bd9Sstevel@tonic-gate code ? "FAILED" : "SUCCEEDED"); 779*7c478bd9Sstevel@tonic-gate 780*7c478bd9Sstevel@tonic-gate cleanTM(); 781*7c478bd9Sstevel@tonic-gate if ((code == 0) && (uuxqtflag == 1)) 782*7c478bd9Sstevel@tonic-gate xuuxqt(uuxqtarg); 783*7c478bd9Sstevel@tonic-gate exit(code); 784*7c478bd9Sstevel@tonic-gate } 785*7c478bd9Sstevel@tonic-gate 786*7c478bd9Sstevel@tonic-gate short TM_cnt = 0; 787*7c478bd9Sstevel@tonic-gate char TM_name[MAXNAMESIZE]; 788*7c478bd9Sstevel@tonic-gate 789*7c478bd9Sstevel@tonic-gate void 790*7c478bd9Sstevel@tonic-gate cleanTM() 791*7c478bd9Sstevel@tonic-gate { 792*7c478bd9Sstevel@tonic-gate register int i; 793*7c478bd9Sstevel@tonic-gate char tm_name[MAXNAMESIZE]; 794*7c478bd9Sstevel@tonic-gate 795*7c478bd9Sstevel@tonic-gate DEBUG(7,"TM_cnt: %d\n",TM_cnt); 796*7c478bd9Sstevel@tonic-gate for(i=0; i < TM_cnt; i++) { 797*7c478bd9Sstevel@tonic-gate (void) sprintf(tm_name, "%s.%3.3d", TM_name, i); 798*7c478bd9Sstevel@tonic-gate DEBUG(7, "tm_name: %s\n", tm_name); 799*7c478bd9Sstevel@tonic-gate unlink(tm_name); 800*7c478bd9Sstevel@tonic-gate } 801*7c478bd9Sstevel@tonic-gate return; 802*7c478bd9Sstevel@tonic-gate } 803*7c478bd9Sstevel@tonic-gate 804*7c478bd9Sstevel@tonic-gate void 805*7c478bd9Sstevel@tonic-gate TMname(file, pnum) 806*7c478bd9Sstevel@tonic-gate char *file; 807*7c478bd9Sstevel@tonic-gate pid_t pnum; 808*7c478bd9Sstevel@tonic-gate { 809*7c478bd9Sstevel@tonic-gate 810*7c478bd9Sstevel@tonic-gate (void) sprintf(file, "%s/TM.%.5ld.%.3d", RemSpool, (long) pnum, TM_cnt); 811*7c478bd9Sstevel@tonic-gate if (TM_cnt == 0) 812*7c478bd9Sstevel@tonic-gate (void) sprintf(TM_name, "%s/TM.%.5ld", RemSpool, (long) pnum); 813*7c478bd9Sstevel@tonic-gate DEBUG(7, "TMname(%s)\n", file); 814*7c478bd9Sstevel@tonic-gate TM_cnt++; 815*7c478bd9Sstevel@tonic-gate return; 816*7c478bd9Sstevel@tonic-gate } 817*7c478bd9Sstevel@tonic-gate 818*7c478bd9Sstevel@tonic-gate /* 819*7c478bd9Sstevel@tonic-gate * intrrupt - remove locks and exit 820*7c478bd9Sstevel@tonic-gate */ 821*7c478bd9Sstevel@tonic-gate void 822*7c478bd9Sstevel@tonic-gate onintr(inter) 823*7c478bd9Sstevel@tonic-gate register int inter; 824*7c478bd9Sstevel@tonic-gate { 825*7c478bd9Sstevel@tonic-gate char str[30]; 826*7c478bd9Sstevel@tonic-gate /* I'm putting a test for zero here because I saw it happen 827*7c478bd9Sstevel@tonic-gate * and don't know how or why, but it seemed to then loop 828*7c478bd9Sstevel@tonic-gate * here for ever? 829*7c478bd9Sstevel@tonic-gate */ 830*7c478bd9Sstevel@tonic-gate if (inter == 0) 831*7c478bd9Sstevel@tonic-gate exit(99); 832*7c478bd9Sstevel@tonic-gate (void) signal(inter, SIG_IGN); 833*7c478bd9Sstevel@tonic-gate (void) sprintf(str, "SIGNAL %d", inter); 834*7c478bd9Sstevel@tonic-gate logent(str, "CAUGHT"); 835*7c478bd9Sstevel@tonic-gate pfEndfile("PARTIAL FILE"); 836*7c478bd9Sstevel@tonic-gate acEnd(PARTIAL); /*stop collecting accounting log */ 837*7c478bd9Sstevel@tonic-gate cleanup(inter); 838*7c478bd9Sstevel@tonic-gate } 839*7c478bd9Sstevel@tonic-gate 840*7c478bd9Sstevel@tonic-gate void 841*7c478bd9Sstevel@tonic-gate intrEXIT(inter) 842*7c478bd9Sstevel@tonic-gate int inter; 843*7c478bd9Sstevel@tonic-gate { 844*7c478bd9Sstevel@tonic-gate char cb[20]; 845*7c478bd9Sstevel@tonic-gate 846*7c478bd9Sstevel@tonic-gate (void) sprintf(cb, "SIGNAL %d", inter); 847*7c478bd9Sstevel@tonic-gate logent("INTREXIT", cb); 848*7c478bd9Sstevel@tonic-gate (void) signal(SIGIOT, SIG_DFL); 849*7c478bd9Sstevel@tonic-gate (void) signal(SIGILL, SIG_DFL); 850*7c478bd9Sstevel@tonic-gate rmlock(CNULL); 851*7c478bd9Sstevel@tonic-gate closedem(); 852*7c478bd9Sstevel@tonic-gate (void) setuid(Uid); 853*7c478bd9Sstevel@tonic-gate abort(); 854*7c478bd9Sstevel@tonic-gate } 855*7c478bd9Sstevel@tonic-gate 856*7c478bd9Sstevel@tonic-gate /* 857*7c478bd9Sstevel@tonic-gate * catch SIGALRM routine 858*7c478bd9Sstevel@tonic-gate */ 859*7c478bd9Sstevel@tonic-gate void 860*7c478bd9Sstevel@tonic-gate timeout() 861*7c478bd9Sstevel@tonic-gate { 862*7c478bd9Sstevel@tonic-gate longjmp(Sjbuf, 1); 863*7c478bd9Sstevel@tonic-gate } 864*7c478bd9Sstevel@tonic-gate 865*7c478bd9Sstevel@tonic-gate /* skip to next field */ 866*7c478bd9Sstevel@tonic-gate static char * 867*7c478bd9Sstevel@tonic-gate pskip(p) 868*7c478bd9Sstevel@tonic-gate register char *p; 869*7c478bd9Sstevel@tonic-gate { 870*7c478bd9Sstevel@tonic-gate if ((p = strchr(p, ' ')) != CNULL) 871*7c478bd9Sstevel@tonic-gate do 872*7c478bd9Sstevel@tonic-gate *p++ = NULLCHAR; 873*7c478bd9Sstevel@tonic-gate while (*p == ' '); 874*7c478bd9Sstevel@tonic-gate return(p); 875*7c478bd9Sstevel@tonic-gate } 876*7c478bd9Sstevel@tonic-gate 877*7c478bd9Sstevel@tonic-gate void 878*7c478bd9Sstevel@tonic-gate closedem() 879*7c478bd9Sstevel@tonic-gate { 880*7c478bd9Sstevel@tonic-gate register i, maxfiles; 881*7c478bd9Sstevel@tonic-gate 882*7c478bd9Sstevel@tonic-gate #ifdef ATTSVR3 883*7c478bd9Sstevel@tonic-gate maxfiles = ulimit(4,0); 884*7c478bd9Sstevel@tonic-gate #else /* !ATTSVR3 */ 885*7c478bd9Sstevel@tonic-gate #ifdef BSD4_2 886*7c478bd9Sstevel@tonic-gate maxfiles = getdtablesize(); 887*7c478bd9Sstevel@tonic-gate #else /* BSD4_2 */ 888*7c478bd9Sstevel@tonic-gate maxfiles = _NFILE; 889*7c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */ 890*7c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */ 891*7c478bd9Sstevel@tonic-gate 892*7c478bd9Sstevel@tonic-gate for ( i = 3; i < maxfiles; i++ ) 893*7c478bd9Sstevel@tonic-gate if ( i != Ifn && i != Ofn && i != fileno(stderr) ) 894*7c478bd9Sstevel@tonic-gate (void) close(i); 895*7c478bd9Sstevel@tonic-gate return; 896*7c478bd9Sstevel@tonic-gate } 897*7c478bd9Sstevel@tonic-gate 898*7c478bd9Sstevel@tonic-gate #ifndef ATTSVR3 899*7c478bd9Sstevel@tonic-gate 900*7c478bd9Sstevel@tonic-gate /* 901*7c478bd9Sstevel@tonic-gate * setTZ() 902*7c478bd9Sstevel@tonic-gate * 903*7c478bd9Sstevel@tonic-gate * if login "shell" is uucico (i.e., Role == SLAVE), must set 904*7c478bd9Sstevel@tonic-gate * timezone env variable TZ. otherwise will default to EST. 905*7c478bd9Sstevel@tonic-gate */ 906*7c478bd9Sstevel@tonic-gate 907*7c478bd9Sstevel@tonic-gate #define LINELEN 81 908*7c478bd9Sstevel@tonic-gate 909*7c478bd9Sstevel@tonic-gate void 910*7c478bd9Sstevel@tonic-gate setTZ() 911*7c478bd9Sstevel@tonic-gate { 912*7c478bd9Sstevel@tonic-gate static char buf[LINELEN], *bp; 913*7c478bd9Sstevel@tonic-gate extern char *fgets(); 914*7c478bd9Sstevel@tonic-gate FILE *tzfp; 915*7c478bd9Sstevel@tonic-gate extern FILE *fopen(); 916*7c478bd9Sstevel@tonic-gate register int i; 917*7c478bd9Sstevel@tonic-gate extern int fclose(), strncmp(); 918*7c478bd9Sstevel@tonic-gate 919*7c478bd9Sstevel@tonic-gate if ( (tzfp = fopen("/etc/TIMEZONE","r")) == (FILE *)NULL ) 920*7c478bd9Sstevel@tonic-gate return; 921*7c478bd9Sstevel@tonic-gate while ( (bp = fgets(buf,LINELEN,tzfp)) != (char *)NULL ) { 922*7c478bd9Sstevel@tonic-gate while ( isspace(*bp) ) 923*7c478bd9Sstevel@tonic-gate ++bp; 924*7c478bd9Sstevel@tonic-gate if ( strncmp(bp, "TZ=", 3) == 0 ) { 925*7c478bd9Sstevel@tonic-gate for ( i = strlen(bp) - 1; i > 0 && isspace(*(bp+i)); --i ) 926*7c478bd9Sstevel@tonic-gate *(bp+i) = '\0'; 927*7c478bd9Sstevel@tonic-gate putenv(bp); 928*7c478bd9Sstevel@tonic-gate (void)fclose(tzfp); 929*7c478bd9Sstevel@tonic-gate return; 930*7c478bd9Sstevel@tonic-gate } 931*7c478bd9Sstevel@tonic-gate } 932*7c478bd9Sstevel@tonic-gate (void)fclose(tzfp); 933*7c478bd9Sstevel@tonic-gate return; 934*7c478bd9Sstevel@tonic-gate } 935*7c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */ 936*7c478bd9Sstevel@tonic-gate 937*7c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS 938*7c478bd9Sstevel@tonic-gate /* 939*7c478bd9Sstevel@tonic-gate * Function: checkrmt 940*7c478bd9Sstevel@tonic-gate * 941*7c478bd9Sstevel@tonic-gate * If NOSTRANGERS is defined, see if the remote system is in our systems 942*7c478bd9Sstevel@tonic-gate * file. If it is not, execute NOSTRANGERS and then reject the call. 943*7c478bd9Sstevel@tonic-gate */ 944*7c478bd9Sstevel@tonic-gate 945*7c478bd9Sstevel@tonic-gate static void 946*7c478bd9Sstevel@tonic-gate checkrmt () 947*7c478bd9Sstevel@tonic-gate 948*7c478bd9Sstevel@tonic-gate { 949*7c478bd9Sstevel@tonic-gate char ** eVarPtr; /* Pointer to environment variable. */ 950*7c478bd9Sstevel@tonic-gate char msgbuf[BUFSIZ]; /* Place to build messages. */ 951*7c478bd9Sstevel@tonic-gate pid_t procid; /* ID of Nostranger process. */ 952*7c478bd9Sstevel@tonic-gate static char * safePath = PATH; 953*7c478bd9Sstevel@tonic-gate int status; /* Exit status of child. */ 954*7c478bd9Sstevel@tonic-gate pid_t waitrv; /* Return value from wait system call. */ 955*7c478bd9Sstevel@tonic-gate 956*7c478bd9Sstevel@tonic-gate /* here's the place to look the remote system up in the Systems file. 957*7c478bd9Sstevel@tonic-gate * If the command NOSTRANGERS is executable and 958*7c478bd9Sstevel@tonic-gate * If they're not in my file then hang up */ 959*7c478bd9Sstevel@tonic-gate 960*7c478bd9Sstevel@tonic-gate if (versys(Rmtname) && (access(NOSTRANGERS, 1) == 0)) { 961*7c478bd9Sstevel@tonic-gate sprintf(msgbuf, "Invoking %s for %%s\n", NOSTRANGERS); 962*7c478bd9Sstevel@tonic-gate DEBUG(4, msgbuf, Rmtname); 963*7c478bd9Sstevel@tonic-gate 964*7c478bd9Sstevel@tonic-gate /* 965*7c478bd9Sstevel@tonic-gate * Ignore hangup in case remote goes away before we can 966*7c478bd9Sstevel@tonic-gate * finish logging. 967*7c478bd9Sstevel@tonic-gate */ 968*7c478bd9Sstevel@tonic-gate 969*7c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN); 970*7c478bd9Sstevel@tonic-gate omsg('R', "You are unknown to me", Ofn); 971*7c478bd9Sstevel@tonic-gate scWrite(); /* log unknown remote system */ 972*7c478bd9Sstevel@tonic-gate procid = fork(); 973*7c478bd9Sstevel@tonic-gate if ( procid == 0 ) { 974*7c478bd9Sstevel@tonic-gate /* 975*7c478bd9Sstevel@tonic-gate * Before execing the no strangers program, there is 976*7c478bd9Sstevel@tonic-gate * a security aspect to consider. If NOSTRANGERS is 977*7c478bd9Sstevel@tonic-gate * not a full path name, then the PATH environment 978*7c478bd9Sstevel@tonic-gate * variable will provide places to look for the file. 979*7c478bd9Sstevel@tonic-gate * To be safe, we will set the PATH environment 980*7c478bd9Sstevel@tonic-gate * variable before we do the exec. 981*7c478bd9Sstevel@tonic-gate */ 982*7c478bd9Sstevel@tonic-gate 983*7c478bd9Sstevel@tonic-gate /* Find PATH in current environment and change it. */ 984*7c478bd9Sstevel@tonic-gate 985*7c478bd9Sstevel@tonic-gate for (eVarPtr = Env; *eVarPtr != CNULL; eVarPtr++) { 986*7c478bd9Sstevel@tonic-gate if (PREFIX("PATH=", *eVarPtr)) 987*7c478bd9Sstevel@tonic-gate *eVarPtr = safePath; 988*7c478bd9Sstevel@tonic-gate } 989*7c478bd9Sstevel@tonic-gate execlp( NOSTRANGERS, "stranger", Rmtname, (char *) 0); 990*7c478bd9Sstevel@tonic-gate sprintf(msgbuf, "Execlp of %s failed with errno=%%d\n", 991*7c478bd9Sstevel@tonic-gate NOSTRANGERS); 992*7c478bd9Sstevel@tonic-gate DEBUG(4, msgbuf, errno); 993*7c478bd9Sstevel@tonic-gate perror(gettext("cico.c: execlp NOSTRANGERS failed")); 994*7c478bd9Sstevel@tonic-gate cleanup(errno); 995*7c478bd9Sstevel@tonic-gate } else if (procid < 0) { 996*7c478bd9Sstevel@tonic-gate perror(gettext("cico.c: execlp NOSTRANGERS failed")); 997*7c478bd9Sstevel@tonic-gate cleanup(errno); 998*7c478bd9Sstevel@tonic-gate } else { 999*7c478bd9Sstevel@tonic-gate while ((waitrv = wait(&status)) != procid) 1000*7c478bd9Sstevel@tonic-gate if (waitrv == -1 && errno != EINTR) 1001*7c478bd9Sstevel@tonic-gate cleanup(errno); 1002*7c478bd9Sstevel@tonic-gate sprintf(msgbuf, "%s exit status was %%#x\n", 1003*7c478bd9Sstevel@tonic-gate NOSTRANGERS); 1004*7c478bd9Sstevel@tonic-gate DEBUG(4, msgbuf, status); 1005*7c478bd9Sstevel@tonic-gate } 1006*7c478bd9Sstevel@tonic-gate cleanup(101); 1007*7c478bd9Sstevel@tonic-gate } 1008*7c478bd9Sstevel@tonic-gate } 1009*7c478bd9Sstevel@tonic-gate #endif /* NOSTRANGERS */ 1010