How to retrieve all the attributes of LDAP database(如何检索 LDAP 数据库的所有属性)
问题描述
我正在使用 python 的 ldap 模块 连接到 ldap 服务器.我可以查询数据库,但我不知道如何检索数据库中存在的字段,以便我可以提前通知用户查询数据库,告诉他试图访问的字段不在数据库中.
I am using ldap module of python to connect to ldap server. I am able to query the database but I dont know how to retrieve the fields present in the database, so that I can notify the user in advance to quering the database, telling him that the field he is trying to access is not in the database.
例如,如果存在的字段只是
For example if the fields present are just
cn
memberOf
如果用户尝试使用过滤器查询数据库
and if the user tries to query the database with filter
cn and memberOf and notcontained
我应该能够知道 notcontained 属性不在 dabase 架构中.
I should be able to know that the notcontained attribute is not in the dabase schema.
我怎样才能做到这一点.
How can I accomplish this.
谢谢.
推荐答案
我正在使用 python 的 ldap 模块连接到 ldap 服务器.我能查询数据库,但我不知道如何检索字段存在于数据库中,以便我可以提前通知用户查询数据库,告诉他他正在尝试的领域访问不在数据库中.
I am using ldap module of python to connect to ldap server. I am able to query the database but I dont know how to retrieve the fields present in the database, so that I can notify the user in advance to quering the database, telling him that the field he is trying to access is not in the database.
一个简单的解决方案是搜索然后从结果中打印一个键列表.
A simple solution would be to search and then print a list of the keys from the result.
import ldap
# connect to your ldap server
some_dn = '...' # Your base dn
some_lookup = '...' # your lookup attr
result = conn.search_s(some_dn,ldap.SCOPE_SUBTREE,some_lookup)
result[0][1].keys()
例如,针对我的 AD 服务器,它返回以下内容:
For example, against my AD server it returns the following:
['mailNickname',
'publicDelegatesBL',
'logonCount',
'cn',
'countryCode',
'dSCorePropagationData',
'objectClass',
# ... many many more
'telephoneNumber',
'physicalDeliveryOfficeName',
'name',
'memberOf',
'codePage',
'userAccountControl',
'msExchMDBRulesQuota',
'lastLogon',
'protocolSettings',
'uSNChanged',
'sn',
'msExchVersion',
'mDBUseDefaults',
'givenName',
'msExchMailboxGuid',
'lastLogoff']
这篇关于如何检索 LDAP 数据库的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检索 LDAP 数据库的所有属性
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
