Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#! /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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found