Newsgroups: fj.questions.unix,fj.lang.perl
Path: galaxy.trc.rwcp.or.jp!sparky!uunet!sun-barr!sh.wide!wnoc-tyo-news!etl.go.jp!tacho!tinygw!takahasi
From: takahasi@tiny.or.jp (Hironobu Takahashi)
Subject: Re: Change password
Organization: Tsukuba internet Club (TINY net)
Distribution: fj
Date: Sun, 7 Jun 1992 15:43:56 GMT
Message-ID: <1992Jun7.154356.8915@tiny.or.jp>
References: <1467@tmcaen1.kouku-k.ac.jp> <365@kocb.kocb.astem.or.jp> <1992Jun7.084211.10433@tiny.or.jp>
Lines: 37
Xref: galaxy.trc.rwcp.or.jp fj.questions.unix:2735 fj.lang.perl:34
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.questions.unix&nb=2735&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

>$B$H$$$&$3$H$G$7$g$&$M!#:#F|$O$*5Y$_$J$N$G(B C $B$G:n$C$F$_$^$7$?!#(B

$B$3$&$$$&;E;v$O(B perl $B$,F@0U$G$9$M!#(B perl $B$NN}=,$r$+$M$F(B perl $BHG(B
$B$b:n$C$F$_$^$7$?!#;EMM$O(B C $BHG$H$$$C$7$g$G$9!#KM$O(B perl $B$O=i?4(B
$B<T$J$N$G$$$8$a$J$$$G$/$@$5$$$M!#(B

$B$3$s$J$N$r=q$$$F$$$k$HBg7?5!$r;H$C$F$$$?@N$r;W$$$@$7$F$7$^$&$J(B :-)

#! /usr/local/bin/suidperl
#
#  CPASS -- change password of a specified user.
#

$authfile = "/etc/passwd.authority";

if ($#ARGV != 0) { die "Usage: $0 userid\n"; }
$userid=$ARGV[0];

$len=length($userid);
($user) = getpwnam($userid);
if (($len == 0) || ($len > 8) || ($user ne $userid))
    { die "Invalid userid: $userid\n"; }

($authority) = getpwuid($<);

open (AUTHFILE, $authfile) || die "Can't open $authfile\n";
while(<AUTHFILE>) {
    chop;
    ($admin, $user) = split;
    if (($admin eq $authority) && ($user eq $userid)) {
        $< = 0;
        $ENV{'PATH'} = '/bin';
        exec("/bin/passwd", "$user");
exit;
    }
}
die "You are not authorized \n";
