]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* When sending mail, copy to the sender's "Sent Items>" room instead of to
[citadel.git] / citadel / user_ops.c
index 6dc5ff8a2c98dc0b88761ceb2250ecc3953149bb..f154425078d9b29f2ec4bec8c1b8ea9eb5e1228a 100644 (file)
@@ -5,6 +5,10 @@
  *
  */
 
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
 #include "sysdep.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <pwd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <string.h>
 #include <syslog.h>
 #include <limits.h>
@@ -26,6 +41,7 @@
 #include "server.h"
 #include "database.h"
 #include "user_ops.h"
+#include "dynloader.h"
 #include "sysdep_decls.h"
 #include "support.h"
 #include "room_ops.h"
@@ -34,7 +50,6 @@
 #include "control.h"
 #include "msgbase.h"
 #include "config.h"
-#include "dynloader.h"
 #include "tools.h"
 #include "citserver.h"
 
@@ -213,7 +228,11 @@ void CtdlGetRelationship(struct visit *vbuf,
                       ((cdbvisit->len > sizeof(struct visit)) ?
                        sizeof(struct visit) : cdbvisit->len));
                cdb_free(cdbvisit);
-               return;
+       }
+
+       /* Set v_seen if necessary */
+       if (vbuf->v_seen[0] == 0) {
+               sprintf(vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
        }
 }
 
@@ -274,6 +293,7 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
                        sizeof(struct usersupp) : cdbus->len));
                cdb_free(cdbus);
                if (usbuf->usernum == number) {
+                       cdb_close_cursor(CDB_USERSUPP);
                        return (0);
                }
        }
@@ -284,14 +304,16 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
 /*
  * Back end for cmd_user() and its ilk
  */
