From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,778249772fea0191,start X-Google-Attributes: gidfee84,public X-Google-Thread: 116329,778249772fea0191,start X-Google-Attributes: gid116329,public X-Google-ArrivalTime: 2001-11-28 08:24:33 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!206.228.179.2!news-peer1.sprintlink.net!news-in-east1.sprintlink.net!news.sprintlink.net!news.umkc.edu!not-for-mail From: David Nicol Newsgroups: comp.perl.misc,comp.unix.osf.osf1 Subject: vipw in perl, to help with "vipw: you mangled the temp file, /etc/passwd unchanged" errors Date: Tue, 27 Nov 2001 13:50:20 -0600 Organization: University of Missouri - Kansas City Message-ID: <3C03EE7C.42C37CC6@umkc.edu> NNTP-Posting-Host: nicol6.umkc.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: littleroo.umkc.edu 1006890622 31638 134.193.4.67 (27 Nov 2001 19:50:22 GMT) X-Complaints-To: abuse@umkc.edu NNTP-Posting-Date: Tue, 27 Nov 2001 19:50:22 +0000 (UTC) X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.4.7 i586) X-Accept-Language: en-GB, en, ru Xref: archiver1.google.com comp.unix.osf.osf1:56 after reading http://isisesc.supelec.fr/list-tru64/archive/August2000/0355.html about vipw: you mangled the temp file, /etc/passwd unchanged errors, I have written the following replacement for vipw. What other checks should it do on the password file? #!/usr/local/bin/perl =pod perl vipw copyright 2002 UMKC (David Nicol) released as public domain utility =cut $pid = $$; system "cp /etc/passwd /etc/ptmp.$pid"; EDIT: fork or exec "vi /etc/ptmp.$pid"; wait; eval { open CHECK, "){ /\S/ or next; # blank lines are okay @F = split /:/; $F[2] =~ /^\d+$/ or die "nonnumeric UID in line $. : [$_]\n"; $F[3] =~ /^\d+$/ or die "nonnumeric GID in line $. : [$_]\n"; -d $F[5] or die "home directory [$F[5]] does not exist in line $. : [$_]\n"; }; }; if ($@){ print $@; print "enter q* or e* to quit/exit, anything else to edit again\n"; $_=; /^[qeQE]/ or goto EDIT; unlink "/etc/ptmp.$pid"; exit; }; system "mv /etc/ptmp.$pid /etc/passwd"; exec q{/usr/sbin/mkpasswd /etc/passwd}; __END__