#!/usr/bin/perl -w
#------------------------------------------------------------
#This action modifies the Active Directory with 
#attributes specific to Koozali SME Server
#
#Copyright 2016 Koozali Foundation, Inc.
#06/30/2016: G.Zartman <gzartman@koozali.org>
#
#The code contained herein can be distributed under the same
#license as Perl
#------------------------------------------------------------
use strict;
use warnings;

##Pull arguments
my $event = $ARGV [0] || 'none';

##Set a few path vars to abbreviate the systems commands
my $ldifs = '/etc/samba/schema/';
my $ad = '/var/lib/samba/private/sam.ldb';

warn "Extending Active Directory:\n";

##Add Attributes
warn ("Attributes: Maxblocks, MaxBlocksSoftLim, lockable, 
       removeable, and smeCustom\n"
     );
my $addAttributes = '/usr/bin/ldbadd -H ' .
                    "$ad " . 
                    $ldifs . 'extendedADAttributes.ldif ' .
                    '--option="dsdb:schema update allowed"=true';
system ($addAttributes);


##Create Koozali Object Class for new attributes
my $addKoozaliClass = '/usr/bin/ldbadd -H ' .
                      "$ad " .
                      $ldifs . 'smeExtendedClass.ldif ' .
                      '--option="dsdb:schema update allowed"=true';
system ($addKoozaliClass);


##Apply User class updates
warn "Attempting to register User Class.\n";
my $modifyUserClass = '/usr/bin/ldbmodify -H ' .
                      "$ad " .
                      $ldifs . 'modifyADSchema.ldif ' .
                      '--option="dsdb:schema update allowed"=true';

system ($modifyUserClass);

exit(0);
