2 * A server-side module for Citadel designed to filter idiots off the network.
4 * Copyright (c) 2002-2009 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/types.h>
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
36 # include <sys/time.h>
45 #include <libcitadel.h>
48 #include "citserver.h"
57 #include "ctdl_module.h"
59 typedef struct FilterList FilterList;
68 struct FilterList *filterlist = NULL;
71 * Keep track of what messages to reject
73 FilterList *load_filter_list(void) {
74 char *serialized_list = NULL;
77 FilterList *newlist = NULL;
80 serialized_list = CtdlGetSysConfig(FILTERLIST);
81 if (serialized_list == NULL) return(NULL); /* if null, no entries */
83 /* Use the string tokenizer to grab one line at a time */
84 for (i=0; i<num_tokens(serialized_list, '\n'); ++i) {
85 extract_token(buf, serialized_list, i, '\n', sizeof buf);
86 nptr = (FilterList *) malloc(sizeof(FilterList));
87 extract_token(nptr->fl_user, buf, 0, '|', sizeof nptr->fl_user);
88 striplt(nptr->fl_user);
89 extract_token(nptr->fl_room, buf, 1, '|', sizeof nptr->fl_room);
90 striplt(nptr->fl_room);
91 extract_token(nptr->fl_node, buf, 2, '|', sizeof nptr->fl_node);
92 striplt(nptr->fl_node);
94 /* Cowardly refuse to add an any/any/any entry that would
95 * end up filtering every single message.
97 if (IsEmptyStr(nptr->fl_user) &&
98 IsEmptyStr(nptr->fl_room) &&
99 IsEmptyStr(nptr->fl_node)) {
103 nptr->next = newlist;
108 free(serialized_list);
113 void free_filter_list(FilterList *fl) {
114 if (fl == NULL) return;
115 free_filter_list(fl->next);
119 void free_netfilter_list(void)
121 free_filter_list(filterlist);
125 void load_network_filter_list(void)
127 filterlist = load_filter_list();
132 * This handler detects whether an incoming network message is from some
133 * moron user who the site operator has elected to filter out. If a match
134 * is found, the message is rejected.
136 int filter_the_idiots(struct CtdlMessage *msg, char *target_room) {
142 if ( (msg == NULL) || (filterlist == NULL) ) {
146 for (fptr = filterlist; fptr != NULL; fptr = fptr->next) {
152 if (msg->cm_fields['A'] != NULL) {
153 if ( (!strcasecmp(msg->cm_fields['A'], fptr->fl_user))
154 || (fptr->fl_user[0] == 0) ) {
159 if (msg->cm_fields['C'] != NULL) {
160 if ( (!strcasecmp(msg->cm_fields['C'], fptr->fl_room))
161 || (fptr->fl_room[0] == 0) ) {
166 if (msg->cm_fields['O'] != NULL) {
167 if ( (!strcasecmp(msg->cm_fields['O'], fptr->fl_room))
168 || (fptr->fl_room[0] == 0) ) {
173 if (msg->cm_fields['N'] != NULL) {
174 if ( (!strcasecmp(msg->cm_fields['N'], fptr->fl_node))
175 || (fptr->fl_node[0] == 0) ) {
180 if (zap_user + zap_room + zap_node == 3) return(1);
188 CTDL_MODULE_INIT(netfilter)
192 CtdlRegisterNetprocHook(filter_the_idiots);
195 /* return our module name for the log */