17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23ace1a5f1Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24ace1a5f1Sdp * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 31ace1a5f1Sdp #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * logs attempts by unknown remote machines to run uucico in FOREIGN 347c478bd9Sstevel@tonic-gate * ("/var/uucp/.Admin/Foreign"). if anything goes wrong, 357c478bd9Sstevel@tonic-gate * sends mail to login MAILTO ("uucp"). the executable should be 367c478bd9Sstevel@tonic-gate * placed in /usr/lib/uucp/remote.unknown, and should run setuid-uucp. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <stdio.h> 407c478bd9Sstevel@tonic-gate #include <sys/types.h> 417c478bd9Sstevel@tonic-gate #include <time.h> 427c478bd9Sstevel@tonic-gate #include <errno.h> 437c478bd9Sstevel@tonic-gate #include "uucp.h" 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #define FOREIGN "/var/uucp/.Admin/Foreign" 467c478bd9Sstevel@tonic-gate #define MAILTO "uucp" 477c478bd9Sstevel@tonic-gate #define LOGLEN 256 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate void fall_on_sword(); 507c478bd9Sstevel@tonic-gate 51*462be471Sceastha int 527c478bd9Sstevel@tonic-gate main(argc, argv) 537c478bd9Sstevel@tonic-gate int argc; 547c478bd9Sstevel@tonic-gate char *argv[]; 557c478bd9Sstevel@tonic-gate { 567c478bd9Sstevel@tonic-gate char buf[LOGLEN], *ctoday, *logname, tmpbuf[MAXBASENAME+1]; 577c478bd9Sstevel@tonic-gate FILE *fp; 587c478bd9Sstevel@tonic-gate time_t today; 597c478bd9Sstevel@tonic-gate extern char *ctime(); 607c478bd9Sstevel@tonic-gate extern FILE *fopen(); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate if ( argc != 2 ) { 637c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "USAGE: %s remotename\n", argv[0]); 647c478bd9Sstevel@tonic-gate exit(101); 657c478bd9Sstevel@tonic-gate } 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate if ( time(&today) != -1 ) { 687c478bd9Sstevel@tonic-gate ctoday = ctime(&today); 697c478bd9Sstevel@tonic-gate *(ctoday + strlen(ctoday) - 1) = '\0'; /* no ending \n */ 707c478bd9Sstevel@tonic-gate } else 717c478bd9Sstevel@tonic-gate ctoday = "NO DATE"; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate logname = cuserid((char *) NULL); 747c478bd9Sstevel@tonic-gate (void) strncpy(tmpbuf, argv[1], MAXBASENAME); 757c478bd9Sstevel@tonic-gate tmpbuf[MAXBASENAME] = '\0'; 767c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof(buf), "%s: call from system %s login %s\n", 777c478bd9Sstevel@tonic-gate ctoday, tmpbuf, (logname == NULL ? "<unknown>" : logname)); 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate errno = 0; 807c478bd9Sstevel@tonic-gate if ( (fp = fopen(FOREIGN, "a+")) == (FILE *)NULL ) 817c478bd9Sstevel@tonic-gate fall_on_sword("cannot open", buf); 827c478bd9Sstevel@tonic-gate if ( fputs(buf, fp) == EOF ) 837c478bd9Sstevel@tonic-gate fall_on_sword("cannot write", buf); 847c478bd9Sstevel@tonic-gate if ( fclose(fp) != 0 ) 857c478bd9Sstevel@tonic-gate fall_on_sword("cannot close", buf); 867c478bd9Sstevel@tonic-gate 87*462be471Sceastha return (0); 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* don't return from here */ 917c478bd9Sstevel@tonic-gate void 927c478bd9Sstevel@tonic-gate fall_on_sword(errmsg, logmsg) 937c478bd9Sstevel@tonic-gate char *errmsg, *logmsg; 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate char ebuf[BUFSIZ+1]; 967c478bd9Sstevel@tonic-gate int fds[2]; 977c478bd9Sstevel@tonic-gate size_t sz; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate (void) snprintf(ebuf, BUFSIZ, 1007c478bd9Sstevel@tonic-gate "To: %s\nSubject: %s %s\n\n%s %s:\t%s (%d)\nlog msg:\t%s", 1017c478bd9Sstevel@tonic-gate MAILTO, errmsg, FOREIGN, errmsg, FOREIGN, 102ace1a5f1Sdp strerror(errno), errno, logmsg); 1037c478bd9Sstevel@tonic-gate sz = strlen(ebuf); 1047c478bd9Sstevel@tonic-gate if (ebuf[sz-1] != '\n') { 1057c478bd9Sstevel@tonic-gate ebuf[sz] = '\n'; 1067c478bd9Sstevel@tonic-gate ebuf[sz+1] = '\0'; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* reset to real uid. get a pipe. put error message on */ 1107c478bd9Sstevel@tonic-gate /* "write end" of pipe, close it. dup "read end" to */ 1117c478bd9Sstevel@tonic-gate /* stdin and then execl mail (which will read the error */ 1127c478bd9Sstevel@tonic-gate /* message we just wrote). */ 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate if ( setuid(getuid()) == -1 || pipe(fds) != 0 1157c478bd9Sstevel@tonic-gate || write(fds[1], ebuf, strlen(ebuf)) != strlen(ebuf) 1167c478bd9Sstevel@tonic-gate || close(fds[1]) != 0 ) 1177c478bd9Sstevel@tonic-gate exit(errno); 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate if ( fds[0] != 0 ) { 1207c478bd9Sstevel@tonic-gate close(0); 1217c478bd9Sstevel@tonic-gate if ( dup(fds[0]) != 0 ) 1227c478bd9Sstevel@tonic-gate exit(errno); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate execl("/usr/bin/mail", "mail", MAILTO, (char *) 0); 1267c478bd9Sstevel@tonic-gate exit(errno); /* shouldn't get here */ 1277c478bd9Sstevel@tonic-gate } 128