Beispiel #1
0
def local_node():
    """Returns local DS node"""
    my_session = ODSession.defaultSession()
    if not my_session:
        return None
    node, err = ODNode.nodeWithSession_name_error_(my_session,
                                                   "/Local/Default", None)
    if err:
        print >> sys.stderr, err
    return node
Beispiel #2
0
def _get_node(path):
    '''
    Get a reference to an ODNode instance given a path string eg. /LDAPv3/127.0.0.1
    '''
    session = ODSession.defaultSession()
    node, err = ODNode.nodeWithSession_name_error_(session, path, None)

    if err:
        raise CommandExecutionError(
            'cannot retrieve ODNode instance, reason: {}'.format(err))

    return node
def _get_node(path):
    '''
    Get a reference to an ODNode instance given a path string eg. /LDAPv3/127.0.0.1
    '''
    session = ODSession.defaultSession()
    node, err = ODNode.nodeWithSession_name_error_(session, path, None)

    if err:
        log.error(err)
        return None

    return node
Beispiel #4
0
def _get_node(path):
    '''
    Get a reference to an ODNode instance given a path string eg. /LDAPv3/127.0.0.1
    '''
    session = ODSession.defaultSession()
    node, err = ODNode.nodeWithSession_name_error_(session, path, None)

    if err:
        raise CommandExecutionError(
            'cannot retrieve ODNode instance, reason: {}'.format(err)
        )

    return node
def nodes():
    '''
    Get a list of registered nodes eg. /Local/Default
    CLI Example::
        salt '*' opendirectory.nodes
    '''
    session = ODSession.defaultSession()
    names, err = session.nodeNamesAndReturnError_(None)

    if err is not None:
        log.error(err)
        return None

    # The method returns with a tuple so it is converted to a list here.
    return list(names)
def get_od_node():
    """Description"""

    session = ODSession.defaultSession()

    if not session:
        return None

    node, error = ODNode.nodeWithSession_type_error_(session,
                                                     kODNodeTypeLocalNodes,
                                                     None)

    if error:
        print >> sys.stderr, error
        return None

    return node
Beispiel #7
0
def macOSLAPS_Utility(choice, ad_user_name, ad_password, computer_name):
        '''Function to connect and pull information from Active Directory
        some code borrowed from AD PassMon - Thanks @macmuleblog'''
        # Active Directory Connection and Extraction of Data
        try:
            # Create Net Config
            net_config = SCDynamicStoreCreate(None, "net", None, None)
            # Get Active Directory Info
            ad_info = dict(
                SCDynamicStoreCopyValue(
                    net_config, 'com.apple.opendirectoryd.ActiveDirectory'))
            # Create Active Directory Path
            adpath = '{0:}/{1:}'.format(ad_info['NodeName'],
                                        ad_info['DomainNameDns'])
            # Use Open Directory To Connect to Active Directory
            node, error = ODNode.nodeWithSession_name_error_(
                ODSession.defaultSession(), adpath, None)
            node.setCredentialsWithRecordType_recordName_password_error_(
                None, ad_user_name, ad_password, None)
            # Grab the Computer Record
            computer_record, error = node.\
                recordWithRecordType_name_attributes_error_(
                    kODRecordTypeComputers,
                    "{0:}$".format(computer_name), None, None)
            # Convert to Readable Values
            values, error = computer_record.\
                recordDetailsForAttributes_error_(None, None)
            # Get LAPS Password for machine
            if choice == "1":
                print "Password: {0:}{1:}{2:}".format(
                    color.BOLD,
                    values['dsAttrTypeNative:ms-Mcs-AdmPwd'][0],
                    color.END)
                raw_input("\n\nPress any key to continue....")
            elif choice == "2":
                computer_record.setValue_forAttribute_error_(
                    '126227988000000000',
                    'dsAttrTypeNative:ms-Mcs-AdmPwdExpirationTime',
                    None)
                raw_input("\n\nForce Expire time Set. Keep in mind that"
                          " macOSLAPS will need to run on the system before"
                          " the password is changed."
                          " Press any key to continue...")
        except StandardError as error:
            print error
Beispiel #8
0
def nodes():
    '''
    Get a list of registered nodes eg. /Local/Default

    CLI Example::

        salt '*' opendirectory.nodes
    '''
    session = ODSession.defaultSession()
    names, err = session.nodeNamesAndReturnError_(None)

    if err is not None:
        raise SaltInvocationError(
            'cannot retrieve a list of directory services nodes, reason: {}'.format(err.localizedDescription())
        )

    # The method returns with a tuple so it is converted to a list here.
    return list(names)
Beispiel #9
0
def get_od_node():
    """
    Returns an ODNode object, used to communicate with the Open Directory API.
    """

    session = ODSession.defaultSession()

    if not session:
        return None

    node, error = ODNode.nodeWithSession_type_error_(session,
                                                     kODNodeTypeLocalNodes,
                                                     None)

    if error:
        print error
        return None

    return node