/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
/* * mod_ident: Handle RFC 1413 ident request * obtained from rfc1413.c * * rfc1413() speaks a common subset of the RFC 1413, AUTH, TAP and IDENT * protocols. The code queries an RFC 1413 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. * * Author: Wietse Venema, Eindhoven University of Technology, * The Netherlands.
*/
/* Some small additions for Apache --- ditch the "sccsid" var if * compiling with gcc (it *has* changed), include ap_config.h for the * prototypes it defines on at least one system (SunlOSs) which has * them missing from the standard header files, and one minor change * below (extra parens around assign "if (foo = bar) ..." to shut up * gcc -Wall).
*/
#include"httpd.h"/* for server_rec, conn_rec, etc. */ #include"http_config.h" #include"http_core.h" #include"http_log.h"/* for aplog_error */ #include"util_ebcdic.h"
/* Whether we should enable rfc1413 identity checking */ #ifndef DEFAULT_RFC1413 #define DEFAULT_RFC1413 0 #endif
if ((rv = apr_sockaddr_info_get(&localsa, conn->local_ip, APR_UNSPEC,
0, /* ephemeral port */
0, conn->pool)) != APR_SUCCESS) { /* This should not fail since we have a numeric address string
* as the host. */
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, srv, APLOGNO(01492) "rfc1413: apr_sockaddr_info_get(%s) failed",
conn->local_ip); return rv;
}
if ((rv = apr_sockaddr_info_get(&destsa, conn->client_ip,
localsa->family, /* has to match */
RFC1413_PORT, 0, conn->pool)) != APR_SUCCESS) { /* This should not fail since we have a numeric address string
* as the host. */
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, srv, APLOGNO(01493) "rfc1413: apr_sockaddr_info_get(%s) failed",
conn->client_ip); return rv;
}
if ((rv = apr_socket_create(newsock,
localsa->family, /* has to match */
SOCK_STREAM, 0, conn->pool)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, srv, APLOGNO(01494) "rfc1413: error creating query socket"); return rv;
}
/* * 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 RFC1413 etc. * client sends only port numbers; the server takes the IP * addresses from the query socket.
*/
if ((rv = apr_socket_bind(*newsock, localsa)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, srv, APLOGNO(01496) "rfc1413: Error binding query socket to local port");
apr_socket_close(*newsock); return rv;
}
/* * errors from connect usually imply the remote machine doesn't support * the service; don't log such an error
*/ if ((rv = apr_socket_connect(*newsock, destsa)) != APR_SUCCESS) {
apr_socket_close(*newsock); return rv;
}
/* send the data */
buflen = apr_snprintf(buffer, sizeof(buffer), "%hu,%hu\r\n", sav_rmt_port,
sav_our_port);
ap_xlate_proto_to_ascii(buffer, buflen);
/* send query to server. Handle short write. */
i = 0; while (i < buflen) {
apr_size_t j = strlen(buffer + i);
apr_status_t status;
status = apr_socket_send(sock, buffer+i, &j); if (status != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv, APLOGNO(01497) "write: rfc1413: error sending request"); return status;
} elseif (j > 0) {
i+=j;
}
}
/* * Read response from server. - the response should be newline * terminated according to rfc - make sure it doesn't stomp its * way out of the buffer.
*/
i = 0;
memset(buffer, '\0', sizeof(buffer)); /* * Note that the strchr function below checks for \012 instead of '\n' * this allows it to work on both ASCII and EBCDIC machines.
*/ while ((cp = strchr(buffer, '\012')) == NULL && i < sizeof(buffer) - 1) {
apr_size_t j = sizeof(buffer) - 1 - i;
apr_status_t status;
status = apr_socket_recv(sock, buffer+i, &j); if (status != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv, APLOGNO(01498) "read: rfc1413: error reading response"); return status;
} elseif (j > 0) {
i+=j;
} elseif (status == APR_SUCCESS && j == 0) { /* Oops... we ran out of data before finding newline */ return APR_EINVAL;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.