/* Inner loops of cache daemon.
- Copyright (C) 1998-2003, 2004, 2005, 2006, 2007, 2008
- Free Software Foundation, Inc.
+ Copyright (C) 1998-2007, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
.propagate = 1,
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
- .reset_res = 0,
+ .suggested_module = DEFAULT_SUGGESTED_MODULE,
+ .reset_res = 0,
.filename = "/etc/passwd",
.db_filename = _PATH_NSCD_PASSWD_DB,
.disabled_iov = &pwd_iov_disabled,
.propagate = 1,
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
+ .suggested_module = DEFAULT_SUGGESTED_MODULE,
.reset_res = 0,
.filename = "/etc/group",
.db_filename = _PATH_NSCD_GROUP_DB,
.propagate = 0, /* Not used. */
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
+ .suggested_module = DEFAULT_SUGGESTED_MODULE,
.reset_res = 1,
.filename = "/etc/hosts",
.db_filename = _PATH_NSCD_HOSTS_DB,
.propagate = 0, /* Not used. */
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
+ .suggested_module = DEFAULT_SUGGESTED_MODULE,
.reset_res = 0,
.filename = "/etc/services",
.db_filename = _PATH_NSCD_SERVICES_DB,
struct database_pers_head head_copy = *head;
/* Check that the header that was read matches the head in the database. */
- if (readhead != NULL && memcmp (head, readhead, sizeof (*head)) != 0)
+ if (memcmp (head, readhead, sizeof (*head)) != 0)
return 0;
/* First some easy tests: make sure the database header is sane. */
This should cover daylight saving time changes. */
|| head->timestamp > now + 60 * 60 + 60
|| (head->gc_cycle & 1)
+ || head->module == 0
|| (size_t) head->module > INT32_MAX / sizeof (ref_t)
|| (size_t) head->data_size > INT32_MAX - head->module * sizeof (ref_t)
|| head->first_free < 0
int fd = open (dbs[cnt].db_filename, O_RDWR | EXTRA_O_FLAGS);
if (fd != -1)
{
+ char *msg = NULL;
struct stat64 st;
void *mem;
size_t total;
sizeof (head)));
if (n != sizeof (head) || fstat64 (fd, &st) != 0)
{
+ fail_db_errno:
+ /* The code is single-threaded at this point so
+ using strerror is just fine. */
+ msg = strerror (errno);
fail_db:
dbg_log (_("invalid persistent database file \"%s\": %s"),
- dbs[cnt].db_filename, strerror (errno));
+ dbs[cnt].db_filename, msg);
unlink (dbs[cnt].db_filename);
}
else if (head.module == 0 && head.data_size == 0)
{
- /* The file has been created, but the head has not been
- initialized yet. Remove the old file. */
- unlink (dbs[cnt].db_filename);
+ /* The file has been created, but the head has not
+ been initialized yet. */
+ msg = _("uninitialized header");
+ goto fail_db;
}
else if (head.header_size != (int) sizeof (head))
{
- dbg_log (_("invalid persistent database file \"%s\": %s"),
- dbs[cnt].db_filename,
- _("header size does not match"));
- unlink (dbs[cnt].db_filename);
+ msg = _("header size does not match");
+ goto fail_db;
}
else if ((total = (sizeof (head)
+ roundup (head.module * sizeof (ref_t),
> st.st_size
|| total < sizeof (head))
{
- dbg_log (_("invalid persistent database file \"%s\": %s"),
- dbs[cnt].db_filename,
- _("file size does not match"));
- unlink (dbs[cnt].db_filename);
+ msg = _("file size does not match");
+ goto fail_db;
}
/* Note we map with the maximum size allowed for the
database. This is likely much larger than the
PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0))
== MAP_FAILED)
- goto fail_db;
+ goto fail_db_errno;
else if (!verify_persistent_db (mem, &head, cnt))
{
munmap (mem, total);
- dbg_log (_("invalid persistent database file \"%s\": %s"),
- dbs[cnt].db_filename,
- _("verification failed"));
- unlink (dbs[cnt].db_filename);
+ msg = _("verification failed");
+ goto fail_db;
}
else
{
-/* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
+/* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
/* Number of bytes of data we initially reserve for each hash table bucket. */
#define DEFAULT_DATASIZE_PER_BUCKET 1024
+/* Default module of hash table. */
+#define DEFAULT_SUGGESTED_MODULE 211
+
/* Number of seconds between two cache pruning runs if we do not have
better information when it is really needed. */
-/* Copyright (c) 1998, 2000, 2003-2006, 2007 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 2000, 2003-2007, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
{
int idx = find_db (arg1);
if (idx >= 0)
- dbs[idx].suggested_module = atol (arg2);
+ dbs[idx].suggested_module
+ = atol (arg2) ?: DEFAULT_SUGGESTED_MODULE;
}
else if (strcmp (entry, "enable-cache") == 0)
{
{
int idx = find_db (arg1);
if (idx >= 0)
- dbs[idx].max_db_size = atol (arg2);
+ dbs[idx].max_db_size = atol (arg2) ?: DEFAULT_MAX_DB_SIZE;
}
else if (strcmp (entry, "logfile") == 0)
set_logfile (arg1);
-/* Copyright (C) 1998-2002,2003,2004,2005,2006,2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1998-2007, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
if (__builtin_expect (head->version != DB_VERSION, 0)
|| __builtin_expect (head->header_size != sizeof (*head), 0)
+ /* Catch some misconfiguration. The server should catch
+ them now but some older versions did not. */
+ || __builtin_expect (head->module == 0, 0)
/* This really should not happen but who knows, maybe the update
thread got stuck. */
|| __builtin_expect (! head->nscd_certainly_running