def getDomainConfig(domain): result = subprocess.run("adcli info '{}'".format(domain), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True) if result.returncode != 0: logging.error("Failed to get details of domain {}!".format(domain)) return False, None rawConfig = _readConfigFromString(result.stdout) try: rawDomainConfig = rawConfig["domain"] except KeyError: logging.error("Error when reading domain details") return False, None domainConfig = {} try: domainConfig["domain-controller"] = rawDomainConfig["domain-controller"] domainConfig["domain-name"] = rawDomainConfig["domain-name"] except KeyError: logging.error("Error when reading domain details (2)") return False, None return True, domainConfig
def _processPrintersPolicy(policyBasepath): logging.info("== Parsing a printer policy! ==") policyFile = "{}/User/Preferences/Printers/Printers.xml".format( policyBasepath) printerList = [] # test rc, tree = _parseXmlPolicy(policyFile) if not rc: logging.error( "==> Error while reading Printer policy file, skipping! ==") return xmlPrinters = tree.getroot() if not xmlPrinters.tag == "Printers": logging.warning( "==> Printer policy xml File is of invalid format, skipping! ==") return for xmlPrinter in xmlPrinters: if xmlPrinter.tag != "SharedPrinter" or ( "disabled" in xmlPrinter.attrib and xmlPrinter.attrib["disabled"] == "1"): continue printer = {} printer["filters"] = [] try: printer["name"] = xmlPrinter.attrib["name"] except Exception as e: logging.warning( "Exception when reading a printer name from a printer policy XML file" ) logging.exception(e) for xmlPrinterProperty in xmlPrinter: if xmlPrinterProperty.tag == "Properties": try: rc, printerUrl = printers.translateSambaToIpp( xmlPrinterProperty.attrib["path"]) if rc: printer["path"] = printerUrl except Exception as e: logging.warning( "Exception when parsing a printer policy XML file") logging.exception(e) continue if xmlPrinterProperty.tag == "Filters": printer["filters"] = _parseXmlFilters(xmlPrinterProperty) printerList.append(printer) printerList = _processFilters(printerList) logging.info("Found printers:") for printer in printerList: logging.info("* {0}\t\t| {1}\t| {2}".format(printer["name"], printer["path"], printer["filters"])) printers.installPrinter(printer["path"], printer["name"]) logging.info("==> Successfully parsed a printer policy! ==")
def verifyDomainJoin(): logging.info("Testing if the domain join actually works") if not isJoined(): logging.error("No domain is joined!") return False logging.info("* Checking if the group \"domain users\" exists") if subprocess.call(["getent", "group", "domain users"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) != 0: logging.error("The \"domain users\" group does not exists! Users wont be able to log in!") logging.error("This is sometimes related to /etc/nsswitch.conf.") return False # Try to get a kerberos ticket for the computer account logging.info("* Trying to get a kerberos ticket for the Computer Account") if not pullKerberosTicketForComputerAccount(): logging.error("Could not get a kerberos ticket for the Computer Account!") logging.error("Logins of non-cached users WILL NOT WORK!") logging.error("Please try to re-join the Domain.") return False logging.info("The domain join is working!") return True
def _processDrivesPolicy(policyBasepath): logging.info("== Parsing a drive policy! ==") policyFile = "{}/User/Preferences/Drives/Drives.xml".format(policyBasepath) shareList = [] rc, tree = _parseXmlPolicy(policyFile) if not rc: logging.error( "==> Error while reading Drives policy file, skipping! ==") return xmlDrives = tree.getroot() if not xmlDrives.tag == "Drives": logging.warning( "==> Drive policy xml File is of invalid format, skipping! ==") return for xmlDrive in xmlDrives: if xmlDrive.tag != "Drive" or ("disabled" in xmlDrive.attrib and xmlDrive.attrib["disabled"] == "1"): continue drive = {} drive["filters"] = [] for xmlDriveProperty in xmlDrive: if xmlDriveProperty.tag == "Properties": try: drive["label"] = xmlDriveProperty.attrib["label"] drive["letter"] = xmlDriveProperty.attrib["letter"] drive["path"] = xmlDriveProperty.attrib["path"] drive["useLetter"] = xmlDriveProperty.attrib["useLetter"] except Exception as e: logging.warning( "Exception when parsing a drive policy XML file") logging.exception(e) continue if xmlDriveProperty.tag == "Filters": drive["filters"] = _parseXmlFilters(xmlDriveProperty) shareList.append(drive) shareList = _processFilters(shareList) logging.info("Found shares:") for drive in shareList: logging.info("* {:10}| {:5}| {:40}| {:5}".format( drive["label"], drive["letter"], drive["path"], drive["useLetter"])) for drive in shareList: if drive["useLetter"] == "1": shareName = f"{drive['label']} ({drive['letter']}:)" else: drive["label"] shares.mountShare(drive["path"], shareName=shareName) logging.info("==> Successfully parsed a drive policy! ==")