File: login.example

package info (click to toggle)
freeradius-client 1.1.6-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,048 kB
  • ctags: 504
  • sloc: sh: 8,504; ansic: 4,704; perl: 425; makefile: 86
file content (279 lines) | stat: -rw-r--r-- 7,602 bytes parent folder | download | duplicates (2)
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/perl
#
# Sample login-Skript for use with radlogin
#
# Copyright  (c)  1998  S.u.S.E. GmbH  Fuerth, Germany.
#
# please send bugfixes or comments to feedback@suse.de.
#
# derived partly from login.radius/migs/login.radius
# currently does not do anything useful - for testing purposes only
# It only sets up Accounting for a simple Rlogin-User
#
# You can install this is /usr/sbin/login.radius for testing with
# radlogin

use strict;

# Programs and files.
my $prog_radacct  = "/usr/bin/radacct";
my $prog_rlogin   = "/usr/bin/rlogin";
my $prog_telnet   = "/usr/bin/telnet";
my $prog_tcpclear = "/usr/bin/telnet -e ''";
my $prog_tty      = "/usr/bin/tty";
my $prog_who      = "/usr/bin/who";

my $debug = 1;

my $path_radiusclient_map = "/etc/radclient/port-id-map";

my $login_host = "0.0.0.0";

#############################################################################

# Main program.

print "Starting.\n" if ($debug);

# Run 'who am i' to determine the current port.
my $port = `$prog_tty`;
chomp ($port);

# Translate port numbers to numbers for RADIUS.
# This translation is done again by radacct, but it may be useful here.
# Remove if CPU time is a problem.

my ($portid, $line);
open (H, $path_radiusclient_map);
while (($line = <H>) && (!$portid))
{
    my @info = split (/\s+/, $line);
    $portid = $info[1] if ($info[0] eq $port);
}
close (H);

if ($debug)
{
    # Print out all the RADIUS variables.
    my @el = grep (/^RADIUS/, keys (%ENV));
    my $e;
    foreach $e (@el)
    {
       print "$e = " . $ENV{$e} . "\n";
    }
}

# If the service type is Framed, then give them PPP.
# SLIP is not implemented (and will probably never be).
my $username = $ENV{"RADIUS_USER_NAME"};

# Generate a "unique" string for the session ID.
my $sessionid = "$$" . time ();

