#!/usr/bin/perl

use warnings;
use strict;
use Net::LDAP;
use Getopt::Std;

my $ldap;
my $ldapserver = "localhost";
my $basedn = "ou=people,dc=acme,dc=com";
my $result;
my $binddn = "cn=Manager,dc=acme,dc=com";
my $bindpass = "test";
my $mtacluster = "acme.com";

my $lhs = $ARGV[0];
my $rhs = $ARGV[1];

if (!$lhs or !$rhs) {
    die ("Alias incorrectly formatted");
}

$ldap = Net::LDAP->new($ldapserver) or die "$@";
$ldap->bind ($binddn, password => $bindpass);

$result = $ldap->add("sendmailMTAKey=$lhs,$basedn",
     attr => [
         'objectClass' => ['sendmailMTA'],
         'objectClass' => ['sendmailMTAAlias'],
         'objectClass' => ['sendmailMTAAliasObject'],
         'sendmailMTAAliasGrouping' => ['aliases'],
         'sendmailMTACluster' => ['$mtacluster'],
         'sendmailMTAKey' => [$lhs],
         'sendmailMTAAliasValue' => [$rhs]
      ]
    );
$result->code && die "failed to add entry: ", $result->error ;



