]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* Removed the built-in memory leak checker. It wasn't threadsafe and
[citadel.git] / citadel / user_ops.c
index a85a553ad8197b60cb3b639df692ac2b5817dd81..6f2e12eb4f006b4e61f88cfae419500b096a228e 100644 (file)
@@ -352,6 +352,7 @@ int CtdlLoginExistingUser(char *trythisname)
        char username[SIZ];
        int found_user;
        struct recptypes *valid = NULL;
+       struct passwd *p = NULL;
 
        if (trythisname == NULL) return login_not_found;
        safestrncpy(username, trythisname, sizeof username);
@@ -374,9 +375,23 @@ int CtdlLoginExistingUser(char *trythisname)
                                found_user = getuser(&CC->user,
                                                valid->recp_local);
                        }
-                       phree(valid);
+                       free(valid);
+               }
+       }
+
+#ifdef ENABLE_AUTOLOGIN
+       /* If we haven't found the account yet, and the supplied name
+        * is a login name on the underlying host system, create the
+        * account.
+        */
+       if (found_user != 0) {
+               p = (struct passwd *) getpwnam(username);
+               if (p != NULL) {
+                       create_user(username, 0);
+                       found_user = getuser(&CC->user, username);
                }
        }
+#endif /* ENABLE_AUTOLOGIN */
 
        /* Did we find something? */
        if (found_user == 0) {
@@ -423,6 +438,7 @@ void cmd_user(char *cmdbuf)
        case login_not_found:
                cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
                return;
+       default:
                cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
        }
 }
@@ -729,7 +745,7 @@ int purge_user(char pname[])
        lprintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
 
        /* Perform any purge functions registered by server extensions */
-       PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
+       PerformUserHooks(&usbuf, EVT_PURGEUSER);
 
        /* delete any existing user/room relationships */
        cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
@@ -825,8 +841,11 @@ int create_user(char *newusername, int become_user)
                 lputroom(&qrbuf);
         }
 
+       /* Perform any create functions registered by server extensions */
+       PerformUserHooks(&usbuf, EVT_NEWUSER);
+
        /* Everything below this line can be bypassed if administratively
-          creating a user, instead of doing self-service account creation
+        * creating a user, instead of doing self-service account creation
         */
 
        if (become_user) {
@@ -1093,16 +1112,48 @@ void cmd_gtsn(char *argbuf) {
 }
 
 
-
 /*
- * INVT and KICK commands
+ * API function for cmd_invt_kick() and anything else that needs to
+ * invite or kick out a user to/from a room.
+ * 
+ * Set iuser to the name of the user, and op to 1=invite or 0=kick
  */
-void cmd_invt_kick(char *iuser, int op)
-                       /* user name */
-{                              /* 1 = invite, 0 = kick out */
+int CtdlInvtKick(char *iuser, int op) {
        struct ctdluser USscratch;
-       char bbb[SIZ];
        struct visit vbuf;
+       char bbb[SIZ];
+
+       if (getuser(&USscratch, iuser) != 0) {
+               return(1);
+       }
+
+       CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
+       if (op == 1) {
+               vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
+               vbuf.v_flags = vbuf.v_flags | V_ACCESS;
+       }
+       if (op == 0) {
+               vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
+               vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
+       }
+       CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
+
+       /* post a message in Aide> saying what we just did */
+       snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
+               iuser,
+               ((op == 1) ? "invited to" : "kicked out of"),
+               CC->room.QRname,
+               CC->user.fullname);
+       aide_message(bbb);
+
+       return(0);
+}
+
+
+/*
+ * INVT and KICK commands
+ */
+void cmd_invt_kick(char *iuser, int op) {
 
        /*
         * These commands are only allowed by aides, room aides,
@@ -1125,32 +1176,11 @@ void cmd_invt_kick(char *iuser, int op)
                return;
        }
 
-       if (lgetuser(&USscratch, iuser) != 0) {
+       if (CtdlInvtKick(iuser, op) != 0) {
                cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
                return;
        }
 
-       CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
-       if (op == 1) {
-               vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
-               vbuf.v_flags = vbuf.v_flags | V_ACCESS;
-       }
-       if (op == 0) {
-               vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
-               vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
-       }
-       CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
-
-       lputuser(&USscratch);
-
-       /* post a message in Aide> saying what we just did */
-       snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
-               iuser,
-               ((op == 1) ? "invited to" : "kicked out of"),
-               CC->room.QRname,
-               CC->user.fullname);
-       aide_message(bbb);
-
        cprintf("%d %s %s %s.\n",
                CIT_OK, iuser,
                ((op == 1) ? "invited to" : "kicked out of"),
@@ -1547,7 +1577,7 @@ int InitialMailCheck()
         cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
 
         if (cdbfr != NULL) {
-                msglist = mallok(cdbfr->len);
+                msglist = malloc(cdbfr->len);
                 memcpy(msglist, cdbfr->ptr, cdbfr->len);
                 num_msgs = cdbfr->len / sizeof(long);
                 cdb_free(cdbfr);
@@ -1561,7 +1591,7 @@ int InitialMailCheck()
                         }
                 }
         if (msglist != NULL)
-                phree(msglist);
+                free(msglist);
 
         return (num_newmsgs);
 }