diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/libsmb/namecache.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/source3/libsmb/namecache.c b/source3/libsmb/namecache.c index 31341df86e..2252e8e59c 100644 --- a/source3/libsmb/namecache.c +++ b/source3/libsmb/namecache.c @@ -34,19 +34,19 @@ struct nc_value { /* Initialise namecache system */ -void namecache_enable(void) +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; + return False; done_namecache_init = True; if (lp_name_cache_timeout() == 0) { DEBUG(5, ("namecache_init: disabling netbios name cache\n")); - return; + return False; } /* Open namecache tdb in read/write or readonly mode */ @@ -58,13 +58,15 @@ void namecache_enable(void) if (!namecache_tdb) { DEBUG(5, ("namecache_init: could not open %s\n", lock_path("namecache.tdb"))); - return; + return False; } DEBUG(5, ("namecache_init: enabling netbios namecache, timeout %d " "seconds\n", lp_name_cache_timeout())); enable_namecache = True; + + return True; } /* Return a key for a name and name type. The caller must free @@ -104,7 +106,7 @@ static TDB_DATA namecache_value(struct in_addr *ip_list, int num_names, value->count = num_names; if (ip_list) - memcpy(value->ip_list, ip_list, sizeof(*ip_list)); + memcpy(value->ip_list, ip_list, sizeof(struct in_addr) * num_names); retval.dptr = (char *)value; retval.dsize = size; @@ -163,6 +165,9 @@ BOOL namecache_fetch(const char *name, int name_type, struct in_addr **ip_list, time_t now; int i; + *ip_list = NULL; + *num_names = 0; + if (!enable_namecache) return False; @@ -212,20 +217,23 @@ BOOL namecache_fetch(const char *name, int name_type, struct in_addr **ip_list, /* Extract and return namelist */ - *ip_list = (struct in_addr *)malloc( - sizeof(struct in_addr) * (data->count-1)); - - memcpy(*ip_list, data->ip_list, sizeof(struct in_addr) * - (data->count-1)); + DEBUG(5, ("namecache_fetch: returning %d address%s for %s#%02x: ", + data->count, data->count == 1 ? "" : "es", name, name_type)); - *num_names = data->count; + if (data->count) { - DEBUG(5, ("namecache_fetch: returning %d address%s for %s#%02x: ", - *num_names, *num_names == 1 ? "" : "es", name, name_type)); + *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) ? "" : ", ")); - for (i = 0; i < *num_names; i++) - DEBUGADD(5, ("%s%s", inet_ntoa((*ip_list)[i]), - i == (*num_names - 1) ? "" : ", ")); + } DEBUGADD(5, ("\n")); |