Click to See Complete Forum and Search --> : Automatically create virtual mail account


hawkinpaul
06-24-2005, 01:30 PM
I have a server running Debian Woody with Postfix, Courier IMAP and Squirrelmail. The server runs fine but I want to be able to automate the creation of users.

When I started, creating virtual user account was a bit of a process so I wrote a script that took care of most of it. Here is the script I am using:

__________________________________________________ ____________
#
#Script to create virtual user for email account
#

echo "Enter the username:"
read uname
maildirmake /home/vmail/Maildir-$uname
chown vmail /home/vmail/Maildir-$uname
userdb "$uname" set home=/home/vmail mail=/home/vmail/Maildir-$uname uid=1002 gid=100
userdbpw | userdb "$uname" set imappw
makeuserdb
echo $uname@mydomain.com Maildir-$uname/ >> /etc/postfix/vmailbox
postmap /etc/postfix/virtual
postmap /etc/postfix/vmailbox
postfix reload
chown -R vmail /home/vmail/Maildir-$uname
chgrp -R users /home/vmail/Maildir-$uname

__________________________________________________ _____________

This works just fine. It asks me to enter the username and then I have to enter the password twice. I would like to be able to set this to automatically run when one of my users signs up for email.

The only thing that is getting in my way is that it asks me for a password. I would like to designate the password in the script. I have read a few sites that say I can do that by changing my "userdbpw" line to this:


userdbpw | userdb "$uname" set imappw=password

Where "password" is the password I want to give to the user. That great except that it doesn't work. :confused: It still asks me for the password. If I cancel out when it asks me for the password and then check out the /etc/courier/usedb file the correct password shows up but it doesn't work when I try to log in. All the others that were created the default way seem to be encrypted but the one where I used imappw=password is just plain text.

Does anyone know what I need to do to get this to work?

Sorry for the long post. Thanks for the help!

bwkaz
06-24-2005, 06:38 PM
I believe the "userdbpw" process might be what's asking you for the password. Instead of userdbpw | userdb "$uname" set imappw=password, try just userdb "$uname" set imappw=password instead.

hawkinpaul
06-27-2005, 09:52 AM
I tried that and it is no longer asking me for a password but the password that it puts into the /etc/courier/userdb file is plain text. All of the other passwords in there are encrypted. Is there any way for me to make it encrypt the password.

When it isn't encrypted it doesn't work when I try to log in as the new user I created.

Thanks so much for your help,

Hawkinpaul

bwkaz
06-27-2005, 09:13 PM
Hmm, looks like userdbpw is encrypting the password too then. Ugh.

Well, I've never used Postfix or Courier (at least not extensively), so I'm not positive, but does userdbpw perhaps have an option where you can feed the password to it in a script? Maybe the manpage would document such an option?

hawkinpaul
06-28-2005, 03:15 PM
Thanks for the tip but I checked the man page for userdbpw... here it is below. The only example that it gives of sending the password along with the command is one where userdbpw isn't even used. Check out this exerpt of the man page. This is the whole description section:


DESCRIPTION
userdbpw enables secure entry of encrypted passwords into
/etc/courier/userdb.

userdbpw reads a single line of text on standard input,
encrypts it, and prints the encrypted result to standard
output.

If standard input is attached to a terminal device,
userdbpw explicitly issues a "Password: " prompt on stan*
dard error, and turns off echo while the password is
entered.

or:

userdbpw -hmac-md5 | userdb users/john set hmac-md5pw

These commands set the systempw field in the record for
the user john in /etc/courier/userdb/users file, and the
hmac-md5pw field. Don't forget to run makeuserdb for the
change to take effect.

The following command does the same thing:

userdb users/john set systempw=SECRETPASSWORD

However, this command passes the secret password as an
argument to the userdb command, which can be viewed by
anyone who happens to run ps(1) at the same time. Using
userdbpw allows the secret password to be specified in a
way that cannot be easily viewed by ps(1).

Any more ideas?

Thanks,

Hawkinpaul

bwkaz
06-28-2005, 06:45 PM
userdb users/john set systempw=SECRETPASSWORD Have you tried this? (systempw instead of imappw.)

If you have, then maybe:

echo "password" | userdbpw | userdb "$username" set imappw

would work?

hawkinpaul
06-29-2005, 08:54 AM
Thank you Thanks you thank you

It worked. Thanks for taking the time to help me out. It is working now and I can move on. ;)

Hawkinpaul