[Mono-dev] UnixUserInfo issues in OpenBSD

Robert Nagy robert at openbsd.org
Sun Oct 17 18:22:53 EDT 2010


You get errno 13 (EACCES) because you are not running it as root
and getpwnam_r will try to give you struct passwd which inludes
the encrypted password of the user so errno will be set to EACCES,
but the other fields will be set.

According to the comment in mph.h getpnam_r only returns ERANGE on
linux and -1 on Mac OS, bt errno == ERANGE was wrong anyways.
On OpenBSD we return 1 until everything is okay and then we return 0.
The following diff fixes OpenBSD and Mac OS too.

diff --git a/support/mph.h b/support/mph.h
index 8a61999..08ce5ea 100644
--- a/support/mph.h
+++ b/support/mph.h
@@ -198,8 +198,8 @@ recheck_range (int ret)
 {
        if (ret == ERANGE)
                return 1;
-       if (ret == -1)
-               return errno == ERANGE;
+       if (ret != 0)
+               return errno = ERANGE;
        return 0;
 }
 
On (2010-10-13 12:56), Jonathan Pryor wrote:
> On Wed, 2010-10-13 at 16:38 +0200, pablosantosluac at terra.es wrote:
> > This is what I get:
> > 
> > $ ./a.out tester
> > # checking return value 1; errno=13
> 
> That's...horribly wrong.
> 
> First, what's errno=13?  (i.e. what EVALUE is 13?  I'm sure OpenBSD has
> different values than Linux does.)
> 
> Regardless, OpenBSD doesn't appear to be conforming to the standard
> here:
> 
>         http://www.opengroup.org/onlinepubs/009695399/functions/getpwnam_r.html
> 
>         If successful, the getpwnam_r() function shall return zero;
>         otherwise, an error number shall be returned to indicate the
>         error. 
> 
> The value '1' is likely not the correct errno for ERANGE (Under Linux,
> EPERM has the value 1), and since the return value isn't -1
> recheck_range() won't check errno against ERANGE either.
> 
> However, this does point out a bug in MonoPosixHelper: if getpwnam_r()
> returns non-zero it should treat it as an error, which is clearly not
> happening here (and is why we're printing garbage data to the screen).
> 
> This would only marginally help you, though, as it would result in no
> users being found, ever.
> 
> The fundamental problem is that Mono_Posix_Syscall_getpwnam_r()'s logic
> for checking for ERANGE (so it'll resize the buffer and try the call
> again) is failing under OpenBSD, and from what I can see here the
> problem is within OpenBSD, not MonoPosixHelper.
> 
> Patches welcome to properly support OpenBSD. :-)
> 
>  - Jon
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list


More information about the Mono-devel-list mailing list