]> code.citadel.org Git - citadel.git/blob - citadel/imap_acl.c
* CtdlCheckRoomAccess() now sets a new bit UA_ADMINALLOWED
[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 /*
78  * Implements the GETACL command.
79  */
80 void imap_getacl(int num_parms, char *parms[]) {
81         char roomname[ROOMNAMELEN];
82         char savedroom[ROOMNAMELEN];
83         int msgs, new;
84         int ret;
85         struct ctdluser temp;
86         struct cdbdata *cdbus;
87         int ra;
88         char rights[32];
89
90         if (num_parms != 3) {
91                 cprintf("%s BAD usage error\r\n", parms[0]);
92                 return;
93         }
94
95         ret = imap_grabroom(roomname, parms[2], 0);
96         if (ret != 0) {
97                 cprintf("%s NO Invalid mailbox name or access denied\r\n",
98                         parms[0]);
99                 return;
100         }
101
102         /*
103          * usergoto() formally takes us to the desired room.  (If another
104          * folder is selected, save its name so we can return there!!!!!)
105          */
106         if (IMAP->selected) {
107                 strcpy(savedroom, CC->room.QRname);
108         }
109         usergoto(roomname, 0, 0, &msgs, &new);
110
111         cprintf("* ACL");
112         cprintf(" ");
113         imap_strout(parms[2]);
114
115         /*
116          * Traverse the userlist
117          */
118         cdb_rewind(CDB_USERS);
119         while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
120                 memset(&temp, 0, sizeof temp);
121                 memcpy(&temp, cdbus->ptr, sizeof temp);
122                 cdb_free(cdbus);
123
124                 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
125                 if (strlen(temp.fullname) > 0) {
126                         strcpy(rights, "");
127
128                         /* l - lookup (mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox)
129                          * r - read (SELECT the mailbox, perform STATUS)
130                          * s - keep seen/unseen information across sessions (set or clear \SEEN flag
131                          *     via STORE, also set \SEEN during APPEND/COPY/ FETCH BODY[...])
132                          * e - perform EXPUNGE and expunge as a part of CLOSE
133                          */
134                         if (    (ra & UA_KNOWN)                                 /* known rooms */
135                            ||   ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED))     /* zapped rooms */
136                            ) {
137                                 strcat(rights, "l");
138                                 strcat(rights, "r");
139                                 strcat(rights, "s");
140                                 strcat(rights, "e");
141
142                                 /* Only output the remaining flags if the room is known */
143
144                                 /* w - write (set or clear arbitrary flags; not supported in Citadel) */
145         
146                                 /* i - insert (perform APPEND, COPY into mailbox) */
147                                 /* p - post (send mail to submission address for mailbox - not enforced) */
148                                 if (ra & UA_POSTALLOWED) {
149                                         strcat(rights, "i");
150                                         strcat(rights, "p");
151                                 }
152         
153                                 /* k - create mailboxes in this hierarchy */
154         
155                                 /* t - delete messages (set/clear \Deleted flag) */
156
157                                 /* a - administer (perform SETACL/DELETEACL/GETACL/LISTRIGHTS) */
158                                 /* x - delete mailbox (DELETE mailbox, old mailbox name in RENAME) */
159                                 if (ra & UA_ADMINALLOWED) {
160                                         strcat(rights, "a");
161                                         strcat(rights, "x");
162                                 }
163                         }
164
165                         if (strlen(rights) > 0) {
166                                 cprintf(" ");
167                                 imap_strout(temp.fullname);
168                                 cprintf(" %s", rights);
169                         }
170                 }
171         }
172
173         cprintf("\r\n");
174
175         /*
176          * If another folder is selected, go back to that room so we can resume
177          * our happy day without violent explosions.
178          */
179         if (IMAP->selected) {
180                 usergoto(savedroom, 0, 0, &msgs, &new);
181         }
182
183         cprintf("%s OK GETACL completed\r\n", parms[0]);
184 }
185
186
187 /*
188  * Implements the LISTRIGHTS command.
189  */
190 void imap_listrights(int num_parms, char *parms[]) {
191
192         cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
193         return;
194 }
195
196
197 /*
198  * Implements the MYRIGHTS command.
199  */
200 void imap_myrights(int num_parms, char *parms[]) {
201
202         cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
203         return;
204 }
205
206