if ($ENV{"RADIUS_SERVICE_TYPE"} =~ /Login/)
{
    # Warning:  This code has not been tested as well as the PPP version,
    # as of now (19961107).

    # Determine what host to connect to.
    if (($ENV{"RADIUS_LOGIN_IP_HOST"} eq "0.0.0.0") ||
       !defined ($ENV{"RADIUS_LOGIN_IP_HOST"}))
    {
       die ("login_host not defined");
    }
    elsif ($ENV{"RADIUS_LOGIN_IP_HOST"} eq "255.255.255.255")
    {
       # The user should be able to choose.  Prompt the user.
       print "Host to connect to?  ";
       $login_host = <STDIN>;
       chomp ($login_host);
    }
    else
    {
       # Use what's specified by the RADIUS server.
       $login_host = $ENV{"RADIUS_LOGIN_IP_HOST"};
    }

    # Log into a host.  Default to telnet.  Do the accounting
    # now, since the target of the login wouldn't know how to
    # account for it.

    # Time.
    my $timestart = time ();
    my $login_service = $ENV{"RADIUS_LOGIN_SERVICE"};

    # What protocol are we running?
    my ($prog_run, $login_port);

    if ($login_service eq "Rlogin")
    {
       $prog_run = $prog_rlogin;
    }
    elsif ($login_service eq "Telnet")
    {
       $prog_run = $prog_telnet;
       $login_port = $ENV{"RADIUS_LOGIN_PORT"};
    }
    elsif ($login_service eq "TCP-Clear")
    {
       $prog_run = $prog_tcpclear;
       $login_port = $ENV{"RADIUS_LOGIN_PORT"};
    } else {
        die "unkown login_service $login_service\n";
    }

    # Start accounting.  Send the record.
    open  (H, "| $prog_radacct") || die ("Cannot run $prog_radacct");

    my $cmd =
       "Acct-Session-ID = \"$sessionid\"\n" .
       "User-Name = \"$username\"\n" .
       "Acct-Status-Type = Start\n" .
        "Acct-Authentic = RADIUS\n" .
        "Service-Type = Login-User\n" .
        "Login-Service = " . $login_service . "\n" .
        "Login-IP-Host = $login_host\n";
    print H $cmd;
    close (H);

    # Store the user information into portinfo.  We need to
    # manually fork, since we have to know the PID of the program.

    my $pid = fork ();
    if ($pid == 0)
    {
       # Child.  Run the program.
       # print "Connecting to $login_host:\n";
       my $cmd = "$prog_run $login_host $login_port";
       print "Running $cmd\n" if ($debug);
       exec ("$cmd");
    }
    else
    {
       # Parent.
       $login_host = $ENV{"RADIUS_LOGIN_IP_HOST"};
    }

    # Log into a host.  Default to telnet.  Do the accounting
    # now, since the target of the login wouldn't know how to
    # account for it.

    # Time.
    my $timestart = time ();
    my $login_service = $ENV{"RADIUS_LOGIN_SERVICE"};

    # What protocol are we running?
    my ($prog_run, $login_port);

    if ($login_service eq "Rlogin")
    {
       $prog_run = $prog_rlogin;
    }
    elsif ($login_service eq "Telnet")
    {
       $prog_run = $prog_telnet;
       $login_port = $ENV{"RADIUS_LOGIN_PORT"};
    }
    elsif ($login_service eq "TCP-Clear")
    {
       $prog_run = $prog_tcpclear;
       $login_port = $ENV{"RADIUS_LOGIN_PORT"};
    } else {
        die "unkown login_service $login_service\n";
    }

    # Start accounting.  Send the record.
    open  (H, "| $prog_radacct") || die ("Cannot run $prog_radacct");

    my $cmd =
       "Acct-Session-ID = \"$sessionid\"\n" .
       "User-Name = \"$username\"\n" .
       "Acct-Status-Type = Start\n" .
        "Acct-Authentic = RADIUS\n" .
        "Service-Type = Login-User\n" .
        "Login-Service = " . $login_service . "\n" .
        "Login-IP-Host = $login_host\n";
    print H $cmd;
    close (H);

    # Store the user information into portinfo.  We need to
    # manually fork, since we have to know the PID of the program.

    my $pid = fork ();
    if ($pid == 0)
    {
       # Child.  Run the program.
       # print "Connecting to $login_host:\n";
       my $cmd = "$prog_run $login_host $login_port";
       print "Running $cmd\n" if ($debug);
       exec ("$cmd");
    }
    else
    {
       # Parent.
       # Create the portinfo record, which needs the pid of the program
       # to kill.
       # The IP address is all zero, as it is not applicable here.
       # Store the time now, and the Session-Timeout.

       # Wait for the session to finish.
       waitpid ($pid, 0);
    }
    # Stop.  Send the record.
    open  (H, "| $prog_radacct") || die ("Cannot run $prog_radacct");

    my $timespent = time () - $timestart;

    my $cmd =
       "Acct-Session-ID = \"$sessionid\"\n" .
       "User-Name = \"$username\"\n" .
       "Acct-Status-Type = Stop\n" .
        "Acct-Authentic = RADIUS\n" .
        "Service-Type = Login-User\n" .
        "Login-Service = " . $login_service . "\n" .
        "Login-IP-Host = $login_host\n" .
        "Acct-Session-Time = $timespent\n";

    print H $cmd;
    close (H);
} else {
    my $r = $ENV{"RADIUS_SERVICE_TYP"};
    print "Unhandled Service-Type $r\n";
}

### END ####




       # Create the portinfo record, which needs the pid of the program
       # to kill.
       # The IP address is all zero, as it is not applicable here.
       # Store the time now, and the Session-Timeout.

       # Wait for the session to finish.
       waitpid ($pid, 0);
    }
    # Stop.  Send the record.
    open  (H, "| $prog_radacct") || die ("Cannot run $prog_radacct");

    my $timespent = time () - $timestart;

    my $cmd =
       "Acct-Session-ID = \"$sessionid\"\n" .
       "User-Name = \"$username\"\n" .
       "Acct-Status-Type = Stop\n" .
        "Acct-Authentic = RADIUS\n" .
        "Service-Type = Login-User\n" .
        "Login-Service = " . $login_service . "\n" .
        "Login-IP-Host = $login_host\n" .
        "Acct-Session-Time = $timespent\n";

    print H $cmd;
    close (H);
} else {
    my $r = $ENV{"RADIUS_SERVICE_TYP"};
    print "Unhandled Service-Type $r\n";
}

### END ####