- restructured
- implementation of client and sysuser cli - backend for client, sysuser, domain and record - unified cli binary gva git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@226 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
ee36146629
commit
926acaddfa
19 changed files with 1010 additions and 345 deletions
24
gnuviechadmin/util/__init__.py
Normal file
24
gnuviechadmin/util/__init__.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# Copyright (C) 2007 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
# USA.
|
||||
#
|
||||
# Version: $Id$
|
||||
|
||||
"""This is the gnuviechadmin.util package.
|
||||
|
||||
The package provides utility modules for various functions."""
|
94
gnuviechadmin/util/getenttools.py
Normal file
94
gnuviechadmin/util/getenttools.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# Copyright (C) 2007 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
# USA.
|
||||
#
|
||||
# Version: $Id$
|
||||
|
||||
import os, popen2
|
||||
|
||||
class PasswdUser(object):
|
||||
"""This class represents users in the user database."""
|
||||
def __init__(self, username, pw, uid, gid, gecos, home, shell):
|
||||
self.username = username
|
||||
self.uid = int(uid)
|
||||
self.gid = int(gid)
|
||||
self.gecos = gecos
|
||||
self.home = home
|
||||
self.shell = shell
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%s:%d:%d:%s:%s:%s)" % (self.__class__.__name__,
|
||||
self.username,
|
||||
self.uid,
|
||||
self.gid,
|
||||
self.gecos,
|
||||
self.home,
|
||||
self.shell)
|
||||
|
||||
class PasswdGroup(object):
|
||||
"""This class represents lines in the groups database."""
|
||||
def __init__(self, groupname, pw, gid, members):
|
||||
self.groupname = groupname
|
||||
self.gid = int(gid)
|
||||
self.members = members.split(",")
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%s:%d:%s)" % (self.__class__.__name__,
|
||||
self.groupname,
|
||||
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 parseusers():
|
||||
(stdout, stdin) = popen2.popen2("getent passwd")
|
||||
return [PasswdUser(*arr) for arr in [line.strip().split(":") for line in stdout]]
|
||||
|
||||
def finduserbyprefix(prefix):
|
||||
"""Finds all user entries with the given prefix."""
|
||||
return [user for user in parseusers() if user.username.startswith(prefix)]
|
||||
|
||||
def getuserbyid(uid):
|
||||
"""Gets the user with the given user id."""
|
||||
users = [user for user in parseusers() if user.uid == uid]
|
||||
if users:
|
||||
return users[0]
|
||||
return None
|
||||
|
||||
def getgroupbyid(gid):
|
||||
"""Gets the group with the given group id."""
|
||||
groups = [group for group in parsegroups() if group.gid == gid]
|
||||
if groups:
|
||||
return groups[0]
|
||||
return None
|
||||
|
||||
def getmaxuid(boundary = 65536):
|
||||
"""Gets the highest uid value."""
|
||||
return max([user.uid for user in parseusers() if user.uid <= boundary])
|
||||
|
||||
def getmaxgid(boundary = 65536):
|
||||
"""Gets the highest gid value."""
|
||||
return max([group.gid for group in parsegroups() 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)))
|
57
gnuviechadmin/util/passwordutils.py
Normal file
57
gnuviechadmin/util/passwordutils.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# Copyright (C) 2007 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
# USA.
|
||||
#
|
||||
# Version: $Id$
|
||||
|
||||
import crypt, crack, random
|
||||
|
||||
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.randint(minlength, maxlength))])
|
||||
|
||||
def checkpassword(password):
|
||||
"""Checks the password with cracklib. The password is returned if
|
||||
it is good enough. Otherwise None is returned."""
|
||||
try:
|
||||
return crack.VeryFascistCheck(password)
|
||||
except ValueError, ve:
|
||||
print "Weak password:", ve
|
||||
return None
|
||||
|
||||
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)])
|
||||
return crypt.crypt(password, '$1$' + salt)
|
||||
|
||||
def get_pw_tuple(password = None):
|
||||
"""Gets a valid tuple consisting of a password and a md5 hash of the
|
||||
password. If a password is given it is checked and if it is too weak
|
||||
replaced by a generated one."""
|
||||
while password == None or checkpassword(password) == None:
|
||||
password = generatepassword()
|
||||
return (password, md5_crypt_password(password))
|
Loading…
Add table
Add a link
Reference in a new issue