From 2aa9a66c57692226bce81082f2cb7e5ef09f6715 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Tue, 19 Jun 2012 21:26:52 +0200 Subject: [PATCH] don't duplicate user and password anymore, anyway, the PPP user will have them already allocated as static strings or from configuration flash/file --- src/netif/ppp/auth.c | 4 ++-- src/netif/ppp/chap-new.c | 5 ++++- src/netif/ppp/eap.c | 3 +++ src/netif/ppp/ppp.c | 16 +++++----------- src/netif/ppp/ppp.h | 6 +++--- src/netif/ppp/upap.c | 4 ++++ 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index bb6b9c96..3d64fe73 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -1465,7 +1465,7 @@ void auth_reset(ppp_pcb *pcb) { lcp_options *go = &pcb->lcp_gotoptions; lcp_options *ao = &pcb->lcp_allowoptions; - if( pcb->settings.passwd[0] ) { + if(pcb->settings.passwd) { #if PAP_SUPPORT ao->neg_upap = !pcb->settings.refuse_pap; @@ -1932,7 +1932,7 @@ int get_secret(ppp_pcb *pcb, char *client, char *server, char *secret, int *secr LWIP_UNUSED_ARG(server); LWIP_UNUSED_ARG(am_server); - if(!client || !client[0] || strcmp(client, pcb->settings.user)) { + if(!client || !client[0] || !pcb->settings.user || !pcb->settings.passwd || strcmp(client, pcb->settings.user)) { return 0; } diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index 8e026867..825658d7 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -205,6 +205,9 @@ void chap_auth_peer(ppp_pcb *pcb, char *our_name, int digest_code) { void chap_auth_with_peer(ppp_pcb *pcb, char *our_name, int digest_code) { struct chap_digest_type *dp; + if(NULL == our_name) + return; + if (pcb->chap_client.flags & AUTH_STARTED) { error("CHAP: authentication with peer already started!"); return; @@ -221,7 +224,7 @@ void chap_auth_with_peer(ppp_pcb *pcb, char *our_name, int digest_code) { pcb->chap_client.flags |= AUTH_STARTED; } -# if PPP_SERVER +#if PPP_SERVER /* * chap_timeout - It's time to send another challenge to the peer. * This could be either a retransmission of a previous challenge, diff --git a/src/netif/ppp/eap.c b/src/netif/ppp/eap.c index 1b2663ad..f930531c 100644 --- a/src/netif/ppp/eap.c +++ b/src/netif/ppp/eap.c @@ -235,6 +235,9 @@ static void eap_client_timeout(void *arg) { */ void eap_authwithpeer(ppp_pcb *pcb, char *localname) { + if(NULL == localname) + return; + /* Save the peer name we're given */ pcb->eap.es_client.ea_name = localname; pcb->eap.es_client.ea_namelen = strlen(localname); diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index c733b197..8729acc9 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -261,7 +261,7 @@ ppp_pcb *ppp_new(u8_t num) { return pcb; } -void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) { +void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd) { #if PAP_SUPPORT if(authtype & PPPAUTHTYPE_PAP) @@ -293,17 +293,11 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas pcb->settings.refuse_eap = 1; #endif /* EAP_SUPPORT */ - if(user) { - strncpy(pcb->settings.user, user, sizeof(pcb->settings.user)-1); - pcb->settings.user[sizeof(pcb->settings.user)-1] = '\0'; - } else - pcb->settings.user[0] = '\0'; + if(user) + pcb->settings.user = user; - if(passwd) { - strncpy(pcb->settings.passwd, passwd, sizeof(pcb->settings.passwd)-1); - pcb->settings.passwd[sizeof(pcb->settings.passwd)-1] = '\0'; - } else - pcb->settings.passwd[0] = '\0'; + if(passwd) + pcb->settings.passwd = passwd; } #if PPPOS_SUPPORT diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index a42a0a3d..c6998aac 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -193,8 +193,8 @@ typedef struct ppp_settings_s { #endif /* PPP_MAXCONNECT */ /* auth data */ - char user [MAXNAMELEN + 1]; /* Username for PAP */ - char passwd [MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */ + char *user; /* Username for PAP */ + char *passwd; /* Password for PAP, secret for CHAP */ #if PPP_SERVER char our_name [MAXNAMELEN + 1]; /* Our name for authentication purposes */ #endif /* PPP_SERVER */ @@ -390,7 +390,7 @@ ppp_pcb *ppp_new(u8_t num); #define PPPAUTHTYPE_EAP 0x08 #define PPPAUTHTYPE_ANY 0xff -void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd); +void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd); /* Link status callback function prototype */ typedef void (*ppp_link_status_cb_fn)(void *ctx, int errcode, void *arg); diff --git a/src/netif/ppp/upap.c b/src/netif/ppp/upap.c index 2df9ce3b..8e31f7ee 100644 --- a/src/netif/ppp/upap.c +++ b/src/netif/ppp/upap.c @@ -157,6 +157,10 @@ static void upap_init(ppp_pcb *pcb) { * Set new state and send authenticate's. */ void upap_authwithpeer(ppp_pcb *pcb, char *user, char *password) { + + if(!user || !password) + return; + /* Save the username and password we're given */ pcb->upap.us_user = user; pcb->upap.us_userlen = strlen(user);