Exemple #1
0
    def do_naming_contexts(self, argstr):
        """Read list of naming contexts from directory.
usage: naming_contexts 
		"""
        if not self.conn:
            self.conn = ldap.init(self.host, self.port)
        try:
            naming_contexts = self.get_naming_contexts()
            print "Naming contexts:", naming_contexts
        except LDAPError, e:
            print "error:", sys.exc_type, e
Exemple #2
0
 def init_ldap(self, uri='', dn='', pw=''):
     """Initialise LDAP"""
     prot, sep, uri = uri.partition('://')
     if not sep:
         uri = prot
         prot = 'ldap'
     url, sep, port = uri.partition(':')
     if not sep:
         port = 389
     self.connection = ldap.init(url, port)
     result = self.connection.simple_bind_s(dn, pw)
     if result[0] != 97:
         raise ldap.LDAPError("Connection was not successfull: result = {0}"
                                 .format(result))
Exemple #3
0
    def do_init(self, argstr):
        """Initialize connection parameters but don't actually connect until necessary.
usage: init [host] [port]"""
        if argstr:
            args = split_args(argstr)
            self.host = args[0]
            if len(args) > 1:
                self.port = int(args[1])
        try:
            new_conn = ldap.init(self.host, self.port)
            if self.conn:
                self.conn.unbind()
            self.conn = new_conn
        except LDAPError, e:
            print "error:", sys.exc_type, e
Exemple #4
0
    def do_bind(self, argstr):
        """Bind to directory as a specific user.
usage: bind [user] [pass]
user defaults to ""
pass defaults to ""
		"""
        if not self.conn:
            self.conn = ldap.init(self.host, self.port)
        if argstr:
            args = split_args(argstr)
            self.user = self.get_dn(args[0])
            if len(args) > 1:
                self.cred = args[1]
            else:
                self.cred = getpass.getpass("password: "******"Binding as", self.user
            else:
                print "Binding anonymously"
            self.conn.simple_bind_s(self.user, self.cred)
        except LDAPError, e:
            print "error:", sys.exc_type, e
Exemple #5
0
import ldap

host = "localhost:1390"

print("API info:", ldap.get_option(ldap.OPT_API_INFO))
print("debug level:", ldap.get_option(ldap.OPT_DEBUG_LEVEL))
#print("Setting debug level to 255...")
#ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
#print("debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL))
print("default size limit:", ldap.get_option(ldap.OPT_SIZELIMIT))
print("Setting default size limit to 10...")
ldap.set_option(ldap.OPT_SIZELIMIT, 10)
print("default size limit:", ldap.get_option(ldap.OPT_SIZELIMIT))
print("Creating connection to", host, "...")
l = ldap.init(host)
print("size limit:", l.get_option(ldap.OPT_SIZELIMIT))
print("Setting connection size limit to 20...")
l.set_option(ldap.OPT_SIZELIMIT, 20)
print("size limit:", l.get_option(ldap.OPT_SIZELIMIT))
#print("Setting time limit to 60 secs...")
l.set_option(ldap.OPT_TIMELIMIT, 60)
#print("time limit:",l.get_option(ldap.OPT_TIMELIMIT))
print("Binding...")
l.simple_bind_s("", "")
Exemple #6
0
import ldap

host="localhost:1390"

print "API info:",ldap.get_option(ldap.OPT_API_INFO)
print "debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL)
#print "Setting debug level to 255..."
#ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
#print "debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL)
print "default size limit:",ldap.get_option(ldap.OPT_SIZELIMIT)
print "Setting default size limit to 10..."
ldap.set_option(ldap.OPT_SIZELIMIT,10)
print "default size limit:",ldap.get_option(ldap.OPT_SIZELIMIT)
print "Creating connection to",host,"..."
l=ldap.init(host)
print "size limit:",l.get_option(ldap.OPT_SIZELIMIT)
print "Setting connection size limit to 20..."
l.set_option(ldap.OPT_SIZELIMIT,20)
print "size limit:",l.get_option(ldap.OPT_SIZELIMIT)
#print "Setting time limit to 60 secs..."
l.set_option(ldap.OPT_TIMELIMIT,60)
#print "time limit:",l.get_option(ldap.OPT_TIMELIMIT)
print "Binding..."
l.simple_bind_s("","")




Exemple #7
0
 def connect(self):
     print self.app.config['LDAP_HOST']
     self.conn = ldap.init(self.app.config['LDAP_HOST'])
     return self.conn
# host
#
# Diego Woitasen <*****@*****.**>
# http://www.woitasen.com.ar
#

import ldap
from getpass import getpass
from time import sleep
import sys

bind_dn = "cn=directory manager"
host = "localhost"
base = "cn=config"

ldap_c = ldap.init(host)
ldap_c.start_tls_s()
ldap_c.bind_s(bind_dn, getpass('Ingrese password del manager: '))

if len(sys.argv) > 1:
    print base
    print '(&(objectClass=nsDS5ReplicationAgreement)(nsDS5ReplicaHost=%s))' % \
                sys.argv[1]
    results = ldap_c.search_s(base,
                ldap.SCOPE_SUBTREE,
                '(&(objectClass=nsDS5ReplicationAgreement)(nsDS5ReplicaHost=%s))' % \
                sys.argv[1])
else:
    results = ldap_c.search_s(base, ldap.SCOPE_SUBTREE,
                              'objectClass=nsDS5ReplicationAgreement')
#
# Diego Woitasen <*****@*****.**>
# http://www.woitasen.com.ar
#


import ldap
from getpass import getpass
from time import sleep
import sys

bind_dn = "cn=directory manager"
host = "localhost"
base = "cn=config"

ldap_c = ldap.init(host)
ldap_c.start_tls_s()
ldap_c.bind_s(bind_dn, getpass('Ingrese password del manager: '))

if len(sys.argv) > 1:
    print base
    print '(&(objectClass=nsDS5ReplicationAgreement)(nsDS5ReplicaHost=%s))' % \
                sys.argv[1]
    results = ldap_c.search_s(base, 
                ldap.SCOPE_SUBTREE,
                '(&(objectClass=nsDS5ReplicationAgreement)(nsDS5ReplicaHost=%s))' % \
                sys.argv[1])
else:
    results = ldap_c.search_s(base, 
                            ldap.SCOPE_SUBTREE,
                            'objectClass=nsDS5ReplicationAgreement')
 def __init__(self):
     try:
         self.ldapHandle = ldap.init(self.host)
         self.ldapHandle.bind(self.binddn, self.cred)
     except ldap.SERVER_DOWN as error:
         print 'init failed -> %s -> at %s' % (error, self.host)