Included the changes needed to re-add the upstream proxy option.
This commit is contained in:
parent
e5b99e549d
commit
10317d6701
@ -1,4 +1,4 @@
|
||||
/* $Id: dnscache.c,v 1.1.1.1 2000-02-16 17:32:22 sdyoung Exp $
|
||||
/* $Id: dnscache.c,v 1.2 2000-03-11 20:37:44 rjkaes Exp $
|
||||
*
|
||||
* This is a caching DNS system. When a host name is needed we look it up here
|
||||
* and see if there is already an answer for it. The domains are placed in a
|
||||
@ -69,7 +69,6 @@ int lookup(struct in_addr *addr, char *domain)
|
||||
struct dnscache_s **rptr = &cache[box];
|
||||
struct dnscache_s *ptr = cache[box];
|
||||
|
||||
assert(addr);
|
||||
assert(domain);
|
||||
|
||||
while (ptr && strcasecmp(ptr->domain, domain)) {
|
||||
@ -90,7 +89,8 @@ int lookup(struct in_addr *addr, char *domain)
|
||||
/* chris - added this so that the routine can be used to just
|
||||
* look stuff up.
|
||||
*/
|
||||
if (addr) *addr = ptr->ipaddr;
|
||||
if (addr)
|
||||
*addr = ptr->ipaddr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
52
src/reqs.c
52
src/reqs.c
@ -1,4 +1,4 @@
|
||||
/* $Id: reqs.c,v 1.1.1.1 2000-02-16 17:32:23 sdyoung Exp $
|
||||
/* $Id: reqs.c,v 1.2 2000-03-11 20:37:44 rjkaes Exp $
|
||||
*
|
||||
* This is where all the work in tinyproxy is actually done. Incoming
|
||||
* connections are added to the active list of connections and then the header
|
||||
@ -227,7 +227,8 @@ static int clientreq(struct conn_s *connptr)
|
||||
/* chris - If domain is in dotted-quad format or is already in the
|
||||
* DNS cache, then go straight to WAITCONN.
|
||||
*/
|
||||
if (inet_aton(uri->authority, NULL) || lookup(NULL, uri->authority) == 0) {
|
||||
if (inet_aton(uri->authority, NULL)
|
||||
|| lookup(NULL, uri->authority)) {
|
||||
if ((fd = opensock(uri->authority, port_no)) < 0) {
|
||||
safefree(request);
|
||||
httperr(connptr, 500,
|
||||
@ -500,10 +501,54 @@ static int write_to_client(struct conn_s *connptr, fd_set * writefds)
|
||||
|
||||
inline static void newconn_req(struct conn_s *connptr, fd_set * readfds)
|
||||
{
|
||||
#ifdef UPSTREAM_PROXY
|
||||
int fd;
|
||||
char peer_ipaddr[PEER_IP_LENGTH];
|
||||
#endif /* UPSTREAM_PROXY */
|
||||
|
||||
assert(connptr);
|
||||
assert(readfds);
|
||||
|
||||
if (FD_ISSET(connptr->client_fd, readfds)) {
|
||||
#ifdef UPSTREAM_PROXY
|
||||
if (config.upstream_name && config.upstream_port != 0) {
|
||||
getpeer_ip(connptr->client_fd, peer_ipaddr);
|
||||
/* Log the incoming connection */
|
||||
if (!config.restricted) {
|
||||
log("Connect (upstream): %s", peer_ipaddr);
|
||||
}
|
||||
|
||||
if (inet_aton(config.upstream_name, NULL)
|
||||
|| lookup(NULL, config.upstream_name)) {
|
||||
if ((fd = opensock(config.upstream_name, config.upstream_port)) < 0) {
|
||||
httperr(connptr, 500,
|
||||
"Unable to connect to host (cannot create sock)");
|
||||
stats.num_badcons++;
|
||||
return;
|
||||
}
|
||||
|
||||
connptr->server_fd = fd;
|
||||
connptr->type = WAITCONN;
|
||||
}
|
||||
/* Otherwise submit a DNS request and hope for
|
||||
the best. */
|
||||
else {
|
||||
if (adns_submit(adns, config.upstream_name, adns_r_a, adns_qf_quoteok_cname | adns_qf_cname_loose, connptr, &(connptr->adns_qu))) {
|
||||
httperr(connptr, 500, "Resolver error connecting to host");
|
||||
stats.num_badcons++;
|
||||
return;
|
||||
} else {
|
||||
#ifdef __DEBUG__
|
||||
log("DNS request submitted");
|
||||
#endif
|
||||
/* copy domain for later caching */
|
||||
connptr->domain = xstrdup(config.upstream_name);
|
||||
connptr->port_no = config.upstream_port;
|
||||
connptr->type = DNS_WAITCONN;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (clientreq(connptr) < 0) {
|
||||
shutdown(connptr->client_fd, 2);
|
||||
connptr->type = FINISHCONN;
|
||||
@ -514,6 +559,9 @@ inline static void newconn_req(struct conn_s *connptr, fd_set * readfds)
|
||||
abort();
|
||||
|
||||
connptr->actiontime = time(NULL);
|
||||
#ifdef UPSTREAM_PROXY
|
||||
}
|
||||
#endif /* UPSTREAM_PROXY */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: tinyproxy.c,v 1.1.1.1 2000-02-16 17:32:23 sdyoung Exp $
|
||||
/* $Id: tinyproxy.c,v 1.2 2000-03-11 20:37:44 rjkaes Exp $
|
||||
*
|
||||
* The initialize routine. Basically sets up all the initial stuff (logfile,
|
||||
* listening socket, config options, etc.) and then sits there and loops
|
||||
@ -79,7 +79,11 @@ struct config_s config = {
|
||||
#endif /* FILTER_ENABLE */
|
||||
FALSE, /* Restrict the log to only errors */
|
||||
#ifdef XTINYPROXY
|
||||
NULL /* The name of this domain */
|
||||
NULL, /* The name of this domain */
|
||||
#endif
|
||||
#ifdef UPSTREAM_PROXY
|
||||
NULL, /* name of the upstream proxy */
|
||||
0, /* port of the upstream proxy */
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -198,30 +202,34 @@ static void usagedisp(void)
|
||||
|
||||
printf("Usage: tinyproxy [args]\n");
|
||||
printf("Options:\n");
|
||||
printf("\t-v\t\tdisplay version number\n");
|
||||
printf("\t-h\t\tdisplay usage\n");
|
||||
printf("\t-d\t\tdo not daemonize\n");
|
||||
printf
|
||||
("\t-n ip_address\tallow access from only this subnet. (i.e. 192.168.0.)\n");
|
||||
printf("\t-i ip_address\tonly listen on this address\n");
|
||||
printf("\t-p port\t\tlisten on 'port'\n");
|
||||
printf("\t-l logfile\tlog to 'logfile'\n");
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
printf("\t-S\t\tlog using the syslog instead\n");
|
||||
#endif
|
||||
printf("\t-r\t\trestrict the log to only errors\n");
|
||||
printf
|
||||
("\t-w load\t\tstop accepting new connections at 'load'. 0 disables\n");
|
||||
printf("\t-s stathost\tset stathost to 'stathost'\n");
|
||||
printf("\t-u user\t\tchange to user after startup. \"\" disables\n");
|
||||
printf("\t-a header\tallow 'header' through the anon block\n");
|
||||
printf("\t-d\t\tdo not daemonize\n");
|
||||
#ifdef FILTER_ENABLE
|
||||
printf("\t-f filterfile\tblock sites specified in filterfile\n");
|
||||
#endif /* FILTER_ENABLE */
|
||||
printf("\t-h\t\tdisplay usage\n");
|
||||
printf("\t-i ip_address\tonly listen on this address\n");
|
||||
printf("\t-l logfile\tlog to 'logfile'\n");
|
||||
printf
|
||||
("\t-n ip_address\tallow access from only this subnet. (i.e. 192.168.0.)\n");
|
||||
printf("\t-p port\t\tlisten on 'port'\n");
|
||||
printf("\t-r\t\trestrict the log to only errors\n");
|
||||
printf("\t-s stathost\tset stathost to 'stathost'\n");
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
printf("\t-S\t\tlog using the syslog instead\n");
|
||||
#endif
|
||||
#ifdef UPSTREAM_PROXY
|
||||
printf("\t-t domain:port\tredirect connections to an upstream proxy\n");
|
||||
#endif
|
||||
printf("\t-u user\t\tchange to user after startup. \"\" disables\n");
|
||||
printf("\t-v\t\tdisplay version number\n");
|
||||
printf
|
||||
("\t-w load\t\tstop accepting new connections at 'load'. 0 disables\n");
|
||||
#ifdef XTINYPROXY
|
||||
printf
|
||||
("\t-x domain\tAdd a XTinyproxy header with the peer's IP address\n");
|
||||
#endif
|
||||
/* UPSTREAM_PROXY */
|
||||
|
||||
/* Display the modes compiled into tinyproxy */
|
||||
printf("\nFeatures Compiled In:\n");
|
||||
@ -235,6 +243,9 @@ static void usagedisp(void)
|
||||
#ifndef NDEBUG
|
||||
printf(" Debuggin code\n");
|
||||
#endif /* NDEBUG */
|
||||
#ifdef UPSTREAM_PROXY
|
||||
printf(" Upstream proxy\n");
|
||||
#endif /* UPSTREAM_PROXY */
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -243,10 +254,14 @@ int main(int argc, char **argv)
|
||||
flag usage = FALSE, godaemon = TRUE, changeid = FALSE;
|
||||
struct passwd *thisuser = NULL;
|
||||
|
||||
#ifdef UPSTREAM_PROXY
|
||||
char *upstream_ptr;
|
||||
#endif /* UPSTREAM_PROXY */
|
||||
|
||||
struct allowedhdr_s **rpallowedptr = &allowedhdrs;
|
||||
struct allowedhdr_s *allowedptr = allowedhdrs, *newallowed;
|
||||
|
||||
while ((optch = getopt(argc, argv, "vh?dp:l:Sa:w:s:u:n:i:rx:f:")) !=
|
||||
while ((optch = getopt(argc, argv, "vh?dp:l:Sa:w:s:u:n:i:rx:f:t:")) !=
|
||||
EOF) {
|
||||
switch (optch) {
|
||||
case 'v':
|
||||
@ -347,6 +362,28 @@ int main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef UPSTREAM_PROXY
|
||||
case 't':
|
||||
if (!(upstream_ptr = strchr(optarg, ':'))) {
|
||||
log("tinyproxy: invalid UPSTREAM declaration");
|
||||
break;
|
||||
}
|
||||
|
||||
*upstream_ptr++ = '\0';
|
||||
if (!(config.upstream_name = xstrdup(optarg))) {
|
||||
log("tinyproxy: could not allocate memory");
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
config.upstream_port = atoi(upstream_ptr);
|
||||
#ifndef NDEBUG
|
||||
log("upstream name: %s", config.upstream_name);
|
||||
log("upstream port: %d", config.upstream_port);
|
||||
#endif /* NDEBUG */
|
||||
|
||||
break;
|
||||
#endif /* UPSTREAM_PROXY */
|
||||
|
||||
case '?':
|
||||
case 'h':
|
||||
default:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: tinyproxy.h,v 1.1.1.1 2000-02-16 17:32:23 sdyoung Exp $
|
||||
/* $Id: tinyproxy.h,v 1.2 2000-03-11 20:37:44 rjkaes Exp $
|
||||
*
|
||||
* See 'tinyproxy.c' for a detailed description.
|
||||
*
|
||||
@ -58,6 +58,10 @@ struct config_s {
|
||||
#ifdef XTINYPROXY
|
||||
char *my_domain;
|
||||
#endif
|
||||
#ifdef UPSTREAM_PROXY
|
||||
char *upstream_name;
|
||||
int upstream_port;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct stat_s {
|
||||
|
Loading…
Reference in New Issue
Block a user