1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00
samba-mirror/python/samba/provision/kerberos.py
Andreas Schneider 28be1acd8e mit-kdc: Use more strict KDC default settings
As we require MIT KRB5 >= 1.19 for the KDC, use more secure defaults.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2021-11-29 08:39:37 +00:00

105 lines
2.9 KiB
Python

# Unix SMB/CIFS implementation
#
# Backend code for provisioning a Samba AD server
#
# Copyright (c) 2015 Andreas Schneider <asn@samba.org>
#
# 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; either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
from samba.provision.kerberos_implementation import (
kdb_modules_dir)
from samba import is_heimdal_built
import os
def create_kdc_conf(kdcconf, realm, domain, logdir):
if is_heimdal_built():
return
# Do nothing if kdc.conf has been set
if 'KRB5_KDC_PROFILE' in os.environ:
return
# We are in selftest
if 'SAMBA_SELFTEST' in os.environ and 'MITKRB5' in os.environ:
return
assert kdcconf is not None
assert domain is not None
domain = domain.upper()
assert realm is not None
realm = realm.upper()
f = open(kdcconf, 'w')
try:
f.write("[kdcdefaults]\n")
f.write("\tkdc_ports = 88\n")
f.write("\tkdc_tcp_ports = 88\n")
f.write("\tkadmind_port = 464\n")
f.write("\trestrict_anonymous_to_tgt = true\n")
f.write("\n")
f.write("[realms]\n")
f.write("\t%s = {\n" % realm)
f.write("\t\tmaster_key_type = aes256-cts\n")
f.write("\t\tdefault_principal_flags = +preauth\n")
f.write("\t}\n")
f.write("\n")
f.write("\t%s = {\n" % realm.lower())
f.write("\t\tmaster_key_type = aes256-cts\n")
f.write("\t\tdefault_principal_flags = +preauth\n")
f.write("\t}\n")
f.write("\n")
f.write("\t%s = {\n" % domain)
f.write("\t\tmaster_key_type = aes256-cts\n")
f.write("\t\tdefault_principal_flags = +preauth\n")
f.write("\t}\n")
f.write("\n")
f.write("[dbmodules]\n")
f.write("\tdb_module_dir = %s\n" % kdb_modules_dir)
f.write("\n")
f.write("\t%s = {\n" % realm)
f.write("\t\tdb_library = samba\n")
f.write("\t}\n")
f.write("\n")
f.write("\t%s = {\n" % realm.lower())
f.write("\t\tdb_library = samba\n")
f.write("\t}\n")
f.write("\n")
f.write("\t%s = {\n" % domain)
f.write("\t\tdb_library = samba\n")
f.write("\t}\n")
f.write("\n")
f.write("[logging]\n")
f.write("\tkdc = FILE:%s/mit_kdc.log\n" % logdir)
f.write("\tadmin_server = FILE:%s/mit_kadmin.log\n" % logdir)
f.write("\n")
finally:
f.close()