Commit 05b2773a authored by jan.koester's avatar jan.koester
Browse files

ad: session groups from the group's member list too, not only memberOf

dirMemberships() walked only the memberOf back link. A membership written
to the group alone (member attribute: LDAP modify, import, replication)
left the session without that group although the web console, which
reads member, showed it -- proxyplus then refused the SMTP relay for
noreply with groups=[]. Now groups naming the object (or a group it is
in) through member count as well, at every nesting level.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent bcbee4c1
Loading
Loading
Loading
Loading
Loading
+21 −2
Changes for plugin/ad/ad.cpp: 21 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -888,11 +888,29 @@ bool ActiveDirectory::dirMemberships(const std::string &domain, const uuid::uuid
    if (!e) { err = "object not found"; return false; }

    groups.clear();
    /* transitive walk over memberOf: a user's groups, plus the groups those
     * groups belong to (nested) */
    /* transitive walk: a user's groups, plus the groups those groups belong
     * to (nested). Both link directions count: the memberOf back link on the
     * object, and groups whose forward link (member) names the object. A
     * membership written to the group alone (LDAP modify on member, an
     * import, replication) used to leave memberOf unset, and the session then
     * carried no groups although the admin UI -- which reads member -- showed
     * the user in the group (proxyplus SMTP relay: groups=[]). */
    const dsdb::Filter isGroup = dsdb::Filter::equal("objectClass", "group");
    auto groupsNaming = [&](const std::string &dn, std::vector<std::string> &into) {
        dsdb::Filter f;
        f.type = dsdb::Filter::And;
        f.children.push_back(isGroup);
        f.children.push_back(dsdb::Filter::equal("member", dn));
        d->dir->search(d->meta.baseDn, LDAP_SCOPE_SUBTREE, f, [&](const dsdb::Entry &g) -> bool {
            into.push_back(g.dn.str());
            return true;
        });
    };

    std::vector<std::string> work;
    if (auto *mo = e->get("memberOf"))
        work = *mo;
    groupsNaming(e->dn.str(), work);
    std::map<std::string, bool, dsdb::CaseLess> seen;
    while (!work.empty()) {
        std::string cur = work.back();
@@ -906,6 +924,7 @@ bool ActiveDirectory::dirMemberships(const std::string &domain, const uuid::uuid
        groups.push_back(g->objectGuid);
        if (auto *mo2 = g->get("memberOf"))
            for (auto &v : *mo2) work.push_back(v);
        groupsNaming(g->dn.str(), work);
    }
    return true;
}