Or maybe in more Perlish lingo:
print "Password: ";
chomp(my $passwd = <STDIN>);
system(
'/usr/sbin/useradd',
-u => $max + 1,
-s => $shell,
-p => crypt($passwd, time),
-g => 100,
'-m',
$username,
);
:-) Btw, I recommend removing the setuid bit from useradd ASAP. Otherwise, anyone can do something like
$ /usr/sbin/useradd -u 0 -g 0 -s /bin/bash -p crypted_passwd_here -m root2
which is a classic escalation of privileges attack. Instead, you want to look into sudo. Your /etc/sudoers should have a line like this:
newuser ALL = (root) NOPASSWD: /usr/sbin/useradd
and then your code changes to
system(
'/usr/bin/sudo',
'/usr/sbin/useradd',
-u => $max + 1,
-s => $shell,
-p => crypt($passwd, time),
-g => 100,
'-m',
$username,
);
That way only newuser, whom only root has control of, may add new users.
Makeshifts last the longest. |