mirror of
https://github.com/samhocevar/rinetd.git
synced 2026-08-24 07:23:28 +08:00
Compare commits
41 Commits
v0.62.1sam
...
v0.63
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
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.
|
||||
|
||||
11
Makefile.am
11
Makefile.am
@@ -1,17 +1,20 @@
|
||||
|
||||
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_SOURCES = rinetd.c rinetd.h match.c match.h
|
||||
|
||||
# _POSIX_C_SOURCE is for SA_RESTART and others
|
||||
# _XOPEN_SOURCE is for struct sigaction
|
||||
# _DEFAULT_SOURCE is for h_errno and gethostbyname-related macros
|
||||
rinetd_CFLAGS = -std=c99 -D_XOPEN_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -Wall -Wextra -Wwrite-strings -I.
|
||||
# _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
|
||||
|
||||
42
index.html
42
index.html
@@ -1,4 +1,4 @@
|
||||
<html>
|
||||
<html>
|
||||
<head>
|
||||
<title>RINETD(8)</title>
|
||||
<style>
|
||||
@@ -40,23 +40,13 @@ blockquote,code {
|
||||
|
||||
<h3>VERSION</h3>
|
||||
|
||||
<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>
|
||||
<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> <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>
|
||||
|
||||
<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>
|
||||
<p> <a href="https://github.com/samhocevar/rinetd/releases">By HTTP on
|
||||
GitHub</a> in the releases section. </p>
|
||||
|
||||
<h3>DESCRIPTION</h3>
|
||||
|
||||
@@ -213,17 +203,25 @@ is untested. </p>
|
||||
|
||||
<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>
|
||||
<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="http://www.boutell.com/rinetd">the rinetd web page</a>
|
||||
for the latest release. Thomas Boutell can be reached by email: <a
|
||||
<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
|
||||
|
||||
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;
|
||||
|
||||
12
rinetd.8
12
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,7 +12,7 @@
|
||||
.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
|
||||
@@ -181,12 +181,18 @@ 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
|
||||
|
||||
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