Commit c6b0a3fa authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Pulling fusiondirectory-insert-schema from 1.0.19 to avoid diff

Showing with 27 additions and 23 deletions
+27 -23
...@@ -153,18 +153,19 @@ $continue++; # activating continue feature only for insertions ...@@ -153,18 +153,19 @@ $continue++; # activating continue feature only for insertions
foreach my $schema (@schemas) { foreach my $schema (@schemas) {
my $schema_name = ""; my $schema_name = "";
my $ldif_file;
if ($modify < 2) { if ($modify < 2) {
# Searching schema name in ldif file first line. # Searching schema name in ldif file first line.
open my $file, q{<}, $path.$schema.".ldif" or die "Count not open ldif file : $!\n"; open $ldif_file, q{<}, $path.$schema.".ldif" or die "Count not open ldif file : $!\n";
my $dn = ""; my $dn = "";
while ($dn eq "") { while ($dn eq "") {
chomp($dn = <$file>); chomp($dn = <$ldif_file>);
} }
if ($dn =~ /^dn: cn=([^,]+),/) { if ($dn =~ /^dn: cn=([^,]+),/) {
$schema_name = $1; $schema_name = $1;
} }
close($file); close($ldif_file);
} }
# Fallback on file name # Fallback on file name
...@@ -181,6 +182,9 @@ remove_ldifs(); ...@@ -181,6 +182,9 @@ remove_ldifs();
sub insert_schema sub insert_schema
{ {
my($schema, $schema_name) = @_; my($schema, $schema_name) = @_;
my $schema_file;
my $update_file;
my $empty_file;
$full_cmd = $search_cmd.$schema_name." cn"; $full_cmd = $search_cmd.$schema_name." cn";
print ("\n"); print ("\n");
...@@ -206,18 +210,18 @@ sub insert_schema ...@@ -206,18 +210,18 @@ sub insert_schema
my $dn_part = $1; my $dn_part = $1;
# if the schema already exists in the LDAP server, modify it # if the schema already exists in the LDAP server, modify it
if ($modify == 1) { if ($modify == 1) {
open(my $schemafile, q{<}, $path.$schema.".ldif") or die_with_error('Could not open '."<".$path.$schema.".ldif: $!"); open($schema_file, q{<}, $path.$schema.".ldif") or die_with_error('Could not open '."<".$path.$schema.".ldif: $!");
open(my $updatefile, q{>}, $path.$schema."_update.ldif") or die_with_error('Could not open '.">".$path.$schema."_update.ldif: $!"); open($update_file, q{>}, $path.$schema."_update.ldif") or die_with_error('Could not open '.">".$path.$schema."_update.ldif: $!");
push @gen_files, $path.$schema."_update"; push @gen_files, $path.$schema."_update";
my $attrs = 0; my $attrs = 0;
my $classes = 0; my $classes = 0;
while (<$schemafile>) { while (<$schema_file>) {
next if m/^#/; # remove comments next if m/^#/; # remove comments
chomp; chomp;
next if m/^$/; # remove empty lines next if m/^$/; # remove empty lines
if (m/^dn: cn=([^,]+),cn=schema,cn=config$/) { if (m/^dn: cn=([^,]+),cn=schema,cn=config$/) {
$updatefile->print("dn: $dn_part,cn=schema,cn=config\n"); print $update_file "dn: $dn_part,cn=schema,cn=config\n";
$updatefile->print("changetype: modify\n"); print $update_file "changetype: modify\n";
next; next;
} }
if (!m/^olcAttributeTypes:/ && !m/^olcObjectClasses:/ && !m/^ /) { if (!m/^olcAttributeTypes:/ && !m/^olcObjectClasses:/ && !m/^ /) {
...@@ -231,29 +235,29 @@ sub insert_schema ...@@ -231,29 +235,29 @@ sub insert_schema
if (!$attrs && m/^olcAttributeTypes:/) { if (!$attrs && m/^olcAttributeTypes:/) {
$attrs = 1; $attrs = 1;
$updatefile->print("replace: olcAttributeTypes\n"); print $update_file "replace: olcAttributeTypes\n";
} }
if (!$classes && m/^olcObjectClasses:/) { if (!$classes && m/^olcObjectClasses:/) {
$classes = 1; $classes = 1;
$updatefile->print("-\n"); print $update_file "-\n";
$updatefile->print("replace: olcObjectClasses\n"); print $update_file "replace: olcObjectClasses\n";
} }
$updatefile->print($_); print $update_file $_;
$updatefile->print("\n"); print $update_file "\n";
} }
$schemafile->close(); close $schema_file;
$updatefile->close(); close $update_file;
} else { # Emptying schema } else { # Emptying schema
open(my $updatefile, q{>}, $path.$schema."_update.ldif") or die_with_error('Could not open '.">".$path.$schema."_update.ldif: $!"); open($empty_file, q{>}, $path.$schema."_update.ldif") or die_with_error('Could not open '.">".$path.$schema."_update.ldif: $!");
push @gen_files, $path.$schema."_update"; push @gen_files, $path.$schema."_update";
$updatefile->print("dn: $dn_part,cn=schema,cn=config\n"); print $empty_file "dn: $dn_part,cn=schema,cn=config\n";
$updatefile->print("changetype: modify\n"); print $empty_file "changetype: modify\n";
$updatefile->print("delete: olcAttributeTypes\n"); print $empty_file "delete: olcAttributeTypes\n";
$updatefile->print("-\n"); print $empty_file "-\n";
$updatefile->print("delete: olcObjectClasses\n"); print $empty_file "delete: olcObjectClasses\n";
$updatefile->print("-\n"); print $empty_file "-\n";
$updatefile->close(); close $empty_file;
} }
$full_cmd = $mod_cmd.$path.$schema."_update.ldif"; $full_cmd = $mod_cmd.$path.$schema."_update.ldif";
print "executing '$full_cmd'\n"; print "executing '$full_cmd'\n";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment