Hi, I was working on an implementation of chown and got an error when running it on OpenBSD. It looks like a change[1] might have introduced unintended side-effects to getgrnam.
Without the patch supplied below some chown implementations may fail with ENOENT when they should succeed. I've tested this change by rebuilding libc from the 6.5 source tree installing it on my system and verifying that chown no longer fails. Since I'm running 6.5 I'm not able to test 'current', but I did checkout the 'current' source tree and the patch applies cleanly. Thanks, Richard [1]: https://github.com/openbsd/src/commit/b971f1acd7c34a49359ccefbe512e06f3826a939 Index: getgrent.c =================================================================== RCS file: /cvs/src/lib/libc/gen/getgrent.c,v retrieving revision 1.47 diff -u -p -u -p -r1.47 getgrent.c --- getgrent.c 13 Sep 2018 12:31:15 -0000 1.47 +++ getgrent.c 2 Jul 2019 14:02:02 -0000 @@ -197,6 +197,8 @@ DEF_WEAK(getgrgid_r); static int start_gr(void) { + int saved_errno; + if (_gr_fp) { rewind(_gr_fp); #ifdef YP @@ -214,7 +216,9 @@ start_gr(void) /* * Hint to the kernel that a passwd database operation is happening. */ + saved_errno = errno; (void)access("/var/run/ypbind.lock", R_OK); + errno = saved_errno; #endif return((_gr_fp = fopen(_PATH_GROUP, "re")) ? 1 : 0);