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 */
{
ap_longjmp(timebuf, sig);
}
+#endif
/* bind_connect - bind both ends of a socket */
/* Ambarish fix this. Very broken */
/* 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);
result = user;
}
ap_set_callback_and_alarm(NULL, 0);
+#endif
ap_pclosesocket(conn->pool, sock);
conn->remote_logname = result;
return conn->remote_logname;
}
+