Skip to content

memberOf plugin :: mbof_add_operation() optimizations#8464

Open
alexey-tikhonov wants to merge 3 commits intoSSSD:masterfrom
alexey-tikhonov:mbof-add
Open

memberOf plugin :: mbof_add_operation() optimizations#8464
alexey-tikhonov wants to merge 3 commits intoSSSD:masterfrom
alexey-tikhonov:mbof-add

Conversation

@alexey-tikhonov
Copy link
Member

@alexey-tikhonov alexey-tikhonov commented Feb 18, 2026

Using the same test case as described in #8454 and testing on top of that PR:

  • users tu1 and tu2 are members of the same 5k LDAP groups (RFC2307 case, no nested groups)
  • SSSD stared with an empty cache
  • time id [email protected] | tr ',' '\n' | wc -l and then time id [email protected] | tr ',' '\n' | wc -l are executed

This patch set reduces time spent by id tu1 from 27 to 8 seconds and by consequent id tu2 from 23 to 5 seconds on my laptop.

gemini-code-assist[bot]

This comment was marked as outdated.

@alexey-tikhonov alexey-tikhonov added the Performance Performance related patches label Feb 18, 2026
@alexey-tikhonov alexey-tikhonov force-pushed the mbof-add branch 2 times, most recently from 9b17f9b to e35eab4 Compare February 25, 2026 17:53
@alexey-tikhonov
Copy link
Member Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several optimizations to the mbof_add_operation() function in the memberof plugin. The changes include a more efficient way to remove duplicate entries from an array and the removal of a redundant check, both of which are good improvements. However, one of the optimizations replaces ldb_dn_compare() with strcmp() for checking DN equality. This is a critical issue as strcmp() performs a case-sensitive comparison, which is incorrect for DNs and can lead to failing to detect duplicates. This could cause data inconsistencies by allowing duplicate memberof values. I have added a review comment with a suggestion to fix this.

@alexey-tikhonov
Copy link
Member Author

(rebased)

@alexey-tikhonov
Copy link
Member Author

Replaced strcmp() with strcasecmp().

If I read rfc4519 correctly:

( 2.5.4.3 NAME 'cn'
 SUP name )

( 2.5.4.41 NAME 'name'
 EQUALITY caseIgnoreMatch
 SUBSTR caseIgnoreSubstringsMatch
 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )

-- EQUALITY caseIgnoreMatch is mandated for any compliant LDAP server.

@sumit-bose
Copy link
Contributor

Hi,

about EQUALITY caseIgnoreMatch I agree that base on that it should not be possible to add two objects with the cn RDN to the same sub-tree where the attribute value only differ in case for compliant LDAP servers. And although the majority of our data sources will be LDAP servers which are at least compliant in this respect there are other data sources e.g. via the proxy provider. I would even agree that if the sources allows to e.g. create different users where the name can only differ in the case, it is still a bad idea to do so. But currently the cache allows to store such objects:

[root@client /]# ldbsearch -H /var/lib/sss/db/cache_ipa.test.ldb [email protected] dn name
asq: Unable to register control with rootdse!
# record 1
dn: [email protected],cn=users,cn=ipa.test,cn=sysdb
name: [email protected]

# record 2
dn: [email protected],cn=users,cn=ipa.test,cn=sysdb
name: [email protected]

# returned 2 records
# 2 entries
# 0 referrals

and this is only true for the name attribute. If you try to add something where a cn attribute differs in spelling you get

[root@client /]# ldbadd -H /var/lib/sss/db/cache_ipa.test.ldb /tmp/bla.ldif 
asq: Unable to register control with rootdse!
ERR: Entry already exists : "Entry [email protected],cn=USERS,cn=ipa.test,cn=sysdb already exists" on DN [email protected],cn=USERS,cn=ipa.test,cn=sysdb at block before line 90
Add failed after processing 0 records

which is because of https://github.com/SSSD/sssd/blob/master/src/db/sysdb_private.h#L58. For name there is no such line.

Long story short, since the cache handles the name attributes case-sensitive in DNs I think this should be respected in the comparison here as well. But I think we also can safely assume that name is only used in the most specific RDN and it might help to speed things up to do this additional check only if strcasecmp() returns 0 which should be a rare case if I understand it correctly.

HTH

bye,
Sumit

'msg->dn' (== 'addop->entry_dn') is already filtered out from 'parents->dns[i]'
at the beginning of `mbof_add_operation()`
when removing a duplicate. DNs order doesn't matter.
@alexey-tikhonov
Copy link
Member Author

(rebased)

`ldb_dn_compare()` here is heavy because when DNs are not equal (vast majority of cases),
it performs `ldb_dn_casefold_internal()` to return -1 or 1, but it's not important in
this context.

Note that in general using `str*cmp()` instead of `ldb_dn_get_linearized()` might yield
incorrect results due to different DN representations.
But since all 'memberof' DNs originate from sysdb cache / memberof plugin itself, it
should be safe replacement in this context.
@alexey-tikhonov
Copy link
Member Author

Thank you.

I think we also can safely assume that name is only used in the most specific RDN and it might help to speed things up to do this additional check only if strcasecmp() returns 0

I have implemented this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants