mirror of
https://github.com/samhocevar/rinetd.git
synced 2026-08-24 07:23:28 +08:00
Compare commits
56 Commits
v0.62.0sam
...
feature-pe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f9f97a963 | ||
|
|
718f4cddf7 | ||
|
|
b3550b8e77 | ||
|
|
9cd2114bcb | ||
|
|
982c14f46f | ||
|
|
8feb3e0513 | ||
|
|
96d60bcabb | ||
|
|
8b071acbe4 | ||
|
|
cb60037d58 | ||
|
|
a259a67e2d | ||
|
|
c92c0cf4bb | ||
|
|
53d670f9b1 | ||
|
|
86cba0ad56 | ||
|
|
e3c2b09c01 | ||
|
|
65273124f3 | ||
|
|
830b7e5fd1 | ||
|
|
f65f4d2506 | ||
|
|
f2d3ecd7f2 | ||
|
|
d4c4c99ec7 | ||
|
|
e365bf65f0 | ||
|
|
31f320a74d | ||
|
|
568b04acd6 | ||
|
|
af28930cd7 | ||
|
|
da1fbfbf4f | ||
|
|
ad8874362c | ||
|
|
e9f4d50051 | ||
|
|
13d8d29093 | ||
|
|
bbf92c9e85 | ||
|
|
cefb09eddd | ||
|
|
cd1de600aa | ||
|
|
990a368df0 | ||
|
|
10935c8dc6 | ||
|
|
4feb1ecd4f | ||
|
|
ed7fe3ce9d | ||
|
|
77548712d1 | ||
|
|
6c385facd2 | ||
|
|
bf11a9a4b5 | ||
|
|
f0e2370747 | ||
|
|
1a4306008c | ||
|
|
b1d6ce5356 | ||
|
|
bf40f07764 | ||
|
|
51d251776b | ||
|
|
fb7eb33697 | ||
|
|
b7c30a067e | ||
|
|
edeb1685d2 | ||
|
|
64a9c56c36 | ||
|
|
a01d7520ec | ||
|
|
9f490d550e | ||
|
|
54cf9badb2 | ||
|
|
e69b28d9a0 | ||
|
|
401a67b569 | ||
|
|
9ceb167e51 | ||
|
|
0090b40252 | ||
|
|
15ed538dcc | ||
|
|
8890e03ae9 | ||
|
|
54ca0fbd34 |
21
.travis.yml
Normal file
21
.travis.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
sudo: false
|
||||
language: c
|
||||
env: VERBOSE=1
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- build-essential
|
||||
- pkg-config
|
||||
|
||||
before_install:
|
||||
- ./bootstrap
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
55
CHANGES
55
CHANGES
@@ -1,55 +0,0 @@
|
||||
Version 0.1: original version.
|
||||
|
||||
Version 0.2: fixed bug when several reads are necessary
|
||||
on one end or the other before a write flushes them.
|
||||
Fixed bug which threw away data not yet sent to the
|
||||
other side on close, when running under Linux. Fixed
|
||||
associated bugs that probably affected other operating
|
||||
systems as well. Fixed bug causing long, perhaps
|
||||
indefinite pauses when a possible connection to a
|
||||
server socket went away before the accept() call,
|
||||
resulting in a blocking call.
|
||||
|
||||
Version 0.3: fixed additional bugs relating to
|
||||
the code previously used only by non-Linux OSes.
|
||||
This should fix problems such as connections not
|
||||
going away when they should or connections being
|
||||
mysteriously closed. Most of that code is now used by
|
||||
Linux also, so it is likely that rinetd is much closer
|
||||
to bug-free on non-Linux platforms. Of course, I don't
|
||||
actually have any to play with it on.
|
||||
|
||||
Version 0.4: added support for kill -1 (SIGHUP)
|
||||
and specification of service names instead of
|
||||
port numbers. Removed calls to realloc(), replacing
|
||||
them with code that should fail gracefully without
|
||||
crashing the program or breaking existing connections
|
||||
when another application is hogging memory.
|
||||
|
||||
Version 0.5: added logging in both tab-delimited
|
||||
and web-server-style formats. No longer exits if
|
||||
an individual configuration file line generates
|
||||
an error. Added allow and deny rules. Added
|
||||
-c command line option to specify a configuration file.
|
||||
|
||||
Version 0.51: fixed failure to check for an open
|
||||
log file before writing log entries.
|
||||
|
||||
Version 0.52: documentation added regarding the
|
||||
ability to bind to all IP addresses, if desired,
|
||||
using the special address 0.0.0.0.
|
||||
|
||||
Version 0.6: ported to Win32. Various compatibility
|
||||
fixes were made and some minor oversights without
|
||||
functional consequences were corrected.
|
||||
|
||||
Version 0.61: fixed a bug in 0.6 which completely
|
||||
broke rinetd under Linux. Oops.
|
||||
|
||||
Version 0.62: fixed a potential buffer overrun;
|
||||
prior versions failed to reallocate one of the
|
||||
arrays correctly when reallocating memory to
|
||||
accommodate more connections. Thanks to
|
||||
Sam Hocevar.
|
||||
|
||||
|
||||
73
CHANGES.md
Normal file
73
CHANGES.md
Normal file
@@ -0,0 +1,73 @@
|
||||
## Version 0.63
|
||||
|
||||
* added a `-f` flag to run in the foreground
|
||||
* quit cleanly when `SIGINT` is received
|
||||
* increased data buffer size for better performance
|
||||
* fixed random uninitialised data accesses
|
||||
* fixed a memory leak in connection reallocation
|
||||
* fixed a file descriptor leak in configuration reload
|
||||
* fixed configuration file parsing (many bugs including a buffer overflow)
|
||||
* fixed configuration error reporting (line numbers were wrong)
|
||||
* log accepted connections in addition to denied ones
|
||||
* log DNS errors
|
||||
* code quality refactoring: got rid of a lot of old code, used C
|
||||
library functions instead of custom ones, enforced `const` correctness
|
||||
|
||||
## Version 0.62
|
||||
|
||||
fixed a potential buffer overrun; prior versions failed to reallocate one of
|
||||
the arrays correctly when reallocating memory to accommodate more connections.
|
||||
Thanks to Sam Hocevar.
|
||||
|
||||
## Version 0.61
|
||||
|
||||
fixed a bug in 0.6 which completely broke rinetd under Linux. Oops.
|
||||
|
||||
## Version 0.6
|
||||
|
||||
ported to Win32. Various compatibility fixes were made and some minor
|
||||
oversights without functional consequences were corrected.
|
||||
|
||||
## Version 0.52
|
||||
|
||||
documentation added regarding the ability to bind to all IP addresses, if
|
||||
desired, using the special address 0.0.0.0.
|
||||
|
||||
## Version 0.51
|
||||
|
||||
fixed failure to check for an open log file before writing log entries.
|
||||
|
||||
## Version 0.5
|
||||
|
||||
added logging in both tab-delimited and web-server-style formats. No longer
|
||||
exits if an individual configuration file line generates an error. Added allow
|
||||
and deny rules. Added -c command line option to specify a configuration file.
|
||||
|
||||
## Version 0.4
|
||||
|
||||
added support for kill -1 (SIGHUP) and specification of service names instead
|
||||
of port numbers. Removed calls to realloc(), replacing them with code that
|
||||
should fail gracefully without crashing the program or breaking existing
|
||||
connections when another application is hogging memory.
|
||||
|
||||
## Version 0.3
|
||||
|
||||
fixed additional bugs relating to the code previously used only by non-Linux
|
||||
OSes. This should fix problems such as connections not going away when they
|
||||
should or connections being mysteriously closed. Most of that code is now
|
||||
used by Linux also, so it is likely that rinetd is much closer to bug-free on
|
||||
non-Linux platforms. Of course, I don't actually have any to play with it on.
|
||||
|
||||
## Version 0.2
|
||||
|
||||
fixed bug when several reads are necessary on one end or the other before a
|
||||
write flushes them. Fixed bug which threw away data not yet sent to the other
|
||||
side on close, when running under Linux. Fixed associated bugs that probably
|
||||
affected other operating systems as well. Fixed bug causing long, perhaps
|
||||
indefinite pauses when a possible connection to a server socket went away
|
||||
before the accept() call, resulting in a blocking call.
|
||||
|
||||
## Version 0.1
|
||||
|
||||
original version.
|
||||
|
||||
19
Makefile.am
19
Makefile.am
@@ -1,13 +1,26 @@
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign dist-bzip2
|
||||
|
||||
EXTRA_DIST = bootstrap CHANGES index.html \
|
||||
EXTRA_DIST = bootstrap CHANGES.md README.md index.html \
|
||||
getopt.c getopt.h $(man_MANS) $(sysconf_DATA)
|
||||
|
||||
man_MANS = rinetd.8
|
||||
sysconf_DATA = rinetd.conf
|
||||
|
||||
sbin_PROGRAMS = rinetd
|
||||
rinetd_SOURCES = rinetd.c match.c match.h
|
||||
rinetd_CFLAGS = -Wall -Wwrite-strings -I.
|
||||
rinetd_SOURCES = rinetd.c rinetd.h parse.h match.c match.h
|
||||
|
||||
GENERATED_SOURCES = parse.h
|
||||
|
||||
# If peg/leg is available, regenerate parse.h
|
||||
parse.h: parse.peg
|
||||
if which leg >/dev/null 2>&1; then leg -o $@ $^; else touch $@; fi
|
||||
|
||||
# _POSIX_C_SOURCE is for SA_RESTART and others
|
||||
# _XOPEN_SOURCE is for struct sigaction
|
||||
# _GNU_SOURCE is for h_errno and gethostbyname-related macros
|
||||
rinetd_CFLAGS = -std=c99 -D_XOPEN_SOURCE -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -Wall -Wextra -Wwrite-strings -I.
|
||||
|
||||
# This is for Travis CI; we don’t have a testsuite yet.
|
||||
test:
|
||||
|
||||
|
||||
14
README
14
README
@@ -1,14 +0,0 @@
|
||||
rinetd, by Thomas Boutell. Released under the terms of the GNU General
|
||||
Public License, version 2 or later.
|
||||
|
||||
This program is used to efficiently redirect connections from one IP
|
||||
address/port combination to another. It is useful when operating virtual
|
||||
servers, firewalls and the like.
|
||||
|
||||
To build under Unix, run "./bootstrap" to create the configuration
|
||||
files, then "./configure" to create the build files, and then type
|
||||
"make" to build rinetd. To install, type "make install" as root.
|
||||
|
||||
For documentation run "make install", then type "man rinetd" for
|
||||
details. Or, read index.html in your browser.
|
||||
|
||||
14
README.md
Normal file
14
README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
rinetd, by Thomas Boutell and Sam Hocevar. Released under the terms
|
||||
of the GNU General Public License, version 2 or later.
|
||||
|
||||
This program is used to efficiently redirect connections from one IP
|
||||
address/port combination to another. It is useful when operating virtual
|
||||
servers, firewalls and the like.
|
||||
|
||||
To build under Unix, run `./bootstrap` to create the configuration
|
||||
files, then `./configure` to create the build files, and then type
|
||||
`make` to build rinetd. To install, type `make install` as root.
|
||||
|
||||
For documentation run `make install`, then type `man rinetd` for
|
||||
details. Or, read `index.html` in your browser.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
AC_PREREQ(2.52)
|
||||
AC_INIT(rinetd, 0.62.0sam, sam@hocevar.net)
|
||||
AC_INIT(rinetd, 0.63, sam@hocevar.net)
|
||||
AC_CONFIG_AUX_DIR(.auto)
|
||||
AC_CONFIG_SRCDIR([getopt.h])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
@@ -11,6 +11,7 @@ AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB(ws2_32, main, [LIBS="${LIBS} -lws2_32"])
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
@@ -26,10 +27,11 @@ AC_CHECK_TYPES(socklen_t, [], [],
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_FORK
|
||||
AC_FUNC_MALLOC
|
||||
#XXX: disabled because of cross-compilation issues
|
||||
#AC_FUNC_MALLOC
|
||||
AC_TYPE_SIGNAL
|
||||
AC_FUNC_STRFTIME
|
||||
AC_CHECK_FUNCS([gethostbyname memset select socket strstr daemon sigaction])
|
||||
AC_CHECK_FUNCS([gethostbyname memset select socket strstr daemon fork sigaction])
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
448
index.html
448
index.html
@@ -1,244 +1,232 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>RINETD(8)</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #fffff0;
|
||||
}
|
||||
h3 {
|
||||
color: #ff8888;
|
||||
}
|
||||
blockquote,code {
|
||||
font-family: consolas, monospace, fixed;
|
||||
font-size: 0.9em;
|
||||
font-weight: bold;
|
||||
color: #555555;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body bgcolor="#FFFFF0">
|
||||
<body>
|
||||
<!--
|
||||
Copyright (c) 1997, 1998, 1999, Thomas Boutell and Boutell.Com, Inc.
|
||||
This software is released for free use under the terms of
|
||||
the GNU General Public License, version 2 or higher.
|
||||
-->
|
||||
<table>
|
||||
<tr>
|
||||
<th width=33% align=left>RINETD(8)
|
||||
<th width=33% align=right>Unix System Manager's Manual
|
||||
<th width=33% align=right>RINETD(8)
|
||||
</tr>
|
||||
<tr>
|
||||
<th width=33% align=left>RINETD(8)
|
||||
<th width=33% align=right>Unix System Manager's Manual
|
||||
<th width=33% align=right>RINETD(8)
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<font color="#FF8888" size="4">NAME</font>
|
||||
<p>
|
||||
rinetd -- internet ``redirection server''
|
||||
<p>
|
||||
<font color="#FF8888" size="4">SYNOPSIS</font>
|
||||
<p>
|
||||
<code>/usr/sbin/rinetd</code>
|
||||
<p>
|
||||
<font color="#FF8888" size="4">VERSION</font>
|
||||
<p>
|
||||
Version 0.62, 04/13/2003. Version 0.62 corrects a potential
|
||||
buffer overflow when reallocating memory to accommodate more
|
||||
connections. Upgrading is strongly recommended.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">WHERE TO GET</font>
|
||||
<p>
|
||||
<strong>For Linux:</strong>
|
||||
<a href="ftp://ftp.boutell.com/pub/boutell/rinetd/rinetd.tar.gz">By
|
||||
anonymous FTP from ftp.boutell.com</a> in the subdirectory
|
||||
<code>boutell/rinetd</code> as the file <code>rinetd.tar.gz</code>.
|
||||
<p>
|
||||
<strong>For Windows 95/98/NT:</strong>
|
||||
<a href="ftp://ftp.boutell.com/pub/boutell/rinetd/rinetd.zip">By
|
||||
anonymous FTP from ftp.boutell.com</a> in the subdirectory
|
||||
<code>boutell/rinetd</code> as the file <code>rinetd.zip</code>.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">DESCRIPTION</font>
|
||||
<p>
|
||||
Redirects TCP connections from one IP address and port to another. rinetd
|
||||
is a single-process server which handles any number of connections to
|
||||
the address/port pairs specified in the file <code>/etc/rinetd.conf</code>.
|
||||
Since rinetd runs as a single process using nonblocking I/O, it is
|
||||
able to redirect a large number of connections without a severe
|
||||
impact on the machine. This makes it practical to run TCP services
|
||||
on machines inside an IP masquerading firewall. rinetd <strong>does not
|
||||
redirect FTP,</strong> because FTP requires more than one socket.
|
||||
<p>
|
||||
rinetd is typically launched at boot time, using the following syntax:
|
||||
<p>
|
||||
<code>/usr/sbin/rinetd</code>
|
||||
<p>
|
||||
The configuration file is found in the file
|
||||
<code>/etc/rinetd.conf</code>, unless
|
||||
another file is specified using the <code>-c</code> command line option.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">FORWARDING RULES</font>
|
||||
<p>
|
||||
Most entries in the configuration file are forwarding rules. The
|
||||
format of a forwarding rule is as follows:
|
||||
<pre>
|
||||
bindaddress bindport connectaddress connectport
|
||||
</pre>
|
||||
For example:
|
||||
<pre>
|
||||
206.125.69.81 80 10.1.1.2 80
|
||||
</pre>
|
||||
Would redirect all connections to port 80 of the "real" IP address
|
||||
206.125.69.81, which could be a virtual interface, through
|
||||
rinetd to port 80 of the address 10.1.1.2, which would typically
|
||||
be a machine on the inside of a firewall which has no
|
||||
direct routing to the outside world.
|
||||
<p>
|
||||
Although responding on individual interfaces rather than on all
|
||||
interfaces is one of rinetd's primary features, sometimes it is
|
||||
preferable to respond on all IP addresses that belong to the server.
|
||||
In this situation, the special IP address <code>0.0.0.0</code>
|
||||
can be used. For example:
|
||||
<pre>
|
||||
0.0.0.0 23 10.1.1.2 23
|
||||
</pre>
|
||||
Would redirect all connections to port 23, for all IP addresses
|
||||
assigned to the server. This is the default behavior for most
|
||||
other programs.
|
||||
<p>
|
||||
Service names can be specified instead of port numbers. On most systems,
|
||||
service names are defined in the file /etc/services.
|
||||
<p>
|
||||
Both IP addresses and hostnames are accepted for
|
||||
bindaddress and connectaddress.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">ALLOW AND DENY RULES</font>
|
||||
<p>
|
||||
Configuration files can also contain allow and deny rules.
|
||||
<p>
|
||||
Allow rules which appear before the first forwarding rule are
|
||||
applied globally: if at least one global allow rule exists,
|
||||
and the address of a new connection does not
|
||||
satisfy at least one of the global allow rules, that connection
|
||||
is immediately rejected, regardless of any other rules.
|
||||
<p>
|
||||
Allow rules which appear after a specific forwarding rule apply
|
||||
to that forwarding rule only. If at least one allow rule
|
||||
exists for a particular forwarding rule, and the address of a new
|
||||
connection does not satisfy at least one of the allow rules
|
||||
for that forwarding rule, that connection is immediately
|
||||
rejected, regardless of any other rules.
|
||||
<p>
|
||||
Deny rules which appear before the first forwarding rule are
|
||||
applied globally: if the address of a new connection satisfies
|
||||
any of the global allow rules, that connection
|
||||
is immediately rejected, regardless of any other rules.
|
||||
<p>
|
||||
Deny rules which appear after a specific forwarding rule apply
|
||||
to that forwarding rule only. If the address of a new
|
||||
connection satisfies any of the deny rules for that forwarding rule,
|
||||
that connection is immediately rejected, regardless of any other rules.
|
||||
<p>
|
||||
The format of an allow rule is as follows:
|
||||
<pre>
|
||||
allow pattern
|
||||
</pre>
|
||||
Patterns can contain the following characters: 0, 1, 2, 3, 4, 5,
|
||||
6, 7, 8, 9, . (period), ?, and *. The ? wildcard matches any one
|
||||
character. The * wildcard matches any number of characters, including
|
||||
zero.
|
||||
<p>
|
||||
For example:
|
||||
<p>
|
||||
<pre>
|
||||
allow 206.125.69.*
|
||||
</pre>
|
||||
This allow rule matches all IP addresses in the 206.125.69 class C domain.
|
||||
<p>
|
||||
Host names are NOT permitted in allow and deny rules. The performance
|
||||
cost of looking up IP addresses to find their corresponding names
|
||||
is prohibitive. Since rinetd is a single process server, all other
|
||||
connections would be forced to pause during the address lookup.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">LOGGING</font>
|
||||
<p>
|
||||
rinetd is able to produce a log file in either of two formats:
|
||||
tab-delimited and web server-style "common log format."
|
||||
<p>
|
||||
By default, rinetd does not produce a log file. To activate logging, add
|
||||
the following line to the configuration file:
|
||||
<pre>
|
||||
logfile log-file-location
|
||||
</pre>
|
||||
Example:
|
||||
<pre>
|
||||
logfile /var/log/rinetd.log
|
||||
</pre>
|
||||
By default, rinetd logs in a simple tab-delimited format containing
|
||||
the following information:
|
||||
<p>
|
||||
Date and time<br>
|
||||
Client address<br>
|
||||
|
||||
Listening host
|
||||
<br>
|
||||
Listening port
|
||||
<br>
|
||||
Forwarded-to host
|
||||
<br>
|
||||
Forwarded-to port
|
||||
<br>
|
||||
Bytes received from client
|
||||
<br>
|
||||
Bytes sent to client
|
||||
<br>
|
||||
Result message
|
||||
<p>
|
||||
To activate web server-style "common log format" logging,
|
||||
add the following line to the configuration file:
|
||||
<pre>
|
||||
logcommon
|
||||
</pre>
|
||||
<p>
|
||||
<font color="#FF8888" size="4">COMMAND LINE OPTIONS</font>
|
||||
<p>
|
||||
The -c command line option is used to specify an alternate
|
||||
configuration file.
|
||||
<p>
|
||||
The -f command line option is used to run rinetd in the
|
||||
foreground, without forking to the background.
|
||||
<p>
|
||||
The -h command line option produces a short help message.
|
||||
<p>
|
||||
The -v command line option displays the version number.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">REINITIALIZING RINETD</font>
|
||||
<p>
|
||||
The kill -1 signal (SIGHUP) can be used to cause rinetd
|
||||
to reload its configuration file <strong>without</strong> interrupting existing
|
||||
connections. Under Linux(tm) the process id
|
||||
is saved in the file <code>/var/run/rinetd.pid</code>
|
||||
to facilitate the kill -HUP. An alternate
|
||||
file name can be provided by using the <code>pidlogfile</code>
|
||||
configuration file option.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">BUGS</font>
|
||||
<p>
|
||||
The server redirected to is not able to identify the host the
|
||||
client really came from. This cannot be corrected; however,
|
||||
the log produced by rinetd provides a way to obtain this
|
||||
information. Under Unix, sockets would theoretically lose data when closed
|
||||
with <code>SO_LINGER</code> turned off, but in Linux this is not the case
|
||||
(kernel source comments support this belief on my part). On non-Linux Unix
|
||||
platforms, alternate code which uses a different trick to work around
|
||||
blocking <code>close()</code> is provided, but this code is untested.
|
||||
<p>
|
||||
The logging is inadequate. The duration of the connection should be logged.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">LICENSE</font>
|
||||
<p>
|
||||
Copyright (c) 1997, 1998, 1999,
|
||||
<a href="http://www.boutell.com/boutell">Thomas Boutell</a> and
|
||||
<a href="http://www.boutell.com/">Boutell.Com, Inc.</a>
|
||||
This software is released for free use under the terms of
|
||||
the GNU General Public License, version 2 or higher.
|
||||
<p>
|
||||
<font color="#FF8888" size="4">CONTACT INFORMATION</font>
|
||||
<p>
|
||||
See <a href="http://www.boutell.com/rinetd">the rinetd web page</a>
|
||||
for the latest release.
|
||||
Thomas Boutell can be reached by email:
|
||||
<a href="mailto:boutell@boutell.com">boutell@boutell.com</a>
|
||||
<p>
|
||||
<font color="#FF8888" size="4">THANKS</font>
|
||||
<p>
|
||||
Thanks are due to Bill Davidsen, Libor Pechachek, Sascha Ziemann,
|
||||
Joel S. Noble, the Apache Group, and many others who have contributed
|
||||
advice, encouragement and/or source code to this and other open
|
||||
software projects.
|
||||
<h3>NAME</h3>
|
||||
|
||||
<p> rinetd -- internet “redirection server”</p>
|
||||
|
||||
<h3>SYNOPSIS</h3>
|
||||
|
||||
<p> <code>/usr/sbin/rinetd</code></p>
|
||||
|
||||
<h3>VERSION</h3>
|
||||
|
||||
<p> Version 0.63, 2017/07/19. Version 0.63 corrects several bugs including a
|
||||
denial of service security issue, and greatly improves performance, ease of
|
||||
use, and portability. </p>
|
||||
|
||||
<h3>WHERE TO GET</h3>
|
||||
<p> <a href="https://github.com/samhocevar/rinetd/releases">By HTTP on
|
||||
GitHub</a> in the releases section. </p>
|
||||
|
||||
<h3>DESCRIPTION</h3>
|
||||
|
||||
<p> Redirects TCP connections from one IP address and port to another. rinetd
|
||||
is a single-process server which handles any number of connections to the
|
||||
address/port pairs specified in the file <code>/etc/rinetd.conf</code>. Since
|
||||
rinetd runs as a single process using nonblocking I/O, it is able to redirect
|
||||
a large number of connections without a severe impact on the machine. This
|
||||
makes it practical to run TCP services on machines inside an IP masquerading
|
||||
firewall. rinetd <strong>does not redirect FTP</strong>, because FTP requires
|
||||
more than one socket. </p>
|
||||
|
||||
<p> rinetd is typically launched at boot time, using the following syntax: </p>
|
||||
|
||||
<blockquote>/usr/sbin/rinetd</blockquote>
|
||||
|
||||
<p> The configuration file is found in the file <code>/etc/rinetd.conf</code>,
|
||||
unless another file is specified using the <code>-c</code> command line option.
|
||||
</p>
|
||||
|
||||
<h3>FORWARDING RULES</h3>
|
||||
|
||||
<p> Most entries in the configuration file are forwarding rules. The format of
|
||||
a forwarding rule is as follows:
|
||||
<blockquote>bindaddress bindport connectaddress connectport</blockquote>
|
||||
For example:
|
||||
<blockquote>206.125.69.81 80 10.1.1.2 80</blockquote>
|
||||
Would redirect all connections to port 80 of the “real” IP address
|
||||
206.125.69.81, which could be a virtual interface, through rinetd to port 80
|
||||
of the address 10.1.1.2, which would typically be a machine on the inside of a
|
||||
firewall which has no direct routing to the outside world. </p>
|
||||
|
||||
<p> Although responding on individual interfaces rather than on all interfaces
|
||||
is one of rinetd's primary features, sometimes it is preferable to respond on
|
||||
all IP addresses that belong to the server. In this situation, the special IP
|
||||
address <code>0.0.0.0</code> can be used. For example:
|
||||
<blockquote>0.0.0.0 23 10.1.1.2 23</blockquote>
|
||||
Would redirect all connections to port 23, for all IP addresses assigned to the
|
||||
server. This is the default behavior for most other programs. </p>
|
||||
|
||||
<p> Service names can be specified instead of port numbers. On most systems,
|
||||
service names are defined in the file /etc/services. </p>
|
||||
|
||||
<p> Both IP addresses and hostnames are accepted for bindaddress and
|
||||
connectaddress. </p>
|
||||
|
||||
<h3>ALLOW AND DENY RULES</h3>
|
||||
|
||||
<p> Configuration files can also contain allow and deny rules. </p>
|
||||
|
||||
<p> Allow rules which appear before the first forwarding rule are applied
|
||||
globally: if at least one global allow rule exists, and the address of a new
|
||||
connection does not satisfy at least one of the global allow rules, that
|
||||
connection is immediately rejected, regardless of any other rules. </p>
|
||||
|
||||
<p> Allow rules which appear after a specific forwarding rule apply to that
|
||||
forwarding rule only. If at least one allow rule exists for a particular
|
||||
forwarding rule, and the address of a new connection does not satisfy at least
|
||||
one of the allow rules for that forwarding rule, that connection is immediately
|
||||
rejected, regardless of any other rules. </p>
|
||||
|
||||
<p> Deny rules which appear before the first forwarding rule are applied
|
||||
globally: if the address of a new connection satisfies any of the global deny
|
||||
rules, that connection is immediately rejected, regardless of any other rules.
|
||||
</p>
|
||||
|
||||
<p> Deny rules which appear after a specific forwarding rule apply to that
|
||||
forwarding rule only. If the address of a new connection satisfies any of the
|
||||
deny rules for that forwarding rule, that connection is immediately rejected,
|
||||
regardless of any other rules. </p>
|
||||
|
||||
<p> The format of an allow rule is as follows:
|
||||
<blockquote>allow pattern</blockquote>
|
||||
Patterns can contain the following characters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, .
|
||||
(period), ?, and *. The ? wildcard matches any one character. The * wildcard
|
||||
matches any number of characters, including zero. </p>
|
||||
|
||||
<p> For example: </p>
|
||||
|
||||
<p> <blockquote>allow 206.125.69.*</blockquote>
|
||||
This allow rule matches all IP addresses in the 206.125.69 class C domain. </p>
|
||||
|
||||
<p> Host names are NOT permitted in allow and deny rules. The performance cost
|
||||
of looking up IP addresses to find their corresponding names is prohibitive.
|
||||
Since rinetd is a single process server, all other connections would be forced
|
||||
to pause during the address lookup. </p>
|
||||
|
||||
<h3>LOGGING</h3>
|
||||
|
||||
<p> rinetd is able to produce a log file in either of two formats:
|
||||
tab-delimited and web server-style “common log format.” </p>
|
||||
|
||||
<p> By default, rinetd does not produce a log file. To activate logging, add
|
||||
the following line to the configuration file:
|
||||
<blockquote>logfile log-file-location</blockquote>
|
||||
Example:
|
||||
<blockquote>logfile /var/log/rinetd.log</blockquote>
|
||||
By default, rinetd logs in a simple tab-delimited format containing the
|
||||
following information: </p>
|
||||
|
||||
<ul>
|
||||
<li> Date and time </li>
|
||||
<li> Client address<br />
|
||||
<li> Listening host </li>
|
||||
<li> Listening port </li>
|
||||
<li> Forwarded-to host </li>
|
||||
<li> Forwarded-to port </li>
|
||||
<li> Bytes received from client </li>
|
||||
<li> Bytes sent to client </li>
|
||||
<li> Result message </li>
|
||||
</ul>
|
||||
|
||||
<p> To activate web server-style “common log format” logging, add the following
|
||||
line to the configuration file:
|
||||
<blockquote>logcommon</blockquote>
|
||||
</p>
|
||||
|
||||
<h3>COMMAND LINE OPTIONS</h3>
|
||||
|
||||
<p> The -c command line option is used to specify an alternate configuration
|
||||
file. </p>
|
||||
|
||||
<p> The -f command line option is used to run rinetd in the foreground, without
|
||||
forking to the background. </p>
|
||||
|
||||
<p> The -h command line option produces a short help message. </p>
|
||||
|
||||
<p> The -v command line option displays the version number. </p>
|
||||
|
||||
<h3>REINITIALIZING RINETD</h3>
|
||||
|
||||
<p> The kill -1 signal (SIGHUP) can be used to cause rinetd to reload
|
||||
its configuration file <strong>without</strong> interrupting existing
|
||||
connections. Under Linux(tm) the process id is saved in the file
|
||||
<code>/var/run/rinetd.pid</code> to facilitate the kill -HUP. An alternate file
|
||||
name can be provided by using the <code>pidlogfile</code> configuration file
|
||||
option. </p>
|
||||
|
||||
<h3>BUGS</h3>
|
||||
|
||||
<p> The server redirected to is not able to identify the host the client
|
||||
really came from. This cannot be corrected; however, the log produced by
|
||||
rinetd provides a way to obtain this information. Under Unix, sockets would
|
||||
theoretically lose data when closed with <code>SO_LINGER</code> turned off, but
|
||||
in Linux this is not the case (kernel source comments support this belief on
|
||||
my part). On non-Linux Unix platforms, alternate code which uses a different
|
||||
trick to work around blocking <code>close()</code> is provided, but this code
|
||||
is untested. </p>
|
||||
|
||||
<p> The logging is inadequate. The duration of the connection should be logged.
|
||||
</p>
|
||||
|
||||
<h3>LICENSE</h3>
|
||||
|
||||
<p> Copyright (c) 1997, 1998, 1999,
|
||||
<a href="http://www.boutell.com/boutell">Thomas Boutell</a> and
|
||||
<a href="http://www.boutell.com/">Boutell.Com, Inc.</a> </p>
|
||||
|
||||
<p> Copyright (c) 2003—2017 <a href="https://github.com/samhocevar">Sam
|
||||
Hocevar</a> </p>
|
||||
|
||||
<p> This software is released for free use under the terms of the GNU
|
||||
General Public License, version 2 or higher. </p>
|
||||
|
||||
<h3>CONTACT INFORMATION</h3>
|
||||
|
||||
<p> See <a href="https://github.com/samhocevar/rinetd/releases">the rinetd web
|
||||
page</a> for the latest release. </p>
|
||||
|
||||
<p> Thomas Boutell can be reached by email: <a
|
||||
href="mailto:boutell@boutell.com">boutell@boutell.com</a> </p>
|
||||
|
||||
<p> Sam Hocevar can be reached by email: <a
|
||||
href="mailto:sam@hocevar.net">sam@hocevar.net</a> </p>
|
||||
|
||||
<h3>THANKS</h3>
|
||||
|
||||
<p> Thanks are due to Bill Davidsen, Libor Pechachek, Sascha Ziemann, Joel
|
||||
S. Noble, the Apache Group, and many others who have contributed advice,
|
||||
encouragement and/or source code to this and other open software projects. </p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
6
match.c
6
match.c
@@ -20,7 +20,6 @@ int matchNoCase(char const *sorig, char const *p)
|
||||
|
||||
int matchBody(char const *sorig, char const *p, int nocase)
|
||||
{
|
||||
static int dummy = 0;
|
||||
/* Algorithm:
|
||||
|
||||
Word separator: *. End-of-string
|
||||
@@ -56,11 +55,6 @@ int matchBody(char const *sorig, char const *p, int nocase)
|
||||
|
||||
char const *s = sorig;
|
||||
int escaped = 0;
|
||||
if (strstr(p, "WS-0000")) {
|
||||
if (strstr(s, "ws_ftp_pro.html")) {
|
||||
dummy = 1;
|
||||
}
|
||||
}
|
||||
while (1) {
|
||||
char const *word;
|
||||
int wordLen;
|
||||
|
||||
182
parse.peg
Normal file
182
parse.peg
Normal file
@@ -0,0 +1,182 @@
|
||||
%{
|
||||
#define YY_CTX_LOCAL 1
|
||||
#define YY_CTX_MEMBERS \
|
||||
FILE *fp; \
|
||||
int currentLine; \
|
||||
int isAuthAllow; \
|
||||
unsigned int port, bindPort, connectPort; \
|
||||
char *bindAddress, *connectAddress;
|
||||
#define YY_INPUT(yyctx, buf, result, max_size) \
|
||||
{ \
|
||||
int yyc = fgetc(yyctx->fp); \
|
||||
result = (EOF == yyc) ? 0 : (*(buf) = yyc, 1); \
|
||||
}
|
||||
#define PARSE_ERROR exit(1);
|
||||
%}
|
||||
|
||||
file = (sol (line eol | invalid_syntax))*
|
||||
line = -? (rule | auth | logfile | pidlogfile | logcommon )? -? comment?
|
||||
|
||||
comment = "#" (!eol .)*
|
||||
|
||||
rule = bind_address - bind_port - connect_address - connect_port {
|
||||
/* Turn all of this stuff into reasonable addresses */
|
||||
struct in_addr iaddr;
|
||||
if (getAddress(yy->bindAddress, &iaddr) < 0) {
|
||||
fprintf(stderr, "rinetd: host %s could not be resolved.\n",
|
||||
yy->bindAddress);
|
||||
PARSE_ERROR;
|
||||
}
|
||||
/* Make a server socket */
|
||||
SOCKET fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (fd == INVALID_SOCKET) {
|
||||
syslog(LOG_ERR, "couldn't create "
|
||||
"server socket! (%m)\n");
|
||||
PARSE_ERROR;
|
||||
}
|
||||
struct sockaddr_in saddr;
|
||||
saddr.sin_family = AF_INET;
|
||||
memcpy(&saddr.sin_addr, &iaddr, sizeof(iaddr));
|
||||
saddr.sin_port = htons(yy->bindPort);
|
||||
int tmp = 1;
|
||||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(const char *) &tmp, sizeof(tmp));
|
||||
if (bind(fd, (struct sockaddr *)
|
||||
&saddr, sizeof(saddr)) == SOCKET_ERROR)
|
||||
{
|
||||
/* Warn -- don't exit. */
|
||||
syslog(LOG_ERR, "couldn't bind to "
|
||||
"address %s port %d (%m)\n",
|
||||
yy->bindAddress, yy->bindPort);
|
||||
closesocket(fd);
|
||||
PARSE_ERROR;
|
||||
}
|
||||
if (listen(fd, RINETD_LISTEN_BACKLOG) == SOCKET_ERROR) {
|
||||
/* Warn -- don't exit. */
|
||||
syslog(LOG_ERR, "couldn't listen to "
|
||||
"address %s port %d (%m)\n",
|
||||
yy->bindAddress, yy->bindPort);
|
||||
closesocket(fd);
|
||||
PARSE_ERROR;
|
||||
}
|
||||
#if _WIN32
|
||||
u_long ioctltmp;
|
||||
#else
|
||||
int ioctltmp;
|
||||
#endif
|
||||
ioctlsocket(fd, FIONBIO, &ioctltmp);
|
||||
if (getAddress(yy->connectAddress, &iaddr) < 0) {
|
||||
/* Warn -- don't exit. */
|
||||
syslog(LOG_ERR, "host %s could not be resolved.\n",
|
||||
yy->bindAddress);
|
||||
closesocket(fd);
|
||||
PARSE_ERROR;
|
||||
}
|
||||
/* Allocate server info */
|
||||
seInfo = (ServerInfo *)
|
||||
realloc(seInfo, sizeof(ServerInfo) * (seTotal + 1));
|
||||
if (!seInfo) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
ServerInfo *srv = &seInfo[seTotal];
|
||||
memset(srv, 0, sizeof(*srv));
|
||||
srv->fd = fd;
|
||||
srv->localAddr = iaddr;
|
||||
srv->localPort = htons(yy->connectPort);
|
||||
srv->fromHost = yy->bindAddress;
|
||||
if (!srv->fromHost) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
srv->fromPort = yy->bindPort;
|
||||
srv->toHost = yy->connectAddress;
|
||||
if (!srv->toHost) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
srv->toPort = yy->connectPort;
|
||||
#ifndef _WIN32
|
||||
if (fd > maxfd) {
|
||||
maxfd = fd;
|
||||
}
|
||||
#endif
|
||||
++seTotal;
|
||||
|
||||
yy->bindAddress = yy->connectAddress = NULL;
|
||||
}
|
||||
|
||||
bind_address = < ipv4 > { yy->bindAddress = strdup(yytext); }
|
||||
connect_address = < ipv4 > { yy->connectAddress = strdup(yytext); }
|
||||
bind_port = port { yy->bindPort = yy->port; }
|
||||
connect_port = port { yy->connectPort = yy->port; }
|
||||
|
||||
port = < (number | service) > {
|
||||
struct servent *bindService = getservbyname(yytext, "tcp");
|
||||
yy->port = bindService ? ntohs(bindService->s_port) : atoi(yytext);
|
||||
if (yy->port == 0 || yy->port >= 65536) {
|
||||
syslog(LOG_ERR, "bind port missing or out of range\n");
|
||||
PARSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
auth = auth_key - < pattern > {
|
||||
allRules = (Rule *)
|
||||
realloc(allRules, sizeof(Rule) * (allRulesCount + 1));
|
||||
if (!allRules) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
allRules[allRulesCount].pattern = strdup(yytext);
|
||||
if (!allRules[allRulesCount].pattern) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
allRules[allRulesCount].type = yy->isAuthAllow ? allowRule : denyRule;
|
||||
if (seTotal > 0) {
|
||||
if (seInfo[seTotal - 1].rulesStart == 0) {
|
||||
seInfo[seTotal - 1].rulesStart = allRulesCount;
|
||||
}
|
||||
++seInfo[seTotal - 1].rulesCount;
|
||||
} else {
|
||||
++globalRulesCount;
|
||||
}
|
||||
++allRulesCount;
|
||||
}
|
||||
|
||||
auth_key = < ("allow" | "deny") > { yy->isAuthAllow = (yytext[0] == 'a'); }
|
||||
|
||||
logfile = "logfile" - < filename > {
|
||||
logFileName = strdup(yytext);
|
||||
if (!logFileName) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
pidlogfile = "pidlogfile" - < filename > {
|
||||
pidLogFileName = strdup(yytext);
|
||||
if (!pidLogFileName) {
|
||||
PARSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
logcommon = "logcommon" {
|
||||
logFormatCommon = 1;
|
||||
}
|
||||
|
||||
invalid_syntax = < (!eol .)+ > eol {
|
||||
fprintf(stderr, "rinetd: invalid syntax at line %d: %s\n",
|
||||
yy->currentLine, yytext);
|
||||
PARSE_ERROR; /* FIXME */
|
||||
}
|
||||
|
||||
service = name
|
||||
ipv4 = number [.] number [.] number [.] number | '0'
|
||||
pattern = [0-9*?]+ ('.' [0-9*?]+ ('.' [0-9*?]+ ('.' [0-9*?]+)?)?)?
|
||||
number = digit+
|
||||
|
||||
name = [a-zA-Z][a-zA-Z0-9_]*
|
||||
filename = '"' [^"]+ '"'
|
||||
| [^ \t\r\n]+
|
||||
|
||||
- = [ \t]+
|
||||
digit = [0-9]
|
||||
sol = { ++yy->currentLine; }
|
||||
eol = '\r'? '\n' | eof
|
||||
eof = '\0'
|
||||
|
||||
44
rinetd.8
44
rinetd.8
@@ -2,7 +2,7 @@
|
||||
.\" This software is released for free use under the terms of
|
||||
.\" the GNU Public License, version 2 or higher.
|
||||
.\"
|
||||
.Dd February 18, 1999
|
||||
.Dd July 19, 2017
|
||||
.Dt RINETD 8
|
||||
.Os LINUX
|
||||
.Sh NAME
|
||||
@@ -12,12 +12,12 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm /usr/sbin/rinetd
|
||||
.Sh VERSION
|
||||
Version 0.62, 04/14/2003.
|
||||
Version 0.63, 2017/07/19.
|
||||
.Sh DESCRIPTION
|
||||
.Nm rinetd
|
||||
redirects TCP connections from one IP address and port to another. rinetd
|
||||
is a single-process server which handles any number of connections to
|
||||
the address/port pairs specified in the file /etc/rinetd.conf.
|
||||
the address/port pairs specified in the file /etc/rinetd.conf.
|
||||
Since rinetd runs as a single process using nonblocking I/O, it is
|
||||
able to redirect a large number of connections without a severe
|
||||
impact on the machine. This makes it practical to run TCP services
|
||||
@@ -29,7 +29,7 @@ rinetd is typically launched at boot time, using the following syntax:
|
||||
/usr/sbin/rinetd
|
||||
.Pp
|
||||
The configuration file is found in the file /etc/rinetd.conf, unless
|
||||
another file is specified using the -c command line option.
|
||||
another file is specified using the -c command line option.
|
||||
.Sh FORWARDING RULES
|
||||
Most entries in the configuration file are forwarding rules. The
|
||||
format of a forwarding rule is as follows:
|
||||
@@ -42,12 +42,12 @@ For example:
|
||||
.Pp
|
||||
Would redirect all connections to port 80 of the "real" IP address
|
||||
206.125.69.81, which could be a virtual interface, through
|
||||
rinetd to port 80 of the address 10.1.1.2, which would typically
|
||||
rinetd to port 80 of the address 10.1.1.2, which would typically
|
||||
be a machine on the inside of a firewall which has no
|
||||
direct routing to the outside world.
|
||||
.Pp
|
||||
Although responding on individual interfaces rather than on all
|
||||
interfaces is one of rinetd's primary features, sometimes it is
|
||||
interfaces is one of rinetd's primary features, sometimes it is
|
||||
preferable to respond on all IP addresses that belong to the server.
|
||||
In this situation, the special IP address 0.0.0.0
|
||||
can be used. For example:
|
||||
@@ -65,15 +65,15 @@ Both IP addresses and hostnames are accepted for
|
||||
bindaddress and connectaddress.
|
||||
.Pp
|
||||
.Sh ALLOW AND DENY RULES
|
||||
Configuration files can also contain allow and deny rules.
|
||||
Configuration files can also contain allow and deny rules.
|
||||
.Pp
|
||||
Allow rules which appear before the first forwarding rule are
|
||||
applied globally: if at least one global allow rule exists,
|
||||
and the address of a new connection does not
|
||||
satisfy at least one of the global allow rules, that connection
|
||||
is immediately rejected, regardless of any other rules.
|
||||
is immediately rejected, regardless of any other rules.
|
||||
.Pp
|
||||
Allow rules which appear after a specific forwarding rule apply
|
||||
Allow rules which appear after a specific forwarding rule apply
|
||||
to that forwarding rule only. If at least one allow rule
|
||||
exists for a particular forwarding rule, and the address of a new
|
||||
connection does not satisfy at least one of the allow rules
|
||||
@@ -82,12 +82,12 @@ rejected, regardless of any other rules.
|
||||
.Pp
|
||||
Deny rules which appear before the first forwarding rule are
|
||||
applied globally: if the address of a new connection satisfies
|
||||
any of the global allow rules, that connection
|
||||
is immediately rejected, regardless of any other rules.
|
||||
any of the global deny rules, that connection
|
||||
is immediately rejected, regardless of any other rules.
|
||||
.Pp
|
||||
Deny rules which appear after a specific forwarding rule apply
|
||||
Deny rules which appear after a specific forwarding rule apply
|
||||
to that forwarding rule only. If the address of a new
|
||||
connection satisfies any of the deny rules for that forwarding rule,
|
||||
connection satisfies any of the deny rules for that forwarding rule,
|
||||
that connection is immediately rejected, regardless of any other rules.
|
||||
.Pp
|
||||
The format of an allow rule is as follows:
|
||||
@@ -97,7 +97,7 @@ allow pattern
|
||||
Patterns can contain the following characters: 0, 1, 2, 3, 4, 5,
|
||||
6, 7, 8, 9, . (period), ?, and *. The ? wildcard matches any one
|
||||
character. The * wildcard matches any number of characters, including
|
||||
zero.
|
||||
zero.
|
||||
.Pp
|
||||
For example:
|
||||
.Pp
|
||||
@@ -114,7 +114,7 @@ connections would be forced to pause during the address lookup.
|
||||
rinetd is able to produce a log file in either of two formats:
|
||||
tab-delimited and web server-style "common log format."
|
||||
.Pp
|
||||
By default, rinetd does not produce a log file. To activate logging, add
|
||||
By default, rinetd does not produce a log file. To activate logging, add
|
||||
the following line to the configuration file:
|
||||
.Pp
|
||||
logfile log-file-location
|
||||
@@ -173,20 +173,26 @@ use a single TCP socket. This rules out FTP.
|
||||
The server redirected to is not able to identify the host the
|
||||
client really came from. This cannot be corrected; however,
|
||||
the log produced by rinetd provides a way to obtain this
|
||||
information. Under Unix, Sockets would theoretically lose data when closed
|
||||
with SO_LINGER turned off, but in Linux this is not the case (kernel
|
||||
source comments support this belief on my part). On non-Linux Unix platforms,
|
||||
information. Under Unix, Sockets would theoretically lose data when closed
|
||||
with SO_LINGER turned off, but in Linux this is not the case (kernel
|
||||
source comments support this belief on my part). On non-Linux Unix platforms,
|
||||
alternate code which uses a different trick to work around blocking close()
|
||||
is provided, but this code is untested. The logging is inadequate.
|
||||
The duration of each connection should be logged.
|
||||
.Sh LICENSE
|
||||
Copyright (c) 1997, 1998, 1999, Thomas Boutell and Boutell.Com, Inc.
|
||||
.Pp
|
||||
Copyright (c) 2003\-2017 Sam Hocevar
|
||||
.Pp
|
||||
This software is released for free use under the terms of
|
||||
the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
IS EXPRESSED OR IMPLIED. USE THIS SOFTWARE AT YOUR OWN RISK.
|
||||
.Sh CONTACT INFORMATION
|
||||
See http://www.boutell.com/rinetd/ for the latest release.
|
||||
See https://github.com/samhocevar/rinetd/releases for the latest release.
|
||||
.Pp
|
||||
Thomas Boutell can be reached by email: boutell@boutell.com
|
||||
.Pp
|
||||
Sam Hocevar can be reached by email: sam@hocevar.net
|
||||
.Sh THANKS
|
||||
Thanks are due to Bill Davidsen, Libor Pechachek, Sascha Ziemann, the
|
||||
Apache Group, and many others who have contributed advice
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
# to apply to only that forwarding rule
|
||||
#
|
||||
# bindadress bindport connectaddress connectport
|
||||
|
||||
127.0.0.1 4000 127.0.0.1 22
|
||||
#127.0.0.1 4000/udp 127.0.0.1 22
|
||||
|
||||
# logging information
|
||||
logfile /var/log/rinetd.log
|
||||
|
||||
69
rinetd.h
Normal file
69
rinetd.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Constants */
|
||||
|
||||
static int const RINETD_BUFFER_SIZE = 16384;
|
||||
static int const RINETD_LISTEN_BACKLOG = 128;
|
||||
|
||||
#define RINETD_CONFIG_FILE "/etc/rinetd.conf"
|
||||
#define RINETD_PID_FILE "/var/run/rinetd.pid"
|
||||
|
||||
/* Program state */
|
||||
|
||||
enum ruleType {
|
||||
allowRule,
|
||||
denyRule,
|
||||
};
|
||||
|
||||
typedef struct _rule Rule;
|
||||
struct _rule
|
||||
{
|
||||
char *pattern;
|
||||
int type;
|
||||
};
|
||||
|
||||
typedef struct _server_info ServerInfo;
|
||||
struct _server_info {
|
||||
SOCKET fd;
|
||||
|
||||
/* In network order, for network purposes */
|
||||
struct in_addr localAddr;
|
||||
unsigned short localPort;
|
||||
|
||||
/* In ASCII and local byte order, for logging purposes */
|
||||
char *fromHost, *toHost;
|
||||
int fromPort, toPort;
|
||||
|
||||
/* Offset and count into list of allow and deny rules. Any rules
|
||||
prior to globalAllowRules and globalDenyRules are global rules. */
|
||||
int rulesStart, rulesCount;
|
||||
};
|
||||
|
||||
typedef struct _socket Socket;
|
||||
struct _socket
|
||||
{
|
||||
SOCKET fd;
|
||||
/* recv: received on this socket
|
||||
sent: sent to this socket from the other buffer */
|
||||
int recvPos, sentPos;
|
||||
int recvBytes, sentBytes;
|
||||
char *buffer;
|
||||
};
|
||||
|
||||
typedef struct _connection_info ConnectionInfo;
|
||||
struct _connection_info
|
||||
{
|
||||
Socket remote, local;
|
||||
struct in_addr reAddresses;
|
||||
int coClosing;
|
||||
int coLog;
|
||||
ServerInfo const *server; // only useful for logEvent
|
||||
};
|
||||
|
||||
/* Option parsing */
|
||||
|
||||
typedef struct _rinetd_options RinetdOptions;
|
||||
struct _rinetd_options
|
||||
{
|
||||
char const *conf_file;
|
||||
int foreground;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user