$Log$
+ Revision 573.111 2001/03/11 19:23:32 ajc
+ * IMAP DELETE command ... also split up access control for room delete cmds
+
Revision 573.110 2001/03/10 17:29:07 ajc
* Implement proper access control for deleting messages from IMAP
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
}
+
+/*
+ * Check access control for deleting a room
+ */
+int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr) {
+
+ if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
+ return(0);
+ }
+
+ if (is_noneditable(qr)) {
+ return(0);
+ }
+
+ /*
+ * For mailboxes, check stuff
+ */
+ if (qr->QRflags & QR_MAILBOX) {
+
+ if (strlen(qr->QRname) < 12) return(0); /* bad name */
+
+ if (atol(qr->QRname) != CC->usersupp.usernum) {
+ return(0); /* not my room */
+ }
+
+ /* Can't delete your Mail> room */
+ if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
+
+ /* Otherwise it's ok */
+ return(1);
+ }
+
+ /*
+ * For normal rooms, just check for aide or room aide status.
+ */
+ else {
+ return(is_room_aide());
+ }
+
+ /* Should never get to this point, but to keep the compiler quiet... */
+ return(0);
+}
+
/*
* aide command: kill the current room
*/
kill_ok = extract_int(argbuf, 0);
- if (CtdlAccessCheck(ac_room_aide)) return;
-
- if (is_noneditable(&CC->quickroom)) {
- cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
+ if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom) == 0) {
+ cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
return;
}
if (kill_ok) {
void list_roomname(struct quickroom *qrbuf);
int is_noneditable(struct quickroom *qrbuf);
int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf);
+int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr);
+/*
+ * Implements the DELETE command
+ *
+ */
+void imap_delete(int num_parms, char *parms[]) {
+ int ret;
+ char roomname[ROOMNAMELEN];
+ char savedroom[ROOMNAMELEN];
+ int msgs, new;
+
+ ret = imap_grabroom(roomname, parms[2]);
+ if (ret != 0) {
+ cprintf("%s NO Invalid mailbox name, or access denied\r\n",
+ parms[0]);
+ return;
+ }
+
+ /*
+ * usergoto() formally takes us to the desired room, happily returning
+ * the number of messages and number of new messages. (If another
+ * folder is selected, save its name so we can return there!!!!!)
+ */
+ if (IMAP->selected) {
+ strcpy(savedroom, CC->quickroom.QRname);
+ }
+ usergoto(roomname, 0, &msgs, &new);
+
+ /*
+ * Now delete the room.
+ */
+ if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom)) {
+ cprintf("%s OK DELETE completed\r\n", parms[0]);
+ delete_room(&CC->quickroom);
+ }
+ else {
+ cprintf("%s NO Can't delete this folder.\r\n", parms[0]);
+ }
+
+ /*
+ * If another folder is selected, go back to that room so we can resume
+ * our happy day without violent explosions.
+ */
+ if (IMAP->selected) {
+ usergoto(savedroom, 0, &msgs, &new);
+ }
+}
+
+
+
/*
* Main command loop for IMAP sessions.
imap_create(num_parms, parms);
}
+ else if (!strcasecmp(parms[1], "DELETE")) {
+ imap_delete(num_parms, parms);
+ }
+
else if (!strcasecmp(parms[1], "STATUS")) {
imap_status(num_parms, parms);
}