diff options
| author | Sumit Bose <sbose@redhat.com> | 2011-11-07 12:59:20 +0100 |
|---|---|---|
| committer | Sumit Bose <sbose@redhat.com> | 2011-11-22 08:25:14 +0100 |
| commit | f2ded585f31b789cf68e5958373bff5eedd45a38 (patch) | |
| tree | b6669ada5f8e952cac1f1d0d49cb073d1ac1004e | |
| parent | 681691766fb3e3c2ae4011551128862114acd3dd (diff) | |
| download | freeipa-f2ded585f31b789cf68e5958373bff5eedd45a38.tar.gz freeipa-f2ded585f31b789cf68e5958373bff5eedd45a38.tar.xz freeipa-f2ded585f31b789cf68e5958373bff5eedd45a38.zip | |
Fix some pylint warnings
| -rwxr-xr-x | install/tools/ipa-adtrust-install | 2 | ||||
| -rw-r--r-- | ipaserver/install/adtrustinstance.py | 119 |
2 files changed, 74 insertions, 47 deletions
diff --git a/install/tools/ipa-adtrust-install b/install/tools/ipa-adtrust-install index 423009474..7bdedecbb 100755 --- a/install/tools/ipa-adtrust-install +++ b/install/tools/ipa-adtrust-install @@ -110,7 +110,7 @@ def main(): print "" # Check if samba packages are installed - if not adtrustinstance.check_inst(options.unattended): + if not adtrustinstance.check_inst(): sys.exit("Aborting installation.") # Initialize the ipalib api diff --git a/ipaserver/install/adtrustinstance.py b/ipaserver/install/adtrustinstance.py index 1ec58d942..76556ca18 100644 --- a/ipaserver/install/adtrustinstance.py +++ b/ipaserver/install/adtrustinstance.py @@ -22,10 +22,11 @@ import logging import os import errno import ldap -import service import tempfile import uuid from ipaserver import ipaldap +from ipaserver.install import installutils +from ipaserver.install import service from ipaserver.install.dsinstance import realm_to_serverid from ipaserver.install.bindinstance import get_rr, add_rr, del_rr, \ dns_zone_exists @@ -33,17 +34,17 @@ from ipalib import errors, api from ipapython import sysrestore from ipapython import ipautil -import random import string import struct -allowed_netbios_chars = string.ascii_uppercase + string.digits +ALLOWED_NETBIOS_CHARS = string.ascii_uppercase + string.digits -def check_inst(unattended): - for f in ['/usr/sbin/smbd', '/usr/bin/net', '/usr/bin/smbpasswd']: - if not os.path.exists(f): - print "%s was not found on this system" % f - print "Please install the 'samba' packages and start the installation again" +def check_inst(): + for smbfile in ['/usr/sbin/smbd', '/usr/bin/net', '/usr/bin/smbpasswd']: + if not os.path.exists(smbfile): + print "%s was not found on this system" % file + print "Please install the 'samba' packages and " \ + "start the installation again" return False #TODO: Add check for needed samba4 libraries @@ -52,13 +53,13 @@ def check_inst(unattended): def ipa_smb_conf_exists(): try: - fd = open('/etc/samba/smb.conf', 'r') - except IOError, e: - if e.errno == errno.ENOENT: + conf_fd = open('/etc/samba/smb.conf', 'r') + except IOError, err: + if err.errno == errno.ENOENT: return False - lines = fd.readlines() - fd.close() + lines = conf_fd.readlines() + conf_fd.close() for line in lines: if line.startswith('### Added by IPA Installer ###'): return True @@ -67,13 +68,15 @@ def ipa_smb_conf_exists(): def check_netbios_name(s): # NetBIOS names may not be longer than 15 allowed characters - if not s or len(s) > 15 or ''.join([c for c in s if c not in allowed_netbios_chars]): + if not s or len(s) > 15 or \ + ''.join([c for c in s if c not in ALLOWED_NETBIOS_CHARS]): return False return True def make_netbios_name(s): - return ''.join([c for c in s.split('.')[0].upper() if c in allowed_netbios_chars])[:15] + return ''.join([c for c in s.split('.')[0].upper() \ + if c in ALLOWED_NETBIOS_CHARS])[:15] class ADTRUSTInstance(service.Service): @@ -85,6 +88,22 @@ class ADTRUSTInstance(service.Service): OBJC_DOMAIN = "ipaNTDomainAttrs" def __init__(self, fstore=None, dm_password=None): + self.fqdn = None + self.ip_address = None + self.realm_name = None + self.domain_name = None + self.netbios_name = None + self.no_msdcs = None + self.smbd_user = None + self.suffix = None + self.ldapi_socket = None + self.smb_conf = None + self.smb_dn = None + self.smb_dn_pwd = None + self.trust_dn = None + self.smb_dom_dn = None + self.sub_dict = None + service.Service.__init__(self, "smb", dm_password=dm_password) if fstore: @@ -98,7 +117,8 @@ class ADTRUSTInstance(service.Service): self.admin_conn.getEntry(self.smb_dn, ldap.SCOPE_BASE) print "Samba user entry exists, resetting password" - self.admin_conn.modify_s(self.smb_dn, [(ldap.MOD_REPLACE, "userPassword", self.smb_dn_pwd)]) + self.admin_conn.modify_s(self.smb_dn, \ + [(ldap.MOD_REPLACE, "userPassword", self.smb_dn_pwd)]) return except errors.NotFound: @@ -138,7 +158,8 @@ class ADTRUSTInstance(service.Service): try: self.admin_conn.modify_s(self.suffix, mod) except ldap.TYPE_OR_VALUE_EXISTS: - logging.debug("samba user aci already exists in suffix %s on %s" % (self.suffix, self.admin_conn.host)) + logging.debug("samba user aci already exists in suffix " \ + "%s on %s", self.suffix, self.admin_conn.host) def __gen_sid_string(self): sub_ids = struct.unpack("<LLL", os.urandom(12)) @@ -205,13 +226,14 @@ class ADTRUSTInstance(service.Service): "cn=ad,"+self.trust_dn, \ "cn=ad,cn=etc,"+self.suffix): try: - self.admin_conn.getEntry(dn, ldap.SCOPE_BASE) + self.admin_conn.getEntry(new_dn, ldap.SCOPE_BASE) except errors.NotFound: - entry = ipaldap.Entry(dn) + entry = ipaldap.Entry(new_dn) entry.setValues("objectclass", ["nsContainer"]) - name = dn.split('=')[1].split(',')[0] + name = new_dn.split('=')[1].split(',')[0] if not name: - print "Cannot extract RDN attribute value from [%s]" % dn + print "Cannot extract RDN attribute value from [%s]" % \ + new_dn return entry.setValues("cn", name) self.admin_conn.add_s(entry) @@ -228,18 +250,18 @@ class ADTRUSTInstance(service.Service): def __write_smb_conf(self): self.fstore.backup_file(self.smb_conf) - fd = open(self.smb_conf, "w") - fd.write('### Added by IPA Installer ###\n') - fd.write('[global]\n') - fd.write('config backend = registry\n') - fd.close() + conf_fd = open(self.smb_conf, "w") + conf_fd.write('### Added by IPA Installer ###\n') + conf_fd.write('[global]\n') + conf_fd.write('config backend = registry\n') + conf_fd.close() def __write_smb_registry(self): template = os.path.join(ipautil.SHARE_DIR, "smb.conf.template") conf = ipautil.template_file(template, self.sub_dict) - [fd, tmp_name] = tempfile.mkstemp() - os.write(fd, conf) - os.close(fd) + [tmp_fd, tmp_name] = tempfile.mkstemp() + os.write(tmp_fd, conf) + os.close(tmp_fd) args = ["/usr/bin/net", "conf", "import", tmp_name] @@ -251,7 +273,8 @@ class ADTRUSTInstance(service.Service): def __set_smb_ldap_password(self): args = ["/usr/bin/smbpasswd", "-c", self.smb_conf, "-s", "-W" ] - ipautil.run(args, stdin = self.smb_dn_pwd + "\n" + self.smb_dn_pwd + "\n" ) + ipautil.run(args, stdin = self.smb_dn_pwd + "\n" + \ + self.smb_dn_pwd + "\n" ) def __setup_principal(self): cifs_principal = "cifs/" + self.fqdn + "@" + self.realm_name @@ -262,16 +285,17 @@ class ADTRUSTInstance(service.Service): try: ipautil.run(["ipa-rmkeytab", "--principal", cifs_principal, "-k", "/etc/krb5.keytab"]) - except ipautil.CalledProcessError, e: - if e.returncode != 5: - logging.critical("Failed to remove old key for %s" % cifs_principal) + except ipautil.CalledProcessError, err: + if err.returncode != 5: + logging.critical("Failed to remove old key for %s", \ + cifs_principal) try: ipautil.run(["ipa-getkeytab", "--server", self.fqdn, "--principal", cifs_principal, "-k", "/etc/krb5.keytab"]) - except ipautil.CalledProcessError, e: - logging.critical("Failed to add key for %s" % cifs_principal) + except ipautil.CalledProcessError, err: + logging.critical("Failed to add key for %s", cifs_principal) def __add_dns_service_records(self): """ @@ -292,7 +316,7 @@ class ADTRUSTInstance(service.Service): ".dc._msdcs") err_msg = None - ret = api.Command.dns_is_enabled() + ret = api.Command['dns_is_enabled']() if not ret['result']: err_msg = "DNS management was not enabled at install time." else: @@ -342,10 +366,10 @@ class ADTRUSTInstance(service.Service): # Instead we reply on the IPA init script to start only enabled # components as found in our LDAP configuration tree try: - self.ldap_enable('ADTRUST', self.fqdn, self.dm_password, self.suffix) + self.ldap_enable('ADTRUST', self.fqdn, self.dm_password, \ + self.suffix) except ldap.ALREADY_EXISTS: logging.critical("ADTRUST Service startup entry already exists.") - pass def __setup_sub_dict(self): self.sub_dict = dict(REALM = self.realm_name, @@ -356,7 +380,7 @@ class ADTRUSTInstance(service.Service): def setup(self, fqdn, ip_address, realm_name, domain_name, netbios_name, no_msdcs=False, smbd_user="samba"): - self.fqdn =fqdn + self.fqdn = fqdn self.ip_address = ip_address self.realm_name = realm_name self.domain_name = domain_name @@ -364,7 +388,8 @@ class ADTRUSTInstance(service.Service): self.no_msdcs = no_msdcs self.smbd_user = smbd_user self.suffix = ipautil.realm_to_suffix(self.realm_name) - self.ldapi_socket = "%%2fvar%%2frun%%2fslapd-%s.socket" % realm_to_serverid(self.realm_name) + self.ldapi_socket = "%%2fvar%%2frun%%2fslapd-%s.socket" % \ + realm_to_serverid(self.realm_name) self.smb_conf = "/etc/samba/smb.conf" @@ -384,15 +409,18 @@ class ADTRUSTInstance(service.Service): self.step("stopping smbd", self.__stop) self.step("create samba user", self.__create_samba_user) - self.step("create samba domain object", self.__create_samba_domain_object) + self.step("create samba domain object", \ + self.__create_samba_domain_object) self.step("create samba config registry", self.__write_smb_registry) self.step("writing samba config file", self.__write_smb_conf) - self.step("setting password for the samba user", self.__set_smb_ldap_password) + self.step("setting password for the samba user", \ + self.__set_smb_ldap_password) self.step("Adding cifs Kerberos principal", self.__setup_principal) self.step("Adding admin(group) SIDs", self.__add_admin_sids) self.step("configuring smbd to start on boot", self.__enable) if not self.no_msdcs: - self.step("adding special DNS service records", self.__add_dns_service_records) + self.step("adding special DNS service records", \ + self.__add_dns_service_records) self.step("starting smbd", self.__start) self.start_creation("Configuring smbd:") @@ -409,12 +437,11 @@ class ADTRUSTInstance(service.Service): except: pass - for f in [self.smb_conf]: + for r_file in [self.smb_conf]: try: - self.fstore.restore_file(f) + self.fstore.restore_file(r_file) except ValueError, error: logging.debug(error) - pass if not enabled is None and not enabled: self.disable() |
