2015-07-02 05:38:43 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
|
|
|
#
|
|
|
|
|
|
|
|
'''
|
|
|
|
This base platform module exports platform dependant constants.
|
|
|
|
'''
|
2020-09-11 05:22:02 -05:00
|
|
|
import grp
|
|
|
|
import os
|
|
|
|
import pwd
|
2018-06-14 10:04:13 -05:00
|
|
|
import sys
|
2015-07-02 05:38:43 -05:00
|
|
|
|
|
|
|
|
2020-09-11 05:22:02 -05:00
|
|
|
class _Entity(str):
|
|
|
|
__slots__ = ("_entity", )
|
|
|
|
|
2020-09-15 09:02:46 -05:00
|
|
|
def __new__(cls, name):
|
|
|
|
# if 'name' is already an instance of cls, return identical name
|
|
|
|
if isinstance(name, cls):
|
|
|
|
return name
|
|
|
|
else:
|
|
|
|
return super().__new__(cls, name)
|
|
|
|
|
2020-09-11 05:22:02 -05:00
|
|
|
def __init__(self, name):
|
|
|
|
super().__init__()
|
|
|
|
self._entity = None
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return super().__str__()
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f'<{self.__class__.__name__} "{self!s}">'
|
|
|
|
|
|
|
|
|
|
|
|
class User(_Entity):
|
|
|
|
__slots__ = ()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def entity(self):
|
|
|
|
"""User information struct
|
|
|
|
|
|
|
|
:return: pwd.struct_passwd instance
|
|
|
|
"""
|
|
|
|
entity = self._entity
|
|
|
|
if entity is None:
|
|
|
|
try:
|
|
|
|
self._entity = entity = pwd.getpwnam(self)
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError(f"user '{self!s}' not found") from None
|
|
|
|
return entity
|
|
|
|
|
|
|
|
@property
|
|
|
|
def uid(self):
|
|
|
|
"""Numeric user id (int)
|
|
|
|
"""
|
|
|
|
return self.entity.pw_uid
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pgid(self):
|
|
|
|
"""Primary group id (int)"""
|
|
|
|
return self.entity.pw_gid
|
|
|
|
|
|
|
|
def chown(self, path, gid=None, **kwargs):
|
|
|
|
"""chown() file by path or file descriptor
|
|
|
|
|
|
|
|
gid defaults to user's primary gid. Use -1 to keep gid.
|
|
|
|
"""
|
|
|
|
if gid is None:
|
|
|
|
gid = self.pgid
|
|
|
|
elif isinstance(gid, Group):
|
|
|
|
gid = gid.gid
|
|
|
|
os.chown(path, self.uid, gid, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class Group(_Entity):
|
|
|
|
__slots__ = ()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def entity(self):
|
|
|
|
"""Group information
|
|
|
|
|
|
|
|
:return: grp.struct_group instance
|
|
|
|
"""
|
|
|
|
entity = self._entity
|
|
|
|
if entity is None:
|
|
|
|
try:
|
|
|
|
self._entity = entity = grp.getgrnam(self)
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError(f"group '{self!s}' not found") from None
|
|
|
|
return entity
|
|
|
|
|
|
|
|
@property
|
|
|
|
def gid(self):
|
|
|
|
"""Numeric group id (int)
|
|
|
|
"""
|
|
|
|
return self.entity.gr_gid
|
|
|
|
|
|
|
|
def chgrp(self, path, **kwargs):
|
|
|
|
"""change group owner file by path or file descriptor
|
|
|
|
"""
|
|
|
|
os.chown(path, -1, self.gid, **kwargs)
|
|
|
|
|
|
|
|
|
2018-09-26 04:59:50 -05:00
|
|
|
class BaseConstantsNamespace:
|
2018-06-14 10:04:13 -05:00
|
|
|
IS_64BITS = sys.maxsize > 2 ** 32
|
2019-06-15 09:25:51 -05:00
|
|
|
DEFAULT_ADMIN_SHELL = '/bin/bash'
|
|
|
|
DEFAULT_SHELL = '/bin/sh'
|
2020-09-11 05:22:02 -05:00
|
|
|
IPAAPI_USER = User("ipaapi")
|
|
|
|
IPAAPI_GROUP = Group("ipaapi")
|
|
|
|
DS_USER = User("dirsrv")
|
|
|
|
DS_GROUP = Group("dirsrv")
|
|
|
|
HTTPD_USER = User("apache")
|
|
|
|
HTTPD_GROUP = Group("apache")
|
|
|
|
GSSPROXY_USER = User("root")
|
2018-10-23 02:29:38 -05:00
|
|
|
IPA_ADTRUST_PACKAGE_NAME = "freeipa-server-trust-ad"
|
2015-07-01 08:05:45 -05:00
|
|
|
IPA_DNS_PACKAGE_NAME = "freeipa-server-dns"
|
2020-09-11 05:22:02 -05:00
|
|
|
KDCPROXY_USER = User("kdcproxy")
|
|
|
|
NAMED_USER = User("named")
|
|
|
|
NAMED_GROUP = Group("named")
|
2017-03-29 10:17:28 -05:00
|
|
|
NAMED_DATA_DIR = "data/"
|
2019-09-30 08:47:08 -05:00
|
|
|
NAMED_OPTIONS_VAR = "OPTIONS"
|
|
|
|
NAMED_OPENSSL_ENGINE = None
|
2017-03-29 10:17:28 -05:00
|
|
|
NAMED_ZONE_COMMENT = ""
|
2020-09-11 05:22:02 -05:00
|
|
|
PKI_USER = User("pkiuser")
|
|
|
|
PKI_GROUP = Group("pkiuser")
|
2015-10-06 10:46:00 -05:00
|
|
|
# ntpd init variable used for daemon options
|
|
|
|
NTPD_OPTS_VAR = "OPTIONS"
|
|
|
|
# quote used for daemon options
|
|
|
|
NTPD_OPTS_QUOTE = "\""
|
2020-09-11 05:22:02 -05:00
|
|
|
ODS_USER = User("ods")
|
|
|
|
ODS_GROUP = Group("ods")
|
2015-10-06 08:35:24 -05:00
|
|
|
# nfsd init variable used to enable kerberized NFS
|
|
|
|
SECURE_NFS_VAR = "SECURE_NFS"
|
2017-05-18 10:23:54 -05:00
|
|
|
SELINUX_BOOLEAN_ADTRUST = {
|
|
|
|
'samba_portmapper': 'on',
|
|
|
|
}
|
2017-05-18 10:19:23 -05:00
|
|
|
SELINUX_BOOLEAN_HTTPD = {
|
|
|
|
'httpd_can_network_connect': 'on',
|
|
|
|
'httpd_manage_ipa': 'on',
|
|
|
|
'httpd_run_ipa': 'on',
|
|
|
|
'httpd_dbus_sssd': 'on',
|
|
|
|
}
|
2019-06-11 10:05:29 -05:00
|
|
|
# Unlike above, there are multiple use cases for SMB sharing
|
|
|
|
# SELINUX_BOOLEAN_SMBSERVICE is a dictionary of dictionaries
|
|
|
|
# to define set of booleans for each use case
|
|
|
|
SELINUX_BOOLEAN_SMBSERVICE = {
|
|
|
|
'share_home_dirs': {
|
|
|
|
'samba_enable_home_dirs': 'on',
|
|
|
|
},
|
|
|
|
'reshare_nfs_with_samba': {
|
|
|
|
'samba_share_nfs': 'on',
|
|
|
|
},
|
|
|
|
}
|
2023-08-29 04:37:57 -05:00
|
|
|
SELINUX_BOOLEAN_SSSD = {
|
|
|
|
'sssd_use_usb': 'on',
|
|
|
|
}
|
2019-06-27 03:52:40 -05:00
|
|
|
SELINUX_MCS_MAX = 1023
|
|
|
|
SELINUX_MCS_REGEX = r"^c(\d+)([.,-]c(\d+))*$"
|
|
|
|
SELINUX_MLS_MAX = 15
|
|
|
|
SELINUX_MLS_REGEX = r"^s(\d+)(-s(\d+))?$"
|
|
|
|
SELINUX_USER_REGEX = r"^[a-zA-Z][a-zA-Z_\.]*$"
|
|
|
|
SELINUX_USERMAP_DEFAULT = "unconfined_u:s0-s0:c0.c1023"
|
|
|
|
SELINUX_USERMAP_ORDER = (
|
|
|
|
"guest_u:s0"
|
2019-07-05 06:39:17 -05:00
|
|
|
"$xguest_u:s0"
|
|
|
|
"$user_u:s0"
|
|
|
|
"$staff_u:s0-s0:c0.c1023"
|
|
|
|
"$sysadm_u:s0-s0:c0.c1023"
|
|
|
|
"$unconfined_u:s0-s0:c0.c1023"
|
2019-06-27 03:52:40 -05:00
|
|
|
)
|
2020-09-11 05:22:02 -05:00
|
|
|
SSSD_USER = User("sssd")
|
2018-02-06 03:05:49 -06:00
|
|
|
# WSGI module override, only used on Fedora
|
|
|
|
MOD_WSGI_PYTHON2 = None
|
|
|
|
MOD_WSGI_PYTHON3 = None
|
2018-06-14 10:04:13 -05:00
|
|
|
# WSGIDaemonProcess process count. On 64bit platforms, each process
|
|
|
|
# consumes about 110 MB RSS, from which are about 35 MB shared.
|
2018-06-25 03:59:18 -05:00
|
|
|
WSGI_PROCESSES = 4 if IS_64BITS else 2
|
2018-02-09 04:50:32 -06:00
|
|
|
# high ciphers without RC4, MD5, TripleDES, pre-shared key, secure
|
|
|
|
# remote password, and DSA cert authentication.
|
|
|
|
TLS_HIGH_CIPHERS = "HIGH:!aNULL:!eNULL:!MD5:!RC4:!3DES:!PSK:!SRP:!aDSS"
|
2018-02-06 03:05:49 -06:00
|
|
|
|
2017-10-11 05:09:30 -05:00
|
|
|
|
|
|
|
constants = BaseConstantsNamespace()
|