Example #1
0
void idmap_cache_set_sid2gid(const struct dom_sid *sid, gid_t gid)
{
	time_t now = time(NULL);
	time_t timeout;
	fstring sidstr, key, value;

	if (!is_null_sid(sid)) {
		fstr_sprintf(key, "IDMAP/SID2GID/%s",
			     sid_to_fstring(sidstr, sid));
		fstr_sprintf(value, "%d", (int)gid);
		timeout = (gid == -1)
			? lp_idmap_negative_cache_time()
			: lp_idmap_cache_time();
		gencache_set(key, value, now + timeout);
	}
	if (gid != -1) {
		fstr_sprintf(key, "IDMAP/GID2SID/%d", (int)gid);
		if (is_null_sid(sid)) {
			/* negative gid mapping */
			fstrcpy(value, "-");
			timeout = lp_idmap_negative_cache_time();
		}
		else {
			sid_to_fstring(value, sid);
			timeout = lp_idmap_cache_time();
		}
		gencache_set(key, value, now + timeout);
	}
}
Example #2
0
NTSTATUS idmap_cache_set_negative_id(struct idmap_cache_ctx *cache, const struct id_map *id)
{
	NTSTATUS ret;
	time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
	TDB_DATA keybuf, databuf;
	char *idkey;
	char *valstr;

	ret = idmap_cache_build_idkey(cache, &idkey, id);
	if (!NT_STATUS_IS_OK(ret)) return ret;

	/* use idkey as the local memory ctx */
	valstr = talloc_asprintf(idkey, IDMAP_CACHE_DATA_FMT, (int)timeout, "IDMAP/NEGATIVE");
	if (!valstr) {
		DEBUG(0, ("Out of memory!\n"));
		ret = NT_STATUS_NO_MEMORY;
		goto done;
	}

	keybuf.dptr = idkey;
	keybuf.dsize = strlen(idkey)+1;
	databuf.dptr = valstr;
	databuf.dsize = strlen(valstr)+1;
	DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
	           " %s (%d seconds %s)\n", keybuf.dptr, valstr, ctime(&timeout),
		   (int)(timeout - time(NULL)), 
		   timeout > time(NULL) ? "ahead" : "in the past"));

	if (tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE) != 0) {
		DEBUG(3, ("Failed to store cache entry!\n"));
		ret = NT_STATUS_UNSUCCESSFUL;
		goto done;
	}

done:
	talloc_free(idkey);
	return ret;
}