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

« back to all changes in this revision

Viewing changes to scripts/usrmgt-server

  • Committer: mattgiuca
  • Date: 2008-05-11 05:11:09 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:754
listusers.py: Added options processing (now accepts -h and -n).
    If -n is given, just prints out a list of usernames, rather than
    all the user details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
    db.update_user(**update)
99
99
    db.close()
100
100
 
101
 
def get_login(login, passwd, realm, existing_login, _may_save):
 
101
def get_login(login, passwd, _realm, _login, _may_save):
102
102
    """Callback function used by pysvn for authentication.
103
 
    login, passwd: Credentials of the user attempting to log in.
104
 
        passwd in clear (this should be the user's svn_pass, a
105
 
        randomly-generated permanent password for this user, not their main
106
 
        IVLE password).
107
 
    realm, existing_login, _may_save: The 3 arguments passed by pysvn to
108
 
        callback_get_login.
109
 
        The following has been determined empirically, not from docs:
110
 
        existing_login will be the name of the user who owns the process on
111
 
        the first attempt, "" on subsequent attempts. We use this fact.
112
103
    """
113
 
    logging.debug("Getting password for %s (realm %s)" % (login, realm))
114
 
    # Only provide credentials on the _first_ attempt.
115
 
    # If we're being asked again, then it means the credentials failed for
116
 
    # some reason and we should just fail. (This is not desirable, but it's
117
 
    # better than being asked an infinite number of times).
118
 
    if existing_login == "":
119
 
        logging.warning("Could not authenticate SVN for %s" % login)
120
 
        return (False, login, passwd, False)
121
 
    else:
122
 
        return (True, login, passwd, False)
 
104
    logging.debug("Getting password for %s (realm %s)" % (login, _realm))
 
105
    return (True, login, passwd, False)
123
106
 
124
107
def activate_user(props):
125
108
    """Create the on-disk stuff for the given user.
130
113
       Return Value: None
131
114
    """
132
115
 
133
 
    os.umask(0022) # Bad, but start_server sets it worse.
134
 
 
135
116
    login = props['login']
136
117
 
137
118
    db = common.db.DB()
180
161
            pass
181
162
 
182
163
        logging.debug("Creating jail")
183
 
        common.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
184
 
 
185
 
        common.makeuser.mount_jail(login)
186
 
 
187
 
        do_checkout(props, svn_pass=passwd)
 
164
        common.makeuser.make_jail(login, details.unixid)
 
165
 
 
166
        # FIXME: <hack>
 
167
 
 
168
        tcf_path = os.path.join(conf.jail_base, 'template/opt/ivle/lib/conf/conf.py')
 
169
        cf_path = os.path.join(conf.jail_base, login, 'opt/ivle/lib/conf/conf.py')
 
170
 
 
171
        os.remove(cf_path)
 
172
        cf = open(cf_path, "w")
 
173
        cf.write(open(tcf_path, "r").read())
 
174
        cf.write("# The login name for the owner of the jail\n")
 
175
        cf.write("login = %s\n" % repr(login))
 
176
        cf.write("\n")
 
177
        cf.write("# The subversion-only password for the owner of the jail\n")
 
178
        cf.write("svn_pass = %s\n" % repr(passwd))
 
179
        cf.close()
 
180
 
 
181
        # Check out the repositories into the student's home dir
 
182
        # FIXME: Call do_checkout instead of replicating this code.
 
183
        # (do_checkout currently doesn't work)
 
184
        #do_checkout(props)
 
185
 
 
186
        # FIXME: </hack>
 
187
 
 
188
        logging.debug("Checking out directories in the jail")
 
189
        try:
 
190
            svn.checkout(conf.svn_addr + login + "/stuff",
 
191
                         common.studpath.url_to_local(login + "/stuff")[1])
 
192
            os.system("chown -R %d:%d %s" \
 
193
                    % (details.unixid, details.unixid,
 
194
                       common.studpath.url_to_local(login + "/stuff")[1]))
 
195
        except Exception, exc:
 
196
            logging.warning("While mkdiring stuff: %s" % str(exc))
 
197
            pass
 
198
        try:
 
199
            svn.checkout(conf.svn_addr + login + "/info1",
 
200
                         common.studpath.url_to_local(login + "/info1")[1])
 
201
            os.system("chown -R %d:%d %s" \
 
202
                    % (details.unixid, details.unixid,
 
203
                       common.studpath.url_to_local(login + "/info1")[1]))
 
204
        except Exception, exc:
 
205
            logging.warning("While mkdiring info1: %s" % str(exc))
 
206
            pass
188
207
 
189
208
        # FIXME: should this be nicer?
190
209
        os.system("chown -R %d:%d %s" \
191
210
                % (details.unixid, details.unixid,
192
211
                   common.studpath.url_to_local(login)[1]))
193
212
 
 
213
 
194
214
        logging.info("Enabling user")
195
215
        db.update_user(login, state='enabled')
196
216
 
199
219
    finally:
200
220
        db.close()
201
221
 
202
 
def do_checkout(props, svn_pass=None):
 
222
def do_checkout(props):
203
223
    """Create the default contents of a user's jail by checking out from the
204
224
    repositories.
205
225
    If any directory already exists, just fail silently (so this is not a
209
229
                      STRING REQUIRED
210
230
       Return Value: None
211
231
    """
 
232
    # XXX / FIXME: This doesn't work - cannot get passwd
 
233
    # (activate_me creates passwd, other svn stuff gets it from jailconf - we
 
234
    # can't access either at this point).
 
235
 
212
236
    login = props['login']
213
 
 
214
 
    db = common.db.DB()
215
 
    user = db.get_user(login)
216
 
    # If svn_pass isn't supplied, grab it from the DB
217
 
    if svn_pass is None:
218
 
        svn_pass = user.svn_pass
219
 
    db.close()
220
 
 
221
237
    svn = pysvn.Client()
222
 
    svn.callback_get_login = partial(get_login, login, svn_pass)
223
 
 
224
 
    if conf.svn_addr[-1] != os.sep:
225
 
        conf.svn_addr += os.sep
226
 
 
227
 
    # FIXME: <hack>
 
238
    svn.callback_get_login = partial(get_login, login, passwd)
 
239
 
 
240
    if conf.svn_addr[-1] != '/':
 
241
        conf.svn_addr = conf.svn_addr + "/"
 
242
 
 
243
    # FIXME: </hack>
228
244
 
229
245
    logging.debug("Checking out directories in the jail")
230
246
    try:
231
247
        svn.checkout(conf.svn_addr + login + "/stuff",
232
248
                     common.studpath.url_to_local(login + "/stuff")[1])
233
249
        os.system("chown -R %d:%d %s" \
234
 
                % (user.unixid, user.unixid,
 
250
                % (details.unixid, details.unixid,
235
251
                   common.studpath.url_to_local(login + "/stuff")[1]))
236
252
    except Exception, exc:
237
253
        logging.warning("While mkdiring stuff: %s" % str(exc))
240
256
        svn.checkout(conf.svn_addr + login + "/info1",
241
257
                     common.studpath.url_to_local(login + "/info1")[1])
242
258
        os.system("chown -R %d:%d %s" \
243
 
                % (user.unixid, user.unixid,
 
259
                % (details.unixid, details.unixid,
244
260
                   common.studpath.url_to_local(login + "/info1")[1]))
245
261
    except Exception, exc:
246
262
        logging.warning("While mkdiring info1: %s" % str(exc))
247
263
        pass
248
264
 
249
 
    # FIXME: </hack>
250
 
 
251
265
    return {"response": "okay"}
252
266
 
253
267
actions = {