ipaplatform.constants has platform specific names for a couple of system
users like Apache HTTPD. The user names for PKI_USER, PKI_GROUP, DS_USER
and DS_GROUP are defined in other modules. Similar to #5587 the patch my
patch moves the constants into the platform module.

https://fedorahosted.org/freeipa/ticket/5619
From bd49251543c480ed3d4527b3aeb32f0df6fc9e67 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Tue, 19 Jan 2016 14:18:30 +0100
Subject: [PATCH] Move user/group constants for PKI and DS into ipaplatform

https://fedorahosted.org/freeipa/ticket/5619
---
 install/share/copy-schema-to-ca.py  |  8 ++++----
 ipaplatform/base/constants.py       |  4 ++++
 ipaserver/install/cainstance.py     | 15 +++++++--------
 ipaserver/install/dogtaginstance.py |  3 ++-
 ipaserver/install/dsinstance.py     |  5 +++--
 ipaserver/install/ipa_backup.py     |  4 ++--
 ipaserver/install/ipa_restore.py    | 16 +++++++++-------
 ipaserver/install/krainstance.py    |  8 ++++----
 ipaserver/install/krbinstance.py    |  4 ++--
 ipaserver/install/server/upgrade.py |  3 ++-
 10 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/install/share/copy-schema-to-ca.py b/install/share/copy-schema-to-ca.py
index 10fd3d740bb60b9506a233a6aea6c6ac98356c18..c2f070aa29b7abf1cb32c46020ae80450cfd5080 100755
--- a/install/share/copy-schema-to-ca.py
+++ b/install/share/copy-schema-to-ca.py
@@ -19,9 +19,9 @@ from hashlib import sha1
 
 from ipapython import ipautil
 from ipapython.ipa_log_manager import root_logger, standard_logging_setup
-from ipaserver.install.dsinstance import DS_USER, schema_dirname
-from ipaserver.install.cainstance import PKI_USER
+from ipaserver.install.dsinstance import schema_dirname
 from ipalib import api
+from ipaplatform.constants import constants
 
 try:
     from ipaplatform import services
@@ -52,8 +52,8 @@ def _sha1_file(filename):
 def add_ca_schema():
     """Copy IPA schema files into the CA DS instance
     """
-    pki_pent = pwd.getpwnam(PKI_USER)
-    ds_pent = pwd.getpwnam(DS_USER)
+    pki_pent = pwd.getpwnam(constants.PKI_USER)
+    ds_pent = pwd.getpwnam(constants.DS_USER)
     for schema_fname in SCHEMA_FILENAMES:
         source_fname = os.path.join(ipautil.SHARE_DIR, schema_fname)
         target_fname = os.path.join(schema_dirname(SERVERID), schema_fname)
diff --git a/ipaplatform/base/constants.py b/ipaplatform/base/constants.py
index 50f8a3ed140aca0f6573231f2a7e5b20e2169919..52af12429d090dcc0d7eed14b76e8b651360f283 100644
--- a/ipaplatform/base/constants.py
+++ b/ipaplatform/base/constants.py
@@ -8,9 +8,13 @@ This base platform module exports platform dependant constants.
 
 
 class BaseConstantsNamespace(object):
+    DS_USER = 'dirsrv'
+    DS_GROUP = 'dirsrv'
     HTTPD_USER = "apache"
     IPA_DNS_PACKAGE_NAME = "freeipa-server-dns"
     NAMED_USER = "named"
+    PKI_USER = 'pkiuser'
+    PKI_GROUP = 'pkiuser'
     # ntpd init variable used for daemon options
     NTPD_OPTS_VAR = "OPTIONS"
     # quote used for daemon options
diff --git a/ipaserver/install/cainstance.py b/ipaserver/install/cainstance.py
index f3c1bfa361f2627d8e95ad6cb2fa93b4dc41ee38..269d2387db8293b98ef320156690020c540f952f 100644
--- a/ipaserver/install/cainstance.py
+++ b/ipaserver/install/cainstance.py
@@ -66,8 +66,7 @@ from ipaserver.install import installutils
 from ipaserver.install import ldapupdate
 from ipaserver.install import replication
 from ipaserver.install import service
