From: Art Cancro Date: Sun, 11 Mar 2001 19:23:32 +0000 (+0000) Subject: * IMAP DELETE command ... also split up access control for room delete cmds X-Git-Tag: v7.86~6922 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=11eeb22a34e5be480ab43cc5d75f0c963527c179;p=citadel.git * IMAP DELETE command ... also split up access control for room delete cmds --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index d88a4734f..2887d21b2 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $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 @@ -2444,4 +2447,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 6c819c2a0..c13b8d830 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -1187,6 +1187,49 @@ void delete_room(struct quickroom *qrbuf) } + +/* + * 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 */ @@ -1198,10 +1241,8 @@ void cmd_kill(char *argbuf) 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) { diff --git a/citadel/room_ops.h b/citadel/room_ops.h index a3aca8918..5adab90c4 100644 --- a/citadel/room_ops.h +++ b/citadel/room_ops.h @@ -50,3 +50,4 @@ void delete_room(struct quickroom *qrbuf); 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); diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 46f876012..e19f07cdf 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -675,6 +675,55 @@ void imap_status(int num_parms, char *parms[]) { +/* + * 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. @@ -785,6 +834,10 @@ void imap_command_loop(void) { 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); }