From owner-FreeBSD-users-jp@jp.freebsd.org  Thu Apr 13 21:10:06 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id VAA55562;
	Thu, 13 Apr 2000 21:10:06 +0900 (JST)
	(envelope-from owner-FreeBSD-users-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (mistral@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id VAA55557
	for <FreeBSD-users-jp@jp.freebsd.org>; Thu, 13 Apr 2000 21:10:06 +0900 (JST)
	(envelope-from mistral@imasy.or.jp)
Received: from mistral.wind.prv (isdnb09.imasy.or.jp [202.227.24.137])
	by tasogare.imasy.or.jp (8.9.3+3.2W/3.7W-tasogare/smtpfeed 1.04) with ESMTP id VAA47881
	for <FreeBSD-users-jp@jp.freebsd.org>; Thu, 13 Apr 2000 21:10:03 +0900 (JST)
	(envelope-from mistral@imasy.or.jp)
Message-Id: <200004131210.VAA47881@tasogare.imasy.or.jp>
Received: (from yohta@localhost)
	by mistral.wind.prv (8.9.3/3.7Wpl2-990626) id VAA01476;
	Thu, 13 Apr 2000 21:10:03 +0900 (JST)
Date: Thu, 13 Apr 2000 21:10:03 +0900 (JST)
From: mistral@imasy.or.jp (Yoshihiko SARUMARU)
To: FreeBSD-users-jp@jp.freebsd.org
In-Reply-To: Your message of "Thu, 13 Apr 2000 18:23:55 +0900".
	<200004131823.BHG14380.TBNBT@intnl.doshisha.ac.jp>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
X-Mailer: mnews [version 1.22PL1] 2000-02/15(Tue)
Reply-To: FreeBSD-users-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: FreeBSD-users-jp 51141
Subject: [FreeBSD-users-jp 51141] Re: pw	=?ISO-2022-JP?B?GyRCJE4bKEI=?=
 =?ISO-2022-JP?B?GyRCJVElOSVvITwlSUZ+Tk8bKEI=?= 
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org
X-Originator: mistral@imasy.or.jp

$B!!1n4]$G$9!#(B

2000-04-13($BLZ(B) 18:23:55.$B:"!"(Bmassa@intnl.doshisha.ac.jp$B$5$s$O=q$-$^$7$?!#(B

> perl$B%9%/%j%W%H$r;H$$!"(Bcsv$B%U%!%$%k$rFI$_9~$s$G(B
> $B%f!<%6!<EPO?$r0l3g$7$F9T$*$&$H$7$F$$$^$9$,(B
> $B%Q%9%o!<%I$NEPO?$,>e<j$/$$$-$^$;$s!#(B
> BSD$B$O(B3.2R$B$G!"%9%/%j%W%HFb$G;HMQ$7$F$$$k%3%^%s%I$O(B
> pw adduser$B$G$9!#(B
> 
> UID$B!"%[!<%`%G%#%l%/%H%jEy$N@_Dj$O(B-u$B%*%W%7%g%s$d(B
> -d$B%*%W%7%g%s$d(B-m$B%*%W%7%g%sEy$G=PMh$k$N$G$9$,!"(B
> $B%Q%9%o!<%I$N@_Dj$O(B-h $B%*%W%7%g%s$r;H$&$h$&$K$H%^%K%e%"%k$K(B
> $B$"$j$^$7$?!#(B-h$B$N8e$K$O%Q%$%W$d%U%!%$%k$X$N%O%s%I%k$r(B
> $B5-=R$9$k$h$&$K$H$N;v$G$9$,!"$$$^$$$A$I$&$9$l$P$h$$$N$+(B
> $B$o$+$j$^$;$s!#(B

     open(PW, "|pw useradd -n $user -c \"$real\" -g user -m -h 0");
     print PW $password . "\n";
     close PW;

$B$H$$$&46$8$K$J$j$^$9!#(BC $B8@8l$@$H!"(Bopen(2) $B$G5"$C$F$/$k%U%!%$%k%G%#(B
$B%9%/%j%W%?$NHV9f$G$9!#$D$^$j!"I8=`F~NO$,(B 0, $BI8=`=PNO$,(B 1, $BI8=`%((B
$B%i!<=PNO$,(B 2 $B!D!D!"$H$$$&$d$D$G$9$M!#(B

  $B;29M$^$G$K0JA0K?=j$G;H$C$?$b$N$r:\$;$F$*$-$^$9!#(B
  NTT jTeX $B$,F~$C$F%W%j%s%?$,7R$,$C$F$$$J$$$HF0$-$^$;$s(B :-)
  2.2.7-RELEASE $B$N:";H$C$F$^$7$?!#(BPerl5 $B$G$bF0$/$O$:$@$1$I!D!D!#(B

#! /usr/bin/env LANG=C /usr/bin/perl

srand(time + $$);	# $B;~4V$H(B perl $B$N%W%m%;%9HV9f$GMp?t$r=i4|2=$9$k(B
umask 066;		# owner $B$@$1$K:n$C$?%U%!%$%k$NFI$_=q$-8"8B$rM?$($k(B

if (! -e "/etc/pw.conf") {    	# $B$b$7L5$1$l$P(B /etc/pw.conf $B$r:n$k(B
    &configure_pwconf;	
}

# $B4{B8$N%f!<%6L>$rD4::(B
while (1) {
    ($name) = getpwent();
    if ($name eq "") {
	last;
    } else {
	$names{$name} = "used";
    }
}

# $B4{B8$N%a!<%k%(%$%j%"%9L>$rD4::(B
dbmopen(ALIASES, "/etc/aliases", 0644); 
while (($key, $val) = each %ALIASES) {
    chop $key;
    $aliases{$key} = "used";
}
dbmclose(ALIASES);

dbmopen(ALIASES, "/etc/aliases.majordomo", 0644); 
while (($key, $val) = each %ALIASES) {
    chop $key;
    $aliases{$key} = "used";
}
dbmclose(ALIASES);

# $BBPOCE*$+$I$&$+$N%A%'%C%/(B
$interactive = 0;
if ($#ARGV == -1) {	# $B0z?t$J$7(B
    $size = (stat(STDIN))[7];
    if ($size == 0) {	# $B%U%!%$%k$G$J$/%-!<%\!<%I$+$i$NBPOCE*F~NO(B
	$interactive = 1;
    }
} 

# $B%U%!%$%k$+$i$NF~NO$N>l9g!"FbMF$r$"$i$+$8$aA4It%A%'%C%/$9$k(B
if ($interactive == 0) {
    $i = 0;
    while (<>) {
	chop;
	$num = split(/:/);
	if ($num != 3) {
	    print "$B%G!<%?$N?t$,(B 3 $B$G$O$"$j$^$;$s!#(B$num $B$G$9!#(B\n";
	    print "$.$B9TL\(B>> $_\n";
	    exit 1;
	}
	($user[$i], $real[$i], $kanji[$i]) = split(/:/);
	if ($names{$user[$i]} eq "used") {
	    print "$B%f!<%6L>(B $user[$i] $B$O4{$KB8:_$7$^$9!#(B\n";
	    print "$.$B9TL\(B>> $_\n";
	    exit 1;
	}
	if ($aliases{$user[$i]} eq "used") {
	    print "$B%f!<%6L>(B $user[$i] $B$O4{$K%a!<%k%(%$%j%"%9$H$7$F;HMQ$5$l$F$$$^$9!#(B\n";
	    print "$.$B9TL\(B>> $_\n";
	    exit 1;
	}
	$names{$user[$i]} = "used";
	$i++;
    }
}

# Ctrl-C $B$J$I$N3d$j9~$_$r%H%i%C%W$9$k"*%U%!%$%k$NA]=|$r$9$k(B
$SIG{'INT'} = 'handler';
$SIG{'QUIT'} = 'handler';

# $BDLCN=qMQ%U%!%$%k$r(B open $B$9$k(B
$commandname = substr($0, rindex($0, '/') + 1);
$randomnumber = int(rand(0, 100000000)); # 8$B7e$N%i%s%@%`$J?t;z(B
$basename = "/tmp/$commandname.$randomnumber";
$tex = $basename . ".tex";
$dvi = $basename . ".dvi";
open(TEX, ">$tex");
print TEX <<'EOF';
\documentstyle[a4]{jarticle}
\pagestyle{empty}
\def\namelistlabel#1{\mbox{#1}\hfill}   % itemize
\newenvironment{namelist}[1]{%
\begin{list}{}
  {\let\makelabel\namelistlabel
   \settowidth{\labelwidth}{#1}
   \setlength{\leftmargin}{1.1\labelwidth}}
}{%
\end{list}}
\parindent=0pt\listparindent=4zw
\def\labelitemii{$\circ$}
\begin{document}
\tt
EOF

while (1) {
     $user = &getuser;
     last if ($user eq "") ;	# $BL$F~NO$G=*N;(B
     $real = &getreal;
     $kanji = &getkanji;

     $password = &create_password;
     open(PW, "|pw useradd -n $user -c \"$real\" -g user -m -h 0");
     print PW $password . "\n";
     close PW;
     &print_paper($user, $real, $kanji, $password);
}

print TEX <<'EOF';
\end{document}
EOF
close TEX;

# /tmp $B%G%#%l%/%H%j$G<B9T(B
chdir "/tmp";

if ( ($childpid = fork()) > 0) {
    # $B?F%W%m%;%9(B
    while (wait() != $childpid) {;}
} else {
    # $B;R%W%m%;%9(B
    print "\n==TeX $B$r<B9T$7$FEPO?MQ;f$r@07A$7$^$9!D!D!#(B==\n";
    exec "/usr/local/bin/njlatex $tex";
    die "njlatex $B$,<B9T$G$-$^$;$s$G$7$?!#(B";
}

if ( ($childpid = fork()) > 0) {
    # $B?F%W%m%;%9(B
    while (wait() != $childpid) {;}
} else {
    # $B;R%W%m%;%9(B
    print "\n==dvi2ps $B$r<B9T$7$FEPO?MQ;f$r0u:~$7$^$9!D!D!#(B==\n";
    exec "/usr/local/bin/dvi2ps $dvi | lpr";
    die "dvi2ps $B$,<B9T$G$-$^$;$s$G$7$?!#(B";
}

unlink <$basename*>;


sub getuser {
    if ($interactive == 0) {
	return shift @user;
    } else {
	while (1) {
	    print "$B%f!<%6L>$O(B($BL$F~NO$N$^$^2~9T$G=*N;(B): ";
	    $_ = <>;
	    chop;
	    if ($names{$_} eq "used") {
		print "$B%f!<%6L>(B $_ $B$O4{$KB8:_$7$^$9!#(B\n";
	    } elsif ($aliases{$_} eq "used") {
		print "$B%f!<%6L>(B $_ $B$O4{$K%a!<%k%(%$%j%"%9$H$7$F;HMQ$5$l$F$$$^$9!#(B\n";
	    } else {
		$names{$_} = "used";
		return $_;
	    }
	}
    }
}
	    
sub getreal {
    if ($interactive == 0) {
	return shift @real;
    } else {
	print "$B;aL>$O(B($B1Q8lI=5-(B): ";
	$_ = <>;
	chop;
	return $_;
    }
}

sub getkanji {
    if ($interactive == 0) {
	return shift @kanji;
    } else {
	print "$B;aL>$O(B($B4A;zI=5-(B): ";
	$_ = <>;
	chop;
	return $_;
    }
}

# $B%i%s%@%`$J%Q%9%o!<%I$r:n$k!#(B
# $B%Q%9%o!<%I$O(B8$BJ8;z$G!"$&$A(B2$BJ8;z$O%"%k%U%!%Y%C%H0J30$r;HMQ$9$k!#(B
# $B$?$@$7!"(B1 $B$H(B l $B$J$IJ6$i$o$7$$J8;z!"(BASCII / JIS $BG[Ns$G%-!<$N>l=j$N0c$&(B
# $BJ8;z$O;HMQ$7$J$$!#(B
sub create_password {
    local(@symbol) 
	= split(//, "234567890!#$%-|<>/?");
    local(@alphabet) 
	= split(//, "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ");
    local($pos, $i, @password, $symbol_pos1, $symbol_pos2);

    $symbol_pos1 = int(rand(8));
    do {
	$symbol_pos2 = int(rand(8));
    } while ($symbol_pos2 == $symbol_pos1);

    $pos = 0;
    while ( $pos < 8 ) {
      restart:
	if ($pos == $symbol_pos1 || $pos == $symbol_pos2 ) {
	    $password[$pos] = $symbol[rand($#symbol + 1)];
	} else {
	    $password[$pos] = $alphabet[rand($#alphabet + 1)];
	}
	for ($i = 0 ; $i < $pos ; $i++) {
	    if ($password[$i] eq $password[$pos]) {
		goto restart;
	    }
	}
	$pos ++;
    }
    return join ('', @password);
}

sub handler {  # 1st argument is signal name
    local($sig) = @_;
    print "Caught a SIG$sig--shutting down\n";
    unlink <$basename*>;
    kill TERM, $childpid;
    exit(1);
}

sub print_paper {
    local($user, $real, $kanji, $password) = @_;

    print TEX <<"EOF";
\\noindent
{\\large $kanji \\hspace{0.5zw} $BEB(B}

\\begin{center}
 \\LARGE $B%"%+%&%s%HH/9TDLCN=q(B
\\end{center}

\\vspace{3\\baselineskip}

\\begin{quote}
 \\begin{namelist}{HTML $B%U%!%$%k$N%G%#%l%/%H%j(B:}
  \\item [$B%f!<%6L>(B] $user
  \\item [$B=i4|%Q%9%o!<%I(B] \\verb\@$password\@
  \\item [$B%a!<%k%"%I%l%9(B] $user\@YYY.jp
 \\end{namelist}
\\end{quote}

\\vspace{\\baselineskip}

\$\\hrulefill\$
\\vspace{\\baselineskip}

\\begin{itemize}
 \\item {\\dg $BK?=j$G9T$J$C$F$$$k%5!<%S%9$N%5!<%PL>Ey$O0J2<(B
       $B$NDL$j$G$9!#(B}

       \\vspace{1\\baselineskip}

       \\begin{quote}
	\\begin{namelist}{HTML $B%U%!%$%k$N%G%#%l%/%H%j(B:}
	 \\item[$B%a!<%kAw?.(B(SMTP)$B%5!<%P(B:] XXXX.YYY.jp
	 \\item[$B%a!<%k<u?.(B(POP)$B%5!<%P(B:]  XXXX.YYY.jp
	 \\item[POPPASS $B%5!<%P(B:]         XXXX.YYY.jp
	 \\item[IMAP4 $B%5!<%P(B:]           XXXX.YYY.jp
	 \\item[WWW $B%5!<%P(B:]             www.YYY.jp
	 \\item[HTML $B%U%!%$%k$N%G%#%l%/%H%j(B:]
					public\\_html
\\item[$B8D?M%[!<%`%Z!<%8$N(B URL:]  http://www.YYY.jp/\\verb|~|$user/
	\\end{namelist}
       \\end{quote}

       $B>\$7$/$O(B http://www.YYY.jp/services.html $B$r8fMw(B
       $B2<$5$$!#(B

       \\vspace{2\\baselineskip}

 \\item {\\dg $B%Q%9%o!<%IJQ99$N;EJ}(B}

 \\begin{itemize}
  \\item telnet $B$G%m%0%$%s$7!"(Bpasswd $B%3%^%s%I$r<B9T$9$kJ}K!(B
 \\begin{quote}
  \\begin{verbatim}
rishiri% passwd
Changing local password for $user.
Old password:          $B"+(B $B:#$N%Q%9%o!<%I$rF~NO(B
New password:          $B"+(B $B?7$7$$%Q%9%o!<%I$rF~NO(B
Retype new password:   $B"+(B $B?7$7$$%Q%9%o!<%I$rF~NO(B($B3NG'$N$?$a(B)
passwd: updating the database...
passwd: done
rishiri%
  \\end{verbatim}
 \\end{quote}
  \\item Eudora $B$d(B p-chng $B$J$I(B POPPASS $B%/%i%$%"%s%H$r;H$&J}K!(B
 \\end{itemize}

       $B>\$7$/$O(B http://www.YYY.jp/password.html $B$r8fMw(B
       $B2<$5$$!#(B
\\end{itemize}
\\newpage
EOF
}

sub configure_pwconf {
    print open(CONF, ">/etc/pw.conf") || die "/etc/pw.conf $B$r:n$l$^$;$s$G$7$?!#(B";
    print CONF <<EOF;
logfile		/var/log/pw.log
shellpath	/bin:/usr/local/bin
defaultshell	tcsh
EOF
    close CONF;
}


--
$B1n4](B($B5l@+(B: $BB@ED(B)$BK'I'(B (Yoshihiko SARUMARU)
mail: mistral@imasy.or.jp	web: http://www.imasy.or.jp/~mistral/
