update-mailboxes
changeset 19 2518c7ff759b
parent 18 6597387195d4
parent 17 f9c8259498c2
child 21 9077c793799e
equal deleted inserted replaced
18:6597387195d4 19:2518c7ff759b
    16 my $PRIVATE   = "$ENV{HOME}/private/accounts";
    16 my $PRIVATE   = "$ENV{HOME}/private/accounts";
    17 my $LDAPCONF  = "/etc/ldap/ldap.conf";
    17 my $LDAPCONF  = "/etc/ldap/ldap.conf";
    18 my $SERVER    = "localhost";
    18 my $SERVER    = "localhost";
    19 my $BLACKLIST = "/etc/mail/update-mailboxes.blacklist";
    19 my $BLACKLIST = "/etc/mail/update-mailboxes.blacklist";
    20 my $OULIST    = "/etc/mail/update-mailboxes.oulist";
    20 my $OULIST    = "/etc/mail/update-mailboxes.oulist";
       
    21 my $FILTER         = "(&(objectClass=sambaSamAccount))";
       
    22 my $MBOX_ATTR      = "uid";
       
    23 my $DEFAULT_DOMAIN = "dtele.de";
    21 
    24 
    22 my $opt_delete   = 0;
    25 my $opt_delete   = 0;
    23 my $opt_protocol = undef;
    26 my $opt_protocol = undef;
    24 my $opt_help     = 0;
    27 my $opt_help     = 0;
    25 my $opt_man      = 0;
    28 my $opt_man      = 0;
    92         $ldap->bind($LDAPADMIN, password => $LDAPPASS);
    95         $ldap->bind($LDAPADMIN, password => $LDAPPASS);
    93         foreach my $ou (@OU) {
    96         foreach my $ou (@OU) {
    94             eval {
    97             eval {
    95                 my $msg = $ldap->search(
    98                 my $msg = $ldap->search(
    96                     base   => "$ou,$LDAPBASE",
    99                     base   => "$ou,$LDAPBASE",
    97                     filter => "(&(samAccountName=*))",
   100                     filter => $FILTER,
    98                     attrs  => ["samAccountName"],
   101                     attrs  => [$MBOX_ATTR],
    99                 );
   102                 );
   100                 push @entries, $msg->entries;
   103                 push @entries, $msg->entries;
   101             };
   104             };
   102             warn "problem using $ou,$LDAPBASE: $@\n" if $@;
   105             warn "problem using $ou,$LDAPBASE: $@\n" if $@;
   103         }
   106         }
   106     die "$ME: keine LDAP-Einträge gefunden\n" if not @entries;
   109     die "$ME: keine LDAP-Einträge gefunden\n" if not @entries;
   107 
   110 
   108     my %mbox;
   111     my %mbox;
   109     foreach my $e (@entries) {
   112     foreach my $e (@entries) {
   110 
   113 
   111         my $mbox = $e->get_value("samAccountName");
   114         my $mbox =
       
   115           lc ($e->get_value($MBOX_ATTR)
       
   116           . ($DEFAULT_DOMAIN ? "\@$DEFAULT_DOMAIN" : ""));
   112 
   117 
   113         if ($BLACK{$mbox}) {
   118         if ($BLACK{$mbox}) {
   114             print "$mbox blacklisted\n";
   119             print "$mbox blacklisted\n";
   115             next;
   120             next;
   116         }
   121         }