Added -t option
authorAlan T. DeKok <aland@freeradius.org>
Tue, 3 Aug 2010 09:41:24 +0000 (11:41 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 4 Aug 2010 13:08:28 +0000 (15:08 +0200)
This lets people use radtest for CHAP and MS-CHAP authentication,
without worrying too much about the internals of what's going on.y

man/man1/radtest.1
src/main/radtest.in

index 277165e..f454b4f 100644 (file)
@@ -1,10 +1,14 @@
-.TH RADTEST 1 "24 February 2001" "" "FreeRADIUS Daemon"
+.TH RADTEST 1 "3 August 2010" "" "FreeRADIUS Daemon"
 .SH NAME
 radtest - send packets to a RADIUS server, show reply
 .SH SYNOPSIS
 .B radtest
 .RB [ \-d
 .IR raddb_directory ]
+.RB [ \-t
+.IR pap/chap/mschap ]
+.RB [ \-x
+.IR ]
 .I user password radius-server nas-port-number secret
 .RB [ ppphint ]
 .RB [ nasname ]
@@ -20,6 +24,13 @@ way to test a radius server.
 The directory that contains the RADIUS dictionary files. Defaults to
 \fI/etc/raddb\fP.
 
+.IP "\-t \fIpap/chap/mschap\fP"
+Choose the authentiction method to use.  e.g. "-t pap", or "-t
+mschap".  Defaults to "pap".
+
+.IP "\-x"
+Enables debugging output for the RADIUS client.
+
 .IP user
 Username to send.
 
index 60248a5..e63e0df 100644 (file)
@@ -11,7 +11,10 @@ exec_prefix="@exec_prefix@"
 bindir="@bindir@"
 
 usage() {
-       echo "Usage: radtest user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]" >&2
+       echo "Usage: radtest [OPTIONS] user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]" >&2
+       echo "        -d RADIUS_DIR       Set radius directory" >&2
+       echo "        -t pap/chap/mschap  Set authentication method" >&2
+       echo "        -x                  Enable debug output" >&2
        exit 1
 }
 
@@ -21,14 +24,54 @@ then
        radclient=./radclient
 fi
 
-if [ "$1" = "-d" ]
+OPTIONS=
+PASSWORD="User-Password"
+
+#  We need at LEAST these many options
+if [ $# -lt 5 ] || [ $# -gt 7 ]
 then
-    DICTIONARY="-d $2"
-    shift;shift
-else
-    DICTIONARY=""
+       usage
 fi
 
+# Parse new command-line options
+while [ `echo "$1" | cut -c 1` = "-" ]
+do
+   case "$1" in
+       -d) 
+               OPTIONS="$OPTIONS -d $2"
+               shift;shift
+               ;;
+       -x)
+               OPTIONS="$OPTIONS -x"
+               shift
+               ;;
+
+       -t)
+               shift;
+               case "$1" in
+                       pap)
+                               PASSWORD="User-Password"
+                               ;;
+                       chap)
+                               PASSWORD="CHAP-Password"
+                               ;;
+                       mschap)
+                               PASSWORD="MS-CHAP-Password"
+                               ;;
+                       *)
+                               usage
+                               ;;
+               esac
+               shift
+               ;;
+
+        *)
+               usage
+               ;;
+  esac
+done
+
+# Check that there are enough options left over.
 if [ $# -lt 5 ] || [ $# -gt 7 ]
 then
        usage
@@ -43,13 +86,13 @@ fi
 
 (
        echo "User-Name = \"$1\""
-       echo "User-Password = \"$2\""
+       echo "$PASSWORD = \"$2\""
        echo "NAS-IP-Address = $nas"
        echo "NAS-Port = $4"
        if [ "$6" ]
        then
                echo "Framed-Protocol = PPP"
        fi
-) | $radclient $DICTIONARY -x $3 auth $5
+) | $radclient $OPTIONS -x $3 auth $5
 
 exit $?