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 (c) 1999 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 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" /* from SVR4 bnu:unknown.c 1.8 */ 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * logs attempts by unknown remote machines to run uucico in FOREIGN 34*7c478bd9Sstevel@tonic-gate * ("/var/uucp/.Admin/Foreign"). if anything goes wrong, 35*7c478bd9Sstevel@tonic-gate * sends mail to login MAILTO ("uucp"). the executable should be 36*7c478bd9Sstevel@tonic-gate * placed in /usr/lib/uucp/remote.unknown, and should run setuid-uucp. 37*7c478bd9Sstevel@tonic-gate */ 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #include <stdio.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 41*7c478bd9Sstevel@tonic-gate #include <time.h> 42*7c478bd9Sstevel@tonic-gate #include <errno.h> 43*7c478bd9Sstevel@tonic-gate #include "uucp.h" 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate #define FOREIGN "/var/uucp/.Admin/Foreign" 46*7c478bd9Sstevel@tonic-gate #define MAILTO "uucp" 47*7c478bd9Sstevel@tonic-gate #define LOGLEN 256 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate void fall_on_sword(); 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate main(argc, argv) 52*7c478bd9Sstevel@tonic-gate int argc; 53*7c478bd9Sstevel@tonic-gate char *argv[]; 54*7c478bd9Sstevel@tonic-gate { 55*7c478bd9Sstevel@tonic-gate char buf[LOGLEN], *ctoday, *logname, tmpbuf[MAXBASENAME+1]; 56*7c478bd9Sstevel@tonic-gate FILE *fp; 57*7c478bd9Sstevel@tonic-gate time_t today; 58*7c478bd9Sstevel@tonic-gate extern char *ctime(); 59*7c478bd9Sstevel@tonic-gate extern FILE *fopen(); 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate if ( argc != 2 ) { 62*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "USAGE: %s remotename\n", argv[0]); 63*7c478bd9Sstevel@tonic-gate exit(101); 64*7c478bd9Sstevel@tonic-gate } 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate if ( time(&today) != -1 ) { 67*7c478bd9Sstevel@tonic-gate ctoday = ctime(&today); 68*7c478bd9Sstevel@tonic-gate *(ctoday + strlen(ctoday) - 1) = '\0'; /* no ending \n */ 69*7c478bd9Sstevel@tonic-gate } else 70*7c478bd9Sstevel@tonic-gate ctoday = "NO DATE"; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate logname = cuserid((char *) NULL); 73*7c478bd9Sstevel@tonic-gate (void) strncpy(tmpbuf, argv[1], MAXBASENAME); 74*7c478bd9Sstevel@tonic-gate tmpbuf[MAXBASENAME] = '\0'; 75*7c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof(buf), "%s: call from system %s login %s\n", 76*7c478bd9Sstevel@tonic-gate ctoday, tmpbuf, (logname == NULL ? "<unknown>" : logname)); 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate errno = 0; 79*7c478bd9Sstevel@tonic-gate if ( (fp = fopen(FOREIGN, "a+")) == (FILE *)NULL ) 80*7c478bd9Sstevel@tonic-gate fall_on_sword("cannot open", buf); 81*7c478bd9Sstevel@tonic-gate if ( fputs(buf, fp) == EOF ) 82*7c478bd9Sstevel@tonic-gate fall_on_sword("cannot write", buf); 83*7c478bd9Sstevel@tonic-gate if ( fclose(fp) != 0 ) 84*7c478bd9Sstevel@tonic-gate fall_on_sword("cannot close", buf); 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate exit(0); 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 89*7c478bd9Sstevel@tonic-gate } 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* don't return from here */ 92*7c478bd9Sstevel@tonic-gate void 93*7c478bd9Sstevel@tonic-gate fall_on_sword(errmsg, logmsg) 94*7c478bd9Sstevel@tonic-gate char *errmsg, *logmsg; 95*7c478bd9Sstevel@tonic-gate { 96*7c478bd9Sstevel@tonic-gate char ebuf[BUFSIZ+1]; 97*7c478bd9Sstevel@tonic-gate int fds[2]; 98*7c478bd9Sstevel@tonic-gate size_t sz; 99*7c478bd9Sstevel@tonic-gate extern int sys_nerr; 100*7c478bd9Sstevel@tonic-gate extern char *sys_errlist[]; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate (void) snprintf(ebuf, BUFSIZ, 104*7c478bd9Sstevel@tonic-gate "To: %s\nSubject: %s %s\n\n%s %s:\t%s (%d)\nlog msg:\t%s", 105*7c478bd9Sstevel@tonic-gate MAILTO, errmsg, FOREIGN, errmsg, FOREIGN, 106*7c478bd9Sstevel@tonic-gate (errno < sys_nerr ? sys_errlist[errno] : "Unknown error "), 107*7c478bd9Sstevel@tonic-gate errno, logmsg); 108*7c478bd9Sstevel@tonic-gate sz = strlen(ebuf); 109*7c478bd9Sstevel@tonic-gate if (ebuf[sz-1] != '\n') { 110*7c478bd9Sstevel@tonic-gate ebuf[sz] = '\n'; 111*7c478bd9Sstevel@tonic-gate ebuf[sz+1] = '\0'; 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* reset to real uid. get a pipe. put error message on */ 115*7c478bd9Sstevel@tonic-gate /* "write end" of pipe, close it. dup "read end" to */ 116*7c478bd9Sstevel@tonic-gate /* stdin and then execl mail (which will read the error */ 117*7c478bd9Sstevel@tonic-gate /* message we just wrote). */ 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate if ( setuid(getuid()) == -1 || pipe(fds) != 0 120*7c478bd9Sstevel@tonic-gate || write(fds[1], ebuf, strlen(ebuf)) != strlen(ebuf) 121*7c478bd9Sstevel@tonic-gate || close(fds[1]) != 0 ) 122*7c478bd9Sstevel@tonic-gate exit(errno); 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate if ( fds[0] != 0 ) { 125*7c478bd9Sstevel@tonic-gate close(0); 126*7c478bd9Sstevel@tonic-gate if ( dup(fds[0]) != 0 ) 127*7c478bd9Sstevel@tonic-gate exit(errno); 128*7c478bd9Sstevel@tonic-gate } 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate execl("/usr/bin/mail", "mail", MAILTO, (char *) 0); 131*7c478bd9Sstevel@tonic-gate exit(errno); /* shouldn't get here */ 132*7c478bd9Sstevel@tonic-gate } 133