[ITP] libfakesu 1.0
Christian Franke
Christian.Franke@t-online.de
Sat Sep 13 11:15:00 GMT 2014
D. Boland wrote:
> Hi Christian,
>
> Christian Franke wrote:
>> ...
>> BTW: All these variables except root_uid/gid are not needed as static
>> globals:
>>
>> my_uid is only used to pass the uid from uid_get/set() to get/set(e)uid().
>>
>> my_pw and str255 are only needed because su_getpwnam() calls
>> getpwnam_r() instead of getpwnam().
> I did that to avoid writing into 'external' memory. Would calling getpwnam directly
> be thread-safe?
No and this cannot be fixed because the function interface itself uses
on a static pwd buffer as return value (and TLS is not allowed). As a
consequence, the su_getpwnam() is also not thread safe. Calling
thread-safe su_getpwnam_r() with a static result buffer makes the result
thread-unsafe.
This would work without any extra buffers and is as thread-unsafe as the
current version:
struct passwd *su_getpwnam(const char *name)
{
struct passwd *pwd = getpwnam(name);
if (!pwd)
return NULL;
if (pwd->pw_uid == root_uid)
pwd->pw_uid = 0;
if (pwd->pw_gid == root_gid)
pwd->pw_gid = 0;
return pwd;
}
Christian
More information about the Cygwin-apps
mailing list