如何检索LDAP数据库的所有属性 [英] How to retrieve all the attributes of LDAP database

查看:562
本文介绍了如何检索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.

我该怎么做.

谢谢.

推荐答案

我正在使用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数据库的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