X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fuser_ops.c;h=965cec625563650f19cd964248c2c8d5bc41eda3;hb=be8d2e8c65b70b7caa227f794c3c849ef2367954;hp=172a4ad0921c00da53e5e49bf86911a7880712bb;hpb=06cf6a97dfb504e9132b42dc0fb07d9dcefe8a34;p=citadel.git diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 172a4ad09..965cec625 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -197,26 +197,12 @@ void lputuser(struct ctdluser *usbuf) * */ int rename_user(char *oldname, char *newname) { - CitContext *cptr; int retcode = RENAMEUSER_OK; struct ctdluser usbuf; char oldnamekey[USERNAME_SIZE]; char newnamekey[USERNAME_SIZE]; - /* We cannot rename a user who is currently logged in */ -/* FIXME: This is very broken!!!! - * We check that the user is not already logged in because we can't rename them - * if they are logged in. - * BUT THEN WE LEAVE A HUGE WINDOW FOR THEM TO LOG IN BEFORE WE LOCK TO RENAME THEM!!!!! - * We are also traversing an un-locked context list which is a very bad thing to do. - */ - for (cptr = ContextList; cptr != NULL; cptr = cptr->next) { - if (!strcasecmp(cptr->user.fullname, oldname)) { - return(RENAMEUSER_LOGGED_IN); - } - } - /* Create the database keys... */ makeuserkey(oldnamekey, oldname); makeuserkey(newnamekey, newname); @@ -224,6 +210,12 @@ int rename_user(char *oldname, char *newname) { /* Lock up and get going */ begin_critical_section(S_USERS); + /* We cannot rename a user who is currently logged in */ + if (CtdlIsUserLoggedIn(oldname)) { + end_critical_section(S_USERS); + return RENAMEUSER_LOGGED_IN; + } + if (CtdlGetUser(&usbuf, newname) == 0) { retcode = RENAMEUSER_ALREADY_EXISTS; }