Пример #1
0
def _parsePolicy(policyDn):
    logging.info("=== Parsing policy [{0};{1}] ===".format(
        policyDn[0], policyDn[1]))

    # Check if the policy is disabled
    if policyDn[1] == 1:
        logging.info("===> Policy is disabled! ===")
        return True

    # Find policy in AD
    rc, policyAdObject = ldapHelper.searchOne("(distinguishedName={})".format(
        policyDn[0]))
    if not rc:
        logging.error("===> Could not find poilcy in AD! ===")
        return False, None

    # mount the share the policy is on (probaply already mounted, just to be sure)
    rc, localPolicyPath = shares.getMountpointOfRemotePath(
        policyAdObject["gPCFileSysPath"], hiddenShare=True, autoMount=True)
    if not rc:
        logging.error("===> Could not mount path of poilcy! ===")
        return False, None

    try:
        # parse drives
        _processDrivesPolicy(localPolicyPath)
        # parse printers
        _processPrintersPolicy(localPolicyPath)
    except Exception as e:
        logging.error("An error occured when parsing policy!")
        logging.exception(e)

    logging.info("===> Parsed policy [{0};{1}] ===".format(
        policyDn[0], policyDn[1]))
Пример #2
0
def readAttributes():
    """
    Read all ldap attributes of the cumputer

    :return: Tuple (success, dict of attributes)
    :rtype: tuple
    """
    return ldapHelper.searchOne("(sAMAccountName={}$)".format(hostname()))
Пример #3
0
def readAttributes():
    """
    Reads all attributes of the current user from ldap

    :return: Tuple (success, dict of user attributes)
    :rtype: tuple
    """
    if not user.isInAD():
        return False, None

    return ldapHelper.searchOne(f"(sAMAccountName={user.username()})")
Пример #4
0
def _findApplicablePolicies():

    policyDnList = []
    """ Do this later!
    # 1. Domain
    rc, domainAdObject = ldapHelper.searchOne("(distinguishedName={})".format(ldapHelper.baseDn()))

    if not rc:
        return False, None

    policyDNs.extend(_parseGplinkSring(domainAdObject["gPLink"]))

    # 2. OU policies from top to bottom
    rc, userAdObject = ldapHelper.searchOne("(sAMAccountName={})".format(user.username()))

    if not rc:
        return False, None

    print(userAdObject["distinguishedName"])
    """

    # For now, just parse policy sophomorix:school:<school name>
    rc, schoolName = user.school()
    if not rc:
        return False, None

    policyName = "sophomorix:school:{}".format(schoolName)

    # find policy
    rc, policyAdObject = ldapHelper.searchOne(
        "(displayName={})".format(policyName))
    if not rc:
        return False, None

    policyDnList.append((policyAdObject["distinguishedName"], 0))

    return True, policyDnList
Пример #5
0
def readAttributes():
    if not user.isInAD():
        return False, None

    return ldapHelper.searchOne("(sAMAccountName={})".format(user.username()))
def readAttributes():
    return ldapHelper.searchOne("(sAMAccountName={}$)".format(hostname()))