コード例 #1
0
ファイル: idmap_cache.c プロジェクト: Alexandr-Galko/samba
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);
	}
}
コード例 #2
0
bool trustdom_cache_store(const char *name, const char *alt_name,
			  const struct dom_sid *sid, time_t timeout)
{
	char *key, *alt_key;
	fstring sid_string;
	bool ret;

	DEBUG(5, ("trustdom_store: storing SID %s of domain %s\n",
	          sid_string_dbg(sid), name));

	key = trustdom_cache_key(name);
	alt_key = alt_name ? trustdom_cache_key(alt_name) : NULL;

	/* Generate string representation domain SID */
	sid_to_fstring(sid_string, sid);

	/*
	 * try to put the names in the cache
	 */
	if (alt_key) {
		ret = gencache_set(alt_key, sid_string, timeout);
		if ( ret ) {
			ret = gencache_set(key, sid_string, timeout);
		}
		SAFE_FREE(alt_key);
		SAFE_FREE(key);
		return ret;
	}

	ret = gencache_set(key, sid_string, timeout);
	SAFE_FREE(key);
	return ret;
}
コード例 #3
0
ファイル: net_cache.c プロジェクト: jameshilliard/WECB-BH-GPL
/**
 * Add an entry to the cache. If it does exist, then set it.
 * 
 * @param argv key, value and timeout are passed in command line
 * @return 0 on success, otherwise failure
 **/
static int net_cache_add(int argc, const char **argv)
{
	const char *keystr, *datastr, *timeout_str;
	time_t timeout;
	
	if (argc < 3) {
		d_printf("\nUsage: net cache add <key string> <data string> <timeout>\n");
		return -1;
	}
	
	keystr = argv[0];
	datastr = argv[1];
	timeout_str = argv[2];
	
	/* parse timeout given in command line */
	timeout = parse_timeout(timeout_str);
	if (!timeout) {
		d_fprintf(stderr, "Invalid timeout argument.\n");
		return -1;
	}
	
	if (gencache_set(keystr, datastr, timeout)) {
		d_printf("New cache entry stored successfully.\n");
		gencache_shutdown();
		return 0;
	}
	
	d_fprintf(stderr, "Entry couldn't be added. Perhaps there's already such a key.\n");
	gencache_shutdown();
	return -1;
}
コード例 #4
0
ファイル: net_cache.c プロジェクト: AllardJ/Tomato
/**
 * Add an entry to the cache. If it does exist, then set it.
 *
 * @param c	A net_context structure
 * @param argv key, value and timeout are passed in command line
 * @return 0 on success, otherwise failure
 **/
static int net_cache_add(struct net_context *c, int argc, const char **argv)
{
	const char *keystr, *datastr, *timeout_str;
	time_t timeout;

	if (argc < 3 || c->display_usage) {
		d_printf("%s\n%s",
			 _("Usage:"),
			 _("net cache add <key string> <data string> "
			   "<timeout>\n"));
		return -1;
	}

	keystr = argv[0];
	datastr = argv[1];
	timeout_str = argv[2];

	/* parse timeout given in command line */
	timeout = parse_timeout(timeout_str);
	if (!timeout) {
		d_fprintf(stderr, _("Invalid timeout argument.\n"));
		return -1;
	}

	if (gencache_set(keystr, datastr, timeout)) {
		d_printf(_("New cache entry stored successfully.\n"));
		return 0;
	}

	d_fprintf(stderr, _("Entry couldn't be added. Perhaps there's already such a key.\n"));
	return -1;
}
コード例 #5
0
bool namecache_status_store(const char *keyname, int keyname_type,
                            int name_type, const struct sockaddr_storage *keyip,
                            const char *srvname)
{
    char *key;
    time_t expiry;
    bool ret;

    if (!gencache_init()) {
        return False;
    }

    key = namecache_status_record_key(keyname, keyname_type,
                                      name_type, keyip);
    if (!key)
        return False;

    expiry = time(NULL) + lp_name_cache_timeout();
    ret = gencache_set(key, srvname, expiry);

    if (ret) {
        DEBUG(5, ("namecache_status_store: entry %s -> %s\n",
                  key, srvname ));
    } else {
        DEBUG(5, ("namecache_status_store: entry %s store failed.\n",
                  key ));
    }

    SAFE_FREE(key);
    return ret;
}
コード例 #6
0
bool trustdom_cache_store_timestamp( uint32 t, time_t timeout )
{
	fstring value;

	fstr_sprintf(value, "%d", t );

	if (!gencache_set(TDOMTSKEY, value, timeout)) {
		DEBUG(5, ("failed to set timestamp for trustdom_cache\n"));
		return False;
	} 

	return True;
}
コード例 #7
0
ファイル: wins_srv.c プロジェクト: Arkhont/samba
/*
  mark a wins server as temporarily dead
*/
void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip)
{
	char *keystr;

	if (is_zero_ip_v4(wins_ip) || wins_srv_is_dead(wins_ip, src_ip))
		return;

	keystr = wins_srv_keystr(wins_ip, src_ip);

	gencache_set(keystr, "DOWN", time(NULL) + DEATH_TIME);

	SAFE_FREE(keystr);

	DEBUG(4,("Marking wins server %s dead for %u seconds from source %s\n",
		 inet_ntoa(wins_ip), DEATH_TIME, inet_ntoa(src_ip)));
}
コード例 #8
0
static void store_map_in_gencache(TALLOC_CTX *ctx, const char *from, const char *to)
{
	char *key;
	int cache_time = lp_username_map_cache_time();

	if (cache_time == 0) {
		return;
	}

	key = talloc_asprintf_strupper_m(ctx, "USERNAME_MAP/%s",
					 from);
        if (key == NULL) {
                return;
        }
	gencache_set(key, to, cache_time + time(NULL));
	TALLOC_FREE(key);
}
コード例 #9
0
bool namecache_store(const char *name,
                     int name_type,
                     int num_names,
                     struct ip_service *ip_list)
{
    time_t expiry;
    char *key, *value_string;
    int i;
    bool ret;

    /*
     * we use gecache call to avoid annoying debug messages about
     * initialised namecache again and again...
     */
    if (!gencache_init()) {
        return False;
    }

    if (name_type > 255) {
        return False; /* Don't store non-real name types. */
    }

    if ( DEBUGLEVEL >= 5 ) {
        TALLOC_CTX *ctx = talloc_stackframe();
        char *addr = NULL;

        DEBUG(5, ("namecache_store: storing %d address%s for %s#%02x: ",
                  num_names, num_names == 1 ? "": "es", name, name_type));

        for (i = 0; i < num_names; i++) {
            addr = print_canonical_sockaddr(ctx,
                                            &ip_list[i].ss);
            if (!addr) {
                continue;
            }
            DEBUGADD(5, ("%s%s", addr,
                         (i == (num_names - 1) ? "" : ",")));

        }
        DEBUGADD(5, ("\n"));
        TALLOC_FREE(ctx);
    }

    key = namecache_key(name, name_type);
    if (!key) {
        return False;
    }

    expiry = time(NULL) + lp_name_cache_timeout();

    /*
     * Generate string representation of ip addresses list
     * First, store the number of ip addresses and then
     * place each single ip
     */
    if (!ipstr_list_make(&value_string, ip_list, num_names)) {
        SAFE_FREE(key);
        SAFE_FREE(value_string);
        return false;
    }

    /* set the entry */
    ret = gencache_set(key, value_string, expiry);
    SAFE_FREE(key);
    SAFE_FREE(value_string);
    return ret;
}