[tpop3d-discuss] Notes on auth-flat-file

Paul Makepeace beasts.org at paulm.com
Thu, 10 Oct 2002 04:24:50 +0100


Setting this up went relatively smoothly with one minor oddness. On
glibc it seems the passwd file scanner needs a uid and gid in each line,
rather than just username:crypted_passwd or some variation involving
more colons.

Here are some details on how I set this up - feel free to use, add to
the distro, examples, etc.

My tpop3d.conf looks like,

listen-address: 0.0.0.0
mailbox: bsd:/var/mail/$(domain)/$(local_part)
mailspool-index: /var/lib/tpop3d/index/$(escaped_name)
auth-flatfile-enable: yes
auth-flatfile-mail-group: mail
auth-flatfile-mail-user: mail
auth-flatfile-passwd-file: /etc/mail/passwd/$(domain)

My exim4.conf now has in its director section,

localuser_vmail:
  driver = accept
  local_part_prefix = real-
  require_files = /var/mail/${domain}
  transport = local_delivery_vmail

localuser_vmail:
  driver = accept
  require_files = /var/mail/${domain}
  transport = local_delivery_vmail

# In the transports section,

local_delivery_vmail:
  driver = appendfile
  file = /var/mail/${domain}/${local_part}
  headers_add = Delivered-To: $local_part@$domain
  group = mail
  user = mail
  #mode = 0660
  #no_mode_fail_narrower

# end of exim.conf snippet

I created this script (sudo -u mail) to add users, set their passwords,
and create spool directories if necessary,

#!/usr/bin/perl -w
use strict;

# Paul Makepeace <http://paulm.com/>, 2002-10-10:
# vmail_passwd

use File::Spec::Functions qw(catfile);

my $passwd_root = q[/etc/mail/passwd];
my $spool_root = q[/var/mail];

sub randletter {
        chr int (rand (26)) + (int (rand (1) + .5) % 2 ? 65 : 97);
}

sub usage {
        use File::Basename; my $me = basename $0;
        die "Usage: $me username\@domain\n";
}

usage unless @ARGV == 1;
my ($username, $domain) = $ARGV[0] =~ /(\S+)\@(\S+)/;
usage unless defined $username and defined $domain;

my $salt = randletter() . randletter();
my ($plaintext, $confirm);
system "stty -echo";
for(;;) {
        print "Password: ";
        chomp($plaintext = <STDIN>);
        print "\nConfirm: ";
        chomp($confirm = <STDIN>);
        print "\n";
        if ($plaintext ne $confirm) {
                print "Passwords don't match. Try again.\n";
        } else {
                last;
        }
}
system "stty echo";
my $password = crypt ($plaintext, $salt);
my $passwd_file = catfile($passwd_root, $domain);
my $spool_dir = catfile($spool_root, $domain);
unless (-d $spool_dir) {
        mkdir $spool_dir, 0775
                or die "Can't create spool directory '$spool_dir': $!\n";
        print "Created $spool_dir\n";
}
open P, '>>', $passwd_file or die "Can't append to '$passwd_file': $!\n";
print P qq{$username:$password:0:0:::\n}; # yeah, the :0:0 are needed..
close P;
print "Added $username to $passwd_file\n";

__END__

Suggestions, patches, welcome!

Cheers,
Paul

-- 
Paul Makepeace ....................................... http://paulm.com/

"If I pass the buck, will I get the help, then you can count on me!"
   -- http://paulm.com/toys/surrealism/