2 * A server-side module for Citadel designed to filter idiots off the network.
4 * Copyright (c) 2002-2017 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
39 #include <libcitadel.h>
42 #include "citserver.h"
51 #include "ctdl_module.h"
53 typedef struct FilterList FilterList;
62 struct FilterList *filterlist = NULL;
65 * Keep track of what messages to reject
67 FilterList *load_filter_list(void) {
68 char *serialized_list = NULL;
71 FilterList *newlist = NULL;
74 serialized_list = CtdlGetSysConfig(FILTERLIST);
75 if (serialized_list == NULL) return(NULL); /* if null, no entries */
77 /* Use the string tokenizer to grab one line at a time */
78 for (i=0; i<num_tokens(serialized_list, '\n'); ++i) {
79 extract_token(buf, serialized_list, i, '\n', sizeof buf);
80 nptr = (FilterList *) malloc(sizeof(FilterList));
81 extract_token(nptr->fl_user, buf, 0, '|', sizeof nptr->fl_user);
82 striplt(nptr->fl_user);
83 extract_token(nptr->fl_room, buf, 1, '|', sizeof nptr->fl_room);
84 striplt(nptr->fl_room);
85 extract_token(nptr->fl_node, buf, 2, '|', sizeof nptr->fl_node);
86 striplt(nptr->fl_node);
88 /* Cowardly refuse to add an any/any/any entry that would
89 * end up filtering every single message.
91 if (IsEmptyStr(nptr->fl_user) &&
92 IsEmptyStr(nptr->fl_room) &&
93 IsEmptyStr(nptr->fl_node)) {
102 free(serialized_list);
107 void free_filter_list(FilterList *fl) {
108 if (fl == NULL) return;
109 free_filter_list(fl->next);
113 void free_netfilter_list(void)
115 free_filter_list(filterlist);
119 void load_network_filter_list(void)
121 filterlist = load_filter_list();
126 * This handler detects whether an incoming network message is from some
127 * moron user who the site operator has elected to filter out. If a match
128 * is found, the message is rejected.
130 int filter_the_idiots(struct CtdlMessage *msg, char *target_room) {
136 if ( (msg == NULL) || (filterlist == NULL) ) {
140 for (fptr = filterlist; fptr != NULL; fptr = fptr->next) {
146 if (!CM_IsEmpty(msg, eAuthor)) {
147 if ( (!strcasecmp(msg->cm_fields[eAuthor], fptr->fl_user))
148 || (fptr->fl_user[0] == 0) ) {
153 if (!CM_IsEmpty(msg, eRemoteRoom)) {
154 if ( (!strcasecmp(msg->cm_fields[eRemoteRoom], fptr->fl_room))
155 || (fptr->fl_room[0] == 0) ) {
160 if (!CM_IsEmpty(msg, eOriginalRoom)) {
161 if ( (!strcasecmp(msg->cm_fields[eOriginalRoom], fptr->fl_room))
162 || (fptr->fl_room[0] == 0) ) {
167 if (!CM_IsEmpty(msg, eNodeName)) {
168 if ( (!strcasecmp(msg->cm_fields[eNodeName], fptr->fl_node))
169 || (fptr->fl_node[0] == 0) ) {
174 if (zap_user + zap_room + zap_node == 3) return(1);
182 CTDL_MODULE_INIT(netfilter)
187 currently unsupported.
188 CtdlRegisterNetprocHook(filter_the_idiots);
192 /* return our module name for the log */