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

« back to all changes in this revision

Viewing changes to makeuser.py

  • Committer: mattgiuca
  • Date: 2008-02-05 02:18:01 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:412
lib/common/makeuser: Removed function makeuser. This top-level function is too
    specific. Callers can decide how to call the various make-user functions.
    make_jail: Added "uid" argument. The caller needs to pass the UID who will
    own the jail. This unties the username from the uid.
    Now chowns and chmods 700 the user's home directory within the jail IF it
    is being created. If the jail already exists it is assumed the user has it
    set up the way they like and it is not disturbed.
makeuser.py: Script now performs top-level actions without calling
    makeuser.makeuser. This script currently creates the unix user itself
    (because the lib version doesn't support that anymore).
    It also checks for root, then calls make_user_db and make_jail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
# Script to create a new user. This can also be done through the
24
24
# administration interface.
 
25
# This script wraps common.makeuser.
 
26
# It also creates a unix account which common.makeuser does not.
 
27
# (This script may not be appropriate for production on a multi-node
 
28
# environment).
25
29
 
26
30
import sys
27
31
import os
28
32
import os.path
 
33
import pwd
29
34
# Import modules from the website is tricky since they're in the www
30
35
# directory.
31
36
sys.path.append(os.path.join(os.getcwd(), 'www'))
37
42
        "<fullname> <rolenm> <studentid>"
38
43
    sys.exit()
39
44
 
 
45
if os.getuid() != 0:
 
46
    print "Must run makeuser.py as root."
 
47
    sys.exit()
 
48
 
40
49
username = sys.argv[1]
41
50
password = sys.argv[2]
42
51
nick = sys.argv[3]
45
54
studentid = sys.argv[6]
46
55
 
47
56
try:
48
 
    common.makeuser.makeuser(username, password, nick, fullname, rolenm,
 
57
    # Resolve the user's username into a UID
 
58
    # Create the user if it does not exist
 
59
    try:
 
60
        (_,_,uid,_,_,_,_) = pwd.getpwnam(username)
 
61
    except KeyError:
 
62
        if os.system("useradd '%s'" % username) != 0:
 
63
            raise Exception("Failed to add Unix user account")
 
64
        try:
 
65
            (_,_,uid,_,_,_,_) = pwd.getpwnam(username)
 
66
        except KeyError:
 
67
            raise Exception("Failed to add Unix user account")
 
68
    # Make the user's jail
 
69
    common.makeuser.make_jail(username, uid)
 
70
    # Make the user's database entry
 
71
    common.makeuser.make_user_db(username, password, nick, fullname, rolenm,
49
72
        studentid)
50
73
except Exception, message:
51
74
    print "Error: " + str(message)