global variables removed from chap support

This commit is contained in:
Sylvain Rochet 2012-06-15 01:22:01 +02:00
parent 2deb13df43
commit 19238a910c
6 changed files with 25 additions and 21 deletions

View File

@ -1348,8 +1348,8 @@ auth_check_options()
#endif /* EAP_SUPPORT */ #endif /* EAP_SUPPORT */
) { ) {
#if CHAP_SUPPORT #if CHAP_SUPPORT
wo->neg_chap = chap_mdtype_all != MDTYPE_NONE; wo->neg_chap = pcb->chap_mdtype_all != MDTYPE_NONE;
wo->chap_mdtype = chap_mdtype_all; wo->chap_mdtype = pcb->chap_mdtype_all;
#endif /* CHAP_SUPPORT */ #endif /* CHAP_SUPPORT */
#if PAP_SUPPORT #if PAP_SUPPORT
wo->neg_upap = 1; wo->neg_upap = 1;

View File

@ -52,21 +52,12 @@
#define MDTYPE_ALL (MDTYPE_MD5) #define MDTYPE_ALL (MDTYPE_MD5)
#endif #endif
int chap_mdtype_all = MDTYPE_ALL;
/* Hook for a plugin to validate CHAP challenge */ /* Hook for a plugin to validate CHAP challenge */
int (*chap_verify_hook)(char *name, char *ourname, int id, int (*chap_verify_hook)(char *name, char *ourname, int id,
struct chap_digest_type *digest, struct chap_digest_type *digest,
unsigned char *challenge, unsigned char *response, unsigned char *challenge, unsigned char *response,
char *message, int message_space) = NULL; 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 #if PPP_OPTIONS
/* /*
* Command-line options. * Command-line options.
@ -74,9 +65,9 @@ int chap_rechallenge_time = 0;
static option_t chap_option_list[] = { static option_t chap_option_list[] = {
{ "chap-restart", o_int, &chap_timeout_time, { "chap-restart", o_int, &chap_timeout_time,
"Set timeout for CHAP", OPT_PRIO }, "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 }, "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 }, "Set interval for rechallenge", OPT_PRIO },
{ NULL } { NULL }
}; };
@ -138,6 +129,8 @@ static void chap_init(int unit) {
memset(&pcb->chap_server, 0, sizeof(chap_server_state)); memset(&pcb->chap_server, 0, sizeof(chap_server_state));
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
pcb->chap_mdtype_all = MDTYPE_ALL;
chap_md5_init(); chap_md5_init();
#if MSCHAP_SUPPORT #if MSCHAP_SUPPORT
chapms_init(); chapms_init();
@ -245,7 +238,7 @@ static void chap_timeout(void *arg) {
pcb->chap_server.challenge_xmits = 0; pcb->chap_server.challenge_xmits = 0;
chap_generate_challenge(pcb); chap_generate_challenge(pcb);
pcb->chap_server.flags |= CHALLENGE_VALID; 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 &= ~CHALLENGE_VALID;
pcb->chap_server.flags |= AUTH_DONE | AUTH_FAILED; pcb->chap_server.flags |= AUTH_DONE | AUTH_FAILED;
auth_peer_fail(pcb, PPP_CHAP); 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); ppp_write(pcb, pcb->chap_server.challenge, pcb->chap_server.challenge_pktlen);
++pcb->chap_server.challenge_xmits; ++pcb->chap_server.challenge_xmits;
pcb->chap_server.flags |= TIMEOUT_PENDING; 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, auth_peer_success(pcb, PPP_CHAP,
pcb->chap_server.digest->code, pcb->chap_server.digest->code,
name, strlen(name)); name, strlen(name));
if (chap_rechallenge_time) { if (pcb->settings.chap_rechallenge_time) {
pcb->chap_server.flags |= TIMEOUT_PENDING; pcb->chap_server.flags |= TIMEOUT_PENDING;
TIMEOUT(chap_timeout, pcb, TIMEOUT(chap_timeout, pcb,
chap_rechallenge_time); pcb->settings.chap_rechallenge_time);
} }
} }
pcb->chap_server.flags |= AUTH_DONE; pcb->chap_server.flags |= AUTH_DONE;

View File

@ -67,9 +67,6 @@
#define MDTYPE_MD5 0x4 #define MDTYPE_MD5 0x4
#define MDTYPE_NONE 0 #define MDTYPE_NONE 0
/* hashes supported by this instance of pppd */
extern int chap_mdtype_all;
#if MSCHAP_SUPPORT #if MSCHAP_SUPPORT
/* Return the digest alg. ID for the most preferred digest type. */ /* Return the digest alg. ID for the most preferred digest type. */
#define CHAP_DIGEST(mdtype) \ #define CHAP_DIGEST(mdtype) \

View File

@ -378,6 +378,7 @@ static void
lcp_init(unit) lcp_init(unit)
int unit; int unit;
{ {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &lcp_fsm[unit]; fsm *f = &lcp_fsm[unit];
lcp_options *wo = &lcp_wantoptions[unit]; lcp_options *wo = &lcp_wantoptions[unit];
lcp_options *ao = &lcp_allowoptions[unit]; lcp_options *ao = &lcp_allowoptions[unit];
@ -402,7 +403,7 @@ lcp_init(unit)
ao->neg_asyncmap = 1; ao->neg_asyncmap = 1;
#if CHAP_SUPPORT #if CHAP_SUPPORT
ao->neg_chap = 1; ao->neg_chap = 1;
ao->chap_mdtype = chap_mdtype_all; ao->chap_mdtype = pcb->chap_mdtype_all;
#endif /* CHAP_SUPPORT */ #endif /* CHAP_SUPPORT */
#if PAP_SUPPORT #if PAP_SUPPORT
ao->neg_upap = 1; ao->neg_upap = 1;

View File

@ -255,8 +255,13 @@ ppp_pcb *ppp_new(void) {
pcb->status = EXIT_OK; pcb->status = EXIT_OK;
new_phase(pcb, PHASE_INITIALIZE); new_phase(pcb, PHASE_INITIALIZE);
/* default configuration */
pcb->settings.usepeerdns = 1; pcb->settings.usepeerdns = 1;
pcb->settings.persist = 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. * Initialize each protocol.

View File

@ -169,6 +169,12 @@ typedef struct ppp_settings_s {
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
/* FIXME: make it a compile time option */ /* FIXME: make it a compile time option */
char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */ 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; } ppp_settings;
struct ppp_addrs { struct ppp_addrs {
@ -374,6 +380,8 @@ typedef struct ppp_pcb_s {
#endif /* PAP_SUPPORT */ #endif /* PAP_SUPPORT */
#if CHAP_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; chap_client_state chap_client;
#if PPP_SERVER #if PPP_SERVER
chap_server_state chap_server; chap_server_state chap_server;