1#!/usr/local/bin/perl
2
3# sample_server
4# receives authentication info from a client using recvauth
5
6use blib; # remove if not in module build directory
7use IO::Socket;
8use Sys::Hostname;
9use Authen::Krb5 (KRB5_NT_SRV_HST);
10
11# replace with your own stuff
12$SERVICE = "sample";
13$KEYTAB_FILE = "/etc/krb5.keytab";
14
15chomp($SERVER = hostname());
16
17Authen::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);
28defined $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);
35if ($t) {
36	print "Received authentication info.\n";
37	$client = $t->enc_part2->client;
38	print "Hello, ",$client->data,".\n";
39}
40else {
41	print "recvauth error: ",Authen::Krb5::error(),"\n";
42}
43
44close($ns);
45close($s);
46
47Authen::Krb5::free_context();
48