Add aide message functionality that uses the UT table to protect the user from an...
[citadel.git] / citadel / include / ctdl_module.h
1
2 #ifndef CTDL_MODULE_H
3 #define CTDL_MODULE_H
4
5 #include "sysdep.h"
6
7 #ifdef HAVE_GC
8 #define GC_THREADS
9 #define GC_REDIRECT_TO_LOCAL
10 #include <gc/gc_local_alloc.h>
11 #else
12 #define GC_MALLOC malloc
13 #define GC_MALLOC_ATOMIC malloc
14 #define GC_FREE free
15 #define GC_REALLOC realloc
16 #endif
17
18
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <ctype.h>
24 #include <signal.h>
25 #include <pwd.h>
26 #include <errno.h>
27 #include <syslog.h>
28 #include <sys/types.h>
29
30 #if TIME_WITH_SYS_TIME
31 # include <sys/time.h>
32 # include <time.h>
33 #else
34 # if HAVE_SYS_TIME_H
35 #  include <sys/time.h>
36 # else
37 #  include <time.h>
38 # endif
39 #endif
40
41 #include <sys/wait.h>
42 #include <string.h>
43 #ifdef HAVE_STRINGS_H
44 #include <strings.h>
45 #endif
46 #include <limits.h>
47
48
49 #ifndef HAVE_SNPRINTF
50 #include "snprintf.h"
51 #endif
52
53
54 #include <libcitadel.h>
55
56 #include "server.h"
57 #include "sysdep_decls.h"
58 #include "msgbase.h"
59 #include "threads.h"
60 #include "citadel_dirs.h"
61 #include "context.h"
62
63 /*
64  * define macros for module init stuff
65  */
66  
67 #define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
68
69 #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
70
71 #define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
72
73 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
74
75 #define CtdlAideMessage(TEXT, SUBJECT)          \
76         quickie_message(                        \
77                 "Citadel",                      \
78                 NULL,                           \
79                 NULL,                           \
80                 AIDEROOM,                       \
81                 TEXT,                           \
82                 FMT_CITADEL,                    \
83                 SUBJECT) 
84
85
86 #define CtdlAideFPMessage(TEXT, SUBJECT, N, STR, STRLEN) \
87         flood_protect_quickie_message(                   \
88                 "Citadel",                               \
89                 NULL,                                    \
90                 NULL,                                    \
91                 AIDEROOM,                                \
92                 TEXT,                                    \
93                 FMT_CITADEL,                             \
94                 SUBJECT,                                 \
95                 N,                                       \
96                 STR,                                     \
97                 STRLEN)
98 /*
99  * Hook functions available to modules.
100  */
101 /* Priorities for  */
102 #define PRIO_QUEUE 500
103 #define PRIO_AGGR 1000
104 #define PRIO_SEND 1500
105 #define PRIO_CLEANUP 2000
106 /* Priorities for EVT_HOUSE */
107 #define PRIO_HOUSE 3000
108 /* Priorities for EVT_LOGIN */
109 #define PRIO_CREATE 10000
110 /* Priorities for EVT_LOGOUT */
111 #define PRIO_LOGOUT 15000
112 /* Priorities for EVT_LOGIN */
113 #define PRIO_LOGIN 20000
114 /* Priorities for EVT_START */
115 #define PRIO_START 25000
116 /* Priorities for EVT_STOP */
117 #define PRIO_STOP 30000
118 /* Priorities for EVT_ASYNC */
119 #define PRIO_ASYNC 35000
120 /* Priorities for EVT_SHUTDOWN */
121 #define PRIO_SHUTDOWN 40000
122 /* Priorities for EVT_UNSTEALTH */
123 #define PRIO_UNSTEALTH 45000
124 /* Priorities for EVT_STEALTH */
125 #define PRIO_STEALTH 50000
126 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
127 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
128 void CtdlShutdownServiceHooks(void);
129
130 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
131 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
132
133 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
134 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
135
136 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
137                                                         int EventType);
138 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
139                                                         int EventType);
140
141 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
142 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
143
144 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
145 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
146
147 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
148 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
149
150 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
151 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
152
153 void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
154 void CtdlUnregisterEVCleanupHook(void (*fcn_ptr)(void));
155
156 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
157
158 void CtdlRegisterServiceHook(int tcp_port,
159                              char *sockpath,
160                              void (*h_greeting_function) (void),
161                              void (*h_command_function) (void),
162                              void (*h_async_function) (void),
163                              const char *ServiceName
164 );
165 void CtdlUnregisterServiceHook(int tcp_port,
166                         char *sockpath,
167                         void (*h_greeting_function) (void),
168                         void (*h_command_function) (void),
169                         void (*h_async_function) (void)
170 );
171
172 void CtdlRegisterFixedOutputHook(char *content_type,
173                         void (*output_function) (char *supplied_data, int len)
174 );
175 void CtdlUnRegisterFixedOutputHook(char *content_type);
176
177 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
178
179 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name);
180
181
182 /*
183  * Directory services hooks for LDAP etc
184  */
185
186 #define DIRECTORY_USER_DEL 1    // Delete a user entry
187 #define DIRECTORY_CREATE_HOST 2 // Create a host entry if not already there.
188 #define DIRECTORY_CREATE_OBJECT 3       // Create a new object for directory entry
189 #define DIRECTORY_ATTRIB_ADD 4  // Add an attribute to the directory entry object
190 #define DIRECTORY_SAVE_OBJECT 5 // Save the object to the directory service
191 #define DIRECTORY_FREE_OBJECT 6 // Free the object and its attributes
192
193 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
194 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
195
196 /* TODODRW: This needs to be changed into a hook type interface
197  * for now we have this horrible hack
198  */
199 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
200
201 /* return the current context list as an array and do it in a safe manner
202  * The returned data is a copy so only reading is useful
203  * The number of contexts is returned in count.
204  * Beware, this does not copy any of the data pointed to by the context.
205  * This means that you can not rely on things like the redirect buffer being valid.
206  * You must free the returned pointer when done.
207  */
208 struct CitContext *CtdlGetContextArray (int *count);
209 void CtdlFillSystemContext(struct CitContext *context, char *name);
210 int CtdlTrySingleUser(void);
211 void CtdlEndSingleUser(void);
212 int CtdlWantSingleUser(void);
213 int CtdlIsSingleUser(void);
214
215
216 int CtdlIsUserLoggedIn (char *user_name);
217 int CtdlIsUserLoggedInByNum (long usernum);
218 void CtdlBumpNewMailCounter(long which_user);
219
220
221 /*
222  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
223  * This provides a quick way to initialise a variable that might be used to indicate
224  * messages that should not be processed. EG. a new Sieve script will use this
225  * to record determine that messages older than this should not be processed.
226  * This function is defined in control.c
227  */
228 long CtdlGetCurrentMessageNumber(void);
229
230
231
232 /*
233  * Expose various room operation functions from room_ops.c to the modules API
234  */
235
236 unsigned CtdlCreateRoom(char *new_room_name,
237                         int new_room_type,
238                         char *new_room_pass,
239                         int new_room_floor,
240                         int really_create,
241                         int avoid_access,
242                         int new_room_view);
243 int CtdlGetRoom(struct ctdlroom *qrbuf, char *room_name);
244 int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name);
245 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
246 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
247                 int *result, int *view);
248 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
249 void CtdlForEachRoom(void (*CallBack)(struct ctdlroom *EachRoom, void *out_data),
250         void *in_data);
251 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
252 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
253 void CtdlUserGoto (char *where, int display_result, int transiently,
254                         int *msgs, int *new);
255 struct floor *CtdlGetCachedFloor(int floor_num);
256 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
257 void CtdlGetFloor (struct floor *flbuf, int floor_num);
258 void CtdlPutFloor (struct floor *flbuf, int floor_num);
259 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
260 int CtdlGetFloorByName(const char *floor_name);
261 int CtdlGetFloorByNameLock(const char *floor_name);
262 int CtdlGetAvailableFloor(void);
263 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
264 void CtdlPutRoom(struct ctdlroom *);
265
266 /*
267  * Possible return values for CtdlRenameRoom()
268  */
269 enum {
270         crr_ok,                         /* success */
271         crr_room_not_found,             /* room not found */
272         crr_already_exists,             /* new name already exists */
273         crr_noneditable,                /* cannot edit this room */
274         crr_invalid_floor,              /* target floor does not exist */
275         crr_access_denied               /* not allowed to edit this room */
276 };
277
278
279
280 /*
281  * API declarations from citserver.h
282  */
283 int CtdlAccessCheck(int);
284 /* 'required access level' values which may be passed to CtdlAccessCheck()
285  */
286 enum {
287         ac_none,
288         ac_logged_in_or_guest,
289         ac_logged_in,
290         ac_room_aide,
291         ac_aide,
292         ac_internal,
293 };
294
295
296
297 /*
298  * API declarations from serv_extensions.h
299  */
300 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name);
301
302 /* 
303  * Global system configuration
304  */
305 struct config {
306         char c_nodename[16];            /* short name of this node on a Citadel network */
307         char c_fqdn[64];                /* this site's fully qualified domain name */
308         char c_humannode[21];           /* human-readable site name */
309         char c_phonenum[16];            /* telephone number */
310         uid_t c_ctdluid;                /* uid of posix account under which Citadel will run */
311         char c_creataide;               /* 1 = creating a room auto-grants room aide privileges */
312         int c_sleeping;                 /* watchdog timer (seconds) */
313         char c_initax;                  /* initial access level for new users */
314         char c_regiscall;               /* after c_regiscall logins user will be asked to register */
315         char c_twitdetect;              /* automatically move messages from problem users to trashcan */
316         char c_twitroom[ROOMNAMELEN];   /* name of trashcan */
317         char c_moreprompt[80];          /* paginator prompt */
318         char c_restrict;                /* require per-user permission to send Internet mail */
319         long c_niu_1;
320         char c_site_location[32];       /* geographic location of this Citadel site */
321         char c_sysadm[26];              /* name of system administrator */
322         char c_niu_2[15];
323         int c_niu_3;
324         int c_maxsessions;              /* maximum number of concurrent sessions allowed */
325         char c_ip_addr[20];             /* bind address for listening sockets */
326         int c_port_number;              /* port number for Citadel protocol (usually 504) */
327         int c_niu_4;
328         struct ExpirePolicy c_ep;       /* default expire policy for the entire site */
329         int c_userpurge;                /* user purge time (in days) */
330         int c_roompurge;                /* room purge time (in days) */
331         char c_logpages[ROOMNAMELEN];
332         char c_createax;
333         long c_maxmsglen;
334         int c_min_workers;
335         int c_max_workers;
336         int c_pop3_port;
337         int c_smtp_port;
338         int c_rfc822_strict_from;
339         int c_aide_zap;
340         int c_imap_port;
341         time_t c_net_freq;
342         char c_disable_newu;
343         char c_enable_fulltext;
344         char c_baseroom[ROOMNAMELEN];
345         char c_aideroom[ROOMNAMELEN];
346         int c_purge_hour;
347         struct ExpirePolicy c_mbxep;
348         char c_ldap_host[128];
349         int c_ldap_port;
350         char c_ldap_base_dn[256];
351         char c_ldap_bind_dn[256];
352         char c_ldap_bind_pw[256];
353         int c_msa_port;
354         int c_imaps_port;
355         int c_pop3s_port;
356         int c_smtps_port;
357         char c_auto_cull;
358         char c_instant_expunge;
359         char c_allow_spoofing;
360         char c_journal_email;
361         char c_journal_pubmsgs;
362         char c_journal_dest[128];
363         char c_default_cal_zone[128];
364         int c_pftcpdict_port;
365         int c_managesieve_port;
366         int c_auth_mode;
367         char c_funambol_host[256];
368         int c_funambol_port;
369         char c_funambol_source[256];
370         char c_funambol_auth[256];
371         char c_rbl_at_greeting;
372         char c_master_user[32];
373         char c_master_pass[32];
374         char c_pager_program[256];
375         char c_imap_keep_from;
376         int c_xmpp_c2s_port;
377         int c_xmpp_s2s_port;
378         time_t c_pop3_fetch;
379         time_t c_pop3_fastest;
380         int c_spam_flag_only;
381         int c_guest_logins;
382 };
383
384 extern struct config config;
385
386
387
388 /*
389  * Expose API calls from user_ops.c
390  */
391 int CtdlGetUser(struct ctdluser *usbuf, char *name);
392 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
393 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
394 void CtdlPutUser(struct ctdluser *usbuf);
395 void CtdlPutUserLock(struct ctdluser *usbuf);
396 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
397 void CtdlGetRelationship(visit *vbuf,
398                         struct ctdluser *rel_user,
399                         struct ctdlroom *rel_room);
400 void CtdlSetRelationship(visit *newvisit,
401                         struct ctdluser *rel_user,
402                         struct ctdlroom *rel_room);
403 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
404
405 int CtdlLoginExistingUser(char *authname, const char *username);
406
407 /*
408  * Values which may be returned by CtdlLoginExistingUser()
409  */
410 enum {
411         pass_ok,
412         pass_already_logged_in,
413         pass_no_user,
414         pass_internal_error,
415         pass_wrong_password
416 };
417
418 int CtdlTryPassword(const char *password, long len);
419 /*
420  * Values which may be returned by CtdlTryPassword()
421  */
422 enum {
423         login_ok,
424         login_already_logged_in,
425         login_too_many_users,
426         login_not_found
427 };
428
429 void CtdlUserLogout(void);
430
431
432
433
434 /*
435  * Expose API calls from msgbase.c
436  */
437 char *CtdlGetSysConfig(char *sysconfname);
438 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata);
439
440
441
442
443 /*
444  * Expose API calls from euidindex.c
445  */
446 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
447
448
449 #endif /* CTDL_MODULE_H */