1
0
Fork 0

- mail related tables in database schema

- gpg encryption for mails
- domain creation and deletion completed
- logging
- use pwd and grp


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@230 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
Jan Dittberner 2007-07-09 06:46:36 +00:00
parent 3f4457bdca
commit fdea3217c8
28 changed files with 877 additions and 323 deletions

View file

@ -19,7 +19,7 @@
#
# Version: $Id$
import os, popen2
import pwd, grp
class PasswdUser(object):
"""This class represents users in the user database."""
@ -45,7 +45,7 @@ class PasswdGroup(object):
def __init__(self, groupname, pw, gid, members):
self.groupname = groupname
self.gid = int(gid)
self.members = members.split(",")
self.members = members
def __repr__(self):
return "%s(%s:%d:%s)" % (self.__class__.__name__,
@ -53,42 +53,41 @@ class PasswdGroup(object):
self.gid,
",".join(self.members))
def parsegroups():
(stdout, stdin) = popen2.popen2("getent group")
return [PasswdGroup(*arr) for arr in [line.strip().split(":") for line in stdout]]
def parse_groups():
return [PasswdGroup(*arr) for arr in grp.getgrall()]
def parseusers():
(stdout, stdin) = popen2.popen2("getent passwd")
return [PasswdUser(*arr) for arr in [line.strip().split(":") for line in stdout]]
def parse_users():
return [PasswdUser(*arr) for arr in pwd.getpwall()]
def finduserbyprefix(prefix):
def find_user_by_prefix(prefix):
"""Finds all user entries with the given prefix."""
return [user for user in parseusers() if user.username.startswith(prefix)]
return [user for user in parse_users() if user.username.startswith(prefix)]
def getuserbyid(uid):
def get_user_by_id(uid):
"""Gets the user with the given user id."""
users = [user for user in parseusers() if user.uid == uid]
users = [user for user in parse_users() if user.uid == uid]
if users:
return users[0]
return None
def getgroupbyid(gid):
def get_group_by_id(gid):
"""Gets the group with the given group id."""
groups = [group for group in parsegroups() if group.gid == gid]
groups = [group for group in parse_groups() if group.gid == gid]
if groups:
return groups[0]
return None
def getmaxuid(boundary = 65536):
def get_max_uid(boundary = 65536):
"""Gets the highest uid value."""
return max([user.uid for user in parseusers() if user.uid <= boundary])
return max([user.uid for user in parse_users() if user.uid <= boundary])
def getmaxgid(boundary = 65536):
def get_max_gid(boundary = 65536):
"""Gets the highest gid value."""
return max([group.gid for group in parsegroups() if group.gid <= boundary])
return max([group.gid for group in parse_groups() \
if group.gid <= boundary])
if __name__ == "__main__":
print "Max UID is %d" % (getmaxuid(40000))
print "Max GID is %d" % (getmaxgid(40000))
print "User with max UID is %s" % (getuserbyid(getmaxuid(40000)))
print "Group with max GID is %s" % (getgroupbyid(getmaxgid(40000)))
print "Max UID is %d" % (get_max_uid(40000))
print "Max GID is %d" % (get_max_gid(40000))
print "User with max UID is %s" % (get_user_by_id(get_max_uid(40000)))
print "Group with max GID is %s" % (get_group_by_id(get_max_gid(40000)))

View file

@ -21,16 +21,17 @@
import crypt, crack, random
_pwchars = []
for pair in (('0', '9'), ('A', 'Z'), ('a', 'z')):
_pwchars.extend(range(ord(pair[0]), ord(pair[1])))
for char in "-+/*_@":
_pwchars.append(ord(char))
def generatepassword(minlength = 8, maxlength = 12):
"""Generates a random password with a length between the given
minlength and maxlength values."""
pwchars = []
for pair in (('0', '9'), ('A', 'Z'), ('a', 'z')):
pwchars.extend(range(ord(pair[0]), ord(pair[1])))
for char in "-+/*_@":
pwchars.append(ord(char))
return "".join([chr(letter) for letter in \
random.sample(pwchars,
random.sample(_pwchars,
random.randint(minlength, maxlength))])
def checkpassword(password):
@ -45,7 +46,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(range(ord('a'), ord('z')), 8)])
random.sample(_pwchars, 8)])
return crypt.crypt(password, '$1$' + salt)
def get_pw_tuple(password = None):