pull from https://www.ratbox.org/respond/
This commit is contained in:
commit
971b19fb99
7 changed files with 5026 additions and 0 deletions
29
Makefile.in
Normal file
29
Makefile.in
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# $Id: Makefile.in 21587 2006-01-06 18:12:17Z leeh $
|
||||||
|
#
|
||||||
|
# Copyright (C) 2005 ircd-ratbox development team
|
||||||
|
# This code is in the public domain.
|
||||||
|
|
||||||
|
prefix = @prefix@
|
||||||
|
exec_prefix = @exec_prefix@
|
||||||
|
bindir = @bindir@
|
||||||
|
|
||||||
|
CFLAGS = @CFLAGS@
|
||||||
|
CPPFLAGS = @CPPFLAGS@
|
||||||
|
LDFLAGS = @LDFLAGS@
|
||||||
|
LIBS = @LIBS@
|
||||||
|
SSL_INCLUDES = @SSL_INCLUDES@
|
||||||
|
SSL_LIBS = @SSL_LIBS@
|
||||||
|
|
||||||
|
CC = @CC@
|
||||||
|
RM = @RM@
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
|
build: ratbox-respond.c
|
||||||
|
${CC} ${CFLAGS} ${CPPFLAGS} ${SSL_INCLUDES} -o ratbox-respond ratbox-respond.c ${LDFLAGS} ${LIBS} ${SSL_LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
${RM} -f ratbox-respond *~
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
${RM} -f config.status config.cache config.log setup.h Makefile
|
56
README
Normal file
56
README
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
- ratbox-respond -
|
||||||
|
------------------
|
||||||
|
ratbox-respond takes the challenge from the server and creates a valid
|
||||||
|
response to pass back to the server.
|
||||||
|
|
||||||
|
ratbox-respond will run either interactively, or can have input piped to it
|
||||||
|
through stdin.
|
||||||
|
|
||||||
|
- Compiling -
|
||||||
|
-------------
|
||||||
|
Run:
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
|
||||||
|
This will generate a 'ratbox-respond' binary, which you may place wherever
|
||||||
|
you like. If configure does not detect your openssl installation, you may
|
||||||
|
pass it the directory where it is installed to via --enable-openssl, this
|
||||||
|
should be the base directory which has lib/ and include/openssl/ within it:
|
||||||
|
./configure --enable-openssl=/path/to/opensslbase
|
||||||
|
|
||||||
|
|
||||||
|
- ratbox-respond usage -
|
||||||
|
------------------------
|
||||||
|
ratbox-respond takes only one argument, the path to your private key:
|
||||||
|
./ratbox-respond /path/to/private.key
|
||||||
|
|
||||||
|
|
||||||
|
- Interactive mode -
|
||||||
|
--------------------
|
||||||
|
ratbox-respond runs in interactive mode when it detects theres a tty
|
||||||
|
attached (eg, you run ./ratbox-respond from a normal shell). This will
|
||||||
|
prompt for keyphrases and the challenge, and will generate the output to be
|
||||||
|
given to ircd.
|
||||||
|
|
||||||
|
|
||||||
|
- Non-interactive mode -
|
||||||
|
------------------------
|
||||||
|
To allow for ratbox-respond to be called from a script, input may be piped
|
||||||
|
to ratbox-respond through stdin. The format of the input is:
|
||||||
|
keyphrase\nchallenge\n
|
||||||
|
|
||||||
|
If there is no keyphrase, the \n preceding the challenge from ircd must
|
||||||
|
still be sent. Output will be given on stdout, and will be just the
|
||||||
|
response needed to be sent back to ircd.
|
||||||
|
|
||||||
|
It is required that input is piped for security reasons, as allowing the
|
||||||
|
keyphrase to appear in ps is insecure.
|
||||||
|
|
||||||
|
An example to illustrate this is:
|
||||||
|
echo "keyphrase\nchallenge" | /path/to/ratbox-respond /path/to/key
|
||||||
|
Though this is equally insecure, as the echo will appear in process lists.
|
||||||
|
It can be done better in perl for example, by using the open2() function,
|
||||||
|
see client-scripts/challenge-xchat.pl for an implementation.
|
||||||
|
|
||||||
|
--
|
||||||
|
- $Id: README 21696 2006-01-14 22:30:32Z leeh $ -
|
137
configure.ac
Normal file
137
configure.ac
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
dnl $Id: configure.ac 21635 2006-01-11 21:52:17Z leeh $
|
||||||
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
|
AC_PREREQ(2.57)
|
||||||
|
AC_COPYRIGHT([$Id: configure.ac 21635 2006-01-11 21:52:17Z leeh $])
|
||||||
|
AC_INIT([ratbox-respond],[stable])
|
||||||
|
|
||||||
|
AC_CONFIG_HEADER(setup.h)
|
||||||
|
AC_PREFIX_DEFAULT(.)
|
||||||
|
AC_GNU_SOURCE
|
||||||
|
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
|
||||||
|
AC_PATH_PROG(RM, rm)
|
||||||
|
AC_PATH_PROG(CP, cp)
|
||||||
|
AC_PATH_PROG(MV, mv)
|
||||||
|
AC_PATH_PROG(TOUCH, touch)
|
||||||
|
|
||||||
|
AC_LANG(C)
|
||||||
|
|
||||||
|
AC_HEADER_STDC
|
||||||
|
|
||||||
|
CPPFLAGS="-I /usr/include"
|
||||||
|
LIBS="-L /usr/lib"
|
||||||
|
|
||||||
|
dnl OpenSSL support
|
||||||
|
AC_MSG_CHECKING(for OpenSSL)
|
||||||
|
AC_ARG_ENABLE(openssl,
|
||||||
|
[AC_HELP_STRING([--enable-openssl[=DIR]],[Enable OpenSSL support (DIR optional).])],
|
||||||
|
[cf_enable_openssl=$enableval],
|
||||||
|
[cf_enable_openssl="auto"])
|
||||||
|
|
||||||
|
if test "$cf_enable_openssl" != "no" ; then
|
||||||
|
cf_openssl_basedir=""
|
||||||
|
if test "$cf_enable_openssl" != "auto" &&
|
||||||
|
test "$cf_enable_openssl" != "yes" ; then
|
||||||
|
dnl Support for --enable-openssl=/some/place
|
||||||
|
cf_openssl_basedir="`echo ${cf_enable_openssl} | sed 's/\/$//'`"
|
||||||
|
else
|
||||||
|
dnl Do the auto-probe here. Check some common directory paths.
|
||||||
|
for dirs in /usr/local/ssl /usr/pkg /usr/local \
|
||||||
|
/usr/local/openssl ; do
|
||||||
|
if test -f "${dirs}/include/openssl/opensslv.h" ; then
|
||||||
|
cf_openssl_basedir="${dirs}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
unset dirs
|
||||||
|
fi
|
||||||
|
dnl Now check cf_openssl_found to see if we found anything.
|
||||||
|
if test ! -z "$cf_openssl_basedir"; then
|
||||||
|
if test -f "${cf_openssl_basedir}/include/openssl/opensslv.h" ; then
|
||||||
|
SSL_INCLUDES="-I${cf_openssl_basedir}/include"
|
||||||
|
SSL_LIBS="-L${cf_openssl_basedir}/lib"
|
||||||
|
else
|
||||||
|
dnl OpenSSL wasn't found in the directory specified. Naughty
|
||||||
|
dnl administrator...
|
||||||
|
cf_openssl_basedir=""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
dnl Check for stock FreeBSD 4.x and 5.x systems, since their files
|
||||||
|
dnl are in /usr/include and /usr/lib. In this case, we don't want to
|
||||||
|
dnl change INCLUDES or LIBS, but still want to enable OpenSSL.
|
||||||
|
dnl We can't do this check above, because some people want two versions
|
||||||
|
dnl of OpenSSL installed (stock FreeBSD 4.x/5.x and /usr/local/ssl)
|
||||||
|
dnl and they want /usr/local/ssl to have preference.
|
||||||
|
if test -f "/usr/include/openssl/opensslv.h" ; then
|
||||||
|
cf_openssl_basedir="/usr"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl If we have a basedir defined, then everything is okay. Otherwise,
|
||||||
|
dnl we have a problem.
|
||||||
|
if test ! -z "$cf_openssl_basedir"; then
|
||||||
|
AC_MSG_RESULT($cf_openssl_basedir)
|
||||||
|
cf_enable_openssl="yes"
|
||||||
|
else
|
||||||
|
AC_MSG_RESULT([not found. Specify a correct path?])
|
||||||
|
cf_enable_openssl="no"
|
||||||
|
fi
|
||||||
|
unset cf_openssl_basedir
|
||||||
|
else
|
||||||
|
dnl If --disable-openssl was specified
|
||||||
|
AC_MSG_RESULT(disabled)
|
||||||
|
AC_MSG_ERROR([Need openssl to compile ratbox-respond])
|
||||||
|
fi
|
||||||
|
|
||||||
|
save_CPPFLAGS="$CPPFLAGS"
|
||||||
|
CPPFLAGS="$CPPFLAGS $SSL_INCLUDES"
|
||||||
|
save_LIBS="$LIBS"
|
||||||
|
LIBS="$LIBS $SSL_LIBS"
|
||||||
|
if test "$cf_enable_openssl" != no; then
|
||||||
|
dnl Check OpenSSL version (must be 0.9.6 or above!)
|
||||||
|
AC_MSG_CHECKING(for OpenSSL 0.9.6 or above)
|
||||||
|
AC_RUN_IFELSE(
|
||||||
|
AC_LANG_PROGRAM(
|
||||||
|
[#include <openssl/opensslv.h>
|
||||||
|
#include <stdlib.h>],
|
||||||
|
[[if (OPENSSL_VERSION_NUMBER >= 0x00906000)
|
||||||
|
exit(0); else exit(1);]]),
|
||||||
|
cf_openssl_version_ok=yes,
|
||||||
|
cf_openssl_version_ok=no,
|
||||||
|
cf_openssl_version_ok=no)
|
||||||
|
|
||||||
|
if test "$cf_openssl_version_ok" = yes; then
|
||||||
|
AC_MSG_RESULT(found)
|
||||||
|
|
||||||
|
dnl Do all the HAVE_LIBCRYPTO magic -- and check for ciphers
|
||||||
|
CPPFLAGS="$CPPFLAGS $SSL_LIBS"
|
||||||
|
AC_CHECK_LIB(crypto, RSA_free)
|
||||||
|
SSL_LIBS="$SSL_LIBS -lcrypto"
|
||||||
|
SSL_SRCS_ENABLE='$(SSL_SRCS)'
|
||||||
|
else
|
||||||
|
AC_MSG_RESULT(no - OpenSSL support disabled)
|
||||||
|
AC_MSG_ERROR([Need openssl to compile ratbox-respond])
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
AC_MSG_ERROR([Need openssl development files to compile ratbox-respond])
|
||||||
|
fi
|
||||||
|
|
||||||
|
CPPFLAGS="$save_CPPFLAGS"
|
||||||
|
LIBS="$save_LIBS"
|
||||||
|
|
||||||
|
dnl End OpenSSL detection
|
||||||
|
|
||||||
|
AC_SUBST(CFLAGS)
|
||||||
|
AC_SUBST(CPPFLAGS)
|
||||||
|
AC_SUBST(LIBS)
|
||||||
|
|
||||||
|
AC_SUBST(SSL_SRCS_ENABLE)
|
||||||
|
AC_SUBST(SSL_INCLUDES)
|
||||||
|
AC_SUBST(SSL_LIBS)
|
||||||
|
|
||||||
|
AC_CONFIG_FILES(Makefile)
|
||||||
|
|
||||||
|
AC_OUTPUT
|
270
install-sh
Executable file
270
install-sh
Executable file
|
@ -0,0 +1,270 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# $Id: install-sh 21587 2006-01-06 18:12:17Z leeh $
|
||||||
|
#
|
||||||
|
# install - install a program, script, or datafile
|
||||||
|
#
|
||||||
|
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||||
|
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||||
|
# following copyright and license.
|
||||||
|
#
|
||||||
|
# Copyright (C) 1994 X Consortium
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to
|
||||||
|
# deal in the Software without restriction, including without limitation the
|
||||||
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
# sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||||
|
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# Except as contained in this notice, the name of the X Consortium shall not
|
||||||
|
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||||
|
# ings in this Software without prior written authorization from the X Consor-
|
||||||
|
# tium.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# FSF changes to this file are in the public domain.
|
||||||
|
#
|
||||||
|
# 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
|
275
ratbox-respond.c
Normal file
275
ratbox-respond.c
Normal file
|
@ -0,0 +1,275 @@
|
||||||
|
/*
|
||||||
|
* respond.c: A challenge response generator for ircd-ratbox
|
||||||
|
*
|
||||||
|
* Note: This is not compatible with previous versions of the CHALLENGE
|
||||||
|
* command, as the prior version was seriously flawed in many ways.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2001 by the past and present ircd-hybrid developers.
|
||||||
|
* Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
* $Id: ratbox-respond.c 21723 2006-01-19 17:57:07Z androsyn $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/rsa.h>
|
||||||
|
#include <openssl/pem.h>
|
||||||
|
#include <openssl/sha.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int called_passcb = 0;
|
||||||
|
static int pass_cb(char *buf, int size, int rwflag, void *u)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
called_passcb++;
|
||||||
|
|
||||||
|
if(!isatty(fileno(stdin)))
|
||||||
|
{
|
||||||
|
if(fgets(buf, size, stdin) == NULL)
|
||||||
|
return 0;
|
||||||
|
tmp = strpbrk(buf, "\r\n");
|
||||||
|
if(tmp != NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
return strlen(buf);
|
||||||
|
}
|
||||||
|
tmp = getpass("Enter passphrase for private key: ");
|
||||||
|
len = strlen(tmp);
|
||||||
|
if (len <= 0)
|
||||||
|
return 0;
|
||||||
|
if (len > size)
|
||||||
|
len = size;
|
||||||
|
memcpy(buf, tmp, len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char base64_table[] =
|
||||||
|
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||||
|
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||||
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||||
|
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char base64_pad = '=';
|
||||||
|
|
||||||
|
static const short base64_reverse_table[256] = {
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
|
||||||
|
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||||
|
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
|
||||||
|
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||||
|
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned char *
|
||||||
|
base64_encode(const unsigned char *str, int length)
|
||||||
|
{
|
||||||
|
const unsigned char *current = str;
|
||||||
|
unsigned char *p;
|
||||||
|
unsigned char *result;
|
||||||
|
|
||||||
|
if ((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = malloc(((length + 2) / 3) * 4);
|
||||||
|
p = result;
|
||||||
|
|
||||||
|
while (length > 2)
|
||||||
|
{
|
||||||
|
*p++ = base64_table[current[0] >> 2];
|
||||||
|
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
|
||||||
|
*p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
|
||||||
|
*p++ = base64_table[current[2] & 0x3f];
|
||||||
|
|
||||||
|
current += 3;
|
||||||
|
length -= 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length != 0) {
|
||||||
|
*p++ = base64_table[current[0] >> 2];
|
||||||
|
if (length > 1) {
|
||||||
|
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
|
||||||
|
*p++ = base64_table[(current[1] & 0x0f) << 2];
|
||||||
|
*p++ = base64_pad;
|
||||||
|
} else {
|
||||||
|
*p++ = base64_table[(current[0] & 0x03) << 4];
|
||||||
|
*p++ = base64_pad;
|
||||||
|
*p++ = base64_pad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*p = '\0';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *
|
||||||
|
base64_decode(const unsigned char *str, int length, int *ret)
|
||||||
|
{
|
||||||
|
const unsigned char *current = str;
|
||||||
|
int ch, i = 0, j = 0, k;
|
||||||
|
unsigned char *result;
|
||||||
|
|
||||||
|
result = malloc(length + 1);
|
||||||
|
|
||||||
|
while ((ch = *current++) != '\0' && length-- > 0) {
|
||||||
|
if (ch == base64_pad) break;
|
||||||
|
|
||||||
|
ch = base64_reverse_table[ch];
|
||||||
|
if (ch < 0) continue;
|
||||||
|
|
||||||
|
switch(i % 4) {
|
||||||
|
case 0:
|
||||||
|
result[j] = ch << 2;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
result[j++] |= ch >> 4;
|
||||||
|
result[j] = (ch & 0x0f) << 4;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
result[j++] |= ch >>2;
|
||||||
|
result[j] = (ch & 0x03) << 6;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
result[j++] |= ch;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
k = j;
|
||||||
|
|
||||||
|
if (ch == base64_pad) {
|
||||||
|
switch(i % 4) {
|
||||||
|
case 1:
|
||||||
|
free(result);
|
||||||
|
return NULL;
|
||||||
|
case 2:
|
||||||
|
k++;
|
||||||
|
case 3:
|
||||||
|
result[k++] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result[j] = '\0';
|
||||||
|
*ret = j;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *
|
||||||
|
read_challenge(FILE *f)
|
||||||
|
{
|
||||||
|
static unsigned char buf[16384];
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if(isatty(fileno(f)))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Please paste challenge text now\n");
|
||||||
|
} else {
|
||||||
|
if(!called_passcb)
|
||||||
|
{
|
||||||
|
/* throw away the unneeded password line */
|
||||||
|
fgets((char *)buf, sizeof(buf), f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fgets((char *)buf, sizeof(buf), stdin);
|
||||||
|
|
||||||
|
tmp = strpbrk((char *)buf, "\r\n");
|
||||||
|
if(tmp != NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
|
||||||
|
// fread(buf, sizeof(buf), 1, f);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
FILE *kfile;
|
||||||
|
RSA *rsa = NULL;
|
||||||
|
SHA_CTX ctx;
|
||||||
|
unsigned char *ptr;
|
||||||
|
unsigned char *ndata, ddata[512];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
/* respond privatefile challenge */
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
puts("Error: Usage: respond privatefile");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(kfile = fopen(argv[1], "r")))
|
||||||
|
{
|
||||||
|
puts("Error: Could not open the private keyfile.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSLeay_add_all_ciphers();
|
||||||
|
rsa = PEM_read_RSAPrivateKey(kfile, NULL,pass_cb, NULL);
|
||||||
|
|
||||||
|
if(!rsa)
|
||||||
|
{
|
||||||
|
puts("Error: Unable to read your private key, is the passphrase wrong?");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(kfile);
|
||||||
|
|
||||||
|
ptr = read_challenge(stdin);
|
||||||
|
ndata = base64_decode(ptr, strlen((char *)ptr), &len);
|
||||||
|
if (ndata == NULL)
|
||||||
|
{
|
||||||
|
puts("Error: Bad challenge.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((len = RSA_private_decrypt(len, (unsigned char*)ndata,
|
||||||
|
(unsigned char*)ddata, rsa, RSA_PKCS1_OAEP_PADDING)) == -1)
|
||||||
|
{
|
||||||
|
puts("Error: Decryption error.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA1_Init(&ctx);
|
||||||
|
SHA1_Update(&ctx, (unsigned char *)ddata, len);
|
||||||
|
SHA1_Final((unsigned char *)ddata, &ctx);
|
||||||
|
ndata = base64_encode((unsigned char *)ddata, SHA_DIGEST_LENGTH);
|
||||||
|
if(isatty(fileno(stdin)))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Response: /quote CHALLENGE +");
|
||||||
|
}
|
||||||
|
puts((char *)ndata);
|
||||||
|
fflush(NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
27
setup.h.in
Normal file
27
setup.h.in
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* setup.h.in. Generated from configure.ac by autoheader. */
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||||
|
#undef HAVE_LIBCRYPTO
|
||||||
|
|
||||||
|
/* 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 to 1 if you have the ANSI C header files. */
|
||||||
|
#undef STDC_HEADERS
|
||||||
|
|
||||||
|
/* Enable GNU extensions on systems that have them. */
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
# undef _GNU_SOURCE
|
||||||
|
#endif
|
Loading…
Reference in a new issue