* nscd/nscd.h (struct database_dyn): Add propagate field.

* nscd/nscd_conf.c (nscd_parse_file): Parse auto-propagate lines.
	* nscd/nscd.conf: Add auto-propagate lines.
	* nscd/connections.c (dbs): Initialize .propagate fields.
	* nscd/grpcache.c (cache_addgr): Do not add ID entry for name lookups
	and vice versa if propagation is disabled for the database.
	* nscd/pwdcache.c (cache_addpw): Likewise.
This commit is contained in:
Ulrich Drepper 2006-04-26 17:32:10 +00:00
parent 1f063dcadb
commit 797ed6f7e1
7 changed files with 52 additions and 17 deletions

View File

@ -1,3 +1,13 @@
2006-04-26 Ulrich Drepper <drepper@redhat.com>
* nscd/nscd.h (struct database_dyn): Add propagate field.
* nscd/nscd_conf.c (nscd_parse_file): Parse auto-propagate lines.
* nscd/nscd.conf: Add auto-propagate lines.
* nscd/connections.c (dbs): Initialize .propagate fields.
* nscd/grpcache.c (cache_addgr): Do not add ID entry for name lookups
and vice versa if propagation is disabled for the database.
* nscd/pwdcache.c (cache_addpw): Likewise.
2006-04-26 James Antill <james.antill@redhat.com>
Ulrich Drepper <drepper@redhat.com>

View File

@ -103,6 +103,7 @@ struct database_dyn dbs[lastdb] =
.enabled = 0,
.check_file = 1,
.persistent = 0,
.propagate = 1,
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
.filename = "/etc/passwd",
@ -119,6 +120,7 @@ struct database_dyn dbs[lastdb] =
.enabled = 0,
.check_file = 1,
.persistent = 0,
.propagate = 1,
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
.filename = "/etc/group",
@ -135,6 +137,7 @@ struct database_dyn dbs[lastdb] =
.enabled = 0,
.check_file = 1,
.persistent = 0,
.propagate = 0, /* Not used. */
.shared = 0,
.max_db_size = DEFAULT_MAX_DB_SIZE,
.filename = "/etc/hosts",

View File

@ -342,10 +342,10 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
marked with FIRST first. Otherwise we end up with
dangling "pointers" in case a latter hash entry cannot be
added. */
bool first = req->type == GETGRBYNAME;
bool first = true;
/* If the request was by GID, add that entry first. */
if (req->type != GETGRBYNAME)
if (req->type == GETGRBYGID)
{
if (cache_add (GETGRBYGID, cp, key_offset, &dataset->head, true,
db, owner) < 0)
@ -355,12 +355,14 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
dataset->head.usable = false;
goto out;
}
first = false;
}
/* If the key is different from the name add a separate entry. */
else if (strcmp (key_copy, gr_name) != 0)
{
if (cache_add (GETGRBYNAME, key_copy, key_len + 1,
&dataset->head, first, db, owner) < 0)
&dataset->head, true, db, owner) < 0)
{
/* Could not allocate memory. Make sure the data gets
discarded. */
@ -372,11 +374,13 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
}
/* We have to add the value for both, byname and byuid. */
if (__builtin_expect (cache_add (GETGRBYNAME, gr_name, gr_name_len,
&dataset->head, first, db, owner)
== 0, 1))
if ((req->type == GETGRBYNAME || db->propagate)
&& __builtin_expect (cache_add (GETGRBYNAME, gr_name,
gr_name_len,
&dataset->head, first, db, owner)
== 0, 1))
{
if (req->type == GETGRBYNAME)
if (req->type == GETGRBYNAME && db->propagate)
(void) cache_add (GETGRBYGID, cp, key_offset, &dataset->head,
req->type != GETGRBYNAME, db, owner);
}

View File

@ -23,7 +23,8 @@
# check-files <service> <yes|no>
# persistent <service> <yes|no>
# shared <service> <yes|no>
# max-db-szie <service> <number bytes>
# max-db-size <service> <number bytes>
* auto-propagate <service> <yes|no>
#
# Currently supported cache names (services): passwd, group, hosts
#
@ -47,6 +48,7 @@
persistent passwd yes
shared passwd yes
max-db-size passwd 33554432
auto-propagate passwd yes
enable-cache group yes
positive-time-to-live group 3600
@ -56,6 +58,7 @@
persistent group yes
shared group yes
max-db-size group 33554432
auto-propagate group yes
enable-cache hosts yes
positive-time-to-live hosts 3600

View File

@ -1,4 +1,4 @@
/* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005
/* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@ -63,6 +63,7 @@ struct database_dyn
int check_file;
int persistent;
int shared;
int propagate;
size_t max_db_size;
const char *filename;
const char *db_filename;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
/* Copyright (c) 1998,2000,2003,2004,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@ -256,6 +256,17 @@ nscd_parse_file (const char *fname, struct database_dyn dbs[lastdb])
else
error (0, 0, _("Must specify value for restart-interval option"));
}
else if (strcmp (entry, "auto-propagate") == 0)
{
int idx = find_db (arg1);
if (idx >= 0)
{
if (strcmp (arg2, "no") == 0)
dbs[idx].propagate = 0;
else if (strcmp (arg2, "yes") == 0)
dbs[idx].propagate = 1;
}
}
else
error (0, 0, _("Unknown option: %s %s %s"), entry, arg1, arg2);
}

View File

@ -338,10 +338,10 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
marked with FIRST first. Otherwise we end up with
dangling "pointers" in case a latter hash entry cannot be
added. */
bool first = req->type == GETPWBYNAME;
bool first = true;
/* If the request was by UID, add that entry first. */
if (req->type != GETPWBYNAME)
if (req->type == GETPWBYUID)
{
if (cache_add (GETPWBYUID, cp, key_offset, &dataset->head, true,
db, owner) < 0)
@ -351,12 +351,14 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
dataset->head.usable = false;
goto out;
}
first = false;
}
/* If the key is different from the name add a separate entry. */
else if (strcmp (key_copy, dataset->strdata) != 0)
{
if (cache_add (GETPWBYNAME, key_copy, key_len + 1,
&dataset->head, first, db, owner) < 0)
&dataset->head, true, db, owner) < 0)
{
/* Could not allocate memory. Make sure the data gets
discarded. */
@ -368,11 +370,12 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
}
/* We have to add the value for both, byname and byuid. */
if (__builtin_expect (cache_add (GETPWBYNAME, dataset->strdata,
pw_name_len, &dataset->head, first,
db, owner) == 0, 1))
if ((req->type == GETPWBYNAME || db->propagate)
&& __builtin_expect (cache_add (GETPWBYNAME, dataset->strdata,
pw_name_len, &dataset->head,
first, db, owner) == 0, 1))
{
if (req->type == GETPWBYNAME)
if (req->type == GETPWBYNAME && db->propagate)
(void) cache_add (GETPWBYUID, cp, key_offset, &dataset->head,
req->type != GETPWBYNAME, db, owner);
}