static void pap_response(pap *_this, int authok, const char *mes) { int lpktp, lmes; u_char *pktp, *pktp1; const char *realm; pktp = ppp_packetbuf(_this->ppp, PPP_PROTO_PAP) + HEADERLEN; lpktp = _this->ppp->mru - HEADERLEN; realm = npppd_ppp_get_realm_name(_this->ppp->pppd, _this->ppp); pktp1 = pktp; if (mes == NULL) lmes = 0; else lmes = strlen(mes); lmes = MINIMUM(lmes, lpktp - 1); PUTCHAR(lmes, pktp1); if (lmes > 0) memcpy(pktp1, mes, lmes); lpktp = lmes + 1; if (authok) ppp_output(_this->ppp, PPP_PROTO_PAP, AUTHACK, _this->auth_id, pktp, lpktp); else ppp_output(_this->ppp, PPP_PROTO_PAP, AUTHNAK, _this->auth_id, pktp, lpktp); if (!authok) { pap_log(_this, LOG_ALERT, "logtype=Failure username=\"%s\" realm=%s", _this->name, realm); pap_stop(_this); ppp_set_disconnect_cause(_this->ppp, PPP_DISCON_AUTH_FAILED, PPP_PROTO_PAP, 1 /* peer */, NULL); ppp_stop(_this->ppp, "Authentication Required"); } else { strlcpy(_this->ppp->username, _this->name, sizeof(_this->ppp->username)); pap_log(_this, LOG_INFO, "logtype=Success username=\"%s\" realm=%s", _this->name, realm); pap_stop(_this); ppp_auth_ok(_this->ppp); /* reset the state to response request of retransmision. */ _this->state = PAP_STATE_SENT_RESPONSE; } }
static void ppp_down_others(npppd_ppp *_this) { fsm_lowerdown(&_this->ccp.fsm); fsm_lowerdown(&_this->ipcp.fsm); npppd_release_ip(_this->pppd, _this); if (AUTH_IS_PAP(_this)) pap_stop(&_this->pap); if (AUTH_IS_CHAP(_this)) chap_stop(&_this->chap); #ifdef USE_NPPPD_EAP_RADIUS if (AUTH_IS_EAP(_this)) eap_stop(&_this->eap); #endif evtimer_del(&_this->idle_event); }
/** * Destroy the npppd_ppp instance. Don't use this function after calling * the ppp_start, please use ppp_stop() instead. */ void ppp_destroy(void *ctx) { npppd_ppp *_this = ctx; if (_this->proxy_authen_resp != NULL) free(_this->proxy_authen_resp); /* * Down/stop the protocols again to make sure they are stopped * even if ppp_stop is done. They might be change their state * by receiving packets from the peer. */ fsm_lowerdown(&_this->ccp.fsm); fsm_lowerdown(&_this->ipcp.fsm); pap_stop(&_this->pap); chap_stop(&_this->chap); if (_this->outpacket_buf != NULL) free(_this->outpacket_buf); free(_this); }