4 * Functions which implement RFC2086/RFC4314 (IMAP ACL extension)
17 #include <sys/types.h>
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
36 #include "sysdep_decls.h"
37 #include "citserver.h"
40 #include "serv_extensions.h"
47 #include "internet_addressing.h"
48 #include "serv_imap.h"
49 #include "imap_tools.h"
50 #include "imap_fetch.h"
51 #include "imap_misc.h"
57 * Implements the SETACL command.
59 void imap_setacl(int num_parms, char *parms[]) {
61 cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
67 * Implements the DELETEACL command.
69 void imap_deleteacl(int num_parms, char *parms[]) {
71 cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
77 * Given the bits returned by CtdlRoomAccess(), populate a string buffer
78 * with IMAP ACL format flags. This code is common to GETACL and MYRIGHTS.
80 void imap_acl_flags(char *rights, int ra)
84 /* l - lookup (mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox)
85 * r - read (SELECT the mailbox, perform STATUS)
86 * s - keep seen/unseen information across sessions (set or clear \SEEN flag
87 * via STORE, also set \SEEN during APPEND/COPY/ FETCH BODY[...])
88 * e - perform EXPUNGE and expunge as a part of CLOSE
90 if ( (ra & UA_KNOWN) /* known rooms */
91 || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED)) /* zapped rooms */
98 /* Only output the remaining flags if the room is known */
100 /* w - write (set or clear arbitrary flags; not supported in Citadel) */
102 /* i - insert (perform APPEND, COPY into mailbox) */
103 /* p - post (send mail to submission address for mailbox - not enforced) */
104 if (ra & UA_POSTALLOWED) {
109 /* k - create mailboxes in this hierarchy */
111 /* t - delete messages (set/clear \Deleted flag) */
112 if (ra & UA_DELETEALLOWED) {
117 /* a - administer (perform SETACL/DELETEACL/GETACL/LISTRIGHTS) */
118 /* x - delete mailbox (DELETE mailbox, old mailbox name in RENAME) */
119 if (ra & UA_ADMINALLOWED) {
121 * This is the correct place to put the "a" flag. We are leaving
122 * it commented out for now, because it implies that we could
123 * perform any of SETACL/DELETEACL/GETACL/LISTRIGHTS. Since these
124 * commands are not yet implemented, omitting the flag should
125 * theoretically prevent compliant clients from attempting to
128 /* strcat(rights, "a"); * commented out */
136 * Implements the GETACL command.
138 void imap_getacl(int num_parms, char *parms[]) {
139 char roomname[ROOMNAMELEN];
140 char savedroom[ROOMNAMELEN];
143 struct ctdluser temp;
144 struct cdbdata *cdbus;
148 if (num_parms != 3) {
149 cprintf("%s BAD usage error\r\n", parms[0]);
154 * Search for the specified room or folder
156 ret = imap_grabroom(roomname, parms[2], 0);
158 cprintf("%s NO Invalid mailbox name or access denied\r\n",
164 * usergoto() formally takes us to the desired room. (If another
165 * folder is selected, save its name so we can return there!!!!!)
167 if (IMAP->selected) {
168 strcpy(savedroom, CC->room.QRname);
170 usergoto(roomname, 0, 0, &msgs, &new);
174 imap_strout(parms[2]);
177 * Traverse the userlist
179 cdb_rewind(CDB_USERS);
180 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
181 memset(&temp, 0, sizeof temp);
182 memcpy(&temp, cdbus->ptr, sizeof temp);
185 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
186 if (strlen(temp.fullname) > 0) {
187 imap_acl_flags(rights, ra);
188 if (strlen(rights) > 0) {
190 imap_strout(temp.fullname);
191 cprintf(" %s", rights);
199 * If another folder is selected, go back to that room so we can resume
200 * our happy day without violent explosions.
202 if (IMAP->selected) {
203 usergoto(savedroom, 0, 0, &msgs, &new);
206 cprintf("%s OK GETACL completed\r\n", parms[0]);
211 * Implements the LISTRIGHTS command.
213 void imap_listrights(int num_parms, char *parms[]) {
214 char roomname[ROOMNAMELEN];
215 char savedroom[ROOMNAMELEN];
218 struct recptypes *valid;
219 struct ctdluser temp;
221 if (num_parms != 4) {
222 cprintf("%s BAD usage error\r\n", parms[0]);
227 * Search for the specified room/folder
229 ret = imap_grabroom(roomname, parms[2], 0);
231 cprintf("%s NO Invalid mailbox name or access denied\r\n",
237 * Search for the specified user
240 valid = validate_recipients(parms[3]);
242 if (valid->num_local == 1) {
243 ret = getuser(&temp, valid->recp_local);
248 cprintf("%s NO Invalid user name or access denied\r\n",
254 * usergoto() formally takes us to the desired room. (If another
255 * folder is selected, save its name so we can return there!!!!!)
257 if (IMAP->selected) {
258 strcpy(savedroom, CC->room.QRname);
260 usergoto(roomname, 0, 0, &msgs, &new);
264 * Now output the list of rights
266 cprintf("* LISTRIGHTS ");
267 imap_strout(parms[2]);
269 imap_strout(parms[3]);
271 imap_strout(""); /* FIXME ... do something here */
276 * If another folder is selected, go back to that room so we can resume
277 * our happy day without violent explosions.
279 if (IMAP->selected) {
280 usergoto(savedroom, 0, 0, &msgs, &new);
283 cprintf("%s OK LISTRIGHTS completed\r\n", parms[0]);
289 * Implements the MYRIGHTS command.
291 void imap_myrights(int num_parms, char *parms[]) {
292 char roomname[ROOMNAMELEN];
293 char savedroom[ROOMNAMELEN];
299 if (num_parms != 3) {
300 cprintf("%s BAD usage error\r\n", parms[0]);
304 ret = imap_grabroom(roomname, parms[2], 0);
306 cprintf("%s NO Invalid mailbox name or access denied\r\n",
312 * usergoto() formally takes us to the desired room. (If another
313 * folder is selected, save its name so we can return there!!!!!)
315 if (IMAP->selected) {
316 strcpy(savedroom, CC->room.QRname);
318 usergoto(roomname, 0, 0, &msgs, &new);
320 CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
321 imap_acl_flags(rights, ra);
323 cprintf("* MYRIGHTS ");
324 imap_strout(parms[2]);
325 cprintf(" %s\r\n", rights);
328 * If a different folder was previously selected, return there now.
330 if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
331 usergoto(savedroom, 0, 0, &msgs, &new);
334 cprintf("%s OK MYRIGHTS completed\r\n", parms[0]);