ispman/scripts ldifupdate,1.16,1.17
Joerg Delker <[email protected]>
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18957/scripts
Modified Files:
ldifupdate
Log Message:
added checks for missing ispmanReseller attributes
added checks for domain related posixGroup
Index: ldifupdate
===================================================================
RCS file: /cvsroot/ispman/ispman/scripts/ldifupdate,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ldifupdate 20 Jun 2004 13:05:33 -0000 1.16
+++ ldifupdate 26 Jun 2004 22:53:29 -0000 1.17
@@ -31,8 +31,8 @@
my $dummyPassword = "123456";
# private variables
-my ( $ldif_in, $ldif_out, $entry, $basedn );
-my ( %opts, $dn, $msg, $chng, $mode );
+my ( $ldif_in, $ldif_out, $basedn );
+my ( %opts, $mode );
sub usage {
print qq[
@@ -96,17 +96,57 @@
# input file
$ldif_in = Net::LDAP::LDIF->new( $opts{'i'} );
+# basedn
+$basedn = $opts{'b'};
+
+#### Phase 1: Preparation ####
+print "Phase 1: Preparing...\n\n";
+
+my %clients = ();
+my %groups = ();
+
+# read and parse ldap data
+while ( not $ldif_in->eof() ) {
+ my $entry = $ldif_in->read_entry();
+
+ # skip entry if we find an error
+ if ( $ldif_in->error() ) {
+ print STDERR "Error msg: ", $ldif_in->error(), "\n";
+ print STDERR "Error lines:\n", $ldif_in->error_lines(), "\n";
+ }
+
+ my $dn = $entry->dn();
+
+ next unless !defined($basedn) or $dn =~ m/$basedn$/;
+
+ my @oc = $entry->get_value("objectclass");
+ my %oc;
+ for (@oc) { $oc{$_} = 1 }
+
+ if ( $oc{"ispmanClient"} ) {
+ $clients{ $entry->get_value("ispmanClientId") } = $entry->{'attrs'};
+ }
+
+ if ( $oc{"posixGroup"} ) {
+ if ( $dn =~ /^cn=(.*?),/ ) {
+ $groups{$1} = 1;
+ }
+ }
+}
+$ldif_in->done();
+
+print "Phase 2: Checking...\n\n";
+
+# input file
+$ldif_in = Net::LDAP::LDIF->new( $opts{'i'} );
+
# output file
$ldif_out =
Net::LDAP::LDIF->new( $opts{'o'}, "w", 'change' => ( $mode eq "modify" ) );
-# only work on entries of this basedn
-$basedn = $opts{'b'};
-
# read and parse ldap data
while ( not $ldif_in->eof() ) {
- undef($entry);
- $entry = $ldif_in->read_entry();
+ my $entry = $ldif_in->read_entry();
# skip entry if we find an error
if ( $ldif_in->error() ) {
@@ -115,12 +155,12 @@
}
$entry->changetype($mode);
- $dn = $entry->dn();
+ my $dn = $entry->dn();
next unless !defined($basedn) or $dn =~ m/$basedn$/;
- $msg = "";
- $chng = "";
+ my $msg = "";
+ my $chng = "";
my @oc = $entry->get_value("objectclass");
my %oc;
@@ -145,6 +185,7 @@
}
elsif ( $oc{"ispmanDomain"} ) {
+ my $ispmanDomain = $entry->get_value("ispmanDomain");
# update ispmanDomain objectclasses
if ( $entry->get_value("ispmanDomainType") eq "replica" ) {
@@ -191,6 +232,51 @@
$msg .= "adding FTPStatus: active\n";
$entry->add( "FTPStatus", "active" );
}
+
+ # check related group entry
+ if ( !$groups{$ispmanDomain} ) {
+
+ # add new group entry
+ my $group = Net::LDAP::Entry->new;
+
+ $group->dn( "cn=" . $ispmanDomain . "," . $dn );
+ $group->add(
+ objectclass => 'posixGroup',
+ cn => $ispmanDomain,
+ gidnumber => $entry->get_value("gidnumber")
+ );
+ $msg .=
+ "creating new posixGroup entry for domain "
+ . $ispmanDomain . "\n";
+ $ldif_out->write_entry($group);
+ }
+
+ # check ResellerId
+ my $clientId = $entry->get_value("ispmanClientId");
+ my $resellerId = $entry->get_value("ispmanResellerId");
+ if ( $clientId && !$resellerId ) {
+ $resellerId = $clients{$clientId}{"ispmanresellerid"}[0];
+ if ($resellerId) {
+ $msg .= "adding ispmanResellerId: $resellerId\n";
+ $entry->add( "ispmanResellerId", $resellerId );
+ }
+ else {
+ $msg .=
+ "ERROR: unable to determine ispmanResellerId"
+ . " for domain $ispmanDomain\n";
+ }
+ my $resellerName = $clients{$clientId}{"ispmanresellername"}[0];
+ if ($resellerName) {
+ $msg .= "adding ispmanResellerName: $resellerName\n";
+ $entry->add( "ispmanResellerName", $resellerName );
+ }
+ else {
+ $msg .=
+ "ERROR: unable to determine ispmanResellerName"
+ . " for domain $ispmanDomain\n";
+ }
+ }
+
}
}
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com