From: Paul Mackerras Date: Fri, 27 Apr 2001 23:13:06 +0000 (+0000) Subject: add some more hooks and notifiers X-Git-Tag: ppp-2.4.7~482 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=aac99e2604e20409d9f0538ceb8590c2f75220a0 add some more hooks and notifiers --- diff --git a/pppd/auth.c b/pppd/auth.c index 94871bf..1a8cb34 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -32,7 +32,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: auth.c,v 1.69 2001/03/12 22:50:01 paulus Exp $" +#define RCSID "$Id: auth.c,v 1.70 2001/04/27 23:13:06 paulus Exp $" #include #include @@ -132,6 +132,18 @@ void (*pap_logout_hook) __P((void)) = NULL; /* Hook for a plugin to get the PAP password for authenticating us */ int (*pap_passwd_hook) __P((char *user, char *passwd)) = NULL; +/* Hook for a plugin to say whether it is OK if the peer + refuses to authenticate. */ +int (*null_auth_hook) __P((struct wordlist **paddrs, + struct wordlist **popts)) = NULL; + +/* A notifier for when the peer has authenticated itself, + and we are proceeding to the network phase. */ +struct notifier *auth_up_notifier = NULL; + +/* A notifier for when the link goes down. */ +struct notifier *link_down_notifier = NULL; + /* * This is used to ensure that we don't start an auth-up/down * script while one is already running. @@ -407,6 +419,7 @@ link_down(unit) int i; struct protent *protp; + notify(link_down_notifier, 0); auth_state = s_down; if (auth_script_state == s_up && auth_script_pid == 0) { update_link_stats(unit); @@ -424,7 +437,7 @@ link_down(unit) num_np_open = 0; num_np_up = 0; if (phase != PHASE_DEAD) - new_phase(PHASE_TERMINATE); + new_phase(PHASE_ESTABLISH); } /* @@ -509,6 +522,7 @@ network_phase(unit) * If the peer had to authenticate, run the auth-up script now. */ if (go->neg_chap || go->neg_upap) { + notify(auth_up_notifier, 0); auth_state = s_up; if (auth_script_state == s_down && auth_script_pid == 0) { auth_script_state = s_up; @@ -1250,19 +1264,29 @@ null_login(unit) struct wordlist *addrs, *opts; char secret[MAXWORDLEN]; + /* + * Check if a plugin wants to handle this. + */ + ret = -1; + if (null_auth_hook) + ret = (*null_auth_hook)(&addrs, &opts); + /* * Open the file of pap secrets and scan for a suitable secret. */ - filename = _PATH_UPAPFILE; - addrs = NULL; - f = fopen(filename, "r"); - if (f == NULL) - return 0; - check_access(f, filename); + if (ret <= 0) { + filename = _PATH_UPAPFILE; + addrs = NULL; + f = fopen(filename, "r"); + if (f == NULL) + return 0; + check_access(f, filename); - i = scan_authfile(f, "", our_name, secret, &addrs, &opts, filename); - ret = i >= 0 && secret[0] == 0; - BZERO(secret, sizeof(secret)); + i = scan_authfile(f, "", our_name, secret, &addrs, &opts, filename); + ret = i >= 0 && secret[0] == 0; + BZERO(secret, sizeof(secret)); + fclose(f); + } if (ret) set_allowed_addrs(unit, addrs, opts); @@ -1271,7 +1295,6 @@ null_login(unit) if (addrs != 0) free_wordlist(addrs); - fclose(f); return ret; } diff --git a/pppd/ipcp.c b/pppd/ipcp.c index 5236244..64d67fe 100644 --- a/pppd/ipcp.c +++ b/pppd/ipcp.c @@ -17,7 +17,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: ipcp.c,v 1.57 2001/03/08 05:11:12 paulus Exp $" +#define RCSID "$Id: ipcp.c,v 1.58 2001/04/27 23:13:06 paulus Exp $" /* * TODO: @@ -59,6 +59,10 @@ void (*ip_down_hook) __P((void)) = NULL; /* Hook for a plugin to choose the remote IP address */ void (*ip_choose_hook) __P((u_int32_t *)) = NULL; +/* Notifiers for when IPCP goes up and down */ +struct notifier *ip_up_notifier = NULL; +struct notifier *ip_down_notifier = NULL; + /* local vars */ static int default_route_set[NUM_PPP]; /* Have set up a default route */ static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */ @@ -1709,6 +1713,7 @@ ipcp_up(f) np_up(f->unit, PPP_IP); ipcp_is_up = 1; + notify(ip_up_notifier, 0); if (ip_up_hook) ip_up_hook(); @@ -1737,6 +1742,7 @@ ipcp_down(f) /* XXX a bit IPv4-centric here, we only need to get the stats * before the interface is marked down. */ update_link_stats(f->unit); + notify(ip_down_notifier, 0); if (ip_down_hook) ip_down_hook(); if (ipcp_is_up) {