Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bad configure test for getpwent() ?



Clint Adams <schizo@xxxxxxxxxx> typed:
:>     pw1=getpwnam(buf);
:>     sprintf(buf, "%d:%d", rand(), getpid());
:>     pw2=getpwnam(buf);
:>     exit(pw1!=0 && pw2!=0 && !strcmp(pw1->pw_name, pw2->pw_name));
:
:It's not comparing the pointers; it's comparing the names.
:
:> I don't think getpwent() is required to return a unique pointer each time;
:> that is, I think it's allowed to re-use an internal static buffer for each
:> entry that it returns.  That would mean that this test always succeeds ...

My man page says:
  BUGS
    The functions getpwent(), getpwnam(), and getpwuid(), leave their results
    in an internal static object and return a pointer to that object. Subse-
    quent calls to any of these functions will modify the same object.

On my system then, pw2 will be the same as pw1.

Bart typed:
:I think the only right way is to test the first pointer for nonzero, copy
:the entry into a local struct passwd, then call getpwent() again and do
:the comparison.

I'd say this is correct.

Regards,
-- 
Geoff Wing : <gcw@xxxxxxxxx>     Work URL: http://www.primenet.com.au/
Rxvt Stuff : <gcw@xxxxxxxx>      Ego URL : http://pobox.com/~gcw/
Zsh Stuff  : <gcw@xxxxxxx>       Phone   : (Australia) 0413 431 874



Messages sorted by: Reverse Date, Date, Thread, Author