From: Wilfried Goesgens Date: Thu, 8 Sep 2011 12:35:51 +0000 (+0000) Subject: Networker reordering; remove / change dependencies X-Git-Tag: v8.11~475 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=8b276ba2d09c1d606b6b282961c737b6b4e26d21 Networker reordering; remove / change dependencies - move serv_network.h into modules/network where it belongs... - move structs out of serv_network.h into their respective headers - serv_expire doesn't need serv_network.h anymore, it seems to get the usetable struct from elsewhere - the netfilter module was moved to the network directory, it seems to be closely dangled to networking - move all code about the netfilter (config reading) into serv_netfilter.c - move the code networker related from msgbase.c:CtdlDoIHavePermissionToPostInThisRoom() into serv_netconfig.c:netconfig_check_roomaccess() - move the filterlist instance into serv_netfilter.c lesson learned the hard way today: if you move a header, flush the dependencies, else the make process will abort with no usefull message at all. -> Gentlemen please flush the dependencies and rebootstrap your workingcopy. --- diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index 815cdb7d2..d15670074 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -78,7 +78,6 @@ #include "msgbase.h" #include "user_ops.h" #include "control.h" -#include "serv_network.h" /* Needed for definition of UseTable */ #include "threads.h" #include "context.h" diff --git a/citadel/modules/netfilter/.gitignore b/citadel/modules/netfilter/.gitignore deleted file mode 100644 index 5761abcfd..000000000 --- a/citadel/modules/netfilter/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.o diff --git a/citadel/modules/netfilter/serv_netfilter.c b/citadel/modules/netfilter/serv_netfilter.c deleted file mode 100644 index a75576948..000000000 --- a/citadel/modules/netfilter/serv_netfilter.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * A server-side module for Citadel designed to filter idiots off the network. - * - * Copyright (c) 2002-2009 by the citadel.org team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "sysdep.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#include -#include -#include -#include -#include "citadel.h" -#include "server.h" -#include "citserver.h" -#include "support.h" -#include "config.h" -#include "control.h" -#include "user_ops.h" -#include "database.h" -#include "msgbase.h" -#include "serv_network.h" /* Needed for defenition of FilterList */ - - -#include "ctdl_module.h" - - -/* - * This handler detects whether an incoming network message is from some - * moron user who the site operator has elected to filter out. If a match - * is found, the message is rejected. - */ -int filter_the_idiots(struct CtdlMessage *msg, char *target_room) { - FilterList *fptr; - int zap_user = 0; - int zap_room = 0; - int zap_node = 0; - - if ( (msg == NULL) || (filterlist == NULL) ) { - return(0); - } - - for (fptr = filterlist; fptr != NULL; fptr = fptr->next) { - - zap_user = 0; - zap_room = 0; - zap_node = 0; - - if (msg->cm_fields['A'] != NULL) { - if ( (!strcasecmp(msg->cm_fields['A'], fptr->fl_user)) - || (fptr->fl_user[0] == 0) ) { - zap_user = 1; - } - } - - if (msg->cm_fields['C'] != NULL) { - if ( (!strcasecmp(msg->cm_fields['C'], fptr->fl_room)) - || (fptr->fl_room[0] == 0) ) { - zap_room = 1; - } - } - - if (msg->cm_fields['O'] != NULL) { - if ( (!strcasecmp(msg->cm_fields['O'], fptr->fl_room)) - || (fptr->fl_room[0] == 0) ) { - zap_room = 1; - } - } - - if (msg->cm_fields['N'] != NULL) { - if ( (!strcasecmp(msg->cm_fields['N'], fptr->fl_node)) - || (fptr->fl_node[0] == 0) ) { - zap_node = 1; - } - } - - if (zap_user + zap_room + zap_node == 3) return(1); - - } - - return(0); -} - - -CTDL_MODULE_INIT(netfilter) -{ - if (!threading) - { - CtdlRegisterNetprocHook(filter_the_idiots); - } - - /* return our module name for the log */ - return "netfilter"; -} diff --git a/citadel/modules/network/netconfig.h b/citadel/modules/network/netconfig.h index 0c959fd3f..4e1e26433 100644 --- a/citadel/modules/network/netconfig.h +++ b/citadel/modules/network/netconfig.h @@ -1,3 +1,12 @@ +typedef struct NetMap NetMap; + +struct NetMap { + NetMap *next; + char nodename[SIZ]; + time_t lastcontact; + char nexthop[SIZ]; +}; + NetMap *the_netmap; int netmap_changed; @@ -5,7 +14,5 @@ char *working_ignetcfg; void load_working_ignetcfg(void); void read_network_map(void); -FilterList *load_filter_list(void); void write_network_map(void); -void free_filter_list(FilterList *fl); int is_valid_node(char *nexthop, char *secret, char *node); diff --git a/citadel/modules/network/netspool.h b/citadel/modules/network/netspool.h index 4cfb410ad..e4c8c9fff 100644 --- a/citadel/modules/network/netspool.h +++ b/citadel/modules/network/netspool.h @@ -1,3 +1,30 @@ +typedef struct maplist maplist; + +struct maplist { + struct maplist *next; + char remote_nodename[SIZ]; + char remote_roomname[SIZ]; +}; + + +typedef struct SpoolControl SpoolControl; + +struct SpoolControl { + long lastsent; + namelist *listrecps; + namelist *digestrecps; + namelist *participates; + maplist *ignet_push_shares; + char *misc; + FILE *digestfp; + int num_msgs_spooled; +}; + + void network_spoolout_room(char *room_to_spool); void network_do_spoolin(void); void network_consolidate_spoolout(void); +void free_spoolcontrol_struct(SpoolControl **scc); +int writenfree_spoolcontrol_file(SpoolControl **scc, char *filename); +int read_spoolcontrol_file(SpoolControl **scc, char *filename); +int is_recipient(SpoolControl *sc, const char *Name); diff --git a/citadel/modules/network/serv_netconfig.c b/citadel/modules/network/serv_netconfig.c index 234a1fe5d..970057133 100644 --- a/citadel/modules/network/serv_netconfig.c +++ b/citadel/modules/network/serv_netconfig.c @@ -88,6 +88,7 @@ #include "context.h" #include "netconfig.h" +#include "netspool.h" #include "ctdl_module.h" @@ -185,56 +186,6 @@ void write_network_map(void) { } - -/* - * Keep track of what messages to reject - */ -FilterList *load_filter_list(void) { - char *serialized_list = NULL; - int i; - char buf[SIZ]; - FilterList *newlist = NULL; - FilterList *nptr; - - serialized_list = CtdlGetSysConfig(FILTERLIST); - if (serialized_list == NULL) return(NULL); /* if null, no entries */ - - /* Use the string tokenizer to grab one line at a time */ - for (i=0; ifl_user, buf, 0, '|', sizeof nptr->fl_user); - striplt(nptr->fl_user); - extract_token(nptr->fl_room, buf, 1, '|', sizeof nptr->fl_room); - striplt(nptr->fl_room); - extract_token(nptr->fl_node, buf, 2, '|', sizeof nptr->fl_node); - striplt(nptr->fl_node); - - /* Cowardly refuse to add an any/any/any entry that would - * end up filtering every single message. - */ - if (IsEmptyStr(nptr->fl_user) && - IsEmptyStr(nptr->fl_room) && - IsEmptyStr(nptr->fl_node)) { - free(nptr); - } - else { - nptr->next = newlist; - newlist = nptr; - } - } - - free(serialized_list); - return newlist; -} - - -void free_filter_list(FilterList *fl) { - if (fl == NULL) return; - free_filter_list(fl->next); - free(fl); -} - /* * Check the network map and determine whether the supplied node name is * valid. If it is not a neighbor node, supply the name of a neighbor node @@ -475,6 +426,42 @@ void cmd_netp(char *cmdbuf) cprintf("%d authenticated as network node '%s'\n", CIT_OK, CC->net_node); } +int netconfig_check_roomaccess( + char *errmsgbuf, + size_t n, + const char* RemoteIdentifier) +{ + SpoolControl *sc; + char filename[SIZ]; + int found; + + if (RemoteIdentifier == NULL) + { + snprintf(errmsgbuf, n, "Need sender to permit access."); + return (ERROR + USERNAME_REQUIRED); + } + + assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir); + begin_critical_section(S_NETCONFIGS); + if (!read_spoolcontrol_file(&sc, filename)) + { + end_critical_section(S_NETCONFIGS); + snprintf(errmsgbuf, n, + "This mailing list only accepts posts from subscribers."); + return (ERROR + NO_SUCH_USER); + } + end_critical_section(S_NETCONFIGS); + found = is_recipient (sc, RemoteIdentifier); + free_spoolcontrol_struct(&sc); + if (found) { + return (0); + } + else { + snprintf(errmsgbuf, n, + "This mailing list only accepts posts from subscribers."); + return (ERROR + NO_SUCH_USER); + } +} /* * Module entry point */ diff --git a/citadel/modules/network/serv_netfilter.c b/citadel/modules/network/serv_netfilter.c new file mode 100644 index 000000000..757e62b31 --- /dev/null +++ b/citadel/modules/network/serv_netfilter.c @@ -0,0 +1,197 @@ +/* + * A server-side module for Citadel designed to filter idiots off the network. + * + * Copyright (c) 2002-2009 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#include +#include +#include +#include +#include "citadel.h" +#include "server.h" +#include "citserver.h" +#include "support.h" +#include "config.h" +#include "control.h" +#include "user_ops.h" +#include "database.h" +#include "msgbase.h" + + +#include "ctdl_module.h" + +typedef struct FilterList FilterList; + +struct FilterList { + FilterList *next; + char fl_user[SIZ]; + char fl_room[SIZ]; + char fl_node[SIZ]; +}; + +struct FilterList *filterlist = NULL; + +/* + * Keep track of what messages to reject + */ +FilterList *load_filter_list(void) { + char *serialized_list = NULL; + int i; + char buf[SIZ]; + FilterList *newlist = NULL; + FilterList *nptr; + + serialized_list = CtdlGetSysConfig(FILTERLIST); + if (serialized_list == NULL) return(NULL); /* if null, no entries */ + + /* Use the string tokenizer to grab one line at a time */ + for (i=0; ifl_user, buf, 0, '|', sizeof nptr->fl_user); + striplt(nptr->fl_user); + extract_token(nptr->fl_room, buf, 1, '|', sizeof nptr->fl_room); + striplt(nptr->fl_room); + extract_token(nptr->fl_node, buf, 2, '|', sizeof nptr->fl_node); + striplt(nptr->fl_node); + + /* Cowardly refuse to add an any/any/any entry that would + * end up filtering every single message. + */ + if (IsEmptyStr(nptr->fl_user) && + IsEmptyStr(nptr->fl_room) && + IsEmptyStr(nptr->fl_node)) { + free(nptr); + } + else { + nptr->next = newlist; + newlist = nptr; + } + } + + free(serialized_list); + return newlist; +} + + +void free_filter_list(FilterList *fl) { + if (fl == NULL) return; + free_filter_list(fl->next); + free(fl); +} + +void free_netfilter_list(void) +{ + free_filter_list(filterlist); + filterlist = NULL; +} + +void load_network_filter_list(void) +{ + filterlist = load_filter_list(); +} + + +/* + * This handler detects whether an incoming network message is from some + * moron user who the site operator has elected to filter out. If a match + * is found, the message is rejected. + */ +int filter_the_idiots(struct CtdlMessage *msg, char *target_room) { + FilterList *fptr; + int zap_user = 0; + int zap_room = 0; + int zap_node = 0; + + if ( (msg == NULL) || (filterlist == NULL) ) { + return(0); + } + + for (fptr = filterlist; fptr != NULL; fptr = fptr->next) { + + zap_user = 0; + zap_room = 0; + zap_node = 0; + + if (msg->cm_fields['A'] != NULL) { + if ( (!strcasecmp(msg->cm_fields['A'], fptr->fl_user)) + || (fptr->fl_user[0] == 0) ) { + zap_user = 1; + } + } + + if (msg->cm_fields['C'] != NULL) { + if ( (!strcasecmp(msg->cm_fields['C'], fptr->fl_room)) + || (fptr->fl_room[0] == 0) ) { + zap_room = 1; + } + } + + if (msg->cm_fields['O'] != NULL) { + if ( (!strcasecmp(msg->cm_fields['O'], fptr->fl_room)) + || (fptr->fl_room[0] == 0) ) { + zap_room = 1; + } + } + + if (msg->cm_fields['N'] != NULL) { + if ( (!strcasecmp(msg->cm_fields['N'], fptr->fl_node)) + || (fptr->fl_node[0] == 0) ) { + zap_node = 1; + } + } + + if (zap_user + zap_room + zap_node == 3) return(1); + + } + + return(0); +} + + +CTDL_MODULE_INIT(netfilter) +{ + if (!threading) + { + CtdlRegisterNetprocHook(filter_the_idiots); + } + + /* return our module name for the log */ + return "netfilter"; +} diff --git a/citadel/modules/network/serv_netmail.c b/citadel/modules/network/serv_netmail.c index 6b7494bb7..e2b2f2183 100644 --- a/citadel/modules/network/serv_netmail.c +++ b/citadel/modules/network/serv_netmail.c @@ -88,6 +88,7 @@ #include "context.h" #include "netconfig.h" +#include "netspool.h" #include "ctdl_module.h" diff --git a/citadel/modules/network/serv_netspool.c b/citadel/modules/network/serv_netspool.c index 9538a6dbd..544bf1f04 100644 --- a/citadel/modules/network/serv_netspool.c +++ b/citadel/modules/network/serv_netspool.c @@ -88,6 +88,7 @@ #include "context.h" #include "netconfig.h" +#include "netspool.h" #include "netmail.h" #include "ctdl_module.h" diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 2b3d8fbca..bf5f1d3b9 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -88,6 +88,7 @@ #include "context.h" #include "netconfig.h" +#include "netspool.h" #include "netmail.h" #include "ctdl_module.h" @@ -105,7 +106,6 @@ struct RoomProcList *rplist = NULL; - /* * Check the use table. This is a list of messages which have recently * arrived on the system. It is maintained and queried to prevent the same @@ -446,12 +446,11 @@ void network_do_queue(void) { /* Load the IGnet Configuration into memory */ load_working_ignetcfg(); - /* * Load the network map and filter list into memory. */ read_network_map(); - filterlist = load_filter_list(); + load_network_filter_list(); /* * Go ahead and run the queue @@ -496,8 +495,7 @@ void network_do_queue(void) { write_network_map(); /* Free the filter list in memory */ - free_filter_list(filterlist); - filterlist = NULL; + free_netfilter_list(); network_consolidate_spoolout(); diff --git a/citadel/modules/network/serv_network.h b/citadel/modules/network/serv_network.h new file mode 100644 index 000000000..a855ca462 --- /dev/null +++ b/citadel/modules/network/serv_network.h @@ -0,0 +1,19 @@ + +typedef struct namelist namelist; + +struct namelist { + namelist *next; + char name[SIZ]; +}; + + +void free_netfilter_list(void); +void load_network_filter_list(void); + + + +void network_queue_room(struct ctdlroom *, void *); +void destroy_network_queue_room(void); +void network_bounce(struct CtdlMessage *msg, char *reason); +int network_usetable(struct CtdlMessage *msg); + diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 7eb321905..db65460a2 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -64,7 +64,6 @@ #include "journaling.h" #include "citadel_dirs.h" #include "clientsocket.h" -#include "serv_network.h" #include "threads.h" #include "ctdl_module.h" @@ -75,13 +74,6 @@ struct addresses_to_be_filed *atbf = NULL; /* This temp file holds the queue of operations for AdjRefCount() */ static FILE *arcfp = NULL; -/* - * This really belongs in serv_network.c, but I don't know how to export - * symbols between modules. - */ -struct FilterList *filterlist = NULL; - - /* * These are the four-character field headers we use when outputting * messages in Citadel format (as opposed to RFC822 format). @@ -3881,6 +3873,10 @@ struct CtdlMessage *CtdlMakeMessage( return(msg); } +extern int netconfig_check_roomaccess( + char *errmsgbuf, + size_t n, + const char* RemoteIdentifier); /* TODO: find a smarter way */ /* * Check to see whether we have permission to post a message in the current @@ -3915,36 +3911,8 @@ int CtdlDoIHavePermissionToPostInThisRoom( return (ERROR + NOT_LOGGED_IN); } if ((PostPublic!=POST_LMTP) &&(CC->room.QRflags2 & QR2_SMTP_PUBLIC) == 0) { - SpoolControl *sc; - char filename[SIZ]; - int found; - if (RemoteIdentifier == NULL) - { - snprintf(errmsgbuf, n, "Need sender to permit access."); - return (ERROR + USERNAME_REQUIRED); - } - - assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir); - begin_critical_section(S_NETCONFIGS); - if (!read_spoolcontrol_file(&sc, filename)) - { - end_critical_section(S_NETCONFIGS); - snprintf(errmsgbuf, n, - "This mailing list only accepts posts from subscribers."); - return (ERROR + NO_SUCH_USER); - } - end_critical_section(S_NETCONFIGS); - found = is_recipient (sc, RemoteIdentifier); - free_spoolcontrol_struct(&sc); - if (found) { - return (0); - } - else { - snprintf(errmsgbuf, n, - "This mailing list only accepts posts from subscribers."); - return (ERROR + NO_SUCH_USER); - } + return netconfig_check_roomaccess(errmsgbuf, n, RemoteIdentifier); } return (0); diff --git a/citadel/serv_network.h b/citadel/serv_network.h deleted file mode 100644 index fa3b63261..000000000 --- a/citadel/serv_network.h +++ /dev/null @@ -1,64 +0,0 @@ - -typedef struct namelist namelist; - -struct namelist { - namelist *next; - char name[SIZ]; -}; - -typedef struct maplist maplist; - -struct maplist { - struct maplist *next; - char remote_nodename[SIZ]; - char remote_roomname[SIZ]; -}; - -typedef struct SpoolControl SpoolControl; - -struct SpoolControl { - long lastsent; - namelist *listrecps; - namelist *digestrecps; - namelist *participates; - maplist *ignet_push_shares; - char *misc; - FILE *digestfp; - int num_msgs_spooled; -}; - - -typedef struct NetMap NetMap; - -struct NetMap { - NetMap *next; - char nodename[SIZ]; - time_t lastcontact; - char nexthop[SIZ]; -}; - -typedef struct FilterList FilterList; - -struct FilterList { - FilterList *next; - char fl_user[SIZ]; - char fl_room[SIZ]; - char fl_node[SIZ]; -}; -extern FilterList *filterlist; - -void free_spoolcontrol_struct(SpoolControl **scc); -int writenfree_spoolcontrol_file(SpoolControl **scc, char *filename); -int read_spoolcontrol_file(SpoolControl **scc, char *filename); - -int is_recipient(SpoolControl *sc, const char *Name); - - -void network_queue_room(struct ctdlroom *, void *); -void destroy_network_queue_room(void); -void network_bounce(struct CtdlMessage *msg, char *reason); -int network_usetable(struct CtdlMessage *msg); -void network_do_spoolin(void); -void network_consolidate_spoolout(void); -void network_spoolout_room(char *room_to_spool); -