~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/phish_domaincheck_db.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
Import upstream version 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Phishing module: domain list implementation.
3
3
 *
4
 
 *  Copyright (C) 2007-2008 Sourcefire, Inc.
5
 
 *
6
 
 *  Authors: Török Edvin
 
4
 *  Copyright (C) 2006 T�r�k Edvin <edwintorok@gmail.com>
7
5
 *
8
6
 *  This program is free software; you can redistribute it and/or modify
9
 
 *  it under the terms of the GNU General Public License version 2 as
10
 
 *  published by the Free Software Foundation.
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
11
10
 *
12
11
 *  This program is distributed in the hope that it will be useful,
13
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
17
 *  along with this program; if not, write to the Free Software
19
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
19
 *  MA 02110-1301, USA.
 
20
 *
 
21
 *  $Log: phish_domaincheck_db.c,v $
 
22
 *  Revision 1.5  2006/10/10 23:51:49  tkojm
 
23
 *  apply patches for the anti-phish code from Edwin
 
24
 *
 
25
 *  Revision 1.4  2006/10/07 13:55:01  tkojm
 
26
 *  fix handlers
 
27
 *
 
28
 *  Revision 1.3  2006/10/07 11:00:46  tkojm
 
29
 *  make the experimental anti-phishing code more thread safe
 
30
 *
 
31
 *  Revision 1.2  2006/09/26 18:55:36  njh
 
32
 *  Fixed portability issues
 
33
 *
 
34
 *  Revision 1.1  2006/09/13 19:40:27  njh
 
35
 *  First draft
 
36
 *
 
37
 *  Revision 1.1  2006/09/12 19:38:39  acab
 
38
 *  Phishing module merge - libclamav
 
39
 *
 
40
 *  Revision 1.3  2006/08/20 21:18:11  edwin
 
41
 *  Added the script used to generate iana_tld.sh
 
42
 *  Added checks for phish_domaincheck_db
 
43
 *  Added phishing module design document from wiki (as discussed with aCaB).
 
44
 *  Updated .wdb/.pdb format documentation (in regex_list.c)
 
45
 *  Fixed some memory leaks in regex_list.c
 
46
 *  IOW: cleanups before the deadline.
 
47
 *  I consider my module to be ready for evaluation now.
 
48
 *
 
49
 *  Revision 1.2  2006/08/09 16:26:44  edwin
 
50
 *  Forgot to add these files
 
51
 *
21
52
 */
22
53
 
23
54
#if HAVE_CONFIG_H
24
55
#include "clamav-config.h"
25
56
#endif
26
57
 
 
58
#ifdef CL_EXPERIMENTAL
 
59
 
 
60
#ifndef CL_DEBUG
 
61
#define NDEBUG
 
62
#endif
 
63
 
27
64
#ifdef CL_THREAD_SAFE
28
65
#ifndef _REENTRANT
29
66
#define _REENTRANT
31
68
#endif
32
69
 
33
70
#include <stdio.h>
 
71
#include <stdlib.h>
 
72
#include <errno.h>
34
73
#include <string.h>
 
74
#ifdef  HAVE_STRINGS_H
 
75
#include <strings.h>
 
76
#endif
35
77
#include <ctype.h>
36
78
 
 
79
#include <limits.h>
37
80
#include "clamav.h"
 
81
#include <sys/types.h>
 
82
 
 
83
#ifdef  HAVE_REGEX_H
 
84
/*#define USE_PCRE*/
 
85
#include <regex.h>
 
86
#endif
 
87
 
 
88
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
 
89
#include <stddef.h>
 
90
#endif
 
91
 
38
92
#include "others.h"
39
 
#include "phishcheck.h"
 
93
#include "defaults.h"
 
94
#include "str.h"
 
95
#include "filetypes.h"
 
96
#include "mbox.h"
40
97
#include "phish_domaincheck_db.h"
41
98
#include "regex_list.h"
 
99
#include "matcher-ac.h"
42
100
 
43
 
int domainlist_match(const struct cl_engine* engine,char* real_url,const char* display_url,const struct pre_fixup_info* pre_fixup,int hostOnly)
 
101
int domainlist_match(const struct cl_engine* engine,const char* real_url,const char* display_url,int hostOnly,unsigned short* flags)
44
102
{
45
103
        const char* info;
46
 
        int rc = engine->domainlist_matcher ? regex_list_match(engine->domainlist_matcher,real_url,display_url,hostOnly ? pre_fixup : NULL,hostOnly,&info,0) : 0;
 
104
        int rc = engine->domainlist_matcher ? regex_list_match(engine->domainlist_matcher,real_url,display_url,hostOnly,&info,0) : 0;
 
105
        if(rc && info && info[0]) {/*match successfull, and has custom flags*/
 
106
                if(strlen(info)==3 && isxdigit(info[0]) && isxdigit(info[1]) && isxdigit(info[2])) {
 
107
                        unsigned short notwantedflags=0;
 
108
                        sscanf(info,"%hx",&notwantedflags);
 
109
                        *flags &= ~notwantedflags;/* filter unwanted phishcheck flags */        
 
110
                }
 
111
                else {
 
112
                        cli_warnmsg("Phishcheck:Unknown flag format in domainlist, 3 hex digits expected");
 
113
                }
 
114
        }
47
115
        return rc;
48
116
}
49
117
 
53
121
                engine->domainlist_matcher = (struct regex_matcher *) cli_malloc(sizeof(struct regex_matcher));
54
122
                if(!engine->domainlist_matcher)
55
123
                        return CL_EMEM;
56
 
#ifdef USE_MPOOL
57
 
                ((struct regex_matcher*)engine->domainlist_matcher)->mempool = engine->mempool;
58
 
#endif
59
 
                return init_regex_list(engine->domainlist_matcher, engine->dconf->other&OTHER_CONF_PREFILTERING);
 
124
                return init_regex_list(engine->domainlist_matcher);
60
125
        }
61
126
        else
62
127
                return CL_ENULLARG;
67
132
        return (engine && engine->domainlist_matcher) ? is_regex_ok(engine->domainlist_matcher) : 1;
68
133
}
69
134
 
 
135
void domainlist_cleanup(const struct cl_engine* engine)
 
136
{
 
137
        if(engine && engine->domainlist_matcher) {
 
138
                regex_list_cleanup(engine->domainlist_matcher);
 
139
        }
 
140
}
 
141
 
70
142
void domainlist_done(struct cl_engine* engine)
71
143
{
72
144
        if(engine && engine->domainlist_matcher) {
73
145
                regex_list_done(engine->domainlist_matcher);
74
146
                free(engine->domainlist_matcher);
 
147
                engine->domainlist_matcher = NULL;
75
148
        }
76
149
}
77
150
 
 
151
#endif