Skip to content

Commit

Permalink
* nscd/nscd.h (struct database_dyn): Add propagate field.
Browse files Browse the repository at this point in the history
	* 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.
  • Loading branch information
Ulrich Drepper committed Apr 26, 2006
1 parent 1f063dc commit 797ed6f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 17 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
3 changes: 3 additions & 0 deletions nscd/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
18 changes: 11 additions & 7 deletions nscd/grpcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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. */
Expand All @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion nscd/nscd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion nscd/nscd.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion nscd/nscd_conf.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
17 changes: 10 additions & 7 deletions nscd/pwdcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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. */
Expand All @@ -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);
}
Expand Down

0 comments on commit 797ed6f

Please sign in to comment.