#!/usr/bin/perl -w

# sasl check module

# Version: $Revision: 1.4 $
# Author: Eric Garrido
# Date: $Date: 2007/02/12 02:57:37 $
#
# Copyright (c) 2006 - 2007
# The Trustees of Columbia University in the City of New York
# Columbia University Information Technology
# 
# License restrictions apply, see doc/license.html for details. 

use strict;
use FindBin;
use lib "$FindBin::Bin/../common";
use Survivor::Check;

my %argformat = ('username' => 'string',
		 'password' => 'password',
		 );

sub SaslValidate {
    return(MODEXEC_OK, 0, "Test OK");  
}

sub SaslCheck {

    my $self = shift;
    my $host = shift 
	|| return(MODEXEC_MISCONFIG, 0, "no hostname provided");

    if($host eq ""){
	return(MODEXEC_MISCONFIG, 0, "no hostname provided");
    }
    my $username = $self->Arg('username');
    my $password = $self->Arg('password');
    
    my $result;

    $result = `testsaslauthd -u '$username' -p '$password' 2>&1`;
    chomp($result);

    my($j, $status, $comment) = split(/ /, $result, 3);
    
    if($status eq "OK"){
	return(MODEXEC_OK, 1, $comment);
    }
    else {
	return(MODEXEC_PROBLEM, 0, $comment);
    }
}

# begin main block
{

my $sc = new Survivor::Check();

$sc->GetOpt(\%argformat, \&SaslValidate);

my $result = $sc->Exec(\&SaslCheck);

exit($result);

}
