]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* Every user gets a Trash folder. Clients can also use _TRASH_
[citadel.git] / citadel / user_ops.c
index b43c7bb2af46a9b7833f49e645b3c90e54834ec3..1fb0936e629a818857b1cfc6cfdd58a5e9a0c7eb 100644 (file)
@@ -79,7 +79,9 @@ int getuser(struct ctdluser *usbuf, char name[])
        struct cdbdata *cdbus;
        int using_sysuser = 0;
 
-       memset(usbuf, 0, sizeof(struct ctdluser));
+       if (usbuf != NULL) {
+               memset(usbuf, 0, sizeof(struct ctdluser));
+       }
 
 #ifdef ENABLE_AUTOLOGIN
        if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
@@ -98,9 +100,11 @@ int getuser(struct ctdluser *usbuf, char name[])
        if (cdbus == NULL) {    /* user not found */
                return(1);
        }
-       memcpy(usbuf, cdbus->ptr,
-              ((cdbus->len > sizeof(struct ctdluser)) ?
-               sizeof(struct ctdluser) : cdbus->len));
+       if (usbuf != NULL) {
+               memcpy(usbuf, cdbus->ptr,
+                       ((cdbus->len > sizeof(struct ctdluser)) ?
+                        sizeof(struct ctdluser) : cdbus->len));
+       }
        cdb_free(cdbus);
 
        return (0);
