]> code.citadel.org Git - citadel.git/blob - citadel/imap_acl.c
* ACL extension - GETACL and MYRIGHTS share output code
[citadel.git] / citadel / imap_acl.c
1 /*
2  * $Id:  $
3  *
4  * Functions which implement RFC2086/RFC4314 (IMAP ACL extension)
5  *
6  */
7
8
9 #include "sysdep.h"
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <sys/types.h>
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #include <sys/wait.h>
31 #include <ctype.h>
32 #include <string.h>
33 #include <limits.h>
34 #include "citadel.h"
35 #include "server.h"
36 #include "sysdep_decls.h"
37 #include "citserver.h"
38 #include "support.h"
39 #include "config.h"
40 #include "serv_extensions.h"
41 #include "room_ops.h"
42 #include "user_ops.h"
43 #include "policy.h"
44 #include "database.h"
45 #include "msgbase.h"
46 #include "tools.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"
52 #include "genstamp.h"
53
54
55
56 /*
57  * Implements the SETACL command.
58  */
59 void imap_setacl(int num_parms, char *parms[]) {
60
61         cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
62         return;
63 }
64
65
66 /*
67  * Implements the DELETEACL command.
68  */
69 void imap_deleteacl(int num_parms, char *parms[]) {
70
71         cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
72         return;
73 }
74
75
76 /*
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.
79  */
80 void imap_acl_flags(char *rights, int ra)
81 {
82         strcpy(rights, "");
83
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
89          */
90         if (    (ra & UA_KNOWN)                                 /* known rooms */
91            ||   ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED))     /* zapped rooms */
92            ) {
93                 strcat(rights, "l");
94                 strcat(rights, "r");
95                 strcat(rights, "s");
96                 strcat(rights, "e");
97
98                 /* Only output the remaining flags if the room is known */
99
100                 /* w - write (set or clear arbitrary flags; not supported in Citadel) */
101
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) {
105                         strcat(rights, "i");
106                         strcat(rights, "p");
107                 }
108
109                 /* k - create mailboxes in this hierarchy */
110
111                 /* t - delete messages (set/clear \Deleted flag) */
112
113                 /* a - administer (perform SETACL/DELETEACL/GETACL/LISTRIGHTS) */
114                 /* x - delete mailbox (DELETE mailbox, old mailbox name in RENAME) */
115                 if (ra & UA_ADMINALLOWED) {
116                         strcat(rights, "a");
117                         strcat(rights, "x");
118                 }
119         }
120 }
121
122
123 /*
124  * Implements the GETACL command.
125  */
126 void imap_getacl(int num_parms, char *parms[]) {
127         char roomname[ROOMNAMELEN];
128         char savedroom[ROOMNAMELEN];
129         int msgs, new;
130         int ret;
131         struct ctdluser temp;
132         struct cdbdata *cdbus;
133         int ra;
134         char rights[32];
135
136         if (num_parms != 3) {
137                 cprintf("%s BAD usage error\r\n", parms[0]);
138                 return;
139         }
140
141         ret = imap_grabroom(roomname, parms[2], 0);
142         if (ret != 0) {
143                 cprintf("%s NO Invalid mailbox name or access denied\r\n",
144                         parms[0]);
145                 return;
146         }
147
148         /*
149          * usergoto() formally takes us to the desired room.  (If another
150          * folder is selected, save its name so we can return there!!!!!)
151          */
152         if (IMAP->selected) {
153                 strcpy(savedroom, CC->room.QRname);
154         }
155         usergoto(roomname, 0, 0, &msgs, &new);
156
157         cprintf("* ACL");
158         cprintf(" ");
159         imap_strout(parms[2]);
160
161         /*
162          * Traverse the userlist
163          */
164         cdb_rewind(CDB_USERS);
165         while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
166                 memset(&temp, 0, sizeof temp);
167                 memcpy(&temp, cdbus->ptr, sizeof temp);
168                 cdb_free(cdbus);
169
170                 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
171                 if (strlen(temp.fullname) > 0) {
172                         imap_acl_flags(rights, ra);
173                         if (strlen(rights) > 0) {
174                                 cprintf(" ");
175                                 imap_strout(temp.fullname);
176                                 cprintf(" %s", rights);
177                         }
178                 }
179         }
180
181         cprintf("\r\n");
182
183         /*
184          * If another folder is selected, go back to that room so we can resume
185          * our happy day without violent explosions.
186          */
187         if (IMAP->selected) {
188                 usergoto(savedroom, 0, 0, &msgs, &new);
189         }
190
191         cprintf("%s OK GETACL completed\r\n", parms[0]);
192 }
193
194
195 /*
196  * Implements the LISTRIGHTS command.
197  */
198 void imap_listrights(int num_parms, char *parms[]) {
199
200         cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
201         return;
202 }
203
204
205 /*
206  * Implements the MYRIGHTS command.
207  */
208 void imap_myrights(int num_parms, char *parms[]) {
209         char roomname[ROOMNAMELEN];
210         char savedroom[ROOMNAMELEN];
211         int msgs, new;
212         int ret;
213         int ra;
214         char rights[32];
215
216         if (num_parms != 3) {
217                 cprintf("%s BAD usage error\r\n", parms[0]);
218                 return;
219         }
220
221         ret = imap_grabroom(roomname, parms[2], 0);
222         if (ret != 0) {
223                 cprintf("%s NO Invalid mailbox name or access denied\r\n",
224                         parms[0]);
225                 return;
226         }
227
228         /*
229          * usergoto() formally takes us to the desired room.  (If another
230          * folder is selected, save its name so we can return there!!!!!)
231          */
232         if (IMAP->selected) {
233                 strcpy(savedroom, CC->room.QRname);
234         }
235         usergoto(roomname, 0, 0, &msgs, &new);
236
237         cprintf("* MYRIGHTS ");
238         imap_strout(parms[2]);
239         cprintf(" ");
240
241         CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
242         imap_acl_flags(rights, ra);
243         imap_strout(rights);
244
245         cprintf("\r\n");
246
247         /*
248          * If another folder is selected, go back to that room so we can resume
249          * our happy day without violent explosions.
250          */
251         if (IMAP->selected) {
252                 usergoto(savedroom, 0, 0, &msgs, &new);
253         }
254
255         cprintf("%s OK MYRIGHTS completed\r\n", parms[0]);
256         return;
257 }
258
259