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

« back to all changes in this revision

Viewing changes to lib/common/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:
32
32
# TODO: When creating a new home directory, chown it to its owner
33
33
 
34
34
import os
 
35
import stat
35
36
import shutil
36
37
import warnings
37
38
 
38
39
import conf
39
40
import db
40
41
 
41
 
def makeuser(username, password, nick, fullname, rolenm, studentid):
42
 
    """Creates a new user on a pre-installed system.
43
 
    Sets up the following:
44
 
    * User's jail and home directory within the jail.
45
 
    * Subversion repository
46
 
    * Check out Subversion workspace into jail
47
 
    * Database details for user
48
 
    * Unix user account
49
 
    """
50
 
    homedir = make_jail(username)
51
 
    make_user_db(username, password, nick, fullname, rolenm, studentid)
52
 
    # TODO: -p password (need to use crypt)
53
 
    #if os.system("useradd -d %s '%s'" % (homedir, username)) != 0:
54
 
    #    raise Exception("Failed to add Unix user account")
55
 
 
56
 
def make_jail(username, force=True):
 
42
def make_jail(username, uid, force=True):
57
43
    """Creates a new user's jail space, in the jail directory as configured in
58
44
    conf.py.
59
45
 
64
50
 
65
51
    Returns the path to the user's home directory.
66
52
 
 
53
    Chowns the user's directory within the jail to the given UID.
 
54
 
 
55
    Note: This takes separate username and uid arguments. The UID need not
 
56
    *necessarily* correspond to a Unix username at all, if all you are
 
57
    planning to do is setuid to it. This allows the caller the freedom of
 
58
    deciding the binding between username and uid, if any.
 
59
 
67
60
    force: If false, exception if jail already exists for this user.
68
61
    If true (default), overwrites it, but preserves home directory.
69
62
    """
127
120
        # Set up the user's home directory
128
121
        userhomedir = os.path.join(homedir, username)
129
122
        os.mkdir(userhomedir)
 
123
        # Chown (and set the GID to the same as the UID).
 
124
        os.chown(userhomedir, uid, uid)
 
125
        # Chmod to rwx------ (700)
 
126
        os.chmod(userhomedir, stat.S_IRWXU)
130
127
        return userhomedir
131
128
 
132
129
def linktree(src, dst):