git-svn: trunk@2070
Nigel Horne authored on 2006/07/12 02:46:31... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Tue Jul 11 18:45:22 BST 2006 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamav-milter: Use tableUpdate() to maintain the blacklist |
|
4 |
+ |
|
1 | 5 |
Tue Jul 11 16:26:46 BST 2006 (njh) |
2 | 6 |
---------------------------------- |
3 | 7 |
* clamav-milter: Added -I flag based on an idea by |
... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
* |
24 | 24 |
* For installation instructions see the file INSTALL that came with this file |
25 | 25 |
*/ |
26 |
-static char const rcsid[] = "$Id: clamav-milter.c,v 1.248 2006/07/11 15:25:26 njh Exp $"; |
|
26 |
+static char const rcsid[] = "$Id: clamav-milter.c,v 1.249 2006/07/11 17:46:30 njh Exp $"; |
|
27 | 27 |
|
28 | 28 |
#define CM_VERSION "devel-210606" |
29 | 29 |
|
... | ... |
@@ -3390,11 +3390,7 @@ clamfi_eom(SMFICTX *ctx) |
3390 | 3390 |
|
3391 | 3391 |
if(privdata->ip) { |
3392 | 3392 |
pthread_mutex_lock(&blacklist_mutex); |
3393 |
- /* |
|
3394 |
- * FIXME: should be able to update here, otherwise we |
|
3395 |
- * can't reblacklist an entry that has timed out |
|
3396 |
- */ |
|
3397 |
- (void)tableInsert(blacklist, privdata->ip, |
|
3393 |
+ (void)tableUpdate(blacklist, privdata->ip, |
|
3398 | 3394 |
(int)time((time_t *)0)); |
3399 | 3395 |
pthread_mutex_unlock(&blacklist_mutex); |
3400 | 3396 |
free(privdata->ip); |
... | ... |
@@ -5565,7 +5561,7 @@ mx(void) |
5565 | 5565 |
u_char buf[BUFSIZ]; |
5566 | 5566 |
union { |
5567 | 5567 |
HEADER h; |
5568 |
- u_char u[PACKETSZ]; |
|
5568 |
+ u_char u[PACKETSZ]; |
|
5569 | 5569 |
} q; |
5570 | 5570 |
const HEADER *hp; |
5571 | 5571 |
int len, i; |
... | ... |
@@ -5637,7 +5633,7 @@ resolve(const char *host) |
5637 | 5637 |
u_char buf[BUFSIZ]; |
5638 | 5638 |
union { |
5639 | 5639 |
HEADER h; |
5640 |
- u_char u[PACKETSZ]; |
|
5640 |
+ u_char u[PACKETSZ]; |
|
5641 | 5641 |
} q; |
5642 | 5642 |
const HEADER *hp; |
5643 | 5643 |
int len, i; |
... | ... |
@@ -15,6 +15,10 @@ |
15 | 15 |
* along with this program; if not, write to the Free Software |
16 | 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | 17 |
* MA 02110-1301, USA. |
18 |
+ * |
|
19 |
+ * TODO: Allow individual items to be updated or removed |
|
20 |
+ * |
|
21 |
+ * It is up to the caller to create a mutex for the table if needed |
|
18 | 22 |
*/ |
19 | 23 |
|
20 | 24 |
#if HAVE_CONFIG_H |
... | ... |
@@ -92,7 +96,8 @@ tableInsert(table_t *table, const char *key, int value) |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
/* |
95 |
- * Returns the value - -1 for not found |
|
95 |
+ * Returns the value - -1 for not found. This means the value of a valid key |
|
96 |
+ * can't be -1 :-( |
|
96 | 97 |
*/ |
97 | 98 |
int |
98 | 99 |
tableFind(const table_t *table, const char *key) |
... | ... |
@@ -128,3 +133,31 @@ tableFind(const table_t *table, const char *key) |
128 | 128 |
|
129 | 129 |
return -1; /* not found */ |
130 | 130 |
} |
131 |
+ |
|
132 |
+/* |
|
133 |
+ * Change a value in the table. If the key isn't in the table insert it |
|
134 |
+ * Returns -1 for error, otherwise the new value |
|
135 |
+ */ |
|
136 |
+int |
|
137 |
+tableUpdate(table_t *table, const char *key, int new_value) |
|
138 |
+{ |
|
139 |
+ tableEntry *tableItem; |
|
140 |
+ |
|
141 |
+ assert(table != NULL); |
|
142 |
+ |
|
143 |
+ if(key == NULL) |
|
144 |
+ return -1; /* not treated as a fatal error */ |
|
145 |
+ |
|
146 |
+ if(table->tableHead == NULL) |
|
147 |
+ /* not populated yet */ |
|
148 |
+ return tableInsert(table, key, new_value); |
|
149 |
+ |
|
150 |
+ for(tableItem = table->tableHead; tableItem; tableItem = tableItem->next) |
|
151 |
+ if(strcasecmp(tableItem->key, key) == 0) { |
|
152 |
+ tableItem->value = new_value; |
|
153 |
+ return new_value; |
|
154 |
+ } |
|
155 |
+ |
|
156 |
+ /* not found */ |
|
157 |
+ return tableInsert(table, key, new_value); |
|
158 |
+} |
... | ... |
@@ -34,4 +34,5 @@ typedef struct table { |
34 | 34 |
struct table *tableCreate(void); |
35 | 35 |
void tableDestroy(table_t *table); |
36 | 36 |
int tableInsert(table_t *table, const char *key, int value); |
37 |
+int tableUpdate(table_t *table, const char *key, int new_value); |
|
37 | 38 |
int tableFind(const table_t *table, const char *key); |