X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmain.c;h=409628c4b0a03383d7647d32be1993851f7cce63;hp=6541a3be3c472d208f43059ba8f74e3f88431425;hb=690865e93221a67d2ee33f4d184a8be79c3fc7ec;hpb=215baf28fc53e909b987a4b31d7d25ecd4ee7a71 diff --git a/pppd/main.c b/pppd/main.c index 6541a3b..409628c 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -17,7 +17,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: main.c,v 1.109 2002/01/11 18:10:16 etbe Exp $" +#define RCSID "$Id: main.c,v 1.117 2002/10/27 12:04:07 fcusack Exp $" #include #include @@ -53,8 +53,12 @@ #include "upap.h" #include "chap.h" #include "ccp.h" +#include "ecp.h" #include "pathnames.h" + +#ifdef USE_TDB #include "tdb.h" +#endif #ifdef CBCP_SUPPORT #include "cbcp.h" @@ -94,11 +98,18 @@ volatile int status; /* exit status for pppd */ int unsuccess; /* # unsuccessful connection attempts */ int do_callback; /* != 0 if we should do callback next */ int doing_callback; /* != 0 if we are doing callback */ +int ppp_session_number; /* Session number, for channels with such a + concept (eg PPPoE) */ +#ifdef USE_TDB TDB_CONTEXT *pppdb; /* database for storing status etc. */ +#endif + char db_key[32]; int (*holdoff_hook) __P((void)) = NULL; int (*new_phase_hook) __P((int)) = NULL; +void (*snoop_recv_hook) __P((unsigned char *p, int len)) = NULL; +void (*snoop_send_hook) __P((unsigned char *p, int len)) = NULL; static int conn_running; /* we have a [dis]connector running */ static int devfd; /* fd of underlying device */ @@ -170,10 +181,14 @@ static void open_ccp __P((int)); static void bad_signal __P((int)); static void holdoff_end __P((void *)); static int reap_kids __P((int waitfor)); + +#ifdef USE_TDB static void update_db_entry __P((void)); static void add_db_key __P((const char *)); static void delete_db_key __P((const char *)); static void cleanup_db __P((void)); +#endif + static void handle_events __P((void)); static void print_link_stats __P((void)); @@ -207,6 +222,7 @@ struct protent *protocols[] = { &ipv6cp_protent, #endif &ccp_protent, + &ecp_protent, #ifdef IPX_CHANGE &ipxcp_protent, #endif @@ -344,15 +360,25 @@ main(argc, argv) init_pr_log(NULL, LOG_INFO); print_options(pr_log, NULL); end_pr_log(); - if (dryrun) - die(0); } + /* + * Early check for remote number authorization. + */ + if (!auth_number()) { + warn("calling number %q is not authorized", remote_number); + exit(EXIT_CNID_AUTH_FAILED); + } + + if (dryrun) + die(0); + /* * Initialize system-dependent stuff. */ sys_init(); +#ifdef USE_TDB pppdb = tdb_open(_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644); if (pppdb != NULL) { slprintf(db_key, sizeof(db_key), "pppd%d", getpid()); @@ -364,6 +390,7 @@ main(argc, argv) multilink = 0; } } +#endif /* * Detach ourselves from the terminal, if required, @@ -400,11 +427,14 @@ main(argc, argv) /* * Open the loopback channel and set it up to be the ppp interface. */ +#ifdef USE_TDB tdb_writelock(pppdb); +#endif fd_loop = open_ppp_loopback(); set_ifunit(1); +#ifdef USE_TDB tdb_writeunlock(pppdb); - +#endif /* * Configure the interface and mark it up, etc. */ @@ -454,17 +484,23 @@ main(argc, argv) goto fail; /* set up the serial device as a ppp interface */ +#ifdef USE_TDB tdb_writelock(pppdb); +#endif fd_ppp = the_channel->establish_ppp(devfd); if (fd_ppp < 0) { +#ifdef USE_TDB tdb_writeunlock(pppdb); +#endif status = EXIT_FATAL_ERROR; goto disconnect; } if (!demand && ifunit >= 0) set_ifunit(1); +#ifdef USE_TDB tdb_writeunlock(pppdb); +#endif /* * Start opening the connection and wait for @@ -944,6 +980,7 @@ get_input() } dump_packet("rcvd", p, len); + if (snoop_recv_hook) snoop_recv_hook(p, len); p += 2; /* Skip address and control */ GETSHORT(protocol, p); @@ -1042,8 +1079,11 @@ cleanup() warn("unable to delete pid file %s: %m", linkpidfile); linkpidfile[0] = 0; +#ifdef USE_TDB if (pppdb != NULL) cleanup_db(); +#endif + } void @@ -1076,11 +1116,11 @@ update_link_stats(u) link_connect_time = now.tv_sec - start_time.tv_sec; link_stats_valid = 1; - slprintf(numbuf, sizeof(numbuf), "%d", link_connect_time); + slprintf(numbuf, sizeof(numbuf), "%u", link_connect_time); script_setenv("CONNECT_TIME", numbuf, 0); - slprintf(numbuf, sizeof(numbuf), "%d", link_stats.bytes_out); + slprintf(numbuf, sizeof(numbuf), "%u", link_stats.bytes_out); script_setenv("BYTES_SENT", numbuf, 0); - slprintf(numbuf, sizeof(numbuf), "%d", link_stats.bytes_in); + slprintf(numbuf, sizeof(numbuf), "%u", link_stats.bytes_in); script_setenv("BYTES_RCVD", numbuf, 0); } @@ -1641,7 +1681,7 @@ remove_notifier(notif, func, arg) } /* - * notify - call a set of functions registered with add_notify. + * notify - call a set of functions registered with add_notifier. */ void notify(notif, val) @@ -1690,13 +1730,17 @@ script_setenv(var, value, iskey) if (script_env != 0) { for (i = 0; (p = script_env[i]) != 0; ++i) { if (strncmp(p, var, varl) == 0 && p[varl] == '=') { +#ifdef USE_TDB if (p[-1] && pppdb != NULL) delete_db_key(p); +#endif free(p-1); script_env[i] = newstring; +#ifdef USE_TDB if (iskey && pppdb != NULL) add_db_key(newstring); update_db_entry(); +#endif return; } } @@ -1723,11 +1767,13 @@ script_setenv(var, value, iskey) script_env[i] = newstring; script_env[i+1] = 0; +#ifdef USE_TDB if (pppdb != NULL) { if (iskey) add_db_key(newstring); update_db_entry(); } +#endif } /* @@ -1746,18 +1792,23 @@ script_unsetenv(var) return; for (i = 0; (p = script_env[i]) != 0; ++i) { if (strncmp(p, var, vl) == 0 && p[vl] == '=') { +#ifdef USE_TDB if (p[-1] && pppdb != NULL) delete_db_key(p); +#endif free(p-1); while ((script_env[i] = script_env[i+1]) != 0) ++i; break; } } +#ifdef USE_TDB if (pppdb != NULL) update_db_entry(); +#endif } +#ifdef USE_TDB /* * update_db_entry - update our entry in the database. */ @@ -1840,3 +1891,4 @@ cleanup_db() if (p[-1]) delete_db_key(p); } +#endif /* USE_TDB */