return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
-/* search the cache for the SID an return a mapping if found *
+/* search the cahce for the SID an return a mapping if found *
*
* 4 cases are possible
*
t = strtol((const char *)databuf.dptr, &endptr, 10);
if ((endptr == NULL) || (*endptr != '/')) {
- DEBUG(2, ("Invalid idmap cache data format: %s\n",
- (const char *)databuf.dptr));
+ DEBUG(2, ("Invalid gencache data format: %s\n", (const char *)databuf.dptr));
/* remove the entry */
tdb_delete_bystring(cache->tdb, sidkey);
ret = NT_STATUS_NONE_MAPPED;
/* Check for valid or expired cache hits */
- if (t <= now) {
+ if (t <= now) {
/* We're expired. Return not mapped */
- ret = NT_STATUS_NONE_MAPPED;
- } else {
- /* this is not mapped as it was a negative cache hit */
- id->status = ID_UNMAPPED;
- ret = NT_STATUS_OK;
- }
-
+ ret = NT_STATUS_NONE_MAPPED;
+ } else {
+ /* this is not mapped as it was a negative cache hit */
+ id->status = ID_UNMAPPED;
+ ret = NT_STATUS_OK;
+ }
+
done:
SAFE_FREE(databuf.dptr);
talloc_free(sidkey);
return ret;
}
-/* search the cache for the ID an return a mapping if found *
+/* search the cahce for the ID an return a mapping if found *
*
* 4 cases are possible
*
t = strtol((const char *)databuf.dptr, &endptr, 10);
if ((endptr == NULL) || (*endptr != '/')) {
- DEBUG(2, ("Invalid idmap cache data format: %s\n",
- (const char *)databuf.dptr));
+ DEBUG(2, ("Invalid gencache data format: %s\n", (const char *)databuf.dptr));
/* remove the entry */
tdb_delete_bystring(cache->tdb, idkey);
ret = NT_STATUS_NONE_MAPPED;
/* Process the negative cache hit */
- if (t <= now) {
+ if (t <= now) {
/* We're expired. Return not mapped */
- ret = NT_STATUS_NONE_MAPPED;
- } else {
+ ret = NT_STATUS_NONE_MAPPED;
+ } else {
/* this is not mapped is it was a negative cache hit */
- id->status = ID_UNMAPPED;
- ret = NT_STATUS_OK;
- }
+ id->status = ID_UNMAPPED;
+ ret = NT_STATUS_OK;
+ }
done:
SAFE_FREE(databuf.dptr);
return ret;
}
+bool idmap_cache_find_sid2uid(const struct dom_sid *sid, uid_t *puid,
+ bool *expired)
+{
+ fstring sidstr;
+ char *key;
+ char *value;
+ char *endptr;
+ time_t timeout;
+ uid_t uid;
+ bool ret;
+
+ key = talloc_asprintf(talloc_tos(), "IDMAP/SID2UID/%s",
+ sid_to_fstring(sidstr, sid));
+ if (key == NULL) {
+ return false;
+ }
+ ret = gencache_get(key, &value, &timeout);
+ TALLOC_FREE(key);
+ if (!ret) {
+ return false;
+ }
+ uid = strtol(value, &endptr, 10);
+ ret = (*endptr == '\0');
+ SAFE_FREE(value);
+ if (ret) {
+ *puid = uid;
+ *expired = (timeout <= time(NULL));
+ }
+ return ret;
+}
+
+bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
+{
+ char *key;
+ char *value;
+ time_t timeout;
+ bool ret;
+
+ key = talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid);
+ if (key == NULL) {
+ return false;
+ }
+ ret = gencache_get(key, &value, &timeout);
+ TALLOC_FREE(key);
+ if (!ret) {
+ return false;
+ }
+ ZERO_STRUCTP(sid);
+ ret = string_to_sid(sid, value);
+ SAFE_FREE(value);
+ if (ret) {
+ *expired = (timeout <= time(NULL));
+ }
+ return ret;
+}
+
+void idmap_cache_set_sid2uid(const struct dom_sid *sid, uid_t uid)
+{
+ time_t now = time(NULL);
+ time_t timeout;
+ fstring sidstr, key, value;
+
+ if (!is_null_sid(sid)) {
+ fstr_sprintf(key, "IDMAP/SID2UID/%s",
+ sid_to_fstring(sidstr, sid));
+ fstr_sprintf(value, "%d", (int)uid);
+ timeout = (uid == -1)
+ ? lp_idmap_negative_cache_time()
+ : lp_idmap_cache_time();
+ gencache_set(key, value, now + timeout);
+ }
+ if (uid != -1) {
+ fstr_sprintf(key, "IDMAP/UID2SID/%d", (int)uid);
+ sid_to_fstring(value, sid);
+ timeout = is_null_sid(sid)
+ ? lp_idmap_negative_cache_time()
+ : lp_idmap_cache_time();
+ gencache_set(key, value, now + timeout);
+ }
+}