-from ipaserver.install.dogtaginstance import (
-    PKI_USER, export_kra_agent_pem, DogtagInstance)
+from ipaserver.install.dogtaginstance import export_kra_agent_pem, DogtagInstance
 from ipaserver.plugins import ldap2
 
 # Python 3 rename. The package is available in "six.moves.http_client", but
@@ -279,8 +278,8 @@ def is_ca_installed_locally():
 def create_ca_user():
     """Create PKI user/group if it doesn't exist yet."""
     tasks.create_system_user(
-        name=PKI_USER,
-        group=PKI_USER,
+        name=constants.PKI_USER,
+        group=constants.PKI_GROUP,
         homedir=paths.VAR_LIB,
         shell=paths.NOLOGIN,
     )
@@ -442,7 +441,7 @@ class CAInstance(DogtagInstance):
         # Create an empty and secured file
         (cfg_fd, cfg_file) = tempfile.mkstemp()
         os.close(cfg_fd)
-        pent = pwd.getpwnam(PKI_USER)
+        pent = pwd.getpwnam(constants.PKI_USER)
         os.chown(cfg_file, pent.pw_uid, pent.pw_gid)
 
         # Create CA configuration
@@ -511,7 +510,7 @@ class CAInstance(DogtagInstance):
 
             cafile = self.pkcs12_info[0]
             shutil.copy(cafile, paths.TMP_CA_P12)
-            pent = pwd.getpwnam(PKI_USER)
+            pent = pwd.getpwnam(constants.PKI_USER)
             os.chown(paths.TMP_CA_P12, pent.pw_uid, pent.pw_gid)
 
             # Security domain registration
@@ -606,7 +605,7 @@ class CAInstance(DogtagInstance):
             'ca.enableNonces=false')
         if update_result != 0:
             raise RuntimeError("Disabling nonces failed")
-        pent = pwd.getpwnam(PKI_USER)
+        pent = pwd.getpwnam(constants.PKI_USER)
         os.chown(paths.CA_CS_CFG_PATH, pent.pw_uid, pent.pw_gid)
 
     def enable_pkix(self):
@@ -941,7 +940,7 @@ class CAInstance(DogtagInstance):
             os.mkdir(publishdir)
 
         os.chmod(publishdir, 0o775)
-        pent = pwd.getpwnam(PKI_USER)
+        pent = pwd.getpwnam(constants.PKI_USER)
         os.chown(publishdir, 0, pent.pw_gid)
 
         tasks.restore_context(publishdir)
diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py
index 193423d7e09cec17a82d4f5da2ed6c43accf1c0c..55535a3568fb70057c9305ddc0f77ead25cb79df 100644
--- a/ipaserver/install/dogtaginstance.py
+++ b/ipaserver/install/dogtaginstance.py
@@ -33,6 +33,7 @@ import pki.system
 from ipalib import errors
 
 from ipaplatform import services
+from ipaplatform.constants import constants
 from ipaplatform.paths import paths
 from ipapython import certmonger
 from ipapython import ipaldap
@@ -44,7 +45,7 @@ from ipaserver.install import replication
 from ipaserver.install.installutils import stopped_service
 from ipapython.ipa_log_manager import log_mgr
 
-PKI_USER = "pkiuser"
+PKI_USER = constants.PKI_USER
 
 
 def get_security_domain():
diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py
index 3d5734efe7ad0ed2ccf03120b8461db9f99aa318..cda750445fd9233b6ccd51ffea18844271496a84 100644
--- a/ipaserver/install/dsinstance.py
+++ b/ipaserver/install/dsinstance.py
@@ -44,14 +44,15 @@ from ipalib import api
 from ipalib import certstore
 from ipalib import errors
 from ipalib import constants
+from ipaplatform.constants import constants as platformconstants
 from ipaplatform.tasks import tasks
 from ipalib.constants import CACERT
 from ipapython.dn import DN
 from ipaplatform import services
 from ipaplatform.paths import paths
 
