Fix a bug when '-f -H' is used and the target already exists. cpdup was
[dragonfly.git] / contrib / sendmail-8.13.8 / contrib / passwd-to-alias.pl
1 #!/bin/perl
2
3 #
4 #  Convert GECOS information in password files to alias syntax.
5 #
6 #  Contributed by Kari E. Hurtta <Kari.Hurtta@ozone.fmi.fi>
7 #
8
9 print "# Generated from passwd by $0\n";
10
11 $wordpat = '([a-zA-Z]+?[a-zA-Z0-9-]*)?[a-zA-Z0-9]';     # 'DB2'
12 while (@a = getpwent) {
13     ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = @a;
14
15     ($fullname = $gcos) =~ s/,.*$//;
16
17     if (!-d $dir || !-x $shell || $shell =~ m!/bin/(false|true)$!) {
18         print "$name: root\n";                          # handle pseudo user
19     }
20
21     $fullname =~ s/\.*[ _]+\.*/./g;
22     $fullname =~ tr [åäéöüÅÄÖÜ] [aaeouAAOU];  # <hakan@af.lu.se> 1997-06-15
23     next if (!$fullname || lc($fullname) eq $name);     # avoid nonsense
24     if ($fullname =~ /^$wordpat(\.$wordpat)*$/o) {      # Ulrich Windl
25         print "$fullname: $name\n";
26     } else {
27         print "# $fullname: $name\n";                   # avoid strange names
28     }
29 };
30
31 endpwent;