#! /usr/bin/perl -T
####################################################
# passwd_sync.pl : Program to Setup Unix, Samba, and NIS passwords over web.
# licence GPL
####################################################
####################################################
#YOU NEED TO CREATE THIS SCRIPT "SETUID" and owned by
# root (This is a security risk!!)
####################################################
use strict;
use GDBM_File;
use CGI qw(:standard);
use Crypt::PasswdMD5;
use Passwd::Linux qw(modpwinfo);
####################################################
#datas from HTML form#
my $login = param('login');
my $old_passwd = param('old_passwd');
my $passwd1= param('passwd1');
my $passwd2 = param('passwd2');
####################################################
#things you've got to change to suit you're own configuration
####################################################
my $url_server="https://192.168.0.1"; #url of the web server
my $nis_domain="tbo.edu";#the nis domain (get by domainname)
my $SMBPASSWD="/usr/bin/smbpasswd";#location of smbpasswd
my $MAKEDBM="/usr/lib/yp/makedbm";#location of makedbm (YP server)
my $SUDO="/usr/bin/sudo";#location of sudo
###################################################
#location of nis files
my $passwd_byname="/var/yp/".$nis_domain."/passwd.byname"; #location of the file passwd.byname from nis
my $passwd_byuid="/var/yp/".$nis_domain."/passwd.byuid"; #location of the file passwd.byuid from nis
####################################################
my $name; #login name from /etc/passwd
my $shadow_pass; #md5 password's $name from /etc/shadow
my $uid; #uid's $name from /etc/passwd
my $gid; #gid's $name from /etc/passwd
my $gecos; #gecos's $name from /etc/passwd
my $home; #directory's $name from /etc/passwd
my $shell; #shell's $name from etc/passwd
my $crypte;#old passwd crypted in md5 (to compare with $shadow_pass)
my $crypt_passwd; #new passwd crypted in md5
my $modif;#used to modify /etc/shadow with $crypt_passwd
my %nis; #hash where passwd.byname is stored during manipulations
my %nis2; #hash where passwd.byuid is stored during manipulations
my $value; #$name's info from nis DB
my @new_user_info; #array with $name's infos from nis passwd.byname (split of $value)
my @new_user_info2; #array with $name's infos from nis passwd.byuid (split of $value)
my $html= new CGI;
####################################################
#HTML Header#
print $html->header;
print $html->start_html(-BGCOLOR=>"white");
####################################################
print "Messages du système :