1
0
Files
irix-657m-src/eoe/cmd/uucp/unknown.c
2022-09-29 17:59:04 +03:00

107 lines
2.4 KiB
C

/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */
#ident "$Revision: 1.5 $"
/*
* logs attempts by unknown remote machines to run uucico in FOREIGN
* ("/var/spool/uucp/.Admin/Foreign"). if anything goes wrong,
* sends mail to login MAILTO ("uucp"). the executable should be
* placed in /usr/lib/uucp/remote.unknown, and should run setuid-uucp.
*/
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#define FOREIGN "/var/spool/uucp/.Admin/Foreign"
#define MAILTO "uucp"
#define LOGLEN 256
void fall_on_sword(char *, char *);
void
main(argc, argv)
int argc;
char *argv[];
{
char buf[LOGLEN], *ctoday;
FILE *fp;
time_t today;
extern int errno;
#ifndef sgi
extern char *ctime();
extern FILE *fopen();
if ( argc != 2 ) {
fputs("USAGE: %s remotename\n", argv[0], stderr);
exit(101);
}
#else
if ( argc != 2 ) {
fprintf(stderr,"usage: %s remotename\n", argv[0]);
exit(101);
}
#endif
if ( time(&today) != -1 ) {
ctoday = ctime(&today);
*(ctoday + strlen(ctoday) - 1) = '\0'; /* no ending \n */
} else
ctoday = "NO DATE";
sprintf(buf, "%s: call from system %s login %s\n",
ctoday, argv[1], getlogin() );
errno = 0;
if ( (fp = fopen(FOREIGN, "a+")) == (FILE *)NULL )
fall_on_sword("cannot open", buf);
if ( fputs(buf, fp) == EOF )
fall_on_sword("cannot write", buf);
if ( fclose(fp) != 0 )
fall_on_sword("cannot close", buf);
exit(0);
}
/* don't return from here */
void
fall_on_sword(errmsg, logmsg)
char *errmsg, *logmsg;
{
char ebuf[BUFSIZ];
int fds[2];
extern int errno, sys_nerr;
extern char *sys_errlist[];
sprintf(ebuf, "%s %s:\t%s (%d)\nlog msg:\t%s",
errmsg, FOREIGN,
( errno < sys_nerr ? sys_errlist[errno] : "Unknown error " ),
errno, logmsg);
/* reset to real uid. get a pipe. put error message on */
/* "write end" of pipe, close it. dup "read end" to */
/* stdin and then execl mail (which will read the error */
/* message we just wrote). */
if ( setuid(getuid()) == -1 || pipe(fds) != 0
|| write(fds[1], ebuf, strlen(ebuf)) != strlen(ebuf)
|| close(fds[1]) != 0 )
exit(errno);
if ( fds[0] != 0 ) {
close(0);
if ( dup(fds[0]) != 0 )
exit(errno);
}
execl("/bin/mail", "mail", MAILTO, (char *)NULL);
exit(errno); /* shouldn't get here */
}