]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / user_ops.c
index e6e2e0b331200862a284e025f85ba76fc0c7165e..ce4b0b33e4ed0657ea0627b4164c7f5ba45a0d88 100644 (file)
 #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>
@@ -213,7 +224,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);
        }
 }
 
@@ -265,6 +280,7 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
 {
        struct cdbdata *cdbus;
 
+       cdb_begin_transaction();
        cdb_rewind(CDB_USERSUPP);
 
        while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
@@ -274,9 +290,11 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
                        sizeof(struct usersupp) : cdbus->len));
                cdb_free(cdbus);
                if (usbuf->usernum == number) {
+                       cdb_end_transaction();
                        return (0);
                }
        }
+       cdb_end_transaction();
        return (-1);
 }
 
@@ -284,14 +302,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 +346,7 @@ int CtdlLoginExistingUser(char *username)
  */
 void cmd_user(char *cmdbuf)
 {
-       char username[256];
+       char username[SIZ];
        int a;
 
        extract(username, cmdbuf, 0);
@@ -363,7 +383,8 @@ void cmd_user(char *cmdbuf)
  */
 void session_startup(void)
 {
-       syslog(LOG_NOTICE, "user <%s> logged in", CC->curr_user);
+       syslog(LOG_NOTICE, "session %d: user <%s> logged in",
+              CC->cs_pid, CC->curr_user);
 
        lgetuser(&CC->usersupp, CC->curr_user);
        ++(CC->usersupp.timescalled);
@@ -482,14 +503,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);
@@ -520,7 +548,7 @@ int CtdlTryPassword(char *password)
 
 void cmd_pass(char *buf)
 {
-       char password[256];
+       char password[SIZ];
        int a;
 
        extract(password, buf, 0);
@@ -617,7 +645,6 @@ int create_user(char *newusername)
        int a;
        struct passwd *p = NULL;
        char username[64];
-       char mailboxname[ROOMNAMELEN];
 
        strcpy(username, newusername);
        strproc(username);
@@ -667,8 +694,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);
@@ -683,7 +709,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);
@@ -824,8 +850,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;
@@ -837,6 +864,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);
@@ -844,6 +872,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
  */
@@ -851,7 +900,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))
@@ -892,19 +941,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);
@@ -915,8 +960,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);
+       }
 }
 
 /*
@@ -939,6 +1006,7 @@ void cmd_gnur(void)
        /* There are unvalidated users.  Traverse the usersupp database,
         * and return the first user we find that needs validation.
         */
+       cdb_begin_transaction();
        cdb_rewind(CDB_USERSUPP);
        while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
                memset(&usbuf, 0, sizeof(struct usersupp));
@@ -949,9 +1017,11 @@ void cmd_gnur(void)
                if ((usbuf.flags & US_NEEDVALID)
                    && (usbuf.axlevel > 0)) {
                        cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
+                       cdb_end_transaction();
                        return;
                }
        }
+       cdb_end_transaction();
 
        /* If we get to this point, there are no more unvalidated users.
         * Therefore we clear the "users need validation" flag.
@@ -973,7 +1043,7 @@ void cmd_gnur(void)
  */
 void cmd_vali(char *v_args)
 {
-       char user[256];
+       char user[SIZ];
        int newax;
        struct usersupp userbuf;
 
@@ -1015,6 +1085,7 @@ void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
        struct usersupp usbuf;
        struct cdbdata *cdbus;
 
+       cdb_begin_transaction();
        cdb_rewind(CDB_USERSUPP);
 
        while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
@@ -1025,6 +1096,7 @@ void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
                cdb_free(cdbus);
                (*CallBack) (&usbuf, in_data);
        }
+       cdb_end_transaction();
 }
 
 
@@ -1115,7 +1187,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;
@@ -1147,7 +1219,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;