|
@@ -4441,6 +4441,11 @@ private:
|
|
|
StringBuffer filter;
|
|
|
filter.append("distinguishedName=").append(dn);
|
|
|
|
|
|
+ filter.replaceString("\\", "\\5c");//Replace special characters with valid UTF-8 string (see valueencoding rule in RFC 4515)
|
|
|
+ filter.replaceString("*", "\\2a");
|
|
|
+ filter.replaceString("(", "\\28");
|
|
|
+ filter.replaceString(")", "\\29");
|
|
|
+
|
|
|
char *attribute;
|
|
|
LDAPMessage *message;
|
|
|
|
|
@@ -5014,6 +5019,17 @@ private:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ virtual const bool organizationalUnitExists(const char * ou) const
|
|
|
+ {
|
|
|
+ Owned<ILdapConnection> lconn = m_connections->getConnection();
|
|
|
+ LDAP* sys_ld = ((CLdapConnection*)lconn.get())->getLd();
|
|
|
+ char* attrs[] = {"ou", NULL};
|
|
|
+ CLDAPMessage searchResult;
|
|
|
+ TIMEVAL timeOut = {LDAPTIMEOUT,0};
|
|
|
+ int rc = ldap_search_ext_s(sys_ld,const_cast <char*>(ou),LDAP_SCOPE_ONELEVEL,NULL,attrs,0,NULL,NULL,&timeOut,LDAP_NO_LIMIT,&searchResult.msg);
|
|
|
+ return rc == LDAP_SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
virtual void createLdapBasedn(ISecUser* user, const char* basedn, SecPermissionType ptype)
|
|
|
{
|
|
|
if(basedn == NULL || basedn[0] == '\0')
|
|
@@ -5037,7 +5053,7 @@ private:
|
|
|
ptr = comma + 1;
|
|
|
}
|
|
|
|
|
|
- if(ptr != NULL)
|
|
|
+ if (ptr && strstr(ptr,"ou=") && !organizationalUnitExists(ptr))
|
|
|
createLdapBasedn(user, ptr, ptype);
|
|
|
|
|
|
addOrganizationalUnit(user, oubuf.str(), ptr, ptype);
|
|
@@ -5055,6 +5071,9 @@ private:
|
|
|
StringBuffer dn;
|
|
|
dn.append("ou=").append(name).append(",").append(basedn);
|
|
|
|
|
|
+ if (organizationalUnitExists(dn.str()))
|
|
|
+ return true;
|
|
|
+
|
|
|
char *ou_values[] = {(char*)name, NULL };
|
|
|
LDAPMod ou_attr =
|
|
|
{
|