idmap_cache: Introduce idmap_cache_find_xid2sid
authorVolker Lendecke <vl@samba.org>
Tue, 26 Feb 2019 13:32:52 +0000 (14:32 +0100)
committerVolker Lendecke <vl@samba.org>
Thu, 28 Feb 2019 12:57:24 +0000 (12:57 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13813

source3/lib/idmap_cache.c
source3/lib/idmap_cache.h

index 10c1e8b1e7a70df8f1714f40d38d2ebde9ef1b50..9d2149844ed76aa4ea77a91dde58151054c9c5e2 100644 (file)
@@ -277,6 +277,42 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired)
        return state.ret;
 }
 
+/**
+ * Find a xid2sid mapping
+ * @param[in] id               the unix id to map
+ * @param[out] sid             where to put the result
+ * @param[out] expired         is the cache entry expired?
+ * @retval Was anything in the cache at all?
+ *
+ * If "is_null_sid(sid)", this was a negative mapping.
+ */
+bool idmap_cache_find_xid2sid(
+       const struct unixid *id, struct dom_sid *sid, bool *expired)
+{
+       struct idmap_cache_xid2sid_state state = {
+               .sid = sid, .expired = expired
+       };
+       fstring key;
+       char c;
+
+       switch (id->type) {
+       case ID_TYPE_UID:
+               c = 'U';
+               break;
+       case ID_TYPE_GID:
+               c = 'G';
+               break;
+       default:
+               return false;
+       }
+
+       fstr_sprintf(key, "IDMAP/%cID2SID/%d", c, (int)id->id);
+
+       gencache_parse(key, idmap_cache_xid2sid_parser, &state);
+       return state.ret;
+}
+
+
 /**
  * Store a mapping in the idmap cache
  * @param[in] sid              the sid to map
index dc497022e3bb5e9a43cd719868cc22b555c71533..d5afa170e1a043f38ab89840ed1e5e14315842ac 100644 (file)
@@ -31,6 +31,8 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid,
                              bool *expired);
 bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired);
 bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired);
+bool idmap_cache_find_xid2sid(
+       const struct unixid *id, struct dom_sid *sid, bool *expired);
 void idmap_cache_set_sid2unixid(const struct dom_sid *sid, struct unixid *unix_id);
 
 bool idmap_cache_del_uid(uid_t uid);