From 19238a910c39b6ee0bd714586cdc3a96d0a8e83b Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Fri, 15 Jun 2012 01:22:01 +0200 Subject: [PATCH] global variables removed from chap support --- src/netif/ppp/auth.c | 4 ++-- src/netif/ppp/chap-new.c | 23 ++++++++--------------- src/netif/ppp/chap-new.h | 3 --- src/netif/ppp/lcp.c | 3 ++- src/netif/ppp/ppp.c | 5 +++++ src/netif/ppp/ppp.h | 8 ++++++++ 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 1780ad0f..fe197942 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -1348,8 +1348,8 @@ auth_check_options() #endif /* EAP_SUPPORT */ ) { #if CHAP_SUPPORT - wo->neg_chap = chap_mdtype_all != MDTYPE_NONE; - wo->chap_mdtype = chap_mdtype_all; + wo->neg_chap = pcb->chap_mdtype_all != MDTYPE_NONE; + wo->chap_mdtype = pcb->chap_mdtype_all; #endif /* CHAP_SUPPORT */ #if PAP_SUPPORT wo->neg_upap = 1; diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index a70e5bdb..cb90a4e0 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -52,21 +52,12 @@ #define MDTYPE_ALL (MDTYPE_MD5) #endif -int chap_mdtype_all = MDTYPE_ALL; - /* Hook for a plugin to validate CHAP challenge */ int (*chap_verify_hook)(char *name, char *ourname, int id, struct chap_digest_type *digest, unsigned char *challenge, unsigned char *response, char *message, int message_space) = NULL; -/* - * Option variables. - */ -int chap_timeout_time = 3; -int chap_max_transmits = 10; -int chap_rechallenge_time = 0; - #if PPP_OPTIONS /* * Command-line options. @@ -74,9 +65,9 @@ int chap_rechallenge_time = 0; static option_t chap_option_list[] = { { "chap-restart", o_int, &chap_timeout_time, "Set timeout for CHAP", OPT_PRIO }, - { "chap-max-challenge", o_int, &chap_max_transmits, + { "chap-max-challenge", o_int, &pcb->settings.chap_max_transmits, "Set max #xmits for challenge", OPT_PRIO }, - { "chap-interval", o_int, &chap_rechallenge_time, + { "chap-interval", o_int, &pcb->settings.chap_rechallenge_time, "Set interval for rechallenge", OPT_PRIO }, { NULL } }; @@ -138,6 +129,8 @@ static void chap_init(int unit) { memset(&pcb->chap_server, 0, sizeof(chap_server_state)); #endif /* PPP_SERVER */ + pcb->chap_mdtype_all = MDTYPE_ALL; + chap_md5_init(); #if MSCHAP_SUPPORT chapms_init(); @@ -245,7 +238,7 @@ static void chap_timeout(void *arg) { pcb->chap_server.challenge_xmits = 0; chap_generate_challenge(pcb); pcb->chap_server.flags |= CHALLENGE_VALID; - } else if (pcb->chap_server.challenge_xmits >= chap_max_transmits) { + } else if (pcb->chap_server.challenge_xmits >= pcb->settings.chap_max_transmits) { pcb->chap_server.flags &= ~CHALLENGE_VALID; pcb->chap_server.flags |= AUTH_DONE | AUTH_FAILED; auth_peer_fail(pcb, PPP_CHAP); @@ -255,7 +248,7 @@ static void chap_timeout(void *arg) { ppp_write(pcb, pcb->chap_server.challenge, pcb->chap_server.challenge_pktlen); ++pcb->chap_server.challenge_xmits; pcb->chap_server.flags |= TIMEOUT_PENDING; - TIMEOUT(chap_timeout, arg, chap_timeout_time); + TIMEOUT(chap_timeout, arg, pcb->settings.chap_timeout_time); } /* @@ -380,10 +373,10 @@ static void chap_handle_response(ppp_pcb *pcb, int id, auth_peer_success(pcb, PPP_CHAP, pcb->chap_server.digest->code, name, strlen(name)); - if (chap_rechallenge_time) { + if (pcb->settings.chap_rechallenge_time) { pcb->chap_server.flags |= TIMEOUT_PENDING; TIMEOUT(chap_timeout, pcb, - chap_rechallenge_time); + pcb->settings.chap_rechallenge_time); } } pcb->chap_server.flags |= AUTH_DONE; diff --git a/src/netif/ppp/chap-new.h b/src/netif/ppp/chap-new.h index 902fed7e..c85a91af 100644 --- a/src/netif/ppp/chap-new.h +++ b/src/netif/ppp/chap-new.h @@ -67,9 +67,6 @@ #define MDTYPE_MD5 0x4 #define MDTYPE_NONE 0 -/* hashes supported by this instance of pppd */ -extern int chap_mdtype_all; - #if MSCHAP_SUPPORT /* Return the digest alg. ID for the most preferred digest type. */ #define CHAP_DIGEST(mdtype) \ diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index c671d44c..9279bf7f 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -378,6 +378,7 @@ static void lcp_init(unit) int unit; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; fsm *f = &lcp_fsm[unit]; lcp_options *wo = &lcp_wantoptions[unit]; lcp_options *ao = &lcp_allowoptions[unit]; @@ -402,7 +403,7 @@ lcp_init(unit) ao->neg_asyncmap = 1; #if CHAP_SUPPORT ao->neg_chap = 1; - ao->chap_mdtype = chap_mdtype_all; + ao->chap_mdtype = pcb->chap_mdtype_all; #endif /* CHAP_SUPPORT */ #if PAP_SUPPORT ao->neg_upap = 1; diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 4b3d6e4b..261d86f6 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -255,8 +255,13 @@ ppp_pcb *ppp_new(void) { pcb->status = EXIT_OK; new_phase(pcb, PHASE_INITIALIZE); + /* default configuration */ pcb->settings.usepeerdns = 1; pcb->settings.persist = 1; +#if CHAP_SUPPORT + pcb->settings.chap_timeout_time = 3; + pcb->settings.chap_max_transmits = 10; +#endif /* CHAP_SUPPPORT */ /* * Initialize each protocol. diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index 274f177b..282b018f 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -169,6 +169,12 @@ typedef struct ppp_settings_s { #endif /* PPP_SERVER */ /* FIXME: make it a compile time option */ char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */ + +#if CHAP_SUPPORT + int chap_timeout_time; + int chap_max_transmits; + int chap_rechallenge_time; +#endif /* CHAP_SUPPPORT */ } ppp_settings; struct ppp_addrs { @@ -374,6 +380,8 @@ typedef struct ppp_pcb_s { #endif /* PAP_SUPPORT */ #if CHAP_SUPPORT + /* FIXME: we can probably remove this entry */ + int chap_mdtype_all; /* hashes supported by this instance of pppd */ chap_client_state chap_client; #if PPP_SERVER chap_server_state chap_server;