From owner-FreeBSD-users-jp@jp.freebsd.org  Thu Nov 19 02:01:38 1998
Received: (from daemon@localhost)
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) id CAA07852;
	Thu, 19 Nov 1998 02:01:38 +0900 (JST)
	(envelope-from owner-FreeBSD-users-jp@jp.FreeBSD.org)
Received: from nazuna.bres.tsukuba.ac.jp (nazuna.bres.tsukuba.ac.jp [130.158.220.1])
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) with ESMTP id CAA07847
	for <FreeBSD-users-jp@jp.freebsd.org>; Thu, 19 Nov 1998 02:01:33 +0900 (JST)
	(envelope-from yohta@bres.tsukuba.ac.jp)
Received: by nazuna.bres.tsukuba.ac.jp (8.9.0/3.7W-981018) id CAA19502;
	Thu, 19 Nov 1998 02:01:28 +0900 (JST)
Date: Thu, 19 Nov 1998 02:01:28 +0900 (JST)
Message-Id: <199811181701.CAA19502@nazuna.bres.tsukuba.ac.jp>
To: FreeBSD-users-jp@jp.freebsd.org
In-Reply-To: Your message of "Wed, 18 Nov 1998 20:39:34 +0900 (JST)".
	<199811181139.UAA13119@nazuna.bres.tsukuba.ac.jp>
From: yohta@bres.tsukuba.ac.jp (Yoshihiko OHTA)
X-Mailer: mnews [version 1.21PL4] 1998-06/01(Mon)
Reply-To: FreeBSD-users-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+981115
X-Sequence: FreeBSD-users-jp 35347
Subject: [FreeBSD-users-jp 35347] Re: adduser: bug or supecification
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

$B!!C^GHBg$NB@ED$G$9!#(B

1998-11-18($B?e(B) 20:39:34.$B:"!";d$O=q$-$^$7$?!#(B

> > $B3N$+$K$=$N?75,$K:n@.$5$l$?(B login account $B$KBP$7$F!$$$$o$f$k(B*$BIaDL$N(B*
> > email account $B$,B8:_$7$J$$$+$b$7$l$^$;$s$,!$5U$K$$$($P!V:G=i$K(B email $BE*(B 
> > alias $B$r:n$C$?$1$I!$$=$l$KBP1~$9$k(B login account $B$,$J$$$+$i:n$C$H$3$&!W(B
> > $B$H$$$&2DG=@-$O$"$j$=$&$G$9!%(B

>   $B3NG'$N%W%m%s%W%H$r=P$7$F6/9T$G$-$k$h$&$K$9$l$P$$$$$N$+$J!#$G$b(B
> $B%P%C%A=hM}$N;~$O$I$&$7$h$&!D!D!#%P%C%A$N;~$O(B adduser $B$KEO$90JA0(B
> $B$K%A%'%C%/$5$l$F$$$k$3$H$r4|BT$7$F$7$^$*$&$+!D!D!#(B

  $B$H$$$&$o$1$G!"%Q%C%A$r:n$C$F!"(Bbin/8745 $B$H$7$F(B send-pr $B$7$F$_$^(B
$B$7$?!#K\Ev$K(B serious $B$+$I$&$+$O$o$+$s$J$$$G$9$1$I!"(Bserious $B$G=P(B
$B$7$?$N$G!"(BCurrent FreeBSD problem reports $B$N%Z!<%8$+$i8+$D$1$k$N(B
$B$,LLE]$K$J$C$F$7$^$$$^$7$?!#(B
# non-critical $B$J$i0lHV2<$+$i$_$F$$$1$P$$$$$s$G$9$1$I!#(B

  $B0l1~$3$A$i$K$b%Q%C%A$r:\$;$F$*$-$^$9!#$?$V$sF0$/$H;W$&$s$G$9$1(B
$B$I!"ITHw$J$I$"$j$^$7$?$i(B Submit Followup $B$7$F$$$?$@$1$k$H$"$j$,(B
$B$?$$$G$9!#(B

--- /usr/sbin/adduser	Wed Jul 22 17:15:20 1998
+++ /home/yohta/bin/adduser	Thu Nov 19 01:28:47 1998
@@ -41,6 +41,7 @@
     $home = "/home";		# default HOME
     $etc_shells = "/etc/shells";
     $etc_passwd = "/etc/master.passwd";
+    $sendmail_cf = "/etc/sendmail.cf";
     $group = "/etc/group";
     $pwd_mkdb = "pwd_mkdb -p";	# program for building passwd database
 
@@ -66,6 +67,9 @@
 
     $password = '';		# password for new users
 
+    # mailaliases
+    $aliasname = '';		# mail aliases of sendmail
+
     # group
     $groupname ='';		# $groupname{groupname} = gid
     $groupmembers = '';		# $groupmembers{gid} = members of group/kommalist
@@ -256,6 +260,40 @@
     close P;
 }
 
+# read /etc/aliases and some(if exist)
+sub mailalias_read {
+    local(@aliasfile, $aliases, $item, $description);
+
+    print "Check $sendmail_cf\n" if $verbose;
+    open(A, "$sendmail_cf") || die "$sendmail_cf: $!\n";
+
+    while(<A>) {
+	chop;
+	if (/^O AliasFile=/) {
+	    s/^O AliasFile=//;
+	    s/\s.*$//;
+	    push(@aliasesfile, split(/,/, $_));
+	}
+    }
+    close A;
+
+    foreach $aliases (@aliasesfile) {
+	open(A, $aliases) || die "$aliases: $!\n";
+	while (<A>) {
+	    chop;
+	    # ignore comments
+	    next if /^\s*$/;
+	    next if /^\s*#/;
+	    
+	    ($item, $description) = split(/\s*:\s*/, $_, 2);
+	    print "$item already exists with alias: $aliasname{$item}!\n"
+		if $aliasname{$item} && $verbose;
+	    $aliasname{$item} = $description;
+	}
+	close A;
+    }
+}
+
 # read /etc/group
 sub group_read {
     local($g_groupname,$pw,$g_gid, $memb);
@@ -321,8 +359,17 @@
 	warn "Wrong username. " .
 	    "Please use only lowercase characters or digits\a\n";
 	return 0;
-    } elsif ($username{$name}) {
+    } elsif (defined($username{$name})) {
 	warn "Username ``$name'' already exists!\a\n"; return 0;
+    } elsif ($aliasname{$name})  {
+	warn "Mail alias ``$name'' already exists!\a\n";
+	if ($#batch < 0) {
+	    return 0 unless 
+		&confirm_yn("Really want to continue with this username?", 
+			    "yes");
+	} else {
+	    warn "But going on...\n";
+	}
     }
     return $name;
 }
@@ -1437,6 +1484,7 @@
 &passwd_check;			# check for valid passwdb
 &shells_read;			# read /etc/shells
 &passwd_read;			# read /etc/master.passwd
+&mailalias_read;		# read /etc/aliases and some(if exist)
 &group_read;			# read /etc/group
 &group_check;			# check for incon*
 exit 0 if $check_only;		# only check consistence and exit
--
$BB@EDK'I'(B(Yoshihiko Ohta)  $BC^GHBg3X!!%P%$%*%7%9%F%`8&5f2J(B
E-mail: yohta@bres.tsukuba.ac.jp
$B!V@8J*$NB?MM@-$OCO5e4D6-$NB?MM@-$NI=$l$G$"$k!W(B
$B!V$D$^$j$$$m$$$m$$$k$[$&$,3Z$7$$$C$F$3$H$h$M!W!!LkOC!?L4O)9T(B
