summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-08-28 00:17:11 +0000
committerTim Potter <tpot@samba.org>2002-08-28 00:17:11 +0000
commitb42229c2d8f505470b7b5c1e0d74cf36438d6de7 (patch)
treeba8d4dd23d06f6b0cd575713d5a9409f03b0a801 /source3
parent28a7d0f50681df15d68edeab4a9a428e1d2545d4 (diff)
downloadsamba-b42229c2d8f505470b7b5c1e0d74cf36438d6de7.tar.gz
samba-b42229c2d8f505470b7b5c1e0d74cf36438d6de7.tar.bz2
samba-b42229c2d8f505470b7b5c1e0d74cf36438d6de7.zip
Sync up namecache code with HEAD and APPLIANCE_HEAD. Rerun unit tests.
(This used to be commit 41c2e7b162224a524a1bf4da012f383f2a6032d0)
Diffstat (limited to 'source3')
-rw-r--r--source3/libsmb/namecache.c40
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"));