#!/usr/bin/perl -I../blib/lib -I../blib/arch

use Authen::SASL::Cyrus;
use MIME::Base64;

$conn=Authen::SASL::Cyrus::init_connection("ldap",
					     "loki.dcs.ed.ac.uk",
					     "sxw");

$mesg=Authen::SASL::Cyrus::start($conn,"PLAIN GSSAPI ANONYMOUS");
print "C: ",encode_base64("GSSAPI\0".$mesg,""),"\n";

while (Authen::SASL::Cyrus::error()==
	Authen::SASL::Cyrus::SASL_CONTINUE) {
  $inmsg=<STDIN>;
  $inmsg=~s/^S: //;
  $inmsg=decode_base64($inmsg);
  $mesg=Authen::SASL::Cyrus::respond($conn,$inmsg);
  print "C: ",encode_base64($mesg,""),"\n";
}

if (Authen::SASL::Cyrus::error()!=Authen::SASL::Cyrus::SASL_OK) {
  print "Failed: ",Authen::SASL::Cyrus::error(),"\n";
} else {
  print "Succeeded!\n";
}
