From 86d09ce779fdc9d6ebbbe44b25656808ab37ee14 Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Thu, 21 Feb 2013 12:30:48 -0700 Subject: s3-winbindd: Move common code for LDAP id mapping to idmap_utils idmap_ad and idmap_ldap use the same helper functions and the same maximum query size. Move the code to idmap_utils so that it can be shared by every module issuing LDAP queries. Reviewed-by: Andrew Bartlett --- source3/winbindd/idmap_util.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source3/winbindd/idmap_util.c') diff --git a/source3/winbindd/idmap_util.c b/source3/winbindd/idmap_util.c index 9d9ada7199..cbad91d151 100644 --- a/source3/winbindd/idmap_util.c +++ b/source3/winbindd/idmap_util.c @@ -172,3 +172,44 @@ bool idmap_unix_id_is_in_range(uint32_t id, struct idmap_domain *dom) return true; } + +/** + * Helper for unixids_to_sids: find entry by id in mapping array, + * search up to IDMAP_AD_MAX_IDS entries + */ +struct id_map *idmap_find_map_by_id(struct id_map **maps, enum id_type type, + uint32_t id) +{ + int i; + + for (i = 0; i < IDMAP_LDAP_MAX_IDS; i++) { + if (maps[i] == NULL) { /* end of the run */ + return NULL; + } + if ((maps[i]->xid.type == type) && (maps[i]->xid.id == id)) { + return maps[i]; + } + } + + return NULL; +} + +/** + * Helper for sids_to_unix_ids: find entry by SID in mapping array, + * search up to IDMAP_AD_MAX_IDS entries + */ +struct id_map *idmap_find_map_by_sid(struct id_map **maps, struct dom_sid *sid) +{ + int i; + + for (i = 0; i < IDMAP_LDAP_MAX_IDS; i++) { + if (maps[i] == NULL) { /* end of the run */ + return NULL; + } + if (dom_sid_equal(maps[i]->sid, sid)) { + return maps[i]; + } + } + + return NULL; +} -- cgit