-DS_USER = 'dirsrv'
-DS_GROUP = 'dirsrv'
+DS_USER = platformconstants.DS_USER
+DS_GROUP = platformconstants.DS_GROUP
 
 IPA_SCHEMA_FILES = ("60kerberos.ldif",
                     "60samba.ldif",
diff --git a/ipaserver/install/ipa_backup.py b/ipaserver/install/ipa_backup.py
index d49576d7d5bf3934882cdfe570dee8635eef28b8..a0e064778ffb781ab10df1c65ced8ff7138928ff 100644
--- a/ipaserver/install/ipa_backup.py
+++ b/ipaserver/install/ipa_backup.py
@@ -32,13 +32,13 @@ from ipapython import version
 from ipapython.ipautil import run, write_tmp_file
 from ipapython import admintool
 from ipapython.dn import DN
-from ipaserver.install.dsinstance import DS_USER
 from ipaserver.install.replication import wait_for_task
 from ipaserver.install import installutils
 from ipapython import ipaldap
 from ipalib.session import ISO8601_DATETIME_FMT
 from ipalib.constants import CACERT
 from six.moves.configparser import SafeConfigParser
+from ipaplatform.constants import constants
 from ipaplatform.tasks import tasks
 
 """
@@ -262,7 +262,7 @@ class Backup(admintool.AdminTool):
 
         self.log.info("Preparing backup on %s", api.env.host)
 
-        pent = pwd.getpwnam(DS_USER)
+        pent = pwd.getpwnam(constants.DS_USER)
 
         self.top_dir = tempfile.mkdtemp("ipa")
         os.chown(self.top_dir, pent.pw_uid, pent.pw_gid)
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
index b223bd287f633b863315661ca27641425529cc40..b2ee6aaebd44bb82e32e6b1611caaf0d79ba73dc 100644
--- a/ipaserver/install/ipa_restore.py
+++ b/ipaserver/install/ipa_restore.py
@@ -32,14 +32,15 @@ from ipapython import version, ipautil, certdb
 from ipapython.ipautil import run, user_input
 from ipapython import admintool
 from ipapython.dn import DN
-from ipaserver.install.dsinstance import create_ds_user, DS_USER
-from ipaserver.install.cainstance import PKI_USER, create_ca_user
+from ipaserver.install.dsinstance import create_ds_user
+from ipaserver.install.cainstance import create_ca_user
 from ipaserver.install.replication import (wait_for_task, ReplicationManager,
                                            get_cs_replication_manager)
 from ipaserver.install import installutils
 from ipaserver.install import dsinstance, httpinstance, cainstance
 from ipapython import ipaldap
 import ipapython.errors
+from ipaplatform.constants import constants
 from ipaplatform.tasks import tasks
 from ipaplatform import services
 from ipaplatform.paths import paths
@@ -293,7 +294,7 @@ class Restore(admintool.AdminTool):
                 raise admintool.ScriptError("Aborted")
 
         create_ds_user()
-        pent = pwd.getpwnam(DS_USER)
+        pent = pwd.getpwnam(constants.DS_USER)
 
         # Temporary directory for decrypting files before restoring
         self.top_dir = tempfile.mkdtemp("ipa")
@@ -530,7 +531,7 @@ class Restore(admintool.AdminTool):
         srcldiffile = os.path.join(self.dir, ldifname)
 
         if not os.path.exists(ldifdir):
-            pent = pwd.getpwnam(DS_USER)
+            pent = pwd.getpwnam(constants.DS_USER)
             os.mkdir(ldifdir)
             os.chmod(ldifdir, 0o770)
             os.chown(ldifdir, pent.pw_uid, pent.pw_gid)
@@ -755,7 +756,7 @@ class Restore(admintool.AdminTool):
                ]
         run(args)
 
-        pent = pwd.getpwnam(DS_USER)
+        pent = pwd.getpwnam(constants.DS_USER)
         os.chown(self.top_dir, pent.pw_uid, pent.pw_gid)
         recursive_chown(self.dir, pent.pw_uid, pent.pw_gid)
 
@@ -781,9 +782,10 @@ class Restore(admintool.AdminTool):
                      paths.TOMCAT_SIGNEDAUDIT_DIR]
 
         try:
-            pent = pwd.getpwnam(PKI_USER)
+            pent = pwd.getpwnam(constants.PKI_USER)
         except KeyError:
-            self.log.debug("No %s user exists, skipping CA directory creation" % PKI_USER)
+            self.log.debug("No %s user exists, skipping CA directory creation",
+                           constants.PKI_USER)
             return
         self.log.debug('Creating log directories for dogtag')
         for dir in dirs:
diff --git a/ipaserver/install/krainstance.py b/ipaserver/install/krainstance.py
index 6589bb54eadf9bc5017ef99cdfbf3c46dabc27c6..1343f0fe298dba2b4ad0da435becba885e32a73f 100644
--- a/ipaserver/install/krainstance.py
+++ b/ipaserver/install/krainstance.py
@@ -28,6 +28,7 @@ from six.moves.configparser import ConfigParser
 from ipalib import api
 from ipalib import x509
 from ipaplatform import services
+from ipaplatform.constants import constants
 from ipaplatform.paths import paths
 from ipapython import certdb
 from ipapython import ipautil
@@ -37,8 +38,7 @@ from ipaserver.install import cainstance
 from ipaserver.install import installutils
 from ipaserver.install import ldapupdate
 from ipaserver.install import service
-from ipaserver.install.dogtaginstance import (
-    PKI_USER, export_kra_agent_pem, DogtagInstance)
+from ipaserver.install.dogtaginstance import export_kra_agent_pem, DogtagInstance
 from ipaserver.plugins import ldap2
 from ipapython.ipa_log_manager import log_mgr
 
@@ -134,7 +134,7 @@ class KRAInstance(DogtagInstance):
         # Create an empty and secured file
         (cfg_fd, cfg_file) = tempfile.mkstemp()
         os.close(cfg_fd)
-        pent = pwd.getpwnam(PKI_USER)
+        pent = pwd.getpwnam(constants.PKI_USER)
         os.chown(cfg_file, pent.pw_uid, pent.pw_gid)
 
         # Create KRA configuration
@@ -223,7 +223,7 @@ class KRAInstance(DogtagInstance):
         if self.clone:
             krafile = self.pkcs12_info[0]
             shutil.copy(krafile, p12_tmpfile_name)
-            pent = pwd.getpwnam(PKI_USER)
+            pent = pwd.getpwnam(constants.PKI_USER)
             os.chown(p12_tmpfile_name, pent.pw_uid, pent.pw_gid)
 
             # Security domain registration
diff --git a/ipaserver/install/krbinstance.py b/ipaserver/install/krbinstance.py
index 31149752a1eab62ce142ac9614309a1d0a098754..9f73aab237dfc7555cf2378164c6e911dfd00918 100644
--- a/ipaserver/install/krbinstance.py
+++ b/ipaserver/install/krbinstance.py
@@ -36,11 +36,11 @@ from ipapython.ipa_log_manager import root_logger
 from ipapython.dn import DN
 
 from ipaserver.install import replication
-from ipaserver.install import dsinstance
 from ipaserver.install import ldapupdate
 
 from ipaserver.install import certs
 from distutils import version
+from ipaplatform.constants import constants
 from ipaplatform.tasks import tasks
 from ipaplatform.paths import paths
 
@@ -327,7 +327,7 @@ class KrbInstance(service.Service):
         vardict = {"KRB5_KTNAME": paths.DS_KEYTAB}
         ipautil.config_replace_variables(paths.SYSCONFIG_DIRSRV,
                                          replacevars=vardict)
-        pent = pwd.getpwnam(dsinstance.DS_USER)
+        pent = pwd.getpwnam(constants.DS_USER)
         os.chown(paths.DS_KEYTAB, pent.pw_uid, pent.pw_gid)
 
     def __create_host_keytab(self):
diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py
index f37a8fea504d828f9bce5a870ad0b48f154b4e88..888b5169b3394361448a733e113fc53097d6f0d3 100644
--- a/ipaserver/install/server/upgrade.py
+++ b/ipaserver/install/server/upgrade.py
@@ -25,6 +25,7 @@ from ipapython import ipaldap
 from ipapython.ipa_log_manager import root_logger
 from ipapython import certmonger
 from ipapython.dn import DN
+from ipaplatform.constants import constants
 from ipaplatform.paths import paths
 from ipaserver.install import installutils
 from ipaserver.install import dsinstance
@@ -929,7 +930,7 @@ def copy_crl_file(old_path, new_path=None):
         os.symlink(realpath, new_path)
     else:
         shutil.copy2(old_path, new_path)
-        pent = pwd.getpwnam(cainstance.PKI_USER)
+        pent = pwd.getpwnam(constants.PKI_USER)
         os.chown(new_path, pent.pw_uid, pent.pw_gid)
 
     tasks.restore_context(new_path)
-- 
2.5.0

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to