mirror of
https://github.com/samhocevar/rinetd.git
synced 2026-08-19 12:53:29 +08:00
Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4e0a60119 | ||
|
|
af88e6fd4f | ||
|
|
ff41723590 | ||
|
|
d3dd35327f | ||
|
|
49bf544bad | ||
|
|
1060048fe8 | ||
|
|
e3b47d086a | ||
|
|
f91e34c3af | ||
|
|
5e8be95d8a | ||
|
|
7887c17096 | ||
|
|
432aa4d230 | ||
|
|
b00f175fa4 | ||
|
|
6a1e7e75a3 | ||
|
|
7f76652af9 | ||
|
|
bb0d64ed5d | ||
|
|
3b33f45925 | ||
|
|
878c804d32 | ||
|
|
f9f5aeda80 | ||
|
|
655584ad78 | ||
|
|
4c5a7a1a22 | ||
|
|
7790a617d8 | ||
|
|
7781e97734 | ||
|
|
79bafee414 | ||
|
|
b7fcf65a97 | ||
|
|
c9de417f2e | ||
|
|
26b0e63bf5 | ||
|
|
f58db7ea8d | ||
|
|
7ef50421c0 | ||
|
|
0ef4f1042f | ||
|
|
f7cd21f91f | ||
|
|
a5905bbcea | ||
|
|
a1d2c297ba | ||
|
|
5a70f2bf4e | ||
|
|
7e287f5913 | ||
|
|
4f64342ed5 | ||
|
|
44f973d9fd | ||
|
|
a8ca595620 | ||
|
|
2f8fd87518 | ||
|
|
04d1b74e24 | ||
|
|
2681d17eb4 | ||
|
|
8bde6f6259 | ||
|
|
ae9af9d030 | ||
|
|
ebd31cc72e | ||
|
|
da497404ab | ||
|
|
d9f661ee5d | ||
|
|
0ea83281e3 | ||
|
|
a37e13c910 | ||
|
|
3e18951d7a | ||
|
|
9d140d8f87 | ||
|
|
dd17267afe |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.auto
|
||||
.deps
|
||||
.dirstamp
|
||||
Makefile
|
||||
Makefile.in
|
||||
stamp-*
|
||||
@@ -13,4 +14,8 @@ configure
|
||||
|
||||
*.o
|
||||
rinetd
|
||||
rinetd.exe
|
||||
|
||||
*.vcxproj.user
|
||||
Debug
|
||||
Release
|
||||
|
||||
22
CHANGES.md
22
CHANGES.md
@@ -1,11 +1,29 @@
|
||||
## Version 0.70
|
||||
## Version 0.73 (2021/02/19)
|
||||
|
||||
* improve error reporting
|
||||
* fixed another configuration parsing bug
|
||||
|
||||
## Version 0.72 (2021/02/16)
|
||||
|
||||
* fixed a configuration parsing bug making 0.71 almost unusable
|
||||
|
||||
## Version 0.71 (2021/02/14)
|
||||
|
||||
* IPv6 support
|
||||
* fixed a display overflow in data usage statistics
|
||||
* made the configuration parser more tolerant with service names that contain
|
||||
dashes (e.g. snmp-trap) or hostnames with underscores (e.g. \_http.example.com).
|
||||
* create the log file if it does not exist
|
||||
* new Visual Studio project file
|
||||
|
||||
## Version 0.70 (2017/09/09)
|
||||
|
||||
* UDP support
|
||||
* source address binding support
|
||||
* use a real grammar for the configuration file and get rid of the hand-made
|
||||
parser
|
||||
|
||||
## Version 0.63
|
||||
## Version 0.63 (2017/07/19)
|
||||
|
||||
* added a `-f` flag to run in the foreground
|
||||
* quit cleanly when `SIGINT` is received
|
||||
|
||||
339
COPYING
Normal file
339
COPYING
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
24
Makefile.am
24
Makefile.am
@@ -1,35 +1,19 @@
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign dist-bzip2
|
||||
|
||||
EXTRA_DIST = bootstrap CHANGES.md README.md index.html \
|
||||
parse.peg getopt.c getopt.h $(man_MANS) $(sysconf_DATA)
|
||||
SUBDIRS = src
|
||||
|
||||
EXTRA_DIST = bootstrap COPYING CHANGES.md README.md index.html rinetd.vcxproj \
|
||||
$(man_MANS) $(sysconf_DATA)
|
||||
|
||||
man_MANS = rinetd.8
|
||||
sysconf_DATA = rinetd.conf
|
||||
noinst_DATA = index.html
|
||||
|
||||
sbin_PROGRAMS = rinetd
|
||||
rinetd_SOURCES = rinetd.c rinetd.h \
|
||||
parse.c parse.h \
|
||||
match.c match.h \
|
||||
net.c net.h \
|
||||
types.h
|
||||
|
||||
BUILT_SOURCES = parse.c
|
||||
|
||||
# If peg/leg is available, regenerate parse.h
|
||||
parse.c: parse.peg
|
||||
if which leg >/dev/null 2>&1; then leg -o $@ $^; else touch $@; fi
|
||||
|
||||
# If roffit is available, regenerate index.html
|
||||
index.html: rinetd.8
|
||||
if which roffit >/dev/null 2>&1; then roffit < $^ > $@; 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:
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
AC_PREREQ(2.52)
|
||||
AC_INIT(rinetd, 0.70, sam@hocevar.net)
|
||||
AC_INIT(rinetd, 0.73, sam@hocevar.net)
|
||||
AC_CONFIG_AUX_DIR(.auto)
|
||||
AC_CONFIG_SRCDIR([getopt.h])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_SRCDIR([src/rinetd.c])
|
||||
AC_CONFIG_HEADER([src/config.h])
|
||||
AM_INIT_AUTOMAKE([no-define tar-ustar silent-rules])
|
||||
|
||||
# Checks for programs.
|
||||
@@ -21,6 +21,8 @@ AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h netdb.h netinet/in.h stdlib.h stri
|
||||
AC_C_CONST
|
||||
AC_HEADER_TIME
|
||||
AC_STRUCT_TM
|
||||
AC_CHECK_TYPES(ssize_t, [], [],
|
||||
[#include <sys/types.h>])
|
||||
AC_CHECK_TYPES(socklen_t, [], [],
|
||||
[#include <sys/types.h>
|
||||
#include <sys/socket.h>])
|
||||
@@ -34,4 +36,5 @@ AC_FUNC_STRFTIME
|
||||
AC_CHECK_FUNCS([gethostbyname memset select socket strstr daemon fork sigaction])
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_CONFIG_FILES([src/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -79,7 +79,7 @@ p.roffit {
|
||||
<p class="level0">Ports default to TCP. To specify the protocol, append <span Class="emphasis">/udp</span> or <span Class="emphasis">/tcp</span> to the port number:
|
||||
<p class="level0"><span Class="bold"> 206.125.69.81 80/tcp 10.1.1.2 8000/udp</span>
|
||||
<p class="level0">Service names can be specified instead of port numbers. On most systems, service names are defined in the file <span Class="emphasis">/etc/services</span>.
|
||||
<p class="level0">Both IP addresses and hostnames are accepted for bindaddress and connectaddress.
|
||||
<p class="level0">Both IP addresses and hostnames are accepted for bindaddress and connectaddress, including IPv6.
|
||||
<p class="level0">
|
||||
<p class="level0"><a name="UDP"></a><h2 class="nroffsh">UDP timeout option</h2>
|
||||
<p class="level0">Since UDP is a connectionless protocol, a timeout is necessary or forwarding connections may accumulate with time and exhaust resources. By default, if no data is sent or received on a UDP connection for 72 seconds, the other connection is closed. This value can be changed using the <span Class="emphasis">timeout</span> option:
|
||||
@@ -87,8 +87,8 @@ p.roffit {
|
||||
<p class="level0">This rule will forward all data received on UDP port 8000 to host 10.1.1.2 on TCP port 80, and will close the connection after no data is received on the UDP port for 3600 seconds.
|
||||
<p class="level0"><a name="Source"></a><h2 class="nroffsh">Source address option</h2>
|
||||
<p class="level0">A forwarding rule option allows to bind to a specific local address when sending data to the other end. This is done using the <span Class="emphasis">src</span> option:
|
||||
<p class="level0"><span Class="bold"> 192.168.1.1 80 10.1.1.2 80 [src=192.168.1.2]</span>
|
||||
<p class="level0">Assuming the local host has two IP addresses, 192.168.1.1 and 192.168.1.2, this rule ensures that forwarded packets are sent using source address 192.168.1.2.
|
||||
<p class="level0"><span Class="bold"> 192.168.1.1 80 10.1.1.127 80 [src=10.1.1.2]</span>
|
||||
<p class="level0">Assuming the local host has two IP addresses, 10.1.1.1 and 10.1.1.2, this rule ensures that forwarded packets are sent using source address 10.1.1.2.
|
||||
<p class="level0"><a name="ALLOW"></a><h2 class="nroffsh">ALLOW AND DENY RULES</h2>
|
||||
<p class="level0">Configuration files can also contain allow and deny rules.
|
||||
<p class="level0">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.
|
||||
@@ -130,7 +130,7 @@ p.roffit {
|
||||
<p class="level0">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 <span Class="bold">rinetd</span> 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, alternate code which uses a different trick to work around blocking close() is provided, but this code is untested.
|
||||
<p class="level0">The logging is inadequate. The duration of each connection should be logged. <a name="LICENSE"></a><h2 class="nroffsh">LICENSE</h2>
|
||||
<p class="level0">Copyright (c) 1997, 1998, 1999, Thomas Boutell and Boutell.Com, Inc.
|
||||
<p class="level0">Copyright (c) 2003-2017 Sam Hocevar
|
||||
<p class="level0">Copyright (c) 2003-2021 Sam Hocevar
|
||||
<p class="level0">This software is released for free use under the terms of the GNU General Public License, version 2 or higher. NO WARRANTY IS EXPRESSED OR IMPLIED. USE THIS SOFTWARE AT YOUR OWN RISK. <a name="CONTACT"></a><h2 class="nroffsh">CONTACT INFORMATION</h2>
|
||||
<p class="level0">See https://github.com/samhocevar/rinetd/releases for the latest release.
|
||||
<p class="level0">Thomas Boutell can be reached by email: boutell@boutell.com
|
||||
|
||||
35
net.c
35
net.c
@@ -1,35 +0,0 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
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. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "net.h"
|
||||
|
||||
void setSocketDefaults(SOCKET fd)
|
||||
{
|
||||
/* Make socket non-blocking (FIXME: this uses legacy API) */
|
||||
FIONBIO_ARG_T ioctltmp = 1;
|
||||
#if _WIN32
|
||||
ioctlsocket(fd, FIONBIO, &ioctltmp);
|
||||
#else
|
||||
ioctl(fd, FIONBIO, &ioctltmp);
|
||||
#endif
|
||||
|
||||
#if defined __linux__
|
||||
int tmp = 0;
|
||||
setsockopt(fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
|
||||
#if !defined __linux__ && !defined _WIN32
|
||||
int tmp = 1024;
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
}
|
||||
|
||||
12
rinetd.8
12
rinetd.8
@@ -1,4 +1,4 @@
|
||||
.TH rinetd 8 "2017-09-09" "rinetd 0.70"
|
||||
.TH rinetd 8 "2021-02-19" "rinetd 0.73"
|
||||
|
||||
.SH NAME
|
||||
rinetd \- internet redirection server
|
||||
@@ -80,7 +80,7 @@ Service names can be specified instead of port numbers. On most systems,
|
||||
service names are defined in the file \fI/etc/services\fR.
|
||||
.PP
|
||||
Both IP addresses and hostnames are accepted for
|
||||
bindaddress and connectaddress.
|
||||
bindaddress and connectaddress, including IPv6.
|
||||
.PP
|
||||
|
||||
.SS UDP timeout option
|
||||
@@ -99,10 +99,10 @@ the UDP port for 3600 seconds.
|
||||
A forwarding rule option allows to bind to a specific local address when
|
||||
sending data to the other end. This is done using the \fIsrc\fR option:
|
||||
.PP
|
||||
\fB 192.168.1.1 80 10.1.1.2 80 [src=192.168.1.2]\fR
|
||||
\fB 192.168.1.1 80 10.1.1.127 80 [src=10.1.1.2]\fR
|
||||
.PP
|
||||
Assuming the local host has two IP addresses, 192.168.1.1 and 192.168.1.2, this
|
||||
rule ensures that forwarded packets are sent using source address 192.168.1.2.
|
||||
Assuming the local host has two IP addresses, 10.1.1.1 and 10.1.1.2, this
|
||||
rule ensures that forwarded packets are sent using source address 10.1.1.2.
|
||||
|
||||
.SH ALLOW AND DENY RULES
|
||||
Configuration files can also contain allow and deny rules.
|
||||
@@ -216,7 +216,7 @@ 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
|
||||
Copyright (c) 2003\-2021 Sam Hocevar
|
||||
.PP
|
||||
This software is released for free use under the terms of
|
||||
the GNU General Public License, version 2 or higher. NO WARRANTY
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#
|
||||
# allow 192.168.2.*
|
||||
# deny 192.168.2.1?
|
||||
# allow fe80:*
|
||||
# deny 2001:618:*:e43f
|
||||
|
||||
|
||||
#
|
||||
@@ -17,6 +19,8 @@
|
||||
#
|
||||
# bindadress bindport connectaddress connectport options...
|
||||
# 0.0.0.0 80 192.168.1.2 80
|
||||
# ::1 80 192.168.1.2 80
|
||||
# 0.0.0.0 80 fe80::1 80
|
||||
# 127.0.0.1 4000 127.0.0.1 3000
|
||||
# 127.0.0.1 4000/udp 127.0.0.1 22 [timeout=1200]
|
||||
# 127.0.0.1 8000/udp 192.168.1.2 8000/udp [src=192.168.1.2,timeout=1200]
|
||||
|
||||
110
rinetd.vcxproj
Normal file
110
rinetd.vcxproj
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\getopt.c" />
|
||||
<ClCompile Include="src\match.c" />
|
||||
<ClCompile Include="src\net.c" />
|
||||
<ClCompile Include="src\parse.c" />
|
||||
<ClCompile Include="src\rinetd.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\getopt.h" />
|
||||
<ClInclude Include="src\match.h" />
|
||||
<ClInclude Include="src\net.h" />
|
||||
<ClInclude Include="src\parse.h" />
|
||||
<ClInclude Include="src\rinetd.h" />
|
||||
<ClInclude Include="src\types.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="src\parse.peg" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{3F1D9D58-3205-48E9-9C93-557291A45D74}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>rinetd</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_CONSOLE;PACKAGE_VERSION="0.73";_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
24
src/Makefile.am
Normal file
24
src/Makefile.am
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
EXTRA_DIST = parse.peg getopt.c getopt.h
|
||||
|
||||
sbin_PROGRAMS = ../rinetd
|
||||
___rinetd_SOURCES = rinetd.c rinetd.h \
|
||||
parse.c parse.h \
|
||||
match.c match.h \
|
||||
net.c net.h \
|
||||
types.h
|
||||
|
||||
BUILT_SOURCES = parse.c
|
||||
|
||||
# If peg/leg is available, regenerate parse.h
|
||||
parse.c: parse.peg
|
||||
if which leg >/dev/null 2>&1; then leg -o $@ $^; else touch $@; fi
|
||||
|
||||
# _POSIX_C_SOURCE is for SA_RESTART and others
|
||||
# _DARWIN_C_SOURCE is for NI_MAXHOST on OS X
|
||||
# _XOPEN_SOURCE is for struct sigaction
|
||||
# _GNU_SOURCE is for h_errno and gethostbyname-related macros
|
||||
___rinetd_CFLAGS = -std=c99 -D_POSIX_C_SOURCE=200809L \
|
||||
-D_XOPEN_SOURCE -D_GNU_SOURCE -D_DARWIN_C_SOURCE \
|
||||
-Wall -Wextra -Wwrite-strings
|
||||
|
||||
85
src/net.c
Normal file
85
src/net.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2021 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
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. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "net.h"
|
||||
|
||||
void setSocketDefaults(SOCKET fd) {
|
||||
/* Make socket non-blocking (FIXME: this uses legacy API) */
|
||||
FIONBIO_ARG_T ioctltmp = 1;
|
||||
#if _WIN32
|
||||
ioctlsocket(fd, FIONBIO, &ioctltmp);
|
||||
#else
|
||||
ioctl(fd, FIONBIO, &ioctltmp);
|
||||
#endif
|
||||
|
||||
#if defined __linux__
|
||||
int tmp = 0;
|
||||
setsockopt(fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
|
||||
#if !defined __linux__ && !defined _WIN32
|
||||
int tmp = 1024;
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
}
|
||||
|
||||
int getAddrInfoWithProto(char *address, char *port, int protocol, struct addrinfo **ai)
|
||||
{
|
||||
struct addrinfo hints = {
|
||||
.ai_family = AF_UNSPEC,
|
||||
.ai_protocol = protocol,
|
||||
.ai_socktype = protocol == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM,
|
||||
.ai_flags = AI_PASSIVE,
|
||||
};
|
||||
|
||||
int ret = getaddrinfo(address, port, &hints, ai);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "rinetd: cannot resolve host \"%s\" port %s "
|
||||
"(getaddrinfo() error: %s)\n",
|
||||
address, port ? port : "<null>", gai_strerror(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sameSocketAddress(struct sockaddr_storage *a, struct sockaddr_storage *b) {
|
||||
if (a->ss_family != b->ss_family)
|
||||
return 0;
|
||||
|
||||
switch (a->ss_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *a4 = (struct sockaddr_in *)a;
|
||||
struct sockaddr_in *b4 = (struct sockaddr_in *)b;
|
||||
return a4->sin_port == b4->sin_port
|
||||
&& a4->sin_addr.s_addr == b4->sin_addr.s_addr;
|
||||
}
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)a;
|
||||
struct sockaddr_in6 *b6 = (struct sockaddr_in6 *)b;
|
||||
return a6->sin6_port == b6->sin6_port
|
||||
&& a6->sin6_addr.s6_addr == b6->sin6_addr.s6_addr;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t getPort(struct addrinfo* ai) {
|
||||
switch (ai->ai_family) {
|
||||
case AF_INET:
|
||||
return ntohs(((struct sockaddr_in*)ai->ai_addr)->sin_port);
|
||||
case AF_INET6:
|
||||
return ntohs(((struct sockaddr_in6*)ai->ai_addr)->sin6_port);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
© 2003—2021 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
This software is released for free use under the terms of
|
||||
the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
@@ -12,6 +12,8 @@
|
||||
/* Define this to a reasonably large value */
|
||||
# define FD_SETSIZE 4096
|
||||
# include <winsock2.h>
|
||||
# include <ws2ipdef.h>
|
||||
# include <ws2tcpip.h>
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
@@ -22,6 +24,8 @@
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined HAVE_ERRNO_H
|
||||
# include <errno.h>
|
||||
#endif
|
||||
@@ -36,6 +40,12 @@
|
||||
# include <sys/filio.h>
|
||||
#endif /* FIONBIO */
|
||||
|
||||
#if HAVE_SSIZE_T
|
||||
# define SSIZE_T ssize_t
|
||||
#else
|
||||
# define SSIZE_T int
|
||||
#endif
|
||||
|
||||
#if HAVE_SOCKLEN_T
|
||||
# define SOCKLEN_T socklen_t
|
||||
#else
|
||||
@@ -53,6 +63,10 @@
|
||||
# ifndef WSAEAGAIN
|
||||
# define WSAEAGAIN WSAEWOULDBLOCK
|
||||
# endif
|
||||
# ifdef gai_strerror
|
||||
# undef gai_strerror
|
||||
# define gai_strerror gai_strerrorA
|
||||
# endif
|
||||
#else
|
||||
/* Windows sockets compatibility defines */
|
||||
# define INVALID_SOCKET (-1)
|
||||
@@ -71,4 +85,6 @@ static inline int GetLastError(void) {
|
||||
#endif /* _WIN32 */
|
||||
|
||||
void setSocketDefaults(SOCKET fd);
|
||||
|
||||
int sameSocketAddress(struct sockaddr_storage *a, struct sockaddr_storage *b);
|
||||
int getAddrInfoWithProto(char *address, char *port, int protocol, struct addrinfo **ai);
|
||||
uint16_t getPort(struct addrinfo* ai);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
# Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
# and Boutell.Com, Inc.
|
||||
# © 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
# © 2003—2021 Sam Hocevar <sam@hocevar.net>
|
||||
#
|
||||
# This software is released for free use under the terms of
|
||||
# the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
@@ -21,9 +21,8 @@
|
||||
FILE *fp; \
|
||||
int currentLine; \
|
||||
int isAuthAllow; \
|
||||
char *tmpPort; \
|
||||
int tmpPortNum, tmpProto; \
|
||||
int bindPortNum, bindProto, connectPortNum, connectProto; \
|
||||
char *tmpPort, *bindPort, *connectPort; \
|
||||
int tmpProto, bindProto, connectProto; \
|
||||
int serverTimeout; \
|
||||
char *bindAddress, *connectAddress, *sourceAddress;
|
||||
#define YY_INPUT(yyctx, buf, result, max_size) \
|
||||
@@ -32,6 +31,10 @@
|
||||
result = (EOF == yyc) ? 0 : (*(buf) = yyc, 1); \
|
||||
}
|
||||
#define PARSE_ERROR exit(1);
|
||||
#define MEMORY_ERROR { \
|
||||
logError("could not allocate memory when parsing configuration.\n"); \
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
#if defined __clang__
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
@@ -50,18 +53,24 @@ comment = "#" (!eol .)*
|
||||
|
||||
server-rule = bind-address - bind-port - connect-address - connect-port (-? server-options)?
|
||||
{
|
||||
addServer(yy->bindAddress, yy->bindPortNum, yy->bindProto,
|
||||
yy->connectAddress, yy->connectPortNum, yy->connectProto,
|
||||
addServer(yy->bindAddress, yy->bindPort, yy->bindProto,
|
||||
yy->connectAddress, yy->connectPort, yy->connectProto,
|
||||
yy->serverTimeout > 0 ? yy->serverTimeout : RINETD_DEFAULT_UDP_TIMEOUT,
|
||||
yy->sourceAddress);
|
||||
free(yy->bindAddress);
|
||||
free(yy->connectAddress);
|
||||
free(yy->sourceAddress);
|
||||
yy->bindAddress = yy->connectAddress = yy->sourceAddress = NULL;
|
||||
free(yy->bindPort);
|
||||
free(yy->connectPort);
|
||||
yy->bindPort = yy->connectPort = NULL;
|
||||
yy->serverTimeout = 0;
|
||||
}
|
||||
|
||||
bind-address = < address > { yy->bindAddress = strdup(yytext); }
|
||||
connect-address = < address > { yy->connectAddress = strdup(yytext); }
|
||||
bind-port = full-port { yy->bindPortNum = yy->tmpPortNum; yy->bindProto = yy->tmpProto; }
|
||||
connect-port = full-port { yy->connectPortNum = yy->tmpPortNum; yy->connectProto = yy->tmpProto; }
|
||||
bind-port = full-port { yy->bindPort = yy->tmpPort; yy->bindProto = yy->tmpProto; }
|
||||
connect-port = full-port { yy->connectPort = yy->tmpPort; yy->connectProto = yy->tmpProto; }
|
||||
server-options = "[" -? option-list -? "]"
|
||||
|
||||
option-list = option (-? ',' -? option-list)?
|
||||
@@ -70,35 +79,26 @@ option-timeout = "timeout" -? "=" -? < number > { yy->serverTimeout = atoi(
|
||||
option-source = "src" -? "=" -? < address > { yy->sourceAddress = strdup(yytext); }
|
||||
|
||||
full-port = port proto
|
||||
{
|
||||
char const *proto = yy->tmpProto == protoTcp ? "tcp" : "udp";
|
||||
struct servent *service = getservbyname(yy->tmpPort, proto);
|
||||
yy->tmpPortNum = service ? ntohs(service->s_port) : atoi(yy->tmpPort);
|
||||
if (yy->tmpPortNum == 0 || yy->tmpPortNum >= 65536) {
|
||||
syslog(LOG_ERR, "port %s/%s missing or out of range\n", yy->tmpPort, proto);
|
||||
PARSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
port = < (number | service) > { yy->tmpPort = strdup(yytext); }
|
||||
proto = '/tcp' { yy->tmpProto = protoTcp; }
|
||||
| '/udp' { yy->tmpProto = protoUdp; }
|
||||
| '' { yy->tmpProto = protoTcp; }
|
||||
proto = '/tcp' { yy->tmpProto = IPPROTO_TCP; }
|
||||
| '/udp' { yy->tmpProto = IPPROTO_UDP; }
|
||||
| '' { yy->tmpProto = IPPROTO_TCP; }
|
||||
|
||||
auth-rule = auth-key - < pattern >
|
||||
{
|
||||
allRules = (Rule *)
|
||||
realloc(allRules, sizeof(Rule) * (allRulesCount + 1));
|
||||
if (!allRules) {
|
||||
PARSE_ERROR;
|
||||
MEMORY_ERROR;
|
||||
}
|
||||
allRules[allRulesCount].pattern = strdup(yytext);
|
||||
if (!allRules[allRulesCount].pattern) {
|
||||
PARSE_ERROR;
|
||||
MEMORY_ERROR;
|
||||
}
|
||||
allRules[allRulesCount].type = yy->isAuthAllow ? allowRule : denyRule;
|
||||
if (seTotal > 0) {
|
||||
if (seInfo[seTotal - 1].rulesStart == 0) {
|
||||
if (seInfo[seTotal - 1].rulesStart == 0 && seInfo[seTotal - 1].rulesCount == 0) {
|
||||
seInfo[seTotal - 1].rulesStart = allRulesCount;
|
||||
}
|
||||
++seInfo[seTotal - 1].rulesCount;
|
||||
@@ -114,7 +114,7 @@ logfile = "logfile" - < filename >
|
||||
{
|
||||
logFileName = strdup(yytext);
|
||||
if (!logFileName) {
|
||||
PARSE_ERROR;
|
||||
MEMORY_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ pidlogfile = "pidlogfile" - < filename >
|
||||
{
|
||||
pidLogFileName = strdup(yytext);
|
||||
if (!pidLogFileName) {
|
||||
PARSE_ERROR;
|
||||
MEMORY_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,26 +133,31 @@ logcommon = "logcommon"
|
||||
|
||||
invalid_syntax = < (!eol .)+ > eol
|
||||
{
|
||||
fprintf(stderr, "rinetd: invalid syntax at line %d: %s\n",
|
||||
logError("invalid syntax at line %d: %s\n",
|
||||
yy->currentLine, yytext);
|
||||
PARSE_ERROR; /* FIXME */
|
||||
}
|
||||
|
||||
service = name
|
||||
address = ipv4 | hostname # TODO: IPV6
|
||||
pattern = [0-9*?]+ ('.' [0-9*?]+ ('.' [0-9*?]+ ('.' [0-9*?]+)?)?)?
|
||||
address = ipv4 | ipv6 | hostname
|
||||
pattern = (hexdigit | '[' | ']' | ':' | '.' | [*?] )+
|
||||
number = digit+
|
||||
|
||||
ipv4 = number '.' number '.' number '.' number | '0'
|
||||
hostname = ([-0-9a-zA-Z_]+ '.')* [a-zA-Z][-0-9a-zA-Z_]* '.'?
|
||||
ipv4 = number '.' number '.' number '.' number | '0'
|
||||
ipv6 = '[' bare_ipv6 ']' | bare_ipv6
|
||||
bare_ipv6 = hexdigit* ':' (hexdigit | ':')* # Must have at least one ':'
|
||||
hostname = (label '.')* name '.'?
|
||||
|
||||
|
||||
name = [a-zA-Z][a-zA-Z0-9_]*
|
||||
name = id ('-' | id | digit)*
|
||||
label = (id | digit) ('-' | id | digit)* # DNS labels may have digits
|
||||
filename = '"' [^"]+ '"'
|
||||
| [^ \t\r\n]+
|
||||
| [^ \t\r\n]+
|
||||
|
||||
- = [ \t]+
|
||||
digit = [0-9]
|
||||
hexdigit = [0-9a-fA-F]
|
||||
id = [a-zA-Z_]
|
||||
sol = { ++yy->currentLine; }
|
||||
eol = '\r'? '\n' | eof
|
||||
eof = '\0'
|
||||
@@ -163,17 +168,18 @@ void parseConfiguration(char const *file)
|
||||
{
|
||||
FILE *in = fopen(file, "r");
|
||||
if (!in) {
|
||||
PARSE_ERROR;
|
||||
logError("could not open configuration file %s.\n", file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
yycontext ctx;
|
||||
memset(&ctx, 0, sizeof(yycontext));
|
||||
ctx.fp = in;
|
||||
if (!yyparse(&ctx)) {
|
||||
syslog(LOG_ERR, "invalid syntax "
|
||||
"on file %s, line %d.\n", file, -1);
|
||||
logError("invalid syntax in file %s, line %d.\n", file, -1);
|
||||
exit(1);
|
||||
}
|
||||
yyrelease(&ctx);
|
||||
|
||||
fclose(in);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
© 2003—2021 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
This software is released for free use under the terms of
|
||||
the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
@@ -14,6 +14,10 @@
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
|
||||
#if _WIN32
|
||||
# include "getopt.h"
|
||||
#else
|
||||
@@ -24,9 +28,11 @@
|
||||
# elif HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# endif
|
||||
# include <syslog.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
@@ -76,7 +82,7 @@ int logFormatCommon = 0;
|
||||
FILE *logFile = NULL;
|
||||
|
||||
char const *logMessages[] = {
|
||||
"unknown-error",
|
||||
"unknown-error",
|
||||
"done-local-closed",
|
||||
"done-remote-closed",
|
||||
"accept-failed -",
|
||||
@@ -102,11 +108,13 @@ enum {
|
||||
logDenied,
|
||||
};
|
||||
|
||||
RinetdOptions options = {
|
||||
static RinetdOptions options = {
|
||||
RINETD_CONFIG_FILE,
|
||||
0,
|
||||
};
|
||||
|
||||
static int forked = 0;
|
||||
|
||||
static void selectPass(void);
|
||||
static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socket);
|
||||
static void handleRead(ConnectionInfo *cnx, Socket *socket, Socket *other_socket);
|
||||
@@ -115,7 +123,6 @@ static void handleClose(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
|
||||
static void handleAccept(ServerInfo const *srv);
|
||||
static ConnectionInfo *findAvailableConnection(void);
|
||||
static void setConnectionCount(int newCount);
|
||||
static int getAddress(char const *host, struct in_addr *iaddr);
|
||||
static int checkConnectionAllowed(ConnectionInfo const *cnx);
|
||||
|
||||
static int readArgs (int argc, char **argv, RinetdOptions *options);
|
||||
@@ -155,15 +162,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
readArgs(argc, argv, &options);
|
||||
|
||||
if (!options.foreground) {
|
||||
#if HAVE_DAEMON && !DEBUG
|
||||
if (!options.foreground && daemon(0, 0) != 0) {
|
||||
exit(0);
|
||||
}
|
||||
if (daemon(0, 0) != 0) {
|
||||
exit(0);
|
||||
}
|
||||
forked = 1;
|
||||
#elif HAVE_FORK && !DEBUG
|
||||
if (!options.foreground && fork() != 0) {
|
||||
exit(0);
|
||||
}
|
||||
if (fork() != 0) {
|
||||
exit(0);
|
||||
}
|
||||
forked = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if HAVE_SIGACTION
|
||||
struct sigaction act;
|
||||
@@ -185,7 +196,7 @@ int main(int argc, char *argv[])
|
||||
registerPID(pidLogFileName ? pidLogFileName : RINETD_PID_FILE);
|
||||
}
|
||||
|
||||
syslog(LOG_INFO, "Starting redirections...\n");
|
||||
logInfo("starting redirections...\n");
|
||||
while (1) {
|
||||
selectPass();
|
||||
}
|
||||
@@ -193,6 +204,38 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
void logError(char const *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
#if !_WIN32
|
||||
if (forked)
|
||||
vsyslog(LOG_ERR, fmt, ap);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "rinetd error: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void logInfo(char const *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
#if !_WIN32
|
||||
if (forked)
|
||||
vsyslog(LOG_INFO, fmt, ap);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "rinetd: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void clearConfiguration(void) {
|
||||
/* Remove references to server information */
|
||||
for (int i = 0; i < coTotal; ++i) {
|
||||
@@ -207,6 +250,11 @@ static void clearConfiguration(void) {
|
||||
}
|
||||
free(srv->fromHost);
|
||||
free(srv->toHost);
|
||||
freeaddrinfo(srv->fromAddrInfo);
|
||||
freeaddrinfo(srv->toAddrInfo);
|
||||
if (srv->sourceAddrInfo) {
|
||||
freeaddrinfo(srv->sourceAddrInfo);
|
||||
}
|
||||
}
|
||||
/* Free memory associated with previous set. */
|
||||
free(seInfo);
|
||||
@@ -238,111 +286,98 @@ static void readConfiguration(char const *file) {
|
||||
logFile = NULL;
|
||||
}
|
||||
if (logFileName) {
|
||||
logFile = fopen(logFileName, "a");
|
||||
logFile = fopen(logFileName, "a+");
|
||||
if (logFile) {
|
||||
setvbuf(logFile, NULL, _IONBF, 0);
|
||||
} else {
|
||||
syslog(LOG_ERR, "could not open %s to append (%m).\n",
|
||||
logError("could not open %s to append (%m).\n",
|
||||
logFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addServer(char *bindAddress, int bindPort, int bindProto,
|
||||
char *connectAddress, int connectPort, int connectProto,
|
||||
void addServer(char *bindAddress, char *bindPort, int bindProtocol,
|
||||
char *connectAddress, char *connectPort, int connectProtocol,
|
||||
int serverTimeout, char *sourceAddress)
|
||||
{
|
||||
/* Turn all of this stuff into reasonable addresses */
|
||||
struct in_addr iaddr;
|
||||
if (getAddress(bindAddress, &iaddr) < 0) {
|
||||
fprintf(stderr, "rinetd: host %s could not be resolved.\n",
|
||||
bindAddress);
|
||||
exit(1);
|
||||
}
|
||||
struct in_addr isourceaddr;
|
||||
isourceaddr.s_addr = INADDR_ANY;
|
||||
if (sourceAddress && getAddress(sourceAddress, &isourceaddr) < 0) {
|
||||
fprintf(stderr, "rinetd: host %s could not be resolved.\n",
|
||||
sourceAddress);
|
||||
exit(1);
|
||||
}
|
||||
ServerInfo si = {
|
||||
.fromHost = strdup(bindAddress),
|
||||
.toHost = strdup(connectAddress),
|
||||
.serverTimeout = serverTimeout,
|
||||
};
|
||||
|
||||
/* Make a server socket */
|
||||
SOCKET fd = socket(PF_INET,
|
||||
bindProto == protoTcp ? SOCK_STREAM : SOCK_DGRAM,
|
||||
bindProto == protoTcp ? IPPROTO_TCP : IPPROTO_UDP);
|
||||
if (fd == INVALID_SOCKET) {
|
||||
syslog(LOG_ERR, "couldn't create "
|
||||
"server socket! (%m)\n");
|
||||
exit(1);
|
||||
}
|
||||
struct sockaddr_in saddr;
|
||||
saddr.sin_family = AF_INET;
|
||||
memcpy(&saddr.sin_addr, &iaddr, sizeof(iaddr));
|
||||
saddr.sin_port = htons(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",
|
||||
bindAddress, bindPort);
|
||||
closesocket(fd);
|
||||
struct addrinfo *ai;
|
||||
int ret = getAddrInfoWithProto(bindAddress, bindPort, bindProtocol, &ai);
|
||||
if (ret != 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (bindProto == protoTcp) {
|
||||
if (listen(fd, RINETD_LISTEN_BACKLOG) == SOCKET_ERROR) {
|
||||
si.fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
if (si.fd == INVALID_SOCKET) {
|
||||
logError("couldn't create server socket! (%m)\n");
|
||||
freeaddrinfo(ai);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int tmp = 1;
|
||||
setsockopt(si.fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&tmp, sizeof(tmp));
|
||||
|
||||
if (bind(si.fd, ai->ai_addr, ai->ai_addrlen) == SOCKET_ERROR) {
|
||||
logError("couldn't bind to address %s port %s (%m)\n",
|
||||
bindAddress, bindPort);
|
||||
closesocket(si.fd);
|
||||
freeaddrinfo(ai);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (bindProtocol == IPPROTO_TCP) {
|
||||
if (listen(si.fd, RINETD_LISTEN_BACKLOG) == SOCKET_ERROR) {
|
||||
/* Warn -- don't exit. */
|
||||
syslog(LOG_ERR, "couldn't listen to "
|
||||
"address %s port %d (%m)\n",
|
||||
logError("couldn't listen to address %s port %s (%m)\n",
|
||||
bindAddress, bindPort);
|
||||
closesocket(fd);
|
||||
/* XXX: check whether this is correct */
|
||||
closesocket(si.fd);
|
||||
}
|
||||
|
||||
/* Make socket nonblocking in TCP mode only, otherwise
|
||||
we may miss some data. */
|
||||
setSocketDefaults(fd);
|
||||
setSocketDefaults(si.fd);
|
||||
}
|
||||
si.fromAddrInfo = ai;
|
||||
|
||||
if (getAddress(connectAddress, &iaddr) < 0) {
|
||||
/* Warn -- don't exit. */
|
||||
syslog(LOG_ERR, "host %s could not be resolved.\n",
|
||||
bindAddress);
|
||||
closesocket(fd);
|
||||
/* Resolve destination address. */
|
||||
ret = getAddrInfoWithProto(connectAddress, connectPort, connectProtocol, &ai);
|
||||
if (ret != 0) {
|
||||
freeaddrinfo(si.fromAddrInfo);
|
||||
closesocket(si.fd);
|
||||
exit(1);
|
||||
}
|
||||
si.toAddrInfo = ai;
|
||||
|
||||
/* Resolve source address if applicable. */
|
||||
if (sourceAddress) {
|
||||
ret = getAddrInfoWithProto(sourceAddress, NULL, connectProtocol, &ai);
|
||||
if (ret != 0) {
|
||||
freeaddrinfo(si.fromAddrInfo);
|
||||
freeaddrinfo(si.toAddrInfo);
|
||||
exit(1);
|
||||
}
|
||||
si.sourceAddrInfo = ai;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
if (si.fd > maxfd) {
|
||||
maxfd = si.fd;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate server info */
|
||||
seInfo = (ServerInfo *)
|
||||
realloc(seInfo, sizeof(ServerInfo) * (seTotal + 1));
|
||||
seInfo = (ServerInfo *)realloc(seInfo, sizeof(ServerInfo) * (seTotal + 1));
|
||||
if (!seInfo) {
|
||||
exit(1);
|
||||
}
|
||||
ServerInfo *srv = &seInfo[seTotal];
|
||||
memset(srv, 0, sizeof(*srv));
|
||||
srv->fd = fd;
|
||||
srv->localAddr = iaddr;
|
||||
srv->localPort = htons(connectPort);
|
||||
srv->fromHost = bindAddress;
|
||||
if (!srv->fromHost) {
|
||||
exit(1);
|
||||
}
|
||||
srv->fromPort = bindPort;
|
||||
srv->fromProto = bindProto;
|
||||
srv->sourceAddr = isourceaddr;
|
||||
srv->toHost = connectAddress;
|
||||
if (!srv->toHost) {
|
||||
exit(1);
|
||||
}
|
||||
srv->toPort = connectPort;
|
||||
srv->toProto = connectProto;
|
||||
srv->serverTimeout = serverTimeout;
|
||||
#ifndef _WIN32
|
||||
if (fd > maxfd) {
|
||||
maxfd = fd;
|
||||
}
|
||||
#endif
|
||||
seInfo[seTotal] = si;
|
||||
++seTotal;
|
||||
}
|
||||
|
||||
@@ -357,7 +392,7 @@ static void setConnectionCount(int newCount)
|
||||
closesocket(coInfo[i].local.fd);
|
||||
}
|
||||
if (coInfo[i].remote.fd != INVALID_SOCKET) {
|
||||
if (coInfo[i].remote.proto == protoTcp)
|
||||
if (coInfo[i].remote.protocol == IPPROTO_TCP)
|
||||
closesocket(coInfo[i].remote.fd);
|
||||
}
|
||||
free(coInfo[i].local.buffer);
|
||||
@@ -413,7 +448,7 @@ static ConnectionInfo *findAvailableConnection(void)
|
||||
int oldTotal = coTotal;
|
||||
setConnectionCount(coTotal * 4 / 3 + 8);
|
||||
if (coTotal == oldTotal) {
|
||||
syslog(LOG_ERR, "not enough memory to add slots. "
|
||||
logError("not enough memory to add slots. "
|
||||
"Currently %d slots.\n", coTotal);
|
||||
/* Go back to the previous total number of slots */
|
||||
return NULL;
|
||||
@@ -439,7 +474,12 @@ static void selectPass(void)
|
||||
timeout.tv_sec = timeout.tv_usec = 0;
|
||||
time_t now = time(NULL);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
fd_set* readfds = (fd_set*)alloca(sizeof(*readfds) * fdSetCount);
|
||||
fd_set* writefds = (fd_set*)alloca(sizeof(*writefds) * fdSetCount);
|
||||
#else
|
||||
fd_set readfds[fdSetCount], writefds[fdSetCount];
|
||||
#endif
|
||||
FD_ZERO_EXT(readfds);
|
||||
FD_ZERO_EXT(writefds);
|
||||
/* Server sockets */
|
||||
@@ -468,7 +508,7 @@ static void selectPass(void)
|
||||
if (cnx->remote.recvPos < RINETD_BUFFER_SIZE) {
|
||||
FD_SET_EXT(cnx->remote.fd, readfds);
|
||||
/* For UDP connections, we need to handle timeouts */
|
||||
if (cnx->remote.proto == protoUdp) {
|
||||
if (cnx->remote.protocol == IPPROTO_UDP) {
|
||||
long delay = (long)(cnx->remoteTimeout - now);
|
||||
timeout.tv_sec = delay <= 1 ? 1
|
||||
: (delay < timeout.tv_sec || timeout.tv_sec == 0) ? delay
|
||||
@@ -488,7 +528,7 @@ static void selectPass(void)
|
||||
if (cnx->remote.fd != INVALID_SOCKET) {
|
||||
/* Do not read on remote UDP sockets, the server does it,
|
||||
but handle timeouts instead. */
|
||||
if (cnx->remote.proto == protoTcp) {
|
||||
if (cnx->remote.protocol == IPPROTO_TCP) {
|
||||
if (FD_ISSET_EXT(cnx->remote.fd, readfds)) {
|
||||
handleRead(cnx, &cnx->remote, &cnx->local);
|
||||
}
|
||||
@@ -530,8 +570,8 @@ static void handleRead(ConnectionInfo *cnx, Socket *socket, Socket *other_socket
|
||||
if (RINETD_BUFFER_SIZE == socket->recvPos) {
|
||||
return;
|
||||
}
|
||||
int got = recv(socket->fd, socket->buffer + socket->recvPos,
|
||||
RINETD_BUFFER_SIZE - socket->recvPos, 0);
|
||||
int wanted = RINETD_BUFFER_SIZE - socket->recvPos;
|
||||
int got = recv(socket->fd, socket->buffer + socket->recvPos, wanted, 0);
|
||||
if (got < 0) {
|
||||
if (GetLastError() == WSAEWOULDBLOCK) {
|
||||
return;
|
||||
@@ -545,7 +585,7 @@ static void handleRead(ConnectionInfo *cnx, Socket *socket, Socket *other_socket
|
||||
handleClose(cnx, socket, other_socket);
|
||||
return;
|
||||
}
|
||||
socket->recvBytes += got;
|
||||
socket->totalBytesIn += got;
|
||||
socket->recvPos += got;
|
||||
}
|
||||
|
||||
@@ -556,7 +596,7 @@ static void handleUdpRead(ConnectionInfo *cnx, char const *buffer, int bytes)
|
||||
? bytes : RINETD_BUFFER_SIZE - socket->recvPos;
|
||||
if (got > 0) {
|
||||
memcpy(socket->buffer + socket->recvPos, buffer, got);
|
||||
socket->recvBytes += got;
|
||||
socket->totalBytesIn += got;
|
||||
socket->recvPos += got;
|
||||
}
|
||||
}
|
||||
@@ -566,7 +606,7 @@ static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
|
||||
if (cnx->coClosing && (socket->sentPos == other_socket->recvPos)) {
|
||||
PERROR("rinetd: local closed and no more output");
|
||||
logEvent(cnx, cnx->server, cnx->coLog);
|
||||
if (socket->proto == protoTcp)
|
||||
if (socket->protocol == IPPROTO_TCP)
|
||||
closesocket(socket->fd);
|
||||
socket->fd = INVALID_SOCKET;
|
||||
return;
|
||||
@@ -574,14 +614,14 @@ static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
|
||||
|
||||
struct sockaddr const *addr = NULL;
|
||||
SOCKLEN_T addrlen = 0;
|
||||
if (socket->proto == protoUdp && socket == &cnx->remote) {
|
||||
if (socket->protocol == IPPROTO_UDP && socket == &cnx->remote) {
|
||||
addr = (struct sockaddr const*)&cnx->remoteAddress;
|
||||
addrlen = (SOCKLEN_T)sizeof(cnx->remoteAddress);
|
||||
}
|
||||
|
||||
int wanted = other_socket->recvPos - socket->sentPos;
|
||||
int got = sendto(socket->fd, other_socket->buffer + socket->sentPos,
|
||||
other_socket->recvPos - socket->sentPos, 0,
|
||||
addr, addrlen);
|
||||
wanted, 0, addr, addrlen);
|
||||
if (got < 0) {
|
||||
if (GetLastError() == WSAEWOULDBLOCK) {
|
||||
return;
|
||||
@@ -593,8 +633,8 @@ static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
|
||||
return;
|
||||
}
|
||||
socket->sentPos += got;
|
||||
socket->sentBytes += got;
|
||||
if (socket->sentPos == other_socket->recvPos) {
|
||||
socket->totalBytesOut += got;
|
||||
if (got == wanted) {
|
||||
socket->sentPos = other_socket->recvPos = 0;
|
||||
}
|
||||
}
|
||||
@@ -602,16 +642,16 @@ static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
|
||||
static void handleClose(ConnectionInfo *cnx, Socket *socket, Socket *other_socket)
|
||||
{
|
||||
cnx->coClosing = 1;
|
||||
if (socket->proto == protoTcp) {
|
||||
if (socket->protocol == IPPROTO_TCP) {
|
||||
/* One end fizzled out, so make sure we're all done with that */
|
||||
closesocket(socket->fd);
|
||||
} else /* if (socket->proto == protoUdp) */ {
|
||||
} else /* if (socket->protocol == IPPROTO_UDP) */ {
|
||||
/* Nothing to do in UDP mode */
|
||||
}
|
||||
socket->fd = INVALID_SOCKET;
|
||||
|
||||
if (other_socket->fd != INVALID_SOCKET) {
|
||||
if (other_socket->proto == protoTcp) {
|
||||
if (other_socket->protocol == IPPROTO_TCP) {
|
||||
#if !defined __linux__ && !defined _WIN32
|
||||
/* Now set up the other end for a polite closing */
|
||||
|
||||
@@ -622,7 +662,7 @@ static void handleClose(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
|
||||
setsockopt(other_socket->fd, SOL_SOCKET, SO_SNDLOWAT,
|
||||
&arg, sizeof(arg));
|
||||
#endif
|
||||
} else /* if (other_socket->proto == protoUdp) */ {
|
||||
} else /* if (other_socket->protocol == IPPROTO_UDP) */ {
|
||||
if (other_socket == &cnx->local)
|
||||
closesocket(other_socket->fd);
|
||||
other_socket->fd = INVALID_SOCKET;
|
||||
@@ -637,28 +677,28 @@ static void handleAccept(ServerInfo const *srv)
|
||||
{
|
||||
int udpBytes = 0;
|
||||
|
||||
struct sockaddr addr;
|
||||
struct sockaddr_storage addr;
|
||||
SOCKLEN_T addrlen = sizeof(addr);
|
||||
|
||||
SOCKET nfd;
|
||||
if (srv->fromProto == protoTcp) {
|
||||
if (srv->fromAddrInfo->ai_protocol == IPPROTO_TCP) {
|
||||
/* In TCP mode, get remote address using accept(). */
|
||||
nfd = accept(srv->fd, &addr, &addrlen);
|
||||
nfd = accept(srv->fd, (struct sockaddr *)&addr, &addrlen);
|
||||
if (nfd == INVALID_SOCKET) {
|
||||
syslog(LOG_ERR, "accept(%d): %m\n", srv->fd);
|
||||
logError("accept(%llu): %m\n", (long long unsigned int)srv->fd);
|
||||
logEvent(NULL, srv, logAcceptFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
setSocketDefaults(nfd);
|
||||
} else /* if (srv->fromProto == protoUdp) */ {
|
||||
} else /* if (srv->fromAddrInfo->ai_protocol == IPPROTO_UDP) */ {
|
||||
/* In UDP mode, get remote address using recvfrom() and check
|
||||
for an existing connection from this client. We need
|
||||
to read a lot of data otherwise the datagram contents
|
||||
may be lost later. */
|
||||
nfd = srv->fd;
|
||||
ssize_t ret = recvfrom(nfd, globalUdpBuffer,
|
||||
sizeof(globalUdpBuffer), 0, &addr, &addrlen);
|
||||
SSIZE_T ret = recvfrom(nfd, globalUdpBuffer,
|
||||
sizeof(globalUdpBuffer), 0, (struct sockaddr *)&addr, &addrlen);
|
||||
if (ret < 0) {
|
||||
if (GetLastError() == WSAEWOULDBLOCK) {
|
||||
return;
|
||||
@@ -666,20 +706,17 @@ static void handleAccept(ServerInfo const *srv)
|
||||
if (GetLastError() == WSAEINPROGRESS) {
|
||||
return;
|
||||
}
|
||||
syslog(LOG_ERR, "recvfrom(%d): %m\n", srv->fd);
|
||||
logError("recvfrom(%llu): %m\n", (long long unsigned int)srv->fd);
|
||||
logEvent(NULL, srv, logAcceptFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
udpBytes = (int)ret;
|
||||
|
||||
/* Look for an existing connection with the same remote host and port. */
|
||||
for (int i = 0; i < coTotal; ++i) {
|
||||
ConnectionInfo *cnx = &coInfo[i];
|
||||
struct sockaddr_in *addr_in = (struct sockaddr_in *)&addr;
|
||||
if (cnx->remote.fd == nfd
|
||||
&& cnx->remoteAddress.sin_family == addr_in->sin_family
|
||||
&& cnx->remoteAddress.sin_port == addr_in->sin_port
|
||||
&& cnx->remoteAddress.sin_addr.s_addr == addr_in->sin_addr.s_addr) {
|
||||
if (cnx->remote.fd == nfd && sameSocketAddress(&cnx->remoteAddress, &addr)) {
|
||||
cnx->remoteTimeout = time(NULL) + srv->serverTimeout;
|
||||
handleUdpRead(cnx, globalUdpBuffer, udpBytes);
|
||||
return;
|
||||
@@ -693,16 +730,18 @@ static void handleAccept(ServerInfo const *srv)
|
||||
}
|
||||
|
||||
cnx->local.fd = INVALID_SOCKET;
|
||||
cnx->local.proto = srv->toProto;
|
||||
cnx->local.family = srv->toAddrInfo->ai_family;
|
||||
cnx->local.protocol = srv->toAddrInfo->ai_protocol;
|
||||
cnx->local.recvPos = cnx->local.sentPos = 0;
|
||||
cnx->local.recvBytes = cnx->local.sentBytes = 0;
|
||||
cnx->local.totalBytesIn = cnx->local.totalBytesOut = 0;
|
||||
|
||||
cnx->remote.fd = nfd;
|
||||
cnx->remote.proto = srv->fromProto;
|
||||
cnx->remote.family = srv->fromAddrInfo->ai_family;
|
||||
cnx->remote.protocol = srv->fromAddrInfo->ai_protocol;
|
||||
cnx->remote.recvPos = cnx->remote.sentPos = 0;
|
||||
cnx->remote.recvBytes = cnx->remote.sentBytes = 0;
|
||||
cnx->remoteAddress = *(struct sockaddr_in *)&addr;
|
||||
if (srv->fromProto == protoUdp)
|
||||
cnx->remote.totalBytesIn = cnx->remote.totalBytesOut = 0;
|
||||
cnx->remoteAddress = addr;
|
||||
if (srv->fromAddrInfo->ai_protocol == IPPROTO_UDP)
|
||||
cnx->remoteTimeout = time(NULL) + srv->serverTimeout;
|
||||
|
||||
cnx->coClosing = 0;
|
||||
@@ -713,7 +752,7 @@ static void handleAccept(ServerInfo const *srv)
|
||||
if (logCode != logAllowed) {
|
||||
/* Local fd is not open yet, so only
|
||||
close the remote socket. */
|
||||
if (cnx->remote.proto == protoTcp)
|
||||
if (cnx->remote.protocol == IPPROTO_TCP)
|
||||
closesocket(cnx->remote.fd);
|
||||
cnx->remote.fd = INVALID_SOCKET;
|
||||
logEvent(cnx, cnx->server, logCode);
|
||||
@@ -723,46 +762,38 @@ static void handleAccept(ServerInfo const *srv)
|
||||
/* Now open a connection to the local server.
|
||||
This, too, is nonblocking. Why wait
|
||||
for anything when you don't have to? */
|
||||
struct sockaddr_in saddr;
|
||||
cnx->local.fd = srv->toProto == protoTcp
|
||||
? socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
|
||||
: socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
struct addrinfo* to = srv->toAddrInfo;
|
||||
cnx->local.fd = socket(to->ai_family, to->ai_socktype, to->ai_protocol);
|
||||
if (cnx->local.fd == INVALID_SOCKET) {
|
||||
syslog(LOG_ERR, "socket(): %m\n");
|
||||
if (cnx->remote.proto == protoTcp)
|
||||
logError("socket(): %m\n");
|
||||
if (cnx->remote.protocol == IPPROTO_TCP)
|
||||
closesocket(cnx->remote.fd);
|
||||
cnx->remote.fd = INVALID_SOCKET;
|
||||
logEvent(cnx, srv, logLocalSocketFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (srv->toProto == protoTcp)
|
||||
if (srv->toAddrInfo->ai_protocol == IPPROTO_TCP)
|
||||
setSocketDefaults(cnx->local.fd);
|
||||
|
||||
/* Bind the local socket even if we use connect() later, so that
|
||||
/* Bind the local socket even though we use connect() later, so that
|
||||
we can specify a source address. */
|
||||
memset(&saddr, 0, sizeof(struct sockaddr_in));
|
||||
saddr.sin_family = AF_INET;
|
||||
memcpy(&saddr.sin_addr, &srv->sourceAddr, sizeof(struct in_addr));
|
||||
saddr.sin_port = 0;
|
||||
if (bind(cnx->local.fd, (struct sockaddr *)&saddr,
|
||||
sizeof(saddr)) == SOCKET_ERROR) {
|
||||
syslog(LOG_ERR, "bind(): %m\n");
|
||||
if (srv->sourceAddrInfo) {
|
||||
if (bind(cnx->local.fd, srv->sourceAddrInfo->ai_addr,
|
||||
srv->sourceAddrInfo->ai_addrlen) == SOCKET_ERROR) {
|
||||
logError("bind(): %m\n");
|
||||
}
|
||||
}
|
||||
|
||||
memset(&saddr, 0, sizeof(struct sockaddr_in));
|
||||
saddr.sin_family = AF_INET;
|
||||
memcpy(&saddr.sin_addr, &srv->localAddr, sizeof(struct in_addr));
|
||||
saddr.sin_port = srv->localPort;
|
||||
if (connect(cnx->local.fd, (struct sockaddr *)&saddr,
|
||||
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
|
||||
if (connect(cnx->local.fd, srv->toAddrInfo->ai_addr,
|
||||
srv->toAddrInfo->ai_addrlen) == SOCKET_ERROR)
|
||||
{
|
||||
if ((GetLastError() != WSAEINPROGRESS) &&
|
||||
(GetLastError() != WSAEWOULDBLOCK))
|
||||
{
|
||||
PERROR("rinetd: connect");
|
||||
closesocket(cnx->local.fd);
|
||||
if (cnx->remote.proto == protoTcp)
|
||||
if (cnx->remote.protocol == IPPROTO_TCP)
|
||||
closesocket(cnx->remote.fd);
|
||||
cnx->remote.fd = INVALID_SOCKET;
|
||||
cnx->local.fd = INVALID_SOCKET;
|
||||
@@ -772,15 +803,15 @@ static void handleAccept(ServerInfo const *srv)
|
||||
}
|
||||
|
||||
/* Send a zero-size UDP packet to simulate a connection */
|
||||
if (srv->toProto == protoUdp) {
|
||||
if (srv->toAddrInfo->ai_protocol == IPPROTO_UDP) {
|
||||
int got = sendto(cnx->local.fd, NULL, 0, 0,
|
||||
&saddr, (SOCKLEN_T)sizeof(saddr));
|
||||
srv->toAddrInfo->ai_addr, srv->toAddrInfo->ai_addrlen);
|
||||
/* FIXME: we ignore errors here... is it safe? */
|
||||
(void)got;
|
||||
}
|
||||
|
||||
/* Send UDP data to the other socket */
|
||||
if (srv->fromProto == protoUdp) {
|
||||
if (srv->fromAddrInfo->ai_protocol == IPPROTO_UDP) {
|
||||
handleUdpRead(cnx, globalUdpBuffer, udpBytes);
|
||||
}
|
||||
|
||||
@@ -799,7 +830,10 @@ static void handleAccept(ServerInfo const *srv)
|
||||
static int checkConnectionAllowed(ConnectionInfo const *cnx)
|
||||
{
|
||||
ServerInfo const *srv = cnx->server;
|
||||
char const *addressText = inet_ntoa(cnx->remoteAddress.sin_addr);
|
||||
|
||||
char addressText[NI_MAXHOST];
|
||||
getnameinfo((struct sockaddr *)&cnx->remoteAddress, sizeof(cnx->remoteAddress),
|
||||
addressText, sizeof(addressText), NULL, 0, NI_NUMERICHOST);
|
||||
|
||||
/* 1. Check global allow rules. If there are no
|
||||
global allow rules, it's presumed OK at
|
||||
@@ -855,56 +889,6 @@ static int checkConnectionAllowed(ConnectionInfo const *cnx)
|
||||
return logAllowed;
|
||||
}
|
||||
|
||||
static int getAddress(char const *host, struct in_addr *iaddr)
|
||||
{
|
||||
/* If this is an IP address, use inet_addr() */
|
||||
int is_ipaddr = 1;
|
||||
for (char const *p = host; *p; ++p) {
|
||||
if (!isdigit(*p) && *p != '.') {
|
||||
is_ipaddr = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_ipaddr) {
|
||||
iaddr->s_addr = inet_addr(host);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Otherwise, use gethostbyname() */
|
||||
struct hostent *h = gethostbyname(host);
|
||||
if (h) {
|
||||
#ifdef h_addr
|
||||
memcpy(&iaddr->s_addr, h->h_addr, 4);
|
||||
#else
|
||||
memcpy(&iaddr->s_addr, h->h_addr_list[0], 4);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
char const *msg = "(unknown DNS error)";
|
||||
switch (h_errno)
|
||||
{
|
||||
case HOST_NOT_FOUND:
|
||||
msg = "The specified host is unknown.";
|
||||
break;
|
||||
#ifdef NO_DATA
|
||||
case NO_DATA:
|
||||
#else
|
||||
case NO_ADDRESS:
|
||||
#endif
|
||||
msg = "The requested name is valid but does not have an IP address.";
|
||||
break;
|
||||
case NO_RECOVERY:
|
||||
msg = "A non-recoverable name server error occurred.";
|
||||
break;
|
||||
case TRY_AGAIN:
|
||||
msg = "A temporary error occurred on an authoritative name server. Try again later.";
|
||||
break;
|
||||
}
|
||||
syslog(LOG_ERR, "While resolving `%s' got: %s\n", host, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if !HAVE_SIGACTION && !_WIN32
|
||||
RETSIGTYPE plumber(int s)
|
||||
{
|
||||
@@ -917,7 +901,7 @@ RETSIGTYPE plumber(int s)
|
||||
RETSIGTYPE hup(int s)
|
||||
{
|
||||
(void)s;
|
||||
syslog(LOG_INFO, "Received SIGHUP, reloading configuration...\n");
|
||||
logInfo("received SIGHUP, reloading configuration...\n");
|
||||
/* Learn the new rules */
|
||||
clearConfiguration();
|
||||
readConfiguration(options.conf_file);
|
||||
@@ -947,8 +931,6 @@ void registerPID(char const *pid_file_name)
|
||||
FILE *pid_file = fopen(pid_file_name, "w");
|
||||
if (pid_file == NULL) {
|
||||
/* non-fatal, non-Linux may lack /var/run... */
|
||||
fprintf(stderr, "rinetd: Couldn't write to "
|
||||
"%s. PID was not logged.\n", pid_file_name);
|
||||
goto error;
|
||||
} else {
|
||||
fprintf(pid_file, "%d\n", getpid());
|
||||
@@ -958,8 +940,8 @@ void registerPID(char const *pid_file_name)
|
||||
}
|
||||
return;
|
||||
error:
|
||||
syslog(LOG_ERR, "Couldn't write to "
|
||||
"%s. PID was not logged (%m).\n", pid_file_name);
|
||||
logError("couldn't write to %s. PID was not logged (%m).\n",
|
||||
pid_file_name);
|
||||
#else
|
||||
/* add other systems with wherever they register processes */
|
||||
(void)pid_file_name;
|
||||
@@ -972,6 +954,7 @@ static void logEvent(ConnectionInfo const *cnx, ServerInfo const *srv, int resul
|
||||
thanks folks */
|
||||
int timz;
|
||||
char tstr[1024];
|
||||
char addressText[NI_MAXHOST] = { '?' };
|
||||
struct tm *t = get_gmtoff(&timz);
|
||||
char sign = (timz < 0 ? '-' : '+');
|
||||
if (timz < 0) {
|
||||
@@ -979,28 +962,25 @@ static void logEvent(ConnectionInfo const *cnx, ServerInfo const *srv, int resul
|
||||
}
|
||||
strftime(tstr, sizeof(tstr), "%d/%b/%Y:%H:%M:%S ", t);
|
||||
|
||||
char const *addressText = "?";
|
||||
int bytesOutput = 0;
|
||||
int bytesInput = 0;
|
||||
int64_t bytesOut = 0, bytesIn = 0;
|
||||
if (cnx != NULL) {
|
||||
addressText = inet_ntoa(cnx->remoteAddress.sin_addr);
|
||||
bytesOutput = cnx->remote.sentBytes;
|
||||
bytesInput = cnx->remote.recvBytes;
|
||||
getnameinfo((struct sockaddr *)&cnx->remoteAddress, sizeof(cnx->remoteAddress),
|
||||
addressText, sizeof(addressText), NULL, 0, NI_NUMERICHOST);
|
||||
bytesOut = cnx->remote.totalBytesOut;
|
||||
bytesIn = cnx->remote.totalBytesIn;
|
||||
}
|
||||
|
||||
char const *fromHost = "?";
|
||||
int fromPort = 0;
|
||||
char const *toHost = "?";
|
||||
int toPort = 0;
|
||||
char const *fromHost = "?", *toHost = "?";
|
||||
uint16_t fromPort = 0, toPort = 0;
|
||||
if (srv != NULL) {
|
||||
fromHost = srv->fromHost;
|
||||
fromPort = srv->fromPort;
|
||||
fromPort = getPort(srv->fromAddrInfo);
|
||||
toHost = srv->toHost;
|
||||
toPort = srv->toPort;
|
||||
toPort = getPort(srv->toAddrInfo);
|
||||
}
|
||||
|
||||
if (result==logNotAllowed || result==logDenied)
|
||||
syslog(LOG_INFO, "%s %s\n"
|
||||
logInfo("%s %s\n"
|
||||
, addressText
|
||||
, logMessages[result]);
|
||||
if (logFile) {
|
||||
@@ -1020,28 +1000,28 @@ static void logEvent(ConnectionInfo const *cnx, ServerInfo const *srv, int resul
|
||||
fprintf(logFile, "%s - - "
|
||||
"[%s %c%.2d%.2d] "
|
||||
"\"GET /rinetd-services/%s/%d/%s/%d/%s HTTP/1.0\" "
|
||||
"200 %d - - - %d\n",
|
||||
"200 %llu - - - %llu\n",
|
||||
addressText,
|
||||
tstr,
|
||||
sign,
|
||||
timz / 60,
|
||||
timz % 60,
|
||||
fromHost, fromPort,
|
||||
toHost, toPort,
|
||||
fromHost, (int)fromPort,
|
||||
toHost, (int)toPort,
|
||||
logMessages[result],
|
||||
bytesOutput,
|
||||
bytesInput);
|
||||
(unsigned long long int)bytesOut,
|
||||
(unsigned long long int)bytesIn);
|
||||
} else {
|
||||
/* Write an rinetd-specific log entry with a
|
||||
less goofy format. */
|
||||
fprintf(logFile, "%s\t%s\t%s\t%d\t%s\t%d\t%d"
|
||||
"\t%d\t%s\n",
|
||||
fprintf(logFile, "%s\t%s\t%s\t%d\t%s\t%d\t%llu"
|
||||
"\t%llu\t%s\n",
|
||||
tstr,
|
||||
addressText,
|
||||
fromHost, fromPort,
|
||||
toHost, toPort,
|
||||
bytesInput,
|
||||
bytesOutput,
|
||||
fromHost, (int)fromPort,
|
||||
toHost, (int)toPort,
|
||||
(unsigned long long int)bytesIn,
|
||||
(unsigned long long int)bytesOut,
|
||||
logMessages[result]);
|
||||
}
|
||||
}
|
||||
@@ -1067,7 +1047,7 @@ static int readArgs (int argc, char **argv, RinetdOptions *options)
|
||||
case 'c':
|
||||
options->conf_file = optarg;
|
||||
if (!options->conf_file) {
|
||||
syslog(LOG_ERR, "Not enough memory to "
|
||||
fprintf(stderr, "Not enough memory to "
|
||||
"launch rinetd.\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
© 2003—2021 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
This software is released for free use under the terms of
|
||||
the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
@@ -8,16 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/* Syslog feature */
|
||||
|
||||
#if _WIN32
|
||||
# include <stdio.h>
|
||||
# define syslog fprintf
|
||||
# define LOG_ERR stderr
|
||||
# define LOG_INFO stdout
|
||||
#else
|
||||
# include <syslog.h>
|
||||
#endif /* _WIN32 */
|
||||
#include <stdint.h>
|
||||
|
||||
/* Constants */
|
||||
|
||||
@@ -44,7 +35,8 @@ extern FILE *logFile;
|
||||
|
||||
/* Functions */
|
||||
|
||||
void addServer(char *bindAddress, int bindPort, int bindProto,
|
||||
char *connectAddress, int connectPort, int connectProto,
|
||||
void logError(char const *fmt, ...);
|
||||
void logInfo(char const *fmt, ...);
|
||||
void addServer(char *bindAddress, char *bindPort, int bindProtocol,
|
||||
char *connectAddress, char *connectPort, int connectProtocol,
|
||||
int serverTimeout, char *sourceAddress);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
© 2003—2021 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
This software is released for free use under the terms of
|
||||
the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
@@ -9,22 +9,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum ruleType {
|
||||
typedef enum _rule_type ruleType;
|
||||
enum _rule_type {
|
||||
allowRule,
|
||||
denyRule,
|
||||
};
|
||||
|
||||
enum protocolType {
|
||||
protoTcp = 1,
|
||||
protoUdp = 2,
|
||||
};
|
||||
|
||||
typedef struct _rule Rule;
|
||||
struct _rule
|
||||
{
|
||||
char *pattern;
|
||||
int type;
|
||||
ruleType type;
|
||||
};
|
||||
|
||||
typedef struct _server_info ServerInfo;
|
||||
@@ -32,13 +29,10 @@ struct _server_info {
|
||||
SOCKET fd;
|
||||
|
||||
/* In network order, for network purposes */
|
||||
struct in_addr localAddr;
|
||||
unsigned short localPort;
|
||||
struct in_addr sourceAddr;
|
||||
struct addrinfo *fromAddrInfo, *toAddrInfo, *sourceAddrInfo;
|
||||
|
||||
/* In ASCII and local byte order, for logging purposes */
|
||||
/* In ASCII, for logging purposes */
|
||||
char *fromHost, *toHost;
|
||||
int fromPort, fromProto, toPort, toProto;
|
||||
|
||||
/* Offset and count into list of allow and deny rules. Any rules
|
||||
prior to globalAllowRules and globalDenyRules are global rules. */
|
||||
@@ -52,11 +46,11 @@ typedef struct _socket Socket;
|
||||
struct _socket
|
||||
{
|
||||
SOCKET fd;
|
||||
int proto;
|
||||
int family, protocol;
|
||||
/* recv: received on this socket
|
||||
sent: sent to this socket from the other buffer */
|
||||
sent: sent through this socket from the other buffer */
|
||||
int recvPos, sentPos;
|
||||
int recvBytes, sentBytes;
|
||||
uint64_t totalBytesIn, totalBytesOut;
|
||||
char *buffer;
|
||||
};
|
||||
|
||||
@@ -64,7 +58,7 @@ typedef struct _connection_info ConnectionInfo;
|
||||
struct _connection_info
|
||||
{
|
||||
Socket remote, local;
|
||||
struct sockaddr_in remoteAddress;
|
||||
struct sockaddr_storage remoteAddress;
|
||||
time_t remoteTimeout;
|
||||
int coClosing;
|
||||
int coLog;
|
||||
Reference in New Issue
Block a user