From ee89f7af9e968344fa54dd93f877ea592a282fb0 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 6 Oct 1998 03:56:28 +0000 Subject: [PATCH] Fixed stuff I broke. --- citadel/ChangeLog | 3 + citadel/database.c | 8 -- citadel/msgbase.c | 53 ++++++++----- citadel/room_ops.c | 186 ++++++++++++++++++++++++++++----------------- citadel/server.h | 5 +- citadel/user_ops.c | 67 ++++------------ citadel/user_ops.h | 1 + 7 files changed, 175 insertions(+), 148 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index e1b12ea86..63eb1f3e2 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,6 @@ +Mon Oct 5 17:01:32 EDT 1998 Art Cancro + * Began fixing the stuff I broke + Sun Oct 4 23:35:18 EDT 1998 Art Cancro * Did the big migration to the new data structures. Lots of stuff is now broken. Basic moving from room to room works, but Mail is diff --git a/citadel/database.c b/citadel/database.c index 179ff82f6..0e6c08b27 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -46,7 +46,6 @@ void defrag_databases(void) { /* defrag the user file, mailboxes, and user/room relationships */ begin_critical_section(S_USERSUPP); gdbm_reorganize(gdbms[CDB_USERSUPP]); - gdbm_reorganize(gdbms[CDB_MAILBOXES]); gdbm_reorganize(gdbms[CDB_VISIT]); end_critical_section(S_USERSUPP); @@ -118,13 +117,6 @@ void open_databases(void) { gdbm_strerror(gdbm_errno)); } - gdbms[CDB_MAILBOXES] = gdbm_open("data/mailboxes.gdbm", 0, - GDBM_WRCREAT, 0600, NULL); - if (gdbms[CDB_MAILBOXES] == NULL) { - lprintf(2, "Cannot open mailboxes: %s\n", - gdbm_strerror(gdbm_errno)); - } - for (a=0; aquickroom.QRname); strcpy(hold_rm, ""); + strcpy(recipient, rec); /* If the user is a twit, move to the twit room for posting... */ if (TWITDETECT) if (CC->usersupp.axlevel==2) { - strcpy(hold_rm, CC->cs_room); - strcpy(CC->cs_room, config.c_twitroom); + strcpy(hold_rm, actual_rm); + strcpy(actual_rm, config.c_twitroom); + } + + /* ...or if this is a private message, go to the target mailbox. */ + if (strlen(recipient) > 0) { + mailtype = alias(recipient); + if (mailtype == M_LOCAL) { + if (getuser(&userbuf, recipient)!=0) { + mtsflag = 1; /* User not found, goto Aide */ + } + else { + strcpy(hold_rm, actual_rm); + MailboxName(actual_rm, &userbuf, MAILROOM); + } + } } /* ...or if this message is destined for Aide> then go there. */ if (mtsflag) { - strcpy(hold_rm, CC->cs_room); - strcpy(CC->cs_room, "Aide"); + strcpy(hold_rm, actual_rm); + strcpy(actual_rm, AIDEROOM); } - /* ...or if this is a private message, go to the target mailbox. */ - /* FIX FIX FIX do this! */ /* This call to usergoto() changes rooms if necessary. It also * causes the latest message list to be read into memory. */ lprintf(9, "Changing rooms if necessary...\n"); - usergoto(CC->cs_room, 0); + usergoto(actual_rm, 0); /* read in the quickroom record, obtaining a lock... */ - lprintf(9, "Reading/locking <%s>...\n", CC->cs_room); - lgetroom(&CC->quickroom, CC->cs_room); + lprintf(9, "Reading/locking <%s>...\n", actual_rm); + lgetroom(&CC->quickroom, actual_rm); lprintf(9, "Fetching message list...\n"); get_msglist(&CC->quickroom); - /* FIX here's where we have to to message expiry!! */ + /* FIX here's where we have to handle message expiry!! */ /* Now add the new message */ CC->num_msgs = CC->num_msgs + 1; CC->msglist = realloc(CC->msglist, ((CC->num_msgs) * sizeof(long)) ); if (CC->msglist == NULL) { - lprintf(3, "ERROR can't realloc message list!\n"); + lprintf(3, "ERROR: can't realloc message list!\n"); } SetMessageInList(CC->num_msgs - 1, newmsgid); @@ -753,8 +770,8 @@ void save_message(char *mtmp, /* file containing proper message */ /* update quickroom */ CC->quickroom.QRhighest = newmsgid; - lprintf(9, "Writing/unlocking room <%s>...\n", CC->cs_room); - lputroom(&CC->quickroom,CC->cs_room); + lprintf(9, "Writing/unlocking room <%s>...\n", actual_rm); + lputroom(&CC->quickroom, actual_rm); /* Bump this user's messages posted counter. Also, if the user is a * twit, give them access to the twit room. @@ -765,7 +782,7 @@ void save_message(char *mtmp, /* file containing proper message */ lputuser(&CC->usersupp, CC->curr_user); /* Network mail - send a copy to the network program. */ - if (mailtype!=M_LOCAL) { + if ((strlen(recipient)>0)&&(mailtype != M_LOCAL)) { sprintf(aaa,"./network/spoolin/nm.%d",getpid()); copy_file(mtmp,aaa); system("exec nohup ./netproc >/dev/null 2>&1 &"); @@ -1122,7 +1139,7 @@ void cmd_dele(char *delstr) } /* get room records, obtaining a lock... */ - lgetroom(&CC->quickroom,CC->cs_room); + lgetroom(&CC->quickroom,CC->quickroom.QRname); get_msglist(&CC->quickroom); ok = 0; @@ -1137,7 +1154,7 @@ void cmd_dele(char *delstr) CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1); put_msglist(&CC->quickroom); - lputroom(&CC->quickroom,CC->cs_room); + lputroom(&CC->quickroom,CC->quickroom.QRname); if (ok==1) { cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long)); cprintf("%d Message deleted.\n",OK); @@ -1174,7 +1191,7 @@ void cmd_move(char *args) } /* yank the message out of the current room... */ - lgetroom(&CC->quickroom, CC->cs_room); + lgetroom(&CC->quickroom, CC->quickroom.QRname); get_msglist(&CC->quickroom); foundit = 0; @@ -1189,7 +1206,7 @@ void cmd_move(char *args) put_msglist(&CC->quickroom); CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1); } - lputroom(&CC->quickroom,CC->cs_room); + lputroom(&CC->quickroom,CC->quickroom.QRname); if (!foundit) { cprintf("%d msg %ld does not exist.\n",ERROR,num); return; diff --git a/citadel/room_ops.c b/citadel/room_ops.c index c16c1cac4..4aa538e80 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -135,6 +135,7 @@ int lgetroom(struct quickroom *qrbuf, char *room_name) /* * putroom() - store room data on disk + * (if the supplied buffer is NULL, delete the room record) */ void putroom(struct quickroom *qrbuf, char *room_name) { @@ -145,9 +146,16 @@ void putroom(struct quickroom *qrbuf, char *room_name) lowercase_name[a] = tolower(room_name[a]); } - time(&qrbuf->QRmtime); - cdb_store(CDB_QUICKROOM, lowercase_name, strlen(lowercase_name), - qrbuf, sizeof(struct quickroom)); + if (qrbuf == NULL) { + cdb_delete(CDB_QUICKROOM, + lowercase_name, strlen(lowercase_name)); + } + else { + time(&qrbuf->QRmtime); + cdb_store(CDB_QUICKROOM, + lowercase_name, strlen(lowercase_name), + qrbuf, sizeof(struct quickroom)); + } } @@ -250,17 +258,22 @@ void get_msglist(struct quickroom *whichroom) { struct cdbdata *cdbfr; char dbkey[256]; int a; - + + lprintf(9, "get_msglist() called for <%s>\n", whichroom->QRname); sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen); for (a=0; a\n", dbkey); + + lprintf(9, "Freeing existing message list\n"); if (CC->msglist != NULL) { free(CC->msglist); } CC->msglist = NULL; CC->num_msgs = 0; + lprintf(9, "calling cdb_fetch\n"); cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey)); + lprintf(9, "done\n"); if (cdbfr == NULL) { return; @@ -270,6 +283,7 @@ void get_msglist(struct quickroom *whichroom) { memcpy(CC->msglist, cdbfr->ptr, cdbfr->len); CC->num_msgs = cdbfr->len / sizeof(long); cdb_free(cdbfr); + lprintf(9, "Leaving get_msglist()\n"); } @@ -558,9 +572,12 @@ void usergoto(char *where, int display_result) int newmailcount = 0; struct visit vbuf; - strcpy(CC->cs_room, where); - getroom(&CC->quickroom, CC->cs_room); + strcpy(CC->quickroom.QRname, where); + lprintf(9, "usergoto() fetching room record\n"); + getroom(&CC->quickroom, where); + lprintf(9, "usergoto() fetching user record\n"); lgetuser(&CC->usersupp,CC->curr_user); + lprintf(9, "usergoto() fetching relationships\n"); CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT; @@ -569,6 +586,7 @@ void usergoto(char *where, int display_result) CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); lputuser(&CC->usersupp,CC->curr_user); + lprintf(9, "usergoto() about to check for new mail\n"); /* check for new mail */ newmailcount = NewMailCount(); @@ -576,6 +594,7 @@ void usergoto(char *where, int display_result) if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1; get_mm(); + lprintf(9, "Fetching message list for counting...\n"); get_msglist(&CC->quickroom); for (a=0; anum_msgs; ++a) { if (MessageFromList(a)>0L) { @@ -585,9 +604,9 @@ void usergoto(char *where, int display_result) } } } + lprintf(9, "...done counting\n"); - - if (0) rmailflag = 1; /* FIX to handle mail rooms!!! */ + if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1; else rmailflag = 0; if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum) @@ -724,7 +743,7 @@ void cmd_rdir(void) { return; } - getroom(&CC->quickroom, CC->cs_room); + getroom(&CC->quickroom, CC->quickroom.QRname); getuser(&CC->usersupp, CC->curr_user); if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) { @@ -792,13 +811,13 @@ void cmd_getr(void) { return; } - if ( (!strcasecmp(CC->cs_room, BASEROOM)) - || (!strcasecmp(CC->cs_room, AIDEROOM)) ) { + if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM)) + || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) { cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE); return; } - getroom(&CC->quickroom, CC->cs_room); + getroom(&CC->quickroom, CC->quickroom.QRname); cprintf("%d%c%s|%s|%s|%d|%d\n", OK,check_express(), CC->quickroom.QRname, @@ -828,8 +847,8 @@ void cmd_setr(char *args) { return; } - if ( (!strcasecmp(CC->cs_room, BASEROOM)) - || (!strcasecmp(CC->cs_room, AIDEROOM)) ) { + if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM)) + || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) { cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE); return; } @@ -843,7 +862,7 @@ void cmd_setr(char *args) { } } - lgetroom(&CC->quickroom, CC->cs_room); + lgetroom(&CC->quickroom, CC->quickroom.QRname); extract(buf,args,0); buf[ROOMNAMELEN]=0; strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1); extract(buf,args,1); buf[10]=0; @@ -872,7 +891,7 @@ void cmd_setr(char *args) { CC->quickroom.QRfloor = extract_int(args,5); } - lputroom(&CC->quickroom, CC->cs_room); + lputroom(&CC->quickroom, CC->quickroom.QRname); /* adjust the floor reference counts */ lgetfloor(&flbuf,old_floor); @@ -908,8 +927,8 @@ void cmd_geta(void) { return; } - if ( (!strcasecmp(CC->cs_room, BASEROOM)) - || (!strcasecmp(CC->cs_room, AIDEROOM)) ) { + if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM)) + || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) { cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE); return; } @@ -951,13 +970,13 @@ void cmd_seta(char *new_ra) newu = usbuf.usernum; } - lgetroom(&CC->quickroom, CC->cs_room); + lgetroom(&CC->quickroom, CC->quickroom.QRname); post_notice = 0; if (CC->quickroom.QRroomaide != newu) { post_notice = 1; } CC->quickroom.QRroomaide = newu; - lputroom(&CC->quickroom, CC->cs_room); + lputroom(&CC->quickroom, CC->quickroom.QRname); /* * We have to post the change notice _after_ writing changes to @@ -1009,15 +1028,61 @@ void cmd_rinf(void) { } /* - * aide command: kill the current room + * Back end processing to delete a room and everything associated with it */ -void cmd_kill(char *argbuf) -{ +void delete_room(struct quickroom *qrbuf) { + struct floor flbuf; + long MsgToDelete; char aaa[100]; int a; + + /* Delete the info file */ + assoc_file_name(aaa, qrbuf, "info"); + unlink(aaa); + + /* Delete the image file */ + assoc_file_name(aaa, qrbuf, "images"); + unlink(aaa); + + /* first flag the room record as not in use */ + lgetroom(qrbuf, qrbuf->QRname); + qrbuf->QRflags=0; + + /* then delete the messages in the room */ + lprintf(9, "calling get_msglist()\n"); + get_msglist(qrbuf); + if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) { + MsgToDelete = MessageFromList(a); + lprintf(9, "Deleting message %ld\n", MsgToDelete); + cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long)); + } + lprintf(9, "calling put_msglist()\n"); + put_msglist(qrbuf); + free(CC->msglist); + CC->msglist = NULL; + CC->num_msgs = 0; + lprintf(9, "calling delete_msglist()\n"); + delete_msglist(qrbuf); + lputroom(qrbuf, qrbuf->QRname); + + /* then decrement the reference count for the floor */ + lgetfloor(&flbuf,(int)(qrbuf->QRfloor)); + flbuf.f_ref_count = flbuf.f_ref_count - 1; + lputfloor(&flbuf,(int)(qrbuf->QRfloor)); + + /* Delete the room record from the database! */ + putroom(NULL, qrbuf->QRname); + lprintf(9, "finished with delete_room()\n"); + } + + +/* + * aide command: kill the current room + */ +void cmd_kill(char *argbuf) { + char aaa[100]; + char deleted_room_name[ROOMNAMELEN]; int kill_ok; - struct floor flbuf; - long MsgToDelete; kill_ok = extract_int(argbuf,0); @@ -1032,50 +1097,26 @@ void cmd_kill(char *argbuf) return; } - if ( (!strcasecmp(CC->cs_room, BASEROOM)) - || (!strcasecmp(CC->cs_room, AIDEROOM)) ) { + if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM)) + || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) { cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE); return; } if (kill_ok) { + strcpy(deleted_room_name, CC->quickroom.QRname); + delete_room(&CC->quickroom); /* Do the dirty work */ + lprintf(9, "Calling usergoto()\n"); + usergoto(BASEROOM, 0); /* Return to the Lobby */ - /* Delete the info file */ - assoc_file_name(aaa, &CC->quickroom, "info"); - unlink(aaa); - - /* first flag the room record as not in use */ - lgetroom(&CC->quickroom, CC->cs_room); - CC->quickroom.QRflags=0; - - /* then delete the messages in the room */ - get_msglist(&CC->quickroom); - if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) { - MsgToDelete = MessageFromList(a); - cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long)); - } - put_msglist(&CC->quickroom); - free(CC->msglist); - CC->num_msgs = 0; - delete_msglist(&CC->quickroom); - lputroom(&CC->quickroom, CC->cs_room); - - /* FIX FIX FIX - * To do at this location in the code: - * 1. Delete the associated files (info, image) - * 2. Delete the room record from the database - */ - - /* then decrement the reference count for the floor */ - lgetfloor(&flbuf,(int)CC->quickroom.QRfloor); - flbuf.f_ref_count = flbuf.f_ref_count - 1; - lputfloor(&flbuf,(int)CC->quickroom.QRfloor); - + lprintf(9, "Composing notice\n"); /* tell the world what we did */ - sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user); + sprintf(aaa,"%s> killed by %s", + deleted_room_name, CC->curr_user); + lprintf(9, "Posting notice\n"); aide_message(aaa); - usergoto(BASEROOM, 0); - cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname); + lprintf(9, "done posting notice\n"); + cprintf("%d '%s' deleted.\n", OK, deleted_room_name); } else { cprintf("%d ok to delete.\n",OK); @@ -1107,11 +1148,20 @@ unsigned create_room(char *new_room_name, if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME); if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED); if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX); - qrbuf.QRroomaide = (-1L); - if ((new_room_type > 0)&&(CREATAIDE==1)) + + /* If the room is private, and the system administrator has elected + * to automatically grant room aide privileges, do so now; otherwise, + * set the room aide to undefined. + */ + if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) { qrbuf.QRroomaide=CC->usersupp.usernum; - qrbuf.QRhighest = 0L; - time(&qrbuf.QRgen); + } + else { + qrbuf.QRroomaide = (-1L); + } + + qrbuf.QRhighest = 0L; /* No messages in this room yet */ + time(&qrbuf.QRgen); /* Use a timestamp as the generation number */ qrbuf.QRfloor = new_room_floor; /* save what we just did... */ @@ -1262,9 +1312,9 @@ void cmd_einf(char *ok) fclose(fp); /* now update the room index so people will see our new info */ - lgetroom(&CC->quickroom,CC->cs_room); /* lock so no one steps on us */ + lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */ CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L; - lputroom(&CC->quickroom,CC->cs_room); + lputroom(&CC->quickroom,CC->quickroom.QRname); } diff --git a/citadel/server.h b/citadel/server.h index 615ec3737..6e713647a 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -127,9 +127,8 @@ struct ChatLine { #define CDB_QUICKROOM 2 /* room index */ #define CDB_FLOORTAB 3 /* floor index */ #define CDB_MSGLISTS 4 /* room message lists */ -#define CDB_MAILBOXES 5 /* mailbox message lists */ -#define CDB_VISIT 6 /* user/room relationships */ -#define MAXCDB 7 /* total number of CDB's defined */ +#define CDB_VISIT 5 /* user/room relationships */ +#define MAXCDB 6 /* total number of CDB's defined */ struct cdbdata { size_t len; diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 4efd6b7f0..53ed06818 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -410,11 +410,9 @@ void cmd_pass(char *buf) */ int purge_user(char *pname) { char filename[64]; + char mailboxname[ROOMNAMELEN]; struct usersupp usbuf; - int a; - struct cdbdata *cdbmb; - long *mailbox; - int num_mails; + struct quickroom qrbuf; if (getuser(&usbuf, pname) != 0) { lprintf(5, "Cannot purge user <%s> - not found\n", pname); @@ -426,22 +424,15 @@ int purge_user(char *pname) { /* Perform any purge functions registered by server extensions */ PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER); - /* delete any messages in the user's mailbox */ - cdbmb = cdb_fetch(CDB_MAILBOXES, &usbuf.usernum, sizeof(long)); - if (cdbmb != NULL) { - num_mails = cdbmb->len / sizeof(long); - mailbox = (long *) cdbmb->ptr; - if (num_mails > 0) for (a=0; ausersupp,CC->curr_user)) { return(ERROR+INTERNAL_ERROR); } - + /* give the user a private mailbox */ MailboxName(mailboxname, &CC->usersupp, MAILROOM); create_room(mailboxname, 4, "", 0); @@ -711,13 +702,6 @@ void cmd_invt_kick(char *iuser, int op) return; } - /* FIX - with the new relationships scheme we can lock users out, - so it'll make sense to remove this routine */ - if ( (op==1) && ((CC->quickroom.QRflags&QR_PRIVATE)==0) ) { - cprintf("%d Not a private room.\n",ERROR+NOT_HERE); - return; - } - if (lgetuser(&USscratch,iuser)!=0) { cprintf("%d No such user.\n",ERROR); return; @@ -747,12 +731,10 @@ void cmd_invt_kick(char *iuser, int op) CC->usersupp.fullname); aide_message(bbb); - if ((op==0)&&((CC->quickroom.QRflags&QR_PRIVATE)==0)) { - cprintf("%d Ok. (Not a private room, ap effect only)\n",OK); - } - else { - cprintf("%d Ok.\n",OK); - } + cprintf("%d %s %s %s.\n", + OK, iuser, + ((op == 1) ? "invited to" : "kicked out of"), + CC->quickroom.QRname); return; } @@ -1288,28 +1270,11 @@ void cmd_asup(char *cmdbuf) { */ int NewMailCount() { int num_newmsgs = 0; - struct cdbdata *cdbmb; - int num_mails; - long *mailbox; - int a; char mailboxname[32]; MailboxName(mailboxname, &CC->usersupp, MAILROOM); - for (a=0; a<=strlen(mailboxname); ++a) { - mailboxname[a] = tolower(mailboxname[a]); - } - - cdbmb = cdb_fetch(CDB_MAILBOXES, mailboxname, strlen(mailboxname)); - if (cdbmb != NULL) { - num_mails = cdbmb->len / sizeof(long); - mailbox = (long *) cdbmb->ptr; - if (num_mails > 0) for (a=0; a