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

« back to all changes in this revision

Viewing changes to bin/ivle-remakeuser

  • Committer: William Grant
  • Date: 2009-05-05 06:46:58 UTC
  • mto: (1165.3.65 submissions-admin)
  • mto: This revision was merged to the branch mainline in revision 1247.
  • Revision ID: grantw@unimelb.edu.au-20090505064658-o913x4ooxxbjfo1q
Avoid clobbering the submission owner's privileges if they have offering privs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import optparse
30
30
import logging
31
31
 
32
 
import ivle.db
 
32
import ivle.config
 
33
import ivle.database
33
34
import ivle.makeuser
34
35
 
35
36
p = optparse.OptionParser()
48
49
                          os.path.basename(sys.argv[0])
49
50
    sys.exit(1)
50
51
 
51
 
try:
52
 
    db = ivle.db.DB()
53
 
    if options.all:
54
 
        list = db.get_users()
55
 
    else:
56
 
        if len(arguments) == 0:
57
 
            print >> sys.stderr, "must be run with -a or a username"
58
 
            sys.exit(1)
59
 
        list = [db.get_user(arguments[0])]
60
 
    res = db.get_all('login', ['login', 'unixid'])
61
 
    def repack(flds):
62
 
        return (flds['login'], flds['unixid'])
63
 
    uids = dict(map(repack,res))
64
 
except Exception, message:
65
 
    logging.error(str(message))
66
 
    sys.exit(1)
 
52
config = ivle.config.Config()
 
53
store = ivle.database.get_store(config)
 
54
 
 
55
if options.all:
 
56
    users = store.find(ivle.database.User).order_by(ivle.database.User.login)
 
57
else:
 
58
    if len(arguments) == 0:
 
59
        print >> sys.stderr, "must be run with -a or a username"
 
60
        sys.exit(1)
 
61
    users = [ivle.database.User.get_by_login(store, arguments[0])]
67
62
 
68
63
logging.info("rebuild started")
69
64
 
70
 
list.sort(key=lambda user: user.login)
71
 
for user in list:
72
 
    login = user.login
73
 
 
 
65
for user in users:
74
66
    try:
75
 
        # Resolve the user's login into a UID
76
 
        try:
77
 
            uid = uids[login]
78
 
        except KeyError:
79
 
            raise Exception("user %s does not have a unixid in the database"
80
 
                % login)
81
 
        # Remake the user's jail
82
 
        ivle.makeuser.make_jail(login, uid)
 
67
        ivle.makeuser.make_jail(user, config)
83
68
    except Exception, message:
84
69
        logging.warning(str(message))
85
70
        continue
86
71
 
87
 
    logging.debug("recreated user %s's jail." % login)
 
72
    logging.debug("recreated user %s's jail." % user.login)
88
73
    
89
74
logging.info("rebuild completed successfully")