Allow spaces in shared secret, as posted to the list.
[freeradius.git] / src / main / radtest.in
1 #! /bin/sh
2 #
3 # radtest       Emulate the user interface of the old
4 #               radtest that used to be part of FreeRADIUS.
5 #
6 # Version:      $Id$
7 #
8
9 prefix="@prefix@"
10 exec_prefix="@exec_prefix@"
11 bindir="@bindir@"
12
13 usage() {
14         echo "Usage: radtest [OPTIONS] user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]" >&2
15         echo "        -d RADIUS_DIR       Set radius directory" >&2
16         echo "        -t <type>           Set authentication method" >&2
17         echo "                            type can be pap, chap, mschap, or eap-md5" >&2
18         echo "        -x                  Enable debug output" >&2
19         exit 1
20 }
21
22 radclient=$bindir/radclient
23 if [ ! -x "$radclient" ] && [ -x ./radclient ]
24 then
25         radclient=./radclient
26 fi
27
28 # radeapclient is used for EAP-MD5.
29 radeapclient=$bindir/radeapclient
30
31 OPTIONS=
32 PASSWORD="User-Password"
33
34 #  We need at LEAST these many options
35 if [ $# -lt 5 ]
36 then
37         usage
38 fi
39
40 # Parse new command-line options
41 while [ `echo "$1" | cut -c 1` = "-" ]
42 do
43    case "$1" in
44         -d) 
45                 OPTIONS="$OPTIONS -d $2"
46                 shift;shift
47                 ;;
48         -x)
49                 OPTIONS="$OPTIONS -x"
50                 shift
51                 ;;
52
53         -t)
54                 shift;
55                 case "$1" in
56                         pap)
57                                 PASSWORD="User-Password"
58                                 ;;
59                         chap)
60                                 PASSWORD="CHAP-Password"
61                                 ;;
62                         mschap)
63                                 PASSWORD="MS-CHAP-Password"
64                                 ;;
65                         eap-md5)
66                                 PASSWORD="User-Password"
67                                 if [ ! -x "$radeapclient" ]
68                                 then
69                                     echo "radtest: No 'radeapclient' program was found.  Cannot perform EAP-MD5." >&1
70                                     exit 1
71                                 fi
72                                 radclient="$radeapclient"
73                                 ;;
74                         *)
75                                 usage
76                                 ;;
77                 esac
78                 shift
79                 ;;
80
81         *)
82                 usage
83                 ;;
84   esac
85 done
86
87 # Check that there are enough options left over.
88 if [ $# -lt 5 ] || [ $# -gt 7 ]
89 then
90         usage
91 fi
92
93 if [ "$7" ]
94 then
95         nas=$7
96 else
97         nas=`hostname`
98 fi
99
100 (
101         echo "User-Name = \"$1\""
102         echo "$PASSWORD = \"$2\""
103         echo "NAS-IP-Address = $nas"
104         echo "NAS-Port = $4"
105         if [ "$radclient" = "$radeapclient" ]
106         then
107             echo "EAP-Code = Response"
108             echo "EAP-Type-Identity = \"$1\""
109             echo "Message-Authenticator = 0x00"
110         fi
111         if [ "$6" ]
112         then
113                 echo "Framed-Protocol = PPP"
114         fi
115 ) | $radclient $OPTIONS -x $3 auth "$5"
116
117 exit $?