updated on Wed Jan 25 00:20:47 UTC 2012
[aur-mirror.git] / ppp-alt / ppp-2.4.2-asp-cbcp-mps.patch
blob116f7c5f134e77bcb01102f881b048e5244adf6a
1 --- ppp-2.4.2/chat/Makefile.linux.vns 2004-05-28 12:11:22 +0400
2 +++ ppp-2.4.2/chat/Makefile.linux 2004-05-28 12:11:22 +0400
3 @@ -1,6 +1,6 @@
4 # $Id: Makefile.linux,v 1.10 2004/01/13 03:57:55 paulus Exp $
6 -CDEF1= -DTERMIOS # Use the termios structure
7 +#CDEF1= -DTERMIOS # Use the termios structure
8 CDEF2= -DSIGTYPE=void # Standard definition
9 CDEF3= -UNO_SLEEP # Use the usleep function
10 CDEF4= -DFNDELAY=O_NDELAY # Old name value
11 --- ppp-2.4.2/chat/chat.c.vns 2003-03-30 12:23:48 +0400
12 +++ ppp-2.4.2/chat/chat.c 2004-05-28 12:11:22 +0400
13 @@ -606,10 +606,13 @@
15 #if defined(get_term_param)
16 term_parms t;
18 - if (get_term_param (&t) < 0)
19 - fatal(2, "Can't get terminal parameters: %m");
21 + int ctl;
23 + ctl = get_term_param (&t);
24 + if (ctl < 0) {
25 + syslog(LOG_NOTICE, "Could not get FD: %s", strerror(errno));
26 + fatal(2, "Can't get terminal parameters: %m");
27 + }
28 saved_tty_parameters = t;
29 have_tty_parameters = 1;
31 --- ppp-2.4.2/etc.ppp/callback-client.vns 2004-05-28 12:11:22 +0400
32 +++ ppp-2.4.2/etc.ppp/callback-client 2004-05-28 12:11:22 +0400
33 @@ -0,0 +1,9 @@
34 +#!/bin/sh
35 +# Script callback-client
36 +# Script parameters: delay time in seconds
38 +DELAY="$1"
40 +/usr/sbin/chat -v -t 2 "" \d+++\d\c OK ATH0 OK
41 +sleep $DELAY s
42 +/usr/sbin/chat -v "" ATZ OK "" RING ATA CONNECT
43 --- ppp-2.4.2/etc.ppp/callback-server.vns 2004-05-28 12:11:22 +0400
44 +++ ppp-2.4.2/etc.ppp/callback-server 2004-05-28 12:11:22 +0400
45 @@ -0,0 +1,10 @@
46 +#!/bin/sh
47 +# Script callback-server
48 +# Script parameters: delay time in seconds, callback number
50 +DELAY="$1"
51 +NUMBER="$2"
53 +/usr/sbin/chat -v -t 2 "" \d+++\d\c OK ATH0 OK
54 +sleep $DELAY s
55 +/usr/sbin/chat -v "" ATZ OK ATD$NUMBER CONNECT
56 --- ppp-2.4.2/etc.ppp/callback-users.vns 2004-05-28 12:11:22 +0400
57 +++ ppp-2.4.2/etc.ppp/callback-users 2004-05-28 12:11:22 +0400
58 @@ -0,0 +1,10 @@
59 +# User list for callback
60 +# Username option
61 +# option - no callback
62 +# option * or empty user definied
63 +# option other admin definied: this number
64 +# in username * and ? wildcars valid, callback uses the best fit
65 +# Examples:
66 +# zotyo 67435 # user zotyo admin definied, number 67453
67 +# gates - # gates not called back
69 \ ÷ ËÏÎÃÅ ÆÁÊÌÁ ÎÅÔ ÎÏ×ÏÊ ÓÔÒÏËÉ
70 --- ppp-2.4.2/pppd/auth.c.vns 2003-06-12 03:56:26 +0400
71 +++ ppp-2.4.2/pppd/auth.c 2004-05-28 12:11:22 +0400
72 @@ -248,7 +248,6 @@
74 /* Prototypes for procedures local to this file. */
76 -static void network_phase __P((int));
77 static void check_idle __P((void *));
78 static void connect_time_expired __P((void *));
79 static int plogin __P((char *, char *, char **));
80 @@ -671,8 +670,7 @@
82 * Proceed to the network phase.
84 -static void
85 -network_phase(unit)
86 +void network_phase(unit)
87 int unit;
89 lcp_options *go = &lcp_gotoptions[unit];
90 @@ -697,7 +695,8 @@
92 * If we negotiated callback, do it now.
94 - if (go->neg_cbcp) {
95 + if (((go->neg_cbcp) || (lcp_hisoptions[unit].neg_cbcp))
96 + && (phase != PHASE_CALLBACK)) {
97 new_phase(PHASE_CALLBACK);
98 (*cbcp_protent.open)(unit);
99 return;
100 --- ppp-2.4.2/pppd/cbcp.c.vns 2003-01-31 14:11:17 +0300
101 +++ ppp-2.4.2/pppd/cbcp.c 2004-05-28 12:11:22 +0400
102 @@ -2,6 +2,7 @@
103 * cbcp - Call Back Configuration Protocol.
105 * Copyright (c) 1995 Pedro Roque Marques. All rights reserved.
106 + * Copyright (c) 2001 Bolke de Bruin
108 * Redistribution and use in source and binary forms, with or without
109 * modification, are permitted provided that the following conditions
110 @@ -39,24 +40,18 @@
111 #include <string.h>
112 #include <sys/types.h>
113 #include <sys/time.h>
114 +#include <syslog.h>
115 +#include <sys/stat.h>
117 #include "pppd.h"
118 #include "cbcp.h"
119 #include "fsm.h"
120 #include "lcp.h"
121 +#include "ipcp.h"
122 +#include "pathnames.h"
124 static const char rcsid[] = RCSID;
127 - * Options.
128 - */
129 -static int setcbcp __P((char **));
131 -static option_t cbcp_option_list[] = {
132 - { "callback", o_special, (void *)setcbcp,
133 - "Ask for callback", OPT_PRIO | OPT_A2STRVAL, &cbcp[0].us_number },
134 - { NULL }
138 * Protocol entry points.
139 @@ -84,8 +79,6 @@
141 "CBCP",
142 NULL,
143 - cbcp_option_list,
144 - NULL,
145 NULL,
146 NULL
148 @@ -94,26 +87,21 @@
150 /* internal prototypes */
152 +static void cbcp_sendreq __P((void *arg));
153 static void cbcp_recvreq __P((cbcp_state *us, u_char *pckt, int len));
154 -static void cbcp_resp __P((cbcp_state *us));
155 -static void cbcp_up __P((cbcp_state *us));
156 +static void cbcp_sendresp __P((cbcp_state *us));
157 +static void cbcp_recvresp __P((cbcp_state *us, char *pckt, int len));
158 +static void cbcp_sendack __P((void *));
159 static void cbcp_recvack __P((cbcp_state *us, u_char *pckt, int len));
160 static void cbcp_send __P((cbcp_state *us, int code, u_char *buf, int len));
161 +static void cbcp_make_options __P((int unit));
162 +static int cbcp_check_user __P((char *user, char *mask));
163 +static void cbcp_start_callback __P((cbcp_state *us));
164 +static void cbcp_up __P((cbcp_state *us));
166 -/* option processing */
167 -static int
168 -setcbcp(argv)
169 - char **argv;
171 - lcp_wantoptions[0].neg_cbcp = 1;
172 - cbcp_protent.enabled_flag = 1;
173 - cbcp[0].us_number = strdup(*argv);
174 - if (cbcp[0].us_number == 0)
175 - novm("callback number");
176 - cbcp[0].us_type |= (1 << CB_CONF_USER);
177 - cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
178 - return (1);
180 +cbcp_state *stop_iface = NULL;
182 +void (*cbcp_init_hook) __P((cbcp_state *)) = NULL;
184 /* init state */
185 static void
186 @@ -125,7 +113,6 @@
187 us = &cbcp[iface];
188 memset(us, 0, sizeof(cbcp_state));
189 us->us_unit = iface;
190 - us->us_type |= (1 << CB_CONF_NO);
193 /* lower layer is up */
194 @@ -135,18 +122,19 @@
196 cbcp_state *us = &cbcp[iface];
198 - dbglog("cbcp_lowerup");
199 - dbglog("want: %d", us->us_type);
201 - if (us->us_type == CB_CONF_USER)
202 - dbglog("phone no: %s", us->us_number);
203 + CBCPDEBUG((LOG_DEBUG, "cbcp_lowerup"));
204 + CBCPDEBUG((LOG_DEBUG, "want: %d", us->us_type));
207 +/* CBCP indulhat: kliens oldal eseten nincs feladat,
208 + szerver oldalon atkuldeni a valszthato opciokat */
209 static void
210 cbcp_open(unit)
211 int unit;
213 - dbglog("cbcp_open");
214 + CBCPDEBUG((LOG_DEBUG, "cbcp_open"));
215 + if (lcp_hisoptions[unit].neg_cbcp)
216 + cbcp_make_options(unit);
219 /* process an incomming packet */
220 @@ -161,11 +149,13 @@
221 u_short len;
223 cbcp_state *us = &cbcp[unit];
224 + lcp_options *go = &lcp_gotoptions[unit];
225 + lcp_options *his = &lcp_hisoptions[unit];
227 inp = inpacket;
229 if (pktlen < CBCP_MINLEN) {
230 - error("CBCP packet is too small");
231 + syslog(LOG_ERR, "CBCP packet is too small");
232 return;
235 @@ -175,7 +165,7 @@
237 #if 0
238 if (len > pktlen) {
239 - error("CBCP packet: invalid length");
240 + syslog(LOG_ERR, "CBCP packet: invalid length");
241 return;
243 #endif
244 @@ -184,17 +174,36 @@
246 switch(code) {
247 case CBCP_REQ:
248 + if ( !go->neg_cbcp )
250 + syslog(LOG_ERR, "CBCP received CBCP_REQ, but CBCP running in server mode!");
251 + return;
253 us->us_id = id;
254 cbcp_recvreq(us, inp, len);
255 break;
257 case CBCP_RESP:
258 - dbglog("CBCP_RESP received");
259 + if ( !his->neg_cbcp )
261 + syslog(LOG_ERR, "CBCP received CBCP_RESP, but CBCP running in client mode!");
262 + return;
264 + if (id != us->us_id)
265 + syslog(LOG_DEBUG, "id doesn't match: expected %d recv %d",
266 + us->us_id, id);
268 + cbcp_recvresp(us, inp, len);
269 break;
271 case CBCP_ACK:
272 + if ( !go->neg_cbcp )
274 + syslog(LOG_ERR, "CBCP received CBCP_ACK, but CBCP running in server mode!");
275 + return;
277 if (id != us->us_id)
278 - dbglog("id doesn't match: expected %d recv %d",
279 + syslog(LOG_DEBUG, "id doesn't match: expected %d recv %d",
280 us->us_id, id);
282 cbcp_recvack(us, inp, len);
283 @@ -274,13 +283,14 @@
284 printer(arg, " delay = %d", delay);
287 - if (olen > 3) {
288 + if (olen > 4) {
289 int addrt;
290 char str[256];
292 GETCHAR(addrt, p);
293 memcpy(str, p, olen - 4);
294 str[olen - 4] = 0;
295 + p += olen - 4;
296 printer(arg, " number = %s", str);
298 printer(arg, ">");
299 @@ -306,41 +316,40 @@
300 u_char *pckt;
301 int pcktlen;
303 - u_char type, opt_len, delay, addr_type;
304 + u_char type, opt_len, addr_type;
305 char address[256];
306 int len = pcktlen;
308 address[0] = 0;
310 while (len) {
311 - dbglog("length: %d", len);
313 GETCHAR(type, pckt);
314 GETCHAR(opt_len, pckt);
316 + us->us_delay =0;
317 if (opt_len > 2)
318 - GETCHAR(delay, pckt);
319 + GETCHAR(us->us_delay, pckt);
321 us->us_allowed |= (1 << type);
323 switch(type) {
324 case CB_CONF_NO:
325 - dbglog("no callback allowed");
326 + CBCPDEBUG((LOG_DEBUG, "no callback allowed"));
327 break;
329 case CB_CONF_USER:
330 - dbglog("user callback allowed");
331 + CBCPDEBUG((LOG_DEBUG, "user callback allowed"));
332 if (opt_len > 4) {
333 GETCHAR(addr_type, pckt);
334 memcpy(address, pckt, opt_len - 4);
335 address[opt_len - 4] = 0;
336 if (address[0])
337 - dbglog("address: %s", address);
338 + CBCPDEBUG((LOG_DEBUG, "address: %s", address));
340 break;
342 case CB_CONF_ADMIN:
343 - dbglog("user admin defined allowed");
344 + CBCPDEBUG((LOG_DEBUG, "user admin defined allowed"));
345 break;
347 case CB_CONF_LIST:
348 @@ -349,59 +358,63 @@
349 len -= opt_len;
352 - cbcp_resp(us);
353 + cbcp_sendresp(us);
356 static void
357 -cbcp_resp(us)
358 +cbcp_sendresp(us)
359 cbcp_state *us;
361 - u_char cb_type;
362 + u_char cb_allowed;
363 u_char buf[256];
364 u_char *bufp = buf;
365 int len = 0;
367 - cb_type = us->us_allowed & us->us_type;
368 - dbglog("cbcp_resp cb_type=%d", cb_type);
369 + cb_allowed = us->us_allowed;
370 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendresp: available options: %d", cb_allowed));
372 #if 0
373 - if (!cb_type)
374 + if (!cb_allowed)
375 lcp_down(us->us_unit);
376 #endif
378 - if (cb_type & ( 1 << CB_CONF_USER ) ) {
379 - dbglog("cbcp_resp CONF_USER");
380 + if (cb_allowed & ( 1 << CB_CONF_USER ) ) { /* The best metod :-) */
381 + us->us_type= ( 1 << CB_CONF_USER );
382 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendresp CONF_USER"));
383 PUTCHAR(CB_CONF_USER, bufp);
384 len = 3 + 1 + strlen(us->us_number) + 1;
385 - PUTCHAR(len , bufp);
386 - PUTCHAR(5, bufp); /* delay */
387 + PUTCHAR(len, bufp);
388 + PUTCHAR(us->us_delay, bufp);
389 PUTCHAR(1, bufp);
390 BCOPY(us->us_number, bufp, strlen(us->us_number) + 1);
391 cbcp_send(us, CBCP_RESP, buf, len);
392 return;
395 - if (cb_type & ( 1 << CB_CONF_ADMIN ) ) {
396 - dbglog("cbcp_resp CONF_ADMIN");
397 + if (cb_allowed & ( 1 << CB_CONF_ADMIN ) ) {
398 + us->us_type= ( 1 << CB_CONF_ADMIN );
399 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendresp CONF_ADMIN"));
400 PUTCHAR(CB_CONF_ADMIN, bufp);
401 len = 3;
402 PUTCHAR(len, bufp);
403 - PUTCHAR(5, bufp); /* delay */
404 + PUTCHAR(us->us_delay, bufp);
405 cbcp_send(us, CBCP_RESP, buf, len);
406 return;
409 - if (cb_type & ( 1 << CB_CONF_NO ) ) {
410 - dbglog("cbcp_resp CONF_NO");
411 + if (cb_allowed & ( 1 << CB_CONF_NO ) ) {
412 + us->us_type= ( 1 << CB_CONF_NO );
413 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendresp CONF_NO"));
414 PUTCHAR(CB_CONF_NO, bufp);
415 len = 2;
416 PUTCHAR(len , bufp);
417 cbcp_send(us, CBCP_RESP, buf, len);
418 - start_networks(us->us_unit);
419 return;
421 + syslog(LOG_WARNING, "cbcp_sendresp: no usable options available!");
424 +/* Send the packet */
425 static void
426 cbcp_send(us, code, buf, len)
427 cbcp_state *us;
428 @@ -428,38 +441,339 @@
429 output(us->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
432 +/* Received Ack */
433 static void
434 cbcp_recvack(us, pckt, len)
435 cbcp_state *us;
436 u_char *pckt;
437 int len;
439 - u_char type, delay, addr_type;
440 + u_char type, addr_type;
441 int opt_len;
442 char address[256];
444 + stop_iface = us;
446 if (len) {
447 GETCHAR(type, pckt);
448 GETCHAR(opt_len, pckt);
450 if (opt_len > 2)
451 - GETCHAR(delay, pckt);
452 + GETCHAR(us->us_delay, pckt);
454 if (opt_len > 4) {
455 GETCHAR(addr_type, pckt);
456 memcpy(address, pckt, opt_len - 4);
457 address[opt_len - 4] = 0;
458 if (address[0])
459 - dbglog("peer will call: %s", address);
460 + CBCPDEBUG((LOG_DEBUG, "peer will call: %s", address));
462 - if (type == CB_CONF_NO)
463 - return;
464 + if (type != CB_CONF_NO)
466 + callback_in_progress = us->us_unit + 1;
467 + callback_in_progress |= CBCP_CLIENT;
468 + cbcp_up(us);
470 + else
471 + network_phase(us->us_unit);
473 + else
474 + syslog(LOG_DEBUG, "cbcp: received bad ack - packet too small");
479 +/* Make options
480 + if auth req, options from callback-users file, else use CBCP_CONF_USER */
481 +static void
482 +cbcp_make_options (unit)
483 + int unit;
485 + cbcp_state *us = &cbcp[unit];
486 + FILE *userfile;
487 + struct stat sbuf;
488 + int best_fit, got_fit, newline;
489 + char uname[ 256 ], option[ 256 ];
491 + us->us_id = 1;
492 + us->us_count = 0;
493 + us->us_delay = 5; /* Default delay 5 seconds */
494 + if ( *peer_authname ) { /* Username available */
495 + userfile = fopen( _PATH_CBCP_USERS, "r" );
496 + if ( userfile == NULL ){
497 + syslog( LOG_ERR, "Can't open callback user file: %s %m",
498 + _PATH_CBCP_USERS );
499 + syslog( LOG_WARNING, "Allow user definied callback." );
500 + us->us_allowed = ( 1 << CB_CONF_USER );
501 + }else
503 + if ( fstat(fileno(userfile), &sbuf) < 0) {
504 + syslog(LOG_WARNING, "Cannot stat userfile file %s: %m",
505 + _PATH_CBCP_USERS );
506 + } else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
507 + syslog(LOG_WARNING, "Warning - user file %s has world and/or group access",
508 + _PATH_CBCP_USERS );
511 + us->us_allowed = ( 1 << CB_CONF_NO ); /* Assume, no callback allowed */
513 + if (getword(userfile, uname, &newline, _PATH_CBCP_USERS)){ /* file not empty */
514 + newline = 1;
515 + best_fit = 0;
516 + *option = 0;
517 + for (;;) {
518 + /*
519 + * Skip until we find a word at the start of a line.
520 + */
521 + while (!newline && getword(userfile, uname,
522 + &newline, _PATH_CBCP_USERS))
524 + if (!newline)
525 + break; /* got to end of file */
527 + /*
528 + * Got a user - check if it's a match or a wildcard.
529 + */
530 + got_fit = cbcp_check_user( peer_authname, uname );
531 + if ( got_fit <= best_fit ){
532 + newline = 0;
533 + continue;
536 + /* Read the options */
537 + best_fit = got_fit;
538 + if (getword(userfile, option, &newline, _PATH_CBCP_USERS))
539 + break;
541 + if ( newline )
542 + *option = 0;
544 + if ( best_fit == 100 )
545 + break;
549 + switch ( *option ){
550 + case '-' : us->us_allowed = ( 1 << CB_CONF_NO ); break;
551 + case '*' :
552 + case 0 : us->us_allowed = ( 1 << CB_CONF_USER ); break;
553 + default : us->us_allowed = ( 1 << CB_CONF_ADMIN );
554 + us->us_number = strdup( option ); break;
556 + fclose( userfile );
557 + }
559 + else
560 + us->us_allowed = ( 1 << CB_CONF_USER );
562 + if (cbcp_init_hook)
563 + cbcp_init_hook( us );
565 + cbcp_sendreq( us );
569 +/* make cbcp request packet & send it */
570 +static void
571 +cbcp_sendreq (arg)
572 + void *arg;
574 + cbcp_state *us=(cbcp_state *)arg;
575 + u_char cb_allow = us->us_allowed;
576 + u_char buf[256];
577 + u_char *bufp = buf;
578 + int len = 0;
580 + us->us_count++;
581 + if (us->us_count<=CBCP_MAXRETRY)
582 + TIMEOUT( cbcp_sendreq, arg, CBCP_DEFTIMEOUT );
583 + else
585 + lcp_close(0, "Sorry, CBCP not responding.");
586 + return;
588 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendreq cb_allowed=%d", cb_allow));
591 + if (cb_allow & ( 1 << CB_CONF_USER ) ) {
592 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendreq CONF_USER"));
593 + PUTCHAR(CB_CONF_USER, bufp);
594 + len+=3;
595 + PUTCHAR(3 , bufp);
596 + PUTCHAR(us->us_delay, bufp);
599 + if (cb_allow & ( 1 << CB_CONF_ADMIN ) ) {
600 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendreq CONF_ADMIN"));
601 + PUTCHAR(CB_CONF_ADMIN, bufp);
602 + len += 3;
603 + PUTCHAR(3 , bufp);
604 + PUTCHAR(us->us_delay, bufp);
607 + if (cb_allow & ( 1 << CB_CONF_NO ) ) {
608 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendreq CONF_NO"));
609 + PUTCHAR(CB_CONF_NO, bufp);
610 + len += 3;
611 + PUTCHAR(3 , bufp);
612 + PUTCHAR(us->us_delay, bufp);
615 + if (len)
616 + cbcp_send(us, CBCP_REQ, buf, len);
617 + else
619 + syslog(LOG_WARNING, "cbcp: no available options to client!");
620 + }
623 +/* Received CBCP response, make ACK */
624 +static void
625 +cbcp_recvresp (us, pckt, len)
626 + cbcp_state *us;
627 + char *pckt;
628 + int len;
630 + u_char type, addr_type;
631 + int opt_len;
632 + char address[256];
634 + if (len) {
635 + GETCHAR(type, pckt);
636 + GETCHAR(opt_len, pckt);
638 + if (!(( 1 << type )& us->us_allowed )) {
639 + CBCPDEBUG((LOG_DEBUG, "CBCP received options not allowed on server!"));
640 + return;
643 + if ((type!= CB_CONF_NO ) &&
644 + (type!= CB_CONF_USER ) &&
645 + (type!= CB_CONF_ADMIN )) {
646 + syslog(LOG_DEBUG, "CBCP received BAD Response: too more or unknown options %d",type);
647 + return;
650 + UNTIMEOUT( cbcp_sendreq, us );
651 + us->us_count = 0;
654 + if (opt_len > 2)
655 + GETCHAR(us->us_delay, pckt)
656 + if ( us->us_delay < 5 )
657 + us->us_delay = 5;
659 + if (opt_len > 4) {
660 + GETCHAR(addr_type, pckt); /* Address Type mezo elvesztve !!! */
661 + memcpy(address, pckt, opt_len - 4);
662 + address[opt_len - 4] = 0;
663 + if (address[0])
664 + syslog(LOG_DEBUG, "peer will callback the client on: %s", address);
665 + us->us_number=strdup( address );
668 + us->us_type = ( 1 << type );
669 + cbcp_sendack( us );
671 + else
673 + syslog(LOG_DEBUG, "CBCP received BAD Response: size to small");
677 +/* Send the CBCP_ACK packet */
678 +static void
679 +cbcp_sendack (arg)
680 + void *arg;
682 + cbcp_state *us= (cbcp_state *)arg;
683 + u_char cb_type;
684 + u_char buf[256];
685 + u_char *bufp = buf;
686 + int len = 0;
688 + stop_iface = (cbcp_state *)arg;
689 + cb_type = us->us_type;
691 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendack cb_type=%d", cb_type));
693 + us->us_count++;
694 + if (us->us_count<=CBCP_MAXRETRY)
695 + TIMEOUT( cbcp_sendack, arg, CBCP_DEFTIMEOUT );
696 + else
698 + lcp_close(0, "Sorry, CBCP not responding.");
699 + return;
702 +#if 0
703 + if (!cb_type)
704 + lcp_down(us->us_unit);
705 +#endif
707 + if (cb_type == (1 << CB_CONF_USER )) {
708 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendack CONF_USER"));
709 + PUTCHAR(CB_CONF_USER, bufp);
710 + len = 3 + 1 + strlen(us->us_number) + 1;
711 + PUTCHAR(len , bufp);
712 + PUTCHAR(us->us_delay, bufp); /* delay */
713 + PUTCHAR(1, bufp); /* Elvesztett byte... */
714 + BCOPY(us->us_number, bufp, strlen(us->us_number) + 1);
715 + cbcp_send(us, CBCP_ACK, buf, len);
716 +/* lcp_close( 2, "Illegal, but required to server..." ); */
717 + callback_in_progress = us->us_unit + 1;
718 + return;
721 + if (cb_type == (1 << CB_CONF_ADMIN )) {
722 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendack CONF_ADMIN"));
723 + PUTCHAR(CB_CONF_ADMIN, bufp);
724 + len = 3;
725 + PUTCHAR(len , bufp);
726 + PUTCHAR(us->us_delay, bufp); /* delay */
727 + PUTCHAR(0, bufp);
728 + cbcp_send(us, CBCP_ACK, buf, len);
729 +/* lcp_close( 2, "Illegal, but required to server..." ); */
730 + callback_in_progress = us->us_unit + 1;
731 + return;
734 + if (cb_type == (1 << CB_CONF_NO )) {
735 + CBCPDEBUG((LOG_DEBUG, "cbcp_sendack CONF_NO"));
736 + PUTCHAR(CB_CONF_NO, bufp);
737 + len = 3;
738 + PUTCHAR(len , bufp);
739 + PUTCHAR(0, bufp);
740 + cbcp_send(us, CBCP_ACK, buf, len);
741 + if (us->us_count<=1)
742 + network_phase(us->us_unit);
743 + return;
746 + syslog(LOG_DEBUG, "CBCP - Bad options in Ack routine.");
748 - cbcp_up(us);
751 -/* ok peer will do callback */
752 +/* CBCP coming succesful up */
753 +void cbcp_stop()
755 + if ( stop_iface && lcp_allowoptions[stop_iface->us_unit].neg_cbcp )
757 + UNTIMEOUT( cbcp_sendack, stop_iface );
758 + cbcp_start_callback( stop_iface );
762 +/* The server side coming up & client 'ack-ed' */
763 +void cbcp_start_callback (us)
764 + cbcp_state *us;
766 + lcp_allowoptions[us->us_unit].neg_cbcp=0;
768 + CBCPDEBUG((LOG_DEBUG, "cbcp_start_callback running"));
771 +/* The client side coming up: server allowed the callback */
772 static void
773 cbcp_up(us)
774 cbcp_state *us;
775 @@ -467,4 +781,93 @@
776 persist = 0;
777 lcp_close(0, "Call me back, please");
778 status = EXIT_CALLBACK;
779 + lcp_wantoptions[us->us_unit].neg_cbcp=0;
780 + CBCPDEBUG((LOG_DEBUG, "cbcp_up called"));
781 + lcp_close(us->us_unit, "Call me back, please");
784 +/* The main module gets the script with parameters to run */
785 +char *cbcp_get_script()
787 + cbcp_state *us = &cbcp[(callback_in_progress & CBCP_NCLIENT)-1];
788 + char script[ 256 ];
790 + if ( callback_in_progress & CBCP_CLIENT )
791 + sprintf( script, "%s %d", _PATH_CBCP_CLIENT, us->us_delay );
792 + else
793 + sprintf( script, "%s %d %s", _PATH_CBCP_SERVER,
794 + us->us_delay, us->us_number );
796 + return strdup( script );
799 +/* give me the hit rate. wild cars '*?' valids */
800 +int cbcp_check_user ( user, mask )
801 + char *user;
802 + char *mask;
804 + char *curr_user = user;
805 + char *curr_mask = mask;
806 + char *find, backp = 0;
807 + int count, len = 0;
809 + if ( !strcasecmp( user, mask ))
810 + return 100;
812 + if ( !strcmp( mask, "*" ))
813 + return 1;
815 + if ( !*user )
816 + return 0;
818 + count = 0;
820 + while(( find = strpbrk( curr_mask, "*?" )) != 0 ) {
821 + if ( find != curr_mask ){
822 + len = find - curr_mask;
823 + if ( strncmp( curr_user, curr_mask, len ))
824 + break;
827 + curr_mask += len + 1;
828 + curr_user += len;
829 + count += len;
830 + if ( *curr_user == 0 )
831 + break;
833 + if ( *find == '?' ) {
834 + curr_user++;
835 + if ( *curr_user == 0 )
836 + break;
837 + } else {
838 + if ( *curr_mask == 0 )
839 + break;
841 + if ( ( find = strpbrk( curr_mask, "*?" )) != 0 ){
842 + backp = *find;
843 + *find = 0;
845 + curr_user = strstr( curr_user, curr_mask );
846 + if ( find )
847 + *find = backp;
848 + if ( !curr_user )
849 + break;
851 + find = strpbrk( curr_mask, "*?" );
852 + if ( find )
853 + len = find - curr_mask;
854 + else
855 + len = strlen( curr_mask );
857 + curr_mask += len;
858 + curr_user += len;
859 + count += len;
860 + }
863 + if ( *curr_user && *curr_mask && !strcmp( curr_user, curr_mask ))
864 + count += strlen( curr_user );
866 + return ( count * 100 / strlen( user ) );
869 --- ppp-2.4.2/pppd/cbcp.h.vns 1998-11-07 09:55:38 +0300
870 +++ ppp-2.4.2/pppd/cbcp.h 2004-05-28 12:11:22 +0400
871 @@ -6,6 +6,8 @@
872 u_char us_id; /* Current id */
873 u_char us_allowed;
874 int us_type;
875 + u_char us_delay;
876 + u_char us_count;
877 char *us_number; /* Telefone Number */
878 } cbcp_state;
880 @@ -19,8 +21,19 @@
881 #define CBCP_RESP 2
882 #define CBCP_ACK 3
884 +#define CBCP_DEFTIMEOUT 5
885 +#define CBCP_MAXRETRY 50
886 +#define CBCP_CLIENT 0x8000
887 +#define CBCP_NCLIENT 0x7fff
889 +#define CBCPDEBUG(x) /*if (debug)*/ syslog x
891 #define CB_CONF_NO 1
892 #define CB_CONF_USER 2
893 #define CB_CONF_ADMIN 3
894 #define CB_CONF_LIST 4
896 +char *cbcp_get_script __P(());
897 +void cbcp_stop __P(());
899 #endif
900 --- ppp-2.4.2/pppd/ipcp.c.vns 2004-05-28 12:11:22 +0400
901 +++ ppp-2.4.2/pppd/ipcp.c 2004-05-28 12:11:22 +0400
902 @@ -61,6 +61,10 @@
903 #include "ipcp.h"
904 #include "pathnames.h"
906 +#ifdef CBCP_SUPPORT
907 +#include "cbcp.h"
908 +#endif
910 static const char rcsid[] = RCSID;
912 /* global vars */
913 @@ -1320,6 +1324,9 @@
914 u_char maxslotindex, cflag;
915 int d;
917 +#ifdef CBCP_SUPPORT
918 + cbcp_stop();
919 +#endif
921 * Reset all his options.
923 --- ppp-2.4.2/pppd/ipv6cp.c.vns 2004-01-13 06:59:37 +0300
924 +++ ppp-2.4.2/pppd/ipv6cp.c 2004-05-28 12:11:22 +0400
925 @@ -167,6 +167,10 @@
926 #include "magic.h"
927 #include "pathnames.h"
929 +#ifdef CBCP_SUPPORT
930 +#include "cbcp.h"
931 +#endif
933 static const char rcsid[] = RCSID;
935 /* global vars */
936 @@ -900,6 +904,10 @@
937 u_char *ucp = inp; /* Pointer to current output char */
938 int l = *len; /* Length left */
940 +#ifdef CBCP_SUPPORT
941 + cbcp_stop();
942 +#endif
945 * Reset all his options.
947 --- ppp-2.4.2/pppd/ipxcp.c.vns 2003-11-18 13:42:56 +0300
948 +++ ppp-2.4.2/pppd/ipxcp.c 2004-05-28 12:11:22 +0400
949 @@ -62,6 +62,10 @@
950 #include "pathnames.h"
951 #include "magic.h"
953 +#ifdef CBCP_SUPPORT
954 +#include "cbcp.h"
955 +#endif
957 static const char rcsid[] = RCSID;
959 /* global vars */
960 @@ -998,6 +1002,10 @@
961 u_char *ucp = inp; /* Pointer to current output char */
962 int l = *len; /* Length left */
964 +#ifdef CBCP_SUPPORT
965 + cbcp_stop();
966 +#endif
969 * Reset all his options.
971 --- ppp-2.4.2/pppd/lcp.c.vns 2003-11-18 13:42:56 +0300
972 +++ ppp-2.4.2/pppd/lcp.c 2004-05-28 12:11:22 +0400
973 @@ -365,9 +365,7 @@
974 ao->neg_magicnumber = 1;
975 ao->neg_pcompression = 1;
976 ao->neg_accompression = 1;
977 -#ifdef CBCP_SUPPORT
978 - ao->neg_cbcp = 1;
979 -#endif
980 + ao->neg_cbcp = 0;
981 ao->neg_endpoint = 1;
984 @@ -1769,6 +1767,16 @@
985 ho->neg_accompression = 1;
986 break;
988 + case CI_CALLBACK:
989 + LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd CALLBACK"));
990 + if (!ao->neg_cbcp ||
991 + cilen != CILEN_CHAR ) {
992 + orc = CONFREJ;
993 + break;
995 + ho->neg_cbcp = 1;
996 + break;
998 case CI_MRRU:
999 if (!ao->neg_mrru || !multilink ||
1000 cilen != CILEN_SHORT) {
1001 --- ppp-2.4.2/pppd/main.c.vns 2004-01-13 07:00:34 +0300
1002 +++ ppp-2.4.2/pppd/main.c 2004-05-28 12:11:22 +0400
1003 @@ -156,6 +156,10 @@
1004 char **script_env; /* Env. variable values for scripts */
1005 int s_env_nalloc; /* # words avail at script_env */
1007 +#ifdef CBCP_SUPPORT
1008 +int callback_in_progress; /* Callback running */
1009 +#endif
1011 u_char outpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for outgoing packet */
1012 u_char inpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for incoming packet */
1014 @@ -276,6 +280,10 @@
1015 int i, t;
1016 char *p;
1017 struct passwd *pw;
1018 +#ifdef CBCP_SUPPORT
1019 + char *connector;
1020 +#endif
1022 struct protent *protp;
1023 char numbuf[16];
1025 @@ -540,6 +548,10 @@
1027 add_fd(fd_ppp);
1028 lcp_open(0); /* Start protocol */
1029 +#ifdef CBCP_SUPPORT
1030 + for(callback_in_progress=1;callback_in_progress;){
1031 + callback_in_progress=0;
1032 +#endif
1033 status = EXIT_NEGOTIATION_FAILED;
1034 new_phase(PHASE_ESTABLISH);
1035 while (phase != PHASE_DEAD) {
1036 @@ -568,7 +580,75 @@
1037 warn("unable to delete pid file %s: %m", pidfilename);
1038 pidfilename[0] = 0;
1040 +#ifdef CBCP_SUPPORT
1041 + if (callback_in_progress){
1042 + connector = NULL;
1043 + cbcp_stop();
1044 + remove_fd(fd_ppp);
1045 + clean_check();
1046 + the_channel->disestablish_ppp(devfd);
1047 + fd_ppp = -1;
1049 + if (!hungup){
1050 + lcp_lowerdown(0);
1051 + } else {
1052 + tty_close_fds();
1053 + setup_serial(connector);
1057 + devfd = callback();
1059 + /* set up the serial device as a ppp interface */
1060 + tdb_writelock(pppdb);
1061 + fd_ppp = the_channel->establish_ppp(devfd);
1062 + if (fd_ppp < 0) {
1063 + tdb_writeunlock(pppdb);
1064 + status = EXIT_FATAL_ERROR;
1065 + goto disconnect;
1068 + if (!demand && ifunit >= 0)
1069 + set_ifunit(1);
1070 + tdb_writeunlock(pppdb);
1072 + /*
1073 + * Start opening the connection and wait for
1074 + * incoming events (reply, timeout, etc.).
1075 + */
1076 + notice("Connect: %s <--> %s", ifname, ppp_devnam);
1077 + gettimeofday(&start_time, NULL);
1078 + link_stats_valid = 0;
1079 + script_unsetenv("CONNECT_TIME");
1080 + script_unsetenv("BYTES_SENT");
1081 + script_unsetenv("BYTES_RCVD");
1082 + lcp_lowerup(0);
1084 + /*
1085 + * If we are initiating this connection, wait for a short
1086 + * time for something from the peer. This can avoid bouncing
1087 + * our packets off his tty before he has it set up.
1088 + */
1089 + add_fd(fd_ppp);
1090 + if (listen_time != 0) {
1091 + struct timeval t;
1092 + t.tv_sec = listen_time / 1000;
1093 + t.tv_usec = listen_time % 1000;
1094 + wait_input(&t);
1097 + /*if (connector != NULL || ptycommand != NULL) {
1098 + struct timeval t;
1099 + t.tv_sec = 1;
1100 + t.tv_usec = 0;
1101 + wait_input(&t);
1102 + }*/
1104 + lcp_open(0); /* Start protocol */
1106 + }
1107 +#endif
1110 * If we may want to bring the link up again, transfer
1111 * the ppp unit back to the loopback. Set the
1112 --- ppp-2.4.2/pppd/options.c.vns 2004-01-13 07:02:07 +0300
1113 +++ ppp-2.4.2/pppd/options.c 2004-05-28 12:11:22 +0400
1114 @@ -66,6 +66,12 @@
1115 char *strdup __P((char *));
1116 #endif
1118 +#ifdef CBCP_SUPPORT
1119 +#include "fsm.h"
1120 +#include "lcp.h"
1121 +#include "cbcp.h"
1122 +#endif
1124 static const char rcsid[] = RCSID;
1126 struct option_value {
1127 @@ -162,6 +168,10 @@
1128 static int n_arguments __P((option_t *));
1129 static int number_option __P((char *, u_int32_t *, int));
1131 +#ifdef CBCP_SUPPORT
1132 +static int setcbcp __P((char **));
1133 +#endif
1136 * Structure to store extra lists of options.
1138 @@ -309,6 +319,11 @@
1139 "Check for traffic limit every N seconds", OPT_PRIO | OPT_LLIMIT | 1 },
1140 #endif
1142 +#ifdef CBCP_SUPPORT
1143 + { "callback", o_special, setcbcp,
1144 + "Callback request to server - OR - calling back the client" },
1145 +#endif
1147 { NULL }
1150 @@ -1586,3 +1601,23 @@
1151 return 0;
1153 #endif /* PLUGIN */
1155 +#ifdef CBCP_SUPPORT
1156 +static int
1157 +setcbcp(argv)
1158 + char **argv;
1160 + cbcp[0].us_number = strdup(*argv);
1161 + if (cbcp_protent.enabled_flag)
1162 + novm("Only one callback parameter supported!");
1163 + if (cbcp[0].us_number == 0)
1164 + novm("callback number");
1165 + if (!strcmp(cbcp[0].us_number,"server")){
1166 + lcp_allowoptions[0].neg_cbcp = 1;
1167 + } else {
1168 + lcp_wantoptions[0].neg_cbcp = 1;
1170 + cbcp_protent.enabled_flag = 1;
1171 + return 1;
1173 +#endif
1174 --- ppp-2.4.2/pppd/pathnames.h.vns 2002-11-09 14:24:42 +0300
1175 +++ ppp-2.4.2/pppd/pathnames.h 2004-05-28 12:11:22 +0400
1176 @@ -44,6 +44,13 @@
1177 #define _PATH_IPXDOWN _ROOT_PATH "/etc/ppp/ipx-down"
1178 #endif /* IPX_CHANGE */
1180 +#ifdef CBCP_SUPPORT
1181 +#define _PATH_CBCP_SERVER _ROOT_PATH "/etc/ppp/callback-server"
1182 +#define _PATH_CBCP_CLIENT _ROOT_PATH "/etc/ppp/callback-client"
1183 +#define _PATH_CBCP_USERS _ROOT_PATH "/etc/ppp/callback-users"
1184 +#define _PATH_CBCP _ROOT_PATH "/etc/ppp/callback"
1185 +#endif /* CBCP_SUPPORT */
1187 #ifdef __STDC__
1188 #define _PATH_PPPDB _ROOT_PATH _PATH_VARRUN "pppd.tdb"
1189 #else /* __STDC__ */
1190 --- ppp-2.4.2/pppd/pppd.8.vns 2004-01-15 08:09:00 +0300
1191 +++ ppp-2.4.2/pppd/pppd.8 2004-05-28 12:11:22 +0400
1192 @@ -87,6 +87,14 @@
1193 or include .. as a pathname component. The format of the options file
1194 is described below.
1196 +.B callback \fIserver/number
1197 +When compiled with the CBCP extensions (-DCBCP_SUPPORT) the ppp daemon
1198 +can act as a client to servers which provide CBCP-protocol callback
1199 +negotiation or act as a \fIserver. It reads its options from
1200 +/etc/ppp/callback-users and invokes /etc/ppp/callback-server
1201 +when dialing out. Otherwise it will invoke /etc/ppp/callback-client
1202 +to wait for a call.
1203 +.TP
1204 .B connect \fIscript
1205 Usually there is something which needs to be done to prepare the link
1206 before the PPP protocol can be started; for instance, with a dial-up
1207 --- ppp-2.4.2/pppd/pppd.h.vns 2003-04-07 04:01:46 +0400
1208 +++ ppp-2.4.2/pppd/pppd.h 2004-05-28 12:11:22 +0400
1209 @@ -71,6 +71,9 @@
1210 #include "eui64.h"
1211 #endif
1213 +/* for cbcp_init_hook */
1214 +#include "cbcp.h"
1217 * Limits.
1219 @@ -331,6 +334,10 @@
1220 extern struct bpf_program active_filter; /* Filter for link-active pkts */
1221 #endif
1223 +#ifdef CBCP_SUPPORT
1224 +extern int callback_in_progress; /*Callback running*/
1225 +#endif
1227 #ifdef MSLANMAN
1228 extern bool ms_lanman; /* Use LanMan password instead of NT */
1229 /* Has meaning only with MS-CHAP challenges */
1230 @@ -485,6 +492,8 @@
1232 /* Procedures exported from tty.c. */
1233 void tty_init __P((void));
1234 +void setup_serial __P((char *));
1235 +int callback __P ((void));
1237 /* Procedures exported from utils.c. */
1238 void log_packet __P((u_char *, int, char *, int));
1239 @@ -510,6 +519,7 @@
1240 /* read a complete buffer */
1242 /* Procedures exported from auth.c */
1243 +void network_phase __P((int)); /* the dataexchanger CP-s goung up */
1244 void link_required __P((int)); /* we are starting to use the link */
1245 void link_terminated __P((int)); /* we are finished with the link */
1246 void link_down __P((int)); /* the LCP layer has left the Opened state */
1247 @@ -685,6 +695,7 @@
1248 extern void (*ip_up_hook) __P((void));
1249 extern void (*ip_down_hook) __P((void));
1250 extern void (*ip_choose_hook) __P((u_int32_t *));
1251 +extern void (*cbcp_init_hook) __P((cbcp_state *));
1253 extern int (*chap_check_hook) __P((void));
1254 extern int (*chap_passwd_hook) __P((char *user, char *passwd));
1255 --- ppp-2.4.2/pppd/tty.c.vns 2004-01-13 07:17:59 +0300
1256 +++ ppp-2.4.2/pppd/tty.c 2004-05-28 12:15:32 +0400
1257 @@ -101,6 +101,9 @@
1258 #include "pppd.h"
1259 #include "fsm.h"
1260 #include "lcp.h"
1261 +#ifdef CBCP_SUPPORT
1262 +#include "cbcp.h"
1263 +#endif /* CBCP_SUPPORT */
1265 void tty_process_extra_options __P((void));
1266 void tty_check_options __P((void));
1267 @@ -131,6 +134,8 @@
1268 static int ttyfd; /* Serial port file descriptor */
1269 static char speed_str[16]; /* Serial port speed as string */
1271 +/*static void setup_serial __P();*/
1273 mode_t tty_mode = (mode_t)-1; /* Original access permissions to tty */
1274 int baud_rate; /* Actual bits/second for serial device */
1275 char *callback_script; /* script for doing callback */
1276 @@ -511,10 +516,10 @@
1277 int connect_tty()
1279 char *connector;
1280 - int fdflags;
1281 - struct stat statbuf;
1282 char numbuf[16];
1284 + connector = doing_callback? callback_script: connect_script;
1287 * Get a pty master/slave pair if the pty, notty, socket,
1288 * or record options were specified.
1289 @@ -542,72 +547,7 @@
1290 locked = 1;
1293 - /*
1294 - * Open the serial device and set it up to be the ppp interface.
1295 - * First we open it in non-blocking mode so we can set the
1296 - * various termios flags appropriately. If we aren't dialling
1297 - * out and we want to use the modem lines, we reopen it later
1298 - * in order to wait for the carrier detect signal from the modem.
1299 - */
1300 - hungup = 0;
1301 - kill_link = 0;
1302 - connector = doing_callback? callback_script: connect_script;
1303 - if (devnam[0] != 0) {
1304 - for (;;) {
1305 - /* If the user specified the device name, become the
1306 - user before opening it. */
1307 - int err, prio;
1309 - prio = privopen? OPRIO_ROOT: tty_options[0].priority;
1310 - if (prio < OPRIO_ROOT)
1311 - seteuid(uid);
1312 - ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
1313 - err = errno;
1314 - if (prio < OPRIO_ROOT)
1315 - seteuid(0);
1316 - if (ttyfd >= 0)
1317 - break;
1318 - errno = err;
1319 - if (err != EINTR) {
1320 - error("Failed to open %s: %m", devnam);
1321 - status = EXIT_OPEN_FAILED;
1323 - if (!persist || err != EINTR)
1324 - return -1;
1326 - real_ttyfd = ttyfd;
1327 - if ((fdflags = fcntl(ttyfd, F_GETFL)) == -1
1328 - || fcntl(ttyfd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
1329 - warn("Couldn't reset non-blocking mode on device: %m");
1331 -#ifndef __linux__
1332 - /*
1333 - * Linux 2.4 and above blocks normal writes to the tty
1334 - * when it is in PPP line discipline, so this isn't needed.
1335 - */
1336 - /*
1337 - * Do the equivalent of `mesg n' to stop broadcast messages.
1338 - */
1339 - if (fstat(ttyfd, &statbuf) < 0
1340 - || fchmod(ttyfd, statbuf.st_mode & ~(S_IWGRP | S_IWOTH)) < 0) {
1341 - warn("Couldn't restrict write permissions to %s: %m", devnam);
1342 - } else
1343 - tty_mode = statbuf.st_mode;
1344 -#endif /* __linux__ */
1346 - /*
1347 - * Set line speed, flow control, etc.
1348 - * If we have a non-null connection or initializer script,
1349 - * on most systems we set CLOCAL for now so that we can talk
1350 - * to the modem before carrier comes up. But this has the
1351 - * side effect that we might miss it if CD drops before we
1352 - * get to clear CLOCAL below. On systems where we can talk
1353 - * successfully to the modem with CLOCAL clear and CD down,
1354 - * we could clear CLOCAL at this point.
1355 - */
1356 - set_up_tty(ttyfd, ((connector != NULL && connector[0] != 0)
1357 - || initializer != NULL));
1359 + setup_serial(connector);
1362 * If the pty, socket, notty and/or record option was specified,
1363 @@ -736,6 +676,113 @@
1364 return ttyfd;
1367 +void setup_serial(char *connector)
1369 + int fdflags;
1370 + struct stat statbuf;
1372 + /*
1373 + * Open the serial device and set it up to be the ppp interface.
1374 + * First we open it in non-blocking mode so we can set the
1375 + * various termios flags appropriately. If we aren't dialling
1376 + * out and we want to use the modem lines, we reopen it later
1377 + * in order to wait for the carrier detect signal from the modem.
1378 + */
1379 + hungup = 0;
1380 + kill_link = 0;
1381 + connector = doing_callback? callback_script: connect_script;
1382 + if (devnam[0] != 0) {
1383 + for (;;) {
1384 + /* If the user specified the device name, become the
1385 + user before opening it. */
1386 + int err, prio;
1388 + prio = privopen? OPRIO_ROOT: tty_options[0].priority;
1389 + if (prio < OPRIO_ROOT)
1390 + seteuid(uid);
1391 + ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
1392 + err = errno;
1393 + if (prio < OPRIO_ROOT)
1394 + seteuid(0);
1395 + if (ttyfd >= 0)
1396 + break;
1397 + errno = err;
1398 + if (err != EINTR) {
1399 + error("Failed to open %s: %m", devnam);
1400 + status = EXIT_OPEN_FAILED;
1402 + if (!persist || err != EINTR)
1403 + return -1;
1405 + real_ttyfd = ttyfd;
1406 + if ((fdflags = fcntl(ttyfd, F_GETFL)) == -1
1407 + || fcntl(ttyfd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
1408 + warn("Couldn't reset non-blocking mode on device: %m");
1410 + /*
1411 + * Do the equivalent of `mesg n' to stop broadcast messages.
1412 + */
1413 + if (fstat(ttyfd, &statbuf) < 0
1414 + || fchmod(ttyfd, statbuf.st_mode & ~(S_IWGRP | S_IWOTH)) < 0) {
1415 + warn("Couldn't restrict write permissions to %s: %m", devnam);
1416 + } else
1417 + tty_mode = statbuf.st_mode;
1419 + /*
1420 + * Set line speed, flow control, etc.
1421 + * If we have a non-null connection or initializer script,
1422 + * on most systems we set CLOCAL for now so that we can talk
1423 + * to the modem before carrier comes up. But this has the
1424 + * side effect that we might miss it if CD drops before we
1425 + * get to clear CLOCAL below. On systems where we can talk
1426 + * successfully to the modem with CLOCAL clear and CD down,
1427 + * we could clear CLOCAL at this point.
1428 + */
1429 + set_up_tty(ttyfd, ((connector != NULL && connector[0] != 0)
1430 + || initializer != NULL));
1434 +#ifdef CBCP_SUPPORT
1435 +int callback()
1437 + char *s;
1438 + char numbuf[16];
1440 + cbcp_protent.enabled_flag = 0; /* Already not need */
1441 + s = cbcp_get_script();
1442 + syslog(LOG_INFO, "Callback with <%s>",s );
1444 + set_up_tty( ttyfd, 1 );
1446 + if (real_ttyfd != -1) {
1447 + if (!default_device && modem) {
1448 + setdtr(real_ttyfd, 0); /* in case modem is off hook */
1449 + sleep(1);
1450 + setdtr(real_ttyfd, 1);
1454 + /* syslog(LOG_INFO, "ttyfd is %d and hungup is %d",ttyfd,hungup ); */
1455 + if (device_script(s, ttyfd, ttyfd, 0) < 0) {
1456 + error("Callback script failed");
1457 + status = EXIT_INIT_FAILED;
1458 + setdtr(ttyfd, 0 );
1459 + return -1;
1462 + info("Serial connection established." );
1464 + if (real_ttyfd != -1)
1465 + set_up_tty( real_ttyfd, 0 );
1467 + slprintf(numbuf, sizeof(numbuf), "%d", baud_rate);
1468 + script_setenv("SPEED", numbuf, 1);
1470 + return ttyfd;
1473 +#endif /* CBCP Support */
1475 void disconnect_tty()