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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: me at id
  • Date: 2009-01-15 03:02:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1150
ivle.makeuser.make_jail: Just take an ivle.database.User, rather than some
    attributes.

services/usrmgt-server: Give make_jail a User.

bin/ivle-remakeuser: Rewrite to use ivle.database.User.

Show diffs side-by-side

added added

removed removed

Lines of Context:
182
182
    return (to_add, to_remove)
183
183
 
184
184
 
185
 
def make_jail(username, uid, force=True, svn_pass=None):
 
185
def make_jail(user, force=True):
186
186
    """Creates a new user's jail space, in the jail directory as configured in
187
187
    conf.py.
188
188
 
193
193
 
194
194
    Chowns the user's directory within the jail to the given UID.
195
195
 
196
 
    Note: This takes separate username and uid arguments. The UID need not
197
 
    *necessarily* correspond to a Unix username at all, if all you are
198
 
    planning to do is setuid to it. This allows the caller the freedom of
199
 
    deciding the binding between username and uid, if any.
200
 
 
201
196
    force: If false, exception if jail already exists for this user.
202
197
    If true (default), overwrites it, but preserves home directory.
203
 
 
204
 
    svn_pass: If provided this will be a string, the randomly-generated
205
 
    Subversion password for this user (if you happen to already have it).
206
 
    If not provided, it will be read from the database.
207
198
    """
208
199
    # MUST run as root or some of this may fail
209
200
    if os.getuid() != 0:
216
207
    elif not os.path.isdir(tempdir):
217
208
        os.unlink(tempdir)
218
209
        os.mkdir(tempdir)
219
 
    userdir = os.path.join(ivle.conf.jail_src_base, username)
 
210
    userdir = os.path.join(ivle.conf.jail_src_base, user.login)
220
211
    homedir = os.path.join(userdir, 'home')
221
 
    userhomedir = os.path.join(homedir, username)   # Return value
 
212
    userhomedir = os.path.join(homedir, user.login)   # Return value
222
213
 
223
214
    if os.path.exists(userdir):
224
215
        if not force:
239
230
        shutil.move(homebackup, homedir)
240
231
        # Change the ownership of all the files to the right unixid
241
232
        logging.debug("chown %s's home directory files to uid %d"
242
 
            %(username, uid))
243
 
        os.chown(userhomedir, uid, uid)
 
233
            %(user.login, user.unixid))
 
234
        os.chown(userhomedir, user.unixid, user.unixid)
244
235
        for root, dirs, files in os.walk(userhomedir):
245
236
            for fsobj in dirs + files:
246
 
                os.chown(os.path.join(root, fsobj), uid, uid)
 
237
                os.chown(os.path.join(root, fsobj), user.unixid, user.unixid)
247
238
    else:
248
239
        # No user jail exists
249
240
        # Set up the user's home directory
250
241
        os.makedirs(userhomedir)
251
242
        # Chown (and set the GID to the same as the UID).
252
 
        os.chown(userhomedir, uid, uid)
 
243
        os.chown(userhomedir, user.unixid, user.unixid)
253
244
        # Chmod to rwxr-xr-x (755)
254
245
        os.chmod(userhomedir, 0755)
255
246
 
256
 
    # There are 2 special files which need to be generated specific to this
257
 
    # user: ${python_site_packages}/lib/conf/conf.py and /etc/passwd.
258
 
    # "__" username "__" users are exempt (special)
259
 
    if not (username.startswith("__") and username.endswith("__")):
260
 
        make_conf_py(username, userdir, ivle.conf.jail_system, svn_pass)
261
 
        make_etc_passwd(username, userdir, ivle.conf.jail_system, uid)
 
247
    make_conf_py(user.login, userdir, ivle.conf.jail_system, user.svn_pass)
 
248
    make_etc_passwd(user.login, userdir, ivle.conf.jail_system, user.unixid)
262
249
 
263
250
    return userhomedir
264
251
 
265
 
def make_conf_py(username, user_jail_dir, staging_dir, svn_pass=None):
 
252
def make_conf_py(username, user_jail_dir, staging_dir, svn_pass):
266
253
    """
267
254
    Creates (overwriting any existing file, and creating directories) a
268
255
    file ${python_site_packages}/ivle/conf/conf.py in a given user's jail.
279
266
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
280
267
    os.makedirs(os.path.dirname(conf_path))
281
268
 
282
 
    # If svn_pass isn't supplied, grab it from the DB
283
 
    if svn_pass is None:
284
 
        dbconn = ivle.db.DB()
285
 
        svn_pass = dbconn.get_user(username).svn_pass
286
 
        dbconn.close()
287
 
 
288
269
    # Read the contents of the template conf file
289
270
    try:
290
271
        template_conf_file = open(template_conf_path, "r")