-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_options.c
183 lines (161 loc) · 3.18 KB
/
check_options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* This file is a part of groinc
*
* Copyright (C) 2006, 2007 Sarzyniec Luc <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* see the COPYING file for more informations */
#include <netdb.h>
#include "check_options.h"
#include "globals_filter.h"
#include "globals_args.h"
#include "globals_error.h"
#include "network/protocols.h"
#include "tools/memory_tools.h"
#include "tools/network_tools.h"
#include "tools/math_tools.h"
#include "parse_options.h"
#include "error.h"
#include <regex.h>
#include <sys/socket.h>
int chk_output(char *val)
{
return OPT_OK;
}
int chk_outputdata(char *val)
{
return OPT_OK;
}
int chk_inputfile(char *val)
{
return OPT_OK;
}
int chk_outputfile(char *val)
{
return OPT_OK;
}
int chk_flt_dstport(char *val)
{
/* test valid port */
return OPT_OK;
}
int chk_flt_srcport(char *val)
{
return OPT_OK;
}
int chk_flt_globalport(char *val)
{
return OPT_OK;
}
#define CHK_FLT_HOST(V) __extension__ \
regex_t tmp; \
regcomp(&tmp,CHK_FLT_HOST_REGEX_HOSTNAME,REG_NOSUB); \
if (regexec(&tmp,V,0,0,0)) \
{ \
regfree(&tmp); \
regcomp(&tmp,CHK_FLT_HOST_REGEX_CIDR,REG_NOSUB); \
if (regexec(&tmp,V,0,0,0)) \
{ \
regfree(&tmp); \
regcomp(&tmp,CHK_FLT_HOST_REGEX_IPNETMASK,REG_NOSUB); \
if (regexec(&tmp,V,0,0,0)) \
{ \
regfree(&tmp); \
regcomp(&tmp,CHK_FLT_HOST_REGEX_IP,REG_NOSUB); \
if (regexec(&tmp,V,0,0,0)) \
goto err; \
else \
goto out; \
} \
else \
goto out; \
} \
else \
goto out;\
} \
else \
goto name; \
err: \
regfree(&tmp); \
ERR_SET(list_error,EHOSTNAME_INVAL,V); \
return OPT_ERROR; \
name: \
if (!gethostbyname(V)) \
{ \
herror("Cannot resolve hostname"); \
goto err; \
} \
out: \
regfree(&tmp); \
return OPT_OK;
int chk_flt_srcip(char *val)
{
CHK_FLT_HOST(val);
}
int chk_flt_dstip(char *val)
{
CHK_FLT_HOST(val);
}
int chk_flt_globalip(char *val)
{
CHK_FLT_HOST(val);
}
int chk_flt_srcmac(char *val)
{
return OPT_OK;
}
int chk_flt_dstmac(char *val)
{
return OPT_OK;
}
int chk_flt_limitnb(char *val)
{
return OPT_OK;
}
int chk_flt_timelimit(char *val)
{
return OPT_OK;
}
int chk_flt_filterstr(char *val)
{
return OPT_OK;
}
int chk_flt_filterregex(char *val)
{
regex_t tmp;
if (regcomp(&tmp,val,REG_NOSUB))
{
regfree(&tmp);
ERR_SET(list_error,EREGEX_INVAL,val);
return OPT_ERROR;
}
else
{
regfree(&tmp);
return OPT_OK;
}
}
int chk_flt_protocol(char *val)
{
if ((lookup_protoid(strupr(val)) < 0) && (lookup_ethid(strupr(val)) < 0)
&& (lookup_ipid(strupr(val)) < 0))
{
ERR_SET(list_error,EOPT_PROTO,val);
return OPT_ERROR;
}
else
{
return OPT_OK;
}
}