cloud-mu 3.6.10 → 3.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +2 -3
  3. data/Berksfile.lock +11 -14
  4. data/bin/mu-aws-setup +16 -4
  5. data/bin/mu-configure +2 -1
  6. data/cloud-mu.gemspec +3 -3
  7. data/cookbooks/mu-firewall/Berksfile +1 -1
  8. data/cookbooks/mu-firewall/attributes/default.rb +2 -2
  9. data/cookbooks/mu-firewall/metadata.rb +3 -3
  10. data/cookbooks/mu-firewall/recipes/default.rb +11 -2
  11. data/cookbooks/mu-master/Berksfile +1 -1
  12. data/cookbooks/mu-master/attributes/default.rb +14 -1
  13. data/cookbooks/mu-master/files/default/389ds-perl/ASDialogs.pm +173 -0
  14. data/cookbooks/mu-master/files/default/389ds-perl/AdminMigration.pm +569 -0
  15. data/cookbooks/mu-master/files/default/389ds-perl/AdminServer.pm +952 -0
  16. data/cookbooks/mu-master/files/default/389ds-perl/AdminUtil.pm +983 -0
  17. data/cookbooks/mu-master/files/default/389ds-perl/ConfigDSDialogs.pm +449 -0
  18. data/cookbooks/mu-master/files/default/389ds-perl/DSCreate.pm +1551 -0
  19. data/cookbooks/mu-master/files/default/389ds-perl/DSDialogs.pm +233 -0
  20. data/cookbooks/mu-master/files/default/389ds-perl/DSMigration.pm +1175 -0
  21. data/cookbooks/mu-master/files/default/389ds-perl/DSUpdate.pm +534 -0
  22. data/cookbooks/mu-master/files/default/389ds-perl/DSUpdateDialogs.pm +152 -0
  23. data/cookbooks/mu-master/files/default/389ds-perl/DSUtil.pm +1710 -0
  24. data/cookbooks/mu-master/files/default/389ds-perl/Dialog.pm +249 -0
  25. data/cookbooks/mu-master/files/default/389ds-perl/DialogManager.pm +212 -0
  26. data/cookbooks/mu-master/files/default/389ds-perl/FileConn.pm +461 -0
  27. data/cookbooks/mu-master/files/default/389ds-perl/Inf.pm +268 -0
  28. data/cookbooks/mu-master/files/default/389ds-perl/Migration.pm +327 -0
  29. data/cookbooks/mu-master/files/default/389ds-perl/RegDSDialogs.pm +94 -0
  30. data/cookbooks/mu-master/files/default/389ds-perl/Resource.pm +137 -0
  31. data/cookbooks/mu-master/files/default/389ds-perl/Setup.pm +240 -0
  32. data/cookbooks/mu-master/files/default/389ds-perl/SetupDialogs.pm +243 -0
  33. data/cookbooks/mu-master/files/default/389ds-perl/SetupLog.pm +82 -0
  34. data/cookbooks/mu-master/files/default/setCertName.ldif +4 -0
  35. data/cookbooks/mu-master/libraries/mu.rb +2 -2
  36. data/cookbooks/mu-master/metadata.rb +1 -1
  37. data/cookbooks/mu-master/recipes/389ds.rb +71 -32
  38. data/cookbooks/mu-master/recipes/basepackages.rb +5 -0
  39. data/cookbooks/mu-master/recipes/default.rb +16 -5
  40. data/cookbooks/mu-master/recipes/init.rb +36 -3
  41. data/cookbooks/mu-master/recipes/ssl-certs.rb +6 -0
  42. data/cookbooks/mu-master/recipes/sssd.rb +85 -62
  43. data/cookbooks/mu-master/recipes/update_nagios_only.rb +7 -1
  44. data/cookbooks/mu-master/templates/default/389-directory-setup.inf.erb +11 -26
  45. data/cookbooks/mu-master/templates/default/sssd.conf.erb +18 -8
  46. data/cookbooks/mu-tools/files/default/Mu_CA.pem +33 -0
  47. data/cookbooks/mu-tools/metadata.rb +0 -1
  48. data/cookbooks/mu-tools/recipes/set_local_fw.rb +7 -1
  49. data/cookbooks/mu-tools/templates/amazon/sshd_config.erb +5 -1
  50. data/cookbooks/nagios/CHANGELOG.md +679 -0
  51. data/cookbooks/nagios/LICENSE +201 -0
  52. data/cookbooks/nagios/README.md +340 -0
  53. data/cookbooks/nagios/attributes/config.rb +163 -0
  54. data/cookbooks/nagios/attributes/default.rb +204 -0
  55. data/cookbooks/nagios/libraries/base.rb +311 -0
  56. data/cookbooks/nagios/libraries/command.rb +68 -0
  57. data/cookbooks/nagios/libraries/contact.rb +229 -0
  58. data/cookbooks/nagios/libraries/contactgroup.rb +111 -0
  59. data/cookbooks/{firewall/recipes/disable_firewall.rb → nagios/libraries/custom_option.rb} +20 -7
  60. data/cookbooks/nagios/libraries/data_bag_helper.rb +23 -0
  61. data/cookbooks/nagios/libraries/default.rb +90 -0
  62. data/cookbooks/nagios/libraries/helpers.rb +229 -0
  63. data/cookbooks/nagios/libraries/host.rb +410 -0
  64. data/cookbooks/nagios/libraries/hostdependency.rb +178 -0
  65. data/cookbooks/nagios/libraries/hostescalation.rb +170 -0
  66. data/cookbooks/nagios/libraries/hostgroup.rb +117 -0
  67. data/cookbooks/nagios/libraries/nagios.rb +277 -0
  68. data/cookbooks/nagios/libraries/resource.rb +59 -0
  69. data/cookbooks/nagios/libraries/service.rb +449 -0
  70. data/cookbooks/nagios/libraries/servicedependency.rb +213 -0
  71. data/cookbooks/nagios/libraries/serviceescalation.rb +193 -0
  72. data/cookbooks/nagios/libraries/servicegroup.rb +142 -0
  73. data/cookbooks/nagios/libraries/timeperiod.rb +159 -0
  74. data/cookbooks/nagios/libraries/users_helper.rb +54 -0
  75. data/cookbooks/nagios/metadata.json +44 -0
  76. data/cookbooks/nagios/metadata.rb +22 -0
  77. data/cookbooks/nagios/recipes/_load_databag_config.rb +153 -0
  78. data/cookbooks/nagios/recipes/_load_default_config.rb +241 -0
  79. data/cookbooks/nagios/recipes/apache.rb +114 -0
  80. data/cookbooks/nagios/recipes/default.rb +41 -0
  81. data/cookbooks/nagios/recipes/nginx.rb +114 -0
  82. data/cookbooks/nagios/recipes/pagerduty.rb +95 -0
  83. data/cookbooks/nagios/recipes/server.rb +182 -0
  84. data/cookbooks/nagios/recipes/server_package.rb +85 -0
  85. data/cookbooks/nagios/recipes/server_source.rb +137 -0
  86. data/cookbooks/nagios/resources/command.rb +34 -0
  87. data/cookbooks/nagios/resources/conf.rb +52 -0
  88. data/cookbooks/nagios/resources/contact.rb +34 -0
  89. data/cookbooks/nagios/resources/contactgroup.rb +35 -0
  90. data/cookbooks/nagios/resources/host.rb +35 -0
  91. data/cookbooks/nagios/resources/hostdependency.rb +35 -0
  92. data/cookbooks/nagios/resources/hostescalation.rb +36 -0
  93. data/cookbooks/nagios/resources/hostgroup.rb +35 -0
  94. data/cookbooks/nagios/resources/resource.rb +34 -0
  95. data/cookbooks/nagios/resources/service.rb +35 -0
  96. data/cookbooks/nagios/resources/servicedependency.rb +35 -0
  97. data/cookbooks/nagios/resources/serviceescalation.rb +35 -0
  98. data/cookbooks/nagios/resources/servicegroup.rb +35 -0
  99. data/cookbooks/nagios/resources/timeperiod.rb +35 -0
  100. data/cookbooks/nagios/templates/apache2.conf.erb +102 -0
  101. data/cookbooks/nagios/templates/cgi.cfg.erb +266 -0
  102. data/cookbooks/nagios/templates/commands.cfg.erb +13 -0
  103. data/cookbooks/nagios/templates/contacts.cfg.erb +37 -0
  104. data/cookbooks/nagios/templates/hostgroups.cfg.erb +25 -0
  105. data/cookbooks/nagios/templates/hosts.cfg.erb +15 -0
  106. data/cookbooks/nagios/templates/htpasswd.users.erb +6 -0
  107. data/cookbooks/nagios/templates/nagios.cfg.erb +22 -0
  108. data/cookbooks/nagios/templates/nginx.conf.erb +80 -0
  109. data/cookbooks/nagios/templates/pagerduty.cgi.erb +185 -0
  110. data/cookbooks/nagios/templates/resource.cfg.erb +27 -0
  111. data/cookbooks/nagios/templates/servicedependencies.cfg.erb +15 -0
  112. data/cookbooks/nagios/templates/servicegroups.cfg.erb +14 -0
  113. data/cookbooks/nagios/templates/services.cfg.erb +14 -0
  114. data/cookbooks/nagios/templates/spawn-fcgi.erb +10 -0
  115. data/cookbooks/nagios/templates/templates.cfg.erb +31 -0
  116. data/cookbooks/nagios/templates/timeperiods.cfg.erb +13 -0
  117. data/extras/platform_berksfile_base +3 -3
  118. data/extras/python_rpm/build.sh +4 -4
  119. data/extras/python_rpm/muthon.spec +2 -4
  120. data/extras/vault_tools/export_vaults.sh +11 -1
  121. data/install/installer +1 -1
  122. data/modules/mu/kittens.rb +27523 -0
  123. data/modules/mu/master/ldap.rb +48 -31
  124. data/modules/mu/master.rb +69 -0
  125. data/modules/mu/mu.yaml.rb +351 -0
  126. data/modules/mu/providers/aws/firewall_rule.rb +3 -1
  127. data/modules/mu/providers/aws.rb +11 -5
  128. data/modules/mu.rb +5 -4
  129. metadata +99 -68
  130. data/cookbooks/firewall/CHANGELOG.md +0 -488
  131. data/cookbooks/firewall/LICENSE +0 -202
  132. data/cookbooks/firewall/README.md +0 -366
  133. data/cookbooks/firewall/TODO.md +0 -6
  134. data/cookbooks/firewall/attributes/default.rb +0 -5
  135. data/cookbooks/firewall/attributes/firewalld.rb +0 -8
  136. data/cookbooks/firewall/attributes/iptables.rb +0 -17
  137. data/cookbooks/firewall/attributes/ufw.rb +0 -12
  138. data/cookbooks/firewall/attributes/windows.rb +0 -8
  139. data/cookbooks/firewall/libraries/helpers.rb +0 -105
  140. data/cookbooks/firewall/libraries/helpers_firewalld.rb +0 -116
  141. data/cookbooks/firewall/libraries/helpers_firewalld_dbus.rb +0 -72
  142. data/cookbooks/firewall/libraries/helpers_iptables.rb +0 -112
  143. data/cookbooks/firewall/libraries/helpers_nftables.rb +0 -170
  144. data/cookbooks/firewall/libraries/helpers_ufw.rb +0 -142
  145. data/cookbooks/firewall/libraries/helpers_windows.rb +0 -129
  146. data/cookbooks/firewall/libraries/provider_firewall_firewalld.rb +0 -179
  147. data/cookbooks/firewall/libraries/provider_firewall_iptables.rb +0 -171
  148. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu.rb +0 -200
  149. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu1404.rb +0 -200
  150. data/cookbooks/firewall/libraries/provider_firewall_rule.rb +0 -34
  151. data/cookbooks/firewall/libraries/provider_firewall_ufw.rb +0 -138
  152. data/cookbooks/firewall/libraries/provider_firewall_windows.rb +0 -126
  153. data/cookbooks/firewall/libraries/resource_firewall.rb +0 -26
  154. data/cookbooks/firewall/libraries/resource_firewall_rule.rb +0 -52
  155. data/cookbooks/firewall/metadata.json +0 -40
  156. data/cookbooks/firewall/metadata.rb +0 -15
  157. data/cookbooks/firewall/recipes/default.rb +0 -76
  158. data/cookbooks/firewall/recipes/firewalld.rb +0 -87
  159. data/cookbooks/firewall/resources/firewalld.rb +0 -28
  160. data/cookbooks/firewall/resources/firewalld_config.rb +0 -39
  161. data/cookbooks/firewall/resources/firewalld_helpers.rb +0 -106
  162. data/cookbooks/firewall/resources/firewalld_icmptype.rb +0 -88
  163. data/cookbooks/firewall/resources/firewalld_ipset.rb +0 -104
  164. data/cookbooks/firewall/resources/firewalld_policy.rb +0 -115
  165. data/cookbooks/firewall/resources/firewalld_service.rb +0 -98
  166. data/cookbooks/firewall/resources/firewalld_zone.rb +0 -118
  167. data/cookbooks/firewall/resources/nftables.rb +0 -71
  168. data/cookbooks/firewall/resources/nftables_rule.rb +0 -113
  169. data/cookbooks/firewall/templates/default/ufw/default.erb +0 -13
  170. /data/cookbooks/{firewall → nagios}/chefignore +0 -0
  171. /data/cookbooks/{firewall → nagios}/renovate.json +0 -0
@@ -0,0 +1,983 @@
1
+ # BEGIN COPYRIGHT BLOCK
2
+ # This Program is free software; you can redistribute it and/or modify it under
3
+ # the terms of the GNU General Public License as published by the Free Software
4
+ # Foundation; version 2 of the License.
5
+ #
6
+ # This Program is distributed in the hope that it will be useful, but WITHOUT
7
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9
+ #
10
+ # You should have received a copy of the GNU General Public License along with
11
+ # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
12
+ # Place, Suite 330, Boston, MA 02111-1307 USA.
13
+ #
14
+ # Copyright (C) 2007 Red Hat, Inc.
15
+ # All rights reserved.
16
+ # END COPYRIGHT BLOCK
17
+ #
18
+
19
+ package AdminUtil;
20
+ require Exporter;
21
+ @ISA = qw(Exporter);
22
+ @EXPORT = qw(getAdmConf getConfigDSConn createConfigDS createSubDS
23
+ updateAdmConf updateAdmpw updateLocalConf importCACert
24
+ getLocalConfigDS getPset registerDSWithConfigDS
25
+ registerManyDSWithConfigDS createSubDSNoConn
26
+ registerScatteredDSWithConfigDS getInfs getInfsVal
27
+ unregisterDSWithConfigDS isConfigDS addConfigACIsToSubDS);
28
+ @EXPORT_OK = qw(getAdmConf getConfigDSConn createConfigDS createSubDS
29
+ updateAdmConf updateAdmpw updateLocalConf importCACert
30
+ getLocalConfigDS getPset registerDSWithConfigDS
31
+ registerManyDSWithConfigDS createSubDSNoConn
32
+ registerScatteredDSWithConfigDS getInfs getInfsVal
33
+ unregisterDSWithConfigDS isConfigDS addConfigACIsToSubDS);
34
+
35
+ # load perldap
36
+ use Mozilla::LDAP::Conn;
37
+ use Mozilla::LDAP::Utils qw(normalizeDN);
38
+ use Mozilla::LDAP::API qw(:constant ldap_url_parse ldap_explode_dn);
39
+ use Mozilla::LDAP::LDIF qw(enlist_values);
40
+
41
+ use DSUtil;
42
+ use Inf;
43
+ use FileConn;
44
+
45
+ use strict;
46
+
47
+ # get the adminutil client configuration (adm.conf)
48
+ # the file is in LDIF format
49
+ # just return as a hash ref for easy key/value access
50
+ # single valued attributes will have a single string value
51
+ # multi valued attributes will have an array ref value
52
+ sub getAdmConf {
53
+ my $dir = shift || "/etc/dirsrv/admin-serv";
54
+ my $ret = {};
55
+
56
+ my $fname = "$dir/adm.conf";
57
+ if (-f $fname) {
58
+ open( ADMCONF, "$fname" ) || die "Can't open $fname: $!";
59
+ my $in = Mozilla::LDAP::LDIF->new(*ADMCONF, \&read_file_URL_or_name);
60
+ my @records = $in->get(undef); # read to end of file
61
+ close(ADMCONF);
62
+ @records = enlist_values(@records);
63
+ for (@records) { # there should only be 1 record
64
+ my %h = @{$_}; # cast $_ to an array and use that to init hash
65
+ $ret = \%h;
66
+ }
67
+ $ret->{configdir} = $dir;
68
+ }
69
+
70
+ return $ret;
71
+ }
72
+
73
+ # pset info is from the local.conf file, also in LDIF format
74
+ sub getPset {
75
+ my $admConf = shift;
76
+ my $configdir;
77
+ if ($admConf) {
78
+ if (ref($admConf)) {
79
+ $configdir = $admConf->{configdir} || "/etc/dirsrv/admin-serv";
80
+ } else {
81
+ $configdir = $admConf || "/etc/dirsrv/admin-serv";
82
+ }
83
+ }
84
+ my $ret = {};
85
+ my $fname = "$configdir/local.conf";
86
+ if (-f $fname) {
87
+ open( LOCALCONF, "$fname" ) || die "Can't open $fname: $!";
88
+ my $in = new Mozilla::LDAP::LDIF(*LOCALCONF);
89
+ while (my $ent = readOneEntry $in) {
90
+ foreach my $attr (keys %{$ent}) {
91
+ my @vals = $ent->getValues($attr);
92
+ if (@vals > 1) {
93
+ $ret->{$attr} = \@vals; # value is array ref
94
+ } else {
95
+ $ret->{$attr} = $vals[0]; # value is single string
96
+ }
97
+ }
98
+ }
99
+ close LOCALCONF;
100
+ }
101
+
102
+ return $ret;
103
+ }
104
+
105
+ sub getAdmpw {
106
+ my $admConf = shift;
107
+ my $configdir;
108
+ if ($admConf) {
109
+ if (ref($admConf)) {
110
+ $configdir = $admConf->{configdir} || "/etc/dirsrv/admin-serv";
111
+ } else {
112
+ $configdir = $admConf || "/etc/dirsrv/admin-serv";
113
+ }
114
+ }
115
+ my $ret = {};
116
+ my $fname = "$configdir/admpw";
117
+ if (-f $fname) {
118
+ open( ADMPW, "$fname" ) || die "Can't open $fname: $!";
119
+ while (<ADMPW>) {
120
+ chop;
121
+ ($ret->{ServerAdminID}, $ret->{ServerAdminPwd}) = split /:/;
122
+ last;
123
+ }
124
+ close ADMPW;
125
+ }
126
+
127
+ return $ret;
128
+ }
129
+
130
+ sub getCertDir {
131
+ my $configdir = shift;
132
+ # if configdir already ends in admin-serv, just use it
133
+ if ($configdir =~ /admin-serv$/) {
134
+ return $configdir;
135
+ }
136
+ # otherwise, assume configdir is the directory containing admin-serv
137
+ return "$configdir/admin-serv";
138
+ }
139
+
140
+ sub isConfigDS {
141
+ my $inst = shift;
142
+ my $configdir = shift;
143
+ my $admConf = getAdmConf ($configdir);
144
+ my $ldapstart = $admConf->{ldapStart};
145
+ my $expected = $inst . "/start-slapd";
146
+ if ( "$ldapstart" eq "$expected" ) {
147
+ return 1;
148
+ } else {
149
+ return 0;
150
+ }
151
+ }
152
+
153
+ sub getConfigDSConn {
154
+ my $url = shift;
155
+ my $id = shift;
156
+ my $pwd = shift;
157
+ my $configdir = shift;
158
+ my $errs = shift; # for output errs - an array ref
159
+ my $certdir;
160
+ my $errstr = "Success";
161
+ my $conn;
162
+
163
+ if (!$url or !$id) {
164
+ my $admConf = getAdmConf($configdir);
165
+ $url = $url || $admConf->{ldapurl};
166
+ $id = $id || $admConf->{userdn};
167
+ }
168
+
169
+ my $h = ldap_url_parse($url);
170
+ my $host = $h->{host};
171
+ my $port = $h->{port};
172
+ my $basedn = $h->{dn};
173
+
174
+ # If PerLDAP was build using OpenLDAP, we must check the URL scheme
175
+ # to see if we're using LDAPS. If MozLDAP is being used, we need
176
+ # to check for the secure option.
177
+ if ($h->{scheme}) {
178
+ if ($h->{scheme} eq "ldaps") {
179
+ $certdir = getCertDir($configdir);
180
+ }
181
+ } elsif ($h->{options} & LDAP_URL_OPT_SECURE) {
182
+ $certdir = getCertDir($configdir);
183
+ }
184
+
185
+ if ($id =~ /=/){
186
+ #
187
+ # We have a bind DN so try it first, as anonymous access could be
188
+ # disabled on the config DS.
189
+ #
190
+ debug(3, "Attempting connection to " . $h->{host} . ":" . $h->{port} .
191
+ " bind DN ($id) certdir $certdir configdir $configdir\n");
192
+ $conn = new Mozilla::LDAP::Conn($h->{host}, $h->{port}, $id, $pwd, $certdir);
193
+ if ($conn) {
194
+ $errstr = $conn->getErrorString();
195
+ }
196
+ if (!$conn or ($errstr ne "Success")) {
197
+ if ($conn) {
198
+ $conn->close();
199
+ $conn = 0;
200
+ }
201
+ if ($certdir) {
202
+ push @{$errs}, 'configds_open_error_ssl', $url,
203
+ ($errstr eq "Success") ? 'unknown error' : $errstr,
204
+ $h->{host}, $h->{port}, $h->{host}, $h->{host}, $certdir, $h->{host}, $h->{port};
205
+ } else {
206
+ push @{$errs}, 'configds_open_error', $url,
207
+ ($errstr eq "Success") ? 'unknown error' : $errstr,
208
+ $h->{host}, $h->{port}, $h->{host}, $h->{host}, $h->{host}, $h->{port};
209
+ }
210
+ return $conn;
211
+ }
212
+ } else {
213
+ #
214
+ # We must attempt an anonymous bind to find the entry
215
+ #
216
+ debug(3, "Attempting connection to " . $h->{host} . ":" . $h->{port} .
217
+ " bind DN(anonymous) certdir $certdir configdir $configdir\n");
218
+ $conn = new Mozilla::LDAP::Conn($h->{host}, $h->{port}, "", "", $certdir);
219
+ if ($conn) {
220
+ $errstr = $conn->getErrorString();
221
+ }
222
+ if (!$conn or ($errstr ne "Success")) {
223
+ if ($conn) {
224
+ $conn->close();
225
+ $conn = 0;
226
+ }
227
+ if ($certdir) {
228
+ push @{$errs}, 'configds_open_error_ssl', $url,
229
+ ($errstr eq "Success") ? 'unknown error' : $errstr,
230
+ $h->{host}, $h->{port}, $h->{host}, $h->{host}, $certdir, $h->{host}, $h->{port};
231
+ } else {
232
+ push @{$errs}, 'configds_open_error', $url,
233
+ ($errstr eq "Success") ? 'unknown error' : $errstr,
234
+ $h->{host}, $h->{port}, $h->{host}, $h->{host}, $h->{host}, $h->{port};
235
+ }
236
+ return $conn;
237
+ }
238
+
239
+ # Search for the entry - we assume it starts with uid
240
+ my $ent = $conn->search($h->{dn}, "sub", "(uid=$id)", 1, 'dn');
241
+ $errstr = $conn->getErrorString();
242
+ if (!$ent or ($errstr ne "Success")) {
243
+ $conn->close();
244
+ $conn = 0;
245
+ push @{$errs}, 'configds_finddn_error', $id, $url, (($errstr eq "Success") ? 'unknown error' : $errstr);
246
+ return $conn;
247
+ }
248
+ # Now bind as the entry
249
+ $id = $ent->getDN();
250
+ if (!$conn->simpleAuth($id, $pwd)) {
251
+ $errstr = $conn->getErrorString();
252
+ $conn->close();
253
+ $conn = 0;
254
+ if ($errstr =~ /constraint/i) {
255
+ push @{$errs}, 'configds_bindretry_error', $id, $url;
256
+ } else {
257
+ push @{$errs}, 'configds_bind_error', $id, $url, (($errstr eq "Success") ? 'unknown error' : $errstr);
258
+ }
259
+ return $conn;
260
+ }
261
+ }
262
+ # store the binddn and password for later use
263
+ $conn->setDefaultRebindProc($id, $pwd, LDAP_AUTH_SIMPLE);
264
+ $conn->{adminbinddn} = $id;
265
+
266
+ return $conn;
267
+ }
268
+
269
+ sub verifyAdminDomain {
270
+ my $conn = shift;
271
+ my $url = shift;
272
+ my $domain = shift;
273
+
274
+ my $h = ldap_url_parse($url);
275
+ my $dn = "ou=$domain, $h->{dn}";
276
+ my $ent = $conn->search($dn, "base", "(objectclass=*)", 1, 'dn');
277
+ my $errstr = $conn->getErrorString();
278
+ if (!$ent or ($errstr ne "Success")) {
279
+ return ('configds_no_admindomain', $domain, $h->{dn}, (($errstr eq "Success") ? 'unknown error' : $errstr));
280
+ }
281
+ return ();
282
+ }
283
+
284
+ # Take the slapd server instance specified in the slapd section of the given inf
285
+ # and make it into a configuration directory server
286
+ sub createConfigDS {
287
+ my $inf = shift;
288
+ my $errs = shift;
289
+
290
+ # open a connection to the directory server
291
+ my $conn = new Mozilla::LDAP::Conn($inf->{General}->{FullMachineName},
292
+ $inf->{slapd}->{ServerPort},
293
+ $inf->{slapd}->{RootDN},
294
+ $inf->{slapd}->{RootDNPwd},
295
+ $inf->{General}->{certdir});
296
+ my $errstr;
297
+ if ($conn) {
298
+ $errstr = $conn->getErrorString();
299
+ }
300
+ if (!$conn or ($errstr ne "Success")) {
301
+ @{$errs} = ('error_connection_failed', $inf->{General}->{FullMachineName},
302
+ $inf->{slapd}->{ServerPort}, $inf->{slapd}->{RootDN},
303
+ ($conn ? $errstr : "unknown"));
304
+ if ($conn) {
305
+ $conn->close();
306
+ }
307
+ return 0;
308
+ }
309
+
310
+ # add the NetscapeRoot suffix
311
+ @{$errs} = addSuffix($conn, "o=NetscapeRoot", "NetscapeRoot");
312
+ if (@{$errs}) {
313
+ $conn->close();
314
+ return 0;
315
+ }
316
+
317
+ # add the o=NetscapeRoot tree using the mapper and ldif templates
318
+ my @ldiffiles = ('/usr/share/dirsrv/data/01nsroot.ldif.tmpl',
319
+ '/usr/share/dirsrv/data/02globalpreferences.ldif.tmpl',
320
+ '/usr/share/dirsrv/data/12dsconfig.mod.tmpl',
321
+ '/usr/share/dirsrv/data/13dsschema.mod.tmpl',
322
+ '/usr/share/dirsrv/data/14dsmonitor.mod.tmpl',
323
+ '/usr/share/dirsrv/data/16dssuffixadmin.mod.tmpl'
324
+ );
325
+ my @infs = getInfs("slapd", "admin", "setup");
326
+ my $mapper = new Inf("/usr/share/dirsrv/inf/configdsroot.map");
327
+
328
+ $mapper = process_maptbl($mapper, $errs, $inf, @infs);
329
+ if (!$mapper or @{$errs}) {
330
+ $conn->close();
331
+ if (!@{$errs}) {
332
+ @{$errs} = ('error_creating_configds_maptbl');
333
+ }
334
+ return 0;
335
+ }
336
+
337
+ getMappedEntries($mapper, \@ldiffiles, $errs, \&check_and_add_entry,
338
+ [$conn]);
339
+
340
+ $conn->close();
341
+ return @{$errs} ? 0 : 1;
342
+ }
343
+
344
+ sub internalCreateSubDS {
345
+ my $conn = shift;
346
+ my $inf = shift;
347
+ my $errs = shift;
348
+ my $force_pta = shift;
349
+ my @additionalLdifFiles = @_;
350
+
351
+ # add the o=NetscapeRoot tree using the mapper and ldif templates
352
+ my @ldiffiles = ('/usr/share/dirsrv/data/12dsconfig.mod.tmpl',
353
+ '/usr/share/dirsrv/data/13dsschema.mod.tmpl',
354
+ '/usr/share/dirsrv/data/14dsmonitor.mod.tmpl'
355
+ );
356
+ push @ldiffiles, @additionalLdifFiles;
357
+
358
+ # If PTA is not enabled yet, we need to enable and configure it
359
+ my $ent = $conn->search("cn=Pass Through Authentication,cn=plugins,cn=config", "base", "(objectclass=*)", 0, 'nsslapd-pluginenabled');
360
+ my $errstr = $conn->getErrorString();
361
+ if (!$ent or ($errstr ne "Success")) {
362
+ $conn->close();
363
+ @{$errs} = ('error_finding_pta', (($errstr eq "Success") ? 'unknown error' : $errstr));
364
+ return 0;
365
+ }
366
+
367
+ if (($ent->hasValue("nsslapd-pluginenabled", "off", 1)) || $force_pta == 1) {
368
+ push @ldiffiles, '/usr/share/dirsrv/data/15dspta.mod.tmpl';
369
+ }
370
+
371
+ my @infs = getInfs("slapd", "admin", "setup");
372
+ my $mapper = new Inf("/usr/share/dirsrv/inf/dirserver.map");
373
+
374
+ $mapper = process_maptbl($mapper, $errs, $inf, @infs);
375
+ if (!$mapper or @{$errs}) {
376
+ $conn->close();
377
+ if (!@{$errs}) {
378
+ @{$errs} = ('error_creating_configds_maptbl');
379
+ }
380
+ return 0;
381
+ }
382
+
383
+ getMappedEntries($mapper, \@ldiffiles, $errs, \&check_and_add_entry,
384
+ [$conn]);
385
+
386
+ $conn->close();
387
+ return @{$errs} ? 0 : 1;
388
+ }
389
+
390
+ # Take the slapd server instance specified in the slapd section of the given inf
391
+ # and make it into a subordinative directory server
392
+ # (no o=netscaperoot, with PTA setup)
393
+ sub createSubDS {
394
+ my $inf = shift;
395
+ my $errs = shift;
396
+ my $force_pta = shift;
397
+
398
+ # open a connection to the directory server
399
+ my $conn = new Mozilla::LDAP::Conn($inf->{General}->{FullMachineName},
400
+ $inf->{slapd}->{ServerPort},
401
+ $inf->{slapd}->{RootDN},
402
+ $inf->{slapd}->{RootDNPwd},
403
+ $inf->{General}->{certdir});
404
+ if (!$conn) {
405
+ @{$errs} = ('error_connection_failed', $inf->{General}->{FullMachineName},
406
+ $inf->{slapd}->{ServerPort}, $inf->{slapd}->{RootDN},
407
+ "unknown");
408
+ return 0;
409
+ }
410
+
411
+ return internalCreateSubDS($conn, $inf, $errs, $force_pta, '/usr/share/dirsrv/data/16dssuffixadmin.mod.tmpl');
412
+ }
413
+
414
+ # same as createSubDS but works directly on the dse.ldif file itself
415
+ # this is suitable for use when creating a new DS instance on the local
416
+ # machine,
417
+ sub createSubDSNoConn {
418
+ my $inf = shift;
419
+ my $errs = shift;
420
+ # $ENV{DS_CONFIG_DIR} is set in ds instance creation
421
+ my $dsconfdir = $ENV{DS_CONFIG_DIR} ||
422
+ "/etc/dirsrv/slapd-" . $inf->{slapd}->{ServerIdentifier};
423
+
424
+ my $dseldif = "$dsconfdir/dse.ldif";
425
+ my $conn = new FileConn($dseldif);
426
+ if (!$conn) {
427
+ @{$errs} = ('error_opening_dseldif', $dseldif, $!);
428
+ return 0;
429
+ }
430
+
431
+ return internalCreateSubDS($conn, $inf, $errs, 0);
432
+ }
433
+
434
+ sub addConfigACIsToSubDS {
435
+ my $inf = shift;
436
+ my $errs = shift;
437
+
438
+ # open a connection to the directory server
439
+ my $conn = new Mozilla::LDAP::Conn($inf->{General}->{FullMachineName},
440
+ $inf->{slapd}->{ServerPort},
441
+ $inf->{slapd}->{RootDN},
442
+ $inf->{slapd}->{RootDNPwd},
443
+ $inf->{General}->{certdir});
444
+ if (!$conn) {
445
+ @{$errs} = ('error_connection_failed', $inf->{General}->{FullMachineName},
446
+ $inf->{slapd}->{ServerPort}, $inf->{slapd}->{RootDN},
447
+ "unknown");
448
+ return 0;
449
+ }
450
+
451
+ my @ldiffiles = ('/usr/share/dirsrv/data/16dssuffixadmin.mod.tmpl');
452
+ my @infs = getInfs("slapd", "admin", "setup");
453
+ my $mapper = new Inf("/usr/share/dirsrv/inf/dssuffixadmin.map");
454
+
455
+ $mapper = process_maptbl($mapper, $errs, $inf, @infs);
456
+ if (!$mapper or @{$errs}) {
457
+ $conn->close();
458
+ if (!@{$errs}) {
459
+ @{$errs} = ('error_creating_configds_maptbl');
460
+ }
461
+ return 0;
462
+ }
463
+
464
+ getMappedEntries($mapper, \@ldiffiles, $errs, \&check_and_add_entry,
465
+ [$conn]);
466
+
467
+ $conn->close();
468
+ return @{$errs} ? 0 : 1;
469
+ }
470
+
471
+ sub updateAdmConf {
472
+ my $params = shift; # hashref
473
+ my $configdir = shift || "/etc/dirsrv/admin-serv";
474
+ my $admConf = getAdmConf($configdir);
475
+ my $isnew = 0;
476
+ if (!$admConf || !%{$admConf}) {
477
+ $isnew = 1; # create it
478
+ }
479
+
480
+ # update values in admConf with the passed in params
481
+ while (my ($key,$val) = each %{$params}) {
482
+ $admConf->{$key} = $val;
483
+ }
484
+
485
+ # write it out
486
+ my $filename = "$configdir/adm.conf";
487
+ delete $admConf->{configdir}; # don't write this
488
+ open(ADMCONF, "> $filename") || die "Can't write $filename: $!";
489
+ while (my ($key,$val) = each %{$admConf}) {
490
+ next if (!defined($key) or !defined($val));
491
+ if (ref($val)) {
492
+ for my $vv (@{$val}) {
493
+ print ADMCONF "$key: $vv\n";
494
+ }
495
+ } else {
496
+ print ADMCONF "$key: $val\n";
497
+ }
498
+ }
499
+ close(ADMCONF);
500
+
501
+ if ($isnew) {
502
+ my $uid = getpwnam $admConf->{sysuser};
503
+ chmod 0600, "$filename";
504
+ chown $uid, -1, "$filename";
505
+ }
506
+
507
+ return 1;
508
+ }
509
+
510
+ sub updateAdmpw {
511
+ my $userid = shift;
512
+ my $pwd = shift;
513
+ my $configdir = shift || "/etc/dirsrv/admin-serv";
514
+ my $filename = "$configdir/admpw";
515
+ my $isnew = 0;
516
+ if (! -f $filename) {
517
+ $isnew = 1;
518
+ }
519
+
520
+ $pwd = getHashedPassword($pwd, "SHA");
521
+
522
+ open(ADMPW, ">$filename") or die "Error: can't write file $filename: $!";
523
+ print ADMPW "$userid:$pwd\n";
524
+ close(ADMPW);
525
+
526
+ if ($isnew) {
527
+ my $admConf = getAdmConf($configdir);
528
+ my $uid = getpwnam $admConf->{sysuser};
529
+ chmod 0600, "$filename";
530
+ chown $uid, -1, "$filename";
531
+ }
532
+
533
+ return 1;
534
+ }
535
+
536
+ # this is the prefix used for attribute names in the pset file
537
+ sub getAttrNamePrefix {
538
+ my $dn = shift;
539
+ my $rootdn = shift; # the sie DN
540
+
541
+ my @dnList = ldap_explode_dn($dn, 1);
542
+ my @rootdnList = ldap_explode_dn($rootdn, 1);
543
+
544
+ my $attrLen = scalar(@dnList) - scalar(@rootdnList);
545
+ my $attrName = "";
546
+ while ($attrLen > 0) {
547
+ if ($attrLen == 1) {
548
+ $attrName .= $dnList[0];
549
+ } else {
550
+ $attrName .= $dnList[$attrLen-1] . ".";
551
+ }
552
+ $attrLen--;
553
+ }
554
+
555
+ return $attrName;
556
+ }
557
+
558
+ # these are attributes not written to the pset
559
+ my %nopsetattrs = (
560
+ cn => 'cn',
561
+ aci => 'aci'
562
+ );
563
+
564
+ # This is only used during setup.
565
+ # When the admin server is running, changes
566
+ # occur online, and the file contains a cache
567
+ # of those changes
568
+ # but during setup, we need to create the
569
+ # local.conf as a bootstrap for the server
570
+ sub updateLocalConf {
571
+ my $entry = shift;
572
+ my $siedn = shift;
573
+ my $localfh = shift;
574
+
575
+ # convert entry to pset format
576
+ my $prefix = getAttrNamePrefix($entry->getDN(), $siedn);
577
+
578
+ # write values to file
579
+ foreach my $attr (keys %{$entry}) {
580
+ next if $nopsetattrs{lc($attr)};
581
+ my $attrName;
582
+ if ($prefix) {
583
+ $attrName = $prefix . "." . $attr;
584
+ } else {
585
+ $attrName = $attr;
586
+ }
587
+ foreach my $val ($entry->getValues($attr)) {
588
+ debug(3, "updateLocalConf: writing $attrName: $val\n");
589
+ print $localfh "$attrName: $val\n";
590
+ }
591
+ }
592
+
593
+ return 1;
594
+ }
595
+
596
+ sub importCACert {
597
+ my $securitydir = shift;
598
+ my $cacert = shift; # may be a file or the actual cert in ascii/pem format
599
+ my @errs = (); # return
600
+
601
+ if (! -d $securitydir) {
602
+ @errs = ('securitydir_not_exist', $securitydir);
603
+ return @errs;
604
+ }
605
+
606
+ if (! -w $securitydir) {
607
+ @errs = ('securitydir_not_writable', $securitydir);
608
+ return @errs;
609
+ }
610
+
611
+ # see if "CA certificate" already exists
612
+ my $output = `certutil -L -d \"$securitydir\" 2>&1`;
613
+ if ($output =~ /CA certificate/) {
614
+ @errs = ('cacert_already_exists', $securitydir);
615
+ return @errs;
616
+ }
617
+
618
+ if ($cacert =~ /^-----BEGIN CERTIFICATE-----/) {
619
+ $! = 0;
620
+ $? = 0; # clear error indicators
621
+ if (!open(CERTUTIL, "|certutil -A -d \"$securitydir\" -a -t CT,, -n \"CA certificate\"")) {
622
+ @errs = ("error_running_certutil", $!);
623
+ return @errs;
624
+ }
625
+ print CERTUTIL $cacert, "\n";
626
+ close(CERTUTIL);
627
+ if ($?) {
628
+ @errs = ('error_return_certutil', $?, $!);
629
+ return @errs;
630
+ }
631
+ } elsif (! -f $cacert) {
632
+ @errs = ('cacertfile_not_found', $cacert);
633
+ return @errs;
634
+ } else {
635
+ $! = 0;
636
+ $? = 0; # clear error indicators
637
+ $output = `certutil -A -d \"$securitydir\" -a -t CT,, -n \"CA certificate\" -i \"$cacert\" 2>&1`;
638
+ if ($?) {
639
+ @errs = ('error_return2_certutil', $?, $!, $output);
640
+ return @errs;
641
+ }
642
+ }
643
+
644
+ return @errs;
645
+ }
646
+
647
+ # if the config ds is local to this machine, return
648
+ # the instance name (e.g. "localhost" for slapd-localhost)
649
+ # if not, return null
650
+ sub getLocalConfigDS {
651
+ my $configdir = shift;
652
+ my $admConf = getAdmConf($configdir);
653
+ my $ldapStart = $admConf->{ldapStart};
654
+ my $inst;
655
+ if (!$ldapStart) {
656
+ return $inst; # empty
657
+ }
658
+
659
+ if ($ldapStart =~ /slapd-(.+?)\//) {
660
+ $inst = $1;
661
+ } else {
662
+ # The instance name might not prefixed with "slapd-"
663
+ my @parts = split / /, $ldapStart;
664
+ if ($#parts > 0){
665
+ $inst = $parts[1];
666
+ }
667
+ }
668
+
669
+ return $inst;
670
+ }
671
+
672
+ # most admin server CGIs only use PASSWORD and USERDN
673
+ sub getAuthCredentials {
674
+ if ($AdminUtil::USER) {
675
+ return ($AdminUtil::USER, $AdminUtil::PASSWORD,
676
+ $AdminUtil::AUTHORIZATION, $AdminUtil::USERDN,
677
+ $AdminUtil::SIEPWD);
678
+ }
679
+
680
+ if (!defined($ENV{PASSWORD_PIPE})) {
681
+ return ();
682
+ }
683
+
684
+ my $fh;
685
+ if (fileno(STDIN) == $ENV{PASSWORD_PIPE}) {
686
+ $fh = \*STDIN;
687
+ } else {
688
+ open(INPUT, "<&=$ENV{PASSWORD_PIPE}") or
689
+ die "Error: could not open PASSWORD_PIPE $ENV{PASSWORD_PIPE}: $!";
690
+ $fh = \*INPUT;
691
+ }
692
+ while (<$fh>) {
693
+ if (/^User: (.*)$/) {
694
+ $AdminUtil::USER = $1;
695
+ }
696
+ if (/^Password: (.*)$/) {
697
+ $AdminUtil::PASSWORD = $1;
698
+ }
699
+ if (/^Authorization: (.*)$/) {
700
+ $AdminUtil::AUTHORIZATION = $1;
701
+ }
702
+ if (/^UserDN: (.*)$/) {
703
+ $AdminUtil::USERDN = $1;
704
+ }
705
+ if (/^SIEPWD: (.*)$/) {
706
+ $AdminUtil::SIEPWD = $1;
707
+ }
708
+ }
709
+ if (fileno(STDIN) != $ENV{PASSWORD_PIPE}) {
710
+ close $fh;
711
+ }
712
+
713
+ return ($AdminUtil::USER, $AdminUtil::PASSWORD,
714
+ $AdminUtil::AUTHORIZATION, $AdminUtil::USERDN,
715
+ $AdminUtil::SIEPWD);
716
+ }
717
+
718
+ # this takes a list of DS instances and registers all of them
719
+ # with the config DS
720
+ sub registerManyDSWithConfigDS {
721
+ my $inf = shift;
722
+ my $errs = shift;
723
+ my $configdir = shift;
724
+ my @instances = @_;
725
+
726
+ if (!@instances) {
727
+ return 1; # no instances to register - just return ok
728
+ }
729
+
730
+ # open a connection to the configuration directory server
731
+ my $conn = getConfigDSConn($inf->{General}->{ConfigDirectoryLdapURL},
732
+ $inf->{General}->{ConfigDirectoryAdminID},
733
+ $inf->{General}->{ConfigDirectoryAdminPwd},
734
+ "$configdir/admin-serv", $errs);
735
+
736
+ if (!$conn or @{$errs}) {
737
+ return 0;
738
+ }
739
+
740
+ my $admConf = getAdmConf("$configdir/admin-serv");
741
+
742
+ for my $inst (@instances) {
743
+ my $instinf = createInfFromConfig("$configdir/$inst", $inst);
744
+ if ($instinf->{filename}) {
745
+ unlink($instinf->{filename});
746
+ }
747
+ $instinf->{General}->{ConfigDirectoryLdapURL} =
748
+ $inf->{General}->{ConfigDirectoryLdapURL};
749
+ $instinf->{General}->{ConfigDirectoryAdminID} =
750
+ $inf->{General}->{ConfigDirectoryAdminID};
751
+ $instinf->{General}->{AdminDomain} = $inf->{General}->{AdminDomain};
752
+ $instinf->{admin}->{ServerAdminID} = $inf->{admin}->{ServerAdminID};
753
+ if (!registerDSWithConfigDS($inst, $errs, $instinf,
754
+ $conn, $admConf, $configdir)) {
755
+ return 0;
756
+ }
757
+ }
758
+
759
+ $conn->close();
760
+
761
+ return 1
762
+ }
763
+ sub registerScatteredDSWithConfigDS {
764
+ my $inf = shift;
765
+ my $errs = shift;
766
+ my $instances_ref = shift;
767
+ my @configdirs = keys %{$instances_ref};
768
+ my $configdir = $configdirs[0]; # use the first configdir for admin-serv
769
+
770
+ if ( ! $instances_ref ) {
771
+ return 1; # no instances to register - just return ok
772
+ }
773
+
774
+ # open a connection to the configuration directory server
775
+ my $conn = getConfigDSConn($inf->{General}->{ConfigDirectoryLdapURL},
776
+ $inf->{General}->{ConfigDirectoryAdminID},
777
+ $inf->{General}->{ConfigDirectoryAdminPwd},
778
+ "$configdir/admin-serv", $errs);
779
+
780
+ if (!$conn or @{$errs}) {
781
+ return 0;
782
+ }
783
+
784
+ my $admConf = getAdmConf("$configdir/admin-serv");
785
+
786
+ for $configdir ( @configdirs ) {
787
+ foreach my $dsinst ( @{$instances_ref->{$configdir}} ) {
788
+ my $instinf = createInfFromConfig("$configdir/$dsinst", $dsinst);
789
+ if ($instinf->{filename}) {
790
+ unlink($instinf->{filename});
791
+ }
792
+ $instinf->{General}->{ConfigDirectoryLdapURL} =
793
+ $inf->{General}->{ConfigDirectoryLdapURL};
794
+ $instinf->{General}->{AdminDomain} = $inf->{General}->{AdminDomain};
795
+ $instinf->{General}->{ConfigDirectoryAdminID} = $inf->{General}->{ConfigDirectoryAdminID};
796
+ $instinf->{General}->{ServerAdminID} = $inf->{General}->{ServerAdminID};
797
+ if (!registerDSWithConfigDS($dsinst, $errs, $instinf,
798
+ $conn, $admConf, $configdir)) {
799
+ return 0;
800
+ }
801
+ }
802
+ }
803
+
804
+ $conn->close();
805
+
806
+ return 1
807
+ }
808
+
809
+ sub registerDSWithConfigDS {
810
+ my $servid = shift;
811
+ my $errs = shift;
812
+ my $inf = shift;
813
+ my $conn = shift;
814
+ my $admConf = shift;
815
+ my $configdir = shift || "/etc/dirsrv";
816
+
817
+ my $rc = registerDSWithConfigDSExt(1, $servid, $errs, $inf,
818
+ $conn, $admConf, $configdir);
819
+ return $rc;
820
+ }
821
+
822
+ sub unregisterDSWithConfigDS {
823
+ my $servid = shift;
824
+ my $errs = shift;
825
+ my $inf = shift;
826
+ my $conn = shift;
827
+ my $admConf = shift;
828
+ my $configdir = shift || "/etc/dirsrv";
829
+ my $rc = registerDSWithConfigDSExt(0, $servid, $errs, $inf,
830
+ $conn, $admConf, $configdir);
831
+ return $rc;
832
+ }
833
+
834
+ sub registerDSWithConfigDSExt {
835
+ my $isRegister = shift;
836
+ my $servid = shift;
837
+ my $errs = shift;
838
+ my $inf = shift;
839
+ my $conn = shift;
840
+ my $admConf = shift;
841
+ my $configdir = shift || "/etc/dirsrv";
842
+ my $inst;
843
+ my $needclose;
844
+
845
+ if ($servid =~ /^slapd-/) {
846
+ $inst = $servid;
847
+ } else {
848
+ $inst = "slapd-$servid";
849
+ }
850
+
851
+ my ($dummy1, $pwd, $dummy2, $userdn) = getAuthCredentials();
852
+
853
+ if (!$inf->{General}->{AdminDomain}) {
854
+ if (!$admConf) {
855
+ $admConf = getAdmConf("$configdir/admin-serv");
856
+ }
857
+ $inf->{General}->{AdminDomain} = $admConf->{AdminDomain};
858
+ }
859
+
860
+ # open a connection to the configuration directory server
861
+ if (!$conn) {
862
+ if (!$userdn) {
863
+ $userdn = $inf->{General}->{ConfigDirectoryAdminID};
864
+ }
865
+ if (!$pwd) {
866
+ $pwd = $inf->{General}->{ConfigDirectoryAdminPwd};
867
+ }
868
+
869
+ $conn = getConfigDSConn($inf->{General}->{ConfigDirectoryLdapURL},
870
+ $userdn, $pwd,
871
+ "$configdir/admin-serv", $errs);
872
+ $needclose = 1;
873
+ }
874
+
875
+ if (!$conn or @{$errs}) {
876
+ return 0;
877
+ }
878
+
879
+ # need to get the admin uid
880
+ if (!$inf->{admin}->{ServerAdminID}) {
881
+ my @rdns = ldap_explode_dn($inf->{General}->{ConfigDirectoryAdminID}, 1);
882
+ if (@rdns and $rdns[0]) {
883
+ $inf->{admin}->{ServerAdminID} = $rdns[0];
884
+ } else { # a userid not a dn
885
+ $inf->{admin}->{ServerAdminID} = $inf->{General}->{ConfigDirectoryAdminID};
886
+ }
887
+ }
888
+
889
+ my $instinf;
890
+ # setup will usually supply everything, but ds_create will not
891
+ if ($isRegister && !$inf->{slapd}->{RootDNPwd}) {
892
+ $instinf = createInfFromConfig("$configdir/$inst", $inst, $errs);
893
+ if (!$instinf or @{$errs}) {
894
+ if ($needclose) {
895
+ $conn->close();
896
+ }
897
+ return 0;
898
+ }
899
+ }
900
+
901
+ my @ldiffiles = ();
902
+ if ($isRegister)
903
+ {
904
+ # add the Admin Server configuration entries
905
+ @ldiffiles = ("/usr/share/dirsrv/data/10dsdata.ldif.tmpl",
906
+ "/usr/share/dirsrv/data/11dstasks.ldif.tmpl"
907
+ );
908
+ }
909
+ else
910
+ {
911
+ # remove the Admin Server configuration entries
912
+ @ldiffiles = ("/usr/share/dirsrv/data/10rm_dsdata.ldif.tmpl");
913
+ }
914
+ my @infs = getInfs("slapd", "setup", "admin");
915
+ my $mapper = new Inf("/usr/share/dirsrv/inf/dirserver.map");
916
+
917
+ $mapper = process_maptbl($mapper, $errs, $inf, $instinf, @infs);
918
+ if (!$mapper or @{$errs}) {
919
+ if ($needclose) {
920
+ $conn->close();
921
+ }
922
+ return 0;
923
+ }
924
+
925
+ my $context = [$conn];
926
+ getMappedEntries($mapper, \@ldiffiles, $errs, \&check_and_add_entry, $context);
927
+
928
+ if ($needclose) {
929
+ $conn->close();
930
+ }
931
+
932
+ return @{$errs} ? 0 : 1;
933
+ }
934
+
935
+ # return Inf objects for the given names - the names correspond
936
+ # to .inf file names in the infdir - the list will be ordered
937
+ # so that brand specific names come before generic names -
938
+ # it is assumed in .inf processing that if a value is found
939
+ # in an earlier Inf later Infs will be ignored
940
+ sub getInfs {
941
+ my @names = @_;
942
+ my @ary;
943
+ my @infs = glob("/usr/share/dirsrv/inf/*.inf");
944
+ for my $name (@names) {
945
+ for my $inffile (@infs) {
946
+ if ($inffile =~ m,^/usr/share/dirsrv/inf/.+-$name\.inf$,) {
947
+ # brand specific
948
+ debug(2, "Found brand specific inf file", $inffile, "\n");
949
+ push @ary, new Inf($inffile);
950
+ }
951
+ }
952
+ }
953
+ # added all brand specific inf files, if any - now add generic inf files
954
+ for my $name (@names) {
955
+ push @ary, new Inf("/usr/share/dirsrv/inf/$name.inf");
956
+ }
957
+
958
+ return @ary;
959
+ }
960
+
961
+ # get a value from a collection of Inf objects
962
+ # given a section and a parameter, will return
963
+ # the value from the first Inf that has the
964
+ # section and value
965
+ sub getInfsVal {
966
+ my ($sec, $parm, @infs) = @_;
967
+ for my $inf (@infs) {
968
+ if ($inf and exists($inf->{$sec}) and defined($inf->{$sec}) and
969
+ exists($inf->{$sec}->{$parm}) and defined($inf->{$sec}->{$parm})) {
970
+ return $inf->{$sec}->{$parm};
971
+ }
972
+ }
973
+ return undef;
974
+ }
975
+
976
+ 1;
977
+
978
+ # emacs settings
979
+ # Local Variables:
980
+ # mode:perl
981
+ # indent-tabs-mode: nil
982
+ # tab-width: 4
983
+ # End: