예제 #1
0
__author__ = 'Maskonk'

from pyad import pyad_setdefaults
from pyad import aduser

#This is the pyad version
#setdefaults is supposed to direct it to the AD and log it in but it is not able to find it remotly
#Since setdefaults is supposed to not be required if you are connected to an AD
# it may be possible to get this working while connected to the AD

pyad_setdefaults(ldap_server="DevOps.internal", username="******", password="******")
user = aduser.ADUser.from_cn("Test")

#ou = pyad.adcontainer.ADContainer.from_dn("ou=workstations, dc=domain, dc=com")
#computer = pyad.adcomputer.ADComputer.create("Test", ou)
예제 #2
0
#But neither the add user or the list users work for either pyad or LDAP


#WMI connection
connection = wmi.WMI("10.1.63.2", user="******", password="******")
print("Connection is established")


#LDAP connection
l = open("10.1.63.2")
l.protocol_version = ldap.VERSION3
l.set_option(ldap.OPT_REFERRALS, 0)
bind = l.simple_bind_s("automated", "Arugula01")

#To add a user via pyad
pyad.pyad_setdefaults(ldap_server=wmi.WMI("10.1.63.2", user="******", password="******"))
#user1 = pyad.aduser.ADUser.from_cn("Test")

#To add a user via LDAP (Does not work at the moment.)
try:
    dn = "cn=Tester, dc=DevOps, dc=internal"
    attrs = {}
    attrs['objectclass'] = ['top', 'Test', 'simpleSecurityObject']
    attrs['cn'] = 'Tester'
    attrs['userPassword'] = '******'
    attrs['description'] = 'User object for replication using slurpd'
    ldif = modlist.addModlist(attrs)
    l.add_s(dn, ldif)
    l.unbind_s()
except ldap.LDAPError, e:
    print e