From c06670c5f7a1f4fb38a2feeac34047394e728663 Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 22 Jan 2024 21:07:09 +0000 Subject: [PATCH] I forgot that chpass(1) and passwd(1) reach-around into libc for getpwent.c (isn't it horrible), and therefore lack visibility of the the libc-internal __hash_open() function. Use -DFORCE_DBOPEN in chpass/Makefile and passwd/Makefile and adjust getpwent.c to use the external visible interface. Is there a better way? --- lib/libc/gen/getpwent.c | 16 +++++++++++++--- usr.bin/chpass/Makefile | 4 ++-- usr.bin/passwd/Makefile | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 6bab12a0725..0a959e7aa9e 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getpwent.c,v 1.67 2024/01/22 17:21:52 deraadt Exp $ */ +/* $OpenBSD: getpwent.c,v 1.68 2024/01/22 21:07:09 deraadt Exp $ */ /* * Copyright (c) 2008 Theo de Raadt * Copyright (c) 1988, 1993 @@ -960,10 +960,20 @@ __initdb(int shadow) __ypmode = YPMODE_NONE; __getpwent_has_yppw = -1; #endif - if (shadow) + if (shadow) { +#ifdef FORCE_DBOPEN + _pw_db = dbopen(_PATH_SMP_DB, O_RDONLY, 0, DB_HASH, NULL); +#else _pw_db = __hash_open(_PATH_SMP_DB, O_RDONLY, 0, NULL, 0); - if (!_pw_db) +#endif + } + if (!_pw_db) { +#ifdef FORCE_DBOPEN + _pw_db = dbopen(_PATH_MP_DB, O_RDONLY, 0, DB_HASH, NULL); +#else _pw_db = __hash_open(_PATH_MP_DB, O_RDONLY, 0, NULL, 0); +#endif + } if (_pw_db) { errno = saved_errno; return (1); diff --git a/usr.bin/chpass/Makefile b/usr.bin/chpass/Makefile index b3a4053dfbf..6af5e844a85 100644 --- a/usr.bin/chpass/Makefile +++ b/usr.bin/chpass/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2016/03/30 06:38:45 jmc Exp $ +# $OpenBSD: Makefile,v 1.16 2024/01/22 21:07:10 deraadt Exp $ .include @@ -8,7 +8,7 @@ BINOWN= root BINMODE=4555 .PATH: ${.CURDIR}/../../lib/libc/gen LINKS= ${BINDIR}/chpass ${BINDIR}/chfn ${BINDIR}/chpass ${BINDIR}/chsh -CFLAGS+=-I${.CURDIR}/../../lib/libc/include +CFLAGS+=-I${.CURDIR}/../../lib/libc/include -DFORCE_DBOPEN DPADD+= ${LIBUTIL} LDADD+= -lutil diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile index e1168b760d8..c671a8898ce 100644 --- a/usr.bin/passwd/Makefile +++ b/usr.bin/passwd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.41 2015/11/26 19:01:47 deraadt Exp $ +# $OpenBSD: Makefile,v 1.42 2024/01/22 21:07:10 deraadt Exp $ .include @@ -8,7 +8,7 @@ SRCS= local_passwd.c passwd.c getpwent.c \ .PATH: ${.CURDIR}/../../lib/libc/gen DPADD+= ${LIBRPCSVC} ${LIBUTIL} LDADD+= -lrpcsvc -lutil -CFLAGS+= -I${.CURDIR} +CFLAGS+= -I${.CURDIR} -DFORCE_DBOPEN CFLAGS+=-I${.CURDIR}/../../lib/libc/include -- 2.20.1