mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-22 14:23:19 -06:00
Removed duplication.
This commit is contained in:
parent
0d0f83f603
commit
a471ebe751
@ -25,8 +25,14 @@ import shutil
|
|||||||
import logging
|
import logging
|
||||||
import pwd
|
import pwd
|
||||||
import os
|
import os
|
||||||
|
import stat
|
||||||
|
from util import *
|
||||||
|
|
||||||
|
|
||||||
SHARE_DIR = "/usr/share/ipa/"
|
SHARE_DIR = "/usr/share/ipa/"
|
||||||
|
SERVER_ROOT_64 = "/usr/lib64/fedora-ds-base"
|
||||||
|
SERVER_ROOT_32 = "/usr/lib/fedora-ds-base"
|
||||||
|
|
||||||
|
|
||||||
def generate_serverid():
|
def generate_serverid():
|
||||||
"""Generate a UUID (universally unique identifier) suitable
|
"""Generate a UUID (universally unique identifier) suitable
|
||||||
@ -45,39 +51,20 @@ def realm_to_suffix(realm_name):
|
|||||||
terms = ["dc=" + x.lower() for x in s]
|
terms = ["dc=" + x.lower() for x in s]
|
||||||
return ",".join(terms)
|
return ",".join(terms)
|
||||||
|
|
||||||
def template_str(txt, vars):
|
def find_server_root():
|
||||||
return string.Template(txt).substitute(vars)
|
try:
|
||||||
|
mode = os.stat(SERVER_ROOT_64)[ST_MODE]
|
||||||
|
if stat.IS_DIR(mode):
|
||||||
|
return SERVER_ROOT_64
|
||||||
|
except:
|
||||||
|
return SERVER_ROOT_32
|
||||||
|
|
||||||
def template_file(infilename, vars):
|
|
||||||
txt = open(infilename).read()
|
|
||||||
return template_str(txt, vars)
|
|
||||||
|
|
||||||
def write_tmp_file(txt):
|
|
||||||
fd = tempfile.NamedTemporaryFile()
|
|
||||||
fd.write(txt)
|
|
||||||
fd.flush()
|
|
||||||
|
|
||||||
return fd
|
|
||||||
|
|
||||||
def run(args, stdin=None):
|
|
||||||
logging.debug("running command [%s]" % (" ".join(args)))
|
|
||||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
if stdin:
|
|
||||||
stdout,stderr = p.communicate(stdin)
|
|
||||||
else:
|
|
||||||
stdout,stderr = p.communicate()
|
|
||||||
logging.info(stdout)
|
|
||||||
logging.info(stderr)
|
|
||||||
|
|
||||||
if p.returncode != 0:
|
|
||||||
raise subprocess.CalledProcessError(p.returncode, args[0])
|
|
||||||
|
|
||||||
|
|
||||||
INF_TEMPLATE = """
|
INF_TEMPLATE = """
|
||||||
[General]
|
[General]
|
||||||
FullMachineName= $FQHN
|
FullMachineName= $FQHN
|
||||||
SuiteSpotUserID= $USER
|
SuiteSpotUserID= $USER
|
||||||
ServerRoot= /usr/lib/fedora-ds-base
|
ServerRoot= $SERVER_ROOT
|
||||||
[slapd]
|
[slapd]
|
||||||
ServerPort= 389
|
ServerPort= 389
|
||||||
ServerIdentifier= $SERVERID
|
ServerIdentifier= $SERVERID
|
||||||
@ -103,7 +90,6 @@ class DsInstance:
|
|||||||
self.__setup_sub_dict()
|
self.__setup_sub_dict()
|
||||||
|
|
||||||
self.__create_ds_user()
|
self.__create_ds_user()
|
||||||
self.__set_ds_perms()
|
|
||||||
self.__create_instance()
|
self.__create_instance()
|
||||||
self.__add_default_schemas()
|
self.__add_default_schemas()
|
||||||
self.__enable_ssl()
|
self.__enable_ssl()
|
||||||
@ -129,9 +115,11 @@ class DsInstance:
|
|||||||
|
|
||||||
def __setup_sub_dict(self):
|
def __setup_sub_dict(self):
|
||||||
suffix = realm_to_suffix(self.realm_name)
|
suffix = realm_to_suffix(self.realm_name)
|
||||||
|
server_root = find_server_root()
|
||||||
self.sub_dict = dict(FQHN=self.host_name, SERVERID=self.serverid,
|
self.sub_dict = dict(FQHN=self.host_name, SERVERID=self.serverid,
|
||||||
PASSWORD=self.admin_password, SUFFIX=suffix,
|
PASSWORD=self.admin_password, SUFFIX=suffix,
|
||||||
REALM=self.realm_name, USER=self.ds_user)
|
REALM=self.realm_name, USER=self.ds_user,
|
||||||
|
SERVER_ROOT=server_root)
|
||||||
|
|
||||||
def __create_ds_user(self):
|
def __create_ds_user(self):
|
||||||
try:
|
try:
|
||||||
@ -143,12 +131,6 @@ class DsInstance:
|
|||||||
run(args)
|
run(args)
|
||||||
logging.debug("done adding user")
|
logging.debug("done adding user")
|
||||||
|
|
||||||
def __set_ds_perms(self):
|
|
||||||
p = pwd.getpwnam(self.ds_user)
|
|
||||||
uid = p.pw_uid
|
|
||||||
gid = p.pg_gid
|
|
||||||
os.chown("/var/tmp/fedora-ds", uid, gid)
|
|
||||||
|
|
||||||
def __create_instance(self):
|
def __create_instance(self):
|
||||||
logging.debug("creating ds instance . . . ")
|
logging.debug("creating ds instance . . . ")
|
||||||
inf_txt = template_str(INF_TEMPLATE, self.sub_dict)
|
inf_txt = template_str(INF_TEMPLATE, self.sub_dict)
|
||||||
|
@ -28,13 +28,7 @@ from time import gmtime
|
|||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
import socket
|
import socket
|
||||||
|
from util import *
|
||||||
SHARE_DIR = "/usr/share/ipa/"
|
|
||||||
|
|
||||||
def realm_to_suffix(realm_name):
|
|
||||||
s = realm_name.split(".")
|
|
||||||
terms = ["dc=" + x.lower() for x in s]
|
|
||||||
return ",".join(terms)
|
|
||||||
|
|
||||||
def host_to_domain(fqdn):
|
def host_to_domain(fqdn):
|
||||||
s = fqdn.split(".")
|
s = fqdn.split(".")
|
||||||
@ -49,36 +43,10 @@ def generate_kdc_password():
|
|||||||
rndpwd += chr(r.randint(65,90)) #stricter set for testing
|
rndpwd += chr(r.randint(65,90)) #stricter set for testing
|
||||||
return rndpwd
|
return rndpwd
|
||||||
|
|
||||||
def template_str(txt, vars):
|
|
||||||
return string.Template(txt).substitute(vars)
|
|
||||||
|
|
||||||
def template_file(infilename, vars):
|
|
||||||
txt = open(infilename).read()
|
|
||||||
return template_str(txt, vars)
|
|
||||||
|
|
||||||
def write_tmp_file(txt):
|
|
||||||
fd = tempfile.NamedTemporaryFile()
|
|
||||||
fd.write(txt)
|
|
||||||
fd.flush()
|
|
||||||
|
|
||||||
return fd
|
|
||||||
|
|
||||||
def ldap_mod(fd, dn, pwd):
|
def ldap_mod(fd, dn, pwd):
|
||||||
args = ["/usr/bin/ldapmodify", "-h", "127.0.0.1", "-xv", "-D", dn, "-w", pwd, "-f", fd.name]
|
args = ["/usr/bin/ldapmodify", "-h", "127.0.0.1", "-xv", "-D", dn, "-w", pwd, "-f", fd.name]
|
||||||
run(args)
|
run(args)
|
||||||
|
|
||||||
def run(args, stdin=None):
|
|
||||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
if stdin:
|
|
||||||
stdout,stderr = p.communicate(stdin)
|
|
||||||
else:
|
|
||||||
stdout,stderr = p.communicate()
|
|
||||||
logging.info(stdout)
|
|
||||||
logging.info(stderr)
|
|
||||||
|
|
||||||
if p.returncode != 0:
|
|
||||||
raise subprocess.CalledProcessError(p.returncode, args[0])
|
|
||||||
|
|
||||||
class KrbInstance:
|
class KrbInstance:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ds_user = None
|
self.ds_user = None
|
||||||
|
Loading…
Reference in New Issue
Block a user