diff options
| author | Nathan Kinder <nkinder@redhat.com> | 2009-09-09 09:59:07 -0700 |
|---|---|---|
| committer | Nathan Kinder <nkinder@redhat.com> | 2009-09-09 09:59:07 -0700 |
| commit | 39869a77cbeb1967acfa1354092c81d05dd79be7 (patch) | |
| tree | dc4cc882f80cd3d5bb7344af4d0703d0665316f3 /ldap/admin/src/scripts/DSCreate.pm.in | |
| parent | 01b9f5e3b023ef19608bb017560adcca13271e1f (diff) | |
| download | ds-39869a77cbeb1967acfa1354092c81d05dd79be7.tar.gz ds-39869a77cbeb1967acfa1354092c81d05dd79be7.tar.xz ds-39869a77cbeb1967acfa1354092c81d05dd79be7.zip | |
Add selinux policy for ns-slapd
This adds a "dirsrv" selinux policy module to confine the ns-slapd
daemon. The setup and migration perl modules were changed to take
care of any relabeling of installed files if selinux support was
compiled in.
The build system now takes a "--with-selinux" option that will
compile the dirsrv policy module and enable any selinux specific
setup code.
To use the dirsrv policy module, the module will need to be loaded
using the semodule utility. It is also necessary to relabel the
installed files using restorecon after performing a make install.
All of this will be taken care of in the spec file when in the
case of using a RPM package.
Diffstat (limited to 'ldap/admin/src/scripts/DSCreate.pm.in')
| -rw-r--r-- | ldap/admin/src/scripts/DSCreate.pm.in | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in index d33f13af..15302b9c 100644 --- a/ldap/admin/src/scripts/DSCreate.pm.in +++ b/ldap/admin/src/scripts/DSCreate.pm.in @@ -888,6 +888,41 @@ sub setDefaults { return (); } +sub updateSelinuxPolicy { + my $inf = shift; + + # if selinux is not available, do nothing + if ("@with_selinux@") { + # run restorecon on all directories we created + for (qw(inst_dir config_dir schema_dir log_dir lock_dir run_dir tmp_dir + cert_dir db_dir ldif_dir bak_dir)) { + my $dir = $inf->{slapd}->{$_}; + system("restorecon -R $dir"); + } + + # label the selected port as ldap_port_t + if ($inf->{slapd}->{ServerPort} != 0) { + my $need_label = 1; + + # check if the port is already labeled properly + my $portline = `semanage port -l | grep ldap_port_t | grep tcp`; + chomp($portline); + $portline =~ s/ldap_port_t\s+tcp\s+//g; + my @labeledports = split(/,\s+/, $portline); + foreach my $labeledport (@labeledports) { + if ($inf->{slapd}->{ServerPort} == $labeledport) { + $need_label = 0; + last; + } + } + + if ($need_label == 1) { + system("semanage port -a -t ldap_port_t -p tcp $inf->{slapd}->{ServerPort}"); + } + } + } +} + sub createDSInstance { my $inf = shift; my @errs; @@ -924,6 +959,8 @@ sub createDSInstance { return @errs; } + updateSelinuxPolicy($inf); + if (@errs = startServer($inf)) { return @errs; } @@ -1048,6 +1085,31 @@ sub removeDSInstance { # Finally, config dir push @errs, remove_tree($entry, "nsslapd-schemadir", $instname, 1, "\.db\$"); + # remove the selinux label from the ports if needed + if ("@with_selinux@") { + foreach my $port (@{$entry->{"nsslapd-port"}}) + { + my $semanage_err = `semanage port -d -t ldap_port_t -p tcp $port 2>&1`; + if ($? != 0) { + if ($semanage_err !~ /defined in policy, cannot be deleted/) { + push @errs, [ 'error_removing_port_label', $port, $semanage_err]; + debug(1, "Warning: Port $port not removed from selinux policy correctly. Error: $semanage_err\n"); + } + } + } + + foreach my $secureport (@{$entry->{"nsslapd-secureport"}}) + { + my $semanage_err = `semanage port -d -t ldap_port_t -p tcp $secureport 2>&1`; + if ($? != 0) { + if ($semanage_err !~ /defined in policy, cannot be deleted/) { + push @errs, [ 'error_removing_port_label', $secureport, $semanage_err]; + debug(1, "Warning: Port $secureport not removed from selinux policy correctly. Error: $semanage_err\n"); + } + } + } + } + # if we got here, report success if (@errs) { debug(1, "Could not successfully remove $instname\n"); |
