Back to index

citadel  8.12
ctdl_module.h
Go to the documentation of this file.
00001 
00002 #ifndef CTDL_MODULE_H
00003 #define CTDL_MODULE_H
00004 
00005 #include "sysdep.h"
00006 
00007 #ifdef HAVE_GC
00008 #define GC_THREADS
00009 #define GC_REDIRECT_TO_LOCAL
00010 #include <gc/gc_local_alloc.h>
00011 #else
00012 #define GC_MALLOC malloc
00013 #define GC_MALLOC_ATOMIC malloc
00014 #define GC_FREE free
00015 #define GC_REALLOC realloc
00016 #endif
00017 
00018 
00019 #include <stdlib.h>
00020 #include <unistd.h>
00021 #include <stdio.h>
00022 #include <fcntl.h>
00023 #include <ctype.h>
00024 #include <signal.h>
00025 #include <pwd.h>
00026 #include <errno.h>
00027 #include <syslog.h>
00028 #include <sys/types.h>
00029 
00030 #if TIME_WITH_SYS_TIME
00031 # include <sys/time.h>
00032 # include <time.h>
00033 #else
00034 # if HAVE_SYS_TIME_H
00035 #  include <sys/time.h>
00036 # else
00037 #  include <time.h>
00038 # endif
00039 #endif
00040 
00041 #include <sys/wait.h>
00042 #include <string.h>
00043 #ifdef HAVE_STRINGS_H
00044 #include <strings.h>
00045 #endif
00046 #include <limits.h>
00047 
00048 
00049 #ifndef HAVE_SNPRINTF
00050 #include "snprintf.h"
00051 #endif
00052 
00053 
00054 #include <libcitadel.h>
00055 
00056 #include "server.h"
00057 #include "sysdep_decls.h"
00058 #include "msgbase.h"
00059 #include "threads.h"
00060 #include "citadel_dirs.h"
00061 #include "context.h"
00062 
00063 /*
00064  * define macros for module init stuff
00065  */
00066  
00067 #define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
00068 
00069 #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
00070 
00071 #define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
00072 
00073 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
00074 
00075 #define CtdlAideMessage(TEXT, SUBJECT) quickie_message("Citadel",NULL,NULL,AIDEROOM,TEXT,FMT_CITADEL,SUBJECT) 
00076 /*
00077  * Hook functions available to modules.
00078  */
00079 /* Priorities for  */
00080 #define PRIO_QUEUE 500
00081 #define PRIO_AGGR 1000
00082 #define PRIO_SEND 1500
00083 #define PRIO_CLEANUP 2000
00084 /* Priorities for EVT_HOUSE */
00085 #define PRIO_HOUSE 3000
00086 /* Priorities for EVT_LOGIN */
00087 #define PRIO_CREATE 10000
00088 /* Priorities for EVT_LOGOUT */
00089 #define PRIO_LOGOUT 15000
00090 /* Priorities for EVT_LOGIN */
00091 #define PRIO_LOGIN 20000
00092 /* Priorities for EVT_START */
00093 #define PRIO_START 25000
00094 /* Priorities for EVT_STOP */
00095 #define PRIO_STOP 30000
00096 /* Priorities for EVT_ASYNC */
00097 #define PRIO_ASYNC 35000
00098 /* Priorities for EVT_SHUTDOWN */
00099 #define PRIO_SHUTDOWN 40000
00100 /* Priorities for EVT_UNSTEALTH */
00101 #define PRIO_UNSTEALTH 45000
00102 /* Priorities for EVT_STEALTH */
00103 #define PRIO_STEALTH 50000
00104 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
00105 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
00106 void CtdlShutdownServiceHooks(void);
00107 
00108 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
00109 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
00110 
00111 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
00112 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
00113 
00114 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
00115                                                  int EventType);
00116 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
00117                                                  int EventType);
00118 
00119 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
00120 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
00121 
00122 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
00123 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
00124 
00125 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
00126 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
00127 
00128 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
00129 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
00130 
00131 void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
00132 void CtdlUnregisterEVCleanupHook(void (*fcn_ptr)(void));
00133 
00134 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
00135 
00136 void CtdlRegisterServiceHook(int tcp_port,
00137                           char *sockpath,
00138                           void (*h_greeting_function) (void),
00139                           void (*h_command_function) (void),
00140                           void (*h_async_function) (void),
00141                           const char *ServiceName
00142 );
00143 void CtdlUnregisterServiceHook(int tcp_port,
00144                      char *sockpath,
00145                         void (*h_greeting_function) (void),
00146                         void (*h_command_function) (void),
00147                         void (*h_async_function) (void)
00148 );
00149 
00150 void CtdlRegisterFixedOutputHook(char *content_type,
00151                      void (*output_function) (char *supplied_data, int len)
00152 );
00153 void CtdlUnRegisterFixedOutputHook(char *content_type);
00154 
00155 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
00156 
00157 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name);
00158 
00159 
00160 /*
00161  * Directory services hooks for LDAP etc
00162  */
00163 
00164 #define DIRECTORY_USER_DEL 1       // Delete a user entry
00165 #define DIRECTORY_CREATE_HOST 2    // Create a host entry if not already there.
00166 #define DIRECTORY_CREATE_OBJECT 3  // Create a new object for directory entry
00167 #define DIRECTORY_ATTRIB_ADD 4     // Add an attribute to the directory entry object
00168 #define DIRECTORY_SAVE_OBJECT 5    // Save the object to the directory service
00169 #define DIRECTORY_FREE_OBJECT 6    // Free the object and its attributes
00170 
00171 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
00172 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
00173 
00174 /* TODODRW: This needs to be changed into a hook type interface
00175  * for now we have this horrible hack
00176  */
00177 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
00178 
00179 /* return the current context list as an array and do it in a safe manner
00180  * The returned data is a copy so only reading is useful
00181  * The number of contexts is returned in count.
00182  * Beware, this does not copy any of the data pointed to by the context.
00183  * This means that you can not rely on things like the redirect buffer being valid.
00184  * You must free the returned pointer when done.
00185  */
00186 struct CitContext *CtdlGetContextArray (int *count);
00187 void CtdlFillSystemContext(struct CitContext *context, char *name);
00188 int CtdlTrySingleUser(void);
00189 void CtdlEndSingleUser(void);
00190 int CtdlWantSingleUser(void);
00191 int CtdlIsSingleUser(void);
00192 
00193 
00194 int CtdlIsUserLoggedIn (char *user_name);
00195 int CtdlIsUserLoggedInByNum (long usernum);
00196 void CtdlBumpNewMailCounter(long which_user);
00197 
00198 
00199 /*
00200  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
00201  * This provides a quick way to initialise a variable that might be used to indicate
00202  * messages that should not be processed. EG. a new Sieve script will use this
00203  * to record determine that messages older than this should not be processed.
00204  * This function is defined in control.c
00205  */
00206 long CtdlGetCurrentMessageNumber(void);
00207 
00208 
00209 
00210 /*
00211  * Expose various room operation functions from room_ops.c to the modules API
00212  */
00213 
00214 unsigned CtdlCreateRoom(char *new_room_name,
00215                      int new_room_type,
00216                      char *new_room_pass,
00217                      int new_room_floor,
00218                      int really_create,
00219                      int avoid_access,
00220                      int new_room_view);
00221 int CtdlGetRoom(struct ctdlroom *qrbuf, char *room_name);
00222 int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name);
00223 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
00224 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
00225               int *result, int *view);
00226 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
00227 void CtdlForEachRoom(void (*CallBack)(struct ctdlroom *EachRoom, void *out_data),
00228        void *in_data);
00229 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
00230 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
00231 void CtdlUserGoto (char *where, int display_result, int transiently,
00232                      int *msgs, int *new);
00233 struct floor *CtdlGetCachedFloor(int floor_num);
00234 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
00235 void CtdlGetFloor (struct floor *flbuf, int floor_num);
00236 void CtdlPutFloor (struct floor *flbuf, int floor_num);
00237 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
00238 int CtdlGetFloorByName(const char *floor_name);
00239 int CtdlGetFloorByNameLock(const char *floor_name);
00240 int CtdlGetAvailableFloor(void);
00241 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
00242 void CtdlPutRoom(struct ctdlroom *);
00243 
00244 /*
00245  * Possible return values for CtdlRenameRoom()
00246  */
00247 enum {
00248        crr_ok,                            /* success */
00249        crr_room_not_found,         /* room not found */
00250        crr_already_exists,         /* new name already exists */
00251        crr_noneditable,            /* cannot edit this room */
00252        crr_invalid_floor,          /* target floor does not exist */
00253        crr_access_denied           /* not allowed to edit this room */
00254 };
00255 
00256 
00257 
00258 /*
00259  * API declarations from citserver.h
00260  */
00261 int CtdlAccessCheck(int);
00262 /* 'required access level' values which may be passed to CtdlAccessCheck()
00263  */
00264 enum {
00265        ac_none,
00266        ac_logged_in_or_guest,
00267        ac_logged_in,
00268        ac_room_aide,
00269        ac_aide,
00270        ac_internal,
00271 };
00272 
00273 
00274 
00275 /*
00276  * API declarations from serv_extensions.h
00277  */
00278 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name);
00279 
00280 /* 
00281  * Global system configuration
00282  */
00283 struct config {
00284        char c_nodename[16];        /* short name of this node on a Citadel network */
00285        char c_fqdn[64];            /* this site's fully qualified domain name */
00286        char c_humannode[21];              /* human-readable site name */
00287        char c_phonenum[16];        /* telephone number */
00288        uid_t c_ctdluid;            /* uid of posix account under which Citadel will run */
00289        char c_creataide;           /* 1 = creating a room auto-grants room aide privileges */
00290        int c_sleeping;                    /* watchdog timer (seconds) */
00291        char c_initax;                     /* initial access level for new users */
00292        char c_regiscall;           /* after c_regiscall logins user will be asked to register */
00293        char c_twitdetect;          /* automatically move messages from problem users to trashcan */
00294        char c_twitroom[ROOMNAMELEN];      /* name of trashcan */
00295        char c_moreprompt[80];             /* paginator prompt */
00296        char c_restrict;            /* require per-user permission to send Internet mail */
00297        long c_niu_1;
00298        char c_site_location[32];   /* geographic location of this Citadel site */
00299        char c_sysadm[26];          /* name of system administrator */
00300        char c_niu_2[15];
00301        int c_niu_3;
00302        int c_maxsessions;          /* maximum number of concurrent sessions allowed */
00303        char c_ip_addr[20];         /* bind address for listening sockets */
00304        int c_port_number;          /* port number for Citadel protocol (usually 504) */
00305        int c_niu_4;
00306        struct ExpirePolicy c_ep;   /* default expire policy for the entire site */
00307        int c_userpurge;            /* user purge time (in days) */
00308        int c_roompurge;            /* room purge time (in days) */
00309        char c_logpages[ROOMNAMELEN];
00310        char c_createax;
00311        long c_maxmsglen;
00312        int c_min_workers;
00313        int c_max_workers;
00314        int c_pop3_port;
00315        int c_smtp_port;
00316        int c_rfc822_strict_from;
00317        int c_aide_zap;
00318        int c_imap_port;
00319        time_t c_net_freq;
00320        char c_disable_newu;
00321        char c_enable_fulltext;
00322        char c_baseroom[ROOMNAMELEN];
00323        char c_aideroom[ROOMNAMELEN];
00324        int c_purge_hour;
00325        struct ExpirePolicy c_mbxep;
00326        char c_ldap_host[128];
00327        int c_ldap_port;
00328        char c_ldap_base_dn[256];
00329        char c_ldap_bind_dn[256];
00330        char c_ldap_bind_pw[256];
00331        int c_msa_port;
00332        int c_imaps_port;
00333        int c_pop3s_port;
00334        int c_smtps_port;
00335        char c_auto_cull;
00336        char c_instant_expunge;
00337        char c_allow_spoofing;
00338        char c_journal_email;
00339        char c_journal_pubmsgs;
00340        char c_journal_dest[128];
00341        char c_default_cal_zone[128];
00342        int c_pftcpdict_port;
00343        int c_managesieve_port;
00344        int c_auth_mode;
00345        char c_funambol_host[256];
00346        int c_funambol_port;
00347        char c_funambol_source[256];
00348        char c_funambol_auth[256];
00349        char c_rbl_at_greeting;
00350        char c_master_user[32];
00351        char c_master_pass[32];
00352        char c_pager_program[256];
00353        char c_imap_keep_from;
00354        int c_xmpp_c2s_port;
00355        int c_xmpp_s2s_port;
00356        time_t c_pop3_fetch;
00357        time_t c_pop3_fastest;
00358        int c_spam_flag_only;
00359        int c_guest_logins;
00360 };
00361 
00362 extern struct config config;
00363 
00364 
00365 
00366 /*
00367  * Expose API calls from user_ops.c
00368  */
00369 int CtdlGetUser(struct ctdluser *usbuf, char *name);
00370 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
00371 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
00372 void CtdlPutUser(struct ctdluser *usbuf);
00373 void CtdlPutUserLock(struct ctdluser *usbuf);
00374 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
00375 void CtdlGetRelationship(visit *vbuf,
00376                         struct ctdluser *rel_user,
00377                         struct ctdlroom *rel_room);
00378 void CtdlSetRelationship(visit *newvisit,
00379                         struct ctdluser *rel_user,
00380                         struct ctdlroom *rel_room);
00381 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
00382 
00383 int CtdlLoginExistingUser(char *authname, const char *username);
00384 
00385 /*
00386  * Values which may be returned by CtdlLoginExistingUser()
00387  */
00388 enum {
00389        pass_ok,
00390        pass_already_logged_in,
00391        pass_no_user,
00392        pass_internal_error,
00393        pass_wrong_password
00394 };
00395 
00396 int CtdlTryPassword(const char *password, long len);
00397 /*
00398  * Values which may be returned by CtdlTryPassword()
00399  */
00400 enum {
00401        login_ok,
00402        login_already_logged_in,
00403        login_too_many_users,
00404        login_not_found
00405 };
00406 
00407 void CtdlUserLogout(void);
00408 
00409 
00410 
00411 
00412 /*
00413  * Expose API calls from msgbase.c
00414  */
00415 char *CtdlGetSysConfig(char *sysconfname);
00416 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata);
00417 
00418 
00419 
00420 
00421 /*
00422  * Expose API calls from euidindex.c
00423  */
00424 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
00425 
00426 
00427 #endif /* CTDL_MODULE_H */