From f24de13a6fc400ac552673e896c4afbb056b77a4 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 12 Jan 2008 20:46:28 +0000 Subject: [PATCH] - working with sqlalchemy 0.3.10 - remove duplicate foreign key definitions from tables.py - use _saltchars in passwordutils.py git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@240 a67ec6bc-e5d5-0310-a910-815c51eb3124 --- data/templates/home/README | 0 gnuviechadmin/backend/BackendEntity.py | 19 +++++++++++- gnuviechadmin/backend/BackendTo.py | 4 +-- gnuviechadmin/backend/settings.py | 4 +-- gnuviechadmin/backend/sysuser.py | 24 +++++++------- gnuviechadmin/backend/tables.py | 43 +++++++++----------------- gnuviechadmin/util/passwordutils.py | 5 +-- gnuviechadmin/util/stmtcreator.py | 11 +++++++ 8 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 data/templates/home/README create mode 100644 gnuviechadmin/util/stmtcreator.py diff --git a/data/templates/home/README b/data/templates/home/README new file mode 100644 index 0000000..e69de29 diff --git a/gnuviechadmin/backend/BackendEntity.py b/gnuviechadmin/backend/BackendEntity.py index 71e88f7..887deac 100644 --- a/gnuviechadmin/backend/BackendEntity.py +++ b/gnuviechadmin/backend/BackendEntity.py @@ -1,4 +1,4 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # # Copyright (C) 2007 by Jan Dittberner. # @@ -64,6 +64,23 @@ class BackendEntity(object): self.logger.info("%s: %s", toexec, sts[1]) return sts[1] + def supipe(self, cmdlines): + """Executes multiple commands as root and pipes the output of + the commands to the input of the next commands.""" + self.logger.debug("supipe called: %s", " | ".join(cmdlines)) + suwrapper = config.get('common', 'suwrapper') + predecessor = None + for cmdline in cmdlines: + toexec = "%s %s" % (suwrapper, cmdline) + if predecessor is None: + p = Popen(toexec, shell = True, stdout = PIPE) + else: + p = Popen(toexec, shell = True, stdin = predecessor.stdout, + stdout = PIPE) + predecessor = p + output = predecessor.communicate()[0] + return predecessor.wait() + def send_mail(self, subject, text): """This method sends a mail with the given text and subject and signs it usign GnuPG. If a public key of the recipient is diff --git a/gnuviechadmin/backend/BackendTo.py b/gnuviechadmin/backend/BackendTo.py index 397da3b..1e46058 100644 --- a/gnuviechadmin/backend/BackendTo.py +++ b/gnuviechadmin/backend/BackendTo.py @@ -1,6 +1,6 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # -# Copyright (C) 2007 by Jan Dittberner. +# Copyright (C) 2007, 2008 by Jan Dittberner. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/gnuviechadmin/backend/settings.py b/gnuviechadmin/backend/settings.py index afac9fe..ebf8420 100644 --- a/gnuviechadmin/backend/settings.py +++ b/gnuviechadmin/backend/settings.py @@ -1,6 +1,6 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # -# Copyright (C) 2007 by Jan Dittberner. +# Copyright (C) 2007, 2008 by Jan Dittberner. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/gnuviechadmin/backend/sysuser.py b/gnuviechadmin/backend/sysuser.py index a5f3579..0b65529 100644 --- a/gnuviechadmin/backend/sysuser.py +++ b/gnuviechadmin/backend/sysuser.py @@ -1,6 +1,6 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # -# Copyright (C) 2007 by Jan Dittberner. +# Copyright (C) 2007, 2008 by Jan Dittberner. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ from settings import config from BackendTo import * from BackendEntity import * from BackendEntityHandler import * +import os class SysuserEntity(BackendEntity): """Entity class for system users.""" @@ -52,8 +53,9 @@ class SysuserEntity(BackendEntity): usernames = [user.username for user in \ getenttools.find_user_by_prefix(prefix)] maxid = max([int(username[len(prefix):]) for username in usernames]) - for num in range(1, maxid + 1): - username = "%s%02d" % (prefix, num) + maxid += 2 + for number in range(1, maxid): + username = "%s%02d" % (prefix, number) if not username in usernames: return username @@ -79,15 +81,15 @@ class SysuserEntity(BackendEntity): def _populate_home(self): templatedir = get_template_dir(config.get('sysuser', 'hometemplate')) - cmdline = 'cp -R "%(template)s" "%(home)s"' % { - 'template' : templatedir, - 'home' : self.delegateto.home } - self.sucommand(cmdline) - cmdline = 'chown -R "%(username)s":"%(group)s" %(home)s' % { + olddir = os.getcwd() + os.chdir(templatedir) + cmd1 = 'find . -depth \! -regex ".*\.svn.*" \! -name "*~" -print0' + cmd2 = 'cpio --pass-through --owner=%(username)s.%(group)s --null --make-directories %(home)s' % { 'username' : self.delegateto.username, 'group' : config.get('sysuser', 'defaultgroup'), - 'home' : self.delegateto.home } - self.sucommand(cmdline) + 'home' : self.delegateto.home} + self.supipe((cmd1, cmd2)) + os.chdir(olddir) def _mail_sysuser(self): template = get_template(config.get('common', 'mailtemplates'), diff --git a/gnuviechadmin/backend/tables.py b/gnuviechadmin/backend/tables.py index b8d314d..6c8f9f9 100644 --- a/gnuviechadmin/backend/tables.py +++ b/gnuviechadmin/backend/tables.py @@ -1,6 +1,6 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # -# Copyright (C) 2007 by Jan Dittberner. +# Copyright (C) 2007, 2008 by Jan Dittberner. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,30 +43,15 @@ except exceptions.NoSuchTableError, nste: meta = BoundMetaData(config.get('database', 'uri')) #meta.engine.echo = True -client_table = Table( - 'client', meta, schema = dbschema, autoload = True) -sysuser_table = Table( - 'sysuser', meta, ForeignKeyConstraint(['clientid'], ['client.clientid']), - schema = dbschema, autoload = True) -domain_table = Table( - 'domain', meta, ForeignKeyConstraint(['sysuserid'], ['sysuser.sysuserid']), - schema = dbschema, autoload = True) -record_table = Table( - 'record', meta, ForeignKeyConstraint(['domainid'], ['domain.domainid']), - schema = dbschema, autoload = True) -supermaster_table = Table( - 'supermaster', meta, - ForeignKeyConstraint(['account'], ['sysuser.sysuserid']), - schema = dbschema, autoload = True) -mailaccount_table = Table( - 'mailaccount', meta, - ForeignKeyConstraint(['domainid'], ['domain.domainid']), - schema = dbschema, autoload = True) -mailaddress_table = Table( - 'mailaddress', meta, - ForeignKeyConstraint(['domainid'], ['domain.domainid']), - schema = dbschema, autoload = True) -mailtarget_table = Table( - 'mailtarget', meta, - ForeignKeyConstraint(['mailaddressid'], ['mailaddress.mailaddressid']), - schema = dbschema, autoload = True) +client_table = Table('client', meta, schema = dbschema, autoload = True) +sysuser_table = Table('sysuser', meta, schema = dbschema, autoload = True) +domain_table = Table('domain', meta, schema = dbschema, autoload = True) +record_table = Table('record', meta, schema = dbschema, autoload = True) +supermaster_table = Table('supermaster', meta, schema = dbschema, + autoload = True) +mailaccount_table = Table('mailaccount', meta, schema = dbschema, + autoload = True) +mailaddress_table = Table('mailaddress', meta, schema = dbschema, + autoload = True) +mailtarget_table = Table('mailtarget', meta, schema = dbschema, + autoload = True) diff --git a/gnuviechadmin/util/passwordutils.py b/gnuviechadmin/util/passwordutils.py index 64211df..cae804f 100644 --- a/gnuviechadmin/util/passwordutils.py +++ b/gnuviechadmin/util/passwordutils.py @@ -1,4 +1,4 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # # Copyright (C) 2007 by Jan Dittberner. # @@ -24,6 +24,7 @@ import crypt, crack, random _pwchars = [] for pair in (('0', '9'), ('A', 'Z'), ('a', 'z')): _pwchars.extend(range(ord(pair[0]), ord(pair[1]))) +_saltchars = [char for char in _pwchars] for char in "-+/*_@": _pwchars.append(ord(char)) @@ -46,7 +47,7 @@ def checkpassword(password): def md5_crypt_password(password): """Hashes the given password with MD5 and a random salt value.""" salt = "".join([chr(letter) for letter in \ - random.sample(_pwchars, 8)]) + random.sample(_saltchars, 8)]) return crypt.crypt(password, '$1$' + salt) def get_pw_tuple(password = None): diff --git a/gnuviechadmin/util/stmtcreator.py b/gnuviechadmin/util/stmtcreator.py new file mode 100644 index 0000000..61ee699 --- /dev/null +++ b/gnuviechadmin/util/stmtcreator.py @@ -0,0 +1,11 @@ +from passwordutils import * +import sys + +for line in sys.stdin.read().splitlines(): + parts = line.split() + (email, domain) = parts[0].split("@") + username = parts[1][0:5] + pwtuple = get_pw_tuple() + print "INSERT INTO mailpassword (id, clearpass, cryptpass, uid, gid, home, spamcheck) VALUES ('%s', '%s', '%s', %d, %d, '/home/mail/%s/%s', 'false');" % (parts[1], pwtuple[0], pwtuple[1], int(parts[2]), 119, username, parts[1]) + print "INSERT INTO mailaddress (domainid, email, target) VALUES (%d, '%s', '%s');" % (int(parts[3]), email, parts[1]) +