diff options
Diffstat (limited to 'accel-pppd/auth/auth_chap_md5.c')
-rw-r--r-- | accel-pppd/auth/auth_chap_md5.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/accel-pppd/auth/auth_chap_md5.c b/accel-pppd/auth/auth_chap_md5.c index 8aa3018..f843b92 100644 --- a/accel-pppd/auth/auth_chap_md5.c +++ b/accel-pppd/auth/auth_chap_md5.c @@ -37,41 +37,36 @@ static int conf_interval = 0; static int conf_max_failure = 3; static int conf_any_login = 0; -struct chap_hdr_t -{ +struct chap_hdr_t { uint16_t proto; uint8_t code; uint8_t id; uint16_t len; } __attribute__((packed)); -struct chap_challenge_t -{ +struct chap_challenge_t { struct chap_hdr_t hdr; uint8_t val_size; uint8_t val[VALUE_SIZE]; char name[0]; } __attribute__((packed)); -struct chap_failure_t -{ +struct chap_failure_t { struct chap_hdr_t hdr; char message[sizeof(MSG_FAILURE)]; } __attribute__((packed)); -struct chap_success_t -{ +struct chap_success_t { struct chap_hdr_t hdr; char message[sizeof(MSG_SUCCESS)]; } __attribute__((packed)); -struct chap_auth_data_t -{ +struct chap_auth_data_t { struct auth_data_t auth; struct ppp_handler_t h; struct ppp_t *ppp; - int id; + uint8_t id; uint8_t val[VALUE_SIZE]; struct triton_timer_t timeout; struct triton_timer_t interval; @@ -131,6 +126,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart_timer; d->interval.period = conf_interval * 1000; + d->id = 1; ppp_register_chan_handler(ppp, &d->h); @@ -208,12 +204,12 @@ static void chap_send_failure(struct chap_auth_data_t *ad) ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } -static void chap_send_success(struct chap_auth_data_t *ad) +static void chap_send_success(struct chap_auth_data_t *ad, int id) { struct chap_success_t msg = { .hdr.proto = htons(PPP_CHAP), .hdr.code = CHAP_SUCCESS, - .hdr.id = ad->id, + .hdr.id = id, .hdr.len = htons(sizeof(msg)-1-2), .message = MSG_SUCCESS, }; @@ -229,7 +225,7 @@ static void chap_send_challenge(struct chap_auth_data_t *ad, int new) struct chap_challenge_t msg = { .hdr.proto = htons(PPP_CHAP), .hdr.code = CHAP_CHALLENGE, - .hdr.id = ++ad->id, + .hdr.id = ad->id, .hdr.len = htons(sizeof(msg) - 2), .val_size = VALUE_SIZE, }; @@ -270,6 +266,11 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); log_ppp_info2("\"]\n"); } + + if (ad->started && msg->hdr.id == ad->id - 1) { + chap_send_success(ad, msg->hdr.id); + return; + } if (msg->hdr.id != ad->id) { if (conf_ppp_verbose) @@ -296,8 +297,9 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h _free(name); return; } - chap_send_success(ad); + chap_send_success(ad, ad->id); ad->started = 1; + ad->id++; return; } @@ -337,13 +339,15 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); } else { - chap_send_success(ad); + chap_send_success(ad, ad->id); ad->started = 1; if (conf_interval) triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->interval, 0); } } else _free(name); + + ad->id++; } _free(passwd); } else if (r == PWDB_DENIED) { @@ -360,15 +364,17 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); } else { - chap_send_success(ad); + chap_send_success(ad, ad->id); ad->started = 1; if (conf_interval) triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->interval, 0); } } else { - chap_send_success(ad); + chap_send_success(ad, ad->id); _free(name); } + + ad->id++; } } |