-int CtdlLoginExistingUser(char *username)
+int CtdlLoginExistingUser(char *trythisname)
 {
-       char autoname[256];
+       char username[SIZ];
+       char autoname[SIZ];
        int found_user = 0;
        struct passwd *p;
        int a;
 
-       username[25] = 0;
+       if (trythisname == NULL) return login_not_found;
+       safestrncpy(username, trythisname, sizeof username);
        strproc(username);
 
        if ((CC->logged_in)) {
@@ -326,7 +348,7 @@ int CtdlLoginExistingUser(char *username)
  */
 void cmd_user(char *cmdbuf)
 {
-       char username[256];
+       char username[SIZ];
        int a;
 
        extract(username, cmdbuf, 0);
@@ -378,17 +400,23 @@ void session_startup(void)
        }
        lputuser(&CC->usersupp);
 
-       /* Run any cleanup routines registered by loadable modules */
+       /* Run any startup routines registered by loadable modules */
        PerformSessionHooks(EVT_LOGIN);
 
-       usergoto(BASEROOM, 0, NULL, NULL);      /* Enter the lobby */
+       /* Create any personal rooms required by the system */
+       create_room(SENTITEMS, 4, "", 0, 1);
+
+       /* Enter the lobby */
+       usergoto(BASEROOM, 0, NULL, NULL);
+
+       /* Record this login in the Citadel log */
        rec_log(CL_LOGIN, CC->curr_user);
 }
 
 
 void logged_in_response(void)
 {
-       cprintf("%d %s|%d|%d|%d|%u|%ld\n",
+       cprintf("%d %s|%d|%ld|%ld|%u|%ld\n",
                OK, CC->usersupp.fullname, CC->usersupp.axlevel,
                CC->usersupp.timescalled, CC->usersupp.posted,
                CC->usersupp.flags,
@@ -403,13 +431,29 @@ void logged_in_response(void)
 void logout(struct CitContext *who)
 {
        who->logged_in = 0;
+
+       /*
+        * If there is a download in progress, abort it.
+        */
        if (who->download_fp != NULL) {
                fclose(who->download_fp);
                who->download_fp = NULL;
        }
+
+       /*
+        * If there is an upload in progress, abort it.
+        */
        if (who->upload_fp != NULL) {
                abort_upl(who);
        }
+
+       /*
+        * If we were talking to a network node, we're not anymore...
+        */
+       if (strlen(who->net_node) > 0) {
+               network_talking_to(who->net_node, NTT_REMOVE);
+       }
+
        /* Do modular stuff... */
        PerformSessionHooks(EVT_LOGOUT);
 }
@@ -483,14 +527,21 @@ int CtdlTryPassword(char *password)
        int code;
 
        if ((CC->logged_in)) {
+               lprintf(5, "CtdlTryPassword: already logged in\n");
                return pass_already_logged_in;
        }
        if (!strcmp(CC->curr_user, NLI)) {
+               lprintf(5, "CtdlTryPassword: no user selected\n");
                return pass_no_user;
        }
        if (getuser(&CC->usersupp, CC->curr_user)) {
+               lprintf(5, "CtdlTryPassword: internal error\n");
                return pass_internal_error;
        }
+       if (password == NULL) {
+               lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
+               return pass_wrong_password;
+       }
        code = (-1);
        if (CC->usersupp.uid == BBSUID) {
                strproc(password);
@@ -521,7 +572,7 @@ int CtdlTryPassword(char *password)
 
 void cmd_pass(char *buf)
 {
-       char password[256];
+       char password[SIZ];
        int a;
 
        extract(password, buf, 0);
@@ -618,7 +669,6 @@ int create_user(char *newusername)
        int a;
        struct passwd *p = NULL;
        char username[64];
-       char mailboxname[ROOMNAMELEN];
 
        strcpy(username, newusername);
        strproc(username);
@@ -668,8 +718,7 @@ int create_user(char *newusername)
                return (ERROR + INTERNAL_ERROR);
        }
        /* give the user a private mailbox */
-       MailboxName(mailboxname, &CC->usersupp, MAILROOM);
-       create_room(mailboxname, 4, "", 0);
+       create_room(MAILROOM, 4, "", 0, 1);
 
        rec_log(CL_NEWUSER, CC->curr_user);
        return (0);
@@ -684,7 +733,7 @@ int create_user(char *newusername)
 void cmd_newu(char *cmdbuf)
 {
        int a;
-       char username[256];
+       char username[SIZ];
 
        if ((CC->logged_in)) {
                cprintf("%d Already logged in.\n", ERROR);
@@ -707,7 +756,7 @@ void cmd_newu(char *cmdbuf)
        if ((!strcasecmp(username, "bbs")) ||
            (!strcasecmp(username, "new")) ||
            (!strcasecmp(username, "."))) {
-               cprintf("%d '%s' is an invalid login name.\n", ERROR);
+               cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
                return;
        }
        if (a == ERROR + ALREADY_EXISTS) {
@@ -825,8 +874,9 @@ void cmd_slrp(char *new_ptr)
        long newlr;
        struct visit vbuf;
 
-       if (CtdlAccessCheck(ac_logged_in))
+       if (CtdlAccessCheck(ac_logged_in)) {
                return;
+       }
 
        if (!strncasecmp(new_ptr, "highest", 7)) {
                newlr = CC->quickroom.QRhighest;
@@ -838,6 +888,7 @@ void cmd_slrp(char *new_ptr)
 
        CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
        vbuf.v_lastseen = newlr;
+       sprintf(vbuf.v_seen, "*:%ld", newlr);
        CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
 
        lputuser(&CC->usersupp);
@@ -845,6 +896,27 @@ void cmd_slrp(char *new_ptr)
 }
 
 
+void cmd_seen(char *argbuf) {
+       long target_msgnum = 0L;
+       int target_setting = 0;
+
+       if (CtdlAccessCheck(ac_logged_in)) {
+               return;
+       }
+
+       if (num_parms(argbuf) != 2) {
+               cprintf("%d Invalid parameters\n", ERROR);
+               return;
+       }
+
+       target_msgnum = extract_long(argbuf, 0);
+       target_setting = extract_int(argbuf, 1);
+
+       CtdlSetSeen(target_msgnum, target_setting);
+       cprintf("%d OK\n", OK);
+}
+
+
 /*
  * INVT and KICK commands
  */
@@ -852,7 +924,7 @@ void cmd_invt_kick(char *iuser, int op)
                        /* user name */
 {                              /* 1 = invite, 0 = kick out */
        struct usersupp USscratch;
-       char bbb[256];
+       char bbb[SIZ];
        struct visit vbuf;
 
        if (CtdlAccessCheck(ac_room_aide))
@@ -893,19 +965,15 @@ void cmd_invt_kick(char *iuser, int op)
 
 
 /*
- * forget (Zap) the current room
+ * Forget (Zap) the current room (API call)
+ * Returns 0 on success
  */
-void cmd_forg(void)
-{
+int CtdlForgetThisRoom(void) {
        struct visit vbuf;
 
-       if (CtdlAccessCheck(ac_logged_in)) {
-               return;
-       }
-
+       /* On some systems, Aides are not allowed to forget rooms */
        if (is_aide() && (config.c_aide_zap == 0)) {
-               cprintf("%d Aides cannot forget rooms.\n", ERROR);
-               return;
+               return(1);
        }
 
        lgetuser(&CC->usersupp, CC->curr_user);
@@ -916,8 +984,30 @@ void cmd_forg(void)
 
        CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
        lputuser(&CC->usersupp);
-       cprintf("%d Ok\n", OK);
+
+       /* Return to the Lobby, so we don't end up in an undefined room */
        usergoto(BASEROOM, 0, NULL, NULL);
+       return(0);
+
+}
+
+
+/*
+ * forget (Zap) the current room
+ */
+void cmd_forg(void)
+{
+
+       if (CtdlAccessCheck(ac_logged_in)) {
+               return;
+       }
+
+       if (CtdlForgetThisRoom() == 0) {
+               cprintf("%d Ok\n", OK);
+       }
+       else {
+               cprintf("%d You may not forget this room.\n", ERROR);
+       }
 }
 
 /*
@@ -950,6 +1040,7 @@ void cmd_gnur(void)
                if ((usbuf.flags & US_NEEDVALID)
                    && (usbuf.axlevel > 0)) {
                        cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
+                       cdb_close_cursor(CDB_USERSUPP);
                        return;
                }
        }
@@ -974,7 +1065,7 @@ void cmd_gnur(void)
  */
 void cmd_vali(char *v_args)
 {
-       char user[256];
+       char user[SIZ];
        int newax;
        struct usersupp userbuf;
 
@@ -1038,11 +1129,11 @@ void ListThisUser(struct usersupp *usbuf, void *data)
                if ((CC->usersupp.axlevel >= 6)
                    || ((usbuf->flags & US_UNLISTED) == 0)
                    || ((CC->internal_pgm))) {
-                       cprintf("%s|%d|%ld|%ld|%d|%d|",
+                       cprintf("%s|%d|%ld|%ld|%ld|%ld|",
                                usbuf->fullname,
                                usbuf->axlevel,
                                usbuf->usernum,
-                               usbuf->lastcall,
+                               (long)usbuf->lastcall,
                                usbuf->timescalled,
                                usbuf->posted);
                        if (CC->usersupp.axlevel >= 6)
@@ -1116,7 +1207,7 @@ void cmd_qusr(char *who)
 void cmd_agup(char *cmdbuf)
 {
        struct usersupp usbuf;
-       char requested_user[256];
+       char requested_user[SIZ];
 
        if (CtdlAccessCheck(ac_aide)) {
                return;
@@ -1127,7 +1218,7 @@ void cmd_agup(char *cmdbuf)
                cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
                return;
        }
-       cprintf("%d %s|%s|%u|%d|%d|%d|%ld|%ld|%d\n",
+       cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
                OK,
                usbuf.fullname,
                usbuf.password,
@@ -1136,7 +1227,7 @@ void cmd_agup(char *cmdbuf)
                usbuf.posted,
                (int) usbuf.axlevel,
                usbuf.usernum,
-               usbuf.lastcall,
+               (long)usbuf.lastcall,
                usbuf.USuserpurge);
 }
 
@@ -1148,7 +1239,7 @@ void cmd_agup(char *cmdbuf)
 void cmd_asup(char *cmdbuf)
 {
        struct usersupp usbuf;
-       char requested_user[256];
+       char requested_user[SIZ];
        int np;
        int newax;
        int deleted = 0;