diff options
author | Rich Megginson <rmeggins@redhat.com> | 2007-07-13 19:51:48 +0000 |
---|---|---|
committer | Rich Megginson <rmeggins@redhat.com> | 2007-07-13 19:51:48 +0000 |
commit | 99500fdbe2c14ed53bce3ac26b7a705255a5c269 (patch) | |
tree | 0c257c17632135f475728fd78b64384fe7aba318 | |
parent | cd0220f611d38f47c6414a3a976c85800eddce52 (diff) | |
download | ds-99500fdbe2c14ed53bce3ac26b7a705255a5c269.tar.gz ds-99500fdbe2c14ed53bce3ac26b7a705255a5c269.tar.xz ds-99500fdbe2c14ed53bce3ac26b7a705255a5c269.zip |
Resolves: bug 248145
Bug Description: Replace ds_newinst binary with perl script
Reviewed by: nhosoi (Thanks!)
Fix Description: 1) Inf needs to be able to read the .inf file from stdin. This is what ds_newinst.pl does currently.
2) getlogin seems not to work in all cases, so add a more robust replacement.
Platforms tested: RHEL4, FC6
Flag Day: no
Doc impact: no
-rw-r--r-- | ldap/admin/src/scripts/DSCreate.pm.in | 2 | ||||
-rw-r--r-- | ldap/admin/src/scripts/Inf.pm | 16 | ||||
-rw-r--r-- | ldap/admin/src/scripts/SetupDialogs.pm.in | 5 | ||||
-rw-r--r-- | ldap/admin/src/scripts/Util.pm.in | 14 |
4 files changed, 26 insertions, 11 deletions
diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in index 62cbf8ea..3401f86c 100644 --- a/ldap/admin/src/scripts/DSCreate.pm.in +++ b/ldap/admin/src/scripts/DSCreate.pm.in @@ -596,7 +596,7 @@ sub setDefaults { if (!$inf->{General}->{SuiteSpotUserID}) { if ($> != 0) { # if not root, use the user's uid - $inf->{General}->{SuiteSpotUserID} = getlogin; + $inf->{General}->{SuiteSpotUserID} = getLogin; } # otherwise, the uid must be specified } diff --git a/ldap/admin/src/scripts/Inf.pm b/ldap/admin/src/scripts/Inf.pm index 27a840ad..347404aa 100644 --- a/ldap/admin/src/scripts/Inf.pm +++ b/ldap/admin/src/scripts/Inf.pm @@ -77,8 +77,14 @@ sub read { my $incontinuation = 0; my $curkey; - open INF, $filename or die "Error: could not open inf file $filename: $!"; - while (<INF>) { + my $inffh; + if ($filename eq "-") { + $inffh = \*STDIN; + } else { + open INF, $filename or die "Error: could not open inf file $filename: $!"; + $inffh = \*INF; + } + while (<$inffh>) { my $iscontinuation; chop; # trim trailing newline if (/^\s*$/) { # skip blank/empty lines @@ -107,7 +113,9 @@ sub read { $incontinuation = 0; } } - close INF; + if ($inffh ne \*STDIN) { + close $inffh; + } } sub section { @@ -149,6 +157,8 @@ sub write { $filename = $self->{filename}; } + return if ($filename eq "-"); + open INF, ">$filename" or die "Error: could not write inf file $filename: $!"; # write General section first $self->writeSection('General', \*INF); diff --git a/ldap/admin/src/scripts/SetupDialogs.pm.in b/ldap/admin/src/scripts/SetupDialogs.pm.in index 86f9ebae..ec450c3d 100644 --- a/ldap/admin/src/scripts/SetupDialogs.pm.in +++ b/ldap/admin/src/scripts/SetupDialogs.pm.in @@ -44,6 +44,7 @@ use DialogManager; use Setup; use Dialog; use Net::Domain qw(hostfqdn); +use Util; my $welcome = new DialogYesNo ( $EXPRESS, @@ -136,7 +137,7 @@ sub verifyUserChoice { } } if ($> != 0) { # if not root, the user must be our uid - my $username = getlogin; + my $username = getLogin; if ($strans ne $username) { $self->{manager}->alert("dialog_ssuser_must_be_same", $username); return $DialogManager::SAME; @@ -218,7 +219,7 @@ my $usergroup = new Dialog ( if ($> == 0) { # if root, use the default user $username = "@defaultuser@"; } else { # if not root, use the user's uid - $username = getlogin; + $username = getLogin; } } return $username; diff --git a/ldap/admin/src/scripts/Util.pm.in b/ldap/admin/src/scripts/Util.pm.in index ce20bfb3..a4d50d8a 100644 --- a/ldap/admin/src/scripts/Util.pm.in +++ b/ldap/admin/src/scripts/Util.pm.in @@ -48,11 +48,11 @@ require Exporter; @EXPORT = qw(portAvailable getAvailablePort isValidDN addSuffix getMappedEntries process_maptbl check_and_add_entry getMappedEntries getHashedPassword debug createInfFromConfig - isValidServerID isValidUser makePaths); + isValidServerID isValidUser makePaths getLogin); @EXPORT_OK = qw(portAvailable getAvailablePort isValidDN addSuffix getMappedEntries process_maptbl check_and_add_entry getMappedEntries getHashedPassword debug createInfFromConfig - isValidServerID isValidUser makePaths); + isValidServerID isValidUser makePaths getLogin); use strict; @@ -111,6 +111,10 @@ sub isValidServerID { return $servid =~ /^[$validchars]+$/o; } +sub getLogin { + return getlogin || (getpwuid($>))[0] || $ENV{USER} || die "Error: could not determine the current user ID: $!"; +} + sub isValidUser { my $user = shift; # convert numeric uid to string @@ -122,7 +126,7 @@ sub isValidUser { } } if ($> != 0) { # if not root, the user must be our uid - my $username = getlogin; + my $username = getLogin; if ($strans ne $username) { return ("dialog_ssuser_must_be_same", $username); } @@ -799,8 +803,8 @@ sub createInfFromConfig { print $outfh "start_server= 0\n"; my $suffix; - my $ent = $conn->search("cn=ldbm database,cn=plugins,cn=config", - "one", "(objectclass=*)"); + $ent = $conn->search("cn=ldbm database,cn=plugins,cn=config", + "one", "(objectclass=*)"); if (!$ent) { push @{$errs}, "error_opening_dseldif", $fname, $!; close $outfh; |