mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-29 22:20:12 +00:00
Minor changes: coding style (tabs, ident, etc...).
This commit is contained in:
parent
865f6eb5f3
commit
37a5a87057
@ -93,7 +93,6 @@
|
|||||||
#define CHAP_PEER 8
|
#define CHAP_PEER 8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************/
|
/************************/
|
||||||
/*** LOCAL DATA TYPES ***/
|
/*** LOCAL DATA TYPES ***/
|
||||||
/************************/
|
/************************/
|
||||||
@ -104,7 +103,6 @@ struct wordlist {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
/*** LOCAL FUNCTION DECLARATIONS ***/
|
/*** LOCAL FUNCTION DECLARATIONS ***/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
@ -170,7 +168,6 @@ static int passwd_from_file;
|
|||||||
#endif /* PAP_SUPPORT || CHAP_SUPPORT */
|
#endif /* PAP_SUPPORT || CHAP_SUPPORT */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
@ -178,7 +175,8 @@ static int passwd_from_file;
|
|||||||
* An Open on LCP has requested a change from Dead to Establish phase.
|
* An Open on LCP has requested a change from Dead to Establish phase.
|
||||||
* Do what's necessary to bring the physical layer up.
|
* Do what's necessary to bring the physical layer up.
|
||||||
*/
|
*/
|
||||||
void link_required(int unit)
|
void
|
||||||
|
link_required(int unit)
|
||||||
{
|
{
|
||||||
AUTHDEBUG((LOG_INFO, "link_required: %d\n", unit));
|
AUTHDEBUG((LOG_INFO, "link_required: %d\n", unit));
|
||||||
}
|
}
|
||||||
@ -187,14 +185,16 @@ void link_required(int unit)
|
|||||||
* LCP has terminated the link; go to the Dead phase and take the
|
* LCP has terminated the link; go to the Dead phase and take the
|
||||||
* physical layer down.
|
* physical layer down.
|
||||||
*/
|
*/
|
||||||
void link_terminated(int unit)
|
void
|
||||||
|
link_terminated(int unit)
|
||||||
{
|
{
|
||||||
AUTHDEBUG((LOG_INFO, "link_terminated: %d\n", unit));
|
AUTHDEBUG((LOG_INFO, "link_terminated: %d\n", unit));
|
||||||
|
if (lcp_phase[unit] == PHASE_DEAD) {
|
||||||
if (lcp_phase[unit] == PHASE_DEAD)
|
|
||||||
return;
|
return;
|
||||||
if (logged_in)
|
}
|
||||||
|
if (logged_in) {
|
||||||
logout();
|
logout();
|
||||||
|
}
|
||||||
lcp_phase[unit] = PHASE_DEAD;
|
lcp_phase[unit] = PHASE_DEAD;
|
||||||
AUTHDEBUG((LOG_NOTICE, "Connection terminated.\n"));
|
AUTHDEBUG((LOG_NOTICE, "Connection terminated.\n"));
|
||||||
pppLinkTerminated(unit);
|
pppLinkTerminated(unit);
|
||||||
@ -203,7 +203,8 @@ void link_terminated(int unit)
|
|||||||
/*
|
/*
|
||||||
* LCP has gone down; it will either die or try to re-establish.
|
* LCP has gone down; it will either die or try to re-establish.
|
||||||
*/
|
*/
|
||||||
void link_down(int unit)
|
void
|
||||||
|
link_down(int unit)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct protent *protp;
|
struct protent *protp;
|
||||||
@ -214,17 +215,21 @@ void link_down(int unit)
|
|||||||
did_authup = 0;
|
did_authup = 0;
|
||||||
}
|
}
|
||||||
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
|
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
|
||||||
if (!protp->enabled_flag)
|
if (!protp->enabled_flag) {
|
||||||
continue;
|
continue;
|
||||||
if (protp->protocol != PPP_LCP && protp->lowerdown != NULL)
|
}
|
||||||
|
if (protp->protocol != PPP_LCP && protp->lowerdown != NULL) {
|
||||||
(*protp->lowerdown)(unit);
|
(*protp->lowerdown)(unit);
|
||||||
if (protp->protocol < 0xC000 && protp->close != NULL)
|
}
|
||||||
|
if (protp->protocol < 0xC000 && protp->close != NULL) {
|
||||||
(*protp->close)(unit, "LCP down");
|
(*protp->close)(unit, "LCP down");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
num_np_open = 0;
|
num_np_open = 0;
|
||||||
num_np_up = 0;
|
num_np_up = 0;
|
||||||
if (lcp_phase[unit] != PHASE_DEAD)
|
if (lcp_phase[unit] != PHASE_DEAD) {
|
||||||
lcp_phase[unit] = PHASE_TERMINATE;
|
lcp_phase[unit] = PHASE_TERMINATE;
|
||||||
|
}
|
||||||
pppLinkDown(unit);
|
pppLinkDown(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +237,8 @@ void link_down(int unit)
|
|||||||
* The link is established.
|
* The link is established.
|
||||||
* Proceed to the Dead, Authenticate or Network phase as appropriate.
|
* Proceed to the Dead, Authenticate or Network phase as appropriate.
|
||||||
*/
|
*/
|
||||||
void link_established(int unit)
|
void
|
||||||
|
link_established(int unit)
|
||||||
{
|
{
|
||||||
int auth;
|
int auth;
|
||||||
int i;
|
int i;
|
||||||
@ -247,11 +253,11 @@ void link_established(int unit)
|
|||||||
/*
|
/*
|
||||||
* Tell higher-level protocols that LCP is up.
|
* Tell higher-level protocols that LCP is up.
|
||||||
*/
|
*/
|
||||||
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i)
|
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
|
||||||
if (protp->protocol != PPP_LCP && protp->enabled_flag
|
if (protp->protocol != PPP_LCP && protp->enabled_flag && protp->lowerup != NULL) {
|
||||||
&& protp->lowerup != NULL)
|
|
||||||
(*protp->lowerup)(unit);
|
(*protp->lowerup)(unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ppp_settings.auth_required && !(go->neg_chap || go->neg_upap)) {
|
if (ppp_settings.auth_required && !(go->neg_chap || go->neg_upap)) {
|
||||||
/*
|
/*
|
||||||
* We wanted the peer to authenticate itself, and it refused:
|
* We wanted the peer to authenticate itself, and it refused:
|
||||||
@ -295,24 +301,26 @@ void link_established(int unit)
|
|||||||
if (ho->neg_upap) {
|
if (ho->neg_upap) {
|
||||||
if (ppp_settings.passwd[0] == 0) {
|
if (ppp_settings.passwd[0] == 0) {
|
||||||
passwd_from_file = 1;
|
passwd_from_file = 1;
|
||||||
if (!get_pap_passwd(unit, ppp_settings.user, ppp_settings.passwd))
|
if (!get_pap_passwd(unit, ppp_settings.user, ppp_settings.passwd)) {
|
||||||
AUTHDEBUG((LOG_ERR, "No secret found for PAP login\n"));
|
AUTHDEBUG((LOG_ERR, "No secret found for PAP login\n"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
upap_authwithpeer(unit, ppp_settings.user, ppp_settings.passwd);
|
upap_authwithpeer(unit, ppp_settings.user, ppp_settings.passwd);
|
||||||
auth |= PAP_WITHPEER;
|
auth |= PAP_WITHPEER;
|
||||||
}
|
}
|
||||||
#endif /* PAP_SUPPORT */
|
#endif /* PAP_SUPPORT */
|
||||||
auth_pending[unit] = auth;
|
auth_pending[unit] = auth;
|
||||||
|
|
||||||
if (!auth)
|
if (!auth) {
|
||||||
network_phase(unit);
|
network_phase(unit);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The peer has failed to authenticate himself using `protocol'.
|
* The peer has failed to authenticate himself using `protocol'.
|
||||||
*/
|
*/
|
||||||
void auth_peer_fail(int unit, u16_t protocol)
|
void
|
||||||
|
auth_peer_fail(int unit, u16_t protocol)
|
||||||
{
|
{
|
||||||
AUTHDEBUG((LOG_INFO, "auth_peer_fail: %d proto=%X\n", unit, protocol));
|
AUTHDEBUG((LOG_INFO, "auth_peer_fail: %d proto=%X\n", unit, protocol));
|
||||||
/*
|
/*
|
||||||
@ -326,7 +334,8 @@ void auth_peer_fail(int unit, u16_t protocol)
|
|||||||
/*
|
/*
|
||||||
* The peer has been successfully authenticated using `protocol'.
|
* The peer has been successfully authenticated using `protocol'.
|
||||||
*/
|
*/
|
||||||
void auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
|
void
|
||||||
|
auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
|
||||||
{
|
{
|
||||||
int pbit;
|
int pbit;
|
||||||
|
|
||||||
@ -339,16 +348,16 @@ void auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
|
|||||||
pbit = PAP_PEER;
|
pbit = PAP_PEER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n",
|
AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n", protocol));
|
||||||
protocol));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save the authenticated name of the peer for later.
|
* Save the authenticated name of the peer for later.
|
||||||
*/
|
*/
|
||||||
if (namelen > sizeof(peer_authname) - 1)
|
if (namelen > sizeof(peer_authname) - 1) {
|
||||||
namelen = sizeof(peer_authname) - 1;
|
namelen = sizeof(peer_authname) - 1;
|
||||||
|
}
|
||||||
BCOPY(name, peer_authname, namelen);
|
BCOPY(name, peer_authname, namelen);
|
||||||
peer_authname[namelen] = 0;
|
peer_authname[namelen] = 0;
|
||||||
|
|
||||||
@ -356,20 +365,23 @@ void auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
|
|||||||
* If there is no more authentication still to be done,
|
* If there is no more authentication still to be done,
|
||||||
* proceed to the network (or callback) phase.
|
* proceed to the network (or callback) phase.
|
||||||
*/
|
*/
|
||||||
if ((auth_pending[unit] &= ~pbit) == 0)
|
if ((auth_pending[unit] &= ~pbit) == 0) {
|
||||||
network_phase(unit);
|
network_phase(unit);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have failed to authenticate ourselves to the peer using `protocol'.
|
* We have failed to authenticate ourselves to the peer using `protocol'.
|
||||||
*/
|
*/
|
||||||
void auth_withpeer_fail(int unit, u16_t protocol)
|
void
|
||||||
|
auth_withpeer_fail(int unit, u16_t protocol)
|
||||||
{
|
{
|
||||||
int errCode = PPPERR_AUTHFAIL;
|
int errCode = PPPERR_AUTHFAIL;
|
||||||
|
|
||||||
AUTHDEBUG((LOG_INFO, "auth_withpeer_fail: %d proto=%X\n", unit, protocol));
|
AUTHDEBUG((LOG_INFO, "auth_withpeer_fail: %d proto=%X\n", unit, protocol));
|
||||||
if (passwd_from_file)
|
if (passwd_from_file) {
|
||||||
BZERO(ppp_settings.passwd, MAXSECRETLEN);
|
BZERO(ppp_settings.passwd, MAXSECRETLEN);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* XXX Warning: the unit number indicates the interface which is
|
* XXX Warning: the unit number indicates the interface which is
|
||||||
* not necessarily the PPP connection. It works here as long
|
* not necessarily the PPP connection. It works here as long
|
||||||
@ -387,7 +399,8 @@ void auth_withpeer_fail(int unit, u16_t protocol)
|
|||||||
/*
|
/*
|
||||||
* We have successfully authenticated ourselves with the peer using `protocol'.
|
* We have successfully authenticated ourselves with the peer using `protocol'.
|
||||||
*/
|
*/
|
||||||
void auth_withpeer_success(int unit, u16_t protocol)
|
void
|
||||||
|
auth_withpeer_success(int unit, u16_t protocol)
|
||||||
{
|
{
|
||||||
int pbit;
|
int pbit;
|
||||||
|
|
||||||
@ -397,13 +410,13 @@ void auth_withpeer_success(int unit, u16_t protocol)
|
|||||||
pbit = CHAP_WITHPEER;
|
pbit = CHAP_WITHPEER;
|
||||||
break;
|
break;
|
||||||
case PPP_PAP:
|
case PPP_PAP:
|
||||||
if (passwd_from_file)
|
if (passwd_from_file) {
|
||||||
BZERO(ppp_settings.passwd, MAXSECRETLEN);
|
BZERO(ppp_settings.passwd, MAXSECRETLEN);
|
||||||
|
}
|
||||||
pbit = PAP_WITHPEER;
|
pbit = PAP_WITHPEER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n",
|
AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n", protocol));
|
||||||
protocol));
|
|
||||||
pbit = 0;
|
pbit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,16 +424,18 @@ void auth_withpeer_success(int unit, u16_t protocol)
|
|||||||
* If there is no more authentication still being done,
|
* If there is no more authentication still being done,
|
||||||
* proceed to the network (or callback) phase.
|
* proceed to the network (or callback) phase.
|
||||||
*/
|
*/
|
||||||
if ((auth_pending[unit] &= ~pbit) == 0)
|
if ((auth_pending[unit] &= ~pbit) == 0) {
|
||||||
network_phase(unit);
|
network_phase(unit);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif /* PAP_SUPPORT || CHAP_SUPPORT */
|
#endif /* PAP_SUPPORT || CHAP_SUPPORT */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* np_up - a network protocol has come up.
|
* np_up - a network protocol has come up.
|
||||||
*/
|
*/
|
||||||
void np_up(int unit, u16_t proto)
|
void
|
||||||
|
np_up(int unit, u16_t proto)
|
||||||
{
|
{
|
||||||
AUTHDEBUG((LOG_INFO, "np_up: %d proto=%X\n", unit, proto));
|
AUTHDEBUG((LOG_INFO, "np_up: %d proto=%X\n", unit, proto));
|
||||||
if (num_np_up == 0) {
|
if (num_np_up == 0) {
|
||||||
@ -428,23 +443,26 @@ void np_up(int unit, u16_t proto)
|
|||||||
/*
|
/*
|
||||||
* At this point we consider that the link has come up successfully.
|
* At this point we consider that the link has come up successfully.
|
||||||
*/
|
*/
|
||||||
if (ppp_settings.idle_time_limit > 0)
|
if (ppp_settings.idle_time_limit > 0) {
|
||||||
TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit);
|
TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a timeout to close the connection once the maximum
|
* Set a timeout to close the connection once the maximum
|
||||||
* connect time has expired.
|
* connect time has expired.
|
||||||
*/
|
*/
|
||||||
if (ppp_settings.maxconnect > 0)
|
if (ppp_settings.maxconnect > 0) {
|
||||||
TIMEOUT(connect_time_expired, 0, ppp_settings.maxconnect);
|
TIMEOUT(connect_time_expired, 0, ppp_settings.maxconnect);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
++num_np_up;
|
++num_np_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* np_down - a network protocol has gone down.
|
* np_down - a network protocol has gone down.
|
||||||
*/
|
*/
|
||||||
void np_down(int unit, u16_t proto)
|
void
|
||||||
|
np_down(int unit, u16_t proto)
|
||||||
{
|
{
|
||||||
AUTHDEBUG((LOG_INFO, "np_down: %d proto=%X\n", unit, proto));
|
AUTHDEBUG((LOG_INFO, "np_down: %d proto=%X\n", unit, proto));
|
||||||
if (--num_np_up == 0 && ppp_settings.idle_time_limit > 0) {
|
if (--num_np_up == 0 && ppp_settings.idle_time_limit > 0) {
|
||||||
@ -455,7 +473,8 @@ void np_down(int unit, u16_t proto)
|
|||||||
/*
|
/*
|
||||||
* np_finished - a network protocol has finished using the link.
|
* np_finished - a network protocol has finished using the link.
|
||||||
*/
|
*/
|
||||||
void np_finished(int unit, u16_t proto)
|
void
|
||||||
|
np_finished(int unit, u16_t proto)
|
||||||
{
|
{
|
||||||
AUTHDEBUG((LOG_INFO, "np_finished: %d proto=%X\n", unit, proto));
|
AUTHDEBUG((LOG_INFO, "np_finished: %d proto=%X\n", unit, proto));
|
||||||
if (--num_np_open <= 0) {
|
if (--num_np_open <= 0) {
|
||||||
@ -469,7 +488,8 @@ void np_finished(int unit, u16_t proto)
|
|||||||
* authentication options, i.e. whether we have appropriate secrets
|
* authentication options, i.e. whether we have appropriate secrets
|
||||||
* to use for authenticating ourselves and/or the peer.
|
* to use for authenticating ourselves and/or the peer.
|
||||||
*/
|
*/
|
||||||
void auth_reset(int unit)
|
void
|
||||||
|
auth_reset(int unit)
|
||||||
{
|
{
|
||||||
lcp_options *go = &lcp_gotoptions[unit];
|
lcp_options *go = &lcp_gotoptions[unit];
|
||||||
lcp_options *ao = &lcp_allowoptions[0];
|
lcp_options *ao = &lcp_allowoptions[0];
|
||||||
@ -480,14 +500,16 @@ void auth_reset(int unit)
|
|||||||
ao->neg_upap = !ppp_settings.refuse_pap && (ppp_settings.passwd[0] != 0 || get_pap_passwd(unit, NULL, NULL));
|
ao->neg_upap = !ppp_settings.refuse_pap && (ppp_settings.passwd[0] != 0 || get_pap_passwd(unit, NULL, NULL));
|
||||||
ao->neg_chap = !ppp_settings.refuse_chap && ppp_settings.passwd[0] != 0 /*have_chap_secret(ppp_settings.user, ppp_settings.remote_name, (u32_t)0)*/;
|
ao->neg_chap = !ppp_settings.refuse_chap && ppp_settings.passwd[0] != 0 /*have_chap_secret(ppp_settings.user, ppp_settings.remote_name, (u32_t)0)*/;
|
||||||
|
|
||||||
if (go->neg_upap && !have_pap_secret())
|
if (go->neg_upap && !have_pap_secret()) {
|
||||||
go->neg_upap = 0;
|
go->neg_upap = 0;
|
||||||
|
}
|
||||||
if (go->neg_chap) {
|
if (go->neg_chap) {
|
||||||
remote = ipwo->accept_remote? 0: ipwo->hisaddr;
|
remote = ipwo->accept_remote? 0: ipwo->hisaddr;
|
||||||
if (!have_chap_secret(ppp_settings.remote_name, ppp_settings.our_name, remote))
|
if (!have_chap_secret(ppp_settings.remote_name, ppp_settings.our_name, remote)) {
|
||||||
go->neg_chap = 0;
|
go->neg_chap = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if PAP_SUPPORT
|
#if PAP_SUPPORT
|
||||||
/*
|
/*
|
||||||
@ -500,15 +522,8 @@ void auth_reset(int unit)
|
|||||||
* UPAP_AUTHACK: Authentication succeeded.
|
* UPAP_AUTHACK: Authentication succeeded.
|
||||||
* In either case, msg points to an appropriate message.
|
* In either case, msg points to an appropriate message.
|
||||||
*/
|
*/
|
||||||
int check_passwd(
|
int
|
||||||
int unit,
|
check_passwd( int unit, char *auser, int userlen, char *apasswd, int passwdlen, char **msg, int *msglen)
|
||||||
char *auser,
|
|
||||||
int userlen,
|
|
||||||
char *apasswd,
|
|
||||||
int passwdlen,
|
|
||||||
char **msg,
|
|
||||||
int *msglen
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
*msg = (char *) 0;
|
*msg = (char *) 0;
|
||||||
@ -533,8 +548,9 @@ int check_passwd(
|
|||||||
ret = UPAP_AUTHACK; /* XXX Assume all entries OK. */
|
ret = UPAP_AUTHACK; /* XXX Assume all entries OK. */
|
||||||
|
|
||||||
if (ret == UPAP_AUTHNAK) {
|
if (ret == UPAP_AUTHNAK) {
|
||||||
if (*msg == (char *) 0)
|
if (*msg == (char *) 0) {
|
||||||
*msg = "Login incorrect";
|
*msg = "Login incorrect";
|
||||||
|
}
|
||||||
*msglen = strlen(*msg);
|
*msglen = strlen(*msg);
|
||||||
/*
|
/*
|
||||||
* Frustrate passwd stealer programs.
|
* Frustrate passwd stealer programs.
|
||||||
@ -553,8 +569,9 @@ int check_passwd(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
attempts = 0; /* Reset count */
|
attempts = 0; /* Reset count */
|
||||||
if (*msg == (char *) 0)
|
if (*msg == (char *) 0) {
|
||||||
*msg = "Login ok";
|
*msg = "Login ok";
|
||||||
|
}
|
||||||
*msglen = strlen(*msg);
|
*msglen = strlen(*msg);
|
||||||
set_allowed_addrs(unit, addrs);
|
set_allowed_addrs(unit, addrs);
|
||||||
}
|
}
|
||||||
@ -572,7 +589,8 @@ int check_passwd(
|
|||||||
* auth_ip_addr - check whether the peer is authorized to use
|
* auth_ip_addr - check whether the peer is authorized to use
|
||||||
* a given IP address. Returns 1 if authorized, 0 otherwise.
|
* a given IP address. Returns 1 if authorized, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int auth_ip_addr(int unit, u32_t addr)
|
int
|
||||||
|
auth_ip_addr(int unit, u32_t addr)
|
||||||
{
|
{
|
||||||
return ip_addr_check(addr, addresses[unit]);
|
return ip_addr_check(addr, addresses[unit]);
|
||||||
}
|
}
|
||||||
@ -582,7 +600,8 @@ int auth_ip_addr(int unit, u32_t addr)
|
|||||||
* to use, such as an address in the loopback net or a multicast address.
|
* to use, such as an address in the loopback net or a multicast address.
|
||||||
* addr is in network byte order.
|
* addr is in network byte order.
|
||||||
*/
|
*/
|
||||||
int bad_ip_adrs(u32_t addr)
|
int
|
||||||
|
bad_ip_adrs(u32_t addr)
|
||||||
{
|
{
|
||||||
addr = ntohl(addr);
|
addr = ntohl(addr);
|
||||||
return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
|
return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
|
||||||
@ -596,14 +615,7 @@ int bad_ip_adrs(u32_t addr)
|
|||||||
* for authenticating the given client on the given server.
|
* for authenticating the given client on the given server.
|
||||||
* (We could be either client or server).
|
* (We could be either client or server).
|
||||||
*/
|
*/
|
||||||
int get_secret(
|
int get_secret( int unit, char *client, char *server, char *secret, int *secret_len, int save_addrs)
|
||||||
int unit,
|
|
||||||
char *client,
|
|
||||||
char *server,
|
|
||||||
char *secret,
|
|
||||||
int *secret_len,
|
|
||||||
int save_addrs
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
int len;
|
int len;
|
||||||
@ -620,6 +632,7 @@ int get_secret(
|
|||||||
AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
|
AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
|
||||||
len = MAXSECRETLEN;
|
len = MAXSECRETLEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
BCOPY(ppp_settings.passwd, secret, len);
|
BCOPY(ppp_settings.passwd, secret, len);
|
||||||
*secret_len = len;
|
*secret_len = len;
|
||||||
|
|
||||||
@ -633,17 +646,20 @@ int get_secret(
|
|||||||
secbuf[0] = 0;
|
secbuf[0] = 0;
|
||||||
|
|
||||||
/* XXX Find secret. */
|
/* XXX Find secret. */
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (save_addrs)
|
if (save_addrs) {
|
||||||
set_allowed_addrs(unit, addrs);
|
set_allowed_addrs(unit, addrs);
|
||||||
|
}
|
||||||
|
|
||||||
len = strlen(secbuf);
|
len = strlen(secbuf);
|
||||||
if (len > MAXSECRETLEN) {
|
if (len > MAXSECRETLEN) {
|
||||||
AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
|
AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
|
||||||
len = MAXSECRETLEN;
|
len = MAXSECRETLEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
BCOPY(secbuf, secret, len);
|
BCOPY(secbuf, secret, len);
|
||||||
BZERO(secbuf, sizeof(secbuf));
|
BZERO(secbuf, sizeof(secbuf));
|
||||||
*secret_len = len;
|
*secret_len = len;
|
||||||
@ -658,7 +674,8 @@ int get_secret(
|
|||||||
/*
|
/*
|
||||||
* auth_check_options - called to check authentication options.
|
* auth_check_options - called to check authentication options.
|
||||||
*/
|
*/
|
||||||
void auth_check_options(void)
|
void
|
||||||
|
auth_check_options(void)
|
||||||
{
|
{
|
||||||
lcp_options *wo = &lcp_wantoptions[0];
|
lcp_options *wo = &lcp_wantoptions[0];
|
||||||
int can_auth;
|
int can_auth;
|
||||||
@ -666,10 +683,13 @@ void auth_check_options(void)
|
|||||||
u32_t remote;
|
u32_t remote;
|
||||||
|
|
||||||
/* Default our_name to hostname, and user to our_name */
|
/* Default our_name to hostname, and user to our_name */
|
||||||
if (ppp_settings.our_name[0] == 0 || ppp_settings.usehostname)
|
if (ppp_settings.our_name[0] == 0 || ppp_settings.usehostname) {
|
||||||
strcpy(ppp_settings.our_name, ppp_settings.hostname);
|
strcpy(ppp_settings.our_name, ppp_settings.hostname);
|
||||||
if (ppp_settings.user[0] == 0)
|
}
|
||||||
|
|
||||||
|
if (ppp_settings.user[0] == 0) {
|
||||||
strcpy(ppp_settings.user, ppp_settings.our_name);
|
strcpy(ppp_settings.user, ppp_settings.our_name);
|
||||||
|
}
|
||||||
|
|
||||||
/* If authentication is required, ask peer for CHAP or PAP. */
|
/* If authentication is required, ask peer for CHAP or PAP. */
|
||||||
if (ppp_settings.auth_required && !wo->neg_chap && !wo->neg_upap) {
|
if (ppp_settings.auth_required && !wo->neg_chap && !wo->neg_upap) {
|
||||||
@ -700,7 +720,8 @@ void auth_check_options(void)
|
|||||||
/*
|
/*
|
||||||
* Proceed to the network phase.
|
* Proceed to the network phase.
|
||||||
*/
|
*/
|
||||||
static void network_phase(int unit)
|
static void
|
||||||
|
network_phase(int unit)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct protent *protp;
|
struct protent *protp;
|
||||||
@ -726,31 +747,35 @@ static void network_phase(int unit)
|
|||||||
#endif /* CBCP_SUPPORT */
|
#endif /* CBCP_SUPPORT */
|
||||||
|
|
||||||
lcp_phase[unit] = PHASE_NETWORK;
|
lcp_phase[unit] = PHASE_NETWORK;
|
||||||
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i)
|
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
|
||||||
if (protp->protocol < 0xC000 && protp->enabled_flag
|
if (protp->protocol < 0xC000 && protp->enabled_flag && protp->open != NULL) {
|
||||||
&& protp->open != NULL) {
|
|
||||||
(*protp->open)(unit);
|
(*protp->open)(unit);
|
||||||
if (protp->protocol != PPP_CCP)
|
if (protp->protocol != PPP_CCP) {
|
||||||
++num_np_open;
|
++num_np_open;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (num_np_open == 0)
|
if (num_np_open == 0) {
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
lcp_close(0, "No network protocols running");
|
lcp_close(0, "No network protocols running");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check_idle - check whether the link has been idle for long
|
* check_idle - check whether the link has been idle for long
|
||||||
* enough that we can shut it down.
|
* enough that we can shut it down.
|
||||||
*/
|
*/
|
||||||
static void check_idle(void *arg)
|
static void
|
||||||
|
check_idle(void *arg)
|
||||||
{
|
{
|
||||||
struct ppp_idle idle;
|
struct ppp_idle idle;
|
||||||
u_short itime;
|
u_short itime;
|
||||||
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
if (!get_idle_time(0, &idle))
|
if (!get_idle_time(0, &idle)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle);
|
itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle);
|
||||||
if (itime >= ppp_settings.idle_time_limit) {
|
if (itime >= ppp_settings.idle_time_limit) {
|
||||||
/* link is idle: shut it down. */
|
/* link is idle: shut it down. */
|
||||||
@ -764,7 +789,8 @@ static void check_idle(void *arg)
|
|||||||
/*
|
/*
|
||||||
* connect_time_expired - log a message and close the connection.
|
* connect_time_expired - log a message and close the connection.
|
||||||
*/
|
*/
|
||||||
static void connect_time_expired(void *arg)
|
static void
|
||||||
|
connect_time_expired(void *arg)
|
||||||
{
|
{
|
||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
|
|
||||||
@ -782,7 +808,8 @@ static void connect_time_expired(void *arg)
|
|||||||
* UPAP_AUTHACK: Login succeeded.
|
* UPAP_AUTHACK: Login succeeded.
|
||||||
* In either case, msg points to an appropriate message.
|
* In either case, msg points to an appropriate message.
|
||||||
*/
|
*/
|
||||||
static int login(char *user, char *passwd, char **msg, int *msglen)
|
static int
|
||||||
|
login(char *user, char *passwd, char **msg, int *msglen)
|
||||||
{
|
{
|
||||||
/* XXX Fail until we decide that we want to support logins. */
|
/* XXX Fail until we decide that we want to support logins. */
|
||||||
return (UPAP_AUTHNAK);
|
return (UPAP_AUTHNAK);
|
||||||
@ -792,64 +819,66 @@ static int login(char *user, char *passwd, char **msg, int *msglen)
|
|||||||
/*
|
/*
|
||||||
* logout - Logout the user.
|
* logout - Logout the user.
|
||||||
*/
|
*/
|
||||||
static void logout(void)
|
static void
|
||||||
|
logout(void)
|
||||||
{
|
{
|
||||||
logged_in = 0;
|
logged_in = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* null_login - Check if a username of "" and a password of "" are
|
* null_login - Check if a username of "" and a password of "" are
|
||||||
* acceptable, and iff so, set the list of acceptable IP addresses
|
* acceptable, and iff so, set the list of acceptable IP addresses
|
||||||
* and return 1.
|
* and return 1.
|
||||||
*/
|
*/
|
||||||
static int null_login(int unit)
|
static int
|
||||||
|
null_login(int unit)
|
||||||
{
|
{
|
||||||
LWIP_UNUSED_ARG(unit);
|
LWIP_UNUSED_ARG(unit);
|
||||||
/* XXX Fail until we decide that we want to support logins. */
|
/* XXX Fail until we decide that we want to support logins. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_pap_passwd - get a password for authenticating ourselves with
|
* get_pap_passwd - get a password for authenticating ourselves with
|
||||||
* our peer using PAP. Returns 1 on success, 0 if no suitable password
|
* our peer using PAP. Returns 1 on success, 0 if no suitable password
|
||||||
* could be found.
|
* could be found.
|
||||||
*/
|
*/
|
||||||
static int get_pap_passwd(int unit, char *user, char *passwd)
|
static int
|
||||||
|
get_pap_passwd(int unit, char *user, char *passwd)
|
||||||
{
|
{
|
||||||
/* normally we would reject PAP if no password is provided,
|
/* normally we would reject PAP if no password is provided,
|
||||||
but this causes problems with some providers (like CHT in Taiwan)
|
but this causes problems with some providers (like CHT in Taiwan)
|
||||||
who incorrectly request PAP and expect a bogus/empty password, so
|
who incorrectly request PAP and expect a bogus/empty password, so
|
||||||
always provide a default user/passwd of "none"/"none"
|
always provide a default user/passwd of "none"/"none"
|
||||||
*/
|
*/
|
||||||
if(user)
|
if(user) {
|
||||||
strcpy(user, "none");
|
strcpy(user, "none");
|
||||||
if(passwd)
|
}
|
||||||
|
if(passwd) {
|
||||||
strcpy(passwd, "none");
|
strcpy(passwd, "none");
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* have_pap_secret - check whether we have a PAP file with any
|
* have_pap_secret - check whether we have a PAP file with any
|
||||||
* secrets that we could possibly use for authenticating the peer.
|
* secrets that we could possibly use for authenticating the peer.
|
||||||
*/
|
*/
|
||||||
static int have_pap_secret(void)
|
static int
|
||||||
|
have_pap_secret(void)
|
||||||
{
|
{
|
||||||
/* XXX Fail until we set up our passwords. */
|
/* XXX Fail until we set up our passwords. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* have_chap_secret - check whether we have a CHAP file with a
|
* have_chap_secret - check whether we have a CHAP file with a
|
||||||
* secret that we could possibly use for authenticating `client'
|
* secret that we could possibly use for authenticating `client'
|
||||||
* on `server'. Either can be the null string, meaning we don't
|
* on `server'. Either can be the null string, meaning we don't
|
||||||
* know the identity yet.
|
* know the identity yet.
|
||||||
*/
|
*/
|
||||||
static int have_chap_secret(char *client, char *server, u32_t remote)
|
static int
|
||||||
|
have_chap_secret(char *client, char *server, u32_t remote)
|
||||||
{
|
{
|
||||||
LWIP_UNUSED_ARG(client);
|
LWIP_UNUSED_ARG(client);
|
||||||
LWIP_UNUSED_ARG(server);
|
LWIP_UNUSED_ARG(server);
|
||||||
@ -858,15 +887,16 @@ static int have_chap_secret(char *client, char *server, u32_t remote)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
|
#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
|
||||||
/*
|
/*
|
||||||
* set_allowed_addrs() - set the list of allowed addresses.
|
* set_allowed_addrs() - set the list of allowed addresses.
|
||||||
*/
|
*/
|
||||||
static void set_allowed_addrs(int unit, struct wordlist *addrs)
|
static void
|
||||||
|
set_allowed_addrs(int unit, struct wordlist *addrs)
|
||||||
{
|
{
|
||||||
if (addresses[unit] != NULL)
|
if (addresses[unit] != NULL) {
|
||||||
free_wordlist(addresses[unit]);
|
free_wordlist(addresses[unit]);
|
||||||
|
}
|
||||||
addresses[unit] = addrs;
|
addresses[unit] = addrs;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -880,30 +910,33 @@ static void set_allowed_addrs(int unit, struct wordlist *addrs)
|
|||||||
u32_t a;
|
u32_t a;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
|
|
||||||
if (wo->hisaddr == 0 && *p != '!' && *p != '-'
|
if (wo->hisaddr == 0 && *p != '!' && *p != '-' && strchr(p, '/') == NULL) {
|
||||||
&& strchr(p, '/') == NULL) {
|
|
||||||
hp = gethostbyname(p);
|
hp = gethostbyname(p);
|
||||||
if (hp != NULL && hp->h_addrtype == AF_INET)
|
if (hp != NULL && hp->h_addrtype == AF_INET) {
|
||||||
a = *(u32_t *)hp->h_addr;
|
a = *(u32_t *)hp->h_addr;
|
||||||
else
|
} else {
|
||||||
a = inet_addr(p);
|
a = inet_addr(p);
|
||||||
if (a != (u32_t) -1)
|
}
|
||||||
|
if (a != (u32_t) -1) {
|
||||||
wo->hisaddr = a;
|
wo->hisaddr = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
|
#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
|
||||||
|
|
||||||
static int ip_addr_check(u32_t addr, struct wordlist *addrs)
|
static int
|
||||||
|
ip_addr_check(u32_t addr, struct wordlist *addrs)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* don't allow loopback or multicast address */
|
/* don't allow loopback or multicast address */
|
||||||
if (bad_ip_adrs(addr))
|
if (bad_ip_adrs(addr)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (addrs == NULL)
|
if (addrs == NULL) {
|
||||||
return !ppp_settings.auth_required; /* no addresses authorized */
|
return !ppp_settings.auth_required; /* no addresses authorized */
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX All other addresses allowed. */
|
/* XXX All other addresses allowed. */
|
||||||
return 1;
|
return 1;
|
||||||
@ -913,7 +946,8 @@ static int ip_addr_check(u32_t addr, struct wordlist *addrs)
|
|||||||
/*
|
/*
|
||||||
* free_wordlist - release memory allocated for a wordlist.
|
* free_wordlist - release memory allocated for a wordlist.
|
||||||
*/
|
*/
|
||||||
static void free_wordlist(struct wordlist *wp)
|
static void
|
||||||
|
free_wordlist(struct wordlist *wp)
|
||||||
{
|
{
|
||||||
struct wordlist *next;
|
struct wordlist *next;
|
||||||
|
|
||||||
|
@ -56,14 +56,30 @@
|
|||||||
/***********************
|
/***********************
|
||||||
*** PUBLIC FUNCTIONS ***
|
*** PUBLIC FUNCTIONS ***
|
||||||
***********************/
|
***********************/
|
||||||
void link_required (int); /* we are starting to use the link */
|
|
||||||
void link_terminated (int); /* we are finished with the link */
|
/* we are starting to use the link */
|
||||||
void link_down (int); /* the LCP layer has left the Opened state */
|
void link_required (int);
|
||||||
void link_established (int); /* the link is up; authenticate now */
|
|
||||||
void np_up (int, u16_t); /* a network protocol has come up */
|
/* we are finished with the link */
|
||||||
void np_down (int, u16_t); /* a network protocol has gone down */
|
void link_terminated (int);
|
||||||
void np_finished (int, u16_t); /* a network protocol no longer needs link */
|
|
||||||
void auth_peer_fail (int, u16_t);/* peer failed to authenticate itself */
|
/* the LCP layer has left the Opened state */
|
||||||
|
void link_down (int);
|
||||||
|
|
||||||
|
/* the link is up; authenticate now */
|
||||||
|
void link_established (int);
|
||||||
|
|
||||||
|
/* a network protocol has come up */
|
||||||
|
void np_up (int, u16_t);
|
||||||
|
|
||||||
|
/* a network protocol has gone down */
|
||||||
|
void np_down (int, u16_t);
|
||||||
|
|
||||||
|
/* a network protocol no longer needs link */
|
||||||
|
void np_finished (int, u16_t);
|
||||||
|
|
||||||
|
/* peer failed to authenticate itself */
|
||||||
|
void auth_peer_fail (int, u16_t);
|
||||||
|
|
||||||
/* peer successfully authenticated itself */
|
/* peer successfully authenticated itself */
|
||||||
void auth_peer_success (int, u16_t, char *, int);
|
void auth_peer_success (int, u16_t, char *, int);
|
||||||
@ -76,7 +92,9 @@ void auth_withpeer_success (int, u16_t);
|
|||||||
|
|
||||||
/* check authentication options supplied */
|
/* check authentication options supplied */
|
||||||
void auth_check_options (void);
|
void auth_check_options (void);
|
||||||
void auth_reset (int); /* check what secrets we have */
|
|
||||||
|
/* check what secrets we have */
|
||||||
|
void auth_reset (int);
|
||||||
|
|
||||||
/* Check peer-supplied username/password */
|
/* Check peer-supplied username/password */
|
||||||
int check_passwd (int, char *, int, char *, int, char **, int *);
|
int check_passwd (int, char *, int, char *, int, char **, int *);
|
||||||
|
@ -105,8 +105,7 @@ static void ChapLowerDown (int);
|
|||||||
static void ChapInput (int, u_char *, int);
|
static void ChapInput (int, u_char *, int);
|
||||||
static void ChapProtocolReject (int);
|
static void ChapProtocolReject (int);
|
||||||
#if 0
|
#if 0
|
||||||
static int ChapPrintPkt (u_char *, int,
|
static int ChapPrintPkt (u_char *, int, void (*) (void *, char *, ...), void *);
|
||||||
void (*) (void *, char *, ...), void *);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void ChapChallengeTimeout (void *);
|
static void ChapChallengeTimeout (void *);
|
||||||
@ -150,7 +149,6 @@ struct protent chap_protent = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
@ -158,7 +156,8 @@ struct protent chap_protent = {
|
|||||||
* ChapAuthWithPeer - Authenticate us with our peer (start client).
|
* ChapAuthWithPeer - Authenticate us with our peer (start client).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ChapAuthWithPeer(int unit, char *our_name, int digest)
|
void
|
||||||
|
ChapAuthWithPeer(int unit, char *our_name, int digest)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
|
|
||||||
@ -184,7 +183,8 @@ void ChapAuthWithPeer(int unit, char *our_name, int digest)
|
|||||||
/*
|
/*
|
||||||
* ChapAuthPeer - Authenticate our peer (start server).
|
* ChapAuthPeer - Authenticate our peer (start server).
|
||||||
*/
|
*/
|
||||||
void ChapAuthPeer(int unit, char *our_name, int digest)
|
void
|
||||||
|
ChapAuthPeer(int unit, char *our_name, int digest)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
|
|
||||||
@ -204,15 +204,14 @@ void ChapAuthPeer(int unit, char *our_name, int digest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************/
|
/**********************************/
|
||||||
/*** LOCAL FUNCTION DEFINITIONS ***/
|
/*** LOCAL FUNCTION DEFINITIONS ***/
|
||||||
/**********************************/
|
/**********************************/
|
||||||
/*
|
/*
|
||||||
* ChapInit - Initialize a CHAP unit.
|
* ChapInit - Initialize a CHAP unit.
|
||||||
*/
|
*/
|
||||||
static void ChapInit(int unit)
|
static void
|
||||||
|
ChapInit(int unit)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
|
|
||||||
@ -229,15 +228,17 @@ static void ChapInit(int unit)
|
|||||||
/*
|
/*
|
||||||
* ChapChallengeTimeout - Timeout expired on sending challenge.
|
* ChapChallengeTimeout - Timeout expired on sending challenge.
|
||||||
*/
|
*/
|
||||||
static void ChapChallengeTimeout(void *arg)
|
static void
|
||||||
|
ChapChallengeTimeout(void *arg)
|
||||||
{
|
{
|
||||||
chap_state *cstate = (chap_state *) arg;
|
chap_state *cstate = (chap_state *) arg;
|
||||||
|
|
||||||
/* if we aren't sending challenges, don't worry. then again we */
|
/* if we aren't sending challenges, don't worry. then again we */
|
||||||
/* probably shouldn't be here either */
|
/* probably shouldn't be here either */
|
||||||
if (cstate->serverstate != CHAPSS_INITIAL_CHAL &&
|
if (cstate->serverstate != CHAPSS_INITIAL_CHAL &&
|
||||||
cstate->serverstate != CHAPSS_RECHALLENGE)
|
cstate->serverstate != CHAPSS_RECHALLENGE) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cstate->chal_transmits >= cstate->max_transmits) {
|
if (cstate->chal_transmits >= cstate->max_transmits) {
|
||||||
/* give up on peer */
|
/* give up on peer */
|
||||||
@ -254,13 +255,15 @@ static void ChapChallengeTimeout(void *arg)
|
|||||||
/*
|
/*
|
||||||
* ChapResponseTimeout - Timeout expired on sending response.
|
* ChapResponseTimeout - Timeout expired on sending response.
|
||||||
*/
|
*/
|
||||||
static void ChapResponseTimeout(void *arg)
|
static void
|
||||||
|
ChapResponseTimeout(void *arg)
|
||||||
{
|
{
|
||||||
chap_state *cstate = (chap_state *) arg;
|
chap_state *cstate = (chap_state *) arg;
|
||||||
|
|
||||||
/* if we aren't sending a response, don't worry. */
|
/* if we aren't sending a response, don't worry. */
|
||||||
if (cstate->clientstate != CHAPCS_RESPONSE)
|
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ChapSendResponse(cstate); /* re-send response */
|
ChapSendResponse(cstate); /* re-send response */
|
||||||
}
|
}
|
||||||
@ -269,13 +272,15 @@ static void ChapResponseTimeout(void *arg)
|
|||||||
/*
|
/*
|
||||||
* ChapRechallenge - Time to challenge the peer again.
|
* ChapRechallenge - Time to challenge the peer again.
|
||||||
*/
|
*/
|
||||||
static void ChapRechallenge(void *arg)
|
static void
|
||||||
|
ChapRechallenge(void *arg)
|
||||||
{
|
{
|
||||||
chap_state *cstate = (chap_state *) arg;
|
chap_state *cstate = (chap_state *) arg;
|
||||||
|
|
||||||
/* if we aren't sending a response, don't worry. */
|
/* if we aren't sending a response, don't worry. */
|
||||||
if (cstate->serverstate != CHAPSS_OPEN)
|
if (cstate->serverstate != CHAPSS_OPEN) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ChapGenChallenge(cstate);
|
ChapGenChallenge(cstate);
|
||||||
ChapSendChallenge(cstate);
|
ChapSendChallenge(cstate);
|
||||||
@ -288,18 +293,20 @@ static void ChapRechallenge(void *arg)
|
|||||||
*
|
*
|
||||||
* Start up if we have pending requests.
|
* Start up if we have pending requests.
|
||||||
*/
|
*/
|
||||||
static void ChapLowerUp(int unit)
|
static void
|
||||||
|
ChapLowerUp(int unit)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
|
|
||||||
if (cstate->clientstate == CHAPCS_INITIAL)
|
if (cstate->clientstate == CHAPCS_INITIAL) {
|
||||||
cstate->clientstate = CHAPCS_CLOSED;
|
cstate->clientstate = CHAPCS_CLOSED;
|
||||||
else if (cstate->clientstate == CHAPCS_PENDING)
|
} else if (cstate->clientstate == CHAPCS_PENDING) {
|
||||||
cstate->clientstate = CHAPCS_LISTEN;
|
cstate->clientstate = CHAPCS_LISTEN;
|
||||||
|
}
|
||||||
|
|
||||||
if (cstate->serverstate == CHAPSS_INITIAL)
|
if (cstate->serverstate == CHAPSS_INITIAL) {
|
||||||
cstate->serverstate = CHAPSS_CLOSED;
|
cstate->serverstate = CHAPSS_CLOSED;
|
||||||
else if (cstate->serverstate == CHAPSS_PENDING) {
|
} else if (cstate->serverstate == CHAPSS_PENDING) {
|
||||||
ChapGenChallenge(cstate);
|
ChapGenChallenge(cstate);
|
||||||
ChapSendChallenge(cstate);
|
ChapSendChallenge(cstate);
|
||||||
cstate->serverstate = CHAPSS_INITIAL_CHAL;
|
cstate->serverstate = CHAPSS_INITIAL_CHAL;
|
||||||
@ -312,20 +319,22 @@ static void ChapLowerUp(int unit)
|
|||||||
*
|
*
|
||||||
* Cancel all timeouts.
|
* Cancel all timeouts.
|
||||||
*/
|
*/
|
||||||
static void ChapLowerDown(int unit)
|
static void
|
||||||
|
ChapLowerDown(int unit)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
|
|
||||||
/* Timeout(s) pending? Cancel if so. */
|
/* Timeout(s) pending? Cancel if so. */
|
||||||
if (cstate->serverstate == CHAPSS_INITIAL_CHAL ||
|
if (cstate->serverstate == CHAPSS_INITIAL_CHAL ||
|
||||||
cstate->serverstate == CHAPSS_RECHALLENGE)
|
cstate->serverstate == CHAPSS_RECHALLENGE) {
|
||||||
UNTIMEOUT(ChapChallengeTimeout, cstate);
|
UNTIMEOUT(ChapChallengeTimeout, cstate);
|
||||||
else if (cstate->serverstate == CHAPSS_OPEN
|
} else if (cstate->serverstate == CHAPSS_OPEN
|
||||||
&& cstate->chal_interval != 0)
|
&& cstate->chal_interval != 0) {
|
||||||
UNTIMEOUT(ChapRechallenge, cstate);
|
UNTIMEOUT(ChapRechallenge, cstate);
|
||||||
if (cstate->clientstate == CHAPCS_RESPONSE)
|
}
|
||||||
|
if (cstate->clientstate == CHAPCS_RESPONSE) {
|
||||||
UNTIMEOUT(ChapResponseTimeout, cstate);
|
UNTIMEOUT(ChapResponseTimeout, cstate);
|
||||||
|
}
|
||||||
cstate->clientstate = CHAPCS_INITIAL;
|
cstate->clientstate = CHAPCS_INITIAL;
|
||||||
cstate->serverstate = CHAPSS_INITIAL;
|
cstate->serverstate = CHAPSS_INITIAL;
|
||||||
}
|
}
|
||||||
@ -334,16 +343,19 @@ static void ChapLowerDown(int unit)
|
|||||||
/*
|
/*
|
||||||
* ChapProtocolReject - Peer doesn't grok CHAP.
|
* ChapProtocolReject - Peer doesn't grok CHAP.
|
||||||
*/
|
*/
|
||||||
static void ChapProtocolReject(int unit)
|
static void
|
||||||
|
ChapProtocolReject(int unit)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
|
|
||||||
if (cstate->serverstate != CHAPSS_INITIAL &&
|
if (cstate->serverstate != CHAPSS_INITIAL &&
|
||||||
cstate->serverstate != CHAPSS_CLOSED)
|
cstate->serverstate != CHAPSS_CLOSED) {
|
||||||
auth_peer_fail(unit, PPP_CHAP);
|
auth_peer_fail(unit, PPP_CHAP);
|
||||||
|
}
|
||||||
if (cstate->clientstate != CHAPCS_INITIAL &&
|
if (cstate->clientstate != CHAPCS_INITIAL &&
|
||||||
cstate->clientstate != CHAPCS_CLOSED)
|
cstate->clientstate != CHAPCS_CLOSED) {
|
||||||
auth_withpeer_fail(unit, PPP_CHAP);
|
auth_withpeer_fail(unit, PPP_CHAP);
|
||||||
|
}
|
||||||
ChapLowerDown(unit); /* shutdown chap */
|
ChapLowerDown(unit); /* shutdown chap */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +363,8 @@ static void ChapProtocolReject(int unit)
|
|||||||
/*
|
/*
|
||||||
* ChapInput - Input CHAP packet.
|
* ChapInput - Input CHAP packet.
|
||||||
*/
|
*/
|
||||||
static void ChapInput(int unit, u_char *inpacket, int packet_len)
|
static void
|
||||||
|
ChapInput(int unit, u_char *inpacket, int packet_len)
|
||||||
{
|
{
|
||||||
chap_state *cstate = &chap[unit];
|
chap_state *cstate = &chap[unit];
|
||||||
u_char *inp;
|
u_char *inp;
|
||||||
@ -410,7 +423,8 @@ static void ChapInput(int unit, u_char *inpacket, int packet_len)
|
|||||||
/*
|
/*
|
||||||
* ChapReceiveChallenge - Receive Challenge and send Response.
|
* ChapReceiveChallenge - Receive Challenge and send Response.
|
||||||
*/
|
*/
|
||||||
static void ChapReceiveChallenge(chap_state *cstate, u_char *inp, int id, int len)
|
static void
|
||||||
|
ChapReceiveChallenge(chap_state *cstate, u_char *inp, int id, int len)
|
||||||
{
|
{
|
||||||
int rchallenge_len;
|
int rchallenge_len;
|
||||||
u_char *rchallenge;
|
u_char *rchallenge;
|
||||||
@ -442,32 +456,31 @@ static void ChapReceiveChallenge(chap_state *cstate, u_char *inp, int id, int le
|
|||||||
rchallenge = inp;
|
rchallenge = inp;
|
||||||
INCPTR(rchallenge_len, inp);
|
INCPTR(rchallenge_len, inp);
|
||||||
|
|
||||||
if (len >= sizeof(rhostname))
|
if (len >= sizeof(rhostname)) {
|
||||||
len = sizeof(rhostname) - 1;
|
len = sizeof(rhostname) - 1;
|
||||||
|
}
|
||||||
BCOPY(inp, rhostname, len);
|
BCOPY(inp, rhostname, len);
|
||||||
rhostname[len] = '\000';
|
rhostname[len] = '\000';
|
||||||
|
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: received name field '%s'\n",
|
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: received name field '%s'\n", rhostname));
|
||||||
rhostname));
|
|
||||||
|
|
||||||
/* Microsoft doesn't send their name back in the PPP packet */
|
/* Microsoft doesn't send their name back in the PPP packet */
|
||||||
if (ppp_settings.remote_name[0] != 0 && (ppp_settings.explicit_remote || rhostname[0] == 0)) {
|
if (ppp_settings.remote_name[0] != 0 && (ppp_settings.explicit_remote || rhostname[0] == 0)) {
|
||||||
strncpy(rhostname, ppp_settings.remote_name, sizeof(rhostname));
|
strncpy(rhostname, ppp_settings.remote_name, sizeof(rhostname));
|
||||||
rhostname[sizeof(rhostname) - 1] = 0;
|
rhostname[sizeof(rhostname) - 1] = 0;
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: using '%s' as remote name\n",
|
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: using '%s' as remote name\n", rhostname));
|
||||||
rhostname));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get secret for authenticating ourselves with the specified host */
|
/* get secret for authenticating ourselves with the specified host */
|
||||||
if (!get_secret(cstate->unit, cstate->resp_name, rhostname,
|
if (!get_secret(cstate->unit, cstate->resp_name, rhostname, secret, &secret_len, 0)) {
|
||||||
secret, &secret_len, 0)) {
|
|
||||||
secret_len = 0; /* assume null secret if can't find one */
|
secret_len = 0; /* assume null secret if can't find one */
|
||||||
CHAPDEBUG((LOG_WARNING, "No CHAP secret found for authenticating us to %s\n", rhostname));
|
CHAPDEBUG((LOG_WARNING, "No CHAP secret found for authenticating us to %s\n", rhostname));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cancel response send timeout if necessary */
|
/* cancel response send timeout if necessary */
|
||||||
if (cstate->clientstate == CHAPCS_RESPONSE)
|
if (cstate->clientstate == CHAPCS_RESPONSE) {
|
||||||
UNTIMEOUT(ChapResponseTimeout, cstate);
|
UNTIMEOUT(ChapResponseTimeout, cstate);
|
||||||
|
}
|
||||||
|
|
||||||
cstate->resp_id = id;
|
cstate->resp_id = id;
|
||||||
cstate->resp_transmits = 0;
|
cstate->resp_transmits = 0;
|
||||||
@ -504,7 +517,8 @@ static void ChapReceiveChallenge(chap_state *cstate, u_char *inp, int id, int le
|
|||||||
/*
|
/*
|
||||||
* ChapReceiveResponse - Receive and process response.
|
* ChapReceiveResponse - Receive and process response.
|
||||||
*/
|
*/
|
||||||
static void ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len)
|
static void
|
||||||
|
ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len)
|
||||||
{
|
{
|
||||||
u_char *remmd, remmd_len;
|
u_char *remmd, remmd_len;
|
||||||
int secret_len, old_state;
|
int secret_len, old_state;
|
||||||
@ -523,8 +537,9 @@ static void ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != cstate->chal_id)
|
if (id != cstate->chal_id) {
|
||||||
return; /* doesn't match ID of last challenge */
|
return; /* doesn't match ID of last challenge */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have received a duplicate or bogus Response,
|
* If we have received a duplicate or bogus Response,
|
||||||
@ -556,32 +571,31 @@ static void ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len
|
|||||||
|
|
||||||
UNTIMEOUT(ChapChallengeTimeout, cstate);
|
UNTIMEOUT(ChapChallengeTimeout, cstate);
|
||||||
|
|
||||||
if (len >= sizeof(rhostname))
|
if (len >= sizeof(rhostname)) {
|
||||||
len = sizeof(rhostname) - 1;
|
len = sizeof(rhostname) - 1;
|
||||||
|
}
|
||||||
BCOPY(inp, rhostname, len);
|
BCOPY(inp, rhostname, len);
|
||||||
rhostname[len] = '\000';
|
rhostname[len] = '\000';
|
||||||
|
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: received name field: %s\n",
|
CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: received name field: %s\n", rhostname));
|
||||||
rhostname));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get secret for authenticating them with us,
|
* Get secret for authenticating them with us,
|
||||||
* do the hash ourselves, and compare the result.
|
* do the hash ourselves, and compare the result.
|
||||||
*/
|
*/
|
||||||
code = CHAP_FAILURE;
|
code = CHAP_FAILURE;
|
||||||
if (!get_secret(cstate->unit, rhostname, cstate->chal_name,
|
if (!get_secret(cstate->unit, rhostname, cstate->chal_name, secret, &secret_len, 1)) {
|
||||||
secret, &secret_len, 1)) {
|
|
||||||
/* CHAPDEBUG((LOG_WARNING, TL_CHAP, "No CHAP secret found for authenticating %s\n", rhostname)); */
|
/* CHAPDEBUG((LOG_WARNING, TL_CHAP, "No CHAP secret found for authenticating %s\n", rhostname)); */
|
||||||
CHAPDEBUG((LOG_WARNING, "No CHAP secret found for authenticating %s\n",
|
CHAPDEBUG((LOG_WARNING, "No CHAP secret found for authenticating %s\n",
|
||||||
rhostname));
|
rhostname));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* generate MD based on negotiated type */
|
/* generate MD based on negotiated type */
|
||||||
switch (cstate->chal_type) {
|
switch (cstate->chal_type) {
|
||||||
|
|
||||||
case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
|
case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
|
||||||
if (remmd_len != MD5_SIGNATURE_SIZE)
|
if (remmd_len != MD5_SIGNATURE_SIZE) {
|
||||||
break; /* it's not even the right length */
|
break; /* it's not even the right length */
|
||||||
|
}
|
||||||
MD5Init(&mdContext);
|
MD5Init(&mdContext);
|
||||||
MD5Update(&mdContext, &cstate->chal_id, 1);
|
MD5Update(&mdContext, &cstate->chal_id, 1);
|
||||||
MD5Update(&mdContext, (u_char*)secret, secret_len);
|
MD5Update(&mdContext, (u_char*)secret, secret_len);
|
||||||
@ -589,8 +603,9 @@ static void ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len
|
|||||||
MD5Final(hash, &mdContext);
|
MD5Final(hash, &mdContext);
|
||||||
|
|
||||||
/* compare local and remote MDs and send the appropriate status */
|
/* compare local and remote MDs and send the appropriate status */
|
||||||
if (memcmp (hash, remmd, MD5_SIGNATURE_SIZE) == 0)
|
if (memcmp (hash, remmd, MD5_SIGNATURE_SIZE) == 0) {
|
||||||
code = CHAP_SUCCESS; /* they are the same! */
|
code = CHAP_SUCCESS; /* they are the same! */
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -607,8 +622,9 @@ static void ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len
|
|||||||
if (old_state == CHAPSS_INITIAL_CHAL) {
|
if (old_state == CHAPSS_INITIAL_CHAL) {
|
||||||
auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len);
|
auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len);
|
||||||
}
|
}
|
||||||
if (cstate->chal_interval != 0)
|
if (cstate->chal_interval != 0) {
|
||||||
TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval);
|
TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CHAPDEBUG((LOG_ERR, "CHAP peer authentication failed\n"));
|
CHAPDEBUG((LOG_ERR, "CHAP peer authentication failed\n"));
|
||||||
cstate->serverstate = CHAPSS_BADAUTH;
|
cstate->serverstate = CHAPSS_BADAUTH;
|
||||||
@ -619,19 +635,19 @@ static void ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len
|
|||||||
/*
|
/*
|
||||||
* ChapReceiveSuccess - Receive Success
|
* ChapReceiveSuccess - Receive Success
|
||||||
*/
|
*/
|
||||||
static void ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int len)
|
static void
|
||||||
|
ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int len)
|
||||||
{
|
{
|
||||||
|
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: Rcvd id %d.\n", id));
|
CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: Rcvd id %d.\n", id));
|
||||||
|
|
||||||
if (cstate->clientstate == CHAPCS_OPEN)
|
if (cstate->clientstate == CHAPCS_OPEN) {
|
||||||
/* presumably an answer to a duplicate response */
|
/* presumably an answer to a duplicate response */
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
||||||
/* don't know what this is */
|
/* don't know what this is */
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: in state %d\n",
|
CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: in state %d\n", cstate->clientstate));
|
||||||
cstate->clientstate));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,8 +656,9 @@ static void ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int l
|
|||||||
/*
|
/*
|
||||||
* Print message.
|
* Print message.
|
||||||
*/
|
*/
|
||||||
if (len > 0)
|
if (len > 0) {
|
||||||
PRINTMSG(inp, len);
|
PRINTMSG(inp, len);
|
||||||
|
}
|
||||||
|
|
||||||
cstate->clientstate = CHAPCS_OPEN;
|
cstate->clientstate = CHAPCS_OPEN;
|
||||||
|
|
||||||
@ -652,14 +669,14 @@ static void ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int l
|
|||||||
/*
|
/*
|
||||||
* ChapReceiveFailure - Receive failure.
|
* ChapReceiveFailure - Receive failure.
|
||||||
*/
|
*/
|
||||||
static void ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int len)
|
static void
|
||||||
|
ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int len)
|
||||||
{
|
{
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: Rcvd id %d.\n", id));
|
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: Rcvd id %d.\n", id));
|
||||||
|
|
||||||
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
if (cstate->clientstate != CHAPCS_RESPONSE) {
|
||||||
/* don't know what this is */
|
/* don't know what this is */
|
||||||
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: in state %d\n",
|
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: in state %d\n", cstate->clientstate));
|
||||||
cstate->clientstate));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,8 +685,9 @@ static void ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int l
|
|||||||
/*
|
/*
|
||||||
* Print message.
|
* Print message.
|
||||||
*/
|
*/
|
||||||
if (len > 0)
|
if (len > 0) {
|
||||||
PRINTMSG(inp, len);
|
PRINTMSG(inp, len);
|
||||||
|
}
|
||||||
|
|
||||||
CHAPDEBUG((LOG_ERR, "CHAP authentication failed\n"));
|
CHAPDEBUG((LOG_ERR, "CHAP authentication failed\n"));
|
||||||
auth_withpeer_fail(cstate->unit, PPP_CHAP);
|
auth_withpeer_fail(cstate->unit, PPP_CHAP);
|
||||||
@ -679,7 +697,8 @@ static void ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int l
|
|||||||
/*
|
/*
|
||||||
* ChapSendChallenge - Send an Authenticate challenge.
|
* ChapSendChallenge - Send an Authenticate challenge.
|
||||||
*/
|
*/
|
||||||
static void ChapSendChallenge(chap_state *cstate)
|
static void
|
||||||
|
ChapSendChallenge(chap_state *cstate)
|
||||||
{
|
{
|
||||||
u_char *outp;
|
u_char *outp;
|
||||||
int chal_len, name_len;
|
int chal_len, name_len;
|
||||||
@ -714,16 +733,18 @@ static void ChapSendChallenge(chap_state *cstate)
|
|||||||
/*
|
/*
|
||||||
* ChapSendStatus - Send a status response (ack or nak).
|
* ChapSendStatus - Send a status response (ack or nak).
|
||||||
*/
|
*/
|
||||||
static void ChapSendStatus(chap_state *cstate, int code)
|
static void
|
||||||
|
ChapSendStatus(chap_state *cstate, int code)
|
||||||
{
|
{
|
||||||
u_char *outp;
|
u_char *outp;
|
||||||
int outlen, msglen;
|
int outlen, msglen;
|
||||||
char msg[256];
|
char msg[256];
|
||||||
|
|
||||||
if (code == CHAP_SUCCESS)
|
if (code == CHAP_SUCCESS) {
|
||||||
strcpy(msg, "Welcome!");
|
strcpy(msg, "Welcome!");
|
||||||
else
|
} else {
|
||||||
strcpy(msg, "I don't like you. Go 'way.");
|
strcpy(msg, "I don't like you. Go 'way.");
|
||||||
|
}
|
||||||
msglen = strlen(msg);
|
msglen = strlen(msg);
|
||||||
|
|
||||||
outlen = CHAP_HEADERLEN + msglen;
|
outlen = CHAP_HEADERLEN + msglen;
|
||||||
@ -737,8 +758,7 @@ static void ChapSendStatus(chap_state *cstate, int code)
|
|||||||
BCOPY(msg, outp, msglen);
|
BCOPY(msg, outp, msglen);
|
||||||
pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN);
|
pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN);
|
||||||
|
|
||||||
CHAPDEBUG((LOG_INFO, "ChapSendStatus: Sent code %d, id %d.\n", code,
|
CHAPDEBUG((LOG_INFO, "ChapSendStatus: Sent code %d, id %d.\n", code, cstate->chal_id));
|
||||||
cstate->chal_id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -748,7 +768,8 @@ static void ChapSendStatus(chap_state *cstate, int code)
|
|||||||
* *cstate are initialized.
|
* *cstate are initialized.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void ChapGenChallenge(chap_state *cstate)
|
static void
|
||||||
|
ChapGenChallenge(chap_state *cstate)
|
||||||
{
|
{
|
||||||
int chal_len;
|
int chal_len;
|
||||||
u_char *ptr = cstate->challenge;
|
u_char *ptr = cstate->challenge;
|
||||||
@ -765,16 +786,18 @@ static void ChapGenChallenge(chap_state *cstate)
|
|||||||
cstate->chal_transmits = 0;
|
cstate->chal_transmits = 0;
|
||||||
|
|
||||||
/* generate a random string */
|
/* generate a random string */
|
||||||
for (i = 0; i < chal_len; i++ )
|
for (i = 0; i < chal_len; i++ ) {
|
||||||
*ptr++ = (char) (magic() & 0xff);
|
*ptr++ = (char) (magic() & 0xff);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ChapSendResponse - send a response packet with values as specified
|
* ChapSendResponse - send a response packet with values as specified
|
||||||
* in *cstate.
|
* in *cstate.
|
||||||
*/
|
*/
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
static void ChapSendResponse(chap_state *cstate)
|
static void
|
||||||
|
ChapSendResponse(chap_state *cstate)
|
||||||
{
|
{
|
||||||
u_char *outp;
|
u_char *outp;
|
||||||
int outlen, md_len, name_len;
|
int outlen, md_len, name_len;
|
||||||
@ -811,39 +834,39 @@ static char *ChapCodenames[] = {
|
|||||||
/*
|
/*
|
||||||
* ChapPrintPkt - print the contents of a CHAP packet.
|
* ChapPrintPkt - print the contents of a CHAP packet.
|
||||||
*/
|
*/
|
||||||
static int ChapPrintPkt(
|
static int
|
||||||
u_char *p,
|
ChapPrintPkt( u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
|
||||||
int plen,
|
|
||||||
void (*printer) (void *, char *, ...),
|
|
||||||
void *arg
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int code, id, len;
|
int code, id, len;
|
||||||
int clen, nlen;
|
int clen, nlen;
|
||||||
u_char x;
|
u_char x;
|
||||||
|
|
||||||
if (plen < CHAP_HEADERLEN)
|
if (plen < CHAP_HEADERLEN) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
GETCHAR(code, p);
|
GETCHAR(code, p);
|
||||||
GETCHAR(id, p);
|
GETCHAR(id, p);
|
||||||
GETSHORT(len, p);
|
GETSHORT(len, p);
|
||||||
if (len < CHAP_HEADERLEN || len > plen)
|
if (len < CHAP_HEADERLEN || len > plen) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (code >= 1 && code <= sizeof(ChapCodenames) / sizeof(char *))
|
if (code >= 1 && code <= sizeof(ChapCodenames) / sizeof(char *)) {
|
||||||
printer(arg, " %s", ChapCodenames[code-1]);
|
printer(arg, " %s", ChapCodenames[code-1]);
|
||||||
else
|
} else {
|
||||||
printer(arg, " code=0x%x", code);
|
printer(arg, " code=0x%x", code);
|
||||||
|
}
|
||||||
printer(arg, " id=0x%x", id);
|
printer(arg, " id=0x%x", id);
|
||||||
len -= CHAP_HEADERLEN;
|
len -= CHAP_HEADERLEN;
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case CHAP_CHALLENGE:
|
case CHAP_CHALLENGE:
|
||||||
case CHAP_RESPONSE:
|
case CHAP_RESPONSE:
|
||||||
if (len < 1)
|
if (len < 1) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
clen = p[0];
|
clen = p[0];
|
||||||
if (len < clen + 1)
|
if (len < clen + 1) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
++p;
|
++p;
|
||||||
nlen = len - clen - 1;
|
nlen = len - clen - 1;
|
||||||
printer(arg, " <");
|
printer(arg, " <");
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
#include "randm.h"
|
#include "randm.h"
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
@ -75,5 +74,3 @@ u32_t magic()
|
|||||||
{
|
{
|
||||||
return avRandom();
|
return avRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
*
|
||||||
* $Id: magic.h,v 1.1 2003/05/27 14:37:56 jani Exp $
|
* $Id: magic.h,v 1.2 2007/12/02 22:35:55 fbernon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MAGIC_H
|
#ifndef MAGIC_H
|
||||||
@ -58,7 +58,10 @@
|
|||||||
************************** PUBLIC FUNCTIONS **********************************
|
************************** PUBLIC FUNCTIONS **********************************
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
void magicInit(void); /* Initialize the magic number generator */
|
/* Initialize the magic number generator */
|
||||||
u32_t magic(void); /* Returns the next magic number */
|
void magicInit(void);
|
||||||
|
|
||||||
|
/* Returns the next magic number */
|
||||||
|
u32_t magic(void);
|
||||||
|
|
||||||
#endif /* MAGIC_H */
|
#endif /* MAGIC_H */
|
||||||
|
@ -210,6 +210,7 @@ enum NPmode {
|
|||||||
#define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
|
#define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
|
||||||
#define BCOPY(s, d, l) MEMCPY((d), (s), (l))
|
#define BCOPY(s, d, l) MEMCPY((d), (s), (l))
|
||||||
#define BZERO(s, n) memset(s, 0, n)
|
#define BZERO(s, n) memset(s, 0, n)
|
||||||
|
|
||||||
#if PPP_DEBUG
|
#if PPP_DEBUG
|
||||||
#define PRINTMSG(m, l) { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); }
|
#define PRINTMSG(m, l) { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); }
|
||||||
#else /* PPP_DEBUG */
|
#else /* PPP_DEBUG */
|
||||||
@ -330,6 +331,7 @@ struct ppp_addrs {
|
|||||||
/*****************************
|
/*****************************
|
||||||
*** PUBLIC DATA STRUCTURES ***
|
*** PUBLIC DATA STRUCTURES ***
|
||||||
*****************************/
|
*****************************/
|
||||||
|
|
||||||
/* Buffers for outgoing packets. */
|
/* Buffers for outgoing packets. */
|
||||||
extern u_char *outpacket_buf[NUM_PPP];
|
extern u_char *outpacket_buf[NUM_PPP];
|
||||||
|
|
||||||
@ -382,13 +384,14 @@ void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd)
|
|||||||
*/
|
*/
|
||||||
int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
|
int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
|
||||||
|
|
||||||
/* for source code compatibility */
|
|
||||||
#define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls)
|
|
||||||
/*
|
/*
|
||||||
* Open a new PPP Over Ethernet (PPPOE) connection.
|
* Open a new PPP Over Ethernet (PPPOE) connection.
|
||||||
*/
|
*/
|
||||||
int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
|
int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
|
||||||
|
|
||||||
|
/* for source code compatibility */
|
||||||
|
#define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close a PPP connection and release the descriptor.
|
* Close a PPP connection and release the descriptor.
|
||||||
* Any outstanding packets in the queues are dropped.
|
* Any outstanding packets in the queues are dropped.
|
||||||
@ -414,8 +417,7 @@ u_int pppMTU(int pd);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Write n characters to a ppp link.
|
* Write n characters to a ppp link.
|
||||||
* RETURN: >= 0 Number of characters written
|
* RETURN: >= 0 Number of characters written, -1 Failed to write to device.
|
||||||
* -1 Failed to write to device
|
|
||||||
*/
|
*/
|
||||||
int pppWrite(int pd, const u_char *s, int n);
|
int pppWrite(int pd, const u_char *s, int n);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user