#! /usr/bin/perl -T #################################################### # passwd_sync.pl : Program to Setup Unix, Samba, and NIS passwords ove +r 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 o +f 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 (s +plit of $value) my @new_user_info2; #array with $name's infos from nis passwd.byuid (s +plit of $value) my $html= new CGI; #################################################### #HTML Header# print $html->header; print $html->start_html(-BGCOLOR=>"white"); #################################################### print "Messages du système : <br><hr>"; ($name,$shadow_pass,$uid,$gid,$gecos,$home,$shell)=getpwnam("$login"); $crypte=unix_md5_crypt($old_passwd,$shadow_pass); if ($uid<500){ print "You don't have the right to change the password by this way"; } else { if ($passwd1 eq $passwd2) { if($crypte eq $shadow_pass) { $crypt_passwd=unix_md5_crypt($passwd1,int rand (99)); $modif=modpwinfo($name,$crypt_passwd,$uid,$gid,$gecos,$home,$sh +ell); system ("$SUDO","$SMBPASSWD","-s","$name","$passwd1"); ($name,$shadow_pass,$uid)=getpwnam("$login"); tie (%nis,'GDBM_File',$passwd_byname,1,0) or die "Can't access NIS + passwd.byname"; $value=$nis{"$login"}; @new_user_info=split (/:/,$value); $new_user_info[1]="$shadow_pass"; $value= join (":",@new_user_info); $nis{"$login"}=$value; untie (%nis); tie (%nis2,'GDBM_File',$passwd_byuid,1,0) or die "Can't access NIS + passwd.byuid"; $value=$nis2{$uid}; @new_user_info2=split (/:/,$value); $new_user_info2[1]="$shadow_pass"; $value= join (":",@new_user_info2); $nis2{"$uid"}=$value; untie (%nis2); system ("$MAKEDBM","-c"); } else { print "The old password or the login name are bad."; } } else { print "Passwords do not match."} } #################################################### #HTML footer print $html->hr; print $html->a({href=>"$url_server"},"Back"); print $html->end_html; ####################################################

In reply to To setup Linux NIS, samba and shadow shadow passwords by tbo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.