Imported Debian patch 0.62-5.1

This commit is contained in:
Petter Reinholdtsen 2008-03-30 12:59:52 +02:00 committed by Mario Fetka
parent 57f4f99a0b
commit a679a55d0c
21 changed files with 5148 additions and 212 deletions

55
Makefile.in Normal file
View File

@ -0,0 +1,55 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
datadir=@datadir@
bindir=@bindir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
mandir=@mandir@
srcdir=@srcdir@
VPATH = @srcdir@
SHELL=@SHELL@
CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@ -Wall -Wwrite-strings -I.
LDFLAGS=@LDFLAGS@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@
EXEEXT=@EXEEXT@
OBJEXT=@OBJEXT@
rinetd: rinetd.$(OBJEXT) match.$(OBJEXT)
gcc rinetd.$(OBJEXT) match.$(OBJEXT) -o rinetd$(EXEEXT) $(LDFLAGS)
install: rinetd
$(INSTALL_PROGRAM) rinetd$(EXEEXT) $(DESTDIR)$(sbindir)
$(INSTALL_DATA) $(srcdir)/rinetd.8 $(DESTDIR)$(mandir)/man8
$(INSTALL) -m 600 $(srcdir)/rinetd.conf $(DESTDIR)/$(sysconfdir)
clean:
rm -f rinetd$(EXEEXT) *.$(OBJEXT) *~
distclean: clean
rm -rf config.status Makefile config.log config.h
match.o: match.c match.h config.h
rinetd.o: rinetd.c match.h config.h
$(srcdir)/configure: configure.ac # aclocal.m4
cd $(srcdir) && autoconf
# autoheader might not change config.h.in, so touch a stamp file.
$(srcdir)/config.h.in: stamp-h.in
$(srcdir)/stamp-h.in: configure.ac # aclocal.m4
cd $(srcdir) && autoheader
echo timestamp > $(srcdir)/stamp-h.in
config.h: stamp-h
stamp-h: config.h.in config.status
./config.status
Makefile: Makefile.in config.status
./config.status
config.status: configure
./config.status --recheck

137
config.h.in Normal file
View File

@ -0,0 +1,137 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H
/* Define to 1 if you have the `daemon' function. */
#undef HAVE_DAEMON
/* Define to 1 if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `sigaction' function. */
#undef HAVE_SIGACTION
/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strftime' function. */
#undef HAVE_STRFTIME
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strstr' function. */
#undef HAVE_STRSTR
/* Define to 1 if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H
/* Define to 1 if `fork' works. */
#undef HAVE_WORKING_FORK
/* Define to 1 if `vfork' works. */
#undef HAVE_WORKING_VFORK
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
#undef TM_IN_SYS_TIME
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
/* Define as `fork' if `vfork' does not work. */
#undef vfork

4043
configure vendored Normal file

File diff suppressed because it is too large Load Diff

30
configure.ac Normal file
View File

@ -0,0 +1,30 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.52)
AC_INIT([rinetd],[0.61],[rinetd@packages.debian.org])
AC_CONFIG_SRCDIR([getopt.h])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
# Checks for libraries.
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h syslog.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_TIME
AC_STRUCT_TM
# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([gethostbyname memset select socket strstr daemon sigaction])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

144
debian/changelog vendored Normal file
View File

