1 /****************************************************************************
2  *
3  * Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
4  * Copyright (C) 2011-2013 Sourcefire, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 as
8  * published by the Free Software Foundation.  You may not use, modify or
9  * distribute this program under any other version of the GNU General
10  * Public License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  *
21  ****************************************************************************/
22 
23 /***************************************************************************
24  *
25  * imap_config.h
26  *
27  * Author: Bhagyashree Bantwal <bbantwal@cisco.com>
28  *
29  ***************************************************************************/
30 
31 #ifndef __IMAP_CONFIG_H__
32 #define __IMAP_CONFIG_H__
33 
34 #include "sfPolicyUserData.h"
35 #include "file_mail_common.h"
36 #include "sf_email_attach_decode.h"
37 
38 #define CONF_SEPARATORS                  " \t\n\r"
39 #define CONF_PORTS                       "ports"
40 #define CONF_IMAP_MEMCAP                 "memcap"
41 #define CONF_MAX_MIME_MEM                "max_mime_mem"
42 #define CONF_B64_DECODE                  "b64_decode_depth"
43 #define CONF_QP_DECODE                   "qp_decode_depth"
44 #define CONF_BITENC_DECODE               "bitenc_decode_depth"
45 #define CONF_UU_DECODE                   "uu_decode_depth"
46 #define CONF_DISABLED                    "disabled"
47 #define CONF_START_LIST "{"
48 #define CONF_END_LIST   "}"
49 
50 /*These are temporary values*/
51 #define DEFAULT_MAX_MIME_MEM          838860
52 #define DEFAULT_IMAP_MEMCAP           838860
53 #define MAX_IMAP_MEMCAP               104857600
54 #define MIN_IMAP_MEMCAP               3276
55 #define MAX_MIME_MEM                  104857600
56 #define MIN_MIME_MEM                  3276
57 #define MAX_DEPTH                     65535
58 #define MIN_DEPTH                     -1
59 #define IMAP_DEFAULT_SERVER_PORT       143  /* IMAP normally runs on port 143 */
60 
61 #define ERRSTRLEN   512
62 
63 typedef struct _IMAPSearch
64 {
65     char *name;
66     int   name_len;
67 
68 } IMAPSearch;
69 
70 typedef struct _IMAPToken
71 {
72     char *name;
73     int   name_len;
74     int   search_id;
75 
76 } IMAPToken;
77 
78 typedef struct _IMAPCmdConfig
79 {
80     char alert;          /*  1 if alert when seen                          */
81     char normalize;      /*  1 if we should normalize this command         */
82     int  max_line_len;   /*  Max length of this particular command         */
83 
84 } IMAPCmdConfig;
85 
86 typedef struct _IMAPConfig
87 {
88     uint8_t ports[8192];
89     uint32_t  memcap;
90     IMAPToken *cmds;
91     IMAPSearch *cmd_search;
92     void *cmd_search_mpse;
93     int num_cmds;
94     int disabled;
95     MAIL_LogConfig log_config;
96 
97     DecodeConfig decode_conf;
98     int ref_count;
99 
100 } IMAPConfig;
101 
102 typedef struct _IMAP_Stats
103 {
104     uint64_t sessions;
105     uint64_t conc_sessions;
106     uint64_t max_conc_sessions;
107     uint64_t log_memcap_exceeded;
108     uint64_t cur_sessions;
109     MimeStats mime_stats;
110 
111 } IMAP_Stats;
112 
113 extern IMAP_Stats imap_stats;
114 
115 /* Function prototypes  */
116 void IMAP_ParseArgs(IMAPConfig *, char *);
117 void IMAP_PrintConfig(IMAPConfig *config);
118 
119 void IMAP_CheckConfig(IMAPConfig *, tSfPolicyUserContextId);
120 
121 #endif
122 
123