BOOL namecache_enable(void) { /* Check if we have been here before, or name caching disabled by setting the name cache timeout to zero. */ if (done_namecache_init) return False; done_namecache_init = True; if (lp_name_cache_timeout() == 0) { DEBUG(5, ("namecache_init: disabling netbios name cache\n")); return False; } /* Open namecache tdb in read/write or readonly mode */ namecache_tdb = tdb_open_log( lock_path("namecache.tdb"), 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644); if (!namecache_tdb) { DEBUG(5, ("namecache_init: could not open %s\n", lock_path("namecache.tdb"))); return False; } DEBUG(5, ("namecache_init: enabling netbios namecache, timeout %d " "seconds\n", lp_name_cache_timeout())); enable_namecache = True; return True; }
bool namecache_enable(void) { /* * Check if name caching disabled by setting the name cache * timeout to zero. */ if (lp_name_cache_timeout() == 0) { DEBUG(5, ("namecache_enable: disabling netbios name cache\n")); return False; } /* Init namecache by calling gencache initialisation */ if (!gencache_init()) { DEBUG(2, ("namecache_enable: " "Couldn't initialise namecache on top of gencache.\n")); return False; } /* I leave it for now, though I don't think we really * need this (mimir, 27.09.2002) */ DEBUG(5, ("namecache_enable: enabling netbios namecache, timeout %d " "seconds\n", lp_name_cache_timeout())); return True; }
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; }
void namecache_store(const char *name, int name_type, int num_names, struct in_addr *ip_list) { TDB_DATA key, value; time_t expiry; int i; if (!enable_namecache) return; 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++) DEBUGADD(5, ("%s%s", inet_ntoa(ip_list[i]), i == (num_names - 1) ? "" : ", ")); DEBUGADD(5, ("\n")); key = namecache_key(name, name_type); /* Cache pdc location or dc lists for only a little while otherwise if we lock on to a bad DC we can potentially be out of action for the entire cache timeout time! */ if (name_type != 0x1b || name_type != 0x1c) expiry = time(NULL) + 10; else expiry = time(NULL) + lp_name_cache_timeout(); value = namecache_value(ip_list, num_names, expiry); tdb_store(namecache_tdb, key, value, TDB_REPLACE); free(key.dptr); free(value.dptr); }
BOOL namecache_fetch(const char *name, int name_type, struct in_addr **ip_list, int *num_names) { TDB_DATA key, value; struct nc_value *data = NULL; time_t now; int i; *ip_list = NULL; *num_names = 0; if (!enable_namecache) return False; /* Read value */ key = namecache_key(name, name_type); value = tdb_fetch(namecache_tdb, key); if (!value.dptr) { DEBUG(5, ("namecache_fetch: %s#%02x not found\n", name, name_type)); goto done; } data = (struct nc_value *)value.dptr; /* Check expiry time */ now = time(NULL); if (now > data->expiry) { DEBUG(5, ("namecache_fetch: entry for %s#%02x expired\n", name, name_type)); tdb_delete(namecache_tdb, key); SAFE_FREE(value.dptr); value = tdb_null; goto done; } if ((data->expiry - now) > lp_name_cache_timeout()) { /* Someone may have changed the system time on us */ DEBUG(5, ("namecache_fetch: entry for %s#%02x has bad expiry\n", name, name_type)); tdb_delete(namecache_tdb, key); SAFE_FREE(value.dptr); value = tdb_null; goto done; } /* Extract and return namelist */ DEBUG(5, ("namecache_fetch: returning %d address%s for %s#%02x: ", data->count, data->count == 1 ? "" : "es", name, name_type)); if (data->count) { *ip_list = (struct in_addr *)malloc( sizeof(struct in_addr) * data->count); memcpy(*ip_list, data->ip_list, sizeof(struct in_addr) * data->count); *num_names = data->count; for (i = 0; i < *num_names; i++) DEBUGADD(5, ("%s%s", inet_ntoa((*ip_list)[i]), i == (*num_names - 1) ? "" : ", ")); } DEBUGADD(5, ("\n")); done: SAFE_FREE(key.dptr); SAFE_FREE(value.dptr); return value.dsize > 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; }