summaryrefslogtreecommitdiffstats
path: root/scripts/cobbler_auth_help
blob: c43cd5b2a2ddb399ff2dc08f8d71577d1c571411 (plain)
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
#!/usr/bin/perl

# Kerberos helper for logins
#
# Copyright 2007, Red Hat, Inc
# Michael DeHaan <mdehaan@redhat.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Usage:
# cobbler_auth_helper kerberos username pass 
# (may do other auth types later)
# Returns:
# 0 on ok, non-0 on failure
# API info:
# http://search.cpan.org/~chansen/Authen-Simple-Kerberos-0.1/

use warnings;
use strict;

use Authen::Simple::Kerberos;
use Getopt::Long;

my $method;
my $username;
my $realm;
my $password;
my $verbose=1;

my $result = GetOptions(
    "method=s"   => \$method,
    "username=s" => \$username,
    "realm=s"    => \$realm,
    "password=s" => \$password,
);

my $kerberos = Authen::Simple::Kerberos->new(
    realm => $realm
);

print "authenticating: $username against (realm=$realm) (pass=$password)\n" if $verbose;

if ( $kerberos->authenticate( $username, $password ) ) {
    print "ok\n" if $verbose;
    exit(42);
}

print "denied\n" if $verbose;
exit(1);