/usr/bin/ldif-duplicate-attrs is in hxtools 20170430-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #!/usr/bin/perl
#
# Check for multi-value attributes in LDIF file
# written by Jan Engelhardt, 2015
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the WTF Public License version 2 or
# (at your option) any later version.
#
use strict;
use warnings;
use Getopt::Long;
our @wl = qw(
ACL objectClass member equivalentToMe DirXML-Associations
groupMembership securityEquals DirXML-PasswordSyncStatus
zarafaSendAsPrivilege zarafaAliases
departmentNumber
);
our $do_color = -t 1;
&main();
sub main
{
&Getopt::Long::Configure(qw(bundling));
&GetOptions(
"C" => \$do_color,
);
my $attrcount = &parse_ldif();
&print_stats($attrcount);
}
sub parse_ldif
{
my $dn;
my $attrcount = {};
while (defined(my $line = <STDIN>)) {
chomp($line);
if (substr($line, 0, 1) eq "#") {
next;
}
if ($line =~ /^dn:\s*/) {
$dn = $';
$attrcount->{$dn} = {};
}
my($key, $value) = &parse_line($line);
if (!defined($key) || &whitelisted($key)) {
# Blank lines and other unparsable lines get filtered
# here.
next;
}
++$attrcount->{$dn}->{$key};
}
close(STDIN);
return $attrcount;
}
sub parse_line
{
return (shift(@_) =~ /^([^:]+):+(?:\s*)?(.*)/);
}
sub whitelisted
{
my $needle = shift @_;
return scalar grep { $_ eq $needle } @wl;
}
sub print_stats
{
my $attrcount = shift @_;
my $dncount = {};
my $crapdn;
my $globattr = {};
foreach my $dn (keys %$attrcount) {
my $count = 0;
my $dh = $attrcount->{$dn};
foreach my $key (keys %$dh) {
if ($dh->{$key} < 2) {
next;
}
$count += $dh->{$key};
}
$dncount->{$dn} = $count;
}
foreach my $dn (sort { $dncount->{$b} <=> $dncount->{$a} }
keys %$dncount)
{
my $dh = $attrcount->{$dn};
if ($dncount->{$dn} == 0) {
next;
}
if ($do_color) {
print "\e[1;31m";
}
print $dncount->{$dn};
if ($do_color) {
print "\e[0;31m";
}
print "\t$dn\n";
print "\t";
foreach my $key (sort {
$dh->{$b} <=> $dh->{$a} || $a cmp $b }
keys %$dh)
{
if ($dh->{$key} < 2) {
next;
}
if ($do_color) {
print "\e[32m", substr($key, 0, 1), "\e[0m",
substr($key, 1);
} else {
print $key;
}
print "(", $attrcount->{$dn}->{$key}, ") ";
$globattr->{$dn} += $dh->{$key};
}
print "\n\n";
++$crapdn;
}
print $crapdn, " DNs\n";
}
|