如何检索 LDAP 数据库的所有属性

How to retrieve all the attributes of LDAP database(如何检索 LDAP 数据库的所有属性)
本文介绍了如何检索 LDAP 数据库的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pythonldap 模块 连接到 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 数据库的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)