PasswdFile(3pm)

πŸ’– NAME πŸ’–

okay so bestie, <pink>Unix::PasswdFile</pink> β€” it's the Perl interface to /etc/passwd format files. that's it, that's the whole vibe ✨


🌸 SYNOPSIS 🌸

use Unix::PasswdFile;

$pw = new Unix::PasswdFile "/etc/passwd";
$pw->user("joeblow", $pw->encpass("secret"), $pw->maxuid + 1, 10,
          "Joe Blow", "/export/home/joeblow", "/bin/ksh");
$pw->delete("deadguy");
$pw->passwd("johndoe", $pw->encpass("newpass"));
foreach $user ($pw->users) {
    print "Username: $user, Full Name: ", $pw->gecos($user), "\n";
}
$pw->commit();
undef $pw;

like literally just look at it. she's serving 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the <cyan>Unix::PasswdFile</cyan> module hands you an abstract interface to files in /etc/passwd format. she does the unglamorous stuff for you, no cap: file locking, getting colons in the right places, and every other tiny niggling little detail you do NOT want to be hand-formatting at 2am 😭

it's giving "let me handle it bestie" energy. periodt.


πŸ‘‘ METHODS πŸ‘‘

πŸ’… commit( [BACKUPEXT] )

go read the <lavender>Unix::ConfigFile</lavender> documentation for the description of this method, babes. that's where the tea is β˜•

πŸ’… delete( USERNAME )

this one deletes the named user. if the user you passed in doesn't exist, it just… does nothing. no drama, no error, no effect πŸ’€

πŸ’… encpass( PASSWORD )

again, the <lavender>Unix::ConfigFile</lavender> documentation has the full description of this method. go peek ✨

πŸ’… gecos( USERNAME [,GECOS] )

reads or modifies a user's GECOS string β€” which is typically their full name, iykyk. either way, it returns the GECOS string back to you 🌸

πŸ’… gid( USERNAME [,GID] )

reads or modifies a user's GID. and yes, it returns the GID in either case πŸ’œ

πŸ’… home( USERNAME [,HOMEDIR] )

reads or modifies a user's home directory. returns the home directory either way, always 🏠

πŸ’… maxuid( [IGNORE] )

this method returns the maximum UID in use by all users. now if you pass in that optional IGNORE parameter, it'll skip over every UID that's greater than or equal to IGNORE while it's doing the math. super handy for leaving out accounts like nobody, bestie β€” iconic behaviour honestly πŸ‘‘

πŸ’… new( FILENAME [,OPTIONS] )

yep, <lavender>Unix::ConfigFile</lavender> documentation, description of this method, go read it πŸŽ€

πŸ’… passwd( USERNAME [,PASSWD] )

reads or modifies a user's password, and returns the encrypted password in either case. ⚠️ important though: if you've got a plaintext password, use the encpass method to encrypt it first before you hand it to this method. do not skip that step, fr fr 🚨

πŸ’… rename( OLDNAME, NEWNAME )

this one changes the username for a user πŸ¦‹. heads up though β€” if NEWNAME matches a user that already exists, that user will be overwritten. gone. poof. it returns 0 on failure and 1 on success.

πŸ’… shell( USERNAME [,SHELL] )

reads or modifies a user's shell. returns the shell in either case 🐚

πŸ’… uid( USERNAME [,UID] )

reads or modifies a user's UID. returns the UID in either case ⭐

πŸ’… user( USERNAME [,PASSWD, UID, GID, GECOS, HOMEDIR, SHELL] )

okay this is the main character method ✨ she can add, modify, or return information about a user, depending on what you give her.

  • give her just the single username parameter and she returns a six element list of (PASSWORD, UID, GID, GECOS, HOMEDIR, SHELL) β€” or undef if no such user exists πŸ’€
  • give her all seven parameters and the named user gets created, or modified if they already exist. and yes, you still get that same six element list back in this case too 🫢

πŸ’… users( [SORTBY] )

returns a list of all existing usernames πŸ’œ. by default that list is sorted by the UIDs of the users. you can also pass "name" as the parameter to get it sorted by username instead. and in scalar context? this method returns the total number of users. versatile queen 🌈


🌟 AUTHOR 🌟

Steve Snodgrass, ssnodgra@fore.com πŸ’–


πŸ”₯ SEE ALSO πŸ”₯

Unix::AliasFile, Unix::AutomountFile, Unix::ConfigFile, Unix::GroupFile


and that's the whole page bestie, no notes πŸ’… this was perl v5.32.1, dated 2021-08-21, and it's the <rainbow>PasswdFile(3pm)</rainbow> page from the User Contributed Perl Documentation β€” go forth and manage those users, you absolute icon πŸ‘‘πŸŽ€βœ¨

πŸ“¦ where this page comes from