python - LDAP gidNumber 类似自动整数

标签 python django active-directory ldap openldap

仍在使用 LDAP...
我今天提交的问题是这样的:我正在使用 Django 框架在 python 中开发的自定义方法在服务器 LDAP 上创建 posixGroup。我附上下面的方法代码。
主要问题是属性 gidNumber 是 posixGroup 类的强制属性,但在使用像 phpLDAPadmin 这样的图形 LDAP 客户端时通常不需要,因为它们会自动填充此字段,例如一个自动整数。
这里的问题是:gidNumber是默认的自动整数属性,还是像上面引用的那样使用客户端?我必须在创建 posixGroup 条目时指定它吗?

def ldap_cn_entry(self):

        import ldap.modlist as modlist

        dn = u"cn=myGroupName,ou=plant,dc=ldap,dc=dem2m,dc=it"

        # A dict to help build the "body" of the object
        attrs = {}
        attrs['objectclass'] = ['posixGroup']
        attrs['cn'] = 'myGroupName'
        attrs['gidNumber'] = '508'

        # Convert our dict to nice syntax for the add-function using modlist-module
        ldif = modlist.addModlist(attrs)

        # Do the actual synchronous add-operation to the ldapserver
        self.connector.add_s(dn, ldif)
  • 连接器首先在构建此方法的类的构造函数中实例化。该构造函数还提供 LDAP 初始化和绑定(bind)。然后,连接将被析构函数关闭。
  • 为了使用该方法,我开始实例化它所属的类,因此它也连接到 LDAP 服务器。比我使用该方法,最后我销毁之前实例化的对象以关闭连接。 如果使用此过程创建不同的条目,或者如果我手动指定 gidNumber,则所有工作确实有效
    事实是,每当我想创建一个组来实现我的目的时,我都无法指定 gidNumber。我应该让它自动填充(如果可能的话)或者考虑另一种方法来完成它。

我不会发布更多关于我所做的类的代码,以免挤满页面。
如果需要,我会提供更多信息。谢谢。

最佳答案

LDAP 协议(protocol)没有自动整数的方法。

您需要在创建条目时指定该值。

您可以采取一些技巧来提供帮助。 我们经常将最后使用的值放在 LDAP 中的 OU 上(我们向 OU 添加具有自定义属性的 AUX 类),然后在使用 gidNumber 时读取、递增并使用该值。

Found this described 。 -吉姆

关于python - LDAP gidNumber 类似自动整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25570507/

相关文章:

python - 无法读取行中包含分号的 CSV 文件。无法在 pandas 中使用 drop 函数删除行

python - python中如何不自动将byte转换为ascii

python - Django项目: track migrations

python - 使用 Numpy 查找输入数字集的均值、中值、众数或范围

python - Django - 记录器正在覆盖以前的日志文件和新的日志文件

django - 在 Visual Studio Online 上构建 Django

python - django for 循环计数器中断

c# - DirectoryServices.DirectoryEntry 组调用 ("remove") 和属性 ["member"].remove 之间的差异

windows - Active Directory - 用于查找不在一组组中的所有用户的脚本?

c# - 在 C# .NET 中连接到 Active Directory 服务器时出现问题