libclamav/phish_whitelist.c
bd912dd8
 /*
  *  Phishing module: whitelist implementation.
  *
e1cbc270
  *  Copyright (C) 2013-2019 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  *  Copyright (C) 2007-2013 Sourcefire, Inc.
2023340a
  *
  *  Authors: Török Edvin
bd912dd8
  *
  *  This program is free software; you can redistribute it and/or modify
2023340a
  *  it under the terms of the GNU General Public License version 2 as
38a00199
  *  published by the Free Software Foundation.
bd912dd8
  *
  *  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., 51 Franklin Street, Fifth Floor, Boston,
  *  MA 02110-1301, USA.
  */
 
 #if HAVE_CONFIG_H
 #include "clamav-config.h"
 #endif
 
 #ifdef CL_THREAD_SAFE
 #ifndef _REENTRANT
 #define _REENTRANT
 #endif
 #endif
 
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 
 #include "clamav.h"
 #include "others.h"
 #include "phish_whitelist.h"
 #include "regex_list.h"
 
0728972e
 #include "mpool.h"
 
102cd430
 cl_error_t whitelist_match(const struct cl_engine* engine, char* real_url, const char* display_url, int hostOnly)
bd912dd8
 {
288057e9
     const char* info; /*unused*/
     cli_dbgmsg("Phishing: looking up in whitelist: %s:%s; host-only:%d\n", real_url, display_url, hostOnly);
     return engine->whitelist_matcher ? regex_list_match(engine->whitelist_matcher, real_url, display_url, NULL, hostOnly, &info, 1) : 0;
bd912dd8
 }
 
102cd430
 cl_error_t init_whitelist(struct cl_engine* engine)
bd912dd8
 {
288057e9
     if (engine) {
544fa973
         engine->whitelist_matcher = (struct regex_matcher*)MPOOL_MALLOC(engine->mempool, sizeof(struct regex_matcher));
288057e9
         if (!engine->whitelist_matcher) {
241e7eb1
             cli_errmsg("Phish_whitelist: Unable to allocate memory for whitelist_match\n");
288057e9
             return CL_EMEM;
241e7eb1
         }
0728972e
 #ifdef USE_MPOOL
288057e9
         ((struct regex_matcher*)(engine->whitelist_matcher))->mempool = engine->mempool;
0728972e
 #endif
288057e9
         return init_regex_list(engine->whitelist_matcher, engine->dconf->other & OTHER_CONF_PREFILTERING);
     } else
         return CL_ENULLARG;
bd912dd8
 }
 
3da4dd4c
 int is_whitelist_ok(const struct cl_engine* engine)
bd912dd8
 {
288057e9
     return (engine && engine->whitelist_matcher) ? is_regex_ok(engine->whitelist_matcher) : 1;
bd912dd8
 }
 
3da4dd4c
 void whitelist_done(struct cl_engine* engine)
bd912dd8
 {
288057e9
     if (engine && engine->whitelist_matcher) {
         regex_list_done(engine->whitelist_matcher);
544fa973
         MPOOL_FREE(engine->mempool, engine->whitelist_matcher);
288057e9
         engine->whitelist_matcher = NULL;
     }
bd912dd8
 }