Fixed indent

This commit is contained in:
Benjamin Renard 2013-05-15 17:30:15 +02:00
parent ec08775469
commit 0c32a0d67d

View file

@ -35,73 +35,73 @@ parser.add_option( "-p", "--provider",
dest="provider", dest="provider",
action="store", action="store",
type='string', type='string',
help="LDAP provider URI (example : ldaps://ldapmaster.foo:636)") help="LDAP provider URI (example : ldaps://ldapmaster.foo:636)")
parser.add_option( "-c", "--consumer", parser.add_option( "-c", "--consumer",
dest="consumer", dest="consumer",
action="store", action="store",
type='string', type='string',
help="LDAP consumer URI (example : ldaps://ldapslave.foo:636)") help="LDAP consumer URI (example : ldaps://ldapslave.foo:636)")
parser.add_option( "-D", "--dn", parser.add_option( "-D", "--dn",
dest="dn", dest="dn",
action="store", action="store",
type='string', type='string',
help="LDAP bind DN (example : uid=nagios,ou=sysaccounts,o=example") help="LDAP bind DN (example : uid=nagios,ou=sysaccounts,o=example")
parser.add_option( "-P", "--pwd", parser.add_option( "-P", "--pwd",
dest="pwd", dest="pwd",
action="store", action="store",
type='string', type='string',
help="LDAP bind password") help="LDAP bind password")
parser.add_option( "-b", "--basedn", parser.add_option( "-b", "--basedn",
dest="basedn", dest="basedn",
action="store", action="store",
type='string', type='string',
help="LDAP base DN (example : o=example)") help="LDAP base DN (example : o=example)")
parser.add_option( "-f", "--filter", parser.add_option( "-f", "--filter",
dest="filter", dest="filter",
action="store", action="store",
type='string', type='string',
help="LDAP filter (default : (objectClass=*))", help="LDAP filter (default : (objectClass=*))",
default='(objectClass=*)') default='(objectClass=*)')
parser.add_option( "-d", "--debug", parser.add_option( "-d", "--debug",
dest="debug", dest="debug",
action="store_true", action="store_true",
help="Debug mode", help="Debug mode",
default=False) default=False)
parser.add_option( "-n", "--nagios", parser.add_option( "-n", "--nagios",
dest="nagios", dest="nagios",
action="store_true", action="store_true",
help="Nagios check plugin mode", help="Nagios check plugin mode",
default=False) default=False)
parser.add_option( "-q", "--quiet", parser.add_option( "-q", "--quiet",
dest="quiet", dest="quiet",
action="store_true", action="store_true",
help="Quiet mode", help="Quiet mode",
default=False) default=False)
parser.add_option( "--no-check-certificate", parser.add_option( "--no-check-certificate",
dest="nocheckcert", dest="nocheckcert",
action="store_true", action="store_true",
help="Don't check the server certificate (Default : False)", help="Don't check the server certificate (Default : False)",
default=False) default=False)
parser.add_option( "--no-check-contextCSN", parser.add_option( "--no-check-contextCSN",
dest="nocheckcontextcsn", dest="nocheckcontextcsn",
action="store_true", action="store_true",
help="Don't check servers contextCSN (Default : False)", help="Don't check servers contextCSN (Default : False)",
default=False) default=False)
parser.add_option( "-a", "--attributes", parser.add_option( "-a", "--attributes",
dest="attrs", dest="attrs",
action="store_true", action="store_true",
help="Check attributes values (Default : check only entryCSN)", help="Check attributes values (Default : check only entryCSN)",
default=False) default=False)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -134,28 +134,28 @@ else:
class LdapServer(object): class LdapServer(object):
uri = "" uri = ""
dn = "" dn = ""
pwd = "" pwd = ""
con = 0 con = 0
def __init__(self,uri,dn,pwd): def __init__(self,uri,dn,pwd):
self.uri = uri self.uri = uri
self.dn = dn self.dn = dn
self.pwd = pwd self.pwd = pwd
def connect(self): def connect(self):
if self.con == 0: if self.con == 0:
try: try:
con = ldap.initialize(self.uri) con = ldap.initialize(self.uri)
con.protocol_version = ldap.VERSION3 con.protocol_version = ldap.VERSION3
if self.dn != '': if self.dn != '':
con.simple_bind_s(self.dn,self.pwd) con.simple_bind_s(self.dn,self.pwd)
self.con = con self.con = con
return True return True
except ldap.LDAPError, e: except ldap.LDAPError, e:
logging.error("LDAP Error : %s" % e) logging.error("LDAP Error : %s" % e)
return return
def getContextCSN(self,basedn): def getContextCSN(self,basedn):
@ -165,17 +165,17 @@ class LdapServer(object):
else: else:
return False return False
def search(self,basedn,filter,attrs): def search(self,basedn,filter,attrs):
res_id = self.con.search(basedn,ldap.SCOPE_SUBTREE,filter,attrs) res_id = self.con.search(basedn,ldap.SCOPE_SUBTREE,filter,attrs)
ret = [] ret = []
while 1: while 1:
res_type, res_data = self.con.result(res_id,0) res_type, res_data = self.con.result(res_id,0)
if res_data == []: if res_data == []:
break break
else: else:
if res_type == ldap.RES_SEARCH_ENTRY: if res_type == ldap.RES_SEARCH_ENTRY:
ret.append(res_data) ret.append(res_data)
return ret return ret
if options.nocheckcert: if options.nocheckcert:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_NEVER) ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_NEVER)