/usr/sbin/register-ds-admin is in 389-admin 1.1.35-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | #!/usr/bin/env perl
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# In addition, as a special exception, Red Hat, Inc. gives You the additional
# right to link the code of this Program with code not covered under the GNU
# General Public License ("Non-GPL Code") and to distribute linked combinations
# including the two, subject to the limitations in this paragraph. Non-GPL Code
# permitted under this exception must only link to the code of this Program
# through those well defined interfaces identified in the file named EXCEPTION
# found in the source code files (the "Approved Interfaces"). The files of
# Non-GPL Code may instantiate templates or use macros or inline functions from
# the Approved Interfaces without causing the resulting work to be covered by
# the GNU General Public License. Only Red Hat, Inc. may make changes or
# additions to the list of Approved Interfaces. You must obey the GNU General
# Public License in all respects for all of the Program code and other code used
# in conjunction with the Program except the Non-GPL Code covered by this
# exception. If you modify this file, you may extend this exception to your
# version of the file, but you are not obligated to do so. If you do not wish to
# provide this exception without modification, you must delete this exception
# statement from your version and license this file solely under the GPL without
# exception.
#
#
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#
use lib qw(/usr/lib/x86_64-linux-gnu/dirsrv/perl);
use strict;
use File::Basename;
use Net::Domain qw(hostfqdn);
# Admin Setup modules
use AdminUtil;
use AdminServer;
# Directory Setup modules
use Resource;
use Setup;
use SetupLog;
use DialogManager;
use Inf;
use DSUtil;
sub reg_get_passwd
{
my $setup = shift;
my $key = shift;
my $value0 = shift;
my $value1 = shift;
print("\n==============================================================================\n");
if ( $value1 )
{
$setup->msg(0, $key, $value0, $value1);
}
elsif ( $value0 )
{
$setup->msg(0, $key, $value0);
}
else
{
$setup->msg(0, $key);
}
system("stty -echo");
my $ans = <STDIN>;
system("stty echo");
print "\n";
chop($ans);
return $ans;
}
sub reg_get_response
{
my $setup = shift;
my $key = shift;
my $value = shift;
print("\n==============================================================================\n");
$setup->msg(0, $key, $value);
my $ans = <STDIN>;
print "\n";
chop($ans);
return $ans;
}
my $res = new Resource("/usr/share/dirsrv/properties/register-ds-admin.res",
"/usr/share/dirsrv/properties/setup-ds-admin.res",
"/usr/share/dirsrv/properties/setup-ds.res");
my $setup = new Setup($res);
$setup->msg('begin_ds_registration');
# get existing instances
my $instconfigdir = $setup->{configdir};
my %instances = ();
for my $dir (glob("$setup->{configdir}/slapd-*"))
{
if (-d $dir)
{
my $dname = dirname($dir);
my $bname = basename($dir);
push @{$instances{$dname}}, $bname;
}
}
# in case Directory Servers are installed at the unexpected location.
my $done = 0;
my $ans;
while ( !$done && ($ans = reg_get_response($setup, 'subds_conf_prompt', "/etc/dirsrv")) )
{
if ( $ans eq "" || !$ans )
{
$done = 1;
}
elsif ( ! -d $ans )
{
;
}
elsif ( basename($ans) =~ /^slapd-/ )
{
my $dname = dirname($ans);
my $bname = basename($ans);
if ( exists $instances{$dname} )
{
my $addit = 1;
foreach my $thisslapd ( @{$instances{$dname}} )
{
if ( $thisslapd eq $bname )
{
$addit = 0;
goto out0;
}
}
out0:
if ( $addit )
{
push @{$instances{$dname}}, $bname;
}
}
else
{
push @{$instances{$dname}}, $bname;
}
}
else
{
$ans =~ s/^\s+//;
$ans =~ s/[\/\s]+$//;
my $rc = opendir(DIR, $ans);
if ( $rc )
{
my $file = "";
while ( defined($file = readdir(DIR)) )
{
next if ( !("$file" =~ /^slapd-/) );
if ( exists $instances{$ans} )
{
my $addit = 1;
foreach my $thisslapd ( @{$instances{$ans}} )
{
if ( $thisslapd eq $file )
{
$addit = 0;
goto out1;
}
}
out1:
if ( $addit )
{
push @{$instances{$ans}}, $file;
}
}
else
{
push @{$instances{$ans}}, $file;
}
}
closedir(DIR);
}
}
}
my @instconfigdirs = keys %instances;
if ( $#instconfigdirs < 0 )
{
$setup->msg($FATAL, 'error_no_ds');
$setup->doExit(1);
}
print("\n==============================================================================\n");
$setup->msg('candidate_list_txt');
foreach my $c ( @instconfigdirs )
{
foreach my $i ( @{$instances{$c}} )
{
print " $c/$i\n";
}
}
# see if there is already a configds
my $admConf = AdminUtil::getAdmConf("$instconfigdir/admin-serv");
my @admConfKeys = keys %$admConf;
my $orig_confdsid = "";
my $new_confdsid = "";
my $new_confdir = "";
my $adminuid = "";
my @errs = ();
my $fqdn = hostfqdn();
# set defaults
if ( $#admConfKeys >= 4 ) # admserv.conf, console.conf, httpd.conf, nss.conf
{
# Admin Server is installed; that is Config DS exists, which may be
# replaced with a new one in the RegDSDialogs
$orig_confdsid = getLocalConfigDS("$instconfigdir/admin-serv");
$setup->{inf}->{slapd}->{ServerIdentifier} = $orig_confdsid;
$setup->{inf}->{slapd}->{config_dir} = $instconfigdir;
$setup->{inf}->{slapd}->{Instances} = \%instances;
$setup->{inf}->{General}->{ConfigDirectoryLdapURL} = $admConf->{ldapurl};
$setup->{inf}->{General}->{ConfigDirectoryAdminID} = $admConf->{userdn};
$setup->{inf}->{General}->{AdminDomain} = $admConf->{AdminDomain};
$setup->{inf}->{General}->{SuiteSpotUserID} = $admConf->{SuiteSpotUserID};
$setup->{inf}->{General}->{SuiteSpotGroup} = $admConf->{SuiteSpotGroup};
($setup->{inf}->{General}->{FullMachineName} = $admConf->{ldapurl}) =~
s/.*:\/\/(.*):[0-9]*\/.*/\1/;
$setup->{inf}->{admin}->{SysUser} = $admConf->{sysuser};
$adminuid = $admConf->{userdn};
# read additional config from config DS
my $pset = AdminUtil::getPset($admConf);
if ($pset && %{$pset}) {
$setup->{inf}->{admin}->{Port} = $pset->{"configuration.nsserverport"};
$setup->{asorigport} = $pset->{"configuration.nsserverport"}; # save orig. port
$setup->{inf}->{admin}->{ServerIpAddress} = $pset->{"configuration.nsserveraddress"};
}
my $admpw = AdminUtil::getAdmpw($admConf);
if ($admpw && %{$admpw}) {
$setup->{inf}->{admin}->{ServerAdminID} = $admpw->{ServerAdminID};
$setup->{inf}->{admin}->{ServerAdminPwd} = $admpw->{ServerAdminPwd};
}
$setup->{reconfigas} = 1; # allow AS reconfig
my $dialogmgr = new DialogManager($setup, $res, $TYPICAL);
require RegDSDialogs;
my @dialogs = RegDSDialogs->getDialogs();
$dialogmgr->addDialog(@dialogs);
my $rc = $dialogmgr->run();
if ($rc)
{
$setup->doExit(1);
}
$new_confdsid = $setup->{inf}->{slapd}->{ServerIdentifier};
$new_confdir = $setup->{inf}->{slapd}->{config_dir};
my $newinst = "slapd-$new_confdsid";
my $inf = createInfFromConfig("$instconfigdir/$newinst", $newinst);
if ( ! $inf )
{
$setup->msg($FATAL, 'error_create_inf_from_config',
"$instconfigdir/$newinst");
$setup->doExit(1);
}
if ( $orig_confdsid ne $new_confdsid )
{
# To switch to the new Config DS, unregister the old one
print("\n==============================================================================\n");
$setup->msg('unregister_old_confds', $orig_confdsid);
# If we don't have it, prompt for the Admin password
if (!$setup->{inf}->{General}->{ConfigDirectoryAdminPwd} ||
"" eq $setup->{inf}->{General}->{ConfigDirectoryAdminPwd})
{
$ans = reg_get_passwd($setup, 'input_admin_passwd', $adminuid);
$setup->{inf}->{General}->{ConfigDirectoryAdminPwd} = $ans;
}
while (!unregisterDSWithConfigDS($orig_confdsid, \@errs, $setup->{inf}))
{
$setup->msg($FATAL, 'error_unregister_ds', $orig_confdsid);
$ans = reg_get_passwd($setup, 'input_admin_passwd', $adminuid);
$setup->{inf}->{General}->{ConfigDirectoryAdminPwd} = $ans;
@errs = ();
}
# updating the port number
my $oldport = 0;
my $newport = $inf->{slapd}->{ServerPort};
($oldport = $setup->{inf}->{General}->{ldapurl}) =~ s/.*:([0-9]*)\/.*/\1/;
$setup->{inf}->{General}->{ldapurl} =~ s/$oldport/$newport/;
$setup->{inf}->{General}->{ConfigDirectoryLdapURL} = "ldap://" . $fqdn . ":". $newport . "/o=NetscapeRoot";
}
# Set the new inf to $setup->{inf}
$setup->{inf}->{slapd} = $inf->{slapd};
$setup->{inf}->{slapd}->{config_dir} = $instconfigdir;
$setup->{inf}->{slapd}->{Instances} = \%instances;
}
else
{
# Admin Server is not set up.
# %instances has more than one instance
# note: this is orig_confdsid is just a candidate...
my $orig_confdir = $instconfigdirs[0];
my @orig_confdsids = @{$instances{$orig_confdir}};
($orig_confdsid = $orig_confdsids[0]) =~ s/slapd-(.*)/\1/;
my $originst = "slapd-$orig_confdsid";
my $inf = createInfFromConfig("$orig_confdir/$originst", $originst);
if ( ! $inf )
{
$setup->msg($FATAL, 'error_create_inf_from_config',
"$orig_confdir/$originst");
$setup->doExit(1);
}
$setup->{inf} = $inf;
$setup->{inf}->{slapd}->{ServerIdentifier} = $orig_confdsid;
$setup->{inf}->{slapd}->{config_dir} = $orig_confdir;
$setup->{inf}->{slapd}->{Instances} = \%instances;
my $dialogmgr = new DialogManager($setup, $res, $TYPICAL);
require RegDSDialogs;
require SetupDialogs;
require ConfigDSDialogs;
require ASDialogs;
my @dialogs = RegDSDialogs->getDialogs();
$dialogmgr->addDialog(@dialogs);
my $rc = $dialogmgr->run();
if ( $rc )
{
$setup->doExit(1);
}
$new_confdsid = $setup->{inf}->{slapd}->{ServerIdentifier};
$new_confdir = $setup->{inf}->{slapd}->{config_dir};
if ( $orig_confdsid ne $new_confdsid )
{
my $newinst = "slapd-$new_confdsid";
$inf = createInfFromConfig("$instconfigdir/$newinst", $newinst);
if ( ! $inf )
{
$setup->msg($FATAL, 'error_create_inf_from_config',
"$instconfigdir/$newinst");
$setup->doExit(1);
}
$setup->{inf}->{slapd} = $inf->{slapd};
$setup->{inf}->{slapd}->{Instances} = \%instances;
}
$setup->{inf}->{General}->{ConfigDirectoryLdapURL} = "ldap://" . $fqdn . ":". $setup->{inf}->{slapd}->{ServerPort} . "/o=NetscapeRoot";
$dialogmgr->resetDialog();
@dialogs = SetupDialogs->getRegDialogs();
push @dialogs, ConfigDSDialogs->getRegDialogs();
push @dialogs, ASDialogs->getDialogs();
$dialogmgr->addDialog(@dialogs);
$rc = $dialogmgr->run();
if ( $rc )
{
$setup->doExit(1);
}
$adminuid = $setup->{inf}->{General}->{ConfigDirectoryAdminID};
}
# Get the ConfigDS's rootDN password
print("\n==============================================================================\n");
$setup->msg('register_new_confds', $new_confdsid);
$setup->{inf}->{slapd}->{RootDNPwd} =
reg_get_passwd($setup, 'input_rootdn_passwd', $new_confdsid);
if ( ($#admConfKeys >= 0 && ($orig_confdsid ne $new_confdsid)) ||
$#admConfKeys < 0 )
{
@errs = ();
# First, let's register the Configuration Directory itself
while (!createConfigDS($setup->{inf}, \@errs))
{
foreach my $err (@errs)
{
if ( $err eq "suffix_already_exists" )
{
goto out;
}
}
$setup->{inf}->{slapd}->{RootDNPwd} =
reg_get_passwd($setup, 'input_rootdn_passwd', $new_confdsid);
@errs = ();
}
out:
}
# If we don't have it, prompt for the Admin password
if (!$setup->{inf}->{General}->{ConfigDirectoryAdminPwd} ||
"" eq $setup->{inf}->{General}->{ConfigDirectoryAdminPwd})
{
$ans = reg_get_passwd($setup, 'input_admin_passwd', $adminuid);
$setup->{inf}->{General}->{ConfigDirectoryAdminPwd} = $ans;
}
@errs = ();
while (!registerDSWithConfigDS($new_confdsid, \@errs, $setup->{inf}))
{
$setup->msg($WARN, 'error_register_configds', $new_confdsid);
$ans = reg_get_passwd($setup, 'input_admin_passwd', $adminuid);
$setup->{inf}->{General}->{ConfigDirectoryAdminPwd} = $ans;
@errs = ();
}
my $hassubinst = 0;
# Then, register the rest of the Directory Servers, if any
my %subinstances = (); # hash without the Config DS
%instances = %{$setup->{inf}->{slapd}->{Instances}};
foreach my $subconfdir (keys %instances)
{
my @subinsts = @{$instances{$subconfdir}};
foreach my $subinst ( @subinsts )
{
if ( ("$subinst" ne "slapd-" . $new_confdsid) ||
($subconfdir ne $new_confdir) )
{
if ( 0 == $hassubinst )
{
$hassubinst = 1;
print("\n==============================================================================\n");
$setup->msg('register_subds');
}
my $subid = $subinst;
$subid =~ s/slapd-//;
my $passwd =
reg_get_passwd($setup, 'input_rootdn_passwd_sub', $subid, $subid);
# if the password is not given, we don't register the server
next if ( "" eq $passwd || !$passwd );
my $subinf = createInfFromConfig("$subconfdir/$subinst", $subinst);
if ( ! $subinf )
{
$setup->msg($FATAL, 'error_create_inf_from_config',
"$subconfdir/$subinst");
}
else
{
# If we're switching the config DS, we want to force updating the
# PTA plug-in since it's configured for the old config DS.
my $force_pta = 0;
if ( $orig_confdsid ne $new_confdsid ) {
$force_pta = 1;
}
$setup->{inf}->{slapd} = $subinf->{slapd};
$setup->{inf}->{slapd}->{RootDNPwd} = $passwd;
push @{$subinstances{$subconfdir}}, $subinst;
$done = 0;
while ( !$done && !createSubDS($setup->{inf}, \@errs, $force_pta) )
{
$setup->msg($FATAL, @errs);
$passwd = reg_get_passwd($setup, 'input_rootdn_passwd_sub',
$subid, $subid);
if ( "" eq $passwd || !$passwd )
{
$done = 1;
pop @{$subinstances{$subconfdir}};
}
else
{
$setup->{inf}->{slapd}->{RootDNPwd} = $passwd;
}
}
# add the aci that allows the admin user to administer the server
@errs = ();
if (!addConfigACIsToSubDS($setup->{inf}, \@errs)) {
$setup->msg(@errs);
$setup->doExit(1);
}
}
}
}
}
my @subkeys = keys %subinstances;
if ( $#subkeys >= 0 )
{
@errs = ();
if ( !registerScatteredDSWithConfigDS($setup->{inf}, \@errs, \%subinstances) )
{
$setup->msg($FATAL, @errs);
$setup->doExit(1);
}
}
# Configure and register the admin server instance.
# Generate a new inf for the config DS and override
# the old slapd data from the last instance we registered.
$new_confdir = $setup->{inf}->{slapd}->{config_dir};
my $newinst = "slapd-$new_confdsid";
my $inf = createInfFromConfig("$instconfigdir/$newinst", $newinst);
if ( ! $inf )
{
$setup->msg($FATAL, 'error_create_inf_from_config', "$instconfigdir/$newinst");
$setup->doExit(1);
}
$setup->{inf}->{slapd} = $inf->{slapd};
# need these manually set these 2 parameters
$setup->{inf}->{slapd}->{UseExistingMC} = "yes";
$setup->{inf}->{slapd}->{SlapdConfigForMC} = "yes";
if ( !$setup->{reconfigas} )
{
if ( !createAdminServer($setup) )
{
$setup->msg($FATAL, 'error_create_adminserver');
$setup->doExit(1);
}
}
else
{
if ( !reconfigAdminServer($setup) )
{
$setup->msg($FATAL, 'error_reconfig_adminserver');
$setup->doExit(1);
}
}
$setup->msg('end_ds_registration');
$setup->doExit(0);
|