Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 157159 Details for
Bug 237356
Move DS Admin Code into Admin Server
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
move mapfile and template processing code into DS
cvsdiffs (text/plain), 30.58 KB, created by
Rich Megginson
on 2007-06-15 21:01:01 UTC
(
hide
)
Description:
move mapfile and template processing code into DS
Filename:
MIME Type:
Creator:
Rich Megginson
Created:
2007-06-15 21:01:01 UTC
Size:
30.58 KB
patch
obsolete
>Index: ldapserver/ldap/admin/src/create_instance.c >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/create_instance.c,v >retrieving revision 1.58 >diff -u -8 -r1.58 create_instance.c >--- ldapserver/ldap/admin/src/create_instance.c 7 Jun 2007 22:40:14 -0000 1.58 >+++ ldapserver/ldap/admin/src/create_instance.c 15 Jun 2007 20:57:28 -0000 >@@ -3399,22 +3399,16 @@ > fprintf(f, "\n"); > > fprintf(f, "dn: cn=tasks,cn=config\n"); > fprintf(f, "objectclass: top\n"); > fprintf(f, "objectclass: extensibleObject\n"); > fprintf(f, "cn: tasks\n"); > fprintf(f, "\n"); > >- /* Entries for the ldbm instances and mapping tree */ >- if ( cf->netscaperoot && !cf->use_existing_config_ds) >- { >- suffix_gen_conf(f, cf->netscaperoot, "NetscapeRoot"); >- } >- > if (!cf->use_existing_user_ds) > { > suffix_gen_conf(f, cf->suffix, "userRoot"); > } > > if ( cf->samplesuffix && cf->suffix && PL_strcasecmp(cf->samplesuffix, cf->suffix)) > { > suffix_gen_conf(f, cf->samplesuffix, "sampleRoot"); >Index: ldapserver/ldap/admin/src/ds_newinst.pl.in >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/ds_newinst.pl.in,v >retrieving revision 1.7 >diff -u -8 -r1.7 ds_newinst.pl.in >--- ldapserver/ldap/admin/src/ds_newinst.pl.in 7 Jun 2007 22:40:14 -0000 1.7 >+++ ldapserver/ldap/admin/src/ds_newinst.pl.in 15 Jun 2007 20:57:28 -0000 >@@ -184,17 +184,17 @@ > close IN; > } > } > > usage("No arguments given") if (!@ARGV); > > # process command line arguments > for (@ARGV) { >- if (/^(\w+).(\w+)=(.*)$/) { # e.g. section.param=value >+ if (/^(\w+)\.(\w+)=(.*)$/) { # e.g. section.param=value > $table{$1}->{$2} = $3; > } else { # file? > readInfFile($_); > } > } > > #printhash (\%table); > >Index: ldapserver/ldap/admin/src/scripts/Dialog.pm >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Dialog.pm,v >retrieving revision 1.2 >diff -u -8 -r1.2 Dialog.pm >--- ldapserver/ldap/admin/src/scripts/Dialog.pm 12 Jun 2007 21:08:20 -0000 1.2 >+++ ldapserver/ldap/admin/src/scripts/Dialog.pm 15 Jun 2007 20:57:28 -0000 >@@ -101,16 +101,31 @@ > # returns true if this dialog is to be displayed for the current setup type > # false otherwise > sub isDisplayed { > my $self = shift; > > return $self->{type} <= $self->{"manager"}->{type}; > } > >+sub isEnabled { >+ my $self = shift; >+ return !defined($self->{disabled}); >+} >+ >+sub enable { >+ my $self = shift; >+ delete $self->{disabled}; >+} >+ >+sub disable { >+ my $self = shift; >+ $self->{disabled} = 1; >+} >+ > # each prompt looks like this: > # [ 'resource key', is pwd, hide ] > # The resource key is the string key of the resource > # is pwd is optional - if present, the prompt is for a password > # and should not echo the answer > # hide is optional - if present and true, the prompt will not be displayed - this > # is useful in cases where you may want to display or hide a subprompt depending > # on the response to a main prompt >@@ -130,17 +145,17 @@ > > # display each prompt for this dialog > my $index = 0; > my @prompts = @{$self->{prompts}}; > for (my $index = 0; $index < @prompts; ++$index) { > my $prompt = $prompts[$index]; > my $defaultans = $self->{defaultAns}($self, $index); > my $ans; >- if ($self->isDisplayed() && !$promtpt->[2]) { >+ if ($self->isDisplayed() && !$prompt->[2]) { > $ans = $self->{manager}->showPrompt($prompt->[0], $defaultans, $prompt->[1]); > } else { > $ans = $defaultans; > } > > # see if this is the special BACK response, and finish if so > if ($self->{"manager"}->isBack($ans)) { > $resp = $DialogManager::BACK; >@@ -150,22 +165,24 @@ > # figure out what action to take based on the users response > # this will set values in the setup info file > # this will also validate input, and display errors if the > # input is not correct - in that case, the resp will be > # SAME to reprompt, or ERR if unrecoverable > # NOTE: user cannot BACK from prompt to prompt - BACK > # always means BACK to the previous dialog > $resp = $self->{handleResp}($self, $ans, $index); >- if ($resp == $DialogManager::SAME) { >+ if (($resp == $DialogManager::SAME) or ($resp == $DialogManager::FIRST)) { > if (!$self->isDisplayed()) { > $self->{manager}->alert('dialog_use_different_type'); > $resp = $DialogManager::ERR; >- } else { >+ } elsif ($resp == $DialogManager::SAME) { > $index--; # reprompt >+ } else { >+ $index = -1; # reshow first prompt on dialog > } > } elsif ($resp == $DialogManager::ERR) { > last; > } > } > > return $resp; > } >Index: ldapserver/ldap/admin/src/scripts/DialogManager.pm >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/DialogManager.pm,v >retrieving revision 1.1 >diff -u -8 -r1.1 DialogManager.pm >--- ldapserver/ldap/admin/src/scripts/DialogManager.pm 8 Jun 2007 01:09:16 -0000 1.1 >+++ ldapserver/ldap/admin/src/scripts/DialogManager.pm 15 Jun 2007 20:57:28 -0000 >@@ -41,20 +41,21 @@ > @ISA = qw(Exporter); > @EXPORT = qw($BACK $SAME $NEXT $ERR); > @EXPORT_OK = qw($BACK $SAME $NEXT $ERR); > > use Dialog; > use SetupLog; > > # Dialog responses >-$BACK = -1; >-$SAME = 0; >-$NEXT = 1; >-$ERR = 2; >+$FIRST = -2; # go back to first prompt on a dialog >+$BACK = -1; # go back to previous dialog >+$SAME = 0; # reshow the same prompt or dialog >+$NEXT = 1; # go to the next dialog >+$ERR = 2; # fatal error > > # The DialogManager controls the flow of the dialogs and contains context shared > # among all of the dialogs (resources, logs, current setup type, etc.) > # all of these are optional > sub new { > my $type = shift; > my $self = {}; > >@@ -194,28 +195,30 @@ > my $self = shift; > my $done; > my $index = 0; > my $incr = 1; > my $rc = 0; > > while (!$done) { > my $dialog = $self->{dialogs}->[$index]; >- my $resp = $NEXT; >- $resp = $dialog->run(); >- if ($resp == $BACK) { >- $incr = -1; >- } elsif ($resp == $NEXT) { >- $incr = 1; >- } elsif ($resp == $SAME) { >- $incr = 0; >- } else { >- $self->handleError($resp); >- $done = 1; >- $rc = 1; >+ if ($dialog->isEnabled()) { >+ my $resp = $NEXT; >+ $resp = $dialog->run(); >+ if ($resp == $BACK) { >+ $incr = -1; >+ } elsif ($resp == $NEXT) { >+ $incr = 1; >+ } elsif (($resp == $SAME) or ($resp == $FIRST)) { >+ $incr = 0; >+ } else { >+ $self->handleError($resp); >+ $done = 1; >+ $rc = 1; >+ } > } > $index += $incr; > if ($index < 0) { > $index = 0; > } elsif ($index >= @{$self->{dialogs}}) { > $done = 1; > } > } >Index: ldapserver/ldap/admin/src/scripts/Resource.pm >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Resource.pm,v >retrieving revision 1.2 >diff -u -8 -r1.2 Resource.pm >--- ldapserver/ldap/admin/src/scripts/Resource.pm 8 Jun 2007 20:36:53 -0000 1.2 >+++ ldapserver/ldap/admin/src/scripts/Resource.pm 15 Jun 2007 20:57:28 -0000 >@@ -69,29 +69,55 @@ > sub read { > my $self = shift; > > while (@_) { > push @{$self->{filenames}}, shift; > } > > for my $filename (@{$self->{filenames}}) { >+ my $incontinuation = 0; >+ my $curkey; > open RES, $filename or die "Error: could not open resource file $filename: $!"; > while (<RES>) { >- next if (/^\s*$/); # skip blank lines >- next if (/^\s*\#/); # skip comment lines >+ my $iscontinuation; >+ chop; # trim trailing newline >+ if (/^\s*$/) { # skip blank/empty lines >+ $incontinuation = 0; >+ next; >+ } >+ if (/^\s*\#/) { # skip comment lines >+ $incontinuation = 0; >+ next; >+ } > # read name = value pairs like this > # bol whitespace* name whitespace* '=' whitespace* value eol > # the value will include any trailing whitespace >- if (/^\s*(.*?)\s*=\s*(.*?)$/) { >- $self->{res}->{$1} = $2; >+ if (/\\$/) { >+ chop; >+ $iscontinuation = 1; >+ } >+ if ($incontinuation) { >+ $self->{res}->{$curkey} .= "\n" . $_; >+ } elsif (/^\s*(.*?)\s*=\s*(.*?)$/) { > # replace \n with real newline >- $self->{res}->{$1} =~ s/\\n/\n/g; >+ if ($curkey) { >+ $self->{res}->{$curkey} =~ s/\\n/\n/g; >+ } >+ $curkey = $1; >+ $self->{res}->{$curkey} = $2; >+ } >+ if ($iscontinuation) { # if line ends with a backslash, continue the data on the next line >+ $incontinuation = 1; >+ } else { >+ $incontinuation = 0; > } > } >+ # replace \n with real newline >+ $self->{res}->{$curkey} =~ s/\\n/\n/g; > close RES; > } > } > > # given a resource key and optional args, return the value > # $text = $res->getText('key'); > # or > # $text = $res->getText('key', @args); >Index: ldapserver/ldap/admin/src/scripts/Setup.pm.in >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Setup.pm.in,v >retrieving revision 1.2 >diff -u -8 -r1.2 Setup.pm.in >--- ldapserver/ldap/admin/src/scripts/Setup.pm.in 12 Jun 2007 21:08:20 -0000 1.2 >+++ ldapserver/ldap/admin/src/scripts/Setup.pm.in 15 Jun 2007 20:57:28 -0000 >@@ -142,17 +142,17 @@ > $self->{inf} = new Inf($self->{inffile}); > $self->{keep} = 1; # do not delete user supplied inf file > } > > # see if user passed in default inf values - also, command line > # arguments override those passed in via an inf file - this > # allows the reuse of .inf files with some parameters overridden > for (@ARGV) { >- if (/^(\w+).(\w+)=(.*)$/) { # e.g. section.param=value >+ if (/^(\w+)\.(\w+)=(.*)$/) { # e.g. section.param=value > $self->{inf}->{$1}->{$2} = $3; > } else { # error > print STDERR "Error: unknown command line option $_\n"; > usage(); > exit 1; > } > } > >@@ -197,12 +197,27 @@ > > sub doExit { > my $self = shift; > $self->msg($FATAL, "Exiting . . .\n"); > $self->msg("Log file is " . $self->{log}->{filename} . "\n"); > exit 1; > } > >+# get a list of the directory servers in configdir >+sub getDirServers { >+ my $self = shift; >+ if (!$self->{dirservers}) { >+ $self->{dirservers} = []; >+ for my $dir (glob("$self->{configdir}/slapd-*")) { >+ if (-d $dir) { >+ push @{$self->{dirservers}}, $dir; >+ } >+ } >+ } >+ return @{$self->{dirservers}}; >+} >+ >+ > ############################################################################# > # Mandatory TRUE return value. > # > 1; >Index: ldapserver/ldap/admin/src/scripts/Util.pm >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Util.pm,v >retrieving revision 1.1 >diff -u -8 -r1.1 Util.pm >--- ldapserver/ldap/admin/src/scripts/Util.pm 8 Jun 2007 01:09:16 -0000 1.1 >+++ ldapserver/ldap/admin/src/scripts/Util.pm 15 Jun 2007 20:57:28 -0000 >@@ -32,20 +32,28 @@ > # > # > # Copyright (C) 2007 Red Hat, Inc. > # All rights reserved. > # END COPYRIGHT BLOCK > # > > package Util; >+ >+use Mozilla::LDAP::Conn; >+use Mozilla::LDAP::Utils qw(normalizeDN); >+use Mozilla::LDAP::API; # Direct access to C API >+use Mozilla::LDAP::LDIF; >+ > require Exporter; > @ISA = qw(Exporter); >-@EXPORT = qw(portAvailable getAvailablePort isValidDN); >-@EXPORT_OK = qw(portAvailable getAvailablePort isValidDN); >+@EXPORT = qw(portAvailable getAvailablePort isValidDN addSuffix getMappedEntries >+ process_maptbl check_and_add_entry getMappedEntries); >+@EXPORT_OK = qw(portAvailable getAvailablePort isValidDN addSuffix getMappedEntries >+ process_maptbl check_and_add_entry getMappedEntries); > > use strict; > > use Socket; > > # return true if the given port number is available, false otherwise > sub portAvailable { > my $port = shift; >@@ -74,9 +82,531 @@ > } > } > > sub isValidDN { > my $dn = shift; > return ($dn =~ /^[0-9a-zA-Z_-]+=.*$/); > } > >+sub debug { >+ print @_, "\n"; >+} >+ >+# delete the subtree starting from the passed entry >+sub delete_all >+{ >+ my ($conn, $bentry) = @_; >+ my $sentry = $conn->search($bentry->{dn}, >+ "subtree", "(objectclass=*)", 0, ("dn")); >+ my @mystack = (); >+ while ($sentry) { >+ push @mystack, $sentry->getDN(); >+ $sentry = $conn->nextEntry(); >+ } >+ # reverse order >+ my $dn = pop @mystack; >+ while ($dn) { >+ $conn->delete($dn); >+ my $rc = $conn->getErrorCode(); >+ if ( $rc != 0 ) { >+ $conn->printError(); >+ print "ERROR: unable to delete entry $dn, error code: $rc\n"; >+ return 1; >+ } >+ $dn = pop @mystack; >+ } >+ return 0; >+} >+ >+my %ignorelist = ( >+ "modifytimestamp", "modifyTimestamp", >+ "createtimestamp", "createTimestamp", >+ "installationtimestamp", "installationTimestamp", >+ "creatorsname", "creatorsName", >+ "modifiersname", "modifiersName", >+ "numsubordinates", "numSubordinates" >+); >+ >+my %speciallist = ( >+ "uniquemember", 1 >+); >+ >+# compare 2 entries >+# return 0 if they match 100% (exception: %ignorelist). >+# return 1 if they match except %speciallist. >+# return -1 if they do not match. >+sub comp_entries >+{ >+ my ($e0, $e1) = @_; >+ my $rc = 0; >+ foreach my $akey ( keys %{$e0} ) >+ { >+ next if ( $ignorelist{lc($akey)} ); >+ my $aval0 = $e0->{$akey}; >+ my $aval1 = $e1->{$akey}; >+ my $amin; >+ my $amax; >+ my $a0max = $#{$aval0}; >+ my $a1max = $#{$aval1}; >+ if ( $a0max != $a1max ) >+ { >+ if ( $speciallist{lc($akey)} ) >+ { >+ $rc = 1; >+ if ( $a0max < $a1max ) >+ { >+ $amin = $a0max; >+ $amax = $a1max; >+ } >+ else >+ { >+ $amin = $a1max; >+ $amax = $a0max; >+ } >+ } >+ else >+ { >+ $rc = -1; >+ return $rc; >+ } >+ } >+ my @sval0 = sort { $a cmp $b } @{$aval0}; >+ my @sval1 = sort { $a cmp $b } @{$aval1}; >+ for ( my $i = 0; $i <= $amin; $i++ ) >+ { >+ my $isspecial = -1; >+ if ( $sval0[$i] ne $sval1[$i] ) >+ { >+ if ( 0 > $isspecial ) >+ { >+ $isspecial = $speciallist{lc($akey)}; >+ } >+ if ( $isspecial ) >+ { >+ $rc = 1; >+ } >+ else >+ { >+ $rc = -1; >+ return $rc; >+ } >+ } >+ } >+ } >+ return $rc; >+} >+ >+# if the entry does not exist on the server, add the entry. >+# otherwise, do nothing >+# you can use this as the callback to getMappedEntries, so >+# that for each entry in the ldif file being processed, you >+# can call this subroutine to add or update the entry >+# use like this: >+# getMappedEntries($mapper, \@ldiffiles, \&check_and_add_entry, >+# [$conn, $fresh, $verbose]); >+# where $conn is a perldap Conn >+# $fresh if true will update the entry if it exists >+# $verbose prints out more info >+sub check_and_add_entry >+{ >+ my ($context, $aentry) = @_; >+ my $conn = $context->[0]; >+ my $fresh = $context->[1]; >+ my $verbose = $context->[2]; >+ my $sentry = $conn->search($aentry->{dn}, "base", "(objectclass=*)"); >+ do >+ { >+ my $needtoadd = 1; >+ my $needtomod = 0; >+ my $rval = -1; >+ if ( $sentry && !$fresh ) >+ { >+ $rval = comp_entries( $sentry, $aentry ); >+ } >+ if ( 0 == $rval && !$fresh ) >+ { >+ # the identical entry exists on the configuration DS. >+ # no need to add the entry. >+ $needtoadd = 0; >+ goto out; >+ } >+ elsif ( (1 == $rval) && !$fresh ) >+ { >+ $needtoadd = 0; >+ $needtomod = 1; >+ } >+ elsif ( $sentry && $sentry->{dn} ) >+ { >+ # $fresh || $rval == -1 >+ # an entry having the same DN exists, but the attributes do not >+ # match. remove the entry and the subtree underneath. >+ if ( $verbose ) >+ { >+ print "Deleting an entry dn: $sentry->{dn} ...\n"; >+ } >+ $rval = delete_all($conn, $sentry); >+ if ( 0 != $rval ) >+ { >+ return 0; >+ } >+ } >+ >+ if ( 1 == $needtoadd ) >+ { >+ $conn->add($aentry); >+ my $rc = $conn->getErrorCode(); >+ if ( $rc != 0 ) >+ { >+ print "ERROR: adding an entry $aentry->{dn} failed, error code: $rc\n"; >+ print "[entry]\n"; >+ $aentry->printLDIF(); >+ $conn->close(); >+ return 0; >+ } >+# if ( $verbose ) >+# { >+# print "Entry $aentry->{dn} is added\n"; >+# } >+ } >+ elsif ( 1 == $needtomod ) # $sentry exists >+ { >+ foreach my $attr ( keys %speciallist ) >+ { >+ foreach my $nval ( @{$aentry->{$attr}} ) >+ { >+ $sentry->addValue( $attr, $nval ); >+ } >+ } >+ $conn->update($sentry); >+ my $rc = $conn->getErrorCode(); >+ if ( $rc != 0 ) >+ { >+ print "ERROR: updating an entry $sentry->{dn} failed, error code: $rc\n"; >+ print "[entry]\n"; >+ $aentry->printLDIF(); >+ $conn->close(); >+ return 0; >+ } >+ } >+ if ( $sentry ) >+ { >+ $sentry = $conn->nextEntry(); # supposed to have no more entries >+ } >+ } until ( !$sentry ); >+out: >+ return 1; >+} >+ >+# the default callback used with getMappedEntries >+# just adds the given entry to the given list >+sub cbaddent { >+ my $list = shift; >+ my $ent = shift; >+ push @{$list}, $ent; >+ return 1; >+} >+ >+# given a mapper and a list of LDIF files, produce a list of >+# perldap Entry objects which have had their tokens subst-ed >+# with values from the mapper >+# An optional callback can be supplied. Each entry will be >+# given to this callback. The callback should return a list >+# of localizable errors. If no callback is supplied, the >+# entries will be returned in a list. >+# Arguments: >+# mapper - a hash ref - the keys are the tokens to replace >+# and the values are the replacements >+# ldiffiles - an array ref - the list of LDIF files to >+# operate on >+# callback (optional) - a code ref - a ref to a subroutine >+# that will be called with each entry - see below >+# context (optional) - this will be passed as the first >+# argument to your given callback - see below >+# errs (optional) - an array ref - This is how errors >+# are returned to the caller - see below >+# Callback: >+# The callback sub will be called for each entry after >+# the entry has been converted. The callback will be >+# called with the given context as the first argument >+# and the Mozilla::LDAP::Entry as the second argument, >+# and an errs array ref as the third argument. The >+# callback should return true to continue processing, >+# or false if a fatal error was encountered that should >+# abort processing of any further. >+# Errors: >+# This function should return an array of errors in the >+# format described below, for use with Resource::getText(). >+# If the callback returns any errors >+# Return: >+# The return value is a list of entries. >+# Example usage: >+# sub handle_entries { >+# my $context = shift; >+# my $entry = shift; >+# .... do something with entry .... >+# .... if $context is Mozilla::LDAP::Conn, $conn->add($entry); ... >+# .... report errors .... >+# if ($fatalerror) { >+# return 0; >+# } else { >+# return 1; >+# } >+# } >+# $mapper = {foo => 'bar', baz => 'biff'}; >+# @ldiffiles = ('foo.ldif', 'bar.ldif', ..., 'biff.ldif'); >+# $conn = new Mozilla::LDAP::Conn(...); >+# @entries = getMappedEntries($mapper, \@ldiffiles, \&handle_entries, $conn); >+# Note that this will return 0 entries since a callback was used. >+# The simpler example is this: >+# @entries = getMappedEntries($mapper, \@ldiffiles); >+# >+sub getMappedEntries { >+ my $mapper = shift; >+ my $ldiffiles = shift; >+ my $callback = shift || \&cbaddent; # default - just add entry to @entries >+ my @entries = (); >+ my $context = shift || \@entries; >+ my $error; >+ >+ if (!ref($ldiffiles)) { >+ $ldiffiles = [ $ldiffiles ]; >+ } >+ >+ foreach my $ldiffile (@{$ldiffiles}) { >+ open(MYLDIF, "< $ldiffile") or die "Can't open $ldiffile : $!"; >+ my $in = new Mozilla::LDAP::LDIF(*MYLDIF); >+ debug("Processing $ldiffile ..."); >+ ENTRY: while (my $entry = Mozilla::LDAP::LDIF::readOneEntry($in)) { >+ # first, fix the DN >+ my $dn = $entry->getDN(); >+ my $origdn = $dn; >+ while ( $dn =~ /%([\w_-]+)%/ ) { >+ if (exists($mapper->{$1})) { >+ $dn =~ s{%([\w_-]+)%}{$mapper->{$1}}ge; >+ } else { >+ print "ERROR: \"$origdn\" mapped to \"$dn\".\n"; >+ print "The LDIF file $ldiffile contains a token $1 for which there is no mapper.\n"; >+ print "Please check $ldiffile and your mapper to make sure all tokens are handled correctly.\n"; >+ $error = 1; >+ last ENTRY; >+ } >+ } >+ $entry->setDN($dn); >+ # next, fix all of the values in all of the attributes >+ foreach my $attr (keys %{$entry}) { >+ my @newvalues = (); >+ foreach my $value ($entry->getValues($attr)) { >+ # Need to repeat to handle nested subst >+ my $origvalue = $value; >+ while ( $value =~ /%([\w_-]+)%/ ) { >+ if (exists($mapper->{$1})) { >+ $value =~ s{%([\w_-]+)%}{$mapper->{$1}}ge; >+ } else { >+ print "ERROR: \"$origvalue\" mapped to \"$value\".\n"; >+ print "The LDIF file $ldiffile contains a token $1 for which there is no mapper.\n"; >+ print "Please check $ldiffile and your mapper to make sure all tokens are handled correctly.\n"; >+ $error = 1; >+ last ENTRY; >+ } >+ } >+ push @newvalues, $value; >+ } >+ $entry->setValues( $attr, @newvalues ); >+ } >+ >+ if (!&{$callback}($context, $entry)) { >+ print "There was an error processing entry ", $entry->getDN(), "\n"; >+ print "Cannot continue processing entries.\n"; >+ $error = 1; >+ last ENTRY; >+ } >+ >+ } >+ close(MYLDIF); >+ last if ($error); # do not process any more ldiffiles if an error occurred >+ } >+ >+ return @entries; >+} >+ >+# you should only use this function if you know for sure >+# that the suffix and backend do not already exist >+# use addSuffix instead >+sub newSuffixAndBackend { >+ my $context = shift; >+ my $suffix = shift; >+ my $bename = shift; >+ my $nsuffix = normalizeDN($suffix); >+ my @errs; >+ >+ my $dn = "cn=$bename, cn=ldbm database, cn=plugins, cn=config"; >+ my $entry = new Mozilla::LDAP::Entry(); >+ $entry->setDN($dn); >+ $entry->setValues('objectclass', 'top', 'extensibleObject', 'nsBackendInstance'); >+ $entry->setValues('cn', $bename); >+ $entry->setValues('nsslapd-suffix', $nsuffix); >+ $context->add($entry); >+ my $rc = $context->getErrorCode(); >+ if ($rc) { >+ return ('error_creating_suffix_backend', $suffix, $bename, $context->getErrorString()); >+ } >+ >+ $entry = new Mozilla::LDAP::Entry(); >+ $dn = "cn=\"$nsuffix\", cn=mapping tree, cn=config"; >+ $entry->setDN($dn); >+ $entry->setValues('objectclass', 'top', 'extensibleObject', 'nsMappingTree'); >+ $entry->setValues('cn', "\"$nsuffix\""); >+ $entry->setValues('nsslapd-state', 'backend'); >+ $entry->setValues('nsslapd-backend', $bename); >+ $context->add($entry); >+ $rc = $context->getErrorCode(); >+ if ($rc) { >+ return ('error_creating_suffix', $suffix, $context->getErrorString()); >+ } >+ >+ return (); >+} >+ >+sub findbecb { >+ my $entry = shift; >+ my $attrs = shift; >+ return $entry->hasValue('objectclass', $attrs->[0], 1) && >+ $entry->hasValue('cn', $attrs->[1], 1); >+} >+ >+sub findBackend { >+ my $context = shift; >+ my $bename = shift; >+ my $ent; >+ if (ref($context) eq 'Mozilla::LDAP::Conn') { >+ $ent = $context->search("cn=ldbm database,cn=plugins,cn=config", "one", >+ "(&(objectclass=nsBackendInstance)(cn=$bename)") >+ } else { >+ $ent = $context->search("cn=ldbm database,cn=plugins,cn=config", "one", >+ \&findbecb, ['nsBackendInstance', $bename]) >+ } >+} >+ >+sub findsuffixcb { >+ my $entry = shift; >+ my $attrs = shift; >+ return $entry->hasValue('cn', $attrs->[0], 1) || >+ $entry->hasValue('cn', $attrs->[1], 1); >+} >+ >+sub findSuffix { >+ my $context = shift; >+ my $suffix = shift; >+ my $nsuffix = normalizeDN($suffix); >+ my $ent; >+ if (ref($context) eq 'Mozilla::LDAP::Conn') { >+ $ent = $context->search("cn=mapping tree,cn=config", "one", >+ "(|(cn=\"$suffix\")(cn=\"$nsuffix\"))"); >+ } else { >+ $ent = $context->search("cn=mapping tree,cn=config", "one", >+ \&findsuffixcb, ["\"$suffix\"", "\"$nsuffix\""]) >+ } >+} >+ >+sub getUniqueBackendName { >+ my $context = shift; >+ my $bename = "backend"; >+ my $index = 0; >+ my $ent = findBackend($context, ($bename . $index)); >+ while ($ent) { >+ ++$index; >+ $ent = findBackend($context, ($bename . $index)); >+ } >+ >+ return $bename.$index; >+} >+ >+sub addSuffix { >+ my $context = shift; # Conn >+ my $suffix = shift; >+ my $bename = shift; # optional >+ my $ent; >+ >+ if ($bename && ($ent = findBackend($context, $bename))) { >+ return ('backend_already_exists', $bename, $ent->getDN()); >+ } >+ >+ if ($ent = findSuffix($context, $suffix)) { >+ return ('suffix_already_exists', $suffix, $ent->getDN()); >+ } >+ >+ if (!$bename) { >+ $bename = getUniqueBackendName($context); >+ } >+ >+ my @errs = newSuffixAndBackend($context, $suffix, $bename); >+ >+ return @errs; >+} >+ >+# process map table >+# [map table sample] >+# fqdn = FullMachineName >+# hostname = `use Sys::Hostname; $returnvalue = hostname();` >+# ds_console_jar ="%normbrand%-ds-%ds_version%.jar" >+# >+# * If the right-hand value is in ` (backquote), the value is eval'ed by perl. >+# The output should be stored in $returnvalue to pass to the internal hash. >+# * If the right-hand value is in " (doublequote), the value is passed as is. >+# * If the right-hand value is not in any quote, the value should be found >+# in either of the setup inf file (static) or the install inf file (dynamic). >+# * Variables surrounded by @ (e.g., @admin_confdir@) are replaced with the >+# system path at the compile time. >+# * The right-hand value can contain variables surrounded by % (e.g., %asid%) >+# which refers the right-hand value (key) of this map file. >+# The %token% tokens are replaced in getMappedEntries >+sub process_maptbl >+{ >+ my ($mapper, @infdata) = @_; >+ >+ if (defined($mapper->{""})) { >+ $mapper = $mapper->{""}; # side effect of Inf with no sections >+ } >+ >+ KEY: foreach my $key (keys %{$mapper}) >+ { >+ my $value = $mapper->{$key}; >+ if ($value =~ /^\"/) >+ { >+ $value =~ tr/\"//d; # value is a regular double quoted string - remove quotes >+ $mapper->{$key} = $value; >+ } >+ elsif ($value =~ /^\`/) >+ { >+ $value =~ tr/\`//d; # value is a perl expression to eval >+ my $returnvalue; # set in eval expression >+ eval $value; >+ $mapper->{$key} = $returnvalue; # perl expression sets $returnvalue >+ } >+ else >+ { >+ # get the value from one of the Inf passed in >+ my $infsection; >+ foreach my $thisinf (@infdata) >+ { >+ foreach my $section0 (keys %{$thisinf}) >+ { >+ $infsection = $thisinf->{$section0}; >+ next if (!ref($infsection)); >+ if (defined($infsection->{$value})) >+ { >+ $mapper->{$key} = $infsection->{$value}; >+ next KEY; >+ } >+ } >+ } >+ if (!defined($infsection->{$value})) >+ { >+ print "ERROR: $value not found in the .inf files\n"; >+ return {}; >+ } >+ } >+ } >+ return $mapper; >+} >+ > 1; >Index: ldapserver/ldap/admin/src/scripts/setup-ds.res.in >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/setup-ds.res.in,v >retrieving revision 1.2 >diff -u -8 -r1.2 setup-ds.res.in >--- ldapserver/ldap/admin/src/scripts/setup-ds.res.in 8 Jun 2007 20:36:53 -0000 1.2 >+++ ldapserver/ldap/admin/src/scripts/setup-ds.res.in 15 Jun 2007 20:57:28 -0000 >@@ -74,8 +74,14 @@ > # ----------- DS Sample Data Dialog Resource ---------------- > dialog_dssample_text = You may install some sample entries in this directory instance. These\nentries will be installed in a separate suffix and will not interfere\nwith the normal operation of the directory server.\n\n > dialog_dssample_prompt = Do you want to install the sample entries? > > # ----------- DS Populate Data Dialog Resource ---------------- > dialog_dspopulate_text = You may wish to populate your new directory instance with some data.\n"You may already have a file in LDIF format to use or some suggested\nentries can be added. If you want to import entries from an LDIF\nfile, you may type in the full path and filename at the prompt. If\nyou want the setup program to add the suggested entries, type the\nword suggest at the prompt. The suggested entries are common\ncontainer entries under your specified suffix, such as ou=People and\nou=Groups, which are commonly used to hold the entries for the persons\nand groups in your organization. If you do not want to add any of\nthese entries, type the word none at the prompt.\n\n > dialog_dspopulate_prompt = Type the full path and filename, the word suggest, or the word none > dialog_dspopulate_error = The file '%s' was not found. Please choose another one.\n\n >+ >+# ----------- miscellaneous ---------------- >+backend_already_exists = A database backend with the name '%s' already exists. Config entry DN '%s'. Please choose another backend name. addSuffix can generate a unique backend name if you do not specify a backend name.\n\n >+suffix_already_exists = The suffix '%s' already exists. Config entry DN '%s'.\n\n >+error_creating_suffix_backend = Could not create the suffix '%s'. There was an error creating the backend database named '%s' for the suffix. Error: %s\n\n >+error_creating_suffix = Could not create the suffix '%s'. Error: %s\n\n
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 237356
:
153230
|
153562
|
153667
|
153668
|
153674
|
153675
|
153677
|
153678
|
155103
|
155105
|
155406
|
155407
|
155408
|
155409
|
155410
|
155411
|
155412
|
155413
|
155414
|
155483
|
155484
|
155485
|
155486
|
155487
|
155488
|
155489
|
155490
|
156389
|
156510
|
156525
|
156539
|
156540
|
156541
|
156612
|
156613
|
156614
|
156626
|
156633
|
156634
|
156741
|
156829
|
156834
|
156839
|
156840
|
156895
|
157043
|
157044
|
157133
| 157159 |
157160
|
157164
|
157165
|
157167
|
157298
|
157378
|
157381
|
157388
|
157390
|
157400
|
157401
|
157407
|
157408
|
157429
|
157431
|
157469
|
157471
|
157479
|
157480
|
160762