couple of getpwnam() questions
Steve Langasek
vorlon at netexpress.net
Sat Nov 25 16:43:14 GMT 2000
On Sun, 26 Nov 2000 okuyamak at dd.iij4u.or.jp wrote:
> I don't really know what is the "right" cases about
> 'Administorator's. But if I were....
> >>>>> "GC" == Gerald Carter <gcarter at valinux.com> writes:
> GC> No one responded to this. Should I threaten making
> GC> the change to issue #1 unless I hear differently?
> GC> Does anyone depend on this behavior currently?
> I don't even see the reason why current code uses this way.
> Instead, I recommend using getpwent() function, take out each entry,
> and do case insensitive match, or what ever match required.
> # or, simply open the /etc/passwd file directly and look for
> # entry.
[...]
> At least, getpwnam() will open(), close() and scan entire
> /etc/passwd every time being called. This is large overhead, too
> large. With 'getpwent() + case insensitive match', we only need
> to scan once, though we might need more complex matching engine.
This is true when getpwnam() uses a flatfile (/etc/passwd) for its backend,
but this is not always the case, and therefore getpwent() is not always going
to be much more efficient. With some database backends (NIS+, LDAP, Berkeley
DB, for example), you may find that calling getpwnam("user") is a *LOT* more
efficient than iterating through getpwent().
I think Gerald's question is still relevant: even if there is a more efficient
way to do what the code currently does, *why* is it being done at all?
Steve Langasek
postmodern programmer
More information about the samba-technical
mailing list