Authentication mechanism changed. I don't use Django's builtin

passwords encryption anymore because the default format is something
like : <algo>$<salt>$<password>
I really think this format is not compatible with external softwares
so I use simple hashes.
This commit is contained in:
tonio
2009-03-27 09:25:09 +01:00
parent 80f17440cc
commit ab5b8d96c3
5 changed files with 59 additions and 2 deletions
+26 -1
View File
@@ -11,6 +11,7 @@ How to install
--------------
Download Mailng's tarball and extract it::
tar xzf mailng-<version>.tar.gz
Enter the mailng directory, create a settings.py file (you can use
@@ -19,15 +20,39 @@ must choose between mysql and postgresql, other types are not supported by
major email projects like postfix or dovecot.
Initialise the database by running the following command::
python manage.py syncdb
Create the super admin account (just follow the procedure).
Host configuration
------------------
Before testing Mailng, you must create a group and a user that will be
used to store mails on the host filesystem. There is only one
group/user needed because we are in a virtual hosting configuration
(ie. users with non-UNIX accounts).
For example, create a vmail group::
groupadd vmail
Then create a vmail user::
useradd -g vmail -d /var/vmail -m vmail
At last, the system user used to run mailng will need permissions to
manipulate directories in vmail's homedir. To do that, edit your /etc/sudoers
file and add the following inside::
www-data ALL=(vmail) NOPASSWD: ALL
Testing installation
--------------------
As a typical Django application, Mailng can be tested using a simple web
server. Just run this command to start it::
python manage.py runserver
You will be able to play with mailng by looking at
@@ -105,6 +130,6 @@ Then, edit your /etc/dovecot/dovecot-sql.conf and modify following lines::
driver = mysql
connect = host=<mysqld socket> dbname=<database> user=<user> password=<password>
default_pass_scheme = MD5
default_pass_scheme = PLAIN-MD5
password_query = SELECT address as user, password FROM admin_mailbox WHERE full_address = '%u'
user_query = SELECT path as home, uid, gid FROM admin_mailbox WHERE full_address = '%u'
+1
View File
@@ -40,6 +40,7 @@ class Mailbox(models.Model):
name = models.CharField(max_length=100)
address = models.CharField(max_length=100)
full_address = models.CharField(max_length=150)
password = models.CharField(max_length=100)
quota = models.IntegerField()
uid = models.IntegerField()
gid = models.IntegerField()
+4 -1
View File
@@ -10,6 +10,7 @@ from django.contrib.auth.models import User
from mailng import admin
from mailng.admin.models import Domain, Mailbox, Alias
from forms import MailboxForm, DomainForm, AliasForm
import md5
def _ctx_ok(url):
return {"status" : "ok", "url" : url}
@@ -114,7 +115,8 @@ def newmailbox(request, dom_id=None):
if mb.create_dir(domain):
user = User()
user.username = user.email = "%s@%s" % (mb.address, domain.name)
user.set_password(request.POST["password1"])
# user.set_password(request.POST["password1"])
user.set_unusable_password()
user.is_active = request.POST.has_key("enabled") \
and True or False
fname, lname = mb.name.split()
@@ -123,6 +125,7 @@ def newmailbox(request, dom_id=None):
user.save()
mb.user = user
mb.password = md5.new(request.POST["password1"]).hexdigest()
mb.uid = mb.gid = 500
mb.domain = domain
mb.quota = request.POST["quota"]
+23
View File
@@ -0,0 +1,23 @@
from django.contrib.auth.models import User
from mailng.admin.models import Mailbox
import md5
class SimpleBackend:
def authenticate(self, username=None, password=None):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
return None
try:
mb = Mailbox.objects.get(full_address=username)
except Exception:
return None
if mb.password != md5.new(password).hexdigest():
return None
return user
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
+5
View File
@@ -81,6 +81,11 @@ INSTALLED_APPS = (
'mailng.admin'
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'mailng.lib.authbackends.SimpleBackend'
)
# Mailng specific options
STORAGE_PATH = "/var/vmail"
VIRTUAL_UID = "vmail"