23 |
|
|
24 |
#include "config.h" |
#include "config.h" |
25 |
|
|
26 |
|
#include <unistd.h> |
27 |
#include <stdlib.h> |
#include <stdlib.h> |
28 |
#include <stdio.h> |
#include <stdio.h> |
29 |
#include <string.h> |
#include <string.h> |
30 |
|
#include <getopt.h> |
31 |
|
#include <assert.h> |
32 |
|
|
33 |
|
#include "common.h" |
34 |
#include "options.h" |
#include "options.h" |
35 |
#include "utils.h" |
#include "utils.h" |
36 |
#include "access.h" |
#include "access.h" |
40 |
|
|
41 |
param_t param[PARAM_MAX] = { |
param_t param[PARAM_MAX] = { |
42 |
/* GENERAL CONFIGURATION */ |
/* GENERAL CONFIGURATION */ |
43 |
{NULL, "access-method", "access_method", string, false, {string:"modem"} |
{opt_none, "access_method", string, false, {string:"modem"} |
44 |
} |
} |
45 |
, |
, |
46 |
{NULL, "protocol", "protocol", string, false, {string:"aol30"} |
{opt_none, "protocol", string, false, {string:"aol30"} |
47 |
} |
} |
48 |
, |
, |
49 |
{"it", "interface-type", "interface_type", string, false, {string:"tun"} |
{opt_interface_type, "interface_type", string, false, {string:"tun"} |
50 |
} |
} |
51 |
, |
, |
52 |
{"i", "interface", "interface_name", string, false, {string:"tun0"} |
{opt_interface_name, "interface_name", string, false, {string:"tun0"} |
53 |
} |
} |
54 |
, |
, |
55 |
{"u", "user", "user", string, false, {string:NULL} |
{opt_user, "user", string, false, {string:NULL} |
56 |
} |
} |
57 |
, |
, |
58 |
{"p", "pass", "pass", string, false, {string:NULL} |
{opt_pass, "pass", string, false, {string:NULL} |
59 |
} |
} |
60 |
, |
, |
61 |
{"r", "auto-reconnect", "auto_reconnect", boolean, false, {boolean:false} |
{opt_auto_reconnect, "auto_reconnect", boolean, false, {boolean:false} |
62 |
} |
} |
63 |
, |
, |
64 |
{NULL, "reconnect-delay", "reconnect_delay", integer, false, {integer:0} |
{opt_none, "reconnect_delay", integer, false, {integer:0} |
65 |
} |
} |
66 |
, |
, |
67 |
{"d", "daemon", "daemon", boolean, false, {boolean:false} |
{opt_daemon, "daemon", boolean, false, {boolean:false} |
68 |
} |
} |
69 |
, |
, |
70 |
{"D", "debug-level", "debug_level", integer, false, {integer:-1} |
{opt_debug_level, "debug_level", integer, false, {integer:-1} |
71 |
} |
} |
72 |
, |
, |
73 |
{NULL, "dns", "set_dns", boolean, false, {boolean:true} |
{opt_none, "set_dns", boolean, false, {boolean:true} |
74 |
} |
} |
75 |
, |
, |
76 |
{NULL, "pid", "pid_file", string, false, {string:"/var/run/pengaol.pid"} |
{opt_pid_file, "pid_file", string, false, {string:"/var/run/pengaol.pid"} |
77 |
} |
} |
78 |
, |
, |
79 |
{NULL, "ip-up", "ip-up_script", string, false, {string:"/etc/pengaol/ip-up"} |
{opt_ip_up, "ip-up_script", string, false, {string:NULL} |
80 |
} |
} |
81 |
, |
, |
82 |
{NULL, "ip-down", "ip-down_script", string, false, {string:"/etc/pengaol/ip-down"} |
{opt_ip_down, "ip-down_script", string, false, {string:NULL} |
83 |
} |
} |
84 |
, |
, |
85 |
|
|
86 |
/* MODEM SPECIFIC */ |
/* MODEM SPECIFIC */ |
87 |
{"m", "modem", "modem_device", string, false, {string:"/dev/modem"} |
{opt_modem, "modem_device", string, false, {string:"/dev/modem"} |
88 |
} |
} |
89 |
, |
, |
90 |
{NULL, "rtscts", "rtscts", boolean, false, {boolean:true} |
{opt_rtscts, "rtscts", boolean, false, {boolean:true} |
91 |
} |
} |
92 |
, |
, |
93 |
{NULL, "init-str", "initstr1", string, false, {string:"ATZ"} |
{opt_init_str, "initstr1", string, false, {string:"ATZ"} |
94 |
} |
} |
95 |
, |
, |
96 |
{NULL, NULL, "initstr2", string, false, {string:NULL} |
{opt_none, "initstr2", string, false, {string:NULL} |
97 |
} |
} |
98 |
, |
, |
99 |
{NULL, NULL, "initstr3", string, false, {string:NULL} |
{opt_none, "initstr3", string, false, {string:NULL} |
100 |
} |
} |
101 |
, |
, |
102 |
{NULL, NULL, "initstr4", string, false, {string:NULL} |
{opt_none, "initstr4", string, false, {string:NULL} |
103 |
} |
} |
104 |
, |
, |
105 |
{NULL, NULL, "initstr5", string, false, {string:NULL} |
{opt_none, "initstr5", string, false, {string:NULL} |
106 |
} |
} |
107 |
, |
, |
108 |
{NULL, NULL, "initstr6", string, false, {string:NULL} |
{opt_none, "initstr6", string, false, {string:NULL} |
109 |
} |
} |
110 |
, |
, |
111 |
{NULL, NULL, "initstr7", string, false, {string:NULL} |
{opt_none, "initstr7", string, false, {string:NULL} |
112 |
} |
} |
113 |
, |
, |
114 |
{NULL, NULL, "initstr8", string, false, {string:NULL} |
{opt_none, "initstr8", string, false, {string:NULL} |
115 |
} |
} |
116 |
, |
, |
117 |
{NULL, NULL, "initstr9", string, false, {string:NULL} |
{opt_none, "initstr9", string, false, {string:NULL} |
118 |
} |
} |
119 |
, |
, |
120 |
{NULL, "dial-str", "dialstr", string, false, {string:"ATDT"} |
{opt_dial_str, "dialstr", string, false, {string:"ATDT"} |
121 |
} |
} |
122 |
, |
, |
123 |
{NULL, NULL, "dial_prefix", string, false, {string:NULL} |
{opt_none, "dial_prefix", string, false, {string:NULL} |
124 |
} |
} |
125 |
, |
, |
126 |
{"n", "phone", "phone", string, false, {string:NULL} |
{opt_phone, "phone", string, false, {string:NULL} |
127 |
} |
} |
128 |
, |
, |
129 |
{NULL, NULL, "phone1", string, false, {string:NULL} |
{opt_none, "phone1", string, false, {string:NULL} |
130 |
} |
} |
131 |
, |
, |
132 |
{NULL, NULL, "phone2", string, false, {string:NULL} |
{opt_none, "phone2", string, false, {string:NULL} |
133 |
} |
} |
134 |
, |
, |
135 |
{NULL, NULL, "phone3", string, false, {string:NULL} |
{opt_none, "phone3", string, false, {string:NULL} |
136 |
} |
} |
137 |
, |
, |
138 |
{NULL, NULL, "phone4", string, false, {string:NULL} |
{opt_none, "phone4", string, false, {string:NULL} |
139 |
} |
} |
140 |
, |
, |
141 |
{NULL, NULL, "phone5", string, false, {string:NULL} |
{opt_none, "phone5", string, false, {string:NULL} |
142 |
} |
} |
143 |
, |
, |
144 |
{"s", "line-speed", "line_speed", integer, false, {integer:115200} |
{opt_speed, "line_speed", integer, false, {integer:115200} |
145 |
} |
} |
146 |
, |
, |
147 |
{NULL, NULL, "login_prompt", string, false, {string:"ogin:"} |
{opt_none, "login_prompt", string, false, {string:"ogin:"} |
148 |
} |
} |
149 |
, |
, |
150 |
{NULL, NULL, "server_pass_prompt", string, false, {string:"assword:"} |
{opt_none, "server_pass_prompt", string, false, {string:"assword:"} |
151 |
} |
} |
152 |
, |
, |
153 |
{"sl", "server-login", "server_login", string, false, {string:"aol"} |
{opt_server_login, "server_login", string, false, {string:"aol"} |
154 |
} |
} |
155 |
, |
, |
156 |
{"sp", "server-pass", "server_pass", string, false, {string:"aol"} |
{opt_server_pass, "server_pass", string, false, {string:"aol"} |
157 |
} |
} |
158 |
, |
, |
159 |
{NULL, NULL, "server_connected", string, false, {string:"onnected"} |
{opt_none, "server_connected", string, false, {string:"onnected"} |
160 |
} |
} |
161 |
, |
, |
162 |
{NULL, NULL, "server_bad_passwd", string, false, {string:"assword"} |
{opt_none, "server_bad_passwd", string, false, {string:"assword"} |
163 |
} |
} |
164 |
, |
, |
165 |
{NULL, NULL, "dial_retry", integer, false, {integer:3} |
{opt_none, "dial_retry", integer, false, {integer:3} |
166 |
} |
} |
167 |
, |
, |
168 |
{NULL, NULL, "retry_delay", integer, false, {integer:0} |
{opt_none, "retry_delay", integer, false, {integer:0} |
169 |
} |
} |
170 |
, |
, |
171 |
{NULL, NULL, "abort_busy", boolean, false, {boolean:true} |
{opt_none, "abort_busy", boolean, false, {boolean:true} |
172 |
} |
} |
173 |
, |
, |
174 |
{NULL, NULL, "abort_dialtone", boolean, false, {boolean:true} |
{opt_none, "abort_dialtone", boolean, false, {boolean:true} |
175 |
} |
} |
176 |
, |
, |
177 |
|
|
178 |
/* CABLE SPECIFIC */ |
/* CABLE SPECIFIC */ |
179 |
{NULL, NULL, "aol_host", string, false, {string:"americaonline.aol.com"} |
{opt_none, "aol_host", string, false, {string:"americaonline.aol.com"} |
180 |
} |
} |
181 |
, |
, |
182 |
{NULL, NULL, "aol_port", integer, false, {integer:5190} |
{opt_none, "aol_port", integer, false, {integer:5190} |
183 |
} |
} |
184 |
, |
, |
185 |
{NULL, NULL, "cable_iface", string, false, {string:"eth0"} |
{opt_none, "cable_iface", string, false, {string:"eth0"} |
186 |
} |
} |
187 |
, |
, |
188 |
{NULL, NULL, "connect_ip", string, false, {string:"0.0.0.0"} |
{opt_none, "connect_ip", string, false, {string:"0.0.0.0"} |
189 |
} |
} |
190 |
}; |
}; |
191 |
|
|
192 |
|
/* |
193 |
|
* Command line options |
194 |
|
*/ |
195 |
|
|
196 |
|
/* Be sure to keep both sync. */ |
197 |
|
static const char short_options[] = "hVrt:i:u:p:dD:m:n:s:l:w:"; |
198 |
|
|
199 |
|
int toto; |
200 |
|
|
201 |
|
static struct option const long_options[] = |
202 |
|
{ |
203 |
|
{"help", no_argument, 0, opt_help}, |
204 |
|
{"version", no_argument, 0, opt_version}, |
205 |
|
{"interface-type", required_argument, 0, opt_interface_type}, |
206 |
|
{"interface_name", required_argument, 0, opt_interface_name}, |
207 |
|
{"user", required_argument, 0, opt_user}, |
208 |
|
{"password", required_argument, 0, opt_pass}, |
209 |
|
{"auto-reconnect", no_argument, 0, opt_auto_reconnect}, |
210 |
|
{"daemon", no_argument, 0, opt_daemon}, |
211 |
|
{"debug-level", required_argument, 0, opt_debug_level}, |
212 |
|
{"modem-device", required_argument, 0, opt_modem}, |
213 |
|
{"phone", required_argument, 0, opt_phone}, |
214 |
|
{"speed", required_argument, 0, opt_speed}, |
215 |
|
{"server-login", required_argument, 0, opt_server_login}, |
216 |
|
{"server-password", required_argument, 0, opt_server_pass}, |
217 |
|
{"pid-file", required_argument, 0, opt_pid_file}, |
218 |
|
{"rtscts", required_argument, 0, opt_rtscts}, |
219 |
|
{"init-str", required_argument, 0, opt_init_str}, |
220 |
|
{"dial-str", required_argument, 0, opt_dial_str}, |
221 |
|
{NULL, 0, NULL, 0} |
222 |
|
}; |
223 |
|
|
224 |
|
void |
225 |
|
usage () |
226 |
|
{ |
227 |
|
printf("Usage : %s [OPTIONS]\n |
228 |
|
Operation modes : |
229 |
|
-h, --help print this help, then exit. |
230 |
|
-V, --version print version, then exit. |
231 |
|
|
232 |
|
Network interface properties : |
233 |
|
[-t] --interface-type=TYPE set interface type (tun). |
234 |
|
[-i] --interface-name=NAME set interface name (tun0). |
235 |
|
|
236 |
|
Modem properties : |
237 |
|
[-m] --modem-device=DEV set modem device name (ttyS0). |
238 |
|
[-n] --phone=PHONE set phone number. |
239 |
|
[-s] --speed=SPEED set modem speed. |
240 |
|
--rtscts enable modem rtscts. |
241 |
|
--init-str=STR set modem init string. |
242 |
|
--dial-str=STR set modem dialing string. |
243 |
|
|
244 |
|
User authentification : |
245 |
|
[-u] --user=NAME set username. |
246 |
|
[-p] --password=password set password. |
247 |
|
[-l] --server-login set server login. |
248 |
|
[-w] --server-password set server password. |
249 |
|
|
250 |
|
Misc : |
251 |
|
[-r] --auto-reconnect enable autoreconnection. |
252 |
|
[-d] --daemon daemon mode, run in background. |
253 |
|
[-D] --debug-level=LEVEL set debug verbose level. |
254 |
|
--pid-file=NAME name of pid file (/var/run/pengaol.pid). |
255 |
|
\n", program_name); |
256 |
|
exit (0); |
257 |
|
} |
258 |
|
|
259 |
|
void |
260 |
|
version (void) |
261 |
|
{ |
262 |
|
printf ("%s (" PACKAGE ") v" VERSION "\n", program_name); |
263 |
|
exit (0); |
264 |
|
} |
265 |
|
|
266 |
|
static int |
267 |
|
set_opt_param (option_e opt_id) |
268 |
|
{ |
269 |
|
int i; |
270 |
|
|
271 |
|
for (i = 0; i < PARAM_MAX && param[i].opt_id != opt_id; i++) |
272 |
|
; |
273 |
|
if (i == PARAM_MAX) |
274 |
|
return 1; |
275 |
|
if (param[i].opt_id == opt_id) |
276 |
|
{ |
277 |
|
/* We now we have a parameter */ |
278 |
|
assert ((param[i].type == boolean) || (optarg != NULL)); |
279 |
|
|
280 |
|
switch (param[i].type) |
281 |
|
{ |
282 |
|
case boolean: |
283 |
|
param[i].value.boolean = true; |
284 |
|
break; |
285 |
|
case integer: |
286 |
|
param[i].value.integer = atoi (optarg); |
287 |
|
break; |
288 |
|
case string: |
289 |
|
if (param[i].defined && (param[i].value.string != NULL)) |
290 |
|
free (param[i].value.string); |
291 |
|
param[i].value.string = strdup (optarg); |
292 |
|
} |
293 |
|
} |
294 |
|
return 0; |
295 |
|
} |
296 |
|
|
297 |
|
int |
298 |
|
parse_command_line (argc, argv) |
299 |
|
int argc; |
300 |
|
char **argv; |
301 |
|
{ |
302 |
|
int c; |
303 |
|
|
304 |
|
while ((c = getopt_long (argc, argv, short_options, long_options, |
305 |
|
NULL)) != -1) |
306 |
|
switch (c) |
307 |
|
{ |
308 |
|
case 0: |
309 |
|
/* Options that set a flag. */ |
310 |
|
break; |
311 |
|
|
312 |
|
case opt_help: |
313 |
|
usage (); |
314 |
|
break; |
315 |
|
|
316 |
|
case opt_version: |
317 |
|
version (); |
318 |
|
break; |
319 |
|
|
320 |
|
default: |
321 |
|
if (set_opt_param (c)) |
322 |
|
{ |
323 |
|
fprintf (stderr, "Try `%s --help' for more information.\n", |
324 |
|
program_name); |
325 |
|
exit (1); |
326 |
|
} |
327 |
|
} |
328 |
|
return 0; |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
/* |
333 |
|
* Config file |
334 |
|
*/ |
335 |
|
|
336 |
int |
int |
337 |
parse_config () |
parse_config () |
338 |
{ |
{ |
342 |
home=getenv ("HOME"); |
home=getenv ("HOME"); |
343 |
snprintf (homeconfig,249,"%s/.%s",home,HOME_CONFIG); |
snprintf (homeconfig,249,"%s/.%s",home,HOME_CONFIG); |
344 |
|
|
345 |
if (parse_config_file(DEFAULT_CONFIG)) |
if (!parse_config_file(DEFAULT_CONFIG)) |
346 |
return 1; |
return 0; |
347 |
if (parse_config_file(homeconfig)); |
if (!parse_config_file(homeconfig)) |
348 |
{ |
{ |
349 |
printf ("Warning, no personnal config found !\n"); |
printf ("Warning, no personnal config found !\n"); |
350 |
printf ("Create your personnal config file in %s.\n\n",homeconfig); |
printf ("Create your personnal config file in %s.\n\n",homeconfig); |
351 |
return 0; |
return 1; |
352 |
} |
} |
353 |
|
return 1; |
354 |
} |
} |
355 |
|
|
356 |
int |
int |
366 |
if (f == NULL) |
if (f == NULL) |
367 |
{ |
{ |
368 |
perror (filename); |
perror (filename); |
369 |
return 1; |
return 0; |
370 |
} |
} |
371 |
while (!feof (f)) |
while (!feof (f)) |
372 |
{ |
{ |
386 |
} |
} |
387 |
} |
} |
388 |
} |
} |
389 |
return 0; |
return 1; |
390 |
} |
} |
391 |
|
|
392 |
void |
void |