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
|
/*
* active port forwarder - software for secure forwarding
* Copyright (C) 2003-2007 jeremian <jeremian [at] poczta.fm>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include "server_check.h"
#include "stats.h"
#include "logging.h"
/*
* Function name: check_value
* Description: Checks if the string is a valid positive int number.
* Arguments: what - the string representing number
* info - the information string printed on failure
* Returns: The decoded int number.
*/
int
check_value(char* what, char* info)
{
long tmp;
assert(what != NULL);
assert(info != NULL);
tmp = check_value_liberal(what, info);
if (tmp <= 0) {
aflog(LOG_T_INIT, LOG_I_CRIT,
"%s: %d\n", info, tmp);
exit(1);
}
return tmp;
}
/*
* Function name: check_value_liberal
* Description: Checks if the string is a valid int number.
* Arguments: what - the string representing number
* info - the information string printed on failure
* Returns: The decoded int number.
*/
int
check_value_liberal(char* what, char* info)
{
char* znak;
long tmp;
assert(what != NULL);
assert(info != NULL);
if ((tmp = strtol(what, &znak, 10)) >= INT_MAX) {
aflog(LOG_T_INIT, LOG_I_CRIT,
"%s: %s\n", info, what);
exit(1);
}
if (((*what) == '\0') || (*znak != '\0')) {
aflog(LOG_T_INIT, LOG_I_CRIT,
"%s: %s\n", info, what);
exit(1);
}
return tmp;
}
/*
* Function name: check_long
* Description: Checks if the string is a valid long number.
* Arguments: text - the string representing number
* number - the pointer where decoded number will be stored
* Returns: 0 - success,
* 1 - value from outside the long number range,
* 2 - not the valid long number.
*/
int
check_long(char* text, long* number)
{
char* tmp;
if (((*number = strtol(text, &tmp, 10)) == LONG_MAX) || (*number == LONG_MIN)) {
return 1;
}
if ((*text != '\0') && (*tmp == '\0')) {
return 0;
}
else {
return 2;
}
}
|