29 |
#include <stdlib.h> |
#include <stdlib.h> |
30 |
|
|
31 |
#include "utils.h" |
#include "utils.h" |
32 |
|
#include "gettext.h" |
33 |
#include "options.h" |
#include "options.h" |
34 |
#include "getpass.h" |
#include "getpass.h" |
35 |
#include "log.h" |
#include "log.h" |
37 |
#include "checkopt.h" |
#include "checkopt.h" |
38 |
|
|
39 |
int |
int |
40 |
check_multiple(option, value, choices) |
check_multiple (option, value, choices) |
41 |
char *option; |
char *option; |
42 |
char *value; |
char *value; |
43 |
char **choices; |
char **choices; |
45 |
char *tmp; |
char *tmp; |
46 |
int i; |
int i; |
47 |
|
|
48 |
if(value != NULL) |
if (value != NULL) |
49 |
{ |
{ |
50 |
tmp=malloc( strlen(value) + 1 ); |
tmp = malloc (strlen (value) + 1); |
51 |
strcpy(tmp, value); |
strcpy (tmp, value); |
52 |
/* |
/* |
53 |
* strcasecmp() is not POSIX compliant |
* strcasecmp() is not POSIX compliant |
54 |
* so I must lowerize the string for strcmp |
* so I must lowerize the string for strcmp |
55 |
*/ |
*/ |
56 |
lowerize(tmp); |
lowerize (tmp); |
57 |
for(i=0; choices[i]!=NULL; i++) |
for (i = 0; choices[i] != NULL; i++) |
58 |
if(!strcmp(tmp, choices[i]) ) |
if (!strcmp (tmp, choices[i])) |
59 |
{ |
{ |
60 |
free(tmp); |
free (tmp); |
61 |
return 1; |
return 1; |
62 |
} |
} |
63 |
free(tmp); |
free (tmp); |
64 |
} |
} |
65 |
|
|
66 |
log(LOG_ERR, "%s must be ",option); |
log (LOG_ERR, gettext("%s must be "), option); |
67 |
for(i=0; choices[i]!=NULL; i++) |
for (i = 0; choices[i] != NULL; i++) |
68 |
{ |
{ |
69 |
log(LOG_ERR, "%s", choices[i]); |
log (LOG_ERR, "%s", choices[i]); |
70 |
if(choices[i+1]!=NULL) |
if (choices[i + 1] != NULL) |
71 |
{ |
{ |
72 |
if(choices[i+2]!=NULL) |
if (choices[i + 2] != NULL) |
73 |
log(LOG_ERR, ", "); |
log (LOG_ERR, ", "); |
74 |
else |
else |
75 |
log(LOG_ERR, " or "); |
log (LOG_ERR, gettext(" or ")); |
76 |
} |
} |
77 |
} |
} |
78 |
log(LOG_ERR,".\n"); |
log (LOG_ERR, ".\n"); |
79 |
return 0; |
return 0; |
80 |
} |
} |
81 |
|
|
82 |
int |
int |
83 |
check_access_method(option, method) |
check_access_method (option, method) |
84 |
char *option; |
char *option; |
85 |
char *method; |
char *method; |
86 |
{ |
{ |
87 |
char *choices[] = {"modem", "cable", "dsl", "tcpip", NULL}; |
char *choices[] = { "modem", "cable", "dsl", "tcpip", NULL }; |
88 |
|
|
89 |
return check_multiple(option, method, choices); |
return check_multiple (option, method, choices); |
90 |
} |
} |
91 |
|
|
92 |
int |
int |
93 |
check_protocol(option, protocol) |
check_protocol (option, protocol) |
94 |
char *option; |
char *option; |
95 |
char *protocol; |
char *protocol; |
96 |
{ |
{ |
97 |
char *choices[] = {"p3", "l2tp", NULL}; |
char *choices[] = { "p3", "l2tp", NULL }; |
98 |
|
|
99 |
return check_multiple(option, protocol, choices); |
return check_multiple (option, protocol, choices); |
100 |
} |
} |
101 |
|
|
102 |
int |
int |
103 |
check_iface_type(option, type) |
check_iface_type (option, type) |
104 |
char *option; |
char *option; |
105 |
char *type; |
char *type; |
106 |
{ |
{ |
107 |
char *choices[] = {"tun", NULL}; |
char *choices[] = { "tun", NULL }; |
108 |
|
|
109 |
return check_multiple(option, type, choices); |
return check_multiple (option, type, choices); |
110 |
} |
} |
111 |
|
|
112 |
int |
int |
113 |
check_screen_name(option, sn) |
check_screen_name (option, sn) |
114 |
char *option; |
char *option; |
115 |
char *sn; |
char *sn; |
116 |
{ |
{ |
117 |
char *pass; |
char *pass; |
118 |
|
|
119 |
if(!sn) |
if (!sn) |
120 |
{ |
{ |
121 |
log(LOG_ERR, "Screen name not defined, please edit your configuration file (%s).\n", |
log (LOG_ERR, |
122 |
PARAM_CONFIG_FILE); |
gettext ("Screen name not defined, please edit your configuration file (%s).\n"), |
123 |
return 0; |
PARAM_CONFIG_FILE); |
124 |
|
return 0; |
125 |
} |
} |
126 |
if(get_password(sn,&pass)) |
if (get_password (sn, &pass)) |
127 |
{ |
{ |
128 |
free(pass); |
free (pass); |
129 |
return 1; |
return 1; |
130 |
} |
} |
131 |
else { |
else |
132 |
log(LOG_ERR, "Screen name '%s' not found in %s.\n", sn, PARAM_SECRET_FILE); |
{ |
133 |
return 0; |
log (LOG_ERR, gettext ("Screen name '%s' not found in %s.\n"), sn, |
134 |
} |
PARAM_SECRET_FILE); |
135 |
|
return 0; |
136 |
|
} |
137 |
} |
} |
138 |
|
|
139 |
int |
int |
140 |
check_debug_level(option, level) |
check_debug_level (option, level) |
141 |
char *option; |
char *option; |
142 |
int level; |
int level; |
143 |
{ |
{ |
144 |
if(level>=0 && level<=DEBUG_MAX) return 1; |
if (level >= 0 && level <= DEBUG_MAX) |
145 |
|
return 1; |
146 |
|
|
147 |
log(LOG_ERR, "%s must be between 0 and 10.\n", option); |
log (LOG_ERR, "%s must be between 0 and 10.\n", option); |
148 |
return 0; |
return 0; |
149 |
} |
} |
150 |
|
|
151 |
int |
int |
152 |
check_natural(option, num) |
check_natural (option, num) |
153 |
char *option; |
char *option; |
154 |
int num; |
int num; |
155 |
{ |
{ |
156 |
if(num>=0) return 1; |
if (num >= 0) |
157 |
|
return 1; |
158 |
|
|
159 |
log(LOG_ERR, "%s must be >=0.\n", option); |
log (LOG_ERR, "%s must be >=0.\n", option); |
160 |
return 0; |
return 0; |
161 |
} |
} |
162 |
|
|
163 |
#ifdef WITH_MODEM |
#ifdef WITH_MODEM |
164 |
int |
int |
165 |
check_line_speed(option, speed) |
check_line_speed (option, speed) |
166 |
char *option; |
char *option; |
167 |
int speed; |
int speed; |
168 |
{ |
{ |
169 |
if(modem_valid_speed(speed)) return 1; |
if (modem_valid_speed (speed)) |
170 |
|
return 1; |
171 |
|
|
172 |
log(LOG_ERR, "%s has an invalid line speed specicification.\n", option); |
log (LOG_ERR, "%s has an invalid line speed specicification.\n", option); |
173 |
return 0; |
return 0; |
174 |
} |
} |
175 |
#endif /* WITH_MODEM */ |
#endif /* WITH_MODEM */ |
176 |
|
|
177 |
#ifdef WITH_TCPIP |
#ifdef WITH_TCPIP |
178 |
int |
int |
179 |
check_port(option, port) |
check_port (option, port) |
180 |
char *option; |
char *option; |
181 |
int port; |
int port; |
182 |
{ |
{ |
183 |
if(port>0 && port<65536) return 1; |
if (port > 0 && port < 65536) |
184 |
|
return 1; |
185 |
|
|
186 |
log(LOG_ERR, "%s must be a valid port (between 1 and 65535).\n", option); |
log (LOG_ERR, "%s must be a valid port (between 1 and 65535).\n", option); |
187 |
return 0; |
return 0; |
188 |
} |
} |
189 |
|
|
190 |
int |
int |
191 |
check_ip(option, ip) |
check_ip (option, ip) |
192 |
char *option; |
char *option; |
193 |
char *ip; |
char *ip; |
194 |
{ |
{ |
195 |
struct in_addr inp; |
struct in_addr inp; |
196 |
|
|
197 |
if(inet_aton(ip, &inp)) return 1; |
if (inet_aton (ip, &inp)) |
198 |
|
return 1; |
199 |
|
|
200 |
log(LOG_ERR, "%s must be a valid IP address.\n", option); |
log (LOG_ERR, "%s must be a valid IP address.\n", option); |
201 |
return 0; |
return 0; |
202 |
} |
} |
203 |
#endif /* WITH_TCPIP */ |
#endif /* WITH_TCPIP */ |