Reputation: 25
I have to create a perl script that allows me to add/delete/modify users from my Debian. I've read that is not recommended but I've been asked to do it without using system calls, so no adduser/useradd allowed. This script should check if a user has been added/deleted from a mysql database and then add the user to the system. Maybe by modifying etc/passwd directly? Is there any perl module to do this?
Thanks in advance
Upvotes: 0
Views: 792
Reputation: 1577
Got Unix::Passw::File after quick CPAN search. This module can be used read and manipulate password file entries.
Upvotes: 0
Reputation: 12027
On most distributions nowadays, there is also a file /etc/shadow that is used in conjunction with /etc/passwd, so you most likely would have to add a line to /etc/shadow as well. In addition, you most likely would have to create a home directory and a group for the new user, as well as a few other steps. See http://www.tldp.org/LDP/sag/html/adduser.html the steps involved in creating a new user manually.
Having said all of the above, I'm curious to know what the objection is to simply using useradd
called from the perl script. If it is done safely (i.e. inputs are sanitized to prevent a command line injection attack), this approach seems to be a lot simpler and less error prone than trying to script perl to add a user by doing all of the above steps.
Upvotes: 1