/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC
* 1413 protocols. It queries an RFC 931 etc. compatible daemon on a remote
* host to look up the owner of a connection. The information should not be
* used for authentication purposes. This routine intercepts alarm signals.
*
* Diagnostics are reported through syslog(3).
*
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#ifndef lint
#endif
/* System libraries. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
/* Local stuff. */
#include "tcpd.h"
/* fsocket - open stdio stream on top of socket */
int domain;
int type;
int protocol;
{
int s;
tcpd_warn("socket: %m");
return (0);
} else {
tcpd_warn("fdopen: %m");
close(s);
}
return (fp);
}
}
/* timeout - handle timeouts */
int sig;
{
}
/* rfc931 - return remote user name, given socket structures */
struct sockaddr_gen *rmt_sin;
struct sockaddr_gen *our_sin;
char *dest;
{
unsigned rmt_port;
unsigned our_port;
char *cp;
unsigned saved_timeout = 0;
/*
* Use one unbuffered stdio stream for writing to and for reading from
* the RFC931 etc. server. This is done because of a bug in the SunOS
* 4.1.x stdio library. The bug may live in other stdio implementations,
* too. When we use a single, buffered, bidirectional stdio stream ("r+"
* or "w+" mode) we read our own output. Such behaviour would make sense
* with resources that support random-access operations, but not with
* sockets.
*/
/*
* Set up a timer so we won't get stuck while waiting for the server.
*/
/*
* save the pending time in case the caller has armed an alarm.
*/
saved_timeout = alarm(0);
/*
* It's guaranteed to enter this 'if' condition on the direct
* invocation of setjmp and hence no additional checks while
* restoring the signal handler.
* Now, get the old handler and set the new one
*/
/*
* Bind the local and remote ends of the query socket to the same
* IP addresses as the connection under investigation. We go
* through all this trouble because the local or remote system
* might have more than one network address. The RFC931 etc.
* client sends only port numbers; the server takes the IP
* addresses from the query socket.
*/
our_query_sin = *our_sin;
rmt_query_sin = *rmt_sin;
SGSOCKADDRSZ(&our_query_sin)) >= 0 &&
SGSOCKADDRSZ(&rmt_query_sin)) >= 0) {
/*
* Send query to server. Neglect the risk that a 13-byte
* write would have to be fragmented by the local system and
* cause trouble with buggy System V stdio libraries.
*/
/*
* Read response from server. Use fgets()/sscanf() so we can
* work around System V stdio libraries that incorrectly
* assume EOF when a read from a socket returns less than
* requested.
*/
/*
* Strip trailing carriage return. It is part of the
* protocol, not part of the data.
*/
*cp = 0;
}
}
alarm(0);
}
/* Restore the old handler */
if (saved_timeout > 0)
}
}