diff options
Diffstat (limited to 'source/passdb/lookup_sid.c')
-rw-r--r-- | source/passdb/lookup_sid.c | 130 |
1 files changed, 33 insertions, 97 deletions
diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c index 3861c8e229..a7175b9647 100644 --- a/source/passdb/lookup_sid.c +++ b/source/passdb/lookup_sid.c @@ -1286,37 +1286,20 @@ static bool legacy_sid_to_gid(const DOM_SID *psid, gid_t *pgid) void uid_to_sid(DOM_SID *psid, uid_t uid) { - bool expired = true; - bool ret; ZERO_STRUCTP(psid); if (fetch_sid_from_uid_cache(psid, uid)) return; - /* Check the winbindd cache directly. */ - ret = idmap_cache_find_uid2sid(uid, psid, &expired); - - if (ret && !expired && is_null_sid(psid)) { - /* - * Negative cache entry, we already asked. - * do legacy. - */ - legacy_uid_to_sid(psid, uid); - return; - } - - if (!ret || expired) { - /* Not in cache. Ask winbindd. */ - if (!winbind_uid_to_sid(psid, uid)) { - if (!winbind_ping()) { - legacy_uid_to_sid(psid, uid); - return; - } - - DEBUG(5, ("uid_to_sid: winbind failed to find a sid for uid %u\n", - uid)); + if (!winbind_uid_to_sid(psid, uid)) { + if (!winbind_ping()) { + legacy_uid_to_sid(psid, uid); return; } + + DEBUG(5, ("uid_to_sid: winbind failed to find a sid for uid %u\n", + uid)); + return; } DEBUG(10,("uid %u -> sid %s\n", (unsigned int)uid, @@ -1332,42 +1315,25 @@ void uid_to_sid(DOM_SID *psid, uid_t uid) void gid_to_sid(DOM_SID *psid, gid_t gid) { - bool expired = true; - bool ret; ZERO_STRUCTP(psid); if (fetch_sid_from_gid_cache(psid, gid)) return; - /* Check the winbindd cache directly. */ - ret = idmap_cache_find_gid2sid(gid, psid, &expired); - - if (ret && !expired && is_null_sid(psid)) { - /* - * Negative cache entry, we already asked. - * do legacy. - */ - legacy_gid_to_sid(psid, gid); - return; - } - - if (!ret || expired) { - /* Not in cache. Ask winbindd. */ - if (!winbind_gid_to_sid(psid, gid)) { - if (!winbind_ping()) { - legacy_gid_to_sid(psid, gid); - return; - } - - DEBUG(5, ("gid_to_sid: winbind failed to find a sid for gid %u\n", - gid)); + if (!winbind_gid_to_sid(psid, gid)) { + if (!winbind_ping()) { + legacy_gid_to_sid(psid, gid); return; } + + DEBUG(5, ("gid_to_sid: winbind failed to find a sid for gid %u\n", + gid)); + return; } DEBUG(10,("gid %u -> sid %s\n", (unsigned int)gid, sid_string_dbg(psid))); - + store_gid_sid_cache(psid, gid); return; } @@ -1378,8 +1344,6 @@ void gid_to_sid(DOM_SID *psid, gid_t gid) bool sid_to_uid(const DOM_SID *psid, uid_t *puid) { - bool expired = true; - bool ret; uint32 rid; gid_t gid; @@ -1402,28 +1366,14 @@ bool sid_to_uid(const DOM_SID *psid, uid_t *puid) return true; } - /* Check the winbindd cache directly. */ - ret = idmap_cache_find_sid2uid(psid, puid, &expired); - - if (ret && !expired && (*puid == (uid_t)-1)) { - /* - * Negative cache entry, we already asked. - * do legacy. - */ - return legacy_sid_to_uid(psid, puid); - } - - if (!ret || expired) { - /* Not in cache. Ask winbindd. */ - if (!winbind_sid_to_uid(puid, psid)) { - if (!winbind_ping()) { - return legacy_sid_to_uid(psid, puid); - } - - DEBUG(5, ("winbind failed to find a uid for sid %s\n", - sid_string_dbg(psid))); - return false; + if (!winbind_sid_to_uid(puid, psid)) { + if (!winbind_ping()) { + return legacy_sid_to_uid(psid, puid); } + + DEBUG(5, ("winbind failed to find a uid for sid %s\n", + sid_string_dbg(psid))); + return false; } /* TODO: Here would be the place to allocate both a gid and a uid for @@ -1443,8 +1393,6 @@ bool sid_to_uid(const DOM_SID *psid, uid_t *puid) bool sid_to_gid(const DOM_SID *psid, gid_t *pgid) { - bool expired = true; - bool ret; uint32 rid; uid_t uid; @@ -1466,36 +1414,24 @@ bool sid_to_gid(const DOM_SID *psid, gid_t *pgid) return true; } - /* Check the winbindd cache directly. */ - ret = idmap_cache_find_sid2gid(psid, pgid, &expired); + /* Ask winbindd if it can map this sid to a gid. + * (Idmap will check it is a valid SID and of the right type) */ - if (ret && !expired && (*pgid == (gid_t)-1)) { - /* - * Negative cache entry, we already asked. - * do legacy. - */ - return legacy_sid_to_gid(psid, pgid); - } - - if (!ret || expired) { - /* Not in cache or negative. Ask winbindd. */ - /* Ask winbindd if it can map this sid to a gid. - * (Idmap will check it is a valid SID and of the right type) */ - - if ( !winbind_sid_to_gid(pgid, psid) ) { - if (!winbind_ping()) { - return legacy_sid_to_gid(psid, pgid); - } - - DEBUG(10,("winbind failed to find a gid for sid %s\n", - sid_string_dbg(psid))); - return false; + if ( !winbind_sid_to_gid(pgid, psid) ) { + if (!winbind_ping()) { + return legacy_sid_to_gid(psid, pgid); } + + DEBUG(10,("winbind failed to find a gid for sid %s\n", + sid_string_dbg(psid))); + return false; } DEBUG(10,("sid %s -> gid %u\n", sid_string_dbg(psid), (unsigned int)*pgid )); store_gid_sid_cache(psid, *pgid); + return true; } + |