summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgrr <grr@cvs.openbsd.org>1997-07-27 08:29:10 +0000
committergrr <grr@cvs.openbsd.org>1997-07-27 08:29:10 +0000
commit3d35ecd6ba56444a173263cabf0068f788545c4e (patch)
treed738c723898bcc774f571a33b2bfc33a876adb3c /lib
parentd42318cc1d20f1199ea1280dc58ac9f5d84e80db (diff)
Make correct distinction between "entry not found" and "no capability files",
and allow looking through multiple databases, even if one is the *.db case.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/getcap.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index ae899f93dde..ca0f5f02e65 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getcap.c,v 1.7 1997/07/23 21:09:06 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: getcap.c,v 1.8 1997/07/27 08:29:09 grr Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -193,7 +193,7 @@ getent(cap, len, db_array, fd, name, depth, nfield)
{
DB *capdbp;
register char *r_end, *rp, **db_p;
- int myfd, eof, foundit, retval, clen;
+ int myfd, eof, foundit, opened, retval, clen;
char *record, *cbuf;
int tc_not_resolved;
char pbuf[_POSIX_PATH_MAX];
@@ -205,10 +205,13 @@ getent(cap, len, db_array, fd, name, depth, nfield)
if (depth > MAX_RECURSION)
return (-3);
+ opened = 0;
+
/*
* Check if we have a top record from cgetset().
*/
if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) {
+ opened++;
if ((record = malloc (topreclen + BFRAG)) == NULL) {
errno = ENOMEM;
return (-2);
@@ -243,25 +246,29 @@ getent(cap, len, db_array, fd, name, depth, nfield)
if (fd >= 0) {
(void)lseek(fd, (off_t)0, SEEK_SET);
myfd = 0;
+ opened++;
} else {
+ char *dbrecord;
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
!= NULL) {
- free(record);
- retval = cdbget(capdbp, &record, name);
+ opened++;
+ retval = cdbget(capdbp, &dbrecord, name);
if (retval < 0) {
/* no record available */
(void)capdbp->close(capdbp);
- return (retval);
+ continue;
}
+ free(record);
/* save the data; close frees it */
- clen = strlen(record);
+ clen = strlen(dbrecord);
cbuf = malloc(clen + 1);
- memcpy(cbuf, record, clen + 1);
+ memcpy(cbuf, dbrecord, clen + 1);
if (capdbp->close(capdbp) < 0) {
free(cbuf);
return (-2);
}
+ /* assume tc='s have been expanded??? */
*len = clen;
*cap = cbuf;
return (retval);
@@ -272,27 +279,28 @@ getent(cap, len, db_array, fd, name, depth, nfield)
continue;
}
myfd = 1;
+ opened++;
}
}
/*
* Find the requested capability record ...
*/
{
- char buf[BUFSIZ];
- register char *b_end, *bp;
- register int c;
-
- /*
- * Loop invariants:
- * There is always room for one more character in record.
- * R_end always points just past end of record.
- * Rp always points just past last character in record.
- * B_end always points just past last character in buf.
- * Bp always points at next character in buf.
- */
- b_end = buf;
- bp = buf;
- for (;;) {
+ char buf[BUFSIZ];
+ register char *b_end, *bp;
+ register int c;
+
+ /*
+ * Loop invariants:
+ * There is always room for one more character in record.
+ * R_end always points just past end of record.
+ * Rp always points just past last character in record.
+ * B_end always points just past last character in buf.
+ * Bp always points at next character in buf.
+ */
+ b_end = buf;
+ bp = buf;
+ for (;;) {
/*
* Read in a line implementing (\, newline)
@@ -376,15 +384,15 @@ getent(cap, len, db_array, fd, name, depth, nfield)
break; /* found it! */
}
}
+ }
}
- }
if (foundit)
break;
}
if (!foundit) {
free(record);
- return (-1 - (fd < 0));
+ return (opened ? -1 : -2);
}
/*