4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 * logs attempts by unknown remote machines to run uucico in FOREIGN
34 * ("/var/uucp/.Admin/Foreign"). if anything goes wrong,
35 * sends mail to login MAILTO ("uucp"). the executable should be
36 * placed in /usr/lib/uucp/remote.unknown, and should run setuid-uucp.
40 #include <sys/types.h>
45 #define FOREIGN "/var/uucp/.Admin/Foreign"
56 char buf
[LOGLEN
], *ctoday
, *logname
, tmpbuf
[MAXBASENAME
+1];
63 (void) fprintf(stderr
, "USAGE: %s remotename\n", argv
[0]);
67 if ( time(&today
) != -1 ) {
68 ctoday
= ctime(&today
);
69 *(ctoday
+ strlen(ctoday
) - 1) = '\0'; /* no ending \n */
73 logname
= cuserid((char *) NULL
);
74 (void) strncpy(tmpbuf
, argv
[1], MAXBASENAME
);
75 tmpbuf
[MAXBASENAME
] = '\0';
76 (void) snprintf(buf
, sizeof(buf
), "%s: call from system %s login %s\n",
77 ctoday
, tmpbuf
, (logname
== NULL
? "<unknown>" : logname
));
80 if ( (fp
= fopen(FOREIGN
, "a+")) == (FILE *)NULL
)
81 fall_on_sword("cannot open", buf
);
82 if ( fputs(buf
, fp
) == EOF
)
83 fall_on_sword("cannot write", buf
);
84 if ( fclose(fp
) != 0 )
85 fall_on_sword("cannot close", buf
);
90 /* don't return from here */
92 fall_on_sword(errmsg
, logmsg
)
93 char *errmsg
, *logmsg
;
99 (void) snprintf(ebuf
, BUFSIZ
,
100 "To: %s\nSubject: %s %s\n\n%s %s:\t%s (%d)\nlog msg:\t%s",
101 MAILTO
, errmsg
, FOREIGN
, errmsg
, FOREIGN
,
102 strerror(errno
), errno
, logmsg
);
104 if (ebuf
[sz
-1] != '\n') {
109 /* reset to real uid. get a pipe. put error message on */
110 /* "write end" of pipe, close it. dup "read end" to */
111 /* stdin and then execl mail (which will read the error */
112 /* message we just wrote). */
114 if ( setuid(getuid()) == -1 || pipe(fds
) != 0
115 || write(fds
[1], ebuf
, strlen(ebuf
)) != strlen(ebuf
)
116 || close(fds
[1]) != 0 )
121 if ( dup(fds
[0]) != 0 )
125 execl("/usr/bin/mail", "mail", MAILTO
, (char *) 0);
126 exit(errno
); /* shouldn't get here */