libkrb5.py revision b6ece28856aa36dba6304dca4bac57f552ff0a6a
from __future__ import print_function
import ConfigParser
import tempfile
import os
import subprocess
""" Base class to setup MIT Kerberos server
Default Kerberos Server realm is "EXAMPLE.TEST"
Default Admin password is "Secret123"
"""
""" Initialize realm, host, ports, Kerberos admin password """
if krb_realm is None:
else:
'des3-hmac-sha1:normal', 'arcfour-hmac:normal',
'camellia256-cts:normal', 'camellia128-cts:normal',
'des-hmac-sha1:normal', 'des-cbc-md5:normal',
'des-cbc-crc:normal']
def _config_krb5kdc(self):
""" Configure kdc.conf and kadm5.acl
:param: None
:return str: Return Kerberos kdc.conf file path
"""
realm_def = """ {
acl_file = %s
admin_keytab = %s
supported_enctypes = %s
return krb_config_path
def _krb_acl_config(self):
""" Create ACL file
:param: None
:return: Config file path
"""
return acl_config_path
def krb_setup_new(self):
""" Setup new Kerberos REALM
:param: None
:return: None
:Exception: Raises subprocess.CalledProcessError
"""
try:
except subprocess.CalledProcessError:
raise
try:
service='admin',
service_name='admin')
except subprocess.CalledProcessError:
raise
else:
try:
except subprocess.CalledProcessError:
raise
else:
try:
'-q', "ktadd host/%s" %
except subprocess.CalledProcessError:
raise
try:
(self.admin_keytab)])
except subprocess.CalledProcessError:
raise
try:
(self.admin_keytab)])
except subprocess.CalledProcessError:
raise
try:
except subprocess.CalledProcessError:
raise
else:
try:
except subprocess.CalledProcessError:
raise
else:
p_type='user',
password=None,
service=None,
service_name=None):
:param str principal: principal name (foobar)
:param str password: password ('Secret123')
:param str service_name: Hostname where service is run
:return bool: True if principal is added
:Exception: Raise subprocess.CalledProcessError
"""
# Todo: Need to check if a principal already exists before adding.
if service is None:
service = 'host'
if p_type is 'user':
add_principal = "add_principal -clearpolicy"\
elif p_type is 'admin':
add_principal = "add_principal -clearpolicy"\
'-q', add_principal]
else:
add_principal = "add_principal -clearpolicy"\
'-q', add_principal]
try:
except subprocess.CalledProcessError:
raise
else:
return True
def destroy_krb5server(self):
""" Destroy Kerberos database
:param: None
:Exception: subprocess.CalledProcessError
"""
# stop the Kerberos server
try:
except subprocess.CalledProcessError:
raise
else:
# stop kadmin service
try:
except subprocess.CalledProcessError:
raise
else:
# destroy Kerberos database
try:
except subprocess.CalledProcessError:
raise
else: