X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fserv_extensions.c;h=6197d2880563869a7d5dce70dd2f2ef5aa0affa3;hb=882ff5a53c3b4e440520a073cf07dc60b2671876;hp=897f43c1b74cef4e9f59e675f383c2aa95f71ca5;hpb=ba6d504ceb294a13362371f578c22cb7161f1dc9;p=citadel.git diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index 897f43c1b..6197d2880 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -1,8 +1,8 @@ /* * Citadel Extension Loader - * Written by Brian Costello + * Originally written by Brian Costello * - * Copyright (c) 1987-2017 by the citadel.org team + * Copyright (c) 1987-2021 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 3. @@ -13,36 +13,22 @@ * GNU General Public License for more details. */ +#include +#include #include +#include #include - #include "sysdep_decls.h" #include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */ - #include "serv_extensions.h" #include "ctdl_module.h" #include "config.h" -int DebugModules = 0; -int EnableMarkers = 0; -int EnableCtlProto = 0; - /* * Structure defentitions for hook tables */ -HashList *LogDebugEntryTable = NULL; - -typedef struct LogFunctionHook LogFunctionHook; -struct LogFunctionHook { - LogFunctionHook *next; - int loglevel; - void (*h_function_pointer) (char *); -}; - -LogFunctionHook *LogHookTable = NULL; - typedef struct FixedOutputHook FixedOutputHook; struct FixedOutputHook { FixedOutputHook *next; @@ -52,10 +38,6 @@ struct FixedOutputHook { FixedOutputHook *FixedOutputTable = NULL; - - - - /* * SessionFunctionHook extensions are used for any type of hook for which * the context in which it's being called (which is determined by the event @@ -71,6 +53,7 @@ struct SessionFunctionHook { }; SessionFunctionHook *SessionHookTable = NULL; + /* * UserFunctionHook extensions are used for any type of hook which implements * an operation on a user or username (potentially) other than the one @@ -84,6 +67,7 @@ struct UserFunctionHook { }; UserFunctionHook *UserHookTable = NULL; + /* * MessageFunctionHook extensions are used for hooks which implement handlers * for various types of message operations (save, read, etc.) @@ -91,24 +75,12 @@ UserFunctionHook *UserHookTable = NULL; typedef struct MessageFunctionHook MessageFunctionHook; struct MessageFunctionHook { MessageFunctionHook *next; - int (*h_function_pointer) (struct CtdlMessage *msg, recptypes *recps); + int (*h_function_pointer) (struct CtdlMessage *msg, struct recptypes *recps); int eventtype; }; MessageFunctionHook *MessageHookTable = NULL; -/* - * NetprocFunctionHook extensions are used for hooks which implement handlers - * for incoming network messages. - */ -typedef struct NetprocFunctionHook NetprocFunctionHook; -struct NetprocFunctionHook { - NetprocFunctionHook *next; - int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room); -}; -NetprocFunctionHook *NetprocHookTable = NULL; - - /* * DeleteFunctionHook extensions are used for hooks which get called when a * message is about to be deleted. @@ -136,11 +108,9 @@ struct XmsgFunctionHook { XmsgFunctionHook *XmsgHookTable = NULL; - - /* * RoomFunctionHook extensions are used for hooks which impliment room - * processing functions when new messages are added EG. SIEVE. + * processing functions when new messages are added. */ typedef struct RoomFunctionHook RoomFunctionHook; struct RoomFunctionHook { @@ -150,7 +120,6 @@ struct RoomFunctionHook { RoomFunctionHook *RoomHookTable = NULL; - typedef struct SearchFunctionHook SearchFunctionHook; struct SearchFunctionHook { SearchFunctionHook *next; @@ -159,9 +128,6 @@ struct SearchFunctionHook { }; SearchFunctionHook *SearchFunctionHookTable = NULL; -CleanupFunctionHook *CleanupHookTable = NULL; -CleanupFunctionHook *EVCleanupHookTable = NULL; - ServiceFunctionHook *ServiceHookTable = NULL; typedef struct ProtoFunctionHook ProtoFunctionHook; @@ -178,7 +144,6 @@ HashList *ProtoHookList = NULL; static StrBuf *portlist = NULL; - static StrBuf *errormessages = NULL; @@ -187,21 +152,19 @@ ConstStr Empty = {HKEY("")}; char *ErrSubject = "Startup Problems"; ConstStr ErrGeneral[] = { {HKEY("Citadel had trouble on starting up. ")}, - {HKEY(" This means, citadel won't be the service provider for a specific service you configured it to.\n\n" - "If you don't want citadel to provide these services, turn them off in WebCit via: ")}, + {HKEY(" This means, Citadel won't be the service provider for a specific service you configured it to.\n\n" + "If you don't want Citadel to provide these services, turn them off in WebCit via: ")}, {HKEY("To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n" "The errors returned by the system were:\n")}, {HKEY("You can recheck the above if you follow this faq item:\n" "http://www.citadel.org/doku.php?id=faq:mastering_your_os:net#netstat")} }; -ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be provided by citadel server.\n")}; +ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be provided by Citadel Server.\n")}; ConstStr ErrPortWhere = { HKEY("\"Admin->System Preferences->Network\".\n\nThe failed ports and sockets are: ")}; -ConstStr ErrPortHint = { HKEY("If you want citadel to provide you with that functionality, " - "check the output of \"netstat -lnp\" on linux Servers or \"netstat -na\" on *BSD" - " and stop the program that binds these ports.\n You should eventually remove " - " their initscripts in /etc/init.d so that you won't get this trouble once more.\n" - " After that goto \"Administration -> Shutdown Citadel\" to make Citadel restart & retry to bind this port.\n")}; +ConstStr ErrPortHint = { HKEY("If you want Citadel to provide you with that functionality, " + "check the output of \"netstat -lnp\" on Linux, or \"netstat -na\" on BSD" + " and disable the program that binds these ports.\n")}; void LogPrintMessages(long err) @@ -211,8 +174,7 @@ void LogPrintMessages(long err) ConstStr *Short, *Where, *Hint; - Message = NewStrBufPlain(NULL, - StrLength(portlist) + StrLength(errormessages)); + Message = NewStrBufPlain(NULL, StrLength(portlist) + StrLength(errormessages)); DetailErrorFlags = DetailErrorFlags & ~err; @@ -246,8 +208,8 @@ void LogPrintMessages(long err) StrBufAppendBufPlain(Message, HKEY("\n\n"), 0); StrBufAppendBufPlain(Message, CKEY(ErrGeneral[3]), 0); - syslog(LOG_EMERG, "extensions: %s", ChrPtr(Message)); - syslog(LOG_EMERG, "extensions: %s", ErrSubject); + syslog(LOG_ERR, "extensions: %s", ChrPtr(Message)); + syslog(LOG_ERR, "extensions: %s", ErrSubject); quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(Message), FMT_FIXED, ErrSubject); FreeStrBuf(&Message); @@ -288,70 +250,6 @@ int DLoader_Exec_Cmd(char *cmdbuf) return 0; } -void CtdlRegisterDebugFlagHook(const char *Name, long Len, CtdlDbgFunction F, const int *LogP) -{ - LogDebugEntry *E; - if (LogDebugEntryTable == NULL) - LogDebugEntryTable = NewHash(1, NULL); - E = (LogDebugEntry*) malloc(sizeof(LogDebugEntry)); - E->F = F; - E->Name = Name; - E->Len = Len; - E->LogP = LogP; - Put(LogDebugEntryTable, Name, Len, E, NULL); - -} -void CtdlSetDebugLogFacilities(const char **Str, long n) -{ - StrBuf *Token = NULL; - StrBuf *Buf = NULL; - const char *ch; - int i; - int DoAll = 0; - void *vptr; - - for (i=0; i < n; i++){ - if ((Str[i] != NULL) && !IsEmptyStr(Str[i])) { - if (strcmp(Str[i], "all") == 0) { - DoAll = 1; - continue; - } - Buf = NewStrBufPlain(Str[i], -1); - ch = NULL; - if (Token == NULL) - Token = NewStrBufPlain(NULL, StrLength(Buf)); - while ((ch != StrBufNOTNULL) && - StrBufExtract_NextToken(Token, Buf, &ch, ',')) { - if (GetHash(LogDebugEntryTable, SKEY(Token), &vptr) && - (vptr != NULL)) - { - LogDebugEntry *E = (LogDebugEntry*)vptr; - E->F(1); - } - } - } - FreeStrBuf(&Buf); - } - FreeStrBuf(&Token); - if (DoAll) { - long HKLen; - const char *ch; - HashPos *Pos; - - Pos = GetNewHashPos(LogDebugEntryTable, 0); - while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) { - LogDebugEntry *E = (LogDebugEntry*)vptr; - E->F(1); - } - - DeleteHashPos(&Pos); - } -} -void CtdlDestroyDebugTable(void) -{ - - DeleteHash(&LogDebugEntryTable); -} void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc) { @@ -376,134 +274,6 @@ void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc) syslog(LOG_DEBUG, "extensions: registered server command %s (%s)", cmd, desc); } -void CtdlDestroyProtoHooks(void) -{ - - DeleteHash(&ProtoHookList); -} - - -void CtdlRegisterCleanupHook(void (*fcn_ptr) (void)) -{ - - CleanupFunctionHook *newfcn; - - newfcn = (CleanupFunctionHook *) - malloc(sizeof(CleanupFunctionHook)); - newfcn->next = CleanupHookTable; - newfcn->h_function_pointer = fcn_ptr; - CleanupHookTable = newfcn; - - syslog(LOG_DEBUG, "extensions: registered a new cleanup function"); -} - - -void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void)) -{ - CleanupFunctionHook *cur, *p, *last; - last = NULL; - cur = CleanupHookTable; - while (cur != NULL) - { - if (fcn_ptr == cur->h_function_pointer) - { - syslog(LOG_DEBUG, "extensions: unregistered cleanup function"); - p = cur->next; - - free(cur); - cur = NULL; - - if (last != NULL) - last->next = p; - else - CleanupHookTable = p; - cur = p; - } - else { - last = cur; - cur = cur->next; - } - } -} - - -void CtdlDestroyCleanupHooks(void) -{ - CleanupFunctionHook *cur, *p; - - cur = CleanupHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed cleanup function"); - p = cur->next; - free(cur); - cur = p; - } - CleanupHookTable = NULL; -} - -void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void)) -{ - - CleanupFunctionHook *newfcn; - - newfcn = (CleanupFunctionHook *) - malloc(sizeof(CleanupFunctionHook)); - newfcn->next = EVCleanupHookTable; - newfcn->h_function_pointer = fcn_ptr; - EVCleanupHookTable = newfcn; - - syslog(LOG_DEBUG, "extensions: registered a new cleanup function"); -} - - -void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void)) -{ - CleanupFunctionHook *cur, *p, *last; - last = NULL; - cur = EVCleanupHookTable; - while (cur != NULL) - { - if (fcn_ptr == cur->h_function_pointer) - { - syslog(LOG_DEBUG, "extensions: unregistered cleanup function"); - p = cur->next; - - free(cur); - cur = NULL; - - if (last != NULL) - last->next = p; - else - EVCleanupHookTable = p; - cur = p; - } - else { - last = cur; - cur = cur->next; - } - } -} - - -void CtdlDestroyEVCleanupHooks(void) -{ - CleanupFunctionHook *cur, *p; - - cur = EVCleanupHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed cleanup function"); - p = cur->next; - cur->h_function_pointer(); - free(cur); - cur = p; - } - EVCleanupHookTable = NULL; -} - - - void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority) { @@ -557,21 +327,6 @@ void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType) } } -void CtdlDestroySessionHooks(void) -{ - SessionFunctionHook *cur, *p; - - cur = SessionHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed session function"); - p = cur->next; - free(cur); - cur = p; - } - SessionHookTable = NULL; -} - void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType) { @@ -618,24 +373,8 @@ void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType) } } -void CtdlDestroyUserHooks(void) -{ - UserFunctionHook *cur, *p; - - cur = UserHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed user function"); - p = cur->next; - free(cur); - cur = p; - } - UserHookTable = NULL; -} - -void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), - int EventType) +void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType) { MessageFunctionHook *newfcn; @@ -651,8 +390,7 @@ void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), } -void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), - int EventType) +void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType) { MessageFunctionHook *cur, *p, *last; last = NULL; @@ -679,21 +417,6 @@ void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *) } } -void CtdlDestroyMessageHook(void) -{ - MessageFunctionHook *cur, *p; - - cur = MessageHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed message function (type %d)", cur->eventtype); - p = cur->next; - free(cur); - cur = p; - } - MessageHookTable = NULL; -} - void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) { @@ -737,79 +460,6 @@ void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) } -void CtdlDestroyRoomHooks(void) -{ - RoomFunctionHook *cur, *p; - - cur = RoomHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed room function"); - p = cur->next; - free(cur); - cur = p; - } - RoomHookTable = NULL; -} - -void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) ) -{ - NetprocFunctionHook *newfcn; - - newfcn = (NetprocFunctionHook *) - malloc(sizeof(NetprocFunctionHook)); - newfcn->next = NetprocHookTable; - newfcn->h_function_pointer = handler; - NetprocHookTable = newfcn; - - syslog(LOG_DEBUG, "extensions: registered a new netproc function"); -} - - -void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) ) -{ - NetprocFunctionHook *cur, *p, *last; - - cur = NetprocHookTable; - last = NULL; - - while (cur != NULL) { - if (handler == cur->h_function_pointer) - { - syslog(LOG_DEBUG, "extensions: unregistered netproc function"); - p = cur->next; - free(cur); - if (last != NULL) { - last->next = p; - } - else { - NetprocHookTable = p; - } - cur = p; - } - else { - last = cur; - cur = cur->next; - } - } -} - -void CtdlDestroyNetprocHooks(void) -{ - NetprocFunctionHook *cur, *p; - - cur = NetprocHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed netproc function"); - p = cur->next; - free(cur); - cur = p; - } - NetprocHookTable = NULL; -} - - void CtdlRegisterDeleteHook(void (*handler)(char *, long) ) { DeleteFunctionHook *newfcn; @@ -852,22 +502,6 @@ void CtdlUnregisterDeleteHook(void (*handler)(char *, long) ) } -void CtdlDestroyDeleteHooks(void) -{ - DeleteFunctionHook *cur, *p; - - cur = DeleteHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed delete function"); - p = cur->next; - free(cur); - cur = p; - } - DeleteHookTable = NULL; -} - - void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) ) { FixedOutputHook *newfcn; @@ -911,21 +545,6 @@ void CtdlUnregisterFixedOutputHook(char *content_type) } } -void CtdlDestroyFixedOutputHooks(void) -{ - FixedOutputHook *cur, *p; - - cur = FixedOutputTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed fixed output function for %s", cur->content_type); - p = cur->next; - free(cur); - cur = p; - - } - FixedOutputTable = NULL; -} /* returns nonzero if we found a hook and used it */ int PerformFixedOutputHooks(char *content_type, char *content, int content_length) @@ -986,22 +605,6 @@ void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int } -void CtdlDestroyXmsgHooks(void) -{ - XmsgFunctionHook *cur, *p; - - cur = XmsgHookTable; - while (cur != NULL) - { - syslog(LOG_DEBUG, "extensions: destroyed x-msg function (priority %d)", cur->order); - p = cur->next; - free(cur); - cur = p; - } - XmsgHookTable = NULL; -} - - void CtdlRegisterServiceHook(int tcp_port, char *sockpath, void (*h_greeting_function) (void), @@ -1011,9 +614,7 @@ void CtdlRegisterServiceHook(int tcp_port, { ServiceFunctionHook *newfcn; char *message; - char error[SIZ]; - strcpy(error, ""); newfcn = (ServiceFunctionHook *) malloc(sizeof(ServiceFunctionHook)); message = (char*) malloc (SIZ + SIZ); @@ -1026,7 +627,7 @@ void CtdlRegisterServiceHook(int tcp_port, newfcn->ServiceName = ServiceName; if (sockpath != NULL) { - newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"), error); + newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions")); snprintf(message, SIZ, "extensions: unix domain socket '%s': ", sockpath); } else if (tcp_port <= 0) { /* port -1 to disable */ @@ -1036,10 +637,7 @@ void CtdlRegisterServiceHook(int tcp_port, return; } else { - newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"), - tcp_port, - CtdlGetConfigInt("c_maxsessions"), - error); + newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"), tcp_port, CtdlGetConfigInt("c_maxsessions")); snprintf(message, SIZ, "extensions: TCP port %s:%d: (%s) ", CtdlGetConfigStr("c_ip_addr"), tcp_port, ServiceName); } @@ -1050,7 +648,7 @@ void CtdlRegisterServiceHook(int tcp_port, syslog(LOG_INFO, "%s", message); } else { - AddPortError(message, error); + AddPortError(message, "failed"); strcat(message, "FAILED."); syslog(LOG_ERR, "%s", message); free(newfcn); @@ -1127,39 +725,6 @@ void CtdlShutdownServiceHooks(void) } -void CtdlDestroyServiceHook(void) -{ - const char *Text; - ServiceFunctionHook *cur, *p; - - cur = ServiceHookTable; - while (cur != NULL) - { - if (cur->msock != -1) - { - close(cur->msock); - Text = "Closed"; - } - else - { - Text = " Not closing again"; - } - - if (cur->sockpath) { - syslog(LOG_INFO, "extensions: %s UNIX domain socket %s", Text, cur->sockpath); - unlink(cur->sockpath); - } else if (cur->tcp_port) { - syslog(LOG_INFO, "extensions: %s TCP port %d", Text, cur->tcp_port); - } else { - syslog(LOG_INFO, "extensions: destroyed service \"%s\"", cur->ServiceName); - } - p = cur->next; - free(cur); - cur = p; - } - ServiceHookTable = NULL; -} - void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name) { SearchFunctionHook *newfcn; @@ -1205,18 +770,6 @@ void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), } } -void CtdlDestroySearchHooks(void) -{ - SearchFunctionHook *cur, *p; - - cur = SearchFunctionHookTable; - SearchFunctionHookTable = NULL; - while (cur != NULL) { - p = cur->next; - free(cur); - cur = p; - } -} void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name) { @@ -1257,7 +810,7 @@ void PerformUserHooks(ctdluser *usbuf, int EventType) } } -int PerformMessageHooks(struct CtdlMessage *msg, recptypes *recps, int EventType) +int PerformMessageHooks(struct CtdlMessage *msg, struct recptypes *recps, int EventType) { MessageFunctionHook *fcn = NULL; int total_retval = 0; @@ -1302,23 +855,6 @@ int PerformRoomHooks(struct ctdlroom *target_room) } -int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room) -{ - NetprocFunctionHook *fcn; - int total_retval = 0; - - for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) { - total_retval = total_retval + - (*fcn->h_function_pointer) (msg, target_room); - } - - /* Return the sum of the return codes from the hook functions. - * A nonzero return code will cause the message to *not* be imported. - */ - return total_retval; -} - - void PerformDeleteHooks(char *room, long msgnum) { DeleteFunctionHook *fcn; @@ -1329,9 +865,6 @@ void PerformDeleteHooks(char *room, long msgnum) } - - - int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg) { XmsgFunctionHook *fcn; @@ -1367,25 +900,10 @@ void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *er #endif } -void DebugModulesEnable(const int n) -{ - DebugModules = n; -} -void MarkersEnable(const int n) -{ - EnableMarkers = n; -} -void DebugCitadelProtoEnable(const int n) -{ - EnableCtlProto = n; -} CTDL_MODULE_INIT(modules) { if (!threading) { - CtdlRegisterDebugFlagHook(HKEY("modules"), DebugModulesEnable, &DebugModules); - CtdlRegisterDebugFlagHook(HKEY("periodicmarkers"), MarkersEnable, &EnableMarkers); - CtdlRegisterDebugFlagHook(HKEY("citadelprotocol"), DebugCitadelProtoEnable, &EnableCtlProto); } return "modules"; }