@ -0,0 +1,144 @@
rinetd (0.62-5.1) unstable; urgency=low
* Non-maintainer upload to solve release goal.
* Add LSB dependency header to init.d scripts (Closes: #466976).
-- Petter Reinholdtsen <pere@debian.org> Sun, 30 Mar 2008 12:59:52 +0200
rinetd (0.62-5) unstable; urgency=low
* debian/rules:
+ Fixed timestamps to avoid build issues (Closes: #277979).
-- Sam Hocevar (Debian packages) <sam+deb@zoy.org> Sun, 24 Oct 2004 13:14:09 +0200
rinetd (0.62-4) unstable; urgency=low
* debian/changelog:
+ Converted to UTF-8.
* debian/control:
+ Set policy to 3.6.1.1.
-- Sam Hocevar (Debian packages) <sam+deb@zoy.org> Mon, 2 Aug 2004 12:07:56 +0200
rinetd (0.62-3) unstable; urgency=low
* debian/rules:
+ Fixed autotools clock skews.
-- Sam Hocevar (Debian packages) <sam+deb@zoy.org> Sat, 1 Nov 2003 11:56:55 +0100
rinetd (0.62-2) unstable; urgency=low
* debian/control:
+ Set policy to 3.6.1.0.
+ Set debhelper build-dependency to (>= 4.1.68) because of dh_installppp.
+ Removed leading "an" from the short description and enhanced the long
description.
* debian/rules:
+ Use dh_installppp instead of doing the work by hand (Closes: #212909).
-- Sam Hocevar (Debian packages) <sam+deb@zoy.org> Mon, 27 Oct 2003 11:15:48 +0100
rinetd (0.62-1) unstable; urgency=low
* New upstream release, includes our fix for DSA 289-1.
* Set policy to 3.5.10.
-- Sam Hocevar (Debian packages) <sam+deb@zoy.org> Tue, 27 May 2003 15:41:37 +0200
rinetd (0.61-2) unstable; urgency=low
* New maintainer.
* Maintainer upload (Closes: #86201, #145756).
* Fixed then applied a user-contributed patch to make logging non-buffered
(Closes: #163654).
* Added a 1 second delay in the init.d script to avoid restarting rinetd
too quickly (Closes: #180449). This isn't perfect, though: the real problem
is the race condition when using daemon() and writing a PID file.
* rinetd now closes its configuration file (Closes: #182705).
* Fixed an off-by-one overflow and a missing reallocation in handleAccept().
* Replaced malloc/strcpy with strdup in readArgs().
* Added a -f flag to run rinetd in the foreground, and updated manpage and
index.html accordingly.
-- Samuel Hocevar <sam@zoy.org> Sun, 13 Apr 2003 19:12:01 +0200
rinetd (0.61-1.2) unstable; urgency=low
* NMU (bug squashing party).
* Fixed debian/rules (./configure and make clean) (closes: #145756).
-- Sebastien Bacher <seb128@debian.org> Sat, 31 Aug 2002 15:15:25 +0200
rinetd (0.61-1.1) unstable; urgency=low
* NMU.
* Fixed detection of numeric addresses. This fixes a bug that occurs when
starting rinetd in an unconnected machine.
* Added missing includes.
* Added -O2 to compilation options. Added -Wall and -Wstring
compilation options and removed all the warnings.
* Changed a lot of fprintf(stder,...) to syslogs.
* The program was reporting a bogus line number in errors.
* Replaced signal with sigaction.
* Uses autoconf.
* Now it logs DNS errors.
* Checks closing of pid file, this catchs the failure to write the pidfile
due to a disk full.
* Removed unused function Sleep.
* You don't need bind(2) on a socket you'll use for connect(2).
* Uses compatibility mode 4 of debhelper.
* Reload rinetd configuration when a PPP connection goues up. This useful
when using DNS names in /etc/rinetd.conf that can't be resolved without
an Internet connection. The proper solution to this is to resolve DNS
names *each time that is needed* (with perhaps a small caching period).
* Uses logrotate to rotate logs instead of savelog and cron.
-- Nicolás Lichtmaier <nick@debian.org> Sat, 4 May 2002 00:27:47 -0300
rinetd (0.61-1) unstable; urgency=low
* Non maintainer upload
* New upstream release
* Updated Standards-Version to 3.5.1
* Reference to GPL in debian/copyright is corrected to
/usr/share/common-licenses/GPL
* Upstream URL in debian/copyright is corrected to
ftp://ftp.boutell.com/pub/boutell/rinetd/rinetd.tar.gz
* Upstream changelog will be installed with dh_installchangelogs
instead of dh_installdocs
* dh_suidregister call is removed from debian/rules
* Build-Depends on debhelper added
* Recompiled with newer debhelper version doing the /usr/doc to
/usr/share/doc transition for us
* Moved man pages from /usr/man to /usr/share/man to comply with FHS
-- Roland Bauerschmidt <rb@debian.org> Fri, 16 Feb 2001 10:53:19 -0600
rinetd (0.52-2) unstable; urgency=low
* Add cron.weekly entry for rotating the logs
-- Gergely Madarasz <gorgo@caesar.elte.hu> Sat, 16 Jan 1999 01:21:26 +0100
rinetd (0.52-1) unstable; urgency=low
* New upstream version
-- Gergely Madarasz <gorgo@caesar.elte.hu> Fri, 15 Jan 1999 21:22:14 +0100
rinetd (0.41-1) unstable; urgency=low
* added reload, restart and force-reload entries to init.d script
* marked init.d script as conffile
* remove dh_du calls from debian/rules
* New upstream version
-- Gergely Madarasz <gorgo@caesar.elte.hu> Thu, 5 Mar 1998 18:53:03 +0100
rinetd (0.3-1) unstable; urgency=low
* Initial release
-- Gergely Madarasz <gorgo@caesar.elte.hu> Sun, 7 Dec 1997 02:07:00 +0100

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
4

20
debian/control vendored Normal file
View File

@ -0,0 +1,20 @@
Source: rinetd
Section: net
Priority: optional
Maintainer: Sam Hocevar (Debian packages) <sam+deb@zoy.org>
Standards-Version: 3.6.1.1
Build-Depends: debhelper (>= 4.1.68)
Package: rinetd
Architecture: any
Depends: ${shlibs:Depends}
Description: Internet TCP redirection server
rinetd redirects TCP connections from one IP address and port to another,
with basic IP-based access control.
.
rinetd is a single-process server which handles any number of connections
to the address/port pairs specified in the file /etc/rinetd.conf. Since
rinetd runs as a single process using nonblocking I/O, it is able to
redirect a large number of connections without a severe impact on the
machine. This makes it practical to run services on machines inside an IP
masquerading firewall.

15
debian/copyright vendored Normal file
View File

@ -0,0 +1,15 @@
This package was debianized by Gergely Madarasz gorgo@caesar.elte.hu on
Sun, 07 Dec 1997 01:14:33 +0100.
It was downloaded from
ftp://ftp.boutell.com/pub/boutell/rinetd/rinetd.tar.gz
Changes:
07-December-1997 Gergely Madarasz <gorgo@caesar.elte.hu>
added debian control files
Copyright (c) 1997, Thomas Boutell and Boutell.Com, Inc. This software
is released for free use under the terms of the GNU Public License, version
2 or higher.
On Debian systems see /usr/share/common-licenses/GPL

3
debian/dirs vendored Normal file
View File

@ -0,0 +1,3 @@
usr/sbin
usr/share/man/man8
etc

52
debian/init vendored Normal file
View File

@ -0,0 +1,52 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: rinetd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/rinetd
CONFFILE=/etc/rinetd.conf
NAME=rinetd
DESC="internet redirection server"
test -f $DAEMON || exit 0
test -f $CONFFILE || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC:"
start-stop-daemon --start --quiet --exec $DAEMON && echo -n " $NAME"
echo "."
;;
stop)
echo -n "Stopping $DESC:"
start-stop-daemon --stop --quiet --pidfile /var/run/rinetd.pid --exec $DAEMON && echo -n " $NAME"
echo "."
;;
reload|force-reload)
echo -n "Reloading configuration of $DESC:"
start-stop-daemon --stop --quiet --pidfile /var/run/rinetd.pid --signal 1 --exec $DAEMON && echo -n " $NAME"
echo "."
;;
restart)
echo -n "Stopping $DESC:"
start-stop-daemon --stop --quiet --pidfile /var/run/rinetd.pid --exec $DAEMON && echo -n " $NAME"
echo "."
sleep 1
echo -n "Starting $DESC:"
start-stop-daemon --start --quiet --pidfile /var/run/rinetd.pid --exec $DAEMON && echo -n " $NAME"
echo "."
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload}"
exit 1
;;
esac
exit 0

6
debian/rinetd.logrotate vendored Normal file
View File

@ -0,0 +1,6 @@
/var/log/rinetd.log {
rotate 7
weekly
copytruncate
}

8
debian/rinetd.ppp.ip-up vendored Normal file
View File

@ -0,0 +1,8 @@
#! /bin/sh
set -e
if [ -x /usr/sbin/rinetd ]; then
/etc/init.d/rinetd reload > /dev/null
fi

57
debian/rules vendored Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
DESTDIR=debian/rinetd
build: build-stamp
build-stamp:
dh_testdir
touch configure.ac
touch configure
touch config.h.in
touch stamp-h.in
touch `find . -name Makefile.in`
sh ./configure --prefix=/usr --sysconfdir=/etc --mandir='/usr/share/man'
$(MAKE)
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp
-$(MAKE) distclean
rm -f config.cache *.o config.status config.log config.h
dh_clean
# Build architecture-independent files here.
binary-indep: build
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build
dh_testdir
dh_testroot
dh_clean
dh_installdirs
$(MAKE) DESTDIR=$(DESTDIR) install
dh_installppp
dh_installdocs README index.html
dh_installinit
dh_installlogrotate
dh_installmanpages
dh_installchangelogs CHANGES
dh_installcron
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary

View File

@ -189,6 +189,9 @@ logcommon
The -c command line option is used to specify an alternate The -c command line option is used to specify an alternate
configuration file. configuration file.
<p> <p>
The -f command line option is used to run rinetd in the
foreground, without forking to the background.
<p>
The -h command line option produces a short help message. The -h command line option produces a short help message.
<p> <p>
The -v command line option displays the version number. The -v command line option displays the version number.

251
install-sh Normal file
View File

@ -0,0 +1,251 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

12
match.c
View File

@ -1,20 +1,24 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "match.h" #include "match.h"
int match(char *sorig, char *p) int match(const char *sorig, char *p)
{ {
return matchBody(sorig, p, 0); return matchBody(sorig, p, 0);
} }
int matchNoCase(char *sorig, char *p) int matchNoCase(const char *sorig, char *p)
{ {
return matchBody(sorig, p, 1); return matchBody(sorig, p, 1);
} }
#define CASE(x) (nocase ? tolower(x) : (x)) #define CASE(x) (nocase ? tolower(x) : (x))
int matchBody(char *sorig, char *p, int nocase) int matchBody(const char *sorig, char *p, int nocase)
{ {
static int dummy = 0; static int dummy = 0;
/* Algorithm: /* Algorithm:
@ -50,7 +54,7 @@ int matchBody(char *sorig, char *p, int nocase)
Addendum: consider the | character to be a logical OR Addendum: consider the | character to be a logical OR
separating distinct patterns. */ separating distinct patterns. */
char *s = sorig; const char *s = sorig;
int escaped = 0; int escaped = 0;
if (strstr(p, "WS-0000")) { if (strstr(p, "WS-0000")) {
if (strstr(s, "ws_ftp_pro.html")) { if (strstr(s, "ws_ftp_pro.html")) {

View File

@ -1,9 +1,9 @@
#ifndef MATCH_H #ifndef MATCH_H
#define MATCH_H 1 #define MATCH_H 1
extern int match(char *s, char *p); extern int match(const char *s, char *p);
extern int matchNoCase(char *s, char *p); extern int matchNoCase(const char *s, char *p);
extern int matchBody(char *s, char *p, int nocase); extern int matchBody(const char *s, char *p, int nocase);
#endif /* MATCH_H */ #endif /* MATCH_H */

View File

@ -150,6 +150,9 @@ logcommon
The -c command line option is used to specify an alternate The -c command line option is used to specify an alternate
configuration file. configuration file.
.Pp .Pp
The -f command line option is used to run rinetd in the
foreground, without forking to the background.
.Pp
The -h command line option produces a short help message. The -h command line option produces a short help message.
.Pp .Pp
The -v command line option displays the version number. The -v command line option displays the version number.

488
rinetd.c
View File

@ -1,75 +1,95 @@
#define VERSION "0.62" #define VERSION "0.62"
#ifdef WIN32 #ifdef HAVE_CONFIG_H
#include <windows.h> #include <config.h>
#include <winsock.h> #endif
#include "getopt.h"
#else #ifndef RETSIGTYPE
#include <sys/types.h> #define RETSIGTYPE void
#include <sys/socket.h> #endif
#ifdef WIN32
#include <windows.h>
#include <winsock.h>
#include "getopt.h"
#define syslog fprintf
#define LOG_ERR stderr
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <netdb.h> #include <unistd.h>
#include <netinet/in.h> #include <netdb.h>
#include <getopt.h> #include <netinet/in.h>
#include <errno.h> #include <arpa/inet.h>
#define INVALID_SOCKET (-1) #include <getopt.h>
#include <sys/time.h> #include <errno.h>
#endif /* WIN32 */ #include <syslog.h>
#define INVALID_SOCKET (-1)
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
#endif
#endif /* WIN32 */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#if WIN32 || (!TIME_WITH_SYS_TIME && !HAVE_SYS_TIME_H)
#include <time.h> #include <time.h>
#endif
#include <ctype.h> #include <ctype.h>
#ifndef WIN32 #ifndef WIN32
/* Windows sockets compatibility defines */ /* Windows sockets compatibility defines */
#define INVALID_SOCKET (-1) #define INVALID_SOCKET (-1)
#define SOCKET_ERROR (-1) #define SOCKET_ERROR (-1)
int closesocket(int s); int closesocket(int s);
int closesocket(int s) { int closesocket(int s) {
return close(s); return close(s);
} }
#define ioctlsocket ioctl #define ioctlsocket ioctl
#define MAKEWORD(a, b) #define MAKEWORD(a, b)
#define WSAStartup(a, b) (0) #define WSAStartup(a, b) (0)
#define WSACleanup() #define WSACleanup()
#ifdef __MAC__ #ifdef __MAC__
/* The constants for these are a little screwy in the prelinked /* The constants for these are a little screwy in the prelinked
MSL GUSI lib and we can't rebuild it, so roll with it */ MSL GUSI lib and we can't rebuild it, so roll with it */
#define WSAEWOULDBLOCK EWOULDBLOCK #define WSAEWOULDBLOCK EWOULDBLOCK
#define WSAEAGAIN EAGAIN #define WSAEAGAIN EAGAIN
#define WSAEINPROGRESS EINPROGRESS #define WSAEINPROGRESS EINPROGRESS
#else #else
#define WSAEWOULDBLOCK EWOULDBLOCK #define WSAEWOULDBLOCK EWOULDBLOCK
#define WSAEAGAIN EAGAIN #define WSAEAGAIN EAGAIN
#define WSAEINPROGRESS EINPROGRESS #define WSAEINPROGRESS EINPROGRESS
#endif /* __MAC__ */ #endif /* __MAC__ */
#define WSAEINTR EINTR #define WSAEINTR EINTR
#define SOCKET int #define SOCKET int
#define GetLastError() (errno) #define GetLastError() (errno)
typedef struct { typedef struct {
int dummy; int dummy;
} WSADATA; } WSADATA;
void Sleep(long ms); #else
/* WIN32 doesn't really have WSAEAGAIN */
void Sleep(long ms) #ifndef WSAEAGAIN
{ #define WSAEAGAIN WSAEWOULDBLOCK
struct timeval tv; #endif
tv.tv_sec = ms / 1000; #endif /* WIN32 */
tv.tv_usec = ms * 1000;
select(0, 0, 0, 0, &tv);
}
#else
/* WIN32 doesn't really have WSAEAGAIN */
#ifndef WSAEAGAIN
#define WSAEAGAIN WSAEWOULDBLOCK
#endif
#endif /* WIN32 */
#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
@ -91,7 +111,7 @@ void Sleep(long ms)
#include <sys/filio.h> #include <sys/filio.h>
#endif /* FIONBIO */ #endif /* FIONBIO */
#include "match.h" #include "match.h"
SOCKET *seFds = 0; SOCKET *seFds = 0;
/* In network order, for network purposes */ /* In network order, for network purposes */
@ -115,7 +135,7 @@ int globalDenyRules = 0;
SOCKET *reFds = 0; SOCKET *reFds = 0;
SOCKET *loFds = 0; SOCKET *loFds = 0;
unsigned char *reAddresses = 0; struct in_addr *reAddresses = NULL;
int *coInputRPos = 0; int *coInputRPos = 0;
int *coInputWPos = 0; int *coInputWPos = 0;
int *coOutputRPos = 0; int *coOutputRPos = 0;
@ -164,9 +184,9 @@ int safeRealloc(void **data, int oldsize, int newsize);
void readConfiguration(); void readConfiguration();
/* Signal handlers */ /* Signal handlers */
void plumber(int s); RETSIGTYPE plumber(int s);
void hup(int s); RETSIGTYPE hup(int s);
void term(int s); RETSIGTYPE term(int s);
void initArrays(void); void initArrays(void);
void RegisterPID(void); void RegisterPID(void);
@ -174,10 +194,10 @@ void RegisterPID(void);
void selectLoop(void); void selectLoop(void);
void log(int i, int coSe, int result); void log(int i, int coSe, int result);
int getAddress(char *host, struct in_addr *iaddr);
char *logMessages[] = { int getAddress(char *host, struct in_addr *iaddr);
const char *logMessages[] = {
"done-local-closed", "done-local-closed",
"done-remote-closed", "done-remote-closed",
"accept-failed -", "accept-failed -",
@ -210,11 +230,13 @@ char *logMessages[] = {
typedef struct _rinetd_options RinetdOptions; typedef struct _rinetd_options RinetdOptions;
struct _rinetd_options struct _rinetd_options
{ {
char *conf_file; const char *conf_file;
int foreground;
}; };
RinetdOptions options = { RinetdOptions options = {
"/etc/rinetd.conf" "/etc/rinetd.conf",
0
}; };
int readArgs (int argc, int readArgs (int argc,
@ -222,41 +244,60 @@ int readArgs (int argc,
RinetdOptions *options); RinetdOptions *options);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
WSADATA wsaData; #ifdef WIN32
int result = WSAStartup(MAKEWORD(1, 1), &wsaData); WSADATA wsaData;
if (result != 0) { #endif
fprintf(stderr, "Your computer was not connected " int result;
"to the Internet at the time that " #ifndef WIN32
"this program was launched, or you " openlog("rinetd",LOG_PID,LOG_DAEMON);
"do not have a 32-bit " #endif
"connection to the Internet."); result = WSAStartup(MAKEWORD(1, 1), &wsaData);
exit(1); if (result != 0) {
} fprintf(stderr, "Your computer was not connected "
"to the Internet at the time that "
"this program was launched, or you "
"do not have a 32-bit "
"connection to the Internet.");
exit(1);
}
readArgs(argc, argv, &options); readArgs(argc, argv, &options);
#ifndef WIN32 #ifndef WIN32
#ifndef DEBUG #ifdef DEBUG
if (!fork()) { {
if (!fork()) { #elif HAVE_DAEMON
if(options.foreground || !daemon(0,0)) {
#else
if (options.foreground || !fork()) {
#endif /* DEBUG */ #endif /* DEBUG */
#ifdef HAVE_SIGACTION
struct sigaction act;
act.sa_handler=SIG_IGN;
sigemptyset (&act.sa_mask);
act.sa_flags=SA_RESTART;
sigaction(SIGPIPE, &act, NULL);
act.sa_handler=&hup;
sigaction(SIGHUP, &act, NULL);
#else
signal(SIGPIPE, plumber); signal(SIGPIPE, plumber);
signal(SIGHUP, hup); signal(SIGHUP, hup);
#endif /* WIN32 */ #endif
#endif /* WIN32 */
signal(SIGTERM, term); signal(SIGTERM, term);
initArrays(); initArrays();
readConfiguration(); readConfiguration();
RegisterPID(); RegisterPID();
syslog(LOG_INFO,"Starting redirections...");
selectLoop(); selectLoop();
#ifndef WIN32 #ifndef WIN32
#ifndef DEBUG #ifdef DEBUG
} else { }
exit(0); #else
}
} else { } else {
exit(0); exit(0);
} }
#endif /* DEBUG */ #endif /* DEBUG */
#endif /* WIN32 */ #endif /* WIN32 */
return 0; return 0;
} }
@ -445,19 +486,19 @@ void readConfiguration(void)
} }
bindAddress = strtok(line, " \t\r\n"); bindAddress = strtok(line, " \t\r\n");
if (!bindAddress) { if (!bindAddress) {
fprintf(stderr, "rinetd: no bind address specified " syslog(LOG_ERR, "no bind address specified "
"on line %d.\n", lnum); "on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
if (!strcmp(bindAddress, "allow")) { if (!strcmp(bindAddress, "allow")) {
char *pattern = strtok(0, " \t\r\n"); char *pattern = strtok(0, " \t\r\n");
if (!pattern) { if (!pattern) {
fprintf(stderr, "rinetd: nothing to allow " syslog(LOG_ERR, "nothing to allow "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
if (patternBad(pattern)) { if (patternBad(pattern)) {
fprintf(stderr, "rinetd: illegal allow or " syslog(LOG_ERR, "illegal allow or "
"deny pattern. Only digits, ., and\n" "deny pattern. Only digits, ., and\n"
"the ? and * wild cards are allowed. " "the ? and * wild cards are allowed. "
"For performance reasons, rinetd\n" "For performance reasons, rinetd\n"
@ -483,8 +524,8 @@ void readConfiguration(void)
} else if (!strcmp(bindAddress, "deny")) { } else if (!strcmp(bindAddress, "deny")) {
char *pattern = strtok(0, " \t\r\n"); char *pattern = strtok(0, " \t\r\n");
if (!pattern) { if (!pattern) {
fprintf(stderr, "rinetd: nothing to deny " syslog(LOG_ERR,"nothing to deny "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
denyRules[di] = malloc(strlen(pattern) + 1); denyRules[di] = malloc(strlen(pattern) + 1);
@ -504,8 +545,8 @@ void readConfiguration(void)
} else if (!strcmp(bindAddress, "logfile")) { } else if (!strcmp(bindAddress, "logfile")) {
char *nt = strtok(0, " \t\r\n"); char *nt = strtok(0, " \t\r\n");
if (!nt) { if (!nt) {
fprintf(stderr, "rinetd: no log file name " syslog(LOG_ERR, "no log file name "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
logFileName = malloc(strlen(nt) + 1); logFileName = malloc(strlen(nt) + 1);
@ -516,8 +557,8 @@ void readConfiguration(void)
} else if (!strcmp(bindAddress, "pidlogfile")) { } else if (!strcmp(bindAddress, "pidlogfile")) {
char *nt = strtok(0, " \t\r\n"); char *nt = strtok(0, " \t\r\n");
if (!nt) { if (!nt) {
fprintf(stderr, "rinetd: no PID log file name " syslog(LOG_ERR, "no PID log file name "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
pidLogFileName = malloc(strlen(nt) + 1); pidLogFileName = malloc(strlen(nt) + 1);
@ -531,8 +572,8 @@ void readConfiguration(void)
/* A regular forwarding rule. */ /* A regular forwarding rule. */
bindPortS = strtok(0, " \t\r\n"); bindPortS = strtok(0, " \t\r\n");
if (!bindPortS) { if (!bindPortS) {
fprintf(stderr, "rinetd: no bind port " syslog(LOG_ERR, "no bind port "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
service = getservbyname(bindPortS, "tcp"); service = getservbyname(bindPortS, "tcp");
@ -542,20 +583,20 @@ void readConfiguration(void)
bindPort = atoi(bindPortS); bindPort = atoi(bindPortS);
} }
if ((bindPort == 0) || (bindPort >= 65536)) { if ((bindPort == 0) || (bindPort >= 65536)) {
fprintf(stderr, "rinetd: bind port missing " syslog(LOG_ERR, "bind port missing "
"or out of range on line %d.\n", lnum); "or out of range on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
connectAddress = strtok(0, " \t\r\n"); connectAddress = strtok(0, " \t\r\n");
if (!connectAddress) { if (!connectAddress) {
fprintf(stderr, "rinetd: no connect address " syslog(LOG_ERR, "no connect address "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
connectPortS = strtok(0, " \t\r\n"); connectPortS = strtok(0, " \t\r\n");
if (!connectPortS) { if (!connectPortS) {
fprintf(stderr, "rinetd: no connect port " syslog(LOG_ERR, "no connect port "
"specified on line %d.\n", lnum); "specified on file %s, line %d.\n", options.conf_file, lnum);
continue; continue;
} }
service = getservbyname(connectPortS, "tcp"); service = getservbyname(connectPortS, "tcp");
@ -565,8 +606,8 @@ void readConfiguration(void)
connectPort = atoi(connectPortS); connectPort = atoi(connectPortS);
} }
if ((connectPort == 0) || (connectPort >= 65536)) { if ((connectPort == 0) || (connectPort >= 65536)) {
fprintf(stderr, "rinetd: bind port missing " syslog(LOG_ERR, "bind port missing "
"or out of range on line %d.\n", lnum); "or out of range on file %s, %d.\n", options.conf_file, lnum);
continue; continue;
} }
/* Turn all of this stuff into reasonable addresses */ /* Turn all of this stuff into reasonable addresses */
@ -579,16 +620,16 @@ void readConfiguration(void)
/* Make a server socket */ /* Make a server socket */
seFds[i] = socket(PF_INET, SOCK_STREAM, 0); seFds[i] = socket(PF_INET, SOCK_STREAM, 0);
if (seFds[i] == INVALID_SOCKET) { if (seFds[i] == INVALID_SOCKET) {
fprintf(stderr, "rinetd: couldn't create " syslog(LOG_ERR, "couldn't create "
"server socket!\n"); "server socket! (%m)\n");
seFds[i] = -1; seFds[i] = -1;
continue; continue;
} }
#ifndef WIN32 #ifndef WIN32
if (seFds[i] > maxfd) { if (seFds[i] > maxfd) {
maxfd = seFds[i]; maxfd = seFds[i];
} }
#endif #endif
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
memcpy(&saddr.sin_addr, &iaddr, sizeof(iaddr)); memcpy(&saddr.sin_addr, &iaddr, sizeof(iaddr));
saddr.sin_port = htons(bindPort); saddr.sin_port = htons(bindPort);
@ -599,8 +640,8 @@ void readConfiguration(void)
&saddr, sizeof(saddr)) == SOCKET_ERROR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
{ {
/* Warn -- don't exit. */ /* Warn -- don't exit. */
fprintf(stderr, "rinetd: couldn't bind to " syslog(LOG_ERR, "couldn't bind to "
"address %s port %d\n", "address %s port %d (%m)\n",
bindAddress, bindPort); bindAddress, bindPort);
closesocket(seFds[i]); closesocket(seFds[i]);
seFds[i] = INVALID_SOCKET; seFds[i] = INVALID_SOCKET;
@ -608,19 +649,19 @@ void readConfiguration(void)
} }
if (listen(seFds[i], 5) == SOCKET_ERROR) { if (listen(seFds[i], 5) == SOCKET_ERROR) {
/* Warn -- don't exit. */ /* Warn -- don't exit. */
fprintf(stderr, "rinetd: couldn't listen to " syslog(LOG_ERR, "couldn't listen to "
"address %s port %d\n", "address %s port %d (%m)\n",
bindAddress, bindPort); bindAddress, bindPort);
closesocket(seFds[i]); closesocket(seFds[i]);
seFds[i] = INVALID_SOCKET; seFds[i] = INVALID_SOCKET;
continue; continue;
} }
ioctlsocket(seFds[i], FIONBIO, &j); ioctlsocket(seFds[i], FIONBIO, &j);
if (!getAddress(connectAddress, &iaddr)) { if (!getAddress(connectAddress, &iaddr)) {
/* Warn -- don't exit. */ /* Warn -- don't exit. */
fprintf(stderr, "rinetd: host %s could not be " syslog(LOG_ERR, "host %s could not be "
"resolved on line %d.\n", "resolved on file %s, line %d.\n",
bindAddress, lnum); bindAddress, options.conf_file, lnum);
closesocket(seFds[i]); closesocket(seFds[i]);
seFds[i] = INVALID_SOCKET; seFds[i] = INVALID_SOCKET;
continue; continue;
@ -646,6 +687,7 @@ void readConfiguration(void)
} }
} }
} }
fclose(in);
/* Open the log file */ /* Open the log file */
if (logFile) { if (logFile) {
fclose(logFile); fclose(logFile);
@ -653,14 +695,16 @@ void readConfiguration(void)
} }
if (logFileName) { if (logFileName) {
logFile = fopen(logFileName, "a"); logFile = fopen(logFileName, "a");
if (!logFile) { if (logFile) {
fprintf(stderr, "rinetd: could not open %s to append.\n", setvbuf(logFile, NULL, _IONBF, 0);
} else {
syslog(LOG_ERR, "could not open %s to append (%m).\n",
logFileName); logFileName);
} }
} }
return; return;
lowMemory: lowMemory:
fprintf(stderr, "rinetd: not enough memory to start rinetd.\n"); syslog(LOG_ERR, "not enough memory to start rinetd.\n");
exit(1); exit(1);
} }
@ -668,6 +712,7 @@ int getConfLine(FILE *in, char *line, int space, int *lnum)
{ {
char *p; char *p;
while (1) { while (1) {
(*lnum)++;
if (!fgets(line, space, in)) { if (!fgets(line, space, in)) {
return 0; return 0;
} }
@ -683,7 +728,6 @@ int getConfLine(FILE *in, char *line, int space, int *lnum)
/* Comment lines are also OK */ /* Comment lines are also OK */
continue; continue;
} }
(*lnum)++;
return 1; return 1;
} }
} }
@ -706,7 +750,7 @@ void initArrays(void)
coOutput = (char **) malloc(sizeof(char *) * coTotal); coOutput = (char **) malloc(sizeof(char *) * coTotal);
coBytesInput = (int *) malloc(sizeof(int) * coTotal); coBytesInput = (int *) malloc(sizeof(int) * coTotal);
coBytesOutput = (int *) malloc(sizeof(int) * coTotal); coBytesOutput = (int *) malloc(sizeof(int) * coTotal);
reAddresses = (unsigned char *) malloc(coTotal * 4); reAddresses = (struct in_addr *) malloc(sizeof(struct in_addr) * coTotal);
coLog = (int *) malloc(sizeof(int) * coTotal); coLog = (int *) malloc(sizeof(int) * coTotal);
coSe = (int *) malloc(sizeof(int) * coTotal); coSe = (int *) malloc(sizeof(int) * coTotal);
if ((!reFds) || (!loFds) || (!coInputRPos) || (!coInputWPos) || if ((!reFds) || (!loFds) || (!coInputRPos) || (!coInputWPos) ||
@ -717,7 +761,7 @@ void initArrays(void)
(!coBytesInput) || (!coBytesOutput) || (!coBytesInput) || (!coBytesOutput) ||
(!coLog) || (!coSe) || (!reAddresses)) (!coLog) || (!coSe) || (!reAddresses))
{ {
fprintf(stderr, "rinetd: not enough memory to start rinetd.\n"); syslog(LOG_ERR, "not enough memory to start rinetd.\n");
exit(1); exit(1);
} }
for (j = 0; (j < coTotal); j++) { for (j = 0; (j < coTotal); j++) {
@ -725,7 +769,7 @@ void initArrays(void)
coInput[j] = (char *) malloc(sizeof(char) * bufferSpace); coInput[j] = (char *) malloc(sizeof(char) * bufferSpace);
coOutput[j] = (char *) malloc(sizeof(char) * bufferSpace); coOutput[j] = (char *) malloc(sizeof(char) * bufferSpace);
if ((!coInput[j]) || (!coOutput[j])) { if ((!coInput[j]) || (!coOutput[j])) {
fprintf(stderr, "rinetd: not enough memory to start " syslog(LOG_ERR, "not enough memory to start "
"rinetd.\n"); "rinetd.\n");
exit(1); exit(1);
} }
@ -946,7 +990,6 @@ void handleLocalWrite(int i)
void handleCloseFromLocal(int i) void handleCloseFromLocal(int i)
{ {
int arg;
coClosing[i] = 1; coClosing[i] = 1;
/* The local end fizzled out, so make sure /* The local end fizzled out, so make sure
we're all done with that */ we're all done with that */
@ -954,25 +997,24 @@ void handleCloseFromLocal(int i)
closesocket(loFds[i]); closesocket(loFds[i]);
loClosed[i] = 1; loClosed[i] = 1;
if (!reClosed[i]) { if (!reClosed[i]) {
#ifndef LINUX #ifndef __linux__
#ifndef WIN32 #ifndef WIN32
/* Now set up the remote end for a polite closing */ /* Now set up the remote end for a polite closing */
/* Request a low-water mark equal to the entire /* Request a low-water mark equal to the entire
output buffer, so the next write notification output buffer, so the next write notification
tells us for sure that we can close the socket. */ tells us for sure that we can close the socket. */
arg = 1024; int arg = 1024;
setsockopt(reFds[i], SOL_SOCKET, SO_SNDLOWAT, setsockopt(reFds[i], SOL_SOCKET, SO_SNDLOWAT,
&arg, sizeof(arg)); &arg, sizeof(arg));
#endif /* WIN32 */ #endif /* WIN32 */
#endif /* LINUX */ #endif /* __linux__ */
coLog[i] = logLocalClosedFirst; coLog[i] = logLocalClosedFirst;
} }
} }
void handleCloseFromRemote(int i) void handleCloseFromRemote(int i)
{ {
int arg;
coClosing[i] = 1; coClosing[i] = 1;
/* The remote end fizzled out, so make sure /* The remote end fizzled out, so make sure
we're all done with that */ we're all done with that */
@ -980,18 +1022,18 @@ void handleCloseFromRemote(int i)
closesocket(reFds[i]); closesocket(reFds[i]);
reClosed[i] = 1; reClosed[i] = 1;
if (!loClosed[i]) { if (!loClosed[i]) {
#ifndef LINUX #ifndef __linux__
#ifndef WIN32 #ifndef WIN32
/* Now set up the local end for a polite closing */ /* Now set up the local end for a polite closing */
/* Request a low-water mark equal to the entire /* Request a low-water mark equal to the entire
output buffer, so the next write notification output buffer, so the next write notification
tells us for sure that we can close the socket. */ tells us for sure that we can close the socket. */
arg = 1024; int arg = 1024;
setsockopt(loFds[i], SOL_SOCKET, SO_SNDLOWAT, setsockopt(loFds[i], SOL_SOCKET, SO_SNDLOWAT,
&arg, sizeof(arg)); &arg, sizeof(arg));
#endif /* WIN32 */ #endif /* WIN32 */
#endif /* LINUX */ #endif /* __linux__ */
loClosed[i] = 0; loClosed[i] = 0;
coLog[i] = logRemoteClosedFirst; coLog[i] = logRemoteClosedFirst;
} }
@ -1003,8 +1045,8 @@ void handleAccept(int i)
{ {
struct sockaddr addr; struct sockaddr addr;
struct sockaddr_in *sin; struct sockaddr_in *sin;
unsigned char address[4]; struct in_addr address;
char addressText[64]; const char *addressText;
int j; int j;
int addrlen; int addrlen;
int index = -1; int index = -1;
@ -1013,20 +1055,21 @@ void handleAccept(int i)
addrlen = sizeof(addr); addrlen = sizeof(addr);
nfd = accept(seFds[i], &addr, &addrlen); nfd = accept(seFds[i], &addr, &addrlen);
if (nfd == INVALID_SOCKET) { if (nfd == INVALID_SOCKET) {
syslog(LOG_ERR,"accept(%d): %m",seFds[i]);
log(-1, i, logAcceptFailed); log(-1, i, logAcceptFailed);
return; return;
} }
#ifndef WIN32 #ifndef WIN32
if (nfd > maxfd) { if (nfd > maxfd) {
maxfd = nfd; maxfd = nfd;
} }
#endif /* WIN32 */ #endif /* WIN32 */
j = 1; j = 1;
ioctlsocket(nfd, FIONBIO, &j); ioctlsocket(nfd, FIONBIO, &j);
j = 0; j = 0;
#ifndef WIN32 #ifndef WIN32
setsockopt(nfd, SOL_SOCKET, SO_LINGER, &j, sizeof(j)); setsockopt(nfd, SOL_SOCKET, SO_LINGER, &j, sizeof(j));
#endif #endif
for (j = 0; (j < coTotal); j++) { for (j = 0; (j < coTotal); j++) {
if (coClosed[j]) { if (coClosed[j]) {
index = j; index = j;
@ -1101,8 +1144,8 @@ void handleAccept(int i)
{ {
goto shortage; goto shortage;
} }
if (!SAFE_REALLOC(&reAddresses, 4 * o, if (!SAFE_REALLOC(&reAddresses, sizeof(struct in_addr) * o,
4 * coTotal)) sizeof(struct in_addr) * coTotal))
{ {
goto shortage; goto shortage;
} }
@ -1161,12 +1204,11 @@ void handleAccept(int i)
coLog[index] = 0; coLog[index] = 0;
coSe[index] = i; coSe[index] = i;
sin = (struct sockaddr_in *) &addr; sin = (struct sockaddr_in *) &addr;
memcpy(address, &(sin->sin_addr.s_addr), 4); reAddresses[index].s_addr = address.s_addr = sin->sin_addr.s_addr;
memcpy(reAddresses + index * 4, address, 4);
/* Now, do we want to accept this connection? /* Now, do we want to accept this connection?
Format it for comparison to a pattern. */ Format it for comparison to a pattern. */
sprintf(addressText, "%d.%d.%d.%d", addressText = inet_ntoa(address);
address[0], address[1], address[2], address[3]);
/* 1. Check global allow rules. If there are no /* 1. Check global allow rules. If there are no
global allow rules, it's presumed OK at global allow rules, it's presumed OK at
this step. If there are any, and it doesn't this step. If there are any, and it doesn't
@ -1226,7 +1268,7 @@ void handleAccept(int i)
openLocalFd(i, index); openLocalFd(i, index);
return; return;
shortage: shortage:
fprintf(stderr, "rinetd: not enough memory to " syslog(LOG_ERR, "not enough memory to "
"add slots. Currently %d slots.\n", o); "add slots. Currently %d slots.\n", o);
/* Go back to the previous total number of slots */ /* Go back to the previous total number of slots */
coTotal = o; coTotal = o;
@ -1238,6 +1280,7 @@ void openLocalFd(int se, int i)
struct sockaddr_in saddr; struct sockaddr_in saddr;
loFds[i] = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); loFds[i] = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (loFds[i] == INVALID_SOCKET) { if (loFds[i] == INVALID_SOCKET) {
syslog(LOG_ERR,"socket(): %m");
closesocket(reFds[i]); closesocket(reFds[i]);
reClosed[i] = 1; reClosed[i] = 1;
loClosed[i] = 1; loClosed[i] = 1;
@ -1245,11 +1288,12 @@ void openLocalFd(int se, int i)
log(i, coSe[i], logLocalSocketFailed); log(i, coSe[i], logLocalSocketFailed);
return; return;
} }
#ifndef WIN32 #ifndef WIN32
if (loFds[i] > maxfd) { if (loFds[i] > maxfd) {
maxfd = loFds[i]; maxfd = loFds[i];
} }
#endif /* WIN32 */ #endif /* WIN32 */
#if 0
/* Bind the local socket */ /* Bind the local socket */
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_port = INADDR_ANY; saddr.sin_port = INADDR_ANY;
@ -1263,26 +1307,27 @@ void openLocalFd(int se, int i)
log(i, coSe[i], logLocalBindFailed); log(i, coSe[i], logLocalBindFailed);
return; return;
} }
#endif
memset(&saddr, 0, sizeof(struct sockaddr_in)); memset(&saddr, 0, sizeof(struct sockaddr_in));
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
memcpy(&saddr.sin_addr, &seLocalAddrs[se], sizeof(struct in_addr)); memcpy(&saddr.sin_addr, &seLocalAddrs[se], sizeof(struct in_addr));
saddr.sin_port = seLocalPorts[se]; saddr.sin_port = seLocalPorts[se];
#ifndef WIN32 #ifndef WIN32
#ifdef LINUX #ifdef __linux__
j = 0; j = 0;
setsockopt(loFds[i], SOL_SOCKET, SO_LINGER, &j, sizeof(j)); setsockopt(loFds[i], SOL_SOCKET, SO_LINGER, &j, sizeof(j));
#else #else
j = 1024; j = 1024;
setsockopt(loFds[i], SOL_SOCKET, SO_SNDBUF, &j, sizeof(j)); setsockopt(loFds[i], SOL_SOCKET, SO_SNDBUF, &j, sizeof(j));
#endif /* LINUX */ #endif /* __linux__ */
#endif /* WIN32 */ #endif /* WIN32 */
j = 1; j = 1;
ioctlsocket(loFds[i], FIONBIO, &j); ioctlsocket(loFds[i], FIONBIO, &j);
if (connect(loFds[i], (struct sockaddr *)&saddr, if (connect(loFds[i], (struct sockaddr *)&saddr,
sizeof(struct sockaddr_in)) == INVALID_SOCKET) sizeof(struct sockaddr_in)) == INVALID_SOCKET)
{ {
if ((GetLastError() != WSAEINPROGRESS) && if ((GetLastError() != WSAEINPROGRESS) &&
(GetLastError() != WSAEWOULDBLOCK)) (GetLastError() != WSAEWOULDBLOCK))
{ {
PERROR("rinetd: connect"); PERROR("rinetd: connect");
closesocket(loFds[i]); closesocket(loFds[i]);
@ -1301,7 +1346,7 @@ int getAddress(char *host, struct in_addr *iaddr)
char *p = host; char *p = host;
int ishost = 0; int ishost = 0;
while (*p) { while (*p) {
if (!(isdigit(*p) || ((*p) == '.'))) { if (!isdigit(*p) && ((*p)!='.')) {
ishost = 1; ishost = 1;
break; break;
} }
@ -1311,6 +1356,23 @@ int getAddress(char *host, struct in_addr *iaddr)
struct hostent *h; struct hostent *h;
h = gethostbyname(host); h = gethostbyname(host);
if (!h) { if (!h) {
const char *msg="(unknown DNS error)";
switch(h_errno)
{
case HOST_NOT_FOUND:
msg="The specified host is unknown.";
break;
case NO_ADDRESS:
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",host,msg);
return 0; return 0;
} }
memcpy( memcpy(
@ -1323,22 +1385,27 @@ int getAddress(char *host, struct in_addr *iaddr)
return 1; return 1;
} }
} }
#ifndef WIN32 #ifndef WIN32
void plumber(int s) #ifndef HAVE_SIGACTION
RETSIGTYPE plumber(int s)
{ {
/* Just reinstall */ /* Just reinstall */
signal(SIGPIPE, plumber); signal(SIGPIPE, plumber);
} }
#endif
void hup(int s) RETSIGTYPE hup(int s)
{ {
syslog(LOG_INFO,"Received SIGHUP, reloading configuration...");
/* Learn the new rules */ /* Learn the new rules */
readConfiguration(); readConfiguration();
#ifndef HAVE_SIGACTION
/* And reinstall the signal handler */ /* And reinstall the signal handler */
signal(SIGHUP, hup); signal(SIGHUP, hup);
#endif
} }
#endif /* WIN32 */ #endif /* WIN32 */
int safeRealloc(void **data, int oldsize, int newsize) int safeRealloc(void **data, int oldsize, int newsize)
{ {
@ -1358,32 +1425,37 @@ int safeRealloc(void **data, int oldsize, int newsize)
void RegisterPID(void) void RegisterPID(void)
{ {
FILE *pid_file; FILE *pid_file;
char *pid_file_name = "/var/run/rinetd.pid"; const char *pid_file_name = "/var/run/rinetd.pid";
if (pidLogFileName) { if (pidLogFileName) {
pid_file_name = pidLogFileName; pid_file_name = pidLogFileName;
} }
/* add other systems with wherever they register processes */ /* add other systems with wherever they register processes */
#if defined(LINUX) #if defined(__linux__)
pid_file = fopen(pid_file_name, "w"); pid_file = fopen(pid_file_name, "w");
if (pid_file == NULL) { if (pid_file == NULL) {
/* non-fatal, non-Linux may lack /var/run... */ /* non-fatal, non-Linux may lack /var/run... */
fprintf(stderr, "rinetd: Couldn't write to " goto error;
"%s. PID was not logged.\n", pid_file_name);
} else { } else {
/* error checking deliberately omitted */
fprintf(pid_file, "%d\n", getpid()); fprintf(pid_file, "%d\n", getpid());
fclose(pid_file); /* errors aren't fatal */
if(fclose(pid_file))
goto error;
} }
#endif /* LINUX */ return;
error:
syslog(LOG_ERR, "Couldn't write to "
"%s. PID was not logged (%m).\n", pid_file_name);
#endif /* __linux__ */
} }
unsigned char nullAddress[4] = { 0, 0, 0, 0 }; struct in_addr nullAddress = { 0 };
struct tm *get_gmtoff(int *tz); struct tm *get_gmtoff(int *tz);
void log(int i, int coSe, int result) void log(int i, int coSe, int result)
{ {
unsigned char *reAddress; struct in_addr *reAddress;
const char *addressText;
int bytesOutput; int bytesOutput;
int bytesInput; int bytesInput;
/* Bit of borrowing from Apache logging module here, /* Bit of borrowing from Apache logging module here,
@ -1403,14 +1475,19 @@ void log(int i, int coSe, int result)
strftime(tstr, sizeof(tstr), "%d/%b/%Y:%H:%M:%S ", t); strftime(tstr, sizeof(tstr), "%d/%b/%Y:%H:%M:%S ", t);
if (i != -1) { if (i != -1) {
reAddress = reAddresses + i * 4; reAddress = reAddresses + i;
bytesOutput = coBytesOutput[i]; bytesOutput = coBytesOutput[i];
bytesInput = coBytesInput[i]; bytesInput = coBytesInput[i];
} else { } else {
reAddress = nullAddress; reAddress = &nullAddress;
bytesOutput = 0; bytesOutput = 0;
bytesInput = 0; bytesInput = 0;
} }
addressText = inet_ntoa(*reAddress);
if(result==logNotAllowed || result==logDenied)
syslog(LOG_INFO,"%s %s"
,addressText
,logMessages[result]);
if (logFile) { if (logFile) {
if (logFormatCommon) { if (logFormatCommon) {
/* Fake a common log format log file in a way that /* Fake a common log format log file in a way that
@ -1425,14 +1502,11 @@ void log(int i, int coSe, int result)
after several placeholders meant to fill the after several placeholders meant to fill the
positions frequently occupied by user agent, positions frequently occupied by user agent,
referrer, and server name information. */ referrer, and server name information. */
fprintf(logFile, "%d.%d.%d.%d - - " fprintf(logFile, "%s - - "
"[%s %c%.2d%.2d] " "[%s %c%.2d%.2d] "
"\"GET /rinetd-services/%s/%d/%s/%d/%s HTTP/1.0\" " "\"GET /rinetd-services/%s/%d/%s/%d/%s HTTP/1.0\" "
"200 %d - - - %d\n", "200 %d - - - %d\n",
reAddress[0], addressText,
reAddress[1],
reAddress[2],
reAddress[3],
tstr, tstr,
sign, sign,
timz / 60, timz / 60,
@ -1445,13 +1519,10 @@ void log(int i, int coSe, int result)
} else { } else {
/* Write an rinetd-specific log entry with a /* Write an rinetd-specific log entry with a
less goofy format. */ less goofy format. */
fprintf(logFile, "%s\t%d.%d.%d.%d\t%s\t%d\t%s\t%d\t%d" fprintf(logFile, "%s\t%s\t%s\t%d\t%s\t%d\t%d"
"\t%d\t%s\n", "\t%d\t%s\n",
tstr, tstr,
reAddress[0], addressText,
reAddress[1],
reAddress[2],
reAddress[3],
seFromHosts[coSe], seFromPorts[coSe], seFromHosts[coSe], seFromPorts[coSe],
seToHosts[coSe], seToPorts[coSe], seToHosts[coSe], seToPorts[coSe],
bytesInput, bytesInput,
@ -1468,32 +1539,39 @@ int readArgs (int argc,
int c; int c;
while (1) { while (1) {
char *buf;
int option_index = 0; int option_index = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"conf-file", 1, 0, 'c'}, {"conf-file", 1, 0, 'c'},
{"foreground", 0, 0, 'f'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"version", 0, 0, 'v'}, {"version", 0, 0, 'v'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
c = getopt_long (argc, argv, "c:shv", c = getopt_long (argc, argv, "c:fshv",
long_options, &option_index); long_options, &option_index);
if (c == -1) { if (c == -1) {
break; break;
} }
switch (c) { switch (c) {
case 'c': case 'c':
options->conf_file = malloc(strlen(optarg) + 1); buf = strdup(optarg);
if (!options->conf_file) { if (!buf) {
fprintf(stderr, "Not enough memory to " syslog(LOG_ERR, "Not enough memory to "
"launch rinetd.\n"); "launch rinetd.\n");
exit(1); exit(1);
} }
strcpy(options->conf_file, optarg); options->conf_file=buf;
break;
case 'f':
options->foreground=1;
break; break;
case 'h': case 'h':
printf("Usage: rinetd [OPTION]\n" printf("Usage: rinetd [OPTION]\n"
" -c, --conf-file FILE read configuration " " -c, --conf-file FILE read configuration "
"from FILE\n" "from FILE\n"
" -f, --foreground do not run in the "
"background\n"
" -h, --help display this help\n" " -h, --help display this help\n"
" -v, --version display version " " -v, --version display version "
"number\n\n"); "number\n\n");
@ -1508,7 +1586,7 @@ int readArgs (int argc,
default: default:
exit (1); exit (1);
} }
} }
return 0; return 0;
} }
@ -1554,7 +1632,7 @@ void refuse(int index, int logCode)
log(index, coSe[index], logCode); log(index, coSe[index], logCode);
} }
void term(int s) RETSIGTYPE term(int s)
{ {
/* Obey the request, but first flush the log */ /* Obey the request, but first flush the log */
if (logFile) { if (logFile) {

25
rinetd.conf Normal file
View File

@ -0,0 +1,25 @@
#
# this is the configuration file for rinetd, the internet redirection server
#
# you may specify global allow and deny rules here
# only ip addresses are matched, hostnames cannot be specified here
# the wildcards you may use are * and ?
#
# allow 192.168.2.*
# deny 192.168.2.1?
#
# forwarding rules come here
#
# you may specify allow and deny rules after a specific forwarding rule
# to apply to only that forwarding rule
#
# bindadress bindport connectaddress connectport
# logging information
logfile /var/log/rinetd.log
# uncomment the following line if you want web-server style logfile format
# logcommon

1
stamp-h.in Normal file
View File

@ -0,0 +1 @@
timestamp