| 1 |
#!/usr/local/bin/perl |
| 2 |
|
| 3 |
# sample_server |
| 4 |
# receives authentication info from a client using recvauth |
| 5 |
|
| 6 |
use blib; # remove if not in module build directory |
| 7 |
use IO::Socket; |
| 8 |
use Sys::Hostname; |
| 9 |
use Authen::Krb5 (KRB5_NT_SRV_HST); |
| 10 |
|
| 11 |
# replace with your own stuff |
| 12 |
$SERVICE = "sample"; |
| 13 |
$KEYTAB_FILE = "/etc/krb5.keytab"; |
| 14 |
|
| 15 |
chomp($SERVER = hostname()); |
| 16 |
|
| 17 |
Authen::Krb5::init_context(); |
| 18 |
|
| 19 |
$ac = new Authen::Krb5::AuthContext; |
| 20 |
|
| 21 |
$s = new IO::Socket::INET( |
| 22 |
LocalAddr => $SERVER, |
| 23 |
LocalPort => 12345, |
| 24 |
Proto => 'tcp', |
| 25 |
Reuse => 1, |
| 26 |
Listen => 5 |
| 27 |
); |
| 28 |
defined $s or die $!; |
| 29 |
|
| 30 |
$ns = $s->accept(); |
| 31 |
|
| 32 |
$sprinc = Authen::Krb5::sname_to_principal($SERVER,$SERVICE,KRB5_NT_SRV_HST); |
| 33 |
$kt = Authen::Krb5::kt_resolve("FILE:$KEYTAB_FILE"); |
| 34 |
$t = Authen::Krb5::recvauth($ac,$ns,"V1",$sprinc,$kt); |
| 35 |
if ($t) { |
| 36 |
print "Received authentication info.\n"; |
| 37 |
$client = $t->enc_part2->client; |
| 38 |
print "Hello, ",$client->data,".\n"; |
| 39 |
} |
| 40 |
else { |
| 41 |
print "recvauth error: ",Authen::Krb5::error(),"\n"; |
| 42 |
} |
| 43 |
|
| 44 |
close($ns); |
| 45 |
close($s); |
| 46 |
|
| 47 |
Authen::Krb5::free_context(); |