Skip to content

Commit 415850a

Browse files
SYSDB: lightweight sysdb_entry_in_cache() helper
Unlike `sysdb_search_*_by_name()`, which does filter sanitization, subtree search with filter evaluation, and timestamp attribute merge, this helper constructs the DN directly and performs a base-scoped ldb_search with no attributes. This makes it suitable for callers that only need to check entry existence in the cache. Implementation assisted-by: Claude Code (Opus 4.6)
1 parent c6dc4d7 commit 415850a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/db/sysdb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,10 @@ int sysdb_search_group_by_name(TALLOC_CTX *mem_ctx,
10821082
const char **attrs,
10831083
struct ldb_message **msg);
10841084

1085+
bool sysdb_entry_in_cache(struct sss_domain_info *domain,
1086+
const char *name,
1087+
enum sysdb_obj_type type);
1088+
10851089
int sysdb_search_group_by_gid(TALLOC_CTX *mem_ctx,
10861090
struct sss_domain_info *domain,
10871091
gid_t gid,

src/db/sysdb_ops.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,46 @@ int sysdb_search_group_by_name(TALLOC_CTX *mem_ctx,
796796
return sysdb_search_by_name(mem_ctx, domain, name, SYSDB_GROUP, attrs, msg);
797797
}
798798

799+
bool sysdb_entry_in_cache(struct sss_domain_info *domain,
800+
const char *name,
801+
enum sysdb_obj_type type)
802+
{
803+
static const char *no_attrs[] = { NULL };
804+
TALLOC_CTX *tmp_ctx;
805+
struct ldb_dn *dn;
806+
struct ldb_result *res;
807+
int lret;
808+
809+
tmp_ctx = talloc_new(NULL);
810+
if (tmp_ctx == NULL) {
811+
return false;
812+
}
813+
814+
switch (type) {
815+
case SYSDB_USER:
816+
dn = sysdb_user_dn(tmp_ctx, domain, name);
817+
break;
818+
case SYSDB_GROUP:
819+
dn = sysdb_group_dn(tmp_ctx, domain, name);
820+
break;
821+
default:
822+
dn = NULL;
823+
break;
824+
}
825+
826+
if (dn == NULL) {
827+
talloc_free(tmp_ctx);
828+
return false;
829+
}
830+
831+
lret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res, dn,
832+
LDB_SCOPE_BASE, no_attrs, NULL);
833+
834+
talloc_free(tmp_ctx);
835+
836+
return lret == LDB_SUCCESS && res->count == 1;
837+
}
838+
799839
static int
800840
sysdb_search_group_by_id(TALLOC_CTX *mem_ctx,
801841
struct sss_domain_info *domain,

0 commit comments

Comments
 (0)