Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Password file manipulation

by vivekvp (Acolyte)
on Aug 02, 2002 at 18:40 UTC ( [id://187173] : perlquestion . print w/replies, xml ) Need Help??

vivekvp has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I need to write a script that will take an unix password file (/etc/passwd) and allow users to be added to it.
I would prompt for a unix id and directory then it would get added in this form:

+<unix_id>::0:0:name:/discX/users/login/<directory>:/bin/csh

Anyone written anything like this or know of an available script?
Or any wise tips on how to write one of these?

Thanks,

V

He who laughs last, doesn't get the joke.

Replies are listed 'Best First'.
Re: Password file manipulation
by robobunny (Friar) on Aug 02, 2002 at 19:03 UTC
    i would highly recommend that you use your operating system's useradd or adduser command to manipulate the password file, instead of doing it yourself directly. you can easily write a wrapper around that to supply default arguments for the things you don't want to prompt for, if that is what you are looking for. otherwise, you need to worry about file locking, data that will screw up parsing the file, and a host of other problems that someone else has already thought about, and tested extensively (or one would hope, anyway).
Re: Password file manipulation
by Zaxo (Archbishop) on Aug 02, 2002 at 19:42 UTC

    See the core functions documented under getpwent, getpwnam, getpwuid and sugared by User::pwent.

    They take care of shadow files, and other authentication schemes.

    After Compline,
    Zaxo

Re: Password file manipulation (DBD::CSV)
by DamnDirtyApe (Curate) on Aug 02, 2002 at 18:51 UTC

    There's an example of accessing the /etc/passwd file as a flat-file database in the DBD::CSV docs. That may be a good place to start.


    _______________
    D a m n D i r t y A p e
    Home Node | Email