* IMAP DELETE command ... also split up access control for room delete cmds
authorArt Cancro <ajc@citadel.org>
Sun, 11 Mar 2001 19:23:32 +0000 (19:23 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 11 Mar 2001 19:23:32 +0000 (19:23 +0000)
citadel/ChangeLog
citadel/room_ops.c
citadel/room_ops.h
citadel/serv_imap.c

index d88a4734f67a55c5185a1f545fb3753b128afad8..2887d21b23756d3e03ebd1234385f780e3290371 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 6c819c2a080a7e4a8b35710c864d51d4ecc0eeba..c13b8d830e31753fc7b080a450af491dda362b97 100644 (file)
@@ -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) {
index a3aca8918ffff151afeb028d0a20ee75cf44abdf..5adab90c45325ddf9478e4b86cd3185ff8fda5ea 100644 (file)
@@ -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);
index 46f87601226ffcd5e2df18b47133c22dd0761c14..e19f07cdff0f9e7b774f8b441b448ec444511a5d 100644 (file)
@@ -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);
        }