此错误意味着什么:“警告:ldap

编程入门 行业动态 更新时间:2024-10-28 02:25:25
此错误意味着什么:“警告:ldap_mod_add():修改:存在类型或值”(What does this error implies : “Warning: ldap_mod_add(): Modify: Type or value exists”)

我正在使用ldap 2天(所以我对这个工具并不是很有信心)对于一个项目而且我收到了这个错误。

这是代码:

$ldap_user = $this->container->getParameter('ldap_user'); $ldap_pass= $this->container->getParameter('ldap_pass'); $ldap_co = ldap_connect($this->container->getParameter('ldap_address')); if ($ldap_co) { ldap_set_option($ldap_co, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_bind($ldap_co , $ldap_user, $ldap_pass); $sr =ldap_search($ldap_co, "ou=Users,dc=LOCALLAN,dc=OSAXIS,dc=FR", "uid=*"); $userList = ldap_get_entries($ldap_co, $sr); $tmp = 0; for ($i = 0; $i < count($userList) - 1 ; $i++) { if ($tmp < $userList[$i]['uidnumber']) $tmp = $userList[$i]['uidnumber']; } $tmp[0]++; $userId['memberUid']=$user->getUsrLogin(); ldap_mod_add($ldap_co, 'cn=Osaxis,ou=Groups,dc=LOCALLAN,dc=OSAXIS,dc=FR', $userId); $dn = "uid=".$user->getUsrLogin(); $dn.= ",ou=Users,dc=LOCALLAN,dc=OSAXIS,dc=FR"; $info['cn'] = $user->getUsrLogin(); $info['displayname'] = $user->getUsrNom() . " " . $user->getUsrPrenom(); $info['mail'] = $user->getUsrEmail(); // $info['birthdate'] = str_replace("-", "/",$user->getUsrDateNaissance()->format('d-m-Y')); $info['entrydate'] = str_replace("-", "/",$user->getUsrDateEmbauche()->format('d-m-Y')); $info['gecos'] = "User"; $info['gidnumber'] = "513"; $info['objectClass'][0] = "top"; $info['objectClass'][1] = "person"; $info['objectClass'][2] = "organizationalPerson"; $info['objectClass'][3] = "posixAccount"; $info['objectClass'][4] = "shadowAccount"; $info['objectClass'][5] = "inetOrgPerson"; $info['objectClass'][6] = "entryDateOsaxis"; $info['sn'] = $user->getUsrPrenom(); $info['uidnumber'] = $tmp[0]; $info['givenname'] = $user->getUsrNom(); $info['homedirectory'] = "/home/".$user->getUsrLogin(); $info['shadowlastchange'] = "16605"; $info['shadowmax'] = "3650"; $info['telephonenumber'] = $user->getUsrTelport(); $info['userpassword'] = md5($user->getUsrPassword()); ldap_add($ldap_co, $dn, $info); ldap_close($ldap_co);

起初我以为是因为我添加了birthdate而在ldap中没有这个名字的字段存在。 但是在删除线后错误仍然存​​在。 我也清除了缓存,但错误仍在这里,并不清楚,我不明白是什么问题...

如果有人有一个很棒的解决方案。

I'm using the ldap for 2 days (so I'm not really confident about this tool) for a project and I receive that error.

Here's the code :

$ldap_user = $this->container->getParameter('ldap_user'); $ldap_pass= $this->container->getParameter('ldap_pass'); $ldap_co = ldap_connect($this->container->getParameter('ldap_address')); if ($ldap_co) { ldap_set_option($ldap_co, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_bind($ldap_co , $ldap_user, $ldap_pass); $sr =ldap_search($ldap_co, "ou=Users,dc=LOCALLAN,dc=OSAXIS,dc=FR", "uid=*"); $userList = ldap_get_entries($ldap_co, $sr); $tmp = 0; for ($i = 0; $i < count($userList) - 1 ; $i++) { if ($tmp < $userList[$i]['uidnumber']) $tmp = $userList[$i]['uidnumber']; } $tmp[0]++; $userId['memberUid']=$user->getUsrLogin(); ldap_mod_add($ldap_co, 'cn=Osaxis,ou=Groups,dc=LOCALLAN,dc=OSAXIS,dc=FR', $userId); $dn = "uid=".$user->getUsrLogin(); $dn.= ",ou=Users,dc=LOCALLAN,dc=OSAXIS,dc=FR"; $info['cn'] = $user->getUsrLogin(); $info['displayname'] = $user->getUsrNom() . " " . $user->getUsrPrenom(); $info['mail'] = $user->getUsrEmail(); // $info['birthdate'] = str_replace("-", "/",$user->getUsrDateNaissance()->format('d-m-Y')); $info['entrydate'] = str_replace("-", "/",$user->getUsrDateEmbauche()->format('d-m-Y')); $info['gecos'] = "User"; $info['gidnumber'] = "513"; $info['objectClass'][0] = "top"; $info['objectClass'][1] = "person"; $info['objectClass'][2] = "organizationalPerson"; $info['objectClass'][3] = "posixAccount"; $info['objectClass'][4] = "shadowAccount"; $info['objectClass'][5] = "inetOrgPerson"; $info['objectClass'][6] = "entryDateOsaxis"; $info['sn'] = $user->getUsrPrenom(); $info['uidnumber'] = $tmp[0]; $info['givenname'] = $user->getUsrNom(); $info['homedirectory'] = "/home/".$user->getUsrLogin(); $info['shadowlastchange'] = "16605"; $info['shadowmax'] = "3650"; $info['telephonenumber'] = $user->getUsrTelport(); $info['userpassword'] = md5($user->getUsrPassword()); ldap_add($ldap_co, $dn, $info); ldap_close($ldap_co);

At first I thought it was because I added birthdate while no field exists with this name in the ldap. But the error is still here after I removed the line. I also cleared the cache but the error is still here and not clear enough for me to understand what is the problem...

If anyone has a solution that would be awesome.

最满意答案

顾名思义, ldap_mod_add为现有属性添加了一个值(除了它可能已有的属性)。 ldap_mod_replace只是将属性可能包含的任何值替换为您指定的任何值。

在这种情况下,警告似乎告诉您的是,您尝试添加的值已经作为属性的值存在。 您没有得到与ldap_mod_replace相同的错误,因为它不关心已经为该属性设置了什么值,只关注您指定的任何值。

您可能应该做的是在添加之前检查memberUid的值(这似乎是触发它的值)。

ldap_mod_add, as the name implies, adds a value to an existing attribute (in addition to what it might already have). ldap_mod_replace simply replaces any value(s) the attribute may have with whatever you specify.

In this case, what the warning seems to be telling you is that the value you are attempting to add already exists as a value for the attribute. You don't get the same error with ldap_mod_replace because it doesn't care what values are already set for the attribute and just subs in whatever you specify.

What you probably should do is check the values of memberUid before adding to it (That seems to be the value triggering it anyway).

更多推荐

本文发布于:2023-07-08 19:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1079989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意味着什么   错误   ldap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!