diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-07-28 11:20:00 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-07-28 11:20:00 +0000 |
commit | 28b37f0c3b8be275632b331d600010471a520e63 (patch) | |
tree | 62cddfd9061208a688561159ae396b99fbb7b11f /lib | |
parent | a7d55a70f898b0dc0560a1226af26573136caf88 (diff) |
merge in getcap change by grr, in rev 1.8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getcap.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index d8c5e497121..47b26410192 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.9 1997/07/27 08:59:16 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: getcap.c,v 1.10 1997/07/28 11:19:59 deraadt 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); } /* |