Fix a bug in the database handle caching. This has to do with the way the

underlying database code works. When dealing with first/next queries, you
have the notion of a database 'cursor,' which is essentially a file pointer
for the database. To select the first entry, you do a fetch with the
R_FIRST flag set, then you can use the R_NEXT flag to enumerate the other
entries in the database. Unfortunately, doing a direct fetch with no flag
does _not_ set the 'cursor,' so you can't do a direct fetch and then
enumerate the table from there.

The bug is that cached handles generated as the result of a YPPROC_MATCH
were being treated as though they were the same as handles generated by
a YPPROC_FIRST, which is not the case. The manifestation is that if you
do a 'ypmatch first-key-in-map map' followed by a yp_first()/yp_next()
pair, the yp_first() and yp_next() both return the first key in the
table, which makes the entry appear to be duplicated.

A couple smaller things since I'm here:

- yp_main.c and yp_error.c both have a global 'int debug' in them.
  For some reason, our cc/ld doesn't flag this as a multiply defined
  symbol even though it should. Removed the declaration from yp_main.c;
  we want the one in yp_error.c.

- The Makefile wasn't installing ypinit in the right place.
This commit is contained in:
Bill Paul 1998-02-11 19:15:32 +00:00
parent a293037f7c
commit 0d15a95009
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=33250
4 changed files with 16 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.3 1997/11/10 21:22:17 wpaul Exp $
# $Id: Makefile,v 1.12 1997/11/10 22:17:09 wpaul Exp $
PROG= ypserv
SRCS= yp_svc.c yp_server.c yp_dblookup.c yp_dnslookup.c \
@ -33,7 +33,7 @@ afterinstall:
${.CURDIR}/Makefile.yp \
${DESTDIR}/var/yp/Makefile.dist
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 555 \
${.CURDIR}/ypinit.sh ${BINDIR}/ypinit
${.CURDIR}/ypinit.sh ${DESTDIR}/${BINDIR}/ypinit
@if [ ! -f ${DESTDIR}/var/yp/Makefile.dist ]; then \
ln -s ${DESTDIR}/var/yp/Makefile.dist \
${DESTDIR}/var/yp/Makefile; fi

View File

@ -32,7 +32,7 @@
#ifndef lint
static const char rcsid[] =
"$Id$";
"$Id: yp_dblookup.c,v 1.1 1997/11/09 20:54:38 wpaul Exp wpaul $";
#endif /* not lint */
#include <db.h>
@ -512,8 +512,8 @@ int yp_get_record(domain,map,key,data,allow)
#ifdef DB_CACHE
if (qhead.cqh_first->dbptr->size) {
qhead.cqh_first->dbptr->key = key->data;
qhead.cqh_first->dbptr->size = key->size;
qhead.cqh_first->dbptr->key = "";
qhead.cqh_first->dbptr->size = 0;
}
#else
bcopy((char *)data->data, (char *)&buf, data->size);
@ -679,8 +679,12 @@ ypstat yp_select_map(map, domain, key, allow)
keydat *key;
int allow;
{
yp_currmap_db = yp_open_db_cache(domain, map, key->keydat_val,
key->keydat_len);
if (key == NULL)
yp_currmap_db = yp_open_db_cache(domain, map, NULL, 0);
else
yp_currmap_db = yp_open_db_cache(domain, map,
key->keydat_val,
key->keydat_len);
yp_allow_db = allow;
return(yp_errno);

View File

@ -32,7 +32,7 @@
#ifndef lint
static const char rcsid[] =
"$Id$";
"$Id: yp_main.c,v 1.1 1997/11/09 20:54:38 wpaul Exp wpaul $";
#endif /* not lint */
/*
@ -83,7 +83,7 @@ extern int _rpc_dtablesize __P((void));
extern int _rpcsvcstate; /* Set when a request is serviced */
char *progname = "ypserv";
char *yp_dir = _PATH_YP;
int debug = 0;
/*int debug = 0;*/
int do_dns = 0;
int resfd;

View File

@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] =
"$Id$";
"$Id: yp_server.c,v 1.1 1997/11/09 20:54:38 wpaul Exp wpaul $";
#endif /* not lint */
#include "yp.h"
@ -143,7 +143,7 @@ ypproc_match_2_svc(ypreq_key *argp, struct svc_req *rqstp)
return (&result);
}
if (yp_select_map(argp->map, argp->domain, &argp->key, 1) != YP_TRUE) {
if (yp_select_map(argp->map, argp->domain, NULL, 1) != YP_TRUE) {
result.stat = yp_errno;
return(&result);
}
@ -204,7 +204,7 @@ ypproc_first_2_svc(ypreq_nokey *argp, struct svc_req *rqstp)
return (&result);
}
if (yp_select_map(argp->map, argp->domain, &result.key, 0) != YP_TRUE) {
if (yp_select_map(argp->map, argp->domain, NULL, 0) != YP_TRUE) {
result.stat = yp_errno;
return(&result);
}