@@ -352,11 +356,10 @@ 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);
-       strproc(username);
+       safestrncpy(username, trythisname, USERNAME_SIZE);
+       striplt(username);
 
        if ((CC->logged_in)) {
                return login_already_logged_in;
@@ -369,13 +372,13 @@ int CtdlLoginExistingUser(char *trythisname)
         * is an e-mail address
         */
        if (found_user != 0) {
-               valid = validate_recipients(trythisname);
+               valid = validate_recipients(username);
                if (valid != NULL) {
                        if (valid->num_local == 1) {
                                found_user = getuser(&CC->user,
                                                valid->recp_local);
                        }
-                       phree(valid);
+                       free(valid);
                }
        }
 
@@ -385,7 +388,8 @@ int CtdlLoginExistingUser(char *trythisname)
         * account.
         */
        if (found_user != 0) {
-               p = (struct passwd *) getpwnam(username);
+               struct passwd *p = (struct passwd *) getpwnam(username);
+
                if (p != NULL) {
                        create_user(username, 0);
                        found_user = getuser(&CC->user, username);
@@ -413,10 +417,10 @@ int CtdlLoginExistingUser(char *trythisname)
  */
 void cmd_user(char *cmdbuf)
 {
-       char username[SIZ];
+       char username[256];
        int a;
 
-       extract(username, cmdbuf, 0);
+       extract_token(username, cmdbuf, 0, '|', sizeof username);
        striplt(username);
 
        a = CtdlLoginExistingUser(username);
@@ -438,6 +442,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);
        }
 }
@@ -482,8 +487,9 @@ void session_startup(void)
        /* Create any personal rooms required by the system.
         * (Technically, MAILROOM should be there already, but just in case...)
         */
-       create_room(MAILROOM, 4, "", 0, 1, 0);
-       create_room(SENTITEMS, 4, "", 0, 1, 0);
+       create_room(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
+       create_room(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
+       create_room(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
 
        /* Run any startup routines registered by loadable modules */
        PerformSessionHooks(EVT_LOGIN);
@@ -584,8 +590,8 @@ static int validpw(uid_t uid, const char *pass)
                }
                close(pipev[0]);
 
-               execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
-               perror(BBSDIR "/chkpwd");
+               execl(CTDLDIR "/chkpwd", CTDLDIR "/chkpwd", NULL);
+               perror(CTDLDIR "/chkpwd");
                exit(1);
        }
 
@@ -641,10 +647,10 @@ int CtdlTryPassword(char *password)
 
 
 #ifdef ENABLE_AUTOLOGIN
-       /* A uid of BBSUID or -1 indicates that this user exists only in
+       /* A uid of CTDLUID or -1 indicates that this user exists only in
         * Citadel, not in the underlying operating system.
         */
-       if ( (CC->user.uid == BBSUID) || (CC->user.uid == (-1)) ) {
+       if ( (CC->user.uid == CTDLUID) || (CC->user.uid == (-1)) ) {
                strproc(password);
                strproc(CC->user.password);
                code = strcasecmp(CC->user.password, password);
@@ -679,10 +685,10 @@ int CtdlTryPassword(char *password)
 
 void cmd_pass(char *buf)
 {
-       char password[SIZ];
+       char password[256];
        int a;
 
-       extract(password, buf, 0);
+       extract_token(password, buf, 0, '|', sizeof password);
        a = CtdlTryPassword(password);
 
        switch (a) {
@@ -699,8 +705,6 @@ void cmd_pass(char *buf)
        case pass_ok:
                logged_in_response();
                return;
-               cprintf("%d Can't find user record!\n",
-                       ERROR + INTERNAL_ERROR);
        }
 }
 
@@ -744,7 +748,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));
@@ -753,11 +757,23 @@ int purge_user(char pname[])
        cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
 
        /* remove the user's bio file */
-       snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
+       snprintf(filename, sizeof filename, 
+#ifndef HAVE_DATA_DIR
+                        "."
+#else
+                        DATA_DIR
+#endif
+                        "/bio/%ld", usbuf.usernum);
        unlink(filename);
 
        /* remove the user's picture */
-       snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
+       snprintf(filename, sizeof filename, 
+#ifndef HAVE_DATA_DIR
+                        "."
+#else
+                        DATA_DIR
+#endif
+                        "/userpics/%ld.gif", usbuf.usernum);
        unlink(filename);
 
        return (0);
@@ -775,8 +791,7 @@ int create_user(char *newusername, int become_user)
 {
        struct ctdluser usbuf;
        struct ctdlroom qrbuf;
-       struct passwd *p = NULL;
-       char username[SIZ];
+       char username[256];
        char mailboxname[ROOMNAMELEN];
        uid_t uid;
 
@@ -784,12 +799,15 @@ int create_user(char *newusername, int become_user)
        strproc(username);
 
 #ifdef ENABLE_AUTOLOGIN
-       p = (struct passwd *) getpwnam(username);
-       if (p != NULL) {
-               extract_token(username, p->pw_gecos, 0, ',');
-               uid = p->pw_uid;
-       } else {
-               uid = (-1);
+       {
+               struct passwd *p = (struct passwd *) getpwnam(username);
+
+               if (p != NULL) {
+                       extract_token(username, p->pw_gecos, 0, ',', sizeof username);
+                       uid = p->pw_uid;
+               } else {
+                       uid = (-1);
+               }
        }
 #else
        uid = (-1);
@@ -831,17 +849,20 @@ int create_user(char *newusername, int become_user)
         * Make the latter an invisible system room.
         */
        MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
-       create_room(mailboxname, 5, "", 0, 1, 1);
+       create_room(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
 
        MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
-       create_room(mailboxname, 5, "", 0, 1, 1);
+       create_room(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
         if (lgetroom(&qrbuf, mailboxname) == 0) {
                 qrbuf.QRflags2 |= QR2_SYSTEM;
                 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) {
@@ -869,7 +890,7 @@ int create_user(char *newusername, int become_user)
 void cmd_newu(char *cmdbuf)
 {
        int a;
-       char username[SIZ];
+       char username[26];
 
        if (config.c_disable_newu) {
                cprintf("%d Self-service user account creation "
@@ -886,7 +907,7 @@ void cmd_newu(char *cmdbuf)
                        ERROR + MAX_SESSIONS_EXCEEDED,
                        config.c_nodename, config.c_maxsessions);
        }
-       extract(username, cmdbuf, 0);
+       extract_token(username, cmdbuf, 0, '|', sizeof username);
        username[25] = 0;
        strproc(username);
 
@@ -930,7 +951,7 @@ void cmd_setp(char *new_pw)
        if (CtdlAccessCheck(ac_logged_in)) {
                return;
        }
-       if ( (CC->user.uid != BBSUID) && (CC->user.uid != (-1)) ) {
+       if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
                cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR + NOT_HERE);
                return;
        }
@@ -954,16 +975,16 @@ void cmd_setp(char *new_pw)
 void cmd_creu(char *cmdbuf)
 {
        int a;
-       char username[SIZ];
-       char password[SIZ];
+       char username[26];
+       char password[32];
        struct ctdluser tmp;
 
        if (CtdlAccessCheck(ac_aide)) {
                return;
        }
 
-       extract(username, cmdbuf, 0);
-       extract(password, cmdbuf, 1);
+       extract_token(username, cmdbuf, 0, '|', sizeof username);
+       extract_token(password, cmdbuf, 1, '|', sizeof password);
        username[25] = 0;
        password[31] = 0;
        strproc(username);
@@ -1091,7 +1112,8 @@ void cmd_seen(char *argbuf) {
        target_msgnum = extract_long(argbuf, 0);
        target_setting = extract_int(argbuf, 1);
 
-       CtdlSetSeen(target_msgnum, target_setting, ctdlsetseen_seen);
+       CtdlSetSeen(&target_msgnum, 1, target_setting,
+                       ctdlsetseen_seen, NULL, NULL);
        cprintf("%d OK\n", CIT_OK);
 }
 
@@ -1287,11 +1309,11 @@ void cmd_gnur(void)
  */
 void cmd_vali(char *v_args)
 {
-       char user[SIZ];
+       char user[128];
        int newax;
        struct ctdluser userbuf;
 
-       extract(user, v_args, 0);
+       extract_token(user, v_args, 0, '|', sizeof user);
        newax = extract_int(v_args, 1);
 
        if (CtdlAccessCheck(ac_aide)) {
@@ -1347,6 +1369,13 @@ void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
  */
 void ListThisUser(struct ctdluser *usbuf, void *data)
 {
+       char *searchstring;
+
+       searchstring = (char *)data;
+       if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
+               return;
+       }
+
        if (usbuf->axlevel > 0) {
                if ((CC->user.axlevel >= 6)
                    || ((usbuf->flags & US_UNLISTED) == 0)
@@ -1366,12 +1395,15 @@ void ListThisUser(struct ctdluser *usbuf, void *data)
 }
 
 /* 
- *  List users
+ *  List users (searchstring may be empty to list all users)
  */
-void cmd_list(void)
+void cmd_list(char *cmdbuf)
 {
+       char searchstring[256];
+       extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
+       striplt(searchstring);
        cprintf("%d \n", LISTING_FOLLOWS);
-       ForEachUser(ListThisUser, NULL);
+       ForEachUser(ListThisUser, (void *)searchstring );
        cprintf("000\n");
 }
 
@@ -1429,13 +1461,13 @@ void cmd_qusr(char *who)
 void cmd_agup(char *cmdbuf)
 {
        struct ctdluser usbuf;
-       char requested_user[SIZ];
+       char requested_user[128];
 
        if (CtdlAccessCheck(ac_aide)) {
                return;
        }
 
-       extract(requested_user, cmdbuf, 0);
+       extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
        if (getuser(&usbuf, requested_user) != 0) {
                cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
                return;
@@ -1461,7 +1493,7 @@ void cmd_agup(char *cmdbuf)
 void cmd_asup(char *cmdbuf)
 {
        struct ctdluser usbuf;
-       char requested_user[SIZ];
+       char requested_user[128];
        char notify[SIZ];
        int np;
        int newax;
@@ -1470,14 +1502,14 @@ void cmd_asup(char *cmdbuf)
        if (CtdlAccessCheck(ac_aide))
                return;
 
-       extract(requested_user, cmdbuf, 0);
+       extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
        if (lgetuser(&usbuf, requested_user) != 0) {
                cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
                return;
        }
        np = num_parms(cmdbuf);
        if (np > 1)
-               extract(usbuf.password, cmdbuf, 1);
+               extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
        if (np > 2)
                usbuf.flags = extract_int(cmdbuf, 2);
        if (np > 3)
@@ -1573,7 +1605,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);
@@ -1587,7 +1619,7 @@ int InitialMailCheck()
                         }
                 }
         if (msglist != NULL)
-                phree(msglist);
+                free(msglist);
 
         return (num_newmsgs);
 }