~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to remakeuser.py

  • Committer: dcoles
  • Date: 2008-07-03 04:20:54 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:803
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should 
allow us to get in there and tidy up each module much easier. Also removed 
updatejails since this functionality seems to be duplicated with remakeuser.py 
and remakealluser.py scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
sys.path.append(os.path.join(os.getcwd(), 'www'))
34
34
import conf
35
35
import common.makeuser
 
36
import common.db
36
37
 
37
38
if len(sys.argv) <= 1:
38
 
    print "Usage: python remakeuser.py <username>"
 
39
    print "Usage: python remakeuser.py <login>"
39
40
    sys.exit()
40
41
 
41
42
if os.getuid() != 0:
42
43
    print "Must run remakeuser.py as root."
43
44
    sys.exit()
44
45
 
45
 
username = sys.argv[1]
 
46
login = sys.argv[1]
46
47
 
47
48
try:
48
 
    # Resolve the user's username into a UID
 
49
    # Resolve the user's login into a UID
49
50
    # Create the user if it does not exist
50
51
    try:
51
 
        (_,_,uid,_,_,_,_) = pwd.getpwnam(username)
 
52
        conn = common.db.DB()
 
53
        uid = conn.get_single({'login':login}, 'login', ['unixid'], ['login'])
52
54
    except KeyError:
53
 
        raise Exception("User does not have a Unix user account")
 
55
        raise Exception("User does not have a unixid in the database")
54
56
    # Remake the user's jail
55
 
    common.makeuser.make_jail(username, uid)
 
57
    common.makeuser.make_jail(login, uid)
56
58
except Exception, message:
57
59
    print "Error: " + str(message)
58
60
    sys.exit(1)
59
61
 
60
 
print "Successfully recreated user %s's jail." % username
 
62
print "Successfully recreated user %s's jail." % login