Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Getting Next Available Userid

by nardo (Friar)
on Sep 19, 2001 at 19:09 UTC ( [id://113360]=note: print w/replies, xml ) Need Help??


in reply to Getting Next Available Userid

You can use getpwent to get all of the uid's from /etc/passwd then find a free one, or alternately you could run through uid's with getpwuid until you find a free one. Both of these suffer from the fact that a free uid is not necessarily free once you have found it (since another process could have added it right after you found it was free). I assume that programs like useradd will lock the /etc/passwd to prevent this situation, but they may use fcntl for file locking as it is more portable than flock (you can build perl to emulate flock with fcntl(2), but by default it will use flock(2) if available). For groups it would be the same, with getgrent and getgrgid.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://113360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found