summaryrefslogtreecommitdiffstats
path: root/pki/base
diff options
context:
space:
mode:
authorvakwetu <vakwetu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2011-04-15 18:03:28 +0000
committervakwetu <vakwetu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2011-04-15 18:03:28 +0000
commit34f9619ebca6d38f48792aaf7a44f331f8cc4631 (patch)
treed86fd48471a82259bf31e76baf6235af166829dd /pki/base
parentcb1463e369ce7f659d7e090c161e3c4a2f60a3f9 (diff)
downloadpki-34f9619ebca6d38f48792aaf7a44f331f8cc4631.tar.gz
pki-34f9619ebca6d38f48792aaf7a44f331f8cc4631.tar.xz
pki-34f9619ebca6d38f48792aaf7a44f331f8cc4631.zip
Bugzilla Bug 697035: TPS dataabase schema not populated correctly
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@1963 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki/base')
-rwxr-xr-xpki/base/tps/lib/perl/PKI/TPS/Common.pm45
-rwxr-xr-xpki/base/tps/lib/perl/PKI/TPS/DatabasePanel.pm2
2 files changed, 42 insertions, 5 deletions
diff --git a/pki/base/tps/lib/perl/PKI/TPS/Common.pm b/pki/base/tps/lib/perl/PKI/TPS/Common.pm
index 3061529a2..c66942599 100755
--- a/pki/base/tps/lib/perl/PKI/TPS/Common.pm
+++ b/pki/base/tps/lib/perl/PKI/TPS/Common.pm
@@ -48,9 +48,43 @@ sub r {
return sub { $a; }
}
+# special function to add schema elements. This assumes the entry
+# is ldif update format with changetype "modify" and operation "add"
+#
+sub add_schema_update
+{
+ my ($conn, $aentry, $err_ref) = @_;
+
+ my $sentry = $conn->search($aentry->{dn}, "base", "(objectclass=*)", 0, ("*", "aci"));
+ if (!$sentry) {
+ $$err_ref .= "Error: trying to update entry that does not exist: " . $aentry->{dn} . "\n";
+ return 0;
+ }
+
+ my @addtypes = ("attributeTypes", "objectClasses");
+
+ foreach my $attr (@addtypes) {
+ my @vals = $aentry->getValues($attr);
+ push @vals, $vals[0]; # HACK! for some reason, first value always fails with server unwilling to perform
+
+ foreach my $val (@vals) {
+ $sentry->addValue( $attr, $val );
+ $conn->update($sentry);
+ my $rc = $conn->getErrorCode();
+ if ( $rc != 0 ) {
+ my $string = $conn->getErrorString();
+ $$err_ref .= "Error: updating entry " . $sentry->{dn} . " with value $val : $string\n";
+ } else {
+ $$err_ref .= "Updated entry ". $sentry->{dn} . " with value $val : rc = $rc\n";
+ }
+ }
+ }
+ return 1;
+}
+
sub import_ldif
{
- my ($conn, $ldif_file, $msg_ref) = @_;
+ my ($conn, $ldif_file, $msg_ref, $schema) = @_;
if (!open( MYLDIF, "$ldif_file" )) {
$$msg_ref = "Could not open $ldif_file: $!\n";
@@ -59,15 +93,18 @@ sub import_ldif
my $in = new Mozilla::LDAP::LDIF(*MYLDIF);
while (my $entry = readOneEntry $in) {
- if (!$conn->add($entry)) {
- $$msg_ref .= "Error: could not add entry " . $entry->getDN() . ":" . $conn->getErrorString() . "\n";
+ if (defined($schema) && ($schema == 1)) {
+ add_schema_update($conn, $entry, $msg_ref);
+ } else {
+ if (!$conn->add($entry)) {
+ $$msg_ref .= "Error: could not add entry " . $entry->getDN() . ":" . $conn->getErrorString() . "\n";
+ }
}
}
close( MYLDIF );
return 1;
}
-
# this subroutine checks if an ldaps connection is successful first
# and then if an ldap connection is successful.
# This prevents a hanging condition when someone tries to connect to a ldaps
diff --git a/pki/base/tps/lib/perl/PKI/TPS/DatabasePanel.pm b/pki/base/tps/lib/perl/PKI/TPS/DatabasePanel.pm
index 94ad604ad..d8fee06e8 100755
--- a/pki/base/tps/lib/perl/PKI/TPS/DatabasePanel.pm
+++ b/pki/base/tps/lib/perl/PKI/TPS/DatabasePanel.pm
@@ -159,7 +159,7 @@ sub update
system("rm $tmp");
# add schema
- if (! &PKI::TPS::Common::import_ldif($conn, "/usr/share/$flavor/tps/scripts/schemaMods.ldif", \$msg)) {
+ if (! &PKI::TPS::Common::import_ldif($conn, "/usr/share/$flavor/tps/scripts/schemaMods.ldif", \$msg, 1)) {
&PKI::TPS::Wizard::debug_log("DatabasePanel: $msg");
$::symbol{errorString} = "Failed to add schema";
$conn->close();