modified to use linked lists by jra.
*****************************************************************/
-/*****************************************************************
- Find a SID given a uid.
-*****************************************************************/
-
-static bool fetch_sid_from_uid_cache(struct dom_sid *psid, uid_t uid)
-{
- DATA_BLOB cache_value;
-
- if (!memcache_lookup(NULL, UID_SID_CACHE,
- data_blob_const(&uid, sizeof(uid)),
- &cache_value)) {
- return false;
- }
-
- memcpy(psid, cache_value.data, MIN(sizeof(*psid), cache_value.length));
- SMB_ASSERT(cache_value.length >= offsetof(struct dom_sid, id_auth));
- SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, 0));
-
- return true;
-}
-
-/*****************************************************************
- Find a uid given a SID.
-*****************************************************************/
-
-static bool fetch_uid_from_cache( uid_t *puid, const struct dom_sid *psid )
-{
- DATA_BLOB cache_value;
-
- if (!memcache_lookup(NULL, SID_UID_CACHE,
- data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
- &cache_value)) {
- return false;
- }
-
- SMB_ASSERT(cache_value.length == sizeof(*puid));
- memcpy(puid, cache_value.data, sizeof(*puid));
-
- return true;
-}
-
-/*****************************************************************
- Store uid to SID mapping in cache.
-*****************************************************************/
-
-void store_uid_sid_cache(const struct dom_sid *psid, uid_t uid)
-{
- memcache_add(NULL, SID_UID_CACHE,
- data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
- data_blob_const(&uid, sizeof(uid)));
- memcache_add(NULL, UID_SID_CACHE,
- data_blob_const(&uid, sizeof(uid)),
- data_blob_const(psid, ndr_size_dom_sid(psid, 0)));
-}
-
-/*****************************************************************
- Find a SID given a gid.
-*****************************************************************/
-
-static bool fetch_sid_from_gid_cache(struct dom_sid *psid, gid_t gid)
-{
- DATA_BLOB cache_value;
-
- if (!memcache_lookup(NULL, GID_SID_CACHE,
- data_blob_const(&gid, sizeof(gid)),
- &cache_value)) {
- return false;
- }
-
- memcpy(psid, cache_value.data, MIN(sizeof(*psid), cache_value.length));
- SMB_ASSERT(cache_value.length >= offsetof(struct dom_sid, id_auth));
- SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, 0));
-
- return true;
-}
-
-/*****************************************************************
- Find a gid given a SID.
-*****************************************************************/
-
-static bool fetch_gid_from_cache(gid_t *pgid, const struct dom_sid *psid)
-{
- DATA_BLOB cache_value;
-
- if (!memcache_lookup(NULL, SID_GID_CACHE,
- data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
- &cache_value)) {
- return false;
- }
-
- SMB_ASSERT(cache_value.length == sizeof(*pgid));
- memcpy(pgid, cache_value.data, sizeof(*pgid));
-
- return true;
-}
-
-/*****************************************************************
- Store gid to SID mapping in cache.
-*****************************************************************/
-
-void store_gid_sid_cache(const struct dom_sid *psid, gid_t gid)
-{
- memcache_add(NULL, SID_GID_CACHE,
- data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
- data_blob_const(&gid, sizeof(gid)));
- memcache_add(NULL, GID_SID_CACHE,
- data_blob_const(&gid, sizeof(gid)),
- data_blob_const(psid, ndr_size_dom_sid(psid, 0)));
-}
/*****************************************************************
*THE LEGACY* convert uid_t to SID function.
DEBUG(10,("LEGACY: uid %u -> sid %s\n", (unsigned int)uid,
sid_string_dbg(psid)));
- store_uid_sid_cache(psid, uid);
return;
}
DEBUG(10,("LEGACY: gid %u -> sid %s\n", (unsigned int)gid,
sid_string_dbg(psid)));
- store_gid_sid_cache(psid, gid);
return;
}
DEBUG(10,("LEGACY: sid %s -> uid %u\n", sid_string_dbg(psid),
(unsigned int)*puid ));
- store_uid_sid_cache(psid, *puid);
return true;
}
DEBUG(10,("LEGACY: sid %s -> gid %u\n", sid_string_dbg(psid),
(unsigned int)*pgid ));
- store_gid_sid_cache(psid, *pgid);
-
TALLOC_FREE(map);
return 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);
DEBUG(10,("uid %u -> sid %s\n", (unsigned int)uid,
sid_string_dbg(psid)));
- store_uid_sid_cache(psid, uid);
return;
}
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);
DEBUG(10,("gid %u -> sid %s\n", (unsigned int)gid,
sid_string_dbg(psid)));
- store_gid_sid_cache(psid, gid);
return;
}
bool expired;
uint32_t rid;
- if (fetch_uid_from_cache(&ids[i].id.uid, &sids[i])) {
- ids[i].type = WBC_ID_TYPE_UID;
- continue;
- }
- if (fetch_gid_from_cache(&ids[i].id.gid, &sids[i])) {
- ids[i].type = WBC_ID_TYPE_GID;
- continue;
- }
if (sid_peek_check_rid(&global_sid_Unix_Users,
&sids[i], &rid)) {
ids[i].type = WBC_ID_TYPE_UID;
uint32 rid;
gid_t gid;
- if (fetch_uid_from_cache(puid, psid))
- return true;
-
- if (fetch_gid_from_cache(&gid, psid)) {
- return false;
- }
-
/* Optimize for the Unix Users Domain
* as the conversion is straightforward */
if (sid_peek_check_rid(&global_sid_Unix_Users, psid, &rid)) {
DEBUG(10,("sid %s -> uid %u\n", sid_string_dbg(psid),
(unsigned int)*puid ));
- store_uid_sid_cache(psid, *puid);
return true;
}
uint32 rid;
uid_t uid;
- if (fetch_gid_from_cache(pgid, psid))
- return true;
-
- if (fetch_uid_from_cache(&uid, psid))
- return false;
-
/* Optimize for the Unix Groups Domain
* as the conversion is straightforward */
if (sid_peek_check_rid(&global_sid_Unix_Groups, psid, &rid)) {
DEBUG(10,("sid %s -> gid %u\n", sid_string_dbg(psid),
(unsigned int)*pgid ));
- store_gid_sid_cache(psid, *pgid);
return true;
}
goto fn_exit;
}
- store_uid_sid_cache(pdb_get_user_sid(sampass),
- sampass->unix_pw->pw_uid);
idmap_cache_set_sid2uid(pdb_get_user_sid(sampass),
sampass->unix_pw->pw_uid);
gid_to_sid(&mapped_gsid, sampass->unix_pw->pw_gid);
primary_gsid = pdb_get_group_sid(sampass);
if (primary_gsid && dom_sid_equal(primary_gsid, &mapped_gsid)) {
- store_gid_sid_cache(primary_gsid,
- sampass->unix_pw->pw_gid);
idmap_cache_set_sid2gid(primary_gsid,
sampass->unix_pw->pw_gid);
}
}
if (lp_parm_bool(-1, "ldapsam", "trusted", false)) {
- store_gid_sid_cache(&map->sid, map->gid);
idmap_cache_set_sid2gid(&map->sid, map->gid);
}
*gid = strtoul(gid_str, NULL, 10);
*type = (enum lsa_SidType)strtoul(value, NULL, 10);
- store_gid_sid_cache(sid, *gid);
idmap_cache_set_sid2gid(sid, *gid);
ret = True;
goto done;
*uid = strtoul(value, NULL, 10);
*type = SID_NAME_USER;
- store_uid_sid_cache(sid, *uid);
idmap_cache_set_sid2uid(sid, *uid);
ret = True;
sid_copy(sid, &user_sid);
- store_uid_sid_cache(sid, uid);
idmap_cache_set_sid2uid(sid, uid);
ret = true;
sid_copy(sid, &group_sid);
- store_gid_sid_cache(sid, gid);
idmap_cache_set_sid2gid(sid, gid);
ret = true;