1
0
Эх сурвалжийг харах

Resolves: bug 281631
Bug Description: Pass in schema and config LDIF files to setup
Reviewed by: nhosoi (Thanks!)
Fix Description: 1) Allow multi-valued parameters in .inf files and command line. These values will be represented internally as an array ref. No existing parameters allow being multi-valued (e.g. you can't use Suffix=o=foo and Suffix=o=bar)
2) Add two new .inf parameters - SchemaFile and ConfigFile. The files listed in SchemaFile will be copied into the schema subdirectory of the new instance, so they must already be named appropriately (e.g. 60foo.ldif). The files listed in ConfigFile must be LDIF files with one or more whole entries to be added to the initial dse.ldif. These could be additional suffixes/databases to create, plugin configuration, replication configuration, or anything else.
Right now, if you have an LDIF file that relies on custom schema, you cannot use the InstallLdifFile directive during setup. SchemaFile allows you to do that.
Platforms tested: RHEL5
Flag Day: no
Doc impact: Will need to document the two additional parameters.

Rich Megginson 18 жил өмнө
parent
commit
ba217f8884

+ 18 - 0
ldap/admin/src/scripts/DSCreate.pm.in

@@ -306,6 +306,15 @@ sub createConfigFile {
         push @ldiffiles, "$inf->{General}->{prefix}@templatedir@/template-dnaplugin.ldif";
     }
 
+    # additional configuration LDIF files
+    if (exists($inf->{slapd}->{ConfigFile})) {
+        if (ref($inf->{slapd}->{ConfigFile})) {
+            push @ldiffiles, @{$inf->{slapd}->{ConfigFile}};
+        } else {
+            push @ldiffiles, $inf->{slapd}->{ConfigFile};
+        }
+    }
+
     getMappedEntries($mapper, \@ldiffiles, \@errs, \&check_and_add_entry,
                      [$conn]);
 
@@ -407,6 +416,15 @@ sub installSchema {
     } else {
         push @schemafiles, "$inf->{General}->{prefix}@schemadir@/00core.ldif";
     }
+
+    # additional schema files
+    if (exists($inf->{slapd}->{SchemaFile})) {
+        if (ref($inf->{slapd}->{SchemaFile})) {
+            push @schemafiles, @{$inf->{slapd}->{SchemaFile}};
+        } else {
+            push @schemafiles, $inf->{slapd}->{SchemaFile};
+        }
+    }
     for (@schemafiles) {
         my $src = $_;
         my $basename = basename($src);

+ 23 - 2
ldap/admin/src/scripts/Inf.pm

@@ -77,6 +77,7 @@ sub read {
 
     my $incontinuation = 0;
     my $curkey;
+    my $curval;
     my $inffh;
     if ($filename eq "-") {
         $inffh = \*STDIN;
@@ -100,12 +101,32 @@ sub read {
             $iscontinuation = 1;
         }
         if ($incontinuation) {
-            $self->{$curSection}->{$curkey} .= "\n" . $_; # add line in entirety to current value
+            if ($curval) {
+                $self->{$curSection}->{$curkey}->[$curval] .= "\n" . $_; # add line in entirety to current value
+            } else {
+                $self->{$curSection}->{$curkey} .= "\n" . $_; # add line in entirety to current value
+            }
         } elsif (/^\[(.*?)\]/) { # e.g. [General]
             $curSection = $1;
+            $iscontinuation = 0; # disallow section continuations
         } elsif (/^\s*(.*?)\s*=\s*(.*?)\s*$/) { # key = value
             $curkey = $1;
-            $self->{$curSection}->{$curkey} = $2;
+            # a single value is just a single scalar
+            # multiple values are represented by an array ref
+            if (exists($self->{$curSection}->{$curkey})) {
+                if (!ref($self->{$curSection}->{$curkey})) {
+                    # convert single scalar to array ref
+                    my $ary = [$self->{$curSection}->{$curkey}];
+                    $self->{$curSection}->{$curkey} = $ary;
+                }
+                # just push the new value
+                push @{$self->{$curSection}->{$curkey}}, $2;
+                $curval = @{$self->{$curSection}->{$curkey}} - 1; # curval is index of last item
+            } else {
+                # single value
+                $self->{$curSection}->{$curkey} = $2;
+                $curval = 0; # only 1 value
+            }
         }
         if ($iscontinuation) { # if line ends with a backslash, continue the data on the next line
             $incontinuation = 1;

+ 17 - 1
ldap/admin/src/scripts/Setup.pm.in

@@ -161,7 +161,23 @@ sub init {
     # allows the reuse of .inf files with some parameters overridden
     for (@ARGV) {
         if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
-            $self->{inf}->{$1}->{$2} = $3;
+            my $sec = $1;
+            my $parm = $2;
+            my $val = $3;
+            # a single value is just a single scalar
+            # multiple values are represented by an array ref
+            if (exists($self->{inf}->{$sec}->{$parm})) {
+                if (!ref($self->{inf}->{$sec}->{$parm})) {
+                    # convert single scalar to array ref
+                    my $ary = [$self->{inf}->{$sec}->{$parm}];
+                    $self->{inf}->{$sec}->{$parm} = $ary;
+                }
+                # just push the new value
+                push @{$self->{inf}->{$sec}->{$parm}}, $val;
+            } else {
+                # single value
+                $self->{inf}->{$sec}->{$parm} = $val;
+            }
         } else { # error
             print STDERR "Error: unknown command line option $_\n";
             usage();