summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-06-18 18:11:15 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-06-18 18:11:15 +0000
commit5556a8dd6da099b3a0146784b0e198327165d234 (patch)
treebd16c1f9497a4b586d6f9d46a83a3ae9ee7d1d3b /lib/libc/gen
parent2895f33abe12b8048ada274209fed47cd02cf440 (diff)
Add new cgetusedb() function to toggle reading of .db files in getcap(3).
Needed for cap_mkdb to really DRT when given several input files or an output file with a different name from the input file. cvs: ----------------------------------------------------------------------
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/getcap.326
-rw-r--r--lib/libc/gen/getcap.c24
2 files changed, 45 insertions, 5 deletions
diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3
index 75a1af6269d..07b31baf59b 100644
--- a/lib/libc/gen/getcap.3
+++ b/lib/libc/gen/getcap.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getcap.3,v 1.20 2000/12/24 00:30:47 aaron Exp $
+.\" $OpenBSD: getcap.3,v 1.21 2001/06/18 18:11:14 millert Exp $
.\"
.\" Copyright (c) 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -47,7 +47,8 @@
.Nm cgetustr ,
.Nm cgetfirst ,
.Nm cgetnext ,
-.Nm cgetclose
+.Nm cgetclose ,
+.Nm cgetusedb
.Nd capability database access routines
.Sh SYNOPSIS
.Fd #include <stdlib.h>
@@ -71,6 +72,8 @@
.Fn cgetnext "char **buf" "char **db_array"
.Ft int
.Fn cgetclose "void"
+.Ft int
+.Fn cgetusedb "int usedb"
.Sh DESCRIPTION
The
.Fn cgetent
@@ -256,6 +259,25 @@ closes the sequential access and frees any memory and file descriptors
being used.
Note that it does not erase the buffer pushed by a call to
.Fn cgetset .
+.Pp
+.Fn cgetusedb
+allows the user to specify whether use or ignore database files ending in
+.Dq .db .
+If
+.Ar usedb
+is zero, files ending in
+.Dq .db
+will be ignored.
+If
+.Ar usedb
+is non-zero, files ending in
+.Dq .db
+will be used in preference to the text version.
+The default is to process
+.Dq .db
+files.
+.Fn cgetusedb
+returns the previous setting.
.Ss Capability database syntax
Capability databases are normally
.Tn ASCII
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index 6cb1ef49370..dbefdb883cc 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.17 2000/11/22 19:12:57 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: getcap.c,v 1.18 2001/06/18 18:11:14 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -68,6 +68,23 @@ static int cdbget __P((DB *, char **, const char *));
static int getent __P((char **, u_int *, char **, int, const char *, int, char *));
static int nfcmp __P((const char *, char *));
+static int usedb = 1;
+
+/*
+ * Cgetusedb() allows the user to specify whether or not to use a .db
+ * version of the database file (if it exists) in preference to the
+ * text version. By default, the getcap(3) routines will use a .db file.
+ */
+int
+cgetusedb(new_usedb)
+ int new_usedb;
+{
+ int old_usedb = usedb;
+
+ usedb = new_usedb;
+ return(old_usedb);
+}
+
/*
* Cgetset() allows the addition of a user specified buffer to be added
* to the database array, in effect "pushing" the buffer on top of the
@@ -253,9 +270,10 @@ getent(cap, len, db_array, fd, name, depth, nfield)
opened++;
} else {
char *dbrecord;
+
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
- if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
- != NULL) {
+ if (usedb &&
+ (capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))) {
opened++;
retval = cdbget(capdbp, &dbrecord, name);
if (retval < 0) {