From: Bradley Nicholes Date: Thu, 18 Sep 2003 18:54:26 +0000 (+0000) Subject: Enabled the RFC1413 ident functionality for Win32 and NetWare. Also introduced X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e500b9c6ecf0afd8e2d3cc8e44f1e2d92adaa78;p=thirdparty%2Fapache%2Fhttpd.git Enabled the RFC1413 ident functionality for Win32 and NetWare. Also introduced a thread-safe socket timeout alternative that can be adapted for other non-winsock platforms git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@101283 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/CHANGES b/src/CHANGES index 7115a108b44..e4aafd98bb2 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -1,5 +1,11 @@ Changes with Apache 1.3.29 + *) Enabled RFC1413 ident functionality for both Win32 and + NetWare platforms. This also included an alternate thread safe + implementation of the socket timout functionality when querying + the identd daemon. + [Brad Nicholes, William Rowe] + *) Prevent creation of subprocess Zombies when using CGI wrappers such as suExec and cgiwrap. PR 21737. [Numerous] diff --git a/src/main/rfc1413.c b/src/main/rfc1413.c index ebef8be6886..4df40403f07 100644 --- a/src/main/rfc1413.c +++ b/src/main/rfc1413.c @@ -99,6 +99,38 @@ int ap_rfc1413_timeout = RFC1413_TIMEOUT; /* Global so it can be changed */ +#if (defined (NETWARE) || defined (WIN32)) +#define write(a,b,c) send(a,b,c,0) +#define read(a,b,c) recv(a,b,c,0) +#endif + +#ifdef MULTITHREAD +#define RFC_USER_STATIC + +static int setsocktimeout (int sock, int timeout) +{ +#if (defined (NETWARE) || defined (WIN32)) + u_long msec = 0; + + /* Make sure that we are in blocking mode */ + if (ioctlsocket(sock, FIONBIO, &msec) == SOCKET_ERROR) { + return h_errno; + } + + /* Win32 timeouts are in msec, represented as int */ + msec = timeout * 1000; + setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, + (char *) &msec, sizeof(msec)); + setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, + (char *) &msec, sizeof(msec)); +#else + //XXX Needs to be implemented for non-winsock platforms +#endif + return 0; +} +#else /* MULTITHREAD */ + +#define RFC_USER_STATIC static static JMP_BUF timebuf; /* ident_timeout - handle timeouts */ @@ -106,6 +138,7 @@ static void ident_timeout(int sig) { ap_longjmp(timebuf, sig); } +#endif /* bind_connect - bind both ends of a socket */ /* Ambarish fix this. Very broken */ @@ -237,22 +270,28 @@ static int get_rfc1413(int sock, const struct sockaddr_in *our_sin, /* rfc1413 - return remote user name, given socket structures */ API_EXPORT(char *) ap_rfc1413(conn_rec *conn, server_rec *srv) { - static char user[RFC1413_USERLEN + 1]; /* XXX */ - static char *result; - static int sock; + RFC_USER_STATIC char user[RFC1413_USERLEN + 1]; /* XXX */ + RFC_USER_STATIC char *result; + RFC_USER_STATIC int sock; result = FROM_UNKNOWN; sock = ap_psocket_ex(conn->pool, AF_INET, SOCK_STREAM, IPPROTO_TCP, 1); if (sock < 0) { - ap_log_error(APLOG_MARK, APLOG_CRIT, srv, - "socket: rfc1413: error creating socket"); - conn->remote_logname = result; + ap_log_error(APLOG_MARK, APLOG_CRIT, srv, + "socket: rfc1413: error creating socket"); + conn->remote_logname = result; } /* * Set up a timer so we won't get stuck while waiting for the server. */ +#ifdef MULTITHREAD + if (setsocktimeout(sock, ap_rfc1413_timeout) == 0) { + if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0) + result = ap_pstrdup (conn->pool, user); + } +#else if (ap_setjmp(timebuf) == 0) { ap_set_callback_and_alarm(ident_timeout, ap_rfc1413_timeout); @@ -260,8 +299,10 @@ API_EXPORT(char *) ap_rfc1413(conn_rec *conn, server_rec *srv) result = user; } ap_set_callback_and_alarm(NULL, 0); +#endif ap_pclosesocket(conn->pool, sock); conn->remote_logname = result; return conn->remote_logname; } +