On Wed, 2003-09-03 at 13:41, Ricardo Cerqueira wrote:
> Any chance of re-adding mailQuota? :-)
> I currently have over 2M LDAP entries, most of them are mail users, all
> of which have (different) quotas, and changing the quota attributes in
> all of them is _not_ something I really want to do... I could re-add it
> myself, but I am already using modified versions of qmail-ldap
> (smtp-auth, smtp-rcptcheck, and a few other little tweaks) and it's
> already a pain in the arse to upgrade...

I've converted all of our quotas with a small Perl script. It's not bad
at all. I've attached it just in case anyone cares.
#!/usr/bin/perl -w

use strict;
use Net::LDAP;

$| = 1;
 
my($ldap) = Net::LDAP->new( 'localhost' ) or die "$@";

my($result) = $ldap->bind( 'cn=manager, dc=DOMAIN, dc=DOM',
			    password => 'PASSWORD' );

$result->code && die $result->error;

print "Searching LDAP DB for mailQuota...";

$result = $ldap->search (   base   => "ou=OU,dc=DOMAIN,dc=DOM",
			    filter => "(mailQuota=*)",
			    attrs  => ['mailQuota','cn'] );

print "done.\n";

my $num_results = $result->count;


print "Updating LDAP database ($num_results records)...\n";

my($entry,$oldquota,$mailQuotaSize,$mailQuotaCount);
my $count = 0;

foreach $entry ($result->all_entries) { 

  print "\r";
  printf "%.2f%%", ($count / $num_results) * 100;

  $count++;

  $oldquota = $entry->get_value('mailQuota');

  chomp($oldquota);
  ($mailQuotaSize, $mailQuotaCount) = split(/,/, $oldquota);
  chop($mailQuotaSize, $mailQuotaCount);

  $entry->delete('mailQuota');
  $entry->add('mailQuotaSize' => $mailQuotaSize);
  $entry->add('mailQuotaCount' => $mailQuotaCount);
  $entry->update($ldap);
}

print "\nDone.\n";

print "Cleaning up...";

$result = $ldap->unbind;

print "done.\n";

Reply via email to