| 1 | #! @PERL@ |
| 2 | # |
| 3 | # Convert vchkpw to userdb format. |
| 4 | # |
| 5 | # $Id: vchkpw2userdb.in,v 1.4 2000/02/16 01:12:13 mrsam Exp $ |
| 6 | # |
| 7 | # Copyright 1998 - 1999 Double Precision, Inc. See COPYING for |
| 8 | # distribution information. |
| 9 | |
| 10 | use Getopt::Long; |
| 11 | |
| 12 | die "Invalid options.\n" unless |
| 13 | GetOptions("vpopmailhome=s" => \$vpopmailhome, |
| 14 | "todir=s" => \$todir); |
| 15 | |
| 16 | if ( ! ( $vpopmailhome =~ /./ )) |
| 17 | { |
| 18 | (undef, undef, undef, undef, undef, undef, undef, $vpopmailhome) |
| 19 | = getpwnam("vpopmail"); |
| 20 | |
| 21 | die "Cannot find vpopmail home.\n" unless $vpopmailhome =~ /./; |
| 22 | } |
| 23 | |
| 24 | -d "$vpopmailhome" || die "$vpopmailhome: not found.\n"; |
| 25 | |
| 26 | if ( $todir =~ /./ ) |
| 27 | { |
| 28 | -d "$todir" || mkdir($todir, 0700) || die "$!\n"; |
| 29 | } |
| 30 | |
| 31 | $bindir=$0; |
| 32 | |
| 33 | if ($bindir =~ /^(.*)\/[^\/]*$/ ) |
| 34 | { |
| 35 | $bindir=$1; |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | $bindir="."; |
| 40 | } |
| 41 | |
| 42 | die "Unable to locate pw2userdb.\n" unless -f "$bindir/pw2userdb"; |
| 43 | |
| 44 | $redir=""; |
| 45 | |
| 46 | if ( $todir =~ /./ ) |
| 47 | { |
| 48 | $redir=">$todir/users-vpasswd"; |
| 49 | -d "$todir/domains" || mkdir("$todir/domains", 0700) || die "$!\n"; |
| 50 | } |
| 51 | |
| 52 | if ( -f "$vpopmailhome/users/vpasswd") |
| 53 | { |
| 54 | $rc=system ("$bindir/pw2userdb --vpopuid --passwd='$vpopmailhome/users/vpasswd' --noshadow --nouid $redir"); |
| 55 | exit $rc / 256 if $rc; |
| 56 | } |
| 57 | |
| 58 | if ( opendir(DIR, "$vpopmailhome/domains")) |
| 59 | { |
| 60 | while ($domain=readdir(DIR)) |
| 61 | { |
| 62 | $domainopt="--domain='$domain'"; |
| 63 | $domainopt="" if $domain eq "default"; |
| 64 | next if $domain eq "." || $domain eq ".."; |
| 65 | next unless -f "$vpopmailhome/domains/$domain/vpasswd"; |
| 66 | $redir=""; |
| 67 | if ( $todir =~ /./ ) |
| 68 | { |
| 69 | $redir=">$todir/domains/$domain"; |
| 70 | $redir=">$todir/users-default" |
| 71 | if $domain eq "default"; |
| 72 | } |
| 73 | |
| 74 | $rc=system ("$bindir/pw2userdb --passwd='$vpopmailhome/domains/$domain/vpasswd' --vpopuid --noshadow --nouid $domainopt $redir"); |
| 75 | |
| 76 | exit $rc / 256 if $rc != 0; |
| 77 | } |
| 78 | close(DIR); |
| 79 | } |
| 80 | |